use of org.jikesrvm.classloader.RVMClass in project JikesRVM by JikesRVM.
the class Class method getClasses.
public Class<?>[] getClasses() throws SecurityException {
checkMemberAccess(Member.PUBLIC);
if (!type.isClassType())
return new Class[0];
ArrayList<Class<?>> publicClasses = new ArrayList<Class<?>>();
for (Class<?> c = this; c != null; c = c.getSuperclass()) {
c.checkMemberAccess(Member.PUBLIC);
TypeReference[] declaredClasses = c.type.asClass().getDeclaredClasses();
if (declaredClasses != null) {
for (TypeReference declaredClass : declaredClasses) {
if (declaredClass != null) {
RVMClass dc = declaredClass.resolve().asClass();
if (dc.isPublic()) {
publicClasses.add(dc.getClassForType());
}
}
}
}
}
Class<?>[] result = new Class[publicClasses.size()];
result = publicClasses.toArray(result);
return result;
}
use of org.jikesrvm.classloader.RVMClass in project JikesRVM by JikesRVM.
the class Class method getFieldInternal.
// --- Fields ---
@Pure
private RVMField getFieldInternal(Atom name) {
RVMClass ctype = type.asClass();
// (1) Check my public declared fields
RVMField[] fields = ctype.getDeclaredFields();
for (RVMField field : fields) {
if (field.isPublic() && field.getName() == name) {
return field;
}
}
// (2) Check superinterfaces
RVMClass[] interfaces = ctype.getDeclaredInterfaces();
for (RVMClass anInterface : interfaces) {
RVMField ans = anInterface.getClassForType().getFieldInternal(name);
if (ans != null)
return ans;
}
// (3) Check superclass (if I have one).
if (ctype.getSuperClass() != null) {
return ctype.getSuperClass().getClassForType().getFieldInternal(name);
}
return null;
}
use of org.jikesrvm.classloader.RVMClass in project JikesRVM by JikesRVM.
the class Class method getMethods.
public Method[] getMethods() throws SecurityException {
checkMemberAccess(Member.PUBLIC);
RVMMethod[] static_methods = type.getStaticMethods();
RVMMethod[] virtual_methods = type.getVirtualMethods();
HashSet<Method> coll = new HashSet<Method>(static_methods.length + virtual_methods.length);
for (RVMMethod meth : static_methods) {
if (meth.isPublic()) {
coll.add(JikesRVMSupport.createMethod(meth));
}
}
for (RVMMethod meth : virtual_methods) {
if (meth.isPublic()) {
coll.add(JikesRVMSupport.createMethod(meth));
}
}
// The Java API says that duplicate versions are returned if multiple
// versions of a method are defined by a class. This only applies to
// abstract classes and interfaces because normal classes always have
// exactly one definition for a given signature-name pair.
RVMClass thisClass = type.asClass();
boolean isAbstract = thisClass.isAbstract();
if (isInterface() || isAbstract) {
// For each virtual method , search all superinterfaces
// to find all declarations that aren't shadowed by superinterfaces and
// add those to the set of methods.
HashSet<Method> methods = new HashSet<Method>();
for (RVMMethod m : virtual_methods) {
Atom name = m.getName();
Atom desc = m.getDescriptor();
if (isAbstract && !m.getDeclaringClass().isInterface()) {
// method.
continue;
}
collectDeclarations(thisClass, name, desc, methods);
}
coll.addAll(methods);
}
return coll.toArray(new Method[coll.size()]);
}
use of org.jikesrvm.classloader.RVMClass in project JikesRVM by JikesRVM.
the class VMCommonLibrarySupport method setSystemStreamField.
/**
* Set the value of a static final stream field of the System class
* @param fieldName name of field to set
* @param stream value
*/
static void setSystemStreamField(String fieldName, Object stream) {
try {
RVMField field = ((RVMClass) JikesRVMSupport.getTypeForClass(System.class)).findDeclaredField(Atom.findOrCreateUnicodeAtom(fieldName));
field.setObjectValueUnchecked(null, stream);
} catch (Exception e) {
throw new Error("Error setting stream field " + fieldName + " of java.lang.System", e);
}
}
use of org.jikesrvm.classloader.RVMClass in project JikesRVM by JikesRVM.
the class VMCommonLibrarySupport method construct.
/* ---- Constructor Support ---- */
/**
* Construct an object from the given constructor args, called from the accessing class
*/
@Inline(value = Inline.When.ArgumentsAreConstant, arguments = { 0 })
static Object construct(RVMMethod constructor, Constructor<?> cons, Object[] args, RVMClass accessingClass, ReflectionBase invoker) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
// Check accessibility
if (!constructor.isPublic() && !cons.isAccessible()) {
checkAccess(constructor, accessingClass);
}
// validate number and types of arguments to constructor
if (Reflection.needsCheckArgs(invoker) && !checkArguments(args, constructor)) {
args = makeArgumentsCompatible(args, constructor);
}
RVMClass cls = constructor.getDeclaringClass();
if (cls.isAbstract()) {
throwNewInstantiationException("Abstract class");
}
// Ensure that the class is initialized
if (!cls.isInitialized()) {
runClassInitializer(cls);
}
// Allocate an uninitialized instance;
Object obj = RuntimeEntrypoints.resolvedNewScalar(cls);
// Run the constructor on the instance.
try {
Reflection.invoke(constructor, invoker, obj, args, true);
} catch (Throwable e) {
throw new InvocationTargetException(e);
}
return obj;
}
Aggregations