Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/memory/genOopClosures.inline.hpp
32285 views
/*1* Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_VM_MEMORY_GENOOPCLOSURES_INLINE_HPP25#define SHARE_VM_MEMORY_GENOOPCLOSURES_INLINE_HPP2627#include "memory/cardTableRS.hpp"28#include "memory/defNewGeneration.hpp"29#include "memory/genCollectedHeap.hpp"30#include "memory/genOopClosures.hpp"31#include "memory/genRemSet.hpp"32#include "memory/generation.hpp"33#include "memory/sharedHeap.hpp"34#include "memory/space.hpp"3536inline OopsInGenClosure::OopsInGenClosure(Generation* gen) :37ExtendedOopClosure(gen->ref_processor()), _orig_gen(gen), _rs(NULL) {38set_generation(gen);39}4041inline void OopsInGenClosure::set_generation(Generation* gen) {42_gen = gen;43_gen_boundary = _gen->reserved().start();44// Barrier set for the heap, must be set after heap is initialized45if (_rs == NULL) {46GenRemSet* rs = SharedHeap::heap()->rem_set();47assert(rs->rs_kind() == GenRemSet::CardTable, "Wrong rem set kind");48_rs = (CardTableRS*)rs;49}50}5152template <class T> inline void OopsInGenClosure::do_barrier(T* p) {53assert(generation()->is_in_reserved(p), "expected ref in generation");54T heap_oop = oopDesc::load_heap_oop(p);55assert(!oopDesc::is_null(heap_oop), "expected non-null oop");56oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);57// If p points to a younger generation, mark the card.58if ((HeapWord*)obj < _gen_boundary) {59_rs->inline_write_ref_field_gc(p, obj);60}61}6263template <class T> inline void OopsInGenClosure::par_do_barrier(T* p) {64assert(generation()->is_in_reserved(p), "expected ref in generation");65T heap_oop = oopDesc::load_heap_oop(p);66assert(!oopDesc::is_null(heap_oop), "expected non-null oop");67oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);68// If p points to a younger generation, mark the card.69if ((HeapWord*)obj < gen_boundary()) {70rs()->write_ref_field_gc_par(p, obj);71}72}7374inline void OopsInKlassOrGenClosure::do_klass_barrier() {75assert(_scanned_klass != NULL, "Must be");76_scanned_klass->record_modified_oops();77}7879// NOTE! Any changes made here should also be made80// in FastScanClosure::do_oop_work()81template <class T> inline void ScanClosure::do_oop_work(T* p) {82T heap_oop = oopDesc::load_heap_oop(p);83// Should we copy the obj?84if (!oopDesc::is_null(heap_oop)) {85oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);86if ((HeapWord*)obj < _boundary) {87assert(!_g->to()->is_in_reserved(obj), "Scanning field twice?");88oop new_obj = obj->is_forwarded() ? obj->forwardee()89: _g->copy_to_survivor_space(obj);90oopDesc::encode_store_heap_oop_not_null(p, new_obj);91}9293if (is_scanning_a_klass()) {94do_klass_barrier();95} else if (_gc_barrier) {96// Now call parent closure97do_barrier(p);98}99}100}101102inline void ScanClosure::do_oop_nv(oop* p) { ScanClosure::do_oop_work(p); }103inline void ScanClosure::do_oop_nv(narrowOop* p) { ScanClosure::do_oop_work(p); }104105// NOTE! Any changes made here should also be made106// in ScanClosure::do_oop_work()107template <class T> inline void FastScanClosure::do_oop_work(T* p) {108T heap_oop = oopDesc::load_heap_oop(p);109// Should we copy the obj?110if (!oopDesc::is_null(heap_oop)) {111oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);112if ((HeapWord*)obj < _boundary) {113assert(!_g->to()->is_in_reserved(obj), "Scanning field twice?");114oop new_obj = obj->is_forwarded() ? obj->forwardee()115: _g->copy_to_survivor_space(obj);116oopDesc::encode_store_heap_oop_not_null(p, new_obj);117if (is_scanning_a_klass()) {118do_klass_barrier();119} else if (_gc_barrier) {120// Now call parent closure121do_barrier(p);122}123}124}125}126127inline void FastScanClosure::do_oop_nv(oop* p) { FastScanClosure::do_oop_work(p); }128inline void FastScanClosure::do_oop_nv(narrowOop* p) { FastScanClosure::do_oop_work(p); }129130// Note similarity to ScanClosure; the difference is that131// the barrier set is taken care of outside this closure.132template <class T> inline void ScanWeakRefClosure::do_oop_work(T* p) {133assert(!oopDesc::is_null(*p), "null weak reference?");134oop obj = oopDesc::load_decode_heap_oop_not_null(p);135// weak references are sometimes scanned twice; must check136// that to-space doesn't already contain this object137if ((HeapWord*)obj < _boundary && !_g->to()->is_in_reserved(obj)) {138oop new_obj = obj->is_forwarded() ? obj->forwardee()139: _g->copy_to_survivor_space(obj);140oopDesc::encode_store_heap_oop_not_null(p, new_obj);141}142}143144inline void ScanWeakRefClosure::do_oop_nv(oop* p) { ScanWeakRefClosure::do_oop_work(p); }145inline void ScanWeakRefClosure::do_oop_nv(narrowOop* p) { ScanWeakRefClosure::do_oop_work(p); }146147#endif // SHARE_VM_MEMORY_GENOOPCLOSURES_INLINE_HPP148149150