Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.
/ jdk18u Public archive

Commit

Permalink
8281318: Improve jfr/event/allocation tests reliability
Browse files Browse the repository at this point in the history
Backport-of: 65831eb294b6f1f5f99988836c00005d41c27fd3
  • Loading branch information
shipilev committed Apr 6, 2022
1 parent 8904395 commit b50949a
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,45 @@
import jdk.test.lib.jfr.EventNames;
import jdk.test.lib.jfr.Events;
import jdk.test.lib.Asserts;
import jdk.test.lib.Platform;
import sun.hotspot.WhiteBox;

/**
* @test
* @summary Test that event is triggered when an object is allocated in a new TLAB.
* @key jfr
* @requires vm.hasJFR
* @library /test/lib
* @run main/othervm -XX:+UseTLAB -XX:TLABSize=100k -XX:-ResizeTLAB -XX:TLABRefillWasteFraction=1 jdk.jfr.event.allocation.TestObjectAllocationInNewTLABEvent
* @run main/othervm -XX:+UseTLAB -XX:TLABSize=100k -XX:-ResizeTLAB -XX:TLABRefillWasteFraction=1 -Xint jdk.jfr.event.allocation.TestObjectAllocationInNewTLABEvent
* @build sun.hotspot.WhiteBox
*
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
* @run main/othervm -XX:+WhiteBoxAPI -Xbootclasspath/a:.
* -XX:+UseTLAB -XX:TLABSize=100k -XX:-ResizeTLAB -XX:TLABRefillWasteFraction=1
* jdk.jfr.event.allocation.TestObjectAllocationInNewTLABEvent
* @run main/othervm -XX:+WhiteBoxAPI -Xbootclasspath/a:.
* -XX:+UseTLAB -XX:TLABSize=100k -XX:-ResizeTLAB -XX:TLABRefillWasteFraction=1
* -Xint
* jdk.jfr.event.allocation.TestObjectAllocationInNewTLABEvent
*/

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

private static final int BYTE_ARRAY_OVERHEAD = 16; // Extra bytes used by a byte array.
private static final int OBJECT_SIZE = 100 * 1024;
private static final int OBJECT_SIZE_ALT = OBJECT_SIZE + 8; // Object size in case of disabled CompressedOops.
private static final Boolean COMPRESSED_CLASS_PTRS = WhiteBox.getWhiteBox().getBooleanVMFlag("UseCompressedClassPointers");

private static final int BYTE_ARRAY_OVERHEAD = (Platform.is64bit() && !COMPRESSED_CLASS_PTRS) ? 24 : 16;
private static final int OBJECT_SIZE = 128 * 1024;

private static final int OBJECTS_TO_ALLOCATE = 100;
private static final String BYTE_ARRAY_CLASS_NAME = new byte[0].getClass().getName();
private static final int INITIAL_TLAB_SIZE = 100 * 1024;
Expand Down Expand Up @@ -112,9 +124,9 @@ private static void verify(RecordedEvent event) {
long allocationSize = Events.assertField(event, "allocationSize").atLeast(1L).getValue();
long tlabSize = Events.assertField(event, "tlabSize").atLeast(allocationSize).getValue();
String className = Events.assertField(event, "objectClass.name").notEmpty().getValue();
if (className.equals(BYTE_ARRAY_CLASS_NAME) && (allocationSize == OBJECT_SIZE || allocationSize == OBJECT_SIZE_ALT)) {
if (className.equals(BYTE_ARRAY_CLASS_NAME) && (allocationSize == OBJECT_SIZE)) {
countAllTlabs++;
if (tlabSize == INITIAL_TLAB_SIZE + OBJECT_SIZE || tlabSize == INITIAL_TLAB_SIZE + OBJECT_SIZE_ALT) {
if (tlabSize == INITIAL_TLAB_SIZE + OBJECT_SIZE) {
countFullTlabs++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,45 @@
import jdk.test.lib.jfr.EventNames;
import jdk.test.lib.jfr.Events;
import jdk.test.lib.Asserts;
import jdk.test.lib.Platform;
import sun.hotspot.WhiteBox;

/**
* @test
* @summary Test that when an object is allocated outside a TLAB an event will be triggered.
* @key jfr
* @requires vm.hasJFR
* @library /test/lib
* @run main/othervm -XX:+UseTLAB -XX:TLABSize=90k -XX:-ResizeTLAB -XX:TLABRefillWasteFraction=256 jdk.jfr.event.allocation.TestObjectAllocationOutsideTLABEvent
* @run main/othervm -XX:+UseTLAB -XX:TLABSize=90k -XX:-ResizeTLAB -XX:TLABRefillWasteFraction=256 -Xint jdk.jfr.event.allocation.TestObjectAllocationOutsideTLABEvent
* @build sun.hotspot.WhiteBox
*
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
* @run main/othervm -XX:+WhiteBoxAPI -Xbootclasspath/a:.
* -XX:+UseTLAB -XX:TLABSize=90k -XX:-ResizeTLAB -XX:TLABRefillWasteFraction=256
* jdk.jfr.event.allocation.TestObjectAllocationOutsideTLABEvent
* @run main/othervm -XX:+WhiteBoxAPI -Xbootclasspath/a:.
* -XX:+UseTLAB -XX:TLABSize=90k -XX:-ResizeTLAB -XX:TLABRefillWasteFraction=256
* -Xint
* jdk.jfr.event.allocation.TestObjectAllocationOutsideTLABEvent
*/

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

private static final int BYTE_ARRAY_OVERHEAD = 16; // Extra bytes used by a byte array
private static final int OBJECT_SIZE = 100 * 1024;
private static final int OBJECT_SIZE_ALT = OBJECT_SIZE + 8; // Object size in case of disabled CompressedOops
private static final Boolean COMPRESSED_CLASS_PTRS = WhiteBox.getWhiteBox().getBooleanVMFlag("UseCompressedClassPointers");

private static final int BYTE_ARRAY_OVERHEAD = (Platform.is64bit() && !COMPRESSED_CLASS_PTRS) ? 24 : 16;
private static final int OBJECT_SIZE = 128 * 1024;

private static final int OBJECTS_TO_ALLOCATE = 100;
private static final String BYTE_ARRAY_CLASS_NAME = new byte[0].getClass().getName();
private static int eventCount;
Expand Down Expand Up @@ -94,7 +106,7 @@ private static void verify(RecordedEvent event) {
}
long allocationSize = Events.assertField(event, "allocationSize").atLeast(1L).getValue();
String className = Events.assertField(event, "objectClass.name").notEmpty().getValue();
if (className.equals(BYTE_ARRAY_CLASS_NAME) && (allocationSize == OBJECT_SIZE || allocationSize == OBJECT_SIZE_ALT)) {
if (className.equals(BYTE_ARRAY_CLASS_NAME) && (allocationSize == OBJECT_SIZE)) {
++eventCount;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,31 @@
import jdk.test.lib.jfr.EventNames;
import jdk.test.lib.jfr.Events;
import jdk.test.lib.Asserts;
import jdk.test.lib.Platform;
import sun.hotspot.WhiteBox;

/**
* @test
* @summary Test that when an object is allocated outside a TLAB an event will be triggered.
* @key jfr
* @requires vm.hasJFR
* @library /test/lib
* @run main/othervm -XX:+UseTLAB -XX:TLABSize=2k -XX:-ResizeTLAB jdk.jfr.event.allocation.TestObjectAllocationSampleEventThrottling
* @build sun.hotspot.WhiteBox
*
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
* @run main/othervm -XX:+WhiteBoxAPI -Xbootclasspath/a:.
* -XX:+UseTLAB -XX:TLABSize=2k -XX:-ResizeTLAB
* jdk.jfr.event.allocation.TestObjectAllocationSampleEventThrottling
*/

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

private static final int BYTE_ARRAY_OVERHEAD = 16; // Extra bytes used by a byte array
private static final int OBJECT_SIZE = 100 * 1024;
private static final int OBJECT_SIZE_ALT = OBJECT_SIZE + 8; // Object size in case of disabled CompressedOops
private static final Boolean COMPRESSED_CLASS_PTRS = WhiteBox.getWhiteBox().getBooleanVMFlag("UseCompressedClassPointers");

private static final int BYTE_ARRAY_OVERHEAD = (Platform.is64bit() && !COMPRESSED_CLASS_PTRS) ? 24 : 16;
private static final int OBJECT_SIZE = 128 * 1024;

private static final int OBJECTS_TO_ALLOCATE = 100;
private static final String BYTE_ARRAY_CLASS_NAME = new byte[0].getClass().getName();
private static int eventCount;
Expand Down

1 comment on commit b50949a

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.