1 /*
2 * Copyright (c) 2013, 2025, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 import java.util.concurrent.TimeUnit;
25 import java.util.concurrent.Phaser;
26 import java.util.concurrent.CountDownLatch;
27 import java.util.concurrent.atomic.AtomicInteger;
28 import java.util.concurrent.atomic.AtomicReference;
29 import java.util.concurrent.locks.Condition;
30 import java.util.concurrent.locks.Lock;
31 import java.util.concurrent.locks.StampedLock;
32 import java.util.function.Consumer;
33 import java.util.stream.IntStream;
34 import java.util.stream.Stream;
35
36 /**
37 * @test
38 * @bug 8066859
39 * @summary An adaptation of OOMEInAQS test for StampedLocks
40 * @requires vm.gc.G1
41 * @requires !(vm.graal.enabled & vm.compMode == "Xcomp")
42 * @run main/othervm -XX:+UseG1GC -XX:-UseGCOverheadLimit -Xmx48M -XX:-UseTLAB OOMEInStampedLock
43 */
44
45 public class OOMEInStampedLock extends Thread {
46 static final int NTHREADS = 3;
47 static final int NREPS = 100;
48 // statically allocate
49 static final StampedLock stampedLock = new StampedLock();
50 static final Lock wLock = stampedLock.asWriteLock();
51 static final Lock rLock = stampedLock.asReadLock();
52 static final CountDownLatch started = new CountDownLatch(1);
53 static final CountDownLatch filled = new CountDownLatch(1);
54 static final CountDownLatch canFill = new CountDownLatch(NTHREADS);
55 static volatile Object data;
56 static volatile Throwable exception;
57 static int turn;
58
59 /**
60 * For each of NTHREADS threads, REPS times: Take turns
61 * executing. Introduce OOM using fillHeap during runs. In
|
1 /*
2 * Copyright (c) 2013, 2026, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 import java.util.concurrent.TimeUnit;
25 import java.util.concurrent.Phaser;
26 import java.util.concurrent.CountDownLatch;
27 import java.util.concurrent.atomic.AtomicInteger;
28 import java.util.concurrent.atomic.AtomicReference;
29 import java.util.concurrent.locks.Condition;
30 import java.util.concurrent.locks.Lock;
31 import java.util.concurrent.locks.StampedLock;
32 import java.util.function.Consumer;
33 import java.util.stream.IntStream;
34 import java.util.stream.Stream;
35
36 /**
37 * @test
38 * @bug 8066859
39 * @summary An adaptation of OOMEInAQS test for StampedLocks
40 * @requires vm.gc.G1
41 * @run main/othervm -XX:+UseG1GC -XX:-UseGCOverheadLimit -Xmx48M -XX:-UseTLAB OOMEInStampedLock
42 */
43
44 public class OOMEInStampedLock extends Thread {
45 static final int NTHREADS = 3;
46 static final int NREPS = 100;
47 // statically allocate
48 static final StampedLock stampedLock = new StampedLock();
49 static final Lock wLock = stampedLock.asWriteLock();
50 static final Lock rLock = stampedLock.asReadLock();
51 static final CountDownLatch started = new CountDownLatch(1);
52 static final CountDownLatch filled = new CountDownLatch(1);
53 static final CountDownLatch canFill = new CountDownLatch(NTHREADS);
54 static volatile Object data;
55 static volatile Throwable exception;
56 static int turn;
57
58 /**
59 * For each of NTHREADS threads, REPS times: Take turns
60 * executing. Introduce OOM using fillHeap during runs. In
|