Path: blob/master/test/hotspot/jtreg/compiler/codecache/stress/OverloadCompileQueueTest.java
41153 views
/*1* Copyright (c) 2014, 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*/2223/*24* @test OverloadCompileQueueTest25* @key stress randomness26* @summary stressing code cache by overloading compile queues27* @library /test/lib /28* @modules java.base/jdk.internal.misc29* java.management30*31* @build sun.hotspot.WhiteBox32* compiler.codecache.stress.TestCaseImpl33* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox34* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions35* -XX:+WhiteBoxAPI36* -XX:CompileCommand=dontinline,compiler.codecache.stress.Helper$TestCase::method37* -XX:-SegmentedCodeCache38* compiler.codecache.stress.OverloadCompileQueueTest39* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions40* -XX:+WhiteBoxAPI41* -XX:CompileCommand=dontinline,compiler.codecache.stress.Helper$TestCase::method42* -XX:+SegmentedCodeCache43* compiler.codecache.stress.OverloadCompileQueueTest44*/4546package compiler.codecache.stress;4748import jdk.test.lib.Platform;49import jdk.test.lib.Utils;5051import java.lang.reflect.Method;52import java.util.stream.IntStream;53import java.util.Random;5455class LockUnlockThread extends Thread {56private static final int MAX_SLEEP = 10000;57private static final int DELAY_BETWEEN_LOCKS = 100;58private final Random rng = Utils.getRandomInstance();5960public volatile boolean isActive = true;6162@Override63public void run() {64try {65while (isActive) {66int timeInLockedState = rng.nextInt(MAX_SLEEP);67Helper.WHITE_BOX.lockCompilation();68Thread.sleep(timeInLockedState);69Helper.WHITE_BOX.unlockCompilation();70Thread.sleep(DELAY_BETWEEN_LOCKS);71}72} catch (InterruptedException e) {73if (isActive) {74throw new Error("TESTBUG: LockUnlockThread was unexpectedly interrupted", e);75}76} finally {77Helper.WHITE_BOX.unlockCompilation();78}79}80}8182public class OverloadCompileQueueTest implements Runnable {83private static final String METHOD_TO_ENQUEUE = "method";84private static final int LEVEL_SIMPLE = 1;85private static final int LEVEL_FULL_OPTIMIZATION = 4;86private static final boolean TIERED_COMPILATION87= Helper.WHITE_BOX.getBooleanVMFlag("TieredCompilation");88private static final int TIERED_STOP_AT_LEVEL89= Helper.WHITE_BOX.getIntxVMFlag("TieredStopAtLevel").intValue();90private static final int[] AVAILABLE_LEVELS;91static {92if (TIERED_COMPILATION) {93AVAILABLE_LEVELS = IntStream94.rangeClosed(LEVEL_SIMPLE, TIERED_STOP_AT_LEVEL)95.toArray();96} else if (Platform.isServer() && !Platform.isEmulatedClient()) {97AVAILABLE_LEVELS = new int[] { LEVEL_FULL_OPTIMIZATION };98} else if (Platform.isClient() || Platform.isMinimal() || Platform.isEmulatedClient()) {99AVAILABLE_LEVELS = new int[] { LEVEL_SIMPLE };100} else {101throw new Error("TESTBUG: unknown VM: " + Platform.vmName);102}103}104105public static void main(String[] args) throws InterruptedException {106LockUnlockThread lockUnlockThread = new LockUnlockThread();107lockUnlockThread.start();108109if (Platform.isInt()) {110throw new Error("TESTBUG: test can not be run in interpreter");111}112new CodeCacheStressRunner(new OverloadCompileQueueTest()).runTest();113114lockUnlockThread.isActive = false;115lockUnlockThread.interrupt();116lockUnlockThread.join();117}118119@Override120public void run() {121Helper.TestCase obj = Helper.TestCase.get();122Class clazz = obj.getClass();123Method mEnqueue;124try {125mEnqueue = clazz.getMethod(METHOD_TO_ENQUEUE);126} catch (NoSuchMethodException | SecurityException e) {127throw new Error(String.format(128"TESTBUG: cannot get method '%s' of class %s",129METHOD_TO_ENQUEUE, clazz.getName()), e);130}131for (int compLevel : AVAILABLE_LEVELS) {132Helper.WHITE_BOX.enqueueMethodForCompilation(mEnqueue, compLevel);133}134}135136}137138139