From 479b1de64cd7a8c9c8ca182c699cb2048850c35d Mon Sep 17 00:00:00 2001 From: Andreas Gampe Date: Tue, 19 Jul 2016 18:27:17 -0700 Subject: [PATCH] ART: Remove PACKED from ArtMethod's ptr_sized_fields_ Remove the PACKED(4) hack, as it's highly annoying when debugging a 64-bit process. Instead, fix the actual offset and size computation for cross-size accesses. Test: m test-art-host Change-Id: I295c78760b74b6a62946e76856f218b4eb159cdc --- runtime/art_method.cc | 14 ++++++++++++++ runtime/art_method.h | 16 ++++++++-------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/runtime/art_method.cc b/runtime/art_method.cc index c4d961f4d..113827ac6 100644 --- a/runtime/art_method.cc +++ b/runtime/art_method.cc @@ -16,6 +16,8 @@ #include "art_method.h" +#include + #include "arch/context.h" #include "art_field-inl.h" #include "art_method-inl.h" @@ -498,6 +500,18 @@ void ArtMethod::CopyFrom(ArtMethod* src, size_t image_pointer_size) { } bool ArtMethod::IsImagePointerSize(size_t pointer_size) { + // Hijack this function to get access to PtrSizedFieldsOffset. + // + // Ensure that PrtSizedFieldsOffset is correct. We rely here on usually having both 32-bit and + // 64-bit builds. + static_assert(std::is_standard_layout::value, "ArtMethod is not standard layout."); + static_assert((sizeof(void*) != 4) || + (offsetof(ArtMethod, ptr_sized_fields_) == PtrSizedFieldsOffset(4)), + "Unexpected 32-bit class layout."); + static_assert((sizeof(void*) != 8) || + (offsetof(ArtMethod, ptr_sized_fields_) == PtrSizedFieldsOffset(8)), + "Unexpected 64-bit class layout."); + Runtime* runtime = Runtime::Current(); if (runtime == nullptr) { return true; diff --git a/runtime/art_method.h b/runtime/art_method.h index 91a44248f..d75113e58 100644 --- a/runtime/art_method.h +++ b/runtime/art_method.h @@ -17,6 +17,8 @@ #ifndef ART_RUNTIME_ART_METHOD_H_ #define ART_RUNTIME_ART_METHOD_H_ +#include + #include "base/bit_utils.h" #include "base/casts.h" #include "dex_file.h" @@ -219,7 +221,7 @@ class ImtConflictTable { class ArtMethod FINAL { public: ArtMethod() : access_flags_(0), dex_code_item_offset_(0), dex_method_index_(0), - method_index_(0) { } + method_index_(0), hotness_count_(0) { } ArtMethod(ArtMethod* src, size_t image_pointer_size) { CopyFrom(src, image_pointer_size); @@ -657,7 +659,7 @@ class ArtMethod FINAL { // Size of an instance of this native class. static size_t Size(size_t pointer_size) { - return RoundUp(OFFSETOF_MEMBER(ArtMethod, ptr_sized_fields_), pointer_size) + + return PtrSizedFieldsOffset(pointer_size) + (sizeof(PtrSizedFields) / sizeof(void*)) * pointer_size; } @@ -744,9 +746,7 @@ class ArtMethod FINAL { // Fake padding field gets inserted here. // Must be the last fields in the method. - // PACKED(4) is necessary for the correctness of - // RoundUp(OFFSETOF_MEMBER(ArtMethod, ptr_sized_fields_), pointer_size). - struct PACKED(4) PtrSizedFields { + struct PtrSizedFields { // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access. ArtMethod** dex_cache_resolved_methods_; @@ -763,9 +763,9 @@ class ArtMethod FINAL { } ptr_sized_fields_; private: - static size_t PtrSizedFieldsOffset(size_t pointer_size) { - // Round up to pointer size for padding field. - return RoundUp(OFFSETOF_MEMBER(ArtMethod, ptr_sized_fields_), pointer_size); + static constexpr size_t PtrSizedFieldsOffset(size_t pointer_size) { + // Round up to pointer size for padding field. Tested in art_method.cc. + return RoundUp(offsetof(ArtMethod, hotness_count_) + sizeof(hotness_count_), pointer_size); } // Compare given pointer size to the image pointer size. -- 2.11.0