author | coleenp |
Fri, 16 Mar 2018 09:12:13 -0400 | |
changeset 49449 | ef5d5d343e2a |
parent 47216 | 71c04702a3d5 |
child 49480 | d7df2dd501ce |
permissions | -rw-r--r-- |
1 | 1 |
/* |
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
38031
diff
changeset
|
2 |
* Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
3261
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
3261
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
3261
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "classfile/symbolTable.hpp" |
|
27 |
#include "interpreter/bytecodeStream.hpp" |
|
10546 | 28 |
#include "oops/fieldStreams.hpp" |
7397 | 29 |
#include "prims/jvmtiClassFileReconstituter.hpp" |
30 |
#include "runtime/signature.hpp" |
|
25715
d5a8dbdc5150
8049325: Introduce and clean up umbrella headers for the files in the cpu subdirectories.
goetz
parents:
24322
diff
changeset
|
31 |
#include "utilities/bytes.hpp" |
d5a8dbdc5150
8049325: Introduce and clean up umbrella headers for the files in the cpu subdirectories.
goetz
parents:
24322
diff
changeset
|
32 |
|
13863
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
33 |
// FIXME: add Deprecated attribute |
1 | 34 |
// FIXME: fix Synthetic attribute |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
35 |
// FIXME: per Serguei, add error return handling for ConstantPool::copy_cpool_bytes() |
1 | 36 |
|
49449
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47216
diff
changeset
|
37 |
JvmtiConstantPoolReconstituter::JvmtiConstantPoolReconstituter(InstanceKlass* ik) { |
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47216
diff
changeset
|
38 |
set_error(JVMTI_ERROR_NONE); |
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47216
diff
changeset
|
39 |
_ik = ik; |
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47216
diff
changeset
|
40 |
_cpool = constantPoolHandle(Thread::current(), ik->constants()); |
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47216
diff
changeset
|
41 |
_symmap = new SymbolHashMap(); |
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47216
diff
changeset
|
42 |
_classmap = new SymbolHashMap(); |
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47216
diff
changeset
|
43 |
_cpool_size = _cpool->hash_entries_to(_symmap, _classmap); |
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47216
diff
changeset
|
44 |
if (_cpool_size == 0) { |
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47216
diff
changeset
|
45 |
set_error(JVMTI_ERROR_OUT_OF_MEMORY); |
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47216
diff
changeset
|
46 |
} else if (_cpool_size < 0) { |
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47216
diff
changeset
|
47 |
set_error(JVMTI_ERROR_INTERNAL); |
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47216
diff
changeset
|
48 |
} |
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47216
diff
changeset
|
49 |
} |
1 | 50 |
|
51 |
// Write the field information portion of ClassFile structure |
|
52 |
// JVMSpec| u2 fields_count; |
|
53 |
// JVMSpec| field_info fields[fields_count]; |
|
54 |
void JvmtiClassFileReconstituter::write_field_infos() { |
|
55 |
HandleMark hm(thread()); |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
38031
diff
changeset
|
56 |
Array<AnnotationArray*>* fields_anno = ik()->fields_annotations(); |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
38031
diff
changeset
|
57 |
Array<AnnotationArray*>* fields_type_anno = ik()->fields_type_annotations(); |
1 | 58 |
|
10546 | 59 |
// Compute the real number of Java fields |
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
38031
diff
changeset
|
60 |
int java_fields = ik()->java_fields_count(); |
10546 | 61 |
|
10552 | 62 |
write_u2(java_fields); |
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
38031
diff
changeset
|
63 |
for (JavaFieldStream fs(ik()); !fs.done(); fs.next()) { |
10546 | 64 |
AccessFlags access_flags = fs.access_flags(); |
65 |
int name_index = fs.name_index(); |
|
66 |
int signature_index = fs.signature_index(); |
|
67 |
int initial_value_index = fs.initval_index(); |
|
1 | 68 |
guarantee(name_index != 0 && signature_index != 0, "bad constant pool index for field"); |
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
38031
diff
changeset
|
69 |
// int offset = ik()->field_offset( index ); |
10546 | 70 |
int generic_signature_index = fs.generic_signature_index(); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
71 |
AnnotationArray* anno = fields_anno == NULL ? NULL : fields_anno->at(fs.index()); |
27401
a4697c9502cb
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
25715
diff
changeset
|
72 |
AnnotationArray* type_anno = fields_type_anno == NULL ? NULL : fields_type_anno->at(fs.index()); |
1 | 73 |
|
74 |
// JVMSpec| field_info { |
|
75 |
// JVMSpec| u2 access_flags; |
|
76 |
// JVMSpec| u2 name_index; |
|
77 |
// JVMSpec| u2 descriptor_index; |
|
78 |
// JVMSpec| u2 attributes_count; |
|
79 |
// JVMSpec| attribute_info attributes[attributes_count]; |
|
80 |
// JVMSpec| } |
|
81 |
||
10546 | 82 |
write_u2(access_flags.as_int() & JVM_RECOGNIZED_FIELD_MODIFIERS); |
1 | 83 |
write_u2(name_index); |
84 |
write_u2(signature_index); |
|
85 |
int attr_count = 0; |
|
86 |
if (initial_value_index != 0) { |
|
87 |
++attr_count; |
|
88 |
} |
|
89 |
if (access_flags.is_synthetic()) { |
|
90 |
// ++attr_count; |
|
91 |
} |
|
92 |
if (generic_signature_index != 0) { |
|
93 |
++attr_count; |
|
94 |
} |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
95 |
if (anno != NULL) { |
1 | 96 |
++attr_count; // has RuntimeVisibleAnnotations attribute |
97 |
} |
|
27401
a4697c9502cb
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
25715
diff
changeset
|
98 |
if (type_anno != NULL) { |
a4697c9502cb
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
25715
diff
changeset
|
99 |
++attr_count; // has RuntimeVisibleTypeAnnotations attribute |
a4697c9502cb
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
25715
diff
changeset
|
100 |
} |
1 | 101 |
|
102 |
write_u2(attr_count); |
|
103 |
||
104 |
if (initial_value_index != 0) { |
|
105 |
write_attribute_name_index("ConstantValue"); |
|
106 |
write_u4(2); //length always 2 |
|
107 |
write_u2(initial_value_index); |
|
108 |
} |
|
109 |
if (access_flags.is_synthetic()) { |
|
110 |
// write_synthetic_attribute(); |
|
111 |
} |
|
112 |
if (generic_signature_index != 0) { |
|
113 |
write_signature_attribute(generic_signature_index); |
|
114 |
} |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
115 |
if (anno != NULL) { |
1 | 116 |
write_annotations_attribute("RuntimeVisibleAnnotations", anno); |
117 |
} |
|
27401
a4697c9502cb
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
25715
diff
changeset
|
118 |
if (type_anno != NULL) { |
a4697c9502cb
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
25715
diff
changeset
|
119 |
write_annotations_attribute("RuntimeVisibleTypeAnnotations", type_anno); |
a4697c9502cb
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
25715
diff
changeset
|
120 |
} |
1 | 121 |
} |
122 |
} |
|
123 |
||
124 |
// Write Code attribute |
|
125 |
// JVMSpec| Code_attribute { |
|
126 |
// JVMSpec| u2 attribute_name_index; |
|
127 |
// JVMSpec| u4 attribute_length; |
|
128 |
// JVMSpec| u2 max_stack; |
|
129 |
// JVMSpec| u2 max_locals; |
|
130 |
// JVMSpec| u4 code_length; |
|
131 |
// JVMSpec| u1 code[code_length]; |
|
132 |
// JVMSpec| u2 exception_table_length; |
|
133 |
// JVMSpec| { u2 start_pc; |
|
134 |
// JVMSpec| u2 end_pc; |
|
135 |
// JVMSpec| u2 handler_pc; |
|
136 |
// JVMSpec| u2 catch_type; |
|
137 |
// JVMSpec| } exception_table[exception_table_length]; |
|
138 |
// JVMSpec| u2 attributes_count; |
|
139 |
// JVMSpec| attribute_info attributes[attributes_count]; |
|
140 |
// JVMSpec| } |
|
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
27401
diff
changeset
|
141 |
void JvmtiClassFileReconstituter::write_code_attribute(const methodHandle& method) { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
142 |
ConstMethod* const_method = method->constMethod(); |
1 | 143 |
u2 line_num_cnt = 0; |
144 |
int stackmap_len = 0; |
|
11257
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
145 |
int local_variable_table_length = 0; |
13863
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
146 |
int local_variable_type_table_length = 0; |
1 | 147 |
|
11257
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
148 |
// compute number and length of attributes |
1 | 149 |
int attr_count = 0; |
150 |
int attr_size = 0; |
|
151 |
if (const_method->has_linenumber_table()) { |
|
152 |
line_num_cnt = line_number_table_entries(method); |
|
153 |
if (line_num_cnt != 0) { |
|
154 |
++attr_count; |
|
155 |
// Compute the complete size of the line number table attribute: |
|
156 |
// LineNumberTable_attribute { |
|
157 |
// u2 attribute_name_index; |
|
158 |
// u4 attribute_length; |
|
159 |
// u2 line_number_table_length; |
|
160 |
// { u2 start_pc; |
|
161 |
// u2 line_number; |
|
162 |
// } line_number_table[line_number_table_length]; |
|
163 |
// } |
|
164 |
attr_size += 2 + 4 + 2 + line_num_cnt * (2 + 2); |
|
165 |
} |
|
166 |
} |
|
167 |
if (method->has_stackmap_table()) { |
|
168 |
stackmap_len = method->stackmap_data()->length(); |
|
169 |
if (stackmap_len != 0) { |
|
170 |
++attr_count; |
|
171 |
// Compute the size of the stack map table attribute (VM stores raw): |
|
172 |
// StackMapTable_attribute { |
|
173 |
// u2 attribute_name_index; |
|
174 |
// u4 attribute_length; |
|
175 |
// u2 number_of_entries; |
|
176 |
// stack_map_frame_entries[number_of_entries]; |
|
177 |
// } |
|
178 |
attr_size += 2 + 4 + stackmap_len; |
|
179 |
} |
|
180 |
} |
|
11257
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
181 |
if (method->has_localvariable_table()) { |
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
182 |
local_variable_table_length = method->localvariable_table_length(); |
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
183 |
if (local_variable_table_length != 0) { |
13863
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
184 |
++attr_count; |
11257
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
185 |
// Compute the size of the local variable table attribute (VM stores raw): |
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
186 |
// LocalVariableTable_attribute { |
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
187 |
// u2 attribute_name_index; |
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
188 |
// u4 attribute_length; |
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
189 |
// u2 local_variable_table_length; |
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
190 |
// { |
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
191 |
// u2 start_pc; |
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
192 |
// u2 length; |
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
193 |
// u2 name_index; |
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
194 |
// u2 descriptor_index; |
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
195 |
// u2 index; |
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
196 |
// } |
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
197 |
attr_size += 2 + 4 + 2 + local_variable_table_length * (2 + 2 + 2 + 2 + 2); |
13863
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
198 |
|
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
199 |
// Local variables with generic signatures must have LVTT entries |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
200 |
LocalVariableTableElement *elem = method->localvariable_table_start(); |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
201 |
for (int idx = 0; idx < local_variable_table_length; idx++) { |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
202 |
if (elem[idx].signature_cp_index != 0) { |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
203 |
local_variable_type_table_length++; |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
204 |
} |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
205 |
} |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
206 |
|
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
207 |
if (local_variable_type_table_length != 0) { |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
208 |
++attr_count; |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
209 |
// Compute the size of the local variable type table attribute (VM stores raw): |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
210 |
// LocalVariableTypeTable_attribute { |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
211 |
// u2 attribute_name_index; |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
212 |
// u4 attribute_length; |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
213 |
// u2 local_variable_type_table_length; |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
214 |
// { |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
215 |
// u2 start_pc; |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
216 |
// u2 length; |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
217 |
// u2 name_index; |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
218 |
// u2 signature_index; |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
219 |
// u2 index; |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
220 |
// } |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
221 |
attr_size += 2 + 4 + 2 + local_variable_type_table_length * (2 + 2 + 2 + 2 + 2); |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
222 |
} |
11257
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
223 |
} |
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
224 |
} |
1 | 225 |
|
13282
9872915dd78d
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
12231
diff
changeset
|
226 |
ExceptionTable exception_table(method()); |
9872915dd78d
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
12231
diff
changeset
|
227 |
int exception_table_length = exception_table.length(); |
1 | 228 |
int code_size = const_method->code_size(); |
229 |
int size = |
|
230 |
2+2+4 + // max_stack, max_locals, code_length |
|
231 |
code_size + // code |
|
232 |
2 + // exception_table_length |
|
13282
9872915dd78d
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
12231
diff
changeset
|
233 |
(2+2+2+2) * exception_table_length + // exception_table |
1 | 234 |
2 + // attributes_count |
235 |
attr_size; // attributes |
|
236 |
||
237 |
write_attribute_name_index("Code"); |
|
238 |
write_u4(size); |
|
14480
06c1743f1285
7194607: VerifyLocalVariableTableOnRetransformTest.sh fails after JSR-292 merge
sspitsyn
parents:
13863
diff
changeset
|
239 |
write_u2(method->verifier_max_stack()); |
1 | 240 |
write_u2(method->max_locals()); |
241 |
write_u4(code_size); |
|
242 |
copy_bytecodes(method, (unsigned char*)writeable_address(code_size)); |
|
13282
9872915dd78d
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
12231
diff
changeset
|
243 |
write_u2(exception_table_length); |
9872915dd78d
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
12231
diff
changeset
|
244 |
for (int index = 0; index < exception_table_length; index++) { |
9872915dd78d
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
12231
diff
changeset
|
245 |
write_u2(exception_table.start_pc(index)); |
9872915dd78d
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
12231
diff
changeset
|
246 |
write_u2(exception_table.end_pc(index)); |
9872915dd78d
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
12231
diff
changeset
|
247 |
write_u2(exception_table.handler_pc(index)); |
9872915dd78d
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
12231
diff
changeset
|
248 |
write_u2(exception_table.catch_type_index(index)); |
1 | 249 |
} |
250 |
write_u2(attr_count); |
|
251 |
if (line_num_cnt != 0) { |
|
252 |
write_line_number_table_attribute(method, line_num_cnt); |
|
253 |
} |
|
254 |
if (stackmap_len != 0) { |
|
255 |
write_stackmap_table_attribute(method, stackmap_len); |
|
256 |
} |
|
11257
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
257 |
if (local_variable_table_length != 0) { |
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
258 |
write_local_variable_table_attribute(method, local_variable_table_length); |
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
259 |
} |
13863
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
260 |
if (local_variable_type_table_length != 0) { |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
261 |
write_local_variable_type_table_attribute(method, local_variable_type_table_length); |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
262 |
} |
1 | 263 |
} |
264 |
||
265 |
// Write Exceptions attribute |
|
266 |
// JVMSpec| Exceptions_attribute { |
|
267 |
// JVMSpec| u2 attribute_name_index; |
|
268 |
// JVMSpec| u4 attribute_length; |
|
269 |
// JVMSpec| u2 number_of_exceptions; |
|
270 |
// JVMSpec| u2 exception_index_table[number_of_exceptions]; |
|
271 |
// JVMSpec| } |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
272 |
void JvmtiClassFileReconstituter::write_exceptions_attribute(ConstMethod* const_method) { |
1 | 273 |
CheckedExceptionElement* checked_exceptions = const_method->checked_exceptions_start(); |
274 |
int checked_exceptions_length = const_method->checked_exceptions_length(); |
|
275 |
int size = |
|
276 |
2 + // number_of_exceptions |
|
277 |
2 * checked_exceptions_length; // exception_index_table |
|
278 |
||
279 |
write_attribute_name_index("Exceptions"); |
|
280 |
write_u4(size); |
|
281 |
write_u2(checked_exceptions_length); |
|
282 |
for (int index = 0; index < checked_exceptions_length; index++) { |
|
283 |
write_u2(checked_exceptions[index].class_cp_index); |
|
284 |
} |
|
285 |
} |
|
286 |
||
287 |
// Write SourceFile attribute |
|
288 |
// JVMSpec| SourceFile_attribute { |
|
289 |
// JVMSpec| u2 attribute_name_index; |
|
290 |
// JVMSpec| u4 attribute_length; |
|
291 |
// JVMSpec| u2 sourcefile_index; |
|
292 |
// JVMSpec| } |
|
293 |
void JvmtiClassFileReconstituter::write_source_file_attribute() { |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
38031
diff
changeset
|
294 |
assert(ik()->source_file_name() != NULL, "caller must check"); |
1 | 295 |
|
296 |
write_attribute_name_index("SourceFile"); |
|
297 |
write_u4(2); // always length 2 |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
38031
diff
changeset
|
298 |
write_u2(symbol_to_cpool_index(ik()->source_file_name())); |
1 | 299 |
} |
300 |
||
301 |
// Write SourceDebugExtension attribute |
|
302 |
// JSR45| SourceDebugExtension_attribute { |
|
303 |
// JSR45| u2 attribute_name_index; |
|
304 |
// JSR45| u4 attribute_length; |
|
13201
69f157caabcc
6294277: java -Xdebug crashes on SourceDebugExtension attribute larger than 64K
fparain
parents:
12231
diff
changeset
|
305 |
// JSR45| u1 debug_extension[attribute_length]; |
1 | 306 |
// JSR45| } |
307 |
void JvmtiClassFileReconstituter::write_source_debug_extension_attribute() { |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
38031
diff
changeset
|
308 |
assert(ik()->source_debug_extension() != NULL, "caller must check"); |
1 | 309 |
|
310 |
write_attribute_name_index("SourceDebugExtension"); |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
38031
diff
changeset
|
311 |
int len = (int)strlen(ik()->source_debug_extension()); |
13201
69f157caabcc
6294277: java -Xdebug crashes on SourceDebugExtension attribute larger than 64K
fparain
parents:
12231
diff
changeset
|
312 |
write_u4(len); |
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
38031
diff
changeset
|
313 |
u1* ext = (u1*)ik()->source_debug_extension(); |
13201
69f157caabcc
6294277: java -Xdebug crashes on SourceDebugExtension attribute larger than 64K
fparain
parents:
12231
diff
changeset
|
314 |
for (int i=0; i<len; i++) { |
69f157caabcc
6294277: java -Xdebug crashes on SourceDebugExtension attribute larger than 64K
fparain
parents:
12231
diff
changeset
|
315 |
write_u1(ext[i]); |
69f157caabcc
6294277: java -Xdebug crashes on SourceDebugExtension attribute larger than 64K
fparain
parents:
12231
diff
changeset
|
316 |
} |
1 | 317 |
} |
318 |
||
319 |
// Write (generic) Signature attribute |
|
320 |
// JVMSpec| Signature_attribute { |
|
321 |
// JVMSpec| u2 attribute_name_index; |
|
322 |
// JVMSpec| u4 attribute_length; |
|
323 |
// JVMSpec| u2 signature_index; |
|
324 |
// JVMSpec| } |
|
325 |
void JvmtiClassFileReconstituter::write_signature_attribute(u2 generic_signature_index) { |
|
326 |
write_attribute_name_index("Signature"); |
|
327 |
write_u4(2); // always length 2 |
|
328 |
write_u2(generic_signature_index); |
|
329 |
} |
|
330 |
||
331 |
// Compute the number of entries in the InnerClasses attribute |
|
332 |
u2 JvmtiClassFileReconstituter::inner_classes_attribute_length() { |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
38031
diff
changeset
|
333 |
InnerClassesIterator iter(ik()); |
12231
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
12102
diff
changeset
|
334 |
return iter.length(); |
1 | 335 |
} |
336 |
||
337 |
// Write an annotation attribute. The VM stores them in raw form, so all we need |
|
338 |
// to do is add the attrubute name and fill in the length. |
|
339 |
// JSR202| *Annotations_attribute { |
|
340 |
// JSR202| u2 attribute_name_index; |
|
341 |
// JSR202| u4 attribute_length; |
|
342 |
// JSR202| ... |
|
343 |
// JSR202| } |
|
344 |
void JvmtiClassFileReconstituter::write_annotations_attribute(const char* attr_name, |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
345 |
AnnotationArray* annos) { |
1 | 346 |
u4 length = annos->length(); |
347 |
write_attribute_name_index(attr_name); |
|
348 |
write_u4(length); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
349 |
memcpy(writeable_address(length), annos->adr_at(0), length); |
1 | 350 |
} |
351 |
||
17307
74bb7db916df
8009615: JvmtiClassFileReconstituter does not create BootstrapMethod attributes
sla
parents:
17294
diff
changeset
|
352 |
// BootstrapMethods_attribute { |
74bb7db916df
8009615: JvmtiClassFileReconstituter does not create BootstrapMethod attributes
sla
parents:
17294
diff
changeset
|
353 |
// u2 attribute_name_index; |
74bb7db916df
8009615: JvmtiClassFileReconstituter does not create BootstrapMethod attributes
sla
parents:
17294
diff
changeset
|
354 |
// u4 attribute_length; |
74bb7db916df
8009615: JvmtiClassFileReconstituter does not create BootstrapMethod attributes
sla
parents:
17294
diff
changeset
|
355 |
// u2 num_bootstrap_methods; |
74bb7db916df
8009615: JvmtiClassFileReconstituter does not create BootstrapMethod attributes
sla
parents:
17294
diff
changeset
|
356 |
// { u2 bootstrap_method_ref; |
74bb7db916df
8009615: JvmtiClassFileReconstituter does not create BootstrapMethod attributes
sla
parents:
17294
diff
changeset
|
357 |
// u2 num_bootstrap_arguments; |
74bb7db916df
8009615: JvmtiClassFileReconstituter does not create BootstrapMethod attributes
sla
parents:
17294
diff
changeset
|
358 |
// u2 bootstrap_arguments[num_bootstrap_arguments]; |
74bb7db916df
8009615: JvmtiClassFileReconstituter does not create BootstrapMethod attributes
sla
parents:
17294
diff
changeset
|
359 |
// } bootstrap_methods[num_bootstrap_methods]; |
74bb7db916df
8009615: JvmtiClassFileReconstituter does not create BootstrapMethod attributes
sla
parents:
17294
diff
changeset
|
360 |
// } |
17309
83ac929d332a
8014044: Spelling error in JDK-8009615: boostrapmethod
sla
parents:
17307
diff
changeset
|
361 |
void JvmtiClassFileReconstituter::write_bootstrapmethod_attribute() { |
17307
74bb7db916df
8009615: JvmtiClassFileReconstituter does not create BootstrapMethod attributes
sla
parents:
17294
diff
changeset
|
362 |
Array<u2>* operands = cpool()->operands(); |
74bb7db916df
8009615: JvmtiClassFileReconstituter does not create BootstrapMethod attributes
sla
parents:
17294
diff
changeset
|
363 |
write_attribute_name_index("BootstrapMethods"); |
74bb7db916df
8009615: JvmtiClassFileReconstituter does not create BootstrapMethod attributes
sla
parents:
17294
diff
changeset
|
364 |
int num_bootstrap_methods = ConstantPool::operand_array_length(operands); |
74bb7db916df
8009615: JvmtiClassFileReconstituter does not create BootstrapMethod attributes
sla
parents:
17294
diff
changeset
|
365 |
|
74bb7db916df
8009615: JvmtiClassFileReconstituter does not create BootstrapMethod attributes
sla
parents:
17294
diff
changeset
|
366 |
// calculate length of attribute |
17309
83ac929d332a
8014044: Spelling error in JDK-8009615: boostrapmethod
sla
parents:
17307
diff
changeset
|
367 |
int length = sizeof(u2); // num_bootstrap_methods |
17307
74bb7db916df
8009615: JvmtiClassFileReconstituter does not create BootstrapMethod attributes
sla
parents:
17294
diff
changeset
|
368 |
for (int n = 0; n < num_bootstrap_methods; n++) { |
74bb7db916df
8009615: JvmtiClassFileReconstituter does not create BootstrapMethod attributes
sla
parents:
17294
diff
changeset
|
369 |
u2 num_bootstrap_arguments = cpool()->operand_argument_count_at(n); |
74bb7db916df
8009615: JvmtiClassFileReconstituter does not create BootstrapMethod attributes
sla
parents:
17294
diff
changeset
|
370 |
length += sizeof(u2); // bootstrap_method_ref |
74bb7db916df
8009615: JvmtiClassFileReconstituter does not create BootstrapMethod attributes
sla
parents:
17294
diff
changeset
|
371 |
length += sizeof(u2); // num_bootstrap_arguments |
74bb7db916df
8009615: JvmtiClassFileReconstituter does not create BootstrapMethod attributes
sla
parents:
17294
diff
changeset
|
372 |
length += sizeof(u2) * num_bootstrap_arguments; // bootstrap_arguments[num_bootstrap_arguments] |
74bb7db916df
8009615: JvmtiClassFileReconstituter does not create BootstrapMethod attributes
sla
parents:
17294
diff
changeset
|
373 |
} |
74bb7db916df
8009615: JvmtiClassFileReconstituter does not create BootstrapMethod attributes
sla
parents:
17294
diff
changeset
|
374 |
write_u4(length); |
74bb7db916df
8009615: JvmtiClassFileReconstituter does not create BootstrapMethod attributes
sla
parents:
17294
diff
changeset
|
375 |
|
74bb7db916df
8009615: JvmtiClassFileReconstituter does not create BootstrapMethod attributes
sla
parents:
17294
diff
changeset
|
376 |
// write attribute |
74bb7db916df
8009615: JvmtiClassFileReconstituter does not create BootstrapMethod attributes
sla
parents:
17294
diff
changeset
|
377 |
write_u2(num_bootstrap_methods); |
74bb7db916df
8009615: JvmtiClassFileReconstituter does not create BootstrapMethod attributes
sla
parents:
17294
diff
changeset
|
378 |
for (int n = 0; n < num_bootstrap_methods; n++) { |
74bb7db916df
8009615: JvmtiClassFileReconstituter does not create BootstrapMethod attributes
sla
parents:
17294
diff
changeset
|
379 |
u2 bootstrap_method_ref = cpool()->operand_bootstrap_method_ref_index_at(n); |
74bb7db916df
8009615: JvmtiClassFileReconstituter does not create BootstrapMethod attributes
sla
parents:
17294
diff
changeset
|
380 |
u2 num_bootstrap_arguments = cpool()->operand_argument_count_at(n); |
74bb7db916df
8009615: JvmtiClassFileReconstituter does not create BootstrapMethod attributes
sla
parents:
17294
diff
changeset
|
381 |
write_u2(bootstrap_method_ref); |
74bb7db916df
8009615: JvmtiClassFileReconstituter does not create BootstrapMethod attributes
sla
parents:
17294
diff
changeset
|
382 |
write_u2(num_bootstrap_arguments); |
74bb7db916df
8009615: JvmtiClassFileReconstituter does not create BootstrapMethod attributes
sla
parents:
17294
diff
changeset
|
383 |
for (int arg = 0; arg < num_bootstrap_arguments; arg++) { |
74bb7db916df
8009615: JvmtiClassFileReconstituter does not create BootstrapMethod attributes
sla
parents:
17294
diff
changeset
|
384 |
u2 bootstrap_argument = cpool()->operand_argument_index_at(n, arg); |
74bb7db916df
8009615: JvmtiClassFileReconstituter does not create BootstrapMethod attributes
sla
parents:
17294
diff
changeset
|
385 |
write_u2(bootstrap_argument); |
74bb7db916df
8009615: JvmtiClassFileReconstituter does not create BootstrapMethod attributes
sla
parents:
17294
diff
changeset
|
386 |
} |
74bb7db916df
8009615: JvmtiClassFileReconstituter does not create BootstrapMethod attributes
sla
parents:
17294
diff
changeset
|
387 |
} |
74bb7db916df
8009615: JvmtiClassFileReconstituter does not create BootstrapMethod attributes
sla
parents:
17294
diff
changeset
|
388 |
} |
74bb7db916df
8009615: JvmtiClassFileReconstituter does not create BootstrapMethod attributes
sla
parents:
17294
diff
changeset
|
389 |
|
1 | 390 |
|
391 |
// Write InnerClasses attribute |
|
392 |
// JVMSpec| InnerClasses_attribute { |
|
393 |
// JVMSpec| u2 attribute_name_index; |
|
394 |
// JVMSpec| u4 attribute_length; |
|
395 |
// JVMSpec| u2 number_of_classes; |
|
396 |
// JVMSpec| { u2 inner_class_info_index; |
|
397 |
// JVMSpec| u2 outer_class_info_index; |
|
398 |
// JVMSpec| u2 inner_name_index; |
|
399 |
// JVMSpec| u2 inner_class_access_flags; |
|
400 |
// JVMSpec| } classes[number_of_classes]; |
|
401 |
// JVMSpec| } |
|
402 |
void JvmtiClassFileReconstituter::write_inner_classes_attribute(int length) { |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
38031
diff
changeset
|
403 |
InnerClassesIterator iter(ik()); |
12231
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
12102
diff
changeset
|
404 |
guarantee(iter.length() != 0 && iter.length() == length, |
1 | 405 |
"caller must check"); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
406 |
u2 entry_count = length / InstanceKlass::inner_class_next_offset; |
1 | 407 |
u4 size = 2 + entry_count * (2+2+2+2); |
408 |
||
409 |
write_attribute_name_index("InnerClasses"); |
|
410 |
write_u4(size); |
|
411 |
write_u2(entry_count); |
|
12231
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
12102
diff
changeset
|
412 |
for (; !iter.done(); iter.next()) { |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
12102
diff
changeset
|
413 |
write_u2(iter.inner_class_info_index()); |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
12102
diff
changeset
|
414 |
write_u2(iter.outer_class_info_index()); |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
12102
diff
changeset
|
415 |
write_u2(iter.inner_name_index()); |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
12102
diff
changeset
|
416 |
write_u2(iter.inner_access_flags()); |
1 | 417 |
} |
418 |
} |
|
419 |
||
420 |
// Write Synthetic attribute |
|
421 |
// JVMSpec| Synthetic_attribute { |
|
422 |
// JVMSpec| u2 attribute_name_index; |
|
423 |
// JVMSpec| u4 attribute_length; |
|
424 |
// JVMSpec| } |
|
425 |
void JvmtiClassFileReconstituter::write_synthetic_attribute() { |
|
426 |
write_attribute_name_index("Synthetic"); |
|
427 |
write_u4(0); //length always zero |
|
428 |
} |
|
429 |
||
430 |
// Compute size of LineNumberTable |
|
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
27401
diff
changeset
|
431 |
u2 JvmtiClassFileReconstituter::line_number_table_entries(const methodHandle& method) { |
1 | 432 |
// The line number table is compressed so we don't know how big it is until decompressed. |
433 |
// Decompression is really fast so we just do it twice. |
|
434 |
u2 num_entries = 0; |
|
435 |
CompressedLineNumberReadStream stream(method->compressed_linenumber_table()); |
|
436 |
while (stream.read_pair()) { |
|
437 |
num_entries++; |
|
438 |
} |
|
439 |
return num_entries; |
|
440 |
} |
|
441 |
||
442 |
// Write LineNumberTable attribute |
|
443 |
// JVMSpec| LineNumberTable_attribute { |
|
444 |
// JVMSpec| u2 attribute_name_index; |
|
445 |
// JVMSpec| u4 attribute_length; |
|
446 |
// JVMSpec| u2 line_number_table_length; |
|
447 |
// JVMSpec| { u2 start_pc; |
|
448 |
// JVMSpec| u2 line_number; |
|
449 |
// JVMSpec| } line_number_table[line_number_table_length]; |
|
450 |
// JVMSpec| } |
|
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
27401
diff
changeset
|
451 |
void JvmtiClassFileReconstituter::write_line_number_table_attribute(const methodHandle& method, |
1 | 452 |
u2 num_entries) { |
453 |
||
454 |
write_attribute_name_index("LineNumberTable"); |
|
455 |
write_u4(2 + num_entries * (2 + 2)); |
|
456 |
write_u2(num_entries); |
|
457 |
||
458 |
CompressedLineNumberReadStream stream(method->compressed_linenumber_table()); |
|
459 |
while (stream.read_pair()) { |
|
460 |
write_u2(stream.bci()); |
|
461 |
write_u2(stream.line()); |
|
462 |
} |
|
463 |
} |
|
464 |
||
13863
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
465 |
// Write LocalVariableTable attribute |
11257
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
466 |
// JVMSpec| LocalVariableTable_attribute { |
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
467 |
// JVMSpec| u2 attribute_name_index; |
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
468 |
// JVMSpec| u4 attribute_length; |
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
469 |
// JVMSpec| u2 local_variable_table_length; |
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
470 |
// JVMSpec| { u2 start_pc; |
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
471 |
// JVMSpec| u2 length; |
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
472 |
// JVMSpec| u2 name_index; |
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
473 |
// JVMSpec| u2 descriptor_index; |
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
474 |
// JVMSpec| u2 index; |
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
475 |
// JVMSpec| } local_variable_table[local_variable_table_length]; |
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
476 |
// JVMSpec| } |
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
27401
diff
changeset
|
477 |
void JvmtiClassFileReconstituter::write_local_variable_table_attribute(const methodHandle& method, u2 num_entries) { |
11257
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
478 |
write_attribute_name_index("LocalVariableTable"); |
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
479 |
write_u4(2 + num_entries * (2 + 2 + 2 + 2 + 2)); |
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
480 |
write_u2(num_entries); |
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
481 |
|
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
482 |
assert(method->localvariable_table_length() == num_entries, "just checking"); |
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
483 |
|
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
484 |
LocalVariableTableElement *elem = method->localvariable_table_start(); |
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
485 |
for (int j=0; j<method->localvariable_table_length(); j++) { |
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
486 |
write_u2(elem->start_bci); |
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
487 |
write_u2(elem->length); |
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
488 |
write_u2(elem->name_cp_index); |
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
489 |
write_u2(elem->descriptor_cp_index); |
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
490 |
write_u2(elem->slot); |
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
491 |
elem++; |
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
492 |
} |
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
493 |
} |
b98dfa12a8f7
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
10552
diff
changeset
|
494 |
|
13863
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
495 |
// Write LocalVariableTypeTable attribute |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
496 |
// JVMSpec| LocalVariableTypeTable_attribute { |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
497 |
// JVMSpec| u2 attribute_name_index; |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
498 |
// JVMSpec| u4 attribute_length; |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
499 |
// JVMSpec| u2 local_variable_type_table_length; |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
500 |
// JVMSpec| { u2 start_pc; |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
501 |
// JVMSpec| u2 length; |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
502 |
// JVMSpec| u2 name_index; |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
503 |
// JVMSpec| u2 signature_index; |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
504 |
// JVMSpec| u2 index; |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
505 |
// JVMSpec| } local_variable_type_table[local_variable_type_table_length]; |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
506 |
// JVMSpec| } |
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
27401
diff
changeset
|
507 |
void JvmtiClassFileReconstituter::write_local_variable_type_table_attribute(const methodHandle& method, u2 num_entries) { |
13863
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
508 |
write_attribute_name_index("LocalVariableTypeTable"); |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
509 |
write_u4(2 + num_entries * (2 + 2 + 2 + 2 + 2)); |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
510 |
write_u2(num_entries); |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
511 |
|
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
512 |
LocalVariableTableElement *elem = method->localvariable_table_start(); |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
513 |
for (int j=0; j<method->localvariable_table_length(); j++) { |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
514 |
if (elem->signature_cp_index > 0) { |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
515 |
// Local variable has a generic signature - write LVTT attribute entry |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
516 |
write_u2(elem->start_bci); |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
517 |
write_u2(elem->length); |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
518 |
write_u2(elem->name_cp_index); |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
519 |
write_u2(elem->signature_cp_index); |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
520 |
write_u2(elem->slot); |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
521 |
num_entries--; |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
522 |
} |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
523 |
elem++; |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
524 |
} |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
525 |
assert(num_entries == 0, "just checking"); |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
526 |
} |
3a6dfc8fdfd1
7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents:
13728
diff
changeset
|
527 |
|
1 | 528 |
// Write stack map table attribute |
529 |
// JSR-202| StackMapTable_attribute { |
|
530 |
// JSR-202| u2 attribute_name_index; |
|
531 |
// JSR-202| u4 attribute_length; |
|
532 |
// JSR-202| u2 number_of_entries; |
|
533 |
// JSR-202| stack_map_frame_entries[number_of_entries]; |
|
534 |
// JSR-202| } |
|
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
27401
diff
changeset
|
535 |
void JvmtiClassFileReconstituter::write_stackmap_table_attribute(const methodHandle& method, |
1 | 536 |
int stackmap_len) { |
537 |
||
538 |
write_attribute_name_index("StackMapTable"); |
|
539 |
write_u4(stackmap_len); |
|
540 |
memcpy( |
|
541 |
writeable_address(stackmap_len), |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
542 |
(void*)(method->stackmap_data()->adr_at(0)), |
1 | 543 |
stackmap_len); |
544 |
} |
|
545 |
||
546 |
// Write one method_info structure |
|
547 |
// JVMSpec| method_info { |
|
548 |
// JVMSpec| u2 access_flags; |
|
549 |
// JVMSpec| u2 name_index; |
|
550 |
// JVMSpec| u2 descriptor_index; |
|
551 |
// JVMSpec| u2 attributes_count; |
|
552 |
// JVMSpec| attribute_info attributes[attributes_count]; |
|
553 |
// JVMSpec| } |
|
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
27401
diff
changeset
|
554 |
void JvmtiClassFileReconstituter::write_method_info(const methodHandle& method) { |
1 | 555 |
AccessFlags access_flags = method->access_flags(); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
556 |
ConstMethod* const_method = method->constMethod(); |
1 | 557 |
u2 generic_signature_index = const_method->generic_signature_index(); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
558 |
AnnotationArray* anno = method->annotations(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
559 |
AnnotationArray* param_anno = method->parameter_annotations(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
560 |
AnnotationArray* default_anno = method->annotation_default(); |
27401
a4697c9502cb
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
25715
diff
changeset
|
561 |
AnnotationArray* type_anno = method->type_annotations(); |
1 | 562 |
|
17294
a1a03f4c1cab
8008453: JvmtiClassFileReconstituter does not recognize default methods
sla
parents:
14481
diff
changeset
|
563 |
// skip generated default interface methods |
a1a03f4c1cab
8008453: JvmtiClassFileReconstituter does not recognize default methods
sla
parents:
14481
diff
changeset
|
564 |
if (method->is_overpass()) { |
a1a03f4c1cab
8008453: JvmtiClassFileReconstituter does not recognize default methods
sla
parents:
14481
diff
changeset
|
565 |
return; |
a1a03f4c1cab
8008453: JvmtiClassFileReconstituter does not recognize default methods
sla
parents:
14481
diff
changeset
|
566 |
} |
a1a03f4c1cab
8008453: JvmtiClassFileReconstituter does not recognize default methods
sla
parents:
14481
diff
changeset
|
567 |
|
1 | 568 |
write_u2(access_flags.get_flags() & JVM_RECOGNIZED_METHOD_MODIFIERS); |
569 |
write_u2(const_method->name_index()); |
|
570 |
write_u2(const_method->signature_index()); |
|
571 |
||
572 |
// write attributes in the same order javac does, so we can test with byte for |
|
573 |
// byte comparison |
|
574 |
int attr_count = 0; |
|
575 |
if (const_method->code_size() != 0) { |
|
576 |
++attr_count; // has Code attribute |
|
577 |
} |
|
578 |
if (const_method->has_checked_exceptions()) { |
|
579 |
++attr_count; // has Exceptions attribute |
|
580 |
} |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
581 |
if (default_anno != NULL) { |
1 | 582 |
++attr_count; // has AnnotationDefault attribute |
583 |
} |
|
584 |
// Deprecated attribute would go here |
|
585 |
if (access_flags.is_synthetic()) { // FIXME |
|
586 |
// ++attr_count; |
|
587 |
} |
|
588 |
if (generic_signature_index != 0) { |
|
589 |
++attr_count; |
|
590 |
} |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
591 |
if (anno != NULL) { |
1 | 592 |
++attr_count; // has RuntimeVisibleAnnotations attribute |
593 |
} |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
594 |
if (param_anno != NULL) { |
1 | 595 |
++attr_count; // has RuntimeVisibleParameterAnnotations attribute |
596 |
} |
|
27401
a4697c9502cb
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
25715
diff
changeset
|
597 |
if (type_anno != NULL) { |
a4697c9502cb
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
25715
diff
changeset
|
598 |
++attr_count; // has RuntimeVisibleTypeAnnotations attribute |
a4697c9502cb
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
25715
diff
changeset
|
599 |
} |
1 | 600 |
|
601 |
write_u2(attr_count); |
|
602 |
if (const_method->code_size() > 0) { |
|
603 |
write_code_attribute(method); |
|
604 |
} |
|
605 |
if (const_method->has_checked_exceptions()) { |
|
606 |
write_exceptions_attribute(const_method); |
|
607 |
} |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
608 |
if (default_anno != NULL) { |
1 | 609 |
write_annotations_attribute("AnnotationDefault", default_anno); |
610 |
} |
|
611 |
// Deprecated attribute would go here |
|
612 |
if (access_flags.is_synthetic()) { |
|
613 |
// write_synthetic_attribute(); |
|
614 |
} |
|
615 |
if (generic_signature_index != 0) { |
|
616 |
write_signature_attribute(generic_signature_index); |
|
617 |
} |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
618 |
if (anno != NULL) { |
1 | 619 |
write_annotations_attribute("RuntimeVisibleAnnotations", anno); |
620 |
} |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
621 |
if (param_anno != NULL) { |
1 | 622 |
write_annotations_attribute("RuntimeVisibleParameterAnnotations", param_anno); |
623 |
} |
|
27401
a4697c9502cb
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
25715
diff
changeset
|
624 |
if (type_anno != NULL) { |
a4697c9502cb
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
25715
diff
changeset
|
625 |
write_annotations_attribute("RuntimeVisibleTypeAnnotations", type_anno); |
a4697c9502cb
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
25715
diff
changeset
|
626 |
} |
1 | 627 |
} |
628 |
||
629 |
// Write the class attributes portion of ClassFile structure |
|
630 |
// JVMSpec| u2 attributes_count; |
|
631 |
// JVMSpec| attribute_info attributes[attributes_count]; |
|
632 |
void JvmtiClassFileReconstituter::write_class_attributes() { |
|
633 |
u2 inner_classes_length = inner_classes_attribute_length(); |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
38031
diff
changeset
|
634 |
Symbol* generic_signature = ik()->generic_signature(); |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
38031
diff
changeset
|
635 |
AnnotationArray* anno = ik()->class_annotations(); |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
38031
diff
changeset
|
636 |
AnnotationArray* type_anno = ik()->class_type_annotations(); |
1 | 637 |
|
638 |
int attr_count = 0; |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
639 |
if (generic_signature != NULL) { |
1 | 640 |
++attr_count; |
641 |
} |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
38031
diff
changeset
|
642 |
if (ik()->source_file_name() != NULL) { |
1 | 643 |
++attr_count; |
644 |
} |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
38031
diff
changeset
|
645 |
if (ik()->source_debug_extension() != NULL) { |
1 | 646 |
++attr_count; |
647 |
} |
|
648 |
if (inner_classes_length > 0) { |
|
649 |
++attr_count; |
|
650 |
} |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
651 |
if (anno != NULL) { |
1 | 652 |
++attr_count; // has RuntimeVisibleAnnotations attribute |
653 |
} |
|
27401
a4697c9502cb
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
25715
diff
changeset
|
654 |
if (type_anno != NULL) { |
a4697c9502cb
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
25715
diff
changeset
|
655 |
++attr_count; // has RuntimeVisibleTypeAnnotations attribute |
a4697c9502cb
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
25715
diff
changeset
|
656 |
} |
17307
74bb7db916df
8009615: JvmtiClassFileReconstituter does not create BootstrapMethod attributes
sla
parents:
17294
diff
changeset
|
657 |
if (cpool()->operands() != NULL) { |
74bb7db916df
8009615: JvmtiClassFileReconstituter does not create BootstrapMethod attributes
sla
parents:
17294
diff
changeset
|
658 |
++attr_count; |
74bb7db916df
8009615: JvmtiClassFileReconstituter does not create BootstrapMethod attributes
sla
parents:
17294
diff
changeset
|
659 |
} |
1 | 660 |
|
661 |
write_u2(attr_count); |
|
662 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
663 |
if (generic_signature != NULL) { |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
664 |
write_signature_attribute(symbol_to_cpool_index(generic_signature)); |
1 | 665 |
} |
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
38031
diff
changeset
|
666 |
if (ik()->source_file_name() != NULL) { |
1 | 667 |
write_source_file_attribute(); |
668 |
} |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
38031
diff
changeset
|
669 |
if (ik()->source_debug_extension() != NULL) { |
1 | 670 |
write_source_debug_extension_attribute(); |
671 |
} |
|
672 |
if (inner_classes_length > 0) { |
|
673 |
write_inner_classes_attribute(inner_classes_length); |
|
674 |
} |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
675 |
if (anno != NULL) { |
1 | 676 |
write_annotations_attribute("RuntimeVisibleAnnotations", anno); |
677 |
} |
|
27401
a4697c9502cb
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
25715
diff
changeset
|
678 |
if (type_anno != NULL) { |
a4697c9502cb
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
25715
diff
changeset
|
679 |
write_annotations_attribute("RuntimeVisibleTypeAnnotations", type_anno); |
a4697c9502cb
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
25715
diff
changeset
|
680 |
} |
17307
74bb7db916df
8009615: JvmtiClassFileReconstituter does not create BootstrapMethod attributes
sla
parents:
17294
diff
changeset
|
681 |
if (cpool()->operands() != NULL) { |
17309
83ac929d332a
8014044: Spelling error in JDK-8009615: boostrapmethod
sla
parents:
17307
diff
changeset
|
682 |
write_bootstrapmethod_attribute(); |
17307
74bb7db916df
8009615: JvmtiClassFileReconstituter does not create BootstrapMethod attributes
sla
parents:
17294
diff
changeset
|
683 |
} |
1 | 684 |
} |
685 |
||
686 |
// Write the method information portion of ClassFile structure |
|
687 |
// JVMSpec| u2 methods_count; |
|
688 |
// JVMSpec| method_info methods[methods_count]; |
|
689 |
void JvmtiClassFileReconstituter::write_method_infos() { |
|
690 |
HandleMark hm(thread()); |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
38031
diff
changeset
|
691 |
Array<Method*>* methods = ik()->methods(); |
1 | 692 |
int num_methods = methods->length(); |
17294
a1a03f4c1cab
8008453: JvmtiClassFileReconstituter does not recognize default methods
sla
parents:
14481
diff
changeset
|
693 |
int num_overpass = 0; |
1 | 694 |
|
17294
a1a03f4c1cab
8008453: JvmtiClassFileReconstituter does not recognize default methods
sla
parents:
14481
diff
changeset
|
695 |
// count the generated default interface methods |
a1a03f4c1cab
8008453: JvmtiClassFileReconstituter does not recognize default methods
sla
parents:
14481
diff
changeset
|
696 |
// these will not be re-created by write_method_info |
a1a03f4c1cab
8008453: JvmtiClassFileReconstituter does not recognize default methods
sla
parents:
14481
diff
changeset
|
697 |
// and should not be included in the total count |
a1a03f4c1cab
8008453: JvmtiClassFileReconstituter does not recognize default methods
sla
parents:
14481
diff
changeset
|
698 |
for (int index = 0; index < num_methods; index++) { |
a1a03f4c1cab
8008453: JvmtiClassFileReconstituter does not recognize default methods
sla
parents:
14481
diff
changeset
|
699 |
Method* method = methods->at(index); |
a1a03f4c1cab
8008453: JvmtiClassFileReconstituter does not recognize default methods
sla
parents:
14481
diff
changeset
|
700 |
if (method->is_overpass()) { |
a1a03f4c1cab
8008453: JvmtiClassFileReconstituter does not recognize default methods
sla
parents:
14481
diff
changeset
|
701 |
num_overpass++; |
a1a03f4c1cab
8008453: JvmtiClassFileReconstituter does not recognize default methods
sla
parents:
14481
diff
changeset
|
702 |
} |
a1a03f4c1cab
8008453: JvmtiClassFileReconstituter does not recognize default methods
sla
parents:
14481
diff
changeset
|
703 |
} |
a1a03f4c1cab
8008453: JvmtiClassFileReconstituter does not recognize default methods
sla
parents:
14481
diff
changeset
|
704 |
|
a1a03f4c1cab
8008453: JvmtiClassFileReconstituter does not recognize default methods
sla
parents:
14481
diff
changeset
|
705 |
write_u2(num_methods - num_overpass); |
1 | 706 |
if (JvmtiExport::can_maintain_original_method_order()) { |
707 |
int index; |
|
708 |
int original_index; |
|
38031
e0b822facc03
8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents:
33593
diff
changeset
|
709 |
intArray method_order(num_methods, num_methods, 0); |
1 | 710 |
|
711 |
// invert the method order mapping |
|
712 |
for (index = 0; index < num_methods; index++) { |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
38031
diff
changeset
|
713 |
original_index = ik()->method_ordering()->at(index); |
1 | 714 |
assert(original_index >= 0 && original_index < num_methods, |
715 |
"invalid original method index"); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
716 |
method_order.at_put(original_index, index); |
1 | 717 |
} |
718 |
||
719 |
// write in original order |
|
720 |
for (original_index = 0; original_index < num_methods; original_index++) { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
721 |
index = method_order.at(original_index); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
722 |
methodHandle method(thread(), methods->at(index)); |
1 | 723 |
write_method_info(method); |
724 |
} |
|
725 |
} else { |
|
726 |
// method order not preserved just dump the method infos |
|
727 |
for (int index = 0; index < num_methods; index++) { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
728 |
methodHandle method(thread(), methods->at(index)); |
1 | 729 |
write_method_info(method); |
730 |
} |
|
731 |
} |
|
732 |
} |
|
733 |
||
734 |
void JvmtiClassFileReconstituter::write_class_file_format() { |
|
735 |
ReallocMark(); |
|
736 |
||
737 |
// JVMSpec| ClassFile { |
|
738 |
// JVMSpec| u4 magic; |
|
739 |
write_u4(0xCAFEBABE); |
|
740 |
||
741 |
// JVMSpec| u2 minor_version; |
|
742 |
// JVMSpec| u2 major_version; |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
38031
diff
changeset
|
743 |
write_u2(ik()->minor_version()); |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
38031
diff
changeset
|
744 |
u2 major = ik()->major_version(); |
1 | 745 |
write_u2(major); |
746 |
||
747 |
// JVMSpec| u2 constant_pool_count; |
|
748 |
// JVMSpec| cp_info constant_pool[constant_pool_count-1]; |
|
749 |
write_u2(cpool()->length()); |
|
750 |
copy_cpool_bytes(writeable_address(cpool_size())); |
|
751 |
||
752 |
// JVMSpec| u2 access_flags; |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
38031
diff
changeset
|
753 |
write_u2(ik()->access_flags().get_flags() & JVM_RECOGNIZED_CLASS_MODIFIERS); |
1 | 754 |
|
755 |
// JVMSpec| u2 this_class; |
|
756 |
// JVMSpec| u2 super_class; |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
38031
diff
changeset
|
757 |
write_u2(class_symbol_to_cpool_index(ik()->name())); |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
38031
diff
changeset
|
758 |
Klass* super_class = ik()->super(); |
1 | 759 |
write_u2(super_class == NULL? 0 : // zero for java.lang.Object |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
760 |
class_symbol_to_cpool_index(super_class->name())); |
1 | 761 |
|
762 |
// JVMSpec| u2 interfaces_count; |
|
763 |
// JVMSpec| u2 interfaces[interfaces_count]; |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
38031
diff
changeset
|
764 |
Array<Klass*>* interfaces = ik()->local_interfaces(); |
1 | 765 |
int num_interfaces = interfaces->length(); |
766 |
write_u2(num_interfaces); |
|
767 |
for (int index = 0; index < num_interfaces; index++) { |
|
768 |
HandleMark hm(thread()); |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
38031
diff
changeset
|
769 |
InstanceKlass* iik = InstanceKlass::cast(interfaces->at(index)); |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
38031
diff
changeset
|
770 |
write_u2(class_symbol_to_cpool_index(iik->name())); |
1 | 771 |
} |
772 |
||
773 |
// JVMSpec| u2 fields_count; |
|
774 |
// JVMSpec| field_info fields[fields_count]; |
|
775 |
write_field_infos(); |
|
776 |
||
777 |
// JVMSpec| u2 methods_count; |
|
778 |
// JVMSpec| method_info methods[methods_count]; |
|
779 |
write_method_infos(); |
|
780 |
||
781 |
// JVMSpec| u2 attributes_count; |
|
782 |
// JVMSpec| attribute_info attributes[attributes_count]; |
|
783 |
// JVMSpec| } /* end ClassFile 8? |
|
784 |
write_class_attributes(); |
|
785 |
} |
|
786 |
||
787 |
address JvmtiClassFileReconstituter::writeable_address(size_t size) { |
|
788 |
size_t used_size = _buffer_ptr - _buffer; |
|
789 |
if (size + used_size >= _buffer_size) { |
|
790 |
// compute the new buffer size: must be at least twice as big as before |
|
791 |
// plus whatever new is being used; then convert to nice clean block boundary |
|
792 |
size_t new_buffer_size = (size + _buffer_size*2 + 1) / initial_buffer_size |
|
793 |
* initial_buffer_size; |
|
794 |
||
795 |
// VM goes belly-up if the memory isn't available, so cannot do OOM processing |
|
796 |
_buffer = REALLOC_RESOURCE_ARRAY(u1, _buffer, _buffer_size, new_buffer_size); |
|
797 |
_buffer_size = new_buffer_size; |
|
798 |
_buffer_ptr = _buffer + used_size; |
|
799 |
} |
|
800 |
u1* ret_ptr = _buffer_ptr; |
|
801 |
_buffer_ptr += size; |
|
802 |
return ret_ptr; |
|
803 |
} |
|
804 |
||
805 |
void JvmtiClassFileReconstituter::write_attribute_name_index(const char* name) { |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
806 |
TempNewSymbol sym = SymbolTable::probe(name, (int)strlen(name)); |
1 | 807 |
assert(sym != NULL, "attribute name symbol not found"); |
808 |
u2 attr_name_index = symbol_to_cpool_index(sym); |
|
809 |
assert(attr_name_index != 0, "attribute name symbol not in constant pool"); |
|
810 |
write_u2(attr_name_index); |
|
811 |
} |
|
812 |
||
813 |
void JvmtiClassFileReconstituter::write_u1(u1 x) { |
|
814 |
*writeable_address(1) = x; |
|
815 |
} |
|
816 |
||
817 |
void JvmtiClassFileReconstituter::write_u2(u2 x) { |
|
818 |
Bytes::put_Java_u2(writeable_address(2), x); |
|
819 |
} |
|
820 |
||
821 |
void JvmtiClassFileReconstituter::write_u4(u4 x) { |
|
822 |
Bytes::put_Java_u4(writeable_address(4), x); |
|
823 |
} |
|
824 |
||
825 |
void JvmtiClassFileReconstituter::write_u8(u8 x) { |
|
826 |
Bytes::put_Java_u8(writeable_address(8), x); |
|
827 |
} |
|
828 |
||
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
27401
diff
changeset
|
829 |
void JvmtiClassFileReconstituter::copy_bytecodes(const methodHandle& mh, |
1 | 830 |
unsigned char* bytecodes) { |
831 |
// use a BytecodeStream to iterate over the bytecodes. JVM/fast bytecodes |
|
832 |
// and the breakpoint bytecode are converted to their original bytecodes. |
|
833 |
||
834 |
BytecodeStream bs(mh); |
|
835 |
||
836 |
unsigned char* p = bytecodes; |
|
837 |
Bytecodes::Code code; |
|
14391
df0a1573d5bd
8000725: NPG: method_holder() and pool_holder() and pool_holder field should be InstanceKlass
coleenp
parents:
13863
diff
changeset
|
838 |
bool is_rewritten = mh->method_holder()->is_rewritten(); |
1 | 839 |
|
840 |
while ((code = bs.next()) >= 0) { |
|
841 |
assert(Bytecodes::is_java_code(code), "sanity check"); |
|
842 |
assert(code != Bytecodes::_breakpoint, "sanity check"); |
|
843 |
||
844 |
// length of bytecode (mnemonic + operands) |
|
845 |
address bcp = bs.bcp(); |
|
5688 | 846 |
int len = bs.instruction_size(); |
1 | 847 |
assert(len > 0, "length must be > 0"); |
848 |
||
849 |
// copy the bytecodes |
|
850 |
*p = (unsigned char) (bs.is_wide()? Bytecodes::_wide : code); |
|
851 |
if (len > 1) { |
|
852 |
memcpy(p+1, bcp+1, len-1); |
|
853 |
} |
|
854 |
||
855 |
// During linking the get/put and invoke instructions are rewritten |
|
856 |
// with an index into the constant pool cache. The original constant |
|
857 |
// pool index must be returned to caller. Rewrite the index. |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
858 |
if (is_rewritten && len > 1) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
859 |
bool is_wide = false; |
1 | 860 |
switch (code) { |
861 |
case Bytecodes::_getstatic : // fall through |
|
862 |
case Bytecodes::_putstatic : // fall through |
|
863 |
case Bytecodes::_getfield : // fall through |
|
864 |
case Bytecodes::_putfield : // fall through |
|
865 |
case Bytecodes::_invokevirtual : // fall through |
|
866 |
case Bytecodes::_invokespecial : // fall through |
|
867 |
case Bytecodes::_invokestatic : // fall through |
|
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
868 |
case Bytecodes::_invokedynamic : // fall through |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
869 |
case Bytecodes::_invokeinterface : { |
12102
7a1c6c80bc23
7118280: The gbyc00102 JCK7 test causes an assert in JVM 7.0 fastdebug mode
dsamersoff
parents:
11257
diff
changeset
|
870 |
assert(len == 3 || |
7a1c6c80bc23
7118280: The gbyc00102 JCK7 test causes an assert in JVM 7.0 fastdebug mode
dsamersoff
parents:
11257
diff
changeset
|
871 |
(code == Bytecodes::_invokeinterface && len == 5) || |
7a1c6c80bc23
7118280: The gbyc00102 JCK7 test causes an assert in JVM 7.0 fastdebug mode
dsamersoff
parents:
11257
diff
changeset
|
872 |
(code == Bytecodes::_invokedynamic && len == 5), |
1 | 873 |
"sanity check"); |
12102
7a1c6c80bc23
7118280: The gbyc00102 JCK7 test causes an assert in JVM 7.0 fastdebug mode
dsamersoff
parents:
11257
diff
changeset
|
874 |
|
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
875 |
int cpci = Bytes::get_native_u2(bcp+1); |
24322 | 876 |
bool is_invokedynamic = (code == Bytecodes::_invokedynamic); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
877 |
ConstantPoolCacheEntry* entry; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
878 |
if (is_invokedynamic) { |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
879 |
cpci = Bytes::get_native_u4(bcp+1); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
880 |
entry = mh->constants()->invokedynamic_cp_cache_entry_at(cpci); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
881 |
} else { |
1 | 882 |
// cache cannot be pre-fetched since some classes won't have it yet |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
883 |
entry = mh->constants()->cache()->entry_at(cpci); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
884 |
} |
1 | 885 |
int i = entry->constant_pool_index(); |
886 |
assert(i < mh->constants()->length(), "sanity check"); |
|
887 |
Bytes::put_Java_u2((address)(p+1), (u2)i); // java byte ordering |
|
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
888 |
if (is_invokedynamic) *(p+3) = *(p+4) = 0; |
1 | 889 |
break; |
890 |
} |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
891 |
case Bytecodes::_ldc_w: |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
892 |
is_wide = true; // fall through |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
893 |
case Bytecodes::_ldc: { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
894 |
if (bs.raw_code() == Bytecodes::_fast_aldc || bs.raw_code() == Bytecodes::_fast_aldc_w) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
895 |
int cpci = is_wide ? Bytes::get_native_u2(bcp+1) : (u1)(*(bcp+1)); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
896 |
int i = mh->constants()->object_to_cp_index(cpci); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
897 |
assert(i < mh->constants()->length(), "sanity check"); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
898 |
if (is_wide) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
899 |
Bytes::put_Java_u2((address)(p+1), (u2)i); // java byte ordering |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
900 |
} else { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
901 |
*(p+1) = (u1)i; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
902 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
903 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
904 |
break; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
905 |
} |
46630
75aa3e39d02c
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents:
46329
diff
changeset
|
906 |
default: |
75aa3e39d02c
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents:
46329
diff
changeset
|
907 |
break; |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13286
diff
changeset
|
908 |
} |
1 | 909 |
} |
910 |
||
911 |
p += len; |
|
912 |
} |
|
913 |
} |