use of org.jikesrvm.classloader.Atom in project JikesRVM by JikesRVM.
the class EntrypointHelper method getField.
/**
* Get description of virtual machine field.
* @param klass class containing field
* @param member member name - something like "invokestatic"
* @param type of field
* @return corresponding RVMField
*/
static RVMField getField(String klass, String member, Class<?> type) {
if (!VM.runningVM) {
// avoid compiling this code into the boot image
try {
TypeReference tRef = TypeReference.findOrCreate(klass);
RVMClass cls = tRef.resolve().asClass();
cls.resolve();
Atom memName = Atom.findOrCreateAsciiAtom(member);
Atom typeName = TypeReference.findOrCreate(type).getName();
RVMField field = cls.findDeclaredField(memName, typeName);
if (field != null) {
verifyPresenceOfEntrypointAnnotation(field);
verifyThatFieldIsNotFinal(field);
return field;
}
} catch (Throwable t) {
throw new Error("Entrypoints.getField: can't resolve class=" + klass + " member=" + member + " desc=" + type, t);
}
}
throw new Error("Entrypoints.getField: can't resolve class=" + klass + " member=" + member + " desc=" + type);
}
use of org.jikesrvm.classloader.Atom 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.Atom in project JikesRVM by JikesRVM.
the class JNIFunctions method GetFieldID.
/**
* GetFieldID: 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 fieldID of an instance 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 GetFieldID(JNIEnvironment env, int classJREF, Address fieldNameAddress, Address descriptorAddress) {
if (traceJNI)
VM.sysWriteln("JNI called: GetFieldID");
RuntimeEntrypoints.checkJNICountDownToGC();
try {
if (traceJNI)
VM.sysWriteln("called GetFieldID with classJREF = ", classJREF);
Class<?> cls = (Class<?>) env.getJNIRef(classJREF);
if (VM.VerifyAssertions)
VM._assert(cls != null);
String fieldString = JNIGenericHelpers.createStringFromC(fieldNameAddress);
Atom fieldName = Atom.findOrCreateAsciiAtom(fieldString);
String descriptorString = JNIGenericHelpers.createStringFromC(descriptorAddress);
Atom descriptor = Atom.findOrCreateAsciiAtom(descriptorString);
// list of all instance fields including superclasses.
// Iterate in reverse order since if there are multiple instance
// fields of the same name & descriptor we want to find the most derived one.
RVMField[] fields = java.lang.JikesRVMSupport.getTypeForClass(cls).getInstanceFields();
for (int i = fields.length - 1; i >= 0; i--) {
RVMField f = fields[i];
if (f.getName() == fieldName && f.getDescriptor() == descriptor) {
return f.getId();
}
}
// create exception and return 0 if not found
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.Atom in project JikesRVM by JikesRVM.
the class OptTestHarnessTest method getTypeReferenceForClass.
private TypeReference getTypeReferenceForClass(String className) {
Atom classDescriptorAsAtom = Atom.findAsciiAtom(className).descriptorFromClassName();
ClassLoader appCl = ApplicationClassLoader.getSystemClassLoader();
return TypeReference.findOrCreate(appCl, classDescriptorAsAtom);
}
Aggregations