use of org.jikesrvm.classloader.Atom 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.Atom 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.Atom in project JikesRVM by JikesRVM.
the class InterfaceHierarchy method getUniqueImplementation.
/**
* If, in the current class hierarchy, there is exactly one method that
* defines the interface method foo, then return the unique
* implementation. If there is not a unique implementation, return
* null.
*
* @param foo an interface method
* @return the unique implementation if it exists, {@code null} otherwise
*/
public static synchronized RVMMethod getUniqueImplementation(RVMMethod foo) {
RVMClass I = foo.getDeclaringClass();
ImmutableEntryHashSetRVM<RVMClass> classes = allImplementors(I);
RVMMethod firstMethod = null;
Atom name = foo.getName();
Atom desc = foo.getDescriptor();
for (RVMClass klass : classes) {
RVMMethod m = klass.findDeclaredMethod(name, desc);
if (firstMethod == null) {
firstMethod = m;
}
if (m != firstMethod) {
return null;
}
}
return firstMethod;
}
use of org.jikesrvm.classloader.Atom in project JikesRVM by JikesRVM.
the class CompilerAdviceInfoReader method readOneAttribute.
/**
* Actual reading is done here. This method reads one attribute
* from a single line of an input stream. There are six elements
* per line corresponding to each call site. First three are
* strings, <i>class name</i>, <i>method name</i>, <i>method
* signature</i>, followed by one number,
* <i>compiler advice</i>.
*
* @param st an input stream
* @return an compileration advice atribute
*/
private static CompilerAdviceAttribute readOneAttribute(StringTokenizer st) {
int compiler, optLevel = -1;
try {
Atom cls = Atom.findOrCreateUnicodeAtom(st.nextToken());
Atom mth = Atom.findOrCreateUnicodeAtom(st.nextToken());
Atom sig = Atom.findOrCreateUnicodeAtom(st.nextToken());
compiler = Integer.parseInt(st.nextToken());
optLevel = Integer.parseInt(st.nextToken());
// this is the attribute which will be returned
CompilerAdviceAttribute newAttrib;
if (optLevel >= 0) {
newAttrib = new CompilerAdviceAttribute(cls, mth, sig, compiler, optLevel);
} else {
newAttrib = new CompilerAdviceAttribute(cls, mth, sig, compiler);
}
return newAttrib;
} catch (NoSuchElementException e) {
return null;
}
}
use of org.jikesrvm.classloader.Atom in project JikesRVM by JikesRVM.
the class OptTestHarness method findDeclaredOrFirstMethod.
/**
* Finds a method, either one with a given descriptor or the first matching
* one in in the given class.
* @param klass the class to search
* @param methname the method's name
* @param methdesc a descriptor of the method's signature if a specific
* method is desired or "-" to find the first method with the given name
* @return the method or {@code null} if no method was found
*/
RVMMethod findDeclaredOrFirstMethod(RVMClass klass, String methname, String methdesc) {
if (klass == null)
return null;
Atom methodName = Atom.findOrCreateAsciiAtom(methname);
Atom methodDesc = "-".equals(methdesc) ? null : Atom.findOrCreateAsciiAtom(methdesc);
for (RVMMethod method : klass.getDeclaredMethods()) {
if (method.getName() == methodName && ((methodDesc == null) || (methodDesc == method.getDescriptor()))) {
return method;
}
}
if (methodDesc == null) {
output.sysErrPrintln("No method named " + methodName + " found in class " + klass);
} else {
output.sysErrPrintln("No method matching " + methodName + " " + methodDesc + " found in class " + klass);
}
return null;
}
Aggregations