org.jikesrvm.adaptive.database.methodsamples
Class MethodCountData

java.lang.Object
  extended by org.jikesrvm.adaptive.database.methodsamples.MethodCountData
All Implemented Interfaces:
Reportable

public final class MethodCountData
extends Object
implements Reportable

A container for recording how often a method is executed.


Field Summary
private  int[] cmids
          Maps count array index to compiled method id.
private  double[] counts
          Count array: counts how many times a method is executed.
private static boolean DEBUG
           
private  int[] map
          Maps compiled method id to count array index
private  int nextIndex
          Next available count array entry.
private  double totalCountsTaken
          Sum of values in count array.
 
Constructor Summary
MethodCountData()
          Constructor
 
Method Summary
 void augmentData(int cmid, double addVal)
          Augment the data associated with a given cmid by the specified number of samples
 MethodCountSet collectHotMethods(int optLevel, double threshold)
          Collect the hot methods that have been compiled at the given opt level.
private  void collectHotOptMethodsInternal(int index, List<HotMethodRecompilationEvent> collect, double threshold, int optLevel)
          Recursive implementation of collectHotOptNMethods.
private  double countsToHotness(double numCounts)
          Convert a value to a [0.0...1.0] fractional hotness value
private  int findHeapIdx(int cmid)
          Find the index that is already being used to hold the counts for cmid.
private  int findOrCreateHeapIdx(int cmid)
          Either find the index that is already being used to hold the counts for cmid or allocate a new entry in the heap for cmid.
 double getData(int cmid)
          Get the current count for a given compiled method id.
 double getTotalNumberOfSamples()
           
private  void growHeap()
          Increase the size of the count's backing arrays
private  void growHeapMap(int cmid)
          Grow the map to be at least as large as would be required to map cmid
private  void heapifyDown(int index)
          Restore the heap property after decreasing a count array entry's value
private  void heapifyUp(int index)
          Restore the heap property after increasing a count array entry's value
private  double hotnessToCounts(double hotness)
          Convert from a [0.0...1.0] hotness value to the number of counts that represents that fraction of hotness
private  void initialize()
          Reset fields.
 void insertHotMethods(int filterOptLevel, double threshold)
          Enqueue events describing the "hot" methods on the organizer's event queue.
private  void insertHotMethodsInternal(int index, int filterOptLevel, double threshold)
          Recursive implementation of insertHotMethods.
 void report()
          Print the counted (nonzero) methods.
 void reset()
          Reset (clear) the method counts
 void reset(int cmid)
          Reset (set to 0.0) the count for a given compiled method id.
private  void swap(int i, int j)
          Swap the heap entries at i and j.
 void update(int[] countBuffer, int numCounts)
          Drain a buffer of compiled method id's and update the count array.
 void update(int cmid, double numCounts)
          Increment the count for a compiled method id.
private  void validityCheck()
          Validate that internal fields are consistent.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

private static final boolean DEBUG
See Also:
Constant Field Values

totalCountsTaken

private double totalCountsTaken
Sum of values in count array.


counts

private double[] counts
Count array: counts how many times a method is executed. Constraint: counts[0] is not used.


cmids

private int[] cmids
Maps count array index to compiled method id. Constraint: cmids[0] is not used.


map

private int[] map
Maps compiled method id to count array index. '0' implies that there is no entry in the count array for this cmid


nextIndex

private int nextIndex
Next available count array entry.

Constructor Detail

MethodCountData

public MethodCountData()
Constructor

Method Detail

initialize

private void initialize()
Reset fields.


update

public void update(int[] countBuffer,
                   int numCounts)
Drain a buffer of compiled method id's and update the count array.

Parameters:
countBuffer - a buffer of compiled method id's
numCounts - the number of valid entries in the buffer

update

public void update(int cmid,
                   double numCounts)
Increment the count for a compiled method id.

Parameters:
cmid - compiled method id
numCounts - number of counts

report

public void report()
Print the counted (nonzero) methods. To get a sorted list, pipe the output through sort -n -r.

Specified by:
report in interface Reportable

getTotalNumberOfSamples

public double getTotalNumberOfSamples()
Returns:
the total number of samples taken

reset

public void reset()
Reset (clear) the method counts

Specified by:
reset in interface Reportable

getData

public double getData(int cmid)
Get the current count for a given compiled method id.

Parameters:
cmid - compiled method id

reset

public void reset(int cmid)
Reset (set to 0.0) the count for a given compiled method id.

Parameters:
cmid - compiled method id

augmentData

public void augmentData(int cmid,
                        double addVal)
Augment the data associated with a given cmid by the specified number of samples

Parameters:
cmid - compiled method id
addVal - samples to add

insertHotMethods

public void insertHotMethods(int filterOptLevel,
                             double threshold)
Enqueue events describing the "hot" methods on the organizer's event queue.

Parameters:
filterOptLevel - filter out all methods already compiled at this opt level (or higher)
threshold - hotness value above which the method is considered to be hot. (0.0 to 1.0)

collectHotMethods

public MethodCountSet collectHotMethods(int optLevel,
                                        double threshold)
Collect the hot methods that have been compiled at the given opt level.

Parameters:
optLevel - target opt level
threshold - hotness value above which the method is considered to be hot. (0.0 to 1.0)
Returns:
a MethodCountSet containing an array of compiled methods and an array of their counts.

hotnessToCounts

private double hotnessToCounts(double hotness)
Convert from a [0.0...1.0] hotness value to the number of counts that represents that fraction of hotness

Parameters:
hotness - a value [0.0...1.0]
Returns:
a number of counts

countsToHotness

private double countsToHotness(double numCounts)
Convert a value to a [0.0...1.0] fractional hotness value

Parameters:
numCounts - number of counts
Returns:
a value [0.0...1.0]

insertHotMethodsInternal

private void insertHotMethodsInternal(int index,
                                      int filterOptLevel,
                                      double threshold)
Recursive implementation of insertHotMethods. Exploit heap property. Note threshold has been converted into a count value by my caller!

Parameters:
index - count array index
filterOptLevel - filter out all methods already compiled at this opt level (or higher)
threshold - hotness value above which the method is considered to be hot. (0.0 to 1.0)

collectHotOptMethodsInternal

private void collectHotOptMethodsInternal(int index,
                                          List<HotMethodRecompilationEvent> collect,
                                          double threshold,
                                          int optLevel)
Recursive implementation of collectHotOptNMethods. Exploit heap property. Constraint: threshold has been converted into a count value by my caller!

Parameters:
index - count array index
collect - vector used to collect output.
threshold - hotness value above which the method is considered to be hot. (0.0 to 1.0)
optLevel - target opt level to look for.

findOrCreateHeapIdx

private int findOrCreateHeapIdx(int cmid)
Either find the index that is already being used to hold the counts for cmid or allocate a new entry in the heap for cmid.

Parameters:
cmid - compiled method id
Returns:
count array index

findHeapIdx

private int findHeapIdx(int cmid)
Find the index that is already being used to hold the counts for cmid. If no such index exists, return 0.

Parameters:
cmid - compiled method id

growHeapMap

private void growHeapMap(int cmid)
Grow the map to be at least as large as would be required to map cmid

Parameters:
cmid - compiled method id

growHeap

private void growHeap()
Increase the size of the count's backing arrays


heapifyUp

private void heapifyUp(int index)
Restore the heap property after increasing a count array entry's value

Parameters:
index - of count array entry

heapifyDown

private void heapifyDown(int index)
Restore the heap property after decreasing a count array entry's value

Parameters:
index - of count array entry

swap

private void swap(int i,
                  int j)
Swap the heap entries at i and j.

Parameters:
i - count array index
j - count array index

validityCheck

private void validityCheck()
Validate that internal fields are consistent. This is very expensive. Only use for debugging purposes.