From a0e10b1691aca250f390704c73b18810b89302e1 Mon Sep 17 00:00:00 2001 From: Sorin Basca Date: Wed, 11 Aug 2021 16:00:13 +0000 Subject: [PATCH] Have counter pre-initialized in ParallelGC test Bug: 94471075 Test: testrunner.py --target --verbose --ndebug --gcstress --optimizing --debuggable -t 114-ParallelGC Change-Id: Id0b3640bc4e21caf187fd886d153e00761b9ba15 --- test/114-ParallelGC/src/Main.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test/114-ParallelGC/src/Main.java b/test/114-ParallelGC/src/Main.java index 2199872ba6..213b07f16c 100644 --- a/test/114-ParallelGC/src/Main.java +++ b/test/114-ParallelGC/src/Main.java @@ -30,10 +30,19 @@ public class Main implements Runnable { private final static int THREAD_COUNT = 16; // Use a couple of different forms of synchronizing to test some of these... - private final static AtomicInteger counter = new AtomicInteger(); + private final static AtomicInteger counter = new AtomicInteger(-1); private final static Object gate = new Object(); private volatile static int waitCount = 0; + static { + // If we're using the interpreter for the boot class path, the VarHandle implementation of + // AtomicInteger.incrementAndGet() needs to resolve a MethodType which is then cached for + // subsequent uses. Make sure the MethodType is resolved early, otherwise the + // counter.incrementAndGet() call in work(), after we have tried to allocate all memory, + // could throw OOME. + counter.incrementAndGet(); + } + public static void main(String[] args) throws Exception { Thread[] threads = new Thread[THREAD_COUNT];