changeset 49690:398f83f17970 condy-folding

Improvements to DynamicCallSiteRef
author briangoetz
date Thu, 15 Mar 2018 19:06:44 -0400
parents 47f797792311
children 3623e1e0e5d8
files src/java.base/share/classes/java/lang/invoke/constant/DynamicCallSiteRef.java
diffstat 1 files changed, 17 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/lang/invoke/constant/DynamicCallSiteRef.java	Mon Mar 12 11:40:08 2018 -0400
+++ b/src/java.base/share/classes/java/lang/invoke/constant/DynamicCallSiteRef.java	Thu Mar 15 19:06:44 2018 -0400
@@ -31,8 +31,10 @@
 import java.lang.invoke.MethodHandles;
 import java.util.Arrays;
 import java.util.Objects;
+import java.util.stream.Stream;
 
 import static java.lang.invoke.constant.ConstantRefs.CR_String;
+import static java.util.stream.Collectors.joining;
 
 /**
  * A nominal reference for an {@code invokedynamic} call site.
@@ -41,7 +43,7 @@
 public final class DynamicCallSiteRef {
     private static final ConstantRef<?>[] EMPTY_ARGS = new ConstantRef<?>[0];
 
-    private final MethodHandleRef bootstrapMethod;
+    private final ConstantMethodHandleRef bootstrapMethod;
     private final ConstantRef<?>[] bootstrapArgs;
     private final String name;
     private final MethodTypeRef type;
@@ -57,15 +59,22 @@
      * @param bootstrapArgs The static arguments to the bootstrap, that would
      *                      appear in the {@code BootstrapMethods} attribute
      * @throws NullPointerException if any parameter is null
+     * @throws IllegalArgumentException if the bootstrap method is not a
+     * {@link ConstantMethodHandleRef}
+     * @throws IllegalArgumentException if {@code name.length()} is zero
      */
     private DynamicCallSiteRef(MethodHandleRef bootstrapMethod,
                                String name,
                                MethodTypeRef type,
                                ConstantRef<?>[] bootstrapArgs) {
+        if (!(bootstrapMethod instanceof ConstantMethodHandleRef))
+            throw new IllegalArgumentException("bootstrap method must be a ConstantMethodHandleRef");
         this.name = Objects.requireNonNull(name);
         this.type = Objects.requireNonNull(type);
-        this.bootstrapMethod = Objects.requireNonNull(bootstrapMethod);
+        this.bootstrapMethod = (ConstantMethodHandleRef) Objects.requireNonNull(bootstrapMethod);
         this.bootstrapArgs = Objects.requireNonNull(bootstrapArgs.clone());
+        if (name.length() == 0)
+            throw new IllegalArgumentException("Illegal invocation name: " + name);
     }
 
     /**
@@ -252,6 +261,11 @@
 
     @Override
     public String toString() {
-        return String.format("DynamicCallSiteRef[%s(%s) %s%s]", bootstrapMethod, Arrays.toString(bootstrapArgs), name, type);
+        return String.format("DynamicCallSiteRef[%s::%s(%s%s):%s]",
+                             bootstrapMethod.owner().simpleName(),
+                             bootstrapMethod.methodName(),
+                             name.equals("_") ? "" : name + "/",
+                             Stream.of(bootstrapArgs).map(Object::toString).collect(joining(",")),
+                             type.simpleDescriptor());
     }
 }