Path: blob/master/test/hotspot/jtreg/gc/g1/TestPeriodicCollectionJNI.java
40942 views
/*1* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package gc.g1;2425/* @test26* @bug 821888027* @summary Test that issuing a periodic collection while the GC locker is28* held does not crash the VM.29* @requires vm.gc.G130* @run main/othervm/native31* -Xbootclasspath/a:.32* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI33* -XX:+UseG1GC -XX:G1PeriodicGCInterval=10034* -XX:+G1PeriodicGCInvokesConcurrent35* -Xlog:gc*,gc+periodic=debug36* gc.g1.TestPeriodicCollectionJNI37* @run main/othervm/native38* -Xbootclasspath/a:.39* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI40* -XX:+UseG1GC -XX:G1PeriodicGCInterval=10041* -XX:-G1PeriodicGCInvokesConcurrent42* -Xlog:gc*,gc+periodic=debug43* gc.g1.TestPeriodicCollectionJNI44*/4546public class TestPeriodicCollectionJNI {47static { System.loadLibrary("TestPeriodicCollectionJNI"); }4849private static native boolean blockInNative(byte[] array);50private static native void unblock();5152public static void block() {53if (!blockInNative(new byte[0])) {54throw new RuntimeException("failed to acquire lock to dummy object");55}56}5758public static void main(String[] args) throws InterruptedException {59long timeout = 2000;60long startTime = System.currentTimeMillis();6162// Start thread doing JNI call63BlockInNative blocker = new BlockInNative();64blocker.start();6566try {67// Wait for periodic GC timeout to trigger68while (System.currentTimeMillis() < startTime + timeout) {69System.out.println("Sleeping to let periodic GC trigger...");70Thread.sleep(200);71}72} finally {73unblock();74}75}76}7778class BlockInNative extends Thread {7980public void run() {81TestPeriodicCollectionJNI.block();82}8384native void unlock();85}868788