Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/exceptions/SumTest.java
41149 views
1
/*
2
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
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
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test
26
* @bug 8066900
27
* @summary FP registers are not properly restored by C1 when handling exceptions
28
*
29
* @run main/othervm -Xbatch compiler.exceptions.SumTest
30
*/
31
32
package compiler.exceptions;
33
34
public class SumTest {
35
private static class Sum {
36
37
double[] sums;
38
39
/**
40
* Construct empty Sum
41
*/
42
public Sum() {
43
sums = new double[0];
44
}
45
46
/**
47
* Return the sum of all numbers added to this Sum
48
*
49
* @return the sum
50
*/
51
final public double getSum() {
52
double sum = 0;
53
for (final double s : sums) {
54
sum += s;
55
}
56
57
return sum;
58
}
59
60
/**
61
* Add a new number to this Sum
62
*
63
* @param a number to be added.
64
*/
65
final public void add(double a) {
66
try {
67
sums[sums.length] = -1; // Cause IndexOutOfBoundsException
68
} catch (final IndexOutOfBoundsException e) {
69
final double[] oldSums = sums;
70
sums = new double[oldSums.length + 1]; // Extend sums
71
System.arraycopy(oldSums, 0, sums, 0, oldSums.length);
72
sums[oldSums.length] = a; // Append a
73
}
74
}
75
}
76
77
public static void main(String[] args) throws Exception {
78
final Sum sum = new Sum();
79
for (int i = 1; i <= 10000; ++i) {
80
sum.add(1);
81
double ii = sum.getSum();
82
if (i != ii) {
83
throw new Exception("Failure: computed = " + ii + ", expected = " + i);
84
}
85
}
86
}
87
88
}
89
90
91