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 * @run main/othervm -Xbatch SumTest 29 * 30 */ 31 public class SumTest { 32 private static class Sum { 33 34 double[] sums; 35 36 /** 37 * Construct empty Sum 38 */ 39 public Sum() { 40 sums = new double[0]; 41 } 42 43 /** 44 * Return the sum of all numbers added to this Sum 45 * 46 * @return the sum 47 */ 48 final public double getSum() { 49 double sum = 0; 50 for (final double s : sums) { 51 sum += s; 52 } 53 54 return sum; 55 } 56 57 /** 58 * Add a new number to this Sum 59 * 60 * @param a number to be added. 61 */ 62 final public void add(double a) { 63 try { 64 sums[sums.length] = -1; // Cause IndexOutOfBoundsException 65 } catch (final IndexOutOfBoundsException e) { 66 final double[] oldSums = sums; 67 sums = new double[oldSums.length + 1]; // Extend sums 68 System.arraycopy(oldSums, 0, sums, 0, oldSums.length); 69 sums[oldSums.length] = a; // Append a 70 } 71 } 72 } 73 74 public static void main(String[] args) throws Exception { 75 final Sum sum = new Sum(); 76 for (int i = 1; i <= 10000; ++i) { 77 sum.add(1); 78 double ii = sum.getSum(); 79 if (i != ii) { 80 throw new Exception("Failure: computed = " + ii + ", expected = " + i); 81 } 82 } 83 } 84 85 } 86