Skip to content

Commit

Permalink
8251570: JDK-8215624 causes assert(worker_id < _n_workers) failed: In…
Browse files Browse the repository at this point in the history
…valid worker_id

Reviewed-by: rschmelter, clanger
Backport-of: 2631422
  • Loading branch information
Bin Liao authored and RealCLanger committed Sep 8, 2021
1 parent 085dbe3 commit 1d1e4ce
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 43 deletions.
3 changes: 0 additions & 3 deletions src/hotspot/share/gc/cms/cmsHeap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ class CMSHeap : public GenCollectedHeap {

virtual void print_gc_threads_on(outputStream* st) const;
virtual void gc_threads_do(ThreadClosure* tc) const;
// Runs the given AbstractGangTask with the current active workers.
// No workGang for CmsHeap, work serially with thread 0
virtual void run_task(AbstractGangTask* task) { task->work(0); }
virtual void print_on_error(outputStream* st) const;

// Perform a full collection of the heap; intended for use in implementing
Expand Down
4 changes: 0 additions & 4 deletions src/hotspot/share/gc/epsilon/epsilonHeap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,6 @@ class EpsilonHeap : public CollectedHeap {
virtual void print_gc_threads_on(outputStream* st) const {}
virtual void gc_threads_do(ThreadClosure* tc) const {}

// Runs the given AbstractGangTask with the current active workers
// No workGang for EpsilonHeap, work serially with thread 0
virtual void run_task(AbstractGangTask* task) { task->work(0); }

// No heap verification
virtual void prepare_for_verify() {}
virtual void verify(VerifyOption option) {}
Expand Down
4 changes: 0 additions & 4 deletions src/hotspot/share/gc/g1/g1CollectedHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,6 @@ void G1RegionMappingChangedListener::on_commit(uint start_idx, size_t num_region
reset_from_card_cache(start_idx, num_regions);
}

void G1CollectedHeap::run_task(AbstractGangTask* task) {
workers()->run_task(task, workers()->active_workers());
}

HeapRegion* G1CollectedHeap::new_heap_region(uint hrs_index,
MemRegion mr) {
return new HeapRegion(hrs_index, bot(), mr);
Expand Down
3 changes: 0 additions & 3 deletions src/hotspot/share/gc/g1/g1CollectedHeap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,9 +528,6 @@ class G1CollectedHeap : public CollectedHeap {

WorkGang* workers() const { return _workers; }

// Runs the given AbstractGangTask with the current active workers.
virtual void run_task(AbstractGangTask* task);

G1Allocator* allocator() {
return _allocator;
}
Expand Down
6 changes: 0 additions & 6 deletions src/hotspot/share/gc/parallel/parallelScavengeHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -604,12 +604,6 @@ void ParallelScavengeHeap::print_gc_threads_on(outputStream* st) const {
PSScavenge::gc_task_manager()->print_threads_on(st);
}

void ParallelScavengeHeap::run_task(AbstractGangTask* task) {
WorkGang workers("GC Threads", ParallelGCThreads, true, false);
workers.initialize_workers();
workers.run_task(task);
}

void ParallelScavengeHeap::print_tracing_info() const {
AdaptiveSizePolicyOutput::print();
log_debug(gc, heap, exit)("Accumulated young generation GC time %3.7f secs", PSScavenge::accumulated_time()->seconds());
Expand Down
2 changes: 0 additions & 2 deletions src/hotspot/share/gc/parallel/parallelScavengeHeap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,6 @@ class ParallelScavengeHeap : public CollectedHeap {
virtual void print_on_error(outputStream* st) const;
virtual void print_gc_threads_on(outputStream* st) const;
virtual void gc_threads_do(ThreadClosure* tc) const;
// Runs the given AbstractGangTask with the current active workers.
virtual void run_task(AbstractGangTask* task);
virtual void print_tracing_info() const;

void verify(VerifyOption option /* ignored */);
Expand Down
3 changes: 0 additions & 3 deletions src/hotspot/share/gc/serial/serialHeap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ class SerialHeap : public GenCollectedHeap {
void oop_since_save_marks_iterate(OopClosureType1* cur,
OopClosureType2* older);

// Runs the given AbstractGangTask with the current active workers.
// No workGang for SerialHeap, work serially with thread 0.
virtual void run_task(AbstractGangTask* task) { task->work(0); }
};

#endif // SHARE_VM_GC_CMS_CMSHEAP_HPP
3 changes: 0 additions & 3 deletions src/hotspot/share/gc/shared/collectedHeap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,9 +528,6 @@ class CollectedHeap : public CHeapObj<mtInternal> {
// Iterator for all GC threads (other than VM thread)
virtual void gc_threads_do(ThreadClosure* tc) const = 0;

// Run given task. Possibly in parallel if the GC supports it.
virtual void run_task(AbstractGangTask* task) = 0;

// Print any relevant tracing info that flags imply.
// Default implementation does nothing.
virtual void print_tracing_info() const = 0;
Expand Down
21 changes: 21 additions & 0 deletions src/hotspot/share/gc/shared/workgroup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,27 @@ class AbstractWorkGang : public CHeapObj<mtInternal> {
virtual AbstractGangWorker* allocate_worker(uint which) = 0;
};

// Temporarily try to set the number of active workers.
// It's not guaranteed that it succeeds, and users need to
// query the number of active workers.
class WithUpdatedActiveWorkers : public StackObj {
private:
AbstractWorkGang* const _gang;
const uint _old_active_workers;

public:
WithUpdatedActiveWorkers(AbstractWorkGang* gang, uint requested_num_workers) :
_gang(gang),
_old_active_workers(gang->active_workers()) {
uint capped_num_workers = MIN2(requested_num_workers, gang->total_workers());
gang->update_active_workers(capped_num_workers);
}

~WithUpdatedActiveWorkers() {
_gang->update_active_workers(_old_active_workers);
}
};

// An class representing a gang of workers.
class WorkGang: public AbstractWorkGang {
// To get access to the GangTaskDispatcher instance.
Expand Down
4 changes: 0 additions & 4 deletions src/hotspot/share/gc/shenandoah/shenandoahHeap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,6 @@ class ShenandoahHeap : public CollectedHeap {

void gc_threads_do(ThreadClosure* tcl) const;

// Runs the given AbstractGangTask with the current active workers
// No workGang for shenandoahHeap, work serially with thread 0
virtual void run_task(AbstractGangTask* task) { task->work(0); }

// ---------- Heap regions handling machinery
//
private:
Expand Down
4 changes: 0 additions & 4 deletions src/hotspot/share/gc/z/zCollectedHeap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,6 @@ class ZCollectedHeap : public CollectedHeap {
virtual void object_iterate(ObjectClosure* cl);
virtual void safe_object_iterate(ObjectClosure* cl);

// Runs the given AbstractGangTask with the current active workers.
// No workGang for zHeap, work serially with thread 0
virtual void run_task(AbstractGangTask* task) { task->work(0); }

virtual HeapWord* block_start(const void* addr) const;
virtual size_t block_size(const HeapWord* addr) const;
virtual bool block_is_obj(const HeapWord* addr) const;
Expand Down
26 changes: 19 additions & 7 deletions src/hotspot/share/memory/heapInspection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -780,13 +780,25 @@ uintx HeapInspection::populate_table(KlassInfoTable* cit, BoolObjectClosure *fil
// Try parallel first.
if (parallel_thread_num > 1) {
ResourceMark rm;
ParallelObjectIterator* poi = Universe::heap()->parallel_object_iterator(parallel_thread_num);
if (poi != NULL) {
ParHeapInspectTask task(poi, cit, filter);
Universe::heap()->run_task(&task);
delete poi;
if (task.success()) {
return task.missed_count();
WorkGang* gang = Universe::heap()->get_safepoint_workers();
if (gang != NULL) {
// The GC provided a WorkGang to be used during a safepoint.

// Can't run with more threads than provided by the WorkGang.
WithUpdatedActiveWorkers update_and_restore(gang, parallel_thread_num);

ParallelObjectIterator* poi = Universe::heap()->parallel_object_iterator(gang->active_workers());
if (poi != NULL) {
// The GC supports parallel object iteration.

ParHeapInspectTask task(poi, cit, filter);
// Run task with the active workers.
gang->run_task(&task);

delete poi;
if (task.success()) {
return task.missed_count();
}
}
}
}
Expand Down

1 comment on commit 1d1e4ce

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.