test/compiler/8004741/Test8004741.java

Wed, 28 Aug 2013 19:25:18 -0400

author
dholmes
date
Wed, 28 Aug 2013 19:25:18 -0400
changeset 5590
2b113b65a051
parent 4534
76341426b645
child 6876
710a3c8b516e
permissions
-rw-r--r--

8023900: [TESTBUG] Initial compact profile test groups need adjusting
Reviewed-by: dcubed, mchung, hseigel

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

mercurial