Skip to content

Commit

Permalink
Merge branch 'class_vars_overtaken' of github.com:enebo/jruby into cl…
Browse files Browse the repository at this point in the history
…ass_vars_overtaken
  • Loading branch information
enebo committed Apr 30, 2024
2 parents 85ab4ab + 50eb82b commit 4c9bcd9
Show file tree
Hide file tree
Showing 331 changed files with 2,910 additions and 1,468 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9.4.7.0-SNAPSHOT
9.4.8.0-SNAPSHOT
2 changes: 1 addition & 1 deletion bin/ast
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def ir_setup(root)
JRuby::IR.compiler_debug = true


builder = org.jruby.ir.IRBuilder
builder = org.jruby.ir.builder.IRBuilderAST

scope = builder.build_root(manager, root).scope
scope.prepare_for_compilation
Expand Down
4 changes: 2 additions & 2 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ DO NOT MODIFY - GENERATED CODE
<parent>
<groupId>org.jruby</groupId>
<artifactId>jruby-parent</artifactId>
<version>9.4.7.0-SNAPSHOT</version>
<version>9.4.8.0-SNAPSHOT</version>
</parent>
<artifactId>jruby-base</artifactId>
<name>JRuby Base</name>
Expand Down Expand Up @@ -711,7 +711,7 @@ DO NOT MODIFY - GENERATED CODE
<path>
<groupId>org.jruby</groupId>
<artifactId>jruby-base</artifactId>
<version>9.4.7.0-SNAPSHOT</version>
<version>9.4.8.0-SNAPSHOT</version>
</path>
</annotationProcessorPaths>
</configuration>
Expand Down
10 changes: 4 additions & 6 deletions core/src/main/java/org/jruby/RubyArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import java.io.IOException;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collection;
Expand All @@ -59,7 +58,6 @@
import org.jruby.ast.util.ArgsUtil;
import org.jruby.common.IRubyWarnings.ID;
import org.jruby.exceptions.RaiseException;
import org.jruby.exceptions.RangeError;
import org.jruby.java.util.ArrayUtils;
import org.jruby.javasupport.JavaUtil;
import org.jruby.runtime.Arity;
Expand Down Expand Up @@ -1851,7 +1849,7 @@ protected IRubyObject inspectAry(ThreadContext context) {
} else {
EncodingUtils.encAssociateIndex(str, s.getEncoding());
}
str.cat19(s);
str.catWithCodeRange(s);
}
str.cat((byte) ']');

Expand Down Expand Up @@ -2088,7 +2086,7 @@ protected int joinStrings(RubyString sep, int max, RubyString result) {
for (i = 0; i < max; i++) {
IRubyObject val = eltInternal(i);
if (!(val instanceof RubyString)) break;
if (i > 0 && sep != null) result.cat19(sep);
if (i > 0 && sep != null) result.catWithCodeRange(sep);
result.append(val);
}
} catch (ArrayIndexOutOfBoundsException e) {
Expand All @@ -2106,7 +2104,7 @@ private RubyString joinAny(ThreadContext context, RubyString sep, int i, RubyStr
JavaSites.CheckedSites to_ary_checked = null;

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

IRubyObject val = eltOk(i);

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

// MRI: ary_join_1, str_join label
private static void strJoin(RubyString result, RubyString val, boolean[] first) {
result.cat19(val);
result.catWithCodeRange(val);
if (first[0]) {
result.setEncoding(val.getEncoding());
first[0] = false;
Expand Down
85 changes: 35 additions & 50 deletions core/src/main/java/org/jruby/RubyBignum.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
import org.jruby.runtime.marshal.MarshalStream;
import org.jruby.runtime.marshal.UnmarshalStream;

import static org.jruby.RubyFixnum.zero;

/**
*
* @author jpetersen
Expand Down Expand Up @@ -230,9 +232,9 @@ public static double big2dbl(RubyBignum val) {
}

private RubyFixnum checkShiftDown(ThreadContext context, RubyBignum other) {
if (other.value.signum() == 0) return RubyFixnum.zero(context.runtime);
if (other.value.signum() == 0) return zero(context.runtime);
if (value.compareTo(LONG_MIN) < 0 || value.compareTo(LONG_MAX) > 0) {
return other.value.signum() >= 0 ? RubyFixnum.zero(context.runtime) : RubyFixnum.minus_one(context.runtime);
return other.value.signum() >= 0 ? zero(context.runtime) : RubyFixnum.minus_one(context.runtime);
}
return null;
}
Expand Down Expand Up @@ -338,47 +340,30 @@ public IRubyObject truncate(ThreadContext context, IRubyObject arg){
@Override
public RubyArray digits(ThreadContext context, IRubyObject base) {
BigInteger self = value;
Ruby runtime = context.runtime;
if (self.compareTo(BigInteger.ZERO) == -1) {
throw runtime.newMathDomainError("out of domain");
}
if (!(base instanceof RubyInteger)) {
try {
base = base.convertToInteger();
} catch (ClassCastException e) {
String cname = getMetaClass(base).getRealClass().getName();
throw runtime.newTypeError("wrong argument type " + cname + " (expected Integer)");
}
}

BigInteger bigBase;
if (base instanceof RubyBignum) {
bigBase = ((RubyBignum) base).value;
} else {
bigBase = long2big( ((RubyFixnum) base).value );
}
if (self.compareTo(BigInteger.ZERO) == -1) throw context.runtime.newMathDomainError("out of domain");

if (bigBase.signum() == -1) {
throw runtime.newArgumentError("negative radix");
}
if (bigBase.compareTo(BigInteger.valueOf(2)) == -1) {
throw runtime.newArgumentError("invalid radix: " + bigBase);
}
base = base.convertToInteger();

RubyArray res = RubyArray.newArray(context.runtime, 0);
BigInteger bigBase = base instanceof RubyBignum ?
((RubyBignum) base).value : long2big(((RubyFixnum) base).value);

if (bigBase.signum() == -1) throw context.runtime.newArgumentError("negative radix");
if (bigBase.compareTo(BigInteger.valueOf(2)) == -1) throw context.runtime.newArgumentError("invalid radix: " + bigBase);

if (self.signum() == 0) {
res.append(RubyFixnum.newFixnum(context.getRuntime(), 0));
return res;
}
return RubyArray.newArray(context.runtime, zero(context.runtime));
} else {
RubyArray res = RubyArray.newArray(context.runtime, 0);

while (self.signum() > 0) {
BigInteger q = self.mod(bigBase);
res.append(RubyBignum.newBignum(context.getRuntime(), q));
self = self.divide(bigBase);
}
while (self.signum() > 0) {
BigInteger q = self.mod(bigBase);
res.append(RubyBignum.newBignum(context.runtime, q));
self = self.divide(bigBase);
}

return res;
return res;
}
}

/** rb_big_to_s
Expand Down Expand Up @@ -742,11 +727,11 @@ public final IRubyObject quo19(ThreadContext context, IRubyObject other) {
@JRubyMethod(name = {"**", "power"})
public IRubyObject op_pow(ThreadContext context, IRubyObject other) {
Ruby runtime = context.runtime;
if (other == RubyFixnum.zero(runtime)) return RubyFixnum.one(runtime);
if (other == zero(runtime)) return RubyFixnum.one(runtime);
final double d;
if (other instanceof RubyFloat) {
d = ((RubyFloat) other).value;
if (compareTo(RubyFixnum.zero(runtime)) == -1 && d != Math.round(d)) {
if (compareTo(zero(runtime)) == -1 && d != Math.round(d)) {
RubyComplex complex = RubyComplex.newComplexRaw(context.runtime, this);
return sites(context).op_exp.call(context, complex, complex, other);
}
Expand Down Expand Up @@ -894,7 +879,7 @@ public IRubyObject op_lshift(ThreadContext context, IRubyObject other) {
if (shift < 0) {
if (value.bitLength() <= -shift ) {
if (value.signum() >= 0) {
return RubyFixnum.zero(context.runtime);
return zero(context.runtime);
} else {
return RubyFixnum.minus_one(context.runtime);
}
Expand All @@ -903,7 +888,7 @@ public IRubyObject op_lshift(ThreadContext context, IRubyObject other) {
break;
} else if (other instanceof RubyBignum) {
if (value.signum() == 0) {
return RubyFixnum.zero(context.runtime);
return zero(context.runtime);
}

RubyBignum otherBignum = (RubyBignum) other;
Expand All @@ -928,7 +913,7 @@ public IRubyObject op_lshift(ThreadContext context, IRubyObject other) {
@Override
public RubyInteger op_lshift(ThreadContext context, long shift) {
if (value.signum() == 0) {
return RubyFixnum.zero(context.runtime);
return zero(context.runtime);
}

if (shift > Integer.MAX_VALUE) {
Expand All @@ -950,15 +935,15 @@ public IRubyObject op_rshift(ThreadContext context, IRubyObject other) {
shift = ((RubyFixnum) other).value;
if (value.bitLength() <= shift ) {
if (value.signum() >= 0) {
return RubyFixnum.zero(context.runtime);
return zero(context.runtime);
} else {
return RubyFixnum.minus_one(context.runtime);
}
}
break;
} else if (other instanceof RubyBignum) {
if (value == BigInteger.ZERO) {
return RubyFixnum.zero(context.runtime);
return zero(context.runtime);
}

RubyBignum otherBignum = (RubyBignum) other;
Expand All @@ -983,7 +968,7 @@ public IRubyObject op_rshift(ThreadContext context, IRubyObject other) {
@Override
public RubyInteger op_rshift(ThreadContext context, long shift) {
if (value.signum() == 0) {
return RubyFixnum.zero(context.runtime);
return zero(context.runtime);
}

if (shift < Integer.MIN_VALUE) {
Expand Down Expand Up @@ -1014,17 +999,17 @@ protected IRubyObject op_aref_subclass(ThreadContext context, IRubyObject other)
if (other instanceof RubyBignum) {
// '!=' for negative value
if ((((RubyBignum) other).value.signum() >= 0) != (value.signum() == -1)) {
return RubyFixnum.zero(context.runtime);
return zero(context.runtime);
}
return RubyFixnum.one(context.runtime);
}
}
long position = num2long(other);
if (position < 0 || position > Integer.MAX_VALUE) {
return RubyFixnum.zero(context.runtime);
return zero(context.runtime);
}

return value.testBit((int)position) ? RubyFixnum.one(context.runtime) : RubyFixnum.zero(context.runtime);
return value.testBit((int)position) ? RubyFixnum.one(context.runtime) : zero(context.runtime);
}

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

IRubyObject rel = op_cmp(context, newBignorm(runtime, yi));
if (yf == 0.0 || !rel.equals(RubyFixnum.zero(runtime))) {
if (yf == 0.0 || !rel.equals(zero(runtime))) {
return rel;
}
if (yf < 0.0) {
Expand Down Expand Up @@ -1386,7 +1371,7 @@ public IRubyObject isNegative(ThreadContext context) {
if (op_lt_site.isBuiltin(metaClass)) {
return RubyBoolean.newBoolean(context, value.signum() < 0);
}
return op_lt_site.call(context, this, this, RubyFixnum.zero(context.runtime));
return op_lt_site.call(context, this, this, zero(context.runtime));
}

@Override
Expand All @@ -1395,7 +1380,7 @@ public IRubyObject isPositive(ThreadContext context) {
if (op_gt_site.isBuiltin(metaClass)) {
return RubyBoolean.newBoolean(context, value.signum() > 0);
}
return op_gt_site.call(context, this, this, RubyFixnum.zero(context.runtime));
return op_gt_site.call(context, this, this, zero(context.runtime));
}

@Override
Expand Down
65 changes: 40 additions & 25 deletions core/src/main/java/org/jruby/RubyClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -1401,50 +1401,56 @@ public synchronized void reify(String classDumpDir, boolean useChildLoader) {
boolean[] java_box = { false };
// re-check reifiable in case another reify call has jumped in ahead of us
if (!isReifiable(java_box)) return;
final boolean concreteExt = java_box[0];

// calculate an appropriate name, for anonymous using inspect like format e.g. "Class:0x628fad4a"
final String name = getBaseName() != null ? getName() :
( "Class_0x" + Integer.toHexString(System.identityHashCode(this)) );

final String javaName = "rubyobj." + StringSupport.replaceAll(name, "::", ".");
final String javaPath = "rubyobj/" + StringSupport.replaceAll(name, "::", "/");
final boolean concreteExt = java_box[0];

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

Class reifiedParent = RubyObject.class;
if (superClass.reifiedClass != null) reifiedParent = superClass.reifiedClass;

Reificator reifier;
if (concreteExt) {
reifier = new ConcreteJavaReifier(parentReified, javaName, javaPath);
} else {
reifier = new MethodReificator(reifiedParent, javaName, javaPath, null, javaPath);
}

final byte[] classBytes = reifier.reify();

final ClassDefiningClassLoader parentCL;
ClassDefiningClassLoader classLoader; // usually parent's class-loader
if (parentReified.getClassLoader() instanceof OneShotClassLoader) {
parentCL = (OneShotClassLoader) parentReified.getClassLoader();
classLoader = (OneShotClassLoader) parentReified.getClassLoader();
} else {
if (useChildLoader) {
MultiClassLoader parentLoader = new MultiClassLoader(runtime.getJRubyClassLoader());
for(Loader cLoader : runtime.getInstanceConfig().getExtraLoaders()) {
parentLoader.addClassLoader(cLoader.getClassLoader());
}
parentCL = new OneShotClassLoader(parentLoader);
classLoader = new OneShotClassLoader(parentLoader);
} else {
parentCL = runtime.getJRubyClassLoader();
classLoader = runtime.getJRubyClassLoader();
}
}

String javaName = getReifiedJavaClassName();
// *might* need to include a Class identifier in the Java class name, since a Ruby class might be dropped
// (using remove_const) and re-created in which case using the same name would cause a conflict...
if (classLoader.hasDefinedClass(javaName)) { // as Ruby class dropping is "unusual" - assume v0 to be the raw name
String versionedName; int v = 1;
// NOTE: '@' is not supported in Ruby class names thus it's safe to use as a "separator"
do {
versionedName = javaName + "@v" + (v++); // rubyobj.SomeModule.Foo@v1
} while (classLoader.hasDefinedClass(versionedName));
javaName = versionedName;
}
final String javaPath = javaName.replace('.', '/');

Reificator reifier;
if (concreteExt) {
reifier = new ConcreteJavaReifier(parentReified, javaName, javaPath);
} else {
Class<?> reifiedParent = superClass.reifiedClass;
if (reifiedParent == null) reifiedParent = RubyObject.class;
reifier = new MethodReificator(reifiedParent, javaName, javaPath, null, javaPath);
}

final byte[] classBytes = reifier.reify();

boolean nearEnd = false;
// Attempt to load the name we plan to use; skip reification if it exists already (see #1229).
try {
Class result = parentCL.defineClass(javaName, classBytes);
Class result = classLoader.defineClass(javaName, classBytes);
dumpReifiedClass(classDumpDir, javaPath, classBytes);

//Trigger initilization
Expand Down Expand Up @@ -1496,6 +1502,15 @@ public synchronized void reify(String classDumpDir, boolean useChildLoader) {
}
}

private String getReifiedJavaClassName() {
final String basePackagePrefix = "rubyobj.";
if (getBaseName() == null) { // anonymous Class instance: rubyobj.Class$0x1234abcd
return basePackagePrefix + anonymousMetaNameWithIdentifier().replace(':', '$');
}
final CharSequence name = StringSupport.replaceAll(getName(), "::", ".");
return basePackagePrefix + name; // TheFoo::Bar -> rubyobj.TheFoo.Bar
}

interface Reificator {
byte[] reify();
} // interface Reificator
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubyConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,12 @@ public IRubyObject primitive_convert(ThreadContext context, IRubyObject[] args)
inBytes = new ByteList();
} else {
input = args[0].convertToString();
input.modify19();
input.modifyAndClearCodeRange();
inBytes = input.getByteList();
}

output = args[1].convertToString();
output.modify19();
output.modifyAndClearCodeRange();
outBytes = output.getByteList();

Ptr inPtr = new Ptr();
Expand Down

0 comments on commit 4c9bcd9

Please sign in to comment.