changeset 14060:6bfe9ce6659d

Interpreter: better processing of caller sensitive and varargs MHs
author jrose
date Sat, 11 Jun 2016 00:06:11 -0700
parents 1be991c83c66
children 04b3b59f601e
files interpreter/src/valhalla/interpreter/InternalHelpers.java interpreter/src/valhalla/interpreter/Interpreter.java
diffstat 2 files changed, 12 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/interpreter/src/valhalla/interpreter/InternalHelpers.java	Fri Jun 10 21:54:20 2016 -0400
+++ b/interpreter/src/valhalla/interpreter/InternalHelpers.java	Sat Jun 11 00:06:11 2016 -0700
@@ -63,7 +63,13 @@
     }
 
     public static MethodHandleInfo crackMethodHandle(MethodHandle mh) {
-        return LOOKUP.revealDirect(mh);
+        MethodHandleInfo mhi = LOOKUP.revealDirect(mh);
+        try {
+            return LOOKUP.in(mhi.getDeclaringClass()).revealDirect(mh);
+        } catch (IllegalArgumentException ex) {
+            // this happens if mh is caller sensitive; FIXME: make a more direct test for mh.isCS
+            return null;
+        }
     }
 
     static MethodHandles.Lookup makeFullPowerLookup(Class<?> clazz) {
--- a/interpreter/src/valhalla/interpreter/Interpreter.java	Fri Jun 10 21:54:20 2016 -0400
+++ b/interpreter/src/valhalla/interpreter/Interpreter.java	Sat Jun 11 00:06:11 2016 -0700
@@ -232,7 +232,7 @@
         String debugInfo = "";
         try {
             mhi = InternalHelpers.crackMethodHandle(resolved);  // privileged cracking to get bytecodes
-            switch (mhi.getReferenceKind()) {
+            switch (mhi == null ? -1 : mhi.getReferenceKind()) {
                 case H_INVOKESTATIC:
                 case H_INVOKESPECIAL:
                     interpretable = true;
@@ -244,6 +244,7 @@
                     selected = tryMethodSelection(mhi, args[0].getClass());
                     if (selected != null) {
                         mhi = InternalHelpers.crackMethodHandle(selected);
+                        if (mhi == null) { selected = null; break; }
                         // method selection should not select an abstract method
                         assert((mhi.getModifiers() & Opcodes.ACC_ABSTRACT) == 0);
                     }
@@ -254,14 +255,15 @@
 
                 default:
                     // do not crack this kind of MH; it has no bytecodes
-                    debugInfo = mhi.toString();
+                    if (mhi != null)
+                        debugInfo = mhi.toString();
                     mhi = null;
                     break;
             }
         } catch (IllegalArgumentException ex) {
             // this can happen if selected MH if the target of an indy call site
         }
-        MethodHandle target = (selected != null) ? selected : resolved;
+        MethodHandle target = ((selected != null) ? selected : resolved).asFixedArity();
 
         if (interpretable) {
             ClassModel cm = tryLoad(mhi.getDeclaringClass().getName());