< prev index next >

src/jdk.jfr/share/classes/jdk/jfr/internal/OldObjectSample.java

Print this page




  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.jfr.internal;
  27 
  28 import java.util.HashMap;
  29 import java.util.List;
  30 import java.util.Map;
  31 
  32 import jdk.jfr.Enabled;

  33 import jdk.jfr.RecordingState;
  34 import jdk.jfr.internal.settings.CutoffSetting;
  35 import jdk.jfr.internal.test.WhiteBox;
  36 
  37 // The Old Object event could have been implemented as a periodic event, but
  38 // due to chunk rotations and how settings are calculated when multiple recordings
  39 // are running at the same time, it would lead to unacceptable overhead.
  40 //
  41 // Instead, the event is only emitted before a recording stops and
  42 // if that recording has the event enabled.
  43 //
  44 // This requires special handling and the purpose of this class is to provide that
  45 //
  46 public final class OldObjectSample {
  47 
  48     private static final String EVENT_NAME = Type.EVENT_NAME_PREFIX + "OldObjectSample";
  49     private static final String OLD_OBJECT_CUTOFF = EVENT_NAME + "#" + Cutoff.NAME;
  50     private static final String OLD_OBJECT_ENABLED = EVENT_NAME + "#" + Enabled.NAME;

  51 
  52     // Emit if old object is enabled in recoding with cutoff for that recording
  53     public static void emit(PlatformRecording recording) {
  54         if (isEnabled(recording)) {
  55             long nanos = CutoffSetting.parseValueSafe(recording.getSettings().get(OLD_OBJECT_CUTOFF));
  56             long ticks = Utils.nanosToTicks(nanos);
  57             JVM.getJVM().emitOldObjectSamples(ticks, WhiteBox.getWriteAllObjectSamples());
  58         }
  59     }
  60 
  61     // Emit if old object is enabled for at least one recording, and use the largest
  62     // cutoff for an enabled recoding
  63     public static void emit(List<PlatformRecording> recordings, Boolean pathToGcRoots) {
  64         boolean enabled = false;
  65         long cutoffNanos = Boolean.TRUE.equals(pathToGcRoots) ? Long.MAX_VALUE : 0L;
  66         for (PlatformRecording r : recordings) {
  67             if (r.getState() == RecordingState.RUNNING) {
  68                 if (isEnabled(r)) {
  69                     enabled = true;
  70                     long c = CutoffSetting.parseValueSafe(r.getSettings().get(OLD_OBJECT_CUTOFF));
  71                     cutoffNanos = Math.max(c, cutoffNanos);
  72                 }
  73             }
  74         }
  75         if (enabled) {
  76             long ticks = Utils.nanosToTicks(cutoffNanos);
  77             JVM.getJVM().emitOldObjectSamples(ticks, WhiteBox.getWriteAllObjectSamples());
  78         }
  79     }
  80 
  81     public static void updateSettingPathToGcRoots(Map<String, String> s, Boolean pathToGcRoots) {
  82         if (pathToGcRoots != null) {
  83             s.put(OLD_OBJECT_CUTOFF, pathToGcRoots ? "infinity" : "0 ns");
  84         }




  85     }
  86 
  87     public static Map<String, String> createSettingsForSnapshot(PlatformRecording recording, Boolean pathToGcRoots) {
  88         Map<String, String> settings = new HashMap<>(recording.getSettings());
  89         updateSettingPathToGcRoots(settings, pathToGcRoots);
  90         return settings;
  91     }
  92 
  93     private static boolean isEnabled(PlatformRecording r) {
  94         Map<String, String> settings = r.getSettings();
  95         String s = settings.get(OLD_OBJECT_ENABLED);
  96         return "true".equals(s);
  97     }
  98 }


  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.jfr.internal;
  27 
  28 import java.util.HashMap;
  29 import java.util.List;
  30 import java.util.Map;
  31 
  32 import jdk.jfr.Enabled;
  33 import jdk.jfr.Recording;
  34 import jdk.jfr.RecordingState;
  35 import jdk.jfr.internal.settings.CutoffSetting;
  36 import jdk.jfr.internal.test.WhiteBox;
  37 
  38 // The Old Object event could have been implemented as a periodic event, but
  39 // due to chunk rotations and how settings are calculated when multiple recordings
  40 // are running at the same time, it would lead to unacceptable overhead.
  41 //
  42 // Instead, the event is only emitted before a recording stops and
  43 // if that recording has the event enabled.
  44 //
  45 // This requires special handling and the purpose of this class is to provide that
  46 //
  47 public final class OldObjectSample {
  48 
  49     private static final String EVENT_NAME = Type.EVENT_NAME_PREFIX + "OldObjectSample";
  50     private static final String OLD_OBJECT_CUTOFF = EVENT_NAME + "#" + Cutoff.NAME;
  51     private static final String OLD_OBJECT_ENABLED = EVENT_NAME + "#" + Enabled.NAME;
  52     private static final String INFINITY = "infinity";
  53 
  54     // Emit if old object is enabled in recoding with cutoff for that recording
  55     public static void emit(PlatformRecording recording) {
  56         if (isEnabled(recording)) {
  57             long nanos = CutoffSetting.parseValueSafe(recording.getSettings().get(OLD_OBJECT_CUTOFF));
  58             long ticks = Utils.nanosToTicks(nanos);
  59             JVM.getJVM().emitOldObjectSamples(ticks, WhiteBox.getWriteAllObjectSamples());
  60         }
  61     }
  62 
  63     // Emit if old object is enabled for at least one recording, and use the largest
  64     // cutoff for an enabled recoding
  65     public static void emit(List<PlatformRecording> recordings, Boolean pathToGcRoots) {
  66         boolean enabled = false;
  67         long cutoffNanos = Boolean.TRUE.equals(pathToGcRoots) ? Long.MAX_VALUE : 0L;
  68         for (PlatformRecording r : recordings) {
  69             if (r.getState() == RecordingState.RUNNING) {
  70                 if (isEnabled(r)) {
  71                     enabled = true;
  72                     long c = CutoffSetting.parseValueSafe(r.getSettings().get(OLD_OBJECT_CUTOFF));
  73                     cutoffNanos = Math.max(c, cutoffNanos);
  74                 }
  75             }
  76         }
  77         if (enabled) {
  78             long ticks = Utils.nanosToTicks(cutoffNanos);
  79             JVM.getJVM().emitOldObjectSamples(ticks, WhiteBox.getWriteAllObjectSamples());
  80         }
  81     }
  82 
  83     public static void updateSettingPathToGcRoots(Map<String, String> s, Boolean pathToGcRoots) {
  84         if (pathToGcRoots != null) {
  85             s.put(OLD_OBJECT_CUTOFF, pathToGcRoots ? INFINITY : "0 ns");
  86         }
  87     }
  88 
  89     public static boolean isPathToGcRootsEnabled(Recording recording) {
  90         return INFINITY.equals(recording.getSettings().get(OLD_OBJECT_CUTOFF));
  91     }
  92 
  93     public static Map<String, String> createSettingsForSnapshot(PlatformRecording recording, Boolean pathToGcRoots) {
  94         Map<String, String> settings = new HashMap<>(recording.getSettings());
  95         updateSettingPathToGcRoots(settings, pathToGcRoots);
  96         return settings;
  97     }
  98 
  99     private static boolean isEnabled(PlatformRecording r) {
 100         Map<String, String> settings = r.getSettings();
 101         String s = settings.get(OLD_OBJECT_ENABLED);
 102         return "true".equals(s);
 103     }
 104 }
< prev index next >