src/share/vm/prims/jvmtiClassFileReconstituter.cpp

Tue, 17 Oct 2017 12:58:25 +0800

author
aoqi
date
Tue, 17 Oct 2017 12:58:25 +0800
changeset 7994
04ff2f6cd0eb
parent 7535
7ae4e26cb1e0
permissions
-rw-r--r--

merge

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

mercurial