use of org.jikesrvm.classloader.Atom in project JikesRVM by JikesRVM.
the class ClassLoaderProxy method lookupMethod.
// --------------------------------------------------------------------------
// Querry classloader data structures
// --------------------------------------------------------------------------
/**
* Find the method of the given class that matches the given descriptor.
*
* @param cls the method's class
* @param ref name and descriptor of the method
* @return a matching method or {@code null} if none was found
*/
public static RVMMethod lookupMethod(RVMClass cls, MethodReference ref) {
RVMMethod newmeth = null;
if (cls.isResolved() && !cls.isInterface()) {
Atom mn = ref.getName();
Atom md = ref.getDescriptor();
for (; (newmeth == null) && (cls != null); cls = cls.getSuperClass()) {
newmeth = cls.findDeclaredMethod(mn, md);
}
}
return newmeth;
}
use of org.jikesrvm.classloader.Atom in project JikesRVM by JikesRVM.
the class Class method forNameInternal.
private static Class<?> forNameInternal(String className, boolean initialize, ClassLoader classLoader) throws ClassNotFoundException, LinkageError, ExceptionInInitializerError {
if (className == null) {
throw new ClassNotFoundException("Cannot load a class with a name of null");
}
try {
if (className.startsWith("[")) {
if (!validArrayDescriptor(className)) {
throw new ClassNotFoundException(className);
}
}
Atom descriptor = Atom.findOrCreateAsciiAtom(className.replace('.', '/')).descriptorFromClassName();
TypeReference tRef = TypeReference.findOrCreate(classLoader, descriptor);
RVMType ans = tRef.resolve();
Callbacks.notifyForName(ans);
if (initialize && !ans.isInitialized()) {
ans.prepareForFirstUse();
}
return ans.getClassForType();
} catch (NoClassDefFoundError ncdfe) {
Throwable cause2 = ncdfe.getCause();
ClassNotFoundException cnf;
// If we get a NCDFE that was caused by a CNFE, throw the original CNFE.
if (cause2 instanceof ClassNotFoundException)
cnf = (ClassNotFoundException) cause2;
else
cnf = new ClassNotFoundException(className, ncdfe);
throw cnf;
}
}
use of org.jikesrvm.classloader.Atom in project JikesRVM by JikesRVM.
the class Class method getMethod.
public Method getMethod(String name, Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException {
throwNPEWhenNameIsNull(name);
checkMemberAccess(Member.PUBLIC);
if (!type.isClassType())
throwNoSuchMethodException(name, parameterTypes);
Atom aName = Atom.findOrCreateUnicodeAtom(name);
if (aName == RVMClassLoader.StandardClassInitializerMethodName || aName == RVMClassLoader.StandardObjectInitializerMethodName) {
// <init> and <clinit> are not methods.
throwNoSuchMethodException(name, parameterTypes);
}
// (1) Scan the declared public methods of this class and each of its superclasses
RVMMethod answer = getMethodInternal1(aName, parameterTypes);
if (answer == null) {
// (2) Now we need to consider methods inherited from interfaces.
// Because we inject the requisite Miranda methods, we can do this simply
// by looking at this class's virtual methods instead of searching interface hierarchies.
answer = getMethodInternal2(aName, parameterTypes);
}
if (answer == null) {
throwNoSuchMethodException(name, parameterTypes);
}
return JikesRVMSupport.createMethod(answer);
}
use of org.jikesrvm.classloader.Atom 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.Atom in project JikesRVM by JikesRVM.
the class Class method getDeclaredMethod.
public Method getDeclaredMethod(String name, Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException {
throwNPEWhenNameIsNull(name);
checkMemberAccess(Member.DECLARED);
if (!type.isClassType())
throwNoSuchMethodException(name, parameterTypes);
if (name == null) {
throwNoSuchMethodException(name, parameterTypes);
}
Atom aName = Atom.findOrCreateUnicodeAtom(name);
if (aName == RVMClassLoader.StandardClassInitializerMethodName || aName == RVMClassLoader.StandardObjectInitializerMethodName) {
// <init> and <clinit> are not methods.
throwNoSuchMethodException(name, parameterTypes);
}
RVMMethod[] methods = type.asClass().getDeclaredMethods();
RVMMethod answer = null;
for (RVMMethod meth : methods) {
if (meth.getName() == aName && parametersMatch(meth.getParameterTypes(), parameterTypes)) {
if (answer == null) {
answer = meth;
} else {
RVMMethod m2 = meth;
if (answer.getReturnType().resolve().isAssignableFrom(m2.getReturnType().resolve())) {
answer = m2;
}
}
}
}
if (answer == null) {
throwNoSuchMethodException(name, parameterTypes);
}
return JikesRVMSupport.createMethod(answer);
}
Aggregations