Search in sources :

Example 1 with OptOptions

use of org.jikesrvm.compilers.opt.OptOptions in project JikesRVM by JikesRVM.

the class OnStackReplacementEvent method process.

/**
 * This function will generate a controller plan and
 * inserted in the recompilation queue.
 */
@Override
public void process() {
    CompiledMethod compiledMethod = CompiledMethods.getCompiledMethod(CMID);
    NormalMethod todoMethod = (NormalMethod) compiledMethod.getMethod();
    double priority;
    OptOptions options;
    OptimizationPlanElement[] optimizationPlan;
    ControllerPlan oldPlan = ControllerMemory.findLatestPlan(todoMethod);
    if (oldPlan != null) {
        CompilationPlan oldCompPlan = oldPlan.getCompPlan();
        priority = oldPlan.getPriority();
        options = oldCompPlan.options;
        optimizationPlan = oldCompPlan.optimizationPlan;
    } else {
        priority = 5.0;
        options = (OptOptions) RuntimeCompiler.options;
        optimizationPlan = (OptimizationPlanElement[]) RuntimeCompiler.optimizationPlan;
    }
    CompilationPlan compPlan = new CompilationPlan(todoMethod, optimizationPlan, null, options);
    OnStackReplacementPlan plan = new OnStackReplacementPlan(this.suspendedThread, compPlan, this.CMID, this.whereFrom, this.tsFromFPoff, this.ypTakenFPoff, priority);
    Controller.compilationQueue.insert(priority, plan);
    AOSLogging.logger.logOsrEvent("OSR inserts compilation plan successfully!");
    // do not hold the reference anymore.
    suspendedThread = null;
    CMID = 0;
}
Also used : NormalMethod(org.jikesrvm.classloader.NormalMethod) OptimizationPlanElement(org.jikesrvm.compilers.opt.driver.OptimizationPlanElement) CompilationPlan(org.jikesrvm.compilers.opt.driver.CompilationPlan) OptOptions(org.jikesrvm.compilers.opt.OptOptions) ControllerPlan(org.jikesrvm.adaptive.controller.ControllerPlan) CompiledMethod(org.jikesrvm.compilers.common.CompiledMethod)

Example 2 with OptOptions

use of org.jikesrvm.compilers.opt.OptOptions in project JikesRVM by JikesRVM.

the class AssemblerDriver method perform.

@Override
public void perform(IR ir) {
    OptOptions options = ir.options;
    boolean shouldPrint = (options.PRINT_MACHINECODE) && (!ir.options.hasMETHOD_TO_PRINT() || ir.options.fuzzyMatchMETHOD_TO_PRINT(ir.method.toString()));
    if (IR.SANITY_CHECK) {
        ir.verify("right before machine codegen", true);
    }
    // ////////
    // STEP 2: Generate the machinecode array.
    // As part of the generation, the machinecode offset
    // of every instruction will be set.
    // ////////
    int codeLength;
    if (VM.BuildForIA32) {
        org.jikesrvm.compilers.opt.mir2mc.ia32.AssemblerOpt asm = new org.jikesrvm.compilers.opt.mir2mc.ia32.AssemblerOpt(0, shouldPrint, ir);
        codeLength = asm.generateCode();
    } else {
        if (VM.VerifyAssertions)
            VM._assert(VM.BuildForPowerPC);
        org.jikesrvm.compilers.opt.mir2mc.ppc.AssemblerOpt asm = new org.jikesrvm.compilers.opt.mir2mc.ppc.AssemblerOpt(0, shouldPrint, ir);
        codeLength = asm.generateCode();
    }
    // ////////
    // STEP 3: Generate all the mapping information
    // associated with the machine code.
    // ////////
    // 3a: Create the exception table
    ir.compiledMethod.createFinalExceptionTable(ir);
    // 3b: Create the primary machine code map
    ir.compiledMethod.createFinalMCMap(ir, codeLength);
    // 3c: Create OSR maps
    ir.compiledMethod.createFinalOSRMap(ir);
    // 3d: Create code patching maps
    if (ir.options.guardWithCodePatch()) {
        ir.compiledMethod.createCodePatchMaps(ir);
    }
    if (shouldPrint) {
        // print exception tables (if any)
        ir.compiledMethod.printExceptionTable();
        OptimizingCompiler.bottom("Final machine code", ir.method);
    }
    if (VM.runningVM) {
        Memory.sync(Magic.objectAsAddress(ir.MIRInfo.machinecode), codeLength << ArchConstants.getLogInstructionWidth());
    }
}
Also used : OptOptions(org.jikesrvm.compilers.opt.OptOptions)

Example 3 with OptOptions

use of org.jikesrvm.compilers.opt.OptOptions in project JikesRVM by JikesRVM.

the class InlineTools method inlinedSizeEstimate.

/**
 * Given the currently available information at the call site,
 * what's our best guess on the inlined size of the callee?
 * @param callee the method to be inlined
 * @param state the compilation state decribing the call site where it
 *              is to be inlined
 * @return an inlined size estimate (number of machine code instructions)
 */
public static int inlinedSizeEstimate(NormalMethod callee, CompilationState state) {
    int sizeEstimate = callee.inlinedSizeEstimate();
    // Adjust size estimate downward to account for optimizations
    // that are typically enabled by constant parameters.
    Instruction callInstr = state.getCallInstruction();
    int numArgs = Call.getNumberOfParams(callInstr);
    // no reduction.
    double reductionFactor = 1.0;
    OptOptions opts = state.getOptions();
    for (int i = 0; i < numArgs; i++) {
        Operand op = Call.getParam(callInstr, i);
        if (op instanceof RegisterOperand) {
            RegisterOperand rop = (RegisterOperand) op;
            TypeReference type = rop.getType();
            if (type.isReferenceType()) {
                if (type.isArrayType()) {
                    // Reductions only come from optimization of dynamic type checks; all virtual methods on arrays are defined on Object.
                    if (rop.isPreciseType()) {
                        reductionFactor -= opts.INLINE_PRECISE_REG_ARRAY_ARG_BONUS;
                    } else if (rop.isDeclaredType() && callee.hasArrayWrite() && type.getArrayElementType().isReferenceType()) {
                        // potential to optimize checkstore portion of aastore bytecode on parameter
                        reductionFactor -= opts.INLINE_DECLARED_AASTORED_ARRAY_ARG_BONUS;
                    }
                } else {
                    // Reductions come from optimization of dynamic type checks and improved inlining of virtual/interface calls
                    if (rop.isPreciseType()) {
                        reductionFactor -= opts.INLINE_PRECISE_REG_CLASS_ARG_BONUS;
                    } else if (rop.isExtant()) {
                        reductionFactor -= opts.INLINE_EXTANT_REG_CLASS_ARG_BONUS;
                    }
                }
            }
        } else if (op.isIntConstant()) {
            reductionFactor -= opts.INLINE_INT_CONST_ARG_BONUS;
        } else if (op.isNullConstant()) {
            reductionFactor -= opts.INLINE_NULL_CONST_ARG_BONUS;
        } else if (op.isObjectConstant()) {
            reductionFactor -= opts.INLINE_OBJECT_CONST_ARG_BONUS;
        }
    }
    reductionFactor = Math.max(reductionFactor, 1.0 - opts.INLINE_MAX_ARG_BONUS);
    if (opts.INLINE_CALL_DEPTH_COST != 0.00) {
        double depthCost = Math.pow(1.0 + opts.INLINE_CALL_DEPTH_COST, state.getInlineDepth() + 1);
        return (int) (sizeEstimate * reductionFactor * depthCost);
    } else {
        return (int) (sizeEstimate * reductionFactor);
    }
}
Also used : RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) Operand(org.jikesrvm.compilers.opt.ir.operand.Operand) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) OptOptions(org.jikesrvm.compilers.opt.OptOptions) TypeReference(org.jikesrvm.classloader.TypeReference) Instruction(org.jikesrvm.compilers.opt.ir.Instruction)

Example 4 with OptOptions

use of org.jikesrvm.compilers.opt.OptOptions in project JikesRVM by JikesRVM.

the class EscapeTransformations method getAggregateReplacer.

/**
 * Generate an object which will perform scalar replacement of
 * an aggregate allocated by a given instruction
 *
 * <p> PRECONDITION: objects returned by this allocation site do NOT escape
 *                 the current method
 *
 * @param inst the allocation site
 * @param ir controlling ir
 * @return an AggregateReplacer specialized to the allocation site,
 *            null if no legal transformation found
 */
private AggregateReplacer getAggregateReplacer(Instruction inst, IR ir) {
    OptOptions options = ir.options;
    RVMType t = null;
    if (inst.getOpcode() == NEW_opcode) {
        t = New.getType(inst).getVMType();
    } else if (inst.getOpcode() == NEWARRAY_opcode) {
        t = NewArray.getType(inst).getVMType();
    } else {
        throw new OptimizingCompilerException("Logic Error in EscapeTransformations");
    }
    // first attempt to perform scalar replacement for an object
    if (t.isClassType() && options.ESCAPE_SCALAR_REPLACE_AGGREGATES) {
        return ObjectReplacer.getReplacer(inst, ir);
    }
    // attempt to perform scalar replacement on a short array
    if (t.isArrayType() && options.ESCAPE_SCALAR_REPLACE_AGGREGATES) {
        return ShortArrayReplacer.getReplacer(inst, ir);
    }
    return null;
}
Also used : RVMType(org.jikesrvm.classloader.RVMType) OptOptions(org.jikesrvm.compilers.opt.OptOptions) OptimizingCompilerException(org.jikesrvm.compilers.opt.OptimizingCompilerException)

Example 5 with OptOptions

use of org.jikesrvm.compilers.opt.OptOptions in project JikesRVM by JikesRVM.

the class GenerationContextTest method childContextsQueryOSRBarrierInformationViaOutermostParent.

@Test
public void childContextsQueryOSRBarrierInformationViaOutermostParent() throws Exception {
    NormalMethod nm = getNormalMethodForTest("methodForInliningTests");
    CompiledMethod cm = new OptCompiledMethod(-1, nm);
    OptOptions opts = new OptOptions();
    InlineOracle io = new DefaultInlineOracle();
    GenerationContext outermost = new GenerationContext(nm, null, cm, opts, io);
    Class<?>[] classArgs = { Object.class };
    NormalMethod callee = getNormalMethodForTest("emptyStaticMethodWithObjectParamAndReturnValue", classArgs);
    MethodOperand methOp = MethodOperand.STATIC(callee);
    RegisterOperand result = createMockRegisterOperand(TypeReference.JavaLangObject);
    Instruction callInstr = Call.create(CALL, result, null, methOp, 1);
    RegisterOperand objectParam = createMockRegisterOperand(TypeReference.JavaLangObject);
    Call.setParam(callInstr, 0, objectParam);
    callInstr.setPosition(new InlineSequence(nm));
    ExceptionHandlerBasicBlockBag ebag = getMockEbag();
    GenerationContext child = outermost.createChildContext(ebag, callee, callInstr);
    Instruction osrBarrier = createMockOSRBarrier();
    Instruction call = createMockCall();
    child.saveOSRBarrierForInst(osrBarrier, call);
    assertThat(outermost.getOSRBarrierFromInst(call), is(osrBarrier));
    assertThat(child.getOSRBarrierFromInst(call), is(osrBarrier));
    GenerationContext child2 = outermost.createChildContext(ebag, callee, callInstr);
    assertThat(child2.getOSRBarrierFromInst(call), is(osrBarrier));
}
Also used : OptCompiledMethod(org.jikesrvm.compilers.opt.runtimesupport.OptCompiledMethod) DefaultInlineOracle(org.jikesrvm.compilers.opt.inlining.DefaultInlineOracle) InlineOracle(org.jikesrvm.compilers.opt.inlining.InlineOracle) OptOptions(org.jikesrvm.compilers.opt.OptOptions) Instruction(org.jikesrvm.compilers.opt.ir.Instruction) OptCompiledMethod(org.jikesrvm.compilers.opt.runtimesupport.OptCompiledMethod) CompiledMethod(org.jikesrvm.compilers.common.CompiledMethod) MethodOperand(org.jikesrvm.compilers.opt.ir.operand.MethodOperand) ExceptionHandlerBasicBlockBag(org.jikesrvm.compilers.opt.ir.ExceptionHandlerBasicBlockBag) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) NormalMethod(org.jikesrvm.classloader.NormalMethod) DefaultInlineOracle(org.jikesrvm.compilers.opt.inlining.DefaultInlineOracle) InlineSequence(org.jikesrvm.compilers.opt.inlining.InlineSequence) Test(org.junit.Test)

Aggregations

OptOptions (org.jikesrvm.compilers.opt.OptOptions)70 Test (org.junit.Test)48 NormalMethod (org.jikesrvm.classloader.NormalMethod)45 CompiledMethod (org.jikesrvm.compilers.common.CompiledMethod)32 OptCompiledMethod (org.jikesrvm.compilers.opt.runtimesupport.OptCompiledMethod)29 DefaultInlineOracle (org.jikesrvm.compilers.opt.inlining.DefaultInlineOracle)28 InlineOracle (org.jikesrvm.compilers.opt.inlining.InlineOracle)28 RegisterOperand (org.jikesrvm.compilers.opt.ir.operand.RegisterOperand)27 Instruction (org.jikesrvm.compilers.opt.ir.Instruction)19 InlineSequence (org.jikesrvm.compilers.opt.inlining.InlineSequence)17 ExceptionHandlerBasicBlockBag (org.jikesrvm.compilers.opt.ir.ExceptionHandlerBasicBlockBag)14 MethodOperand (org.jikesrvm.compilers.opt.ir.operand.MethodOperand)13 TypeReference (org.jikesrvm.classloader.TypeReference)12 BasicBlock (org.jikesrvm.compilers.opt.ir.BasicBlock)12 ExceptionHandlerBasicBlock (org.jikesrvm.compilers.opt.ir.ExceptionHandlerBasicBlock)12 Register (org.jikesrvm.compilers.opt.ir.Register)12 Operand (org.jikesrvm.compilers.opt.ir.operand.Operand)8 TrueGuardOperand (org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand)8 ClassConstantOperand (org.jikesrvm.compilers.opt.ir.operand.ClassConstantOperand)7 ObjectConstantOperand (org.jikesrvm.compilers.opt.ir.operand.ObjectConstantOperand)7