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