< prev index next >

src/share/vm/classfile/verifier.hpp

Print this page




  34 #include "utilities/growableArray.hpp"
  35 
  36 // The verifier class
  37 class Verifier : AllStatic {
  38  public:
  39   enum {
  40     STRICTER_ACCESS_CTRL_CHECK_VERSION  = 49,
  41     STACKMAP_ATTRIBUTE_MAJOR_VERSION    = 50,
  42     INVOKEDYNAMIC_MAJOR_VERSION         = 51,
  43     NO_RELAX_ACCESS_CTRL_CHECK_VERSION  = 52
  44   };
  45   typedef enum { ThrowException, NoException } Mode;
  46 
  47   /**
  48    * Verify the bytecodes for a class.  If 'throw_exception' is true
  49    * then the appropriate VerifyError or ClassFormatError will be thrown.
  50    * Otherwise, no exception is thrown and the return indicates the
  51    * error.
  52    */
  53   static void log_end_verification(outputStream* st, const char* klassName, Symbol* exception_name, TRAPS);
  54   static bool verify(instanceKlassHandle klass, Mode mode, bool should_verify_class, TRAPS);
  55 
  56   // Return false if the class is loaded by the bootstrap loader,
  57   // or if defineClass was called requesting skipping verification
  58   // -Xverify:all/none override this value
  59   static bool should_verify_for(oop class_loader, bool should_verify_class);
  60 
  61   // Relax certain access checks to enable some broken 1.1 apps to run on 1.2.
  62   static bool relax_access_for(oop class_loader);
  63 
  64   // Print output for class+resolve
  65   static void trace_class_resolution(Klass* resolve_class, InstanceKlass* verify_class);
  66 
  67  private:
  68   static bool is_eligible_for_verification(instanceKlassHandle klass, bool should_verify_class);
  69   static Symbol* inference_verify(
  70     instanceKlassHandle klass, char* msg, size_t msg_len, TRAPS);
  71 };
  72 
  73 class RawBytecodeStream;
  74 class StackMapFrame;
  75 class StackMapTable;
  76 
  77 // Summary of verifier's memory usage:
  78 // StackMapTable is stack allocated.
  79 // StackMapFrame are resource allocated. There is only one ResourceMark
  80 // for each class verification, which is created at the top level.
  81 // There is one mutable StackMapFrame (current_frame) which is updated
  82 // by abstract bytecode interpretation. frame_in_exception_handler() returns
  83 // a frame that has a mutable one-item stack (ready for pushing the
  84 // catch type exception object). All the other StackMapFrame's
  85 // are immutable (including their locals and stack arrays) after
  86 // their constructions.
  87 // locals/stack arrays in StackMapFrame are resource allocated.
  88 // locals/stack arrays can be shared between StackMapFrame's, except
  89 // the mutable StackMapFrame (current_frame).
  90 


 258   Thread* _thread;
 259   GrowableArray<Symbol*>* _symbols;  // keep a list of symbols created
 260 
 261   Symbol* _exception_type;
 262   char* _message;
 263 
 264   ErrorContext _error_context;  // contains information about an error
 265 
 266   void verify_method(const methodHandle& method, TRAPS);
 267   char* generate_code_data(const methodHandle& m, u4 code_length, TRAPS);
 268   void verify_exception_handler_table(u4 code_length, char* code_data,
 269                                       int& min, int& max, TRAPS);
 270   void verify_local_variable_table(u4 code_length, char* code_data, TRAPS);
 271 
 272   VerificationType cp_ref_index_to_type(
 273       int index, const constantPoolHandle& cp, TRAPS) {
 274     return cp_index_to_type(cp->klass_ref_index_at(index), cp, THREAD);
 275   }
 276 
 277   bool is_protected_access(
 278     instanceKlassHandle this_class, Klass* target_class,
 279     Symbol* field_name, Symbol* field_sig, bool is_method);
 280 
 281   void verify_cp_index(u2 bci, const constantPoolHandle& cp, int index, TRAPS);
 282   void verify_cp_type(u2 bci, int index, const constantPoolHandle& cp,
 283       unsigned int types, TRAPS);
 284   void verify_cp_class_type(u2 bci, int index, const constantPoolHandle& cp, TRAPS);
 285 
 286   u2 verify_stackmap_table(
 287     u2 stackmap_index, u2 bci, StackMapFrame* current_frame,
 288     StackMapTable* stackmap_table, bool no_control_flow, TRAPS);
 289 
 290   void verify_exception_handler_targets(
 291     u2 bci, bool this_uninit, StackMapFrame* current_frame,
 292     StackMapTable* stackmap_table, TRAPS);
 293 
 294   void verify_ldc(
 295     int opcode, u2 index, StackMapFrame *current_frame,
 296     const constantPoolHandle& cp, u2 bci, TRAPS);
 297 
 298   void verify_switch(


 327 
 328   VerificationType get_newarray_type(u2 index, u2 bci, TRAPS);
 329   void verify_anewarray(u2 bci, u2 index, const constantPoolHandle& cp,
 330       StackMapFrame* current_frame, TRAPS);
 331   void verify_return_value(
 332       VerificationType return_type, VerificationType type, u2 offset,
 333       StackMapFrame* current_frame, TRAPS);
 334 
 335   void verify_iload (u2 index, StackMapFrame* current_frame, TRAPS);
 336   void verify_lload (u2 index, StackMapFrame* current_frame, TRAPS);
 337   void verify_fload (u2 index, StackMapFrame* current_frame, TRAPS);
 338   void verify_dload (u2 index, StackMapFrame* current_frame, TRAPS);
 339   void verify_aload (u2 index, StackMapFrame* current_frame, TRAPS);
 340   void verify_istore(u2 index, StackMapFrame* current_frame, TRAPS);
 341   void verify_lstore(u2 index, StackMapFrame* current_frame, TRAPS);
 342   void verify_fstore(u2 index, StackMapFrame* current_frame, TRAPS);
 343   void verify_dstore(u2 index, StackMapFrame* current_frame, TRAPS);
 344   void verify_astore(u2 index, StackMapFrame* current_frame, TRAPS);
 345   void verify_iinc  (u2 index, StackMapFrame* current_frame, TRAPS);
 346 
 347   bool name_in_supers(Symbol* ref_name, instanceKlassHandle current);
 348 
 349   VerificationType object_type() const;
 350 
 351   instanceKlassHandle _klass;  // the class being verified
 352   methodHandle        _method; // current method being verified
 353   VerificationType    _this_type; // the verification type of the current class
 354 
 355   // Some recursive calls from the verifier to the name resolver
 356   // can cause the current class to be re-verified and rewritten.
 357   // If this happens, the original verification should not continue,
 358   // because constant pool indexes will have changed.
 359   // The rewriter is preceded by the verifier.  If the verifier throws
 360   // an error, rewriting is prevented.  Also, rewriting always precedes
 361   // bytecode execution or compilation.  Thus, is_rewritten implies
 362   // that a class has been verified and prepared for execution.
 363   bool was_recursively_verified() { return _klass->is_rewritten(); }
 364 
 365   bool is_same_or_direct_interface(instanceKlassHandle klass,
 366     VerificationType klass_type, VerificationType ref_class_type);
 367 
 368  public:
 369   enum {
 370     BYTECODE_OFFSET = 1,
 371     NEW_OFFSET = 2
 372   };
 373 
 374   // constructor
 375   ClassVerifier(instanceKlassHandle klass, TRAPS);
 376 
 377   // destructor
 378   ~ClassVerifier();
 379 
 380   Thread* thread()             { return _thread; }
 381   const methodHandle& method() { return _method; }
 382   instanceKlassHandle current_class() const { return _klass; }
 383   VerificationType current_type() const { return _this_type; }
 384 
 385   // Verifies the class.  If a verify or class file format error occurs,
 386   // the '_exception_name' symbols will set to the exception name and
 387   // the message_buffer will be filled in with the exception message.
 388   void verify_class(TRAPS);
 389 
 390   // Return status modes
 391   Symbol* result() const { return _exception_type; }
 392   bool has_error() const { return result() != NULL; }
 393   char* exception_message() {
 394     stringStream ss;
 395     ss.print("%s", _message);
 396     _error_context.details(&ss, _method());
 397     return ss.as_string();
 398   }
 399 
 400   // Called when verify or class format errors are encountered.
 401   // May throw an exception based upon the mode.
 402   void verify_error(ErrorContext ctx, const char* fmt, ...) ATTRIBUTE_PRINTF(3, 4);




  34 #include "utilities/growableArray.hpp"
  35 
  36 // The verifier class
  37 class Verifier : AllStatic {
  38  public:
  39   enum {
  40     STRICTER_ACCESS_CTRL_CHECK_VERSION  = 49,
  41     STACKMAP_ATTRIBUTE_MAJOR_VERSION    = 50,
  42     INVOKEDYNAMIC_MAJOR_VERSION         = 51,
  43     NO_RELAX_ACCESS_CTRL_CHECK_VERSION  = 52
  44   };
  45   typedef enum { ThrowException, NoException } Mode;
  46 
  47   /**
  48    * Verify the bytecodes for a class.  If 'throw_exception' is true
  49    * then the appropriate VerifyError or ClassFormatError will be thrown.
  50    * Otherwise, no exception is thrown and the return indicates the
  51    * error.
  52    */
  53   static void log_end_verification(outputStream* st, const char* klassName, Symbol* exception_name, TRAPS);
  54   static bool verify(InstanceKlass* klass, Mode mode, bool should_verify_class, TRAPS);
  55 
  56   // Return false if the class is loaded by the bootstrap loader,
  57   // or if defineClass was called requesting skipping verification
  58   // -Xverify:all/none override this value
  59   static bool should_verify_for(oop class_loader, bool should_verify_class);
  60 
  61   // Relax certain access checks to enable some broken 1.1 apps to run on 1.2.
  62   static bool relax_access_for(oop class_loader);
  63 
  64   // Print output for class+resolve
  65   static void trace_class_resolution(Klass* resolve_class, InstanceKlass* verify_class);
  66 
  67  private:
  68   static bool is_eligible_for_verification(InstanceKlass* klass, bool should_verify_class);
  69   static Symbol* inference_verify(
  70     InstanceKlass* klass, char* msg, size_t msg_len, TRAPS);
  71 };
  72 
  73 class RawBytecodeStream;
  74 class StackMapFrame;
  75 class StackMapTable;
  76 
  77 // Summary of verifier's memory usage:
  78 // StackMapTable is stack allocated.
  79 // StackMapFrame are resource allocated. There is only one ResourceMark
  80 // for each class verification, which is created at the top level.
  81 // There is one mutable StackMapFrame (current_frame) which is updated
  82 // by abstract bytecode interpretation. frame_in_exception_handler() returns
  83 // a frame that has a mutable one-item stack (ready for pushing the
  84 // catch type exception object). All the other StackMapFrame's
  85 // are immutable (including their locals and stack arrays) after
  86 // their constructions.
  87 // locals/stack arrays in StackMapFrame are resource allocated.
  88 // locals/stack arrays can be shared between StackMapFrame's, except
  89 // the mutable StackMapFrame (current_frame).
  90 


 258   Thread* _thread;
 259   GrowableArray<Symbol*>* _symbols;  // keep a list of symbols created
 260 
 261   Symbol* _exception_type;
 262   char* _message;
 263 
 264   ErrorContext _error_context;  // contains information about an error
 265 
 266   void verify_method(const methodHandle& method, TRAPS);
 267   char* generate_code_data(const methodHandle& m, u4 code_length, TRAPS);
 268   void verify_exception_handler_table(u4 code_length, char* code_data,
 269                                       int& min, int& max, TRAPS);
 270   void verify_local_variable_table(u4 code_length, char* code_data, TRAPS);
 271 
 272   VerificationType cp_ref_index_to_type(
 273       int index, const constantPoolHandle& cp, TRAPS) {
 274     return cp_index_to_type(cp->klass_ref_index_at(index), cp, THREAD);
 275   }
 276 
 277   bool is_protected_access(
 278     InstanceKlass* this_class, Klass* target_class,
 279     Symbol* field_name, Symbol* field_sig, bool is_method);
 280 
 281   void verify_cp_index(u2 bci, const constantPoolHandle& cp, int index, TRAPS);
 282   void verify_cp_type(u2 bci, int index, const constantPoolHandle& cp,
 283       unsigned int types, TRAPS);
 284   void verify_cp_class_type(u2 bci, int index, const constantPoolHandle& cp, TRAPS);
 285 
 286   u2 verify_stackmap_table(
 287     u2 stackmap_index, u2 bci, StackMapFrame* current_frame,
 288     StackMapTable* stackmap_table, bool no_control_flow, TRAPS);
 289 
 290   void verify_exception_handler_targets(
 291     u2 bci, bool this_uninit, StackMapFrame* current_frame,
 292     StackMapTable* stackmap_table, TRAPS);
 293 
 294   void verify_ldc(
 295     int opcode, u2 index, StackMapFrame *current_frame,
 296     const constantPoolHandle& cp, u2 bci, TRAPS);
 297 
 298   void verify_switch(


 327 
 328   VerificationType get_newarray_type(u2 index, u2 bci, TRAPS);
 329   void verify_anewarray(u2 bci, u2 index, const constantPoolHandle& cp,
 330       StackMapFrame* current_frame, TRAPS);
 331   void verify_return_value(
 332       VerificationType return_type, VerificationType type, u2 offset,
 333       StackMapFrame* current_frame, TRAPS);
 334 
 335   void verify_iload (u2 index, StackMapFrame* current_frame, TRAPS);
 336   void verify_lload (u2 index, StackMapFrame* current_frame, TRAPS);
 337   void verify_fload (u2 index, StackMapFrame* current_frame, TRAPS);
 338   void verify_dload (u2 index, StackMapFrame* current_frame, TRAPS);
 339   void verify_aload (u2 index, StackMapFrame* current_frame, TRAPS);
 340   void verify_istore(u2 index, StackMapFrame* current_frame, TRAPS);
 341   void verify_lstore(u2 index, StackMapFrame* current_frame, TRAPS);
 342   void verify_fstore(u2 index, StackMapFrame* current_frame, TRAPS);
 343   void verify_dstore(u2 index, StackMapFrame* current_frame, TRAPS);
 344   void verify_astore(u2 index, StackMapFrame* current_frame, TRAPS);
 345   void verify_iinc  (u2 index, StackMapFrame* current_frame, TRAPS);
 346 
 347   bool name_in_supers(Symbol* ref_name, InstanceKlass* current);
 348 
 349   VerificationType object_type() const;
 350 
 351   InstanceKlass*      _klass;  // the class being verified
 352   methodHandle        _method; // current method being verified
 353   VerificationType    _this_type; // the verification type of the current class
 354 
 355   // Some recursive calls from the verifier to the name resolver
 356   // can cause the current class to be re-verified and rewritten.
 357   // If this happens, the original verification should not continue,
 358   // because constant pool indexes will have changed.
 359   // The rewriter is preceded by the verifier.  If the verifier throws
 360   // an error, rewriting is prevented.  Also, rewriting always precedes
 361   // bytecode execution or compilation.  Thus, is_rewritten implies
 362   // that a class has been verified and prepared for execution.
 363   bool was_recursively_verified() { return _klass->is_rewritten(); }
 364 
 365   bool is_same_or_direct_interface(InstanceKlass* klass,
 366     VerificationType klass_type, VerificationType ref_class_type);
 367 
 368  public:
 369   enum {
 370     BYTECODE_OFFSET = 1,
 371     NEW_OFFSET = 2
 372   };
 373 
 374   // constructor
 375   ClassVerifier(InstanceKlass* klass, TRAPS);
 376 
 377   // destructor
 378   ~ClassVerifier();
 379 
 380   Thread* thread()             { return _thread; }
 381   const methodHandle& method() { return _method; }
 382   InstanceKlass* current_class() const { return _klass; }
 383   VerificationType current_type() const { return _this_type; }
 384 
 385   // Verifies the class.  If a verify or class file format error occurs,
 386   // the '_exception_name' symbols will set to the exception name and
 387   // the message_buffer will be filled in with the exception message.
 388   void verify_class(TRAPS);
 389 
 390   // Return status modes
 391   Symbol* result() const { return _exception_type; }
 392   bool has_error() const { return result() != NULL; }
 393   char* exception_message() {
 394     stringStream ss;
 395     ss.print("%s", _message);
 396     _error_context.details(&ss, _method());
 397     return ss.as_string();
 398   }
 399 
 400   // Called when verify or class format errors are encountered.
 401   // May throw an exception based upon the mode.
 402   void verify_error(ErrorContext ctx, const char* fmt, ...) ATTRIBUTE_PRINTF(3, 4);


< prev index next >