use of org.jikesrvm.classloader.RVMType in project JikesRVM by JikesRVM.
the class JNIFunctions method GetStaticFieldID.
/**
* GetStaticFieldID: return a field id which can be cached in native code and reused
* @param env A JREF index for the JNI environment object
* @param classJREF a JREF index for the RVMClass object
* @param fieldNameAddress a raw address to a null-terminated string in C for the field name
* @param descriptorAddress a raw address to a null-terminated string in C for the descriptor
* @return the offset of a static field given the class, field name
* and type. Return 0 if the field is not found
* @throws NoSuchFieldError if the specified field cannot be found
* @throws ExceptionInInitializerError if the class initializer fails
* @throws OutOfMemoryError if the system runs out of memory
*/
private static int GetStaticFieldID(JNIEnvironment env, int classJREF, Address fieldNameAddress, Address descriptorAddress) {
if (traceJNI)
VM.sysWriteln("JNI called: GetStaticFieldID");
RuntimeEntrypoints.checkJNICountDownToGC();
try {
Class<?> cls = (Class<?>) env.getJNIRef(classJREF);
String fieldString = JNIGenericHelpers.createStringFromC(fieldNameAddress);
Atom fieldName = Atom.findOrCreateAsciiAtom(fieldString);
String descriptorString = JNIGenericHelpers.createStringFromC(descriptorAddress);
Atom descriptor = Atom.findOrCreateAsciiAtom(descriptorString);
RVMType rvmType = java.lang.JikesRVMSupport.getTypeForClass(cls);
if (rvmType.isClassType()) {
// First search for the fields in the class and its superclasses
for (RVMClass curClass = rvmType.asClass(); curClass != null; curClass = curClass.getSuperClass()) {
for (RVMField field : curClass.getStaticFields()) {
if (field.getName() == fieldName && field.getDescriptor() == descriptor) {
return field.getId();
}
}
}
// Now search all implemented interfaces (includes inherited interfaces)
for (RVMClass curClass : rvmType.asClass().getAllImplementedInterfaces()) {
for (RVMField field : curClass.getStaticFields()) {
if (field.getName() == fieldName && field.getDescriptor() == descriptor) {
return field.getId();
}
}
}
}
env.recordException(new NoSuchFieldError(fieldString + ", " + descriptorString + " of " + cls));
return 0;
} catch (Throwable unexpected) {
if (traceJNI)
unexpected.printStackTrace(System.err);
env.recordException(unexpected);
return 0;
}
}
use of org.jikesrvm.classloader.RVMType in project JikesRVM by JikesRVM.
the class DebugUtil method boot.
@Interruptible
static void boot(BootRecord theBootRecord) {
// get addresses of TIBs for RVMArray & RVMClass used for testing Type ptrs
RVMType t = RVMArray.IntArray;
tibForArrayType = ObjectModel.getTIB(t);
tibForPrimitiveType = ObjectModel.getTIB(RVMType.IntType);
t = Magic.getObjectType(BootRecord.the_boot_record);
tibForClassType = ObjectModel.getTIB(t);
}
use of org.jikesrvm.classloader.RVMType in project JikesRVM by JikesRVM.
the class JavaHeader method initializeScalarHeader.
/**
* Perform any required initialization of the JAVA portion of the header.
* @param bootImage The bootimage being written
* @param ptr The object ref to the storage to be initialized
* @param tib The TIB of the instance being created
* @param size The number of bytes allocated by the GC system for this object.
* @param needsIdentityHash needs an identity hash value
* @param identityHashValue the value for the identity hash
* @return the address used for a reference to this object
*/
@Interruptible
public static Address initializeScalarHeader(BootImageInterface bootImage, Address ptr, TIB tib, int size, boolean needsIdentityHash, int identityHashValue) {
Address ref = ptr.plus(OBJECT_REF_OFFSET);
if (needsIdentityHash) {
bootImage.setFullWord(ref.plus(STATUS_OFFSET), HASH_STATE_HASHED_AND_MOVED.toInt());
if (DYNAMIC_HASH_OFFSET) {
// Read the size of this object.
RVMType t = tib.getType();
bootImage.setFullWord(ptr.plus(t.asClass().getInstanceSize()), identityHashValue);
} else {
ref = ref.plus(HASHCODE_BYTES);
bootImage.setFullWord(ref.plus(HASHCODE_OFFSET), (identityHashValue << 1) | ALIGNMENT_MASK);
}
} else {
// As boot image objects can't move there is no benefit in lazily setting them to hashed
bootImage.setFullWord(ref.plus(STATUS_OFFSET), HASH_STATE_HASHED.toInt());
}
return ref;
}
use of org.jikesrvm.classloader.RVMType in project JikesRVM by JikesRVM.
the class JavaHeader method initializeArrayHeader.
/**
* Perform any required initialization of the JAVA portion of the header.
*
* @param bootImage the bootimage being written
* @param ptr the object ref to the storage to be initialized
* @param tib the TIB of the instance being created
* @param size the number of bytes allocated by the GC system for this object.
* @param numElements the number of elements in the array
* @param needsIdentityHash needs an identity hash value
* @param identityHashValue the value for the identity hash
* @return the address used for a reference to this object
*/
@Interruptible
public static Address initializeArrayHeader(BootImageInterface bootImage, Address ptr, TIB tib, int size, int numElements, boolean needsIdentityHash, int identityHashValue) {
Address ref = ptr.plus(OBJECT_REF_OFFSET);
// (TIB set by BootImageWriter; array length set by ObjectModel)
if (needsIdentityHash) {
bootImage.setFullWord(ref.plus(STATUS_OFFSET), HASH_STATE_HASHED_AND_MOVED.toInt());
if (DYNAMIC_HASH_OFFSET) {
// Read the size of this object.
RVMType t = tib.getType();
bootImage.setFullWord(ptr.plus(t.asArray().getInstanceSize(numElements)), identityHashValue);
} else {
ref = ref.plus(HASHCODE_BYTES);
bootImage.setFullWord(ref.plus(HASHCODE_OFFSET), (identityHashValue << 1) | ALIGNMENT_MASK);
}
} else {
// As boot image objects can't move there is no benefit in lazily setting them to hashed
bootImage.setFullWord(ref.plus(STATUS_OFFSET), HASH_STATE_HASHED.toInt());
}
return ref;
}
use of org.jikesrvm.classloader.RVMType in project JikesRVM by JikesRVM.
the class ObjectModel method getObjectEndAddress.
/**
* Get the pointer just past an object.
*
* @param obj the object in question
* @return first word after the object
*/
public static Address getObjectEndAddress(Object obj) {
TIB tib = getTIB(obj);
RVMType type = tib.getType();
if (type.isClassType()) {
return getObjectEndAddress(obj, type.asClass());
} else {
int numElements = Magic.getArrayLength(obj);
return getObjectEndAddress(obj, type.asArray(), numElements);
}
}
Aggregations