annotate src/share/vm/prims/jvmtiClassFileReconstituter.cpp @ 17467:55fb97c4c58d hs25-b65

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