use of org.jikesrvm.classloader.RVMMethod 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.RVMMethod in project JikesRVM by JikesRVM.
the class Class method getDeclaredConstructor.
public Constructor<T> getDeclaredConstructor(Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException {
checkMemberAccess(Member.DECLARED);
if (!type.isClassType())
throwNoSuchMethodException("<init>", parameterTypes);
RVMMethod answer = null;
if (parameterTypes == null || parameterTypes.length == 0) {
answer = getDefaultConstructor();
} else {
RVMMethod[] methods = type.asClass().getConstructorMethods();
for (RVMMethod method : methods) {
if (parametersMatch(method.getParameterTypes(), parameterTypes)) {
answer = method;
break;
}
}
}
if (answer == null) {
throwNoSuchMethodException("<init>", parameterTypes);
}
return JikesRVMSupport.createConstructor(answer);
}
use of org.jikesrvm.classloader.RVMMethod in project JikesRVM by JikesRVM.
the class Class method getDefaultConstructor.
// --- Constructors ---
@Pure
private RVMMethod getDefaultConstructor() {
if (this.defaultConstructor == null) {
RVMMethod defaultConstructor = null;
RVMMethod[] methods = type.asClass().getConstructorMethods();
for (RVMMethod method : methods) {
if (method.getParameterTypes().length == 0) {
defaultConstructor = method;
break;
}
}
this.defaultConstructor = defaultConstructor;
}
return this.defaultConstructor;
}
use of org.jikesrvm.classloader.RVMMethod in project JikesRVM by JikesRVM.
the class Class method newInstance.
// --- newInstance ---
@Inline(value = Inline.When.ArgumentsAreConstant, arguments = { 0 })
public T newInstance() throws IllegalAccessException, InstantiationException, ExceptionInInitializerError, SecurityException {
// Basic checks
checkMemberAccess(Member.PUBLIC);
if (!type.isClassType())
throw new InstantiationException();
RVMClass cls = type.asClass();
if (cls.isAbstract() || cls.isInterface())
throw new InstantiationException();
// Ensure that the class is initialized
if (!cls.isInitialized()) {
RuntimeEntrypoints.initializeClassForDynamicLink(cls);
}
// Find the defaultConstructor
RVMMethod defaultConstructor = getDefaultConstructor();
if (defaultConstructor == null)
throw new InstantiationException();
// Check that caller is allowed to access it
if (!defaultConstructor.isPublic()) {
RVMClass accessingClass = RVMClass.getClassFromStackFrame(1);
VMCommonLibrarySupport.checkAccess(defaultConstructor, accessingClass);
}
// Allocate an uninitialized instance;
// yes, we're giving an anonymous object a type.
@SuppressWarnings("unchecked") T obj = (T) RuntimeEntrypoints.resolvedNewScalar(cls);
// Run the default constructor on the it.
Reflection.invoke(defaultConstructor, null, obj, null, true);
return obj;
}
use of org.jikesrvm.classloader.RVMMethod in project JikesRVM by JikesRVM.
the class Class method getConstructor.
public Constructor<T> getConstructor(Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException {
checkMemberAccess(Member.PUBLIC);
if (!type.isClassType())
throwNoSuchMethodException("<init>", parameterTypes);
RVMMethod answer = null;
if (parameterTypes == null || parameterTypes.length == 0) {
answer = getDefaultConstructor();
} else {
RVMMethod[] methods = type.asClass().getConstructorMethods();
for (RVMMethod method : methods) {
if (method.isPublic() && parametersMatch(method.getParameterTypes(), parameterTypes)) {
answer = method;
break;
}
}
}
if (answer == null) {
throwNoSuchMethodException("<init>", parameterTypes);
}
return JikesRVMSupport.createConstructor(answer);
}
Aggregations