Path: blob/master/test/hotspot/jtreg/compiler/exceptions/SumTest.java
41149 views
/*1* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 806690026* @summary FP registers are not properly restored by C1 when handling exceptions27*28* @run main/othervm -Xbatch compiler.exceptions.SumTest29*/3031package compiler.exceptions;3233public class SumTest {34private static class Sum {3536double[] sums;3738/**39* Construct empty Sum40*/41public Sum() {42sums = new double[0];43}4445/**46* Return the sum of all numbers added to this Sum47*48* @return the sum49*/50final public double getSum() {51double sum = 0;52for (final double s : sums) {53sum += s;54}5556return sum;57}5859/**60* Add a new number to this Sum61*62* @param a number to be added.63*/64final public void add(double a) {65try {66sums[sums.length] = -1; // Cause IndexOutOfBoundsException67} catch (final IndexOutOfBoundsException e) {68final double[] oldSums = sums;69sums = new double[oldSums.length + 1]; // Extend sums70System.arraycopy(oldSums, 0, sums, 0, oldSums.length);71sums[oldSums.length] = a; // Append a72}73}74}7576public static void main(String[] args) throws Exception {77final Sum sum = new Sum();78for (int i = 1; i <= 10000; ++i) {79sum.add(1);80double ii = sum.getSum();81if (i != ii) {82throw new Exception("Failure: computed = " + ii + ", expected = " + i);83}84}85}8687}88899091