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.opt;
014
015import org.jikesrvm.compilers.opt.ir.IR;
016import org.jikesrvm.compilers.opt.ir.Instruction;
017
018/**
019 * This interface defines the functionality necessary to be a
020 * InstrumentedEventCounterManager.  The goal of this interface is
021 * to provide a mechanism for instrumentation phases to performing
022 * counting of events, but to keep the implementation of the counters
023 * completely hidden.
024 */
025public abstract class InstrumentedEventCounterManager {
026  static final boolean DEBUG = false;
027
028  /**
029   *  This method is called to called to tell the counter manager to
030   *  reserve the needed space.  A handle is returned telling where
031   *  the counter space begins.
032   *
033   * @param countersNeeded The number of counters being requested
034   * @return A "handle", or name  for the counter space reserved.
035   */
036  public abstract int registerCounterSpace(int countersNeeded);
037
038  /**
039   *  This method is called to change the number of counters needed.
040   *
041   * @param handle  The handle describing which the data to be resized
042   * @param countersNeeded The number of counters needed
043   */
044  public abstract void resizeCounterSpace(int handle, int countersNeeded);
045
046  /**
047   * @param handle The counter space to look in
048   * @param location The counter whose value to return
049   * @return the value of a counter.
050   */
051  public abstract double getCounter(int handle, int location);
052
053  /**
054   * Sets the value of a counter.
055   *
056   * @param handle The counter space to look in
057   * @param location The counter whose value to return
058   * @param value The new value of the counter
059   */
060  public abstract void setCounter(int handle, int location, double value);
061
062  /**
063   * Create a place holder instruction to represent the counted event.
064   *
065   * @param handle The counter space to look in
066   * @param location The counter whose value to return
067   * @param incrementValue The value to add to the counter
068   * @return The instruction to increment the given counter
069   */
070  public abstract Instruction createEventCounterInstruction(int handle, int location, double incrementValue);
071
072  /**
073   *  Take an event counter instruction and mutate it into IR instructions that
074   *  will do the actual counting.
075   *
076   *  @param i the instruction to mutate
077   *  @param ir the IR that contains the instruction
078   */
079  public abstract void mutateOptEventCounterInstruction(Instruction i, IR ir);
080
081  /**
082   * Allow a counter to be inserted into a baseline compiled method.
083   * Still  under construction.
084   */
085  public abstract void insertBaselineCounter();
086}