< prev index next >

src/hotspot/share/oops/instanceMirrorKlass.inline.hpp

Print this page




  16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  17  *
  18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  19  * or visit www.oracle.com if you need additional information or have any
  20  * questions.
  21  *
  22  */
  23 
  24 #ifndef SHARE_VM_OOPS_INSTANCEMIRRORKLASS_INLINE_HPP
  25 #define SHARE_VM_OOPS_INSTANCEMIRRORKLASS_INLINE_HPP
  26 
  27 #include "classfile/javaClasses.hpp"
  28 #include "oops/instanceKlass.inline.hpp"
  29 #include "oops/instanceMirrorKlass.hpp"
  30 #include "oops/klass.hpp"
  31 #include "oops/oop.inline.hpp"
  32 #include "utilities/debug.hpp"
  33 #include "utilities/globalDefinitions.hpp"
  34 #include "utilities/macros.hpp"
  35 
  36 template <bool nv, typename T, class OopClosureType>
  37 void InstanceMirrorKlass::oop_oop_iterate_statics_specialized(oop obj, OopClosureType* closure) {
  38   T* p         = (T*)start_of_static_fields(obj);
  39   T* const end = p + java_lang_Class::static_oop_field_count(obj);
  40 
  41   for (; p < end; ++p) {
  42     Devirtualizer<nv>::do_oop(closure, p);
  43   }
  44 }
  45 
  46 template <bool nv, class OopClosureType>
  47 void InstanceMirrorKlass::oop_oop_iterate_statics(oop obj, OopClosureType* closure) {
  48   if (UseCompressedOops) {
  49     oop_oop_iterate_statics_specialized<nv, narrowOop>(obj, closure);
  50   } else {
  51     oop_oop_iterate_statics_specialized<nv, oop>(obj, closure);
  52   }
  53 }
  54 
  55 template <bool nv, class OopClosureType>
  56 void InstanceMirrorKlass::oop_oop_iterate(oop obj, OopClosureType* closure) {
  57   InstanceKlass::oop_oop_iterate<nv>(obj, closure);
  58 
  59   if (Devirtualizer<nv>::do_metadata(closure)) {
  60     Klass* klass = java_lang_Class::as_Klass(obj);
  61     // We'll get NULL for primitive mirrors.
  62     if (klass != NULL) {
  63       if (klass->is_instance_klass() && InstanceKlass::cast(klass)->is_anonymous()) {
  64         // An anonymous class doesn't have its own class loader, so when handling
  65         // the java mirror for an anonymous class we need to make sure its class
  66         // loader data is claimed, this is done by calling do_cld explicitly.
  67         // For non-anonymous classes the call to do_cld is made when the class
  68         // loader itself is handled.
  69         Devirtualizer<nv>::do_cld(closure, klass->class_loader_data());
  70       } else {
  71         Devirtualizer<nv>::do_klass(closure, klass);
  72       }
  73     } else {
  74       // We would like to assert here (as below) that if klass has been NULL, then
  75       // this has been a mirror for a primitive type that we do not need to follow
  76       // as they are always strong roots.
  77       // However, we might get across a klass that just changed during CMS concurrent
  78       // marking if allocation occurred in the old generation.
  79       // This is benign here, as we keep alive all CLDs that were loaded during the
  80       // CMS concurrent phase in the class loading, i.e. they will be iterated over
  81       // and kept alive during remark.
  82       // assert(java_lang_Class::is_primitive(obj), "Sanity check");
  83     }
  84   }
  85 
  86   oop_oop_iterate_statics<nv>(obj, closure);
  87 }
  88 
  89 #if INCLUDE_OOP_OOP_ITERATE_BACKWARDS
  90 template <bool nv, class OopClosureType>
  91 void InstanceMirrorKlass::oop_oop_iterate_reverse(oop obj, OopClosureType* closure) {
  92   InstanceKlass::oop_oop_iterate_reverse<nv>(obj, closure);
  93 
  94   InstanceMirrorKlass::oop_oop_iterate_statics<nv>(obj, closure);
  95 }
  96 #endif // INCLUDE_OOP_OOP_ITERATE_BACKWARDS
  97 
  98 template <bool nv, typename T, class OopClosureType>
  99 void InstanceMirrorKlass::oop_oop_iterate_statics_specialized_bounded(oop obj,
 100                                                                      OopClosureType* closure,
 101                                                                      MemRegion mr) {
 102   T* p   = (T*)start_of_static_fields(obj);
 103   T* end = p + java_lang_Class::static_oop_field_count(obj);
 104 
 105   T* const l   = (T*)mr.start();
 106   T* const h   = (T*)mr.end();
 107   assert(mask_bits((intptr_t)l, sizeof(T)-1) == 0 &&
 108          mask_bits((intptr_t)h, sizeof(T)-1) == 0,
 109          "bounded region must be properly aligned");
 110 
 111   if (p < l) {
 112     p = l;
 113   }
 114   if (end > h) {
 115     end = h;
 116   }
 117 
 118   for (;p < end; ++p) {
 119     Devirtualizer<nv>::do_oop(closure, p);
 120   }
 121 }
 122 
 123 template <bool nv, class OopClosureType>
 124 void InstanceMirrorKlass::oop_oop_iterate_statics_bounded(oop obj, OopClosureType* closure, MemRegion mr) {
 125   if (UseCompressedOops) {
 126     oop_oop_iterate_statics_specialized_bounded<nv, narrowOop>(obj, closure, mr);
 127   } else {
 128     oop_oop_iterate_statics_specialized_bounded<nv, oop>(obj, closure, mr);
 129   }
 130 }
 131 
 132 template <bool nv, class OopClosureType>
 133 void InstanceMirrorKlass::oop_oop_iterate_bounded(oop obj, OopClosureType* closure, MemRegion mr) {
 134   InstanceKlass::oop_oop_iterate_bounded<nv>(obj, closure, mr);
 135 
 136   if (Devirtualizer<nv>::do_metadata(closure)) {
 137     if (mr.contains(obj)) {
 138       Klass* klass = java_lang_Class::as_Klass(obj);
 139       // We'll get NULL for primitive mirrors.
 140       if (klass != NULL) {
 141         Devirtualizer<nv>::do_klass(closure, klass);
 142       }
 143     }
 144   }
 145 
 146   oop_oop_iterate_statics_bounded<nv>(obj, closure, mr);
 147 }
 148 
 149 #define ALL_INSTANCE_MIRROR_KLASS_OOP_OOP_ITERATE_DEFN(OopClosureType, nv_suffix)  \
 150   OOP_OOP_ITERATE_DEFN(          InstanceMirrorKlass, OopClosureType, nv_suffix)   \
 151   OOP_OOP_ITERATE_DEFN_BOUNDED(  InstanceMirrorKlass, OopClosureType, nv_suffix)   \
 152   OOP_OOP_ITERATE_DEFN_BACKWARDS(InstanceMirrorKlass, OopClosureType, nv_suffix)
 153 
 154 #endif // SHARE_VM_OOPS_INSTANCEMIRRORKLASS_INLINE_HPP


  16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  17  *
  18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  19  * or visit www.oracle.com if you need additional information or have any
  20  * questions.
  21  *
  22  */
  23 
  24 #ifndef SHARE_VM_OOPS_INSTANCEMIRRORKLASS_INLINE_HPP
  25 #define SHARE_VM_OOPS_INSTANCEMIRRORKLASS_INLINE_HPP
  26 
  27 #include "classfile/javaClasses.hpp"
  28 #include "oops/instanceKlass.inline.hpp"
  29 #include "oops/instanceMirrorKlass.hpp"
  30 #include "oops/klass.hpp"
  31 #include "oops/oop.inline.hpp"
  32 #include "utilities/debug.hpp"
  33 #include "utilities/globalDefinitions.hpp"
  34 #include "utilities/macros.hpp"
  35 
  36 template <typename T, class OopClosureType>
  37 void InstanceMirrorKlass::oop_oop_iterate_statics(oop obj, OopClosureType* closure) {
  38   T* p         = (T*)start_of_static_fields(obj);
  39   T* const end = p + java_lang_Class::static_oop_field_count(obj);
  40 
  41   for (; p < end; ++p) {
  42     Devirtualizer::do_oop(closure, p);









  43   }
  44 }
  45 
  46 template <typename T, class OopClosureType>
  47 void InstanceMirrorKlass::oop_oop_iterate(oop obj, OopClosureType* closure) {
  48   InstanceKlass::oop_oop_iterate<T>(obj, closure);
  49 
  50   if (Devirtualizer::do_metadata(closure)) {
  51     Klass* klass = java_lang_Class::as_Klass(obj);
  52     // We'll get NULL for primitive mirrors.
  53     if (klass != NULL) {
  54       if (klass->is_instance_klass() && InstanceKlass::cast(klass)->is_anonymous()) {
  55         // An anonymous class doesn't have its own class loader, so when handling
  56         // the java mirror for an anonymous class we need to make sure its class
  57         // loader data is claimed, this is done by calling do_cld explicitly.
  58         // For non-anonymous classes the call to do_cld is made when the class
  59         // loader itself is handled.
  60         Devirtualizer::do_cld(closure, klass->class_loader_data());
  61       } else {
  62         Devirtualizer::do_klass(closure, klass);
  63       }
  64     } else {
  65       // We would like to assert here (as below) that if klass has been NULL, then
  66       // this has been a mirror for a primitive type that we do not need to follow
  67       // as they are always strong roots.
  68       // However, we might get across a klass that just changed during CMS concurrent
  69       // marking if allocation occurred in the old generation.
  70       // This is benign here, as we keep alive all CLDs that were loaded during the
  71       // CMS concurrent phase in the class loading, i.e. they will be iterated over
  72       // and kept alive during remark.
  73       // assert(java_lang_Class::is_primitive(obj), "Sanity check");
  74     }
  75   }
  76 
  77   oop_oop_iterate_statics<T>(obj, closure);
  78 }
  79 
  80 template <typename T, class OopClosureType>

  81 void InstanceMirrorKlass::oop_oop_iterate_reverse(oop obj, OopClosureType* closure) {
  82   InstanceKlass::oop_oop_iterate_reverse<T>(obj, closure);
  83 
  84   InstanceMirrorKlass::oop_oop_iterate_statics<T>(obj, closure);
  85 }

  86 
  87 template <typename T, class OopClosureType>
  88 void InstanceMirrorKlass::oop_oop_iterate_statics_bounded(oop obj,
  89                                                           OopClosureType* closure,
  90                                                           MemRegion mr) {
  91   T* p   = (T*)start_of_static_fields(obj);
  92   T* end = p + java_lang_Class::static_oop_field_count(obj);
  93 
  94   T* const l   = (T*)mr.start();
  95   T* const h   = (T*)mr.end();
  96   assert(mask_bits((intptr_t)l, sizeof(T)-1) == 0 &&
  97          mask_bits((intptr_t)h, sizeof(T)-1) == 0,
  98          "bounded region must be properly aligned");
  99 
 100   if (p < l) {
 101     p = l;
 102   }
 103   if (end > h) {
 104     end = h;
 105   }
 106 
 107   for (;p < end; ++p) {
 108     Devirtualizer::do_oop(closure, p);
 109   }
 110 }
 111 
 112 template <typename T, class OopClosureType>









 113 void InstanceMirrorKlass::oop_oop_iterate_bounded(oop obj, OopClosureType* closure, MemRegion mr) {
 114   InstanceKlass::oop_oop_iterate_bounded<T>(obj, closure, mr);
 115 
 116   if (Devirtualizer::do_metadata(closure)) {
 117     if (mr.contains(obj)) {
 118       Klass* klass = java_lang_Class::as_Klass(obj);
 119       // We'll get NULL for primitive mirrors.
 120       if (klass != NULL) {
 121         Devirtualizer::do_klass(closure, klass);
 122       }
 123     }
 124   }
 125 
 126   oop_oop_iterate_statics_bounded<T>(obj, closure, mr);
 127 }





 128 
 129 #endif // SHARE_VM_OOPS_INSTANCEMIRRORKLASS_INLINE_HPP
< prev index next >