1 /* 2 * Copyright (c) 2000, 2019, 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_GC_SERIAL_MARKSWEEP_INLINE_HPP 26 #define SHARE_GC_SERIAL_MARKSWEEP_INLINE_HPP 27 28 #include "gc/serial/markSweep.hpp" 29 30 #include "classfile/classLoaderData.inline.hpp" 31 #include "gc/shared/slidingForwarding.inline.hpp" 32 #include "memory/universe.hpp" 33 #include "oops/markWord.inline.hpp" 34 #include "oops/access.inline.hpp" 35 #include "oops/compressedOops.inline.hpp" 36 #include "oops/oop.inline.hpp" 37 #include "utilities/align.hpp" 38 #include "utilities/stack.inline.hpp" 39 40 inline void MarkSweep::mark_object(oop obj) { 41 // some marks may contain information we need to preserve so we store them away 42 // and overwrite the mark. We'll restore it at the end of markSweep. 43 markWord mark = obj->mark(); 44 obj->set_mark(obj->prototype_mark().set_marked()); 45 46 if (obj->mark_must_be_preserved(mark)) { 47 preserve_mark(obj, mark); 48 } 49 } 50 51 template <class T> inline void MarkSweep::mark_and_push(T* p) { 52 T heap_oop = RawAccess<>::oop_load(p); 53 if (!CompressedOops::is_null(heap_oop)) { 54 oop obj = CompressedOops::decode_not_null(heap_oop); 55 if (!obj->mark().is_marked()) { 56 mark_object(obj); 57 _marking_stack.push(obj); 58 } 59 } 60 } 61 62 inline void MarkSweep::follow_klass(Klass* klass) { 63 oop op = klass->class_loader_data()->holder_no_keepalive(); 64 MarkSweep::mark_and_push(&op); 65 } 66 67 inline void MarkSweep::follow_cld(ClassLoaderData* cld) { 68 MarkSweep::follow_cld_closure.do_cld(cld); 69 } 70 71 template <typename T> 72 inline void MarkAndPushClosure::do_oop_work(T* p) { MarkSweep::mark_and_push(p); } 73 inline void MarkAndPushClosure::do_oop(oop* p) { do_oop_work(p); } 74 inline void MarkAndPushClosure::do_oop(narrowOop* p) { do_oop_work(p); } 75 inline void MarkAndPushClosure::do_klass(Klass* k) { MarkSweep::follow_klass(k); } 76 inline void MarkAndPushClosure::do_cld(ClassLoaderData* cld) { MarkSweep::follow_cld(cld); } 77 78 template <bool ALT_FWD, class T> 79 inline void MarkSweep::adjust_pointer(T* p) { 80 T heap_oop = RawAccess<>::oop_load(p); 81 if (!CompressedOops::is_null(heap_oop)) { 82 oop obj = CompressedOops::decode_not_null(heap_oop); 83 assert(Universe::heap()->is_in(obj), "should be in heap"); 84 85 if (SlidingForwarding::is_forwarded(obj)) { 86 oop new_obj = SlidingForwarding::forwardee<ALT_FWD>(obj); 87 assert(new_obj != NULL, "must be forwarded"); 88 assert(is_object_aligned(new_obj), "oop must be aligned"); 89 RawAccess<IS_NOT_NULL>::oop_store(p, new_obj); 90 } 91 } 92 } 93 94 template <bool ALT_FWD> 95 template <typename T> 96 void AdjustPointerClosure<ALT_FWD>::do_oop_work(T* p) { MarkSweep::adjust_pointer<ALT_FWD>(p); } 97 98 template <bool ALT_FWD> 99 inline void AdjustPointerClosure<ALT_FWD>::do_oop(oop* p) { do_oop_work(p); } 100 101 template <bool ALT_FWD> 102 inline void AdjustPointerClosure<ALT_FWD>::do_oop(narrowOop* p) { do_oop_work(p); } 103 104 template <bool ALT_FWD> 105 inline int MarkSweep::adjust_pointers(oop obj) { 106 AdjustPointerClosure<ALT_FWD> adjust_pointer_closure; 107 return obj->oop_iterate_size(&adjust_pointer_closure); 108 } 109 110 #endif // SHARE_GC_SERIAL_MARKSWEEP_INLINE_HPP