org.jikesrvm.adaptive.measurements.listeners
Class MethodListener

java.lang.Object
  extended by org.jikesrvm.adaptive.measurements.listeners.Listener
      extended by org.jikesrvm.adaptive.measurements.listeners.MethodListener

public final class MethodListener
extends Listener

A MethodListener defines a listener to collect method invocation samples. Samples are collected in a buffer. When sampleSize samples have been collected the listener's organizer is activated to process them. Defines update's interface to be a compiled method identifier, CMID.


Field Summary
(package private)  int numSamples
          Number of samples taken so far
(package private)  int[] samples
          The sample buffer Key Invariant: samples.length >= sampleSize
(package private)  int sampleSize
          Number of samples to be gathered before they are processed
 
Constructor Summary
MethodListener(int sampleSize)
           
 
Method Summary
 int getNumSamples()
           
 int[] getSamples()
           
private  void recordSample(int CMID)
          This method records a sample containing the CMID (compiled method ID) passed.
 void report()
          Entry point to dump what has been collected.
 void reset()
          Reset the buffer to prepare to take more samples.
 void update(int cmid, int callerCmid, int whereFrom)
          This method is called when a sample is taken.
 
Methods inherited from class org.jikesrvm.adaptive.measurements.listeners.Listener
activate, activateOrganizer, isActive, passivate, setOrganizer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sampleSize

int sampleSize
Number of samples to be gathered before they are processed


numSamples

int numSamples
Number of samples taken so far


samples

int[] samples
The sample buffer Key Invariant: samples.length >= sampleSize

Constructor Detail

MethodListener

public MethodListener(int sampleSize)
Parameters:
sampleSize - the initial sampleSize for the listener
Method Detail

update

public void update(int cmid,
                   int callerCmid,
                   int whereFrom)
This method is called when a sample is taken. It parameter "cmid" represents the compiled method ID of the method which was executing at the time of the sample. This method bumps the counter and checks whether a threshold is reached.

NOTE: There can be multiple threads executing this method at the same time. We attempt to ensure that the resulting race conditions are safely handled, but make no guarentee that every sample is actually recorded.

Parameters:
cmid - the compiled method ID to update
callerCmid - a compiled method id for the caller, -1 if none
whereFrom - Was this a yieldpoint in a PROLOGUE, BACKEDGE, or EPILOGUE?

recordSample

private void recordSample(int CMID)
This method records a sample containing the CMID (compiled method ID) passed. Since multiple threads may be taking samples concurrently, we use fetchAndAdd to distribute indices into the buffer AND to record when a sample is taken. (Thread 1 may get an earlier index, but complete the insertion after Thread 2.)

Parameters:
CMID - compiled method ID to record

report

public void report()
Description copied from class: Listener
Entry point to dump what has been collected.

Specified by:
report in class Listener

reset

public void reset()
Reset the buffer to prepare to take more samples.

Specified by:
reset in class Listener

getSamples

public int[] getSamples()
Returns:
the buffer of samples

getNumSamples

public int getNumSamples()
Returns:
how many samples in the array returned by getSamples are valid