jvmtiClassFileReconstituter.cpp revision 726
196N/A * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 0N/A * CA 95054 USA or visit www.sun.com if you need additional information or 0N/A * have any questions. 0N/A#
include "incls/_precompiled.incl" 0N/A// FIXME: add Deprecated, LVT, LVTT attributes 0N/A// FIXME: fix Synthetic attribute 0N/A// FIXME: per Serguei, add error return handling for constantPoolOopDesc::copy_cpool_bytes() 0N/A// Write the field information portion of ClassFile structure 0N/A// JVMSpec| u2 fields_count; 0N/A// JVMSpec| field_info fields[fields_count]; 0N/A // JVMSpec| field_info { 0N/A // JVMSpec| u2 access_flags; 0N/A // JVMSpec| u2 name_index; 0N/A // JVMSpec| u2 descriptor_index; 0N/A // JVMSpec| u2 attributes_count; 0N/A // JVMSpec| attribute_info attributes[attributes_count]; 417N/A // write_synthetic_attribute(); 0N/A// Write Code attribute 0N/A// JVMSpec| Code_attribute { 0N/A// JVMSpec| u2 attribute_name_index; 0N/A// JVMSpec| u4 attribute_length; 0N/A// JVMSpec| u2 max_stack; 0N/A// JVMSpec| u2 max_locals; 0N/A// JVMSpec| u4 code_length; 0N/A// JVMSpec| u1 code[code_length]; 0N/A// JVMSpec| u2 exception_table_length; 0N/A// JVMSpec| { u2 start_pc; 0N/A// JVMSpec| u2 end_pc; 0N/A// JVMSpec| u2 handler_pc; 0N/A// JVMSpec| u2 catch_type; 0N/A// JVMSpec| } exception_table[exception_table_length]; 0N/A// JVMSpec| u2 attributes_count; 0N/A// JVMSpec| attribute_info attributes[attributes_count]; 0N/A // compute number and length of attributes -- FIXME: for now no LVT 0N/A // Compute the complete size of the line number table attribute: 0N/A // LineNumberTable_attribute { 0N/A // u2 attribute_name_index; 0N/A // u4 attribute_length; 0N/A // u2 line_number_table_length; 0N/A // } line_number_table[line_number_table_length]; 0N/A // Compute the size of the stack map table attribute (VM stores raw): 0N/A // StackMapTable_attribute { 0N/A // u2 attribute_name_index; 0N/A // u4 attribute_length; 0N/A // u2 number_of_entries; 0N/A // stack_map_frame_entries[number_of_entries]; 0N/A 2+
2+
4 +
// max_stack, max_locals, code_length 0N/A 2 +
// exception_table_length 0N/A 2 +
// attributes_count 0N/A // FIXME: write LVT attribute 0N/A// Write Exceptions attribute 0N/A// JVMSpec| Exceptions_attribute { 0N/A// JVMSpec| u2 attribute_name_index; 0N/A// JVMSpec| u4 attribute_length; 0N/A// JVMSpec| u2 number_of_exceptions; 0N/A// JVMSpec| u2 exception_index_table[number_of_exceptions]; 0N/A 2 +
// number_of_exceptions 0N/A// Write SourceFile attribute 0N/A// JVMSpec| SourceFile_attribute { 0N/A// JVMSpec| u2 attribute_name_index; 0N/A// JVMSpec| u4 attribute_length; 0N/A// JVMSpec| u2 sourcefile_index; 0N/A// Write SourceDebugExtension attribute 0N/A// JSR45| SourceDebugExtension_attribute { 0N/A// JSR45| u2 attribute_name_index; 0N/A// JSR45| u4 attribute_length; 0N/A// JSR45| u2 sourcefile_index; 0N/A// Write (generic) Signature attribute 0N/A// JVMSpec| Signature_attribute { 0N/A// JVMSpec| u2 attribute_name_index; 0N/A// JVMSpec| u4 attribute_length; 0N/A// JVMSpec| u2 signature_index; 0N/A// Compute the number of entries in the InnerClasses attribute 0N/A// Write an annotation attribute. The VM stores them in raw form, so all we need 0N/A// to do is add the attrubute name and fill in the length. 0N/A// JSR202| *Annotations_attribute { 0N/A// JSR202| u2 attribute_name_index; 0N/A// JSR202| u4 attribute_length; 0N/A// Write InnerClasses attribute 0N/A// JVMSpec| InnerClasses_attribute { 0N/A// JVMSpec| u2 attribute_name_index; 0N/A// JVMSpec| u4 attribute_length; 0N/A// JVMSpec| u2 number_of_classes; 0N/A// JVMSpec| { u2 inner_class_info_index; 0N/A// JVMSpec| u2 outer_class_info_index; 0N/A// JVMSpec| u2 inner_name_index; 0N/A// JVMSpec| u2 inner_class_access_flags; 0N/A// JVMSpec| } classes[number_of_classes]; 0N/A "caller must check");
0N/A// Write Synthetic attribute 0N/A// JVMSpec| Synthetic_attribute { 0N/A// JVMSpec| u2 attribute_name_index; 0N/A// JVMSpec| u4 attribute_length; 0N/A// Compute size of LineNumberTable 0N/A // The line number table is compressed so we don't know how big it is until decompressed. 0N/A // Decompression is really fast so we just do it twice. 0N/A// Write LineNumberTable attribute 0N/A// JVMSpec| LineNumberTable_attribute { 0N/A// JVMSpec| u2 attribute_name_index; 0N/A// JVMSpec| u4 attribute_length; 0N/A// JVMSpec| u2 line_number_table_length; 0N/A// JVMSpec| { u2 start_pc; 0N/A// JVMSpec| u2 line_number; 0N/A// JVMSpec| } line_number_table[line_number_table_length]; 0N/A// Write stack map table attribute 0N/A// JSR-202| StackMapTable_attribute { 0N/A// JSR-202| u2 attribute_name_index; 0N/A// JSR-202| u4 attribute_length; 0N/A// JSR-202| u2 number_of_entries; 0N/A// JSR-202| stack_map_frame_entries[number_of_entries]; 0N/A// Write one method_info structure 0N/A// JVMSpec| method_info { 0N/A// JVMSpec| u2 access_flags; 0N/A// JVMSpec| u2 name_index; 0N/A// JVMSpec| u2 descriptor_index; 0N/A// JVMSpec| u2 attributes_count; 0N/A// JVMSpec| attribute_info attributes[attributes_count]; 0N/A // write attributes in the same order javac does, so we can test with byte for 0N/A // Deprecated attribute would go here 0N/A ++
attr_count;
// has RuntimeVisibleParameterAnnotations attribute 0N/A // Deprecated attribute would go here 0N/A // write_synthetic_attribute(); 0N/A// Write the class attributes portion of ClassFile structure 0N/A// JVMSpec| u2 attributes_count; 0N/A// JVMSpec| attribute_info attributes[attributes_count]; 0N/A// Write the method information portion of ClassFile structure 0N/A// JVMSpec| u2 methods_count; 0N/A// JVMSpec| method_info methods[methods_count]; 0N/A // invert the method order mapping 0N/A "invalid original method index");
0N/A // write in original order 0N/A // method order not preserved just dump the method infos 0N/A // JVMSpec| ClassFile { 0N/A // JVMSpec| u4 magic; 0N/A // JVMSpec| u2 minor_version; 0N/A // JVMSpec| u2 major_version; 0N/A // JVMSpec| u2 constant_pool_count; 0N/A // JVMSpec| cp_info constant_pool[constant_pool_count-1]; 0N/A // JVMSpec| u2 access_flags; 0N/A // JVMSpec| u2 this_class; 0N/A // JVMSpec| u2 super_class; 0N/A // JVMSpec| u2 interfaces_count; 0N/A // JVMSpec| u2 interfaces[interfaces_count]; 0N/A // JVMSpec| u2 fields_count; 0N/A // JVMSpec| field_info fields[fields_count]; 0N/A // JVMSpec| u2 methods_count; 0N/A // JVMSpec| method_info methods[methods_count]; 0N/A // JVMSpec| u2 attributes_count; 0N/A // JVMSpec| attribute_info attributes[attributes_count]; 0N/A // JVMSpec| } /* end ClassFile 8? 0N/A // compute the new buffer size: must be at least twice as big as before 0N/A // plus whatever new is being used; then convert to nice clean block boundary 0N/A // VM goes belly-up if the memory isn't available, so cannot do OOM processing 0N/A // use a BytecodeStream to iterate over the bytecodes. JVM/fast bytecodes 0N/A // and the breakpoint bytecode are converted to their original bytecodes. 0N/A // length of bytecode (mnemonic + operands) 0N/A // copy the bytecodes 0N/A // During linking the get/put and invoke instructions are rewritten 0N/A // with an index into the constant pool cache. The original constant 0N/A // pool index must be returned to caller. Rewrite the index. 0N/A // cache cannot be pre-fetched since some classes won't have it yet