8183962: JVM_DoPrivileged does not find run method in default methods
authorhseigel
Thu, 13 Jul 2017 08:49:09 -0400
changeset 46660 d19370887e09
parent 46659 2a4cca319443
child 46662 396785d39b69
8183962: JVM_DoPrivileged does not find run method in default methods Summary: Add search of interfaces for run() method. Reviewed-by: acorn, gtriantafill
hotspot/src/share/vm/prims/jvm.cpp
hotspot/test/runtime/JVMDoPrivileged/DoPrivRunAbstract$VoidPrivActRunAbstract.jasm
hotspot/test/runtime/JVMDoPrivileged/DoPrivRunAbstract.jasm
hotspot/test/runtime/JVMDoPrivileged/DoPrivileged.java
--- a/hotspot/src/share/vm/prims/jvm.cpp	Thu Jul 13 01:28:24 2017 +0000
+++ b/hotspot/src/share/vm/prims/jvm.cpp	Thu Jul 13 08:49:09 2017 -0400
@@ -1264,8 +1264,17 @@
                                            vmSymbols::run_method_name(),
                                            vmSymbols::void_object_signature(),
                                            Klass::find_overpass);
+
+  // See if there is a default method for "Object run()".
+  if (m_oop == NULL && object->klass()->is_instance_klass()) {
+    InstanceKlass* iklass = InstanceKlass::cast(object->klass());
+    m_oop = iklass->lookup_method_in_ordered_interfaces(
+                                           vmSymbols::run_method_name(),
+                                           vmSymbols::void_object_signature());
+  }
+
   methodHandle m (THREAD, m_oop);
-  if (m.is_null() || !m->is_method() || !m()->is_public() || m()->is_static()) {
+  if (m.is_null() || !m->is_method() || !m()->is_public() || m()->is_static() || m()->is_abstract()) {
     THROW_MSG_0(vmSymbols::java_lang_InternalError(), "No run method");
   }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/runtime/JVMDoPrivileged/DoPrivRunAbstract$VoidPrivActRunAbstract.jasm	Thu Jul 13 08:49:09 2017 -0400
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2017, 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.
+ *
+ * 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.
+ */
+
+interface  DoPrivRunAbstract$VoidPrivActRunAbstract
+    implements java/security/PrivilegedAction version 51:0 {
+
+    public abstract Method perform:"()V";
+    public abstract Method run:"()Ljava/lang/Void;";
+
+} // end Class DoPrivRunAbstract$VoidPrivActRunAbstract
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/runtime/JVMDoPrivileged/DoPrivRunAbstract.jasm	Thu Jul 13 08:49:09 2017 -0400
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2017, 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.
+ *
+ * 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.
+ */
+
+/*
+ * @test
+ * @summary Test that JVM_DoPrivilege throws java.lang.InternalError for an
+ *          abstract run() method.
+ * @bug 8183962
+ * @compile DoPrivRunAbstract.jasm
+ * @compile DoPrivRunAbstract$VoidPrivActRunAbstract.jasm
+ * @run main DoPrivRunAbstract
+ */
+
+
+// This jasm file was generated from Java code similar to the following, except
+// the VoidPrivActRunAbstract interface was removed and changed.  It's now in
+// file DoPrivRunAbstract$VoidPrivActRunAbstract.jasm.
+//
+// public class DoPrivRunAbstract {
+//
+//    interface VoidPrivActRunAbstract extends PrivilegedAction<Void> {
+//        void perform();
+//
+//        @Override
+//        default Void run() {
+//            perform();
+//            return null;
+//        }
+//    }
+//
+//
+//    static void doPrivileged(VoidPrivActRunAbstract act) {
+//        AccessController.doPrivileged(act);
+//    }
+//
+//    public static void main(String[] args) throws Exception {
+//        try {
+//            doPrivileged(() -> System.out.println(System.getProperty("java.home")));
+//            throw new RuntimeException("Expected InternalError not throw");
+//        } catch (java.lang.InternalError e) { }
+//    }
+//}
+
+super public class DoPrivRunAbstract version 51:0 {
+
+    public Method "<init>":"()V" stack 1 locals 1 {
+        aload_0;
+        invokespecial    Method java/lang/Object."<init>":"()V";
+        return;
+    }
+
+    static Method doPrivileged:"(LDoPrivRunAbstract$VoidPrivActRunAbstract;)V" stack 1 locals 1 {
+        aload_0;
+        invokestatic    Method java/security/AccessController.doPrivileged:"(Ljava/security/PrivilegedAction;)Ljava/lang/Object;";
+        pop;
+        return;
+    }
+
+    public static Method main:"([Ljava/lang/String;)V" throws java/lang/Exception stack 3 locals 2 {
+        try t0;
+        invokedynamic    InvokeDynamic REF_invokeStatic:java/lang/invoke/LambdaMetafactory.metafactory:"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;":perform:"()LDoPrivRunAbstract$VoidPrivActRunAbstract;" MethodType "()V", MethodHandle REF_invokeStatic:DoPrivRunAbstract.lambda$main$0:"()V", MethodType "()V";
+        invokestatic    Method doPrivileged:"(LDoPrivRunAbstract$VoidPrivActRunAbstract;)V";
+        new    class java/lang/RuntimeException;
+        dup;
+        ldc    String "Expected InternalError not throw";
+        invokespecial    Method java/lang/RuntimeException."<init>":"(Ljava/lang/String;)V";
+        athrow;
+        endtry t0;
+        catch t0 java/lang/InternalError;
+        stack_frame_type stack1;
+        stack_map class java/lang/InternalError;
+        astore_1;
+        return;
+    }
+
+    private static synthetic Method lambda$main$0:"()V" stack 2 locals 0 {
+        getstatic    Field java/lang/System.out:"Ljava/io/PrintStream;";
+        ldc    String "java.home";
+        invokestatic    Method java/lang/System.getProperty:"(Ljava/lang/String;)Ljava/lang/String;";
+        invokevirtual    Method java/io/PrintStream.println:"(Ljava/lang/String;)V";
+        return;
+    }
+
+} // end Class DoPrivRunAbstract
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/runtime/JVMDoPrivileged/DoPrivileged.java	Thu Jul 13 08:49:09 2017 -0400
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2017, 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.
+ *
+ * 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.
+ */
+
+/*
+ * @test
+ * @summary Test that JVM_DoPrivilege() searches default methods when looking
+ *          for the run() method.
+ * @bug 8183962
+ * @run main DoPrivileged
+ */
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+public class DoPrivileged {
+    interface VoidPrivilegedAction extends PrivilegedAction<Void> {
+        void perform();
+
+        @Override
+        default Void run() {
+            perform();
+            return null;
+        }
+    }
+
+    static void doPrivileged(VoidPrivilegedAction act) {
+        AccessController.doPrivileged(act);
+    }
+
+    public static void main(String[] args) throws Exception {
+        doPrivileged(() -> System.out.println(System.getProperty("java.home")));
+    }
+}