changeset 14059:1be991c83c66

Interpreter: add (failling) test case for reflection
author briangoetz
date Fri, 10 Jun 2016 21:54:20 -0400
parents c6766c447aac
children 6bfe9ce6659d
files interpreter/src/valhalla/interpreter/ClassModel.java interpreter/src/valhalla/interpreter/InternalHelpers.java interpreter/src/valhalla/interpreter/Interpreter.java interpreter/test-helpers/test/valhalla/interpreter/AnnoHelper.java interpreter/test/valhalla/interpreter/InterpreterTest.java
diffstat 5 files changed, 55 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/interpreter/src/valhalla/interpreter/ClassModel.java	Fri Jun 10 17:49:08 2016 -0700
+++ b/interpreter/src/valhalla/interpreter/ClassModel.java	Fri Jun 10 21:54:20 2016 -0400
@@ -90,5 +90,10 @@
             this.name = name;
             this.desc = desc;
         }
+
+        @Override
+        public String toString() {
+            return String.format("MethodHandleDesc[%s.%s:%s(%d)]", owner, name, desc, refKind);
+        }
     }
 }
--- a/interpreter/src/valhalla/interpreter/InternalHelpers.java	Fri Jun 10 17:49:08 2016 -0700
+++ b/interpreter/src/valhalla/interpreter/InternalHelpers.java	Fri Jun 10 21:54:20 2016 -0400
@@ -80,7 +80,7 @@
             return LOOKUP.findSpecial(dynamicReceiver, mhi.getName(), mhi.getMethodType(), dynamicReceiver);
         }
         catch (Throwable ex) {
-            throw new InterpreterError(ex);
+            throw new InterpreterError(String.format("error converting %s to special for %s", mhi, dynamicReceiver.getName()), ex);
         }
     }
 
--- a/interpreter/src/valhalla/interpreter/Interpreter.java	Fri Jun 10 17:49:08 2016 -0700
+++ b/interpreter/src/valhalla/interpreter/Interpreter.java	Fri Jun 10 21:54:20 2016 -0400
@@ -142,8 +142,8 @@
                 return MethodType.fromMethodDescriptorString(f.curClass().cpMethodType(index), f.curClassLoader());
 
             case CONSTANT_MethodHandle:
+                ClassModel.MethodHandleDesc mh = f.curClass().cpMethodHandle(index);
                 try {
-                    ClassModel.MethodHandleDesc mh = f.curClass().cpMethodHandle(index);
                     switch (mh.refKind) {
                         case REF_invokeStatic:
                             return f.getLookup()
@@ -165,7 +165,7 @@
                     }
                 }
                 catch (NoSuchMethodException | IllegalAccessException e) {
-                    throw new InterpreterError(f, e);
+                    throw new InterpreterError(f, "lookup error on " + mh, e);
                 }
 
             default:
@@ -418,7 +418,7 @@
         }
         catch (ClassNotFoundException e) {
             // FIXME: emulate linkage error instead of throwing interpreter exception
-            throw new InterpreterError(f, e);
+            throw new InterpreterError(f, "cannot find class " + name, e);
         }
     }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/interpreter/test-helpers/test/valhalla/interpreter/AnnoHelper.java	Fri Jun 10 21:54:20 2016 -0400
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package valhalla.interpreter;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+
+/**
+ * AnnoHelper
+ *
+ * @author Brian Goetz
+ */
+public class AnnoHelper {
+    public static void testAnno() throws NoSuchMethodException, ClassNotFoundException {
+        Class clazz = Class.forName("java.lang.annotation.Repeatable").asSubclass(Annotation.class);
+        clazz.getMethod("value");
+    }
+}
--- a/interpreter/test/valhalla/interpreter/InterpreterTest.java	Fri Jun 10 17:49:08 2016 -0700
+++ b/interpreter/test/valhalla/interpreter/InterpreterTest.java	Fri Jun 10 21:54:20 2016 -0400
@@ -44,6 +44,7 @@
     public static final String HELPER_4 = "valhalla/interpreter/InterpreterTestHelper4";
     public static final String STATIC_HELPER = "valhalla/interpreter/StaticInitTestHelper";
     public static final String CONSTRUCTOR_HELPER = "valhalla/interpreter/ConstructorTestHelper";
+    public static final String ANNO_HELPER = "valhalla/interpreter/AnnoHelper";
 
     /** Test that a static initializer actually gets run, with final and nonfinal fields */
     public void testStaticInit() throws Throwable {
@@ -262,6 +263,11 @@
         f = ic.getDeclaredField("y"); f.setAccessible(true);
         assertEquals(f.get(arr[0]), 9);
     }
+
+    public void testAnno() throws Throwable {
+        interpreter.TRACING = true;
+        interpreter.invokestatic(ANNO_HELPER, "testAnno", "()V");
+    }
 }