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.VM; 016 import org.jikesrvm.adaptive.recompilation.CompilerDNA; 017 import org.jikesrvm.classloader.RVMMethod; 018 import org.jikesrvm.compilers.common.CompiledMethod; 019 import org.jikesrvm.compilers.opt.runtimesupport.OptCompiledMethod; 020 021 /** 022 * Abstract parent class for events from organizers to the controller 023 * used to communicate that a method should be considered as a candidate 024 * for recompilation. 025 */ 026 public abstract class HotMethodEvent { 027 028 /** 029 * The compiled method associated querries. 030 */ 031 private CompiledMethod cm; 032 033 public final int getCMID() { return cm.getId(); } 034 035 public final CompiledMethod getCompiledMethod() { return cm; } 036 037 public final RVMMethod getMethod() { return cm.getMethod(); } 038 039 public final boolean isOptCompiled() { 040 return cm.getCompilerType() == CompiledMethod.OPT; 041 } 042 043 public final int getOptCompiledLevel() { 044 if (!isOptCompiled()) return -1; 045 return ((OptCompiledMethod) cm).getOptLevel(); 046 } 047 048 public final int getPrevCompilerConstant() { 049 if (isOptCompiled()) { 050 return CompilerDNA.getCompilerConstant(getOptCompiledLevel()); 051 } else { 052 return CompilerDNA.BASELINE; 053 } 054 } 055 056 /** 057 * Number of samples attributed to this method. 058 */ 059 private double numSamples; 060 061 public final double getNumSamples() { return numSamples; } 062 063 /** 064 * @param _cm the compiled method 065 * @param _numSamples the number of samples attributed to the method 066 */ 067 HotMethodEvent(CompiledMethod _cm, double _numSamples) { 068 if (VM.VerifyAssertions) { 069 VM._assert(_cm != null, "Don't create me for null compiled method!"); 070 VM._assert(_numSamples >= 0.0, "Invalid numSamples value"); 071 } 072 cm = _cm; 073 numSamples = _numSamples; 074 } 075 076 /** 077 * @param _cm the compiled method 078 * @param _numSamples the number of samples attributed to the method 079 */ 080 HotMethodEvent(CompiledMethod _cm, int _numSamples) { 081 this(_cm, (double) _numSamples); 082 } 083 084 @Override 085 public String toString() { 086 return getMethod() + " = " + getNumSamples(); 087 } 088 }