diff options
| author | 2016-07-22 15:59:16 -0700 | |
|---|---|---|
| committer | 2016-07-25 15:15:03 -0700 | |
| commit | 311fdf52f7d33b988130d07b3d3a86eb148051ca (patch) | |
| tree | 107308e59eb8cf528ff74029c3c180ca2a7242a6 | |
| parent | a69e790ad9751807d4a660bb4432b7ea79f0ad3b (diff) | |
runtime: Refactor asm_support to be auto-generated (mostly)
Usage:
* If the defines are no longer up to date, re-run generate-asm-support
* To add a new field:
--- Edit one of the offset_ or constant def files.
--- Rebuild cpp-define-generator and re-run generate-asm-support
Change-Id: I772430fcf1ad9af40898ebb453848f8412612386
TODO: Integrate this into the build somehow
TODO: Account for 32 vs 64-bit and read barrier vs no read barrier
21 files changed, 825 insertions, 180 deletions
diff --git a/runtime/asm_support.h b/runtime/asm_support.h index 50a786f1db..e1f00ebdc7 100644 --- a/runtime/asm_support.h +++ b/runtime/asm_support.h @@ -63,54 +63,10 @@ static inline void CheckAsmSupportOffsetsAndSizes() { ADD_TEST_EQ(static_cast<size_t>(1U << POINTER_SIZE_SHIFT), static_cast<size_t>(__SIZEOF_POINTER__)) -// Size of references to the heap on the stack. -#define STACK_REFERENCE_SIZE 4 -ADD_TEST_EQ(static_cast<size_t>(STACK_REFERENCE_SIZE), sizeof(art::StackReference<art::mirror::Object>)) - -// Size of heap references -#define COMPRESSED_REFERENCE_SIZE 4 -ADD_TEST_EQ(static_cast<size_t>(COMPRESSED_REFERENCE_SIZE), - sizeof(art::mirror::CompressedReference<art::mirror::Object>)) - -#define COMPRESSED_REFERENCE_SIZE_SHIFT 2 -ADD_TEST_EQ(static_cast<size_t>(1U << COMPRESSED_REFERENCE_SIZE_SHIFT), - static_cast<size_t>(COMPRESSED_REFERENCE_SIZE)) - -// Note: these callee save methods loads require read barriers. -// Offset of field Runtime::callee_save_methods_[kSaveAll] -#define RUNTIME_SAVE_ALL_CALLEE_SAVE_FRAME_OFFSET 0 -ADD_TEST_EQ(static_cast<size_t>(RUNTIME_SAVE_ALL_CALLEE_SAVE_FRAME_OFFSET), - art::Runtime::GetCalleeSaveMethodOffset(art::Runtime::kSaveAll)) - -// Offset of field Runtime::callee_save_methods_[kRefsOnly] -#define RUNTIME_REFS_ONLY_CALLEE_SAVE_FRAME_OFFSET 8 -ADD_TEST_EQ(static_cast<size_t>(RUNTIME_REFS_ONLY_CALLEE_SAVE_FRAME_OFFSET), - art::Runtime::GetCalleeSaveMethodOffset(art::Runtime::kRefsOnly)) - -// Offset of field Runtime::callee_save_methods_[kRefsAndArgs] -#define RUNTIME_REFS_AND_ARGS_CALLEE_SAVE_FRAME_OFFSET (2 * 8) -ADD_TEST_EQ(static_cast<size_t>(RUNTIME_REFS_AND_ARGS_CALLEE_SAVE_FRAME_OFFSET), - art::Runtime::GetCalleeSaveMethodOffset(art::Runtime::kRefsAndArgs)) - -// Offset of field Thread::tls32_.state_and_flags. -#define THREAD_FLAGS_OFFSET 0 -ADD_TEST_EQ(THREAD_FLAGS_OFFSET, - art::Thread::ThreadFlagsOffset<__SIZEOF_POINTER__>().Int32Value()) - -// Offset of field Thread::tls32_.thin_lock_thread_id. -#define THREAD_ID_OFFSET 12 -ADD_TEST_EQ(THREAD_ID_OFFSET, - art::Thread::ThinLockIdOffset<__SIZEOF_POINTER__>().Int32Value()) - -// Offset of field Thread::tls32_.is_gc_marking. -#define THREAD_IS_GC_MARKING_OFFSET 52 -ADD_TEST_EQ(THREAD_IS_GC_MARKING_OFFSET, - art::Thread::IsGcMarkingOffset<__SIZEOF_POINTER__>().Int32Value()) - -// Offset of field Thread::tlsPtr_.card_table. -#define THREAD_CARD_TABLE_OFFSET 128 -ADD_TEST_EQ(THREAD_CARD_TABLE_OFFSET, - art::Thread::CardTableOffset<__SIZEOF_POINTER__>().Int32Value()) +// Import platform-independent constant defines from our autogenerated list. +// Export new defines (for assembly use) by editing cpp-define-generator def files. +#define DEFINE_CHECK_EQ ADD_TEST_EQ +#include "generated/asm_support_gen.h" // Offset of field Thread::tlsPtr_.exception. #define THREAD_EXCEPTION_OFFSET (THREAD_CARD_TABLE_OFFSET + __SIZEOF_POINTER__) @@ -199,17 +155,6 @@ ADD_TEST_EQ(SHADOWFRAME_HOTNESS_COUNTDOWN_OFFSET, ADD_TEST_EQ(SHADOWFRAME_VREGS_OFFSET, static_cast<int32_t>(art::ShadowFrame::VRegsOffset())) -// Offsets within CodeItem -#define CODEITEM_INSNS_OFFSET 16 -ADD_TEST_EQ(CODEITEM_INSNS_OFFSET, - static_cast<int32_t>(OFFSETOF_MEMBER(art::DexFile::CodeItem, insns_))) - -// Offsets within java.lang.Object. -#define MIRROR_OBJECT_CLASS_OFFSET 0 -ADD_TEST_EQ(MIRROR_OBJECT_CLASS_OFFSET, art::mirror::Object::ClassOffset().Int32Value()) -#define MIRROR_OBJECT_LOCK_WORD_OFFSET 4 -ADD_TEST_EQ(MIRROR_OBJECT_LOCK_WORD_OFFSET, art::mirror::Object::MonitorOffset().Int32Value()) - #if defined(USE_BROOKS_READ_BARRIER) #define MIRROR_OBJECT_HEADER_SIZE 16 #else @@ -231,16 +176,6 @@ ADD_TEST_EQ(MIRROR_CLASS_OBJECT_SIZE_OFFSET, ADD_TEST_EQ(MIRROR_CLASS_STATUS_OFFSET, art::mirror::Class::StatusOffset().Int32Value()) -#define MIRROR_CLASS_STATUS_INITIALIZED 10 -ADD_TEST_EQ(static_cast<uint32_t>(MIRROR_CLASS_STATUS_INITIALIZED), - static_cast<uint32_t>(art::mirror::Class::kStatusInitialized)) -#define ACCESS_FLAGS_CLASS_IS_FINALIZABLE 0x80000000 -ADD_TEST_EQ(static_cast<uint32_t>(ACCESS_FLAGS_CLASS_IS_FINALIZABLE), - static_cast<uint32_t>(art::kAccClassIsFinalizable)) -#define ACCESS_FLAGS_CLASS_IS_FINALIZABLE_BIT 31 -ADD_TEST_EQ(static_cast<uint32_t>(ACCESS_FLAGS_CLASS_IS_FINALIZABLE), - static_cast<uint32_t>(1U << ACCESS_FLAGS_CLASS_IS_FINALIZABLE_BIT)) - // Array offsets. #define MIRROR_ARRAY_LENGTH_OFFSET MIRROR_OBJECT_HEADER_SIZE ADD_TEST_EQ(MIRROR_ARRAY_LENGTH_OFFSET, art::mirror::Array::LengthOffset().Int32Value()) @@ -289,118 +224,7 @@ ADD_TEST_EQ(MIRROR_STRING_COUNT_OFFSET, art::mirror::String::CountOffset().Int32 #define MIRROR_STRING_VALUE_OFFSET (8 + MIRROR_OBJECT_HEADER_SIZE) ADD_TEST_EQ(MIRROR_STRING_VALUE_OFFSET, art::mirror::String::ValueOffset().Int32Value()) -// Offsets within java.lang.reflect.ArtMethod. -#define ART_METHOD_DEX_CACHE_METHODS_OFFSET_32 20 -ADD_TEST_EQ(ART_METHOD_DEX_CACHE_METHODS_OFFSET_32, - art::ArtMethod::DexCacheResolvedMethodsOffset(4).Int32Value()) - -#define ART_METHOD_DEX_CACHE_METHODS_OFFSET_64 24 -ADD_TEST_EQ(ART_METHOD_DEX_CACHE_METHODS_OFFSET_64, - art::ArtMethod::DexCacheResolvedMethodsOffset(8).Int32Value()) - -#define ART_METHOD_DEX_CACHE_TYPES_OFFSET_32 24 -ADD_TEST_EQ(ART_METHOD_DEX_CACHE_TYPES_OFFSET_32, - art::ArtMethod::DexCacheResolvedTypesOffset(4).Int32Value()) - -#define ART_METHOD_DEX_CACHE_TYPES_OFFSET_64 32 -ADD_TEST_EQ(ART_METHOD_DEX_CACHE_TYPES_OFFSET_64, - art::ArtMethod::DexCacheResolvedTypesOffset(8).Int32Value()) - -#define ART_METHOD_JNI_OFFSET_32 28 -ADD_TEST_EQ(ART_METHOD_JNI_OFFSET_32, - art::ArtMethod::EntryPointFromJniOffset(4).Int32Value()) - -#define ART_METHOD_JNI_OFFSET_64 40 -ADD_TEST_EQ(ART_METHOD_JNI_OFFSET_64, - art::ArtMethod::EntryPointFromJniOffset(8).Int32Value()) - -#define ART_METHOD_QUICK_CODE_OFFSET_32 32 -ADD_TEST_EQ(ART_METHOD_QUICK_CODE_OFFSET_32, - art::ArtMethod::EntryPointFromQuickCompiledCodeOffset(4).Int32Value()) - -#define ART_METHOD_QUICK_CODE_OFFSET_64 48 -ADD_TEST_EQ(ART_METHOD_QUICK_CODE_OFFSET_64, - art::ArtMethod::EntryPointFromQuickCompiledCodeOffset(8).Int32Value()) - -#define LOCK_WORD_STATE_SHIFT 30 -ADD_TEST_EQ(LOCK_WORD_STATE_SHIFT, static_cast<int32_t>(art::LockWord::kStateShift)) - -#define LOCK_WORD_STATE_MASK 0xC0000000 -ADD_TEST_EQ(LOCK_WORD_STATE_MASK, static_cast<uint32_t>(art::LockWord::kStateMaskShifted)) - -#define LOCK_WORD_READ_BARRIER_STATE_SHIFT 28 -ADD_TEST_EQ(LOCK_WORD_READ_BARRIER_STATE_SHIFT, - static_cast<int32_t>(art::LockWord::kReadBarrierStateShift)) - -#define LOCK_WORD_READ_BARRIER_STATE_MASK 0x30000000 -ADD_TEST_EQ(LOCK_WORD_READ_BARRIER_STATE_MASK, - static_cast<int32_t>(art::LockWord::kReadBarrierStateMaskShifted)) - -#define LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED 0xCFFFFFFF -ADD_TEST_EQ(LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED, - static_cast<uint32_t>(art::LockWord::kReadBarrierStateMaskShiftedToggled)) - -#define LOCK_WORD_THIN_LOCK_COUNT_ONE 65536 -ADD_TEST_EQ(LOCK_WORD_THIN_LOCK_COUNT_ONE, static_cast<int32_t>(art::LockWord::kThinLockCountOne)) - -#define OBJECT_ALIGNMENT_MASK 7 -ADD_TEST_EQ(static_cast<size_t>(OBJECT_ALIGNMENT_MASK), art::kObjectAlignment - 1) - -#define OBJECT_ALIGNMENT_MASK_TOGGLED 0xFFFFFFF8 -ADD_TEST_EQ(static_cast<uint32_t>(OBJECT_ALIGNMENT_MASK_TOGGLED), - ~static_cast<uint32_t>(art::kObjectAlignment - 1)) - -#define ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE 128 -ADD_TEST_EQ(ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE, - static_cast<int32_t>(art::gc::allocator::RosAlloc::kMaxThreadLocalBracketSize)) - -#define ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT 3 -ADD_TEST_EQ(ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT, - static_cast<int32_t>(art::gc::allocator::RosAlloc::kThreadLocalBracketQuantumSizeShift)) - -#define ROSALLOC_BRACKET_QUANTUM_SIZE_MASK 7 -ADD_TEST_EQ(ROSALLOC_BRACKET_QUANTUM_SIZE_MASK, - static_cast<int32_t>(art::gc::allocator::RosAlloc::kThreadLocalBracketQuantumSize - 1)) - -#define ROSALLOC_BRACKET_QUANTUM_SIZE_MASK_TOGGLED32 0xfffffff8 -ADD_TEST_EQ(static_cast<uint32_t>(ROSALLOC_BRACKET_QUANTUM_SIZE_MASK_TOGGLED32), - ~static_cast<uint32_t>( - art::gc::allocator::RosAlloc::kThreadLocalBracketQuantumSize - 1)) - -#define ROSALLOC_BRACKET_QUANTUM_SIZE_MASK_TOGGLED64 0xfffffffffffffff8 -ADD_TEST_EQ(static_cast<uint64_t>(ROSALLOC_BRACKET_QUANTUM_SIZE_MASK_TOGGLED64), - ~static_cast<uint64_t>( - art::gc::allocator::RosAlloc::kThreadLocalBracketQuantumSize - 1)) - -#define ROSALLOC_RUN_FREE_LIST_OFFSET 8 -ADD_TEST_EQ(ROSALLOC_RUN_FREE_LIST_OFFSET, - static_cast<int32_t>(art::gc::allocator::RosAlloc::RunFreeListOffset())) - -#define ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET 0 -ADD_TEST_EQ(ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET, - static_cast<int32_t>(art::gc::allocator::RosAlloc::RunFreeListHeadOffset())) - -#define ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET 16 -ADD_TEST_EQ(ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET, - static_cast<int32_t>(art::gc::allocator::RosAlloc::RunFreeListSizeOffset())) - -#define ROSALLOC_SLOT_NEXT_OFFSET 0 -ADD_TEST_EQ(ROSALLOC_SLOT_NEXT_OFFSET, - static_cast<int32_t>(art::gc::allocator::RosAlloc::RunSlotNextOffset())) -// Assert this so that we can avoid zeroing the next field by installing the class pointer. -ADD_TEST_EQ(ROSALLOC_SLOT_NEXT_OFFSET, MIRROR_OBJECT_CLASS_OFFSET) - -#define THREAD_SUSPEND_REQUEST 1 -ADD_TEST_EQ(THREAD_SUSPEND_REQUEST, static_cast<int32_t>(art::kSuspendRequest)) - -#define THREAD_CHECKPOINT_REQUEST 2 -ADD_TEST_EQ(THREAD_CHECKPOINT_REQUEST, static_cast<int32_t>(art::kCheckpointRequest)) - -#define JIT_CHECK_OSR (-1) -ADD_TEST_EQ(JIT_CHECK_OSR, static_cast<int32_t>(art::jit::kJitCheckForOSR)) -#define JIT_HOTNESS_DISABLE (-2) -ADD_TEST_EQ(JIT_HOTNESS_DISABLE, static_cast<int32_t>(art::jit::kJitHotnessDisabled)) #if defined(__cplusplus) } // End of CheckAsmSupportOffsets. diff --git a/runtime/generated/asm_support_gen.h b/runtime/generated/asm_support_gen.h new file mode 100644 index 0000000000..f1a32569e1 --- /dev/null +++ b/runtime/generated/asm_support_gen.h @@ -0,0 +1,115 @@ + +/* + * 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_GENERATED_ASM_SUPPORT_GEN_H_ +#define ART_RUNTIME_GENERATED_ASM_SUPPORT_GEN_H_ + +// This file has been auto-generated by cpp-define-generator; do not edit directly. + +#define STACK_REFERENCE_SIZE 0x4 +DEFINE_CHECK_EQ(static_cast<size_t>(STACK_REFERENCE_SIZE), (static_cast<size_t>(sizeof(art::StackReference<art::mirror::Object>)))) +#define COMPRESSED_REFERENCE_SIZE 0x4 +DEFINE_CHECK_EQ(static_cast<size_t>(COMPRESSED_REFERENCE_SIZE), (static_cast<size_t>(sizeof(art::mirror::CompressedReference<art::mirror::Object>)))) +#define COMPRESSED_REFERENCE_SIZE_SHIFT 0x2 +DEFINE_CHECK_EQ(static_cast<size_t>(COMPRESSED_REFERENCE_SIZE_SHIFT), (static_cast<size_t>(art::WhichPowerOf2(sizeof(art::mirror::CompressedReference<art::mirror::Object>))))) +#define RUNTIME_SAVE_ALL_CALLEE_SAVE_FRAME_OFFSET 0 +DEFINE_CHECK_EQ(static_cast<size_t>(RUNTIME_SAVE_ALL_CALLEE_SAVE_FRAME_OFFSET), (static_cast<size_t>(art::Runtime::GetCalleeSaveMethodOffset(art::Runtime:: kSaveAll)))) +#define RUNTIME_REFS_ONLY_CALLEE_SAVE_FRAME_OFFSET 0x8 +DEFINE_CHECK_EQ(static_cast<size_t>(RUNTIME_REFS_ONLY_CALLEE_SAVE_FRAME_OFFSET), (static_cast<size_t>(art::Runtime::GetCalleeSaveMethodOffset(art::Runtime:: kRefsOnly)))) +#define RUNTIME_REFS_AND_ARGS_CALLEE_SAVE_FRAME_OFFSET 0x10 +DEFINE_CHECK_EQ(static_cast<size_t>(RUNTIME_REFS_AND_ARGS_CALLEE_SAVE_FRAME_OFFSET), (static_cast<size_t>(art::Runtime::GetCalleeSaveMethodOffset(art::Runtime:: kRefsAndArgs)))) +#define THREAD_FLAGS_OFFSET 0 +DEFINE_CHECK_EQ(static_cast<int32_t>(THREAD_FLAGS_OFFSET), (static_cast<int32_t>(art::Thread:: ThreadFlagsOffset<sizeof(void*)>().Int32Value()))) +#define THREAD_ID_OFFSET 12 +DEFINE_CHECK_EQ(static_cast<int32_t>(THREAD_ID_OFFSET), (static_cast<int32_t>(art::Thread:: ThinLockIdOffset<sizeof(void*)>().Int32Value()))) +#define THREAD_IS_GC_MARKING_OFFSET 52 +DEFINE_CHECK_EQ(static_cast<int32_t>(THREAD_IS_GC_MARKING_OFFSET), (static_cast<int32_t>(art::Thread:: IsGcMarkingOffset<sizeof(void*)>().Int32Value()))) +#define THREAD_CARD_TABLE_OFFSET 128 +DEFINE_CHECK_EQ(static_cast<int32_t>(THREAD_CARD_TABLE_OFFSET), (static_cast<int32_t>(art::Thread:: CardTableOffset<sizeof(void*)>().Int32Value()))) +#define CODEITEM_INSNS_OFFSET 16 +DEFINE_CHECK_EQ(static_cast<int32_t>(CODEITEM_INSNS_OFFSET), (static_cast<int32_t>(__builtin_offsetof(art::DexFile::CodeItem, insns_)))) +#define MIRROR_OBJECT_CLASS_OFFSET 0 +DEFINE_CHECK_EQ(static_cast<int32_t>(MIRROR_OBJECT_CLASS_OFFSET), (static_cast<int32_t>(art::mirror::Object:: ClassOffset().Int32Value()))) +#define MIRROR_OBJECT_LOCK_WORD_OFFSET 4 +DEFINE_CHECK_EQ(static_cast<int32_t>(MIRROR_OBJECT_LOCK_WORD_OFFSET), (static_cast<int32_t>(art::mirror::Object:: MonitorOffset().Int32Value()))) +#define MIRROR_CLASS_STATUS_INITIALIZED 0xa +DEFINE_CHECK_EQ(static_cast<uint32_t>(MIRROR_CLASS_STATUS_INITIALIZED), (static_cast<uint32_t>((art::mirror::Class::kStatusInitialized)))) +#define ACCESS_FLAGS_CLASS_IS_FINALIZABLE 0x80000000 +DEFINE_CHECK_EQ(static_cast<uint32_t>(ACCESS_FLAGS_CLASS_IS_FINALIZABLE), (static_cast<uint32_t>((art::kAccClassIsFinalizable)))) +#define ACCESS_FLAGS_CLASS_IS_FINALIZABLE_BIT 0x1f +DEFINE_CHECK_EQ(static_cast<uint32_t>(ACCESS_FLAGS_CLASS_IS_FINALIZABLE_BIT), (static_cast<uint32_t>((art::MostSignificantBit(art::kAccClassIsFinalizable))))) +#define ART_METHOD_DEX_CACHE_METHODS_OFFSET_32 20 +DEFINE_CHECK_EQ(static_cast<int32_t>(ART_METHOD_DEX_CACHE_METHODS_OFFSET_32), (static_cast<int32_t>(art::ArtMethod:: DexCacheResolvedMethodsOffset(4).Int32Value()))) +#define ART_METHOD_DEX_CACHE_METHODS_OFFSET_64 24 +DEFINE_CHECK_EQ(static_cast<int32_t>(ART_METHOD_DEX_CACHE_METHODS_OFFSET_64), (static_cast<int32_t>(art::ArtMethod:: DexCacheResolvedMethodsOffset(8).Int32Value()))) +#define ART_METHOD_DEX_CACHE_TYPES_OFFSET_32 24 +DEFINE_CHECK_EQ(static_cast<int32_t>(ART_METHOD_DEX_CACHE_TYPES_OFFSET_32), (static_cast<int32_t>(art::ArtMethod:: DexCacheResolvedTypesOffset(4).Int32Value()))) +#define ART_METHOD_DEX_CACHE_TYPES_OFFSET_64 32 +DEFINE_CHECK_EQ(static_cast<int32_t>(ART_METHOD_DEX_CACHE_TYPES_OFFSET_64), (static_cast<int32_t>(art::ArtMethod:: DexCacheResolvedTypesOffset(8).Int32Value()))) +#define ART_METHOD_JNI_OFFSET_32 28 +DEFINE_CHECK_EQ(static_cast<int32_t>(ART_METHOD_JNI_OFFSET_32), (static_cast<int32_t>(art::ArtMethod:: EntryPointFromJniOffset(4).Int32Value()))) +#define ART_METHOD_JNI_OFFSET_64 40 +DEFINE_CHECK_EQ(static_cast<int32_t>(ART_METHOD_JNI_OFFSET_64), (static_cast<int32_t>(art::ArtMethod:: EntryPointFromJniOffset(8).Int32Value()))) +#define ART_METHOD_QUICK_CODE_OFFSET_32 32 +DEFINE_CHECK_EQ(static_cast<int32_t>(ART_METHOD_QUICK_CODE_OFFSET_32), (static_cast<int32_t>(art::ArtMethod:: EntryPointFromQuickCompiledCodeOffset(4).Int32Value()))) +#define ART_METHOD_QUICK_CODE_OFFSET_64 48 +DEFINE_CHECK_EQ(static_cast<int32_t>(ART_METHOD_QUICK_CODE_OFFSET_64), (static_cast<int32_t>(art::ArtMethod:: EntryPointFromQuickCompiledCodeOffset(8).Int32Value()))) +#define LOCK_WORD_STATE_SHIFT 30 +DEFINE_CHECK_EQ(static_cast<int32_t>(LOCK_WORD_STATE_SHIFT), (static_cast<int32_t>(art::LockWord::kStateShift))) +#define LOCK_WORD_STATE_MASK 0xc0000000 +DEFINE_CHECK_EQ(static_cast<uint32_t>(LOCK_WORD_STATE_MASK), (static_cast<uint32_t>(art::LockWord::kStateMaskShifted))) +#define LOCK_WORD_READ_BARRIER_STATE_SHIFT 28 +DEFINE_CHECK_EQ(static_cast<int32_t>(LOCK_WORD_READ_BARRIER_STATE_SHIFT), (static_cast<int32_t>(art::LockWord::kReadBarrierStateShift))) +#define LOCK_WORD_READ_BARRIER_STATE_MASK 0x30000000 +DEFINE_CHECK_EQ(static_cast<uint32_t>(LOCK_WORD_READ_BARRIER_STATE_MASK), (static_cast<uint32_t>(art::LockWord::kReadBarrierStateMaskShifted))) +#define LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED 0xcfffffff +DEFINE_CHECK_EQ(static_cast<uint32_t>(LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED), (static_cast<uint32_t>(art::LockWord::kReadBarrierStateMaskShiftedToggled))) +#define LOCK_WORD_THIN_LOCK_COUNT_ONE 65536 +DEFINE_CHECK_EQ(static_cast<int32_t>(LOCK_WORD_THIN_LOCK_COUNT_ONE), (static_cast<int32_t>(art::LockWord::kThinLockCountOne))) +#define OBJECT_ALIGNMENT_MASK 0x7 +DEFINE_CHECK_EQ(static_cast<size_t>(OBJECT_ALIGNMENT_MASK), (static_cast<size_t>(art::kObjectAlignment - 1))) +#define OBJECT_ALIGNMENT_MASK_TOGGLED 0xfffffff8 +DEFINE_CHECK_EQ(static_cast<uint32_t>(OBJECT_ALIGNMENT_MASK_TOGGLED), (static_cast<uint32_t>(~static_cast<uint32_t>(art::kObjectAlignment - 1)))) +#define ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE 128 +DEFINE_CHECK_EQ(static_cast<int32_t>(ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE), (static_cast<int32_t>((art::gc::allocator::RosAlloc::kMaxThreadLocalBracketSize)))) +#define ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT 3 +DEFINE_CHECK_EQ(static_cast<int32_t>(ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT), (static_cast<int32_t>((art::gc::allocator::RosAlloc::kThreadLocalBracketQuantumSizeShift)))) +#define ROSALLOC_BRACKET_QUANTUM_SIZE_MASK 7 +DEFINE_CHECK_EQ(static_cast<int32_t>(ROSALLOC_BRACKET_QUANTUM_SIZE_MASK), (static_cast<int32_t>((static_cast<int32_t>(art::gc::allocator::RosAlloc::kThreadLocalBracketQuantumSize - 1))))) +#define ROSALLOC_BRACKET_QUANTUM_SIZE_MASK_TOGGLED32 0xfffffff8 +DEFINE_CHECK_EQ(static_cast<uint32_t>(ROSALLOC_BRACKET_QUANTUM_SIZE_MASK_TOGGLED32), (static_cast<uint32_t>((~static_cast<uint32_t>(art::gc::allocator::RosAlloc::kThreadLocalBracketQuantumSize - 1))))) +#define ROSALLOC_BRACKET_QUANTUM_SIZE_MASK_TOGGLED64 0xfffffffffffffff8 +DEFINE_CHECK_EQ(static_cast<uint64_t>(ROSALLOC_BRACKET_QUANTUM_SIZE_MASK_TOGGLED64), (static_cast<uint64_t>((~static_cast<uint64_t>(art::gc::allocator::RosAlloc::kThreadLocalBracketQuantumSize - 1))))) +#define ROSALLOC_RUN_FREE_LIST_OFFSET 8 +DEFINE_CHECK_EQ(static_cast<int32_t>(ROSALLOC_RUN_FREE_LIST_OFFSET), (static_cast<int32_t>((art::gc::allocator::RosAlloc::RunFreeListOffset())))) +#define ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET 0 +DEFINE_CHECK_EQ(static_cast<int32_t>(ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET), (static_cast<int32_t>((art::gc::allocator::RosAlloc::RunFreeListHeadOffset())))) +#define ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET 16 +DEFINE_CHECK_EQ(static_cast<int32_t>(ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET), (static_cast<int32_t>((art::gc::allocator::RosAlloc::RunFreeListSizeOffset())))) +#define ROSALLOC_SLOT_NEXT_OFFSET 0 +DEFINE_CHECK_EQ(static_cast<int32_t>(ROSALLOC_SLOT_NEXT_OFFSET), (static_cast<int32_t>((art::gc::allocator::RosAlloc::RunSlotNextOffset())))) +#define THREAD_SUSPEND_REQUEST 1 +DEFINE_CHECK_EQ(static_cast<int32_t>(THREAD_SUSPEND_REQUEST), (static_cast<int32_t>((art::kSuspendRequest)))) +#define THREAD_CHECKPOINT_REQUEST 2 +DEFINE_CHECK_EQ(static_cast<int32_t>(THREAD_CHECKPOINT_REQUEST), (static_cast<int32_t>((art::kCheckpointRequest)))) +#define JIT_CHECK_OSR (-1) +DEFINE_CHECK_EQ(static_cast<int16_t>(JIT_CHECK_OSR), (static_cast<int16_t>((art::jit::kJitCheckForOSR)))) +#define JIT_HOTNESS_DISABLE (-2) +DEFINE_CHECK_EQ(static_cast<int16_t>(JIT_HOTNESS_DISABLE), (static_cast<int16_t>((art::jit::kJitHotnessDisabled)))) + +#endif // ART_RUNTIME_GENERATED_ASM_SUPPORT_GEN_H_ + diff --git a/tools/cpp-define-generator/Android.mk b/tools/cpp-define-generator/Android.mk new file mode 100644 index 0000000000..6ba643cd81 --- /dev/null +++ b/tools/cpp-define-generator/Android.mk @@ -0,0 +1,34 @@ +# +# Copyright (C) 2014 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. +# + +LOCAL_PATH := $(call my-dir) + +include art/build/Android.executable.mk + +CPP_DEFINE_GENERATOR_SRC_FILES := \ + main.cc + +CPP_DEFINE_GENERATOR_EXTRA_SHARED_LIBRARIES := +CPP_DEFINE_GENERATOR_EXTRA_INCLUDE := +CPP_DEFINE_GENERATOR_MULTILIB := + +# Build a "data" binary which will hold all the symbol values that will be parsed by the other scripts. +# +# Builds are for host only, target-specific define generation is possibly but is trickier and would need extra tooling. +# +# In the future we may wish to parameterize this on (32,64)x(read_barrier,no_read_barrier). +$(eval $(call build-art-executable,cpp-define-generator-data,$(CPP_DEFINE_GENERATOR_SRC_FILES),$(CPP_DEFINE_GENERATOR_EXTRA_SHARED_LIBRARIES),$(CPP_DEFINE_GENERATOR_EXTRA_INCLUDE),host,debug,$(CPP_DEFINE_GENERATOR_MULTILIB),shared)) + diff --git a/tools/cpp-define-generator/common.def b/tools/cpp-define-generator/common.def new file mode 100644 index 0000000000..76c64c97c2 --- /dev/null +++ b/tools/cpp-define-generator/common.def @@ -0,0 +1,24 @@ +/* + * 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. + */ + +// Convenience macro to define an offset expression. + +#ifndef DEFINE_OFFSET_EXPR +#define DEFINE_OFFSET_EXPR(holder_type, field_name, field_type, expr) \ + DEFINE_EXPR(holder_type ## _ ## field_name ## _OFFSET, field_type, expr) +#define DEFINE_OFFSET_EXPR_STANDARD_DEFINITION +#endif + diff --git a/tools/cpp-define-generator/common_undef.def b/tools/cpp-define-generator/common_undef.def new file mode 100644 index 0000000000..c44aba7c3b --- /dev/null +++ b/tools/cpp-define-generator/common_undef.def @@ -0,0 +1,20 @@ +/* + * 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. + */ + +#ifdef DEFINE_OFFSET_EXPR_STANDARD_DEFINITION +#undef DEFINE_OFFSET_EXPR_STANDARD_DEFINITION +#undef DEFINE_OFFSET_EXPR +#endif diff --git a/tools/cpp-define-generator/constant_class.def b/tools/cpp-define-generator/constant_class.def new file mode 100644 index 0000000000..58372f91d3 --- /dev/null +++ b/tools/cpp-define-generator/constant_class.def @@ -0,0 +1,31 @@ +/* + * 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. + */ + +#if defined(DEFINE_INCLUDE_DEPENDENCIES) +#include "mirror/class.h" // kStatusInitialized +#include "modifiers.h" // kAccClassIsFinalizable +#include "base/bit_utils.h" // MostSignificantBit +#endif + +#define DEFINE_FLAG_OFFSET(type_name, field_name, expr) \ + DEFINE_EXPR(type_name ## _ ## field_name, uint32_t, (expr)) + +DEFINE_FLAG_OFFSET(MIRROR_CLASS, STATUS_INITIALIZED, art::mirror::Class::kStatusInitialized) +DEFINE_FLAG_OFFSET(ACCESS_FLAGS, CLASS_IS_FINALIZABLE, art::kAccClassIsFinalizable) +// TODO: We should really have a BitPosition which also checks it's a power of 2. +DEFINE_FLAG_OFFSET(ACCESS_FLAGS, CLASS_IS_FINALIZABLE_BIT, art::MostSignificantBit(art::kAccClassIsFinalizable)) + +#undef DEFINE_FLAG_OFFSET diff --git a/tools/cpp-define-generator/constant_globals.def b/tools/cpp-define-generator/constant_globals.def new file mode 100644 index 0000000000..1e24d64dda --- /dev/null +++ b/tools/cpp-define-generator/constant_globals.def @@ -0,0 +1,30 @@ +/* + * 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. + */ + +// Export global values. + +#if defined(DEFINE_INCLUDE_DEPENDENCIES) +#include "globals.h" // art::kObjectAlignment +#endif + +#define DEFINE_OBJECT_EXPR(macro_name, type, constant_field_name) \ + DEFINE_EXPR(OBJECT_ ## macro_name, type, constant_field_name) + +DEFINE_OBJECT_EXPR(ALIGNMENT_MASK, size_t, art::kObjectAlignment - 1) +DEFINE_OBJECT_EXPR(ALIGNMENT_MASK_TOGGLED, uint32_t, ~static_cast<uint32_t>(art::kObjectAlignment - 1)) + +#undef DEFINE_OBJECT_EXPR + diff --git a/tools/cpp-define-generator/constant_jit.def b/tools/cpp-define-generator/constant_jit.def new file mode 100644 index 0000000000..5fa5194d00 --- /dev/null +++ b/tools/cpp-define-generator/constant_jit.def @@ -0,0 +1,29 @@ +/* + * 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. + */ + +// Constants within jit.h. + +#if defined(DEFINE_INCLUDE_DEPENDENCIES) +#include "jit/jit.h" // art::kSuspendRequest, etc. +#endif + +#define DEFINE_JIT_CONSTANT(macro_name, type, expr) \ + DEFINE_EXPR(JIT_ ## macro_name, type, (expr)) + +DEFINE_JIT_CONSTANT(CHECK_OSR, int16_t, art::jit::kJitCheckForOSR) +DEFINE_JIT_CONSTANT(HOTNESS_DISABLE, int16_t, art::jit::kJitHotnessDisabled) + +#undef DEFINE_JIT_CONSTANT diff --git a/tools/cpp-define-generator/constant_lockword.def b/tools/cpp-define-generator/constant_lockword.def new file mode 100644 index 0000000000..c1e6099121 --- /dev/null +++ b/tools/cpp-define-generator/constant_lockword.def @@ -0,0 +1,34 @@ +/* + * 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. + */ + +// Export lockword values. + +#if defined(DEFINE_INCLUDE_DEPENDENCIES) +#include "lock_word.h" // art::LockWord +#endif + +#define DEFINE_LOCK_WORD_EXPR(macro_name, type, constant_field_name) \ + DEFINE_EXPR(LOCK_WORD_ ## macro_name, type, art::LockWord::constant_field_name) + +DEFINE_LOCK_WORD_EXPR(STATE_SHIFT, int32_t, kStateShift) +DEFINE_LOCK_WORD_EXPR(STATE_MASK, uint32_t, kStateMaskShifted) +DEFINE_LOCK_WORD_EXPR(READ_BARRIER_STATE_SHIFT, int32_t, kReadBarrierStateShift) +DEFINE_LOCK_WORD_EXPR(READ_BARRIER_STATE_MASK, uint32_t, kReadBarrierStateMaskShifted) +DEFINE_LOCK_WORD_EXPR(READ_BARRIER_STATE_MASK_TOGGLED, uint32_t, kReadBarrierStateMaskShiftedToggled) +DEFINE_LOCK_WORD_EXPR(THIN_LOCK_COUNT_ONE, int32_t, kThinLockCountOne) + +#undef DEFINE_LOCK_WORD_EXPR + diff --git a/tools/cpp-define-generator/constant_reference.def b/tools/cpp-define-generator/constant_reference.def new file mode 100644 index 0000000000..d312f76e0a --- /dev/null +++ b/tools/cpp-define-generator/constant_reference.def @@ -0,0 +1,30 @@ +/* + * 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. + */ + +#if defined(DEFINE_INCLUDE_DEPENDENCIES) +#include "mirror/object.h" // mirror::Object +#include "stack.h" // StackReference +#include "mirror/object_reference.h" // mirror::CompressedReference +#include "base/bit_utils.h" // WhichPowerOf2 +#endif + +// Size of references to the heap on the stack. +DEFINE_EXPR(STACK_REFERENCE_SIZE, size_t, sizeof(art::StackReference<art::mirror::Object>)) +// Size of heap references +DEFINE_EXPR(COMPRESSED_REFERENCE_SIZE, size_t, sizeof(art::mirror::CompressedReference<art::mirror::Object>)) +DEFINE_EXPR(COMPRESSED_REFERENCE_SIZE_SHIFT, size_t, art::WhichPowerOf2(sizeof(art::mirror::CompressedReference<art::mirror::Object>))) + +#undef DEFINE_REFERENCE_OFFSET diff --git a/tools/cpp-define-generator/constant_rosalloc.def b/tools/cpp-define-generator/constant_rosalloc.def new file mode 100644 index 0000000000..2007cef5ad --- /dev/null +++ b/tools/cpp-define-generator/constant_rosalloc.def @@ -0,0 +1,40 @@ +/* + * 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. + */ + +// Constants within RosAlloc. + +#if defined(DEFINE_INCLUDE_DEPENDENCIES) +#include "gc/allocator/rosalloc.h" // art::gc::allocator::RosAlloc +#endif + +#define DEFINE_ROSALLOC_CONSTANT(macro_name, type, expr) \ + DEFINE_EXPR(ROSALLOC_ ## macro_name, type, (expr)) + +DEFINE_ROSALLOC_CONSTANT(MAX_THREAD_LOCAL_BRACKET_SIZE, int32_t, art::gc::allocator::RosAlloc::kMaxThreadLocalBracketSize) +DEFINE_ROSALLOC_CONSTANT(BRACKET_QUANTUM_SIZE_SHIFT, int32_t, art::gc::allocator::RosAlloc::kThreadLocalBracketQuantumSizeShift) +// TODO: This should be a BitUtils helper, e.g. BitMaskFromSize or something like that. +DEFINE_ROSALLOC_CONSTANT(BRACKET_QUANTUM_SIZE_MASK, int32_t, static_cast<int32_t>(art::gc::allocator::RosAlloc::kThreadLocalBracketQuantumSize - 1)) +DEFINE_ROSALLOC_CONSTANT(BRACKET_QUANTUM_SIZE_MASK_TOGGLED32,\ + uint32_t, ~static_cast<uint32_t>(art::gc::allocator::RosAlloc::kThreadLocalBracketQuantumSize - 1)) +DEFINE_ROSALLOC_CONSTANT(BRACKET_QUANTUM_SIZE_MASK_TOGGLED64,\ + uint64_t, ~static_cast<uint64_t>(art::gc::allocator::RosAlloc::kThreadLocalBracketQuantumSize - 1)) +DEFINE_ROSALLOC_CONSTANT(RUN_FREE_LIST_OFFSET, int32_t, art::gc::allocator::RosAlloc::RunFreeListOffset()) +DEFINE_ROSALLOC_CONSTANT(RUN_FREE_LIST_HEAD_OFFSET, int32_t, art::gc::allocator::RosAlloc::RunFreeListHeadOffset()) +DEFINE_ROSALLOC_CONSTANT(RUN_FREE_LIST_SIZE_OFFSET, int32_t, art::gc::allocator::RosAlloc::RunFreeListSizeOffset()) +DEFINE_ROSALLOC_CONSTANT(SLOT_NEXT_OFFSET, int32_t, art::gc::allocator::RosAlloc::RunSlotNextOffset()) + + +#undef DEFINE_ROSALLOC_CONSTANT diff --git a/tools/cpp-define-generator/constant_thread.def b/tools/cpp-define-generator/constant_thread.def new file mode 100644 index 0000000000..af5ca21f17 --- /dev/null +++ b/tools/cpp-define-generator/constant_thread.def @@ -0,0 +1,29 @@ +/* + * 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. + */ + +// Constants within thread.h. + +#if defined(DEFINE_INCLUDE_DEPENDENCIES) +#include "thread.h" // art::kSuspendRequest, etc. +#endif + +#define DEFINE_THREAD_CONSTANT(macro_name, type, expr) \ + DEFINE_EXPR(THREAD_ ## macro_name, type, (expr)) + +DEFINE_THREAD_CONSTANT(SUSPEND_REQUEST, int32_t, art::kSuspendRequest) +DEFINE_THREAD_CONSTANT(CHECKPOINT_REQUEST, int32_t, art::kCheckpointRequest) + +#undef DEFINE_THREAD_CONSTANT diff --git a/tools/cpp-define-generator/generate-asm-support b/tools/cpp-define-generator/generate-asm-support new file mode 100755 index 0000000000..f95648b2b7 --- /dev/null +++ b/tools/cpp-define-generator/generate-asm-support @@ -0,0 +1,8 @@ +#!/bin/bash + +# Generates asm_support_gen.h +# - This must be run after a build since it uses cpp-define-generator-data + +[[ -z ${ANDROID_BUILD_TOP+x} ]] && (echo "Run source build/envsetup.sh first" >&2 && exit 1) + +cpp-define-generator-datad > ${ANDROID_BUILD_TOP}/art/runtime/generated/asm_support_gen.h diff --git a/tools/cpp-define-generator/main.cc b/tools/cpp-define-generator/main.cc new file mode 100644 index 0000000000..a1b463a92d --- /dev/null +++ b/tools/cpp-define-generator/main.cc @@ -0,0 +1,114 @@ +/* + * 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. + */ + +#include <iostream> +#include <sstream> +#include <type_traits> +#include <ios> +#include <algorithm> +#include <string> + +// Art Offset file dependencies +#define DEFINE_INCLUDE_DEPENDENCIES +#include "offsets_all.def" + +std::string to_upper(std::string input) { + std::transform(input.begin(), input.end(), input.begin(), ::toupper); + return input; +} + +template <typename T, typename = void> +typename std::enable_if<!std::is_signed<T>::value, std::string>::type +pretty_format(T value) { + // Print most values as hex. + std::stringstream ss; + ss << std::showbase << std::hex << value; + return ss.str(); +} + +template <typename T, typename = void> +typename std::enable_if<std::is_signed<T>::value, std::string>::type +pretty_format(T value) { + // Print "signed" values as decimal so that the negativity doesn't get lost. + std::stringstream ss; + + // For negative values add a (). Omit it from positive values for conciseness. + if (value < 0) { + ss << "("; + } + + ss << value; + + if (value < 0) { + ss << ")"; + } + return ss.str(); +} + +template <typename T> +void cpp_define(std::string name, T value) { + std::cout << "#define " << name << " " << pretty_format(value) << std::endl; +} + +template <typename T> +void emit_check_eq(T value, std::string expr) { + std::cout << "DEFINE_CHECK_EQ(" << value << ", (" << expr << "))" << std::endl; +} + +const char *kFileHeader = /* // NOLINT [readability/multiline_string] [5] */ R"L1C3NS3( +/* + * 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_GENERATED_ASM_SUPPORT_GEN_H_ +#define ART_RUNTIME_GENERATED_ASM_SUPPORT_GEN_H_ + +// This file has been auto-generated by cpp-define-generator; do not edit directly. +)L1C3NS3"; // NOLINT [readability/multiline_string] [5] + +const char *kFileFooter = /* // NOLINT [readability/multiline_string] [5] */ R"F00T3R( +#endif // ART_RUNTIME_GENERATED_ASM_SUPPORT_GEN_H_ +)F00T3R"; // NOLINT [readability/multiline_string] [5] + +#define MACROIZE(holder_type, field_name) to_upper(#holder_type "_" #field_name "_OFFSET") + +int main() { + std::cout << kFileHeader << std::endl; + + std::string z = ""; + + // Print every constant expression to stdout as a #define or a CHECK_EQ +#define DEFINE_EXPR(macro_name, field_type, expr) \ + cpp_define(to_upper(#macro_name), static_cast<field_type>(expr)); \ + emit_check_eq(z + "static_cast<" #field_type ">(" + to_upper(#macro_name) + ")", \ + "static_cast<" #field_type ">(" #expr ")"); +#include "offsets_all.def" + + std::cout << kFileFooter << std::endl; + return 0; +} diff --git a/tools/cpp-define-generator/offset_codeitem.def b/tools/cpp-define-generator/offset_codeitem.def new file mode 100644 index 0000000000..e5acd1d93d --- /dev/null +++ b/tools/cpp-define-generator/offset_codeitem.def @@ -0,0 +1,33 @@ +/* + * 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. + */ + +// Offsets within CodeItem. + +#if defined(DEFINE_INCLUDE_DEPENDENCIES) +#include <cstddef> // offsetof +#include "dex_file.h" // art::DexFile +#endif + +#include "common.def" // DEFINE_OFFSET_EXPR + +#define DEFINE_CODEITEM_OFFSET(field_name) \ + DEFINE_OFFSET_EXPR(CodeItem, field_name, int32_t, offsetof(art::DexFile::CodeItem, field_name ## _)) + +// Field Name +DEFINE_CODEITEM_OFFSET(insns) + +#undef DEFINE_CODEITEM_OFFSET +#include "common_undef.def" // undef DEFINE_OFFSET_EXPR diff --git a/tools/cpp-define-generator/offset_dexcache.def b/tools/cpp-define-generator/offset_dexcache.def new file mode 100644 index 0000000000..ec4b248e5d --- /dev/null +++ b/tools/cpp-define-generator/offset_dexcache.def @@ -0,0 +1,33 @@ +/* + * 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. + */ + +// Offsets within art::ArtMethod. + +#if defined(DEFINE_INCLUDE_DEPENDENCIES) +#include "art_method.h" // art::ArtMethod +#endif + +#define DEFINE_ART_METHOD_OFFSET(field_name, method_name) \ + DEFINE_EXPR(ART_METHOD_ ## field_name ## _OFFSET_32, int32_t, art::ArtMethod::method_name##Offset(4).Int32Value()) \ + DEFINE_EXPR(ART_METHOD_ ## field_name ## _OFFSET_64, int32_t, art::ArtMethod::method_name##Offset(8).Int32Value()) + +// New macro suffix Method Name (of the Offset method) +DEFINE_ART_METHOD_OFFSET(DEX_CACHE_METHODS, DexCacheResolvedMethods) +DEFINE_ART_METHOD_OFFSET(DEX_CACHE_TYPES, DexCacheResolvedTypes) +DEFINE_ART_METHOD_OFFSET(JNI, EntryPointFromJni) +DEFINE_ART_METHOD_OFFSET(QUICK_CODE, EntryPointFromQuickCompiledCode) + +#undef DEFINE_ART_METHOD_OFFSET diff --git a/tools/cpp-define-generator/offset_mirror_object.def b/tools/cpp-define-generator/offset_mirror_object.def new file mode 100644 index 0000000000..9b99634e6e --- /dev/null +++ b/tools/cpp-define-generator/offset_mirror_object.def @@ -0,0 +1,33 @@ +/* + * 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. + */ + +// Offsets within java.lang.Object (mirror::Object). + +#if defined(DEFINE_INCLUDE_DEPENDENCIES) +#include "mirror/object.h" // art::mirror::Object +#endif + +#include "common.def" // DEFINE_OFFSET_EXPR + +#define DEFINE_MIRROR_OBJECT_OFFSET(field_name, method_name) \ + DEFINE_OFFSET_EXPR(MIRROR_OBJECT, field_name, int32_t, art::mirror::Object::method_name##Offset().Int32Value()) + +// New macro suffix Method Name (of the Offset method) +DEFINE_MIRROR_OBJECT_OFFSET(CLASS, Class) +DEFINE_MIRROR_OBJECT_OFFSET(LOCK_WORD, Monitor) + +#undef DEFINE_MIRROR_OBJECT_OFFSET +#include "common_undef.def" // undef DEFINE_OFFSET_EXPR diff --git a/tools/cpp-define-generator/offset_runtime.def b/tools/cpp-define-generator/offset_runtime.def new file mode 100644 index 0000000000..b327ca3a96 --- /dev/null +++ b/tools/cpp-define-generator/offset_runtime.def @@ -0,0 +1,39 @@ +/* + * 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. + */ + +// Offsets within ShadowFrame. + +#if defined(DEFINE_INCLUDE_DEPENDENCIES) +#include "runtime.h" // art::Runtime +#endif + +#include "common.def" // DEFINE_OFFSET_EXPR + +// Note: these callee save methods loads require read barriers. + +#define DEFINE_RUNTIME_CALLEE_SAVE_OFFSET(field_name, constant_name) \ + DEFINE_OFFSET_EXPR(Runtime, field_name ## _CALLEE_SAVE_FRAME, size_t, art::Runtime::GetCalleeSaveMethodOffset(art::Runtime:: constant_name)) + + // Macro substring Constant name +// Offset of field Runtime::callee_save_methods_[kSaveAll] +DEFINE_RUNTIME_CALLEE_SAVE_OFFSET(SAVE_ALL, kSaveAll) +// Offset of field Runtime::callee_save_methods_[kRefsOnly] +DEFINE_RUNTIME_CALLEE_SAVE_OFFSET(REFS_ONLY, kRefsOnly) +// Offset of field Runtime::callee_save_methods_[kRefsAndArgs] +DEFINE_RUNTIME_CALLEE_SAVE_OFFSET(REFS_AND_ARGS, kRefsAndArgs) + +#undef DEFINE_RUNTIME_CALLEE_SAVE_OFFSET +#include "common_undef.def" // undef DEFINE_OFFSET_EXPR diff --git a/tools/cpp-define-generator/offset_shadow_frame.def b/tools/cpp-define-generator/offset_shadow_frame.def new file mode 100644 index 0000000000..b49a3400d3 --- /dev/null +++ b/tools/cpp-define-generator/offset_shadow_frame.def @@ -0,0 +1,41 @@ +/* + * 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. + */ + +// Offsets within ShadowFrame. + +#if defined(DEFINE_INCLUDE_DEPENDENCIES) +#include "stack.h" // art::ShadowFrame +#endif + +#include "common.def" // DEFINE_OFFSET_EXPR + +#define DEFINE_SHADOW_FRAME_OFFSET(field_name, method_name) \ + DEFINE_OFFSET_EXPR(ShadowFrame, field_name, int32_t, art::ShadowFrame::method_name##Offset()) + +// New macro suffix Method Name (of the Offset method) +DEFINE_SHADOW_FRAME_OFFSET(LINK, Link) +DEFINE_SHADOW_FRAME_OFFSET(METHOD, Method) +DEFINE_SHADOW_FRAME_OFFSET(RESULT_REGISTER, ResultRegister) +DEFINE_SHADOW_FRAME_OFFSET(DEX_PC_PTR, DexPCPtr) +DEFINE_SHADOW_FRAME_OFFSET(CODE_ITEM, CodeItem) +DEFINE_SHADOW_FRAME_OFFSET(LOCK_COUNT_DATA, LockCountData) +DEFINE_SHADOW_FRAME_OFFSET(NUMBER_OF_VREGS, NumberOfVRegs) +DEFINE_SHADOW_FRAME_OFFSET(DEX_PC, DexPC) +DEFINE_SHADOW_FRAME_OFFSET(CACHED_HOTNESS_COUNTDOWN, CachedHotnessCountdown) +DEFINE_SHADOW_FRAME_OFFSET(VREGS, VRegs) + +#undef DEFINE_SHADOW_FRAME_OFFSET +#include "common_undef.def" // undef DEFINE_OFFSET_EXPR diff --git a/tools/cpp-define-generator/offset_thread.def b/tools/cpp-define-generator/offset_thread.def new file mode 100644 index 0000000000..71648e6cdb --- /dev/null +++ b/tools/cpp-define-generator/offset_thread.def @@ -0,0 +1,39 @@ +/* + * 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. + */ + +// Offsets within ShadowFrame. + +#if defined(DEFINE_INCLUDE_DEPENDENCIES) +#include "stack.h" // art::ShadowFrame +#endif + +#include "common.def" // DEFINE_OFFSET_EXPR + +#define DEFINE_THREAD_OFFSET(field_name, method_name) \ + DEFINE_OFFSET_EXPR(Thread, field_name, int32_t, art::Thread::method_name##Offset<sizeof(void*)>().Int32Value()) + +// New macro suffix Method Name (of the Offset method) +DEFINE_THREAD_OFFSET(FLAGS, ThreadFlags) +DEFINE_THREAD_OFFSET(ID, ThinLockId) +DEFINE_THREAD_OFFSET(IS_GC_MARKING, IsGcMarking) +DEFINE_THREAD_OFFSET(CARD_TABLE, CardTable) + +// TODO: The rest of the offsets +// are dependent on __SIZEOF_POINTER__ + +#undef DEFINE_THREAD_OFFSET + +#include "common_undef.def" // undef DEFINE_OFFSET_EXPR diff --git a/tools/cpp-define-generator/offsets_all.def b/tools/cpp-define-generator/offsets_all.def new file mode 100644 index 0000000000..01e4d5b0c4 --- /dev/null +++ b/tools/cpp-define-generator/offsets_all.def @@ -0,0 +1,65 @@ +/* + * 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. + */ + +// Includes every single offset file in art. +// Useful for processing every single offset together. + +// Usage: +// #define DEFINE_INCLUDE_DEPENDENCIES +// #include "offsets_all.def" +// to automatically include each def file's header dependencies. +// +// Afterwards, +// #define DEFINE_EXPR(define_name, field_type, expr) ... +// #include "offsets_all.def" +// to process each offset however one wants. +#if defined(DEFINE_INCLUDE_DEPENDENCIES) +#define DEFINE_EXPR(define_name, field_type, expr) +#endif + +#if !defined(DEFINE_EXPR) +#error "Either DEFINE_INCLUDE_DEPENDENCIES or DEFINE_EXPR must be defined" +#endif + +#include "constant_reference.def" +#include "offset_runtime.def" +// TODO: rest of THREAD_ offsets (depends on __SIZEOF__POINTER__). +#include "offset_thread.def" +// TODO: SHADOW_FRAME depends on __SIZEOF__POINTER__ +// #include "offset_shadow_frame.def" +#include "offset_codeitem.def" +// TODO: MIRROR_OBJECT_HEADER_SIZE (depends on #ifdef read barrier) +// TODO: MIRROR_CLASS offsets (see above) +#include "offset_mirror_object.def" +#include "constant_class.def" +// TODO: MIRROR_*_ARRAY offsets (depends on header size) +// TODO: MIRROR_STRING offsets (depends on header size) +#include "offset_dexcache.def" +#include "constant_lockword.def" +#include "constant_globals.def" +#include "constant_rosalloc.def" +#include "constant_thread.def" +#include "constant_jit.def" + +// TODO: MIRROR_OBJECT_HEADER_SIZE #ifdef depends on read barriers +// TODO: Array offsets (depends on MIRROR_OBJECT_HEADER_SIZE) + +#if defined(DEFINE_INCLUDE_DEPENDENCIES) +#undef DEFINE_EXPR +#undef DEFINE_INCLUDE_DEPENDENCIES +#endif + + |