Skip to content
This repository has been archived by the owner on Aug 27, 2022. It is now read-only.
/ lanai Public archive

Commit

Permalink
8245236: Remove MO_VOLATILE Access decorator
Browse files Browse the repository at this point in the history
Use MO_RELAXED instead of MO_VOLATILE and removed MO_VOLATILE.

Reviewed-by: stefank, tschatzl
  • Loading branch information
Kim Barrett committed May 20, 2020
1 parent 18db3de commit e9b8463
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 73 deletions.
4 changes: 2 additions & 2 deletions src/hotspot/share/gc/g1/g1BarrierSet.inline.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -39,7 +39,7 @@ inline void G1BarrierSet::write_ref_field_pre(T* field) {
return;
}

T heap_oop = RawAccess<MO_VOLATILE>::oop_load(field);
T heap_oop = RawAccess<MO_RELAXED>::oop_load(field);
if (!CompressedOops::is_null(heap_oop)) {
enqueue(CompressedOops::decode_not_null(heap_oop));
}
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/gc/g1/g1ConcurrentMark.inline.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -260,7 +260,7 @@ inline bool G1CMTask::make_reference_grey(oop obj) {
template <class T>
inline bool G1CMTask::deal_with_reference(T* p) {
increment_refs_reached();
oop const obj = RawAccess<MO_VOLATILE>::oop_load(p);
oop const obj = RawAccess<MO_RELAXED>::oop_load(p);
if (obj == NULL) {
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions src/hotspot/share/gc/g1/g1OopClosures.inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ inline void G1CMOopClosure::do_oop_work(T* p) {

template <class T>
inline void G1RootRegionScanClosure::do_oop_work(T* p) {
T heap_oop = RawAccess<MO_VOLATILE>::oop_load(p);
T heap_oop = RawAccess<MO_RELAXED>::oop_load(p);
if (CompressedOops::is_null(heap_oop)) {
return;
}
Expand Down Expand Up @@ -133,7 +133,7 @@ inline static void check_obj_during_refinement(T* p, oop const obj) {

template <class T>
inline void G1ConcurrentRefineOopClosure::do_oop_work(T* p) {
T o = RawAccess<MO_VOLATILE>::oop_load(p);
T o = RawAccess<MO_RELAXED>::oop_load(p);
if (CompressedOops::is_null(o)) {
return;
}
Expand Down Expand Up @@ -260,7 +260,7 @@ void G1ParCopyClosure<barrier, do_mark_object>::do_oop_work(T* p) {
}

template <class T> void G1RebuildRemSetClosure::do_oop_work(T* p) {
oop const obj = RawAccess<MO_VOLATILE>::oop_load(p);
oop const obj = RawAccess<MO_RELAXED>::oop_load(p);
if (obj == NULL) {
return;
}
Expand Down
7 changes: 3 additions & 4 deletions src/hotspot/share/oops/access.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -123,8 +123,8 @@ class Access: public AllStatic {
verify_decorators<expected_mo_decorators | heap_oop_decorators>();
}

static const DecoratorSet load_mo_decorators = MO_UNORDERED | MO_VOLATILE | MO_RELAXED | MO_ACQUIRE | MO_SEQ_CST;
static const DecoratorSet store_mo_decorators = MO_UNORDERED | MO_VOLATILE | MO_RELAXED | MO_RELEASE | MO_SEQ_CST;
static const DecoratorSet load_mo_decorators = MO_UNORDERED | MO_RELAXED | MO_ACQUIRE | MO_SEQ_CST;
static const DecoratorSet store_mo_decorators = MO_UNORDERED | MO_RELAXED | MO_RELEASE | MO_SEQ_CST;
static const DecoratorSet atomic_xchg_mo_decorators = MO_SEQ_CST;
static const DecoratorSet atomic_cmpxchg_mo_decorators = MO_RELAXED | MO_SEQ_CST;

Expand Down Expand Up @@ -360,7 +360,6 @@ void Access<decorators>::verify_decorators() {
const DecoratorSet memory_ordering_decorators = decorators & MO_DECORATOR_MASK;
STATIC_ASSERT(memory_ordering_decorators == 0 || ( // make sure memory ordering decorators are disjoint if set
(memory_ordering_decorators ^ MO_UNORDERED) == 0 ||
(memory_ordering_decorators ^ MO_VOLATILE) == 0 ||
(memory_ordering_decorators ^ MO_RELAXED) == 0 ||
(memory_ordering_decorators ^ MO_ACQUIRE) == 0 ||
(memory_ordering_decorators ^ MO_RELEASE) == 0 ||
Expand Down
26 changes: 6 additions & 20 deletions src/hotspot/share/oops/accessBackend.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -247,13 +247,6 @@ class RawAccessBarrier: public AllStatic {
HasDecorator<ds, MO_RELAXED>::value, T>::type
load_internal(void* addr);

template <DecoratorSet ds, typename T>
static inline typename EnableIf<
HasDecorator<ds, MO_VOLATILE>::value, T>::type
load_internal(void* addr) {
return *reinterpret_cast<const volatile T*>(addr);
}

template <DecoratorSet ds, typename T>
static inline typename EnableIf<
HasDecorator<ds, MO_UNORDERED>::value, T>::type
Expand All @@ -276,13 +269,6 @@ class RawAccessBarrier: public AllStatic {
HasDecorator<ds, MO_RELAXED>::value>::type
store_internal(void* addr, T value);

template <DecoratorSet ds, typename T>
static inline typename EnableIf<
HasDecorator<ds, MO_VOLATILE>::value>::type
store_internal(void* addr, T value) {
(void)const_cast<T&>(*reinterpret_cast<volatile T*>(addr) = value);
}

template <DecoratorSet ds, typename T>
static inline typename EnableIf<
HasDecorator<ds, MO_UNORDERED>::value>::type
Expand Down Expand Up @@ -1119,7 +1105,7 @@ namespace AccessInternal {
}

// Step 1: Set default decorators. This step remembers if a type was volatile
// and then sets the MO_VOLATILE decorator by default. Otherwise, a default
// and then sets the MO_RELAXED decorator by default. Otherwise, a default
// memory ordering is set for the access, and the implied decorator rules
// are applied to select sensible defaults for decorators that have not been
// explicitly set. For example, default object referent strength is set to strong.
Expand All @@ -1143,10 +1129,10 @@ namespace AccessInternal {
typedef typename Decay<T>::type DecayedT;
DecayedT decayed_value = value;
// If a volatile address is passed in but no memory ordering decorator,
// set the memory ordering to MO_VOLATILE by default.
// set the memory ordering to MO_RELAXED by default.
const DecoratorSet expanded_decorators = DecoratorFixup<
(IsVolatile<P>::value && !HasDecorator<decorators, MO_DECORATOR_MASK>::value) ?
(MO_VOLATILE | decorators) : decorators>::value;
(MO_RELAXED | decorators) : decorators>::value;
store_reduce_types<expanded_decorators>(const_cast<DecayedP*>(addr), decayed_value);
}

Expand All @@ -1169,10 +1155,10 @@ namespace AccessInternal {
typename OopOrNarrowOop<T>::type,
typename Decay<T>::type>::type DecayedT;
// If a volatile address is passed in but no memory ordering decorator,
// set the memory ordering to MO_VOLATILE by default.
// set the memory ordering to MO_RELAXED by default.
const DecoratorSet expanded_decorators = DecoratorFixup<
(IsVolatile<P>::value && !HasDecorator<decorators, MO_DECORATOR_MASK>::value) ?
(MO_VOLATILE | decorators) : decorators>::value;
(MO_RELAXED | decorators) : decorators>::value;
return load_reduce_types<expanded_decorators, DecayedT>(const_cast<DecayedP*>(addr));
}

Expand Down
70 changes: 34 additions & 36 deletions src/hotspot/share/oops/accessDecorators.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -78,7 +78,6 @@ const DecoratorSet INTERNAL_DECORATOR_MASK = INTERNAL_CONVERT_COMPRESS
// have a JMM equivalent property.
// The equivalence may be viewed like this:
// MO_UNORDERED is equivalent to JMM plain.
// MO_VOLATILE has no equivalence in JMM, because it's a C++ thing.
// MO_RELAXED is equivalent to JMM opaque.
// MO_ACQUIRE is equivalent to JMM acquire.
// MO_RELEASE is equivalent to JMM release.
Expand All @@ -87,12 +86,12 @@ const DecoratorSet INTERNAL_DECORATOR_MASK = INTERNAL_CONVERT_COMPRESS
// === Stores ===
// * MO_UNORDERED (Default): No guarantees.
// - The compiler and hardware are free to reorder aggressively. And they will.
// * MO_VOLATILE: Volatile stores (in the C++ sense).
// - The stores are not reordered by the compiler (but possibly the HW) w.r.t. other
// volatile accesses in program order (but possibly non-volatile accesses).
// * MO_RELAXED: Relaxed atomic stores.
// - The stores are atomic.
// - Guarantees from volatile stores hold.
// - The stores are not reordered by the compiler (but possibly the HW) w.r.t
// other ordered accesses in program order.
// - Also used for C++ volatile stores, since actual usage of volatile
// requires no word tearing.
// * MO_RELEASE: Releasing stores.
// - The releasing store will make its preceding memory accesses observable to memory accesses
// subsequent to an acquiring load observing this releasing store.
Expand All @@ -104,12 +103,12 @@ const DecoratorSet INTERNAL_DECORATOR_MASK = INTERNAL_CONVERT_COMPRESS
// === Loads ===
// * MO_UNORDERED (Default): No guarantees
// - The compiler and hardware are free to reorder aggressively. And they will.
// * MO_VOLATILE: Volatile loads (in the C++ sense).
// - The loads are not reordered by the compiler (but possibly the HW) w.r.t. other
// volatile accesses in program order (but possibly non-volatile accesses).
// * MO_RELAXED: Relaxed atomic loads.
// - The loads are atomic.
// - Guarantees from volatile loads hold.
// - The loads are not reordered by the compiler (but possibly the HW) w.r.t.
// other ordered accesses in program order.
// - Also used for C++ volatile loads, since actual usage of volatile
// requires no word tearing.
// * MO_ACQUIRE: Acquiring loads.
// - An acquiring load will make subsequent memory accesses observe the memory accesses
// preceding the releasing store that the acquiring load observed.
Expand All @@ -129,12 +128,11 @@ const DecoratorSet INTERNAL_DECORATOR_MASK = INTERNAL_CONVERT_COMPRESS
// * MO_SEQ_CST: Sequentially consistent xchg.
// - Guarantees from MO_SEQ_CST loads and MO_SEQ_CST stores hold.
const DecoratorSet MO_UNORDERED = UCONST64(1) << 6;
const DecoratorSet MO_VOLATILE = UCONST64(1) << 7;
const DecoratorSet MO_RELAXED = UCONST64(1) << 8;
const DecoratorSet MO_ACQUIRE = UCONST64(1) << 9;
const DecoratorSet MO_RELEASE = UCONST64(1) << 10;
const DecoratorSet MO_SEQ_CST = UCONST64(1) << 11;
const DecoratorSet MO_DECORATOR_MASK = MO_UNORDERED | MO_VOLATILE | MO_RELAXED |
const DecoratorSet MO_RELAXED = UCONST64(1) << 7;
const DecoratorSet MO_ACQUIRE = UCONST64(1) << 8;
const DecoratorSet MO_RELEASE = UCONST64(1) << 9;
const DecoratorSet MO_SEQ_CST = UCONST64(1) << 10;
const DecoratorSet MO_DECORATOR_MASK = MO_UNORDERED | MO_RELAXED |
MO_ACQUIRE | MO_RELEASE | MO_SEQ_CST;

// === Barrier Strength Decorators ===
Expand All @@ -154,9 +152,9 @@ const DecoratorSet MO_DECORATOR_MASK = MO_UNORDERED | MO_VOLATILE | MO_RELAXED |
// responsibility of performing the access and what barriers to be performed to the GC. This is the default.
// Note that primitive accesses will only be resolved on the barrier set if the appropriate build-time
// decorator for enabling primitive barriers is enabled for the build.
const DecoratorSet AS_RAW = UCONST64(1) << 12;
const DecoratorSet AS_NO_KEEPALIVE = UCONST64(1) << 13;
const DecoratorSet AS_NORMAL = UCONST64(1) << 14;
const DecoratorSet AS_RAW = UCONST64(1) << 11;
const DecoratorSet AS_NO_KEEPALIVE = UCONST64(1) << 12;
const DecoratorSet AS_NORMAL = UCONST64(1) << 13;
const DecoratorSet AS_DECORATOR_MASK = AS_RAW | AS_NO_KEEPALIVE | AS_NORMAL;

// === Reference Strength Decorators ===
Expand All @@ -168,10 +166,10 @@ const DecoratorSet AS_DECORATOR_MASK = AS_RAW | AS_NO_KEEPALIVE | AS_NORMA
// * ON_UNKNOWN_OOP_REF: The memory access is performed on a reference of unknown strength.
// This could for example come from the unsafe API.
// * Default (no explicit reference strength specified): ON_STRONG_OOP_REF
const DecoratorSet ON_STRONG_OOP_REF = UCONST64(1) << 15;
const DecoratorSet ON_WEAK_OOP_REF = UCONST64(1) << 16;
const DecoratorSet ON_PHANTOM_OOP_REF = UCONST64(1) << 17;
const DecoratorSet ON_UNKNOWN_OOP_REF = UCONST64(1) << 18;
const DecoratorSet ON_STRONG_OOP_REF = UCONST64(1) << 14;
const DecoratorSet ON_WEAK_OOP_REF = UCONST64(1) << 15;
const DecoratorSet ON_PHANTOM_OOP_REF = UCONST64(1) << 16;
const DecoratorSet ON_UNKNOWN_OOP_REF = UCONST64(1) << 17;
const DecoratorSet ON_DECORATOR_MASK = ON_STRONG_OOP_REF | ON_WEAK_OOP_REF |
ON_PHANTOM_OOP_REF | ON_UNKNOWN_OOP_REF;

Expand All @@ -181,8 +179,8 @@ const DecoratorSet ON_DECORATOR_MASK = ON_STRONG_OOP_REF | ON_WEAK_OOP_REF |
// * IN_HEAP: The access is performed in the heap. Many barriers such as card marking will
// be omitted if this decorator is not set.
// * IN_NATIVE: The access is performed in an off-heap data structure.
const DecoratorSet IN_HEAP = UCONST64(1) << 19;
const DecoratorSet IN_NATIVE = UCONST64(1) << 20;
const DecoratorSet IN_HEAP = UCONST64(1) << 18;
const DecoratorSet IN_NATIVE = UCONST64(1) << 19;
const DecoratorSet IN_DECORATOR_MASK = IN_HEAP | IN_NATIVE;

// == Boolean Flag Decorators ==
Expand All @@ -191,9 +189,9 @@ const DecoratorSet IN_DECORATOR_MASK = IN_HEAP | IN_NATIVE;
// * IS_DEST_UNINITIALIZED: This property can be important to e.g. SATB barriers by
// marking that the previous value is uninitialized nonsense rather than a real value.
// * IS_NOT_NULL: This property can make certain barriers faster such as compressing oops.
const DecoratorSet IS_ARRAY = UCONST64(1) << 21;
const DecoratorSet IS_DEST_UNINITIALIZED = UCONST64(1) << 22;
const DecoratorSet IS_NOT_NULL = UCONST64(1) << 23;
const DecoratorSet IS_ARRAY = UCONST64(1) << 20;
const DecoratorSet IS_DEST_UNINITIALIZED = UCONST64(1) << 21;
const DecoratorSet IS_NOT_NULL = UCONST64(1) << 22;

// == Arraycopy Decorators ==
// * ARRAYCOPY_CHECKCAST: This property means that the class of the objects in source
Expand All @@ -205,11 +203,11 @@ const DecoratorSet IS_NOT_NULL = UCONST64(1) << 23;
// * ARRAYCOPY_ARRAYOF: The copy is in the arrayof form.
// * ARRAYCOPY_ATOMIC: The accesses have to be atomic over the size of its elements.
// * ARRAYCOPY_ALIGNED: The accesses have to be aligned on a HeapWord.
const DecoratorSet ARRAYCOPY_CHECKCAST = UCONST64(1) << 24;
const DecoratorSet ARRAYCOPY_DISJOINT = UCONST64(1) << 25;
const DecoratorSet ARRAYCOPY_ARRAYOF = UCONST64(1) << 26;
const DecoratorSet ARRAYCOPY_ATOMIC = UCONST64(1) << 27;
const DecoratorSet ARRAYCOPY_ALIGNED = UCONST64(1) << 28;
const DecoratorSet ARRAYCOPY_CHECKCAST = UCONST64(1) << 23;
const DecoratorSet ARRAYCOPY_DISJOINT = UCONST64(1) << 24;
const DecoratorSet ARRAYCOPY_ARRAYOF = UCONST64(1) << 25;
const DecoratorSet ARRAYCOPY_ATOMIC = UCONST64(1) << 26;
const DecoratorSet ARRAYCOPY_ALIGNED = UCONST64(1) << 27;
const DecoratorSet ARRAYCOPY_DECORATOR_MASK = ARRAYCOPY_CHECKCAST | ARRAYCOPY_DISJOINT |
ARRAYCOPY_DISJOINT | ARRAYCOPY_ARRAYOF |
ARRAYCOPY_ATOMIC | ARRAYCOPY_ALIGNED;
Expand All @@ -218,11 +216,11 @@ const DecoratorSet ARRAYCOPY_DECORATOR_MASK = ARRAYCOPY_CHECKCAST | ARRAYC
// * ACCESS_READ: Indicate that the resolved object is accessed read-only. This allows the GC
// backend to use weaker and more efficient barriers.
// * ACCESS_WRITE: Indicate that the resolved object is used for write access.
const DecoratorSet ACCESS_READ = UCONST64(1) << 29;
const DecoratorSet ACCESS_WRITE = UCONST64(1) << 30;
const DecoratorSet ACCESS_READ = UCONST64(1) << 28;
const DecoratorSet ACCESS_WRITE = UCONST64(1) << 29;

// Keep track of the last decorator.
const DecoratorSet DECORATOR_LAST = UCONST64(1) << 30;
const DecoratorSet DECORATOR_LAST = UCONST64(1) << 29;

namespace AccessInternal {
// This class adds implied decorators that follow according to decorator rules.
Expand Down
6 changes: 3 additions & 3 deletions src/hotspot/share/oops/oop.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -64,8 +64,8 @@ class oopDesc {
inline markWord mark_raw() const;
inline markWord* mark_addr_raw() const;

inline void set_mark(volatile markWord m);
inline void set_mark_raw(volatile markWord m);
inline void set_mark(markWord m);
inline void set_mark_raw(markWord m);
static inline void set_mark_raw(HeapWord* mem, markWord m);

inline void release_set_mark(markWord m);
Expand Down
6 changes: 3 additions & 3 deletions src/hotspot/share/oops/oop.inline.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -43,7 +43,7 @@
// We need a separate file to avoid circular references

markWord oopDesc::mark() const {
uintptr_t v = HeapAccess<MO_VOLATILE>::load_at(as_oop(), mark_offset_in_bytes());
uintptr_t v = HeapAccess<MO_RELAXED>::load_at(as_oop(), mark_offset_in_bytes());
return markWord(v);
}

Expand All @@ -56,7 +56,7 @@ markWord* oopDesc::mark_addr_raw() const {
}

void oopDesc::set_mark(markWord m) {
HeapAccess<MO_VOLATILE>::store_at(as_oop(), mark_offset_in_bytes(), m.value());
HeapAccess<MO_RELAXED>::store_at(as_oop(), mark_offset_in_bytes(), m.value());
}

void oopDesc::set_mark_raw(markWord m) {
Expand Down

0 comments on commit e9b8463

Please sign in to comment.