changeset 12280:0baa3226c993

8169331: [JVMCI] incomplete API to MethodParameters attribute Reviewed-by: kvn
author dnsimon
date Mon, 07 Nov 2016 17:02:46 +0100
parents f02245c92146
children a169535aff9d
files src/jdk.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedJavaMethodImpl.java src/jdk.vm.ci/share/classes/jdk.vm.ci.meta/src/jdk/vm/ci/meta/ResolvedJavaMethod.java test/compiler/jvmci/jdk.vm.ci.runtime.test/src/jdk/vm/ci/runtime/test/TestResolvedJavaMethod.java
diffstat 3 files changed, 31 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedJavaMethodImpl.java	Fri Oct 28 15:50:09 2016 +0200
+++ b/src/jdk.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedJavaMethodImpl.java	Mon Nov 07 17:02:46 2016 +0100
@@ -472,7 +472,8 @@
         Parameter[] res = new Parameter[javaParameters.length];
         for (int i = 0; i < res.length; i++) {
             java.lang.reflect.Parameter src = javaParameters[i];
-            res[i] = new Parameter(src.getName(), src.getModifiers(), this, i);
+            String paramName = src.isNamePresent() ? src.getName() : null;
+            res[i] = new Parameter(paramName, src.getModifiers(), this, i);
         }
         return res;
     }
--- a/src/jdk.vm.ci/share/classes/jdk.vm.ci.meta/src/jdk/vm/ci/meta/ResolvedJavaMethod.java	Fri Oct 28 15:50:09 2016 +0200
+++ b/src/jdk.vm.ci/share/classes/jdk.vm.ci.meta/src/jdk/vm/ci/meta/ResolvedJavaMethod.java	Mon Nov 07 17:02:46 2016 +0100
@@ -177,7 +177,7 @@
     /**
      * A {@code Parameter} provides information about method parameters.
      */
-    public static class Parameter implements AnnotatedElement {
+    class Parameter implements AnnotatedElement {
         private final String name;
         private final ResolvedJavaMethod method;
         private final int modifiers;
@@ -186,7 +186,9 @@
         /**
          * Constructor for {@code Parameter}.
          *
-         * @param name the name of the parameter
+         * @param name the name of the parameter or {@code null} if there is no
+         *            {@literal MethodParameters} class file attribute providing a non-empty name
+         *            for the parameter
          * @param modifiers the modifier flags for the parameter
          * @param method the method which defines this parameter
          * @param index the index of the parameter
@@ -195,6 +197,7 @@
                         int modifiers,
                         ResolvedJavaMethod method,
                         int index) {
+            assert name == null || !name.isEmpty();
             this.name = name;
             this.modifiers = modifiers;
             this.method = method;
@@ -202,10 +205,20 @@
         }
 
         /**
-         * Gets the name of the parameter.
+         * Gets the name of the parameter. If the parameter's name is {@linkplain #isNamePresent()
+         * present}, then this method returns the name provided by the class file. Otherwise, this
+         * method synthesizes a name of the form argN, where N is the index of the parameter in the
+         * descriptor of the method which declares the parameter.
+         *
+         * @return the name of the parameter, either provided by the class file or synthesized if
+         *         the class file does not provide a name
          */
         public String getName() {
-            return name;
+            if (name == null) {
+                return "arg" + index;
+            } else {
+                return name;
+            }
         }
 
         /**
@@ -216,7 +229,7 @@
         }
 
         /**
-         * Get the modifier flags for the parameter
+         * Get the modifier flags for the parameter.
          */
         public int getModifiers() {
             return modifiers;
@@ -244,6 +257,16 @@
         }
 
         /**
+         * Determines if the parameter has a name according to a {@literal MethodParameters} class
+         * file attribute.
+         *
+         * @return true if and only if the parameter has a name according to the class file.
+         */
+        public boolean isNamePresent() {
+            return name != null;
+        }
+
+        /**
          * Determines if the parameter represents a variable argument list.
          */
         public boolean isVarArgs() {
--- a/test/compiler/jvmci/jdk.vm.ci.runtime.test/src/jdk/vm/ci/runtime/test/TestResolvedJavaMethod.java	Fri Oct 28 15:50:09 2016 +0200
+++ b/test/compiler/jvmci/jdk.vm.ci.runtime.test/src/jdk/vm/ci/runtime/test/TestResolvedJavaMethod.java	Mon Nov 07 17:02:46 2016 +0100
@@ -278,7 +278,7 @@
                 java.lang.reflect.Parameter exp = expected[i];
                 Parameter act = actual[i];
                 assertEquals(exp.getName(), act.getName());
-                assertEquals(exp.getModifiers(), act.getModifiers());
+                assertEquals(exp.isNamePresent(), act.isNamePresent());
                 assertEquals(exp.getModifiers(), act.getModifiers());
                 assertArrayEquals(exp.getAnnotations(), act.getAnnotations());
                 assertEquals(exp.getType().getName(), act.getType().toClassName());