< prev index next >

test/jdk/jdk/jfr/event/gc/detailed/PromotionEvent.java

Print this page




  53     private final static String PROMOTION_OUTSIDE_PLAB_NAME = EventNames.PromoteObjectOutsidePLAB;
  54 
  55     // This value needs to match the command line option set above
  56     private final static int MAX_TENURING_THRESHOLD = 5;
  57 
  58     // Keep track of the collection count just before and after JFR recording
  59     private static int startGCCount = 0;
  60 
  61     // Dummy objects to keep things alive and assure allocation happens
  62     public static Object dummy;
  63     public static Object[] keepAlive = new Object[128];
  64     public static Object[] age = new Object[128];
  65 
  66     public static void test() throws Exception {
  67         GarbageCollectorMXBean ycBean = null;
  68 
  69         List<GarbageCollectorMXBean> gcBeans = ManagementFactory.getGarbageCollectorMXBeans();
  70         for (GarbageCollectorMXBean gcBean : gcBeans) {
  71             if ("PS Scavenge".equals(gcBean.getName())
  72                     || "G1 Young Generation".equals(gcBean.getName())
  73                     || ("ParNew".equals(gcBean.getName()))) {

  74                 ycBean = gcBean;
  75             }
  76 
  77             if (ycBean != null) {
  78                 break;
  79             }
  80         }
  81 
  82         if (ycBean == null) {
  83             assertNotNull(ycBean, "Test failed since the MXBean for the Young Collector could not be found.");
  84             return; // To remove IDE warning
  85         }
  86 
  87         System.gc(); // Clear nusery before recording
  88 
  89         // Get total GC count before recording
  90         for (GarbageCollectorMXBean gcBean : gcBeans) {
  91             startGCCount += gcBean.getCollectionCount();
  92         }
  93 
  94         Recording recording = new Recording();
  95         recording.enable(PROMOTION_IN_NEW_PLAB_NAME);
  96         recording.enable(PROMOTION_OUTSIDE_PLAB_NAME);
  97         recording.start();
  98 
  99         byte[] largeBytes = new byte[1024 * 10];
 100         byte[] smallBytes = new byte[64];
 101 
 102         // Some large strings to keep alive for tenuring
 103         for (int i = 0; i < keepAlive.length / 2; i++) {
 104             ThreadLocalRandom.current().nextBytes(largeBytes);
 105             keepAlive[i] = new String(largeBytes);
 106         }
 107 




  53     private final static String PROMOTION_OUTSIDE_PLAB_NAME = EventNames.PromoteObjectOutsidePLAB;
  54 
  55     // This value needs to match the command line option set above
  56     private final static int MAX_TENURING_THRESHOLD = 5;
  57 
  58     // Keep track of the collection count just before and after JFR recording
  59     private static int startGCCount = 0;
  60 
  61     // Dummy objects to keep things alive and assure allocation happens
  62     public static Object dummy;
  63     public static Object[] keepAlive = new Object[128];
  64     public static Object[] age = new Object[128];
  65 
  66     public static void test() throws Exception {
  67         GarbageCollectorMXBean ycBean = null;
  68 
  69         List<GarbageCollectorMXBean> gcBeans = ManagementFactory.getGarbageCollectorMXBeans();
  70         for (GarbageCollectorMXBean gcBean : gcBeans) {
  71             if ("PS Scavenge".equals(gcBean.getName())
  72                     || "G1 Young Generation".equals(gcBean.getName())
  73                     || "G1 Young".equals(gcBean.getName())
  74                     || "ParNew".equals(gcBean.getName())) {
  75                 ycBean = gcBean;
  76             }
  77 
  78             if (ycBean != null) {
  79                 break;
  80             }
  81         }
  82 
  83         if (ycBean == null) {
  84             assertNotNull(ycBean, "Test failed since the MXBean for the Young Collector could not be found.");
  85             return; // To remove IDE warning
  86         }
  87 
  88         System.gc(); // Clear nursery before recording
  89 
  90         // Get total GC count before recording
  91         for (GarbageCollectorMXBean gcBean : gcBeans) {
  92             startGCCount += gcBean.getCollectionCount();
  93         }
  94 
  95         Recording recording = new Recording();
  96         recording.enable(PROMOTION_IN_NEW_PLAB_NAME);
  97         recording.enable(PROMOTION_OUTSIDE_PLAB_NAME);
  98         recording.start();
  99 
 100         byte[] largeBytes = new byte[1024 * 10];
 101         byte[] smallBytes = new byte[64];
 102 
 103         // Some large strings to keep alive for tenuring
 104         for (int i = 0; i < keepAlive.length / 2; i++) {
 105             ThreadLocalRandom.current().nextBytes(largeBytes);
 106             keepAlive[i] = new String(largeBytes);
 107         }
 108 


< prev index next >