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