comparison src/share/vm/classfile/classFileParser.cpp @ 2416:38fea01eb669

6817525: turn on method handle functionality by default for JSR 292 Summary: After appropriate testing, we need to turn on EnableMethodHandles and EnableInvokeDynamic by default. Reviewed-by: never, kvn, jrose, phh
author twisti
date Thu, 31 Mar 2011 02:31:57 -0700
parents c7f3d0b4570f
children ed69575596ac
comparison
equal deleted inserted replaced
2415:09f96c3ff1ad 2416:38fea01eb669
150 if (_major_version < Verifier::INVOKEDYNAMIC_MAJOR_VERSION) { 150 if (_major_version < Verifier::INVOKEDYNAMIC_MAJOR_VERSION) {
151 classfile_parse_error( 151 classfile_parse_error(
152 "Class file version does not support constant tag %u in class file %s", 152 "Class file version does not support constant tag %u in class file %s",
153 tag, CHECK); 153 tag, CHECK);
154 } 154 }
155 if (!EnableMethodHandles) { 155 if (!EnableInvokeDynamic) {
156 classfile_parse_error( 156 classfile_parse_error(
157 "This JVM does not support constant tag %u in class file %s", 157 "This JVM does not support constant tag %u in class file %s",
158 tag, CHECK); 158 tag, CHECK);
159 } 159 }
160 if (tag == JVM_CONSTANT_MethodHandle) { 160 if (tag == JVM_CONSTANT_MethodHandle) {
258 // Before storing the symbol, make sure it's legal 258 // Before storing the symbol, make sure it's legal
259 if (_need_verify) { 259 if (_need_verify) {
260 verify_legal_utf8((unsigned char*)utf8_buffer, utf8_length, CHECK); 260 verify_legal_utf8((unsigned char*)utf8_buffer, utf8_length, CHECK);
261 } 261 }
262 262
263 if (AnonymousClasses && has_cp_patch_at(index)) { 263 if (EnableInvokeDynamic && has_cp_patch_at(index)) {
264 Handle patch = clear_cp_patch_at(index); 264 Handle patch = clear_cp_patch_at(index);
265 guarantee_property(java_lang_String::is_instance(patch()), 265 guarantee_property(java_lang_String::is_instance(patch()),
266 "Illegal utf8 patch at %d in class file %s", 266 "Illegal utf8 patch at %d in class file %s",
267 index, CHECK); 267 index, CHECK);
268 char* str = java_lang_String::as_utf8_string(patch()); 268 char* str = java_lang_String::as_utf8_string(patch());
441 case JVM_CONSTANT_MethodHandle : 441 case JVM_CONSTANT_MethodHandle :
442 { 442 {
443 int ref_index = cp->method_handle_index_at(index); 443 int ref_index = cp->method_handle_index_at(index);
444 check_property( 444 check_property(
445 valid_cp_range(ref_index, length) && 445 valid_cp_range(ref_index, length) &&
446 EnableMethodHandles, 446 EnableInvokeDynamic,
447 "Invalid constant pool index %u in class file %s", 447 "Invalid constant pool index %u in class file %s",
448 ref_index, CHECK_(nullHandle)); 448 ref_index, CHECK_(nullHandle));
449 constantTag tag = cp->tag_at(ref_index); 449 constantTag tag = cp->tag_at(ref_index);
450 int ref_kind = cp->method_handle_ref_kind_at(index); 450 int ref_kind = cp->method_handle_ref_kind_at(index);
451 switch (ref_kind) { 451 switch (ref_kind) {
485 { 485 {
486 int ref_index = cp->method_type_index_at(index); 486 int ref_index = cp->method_type_index_at(index);
487 check_property( 487 check_property(
488 valid_cp_range(ref_index, length) && 488 valid_cp_range(ref_index, length) &&
489 cp->tag_at(ref_index).is_utf8() && 489 cp->tag_at(ref_index).is_utf8() &&
490 EnableMethodHandles, 490 EnableInvokeDynamic,
491 "Invalid constant pool index %u in class file %s", 491 "Invalid constant pool index %u in class file %s",
492 ref_index, CHECK_(nullHandle)); 492 ref_index, CHECK_(nullHandle));
493 } 493 }
494 break; 494 break;
495 case JVM_CONSTANT_InvokeDynamicTrans : 495 case JVM_CONSTANT_InvokeDynamicTrans :
520 } // end of switch 520 } // end of switch
521 } // end of for 521 } // end of for
522 522
523 if (_cp_patches != NULL) { 523 if (_cp_patches != NULL) {
524 // need to treat this_class specially... 524 // need to treat this_class specially...
525 assert(AnonymousClasses, ""); 525 assert(EnableInvokeDynamic, "");
526 int this_class_index; 526 int this_class_index;
527 { 527 {
528 cfs->guarantee_more(8, CHECK_(nullHandle)); // flags, this_class, super_class, infs_len 528 cfs->guarantee_more(8, CHECK_(nullHandle)); // flags, this_class, super_class, infs_len
529 u1* mark = cfs->current(); 529 u1* mark = cfs->current();
530 u2 flags = cfs->get_u2_fast(); 530 u2 flags = cfs->get_u2_fast();
675 return cp; 675 return cp;
676 } 676 }
677 677
678 678
679 void ClassFileParser::patch_constant_pool(constantPoolHandle cp, int index, Handle patch, TRAPS) { 679 void ClassFileParser::patch_constant_pool(constantPoolHandle cp, int index, Handle patch, TRAPS) {
680 assert(AnonymousClasses, ""); 680 assert(EnableInvokeDynamic, "");
681 BasicType patch_type = T_VOID; 681 BasicType patch_type = T_VOID;
682 switch (cp->tag_at(index).value()) { 682 switch (cp->tag_at(index).value()) {
683 683
684 case JVM_CONSTANT_UnresolvedClass : 684 case JVM_CONSTANT_UnresolvedClass :
685 // Patching a class means pre-resolving it. 685 // Patching a class means pre-resolving it.
2101 signature == vmSymbols::void_method_signature() && 2101 signature == vmSymbols::void_method_signature() &&
2102 m->is_vanilla_constructor()) { 2102 m->is_vanilla_constructor()) {
2103 _has_vanilla_constructor = true; 2103 _has_vanilla_constructor = true;
2104 } 2104 }
2105 2105
2106 if (EnableMethodHandles && (m->is_method_handle_invoke() || 2106 if (EnableInvokeDynamic && (m->is_method_handle_invoke() ||
2107 m->is_method_handle_adapter())) { 2107 m->is_method_handle_adapter())) {
2108 THROW_MSG_(vmSymbols::java_lang_VirtualMachineError(), 2108 THROW_MSG_(vmSymbols::java_lang_VirtualMachineError(),
2109 "Method handle invokers must be defined internally to the VM", nullHandle); 2109 "Method handle invokers must be defined internally to the VM", nullHandle);
2110 } 2110 }
2111 2111
2769 // Add fake fields for java.lang.invoke.MethodHandle instances 2769 // Add fake fields for java.lang.invoke.MethodHandle instances
2770 // 2770 //
2771 // This is not particularly nice, but since there is no way to express 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. 2772 // a native wordSize field in Java, we must do it at this level.
2773 2773
2774 if (!EnableMethodHandles) return; 2774 if (!EnableInvokeDynamic) return;
2775 2775
2776 int word_sig_index = 0; 2776 int word_sig_index = 0;
2777 const int cp_size = cp->length(); 2777 const int cp_size = cp->length();
2778 for (int index = 1; index < cp_size; index++) { 2778 for (int index = 1; index < cp_size; index++) {
2779 if (cp->tag_at(index).is_utf8() && 2779 if (cp->tag_at(index).is_utf8() &&
3189 first_nonstatic_field_offset = instanceOopDesc::base_offset_in_bytes() + 3189 first_nonstatic_field_offset = instanceOopDesc::base_offset_in_bytes() +
3190 nonstatic_field_size * heapOopSize; 3190 nonstatic_field_size * heapOopSize;
3191 next_nonstatic_field_offset = first_nonstatic_field_offset; 3191 next_nonstatic_field_offset = first_nonstatic_field_offset;
3192 3192
3193 // adjust the vmentry field declaration in java.lang.invoke.MethodHandle 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()) { 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)); 3195 java_lang_invoke_MethodHandle_fix_pre(cp, fields, &fac, CHECK_(nullHandle));
3196 } 3196 }
3197 if (AllowTransitionalJSR292 && 3197 if (AllowTransitionalJSR292 &&
3198 EnableMethodHandles && class_name == vmSymbols::java_dyn_MethodHandle() && class_loader.is_null()) { 3198 EnableInvokeDynamic && class_name == vmSymbols::java_dyn_MethodHandle() && class_loader.is_null()) {
3199 java_lang_invoke_MethodHandle_fix_pre(cp, fields, &fac, CHECK_(nullHandle)); 3199 java_lang_invoke_MethodHandle_fix_pre(cp, fields, &fac, CHECK_(nullHandle));
3200 } 3200 }
3201 if (AllowTransitionalJSR292 && 3201 if (AllowTransitionalJSR292 &&
3202 EnableMethodHandles && class_name == vmSymbols::sun_dyn_MethodHandleImpl() && class_loader.is_null()) { 3202 EnableInvokeDynamic && class_name == vmSymbols::sun_dyn_MethodHandleImpl() && class_loader.is_null()) {
3203 // allow vmentry field in MethodHandleImpl also 3203 // allow vmentry field in MethodHandleImpl also
3204 java_lang_invoke_MethodHandle_fix_pre(cp, fields, &fac, CHECK_(nullHandle)); 3204 java_lang_invoke_MethodHandle_fix_pre(cp, fields, &fac, CHECK_(nullHandle));
3205 } 3205 }
3206 3206
3207 // Add a fake "discovered" field if it is not present 3207 // Add a fake "discovered" field if it is not present