diff options
Diffstat (limited to 'tools/cpp-define-generator')
19 files changed, 706 insertions, 0 deletions
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 + + |