src/share/vm/prims/jvmtiClassFileReconstituter.hpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 6198
55fb97c4c58d
parent 0
f90c822e73f8
child 7994
04ff2f6cd0eb
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_PRIMS_JVMTICLASSFILERECONSTITUTER_HPP
aoqi@0 26 #define SHARE_VM_PRIMS_JVMTICLASSFILERECONSTITUTER_HPP
aoqi@0 27
aoqi@0 28 #include "jvmtifiles/jvmtiEnv.hpp"
aoqi@0 29
aoqi@0 30
aoqi@0 31 class JvmtiConstantPoolReconstituter : public StackObj {
aoqi@0 32 private:
aoqi@0 33 int _cpool_size;
aoqi@0 34 SymbolHashMap* _symmap;
aoqi@0 35 SymbolHashMap* _classmap;
aoqi@0 36 constantPoolHandle _cpool;
aoqi@0 37 instanceKlassHandle _ikh;
aoqi@0 38 jvmtiError _err;
aoqi@0 39
aoqi@0 40 protected:
aoqi@0 41 instanceKlassHandle ikh() { return _ikh; };
aoqi@0 42 constantPoolHandle cpool() { return _cpool; };
aoqi@0 43
aoqi@0 44 u2 symbol_to_cpool_index(Symbol* sym) {
aoqi@0 45 return _symmap->symbol_to_value(sym);
aoqi@0 46 }
aoqi@0 47
aoqi@0 48 u2 class_symbol_to_cpool_index(Symbol* sym) {
aoqi@0 49 return _classmap->symbol_to_value(sym);
aoqi@0 50 }
aoqi@0 51
aoqi@0 52 public:
aoqi@0 53 // Calls to this constructor must be proceeded by a ResourceMark
aoqi@0 54 // and a HandleMark
aoqi@0 55 JvmtiConstantPoolReconstituter(instanceKlassHandle ikh){
aoqi@0 56 set_error(JVMTI_ERROR_NONE);
aoqi@0 57 _ikh = ikh;
aoqi@0 58 _cpool = constantPoolHandle(Thread::current(), ikh->constants());
aoqi@0 59 _symmap = new SymbolHashMap();
aoqi@0 60 _classmap = new SymbolHashMap();
aoqi@0 61 _cpool_size = _cpool->hash_entries_to(_symmap, _classmap);
aoqi@0 62 if (_cpool_size == 0) {
aoqi@0 63 set_error(JVMTI_ERROR_OUT_OF_MEMORY);
aoqi@0 64 } else if (_cpool_size < 0) {
aoqi@0 65 set_error(JVMTI_ERROR_INTERNAL);
aoqi@0 66 }
aoqi@0 67 }
aoqi@0 68
aoqi@0 69 ~JvmtiConstantPoolReconstituter() {
aoqi@0 70 if (_symmap != NULL) {
aoqi@0 71 os::free(_symmap, mtClass);
aoqi@0 72 _symmap = NULL;
aoqi@0 73 }
aoqi@0 74 if (_classmap != NULL) {
aoqi@0 75 os::free(_classmap, mtClass);
aoqi@0 76 _classmap = NULL;
aoqi@0 77 }
aoqi@0 78 }
aoqi@0 79
aoqi@0 80
aoqi@0 81 void set_error(jvmtiError err) { _err = err; }
aoqi@0 82 jvmtiError get_error() { return _err; }
aoqi@0 83
aoqi@0 84 int cpool_size() { return _cpool_size; }
aoqi@0 85
aoqi@0 86 void copy_cpool_bytes(unsigned char *cpool_bytes) {
aoqi@0 87 if (cpool_bytes == NULL) {
aoqi@0 88 assert(cpool_bytes != NULL, "cpool_bytes pointer must not be NULL");
aoqi@0 89 return;
aoqi@0 90 }
aoqi@0 91 cpool()->copy_cpool_bytes(cpool_size(), _symmap, cpool_bytes);
aoqi@0 92 }
aoqi@0 93 };
aoqi@0 94
aoqi@0 95
aoqi@0 96 class JvmtiClassFileReconstituter : public JvmtiConstantPoolReconstituter {
aoqi@0 97 private:
aoqi@0 98 size_t _buffer_size;
aoqi@0 99 u1* _buffer;
aoqi@0 100 u1* _buffer_ptr;
aoqi@0 101 Thread* _thread;
aoqi@0 102
aoqi@0 103 enum {
aoqi@0 104 // initial size should be power of two
aoqi@0 105 initial_buffer_size = 1024
aoqi@0 106 };
aoqi@0 107
aoqi@0 108 inline Thread* thread() { return _thread; }
aoqi@0 109
aoqi@0 110 void write_class_file_format();
aoqi@0 111 void write_field_infos();
aoqi@0 112 void write_method_infos();
aoqi@0 113 void write_method_info(methodHandle method);
aoqi@0 114 void write_code_attribute(methodHandle method);
aoqi@0 115 void write_exceptions_attribute(ConstMethod* const_method);
aoqi@0 116 void write_synthetic_attribute();
aoqi@0 117 void write_class_attributes();
aoqi@0 118 void write_source_file_attribute();
aoqi@0 119 void write_source_debug_extension_attribute();
aoqi@0 120 u2 line_number_table_entries(methodHandle method);
aoqi@0 121 void write_line_number_table_attribute(methodHandle method, u2 num_entries);
aoqi@0 122 void write_local_variable_table_attribute(methodHandle method, u2 num_entries);
aoqi@0 123 void write_local_variable_type_table_attribute(methodHandle method, u2 num_entries);
aoqi@0 124 void write_stackmap_table_attribute(methodHandle method, int stackmap_table_len);
aoqi@0 125 u2 inner_classes_attribute_length();
aoqi@0 126 void write_inner_classes_attribute(int length);
aoqi@0 127 void write_signature_attribute(u2 generic_signaure_index);
aoqi@0 128 void write_attribute_name_index(const char* name);
aoqi@0 129 void write_annotations_attribute(const char* attr_name, AnnotationArray* annos);
aoqi@0 130 void write_bootstrapmethod_attribute();
aoqi@0 131
aoqi@0 132 address writeable_address(size_t size);
aoqi@0 133 void write_u1(u1 x);
aoqi@0 134 void write_u2(u2 x);
aoqi@0 135 void write_u4(u4 x);
aoqi@0 136 void write_u8(u8 x);
aoqi@0 137
aoqi@0 138 public:
aoqi@0 139 // Calls to this constructor must be proceeded by a ResourceMark
aoqi@0 140 // and a HandleMark
aoqi@0 141 JvmtiClassFileReconstituter(instanceKlassHandle ikh) :
aoqi@0 142 JvmtiConstantPoolReconstituter(ikh) {
aoqi@0 143 _buffer_size = initial_buffer_size;
aoqi@0 144 _buffer = _buffer_ptr = NEW_RESOURCE_ARRAY(u1, _buffer_size);
aoqi@0 145 _thread = Thread::current();
aoqi@0 146 write_class_file_format();
aoqi@0 147 };
aoqi@0 148
aoqi@0 149 size_t class_file_size() { return _buffer_ptr - _buffer; }
aoqi@0 150
aoqi@0 151 u1* class_file_bytes() { return _buffer; }
aoqi@0 152
aoqi@0 153 static void copy_bytecodes(methodHandle method, unsigned char* bytecodes);
aoqi@0 154 };
aoqi@0 155
aoqi@0 156 #endif // SHARE_VM_PRIMS_JVMTICLASSFILERECONSTITUTER_HPP

mercurial