Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/9.5-dev' into remove_remaining_v…
Browse files Browse the repository at this point in the history
…ersion_methods
  • Loading branch information
headius committed Mar 27, 2024
2 parents 725379c + c60310f commit 632617f
Show file tree
Hide file tree
Showing 2,635 changed files with 139,181 additions and 115,032 deletions.
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
2 changes: 1 addition & 1 deletion core/pom.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

jar 'org.jruby.joni:joni:2.2.1'
jar 'org.jruby.jcodings:jcodings:1.0.58'
jar 'org.jruby:dirgra:0.3'
jar 'org.jruby:dirgra:0.5'

jar 'com.headius:invokebinder:1.13'
jar 'com.headius:options:1.6'
Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ DO NOT MODIFY - GENERATED CODE
<dependency>
<groupId>org.jruby</groupId>
<artifactId>dirgra</artifactId>
<version>0.3</version>
<version>0.5</version>
</dependency>
<dependency>
<groupId>com.headius</groupId>
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/ObjectFlags.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public interface ObjectFlags {
int IS_OVERLAID_F = registry.newFlag(RubyModule.class);
int OMOD_SHARED = registry.newFlag(RubyModule.class);
int INCLUDED_INTO_REFINEMENT = registry.newFlag(RubyModule.class);
int TEMPORARY_NAME = registry.newFlag(RubyModule.class);

int CR_7BIT_F = registry.newFlag(RubyString.class);
int CR_VALID_F = registry.newFlag(RubyString.class);
Expand Down
92 changes: 71 additions & 21 deletions core/src/main/java/org/jruby/RubyBasicObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,10 @@ private static void initCopy(ThreadContext context, IRubyObject clone, IRubyObje

original.copySpecialInstanceVariables(clone);

if (original.hasVariables()) clone.syncVariables(original);
if (original.hasVariables()) {
clone.syncVariables(original);
((RubyBasicObject) clone).dupFinalizer();
}
if (original instanceof RubyModule) {
RubyModule cloneMod = (RubyModule)clone;
cloneMod.syncConstants((RubyModule)original);
Expand Down Expand Up @@ -897,19 +900,16 @@ public IRubyObject rbClone(ThreadContext context, IRubyObject maybeOpts) {
return rbCloneInternal(context, kwfreeze);
}

// freeze (false, true, nil)
private RubyBasicObject rbCloneInternal(ThreadContext context, IRubyObject freeze) {

// MRI: immutable_obj_clone
if (isSpecialObject()) {
final Ruby runtime = context.runtime;
if (freeze == runtime.getFalse()) throw runtime.newArgumentError(str(runtime, "can't unfreeze ", types(runtime, getType())));
// MRI: rb_dup_setup
protected RubyBasicObject dupSetup(ThreadContext context, RubyBasicObject dup) {
initCopy(context, dup, this);
sites(context).initialize_dup.call(context, dup, dup, this);

return this;
}
return dup;
}

// We're cloning ourselves, so we know the result should be a RubyObject
RubyBasicObject clone = (RubyBasicObject) metaClass.getRealClass().allocate();
// MRI: rb_clone_setup
protected RubyBasicObject cloneSetup(ThreadContext context, RubyBasicObject clone, IRubyObject freeze) {
clone.setMetaClass(getSingletonClassCloneAndAttach(clone));

initCopy(context, clone, this);
Expand All @@ -930,6 +930,24 @@ private RubyBasicObject rbCloneInternal(ThreadContext context, IRubyObject freez
}


// freeze (false, true, nil)
private RubyBasicObject rbCloneInternal(ThreadContext context, IRubyObject freeze) {

// MRI: immutable_obj_clone
if (isSpecialObject()) {
final Ruby runtime = context.runtime;
if (freeze == runtime.getFalse()) throw runtime.newArgumentError(str(runtime, "can't unfreeze ", types(runtime, getType())));

return this;
}

// We're cloning ourselves, so we know the result should be a RubyObject
RubyBasicObject clone = (RubyBasicObject) metaClass.getRealClass().allocate();

return cloneSetup(context, clone, freeze);
}


protected RubyClass getSingletonClassClone() {
return getSingletonClassCloneAndAttach(null);
}
Expand Down Expand Up @@ -1226,14 +1244,7 @@ public boolean eql(IRubyObject other) {
public void addFinalizer(IRubyObject f) {
Finalizer finalizer = (Finalizer) getInternalVariable("__finalizer__");
if (finalizer == null) {
// since this is the first time we're registering a finalizer, we
// must also register this object in ObjectSpace, so that future
// calls to undefine_finalizer, which takes an object symbol, can
// locate the object properly. See JRUBY-4839.
long id = getObjectId();
IRubyObject fixnumId = id();

getRuntime().getObjectSpace().registerObjectId(id, this);
IRubyObject fixnumId = registerWithObjectSpace();

finalizer = new Finalizer(fixnumId);
setInternalVariable("__finalizer__", finalizer);
Expand All @@ -1242,6 +1253,34 @@ public void addFinalizer(IRubyObject f) {
finalizer.addFinalizer(f);
}

private IRubyObject registerWithObjectSpace() {
// since this is the first time we're registering a finalizer, we
// must also register this object in ObjectSpace, so that future
// calls to undefine_finalizer, which takes an object symbol, can
// locate the object properly. See JRUBY-4839.
long id = getObjectId();
IRubyObject fixnumId = id();

getRuntime().getObjectSpace().registerObjectId(id, this);
return fixnumId;
}

/**
* Stange method. We will dup the __finalizer__ variable in a freshly dup'd object,
* but it needs to be set to this objects __finalizer__.
*/
protected void dupFinalizer() {
Finalizer finalizer = (Finalizer) getInternalVariable("__finalizer__");
if (finalizer != null) {
// We need ObjectSpace to make this object reachable for the finalization
IRubyObject fixnumId = registerWithObjectSpace();

finalizer = new Finalizer(fixnumId, finalizer);
setInternalVariable("__finalizer__", finalizer);
getRuntime().addFinalizer(finalizer);
}
}

/**
* Remove all the finalizers for this object.
*/
Expand Down Expand Up @@ -1870,6 +1909,17 @@ public Finalizer(RubyFixnum id) {
this((IRubyObject) id);
}

/**
* Cloning finalizer needs new copy with its own id.
* @param id
* @param original
*/
public Finalizer(IRubyObject id, Finalizer original) {
this(id);
this.firstFinalizer = original.firstFinalizer;
this.finalizers = original.finalizers == null ? null : new ArrayList<>(original.finalizers);
}

Finalizer(IRubyObject id) {
this.id = id;
this.finalized = new AtomicBoolean(false);
Expand All @@ -1879,7 +1929,7 @@ public void addFinalizer(IRubyObject finalizer) {
if (firstFinalizer == null) {
firstFinalizer = finalizer;
} else {
if (finalizers == null) finalizers = new ArrayList<IRubyObject>(4);
if (finalizers == null) finalizers = new ArrayList<>(4);
finalizers.add(finalizer);
}
}
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 @@ -224,9 +226,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 @@ -332,47 +334,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 @@ -716,11 +701,11 @@ public IRubyObject quo(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 @@ -848,7 +833,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 @@ -857,7 +842,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 @@ -882,7 +867,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 @@ -904,15 +889,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 @@ -937,7 +922,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 @@ -968,17 +953,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 @@ -1086,7 +1071,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 @@ -1335,7 +1320,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 @@ -1344,7 +1329,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
Loading

0 comments on commit 632617f

Please sign in to comment.