changeset 3282:3ae1321e6516

Fix: add hash to desugared generic method inner classes
author mcimadamore
date Tue, 05 Jan 2016 12:56:28 +0000
parents dddf65a2e118
children 7af97c773606
files src/jdk.compiler/share/classes/com/sun/tools/javac/comp/SpecializeTypes.java test/tools/javac/valhalla/typespec/GenericMethod01.java test/tools/javac/valhalla/typespec/GenericMethod02.java
diffstat 3 files changed, 49 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/SpecializeTypes.java	Tue Dec 22 19:11:56 2015 +0000
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/SpecializeTypes.java	Tue Jan 05 12:56:28 2016 +0000
@@ -786,7 +786,7 @@
 
         //create generic inner class symbol
         ClassSymbol genMethodClassSym = new ClassSymbol(Flags.SYNTHETIC | msym.flags(),
-                currentClass.getSimpleName().append('$', msym.name),
+                currentClass.getSimpleName().append('$', msym.name).append('$', sigHash(msym)),
                 null,
                 currentClass);
         genMethodClassSym.flags_field &= ~Flags.AccessFlags;
@@ -969,6 +969,12 @@
             }
         }
 
+        private Name sigHash(MethodSymbol msym) {
+            String s = types.typeDesc(msym.type).toString();
+            String params = s.substring(1, s.lastIndexOf(')'));
+            return names.fromString(String.valueOf(Math.abs(params.hashCode())));
+        }
+
     /**
      * Generate a tree corresponding to a virtual (synthetic) interface. Such an interface contains
      * two things: (i) boxing getters/setters for the anyfied class fields; (ii) boxing bridges for
--- a/test/tools/javac/valhalla/typespec/GenericMethod01.java	Tue Dec 22 19:11:56 2015 +0000
+++ b/test/tools/javac/valhalla/typespec/GenericMethod01.java	Tue Jan 05 12:56:28 2016 +0000
@@ -25,7 +25,7 @@
 
 /*
  * @test
- * @summary smoke test for generic methods (suaing both translation schemes)
+ * @summary smoke test for generic methods (using both translation schemes)
  * @clean .*
  * @compile GenericMethod01.java
  * @run main GenericMethod01
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/valhalla/typespec/GenericMethod02.java	Tue Jan 05 12:56:28 2016 +0000
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2016, 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 translation clashes using alt translation scheme
+ * @clean .*
+ * @compile -XDdesugarGenericMethods GenericMethod02.java
+ * @run main GenericMethod02
+ */
+public class GenericMethod02 {
+
+    static <any Z> void m() { }
+    static <any Z> void m(int i) { }
+
+    public static void main(String[] args) {
+        new GenericMethod02(); //should not throw verifier error because of duplicate signatures!
+    }
+}