8201436: Replace oop_ps_push_contents with oop_iterate and closure

Reviewed-by: sjohanss, tschatzl
This commit is contained in:
Leo Korinth 2018-10-12 12:10:34 +02:00
parent ce05c7751d
commit 4bc903d17a
16 changed files with 171 additions and 222 deletions

View File

@ -28,7 +28,7 @@
#include "gc/parallel/parallelScavengeHeap.inline.hpp"
#include "gc/parallel/psCardTable.hpp"
#include "gc/parallel/psPromotionManager.inline.hpp"
#include "gc/parallel/psScavenge.hpp"
#include "gc/parallel/psScavenge.inline.hpp"
#include "gc/parallel/psTasks.hpp"
#include "gc/parallel/psYoungGen.hpp"
#include "memory/iterator.inline.hpp"

View File

@ -0,0 +1,121 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#ifndef SHARE_VM_GC_PARALLEL_PSCLOSURE_INLINE_HPP
#define SHARE_VM_GC_PARALLEL_PSCLOSURE_INLINE_HPP
#include "gc/parallel/psPromotionManager.inline.hpp"
#include "gc/parallel/psScavenge.inline.hpp"
#include "memory/iterator.hpp"
#include "oops/access.inline.hpp"
#include "oops/oop.inline.hpp"
#include "utilities/globalDefinitions.hpp"
template <bool promote_immediately>
class PSRootsClosure: public OopClosure {
private:
PSPromotionManager* _promotion_manager;
template <class T> void do_oop_work(T *p) {
if (PSScavenge::should_scavenge(p)) {
// We never card mark roots, maybe call a func without test?
_promotion_manager->copy_and_push_safe_barrier<T, promote_immediately>(p);
}
}
public:
PSRootsClosure(PSPromotionManager* pm) : _promotion_manager(pm) { }
void do_oop(oop* p) { PSRootsClosure::do_oop_work(p); }
void do_oop(narrowOop* p) { PSRootsClosure::do_oop_work(p); }
};
typedef PSRootsClosure</*promote_immediately=*/false> PSScavengeRootsClosure;
typedef PSRootsClosure</*promote_immediately=*/true> PSPromoteRootsClosure;
// Scavenges a single oop in a ClassLoaderData.
class PSScavengeFromCLDClosure: public OopClosure {
private:
PSPromotionManager* _pm;
// Used to redirty a scanned cld if it has oops
// pointing to the young generation after being scanned.
ClassLoaderData* _scanned_cld;
public:
PSScavengeFromCLDClosure(PSPromotionManager* pm) : _pm(pm), _scanned_cld(NULL) { }
void do_oop(narrowOop* p) { ShouldNotReachHere(); }
void do_oop(oop* p) {
ParallelScavengeHeap* psh = ParallelScavengeHeap::heap();
assert(!psh->is_in_reserved(p), "GC barrier needed");
if (PSScavenge::should_scavenge(p)) {
assert(PSScavenge::should_scavenge(p, true), "revisiting object?");
oop o = *p;
oop new_obj;
if (o->is_forwarded()) {
new_obj = o->forwardee();
} else {
new_obj = _pm->copy_to_survivor_space</*promote_immediately=*/false>(o);
}
RawAccess<IS_NOT_NULL>::oop_store(p, new_obj);
if (PSScavenge::is_obj_in_young(new_obj)) {
do_cld_barrier();
}
}
}
void set_scanned_cld(ClassLoaderData* cld) {
assert(_scanned_cld == NULL || cld == NULL, "Should always only handling one cld at a time");
_scanned_cld = cld;
}
private:
void do_cld_barrier() {
assert(_scanned_cld != NULL, "Should not be called without having a scanned cld");
_scanned_cld->record_modified_oops();
}
};
// Scavenges the oop in a ClassLoaderData.
class PSScavengeCLDClosure: public CLDClosure {
private:
PSScavengeFromCLDClosure _oop_closure;
public:
PSScavengeCLDClosure(PSPromotionManager* pm) : _oop_closure(pm) { }
void do_cld(ClassLoaderData* cld) {
// If the cld has not been dirtied we know that there's
// no references into the young gen and we can skip it.
if (cld->has_modified_oops()) {
// Setup the promotion manager to redirty this cld
// if references are left in the young gen.
_oop_closure.set_scanned_cld(cld);
// Clean the cld since we're going to scavenge all the metadata.
cld->oops_do(&_oop_closure, false, /*clear_modified_oops*/true);
_oop_closure.set_scanned_cld(NULL);
}
}
};
#endif

View File

@ -41,14 +41,7 @@
#include "memory/padded.inline.hpp"
#include "memory/resourceArea.hpp"
#include "oops/access.inline.hpp"
#include "oops/arrayOop.inline.hpp"
#include "oops/compressedOops.inline.hpp"
#include "oops/instanceClassLoaderKlass.inline.hpp"
#include "oops/instanceKlass.inline.hpp"
#include "oops/instanceMirrorKlass.inline.hpp"
#include "oops/objArrayKlass.inline.hpp"
#include "oops/objArrayOop.inline.hpp"
#include "oops/oop.inline.hpp"
PaddedEnd<PSPromotionManager>* PSPromotionManager::_manager_array = NULL;
OopStarTaskQueueSet* PSPromotionManager::_stack_array_depth = NULL;
@ -397,101 +390,6 @@ void PSPromotionManager::process_array_chunk(oop old) {
}
}
class PushContentsClosure : public BasicOopIterateClosure {
PSPromotionManager* _pm;
public:
PushContentsClosure(PSPromotionManager* pm) : _pm(pm) {}
template <typename T> void do_oop_work(T* p) {
if (PSScavenge::should_scavenge(p)) {
_pm->claim_or_forward_depth(p);
}
}
virtual void do_oop(oop* p) { do_oop_work(p); }
virtual void do_oop(narrowOop* p) { do_oop_work(p); }
// Don't use the oop verification code in the oop_oop_iterate framework.
debug_only(virtual bool should_verify_oops() { return false; })
};
void InstanceKlass::oop_ps_push_contents(oop obj, PSPromotionManager* pm) {
PushContentsClosure cl(pm);
if (UseCompressedOops) {
oop_oop_iterate_oop_maps_reverse<narrowOop>(obj, &cl);
} else {
oop_oop_iterate_oop_maps_reverse<oop>(obj, &cl);
}
}
void InstanceMirrorKlass::oop_ps_push_contents(oop obj, PSPromotionManager* pm) {
// Note that we don't have to follow the mirror -> klass pointer, since all
// klasses that are dirty will be scavenged when we iterate over the
// ClassLoaderData objects.
InstanceKlass::oop_ps_push_contents(obj, pm);
PushContentsClosure cl(pm);
if (UseCompressedOops) {
oop_oop_iterate_statics<narrowOop>(obj, &cl);
} else {
oop_oop_iterate_statics<oop>(obj, &cl);
}
}
void InstanceClassLoaderKlass::oop_ps_push_contents(oop obj, PSPromotionManager* pm) {
InstanceKlass::oop_ps_push_contents(obj, pm);
// This is called by the young collector. It will already have taken care of
// all class loader data. So, we don't have to follow the class loader ->
// class loader data link.
}
template <class T>
static void oop_ps_push_contents_specialized(oop obj, InstanceRefKlass *klass, PSPromotionManager* pm) {
T* referent_addr = (T*)java_lang_ref_Reference::referent_addr_raw(obj);
if (PSScavenge::should_scavenge(referent_addr)) {
ReferenceProcessor* rp = PSScavenge::reference_processor();
if (rp->discover_reference(obj, klass->reference_type())) {
// reference discovered, referent will be traversed later.
klass->InstanceKlass::oop_ps_push_contents(obj, pm);
return;
} else {
// treat referent as normal oop
pm->claim_or_forward_depth(referent_addr);
}
}
// Treat discovered as normal oop
T* discovered_addr = (T*)java_lang_ref_Reference::discovered_addr_raw(obj);
if (PSScavenge::should_scavenge(discovered_addr)) {
pm->claim_or_forward_depth(discovered_addr);
}
klass->InstanceKlass::oop_ps_push_contents(obj, pm);
}
void InstanceRefKlass::oop_ps_push_contents(oop obj, PSPromotionManager* pm) {
if (UseCompressedOops) {
oop_ps_push_contents_specialized<narrowOop>(obj, this, pm);
} else {
oop_ps_push_contents_specialized<oop>(obj, this, pm);
}
}
void ObjArrayKlass::oop_ps_push_contents(oop obj, PSPromotionManager* pm) {
assert(obj->is_objArray(), "obj must be obj array");
PushContentsClosure cl(pm);
if (UseCompressedOops) {
oop_oop_iterate_elements<narrowOop>(objArrayOop(obj), &cl);
} else {
oop_oop_iterate_elements<oop>(objArrayOop(obj), &cl);
}
}
void TypeArrayKlass::oop_ps_push_contents(oop obj, PSPromotionManager* pm) {
assert(obj->is_typeArray(),"must be a type array");
ShouldNotReachHere();
}
oop PSPromotionManager::oop_promotion_failed(oop obj, markOop obj_mark) {
assert(_old_gen_is_full || PromotionFailureALot, "Sanity");

View File

@ -30,9 +30,10 @@
#include "gc/parallel/psOldGen.hpp"
#include "gc/parallel/psPromotionLAB.inline.hpp"
#include "gc/parallel/psPromotionManager.hpp"
#include "gc/parallel/psScavenge.hpp"
#include "gc/parallel/psScavenge.inline.hpp"
#include "gc/shared/taskqueue.inline.hpp"
#include "logging/log.hpp"
#include "memory/iterator.inline.hpp"
#include "oops/access.inline.hpp"
#include "oops/oop.inline.hpp"
@ -99,8 +100,48 @@ inline void PSPromotionManager::promotion_trace_event(oop new_obj, oop old_obj,
}
}
class PSPushContentsClosure: public BasicOopIterateClosure {
PSPromotionManager* _pm;
public:
PSPushContentsClosure(PSPromotionManager* pm) : BasicOopIterateClosure(PSScavenge::reference_processor()), _pm(pm) {}
template <typename T> void do_oop_nv(T* p) {
if (PSScavenge::should_scavenge(p)) {
_pm->claim_or_forward_depth(p);
}
}
virtual void do_oop(oop* p) { do_oop_nv(p); }
virtual void do_oop(narrowOop* p) { do_oop_nv(p); }
// Don't use the oop verification code in the oop_oop_iterate framework.
debug_only(virtual bool should_verify_oops() { return false; })
};
//
// This closure specialization will override the one that is defined in
// instanceRefKlass.inline.cpp. It swaps the order of oop_oop_iterate and
// oop_oop_iterate_ref_processing. Unfortunately G1 and Parallel behaves
// significantly better (especially in the Derby benchmark) using opposite
// order of these function calls.
//
template <>
inline void InstanceRefKlass::oop_oop_iterate_reverse<oop, PSPushContentsClosure>(oop obj, PSPushContentsClosure* closure) {
oop_oop_iterate_ref_processing<oop>(obj, closure);
InstanceKlass::oop_oop_iterate_reverse<oop>(obj, closure);
}
template <>
inline void InstanceRefKlass::oop_oop_iterate_reverse<narrowOop, PSPushContentsClosure>(oop obj, PSPushContentsClosure* closure) {
oop_oop_iterate_ref_processing<narrowOop>(obj, closure);
InstanceKlass::oop_oop_iterate_reverse<narrowOop>(obj, closure);
}
inline void PSPromotionManager::push_contents(oop obj) {
obj->ps_push_contents(this);
if (!obj->klass()->is_typeArray_klass()) {
PSPushContentsClosure pcc(this);
obj->oop_iterate_backwards(&pcc);
}
}
//
// This method is pretty bulky. It would be nice to split it up

View File

@ -28,8 +28,10 @@
#include "gc/parallel/gcTaskManager.hpp"
#include "gc/parallel/parallelScavengeHeap.hpp"
#include "gc/parallel/psAdaptiveSizePolicy.hpp"
#include "gc/parallel/psClosure.inline.hpp"
#include "gc/parallel/psMarkSweepProxy.hpp"
#include "gc/parallel/psParallelCompact.inline.hpp"
#include "gc/parallel/psPromotionManager.inline.hpp"
#include "gc/parallel/psScavenge.inline.hpp"
#include "gc/parallel/psTasks.hpp"
#include "gc/shared/collectorPolicy.hpp"

View File

@ -26,7 +26,6 @@
#define SHARE_VM_GC_PARALLEL_PSSCAVENGE_INLINE_HPP
#include "gc/parallel/parallelScavengeHeap.hpp"
#include "gc/parallel/psPromotionManager.inline.hpp"
#include "gc/parallel/psScavenge.hpp"
#include "logging/log.hpp"
#include "memory/iterator.hpp"
@ -65,93 +64,4 @@ inline bool PSScavenge::should_scavenge(T* p, bool check_to_space) {
return should_scavenge(p);
}
template<bool promote_immediately>
class PSRootsClosure: public OopClosure {
private:
PSPromotionManager* _promotion_manager;
protected:
template <class T> void do_oop_work(T *p) {
if (PSScavenge::should_scavenge(p)) {
// We never card mark roots, maybe call a func without test?
_promotion_manager->copy_and_push_safe_barrier<T, promote_immediately>(p);
}
}
public:
PSRootsClosure(PSPromotionManager* pm) : _promotion_manager(pm) { }
void do_oop(oop* p) { PSRootsClosure::do_oop_work(p); }
void do_oop(narrowOop* p) { PSRootsClosure::do_oop_work(p); }
};
typedef PSRootsClosure</*promote_immediately=*/false> PSScavengeRootsClosure;
typedef PSRootsClosure</*promote_immediately=*/true> PSPromoteRootsClosure;
// Scavenges a single oop in a ClassLoaderData.
class PSScavengeFromCLDClosure: public OopClosure {
private:
PSPromotionManager* _pm;
// Used to redirty a scanned cld if it has oops
// pointing to the young generation after being scanned.
ClassLoaderData* _scanned_cld;
public:
PSScavengeFromCLDClosure(PSPromotionManager* pm) : _pm(pm), _scanned_cld(NULL) { }
void do_oop(narrowOop* p) { ShouldNotReachHere(); }
void do_oop(oop* p) {
ParallelScavengeHeap* psh = ParallelScavengeHeap::heap();
assert(!psh->is_in_reserved(p), "GC barrier needed");
if (PSScavenge::should_scavenge(p)) {
assert(PSScavenge::should_scavenge(p, true), "revisiting object?");
oop o = *p;
oop new_obj;
if (o->is_forwarded()) {
new_obj = o->forwardee();
} else {
new_obj = _pm->copy_to_survivor_space</*promote_immediately=*/false>(o);
}
RawAccess<IS_NOT_NULL>::oop_store(p, new_obj);
if (PSScavenge::is_obj_in_young(new_obj)) {
do_cld_barrier();
}
}
}
void set_scanned_cld(ClassLoaderData* cld) {
assert(_scanned_cld == NULL || cld == NULL, "Should always only handling one cld at a time");
_scanned_cld = cld;
}
private:
void do_cld_barrier() {
assert(_scanned_cld != NULL, "Should not be called without having a scanned cld");
_scanned_cld->record_modified_oops();
}
};
// Scavenges the oop in a ClassLoaderData.
class PSScavengeCLDClosure: public CLDClosure {
private:
PSScavengeFromCLDClosure _oop_closure;
protected:
public:
PSScavengeCLDClosure(PSPromotionManager* pm) : _oop_closure(pm) { }
void do_cld(ClassLoaderData* cld) {
// If the cld has not been dirtied we know that there's
// no references into the young gen and we can skip it.
if (cld->has_modified_oops()) {
// Setup the promotion manager to redirty this cld
// if references are left in the young gen.
_oop_closure.set_scanned_cld(cld);
// Clean the cld since we're going to scavenge all the metadata.
cld->oops_do(&_oop_closure, false, /*clear_modified_oops*/true);
_oop_closure.set_scanned_cld(NULL);
}
}
};
#endif // SHARE_VM_GC_PARALLEL_PSSCAVENGE_INLINE_HPP

View File

@ -29,6 +29,7 @@
#include "code/codeCache.hpp"
#include "gc/parallel/gcTaskManager.hpp"
#include "gc/parallel/psCardTable.hpp"
#include "gc/parallel/psClosure.inline.hpp"
#include "gc/parallel/psPromotionManager.hpp"
#include "gc/parallel/psPromotionManager.inline.hpp"
#include "gc/parallel/psScavenge.inline.hpp"

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -51,8 +51,6 @@ public:
// GC specific object visitors
//
#if INCLUDE_PARALLELGC
// Parallel Scavenge
void oop_ps_push_contents( oop obj, PSPromotionManager* pm);
// Parallel Compact
void oop_pc_follow_contents(oop obj, ParCompactionManager* cm);
void oop_pc_update_pointers(oop obj, ParCompactionManager* cm);

View File

@ -1186,8 +1186,6 @@ public:
// GC specific object visitors
//
#if INCLUDE_PARALLELGC
// Parallel Scavenge
void oop_ps_push_contents( oop obj, PSPromotionManager* pm);
// Parallel Compact
void oop_pc_follow_contents(oop obj, ParCompactionManager* cm);
void oop_pc_update_pointers(oop obj, ParCompactionManager* cm);

View File

@ -92,8 +92,6 @@ class InstanceMirrorKlass: public InstanceKlass {
// GC specific object visitors
//
#if INCLUDE_PARALLELGC
// Parallel Scavenge
void oop_ps_push_contents( oop obj, PSPromotionManager* pm);
// Parallel Compact
void oop_pc_follow_contents(oop obj, ParCompactionManager* cm);
void oop_pc_update_pointers(oop obj, ParCompactionManager* cm);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -61,8 +61,6 @@ class InstanceRefKlass: public InstanceKlass {
// GC specific object visitors
//
#if INCLUDE_PARALLELGC
// Parallel Scavenge
void oop_ps_push_contents( oop obj, PSPromotionManager* pm);
// Parallel Compact
void oop_pc_follow_contents(oop obj, ParCompactionManager* cm);
void oop_pc_update_pointers(oop obj, ParCompactionManager* cm);

View File

@ -676,8 +676,6 @@ protected:
// GC specific object visitors
//
#if INCLUDE_PARALLELGC
// Parallel Scavenge
virtual void oop_ps_push_contents( oop obj, PSPromotionManager* pm) = 0;
// Parallel Compact
virtual void oop_pc_follow_contents(oop obj, ParCompactionManager* cm) = 0;
virtual void oop_pc_update_pointers(oop obj, ParCompactionManager* cm) = 0;

View File

@ -123,8 +123,6 @@ class ObjArrayKlass : public ArrayKlass {
// GC specific object visitors
//
#if INCLUDE_PARALLELGC
// Parallel Scavenge
void oop_ps_push_contents( oop obj, PSPromotionManager* pm);
// Parallel Compact
void oop_pc_follow_contents(oop obj, ParCompactionManager* cm);
void oop_pc_update_pointers(oop obj, ParCompactionManager* cm);

View File

@ -291,8 +291,6 @@ class oopDesc {
// Parallel Compact
inline void pc_follow_contents(ParCompactionManager* cm);
inline void pc_update_contents(ParCompactionManager* cm);
// Parallel Scavenge
inline void ps_push_contents(PSPromotionManager* pm);
#endif
template <typename OopClosureType>

View File

@ -439,15 +439,6 @@ void oopDesc::pc_update_contents(ParCompactionManager* cm) {
}
// Else skip it. The TypeArrayKlass in the header never needs scavenging.
}
void oopDesc::ps_push_contents(PSPromotionManager* pm) {
Klass* k = klass();
if (!k->is_typeArray_klass()) {
// It might contain oops beyond the header, so take the virtual call.
k->oop_ps_push_contents(this, pm);
}
// Else skip it. The TypeArrayKlass in the header never needs scavenging.
}
#endif // INCLUDE_PARALLELGC
template <typename OopClosureType>

View File

@ -76,9 +76,8 @@ class TypeArrayKlass : public ArrayKlass {
// GC specific object visitors
//
#if INCLUDE_PARALLELGC
// Parallel Scavenge
void oop_ps_push_contents( oop obj, PSPromotionManager* pm);
// Parallel Compact
void oop_pc_follow_contents(oop obj, ParCompactionManager* cm);
void oop_pc_update_pointers(oop obj, ParCompactionManager* cm);