Skip to content

Commit ce52047

Browse files
committed
Optimism: Do not really need release-acquire for compiler side?
1 parent a88e109 commit ce52047

File tree

9 files changed

+18
-63
lines changed

9 files changed

+18
-63
lines changed

src/hotspot/share/c1/c1_GraphBuilder.cpp

Lines changed: 3 additions & 6 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() || scope()->wrote_stable() ||
1566+
(scope()->wrote_final_or_stable() ||
15671567
(AlwaysSafeConstructors && scope()->wrote_fields()) ||
15681568
(support_IRIW_for_not_multiple_copy_atomic_cpu && scope()->wrote_volatile()))) {
15691569
need_mem_bar = true;
@@ -1746,11 +1746,8 @@ void GraphBuilder::access_field(Bytecodes::Code code) {
17461746
if (field->is_volatile()) {
17471747
scope()->set_wrote_volatile();
17481748
}
1749-
if (field->is_final()) {
1750-
scope()->set_wrote_final();
1751-
}
1752-
if (field->is_stable()) {
1753-
scope()->set_wrote_stable();
1749+
if (field->is_final() || field->is_stable()) {
1750+
scope()->set_wrote_final_or_stable();
17541751
}
17551752
}
17561753

src/hotspot/share/c1/c1_IR.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,9 @@ 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 = false;
146+
_wrote_final_or_stable = false;
147147
_wrote_fields = false;
148148
_wrote_volatile = false;
149-
_wrote_stable = false;
150149
_start = nullptr;
151150

152151
if (osr_bci != -1) {

src/hotspot/share/c1/c1_IR.hpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,9 @@ 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; // has written final field
149+
bool _wrote_final_or_stable; // has written final or @Stable field
150150
bool _wrote_fields; // has written fields
151151
bool _wrote_volatile; // has written volatile field
152-
bool _wrote_stable; // has written @Stable field
153152
BlockBegin* _start; // the start block, successsors are method entries
154153

155154
ResourceBitMap _requires_phi_function; // bit is set if phi functions at loop headers are necessary for a local variable
@@ -182,14 +181,12 @@ class IRScope: public CompilationResourceObj {
182181
void set_min_number_of_locks(int n) { if (n > _number_of_locks) _number_of_locks = n; }
183182
bool monitor_pairing_ok() const { return _monitor_pairing_ok; }
184183
BlockBegin* start() const { return _start; }
185-
void set_wrote_final() { _wrote_final = true; }
186-
bool wrote_final () const { return _wrote_final; }
184+
void set_wrote_final_or_stable() { _wrote_final_or_stable = true; }
185+
bool wrote_final_or_stable() const { return _wrote_final_or_stable; }
187186
void set_wrote_fields() { _wrote_fields = true; }
188187
bool wrote_fields () const { return _wrote_fields; }
189188
void set_wrote_volatile() { _wrote_volatile = true; }
190189
bool wrote_volatile () const { return _wrote_volatile; }
191-
void set_wrote_stable() { _wrote_stable = true; }
192-
bool wrote_stable() const { return _wrote_stable; }
193190
};
194191

195192

src/hotspot/share/c1/c1_LIRGenerator.cpp

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

16781678
DecoratorSet decorators = IN_HEAP;
16791679
if (is_volatile) {
1680-
// Volatile access, full SC.
16811680
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;
16921681
}
16931682
if (needs_patching) {
16941683
decorators |= C1_NEEDS_PATCHING;

src/hotspot/share/ci/ciInstance.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,7 @@ 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-
// 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);
81+
oop o = obj->obj_field(offset);
8682

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

src/hotspot/share/opto/parse.hpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,8 @@ 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; // Did we write a final field?
357+
bool _wrote_final_or_stable; // Did we write a final or @Stable field?
358358
bool _wrote_volatile; // Did we write a volatile field?
359-
bool _wrote_stable; // Did we write a @Stable field?
360359
bool _wrote_fields; // Did we write any field?
361360
Node* _alloc_with_final_or_stable; // An allocation node with final or @Stable field
362361

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

397396
GraphKit& exits() { return _exits; }
398-
bool wrote_final() const { return _wrote_final; }
399-
void set_wrote_final(bool z) { _wrote_final = z; }
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; }
400399
bool wrote_volatile() const { return _wrote_volatile; }
401400
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; }
404401
bool wrote_fields() const { return _wrote_fields; }
405402
void set_wrote_fields(bool z) { _wrote_fields = z; }
406403
Node* alloc_with_final_or_stable() const { return _alloc_with_final_or_stable; }

src/hotspot/share/opto/parse1.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,8 @@ 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 = false;
411+
_wrote_final_or_stable = false;
412412
_wrote_volatile = false;
413-
_wrote_stable = false;
414413
_wrote_fields = false;
415414
_alloc_with_final_or_stable = nullptr;
416415
_block = nullptr;
@@ -1010,7 +1009,7 @@ void Parse::do_exits() {
10101009
// exceptional returns, since they cannot publish normally.
10111010
//
10121011
if (method()->is_initializer() &&
1013-
(wrote_final() || wrote_stable() ||
1012+
(wrote_final_or_stable() ||
10141013
(AlwaysSafeConstructors && wrote_fields()) ||
10151014
(support_IRIW_for_not_multiple_copy_atomic_cpu && wrote_volatile()))) {
10161015
Node* recorded_alloc = alloc_with_final_or_stable();

src/hotspot/share/opto/parse3.cpp

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -209,21 +209,7 @@ 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-
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-
}
212+
decorators |= is_vol ? MO_SEQ_CST : MO_UNORDERED;
227213

228214
bool is_obj = is_reference_type(bt);
229215

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

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

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

110110
@Test
111-
@IR(counts = { IRNode.MEMBAR, ">0" })
111+
@IR(failOn = { IRNode.MEMBAR })
112112
static void testMethodInit() {
113-
// Reference inits should have membars.
114-
INIT_CARRIER.init(); // Init again.
113+
// Reference inits have no membars.
114+
INIT_CARRIER.init();
115115
}
116116

117117
}

0 commit comments

Comments
 (0)