changeset 47599:98e960939ef2

8180711: Better invokespecial checks Reviewed-by: acorn, ahgross, rhalade Contributed-by: harold.seigel@oracle.com
author hseigel
date Wed, 26 Jul 2017 11:45:53 -0400
parents f1721aa42d2c
children fd5d1d2bc1d4
files src/hotspot/share/interpreter/linkResolver.cpp src/hotspot/share/interpreter/linkResolver.hpp
diffstat 2 files changed, 14 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/interpreter/linkResolver.cpp	Fri May 19 11:18:49 2017 +0100
+++ b/src/hotspot/share/interpreter/linkResolver.cpp	Wed Jul 26 11:45:53 2017 -0400
@@ -1074,11 +1074,7 @@
                                         const LinkInfo& link_info,
                                         TRAPS) {
   methodHandle resolved_method = linktime_resolve_special_method(link_info, CHECK);
-  runtime_resolve_special_method(result, resolved_method,
-                                 link_info.resolved_klass(),
-                                 link_info.current_klass(),
-                                 recv,
-                                 link_info.check_access(), CHECK);
+  runtime_resolve_special_method(result, link_info, resolved_method, recv, CHECK);
 }
 
 // throws linktime exceptions
@@ -1162,11 +1158,11 @@
 
 // throws runtime exceptions
 void LinkResolver::runtime_resolve_special_method(CallInfo& result,
+                                                  const LinkInfo& link_info,
                                                   const methodHandle& resolved_method,
-                                                  Klass* resolved_klass,
-                                                  Klass* current_klass,
-                                                  Handle recv,
-                                                  bool check_access, TRAPS) {
+                                                  Handle recv, TRAPS) {
+
+  Klass* resolved_klass = link_info.resolved_klass();
 
   // resolved method is selected method unless we have an old-style lookup
   // for a superclass method
@@ -1174,12 +1170,13 @@
   // no checks for shadowing
   methodHandle sel_method(THREAD, resolved_method());
 
-  if (check_access &&
+  if (link_info.check_access() &&
       // check if the method is not <init>
       resolved_method->name() != vmSymbols::object_initializer_name()) {
 
-  // check if this is an old-style super call and do a new lookup if so
+     // check if this is an old-style super call and do a new lookup if so
         // a) check if ACC_SUPER flag is set for the current class
+    Klass* current_klass = link_info.current_klass();
     if ((current_klass->is_super() || !AllowNonVirtualCalls) &&
         // b) check if the class of the resolved_klass is a superclass
         // (not supertype in order to exclude interface classes) of the current class.
@@ -1199,6 +1196,9 @@
                   Method::name_and_sig_as_C_string(resolved_klass,
                                             resolved_method->name(),
                                             resolved_method->signature()));
+      // check loader constraints if found a different method
+      } else if (sel_method() != resolved_method()) {
+        check_method_loader_constraints(link_info, sel_method, "method", CHECK);
       }
     }
 
--- a/src/hotspot/share/interpreter/linkResolver.hpp	Fri May 19 11:18:49 2017 +0100
+++ b/src/hotspot/share/interpreter/linkResolver.hpp	Wed Jul 26 11:45:53 2017 -0400
@@ -233,11 +233,10 @@
   static methodHandle linktime_resolve_interface_method (const LinkInfo& link_info, TRAPS);
 
   static void runtime_resolve_special_method    (CallInfo& result,
+                                                 const LinkInfo& link_info,
                                                  const methodHandle& resolved_method,
-                                                 Klass* resolved_klass,
-                                                 Klass* current_klass,
-                                                 Handle recv,
-                                                 bool check_access, TRAPS);
+                                                 Handle recv, TRAPS);
+
   static void runtime_resolve_virtual_method    (CallInfo& result,
                                                  const methodHandle& resolved_method,
                                                  Klass* resolved_klass,