use of com.jopdesign.common.processormodel.ProcessorModel 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.processormodel.ProcessorModel in project jop by jop-devel.
the class SimpleInliner method analyzeCodeSize.
/**
* Check if the resulting code will not be larger than the older code.
* @param invokeSite the invokesite to inline.
* @param invokee the invoked method.
* @param inlineData the map to store the analyzer results
* @return true if the new code will not violate any size constrains
*/
private boolean analyzeCodeSize(InvokeSite invokeSite, MethodInfo invokee, InlineData inlineData) {
ProcessorModel pm = AppInfo.getSingleton().getProcessorModel();
MethodInfo invoker = invokeSite.getInvoker();
// delta = new prologue + inlined code + epilogue - old prologue - invokesite
int delta = 0;
InstructionHandle[] il = invokee.getCode().getInstructionList().getInstructionHandles();
InstructionHandle ih = il[inlineData.getInlineStart()];
while (ih != null) {
Instruction instr = ih.getInstruction();
if (instr instanceof ReturnInstruction) {
break;
}
delta += pm.getNumberOfBytes(invokee, instr);
ih = ih.getNext();
}
for (InstructionHandle instr : inlineData.getPrologue().getInstructionHandles()) {
delta += pm.getNumberOfBytes(invoker, instr.getInstruction());
}
for (InstructionHandle instr : inlineData.getEpilogue().getInstructionHandles()) {
delta += pm.getNumberOfBytes(invoker, instr.getInstruction());
}
ih = invokeSite.getInstructionHandle();
for (int i = 0; i <= inlineData.getOldPrologueLength(); i++) {
Instruction instr = ih.getInstruction();
delta -= pm.getNumberOfBytes(invoker, instr);
ih = ih.getPrev();
}
// TODO we could allow for some slack, especially if we decreased the codesize before..
return delta <= 0;
}
use of com.jopdesign.common.processormodel.ProcessorModel 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.processormodel.ProcessorModel in project jop by jop-devel.
the class MethodCode method getNumberOfBytes.
/**
* @see ProcessorModel#getNumberOfBytes(MethodInfo, Instruction)
* @param il the instruction list to get the size for
* @return the number of bytes for a given instruction list on the target.
*/
public int getNumberOfBytes(InstructionList il) {
int sum = 0;
ProcessorModel pm = getAppInfo().getProcessorModel();
for (InstructionHandle ih : il.getInstructionHandles()) {
sum += pm.getNumberOfBytes(methodInfo, ih.getInstruction());
}
return sum;
}
Aggregations