T8077247.java revision 3031:286fc9270404
1/*
2 * Copyright (c) 2015, 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.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26/*
27 * @test
28 * @bug 8078093 8077247
29 * @summary Exponential performance regression Java 8 compiler compared to Java 7 compiler
30 * @compile T8077247.java
31 */
32import java.util.ArrayList;
33import java.util.HashMap;
34import java.util.List;
35import java.util.Map;
36
37class T8077247 {
38    public static void test() {
39        int x = add(add(add(add(add(add(add(add(add(add(1, 2), 3), 4), 5), 6), 7), 8), 9), 10), 11);
40    }
41
42    public static int add(int x, int y) {
43        long rslt = (long)x + (long)y;
44        if (Integer.MIN_VALUE <= rslt && rslt <= Integer.MAX_VALUE) {
45            return (int)rslt;
46        }
47
48        String msg = String.format("Integer overflow: %d + %d.", x, y);
49        throw new IllegalArgumentException(msg);
50    }
51
52    public static double add(double x, double y) {
53        double rslt = x + y;
54        if (Double.isInfinite(rslt)) {
55            String msg = String.format("Real overflow: %s + %s.", x, y);
56            throw new IllegalArgumentException(msg);
57        }
58        return (rslt == -0.0) ? 0.0 : rslt;
59    }
60
61    public static <T> List<T> add(List<T> x, List<T> y) {
62        List<T> rslt = new ArrayList<>(x.size() + y.size());
63        rslt.addAll(x);
64        rslt.addAll(y);
65        return rslt;
66    }
67
68    public static String add(String x, String y) {
69        return x + y;
70    }
71
72    public static <K, V> Map<K, V> add(Map<K, V> x, Map<K, V> y) {
73        Map<K, V> rslt = new HashMap<>(x);
74        rslt.putAll(y);
75        return rslt;
76    }
77}
78