1.1 --- a/src/share/vm/classfile/classFileParser.cpp Fri Mar 18 15:52:42 2011 -0700 1.2 +++ b/src/share/vm/classfile/classFileParser.cpp Fri Mar 18 16:00:34 2011 -0700 1.3 @@ -37,6 +37,7 @@ 1.4 #include "memory/universe.inline.hpp" 1.5 #include "oops/constantPoolOop.hpp" 1.6 #include "oops/instanceKlass.hpp" 1.7 +#include "oops/instanceMirrorKlass.hpp" 1.8 #include "oops/klass.inline.hpp" 1.9 #include "oops/klassOop.hpp" 1.10 #include "oops/klassVtable.hpp" 1.11 @@ -2606,54 +2607,6 @@ 1.12 } 1.13 1.14 1.15 -static void initialize_static_field(fieldDescriptor* fd, TRAPS) { 1.16 - KlassHandle h_k (THREAD, fd->field_holder()); 1.17 - assert(h_k.not_null() && fd->is_static(), "just checking"); 1.18 - if (fd->has_initial_value()) { 1.19 - BasicType t = fd->field_type(); 1.20 - switch (t) { 1.21 - case T_BYTE: 1.22 - h_k()->byte_field_put(fd->offset(), fd->int_initial_value()); 1.23 - break; 1.24 - case T_BOOLEAN: 1.25 - h_k()->bool_field_put(fd->offset(), fd->int_initial_value()); 1.26 - break; 1.27 - case T_CHAR: 1.28 - h_k()->char_field_put(fd->offset(), fd->int_initial_value()); 1.29 - break; 1.30 - case T_SHORT: 1.31 - h_k()->short_field_put(fd->offset(), fd->int_initial_value()); 1.32 - break; 1.33 - case T_INT: 1.34 - h_k()->int_field_put(fd->offset(), fd->int_initial_value()); 1.35 - break; 1.36 - case T_FLOAT: 1.37 - h_k()->float_field_put(fd->offset(), fd->float_initial_value()); 1.38 - break; 1.39 - case T_DOUBLE: 1.40 - h_k()->double_field_put(fd->offset(), fd->double_initial_value()); 1.41 - break; 1.42 - case T_LONG: 1.43 - h_k()->long_field_put(fd->offset(), fd->long_initial_value()); 1.44 - break; 1.45 - case T_OBJECT: 1.46 - { 1.47 - #ifdef ASSERT 1.48 - TempNewSymbol sym = SymbolTable::new_symbol("Ljava/lang/String;", CHECK); 1.49 - assert(fd->signature() == sym, "just checking"); 1.50 - #endif 1.51 - oop string = fd->string_initial_value(CHECK); 1.52 - h_k()->obj_field_put(fd->offset(), string); 1.53 - } 1.54 - break; 1.55 - default: 1.56 - THROW_MSG(vmSymbols::java_lang_ClassFormatError(), 1.57 - "Illegal ConstantValue attribute in class file"); 1.58 - } 1.59 - } 1.60 -} 1.61 - 1.62 - 1.63 void ClassFileParser::java_lang_ref_Reference_fix_pre(typeArrayHandle* fields_ptr, 1.64 constantPoolHandle cp, FieldAllocationCount *fac_ptr, TRAPS) { 1.65 // This code is for compatibility with earlier jdk's that do not 1.66 @@ -2769,8 +2722,8 @@ 1.67 } 1.68 1.69 1.70 -void ClassFileParser::java_lang_Class_fix_pre(objArrayHandle* methods_ptr, 1.71 - FieldAllocationCount *fac_ptr, TRAPS) { 1.72 +void ClassFileParser::java_lang_Class_fix_pre(int* nonstatic_field_size, 1.73 + FieldAllocationCount *fac_ptr) { 1.74 // Add fake fields for java.lang.Class instances 1.75 // 1.76 // This is not particularly nice. We should consider adding a 1.77 @@ -2787,10 +2740,13 @@ 1.78 // versions because when the offsets are computed at bootstrap 1.79 // time we don't know yet which version of the JDK we're running in. 1.80 1.81 - // The values below are fake but will force two non-static oop fields and 1.82 + // The values below are fake but will force three non-static oop fields and 1.83 // a corresponding non-static oop map block to be allocated. 1.84 const int extra = java_lang_Class::number_of_fake_oop_fields; 1.85 fac_ptr->nonstatic_oop_count += extra; 1.86 + 1.87 + // Reserve some leading space for fake ints 1.88 + *nonstatic_field_size += align_size_up(java_lang_Class::hc_number_of_fake_int_fields * BytesPerInt, heapOopSize) / heapOopSize; 1.89 } 1.90 1.91 1.92 @@ -3205,9 +3161,7 @@ 1.93 int next_nonstatic_field_offset; 1.94 1.95 // Calculate the starting byte offsets 1.96 - next_static_oop_offset = (instanceKlass::header_size() + 1.97 - align_object_offset(vtable_size) + 1.98 - align_object_offset(itable_size)) * wordSize; 1.99 + next_static_oop_offset = instanceMirrorKlass::offset_of_static_fields(); 1.100 next_static_double_offset = next_static_oop_offset + 1.101 (fac.static_oop_count * heapOopSize); 1.102 if ( fac.static_double_count && 1.103 @@ -3226,15 +3180,16 @@ 1.104 fac.static_byte_count ), wordSize ); 1.105 static_field_size = (next_static_type_offset - 1.106 next_static_oop_offset) / wordSize; 1.107 + 1.108 + // Add fake fields for java.lang.Class instances (also see below) 1.109 + if (class_name == vmSymbols::java_lang_Class() && class_loader.is_null()) { 1.110 + java_lang_Class_fix_pre(&nonstatic_field_size, &fac); 1.111 + } 1.112 + 1.113 first_nonstatic_field_offset = instanceOopDesc::base_offset_in_bytes() + 1.114 nonstatic_field_size * heapOopSize; 1.115 next_nonstatic_field_offset = first_nonstatic_field_offset; 1.116 1.117 - // Add fake fields for java.lang.Class instances (also see below) 1.118 - if (class_name == vmSymbols::java_lang_Class() && class_loader.is_null()) { 1.119 - java_lang_Class_fix_pre(&methods, &fac, CHECK_(nullHandle)); 1.120 - } 1.121 - 1.122 // adjust the vmentry field declaration in java.lang.invoke.MethodHandle 1.123 if (EnableMethodHandles && class_name == vmSymbols::java_lang_invoke_MethodHandle() && class_loader.is_null()) { 1.124 java_lang_invoke_MethodHandle_fix_pre(cp, fields, &fac, CHECK_(nullHandle)); 1.125 @@ -3566,7 +3521,7 @@ 1.126 } 1.127 1.128 // We can now create the basic klassOop for this klass 1.129 - klassOop ik = oopFactory::new_instanceKlass(vtable_size, itable_size, 1.130 + klassOop ik = oopFactory::new_instanceKlass(name, vtable_size, itable_size, 1.131 static_field_size, 1.132 total_oop_map_count, 1.133 rt, CHECK_(nullHandle)); 1.134 @@ -3588,7 +3543,7 @@ 1.135 this_klass->set_class_loader(class_loader()); 1.136 this_klass->set_nonstatic_field_size(nonstatic_field_size); 1.137 this_klass->set_has_nonstatic_fields(has_nonstatic_fields); 1.138 - this_klass->set_static_oop_field_size(fac.static_oop_count); 1.139 + this_klass->set_static_oop_field_count(fac.static_oop_count); 1.140 cp->set_pool_holder(this_klass()); 1.141 error_handler.set_in_error(false); // turn off error handler for cp 1.142 this_klass->set_constants(cp()); 1.143 @@ -3649,9 +3604,6 @@ 1.144 // Make sure this is the end of class file stream 1.145 guarantee_property(cfs->at_eos(), "Extra bytes at the end of class file %s", CHECK_(nullHandle)); 1.146 1.147 - // Initialize static fields 1.148 - this_klass->do_local_static_fields(&initialize_static_field, CHECK_(nullHandle)); 1.149 - 1.150 // VerifyOops believes that once this has been set, the object is completely loaded. 1.151 // Compute transitive closure of interfaces this class implements 1.152 this_klass->set_transitive_interfaces(transitive_interfaces()); 1.153 @@ -3685,6 +3637,9 @@ 1.154 check_illegal_static_method(this_klass, CHECK_(nullHandle)); 1.155 } 1.156 1.157 + // Allocate mirror and initialize static fields 1.158 + java_lang_Class::create_mirror(this_klass, CHECK_(nullHandle)); 1.159 + 1.160 ClassLoadingService::notify_class_loaded(instanceKlass::cast(this_klass()), 1.161 false /* not shared class */); 1.162