From b1106e2aa98105dec533cdac9074a8f0216a4106 Mon Sep 17 00:00:00 2001 From: Andreas Gampe Date: Thu, 23 Feb 2017 11:34:48 -0800 Subject: [PATCH] ART: Add flag for ArtMethod class state checks The checks, especially in GetAccessFlags, is expensive. To help with running a debug build on devices, add a flag to be able to turn the checks off. Bug: 35644369 Test: m Change-Id: I2a3db1a56986df8f4a8b2dc5bcb26e1bcaea0a24 --- runtime/art_method-inl.h | 14 +++++++++----- runtime/art_method.h | 2 ++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/runtime/art_method-inl.h b/runtime/art_method-inl.h index 473d9cf74..685e26c78 100644 --- a/runtime/art_method-inl.h +++ b/runtime/art_method-inl.h @@ -55,8 +55,10 @@ inline mirror::Class* ArtMethod::GetDeclaringClass() { if (kIsDebugBuild) { if (!IsRuntimeMethod()) { CHECK(result != nullptr) << this; - CHECK(result->IsIdxLoaded() || result->IsErroneous()) - << result->GetStatus() << " " << result->PrettyClass(); + if (kCheckDeclaringClassState) { + CHECK(result->IsIdxLoaded() || result->IsErroneous()) + << result->GetStatus() << " " << result->PrettyClass(); + } } else { CHECK(result == nullptr) << this; } @@ -89,7 +91,7 @@ ALWAYS_INLINE static inline void DoGetAccessFlagsHelper(ArtMethod* method) template inline uint32_t ArtMethod::GetAccessFlags() { - if (kIsDebugBuild) { + if (kCheckDeclaringClassState) { Thread* self = Thread::Current(); if (!Locks::mutator_lock_->IsSharedHeld(self)) { if (self->IsThreadSuspensionAllowable()) { @@ -118,8 +120,10 @@ inline uint16_t ArtMethod::GetMethodIndexDuringLinking() { } inline uint32_t ArtMethod::GetDexMethodIndex() { - DCHECK(IsRuntimeMethod() || GetDeclaringClass()->IsIdxLoaded() || - GetDeclaringClass()->IsErroneous()); + if (kCheckDeclaringClassState) { + CHECK(IsRuntimeMethod() || GetDeclaringClass()->IsIdxLoaded() || + GetDeclaringClass()->IsErroneous()); + } return GetDexMethodIndexUnchecked(); } diff --git a/runtime/art_method.h b/runtime/art_method.h index 99d7a49dc..cd1950c0e 100644 --- a/runtime/art_method.h +++ b/runtime/art_method.h @@ -53,6 +53,8 @@ class PointerArray; class ArtMethod FINAL { public: + static constexpr bool kCheckDeclaringClassState = kIsDebugBuild; + ArtMethod() : access_flags_(0), dex_code_item_offset_(0), dex_method_index_(0), method_index_(0), hotness_count_(0) { } -- 2.11.0