Skip to content

Commit 128b986

Browse files
committed
Revert "Optimism: Do not really need release-acquire for compiler side?"
This reverts commit d018cc0.
1 parent ba23b2f commit 128b986

File tree

11 files changed

+64
-21
lines changed

11 files changed

+64
-21
lines changed

src/hotspot/share/c1/c1_GraphBuilder.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,7 +1563,7 @@ void GraphBuilder::method_return(Value x, bool ignore_return) {
15631563
// The conditions for a memory barrier are described in Parse::do_exits().
15641564
bool need_mem_bar = false;
15651565
if (method()->name() == ciSymbols::object_initializer_name() &&
1566-
(scope()->wrote_final_or_stable() ||
1566+
(scope()->wrote_final() || scope()->wrote_stable() ||
15671567
(AlwaysSafeConstructors && scope()->wrote_fields()) ||
15681568
(support_IRIW_for_not_multiple_copy_atomic_cpu && scope()->wrote_volatile()))) {
15691569
need_mem_bar = true;
@@ -1746,8 +1746,11 @@ void GraphBuilder::access_field(Bytecodes::Code code) {
17461746
if (field->is_volatile()) {
17471747
scope()->set_wrote_volatile();
17481748
}
1749-
if (field->is_final() || field->is_stable()) {
1750-
scope()->set_wrote_final_or_stable();
1749+
if (field->is_final()) {
1750+
scope()->set_wrote_final();
1751+
}
1752+
if (field->is_stable()) {
1753+
scope()->set_wrote_stable();
17511754
}
17521755
}
17531756

src/hotspot/share/c1/c1_IR.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,10 @@ IRScope::IRScope(Compilation* compilation, IRScope* caller, int caller_bci, ciMe
143143
_xhandlers = new XHandlers(method);
144144
_number_of_locks = 0;
145145
_monitor_pairing_ok = method->has_balanced_monitors();
146-
_wrote_final_or_stable = false;
146+
_wrote_final = false;
147147
_wrote_fields = false;
148148
_wrote_volatile = false;
149+
_wrote_stable = false;
149150
_start = nullptr;
150151

151152
if (osr_bci != -1) {

src/hotspot/share/c1/c1_IR.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,10 @@ class IRScope: public CompilationResourceObj {
146146
XHandlers* _xhandlers; // the exception handlers
147147
int _number_of_locks; // the number of monitor lock slots needed
148148
bool _monitor_pairing_ok; // the monitor pairing info
149-
bool _wrote_final_or_stable; // has written final or @Stable field
149+
bool _wrote_final; // has written final field
150150
bool _wrote_fields; // has written fields
151151
bool _wrote_volatile; // has written volatile field
152+
bool _wrote_stable; // has written @Stable field
152153
BlockBegin* _start; // the start block, successsors are method entries
153154

154155
ResourceBitMap _requires_phi_function; // bit is set if phi functions at loop headers are necessary for a local variable
@@ -181,12 +182,14 @@ class IRScope: public CompilationResourceObj {
181182
void set_min_number_of_locks(int n) { if (n > _number_of_locks) _number_of_locks = n; }
182183
bool monitor_pairing_ok() const { return _monitor_pairing_ok; }
183184
BlockBegin* start() const { return _start; }
184-
void set_wrote_final_or_stable() { _wrote_final_or_stable = true; }
185-
bool wrote_final_or_stable() const { return _wrote_final_or_stable; }
185+
void set_wrote_final() { _wrote_final = true; }
186+
bool wrote_final () const { return _wrote_final; }
186187
void set_wrote_fields() { _wrote_fields = true; }
187188
bool wrote_fields () const { return _wrote_fields; }
188189
void set_wrote_volatile() { _wrote_volatile = true; }
189190
bool wrote_volatile () const { return _wrote_volatile; }
191+
void set_wrote_stable() { _wrote_stable = true; }
192+
bool wrote_stable() const { return _wrote_stable; }
190193
};
191194

192195

src/hotspot/share/c1/c1_LIRGenerator.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,7 +1677,18 @@ void LIRGenerator::do_StoreField(StoreField* x) {
16771677

16781678
DecoratorSet decorators = IN_HEAP;
16791679
if (is_volatile) {
1680+
// Volatile access, full SC.
16801681
decorators |= MO_SEQ_CST;
1682+
} else if (x->field()->is_stable() && !x->field()->is_final() &&
1683+
is_reference_type(field_type)) {
1684+
// For reference @Stable fields, make sure we publish the contents
1685+
// safely. We need this to make sure compilers see a proper value when
1686+
// constant folding the access. Final @Stable fields are already
1687+
// handled in constructors.
1688+
decorators |= MO_RELEASE;
1689+
} else {
1690+
// Everything else is unordered.
1691+
decorators |= MO_UNORDERED;
16811692
}
16821693
if (needs_patching) {
16831694
decorators |= C1_NEEDS_PATCHING;

src/hotspot/share/ci/ciInstance.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ ciConstant ciInstance::field_value_impl(BasicType field_btype, int offset) {
7878
case T_LONG: value = ciConstant(obj->long_field(offset)); break;
7979
case T_OBJECT: // fall through
8080
case T_ARRAY: {
81-
oop o = obj->obj_field(offset);
81+
// In case we are reading the constant off a reference @Stable field,
82+
// we need to match the releasing store with this acquire. There is no easy
83+
// way to know this from the offset, but it should not hurt to ask this for
84+
// all reference fields.
85+
oop o = obj->obj_field_acquire(offset);
8286

8387
// A field will be "constant" if it is known always to be
8488
// a non-null reference to an instance of a particular class,

src/hotspot/share/opto/parse.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,9 @@ class Parse : public GraphKit {
354354
int _block_count; // Number of elements in _blocks.
355355

356356
GraphKit _exits; // Record all normal returns and throws here.
357-
bool _wrote_final_or_stable; // Did we write a final or @Stable field?
357+
bool _wrote_final; // Did we write a final field?
358358
bool _wrote_volatile; // Did we write a volatile field?
359+
bool _wrote_stable; // Did we write a @Stable field?
359360
bool _wrote_fields; // Did we write any field?
360361
Node* _alloc_with_final_or_stable; // An allocation node with final or @Stable field
361362

@@ -394,10 +395,12 @@ class Parse : public GraphKit {
394395
int block_count() const { return _block_count; }
395396

396397
GraphKit& exits() { return _exits; }
397-
bool wrote_final_or_stable() const { return _wrote_final_or_stable; }
398-
void set_wrote_final_or_stable(bool z) { _wrote_final_or_stable = z; }
398+
bool wrote_final() const { return _wrote_final; }
399+
void set_wrote_final(bool z) { _wrote_final = z; }
399400
bool wrote_volatile() const { return _wrote_volatile; }
400401
void set_wrote_volatile(bool z) { _wrote_volatile = z; }
402+
bool wrote_stable() const { return _wrote_stable; }
403+
void set_wrote_stable(bool z) { _wrote_stable = z; }
401404
bool wrote_fields() const { return _wrote_fields; }
402405
void set_wrote_fields(bool z) { _wrote_fields = z; }
403406
Node* alloc_with_final_or_stable() const { return _alloc_with_final_or_stable; }

src/hotspot/share/opto/parse1.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,9 @@ Parse::Parse(JVMState* caller, ciMethod* parse_method, float expected_uses)
408408
_method = parse_method;
409409
_expected_uses = expected_uses;
410410
_depth = 1 + (caller->has_method() ? caller->depth() : 0);
411-
_wrote_final_or_stable = false;
411+
_wrote_final = false;
412412
_wrote_volatile = false;
413+
_wrote_stable = false;
413414
_wrote_fields = false;
414415
_alloc_with_final_or_stable = nullptr;
415416
_block = nullptr;
@@ -1009,7 +1010,7 @@ void Parse::do_exits() {
10091010
// exceptional returns, since they cannot publish normally.
10101011
//
10111012
if (method()->is_initializer() &&
1012-
(wrote_final_or_stable() ||
1013+
(wrote_final() || wrote_stable() ||
10131014
(AlwaysSafeConstructors && wrote_fields()) ||
10141015
(support_IRIW_for_not_multiple_copy_atomic_cpu && wrote_volatile()))) {
10151016
Node* recorded_alloc = alloc_with_final_or_stable();

src/hotspot/share/opto/parse3.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,21 @@ void Parse::do_put_xxx(Node* obj, ciField* field, bool is_field) {
209209
Node* val = type2size[bt] == 1 ? pop() : pop_pair();
210210

211211
DecoratorSet decorators = IN_HEAP;
212-
decorators |= is_vol ? MO_SEQ_CST : MO_UNORDERED;
212+
213+
if (is_vol) {
214+
// Volatile access, full SC.
215+
decorators |= MO_SEQ_CST;
216+
} else if (field->is_stable() && !field->is_final() &&
217+
is_reference_type(field->layout_type())) {
218+
// For reference @Stable fields, make sure we publish the contents
219+
// safely. We need this to make sure compilers see a proper value when
220+
// constant folding the access. Final @Stable fields are already
221+
// handled in constructors.
222+
decorators |= MO_RELEASE;
223+
} else {
224+
// Everything else is unordered.
225+
decorators |= MO_UNORDERED;
226+
}
213227

214228
bool is_obj = is_reference_type(bt);
215229

@@ -243,7 +257,12 @@ void Parse::do_put_xxx(Node* obj, ciField* field, bool is_field) {
243257
// can insert a memory barrier later on to keep the writes from floating
244258
// out of the constructor.
245259
if (field->is_final() || field->is_stable()) {
246-
set_wrote_final_or_stable(true);
260+
if (field->is_final()) {
261+
set_wrote_final(true);
262+
}
263+
if (field->is_stable()) {
264+
set_wrote_stable(true);
265+
}
247266
if (AllocateNode::Ideal_allocation(obj) != nullptr) {
248267
// Preserve allocation ptr to create precedent edge to it in membar
249268
// generated on exit from constructor.

test/hotspot/jtreg/compiler/c2/irTests/stable/StablePrimVolatileTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,8 @@ static Carrier testConstructorFullInit() {
104104
}
105105

106106
@Test
107-
@IR(counts = { IRNode.STORE, ">0" })
108107
@IR(counts = { IRNode.MEMBAR, ">0" })
109108
static void testMethodInit() {
110-
// Expect stores.
111109
// Volatile barriers expected.
112110
INIT_CARRIER.init();
113111
}

test/hotspot/jtreg/compiler/c2/irTests/stable/StableRefPlainTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ static Carrier testConstructorFullInit() {
108108
}
109109

110110
@Test
111-
@IR(failOn = { IRNode.MEMBAR })
111+
@IR(counts = { IRNode.MEMBAR_RELEASE, "1" })
112112
static void testMethodInit() {
113-
// Reference inits have no membars.
113+
// Reference inits have release membars.
114114
INIT_CARRIER.init();
115115
}
116116

0 commit comments

Comments
 (0)