Skip to content

Commit 4c9bcd9

Browse files
committed
Merge branch 'class_vars_overtaken' of github.com:enebo/jruby into class_vars_overtaken
2 parents 85ab4ab + 50eb82b commit 4c9bcd9

File tree

331 files changed

+2910
-1468
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

331 files changed

+2910
-1468
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9.4.7.0-SNAPSHOT
1+
9.4.8.0-SNAPSHOT

bin/ast

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def ir_setup(root)
191191
JRuby::IR.compiler_debug = true
192192

193193

194-
builder = org.jruby.ir.IRBuilder
194+
builder = org.jruby.ir.builder.IRBuilderAST
195195

196196
scope = builder.build_root(manager, root).scope
197197
scope.prepare_for_compilation

core/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ DO NOT MODIFY - GENERATED CODE
1212
<parent>
1313
<groupId>org.jruby</groupId>
1414
<artifactId>jruby-parent</artifactId>
15-
<version>9.4.7.0-SNAPSHOT</version>
15+
<version>9.4.8.0-SNAPSHOT</version>
1616
</parent>
1717
<artifactId>jruby-base</artifactId>
1818
<name>JRuby Base</name>
@@ -711,7 +711,7 @@ DO NOT MODIFY - GENERATED CODE
711711
<path>
712712
<groupId>org.jruby</groupId>
713713
<artifactId>jruby-base</artifactId>
714-
<version>9.4.7.0-SNAPSHOT</version>
714+
<version>9.4.8.0-SNAPSHOT</version>
715715
</path>
716716
</annotationProcessorPaths>
717717
</configuration>

core/src/main/java/org/jruby/RubyArray.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import java.io.IOException;
4242
import java.lang.reflect.Array;
4343
import java.math.BigInteger;
44-
import java.util.ArrayList;
4544
import java.util.Arrays;
4645
import java.util.BitSet;
4746
import java.util.Collection;
@@ -59,7 +58,6 @@
5958
import org.jruby.ast.util.ArgsUtil;
6059
import org.jruby.common.IRubyWarnings.ID;
6160
import org.jruby.exceptions.RaiseException;
62-
import org.jruby.exceptions.RangeError;
6361
import org.jruby.java.util.ArrayUtils;
6462
import org.jruby.javasupport.JavaUtil;
6563
import org.jruby.runtime.Arity;
@@ -1851,7 +1849,7 @@ protected IRubyObject inspectAry(ThreadContext context) {
18511849
} else {
18521850
EncodingUtils.encAssociateIndex(str, s.getEncoding());
18531851
}
1854-
str.cat19(s);
1852+
str.catWithCodeRange(s);
18551853
}
18561854
str.cat((byte) ']');
18571855

@@ -2088,7 +2086,7 @@ protected int joinStrings(RubyString sep, int max, RubyString result) {
20882086
for (i = 0; i < max; i++) {
20892087
IRubyObject val = eltInternal(i);
20902088
if (!(val instanceof RubyString)) break;
2091-
if (i > 0 && sep != null) result.cat19(sep);
2089+
if (i > 0 && sep != null) result.catWithCodeRange(sep);
20922090
result.append(val);
20932091
}
20942092
} catch (ArrayIndexOutOfBoundsException e) {
@@ -2106,7 +2104,7 @@ private RubyString joinAny(ThreadContext context, RubyString sep, int i, RubyStr
21062104
JavaSites.CheckedSites to_ary_checked = null;
21072105

21082106
for (; i < realLength; i++) {
2109-
if (i > 0 && sep != null) result.cat19(sep);
2107+
if (i > 0 && sep != null) result.catWithCodeRange(sep);
21102108

21112109
IRubyObject val = eltOk(i);
21122110

@@ -2137,7 +2135,7 @@ private RubyString joinAny(ThreadContext context, RubyString sep, int i, RubyStr
21372135

21382136
// MRI: ary_join_1, str_join label
21392137
private static void strJoin(RubyString result, RubyString val, boolean[] first) {
2140-
result.cat19(val);
2138+
result.catWithCodeRange(val);
21412139
if (first[0]) {
21422140
result.setEncoding(val.getEncoding());
21432141
first[0] = false;

core/src/main/java/org/jruby/RubyBignum.java

Lines changed: 35 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
import org.jruby.runtime.marshal.MarshalStream;
5151
import org.jruby.runtime.marshal.UnmarshalStream;
5252

53+
import static org.jruby.RubyFixnum.zero;
54+
5355
/**
5456
*
5557
* @author jpetersen
@@ -230,9 +232,9 @@ public static double big2dbl(RubyBignum val) {
230232
}
231233

232234
private RubyFixnum checkShiftDown(ThreadContext context, RubyBignum other) {
233-
if (other.value.signum() == 0) return RubyFixnum.zero(context.runtime);
235+
if (other.value.signum() == 0) return zero(context.runtime);
234236
if (value.compareTo(LONG_MIN) < 0 || value.compareTo(LONG_MAX) > 0) {
235-
return other.value.signum() >= 0 ? RubyFixnum.zero(context.runtime) : RubyFixnum.minus_one(context.runtime);
237+
return other.value.signum() >= 0 ? zero(context.runtime) : RubyFixnum.minus_one(context.runtime);
236238
}
237239
return null;
238240
}
@@ -338,47 +340,30 @@ public IRubyObject truncate(ThreadContext context, IRubyObject arg){
338340
@Override
339341
public RubyArray digits(ThreadContext context, IRubyObject base) {
340342
BigInteger self = value;
341-
Ruby runtime = context.runtime;
342-
if (self.compareTo(BigInteger.ZERO) == -1) {
343-
throw runtime.newMathDomainError("out of domain");
344-
}
345-
if (!(base instanceof RubyInteger)) {
346-
try {
347-
base = base.convertToInteger();
348-
} catch (ClassCastException e) {
349-
String cname = getMetaClass(base).getRealClass().getName();
350-
throw runtime.newTypeError("wrong argument type " + cname + " (expected Integer)");
351-
}
352-
}
353343

354-
BigInteger bigBase;
355-
if (base instanceof RubyBignum) {
356-
bigBase = ((RubyBignum) base).value;
357-
} else {
358-
bigBase = long2big( ((RubyFixnum) base).value );
359-
}
344+
if (self.compareTo(BigInteger.ZERO) == -1) throw context.runtime.newMathDomainError("out of domain");
360345

361-
if (bigBase.signum() == -1) {
362-
throw runtime.newArgumentError("negative radix");
363-
}
364-
if (bigBase.compareTo(BigInteger.valueOf(2)) == -1) {
365-
throw runtime.newArgumentError("invalid radix: " + bigBase);
366-
}
346+
base = base.convertToInteger();
367347

368-
RubyArray res = RubyArray.newArray(context.runtime, 0);
348+
BigInteger bigBase = base instanceof RubyBignum ?
349+
((RubyBignum) base).value : long2big(((RubyFixnum) base).value);
350+
351+
if (bigBase.signum() == -1) throw context.runtime.newArgumentError("negative radix");
352+
if (bigBase.compareTo(BigInteger.valueOf(2)) == -1) throw context.runtime.newArgumentError("invalid radix: " + bigBase);
369353

370354
if (self.signum() == 0) {
371-
res.append(RubyFixnum.newFixnum(context.getRuntime(), 0));
372-
return res;
373-
}
355+
return RubyArray.newArray(context.runtime, zero(context.runtime));
356+
} else {
357+
RubyArray res = RubyArray.newArray(context.runtime, 0);
374358

375-
while (self.signum() > 0) {
376-
BigInteger q = self.mod(bigBase);
377-
res.append(RubyBignum.newBignum(context.getRuntime(), q));
378-
self = self.divide(bigBase);
379-
}
359+
while (self.signum() > 0) {
360+
BigInteger q = self.mod(bigBase);
361+
res.append(RubyBignum.newBignum(context.runtime, q));
362+
self = self.divide(bigBase);
363+
}
380364

381-
return res;
365+
return res;
366+
}
382367
}
383368

384369
/** rb_big_to_s
@@ -742,11 +727,11 @@ public final IRubyObject quo19(ThreadContext context, IRubyObject other) {
742727
@JRubyMethod(name = {"**", "power"})
743728
public IRubyObject op_pow(ThreadContext context, IRubyObject other) {
744729
Ruby runtime = context.runtime;
745-
if (other == RubyFixnum.zero(runtime)) return RubyFixnum.one(runtime);
730+
if (other == zero(runtime)) return RubyFixnum.one(runtime);
746731
final double d;
747732
if (other instanceof RubyFloat) {
748733
d = ((RubyFloat) other).value;
749-
if (compareTo(RubyFixnum.zero(runtime)) == -1 && d != Math.round(d)) {
734+
if (compareTo(zero(runtime)) == -1 && d != Math.round(d)) {
750735
RubyComplex complex = RubyComplex.newComplexRaw(context.runtime, this);
751736
return sites(context).op_exp.call(context, complex, complex, other);
752737
}
@@ -894,7 +879,7 @@ public IRubyObject op_lshift(ThreadContext context, IRubyObject other) {
894879
if (shift < 0) {
895880
if (value.bitLength() <= -shift ) {
896881
if (value.signum() >= 0) {
897-
return RubyFixnum.zero(context.runtime);
882+
return zero(context.runtime);
898883
} else {
899884
return RubyFixnum.minus_one(context.runtime);
900885
}
@@ -903,7 +888,7 @@ public IRubyObject op_lshift(ThreadContext context, IRubyObject other) {
903888
break;
904889
} else if (other instanceof RubyBignum) {
905890
if (value.signum() == 0) {
906-
return RubyFixnum.zero(context.runtime);
891+
return zero(context.runtime);
907892
}
908893

909894
RubyBignum otherBignum = (RubyBignum) other;
@@ -928,7 +913,7 @@ public IRubyObject op_lshift(ThreadContext context, IRubyObject other) {
928913
@Override
929914
public RubyInteger op_lshift(ThreadContext context, long shift) {
930915
if (value.signum() == 0) {
931-
return RubyFixnum.zero(context.runtime);
916+
return zero(context.runtime);
932917
}
933918

934919
if (shift > Integer.MAX_VALUE) {
@@ -950,15 +935,15 @@ public IRubyObject op_rshift(ThreadContext context, IRubyObject other) {
950935
shift = ((RubyFixnum) other).value;
951936
if (value.bitLength() <= shift ) {
952937
if (value.signum() >= 0) {
953-
return RubyFixnum.zero(context.runtime);
938+
return zero(context.runtime);
954939
} else {
955940
return RubyFixnum.minus_one(context.runtime);
956941
}
957942
}
958943
break;
959944
} else if (other instanceof RubyBignum) {
960945
if (value == BigInteger.ZERO) {
961-
return RubyFixnum.zero(context.runtime);
946+
return zero(context.runtime);
962947
}
963948

964949
RubyBignum otherBignum = (RubyBignum) other;
@@ -983,7 +968,7 @@ public IRubyObject op_rshift(ThreadContext context, IRubyObject other) {
983968
@Override
984969
public RubyInteger op_rshift(ThreadContext context, long shift) {
985970
if (value.signum() == 0) {
986-
return RubyFixnum.zero(context.runtime);
971+
return zero(context.runtime);
987972
}
988973

989974
if (shift < Integer.MIN_VALUE) {
@@ -1014,17 +999,17 @@ protected IRubyObject op_aref_subclass(ThreadContext context, IRubyObject other)
1014999
if (other instanceof RubyBignum) {
10151000
// '!=' for negative value
10161001
if ((((RubyBignum) other).value.signum() >= 0) != (value.signum() == -1)) {
1017-
return RubyFixnum.zero(context.runtime);
1002+
return zero(context.runtime);
10181003
}
10191004
return RubyFixnum.one(context.runtime);
10201005
}
10211006
}
10221007
long position = num2long(other);
10231008
if (position < 0 || position > Integer.MAX_VALUE) {
1024-
return RubyFixnum.zero(context.runtime);
1009+
return zero(context.runtime);
10251010
}
10261011

1027-
return value.testBit((int)position) ? RubyFixnum.one(context.runtime) : RubyFixnum.zero(context.runtime);
1012+
return value.testBit((int)position) ? RubyFixnum.one(context.runtime) : zero(context.runtime);
10281013
}
10291014

10301015
private enum BIGNUM_OP_T {
@@ -1132,7 +1117,7 @@ private IRubyObject float_cmp(ThreadContext context, RubyFloat y) {
11321117
yf = yd - yi;
11331118

11341119
IRubyObject rel = op_cmp(context, newBignorm(runtime, yi));
1135-
if (yf == 0.0 || !rel.equals(RubyFixnum.zero(runtime))) {
1120+
if (yf == 0.0 || !rel.equals(zero(runtime))) {
11361121
return rel;
11371122
}
11381123
if (yf < 0.0) {
@@ -1386,7 +1371,7 @@ public IRubyObject isNegative(ThreadContext context) {
13861371
if (op_lt_site.isBuiltin(metaClass)) {
13871372
return RubyBoolean.newBoolean(context, value.signum() < 0);
13881373
}
1389-
return op_lt_site.call(context, this, this, RubyFixnum.zero(context.runtime));
1374+
return op_lt_site.call(context, this, this, zero(context.runtime));
13901375
}
13911376

13921377
@Override
@@ -1395,7 +1380,7 @@ public IRubyObject isPositive(ThreadContext context) {
13951380
if (op_gt_site.isBuiltin(metaClass)) {
13961381
return RubyBoolean.newBoolean(context, value.signum() > 0);
13971382
}
1398-
return op_gt_site.call(context, this, this, RubyFixnum.zero(context.runtime));
1383+
return op_gt_site.call(context, this, this, zero(context.runtime));
13991384
}
14001385

14011386
@Override

core/src/main/java/org/jruby/RubyClass.java

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,50 +1401,56 @@ public synchronized void reify(String classDumpDir, boolean useChildLoader) {
14011401
boolean[] java_box = { false };
14021402
// re-check reifiable in case another reify call has jumped in ahead of us
14031403
if (!isReifiable(java_box)) return;
1404-
final boolean concreteExt = java_box[0];
1405-
1406-
// calculate an appropriate name, for anonymous using inspect like format e.g. "Class:0x628fad4a"
1407-
final String name = getBaseName() != null ? getName() :
1408-
( "Class_0x" + Integer.toHexString(System.identityHashCode(this)) );
1409-
1410-
final String javaName = "rubyobj." + StringSupport.replaceAll(name, "::", ".");
1411-
final String javaPath = "rubyobj/" + StringSupport.replaceAll(name, "::", "/");
1404+
final boolean concreteExt = java_box[0];
14121405

14131406
final Class<?> parentReified = superClass.getRealClass().getReifiedClass();
14141407
if (parentReified == null) {
14151408
throw getClassRuntime().newTypeError(getName() + "'s parent class is not yet reified");
14161409
}
14171410

1418-
Class reifiedParent = RubyObject.class;
1419-
if (superClass.reifiedClass != null) reifiedParent = superClass.reifiedClass;
1420-
1421-
Reificator reifier;
1422-
if (concreteExt) {
1423-
reifier = new ConcreteJavaReifier(parentReified, javaName, javaPath);
1424-
} else {
1425-
reifier = new MethodReificator(reifiedParent, javaName, javaPath, null, javaPath);
1426-
}
1427-
1428-
final byte[] classBytes = reifier.reify();
1429-
1430-
final ClassDefiningClassLoader parentCL;
1411+
ClassDefiningClassLoader classLoader; // usually parent's class-loader
14311412
if (parentReified.getClassLoader() instanceof OneShotClassLoader) {
1432-
parentCL = (OneShotClassLoader) parentReified.getClassLoader();
1413+
classLoader = (OneShotClassLoader) parentReified.getClassLoader();
14331414
} else {
14341415
if (useChildLoader) {
14351416
MultiClassLoader parentLoader = new MultiClassLoader(runtime.getJRubyClassLoader());
14361417
for(Loader cLoader : runtime.getInstanceConfig().getExtraLoaders()) {
14371418
parentLoader.addClassLoader(cLoader.getClassLoader());
14381419
}
1439-
parentCL = new OneShotClassLoader(parentLoader);
1420+
classLoader = new OneShotClassLoader(parentLoader);
14401421
} else {
1441-
parentCL = runtime.getJRubyClassLoader();
1422+
classLoader = runtime.getJRubyClassLoader();
14421423
}
14431424
}
1425+
1426+
String javaName = getReifiedJavaClassName();
1427+
// *might* need to include a Class identifier in the Java class name, since a Ruby class might be dropped
1428+
// (using remove_const) and re-created in which case using the same name would cause a conflict...
1429+
if (classLoader.hasDefinedClass(javaName)) { // as Ruby class dropping is "unusual" - assume v0 to be the raw name
1430+
String versionedName; int v = 1;
1431+
// NOTE: '@' is not supported in Ruby class names thus it's safe to use as a "separator"
1432+
do {
1433+
versionedName = javaName + "@v" + (v++); // rubyobj.SomeModule.Foo@v1
1434+
} while (classLoader.hasDefinedClass(versionedName));
1435+
javaName = versionedName;
1436+
}
1437+
final String javaPath = javaName.replace('.', '/');
1438+
1439+
Reificator reifier;
1440+
if (concreteExt) {
1441+
reifier = new ConcreteJavaReifier(parentReified, javaName, javaPath);
1442+
} else {
1443+
Class<?> reifiedParent = superClass.reifiedClass;
1444+
if (reifiedParent == null) reifiedParent = RubyObject.class;
1445+
reifier = new MethodReificator(reifiedParent, javaName, javaPath, null, javaPath);
1446+
}
1447+
1448+
final byte[] classBytes = reifier.reify();
1449+
14441450
boolean nearEnd = false;
14451451
// Attempt to load the name we plan to use; skip reification if it exists already (see #1229).
14461452
try {
1447-
Class result = parentCL.defineClass(javaName, classBytes);
1453+
Class result = classLoader.defineClass(javaName, classBytes);
14481454
dumpReifiedClass(classDumpDir, javaPath, classBytes);
14491455

14501456
//Trigger initilization
@@ -1496,6 +1502,15 @@ public synchronized void reify(String classDumpDir, boolean useChildLoader) {
14961502
}
14971503
}
14981504

1505+
private String getReifiedJavaClassName() {
1506+
final String basePackagePrefix = "rubyobj.";
1507+
if (getBaseName() == null) { // anonymous Class instance: rubyobj.Class$0x1234abcd
1508+
return basePackagePrefix + anonymousMetaNameWithIdentifier().replace(':', '$');
1509+
}
1510+
final CharSequence name = StringSupport.replaceAll(getName(), "::", ".");
1511+
return basePackagePrefix + name; // TheFoo::Bar -> rubyobj.TheFoo.Bar
1512+
}
1513+
14991514
interface Reificator {
15001515
byte[] reify();
15011516
} // interface Reificator

core/src/main/java/org/jruby/RubyConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,12 @@ public IRubyObject primitive_convert(ThreadContext context, IRubyObject[] args)
287287
inBytes = new ByteList();
288288
} else {
289289
input = args[0].convertToString();
290-
input.modify19();
290+
input.modifyAndClearCodeRange();
291291
inBytes = input.getByteList();
292292
}
293293

294294
output = args[1].convertToString();
295-
output.modify19();
295+
output.modifyAndClearCodeRange();
296296
outBytes = output.getByteList();
297297

298298
Ptr inPtr = new Ptr();

0 commit comments

Comments
 (0)