src/share/vm/prims/jvmtiClassFileReconstituter.hpp

Wed, 23 Apr 2014 11:18:53 +0200

author
sjohanss
date
Wed, 23 Apr 2014 11:18:53 +0200
changeset 6641
1d01a7f3a336
parent 6198
55fb97c4c58d
child 6876
710a3c8b516e
child 7571
d9c03a9ead96
permissions
-rw-r--r--

8033426: Scale initial NewSize using NewRatio if not set on command line
Summary: Now using NewRatio to size initial NewSize if not specified on commandline.
Reviewed-by: jmasa, jwilhelm

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

mercurial