Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
Expand Up @@ -1618,7 +1618,7 @@ private RubyClass initContinuation(ThreadContext context) {
return null;
}

public static final int NIL_PREFILLED_ARRAY_SIZE = RubyArray.ARRAY_DEFAULT_SIZE * 8;
public static final int NIL_PREFILLED_ARRAY_SIZE = RubyArrayNative.ARRAY_DEFAULT_SIZE * 8;
private final IRubyObject nilPrefilledArray[];

public IRubyObject[] getNilPrefilledArray() {
Expand Down
6,069 changes: 738 additions & 5,331 deletions core/src/main/java/org/jruby/RubyArray.java

Large diffs are not rendered by default.

5,263 changes: 5,263 additions & 0 deletions core/src/main/java/org/jruby/RubyArrayNative.java

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,7 @@ private SubclassArray newConcreteSubclassesArray(ThreadContext context) {
return new SubclassArray(context.runtime, this.concreteSubclassesEstimate);
}

private static class SubclassArray extends RubyArray<RubyClass> implements BiConsumer<ThreadContext, RubyClass> {
private static class SubclassArray extends RubyArrayNative<RubyClass> implements BiConsumer<ThreadContext, RubyClass> {
public SubclassArray(Ruby runtime, int length) {
super(runtime, length);
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubyEnumerable.java
Original file line number Diff line number Diff line change
Expand Up @@ -1877,7 +1877,7 @@ public static IRubyObject zipCommon(ThreadContext context, IRubyObject self,

if (block.isGiven()) {
callEach(context, eachSite(context), self, (ctx, largs, unused) -> {
var array = RubyArray.newBlankArrayInternal(ctx.runtime, len);
var array = RubyArrayNative.newBlankArrayInternal(ctx.runtime, len);
int myIx = ix.getAndIncrement();
array.eltInternalSet(0, packEnumValues(ctx, largs));
for (int i = 0, j = args.length; i < j; i++) {
Expand All @@ -1891,7 +1891,7 @@ public static IRubyObject zipCommon(ThreadContext context, IRubyObject self,
} else {
final var zip = newArray(context);
callEach(context, eachSite(context), self, Signature.ONE_REQUIRED, (ctx, largs, unused) -> {
var array = RubyArray.newBlankArrayInternal(ctx.runtime, len);
var array = RubyArrayNative.newBlankArrayInternal(ctx.runtime, len);
int myIx = ix.getAndIncrement();
array.eltInternalSet(0, packEnumValues(ctx, largs));
for (int i = 0, j = args.length; i < j; i++) {
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubyGlobal.java
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ public IRubyObject delete(ThreadContext context, IRubyObject key, Block block) {
public IRubyObject each(final ThreadContext context, final Block block) {
if (!block.isGiven()) return super.each(context, block);

RubyArray ary = new RubyArray(context.runtime, size());
RubyArray ary = RubyArray.newArray(context.runtime, size());

visitAll(context, EachVisitor, ary);

Expand Down Expand Up @@ -584,7 +584,7 @@ public IRubyObject index(ThreadContext context, IRubyObject expected) {
@JRubyMethod(name = "keys")
public RubyArray keys(final ThreadContext context) {
try {
RubyArray keys = RubyArray.newBlankArrayInternal(context.runtime, size());
RubyArray keys = RubyArrayNative.newBlankArrayInternal(context.runtime, size());

visitAll(context, StoreKeyVisitor, keys);

Expand Down
10 changes: 5 additions & 5 deletions core/src/main/java/org/jruby/RubyHash.java
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ public RubyBoolean empty_p(ThreadContext context) {
public RubyArray to_a(ThreadContext context) {
final Ruby runtime = context.runtime;
try {
final RubyArray result = RubyArray.newBlankArrayInternal(runtime, size);
final RubyArray result = RubyArrayNative.newBlankArrayInternal(runtime, size);

visitAll(context, RubyHash.StoreKeyValueVisitor, result);

Expand Down Expand Up @@ -1924,7 +1924,7 @@ public void visit(ThreadContext context, RubyHash self, IRubyObject key, IRubyOb
@JRubyMethod(name = "keys")
public RubyArray keys(final ThreadContext context) {
try {
RubyArray keys = RubyArray.newBlankArrayInternal(context.runtime, size());
RubyArray keys = RubyArrayNative.newBlankArrayInternal(context.runtime, size());

visitAll(context, StoreKeyVisitor, keys);

Expand Down Expand Up @@ -1952,7 +1952,7 @@ public void visit(ThreadContext context, RubyHash self, IRubyObject key, IRubyOb
@JRubyMethod(name = "values")
public RubyArray values(final ThreadContext context) {
try {
RubyArray values = RubyArray.newBlankArrayInternal(context.runtime, size());
RubyArray values = RubyArrayNative.newBlankArrayInternal(context.runtime, size());

visitAll(context, StoreValueVisitor, values);

Expand Down Expand Up @@ -2280,7 +2280,7 @@ public void visit(ThreadContext context, RubyHash self, IRubyObject key, IRubyOb
*/
@JRubyMethod(name = "values_at", rest = true)
public RubyArray values_at(ThreadContext context, IRubyObject[] args) {
RubyArray result = RubyArray.newBlankArrayInternal(context.runtime, args.length);
RubyArray result = RubyArrayNative.newBlankArrayInternal(context.runtime, args.length);
for (int i = 0; i < args.length; i++) {
result.storeInternal(context, i, op_aref(context, args[i]));
}
Expand All @@ -2289,7 +2289,7 @@ public RubyArray values_at(ThreadContext context, IRubyObject[] args) {

@JRubyMethod(name = "fetch_values", rest = true)
public RubyArray fetch_values(ThreadContext context, IRubyObject[] args, Block block) {
RubyArray result = RubyArray.newBlankArrayInternal(context.runtime, args.length);
RubyArray result = RubyArrayNative.newBlankArrayInternal(context.runtime, args.length);
for (int i = 0; i < args.length; i++) {
result.storeInternal(context, i, fetch(context, args[i], block));
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -4918,7 +4918,7 @@ public RubyArray constants(ThreadContext context, IRubyObject allConstants) {

private RubyArray<?> constantsCommon(ThreadContext context, boolean replaceModule, boolean allConstants) {
Collection<String> constantNames = constantsCommon(context.runtime, replaceModule, allConstants, false);
var array = RubyArray.newBlankArrayInternal(context.runtime, constantNames.size());
var array = RubyArrayNative.newBlankArrayInternal(context.runtime, constantNames.size());

int i = 0;
for (String name : constantNames) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyRegexp.java
Original file line number Diff line number Diff line change
Expand Up @@ -1581,7 +1581,7 @@ public IRubyObject named_captures(ThreadContext context) {
for (Iterator<NameEntry> i = pattern.namedBackrefIterator(); i.hasNext();) {
NameEntry e = i.next();
int[] backrefs = e.getBackRefs();
RubyArray ary = RubyArray.newBlankArrayInternal(context.runtime, backrefs.length);
RubyArray ary = RubyArrayNative.newBlankArrayInternal(context.runtime, backrefs.length);

for (int idx = 0; idx<backrefs.length; idx++) {
ary.storeInternal(context, idx, asFixnum(context, backrefs[idx]));
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyString.java
Original file line number Diff line number Diff line change
Expand Up @@ -5215,7 +5215,7 @@ private static IRubyObject scanOnce(ThreadContext context, RubyString str, IRuby
return RubyRegexp.nth_match(context, 0, match);
}
int size = match.numRegs();
RubyArray result = RubyArray.newBlankArrayInternal(context.runtime, size - 1);
RubyArrayNative result = RubyArrayNative.newBlankArrayInternal(context.runtime, size - 1);
for (int i = 1; i < size; i++) {
result.eltInternalSet(i - 1, RubyRegexp.nth_match(context, i, match));
}
Expand Down
9 changes: 9 additions & 0 deletions core/src/main/java/org/jruby/api/Create.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public static RubyArray<?> allocArray(ThreadContext context, int length) {
return RubyArray.newArray(context, length);
}

public static RubyArrayNative<?> allocNativeArray(ThreadContext context, int length) {
// note: this cannot be newBlankArray because packed arrays only exist fully populated.
return RubyArrayNative.newArray(context, length);
}

/**
* Create an empty array with a specific allocated size. This should be used to
* make an array where you think you know how big the array will be and you plan on
Expand All @@ -67,6 +72,10 @@ public static RubyArray<?> allocArray(ThreadContext context, long length) {
return allocArray(context, checkLength(context, length));
}

public static RubyArrayNative<?> allocNativeArray(ThreadContext context, long length) {
// note: this cannot be newBlankArray because packed arrays only exist fully populated.
return allocNativeArray(context, checkLength(context, length));
}

/**
* Create a new array with a single element.
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/ir/targets/JVMVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,8 @@ private void compileCallCommon(IRBytecodeAdapter m, CallBase call) {

if (args.length == 1 && args[0] instanceof Splat) {
visit(args[0]);
m.adapter.invokevirtual(p(RubyArray.class), "toJavaArray", sig(IRubyObject[].class));
m.loadContext();
m.adapter.invokevirtual(p(RubyArray.class), "toJavaArray", sig(IRubyObject[].class, ThreadContext.class));
arity = -1;
} else if (CallBase.containsArgSplat(args)) {
throw new NotCompilableException("splat in non-initial argument for normal call is unsupported in JIT");
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/javasupport/ext/JavaLang.java
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ public static IRubyObject java_instance_methods(final ThreadContext context, fin
// quick count for accurate size
int size = 0;
for (java.lang.reflect.Method method : publicMethods) if (!Modifier.isStatic(method.getModifiers())) size++;
final var methods = allocArray(context, size);
final var methods = allocNativeArray(context, size);

for (java.lang.reflect.Method method : publicMethods) {
if (!Modifier.isStatic(method.getModifiers())) methods.add(context, method);
Expand All @@ -550,7 +550,7 @@ public static IRubyObject declared_instance_methods(final ThreadContext context,
// quick count for accurate size
int size = 0;
for (java.lang.reflect.Method method : declaredMethods) if (!Modifier.isStatic(method.getModifiers())) size++;
final var methods = allocArray(context, size);
final var methods = allocNativeArray(context, size);

for (java.lang.reflect.Method method : declaredMethods) {
if (!Modifier.isStatic(method.getModifiers())) methods.add(context, method);
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/runtime/Helpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -2008,7 +2008,7 @@ public static IRubyObject aryOrToAry(ThreadContext context, IRubyObject value) {
@Deprecated(since = "9.2.0.0") // not used
public static IRubyObject aValueSplat(IRubyObject value) {
var context = ((RubyBasicObject) value).getCurrentContext();
if (!(value instanceof RubyArray array) || array.length().getValue() == 0) return context.nil;
if (!(value instanceof RubyArray array) || array.getLength() == 0) return context.nil;

return array.getLength() == 1 ? array.first(context) : array;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.jcodings.specific.USASCIIEncoding;
import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.RubyArrayNative;
import org.jruby.RubyClass;
import org.jruby.RubyString;
import org.jruby.javasupport.JavaUtil;
Expand Down Expand Up @@ -61,7 +62,7 @@ protected void finishUnpack(IRubyObject nil) {
}

@Override
public RubyArray<?> aryDup() {
public RubyArrayNative<?> aryDup() {
if (!packed()) return super.aryDup();
return new RubyArrayOneObject(getRuntime().getArray(), this);
}
Expand Down Expand Up @@ -104,7 +105,7 @@ public void copyInto(ThreadContext context, IRubyObject[] target, int start, int
}

@Override
protected RubyArray<?> dupImpl(Ruby runtime, RubyClass metaClass) {
protected RubyArrayNative<?> dupImpl(Ruby runtime, RubyClass metaClass) {
if (!packed()) return super.dupImpl(runtime, metaClass);
return new RubyArrayOneObject(metaClass, this);
}
Expand Down Expand Up @@ -268,7 +269,7 @@ public RubyArray<?> collectArray(ThreadContext context, Block block) {
}

@Override
protected RubyArray<?> makeShared() {
protected RubyArrayNative<?> makeShared() {
if (!packed()) return super.makeShared();

return new RubyArrayOneObject(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.RubyArrayNative;
import org.jruby.RubyClass;
import org.jruby.runtime.Helpers;
import org.jruby.runtime.ThreadContext;
Expand Down Expand Up @@ -39,7 +40,7 @@
* RubyArray{@link #toJavaArray(ThreadContext)}
* RubyArray{@link #uniq(org.jruby.runtime.ThreadContext)}
*/
public abstract class RubyArraySpecialized extends RubyArray {
public abstract class RubyArraySpecialized extends RubyArrayNative {
public static final int MAX_PACKED_SIZE = 2;

public RubyArraySpecialized(Ruby runtime, boolean light) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.jcodings.specific.USASCIIEncoding;
import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.RubyArrayNative;
import org.jruby.RubyClass;
import org.jruby.RubyComparable;
import org.jruby.RubyFixnum;
Expand Down Expand Up @@ -73,7 +74,7 @@ protected void finishUnpack(IRubyObject nil) {
}

@Override
public RubyArray<?> aryDup() {
public RubyArrayNative<?> aryDup() {
if (!packed()) return super.aryDup();
return new RubyArrayTwoObject(getRuntime().getArray(), this);
}
Expand Down Expand Up @@ -118,7 +119,7 @@ public void copyInto(ThreadContext context, IRubyObject[] target, int start, int
}

@Override
protected RubyArray<?> dupImpl(Ruby runtime, RubyClass metaClass) {
protected RubyArrayNative<?> dupImpl(Ruby runtime, RubyClass metaClass) {
if (!packed()) return super.dupImpl(runtime, metaClass);
return new RubyArrayTwoObject(metaClass, this);
}
Expand Down Expand Up @@ -313,7 +314,7 @@ public IRubyObject subseq(RubyClass metaClass, long beg, long len, boolean light

if (beg > 2 || beg < 0 || len < 0) return runtime.getNil();

if (len == 0 || beg == 2) return new RubyArray<>(runtime, metaClass, IRubyObject.NULL_ARRAY);
if (len == 0 || beg == 2) return RubyArray.newEmptyArray(runtime, metaClass);

if (beg == 0) {
if (len == 1) return new RubyArrayOneObject(metaClass, car);
Expand Down Expand Up @@ -379,7 +380,7 @@ public RubyArray<?> collectArray(ThreadContext context, Block block) {
}

@Override
protected RubyArray<?> makeShared() {
protected RubyArrayNative<?> makeShared() {
if (!packed()) return super.makeShared();

return new RubyArrayTwoObject(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.Set;
import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.RubyArrayNative;
import org.jruby.RubyBoolean;
import org.jruby.RubyString;
import org.jruby.runtime.Block;
Expand All @@ -45,7 +46,7 @@
/**
* An RubyArray that maintains an O(1) Set for fast include? operations.
*/
public class StringArraySet extends RubyArray {
public class StringArraySet extends RubyArrayNative {

private final Set<String> set;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void testAPIUsageTheNonGenericWay() { // before <T> generic signatures we
assertEquals("barbarbar", javaStr);

Object val = JavaEmbedUtils.rubyToJava(newEmptyArray(context));
assertEquals("org.jruby.RubyArray", val.getClass().getName());
assertEquals("org.jruby.RubyArrayNative", val.getClass().getName());
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion test/jruby/test_higher_javasupport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1886,7 +1886,7 @@ def test_callable_no_match_raised_errors
fail 'expected to raise'
rescue NameError => e
msg = e.message
assert msg.start_with?('no constructor for arguments (org.jruby.RubyArray) on Java::JavaLang::StringBuilder'), msg
assert msg.start_with?('no constructor for arguments (org.jruby.RubyArrayNative) on Java::JavaLang::StringBuilder'), msg
assert msg.index('available overloads'), msg
assert msg.index(' (int)'), msg
assert msg.index(' (java.lang.String)'), msg
Expand Down