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