135 cfs->guarantee_more(5, CHECK); // class_index, name_and_type_index, tag/access_flags
136 u2 class_index = cfs->get_u2_fast();
137 u2 name_and_type_index = cfs->get_u2_fast();
138 cp->interface_method_at_put(index, class_index, name_and_type_index);
139 }
140 break;
141 case JVM_CONSTANT_String :
142 {
143 cfs->guarantee_more(3, CHECK); // string_index, tag/access_flags
144 u2 string_index = cfs->get_u2_fast();
145 cp->string_index_at_put(index, string_index);
146 }
147 break;
148 case JVM_CONSTANT_MethodHandle :
149 case JVM_CONSTANT_MethodType :
150 if (_major_version < Verifier::INVOKEDYNAMIC_MAJOR_VERSION) {
151 classfile_parse_error(
152 "Class file version does not support constant tag %u in class file %s",
153 tag, CHECK);
154 }
155 if (!EnableMethodHandles) {
156 classfile_parse_error(
157 "This JVM does not support constant tag %u in class file %s",
158 tag, CHECK);
159 }
160 if (tag == JVM_CONSTANT_MethodHandle) {
161 cfs->guarantee_more(4, CHECK); // ref_kind, method_index, tag/access_flags
162 u1 ref_kind = cfs->get_u1_fast();
163 u2 method_index = cfs->get_u2_fast();
164 cp->method_handle_index_at_put(index, ref_kind, method_index);
165 } else if (tag == JVM_CONSTANT_MethodType) {
166 cfs->guarantee_more(3, CHECK); // signature_index, tag/access_flags
167 u2 signature_index = cfs->get_u2_fast();
168 cp->method_type_index_at_put(index, signature_index);
169 } else {
170 ShouldNotReachHere();
171 }
172 break;
173 case JVM_CONSTANT_InvokeDynamicTrans : // this tag appears only in old classfiles
174 case JVM_CONSTANT_InvokeDynamic :
175 {
243 u2 name_index = cfs->get_u2_fast();
244 u2 signature_index = cfs->get_u2_fast();
245 cp->name_and_type_at_put(index, name_index, signature_index);
246 }
247 break;
248 case JVM_CONSTANT_Utf8 :
249 {
250 cfs->guarantee_more(2, CHECK); // utf8_length
251 u2 utf8_length = cfs->get_u2_fast();
252 u1* utf8_buffer = cfs->get_u1_buffer();
253 assert(utf8_buffer != NULL, "null utf8 buffer");
254 // Got utf8 string, guarantee utf8_length+1 bytes, set stream position forward.
255 cfs->guarantee_more(utf8_length+1, CHECK); // utf8 string, tag/access_flags
256 cfs->skip_u1_fast(utf8_length);
257
258 // Before storing the symbol, make sure it's legal
259 if (_need_verify) {
260 verify_legal_utf8((unsigned char*)utf8_buffer, utf8_length, CHECK);
261 }
262
263 if (AnonymousClasses && has_cp_patch_at(index)) {
264 Handle patch = clear_cp_patch_at(index);
265 guarantee_property(java_lang_String::is_instance(patch()),
266 "Illegal utf8 patch at %d in class file %s",
267 index, CHECK);
268 char* str = java_lang_String::as_utf8_string(patch());
269 // (could use java_lang_String::as_symbol instead, but might as well batch them)
270 utf8_buffer = (u1*) str;
271 utf8_length = (int) strlen(str);
272 }
273
274 unsigned int hash;
275 Symbol* result = SymbolTable::lookup_only((char*)utf8_buffer, utf8_length, hash);
276 if (result == NULL) {
277 names[names_count] = (char*)utf8_buffer;
278 lengths[names_count] = utf8_length;
279 indices[names_count] = index;
280 hashValues[names_count++] = hash;
281 if (names_count == SymbolTable::symbol_alloc_batch_size) {
282 SymbolTable::new_symbols(cp, names_count, names, lengths, indices, hashValues, CHECK);
283 names_count = 0;
426 case JVM_CONSTANT_UnresolvedString :
427 ShouldNotReachHere(); // Only JVM_CONSTANT_StringIndex should be present
428 break;
429 case JVM_CONSTANT_StringIndex :
430 {
431 int string_index = cp->string_index_at(index);
432 check_property(
433 valid_cp_range(string_index, length) &&
434 cp->tag_at(string_index).is_utf8(),
435 "Invalid constant pool index %u in class file %s",
436 string_index, CHECK_(nullHandle));
437 Symbol* sym = cp->symbol_at(string_index);
438 cp->unresolved_string_at_put(index, sym);
439 }
440 break;
441 case JVM_CONSTANT_MethodHandle :
442 {
443 int ref_index = cp->method_handle_index_at(index);
444 check_property(
445 valid_cp_range(ref_index, length) &&
446 EnableMethodHandles,
447 "Invalid constant pool index %u in class file %s",
448 ref_index, CHECK_(nullHandle));
449 constantTag tag = cp->tag_at(ref_index);
450 int ref_kind = cp->method_handle_ref_kind_at(index);
451 switch (ref_kind) {
452 case JVM_REF_getField:
453 case JVM_REF_getStatic:
454 case JVM_REF_putField:
455 case JVM_REF_putStatic:
456 check_property(
457 tag.is_field(),
458 "Invalid constant pool index %u in class file %s (not a field)",
459 ref_index, CHECK_(nullHandle));
460 break;
461 case JVM_REF_invokeVirtual:
462 case JVM_REF_invokeStatic:
463 case JVM_REF_invokeSpecial:
464 case JVM_REF_newInvokeSpecial:
465 check_property(
466 tag.is_method(),
470 case JVM_REF_invokeInterface:
471 check_property(
472 tag.is_interface_method(),
473 "Invalid constant pool index %u in class file %s (not an interface method)",
474 ref_index, CHECK_(nullHandle));
475 break;
476 default:
477 classfile_parse_error(
478 "Bad method handle kind at constant pool index %u in class file %s",
479 index, CHECK_(nullHandle));
480 }
481 // Keep the ref_index unchanged. It will be indirected at link-time.
482 }
483 break;
484 case JVM_CONSTANT_MethodType :
485 {
486 int ref_index = cp->method_type_index_at(index);
487 check_property(
488 valid_cp_range(ref_index, length) &&
489 cp->tag_at(ref_index).is_utf8() &&
490 EnableMethodHandles,
491 "Invalid constant pool index %u in class file %s",
492 ref_index, CHECK_(nullHandle));
493 }
494 break;
495 case JVM_CONSTANT_InvokeDynamicTrans :
496 case JVM_CONSTANT_InvokeDynamic :
497 {
498 int name_and_type_ref_index = cp->invoke_dynamic_name_and_type_ref_index_at(index);
499 check_property(valid_cp_range(name_and_type_ref_index, length) &&
500 cp->tag_at(name_and_type_ref_index).is_name_and_type(),
501 "Invalid constant pool index %u in class file %s",
502 name_and_type_ref_index,
503 CHECK_(nullHandle));
504 if (tag == JVM_CONSTANT_InvokeDynamicTrans) {
505 int bootstrap_method_ref_index = cp->invoke_dynamic_bootstrap_method_ref_index_at(index);
506 check_property(valid_cp_range(bootstrap_method_ref_index, length) &&
507 cp->tag_at(bootstrap_method_ref_index).is_method_handle(),
508 "Invalid constant pool index %u in class file %s",
509 bootstrap_method_ref_index,
510 CHECK_(nullHandle));
511 }
512 // bootstrap specifier index must be checked later, when BootstrapMethods attr is available
513 break;
514 }
515 default:
516 fatal(err_msg("bad constant pool tag value %u",
517 cp->tag_at(index).value()));
518 ShouldNotReachHere();
519 break;
520 } // end of switch
521 } // end of for
522
523 if (_cp_patches != NULL) {
524 // need to treat this_class specially...
525 assert(AnonymousClasses, "");
526 int this_class_index;
527 {
528 cfs->guarantee_more(8, CHECK_(nullHandle)); // flags, this_class, super_class, infs_len
529 u1* mark = cfs->current();
530 u2 flags = cfs->get_u2_fast();
531 this_class_index = cfs->get_u2_fast();
532 cfs->set_current(mark); // revert to mark
533 }
534
535 for (index = 1; index < length; index++) { // Index 0 is unused
536 if (has_cp_patch_at(index)) {
537 guarantee_property(index != this_class_index,
538 "Illegal constant pool patch to self at %d in class file %s",
539 index, CHECK_(nullHandle));
540 patch_constant_pool(cp, index, cp_patch_at(index), CHECK_(nullHandle));
541 }
542 }
543 // Ensure that all the patches have been used.
544 for (index = 0; index < _cp_patches->length(); index++) {
545 guarantee_property(!has_cp_patch_at(index),
660 break;
661 }
662 case JVM_CONSTANT_MethodType: {
663 Symbol* no_name = vmSymbols::type_name(); // place holder
664 Symbol* signature = cp->method_type_signature_at(index);
665 verify_legal_method_signature(no_name, signature, CHECK_(nullHandle));
666 break;
667 }
668 case JVM_CONSTANT_Utf8: {
669 assert(cp->symbol_at(index)->refcount() != 0, "count corrupted");
670 }
671 } // end of switch
672 } // end of for
673
674 cp_in_error.set_in_error(false);
675 return cp;
676 }
677
678
679 void ClassFileParser::patch_constant_pool(constantPoolHandle cp, int index, Handle patch, TRAPS) {
680 assert(AnonymousClasses, "");
681 BasicType patch_type = T_VOID;
682 switch (cp->tag_at(index).value()) {
683
684 case JVM_CONSTANT_UnresolvedClass :
685 // Patching a class means pre-resolving it.
686 // The name in the constant pool is ignored.
687 if (java_lang_Class::is_instance(patch())) {
688 guarantee_property(!java_lang_Class::is_primitive(patch()),
689 "Illegal class patch at %d in class file %s",
690 index, CHECK);
691 cp->klass_at_put(index, java_lang_Class::as_klassOop(patch()));
692 } else {
693 guarantee_property(java_lang_String::is_instance(patch()),
694 "Illegal class patch at %d in class file %s",
695 index, CHECK);
696 Symbol* name = java_lang_String::as_symbol(patch(), CHECK);
697 cp->unresolved_klass_at_put(index, name);
698 }
699 break;
700
2086 *method_default_annotations = assemble_annotations(annotation_default,
2087 annotation_default_length,
2088 NULL,
2089 0,
2090 CHECK_(nullHandle));
2091
2092 if (name == vmSymbols::finalize_method_name() &&
2093 signature == vmSymbols::void_method_signature()) {
2094 if (m->is_empty_method()) {
2095 _has_empty_finalizer = true;
2096 } else {
2097 _has_finalizer = true;
2098 }
2099 }
2100 if (name == vmSymbols::object_initializer_name() &&
2101 signature == vmSymbols::void_method_signature() &&
2102 m->is_vanilla_constructor()) {
2103 _has_vanilla_constructor = true;
2104 }
2105
2106 if (EnableMethodHandles && (m->is_method_handle_invoke() ||
2107 m->is_method_handle_adapter())) {
2108 THROW_MSG_(vmSymbols::java_lang_VirtualMachineError(),
2109 "Method handle invokers must be defined internally to the VM", nullHandle);
2110 }
2111
2112 return m;
2113 }
2114
2115
2116 // The promoted_flags parameter is used to pass relevant access_flags
2117 // from the methods back up to the containing klass. These flag values
2118 // are added to klass's access_flags.
2119
2120 objArrayHandle ClassFileParser::parse_methods(constantPoolHandle cp, bool is_interface,
2121 AccessFlags* promoted_flags,
2122 bool* has_final_method,
2123 objArrayOop* methods_annotations_oop,
2124 objArrayOop* methods_parameter_annotations_oop,
2125 objArrayOop* methods_default_annotations_oop,
2126 TRAPS) {
2754 // Cause the extra fake fields in java.lang.Class to show up before
2755 // the Java fields for layout compatibility between 1.3 and 1.4
2756 // Incrementing next_nonstatic_oop_offset here advances the
2757 // location where the real java fields are placed.
2758 const int extra = java_lang_Class::number_of_fake_oop_fields;
2759 (*next_nonstatic_oop_offset_ptr) += (extra * heapOopSize);
2760 }
2761
2762
2763 // Force MethodHandle.vmentry to be an unmanaged pointer.
2764 // There is no way for a classfile to express this, so we must help it.
2765 void ClassFileParser::java_lang_invoke_MethodHandle_fix_pre(constantPoolHandle cp,
2766 typeArrayHandle fields,
2767 FieldAllocationCount *fac_ptr,
2768 TRAPS) {
2769 // Add fake fields for java.lang.invoke.MethodHandle instances
2770 //
2771 // This is not particularly nice, but since there is no way to express
2772 // a native wordSize field in Java, we must do it at this level.
2773
2774 if (!EnableMethodHandles) return;
2775
2776 int word_sig_index = 0;
2777 const int cp_size = cp->length();
2778 for (int index = 1; index < cp_size; index++) {
2779 if (cp->tag_at(index).is_utf8() &&
2780 cp->symbol_at(index) == vmSymbols::machine_word_signature()) {
2781 word_sig_index = index;
2782 break;
2783 }
2784 }
2785
2786 if (AllowTransitionalJSR292 && word_sig_index == 0) return;
2787 if (word_sig_index == 0)
2788 THROW_MSG(vmSymbols::java_lang_VirtualMachineError(),
2789 "missing I or J signature (for vmentry) in java.lang.invoke.MethodHandle");
2790
2791 // Find vmentry field and change the signature.
2792 bool found_vmentry = false;
2793 for (int i = 0; i < fields->length(); i += instanceKlass::next_offset) {
2794 int name_index = fields->ushort_at(i + instanceKlass::name_index_offset);
3174 (fac.static_double_count * BytesPerLong);
3175 next_static_short_offset = next_static_word_offset +
3176 (fac.static_word_count * BytesPerInt);
3177 next_static_byte_offset = next_static_short_offset +
3178 (fac.static_short_count * BytesPerShort);
3179 next_static_type_offset = align_size_up((next_static_byte_offset +
3180 fac.static_byte_count ), wordSize );
3181 static_field_size = (next_static_type_offset -
3182 next_static_oop_offset) / wordSize;
3183
3184 // Add fake fields for java.lang.Class instances (also see below)
3185 if (class_name == vmSymbols::java_lang_Class() && class_loader.is_null()) {
3186 java_lang_Class_fix_pre(&nonstatic_field_size, &fac);
3187 }
3188
3189 first_nonstatic_field_offset = instanceOopDesc::base_offset_in_bytes() +
3190 nonstatic_field_size * heapOopSize;
3191 next_nonstatic_field_offset = first_nonstatic_field_offset;
3192
3193 // adjust the vmentry field declaration in java.lang.invoke.MethodHandle
3194 if (EnableMethodHandles && class_name == vmSymbols::java_lang_invoke_MethodHandle() && class_loader.is_null()) {
3195 java_lang_invoke_MethodHandle_fix_pre(cp, fields, &fac, CHECK_(nullHandle));
3196 }
3197 if (AllowTransitionalJSR292 &&
3198 EnableMethodHandles && class_name == vmSymbols::java_dyn_MethodHandle() && class_loader.is_null()) {
3199 java_lang_invoke_MethodHandle_fix_pre(cp, fields, &fac, CHECK_(nullHandle));
3200 }
3201 if (AllowTransitionalJSR292 &&
3202 EnableMethodHandles && class_name == vmSymbols::sun_dyn_MethodHandleImpl() && class_loader.is_null()) {
3203 // allow vmentry field in MethodHandleImpl also
3204 java_lang_invoke_MethodHandle_fix_pre(cp, fields, &fac, CHECK_(nullHandle));
3205 }
3206
3207 // Add a fake "discovered" field if it is not present
3208 // for compatibility with earlier jdk's.
3209 if (class_name == vmSymbols::java_lang_ref_Reference()
3210 && class_loader.is_null()) {
3211 java_lang_ref_Reference_fix_pre(&fields, cp, &fac, CHECK_(nullHandle));
3212 }
3213 // end of "discovered" field compactibility fix
3214
3215 unsigned int nonstatic_double_count = fac.nonstatic_double_count;
3216 unsigned int nonstatic_word_count = fac.nonstatic_word_count;
3217 unsigned int nonstatic_short_count = fac.nonstatic_short_count;
3218 unsigned int nonstatic_byte_count = fac.nonstatic_byte_count;
3219 unsigned int nonstatic_oop_count = fac.nonstatic_oop_count;
3220
3221 bool super_has_nonstatic_fields =
3222 (super_klass() != NULL && super_klass->has_nonstatic_fields());
|
135 cfs->guarantee_more(5, CHECK); // class_index, name_and_type_index, tag/access_flags
136 u2 class_index = cfs->get_u2_fast();
137 u2 name_and_type_index = cfs->get_u2_fast();
138 cp->interface_method_at_put(index, class_index, name_and_type_index);
139 }
140 break;
141 case JVM_CONSTANT_String :
142 {
143 cfs->guarantee_more(3, CHECK); // string_index, tag/access_flags
144 u2 string_index = cfs->get_u2_fast();
145 cp->string_index_at_put(index, string_index);
146 }
147 break;
148 case JVM_CONSTANT_MethodHandle :
149 case JVM_CONSTANT_MethodType :
150 if (_major_version < Verifier::INVOKEDYNAMIC_MAJOR_VERSION) {
151 classfile_parse_error(
152 "Class file version does not support constant tag %u in class file %s",
153 tag, CHECK);
154 }
155 if (!EnableInvokeDynamic) {
156 classfile_parse_error(
157 "This JVM does not support constant tag %u in class file %s",
158 tag, CHECK);
159 }
160 if (tag == JVM_CONSTANT_MethodHandle) {
161 cfs->guarantee_more(4, CHECK); // ref_kind, method_index, tag/access_flags
162 u1 ref_kind = cfs->get_u1_fast();
163 u2 method_index = cfs->get_u2_fast();
164 cp->method_handle_index_at_put(index, ref_kind, method_index);
165 } else if (tag == JVM_CONSTANT_MethodType) {
166 cfs->guarantee_more(3, CHECK); // signature_index, tag/access_flags
167 u2 signature_index = cfs->get_u2_fast();
168 cp->method_type_index_at_put(index, signature_index);
169 } else {
170 ShouldNotReachHere();
171 }
172 break;
173 case JVM_CONSTANT_InvokeDynamicTrans : // this tag appears only in old classfiles
174 case JVM_CONSTANT_InvokeDynamic :
175 {
243 u2 name_index = cfs->get_u2_fast();
244 u2 signature_index = cfs->get_u2_fast();
245 cp->name_and_type_at_put(index, name_index, signature_index);
246 }
247 break;
248 case JVM_CONSTANT_Utf8 :
249 {
250 cfs->guarantee_more(2, CHECK); // utf8_length
251 u2 utf8_length = cfs->get_u2_fast();
252 u1* utf8_buffer = cfs->get_u1_buffer();
253 assert(utf8_buffer != NULL, "null utf8 buffer");
254 // Got utf8 string, guarantee utf8_length+1 bytes, set stream position forward.
255 cfs->guarantee_more(utf8_length+1, CHECK); // utf8 string, tag/access_flags
256 cfs->skip_u1_fast(utf8_length);
257
258 // Before storing the symbol, make sure it's legal
259 if (_need_verify) {
260 verify_legal_utf8((unsigned char*)utf8_buffer, utf8_length, CHECK);
261 }
262
263 if (EnableInvokeDynamic && has_cp_patch_at(index)) {
264 Handle patch = clear_cp_patch_at(index);
265 guarantee_property(java_lang_String::is_instance(patch()),
266 "Illegal utf8 patch at %d in class file %s",
267 index, CHECK);
268 char* str = java_lang_String::as_utf8_string(patch());
269 // (could use java_lang_String::as_symbol instead, but might as well batch them)
270 utf8_buffer = (u1*) str;
271 utf8_length = (int) strlen(str);
272 }
273
274 unsigned int hash;
275 Symbol* result = SymbolTable::lookup_only((char*)utf8_buffer, utf8_length, hash);
276 if (result == NULL) {
277 names[names_count] = (char*)utf8_buffer;
278 lengths[names_count] = utf8_length;
279 indices[names_count] = index;
280 hashValues[names_count++] = hash;
281 if (names_count == SymbolTable::symbol_alloc_batch_size) {
282 SymbolTable::new_symbols(cp, names_count, names, lengths, indices, hashValues, CHECK);
283 names_count = 0;
426 case JVM_CONSTANT_UnresolvedString :
427 ShouldNotReachHere(); // Only JVM_CONSTANT_StringIndex should be present
428 break;
429 case JVM_CONSTANT_StringIndex :
430 {
431 int string_index = cp->string_index_at(index);
432 check_property(
433 valid_cp_range(string_index, length) &&
434 cp->tag_at(string_index).is_utf8(),
435 "Invalid constant pool index %u in class file %s",
436 string_index, CHECK_(nullHandle));
437 Symbol* sym = cp->symbol_at(string_index);
438 cp->unresolved_string_at_put(index, sym);
439 }
440 break;
441 case JVM_CONSTANT_MethodHandle :
442 {
443 int ref_index = cp->method_handle_index_at(index);
444 check_property(
445 valid_cp_range(ref_index, length) &&
446 EnableInvokeDynamic,
447 "Invalid constant pool index %u in class file %s",
448 ref_index, CHECK_(nullHandle));
449 constantTag tag = cp->tag_at(ref_index);
450 int ref_kind = cp->method_handle_ref_kind_at(index);
451 switch (ref_kind) {
452 case JVM_REF_getField:
453 case JVM_REF_getStatic:
454 case JVM_REF_putField:
455 case JVM_REF_putStatic:
456 check_property(
457 tag.is_field(),
458 "Invalid constant pool index %u in class file %s (not a field)",
459 ref_index, CHECK_(nullHandle));
460 break;
461 case JVM_REF_invokeVirtual:
462 case JVM_REF_invokeStatic:
463 case JVM_REF_invokeSpecial:
464 case JVM_REF_newInvokeSpecial:
465 check_property(
466 tag.is_method(),
470 case JVM_REF_invokeInterface:
471 check_property(
472 tag.is_interface_method(),
473 "Invalid constant pool index %u in class file %s (not an interface method)",
474 ref_index, CHECK_(nullHandle));
475 break;
476 default:
477 classfile_parse_error(
478 "Bad method handle kind at constant pool index %u in class file %s",
479 index, CHECK_(nullHandle));
480 }
481 // Keep the ref_index unchanged. It will be indirected at link-time.
482 }
483 break;
484 case JVM_CONSTANT_MethodType :
485 {
486 int ref_index = cp->method_type_index_at(index);
487 check_property(
488 valid_cp_range(ref_index, length) &&
489 cp->tag_at(ref_index).is_utf8() &&
490 EnableInvokeDynamic,
491 "Invalid constant pool index %u in class file %s",
492 ref_index, CHECK_(nullHandle));
493 }
494 break;
495 case JVM_CONSTANT_InvokeDynamicTrans :
496 case JVM_CONSTANT_InvokeDynamic :
497 {
498 int name_and_type_ref_index = cp->invoke_dynamic_name_and_type_ref_index_at(index);
499 check_property(valid_cp_range(name_and_type_ref_index, length) &&
500 cp->tag_at(name_and_type_ref_index).is_name_and_type(),
501 "Invalid constant pool index %u in class file %s",
502 name_and_type_ref_index,
503 CHECK_(nullHandle));
504 if (tag == JVM_CONSTANT_InvokeDynamicTrans) {
505 int bootstrap_method_ref_index = cp->invoke_dynamic_bootstrap_method_ref_index_at(index);
506 check_property(valid_cp_range(bootstrap_method_ref_index, length) &&
507 cp->tag_at(bootstrap_method_ref_index).is_method_handle(),
508 "Invalid constant pool index %u in class file %s",
509 bootstrap_method_ref_index,
510 CHECK_(nullHandle));
511 }
512 // bootstrap specifier index must be checked later, when BootstrapMethods attr is available
513 break;
514 }
515 default:
516 fatal(err_msg("bad constant pool tag value %u",
517 cp->tag_at(index).value()));
518 ShouldNotReachHere();
519 break;
520 } // end of switch
521 } // end of for
522
523 if (_cp_patches != NULL) {
524 // need to treat this_class specially...
525 assert(EnableInvokeDynamic, "");
526 int this_class_index;
527 {
528 cfs->guarantee_more(8, CHECK_(nullHandle)); // flags, this_class, super_class, infs_len
529 u1* mark = cfs->current();
530 u2 flags = cfs->get_u2_fast();
531 this_class_index = cfs->get_u2_fast();
532 cfs->set_current(mark); // revert to mark
533 }
534
535 for (index = 1; index < length; index++) { // Index 0 is unused
536 if (has_cp_patch_at(index)) {
537 guarantee_property(index != this_class_index,
538 "Illegal constant pool patch to self at %d in class file %s",
539 index, CHECK_(nullHandle));
540 patch_constant_pool(cp, index, cp_patch_at(index), CHECK_(nullHandle));
541 }
542 }
543 // Ensure that all the patches have been used.
544 for (index = 0; index < _cp_patches->length(); index++) {
545 guarantee_property(!has_cp_patch_at(index),
660 break;
661 }
662 case JVM_CONSTANT_MethodType: {
663 Symbol* no_name = vmSymbols::type_name(); // place holder
664 Symbol* signature = cp->method_type_signature_at(index);
665 verify_legal_method_signature(no_name, signature, CHECK_(nullHandle));
666 break;
667 }
668 case JVM_CONSTANT_Utf8: {
669 assert(cp->symbol_at(index)->refcount() != 0, "count corrupted");
670 }
671 } // end of switch
672 } // end of for
673
674 cp_in_error.set_in_error(false);
675 return cp;
676 }
677
678
679 void ClassFileParser::patch_constant_pool(constantPoolHandle cp, int index, Handle patch, TRAPS) {
680 assert(EnableInvokeDynamic, "");
681 BasicType patch_type = T_VOID;
682 switch (cp->tag_at(index).value()) {
683
684 case JVM_CONSTANT_UnresolvedClass :
685 // Patching a class means pre-resolving it.
686 // The name in the constant pool is ignored.
687 if (java_lang_Class::is_instance(patch())) {
688 guarantee_property(!java_lang_Class::is_primitive(patch()),
689 "Illegal class patch at %d in class file %s",
690 index, CHECK);
691 cp->klass_at_put(index, java_lang_Class::as_klassOop(patch()));
692 } else {
693 guarantee_property(java_lang_String::is_instance(patch()),
694 "Illegal class patch at %d in class file %s",
695 index, CHECK);
696 Symbol* name = java_lang_String::as_symbol(patch(), CHECK);
697 cp->unresolved_klass_at_put(index, name);
698 }
699 break;
700
2086 *method_default_annotations = assemble_annotations(annotation_default,
2087 annotation_default_length,
2088 NULL,
2089 0,
2090 CHECK_(nullHandle));
2091
2092 if (name == vmSymbols::finalize_method_name() &&
2093 signature == vmSymbols::void_method_signature()) {
2094 if (m->is_empty_method()) {
2095 _has_empty_finalizer = true;
2096 } else {
2097 _has_finalizer = true;
2098 }
2099 }
2100 if (name == vmSymbols::object_initializer_name() &&
2101 signature == vmSymbols::void_method_signature() &&
2102 m->is_vanilla_constructor()) {
2103 _has_vanilla_constructor = true;
2104 }
2105
2106 if (EnableInvokeDynamic && (m->is_method_handle_invoke() ||
2107 m->is_method_handle_adapter())) {
2108 THROW_MSG_(vmSymbols::java_lang_VirtualMachineError(),
2109 "Method handle invokers must be defined internally to the VM", nullHandle);
2110 }
2111
2112 return m;
2113 }
2114
2115
2116 // The promoted_flags parameter is used to pass relevant access_flags
2117 // from the methods back up to the containing klass. These flag values
2118 // are added to klass's access_flags.
2119
2120 objArrayHandle ClassFileParser::parse_methods(constantPoolHandle cp, bool is_interface,
2121 AccessFlags* promoted_flags,
2122 bool* has_final_method,
2123 objArrayOop* methods_annotations_oop,
2124 objArrayOop* methods_parameter_annotations_oop,
2125 objArrayOop* methods_default_annotations_oop,
2126 TRAPS) {
2754 // Cause the extra fake fields in java.lang.Class to show up before
2755 // the Java fields for layout compatibility between 1.3 and 1.4
2756 // Incrementing next_nonstatic_oop_offset here advances the
2757 // location where the real java fields are placed.
2758 const int extra = java_lang_Class::number_of_fake_oop_fields;
2759 (*next_nonstatic_oop_offset_ptr) += (extra * heapOopSize);
2760 }
2761
2762
2763 // Force MethodHandle.vmentry to be an unmanaged pointer.
2764 // There is no way for a classfile to express this, so we must help it.
2765 void ClassFileParser::java_lang_invoke_MethodHandle_fix_pre(constantPoolHandle cp,
2766 typeArrayHandle fields,
2767 FieldAllocationCount *fac_ptr,
2768 TRAPS) {
2769 // Add fake fields for java.lang.invoke.MethodHandle instances
2770 //
2771 // This is not particularly nice, but since there is no way to express
2772 // a native wordSize field in Java, we must do it at this level.
2773
2774 if (!EnableInvokeDynamic) return;
2775
2776 int word_sig_index = 0;
2777 const int cp_size = cp->length();
2778 for (int index = 1; index < cp_size; index++) {
2779 if (cp->tag_at(index).is_utf8() &&
2780 cp->symbol_at(index) == vmSymbols::machine_word_signature()) {
2781 word_sig_index = index;
2782 break;
2783 }
2784 }
2785
2786 if (AllowTransitionalJSR292 && word_sig_index == 0) return;
2787 if (word_sig_index == 0)
2788 THROW_MSG(vmSymbols::java_lang_VirtualMachineError(),
2789 "missing I or J signature (for vmentry) in java.lang.invoke.MethodHandle");
2790
2791 // Find vmentry field and change the signature.
2792 bool found_vmentry = false;
2793 for (int i = 0; i < fields->length(); i += instanceKlass::next_offset) {
2794 int name_index = fields->ushort_at(i + instanceKlass::name_index_offset);
3174 (fac.static_double_count * BytesPerLong);
3175 next_static_short_offset = next_static_word_offset +
3176 (fac.static_word_count * BytesPerInt);
3177 next_static_byte_offset = next_static_short_offset +
3178 (fac.static_short_count * BytesPerShort);
3179 next_static_type_offset = align_size_up((next_static_byte_offset +
3180 fac.static_byte_count ), wordSize );
3181 static_field_size = (next_static_type_offset -
3182 next_static_oop_offset) / wordSize;
3183
3184 // Add fake fields for java.lang.Class instances (also see below)
3185 if (class_name == vmSymbols::java_lang_Class() && class_loader.is_null()) {
3186 java_lang_Class_fix_pre(&nonstatic_field_size, &fac);
3187 }
3188
3189 first_nonstatic_field_offset = instanceOopDesc::base_offset_in_bytes() +
3190 nonstatic_field_size * heapOopSize;
3191 next_nonstatic_field_offset = first_nonstatic_field_offset;
3192
3193 // adjust the vmentry field declaration in java.lang.invoke.MethodHandle
3194 if (EnableInvokeDynamic && class_name == vmSymbols::java_lang_invoke_MethodHandle() && class_loader.is_null()) {
3195 java_lang_invoke_MethodHandle_fix_pre(cp, fields, &fac, CHECK_(nullHandle));
3196 }
3197 if (AllowTransitionalJSR292 &&
3198 EnableInvokeDynamic && class_name == vmSymbols::java_dyn_MethodHandle() && class_loader.is_null()) {
3199 java_lang_invoke_MethodHandle_fix_pre(cp, fields, &fac, CHECK_(nullHandle));
3200 }
3201 if (AllowTransitionalJSR292 &&
3202 EnableInvokeDynamic && class_name == vmSymbols::sun_dyn_MethodHandleImpl() && class_loader.is_null()) {
3203 // allow vmentry field in MethodHandleImpl also
3204 java_lang_invoke_MethodHandle_fix_pre(cp, fields, &fac, CHECK_(nullHandle));
3205 }
3206
3207 // Add a fake "discovered" field if it is not present
3208 // for compatibility with earlier jdk's.
3209 if (class_name == vmSymbols::java_lang_ref_Reference()
3210 && class_loader.is_null()) {
3211 java_lang_ref_Reference_fix_pre(&fields, cp, &fac, CHECK_(nullHandle));
3212 }
3213 // end of "discovered" field compactibility fix
3214
3215 unsigned int nonstatic_double_count = fac.nonstatic_double_count;
3216 unsigned int nonstatic_word_count = fac.nonstatic_word_count;
3217 unsigned int nonstatic_short_count = fac.nonstatic_short_count;
3218 unsigned int nonstatic_byte_count = fac.nonstatic_byte_count;
3219 unsigned int nonstatic_oop_count = fac.nonstatic_oop_count;
3220
3221 bool super_has_nonstatic_fields =
3222 (super_klass() != NULL && super_klass->has_nonstatic_fields());
|