annotate src/share/vm/prims/jvmtiClassFileReconstituter.cpp @ 4718:c01e115b095e

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