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

Split Split Close
Expand all
Collapse all
          --- old/src/share/vm/prims/jvmtiClassFileReconstituter.cpp
          +++ new/src/share/vm/prims/jvmtiClassFileReconstituter.cpp
↓ open down ↓ 46 lines elided ↑ open up ↑
  47   47  // FIXME: fix Synthetic attribute
  48   48  // FIXME: per Serguei, add error return handling for ConstantPool::copy_cpool_bytes()
  49   49  
  50   50  
  51   51  // Write the field information portion of ClassFile structure
  52   52  // JVMSpec|     u2 fields_count;
  53   53  // JVMSpec|     field_info fields[fields_count];
  54   54  void JvmtiClassFileReconstituter::write_field_infos() {
  55   55    HandleMark hm(thread());
  56   56    Array<AnnotationArray*>* fields_anno = ikh()->fields_annotations();
       57 +  Array<AnnotationArray*>* fields_type_anno = ikh()->fields_type_annotations();
  57   58  
  58   59    // Compute the real number of Java fields
  59   60    int java_fields = ikh()->java_fields_count();
  60   61  
  61   62    write_u2(java_fields);
  62   63    for (JavaFieldStream fs(ikh()); !fs.done(); fs.next()) {
  63   64      AccessFlags access_flags = fs.access_flags();
  64   65      int name_index = fs.name_index();
  65   66      int signature_index = fs.signature_index();
  66   67      int initial_value_index = fs.initval_index();
  67   68      guarantee(name_index != 0 && signature_index != 0, "bad constant pool index for field");
  68   69      // int offset = ikh()->field_offset( index );
  69   70      int generic_signature_index = fs.generic_signature_index();
  70   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());
  71   73  
  72   74      // JVMSpec|   field_info {
  73   75      // JVMSpec|         u2 access_flags;
  74   76      // JVMSpec|         u2 name_index;
  75   77      // JVMSpec|         u2 descriptor_index;
  76   78      // JVMSpec|         u2 attributes_count;
  77   79      // JVMSpec|         attribute_info attributes[attributes_count];
  78   80      // JVMSpec|   }
  79   81  
  80   82      write_u2(access_flags.as_int() & JVM_RECOGNIZED_FIELD_MODIFIERS);
↓ open down ↓ 5 lines elided ↑ open up ↑
  86   88      }
  87   89      if (access_flags.is_synthetic()) {
  88   90        // ++attr_count;
  89   91      }
  90   92      if (generic_signature_index != 0) {
  91   93        ++attr_count;
  92   94      }
  93   95      if (anno != NULL) {
  94   96        ++attr_count;     // has RuntimeVisibleAnnotations attribute
  95   97      }
       98 +    if (type_anno != NULL) {
       99 +      ++attr_count;     // has RuntimeVisibleTypeAnnotations attribute
      100 +    }
  96  101  
  97  102      write_u2(attr_count);
  98  103  
  99  104      if (initial_value_index != 0) {
 100  105        write_attribute_name_index("ConstantValue");
 101  106        write_u4(2); //length always 2
 102  107        write_u2(initial_value_index);
 103  108      }
 104  109      if (access_flags.is_synthetic()) {
 105  110        // write_synthetic_attribute();
 106  111      }
 107  112      if (generic_signature_index != 0) {
 108  113        write_signature_attribute(generic_signature_index);
 109  114      }
 110  115      if (anno != NULL) {
 111  116        write_annotations_attribute("RuntimeVisibleAnnotations", anno);
 112  117      }
      118 +    if (type_anno != NULL) {
      119 +      write_annotations_attribute("RuntimeVisibleTypeAnnotations", type_anno);
      120 +    }
 113  121    }
 114  122  }
 115  123  
 116  124  // Write Code attribute
 117  125  // JVMSpec|   Code_attribute {
 118  126  // JVMSpec|     u2 attribute_name_index;
 119  127  // JVMSpec|     u4 attribute_length;
 120  128  // JVMSpec|     u2 max_stack;
 121  129  // JVMSpec|     u2 max_locals;
 122  130  // JVMSpec|     u4 code_length;
↓ open down ↓ 420 lines elided ↑ open up ↑
 543  551  // JVMSpec|     u2 attributes_count;
 544  552  // JVMSpec|     attribute_info attributes[attributes_count];
 545  553  // JVMSpec|   }
 546  554  void JvmtiClassFileReconstituter::write_method_info(methodHandle method) {
 547  555    AccessFlags access_flags = method->access_flags();
 548  556    ConstMethod* const_method = method->constMethod();
 549  557    u2 generic_signature_index = const_method->generic_signature_index();
 550  558    AnnotationArray* anno = method->annotations();
 551  559    AnnotationArray* param_anno = method->parameter_annotations();
 552  560    AnnotationArray* default_anno = method->annotation_default();
      561 +  AnnotationArray* type_anno = method->type_annotations();
 553  562  
 554  563    // skip generated default interface methods
 555  564    if (method->is_overpass()) {
 556  565      return;
 557  566    }
 558  567  
 559  568    write_u2(access_flags.get_flags() & JVM_RECOGNIZED_METHOD_MODIFIERS);
 560  569    write_u2(const_method->name_index());
 561  570    write_u2(const_method->signature_index());
 562  571  
↓ open down ↓ 15 lines elided ↑ open up ↑
 578  587    }
 579  588    if (generic_signature_index != 0) {
 580  589      ++attr_count;
 581  590    }
 582  591    if (anno != NULL) {
 583  592      ++attr_count;     // has RuntimeVisibleAnnotations attribute
 584  593    }
 585  594    if (param_anno != NULL) {
 586  595      ++attr_count;     // has RuntimeVisibleParameterAnnotations attribute
 587  596    }
      597 +  if (type_anno != NULL) {
      598 +    ++attr_count;     // has RuntimeVisibleTypeAnnotations attribute
      599 +  }
 588  600  
 589  601    write_u2(attr_count);
 590  602    if (const_method->code_size() > 0) {
 591  603      write_code_attribute(method);
 592  604    }
 593  605    if (const_method->has_checked_exceptions()) {
 594  606      write_exceptions_attribute(const_method);
 595  607    }
 596  608    if (default_anno != NULL) {
 597  609      write_annotations_attribute("AnnotationDefault", default_anno);
↓ open down ↓ 4 lines elided ↑ open up ↑
 602  614    }
 603  615    if (generic_signature_index != 0) {
 604  616      write_signature_attribute(generic_signature_index);
 605  617    }
 606  618    if (anno != NULL) {
 607  619      write_annotations_attribute("RuntimeVisibleAnnotations", anno);
 608  620    }
 609  621    if (param_anno != NULL) {
 610  622      write_annotations_attribute("RuntimeVisibleParameterAnnotations", param_anno);
 611  623    }
      624 +  if (type_anno != NULL) {
      625 +    write_annotations_attribute("RuntimeVisibleTypeAnnotations", type_anno);
      626 +  }
 612  627  }
 613  628  
 614  629  // Write the class attributes portion of ClassFile structure
 615  630  // JVMSpec|     u2 attributes_count;
 616  631  // JVMSpec|     attribute_info attributes[attributes_count];
 617  632  void JvmtiClassFileReconstituter::write_class_attributes() {
 618  633    u2 inner_classes_length = inner_classes_attribute_length();
 619  634    Symbol* generic_signature = ikh()->generic_signature();
 620  635    AnnotationArray* anno = ikh()->class_annotations();
      636 +  AnnotationArray* type_anno = ikh()->class_type_annotations();
 621  637  
 622  638    int attr_count = 0;
 623  639    if (generic_signature != NULL) {
 624  640      ++attr_count;
 625  641    }
 626  642    if (ikh()->source_file_name() != NULL) {
 627  643      ++attr_count;
 628  644    }
 629  645    if (ikh()->source_debug_extension() != NULL) {
 630  646      ++attr_count;
 631  647    }
 632  648    if (inner_classes_length > 0) {
 633  649      ++attr_count;
 634  650    }
 635  651    if (anno != NULL) {
 636  652      ++attr_count;     // has RuntimeVisibleAnnotations attribute
 637  653    }
      654 +  if (type_anno != NULL) {
      655 +    ++attr_count;     // has RuntimeVisibleTypeAnnotations attribute
      656 +  }
 638  657    if (cpool()->operands() != NULL) {
 639  658      ++attr_count;
 640  659    }
 641  660  
 642  661    write_u2(attr_count);
 643  662  
 644  663    if (generic_signature != NULL) {
 645  664      write_signature_attribute(symbol_to_cpool_index(generic_signature));
 646  665    }
 647  666    if (ikh()->source_file_name() != NULL) {
↓ open down ↓ 1 lines elided ↑ open up ↑
 649  668    }
 650  669    if (ikh()->source_debug_extension() != NULL) {
 651  670      write_source_debug_extension_attribute();
 652  671    }
 653  672    if (inner_classes_length > 0) {
 654  673      write_inner_classes_attribute(inner_classes_length);
 655  674    }
 656  675    if (anno != NULL) {
 657  676      write_annotations_attribute("RuntimeVisibleAnnotations", anno);
 658  677    }
      678 +  if (type_anno != NULL) {
      679 +    write_annotations_attribute("RuntimeVisibleTypeAnnotations", type_anno);
      680 +  }
 659  681    if (cpool()->operands() != NULL) {
 660  682      write_bootstrapmethod_attribute();
 661  683    }
 662  684  }
 663  685  
 664  686  // Write the method information portion of ClassFile structure
 665  687  // JVMSpec|     u2 methods_count;
 666  688  // JVMSpec|     method_info methods[methods_count];
 667  689  void JvmtiClassFileReconstituter::write_method_infos() {
 668  690    HandleMark hm(thread());
↓ open down ↓ 221 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX