use of org.jikesrvm.classloader.RVMType in project JikesRVM by JikesRVM.
the class JNIFunctions method RegisterNatives.
/**
* RegisterNatives: registers implementation of native methods
* @param env A JREF index for the JNI environment object
* @param classJREF a JREF index for the class to register native methods in
* @param methodsAddress the address of an array of native methods to be registered
* @param nmethods the number of native methods in the array
* @return 0 is successful -1 if failed
* @throws NoSuchMethodError if a specified method cannot be found or is not native
*/
private static int RegisterNatives(JNIEnvironment env, int classJREF, Address methodsAddress, int nmethods) {
if (traceJNI)
VM.sysWriteln("JNI called: RegisterNatives");
RuntimeEntrypoints.checkJNICountDownToGC();
try {
// get the target class
Class<?> jcls = (Class<?>) env.getJNIRef(classJREF);
RVMType type = java.lang.JikesRVMSupport.getTypeForClass(jcls);
if (!type.isClassType()) {
env.recordException(new NoSuchMethodError());
return 0;
}
RVMClass klass = type.asClass();
if (!klass.isInitialized()) {
RuntimeEntrypoints.initializeClassForDynamicLink(klass);
}
// Create list of methods and verify them to avoid partial success
NativeMethod[] methods = new NativeMethod[nmethods];
AddressArray symbols = AddressArray.create(nmethods);
Address curMethod = methodsAddress;
for (int i = 0; i < nmethods; i++) {
String methodString = JNIGenericHelpers.createStringFromC(curMethod.loadAddress());
Atom methodName = Atom.findOrCreateAsciiAtom(methodString);
String sigString = JNIGenericHelpers.createStringFromC(curMethod.loadAddress(Offset.fromIntSignExtend(BYTES_IN_ADDRESS)));
Atom sigName = Atom.findOrCreateAsciiAtom(sigString);
// Find the target method
RVMMethod meth = klass.findDeclaredMethod(methodName, sigName);
if (meth == null || !meth.isNative()) {
env.recordException(new NoSuchMethodError(klass + ": " + methodName + " " + sigName));
return -1;
}
methods[i] = (NativeMethod) meth;
symbols.set(i, curMethod.loadAddress(Offset.fromIntSignExtend(BYTES_IN_ADDRESS * 2)));
curMethod = curMethod.plus(3 * BYTES_IN_ADDRESS);
}
// Register methods
for (int i = 0; i < nmethods; i++) {
methods[i].registerNativeSymbol(symbols.get(i));
}
return 0;
} catch (Throwable unexpected) {
if (traceJNI)
unexpected.printStackTrace(System.err);
env.recordException(unexpected);
return -1;
}
}
use of org.jikesrvm.classloader.RVMType in project JikesRVM by JikesRVM.
the class JNIFunctions method GetStaticMethodID.
/**
* GetStaticMethodID: return the method ID for invocation later
* @param env A JREF index for the JNI environment object
* @param classJREF a JREF index for the class object
* @param methodNameAddress a raw address to a null-terminated string in C for the method name
* @param methodSigAddress a raw address to a null-terminated string in C for (TODO: document me)
* @return a method ID or null if it fails
* @throws NoSuchMethodError if the method is not found
* @throws ExceptionInInitializerError if the initializer fails
* @throws OutOfMemoryError if the system runs out of memory
*/
private static int GetStaticMethodID(JNIEnvironment env, int classJREF, Address methodNameAddress, Address methodSigAddress) {
if (traceJNI)
VM.sysWriteln("JNI called: GetStaticMethodID");
RuntimeEntrypoints.checkJNICountDownToGC();
try {
// obtain the names as String from the native space
String methodString = JNIGenericHelpers.createStringFromC(methodNameAddress);
Atom methodName = Atom.findOrCreateAsciiAtom(methodString);
String sigString = JNIGenericHelpers.createStringFromC(methodSigAddress);
Atom sigName = Atom.findOrCreateAsciiAtom(sigString);
// get the target class
Class<?> jcls = (Class<?>) env.getJNIRef(classJREF);
RVMType type = java.lang.JikesRVMSupport.getTypeForClass(jcls);
if (!type.isClassType()) {
env.recordException(new NoSuchMethodError());
return 0;
}
RVMClass klass = type.asClass();
if (!klass.isInitialized()) {
RuntimeEntrypoints.initializeClassForDynamicLink(klass);
}
// Find the target method
RVMMethod meth = klass.findStaticMethod(methodName, sigName);
if (meth == null) {
env.recordException(new NoSuchMethodError());
return 0;
}
if (traceJNI)
VM.sysWriteln("got method " + meth);
return meth.getId();
} 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 JNIFunctions method GetMethodID.
/**
* GetMethodID: get the virtual method ID given the name and the signature
* @param env A JREF index for the JNI environment object
* @param classJREF a JREF index for the class object
* @param methodNameAddress a raw address to a null-terminated string in C for the method name
* @param methodSigAddress a raw address to a null-terminated string in C for the method signature
* @return id of a MethodReference
* @throws NoSuchMethodError if the method cannot be found
* @throws ExceptionInInitializerError if the class or interface static initializer fails
* @throws OutOfMemoryError if the system runs out of memory
*/
private static int GetMethodID(JNIEnvironment env, int classJREF, Address methodNameAddress, Address methodSigAddress) {
if (traceJNI)
VM.sysWriteln("JNI called: GetMethodID");
RuntimeEntrypoints.checkJNICountDownToGC();
try {
// obtain the names as String from the native space
String methodString = JNIGenericHelpers.createStringFromC(methodNameAddress);
Atom methodName = Atom.findOrCreateAsciiAtom(methodString);
String sigString = JNIGenericHelpers.createStringFromC(methodSigAddress);
Atom sigName = Atom.findOrCreateAsciiAtom(sigString);
// get the target class
Class<?> jcls = (Class<?>) env.getJNIRef(classJREF);
RVMType type = java.lang.JikesRVMSupport.getTypeForClass(jcls);
if (!type.isClassType()) {
env.recordException(new NoSuchMethodError());
return 0;
}
RVMClass klass = type.asClass();
if (!klass.isInitialized()) {
RuntimeEntrypoints.initializeClassForDynamicLink(klass);
}
// Find the target method
final RVMMethod meth;
if (methodString.equals("<init>")) {
meth = klass.findInitializerMethod(sigName);
} else {
meth = klass.findVirtualMethod(methodName, sigName);
}
if (meth == null) {
env.recordException(new NoSuchMethodError(klass + ": " + methodName + " " + sigName));
return 0;
}
if (traceJNI)
VM.sysWriteln("got method " + meth);
return meth.getId();
} 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 JNIFunctions method UnregisterNatives.
/**
* UnregisterNatives: unregisters native methods
* @param env A JREF index for the JNI environment object
* @param classJREF a JREF index for the class to register native methods in
* @return 0 is successful -1 if failed
*/
private static int UnregisterNatives(JNIEnvironment env, int classJREF) {
if (traceJNI)
VM.sysWriteln("JNI called: UnregisterNatives");
RuntimeEntrypoints.checkJNICountDownToGC();
try {
// get the target class
Class<?> jcls = (Class<?>) env.getJNIRef(classJREF);
RVMType type = java.lang.JikesRVMSupport.getTypeForClass(jcls);
if (!type.isClassType()) {
env.recordException(new NoClassDefFoundError());
return -1;
}
RVMClass klass = type.asClass();
if (!klass.isInitialized()) {
return 0;
}
klass.unregisterNativeMethods();
return 0;
} catch (Throwable unexpected) {
if (traceJNI)
unexpected.printStackTrace(System.err);
env.recordException(unexpected);
return -1;
}
}
use of org.jikesrvm.classloader.RVMType in project JikesRVM by JikesRVM.
the class DebugUtil method dumpRef.
@Uninterruptible
public static void dumpRef(ObjectReference ref) {
VM.sysWrite("REF=");
if (ref.isNull()) {
VM.sysWriteln("NULL");
VM.sysWriteln();
return;
}
VM.sysWrite(ref);
if (!mappedVMRef(ref)) {
VM.sysWriteln(" (REF OUTSIDE OF HEAP OR NOT MAPPED)");
return;
}
ObjectModel.dumpHeader(ref);
ObjectReference tib = ObjectReference.fromObject(ObjectModel.getTIB(ref));
if (!MemoryManager.mightBeTIB(tib)) {
VM.sysWriteln(" (INVALID TIB: CLASS NOT ACCESSIBLE)");
return;
}
RVMType type = Magic.getObjectType(ref.toObject());
ObjectReference itype = ObjectReference.fromObject(type);
VM.sysWrite(" TYPE=");
VM.sysWrite(itype);
if (!validType(itype)) {
VM.sysWriteln(" (INVALID TYPE: CLASS NOT ACCESSIBLE)");
return;
}
VM.sysWrite(" CLASS=");
VM.sysWrite(type.getDescriptor());
VM.sysWriteln();
}
Aggregations