< prev index next >

src/hotspot/share/classfile/verifier.cpp

Print this page
*** 62,10 ***
--- 62,11 ---
  #include "utilities/bytes.hpp"
  
  #define NOFAILOVER_MAJOR_VERSION                       51
  #define NONZERO_PADDING_BYTES_IN_SWITCH_MAJOR_VERSION  51
  #define STATIC_METHOD_IN_INTERFACE_MAJOR_VERSION       52
+ #define INLINE_TYPE_MAJOR_VERSION                       56
  #define MAX_ARRAY_DIMENSIONS 255
  
  // Access to external entry for VerifyClassForMajorVersion - old byte code verifier
  
  extern "C" {

*** 275,11 ***
                                  klass->is_subtype_of(refl_serialization_ctor_klass);
  
    return (should_verify_for(klass->class_loader(), should_verify_class) &&
      // return if the class is a bootstrapping class
      // or defineClass specified not to verify by default (flags override passed arg)
!     // We need to skip the following four for bootstraping
      name != vmSymbols::java_lang_Object() &&
      name != vmSymbols::java_lang_Class() &&
      name != vmSymbols::java_lang_String() &&
      name != vmSymbols::java_lang_Throwable() &&
  
--- 276,11 ---
                                  klass->is_subtype_of(refl_serialization_ctor_klass);
  
    return (should_verify_for(klass->class_loader(), should_verify_class) &&
      // return if the class is a bootstrapping class
      // or defineClass specified not to verify by default (flags override passed arg)
!     // We need to skip the following four for bootstrapping
      name != vmSymbols::java_lang_Object() &&
      name != vmSymbols::java_lang_Class() &&
      name != vmSymbols::java_lang_String() &&
      name != vmSymbols::java_lang_Throwable() &&
  

*** 494,10 ***
--- 495,17 ---
        ss->print("Expected stackmap frame at this location.");
        break;
      case BAD_STACKMAP:
        ss->print("Invalid stackmap specification.");
        break;
+     case WRONG_INLINE_TYPE:
+       ss->print("Type ");
+       _type.details(ss);
+       ss->print(" and type ");
+       _expected.details(ss);
+       ss->print(" must be identical inline types.");
+       break;
      case UNKNOWN:
      default:
        ShouldNotReachHere();
        ss->print_cr("Unknown");
    }

*** 588,14 ***
    }
  }
  
  // Methods in ClassVerifier
  
  ClassVerifier::ClassVerifier(JavaThread* current, InstanceKlass* klass)
      : _thread(current), _previous_symbol(nullptr), _symbols(nullptr), _exception_type(nullptr),
        _message(nullptr), _klass(klass) {
!   _this_type = VerificationType::reference_type(klass->name());
  }
  
  ClassVerifier::~ClassVerifier() {
    // Decrement the reference count for any symbols created.
    if (_symbols != nullptr) {
--- 596,23 ---
    }
  }
  
  // Methods in ClassVerifier
  
+ VerificationType reference_or_inline_type(InstanceKlass* klass) {
+   // if (klass->is_inline_klass()) {
+   //   return VerificationType::inline_type(klass->name());
+   // } else {
+   //   return VerificationType::reference_type(klass->name());
+   // }  // LW401 CR required: verifier update/cleanup
+   return VerificationType::reference_type(klass->name());
+ }
+ 
  ClassVerifier::ClassVerifier(JavaThread* current, InstanceKlass* klass)
      : _thread(current), _previous_symbol(nullptr), _symbols(nullptr), _exception_type(nullptr),
        _message(nullptr), _klass(klass) {
!   _this_type = reference_or_inline_type(klass);
  }
  
  ClassVerifier::~ClassVerifier() {
    // Decrement the reference count for any symbols created.
    if (_symbols != nullptr) {

*** 1035,11 ***
          case Bytecodes::_aaload : {
            type = current_frame.pop_stack(
              VerificationType::integer_type(), CHECK_VERIFY(this));
            atype = current_frame.pop_stack(
              VerificationType::reference_check(), CHECK_VERIFY(this));
!           if (!atype.is_reference_array()) {
              verify_error(ErrorContext::bad_type(bci,
                  current_frame.stack_top_ctx(),
                  TypeOrigin::implicit(VerificationType::reference_check())),
                  bad_type_msg, "aaload");
              return;
--- 1052,11 ---
          case Bytecodes::_aaload : {
            type = current_frame.pop_stack(
              VerificationType::integer_type(), CHECK_VERIFY(this));
            atype = current_frame.pop_stack(
              VerificationType::reference_check(), CHECK_VERIFY(this));
!           if (!atype.is_nonscalar_array()) {
              verify_error(ErrorContext::bad_type(bci,
                  current_frame.stack_top_ctx(),
                  TypeOrigin::implicit(VerificationType::reference_check())),
                  bad_type_msg, "aaload");
              return;

*** 1213,11 ***
            type2 = current_frame.pop_stack(
              VerificationType::integer_type(), CHECK_VERIFY(this));
            atype = current_frame.pop_stack(
              VerificationType::reference_check(), CHECK_VERIFY(this));
            // more type-checking is done at runtime
!           if (!atype.is_reference_array()) {
              verify_error(ErrorContext::bad_type(bci,
                  current_frame.stack_top_ctx(),
                  TypeOrigin::implicit(VerificationType::reference_check())),
                  bad_type_msg, "aastore");
              return;
--- 1230,11 ---
            type2 = current_frame.pop_stack(
              VerificationType::integer_type(), CHECK_VERIFY(this));
            atype = current_frame.pop_stack(
              VerificationType::reference_check(), CHECK_VERIFY(this));
            // more type-checking is done at runtime
!           if (!atype.is_nonscalar_array()) {
              verify_error(ErrorContext::bad_type(bci,
                  current_frame.stack_top_ctx(),
                  TypeOrigin::implicit(VerificationType::reference_check())),
                  bad_type_msg, "aastore");
              return;

*** 1613,16 ***
              &current_frame, target, CHECK_VERIFY(this));
            no_control_flow = false; break;
          case Bytecodes::_if_acmpeq :
          case Bytecodes::_if_acmpne :
            current_frame.pop_stack(
!             VerificationType::reference_check(), CHECK_VERIFY(this));
            // fall through
          case Bytecodes::_ifnull :
          case Bytecodes::_ifnonnull :
            current_frame.pop_stack(
!             VerificationType::reference_check(), CHECK_VERIFY(this));
            target = bcs.dest();
            stackmap_table.check_jump_target
              (&current_frame, target, CHECK_VERIFY(this));
            no_control_flow = false; break;
          case Bytecodes::_goto :
--- 1630,16 ---
              &current_frame, target, CHECK_VERIFY(this));
            no_control_flow = false; break;
          case Bytecodes::_if_acmpeq :
          case Bytecodes::_if_acmpne :
            current_frame.pop_stack(
!             VerificationType::nonscalar_check(), CHECK_VERIFY(this));
            // fall through
          case Bytecodes::_ifnull :
          case Bytecodes::_ifnonnull :
            current_frame.pop_stack(
!             VerificationType::nonscalar_check(), CHECK_VERIFY(this));
            target = bcs.dest();
            stackmap_table.check_jump_target
              (&current_frame, target, CHECK_VERIFY(this));
            no_control_flow = false; break;
          case Bytecodes::_goto :

*** 1669,11 ***
            verify_return_value(return_type, type, bci,
                                &current_frame, CHECK_VERIFY(this));
            no_control_flow = true; break;
          case Bytecodes::_areturn :
            type = current_frame.pop_stack(
!             VerificationType::reference_check(), CHECK_VERIFY(this));
            verify_return_value(return_type, type, bci,
                                &current_frame, CHECK_VERIFY(this));
            no_control_flow = true; break;
          case Bytecodes::_return :
            if (return_type != VerificationType::bogus_type()) {
--- 1686,11 ---
            verify_return_value(return_type, type, bci,
                                &current_frame, CHECK_VERIFY(this));
            no_control_flow = true; break;
          case Bytecodes::_areturn :
            type = current_frame.pop_stack(
!             VerificationType::nonscalar_check(), CHECK_VERIFY(this));
            verify_return_value(return_type, type, bci,
                                &current_frame, CHECK_VERIFY(this));
            no_control_flow = true; break;
          case Bytecodes::_return :
            if (return_type != VerificationType::bogus_type()) {

*** 1681,11 ***
                           "Method expects a return value");
              return;
            }
            // Make sure "this" has been initialized if current method is an
            // <init>.
!           if (_method->name() == vmSymbols::object_initializer_name() &&
                current_frame.flag_this_uninit()) {
              verify_error(ErrorContext::bad_code(bci),
                           "Constructor must call super() or this() "
                           "before return");
              return;
--- 1698,11 ---
                           "Method expects a return value");
              return;
            }
            // Make sure "this" has been initialized if current method is an
            // <init>.
!           if (_method->is_object_constructor() &&
                current_frame.flag_this_uninit()) {
              verify_error(ErrorContext::bad_code(bci),
                           "Constructor must call super() or this() "
                           "before return");
              return;

*** 1704,19 ***
              &bcs, &current_frame, cp, false, CHECK_VERIFY(this));
            no_control_flow = false; break;
          case Bytecodes::_invokevirtual :
          case Bytecodes::_invokespecial :
          case Bytecodes::_invokestatic :
-           verify_invoke_instructions(
-             &bcs, code_length, &current_frame, (bci >= ex_min && bci < ex_max),
-             &this_uninit, return_type, cp, &stackmap_table, CHECK_VERIFY(this));
-           no_control_flow = false; break;
          case Bytecodes::_invokeinterface :
          case Bytecodes::_invokedynamic :
            verify_invoke_instructions(
              &bcs, code_length, &current_frame, (bci >= ex_min && bci < ex_max),
!             &this_uninit, return_type, cp, &stackmap_table, CHECK_VERIFY(this));
            no_control_flow = false; break;
          case Bytecodes::_new :
          {
            u2 index = bcs.get_index_u2();
            verify_cp_class_type(bci, index, cp, CHECK_VERIFY(this));
--- 1721,15 ---
              &bcs, &current_frame, cp, false, CHECK_VERIFY(this));
            no_control_flow = false; break;
          case Bytecodes::_invokevirtual :
          case Bytecodes::_invokespecial :
          case Bytecodes::_invokestatic :
          case Bytecodes::_invokeinterface :
          case Bytecodes::_invokedynamic :
            verify_invoke_instructions(
              &bcs, code_length, &current_frame, (bci >= ex_min && bci < ex_max),
!             &this_uninit, cp, &stackmap_table, CHECK_VERIFY(this));
            no_control_flow = false; break;
          case Bytecodes::_new :
          {
            u2 index = bcs.get_index_u2();
            verify_cp_class_type(bci, index, cp, CHECK_VERIFY(this));

*** 1770,14 ***
            current_frame.push_stack(
              VerificationType::integer_type(), CHECK_VERIFY(this));
            no_control_flow = false; break;
          }
          case Bytecodes::_monitorenter :
!         case Bytecodes::_monitorexit :
!           current_frame.pop_stack(
!             VerificationType::reference_check(), CHECK_VERIFY(this));
            no_control_flow = false; break;
          case Bytecodes::_multianewarray :
          {
            u2 index = bcs.get_index_u2();
            u2 dim = *(bcs.bcp()+3);
            verify_cp_class_type(bci, index, cp, CHECK_VERIFY(this));
--- 1783,15 ---
            current_frame.push_stack(
              VerificationType::integer_type(), CHECK_VERIFY(this));
            no_control_flow = false; break;
          }
          case Bytecodes::_monitorenter :
!         case Bytecodes::_monitorexit : {
!           VerificationType ref = current_frame.pop_stack(
!             VerificationType::nonscalar_check(), CHECK_VERIFY(this));
            no_control_flow = false; break;
+         }
          case Bytecodes::_multianewarray :
          {
            u2 index = bcs.get_index_u2();
            u2 dim = *(bcs.bcp()+3);
            verify_cp_class_type(bci, index, cp, CHECK_VERIFY(this));

*** 2038,10 ***
--- 2052,11 ---
    // We must check was_recursively_verified() before we get here.
    guarantee(cp->cache() == nullptr, "not rewritten yet");
  
    verify_cp_index(bci, cp, index, CHECK_VERIFY(this));
    unsigned int tag = cp->tag_at(index).value();
+ 
    if ((types & (1 << tag)) == 0) {
      verify_error(ErrorContext::bad_cp_index(bci, index),
        "Illegal type at constant pool entry %d in class %s",
        index, cp->pool_holder()->external_name());
      return;

*** 2152,11 ***
    constantTag tag = cp->tag_at(index);
    unsigned int types = 0;
    if (opcode == Bytecodes::_ldc || opcode == Bytecodes::_ldc_w) {
      if (!tag.is_unresolved_klass()) {
        types = (1 << JVM_CONSTANT_Integer) | (1 << JVM_CONSTANT_Float)
!             | (1 << JVM_CONSTANT_String)  | (1 << JVM_CONSTANT_Class)
              | (1 << JVM_CONSTANT_MethodHandle) | (1 << JVM_CONSTANT_MethodType)
              | (1 << JVM_CONSTANT_Dynamic);
        // Note:  The class file parser already verified the legality of
        // MethodHandle and MethodType constants.
        verify_cp_type(bci, index, cp, types, CHECK_VERIFY(this));
--- 2167,11 ---
    constantTag tag = cp->tag_at(index);
    unsigned int types = 0;
    if (opcode == Bytecodes::_ldc || opcode == Bytecodes::_ldc_w) {
      if (!tag.is_unresolved_klass()) {
        types = (1 << JVM_CONSTANT_Integer) | (1 << JVM_CONSTANT_Float)
!             | (1 << JVM_CONSTANT_String) | (1 << JVM_CONSTANT_Class)
              | (1 << JVM_CONSTANT_MethodHandle) | (1 << JVM_CONSTANT_MethodType)
              | (1 << JVM_CONSTANT_Dynamic);
        // Note:  The class file parser already verified the legality of
        // MethodHandle and MethodType constants.
        verify_cp_type(bci, index, cp, types, CHECK_VERIFY(this));

*** 2327,17 ***
  
    // Get referenced class type
    VerificationType ref_class_type = cp_ref_index_to_type(
      index, cp, CHECK_VERIFY(this));
    if (!ref_class_type.is_object() &&
!     (!allow_arrays || !ref_class_type.is_array())) {
      verify_error(ErrorContext::bad_type(bcs->bci(),
          TypeOrigin::cp(index, ref_class_type)),
          "Expecting reference to class in class %s at constant pool index %d",
          _klass->external_name(), index);
      return;
    }
    VerificationType target_class_type = ref_class_type;
  
    assert(sizeof(VerificationType) == sizeof(uintptr_t),
          "buffer type must match VerificationType size");
    uintptr_t field_type_buffer[2];
--- 2342,18 ---
  
    // Get referenced class type
    VerificationType ref_class_type = cp_ref_index_to_type(
      index, cp, CHECK_VERIFY(this));
    if (!ref_class_type.is_object() &&
!       (!allow_arrays || !ref_class_type.is_array())) {
      verify_error(ErrorContext::bad_type(bcs->bci(),
          TypeOrigin::cp(index, ref_class_type)),
          "Expecting reference to class in class %s at constant pool index %d",
          _klass->external_name(), index);
      return;
    }
+ 
    VerificationType target_class_type = ref_class_type;
  
    assert(sizeof(VerificationType) == sizeof(uintptr_t),
          "buffer type must match VerificationType size");
    uintptr_t field_type_buffer[2];

*** 2786,11 ***
    return false;
  }
  
  void ClassVerifier::verify_invoke_instructions(
      RawBytecodeStream* bcs, u4 code_length, StackMapFrame* current_frame,
!     bool in_try_block, bool *this_uninit, VerificationType return_type,
      const constantPoolHandle& cp, StackMapTable* stackmap_table, TRAPS) {
    // Make sure the constant pool item is the right type
    u2 index = bcs->get_index_u2();
    Bytecodes::Code opcode = bcs->raw_code();
    unsigned int types = 0;
--- 2802,11 ---
    return false;
  }
  
  void ClassVerifier::verify_invoke_instructions(
      RawBytecodeStream* bcs, u4 code_length, StackMapFrame* current_frame,
!     bool in_try_block, bool *this_uninit,
      const constantPoolHandle& cp, StackMapTable* stackmap_table, TRAPS) {
    // Make sure the constant pool item is the right type
    u2 index = bcs->get_index_u2();
    Bytecodes::Code opcode = bcs->raw_code();
    unsigned int types = 0;

*** 2818,11 ***
  
    // Method signature was checked in ClassFileParser.
    assert(SignatureVerifier::is_valid_method_signature(method_sig),
           "Invalid method signature");
  
!   // Get referenced class type
    VerificationType ref_class_type;
    if (opcode == Bytecodes::_invokedynamic) {
      if (_klass->major_version() < Verifier::INVOKEDYNAMIC_MAJOR_VERSION) {
        class_format_error(
          "invokedynamic instructions not supported by this class file version (%d), class %s",
--- 2834,11 ---
  
    // Method signature was checked in ClassFileParser.
    assert(SignatureVerifier::is_valid_method_signature(method_sig),
           "Invalid method signature");
  
!   // Get referenced class
    VerificationType ref_class_type;
    if (opcode == Bytecodes::_invokedynamic) {
      if (_klass->major_version() < Verifier::INVOKEDYNAMIC_MAJOR_VERSION) {
        class_format_error(
          "invokedynamic instructions not supported by this class file version (%d), class %s",

*** 2884,21 ***
        return;
      }
    }
  
    if (method_name->char_at(0) == JVM_SIGNATURE_SPECIAL) {
!     // Make sure <init> can only be invoked by invokespecial
      if (opcode != Bytecodes::_invokespecial ||
!         method_name != vmSymbols::object_initializer_name()) {
        verify_error(ErrorContext::bad_code(bci),
            "Illegal call to internal method");
        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()))) {
      bool subtype = false;
      bool have_imr_indirect = cp->tag_at(index).value() == JVM_CONSTANT_InterfaceMethodref;
      subtype = ref_class_type.is_assignable_from(
                 current_type(), this, false, CHECK_VERIFY(this));
      if (!subtype) {
--- 2900,22 ---
        return;
      }
    }
  
    if (method_name->char_at(0) == JVM_SIGNATURE_SPECIAL) {
!     // Make sure:
+     //   <init> can only be invoked by invokespecial.
      if (opcode != Bytecodes::_invokespecial ||
!           method_name != vmSymbols::object_initializer_name()) {
        verify_error(ErrorContext::bad_code(bci),
            "Illegal call to internal method");
        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()))) { // super() can never be an inline_type.
      bool subtype = false;
      bool have_imr_indirect = cp->tag_at(index).value() == JVM_CONSTANT_InterfaceMethodref;
      subtype = ref_class_type.is_assignable_from(
                 current_type(), this, false, CHECK_VERIFY(this));
      if (!subtype) {

*** 2979,13 ***
    }
    // Push the result type.
    int sig_verif_types_len = sig_verif_types->length();
    if (sig_verif_types_len > nargs) {  // There's a return type
      if (method_name == vmSymbols::object_initializer_name()) {
!       // <init> method must have a void return type
-       /* Unreachable?  Class file parser verifies that methods with '<' have
-        * void return */
        verify_error(ErrorContext::bad_code(bci),
            "Return type must be void in <init> method");
        return;
      }
  
--- 2996,11 ---
    }
    // Push the result type.
    int sig_verif_types_len = sig_verif_types->length();
    if (sig_verif_types_len > nargs) {  // There's a return type
      if (method_name == vmSymbols::object_initializer_name()) {
!       // an <init> method must have a void return type
        verify_error(ErrorContext::bad_code(bci),
            "Return type must be void in <init> method");
        return;
      }
  

*** 3087,11 ***
      VerificationType::double2_type(), CHECK_VERIFY(this));
  }
  
  void ClassVerifier::verify_aload(int index, StackMapFrame* current_frame, TRAPS) {
    VerificationType type = current_frame->get_local(
!     index, VerificationType::reference_check(), CHECK_VERIFY(this));
    current_frame->push_stack(type, CHECK_VERIFY(this));
  }
  
  void ClassVerifier::verify_istore(int index, StackMapFrame* current_frame, TRAPS) {
    current_frame->pop_stack(
--- 3102,11 ---
      VerificationType::double2_type(), CHECK_VERIFY(this));
  }
  
  void ClassVerifier::verify_aload(int index, StackMapFrame* current_frame, TRAPS) {
    VerificationType type = current_frame->get_local(
!     index, VerificationType::nonscalar_check(), CHECK_VERIFY(this));
    current_frame->push_stack(type, CHECK_VERIFY(this));
  }
  
  void ClassVerifier::verify_istore(int index, StackMapFrame* current_frame, TRAPS) {
    current_frame->pop_stack(

*** 3124,11 ***
      VerificationType::double2_type(), CHECK_VERIFY(this));
  }
  
  void ClassVerifier::verify_astore(int index, StackMapFrame* current_frame, TRAPS) {
    VerificationType type = current_frame->pop_stack(
!     VerificationType::reference_check(), CHECK_VERIFY(this));
    current_frame->set_local(index, type, CHECK_VERIFY(this));
  }
  
  void ClassVerifier::verify_iinc(int index, StackMapFrame* current_frame, TRAPS) {
    VerificationType type = current_frame->get_local(
--- 3139,11 ---
      VerificationType::double2_type(), CHECK_VERIFY(this));
  }
  
  void ClassVerifier::verify_astore(int index, StackMapFrame* current_frame, TRAPS) {
    VerificationType type = current_frame->pop_stack(
!     VerificationType::nonscalar_check(), CHECK_VERIFY(this));
    current_frame->set_local(index, type, CHECK_VERIFY(this));
  }
  
  void ClassVerifier::verify_iinc(int index, StackMapFrame* current_frame, TRAPS) {
    VerificationType type = current_frame->get_local(
< prev index next >