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;
}
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();
}
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();
}
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));
}
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();
}
Aggregations