/** * Retrieve or allocate the variable accessor for this variable. This * version differs from getVariableAccessorForWrite only in its visibility * and the fact that it is synchronized against this field to ensure * volatile behavior of the variableAccessor field. * * @param tableMgr the VariableTableManager for which to allocate an * accessor, if it has not already been allocated. * @return the variable accessor appropriate for writes */ private synchronized VariableAccessor allocateVariableAccessor(VariableTableManager tableMgr) { if (variableAccessor == VariableAccessor.DUMMY_ACCESSOR) { variableAccessor = tableMgr.allocateVariableAccessor(name); } return variableAccessor; }
public VariableAccessorField getFFIHandleAccessorField() { return variableTableManager.getFFIHandleAccessorField(); }
public VariableAccessor getFFIHandleAccessorForRead() { return variableTableManager.getFFIHandleAccessorForRead(); }
/** * Set the FFI handle for the given object. * * @param self the object * @param self the object's FFI handle */ public final void setFFIHandle(RubyBasicObject self, Object value) { int index = getFFIHandleAccessorForWrite().getIndex(); setVariableInternal(realClass, self, index, value); }
/** used by CLASS_ALLOCATOR (any Class' class will be a Class!) * also used to bootstrap Object class */ protected RubyClass(Ruby runtime) { super(runtime, runtime.getClassClass()); this.runtime = runtime; this.realClass = this; this.variableTableManager = new VariableTableManager(this); index = ClassIndex.CLASS; }
/** * Removes the entry with the specified name from the variable * table, and returning the removed value. */ protected Object variableTableRemove(String name) { return metaClass.getVariableTableManager().clearVariable(this, name); }
public VariableAccessorField getObjectGroupAccessorField() { return variableTableManager.getObjectGroupAccessorField(); }
public final Object getFFIHandle() { return metaClass.getVariableTableManager().getFFIHandle(this); }
public VariableAccessor getFFIHandleAccessorForWrite() { return variableTableManager.getFFIHandleAccessorForWrite(); }
public VariableAccessor getVariableAccessorForVar(String name, MethodHandle getter, MethodHandle setter) { VariableAccessor ivarAccessor = variableAccessors.get(name); if (ivarAccessor == null) { synchronized (realClass) { Map<String, VariableAccessor> myVariableAccessors = variableAccessors; ivarAccessor = myVariableAccessors.get(name); if (ivarAccessor == null) { // allocate a new accessor and populate a new table ivarAccessor = allocateVariableAccessorForVar(name, getter, setter); Map<String, VariableAccessor> newVariableAccessors = new HashMap<String, VariableAccessor>(myVariableAccessors.size() + 1); newVariableAccessors.putAll(myVariableAccessors); newVariableAccessors.put(name, ivarAccessor); variableAccessors = newVariableAccessors; } } } return ivarAccessor; }
/** * Deserialization proceeds as follows: * * <ol> * <li>Deserialize the object instance. It will have null metaClass and * varTable fields.</li> * <li>Deserialize the name of the object's class, and retrieve class from a * thread-local JRuby instance.</li> * <li>Retrieve each variable in turn, re-assigning them by name.</li> * </ol> * * @see RubyBasicObject#writeObject(java.io.ObjectOutputStream) */ private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException { Ruby ruby = Ruby.getThreadLocalRuntime(); if (ruby == null) { throw new IOException("No thread-local org.jruby.Ruby available; can't deserialize Ruby object. Set with Ruby#setThreadLocalRuntime."); } ois.defaultReadObject(); metaClass = (RubyClass)ruby.getClassFromPath(ois.readUTF()); metaClass.getVariableTableManager().deserializeVariables(this, ois); }
/** * Set the FFI handle for the given object. * * @param self the object * @param self the object's FFI handle */ public final void setFFIHandle(RubyBasicObject self, Object value) { int index = getFFIHandleAccessorForWrite().getIndex(); setVariableInternal(realClass, self, index, value); }
/** used by CLASS_ALLOCATOR (any Class' class will be a Class!) * also used to bootstrap Object class */ protected RubyClass(Ruby runtime) { super(runtime, runtime.getClassClass()); this.runtime = runtime; this.realClass = this; this.variableTableManager = new VariableTableManager(this); index = ClassIndex.CLASS; }
/** * Removes the entry with the specified name from the variable * table, and returning the removed value. */ protected Object variableTableRemove(String name) { return metaClass.getVariableTableManager().clearVariable(this, name); }
public VariableAccessorField getObjectGroupAccessorField() { return variableTableManager.getObjectGroupAccessorField(); }
public final Object getFFIHandle() { return metaClass.getVariableTableManager().getFFIHandle(this); }
public VariableAccessor getFFIHandleAccessorForWrite() { return variableTableManager.getFFIHandleAccessorForWrite(); }
public VariableAccessor getVariableAccessorForVar(String name, MethodHandle getter, MethodHandle setter) { VariableAccessor ivarAccessor = variableAccessors.get(name); if (ivarAccessor == null) { synchronized (realClass) { Map<String, VariableAccessor> myVariableAccessors = variableAccessors; ivarAccessor = myVariableAccessors.get(name); if (ivarAccessor == null) { // allocate a new accessor and populate a new table ivarAccessor = allocateVariableAccessorForVar(name, getter, setter); Map<String, VariableAccessor> newVariableAccessors = new HashMap<String, VariableAccessor>(myVariableAccessors.size() + 1); newVariableAccessors.putAll(myVariableAccessors); newVariableAccessors.put(name, ivarAccessor); variableAccessors = newVariableAccessors; } } } return ivarAccessor; }
/** * Deserialization proceeds as follows: * * <ol> * <li>Deserialize the object instance. It will have null metaClass and * varTable fields.</li> * <li>Deserialize the name of the object's class, and retrieve class from a * thread-local JRuby instance.</li> * <li>Retrieve each variable in turn, re-assigning them by name.</li> * </ol> * * @see RubyBasicObject#writeObject(java.io.ObjectOutputStream) */ private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException { Ruby ruby = Ruby.getThreadLocalRuntime(); if (ruby == null) { throw new IOException("No thread-local org.jruby.Ruby available; can't deserialize Ruby object. Set with Ruby#setThreadLocalRuntime."); } ois.defaultReadObject(); metaClass = (RubyClass)ruby.getClassFromPath(ois.readUTF()); metaClass.getVariableTableManager().deserializeVariables(this, ois); }
/** * Set the FFI handle for the given object. * * @param self the object * @param self the object's FFI handle */ public final void setFFIHandle(RubyBasicObject self, Object value) { int index = getFFIHandleAccessorForWrite().getIndex(); setVariableInternal(realClass, self, index, value); }