org.jikesrvm.adaptive.measurements.instrumentation
Class ManagedCounterData

java.lang.Object
  extended by org.jikesrvm.adaptive.measurements.instrumentation.ManagedCounterData
Direct Known Subclasses:
MethodInvocationCounterData, StringEventCounterData

public class ManagedCounterData
extends Object

This class provides the basic functionality for instrumented data that use counters allocated from a InstrumentedEventCounterManager. It provides the basic interface to access counters, forwarding those requests to the counter manager.


Nested Class Summary
(package private) static class ManagedCounterData.Counter
          Auxiliary class
 
Field Summary
protected  boolean automaticallyGrowCounters
           
protected  InstrumentedEventCounterManager counterManager
          Basic block instrumentation stores its counters using an abstracted counter allocation technique (a counterManager)
protected  int handle
          When a data object is registered with a counter manager, it is given an id, which is stored here.
protected  int numCounters
          How many counters are needed by this data?
 
Constructor Summary
ManagedCounterData(InstrumentedEventCounterManager counterManager)
           
 
Method Summary
 void automaticallyGrowCounters(boolean autoGrow)
          Tell the data to automatically expand the counters if there is a request to count an event that is greater than the current size.
 Instruction createEventCounterInstruction(int counterNumber)
          Create a place holder instruction to represent an increment of a particular counted event.
(package private)  Instruction createEventCounterInstruction(int counterNumber, double incrementValue)
          Create a place holder instruction to represent the counted event.
 double getCounter(int counterNumber)
          Return the count for the given (relative) index
 InstrumentedEventCounterManager getCounterManager()
          Return the counter manager for this data.
 int getHandle()
          Counter Managers give id's that identify the counter space they have given to each data.
 int getNumCounters()
          Return the number of counters currently allocated for this data
 void initializeCounters(int countersNeeded)
          This method must be called before creating any counters for this data.
(package private)  void report(CounterNameFunction f)
          This method prints the (sorted) nonzero elements a counter array.
 void resizeCounters(int countersNeeded)
          Used to reset the number of counters for this data
 void setCounter(int counterNumber, double value)
          Set the count for the given index
private  void sort(Vector<?> v)
          Sort a Vector by decreasing count.
private
<T> void
swap(Vector<T> vec, int i, int j)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

numCounters

protected int numCounters
How many counters are needed by this data?


handle

protected int handle
When a data object is registered with a counter manager, it is given an id, which is stored here.


counterManager

protected InstrumentedEventCounterManager counterManager
Basic block instrumentation stores its counters using an abstracted counter allocation technique (a counterManager)


automaticallyGrowCounters

protected boolean automaticallyGrowCounters
Constructor Detail

ManagedCounterData

ManagedCounterData(InstrumentedEventCounterManager counterManager)
Parameters:
counterManager - The counterManager that will provide the counter space
Method Detail

initializeCounters

public void initializeCounters(int countersNeeded)
This method must be called before creating any counters for this data. It registers this data with the counter manager and gets a "handle" that is coded into the counter instruction. If you need to change the number of counters in this data AFTER you have created counters, use void ManagerdCounterData.resizeCounters(int) instead.

Parameters:
countersNeeded - How many counters are needed by this data

automaticallyGrowCounters

public void automaticallyGrowCounters(boolean autoGrow)
Tell the data to automatically expand the counters if there is a request to count an event that is greater than the current size.

Parameters:
autoGrow - Whether the counters should grow automatically.

resizeCounters

public void resizeCounters(int countersNeeded)
Used to reset the number of counters for this data

Parameters:
countersNeeded - The number of counters needed

getCounter

public double getCounter(int counterNumber)
Return the count for the given (relative) index

Parameters:
counterNumber - The event number within the data
Returns:
The count associated with this counter

setCounter

public void setCounter(int counterNumber,
                       double value)
Set the count for the given index

Parameters:
counterNumber - The event number within the data
value - The new value of the counter

getNumCounters

public int getNumCounters()
Return the number of counters currently allocated for this data

Returns:
the number of counters

getHandle

public int getHandle()
Counter Managers give id's that identify the counter space they have given to each data. This method returns that ID.

Returns:
The handle given to this data object by the counter manager.

getCounterManager

public InstrumentedEventCounterManager getCounterManager()
Return the counter manager for this data.

Returns:
the counter manager object

createEventCounterInstruction

public Instruction createEventCounterInstruction(int counterNumber)
Create a place holder instruction to represent an increment of a particular counted event. Simply forwards the request to the counter manager.

Parameters:
counterNumber - The number of the counter to increment
Returns:
The instruction that will update the given counter

createEventCounterInstruction

Instruction createEventCounterInstruction(int counterNumber,
                                          double incrementValue)
Create a place holder instruction to represent the counted event. Simply forwards the request to the counter manager.

Parameters:
counterNumber - The number of the counter to increment
incrementValue - The value to add to the given counter
Returns:
The instruction that will update the given counter

report

final void report(CounterNameFunction f)
This method prints the (sorted) nonzero elements a counter array.

Parameters:
f - a function that gets the "name" for each counter

sort

private void sort(Vector<?> v)
Sort a Vector by decreasing count. (code borrowed from InstructionSampler.java)

Shell sort

Reference: "The C Programming Language", Kernighan & Ritchie, p. 116


swap

private <T> void swap(Vector<T> vec,
                      int i,
                      int j)