use of com.jopdesign.common.type.MemberID in project jop by jop-devel.
the class DFACallgraphBuilder method getInvokedMethods.
@Override
protected Set<MethodInfo> getInvokedMethods(ExecutionContext context, InvokeSite invokeSite) {
// to avoid problems we only use the DFA for virtual calls, all other can be uniquely resolved anyway.
if (!invokeSite.isVirtual()) {
return Collections.singleton(invokeSite.getInvokeeRef().getMethodInfo());
}
Set<String> receivers = dfaTool.getReceivers(invokeSite.getInstructionHandle(), context.getCallString());
if (receivers == null) {
// This can happen e.g. because we have all Runnable.run() methods as roots, regardless if they are used
logger.debug("No receivers for " + invokeSite.getInvokeeRef() + " at " + invokeSite + " in call context " + context.getCallString().toStringVerbose(false));
return appInfo.findImplementations(invokeSite, context.getCallString());
}
if (receivers.size() == 0) {
// This can happen if a method is analyzed for some contexts but not for this context
logger.debug("No receivers for " + invokeSite.getInvokeeRef() + " at " + invokeSite + " in call context " + context.getCallString().toStringVerbose(false));
return appInfo.findImplementations(invokeSite, context.getCallString());
}
Set<MethodInfo> methods = new LinkedHashSet<MethodInfo>(receivers.size());
for (String rcv : receivers) {
MemberID mId = MemberID.parse(rcv);
methods.add(appInfo.getMethodRef(mId).getMethodInfo());
}
return methods;
}
use of com.jopdesign.common.type.MemberID in project jop by jop-devel.
the class InlineHelper method makePublic.
private void makePublic(ClassMemberInfo member) {
boolean wasPrivate = member.isPrivate();
// If we need to make it public, check if we need to make the class and all enclosing classes public too
ClassInfo cls = member.getClassInfo();
while (cls != null) {
if (!cls.isPublic()) {
cls.setAccessType(AccessType.ACC_PUBLIC);
}
cls = cls.getEnclosingClassInfo();
}
if (wasPrivate && member instanceof MethodInfo) {
// we are done here. if the method was private, there are no conflicting
// methods or we needed to rename it anyway.
member.setAccessType(AccessType.ACC_PUBLIC);
return;
}
// if we make a non-private method or any field public, need to go down to find all overriding
// members and make them public too
final MemberID memberID = member.getMemberID();
ClassVisitor visitor = new EmptyClassVisitor() {
@Override
public boolean visitClass(ClassInfo classInfo) {
ClassMemberInfo m = classInfo.getMemberInfo(memberID);
if (m == null) {
return true;
}
if (m.isPublic()) {
// we do not need to go further down if we find a public member
return false;
}
m.setAccessType(AccessType.ACC_PUBLIC);
return true;
}
};
new ClassHierarchyTraverser(visitor).traverseDown(member.getClassInfo());
}
use of com.jopdesign.common.type.MemberID in project jop by jop-devel.
the class AppSetup method getMainSignature.
private MemberID getMainSignature(String signature) throws BadConfigurationException {
MemberID sMain;
ClassPath path = new ClassPath(config.getOption(Config.CLASSPATH));
MemberID sMainMethod = MemberID.parse(config.getOption(Config.MAIN_METHOD_NAME), path);
if (signature == null || "".equals(signature)) {
sMain = sMainMethod;
} else {
// try to parse the signature
sMain = MemberID.parse(signature, path);
// use --mm if only main class has been given
if (!sMain.hasMemberName()) {
if (!sMainMethod.hasMemberName()) {
throw new BadConfigurationException("Option '" + Config.MAIN_METHOD_NAME.getKey() + "' needs to specify a method name.");
}
sMain = new MemberID(sMain.getClassName(), sMainMethod.getMemberName(), sMainMethod.getDescriptor());
}
}
return sMain;
}
use of com.jopdesign.common.type.MemberID in project jop by jop-devel.
the class AppSetup method initProcessorModel.
private void initProcessorModel(Model model) {
ProcessorModel pm;
switch(model) {
case JOP:
pm = new JOPModel(config);
break;
case jamuth:
pm = new JamuthModel(config);
break;
case allocation:
pm = new AllocationModel(config);
break;
case JVM:
pm = new JVMModel();
break;
default:
throw new BadConfigurationError("Unknown processor model " + model);
}
appInfo.setProcessorModel(pm);
// load referenced classes as roots
for (String jvmClass : pm.getJVMClasses()) {
ClassInfo rootInfo = appInfo.loadClass(jvmClass.replaceAll("/", "."));
if (rootInfo == null) {
System.err.println("Error loading JVM class '" + jvmClass + "'.");
System.exit(4);
}
}
if (appInfo.doLoadNatives()) {
for (String nativeClass : pm.getNativeClasses()) {
ClassInfo rootInfo = appInfo.loadClass(nativeClass.replaceAll("/", "."));
if (rootInfo == null) {
System.err.println("Error loading Native class '" + nativeClass + "'.");
System.exit(4);
}
}
}
// we do not set the JVM and native classes as root anymore, instead we let the PM decide which roots we need
for (String root : pm.getJVMRoots()) {
MemberID mID = MemberID.parse(root);
// make sure the class exists..
ClassInfo cls = appInfo.loadClass(mID.getClassName());
// Get the member and add it as root
if (mID.hasMemberName()) {
MethodInfo methodInfo = cls.getMethodInfo(mID);
if (methodInfo == null) {
System.err.println("Could not find JVM root " + root);
System.exit(5);
}
appInfo.addRoot(methodInfo);
} else {
appInfo.addRoot(cls);
}
}
}
use of com.jopdesign.common.type.MemberID in project jop by jop-devel.
the class InvokeSite method resolveInvokeSuper.
/**
* Resolve the reference to the super method.
* See #isInvokeSuper() for more details.
*
* @param ref the method referenced by the instruction
* @return the reference to the method to invoke
*/
private MethodRef resolveInvokeSuper(MethodRef ref) {
String superClass = invoker.getClassInfo().getSuperClassName();
// Restart the lookup in the super class of the invoker class
MemberID superId = new MemberID(superClass, ref.getName(), ref.getDescriptor());
// invokespecial is never used for interface invokes
MethodRef superRef = AppInfo.getSingleton().getMethodRef(superId, false);
if (ref.getMethodInfo() != null && !ref.getMethodInfo().equals(superRef.getMethodInfo())) {
// Just give a warning, just in case there is some code out there which handles this incorrectly..
// Warning level might be changed to debug someday..
logger.warn("InvokeSpecial in " + invoker + " calls super method " + superRef + " but refers to " + ref + " which is valid, but you might want to know that..");
}
return superRef;
}
Aggregations