changeset 14052:1ba172980186

Bugfix: use interpreter class loader instead of default when converting method descriptor strings into MethodType. Failing tests: 1.
author briangoetz
date Thu, 09 Jun 2016 17:04:53 -0400
parents 01f5c9ebab50
children f9072be260c9
files interpreter/src/valhalla/interpreter/Frame.java interpreter/src/valhalla/interpreter/Interpreter.java interpreter/src/valhalla/interpreter/StandardInterpreter.java interpreter/test-helpers/test/valhalla/interpreter/InterpreterTestHelper3.java
diffstat 4 files changed, 24 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/interpreter/src/valhalla/interpreter/Frame.java	Thu Jun 09 15:34:24 2016 -0400
+++ b/interpreter/src/valhalla/interpreter/Frame.java	Thu Jun 09 17:04:53 2016 -0400
@@ -462,6 +462,10 @@
         return clazz.cpMemberRef(read16u(offset));
     }
 
+    public ClassLoader curClassLoader() {
+        return curClass().interpreter().classLoader;
+    }
+
     public Insn curInsn() {
         return insn;
     }
--- a/interpreter/src/valhalla/interpreter/Interpreter.java	Thu Jun 09 15:34:24 2016 -0400
+++ b/interpreter/src/valhalla/interpreter/Interpreter.java	Thu Jun 09 17:04:53 2016 -0400
@@ -24,6 +24,7 @@
  */
 package valhalla.interpreter;
 
+import com.sun.tools.classfile.Opcode;
 import jdk.internal.org.objectweb.asm.Opcodes;
 import jdk.internal.org.objectweb.asm.Type;
 import sun.misc.Resource;
@@ -84,6 +85,8 @@
 
     public abstract ClassModel newClassModel(String binaryName, byte[] bytes);
 
+    public abstract String opcodeToString(int opcode);
+
     public void setEventFilter(Set<InterpreterEvent.Kind> eventFilter) {
         this.eventFilter = eventFilter;
     }
@@ -117,7 +120,7 @@
                 return toClass(f, f.curClass().cpClass(index));
 
             case CONSTANT_MethodType:
-                return MethodType.fromMethodDescriptorString(f.curClass().cpMethodType(index), null);
+                return MethodType.fromMethodDescriptorString(f.curClass().cpMethodType(index), f.curClassLoader());
 
             case CONSTANT_MethodHandle:
                 try {
@@ -126,17 +129,17 @@
                         case REF_invokeStatic:
                             return f.getLookup()
                                     .findStatic(toClass(f, mh.owner), mh.name,
-                                                MethodType.fromMethodDescriptorString(mh.desc, null));
+                                                MethodType.fromMethodDescriptorString(mh.desc, f.curClassLoader()));
                         case REF_invokeVirtual:
                         case REF_invokeInterface:
                             return f.getLookup()
                                     .findVirtual(toClass(f, mh.owner), mh.name,
-                                                 MethodType.fromMethodDescriptorString(mh.desc, null));
+                                                 MethodType.fromMethodDescriptorString(mh.desc, f.curClassLoader()));
 
                         case REF_invokeSpecial:
                             return f.getLookup()
                                     .findSpecial(toClass(f, mh.owner), mh.name,
-                                                 MethodType.fromMethodDescriptorString(mh.desc, null),
+                                                 MethodType.fromMethodDescriptorString(mh.desc, f.curClassLoader()),
                                                  f.curClass().getRepresentationClass());
                         default:
                             throw new InterpreterError("Unknown refkind: " + mh.refKind);
@@ -284,20 +287,20 @@
 
     protected HandlerAction fieldOp(Frame f) throws InterpreterError {
         ClassModel.MemberDesc ref = f.readMemberRef(1);
-        Class type = MethodType.fromMethodDescriptorString("()" + ref.desc, null).returnType();
+        Class type = MethodType.fromMethodDescriptorString("()" + ref.desc, f.curClassLoader()).returnType();
         return memberOp(f, toClass(f, ref.owner), ref.name, type);
     }
 
     protected HandlerAction invokeOp(Frame f) throws InterpreterError {
         ClassModel.MemberDesc ref = f.readMemberRef(1);
-        MethodType methodType = MethodType.fromMethodDescriptorString(ref.desc, null);
+        MethodType methodType = MethodType.fromMethodDescriptorString(ref.desc, f.curClassLoader());
         return memberOp(f, toClass(f, ref.owner), ref.name, methodType);
     }
 
     protected HandlerAction invokeDynamicOp(Frame f) throws InterpreterError {
         Insn insn = f.curInsn();
         CallSite cs = linkIndySite(f, insn);
-        assert(cs.getTarget().type().equals(MethodType.fromMethodDescriptorString(f.curClass().cpIndy(f.read16u(1)).invokeDesc, null)));
+        assert(cs.getTarget().type().equals(MethodType.fromMethodDescriptorString(f.curClass().cpIndy(f.read16u(1)).invokeDesc, f.curClassLoader())));
         if (cs instanceof FailedCallSite)
             return exception(((FailedCallSite) cs).exception);
         return finishInvokeOp(f, cs.getTarget().asFixedArity());
@@ -309,7 +312,7 @@
 
         if (cs == null) {
             ClassModel.IndyDesc indy = f.curClass().cpIndy(index);
-            MethodType methodType = MethodType.fromMethodDescriptorString(indy.invokeDesc, null);
+            MethodType methodType = MethodType.fromMethodDescriptorString(indy.invokeDesc, f.curClassLoader());
             MethodHandle bsm = (MethodHandle) loadConstant(f, indy.bootstrapCPIndex);
             int[] bsmArgs = indy.bootstrapArgCPIndexes;
             Object[] args = new Object[bsmArgs.length + 3];
@@ -529,7 +532,7 @@
                 if (handler == null)
                     throw new InterpreterError(f, "No handler for opcode " + insn);
                 if (TRACING)
-                    System.out.printf("bci=%d: %s%n", f.curBCI(), f.curInsn());
+                    System.out.printf("%s[bci=%d]: opcode=%d (%s) %n", f.curMethod().getName(), f.curBCI(), f.curOpcode(), opcodeToString(f.curOpcode()));
 
                 HandlerAction a = handler.handle(f);
                 switch (a.actionKind) {
@@ -613,7 +616,7 @@
 
         Lookup lookup = InternalHelpers.makeFullPowerLookup(cm.getRepresentationClass());
         MethodHandle method = linkMemberAccess(lookup, opcode, cm.getRepresentationClass(), name,
-                                               MethodType.fromMethodDescriptorString(desc, null));
+                                               MethodType.fromMethodDescriptorString(desc, classLoader));
         return interpretOrExecute(new Frame(lookup), method, args).getReturnValueOrThrow();
     }
 
--- a/interpreter/src/valhalla/interpreter/StandardInterpreter.java	Thu Jun 09 15:34:24 2016 -0400
+++ b/interpreter/src/valhalla/interpreter/StandardInterpreter.java	Thu Jun 09 17:04:53 2016 -0400
@@ -81,6 +81,11 @@
         return StandardClassModel.interpreted(this, binaryName, bytes);
     }
 
+    @Override
+    public String opcodeToString(int opcode) {
+        return Opcode.get(opcode).name();
+    }
+
     private void opcode(int opcode, OpcodeHandler handler) {
         opcode(opcode, 0, handler);
     }
--- a/interpreter/test-helpers/test/valhalla/interpreter/InterpreterTestHelper3.java	Thu Jun 09 15:34:24 2016 -0400
+++ b/interpreter/test-helpers/test/valhalla/interpreter/InterpreterTestHelper3.java	Thu Jun 09 17:04:53 2016 -0400
@@ -46,7 +46,8 @@
     }
 
     static String instanceLambda() {
-        return new InterpreterTestHelper3().instanceLambdaHelper();
+        InterpreterTestHelper3 instance = new InterpreterTestHelper3();
+        return instance.instanceLambdaHelper();
     }
 
     private String instanceLambdaHelper() {