annotate test/compiler/exceptions/SumTest.java @ 20702:b5eb829bbce1

8066900: Array Out Of Bounds Exception causes variable corruption Summary: Fix FP registers save/restore during exception handling Reviewed-by: kvn, vlivanov
author iveresov
date Tue, 09 Dec 2014 12:25:38 -0800
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20702
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
1 /*
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
4 *
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
7 * published by the Free Software Foundation.
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
8 *
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
13 * accompanied this code).
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
14 *
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
18 *
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
21 * questions.
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
22 */
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
23
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
24 /*
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
25 * @test
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
26 * @bug 8066900
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
27 * @summary FP registers are not properly restored by C1 when handling exceptions
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
28 * @run main/othervm -Xbatch SumTest
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
29 *
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
30 */
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
31 public class SumTest {
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
32 private static class Sum {
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
33
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
34 double[] sums;
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
35
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
36 /**
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
37 * Construct empty Sum
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
38 */
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
39 public Sum() {
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
40 sums = new double[0];
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
41 }
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
42
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
43 /**
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
44 * Return the sum of all numbers added to this Sum
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
45 *
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
46 * @return the sum
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
47 */
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
48 final public double getSum() {
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
49 double sum = 0;
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
50 for (final double s : sums) {
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
51 sum += s;
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
52 }
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
53
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
54 return sum;
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
55 }
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
56
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
57 /**
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
58 * Add a new number to this Sum
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
59 *
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
60 * @param a number to be added.
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
61 */
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
62 final public void add(double a) {
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
63 try {
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
64 sums[sums.length] = -1; // Cause IndexOutOfBoundsException
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
65 } catch (final IndexOutOfBoundsException e) {
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
66 final double[] oldSums = sums;
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
67 sums = new double[oldSums.length + 1]; // Extend sums
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
68 System.arraycopy(oldSums, 0, sums, 0, oldSums.length);
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
69 sums[oldSums.length] = a; // Append a
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
70 }
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
71 }
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
72 }
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
73
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
74 public static void main(String[] args) throws Exception {
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
75 final Sum sum = new Sum();
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
76 for (int i = 1; i <= 10000; ++i) {
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
77 sum.add(1);
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
78 double ii = sum.getSum();
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
79 if (i != ii) {
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
80 throw new Exception("Failure: computed = " + ii + ", expected = " + i);
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
81 }
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
82 }
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
83 }
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
84
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
85 }
b5eb829bbce1 8066900: Array Out Of Bounds Exception causes variable corruption
iveresov
parents:
diff changeset
86