Mark most *Offset helper functions as constexpr.
Making the values compile-time constants will help to
clean up the cpp-define-generator.
Test: test.py -b -g
Change-Id: I612a19a54062784b501bfe4f41c6642d48e0dd21
diff --git a/build/Android.bp b/build/Android.bp
index 78fd21a..19d54d5 100644
--- a/build/Android.bp
+++ b/build/Android.bp
@@ -106,6 +106,10 @@
"-Wunreachable-code-break",
"-Wunreachable-code-return",
+ // Disable warning for use of offsetof on non-standard layout type.
+ // We use it to implement OFFSETOF_MEMBER - see macros.h.
+ "-Wno-invalid-offsetof",
+
// Enable thread annotations for std::mutex, etc.
"-D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS",
],
diff --git a/compiler/jni/quick/jni_compiler.cc b/compiler/jni/quick/jni_compiler.cc
index 62e8e02..09376dd 100644
--- a/compiler/jni/quick/jni_compiler.cc
+++ b/compiler/jni/quick/jni_compiler.cc
@@ -219,12 +219,6 @@
jni_asm->cfi().SetEnabled(compiler_options.GenerateAnyDebugInfo());
jni_asm->SetEmitRunTimeChecksInDebugMode(compiler_options.EmitRunTimeChecksInDebugMode());
- // Offsets into data structures
- // TODO: if cross compiling these offsets are for the host not the target
- const Offset functions(OFFSETOF_MEMBER(JNIEnvExt, functions));
- const Offset monitor_enter(OFFSETOF_MEMBER(JNINativeInterface, MonitorEnter));
- const Offset monitor_exit(OFFSETOF_MEMBER(JNINativeInterface, MonitorExit));
-
// 1. Build the frame saving all callee saves, Method*, and PC return address.
const size_t frame_size(main_jni_conv->FrameSize()); // Excludes outgoing args.
ArrayRef<const ManagedRegister> callee_save_regs = main_jni_conv->CalleeSaveRegisters();
diff --git a/libartbase/base/macros.h b/libartbase/base/macros.h
index 315f4d2..323fa4e 100644
--- a/libartbase/base/macros.h
+++ b/libartbase/base/macros.h
@@ -42,8 +42,16 @@
private: \
void* operator new(size_t) = delete // NOLINT
-#define OFFSETOF_MEMBER(t, f) \
- (reinterpret_cast<uintptr_t>(&reinterpret_cast<t*>(16)->f) - static_cast<uintptr_t>(16u)) // NOLINT
+// offsetof is not defined by the spec on types with non-standard layout,
+// however it is implemented by compilers in practice.
+// (note that reinterpret_cast is not valid constexpr)
+//
+// Alternative approach would be something like:
+// #define OFFSETOF_HELPER(t, f) \
+// (reinterpret_cast<uintptr_t>(&reinterpret_cast<t*>(16)->f) - static_cast<uintptr_t>(16u))
+// #define OFFSETOF_MEMBER(t, f) \
+// (__builtin_constant_p(OFFSETOF_HELPER(t,f)) ? OFFSETOF_HELPER(t,f) : OFFSETOF_HELPER(t,f))
+#define OFFSETOF_MEMBER(t, f) offsetof(t, f)
#define OFFSETOF_MEMBERPTR(t, f) \
(reinterpret_cast<uintptr_t>(&(reinterpret_cast<t*>(16)->*f)) - static_cast<uintptr_t>(16)) // NOLINT
diff --git a/runtime/art_method.h b/runtime/art_method.h
index 570b0e6..18ddcc0 100644
--- a/runtime/art_method.h
+++ b/runtime/art_method.h
@@ -103,7 +103,7 @@
bool CASDeclaringClass(ObjPtr<mirror::Class> expected_class, ObjPtr<mirror::Class> desired_class)
REQUIRES_SHARED(Locks::mutator_lock_);
- static MemberOffset DeclaringClassOffset() {
+ static constexpr MemberOffset DeclaringClassOffset() {
return MemberOffset(OFFSETOF_MEMBER(ArtMethod, declaring_class_));
}
@@ -118,7 +118,7 @@
access_flags_.store(new_access_flags, std::memory_order_relaxed);
}
- static MemberOffset AccessFlagsOffset() {
+ static constexpr MemberOffset AccessFlagsOffset() {
return MemberOffset(OFFSETOF_MEMBER(ArtMethod, access_flags_));
}
@@ -351,11 +351,11 @@
method_index_ = new_method_index;
}
- static MemberOffset DexMethodIndexOffset() {
+ static constexpr MemberOffset DexMethodIndexOffset() {
return MemberOffset(OFFSETOF_MEMBER(ArtMethod, dex_method_index_));
}
- static MemberOffset MethodIndexOffset() {
+ static constexpr MemberOffset MethodIndexOffset() {
return MemberOffset(OFFSETOF_MEMBER(ArtMethod, method_index_));
}
@@ -431,16 +431,16 @@
void UnregisterNative() REQUIRES_SHARED(Locks::mutator_lock_);
- static MemberOffset DataOffset(PointerSize pointer_size) {
+ static constexpr MemberOffset DataOffset(PointerSize pointer_size) {
return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
PtrSizedFields, data_) / sizeof(void*) * static_cast<size_t>(pointer_size));
}
- static MemberOffset EntryPointFromJniOffset(PointerSize pointer_size) {
+ static constexpr MemberOffset EntryPointFromJniOffset(PointerSize pointer_size) {
return DataOffset(pointer_size);
}
- static MemberOffset EntryPointFromQuickCompiledCodeOffset(PointerSize pointer_size) {
+ static constexpr MemberOffset EntryPointFromQuickCompiledCodeOffset(PointerSize pointer_size) {
return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
PtrSizedFields, entry_point_from_quick_compiled_code_) / sizeof(void*)
* static_cast<size_t>(pointer_size));
@@ -652,7 +652,7 @@
return hotness_count_;
}
- static MemberOffset HotnessCountOffset() {
+ static constexpr MemberOffset HotnessCountOffset() {
return MemberOffset(OFFSETOF_MEMBER(ArtMethod, hotness_count_));
}
diff --git a/runtime/gc/allocator/rosalloc.h b/runtime/gc/allocator/rosalloc.h
index 0562167..bf26aea 100644
--- a/runtime/gc/allocator/rosalloc.h
+++ b/runtime/gc/allocator/rosalloc.h
@@ -830,16 +830,16 @@
size_t page_release_size_threshold = kDefaultPageReleaseSizeThreshold);
~RosAlloc();
- static size_t RunFreeListOffset() {
+ static constexpr size_t RunFreeListOffset() {
return OFFSETOF_MEMBER(Run, free_list_);
}
- static size_t RunFreeListHeadOffset() {
+ static constexpr size_t RunFreeListHeadOffset() {
return OFFSETOF_MEMBER(SlotFreeList<false>, head_);
}
- static size_t RunFreeListSizeOffset() {
+ static constexpr size_t RunFreeListSizeOffset() {
return OFFSETOF_MEMBER(SlotFreeList<false>, size_);
}
- static size_t RunSlotNextOffset() {
+ static constexpr size_t RunSlotNextOffset() {
return OFFSETOF_MEMBER(Slot, next_);
}
diff --git a/runtime/interpreter/shadow_frame.h b/runtime/interpreter/shadow_frame.h
index 0e4cf27..91371d1 100644
--- a/runtime/interpreter/shadow_frame.h
+++ b/runtime/interpreter/shadow_frame.h
@@ -279,47 +279,47 @@
return lock_count_data_;
}
- static size_t LockCountDataOffset() {
+ static constexpr size_t LockCountDataOffset() {
return OFFSETOF_MEMBER(ShadowFrame, lock_count_data_);
}
- static size_t LinkOffset() {
+ static constexpr size_t LinkOffset() {
return OFFSETOF_MEMBER(ShadowFrame, link_);
}
- static size_t MethodOffset() {
+ static constexpr size_t MethodOffset() {
return OFFSETOF_MEMBER(ShadowFrame, method_);
}
- static size_t DexPCOffset() {
+ static constexpr size_t DexPCOffset() {
return OFFSETOF_MEMBER(ShadowFrame, dex_pc_);
}
- static size_t NumberOfVRegsOffset() {
+ static constexpr size_t NumberOfVRegsOffset() {
return OFFSETOF_MEMBER(ShadowFrame, number_of_vregs_);
}
- static size_t VRegsOffset() {
+ static constexpr size_t VRegsOffset() {
return OFFSETOF_MEMBER(ShadowFrame, vregs_);
}
- static size_t ResultRegisterOffset() {
+ static constexpr size_t ResultRegisterOffset() {
return OFFSETOF_MEMBER(ShadowFrame, result_register_);
}
- static size_t DexPCPtrOffset() {
+ static constexpr size_t DexPCPtrOffset() {
return OFFSETOF_MEMBER(ShadowFrame, dex_pc_ptr_);
}
- static size_t DexInstructionsOffset() {
+ static constexpr size_t DexInstructionsOffset() {
return OFFSETOF_MEMBER(ShadowFrame, dex_instructions_);
}
- static size_t CachedHotnessCountdownOffset() {
+ static constexpr size_t CachedHotnessCountdownOffset() {
return OFFSETOF_MEMBER(ShadowFrame, cached_hotness_countdown_);
}
- static size_t HotnessCountdownOffset() {
+ static constexpr size_t HotnessCountdownOffset() {
return OFFSETOF_MEMBER(ShadowFrame, hotness_countdown_);
}
diff --git a/runtime/managed_stack.h b/runtime/managed_stack.h
index d1c230f..6a0f075 100644
--- a/runtime/managed_stack.h
+++ b/runtime/managed_stack.h
@@ -95,7 +95,7 @@
tagged_top_quick_frame_ = TaggedTopQuickFrame::CreateTagged(top);
}
- static size_t TaggedTopQuickFrameOffset() {
+ static constexpr size_t TaggedTopQuickFrameOffset() {
return OFFSETOF_MEMBER(ManagedStack, tagged_top_quick_frame_);
}
diff --git a/runtime/mirror/accessible_object.h b/runtime/mirror/accessible_object.h
index d489f14..9660bf0 100644
--- a/runtime/mirror/accessible_object.h
+++ b/runtime/mirror/accessible_object.h
@@ -36,7 +36,8 @@
}
private:
- uint8_t flag_;
+ // We only use the field indirectly using the FlagOffset() method.
+ uint8_t flag_ ATTRIBUTE_UNUSED;
// Padding required for correct alignment of subclasses like Executable, Field, etc.
uint8_t padding_[1] ATTRIBUTE_UNUSED;
diff --git a/runtime/mirror/array-inl.h b/runtime/mirror/array-inl.h
index 2e39530..704fb11 100644
--- a/runtime/mirror/array-inl.h
+++ b/runtime/mirror/array-inl.h
@@ -50,14 +50,6 @@
return header_size + data_size;
}
-inline MemberOffset Array::DataOffset(size_t component_size) {
- DCHECK(IsPowerOfTwo(component_size)) << component_size;
- size_t data_offset = RoundUp(OFFSETOF_MEMBER(Array, first_element_), component_size);
- DCHECK_EQ(RoundUp(data_offset, component_size), data_offset)
- << "Array data offset isn't aligned with component size";
- return MemberOffset(data_offset);
-}
-
template<VerifyObjectFlags kVerifyFlags>
inline bool Array::CheckIsValidIndex(int32_t index) {
if (UNLIKELY(static_cast<uint32_t>(index) >=
diff --git a/runtime/mirror/array.h b/runtime/mirror/array.h
index a31a9144..7edc851 100644
--- a/runtime/mirror/array.h
+++ b/runtime/mirror/array.h
@@ -17,6 +17,7 @@
#ifndef ART_RUNTIME_MIRROR_ARRAY_H_
#define ART_RUNTIME_MIRROR_ARRAY_H_
+#include "base/bit_utils.h"
#include "base/enums.h"
#include "gc/allocator_type.h"
#include "obj_ptr.h"
@@ -66,11 +67,17 @@
SetField32<false, false, kVerifyNone>(OFFSET_OF_OBJECT_MEMBER(Array, length_), length);
}
- static MemberOffset LengthOffset() {
+ static constexpr MemberOffset LengthOffset() {
return OFFSET_OF_OBJECT_MEMBER(Array, length_);
}
- static MemberOffset DataOffset(size_t component_size);
+ static constexpr MemberOffset DataOffset(size_t component_size) {
+ DCHECK(IsPowerOfTwo(component_size)) << component_size;
+ size_t data_offset = RoundUp(OFFSETOF_MEMBER(Array, first_element_), component_size);
+ DCHECK_EQ(RoundUp(data_offset, component_size), data_offset)
+ << "Array data offset isn't aligned with component size";
+ return MemberOffset(data_offset);
+ }
void* GetRawData(size_t component_size, int32_t index)
REQUIRES_SHARED(Locks::mutator_lock_) {
@@ -102,9 +109,11 @@
REQUIRES_SHARED(Locks::mutator_lock_);
// The number of array elements.
- int32_t length_;
+ // We only use the field indirectly using the LengthOffset() method.
+ int32_t length_ ATTRIBUTE_UNUSED;
// Marker for the data (used by generated code)
- uint32_t first_element_[0];
+ // We only use the field indirectly using the DataOffset() method.
+ uint32_t first_element_[0] ATTRIBUTE_UNUSED;
DISALLOW_IMPLICIT_CONSTRUCTORS(Array);
};
diff --git a/runtime/mirror/class.h b/runtime/mirror/class.h
index f640d3b..a3240dc 100644
--- a/runtime/mirror/class.h
+++ b/runtime/mirror/class.h
@@ -89,7 +89,7 @@
static void SetStatus(Handle<Class> h_this, ClassStatus new_status, Thread* self)
REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
- static MemberOffset StatusOffset() {
+ static constexpr MemberOffset StatusOffset() {
return MemberOffset(OFFSET_OF_OBJECT_MEMBER(Class, status_));
}
@@ -173,7 +173,7 @@
return GetField32<kVerifyFlags>(AccessFlagsOffset());
}
- static MemberOffset AccessFlagsOffset() {
+ static constexpr MemberOffset AccessFlagsOffset() {
return OFFSET_OF_OBJECT_MEMBER(Class, access_flags_);
}
@@ -352,7 +352,7 @@
return (access_flags & kAccClassIsProxy) != 0;
}
- static MemberOffset PrimitiveTypeOffset() {
+ static constexpr MemberOffset PrimitiveTypeOffset() {
return OFFSET_OF_OBJECT_MEMBER(Class, primitive_type_);
}
@@ -440,7 +440,7 @@
bool IsThrowableClass() REQUIRES_SHARED(Locks::mutator_lock_);
- static MemberOffset ComponentTypeOffset() {
+ static constexpr MemberOffset ComponentTypeOffset() {
return OFFSET_OF_OBJECT_MEMBER(Class, component_type_);
}
@@ -549,10 +549,10 @@
template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
uint32_t GetObjectSize() REQUIRES_SHARED(Locks::mutator_lock_);
- static MemberOffset ObjectSizeOffset() {
+ static constexpr MemberOffset ObjectSizeOffset() {
return OFFSET_OF_OBJECT_MEMBER(Class, object_size_);
}
- static MemberOffset ObjectSizeAllocFastPathOffset() {
+ static constexpr MemberOffset ObjectSizeAllocFastPathOffset() {
return OFFSET_OF_OBJECT_MEMBER(Class, object_size_alloc_fast_path_);
}
@@ -636,7 +636,7 @@
return GetSuperClass() != nullptr;
}
- static MemberOffset SuperClassOffset() {
+ static constexpr MemberOffset SuperClassOffset() {
return MemberOffset(OFFSETOF_MEMBER(Class, super_class_));
}
@@ -646,11 +646,11 @@
void SetClassLoader(ObjPtr<ClassLoader> new_cl) REQUIRES_SHARED(Locks::mutator_lock_);
- static MemberOffset DexCacheOffset() {
+ static constexpr MemberOffset DexCacheOffset() {
return MemberOffset(OFFSETOF_MEMBER(Class, dex_cache_));
}
- static MemberOffset IfTableOffset() {
+ static constexpr MemberOffset IfTableOffset() {
return MemberOffset(OFFSETOF_MEMBER(Class, iftable_));
}
@@ -675,7 +675,7 @@
ALWAYS_INLINE LengthPrefixedArray<ArtMethod>* GetMethodsPtr()
REQUIRES_SHARED(Locks::mutator_lock_);
- static MemberOffset MethodsOffset() {
+ static constexpr MemberOffset MethodsOffset() {
return MemberOffset(OFFSETOF_MEMBER(Class, methods_));
}
@@ -784,15 +784,15 @@
void SetVTable(ObjPtr<PointerArray> new_vtable) REQUIRES_SHARED(Locks::mutator_lock_);
- static MemberOffset VTableOffset() {
+ static constexpr MemberOffset VTableOffset() {
return OFFSET_OF_OBJECT_MEMBER(Class, vtable_);
}
- static MemberOffset EmbeddedVTableLengthOffset() {
+ static constexpr MemberOffset EmbeddedVTableLengthOffset() {
return MemberOffset(sizeof(Class));
}
- static MemberOffset ImtPtrOffset(PointerSize pointer_size) {
+ static constexpr MemberOffset ImtPtrOffset(PointerSize pointer_size) {
return MemberOffset(
RoundUp(EmbeddedVTableLengthOffset().Uint32Value() + sizeof(uint32_t),
static_cast<size_t>(pointer_size)));
diff --git a/runtime/mirror/dex_cache.h b/runtime/mirror/dex_cache.h
index 22ccd20..da1cd3f 100644
--- a/runtime/mirror/dex_cache.h
+++ b/runtime/mirror/dex_cache.h
@@ -226,51 +226,51 @@
return GetFieldObject<String>(OFFSET_OF_OBJECT_MEMBER(DexCache, location_));
}
- static MemberOffset StringsOffset() {
+ static constexpr MemberOffset StringsOffset() {
return OFFSET_OF_OBJECT_MEMBER(DexCache, strings_);
}
- static MemberOffset ResolvedTypesOffset() {
+ static constexpr MemberOffset ResolvedTypesOffset() {
return OFFSET_OF_OBJECT_MEMBER(DexCache, resolved_types_);
}
- static MemberOffset ResolvedFieldsOffset() {
+ static constexpr MemberOffset ResolvedFieldsOffset() {
return OFFSET_OF_OBJECT_MEMBER(DexCache, resolved_fields_);
}
- static MemberOffset ResolvedMethodsOffset() {
+ static constexpr MemberOffset ResolvedMethodsOffset() {
return OFFSET_OF_OBJECT_MEMBER(DexCache, resolved_methods_);
}
- static MemberOffset ResolvedMethodTypesOffset() {
+ static constexpr MemberOffset ResolvedMethodTypesOffset() {
return OFFSET_OF_OBJECT_MEMBER(DexCache, resolved_method_types_);
}
- static MemberOffset ResolvedCallSitesOffset() {
+ static constexpr MemberOffset ResolvedCallSitesOffset() {
return OFFSET_OF_OBJECT_MEMBER(DexCache, resolved_call_sites_);
}
- static MemberOffset NumStringsOffset() {
+ static constexpr MemberOffset NumStringsOffset() {
return OFFSET_OF_OBJECT_MEMBER(DexCache, num_strings_);
}
- static MemberOffset NumResolvedTypesOffset() {
+ static constexpr MemberOffset NumResolvedTypesOffset() {
return OFFSET_OF_OBJECT_MEMBER(DexCache, num_resolved_types_);
}
- static MemberOffset NumResolvedFieldsOffset() {
+ static constexpr MemberOffset NumResolvedFieldsOffset() {
return OFFSET_OF_OBJECT_MEMBER(DexCache, num_resolved_fields_);
}
- static MemberOffset NumResolvedMethodsOffset() {
+ static constexpr MemberOffset NumResolvedMethodsOffset() {
return OFFSET_OF_OBJECT_MEMBER(DexCache, num_resolved_methods_);
}
- static MemberOffset NumResolvedMethodTypesOffset() {
+ static constexpr MemberOffset NumResolvedMethodTypesOffset() {
return OFFSET_OF_OBJECT_MEMBER(DexCache, num_resolved_method_types_);
}
- static MemberOffset NumResolvedCallSitesOffset() {
+ static constexpr MemberOffset NumResolvedCallSitesOffset() {
return OFFSET_OF_OBJECT_MEMBER(DexCache, num_resolved_call_sites_);
}
diff --git a/runtime/mirror/object.h b/runtime/mirror/object.h
index 8fe9923..11e8cca 100644
--- a/runtime/mirror/object.h
+++ b/runtime/mirror/object.h
@@ -86,7 +86,7 @@
return sizeof(Object);
}
- static MemberOffset ClassOffset() {
+ static constexpr MemberOffset ClassOffset() {
return OFFSET_OF_OBJECT_MEMBER(Object, klass_);
}
@@ -138,7 +138,7 @@
REQUIRES(!Locks::thread_list_lock_,
!Locks::thread_suspend_count_lock_);
- static MemberOffset MonitorOffset() {
+ static constexpr MemberOffset MonitorOffset() {
return OFFSET_OF_OBJECT_MEMBER(Object, monitor_);
}
diff --git a/runtime/mirror/string.h b/runtime/mirror/string.h
index d08717c..b32db08 100644
--- a/runtime/mirror/string.h
+++ b/runtime/mirror/string.h
@@ -50,11 +50,11 @@
return sizeof(String);
}
- static MemberOffset CountOffset() {
+ static constexpr MemberOffset CountOffset() {
return OFFSET_OF_OBJECT_MEMBER(String, count_);
}
- static MemberOffset ValueOffset() {
+ static constexpr MemberOffset ValueOffset() {
return OFFSET_OF_OBJECT_MEMBER(String, value_);
}
diff --git a/runtime/offsets.h b/runtime/offsets.h
index 4df9b27..372b821 100644
--- a/runtime/offsets.h
+++ b/runtime/offsets.h
@@ -27,14 +27,14 @@
// Allow the meaning of offsets to be strongly typed.
class Offset {
public:
- explicit Offset(size_t val) : val_(val) {}
- int32_t Int32Value() const {
+ constexpr explicit Offset(size_t val) : val_(val) {}
+ constexpr int32_t Int32Value() const {
return static_cast<int32_t>(val_);
}
- uint32_t Uint32Value() const {
+ constexpr uint32_t Uint32Value() const {
return static_cast<uint32_t>(val_);
}
- size_t SizeValue() const {
+ constexpr size_t SizeValue() const {
return val_;
}
@@ -46,7 +46,7 @@
// Offsets relative to the current frame.
class FrameOffset : public Offset {
public:
- explicit FrameOffset(size_t val) : Offset(val) {}
+ constexpr explicit FrameOffset(size_t val) : Offset(val) {}
bool operator>(FrameOffset other) const { return val_ > other.val_; }
bool operator<(FrameOffset other) const { return val_ < other.val_; }
};
@@ -55,7 +55,7 @@
template<PointerSize pointer_size>
class ThreadOffset : public Offset {
public:
- explicit ThreadOffset(size_t val) : Offset(val) {}
+ constexpr explicit ThreadOffset(size_t val) : Offset(val) {}
};
using ThreadOffset32 = ThreadOffset<PointerSize::k32>;
@@ -64,7 +64,7 @@
// Offsets relative to an object.
class MemberOffset : public Offset {
public:
- explicit MemberOffset(size_t val) : Offset(val) {}
+ constexpr explicit MemberOffset(size_t val) : Offset(val) {}
};
} // namespace art
diff --git a/runtime/runtime.h b/runtime/runtime.h
index ea2eb39..478ff50 100644
--- a/runtime/runtime.h
+++ b/runtime/runtime.h
@@ -399,7 +399,7 @@
QuickMethodFrameInfo GetRuntimeMethodFrameInfo(ArtMethod* method)
REQUIRES_SHARED(Locks::mutator_lock_);
- static size_t GetCalleeSaveMethodOffset(CalleeSaveType type) {
+ static constexpr size_t GetCalleeSaveMethodOffset(CalleeSaveType type) {
return OFFSETOF_MEMBER(Runtime, callee_save_methods_[static_cast<size_t>(type)]);
}
diff --git a/runtime/thread.h b/runtime/thread.h
index a915cd8..3d13774 100644
--- a/runtime/thread.h
+++ b/runtime/thread.h
@@ -651,28 +651,28 @@
//
template<PointerSize pointer_size>
- static ThreadOffset<pointer_size> ThinLockIdOffset() {
+ static constexpr ThreadOffset<pointer_size> ThinLockIdOffset() {
return ThreadOffset<pointer_size>(
OFFSETOF_MEMBER(Thread, tls32_) +
OFFSETOF_MEMBER(tls_32bit_sized_values, thin_lock_thread_id));
}
template<PointerSize pointer_size>
- static ThreadOffset<pointer_size> InterruptedOffset() {
+ static constexpr ThreadOffset<pointer_size> InterruptedOffset() {
return ThreadOffset<pointer_size>(
OFFSETOF_MEMBER(Thread, tls32_) +
OFFSETOF_MEMBER(tls_32bit_sized_values, interrupted));
}
template<PointerSize pointer_size>
- static ThreadOffset<pointer_size> ThreadFlagsOffset() {
+ static constexpr ThreadOffset<pointer_size> ThreadFlagsOffset() {
return ThreadOffset<pointer_size>(
OFFSETOF_MEMBER(Thread, tls32_) +
OFFSETOF_MEMBER(tls_32bit_sized_values, state_and_flags));
}
template<PointerSize pointer_size>
- static ThreadOffset<pointer_size> IsGcMarkingOffset() {
+ static constexpr ThreadOffset<pointer_size> IsGcMarkingOffset() {
return ThreadOffset<pointer_size>(
OFFSETOF_MEMBER(Thread, tls32_) +
OFFSETOF_MEMBER(tls_32bit_sized_values, is_gc_marking));
@@ -687,21 +687,12 @@
private:
template<PointerSize pointer_size>
- static ThreadOffset<pointer_size> ThreadOffsetFromTlsPtr(size_t tls_ptr_offset) {
+ static constexpr ThreadOffset<pointer_size> ThreadOffsetFromTlsPtr(size_t tls_ptr_offset) {
size_t base = OFFSETOF_MEMBER(Thread, tlsPtr_);
- size_t scale;
- size_t shrink;
- if (pointer_size == kRuntimePointerSize) {
- scale = 1;
- shrink = 1;
- } else if (pointer_size > kRuntimePointerSize) {
- scale = static_cast<size_t>(pointer_size) / static_cast<size_t>(kRuntimePointerSize);
- shrink = 1;
- } else {
- DCHECK_GT(kRuntimePointerSize, pointer_size);
- scale = 1;
- shrink = static_cast<size_t>(kRuntimePointerSize) / static_cast<size_t>(pointer_size);
- }
+ size_t scale = (pointer_size > kRuntimePointerSize) ?
+ static_cast<size_t>(pointer_size) / static_cast<size_t>(kRuntimePointerSize) : 1;
+ size_t shrink = (kRuntimePointerSize > pointer_size) ?
+ static_cast<size_t>(kRuntimePointerSize) / static_cast<size_t>(pointer_size) : 1;
return ThreadOffset<pointer_size>(base + ((tls_ptr_offset * scale) / shrink));
}
@@ -741,82 +732,82 @@
}
template<PointerSize pointer_size>
- static ThreadOffset<pointer_size> SelfOffset() {
+ static constexpr ThreadOffset<pointer_size> SelfOffset() {
return ThreadOffsetFromTlsPtr<pointer_size>(OFFSETOF_MEMBER(tls_ptr_sized_values, self));
}
template<PointerSize pointer_size>
- static ThreadOffset<pointer_size> MterpCurrentIBaseOffset() {
+ static constexpr ThreadOffset<pointer_size> MterpCurrentIBaseOffset() {
return ThreadOffsetFromTlsPtr<pointer_size>(
OFFSETOF_MEMBER(tls_ptr_sized_values, mterp_current_ibase));
}
template<PointerSize pointer_size>
- static ThreadOffset<pointer_size> MterpDefaultIBaseOffset() {
+ static constexpr ThreadOffset<pointer_size> MterpDefaultIBaseOffset() {
return ThreadOffsetFromTlsPtr<pointer_size>(
OFFSETOF_MEMBER(tls_ptr_sized_values, mterp_default_ibase));
}
template<PointerSize pointer_size>
- static ThreadOffset<pointer_size> MterpAltIBaseOffset() {
+ static constexpr ThreadOffset<pointer_size> MterpAltIBaseOffset() {
return ThreadOffsetFromTlsPtr<pointer_size>(
OFFSETOF_MEMBER(tls_ptr_sized_values, mterp_alt_ibase));
}
template<PointerSize pointer_size>
- static ThreadOffset<pointer_size> ExceptionOffset() {
+ static constexpr ThreadOffset<pointer_size> ExceptionOffset() {
return ThreadOffsetFromTlsPtr<pointer_size>(OFFSETOF_MEMBER(tls_ptr_sized_values, exception));
}
template<PointerSize pointer_size>
- static ThreadOffset<pointer_size> PeerOffset() {
+ static constexpr ThreadOffset<pointer_size> PeerOffset() {
return ThreadOffsetFromTlsPtr<pointer_size>(OFFSETOF_MEMBER(tls_ptr_sized_values, opeer));
}
template<PointerSize pointer_size>
- static ThreadOffset<pointer_size> CardTableOffset() {
+ static constexpr ThreadOffset<pointer_size> CardTableOffset() {
return ThreadOffsetFromTlsPtr<pointer_size>(OFFSETOF_MEMBER(tls_ptr_sized_values, card_table));
}
template<PointerSize pointer_size>
- static ThreadOffset<pointer_size> ThreadSuspendTriggerOffset() {
+ static constexpr ThreadOffset<pointer_size> ThreadSuspendTriggerOffset() {
return ThreadOffsetFromTlsPtr<pointer_size>(
OFFSETOF_MEMBER(tls_ptr_sized_values, suspend_trigger));
}
template<PointerSize pointer_size>
- static ThreadOffset<pointer_size> ThreadLocalPosOffset() {
+ static constexpr ThreadOffset<pointer_size> ThreadLocalPosOffset() {
return ThreadOffsetFromTlsPtr<pointer_size>(OFFSETOF_MEMBER(tls_ptr_sized_values,
thread_local_pos));
}
template<PointerSize pointer_size>
- static ThreadOffset<pointer_size> ThreadLocalEndOffset() {
+ static constexpr ThreadOffset<pointer_size> ThreadLocalEndOffset() {
return ThreadOffsetFromTlsPtr<pointer_size>(OFFSETOF_MEMBER(tls_ptr_sized_values,
thread_local_end));
}
template<PointerSize pointer_size>
- static ThreadOffset<pointer_size> ThreadLocalObjectsOffset() {
+ static constexpr ThreadOffset<pointer_size> ThreadLocalObjectsOffset() {
return ThreadOffsetFromTlsPtr<pointer_size>(OFFSETOF_MEMBER(tls_ptr_sized_values,
thread_local_objects));
}
template<PointerSize pointer_size>
- static ThreadOffset<pointer_size> RosAllocRunsOffset() {
+ static constexpr ThreadOffset<pointer_size> RosAllocRunsOffset() {
return ThreadOffsetFromTlsPtr<pointer_size>(OFFSETOF_MEMBER(tls_ptr_sized_values,
rosalloc_runs));
}
template<PointerSize pointer_size>
- static ThreadOffset<pointer_size> ThreadLocalAllocStackTopOffset() {
+ static constexpr ThreadOffset<pointer_size> ThreadLocalAllocStackTopOffset() {
return ThreadOffsetFromTlsPtr<pointer_size>(OFFSETOF_MEMBER(tls_ptr_sized_values,
thread_local_alloc_stack_top));
}
template<PointerSize pointer_size>
- static ThreadOffset<pointer_size> ThreadLocalAllocStackEndOffset() {
+ static constexpr ThreadOffset<pointer_size> ThreadLocalAllocStackEndOffset() {
return ThreadOffsetFromTlsPtr<pointer_size>(OFFSETOF_MEMBER(tls_ptr_sized_values,
thread_local_alloc_stack_end));
}
@@ -859,19 +850,19 @@
}
template<PointerSize pointer_size>
- static ThreadOffset<pointer_size> StackEndOffset() {
+ static constexpr ThreadOffset<pointer_size> StackEndOffset() {
return ThreadOffsetFromTlsPtr<pointer_size>(
OFFSETOF_MEMBER(tls_ptr_sized_values, stack_end));
}
template<PointerSize pointer_size>
- static ThreadOffset<pointer_size> JniEnvOffset() {
+ static constexpr ThreadOffset<pointer_size> JniEnvOffset() {
return ThreadOffsetFromTlsPtr<pointer_size>(
OFFSETOF_MEMBER(tls_ptr_sized_values, jni_env));
}
template<PointerSize pointer_size>
- static ThreadOffset<pointer_size> TopOfManagedStackOffset() {
+ static constexpr ThreadOffset<pointer_size> TopOfManagedStackOffset() {
return ThreadOffsetFromTlsPtr<pointer_size>(
OFFSETOF_MEMBER(tls_ptr_sized_values, managed_stack) +
ManagedStack::TaggedTopQuickFrameOffset());
@@ -893,7 +884,7 @@
ALWAYS_INLINE ShadowFrame* PopShadowFrame();
template<PointerSize pointer_size>
- static ThreadOffset<pointer_size> TopShadowFrameOffset() {
+ static constexpr ThreadOffset<pointer_size> TopShadowFrameOffset() {
return ThreadOffsetFromTlsPtr<pointer_size>(
OFFSETOF_MEMBER(tls_ptr_sized_values, managed_stack) +
ManagedStack::TopShadowFrameOffset());
@@ -922,7 +913,7 @@
}
template<PointerSize pointer_size>
- static ThreadOffset<pointer_size> TopHandleScopeOffset() {
+ static constexpr ThreadOffset<pointer_size> TopHandleScopeOffset() {
return ThreadOffsetFromTlsPtr<pointer_size>(OFFSETOF_MEMBER(tls_ptr_sized_values,
top_handle_scope));
}
@@ -1307,11 +1298,11 @@
static void ClearAllInterpreterCaches();
template<PointerSize pointer_size>
- static ThreadOffset<pointer_size> InterpreterCacheOffset() {
+ static constexpr ThreadOffset<pointer_size> InterpreterCacheOffset() {
return ThreadOffset<pointer_size>(OFFSETOF_MEMBER(Thread, interpreter_cache_));
}
- static int InterpreterCacheSizeLog2() {
+ static constexpr int InterpreterCacheSizeLog2() {
return WhichPowerOf2(InterpreterCache::kSize);
}