1.1 --- a/src/share/vm/oops/instanceMirrorKlass.cpp Fri Aug 31 16:39:35 2012 -0700 1.2 +++ b/src/share/vm/oops/instanceMirrorKlass.cpp Sat Sep 01 13:25:18 2012 -0400 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -29,7 +29,6 @@ 1.11 #include "gc_interface/collectedHeap.inline.hpp" 1.12 #include "memory/genOopClosures.inline.hpp" 1.13 #include "memory/oopFactory.hpp" 1.14 -#include "memory/permGen.hpp" 1.15 #include "oops/instanceKlass.hpp" 1.16 #include "oops/instanceMirrorKlass.hpp" 1.17 #include "oops/instanceOop.hpp" 1.18 @@ -37,6 +36,7 @@ 1.19 #include "oops/symbol.hpp" 1.20 #include "runtime/handles.inline.hpp" 1.21 #ifndef SERIALGC 1.22 +#include "gc_implementation/concurrentMarkSweep/cmsOopClosures.inline.hpp" 1.23 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp" 1.24 #include "gc_implementation/g1/g1OopClosures.inline.hpp" 1.25 #include "gc_implementation/g1/g1RemSet.inline.hpp" 1.26 @@ -149,7 +149,19 @@ 1.27 1.28 1.29 void instanceMirrorKlass::oop_follow_contents(oop obj) { 1.30 - instanceKlass::oop_follow_contents(obj); 1.31 + InstanceKlass::oop_follow_contents(obj); 1.32 + 1.33 + // Follow the klass field in the mirror. 1.34 + Klass* klass = java_lang_Class::as_Klass(obj); 1.35 + if (klass != NULL) { 1.36 + MarkSweep::follow_klass(klass); 1.37 + } else { 1.38 + // If klass is NULL then this a mirror for a primitive type. 1.39 + // We don't have to follow them, since they are handled as strong 1.40 + // roots in Universe::oops_do. 1.41 + assert(java_lang_Class::is_primitive(obj), "Sanity check"); 1.42 + } 1.43 + 1.44 InstanceMirrorKlass_OOP_ITERATE( \ 1.45 start_of_static_fields(obj), java_lang_Class::static_oop_field_count(obj), \ 1.46 MarkSweep::mark_and_push(p), \ 1.47 @@ -159,7 +171,19 @@ 1.48 #ifndef SERIALGC 1.49 void instanceMirrorKlass::oop_follow_contents(ParCompactionManager* cm, 1.50 oop obj) { 1.51 - instanceKlass::oop_follow_contents(cm, obj); 1.52 + InstanceKlass::oop_follow_contents(cm, obj); 1.53 + 1.54 + // Follow the klass field in the mirror. 1.55 + Klass* klass = java_lang_Class::as_Klass(obj); 1.56 + if (klass != NULL) { 1.57 + PSParallelCompact::follow_klass(cm, klass); 1.58 + } else { 1.59 + // If klass is NULL then this a mirror for a primitive type. 1.60 + // We don't have to follow them, since they are handled as strong 1.61 + // roots in Universe::oops_do. 1.62 + assert(java_lang_Class::is_primitive(obj), "Sanity check"); 1.63 + } 1.64 + 1.65 InstanceMirrorKlass_OOP_ITERATE( \ 1.66 start_of_static_fields(obj), java_lang_Class::static_oop_field_count(obj), \ 1.67 PSParallelCompact::mark_and_push(cm, p), \ 1.68 @@ -169,7 +193,19 @@ 1.69 1.70 int instanceMirrorKlass::oop_adjust_pointers(oop obj) { 1.71 int size = oop_size(obj); 1.72 - instanceKlass::oop_adjust_pointers(obj); 1.73 + InstanceKlass::oop_adjust_pointers(obj); 1.74 + 1.75 + // Follow the klass field in the mirror. 1.76 + Klass* klass = java_lang_Class::as_Klass(obj); 1.77 + if (klass != NULL) { 1.78 + MarkSweep::adjust_klass(klass); 1.79 + } else { 1.80 + // If klass is NULL then this a mirror for a primitive type. 1.81 + // We don't have to follow them, since they are handled as strong 1.82 + // roots in Universe::oops_do. 1.83 + assert(java_lang_Class::is_primitive(obj), "Sanity check"); 1.84 + } 1.85 + 1.86 InstanceMirrorKlass_OOP_ITERATE( \ 1.87 start_of_static_fields(obj), java_lang_Class::static_oop_field_count(obj), \ 1.88 MarkSweep::adjust_pointer(p), \ 1.89 @@ -193,6 +229,12 @@ 1.90 return oop_size(obj); \ 1.91 1.92 1.93 +#define if_do_metadata_checked(closure, nv_suffix) \ 1.94 + /* Make sure the non-virtual and the virtual versions match. */ \ 1.95 + assert(closure->do_metadata##nv_suffix() == closure->do_metadata(), \ 1.96 + "Inconsistency in do_metadata"); \ 1.97 + if (closure->do_metadata##nv_suffix()) 1.98 + 1.99 // Macro to define instanceMirrorKlass::oop_oop_iterate for virtual/nonvirtual for 1.100 // all closures. Macros calling macros above for each oop size. 1.101 1.102 @@ -203,7 +245,15 @@ 1.103 /* Get size before changing pointers */ \ 1.104 SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::irk); \ 1.105 \ 1.106 - instanceKlass::oop_oop_iterate##nv_suffix(obj, closure); \ 1.107 + InstanceKlass::oop_oop_iterate##nv_suffix(obj, closure); \ 1.108 + \ 1.109 + if_do_metadata_checked(closure, nv_suffix) { \ 1.110 + Klass* klass = java_lang_Class::as_Klass(obj); \ 1.111 + /* We'll get NULL for primitive mirrors. */ \ 1.112 + if (klass != NULL) { \ 1.113 + closure->do_klass##nv_suffix(klass); \ 1.114 + } \ 1.115 + } \ 1.116 \ 1.117 if (UseCompressedOops) { \ 1.118 InstanceMirrorKlass_SPECIALIZED_OOP_ITERATE_DEFN(narrowOop, nv_suffix); \ 1.119 @@ -220,7 +270,7 @@ 1.120 /* Get size before changing pointers */ \ 1.121 SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::irk); \ 1.122 \ 1.123 - instanceKlass::oop_oop_iterate_backwards##nv_suffix(obj, closure); \ 1.124 + InstanceKlass::oop_oop_iterate_backwards##nv_suffix(obj, closure); \ 1.125 \ 1.126 if (UseCompressedOops) { \ 1.127 InstanceMirrorKlass_SPECIALIZED_OOP_ITERATE_DEFN(narrowOop, nv_suffix); \ 1.128 @@ -239,7 +289,18 @@ 1.129 MemRegion mr) { \ 1.130 SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::irk); \ 1.131 \ 1.132 - instanceKlass::oop_oop_iterate##nv_suffix##_m(obj, closure, mr); \ 1.133 + InstanceKlass::oop_oop_iterate##nv_suffix##_m(obj, closure, mr); \ 1.134 + \ 1.135 + if_do_metadata_checked(closure, nv_suffix) { \ 1.136 + if (mr.contains(obj)) { \ 1.137 + Klass* klass = java_lang_Class::as_Klass(obj); \ 1.138 + /* We'll get NULL for primitive mirrors. */ \ 1.139 + if (klass != NULL) { \ 1.140 + closure->do_klass##nv_suffix(klass); \ 1.141 + } \ 1.142 + } \ 1.143 + } \ 1.144 + \ 1.145 if (UseCompressedOops) { \ 1.146 InstanceMirrorKlass_BOUNDED_SPECIALIZED_OOP_ITERATE(narrowOop, nv_suffix, mr); \ 1.147 } else { \ 1.148 @@ -258,7 +319,11 @@ 1.149 1.150 #ifndef SERIALGC 1.151 void instanceMirrorKlass::oop_push_contents(PSPromotionManager* pm, oop obj) { 1.152 - instanceKlass::oop_push_contents(pm, obj); 1.153 + // Note that we don't have to follow the mirror -> klass pointer, since all 1.154 + // klasses that are dirty will be scavenged when we iterate over the 1.155 + // ClassLoaderData objects. 1.156 + 1.157 + InstanceKlass::oop_push_contents(pm, obj); 1.158 InstanceMirrorKlass_OOP_ITERATE( \ 1.159 start_of_static_fields(obj), java_lang_Class::static_oop_field_count(obj),\ 1.160 if (PSScavenge::should_scavenge(p)) { \ 1.161 @@ -268,18 +333,31 @@ 1.162 } 1.163 1.164 int instanceMirrorKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) { 1.165 - instanceKlass::oop_update_pointers(cm, obj); 1.166 + int size = oop_size(obj); 1.167 + InstanceKlass::oop_update_pointers(cm, obj); 1.168 + 1.169 + // Follow the klass field in the mirror. 1.170 + Klass* klass = java_lang_Class::as_Klass(obj); 1.171 + if (klass != NULL) { 1.172 + PSParallelCompact::adjust_klass(cm, klass); 1.173 + } else { 1.174 + // If klass is NULL then this a mirror for a primitive type. 1.175 + // We don't have to follow them, since they are handled as strong 1.176 + // roots in Universe::oops_do. 1.177 + assert(java_lang_Class::is_primitive(obj), "Sanity check"); 1.178 + } 1.179 + 1.180 InstanceMirrorKlass_OOP_ITERATE( \ 1.181 start_of_static_fields(obj), java_lang_Class::static_oop_field_count(obj),\ 1.182 PSParallelCompact::adjust_pointer(p), \ 1.183 assert_nothing) 1.184 - return oop_size(obj); 1.185 + return size; 1.186 } 1.187 #endif // SERIALGC 1.188 1.189 int instanceMirrorKlass::instance_size(KlassHandle k) { 1.190 if (k() != NULL && k->oop_is_instance()) { 1.191 - return align_object_size(size_helper() + instanceKlass::cast(k())->static_field_size()); 1.192 + return align_object_size(size_helper() + InstanceKlass::cast(k())->static_field_size()); 1.193 } 1.194 return size_helper(); 1.195 } 1.196 @@ -287,7 +365,7 @@ 1.197 instanceOop instanceMirrorKlass::allocate_instance(KlassHandle k, TRAPS) { 1.198 // Query before forming handle. 1.199 int size = instance_size(k); 1.200 - KlassHandle h_k(THREAD, as_klassOop()); 1.201 + KlassHandle h_k(THREAD, this); 1.202 instanceOop i = (instanceOop) CollectedHeap::Class_obj_allocate(h_k, size, k, CHECK_NULL); 1.203 return i; 1.204 } 1.205 @@ -297,9 +375,9 @@ 1.206 } 1.207 1.208 int instanceMirrorKlass::compute_static_oop_field_count(oop obj) { 1.209 - klassOop k = java_lang_Class::as_klassOop(obj); 1.210 - if (k != NULL && k->klass_part()->oop_is_instance()) { 1.211 - return instanceKlass::cast(k)->static_oop_field_count(); 1.212 + Klass* k = java_lang_Class::as_Klass(obj); 1.213 + if (k != NULL && k->oop_is_instance()) { 1.214 + return InstanceKlass::cast(k)->static_oop_field_count(); 1.215 } 1.216 return 0; 1.217 }