src/share/vm/classfile/verifier.cpp

Thu, 27 Jan 2011 16:11:27 -0800

author
coleenp
date
Thu, 27 Jan 2011 16:11:27 -0800
changeset 2497
3582bf76420e
parent 2322
828eafbd85cc
child 2508
b92c45f2bc75
permissions
-rw-r--r--

6990754: Use native memory and reference counting to implement SymbolTable
Summary: move symbols from permgen into C heap and reference count them
Reviewed-by: never, acorn, jmasa, stefank

     1 /*
     2  * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  *
    23  */
    25 #include "precompiled.hpp"
    26 #include "classfile/classFileStream.hpp"
    27 #include "classfile/javaClasses.hpp"
    28 #include "classfile/stackMapTable.hpp"
    29 #include "classfile/systemDictionary.hpp"
    30 #include "classfile/verifier.hpp"
    31 #include "classfile/vmSymbols.hpp"
    32 #include "interpreter/bytecodeStream.hpp"
    33 #include "memory/oopFactory.hpp"
    34 #include "memory/resourceArea.hpp"
    35 #include "oops/instanceKlass.hpp"
    36 #include "oops/oop.inline.hpp"
    37 #include "oops/typeArrayOop.hpp"
    38 #include "prims/jvm.h"
    39 #include "runtime/fieldDescriptor.hpp"
    40 #include "runtime/handles.inline.hpp"
    41 #include "runtime/interfaceSupport.hpp"
    42 #include "runtime/javaCalls.hpp"
    43 #include "runtime/orderAccess.hpp"
    44 #include "runtime/os.hpp"
    45 #ifdef TARGET_ARCH_x86
    46 # include "bytes_x86.hpp"
    47 #endif
    48 #ifdef TARGET_ARCH_sparc
    49 # include "bytes_sparc.hpp"
    50 #endif
    51 #ifdef TARGET_ARCH_zero
    52 # include "bytes_zero.hpp"
    53 #endif
    55 #define NOFAILOVER_MAJOR_VERSION 51
    57 // Access to external entry for VerifyClassCodes - old byte code verifier
    59 extern "C" {
    60   typedef jboolean (*verify_byte_codes_fn_t)(JNIEnv *, jclass, char *, jint);
    61   typedef jboolean (*verify_byte_codes_fn_new_t)(JNIEnv *, jclass, char *, jint, jint);
    62 }
    64 static void* volatile _verify_byte_codes_fn = NULL;
    66 static volatile jint _is_new_verify_byte_codes_fn = (jint) true;
    68 static void* verify_byte_codes_fn() {
    69   if (_verify_byte_codes_fn == NULL) {
    70     void *lib_handle = os::native_java_library();
    71     void *func = os::dll_lookup(lib_handle, "VerifyClassCodesForMajorVersion");
    72     OrderAccess::release_store_ptr(&_verify_byte_codes_fn, func);
    73     if (func == NULL) {
    74       OrderAccess::release_store(&_is_new_verify_byte_codes_fn, false);
    75       func = os::dll_lookup(lib_handle, "VerifyClassCodes");
    76       OrderAccess::release_store_ptr(&_verify_byte_codes_fn, func);
    77     }
    78   }
    79   return (void*)_verify_byte_codes_fn;
    80 }
    83 // Methods in Verifier
    85 bool Verifier::should_verify_for(oop class_loader, bool should_verify_class) {
    86   return (class_loader == NULL || !should_verify_class) ?
    87     BytecodeVerificationLocal : BytecodeVerificationRemote;
    88 }
    90 bool Verifier::relax_verify_for(oop loader) {
    91   bool trusted = java_lang_ClassLoader::is_trusted_loader(loader);
    92   bool need_verify =
    93     // verifyAll
    94     (BytecodeVerificationLocal && BytecodeVerificationRemote) ||
    95     // verifyRemote
    96     (!BytecodeVerificationLocal && BytecodeVerificationRemote && !trusted);
    97   return !need_verify;
    98 }
   100 bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool should_verify_class, TRAPS) {
   101   HandleMark hm;
   102   ResourceMark rm(THREAD);
   104   Symbol* exception_name = NULL;
   105   const size_t message_buffer_len = klass->name()->utf8_length() + 1024;
   106   char* message_buffer = NEW_RESOURCE_ARRAY(char, message_buffer_len);
   108   const char* klassName = klass->external_name();
   110   // If the class should be verified, first see if we can use the split
   111   // verifier.  If not, or if verification fails and FailOverToOldVerifier
   112   // is set, then call the inference verifier.
   113   if (is_eligible_for_verification(klass, should_verify_class)) {
   114     if (TraceClassInitialization) {
   115       tty->print_cr("Start class verification for: %s", klassName);
   116     }
   117     if (UseSplitVerifier &&
   118         klass->major_version() >= STACKMAP_ATTRIBUTE_MAJOR_VERSION) {
   119         ClassVerifier split_verifier(
   120           klass, message_buffer, message_buffer_len, THREAD);
   121         split_verifier.verify_class(THREAD);
   122         exception_name = split_verifier.result();
   123       if (klass->major_version() < NOFAILOVER_MAJOR_VERSION &&
   124           FailOverToOldVerifier && !HAS_PENDING_EXCEPTION &&
   125           (exception_name == vmSymbols::java_lang_VerifyError() ||
   126            exception_name == vmSymbols::java_lang_ClassFormatError())) {
   127         if (TraceClassInitialization) {
   128           tty->print_cr(
   129             "Fail over class verification to old verifier for: %s", klassName);
   130         }
   131         exception_name = inference_verify(
   132           klass, message_buffer, message_buffer_len, THREAD);
   133       }
   134     } else {
   135       exception_name = inference_verify(
   136           klass, message_buffer, message_buffer_len, THREAD);
   137     }
   139     if (TraceClassInitialization) {
   140       if (HAS_PENDING_EXCEPTION) {
   141         tty->print("Verification for %s has", klassName);
   142         tty->print_cr(" exception pending %s ",
   143           instanceKlass::cast(PENDING_EXCEPTION->klass())->external_name());
   144       } else if (exception_name != NULL) {
   145         tty->print_cr("Verification for %s failed", klassName);
   146       }
   147       tty->print_cr("End class verification for: %s", klassName);
   148     }
   149   }
   151   if (HAS_PENDING_EXCEPTION) {
   152     return false; // use the existing exception
   153   } else if (exception_name == NULL) {
   154     return true; // verifcation succeeded
   155   } else { // VerifyError or ClassFormatError to be created and thrown
   156     ResourceMark rm(THREAD);
   157     instanceKlassHandle kls =
   158       SystemDictionary::resolve_or_fail(exception_name, true, CHECK_false);
   159     while (!kls.is_null()) {
   160       if (kls == klass) {
   161         // If the class being verified is the exception we're creating
   162         // or one of it's superclasses, we're in trouble and are going
   163         // to infinitely recurse when we try to initialize the exception.
   164         // So bail out here by throwing the preallocated VM error.
   165         THROW_OOP_(Universe::virtual_machine_error_instance(), false);
   166       }
   167       kls = kls->super();
   168     }
   169     message_buffer[message_buffer_len - 1] = '\0'; // just to be sure
   170     THROW_MSG_(exception_name, message_buffer, false);
   171   }
   172 }
   174 bool Verifier::is_eligible_for_verification(instanceKlassHandle klass, bool should_verify_class) {
   175   Symbol* name = klass->name();
   176   klassOop refl_magic_klass = SystemDictionary::reflect_MagicAccessorImpl_klass();
   178   return (should_verify_for(klass->class_loader(), should_verify_class) &&
   179     // return if the class is a bootstrapping class
   180     // or defineClass specified not to verify by default (flags override passed arg)
   181     // We need to skip the following four for bootstraping
   182     name != vmSymbols::java_lang_Object() &&
   183     name != vmSymbols::java_lang_Class() &&
   184     name != vmSymbols::java_lang_String() &&
   185     name != vmSymbols::java_lang_Throwable() &&
   187     // Can not verify the bytecodes for shared classes because they have
   188     // already been rewritten to contain constant pool cache indices,
   189     // which the verifier can't understand.
   190     // Shared classes shouldn't have stackmaps either.
   191     !klass()->is_shared() &&
   193     // As of the fix for 4486457 we disable verification for all of the
   194     // dynamically-generated bytecodes associated with the 1.4
   195     // reflection implementation, not just those associated with
   196     // sun/reflect/SerializationConstructorAccessor.
   197     // NOTE: this is called too early in the bootstrapping process to be
   198     // guarded by Universe::is_gte_jdk14x_version()/UseNewReflection.
   199     (refl_magic_klass == NULL ||
   200      !klass->is_subtype_of(refl_magic_klass) ||
   201      VerifyReflectionBytecodes)
   202   );
   203 }
   205 Symbol* Verifier::inference_verify(
   206     instanceKlassHandle klass, char* message, size_t message_len, TRAPS) {
   207   JavaThread* thread = (JavaThread*)THREAD;
   208   JNIEnv *env = thread->jni_environment();
   210   void* verify_func = verify_byte_codes_fn();
   212   if (verify_func == NULL) {
   213     jio_snprintf(message, message_len, "Could not link verifier");
   214     return vmSymbols::java_lang_VerifyError();
   215   }
   217   ResourceMark rm(THREAD);
   218   if (ClassVerifier::_verify_verbose) {
   219     tty->print_cr("Verifying class %s with old format", klass->external_name());
   220   }
   222   jclass cls = (jclass) JNIHandles::make_local(env, klass->java_mirror());
   223   jint result;
   225   {
   226     HandleMark hm(thread);
   227     ThreadToNativeFromVM ttn(thread);
   228     // ThreadToNativeFromVM takes care of changing thread_state, so safepoint
   229     // code knows that we have left the VM
   231     if (_is_new_verify_byte_codes_fn) {
   232       verify_byte_codes_fn_new_t func =
   233         CAST_TO_FN_PTR(verify_byte_codes_fn_new_t, verify_func);
   234       result = (*func)(env, cls, message, (int)message_len,
   235           klass->major_version());
   236     } else {
   237       verify_byte_codes_fn_t func =
   238         CAST_TO_FN_PTR(verify_byte_codes_fn_t, verify_func);
   239       result = (*func)(env, cls, message, (int)message_len);
   240     }
   241   }
   243   JNIHandles::destroy_local(cls);
   245   // These numbers are chosen so that VerifyClassCodes interface doesn't need
   246   // to be changed (still return jboolean (unsigned char)), and result is
   247   // 1 when verification is passed.
   248   if (result == 0) {
   249     return vmSymbols::java_lang_VerifyError();
   250   } else if (result == 1) {
   251     return NULL; // verified.
   252   } else if (result == 2) {
   253     THROW_MSG_(vmSymbols::java_lang_OutOfMemoryError(), message, NULL);
   254   } else if (result == 3) {
   255     return vmSymbols::java_lang_ClassFormatError();
   256   } else {
   257     ShouldNotReachHere();
   258     return NULL;
   259   }
   260 }
   262 // Methods in ClassVerifier
   264 bool ClassVerifier::_verify_verbose = false;
   266 ClassVerifier::ClassVerifier(
   267     instanceKlassHandle klass, char* msg, size_t msg_len, TRAPS)
   268     : _thread(THREAD), _exception_type(NULL), _message(msg),
   269       _message_buffer_len(msg_len), _klass(klass) {
   270   _this_type = VerificationType::reference_type(klass->name());
   271   // Create list to hold symbols in reference area.
   272   _symbols = new GrowableArray<Symbol*>(100, 0, NULL);
   273 }
   275 ClassVerifier::~ClassVerifier() {
   276   // Decrement the reference count for any symbols created.
   277   for (int i = 0; i < _symbols->length(); i++) {
   278     Symbol* s = _symbols->at(i);
   279     s->decrement_refcount();
   280   }
   281 }
   283 VerificationType ClassVerifier::object_type() const {
   284   return VerificationType::reference_type(vmSymbols::java_lang_Object());
   285 }
   287 void ClassVerifier::verify_class(TRAPS) {
   288   if (_verify_verbose) {
   289     tty->print_cr("Verifying class %s with new format",
   290       _klass->external_name());
   291   }
   293   objArrayHandle methods(THREAD, _klass->methods());
   294   int num_methods = methods->length();
   296   for (int index = 0; index < num_methods; index++) {
   297     // Check for recursive re-verification before each method.
   298     if (was_recursively_verified())  return;
   300     methodOop m = (methodOop)methods->obj_at(index);
   301     if (m->is_native() || m->is_abstract()) {
   302       // If m is native or abstract, skip it.  It is checked in class file
   303       // parser that methods do not override a final method.
   304       continue;
   305     }
   306     verify_method(methodHandle(THREAD, m), CHECK_VERIFY(this));
   307   }
   309   if (_verify_verbose || TraceClassInitialization) {
   310     if (was_recursively_verified())
   311       tty->print_cr("Recursive verification detected for: %s",
   312           _klass->external_name());
   313   }
   314 }
   316 void ClassVerifier::verify_method(methodHandle m, TRAPS) {
   317   _method = m;   // initialize _method
   318   if (_verify_verbose) {
   319     tty->print_cr("Verifying method %s", m->name_and_sig_as_C_string());
   320   }
   322   const char* bad_type_msg = "Bad type on operand stack in %s";
   324   int32_t max_stack = m->max_stack();
   325   int32_t max_locals = m->max_locals();
   326   constantPoolHandle cp(THREAD, m->constants());
   328   if (!SignatureVerifier::is_valid_method_signature(m->signature())) {
   329     class_format_error("Invalid method signature");
   330     return;
   331   }
   333   // Initial stack map frame: offset is 0, stack is initially empty.
   334   StackMapFrame current_frame(max_locals, max_stack, this);
   335   // Set initial locals
   336   VerificationType return_type = current_frame.set_locals_from_arg(
   337     m, current_type(), CHECK_VERIFY(this));
   339   int32_t stackmap_index = 0; // index to the stackmap array
   341   u4 code_length = m->code_size();
   343   // Scan the bytecode and map each instruction's start offset to a number.
   344   char* code_data = generate_code_data(m, code_length, CHECK_VERIFY(this));
   346   int ex_min = code_length;
   347   int ex_max = -1;
   348   // Look through each item on the exception table. Each of the fields must refer
   349   // to a legal instruction.
   350   verify_exception_handler_table(
   351     code_length, code_data, ex_min, ex_max, CHECK_VERIFY(this));
   353   // Look through each entry on the local variable table and make sure
   354   // its range of code array offsets is valid. (4169817)
   355   if (m->has_localvariable_table()) {
   356     verify_local_variable_table(code_length, code_data, CHECK_VERIFY(this));
   357   }
   359   typeArrayHandle stackmap_data(THREAD, m->stackmap_data());
   360   StackMapStream stream(stackmap_data);
   361   StackMapReader reader(this, &stream, code_data, code_length, THREAD);
   362   StackMapTable stackmap_table(&reader, &current_frame, max_locals, max_stack,
   363                                code_data, code_length, CHECK_VERIFY(this));
   365   if (_verify_verbose) {
   366     stackmap_table.print();
   367   }
   369   RawBytecodeStream bcs(m);
   371   // Scan the byte code linearly from the start to the end
   372   bool no_control_flow = false; // Set to true when there is no direct control
   373                                 // flow from current instruction to the next
   374                                 // instruction in sequence
   375   Bytecodes::Code opcode;
   376   while (!bcs.is_last_bytecode()) {
   377     // Check for recursive re-verification before each bytecode.
   378     if (was_recursively_verified())  return;
   380     opcode = bcs.raw_next();
   381     u2 bci = bcs.bci();
   383     // Set current frame's offset to bci
   384     current_frame.set_offset(bci);
   386     // Make sure every offset in stackmap table point to the beginning to
   387     // an instruction. Match current_frame to stackmap_table entry with
   388     // the same offset if exists.
   389     stackmap_index = verify_stackmap_table(
   390       stackmap_index, bci, &current_frame, &stackmap_table,
   391       no_control_flow, CHECK_VERIFY(this));
   393     bool this_uninit = false;  // Set to true when invokespecial <init> initialized 'this'
   395     // Merge with the next instruction
   396     {
   397       u2 index;
   398       int target;
   399       VerificationType type, type2;
   400       VerificationType atype;
   402 #ifndef PRODUCT
   403       if (_verify_verbose) {
   404         current_frame.print();
   405         tty->print_cr("offset = %d,  opcode = %s", bci, Bytecodes::name(opcode));
   406       }
   407 #endif
   409       // Make sure wide instruction is in correct format
   410       if (bcs.is_wide()) {
   411         if (opcode != Bytecodes::_iinc   && opcode != Bytecodes::_iload  &&
   412             opcode != Bytecodes::_aload  && opcode != Bytecodes::_lload  &&
   413             opcode != Bytecodes::_istore && opcode != Bytecodes::_astore &&
   414             opcode != Bytecodes::_lstore && opcode != Bytecodes::_fload  &&
   415             opcode != Bytecodes::_dload  && opcode != Bytecodes::_fstore &&
   416             opcode != Bytecodes::_dstore) {
   417           verify_error(bci, "Bad wide instruction");
   418           return;
   419         }
   420       }
   422       switch (opcode) {
   423         case Bytecodes::_nop :
   424           no_control_flow = false; break;
   425         case Bytecodes::_aconst_null :
   426           current_frame.push_stack(
   427             VerificationType::null_type(), CHECK_VERIFY(this));
   428           no_control_flow = false; break;
   429         case Bytecodes::_iconst_m1 :
   430         case Bytecodes::_iconst_0 :
   431         case Bytecodes::_iconst_1 :
   432         case Bytecodes::_iconst_2 :
   433         case Bytecodes::_iconst_3 :
   434         case Bytecodes::_iconst_4 :
   435         case Bytecodes::_iconst_5 :
   436           current_frame.push_stack(
   437             VerificationType::integer_type(), CHECK_VERIFY(this));
   438           no_control_flow = false; break;
   439         case Bytecodes::_lconst_0 :
   440         case Bytecodes::_lconst_1 :
   441           current_frame.push_stack_2(
   442             VerificationType::long_type(),
   443             VerificationType::long2_type(), CHECK_VERIFY(this));
   444           no_control_flow = false; break;
   445         case Bytecodes::_fconst_0 :
   446         case Bytecodes::_fconst_1 :
   447         case Bytecodes::_fconst_2 :
   448           current_frame.push_stack(
   449             VerificationType::float_type(), CHECK_VERIFY(this));
   450           no_control_flow = false; break;
   451         case Bytecodes::_dconst_0 :
   452         case Bytecodes::_dconst_1 :
   453           current_frame.push_stack_2(
   454             VerificationType::double_type(),
   455             VerificationType::double2_type(), CHECK_VERIFY(this));
   456           no_control_flow = false; break;
   457         case Bytecodes::_sipush :
   458         case Bytecodes::_bipush :
   459           current_frame.push_stack(
   460             VerificationType::integer_type(), CHECK_VERIFY(this));
   461           no_control_flow = false; break;
   462         case Bytecodes::_ldc :
   463           verify_ldc(
   464             opcode, bcs.get_index_u1(), &current_frame,
   465             cp, bci, CHECK_VERIFY(this));
   466           no_control_flow = false; break;
   467         case Bytecodes::_ldc_w :
   468         case Bytecodes::_ldc2_w :
   469           verify_ldc(
   470             opcode, bcs.get_index_u2(), &current_frame,
   471             cp, bci, CHECK_VERIFY(this));
   472           no_control_flow = false; break;
   473         case Bytecodes::_iload :
   474           verify_iload(bcs.get_index(), &current_frame, CHECK_VERIFY(this));
   475           no_control_flow = false; break;
   476         case Bytecodes::_iload_0 :
   477         case Bytecodes::_iload_1 :
   478         case Bytecodes::_iload_2 :
   479         case Bytecodes::_iload_3 :
   480           index = opcode - Bytecodes::_iload_0;
   481           verify_iload(index, &current_frame, CHECK_VERIFY(this));
   482           no_control_flow = false; break;
   483         case Bytecodes::_lload :
   484           verify_lload(bcs.get_index(), &current_frame, CHECK_VERIFY(this));
   485           no_control_flow = false; break;
   486         case Bytecodes::_lload_0 :
   487         case Bytecodes::_lload_1 :
   488         case Bytecodes::_lload_2 :
   489         case Bytecodes::_lload_3 :
   490           index = opcode - Bytecodes::_lload_0;
   491           verify_lload(index, &current_frame, CHECK_VERIFY(this));
   492           no_control_flow = false; break;
   493         case Bytecodes::_fload :
   494           verify_fload(bcs.get_index(), &current_frame, CHECK_VERIFY(this));
   495           no_control_flow = false; break;
   496         case Bytecodes::_fload_0 :
   497         case Bytecodes::_fload_1 :
   498         case Bytecodes::_fload_2 :
   499         case Bytecodes::_fload_3 :
   500           index = opcode - Bytecodes::_fload_0;
   501           verify_fload(index, &current_frame, CHECK_VERIFY(this));
   502           no_control_flow = false; break;
   503         case Bytecodes::_dload :
   504           verify_dload(bcs.get_index(), &current_frame, CHECK_VERIFY(this));
   505           no_control_flow = false; break;
   506         case Bytecodes::_dload_0 :
   507         case Bytecodes::_dload_1 :
   508         case Bytecodes::_dload_2 :
   509         case Bytecodes::_dload_3 :
   510           index = opcode - Bytecodes::_dload_0;
   511           verify_dload(index, &current_frame, CHECK_VERIFY(this));
   512           no_control_flow = false; break;
   513         case Bytecodes::_aload :
   514           verify_aload(bcs.get_index(), &current_frame, CHECK_VERIFY(this));
   515           no_control_flow = false; break;
   516         case Bytecodes::_aload_0 :
   517         case Bytecodes::_aload_1 :
   518         case Bytecodes::_aload_2 :
   519         case Bytecodes::_aload_3 :
   520           index = opcode - Bytecodes::_aload_0;
   521           verify_aload(index, &current_frame, CHECK_VERIFY(this));
   522           no_control_flow = false; break;
   523         case Bytecodes::_iaload :
   524           type = current_frame.pop_stack(
   525             VerificationType::integer_type(), CHECK_VERIFY(this));
   526           atype = current_frame.pop_stack(
   527             VerificationType::reference_check(), CHECK_VERIFY(this));
   528           if (!atype.is_int_array()) {
   529             verify_error(bci, bad_type_msg, "iaload");
   530             return;
   531           }
   532           current_frame.push_stack(
   533             VerificationType::integer_type(), CHECK_VERIFY(this));
   534           no_control_flow = false; break;
   535         case Bytecodes::_baload :
   536           type = current_frame.pop_stack(
   537             VerificationType::integer_type(), CHECK_VERIFY(this));
   538           atype = current_frame.pop_stack(
   539             VerificationType::reference_check(), CHECK_VERIFY(this));
   540           if (!atype.is_bool_array() && !atype.is_byte_array()) {
   541             verify_error(bci, bad_type_msg, "baload");
   542             return;
   543           }
   544           current_frame.push_stack(
   545             VerificationType::integer_type(), CHECK_VERIFY(this));
   546           no_control_flow = false; break;
   547         case Bytecodes::_caload :
   548           type = current_frame.pop_stack(
   549             VerificationType::integer_type(), CHECK_VERIFY(this));
   550           atype = current_frame.pop_stack(
   551             VerificationType::reference_check(), CHECK_VERIFY(this));
   552           if (!atype.is_char_array()) {
   553             verify_error(bci, bad_type_msg, "caload");
   554             return;
   555           }
   556           current_frame.push_stack(
   557             VerificationType::integer_type(), CHECK_VERIFY(this));
   558           no_control_flow = false; break;
   559         case Bytecodes::_saload :
   560           type = current_frame.pop_stack(
   561             VerificationType::integer_type(), CHECK_VERIFY(this));
   562           atype = current_frame.pop_stack(
   563             VerificationType::reference_check(), CHECK_VERIFY(this));
   564           if (!atype.is_short_array()) {
   565             verify_error(bci, bad_type_msg, "saload");
   566             return;
   567           }
   568           current_frame.push_stack(
   569             VerificationType::integer_type(), CHECK_VERIFY(this));
   570           no_control_flow = false; break;
   571         case Bytecodes::_laload :
   572           type = current_frame.pop_stack(
   573             VerificationType::integer_type(), CHECK_VERIFY(this));
   574           atype = current_frame.pop_stack(
   575             VerificationType::reference_check(), CHECK_VERIFY(this));
   576           if (!atype.is_long_array()) {
   577             verify_error(bci, bad_type_msg, "laload");
   578             return;
   579           }
   580           current_frame.push_stack_2(
   581             VerificationType::long_type(),
   582             VerificationType::long2_type(), CHECK_VERIFY(this));
   583           no_control_flow = false; break;
   584         case Bytecodes::_faload :
   585           type = current_frame.pop_stack(
   586             VerificationType::integer_type(), CHECK_VERIFY(this));
   587           atype = current_frame.pop_stack(
   588             VerificationType::reference_check(), CHECK_VERIFY(this));
   589           if (!atype.is_float_array()) {
   590             verify_error(bci, bad_type_msg, "faload");
   591             return;
   592           }
   593           current_frame.push_stack(
   594             VerificationType::float_type(), CHECK_VERIFY(this));
   595           no_control_flow = false; break;
   596         case Bytecodes::_daload :
   597           type = current_frame.pop_stack(
   598             VerificationType::integer_type(), CHECK_VERIFY(this));
   599           atype = current_frame.pop_stack(
   600             VerificationType::reference_check(), CHECK_VERIFY(this));
   601           if (!atype.is_double_array()) {
   602             verify_error(bci, bad_type_msg, "daload");
   603             return;
   604           }
   605           current_frame.push_stack_2(
   606             VerificationType::double_type(),
   607             VerificationType::double2_type(), CHECK_VERIFY(this));
   608           no_control_flow = false; break;
   609         case Bytecodes::_aaload : {
   610           type = current_frame.pop_stack(
   611             VerificationType::integer_type(), CHECK_VERIFY(this));
   612           atype = current_frame.pop_stack(
   613             VerificationType::reference_check(), CHECK_VERIFY(this));
   614           if (!atype.is_reference_array()) {
   615             verify_error(bci, bad_type_msg, "aaload");
   616             return;
   617           }
   618           if (atype.is_null()) {
   619             current_frame.push_stack(
   620               VerificationType::null_type(), CHECK_VERIFY(this));
   621           } else {
   622             VerificationType component =
   623               atype.get_component(this, CHECK_VERIFY(this));
   624             current_frame.push_stack(component, CHECK_VERIFY(this));
   625           }
   626           no_control_flow = false; break;
   627         }
   628         case Bytecodes::_istore :
   629           verify_istore(bcs.get_index(), &current_frame, CHECK_VERIFY(this));
   630           no_control_flow = false; break;
   631         case Bytecodes::_istore_0 :
   632         case Bytecodes::_istore_1 :
   633         case Bytecodes::_istore_2 :
   634         case Bytecodes::_istore_3 :
   635           index = opcode - Bytecodes::_istore_0;
   636           verify_istore(index, &current_frame, CHECK_VERIFY(this));
   637           no_control_flow = false; break;
   638         case Bytecodes::_lstore :
   639           verify_lstore(bcs.get_index(), &current_frame, CHECK_VERIFY(this));
   640           no_control_flow = false; break;
   641         case Bytecodes::_lstore_0 :
   642         case Bytecodes::_lstore_1 :
   643         case Bytecodes::_lstore_2 :
   644         case Bytecodes::_lstore_3 :
   645           index = opcode - Bytecodes::_lstore_0;
   646           verify_lstore(index, &current_frame, CHECK_VERIFY(this));
   647           no_control_flow = false; break;
   648         case Bytecodes::_fstore :
   649           verify_fstore(bcs.get_index(), &current_frame, CHECK_VERIFY(this));
   650           no_control_flow = false; break;
   651         case Bytecodes::_fstore_0 :
   652         case Bytecodes::_fstore_1 :
   653         case Bytecodes::_fstore_2 :
   654         case Bytecodes::_fstore_3 :
   655           index = opcode - Bytecodes::_fstore_0;
   656           verify_fstore(index, &current_frame, CHECK_VERIFY(this));
   657           no_control_flow = false; break;
   658         case Bytecodes::_dstore :
   659           verify_dstore(bcs.get_index(), &current_frame, CHECK_VERIFY(this));
   660           no_control_flow = false; break;
   661         case Bytecodes::_dstore_0 :
   662         case Bytecodes::_dstore_1 :
   663         case Bytecodes::_dstore_2 :
   664         case Bytecodes::_dstore_3 :
   665           index = opcode - Bytecodes::_dstore_0;
   666           verify_dstore(index, &current_frame, CHECK_VERIFY(this));
   667           no_control_flow = false; break;
   668         case Bytecodes::_astore :
   669           verify_astore(bcs.get_index(), &current_frame, CHECK_VERIFY(this));
   670           no_control_flow = false; break;
   671         case Bytecodes::_astore_0 :
   672         case Bytecodes::_astore_1 :
   673         case Bytecodes::_astore_2 :
   674         case Bytecodes::_astore_3 :
   675           index = opcode - Bytecodes::_astore_0;
   676           verify_astore(index, &current_frame, CHECK_VERIFY(this));
   677           no_control_flow = false; break;
   678         case Bytecodes::_iastore :
   679           type = current_frame.pop_stack(
   680             VerificationType::integer_type(), CHECK_VERIFY(this));
   681           type2 = current_frame.pop_stack(
   682             VerificationType::integer_type(), CHECK_VERIFY(this));
   683           atype = current_frame.pop_stack(
   684             VerificationType::reference_check(), CHECK_VERIFY(this));
   685           if (!atype.is_int_array()) {
   686             verify_error(bci, bad_type_msg, "iastore");
   687             return;
   688           }
   689           no_control_flow = false; break;
   690         case Bytecodes::_bastore :
   691           type = current_frame.pop_stack(
   692             VerificationType::integer_type(), CHECK_VERIFY(this));
   693           type2 = current_frame.pop_stack(
   694             VerificationType::integer_type(), CHECK_VERIFY(this));
   695           atype = current_frame.pop_stack(
   696             VerificationType::reference_check(), CHECK_VERIFY(this));
   697           if (!atype.is_bool_array() && !atype.is_byte_array()) {
   698             verify_error(bci, bad_type_msg, "bastore");
   699             return;
   700           }
   701           no_control_flow = false; break;
   702         case Bytecodes::_castore :
   703           current_frame.pop_stack(
   704             VerificationType::integer_type(), CHECK_VERIFY(this));
   705           current_frame.pop_stack(
   706             VerificationType::integer_type(), CHECK_VERIFY(this));
   707           atype = current_frame.pop_stack(
   708             VerificationType::reference_check(), CHECK_VERIFY(this));
   709           if (!atype.is_char_array()) {
   710             verify_error(bci, bad_type_msg, "castore");
   711             return;
   712           }
   713           no_control_flow = false; break;
   714         case Bytecodes::_sastore :
   715           current_frame.pop_stack(
   716             VerificationType::integer_type(), CHECK_VERIFY(this));
   717           current_frame.pop_stack(
   718             VerificationType::integer_type(), CHECK_VERIFY(this));
   719           atype = current_frame.pop_stack(
   720             VerificationType::reference_check(), CHECK_VERIFY(this));
   721           if (!atype.is_short_array()) {
   722             verify_error(bci, bad_type_msg, "sastore");
   723             return;
   724           }
   725           no_control_flow = false; break;
   726         case Bytecodes::_lastore :
   727           current_frame.pop_stack_2(
   728             VerificationType::long2_type(),
   729             VerificationType::long_type(), CHECK_VERIFY(this));
   730           current_frame.pop_stack(
   731             VerificationType::integer_type(), CHECK_VERIFY(this));
   732           atype = current_frame.pop_stack(
   733             VerificationType::reference_check(), CHECK_VERIFY(this));
   734           if (!atype.is_long_array()) {
   735             verify_error(bci, bad_type_msg, "lastore");
   736             return;
   737           }
   738           no_control_flow = false; break;
   739         case Bytecodes::_fastore :
   740           current_frame.pop_stack(
   741             VerificationType::float_type(), CHECK_VERIFY(this));
   742           current_frame.pop_stack
   743             (VerificationType::integer_type(), CHECK_VERIFY(this));
   744           atype = current_frame.pop_stack(
   745             VerificationType::reference_check(), CHECK_VERIFY(this));
   746           if (!atype.is_float_array()) {
   747             verify_error(bci, bad_type_msg, "fastore");
   748             return;
   749           }
   750           no_control_flow = false; break;
   751         case Bytecodes::_dastore :
   752           current_frame.pop_stack_2(
   753             VerificationType::double2_type(),
   754             VerificationType::double_type(), CHECK_VERIFY(this));
   755           current_frame.pop_stack(
   756             VerificationType::integer_type(), CHECK_VERIFY(this));
   757           atype = current_frame.pop_stack(
   758             VerificationType::reference_check(), CHECK_VERIFY(this));
   759           if (!atype.is_double_array()) {
   760             verify_error(bci, bad_type_msg, "dastore");
   761             return;
   762           }
   763           no_control_flow = false; break;
   764         case Bytecodes::_aastore :
   765           type = current_frame.pop_stack(object_type(), CHECK_VERIFY(this));
   766           type2 = current_frame.pop_stack(
   767             VerificationType::integer_type(), CHECK_VERIFY(this));
   768           atype = current_frame.pop_stack(
   769             VerificationType::reference_check(), CHECK_VERIFY(this));
   770           // more type-checking is done at runtime
   771           if (!atype.is_reference_array()) {
   772             verify_error(bci, bad_type_msg, "aastore");
   773             return;
   774           }
   775           // 4938384: relaxed constraint in JVMS 3nd edition.
   776           no_control_flow = false; break;
   777         case Bytecodes::_pop :
   778           current_frame.pop_stack(
   779             VerificationType::category1_check(), CHECK_VERIFY(this));
   780           no_control_flow = false; break;
   781         case Bytecodes::_pop2 :
   782           type = current_frame.pop_stack(CHECK_VERIFY(this));
   783           if (type.is_category1()) {
   784             current_frame.pop_stack(
   785               VerificationType::category1_check(), CHECK_VERIFY(this));
   786           } else if (type.is_category2_2nd()) {
   787             current_frame.pop_stack(
   788               VerificationType::category2_check(), CHECK_VERIFY(this));
   789           } else {
   790             verify_error(bci, bad_type_msg, "pop2");
   791             return;
   792           }
   793           no_control_flow = false; break;
   794         case Bytecodes::_dup :
   795           type = current_frame.pop_stack(
   796             VerificationType::category1_check(), CHECK_VERIFY(this));
   797           current_frame.push_stack(type, CHECK_VERIFY(this));
   798           current_frame.push_stack(type, CHECK_VERIFY(this));
   799           no_control_flow = false; break;
   800         case Bytecodes::_dup_x1 :
   801           type = current_frame.pop_stack(
   802             VerificationType::category1_check(), CHECK_VERIFY(this));
   803           type2 = current_frame.pop_stack(
   804             VerificationType::category1_check(), CHECK_VERIFY(this));
   805           current_frame.push_stack(type, CHECK_VERIFY(this));
   806           current_frame.push_stack(type2, CHECK_VERIFY(this));
   807           current_frame.push_stack(type, CHECK_VERIFY(this));
   808           no_control_flow = false; break;
   809         case Bytecodes::_dup_x2 :
   810         {
   811           VerificationType type3;
   812           type = current_frame.pop_stack(
   813             VerificationType::category1_check(), CHECK_VERIFY(this));
   814           type2 = current_frame.pop_stack(CHECK_VERIFY(this));
   815           if (type2.is_category1()) {
   816             type3 = current_frame.pop_stack(
   817               VerificationType::category1_check(), CHECK_VERIFY(this));
   818           } else if (type2.is_category2_2nd()) {
   819             type3 = current_frame.pop_stack(
   820               VerificationType::category2_check(), CHECK_VERIFY(this));
   821           } else {
   822             verify_error(bci, bad_type_msg, "dup_x2");
   823             return;
   824           }
   825           current_frame.push_stack(type, CHECK_VERIFY(this));
   826           current_frame.push_stack(type3, CHECK_VERIFY(this));
   827           current_frame.push_stack(type2, CHECK_VERIFY(this));
   828           current_frame.push_stack(type, CHECK_VERIFY(this));
   829           no_control_flow = false; break;
   830         }
   831         case Bytecodes::_dup2 :
   832           type = current_frame.pop_stack(CHECK_VERIFY(this));
   833           if (type.is_category1()) {
   834             type2 = current_frame.pop_stack(
   835               VerificationType::category1_check(), CHECK_VERIFY(this));
   836           } else if (type.is_category2_2nd()) {
   837             type2 = current_frame.pop_stack(
   838               VerificationType::category2_check(), CHECK_VERIFY(this));
   839           } else {
   840             verify_error(bci, bad_type_msg, "dup2");
   841             return;
   842           }
   843           current_frame.push_stack(type2, CHECK_VERIFY(this));
   844           current_frame.push_stack(type, CHECK_VERIFY(this));
   845           current_frame.push_stack(type2, CHECK_VERIFY(this));
   846           current_frame.push_stack(type, CHECK_VERIFY(this));
   847           no_control_flow = false; break;
   848         case Bytecodes::_dup2_x1 :
   849         {
   850           VerificationType type3;
   851           type = current_frame.pop_stack(CHECK_VERIFY(this));
   852           if (type.is_category1()) {
   853             type2 = current_frame.pop_stack(
   854               VerificationType::category1_check(), CHECK_VERIFY(this));
   855           } else if(type.is_category2_2nd()) {
   856             type2 = current_frame.pop_stack
   857               (VerificationType::category2_check(), CHECK_VERIFY(this));
   858           } else {
   859             verify_error(bci, bad_type_msg, "dup2_x1");
   860             return;
   861           }
   862           type3 = current_frame.pop_stack(
   863             VerificationType::category1_check(), CHECK_VERIFY(this));
   864           current_frame.push_stack(type2, CHECK_VERIFY(this));
   865           current_frame.push_stack(type, CHECK_VERIFY(this));
   866           current_frame.push_stack(type3, CHECK_VERIFY(this));
   867           current_frame.push_stack(type2, CHECK_VERIFY(this));
   868           current_frame.push_stack(type, CHECK_VERIFY(this));
   869           no_control_flow = false; break;
   870         }
   871         case Bytecodes::_dup2_x2 :
   872         {
   873           VerificationType type3, type4;
   874           type = current_frame.pop_stack(CHECK_VERIFY(this));
   875           if (type.is_category1()) {
   876             type2 = current_frame.pop_stack(
   877               VerificationType::category1_check(), CHECK_VERIFY(this));
   878           } else if (type.is_category2_2nd()) {
   879             type2 = current_frame.pop_stack(
   880               VerificationType::category2_check(), CHECK_VERIFY(this));
   881           } else {
   882             verify_error(bci, bad_type_msg, "dup2_x2");
   883             return;
   884           }
   885           type3 = current_frame.pop_stack(CHECK_VERIFY(this));
   886           if (type3.is_category1()) {
   887             type4 = current_frame.pop_stack(
   888               VerificationType::category1_check(), CHECK_VERIFY(this));
   889           } else if (type3.is_category2_2nd()) {
   890             type4 = current_frame.pop_stack(
   891               VerificationType::category2_check(), CHECK_VERIFY(this));
   892           } else {
   893             verify_error(bci, bad_type_msg, "dup2_x2");
   894             return;
   895           }
   896           current_frame.push_stack(type2, CHECK_VERIFY(this));
   897           current_frame.push_stack(type, CHECK_VERIFY(this));
   898           current_frame.push_stack(type4, CHECK_VERIFY(this));
   899           current_frame.push_stack(type3, CHECK_VERIFY(this));
   900           current_frame.push_stack(type2, CHECK_VERIFY(this));
   901           current_frame.push_stack(type, CHECK_VERIFY(this));
   902           no_control_flow = false; break;
   903         }
   904         case Bytecodes::_swap :
   905           type = current_frame.pop_stack(
   906             VerificationType::category1_check(), CHECK_VERIFY(this));
   907           type2 = current_frame.pop_stack(
   908             VerificationType::category1_check(), CHECK_VERIFY(this));
   909           current_frame.push_stack(type, CHECK_VERIFY(this));
   910           current_frame.push_stack(type2, CHECK_VERIFY(this));
   911           no_control_flow = false; break;
   912         case Bytecodes::_iadd :
   913         case Bytecodes::_isub :
   914         case Bytecodes::_imul :
   915         case Bytecodes::_idiv :
   916         case Bytecodes::_irem :
   917         case Bytecodes::_ishl :
   918         case Bytecodes::_ishr :
   919         case Bytecodes::_iushr :
   920         case Bytecodes::_ior :
   921         case Bytecodes::_ixor :
   922         case Bytecodes::_iand :
   923           current_frame.pop_stack(
   924             VerificationType::integer_type(), CHECK_VERIFY(this));
   925           // fall through
   926         case Bytecodes::_ineg :
   927           current_frame.pop_stack(
   928             VerificationType::integer_type(), CHECK_VERIFY(this));
   929           current_frame.push_stack(
   930             VerificationType::integer_type(), CHECK_VERIFY(this));
   931           no_control_flow = false; break;
   932         case Bytecodes::_ladd :
   933         case Bytecodes::_lsub :
   934         case Bytecodes::_lmul :
   935         case Bytecodes::_ldiv :
   936         case Bytecodes::_lrem :
   937         case Bytecodes::_land :
   938         case Bytecodes::_lor :
   939         case Bytecodes::_lxor :
   940           current_frame.pop_stack_2(
   941             VerificationType::long2_type(),
   942             VerificationType::long_type(), CHECK_VERIFY(this));
   943           // fall through
   944         case Bytecodes::_lneg :
   945           current_frame.pop_stack_2(
   946             VerificationType::long2_type(),
   947             VerificationType::long_type(), CHECK_VERIFY(this));
   948           current_frame.push_stack_2(
   949             VerificationType::long_type(),
   950             VerificationType::long2_type(), CHECK_VERIFY(this));
   951           no_control_flow = false; break;
   952         case Bytecodes::_lshl :
   953         case Bytecodes::_lshr :
   954         case Bytecodes::_lushr :
   955           current_frame.pop_stack(
   956             VerificationType::integer_type(), CHECK_VERIFY(this));
   957           current_frame.pop_stack_2(
   958             VerificationType::long2_type(),
   959             VerificationType::long_type(), CHECK_VERIFY(this));
   960           current_frame.push_stack_2(
   961             VerificationType::long_type(),
   962             VerificationType::long2_type(), CHECK_VERIFY(this));
   963           no_control_flow = false; break;
   964         case Bytecodes::_fadd :
   965         case Bytecodes::_fsub :
   966         case Bytecodes::_fmul :
   967         case Bytecodes::_fdiv :
   968         case Bytecodes::_frem :
   969           current_frame.pop_stack(
   970             VerificationType::float_type(), CHECK_VERIFY(this));
   971           // fall through
   972         case Bytecodes::_fneg :
   973           current_frame.pop_stack(
   974             VerificationType::float_type(), CHECK_VERIFY(this));
   975           current_frame.push_stack(
   976             VerificationType::float_type(), CHECK_VERIFY(this));
   977           no_control_flow = false; break;
   978         case Bytecodes::_dadd :
   979         case Bytecodes::_dsub :
   980         case Bytecodes::_dmul :
   981         case Bytecodes::_ddiv :
   982         case Bytecodes::_drem :
   983           current_frame.pop_stack_2(
   984             VerificationType::double2_type(),
   985             VerificationType::double_type(), CHECK_VERIFY(this));
   986           // fall through
   987         case Bytecodes::_dneg :
   988           current_frame.pop_stack_2(
   989             VerificationType::double2_type(),
   990             VerificationType::double_type(), CHECK_VERIFY(this));
   991           current_frame.push_stack_2(
   992             VerificationType::double_type(),
   993             VerificationType::double2_type(), CHECK_VERIFY(this));
   994           no_control_flow = false; break;
   995         case Bytecodes::_iinc :
   996           verify_iinc(bcs.get_index(), &current_frame, CHECK_VERIFY(this));
   997           no_control_flow = false; break;
   998         case Bytecodes::_i2l :
   999           type = current_frame.pop_stack(
  1000             VerificationType::integer_type(), CHECK_VERIFY(this));
  1001           current_frame.push_stack_2(
  1002             VerificationType::long_type(),
  1003             VerificationType::long2_type(), CHECK_VERIFY(this));
  1004           no_control_flow = false; break;
  1005        case Bytecodes::_l2i :
  1006           current_frame.pop_stack_2(
  1007             VerificationType::long2_type(),
  1008             VerificationType::long_type(), CHECK_VERIFY(this));
  1009           current_frame.push_stack(
  1010             VerificationType::integer_type(), CHECK_VERIFY(this));
  1011           no_control_flow = false; break;
  1012         case Bytecodes::_i2f :
  1013           current_frame.pop_stack(
  1014             VerificationType::integer_type(), CHECK_VERIFY(this));
  1015           current_frame.push_stack(
  1016             VerificationType::float_type(), CHECK_VERIFY(this));
  1017           no_control_flow = false; break;
  1018         case Bytecodes::_i2d :
  1019           current_frame.pop_stack(
  1020             VerificationType::integer_type(), CHECK_VERIFY(this));
  1021           current_frame.push_stack_2(
  1022             VerificationType::double_type(),
  1023             VerificationType::double2_type(), CHECK_VERIFY(this));
  1024           no_control_flow = false; break;
  1025         case Bytecodes::_l2f :
  1026           current_frame.pop_stack_2(
  1027             VerificationType::long2_type(),
  1028             VerificationType::long_type(), CHECK_VERIFY(this));
  1029           current_frame.push_stack(
  1030             VerificationType::float_type(), CHECK_VERIFY(this));
  1031           no_control_flow = false; break;
  1032         case Bytecodes::_l2d :
  1033           current_frame.pop_stack_2(
  1034             VerificationType::long2_type(),
  1035             VerificationType::long_type(), CHECK_VERIFY(this));
  1036           current_frame.push_stack_2(
  1037             VerificationType::double_type(),
  1038             VerificationType::double2_type(), CHECK_VERIFY(this));
  1039           no_control_flow = false; break;
  1040         case Bytecodes::_f2i :
  1041           current_frame.pop_stack(
  1042             VerificationType::float_type(), CHECK_VERIFY(this));
  1043           current_frame.push_stack(
  1044             VerificationType::integer_type(), CHECK_VERIFY(this));
  1045           no_control_flow = false; break;
  1046         case Bytecodes::_f2l :
  1047           current_frame.pop_stack(
  1048             VerificationType::float_type(), CHECK_VERIFY(this));
  1049           current_frame.push_stack_2(
  1050             VerificationType::long_type(),
  1051             VerificationType::long2_type(), CHECK_VERIFY(this));
  1052           no_control_flow = false; break;
  1053         case Bytecodes::_f2d :
  1054           current_frame.pop_stack(
  1055             VerificationType::float_type(), CHECK_VERIFY(this));
  1056           current_frame.push_stack_2(
  1057             VerificationType::double_type(),
  1058             VerificationType::double2_type(), CHECK_VERIFY(this));
  1059           no_control_flow = false; break;
  1060         case Bytecodes::_d2i :
  1061           current_frame.pop_stack_2(
  1062             VerificationType::double2_type(),
  1063             VerificationType::double_type(), CHECK_VERIFY(this));
  1064           current_frame.push_stack(
  1065             VerificationType::integer_type(), CHECK_VERIFY(this));
  1066           no_control_flow = false; break;
  1067         case Bytecodes::_d2l :
  1068           current_frame.pop_stack_2(
  1069             VerificationType::double2_type(),
  1070             VerificationType::double_type(), CHECK_VERIFY(this));
  1071           current_frame.push_stack_2(
  1072             VerificationType::long_type(),
  1073             VerificationType::long2_type(), CHECK_VERIFY(this));
  1074           no_control_flow = false; break;
  1075         case Bytecodes::_d2f :
  1076           current_frame.pop_stack_2(
  1077             VerificationType::double2_type(),
  1078             VerificationType::double_type(), CHECK_VERIFY(this));
  1079           current_frame.push_stack(
  1080             VerificationType::float_type(), CHECK_VERIFY(this));
  1081           no_control_flow = false; break;
  1082         case Bytecodes::_i2b :
  1083         case Bytecodes::_i2c :
  1084         case Bytecodes::_i2s :
  1085           current_frame.pop_stack(
  1086             VerificationType::integer_type(), CHECK_VERIFY(this));
  1087           current_frame.push_stack(
  1088             VerificationType::integer_type(), CHECK_VERIFY(this));
  1089           no_control_flow = false; break;
  1090         case Bytecodes::_lcmp :
  1091           current_frame.pop_stack_2(
  1092             VerificationType::long2_type(),
  1093             VerificationType::long_type(), CHECK_VERIFY(this));
  1094           current_frame.pop_stack_2(
  1095             VerificationType::long2_type(),
  1096             VerificationType::long_type(), CHECK_VERIFY(this));
  1097           current_frame.push_stack(
  1098             VerificationType::integer_type(), CHECK_VERIFY(this));
  1099           no_control_flow = false; break;
  1100         case Bytecodes::_fcmpl :
  1101         case Bytecodes::_fcmpg :
  1102           current_frame.pop_stack(
  1103             VerificationType::float_type(), CHECK_VERIFY(this));
  1104           current_frame.pop_stack(
  1105             VerificationType::float_type(), CHECK_VERIFY(this));
  1106           current_frame.push_stack(
  1107             VerificationType::integer_type(), CHECK_VERIFY(this));
  1108           no_control_flow = false; break;
  1109         case Bytecodes::_dcmpl :
  1110         case Bytecodes::_dcmpg :
  1111           current_frame.pop_stack_2(
  1112             VerificationType::double2_type(),
  1113             VerificationType::double_type(), CHECK_VERIFY(this));
  1114           current_frame.pop_stack_2(
  1115             VerificationType::double2_type(),
  1116             VerificationType::double_type(), CHECK_VERIFY(this));
  1117           current_frame.push_stack(
  1118             VerificationType::integer_type(), CHECK_VERIFY(this));
  1119           no_control_flow = false; break;
  1120         case Bytecodes::_if_icmpeq:
  1121         case Bytecodes::_if_icmpne:
  1122         case Bytecodes::_if_icmplt:
  1123         case Bytecodes::_if_icmpge:
  1124         case Bytecodes::_if_icmpgt:
  1125         case Bytecodes::_if_icmple:
  1126           current_frame.pop_stack(
  1127             VerificationType::integer_type(), CHECK_VERIFY(this));
  1128           // fall through
  1129         case Bytecodes::_ifeq:
  1130         case Bytecodes::_ifne:
  1131         case Bytecodes::_iflt:
  1132         case Bytecodes::_ifge:
  1133         case Bytecodes::_ifgt:
  1134         case Bytecodes::_ifle:
  1135           current_frame.pop_stack(
  1136             VerificationType::integer_type(), CHECK_VERIFY(this));
  1137           target = bcs.dest();
  1138           stackmap_table.check_jump_target(
  1139             &current_frame, target, CHECK_VERIFY(this));
  1140           no_control_flow = false; break;
  1141         case Bytecodes::_if_acmpeq :
  1142         case Bytecodes::_if_acmpne :
  1143           current_frame.pop_stack(
  1144             VerificationType::reference_check(), CHECK_VERIFY(this));
  1145           // fall through
  1146         case Bytecodes::_ifnull :
  1147         case Bytecodes::_ifnonnull :
  1148           current_frame.pop_stack(
  1149             VerificationType::reference_check(), CHECK_VERIFY(this));
  1150           target = bcs.dest();
  1151           stackmap_table.check_jump_target
  1152             (&current_frame, target, CHECK_VERIFY(this));
  1153           no_control_flow = false; break;
  1154         case Bytecodes::_goto :
  1155           target = bcs.dest();
  1156           stackmap_table.check_jump_target(
  1157             &current_frame, target, CHECK_VERIFY(this));
  1158           no_control_flow = true; break;
  1159         case Bytecodes::_goto_w :
  1160           target = bcs.dest_w();
  1161           stackmap_table.check_jump_target(
  1162             &current_frame, target, CHECK_VERIFY(this));
  1163           no_control_flow = true; break;
  1164         case Bytecodes::_tableswitch :
  1165         case Bytecodes::_lookupswitch :
  1166           verify_switch(
  1167             &bcs, code_length, code_data, &current_frame,
  1168             &stackmap_table, CHECK_VERIFY(this));
  1169           no_control_flow = true; break;
  1170         case Bytecodes::_ireturn :
  1171           type = current_frame.pop_stack(
  1172             VerificationType::integer_type(), CHECK_VERIFY(this));
  1173           verify_return_value(return_type, type, bci, CHECK_VERIFY(this));
  1174           no_control_flow = true; break;
  1175         case Bytecodes::_lreturn :
  1176           type2 = current_frame.pop_stack(
  1177             VerificationType::long2_type(), CHECK_VERIFY(this));
  1178           type = current_frame.pop_stack(
  1179             VerificationType::long_type(), CHECK_VERIFY(this));
  1180           verify_return_value(return_type, type, bci, CHECK_VERIFY(this));
  1181           no_control_flow = true; break;
  1182         case Bytecodes::_freturn :
  1183           type = current_frame.pop_stack(
  1184             VerificationType::float_type(), CHECK_VERIFY(this));
  1185           verify_return_value(return_type, type, bci, CHECK_VERIFY(this));
  1186           no_control_flow = true; break;
  1187         case Bytecodes::_dreturn :
  1188           type2 = current_frame.pop_stack(
  1189             VerificationType::double2_type(),  CHECK_VERIFY(this));
  1190           type = current_frame.pop_stack(
  1191             VerificationType::double_type(), CHECK_VERIFY(this));
  1192           verify_return_value(return_type, type, bci, CHECK_VERIFY(this));
  1193           no_control_flow = true; break;
  1194         case Bytecodes::_areturn :
  1195           type = current_frame.pop_stack(
  1196             VerificationType::reference_check(), CHECK_VERIFY(this));
  1197           verify_return_value(return_type, type, bci, CHECK_VERIFY(this));
  1198           no_control_flow = true; break;
  1199         case Bytecodes::_return :
  1200           if (return_type != VerificationType::bogus_type()) {
  1201             verify_error(bci, "Method expects no return value");
  1202             return;
  1204           // Make sure "this" has been initialized if current method is an
  1205           // <init>
  1206           if (_method->name() == vmSymbols::object_initializer_name() &&
  1207               current_frame.flag_this_uninit()) {
  1208             verify_error(bci,
  1209               "Constructor must call super() or this() before return");
  1210             return;
  1212           no_control_flow = true; break;
  1213         case Bytecodes::_getstatic :
  1214         case Bytecodes::_putstatic :
  1215         case Bytecodes::_getfield :
  1216         case Bytecodes::_putfield :
  1217           verify_field_instructions(
  1218             &bcs, &current_frame, cp, CHECK_VERIFY(this));
  1219           no_control_flow = false; break;
  1220         case Bytecodes::_invokevirtual :
  1221         case Bytecodes::_invokespecial :
  1222         case Bytecodes::_invokestatic :
  1223           verify_invoke_instructions(
  1224             &bcs, code_length, &current_frame,
  1225             &this_uninit, return_type, cp, CHECK_VERIFY(this));
  1226           no_control_flow = false; break;
  1227         case Bytecodes::_invokeinterface :
  1228         case Bytecodes::_invokedynamic :
  1229           verify_invoke_instructions(
  1230             &bcs, code_length, &current_frame,
  1231             &this_uninit, return_type, cp, CHECK_VERIFY(this));
  1232           no_control_flow = false; break;
  1233         case Bytecodes::_new :
  1235           index = bcs.get_index_u2();
  1236           verify_cp_class_type(index, cp, CHECK_VERIFY(this));
  1237           VerificationType new_class_type =
  1238             cp_index_to_type(index, cp, CHECK_VERIFY(this));
  1239           if (!new_class_type.is_object()) {
  1240             verify_error(bci, "Illegal new instruction");
  1241             return;
  1243           type = VerificationType::uninitialized_type(bci);
  1244           current_frame.push_stack(type, CHECK_VERIFY(this));
  1245           no_control_flow = false; break;
  1247         case Bytecodes::_newarray :
  1248           type = get_newarray_type(bcs.get_index(), bci, CHECK_VERIFY(this));
  1249           current_frame.pop_stack(
  1250             VerificationType::integer_type(),  CHECK_VERIFY(this));
  1251           current_frame.push_stack(type, CHECK_VERIFY(this));
  1252           no_control_flow = false; break;
  1253         case Bytecodes::_anewarray :
  1254           verify_anewarray(
  1255             bcs.get_index_u2(), cp, &current_frame, CHECK_VERIFY(this));
  1256           no_control_flow = false; break;
  1257         case Bytecodes::_arraylength :
  1258           type = current_frame.pop_stack(
  1259             VerificationType::reference_check(), CHECK_VERIFY(this));
  1260           if (!(type.is_null() || type.is_array())) {
  1261             verify_error(bci, bad_type_msg, "arraylength");
  1263           current_frame.push_stack(
  1264             VerificationType::integer_type(), CHECK_VERIFY(this));
  1265           no_control_flow = false; break;
  1266         case Bytecodes::_checkcast :
  1268           index = bcs.get_index_u2();
  1269           verify_cp_class_type(index, cp, CHECK_VERIFY(this));
  1270           current_frame.pop_stack(object_type(), CHECK_VERIFY(this));
  1271           VerificationType klass_type = cp_index_to_type(
  1272             index, cp, CHECK_VERIFY(this));
  1273           current_frame.push_stack(klass_type, CHECK_VERIFY(this));
  1274           no_control_flow = false; break;
  1276         case Bytecodes::_instanceof : {
  1277           index = bcs.get_index_u2();
  1278           verify_cp_class_type(index, cp, CHECK_VERIFY(this));
  1279           current_frame.pop_stack(object_type(), CHECK_VERIFY(this));
  1280           current_frame.push_stack(
  1281             VerificationType::integer_type(), CHECK_VERIFY(this));
  1282           no_control_flow = false; break;
  1284         case Bytecodes::_monitorenter :
  1285         case Bytecodes::_monitorexit :
  1286           current_frame.pop_stack(
  1287             VerificationType::reference_check(), CHECK_VERIFY(this));
  1288           no_control_flow = false; break;
  1289         case Bytecodes::_multianewarray :
  1291           index = bcs.get_index_u2();
  1292           u2 dim = *(bcs.bcp()+3);
  1293           verify_cp_class_type(index, cp, CHECK_VERIFY(this));
  1294           VerificationType new_array_type =
  1295             cp_index_to_type(index, cp, CHECK_VERIFY(this));
  1296           if (!new_array_type.is_array()) {
  1297             verify_error(bci,
  1298               "Illegal constant pool index in multianewarray instruction");
  1299             return;
  1301           if (dim < 1 || new_array_type.dimensions() < dim) {
  1302             verify_error(bci,
  1303               "Illegal dimension in multianewarray instruction");
  1304             return;
  1306           for (int i = 0; i < dim; i++) {
  1307             current_frame.pop_stack(
  1308               VerificationType::integer_type(), CHECK_VERIFY(this));
  1310           current_frame.push_stack(new_array_type, CHECK_VERIFY(this));
  1311           no_control_flow = false; break;
  1313         case Bytecodes::_athrow :
  1314           type = VerificationType::reference_type(
  1315             vmSymbols::java_lang_Throwable());
  1316           current_frame.pop_stack(type, CHECK_VERIFY(this));
  1317           no_control_flow = true; break;
  1318         default:
  1319           // We only need to check the valid bytecodes in class file.
  1320           // And jsr and ret are not in the new class file format in JDK1.5.
  1321           verify_error(bci, "Bad instruction");
  1322           no_control_flow = false;
  1323           return;
  1324       }  // end switch
  1325     }  // end Merge with the next instruction
  1327     // Look for possible jump target in exception handlers and see if it
  1328     // matches current_frame
  1329     if (bci >= ex_min && bci < ex_max) {
  1330       verify_exception_handler_targets(
  1331         bci, this_uninit, &current_frame, &stackmap_table, CHECK_VERIFY(this));
  1333   } // end while
  1335   // Make sure that control flow does not fall through end of the method
  1336   if (!no_control_flow) {
  1337     verify_error(code_length, "Control flow falls through code end");
  1338     return;
  1342 char* ClassVerifier::generate_code_data(methodHandle m, u4 code_length, TRAPS) {
  1343   char* code_data = NEW_RESOURCE_ARRAY(char, code_length);
  1344   memset(code_data, 0, sizeof(char) * code_length);
  1345   RawBytecodeStream bcs(m);
  1347   while (!bcs.is_last_bytecode()) {
  1348     if (bcs.raw_next() != Bytecodes::_illegal) {
  1349       int bci = bcs.bci();
  1350       if (bcs.raw_code() == Bytecodes::_new) {
  1351         code_data[bci] = NEW_OFFSET;
  1352       } else {
  1353         code_data[bci] = BYTECODE_OFFSET;
  1355     } else {
  1356       verify_error(bcs.bci(), "Bad instruction");
  1357       return NULL;
  1361   return code_data;
  1364 void ClassVerifier::verify_exception_handler_table(u4 code_length, char* code_data, int& min, int& max, TRAPS) {
  1365   typeArrayHandle exhandlers (THREAD, _method->exception_table());
  1366   constantPoolHandle cp (THREAD, _method->constants());
  1368   if (exhandlers() != NULL) {
  1369     for(int i = 0; i < exhandlers->length();) {
  1370       u2 start_pc = exhandlers->int_at(i++);
  1371       u2 end_pc = exhandlers->int_at(i++);
  1372       u2 handler_pc = exhandlers->int_at(i++);
  1373       if (start_pc >= code_length || code_data[start_pc] == 0) {
  1374         class_format_error("Illegal exception table start_pc %d", start_pc);
  1375         return;
  1377       if (end_pc != code_length) {   // special case: end_pc == code_length
  1378         if (end_pc > code_length || code_data[end_pc] == 0) {
  1379           class_format_error("Illegal exception table end_pc %d", end_pc);
  1380           return;
  1383       if (handler_pc >= code_length || code_data[handler_pc] == 0) {
  1384         class_format_error("Illegal exception table handler_pc %d", handler_pc);
  1385         return;
  1387       int catch_type_index = exhandlers->int_at(i++);
  1388       if (catch_type_index != 0) {
  1389         VerificationType catch_type = cp_index_to_type(
  1390           catch_type_index, cp, CHECK_VERIFY(this));
  1391         VerificationType throwable =
  1392           VerificationType::reference_type(vmSymbols::java_lang_Throwable());
  1393         bool is_subclass = throwable.is_assignable_from(
  1394           catch_type, this, CHECK_VERIFY(this));
  1395         if (!is_subclass) {
  1396           // 4286534: should throw VerifyError according to recent spec change
  1397           verify_error(
  1398             "Catch type is not a subclass of Throwable in handler %d",
  1399             handler_pc);
  1400           return;
  1403       if (start_pc < min) min = start_pc;
  1404       if (end_pc > max) max = end_pc;
  1409 void ClassVerifier::verify_local_variable_table(u4 code_length, char* code_data, TRAPS) {
  1410   int localvariable_table_length = _method()->localvariable_table_length();
  1411   if (localvariable_table_length > 0) {
  1412     LocalVariableTableElement* table = _method()->localvariable_table_start();
  1413     for (int i = 0; i < localvariable_table_length; i++) {
  1414       u2 start_bci = table[i].start_bci;
  1415       u2 length = table[i].length;
  1417       if (start_bci >= code_length || code_data[start_bci] == 0) {
  1418         class_format_error(
  1419           "Illegal local variable table start_pc %d", start_bci);
  1420         return;
  1422       u4 end_bci = (u4)(start_bci + length);
  1423       if (end_bci != code_length) {
  1424         if (end_bci >= code_length || code_data[end_bci] == 0) {
  1425           class_format_error( "Illegal local variable table length %d", length);
  1426           return;
  1433 u2 ClassVerifier::verify_stackmap_table(u2 stackmap_index, u2 bci,
  1434                                         StackMapFrame* current_frame,
  1435                                         StackMapTable* stackmap_table,
  1436                                         bool no_control_flow, TRAPS) {
  1437   if (stackmap_index < stackmap_table->get_frame_count()) {
  1438     u2 this_offset = stackmap_table->get_offset(stackmap_index);
  1439     if (no_control_flow && this_offset > bci) {
  1440       verify_error(bci, "Expecting a stack map frame");
  1441       return 0;
  1443     if (this_offset == bci) {
  1444       // See if current stack map can be assigned to the frame in table.
  1445       // current_frame is the stackmap frame got from the last instruction.
  1446       // If matched, current_frame will be updated by this method.
  1447       bool match = stackmap_table->match_stackmap(
  1448         current_frame, this_offset, stackmap_index,
  1449         !no_control_flow, true, CHECK_VERIFY_(this, 0));
  1450       if (!match) {
  1451         // report type error
  1452         verify_error(bci, "Instruction type does not match stack map");
  1453         return 0;
  1455       stackmap_index++;
  1456     } else if (this_offset < bci) {
  1457       // current_offset should have met this_offset.
  1458       class_format_error("Bad stack map offset %d", this_offset);
  1459       return 0;
  1461   } else if (no_control_flow) {
  1462     verify_error(bci, "Expecting a stack map frame");
  1463     return 0;
  1465   return stackmap_index;
  1468 void ClassVerifier::verify_exception_handler_targets(u2 bci, bool this_uninit, StackMapFrame* current_frame,
  1469                                                      StackMapTable* stackmap_table, TRAPS) {
  1470   constantPoolHandle cp (THREAD, _method->constants());
  1471   typeArrayHandle exhandlers (THREAD, _method->exception_table());
  1472   if (exhandlers() != NULL) {
  1473     for(int i = 0; i < exhandlers->length();) {
  1474       u2 start_pc = exhandlers->int_at(i++);
  1475       u2 end_pc = exhandlers->int_at(i++);
  1476       u2 handler_pc = exhandlers->int_at(i++);
  1477       int catch_type_index = exhandlers->int_at(i++);
  1478       if(bci >= start_pc && bci < end_pc) {
  1479         u1 flags = current_frame->flags();
  1480         if (this_uninit) {  flags |= FLAG_THIS_UNINIT; }
  1481         StackMapFrame* new_frame = current_frame->frame_in_exception_handler(flags);
  1482         if (catch_type_index != 0) {
  1483           // We know that this index refers to a subclass of Throwable
  1484           VerificationType catch_type = cp_index_to_type(
  1485             catch_type_index, cp, CHECK_VERIFY(this));
  1486           new_frame->push_stack(catch_type, CHECK_VERIFY(this));
  1487         } else {
  1488           VerificationType throwable =
  1489             VerificationType::reference_type(vmSymbols::java_lang_Throwable());
  1490           new_frame->push_stack(throwable, CHECK_VERIFY(this));
  1492         bool match = stackmap_table->match_stackmap(
  1493           new_frame, handler_pc, true, false, CHECK_VERIFY(this));
  1494         if (!match) {
  1495           verify_error(bci,
  1496             "Stack map does not match the one at exception handler %d",
  1497             handler_pc);
  1498           return;
  1505 void ClassVerifier::verify_cp_index(constantPoolHandle cp, int index, TRAPS) {
  1506   int nconstants = cp->length();
  1507   if ((index <= 0) || (index >= nconstants)) {
  1508     verify_error("Illegal constant pool index %d in class %s",
  1509       index, instanceKlass::cast(cp->pool_holder())->external_name());
  1510     return;
  1514 void ClassVerifier::verify_cp_type(
  1515     int index, constantPoolHandle cp, unsigned int types, TRAPS) {
  1517   // In some situations, bytecode rewriting may occur while we're verifying.
  1518   // In this case, a constant pool cache exists and some indices refer to that
  1519   // instead.  Be sure we don't pick up such indices by accident.
  1520   // We must check was_recursively_verified() before we get here.
  1521   guarantee(cp->cache() == NULL, "not rewritten yet");
  1523   verify_cp_index(cp, index, CHECK_VERIFY(this));
  1524   unsigned int tag = cp->tag_at(index).value();
  1525   if ((types & (1 << tag)) == 0) {
  1526     verify_error(
  1527       "Illegal type at constant pool entry %d in class %s",
  1528       index, instanceKlass::cast(cp->pool_holder())->external_name());
  1529     return;
  1533 void ClassVerifier::verify_cp_class_type(
  1534     int index, constantPoolHandle cp, TRAPS) {
  1535   verify_cp_index(cp, index, CHECK_VERIFY(this));
  1536   constantTag tag = cp->tag_at(index);
  1537   if (!tag.is_klass() && !tag.is_unresolved_klass()) {
  1538     verify_error("Illegal type at constant pool entry %d in class %s",
  1539       index, instanceKlass::cast(cp->pool_holder())->external_name());
  1540     return;
  1544 void ClassVerifier::format_error_message(
  1545     const char* fmt, int offset, va_list va) {
  1546   ResourceMark rm(_thread);
  1547   stringStream message(_message, _message_buffer_len);
  1548   message.vprint(fmt, va);
  1549   if (!_method.is_null()) {
  1550     message.print(" in method %s", _method->name_and_sig_as_C_string());
  1552   if (offset != -1) {
  1553     message.print(" at offset %d", offset);
  1557 void ClassVerifier::verify_error(u2 offset, const char* fmt, ...) {
  1558   _exception_type = vmSymbols::java_lang_VerifyError();
  1559   va_list va;
  1560   va_start(va, fmt);
  1561   format_error_message(fmt, offset, va);
  1562   va_end(va);
  1565 void ClassVerifier::verify_error(const char* fmt, ...) {
  1566   _exception_type = vmSymbols::java_lang_VerifyError();
  1567   va_list va;
  1568   va_start(va, fmt);
  1569   format_error_message(fmt, -1, va);
  1570   va_end(va);
  1573 void ClassVerifier::class_format_error(const char* msg, ...) {
  1574   _exception_type = vmSymbols::java_lang_ClassFormatError();
  1575   va_list va;
  1576   va_start(va, msg);
  1577   format_error_message(msg, -1, va);
  1578   va_end(va);
  1581 klassOop ClassVerifier::load_class(Symbol* name, TRAPS) {
  1582   // Get current loader and protection domain first.
  1583   oop loader = current_class()->class_loader();
  1584   oop protection_domain = current_class()->protection_domain();
  1586   return SystemDictionary::resolve_or_fail(
  1587     name, Handle(THREAD, loader), Handle(THREAD, protection_domain),
  1588     true, CHECK_NULL);
  1591 bool ClassVerifier::is_protected_access(instanceKlassHandle this_class,
  1592                                         klassOop target_class,
  1593                                         Symbol* field_name,
  1594                                         Symbol* field_sig,
  1595                                         bool is_method) {
  1596   No_Safepoint_Verifier nosafepoint;
  1598   // If target class isn't a super class of this class, we don't worry about this case
  1599   if (!this_class->is_subclass_of(target_class)) {
  1600     return false;
  1602   // Check if the specified method or field is protected
  1603   instanceKlass* target_instance = instanceKlass::cast(target_class);
  1604   fieldDescriptor fd;
  1605   if (is_method) {
  1606     methodOop m = target_instance->uncached_lookup_method(field_name, field_sig);
  1607     if (m != NULL && m->is_protected()) {
  1608       if (!this_class->is_same_class_package(m->method_holder())) {
  1609         return true;
  1612   } else {
  1613     klassOop member_klass = target_instance->find_field(field_name, field_sig, &fd);
  1614     if(member_klass != NULL && fd.is_protected()) {
  1615       if (!this_class->is_same_class_package(member_klass)) {
  1616         return true;
  1620   return false;
  1623 void ClassVerifier::verify_ldc(
  1624     int opcode, u2 index, StackMapFrame *current_frame,
  1625      constantPoolHandle cp, u2 bci, TRAPS) {
  1626   verify_cp_index(cp, index, CHECK_VERIFY(this));
  1627   constantTag tag = cp->tag_at(index);
  1628   unsigned int types;
  1629   if (opcode == Bytecodes::_ldc || opcode == Bytecodes::_ldc_w) {
  1630     if (!tag.is_unresolved_string() && !tag.is_unresolved_klass()) {
  1631       types = (1 << JVM_CONSTANT_Integer) | (1 << JVM_CONSTANT_Float)
  1632             | (1 << JVM_CONSTANT_String)  | (1 << JVM_CONSTANT_Class)
  1633             | (1 << JVM_CONSTANT_MethodHandle) | (1 << JVM_CONSTANT_MethodType);
  1634       // Note:  The class file parser already verified the legality of
  1635       // MethodHandle and MethodType constants.
  1636       verify_cp_type(index, cp, types, CHECK_VERIFY(this));
  1638   } else {
  1639     assert(opcode == Bytecodes::_ldc2_w, "must be ldc2_w");
  1640     types = (1 << JVM_CONSTANT_Double) | (1 << JVM_CONSTANT_Long);
  1641     verify_cp_type(index, cp, types, CHECK_VERIFY(this));
  1643   if (tag.is_string() && cp->is_pseudo_string_at(index)) {
  1644     current_frame->push_stack(object_type(), CHECK_VERIFY(this));
  1645   } else if (tag.is_string() || tag.is_unresolved_string()) {
  1646     current_frame->push_stack(
  1647       VerificationType::reference_type(
  1648         vmSymbols::java_lang_String()), CHECK_VERIFY(this));
  1649   } else if (tag.is_klass() || tag.is_unresolved_klass()) {
  1650     current_frame->push_stack(
  1651       VerificationType::reference_type(
  1652         vmSymbols::java_lang_Class()), CHECK_VERIFY(this));
  1653   } else if (tag.is_int()) {
  1654     current_frame->push_stack(
  1655       VerificationType::integer_type(), CHECK_VERIFY(this));
  1656   } else if (tag.is_float()) {
  1657     current_frame->push_stack(
  1658       VerificationType::float_type(), CHECK_VERIFY(this));
  1659   } else if (tag.is_double()) {
  1660     current_frame->push_stack_2(
  1661       VerificationType::double_type(),
  1662       VerificationType::double2_type(), CHECK_VERIFY(this));
  1663   } else if (tag.is_long()) {
  1664     current_frame->push_stack_2(
  1665       VerificationType::long_type(),
  1666       VerificationType::long2_type(), CHECK_VERIFY(this));
  1667   } else if (tag.is_method_handle()) {
  1668     current_frame->push_stack(
  1669       VerificationType::reference_type(
  1670         vmSymbols::java_dyn_MethodHandle()), CHECK_VERIFY(this));
  1671   } else if (tag.is_method_type()) {
  1672     current_frame->push_stack(
  1673       VerificationType::reference_type(
  1674         vmSymbols::java_dyn_MethodType()), CHECK_VERIFY(this));
  1675   } else {
  1676     verify_error(bci, "Invalid index in ldc");
  1677     return;
  1681 void ClassVerifier::verify_switch(
  1682     RawBytecodeStream* bcs, u4 code_length, char* code_data,
  1683     StackMapFrame* current_frame, StackMapTable* stackmap_table, TRAPS) {
  1684   int bci = bcs->bci();
  1685   address bcp = bcs->bcp();
  1686   address aligned_bcp = (address) round_to((intptr_t)(bcp + 1), jintSize);
  1688   // 4639449 & 4647081: padding bytes must be 0
  1689   u2 padding_offset = 1;
  1690   while ((bcp + padding_offset) < aligned_bcp) {
  1691     if(*(bcp + padding_offset) != 0) {
  1692       verify_error(bci, "Nonzero padding byte in lookswitch or tableswitch");
  1693       return;
  1695     padding_offset++;
  1697   int default_offset = (int) Bytes::get_Java_u4(aligned_bcp);
  1698   int keys, delta;
  1699   current_frame->pop_stack(
  1700     VerificationType::integer_type(), CHECK_VERIFY(this));
  1701   if (bcs->raw_code() == Bytecodes::_tableswitch) {
  1702     jint low = (jint)Bytes::get_Java_u4(aligned_bcp + jintSize);
  1703     jint high = (jint)Bytes::get_Java_u4(aligned_bcp + 2*jintSize);
  1704     if (low > high) {
  1705       verify_error(bci,
  1706         "low must be less than or equal to high in tableswitch");
  1707       return;
  1709     keys = high - low + 1;
  1710     if (keys < 0) {
  1711       verify_error(bci, "too many keys in tableswitch");
  1712       return;
  1714     delta = 1;
  1715   } else {
  1716     keys = (int)Bytes::get_Java_u4(aligned_bcp + jintSize);
  1717     if (keys < 0) {
  1718       verify_error(bci, "number of keys in lookupswitch less than 0");
  1719       return;
  1721     delta = 2;
  1722     // Make sure that the lookupswitch items are sorted
  1723     for (int i = 0; i < (keys - 1); i++) {
  1724       jint this_key = Bytes::get_Java_u4(aligned_bcp + (2+2*i)*jintSize);
  1725       jint next_key = Bytes::get_Java_u4(aligned_bcp + (2+2*i+2)*jintSize);
  1726       if (this_key >= next_key) {
  1727         verify_error(bci, "Bad lookupswitch instruction");
  1728         return;
  1732   int target = bci + default_offset;
  1733   stackmap_table->check_jump_target(current_frame, target, CHECK_VERIFY(this));
  1734   for (int i = 0; i < keys; i++) {
  1735     target = bci + (jint)Bytes::get_Java_u4(aligned_bcp+(3+i*delta)*jintSize);
  1736     stackmap_table->check_jump_target(
  1737       current_frame, target, CHECK_VERIFY(this));
  1741 bool ClassVerifier::name_in_supers(
  1742     Symbol* ref_name, instanceKlassHandle current) {
  1743   klassOop super = current->super();
  1744   while (super != NULL) {
  1745     if (super->klass_part()->name() == ref_name) {
  1746       return true;
  1748     super = super->klass_part()->super();
  1750   return false;
  1753 void ClassVerifier::verify_field_instructions(RawBytecodeStream* bcs,
  1754                                               StackMapFrame* current_frame,
  1755                                               constantPoolHandle cp,
  1756                                               TRAPS) {
  1757   u2 index = bcs->get_index_u2();
  1758   verify_cp_type(index, cp, 1 << JVM_CONSTANT_Fieldref, CHECK_VERIFY(this));
  1760   // Get field name and signature
  1761   Symbol* field_name = cp->name_ref_at(index);
  1762   Symbol* field_sig = cp->signature_ref_at(index);
  1764   if (!SignatureVerifier::is_valid_type_signature(field_sig)) {
  1765     class_format_error(
  1766       "Invalid signature for field in class %s referenced "
  1767       "from constant pool index %d", _klass->external_name(), index);
  1768     return;
  1771   // Get referenced class type
  1772   VerificationType ref_class_type = cp_ref_index_to_type(
  1773     index, cp, CHECK_VERIFY(this));
  1774   if (!ref_class_type.is_object()) {
  1775     verify_error(
  1776       "Expecting reference to class in class %s at constant pool index %d",
  1777       _klass->external_name(), index);
  1778     return;
  1780   VerificationType target_class_type = ref_class_type;
  1782   assert(sizeof(VerificationType) == sizeof(uintptr_t),
  1783         "buffer type must match VerificationType size");
  1784   uintptr_t field_type_buffer[2];
  1785   VerificationType* field_type = (VerificationType*)field_type_buffer;
  1786   // If we make a VerificationType[2] array directly, the compiler calls
  1787   // to the c-runtime library to do the allocation instead of just
  1788   // stack allocating it.  Plus it would run constructors.  This shows up
  1789   // in performance profiles.
  1791   SignatureStream sig_stream(field_sig, false);
  1792   VerificationType stack_object_type;
  1793   int n = change_sig_to_verificationType(
  1794     &sig_stream, field_type, CHECK_VERIFY(this));
  1795   u2 bci = bcs->bci();
  1796   bool is_assignable;
  1797   switch (bcs->raw_code()) {
  1798     case Bytecodes::_getstatic: {
  1799       for (int i = 0; i < n; i++) {
  1800         current_frame->push_stack(field_type[i], CHECK_VERIFY(this));
  1802       break;
  1804     case Bytecodes::_putstatic: {
  1805       for (int i = n - 1; i >= 0; i--) {
  1806         current_frame->pop_stack(field_type[i], CHECK_VERIFY(this));
  1808       break;
  1810     case Bytecodes::_getfield: {
  1811       stack_object_type = current_frame->pop_stack(
  1812         target_class_type, CHECK_VERIFY(this));
  1813       for (int i = 0; i < n; i++) {
  1814         current_frame->push_stack(field_type[i], CHECK_VERIFY(this));
  1816       goto check_protected;
  1818     case Bytecodes::_putfield: {
  1819       for (int i = n - 1; i >= 0; i--) {
  1820         current_frame->pop_stack(field_type[i], CHECK_VERIFY(this));
  1822       stack_object_type = current_frame->pop_stack(CHECK_VERIFY(this));
  1824       // The JVMS 2nd edition allows field initialization before the superclass
  1825       // initializer, if the field is defined within the current class.
  1826       fieldDescriptor fd;
  1827       if (stack_object_type == VerificationType::uninitialized_this_type() &&
  1828           target_class_type.equals(current_type()) &&
  1829           _klass->find_local_field(field_name, field_sig, &fd)) {
  1830         stack_object_type = current_type();
  1832       is_assignable = target_class_type.is_assignable_from(
  1833         stack_object_type, this, CHECK_VERIFY(this));
  1834       if (!is_assignable) {
  1835         verify_error(bci, "Bad type on operand stack in putfield");
  1836         return;
  1839     check_protected: {
  1840       if (_this_type == stack_object_type)
  1841         break; // stack_object_type must be assignable to _current_class_type
  1842       Symbol* ref_class_name =
  1843         cp->klass_name_at(cp->klass_ref_index_at(index));
  1844       if (!name_in_supers(ref_class_name, current_class()))
  1845         // stack_object_type must be assignable to _current_class_type since:
  1846         // 1. stack_object_type must be assignable to ref_class.
  1847         // 2. ref_class must be _current_class or a subclass of it. It can't
  1848         //    be a superclass of it. See revised JVMS 5.4.4.
  1849         break;
  1851       klassOop ref_class_oop = load_class(ref_class_name, CHECK);
  1852       if (is_protected_access(current_class(), ref_class_oop, field_name,
  1853                               field_sig, false)) {
  1854         // It's protected access, check if stack object is assignable to
  1855         // current class.
  1856         is_assignable = current_type().is_assignable_from(
  1857           stack_object_type, this, CHECK_VERIFY(this));
  1858         if (!is_assignable) {
  1859           verify_error(bci, "Bad access to protected data in getfield");
  1860           return;
  1863       break;
  1865     default: ShouldNotReachHere();
  1869 void ClassVerifier::verify_invoke_init(
  1870     RawBytecodeStream* bcs, VerificationType ref_class_type,
  1871     StackMapFrame* current_frame, u4 code_length, bool *this_uninit,
  1872     constantPoolHandle cp, TRAPS) {
  1873   u2 bci = bcs->bci();
  1874   VerificationType type = current_frame->pop_stack(
  1875     VerificationType::reference_check(), CHECK_VERIFY(this));
  1876   if (type == VerificationType::uninitialized_this_type()) {
  1877     // The method must be an <init> method of either this class, or one of its
  1878     // superclasses
  1879     if (ref_class_type.name() != current_class()->name() &&
  1880         !name_in_supers(ref_class_type.name(), current_class())) {
  1881       verify_error(bci, "Bad <init> method call");
  1882       return;
  1884     current_frame->initialize_object(type, current_type());
  1885     *this_uninit = true;
  1886   } else if (type.is_uninitialized()) {
  1887     u2 new_offset = type.bci();
  1888     address new_bcp = bcs->bcp() - bci + new_offset;
  1889     if (new_offset > (code_length - 3) || (*new_bcp) != Bytecodes::_new) {
  1890       verify_error(new_offset, "Expecting new instruction");
  1891       return;
  1893     u2 new_class_index = Bytes::get_Java_u2(new_bcp + 1);
  1894     verify_cp_class_type(new_class_index, cp, CHECK_VERIFY(this));
  1896     // The method must be an <init> method of the indicated class
  1897     VerificationType new_class_type = cp_index_to_type(
  1898       new_class_index, cp, CHECK_VERIFY(this));
  1899     if (!new_class_type.equals(ref_class_type)) {
  1900       verify_error(bci, "Call to wrong <init> method");
  1901       return;
  1903     // According to the VM spec, if the referent class is a superclass of the
  1904     // current class, and is in a different runtime package, and the method is
  1905     // protected, then the objectref must be the current class or a subclass
  1906     // of the current class.
  1907     VerificationType objectref_type = new_class_type;
  1908     if (name_in_supers(ref_class_type.name(), current_class())) {
  1909       klassOop ref_klass = load_class(
  1910         ref_class_type.name(), CHECK_VERIFY(this));
  1911       methodOop m = instanceKlass::cast(ref_klass)->uncached_lookup_method(
  1912         vmSymbols::object_initializer_name(),
  1913         cp->signature_ref_at(bcs->get_index_u2()));
  1914       instanceKlassHandle mh(THREAD, m->method_holder());
  1915       if (m->is_protected() && !mh->is_same_class_package(_klass())) {
  1916         bool assignable = current_type().is_assignable_from(
  1917           objectref_type, this, CHECK_VERIFY(this));
  1918         if (!assignable) {
  1919           verify_error(bci, "Bad access to protected <init> method");
  1920           return;
  1924     current_frame->initialize_object(type, new_class_type);
  1925   } else {
  1926     verify_error(bci, "Bad operand type when invoking <init>");
  1927     return;
  1931 void ClassVerifier::verify_invoke_instructions(
  1932     RawBytecodeStream* bcs, u4 code_length, StackMapFrame* current_frame,
  1933     bool *this_uninit, VerificationType return_type,
  1934     constantPoolHandle cp, TRAPS) {
  1935   // Make sure the constant pool item is the right type
  1936   u2 index = bcs->get_index_u2();
  1937   Bytecodes::Code opcode = bcs->raw_code();
  1938   unsigned int types = (opcode == Bytecodes::_invokeinterface
  1939                                 ? 1 << JVM_CONSTANT_InterfaceMethodref
  1940                       : opcode == Bytecodes::_invokedynamic
  1941                                 ? ((AllowTransitionalJSR292 ? 1 << JVM_CONSTANT_NameAndType : 0)
  1942                                   |1 << JVM_CONSTANT_InvokeDynamic)
  1943                                 : 1 << JVM_CONSTANT_Methodref);
  1944   verify_cp_type(index, cp, types, CHECK_VERIFY(this));
  1946   // Get method name and signature
  1947   Symbol* method_name = cp->name_ref_at(index);
  1948   Symbol* method_sig = cp->signature_ref_at(index);
  1950   if (!SignatureVerifier::is_valid_method_signature(method_sig)) {
  1951     class_format_error(
  1952       "Invalid method signature in class %s referenced "
  1953       "from constant pool index %d", _klass->external_name(), index);
  1954     return;
  1957   // Get referenced class type
  1958   VerificationType ref_class_type;
  1959   if (opcode == Bytecodes::_invokedynamic) {
  1960     if (!EnableInvokeDynamic ||
  1961         _klass->major_version() < Verifier::INVOKEDYNAMIC_MAJOR_VERSION) {
  1962       class_format_error(
  1963         (!EnableInvokeDynamic ?
  1964          "invokedynamic instructions not enabled in this JVM" :
  1965          "invokedynamic instructions not supported by this class file version"),
  1966         _klass->external_name());
  1967       return;
  1969   } else {
  1970     ref_class_type = cp_ref_index_to_type(index, cp, CHECK_VERIFY(this));
  1973   // For a small signature length, we just allocate 128 bytes instead
  1974   // of parsing the signature once to find its size.
  1975   // -3 is for '(', ')' and return descriptor; multiply by 2 is for
  1976   // longs/doubles to be consertive.
  1977   assert(sizeof(VerificationType) == sizeof(uintptr_t),
  1978         "buffer type must match VerificationType size");
  1979   uintptr_t on_stack_sig_types_buffer[128];
  1980   // If we make a VerificationType[128] array directly, the compiler calls
  1981   // to the c-runtime library to do the allocation instead of just
  1982   // stack allocating it.  Plus it would run constructors.  This shows up
  1983   // in performance profiles.
  1985   VerificationType* sig_types;
  1986   int size = (method_sig->utf8_length() - 3) * 2;
  1987   if (size > 128) {
  1988     // Long and double occupies two slots here.
  1989     ArgumentSizeComputer size_it(method_sig);
  1990     size = size_it.size();
  1991     sig_types = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, VerificationType, size);
  1992   } else{
  1993     sig_types = (VerificationType*)on_stack_sig_types_buffer;
  1995   SignatureStream sig_stream(method_sig);
  1996   int sig_i = 0;
  1997   while (!sig_stream.at_return_type()) {
  1998     sig_i += change_sig_to_verificationType(
  1999       &sig_stream, &sig_types[sig_i], CHECK_VERIFY(this));
  2000     sig_stream.next();
  2002   int nargs = sig_i;
  2004 #ifdef ASSERT
  2006     ArgumentSizeComputer size_it(method_sig);
  2007     assert(nargs == size_it.size(), "Argument sizes do not match");
  2008     assert(nargs <= (method_sig->utf8_length() - 3) * 2, "estimate of max size isn't conservative enough");
  2010 #endif
  2012   // Check instruction operands
  2013   u2 bci = bcs->bci();
  2014   if (opcode == Bytecodes::_invokeinterface) {
  2015     address bcp = bcs->bcp();
  2016     // 4905268: count operand in invokeinterface should be nargs+1, not nargs.
  2017     // JSR202 spec: The count operand of an invokeinterface instruction is valid if it is
  2018     // the difference between the size of the operand stack before and after the instruction
  2019     // executes.
  2020     if (*(bcp+3) != (nargs+1)) {
  2021       verify_error(bci, "Inconsistent args count operand in invokeinterface");
  2022       return;
  2024     if (*(bcp+4) != 0) {
  2025       verify_error(bci, "Fourth operand byte of invokeinterface must be zero");
  2026       return;
  2030   if (opcode == Bytecodes::_invokedynamic) {
  2031     address bcp = bcs->bcp();
  2032     if (*(bcp+3) != 0 || *(bcp+4) != 0) {
  2033       verify_error(bci, "Third and fourth operand bytes of invokedynamic must be zero");
  2034       return;
  2038   if (method_name->byte_at(0) == '<') {
  2039     // Make sure <init> can only be invoked by invokespecial
  2040     if (opcode != Bytecodes::_invokespecial ||
  2041         method_name != vmSymbols::object_initializer_name()) {
  2042       verify_error(bci, "Illegal call to internal method");
  2043       return;
  2045   } else if (opcode == Bytecodes::_invokespecial
  2046              && !ref_class_type.equals(current_type())
  2047              && !ref_class_type.equals(VerificationType::reference_type(
  2048                   current_class()->super()->klass_part()->name()))) {
  2049     bool subtype = ref_class_type.is_assignable_from(
  2050       current_type(), this, CHECK_VERIFY(this));
  2051     if (!subtype) {
  2052       verify_error(bci, "Bad invokespecial instruction: "
  2053           "current class isn't assignable to reference class.");
  2054        return;
  2057   // Match method descriptor with operand stack
  2058   for (int i = nargs - 1; i >= 0; i--) {  // Run backwards
  2059     current_frame->pop_stack(sig_types[i], CHECK_VERIFY(this));
  2061   // Check objectref on operand stack
  2062   if (opcode != Bytecodes::_invokestatic &&
  2063       opcode != Bytecodes::_invokedynamic) {
  2064     if (method_name == vmSymbols::object_initializer_name()) {  // <init> method
  2065       verify_invoke_init(bcs, ref_class_type, current_frame,
  2066         code_length, this_uninit, cp, CHECK_VERIFY(this));
  2067     } else {   // other methods
  2068       // Ensures that target class is assignable to method class.
  2069       if (opcode == Bytecodes::_invokespecial) {
  2070         current_frame->pop_stack(current_type(), CHECK_VERIFY(this));
  2071       } else if (opcode == Bytecodes::_invokevirtual) {
  2072         VerificationType stack_object_type =
  2073           current_frame->pop_stack(ref_class_type, CHECK_VERIFY(this));
  2074         if (current_type() != stack_object_type) {
  2075           assert(cp->cache() == NULL, "not rewritten yet");
  2076           Symbol* ref_class_name =
  2077             cp->klass_name_at(cp->klass_ref_index_at(index));
  2078           // See the comments in verify_field_instructions() for
  2079           // the rationale behind this.
  2080           if (name_in_supers(ref_class_name, current_class())) {
  2081             klassOop ref_class = load_class(ref_class_name, CHECK);
  2082             if (is_protected_access(
  2083                   _klass, ref_class, method_name, method_sig, true)) {
  2084               // It's protected access, check if stack object is
  2085               // assignable to current class.
  2086               bool is_assignable = current_type().is_assignable_from(
  2087                 stack_object_type, this, CHECK_VERIFY(this));
  2088               if (!is_assignable) {
  2089                 if (ref_class_type.name() == vmSymbols::java_lang_Object()
  2090                     && stack_object_type.is_array()
  2091                     && method_name == vmSymbols::clone_name()) {
  2092                   // Special case: arrays pretend to implement public Object
  2093                   // clone().
  2094                 } else {
  2095                   verify_error(bci,
  2096                     "Bad access to protected data in invokevirtual");
  2097                   return;
  2103       } else {
  2104         assert(opcode == Bytecodes::_invokeinterface, "Unexpected opcode encountered");
  2105         current_frame->pop_stack(ref_class_type, CHECK_VERIFY(this));
  2109   // Push the result type.
  2110   if (sig_stream.type() != T_VOID) {
  2111     if (method_name == vmSymbols::object_initializer_name()) {
  2112       // <init> method must have a void return type
  2113       verify_error(bci, "Return type must be void in <init> method");
  2114       return;
  2116     VerificationType return_type[2];
  2117     int n = change_sig_to_verificationType(
  2118       &sig_stream, return_type, CHECK_VERIFY(this));
  2119     for (int i = 0; i < n; i++) {
  2120       current_frame->push_stack(return_type[i], CHECK_VERIFY(this)); // push types backwards
  2125 VerificationType ClassVerifier::get_newarray_type(
  2126     u2 index, u2 bci, TRAPS) {
  2127   const char* from_bt[] = {
  2128     NULL, NULL, NULL, NULL, "[Z", "[C", "[F", "[D", "[B", "[S", "[I", "[J",
  2129   };
  2130   if (index < T_BOOLEAN || index > T_LONG) {
  2131     verify_error(bci, "Illegal newarray instruction");
  2132     return VerificationType::bogus_type();
  2135   // from_bt[index] contains the array signature which has a length of 2
  2136   Symbol* sig = create_temporary_symbol(
  2137     from_bt[index], 2, CHECK_(VerificationType::bogus_type()));
  2138   return VerificationType::reference_type(sig);
  2141 void ClassVerifier::verify_anewarray(
  2142     u2 index, constantPoolHandle cp, StackMapFrame* current_frame, TRAPS) {
  2143   verify_cp_class_type(index, cp, CHECK_VERIFY(this));
  2144   current_frame->pop_stack(
  2145     VerificationType::integer_type(), CHECK_VERIFY(this));
  2147   VerificationType component_type =
  2148     cp_index_to_type(index, cp, CHECK_VERIFY(this));
  2149   int length;
  2150   char* arr_sig_str;
  2151   if (component_type.is_array()) {     // it's an array
  2152     const char* component_name = component_type.name()->as_utf8();
  2153     // add one dimension to component
  2154     length = (int)strlen(component_name) + 1;
  2155     arr_sig_str = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, length);
  2156     arr_sig_str[0] = '[';
  2157     strncpy(&arr_sig_str[1], component_name, length - 1);
  2158   } else {         // it's an object or interface
  2159     const char* component_name = component_type.name()->as_utf8();
  2160     // add one dimension to component with 'L' prepended and ';' postpended.
  2161     length = (int)strlen(component_name) + 3;
  2162     arr_sig_str = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, length);
  2163     arr_sig_str[0] = '[';
  2164     arr_sig_str[1] = 'L';
  2165     strncpy(&arr_sig_str[2], component_name, length - 2);
  2166     arr_sig_str[length - 1] = ';';
  2168   Symbol* arr_sig = create_temporary_symbol(
  2169     arr_sig_str, length, CHECK_VERIFY(this));
  2170   VerificationType new_array_type = VerificationType::reference_type(arr_sig);
  2171   current_frame->push_stack(new_array_type, CHECK_VERIFY(this));
  2174 void ClassVerifier::verify_iload(u2 index, StackMapFrame* current_frame, TRAPS) {
  2175   current_frame->get_local(
  2176     index, VerificationType::integer_type(), CHECK_VERIFY(this));
  2177   current_frame->push_stack(
  2178     VerificationType::integer_type(), CHECK_VERIFY(this));
  2181 void ClassVerifier::verify_lload(u2 index, StackMapFrame* current_frame, TRAPS) {
  2182   current_frame->get_local_2(
  2183     index, VerificationType::long_type(),
  2184     VerificationType::long2_type(), CHECK_VERIFY(this));
  2185   current_frame->push_stack_2(
  2186     VerificationType::long_type(),
  2187     VerificationType::long2_type(), CHECK_VERIFY(this));
  2190 void ClassVerifier::verify_fload(u2 index, StackMapFrame* current_frame, TRAPS) {
  2191   current_frame->get_local(
  2192     index, VerificationType::float_type(), CHECK_VERIFY(this));
  2193   current_frame->push_stack(
  2194     VerificationType::float_type(), CHECK_VERIFY(this));
  2197 void ClassVerifier::verify_dload(u2 index, StackMapFrame* current_frame, TRAPS) {
  2198   current_frame->get_local_2(
  2199     index, VerificationType::double_type(),
  2200     VerificationType::double2_type(), CHECK_VERIFY(this));
  2201   current_frame->push_stack_2(
  2202     VerificationType::double_type(),
  2203     VerificationType::double2_type(), CHECK_VERIFY(this));
  2206 void ClassVerifier::verify_aload(u2 index, StackMapFrame* current_frame, TRAPS) {
  2207   VerificationType type = current_frame->get_local(
  2208     index, VerificationType::reference_check(), CHECK_VERIFY(this));
  2209   current_frame->push_stack(type, CHECK_VERIFY(this));
  2212 void ClassVerifier::verify_istore(u2 index, StackMapFrame* current_frame, TRAPS) {
  2213   current_frame->pop_stack(
  2214     VerificationType::integer_type(), CHECK_VERIFY(this));
  2215   current_frame->set_local(
  2216     index, VerificationType::integer_type(), CHECK_VERIFY(this));
  2219 void ClassVerifier::verify_lstore(u2 index, StackMapFrame* current_frame, TRAPS) {
  2220   current_frame->pop_stack_2(
  2221     VerificationType::long2_type(),
  2222     VerificationType::long_type(), CHECK_VERIFY(this));
  2223   current_frame->set_local_2(
  2224     index, VerificationType::long_type(),
  2225     VerificationType::long2_type(), CHECK_VERIFY(this));
  2228 void ClassVerifier::verify_fstore(u2 index, StackMapFrame* current_frame, TRAPS) {
  2229   current_frame->pop_stack(VerificationType::float_type(), CHECK_VERIFY(this));
  2230   current_frame->set_local(
  2231     index, VerificationType::float_type(), CHECK_VERIFY(this));
  2234 void ClassVerifier::verify_dstore(u2 index, StackMapFrame* current_frame, TRAPS) {
  2235   current_frame->pop_stack_2(
  2236     VerificationType::double2_type(),
  2237     VerificationType::double_type(), CHECK_VERIFY(this));
  2238   current_frame->set_local_2(
  2239     index, VerificationType::double_type(),
  2240     VerificationType::double2_type(), CHECK_VERIFY(this));
  2243 void ClassVerifier::verify_astore(u2 index, StackMapFrame* current_frame, TRAPS) {
  2244   VerificationType type = current_frame->pop_stack(
  2245     VerificationType::reference_check(), CHECK_VERIFY(this));
  2246   current_frame->set_local(index, type, CHECK_VERIFY(this));
  2249 void ClassVerifier::verify_iinc(u2 index, StackMapFrame* current_frame, TRAPS) {
  2250   VerificationType type = current_frame->get_local(
  2251     index, VerificationType::integer_type(), CHECK_VERIFY(this));
  2252   current_frame->set_local(index, type, CHECK_VERIFY(this));
  2255 void ClassVerifier::verify_return_value(
  2256     VerificationType return_type, VerificationType type, u2 bci, TRAPS) {
  2257   if (return_type == VerificationType::bogus_type()) {
  2258     verify_error(bci, "Method expects a return value");
  2259     return;
  2261   bool match = return_type.is_assignable_from(type, this, CHECK_VERIFY(this));
  2262   if (!match) {
  2263     verify_error(bci, "Bad return type");
  2264     return;
  2268 // The verifier creates symbols which are substrings of Symbols.
  2269 // These are stored in the verifier until the end of verification so that
  2270 // they can be reference counted.
  2271 Symbol* ClassVerifier::create_temporary_symbol(const Symbol *s, int begin,
  2272                                                int end, TRAPS) {
  2273   Symbol* sym = SymbolTable::new_symbol(s, begin, end, CHECK_NULL);
  2274   _symbols->push(sym);
  2275   return sym;
  2278 Symbol* ClassVerifier::create_temporary_symbol(const char *s, int length, TRAPS) {
  2279   Symbol* sym = SymbolTable::new_symbol(s, length, CHECK_NULL);
  2280   _symbols->push(sym);
  2281   return sym;

mercurial