Skip to content

Commit 65831eb

Browse files
committed
8281318: Improve jfr/event/allocation tests reliability
Reviewed-by: mgronlun
1 parent eee6a56 commit 65831eb

File tree

3 files changed

+54
-21
lines changed

3 files changed

+54
-21
lines changed

test/jdk/jdk/jfr/event/allocation/TestObjectAllocationInNewTLABEvent.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,33 +30,45 @@
3030
import jdk.test.lib.jfr.EventNames;
3131
import jdk.test.lib.jfr.Events;
3232
import jdk.test.lib.Asserts;
33+
import jdk.test.lib.Platform;
34+
import sun.hotspot.WhiteBox;
3335

3436
/**
3537
* @test
3638
* @summary Test that event is triggered when an object is allocated in a new TLAB.
3739
* @key jfr
3840
* @requires vm.hasJFR
3941
* @library /test/lib
40-
* @run main/othervm -XX:+UseTLAB -XX:TLABSize=100k -XX:-ResizeTLAB -XX:TLABRefillWasteFraction=1 jdk.jfr.event.allocation.TestObjectAllocationInNewTLABEvent
41-
* @run main/othervm -XX:+UseTLAB -XX:TLABSize=100k -XX:-ResizeTLAB -XX:TLABRefillWasteFraction=1 -Xint jdk.jfr.event.allocation.TestObjectAllocationInNewTLABEvent
42+
* @build sun.hotspot.WhiteBox
43+
*
44+
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
45+
* @run main/othervm -XX:+WhiteBoxAPI -Xbootclasspath/a:.
46+
* -XX:+UseTLAB -XX:TLABSize=100k -XX:-ResizeTLAB -XX:TLABRefillWasteFraction=1
47+
* jdk.jfr.event.allocation.TestObjectAllocationInNewTLABEvent
48+
* @run main/othervm -XX:+WhiteBoxAPI -Xbootclasspath/a:.
49+
* -XX:+UseTLAB -XX:TLABSize=100k -XX:-ResizeTLAB -XX:TLABRefillWasteFraction=1
50+
* -Xint
51+
* jdk.jfr.event.allocation.TestObjectAllocationInNewTLABEvent
4252
*/
4353

4454
/**
4555
* Test that when an object is allocated in a new Thread Local Allocation Buffer (TLAB)
4656
* an event will be triggered. The test is done for default and interpreted mode (-Xint).
4757
*
4858
* To force objects to be allocated in a new TLAB:
49-
* the size of TLAB is set to 100k (-XX:TLABSize=100k);
50-
* the size of allocated objects is set to 100k minus 16 bytes overhead;
59+
* the initial size of TLAB is set to 100k (-XX:TLABSize=100k);
60+
* the size of allocated objects is set to 128k;
5161
* max TLAB waste at refill is set to minimum (-XX:TLABRefillWasteFraction=1),
5262
* to provoke a new TLAB creation.
5363
*/
5464
public class TestObjectAllocationInNewTLABEvent {
5565
private final static String EVENT_NAME = EventNames.ObjectAllocationInNewTLAB;
5666

57-
private static final int BYTE_ARRAY_OVERHEAD = 16; // Extra bytes used by a byte array.
58-
private static final int OBJECT_SIZE = 100 * 1024;
59-
private static final int OBJECT_SIZE_ALT = OBJECT_SIZE + 8; // Object size in case of disabled CompressedOops.
67+
private static final Boolean COMPRESSED_CLASS_PTRS = WhiteBox.getWhiteBox().getBooleanVMFlag("UseCompressedClassPointers");
68+
69+
private static final int BYTE_ARRAY_OVERHEAD = (Platform.is64bit() && !COMPRESSED_CLASS_PTRS) ? 24 : 16;
70+
private static final int OBJECT_SIZE = 128 * 1024;
71+
6072
private static final int OBJECTS_TO_ALLOCATE = 100;
6173
private static final String BYTE_ARRAY_CLASS_NAME = new byte[0].getClass().getName();
6274
private static final int INITIAL_TLAB_SIZE = 100 * 1024;
@@ -112,9 +124,9 @@ private static void verify(RecordedEvent event) {
112124
long allocationSize = Events.assertField(event, "allocationSize").atLeast(1L).getValue();
113125
long tlabSize = Events.assertField(event, "tlabSize").atLeast(allocationSize).getValue();
114126
String className = Events.assertField(event, "objectClass.name").notEmpty().getValue();
115-
if (className.equals(BYTE_ARRAY_CLASS_NAME) && (allocationSize == OBJECT_SIZE || allocationSize == OBJECT_SIZE_ALT)) {
127+
if (className.equals(BYTE_ARRAY_CLASS_NAME) && (allocationSize == OBJECT_SIZE)) {
116128
countAllTlabs++;
117-
if (tlabSize == INITIAL_TLAB_SIZE + OBJECT_SIZE || tlabSize == INITIAL_TLAB_SIZE + OBJECT_SIZE_ALT) {
129+
if (tlabSize == INITIAL_TLAB_SIZE + OBJECT_SIZE) {
118130
countFullTlabs++;
119131
}
120132
}

test/jdk/jdk/jfr/event/allocation/TestObjectAllocationOutsideTLABEvent.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,33 +30,45 @@
3030
import jdk.test.lib.jfr.EventNames;
3131
import jdk.test.lib.jfr.Events;
3232
import jdk.test.lib.Asserts;
33+
import jdk.test.lib.Platform;
34+
import sun.hotspot.WhiteBox;
3335

3436
/**
3537
* @test
3638
* @summary Test that when an object is allocated outside a TLAB an event will be triggered.
3739
* @key jfr
3840
* @requires vm.hasJFR
3941
* @library /test/lib
40-
* @run main/othervm -XX:+UseTLAB -XX:TLABSize=90k -XX:-ResizeTLAB -XX:TLABRefillWasteFraction=256 jdk.jfr.event.allocation.TestObjectAllocationOutsideTLABEvent
41-
* @run main/othervm -XX:+UseTLAB -XX:TLABSize=90k -XX:-ResizeTLAB -XX:TLABRefillWasteFraction=256 -Xint jdk.jfr.event.allocation.TestObjectAllocationOutsideTLABEvent
42+
* @build sun.hotspot.WhiteBox
43+
*
44+
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
45+
* @run main/othervm -XX:+WhiteBoxAPI -Xbootclasspath/a:.
46+
* -XX:+UseTLAB -XX:TLABSize=90k -XX:-ResizeTLAB -XX:TLABRefillWasteFraction=256
47+
* jdk.jfr.event.allocation.TestObjectAllocationOutsideTLABEvent
48+
* @run main/othervm -XX:+WhiteBoxAPI -Xbootclasspath/a:.
49+
* -XX:+UseTLAB -XX:TLABSize=90k -XX:-ResizeTLAB -XX:TLABRefillWasteFraction=256
50+
* -Xint
51+
* jdk.jfr.event.allocation.TestObjectAllocationOutsideTLABEvent
4252
*/
4353

4454
/**
4555
* Test that an event is triggered when an object is allocated outside a
4656
* Thread Local Allocation Buffer (TLAB). The test is done for default interpreted mode (-Xint).
4757
*
4858
* To force objects to be allocated outside TLAB:
49-
* the size of TLAB is set to 90k (-XX:TLABSize=90k);
50-
* the size of allocated objects is set to 100k.
59+
* the initial size of TLAB is set to 90k (-XX:TLABSize=90k);
60+
* the size of allocated objects is set to 128k;
5161
* max TLAB waste at refill is set to 256 (-XX:TLABRefillWasteFraction=256),
5262
* to prevent a new TLAB creation.
5363
*/
5464
public class TestObjectAllocationOutsideTLABEvent {
5565
private static final String EVENT_NAME = EventNames.ObjectAllocationOutsideTLAB;
5666

57-
private static final int BYTE_ARRAY_OVERHEAD = 16; // Extra bytes used by a byte array
58-
private static final int OBJECT_SIZE = 100 * 1024;
59-
private static final int OBJECT_SIZE_ALT = OBJECT_SIZE + 8; // Object size in case of disabled CompressedOops
67+
private static final Boolean COMPRESSED_CLASS_PTRS = WhiteBox.getWhiteBox().getBooleanVMFlag("UseCompressedClassPointers");
68+
69+
private static final int BYTE_ARRAY_OVERHEAD = (Platform.is64bit() && !COMPRESSED_CLASS_PTRS) ? 24 : 16;
70+
private static final int OBJECT_SIZE = 128 * 1024;
71+
6072
private static final int OBJECTS_TO_ALLOCATE = 100;
6173
private static final String BYTE_ARRAY_CLASS_NAME = new byte[0].getClass().getName();
6274
private static int eventCount;
@@ -94,7 +106,7 @@ private static void verify(RecordedEvent event) {
94106
}
95107
long allocationSize = Events.assertField(event, "allocationSize").atLeast(1L).getValue();
96108
String className = Events.assertField(event, "objectClass.name").notEmpty().getValue();
97-
if (className.equals(BYTE_ARRAY_CLASS_NAME) && (allocationSize == OBJECT_SIZE || allocationSize == OBJECT_SIZE_ALT)) {
109+
if (className.equals(BYTE_ARRAY_CLASS_NAME) && (allocationSize == OBJECT_SIZE)) {
98110
++eventCount;
99111
}
100112
}

test/jdk/jdk/jfr/event/allocation/TestObjectAllocationSampleEventThrottling.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,31 @@
3232
import jdk.test.lib.jfr.EventNames;
3333
import jdk.test.lib.jfr.Events;
3434
import jdk.test.lib.Asserts;
35+
import jdk.test.lib.Platform;
36+
import sun.hotspot.WhiteBox;
3537

3638
/**
3739
* @test
3840
* @summary Test that when an object is allocated outside a TLAB an event will be triggered.
3941
* @key jfr
4042
* @requires vm.hasJFR
4143
* @library /test/lib
42-
* @run main/othervm -XX:+UseTLAB -XX:TLABSize=2k -XX:-ResizeTLAB jdk.jfr.event.allocation.TestObjectAllocationSampleEventThrottling
44+
* @build sun.hotspot.WhiteBox
45+
*
46+
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
47+
* @run main/othervm -XX:+WhiteBoxAPI -Xbootclasspath/a:.
48+
* -XX:+UseTLAB -XX:TLABSize=2k -XX:-ResizeTLAB
49+
* jdk.jfr.event.allocation.TestObjectAllocationSampleEventThrottling
4350
*/
4451

4552
public class TestObjectAllocationSampleEventThrottling {
4653
private static final String EVENT_NAME = EventNames.ObjectAllocationSample;
4754

48-
private static final int BYTE_ARRAY_OVERHEAD = 16; // Extra bytes used by a byte array
49-
private static final int OBJECT_SIZE = 100 * 1024;
50-
private static final int OBJECT_SIZE_ALT = OBJECT_SIZE + 8; // Object size in case of disabled CompressedOops
55+
private static final Boolean COMPRESSED_CLASS_PTRS = WhiteBox.getWhiteBox().getBooleanVMFlag("UseCompressedClassPointers");
56+
57+
private static final int BYTE_ARRAY_OVERHEAD = (Platform.is64bit() && !COMPRESSED_CLASS_PTRS) ? 24 : 16;
58+
private static final int OBJECT_SIZE = 128 * 1024;
59+
5160
private static final int OBJECTS_TO_ALLOCATE = 100;
5261
private static final String BYTE_ARRAY_CLASS_NAME = new byte[0].getClass().getName();
5362
private static int eventCount;

0 commit comments

Comments
 (0)