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 #ifndef SHARE_GC_Z_ZITERATOR_INLINE_HPP
25 #define SHARE_GC_Z_ZITERATOR_INLINE_HPP
26
27 #include "gc/z/zIterator.hpp"
28
29 #include "gc/z/zVerify.hpp"
30 #include "memory/iterator.inline.hpp"
31 #include "oops/objArrayOop.hpp"
32 #include "oops/oop.inline.hpp"
33
34 inline bool ZIterator::is_invisible_object(oop obj) {
35 // This is a good place to make sure that we can't concurrently iterate over
36 // objects while VMThread operations think they have exclusive access to the
37 // object graph.
38 //
39 // One example that have caused problems is the JFR Leak Profiler, which
40 // sets the mark word to a value that makes the object arrays look like
41 // invisible objects.
42 z_verify_safepoints_are_blocked();
43
44 return obj->mark_acquire().is_marked();
45 }
46
47 inline bool ZIterator::is_invisible_object_array(oop obj) {
48 return is_invisible_object_array(obj, obj->klass());
49 }
50
51 inline bool ZIterator::is_invisible_object_array(oop obj, Klass* klass) {
52 return klass->is_objArray_klass() && is_invisible_object(obj);
53 }
54
55 // These iterators skips invisible object arrays
56
57 template <typename OopClosureT>
58 void ZIterator::oop_iterate_safe(oop obj, OopClosureT* cl) {
59 oop_iterate_safe(obj, obj->klass(), cl);
60 }
61
62 template <typename OopClosureT>
63 void ZIterator::oop_iterate_safe(oop obj, Klass* klass, OopClosureT* cl) {
64 // Skip invisible object arrays - we only filter out *object* arrays,
65 // because that check is arguably faster than the is_invisible_object
66 // check, and primitive arrays are cheap to call oop_iterate on.
67 if (!is_invisible_object_array(obj, klass)) {
68 OopIteratorClosureDispatch::oop_oop_iterate(cl, obj, klass);
69 }
70 }
71
72 template <typename OopClosureT>
73 void ZIterator::oop_iterate(oop obj, OopClosureT* cl) {
74 assert(!is_invisible_object_array(obj), "not safe");
75 obj->oop_iterate(cl);
76 }
77
78 template <typename OopClosureT>
79 void ZIterator::oop_iterate_elements_range(objArrayOop obj, OopClosureT* cl, int start, int end) {
80 assert(!is_invisible_object_array(obj), "not safe");
81 obj->oop_iterate_elements_range(cl, start, end);
82 }
83
84 template <typename Function>
85 class ZBasicOopIterateClosure : public BasicOopIterateClosure {
86 private:
87 Function _function;
88
89 public:
90 ZBasicOopIterateClosure(Function function)
91 : _function(function) {}
92
93 virtual void do_oop(oop* p) {
94 _function((volatile zpointer*)p);
95 }
96
97 virtual void do_oop(narrowOop* p_) {
98 ShouldNotReachHere();
99 }
100 };
101
|
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 #ifndef SHARE_GC_Z_ZITERATOR_INLINE_HPP
25 #define SHARE_GC_Z_ZITERATOR_INLINE_HPP
26
27 #include "gc/z/zIterator.hpp"
28
29 #include "gc/z/zVerify.hpp"
30 #include "memory/iterator.inline.hpp"
31 #include "oops/objArrayOop.hpp"
32 #include "oops/oop.inline.hpp"
33 #include "oops/refArrayOop.hpp"
34
35 inline bool ZIterator::is_invisible_object(oop obj) {
36 // This is a good place to make sure that we can't concurrently iterate over
37 // objects while VMThread operations think they have exclusive access to the
38 // object graph.
39 //
40 // One example that have caused problems is the JFR Leak Profiler, which
41 // sets the mark word to a value that makes the object arrays look like
42 // invisible objects.
43 z_verify_safepoints_are_blocked();
44
45 return obj->mark_acquire().is_marked();
46 }
47
48 inline bool ZIterator::is_invisible_object_array(oop obj) {
49 return is_invisible_object_array(obj, obj->klass());
50 }
51
52 inline bool ZIterator::is_invisible_object_array(oop obj, Klass* klass) {
53 return klass->is_refArray_klass() && is_invisible_object(obj);
54 }
55
56 // These iterators skips invisible object arrays
57
58 template <typename OopClosureT>
59 void ZIterator::oop_iterate_safe(oop obj, OopClosureT* cl) {
60 oop_iterate_safe(obj, obj->klass(), cl);
61 }
62
63 template <typename OopClosureT>
64 void ZIterator::oop_iterate_safe(oop obj, Klass* klass, OopClosureT* cl) {
65 // Skip invisible object arrays - we only filter out *object* arrays,
66 // because that check is arguably faster than the is_invisible_object
67 // check, and primitive arrays are cheap to call oop_iterate on.
68 if (!is_invisible_object_array(obj, klass)) {
69 OopIteratorClosureDispatch::oop_oop_iterate(cl, obj, klass);
70 }
71 }
72
73 template <typename OopClosureT>
74 void ZIterator::oop_iterate(oop obj, OopClosureT* cl) {
75 assert(!is_invisible_object_array(obj), "not safe");
76 obj->oop_iterate(cl);
77 }
78
79 template <typename OopClosureT>
80 void ZIterator::oop_iterate_elements_range(objArrayOop obj, OopClosureT* cl, int start, int end) {
81 assert(!is_invisible_object_array(obj), "not safe");
82 assert(obj->is_refArray(), "Must be");
83 refArrayOop(obj)->oop_iterate_elements_range(cl, start, end);
84 }
85
86 template <typename Function>
87 class ZBasicOopIterateClosure : public BasicOopIterateClosure {
88 private:
89 Function _function;
90
91 public:
92 ZBasicOopIterateClosure(Function function)
93 : _function(function) {}
94
95 virtual void do_oop(oop* p) {
96 _function((volatile zpointer*)p);
97 }
98
99 virtual void do_oop(narrowOop* p_) {
100 ShouldNotReachHere();
101 }
102 };
103
|