50113
|
1 |
/*
|
|
2 |
* Copyright (c) 2013, 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 |
|
|
26 |
package jdk.jfr.event.compiler;
|
|
27 |
|
|
28 |
import static java.lang.Math.floor;
|
|
29 |
import static jdk.test.lib.Asserts.assertGreaterThanOrEqual;
|
|
30 |
import static jdk.test.lib.Asserts.assertLessThanOrEqual;
|
|
31 |
|
|
32 |
import java.time.Duration;
|
|
33 |
|
|
34 |
import jdk.jfr.Recording;
|
|
35 |
import jdk.jfr.consumer.RecordedEvent;
|
|
36 |
import jdk.test.lib.jfr.EventNames;
|
|
37 |
import jdk.test.lib.jfr.Events;
|
|
38 |
|
51214
|
39 |
/**
|
50113
|
40 |
* @test
|
|
41 |
* @summary Test that when an object is allocated outside a TLAB an event will be triggered.
|
|
42 |
* @key jfr
|
51214
|
43 |
* @requires vm.hasJFR
|
50113
|
44 |
* @library /test/lib
|
51991
|
45 |
* @run main/othervm -XX:+UseTLAB -XX:TLABSize=90k -XX:-ResizeTLAB -XX:TLABRefillWasteFraction=256 jdk.jfr.event.compiler.TestAllocOutsideTLAB
|
|
46 |
* @run main/othervm -XX:+UseTLAB -XX:TLABSize=90k -XX:-ResizeTLAB -XX:TLABRefillWasteFraction=256 -Xint jdk.jfr.event.compiler.TestAllocOutsideTLAB
|
50113
|
47 |
*/
|
|
48 |
|
|
49 |
/**
|
|
50 |
* Test that an event is triggered when an object is allocated outside a
|
51991
|
51 |
* Thread Local Allocation Buffer (TLAB). The test is done for default interpreted mode (-Xint).
|
50113
|
52 |
*
|
|
53 |
* To force objects to be allocated outside TLAB:
|
|
54 |
* the size of TLAB is set to 90k (-XX:TLABSize=90k);
|
|
55 |
* the size of allocated objects is set to 100k.
|
|
56 |
* max TLAB waste at refill is set to 256 (-XX:TLABRefillWasteFraction=256),
|
|
57 |
* to prevent a new TLAB creation.
|
|
58 |
*/
|
|
59 |
public class TestAllocOutsideTLAB {
|
|
60 |
private static final String EVENT_NAME = EventNames.ObjectAllocationOutsideTLAB;
|
|
61 |
|
|
62 |
private static final int BYTE_ARRAY_OVERHEAD = 16; // Extra bytes used by a byte array
|
|
63 |
private static final int OBJECT_SIZE = 100 * 1024;
|
|
64 |
private static final int OBJECT_SIZE_ALT = OBJECT_SIZE + 8; // Object size in case of disabled CompressedOops
|
|
65 |
private static final int OBJECTS_TO_ALLOCATE = 100;
|
|
66 |
private static final String BYTE_ARRAY_CLASS_NAME = new byte[0].getClass().getName();
|
|
67 |
|
|
68 |
public static byte[] tmp; // Used to prevent optimizer from removing code.
|
|
69 |
|
|
70 |
public static void main(String[] args) throws Exception {
|
|
71 |
Recording recording = new Recording();
|
|
72 |
recording.enable(EVENT_NAME).withThreshold(Duration.ofMillis(0));
|
|
73 |
recording.start();
|
|
74 |
for (int i = 0; i < OBJECTS_TO_ALLOCATE; ++i) {
|
|
75 |
tmp = new byte[OBJECT_SIZE - BYTE_ARRAY_OVERHEAD];
|
|
76 |
}
|
|
77 |
recording.stop();
|
|
78 |
|
|
79 |
int countEvents = 0;
|
|
80 |
for (RecordedEvent event : Events.fromRecording(recording)) {
|
|
81 |
if (!EVENT_NAME.equals(event.getEventType().getName())) {
|
|
82 |
continue;
|
|
83 |
}
|
|
84 |
System.out.println("Event:" + event);
|
|
85 |
|
|
86 |
long allocationSize = Events.assertField(event, "allocationSize").atLeast(1L).getValue();
|
|
87 |
String className = Events.assertField(event, "objectClass.name").notEmpty().getValue();
|
|
88 |
|
|
89 |
boolean isMyEvent = Thread.currentThread().getId() == event.getThread().getJavaThreadId()
|
|
90 |
&& className.equals(BYTE_ARRAY_CLASS_NAME)
|
|
91 |
&& (allocationSize == OBJECT_SIZE || allocationSize == OBJECT_SIZE_ALT);
|
|
92 |
if (isMyEvent) {
|
|
93 |
++countEvents;
|
|
94 |
}
|
|
95 |
}
|
|
96 |
|
|
97 |
int minCount = (int) floor(OBJECTS_TO_ALLOCATE * 0.80);
|
|
98 |
assertGreaterThanOrEqual(countEvents, minCount, "Too few tlab objects allocated");
|
|
99 |
assertLessThanOrEqual(countEvents, OBJECTS_TO_ALLOCATE, "Too many tlab objects allocated");
|
|
100 |
}
|
|
101 |
|
|
102 |
}
|