< prev index next >

src/share/vm/classfile/verifier.cpp

Print this page
rev 13288 : imported patch 8181917-refactor-ul-logstream


  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  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/classFileStream.hpp"
  27 #include "classfile/javaClasses.hpp"
  28 #include "classfile/stackMapTable.hpp"
  29 #include "classfile/stackMapFrame.hpp"
  30 #include "classfile/stackMapTableFormat.hpp"
  31 #include "classfile/systemDictionary.hpp"
  32 #include "classfile/verifier.hpp"
  33 #include "classfile/vmSymbols.hpp"
  34 #include "interpreter/bytecodes.hpp"
  35 #include "interpreter/bytecodeStream.hpp"
  36 #include "logging/log.hpp"

  37 #include "memory/oopFactory.hpp"
  38 #include "memory/resourceArea.hpp"
  39 #include "oops/instanceKlass.hpp"
  40 #include "oops/oop.inline.hpp"
  41 #include "oops/typeArrayOop.hpp"
  42 #include "prims/jvm.h"
  43 #include "runtime/fieldDescriptor.hpp"
  44 #include "runtime/handles.inline.hpp"
  45 #include "runtime/interfaceSupport.hpp"
  46 #include "runtime/javaCalls.hpp"
  47 #include "runtime/orderAccess.inline.hpp"
  48 #include "runtime/os.hpp"
  49 #include "runtime/thread.hpp"
  50 #include "services/threadService.hpp"
  51 #include "utilities/align.hpp"
  52 #include "utilities/bytes.hpp"
  53 
  54 #define NOFAILOVER_MAJOR_VERSION                       51
  55 #define NONZERO_PADDING_BYTES_IN_SWITCH_MAJOR_VERSION  51
  56 #define STATIC_METHOD_IN_INTERFACE_MAJOR_VERSION       52


 174   if (klass->major_version() >= STACKMAP_ATTRIBUTE_MAJOR_VERSION) {
 175     ClassVerifier split_verifier(klass, THREAD);
 176     split_verifier.verify_class(THREAD);
 177     exception_name = split_verifier.result();
 178     if (can_failover && !HAS_PENDING_EXCEPTION &&
 179         (exception_name == vmSymbols::java_lang_VerifyError() ||
 180          exception_name == vmSymbols::java_lang_ClassFormatError())) {
 181       log_info(verification)("Fail over class verification to old verifier for: %s", klassName);
 182       log_info(class, init)("Fail over class verification to old verifier for: %s", klassName);
 183       exception_name = inference_verify(
 184         klass, message_buffer, message_buffer_len, THREAD);
 185     }
 186     if (exception_name != NULL) {
 187       exception_message = split_verifier.exception_message();
 188     }
 189   } else {
 190     exception_name = inference_verify(
 191         klass, message_buffer, message_buffer_len, THREAD);
 192   }
 193 
 194   if (log_is_enabled(Info, class, init)){
 195     log_end_verification(Log(class, init)::info_stream(), klassName, exception_name, THREAD);
 196   }
 197   if (log_is_enabled(Info, verification)){
 198     log_end_verification(Log(verification)::info_stream(), klassName, exception_name, THREAD);




 199   }
 200 
 201   if (HAS_PENDING_EXCEPTION) {
 202     return false; // use the existing exception
 203   } else if (exception_name == NULL) {
 204     return true; // verifcation succeeded
 205   } else { // VerifyError or ClassFormatError to be created and thrown
 206     ResourceMark rm(THREAD);
 207     Klass* kls =
 208       SystemDictionary::resolve_or_fail(exception_name, true, CHECK_false);
 209     if (log_is_enabled(Debug, class, resolve)) {
 210       Verifier::trace_class_resolution(kls, klass);
 211     }
 212 
 213     while (kls != NULL) {
 214       if (kls == klass) {
 215         // If the class being verified is the exception we're creating
 216         // or one of it's superclasses, we're in trouble and are going
 217         // to infinitely recurse when we try to initialize the exception.
 218         // So bail out here by throwing the preallocated VM error.


 645   int ex_min = code_length;
 646   int ex_max = -1;
 647   // Look through each item on the exception table. Each of the fields must refer
 648   // to a legal instruction.
 649   if (was_recursively_verified()) return;
 650   verify_exception_handler_table(
 651     code_length, code_data, ex_min, ex_max, CHECK_VERIFY(this));
 652 
 653   // Look through each entry on the local variable table and make sure
 654   // its range of code array offsets is valid. (4169817)
 655   if (m->has_localvariable_table()) {
 656     verify_local_variable_table(code_length, code_data, CHECK_VERIFY(this));
 657   }
 658 
 659   Array<u1>* stackmap_data = m->stackmap_data();
 660   StackMapStream stream(stackmap_data);
 661   StackMapReader reader(this, &stream, code_data, code_length, THREAD);
 662   StackMapTable stackmap_table(&reader, &current_frame, max_locals, max_stack,
 663                                code_data, code_length, CHECK_VERIFY(this));
 664 
 665   if (log_is_enabled(Info, verification)) {

 666     ResourceMark rm(THREAD);
 667     stackmap_table.print_on(Log(verification)::info_stream());

 668   }
 669 
 670   RawBytecodeStream bcs(m);
 671 
 672   // Scan the byte code linearly from the start to the end
 673   bool no_control_flow = false; // Set to true when there is no direct control
 674                                 // flow from current instruction to the next
 675                                 // instruction in sequence
 676 
 677   Bytecodes::Code opcode;
 678   while (!bcs.is_last_bytecode()) {
 679     // Check for recursive re-verification before each bytecode.
 680     if (was_recursively_verified())  return;
 681 
 682     opcode = bcs.raw_next();
 683     u2 bci = bcs.bci();
 684 
 685     // Set current frame's offset to bci
 686     current_frame.set_offset(bci);
 687     current_frame.set_mark();
 688 
 689     // Make sure every offset in stackmap table point to the beginning to
 690     // an instruction. Match current_frame to stackmap_table entry with
 691     // the same offset if exists.
 692     stackmap_index = verify_stackmap_table(
 693       stackmap_index, bci, &current_frame, &stackmap_table,
 694       no_control_flow, CHECK_VERIFY(this));
 695 
 696 
 697     bool this_uninit = false;  // Set to true when invokespecial <init> initialized 'this'
 698     bool verified_exc_handlers = false;
 699 
 700     // Merge with the next instruction
 701     {
 702       u2 index;
 703       int target;
 704       VerificationType type, type2;
 705       VerificationType atype;
 706 
 707       if (log_is_enabled(Info, verification)) {

 708         ResourceMark rm(THREAD);
 709         current_frame.print_on(Log(verification)::info_stream());
 710         log_info(verification)("offset = %d,  opcode = %s", bci, Bytecodes::name(opcode));

 711       }
 712 
 713       // Make sure wide instruction is in correct format
 714       if (bcs.is_wide()) {
 715         if (opcode != Bytecodes::_iinc   && opcode != Bytecodes::_iload  &&
 716             opcode != Bytecodes::_aload  && opcode != Bytecodes::_lload  &&
 717             opcode != Bytecodes::_istore && opcode != Bytecodes::_astore &&
 718             opcode != Bytecodes::_lstore && opcode != Bytecodes::_fload  &&
 719             opcode != Bytecodes::_dload  && opcode != Bytecodes::_fstore &&
 720             opcode != Bytecodes::_dstore) {
 721           /* Unreachable?  RawBytecodeStream's raw_next() returns 'illegal'
 722            * if we encounter a wide instruction that modifies an invalid
 723            * opcode (not one of the ones listed above) */
 724           verify_error(ErrorContext::bad_code(bci), "Bad wide instruction");
 725           return;
 726         }
 727       }
 728 
 729       // Look for possible jump target in exception handlers and see if it
 730       // matches current_frame.  Do this check here for astore*, dstore*,




  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  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/classFileStream.hpp"
  27 #include "classfile/javaClasses.hpp"
  28 #include "classfile/stackMapTable.hpp"
  29 #include "classfile/stackMapFrame.hpp"
  30 #include "classfile/stackMapTableFormat.hpp"
  31 #include "classfile/systemDictionary.hpp"
  32 #include "classfile/verifier.hpp"
  33 #include "classfile/vmSymbols.hpp"
  34 #include "interpreter/bytecodes.hpp"
  35 #include "interpreter/bytecodeStream.hpp"
  36 #include "logging/log.hpp"
  37 #include "logging/logStream.hpp"
  38 #include "memory/oopFactory.hpp"
  39 #include "memory/resourceArea.hpp"
  40 #include "oops/instanceKlass.hpp"
  41 #include "oops/oop.inline.hpp"
  42 #include "oops/typeArrayOop.hpp"
  43 #include "prims/jvm.h"
  44 #include "runtime/fieldDescriptor.hpp"
  45 #include "runtime/handles.inline.hpp"
  46 #include "runtime/interfaceSupport.hpp"
  47 #include "runtime/javaCalls.hpp"
  48 #include "runtime/orderAccess.inline.hpp"
  49 #include "runtime/os.hpp"
  50 #include "runtime/thread.hpp"
  51 #include "services/threadService.hpp"
  52 #include "utilities/align.hpp"
  53 #include "utilities/bytes.hpp"
  54 
  55 #define NOFAILOVER_MAJOR_VERSION                       51
  56 #define NONZERO_PADDING_BYTES_IN_SWITCH_MAJOR_VERSION  51
  57 #define STATIC_METHOD_IN_INTERFACE_MAJOR_VERSION       52


 175   if (klass->major_version() >= STACKMAP_ATTRIBUTE_MAJOR_VERSION) {
 176     ClassVerifier split_verifier(klass, THREAD);
 177     split_verifier.verify_class(THREAD);
 178     exception_name = split_verifier.result();
 179     if (can_failover && !HAS_PENDING_EXCEPTION &&
 180         (exception_name == vmSymbols::java_lang_VerifyError() ||
 181          exception_name == vmSymbols::java_lang_ClassFormatError())) {
 182       log_info(verification)("Fail over class verification to old verifier for: %s", klassName);
 183       log_info(class, init)("Fail over class verification to old verifier for: %s", klassName);
 184       exception_name = inference_verify(
 185         klass, message_buffer, message_buffer_len, THREAD);
 186     }
 187     if (exception_name != NULL) {
 188       exception_message = split_verifier.exception_message();
 189     }
 190   } else {
 191     exception_name = inference_verify(
 192         klass, message_buffer, message_buffer_len, THREAD);
 193   }
 194 
 195   LogTarget(Info, class, init) lt1;
 196   if (lt1.is_enabled()) {
 197     LogStream ls(lt1);
 198     log_end_verification(&ls, klassName, exception_name, THREAD);
 199   }
 200   LogTarget(Info, verification) lt2;
 201   if (lt2.is_enabled()) {
 202     LogStream ls(lt2);
 203     log_end_verification(&ls, klassName, exception_name, THREAD);
 204   }
 205 
 206   if (HAS_PENDING_EXCEPTION) {
 207     return false; // use the existing exception
 208   } else if (exception_name == NULL) {
 209     return true; // verifcation succeeded
 210   } else { // VerifyError or ClassFormatError to be created and thrown
 211     ResourceMark rm(THREAD);
 212     Klass* kls =
 213       SystemDictionary::resolve_or_fail(exception_name, true, CHECK_false);
 214     if (log_is_enabled(Debug, class, resolve)) {
 215       Verifier::trace_class_resolution(kls, klass);
 216     }
 217 
 218     while (kls != NULL) {
 219       if (kls == klass) {
 220         // If the class being verified is the exception we're creating
 221         // or one of it's superclasses, we're in trouble and are going
 222         // to infinitely recurse when we try to initialize the exception.
 223         // So bail out here by throwing the preallocated VM error.


 650   int ex_min = code_length;
 651   int ex_max = -1;
 652   // Look through each item on the exception table. Each of the fields must refer
 653   // to a legal instruction.
 654   if (was_recursively_verified()) return;
 655   verify_exception_handler_table(
 656     code_length, code_data, ex_min, ex_max, CHECK_VERIFY(this));
 657 
 658   // Look through each entry on the local variable table and make sure
 659   // its range of code array offsets is valid. (4169817)
 660   if (m->has_localvariable_table()) {
 661     verify_local_variable_table(code_length, code_data, CHECK_VERIFY(this));
 662   }
 663 
 664   Array<u1>* stackmap_data = m->stackmap_data();
 665   StackMapStream stream(stackmap_data);
 666   StackMapReader reader(this, &stream, code_data, code_length, THREAD);
 667   StackMapTable stackmap_table(&reader, &current_frame, max_locals, max_stack,
 668                                code_data, code_length, CHECK_VERIFY(this));
 669 
 670   LogTarget(Info, verification) lt;
 671   if (lt.is_enabled()) {
 672     ResourceMark rm(THREAD);
 673     LogStream ls(lt);
 674     stackmap_table.print_on(&ls);
 675   }
 676 
 677   RawBytecodeStream bcs(m);
 678 
 679   // Scan the byte code linearly from the start to the end
 680   bool no_control_flow = false; // Set to true when there is no direct control
 681                                 // flow from current instruction to the next
 682                                 // instruction in sequence
 683 
 684   Bytecodes::Code opcode;
 685   while (!bcs.is_last_bytecode()) {
 686     // Check for recursive re-verification before each bytecode.
 687     if (was_recursively_verified())  return;
 688 
 689     opcode = bcs.raw_next();
 690     u2 bci = bcs.bci();
 691 
 692     // Set current frame's offset to bci
 693     current_frame.set_offset(bci);
 694     current_frame.set_mark();
 695 
 696     // Make sure every offset in stackmap table point to the beginning to
 697     // an instruction. Match current_frame to stackmap_table entry with
 698     // the same offset if exists.
 699     stackmap_index = verify_stackmap_table(
 700       stackmap_index, bci, &current_frame, &stackmap_table,
 701       no_control_flow, CHECK_VERIFY(this));
 702 
 703 
 704     bool this_uninit = false;  // Set to true when invokespecial <init> initialized 'this'
 705     bool verified_exc_handlers = false;
 706 
 707     // Merge with the next instruction
 708     {
 709       u2 index;
 710       int target;
 711       VerificationType type, type2;
 712       VerificationType atype;
 713 
 714       LogTarget(Info, verification) lt;
 715       if (lt.is_enabled()) {
 716         ResourceMark rm(THREAD);
 717         LogStream ls(lt);
 718         current_frame.print_on(&ls);
 719         lt.print("offset = %d,  opcode = %s", bci, Bytecodes::name(opcode));
 720       }
 721 
 722       // Make sure wide instruction is in correct format
 723       if (bcs.is_wide()) {
 724         if (opcode != Bytecodes::_iinc   && opcode != Bytecodes::_iload  &&
 725             opcode != Bytecodes::_aload  && opcode != Bytecodes::_lload  &&
 726             opcode != Bytecodes::_istore && opcode != Bytecodes::_astore &&
 727             opcode != Bytecodes::_lstore && opcode != Bytecodes::_fload  &&
 728             opcode != Bytecodes::_dload  && opcode != Bytecodes::_fstore &&
 729             opcode != Bytecodes::_dstore) {
 730           /* Unreachable?  RawBytecodeStream's raw_next() returns 'illegal'
 731            * if we encounter a wide instruction that modifies an invalid
 732            * opcode (not one of the ones listed above) */
 733           verify_error(ErrorContext::bad_code(bci), "Bad wide instruction");
 734           return;
 735         }
 736       }
 737 
 738       // Look for possible jump target in exception handlers and see if it
 739       // matches current_frame.  Do this check here for astore*, dstore*,


< prev index next >