Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
BEGIN LICENSE BLOCK ***** Version: EPL 1.0/GPL 2.0/LGPL 2.1 The contents of this file are subject to the Eclipse Public License Version 1.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.eclipse.org/legal/epl-v10.html Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. Copyright (C) 2008 Thomas E Enebo <enebo@acm.org> Alternatively, the contents of this file may be used under the terms of either of the GNU General Public License Version 2 or later (the "GPL"), or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), in which case the provisions of the GPL or the LGPL are applicable instead of those above. If you wish to allow use of your version of this file only under the terms of either the GPL or the LGPL, and not to allow others to use your version of this file under the terms of the EPL, indicate your decision by deleting the provisions above and replace them with the notice and other provisions required by the GPL or the LGPL. If you do not delete the provisions above, a recipient may use your version of this file under the terms of any one of the EPL, the GPL or the LGPL. END LICENSE BLOCK ***
  
  package org.jruby;
  
  import java.util.HashSet;
  import java.util.List;
  import java.util.Map;
  import java.util.Set;
  
  import static org.jruby.runtime.Visibility.*;
  import static org.jruby.CompatVersion.*;
  
  import static org.jruby.runtime.Helpers.invokedynamic;
  import static org.jruby.runtime.invokedynamic.MethodNames.OP_EQUAL;
  import static org.jruby.runtime.invokedynamic.MethodNames.OP_CMP;
  import static org.jruby.runtime.invokedynamic.MethodNames.EQL;
  import static org.jruby.runtime.invokedynamic.MethodNames.INSPECT;
RubyBasicObject is the only implementation of the org.jruby.runtime.builtin.IRubyObject. Every Ruby object in JRuby is represented by something that is an instance of RubyBasicObject. In the core class implementations, this means doing a subclass that extends RubyBasicObject. In other cases it means using a simple RubyBasicObject instance and its data fields to store specific information about the Ruby object. Some care has been taken to make the implementation be as monomorphic as possible, so that the Java Hotspot engine can improve performance of it. That is the reason for several patterns that might seem odd in this class. The IRubyObject interface used to have lots of methods for different things, but these have now mostly been refactored into several interfaces that gives access to that specific part of the object. This gives us the possibility to switch out that subsystem without changing interfaces again. For example, instance variable and internal variables are handled this way, but the implementation in RubyObject only returns "this" in getInstanceVariables() and getInternalVariables(). Methods that are implemented here, such as "initialize" should be implemented with care; reification of Ruby classes into Java classes can produce conflicting method names in rare cases. See JRUBY-5906 for an example.
 
 
     private static final Logger LOG = LoggerFactory.getLogger("RubyBasicObject");
 
     private static final boolean DEBUG = false;
    
    
The class of this object
 
     protected transient RubyClass metaClass;

    
object flags
 
     protected int flags;

    
variable table, lazily allocated as needed (if needed)
 
     public transient Object[] varTable;
    
    
locking stamp for Unsafe ops updating the vartable
 
     public transient volatile int varTableStamp;
    
    
offset of the varTable field in RubyBasicObject
 
     public static final long VAR_TABLE_OFFSET = UnsafeHolder.fieldOffset(RubyBasicObject.class"varTable");
    
    
offset of the varTableTamp field in RubyBasicObject
 
     public static final long STAMP_OFFSET = UnsafeHolder.fieldOffset(RubyBasicObject.class"varTableStamp");

    
The error message used when some one tries to modify an instance variable in a high security setting.
 
     public static final String ERR_INSECURE_SET_INST_VAR  = "Insecure: can't modify instance variable";
 
     public static final int ALL_F = -1;
     public static final int FALSE_F = 1 << 0;
    
This flag is a bit funny. It's used to denote that this value is nil. It's a bit counterintuitive for a Java programmer to not use subclassing to handle this case, since we have a RubyNil subclass anyway. Well, the reason for it being a flag is that the isNil() method is called extremely often. So often that it gives a good speed boost to make it monomorphic and final. It turns out using a flag for this actually gives us better performance than having a polymorphic isNil() method.
 
     public static final int NIL_F = 1 << 1;
     public static final int FROZEN_F = 1 << 2;
     public static final int TAINTED_F = 1 << 3;
     public static final int UNTRUSTED_F = 1 << 4;
 
     public static final int FL_USHIFT = 5;
 
     public static final int USER0_F = (1<<(+0));
     public static final int USER1_F = (1<<(+1));
     public static final int USER2_F = (1<<(+2));
     public static final int USER3_F = (1<<(+3));
     public static final int USER4_F = (1<<(+4));
     public static final int USER5_F = (1<<(+5));
     public static final int USER6_F = (1<<(+6));
     public static final int USER7_F = (1<<(+7));
     public static final int USER8_F = (1<<(+8));
 
     public static final int COMPARE_BY_IDENTITY_F = ;

    
A value that is used as a null sentinel in among other places the RubyArray implementation. It will cause large problems to call any methods on this object.
 
     public static final IRubyObject NEVER = new RubyBasicObject();

    
A value that specifies an undefined value. This value is used as a sentinel for undefined constant values, and other places where neither null nor NEVER makes sense.
 
     public static final IRubyObject UNDEF = new RubyBasicObject();

    
It's not valid to create a totally empty RubyObject. Since the RubyObject is always defined in relation to a runtime, that means that creating RubyObjects from outside the class might cause problems.
 
     private RubyBasicObject(){};

    
Default allocator instance for all Ruby objects. The only reason to not use this allocator is if you actually need to have all instances of something be a subclass of RubyObject.

 
     public static final ObjectAllocator BASICOBJECT_ALLOCATOR = new ObjectAllocator() {
         public IRubyObject allocate(Ruby runtimeRubyClass klass) {
             return new RubyBasicObject(runtimeklass);
         }
     };

    
Will create the Ruby class Object in the runtime specified. This method needs to take the actual class as an argument because of the Object class' central part in runtime initialization.
 
     public static RubyClass createBasicObjectClass(Ruby runtimeRubyClass objectClass) {
         objectClass.index = .;
 
         objectClass.defineAnnotatedMethods(RubyBasicObject.class);
 
         recacheBuiltinMethods(runtime);
 
         return objectClass;
     }
 
     static void recacheBuiltinMethods(Ruby runtime) {
         RubyModule objectClass = runtime.getBasicObject();
 
         if (runtime.is1_9()) { // method_missing is in Kernel in 1.9
             runtime.setDefaultMethodMissing(objectClass.searchMethod("method_missing"));
         }
     }
 
     @JRubyMethod(name = "initialize", visibility = , compat = )
     public IRubyObject initialize19(ThreadContext context) {
         return context.nil;
     }

    
Standard path for object creation. Objects are entered into ObjectSpace only if ObjectSpace is enabled.
 
     public RubyBasicObject(Ruby runtimeRubyClass metaClass) {
         this. = metaClass;
 
         runtime.addToObjectSpace(truethis);
     }

    
Path for objects that don't taint and don't enter objectspace.
 
     public RubyBasicObject(RubyClass metaClass) {
         this. = metaClass;
     }

    
Path for objects who want to decide whether they don't want to be in ObjectSpace even when it is on. (notably used by objects being considered immediate, they'll always pass false here)
 
     protected RubyBasicObject(Ruby runtimeRubyClass metaClassboolean useObjectSpace) {
         this. = metaClass;
 
         runtime.addToObjectSpace(useObjectSpacethis);
     }
 
     protected void taint(Ruby runtime) {
         if (!isTaint()) {
         	testFrozen();
             setTaint(true);
         }
     }

    
rb_frozen_class_p Helper to test whether this object is frozen, and if it is will throw an exception based on the message.
 
    protected final void testFrozen(String message) {
        if (isFrozen()) {
            throw getRuntime().newFrozenError(message);
        }
    }

    
rb_frozen_class_p Helper to test whether this object is frozen, and if it is will throw an exception based on the message.
 
    protected final void testFrozen() {
        if (isFrozen()) {
            throw getRuntime().newFrozenError("object");
        }
    }

    
Sets or unsets a flag on this object. The only flags that are guaranteed to be valid to use as the first argument is:

Parameters:
flag the actual flag to set or unset.
set if true, the flag will be set, if false, the flag will be unset.
 
     public final void setFlag(int flagboolean set) {
         if (set) {
              |= flag;
         } else {
              &= ~flag;
         }
     }

    
Get the value of a custom flag on this object. The only guaranteed flags that can be sent in to this method is:

Parameters:
flag the flag to get
Returns:
true if the flag is set, false otherwise
 
     public final boolean getFlag(int flag) {
         return ( & flag) != 0;
     }

    
Will invoke a named method with no arguments and no block if that method or a custom method missing exists. Otherwise returns null. 1.9: rb_check_funcall
 
     public final IRubyObject checkCallMethod(ThreadContext contextString name) {
         return Helpers.invokeChecked(contextthisname);
     }

    
Will invoke a named method with no arguments and no block.
 
     public final IRubyObject callMethod(ThreadContext contextString name) {
         return Helpers.invoke(contextthisname);
     }

    
Will invoke a named method with one argument and no block with functional invocation.
 
      public final IRubyObject callMethod(ThreadContext contextString nameIRubyObject arg) {
         return Helpers.invoke(contextthisnamearg);
     }

    
Will invoke a named method with the supplied arguments and no block with functional invocation.
 
     public final IRubyObject callMethod(ThreadContext contextString nameIRubyObject[] args) {
         return Helpers.invoke(contextthisnameargs);
     }
 
     public final IRubyObject callMethod(String nameIRubyObject... args) {
         return Helpers.invoke(getRuntime().getCurrentContext(), thisnameargs);
     }
 
     public final IRubyObject callMethod(String name) {
         return Helpers.invoke(getRuntime().getCurrentContext(), thisname);
     }

    
Will invoke a named method with the supplied arguments and supplied block with functional invocation.
 
     public final IRubyObject callMethod(ThreadContext contextString nameIRubyObject[] argsBlock block) {
         return Helpers.invoke(contextthisnameargsblock);
     }

    
Does this object represent nil? See the docs for the NIL_F flag for more information.
 
     public final boolean isNil() {
         return ( & ) != 0;
     }

    
Is this value a truthy value or not? Based on the FALSE_F flag.
 
     public final boolean isTrue() {
         return ( & ) == 0;
     }

    
Is this value a falsey value or not? Based on the FALSE_F flag.
 
     public final boolean isFalse() {
         return ( & ) != 0;
     }

    
Gets the taint. Shortcut for getFlag(TAINTED_F).

Returns:
true if this object is tainted
 
     public boolean isTaint() {
         return ( & ) != 0;
     }

    
Sets the taint flag. Shortcut for setFlag(TAINTED_F, taint)

Parameters:
taint should this object be tainted or not?
 
     public void setTaint(boolean taint) {
         // JRUBY-4113: callers should not call setTaint on immediate objects
         if (isImmediate()) return;
         
         if (taint) {
              |= ;
         } else {
              &= ~;
         }
     }


    
OBJ_INFECT Infects this object with traits from the argument obj. In real terms this currently means that if obj is tainted, this object will get tainted too. It's possible to hijack this method to do other infections if that would be interesting.
 
     public IRubyObject infectBy(IRubyObject obj) {
         if (obj.isTaint()) setTaint(true);
         if (obj.isUntrusted()) setUntrusted(true);
         return this;
     }
 
     final RubyBasicObject infectBy(RubyBasicObject obj) {
          |= (obj.flags & ( | ));
         return this;
     }
 
     final RubyBasicObject infectBy(int tuFlags) {
          |= (tuFlags & ( | ));
         return this;
     }

    
Is this value frozen or not? Shortcut for doing getFlag(FROZEN_F).

Returns:
true if this object is frozen, false otherwise
 
     public boolean isFrozen() {
         return ( & ) != 0;
     }

    
Sets whether this object is frozen or not. Shortcut for doing setFlag(FROZEN_F, frozen).

Parameters:
frozen should this object be frozen?
 
     public void setFrozen(boolean frozen) {
         if (frozen) {
              |= ;
         } else {
              &= ~;
         }
     }


    
Is this value untrusted or not? Shortcut for doing getFlag(UNTRUSTED_F).

Returns:
true if this object is frozen, false otherwise
 
     public boolean isUntrusted() {
         return ( & ) != 0;
     }

    
Sets whether this object is untrusted or not. Shortcut for doing setFlag(UNTRUSTED_F, untrusted).

Parameters:
untrusted should this object be frozen?
 
     public void setUntrusted(boolean untrusted) {
         if (untrusted) {
              |= ;
         } else {
              &= ~;
         }
     }

    
Is object immediate (def: Fixnum, Symbol, true, false, nil?).
 
     public boolean isImmediate() {
     	return false;
     }

    
if exist return the meta-class else return the type of the object.
 
     public final RubyClass getMetaClass() {
         return ;
     }

    
rb_singleton_class Note: this method is specialized for RubyFixnum, RubySymbol, RubyNil and RubyBoolean Will either return the existing singleton class for this object, or create a new one and return that.
 
     public RubyClass getSingletonClass() {
         RubyClass klass;
 
         if (getMetaClass().isSingleton() && ((MetaClass)getMetaClass()).getAttached() == this) {
             klass = getMetaClass();
         } else {
             klass = makeMetaClass(getMetaClass());
         }
 
         klass.setTaint(isTaint());
         if (isFrozen()) klass.setFrozen(true);
 
         return klass;
     }

    
rb_make_metaclass Will create a new meta class, insert this in the chain of classes for this specific object, and return the generated meta class.
 
     public RubyClass makeMetaClass(RubyClass superClass) {
         MetaClass klass = new MetaClass(getRuntime(), superClassthis); // rb_class_boot
         setMetaClass(klass);
 
         klass.setMetaClass(superClass.getRealClass().getMetaClass());
 
         superClass.addSubclass(klass);
 
         return klass;
     }

    
Makes it possible to change the metaclass of an object. In practice, this is a simple version of Smalltalks Become, except that it doesn't work when we're dealing with subclasses. In practice it's used to change the singleton/meta class used, without changing the "real" inheritance chain.
 
     public void setMetaClass(RubyClass metaClass) {
         this. = metaClass;
     }

    
 
     public RubyClass getType() {
         return getMetaClass().getRealClass();
     }

    
Does this object respond to the specified message? Uses a shortcut if it can be proved that respond_to? haven't been overridden.
 
     public final boolean respondsTo(String name) {
         DynamicMethod method = getMetaClass().searchMethod("respond_to?");
         if(method.equals(getRuntime().getRespondToMethod())) {
             // fastest path; builtin respond_to? which just does isMethodBound
             return getMetaClass().isMethodBound(namefalse);
         } else if (!method.isUndefined()) {
             // medium path, invoke user's respond_to? if defined
             return method.call(getRuntime().getCurrentContext(), this"respond_to?"getRuntime().newSymbol(name)).isTrue();
         } else {
             // slowest path, full callMethod to hit method_missing if present, or produce error
             return callMethod(getRuntime().getCurrentContext(), "respond_to?"getRuntime().newSymbol(name)).isTrue();
         }
     }

    
Does this object respond to the specified message via "method_missing?"
 
     public final boolean respondsToMissing(String name) {
         return respondsToMissing(nametrue);
     }

    
Does this object respond to the specified message via "method_missing?"
 
     public final boolean respondsToMissing(String nameboolean priv) {
         DynamicMethod method = getMetaClass().searchMethod("respond_to_missing?");
         // perhaps should try a smart version as for respondsTo above?
         if(method.isUndefined()) {
             return false;
         } else {
             return method.call(
                     getRuntime().getCurrentContext(),
                     this,
                     ,
                     "respond_to_missing?",
                     getRuntime().newSymbol(name),
                     getRuntime().newBoolean(priv)).isTrue();
         }
     }

    
Will return the runtime that this object is associated with.

Returns:
current runtime
 
     public final Ruby getRuntime() {
         return getMetaClass().getClassRuntime();
     }

    
Will return the Java interface that most closely can represent this object, when working through JAva integration translations.
 
     public Class getJavaClass() {
         Object obj = dataGetStruct();
         if (obj instanceof JavaObject) {
             return ((JavaObject)obj).getValue().getClass();
         }
         return getClass();
     }

    
rb_to_id Will try to convert this object to a String using the Ruby "to_str" if the object isn't already a String. If this still doesn't work, will throw a Ruby TypeError.
 
     public String asJavaString() {
         IRubyObject asString = checkStringType();
         if(!asString.isNil()) return ((RubyString)asString).asJavaString();
         throw getRuntime().newTypeError(inspect().toString() + " is not a string");
     }

    
rb_obj_as_string First converts this object into a String using the "to_s" method, infects it with the current taint and returns it. If to_s doesn't return a Ruby String, anyToString() is used instead.
 
     public RubyString asString() {
         IRubyObject str = Helpers.invoke(getRuntime().getCurrentContext(), this"to_s");
 
         if (!(str instanceof RubyString)) return (RubyString)anyToString();
         if (isTaint()) str.setTaint(true);
         return (RubyStringstr;
     }

 
Tries to convert this object to a Ruby Array using the "to_ary" method.
 
     public RubyArray convertToArray() {
         return (RubyArray) TypeConverter.convertToType(thisgetRuntime().getArray(), "to_ary");
     }

    
Tries to convert this object to a Ruby Hash using the "to_hash" method.
 
     public RubyHash convertToHash() {
         return (RubyHash)TypeConverter.convertToType(thisgetRuntime().getHash(), "to_hash");
     }

    
Tries to convert this object to a Ruby Float using the "to_f" method.
 
     public RubyFloat convertToFloat() {
         return (RubyFloat) TypeConverter.convertToType(thisgetRuntime().getFloat(), "to_f");
     }

    
Tries to convert this object to a Ruby Integer using the "to_int" method.
 
     public RubyInteger convertToInteger() {
         return convertToInteger("to_int");
     }

    
Tries to convert this object to a Ruby Integer using the supplied conversion method.
 
     public RubyInteger convertToInteger(String convertMethod) {
         IRubyObject val = TypeConverter.convertToType(thisgetRuntime().getInteger(), convertMethodtrue);
         if (!(val instanceof RubyInteger)) throw getRuntime().newTypeError(getMetaClass().getName() + "#" + convertMethod + " should return Integer");
         return (RubyInteger)val;
     }

    
Tries to convert this object to a Ruby String using the "to_str" method.
 
     public RubyString convertToString() {
         return (RubyString) TypeConverter.convertToType(thisgetRuntime().getString(), "to_str");
     }

    
Internal method that helps to convert any object into the format of a class name and a hex string inside of #<>.
 
     public IRubyObject anyToString() {
         String cname = getMetaClass().getRealClass().getName();
         /* 6:tags 16:addr 1:eos */
         RubyString str = getRuntime().newString("#<" + cname + ":0x" + Integer.toHexString(System.identityHashCode(this)) + ">");
         str.setTaint(isTaint());
         return str;
     }

    
rb_check_string_type Tries to return a coerced string representation of this object, using "to_str". If that returns something other than a String or nil, an empty String will be returned.
 
     public IRubyObject checkStringType() {
         IRubyObject str = TypeConverter.convertToTypeWithCheck(thisgetRuntime().getString(), "to_str");
         if(!str.isNil() && !(str instanceof RubyString)) {
             str = RubyString.newEmptyString(getRuntime());
         }
         return str;
     }

    
rb_check_string_type Tries to return a coerced string representation of this object, using "to_str". If that returns something other than a String or nil, an empty String will be returned.
 
     public IRubyObject checkStringType19() {
         IRubyObject str = TypeConverter.convertToTypeWithCheck19(thisgetRuntime().getString(), "to_str");
         if(!str.isNil() && !(str instanceof RubyString)) {
             str = RubyString.newEmptyString(getRuntime());
         }
         return str;
     }

    
rb_check_array_type Returns the result of trying to convert this object to an Array with "to_ary".
 
     public IRubyObject checkArrayType() {
         return TypeConverter.convertToTypeWithCheck(thisgetRuntime().getArray(), "to_ary");
     }

    
 
     public Object toJava(Class target) {
         // for callers that unconditionally pass null retval type (JRUBY-4737)
         if (target == void.classreturn null;
 
         if (dataGetStruct() instanceof JavaObject) {
             // for interface impls
 
             JavaObject innerWrapper = (JavaObject)dataGetStruct();
 
             // ensure the object is associated with the wrapper we found it in,
             // so that if it comes back we don't re-wrap it
             if (target.isAssignableFrom(innerWrapper.getValue().getClass())) {
                 getRuntime().getJavaSupport().getObjectProxyCache().put(innerWrapper.getValue(), this);
 
                 return innerWrapper.getValue();
             }
         } else if (JavaUtil.isDuckTypeConvertable(getClass(), target)) {
             if (!respondsTo("java_object")) {
                 return JavaUtil.convertProcToInterface(getRuntime().getCurrentContext(), thistarget);
             }
         } else if (target.isAssignableFrom(getClass())) {
             return this;
         }
         
         throw getRuntime().newTypeError("cannot convert instance of " + getClass() + " to " + target);
     }
 
     public IRubyObject dup() {
         Ruby runtime = getRuntime();
 
         if (isImmediate()) throw runtime.newTypeError("can't dup " + getMetaClass().getName());
 
         IRubyObject dup = getMetaClass().getRealClass().allocate();
         if (isTaint()) dup.setTaint(true);
         if (isUntrusted()) dup.setUntrusted(true);
 
         initCopy(dupthisruntime.is1_9() ? "initialize_dup" : "initialize_copy");
 
         return dup;
     }

    
init_copy Initializes a copy with variable and special instance variable information, and then call the initialize_copy Ruby method.
 
     private static void initCopy(IRubyObject cloneIRubyObject originalString method) {
         assert !clone.isFrozen() : "frozen object (" + clone.getMetaClass().getName() + ") allocated";
 
         original.copySpecialInstanceVariables(clone);
 
         if (original.hasVariables()) clone.syncVariables(original);
         if (original instanceof RubyModule) {
             RubyModule cloneMod = (RubyModule)clone;
             cloneMod.syncConstants((RubyModule)original);
             cloneMod.syncClassVariables((RubyModule)original);
         }
 
         /* FIXME: finalizer should be dupped here */
         clone.callMethod(clone.getRuntime().getCurrentContext(), methodoriginal);
     }

    
Lots of MRI objects keep their state in non-lookupable ivars (e:g. Range, Struct, etc). This method is responsible for dupping our java field equivalents
 
     public void copySpecialInstanceVariables(IRubyObject clone) {
     }

    
rb_inspect The internal helper that ensures a RubyString instance is returned so dangerous casting can be omitted Prefered over callMethod(context, "inspect")
 
     static RubyString inspect(ThreadContext contextIRubyObject object) {
         return RubyString.objAsString(contextinvokedynamic(contextobject));
     }
 
     public IRubyObject rbClone() {
         Ruby runtime = getRuntime();
 
         if (isImmediate()) throw runtime.newTypeError("can't clone " + getMetaClass().getName());
 
         // We're cloning ourselves, so we know the result should be a RubyObject
         clone.setMetaClass(getSingletonClassClone());
         if (isTaint()) clone.setTaint(true);
 
         initCopy(clonethisruntime.is1_9() ? "initialize_clone" : "initialize_copy");
 
         if (isFrozen()) clone.setFrozen(true);
         if (isUntrusted()) clone.setUntrusted(true);
         return clone;
     }

    
rb_singleton_class_clone Will make sure that if the current objects class is a singleton, it will get cloned.

Returns:
either a real class, or a clone of the current singleton class
 
     protected RubyClass getSingletonClassClone() {
         RubyClass klass = getMetaClass();
 
         if (!klass.isSingleton()) {
             return klass;
         }
 
         MetaClass clone = new MetaClass(getRuntime(), klass.getSuperClass(), ((MetaClassklass).getAttached());
         clone.flags = ;
 
         if (this instanceof RubyClass) {
             clone.setMetaClass(clone);
         } else {
             clone.setMetaClass(klass.getSingletonClassClone());
         }
 
         if (klass.hasVariables()) {
             clone.syncVariables(klass);
         }
         clone.syncConstants(klass);
 
         klass.cloneMethods(clone);
 
         ((MetaClassclone.getMetaClass()).setAttached(clone);
 
         return clone;
     }

    
Specifically polymorphic method that are meant to be overridden by modules to specify that they are modules in an easy way.
 
     public boolean isModule() {
         return false;
     }

    
Specifically polymorphic method that are meant to be overridden by classes to specify that they are classes in an easy way.
 
     public boolean isClass() {
         return false;
     }


    
 
     public synchronized void dataWrapStruct(Object obj) {
         if (obj == null) {
             removeInternalVariable("__wrap_struct__");
         } else {
             fastSetInternalVariable("__wrap_struct__"obj);
         }
     }
 
     // The dataStruct is a place where custom information can be
     // contained for core implementations that doesn't necessarily
     // want to go to the trouble of creating a subclass of
     // RubyObject. The OpenSSL implementation uses this heavily to
     // save holder objects containing Java cryptography objects.
     // Java integration uses this to store the Java object ref.
     //protected transient Object dataStruct;
     
 
     public synchronized Object dataGetStruct() {
         return getInternalVariable("__wrap_struct__");
     }
 
     // Equivalent of Data_Get_Struct
     // This will first check that the object in question is actually a T_DATA equivalent.
     public synchronized Object dataGetStructChecked() {
         TypeConverter.checkData(this);
         return getInternalVariable("__wrap_struct__");
     }

    
rb_obj_id Return the internal id of an object.
 
     @JRubyMethod(name = {"object_id""__id__"}, compat = )
     public IRubyObject id() {
         return getRuntime().newFixnum(getObjectId());
     }

    
The logic here is to use the special objectId accessor slot from the parent as a lazy store for an object ID. IDs are generated atomically, in serial, and guaranteed unique for up to 2^63 objects. The special objectId slot is managed separately from the "normal" vars so it does not marshal, clone/dup, or refuse to be initially set when the object is frozen.
 
     protected long getObjectId() {
         return .getRealClass().getVariableTableManager().getObjectId(this);
     }

    
rb_obj_inspect call-seq: obj.inspect => string Returns a string containing a human-readable representation of obj. If not overridden, uses the to_s method to generate the string. [ 1, 2, 3..4, 'five' ].inspect #=> "[1, 2, 3..4, \"five\"]" Time.new.inspect #=> "Wed Apr 09 08:54:39 CDT 2003"
 
     public IRubyObject inspect() {
         Ruby runtime = getRuntime();
         if ((!isImmediate()) && !(this instanceof RubyModule) && hasVariables()) {
             return hashyInspect();
        }
        if (isNil()) return RubyNil.inspect(this);
        return Helpers.invoke(runtime.getCurrentContext(), this"to_s");
    }
    public IRubyObject hashyInspect() {
        Ruby runtime = getRuntime();
        StringBuilder part = new StringBuilder();
        String cname = getMetaClass().getRealClass().getName();
        part.append("#<").append(cname).append(":0x");
        part.append(Integer.toHexString(inspectHashCode()));
        if (runtime.isInspecting(this)) {
            /* 6:tags 16:addr 1:eos */
            part.append(" ...>");
            return runtime.newString(part.toString());
        }
        try {
            runtime.registerInspecting(this);
            return runtime.newString(inspectObj(part).toString());
        } finally {
            runtime.unregisterInspecting(this);
        }
    }

    
For most objects, the hash used in the default #inspect is just the identity hashcode of the actual object. See org.jruby.java.proxies.JavaProxy for a divergent case.

Returns:
The identity hashcode of this object
    protected int inspectHashCode() {
        return System.identityHashCode(this);
    }

    
inspect_obj The internal helper method that takes care of the part of the inspection that inspects instance variables.
    private StringBuilder inspectObj(StringBuilder part) {
        ThreadContext context = getRuntime().getCurrentContext();
        String sep = "";
            Object value = entry.getValue().get(this);
            if (value == null || !(value instanceof IRubyObject) || !IdUtil.isInstanceVariable(entry.getKey())) continue;
            
            part.append(sep).append(" ").append(entry.getKey()).append("=");
            part.append(invokedynamic(context, (IRubyObject)value));
            sep = ",";
        }
        part.append(">");
        return part;
    }
    // Methods of the Object class (rb_obj_*):
    @JRubyMethod(name = "!", compat = )
    public IRubyObject op_not(ThreadContext context) {
        return context.runtime.newBoolean(!this.isTrue());
    }
    @JRubyMethod(name = "!=", required = 1, compat = )
    public IRubyObject op_not_equal(ThreadContext contextIRubyObject other) {
        return context.runtime.newBoolean(!invokedynamic(contextthisother).isTrue());
    }

    
Compares this Ruby object with another.

Parameters:
other another IRubyObject
Returns:
0 if equal, < 0 if this is less than other, > 0 if this is greater than other
Throws:
java.lang.IllegalArgumentException if the objects cannot be compared.
    public int compareTo(IRubyObject other) {
        try {
            IRubyObject cmp = invokedynamic(getRuntime().getCurrentContext(),
                    thisother);
            
            // if RubyBasicObject#op_cmp is used, the result may be nil
            if (!cmp.isNil()) {
                return (intcmp.convertToInteger().getLongValue();
            }
        } catch (RaiseException ex) {
        }
        
        /* We used to raise an error if two IRubyObject were not comparable, but
         * in order to support the new ConcurrentHashMapV8 and other libraries
         * and containers that arbitrarily call compareTo expecting it to always
         * succeed, we have opted to return 0 here. This will allow all
         * RubyBasicObject subclasses to be compared, but if the comparison is
         * not valid we they will appear the same for sorting purposes.
         * 
         * See https://jira.codehaus.org/browse/JRUBY-7013
         */
        return 0;
    }
    public IRubyObject op_equal(ThreadContext contextIRubyObject obj) {
        return op_equal_19(contextobj);
    }

    
rb_obj_equal Will by default use identity equality to compare objects. This follows the Ruby semantics. The name of this method doesn't follow the convention because hierarchy problems
    @JRubyMethod(name = "==", compat = )
    public IRubyObject op_equal_19(ThreadContext contextIRubyObject obj) {
        return this == obj ? context.runtime.getTrue() : context.runtime.getFalse();
    }
    public IRubyObject op_eqq(ThreadContext contextIRubyObject other) {
        // Remain unimplemented due to problems with the double java hierarchy
        return context.runtime.getNil();
    }
    @JRubyMethod(name = "equal?", required = 1, compat = )
    public IRubyObject equal_p19(ThreadContext contextIRubyObject other) {
        return op_equal_19(contextother);
    }

    
Helper method for checking equality, first using Java identity equality, and then calling the "==" method.
    protected static boolean equalInternal(final ThreadContext contextfinal IRubyObject thatfinal IRubyObject other){
        return that == other || invokedynamic(contextthatother).isTrue();
    }

    
method used for Hash key comparison (specialized for String, Symbol and Fixnum) Will by default just call the Ruby method "eql?"
    public boolean eql(IRubyObject other) {
        return invokedynamic(getRuntime().getCurrentContext(), thisother).isTrue();
    }

    
Adds the specified object as a finalizer for this object.
    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 ID, can
            // locate the object properly. See JRUBY-4839.
            long id = getObjectId();
            RubyFixnum fixnumId = (RubyFixnum)id();
            getRuntime().getObjectSpace().registerObjectId(idthis);
            finalizer = new Finalizer(fixnumId);
            fastSetInternalVariable("__finalizer__"finalizer);
            getRuntime().addFinalizer(finalizer);
        }
        finalizer.addFinalizer(f);
    }

    
Remove all the finalizers for this object.
    public void removeFinalizers() {
        Finalizer finalizer = (Finalizer)getInternalVariable("__finalizer__");
        if (finalizer != null) {
            finalizer.removeFinalizers();
            removeInternalVariable("__finalizer__");
            getRuntime().removeFinalizer(finalizer);
        }
    }
    public Object getVariable(int index) {
        return VariableAccessor.getVariable(thisindex);
    }
    
    public void setVariable(int indexObject value) {
        if (index < 0) return;
        .getVariableTableManager().setVariableInternal(thisindexvalue);
    }
    
    public final Object getNativeHandle() {
        return .getVariableTableManager().getNativeHandle(this);
    }
    public final void setNativeHandle(Object value) {
        .getVariableTableManager().setNativeHandle(thisvalue);
    }
    public final Object getFFIHandle() {
        return .getVariableTableManager().getFFIHandle(this);
    }
    public final void setFFIHandle(Object value) {
        .getVariableTableManager().setFFIHandle(thisvalue);
    }
    //
    // COMMON VARIABLE METHODS
    //

    
    public boolean hasVariables() {
        return .getVariableTableManager().hasVariables(this);
    }

    
Gets a list of all variables in this object.
    // TODO: must override in RubyModule to pick up constants
    public List<Variable<Object>> getVariableList() {
        Map<StringVariableAccessorivarAccessors = .getVariableAccessorsForRead();
        ArrayList<Variable<Object>> list = new ArrayList<Variable<Object>>();
        for (Map.Entry<StringVariableAccessorentry : ivarAccessors.entrySet()) {
            Object value = entry.getValue().get(this);
            if (value == nullcontinue;
            list.add(new VariableEntry<Object>(entry.getKey(), value));
        }
        return list;
    }

    
Gets a name list of all variables in this object.
   // TODO: must override in RubyModule to pick up constants
   public List<StringgetVariableNameList() {
        Map<StringVariableAccessorivarAccessors = .getVariableAccessorsForRead();
        ArrayList<Stringlist = new ArrayList<String>();
        for (Map.Entry<StringVariableAccessorentry : ivarAccessors.entrySet()) {
            Object value = entry.getValue().get(this);
            if (value == nullcontinue;
            list.add(entry.getKey());
        }
        return list;
    }

    
Checks if the variable table contains a variable of the specified name.
    protected boolean variableTableContains(String name) {
        return .getVariableAccessorForRead(name).get(this) != null;
    }

    
Fetch an object from the variable table based on the name.

Returns:
the object or null if not found
    protected Object variableTableFetch(String name) {
        return .getVariableAccessorForRead(name).get(this);
    }

    
Store a value in the variable store under the specific name.
    protected Object variableTableStore(String nameObject value) {
        .getVariableAccessorForWrite(name).set(thisvalue);
        return value;
    }

    
Removes the entry with the specified name from the variable table, and returning the removed value.
    protected Object variableTableRemove(String name) {
        return .getVariableTableManager().clearVariable(thisname);
    }

    
Synchronize the variable table with the argument. In real terms this means copy all entries into a newly allocated table.
    protected void variableTableSync(List<Variable<Object>> vars) {
        synchronized(this) {
            for (Variable<Objectvar : vars) {
                variableTableStore(var.getName(), var.getValue());
            }
        }
    }
    //
    // INTERNAL VARIABLE METHODS
    //

    
Dummy method to avoid a cast, and to avoid polluting the IRubyObject interface with all the instance variable management methods.
        return this;
    }

    
    public boolean hasInternalVariable(String name) {
        assert !IdUtil.isRubyVariable(name);
        return variableTableContains(name);
    }

    
    public Object getInternalVariable(String name) {
        assert !IdUtil.isRubyVariable(name);
        return variableTableFetch(name);
    }

    
    public void setInternalVariable(String nameObject value) {
        assert !IdUtil.isRubyVariable(name);
        variableTableStore(namevalue);
    }

    
    public Object removeInternalVariable(String name) {
        assert !IdUtil.isRubyVariable(name);
        return variableTableRemove(name);
    }
    
    
Sync one this object's variables with other's - this is used to make rbClone work correctly.
    public void syncVariables(IRubyObject other) {
        .getVariableTableManager().syncVariables(thisother);
    }
    
    //
    // INSTANCE VARIABLE API METHODS
    //

    
Dummy method to avoid a cast, and to avoid polluting the IRubyObject interface with all the instance variable management methods.
        return this;
    }

    
    public boolean hasInstanceVariable(String name) {
        return variableTableContains(name);
    }

    
    public IRubyObject getInstanceVariable(String name) {
        return (IRubyObject)variableTableFetch(name);
    }

    
    public IRubyObject setInstanceVariable(String nameIRubyObject value) {
        assert value != null;
        return (IRubyObject)variableTableStore(namevalue);
    }

    
    public IRubyObject removeInstanceVariable(String name) {
        return (IRubyObject)variableTableRemove(name);
    }

    
Gets a list of all variables in this object.
    // TODO: must override in RubyModule to pick up constants
        Map<StringVariableAccessorivarAccessors = .getVariableAccessorsForRead();
        ArrayList<Variable<IRubyObject>> list = new ArrayList<Variable<IRubyObject>>();
        for (Map.Entry<StringVariableAccessorentry : ivarAccessors.entrySet()) {
            Object value = entry.getValue().get(this);
            if (value == null || !(value instanceof IRubyObject) || !IdUtil.isInstanceVariable(entry.getKey())) continue;
            list.add(new VariableEntry<IRubyObject>(entry.getKey(), (IRubyObject)value));
        }
        return list;
    }

    
Gets a name list of all variables in this object.
   // TODO: must override in RubyModule to pick up constants
        Map<StringVariableAccessorivarAccessors = .getVariableAccessorsForRead();
        ArrayList<Stringlist = new ArrayList<String>();
        for (Map.Entry<StringVariableAccessorentry : ivarAccessors.entrySet()) {
            Object value = entry.getValue().get(this);
            if (value == null || !(value instanceof IRubyObject) || !IdUtil.isInstanceVariable(entry.getKey())) continue;
            list.add(entry.getKey());
        }
        return list;
    }

    
    public void copyInstanceVariablesInto(final InstanceVariables other) {
        for (Variable<IRubyObjectvar : getInstanceVariableList()) {
            synchronized (this) {
                other.setInstanceVariable(var.getName(), var.getValue());
            }
        }
    }

    
Makes sure that instance variables can be set on this object, including information about whether this object is frozen, or tainted. Will throw a suitable exception in that case.
    public final void ensureInstanceVariablesSettable() {
        if (!isFrozen()) {
            return;
        }
        raiseFrozenError();
    }
    private void raiseFrozenError() throws RaiseException {