< prev index next >

test/jdk/java/util/concurrent/locks/Lock/OOMEInAQS.java

Print this page

  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.Condition;
 32 import java.util.concurrent.locks.ReentrantLock;
 33 import java.util.function.Consumer;
 34 import java.util.stream.IntStream;
 35 import java.util.stream.Stream;
 36 
 37 /**
 38  * @test
 39  * @bug 8066859
 40  * @summary Check that AQS-based locks, conditions, and CountDownLatches do not fail when encountering OOME
 41  * @requires vm.gc.G1
 42  * @requires test.thread.factory == null
 43  * @requires !(vm.graal.enabled & vm.compMode == "Xcomp")
 44  * @run main/othervm -XX:+UseG1GC -XX:-UseGCOverheadLimit -Xmx48M -XX:-UseTLAB OOMEInAQS
 45  */
 46 
 47 public class OOMEInAQS extends Thread {
 48     static final int NTHREADS = 2; // intentionally not a scalable test; > 2 is very slow
 49     static final int NREPS = 100;
 50     // statically allocate
 51     static final ReentrantLock mainLock = new ReentrantLock();
 52     static final Condition condition = mainLock.newCondition();
 53     static final CountDownLatch started = new CountDownLatch(1);
 54     static final CountDownLatch filled = new CountDownLatch(1);
 55     static final CountDownLatch canFill = new CountDownLatch(NTHREADS);
 56     static volatile Object data;
 57     static volatile Throwable exception;
 58     static int turn;
 59 
 60     /**
 61      * For each of NTHREADS threads, REPS times: Take turns
 62      * executing. Introduce OOM using fillHeap during runs. In
 63      * addition to testing AQS, the CountDownLatches ensure that

  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.Condition;
 32 import java.util.concurrent.locks.ReentrantLock;
 33 import java.util.function.Consumer;
 34 import java.util.stream.IntStream;
 35 import java.util.stream.Stream;
 36 
 37 /**
 38  * @test
 39  * @bug 8066859
 40  * @summary Check that AQS-based locks, conditions, and CountDownLatches do not fail when encountering OOME
 41  * @requires vm.gc.G1
 42  * @requires test.thread.factory == null

 43  * @run main/othervm -XX:+UseG1GC -XX:-UseGCOverheadLimit -Xmx48M -XX:-UseTLAB OOMEInAQS
 44  */
 45 
 46 public class OOMEInAQS extends Thread {
 47     static final int NTHREADS = 2; // intentionally not a scalable test; > 2 is very slow
 48     static final int NREPS = 100;
 49     // statically allocate
 50     static final ReentrantLock mainLock = new ReentrantLock();
 51     static final Condition condition = mainLock.newCondition();
 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
 62      * addition to testing AQS, the CountDownLatches ensure that
< prev index next >