Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/gc_implementation/parNew/parOopClosures.inline.hpp
38920 views
/*1* Copyright (c) 2007, 2014, 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_GC_IMPLEMENTATION_PARNEW_PAROOPCLOSURES_INLINE_HPP25#define SHARE_VM_GC_IMPLEMENTATION_PARNEW_PAROOPCLOSURES_INLINE_HPP2627#include "gc_implementation/parNew/parNewGeneration.hpp"28#include "gc_implementation/parNew/parOopClosures.hpp"29#include "memory/cardTableRS.hpp"3031template <class T> inline void ParScanWeakRefClosure::do_oop_work(T* p) {32assert (!oopDesc::is_null(*p), "null weak reference?");33oop obj = oopDesc::load_decode_heap_oop_not_null(p);34// weak references are sometimes scanned twice; must check35// that to-space doesn't already contain this object36if ((HeapWord*)obj < _boundary && !_g->to()->is_in_reserved(obj)) {37// we need to ensure that it is copied (see comment in38// ParScanClosure::do_oop_work).39Klass* objK = obj->klass();40markOop m = obj->mark();41oop new_obj;42if (m->is_marked()) { // Contains forwarding pointer.43new_obj = ParNewGeneration::real_forwardee(obj);44} else {45size_t obj_sz = obj->size_given_klass(objK);46new_obj = ((ParNewGeneration*)_g)->copy_to_survivor_space(_par_scan_state,47obj, obj_sz, m);48}49oopDesc::encode_store_heap_oop_not_null(p, new_obj);50}51}5253inline void ParScanWeakRefClosure::do_oop_nv(oop* p) { ParScanWeakRefClosure::do_oop_work(p); }54inline void ParScanWeakRefClosure::do_oop_nv(narrowOop* p) { ParScanWeakRefClosure::do_oop_work(p); }5556template <class T> inline void ParScanClosure::par_do_barrier(T* p) {57assert(generation()->is_in_reserved(p), "expected ref in generation");58assert(!oopDesc::is_null(*p), "expected non-null object");59oop obj = oopDesc::load_decode_heap_oop_not_null(p);60// If p points to a younger generation, mark the card.61if ((HeapWord*)obj < gen_boundary()) {62rs()->write_ref_field_gc_par(p, obj);63}64}6566template <class T>67inline void ParScanClosure::do_oop_work(T* p,68bool gc_barrier,69bool root_scan) {70assert((!Universe::heap()->is_in_reserved(p) ||71generation()->is_in_reserved(p))72&& (generation()->level() == 0 || gc_barrier),73"The gen must be right, and we must be doing the barrier "74"in older generations.");75T heap_oop = oopDesc::load_heap_oop(p);76if (!oopDesc::is_null(heap_oop)) {77oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);78if ((HeapWord*)obj < _boundary) {79#ifndef PRODUCT80if (_g->to()->is_in_reserved(obj)) {81tty->print_cr("Scanning field (" PTR_FORMAT ") twice?", p2i(p));82GenCollectedHeap* gch = (GenCollectedHeap*)Universe::heap();83Space* sp = gch->space_containing(p);84oop obj = oop(sp->block_start(p));85assert((HeapWord*)obj < (HeapWord*)p, "Error");86tty->print_cr("Object: " PTR_FORMAT, p2i((void *)obj));87tty->print_cr("-------");88obj->print();89tty->print_cr("-----");90tty->print_cr("Heap:");91tty->print_cr("-----");92gch->print();93ShouldNotReachHere();94}95#endif96// OK, we need to ensure that it is copied.97// We read the klass and mark in this order, so that we can reliably98// get the size of the object: if the mark we read is not a99// forwarding pointer, then the klass is valid: the klass is only100// overwritten with an overflow next pointer after the object is101// forwarded.102Klass* objK = obj->klass();103markOop m = obj->mark();104oop new_obj;105if (m->is_marked()) { // Contains forwarding pointer.106new_obj = ParNewGeneration::real_forwardee(obj);107oopDesc::encode_store_heap_oop_not_null(p, new_obj);108#ifndef PRODUCT109if (TraceScavenge) {110gclog_or_tty->print_cr("{%s %s ( " PTR_FORMAT " ) " PTR_FORMAT " -> " PTR_FORMAT " (%d)}",111"forwarded ",112new_obj->klass()->internal_name(), p2i(p), p2i((void *)obj), p2i((void *)new_obj), new_obj->size());113}114#endif115116} else {117size_t obj_sz = obj->size_given_klass(objK);118new_obj = _g->copy_to_survivor_space(_par_scan_state, obj, obj_sz, m);119oopDesc::encode_store_heap_oop_not_null(p, new_obj);120if (root_scan) {121// This may have pushed an object. If we have a root122// category with a lot of roots, can't let the queue get too123// full:124(void)_par_scan_state->trim_queues(10 * ParallelGCThreads);125}126}127if (is_scanning_a_klass()) {128do_klass_barrier();129} else if (gc_barrier) {130// Now call parent closure131par_do_barrier(p);132}133}134}135}136137inline void ParScanWithBarrierClosure::do_oop_nv(oop* p) { ParScanClosure::do_oop_work(p, true, false); }138inline void ParScanWithBarrierClosure::do_oop_nv(narrowOop* p) { ParScanClosure::do_oop_work(p, true, false); }139140inline void ParScanWithoutBarrierClosure::do_oop_nv(oop* p) { ParScanClosure::do_oop_work(p, false, false); }141inline void ParScanWithoutBarrierClosure::do_oop_nv(narrowOop* p) { ParScanClosure::do_oop_work(p, false, false); }142143#endif // SHARE_VM_GC_IMPLEMENTATION_PARNEW_PAROOPCLOSURES_INLINE_HPP144145146