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.compilers.baseline;
014
015import org.vmmagic.pragma.Pure;
016
017/**
018 * Profile data for a branch instruction.
019 */
020public abstract class BranchProfile {
021  /** The bytecode index of the branch instruction */
022  protected final int bci;
023
024  /** The number of times the branch was executed. */
025  protected final float freq;
026
027  /**
028   * @param bci the bytecode index of the source branch instruction
029   * @param freq the number of times the branch was executed
030   */
031  BranchProfile(int bci, float freq) {
032    this.bci = bci;
033    this.freq = freq;
034  }
035
036  public final int getBytecodeIndex() {
037    return bci;
038  }
039
040  public final float getFrequency() {
041    return freq;
042  }
043
044  /**
045   * Converts integer count to float handling overflow
046   * @param count integer count
047   * @return floating point count
048   */
049  @Pure
050  static float countToFloat(int count) {
051    if (count < 0) {
052      final float MAX_UNSIGNED_INT = 2147483648f;
053      return MAX_UNSIGNED_INT + (count & 0x7FFFFFFF);
054    } else {
055      return count;
056    }
057  }
058
059}