Thu, 30 Jul 2009 10:29:53 +0100
6827648: Extremely slow compilation time for visitor pattern code + generics
Summary: Javac unnecessarily recomputates type-substitutions multiple times
Reviewed-by: jjg
mcimadamore@133 | 1 | /* |
mcimadamore@133 | 2 | * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. |
mcimadamore@133 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
mcimadamore@133 | 4 | * |
mcimadamore@133 | 5 | * This code is free software; you can redistribute it and/or modify it |
mcimadamore@133 | 6 | * under the terms of the GNU General Public License version 2 only, as |
mcimadamore@133 | 7 | * published by the Free Software Foundation. |
mcimadamore@133 | 8 | * |
mcimadamore@133 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
mcimadamore@133 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
mcimadamore@133 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
mcimadamore@133 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
mcimadamore@133 | 13 | * accompanied this code). |
mcimadamore@133 | 14 | * |
mcimadamore@133 | 15 | * You should have received a copy of the GNU General Public License version |
mcimadamore@133 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
mcimadamore@133 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
mcimadamore@133 | 18 | * |
mcimadamore@133 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
mcimadamore@133 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
mcimadamore@133 | 21 | * have any questions. |
mcimadamore@133 | 22 | */ |
mcimadamore@133 | 23 | |
mcimadamore@133 | 24 | /* |
mcimadamore@133 | 25 | * @test |
mcimadamore@133 | 26 | * @bug 6751514 |
mcimadamore@133 | 27 | * @summary Unary post-increment with type variables crash javac during lowering |
mcimadamore@133 | 28 | * @author Maurizio Cimadamore |
mcimadamore@133 | 29 | */ |
mcimadamore@133 | 30 | |
mcimadamore@133 | 31 | public class T6751514 { |
mcimadamore@133 | 32 | |
mcimadamore@133 | 33 | static class Foo<X> { |
mcimadamore@133 | 34 | X x; |
mcimadamore@133 | 35 | Foo (X x) { |
mcimadamore@133 | 36 | this.x = x; |
mcimadamore@133 | 37 | } |
mcimadamore@133 | 38 | } |
mcimadamore@133 | 39 | |
mcimadamore@133 | 40 | static void test1(Foo<Integer> foo) { |
mcimadamore@133 | 41 | int start = foo.x; |
mcimadamore@133 | 42 | equals(foo.x += 1, start + 1); |
mcimadamore@133 | 43 | equals(foo.x++, start + 1); |
mcimadamore@133 | 44 | equals(++foo.x, start + 3); |
mcimadamore@133 | 45 | equals(foo.x--, start + 3); |
mcimadamore@133 | 46 | equals(foo.x -= 1, start + 1); |
mcimadamore@133 | 47 | equals(--foo.x, start); |
mcimadamore@133 | 48 | } |
mcimadamore@133 | 49 | |
mcimadamore@133 | 50 | static void test2(Foo<Integer> foo) { |
mcimadamore@133 | 51 | int start = foo.x; |
mcimadamore@133 | 52 | equals((foo.x) += 1, start + 1); |
mcimadamore@133 | 53 | equals((foo.x)++, start + 1); |
mcimadamore@133 | 54 | equals(++(foo.x), start + 3); |
mcimadamore@133 | 55 | equals((foo.x)--, start + 3); |
mcimadamore@133 | 56 | equals((foo.x) -= 1, start + 1); |
mcimadamore@133 | 57 | equals(--(foo.x), start); |
mcimadamore@133 | 58 | } |
mcimadamore@133 | 59 | |
mcimadamore@133 | 60 | static void test3(Foo<Integer> foo) { |
mcimadamore@133 | 61 | int start = foo.x; |
mcimadamore@133 | 62 | equals(((foo.x)) += 1, start + 1); |
mcimadamore@133 | 63 | equals(((foo.x))++, start + 1); |
mcimadamore@133 | 64 | equals(++((foo.x)), start + 3); |
mcimadamore@133 | 65 | equals(((foo.x))--, start + 3); |
mcimadamore@133 | 66 | equals(((foo.x)) -= 1, start + 1); |
mcimadamore@133 | 67 | equals(--((foo.x)), start); |
mcimadamore@133 | 68 | } |
mcimadamore@133 | 69 | |
mcimadamore@133 | 70 | public static void main(String[] args) { |
mcimadamore@133 | 71 | test1(new Foo<Integer>(1)); |
mcimadamore@133 | 72 | test2(new Foo<Integer>(1)); |
mcimadamore@133 | 73 | test3(new Foo<Integer>(1)); |
mcimadamore@133 | 74 | } |
mcimadamore@133 | 75 | |
mcimadamore@133 | 76 | static void equals(int found, int req) { |
mcimadamore@133 | 77 | if (found != req) { |
mcimadamore@133 | 78 | throw new AssertionError("Error (expected: "+ req + |
mcimadamore@133 | 79 | " - found: " + found + ")"); |
mcimadamore@133 | 80 | } |
mcimadamore@133 | 81 | } |
mcimadamore@133 | 82 | } |