use of org.jikesrvm.classloader.Atom in project JikesRVM by JikesRVM.
the class VM method runClassInitializer.
/**
* Run {@code <clinit>} method of specified class, if that class appears
* in bootimage and actually has a clinit method (we are flexible to
* allow one list of classes to work with different bootimages and
* different version of classpath (eg 0.05 vs. cvs head).
* <p>
* This method is called only while the VM boots.
*
* @param className class whose initializer needs to be run
*/
@Interruptible
static void runClassInitializer(String className) {
if (verboseBoot >= 2) {
sysWrite("running class initializer for ");
sysWriteln(className);
}
Atom classDescriptor = Atom.findOrCreateAsciiAtom(className.replace('.', '/')).descriptorFromClassName();
TypeReference tRef = TypeReference.findOrCreate(BootstrapClassLoader.getBootstrapClassLoader(), classDescriptor);
RVMClass cls = (RVMClass) tRef.peekType();
if (null == cls) {
sysWrite("Failed to run class initializer for ");
sysWrite(className);
sysWriteln(" as the class does not exist.");
} else if (!cls.isInBootImage()) {
sysWrite("Failed to run class initializer for ");
sysWrite(className);
sysWriteln(" as the class is not in the boot image.");
} else {
RVMMethod clinit = cls.getClassInitializerMethod();
if (clinit != null) {
clinit.compile();
if (verboseBoot >= 10)
VM.sysWriteln("invoking method " + clinit);
try {
Magic.invokeClassInitializer(clinit.getCurrentEntryCodeArray());
} catch (Error e) {
throw e;
} catch (Throwable t) {
ExceptionInInitializerError eieio = new ExceptionInInitializerError(t);
throw eieio;
}
// <clinit> is no longer needed: reclaim space by removing references to it
clinit.invalidateCompiledMethod(clinit.getCurrentCompiledMethod());
} else {
if (verboseBoot >= 10)
VM.sysWriteln("has no clinit method ");
}
cls.setAllFinalStaticJTOCEntries();
}
}
use of org.jikesrvm.classloader.Atom in project JikesRVM by JikesRVM.
the class Class method getTypeParameters.
@Override
@SuppressWarnings("unchecked")
public TypeVariable<Class<T>>[] getTypeParameters() {
if (!type.isClassType()) {
return new TypeVariable[0];
} else {
RVMClass klass = type.asClass();
Atom sig = klass.getSignature();
if (sig == null) {
return new TypeVariable[0];
} else {
return JikesRVMHelpers.getTypeParameters(this, sig);
}
}
}
use of org.jikesrvm.classloader.Atom in project JikesRVM by JikesRVM.
the class Class method getDeclaredField.
public Field getDeclaredField(String name) throws NoSuchFieldException, SecurityException {
throwNPEWhenNameIsNull(name);
checkMemberAccess(Member.DECLARED);
if (!type.isClassType() || name == null)
throwNoSuchFieldException(name);
Atom aName = Atom.findOrCreateUnicodeAtom(name);
RVMField answer = type.asClass().findDeclaredField(aName);
if (answer == null) {
throwNoSuchFieldException(name);
}
return JikesRVMSupport.createField(answer);
}
use of org.jikesrvm.classloader.Atom in project JikesRVM by JikesRVM.
the class Class method getField.
public Field getField(String name) throws NoSuchFieldException, SecurityException {
throwNPEWhenNameIsNull(name);
checkMemberAccess(Member.PUBLIC);
if (!type.isClassType())
throw new NoSuchFieldException();
Atom aName = Atom.findUnicodeAtom(name);
if (aName == null)
throwNoSuchFieldException(name);
RVMField answer = getFieldInternal(aName);
if (answer == null) {
throwNoSuchFieldException(name);
}
return JikesRVMSupport.createField(answer);
}
use of org.jikesrvm.classloader.Atom 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;
}
}
Aggregations