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
14 changes: 10 additions & 4 deletions core/src/main/java/org/jruby/IncludedModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,21 @@ public RubyModule getNonIncludedClass() {
return origin;
}

/**
* We don't want to reveal ourselves to Ruby code, so origin this
* operation.
*/
@Deprecated(since = "10.0.3.0")
@Override
public IRubyObject id() {
return origin.id();
}

/**
* We don't want to reveal ourselves to Ruby code, so origin this
* operation.
*/
@Override
public RubyInteger __id__(ThreadContext context) {
return origin.__id__(context);
}

@Override
protected synchronized Map<String, IRubyObject> getClassVariables() {
return origin.getClassVariables();
Expand Down
11 changes: 8 additions & 3 deletions core/src/main/java/org/jruby/PrependedModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,19 @@ public RubyModule getNonIncludedClass() {
return origin;
}

@Deprecated(since = "10.0.3.0")
@Override
public IRubyObject id() {
return origin.id();
}

/**
* We don't want to reveal ourselves to Ruby code, so origin this
* operation.
*/
@Override
public IRubyObject id() {
return origin.id();
public RubyInteger __id__(ThreadContext context) {
return origin.__id__(context);
}

@Override
Expand All @@ -158,7 +164,6 @@ public void addMethod(ThreadContext context, String id, DynamicMethod method) {
method.setDefinedClass(origin);
}


@Override
protected synchronized Map<String, IRubyObject> getClassVariables() {
return origin.getClassVariables();
Expand Down
22 changes: 14 additions & 8 deletions core/src/main/java/org/jruby/RubyBasicObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ private static void initCopy(ThreadContext context, IRubyObject clone, IRubyObje

if (original.hasVariables()) {
clone.syncVariables(original);
((RubyBasicObject) clone).dupFinalizer();
((RubyBasicObject) clone).dupFinalizer(context);
}
if (original instanceof RubyModule) {
RubyModule cloneMod = (RubyModule)clone;
Expand Down Expand Up @@ -1088,14 +1088,20 @@ public Object dataGetStruct() {
return getInternalVariable("__wrap_struct__");
}

@Deprecated
@Override
public IRubyObject id() {
return getRuntime().newFixnum(getObjectId());
}

/** rb_obj_id
*
* Return the internal id of an object.
*/
@JRubyMethod(name = "__id__")
@Override
public IRubyObject id() {
return getRuntime().newFixnum(getObjectId());
public RubyInteger __id__(ThreadContext context) {
return asFixnum(context, getObjectId());
}

/**
Expand Down Expand Up @@ -1321,7 +1327,7 @@ public void addFinalizer(IRubyObject f) {
public IRubyObject addFinalizer(ThreadContext context, IRubyObject f) {
Finalizer finalizer = (Finalizer) getInternalVariable("__finalizer__");
if (finalizer == null) {
IRubyObject fixnumId = registerWithObjectSpace();
IRubyObject fixnumId = registerWithObjectSpace(context);

finalizer = new Finalizer(fixnumId);
setInternalVariable("__finalizer__", finalizer);
Expand All @@ -1330,13 +1336,13 @@ public IRubyObject addFinalizer(ThreadContext context, IRubyObject f) {
return finalizer.addFinalizer(context, f);
}

private IRubyObject registerWithObjectSpace() {
private IRubyObject registerWithObjectSpace(ThreadContext context) {
// 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();
IRubyObject fixnumId = __id__(context);

getRuntime().getObjectSpace().registerObjectId(id, this);
return fixnumId;
Expand All @@ -1346,11 +1352,11 @@ private IRubyObject registerWithObjectSpace() {
* 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() {
protected void dupFinalizer(ThreadContext context) {
Finalizer finalizer = (Finalizer) getInternalVariable("__finalizer__");
if (finalizer != null) {
// We need ObjectSpace to make this object reachable for the finalization
IRubyObject fixnumId = registerWithObjectSpace();
IRubyObject fixnumId = registerWithObjectSpace(context);

finalizer = new Finalizer(fixnumId, finalizer);
setInternalVariable("__finalizer__", finalizer);
Expand Down
10 changes: 10 additions & 0 deletions core/src/main/java/org/jruby/RubyBoolean.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ public int hashCode() {
return hashCode;
}

@Deprecated(since = "10.0.3.0")
@Override
public RubyFixnum id() {
if ((flags & FALSE_F) == 0) {
Expand All @@ -244,6 +245,15 @@ public RubyFixnum id() {
}
}

@Override
public RubyInteger __id__(ThreadContext context) {
if ((flags & FALSE_F) == 0) {
return asFixnum(context, 20);
} else {
return RubyFixnum.zero(context.runtime);
}
}

@Deprecated(since = "10.0.0.0", forRemoval = true)
@SuppressWarnings("removal")
public void marshalTo(org.jruby.runtime.marshal.MarshalStream output) throws java.io.IOException {
Expand Down
12 changes: 12 additions & 0 deletions core/src/main/java/org/jruby/RubyFixnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,7 @@ public IRubyObject bit_length(ThreadContext context) {
return asFixnum(context, 64 - Long.numberOfLeadingZeros(tmpValue));
}

@Deprecated(since = "10.0.3.0")
@Override
public IRubyObject id() {
long value = this.value;
Expand All @@ -1418,6 +1419,17 @@ public IRubyObject id() {
return super.id();
}

@Override
public RubyInteger __id__(ThreadContext context) {
long value = this.value;

if (fixnumable(value)) {
return asFixnum(context, 2 * value + 1);
}

return super.__id__(context);
}

// Piece of mri rb_to_id
@Override
public String asJavaString() {
Expand Down
24 changes: 21 additions & 3 deletions core/src/main/java/org/jruby/RubyFloat.java
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,24 @@ public IRubyObject prev_float(ThreadContext context) {
return asFloat(context, Math.nextAfter(value, Double.NEGATIVE_INFINITY));
}

@Deprecated(since = "10.0.3.0")
@Override
public IRubyObject id() {
long longBits = Double.doubleToLongBits(value);
long flonum;

// calculate flonum to use for ID, or fall back on default incremental ID
if (flonumRange(longBits)) {
flonum = (Numeric.rotl(longBits, 3) & ~0x01) | 0x02;
} else if (positiveZero(longBits)) {
flonum = 0x8000000000000002L;
} else {
return super.id();
}

return RubyFixnum.newFixnum(metaClass.runtime, flonum);
}

/**
* Produce an object ID for this Float.
*
Expand All @@ -1213,7 +1231,7 @@ public IRubyObject prev_float(ThreadContext context) {
* @return the object ID for this Float
*/
@Override
public IRubyObject id() {
public RubyInteger __id__(ThreadContext context) {
long longBits = Double.doubleToLongBits(value);
long flonum;

Expand All @@ -1223,10 +1241,10 @@ public IRubyObject id() {
} else if (positiveZero(longBits)) {
flonum = 0x8000000000000002L;
} else {
return super.id();
return super.__id__(context);
}

return RubyFixnum.newFixnum(metaClass.runtime, flonum);
return asFixnum(context, flonum);
}

/**
Expand Down
7 changes: 6 additions & 1 deletion core/src/main/java/org/jruby/RubyKernel.java
Original file line number Diff line number Diff line change
Expand Up @@ -2307,11 +2307,16 @@ public static IRubyObject methods(ThreadContext context, IRubyObject self, IRuby
return ((RubyBasicObject)self).methods(context, args);
}

@JRubyMethod(name = "object_id")
@Deprecated(since = "10.0.3.0")
public static IRubyObject object_id(IRubyObject self) {
return self.id();
}

@JRubyMethod(name = "object_id")
public static IRubyObject object_id(ThreadContext context, IRubyObject self) {
return self.__id__(context);
}

@JRubyMethod(name = "public_methods", optional = 1, checkArity = false)
public static IRubyObject public_methods(ThreadContext context, IRubyObject self, IRubyObject[] args) {
Arity.checkArgumentCount(context, args, 0, 1);
Expand Down
6 changes: 6 additions & 0 deletions core/src/main/java/org/jruby/RubyNil.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,17 @@ public int hashCode() {
return hashCode;
}

@Deprecated(since = "10.0.3.0")
@Override
public RubyFixnum id() {
return RubyFixnum.newFixnum(metaClass.runtime, 8);
}

@Override
public RubyInteger __id__(ThreadContext context) {
return asFixnum(context, 8);
}

/** nilclass_to_c
*
*/
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyObjectSpace.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public static IRubyObject undefine_finalizer(IRubyObject recv, IRubyObject obj,

@JRubyMethod(module = true, visibility = PRIVATE)
public static IRubyObject undefine_finalizer(ThreadContext context, IRubyObject recv, IRubyObject obj, Block block) {
context.runtime.getObjectSpace().removeFinalizers(toLong(context, obj.id()));
context.runtime.getObjectSpace().removeFinalizers(toLong(context, obj.__id__(context)));
return recv;
}

Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/api/Convert.java
Original file line number Diff line number Diff line change
Expand Up @@ -409,11 +409,12 @@ public static RubyBoolean asBoolean(ThreadContext context, boolean value) {

/**
* Create a Ruby Fixnum from a java long.
*
* MRI: RB_INT2FIX
* @param context the current thread context
* @param value the long value
* @return the Ruby Fixnum
*/
// mri: fix2int
public static RubyFixnum asFixnum(ThreadContext context, long value) {
return RubyFixnum.newFixnum(context.runtime, value);
}
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/org/jruby/ir/operands/UndefinedValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ private RuntimeException undefinedOperation() {
@Override
public IRubyObject id() { throw undefinedOperation(); }

@Override
public RubyInteger __id__(ThreadContext context) { throw undefinedOperation(); }

@Override
public IRubyObject op_equal(ThreadContext context, IRubyObject other) { throw undefinedOperation(); }
@Override
Expand Down
12 changes: 10 additions & 2 deletions core/src/main/java/org/jruby/java/proxies/ConcreteJavaProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
import org.jruby.Ruby;
import org.jruby.RubyClass;
import org.jruby.RubyFixnum;
import org.jruby.RubyInteger;
import org.jruby.RubyModule;
import org.jruby.api.Convert;
import org.jruby.internal.runtime.AbstractIRMethod;
import org.jruby.internal.runtime.SplitSuperState;
import org.jruby.internal.runtime.methods.DynamicMethod;
Expand Down Expand Up @@ -452,15 +454,21 @@ protected static void initialize(ThreadContext context, final RubyClass concrete
// getRuntime().getJavaSupport().setJavaObjectVariable(this, index, value);
// }

@Deprecated(since = "10.0.3.0")
@Override
public IRubyObject id() {
return RubyFixnum.newFixnum(getRuntime(), System.identityHashCode(getObject()));
}

/**
* Because we can't physically associate an ID with a Java object, we can
* only use the identity hashcode here.
*
* @return The identity hashcode for the Java object.
*/
@Override
public IRubyObject id() {
return RubyFixnum.newFixnum(getRuntime(), System.identityHashCode(getObject()));
public RubyInteger __id__(ThreadContext context) {
return Convert.asFixnum(context, System.identityHashCode(getObject()));
}

@Override
Expand Down
8 changes: 5 additions & 3 deletions core/src/main/java/org/jruby/runtime/builtin/IRubyObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,15 @@ default IRubyObject inspect(ThreadContext context) {

@Deprecated // not used at all
Object dataGetStructChecked();


@Deprecated
IRubyObject id();

/**
* The id of the object
* @return the object id
*/
IRubyObject id();

RubyInteger __id__(ThreadContext context);

public IRubyObject op_equal(ThreadContext context, IRubyObject other);
public IRubyObject op_eqq(ThreadContext context, IRubyObject other);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public VariableAccessor getVariableAccessorForRead() {
* @return the variable accessor appropriate for writes.
*/
public VariableAccessor getVariableAccessorForWrite(VariableTableManager tableMgr) {
VariableAccessor variableAccessor = this.variableAccessor;
return variableAccessor != VariableAccessor.DUMMY_ACCESSOR ? variableAccessor : allocateVariableAccessor(tableMgr);
}

Expand All @@ -77,8 +78,9 @@ public VariableAccessor getVariableAccessorForWrite(VariableTableManager tableMg
* @return the variable accessor appropriate for writes
*/
private synchronized VariableAccessor allocateVariableAccessor(VariableTableManager tableMgr) {
VariableAccessor variableAccessor = this.variableAccessor;
if (variableAccessor == VariableAccessor.DUMMY_ACCESSOR) {
variableAccessor = tableMgr.allocateVariableAccessor(name);
variableAccessor = this.variableAccessor = tableMgr.allocateVariableAccessor(name);
}
return variableAccessor;
}
Expand Down
Loading
Loading