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_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSSCAVENGE_INLINE_HPP
26 #define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSSCAVENGE_INLINE_HPP
27
28 #include "gc_implementation/parallelScavenge/cardTableExtension.hpp"
29 #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
30 #include "gc_implementation/parallelScavenge/psPromotionManager.hpp"
31 #include "gc_implementation/parallelScavenge/psPromotionManager.inline.hpp"
32 #include "gc_implementation/parallelScavenge/psScavenge.hpp"
33 #include "memory/iterator.hpp"
34 #include "utilities/globalDefinitions.hpp"
35
36 inline void PSScavenge::save_to_space_top_before_gc() {
37 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
38 _to_space_top_before_gc = heap->young_gen()->to_space()->top();
39 }
40
41 template <class T> inline bool PSScavenge::should_scavenge(T* p) {
42 T heap_oop = oopDesc::load_heap_oop(p);
43 return PSScavenge::is_obj_in_young(heap_oop);
44 }
45
46 template <class T>
47 inline bool PSScavenge::should_scavenge(T* p, MutableSpace* to_space) {
48 if (should_scavenge(p)) {
49 oop obj = oopDesc::load_decode_heap_oop_not_null(p);
50 // Skip objects copied to to_space since the scavenge started.
51 HeapWord* const addr = (HeapWord*)obj;
52 return addr < to_space_top_before_gc() || addr >= to_space->end();
53 }
54 return false;
55 }
56
57 template <class T>
58 inline bool PSScavenge::should_scavenge(T* p, bool check_to_space) {
59 if (check_to_space) {
60 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
61 return should_scavenge(p, heap->young_gen()->to_space());
62 }
63 return should_scavenge(p);
64 }
65
66 // Attempt to "claim" oop at p via CAS, push the new obj if successful
67 // This version tests the oop* to make sure it is within the heap before
68 // attempting marking.
69 template <class T, bool promote_immediately>
70 inline void PSScavenge::copy_and_push_safe_barrier(PSPromotionManager* pm,
71 T* p) {
72 assert(should_scavenge(p, true), "revisiting object?");
73
74 oop o = oopDesc::load_decode_heap_oop_not_null(p);
75 oop new_obj = o->is_forwarded()
76 ? o->forwardee()
77 : pm->copy_to_survivor_space<promote_immediately>(o);
78
79 #ifndef PRODUCT
80 // This code must come after the CAS test, or it will print incorrect
81 // information.
82 if (TraceScavenge && o->is_forwarded()) {
83 gclog_or_tty->print_cr("{%s %s " PTR_FORMAT " -> " PTR_FORMAT " (%d)}",
84 "forwarding",
85 new_obj->klass()->internal_name(), p2i((void *)o), p2i((void *)new_obj), new_obj->size());
86 }
87 #endif
88
89 oopDesc::encode_store_heap_oop_not_null(p, new_obj);
90
91 // We cannot mark without test, as some code passes us pointers
92 // that are outside the heap. These pointers are either from roots
93 // or from metadata.
94 if ((!PSScavenge::is_obj_in_young((HeapWord*)p)) &&
95 Universe::heap()->is_in_reserved(p)) {
96 if (PSScavenge::is_obj_in_young(new_obj)) {
97 card_table()->inline_write_ref_field_gc(p, new_obj);
98 }
99 }
100 }
101
102 template<bool promote_immediately>
103 class PSRootsClosure: public OopClosure {
104 private:
105 PSPromotionManager* _promotion_manager;
106
107 protected:
108 template <class T> void do_oop_work(T *p) {
109 if (PSScavenge::should_scavenge(p)) {
110 // We never card mark roots, maybe call a func without test?
111 PSScavenge::copy_and_push_safe_barrier<T, promote_immediately>(_promotion_manager, p);
112 }
113 }
114 public:
115 PSRootsClosure(PSPromotionManager* pm) : _promotion_manager(pm) { }
116 void do_oop(oop* p) { PSRootsClosure::do_oop_work(p); }
117 void do_oop(narrowOop* p) { PSRootsClosure::do_oop_work(p); }
118 };
119
120 typedef PSRootsClosure</*promote_immediately=*/false> PSScavengeRootsClosure;
121 typedef PSRootsClosure</*promote_immediately=*/true> PSPromoteRootsClosure;
122
123 // Scavenges a single oop in a Klass.
124 class PSScavengeFromKlassClosure: public OopClosure {
125 private:
126 PSPromotionManager* _pm;
127 // Used to redirty a scanned klass if it has oops
128 // pointing to the young generation after being scanned.
129 Klass* _scanned_klass;
130 public:
131 PSScavengeFromKlassClosure(PSPromotionManager* pm) : _pm(pm), _scanned_klass(NULL) { }
|
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_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSSCAVENGE_INLINE_HPP
26 #define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSSCAVENGE_INLINE_HPP
27
28 #include "gc_implementation/parallelScavenge/cardTableExtension.hpp"
29 #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
30 #include "gc_implementation/parallelScavenge/psPromotionManager.inline.hpp"
31 #include "gc_implementation/parallelScavenge/psScavenge.hpp"
32 #include "memory/iterator.hpp"
33 #include "utilities/globalDefinitions.hpp"
34
35 inline void PSScavenge::save_to_space_top_before_gc() {
36 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
37 _to_space_top_before_gc = heap->young_gen()->to_space()->top();
38 }
39
40 template <class T> inline bool PSScavenge::should_scavenge(T* p) {
41 T heap_oop = oopDesc::load_heap_oop(p);
42 return PSScavenge::is_obj_in_young(heap_oop);
43 }
44
45 template <class T>
46 inline bool PSScavenge::should_scavenge(T* p, MutableSpace* to_space) {
47 if (should_scavenge(p)) {
48 oop obj = oopDesc::load_decode_heap_oop_not_null(p);
49 // Skip objects copied to to_space since the scavenge started.
50 HeapWord* const addr = (HeapWord*)obj;
51 return addr < to_space_top_before_gc() || addr >= to_space->end();
52 }
53 return false;
54 }
55
56 template <class T>
57 inline bool PSScavenge::should_scavenge(T* p, bool check_to_space) {
58 if (check_to_space) {
59 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
60 return should_scavenge(p, heap->young_gen()->to_space());
61 }
62 return should_scavenge(p);
63 }
64
65 template<bool promote_immediately>
66 class PSRootsClosure: public OopClosure {
67 private:
68 PSPromotionManager* _promotion_manager;
69
70 protected:
71 template <class T> void do_oop_work(T *p) {
72 if (PSScavenge::should_scavenge(p)) {
73 // We never card mark roots, maybe call a func without test?
74 _promotion_manager->copy_and_push_safe_barrier<T, promote_immediately>(p);
75 }
76 }
77 public:
78 PSRootsClosure(PSPromotionManager* pm) : _promotion_manager(pm) { }
79 void do_oop(oop* p) { PSRootsClosure::do_oop_work(p); }
80 void do_oop(narrowOop* p) { PSRootsClosure::do_oop_work(p); }
81 };
82
83 typedef PSRootsClosure</*promote_immediately=*/false> PSScavengeRootsClosure;
84 typedef PSRootsClosure</*promote_immediately=*/true> PSPromoteRootsClosure;
85
86 // Scavenges a single oop in a Klass.
87 class PSScavengeFromKlassClosure: public OopClosure {
88 private:
89 PSPromotionManager* _pm;
90 // Used to redirty a scanned klass if it has oops
91 // pointing to the young generation after being scanned.
92 Klass* _scanned_klass;
93 public:
94 PSScavengeFromKlassClosure(PSPromotionManager* pm) : _pm(pm), _scanned_klass(NULL) { }
|