Skip to content

Commit 488330d

Browse files
committed
8307533: Use atomic bitset functions for metadata flags
Reviewed-by: ccheung, kbarrett
1 parent 60ab135 commit 488330d

File tree

5 files changed

+10
-62
lines changed

5 files changed

+10
-62
lines changed

src/hotspot/share/oops/fieldInfo.inline.hpp

+3-14
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "memory/metadataFactory.hpp"
3131
#include "oops/constantPool.hpp"
3232
#include "oops/symbol.hpp"
33+
#include "runtime/atomic.hpp"
3334

3435
inline Symbol* FieldInfo::name(ConstantPool* cp) const {
3536
int index = _name_index;
@@ -151,23 +152,11 @@ inline FieldInfoReader& FieldInfoReader::set_position_and_next_index(int positio
151152
}
152153

153154
inline void FieldStatus::atomic_set_bits(u1& flags, u1 mask) {
154-
// Atomically update the flags with the bits given
155-
u1 old_flags, new_flags, witness;
156-
do {
157-
old_flags = flags;
158-
new_flags = old_flags | mask;
159-
witness = Atomic::cmpxchg(&flags, old_flags, new_flags);
160-
} while (witness != old_flags);
155+
Atomic::fetch_then_or(&flags, mask);
161156
}
162157

163158
inline void FieldStatus::atomic_clear_bits(u1& flags, u1 mask) {
164-
// Atomically update the flags with the bits given
165-
u1 old_flags, new_flags, witness;
166-
do {
167-
old_flags = flags;
168-
new_flags = old_flags & ~mask;
169-
witness = Atomic::cmpxchg(&flags, old_flags, new_flags);
170-
} while (witness != old_flags);
159+
Atomic::fetch_then_and(&flags, (u1)(~mask));
171160
}
172161

173162
inline void FieldStatus::update_flag(FieldStatusBitPosition pos, bool z) {

src/hotspot/share/oops/instanceKlassFlags.cpp

-22
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,10 @@
2626
#include "classfile/classLoader.hpp"
2727
#include "classfile/classLoaderData.inline.hpp"
2828
#include "oops/instanceKlassFlags.hpp"
29-
#include "runtime/atomic.hpp"
3029
#include "runtime/safepoint.hpp"
3130
#include "utilities/macros.hpp"
3231
#include "utilities/ostream.hpp"
3332

34-
// This can be removed for the atomic bitset functions, when available.
35-
void InstanceKlassFlags::atomic_set_bits(u1 bits) {
36-
// Atomically update the status with the bits given
37-
u1 old_status, new_status, f;
38-
do {
39-
old_status = _status;
40-
new_status = old_status | bits;
41-
f = Atomic::cmpxchg(&_status, old_status, new_status);
42-
} while(f != old_status);
43-
}
44-
45-
void InstanceKlassFlags::atomic_clear_bits(u1 bits) {
46-
// Atomically update the status with the bits given
47-
u1 old_status, new_status, f;
48-
do {
49-
old_status = _status;
50-
new_status = old_status & ~bits;
51-
f = Atomic::cmpxchg(&_status, old_status, new_status);
52-
} while(f != old_status);
53-
}
54-
5533
void InstanceKlassFlags::print_on(outputStream* st) const {
5634
#define IK_FLAGS_PRINT(name, ignore) \
5735
if (name()) st->print(" ##name ");

src/hotspot/share/oops/instanceKlassFlags.hpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#ifndef SHARE_OOPS_INSTANCEKLASSFLAGS_HPP
2626
#define SHARE_OOPS_INSTANCEKLASSFLAGS_HPP
2727

28+
#include "runtime/atomic.hpp"
29+
2830
class ClassLoaderData;
2931

3032
// The InstanceKlassFlags class contains the parse-time and writeable flags associated with
@@ -121,8 +123,8 @@ class InstanceKlassFlags {
121123
IK_STATUS_DO(IK_STATUS_GET_SET)
122124
#undef IK_STATUS_GET_SET
123125

124-
void atomic_set_bits(u1 bits);
125-
void atomic_clear_bits(u1 bits);
126+
void atomic_set_bits(u1 bits) { Atomic::fetch_then_or(&_status, bits); }
127+
void atomic_clear_bits(u1 bits) { Atomic::fetch_then_and(&_status, (u1)(~bits)); }
126128
void print_on(outputStream* st) const;
127129
};
128130

src/hotspot/share/oops/methodFlags.cpp

-22
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,8 @@
2424

2525
#include "precompiled.hpp"
2626
#include "oops/methodFlags.hpp"
27-
#include "runtime/atomic.hpp"
2827
#include "utilities/ostream.hpp"
2928

30-
// This can be removed for the atomic bitset functions, when available.
31-
void MethodFlags::atomic_set_bits(u4 bits) {
32-
// Atomically update the status with the bits given
33-
u4 old_status, new_status, f;
34-
do {
35-
old_status = _status;
36-
new_status = old_status | bits;
37-
f = Atomic::cmpxchg(&_status, old_status, new_status);
38-
} while(f != old_status);
39-
}
40-
41-
void MethodFlags::atomic_clear_bits(u4 bits) {
42-
// Atomically update the status with the bits given
43-
u4 old_status, new_status, f;
44-
do {
45-
old_status = _status;
46-
new_status = old_status & ~bits;
47-
f = Atomic::cmpxchg(&_status, old_status, new_status);
48-
} while(f != old_status);
49-
}
50-
5129
void MethodFlags::print_on(outputStream* st) const {
5230
#define M_PRINT(name, ignore) \
5331
if (name()) st->print(" " #name " ");

src/hotspot/share/oops/methodFlags.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#ifndef SHARE_OOPS_METHODFLAGS_HPP
2626
#define SHARE_OOPS_METHODFLAGS_HPP
2727

28+
#include "runtime/atomic.hpp"
2829
#include "utilities/globalDefinitions.hpp"
2930
#include "utilities/macros.hpp"
3031

@@ -86,8 +87,8 @@ class MethodFlags {
8687
#undef M_STATUS_GET_SET
8788

8889
int as_int() const { return _status; }
89-
void atomic_set_bits(u4 bits);
90-
void atomic_clear_bits(u4 bits);
90+
void atomic_set_bits(u4 bits) { Atomic::fetch_then_or(&_status, bits); }
91+
void atomic_clear_bits(u4 bits) { Atomic::fetch_then_and(&_status, ~bits); }
9192
void print_on(outputStream* st) const;
9293
};
9394

0 commit comments

Comments
 (0)