1 /* 2 * Copyright (c) 2014, 2016, 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 25 /* 26 * @test OverloadCompileQueueTest 27 * @summary stressing code cache by overloading compile queues 28 * @library /test/lib / 29 * @modules java.base/jdk.internal.misc 30 * java.management 31 * 32 * @ignore 8071905 33 * @build sun.hotspot.WhiteBox 34 * @run driver ClassFileInstaller sun.hotspot.WhiteBox 35 * sun.hotspot.WhiteBox$WhiteBoxPermission 36 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 37 * -XX:+WhiteBoxAPI 38 * -XX:CompileCommand=dontinline,compiler.codecache.stress.Helper$TestCase::method 39 * -XX:-SegmentedCodeCache 40 * compiler.codecache.stress.OverloadCompileQueueTest 41 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 42 * -XX:+WhiteBoxAPI 43 * -XX:CompileCommand=dontinline,compiler.codecache.stress.Helper$TestCase::method 44 * -XX:+SegmentedCodeCache 45 * compiler.codecache.stress.OverloadCompileQueueTest 46 */ 47 48 package compiler.codecache.stress; 49 50 import jdk.test.lib.Platform; 51 52 import java.lang.reflect.Method; 53 import java.util.stream.IntStream; 54 55 public class OverloadCompileQueueTest implements Runnable { 56 private static final int MAX_SLEEP = 10000; 57 private static final String METHOD_TO_ENQUEUE = "method"; 58 private static final int LEVEL_SIMPLE = 1; 59 private static final int LEVEL_FULL_OPTIMIZATION = 4; 60 private static final boolean TIERED_COMPILATION 61 = Helper.WHITE_BOX.getBooleanVMFlag("TieredCompilation"); 62 private static final int TIERED_STOP_AT_LEVEL 63 = Helper.WHITE_BOX.getIntxVMFlag("TieredStopAtLevel").intValue(); 64 private static final int[] AVAILABLE_LEVELS; 65 static { 66 if (TIERED_COMPILATION) { 67 AVAILABLE_LEVELS = IntStream 68 .rangeClosed(LEVEL_SIMPLE, TIERED_STOP_AT_LEVEL) 69 .toArray(); 70 } else if (Platform.isServer()) { 71 AVAILABLE_LEVELS = new int[] { LEVEL_FULL_OPTIMIZATION }; 72 } else if (Platform.isClient() || Platform.isMinimal()) { 73 AVAILABLE_LEVELS = new int[] { LEVEL_SIMPLE }; 74 } else { 75 throw new Error("TESTBUG: unknown VM: " + Platform.vmName); 76 } 77 } 78 79 public static void main(String[] args) { 80 if (Platform.isInt()) { 81 throw new Error("TESTBUG: test can not be run in interpreter"); 82 } 83 new CodeCacheStressRunner(new OverloadCompileQueueTest()).runTest(); 84 } 85 86 public OverloadCompileQueueTest() { 87 Helper.startInfiniteLoopThread(this::lockUnlock, 100L); 88 } 89 90 @Override 91 public void run() { 92 Helper.TestCase obj = Helper.TestCase.get(); 93 Class clazz = obj.getClass(); 94 Method mEnqueue; 95 try { 96 mEnqueue = clazz.getMethod(METHOD_TO_ENQUEUE); 97 } catch (NoSuchMethodException | SecurityException e) { 98 throw new Error(String.format( 99 "TESTBUG: cannot get method '%s' of class %s", 100 METHOD_TO_ENQUEUE, clazz.getName()), e); 101 } 102 for (int compLevel : AVAILABLE_LEVELS) { 103 Helper.WHITE_BOX.enqueueMethodForCompilation(mEnqueue, compLevel); 104 } 105 } 106 107 private void lockUnlock() { 108 try { 109 int sleep = Helper.RNG.nextInt(MAX_SLEEP); 110 Helper.WHITE_BOX.lockCompilation(); 111 Thread.sleep(sleep); 112 } catch (InterruptedException e) { 113 throw new Error("TESTBUG: lockUnlocker thread was unexpectedly interrupted", e); 114 } finally { 115 Helper.WHITE_BOX.unlockCompilation(); 116 } 117 } 118 119 }