Remove ArtMethod's declaring class state checks.
This check was not very useful because the Class is already
in a state to pass the check when we're constructing the
ArtMethod and it can never revert to an earlier state, so
the check is essentially a weak protection against GC bugs.
Besides not being very useful, the check had the ability to
invalidate ObjPtr<> cookies (when called in non-runnable
state), making it difficult to fully ObjPtr<>-ify the code.
Also remove a lot of kReadBarrierOption template parameters
which were needed specifically for this check. This removes
unnecessary maintence burden as shown by past bugs dealing
with carefully adding those parameters where necessary.
Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Bug: 74373650
Bug: 31113334
Change-Id: I87f2999fc4e7c27b5c2307139269b4b5f6649d16
diff --git a/runtime/art_method.h b/runtime/art_method.h
index f5ef3fa..ce08cb0 100644
--- a/runtime/art_method.h
+++ b/runtime/art_method.h
@@ -107,13 +107,7 @@
return MemberOffset(OFFSETOF_MEMBER(ArtMethod, declaring_class_));
}
- // Note: GetAccessFlags acquires the mutator lock in debug mode to check that it is not called for
- // a proxy method.
- template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
uint32_t GetAccessFlags() {
- if (kCheckDeclaringClassState) {
- GetAccessFlagsDCheck<kReadBarrierOption>();
- }
return access_flags_.load(std::memory_order_relaxed);
}
@@ -172,14 +166,12 @@
return (GetAccessFlags() & synchonized) != 0;
}
- template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
bool IsFinal() {
- return (GetAccessFlags<kReadBarrierOption>() & kAccFinal) != 0;
+ return (GetAccessFlags() & kAccFinal) != 0;
}
- template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
bool IsIntrinsic() {
- return (GetAccessFlags<kReadBarrierOption>() & kAccIntrinsic) != 0;
+ return (GetAccessFlags() & kAccIntrinsic) != 0;
}
ALWAYS_INLINE void SetIntrinsic(uint32_t intrinsic) REQUIRES_SHARED(Locks::mutator_lock_);
@@ -241,25 +233,22 @@
}
// This is set by the class linker.
- template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
bool IsDefault() {
static_assert((kAccDefault & (kAccIntrinsic | kAccIntrinsicBits)) == 0,
"kAccDefault conflicts with intrinsic modifier");
- return (GetAccessFlags<kReadBarrierOption>() & kAccDefault) != 0;
+ return (GetAccessFlags() & kAccDefault) != 0;
}
- template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
bool IsObsolete() {
- return (GetAccessFlags<kReadBarrierOption>() & kAccObsoleteMethod) != 0;
+ return (GetAccessFlags() & kAccObsoleteMethod) != 0;
}
void SetIsObsolete() {
AddAccessFlags(kAccObsoleteMethod);
}
- template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
bool IsNative() {
- return (GetAccessFlags<kReadBarrierOption>() & kAccNative) != 0;
+ return (GetAccessFlags() & kAccNative) != 0;
}
// Checks to see if the method was annotated with @dalvik.annotation.optimization.FastNative.
@@ -280,9 +269,8 @@
return (GetAccessFlags() & mask) == mask;
}
- template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
bool IsAbstract() {
- return (GetAccessFlags<kReadBarrierOption>() & kAccAbstract) != 0;
+ return (GetAccessFlags() & kAccAbstract) != 0;
}
bool IsSynthetic() {
@@ -305,7 +293,7 @@
void SetSkipAccessChecks() {
// SkipAccessChecks() is applicable only to non-native methods.
- DCHECK(!IsNative<kWithoutReadBarrier>());
+ DCHECK(!IsNative());
AddAccessFlags(kAccSkipAccessChecks);
}
@@ -317,13 +305,12 @@
return (GetAccessFlags() & kAccPreviouslyWarm) != 0;
}
- template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
void SetPreviouslyWarm() {
- if (IsIntrinsic<kReadBarrierOption>()) {
+ if (IsIntrinsic()) {
// kAccPreviouslyWarm overlaps with kAccIntrinsicBits.
return;
}
- AddAccessFlags<kReadBarrierOption>(kAccPreviouslyWarm);
+ AddAccessFlags(kAccPreviouslyWarm);
}
// Should this method be run in the interpreter and count locks (e.g., failed structured-
@@ -384,11 +371,9 @@
// Number of 32bit registers that would be required to hold all the arguments
static size_t NumArgRegisters(const StringPiece& shorty);
- ALWAYS_INLINE uint32_t GetDexMethodIndexUnchecked() {
+ ALWAYS_INLINE uint32_t GetDexMethodIndex() {
return dex_method_index_;
}
- template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
- ALWAYS_INLINE uint32_t GetDexMethodIndex() REQUIRES_SHARED(Locks::mutator_lock_);
void SetDexMethodIndex(uint32_t new_idx) {
// Not called within a transaction.
@@ -472,11 +457,7 @@
}
ProfilingInfo* GetProfilingInfo(PointerSize pointer_size) REQUIRES_SHARED(Locks::mutator_lock_) {
- // Don't do a read barrier in the DCHECK() inside GetAccessFlags() called by IsNative(),
- // as GetProfilingInfo is called in places where the declaring class is treated as a weak
- // reference (accessing it with a read barrier would either prevent unloading the class,
- // or crash the runtime if the GC wants to unload it).
- if (UNLIKELY(IsNative<kWithoutReadBarrier>()) || UNLIKELY(IsProxyMethod())) {
+ if (UNLIKELY(IsNative()) || UNLIKELY(IsProxyMethod())) {
return nullptr;
}
return reinterpret_cast<ProfilingInfo*>(GetDataPtrSize(pointer_size));
@@ -513,15 +494,12 @@
ArtMethod* GetCanonicalMethod(PointerSize pointer_size = kRuntimePointerSize)
REQUIRES_SHARED(Locks::mutator_lock_);
- template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
- ArtMethod* GetSingleImplementation(PointerSize pointer_size)
- REQUIRES_SHARED(Locks::mutator_lock_);
+ ArtMethod* GetSingleImplementation(PointerSize pointer_size);
- template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
ALWAYS_INLINE void SetSingleImplementation(ArtMethod* method, PointerSize pointer_size) {
- DCHECK(!IsNative<kReadBarrierOption>());
+ DCHECK(!IsNative());
// Non-abstract method's single implementation is just itself.
- DCHECK(IsAbstract<kReadBarrierOption>());
+ DCHECK(IsAbstract());
SetDataPtrSize(method, pointer_size);
}
@@ -713,7 +691,7 @@
REQUIRES_SHARED(Locks::mutator_lock_);
// Update entry points by passing them through the visitor.
- template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier, typename Visitor>
+ template <typename Visitor>
ALWAYS_INLINE void UpdateEntrypoints(const Visitor& visitor, PointerSize pointer_size);
// Visit the individual members of an ArtMethod. Used by imgdiag.
@@ -833,8 +811,6 @@
}
}
- template <ReadBarrierOption kReadBarrierOption> void GetAccessFlagsDCheck();
-
static inline bool IsValidIntrinsicUpdate(uint32_t modifier) {
return (((modifier & kAccIntrinsic) == kAccIntrinsic) &&
(((modifier & ~(kAccIntrinsic | kAccIntrinsicBits)) == 0)));
@@ -845,9 +821,8 @@
}
// This setter guarantees atomicity.
- template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
void AddAccessFlags(uint32_t flag) {
- DCHECK(!IsIntrinsic<kReadBarrierOption>() ||
+ DCHECK(!IsIntrinsic() ||
!OverlapsIntrinsicBits(flag) ||
IsValidIntrinsicUpdate(flag));
uint32_t old_access_flags;