< prev index next >

src/share/vm/prims/jvmtiClassFileReconstituter.cpp

Print this page
rev 6869 : 8057043: Type annotations not retained during class redefine / retransform
Reviewed-by: coleenp, sspitsyn, jfranck


  37 #ifdef TARGET_ARCH_zero
  38 # include "bytes_zero.hpp"
  39 #endif
  40 #ifdef TARGET_ARCH_arm
  41 # include "bytes_arm.hpp"
  42 #endif
  43 #ifdef TARGET_ARCH_ppc
  44 # include "bytes_ppc.hpp"
  45 #endif
  46 // FIXME: add Deprecated attribute
  47 // FIXME: fix Synthetic attribute
  48 // FIXME: per Serguei, add error return handling for ConstantPool::copy_cpool_bytes()
  49 
  50 
  51 // Write the field information portion of ClassFile structure
  52 // JVMSpec|     u2 fields_count;
  53 // JVMSpec|     field_info fields[fields_count];
  54 void JvmtiClassFileReconstituter::write_field_infos() {
  55   HandleMark hm(thread());
  56   Array<AnnotationArray*>* fields_anno = ikh()->fields_annotations();

  57 
  58   // Compute the real number of Java fields
  59   int java_fields = ikh()->java_fields_count();
  60 
  61   write_u2(java_fields);
  62   for (JavaFieldStream fs(ikh()); !fs.done(); fs.next()) {
  63     AccessFlags access_flags = fs.access_flags();
  64     int name_index = fs.name_index();
  65     int signature_index = fs.signature_index();
  66     int initial_value_index = fs.initval_index();
  67     guarantee(name_index != 0 && signature_index != 0, "bad constant pool index for field");
  68     // int offset = ikh()->field_offset( index );
  69     int generic_signature_index = fs.generic_signature_index();
  70     AnnotationArray* anno = fields_anno == NULL ? NULL : fields_anno->at(fs.index());

  71 
  72     // JVMSpec|   field_info {
  73     // JVMSpec|         u2 access_flags;
  74     // JVMSpec|         u2 name_index;
  75     // JVMSpec|         u2 descriptor_index;
  76     // JVMSpec|         u2 attributes_count;
  77     // JVMSpec|         attribute_info attributes[attributes_count];
  78     // JVMSpec|   }
  79 
  80     write_u2(access_flags.as_int() & JVM_RECOGNIZED_FIELD_MODIFIERS);
  81     write_u2(name_index);
  82     write_u2(signature_index);
  83     int attr_count = 0;
  84     if (initial_value_index != 0) {
  85       ++attr_count;
  86     }
  87     if (access_flags.is_synthetic()) {
  88       // ++attr_count;
  89     }
  90     if (generic_signature_index != 0) {
  91       ++attr_count;
  92     }
  93     if (anno != NULL) {
  94       ++attr_count;     // has RuntimeVisibleAnnotations attribute
  95     }



  96 
  97     write_u2(attr_count);
  98 
  99     if (initial_value_index != 0) {
 100       write_attribute_name_index("ConstantValue");
 101       write_u4(2); //length always 2
 102       write_u2(initial_value_index);
 103     }
 104     if (access_flags.is_synthetic()) {
 105       // write_synthetic_attribute();
 106     }
 107     if (generic_signature_index != 0) {
 108       write_signature_attribute(generic_signature_index);
 109     }
 110     if (anno != NULL) {
 111       write_annotations_attribute("RuntimeVisibleAnnotations", anno);
 112     }



 113   }
 114 }
 115 
 116 // Write Code attribute
 117 // JVMSpec|   Code_attribute {
 118 // JVMSpec|     u2 attribute_name_index;
 119 // JVMSpec|     u4 attribute_length;
 120 // JVMSpec|     u2 max_stack;
 121 // JVMSpec|     u2 max_locals;
 122 // JVMSpec|     u4 code_length;
 123 // JVMSpec|     u1 code[code_length];
 124 // JVMSpec|     u2 exception_table_length;
 125 // JVMSpec|     {       u2 start_pc;
 126 // JVMSpec|             u2 end_pc;
 127 // JVMSpec|             u2  handler_pc;
 128 // JVMSpec|             u2  catch_type;
 129 // JVMSpec|     }       exception_table[exception_table_length];
 130 // JVMSpec|     u2 attributes_count;
 131 // JVMSpec|     attribute_info attributes[attributes_count];
 132 // JVMSpec|   }


 533     writeable_address(stackmap_len),
 534     (void*)(method->stackmap_data()->adr_at(0)),
 535     stackmap_len);
 536 }
 537 
 538 // Write one method_info structure
 539 // JVMSpec|   method_info {
 540 // JVMSpec|     u2 access_flags;
 541 // JVMSpec|     u2 name_index;
 542 // JVMSpec|     u2 descriptor_index;
 543 // JVMSpec|     u2 attributes_count;
 544 // JVMSpec|     attribute_info attributes[attributes_count];
 545 // JVMSpec|   }
 546 void JvmtiClassFileReconstituter::write_method_info(methodHandle method) {
 547   AccessFlags access_flags = method->access_flags();
 548   ConstMethod* const_method = method->constMethod();
 549   u2 generic_signature_index = const_method->generic_signature_index();
 550   AnnotationArray* anno = method->annotations();
 551   AnnotationArray* param_anno = method->parameter_annotations();
 552   AnnotationArray* default_anno = method->annotation_default();

 553 
 554   // skip generated default interface methods
 555   if (method->is_overpass()) {
 556     return;
 557   }
 558 
 559   write_u2(access_flags.get_flags() & JVM_RECOGNIZED_METHOD_MODIFIERS);
 560   write_u2(const_method->name_index());
 561   write_u2(const_method->signature_index());
 562 
 563   // write attributes in the same order javac does, so we can test with byte for
 564   // byte comparison
 565   int attr_count = 0;
 566   if (const_method->code_size() != 0) {
 567     ++attr_count;     // has Code attribute
 568   }
 569   if (const_method->has_checked_exceptions()) {
 570     ++attr_count;     // has Exceptions attribute
 571   }
 572   if (default_anno != NULL) {
 573     ++attr_count;     // has AnnotationDefault attribute
 574   }
 575   // Deprecated attribute would go here
 576   if (access_flags.is_synthetic()) { // FIXME
 577     // ++attr_count;
 578   }
 579   if (generic_signature_index != 0) {
 580     ++attr_count;
 581   }
 582   if (anno != NULL) {
 583     ++attr_count;     // has RuntimeVisibleAnnotations attribute
 584   }
 585   if (param_anno != NULL) {
 586     ++attr_count;     // has RuntimeVisibleParameterAnnotations attribute
 587   }



 588 
 589   write_u2(attr_count);
 590   if (const_method->code_size() > 0) {
 591     write_code_attribute(method);
 592   }
 593   if (const_method->has_checked_exceptions()) {
 594     write_exceptions_attribute(const_method);
 595   }
 596   if (default_anno != NULL) {
 597     write_annotations_attribute("AnnotationDefault", default_anno);
 598   }
 599   // Deprecated attribute would go here
 600   if (access_flags.is_synthetic()) {
 601     // write_synthetic_attribute();
 602   }
 603   if (generic_signature_index != 0) {
 604     write_signature_attribute(generic_signature_index);
 605   }
 606   if (anno != NULL) {
 607     write_annotations_attribute("RuntimeVisibleAnnotations", anno);
 608   }
 609   if (param_anno != NULL) {
 610     write_annotations_attribute("RuntimeVisibleParameterAnnotations", param_anno);
 611   }



 612 }
 613 
 614 // Write the class attributes portion of ClassFile structure
 615 // JVMSpec|     u2 attributes_count;
 616 // JVMSpec|     attribute_info attributes[attributes_count];
 617 void JvmtiClassFileReconstituter::write_class_attributes() {
 618   u2 inner_classes_length = inner_classes_attribute_length();
 619   Symbol* generic_signature = ikh()->generic_signature();
 620   AnnotationArray* anno = ikh()->class_annotations();

 621 
 622   int attr_count = 0;
 623   if (generic_signature != NULL) {
 624     ++attr_count;
 625   }
 626   if (ikh()->source_file_name() != NULL) {
 627     ++attr_count;
 628   }
 629   if (ikh()->source_debug_extension() != NULL) {
 630     ++attr_count;
 631   }
 632   if (inner_classes_length > 0) {
 633     ++attr_count;
 634   }
 635   if (anno != NULL) {
 636     ++attr_count;     // has RuntimeVisibleAnnotations attribute
 637   }



 638   if (cpool()->operands() != NULL) {
 639     ++attr_count;
 640   }
 641 
 642   write_u2(attr_count);
 643 
 644   if (generic_signature != NULL) {
 645     write_signature_attribute(symbol_to_cpool_index(generic_signature));
 646   }
 647   if (ikh()->source_file_name() != NULL) {
 648     write_source_file_attribute();
 649   }
 650   if (ikh()->source_debug_extension() != NULL) {
 651     write_source_debug_extension_attribute();
 652   }
 653   if (inner_classes_length > 0) {
 654     write_inner_classes_attribute(inner_classes_length);
 655   }
 656   if (anno != NULL) {
 657     write_annotations_attribute("RuntimeVisibleAnnotations", anno);
 658   }



 659   if (cpool()->operands() != NULL) {
 660     write_bootstrapmethod_attribute();
 661   }
 662 }
 663 
 664 // Write the method information portion of ClassFile structure
 665 // JVMSpec|     u2 methods_count;
 666 // JVMSpec|     method_info methods[methods_count];
 667 void JvmtiClassFileReconstituter::write_method_infos() {
 668   HandleMark hm(thread());
 669   Array<Method*>* methods = ikh()->methods();
 670   int num_methods = methods->length();
 671   int num_overpass = 0;
 672 
 673   // count the generated default interface methods
 674   // these will not be re-created by write_method_info
 675   // and should not be included in the total count
 676   for (int index = 0; index < num_methods; index++) {
 677     Method* method = methods->at(index);
 678     if (method->is_overpass()) {




  37 #ifdef TARGET_ARCH_zero
  38 # include "bytes_zero.hpp"
  39 #endif
  40 #ifdef TARGET_ARCH_arm
  41 # include "bytes_arm.hpp"
  42 #endif
  43 #ifdef TARGET_ARCH_ppc
  44 # include "bytes_ppc.hpp"
  45 #endif
  46 // FIXME: add Deprecated attribute
  47 // FIXME: fix Synthetic attribute
  48 // FIXME: per Serguei, add error return handling for ConstantPool::copy_cpool_bytes()
  49 
  50 
  51 // Write the field information portion of ClassFile structure
  52 // JVMSpec|     u2 fields_count;
  53 // JVMSpec|     field_info fields[fields_count];
  54 void JvmtiClassFileReconstituter::write_field_infos() {
  55   HandleMark hm(thread());
  56   Array<AnnotationArray*>* fields_anno = ikh()->fields_annotations();
  57   Array<AnnotationArray*>* fields_type_anno = ikh()->fields_type_annotations();
  58 
  59   // Compute the real number of Java fields
  60   int java_fields = ikh()->java_fields_count();
  61 
  62   write_u2(java_fields);
  63   for (JavaFieldStream fs(ikh()); !fs.done(); fs.next()) {
  64     AccessFlags access_flags = fs.access_flags();
  65     int name_index = fs.name_index();
  66     int signature_index = fs.signature_index();
  67     int initial_value_index = fs.initval_index();
  68     guarantee(name_index != 0 && signature_index != 0, "bad constant pool index for field");
  69     // int offset = ikh()->field_offset( index );
  70     int generic_signature_index = fs.generic_signature_index();
  71     AnnotationArray* anno = fields_anno == NULL ? NULL : fields_anno->at(fs.index());
  72     AnnotationArray* type_anno = fields_type_anno == NULL ? NULL : fields_type_anno->at(fs.index());
  73 
  74     // JVMSpec|   field_info {
  75     // JVMSpec|         u2 access_flags;
  76     // JVMSpec|         u2 name_index;
  77     // JVMSpec|         u2 descriptor_index;
  78     // JVMSpec|         u2 attributes_count;
  79     // JVMSpec|         attribute_info attributes[attributes_count];
  80     // JVMSpec|   }
  81 
  82     write_u2(access_flags.as_int() & JVM_RECOGNIZED_FIELD_MODIFIERS);
  83     write_u2(name_index);
  84     write_u2(signature_index);
  85     int attr_count = 0;
  86     if (initial_value_index != 0) {
  87       ++attr_count;
  88     }
  89     if (access_flags.is_synthetic()) {
  90       // ++attr_count;
  91     }
  92     if (generic_signature_index != 0) {
  93       ++attr_count;
  94     }
  95     if (anno != NULL) {
  96       ++attr_count;     // has RuntimeVisibleAnnotations attribute
  97     }
  98     if (type_anno != NULL) {
  99       ++attr_count;     // has RuntimeVisibleTypeAnnotations attribute
 100     }
 101 
 102     write_u2(attr_count);
 103 
 104     if (initial_value_index != 0) {
 105       write_attribute_name_index("ConstantValue");
 106       write_u4(2); //length always 2
 107       write_u2(initial_value_index);
 108     }
 109     if (access_flags.is_synthetic()) {
 110       // write_synthetic_attribute();
 111     }
 112     if (generic_signature_index != 0) {
 113       write_signature_attribute(generic_signature_index);
 114     }
 115     if (anno != NULL) {
 116       write_annotations_attribute("RuntimeVisibleAnnotations", anno);
 117     }
 118     if (type_anno != NULL) {
 119       write_annotations_attribute("RuntimeVisibleTypeAnnotations", type_anno);
 120     }
 121   }
 122 }
 123 
 124 // Write Code attribute
 125 // JVMSpec|   Code_attribute {
 126 // JVMSpec|     u2 attribute_name_index;
 127 // JVMSpec|     u4 attribute_length;
 128 // JVMSpec|     u2 max_stack;
 129 // JVMSpec|     u2 max_locals;
 130 // JVMSpec|     u4 code_length;
 131 // JVMSpec|     u1 code[code_length];
 132 // JVMSpec|     u2 exception_table_length;
 133 // JVMSpec|     {       u2 start_pc;
 134 // JVMSpec|             u2 end_pc;
 135 // JVMSpec|             u2  handler_pc;
 136 // JVMSpec|             u2  catch_type;
 137 // JVMSpec|     }       exception_table[exception_table_length];
 138 // JVMSpec|     u2 attributes_count;
 139 // JVMSpec|     attribute_info attributes[attributes_count];
 140 // JVMSpec|   }


 541     writeable_address(stackmap_len),
 542     (void*)(method->stackmap_data()->adr_at(0)),
 543     stackmap_len);
 544 }
 545 
 546 // Write one method_info structure
 547 // JVMSpec|   method_info {
 548 // JVMSpec|     u2 access_flags;
 549 // JVMSpec|     u2 name_index;
 550 // JVMSpec|     u2 descriptor_index;
 551 // JVMSpec|     u2 attributes_count;
 552 // JVMSpec|     attribute_info attributes[attributes_count];
 553 // JVMSpec|   }
 554 void JvmtiClassFileReconstituter::write_method_info(methodHandle method) {
 555   AccessFlags access_flags = method->access_flags();
 556   ConstMethod* const_method = method->constMethod();
 557   u2 generic_signature_index = const_method->generic_signature_index();
 558   AnnotationArray* anno = method->annotations();
 559   AnnotationArray* param_anno = method->parameter_annotations();
 560   AnnotationArray* default_anno = method->annotation_default();
 561   AnnotationArray* type_anno = method->type_annotations();
 562 
 563   // skip generated default interface methods
 564   if (method->is_overpass()) {
 565     return;
 566   }
 567 
 568   write_u2(access_flags.get_flags() & JVM_RECOGNIZED_METHOD_MODIFIERS);
 569   write_u2(const_method->name_index());
 570   write_u2(const_method->signature_index());
 571 
 572   // write attributes in the same order javac does, so we can test with byte for
 573   // byte comparison
 574   int attr_count = 0;
 575   if (const_method->code_size() != 0) {
 576     ++attr_count;     // has Code attribute
 577   }
 578   if (const_method->has_checked_exceptions()) {
 579     ++attr_count;     // has Exceptions attribute
 580   }
 581   if (default_anno != NULL) {
 582     ++attr_count;     // has AnnotationDefault attribute
 583   }
 584   // Deprecated attribute would go here
 585   if (access_flags.is_synthetic()) { // FIXME
 586     // ++attr_count;
 587   }
 588   if (generic_signature_index != 0) {
 589     ++attr_count;
 590   }
 591   if (anno != NULL) {
 592     ++attr_count;     // has RuntimeVisibleAnnotations attribute
 593   }
 594   if (param_anno != NULL) {
 595     ++attr_count;     // has RuntimeVisibleParameterAnnotations attribute
 596   }
 597   if (type_anno != NULL) {
 598     ++attr_count;     // has RuntimeVisibleTypeAnnotations attribute
 599   }
 600 
 601   write_u2(attr_count);
 602   if (const_method->code_size() > 0) {
 603     write_code_attribute(method);
 604   }
 605   if (const_method->has_checked_exceptions()) {
 606     write_exceptions_attribute(const_method);
 607   }
 608   if (default_anno != NULL) {
 609     write_annotations_attribute("AnnotationDefault", default_anno);
 610   }
 611   // Deprecated attribute would go here
 612   if (access_flags.is_synthetic()) {
 613     // write_synthetic_attribute();
 614   }
 615   if (generic_signature_index != 0) {
 616     write_signature_attribute(generic_signature_index);
 617   }
 618   if (anno != NULL) {
 619     write_annotations_attribute("RuntimeVisibleAnnotations", anno);
 620   }
 621   if (param_anno != NULL) {
 622     write_annotations_attribute("RuntimeVisibleParameterAnnotations", param_anno);
 623   }
 624   if (type_anno != NULL) {
 625     write_annotations_attribute("RuntimeVisibleTypeAnnotations", type_anno);
 626   }
 627 }
 628 
 629 // Write the class attributes portion of ClassFile structure
 630 // JVMSpec|     u2 attributes_count;
 631 // JVMSpec|     attribute_info attributes[attributes_count];
 632 void JvmtiClassFileReconstituter::write_class_attributes() {
 633   u2 inner_classes_length = inner_classes_attribute_length();
 634   Symbol* generic_signature = ikh()->generic_signature();
 635   AnnotationArray* anno = ikh()->class_annotations();
 636   AnnotationArray* type_anno = ikh()->class_type_annotations();
 637 
 638   int attr_count = 0;
 639   if (generic_signature != NULL) {
 640     ++attr_count;
 641   }
 642   if (ikh()->source_file_name() != NULL) {
 643     ++attr_count;
 644   }
 645   if (ikh()->source_debug_extension() != NULL) {
 646     ++attr_count;
 647   }
 648   if (inner_classes_length > 0) {
 649     ++attr_count;
 650   }
 651   if (anno != NULL) {
 652     ++attr_count;     // has RuntimeVisibleAnnotations attribute
 653   }
 654   if (type_anno != NULL) {
 655     ++attr_count;     // has RuntimeVisibleTypeAnnotations attribute
 656   }
 657   if (cpool()->operands() != NULL) {
 658     ++attr_count;
 659   }
 660 
 661   write_u2(attr_count);
 662 
 663   if (generic_signature != NULL) {
 664     write_signature_attribute(symbol_to_cpool_index(generic_signature));
 665   }
 666   if (ikh()->source_file_name() != NULL) {
 667     write_source_file_attribute();
 668   }
 669   if (ikh()->source_debug_extension() != NULL) {
 670     write_source_debug_extension_attribute();
 671   }
 672   if (inner_classes_length > 0) {
 673     write_inner_classes_attribute(inner_classes_length);
 674   }
 675   if (anno != NULL) {
 676     write_annotations_attribute("RuntimeVisibleAnnotations", anno);
 677   }
 678   if (type_anno != NULL) {
 679     write_annotations_attribute("RuntimeVisibleTypeAnnotations", type_anno);
 680   }
 681   if (cpool()->operands() != NULL) {
 682     write_bootstrapmethod_attribute();
 683   }
 684 }
 685 
 686 // Write the method information portion of ClassFile structure
 687 // JVMSpec|     u2 methods_count;
 688 // JVMSpec|     method_info methods[methods_count];
 689 void JvmtiClassFileReconstituter::write_method_infos() {
 690   HandleMark hm(thread());
 691   Array<Method*>* methods = ikh()->methods();
 692   int num_methods = methods->length();
 693   int num_overpass = 0;
 694 
 695   // count the generated default interface methods
 696   // these will not be re-created by write_method_info
 697   // and should not be included in the total count
 698   for (int index = 0; index < num_methods; index++) {
 699     Method* method = methods->at(index);
 700     if (method->is_overpass()) {


< prev index next >