jvmtiClassFileReconstituter.cpp revision 2073
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "precompiled.hpp"
#include "classfile/symbolTable.hpp"
#include "interpreter/bytecodeStream.hpp"
#include "prims/jvmtiClassFileReconstituter.hpp"
#include "runtime/signature.hpp"
#ifdef TARGET_ARCH_x86
# include "bytes_x86.hpp"
#endif
#ifdef TARGET_ARCH_sparc
# include "bytes_sparc.hpp"
#endif
#ifdef TARGET_ARCH_zero
# include "bytes_zero.hpp"
#endif
#ifdef TARGET_ARCH_arm
# include "bytes_arm.hpp"
#endif
#ifdef TARGET_ARCH_ppc
# include "bytes_ppc.hpp"
#endif
// FIXME: add Deprecated, LVT, LVTT attributes
// FIXME: fix Synthetic attribute
// FIXME: per Serguei, add error return handling for constantPoolOopDesc::copy_cpool_bytes()
// Write the field information portion of ClassFile structure
// JVMSpec| u2 fields_count;
// JVMSpec| field_info fields[fields_count];
void JvmtiClassFileReconstituter::write_field_infos() {
int generic_signature_index =
(typeArrayOop)NULL);
// JVMSpec| field_info {
// JVMSpec| u2 access_flags;
// JVMSpec| u2 name_index;
// JVMSpec| u2 descriptor_index;
// JVMSpec| u2 attributes_count;
// JVMSpec| attribute_info attributes[attributes_count];
// JVMSpec| }
int attr_count = 0;
if (initial_value_index != 0) {
++attr_count;
}
if (access_flags.is_synthetic()) {
// ++attr_count;
}
if (generic_signature_index != 0) {
++attr_count;
}
++attr_count; // has RuntimeVisibleAnnotations attribute
}
if (initial_value_index != 0) {
write_attribute_name_index("ConstantValue");
}
if (access_flags.is_synthetic()) {
// write_synthetic_attribute();
}
if (generic_signature_index != 0) {
}
}
}
}
// Write Code attribute
// JVMSpec| Code_attribute {
// JVMSpec| u2 attribute_name_index;
// JVMSpec| u4 attribute_length;
// JVMSpec| u2 max_stack;
// JVMSpec| u2 max_locals;
// JVMSpec| u4 code_length;
// JVMSpec| u1 code[code_length];
// JVMSpec| u2 exception_table_length;
// JVMSpec| { u2 start_pc;
// JVMSpec| u2 end_pc;
// JVMSpec| u2 handler_pc;
// JVMSpec| u2 catch_type;
// JVMSpec| } exception_table[exception_table_length];
// JVMSpec| u2 attributes_count;
// JVMSpec| attribute_info attributes[attributes_count];
// JVMSpec| }
u2 line_num_cnt = 0;
int stackmap_len = 0;
// compute number and length of attributes -- FIXME: for now no LVT
int attr_count = 0;
int attr_size = 0;
if (const_method->has_linenumber_table()) {
if (line_num_cnt != 0) {
++attr_count;
// Compute the complete size of the line number table attribute:
// LineNumberTable_attribute {
// u2 attribute_name_index;
// u4 attribute_length;
// u2 line_number_table_length;
// { u2 start_pc;
// u2 line_number;
// } line_number_table[line_number_table_length];
// }
}
}
if (method->has_stackmap_table()) {
if (stackmap_len != 0) {
++attr_count;
// Compute the size of the stack map table attribute (VM stores raw):
// StackMapTable_attribute {
// u2 attribute_name_index;
// u4 attribute_length;
// u2 number_of_entries;
// stack_map_frame_entries[number_of_entries];
// }
}
}
int size =
2+2+4 + // max_stack, max_locals, code_length
code_size + // code
2 + // exception_table_length
2 + // attributes_count
attr_size; // attributes
write_attribute_name_index("Code");
}
if (line_num_cnt != 0) {
}
if (stackmap_len != 0) {
}
// FIXME: write LVT attribute
}
// Write Exceptions attribute
// JVMSpec| Exceptions_attribute {
// JVMSpec| u2 attribute_name_index;
// JVMSpec| u4 attribute_length;
// JVMSpec| u2 number_of_exceptions;
// JVMSpec| u2 exception_index_table[number_of_exceptions];
// JVMSpec| }
int size =
2 + // number_of_exceptions
write_attribute_name_index("Exceptions");
}
}
// Write SourceFile attribute
// JVMSpec| SourceFile_attribute {
// JVMSpec| u2 attribute_name_index;
// JVMSpec| u4 attribute_length;
// JVMSpec| u2 sourcefile_index;
// JVMSpec| }
write_attribute_name_index("SourceFile");
}
// Write SourceDebugExtension attribute
// JSR45| SourceDebugExtension_attribute {
// JSR45| u2 attribute_name_index;
// JSR45| u4 attribute_length;
// JSR45| u2 sourcefile_index;
// JSR45| }
write_attribute_name_index("SourceDebugExtension");
}
// Write (generic) Signature attribute
// JVMSpec| Signature_attribute {
// JVMSpec| u2 attribute_name_index;
// JVMSpec| u4 attribute_length;
// JVMSpec| u2 signature_index;
// JVMSpec| }
write_attribute_name_index("Signature");
}
// Compute the number of entries in the InnerClasses attribute
}
// Write an annotation attribute. The VM stores them in raw form, so all we need
// to do is add the attrubute name and fill in the length.
// JSR202| *Annotations_attribute {
// JSR202| u2 attribute_name_index;
// JSR202| u4 attribute_length;
// JSR202| ...
// JSR202| }
}
// Write InnerClasses attribute
// JVMSpec| InnerClasses_attribute {
// JVMSpec| u2 attribute_name_index;
// JVMSpec| u4 attribute_length;
// JVMSpec| u2 number_of_classes;
// JVMSpec| { u2 inner_class_info_index;
// JVMSpec| u2 outer_class_info_index;
// JVMSpec| u2 inner_name_index;
// JVMSpec| u2 inner_class_access_flags;
// JVMSpec| } classes[number_of_classes];
// JVMSpec| }
"caller must check");
write_attribute_name_index("InnerClasses");
}
}
// Write Synthetic attribute
// JVMSpec| Synthetic_attribute {
// JVMSpec| u2 attribute_name_index;
// JVMSpec| u4 attribute_length;
// JVMSpec| }
write_attribute_name_index("Synthetic");
write_u4(0); //length always zero
}
// Compute size of LineNumberTable
// The line number table is compressed so we don't know how big it is until decompressed.
// Decompression is really fast so we just do it twice.
u2 num_entries = 0;
num_entries++;
}
return num_entries;
}
// Write LineNumberTable attribute
// JVMSpec| LineNumberTable_attribute {
// JVMSpec| u2 attribute_name_index;
// JVMSpec| u4 attribute_length;
// JVMSpec| u2 line_number_table_length;
// JVMSpec| { u2 start_pc;
// JVMSpec| u2 line_number;
// JVMSpec| } line_number_table[line_number_table_length];
// JVMSpec| }
u2 num_entries) {
write_attribute_name_index("LineNumberTable");
}
}
// Write stack map table attribute
// JSR-202| StackMapTable_attribute {
// JSR-202| u2 attribute_name_index;
// JSR-202| u4 attribute_length;
// JSR-202| u2 number_of_entries;
// JSR-202| stack_map_frame_entries[number_of_entries];
// JSR-202| }
int stackmap_len) {
write_attribute_name_index("StackMapTable");
}
// Write one method_info structure
// JVMSpec| method_info {
// JVMSpec| u2 access_flags;
// JVMSpec| u2 name_index;
// JVMSpec| u2 descriptor_index;
// JVMSpec| u2 attributes_count;
// JVMSpec| attribute_info attributes[attributes_count];
// JVMSpec| }
// write attributes in the same order javac does, so we can test with byte for
// byte comparison
int attr_count = 0;
if (const_method->code_size() != 0) {
++attr_count; // has Code attribute
}
if (const_method->has_checked_exceptions()) {
++attr_count; // has Exceptions attribute
}
if (default_anno.not_null()) {
++attr_count; // has AnnotationDefault attribute
}
// Deprecated attribute would go here
// ++attr_count;
}
if (generic_signature_index != 0) {
++attr_count;
}
++attr_count; // has RuntimeVisibleAnnotations attribute
}
if (param_anno.not_null()) {
++attr_count; // has RuntimeVisibleParameterAnnotations attribute
}
if (const_method->code_size() > 0) {
}
if (const_method->has_checked_exceptions()) {
}
if (default_anno.not_null()) {
}
// Deprecated attribute would go here
if (access_flags.is_synthetic()) {
// write_synthetic_attribute();
}
if (generic_signature_index != 0) {
}
}
if (param_anno.not_null()) {
}
}
// Write the class attributes portion of ClassFile structure
// JVMSpec| u2 attributes_count;
// JVMSpec| attribute_info attributes[attributes_count];
int attr_count = 0;
if (generic_signature != NULL) {
++attr_count;
}
++attr_count;
}
++attr_count;
}
if (inner_classes_length > 0) {
++attr_count;
}
++attr_count; // has RuntimeVisibleAnnotations attribute
}
if (generic_signature != NULL) {
}
}
}
if (inner_classes_length > 0) {
}
}
}
// Write the method information portion of ClassFile structure
// JVMSpec| u2 methods_count;
// JVMSpec| method_info methods[methods_count];
int index;
int original_index;
// invert the method order mapping
"invalid original method index");
}
// write in original order
}
} else {
// method order not preserved just dump the method infos
}
}
}
ReallocMark();
// JVMSpec| ClassFile {
// JVMSpec| u4 magic;
write_u4(0xCAFEBABE);
// JVMSpec| u2 minor_version;
// JVMSpec| u2 major_version;
// JVMSpec| u2 constant_pool_count;
// JVMSpec| cp_info constant_pool[constant_pool_count-1];
// JVMSpec| u2 access_flags;
// JVMSpec| u2 this_class;
// JVMSpec| u2 super_class;
// JVMSpec| u2 interfaces_count;
// JVMSpec| u2 interfaces[interfaces_count];
}
// JVMSpec| u2 fields_count;
// JVMSpec| field_info fields[fields_count];
// JVMSpec| u2 methods_count;
// JVMSpec| method_info methods[methods_count];
// JVMSpec| u2 attributes_count;
// JVMSpec| attribute_info attributes[attributes_count];
// JVMSpec| } /* end ClassFile 8?
}
// compute the new buffer size: must be at least twice as big as before
// plus whatever new is being used; then convert to nice clean block boundary
// VM goes belly-up if the memory isn't available, so cannot do OOM processing
}
_buffer_ptr += size;
return ret_ptr;
}
}
*writeable_address(1) = x;
}
}
}
}
unsigned char* bytecodes) {
// and the breakpoint bytecode are converted to their original bytecodes.
unsigned char* p = bytecodes;
// length of bytecode (mnemonic + operands)
// copy the bytecodes
if (len > 1) {
}
// with an index into the constant pool cache. The original constant
// pool index must be returned to caller. Rewrite the index.
switch (code) {
case Bytecodes::_invokeinterface :
"sanity check");
if (is_invokedynamic)
// cache cannot be pre-fetched since some classes won't have it yet
int i = entry->constant_pool_index();
break;
}
}
p += len;
}
}