Skip to content

Commit 5cd6ee4

Browse files
committedMar 31, 2021
Short-circuit derived pointer processing
1 parent 2b98429 commit 5cd6ee4

File tree

5 files changed

+34
-11
lines changed

5 files changed

+34
-11
lines changed
 

‎src/hotspot/share/compiler/oopMap.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ OopMap::OopMap(int frame_size, int arg_count) {
9191
set_write_stream(new CompressedWriteStream(32));
9292
set_omv_count(0);
9393
_num_oops = 0;
94+
_has_derived_oops = false;
9495
_index = -1;
9596

9697
#ifdef ASSERT
@@ -108,6 +109,7 @@ OopMap::OopMap(OopMap::DeepCopyToken, OopMap* source) {
108109
set_omv_count(0);
109110
set_offset(source->offset());
110111
_num_oops = source->num_oops();
112+
_has_derived_oops = source->has_derived_oops();
111113
_index = -1;
112114

113115
#ifdef ASSERT
@@ -315,8 +317,11 @@ void OopMap::set_xxx(VMReg reg, OopMapValue::oop_types x, VMReg optional) {
315317
OopMapValue o(reg, x, optional);
316318
o.write_on(write_stream());
317319
increment_count();
318-
if (x == OopMapValue::oop_value || x == OopMapValue::narrowoop_value)
320+
if (x == OopMapValue::oop_value || x == OopMapValue::narrowoop_value) {
319321
increment_num_oops();
322+
} else if (x == OopMapValue::derived_oop_value) {
323+
set_has_derived_oops(true);
324+
}
320325
}
321326

322327

@@ -756,6 +761,7 @@ ImmutableOopMap::ImmutableOopMap(const OopMap* oopmap)
756761
_thaw_stub(NULL /*Continuations::default_thaw_oops_stub()*/),
757762
_count(oopmap->count()), _num_oops(oopmap->num_oops()) {
758763
_num_oops = oopmap->num_oops();
764+
_has_derived_oops = oopmap->has_derived_oops();
759765
address addr = data_addr();
760766
//oopmap->copy_data_to(addr);
761767
oopmap->copy_and_sort_data_to(addr);

‎src/hotspot/share/compiler/oopMap.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ class OopMap: public ResourceObj {
157157
int _omv_count; // number of OopMapValues in the stream
158158
int _num_oops; // number of oops
159159
int _index; // index in OopMapSet
160+
bool _has_derived_oops;
160161
CompressedWriteStream* _write_stream;
161162

162163
debug_only( OopMapValue::oop_types* _locs_used; int _locs_length;)
@@ -166,6 +167,7 @@ class OopMap: public ResourceObj {
166167
void set_omv_count(int value) { _omv_count = value; }
167168
void increment_count() { _omv_count++; }
168169
void increment_num_oops() { _num_oops++; }
170+
void set_has_derived_oops(bool value) { _has_derived_oops = value; }
169171
CompressedWriteStream* write_stream() const { return _write_stream; }
170172
void set_write_stream(CompressedWriteStream* value) { _write_stream = value; }
171173

@@ -185,6 +187,7 @@ class OopMap: public ResourceObj {
185187
int data_size() const { return write_stream()->position(); }
186188
address data() const { return write_stream()->buffer(); }
187189
int num_oops() const { return _num_oops; }
190+
bool has_derived_oops() const { return _has_derived_oops; }
188191
int index() const { return _index; }
189192

190193
// Construction
@@ -283,13 +286,15 @@ class ImmutableOopMap {
283286
mutable address _thaw_stub;
284287
int _count; // contains the number of entries in this OopMap
285288
int _num_oops;
289+
bool _has_derived_oops;
286290

287291
address data_addr() const { return (address) this + sizeof(ImmutableOopMap); }
288292
public:
289293
ImmutableOopMap(const OopMap* oopmap);
290294

291295
int count() const { return _count; }
292296
int num_oops() const { return _num_oops; }
297+
bool has_derived_oops() const { return _has_derived_oops; }
293298
bool has_any(OopMapValue::oop_types type) const;
294299

295300
#ifdef ASSERT

‎src/hotspot/share/oops/instanceStackChunkKlass.cpp

+11-5
Original file line numberDiff line numberDiff line change
@@ -320,17 +320,23 @@ void InstanceStackChunkKlass::fix_frame(const StackChunkFrameStream<mixed>& f, c
320320

321321
run_nmethod_entry_barrier_if_needed<mixed>(f);
322322

323-
if (UseZGC || UseShenandoahGC) {
324-
RelativizeDerivedPointers<true> derived_closure;
325-
f.iterate_derived_pointers(&derived_closure, map);
323+
assert (!f.is_compiled() || f.oopmap()->has_derived_oops() == f.oopmap()->has_any(OopMapValue::derived_oop_value), "");
324+
bool has_derived = f.is_compiled() && f.oopmap()->has_derived_oops();
325+
if (has_derived) {
326+
if (UseZGC || UseShenandoahGC) {
327+
RelativizeDerivedPointers<true> derived_closure;
328+
f.iterate_derived_pointers(&derived_closure, map);
329+
}
326330
}
327331

328332
BarrierClosure<store> oops_closure(f.sp());
329333
f.iterate_oops(&oops_closure, map);
330334
OrderAccess::loadload(); // observing the barriers will prevent derived pointers from being derelativized concurrently
331335

332-
DerelativizeDerivedPointers derived_closure;
333-
f.iterate_derived_pointers(&derived_closure, map);
336+
if (has_derived) {
337+
DerelativizeDerivedPointers derived_closure;
338+
f.iterate_derived_pointers(&derived_closure, map);
339+
}
334340
}
335341

336342
template void InstanceStackChunkKlass::fix_frame<true, false>(const StackChunkFrameStream<true >& f, const RegisterMap* map);

‎src/hotspot/share/oops/instanceStackChunkKlass.inline.hpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -934,12 +934,15 @@ class OopOopIterateStackClosure {
934934
}
935935

936936
if (_do_destructive_processing) { // evacuation always takes place at a safepoint; for concurrent iterations, we skip derived pointers, which is ok b/c coarse card marking is used for chunks
937-
if (concurrent_gc) {
938-
_chunk->set_gc_mode(true);
939-
OrderAccess::storestore(); // if you see any following writes, you'll see this
937+
assert (!f.is_compiled() || f.oopmap()->has_derived_oops() == f.oopmap()->has_any(OopMapValue::derived_oop_value), "");
938+
if (f.is_compiled() && f.oopmap()->has_derived_oops()) {
939+
if (concurrent_gc) {
940+
_chunk->set_gc_mode(true);
941+
OrderAccess::storestore(); // if you see any following writes, you'll see this
942+
}
943+
RelativizeDerivedPointers<concurrent_gc> derived_closure;
944+
f.iterate_derived_pointers(&derived_closure, map);
940945
}
941-
RelativizeDerivedPointers<concurrent_gc> derived_closure;
942-
f.iterate_derived_pointers(&derived_closure, map);
943946
}
944947

945948
CheckMutationWrapper<OopClosureType> cl(_closure, _chunk);

‎src/hotspot/share/opto/buildOopMap.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -378,11 +378,13 @@ OopMap *OopFlow::build_oop_map( Node *n, int max_reg, PhaseRegAlloc *regalloc, i
378378
#endif
379379

380380
#ifdef ASSERT
381+
bool has_derived_oops = false;
381382
for( OopMapStream oms1(omap); !oms1.is_done(); oms1.next()) {
382383
OopMapValue omv1 = oms1.current();
383384
if (omv1.type() != OopMapValue::derived_oop_value) {
384385
continue;
385386
}
387+
has_derived_oops = true;
386388
bool found = false;
387389
for( OopMapStream oms2(omap); !oms2.is_done(); oms2.next()) {
388390
OopMapValue omv2 = oms2.current();
@@ -394,6 +396,7 @@ OopMap *OopFlow::build_oop_map( Node *n, int max_reg, PhaseRegAlloc *regalloc, i
394396
break;
395397
}
396398
}
399+
assert(has_derived_oops == omap->has_derived_oops(), "");
397400
assert( found, "derived with no base in oopmap" );
398401
}
399402

0 commit comments

Comments
 (0)
Please sign in to comment.