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.compilers.baseline; 014 015 /** 016 * Profile data for a branch instruction. 017 */ 018 public final class ConditionalBranchProfile extends BranchProfile { 019 020 final float taken; 021 final boolean backwards; 022 023 /** 024 * @param _bci the bytecode index of the source branch instruction 025 * @param yea the number of times the branch was taken 026 * @param nea the number of times the branch was not taken 027 * @param bw is this a backwards branch? 028 */ 029 ConditionalBranchProfile(int _bci, int yea, int nea, boolean bw) { 030 super(_bci, ((float) yea + (float) nea)); 031 taken = yea; 032 backwards = bw; 033 } 034 035 public float getTakenProbability() { 036 if (freq > 0) { 037 return taken / freq; 038 } else if (backwards) { 039 return 0.9f; 040 } else { 041 return 0.5f; 042 } 043 } 044 045 @Override 046 public String toString() { 047 String ans = bci + (backwards ? "\tbackbranch" : "\tforwbranch"); 048 ans += " < " + (int) taken + ", " + (int) (freq - taken) + " > "; 049 if (freq > 0) { 050 ans += (100.0f * taken / freq) + "% taken"; 051 } else { 052 ans += "Never Executed"; 053 } 054 return ans; 055 } 056 057 }