Skip to content
Permalink
Browse files
8265450: Merge PreservedMarksSet::restore code paths
Reviewed-by: sjohanss, iwalulya
  • Loading branch information
Thomas Schatzl committed Apr 21, 2021
1 parent b337f63 commit 325edbc364074e103047173c59305ce0b8ad8b00
Showing 1 changed file with 35 additions and 38 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2021, 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
@@ -77,7 +77,7 @@ void RemoveForwardedPointerClosure::do_object(oop obj) {
}

void PreservedMarksSet::init(uint num) {
assert(_stacks == NULL && _num == 0, "do not re-initialize");
assert(_stacks == nullptr && _num == 0, "do not re-initialize");
assert(num > 0, "pre-condition");
if (_in_c_heap) {
_stacks = NEW_C_HEAP_ARRAY(Padded<PreservedMarks>, num, mtGC);
@@ -92,57 +92,54 @@ void PreservedMarksSet::init(uint num) {
assert_empty();
}

class ParRestoreTask : public AbstractGangTask {
private:
class RestorePreservedMarksTask : public AbstractGangTask {
PreservedMarksSet* const _preserved_marks_set;
SequentialSubTasksDone _sub_tasks;
volatile size_t* const _total_size_addr;
volatile size_t _total_size;
#ifdef ASSERT
size_t _total_size_before;
#endif // ASSERT

public:
virtual void work(uint worker_id) {
void work(uint worker_id) override {
uint task_id = 0;
while (_sub_tasks.try_claim_task(/* reference */ task_id)) {
_preserved_marks_set->get(task_id)->restore_and_increment(_total_size_addr);
while (_sub_tasks.try_claim_task(task_id)) {
_preserved_marks_set->get(task_id)->restore_and_increment(&_total_size);
}
}

ParRestoreTask(PreservedMarksSet* preserved_marks_set,
volatile size_t* total_size_addr)
: AbstractGangTask("Parallel Preserved Mark Restoration"),
_preserved_marks_set(preserved_marks_set),
_sub_tasks(preserved_marks_set->num()),
_total_size_addr(total_size_addr) {
RestorePreservedMarksTask(PreservedMarksSet* preserved_marks_set)
: AbstractGangTask("Restore Preserved Marks"),
_preserved_marks_set(preserved_marks_set),
_sub_tasks(preserved_marks_set->num()),
_total_size(0)
DEBUG_ONLY(COMMA _total_size_before(0)) {
#ifdef ASSERT
// This is to make sure the total_size we'll calculate below is correct.
for (uint i = 0; i < _preserved_marks_set->num(); ++i) {
_total_size_before += _preserved_marks_set->get(i)->size();
}
};
#endif // ASSERT
}

void PreservedMarksSet::restore(WorkGang* workers) {
volatile size_t total_size = 0;
~RestorePreservedMarksTask() {
assert(_total_size == _total_size_before, "total_size = %zu before = %zu", _total_size, _total_size_before);

#ifdef ASSERT
// This is to make sure the total_size we'll calculate below is correct.
size_t total_size_before = 0;
for (uint i = 0; i < _num; i += 1) {
total_size_before += get(i)->size();
log_trace(gc)("Restored %zu marks", _total_size);
}
#endif // ASSERT
};

if (workers == NULL) {
for (uint i = 0; i < num(); i += 1) {
total_size += get(i)->size();
get(i)->restore();
void PreservedMarksSet::restore(WorkGang* workers) {
{
RestorePreservedMarksTask cl(this);
if (workers == nullptr) {
cl.work(0);
} else {
workers->run_task(&cl);
}
} else {
ParRestoreTask task(this, &total_size);
workers->run_task(&task);
}

assert_empty();

assert(total_size == total_size_before,
"total_size = " SIZE_FORMAT " before = " SIZE_FORMAT,
total_size, total_size_before);

log_trace(gc)("Restored " SIZE_FORMAT " marks", total_size);
}

void PreservedMarksSet::reclaim() {
@@ -157,13 +154,13 @@ void PreservedMarksSet::reclaim() {
} else {
// the array was resource-allocated, so nothing to do
}
_stacks = NULL;
_stacks = nullptr;
_num = 0;
}

#ifndef PRODUCT
void PreservedMarksSet::assert_empty() {
assert(_stacks != NULL && _num > 0, "should have been initialized");
assert(_stacks != nullptr && _num > 0, "should have been initialized");
for (uint i = 0; i < _num; i += 1) {
get(i)->assert_empty();
}

1 comment on commit 325edbc

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 325edbc Apr 21, 2021

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.