Class Generator

  • Direct Known Subclasses:
    SecretGenerator.MethodHandleGenerator, SecretGenerator.VarHandleGenerator, SecretGenerator.VolatileGenerator

    public class Generator
    extends java.lang.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 long FAILURE
      Represents a failure to enable PerfMark library.
      static int GEN_OFFSET
      The number of reserved bits at the bottom of the generation.
      (package private) static long INIT_CURRENT_TIME_MILLIS
      This field is also here as a hack, capturing the time the class loaded.
      (package private) static long INIT_NANO_TIME
      This field is here as a hack.
      (package private) static long NO_NANO_TIME  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected Generator()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      long costOfGetNanos()
      Returns the approximate cost to read the generation.
      long costOfSetNanos()
      Returns the approximate cost to change the generation.
      long getGeneration()
      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 Detail

      • 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:
        Constant Field Values
      • 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:
        Constant Field Values
    • Constructor Detail

      • Generator

        protected Generator()
    • Method Detail

      • 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.