Class Generator

java.lang.Object
io.perfmark.impl.Generator
Direct Known Subclasses:
SecretGenerator.MethodHandleGenerator, SecretGenerator.VarHandleGenerator, SecretGenerator.VolatileGenerator

public class Generator extends Object
A Generator keeps track of what generation the PerfMark library is on. A generation is a way to group PerfMark recorded tasks and links together. This allows dynamically enabling and disabling PerfMark. Each time the library is enabled, a new generation is started and associated with all the recorded data.

This class is not threadsafe. Synchronization is handled externally.

Normal users are not expected to use this class.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final long
    Represents a failure to enable PerfMark library.
    static final int
    The number of reserved bits at the bottom of the generation.
    (package private) static final long
    This field is also here as a hack, capturing the time the class loaded.
    (package private) static final long
    This field is here as a hack.
    (package private) static final long
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
     
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    Returns the approximate cost to read the generation.
    long
    Returns the approximate cost to change the generation.
    long
    Gets the current generation, shifted left by GEN_OFFSET.
    void
    setGeneration(long generation)
    Sets the current generation count.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • INIT_NANO_TIME

      static final long INIT_NANO_TIME
      This field is here as a hack. This class is a shared dependency of both SecretPerfMarkImpl and Storage. The impl needs to record the first time an event occurs, but doesn't call Storage#clinit until PerfMark is enabled. This leads to the timings being off in the trace event viewer, since the "start" time is since it was enabled, rather than when the first PerfMark call happens.
    • NO_NANO_TIME

      static final long NO_NANO_TIME
    • INIT_CURRENT_TIME_MILLIS

      static final long INIT_CURRENT_TIME_MILLIS
      This field is also here as a hack, capturing the time the class loaded.
    • GEN_OFFSET

      public static final int GEN_OFFSET
      The number of reserved bits at the bottom of the generation. All generations should be left-shifted by this amount.
      See Also:
    • FAILURE

      public static final long FAILURE
      Represents a failure to enable PerfMark library. This can be used by subclasses to indicate a previous failure to set the generation. It can also be used to indicate the generation count has overflowed.
      See Also:
  • Constructor Details

    • Generator

      protected Generator()
  • Method Details

    • setGeneration

      public void setGeneration(long generation)
      Sets the current generation count. This should be eventually noticeable for callers of getGeneration(). An odd number means the library is enabled, while an even number means the library is disabled.
      Parameters:
      generation - the generation id, shifted left by GEN_OFFSET.
    • getGeneration

      public long getGeneration()
      Gets the current generation, shifted left by GEN_OFFSET. An odd number means the library is enabled, while an even number means the library is disabled.
      Returns:
      the current generation or FAILURE.
    • costOfSetNanos

      public long costOfSetNanos()
      Returns the approximate cost to change the generation.
      Returns:
      an approximate number of nanoseconds needed to change the generator value.
    • costOfGetNanos

      public long costOfGetNanos()
      Returns the approximate cost to read the generation.
      Returns:
      an approximate number of nanoseconds needed to read the generator value.