Search in sources :

Example 1 with ProcessorModel

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);
        }
    }
}
Also used : MemberID(com.jopdesign.common.type.MemberID) BadConfigurationError(com.jopdesign.common.config.Config.BadConfigurationError) JOPModel(com.jopdesign.common.processormodel.JOPModel) AllocationModel(com.jopdesign.common.processormodel.AllocationModel) ProcessorModel(com.jopdesign.common.processormodel.ProcessorModel) JVMModel(com.jopdesign.common.processormodel.JVMModel) JamuthModel(com.jopdesign.common.processormodel.JamuthModel)

Example 2 with ProcessorModel

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;
}
Also used : ReturnInstruction(org.apache.bcel.generic.ReturnInstruction) MethodInfo(com.jopdesign.common.MethodInfo) ProcessorModel(com.jopdesign.common.processormodel.ProcessorModel) InvokeInstruction(org.apache.bcel.generic.InvokeInstruction) StackInstruction(org.apache.bcel.generic.StackInstruction) Instruction(org.apache.bcel.generic.Instruction) FieldInstruction(org.apache.bcel.generic.FieldInstruction) ArithmeticInstruction(org.apache.bcel.generic.ArithmeticInstruction) ConversionInstruction(org.apache.bcel.generic.ConversionInstruction) ReturnInstruction(org.apache.bcel.generic.ReturnInstruction) PushInstruction(org.apache.bcel.generic.PushInstruction) InstructionHandle(org.apache.bcel.generic.InstructionHandle)

Example 3 with ProcessorModel

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();
}
Also used : ProcessorModel(com.jopdesign.common.processormodel.ProcessorModel) AppInfo(com.jopdesign.common.AppInfo) ClassInfo(com.jopdesign.common.ClassInfo)

Example 4 with ProcessorModel

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;
}
Also used : ProcessorModel(com.jopdesign.common.processormodel.ProcessorModel) InstructionHandle(org.apache.bcel.generic.InstructionHandle)

Aggregations

ProcessorModel (com.jopdesign.common.processormodel.ProcessorModel)4 InstructionHandle (org.apache.bcel.generic.InstructionHandle)2 AppInfo (com.jopdesign.common.AppInfo)1 ClassInfo (com.jopdesign.common.ClassInfo)1 MethodInfo (com.jopdesign.common.MethodInfo)1 BadConfigurationError (com.jopdesign.common.config.Config.BadConfigurationError)1 AllocationModel (com.jopdesign.common.processormodel.AllocationModel)1 JOPModel (com.jopdesign.common.processormodel.JOPModel)1 JVMModel (com.jopdesign.common.processormodel.JVMModel)1 JamuthModel (com.jopdesign.common.processormodel.JamuthModel)1 MemberID (com.jopdesign.common.type.MemberID)1 ArithmeticInstruction (org.apache.bcel.generic.ArithmeticInstruction)1 ConversionInstruction (org.apache.bcel.generic.ConversionInstruction)1 FieldInstruction (org.apache.bcel.generic.FieldInstruction)1 Instruction (org.apache.bcel.generic.Instruction)1 InvokeInstruction (org.apache.bcel.generic.InvokeInstruction)1 PushInstruction (org.apache.bcel.generic.PushInstruction)1 ReturnInstruction (org.apache.bcel.generic.ReturnInstruction)1 StackInstruction (org.apache.bcel.generic.StackInstruction)1