src/share/vm/gc_implementation/parallelScavenge/psScavenge.inline.hpp

Mon, 12 Aug 2019 18:30:40 +0300

author
apetushkov
date
Mon, 12 Aug 2019 18:30:40 +0300
changeset 9858
b985cbb00e68
parent 6680
78bbf4d43a14
child 6876
710a3c8b516e
permissions
-rw-r--r--

8223147: JFR Backport
8199712: Flight Recorder
8203346: JFR: Inconsistent signature of jfr_add_string_constant
8195817: JFR.stop should require name of recording
8195818: JFR.start should increase autogenerated name by one
8195819: Remove recording=x from jcmd JFR.check output
8203921: JFR thread sampling is missing fixes from JDK-8194552
8203929: Limit amount of data for JFR.dump
8203664: JFR start failure after AppCDS archive created with JFR StartFlightRecording
8003209: JFR events for network utilization
8207392: [PPC64] Implement JFR profiling
8202835: jfr/event/os/TestSystemProcess.java fails on missing events
Summary: Backport JFR from JDK11. Initial integration
Reviewed-by: neugens

duke@435 1 /*
drchase@6680 2 * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSSCAVENGE_INLINE_HPP
stefank@2314 26 #define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSSCAVENGE_INLINE_HPP
stefank@2314 27
stefank@2314 28 #include "gc_implementation/parallelScavenge/cardTableExtension.hpp"
stefank@2314 29 #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
stefank@2314 30 #include "gc_implementation/parallelScavenge/psPromotionManager.hpp"
iveresov@3536 31 #include "gc_implementation/parallelScavenge/psPromotionManager.inline.hpp"
stefank@2314 32 #include "gc_implementation/parallelScavenge/psScavenge.hpp"
coleenp@4037 33 #include "memory/iterator.hpp"
stefank@2314 34
duke@435 35 inline void PSScavenge::save_to_space_top_before_gc() {
duke@435 36 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
duke@435 37 _to_space_top_before_gc = heap->young_gen()->to_space()->top();
duke@435 38 }
duke@435 39
coleenp@548 40 template <class T> inline bool PSScavenge::should_scavenge(T* p) {
coleenp@548 41 T heap_oop = oopDesc::load_heap_oop(p);
stefank@5202 42 return PSScavenge::is_obj_in_young(heap_oop);
duke@435 43 }
duke@435 44
coleenp@548 45 template <class T>
coleenp@548 46 inline bool PSScavenge::should_scavenge(T* p, MutableSpace* to_space) {
duke@435 47 if (should_scavenge(p)) {
coleenp@548 48 oop obj = oopDesc::load_decode_heap_oop_not_null(p);
duke@435 49 // Skip objects copied to to_space since the scavenge started.
coleenp@548 50 HeapWord* const addr = (HeapWord*)obj;
duke@435 51 return addr < to_space_top_before_gc() || addr >= to_space->end();
duke@435 52 }
duke@435 53 return false;
duke@435 54 }
duke@435 55
coleenp@548 56 template <class T>
coleenp@548 57 inline bool PSScavenge::should_scavenge(T* p, bool check_to_space) {
duke@435 58 if (check_to_space) {
coleenp@548 59 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
duke@435 60 return should_scavenge(p, heap->young_gen()->to_space());
duke@435 61 }
duke@435 62 return should_scavenge(p);
duke@435 63 }
duke@435 64
duke@435 65 // Attempt to "claim" oop at p via CAS, push the new obj if successful
duke@435 66 // This version tests the oop* to make sure it is within the heap before
duke@435 67 // attempting marking.
iveresov@3536 68 template <class T, bool promote_immediately>
duke@435 69 inline void PSScavenge::copy_and_push_safe_barrier(PSPromotionManager* pm,
coleenp@548 70 T* p) {
coleenp@548 71 assert(should_scavenge(p, true), "revisiting object?");
duke@435 72
coleenp@548 73 oop o = oopDesc::load_decode_heap_oop_not_null(p);
coleenp@548 74 oop new_obj = o->is_forwarded()
coleenp@548 75 ? o->forwardee()
iveresov@3536 76 : pm->copy_to_survivor_space<promote_immediately>(o);
coleenp@4037 77
coleenp@4037 78 #ifndef PRODUCT
coleenp@4037 79 // This code must come after the CAS test, or it will print incorrect
coleenp@4037 80 // information.
coleenp@4037 81 if (TraceScavenge && o->is_forwarded()) {
coleenp@4037 82 gclog_or_tty->print_cr("{%s %s " PTR_FORMAT " -> " PTR_FORMAT " (%d)}",
coleenp@4037 83 "forwarding",
drchase@6680 84 new_obj->klass()->internal_name(), p2i((void *)o), p2i((void *)new_obj), new_obj->size());
coleenp@4037 85 }
coleenp@4037 86 #endif
coleenp@4037 87
coleenp@548 88 oopDesc::encode_store_heap_oop_not_null(p, new_obj);
duke@435 89
duke@435 90 // We cannot mark without test, as some code passes us pointers
coleenp@4037 91 // that are outside the heap. These pointers are either from roots
coleenp@4037 92 // or from metadata.
coleenp@548 93 if ((!PSScavenge::is_obj_in_young((HeapWord*)p)) &&
duke@435 94 Universe::heap()->is_in_reserved(p)) {
stefank@5202 95 if (PSScavenge::is_obj_in_young(new_obj)) {
coleenp@548 96 card_table()->inline_write_ref_field_gc(p, new_obj);
duke@435 97 }
duke@435 98 }
duke@435 99 }
stefank@2314 100
iveresov@3536 101 template<bool promote_immediately>
iveresov@3536 102 class PSRootsClosure: public OopClosure {
jcoomes@2661 103 private:
jcoomes@2661 104 PSPromotionManager* _promotion_manager;
jcoomes@2661 105
jcoomes@2661 106 protected:
jcoomes@2661 107 template <class T> void do_oop_work(T *p) {
jcoomes@2661 108 if (PSScavenge::should_scavenge(p)) {
jcoomes@2661 109 // We never card mark roots, maybe call a func without test?
iveresov@3536 110 PSScavenge::copy_and_push_safe_barrier<T, promote_immediately>(_promotion_manager, p);
jcoomes@2661 111 }
jcoomes@2661 112 }
jcoomes@2661 113 public:
iveresov@3536 114 PSRootsClosure(PSPromotionManager* pm) : _promotion_manager(pm) { }
iveresov@3536 115 void do_oop(oop* p) { PSRootsClosure::do_oop_work(p); }
iveresov@3536 116 void do_oop(narrowOop* p) { PSRootsClosure::do_oop_work(p); }
jcoomes@2661 117 };
jcoomes@2661 118
iveresov@3536 119 typedef PSRootsClosure</*promote_immediately=*/false> PSScavengeRootsClosure;
iveresov@3536 120 typedef PSRootsClosure</*promote_immediately=*/true> PSPromoteRootsClosure;
iveresov@3536 121
coleenp@4037 122 // Scavenges a single oop in a Klass.
coleenp@4037 123 class PSScavengeFromKlassClosure: public OopClosure {
coleenp@4037 124 private:
coleenp@4037 125 PSPromotionManager* _pm;
coleenp@4037 126 // Used to redirty a scanned klass if it has oops
coleenp@4037 127 // pointing to the young generation after being scanned.
coleenp@4037 128 Klass* _scanned_klass;
coleenp@4037 129 public:
coleenp@4037 130 PSScavengeFromKlassClosure(PSPromotionManager* pm) : _pm(pm), _scanned_klass(NULL) { }
coleenp@4037 131 void do_oop(narrowOop* p) { ShouldNotReachHere(); }
coleenp@4037 132 void do_oop(oop* p) {
coleenp@4037 133 ParallelScavengeHeap* psh = ParallelScavengeHeap::heap();
coleenp@4037 134 assert(!psh->is_in_reserved(p), "GC barrier needed");
coleenp@4037 135 if (PSScavenge::should_scavenge(p)) {
coleenp@4037 136 assert(!Universe::heap()->is_in_reserved(p), "Not from meta-data?");
coleenp@4037 137 assert(PSScavenge::should_scavenge(p, true), "revisiting object?");
coleenp@4037 138
coleenp@4037 139 oop o = *p;
coleenp@4037 140 oop new_obj;
coleenp@4037 141 if (o->is_forwarded()) {
coleenp@4037 142 new_obj = o->forwardee();
coleenp@4037 143 } else {
coleenp@4037 144 new_obj = _pm->copy_to_survivor_space</*promote_immediately=*/false>(o);
coleenp@4037 145 }
coleenp@4037 146 oopDesc::encode_store_heap_oop_not_null(p, new_obj);
coleenp@4037 147
stefank@5202 148 if (PSScavenge::is_obj_in_young(new_obj)) {
coleenp@4037 149 do_klass_barrier();
coleenp@4037 150 }
coleenp@4037 151 }
coleenp@4037 152 }
coleenp@4037 153
coleenp@4037 154 void set_scanned_klass(Klass* klass) {
coleenp@4037 155 assert(_scanned_klass == NULL || klass == NULL, "Should always only handling one klass at a time");
coleenp@4037 156 _scanned_klass = klass;
coleenp@4037 157 }
coleenp@4037 158
coleenp@4037 159 private:
coleenp@4037 160 void do_klass_barrier() {
coleenp@4037 161 assert(_scanned_klass != NULL, "Should not be called without having a scanned klass");
coleenp@4037 162 _scanned_klass->record_modified_oops();
coleenp@4037 163 }
coleenp@4037 164
coleenp@4037 165 };
coleenp@4037 166
coleenp@4037 167 // Scavenges the oop in a Klass.
coleenp@4037 168 class PSScavengeKlassClosure: public KlassClosure {
coleenp@4037 169 private:
coleenp@4037 170 PSScavengeFromKlassClosure _oop_closure;
coleenp@4037 171 protected:
coleenp@4037 172 public:
coleenp@4037 173 PSScavengeKlassClosure(PSPromotionManager* pm) : _oop_closure(pm) { }
coleenp@4037 174 void do_klass(Klass* klass) {
coleenp@4037 175 // If the klass has not been dirtied we know that there's
coleenp@4037 176 // no references into the young gen and we can skip it.
coleenp@4037 177
coleenp@4037 178 #ifndef PRODUCT
coleenp@4037 179 if (TraceScavenge) {
coleenp@4037 180 ResourceMark rm;
coleenp@4037 181 gclog_or_tty->print_cr("PSScavengeKlassClosure::do_klass %p, %s, dirty: %s",
coleenp@4037 182 klass,
coleenp@4037 183 klass->external_name(),
coleenp@4037 184 klass->has_modified_oops() ? "true" : "false");
coleenp@4037 185 }
coleenp@4037 186 #endif
coleenp@4037 187
coleenp@4037 188 if (klass->has_modified_oops()) {
coleenp@4037 189 // Clean the klass since we're going to scavenge all the metadata.
coleenp@4037 190 klass->clear_modified_oops();
coleenp@4037 191
coleenp@4037 192 // Setup the promotion manager to redirty this klass
coleenp@4037 193 // if references are left in the young gen.
coleenp@4037 194 _oop_closure.set_scanned_klass(klass);
coleenp@4037 195
coleenp@4037 196 klass->oops_do(&_oop_closure);
coleenp@4037 197
coleenp@4037 198 _oop_closure.set_scanned_klass(NULL);
coleenp@4037 199 }
coleenp@4037 200 }
coleenp@4037 201 };
coleenp@4037 202
stefank@2314 203 #endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSSCAVENGE_INLINE_HPP

mercurial