test/jdk/jdk/jfr/event/oldobject/TestLargeRootSet.java
branchJEP-349-branch
changeset 58399 db26cf04e6ab
parent 51991 ad00713a0562
child 58484 a797a3b03d51
equal deleted inserted replaced
58396:58c7f9d726ba 58399:db26cf04e6ab
    89     private static class StackObject {
    89     private static class StackObject {
    90     }
    90     }
    91 
    91 
    92     public static void main(String[] args) throws Exception {
    92     public static void main(String[] args) throws Exception {
    93         WhiteBox.setWriteAllObjectSamples(true);
    93         WhiteBox.setWriteAllObjectSamples(true);
    94 
    94         while (true) {
    95         List<RootThread> threads = new ArrayList<>();
    95             List<RootThread> threads = new ArrayList<>();
    96         try (Recording r = new Recording()) {
    96             try (Recording r = new Recording()) {
    97             r.enable(EventNames.OldObjectSample).withStackTrace().with("cutoff", "infinity");
    97                 r.enable(EventNames.OldObjectSample).withStackTrace().with("cutoff", "infinity");
    98             r.start();
    98                 r.start();
    99             CyclicBarrier cb = new CyclicBarrier(THREAD_COUNT + 1);
    99                 CyclicBarrier cb = new CyclicBarrier(THREAD_COUNT + 1);
   100             for (int i = 0; i < THREAD_COUNT; i++) {
   100                 for (int i = 0; i < THREAD_COUNT; i++) {
   101                 RootThread t = new RootThread(cb);
   101                     RootThread t = new RootThread(cb);
   102                 t.start();
   102                     t.start();
   103                 if (i % 10 == 0) {
   103                     if (i % 10 == 0) {
   104                     // Give threads some breathing room before starting next batch
   104                         // Give threads some breathing room before starting next batch
   105                     Thread.sleep(100);
   105                         Thread.sleep(100);
       
   106                     }
       
   107                     threads.add(t);
   106                 }
   108                 }
   107                 threads.add(t);
   109                 cb.await();
       
   110                 System.gc();
       
   111                 r.stop();
       
   112                 cb.await();
       
   113                 List<RecordedEvent> events = Events.fromRecording(r);
       
   114                 Events.hasEvents(events);
       
   115                 for (RecordedEvent e : events) {
       
   116                     RecordedObject ro = e.getValue("object");
       
   117                     RecordedClass rc = ro.getValue("type");
       
   118                     System.out.println(rc.getName());
       
   119                     if (rc.getName().equals(StackObject[].class.getName())) {
       
   120                         return; // ok
       
   121                     }
       
   122                 }
       
   123                 // Asserts.fail("Could not find root object");
   108             }
   124             }
   109             cb.await();
       
   110             System.gc();
       
   111             r.stop();
       
   112             cb.await();
       
   113             List<RecordedEvent> events = Events.fromRecording(r);
       
   114             Events.hasEvents(events);
       
   115             for (RecordedEvent e : events) {
       
   116                 RecordedObject ro = e.getValue("object");
       
   117                 RecordedClass rc = ro.getValue("type");
       
   118                 System.out.println(rc.getName());
       
   119                 if (rc.getName().equals(StackObject[].class.getName())) {
       
   120                     return; // ok
       
   121                 }
       
   122             }
       
   123             Asserts.fail("Could not find root object");
       
   124         }
   125         }
   125     }
   126     }
   126 }
   127 }
   127 
   128