changeset 3298:776432d52150

Fix: BootstrapMethodKeys.equals() ignores differences in BSM handle Enhancement: simpler synthetic class names for translated generic methods Test: added stress tests for generic methods and Model 3
author mcimadamore
date Fri, 29 Jan 2016 19:04:38 +0000
parents 3700d512c76d
children 1b3a1239c255
files src/jdk.compiler/share/classes/com/sun/tools/javac/comp/SpecializeTypes.java src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/PoolWriter.java test/tools/javac/valhalla/typespec/GenericMethod01.java test/tools/javac/valhalla/typespec/GenericMethod02.java test/tools/javac/valhalla/typespec/GenericMethod03.java
diffstat 5 files changed, 96 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/SpecializeTypes.java	Fri Jan 29 15:57:10 2016 +0000
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/SpecializeTypes.java	Fri Jan 29 19:04:38 2016 +0000
@@ -808,7 +808,7 @@
 
         //create generic inner class symbol
         ClassSymbol genMethodClassSym = new ClassSymbol(Flags.SYNTHETIC | msym.flags(),
-                currentClass.getSimpleName().append('$', msym.name).append('$', sigHash(msym)),
+                msym.name.append('$', sigHash(msym)),
                 null,
                 currentClass);
         genMethodClassSym.flags_field &= ~Flags.AccessFlags;
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/PoolWriter.java	Fri Jan 29 15:57:10 2016 +0000
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/PoolWriter.java	Fri Jan 29 19:04:38 2016 +0000
@@ -302,7 +302,7 @@
                     .map(this::visitStaticIndyArg)
                     .toArray(Entry[]::new);
 
-            BootstrapMethodsKey key = new BootstrapMethodsKey(staticArgs);
+            BootstrapMethodsKey key = new BootstrapMethodsKey(handle, staticArgs);
 
             // Figure out the index for existing BSM; create a new BSM if no key
             Tuple2<MethodHandle, Integer> val = bootstrapMethods.get(key);
@@ -618,22 +618,27 @@
      */
     static class BootstrapMethodsKey {
 
+        /** Bootstrap handle. */
+        MethodHandle handle;
+
         /** Static args entries. */
         Entry[] staticArgs;
 
-        BootstrapMethodsKey(Entry[] staticArgs) {
+        BootstrapMethodsKey(MethodHandle handle, Entry[] staticArgs) {
+            this.handle = handle;
             this.staticArgs = staticArgs;
         }
 
         @Override
         public int hashCode() {
-            return Arrays.hashCode(staticArgs);
+            return Objects.hash(handle, Arrays.hashCode(staticArgs));
         }
 
         public boolean equals(Object o) {
             if (o instanceof BootstrapMethodsKey) {
                 BootstrapMethodsKey that = (BootstrapMethodsKey)o;
-                return Objects.deepEquals(that.staticArgs, staticArgs);
+                return that.handle.equals(handle) &&
+                        Objects.deepEquals(that.staticArgs, staticArgs);
             } else {
                 return false;
             }
--- a/test/tools/javac/valhalla/typespec/GenericMethod01.java	Fri Jan 29 15:57:10 2016 +0000
+++ b/test/tools/javac/valhalla/typespec/GenericMethod01.java	Fri Jan 29 19:04:38 2016 +0000
@@ -30,10 +30,8 @@
  * @compile GenericMethod01.java
  * @run main GenericMethod01 *
  * @clean .*
- * @compile -XDdesugarGenericMethods GenericMethod01.java
+ * @compile -XDgenericClassFile GenericMethod01.java
  * @run main GenericMethod01
- * @clean .*
- * @compile -XDgenericClassFile GenericMethod01.java
  */
 public class GenericMethod01 {
 
--- a/test/tools/javac/valhalla/typespec/GenericMethod02.java	Fri Jan 29 15:57:10 2016 +0000
+++ b/test/tools/javac/valhalla/typespec/GenericMethod02.java	Fri Jan 29 19:04:38 2016 +0000
@@ -27,10 +27,8 @@
  * @test
  * @summary smoke test for translation clashes using alt translation scheme
  * @clean .*
- * @compile -XDdesugarGenericMethods GenericMethod02.java
+ * @compile -XDgenericClassFile GenericMethod02.java
  * @run main GenericMethod02
- * @clean .*
- * @compile -XDgenericClassFile GenericMethod02.java
  */
 public class GenericMethod02 {
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/valhalla/typespec/GenericMethod03.java	Fri Jan 29 19:04:38 2016 +0000
@@ -0,0 +1,84 @@
+/*
+ * 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 stress test for generic methods using (both translation schemes)
+ * @clean .*
+ * @compile GenericMethod03.java
+ * @run main GenericMethod03
+ * @clean .*
+ * @compile -XDgenericClassFile GenericMethod03.java
+ * @run main GenericMethod03
+ */
+public class GenericMethod03 {
+
+	static class Foo<any X> {
+		static <any Z> void m_static(Z z) {
+			System.err.println("Hello static Foo!");
+		}
+
+		<any Z> void m_inst(Z z, X x) {
+		    System.err.println("Hello Foo!");
+		}
+	}
+
+	static class Bar<any X> extends Foo<X> {
+		<any Z> void m_inst(Z z, X x) {
+		    System.err.println("Hello Bar!");
+		}
+	}
+
+
+	static void testStaticFoo() {
+        Foo.m_static(1);
+		Foo.m_static("");
+    }
+
+	static void testFoo() {
+        new Foo<String>().m_inst(1, "");
+		new Foo<float>().m_inst(1, 1F);
+        new Foo<String>().m_inst("", "");
+		new Foo<float>().m_inst("", 1F);
+        new Foo().m_inst(1, null);
+		new Foo().m_inst("", null);
+    }
+
+	static void testBar() {
+        new Bar<String>().m_inst(1, "");
+		new Bar<float>().m_inst(1, 1F);
+        new Bar<String>().m_inst("", "");
+		new Bar<float>().m_inst("", 1F);
+        new Bar().m_inst(1, null);
+		new Bar().m_inst("", null);
+    }
+
+
+	public static void main(String[] args) {
+        testStaticFoo();
+		testFoo();
+        testBar();
+    }
+}