/** * Store a value into a reference field of an object. * * @param object The object to store the field of. * @param index The field index. * @param value The value to store. */ public void storeReferenceField(ObjectReference object, int index, ObjectReference value) { int limit = ObjectModel.getRefs(object); if (Trace.isEnabled(Item.STORE) || ObjectModel.isWatched(object)) { Trace.printf( Item.STORE, "[%s].object[%d/%d] = %s", ObjectModel.getString(object), index, limit, value.toString()); } check(!object.isNull(), "Object can not be null"); check(index >= 0, "Index must be non-negative"); check(index < limit, "Index " + index + " out of bounds " + limit); Address referenceSlot = ObjectModel.getRefSlot(object, index); if (ActivePlan.constraints.needsWriteBarrier()) { context.writeBarrier(object, referenceSlot, value, null, null, Plan.AASTORE_WRITE_BARRIER); if (gcEveryWB) { gc(); } } else { referenceSlot.store(value); } }
/** Prints the address of the object. */ @Override public String toString() { if (value.isNull()) { return "null"; } return value.toString(); }
/** * Store a value into the data field of an object. * * @param object The object to store the field of. * @param index The field index. * @param value The value to store. */ public void storeDataField(ObjectReference object, int index, int value) { int limit = ObjectModel.getDataCount(object); check(!object.isNull(), "Object can not be null"); check(index >= 0, "Index must be non-negative"); check(index < limit, "Index " + index + " out of bounds " + limit); Address ref = ObjectModel.getDataSlot(object, index); ref.store(value); Trace.trace(Item.STORE, "%s.[%d] = %d", object.toString(), index, value); }
/** * Load and return the value of a reference field of an object. * * @param object The object to load the field of. * @param index The field index. */ public ObjectReference loadReferenceField(ObjectReference object, int index) { int limit = ObjectModel.getRefs(object); check(!object.isNull(), "Object can not be null"); check(index >= 0, "Index must be non-negative"); check(index < limit, "Index " + index + " out of bounds " + limit); Address referenceSlot = ObjectModel.getRefSlot(object, index); ObjectReference result; if (ActivePlan.constraints.needsReadBarrier()) { result = context.readBarrier(object, referenceSlot, null, null, Plan.AASTORE_WRITE_BARRIER); } else { result = referenceSlot.loadObjectReference(); } Trace.trace( Item.LOAD, "[%s].object[%d] returned [%s]", ObjectModel.getString(object), index, result.toString()); return result; }