use of com.jopdesign.common.misc.Ternary in project jop by jop-devel.
the class InvokeSite method isSuperMethod.
/**
* Check if this invokespecial is a super invoke. Does NOT check if the instruction is indeed an
* special invoke, check this first!
* See #isInvokeSuper() for more details.
*
* @param invokee the method referenced by the instruction.
* @return true if this references to a super method
*/
private boolean isSuperMethod(MethodRef invokee) {
// This is the class where the invoker method is defined (not the class of the object instance!)
ClassInfo cls = invoker.getClassInfo();
if (!cls.hasSuperFlag())
return false;
if ("<init>".equals(invokee.getName()))
return false;
// just to handle some special cases of unknown superclasses gracefully, without requiring a classInfo
if (cls.getClassName().equals(invokee.getClassName())) {
// this is an invoke within the same class, no super here
return false;
}
if (cls.isRootClass()) {
// trying to call a super-method of Object? Not likely, dude ..
return false;
}
// do not need to check interfaces, since invokespecial must not call interface methods
Ternary rs = cls.hasSuperClass(invokee.getClassName(), false);
if (rs == Ternary.UNKNOWN) {
if (invokee.getClassRef().getClassInfo() != null) {
// class exists, but method does not exists, either an error or superclasses are missing
throw new JavaClassFormatError("Invokespecial tries to call " + invokee + " but this method has not been found");
}
// invokespecial to an unknown class, we cannot handle this safely
throw new JavaClassFormatError("Could not determine if invokespecial is a super invoke for " + invokee);
}
return rs == Ternary.TRUE;
}
use of com.jopdesign.common.misc.Ternary in project jop by jop-devel.
the class AppInfo method getThreadRootMethods.
/**
* Find all Runnable.run() implementations from all the loaded classes.
* @param callgraphRootsOnly if true and if a callgraph has been created, only check callgraph root classes.
* This can be used to ignore unused Runnables by removing them from the callgraph (roots).
* @return a set of methods which implement Runnable.run().
*/
public Collection<MethodInfo> getThreadRootMethods(boolean callgraphRootsOnly) {
List<MethodInfo> methods = new ArrayList<MethodInfo>();
Collection<ClassInfo> classList;
if (callGraph != null && callgraphRootsOnly) {
classList = callGraph.getRootClasses();
} else {
classList = classes.values();
}
for (ClassInfo cls : classList) {
Ternary isRunnable = cls.hasSuperClass("java.lang.Runnable", true);
if (isRunnable == Ternary.UNKNOWN) {
// what if unsafe? We ignore for now, must be added as root manually; should we log?
continue;
}
if (isRunnable == Ternary.TRUE) {
MethodInfo run = cls.getMethodInfo("run()V");
if (run != null && !run.isAbstract()) {
methods.add(run);
}
// TODO any other methods we might need to add?
}
}
return methods;
}
Aggregations