1 /*
   2  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_MEMORY_ITERATOR_INLINE_HPP
  26 #define SHARE_VM_MEMORY_ITERATOR_INLINE_HPP
  27 
  28 #include "classfile/classLoaderData.hpp"
  29 #include "memory/iterator.hpp"
  30 #include "oops/klass.hpp"
  31 #include "oops/instanceKlass.inline.hpp"
  32 #include "oops/instanceMirrorKlass.inline.hpp"
  33 #include "oops/instanceClassLoaderKlass.inline.hpp"
  34 #include "oops/instanceRefKlass.inline.hpp"
  35 #include "oops/objArrayKlass.inline.hpp"
  36 #include "oops/typeArrayKlass.inline.hpp"
  37 #include "utilities/debug.hpp"
  38 
  39 inline void MetadataAwareOopClosure::do_cld_nv(ClassLoaderData* cld) {


  40   bool claim = true;  // Must claim the class loader data before processing.
  41   cld->oops_do(this, claim);
  42 }
  43 
  44 inline void MetadataAwareOopClosure::do_klass_nv(Klass* k) {
  45   ClassLoaderData* cld = k->class_loader_data();
  46   do_cld_nv(cld);
  47 }
  48 
  49 #ifdef ASSERT
  50 // This verification is applied to all visited oops.
  51 // The closures can turn is off by overriding should_verify_oops().
  52 template <typename T>
  53 void ExtendedOopClosure::verify(T* p) {
  54   if (should_verify_oops()) {
  55     T heap_oop = oopDesc::load_heap_oop(p);
  56     if (!oopDesc::is_null(heap_oop)) {
  57       oop o = oopDesc::decode_heap_oop_not_null(heap_oop);
  58       assert(Universe::heap()->is_in_closed_subset(o),
  59              "should be in closed *p " PTR_FORMAT " " PTR_FORMAT, p2i(p), p2i(o));
  60     }
  61   }
  62 }
  63 #endif
  64 
  65 // Implementation of the non-virtual do_oop dispatch.
  66 
  67 template <class OopClosureType, typename T>
  68 inline void Devirtualizer<true>::do_oop(OopClosureType* closure, T* p) {
  69   debug_only(closure->verify(p));
  70   closure->do_oop_nv(p);
  71 }
  72 template <class OopClosureType>
  73 inline void Devirtualizer<true>::do_klass(OopClosureType* closure, Klass* k) {
  74   closure->do_klass_nv(k);
  75 }
  76 template <class OopClosureType>
  77 void Devirtualizer<true>::do_cld(OopClosureType* closure, ClassLoaderData* cld) {
  78   closure->do_cld_nv(cld);
  79 }
  80 template <class OopClosureType>
  81 inline bool Devirtualizer<true>::do_metadata(OopClosureType* closure) {
  82   // Make sure the non-virtual and the virtual versions match.
  83   assert(closure->do_metadata_nv() == closure->do_metadata(), "Inconsistency in do_metadata");
  84   return closure->do_metadata_nv();
  85 }
  86 
  87 // Implementation of the virtual do_oop dispatch.
  88 
  89 template <class OopClosureType, typename T>
  90 void Devirtualizer<false>::do_oop(OopClosureType* closure, T* p) {
  91   debug_only(closure->verify(p));
  92   closure->do_oop(p);
  93 }
  94 template <class OopClosureType>
  95 void Devirtualizer<false>::do_klass(OopClosureType* closure, Klass* k) {
  96   closure->do_klass(k);
  97 }
  98 template <class OopClosureType>
  99 void Devirtualizer<false>::do_cld(OopClosureType* closure, ClassLoaderData* cld) {
 100   closure->do_cld(cld);
 101 }
 102 template <class OopClosureType>
 103 bool Devirtualizer<false>::do_metadata(OopClosureType* closure) {
 104   return closure->do_metadata();
 105 }
 106 
 107 // The list of all "specializable" oop_oop_iterate function definitions.
 108 #define ALL_KLASS_OOP_OOP_ITERATE_DEFN(OopClosureType, nv_suffix)                  \
 109   ALL_INSTANCE_KLASS_OOP_OOP_ITERATE_DEFN(             OopClosureType, nv_suffix)  \
 110   ALL_INSTANCE_REF_KLASS_OOP_OOP_ITERATE_DEFN(         OopClosureType, nv_suffix)  \
 111   ALL_INSTANCE_MIRROR_KLASS_OOP_OOP_ITERATE_DEFN(      OopClosureType, nv_suffix)  \
 112   ALL_INSTANCE_CLASS_LOADER_KLASS_OOP_OOP_ITERATE_DEFN(OopClosureType, nv_suffix)  \
 113   ALL_OBJ_ARRAY_KLASS_OOP_OOP_ITERATE_DEFN(            OopClosureType, nv_suffix)  \
 114   ALL_TYPE_ARRAY_KLASS_OOP_OOP_ITERATE_DEFN(           OopClosureType, nv_suffix)
 115 
 116 #endif // SHARE_VM_MEMORY_ITERATOR_INLINE_HPP
--- EOF ---