Search in sources :

Example 36 with NormalMethod

use of org.jikesrvm.classloader.NormalMethod in project JikesRVM by JikesRVM.

the class AnalyticModel method considerHotMethod.

/**
 * This method is the main decision making loop for all
 * recompilation strategies that use the analytic model.
 * <p>
 * Given a HotMethodRecompilationEvent, this code will determine
 * IF the method should be recompiled, and if so, HOW to perform
 * the recompilation, i.e., what compilation plan should be used.
 * The method returns a controller plan, which contains the compilation
 * plan and other goodies.
 *
 * @param cmpMethod the compiled method of interest
 * @param hme       the HotMethodRecompilationEvent
 * @return the controller plan to be used or NULL, if no
 *                   compilation is to be performed.
 */
@Override
ControllerPlan considerHotMethod(CompiledMethod cmpMethod, HotMethodEvent hme) {
    // Compiler used for the previous compilation
    int prevCompiler = CompilerDNA.getPreviousCompiler(cmpMethod);
    if (prevCompiler == CANNOT_RECOMPILE) {
        return null;
    }
    ControllerPlan plan = ControllerMemory.findMatchingPlan(cmpMethod);
    // and execute plan in the routine, no more action here
    if (considerOSRRecompilation(cmpMethod, hme, plan))
        return null;
    if (!considerForRecompilation(hme, plan))
        return null;
    // Now we know the compiler that generated the method (prevCompiler) and
    // that the method is a potential candidate for additional recompilation.
    // So, next decide what, if anything, should be done now.
    // We consider doing nothing (ie leaving the method at the current
    // opt level, which incurs no  compilation cost), and recompiling the
    // method at each greater compilation level.
    double futureTimeForMethod = futureTimeForMethod(hme);
    // initialize bestAction as doing nothing, which means we'll
    // spend just as much time in the method in the future as we have so far.
    RecompilationChoice bestActionChoice = null;
    double bestActionTime = futureTimeForMethod;
    double bestCost = 0.0;
    AOSLogging.logger.recordControllerEstimateCostDoNothing(cmpMethod.getMethod(), CompilerDNA.getOptLevel(prevCompiler), bestActionTime);
    // Get a vector of optimization choices to consider
    RecompilationChoice[] recompilationChoices = getViableRecompilationChoices(prevCompiler, cmpMethod);
    // Consider all choices in the vector of possibilities
    NormalMethod meth = (NormalMethod) hme.getMethod();
    for (RecompilationChoice choice : recompilationChoices) {
        // Get the cost and benefit of this choice
        double cost = choice.getCost(meth);
        double futureExecutionTime = choice.getFutureExecutionTime(prevCompiler, futureTimeForMethod);
        double curActionTime = cost + futureExecutionTime;
        AOSLogging.logger.recordControllerEstimateCostOpt(cmpMethod.getMethod(), choice.toString(), cost, curActionTime);
        if (curActionTime < bestActionTime) {
            bestActionTime = curActionTime;
            bestActionChoice = choice;
            bestCost = cost;
        }
    }
    // if the best action is the previous than we don't need to recompile
    if (bestActionChoice == null) {
        plan = null;
    } else {
        plan = bestActionChoice.makeControllerPlan(cmpMethod, prevCompiler, futureTimeForMethod, bestActionTime, bestCost);
    }
    return plan;
}
Also used : NormalMethod(org.jikesrvm.classloader.NormalMethod)

Example 37 with NormalMethod

use of org.jikesrvm.classloader.NormalMethod in project JikesRVM by JikesRVM.

the class OptTestHarnessTest method methodsAreOptCompiledByDefault.

@Test
@Category(RequiresOptCompiler.class)
public void methodsAreOptCompiledByDefault() throws Exception {
    String[] compileClass = { "-class", ABSTRACT_CLASS_WITH_EMPTY_METHOD };
    executeOptTestHarness(compileClass);
    assertThatNumberOfBaselineCompiledMethodsIs(0);
    assertThatNumberOfOptCompiledMethodsIs(2);
    assertThatNoAdditionalErrorsHaveOccurred();
    Class<?> testClass2 = Class.forName(ABSTRACT_CLASS_WITH_EMPTY_METHOD);
    NormalMethod emptyMethod = TestingTools.getNormalMethod(testClass2, "emptyMethod");
    assertThatOutputContainsMessageForCompiledMethod(emptyMethod);
    removeCompiledMethodMessageFromStandardOutput(emptyMethod);
    NormalMethod constructor = TestingTools.getNoArgumentConstructor(testClass2);
    assertThatOutputContainsMessageForCompiledMethod(constructor);
    removeCompiledMethodMessageFromStandardOutput(constructor);
    assertThatRemainingOutputIsEmptyWhenTrimmed();
}
Also used : NormalMethod(org.jikesrvm.classloader.NormalMethod) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 38 with NormalMethod

use of org.jikesrvm.classloader.NormalMethod in project JikesRVM by JikesRVM.

the class OptTestHarnessTest method canRunAndExecuteMainMethod.

@Test
public void canRunAndExecuteMainMethod() throws Exception {
    String firstArg = "abc";
    String secondArg = "123";
    String[] args = { "-main", CLASS_WITH_MAIN_METHOD, firstArg, secondArg };
    executeOTHWithStreamRedirection(args);
    assertThatNumberOfBaselineCompiledMethodsIs(0);
    assertThatNumberOfOptCompiledMethodsIs(0);
    Class<?> classWithMain = Class.forName(CLASS_WITH_MAIN_METHOD);
    NormalMethod mainMethod = TestingTools.getNormalMethod(classWithMain, "main", String[].class);
    String expectedOutput = OptTestHarness.startOfExecutionString(mainMethod) + lineEnd + firstArg + lineEnd + secondArg + lineEnd + OptTestHarness.endOfExecutionString(mainMethod) + lineEnd;
    assertThat(getStandardOutput(), equalTo(expectedOutput));
    removeMessageFromStandardOutput(expectedOutput);
    assertThatRemainingOutputIsEmptyWhenTrimmed();
    assertThatNoAdditionalErrorsHaveOccurred();
}
Also used : NormalMethod(org.jikesrvm.classloader.NormalMethod) Test(org.junit.Test)

Example 39 with NormalMethod

use of org.jikesrvm.classloader.NormalMethod in project JikesRVM by JikesRVM.

the class OptTestHarnessTest method executeAndRunCanParseStringArrays.

@Test
public void executeAndRunCanParseStringArrays() throws Exception {
    String firstString = "test";
    String secondString = "success";
    String[] compilePrintIntMethod = { "-er", CLASS_OVERLOADED_METHODS, "print", "([Ljava/lang/String;)V", firstString, secondString };
    executeOTHWithStreamRedirection(compilePrintIntMethod);
    assertThatNumberOfBaselineCompiledMethodsIs(0);
    assertThatNumberOfOptCompiledMethodsIs(0);
    assertThatNoAdditionalErrorsHaveOccurred();
    Class<?> classWithOverloadedMethods = Class.forName(CLASS_OVERLOADED_METHODS);
    NormalMethod printMethod = TestingTools.getNormalMethod(classWithOverloadedMethods, "print", String[].class);
    assertThatOutputContainsMessageForCompiledMethod(printMethod);
    removeCompiledMethodMessageFromStandardOutput(printMethod);
    String output = getStandardOutput();
    String expectedOutput = lineEnd + OptTestHarness.startOfExecutionString(printMethod) + lineEnd + firstString + lineEnd + secondString + lineEnd + OptTestHarness.endOfExecutionString(printMethod) + lineEnd + OptTestHarness.resultString(null) + lineEnd;
    assertThat(output, equalTo(expectedOutput));
}
Also used : NormalMethod(org.jikesrvm.classloader.NormalMethod) Test(org.junit.Test)

Example 40 with NormalMethod

use of org.jikesrvm.classloader.NormalMethod in project JikesRVM by JikesRVM.

the class OptTestHarnessTest method assertThatBothMethodsOfTestClass2HaveBeenBaselineCompiled.

private void assertThatBothMethodsOfTestClass2HaveBeenBaselineCompiled() throws ClassNotFoundException, Exception {
    assertThatNumberOfBaselineCompiledMethodsIs(2);
    assertThatNoAdditionalErrorsHaveOccurred();
    Class<?> testClass2 = Class.forName(ABSTRACT_CLASS_WITH_EMPTY_METHOD);
    NormalMethod emptyMethod = TestingTools.getNormalMethod(testClass2, "emptyMethod");
    assertThatOutputContainsMessageForCompiledMethod(emptyMethod);
    removeCompiledMethodMessageFromStandardOutput(emptyMethod);
    NormalMethod constructor = TestingTools.getNoArgumentConstructor(testClass2);
    assertThatOutputContainsMessageForCompiledMethod(constructor);
    removeCompiledMethodMessageFromStandardOutput(constructor);
    assertThatNumberOfOptCompiledMethodsIs(0);
    assertThatRemainingOutputIsEmptyWhenTrimmed();
}
Also used : NormalMethod(org.jikesrvm.classloader.NormalMethod)

Aggregations

NormalMethod (org.jikesrvm.classloader.NormalMethod)95 Test (org.junit.Test)66 OptOptions (org.jikesrvm.compilers.opt.OptOptions)45 CompiledMethod (org.jikesrvm.compilers.common.CompiledMethod)41 OptCompiledMethod (org.jikesrvm.compilers.opt.runtimesupport.OptCompiledMethod)31 DefaultInlineOracle (org.jikesrvm.compilers.opt.inlining.DefaultInlineOracle)28 InlineOracle (org.jikesrvm.compilers.opt.inlining.InlineOracle)28 RegisterOperand (org.jikesrvm.compilers.opt.ir.operand.RegisterOperand)28 Instruction (org.jikesrvm.compilers.opt.ir.Instruction)21 InlineSequence (org.jikesrvm.compilers.opt.inlining.InlineSequence)17 TypeReference (org.jikesrvm.classloader.TypeReference)15 ExceptionHandlerBasicBlockBag (org.jikesrvm.compilers.opt.ir.ExceptionHandlerBasicBlockBag)15 MethodOperand (org.jikesrvm.compilers.opt.ir.operand.MethodOperand)15 BasicBlock (org.jikesrvm.compilers.opt.ir.BasicBlock)13 ExceptionHandlerBasicBlock (org.jikesrvm.compilers.opt.ir.ExceptionHandlerBasicBlock)13 Register (org.jikesrvm.compilers.opt.ir.Register)13 RVMMethod (org.jikesrvm.classloader.RVMMethod)8 Operand (org.jikesrvm.compilers.opt.ir.operand.Operand)8 TrueGuardOperand (org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand)8 TypeOperand (org.jikesrvm.compilers.opt.ir.operand.TypeOperand)8