use of org.jikesrvm.classloader.RVMClass 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.RVMClass in project JikesRVM by JikesRVM.
the class Class method getDeclaredClasses.
public Class<?>[] getDeclaredClasses() throws SecurityException {
checkMemberAccess(Member.DECLARED);
if (!type.isClassType())
return new Class[0];
// Get array of declared classes from RVMClass object
RVMClass cls = type.asClass();
TypeReference[] declaredClasses = cls.getDeclaredClasses();
// The array can be null if the class has no declared inner class members
if (declaredClasses == null)
return new Class[0];
// Count the number of actual declared inner and static classes.
// (The array may contain null elements, which we want to skip.)
int count = 0;
int length = declaredClasses.length;
for (int i = 0; i < length; ++i) {
if (declaredClasses[i] != null) {
++count;
}
}
// Now build actual result array.
Class<?>[] result = new Class[count];
count = 0;
for (int i = 0; i < length; ++i) {
if (declaredClasses[i] != null) {
result[count++] = declaredClasses[i].resolve().getClassForType();
}
}
return result;
}
use of org.jikesrvm.classloader.RVMClass 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.RVMClass 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.RVMClass in project JikesRVM by JikesRVM.
the class VMCommonLibrarySupport method checkAccess.
/* ---- General Reflection Support ---- */
/**
* Check to see if a method declared by the accessingClass
* should be allowed to access the argument RVMMember.
* Assumption: member is not public. This trivial case should
* be approved by the caller without needing to call this method.
*/
static void checkAccess(RVMMember member, RVMClass accessingClass) throws IllegalAccessException {
RVMClass declaringClass = member.getDeclaringClass();
if (member.isPrivate()) {
// access from the declaringClass is allowed
if (accessingClass == declaringClass)
return;
} else if (member.isProtected()) {
// access within the package is allowed.
if (declaringClass.getClassLoader() == accessingClass.getClassLoader() && declaringClass.getPackageName().equals(accessingClass.getPackageName()))
return;
// access by subclasses is allowed.
for (RVMClass cls = accessingClass; cls != null; cls = cls.getSuperClass()) {
if (accessingClass == declaringClass)
return;
}
} else {
// default: access within package is allowed
if (declaringClass.getClassLoader() == accessingClass.getClassLoader() && declaringClass.getPackageName().equals(accessingClass.getPackageName()))
return;
}
throwNewIllegalAccessException(member, accessingClass);
}
Aggregations