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 getReferencedMethod.
////////////////////////////////////////////////////////////////////////////////
// Private methods
////////////////////////////////////////////////////////////////////////////////
/**
* Get a MethodRef for the referenced method in a given invoke instruction in the invoker method.
* This does not resolve any super methods or devirtualize the call.
* <p>
* If you call {@link MethodRef#getMethodInfo()}, the method found in the referenced class
* or in its superclasses will be returned. For InvokeSpecial, this might not be correct,
* so use {@link #getInvokeeRef()} or {@link AppInfo#findImplementations(InvokeSite)} instead.</p>
* <p>
* Note: Since this could easily be used incorrectly, this method has been moved here from MethodInfo and
* made private in favor of getInvokeeRef()
* </p>
*
* @param invoker the method containing the instruction, used to resolve constantpool references.
* @param instr the instruction to resolve
* @return a method reference representing the invoke reference.
*/
private static MethodRef getReferencedMethod(MethodInfo invoker, InvokeInstruction instr) {
ConstantPoolGen cpg = invoker.getConstantPoolGen();
String methodname = instr.getMethodName(cpg);
String classname = invoker.getCode().getReferencedClassName(instr);
MemberID memberID = new MemberID(classname, methodname, instr.getSignature(cpg));
if ("<clinit>".equals(methodname)) {
// can have <clinit> methods which are invoked by invokestatic
return AppInfo.getSingleton().getMethodRef(memberID);
}
boolean isInterface = (instr instanceof INVOKEINTERFACE);
return AppInfo.getSingleton().getMethodRef(memberID, isInterface);
}
use of com.jopdesign.common.type.MemberID in project jop by jop-devel.
the class AppSetup method getMainMethod.
private MethodInfo getMainMethod(String signature) throws Config.BadConfigurationException {
ClassInfo clsInfo;
String clsName;
MemberID sMain = getMainSignature(signature);
clsName = sMain.getClassName();
if (clsName == null) {
throw new BadConfigurationException("You need to specify a classname for the main method.");
}
try {
clsInfo = appInfo.loadClass(clsName, true, false);
} catch (ClassInfoNotFoundException e) {
throw new BadConfigurationException("Class for '" + signature + "' could not be loaded: " + e.getMessage(), e);
}
// check if we have a full signature
if (sMain.hasMethodSignature()) {
MethodInfo method = clsInfo.getMethodInfo(sMain.getMethodSignature());
if (method == null) {
throw new BadConfigurationException("Method '" + sMain.getMethodSignature() + "' not found in '" + clsName + "'.");
}
return method;
}
// try to find main method
String mainName = sMain.getMemberName();
if (mainName == null) {
mainName = config.getOption(Config.MAIN_METHOD_NAME);
if (mainName != null) {
mainName = MemberID.parse(mainName).getMethodSignature();
}
}
Collection<MethodInfo> methods = clsInfo.getMethodByName(mainName);
if (methods.isEmpty()) {
throw new BadConfigurationException("'No method '" + mainName + "' found in '" + clsName + "'.");
}
if (methods.size() > 1) {
StringBuilder s = new StringBuilder(String.format("Multiple candidates for '%s' in '%s', please specify with a signature: ", mainName, clsName));
for (MethodInfo m : methods) {
s.append("\n");
s.append(m.getMemberID());
}
throw new BadConfigurationException(s.toString());
}
return methods.iterator().next();
}
use of com.jopdesign.common.type.MemberID in project jop by jop-devel.
the class Config method parseMethodList.
/**
* @param methodNames comma separated list of method names, either fully qualified with or without descriptor, or
* method names of methods in the main class.
* @return the set of methods represented by these names
* @throws BadConfigurationException if a name is not resolvable
*/
public static List<MethodInfo> parseMethodList(String methodNames) throws BadConfigurationException {
List<String> names = splitStringList(methodNames);
List<MethodInfo> methods = new ArrayList<MethodInfo>(names.size());
for (String name : names) {
MemberID id = MemberID.parse(name);
if (!id.hasClassName()) {
ClassInfo main = AppInfo.getSingleton().getMainMethod().getClassInfo();
Set<MethodInfo> m = main.getMethodInfos(id);
if (m.isEmpty()) {
throw new BadConfigurationException("Cannot find method '" + name + "' in main class " + main);
}
methods.addAll(m);
} else {
try {
Collection<MethodInfo> infos = AppInfo.getSingleton().getMethodInfos(id);
if (infos.isEmpty()) {
throw new BadConfigurationException("Cannot find methods for " + name);
}
methods.addAll(infos);
} catch (MethodNotFoundException e) {
throw new BadConfigurationException("Cannot find class for " + name, e);
}
}
}
return methods;
}
Aggregations