Tue, 08 Aug 2017 15:57:29 +0800
merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. |
aoqi@0 | 8 | * |
aoqi@0 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 13 | * accompanied this code). |
aoqi@0 | 14 | * |
aoqi@0 | 15 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 18 | * |
aoqi@0 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 20 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 21 | * questions. |
aoqi@0 | 22 | */ |
aoqi@0 | 23 | |
aoqi@0 | 24 | /* |
aoqi@0 | 25 | * @test Test8004741.java |
aoqi@0 | 26 | * @bug 8004741 |
aoqi@0 | 27 | * @summary Missing compiled exception handle table entry for multidimensional array allocation |
aoqi@0 | 28 | * @run main/othervm -Xmx64m -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:-TieredCompilation -XX:+StressCompiledExceptionHandlers -XX:+SafepointALot -XX:GuaranteedSafepointInterval=100 Test8004741 |
aoqi@0 | 29 | * @run main/othervm -Xmx64m -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:-TieredCompilation -XX:+StressCompiledExceptionHandlers Test8004741 |
aoqi@0 | 30 | */ |
aoqi@0 | 31 | |
aoqi@0 | 32 | import java.util.*; |
aoqi@0 | 33 | |
aoqi@0 | 34 | public class Test8004741 extends Thread { |
aoqi@0 | 35 | |
aoqi@0 | 36 | static int passed = 0; |
aoqi@0 | 37 | |
aoqi@0 | 38 | /** |
aoqi@0 | 39 | * Loop forever allocating 2-d arrays. |
aoqi@0 | 40 | * Catches and rethrows all exceptions; in the case of ThreadDeath, increments passed. |
aoqi@0 | 41 | * Note that passed is incremented here because this is the exception handler with |
aoqi@0 | 42 | * the smallest scope; we only want to declare success in the case where it is highly |
aoqi@0 | 43 | * likely that the test condition |
aoqi@0 | 44 | * (exception in 2-d array alloc interrupted by ThreadDeath) |
aoqi@0 | 45 | * actually occurs. |
aoqi@0 | 46 | */ |
aoqi@0 | 47 | static int[][] test(int a, int b) throws Exception { |
aoqi@0 | 48 | int[][] ar; |
aoqi@0 | 49 | try { |
aoqi@0 | 50 | ar = new int[a][b]; |
aoqi@0 | 51 | } catch (ThreadDeath e) { |
aoqi@0 | 52 | System.out.println("test got ThreadDeath"); |
aoqi@0 | 53 | passed++; |
aoqi@0 | 54 | throw(e); |
aoqi@0 | 55 | } |
aoqi@0 | 56 | return ar; |
aoqi@0 | 57 | } |
aoqi@0 | 58 | |
aoqi@0 | 59 | /* Cookbook wait-notify to track progress of test thread. */ |
aoqi@0 | 60 | Object progressLock = new Object(); |
aoqi@0 | 61 | private static final int NOT_STARTED = 0; |
aoqi@0 | 62 | private static final int RUNNING = 1; |
aoqi@0 | 63 | private static final int STOPPING = 2; |
aoqi@0 | 64 | |
aoqi@0 | 65 | int progressState = NOT_STARTED; |
aoqi@0 | 66 | |
aoqi@0 | 67 | void toState(int state) { |
aoqi@0 | 68 | synchronized (progressLock) { |
aoqi@0 | 69 | progressState = state; |
aoqi@0 | 70 | progressLock.notify(); |
aoqi@0 | 71 | } |
aoqi@0 | 72 | } |
aoqi@0 | 73 | |
aoqi@0 | 74 | void waitFor(int state) { |
aoqi@0 | 75 | synchronized (progressLock) { |
aoqi@0 | 76 | while (progressState < state) { |
aoqi@0 | 77 | try { |
aoqi@0 | 78 | progressLock.wait(); |
aoqi@0 | 79 | } catch (InterruptedException e) { |
aoqi@0 | 80 | e.printStackTrace(); |
aoqi@0 | 81 | System.out.println("unexpected InterruptedException"); |
aoqi@0 | 82 | fail(); |
aoqi@0 | 83 | } |
aoqi@0 | 84 | } |
aoqi@0 | 85 | if (progressState > state) { |
aoqi@0 | 86 | System.out.println("unexpected test state change, expected " + |
aoqi@0 | 87 | state + " but saw " + progressState); |
aoqi@0 | 88 | fail(); |
aoqi@0 | 89 | } |
aoqi@0 | 90 | } |
aoqi@0 | 91 | } |
aoqi@0 | 92 | |
aoqi@0 | 93 | /** |
aoqi@0 | 94 | * Loops running test until some sort of an exception or error, |
aoqi@0 | 95 | * expects to see ThreadDeath. |
aoqi@0 | 96 | */ |
aoqi@0 | 97 | public void run() { |
aoqi@0 | 98 | try { |
aoqi@0 | 99 | // Print before state change, so that other thread is most likely |
aoqi@0 | 100 | // to see this thread executing calls to test() in a loop. |
aoqi@0 | 101 | System.out.println("thread running"); |
aoqi@0 | 102 | toState(RUNNING); |
aoqi@0 | 103 | while (true) { |
aoqi@0 | 104 | // (2,2) (2,10) (2,100) were observed to tickle the bug; |
aoqi@0 | 105 | test(2, 100); |
aoqi@0 | 106 | } |
aoqi@0 | 107 | } catch (ThreadDeath e) { |
aoqi@0 | 108 | // nothing to say, passing was incremented by the test. |
aoqi@0 | 109 | } catch (Throwable e) { |
aoqi@0 | 110 | e.printStackTrace(); |
aoqi@0 | 111 | System.out.println("unexpected Throwable " + e); |
aoqi@0 | 112 | fail(); |
aoqi@0 | 113 | } |
aoqi@0 | 114 | toState(STOPPING); |
aoqi@0 | 115 | } |
aoqi@0 | 116 | |
aoqi@0 | 117 | /** |
aoqi@0 | 118 | * Runs a single trial of the test in a thread. |
aoqi@0 | 119 | * No single trial is definitive, since the ThreadDeath |
aoqi@0 | 120 | * exception might not land in the tested region of code. |
aoqi@0 | 121 | */ |
aoqi@0 | 122 | public static void threadTest() throws InterruptedException { |
aoqi@0 | 123 | Test8004741 t = new Test8004741(); |
aoqi@0 | 124 | t.start(); |
aoqi@0 | 125 | t.waitFor(RUNNING); |
aoqi@0 | 126 | Thread.sleep(100); |
aoqi@0 | 127 | System.out.println("stopping thread"); |
aoqi@0 | 128 | t.stop(); |
aoqi@0 | 129 | t.waitFor(STOPPING); |
aoqi@0 | 130 | t.join(); |
aoqi@0 | 131 | } |
aoqi@0 | 132 | |
aoqi@0 | 133 | public static void main(String[] args) throws Exception { |
aoqi@0 | 134 | // Warm up "test" |
aoqi@0 | 135 | // t will never be started. |
aoqi@0 | 136 | for (int n = 0; n < 11000; n++) { |
aoqi@0 | 137 | test(2, 100); |
aoqi@0 | 138 | } |
aoqi@0 | 139 | |
aoqi@0 | 140 | // Will this sleep help ensure that the compiler is run? |
aoqi@0 | 141 | Thread.sleep(500); |
aoqi@0 | 142 | passed = 0; |
aoqi@0 | 143 | |
aoqi@0 | 144 | try { |
aoqi@0 | 145 | test(-1, 100); |
aoqi@0 | 146 | System.out.println("Missing NegativeArraySizeException #1"); |
aoqi@0 | 147 | fail(); |
aoqi@0 | 148 | } catch ( java.lang.NegativeArraySizeException e ) { |
aoqi@0 | 149 | System.out.println("Saw expected NegativeArraySizeException #1"); |
aoqi@0 | 150 | } |
aoqi@0 | 151 | |
aoqi@0 | 152 | try { |
aoqi@0 | 153 | test(100, -1); |
aoqi@0 | 154 | fail(); |
aoqi@0 | 155 | System.out.println("Missing NegativeArraySizeException #2"); |
aoqi@0 | 156 | fail(); |
aoqi@0 | 157 | } catch ( java.lang.NegativeArraySizeException e ) { |
aoqi@0 | 158 | System.out.println("Saw expected NegativeArraySizeException #2"); |
aoqi@0 | 159 | } |
aoqi@0 | 160 | |
aoqi@0 | 161 | /* Test repetitions. If the test succeeds-mostly, it succeeds, |
aoqi@0 | 162 | * as long as it does not crash (the outcome if the exception range |
aoqi@0 | 163 | * table entry for the array allocation is missing). |
aoqi@0 | 164 | */ |
aoqi@0 | 165 | int N = 12; |
aoqi@0 | 166 | for (int n = 0; n < N; n++) { |
aoqi@0 | 167 | threadTest(); |
aoqi@0 | 168 | } |
aoqi@0 | 169 | |
aoqi@0 | 170 | if (passed > N/2) { |
aoqi@0 | 171 | System.out.println("Saw " + passed + " out of " + N + " possible ThreadDeath hits"); |
aoqi@0 | 172 | System.out.println("PASSED"); |
aoqi@0 | 173 | } else { |
aoqi@0 | 174 | System.out.println("Too few ThreadDeath hits; expected at least " + N/2 + |
aoqi@0 | 175 | " but saw only " + passed); |
aoqi@0 | 176 | fail(); |
aoqi@0 | 177 | } |
aoqi@0 | 178 | } |
aoqi@0 | 179 | |
aoqi@0 | 180 | static void fail() { |
aoqi@0 | 181 | System.out.println("FAILED"); |
aoqi@0 | 182 | System.exit(97); |
aoqi@0 | 183 | } |
aoqi@0 | 184 | }; |