use of org.jikesrvm.classloader.RVMField in project JikesRVM by JikesRVM.
the class JNIFunctions method SetIntField.
/**
* SetIntField: set an instance field of type integer
* @param env A JREF index for the JNI environment object
* @param objJREF a JREF index for the target object
* @param fieldID the id for the RVMField that describes this field
* @param value integer value to assign
*/
private static void SetIntField(JNIEnvironment env, int objJREF, int fieldID, int value) {
if (traceJNI)
VM.sysWriteln("JNI called: SetIntField");
RuntimeEntrypoints.checkJNICountDownToGC();
try {
Object obj = env.getJNIRef(objJREF);
RVMField field = MemberReference.getFieldRef(fieldID).resolve();
field.setIntValueUnchecked(obj, value);
} catch (Throwable unexpected) {
if (traceJNI)
unexpected.printStackTrace(System.err);
env.recordException(unexpected);
}
}
use of org.jikesrvm.classloader.RVMField in project JikesRVM by JikesRVM.
the class JNIFunctions method SetBooleanField.
/**
* SetBooleanField: set an instance field of type boolean
* @param env A JREF index for the JNI environment object
* @param objJREF a JREF index for the target object
* @param fieldID the id for the RVMField that describes this field
* @param value boolean value to assign
*/
private static void SetBooleanField(JNIEnvironment env, int objJREF, int fieldID, boolean value) {
if (traceJNI)
VM.sysWriteln("JNI called: SetBooleanField");
RuntimeEntrypoints.checkJNICountDownToGC();
try {
Object obj = env.getJNIRef(objJREF);
RVMField field = MemberReference.getFieldRef(fieldID).resolve();
field.setBooleanValueUnchecked(obj, value);
} catch (Throwable unexpected) {
if (traceJNI)
unexpected.printStackTrace(System.err);
env.recordException(unexpected);
}
}
use of org.jikesrvm.classloader.RVMField in project JikesRVM by JikesRVM.
the class JNIFunctions method SetStaticIntField.
/**
* SetStaticIntField: set a static field of type integer
* @param env A JREF index for the JNI environment object
* @param classJREF a JREF index for the RVMClass object
* @param fieldID the id for the RVMField that describes this field
* @param fieldValue The value to assign
*/
private static void SetStaticIntField(JNIEnvironment env, int classJREF, int fieldID, int fieldValue) {
if (traceJNI)
VM.sysWriteln("JNI called: SetStaticIntField");
RuntimeEntrypoints.checkJNICountDownToGC();
try {
RVMField field = MemberReference.getFieldRef(fieldID).resolve();
field.setIntValueUnchecked(null, fieldValue);
} catch (Throwable unexpected) {
if (traceJNI)
unexpected.printStackTrace(System.err);
env.recordException(unexpected);
}
}
use of org.jikesrvm.classloader.RVMField in project JikesRVM by JikesRVM.
the class JNIFunctions method SetFloatField.
/**
* SetFloatField: set an instance field of type float
* @param env A JREF index for the JNI environment object
* @param objJREF a JREF index for the target object
* @param fieldID the id for the RVMField that describes this field
* @param value float value to assign
*/
private static void SetFloatField(JNIEnvironment env, int objJREF, int fieldID, float value) {
if (traceJNI)
VM.sysWriteln("JNI called: SetFloatField");
RuntimeEntrypoints.checkJNICountDownToGC();
try {
Object obj = env.getJNIRef(objJREF);
RVMField field = MemberReference.getFieldRef(fieldID).resolve();
field.setFloatValueUnchecked(obj, value);
} catch (Throwable unexpected) {
if (traceJNI)
unexpected.printStackTrace(System.err);
env.recordException(unexpected);
}
}
use of org.jikesrvm.classloader.RVMField 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;
}
}
Aggregations