< prev index next >

src/hotspot/share/prims/jvmtiClassFileReconstituter.cpp

Print this page


   1 /*
   2  * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  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  *


 406 //  NestMembers_attribute {
 407 //    u2 attribute_name_index;
 408 //    u4 attribute_length;
 409 //    u2 number_of_classes;
 410 //    u2 classes[number_of_classes];
 411 //  }
 412 void JvmtiClassFileReconstituter::write_nest_members_attribute() {
 413   Array<u2>* nest_members = ik()->nest_members();
 414   int number_of_classes = nest_members->length();
 415   int length = sizeof(u2) * (1 + number_of_classes);
 416 
 417   write_attribute_name_index("NestMembers");
 418   write_u4(length);
 419   write_u2(number_of_classes);
 420   for (int i = 0; i < number_of_classes; i++) {
 421     u2 class_cp_index = nest_members->at(i);
 422     write_u2(class_cp_index);
 423   }
 424 }
 425 




















 426 
 427 // Write InnerClasses attribute
 428 // JVMSpec|   InnerClasses_attribute {
 429 // JVMSpec|     u2 attribute_name_index;
 430 // JVMSpec|     u4 attribute_length;
 431 // JVMSpec|     u2 number_of_classes;
 432 // JVMSpec|     {  u2 inner_class_info_index;
 433 // JVMSpec|        u2 outer_class_info_index;
 434 // JVMSpec|        u2 inner_name_index;
 435 // JVMSpec|        u2 inner_class_access_flags;
 436 // JVMSpec|     } classes[number_of_classes];
 437 // JVMSpec|   }
 438 void JvmtiClassFileReconstituter::write_inner_classes_attribute(int length) {
 439   InnerClassesIterator iter(ik());
 440   guarantee(iter.length() != 0 && iter.length() == length,
 441             "caller must check");
 442   u2 entry_count = length / InstanceKlass::inner_class_next_offset;
 443   u4 size = 2 + entry_count * (2+2+2+2);
 444 
 445   write_attribute_name_index("InnerClasses");


 682     ++attr_count;
 683   }
 684   if (inner_classes_length > 0) {
 685     ++attr_count;
 686   }
 687   if (anno != NULL) {
 688     ++attr_count;     // has RuntimeVisibleAnnotations attribute
 689   }
 690   if (type_anno != NULL) {
 691     ++attr_count;     // has RuntimeVisibleTypeAnnotations attribute
 692   }
 693   if (cpool()->operands() != NULL) {
 694     ++attr_count;
 695   }
 696   if (ik()->nest_host_index() != 0) {
 697     ++attr_count;
 698   }
 699   if (ik()->nest_members() != Universe::the_empty_short_array()) {
 700     ++attr_count;
 701   }



 702 
 703   write_u2(attr_count);
 704 
 705   if (generic_signature != NULL) {
 706     write_signature_attribute(symbol_to_cpool_index(generic_signature));
 707   }
 708   if (ik()->source_file_name() != NULL) {
 709     write_source_file_attribute();
 710   }
 711   if (ik()->source_debug_extension() != NULL) {
 712     write_source_debug_extension_attribute();
 713   }
 714   if (inner_classes_length > 0) {
 715     write_inner_classes_attribute(inner_classes_length);
 716   }
 717   if (anno != NULL) {
 718     write_annotations_attribute("RuntimeVisibleAnnotations", anno);
 719   }
 720   if (type_anno != NULL) {
 721     write_annotations_attribute("RuntimeVisibleTypeAnnotations", type_anno);
 722   }
 723   if (cpool()->operands() != NULL) {
 724     write_bootstrapmethod_attribute();
 725   }
 726   if (ik()->nest_host_index() != 0) {
 727     write_nest_host_attribute();
 728   }
 729   if (ik()->nest_members() != Universe::the_empty_short_array()) {
 730     write_nest_members_attribute();



 731   }
 732 }
 733 
 734 // Write the method information portion of ClassFile structure
 735 // JVMSpec|     u2 methods_count;
 736 // JVMSpec|     method_info methods[methods_count];
 737 void JvmtiClassFileReconstituter::write_method_infos() {
 738   HandleMark hm(thread());
 739   Array<Method*>* methods = ik()->methods();
 740   int num_methods = methods->length();
 741   int num_overpass = 0;
 742 
 743   // count the generated default interface methods
 744   // these will not be re-created by write_method_info
 745   // and should not be included in the total count
 746   for (int index = 0; index < num_methods; index++) {
 747     Method* method = methods->at(index);
 748     if (method->is_overpass()) {
 749       num_overpass++;
 750     }


   1 /*
   2  * Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  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  *


 406 //  NestMembers_attribute {
 407 //    u2 attribute_name_index;
 408 //    u4 attribute_length;
 409 //    u2 number_of_classes;
 410 //    u2 classes[number_of_classes];
 411 //  }
 412 void JvmtiClassFileReconstituter::write_nest_members_attribute() {
 413   Array<u2>* nest_members = ik()->nest_members();
 414   int number_of_classes = nest_members->length();
 415   int length = sizeof(u2) * (1 + number_of_classes);
 416 
 417   write_attribute_name_index("NestMembers");
 418   write_u4(length);
 419   write_u2(number_of_classes);
 420   for (int i = 0; i < number_of_classes; i++) {
 421     u2 class_cp_index = nest_members->at(i);
 422     write_u2(class_cp_index);
 423   }
 424 }
 425 
 426 //  PermittedSubtypes {
 427 //    u2 attribute_name_index;
 428 //    u4 attribute_length;
 429 //    u2 number_of_classes;
 430 //    u2 classes[number_of_classes];
 431 //  }
 432 void JvmtiClassFileReconstituter::write_permitted_subtypes_attribute() {
 433   Array<u2>* permitted_subtypes = ik()->permitted_subtypes();
 434   int number_of_classes = permitted_subtypes->length();
 435   int length = sizeof(u2) * (1 + number_of_classes);
 436 
 437   write_attribute_name_index("PermittedSubtypes");
 438   write_u4(length);
 439   write_u2(number_of_classes);
 440   for (int i = 0; i < number_of_classes; i++) {
 441     u2 class_cp_index = permitted_subtypes->at(i);
 442     write_u2(class_cp_index);
 443   }
 444 }
 445 
 446 
 447 // Write InnerClasses attribute
 448 // JVMSpec|   InnerClasses_attribute {
 449 // JVMSpec|     u2 attribute_name_index;
 450 // JVMSpec|     u4 attribute_length;
 451 // JVMSpec|     u2 number_of_classes;
 452 // JVMSpec|     {  u2 inner_class_info_index;
 453 // JVMSpec|        u2 outer_class_info_index;
 454 // JVMSpec|        u2 inner_name_index;
 455 // JVMSpec|        u2 inner_class_access_flags;
 456 // JVMSpec|     } classes[number_of_classes];
 457 // JVMSpec|   }
 458 void JvmtiClassFileReconstituter::write_inner_classes_attribute(int length) {
 459   InnerClassesIterator iter(ik());
 460   guarantee(iter.length() != 0 && iter.length() == length,
 461             "caller must check");
 462   u2 entry_count = length / InstanceKlass::inner_class_next_offset;
 463   u4 size = 2 + entry_count * (2+2+2+2);
 464 
 465   write_attribute_name_index("InnerClasses");


 702     ++attr_count;
 703   }
 704   if (inner_classes_length > 0) {
 705     ++attr_count;
 706   }
 707   if (anno != NULL) {
 708     ++attr_count;     // has RuntimeVisibleAnnotations attribute
 709   }
 710   if (type_anno != NULL) {
 711     ++attr_count;     // has RuntimeVisibleTypeAnnotations attribute
 712   }
 713   if (cpool()->operands() != NULL) {
 714     ++attr_count;
 715   }
 716   if (ik()->nest_host_index() != 0) {
 717     ++attr_count;
 718   }
 719   if (ik()->nest_members() != Universe::the_empty_short_array()) {
 720     ++attr_count;
 721   }
 722   if (ik()->permitted_subtypes() != Universe::the_empty_short_array()) {
 723     ++attr_count;
 724   }
 725 
 726   write_u2(attr_count);
 727 
 728   if (generic_signature != NULL) {
 729     write_signature_attribute(symbol_to_cpool_index(generic_signature));
 730   }
 731   if (ik()->source_file_name() != NULL) {
 732     write_source_file_attribute();
 733   }
 734   if (ik()->source_debug_extension() != NULL) {
 735     write_source_debug_extension_attribute();
 736   }
 737   if (inner_classes_length > 0) {
 738     write_inner_classes_attribute(inner_classes_length);
 739   }
 740   if (anno != NULL) {
 741     write_annotations_attribute("RuntimeVisibleAnnotations", anno);
 742   }
 743   if (type_anno != NULL) {
 744     write_annotations_attribute("RuntimeVisibleTypeAnnotations", type_anno);
 745   }
 746   if (cpool()->operands() != NULL) {
 747     write_bootstrapmethod_attribute();
 748   }
 749   if (ik()->nest_host_index() != 0) {
 750     write_nest_host_attribute();
 751   }
 752   if (ik()->nest_members() != Universe::the_empty_short_array()) {
 753     write_nest_members_attribute();
 754   }
 755   if (ik()->permitted_subtypes() != Universe::the_empty_short_array()) {
 756     write_permitted_subtypes_attribute();
 757   }
 758 }
 759 
 760 // Write the method information portion of ClassFile structure
 761 // JVMSpec|     u2 methods_count;
 762 // JVMSpec|     method_info methods[methods_count];
 763 void JvmtiClassFileReconstituter::write_method_infos() {
 764   HandleMark hm(thread());
 765   Array<Method*>* methods = ik()->methods();
 766   int num_methods = methods->length();
 767   int num_overpass = 0;
 768 
 769   // count the generated default interface methods
 770   // these will not be re-created by write_method_info
 771   // and should not be included in the total count
 772   for (int index = 0; index < num_methods; index++) {
 773     Method* method = methods->at(index);
 774     if (method->is_overpass()) {
 775       num_overpass++;
 776     }


< prev index next >