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;
|
58863
|
29 |
import java.util.Random;
|
|
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;
|
58863
|
37 |
import jdk.jfr.consumer.RecordedFrame;
|
|
38 |
import jdk.jfr.consumer.RecordedMethod;
|
50113
|
39 |
import jdk.jfr.consumer.RecordedObject;
|
58863
|
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;
|
58863
|
57 |
private static final Random RANDOM = new Random(4711);
|
|
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) {
|
58863
|
74 |
// Allocate array to trigger sampling code path for interpreter
|
|
75 |
// / c1
|
|
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);
|
58863
|
99 |
int attempt = 1;
|
|
100 |
while (true) {
|
|
101 |
System.out.println();
|
|
102 |
System.out.println();
|
|
103 |
System.out.println("ATTEMPT: " + attempt);
|
|
104 |
System.out.println("====================================");
|
|
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) {
|
|
114 |
// Give threads some breathing room before starting next
|
|
115 |
// batch
|
|
116 |
Thread.sleep(100);
|
|
117 |
}
|
|
118 |
threads.add(t);
|
50113
|
119 |
}
|
58863
|
120 |
cb.await();
|
|
121 |
System.gc();
|
|
122 |
r.stop();
|
|
123 |
cb.await();
|
|
124 |
List<RecordedEvent> events = Events.fromRecording(r);
|
|
125 |
Events.hasEvents(events);
|
|
126 |
int sample = 0;
|
|
127 |
for (RecordedEvent e : events) {
|
|
128 |
RecordedObject ro = e.getValue("object");
|
|
129 |
RecordedClass rc = ro.getValue("type");
|
|
130 |
System.out.println("Sample: " + sample);
|
|
131 |
System.out.println(" - allocationTime: " + e.getInstant("allocationTime"));
|
|
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"));
|
|
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;
|
|
146 |
for (RecordedFrame frame : stack.getFrames()) {
|
|
147 |
RecordedMethod m = frame.getMethod();
|
|
148 |
System.out.println(" " + m.getType().getName() + "." + m.getName() + "(...)");
|
|
149 |
frameCount++;
|
|
150 |
if (frameCount == 10) {
|
|
151 |
break;
|
|
152 |
}
|
|
153 |
}
|
|
154 |
} else {
|
|
155 |
System.out.println(" - stack: N/A");
|
|
156 |
}
|
|
157 |
System.out.println();
|
|
158 |
if (rc.getName().equals(StackObject[].class.getName())) {
|
|
159 |
return; // ok
|
|
160 |
}
|
|
161 |
sample++;
|
50113
|
162 |
}
|
|
163 |
}
|
58863
|
164 |
attempt++;
|
50113
|
165 |
}
|
|
166 |
}
|
58863
|
167 |
|
50113
|
168 |
}
|