1.1 --- a/src/share/vm/ci/ciObjectFactory.cpp Tue Jul 01 09:03:55 2014 +0200 1.2 +++ b/src/share/vm/ci/ciObjectFactory.cpp Mon Jul 07 10:12:40 2014 +0200 1.3 @@ -46,6 +46,9 @@ 1.4 #include "oops/oop.inline.hpp" 1.5 #include "oops/oop.inline2.hpp" 1.6 #include "runtime/fieldType.hpp" 1.7 +#if INCLUDE_ALL_GCS 1.8 +# include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp" 1.9 +#endif 1.10 1.11 // ciObjectFactory 1.12 // 1.13 @@ -374,6 +377,37 @@ 1.14 return NULL; 1.15 } 1.16 1.17 +// ------------------------------------------------------------------ 1.18 +// ciObjectFactory::ensure_metadata_alive 1.19 +// 1.20 +// Ensure that the metadata wrapped by the ciMetadata is kept alive by GC. 1.21 +// This is primarily useful for metadata which is considered as weak roots 1.22 +// by the GC but need to be strong roots if reachable from a current compilation. 1.23 +// 1.24 +void ciObjectFactory::ensure_metadata_alive(ciMetadata* m) { 1.25 + ASSERT_IN_VM; // We're handling raw oops here. 1.26 + 1.27 +#if INCLUDE_ALL_GCS 1.28 + if (!UseG1GC) { 1.29 + return; 1.30 + } 1.31 + Klass* metadata_owner_klass; 1.32 + if (m->is_klass()) { 1.33 + metadata_owner_klass = m->as_klass()->get_Klass(); 1.34 + } else if (m->is_method()) { 1.35 + metadata_owner_klass = m->as_method()->get_Method()->constants()->pool_holder(); 1.36 + } else { 1.37 + fatal("Not implemented for other types of metadata"); 1.38 + } 1.39 + 1.40 + oop metadata_holder = metadata_owner_klass->klass_holder(); 1.41 + if (metadata_holder != NULL) { 1.42 + G1SATBCardTableModRefBS::enqueue(metadata_holder); 1.43 + } 1.44 + 1.45 +#endif 1.46 +} 1.47 + 1.48 //------------------------------------------------------------------ 1.49 // ciObjectFactory::get_unloaded_method 1.50 //