changeset 13578:8ee20a905c42 nestmates

8187360: [Nestmates] Remove invokespecial changes Summary: revert invokespecial changes no longer needed Reviewed-by: mcicamadore
author dholmes
date Mon, 11 Sep 2017 23:44:23 -0400
parents e583bb68cacb
children 2dfe246179c0
files src/share/vm/classfile/verificationType.cpp src/share/vm/classfile/verificationType.hpp src/share/vm/classfile/verifier.cpp
diffstat 3 files changed, 6 insertions(+), 106 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/classfile/verificationType.cpp	Thu Sep 07 01:09:20 2017 -0400
+++ b/src/share/vm/classfile/verificationType.cpp	Mon Sep 11 23:44:23 2017 -0400
@@ -141,31 +141,6 @@
   }
 }
 
-bool VerificationType::is_nestmate_of(InstanceKlass* cur, TRAPS) const {
-  // cur is the current class being verified
-  // 'this' represents the target class for the bytecode e.g. invokespecial
-  if (is_object()) {
-    // target class may not have been loaded so we have to be prepared to do 
-    // that here and allow for possible exceptions
-    Klass* target = 
-        SystemDictionary::resolve_or_fail(name(),
-                                          Handle(THREAD, cur->class_loader()),
-                                          Handle(THREAD, cur->protection_domain()),
-                                          true,
-                                          CHECK_false);
-    if (log_is_enabled(Info, class, resolve)) {
-      Verifier::trace_class_resolution(target, cur);
-    }
-    assert(target->is_instance_klass(), "is_object() but not instance class??");
-    //ResourceMark rm(THREAD);
-    //    tty->print_cr(" Verification: checking %s->%s", cur->name()->as_C_string(), target->name()->as_C_string());
-    bool res = cur->has_nestmate_access_to(InstanceKlass::cast(target), THREAD);
-    //tty->print_cr(" - result: %s", res ? "true" : "false");
-    return res;
-  } 
-  return false;
-}
-
 void VerificationType::print_on(outputStream* st) const {
   switch (_u._data) {
     case Bogus:            st->print("top"); break;
--- a/src/share/vm/classfile/verificationType.hpp	Thu Sep 07 01:09:20 2017 -0400
+++ b/src/share/vm/classfile/verificationType.hpp	Mon Sep 11 23:44:23 2017 -0400
@@ -327,10 +327,6 @@
     return index;
   }
 
-  // checks if the class represented by 'this' is a nestmate of the
-  // cur class being verified
-  bool is_nestmate_of(InstanceKlass* cur, TRAPS) const;
-
   void print_on(outputStream* st) const;
 
  private:
--- a/src/share/vm/classfile/verifier.cpp	Thu Sep 07 01:09:20 2017 -0400
+++ b/src/share/vm/classfile/verifier.cpp	Mon Sep 11 23:44:23 2017 -0400
@@ -2776,10 +2776,6 @@
     }
   }
 
-  // need to track if invokespecial is related to a nestmate access
-  bool nestmate_access = false;
-  bool nestmates_checked = false;
-
   if (method_name->byte_at(0) == '<') {
     // Make sure <init> can only be invoked by invokespecial
     if (opcode != Bytecodes::_invokespecial ||
@@ -2788,69 +2784,6 @@
           "Illegal call to internal method");
       return;
     }
-  } else if (UseNewCode && opcode == Bytecodes::_invokespecial) {
-    bool same_or_direct_interface = is_same_or_direct_interface(current_class(), current_type(), ref_class_type);
-    bool is_super_class = ref_class_type.equals(VerificationType::reference_type(current_class()->super()->name()));
-
-    // We can pass these initial set of verification checks when dealing with nestmates that are
-    // in the same type hierarchy, only to fail later when we finally apply the 4.9.2 check that
-    // the objectref on the operand stack is assignable to the current class. So we need to perform
-    // that check early and if it would fail then do a nestmate check. Then below we skip the
-    // operand check when we pop the stack. Unfortunately in the failing case we perform the check
-    // a second time to trigger the failure. This also means that we are forced to do the nestmate
-    // access check early, instead of using it is a last resort when all other checks have failed.
-
-    // If we don't skip anonymous classes here things break very badly
-    if (!current_class()->is_anonymous()) {
-      VerificationType top = current_frame->stack_at(current_frame->stack_size() - nargs - 1);
-      bool is_assignable = current_type().is_assignable_from(top, this, false, CHECK_VERIFY(this));
-      if (!is_assignable) {
-        nestmate_access = ref_class_type.is_nestmate_of(current_class(), CHECK_VERIFY(this));
-        nestmates_checked = true;
-      }
-    }
-
-    if (!same_or_direct_interface && !is_super_class) {
-      bool subtype = false;
-      bool have_imr_indirect = cp->tag_at(index).value() == JVM_CONSTANT_InterfaceMethodref;
-      if (!current_class()->is_anonymous()) {
-        subtype = ref_class_type.is_assignable_from(current_type(), this, false, CHECK_VERIFY(this));
-      } else {
-        VerificationType host_klass_type =
-            VerificationType::reference_type(current_class()->host_klass()->name());
-        subtype = ref_class_type.is_assignable_from(host_klass_type, this, false, CHECK_VERIFY(this));
-
-        // If invokespecial of IMR, need to recheck for same or
-        // direct interface relative to the host class
-        have_imr_indirect = (have_imr_indirect &&
-                             !is_same_or_direct_interface(current_class()->host_klass(),
-                                                          host_klass_type, ref_class_type));
-      }
-
-      if ((!subtype  || have_imr_indirect) && !nestmates_checked) {
-        // invokespecial may still be legitimate if current class and reference class
-        // are nestmates. But in that case we also have to check that the method being
-        // invoked is defined in the reference class. However that is deferred to runtime
-        // as we don't have the information available here.
-        nestmate_access = ref_class_type.is_nestmate_of(current_class(), CHECK_VERIFY(this));
-        nestmates_checked = true;
-      }
-
-      // report any definite verification failures
-      if (!nestmate_access) {
-        if (!subtype) {
-          verify_error(ErrorContext::bad_code(bci),
-                       "Bad invokespecial instruction: "
-                       "current class isn't assignable to reference class.");
-          return;
-        } else if (have_imr_indirect) {
-          verify_error(ErrorContext::bad_code(bci),
-                       "Bad invokespecial instruction: "
-                       "interface method reference is in an indirect superinterface.");
-          return;
-        }
-      }
-    }
   } else if (opcode == Bytecodes::_invokespecial
              && !is_same_or_direct_interface(current_class(), current_type(), ref_class_type)
              && !ref_class_type.equals(VerificationType::reference_type(current_class()->super()->name()))) {
@@ -2895,13 +2828,9 @@
         CHECK_VERIFY(this));
       if (was_recursively_verified()) return;
     } else {   // other methods
-      // Ensures that target class is assignable to current class (4.9.2),
-      // unless performing a nestmate access
+      // Ensures that target class is assignable to current class (4.9.2)
       if (opcode == Bytecodes::_invokespecial) {
-        if (UseNewCode && nestmate_access) {
-          VerificationType top = current_frame->pop_stack(CHECK_VERIFY(this));
-        }
-        else if (!current_class()->is_anonymous()) {
+        if (!current_class()->is_anonymous()) {
           current_frame->pop_stack(current_type(), CHECK_VERIFY(this));
         } else {
           // anonymous class invokespecial calls: check if the
@@ -2912,10 +2841,10 @@
             VerificationType::reference_type(current_class()->host_klass()->name());
           bool subtype = hosttype.is_assignable_from(top, this, false, CHECK_VERIFY(this));
           if (!subtype) {
-            verify_error( ErrorContext::bad_type(current_frame->offset(),
-              current_frame->stack_top_ctx(),
-              TypeOrigin::implicit(top)),
-              "Bad type on operand stack");
+            verify_error(ErrorContext::bad_type(current_frame->offset(),
+                                                current_frame->stack_top_ctx(),
+                                                TypeOrigin::implicit(top)),
+                         "Bad type on operand stack");
             return;
           }
         }