OverloadCompileQueueTest.java revision 11715:ffb2960cd05d
1251881Speter/*
2251881Speter * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
3251881Speter * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4251881Speter *
5251881Speter * This code is free software; you can redistribute it and/or modify it
6251881Speter * under the terms of the GNU General Public License version 2 only, as
7251881Speter * published by the Free Software Foundation.
8251881Speter *
9251881Speter * This code is distributed in the hope that it will be useful, but WITHOUT
10251881Speter * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11251881Speter * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12251881Speter * version 2 for more details (a copy is included in the LICENSE file that
13251881Speter * accompanied this code).
14251881Speter *
15251881Speter * You should have received a copy of the GNU General Public License version
16251881Speter * 2 along with this work; if not, write to the Free Software Foundation,
17251881Speter * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18251881Speter *
19251881Speter * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20251881Speter * or visit www.oracle.com if you need additional information or have any
21251881Speter * questions.
22251881Speter *
23251881Speter */
24251881Speter
25251881Speter/*
26251881Speter * @test OverloadCompileQueueTest
27251881Speter * @summary stressing code cache by overloading compile queues
28251881Speter * @library /testlibrary /test/lib /
29251881Speter * @modules java.base/jdk.internal.misc
30251881Speter *          java.management
31251881Speter *
32251881Speter * @ignore 8071905
33251881Speter * @build compiler.codecache.stress.OverloadCompileQueueTest
34251881Speter * @run driver ClassFileInstaller sun.hotspot.WhiteBox
35251881Speter *                                sun.hotspot.WhiteBox$WhiteBoxPermission
36251881Speter * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
37251881Speter *                   -XX:+WhiteBoxAPI
38251881Speter *                   -XX:CompileCommand=dontinline,compiler.codecache.stress.Helper$TestCase::method
39251881Speter *                   -XX:-SegmentedCodeCache
40251881Speter *                   compiler.codecache.stress.OverloadCompileQueueTest
41251881Speter * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
42251881Speter *                   -XX:+WhiteBoxAPI
43251881Speter *                   -XX:CompileCommand=dontinline,compiler.codecache.stress.Helper$TestCase::method
44251881Speter *                   -XX:+SegmentedCodeCache
45251881Speter *                   compiler.codecache.stress.OverloadCompileQueueTest
46251881Speter */
47251881Speter
48251881Speterpackage compiler.codecache.stress;
49251881Speter
50251881Speterimport jdk.test.lib.Platform;
51251881Speter
52251881Speterimport java.lang.reflect.Method;
53251881Speterimport java.util.stream.IntStream;
54251881Speter
55251881Speterpublic class OverloadCompileQueueTest implements Runnable {
56251881Speter    private static final int MAX_SLEEP = 10000;
57251881Speter    private static final String METHOD_TO_ENQUEUE = "method";
58251881Speter    private static final int LEVEL_SIMPLE = 1;
59251881Speter    private static final int LEVEL_FULL_OPTIMIZATION = 4;
60251881Speter    private static final boolean TIERED_COMPILATION
61251881Speter            = Helper.WHITE_BOX.getBooleanVMFlag("TieredCompilation");
62251881Speter    private static final int TIERED_STOP_AT_LEVEL
63251881Speter            = Helper.WHITE_BOX.getIntxVMFlag("TieredStopAtLevel").intValue();
64251881Speter    private static final int[] AVAILABLE_LEVELS;
65251881Speter    static {
66251881Speter        if (TIERED_COMPILATION) {
67251881Speter            AVAILABLE_LEVELS = IntStream
68251881Speter                    .rangeClosed(LEVEL_SIMPLE, TIERED_STOP_AT_LEVEL)
69251881Speter                    .toArray();
70251881Speter        } else if (Platform.isServer()) {
71251881Speter            AVAILABLE_LEVELS = new int[] { LEVEL_FULL_OPTIMIZATION };
72251881Speter        } else if (Platform.isClient() || Platform.isMinimal()) {
73251881Speter            AVAILABLE_LEVELS = new int[] { LEVEL_SIMPLE };
74251881Speter        } else {
75251881Speter            throw new Error("TESTBUG: unknown VM: " + Platform.vmName);
76251881Speter        }
77251881Speter    }
78251881Speter
79251881Speter    public static void main(String[] args) {
80251881Speter        if (Platform.isInt()) {
81251881Speter            throw new Error("TESTBUG: test can not be run in interpreter");
82251881Speter        }
83251881Speter        new CodeCacheStressRunner(new OverloadCompileQueueTest()).runTest();
84251881Speter    }
85251881Speter
86251881Speter    public OverloadCompileQueueTest() {
87251881Speter        Helper.startInfiniteLoopThread(this::lockUnlock, 100L);
88251881Speter    }
89251881Speter
90251881Speter    @Override
91251881Speter    public void run() {
92251881Speter        Helper.TestCase obj = Helper.TestCase.get();
93251881Speter        Class clazz = obj.getClass();
94251881Speter        Method mEnqueue;
95251881Speter        try {
96251881Speter            mEnqueue = clazz.getMethod(METHOD_TO_ENQUEUE);
97251881Speter        } catch (NoSuchMethodException | SecurityException e) {
98251881Speter            throw new Error(String.format(
99251881Speter                    "TESTBUG: cannot get method '%s' of class %s",
100251881Speter                    METHOD_TO_ENQUEUE, clazz.getName()), e);
101251881Speter        }
102251881Speter        for (int compLevel : AVAILABLE_LEVELS) {
103251881Speter            Helper.WHITE_BOX.enqueueMethodForCompilation(mEnqueue, compLevel);
104251881Speter        }
105251881Speter    }
106251881Speter
107251881Speter    private void lockUnlock() {
108251881Speter        try {
109251881Speter            int sleep = Helper.RNG.nextInt(MAX_SLEEP);
110251881Speter            Helper.WHITE_BOX.lockCompilation();
111251881Speter            Thread.sleep(sleep);
112251881Speter        } catch (InterruptedException e) {
113251881Speter            throw new Error("TESTBUG: lockUnlocker thread was unexpectedly interrupted", e);
114251881Speter        } finally {
115251881Speter            Helper.WHITE_BOX.unlockCompilation();
116251881Speter        }
117251881Speter    }
118251881Speter
119251881Speter}
120251881Speter