changeset 419:905bcd21d2bb

meth-lazy: incorporate review comments
author jrose
date Sat, 21 Jul 2012 16:50:34 -0700
parents 4a0cedf169a2
children 3b3f4347ab7e
files meth-lazy-7023639.rmcode.patch
diffstat 1 files changed, 165 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/meth-lazy-7023639.rmcode.patch	Sat Jul 21 14:10:20 2012 -0700
+++ b/meth-lazy-7023639.rmcode.patch	Sat Jul 21 16:50:34 2012 -0700
@@ -664,10 +664,29 @@
              // else if isLinker, then MTYPE is passed in from the caller (e.g., the JVM)
          }
  
+@@ -320,9 +320,7 @@
+             form.genericInvoker = gamh;
+             return gamh;
+         } catch (Exception ex) {
+-            Error err = new InternalError("Exception while resolving inexact invoke", ex);
+-            err.initCause(ex);
+-            throw err;
++            throw new InternalError("Exception while resolving inexact invoke", ex);
+         }
+     }
+ 
 diff --git a/src/share/classes/java/lang/invoke/LambdaForm.java b/src/share/classes/java/lang/invoke/LambdaForm.java
 --- a/src/share/classes/java/lang/invoke/LambdaForm.java
 +++ b/src/share/classes/java/lang/invoke/LambdaForm.java
-@@ -773,14 +773,14 @@
+@@ -37,6 +37,7 @@
+ import static java.lang.invoke.MethodHandleStatics.*;
+ import static java.lang.invoke.MethodHandleNatives.Constants.*;
+ import java.lang.reflect.Field;
++import java.util.Objects;
+ 
+ /**
+  * The symbolic, non-executable form of a method handle's invocation semantics.
+@@ -773,14 +774,14 @@
          return new LambdaForm(debugName, arity2, names2, result2);
      }
  
@@ -686,6 +705,151 @@
          int pos = name.index;
          assert(name.isParam());
          assert(!binding.isParam());
+@@ -1010,6 +1011,13 @@
+             return this.member != null && this.member.equals(that.member);
+         }
+ 
++        @Override
++        public int hashCode() {
++            if (member != null)
++                return member.hashCode();
++            return super.hashCode();
++        }
++
+         // Put the predefined NamedFunction invokers into the table.
+         static void initializeInvokers() {
+             for (MemberName m : MemberName.getFactory().getMethods(NamedFunction.class, false, null, null, null)) {
+@@ -1183,14 +1191,15 @@
+         }
+ 
+         MemberName member() {
+-            assert(memberIsConsistent());
++            assert(assertMemberIsConsistent());
+             return member;
+         }
+ 
+-        boolean memberIsConsistent() {
++        // Called only from assert.
++        private boolean assertMemberIsConsistent() {
+             if (resolvedHandle instanceof DirectMethodHandle) {
+                 MemberName m = resolvedHandle.internalMemberName();
+-                assert(m.equals(member)) : Arrays.asList(member, m, resolvedHandle);
++                assert(m.equals(member));
+             }
+             return true;
+         }
+@@ -1408,9 +1417,6 @@
+             return true;
+         }
+ 
+-        public boolean equals(Object x) {
+-            return x instanceof Name && equals((Name)x);
+-        }
+         /**
+          * Does this Name precede the given binding node in some canonical order?
+          * This predicate is used to order data bindings (via insertion sort)
+@@ -1440,6 +1446,7 @@
+             }
+             return false;
+         }
++
+         public boolean equals(Name that) {
+             if (this == that)  return true;
+             if (isParam())
+@@ -1451,6 +1458,11 @@
+                 this.function.equals(that.function) &&
+                 Arrays.equals(this.arguments, that.arguments);
+         }
++        @Override
++        public boolean equals(Object x) {
++            return x instanceof Name && equals((Name)x);
++        }
++        @Override
+         public int hashCode() {
+             if (isParam())
+                 return index | (type << 8);
+diff --git a/src/share/classes/java/lang/invoke/MemberName.java b/src/share/classes/java/lang/invoke/MemberName.java
+--- a/src/share/classes/java/lang/invoke/MemberName.java
++++ b/src/share/classes/java/lang/invoke/MemberName.java
+@@ -40,6 +40,7 @@
+ import java.util.List;
+ import static java.lang.invoke.MethodHandleNatives.Constants.*;
+ import static java.lang.invoke.MethodHandleStatics.*;
++import java.util.Objects;
+ 
+ /**
+  * A {@code MemberName} is a compact symbolic datum which fully characterizes
+@@ -77,32 +78,6 @@
+     //@Injected int         vmindex;
+     private Object     resolution;  // if null, this guy is resolved
+ 
+-    @Override
+-    public boolean equals(Object other) {
+-        if (this == other) return true;
+-        if (other == null) return false;
+-        if (!(other instanceof MemberName)) return false;
+-        MemberName that = (MemberName) other;
+-        return this.clazz == that.clazz
+-                && this.flags == that.flags
+-                && this.name.equals(that.name)
+-                && typesEqual(this.getType(), that.getType());
+-    }
+-
+-    private static boolean typesEqual(Object a, Object b) {
+-        if (a == null && b == null)
+-            return true;
+-        if (a == null ^ b == null)
+-            return false;
+-        if (a.getClass() != b.getClass())
+-            return false;
+-        if (a instanceof Class<?>)
+-            return a == b;
+-        if (a instanceof MethodType)
+-            return a.equals(b);
+-        return false;
+-    }
+-
+     /** Return the declaring class of this member.
+      *  In the case of a bare name and type, the declaring class will be null.
+      */
+@@ -604,22 +579,27 @@
+         return res;
+     }
+ 
+-    /*
+     @Override
+     public int hashCode() {
+-        Object[] elements = { getDeclaringClass(), getName(), getMethodOrFieldType(), getReferenceKind() };
+-        return Arrays.hashCode(elements);
++        return Objects.hash(clazz, flags, name, getType());
+     }
+     @Override
+     public boolean equals(Object that) {
+-        return (that instanceof MemberName && this.sameReference((MemberName)that));
++        return (that instanceof MemberName && this.equals((MemberName)that));
+     }
+-    */
+-    public boolean sameReference(MemberName that) {
+-        return (this.getDeclaringClass().equals(that.getDeclaringClass()) &&
+-                this.getName().equals(that.getName()) &&
+-                this.getMethodOrFieldType().equals(that.getMethodOrFieldType()) &&
+-                this.getReferenceKind() == that.getReferenceKind());
++
++    /** Decide if two member names have exactly the same symbolic content.
++     *  Does not take into account any actual class members, so even if
++     *  two member names resolve to the same actual member, they may
++     *  be distinct references.
++     */
++    public boolean equals(MemberName that) {
++        if (this == that)  return true;
++        if (that == null)  return false;
++        return this.clazz == that.clazz
++                && this.flags == that.flags
++                && Objects.equals(this.name, that.name)
++                && Objects.equals(this.getType(), that.getType());
+     }
+ 
+     // Construction from symbolic parts, for queries:
 diff --git a/src/share/classes/java/lang/invoke/MethodHandle.java b/src/share/classes/java/lang/invoke/MethodHandle.java
 --- a/src/share/classes/java/lang/invoke/MethodHandle.java
 +++ b/src/share/classes/java/lang/invoke/MethodHandle.java