use of com.jopdesign.common.AppInfo in project jop by jop-devel.
the class InlineHelper method devirtualize.
/**
* Devirtualize an invocation.
* <p>
* Since this uses the callgraph if available, the callstring must match the state of the callgraph,
* i.e. if an invocation in the callstring has been inlined and the callgraph has been updated to reflect
* the new invoke, the inlined invocation must be removed from the callstring too.
* Contrariwise, if an invoke has been inlined but the callgraph has not yet been updated, the callstring
* must also contain the inlined invoke. Also the callstring does not need to start at the method to optimize.
* This is different from what {@link #canInline(CallString, InvokeSite, MethodInfo)} expects.
* </p>
*
* @see #canInline(CallString, InvokeSite, MethodInfo)
* @param invokers the callstring of the invocation to devirtualize. The last entry must be the invoke site to
* devirtualize. The first first entry does not need to be the method into which inlining
* is performed.
* @return the method info to call if unique, else null.
*/
public MethodInfo devirtualize(CallString invokers) {
AppInfo appInfo = AppInfo.getSingleton();
Set<MethodInfo> methods = appInfo.findImplementations(invokers);
if (methods.size() == 1) {
return methods.iterator().next();
} else {
return null;
}
}
use of com.jopdesign.common.AppInfo in project jop by jop-devel.
the class UnusedCodeRemover method execute.
public void execute() {
ucf.resetMarks();
// This starts at all app roots and JVM roots, as well as all threads,
// <clinit> methods are marked in all reached classes
ucf.markUsedMembers();
// We also need to mark everything else we do not want to remove ..
AppInfo appInfo = AppInfo.getSingleton();
ProcessorModel pm = appInfo.getProcessorModel();
if (pm.keepJVMClasses()) {
for (String clName : pm.getJVMClasses()) {
ClassInfo cls = appInfo.getClassInfo(clName);
if (cls != null) {
ucf.markUsedMembers(cls, true);
}
}
}
removeUnusedMembers();
}
use of com.jopdesign.common.AppInfo in project jop by jop-devel.
the class AppLoader method loadAll.
public void loadAll(boolean startFromRootsOnly) {
AppInfo appInfo = AppInfo.getSingleton();
if (startFromRootsOnly) {
// we only work on classes, not methods, so starting with root classes is sufficient here
enqueue(appInfo.getRootClasses());
} else {
enqueue(appInfo.getClassInfos());
}
processQueue();
}
use of com.jopdesign.common.AppInfo in project jop by jop-devel.
the class ExampleTool method doSomething.
public void doSomething(Config config) {
AppInfo appInfo = AppInfo.getSingleton();
// access and modify some classes
System.out.println("field of main class: " + manager.getMyField(appInfo.getMainMethod().getClassInfo()));
for (ClassInfo root : appInfo.getRootClasses()) {
System.out.println("field of root: " + manager.getMyField(root));
}
// create a new class and new methods
try {
ClassInfo newCls = appInfo.createClass("MyTest", appInfo.getClassRef("java.lang.Object"), false);
} catch (NamingConflictException e) {
e.printStackTrace();
}
}
use of com.jopdesign.common.AppInfo in project jop by jop-devel.
the class ClassWriter method write.
public void write(String writeDir) throws IOException {
AppInfo appInfo = AppInfo.getSingleton();
if (logger.isInfoEnabled()) {
logger.info("Start writing classes to '" + writeDir + "' ..");
}
File classDir = new File(writeDir);
if (classDir.exists()) {
if (classDir.isFile()) {
throw new IOException("Output directory '" + classDir + "' is a file.");
}
} else if (!classDir.mkdirs()) {
throw new IOException("Could not create output directory " + classDir);
}
for (ClassInfo cls : appInfo.getClassInfos()) {
if (logger.isDebugEnabled()) {
logger.debug("Writing class: " + cls.getClassName());
}
JavaClass jc = cls.compile();
String filename = classDir + File.separator + cls.getClassName().replace(".", File.separator) + ".class";
File file = new File(filename);
String parent = file.getParent();
if (parent != null) {
File pDir = new File(parent);
// noinspection ResultOfMethodCallIgnored
pDir.mkdirs();
}
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file));
DataOutputStream stream = new DataOutputStream(out);
jc.dump(stream);
stream.close();
}
if (logger.isInfoEnabled()) {
logger.info(appInfo.getClassInfos().size() + " classes written.");
}
}
Aggregations