comparison src/share/vm/oops/instanceKlass.cpp @ 4841:6bd680e9ea35

8003421: NPG: Move oops out of InstanceKlass into mirror Summary: Inject protection_domain, signers, init_lock into java_lang_Class Reviewed-by: stefank, dholmes, sla
author coleenp
date Wed, 22 May 2013 14:37:49 -0400
parents 92ef81e2f571
children b7fa10a3a69a
comparison
equal deleted inserted replaced
109:27ba4ead1fe7 111:5be4ac280317
266 set_transitive_interfaces(NULL); 266 set_transitive_interfaces(NULL);
267 init_implementor(); 267 init_implementor();
268 set_fields(NULL, 0); 268 set_fields(NULL, 0);
269 set_constants(NULL); 269 set_constants(NULL);
270 set_class_loader_data(NULL); 270 set_class_loader_data(NULL);
271 set_protection_domain(NULL);
272 set_signers(NULL);
273 set_source_file_name(NULL); 271 set_source_file_name(NULL);
274 set_source_debug_extension(NULL, 0); 272 set_source_debug_extension(NULL, 0);
275 set_array_name(NULL); 273 set_array_name(NULL);
276 set_inner_classes(NULL); 274 set_inner_classes(NULL);
277 set_static_oop_field_count(0); 275 set_static_oop_field_count(0);
278 set_nonstatic_field_size(0); 276 set_nonstatic_field_size(0);
279 set_is_marked_dependent(false); 277 set_is_marked_dependent(false);
280 set_init_state(InstanceKlass::allocated); 278 set_init_state(InstanceKlass::allocated);
281 set_init_thread(NULL); 279 set_init_thread(NULL);
282 set_init_lock(NULL);
283 set_reference_type(rt); 280 set_reference_type(rt);
284 set_oop_map_cache(NULL); 281 set_oop_map_cache(NULL);
285 set_jni_ids(NULL); 282 set_jni_ids(NULL);
286 set_osr_nmethods_head(NULL); 283 set_osr_nmethods_head(NULL);
287 set_breakpoints(NULL); 284 set_breakpoints(NULL);
406 if (inner_classes() != Universe::the_empty_short_array()) { 403 if (inner_classes() != Universe::the_empty_short_array()) {
407 MetadataFactory::free_array<jushort>(loader_data, inner_classes()); 404 MetadataFactory::free_array<jushort>(loader_data, inner_classes());
408 } 405 }
409 set_inner_classes(NULL); 406 set_inner_classes(NULL);
410 407
411 // Null out Java heap objects, although these won't be walked to keep
412 // alive once this InstanceKlass is deallocated.
413 set_protection_domain(NULL);
414 set_signers(NULL);
415 set_init_lock(NULL);
416
417 // We should deallocate the Annotations instance 408 // We should deallocate the Annotations instance
418 MetadataFactory::free_metadata(loader_data, annotations()); 409 MetadataFactory::free_metadata(loader_data, annotations());
419 set_annotations(NULL); 410 set_annotations(NULL);
420 } 411 }
421 412
449 instanceKlassHandle this_oop(thread, this); 440 instanceKlassHandle this_oop(thread, this);
450 eager_initialize_impl(this_oop); 441 eager_initialize_impl(this_oop);
451 } 442 }
452 } 443 }
453 444
445 // JVMTI spec thinks there are signers and protection domain in the
446 // instanceKlass. These accessors pretend these fields are there.
447 // The hprof specification also thinks these fields are in InstanceKlass.
448 oop InstanceKlass::protection_domain() const {
449 // return the protection_domain from the mirror
450 return java_lang_Class::protection_domain(java_mirror());
451 }
452
453 // To remove these from requires an incompatible change and CCC request.
454 objArrayOop InstanceKlass::signers() const {
455 // return the signers from the mirror
456 return java_lang_Class::signers(java_mirror());
457 }
458
459 volatile oop InstanceKlass::init_lock() const {
460 // return the init lock from the mirror
461 return java_lang_Class::init_lock(java_mirror());
462 }
454 463
455 void InstanceKlass::eager_initialize_impl(instanceKlassHandle this_oop) { 464 void InstanceKlass::eager_initialize_impl(instanceKlassHandle this_oop) {
456 EXCEPTION_MARK; 465 EXCEPTION_MARK;
457 volatile oop init_lock = this_oop->init_lock(); 466 volatile oop init_lock = this_oop->init_lock();
458 ObjectLocker ol(init_lock, THREAD); 467 ObjectLocker ol(init_lock, THREAD);
1881 #endif //PRODUCT 1890 #endif //PRODUCT
1882 1891
1883 1892
1884 // Garbage collection 1893 // Garbage collection
1885 1894
1886 void InstanceKlass::oops_do(OopClosure* cl) {
1887 Klass::oops_do(cl);
1888
1889 cl->do_oop(adr_protection_domain());
1890 cl->do_oop(adr_signers());
1891 cl->do_oop(adr_init_lock());
1892
1893 // Don't walk the arrays since they are walked from the ClassLoaderData objects.
1894 }
1895
1896 #ifdef ASSERT 1895 #ifdef ASSERT
1897 template <class T> void assert_is_in(T *p) { 1896 template <class T> void assert_is_in(T *p) {
1898 T heap_oop = oopDesc::load_heap_oop(p); 1897 T heap_oop = oopDesc::load_heap_oop(p);
1899 if (!oopDesc::is_null(heap_oop)) { 1898 if (!oopDesc::is_null(heap_oop)) {
1900 oop o = oopDesc::decode_heap_oop_not_null(heap_oop); 1899 oop o = oopDesc::decode_heap_oop_not_null(heap_oop);
2239 for (int i = 0; i < methods()->length(); i++) { 2238 for (int i = 0; i < methods()->length(); i++) {
2240 Method* m = methods()->at(i); 2239 Method* m = methods()->at(i);
2241 m->remove_unshareable_info(); 2240 m->remove_unshareable_info();
2242 } 2241 }
2243 2242
2244 // Need to reinstate when reading back the class.
2245 set_init_lock(NULL);
2246
2247 // do array classes also. 2243 // do array classes also.
2248 array_klasses_do(remove_unshareable_in_class); 2244 array_klasses_do(remove_unshareable_in_class);
2249 } 2245 }
2250 2246
2251 void restore_unshareable_in_class(Klass* k, TRAPS) { 2247 void restore_unshareable_in_class(Klass* k, TRAPS) {
2272 // It also redefines the itable too so fix that too. 2268 // It also redefines the itable too so fix that too.
2273 ResourceMark rm(THREAD); 2269 ResourceMark rm(THREAD);
2274 ik->vtable()->initialize_vtable(false, CHECK); 2270 ik->vtable()->initialize_vtable(false, CHECK);
2275 ik->itable()->initialize_itable(false, CHECK); 2271 ik->itable()->initialize_itable(false, CHECK);
2276 } 2272 }
2277
2278 // Allocate a simple java object for a lock.
2279 // This needs to be a java object because during class initialization
2280 // it can be held across a java call.
2281 typeArrayOop r = oopFactory::new_typeArray(T_INT, 0, CHECK);
2282 Handle h(THREAD, (oop)r);
2283 ik->set_init_lock(h());
2284 2273
2285 // restore constant pool resolved references 2274 // restore constant pool resolved references
2286 ik->constants()->restore_unshareable_info(CHECK); 2275 ik->constants()->restore_unshareable_info(CHECK);
2287 2276
2288 ik->array_klasses_do(restore_unshareable_in_class, CHECK); 2277 ik->array_klasses_do(restore_unshareable_in_class, CHECK);
2834 if (class_loader_data() != NULL) { 2823 if (class_loader_data() != NULL) {
2835 st->print(BULLET"class loader data: "); 2824 st->print(BULLET"class loader data: ");
2836 class_loader_data()->print_value_on(st); 2825 class_loader_data()->print_value_on(st);
2837 st->cr(); 2826 st->cr();
2838 } 2827 }
2839 st->print(BULLET"protection domain: "); ((InstanceKlass*)this)->protection_domain()->print_value_on(st); st->cr();
2840 st->print(BULLET"host class: "); host_klass()->print_value_on_maybe_null(st); st->cr(); 2828 st->print(BULLET"host class: "); host_klass()->print_value_on_maybe_null(st); st->cr();
2841 st->print(BULLET"signers: "); signers()->print_value_on(st); st->cr();
2842 st->print(BULLET"init_lock: "); ((oop)_init_lock)->print_value_on(st); st->cr();
2843 if (source_file_name() != NULL) { 2829 if (source_file_name() != NULL) {
2844 st->print(BULLET"source file: "); 2830 st->print(BULLET"source file: ");
2845 source_file_name()->print_value_on(st); 2831 source_file_name()->print_value_on(st);
2846 st->cr(); 2832 st->cr();
2847 } 2833 }
3038 int n = 0; 3024 int n = 0;
3039 n += (sz->_methods_array_bytes = sz->count_array(methods())); 3025 n += (sz->_methods_array_bytes = sz->count_array(methods()));
3040 n += (sz->_method_ordering_bytes = sz->count_array(method_ordering())); 3026 n += (sz->_method_ordering_bytes = sz->count_array(method_ordering()));
3041 n += (sz->_local_interfaces_bytes = sz->count_array(local_interfaces())); 3027 n += (sz->_local_interfaces_bytes = sz->count_array(local_interfaces()));
3042 n += (sz->_transitive_interfaces_bytes = sz->count_array(transitive_interfaces())); 3028 n += (sz->_transitive_interfaces_bytes = sz->count_array(transitive_interfaces()));
3043 n += (sz->_signers_bytes = sz->count_array(signers()));
3044 n += (sz->_fields_bytes = sz->count_array(fields())); 3029 n += (sz->_fields_bytes = sz->count_array(fields()));
3045 n += (sz->_inner_classes_bytes = sz->count_array(inner_classes())); 3030 n += (sz->_inner_classes_bytes = sz->count_array(inner_classes()));
3046 sz->_ro_bytes += n; 3031 sz->_ro_bytes += n;
3047 3032
3048 const ConstantPool* cp = constants(); 3033 const ConstantPool* cp = constants();
3204 } 3189 }
3205 if (constants() != NULL) { 3190 if (constants() != NULL) {
3206 guarantee(constants()->is_metadata(), "should be in metaspace"); 3191 guarantee(constants()->is_metadata(), "should be in metaspace");
3207 guarantee(constants()->is_constantPool(), "should be constant pool"); 3192 guarantee(constants()->is_constantPool(), "should be constant pool");
3208 } 3193 }
3209 if (protection_domain() != NULL) {
3210 guarantee(protection_domain()->is_oop(), "should be oop");
3211 }
3212 const Klass* host = host_klass(); 3194 const Klass* host = host_klass();
3213 if (host != NULL) { 3195 if (host != NULL) {
3214 guarantee(host->is_metadata(), "should be in metaspace"); 3196 guarantee(host->is_metadata(), "should be in metaspace");
3215 guarantee(host->is_klass(), "should be klass"); 3197 guarantee(host->is_klass(), "should be klass");
3216 }
3217 if (signers() != NULL) {
3218 guarantee(signers()->is_objArray(), "should be obj array");
3219 } 3198 }
3220 } 3199 }
3221 3200
3222 void InstanceKlass::oop_verify_on(oop obj, outputStream* st) { 3201 void InstanceKlass::oop_verify_on(oop obj, outputStream* st) {
3223 Klass::oop_verify_on(obj, st); 3202 Klass::oop_verify_on(obj, st);