Skip to content

Commit ca4aa5f

Browse files
committed
Use marking cycle counter instead of barriers in old chunks
1 parent 2302195 commit ca4aa5f

File tree

6 files changed

+52
-4
lines changed

6 files changed

+52
-4
lines changed

src/hotspot/cpu/x86/continuationChunk_x86.inline.hpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,23 @@ static bool iterate_oops(OopClosureType* closure, const ImmutableOopMap* oopmap,
179179
return mutated;
180180
}
181181

182+
static int get_chunk_sp(oop chunk) {
183+
// we don't invoke write barriers on oops in thawed frames, so we use the gcSP field to traverse thawed frames
184+
int chunk_sp = jdk_internal_misc_StackChunk::sp(chunk);
185+
if (chunk_sp != jdk_internal_misc_StackChunk::gc_sp(chunk) && Universe::heap()->requires_barriers(chunk)) {
186+
uint64_t marking_cycle = CodeCache::marking_cycle() >> 1;
187+
uint64_t chunk_marking_cycle = jdk_internal_misc_StackChunk::mark_cycle(chunk) >> 1;
188+
if (marking_cycle == chunk_marking_cycle) {
189+
// Marking isn't finished, so we need to traverse thawed frames
190+
chunk_sp = jdk_internal_misc_StackChunk::gc_sp(chunk);
191+
assert (chunk_sp >= 0 && chunk_sp <= jdk_internal_misc_StackChunk::sp(chunk), "");
192+
} else {
193+
jdk_internal_misc_StackChunk::set_gc_sp(chunk, chunk_sp); // atomic; benign race
194+
}
195+
}
196+
return chunk_sp;
197+
}
198+
182199
template <class OopClosureType, bool concurrent_gc>
183200
void Continuation::stack_chunk_iterate_stack(oop chunk, OopClosureType* closure) {
184201
// see sender_for_compiled_frame
@@ -209,7 +226,7 @@ void Continuation::stack_chunk_iterate_stack(oop chunk, OopClosureType* closure)
209226
intptr_t* const start = (intptr_t*)InstanceStackChunkKlass::start_of_stack(chunk);
210227
intptr_t* const end = start + jdk_internal_misc_StackChunk::size(chunk) - argsize;
211228
CodeBlob* cb = NULL;
212-
for (intptr_t* sp = start + jdk_internal_misc_StackChunk::sp(chunk); sp < end; sp += cb->frame_size()) {
229+
for (intptr_t* sp = start + get_chunk_sp(chunk); sp < end; sp += cb->frame_size()) {
213230
address pc = *(address*)(sp - 1);
214231
log_develop_trace(jvmcont)("stack_chunk_iterate_stack sp: %ld pc: " INTPTR_FORMAT, sp - start, p2i(pc));
215232
assert (pc != NULL, "");
@@ -394,7 +411,7 @@ void Continuation::stack_chunk_iterate_stack_bounded(oop chunk, OopClosureType*
394411
intptr_t* end = start + jdk_internal_misc_StackChunk::size(chunk) - argsize;
395412
if (end > h) end = h;
396413
CodeBlob* cb = NULL;
397-
for (intptr_t* sp = start + jdk_internal_misc_StackChunk::sp(chunk); sp < end; sp += cb->frame_size()) {
414+
for (intptr_t* sp = start + get_chunk_sp(chunk); sp < end; sp += cb->frame_size()) {
398415
intptr_t* next_sp = sp + cb->frame_size();
399416
if (sp + cb->frame_size() >= l) {
400417
sp += cb->frame_size();

src/hotspot/share/classfile/javaClasses.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4941,6 +4941,8 @@ int jdk_internal_misc_StackChunk::_sp_offset;
49414941
int jdk_internal_misc_StackChunk::_pc_offset;
49424942
int jdk_internal_misc_StackChunk::_argsize_offset;
49434943
int jdk_internal_misc_StackChunk::_mode_offset;
4944+
int jdk_internal_misc_StackChunk::_gcSP_offset;
4945+
int jdk_internal_misc_StackChunk::_markCycle_offset;
49444946
int jdk_internal_misc_StackChunk::_numFrames_offset;
49454947
int jdk_internal_misc_StackChunk::_numOops_offset;
49464948
int jdk_internal_misc_StackChunk::_cont_offset;
@@ -4952,6 +4954,8 @@ int jdk_internal_misc_StackChunk::_cont_offset;
49524954
macro(_pc_offset, k, vmSymbols::pc_name(), long_signature, false); \
49534955
macro(_argsize_offset, k, vmSymbols::argsize_name(), int_signature, false); \
49544956
macro(_mode_offset, k, vmSymbols::mode_name(), bool_signature, false); \
4957+
macro(_gcSP_offset, k, "gcSP", int_signature, false); \
4958+
macro(_markCycle_offset, k, "markCycle", long_signature, false); \
49554959
macro(_numFrames_offset, k, vmSymbols::numFrames_name(), int_signature, false); \
49564960
macro(_numOops_offset, k, vmSymbols::numOops_name(), int_signature, false); \
49574961
macro(_cont_offset, k, "cont", continuation_signature, false);

src/hotspot/share/classfile/javaClasses.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,8 @@ class jdk_internal_misc_StackChunk: AllStatic {
11181118
static int _pc_offset;
11191119
static int _argsize_offset;
11201120
static int _mode_offset;
1121+
static int _gcSP_offset;
1122+
static int _markCycle_offset;
11211123
static int _numFrames_offset;
11221124
static int _numOops_offset;
11231125
static int _cont_offset;
@@ -1143,6 +1145,10 @@ class jdk_internal_misc_StackChunk: AllStatic {
11431145
static inline void set_argsize(oop ref, int value);
11441146
static inline bool gc_mode(oop ref);
11451147
static inline void set_gc_mode(oop ref, bool value);
1148+
static inline int gc_sp(oop ref);
1149+
static inline void set_gc_sp(oop ref, int value);
1150+
static inline uint64_t mark_cycle(oop ref);
1151+
static inline void set_mark_cycle(oop ref, uint64_t value);
11461152
static inline int end(oop ref);
11471153
static inline int numFrames(oop ref);
11481154
static inline void set_numFrames(oop ref, int value);

src/hotspot/share/classfile/javaClasses.inline.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,18 @@ inline bool jdk_internal_misc_StackChunk::gc_mode(oop ref) {
336336
inline void jdk_internal_misc_StackChunk::set_gc_mode(oop ref, bool value) {
337337
ref->bool_field_put(_mode_offset, (jboolean)value);
338338
}
339+
inline int jdk_internal_misc_StackChunk::gc_sp(oop ref) {
340+
return ref->int_field(_gcSP_offset);
341+
}
342+
inline void jdk_internal_misc_StackChunk::set_gc_sp(oop ref, int value) {
343+
ref->int_field_put(_gcSP_offset, value);
344+
}
345+
inline uint64_t jdk_internal_misc_StackChunk::mark_cycle(oop ref) {
346+
return (uint64_t)ref->long_field(_markCycle_offset);
347+
}
348+
inline void jdk_internal_misc_StackChunk::set_mark_cycle(oop ref, uint64_t value) {
349+
ref->long_field_put(_markCycle_offset, (jlong)value);
350+
}
339351
inline int jdk_internal_misc_StackChunk::end(oop ref) {
340352
return size(ref) - argsize(ref);
341353
}

src/hotspot/share/runtime/continuation.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2518,6 +2518,7 @@ class Freeze {
25182518
// We're always writing to a young chunk, so the GC can't see it until the next safepoint.
25192519
jdk_internal_misc_StackChunk::set_sp(chunk, sp);
25202520
jdk_internal_misc_StackChunk::set_pc(chunk, *(address*)(top - SENDER_SP_RET_ADDRESS_OFFSET));
2521+
jdk_internal_misc_StackChunk::set_gc_sp(chunk, sp);
25212522

25222523
// we copy the top frame's return address and link, but not the bottom's
25232524
intptr_t* chunk_top = (intptr_t*)InstanceStackChunkKlass::start_of_stack(chunk) + sp;
@@ -2570,6 +2571,8 @@ class Freeze {
25702571
jdk_internal_misc_StackChunk::set_pc(chunk, NULL);
25712572
jdk_internal_misc_StackChunk::set_argsize(chunk, 0); // TODO PERF unnecessary?
25722573
jdk_internal_misc_StackChunk::set_gc_mode(chunk, false);
2574+
jdk_internal_misc_StackChunk::set_gc_sp(chunk, sp);
2575+
jdk_internal_misc_StackChunk::set_mark_cycle(chunk, 0);
25732576
jdk_internal_misc_StackChunk::set_parent_raw<typename ConfigT::OopT>(chunk, chunk0); // field is uninitialized
25742577
jdk_internal_misc_StackChunk::set_cont_raw<typename ConfigT::OopT>(chunk, _cont.mirror());
25752578
ContMirror::reset_chunk_counters(chunk);
@@ -2627,6 +2630,7 @@ class Freeze {
26272630
for (oop chunk = _cont.tail(); chunk != (oop)NULL; chunk = jdk_internal_misc_StackChunk::parent(chunk)) {
26282631
// jdk_internal_misc_StackChunk::set_parent(chunk, (oop)NULL); // TODO: kills loop
26292632
jdk_internal_misc_StackChunk::set_sp(chunk, jdk_internal_misc_StackChunk::size(chunk) + frame_metadata);
2633+
jdk_internal_misc_StackChunk::set_gc_sp(chunk, jdk_internal_misc_StackChunk::sp(chunk));
26302634
ContMirror::reset_chunk_counters(chunk);
26312635
}
26322636
assert (!_cont.is_flag(FLAG_LAST_FRAME_INTERPRETED), "");
@@ -3960,7 +3964,7 @@ class Thaw {
39603964
assert (verify_stack_chunk<1>(chunk), "");
39613965
// assert (verify_continuation<99>(_cont.mirror()), "");
39623966

3963-
const bool barriers = requires_barriers(chunk); // TODO R PERF
3967+
const bool barriers = false; // requires_barriers(chunk); // TODO R PERF
39643968

39653969
// if (!barriers) { // TODO ????
39663970
// ContMirror::reset_chunk_counters(chunk);
@@ -3976,8 +3980,11 @@ class Thaw {
39763980
vsp = _cont.entrySP();
39773981
}
39783982

3983+
// Instead of invoking barriers on oops in thawed frames, we use the gcSP field; see continuationChunk's get_chunk_sp
3984+
jdk_internal_misc_StackChunk::set_mark_cycle(chunk, CodeCache::marking_cycle());
3985+
39793986
bool partial, empty;
3980-
if (!TEST_THAW_ONE_CHUNK_FRAME && !barriers && LIKELY(FULL_STACK || (size < threshold))) {
3987+
if (!TEST_THAW_ONE_CHUNK_FRAME && LIKELY((FULL_STACK || (size < threshold)) && !barriers)) {
39813988
// prefetch with anticipation of memcpy starting at highest address
39823989
prefetch_chunk_pd(InstanceStackChunkKlass::start_of_stack(chunk), size);
39833990

src/java.base/share/classes/jdk/internal/misc/StackChunk.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public class StackChunk {
3232
public int sp; // in words
3333
private int argsize; // bottom stack-passed arguments, in words
3434
private long pc;
35+
private int gcSP;
36+
private long markCycle;
3537

3638
private int numFrames;
3739
private int numOops;

0 commit comments

Comments
 (0)