Skip to content

Commit

Permalink
8298059: Linked stack watermarks don't support nesting
Browse files Browse the repository at this point in the history
Reviewed-by: stefank, sspitsyn, rehn, pchilanomate
  • Loading branch information
fisk committed Dec 15, 2022
1 parent 98fa48c commit b17c524
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/hotspot/share/runtime/keepStackGCProcessed.cpp
Expand Up @@ -44,15 +44,15 @@ KeepStackGCProcessedMark::KeepStackGCProcessedMark(JavaThread* jt) :
return;
}
StackWatermark* their_watermark = StackWatermarkSet::get(jt, StackWatermarkKind::gc);
our_watermark->link_watermark(their_watermark);
our_watermark->push_linked_watermark(their_watermark);
}

KeepStackGCProcessedMark::~KeepStackGCProcessedMark() {
if (!_active) {
return;
}
StackWatermark* our_watermark = StackWatermarkSet::get(JavaThread::current(), StackWatermarkKind::gc);
our_watermark->link_watermark(NULL);
our_watermark->pop_linked_watermark();
}

void KeepStackGCProcessedMark::finish_processing() {
Expand Down
34 changes: 25 additions & 9 deletions src/hotspot/share/runtime/stackWatermark.cpp
Expand Up @@ -36,7 +36,7 @@
#include "utilities/macros.hpp"
#include "utilities/preserveException.hpp"

class StackWatermarkFramesIterator : public CHeapObj<mtInternal> {
class StackWatermarkFramesIterator : public CHeapObj<mtThread> {
JavaThread* _jt;
uintptr_t _caller;
uintptr_t _callee;
Expand Down Expand Up @@ -166,7 +166,7 @@ StackWatermark::StackWatermark(JavaThread* jt, StackWatermarkKind kind, uint32_t
_iterator(NULL),
_lock(Mutex::stackwatermark, "StackWatermark_lock"),
_kind(kind),
_linked_watermark(NULL) {
_linked_watermarks() {
}

StackWatermark::~StackWatermark() {
Expand Down Expand Up @@ -250,9 +250,15 @@ void StackWatermark::process_one() {
}
}

void StackWatermark::link_watermark(StackWatermark* watermark) {
assert(watermark == NULL || _linked_watermark == NULL, "nesting not supported");
_linked_watermark = watermark;
void StackWatermark::push_linked_watermark(StackWatermark* watermark) {
assert(JavaThread::current() == _jt, "This code is not thread safe");
_linked_watermarks.push(watermark);
}

void StackWatermark::pop_linked_watermark() {
assert(JavaThread::current() == _jt, "This code is not thread safe");
assert(_linked_watermarks.length() > 0, "Mismatched push and pop?");
_linked_watermarks.pop();
}

uintptr_t StackWatermark::watermark() {
Expand Down Expand Up @@ -288,12 +294,22 @@ bool StackWatermark::processing_completed_acquire() const {
return processing_completed(Atomic::load_acquire(&_state));
}

void StackWatermark::process_linked_watermarks() {
assert(JavaThread::current() == _jt, "This code is not thread safe");

// Finish processing all linked stack watermarks
for (StackWatermark* watermark : _linked_watermarks) {
watermark->finish_processing(NULL /* context */);
}
}

void StackWatermark::on_safepoint() {
start_processing();
StackWatermark* linked_watermark = _linked_watermark;
if (linked_watermark != NULL) {
linked_watermark->finish_processing(NULL /* context */);
}

// If the thread waking up from a safepoint expected certain other
// stack watermarks (potentially from different threads) are processed,
// then we have to perform processing of said linked watermarks here.
process_linked_watermarks();
}

void StackWatermark::start_processing() {
Expand Down
10 changes: 7 additions & 3 deletions src/hotspot/share/runtime/stackWatermark.hpp
Expand Up @@ -28,6 +28,7 @@
#include "memory/allStatic.hpp"
#include "runtime/mutex.hpp"
#include "runtime/stackWatermarkKind.hpp"
#include "utilities/growableArray.hpp"

class frame;
class JavaThread;
Expand Down Expand Up @@ -83,7 +84,7 @@ class StackWatermarkState : public AllStatic {
// ---------- <-- watermark (callee SP from the snapshot, SP at the
// point of unwinding, might be above or below
// due to frame resizing)
class StackWatermark : public CHeapObj<mtInternal> {
class StackWatermark : public CHeapObj<mtThread> {
friend class StackWatermarkFramesIterator;
protected:
volatile uint32_t _state;
Expand All @@ -93,7 +94,7 @@ class StackWatermark : public CHeapObj<mtInternal> {
StackWatermarkFramesIterator* _iterator;
Mutex _lock;
StackWatermarkKind _kind;
StackWatermark* _linked_watermark;
GrowableArrayCHeap<StackWatermark*, mtThread> _linked_watermarks;

void process_one();

Expand All @@ -116,6 +117,8 @@ class StackWatermark : public CHeapObj<mtInternal> {
// opposed to due to frames being unwound by the owning thread.
virtual bool process_on_iteration() { return true; }

void process_linked_watermarks();

bool processing_started(uint32_t state) const;
bool processing_completed(uint32_t state) const;

Expand All @@ -129,7 +132,8 @@ class StackWatermark : public CHeapObj<mtInternal> {
StackWatermark* next() const { return _next; }
void set_next(StackWatermark* n) { _next = n; }

void link_watermark(StackWatermark* watermark);
void push_linked_watermark(StackWatermark* watermark);
void pop_linked_watermark();

uintptr_t watermark();
uintptr_t last_processed();
Expand Down
3 changes: 0 additions & 3 deletions test/hotspot/jtreg/ProblemList-zgc.txt
Expand Up @@ -83,6 +83,3 @@ vmTestbase/nsk/monitoring/stress/lowmem/lowmem033/TestDescription.java 8297979 g
vmTestbase/nsk/monitoring/stress/lowmem/lowmem034/TestDescription.java 8297979 generic-all
vmTestbase/nsk/monitoring/stress/lowmem/lowmem035/TestDescription.java 8297979 generic-all
vmTestbase/nsk/monitoring/stress/lowmem/lowmem036/TestDescription.java 8297979 generic-all

vmTestbase/nsk/jdi/ExceptionRequest/addInstanceFilter/instancefilter001/TestDescription.java 8298059 generic-x64
vmTestbase/nsk/jdi/ExceptionRequest/addInstanceFilter/instancefilter004/TestDescription.java 8298059 generic-x64

0 comments on commit b17c524

Please sign in to comment.