001 /*
002 * This file is part of the Jikes RVM project (http://jikesrvm.org).
003 *
004 * This file is licensed to You under the Eclipse Public License (EPL);
005 * You may not use this file except in compliance with the License. You
006 * may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/eclipse-1.0.php
009 *
010 * See the COPYRIGHT.txt file distributed with this work for information
011 * regarding copyright ownership.
012 */
013 package org.jikesrvm.adaptive.controller;
014
015 import org.jikesrvm.adaptive.recompilation.CompilerDNA;
016 import org.jikesrvm.classloader.NormalMethod;
017 import org.jikesrvm.compilers.common.CompiledMethod;
018
019 /**
020 * Represents the recompilation choice of simply recompiling the
021 * method in question at a particular opt-level. The cost is the
022 * expected compilation time at that level, and the benefit is the
023 * execution improvement of executing at that level.
024 */
025 class RecompileOptChoice extends RecompilationChoice {
026
027 /**
028 * The opt level associated with this recompilation choice
029 */
030 private int thisChoiceOptLevel;
031
032 /**
033 * The "compiler" (see CompilerDNA) that is associated with this choice
034 */
035 private int thisChoiceCompiler;
036
037 /**
038 * Constructor
039 */
040 RecompileOptChoice(int level) {
041 thisChoiceOptLevel = level;
042 thisChoiceCompiler = CompilerDNA.getCompilerConstant(level);
043 }
044
045 /**
046 * What is the cost of executing this plan?
047 *
048 * @param meth The method being considered for recompilation.
049 * @return The expected cost of exeuting this recompilation choice
050 */
051 double getCost(NormalMethod meth) {
052 return CompilerDNA.estimateCompileTime(getCompiler(), meth);
053 }
054
055 /**
056 * What is the benefit of executing this plan, given the estimated
057 * future time for the method if nothing changes?
058 *
059 * @param prevCompiler The previous compiler
060 * @param futureTimeForMethod The expected future execution time of
061 * the method if left running with the previous compiler.
062 * @return The expected future execution time if this choice were selected
063 */
064 double getFutureExecutionTime(int prevCompiler, double futureTimeForMethod) {
065 double rtFactor = CompilerDNA.getBenefitRatio(prevCompiler, getCompiler());
066 return futureTimeForMethod / rtFactor;
067 }
068
069 /**
070 * Return a controller plan that will start this recompilation
071 * choice in action. In this case, simply create a plan to
072 * recompile at level "optLevel"
073 *
074 * @param cmpMethod The method in question
075 * @param prevCompiler The previous compiler
076 * @param prevTimeForMethod The estimated future time had nothing been done
077 * @param bestActionTime The estimated total time implementing this choice
078 * @param expectedCompilationTime The expected time for recompiling
079 * @return The controller plan implementing this recompilation choice
080 */
081 ControllerPlan makeControllerPlan(CompiledMethod cmpMethod, int prevCompiler, double prevTimeForMethod,
082 double bestActionTime, double expectedCompilationTime) {
083 double speedup = CompilerDNA.getBenefitRatio(prevCompiler, getCompiler());
084 double priority = prevTimeForMethod - bestActionTime;
085 return Controller.recompilationStrategy.
086 createControllerPlan(cmpMethod.getMethod(),
087 thisChoiceOptLevel,
088 null,
089 cmpMethod.getId(),
090 speedup,
091 expectedCompilationTime,
092 priority);
093 }
094
095 /**
096 * How should this choice be displayed?
097 */
098 public String toString() {
099 return "O" + getOptLevel();
100 }
101
102 /**
103 * Which opt-level is associated with this choice?
104 */
105 int getOptLevel() {
106 return thisChoiceOptLevel;
107 }
108
109 /**
110 * Which "compiler" (@see CompilerDNA) is associated with this choice?
111 */
112 int getCompiler() {
113 return thisChoiceCompiler;
114 }
115 }