Skip to content

Commit

Permalink
Added garbage producer thread to test to stress GC
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiHartmann committed Nov 14, 2024
1 parent 3bda1c3 commit af869ef
Showing 1 changed file with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@
/*
* TODO LIST
* - Run with combinations of -XX:-TieredCompilation -XX:+PreserveFramePointer -XX:-UseOnStackReplacement -XX:+DeoptimizeALot -XX:+StressCallingConvention -XX:-InlineTypePassFieldsAsArgs -XX:-InlineTypeReturnedAsFields
* - Add methods invoked via virtual calls exercise the different entry point
* - Add a stress mode where another thread does some allocations and System.gc() in parallel to trigger GCs while threads are parked
* - Add methods invoked via virtual calls to exercise the different entry point
*/

import java.lang.reflect.Method;
Expand Down Expand Up @@ -481,6 +480,19 @@ public static DoubleValue testDoubleValueHelper(double d, boolean useNull, boole
return val1;
}

static class GarbageProducerThread extends Thread {
public void run() {
for (;;) {
// Produce some garbage and then let the GC do its work
Object[] arrays = new Object[1024];
for (int i = 0; i < arrays.length; i++) {
arrays[i] = new int[1024];
}
System.gc();
}
}
}

public static void main(String[] args) throws Exception {
// Sometimes, exclude some methods from compilation with C1 and/or C2 to stress test the calling convention
if (Utils.getRandomInstance().nextBoolean()) {
Expand All @@ -507,6 +519,12 @@ public static void main(String[] args) throws Exception {
}
}

// Start another thread that does some allocations and calls System.gc()
// to trigger GCs while virtual threads are parked.
Thread garbage_producer = new GarbageProducerThread();
garbage_producer.setDaemon(true);
garbage_producer.start();

CountDownLatch cdl = new CountDownLatch(1);
Thread.ofVirtual().start(() -> {
try {
Expand Down

0 comments on commit af869ef

Please sign in to comment.