Skip to content

Commit aea5090

Browse files
Fix transient failure in TestObjectAllocationOutsideTLABEvent.
1 parent 4f61e16 commit aea5090

File tree

3 files changed

+31
-24
lines changed

3 files changed

+31
-24
lines changed

substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/TlabSupport.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -409,10 +409,10 @@ public static void resize(IsolateThread thread) {
409409

410410
if (SerialAndEpsilonGCOptions.PrintTLAB.getValue()) {
411411
Log.log().string("TLAB new size: thread ").zhex(thread)
412-
.string(" target refills: ").unsigned(targetRefills)
413-
.string(" alloc avg.: ").unsigned(allocatedAvg)
414-
.string(" desired size: ").hex(desiredSize.get(thread))
415-
.string(" -> ").hex(alignedNewSize).newline();
412+
.string(", target refills: ").unsigned(targetRefills)
413+
.string(", alloc avg.: ").unsigned(allocatedAvg)
414+
.string(", desired size: ").unsigned(desiredSize.get(thread))
415+
.string(" -> ").unsigned(alignedNewSize).newline();
416416
}
417417

418418
desiredSize.set(thread, alignedNewSize);
@@ -498,13 +498,13 @@ private static void printStats(IsolateThread thread, UnsignedWord allocatedBytes
498498

499499
long waste = gcWaste.get(thread) + refillWaste.get(thread);
500500
Log.log().string("TLAB: thread: ").zhex(thread)
501-
.string(" slow allocs: ").unsigned(slowAllocations.get(thread))
502-
.string(" refills: ").unsigned(numberOfRefills.get(thread))
503-
.string(" alloc bytes: ").unsigned(allocatedBytesSinceLastGC)
504-
.string(" alloc avg.: ").unsigned((long) allocatedBytesAvg.getAddress(thread).getAverage())
505-
.string(" waste bytes: ").zhex(waste)
506-
.string(" GC waste: ").unsigned(gcWaste.get(thread))
507-
.string(" refill waste: ").unsigned(refillWaste.get(thread)).newline();
501+
.string(", slow allocs: ").unsigned(slowAllocations.get(thread))
502+
.string(", refills: ").unsigned(numberOfRefills.get(thread))
503+
.string(", alloc bytes: ").unsigned(allocatedBytesSinceLastGC)
504+
.string(", alloc avg.: ").unsigned((long) allocatedBytesAvg.getAddress(thread).getAverage())
505+
.string(", waste bytes: ").unsigned(waste)
506+
.string(", GC waste: ").unsigned(gcWaste.get(thread))
507+
.string(", refill waste: ").unsigned(refillWaste.get(thread)).newline();
508508
}
509509

510510
static void logTlabChunks(Log log, IsolateThread thread, String shortSpaceName) {

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/events/JfrAllocationEvents.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ public static void reset() {
5959
@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
6060
public static void emit(long startTicks, DynamicHub hub, UnsignedWord allocationSize, UnsignedWord tlabSize, boolean allocatedOutsideTlab) {
6161
if (HasJfrSupport.get()) {
62-
6362
if (allocatedOutsideTlab) {
6463
emitObjectAllocationOutsideTLAB(startTicks, hub, allocationSize);
6564
} else if (tlabSize.notEqual(0)) {

substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestObjectAllocationOutsideTLABEvent.java

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,27 +56,28 @@ public void test() throws Throwable {
5656
String[] events = new String[]{JfrEvent.ObjectAllocationOutsideTLAB.getName()};
5757
Recording recording = startRecording(events);
5858

59+
/* Do a GC before the allocations to avoid that the GC interferes with the test. */
60+
System.gc();
61+
5962
/*
6063
* Use a separate thread for allocating the objects, to have better control over the TLAB
6164
* and to make sure the objects are actually allocated outside the TLAB.
6265
*/
6366
Thread testThread = new Thread(() -> {
64-
final long largeObjectThreshold = SerialAndEpsilonGCOptions.LargeArrayThreshold.getValue();
65-
final int arraySize = NumUtil.safeToInt(largeObjectThreshold - 1024);
67+
int arrayDataSize = arrayDataSizeForOutOfTLABAllocation();
6668

67-
// Allocate a small object to make sure we have a TLAB.
68-
Object o = new Object();
69-
GraalDirectives.blackhole(o);
69+
/* Allocate a small object to make sure we have a TLAB. */
70+
GraalDirectives.blackhole(new Object());
7071

71-
allocateByteArray(arraySize / Byte.BYTES);
72-
allocateCharArray(arraySize / Character.BYTES);
72+
/* Allocate large arrays that don't fit into the TLAB. */
73+
GraalDirectives.blackhole(allocateByteArray(arrayDataSize / Byte.BYTES));
74+
GraalDirectives.blackhole(allocateCharArray(arrayDataSize / Character.BYTES));
7375
}, TEST_THREAD_NAME);
7476

7577
testThread.start();
7678
testThread.join();
7779

7880
stopRecording(recording, TestObjectAllocationOutsideTLABEvent::validateEvents);
79-
8081
}
8182

8283
@NeverInline("Prevent escape analysis.")
@@ -89,9 +90,17 @@ private static char[] allocateCharArray(int length) {
8990
return new char[length];
9091
}
9192

93+
/**
94+
* Returns the required array data size in bytes such that an array is too large to be allocated
95+
* in the TLAB, yet still small enough to fit within an aligned heap chunk.
96+
*/
97+
private static int arrayDataSizeForOutOfTLABAllocation() {
98+
long largeObjectThreshold = SerialAndEpsilonGCOptions.LargeArrayThreshold.getValue();
99+
return NumUtil.safeToInt(largeObjectThreshold - 512);
100+
}
101+
92102
private static void validateEvents(List<RecordedEvent> events) {
93-
final long largeObjectThreshold = SerialAndEpsilonGCOptions.LargeArrayThreshold.getValue();
94-
final int arrayLength = NumUtil.safeToInt(largeObjectThreshold - 1024);
103+
int arrayDataSize = arrayDataSizeForOutOfTLABAllocation();
95104

96105
boolean foundByteArray = false;
97106
boolean foundCharArray = false;
@@ -105,7 +114,7 @@ private static void validateEvents(List<RecordedEvent> events) {
105114
long allocationSize = event.<Long> getValue("allocationSize");
106115
String className = event.<RecordedClass> getValue("objectClass").getName();
107116

108-
if (allocationSize >= arrayLength) {
117+
if (allocationSize >= arrayDataSize) {
109118
if (className.equals(char[].class.getName())) {
110119
foundCharArray = true;
111120
} else if (className.equals(byte[].class.getName())) {
@@ -119,5 +128,4 @@ private static void validateEvents(List<RecordedEvent> events) {
119128
assertTrue(foundByteArray);
120129
assertTrue(foundCharArray);
121130
}
122-
123131
}

0 commit comments

Comments
 (0)