changeset 3277:7d1d10fd767b

Enhancement: add support for inner classes specialization
author mcimadamore
date Wed, 16 Dec 2015 19:01:41 +0000
parents 3cc4be0968e4
children 3f01e9c496fe
files src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassWriter.java src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java test/tools/javac/valhalla/typespec/Inner02.java
diffstat 5 files changed, 63 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java	Mon Dec 14 13:39:57 2015 +0000
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java	Wed Dec 16 19:01:41 2015 +0000
@@ -5827,12 +5827,12 @@
              * Mangle specialized type (transitional).
              */
             Name mangledName(Type type) {
-                List<Type> typeargs = type.getTypeArguments();
+                List<Type> typeargs = type.allparams();
                 int offset = 0;
 
                 //compute name string
                 List<String> specNames =
-                        Tuple2.zip(List.range(offset, offset + typeargs.length()), typeargs).stream()
+                        Tuple2.zip(List.range(0, typeargs.length()), typeargs).stream()
                                 .filter(p -> p.elem1.isPrimitiveOrValue())
                                 .map(p -> String.join("=", p.elem0.toString(), typeSig(p.elem1)))
                                 .collect(List.collector());
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java	Mon Dec 14 13:39:57 2015 +0000
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java	Wed Dec 16 19:01:41 2015 +0000
@@ -1637,7 +1637,7 @@
         Type unerasedType = owner.enclClass().type.getEnclosingType();
         Type target = types.erasure(unerasedType);
         VarSymbol outerThis =
-            new VarSymbol(flags, outerThisName(target, owner), unerasedType, owner);
+            new VarSymbol(flags | SPECIALIZABLE, outerThisName(target, owner), unerasedType, owner);
         outerThisStack = outerThisStack.prepend(outerThis);
         return outerThis;
     }
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassWriter.java	Mon Dec 14 13:39:57 2015 +0000
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassWriter.java	Wed Dec 16 19:01:41 2015 +0000
@@ -491,6 +491,17 @@
                 acount++;
             }
         }
+
+        if (sym.isConstructor() && sym.enclClass().isInner()) {
+            Descriptor d = Descriptor.of(sym, sym.enclClass().type, types);
+            if (!types.isSameType(d.externalType(types), sym.type)) {
+                int alenIdx = writeAttr(names.SpecializerSignature);
+                databuf.appendChar(poolwriter.putConstant(typeSig(d.externalType(types))));
+                endAttr(alenIdx);
+                acount++;
+            }
+        }
+
         acount += writeJavaAnnotations(sym.getRawAttributes());
         acount += writeTypeAnnotations(sym.getRawTypeAttributes(), false);
         return acount;
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java	Mon Dec 14 13:39:57 2015 +0000
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java	Wed Dec 16 19:01:41 2015 +0000
@@ -340,7 +340,7 @@
             boolean addedParams = false;
             if (name == name.table.names.init && other.owner.hasOuterInstance()) {
                 //add outer instance param
-                params = params.prepend(other.externalType(types).getParameterTypes().head);
+                params = params.prepend(site.getEnclosingType());
                 addedParams = true;
             } else if (name == name.table.names.init &&
                     (other.owner.flags_field & ENUM) != 0 &&
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/valhalla/typespec/Inner02.java	Wed Dec 16 19:01:41 2015 +0000
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @summary smoke test for inner class support
+ * @clean .*
+ * @compile Inner02.java
+ * @run main Inner02
+ */
+public class Inner02<any X> {
+
+    static class Foo<any X> { }
+
+    final Foo<X> fx = new Foo<X>();
+
+	class Inner<any Y> {
+		void test() {
+			System.out.println(fx);
+        }
+    }
+
+    public static void main(String[] args) {
+		new Inner02<int>().new Inner<long>().test();
+    }
+}
\ No newline at end of file