Mercurial > hg > graal-compiler
annotate src/share/vm/prims/jvmtiClassFileReconstituter.cpp @ 6217:e74da3c2b827
Merge
author | jiangli |
---|---|
date | Fri, 13 Jul 2012 20:14:27 -0400 |
parents | 04ade88d9712 8150fa46d2ed |
children | da91efe96a93 |
rev | line source |
---|---|
0 | 1 /* |
5922
ff29ce866f23
7118280: The gbyc00102 JCK7 test causes an assert in JVM 7.0 fastdebug mode
dsamersoff
parents:
4718
diff
changeset
|
2 * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
844
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
844
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
844
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "classfile/symbolTable.hpp" | |
27 #include "interpreter/bytecodeStream.hpp" | |
3938 | 28 #include "oops/fieldStreams.hpp" |
1972 | 29 #include "prims/jvmtiClassFileReconstituter.hpp" |
30 #include "runtime/signature.hpp" | |
31 #ifdef TARGET_ARCH_x86 | |
32 # include "bytes_x86.hpp" | |
33 #endif | |
34 #ifdef TARGET_ARCH_sparc | |
35 # include "bytes_sparc.hpp" | |
36 #endif | |
37 #ifdef TARGET_ARCH_zero | |
38 # include "bytes_zero.hpp" | |
39 #endif | |
2192
b92c45f2bc75
7016023: Enable building ARM and PPC from src/closed repository
bobv
parents:
2177
diff
changeset
|
40 #ifdef TARGET_ARCH_arm |
b92c45f2bc75
7016023: Enable building ARM and PPC from src/closed repository
bobv
parents:
2177
diff
changeset
|
41 # include "bytes_arm.hpp" |
b92c45f2bc75
7016023: Enable building ARM and PPC from src/closed repository
bobv
parents:
2177
diff
changeset
|
42 #endif |
b92c45f2bc75
7016023: Enable building ARM and PPC from src/closed repository
bobv
parents:
2177
diff
changeset
|
43 #ifdef TARGET_ARCH_ppc |
b92c45f2bc75
7016023: Enable building ARM and PPC from src/closed repository
bobv
parents:
2177
diff
changeset
|
44 # include "bytes_ppc.hpp" |
b92c45f2bc75
7016023: Enable building ARM and PPC from src/closed repository
bobv
parents:
2177
diff
changeset
|
45 #endif |
4718
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
46 // FIXME: add Deprecated, LVTT attributes |
0 | 47 // FIXME: fix Synthetic attribute |
48 // FIXME: per Serguei, add error return handling for constantPoolOopDesc::copy_cpool_bytes() | |
49 | |
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()); | |
56 objArrayHandle fields_anno(thread(), ikh()->fields_annotations()); | |
57 | |
3938 | 58 // Compute the real number of Java fields |
59 int java_fields = ikh()->java_fields_count(); | |
60 | |
3944 | 61 write_u2(java_fields); |
3938 | 62 for (JavaFieldStream fs(ikh()); !fs.done(); fs.next()) { |
63 AccessFlags access_flags = fs.access_flags(); | |
64 int name_index = fs.name_index(); | |
65 int signature_index = fs.signature_index(); | |
66 int initial_value_index = fs.initval_index(); | |
0 | 67 guarantee(name_index != 0 && signature_index != 0, "bad constant pool index for field"); |
3938 | 68 // int offset = ikh()->field_offset( index ); |
69 int generic_signature_index = fs.generic_signature_index(); | |
0 | 70 typeArrayHandle anno(thread(), fields_anno.not_null() ? |
3938 | 71 (typeArrayOop)(fields_anno->obj_at(fs.index())) : |
0 | 72 (typeArrayOop)NULL); |
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 | |
3938 | 82 write_u2(access_flags.as_int() & JVM_RECOGNIZED_FIELD_MODIFIERS); |
0 | 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 } | |
95 if (anno.not_null()) { | |
96 ++attr_count; // has RuntimeVisibleAnnotations attribute | |
97 } | |
98 | |
99 write_u2(attr_count); | |
100 | |
101 if (initial_value_index != 0) { | |
102 write_attribute_name_index("ConstantValue"); | |
103 write_u4(2); //length always 2 | |
104 write_u2(initial_value_index); | |
105 } | |
106 if (access_flags.is_synthetic()) { | |
107 // write_synthetic_attribute(); | |
108 } | |
109 if (generic_signature_index != 0) { | |
110 write_signature_attribute(generic_signature_index); | |
111 } | |
112 if (anno.not_null()) { | |
113 write_annotations_attribute("RuntimeVisibleAnnotations", anno); | |
114 } | |
115 } | |
116 } | |
117 | |
118 // Write Code attribute | |
119 // JVMSpec| Code_attribute { | |
120 // JVMSpec| u2 attribute_name_index; | |
121 // JVMSpec| u4 attribute_length; | |
122 // JVMSpec| u2 max_stack; | |
123 // JVMSpec| u2 max_locals; | |
124 // JVMSpec| u4 code_length; | |
125 // JVMSpec| u1 code[code_length]; | |
126 // JVMSpec| u2 exception_table_length; | |
127 // JVMSpec| { u2 start_pc; | |
128 // JVMSpec| u2 end_pc; | |
129 // JVMSpec| u2 handler_pc; | |
130 // JVMSpec| u2 catch_type; | |
131 // JVMSpec| } exception_table[exception_table_length]; | |
132 // JVMSpec| u2 attributes_count; | |
133 // JVMSpec| attribute_info attributes[attributes_count]; | |
134 // JVMSpec| } | |
135 void JvmtiClassFileReconstituter::write_code_attribute(methodHandle method) { | |
136 constMethodHandle const_method(thread(), method->constMethod()); | |
137 u2 line_num_cnt = 0; | |
138 int stackmap_len = 0; | |
4718
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
139 int local_variable_table_length = 0; |
0 | 140 |
4718
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
141 // compute number and length of attributes |
0 | 142 int attr_count = 0; |
143 int attr_size = 0; | |
144 if (const_method->has_linenumber_table()) { | |
145 line_num_cnt = line_number_table_entries(method); | |
146 if (line_num_cnt != 0) { | |
147 ++attr_count; | |
148 // Compute the complete size of the line number table attribute: | |
149 // LineNumberTable_attribute { | |
150 // u2 attribute_name_index; | |
151 // u4 attribute_length; | |
152 // u2 line_number_table_length; | |
153 // { u2 start_pc; | |
154 // u2 line_number; | |
155 // } line_number_table[line_number_table_length]; | |
156 // } | |
157 attr_size += 2 + 4 + 2 + line_num_cnt * (2 + 2); | |
158 } | |
159 } | |
160 if (method->has_stackmap_table()) { | |
161 stackmap_len = method->stackmap_data()->length(); | |
162 if (stackmap_len != 0) { | |
163 ++attr_count; | |
164 // Compute the size of the stack map table attribute (VM stores raw): | |
165 // StackMapTable_attribute { | |
166 // u2 attribute_name_index; | |
167 // u4 attribute_length; | |
168 // u2 number_of_entries; | |
169 // stack_map_frame_entries[number_of_entries]; | |
170 // } | |
171 attr_size += 2 + 4 + stackmap_len; | |
172 } | |
173 } | |
4718
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
174 if (method->has_localvariable_table()) { |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
175 local_variable_table_length = method->localvariable_table_length(); |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
176 ++attr_count; |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
177 if (local_variable_table_length != 0) { |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
178 // Compute the size of the local variable table attribute (VM stores raw): |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
179 // LocalVariableTable_attribute { |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
180 // u2 attribute_name_index; |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
181 // u4 attribute_length; |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
182 // u2 local_variable_table_length; |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
183 // { |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
184 // u2 start_pc; |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
185 // u2 length; |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
186 // u2 name_index; |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
187 // u2 descriptor_index; |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
188 // u2 index; |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
189 // } |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
190 attr_size += 2 + 4 + 2 + local_variable_table_length * (2 + 2 + 2 + 2 + 2); |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
191 } |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
192 } |
0 | 193 |
6213
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
5967
diff
changeset
|
194 ExceptionTable exception_table(method()); |
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
5967
diff
changeset
|
195 int exception_table_length = exception_table.length(); |
0 | 196 int code_size = const_method->code_size(); |
197 int size = | |
198 2+2+4 + // max_stack, max_locals, code_length | |
199 code_size + // code | |
200 2 + // exception_table_length | |
6213
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
5967
diff
changeset
|
201 (2+2+2+2) * exception_table_length + // exception_table |
0 | 202 2 + // attributes_count |
203 attr_size; // attributes | |
204 | |
205 write_attribute_name_index("Code"); | |
206 write_u4(size); | |
207 write_u2(method->max_stack()); | |
208 write_u2(method->max_locals()); | |
209 write_u4(code_size); | |
210 copy_bytecodes(method, (unsigned char*)writeable_address(code_size)); | |
6213
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
5967
diff
changeset
|
211 write_u2(exception_table_length); |
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
5967
diff
changeset
|
212 for (int index = 0; index < exception_table_length; index++) { |
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
5967
diff
changeset
|
213 write_u2(exception_table.start_pc(index)); |
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
5967
diff
changeset
|
214 write_u2(exception_table.end_pc(index)); |
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
5967
diff
changeset
|
215 write_u2(exception_table.handler_pc(index)); |
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
5967
diff
changeset
|
216 write_u2(exception_table.catch_type_index(index)); |
0 | 217 } |
218 write_u2(attr_count); | |
219 if (line_num_cnt != 0) { | |
220 write_line_number_table_attribute(method, line_num_cnt); | |
221 } | |
222 if (stackmap_len != 0) { | |
223 write_stackmap_table_attribute(method, stackmap_len); | |
224 } | |
4718
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
225 if (local_variable_table_length != 0) { |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
226 write_local_variable_table_attribute(method, local_variable_table_length); |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
227 } |
0 | 228 } |
229 | |
230 // Write Exceptions attribute | |
231 // JVMSpec| Exceptions_attribute { | |
232 // JVMSpec| u2 attribute_name_index; | |
233 // JVMSpec| u4 attribute_length; | |
234 // JVMSpec| u2 number_of_exceptions; | |
235 // JVMSpec| u2 exception_index_table[number_of_exceptions]; | |
236 // JVMSpec| } | |
237 void JvmtiClassFileReconstituter::write_exceptions_attribute(constMethodHandle const_method) { | |
238 CheckedExceptionElement* checked_exceptions = const_method->checked_exceptions_start(); | |
239 int checked_exceptions_length = const_method->checked_exceptions_length(); | |
240 int size = | |
241 2 + // number_of_exceptions | |
242 2 * checked_exceptions_length; // exception_index_table | |
243 | |
244 write_attribute_name_index("Exceptions"); | |
245 write_u4(size); | |
246 write_u2(checked_exceptions_length); | |
247 for (int index = 0; index < checked_exceptions_length; index++) { | |
248 write_u2(checked_exceptions[index].class_cp_index); | |
249 } | |
250 } | |
251 | |
252 // Write SourceFile attribute | |
253 // JVMSpec| SourceFile_attribute { | |
254 // JVMSpec| u2 attribute_name_index; | |
255 // JVMSpec| u4 attribute_length; | |
256 // JVMSpec| u2 sourcefile_index; | |
257 // JVMSpec| } | |
258 void JvmtiClassFileReconstituter::write_source_file_attribute() { | |
259 assert(ikh()->source_file_name() != NULL, "caller must check"); | |
260 | |
261 write_attribute_name_index("SourceFile"); | |
262 write_u4(2); // always length 2 | |
263 write_u2(symbol_to_cpool_index(ikh()->source_file_name())); | |
264 } | |
265 | |
266 // Write SourceDebugExtension attribute | |
267 // JSR45| SourceDebugExtension_attribute { | |
268 // JSR45| u2 attribute_name_index; | |
269 // JSR45| u4 attribute_length; | |
6203
04ade88d9712
6294277: java -Xdebug crashes on SourceDebugExtension attribute larger than 64K
fparain
parents:
5967
diff
changeset
|
270 // JSR45| u1 debug_extension[attribute_length]; |
0 | 271 // JSR45| } |
272 void JvmtiClassFileReconstituter::write_source_debug_extension_attribute() { | |
273 assert(ikh()->source_debug_extension() != NULL, "caller must check"); | |
274 | |
275 write_attribute_name_index("SourceDebugExtension"); | |
6203
04ade88d9712
6294277: java -Xdebug crashes on SourceDebugExtension attribute larger than 64K
fparain
parents:
5967
diff
changeset
|
276 int len = (int)strlen(ikh()->source_debug_extension()); |
04ade88d9712
6294277: java -Xdebug crashes on SourceDebugExtension attribute larger than 64K
fparain
parents:
5967
diff
changeset
|
277 write_u4(len); |
04ade88d9712
6294277: java -Xdebug crashes on SourceDebugExtension attribute larger than 64K
fparain
parents:
5967
diff
changeset
|
278 u1* ext = (u1*)ikh()->source_debug_extension(); |
04ade88d9712
6294277: java -Xdebug crashes on SourceDebugExtension attribute larger than 64K
fparain
parents:
5967
diff
changeset
|
279 for (int i=0; i<len; i++) { |
04ade88d9712
6294277: java -Xdebug crashes on SourceDebugExtension attribute larger than 64K
fparain
parents:
5967
diff
changeset
|
280 write_u1(ext[i]); |
04ade88d9712
6294277: java -Xdebug crashes on SourceDebugExtension attribute larger than 64K
fparain
parents:
5967
diff
changeset
|
281 } |
0 | 282 } |
283 | |
284 // Write (generic) Signature attribute | |
285 // JVMSpec| Signature_attribute { | |
286 // JVMSpec| u2 attribute_name_index; | |
287 // JVMSpec| u4 attribute_length; | |
288 // JVMSpec| u2 signature_index; | |
289 // JVMSpec| } | |
290 void JvmtiClassFileReconstituter::write_signature_attribute(u2 generic_signature_index) { | |
291 write_attribute_name_index("Signature"); | |
292 write_u4(2); // always length 2 | |
293 write_u2(generic_signature_index); | |
294 } | |
295 | |
296 // Compute the number of entries in the InnerClasses attribute | |
297 u2 JvmtiClassFileReconstituter::inner_classes_attribute_length() { | |
5967
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
5922
diff
changeset
|
298 InnerClassesIterator iter(ikh()); |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
5922
diff
changeset
|
299 return iter.length(); |
0 | 300 } |
301 | |
302 // Write an annotation attribute. The VM stores them in raw form, so all we need | |
303 // to do is add the attrubute name and fill in the length. | |
304 // JSR202| *Annotations_attribute { | |
305 // JSR202| u2 attribute_name_index; | |
306 // JSR202| u4 attribute_length; | |
307 // JSR202| ... | |
308 // JSR202| } | |
309 void JvmtiClassFileReconstituter::write_annotations_attribute(const char* attr_name, | |
310 typeArrayHandle annos) { | |
311 u4 length = annos->length(); | |
312 write_attribute_name_index(attr_name); | |
313 write_u4(length); | |
314 memcpy(writeable_address(length), annos->byte_at_addr(0), length); | |
315 } | |
316 | |
317 | |
318 // Write InnerClasses attribute | |
319 // JVMSpec| InnerClasses_attribute { | |
320 // JVMSpec| u2 attribute_name_index; | |
321 // JVMSpec| u4 attribute_length; | |
322 // JVMSpec| u2 number_of_classes; | |
323 // JVMSpec| { u2 inner_class_info_index; | |
324 // JVMSpec| u2 outer_class_info_index; | |
325 // JVMSpec| u2 inner_name_index; | |
326 // JVMSpec| u2 inner_class_access_flags; | |
327 // JVMSpec| } classes[number_of_classes]; | |
328 // JVMSpec| } | |
329 void JvmtiClassFileReconstituter::write_inner_classes_attribute(int length) { | |
5967
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
5922
diff
changeset
|
330 InnerClassesIterator iter(ikh()); |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
5922
diff
changeset
|
331 guarantee(iter.length() != 0 && iter.length() == length, |
0 | 332 "caller must check"); |
333 u2 entry_count = length / instanceKlass::inner_class_next_offset; | |
334 u4 size = 2 + entry_count * (2+2+2+2); | |
335 | |
336 write_attribute_name_index("InnerClasses"); | |
337 write_u4(size); | |
338 write_u2(entry_count); | |
5967
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
5922
diff
changeset
|
339 for (; !iter.done(); iter.next()) { |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
5922
diff
changeset
|
340 write_u2(iter.inner_class_info_index()); |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
5922
diff
changeset
|
341 write_u2(iter.outer_class_info_index()); |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
5922
diff
changeset
|
342 write_u2(iter.inner_name_index()); |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
5922
diff
changeset
|
343 write_u2(iter.inner_access_flags()); |
0 | 344 } |
345 } | |
346 | |
347 // Write Synthetic attribute | |
348 // JVMSpec| Synthetic_attribute { | |
349 // JVMSpec| u2 attribute_name_index; | |
350 // JVMSpec| u4 attribute_length; | |
351 // JVMSpec| } | |
352 void JvmtiClassFileReconstituter::write_synthetic_attribute() { | |
353 write_attribute_name_index("Synthetic"); | |
354 write_u4(0); //length always zero | |
355 } | |
356 | |
357 // Compute size of LineNumberTable | |
358 u2 JvmtiClassFileReconstituter::line_number_table_entries(methodHandle method) { | |
359 // The line number table is compressed so we don't know how big it is until decompressed. | |
360 // Decompression is really fast so we just do it twice. | |
361 u2 num_entries = 0; | |
362 CompressedLineNumberReadStream stream(method->compressed_linenumber_table()); | |
363 while (stream.read_pair()) { | |
364 num_entries++; | |
365 } | |
366 return num_entries; | |
367 } | |
368 | |
369 // Write LineNumberTable attribute | |
370 // JVMSpec| LineNumberTable_attribute { | |
371 // JVMSpec| u2 attribute_name_index; | |
372 // JVMSpec| u4 attribute_length; | |
373 // JVMSpec| u2 line_number_table_length; | |
374 // JVMSpec| { u2 start_pc; | |
375 // JVMSpec| u2 line_number; | |
376 // JVMSpec| } line_number_table[line_number_table_length]; | |
377 // JVMSpec| } | |
378 void JvmtiClassFileReconstituter::write_line_number_table_attribute(methodHandle method, | |
379 u2 num_entries) { | |
380 | |
381 write_attribute_name_index("LineNumberTable"); | |
382 write_u4(2 + num_entries * (2 + 2)); | |
383 write_u2(num_entries); | |
384 | |
385 CompressedLineNumberReadStream stream(method->compressed_linenumber_table()); | |
386 while (stream.read_pair()) { | |
387 write_u2(stream.bci()); | |
388 write_u2(stream.line()); | |
389 } | |
390 } | |
391 | |
4718
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
392 // Write LineNumberTable attribute |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
393 // JVMSpec| LocalVariableTable_attribute { |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
394 // JVMSpec| u2 attribute_name_index; |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
395 // JVMSpec| u4 attribute_length; |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
396 // JVMSpec| u2 local_variable_table_length; |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
397 // JVMSpec| { u2 start_pc; |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
398 // JVMSpec| u2 length; |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
399 // JVMSpec| u2 name_index; |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
400 // JVMSpec| u2 descriptor_index; |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
401 // JVMSpec| u2 index; |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
402 // JVMSpec| } local_variable_table[local_variable_table_length]; |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
403 // JVMSpec| } |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
404 void JvmtiClassFileReconstituter::write_local_variable_table_attribute(methodHandle method, u2 num_entries) { |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
405 write_attribute_name_index("LocalVariableTable"); |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
406 write_u4(2 + num_entries * (2 + 2 + 2 + 2 + 2)); |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
407 write_u2(num_entries); |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
408 |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
409 assert(method->localvariable_table_length() == num_entries, "just checking"); |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
410 |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
411 LocalVariableTableElement *elem = method->localvariable_table_start(); |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
412 for (int j=0; j<method->localvariable_table_length(); j++) { |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
413 write_u2(elem->start_bci); |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
414 write_u2(elem->length); |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
415 write_u2(elem->name_cp_index); |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
416 write_u2(elem->descriptor_cp_index); |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
417 write_u2(elem->slot); |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
418 elem++; |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
419 } |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
420 } |
c01e115b095e
7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents:
3944
diff
changeset
|
421 |
0 | 422 // Write stack map table attribute |
423 // JSR-202| StackMapTable_attribute { | |
424 // JSR-202| u2 attribute_name_index; | |
425 // JSR-202| u4 attribute_length; | |
426 // JSR-202| u2 number_of_entries; | |
427 // JSR-202| stack_map_frame_entries[number_of_entries]; | |
428 // JSR-202| } | |
429 void JvmtiClassFileReconstituter::write_stackmap_table_attribute(methodHandle method, | |
430 int stackmap_len) { | |
431 | |
432 write_attribute_name_index("StackMapTable"); | |
433 write_u4(stackmap_len); | |
434 memcpy( | |
435 writeable_address(stackmap_len), | |
436 (void*)(method->stackmap_data()->byte_at_addr(0)), | |
437 stackmap_len); | |
438 } | |
439 | |
440 // Write one method_info structure | |
441 // JVMSpec| method_info { | |
442 // JVMSpec| u2 access_flags; | |
443 // JVMSpec| u2 name_index; | |
444 // JVMSpec| u2 descriptor_index; | |
445 // JVMSpec| u2 attributes_count; | |
446 // JVMSpec| attribute_info attributes[attributes_count]; | |
447 // JVMSpec| } | |
448 void JvmtiClassFileReconstituter::write_method_info(methodHandle method) { | |
449 AccessFlags access_flags = method->access_flags(); | |
450 constMethodHandle const_method(thread(), method->constMethod()); | |
451 u2 generic_signature_index = const_method->generic_signature_index(); | |
452 typeArrayHandle anno(thread(), method->annotations()); | |
453 typeArrayHandle param_anno(thread(), method->parameter_annotations()); | |
454 typeArrayHandle default_anno(thread(), method->annotation_default()); | |
455 | |
456 write_u2(access_flags.get_flags() & JVM_RECOGNIZED_METHOD_MODIFIERS); | |
457 write_u2(const_method->name_index()); | |
458 write_u2(const_method->signature_index()); | |
459 | |
460 // write attributes in the same order javac does, so we can test with byte for | |
461 // byte comparison | |
462 int attr_count = 0; | |
463 if (const_method->code_size() != 0) { | |
464 ++attr_count; // has Code attribute | |
465 } | |
466 if (const_method->has_checked_exceptions()) { | |
467 ++attr_count; // has Exceptions attribute | |
468 } | |
469 if (default_anno.not_null()) { | |
470 ++attr_count; // has AnnotationDefault attribute | |
471 } | |
472 // Deprecated attribute would go here | |
473 if (access_flags.is_synthetic()) { // FIXME | |
474 // ++attr_count; | |
475 } | |
476 if (generic_signature_index != 0) { | |
477 ++attr_count; | |
478 } | |
479 if (anno.not_null()) { | |
480 ++attr_count; // has RuntimeVisibleAnnotations attribute | |
481 } | |
482 if (param_anno.not_null()) { | |
483 ++attr_count; // has RuntimeVisibleParameterAnnotations attribute | |
484 } | |
485 | |
486 write_u2(attr_count); | |
487 if (const_method->code_size() > 0) { | |
488 write_code_attribute(method); | |
489 } | |
490 if (const_method->has_checked_exceptions()) { | |
491 write_exceptions_attribute(const_method); | |
492 } | |
493 if (default_anno.not_null()) { | |
494 write_annotations_attribute("AnnotationDefault", default_anno); | |
495 } | |
496 // Deprecated attribute would go here | |
497 if (access_flags.is_synthetic()) { | |
498 // write_synthetic_attribute(); | |
499 } | |
500 if (generic_signature_index != 0) { | |
501 write_signature_attribute(generic_signature_index); | |
502 } | |
503 if (anno.not_null()) { | |
504 write_annotations_attribute("RuntimeVisibleAnnotations", anno); | |
505 } | |
506 if (param_anno.not_null()) { | |
507 write_annotations_attribute("RuntimeVisibleParameterAnnotations", param_anno); | |
508 } | |
509 } | |
510 | |
511 // Write the class attributes portion of ClassFile structure | |
512 // JVMSpec| u2 attributes_count; | |
513 // JVMSpec| attribute_info attributes[attributes_count]; | |
514 void JvmtiClassFileReconstituter::write_class_attributes() { | |
515 u2 inner_classes_length = inner_classes_attribute_length(); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
516 Symbol* generic_signature = ikh()->generic_signature(); |
0 | 517 typeArrayHandle anno(thread(), ikh()->class_annotations()); |
518 | |
519 int attr_count = 0; | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
520 if (generic_signature != NULL) { |
0 | 521 ++attr_count; |
522 } | |
523 if (ikh()->source_file_name() != NULL) { | |
524 ++attr_count; | |
525 } | |
526 if (ikh()->source_debug_extension() != NULL) { | |
527 ++attr_count; | |
528 } | |
529 if (inner_classes_length > 0) { | |
530 ++attr_count; | |
531 } | |
532 if (anno.not_null()) { | |
533 ++attr_count; // has RuntimeVisibleAnnotations attribute | |
534 } | |
535 | |
536 write_u2(attr_count); | |
537 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
538 if (generic_signature != NULL) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
539 write_signature_attribute(symbol_to_cpool_index(generic_signature)); |
0 | 540 } |
541 if (ikh()->source_file_name() != NULL) { | |
542 write_source_file_attribute(); | |
543 } | |
544 if (ikh()->source_debug_extension() != NULL) { | |
545 write_source_debug_extension_attribute(); | |
546 } | |
547 if (inner_classes_length > 0) { | |
548 write_inner_classes_attribute(inner_classes_length); | |
549 } | |
550 if (anno.not_null()) { | |
551 write_annotations_attribute("RuntimeVisibleAnnotations", anno); | |
552 } | |
553 } | |
554 | |
555 // Write the method information portion of ClassFile structure | |
556 // JVMSpec| u2 methods_count; | |
557 // JVMSpec| method_info methods[methods_count]; | |
558 void JvmtiClassFileReconstituter::write_method_infos() { | |
559 HandleMark hm(thread()); | |
560 objArrayHandle methods(thread(), ikh()->methods()); | |
561 int num_methods = methods->length(); | |
562 | |
563 write_u2(num_methods); | |
564 if (JvmtiExport::can_maintain_original_method_order()) { | |
565 int index; | |
566 int original_index; | |
567 int* method_order = NEW_RESOURCE_ARRAY(int, num_methods); | |
568 | |
569 // invert the method order mapping | |
570 for (index = 0; index < num_methods; index++) { | |
571 original_index = ikh()->method_ordering()->int_at(index); | |
572 assert(original_index >= 0 && original_index < num_methods, | |
573 "invalid original method index"); | |
574 method_order[original_index] = index; | |
575 } | |
576 | |
577 // write in original order | |
578 for (original_index = 0; original_index < num_methods; original_index++) { | |
579 index = method_order[original_index]; | |
580 methodHandle method(thread(), (methodOop)(ikh()->methods()->obj_at(index))); | |
581 write_method_info(method); | |
582 } | |
583 } else { | |
584 // method order not preserved just dump the method infos | |
585 for (int index = 0; index < num_methods; index++) { | |
586 methodHandle method(thread(), (methodOop)(ikh()->methods()->obj_at(index))); | |
587 write_method_info(method); | |
588 } | |
589 } | |
590 } | |
591 | |
592 void JvmtiClassFileReconstituter::write_class_file_format() { | |
593 ReallocMark(); | |
594 | |
595 // JVMSpec| ClassFile { | |
596 // JVMSpec| u4 magic; | |
597 write_u4(0xCAFEBABE); | |
598 | |
599 // JVMSpec| u2 minor_version; | |
600 // JVMSpec| u2 major_version; | |
601 write_u2(ikh()->minor_version()); | |
602 u2 major = ikh()->major_version(); | |
603 write_u2(major); | |
604 | |
605 // JVMSpec| u2 constant_pool_count; | |
606 // JVMSpec| cp_info constant_pool[constant_pool_count-1]; | |
607 write_u2(cpool()->length()); | |
608 copy_cpool_bytes(writeable_address(cpool_size())); | |
609 | |
610 // JVMSpec| u2 access_flags; | |
611 write_u2(ikh()->access_flags().get_flags() & JVM_RECOGNIZED_CLASS_MODIFIERS); | |
612 | |
613 // JVMSpec| u2 this_class; | |
614 // JVMSpec| u2 super_class; | |
615 write_u2(class_symbol_to_cpool_index(ikh()->name())); | |
616 klassOop super_class = ikh()->super(); | |
617 write_u2(super_class == NULL? 0 : // zero for java.lang.Object | |
618 class_symbol_to_cpool_index(super_class->klass_part()->name())); | |
619 | |
620 // JVMSpec| u2 interfaces_count; | |
621 // JVMSpec| u2 interfaces[interfaces_count]; | |
622 objArrayHandle interfaces(thread(), ikh()->local_interfaces()); | |
623 int num_interfaces = interfaces->length(); | |
624 write_u2(num_interfaces); | |
625 for (int index = 0; index < num_interfaces; index++) { | |
626 HandleMark hm(thread()); | |
627 instanceKlassHandle iikh(thread(), klassOop(interfaces->obj_at(index))); | |
628 write_u2(class_symbol_to_cpool_index(iikh->name())); | |
629 } | |
630 | |
631 // JVMSpec| u2 fields_count; | |
632 // JVMSpec| field_info fields[fields_count]; | |
633 write_field_infos(); | |
634 | |
635 // JVMSpec| u2 methods_count; | |
636 // JVMSpec| method_info methods[methods_count]; | |
637 write_method_infos(); | |
638 | |
639 // JVMSpec| u2 attributes_count; | |
640 // JVMSpec| attribute_info attributes[attributes_count]; | |
641 // JVMSpec| } /* end ClassFile 8? | |
642 write_class_attributes(); | |
643 } | |
644 | |
645 address JvmtiClassFileReconstituter::writeable_address(size_t size) { | |
646 size_t used_size = _buffer_ptr - _buffer; | |
647 if (size + used_size >= _buffer_size) { | |
648 // compute the new buffer size: must be at least twice as big as before | |
649 // plus whatever new is being used; then convert to nice clean block boundary | |
650 size_t new_buffer_size = (size + _buffer_size*2 + 1) / initial_buffer_size | |
651 * initial_buffer_size; | |
652 | |
653 // VM goes belly-up if the memory isn't available, so cannot do OOM processing | |
654 _buffer = REALLOC_RESOURCE_ARRAY(u1, _buffer, _buffer_size, new_buffer_size); | |
655 _buffer_size = new_buffer_size; | |
656 _buffer_ptr = _buffer + used_size; | |
657 } | |
658 u1* ret_ptr = _buffer_ptr; | |
659 _buffer_ptr += size; | |
660 return ret_ptr; | |
661 } | |
662 | |
663 void JvmtiClassFileReconstituter::write_attribute_name_index(const char* name) { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
664 TempNewSymbol sym = SymbolTable::probe(name, (int)strlen(name)); |
0 | 665 assert(sym != NULL, "attribute name symbol not found"); |
666 u2 attr_name_index = symbol_to_cpool_index(sym); | |
667 assert(attr_name_index != 0, "attribute name symbol not in constant pool"); | |
668 write_u2(attr_name_index); | |
669 } | |
670 | |
671 void JvmtiClassFileReconstituter::write_u1(u1 x) { | |
672 *writeable_address(1) = x; | |
673 } | |
674 | |
675 void JvmtiClassFileReconstituter::write_u2(u2 x) { | |
676 Bytes::put_Java_u2(writeable_address(2), x); | |
677 } | |
678 | |
679 void JvmtiClassFileReconstituter::write_u4(u4 x) { | |
680 Bytes::put_Java_u4(writeable_address(4), x); | |
681 } | |
682 | |
683 void JvmtiClassFileReconstituter::write_u8(u8 x) { | |
684 Bytes::put_Java_u8(writeable_address(8), x); | |
685 } | |
686 | |
687 void JvmtiClassFileReconstituter::copy_bytecodes(methodHandle mh, | |
688 unsigned char* bytecodes) { | |
689 // use a BytecodeStream to iterate over the bytecodes. JVM/fast bytecodes | |
690 // and the breakpoint bytecode are converted to their original bytecodes. | |
691 | |
692 BytecodeStream bs(mh); | |
693 | |
694 unsigned char* p = bytecodes; | |
695 Bytecodes::Code code; | |
696 bool is_rewritten = instanceKlass::cast(mh->method_holder())->is_rewritten(); | |
697 | |
698 while ((code = bs.next()) >= 0) { | |
699 assert(Bytecodes::is_java_code(code), "sanity check"); | |
700 assert(code != Bytecodes::_breakpoint, "sanity check"); | |
701 | |
702 // length of bytecode (mnemonic + operands) | |
703 address bcp = bs.bcp(); | |
1565 | 704 int len = bs.instruction_size(); |
0 | 705 assert(len > 0, "length must be > 0"); |
706 | |
707 // copy the bytecodes | |
708 *p = (unsigned char) (bs.is_wide()? Bytecodes::_wide : code); | |
709 if (len > 1) { | |
710 memcpy(p+1, bcp+1, len-1); | |
711 } | |
712 | |
713 // During linking the get/put and invoke instructions are rewritten | |
714 // with an index into the constant pool cache. The original constant | |
715 // pool index must be returned to caller. Rewrite the index. | |
716 if (is_rewritten && len >= 3) { | |
717 switch (code) { | |
718 case Bytecodes::_getstatic : // fall through | |
719 case Bytecodes::_putstatic : // fall through | |
720 case Bytecodes::_getfield : // fall through | |
721 case Bytecodes::_putfield : // fall through | |
722 case Bytecodes::_invokevirtual : // fall through | |
723 case Bytecodes::_invokespecial : // fall through | |
724 case Bytecodes::_invokestatic : // fall through | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
725 case Bytecodes::_invokedynamic : // fall through |
0 | 726 case Bytecodes::_invokeinterface : |
5922
ff29ce866f23
7118280: The gbyc00102 JCK7 test causes an assert in JVM 7.0 fastdebug mode
dsamersoff
parents:
4718
diff
changeset
|
727 assert(len == 3 || |
ff29ce866f23
7118280: The gbyc00102 JCK7 test causes an assert in JVM 7.0 fastdebug mode
dsamersoff
parents:
4718
diff
changeset
|
728 (code == Bytecodes::_invokeinterface && len == 5) || |
ff29ce866f23
7118280: The gbyc00102 JCK7 test causes an assert in JVM 7.0 fastdebug mode
dsamersoff
parents:
4718
diff
changeset
|
729 (code == Bytecodes::_invokedynamic && len == 5), |
0 | 730 "sanity check"); |
5922
ff29ce866f23
7118280: The gbyc00102 JCK7 test causes an assert in JVM 7.0 fastdebug mode
dsamersoff
parents:
4718
diff
changeset
|
731 |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
732 int cpci = Bytes::get_native_u2(bcp+1); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
733 bool is_invokedynamic = (EnableInvokeDynamic && code == Bytecodes::_invokedynamic); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
734 if (is_invokedynamic) |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
735 cpci = Bytes::get_native_u4(bcp+1); |
0 | 736 // cache cannot be pre-fetched since some classes won't have it yet |
737 ConstantPoolCacheEntry* entry = | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
738 mh->constants()->cache()->main_entry_at(cpci); |
0 | 739 int i = entry->constant_pool_index(); |
740 assert(i < mh->constants()->length(), "sanity check"); | |
741 Bytes::put_Java_u2((address)(p+1), (u2)i); // java byte ordering | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
742 if (is_invokedynamic) *(p+3) = *(p+4) = 0; |
0 | 743 break; |
744 } | |
745 } | |
746 | |
747 p += len; | |
748 } | |
749 } |