diff options
author | 2017-02-01 16:46:28 -0800 | |
---|---|---|
committer | 2017-04-21 08:40:33 -0700 | |
commit | c6ea7d00ad069a2736f603daa3d8eaa9a1f8ea11 (patch) | |
tree | a6d3332a8592fb806841314d55b206b573d37d86 | |
parent | d68677c5fde1ace16ea58d65733776c954e7acb4 (diff) |
ART: Clean up art_method.h
Clean up the header. Fix up other headers including the -inl file,
in an effort to prune the include graph. Fix broken transitive
includes by making includes explicit. Introduce new -inl files
for method handles and reference visiting.
Test: source build/envsetup.sh && lunch aosp_angler-userdebug && mmma art
Test: source build/envsetup.sh && lunch aosp_mips64-userdebug && mmma art
Change-Id: I8f60f1160c2a702fdf3598149dae38f6fa6bc851
82 files changed, 473 insertions, 358 deletions
diff --git a/compiler/common_compiler_test.cc b/compiler/common_compiler_test.cc index 8b3029261f..39edd1eb02 100644 --- a/compiler/common_compiler_test.cc +++ b/compiler/common_compiler_test.cc @@ -18,7 +18,7 @@ #include "arch/instruction_set_features.h" #include "art_field-inl.h" -#include "art_method.h" +#include "art_method-inl.h" #include "base/enums.h" #include "class_linker.h" #include "compiled_method.h" diff --git a/compiler/dex/dex_to_dex_compiler.cc b/compiler/dex/dex_to_dex_compiler.cc index 538fe93793..1573062033 100644 --- a/compiler/dex/dex_to_dex_compiler.cc +++ b/compiler/dex/dex_to_dex_compiler.cc @@ -27,7 +27,6 @@ #include "dex_instruction-inl.h" #include "driver/compiler_driver.h" #include "driver/dex_compilation_unit.h" -#include "mirror/class-inl.h" #include "mirror/dex_cache.h" #include "thread-inl.h" diff --git a/compiler/dex/verified_method.cc b/compiler/dex/verified_method.cc index cbca33320d..608a18aa66 100644 --- a/compiler/dex/verified_method.cc +++ b/compiler/dex/verified_method.cc @@ -18,22 +18,15 @@ #include <algorithm> #include <memory> -#include <vector> -#include "art_method-inl.h" -#include "base/enums.h" #include "base/logging.h" -#include "base/stl_util.h" #include "dex_file.h" #include "dex_instruction-inl.h" -#include "dex_instruction_utils.h" -#include "mirror/class-inl.h" -#include "mirror/dex_cache-inl.h" -#include "mirror/object-inl.h" -#include "utils.h" +#include "runtime.h" #include "verifier/method_verifier-inl.h" #include "verifier/reg_type-inl.h" #include "verifier/register_line-inl.h" +#include "verifier/verifier_deps.h" namespace art { diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc index 1a4452429e..805c5dadc1 100644 --- a/compiler/driver/compiler_driver.cc +++ b/compiler/driver/compiler_driver.cc @@ -61,6 +61,7 @@ #include "mirror/class-inl.h" #include "mirror/dex_cache-inl.h" #include "mirror/object-inl.h" +#include "mirror/object-refvisitor-inl.h" #include "mirror/object_array-inl.h" #include "mirror/throwable.h" #include "scoped_thread_state_change-inl.h" diff --git a/compiler/elf_writer.cc b/compiler/elf_writer.cc index 0c0609009d..37e4f113fa 100644 --- a/compiler/elf_writer.cc +++ b/compiler/elf_writer.cc @@ -16,17 +16,8 @@ #include "elf_writer.h" -#include "art_method-inl.h" #include "base/unix_file/fd_file.h" -#include "class_linker.h" -#include "dex_file-inl.h" -#include "dex_method_iterator.h" -#include "driver/compiler_driver.h" #include "elf_file.h" -#include "invoke_type.h" -#include "mirror/object-inl.h" -#include "oat.h" -#include "scoped_thread_state_change-inl.h" namespace art { diff --git a/compiler/image_test.cc b/compiler/image_test.cc index 897d81993d..7e53d8d2ab 100644 --- a/compiler/image_test.cc +++ b/compiler/image_test.cc @@ -22,6 +22,7 @@ #include "android-base/stringprintf.h" +#include "art_method-inl.h" #include "base/unix_file/fd_file.h" #include "class_linker-inl.h" #include "compiler_callbacks.h" diff --git a/compiler/image_writer.cc b/compiler/image_writer.cc index d129249d63..952a7c637a 100644 --- a/compiler/image_writer.cc +++ b/compiler/image_writer.cc @@ -59,6 +59,7 @@ #include "mirror/executable.h" #include "mirror/method.h" #include "mirror/object-inl.h" +#include "mirror/object-refvisitor-inl.h" #include "mirror/object_array-inl.h" #include "mirror/string-inl.h" #include "oat.h" diff --git a/compiler/optimizing/code_generator.cc b/compiler/optimizing/code_generator.cc index b7c80756b0..c840e70660 100644 --- a/compiler/optimizing/code_generator.cc +++ b/compiler/optimizing/code_generator.cc @@ -42,6 +42,7 @@ #endif #include "bytecode_utils.h" +#include "class_linker.h" #include "compiled_method.h" #include "dex/verified_method.h" #include "driver/compiler_driver.h" @@ -51,9 +52,12 @@ #include "mirror/array-inl.h" #include "mirror/object_array-inl.h" #include "mirror/object_reference.h" +#include "mirror/reference.h" #include "mirror/string.h" #include "parallel_move_resolver.h" #include "ssa_liveness_analysis.h" +#include "scoped_thread_state_change-inl.h" +#include "thread-inl.h" #include "utils/assembler.h" namespace art { diff --git a/compiler/optimizing/instruction_simplifier.cc b/compiler/optimizing/instruction_simplifier.cc index 60790e5b84..2dcc12e294 100644 --- a/compiler/optimizing/instruction_simplifier.cc +++ b/compiler/optimizing/instruction_simplifier.cc @@ -16,6 +16,8 @@ #include "instruction_simplifier.h" +#include "art_method-inl.h" +#include "class_linker-inl.h" #include "escape.h" #include "intrinsics.h" #include "mirror/class-inl.h" diff --git a/compiler/optimizing/instruction_simplifier_arm.cc b/compiler/optimizing/instruction_simplifier_arm.cc index 5f5e29b024..3fc7c50bb1 100644 --- a/compiler/optimizing/instruction_simplifier_arm.cc +++ b/compiler/optimizing/instruction_simplifier_arm.cc @@ -19,6 +19,7 @@ #include "instruction_simplifier_arm.h" #include "instruction_simplifier_shared.h" #include "mirror/array-inl.h" +#include "mirror/string.h" #include "nodes.h" namespace art { diff --git a/compiler/optimizing/intrinsics.cc b/compiler/optimizing/intrinsics.cc index 8df80adc9f..6069f3482c 100644 --- a/compiler/optimizing/intrinsics.cc +++ b/compiler/optimizing/intrinsics.cc @@ -16,7 +16,7 @@ #include "intrinsics.h" -#include "art_method.h" +#include "art_method-inl.h" #include "class_linker.h" #include "driver/compiler_driver.h" #include "driver/compiler_options.h" diff --git a/compiler/optimizing/intrinsics_arm.cc b/compiler/optimizing/intrinsics_arm.cc index 1006a776f0..c0714d7089 100644 --- a/compiler/optimizing/intrinsics_arm.cc +++ b/compiler/optimizing/intrinsics_arm.cc @@ -22,9 +22,12 @@ #include "entrypoints/quick/quick_entrypoints.h" #include "intrinsics.h" #include "intrinsics_utils.h" +#include "lock_word.h" #include "mirror/array-inl.h" +#include "mirror/reference.h" #include "mirror/string.h" -#include "thread.h" +#include "scoped_thread_state_change-inl.h" +#include "thread-inl.h" #include "utils/arm/assembler_arm.h" namespace art { diff --git a/compiler/optimizing/intrinsics_arm64.cc b/compiler/optimizing/intrinsics_arm64.cc index 47bcb5d000..788c16200d 100644 --- a/compiler/optimizing/intrinsics_arm64.cc +++ b/compiler/optimizing/intrinsics_arm64.cc @@ -22,9 +22,12 @@ #include "common_arm64.h" #include "entrypoints/quick/quick_entrypoints.h" #include "intrinsics.h" +#include "lock_word.h" #include "mirror/array-inl.h" +#include "mirror/reference.h" #include "mirror/string-inl.h" -#include "thread.h" +#include "scoped_thread_state_change-inl.h" +#include "thread-inl.h" #include "utils/arm64/assembler_arm64.h" using namespace vixl::aarch64; // NOLINT(build/namespaces) diff --git a/compiler/optimizing/intrinsics_arm_vixl.cc b/compiler/optimizing/intrinsics_arm_vixl.cc index 0d933eaf82..a68fafcf18 100644 --- a/compiler/optimizing/intrinsics_arm_vixl.cc +++ b/compiler/optimizing/intrinsics_arm_vixl.cc @@ -17,10 +17,15 @@ #include "intrinsics_arm_vixl.h" #include "arch/arm/instruction_set_features_arm.h" +#include "art_method.h" #include "code_generator_arm_vixl.h" #include "common_arm.h" #include "lock_word.h" #include "mirror/array-inl.h" +#include "mirror/reference.h" +#include "mirror/string.h" +#include "scoped_thread_state_change-inl.h" +#include "thread-inl.h" #include "aarch32/constants-aarch32.h" diff --git a/compiler/optimizing/intrinsics_x86.cc b/compiler/optimizing/intrinsics_x86.cc index ecf919bceb..50ea33d7f3 100644 --- a/compiler/optimizing/intrinsics_x86.cc +++ b/compiler/optimizing/intrinsics_x86.cc @@ -25,9 +25,12 @@ #include "entrypoints/quick/quick_entrypoints.h" #include "intrinsics.h" #include "intrinsics_utils.h" +#include "lock_word.h" #include "mirror/array-inl.h" +#include "mirror/reference.h" #include "mirror/string.h" -#include "thread.h" +#include "scoped_thread_state_change-inl.h" +#include "thread-inl.h" #include "utils/x86/assembler_x86.h" #include "utils/x86/constants_x86.h" diff --git a/compiler/optimizing/intrinsics_x86_64.cc b/compiler/optimizing/intrinsics_x86_64.cc index 13956dfb8e..0ece86a540 100644 --- a/compiler/optimizing/intrinsics_x86_64.cc +++ b/compiler/optimizing/intrinsics_x86_64.cc @@ -19,15 +19,18 @@ #include <limits> #include "arch/x86_64/instruction_set_features_x86_64.h" -#include "art_method-inl.h" +#include "art_method.h" #include "base/bit_utils.h" #include "code_generator_x86_64.h" #include "entrypoints/quick/quick_entrypoints.h" #include "intrinsics.h" #include "intrinsics_utils.h" +#include "lock_word.h" #include "mirror/array-inl.h" +#include "mirror/reference.h" #include "mirror/string.h" -#include "thread.h" +#include "scoped_thread_state_change-inl.h" +#include "thread-inl.h" #include "utils/x86_64/assembler_x86_64.h" #include "utils/x86_64/constants_x86_64.h" diff --git a/compiler/optimizing/nodes.cc b/compiler/optimizing/nodes.cc index e71fea92a9..ca953a1a7e 100644 --- a/compiler/optimizing/nodes.cc +++ b/compiler/optimizing/nodes.cc @@ -17,6 +17,8 @@ #include <cfloat> +#include "art_method-inl.h" +#include "class_linker-inl.h" #include "code_generator.h" #include "common_dominator.h" #include "ssa_builder.h" diff --git a/compiler/optimizing/reference_type_propagation.cc b/compiler/optimizing/reference_type_propagation.cc index d5637b9b75..39effe0d0a 100644 --- a/compiler/optimizing/reference_type_propagation.cc +++ b/compiler/optimizing/reference_type_propagation.cc @@ -16,6 +16,7 @@ #include "reference_type_propagation.h" +#include "art_method-inl.h" #include "base/enums.h" #include "class_linker-inl.h" #include "mirror/class-inl.h" diff --git a/compiler/verifier_deps_test.cc b/compiler/verifier_deps_test.cc index 3b6b9cc7f0..0b1ab758b2 100644 --- a/compiler/verifier_deps_test.cc +++ b/compiler/verifier_deps_test.cc @@ -17,6 +17,7 @@ // Test is in compiler, as it uses compiler related code. #include "verifier/verifier_deps.h" +#include "art_method-inl.h" #include "class_linker.h" #include "common_compiler_test.h" #include "compiler_callbacks.h" diff --git a/patchoat/patchoat.cc b/patchoat/patchoat.cc index 0c2717f207..fbb0978d53 100644 --- a/patchoat/patchoat.cc +++ b/patchoat/patchoat.cc @@ -42,6 +42,7 @@ #include "mirror/dex_cache.h" #include "mirror/executable.h" #include "mirror/object-inl.h" +#include "mirror/object-refvisitor-inl.h" #include "mirror/method.h" #include "mirror/reference.h" #include "noop_compiler_callbacks.h" diff --git a/runtime/arch/arm/fault_handler_arm.cc b/runtime/arch/arm/fault_handler_arm.cc index 923ff4ff29..4c15450ff7 100644 --- a/runtime/arch/arm/fault_handler_arm.cc +++ b/runtime/arch/arm/fault_handler_arm.cc @@ -19,14 +19,12 @@ #include <sys/ucontext.h> -#include "art_method-inl.h" +#include "art_method.h" #include "base/enums.h" -#include "base/macros.h" #include "base/hex_dump.h" -#include "globals.h" #include "base/logging.h" -#include "base/hex_dump.h" -#include "thread.h" +#include "base/macros.h" +#include "globals.h" #include "thread-inl.h" // diff --git a/runtime/arch/arm64/fault_handler_arm64.cc b/runtime/arch/arm64/fault_handler_arm64.cc index 193af58f11..dc4e8f389e 100644 --- a/runtime/arch/arm64/fault_handler_arm64.cc +++ b/runtime/arch/arm64/fault_handler_arm64.cc @@ -19,14 +19,13 @@ #include <sys/ucontext.h> -#include "art_method-inl.h" +#include "art_method.h" #include "base/enums.h" +#include "base/hex_dump.h" +#include "base/logging.h" #include "base/macros.h" #include "globals.h" -#include "base/logging.h" -#include "base/hex_dump.h" #include "registers_arm64.h" -#include "thread.h" #include "thread-inl.h" extern "C" void art_quick_throw_stack_overflow(); diff --git a/runtime/arch/mips/fault_handler_mips.cc b/runtime/arch/mips/fault_handler_mips.cc index f9c19e87e6..7072a8a613 100644 --- a/runtime/arch/mips/fault_handler_mips.cc +++ b/runtime/arch/mips/fault_handler_mips.cc @@ -14,16 +14,16 @@ * limitations under the License. */ -#include "arch/mips/quick_method_frame_info_mips.h" #include "fault_handler.h" #include <sys/ucontext.h> -#include "art_method-inl.h" + +#include "art_method.h" +#include "base/hex_dump.h" +#include "base/logging.h" #include "base/macros.h" #include "globals.h" -#include "base/logging.h" -#include "base/hex_dump.h" +#include "quick_method_frame_info_mips.h" #include "registers_mips.h" -#include "thread.h" #include "thread-inl.h" extern "C" void art_quick_throw_stack_overflow(); diff --git a/runtime/arch/mips64/fault_handler_mips64.cc b/runtime/arch/mips64/fault_handler_mips64.cc index d668d3ab62..f9a92c834e 100644 --- a/runtime/arch/mips64/fault_handler_mips64.cc +++ b/runtime/arch/mips64/fault_handler_mips64.cc @@ -14,16 +14,17 @@ * limitations under the License. */ -#include "arch/mips64/quick_method_frame_info_mips64.h" #include "fault_handler.h" + #include <sys/ucontext.h> -#include "art_method-inl.h" + +#include "art_method.h" +#include "base/hex_dump.h" +#include "base/logging.h" #include "base/macros.h" #include "globals.h" -#include "base/logging.h" -#include "base/hex_dump.h" +#include "quick_method_frame_info_mips64.h" #include "registers_mips64.h" -#include "thread.h" #include "thread-inl.h" extern "C" void art_quick_throw_stack_overflow(); diff --git a/runtime/arch/x86/fault_handler_x86.cc b/runtime/arch/x86/fault_handler_x86.cc index 014cc15a40..7d8abb8cc5 100644 --- a/runtime/arch/x86/fault_handler_x86.cc +++ b/runtime/arch/x86/fault_handler_x86.cc @@ -19,14 +19,13 @@ #include <sys/ucontext.h> -#include "art_method-inl.h" +#include "art_method.h" #include "base/enums.h" -#include "base/macros.h" -#include "globals.h" -#include "base/logging.h" #include "base/hex_dump.h" +#include "base/logging.h" +#include "base/macros.h" #include "base/safe_copy.h" -#include "thread.h" +#include "globals.h" #include "thread-inl.h" #if defined(__APPLE__) diff --git a/runtime/art_field-inl.h b/runtime/art_field-inl.h index 16b73c681f..0e00977a32 100644 --- a/runtime/art_field-inl.h +++ b/runtime/art_field-inl.h @@ -21,6 +21,7 @@ #include "base/logging.h" #include "class_linker.h" +#include "dex_file-inl.h" #include "gc_root-inl.h" #include "gc/accounting/card_table-inl.h" #include "jvalue.h" diff --git a/runtime/art_method-inl.h b/runtime/art_method-inl.h index 5cf0e0f90c..59cd978a66 100644 --- a/runtime/art_method-inl.h +++ b/runtime/art_method-inl.h @@ -82,37 +82,6 @@ inline bool ArtMethod::CASDeclaringClass(mirror::Class* expected_class, expected_root, desired_root); } -// AssertSharedHeld doesn't work in GetAccessFlags, so use a NO_THREAD_SAFETY_ANALYSIS helper. -// TODO: Figure out why ASSERT_SHARED_CAPABILITY doesn't work. -template <ReadBarrierOption kReadBarrierOption> -ALWAYS_INLINE static inline void DoGetAccessFlagsHelper(ArtMethod* method) - NO_THREAD_SAFETY_ANALYSIS { - CHECK(method->IsRuntimeMethod() || - method->GetDeclaringClass<kReadBarrierOption>()->IsIdxLoaded() || - method->GetDeclaringClass<kReadBarrierOption>()->IsErroneous()); -} - -template <ReadBarrierOption kReadBarrierOption> -inline uint32_t ArtMethod::GetAccessFlags() { - if (kCheckDeclaringClassState) { - Thread* self = Thread::Current(); - if (!Locks::mutator_lock_->IsSharedHeld(self)) { - if (self->IsThreadSuspensionAllowable()) { - ScopedObjectAccess soa(self); - CHECK(IsRuntimeMethod() || - GetDeclaringClass<kReadBarrierOption>()->IsIdxLoaded() || - GetDeclaringClass<kReadBarrierOption>()->IsErroneous()); - } - } else { - // We cannot use SOA in this case. We might be holding the lock, but may not be in the - // runnable state (e.g., during GC). - Locks::mutator_lock_->AssertSharedHeld(self); - DoGetAccessFlagsHelper<kReadBarrierOption>(this); - } - } - return access_flags_.load(std::memory_order_relaxed); -} - inline uint16_t ArtMethod::GetMethodIndex() { DCHECK(IsRuntimeMethod() || GetDeclaringClass()->IsResolved()); return method_index_; @@ -224,10 +193,6 @@ inline bool ArtMethod::CheckIncompatibleClassChange(InvokeType type) { } } -inline bool ArtMethod::IsRuntimeMethod() { - return dex_method_index_ == DexFile::kDexNoIndex; -} - inline bool ArtMethod::IsCalleeSaveMethod() { if (!IsRuntimeMethod()) { return false; @@ -273,6 +238,11 @@ inline const char* ArtMethod::GetDeclaringClassDescriptor() { return dex_file->GetMethodDeclaringClassDescriptor(dex_file->GetMethodId(dex_method_idx)); } +inline const char* ArtMethod::GetShorty() { + uint32_t unused_length; + return GetShorty(&unused_length); +} + inline const char* ArtMethod::GetShorty(uint32_t* out_length) { DCHECK(!IsProxyMethod()); const DexFile* dex_file = GetDexFile(); diff --git a/runtime/art_method.cc b/runtime/art_method.cc index 76fdd43992..a6ee7eb769 100644 --- a/runtime/art_method.cc +++ b/runtime/art_method.cc @@ -56,6 +56,10 @@ extern "C" void art_quick_invoke_stub(ArtMethod*, uint32_t*, uint32_t, Thread*, extern "C" void art_quick_invoke_static_stub(ArtMethod*, uint32_t*, uint32_t, Thread*, JValue*, const char*); +// Enforce that we he have the right index for runtime methods. +static_assert(ArtMethod::kRuntimeMethodDexMethodIndex == DexFile::kDexNoIndex, + "Wrong runtime-method dex method index"); + ArtMethod* ArtMethod::GetNonObsoleteMethod() { DCHECK_EQ(kRuntimePointerSize, Runtime::Current()->GetClassLinker()->GetImagePointerSize()); if (LIKELY(!IsObsolete())) { @@ -807,4 +811,35 @@ std::string ArtMethod::JniLongName() { return long_name; } +// AssertSharedHeld doesn't work in GetAccessFlags, so use a NO_THREAD_SAFETY_ANALYSIS helper. +// TODO: Figure out why ASSERT_SHARED_CAPABILITY doesn't work. +template <ReadBarrierOption kReadBarrierOption> +ALWAYS_INLINE static inline void DoGetAccessFlagsHelper(ArtMethod* method) + NO_THREAD_SAFETY_ANALYSIS { + CHECK(method->IsRuntimeMethod() || + method->GetDeclaringClass<kReadBarrierOption>()->IsIdxLoaded() || + method->GetDeclaringClass<kReadBarrierOption>()->IsErroneous()); +} + +template <ReadBarrierOption kReadBarrierOption> void ArtMethod::GetAccessFlagsDCheck() { + if (kCheckDeclaringClassState) { + Thread* self = Thread::Current(); + if (!Locks::mutator_lock_->IsSharedHeld(self)) { + if (self->IsThreadSuspensionAllowable()) { + ScopedObjectAccess soa(self); + CHECK(IsRuntimeMethod() || + GetDeclaringClass<kReadBarrierOption>()->IsIdxLoaded() || + GetDeclaringClass<kReadBarrierOption>()->IsErroneous()); + } + } else { + // We cannot use SOA in this case. We might be holding the lock, but may not be in the + // runnable state (e.g., during GC). + Locks::mutator_lock_->AssertSharedHeld(self); + DoGetAccessFlagsHelper<kReadBarrierOption>(this); + } + } +} +template void ArtMethod::GetAccessFlagsDCheck<ReadBarrierOption::kWithReadBarrier>(); +template void ArtMethod::GetAccessFlagsDCheck<ReadBarrierOption::kWithoutReadBarrier>(); + } // namespace art diff --git a/runtime/art_method.h b/runtime/art_method.h index b01b344bda..856bfd23e5 100644 --- a/runtime/art_method.h +++ b/runtime/art_method.h @@ -55,6 +55,10 @@ class ArtMethod FINAL { public: static constexpr bool kCheckDeclaringClassState = kIsDebugBuild; + // The runtime dex_method_index is kDexNoIndex. To lower dependencies, we use this + // constexpr, and ensure that the value is correct in art_method.cc. + static constexpr uint32_t kRuntimeMethodDexMethodIndex = 0xFFFFFFFF; + ArtMethod() : access_flags_(0), dex_code_item_offset_(0), dex_method_index_(0), method_index_(0), hotness_count_(0) { } @@ -90,7 +94,12 @@ class ArtMethod FINAL { // Note: GetAccessFlags acquires the mutator lock in debug mode to check that it is not called for // a proxy method. template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier> - ALWAYS_INLINE uint32_t GetAccessFlags(); + uint32_t GetAccessFlags() { + if (kCheckDeclaringClassState) { + GetAccessFlagsDCheck<kReadBarrierOption>(); + } + return access_flags_.load(std::memory_order_relaxed); + } // This version should only be called when it's certain there is no // concurrency so there is no need to guarantee atomicity. For example, @@ -504,7 +513,9 @@ class ArtMethod FINAL { // Is this a CalleSaveMethod or ResolutionMethod and therefore doesn't adhere to normal // conventions for a method of managed code. Returns false for Proxy methods. - ALWAYS_INLINE bool IsRuntimeMethod(); + ALWAYS_INLINE bool IsRuntimeMethod() { + return dex_method_index_ == kRuntimeMethodDexMethodIndex;; + } // Is this a hand crafted method used for something like describing callee saves? bool IsCalleeSaveMethod() REQUIRES_SHARED(Locks::mutator_lock_); @@ -532,10 +543,7 @@ class ArtMethod FINAL { const char* GetDeclaringClassDescriptor() REQUIRES_SHARED(Locks::mutator_lock_); - const char* GetShorty() REQUIRES_SHARED(Locks::mutator_lock_) { - uint32_t unused_length; - return GetShorty(&unused_length); - } + ALWAYS_INLINE const char* GetShorty() REQUIRES_SHARED(Locks::mutator_lock_); const char* GetShorty(uint32_t* out_length) REQUIRES_SHARED(Locks::mutator_lock_); @@ -743,6 +751,8 @@ class ArtMethod FINAL { } } + template <ReadBarrierOption kReadBarrierOption> void GetAccessFlagsDCheck(); + DISALLOW_COPY_AND_ASSIGN(ArtMethod); // Need to use CopyFrom to deal with 32 vs 64 bits. }; diff --git a/runtime/base/allocator.cc b/runtime/base/allocator.cc index f1d0a5fbff..2a2790c7d9 100644 --- a/runtime/base/allocator.cc +++ b/runtime/base/allocator.cc @@ -21,7 +21,6 @@ #include "atomic.h" #include "base/logging.h" -#include "thread-inl.h" namespace art { diff --git a/runtime/class_linker-inl.h b/runtime/class_linker-inl.h index 9ddc6cf0ae..c9fb3ed3ad 100644 --- a/runtime/class_linker-inl.h +++ b/runtime/class_linker-inl.h @@ -33,10 +33,6 @@ namespace art { -inline mirror::Class* ClassLinker::FindSystemClass(Thread* self, const char* descriptor) { - return FindClass(self, descriptor, ScopedNullHandle<mirror::ClassLoader>()); -} - inline mirror::Class* ClassLinker::FindArrayClass(Thread* self, ObjPtr<mirror::Class>* element_class) { for (size_t i = 0; i < kFindArrayCacheSize; ++i) { @@ -65,19 +61,6 @@ inline mirror::Class* ClassLinker::FindArrayClass(Thread* self, return array_class.Ptr(); } -inline mirror::String* ClassLinker::ResolveString(dex::StringIndex string_idx, - ArtMethod* referrer) { - Thread::PoisonObjectPointersIfDebug(); - ObjPtr<mirror::String> string = referrer->GetDexCache()->GetResolvedString(string_idx); - if (UNLIKELY(string == nullptr)) { - StackHandleScope<1> hs(Thread::Current()); - Handle<mirror::DexCache> dex_cache(hs.NewHandle(referrer->GetDexCache())); - const DexFile& dex_file = *dex_cache->GetDexFile(); - string = ResolveString(dex_file, string_idx, dex_cache); - } - return string.Ptr(); -} - inline ObjPtr<mirror::Class> ClassLinker::LookupResolvedType( dex::TypeIndex type_idx, ObjPtr<mirror::DexCache> dex_cache, @@ -191,36 +174,6 @@ inline ArtField* ClassLinker::ResolveField(uint32_t field_idx, return resolved_field; } -inline mirror::Object* ClassLinker::AllocObject(Thread* self) { - return GetClassRoot(kJavaLangObject)->Alloc<true, false>( - self, - Runtime::Current()->GetHeap()->GetCurrentAllocator()).Ptr(); -} - -template <class T> -inline mirror::ObjectArray<T>* ClassLinker::AllocObjectArray(Thread* self, size_t length) { - return mirror::ObjectArray<T>::Alloc(self, GetClassRoot(kObjectArrayClass), length); -} - -inline mirror::ObjectArray<mirror::Class>* ClassLinker::AllocClassArray(Thread* self, - size_t length) { - return mirror::ObjectArray<mirror::Class>::Alloc(self, GetClassRoot(kClassArrayClass), length); -} - -inline mirror::ObjectArray<mirror::String>* ClassLinker::AllocStringArray(Thread* self, - size_t length) { - return mirror::ObjectArray<mirror::String>::Alloc(self, - GetClassRoot(kJavaLangStringArrayClass), - length); -} - -inline mirror::IfTable* ClassLinker::AllocIfTable(Thread* self, size_t ifcount) { - return down_cast<mirror::IfTable*>( - mirror::IfTable::Alloc(self, - GetClassRoot(kObjectArrayClass), - ifcount * mirror::IfTable::kMax)); -} - inline mirror::Class* ClassLinker::GetClassRoot(ClassRoot class_root) { DCHECK(!class_roots_.IsNull()); mirror::ObjectArray<mirror::Class>* class_roots = class_roots_.Read(); diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc index 1d0684202c..bee7d0bbdf 100644 --- a/runtime/class_linker.cc +++ b/runtime/class_linker.cc @@ -8983,6 +8983,13 @@ mirror::Class* ClassLinker::GetHoldingClassOfCopiedMethod(ArtMethod* method) { return visitor.holder_.Ptr(); } +mirror::IfTable* ClassLinker::AllocIfTable(Thread* self, size_t ifcount) { + return down_cast<mirror::IfTable*>( + mirror::IfTable::Alloc(self, + GetClassRoot(kObjectArrayClass), + ifcount * mirror::IfTable::kMax)); +} + // Instantiate ResolveMethod. template ArtMethod* ClassLinker::ResolveMethod<ClassLinker::kForceICCECheck>( const DexFile& dex_file, diff --git a/runtime/class_linker.h b/runtime/class_linker.h index a26e63b49e..1c280a4662 100644 --- a/runtime/class_linker.h +++ b/runtime/class_linker.h @@ -185,7 +185,9 @@ class ClassLinker { // boot_class_path_. mirror::Class* FindSystemClass(Thread* self, const char* descriptor) REQUIRES_SHARED(Locks::mutator_lock_) - REQUIRES(!Locks::dex_lock_); + REQUIRES(!Locks::dex_lock_) { + return FindClass(self, descriptor, ScopedNullHandle<mirror::ClassLoader>()); + } // Finds the array class given for the element class. mirror::Class* FindArrayClass(Thread* self, ObjPtr<mirror::Class>* element_class) @@ -231,12 +233,6 @@ class ClassLinker { REQUIRES_SHARED(Locks::mutator_lock_); // Resolve a String with the given index from the DexFile, storing the - // result in the DexCache. The referrer is used to identify the - // target DexCache and ClassLoader to use for resolution. - mirror::String* ResolveString(dex::StringIndex string_idx, ArtMethod* referrer) - REQUIRES_SHARED(Locks::mutator_lock_); - - // Resolve a String with the given index from the DexFile, storing the // result in the DexCache. mirror::String* ResolveString(const DexFile& dex_file, dex::StringIndex string_idx, @@ -436,25 +432,6 @@ class ClassLinker { REQUIRES(!Locks::dex_lock_) REQUIRES_SHARED(Locks::mutator_lock_); - // Allocate an instance of a java.lang.Object. - mirror::Object* AllocObject(Thread* self) - REQUIRES_SHARED(Locks::mutator_lock_) - REQUIRES(!Roles::uninterruptible_); - - // TODO: replace this with multiple methods that allocate the correct managed type. - template <class T> - mirror::ObjectArray<T>* AllocObjectArray(Thread* self, size_t length) - REQUIRES_SHARED(Locks::mutator_lock_) - REQUIRES(!Roles::uninterruptible_); - - mirror::ObjectArray<mirror::Class>* AllocClassArray(Thread* self, size_t length) - REQUIRES_SHARED(Locks::mutator_lock_) - REQUIRES(!Roles::uninterruptible_); - - mirror::ObjectArray<mirror::String>* AllocStringArray(Thread* self, size_t length) - REQUIRES_SHARED(Locks::mutator_lock_) - REQUIRES(!Roles::uninterruptible_); - LengthPrefixedArray<ArtField>* AllocArtFieldArray(Thread* self, LinearAlloc* allocator, size_t length); diff --git a/runtime/entrypoints/entrypoint_utils-inl.h b/runtime/entrypoints/entrypoint_utils-inl.h index ba8cec3a52..caf2e5dfee 100644 --- a/runtime/entrypoints/entrypoint_utils-inl.h +++ b/runtime/entrypoints/entrypoint_utils-inl.h @@ -779,9 +779,32 @@ inline mirror::Class* ResolveVerifyAndClinit(dex::TypeIndex type_idx, return h_class.Get(); } +static inline mirror::String* ResolveString(ClassLinker* class_linker, + dex::StringIndex string_idx, + ArtMethod* referrer) + REQUIRES_SHARED(Locks::mutator_lock_) { + Thread::PoisonObjectPointersIfDebug(); + ObjPtr<mirror::String> string = referrer->GetDexCache()->GetResolvedString(string_idx); + if (UNLIKELY(string == nullptr)) { + StackHandleScope<1> hs(Thread::Current()); + Handle<mirror::DexCache> dex_cache(hs.NewHandle(referrer->GetDexCache())); + const DexFile& dex_file = *dex_cache->GetDexFile(); + string = class_linker->ResolveString(dex_file, string_idx, dex_cache); + } + return string.Ptr(); +} + inline mirror::String* ResolveStringFromCode(ArtMethod* referrer, dex::StringIndex string_idx) { - ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); - return class_linker->ResolveString(string_idx, referrer); + Thread::PoisonObjectPointersIfDebug(); + ObjPtr<mirror::String> string = referrer->GetDexCache()->GetResolvedString(string_idx); + if (UNLIKELY(string == nullptr)) { + StackHandleScope<1> hs(Thread::Current()); + Handle<mirror::DexCache> dex_cache(hs.NewHandle(referrer->GetDexCache())); + const DexFile& dex_file = *dex_cache->GetDexFile(); + ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); + string = class_linker->ResolveString(dex_file, string_idx, dex_cache); + } + return string.Ptr(); } inline void UnlockJniSynchronizedMethod(jobject locked, Thread* self) { diff --git a/runtime/entrypoints/quick/quick_deoptimization_entrypoints.cc b/runtime/entrypoints/quick/quick_deoptimization_entrypoints.cc index 343343fc3f..3820d854f9 100644 --- a/runtime/entrypoints/quick/quick_deoptimization_entrypoints.cc +++ b/runtime/entrypoints/quick/quick_deoptimization_entrypoints.cc @@ -14,22 +14,18 @@ * limitations under the License. */ -#include "art_method-inl.h" #include "base/logging.h" +#include "base/mutex.h" #include "callee_save_frame.h" -#include "dex_file-inl.h" #include "interpreter/interpreter.h" -#include "mirror/class-inl.h" -#include "mirror/object_array-inl.h" -#include "mirror/object-inl.h" +#include "obj_ptr-inl.h" // TODO: Find the other include that isn't complete, and clean this up. #include "quick_exception_handler.h" #include "thread.h" -#include "verifier/method_verifier.h" namespace art { NO_RETURN static void artDeoptimizeImpl(Thread* self, bool single_frame) - REQUIRES_SHARED(Locks::mutator_lock_) { + REQUIRES_SHARED(Locks::mutator_lock_) { if (VLOG_IS_ON(deopt)) { if (single_frame) { // Deopt logging will be in DeoptimizeSingleFrame. It is there to take advantage of the diff --git a/runtime/entrypoints/quick/quick_instrumentation_entrypoints.cc b/runtime/entrypoints/quick/quick_instrumentation_entrypoints.cc index aa547bf04e..81560ccbaf 100644 --- a/runtime/entrypoints/quick/quick_instrumentation_entrypoints.cc +++ b/runtime/entrypoints/quick/quick_instrumentation_entrypoints.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "art_method-inl.h" +#include "art_method.h" #include "base/enums.h" #include "callee_save_frame.h" #include "entrypoints/runtime_asm_entrypoints.h" diff --git a/runtime/gc/accounting/mod_union_table.cc b/runtime/gc/accounting/mod_union_table.cc index a5bb91a71e..34e30c177f 100644 --- a/runtime/gc/accounting/mod_union_table.cc +++ b/runtime/gc/accounting/mod_union_table.cc @@ -26,6 +26,7 @@ #include "gc/space/image_space.h" #include "gc/space/space.h" #include "mirror/object-inl.h" +#include "mirror/object-refvisitor-inl.h" #include "space_bitmap-inl.h" #include "thread-inl.h" diff --git a/runtime/gc/accounting/remembered_set.cc b/runtime/gc/accounting/remembered_set.cc index 7b1e2b83c3..f2fe58aa83 100644 --- a/runtime/gc/accounting/remembered_set.cc +++ b/runtime/gc/accounting/remembered_set.cc @@ -26,8 +26,9 @@ #include "gc/collector/semi_space.h" #include "gc/heap.h" #include "gc/space/space.h" -#include "mirror/object-inl.h" #include "mirror/class-inl.h" +#include "mirror/object-inl.h" +#include "mirror/object-refvisitor-inl.h" #include "mirror/object_array-inl.h" #include "space_bitmap-inl.h" #include "thread.h" diff --git a/runtime/gc/collector/concurrent_copying.cc b/runtime/gc/collector/concurrent_copying.cc index 792c191017..46c9c0eeaa 100644 --- a/runtime/gc/collector/concurrent_copying.cc +++ b/runtime/gc/collector/concurrent_copying.cc @@ -33,6 +33,7 @@ #include "intern_table.h" #include "mirror/class-inl.h" #include "mirror/object-inl.h" +#include "mirror/object-refvisitor-inl.h" #include "scoped_thread_state_change-inl.h" #include "thread-inl.h" #include "thread_list.h" diff --git a/runtime/gc/collector/mark_compact.cc b/runtime/gc/collector/mark_compact.cc index c61f69dad3..cab293f23c 100644 --- a/runtime/gc/collector/mark_compact.cc +++ b/runtime/gc/collector/mark_compact.cc @@ -29,6 +29,7 @@ #include "gc/space/space-inl.h" #include "mirror/class-inl.h" #include "mirror/object-inl.h" +#include "mirror/object-refvisitor-inl.h" #include "runtime.h" #include "stack.h" #include "thread-inl.h" diff --git a/runtime/gc/collector/mark_sweep-inl.h b/runtime/gc/collector/mark_sweep-inl.h index e72277ffb2..e4993ce718 100644 --- a/runtime/gc/collector/mark_sweep-inl.h +++ b/runtime/gc/collector/mark_sweep-inl.h @@ -21,6 +21,7 @@ #include "gc/heap.h" #include "mirror/class-inl.h" +#include "mirror/object-refvisitor-inl.h" #include "mirror/object_array-inl.h" #include "mirror/reference.h" diff --git a/runtime/gc/collector/semi_space.cc b/runtime/gc/collector/semi_space.cc index 67e7383a4f..41e605104c 100644 --- a/runtime/gc/collector/semi_space.cc +++ b/runtime/gc/collector/semi_space.cc @@ -44,6 +44,7 @@ #include "monitor.h" #include "mirror/reference-inl.h" #include "mirror/object-inl.h" +#include "mirror/object-refvisitor-inl.h" #include "runtime.h" #include "thread-inl.h" #include "thread_list.h" diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc index 28dd62717a..e08784dc63 100644 --- a/runtime/gc/heap.cc +++ b/runtime/gc/heap.cc @@ -70,6 +70,7 @@ #include "obj_ptr-inl.h" #include "mirror/class-inl.h" #include "mirror/object-inl.h" +#include "mirror/object-refvisitor-inl.h" #include "mirror/object_array-inl.h" #include "mirror/reference-inl.h" #include "os.h" diff --git a/runtime/gc/space/image_space.cc b/runtime/gc/space/image_space.cc index 662efe2c8d..ac7293d545 100644 --- a/runtime/gc/space/image_space.cc +++ b/runtime/gc/space/image_space.cc @@ -25,7 +25,7 @@ #include "android-base/stringprintf.h" #include "android-base/strings.h" -#include "art_method.h" +#include "art_method-inl.h" #include "base/enums.h" #include "base/macros.h" #include "base/stl_util.h" @@ -38,6 +38,7 @@ #include "image_space_fs.h" #include "mirror/class-inl.h" #include "mirror/object-inl.h" +#include "mirror/object-refvisitor-inl.h" #include "oat_file.h" #include "os.h" #include "space-inl.h" diff --git a/runtime/hprof/hprof.cc b/runtime/hprof/hprof.cc index 495fec7a48..4f390fd30a 100644 --- a/runtime/hprof/hprof.cc +++ b/runtime/hprof/hprof.cc @@ -40,6 +40,7 @@ #include "android-base/stringprintf.h" #include "art_field-inl.h" +#include "art_method-inl.h" #include "base/logging.h" #include "base/time_utils.h" #include "base/unix_file/fd_file.h" @@ -58,7 +59,7 @@ #include "jdwp/jdwp_priv.h" #include "mirror/class.h" #include "mirror/class-inl.h" -#include "mirror/object-inl.h" +#include "mirror/object-refvisitor-inl.h" #include "os.h" #include "safe_map.h" #include "scoped_thread_state_change-inl.h" diff --git a/runtime/image.cc b/runtime/image.cc index b153ea0e02..b2486a1209 100644 --- a/runtime/image.cc +++ b/runtime/image.cc @@ -17,6 +17,7 @@ #include "image.h" #include "base/bit_utils.h" +#include "base/length_prefixed_array.h" #include "mirror/object_array.h" #include "mirror/object_array-inl.h" #include "mirror/object-inl.h" diff --git a/runtime/interpreter/interpreter_common.cc b/runtime/interpreter/interpreter_common.cc index 8978bfd5af..326f5c96c0 100644 --- a/runtime/interpreter/interpreter_common.cc +++ b/runtime/interpreter/interpreter_common.cc @@ -28,7 +28,7 @@ #include "mirror/array-inl.h" #include "mirror/class.h" #include "mirror/emulated_stack_frame.h" -#include "mirror/method_handle_impl.h" +#include "mirror/method_handle_impl-inl.h" #include "reflection.h" #include "reflection-inl.h" #include "stack.h" diff --git a/runtime/interpreter/unstarted_runtime_test.cc b/runtime/interpreter/unstarted_runtime_test.cc index 56e261cfc8..c314f3c35e 100644 --- a/runtime/interpreter/unstarted_runtime_test.cc +++ b/runtime/interpreter/unstarted_runtime_test.cc @@ -1341,7 +1341,8 @@ TEST_F(UnstartedRuntimeTest, ConstructorNewInstance0) { ASSERT_TRUE(cons != nullptr); Handle<mirror::ObjectArray<mirror::Object>> args = hs.NewHandle( - class_linker->AllocObjectArray<mirror::Object>(self, 1)); + mirror::ObjectArray<mirror::Object>::Alloc( + self, class_linker_->GetClassRoot(ClassLinker::ClassRoot::kObjectArrayClass), 1)); ASSERT_TRUE(args != nullptr); args->Set(0, input.Get()); diff --git a/runtime/java_vm_ext.cc b/runtime/java_vm_ext.cc index c8dc2f2d20..6d3118e4aa 100644 --- a/runtime/java_vm_ext.cc +++ b/runtime/java_vm_ext.cc @@ -20,7 +20,7 @@ #include "android-base/stringprintf.h" -#include "art_method.h" +#include "art_method-inl.h" #include "base/dumpable.h" #include "base/mutex.h" #include "base/stl_util.h" diff --git a/runtime/jit/profile_compilation_info.cc b/runtime/jit/profile_compilation_info.cc index 2d1601e883..52649c7075 100644 --- a/runtime/jit/profile_compilation_info.cc +++ b/runtime/jit/profile_compilation_info.cc @@ -24,7 +24,6 @@ #include <sys/stat.h> #include <sys/uio.h> -#include "art_method-inl.h" #include "base/mutex.h" #include "base/scoped_flock.h" #include "base/stl_util.h" @@ -33,6 +32,7 @@ #include "jit/profiling_info.h" #include "os.h" #include "safe_map.h" +#include "utils.h" namespace art { diff --git a/runtime/method_handles.cc b/runtime/method_handles.cc index b6f8a173c0..54d45b1e79 100644 --- a/runtime/method_handles.cc +++ b/runtime/method_handles.cc @@ -22,7 +22,7 @@ #include "jvalue.h" #include "jvalue-inl.h" #include "mirror/emulated_stack_frame.h" -#include "mirror/method_handle_impl.h" +#include "mirror/method_handle_impl-inl.h" #include "mirror/method_type.h" #include "reflection.h" #include "reflection-inl.h" diff --git a/runtime/mirror/array-inl.h b/runtime/mirror/array-inl.h index 04c80c5cc0..be03f044e6 100644 --- a/runtime/mirror/array-inl.h +++ b/runtime/mirror/array-inl.h @@ -24,7 +24,7 @@ #include "base/bit_utils.h" #include "base/casts.h" #include "base/logging.h" -#include "class-inl.h" +#include "class.h" #include "gc/heap-inl.h" #include "obj_ptr-inl.h" #include "thread.h" diff --git a/runtime/mirror/class-inl.h b/runtime/mirror/class-inl.h index 9124a3ad84..d78ed7f7e9 100644 --- a/runtime/mirror/class-inl.h +++ b/runtime/mirror/class-inl.h @@ -21,7 +21,6 @@ #include "art_field-inl.h" #include "art_method.h" -#include "art_method-inl.h" #include "base/array_slice.h" #include "base/length_prefixed_array.h" #include "class_loader.h" @@ -29,7 +28,6 @@ #include "dex_file.h" #include "gc/heap-inl.h" #include "iftable.h" -#include "class_ext-inl.h" #include "object_array-inl.h" #include "read_barrier-inl.h" #include "reference-inl.h" @@ -343,6 +341,21 @@ inline bool Class::Implements(ObjPtr<Class> klass) { return false; } +template<VerifyObjectFlags kVerifyFlags, ReadBarrierOption kReadBarrierOption> +inline bool Class::IsVariableSize() { + // Classes, arrays, and strings vary in size, and so the object_size_ field cannot + // be used to Get their instance size + return IsClassClass<kVerifyFlags, kReadBarrierOption>() || + IsArrayClass<kVerifyFlags, kReadBarrierOption>() || + IsStringClass(); +} + +inline void Class::SetObjectSize(uint32_t new_object_size) { + DCHECK(!IsVariableSize()); + // Not called within a transaction. + return SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, object_size_), new_object_size); +} + // Determine whether "this" is assignable from "src", where both of these // are array classes. // @@ -784,32 +797,6 @@ inline uint32_t Class::ComputeClassSize(bool has_embedded_vtable, return size; } -template <bool kVisitNativeRoots, - VerifyObjectFlags kVerifyFlags, - ReadBarrierOption kReadBarrierOption, - typename Visitor> -inline void Class::VisitReferences(ObjPtr<Class> klass, const Visitor& visitor) { - VisitInstanceFieldsReferences<kVerifyFlags, kReadBarrierOption>(klass.Ptr(), visitor); - // Right after a class is allocated, but not yet loaded - // (kStatusNotReady, see ClassLinker::LoadClass()), GC may find it - // and scan it. IsTemp() may call Class::GetAccessFlags() but may - // fail in the DCHECK in Class::GetAccessFlags() because the class - // status is kStatusNotReady. To avoid it, rely on IsResolved() - // only. This is fine because a temp class never goes into the - // kStatusResolved state. - if (IsResolved<kVerifyFlags>()) { - // Temp classes don't ever populate imt/vtable or static fields and they are not even - // allocated with the right size for those. Also, unresolved classes don't have fields - // linked yet. - VisitStaticFieldsReferences<kVerifyFlags, kReadBarrierOption>(this, visitor); - } - if (kVisitNativeRoots) { - // Since this class is reachable, we must also visit the associated roots when we scan it. - VisitNativeRoots<kReadBarrierOption>( - visitor, Runtime::Current()->GetClassLinker()->GetImagePointerSize()); - } -} - template<ReadBarrierOption kReadBarrierOption> inline bool Class::IsReferenceClass() const { return this == Reference::GetJavaLangRefReference<kReadBarrierOption>(); @@ -942,31 +929,6 @@ inline uint32_t Class::NumDirectInterfaces() { } } -template<ReadBarrierOption kReadBarrierOption, class Visitor> -void Class::VisitNativeRoots(Visitor& visitor, PointerSize pointer_size) { - for (ArtField& field : GetSFieldsUnchecked()) { - // Visit roots first in case the declaring class gets moved. - field.VisitRoots(visitor); - if (kIsDebugBuild && IsResolved()) { - CHECK_EQ(field.GetDeclaringClass<kReadBarrierOption>(), this) << GetStatus(); - } - } - for (ArtField& field : GetIFieldsUnchecked()) { - // Visit roots first in case the declaring class gets moved. - field.VisitRoots(visitor); - if (kIsDebugBuild && IsResolved()) { - CHECK_EQ(field.GetDeclaringClass<kReadBarrierOption>(), this) << GetStatus(); - } - } - for (ArtMethod& method : GetMethods(pointer_size)) { - method.VisitRoots<kReadBarrierOption>(visitor, pointer_size); - } - ObjPtr<ClassExt> ext(GetExtData<kDefaultVerifyFlags, kReadBarrierOption>()); - if (!ext.IsNull()) { - ext->VisitNativeRoots<kReadBarrierOption, Visitor>(visitor, pointer_size); - } -} - inline IterationRange<StrideIterator<ArtMethod>> Class::GetDirectMethods(PointerSize pointer_size) { CheckPointerSize(pointer_size); return GetDirectMethodsSliceUnchecked(pointer_size).AsRange(); @@ -1036,6 +998,12 @@ inline bool Class::IsArrayClass() { return GetComponentType<kVerifyFlags, kReadBarrierOption>() != nullptr; } +template<VerifyObjectFlags kVerifyFlags, ReadBarrierOption kReadBarrierOption> +inline bool Class::IsObjectArrayClass() { + ObjPtr<Class> const component_type = GetComponentType<kVerifyFlags, kReadBarrierOption>(); + return component_type != nullptr && !component_type->IsPrimitive(); +} + inline bool Class::IsAssignableFrom(ObjPtr<Class> src) { DCHECK(src != nullptr); if (this == src) { diff --git a/runtime/mirror/class-refvisitor-inl.h b/runtime/mirror/class-refvisitor-inl.h new file mode 100644 index 0000000000..ffc4af5712 --- /dev/null +++ b/runtime/mirror/class-refvisitor-inl.h @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ART_RUNTIME_MIRROR_CLASS_REFVISITOR_INL_H_ +#define ART_RUNTIME_MIRROR_CLASS_REFVISITOR_INL_H_ + +#include "class-inl.h" + +#include "class_ext-inl.h" + +namespace art { +namespace mirror { + +template <bool kVisitNativeRoots, + VerifyObjectFlags kVerifyFlags, + ReadBarrierOption kReadBarrierOption, + typename Visitor> +inline void Class::VisitReferences(ObjPtr<Class> klass, const Visitor& visitor) { + VisitInstanceFieldsReferences<kVerifyFlags, kReadBarrierOption>(klass.Ptr(), visitor); + // Right after a class is allocated, but not yet loaded + // (kStatusNotReady, see ClassLinker::LoadClass()), GC may find it + // and scan it. IsTemp() may call Class::GetAccessFlags() but may + // fail in the DCHECK in Class::GetAccessFlags() because the class + // status is kStatusNotReady. To avoid it, rely on IsResolved() + // only. This is fine because a temp class never goes into the + // kStatusResolved state. + if (IsResolved<kVerifyFlags>()) { + // Temp classes don't ever populate imt/vtable or static fields and they are not even + // allocated with the right size for those. Also, unresolved classes don't have fields + // linked yet. + VisitStaticFieldsReferences<kVerifyFlags, kReadBarrierOption>(this, visitor); + } + if (kVisitNativeRoots) { + // Since this class is reachable, we must also visit the associated roots when we scan it. + VisitNativeRoots<kReadBarrierOption>( + visitor, Runtime::Current()->GetClassLinker()->GetImagePointerSize()); + } +} + +template<ReadBarrierOption kReadBarrierOption, class Visitor> +void Class::VisitNativeRoots(Visitor& visitor, PointerSize pointer_size) { + for (ArtField& field : GetSFieldsUnchecked()) { + // Visit roots first in case the declaring class gets moved. + field.VisitRoots(visitor); + if (kIsDebugBuild && IsResolved()) { + CHECK_EQ(field.GetDeclaringClass<kReadBarrierOption>(), this) << GetStatus(); + } + } + for (ArtField& field : GetIFieldsUnchecked()) { + // Visit roots first in case the declaring class gets moved. + field.VisitRoots(visitor); + if (kIsDebugBuild && IsResolved()) { + CHECK_EQ(field.GetDeclaringClass<kReadBarrierOption>(), this) << GetStatus(); + } + } + for (ArtMethod& method : GetMethods(pointer_size)) { + method.VisitRoots<kReadBarrierOption>(visitor, pointer_size); + } + ObjPtr<ClassExt> ext(GetExtData<kDefaultVerifyFlags, kReadBarrierOption>()); + if (!ext.IsNull()) { + ext->VisitNativeRoots<kReadBarrierOption, Visitor>(visitor, pointer_size); + } +} + +} // namespace mirror +} // namespace art + +#endif // ART_RUNTIME_MIRROR_CLASS_REFVISITOR_INL_H_ diff --git a/runtime/mirror/class.cc b/runtime/mirror/class.cc index 26af488bd2..06ee3d36fe 100644 --- a/runtime/mirror/class.cc +++ b/runtime/mirror/class.cc @@ -32,6 +32,7 @@ #include "method.h" #include "object_array-inl.h" #include "object-inl.h" +#include "object-refvisitor-inl.h" #include "object_lock.h" #include "runtime.h" #include "thread.h" diff --git a/runtime/mirror/class.h b/runtime/mirror/class.h index 27aecd5150..dfb2788c51 100644 --- a/runtime/mirror/class.h +++ b/runtime/mirror/class.h @@ -530,10 +530,7 @@ class MANAGED Class FINAL : public Object { template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, ReadBarrierOption kReadBarrierOption = kWithReadBarrier> - bool IsObjectArrayClass() REQUIRES_SHARED(Locks::mutator_lock_) { - ObjPtr<Class> const component_type = GetComponentType<kVerifyFlags, kReadBarrierOption>(); - return component_type != nullptr && !component_type->IsPrimitive(); - } + ALWAYS_INLINE bool IsObjectArrayClass() REQUIRES_SHARED(Locks::mutator_lock_); template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> bool IsIntArrayClass() REQUIRES_SHARED(Locks::mutator_lock_) { @@ -561,12 +558,7 @@ class MANAGED Class FINAL : public Object { template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, ReadBarrierOption kReadBarrierOption = kWithReadBarrier> - bool IsVariableSize() REQUIRES_SHARED(Locks::mutator_lock_) { - // Classes, arrays, and strings vary in size, and so the object_size_ field cannot - // be used to Get their instance size - return IsClassClass<kVerifyFlags, kReadBarrierOption>() || - IsArrayClass<kVerifyFlags, kReadBarrierOption>() || IsStringClass(); - } + ALWAYS_INLINE bool IsVariableSize() REQUIRES_SHARED(Locks::mutator_lock_); template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, ReadBarrierOption kReadBarrierOption = kWithReadBarrier> @@ -614,11 +606,7 @@ class MANAGED Class FINAL : public Object { return OFFSET_OF_OBJECT_MEMBER(Class, object_size_alloc_fast_path_); } - void SetObjectSize(uint32_t new_object_size) REQUIRES_SHARED(Locks::mutator_lock_) { - DCHECK(!IsVariableSize()); - // Not called within a transaction. - return SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, object_size_), new_object_size); - } + ALWAYS_INLINE void SetObjectSize(uint32_t new_object_size) REQUIRES_SHARED(Locks::mutator_lock_); void SetObjectSizeAllocFastPath(uint32_t new_object_size) REQUIRES_SHARED(Locks::mutator_lock_); diff --git a/runtime/mirror/dex_cache-inl.h b/runtime/mirror/dex_cache-inl.h index 5d3af5071a..37a67e80cf 100644 --- a/runtime/mirror/dex_cache-inl.h +++ b/runtime/mirror/dex_cache-inl.h @@ -20,7 +20,7 @@ #include "dex_cache.h" #include "art_field-inl.h" -#include "art_method-inl.h" +#include "art_method.h" #include "base/casts.h" #include "base/enums.h" #include "base/logging.h" diff --git a/runtime/mirror/dex_cache_test.cc b/runtime/mirror/dex_cache_test.cc index 71a47f66a0..a110ed7f6b 100644 --- a/runtime/mirror/dex_cache_test.cc +++ b/runtime/mirror/dex_cache_test.cc @@ -18,6 +18,7 @@ #include <stdio.h> +#include "art_method-inl.h" #include "class_linker.h" #include "common_runtime_test.h" #include "linear_alloc.h" diff --git a/runtime/mirror/method_handle_impl-inl.h b/runtime/mirror/method_handle_impl-inl.h new file mode 100644 index 0000000000..0840d16c38 --- /dev/null +++ b/runtime/mirror/method_handle_impl-inl.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ART_RUNTIME_MIRROR_METHOD_HANDLE_IMPL_INL_H_ +#define ART_RUNTIME_MIRROR_METHOD_HANDLE_IMPL_INL_H_ + +#include "method_handle_impl.h" + +#include "art_method-inl.h" +#include "object-inl.h" + +namespace art { +namespace mirror { + +inline mirror::MethodType* MethodHandle::GetMethodType() { + return GetFieldObject<mirror::MethodType>(OFFSET_OF_OBJECT_MEMBER(MethodHandle, method_type_)); +} + +inline mirror::MethodType* MethodHandle::GetNominalType() { + return GetFieldObject<mirror::MethodType>(OFFSET_OF_OBJECT_MEMBER(MethodHandle, nominal_type_)); +} + +inline ObjPtr<mirror::Class> MethodHandle::GetTargetClass() { + Kind kind = GetHandleKind(); + return (kind <= kLastValidKind) ? + GetTargetMethod()->GetDeclaringClass() : GetTargetField()->GetDeclaringClass(); +} + +} // namespace mirror +} // namespace art + +#endif // ART_RUNTIME_MIRROR_METHOD_HANDLE_IMPL_INL_H_ diff --git a/runtime/mirror/method_handle_impl.cc b/runtime/mirror/method_handle_impl.cc index fa4d25a031..42b8473ef0 100644 --- a/runtime/mirror/method_handle_impl.cc +++ b/runtime/mirror/method_handle_impl.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "method_handle_impl.h" +#include "method_handle_impl-inl.h" #include "class-inl.h" #include "gc_root-inl.h" @@ -42,6 +42,10 @@ void MethodHandle::Initialize(uintptr_t art_field_or_method, GcRoot<mirror::Class> MethodHandleImpl::static_class_; +mirror::Class* MethodHandleImpl::StaticClass() { + return static_class_.Read(); +} + void MethodHandleImpl::SetClass(Class* klass) { CHECK(static_class_.IsNull()) << static_class_.Read() << " " << klass; CHECK(klass != nullptr); diff --git a/runtime/mirror/method_handle_impl.h b/runtime/mirror/method_handle_impl.h index 9938af8abf..c598fa3876 100644 --- a/runtime/mirror/method_handle_impl.h +++ b/runtime/mirror/method_handle_impl.h @@ -21,7 +21,7 @@ #include "art_method.h" #include "class.h" #include "gc_root.h" -#include "object-inl.h" +#include "object.h" #include "method_type.h" namespace art { @@ -65,13 +65,9 @@ class MANAGED MethodHandle : public Object { return static_cast<Kind>(handle_kind); } - mirror::MethodType* GetMethodType() REQUIRES_SHARED(Locks::mutator_lock_) { - return GetFieldObject<mirror::MethodType>(OFFSET_OF_OBJECT_MEMBER(MethodHandle, method_type_)); - } + ALWAYS_INLINE mirror::MethodType* GetMethodType() REQUIRES_SHARED(Locks::mutator_lock_); - mirror::MethodType* GetNominalType() REQUIRES_SHARED(Locks::mutator_lock_) { - return GetFieldObject<mirror::MethodType>(OFFSET_OF_OBJECT_MEMBER(MethodHandle, nominal_type_)); - } + ALWAYS_INLINE mirror::MethodType* GetNominalType() REQUIRES_SHARED(Locks::mutator_lock_); ArtField* GetTargetField() REQUIRES_SHARED(Locks::mutator_lock_) { return reinterpret_cast<ArtField*>( @@ -83,11 +79,7 @@ class MANAGED MethodHandle : public Object { GetField64(OFFSET_OF_OBJECT_MEMBER(MethodHandle, art_field_or_method_))); } - ObjPtr<mirror::Class> GetTargetClass() REQUIRES_SHARED(Locks::mutator_lock_) { - Kind kind = GetHandleKind(); - return (kind <= kLastValidKind) ? - GetTargetMethod()->GetDeclaringClass() : GetTargetField()->GetDeclaringClass(); - } + ALWAYS_INLINE ObjPtr<mirror::Class> GetTargetClass() REQUIRES_SHARED(Locks::mutator_lock_); static mirror::Class* StaticClass() REQUIRES_SHARED(Locks::mutator_lock_); @@ -132,9 +124,7 @@ class MANAGED MethodHandleImpl : public MethodHandle { Handle<MethodType> method_type) REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_); - static mirror::Class* StaticClass() REQUIRES_SHARED(Locks::mutator_lock_) { - return static_class_.Read(); - } + static mirror::Class* StaticClass() REQUIRES_SHARED(Locks::mutator_lock_); static void SetClass(Class* klass) REQUIRES_SHARED(Locks::mutator_lock_); static void ResetClass() REQUIRES_SHARED(Locks::mutator_lock_); diff --git a/runtime/mirror/method_handles_lookup.cc b/runtime/mirror/method_handles_lookup.cc index c758e54dd4..0c25fa8ba0 100644 --- a/runtime/mirror/method_handles_lookup.cc +++ b/runtime/mirror/method_handles_lookup.cc @@ -16,7 +16,7 @@ #include "method_handles_lookup.h" -#include "class.h" +#include "class-inl.h" #include "gc_root-inl.h" #include "object-inl.h" #include "handle_scope.h" diff --git a/runtime/mirror/method_type_test.cc b/runtime/mirror/method_type_test.cc index 41231ef617..a361772c58 100644 --- a/runtime/mirror/method_type_test.cc +++ b/runtime/mirror/method_type_test.cc @@ -20,7 +20,7 @@ #include <vector> #include "class-inl.h" -#include "class_linker.h" +#include "class_linker-inl.h" #include "class_loader.h" #include "common_runtime_test.h" #include "handle_scope-inl.h" diff --git a/runtime/mirror/object-inl.h b/runtime/mirror/object-inl.h index f83645e6e8..aaa590b20c 100644 --- a/runtime/mirror/object-inl.h +++ b/runtime/mirror/object-inl.h @@ -23,7 +23,7 @@ #include "art_method.h" #include "atomic.h" #include "array-inl.h" -#include "class.h" +#include "class-inl.h" #include "class_flags.h" #include "class_linker.h" #include "class_loader-inl.h" @@ -798,19 +798,6 @@ inline bool Object::CasFieldStrongSequentiallyConsistent32(MemberOffset field_of return atomic_addr->CompareExchangeStrongSequentiallyConsistent(old_value, new_value); } -template<VerifyObjectFlags kVerifyFlags, bool kIsVolatile> -inline int64_t Object::GetField64(MemberOffset field_offset) { - if (kVerifyFlags & kVerifyThis) { - VerifyObject(this); - } - return GetField<int64_t, kIsVolatile>(field_offset); -} - -template<VerifyObjectFlags kVerifyFlags> -inline int64_t Object::GetField64Volatile(MemberOffset field_offset) { - return GetField64<kVerifyFlags, true>(field_offset); -} - template<bool kTransactionActive, bool kCheckTransaction, VerifyObjectFlags kVerifyFlags, bool kIsVolatile> inline void Object::SetField64(MemberOffset field_offset, int64_t new_value) { @@ -1186,67 +1173,6 @@ inline mirror::DexCache* Object::AsDexCache() { return down_cast<mirror::DexCache*>(this); } -template <bool kVisitNativeRoots, - VerifyObjectFlags kVerifyFlags, - ReadBarrierOption kReadBarrierOption, - typename Visitor, - typename JavaLangRefVisitor> -inline void Object::VisitReferences(const Visitor& visitor, - const JavaLangRefVisitor& ref_visitor) { - ObjPtr<Class> klass = GetClass<kVerifyFlags, kReadBarrierOption>(); - visitor(this, ClassOffset(), false); - const uint32_t class_flags = klass->GetClassFlags<kVerifyNone>(); - if (LIKELY(class_flags == kClassFlagNormal)) { - DCHECK((!klass->IsVariableSize<kVerifyFlags, kReadBarrierOption>())); - VisitInstanceFieldsReferences<kVerifyFlags, kReadBarrierOption>(klass, visitor); - DCHECK((!klass->IsClassClass<kVerifyFlags, kReadBarrierOption>())); - DCHECK(!klass->IsStringClass()); - DCHECK(!klass->IsClassLoaderClass()); - DCHECK((!klass->IsArrayClass<kVerifyFlags, kReadBarrierOption>())); - } else { - if ((class_flags & kClassFlagNoReferenceFields) == 0) { - DCHECK(!klass->IsStringClass()); - if (class_flags == kClassFlagClass) { - DCHECK((klass->IsClassClass<kVerifyFlags, kReadBarrierOption>())); - ObjPtr<Class> as_klass = AsClass<kVerifyNone, kReadBarrierOption>(); - as_klass->VisitReferences<kVisitNativeRoots, kVerifyFlags, kReadBarrierOption>(klass, - visitor); - } else if (class_flags == kClassFlagObjectArray) { - DCHECK((klass->IsObjectArrayClass<kVerifyFlags, kReadBarrierOption>())); - AsObjectArray<mirror::Object, kVerifyNone, kReadBarrierOption>()->VisitReferences(visitor); - } else if ((class_flags & kClassFlagReference) != 0) { - VisitInstanceFieldsReferences<kVerifyFlags, kReadBarrierOption>(klass, visitor); - ref_visitor(klass, AsReference<kVerifyFlags, kReadBarrierOption>()); - } else if (class_flags == kClassFlagDexCache) { - mirror::DexCache* const dex_cache = AsDexCache<kVerifyFlags, kReadBarrierOption>(); - dex_cache->VisitReferences<kVisitNativeRoots, - kVerifyFlags, - kReadBarrierOption>(klass, visitor); - } else { - mirror::ClassLoader* const class_loader = AsClassLoader<kVerifyFlags, kReadBarrierOption>(); - class_loader->VisitReferences<kVisitNativeRoots, - kVerifyFlags, - kReadBarrierOption>(klass, visitor); - } - } else if (kIsDebugBuild) { - CHECK((!klass->IsClassClass<kVerifyFlags, kReadBarrierOption>())); - CHECK((!klass->IsObjectArrayClass<kVerifyFlags, kReadBarrierOption>())); - // String still has instance fields for reflection purposes but these don't exist in - // actual string instances. - if (!klass->IsStringClass()) { - size_t total_reference_instance_fields = 0; - ObjPtr<Class> super_class = klass; - do { - total_reference_instance_fields += super_class->NumReferenceInstanceFields(); - super_class = super_class->GetSuperClass<kVerifyFlags, kReadBarrierOption>(); - } while (super_class != nullptr); - // The only reference field should be the object's class. This field is handled at the - // beginning of the function. - CHECK_EQ(total_reference_instance_fields, 1u); - } - } - } -} } // namespace mirror } // namespace art diff --git a/runtime/mirror/object-refvisitor-inl.h b/runtime/mirror/object-refvisitor-inl.h new file mode 100644 index 0000000000..49ab7c2a53 --- /dev/null +++ b/runtime/mirror/object-refvisitor-inl.h @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ART_RUNTIME_MIRROR_OBJECT_REFVISITOR_INL_H_ +#define ART_RUNTIME_MIRROR_OBJECT_REFVISITOR_INL_H_ + +#include "object-inl.h" + +#include "class-refvisitor-inl.h" + +namespace art { +namespace mirror { + +template <bool kVisitNativeRoots, + VerifyObjectFlags kVerifyFlags, + ReadBarrierOption kReadBarrierOption, + typename Visitor, + typename JavaLangRefVisitor> +inline void Object::VisitReferences(const Visitor& visitor, + const JavaLangRefVisitor& ref_visitor) { + ObjPtr<Class> klass = GetClass<kVerifyFlags, kReadBarrierOption>(); + visitor(this, ClassOffset(), false); + const uint32_t class_flags = klass->GetClassFlags<kVerifyNone>(); + if (LIKELY(class_flags == kClassFlagNormal)) { + DCHECK((!klass->IsVariableSize<kVerifyFlags, kReadBarrierOption>())); + VisitInstanceFieldsReferences<kVerifyFlags, kReadBarrierOption>(klass, visitor); + DCHECK((!klass->IsClassClass<kVerifyFlags, kReadBarrierOption>())); + DCHECK(!klass->IsStringClass()); + DCHECK(!klass->IsClassLoaderClass()); + DCHECK((!klass->IsArrayClass<kVerifyFlags, kReadBarrierOption>())); + } else { + if ((class_flags & kClassFlagNoReferenceFields) == 0) { + DCHECK(!klass->IsStringClass()); + if (class_flags == kClassFlagClass) { + DCHECK((klass->IsClassClass<kVerifyFlags, kReadBarrierOption>())); + ObjPtr<Class> as_klass = AsClass<kVerifyNone, kReadBarrierOption>(); + as_klass->VisitReferences<kVisitNativeRoots, kVerifyFlags, kReadBarrierOption>(klass, + visitor); + } else if (class_flags == kClassFlagObjectArray) { + DCHECK((klass->IsObjectArrayClass<kVerifyFlags, kReadBarrierOption>())); + AsObjectArray<mirror::Object, kVerifyNone, kReadBarrierOption>()->VisitReferences(visitor); + } else if ((class_flags & kClassFlagReference) != 0) { + VisitInstanceFieldsReferences<kVerifyFlags, kReadBarrierOption>(klass, visitor); + ref_visitor(klass, AsReference<kVerifyFlags, kReadBarrierOption>()); + } else if (class_flags == kClassFlagDexCache) { + mirror::DexCache* const dex_cache = AsDexCache<kVerifyFlags, kReadBarrierOption>(); + dex_cache->VisitReferences<kVisitNativeRoots, + kVerifyFlags, + kReadBarrierOption>(klass, visitor); + } else { + mirror::ClassLoader* const class_loader = AsClassLoader<kVerifyFlags, kReadBarrierOption>(); + class_loader->VisitReferences<kVisitNativeRoots, + kVerifyFlags, + kReadBarrierOption>(klass, visitor); + } + } else if (kIsDebugBuild) { + CHECK((!klass->IsClassClass<kVerifyFlags, kReadBarrierOption>())); + CHECK((!klass->IsObjectArrayClass<kVerifyFlags, kReadBarrierOption>())); + // String still has instance fields for reflection purposes but these don't exist in + // actual string instances. + if (!klass->IsStringClass()) { + size_t total_reference_instance_fields = 0; + ObjPtr<Class> super_class = klass; + do { + total_reference_instance_fields += super_class->NumReferenceInstanceFields(); + super_class = super_class->GetSuperClass<kVerifyFlags, kReadBarrierOption>(); + } while (super_class != nullptr); + // The only reference field should be the object's class. This field is handled at the + // beginning of the function. + CHECK_EQ(total_reference_instance_fields, 1u); + } + } + } +} + +} // namespace mirror +} // namespace art + +#endif // ART_RUNTIME_MIRROR_OBJECT_REFVISITOR_INL_H_ diff --git a/runtime/mirror/object.cc b/runtime/mirror/object.cc index eabc29adad..6e5fdb773f 100644 --- a/runtime/mirror/object.cc +++ b/runtime/mirror/object.cc @@ -30,6 +30,7 @@ #include "iftable-inl.h" #include "monitor.h" #include "object-inl.h" +#include "object-refvisitor-inl.h" #include "object_array-inl.h" #include "runtime.h" #include "handle_scope-inl.h" diff --git a/runtime/mirror/object.h b/runtime/mirror/object.h index 417a22dfe3..35a1b733e1 100644 --- a/runtime/mirror/object.h +++ b/runtime/mirror/object.h @@ -487,11 +487,18 @@ class MANAGED LOCKABLE Object { template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false> ALWAYS_INLINE int64_t GetField64(MemberOffset field_offset) - REQUIRES_SHARED(Locks::mutator_lock_); + REQUIRES_SHARED(Locks::mutator_lock_) { + if (kVerifyFlags & kVerifyThis) { + VerifyObject(this); + } + return GetField<int64_t, kIsVolatile>(field_offset); + } template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> ALWAYS_INLINE int64_t GetField64Volatile(MemberOffset field_offset) - REQUIRES_SHARED(Locks::mutator_lock_); + REQUIRES_SHARED(Locks::mutator_lock_) { + return GetField64<kVerifyFlags, true>(field_offset); + } template<bool kTransactionActive, bool kCheckTransaction = true, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false> diff --git a/runtime/mirror/object_test.cc b/runtime/mirror/object_test.cc index d306f9c391..d7527d59b4 100644 --- a/runtime/mirror/object_test.cc +++ b/runtime/mirror/object_test.cc @@ -73,6 +73,13 @@ class ObjectTest : public CommonRuntimeTest { } EXPECT_EQ(expected_hash, string->GetHashCode()); } + + template <class T> + mirror::ObjectArray<T>* AllocObjectArray(Thread* self, size_t length) + REQUIRES_SHARED(Locks::mutator_lock_) { + return mirror::ObjectArray<T>::Alloc( + self, class_linker_->GetClassRoot(ClassLinker::ClassRoot::kObjectArrayClass), length); + } }; // Keep constants in sync. @@ -100,8 +107,7 @@ TEST_F(ObjectTest, IsInSamePackage) { TEST_F(ObjectTest, Clone) { ScopedObjectAccess soa(Thread::Current()); StackHandleScope<2> hs(soa.Self()); - Handle<ObjectArray<Object>> a1( - hs.NewHandle(class_linker_->AllocObjectArray<Object>(soa.Self(), 256))); + Handle<ObjectArray<Object>> a1(hs.NewHandle(AllocObjectArray<Object>(soa.Self(), 256))); size_t s1 = a1->SizeOf(); Object* clone = a1->Clone(soa.Self()); EXPECT_EQ(s1, clone->SizeOf()); @@ -111,8 +117,7 @@ TEST_F(ObjectTest, Clone) { TEST_F(ObjectTest, AllocObjectArray) { ScopedObjectAccess soa(Thread::Current()); StackHandleScope<2> hs(soa.Self()); - Handle<ObjectArray<Object>> oa( - hs.NewHandle(class_linker_->AllocObjectArray<Object>(soa.Self(), 2))); + Handle<ObjectArray<Object>> oa(hs.NewHandle(AllocObjectArray<Object>(soa.Self(), 2))); EXPECT_EQ(2, oa->GetLength()); EXPECT_TRUE(oa->Get(0) == nullptr); EXPECT_TRUE(oa->Get(1) == nullptr); diff --git a/runtime/monitor.cc b/runtime/monitor.cc index f3cb0df80e..e365b42670 100644 --- a/runtime/monitor.cc +++ b/runtime/monitor.cc @@ -31,7 +31,6 @@ #include "lock_word-inl.h" #include "mirror/class-inl.h" #include "mirror/object-inl.h" -#include "mirror/object_array-inl.h" #include "scoped_thread_state_change-inl.h" #include "thread.h" #include "thread_list.h" diff --git a/runtime/native/dalvik_system_ZygoteHooks.cc b/runtime/native/dalvik_system_ZygoteHooks.cc index 836ba81d8e..2eaa8c71b1 100644 --- a/runtime/native/dalvik_system_ZygoteHooks.cc +++ b/runtime/native/dalvik_system_ZygoteHooks.cc @@ -21,6 +21,7 @@ #include "android-base/stringprintf.h" #include "arch/instruction_set.h" +#include "art_method-inl.h" #include "debugger.h" #include "java_vm_ext.h" #include "jit/jit.h" diff --git a/runtime/native/java_lang_Class.cc b/runtime/native/java_lang_Class.cc index 381dc7beb0..4f999471c6 100644 --- a/runtime/native/java_lang_Class.cc +++ b/runtime/native/java_lang_Class.cc @@ -19,8 +19,9 @@ #include <iostream> #include "art_field-inl.h" +#include "art_method-inl.h" #include "base/enums.h" -#include "class_linker.h" +#include "class_linker-inl.h" #include "common_throws.h" #include "dex_file-inl.h" #include "dex_file_annotations.h" diff --git a/runtime/native/java_lang_Void.cc b/runtime/native/java_lang_Void.cc index 96bfd1b4fb..e2b4b82cfb 100644 --- a/runtime/native/java_lang_Void.cc +++ b/runtime/native/java_lang_Void.cc @@ -16,7 +16,7 @@ #include "java_lang_Void.h" -#include "class_linker.h" +#include "class_linker-inl.h" #include "jni_internal.h" #include "runtime.h" #include "scoped_fast_native_object_access-inl.h" diff --git a/runtime/native/scoped_fast_native_object_access-inl.h b/runtime/native/scoped_fast_native_object_access-inl.h index 50a554c930..b2abc4691a 100644 --- a/runtime/native/scoped_fast_native_object_access-inl.h +++ b/runtime/native/scoped_fast_native_object_access-inl.h @@ -19,7 +19,7 @@ #include "scoped_fast_native_object_access.h" -#include "art_method-inl.h" +#include "art_method.h" #include "scoped_thread_state_change-inl.h" namespace art { diff --git a/runtime/oat_file.cc b/runtime/oat_file.cc index a00674a9fe..4a85d4795e 100644 --- a/runtime/oat_file.cc +++ b/runtime/oat_file.cc @@ -34,7 +34,7 @@ #include "android-base/stringprintf.h" -#include "art_method-inl.h" +#include "art_method.h" #include "base/bit_vector.h" #include "base/enums.h" #include "base/stl_util.h" diff --git a/runtime/openjdkjvmti/ti_class.cc b/runtime/openjdkjvmti/ti_class.cc index e94c4e6112..c3a1acf32b 100644 --- a/runtime/openjdkjvmti/ti_class.cc +++ b/runtime/openjdkjvmti/ti_class.cc @@ -55,6 +55,7 @@ #include "mirror/object_array-inl.h" #include "mirror/object_reference.h" #include "mirror/object-inl.h" +#include "mirror/object-refvisitor-inl.h" #include "mirror/reference.h" #include "primitive.h" #include "reflection.h" diff --git a/runtime/openjdkjvmti/ti_class_definition.cc b/runtime/openjdkjvmti/ti_class_definition.cc index 0671105532..180895b597 100644 --- a/runtime/openjdkjvmti/ti_class_definition.cc +++ b/runtime/openjdkjvmti/ti_class_definition.cc @@ -32,10 +32,12 @@ #include "ti_class_definition.h" #include "base/array_slice.h" +#include "class_linker-inl.h" #include "dex_file.h" #include "fixed_up_dex_file.h" #include "handle_scope-inl.h" #include "handle.h" +#include "mirror/class_ext.h" #include "mirror/class-inl.h" #include "mirror/object-inl.h" #include "reflection.h" diff --git a/runtime/openjdkjvmti/ti_redefine.cc b/runtime/openjdkjvmti/ti_redefine.cc index 358bb0f70e..77f507cfe4 100644 --- a/runtime/openjdkjvmti/ti_redefine.cc +++ b/runtime/openjdkjvmti/ti_redefine.cc @@ -35,9 +35,11 @@ #include "android-base/stringprintf.h" +#include "art_method-inl.h" #include "art_jvmti.h" #include "base/array_slice.h" #include "base/logging.h" +#include "class_linker-inl.h" #include "debugger.h" #include "dex_file.h" #include "dex_file_types.h" diff --git a/runtime/proxy_test.cc b/runtime/proxy_test.cc index 5748475163..4e95b019b9 100644 --- a/runtime/proxy_test.cc +++ b/runtime/proxy_test.cc @@ -21,6 +21,7 @@ #include "base/enums.h" #include "class_linker-inl.h" #include "common_compiler_test.h" +#include "mirror/class-inl.h" #include "mirror/field-inl.h" #include "mirror/method.h" #include "scoped_thread_state_change-inl.h" diff --git a/runtime/reference_table_test.cc b/runtime/reference_table_test.cc index 4ccfb6d83b..e809ecf1f6 100644 --- a/runtime/reference_table_test.cc +++ b/runtime/reference_table_test.cc @@ -18,6 +18,7 @@ #include "android-base/stringprintf.h" +#include "art_method-inl.h" #include "class_linker.h" #include "common_runtime_test.h" #include "handle_scope-inl.h" diff --git a/runtime/verifier/verifier_deps.cc b/runtime/verifier/verifier_deps.cc index 55e793527e..51ec51f76a 100644 --- a/runtime/verifier/verifier_deps.cc +++ b/runtime/verifier/verifier_deps.cc @@ -18,8 +18,10 @@ #include <cstring> +#include "art_method-inl.h" #include "base/stl_util.h" #include "compiler_callbacks.h" +#include "dex_file-inl.h" #include "leb128.h" #include "mirror/class-inl.h" #include "obj_ptr-inl.h" diff --git a/test/497-inlining-and-class-loader/clear_dex_cache.cc b/test/497-inlining-and-class-loader/clear_dex_cache.cc index 6c73d7d9b6..34a31aa525 100644 --- a/test/497-inlining-and-class-loader/clear_dex_cache.cc +++ b/test/497-inlining-and-class-loader/clear_dex_cache.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "art_method-inl.h" +#include "art_method.h" #include "base/enums.h" #include "jni.h" #include "scoped_thread_state_change-inl.h" diff --git a/test/common/runtime_state.cc b/test/common/runtime_state.cc index c7a57cefb6..b683a27728 100644 --- a/test/common/runtime_state.cc +++ b/test/common/runtime_state.cc @@ -16,12 +16,14 @@ #include "jni.h" +#include "art_method-inl.h" #include "base/enums.h" #include "base/logging.h" #include "dex_file-inl.h" #include "instrumentation.h" #include "jit/jit.h" #include "jit/jit_code_cache.h" +#include "jit/profiling_info.h" #include "mirror/class-inl.h" #include "oat_quick_method_header.h" #include "runtime.h" |