Skip to content

Commit 292aad2

Browse files
committedOct 20, 2023
8316436: ContinuationWrapper uses unhandled nullptr oop
Reviewed-by: pchilanomate, eosterlund
1 parent 387504c commit 292aad2

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed
 

‎src/hotspot/share/runtime/continuationWrapper.cpp

+3-8
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,12 @@
3838
#include "runtime/stackChunkFrameStream.inline.hpp"
3939

4040
ContinuationWrapper::ContinuationWrapper(const RegisterMap* map)
41-
: _thread(map->thread()),
42-
_entry(Continuation::get_continuation_entry_for_continuation(_thread, map->stack_chunk()->cont())),
43-
_continuation(map->stack_chunk()->cont())
44-
{
45-
assert(oopDesc::is_oop(_continuation),"Invalid cont: " INTPTR_FORMAT, p2i((void*)_continuation));
41+
: ContinuationWrapper(map->thread(),
42+
Continuation::get_continuation_entry_for_continuation(map->thread(), map->stack_chunk()->cont()),
43+
map->stack_chunk()->cont()) {
4644
assert(_entry == nullptr || _continuation == _entry->cont_oop(map->thread()),
4745
"cont: " INTPTR_FORMAT " entry: " INTPTR_FORMAT " entry_sp: " INTPTR_FORMAT,
4846
p2i( (oopDesc*)_continuation), p2i((oopDesc*)_entry->cont_oop(map->thread())), p2i(entrySP()));
49-
disallow_safepoint();
50-
read();
5147
}
5248

5349
const frame ContinuationWrapper::last_frame() {
@@ -96,4 +92,3 @@ bool ContinuationWrapper::chunk_invariant() const {
9692
return true;
9793
}
9894
#endif // ASSERT
99-

‎src/hotspot/share/runtime/continuationWrapper.inline.hpp

+13-12
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class ContinuationWrapper : public StackObj {
4949
// These oops are managed by SafepointOp
5050
oop _continuation; // jdk.internal.vm.Continuation instance
5151
stackChunkOop _tail;
52+
bool _done;
5253

5354
ContinuationWrapper(const ContinuationWrapper& cont); // no copy constructor
5455

@@ -58,6 +59,7 @@ class ContinuationWrapper : public StackObj {
5859

5960
void disallow_safepoint() {
6061
#ifdef ASSERT
62+
assert(!_done, "");
6163
assert(_continuation != nullptr, "");
6264
_current_thread = Thread::current();
6365
if (_current_thread->is_Java_thread()) {
@@ -69,16 +71,19 @@ class ContinuationWrapper : public StackObj {
6971
void allow_safepoint() {
7072
#ifdef ASSERT
7173
// we could have already allowed safepoints in done
72-
if (_continuation != nullptr && _current_thread->is_Java_thread()) {
74+
if (!_done && _current_thread->is_Java_thread()) {
7375
JavaThread::cast(_current_thread)->dec_no_safepoint_count();
7476
}
7577
#endif
7678
}
7779

80+
ContinuationWrapper(JavaThread* thread, ContinuationEntry* entry, oop continuation);
81+
7882
public:
7983
void done() {
8084
allow_safepoint(); // must be done first
81-
_continuation = nullptr;
85+
_done = true;
86+
*reinterpret_cast<intptr_t*>(&_continuation) = badHeapOopVal;
8287
*reinterpret_cast<intptr_t*>(&_tail) = badHeapOopVal;
8388
}
8489

@@ -140,23 +145,19 @@ class ContinuationWrapper : public StackObj {
140145
#endif
141146
};
142147

143-
inline ContinuationWrapper::ContinuationWrapper(JavaThread* thread, oop continuation)
144-
: _thread(thread), _entry(thread->last_continuation()), _continuation(continuation)
145-
{
148+
inline ContinuationWrapper::ContinuationWrapper(JavaThread* thread, ContinuationEntry* entry, oop continuation)
149+
: _thread(thread), _entry(entry), _continuation(continuation), _done(false) {
146150
assert(oopDesc::is_oop(_continuation),
147151
"Invalid continuation object: " INTPTR_FORMAT, p2i((void*)_continuation));
148152
disallow_safepoint();
149153
read();
150154
}
151155

156+
inline ContinuationWrapper::ContinuationWrapper(JavaThread* thread, oop continuation)
157+
: ContinuationWrapper(thread, thread->last_continuation(), continuation) {}
158+
152159
inline ContinuationWrapper::ContinuationWrapper(oop continuation)
153-
: _thread(nullptr), _entry(nullptr), _continuation(continuation)
154-
{
155-
assert(oopDesc::is_oop(_continuation),
156-
"Invalid continuation object: " INTPTR_FORMAT, p2i((void*)_continuation));
157-
disallow_safepoint();
158-
read();
159-
}
160+
: ContinuationWrapper(nullptr, nullptr, continuation) {}
160161

161162
inline bool ContinuationWrapper::is_preempted() {
162163
return jdk_internal_vm_Continuation::is_preempted(_continuation);

0 commit comments

Comments
 (0)
Please sign in to comment.