changeset 58788:8cbd40791397 lworld

8237071: [lworld] Totalize System.identityHashCode for inline types
author sadayapalam
date Mon, 03 Feb 2020 14:21:16 +0530
parents e2f1c4d5f39e
children b4bf177bac61
files src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java src/jdk.compiler/share/classes/com/sun/tools/javac/util/Names.java test/langtools/tools/javac/valhalla/lworld-values/CheckIdentityHash.java test/langtools/tools/javac/valhalla/lworld-values/CheckIdentityHash.out test/langtools/tools/javac/valhalla/lworld-values/CheckIdentityHash01.java test/langtools/tools/javac/valhalla/lworld-values/CheckIdentityHash01.out
diffstat 6 files changed, 90 insertions(+), 64 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Tue Jan 28 17:12:01 2020 +0530
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Mon Feb 03 14:21:16 2020 +0530
@@ -2343,43 +2343,40 @@
             restype = adjustMethodReturnType(msym, qualifier, methName, argtypes, restype);
 
             chk.checkRefTypes(tree.typeargs, typeargtypes);
-            // identity hash code is uncomputable for value instances.
+
             final Symbol symbol = TreeInfo.symbol(tree.meth);
-            if (symbol != null && symbol.name == names.identityHashCode && symbol.owner.flatName() == names.java_lang_System) {
-                if (tree.args.length() == 1 && types.isValue(tree.args.head.type))
-                    log.error(tree.pos(), Errors.ValueDoesNotSupport(names.identityHashCode));
-            }
-
-            /* Is this an ill conceived attempt to invoke jlO methods not available on value types ??
-            */
-            boolean superCallOnValueReceiver = types.isValue(env.enclClass.sym.type)
-                                    && (tree.meth.hasTag(SELECT))
-                                    && ((JCFieldAccess) tree.meth).selected.hasTag(IDENT)
-                                    && TreeInfo.name(((JCFieldAccess) tree.meth).selected) == names._super;
-            if (types.isValue(qualifier) || superCallOnValueReceiver) {
-                int argSize = argtypes.size();
-                Name name = symbol.name;
-                switch (name.toString()) {
-                    case "wait":
-                        if (argSize == 0
-                                || (types.isConvertible(argtypes.head, syms.longType) &&
-                                (argSize == 1 || (argSize == 2 && types.isConvertible(argtypes.tail.head, syms.intType))))) {
-                            log.error(tree.pos(),Errors.ValueDoesNotSupport(name));
-                        }
-                        break;
-                    case "notify":
-                    case "notifyAll":
-                    case "clone":
-                    case "finalize":
-                        if (argSize == 0)
-                            log.error(tree.pos(), Errors.ValueDoesNotSupport(name));
-                        break;
-                    case "hashCode":
-                    case "equals":
-                    case "toString":
-                        if (superCallOnValueReceiver)
-                            log.error(tree.pos(), Errors.ValueDoesNotSupport(names.fromString("invocation of super." + name)));
-                        break;
+            if (symbol != null) {
+                /* Is this an ill conceived attempt to invoke jlO methods not available on value types ??
+                 */
+                boolean superCallOnValueReceiver = types.isValue(env.enclClass.sym.type)
+                        && (tree.meth.hasTag(SELECT))
+                        && ((JCFieldAccess)tree.meth).selected.hasTag(IDENT)
+                        && TreeInfo.name(((JCFieldAccess)tree.meth).selected) == names._super;
+                if (types.isValue(qualifier) || superCallOnValueReceiver) {
+                    int argSize = argtypes.size();
+                    Name name = symbol.name;
+                    switch (name.toString()) {
+                        case "wait":
+                            if (argSize == 0
+                                    || (types.isConvertible(argtypes.head, syms.longType) &&
+                                    (argSize == 1 || (argSize == 2 && types.isConvertible(argtypes.tail.head, syms.intType))))) {
+                                log.error(tree.pos(), Errors.ValueDoesNotSupport(name));
+                            }
+                            break;
+                        case "notify":
+                        case "notifyAll":
+                        case "clone":
+                        case "finalize":
+                            if (argSize == 0)
+                                log.error(tree.pos(), Errors.ValueDoesNotSupport(name));
+                            break;
+                        case "hashCode":
+                        case "equals":
+                        case "toString":
+                            if (superCallOnValueReceiver)
+                                log.error(tree.pos(), Errors.ValueDoesNotSupport(names.fromString("invocation of super." + name)));
+                            break;
+                    }
                 }
             }
 
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Names.java	Tue Jan 28 17:12:01 2020 +0530
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Names.java	Mon Feb 03 14:21:16 2020 +0530
@@ -91,7 +91,6 @@
     public final Name getClass;
     public final Name hasNext;
     public final Name hashCode;
-    public final Name identityHashCode;
     public final Name init;
     public final Name iterator;
     public final Name length;
@@ -253,7 +252,6 @@
         getClass = fromString("getClass");
         hasNext = fromString("hasNext");
         hashCode = fromString("hashCode");
-        identityHashCode = fromString("identityHashCode");
         init = fromString("<init>");
         iterator = fromString("iterator");
         length = fromString("length");
--- a/test/langtools/tools/javac/valhalla/lworld-values/CheckIdentityHash.java	Tue Jan 28 17:12:01 2020 +0530
+++ b/test/langtools/tools/javac/valhalla/lworld-values/CheckIdentityHash.java	Mon Feb 03 14:21:16 2020 +0530
@@ -1,8 +1,31 @@
 /*
- * @test /nodynamiccopyright/
- * @summary Value types do not support identityHashCode
+ * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
- * @compile/fail/ref=CheckIdentityHash.out -XDrawDiagnostics CheckIdentityHash.java
+ * 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.
+ *
+ * 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
+ * @bug 8237071
+ * @summary Totalize System.identityHashCode for inline types.
+ * @compile CheckIdentityHash.java 
  */
 
 final inline class CheckIdentityHash {
@@ -10,11 +33,11 @@
         return 0;
     }
     void test(CheckIdentityHash v) {
-        this.identityHashCode(v);      // <- ok
-        System.identityHashCode(v);    // <- error
-        System.identityHashCode(this); // <- error
-        java.lang.System.identityHashCode(v);    // <- error
-        java.lang.System.identityHashCode(this); // <- error
+        this.identityHashCode(v);
+        System.identityHashCode(v);
+        System.identityHashCode(this);
+        java.lang.System.identityHashCode(v);
+        java.lang.System.identityHashCode(this);
     }
     int x = 10;
 }
--- a/test/langtools/tools/javac/valhalla/lworld-values/CheckIdentityHash.out	Tue Jan 28 17:12:01 2020 +0530
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,5 +0,0 @@
-CheckIdentityHash.java:14:32: compiler.err.value.does.not.support: identityHashCode
-CheckIdentityHash.java:15:32: compiler.err.value.does.not.support: identityHashCode
-CheckIdentityHash.java:16:42: compiler.err.value.does.not.support: identityHashCode
-CheckIdentityHash.java:17:42: compiler.err.value.does.not.support: identityHashCode
-4 errors
--- a/test/langtools/tools/javac/valhalla/lworld-values/CheckIdentityHash01.java	Tue Jan 28 17:12:01 2020 +0530
+++ b/test/langtools/tools/javac/valhalla/lworld-values/CheckIdentityHash01.java	Mon Feb 03 14:21:16 2020 +0530
@@ -1,13 +1,35 @@
 /*
- * @test /nodynamiccopyright/
- * @summary Value types do not support identityHashCode
+ * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
- * @compile/fail/ref=CheckIdentityHash01.out -XDrawDiagnostics CheckIdentityHash01.java
+ * 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.
+ *
+ * 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
+ * @bug 8237071
+ * @summary Totalize System.identityHashCode for inline types.
+ * @compile CheckIdentityHash01.java 
+ */
 import static java.lang.System.*;
 
-final inline class CheckIdentityHash01 {
+public final inline class CheckIdentityHash01 {
     void test(CheckIdentityHash01 v) {
 
         identityHashCode(v);      // <- error
--- a/test/langtools/tools/javac/valhalla/lworld-values/CheckIdentityHash01.out	Tue Jan 28 17:12:01 2020 +0530
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,9 +0,0 @@
-CheckIdentityHash01.java:13:25: compiler.err.value.does.not.support: identityHashCode
-CheckIdentityHash01.java:14:25: compiler.err.value.does.not.support: identityHashCode
-CheckIdentityHash01.java:17:32: compiler.err.value.does.not.support: identityHashCode
-CheckIdentityHash01.java:18:32: compiler.err.value.does.not.support: identityHashCode
-CheckIdentityHash01.java:20:32: compiler.err.value.does.not.support: identityHashCode
-CheckIdentityHash01.java:21:32: compiler.err.value.does.not.support: identityHashCode
-CheckIdentityHash01.java:23:42: compiler.err.value.does.not.support: identityHashCode
-CheckIdentityHash01.java:24:42: compiler.err.value.does.not.support: identityHashCode
-8 errors