331 // 332 333 struct JvmtiCachedClassFileData { 334 jint length; 335 unsigned char data[1]; 336 }; 337 338 class VM_RedefineClasses: public VM_Operation { 339 private: 340 // These static fields are needed by ClassLoaderDataGraph::classes_do() 341 // facility and the AdjustCpoolCacheAndVtable helper: 342 static Array<Method*>* _old_methods; 343 static Array<Method*>* _new_methods; 344 static Method** _matching_old_methods; 345 static Method** _matching_new_methods; 346 static Method** _deleted_methods; 347 static Method** _added_methods; 348 static int _matching_methods_length; 349 static int _deleted_methods_length; 350 static int _added_methods_length; 351 static Klass* _the_class_oop; 352 353 // The instance fields are used to pass information from 354 // doit_prologue() to doit() and doit_epilogue(). 355 jint _class_count; 356 const jvmtiClassDefinition *_class_defs; // ptr to _class_count defs 357 358 // This operation is used by both RedefineClasses and 359 // RetransformClasses. Indicate which. 360 JvmtiClassLoadKind _class_load_kind; 361 362 // _index_map_count is just an optimization for knowing if 363 // _index_map_p contains any entries. 364 int _index_map_count; 365 intArray * _index_map_p; 366 367 // _operands_index_map_count is just an optimization for knowing if 368 // _operands_index_map_p contains any entries. 369 int _operands_cur_length; 370 int _operands_index_map_count; 371 intArray * _operands_index_map_p; 372 373 // ptr to _class_count scratch_classes 374 Klass** _scratch_classes; 375 jvmtiError _res; 376 377 // Performance measurement support. These timers do not cover all 378 // the work done for JVM/TI RedefineClasses() but they do cover 379 // the heavy lifting. 380 elapsedTimer _timer_rsc_phase1; 381 elapsedTimer _timer_rsc_phase2; 382 elapsedTimer _timer_vm_op_prologue; 383 384 // These routines are roughly in call order unless otherwise noted. 385 386 // Load the caller's new class definition(s) into _scratch_classes. 387 // Constant pool merging work is done here as needed. Also calls 388 // compare_and_normalize_class_versions() to verify the class 389 // definition(s). 390 jvmtiError load_new_class_versions(TRAPS); 391 392 // Verify that the caller provided class definition(s) that meet 393 // the restrictions of RedefineClasses. Normalize the order of 394 // overloaded methods as needed. 395 jvmtiError compare_and_normalize_class_versions( 396 instanceKlassHandle the_class, instanceKlassHandle scratch_class); 397 398 // Figure out which new methods match old methods in name and signature, 399 // which methods have been added, and which are no longer present 400 void compute_added_deleted_matching_methods(); 401 402 // Change jmethodIDs to point to the new methods 403 void update_jmethod_ids(); 404 405 // In addition to marking methods as old and/or obsolete, this routine 406 // counts the number of methods that are EMCP (Equivalent Module Constant Pool). 407 int check_methods_and_mark_as_obsolete(); 408 void transfer_old_native_function_registrations(instanceKlassHandle the_class); 409 410 // Install the redefinition of a class 411 void redefine_single_class(jclass the_jclass, 412 Klass* scratch_class_oop, TRAPS); 413 414 void swap_annotations(instanceKlassHandle new_class, 415 instanceKlassHandle scratch_class); 416 417 // Increment the classRedefinedCount field in the specific InstanceKlass 418 // and in all direct and indirect subclasses. 419 void increment_class_counter(InstanceKlass *ik, TRAPS); 420 421 // Support for constant pool merging (these routines are in alpha order): 422 void append_entry(const constantPoolHandle& scratch_cp, int scratch_i, 423 constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS); 424 void append_operand(const constantPoolHandle& scratch_cp, int scratch_bootstrap_spec_index, 425 constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS); 426 void finalize_operands_merge(const constantPoolHandle& merge_cp, TRAPS); 427 int find_or_append_indirect_entry(const constantPoolHandle& scratch_cp, int scratch_i, 428 constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS); 429 int find_or_append_operand(const constantPoolHandle& scratch_cp, int scratch_bootstrap_spec_index, 430 constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS); 431 int find_new_index(int old_index); 432 int find_new_operand_index(int old_bootstrap_spec_index); 433 bool is_unresolved_class_mismatch(const constantPoolHandle& cp1, int index1, 434 const constantPoolHandle& cp2, int index2); 435 void map_index(const constantPoolHandle& scratch_cp, int old_index, int new_index); 436 void map_operand_index(int old_bootstrap_spec_index, int new_bootstrap_spec_index); 437 bool merge_constant_pools(const constantPoolHandle& old_cp, 438 const constantPoolHandle& scratch_cp, constantPoolHandle *merge_cp_p, 439 int *merge_cp_length_p, TRAPS); 440 jvmtiError merge_cp_and_rewrite(instanceKlassHandle the_class, 441 instanceKlassHandle scratch_class, TRAPS); 442 u2 rewrite_cp_ref_in_annotation_data( 443 AnnotationArray* annotations_typeArray, int &byte_i_ref, 444 const char * trace_mesg, TRAPS); 445 bool rewrite_cp_refs(instanceKlassHandle scratch_class, TRAPS); 446 bool rewrite_cp_refs_in_annotation_struct( 447 AnnotationArray* class_annotations, int &byte_i_ref, TRAPS); 448 bool rewrite_cp_refs_in_annotations_typeArray( 449 AnnotationArray* annotations_typeArray, int &byte_i_ref, TRAPS); 450 bool rewrite_cp_refs_in_class_annotations( 451 instanceKlassHandle scratch_class, TRAPS); 452 bool rewrite_cp_refs_in_element_value( 453 AnnotationArray* class_annotations, int &byte_i_ref, TRAPS); 454 bool rewrite_cp_refs_in_type_annotations_typeArray( 455 AnnotationArray* type_annotations_typeArray, int &byte_i_ref, 456 const char * location_mesg, TRAPS); 457 bool rewrite_cp_refs_in_type_annotation_struct( 458 AnnotationArray* type_annotations_typeArray, int &byte_i_ref, 459 const char * location_mesg, TRAPS); 460 bool skip_type_annotation_target( 461 AnnotationArray* type_annotations_typeArray, int &byte_i_ref, 462 const char * location_mesg, TRAPS); 463 bool skip_type_annotation_type_path( 464 AnnotationArray* type_annotations_typeArray, int &byte_i_ref, TRAPS); 465 bool rewrite_cp_refs_in_fields_annotations( 466 instanceKlassHandle scratch_class, TRAPS); 467 void rewrite_cp_refs_in_method(methodHandle method, 468 methodHandle * new_method_p, TRAPS); 469 bool rewrite_cp_refs_in_methods(instanceKlassHandle scratch_class, TRAPS); 470 bool rewrite_cp_refs_in_methods_annotations( 471 instanceKlassHandle scratch_class, TRAPS); 472 bool rewrite_cp_refs_in_methods_default_annotations( 473 instanceKlassHandle scratch_class, TRAPS); 474 bool rewrite_cp_refs_in_methods_parameter_annotations( 475 instanceKlassHandle scratch_class, TRAPS); 476 bool rewrite_cp_refs_in_class_type_annotations( 477 instanceKlassHandle scratch_class, TRAPS); 478 bool rewrite_cp_refs_in_fields_type_annotations( 479 instanceKlassHandle scratch_class, TRAPS); 480 bool rewrite_cp_refs_in_methods_type_annotations( 481 instanceKlassHandle scratch_class, TRAPS); 482 void rewrite_cp_refs_in_stack_map_table(const methodHandle& method, TRAPS); 483 void rewrite_cp_refs_in_verification_type_info( 484 address& stackmap_addr_ref, address stackmap_end, u2 frame_i, 485 u1 frame_size, TRAPS); 486 void set_new_constant_pool(ClassLoaderData* loader_data, 487 instanceKlassHandle scratch_class, 488 constantPoolHandle scratch_cp, int scratch_cp_length, TRAPS); 489 490 void flush_dependent_code(instanceKlassHandle k_h, TRAPS); 491 492 // lock classes to redefine since constant pool merging isn't thread safe. 493 void lock_classes(); 494 void unlock_classes(); 495 496 static void dump_methods(); 497 498 // Check that there are no old or obsolete methods 499 class CheckClass : public KlassClosure { 500 Thread* _thread; 501 public: 502 CheckClass(Thread* t) : _thread(t) {} 503 void do_klass(Klass* k); 504 }; 505 506 // Unevolving classes may point to methods of the_class directly 507 // from their constant pool caches, itables, and/or vtables. We 508 // use the ClassLoaderDataGraph::classes_do() facility and this helper 509 // to fix up these pointers. 510 class AdjustCpoolCacheAndVtable : public KlassClosure { | 331 // 332 333 struct JvmtiCachedClassFileData { 334 jint length; 335 unsigned char data[1]; 336 }; 337 338 class VM_RedefineClasses: public VM_Operation { 339 private: 340 // These static fields are needed by ClassLoaderDataGraph::classes_do() 341 // facility and the AdjustCpoolCacheAndVtable helper: 342 static Array<Method*>* _old_methods; 343 static Array<Method*>* _new_methods; 344 static Method** _matching_old_methods; 345 static Method** _matching_new_methods; 346 static Method** _deleted_methods; 347 static Method** _added_methods; 348 static int _matching_methods_length; 349 static int _deleted_methods_length; 350 static int _added_methods_length; 351 static Klass* _the_class; 352 353 // The instance fields are used to pass information from 354 // doit_prologue() to doit() and doit_epilogue(). 355 jint _class_count; 356 const jvmtiClassDefinition *_class_defs; // ptr to _class_count defs 357 358 // This operation is used by both RedefineClasses and 359 // RetransformClasses. Indicate which. 360 JvmtiClassLoadKind _class_load_kind; 361 362 // _index_map_count is just an optimization for knowing if 363 // _index_map_p contains any entries. 364 int _index_map_count; 365 intArray * _index_map_p; 366 367 // _operands_index_map_count is just an optimization for knowing if 368 // _operands_index_map_p contains any entries. 369 int _operands_cur_length; 370 int _operands_index_map_count; 371 intArray * _operands_index_map_p; 372 373 // ptr to _class_count scratch_classes 374 InstanceKlass** _scratch_classes; 375 jvmtiError _res; 376 377 // Performance measurement support. These timers do not cover all 378 // the work done for JVM/TI RedefineClasses() but they do cover 379 // the heavy lifting. 380 elapsedTimer _timer_rsc_phase1; 381 elapsedTimer _timer_rsc_phase2; 382 elapsedTimer _timer_vm_op_prologue; 383 384 // These routines are roughly in call order unless otherwise noted. 385 386 // Load the caller's new class definition(s) into _scratch_classes. 387 // Constant pool merging work is done here as needed. Also calls 388 // compare_and_normalize_class_versions() to verify the class 389 // definition(s). 390 jvmtiError load_new_class_versions(TRAPS); 391 392 // Verify that the caller provided class definition(s) that meet 393 // the restrictions of RedefineClasses. Normalize the order of 394 // overloaded methods as needed. 395 jvmtiError compare_and_normalize_class_versions( 396 InstanceKlass* the_class, InstanceKlass* scratch_class); 397 398 // Figure out which new methods match old methods in name and signature, 399 // which methods have been added, and which are no longer present 400 void compute_added_deleted_matching_methods(); 401 402 // Change jmethodIDs to point to the new methods 403 void update_jmethod_ids(); 404 405 // In addition to marking methods as old and/or obsolete, this routine 406 // counts the number of methods that are EMCP (Equivalent Module Constant Pool). 407 int check_methods_and_mark_as_obsolete(); 408 void transfer_old_native_function_registrations(InstanceKlass* the_class); 409 410 // Install the redefinition of a class 411 void redefine_single_class(jclass the_jclass, 412 InstanceKlass* scratch_class_oop, TRAPS); 413 414 void swap_annotations(InstanceKlass* new_class, 415 InstanceKlass* scratch_class); 416 417 // Increment the classRedefinedCount field in the specific InstanceKlass 418 // and in all direct and indirect subclasses. 419 void increment_class_counter(InstanceKlass *ik, TRAPS); 420 421 // Support for constant pool merging (these routines are in alpha order): 422 void append_entry(const constantPoolHandle& scratch_cp, int scratch_i, 423 constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS); 424 void append_operand(const constantPoolHandle& scratch_cp, int scratch_bootstrap_spec_index, 425 constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS); 426 void finalize_operands_merge(const constantPoolHandle& merge_cp, TRAPS); 427 int find_or_append_indirect_entry(const constantPoolHandle& scratch_cp, int scratch_i, 428 constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS); 429 int find_or_append_operand(const constantPoolHandle& scratch_cp, int scratch_bootstrap_spec_index, 430 constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS); 431 int find_new_index(int old_index); 432 int find_new_operand_index(int old_bootstrap_spec_index); 433 bool is_unresolved_class_mismatch(const constantPoolHandle& cp1, int index1, 434 const constantPoolHandle& cp2, int index2); 435 void map_index(const constantPoolHandle& scratch_cp, int old_index, int new_index); 436 void map_operand_index(int old_bootstrap_spec_index, int new_bootstrap_spec_index); 437 bool merge_constant_pools(const constantPoolHandle& old_cp, 438 const constantPoolHandle& scratch_cp, constantPoolHandle *merge_cp_p, 439 int *merge_cp_length_p, TRAPS); 440 jvmtiError merge_cp_and_rewrite(InstanceKlass* the_class, 441 InstanceKlass* scratch_class, TRAPS); 442 u2 rewrite_cp_ref_in_annotation_data( 443 AnnotationArray* annotations_typeArray, int &byte_i_ref, 444 const char * trace_mesg, TRAPS); 445 bool rewrite_cp_refs(InstanceKlass* scratch_class, TRAPS); 446 bool rewrite_cp_refs_in_annotation_struct( 447 AnnotationArray* class_annotations, int &byte_i_ref, TRAPS); 448 bool rewrite_cp_refs_in_annotations_typeArray( 449 AnnotationArray* annotations_typeArray, int &byte_i_ref, TRAPS); 450 bool rewrite_cp_refs_in_class_annotations( 451 InstanceKlass* scratch_class, TRAPS); 452 bool rewrite_cp_refs_in_element_value( 453 AnnotationArray* class_annotations, int &byte_i_ref, TRAPS); 454 bool rewrite_cp_refs_in_type_annotations_typeArray( 455 AnnotationArray* type_annotations_typeArray, int &byte_i_ref, 456 const char * location_mesg, TRAPS); 457 bool rewrite_cp_refs_in_type_annotation_struct( 458 AnnotationArray* type_annotations_typeArray, int &byte_i_ref, 459 const char * location_mesg, TRAPS); 460 bool skip_type_annotation_target( 461 AnnotationArray* type_annotations_typeArray, int &byte_i_ref, 462 const char * location_mesg, TRAPS); 463 bool skip_type_annotation_type_path( 464 AnnotationArray* type_annotations_typeArray, int &byte_i_ref, TRAPS); 465 bool rewrite_cp_refs_in_fields_annotations( 466 InstanceKlass* scratch_class, TRAPS); 467 void rewrite_cp_refs_in_method(methodHandle method, 468 methodHandle * new_method_p, TRAPS); 469 bool rewrite_cp_refs_in_methods(InstanceKlass* scratch_class, TRAPS); 470 bool rewrite_cp_refs_in_methods_annotations( 471 InstanceKlass* scratch_class, TRAPS); 472 bool rewrite_cp_refs_in_methods_default_annotations( 473 InstanceKlass* scratch_class, TRAPS); 474 bool rewrite_cp_refs_in_methods_parameter_annotations( 475 InstanceKlass* scratch_class, TRAPS); 476 bool rewrite_cp_refs_in_class_type_annotations( 477 InstanceKlass* scratch_class, TRAPS); 478 bool rewrite_cp_refs_in_fields_type_annotations( 479 InstanceKlass* scratch_class, TRAPS); 480 bool rewrite_cp_refs_in_methods_type_annotations( 481 InstanceKlass* scratch_class, TRAPS); 482 void rewrite_cp_refs_in_stack_map_table(const methodHandle& method, TRAPS); 483 void rewrite_cp_refs_in_verification_type_info( 484 address& stackmap_addr_ref, address stackmap_end, u2 frame_i, 485 u1 frame_size, TRAPS); 486 void set_new_constant_pool(ClassLoaderData* loader_data, 487 InstanceKlass* scratch_class, 488 constantPoolHandle scratch_cp, int scratch_cp_length, TRAPS); 489 490 void flush_dependent_code(InstanceKlass* ik, TRAPS); 491 492 // lock classes to redefine since constant pool merging isn't thread safe. 493 void lock_classes(); 494 void unlock_classes(); 495 496 static void dump_methods(); 497 498 // Check that there are no old or obsolete methods 499 class CheckClass : public KlassClosure { 500 Thread* _thread; 501 public: 502 CheckClass(Thread* t) : _thread(t) {} 503 void do_klass(Klass* k); 504 }; 505 506 // Unevolving classes may point to methods of the_class directly 507 // from their constant pool caches, itables, and/or vtables. We 508 // use the ClassLoaderDataGraph::classes_do() facility and this helper 509 // to fix up these pointers. 510 class AdjustCpoolCacheAndVtable : public KlassClosure { |