author | egahlin |
Thu, 10 Oct 2019 17:36:57 +0200 | |
branch | JEP-349-branch |
changeset 58540 | 43229acd75ea |
parent 58498 | 5a2761a6a564 |
permissions | -rw-r--r-- |
50113 | 1 |
/* |
2 |
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
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 |
package jdk.jfr.event.oldobject; |
|
26 |
||
27 |
import java.util.ArrayList; |
|
28 |
import java.util.List; |
|
58540
43229acd75ea
Random sized allocation for TestLaregRootSet.java
egahlin
parents:
58498
diff
changeset
|
29 |
import java.util.Random; |
58498 | 30 |
import java.util.Vector; |
50113 | 31 |
import java.util.concurrent.BrokenBarrierException; |
32 |
import java.util.concurrent.CyclicBarrier; |
|
33 |
||
34 |
import jdk.jfr.Recording; |
|
35 |
import jdk.jfr.consumer.RecordedClass; |
|
36 |
import jdk.jfr.consumer.RecordedEvent; |
|
58484 | 37 |
import jdk.jfr.consumer.RecordedFrame; |
38 |
import jdk.jfr.consumer.RecordedMethod; |
|
50113 | 39 |
import jdk.jfr.consumer.RecordedObject; |
58484 | 40 |
import jdk.jfr.consumer.RecordedStackTrace; |
50113 | 41 |
import jdk.jfr.internal.test.WhiteBox; |
42 |
import jdk.test.lib.jfr.EventNames; |
|
43 |
import jdk.test.lib.jfr.Events; |
|
44 |
||
51214 | 45 |
/** |
50113 | 46 |
* @test |
47 |
* @key jfr |
|
51214 | 48 |
* @requires vm.hasJFR |
50113 | 49 |
* @requires vm.gc == "null" |
50 |
* @library /test/lib /test/jdk |
|
51 |
* @modules jdk.jfr/jdk.jfr.internal.test |
|
51991 | 52 |
* @run main/othervm -XX:TLABSize=2k jdk.jfr.event.oldobject.TestLargeRootSet |
50113 | 53 |
*/ |
54 |
public class TestLargeRootSet { |
|
55 |
||
56 |
private static final int THREAD_COUNT = 50; |
|
58540
43229acd75ea
Random sized allocation for TestLaregRootSet.java
egahlin
parents:
58498
diff
changeset
|
57 |
private static final Random RANDOM = new Random(4711); |
58498 | 58 |
public static Vector<StackObject[]> temporaries = new Vector<>(OldObjects.MIN_SIZE); |
50113 | 59 |
|
60 |
private static class RootThread extends Thread { |
|
61 |
private final CyclicBarrier barrier; |
|
62 |
private int maxDepth = OldObjects.MIN_SIZE / THREAD_COUNT; |
|
63 |
||
64 |
RootThread(CyclicBarrier cb) { |
|
65 |
this.barrier = cb; |
|
66 |
} |
|
67 |
||
68 |
public void run() { |
|
69 |
buildRootObjects(); |
|
70 |
} |
|
71 |
||
72 |
private void buildRootObjects() { |
|
73 |
if (maxDepth-- > 0) { |
|
58540
43229acd75ea
Random sized allocation for TestLaregRootSet.java
egahlin
parents:
58498
diff
changeset
|
74 |
// Allocate array to trigger sampling code path for interpreter |
43229acd75ea
Random sized allocation for TestLaregRootSet.java
egahlin
parents:
58498
diff
changeset
|
75 |
// / c1 |
43229acd75ea
Random sized allocation for TestLaregRootSet.java
egahlin
parents:
58498
diff
changeset
|
76 |
StackObject[] stackObject = new StackObject[RANDOM.nextInt(7)]; |
50113 | 77 |
temporaries.add(stackObject); // make sure object escapes |
78 |
buildRootObjects(); |
|
79 |
} else { |
|
80 |
temporaries.clear(); |
|
81 |
try { |
|
82 |
barrier.await(); // wait for gc |
|
83 |
barrier.await(); // wait for recording to be stopped |
|
84 |
} catch (InterruptedException e) { |
|
85 |
System.err.println("Thread was unexpected interrupted: " + e.getMessage()); |
|
86 |
} catch (BrokenBarrierException e) { |
|
87 |
System.err.println("Unexpected barrier exception: " + e.getMessage()); |
|
88 |
} |
|
89 |
return; |
|
90 |
} |
|
91 |
} |
|
92 |
} |
|
93 |
||
94 |
private static class StackObject { |
|
95 |
} |
|
96 |
||
97 |
public static void main(String[] args) throws Exception { |
|
98 |
WhiteBox.setWriteAllObjectSamples(true); |
|
58484 | 99 |
int attempt = 1; |
58399 | 100 |
while (true) { |
58484 | 101 |
System.out.println(); |
102 |
System.out.println(); |
|
103 |
System.out.println("ATTEMPT: " + attempt); |
|
104 |
System.out.println("===================================="); |
|
58399 | 105 |
List<RootThread> threads = new ArrayList<>(); |
106 |
try (Recording r = new Recording()) { |
|
107 |
r.enable(EventNames.OldObjectSample).withStackTrace().with("cutoff", "infinity"); |
|
108 |
r.start(); |
|
109 |
CyclicBarrier cb = new CyclicBarrier(THREAD_COUNT + 1); |
|
110 |
for (int i = 0; i < THREAD_COUNT; i++) { |
|
111 |
RootThread t = new RootThread(cb); |
|
112 |
t.start(); |
|
113 |
if (i % 10 == 0) { |
|
58540
43229acd75ea
Random sized allocation for TestLaregRootSet.java
egahlin
parents:
58498
diff
changeset
|
114 |
// Give threads some breathing room before starting next |
43229acd75ea
Random sized allocation for TestLaregRootSet.java
egahlin
parents:
58498
diff
changeset
|
115 |
// batch |
58399 | 116 |
Thread.sleep(100); |
117 |
} |
|
118 |
threads.add(t); |
|
50113 | 119 |
} |
58399 | 120 |
cb.await(); |
121 |
System.gc(); |
|
122 |
r.stop(); |
|
123 |
cb.await(); |
|
124 |
List<RecordedEvent> events = Events.fromRecording(r); |
|
125 |
Events.hasEvents(events); |
|
58484 | 126 |
int sample = 0; |
58399 | 127 |
for (RecordedEvent e : events) { |
128 |
RecordedObject ro = e.getValue("object"); |
|
129 |
RecordedClass rc = ro.getValue("type"); |
|
58484 | 130 |
System.out.println("Sample: " + sample); |
58540
43229acd75ea
Random sized allocation for TestLaregRootSet.java
egahlin
parents:
58498
diff
changeset
|
131 |
System.out.println(" - allocationTime: " + e.getInstant("allocationTime")); |
58484 | 132 |
System.out.println(" - type: " + rc.getName()); |
133 |
RecordedObject root = e.getValue("root"); |
|
134 |
if (root != null) { |
|
135 |
System.out.println(" - root:"); |
|
136 |
System.out.println(" - description: " + root.getValue("description")); |
|
137 |
System.out.println(" - system: " + root.getValue("system")); |
|
138 |
System.out.println(" - type: " + root.getValue("type")); |
|
58498 | 139 |
} else { |
140 |
System.out.println(" - root: N/A"); |
|
141 |
} |
|
142 |
RecordedStackTrace stack = e.getStackTrace(); |
|
143 |
if (stack != null) { |
|
144 |
System.out.println(" - stack:"); |
|
145 |
int frameCount = 0; |
|
58540
43229acd75ea
Random sized allocation for TestLaregRootSet.java
egahlin
parents:
58498
diff
changeset
|
146 |
for (RecordedFrame frame : stack.getFrames()) { |
58498 | 147 |
RecordedMethod m = frame.getMethod(); |
58540
43229acd75ea
Random sized allocation for TestLaregRootSet.java
egahlin
parents:
58498
diff
changeset
|
148 |
System.out.println(" " + m.getType().getName() + "." + m.getName() + "(...)"); |
58498 | 149 |
frameCount++; |
150 |
if (frameCount == 10) { |
|
151 |
break; |
|
58484 | 152 |
} |
153 |
} |
|
58498 | 154 |
} else { |
155 |
System.out.println(" - stack: N/A"); |
|
58399 | 156 |
} |
58484 | 157 |
System.out.println(); |
58498 | 158 |
if (rc.getName().equals(StackObject[].class.getName())) { |
159 |
return; // ok |
|
160 |
} |
|
58484 | 161 |
sample++; |
58399 | 162 |
} |
50113 | 163 |
} |
58484 | 164 |
attempt++; |
50113 | 165 |
} |
166 |
} |
|
58540
43229acd75ea
Random sized allocation for TestLaregRootSet.java
egahlin
parents:
58498
diff
changeset
|
167 |
|
50113 | 168 |
} |