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