Mon, 18 Mar 2013 04:29:08 -0700
8008211: Some of WB tests on compiler fail
Reviewed-by: kvn, vlivanov
iignatyev@4592 | 1 | /* |
iignatyev@4592 | 2 | * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
iignatyev@4592 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
iignatyev@4592 | 4 | * |
iignatyev@4592 | 5 | * This code is free software; you can redistribute it and/or modify it |
iignatyev@4592 | 6 | * under the terms of the GNU General Public License version 2 only, as |
iignatyev@4592 | 7 | * published by the Free Software Foundation. |
iignatyev@4592 | 8 | * |
iignatyev@4592 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
iignatyev@4592 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
iignatyev@4592 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
iignatyev@4592 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
iignatyev@4592 | 13 | * accompanied this code). |
iignatyev@4592 | 14 | * |
iignatyev@4592 | 15 | * You should have received a copy of the GNU General Public License version |
iignatyev@4592 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
iignatyev@4592 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
iignatyev@4592 | 18 | * |
iignatyev@4592 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
iignatyev@4592 | 20 | * or visit www.oracle.com if you need additional information or have any |
iignatyev@4592 | 21 | * questions. |
iignatyev@4592 | 22 | */ |
iignatyev@4592 | 23 | |
iignatyev@4592 | 24 | import sun.hotspot.WhiteBox; |
iignatyev@4592 | 25 | import sun.management.ManagementFactoryHelper; |
iignatyev@4592 | 26 | import com.sun.management.HotSpotDiagnosticMXBean; |
iignatyev@4592 | 27 | |
iignatyev@4592 | 28 | import java.lang.reflect.Method; |
iignatyev@4592 | 29 | |
iignatyev@4592 | 30 | /* |
iignatyev@4592 | 31 | * @author igor.ignatyev@oracle.com |
iignatyev@4592 | 32 | */ |
iignatyev@4592 | 33 | public abstract class CompilerWhiteBoxTest { |
iignatyev@4592 | 34 | protected static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox(); |
iignatyev@4592 | 35 | protected static final Method METHOD = getMethod("method"); |
iignatyev@4592 | 36 | protected static final int COMPILE_THRESHOLD |
iignatyev@4592 | 37 | = Integer.parseInt(getVMOption("CompileThreshold", "10000")); |
iignatyev@4766 | 38 | protected static final boolean BACKGROUND_COMPILATION |
iignatyev@4766 | 39 | = Boolean.valueOf(getVMOption("BackgroundCompilation", "true")); |
iignatyev@4592 | 40 | |
iignatyev@4592 | 41 | protected static Method getMethod(String name) { |
iignatyev@4592 | 42 | try { |
iignatyev@4592 | 43 | return CompilerWhiteBoxTest.class.getDeclaredMethod(name); |
iignatyev@4592 | 44 | } catch (NoSuchMethodException | SecurityException e) { |
iignatyev@4592 | 45 | throw new RuntimeException( |
iignatyev@4592 | 46 | "exception on getting method " + name, e); |
iignatyev@4592 | 47 | } |
iignatyev@4592 | 48 | } |
iignatyev@4592 | 49 | |
iignatyev@4766 | 50 | protected static String getVMOption(String name) { |
iignatyev@4592 | 51 | String result; |
iignatyev@4592 | 52 | HotSpotDiagnosticMXBean diagnostic |
iignatyev@4592 | 53 | = ManagementFactoryHelper.getDiagnosticMXBean(); |
iignatyev@4592 | 54 | result = diagnostic.getVMOption(name).getValue(); |
iignatyev@4766 | 55 | return result; |
iignatyev@4766 | 56 | } |
iignatyev@4766 | 57 | |
iignatyev@4766 | 58 | protected static String getVMOption(String name, String defaultValue) { |
iignatyev@4766 | 59 | String result = getVMOption(name); |
iignatyev@4592 | 60 | return result == null ? defaultValue : result; |
iignatyev@4592 | 61 | } |
iignatyev@4592 | 62 | |
iignatyev@4592 | 63 | protected final void runTest() throws RuntimeException { |
iignatyev@4592 | 64 | if (ManagementFactoryHelper.getCompilationMXBean() == null) { |
iignatyev@4592 | 65 | System.err.println( |
iignatyev@4592 | 66 | "Warning: test is not applicable in interpreted mode"); |
iignatyev@4592 | 67 | return; |
iignatyev@4592 | 68 | } |
iignatyev@4592 | 69 | System.out.println("at test's start:"); |
iignatyev@4592 | 70 | printInfo(METHOD); |
iignatyev@4592 | 71 | try { |
iignatyev@4592 | 72 | test(); |
iignatyev@4592 | 73 | } catch (Exception e) { |
iignatyev@4592 | 74 | System.out.printf("on exception '%s':", e.getMessage()); |
iignatyev@4592 | 75 | printInfo(METHOD); |
iignatyev@4766 | 76 | e.printStackTrace(); |
iignatyev@4592 | 77 | throw new RuntimeException(e); |
iignatyev@4592 | 78 | } |
iignatyev@4592 | 79 | System.out.println("at test's end:"); |
iignatyev@4592 | 80 | printInfo(METHOD); |
iignatyev@4592 | 81 | } |
iignatyev@4592 | 82 | |
iignatyev@4592 | 83 | protected static void checkNotCompiled(Method method) { |
iignatyev@4592 | 84 | if (WHITE_BOX.isMethodCompiled(method)) { |
iignatyev@4592 | 85 | throw new RuntimeException(method + " must be not compiled"); |
iignatyev@4592 | 86 | } |
iignatyev@4592 | 87 | if (WHITE_BOX.getMethodCompilationLevel(method) != 0) { |
iignatyev@4592 | 88 | throw new RuntimeException(method + " comp_level must be == 0"); |
iignatyev@4592 | 89 | } |
iignatyev@4592 | 90 | } |
iignatyev@4592 | 91 | |
iignatyev@4592 | 92 | protected static void checkCompiled(Method method) |
iignatyev@4592 | 93 | throws InterruptedException { |
iignatyev@4592 | 94 | final long start = System.currentTimeMillis(); |
iignatyev@4592 | 95 | waitBackgroundCompilation(method); |
iignatyev@4592 | 96 | if (WHITE_BOX.isMethodQueuedForCompilation(method)) { |
iignatyev@4592 | 97 | System.err.printf("Warning: %s is still in queue after %dms%n", |
iignatyev@4592 | 98 | method, System.currentTimeMillis() - start); |
iignatyev@4592 | 99 | return; |
iignatyev@4592 | 100 | } |
iignatyev@4592 | 101 | if (!WHITE_BOX.isMethodCompiled(method)) { |
iignatyev@4592 | 102 | throw new RuntimeException(method + " must be compiled"); |
iignatyev@4592 | 103 | } |
iignatyev@4592 | 104 | if (WHITE_BOX.getMethodCompilationLevel(method) == 0) { |
iignatyev@4592 | 105 | throw new RuntimeException(method + " comp_level must be != 0"); |
iignatyev@4592 | 106 | } |
iignatyev@4592 | 107 | } |
iignatyev@4592 | 108 | |
iignatyev@4592 | 109 | protected static void waitBackgroundCompilation(Method method) |
iignatyev@4592 | 110 | throws InterruptedException { |
iignatyev@4766 | 111 | if (!BACKGROUND_COMPILATION) { |
iignatyev@4766 | 112 | return; |
iignatyev@4766 | 113 | } |
iignatyev@4592 | 114 | final Object obj = new Object(); |
iignatyev@4592 | 115 | synchronized (obj) { |
iignatyev@4592 | 116 | for (int i = 0; i < 10; ++i) { |
iignatyev@4592 | 117 | if (!WHITE_BOX.isMethodQueuedForCompilation(method)) { |
iignatyev@4592 | 118 | break; |
iignatyev@4592 | 119 | } |
iignatyev@4592 | 120 | obj.wait(1000); |
iignatyev@4592 | 121 | } |
iignatyev@4592 | 122 | } |
iignatyev@4592 | 123 | } |
iignatyev@4592 | 124 | |
iignatyev@4592 | 125 | protected static void printInfo(Method method) { |
iignatyev@4592 | 126 | System.out.printf("%n%s:%n", method); |
iignatyev@4592 | 127 | System.out.printf("\tcompilable:\t%b%n", |
iignatyev@4592 | 128 | WHITE_BOX.isMethodCompilable(method)); |
iignatyev@4592 | 129 | System.out.printf("\tcompiled:\t%b%n", |
iignatyev@4592 | 130 | WHITE_BOX.isMethodCompiled(method)); |
iignatyev@4592 | 131 | System.out.printf("\tcomp_level:\t%d%n", |
iignatyev@4592 | 132 | WHITE_BOX.getMethodCompilationLevel(method)); |
iignatyev@4592 | 133 | System.out.printf("\tin_queue:\t%b%n", |
iignatyev@4592 | 134 | WHITE_BOX.isMethodQueuedForCompilation(method)); |
iignatyev@4592 | 135 | System.out.printf("compile_queues_size:\t%d%n%n", |
iignatyev@4592 | 136 | WHITE_BOX.getCompileQueuesSize()); |
iignatyev@4592 | 137 | } |
iignatyev@4592 | 138 | |
iignatyev@4592 | 139 | protected abstract void test() throws Exception; |
iignatyev@4592 | 140 | |
iignatyev@4592 | 141 | protected final int compile() { |
iignatyev@4592 | 142 | int result = 0; |
iignatyev@4766 | 143 | int count = Math.max(COMPILE_THRESHOLD, 150000); |
iignatyev@4766 | 144 | for (int i = 0; i < count; ++i) { |
iignatyev@4592 | 145 | result += method(); |
iignatyev@4592 | 146 | } |
iignatyev@4766 | 147 | System.out.println("method was invoked " + count + " times"); |
iignatyev@4592 | 148 | return result; |
iignatyev@4592 | 149 | } |
iignatyev@4592 | 150 | |
iignatyev@4592 | 151 | protected int method() { |
iignatyev@4592 | 152 | return 42; |
iignatyev@4592 | 153 | } |
iignatyev@4592 | 154 | } |