Mercurial > hg > graal-jvmci-8
comparison src/share/vm/classfile/classFileParser.cpp @ 2376:c7f3d0b4570f
7017732: move static fields into Class to prepare for perm gen removal
Reviewed-by: kvn, coleenp, twisti, stefank
author | never |
---|---|
date | Fri, 18 Mar 2011 16:00:34 -0700 |
parents | 8033953d67ff |
children | 38fea01eb669 |
comparison
equal
deleted
inserted
replaced
2375:d673ef06fe96 | 2376:c7f3d0b4570f |
---|---|
35 #include "memory/gcLocker.hpp" | 35 #include "memory/gcLocker.hpp" |
36 #include "memory/oopFactory.hpp" | 36 #include "memory/oopFactory.hpp" |
37 #include "memory/universe.inline.hpp" | 37 #include "memory/universe.inline.hpp" |
38 #include "oops/constantPoolOop.hpp" | 38 #include "oops/constantPoolOop.hpp" |
39 #include "oops/instanceKlass.hpp" | 39 #include "oops/instanceKlass.hpp" |
40 #include "oops/instanceMirrorKlass.hpp" | |
40 #include "oops/klass.inline.hpp" | 41 #include "oops/klass.inline.hpp" |
41 #include "oops/klassOop.hpp" | 42 #include "oops/klassOop.hpp" |
42 #include "oops/klassVtable.hpp" | 43 #include "oops/klassVtable.hpp" |
43 #include "oops/methodOop.hpp" | 44 #include "oops/methodOop.hpp" |
44 #include "oops/symbol.hpp" | 45 #include "oops/symbol.hpp" |
2604 } | 2605 } |
2605 return annotations; | 2606 return annotations; |
2606 } | 2607 } |
2607 | 2608 |
2608 | 2609 |
2609 static void initialize_static_field(fieldDescriptor* fd, TRAPS) { | |
2610 KlassHandle h_k (THREAD, fd->field_holder()); | |
2611 assert(h_k.not_null() && fd->is_static(), "just checking"); | |
2612 if (fd->has_initial_value()) { | |
2613 BasicType t = fd->field_type(); | |
2614 switch (t) { | |
2615 case T_BYTE: | |
2616 h_k()->byte_field_put(fd->offset(), fd->int_initial_value()); | |
2617 break; | |
2618 case T_BOOLEAN: | |
2619 h_k()->bool_field_put(fd->offset(), fd->int_initial_value()); | |
2620 break; | |
2621 case T_CHAR: | |
2622 h_k()->char_field_put(fd->offset(), fd->int_initial_value()); | |
2623 break; | |
2624 case T_SHORT: | |
2625 h_k()->short_field_put(fd->offset(), fd->int_initial_value()); | |
2626 break; | |
2627 case T_INT: | |
2628 h_k()->int_field_put(fd->offset(), fd->int_initial_value()); | |
2629 break; | |
2630 case T_FLOAT: | |
2631 h_k()->float_field_put(fd->offset(), fd->float_initial_value()); | |
2632 break; | |
2633 case T_DOUBLE: | |
2634 h_k()->double_field_put(fd->offset(), fd->double_initial_value()); | |
2635 break; | |
2636 case T_LONG: | |
2637 h_k()->long_field_put(fd->offset(), fd->long_initial_value()); | |
2638 break; | |
2639 case T_OBJECT: | |
2640 { | |
2641 #ifdef ASSERT | |
2642 TempNewSymbol sym = SymbolTable::new_symbol("Ljava/lang/String;", CHECK); | |
2643 assert(fd->signature() == sym, "just checking"); | |
2644 #endif | |
2645 oop string = fd->string_initial_value(CHECK); | |
2646 h_k()->obj_field_put(fd->offset(), string); | |
2647 } | |
2648 break; | |
2649 default: | |
2650 THROW_MSG(vmSymbols::java_lang_ClassFormatError(), | |
2651 "Illegal ConstantValue attribute in class file"); | |
2652 } | |
2653 } | |
2654 } | |
2655 | |
2656 | |
2657 void ClassFileParser::java_lang_ref_Reference_fix_pre(typeArrayHandle* fields_ptr, | 2610 void ClassFileParser::java_lang_ref_Reference_fix_pre(typeArrayHandle* fields_ptr, |
2658 constantPoolHandle cp, FieldAllocationCount *fac_ptr, TRAPS) { | 2611 constantPoolHandle cp, FieldAllocationCount *fac_ptr, TRAPS) { |
2659 // This code is for compatibility with earlier jdk's that do not | 2612 // This code is for compatibility with earlier jdk's that do not |
2660 // have the "discovered" field in java.lang.ref.Reference. For 1.5 | 2613 // have the "discovered" field in java.lang.ref.Reference. For 1.5 |
2661 // the check for the "discovered" field should issue a warning if | 2614 // the check for the "discovered" field should issue a warning if |
2767 } | 2720 } |
2768 return; | 2721 return; |
2769 } | 2722 } |
2770 | 2723 |
2771 | 2724 |
2772 void ClassFileParser::java_lang_Class_fix_pre(objArrayHandle* methods_ptr, | 2725 void ClassFileParser::java_lang_Class_fix_pre(int* nonstatic_field_size, |
2773 FieldAllocationCount *fac_ptr, TRAPS) { | 2726 FieldAllocationCount *fac_ptr) { |
2774 // Add fake fields for java.lang.Class instances | 2727 // Add fake fields for java.lang.Class instances |
2775 // | 2728 // |
2776 // This is not particularly nice. We should consider adding a | 2729 // This is not particularly nice. We should consider adding a |
2777 // private transient object field at the Java level to | 2730 // private transient object field at the Java level to |
2778 // java.lang.Class. Alternatively we could add a subclass of | 2731 // java.lang.Class. Alternatively we could add a subclass of |
2785 // nonstatic oop fields were added at the Java level. The offsets | 2738 // nonstatic oop fields were added at the Java level. The offsets |
2786 // of these fake fields can't change between these two JDK | 2739 // of these fake fields can't change between these two JDK |
2787 // versions because when the offsets are computed at bootstrap | 2740 // versions because when the offsets are computed at bootstrap |
2788 // time we don't know yet which version of the JDK we're running in. | 2741 // time we don't know yet which version of the JDK we're running in. |
2789 | 2742 |
2790 // The values below are fake but will force two non-static oop fields and | 2743 // The values below are fake but will force three non-static oop fields and |
2791 // a corresponding non-static oop map block to be allocated. | 2744 // a corresponding non-static oop map block to be allocated. |
2792 const int extra = java_lang_Class::number_of_fake_oop_fields; | 2745 const int extra = java_lang_Class::number_of_fake_oop_fields; |
2793 fac_ptr->nonstatic_oop_count += extra; | 2746 fac_ptr->nonstatic_oop_count += extra; |
2747 | |
2748 // Reserve some leading space for fake ints | |
2749 *nonstatic_field_size += align_size_up(java_lang_Class::hc_number_of_fake_int_fields * BytesPerInt, heapOopSize) / heapOopSize; | |
2794 } | 2750 } |
2795 | 2751 |
2796 | 2752 |
2797 void ClassFileParser::java_lang_Class_fix_post(int* next_nonstatic_oop_offset_ptr) { | 2753 void ClassFileParser::java_lang_Class_fix_post(int* next_nonstatic_oop_offset_ptr) { |
2798 // Cause the extra fake fields in java.lang.Class to show up before | 2754 // Cause the extra fake fields in java.lang.Class to show up before |
3203 int first_nonstatic_oop_offset; | 3159 int first_nonstatic_oop_offset; |
3204 int first_nonstatic_field_offset; | 3160 int first_nonstatic_field_offset; |
3205 int next_nonstatic_field_offset; | 3161 int next_nonstatic_field_offset; |
3206 | 3162 |
3207 // Calculate the starting byte offsets | 3163 // Calculate the starting byte offsets |
3208 next_static_oop_offset = (instanceKlass::header_size() + | 3164 next_static_oop_offset = instanceMirrorKlass::offset_of_static_fields(); |
3209 align_object_offset(vtable_size) + | |
3210 align_object_offset(itable_size)) * wordSize; | |
3211 next_static_double_offset = next_static_oop_offset + | 3165 next_static_double_offset = next_static_oop_offset + |
3212 (fac.static_oop_count * heapOopSize); | 3166 (fac.static_oop_count * heapOopSize); |
3213 if ( fac.static_double_count && | 3167 if ( fac.static_double_count && |
3214 (Universe::field_type_should_be_aligned(T_DOUBLE) || | 3168 (Universe::field_type_should_be_aligned(T_DOUBLE) || |
3215 Universe::field_type_should_be_aligned(T_LONG)) ) { | 3169 Universe::field_type_should_be_aligned(T_LONG)) ) { |
3224 (fac.static_short_count * BytesPerShort); | 3178 (fac.static_short_count * BytesPerShort); |
3225 next_static_type_offset = align_size_up((next_static_byte_offset + | 3179 next_static_type_offset = align_size_up((next_static_byte_offset + |
3226 fac.static_byte_count ), wordSize ); | 3180 fac.static_byte_count ), wordSize ); |
3227 static_field_size = (next_static_type_offset - | 3181 static_field_size = (next_static_type_offset - |
3228 next_static_oop_offset) / wordSize; | 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 | |
3229 first_nonstatic_field_offset = instanceOopDesc::base_offset_in_bytes() + | 3189 first_nonstatic_field_offset = instanceOopDesc::base_offset_in_bytes() + |
3230 nonstatic_field_size * heapOopSize; | 3190 nonstatic_field_size * heapOopSize; |
3231 next_nonstatic_field_offset = first_nonstatic_field_offset; | 3191 next_nonstatic_field_offset = first_nonstatic_field_offset; |
3232 | |
3233 // Add fake fields for java.lang.Class instances (also see below) | |
3234 if (class_name == vmSymbols::java_lang_Class() && class_loader.is_null()) { | |
3235 java_lang_Class_fix_pre(&methods, &fac, CHECK_(nullHandle)); | |
3236 } | |
3237 | 3192 |
3238 // adjust the vmentry field declaration in java.lang.invoke.MethodHandle | 3193 // adjust the vmentry field declaration in java.lang.invoke.MethodHandle |
3239 if (EnableMethodHandles && class_name == vmSymbols::java_lang_invoke_MethodHandle() && class_loader.is_null()) { | 3194 if (EnableMethodHandles && class_name == vmSymbols::java_lang_invoke_MethodHandle() && class_loader.is_null()) { |
3240 java_lang_invoke_MethodHandle_fix_pre(cp, fields, &fac, CHECK_(nullHandle)); | 3195 java_lang_invoke_MethodHandle_fix_pre(cp, fields, &fac, CHECK_(nullHandle)); |
3241 } | 3196 } |
3564 } else { | 3519 } else { |
3565 rt = super_klass->reference_type(); | 3520 rt = super_klass->reference_type(); |
3566 } | 3521 } |
3567 | 3522 |
3568 // We can now create the basic klassOop for this klass | 3523 // We can now create the basic klassOop for this klass |
3569 klassOop ik = oopFactory::new_instanceKlass(vtable_size, itable_size, | 3524 klassOop ik = oopFactory::new_instanceKlass(name, vtable_size, itable_size, |
3570 static_field_size, | 3525 static_field_size, |
3571 total_oop_map_count, | 3526 total_oop_map_count, |
3572 rt, CHECK_(nullHandle)); | 3527 rt, CHECK_(nullHandle)); |
3573 instanceKlassHandle this_klass (THREAD, ik); | 3528 instanceKlassHandle this_klass (THREAD, ik); |
3574 | 3529 |
3586 // Not yet: supers are done below to support the new subtype-checking fields | 3541 // Not yet: supers are done below to support the new subtype-checking fields |
3587 //this_klass->set_super(super_klass()); | 3542 //this_klass->set_super(super_klass()); |
3588 this_klass->set_class_loader(class_loader()); | 3543 this_klass->set_class_loader(class_loader()); |
3589 this_klass->set_nonstatic_field_size(nonstatic_field_size); | 3544 this_klass->set_nonstatic_field_size(nonstatic_field_size); |
3590 this_klass->set_has_nonstatic_fields(has_nonstatic_fields); | 3545 this_klass->set_has_nonstatic_fields(has_nonstatic_fields); |
3591 this_klass->set_static_oop_field_size(fac.static_oop_count); | 3546 this_klass->set_static_oop_field_count(fac.static_oop_count); |
3592 cp->set_pool_holder(this_klass()); | 3547 cp->set_pool_holder(this_klass()); |
3593 error_handler.set_in_error(false); // turn off error handler for cp | 3548 error_handler.set_in_error(false); // turn off error handler for cp |
3594 this_klass->set_constants(cp()); | 3549 this_klass->set_constants(cp()); |
3595 this_klass->set_local_interfaces(local_interfaces()); | 3550 this_klass->set_local_interfaces(local_interfaces()); |
3596 this_klass->set_fields(fields()); | 3551 this_klass->set_fields(fields()); |
3647 parse_classfile_attributes(cp, this_klass, CHECK_(nullHandle)); | 3602 parse_classfile_attributes(cp, this_klass, CHECK_(nullHandle)); |
3648 | 3603 |
3649 // Make sure this is the end of class file stream | 3604 // Make sure this is the end of class file stream |
3650 guarantee_property(cfs->at_eos(), "Extra bytes at the end of class file %s", CHECK_(nullHandle)); | 3605 guarantee_property(cfs->at_eos(), "Extra bytes at the end of class file %s", CHECK_(nullHandle)); |
3651 | 3606 |
3652 // Initialize static fields | |
3653 this_klass->do_local_static_fields(&initialize_static_field, CHECK_(nullHandle)); | |
3654 | |
3655 // VerifyOops believes that once this has been set, the object is completely loaded. | 3607 // VerifyOops believes that once this has been set, the object is completely loaded. |
3656 // Compute transitive closure of interfaces this class implements | 3608 // Compute transitive closure of interfaces this class implements |
3657 this_klass->set_transitive_interfaces(transitive_interfaces()); | 3609 this_klass->set_transitive_interfaces(transitive_interfaces()); |
3658 | 3610 |
3659 // Fill in information needed to compute superclasses. | 3611 // Fill in information needed to compute superclasses. |
3682 | 3634 |
3683 // check that if this class is an interface then it doesn't have static methods | 3635 // check that if this class is an interface then it doesn't have static methods |
3684 if (this_klass->is_interface()) { | 3636 if (this_klass->is_interface()) { |
3685 check_illegal_static_method(this_klass, CHECK_(nullHandle)); | 3637 check_illegal_static_method(this_klass, CHECK_(nullHandle)); |
3686 } | 3638 } |
3639 | |
3640 // Allocate mirror and initialize static fields | |
3641 java_lang_Class::create_mirror(this_klass, CHECK_(nullHandle)); | |
3687 | 3642 |
3688 ClassLoadingService::notify_class_loaded(instanceKlass::cast(this_klass()), | 3643 ClassLoadingService::notify_class_loaded(instanceKlass::cast(this_klass()), |
3689 false /* not shared class */); | 3644 false /* not shared class */); |
3690 | 3645 |
3691 if (TraceClassLoading) { | 3646 if (TraceClassLoading) { |