< prev index next >

test/lib/jdk/test/lib/jfr/GCHelper.java

Print this page




  63     public static final String event_heap_metaspace_summary = EventNames.MetaspaceSummary;
  64     public static final String event_reference_statistics = EventNames.GCReferenceStatistics;
  65     public static final String event_phases_pause = EventNames.GCPhasePause;
  66     public static final String event_phases_level_1 = EventNames.GCPhasePauseLevel1;
  67     public static final String event_phases_level_2 = EventNames.GCPhasePauseLevel2;
  68     public static final String event_phases_level_3 = EventNames.GCPhasePauseLevel3;
  69 
  70     public static final String gcG1New = "G1New";
  71     public static final String gcParNew = "ParNew";
  72     public static final String gcDefNew = "DefNew";
  73     public static final String gcParallelScavenge = "ParallelScavenge";
  74     public static final String gcG1Old = "G1Old";
  75     public static final String gcG1Full = "G1Full";
  76     public static final String gcConcurrentMarkSweep = "ConcurrentMarkSweep";
  77     public static final String gcSerialOld = "SerialOld";
  78     public static final String gcPSMarkSweep = "PSMarkSweep";
  79     public static final String gcParallelOld = "ParallelOld";
  80     public static final String pauseLevelEvent = "GCPhasePauseLevel";
  81 
  82     private static final List<String> g1HeapRegionTypes;

  83     private static PrintStream defaultErrorLog = null;
  84 
  85     public static int getGcId(RecordedEvent event) {
  86         return Events.assertField(event, "gcId").getValue();
  87     }
  88 
  89     public static boolean isGcEvent(RecordedEvent event) {
  90         for (ValueDescriptor v : event.getFields()) {
  91             if ("gcId".equals(v.getName())) {
  92                 return true;
  93             }
  94         }
  95         return false;
  96     }
  97 
  98 //    public static String getEventDesc(RecordedEvent event) {
  99 //      final String path = event.getEventType().getName();
 100 //        if (!isGcEvent(event)) {
 101 //            return path;
 102 //        }


 190         requiredEvents.put(gcParNew, new String[] {event_heap_summary, event_heap_metaspace_summary, event_phases_pause, event_phases_level_1, event_young_garbage_collection});
 191         requiredEvents.put(gcDefNew, new String[] {event_heap_summary, event_heap_metaspace_summary, event_phases_pause, event_phases_level_1, event_young_garbage_collection});
 192         requiredEvents.put(gcParallelScavenge, new String[] {event_heap_summary, event_heap_ps_summary, event_heap_metaspace_summary, event_reference_statistics, event_phases_pause, event_phases_level_1, event_young_garbage_collection});
 193         requiredEvents.put(gcG1Old, new String[] {event_heap_summary, event_old_garbage_collection});
 194         requiredEvents.put(gcG1Full, new String[] {event_heap_summary, event_heap_metaspace_summary, event_phases_pause, event_phases_level_1, event_old_garbage_collection});
 195         requiredEvents.put(gcConcurrentMarkSweep, new String[] {event_phases_pause, event_phases_level_1, event_old_garbage_collection});
 196         requiredEvents.put(gcSerialOld, new String[] {event_heap_summary, event_heap_metaspace_summary, event_phases_pause, event_phases_level_1, event_old_garbage_collection});
 197         requiredEvents.put(gcParallelOld, new String[] {event_heap_summary, event_heap_ps_summary, event_heap_metaspace_summary, event_reference_statistics, event_phases_pause, event_phases_level_1, event_old_garbage_collection, event_parold_garbage_collection});
 198 
 199         String[] g1HeapRegionTypeLiterals = new String[] {
 200                                                            "Free",
 201                                                            "Eden",
 202                                                            "Survivor",
 203                                                            "Starts Humongous",
 204                                                            "Continues Humongous",
 205                                                            "Old",
 206                                                            "Archive"
 207                                                          };
 208 
 209         g1HeapRegionTypes = Collections.unmodifiableList(Arrays.asList(g1HeapRegionTypeLiterals));















 210     }
 211 
 212     /**
 213      * Contains all GC events belonging to the same GC (same gcId).
 214      */
 215     public static class GcBatch {
 216         private List<RecordedEvent> events = new ArrayList<>();
 217 
 218         public int getGcId() {
 219             if (events.isEmpty()) {
 220                 return -1;
 221             }
 222             return GCHelper.getGcId(events.get(0));
 223         }
 224 
 225         public String getName() {
 226             RecordedEvent endEvent = getEndEvent();
 227             String name = endEvent == null ? null : Events.assertField(endEvent, "name").getValue();
 228             return name == null ? "null" : name;
 229         }


 424                 defaultErrorLog = new PrintStream(new FileOutputStream("error.log", true));
 425             } catch (IOException e) {
 426                 e.printStackTrace();
 427                 defaultErrorLog = System.err;
 428             }
 429         }
 430         return defaultErrorLog;
 431     }
 432 
 433     public static void log(Object msg) {
 434         log(msg, System.err);
 435         log(msg, getDefaultErrorLog());
 436     }
 437 
 438     public static void log(Object msg, PrintStream ps) {
 439         ps.println(msg);
 440     }
 441 
 442     public static boolean isValidG1HeapRegionType(final String type) {
 443         return g1HeapRegionTypes.contains(type);







 444     }
 445 
 446     /**
 447      * Helper function to align heap size up.
 448      *
 449      * @param value
 450      * @param alignment
 451      * @return aligned value
 452      */
 453     public static long alignUp(long value, long alignment) {
 454         return (value + alignment - 1) & ~(alignment - 1);
 455     }
 456 
 457     /**
 458      * Helper function to align heap size down.
 459      *
 460      * @param value
 461      * @param alignment
 462      * @return aligned value
 463      */


  63     public static final String event_heap_metaspace_summary = EventNames.MetaspaceSummary;
  64     public static final String event_reference_statistics = EventNames.GCReferenceStatistics;
  65     public static final String event_phases_pause = EventNames.GCPhasePause;
  66     public static final String event_phases_level_1 = EventNames.GCPhasePauseLevel1;
  67     public static final String event_phases_level_2 = EventNames.GCPhasePauseLevel2;
  68     public static final String event_phases_level_3 = EventNames.GCPhasePauseLevel3;
  69 
  70     public static final String gcG1New = "G1New";
  71     public static final String gcParNew = "ParNew";
  72     public static final String gcDefNew = "DefNew";
  73     public static final String gcParallelScavenge = "ParallelScavenge";
  74     public static final String gcG1Old = "G1Old";
  75     public static final String gcG1Full = "G1Full";
  76     public static final String gcConcurrentMarkSweep = "ConcurrentMarkSweep";
  77     public static final String gcSerialOld = "SerialOld";
  78     public static final String gcPSMarkSweep = "PSMarkSweep";
  79     public static final String gcParallelOld = "ParallelOld";
  80     public static final String pauseLevelEvent = "GCPhasePauseLevel";
  81 
  82     private static final List<String> g1HeapRegionTypes;
  83     private static final List<String> shenandoahHeapRegionStates;
  84     private static PrintStream defaultErrorLog = null;
  85 
  86     public static int getGcId(RecordedEvent event) {
  87         return Events.assertField(event, "gcId").getValue();
  88     }
  89 
  90     public static boolean isGcEvent(RecordedEvent event) {
  91         for (ValueDescriptor v : event.getFields()) {
  92             if ("gcId".equals(v.getName())) {
  93                 return true;
  94             }
  95         }
  96         return false;
  97     }
  98 
  99 //    public static String getEventDesc(RecordedEvent event) {
 100 //      final String path = event.getEventType().getName();
 101 //        if (!isGcEvent(event)) {
 102 //            return path;
 103 //        }


 191         requiredEvents.put(gcParNew, new String[] {event_heap_summary, event_heap_metaspace_summary, event_phases_pause, event_phases_level_1, event_young_garbage_collection});
 192         requiredEvents.put(gcDefNew, new String[] {event_heap_summary, event_heap_metaspace_summary, event_phases_pause, event_phases_level_1, event_young_garbage_collection});
 193         requiredEvents.put(gcParallelScavenge, new String[] {event_heap_summary, event_heap_ps_summary, event_heap_metaspace_summary, event_reference_statistics, event_phases_pause, event_phases_level_1, event_young_garbage_collection});
 194         requiredEvents.put(gcG1Old, new String[] {event_heap_summary, event_old_garbage_collection});
 195         requiredEvents.put(gcG1Full, new String[] {event_heap_summary, event_heap_metaspace_summary, event_phases_pause, event_phases_level_1, event_old_garbage_collection});
 196         requiredEvents.put(gcConcurrentMarkSweep, new String[] {event_phases_pause, event_phases_level_1, event_old_garbage_collection});
 197         requiredEvents.put(gcSerialOld, new String[] {event_heap_summary, event_heap_metaspace_summary, event_phases_pause, event_phases_level_1, event_old_garbage_collection});
 198         requiredEvents.put(gcParallelOld, new String[] {event_heap_summary, event_heap_ps_summary, event_heap_metaspace_summary, event_reference_statistics, event_phases_pause, event_phases_level_1, event_old_garbage_collection, event_parold_garbage_collection});
 199 
 200         String[] g1HeapRegionTypeLiterals = new String[] {
 201                                                            "Free",
 202                                                            "Eden",
 203                                                            "Survivor",
 204                                                            "Starts Humongous",
 205                                                            "Continues Humongous",
 206                                                            "Old",
 207                                                            "Archive"
 208                                                          };
 209 
 210         g1HeapRegionTypes = Collections.unmodifiableList(Arrays.asList(g1HeapRegionTypeLiterals));
 211 
 212         String[] shenandoahHeapRegionStateLiterals = new String[] {
 213                                                                     "Empty Uncommitted",
 214                                                                     "Empty Committed",
 215                                                                     "Regular",
 216                                                                     "Humongous Start",
 217                                                                     "Humongous Continuation",
 218                                                                     "Humongous Start, Pinned",
 219                                                                     "Collection Set",
 220                                                                     "Pinned",
 221                                                                     "Collection Set, Pinned",
 222                                                                     "Trash"
 223         };
 224 
 225         shenandoahHeapRegionStates = Collections.unmodifiableList(Arrays.asList(shenandoahHeapRegionStateLiterals));
 226     }
 227 
 228     /**
 229      * Contains all GC events belonging to the same GC (same gcId).
 230      */
 231     public static class GcBatch {
 232         private List<RecordedEvent> events = new ArrayList<>();
 233 
 234         public int getGcId() {
 235             if (events.isEmpty()) {
 236                 return -1;
 237             }
 238             return GCHelper.getGcId(events.get(0));
 239         }
 240 
 241         public String getName() {
 242             RecordedEvent endEvent = getEndEvent();
 243             String name = endEvent == null ? null : Events.assertField(endEvent, "name").getValue();
 244             return name == null ? "null" : name;
 245         }


 440                 defaultErrorLog = new PrintStream(new FileOutputStream("error.log", true));
 441             } catch (IOException e) {
 442                 e.printStackTrace();
 443                 defaultErrorLog = System.err;
 444             }
 445         }
 446         return defaultErrorLog;
 447     }
 448 
 449     public static void log(Object msg) {
 450         log(msg, System.err);
 451         log(msg, getDefaultErrorLog());
 452     }
 453 
 454     public static void log(Object msg, PrintStream ps) {
 455         ps.println(msg);
 456     }
 457 
 458     public static boolean isValidG1HeapRegionType(final String type) {
 459         return g1HeapRegionTypes.contains(type);
 460     }
 461 
 462     public static boolean assertIsValidShenandoahHeapRegionState(final String state) {
 463         if (!shenandoahHeapRegionStates.contains(state)) {
 464             throw new AssertionError("Unknown state '" + state + "', valid heap region states are " + shenandoahHeapRegionStates);
 465         }
 466         return true;
 467     }
 468 
 469     /**
 470      * Helper function to align heap size up.
 471      *
 472      * @param value
 473      * @param alignment
 474      * @return aligned value
 475      */
 476     public static long alignUp(long value, long alignment) {
 477         return (value + alignment - 1) & ~(alignment - 1);
 478     }
 479 
 480     /**
 481      * Helper function to align heap size down.
 482      *
 483      * @param value
 484      * @param alignment
 485      * @return aligned value
 486      */
< prev index next >