Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Ian Rogers | 9651f42 | 2011-09-19 20:26:07 -0700 | [diff] [blame] | 16 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_ASM_SUPPORT_H_ |
| 18 | #define ART_RUNTIME_ASM_SUPPORT_H_ |
Ian Rogers | 9651f42 | 2011-09-19 20:26:07 -0700 | [diff] [blame] | 19 | |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 20 | #if defined(__cplusplus) |
| 21 | #include "mirror/art_method.h" |
| 22 | #include "mirror/class.h" |
| 23 | #include "mirror/string.h" |
| 24 | #include "runtime.h" |
| 25 | #include "thread.h" |
| 26 | #endif |
| 27 | |
Hiroshi Yamauchi | 800ac2d | 2014-04-02 17:32:54 -0700 | [diff] [blame] | 28 | #include "read_barrier_c.h" |
Hiroshi Yamauchi | 9d04a20 | 2014-01-31 13:35:49 -0800 | [diff] [blame] | 29 | |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 30 | #if defined(__arm__) || defined(__aarch64__) || defined(__mips__) |
| 31 | // In quick code for ARM, ARM64 and MIPS we make poor use of registers and perform frequent suspend |
| 32 | // checks in the event of loop back edges. The SUSPEND_CHECK_INTERVAL constant is loaded into a |
| 33 | // register at the point of an up-call or after handling a suspend check. It reduces the number of |
| 34 | // loads of the TLS suspend check value by the given amount (turning it into a decrement and compare |
| 35 | // of a register). This increases the time for a thread to respond to requests from GC and the |
| 36 | // debugger, damaging GC performance and creating other unwanted artifacts. For example, this count |
| 37 | // has the effect of making loops and Java code look cold in profilers, where the count is reset |
| 38 | // impacts where samples will occur. Reducing the count as much as possible improves profiler |
| 39 | // accuracy in tools like traceview. |
| 40 | // TODO: get a compiler that can do a proper job of loop optimization and remove this. |
| 41 | #define SUSPEND_CHECK_INTERVAL 1000 |
| 42 | #endif |
| 43 | |
| 44 | #if defined(__cplusplus) |
| 45 | |
| 46 | #ifndef ADD_TEST_EQ // Allow #include-r to replace with their own. |
| 47 | #define ADD_TEST_EQ(x, y) CHECK_EQ(x, y); |
| 48 | #endif |
| 49 | |
| 50 | static inline void CheckAsmSupportOffsetsAndSizes() { |
| 51 | #else |
| 52 | #define ADD_TEST_EQ(x, y) |
| 53 | #endif |
| 54 | |
| 55 | // Size of references to the heap on the stack. |
| 56 | #define STACK_REFERENCE_SIZE 4 |
| 57 | ADD_TEST_EQ(static_cast<size_t>(STACK_REFERENCE_SIZE), sizeof(art::StackReference<art::mirror::Object>)) |
| 58 | |
| 59 | // Note: these callee save methods loads require read barriers. |
| 60 | // Offset of field Runtime::callee_save_methods_[kSaveAll] |
| 61 | #define RUNTIME_SAVE_ALL_CALLEE_SAVE_FRAME_OFFSET 0 |
| 62 | ADD_TEST_EQ(static_cast<size_t>(RUNTIME_SAVE_ALL_CALLEE_SAVE_FRAME_OFFSET), |
| 63 | art::Runtime::GetCalleeSaveMethodOffset(art::Runtime::kSaveAll)) |
| 64 | |
| 65 | // Offset of field Runtime::callee_save_methods_[kRefsOnly] |
| 66 | #define RUNTIME_REFS_ONLY_CALLEE_SAVE_FRAME_OFFSET __SIZEOF_POINTER__ |
| 67 | ADD_TEST_EQ(static_cast<size_t>(RUNTIME_REFS_ONLY_CALLEE_SAVE_FRAME_OFFSET), |
| 68 | art::Runtime::GetCalleeSaveMethodOffset(art::Runtime::kRefsOnly)) |
| 69 | |
| 70 | // Offset of field Runtime::callee_save_methods_[kRefsAndArgs] |
| 71 | #define RUNTIME_REFS_AND_ARGS_CALLEE_SAVE_FRAME_OFFSET (2 * __SIZEOF_POINTER__) |
| 72 | ADD_TEST_EQ(static_cast<size_t>(RUNTIME_REFS_AND_ARGS_CALLEE_SAVE_FRAME_OFFSET), |
| 73 | art::Runtime::GetCalleeSaveMethodOffset(art::Runtime::kRefsAndArgs)) |
| 74 | |
| 75 | // Offset of field Thread::tls32_.state_and_flags. |
| 76 | #define THREAD_FLAGS_OFFSET 0 |
| 77 | ADD_TEST_EQ(THREAD_FLAGS_OFFSET, |
| 78 | art::Thread::ThreadFlagsOffset<__SIZEOF_POINTER__>().Int32Value()) |
| 79 | |
| 80 | // Offset of field Thread::tls32_.thin_lock_thread_id. |
| 81 | #define THREAD_ID_OFFSET 12 |
| 82 | ADD_TEST_EQ(THREAD_ID_OFFSET, |
| 83 | art::Thread::ThinLockIdOffset<__SIZEOF_POINTER__>().Int32Value()) |
| 84 | |
| 85 | // Offset of field Thread::tlsPtr_.card_table. |
| 86 | #define THREAD_CARD_TABLE_OFFSET 120 |
| 87 | ADD_TEST_EQ(THREAD_CARD_TABLE_OFFSET, |
| 88 | art::Thread::CardTableOffset<__SIZEOF_POINTER__>().Int32Value()) |
| 89 | |
| 90 | // Offset of field Thread::tlsPtr_.exception. |
| 91 | #define THREAD_EXCEPTION_OFFSET (THREAD_CARD_TABLE_OFFSET + __SIZEOF_POINTER__) |
| 92 | ADD_TEST_EQ(THREAD_EXCEPTION_OFFSET, |
| 93 | art::Thread::ExceptionOffset<__SIZEOF_POINTER__>().Int32Value()) |
| 94 | |
| 95 | // Offset of field Thread::tlsPtr_.managed_stack.top_quick_frame_. |
| 96 | #define THREAD_TOP_QUICK_FRAME_OFFSET (THREAD_CARD_TABLE_OFFSET + (3 * __SIZEOF_POINTER__)) |
| 97 | ADD_TEST_EQ(THREAD_TOP_QUICK_FRAME_OFFSET, |
| 98 | art::Thread::TopOfManagedStackOffset<__SIZEOF_POINTER__>().Int32Value()) |
| 99 | |
| 100 | // Offset of field Thread::tlsPtr_.managed_stack.top_quick_frame_. |
| 101 | #define THREAD_SELF_OFFSET (THREAD_CARD_TABLE_OFFSET + (8 * __SIZEOF_POINTER__)) |
| 102 | ADD_TEST_EQ(THREAD_SELF_OFFSET, |
| 103 | art::Thread::SelfOffset<__SIZEOF_POINTER__>().Int32Value()) |
Ian Rogers | 4a510d8 | 2011-10-09 14:30:24 -0700 | [diff] [blame] | 104 | |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 105 | // Offsets within java.lang.Object. |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 106 | #define MIRROR_OBJECT_CLASS_OFFSET 0 |
| 107 | ADD_TEST_EQ(MIRROR_OBJECT_CLASS_OFFSET, art::mirror::Object::ClassOffset().Int32Value()) |
| 108 | #define MIRROR_OBJECT_LOCK_WORD_OFFSET 4 |
| 109 | ADD_TEST_EQ(MIRROR_OBJECT_LOCK_WORD_OFFSET, art::mirror::Object::MonitorOffset().Int32Value()) |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 110 | |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 111 | #if defined(USE_BAKER_OR_BROOKS_READ_BARRIER) |
| 112 | #define MIRROR_OBJECT_HEADER_SIZE 16 |
Hiroshi Yamauchi | 9d04a20 | 2014-01-31 13:35:49 -0800 | [diff] [blame] | 113 | #else |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 114 | #define MIRROR_OBJECT_HEADER_SIZE 8 |
| 115 | #endif |
| 116 | ADD_TEST_EQ(size_t(MIRROR_OBJECT_HEADER_SIZE), sizeof(art::mirror::Object)) |
Hiroshi Yamauchi | 9d04a20 | 2014-01-31 13:35:49 -0800 | [diff] [blame] | 117 | |
| 118 | // Offsets within java.lang.Class. |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 119 | #define MIRROR_CLASS_COMPONENT_TYPE_OFFSET (4 + MIRROR_OBJECT_HEADER_SIZE) |
| 120 | ADD_TEST_EQ(MIRROR_CLASS_COMPONENT_TYPE_OFFSET, |
| 121 | art::mirror::Class::ComponentTypeOffset().Int32Value()) |
Hiroshi Yamauchi | 9d04a20 | 2014-01-31 13:35:49 -0800 | [diff] [blame] | 122 | |
| 123 | // Array offsets. |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 124 | #define MIRROR_ARRAY_LENGTH_OFFSET MIRROR_OBJECT_HEADER_SIZE |
| 125 | ADD_TEST_EQ(MIRROR_ARRAY_LENGTH_OFFSET, art::mirror::Array::LengthOffset().Int32Value()) |
| 126 | |
| 127 | #define MIRROR_CHAR_ARRAY_DATA_OFFSET (4 + MIRROR_OBJECT_HEADER_SIZE) |
| 128 | ADD_TEST_EQ(MIRROR_CHAR_ARRAY_DATA_OFFSET, |
| 129 | art::mirror::Array::DataOffset(sizeof(uint16_t)).Int32Value()) |
| 130 | |
| 131 | #define MIRROR_OBJECT_ARRAY_DATA_OFFSET (4 + MIRROR_OBJECT_HEADER_SIZE) |
| 132 | ADD_TEST_EQ(MIRROR_OBJECT_ARRAY_DATA_OFFSET, |
| 133 | art::mirror::Array::DataOffset( |
| 134 | sizeof(art::mirror::HeapReference<art::mirror::Object>)).Int32Value()) |
Hiroshi Yamauchi | 9d04a20 | 2014-01-31 13:35:49 -0800 | [diff] [blame] | 135 | |
| 136 | // Offsets within java.lang.String. |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 137 | #define MIRROR_STRING_VALUE_OFFSET MIRROR_OBJECT_HEADER_SIZE |
| 138 | ADD_TEST_EQ(MIRROR_STRING_VALUE_OFFSET, art::mirror::String::ValueOffset().Int32Value()) |
Hiroshi Yamauchi | 9d04a20 | 2014-01-31 13:35:49 -0800 | [diff] [blame] | 139 | |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 140 | #define MIRROR_STRING_COUNT_OFFSET (4 + MIRROR_OBJECT_HEADER_SIZE) |
| 141 | ADD_TEST_EQ(MIRROR_STRING_COUNT_OFFSET, art::mirror::String::CountOffset().Int32Value()) |
Hiroshi Yamauchi | 9d04a20 | 2014-01-31 13:35:49 -0800 | [diff] [blame] | 142 | |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 143 | #define MIRROR_STRING_OFFSET_OFFSET (12 + MIRROR_OBJECT_HEADER_SIZE) |
| 144 | ADD_TEST_EQ(MIRROR_STRING_OFFSET_OFFSET, art::mirror::String::OffsetOffset().Int32Value()) |
| 145 | |
| 146 | // Offsets within java.lang.reflect.ArtMethod. |
| 147 | #define MIRROR_ART_METHOD_DEX_CACHE_METHODS_OFFSET (4 + MIRROR_OBJECT_HEADER_SIZE) |
| 148 | ADD_TEST_EQ(MIRROR_ART_METHOD_DEX_CACHE_METHODS_OFFSET, |
| 149 | art::mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value()) |
| 150 | |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 151 | #define MIRROR_ART_METHOD_QUICK_CODE_OFFSET_32 (36 + MIRROR_OBJECT_HEADER_SIZE) |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 152 | ADD_TEST_EQ(MIRROR_ART_METHOD_QUICK_CODE_OFFSET_32, |
| 153 | art::mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(4).Int32Value()) |
| 154 | |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 155 | #define MIRROR_ART_METHOD_QUICK_CODE_OFFSET_64 (48 + MIRROR_OBJECT_HEADER_SIZE) |
| 156 | ADD_TEST_EQ(MIRROR_ART_METHOD_QUICK_CODE_OFFSET_64, |
| 157 | art::mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(8).Int32Value()) |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 158 | |
| 159 | #if defined(__cplusplus) |
| 160 | } // End of CheckAsmSupportOffsets. |
Hiroshi Yamauchi | 9d04a20 | 2014-01-31 13:35:49 -0800 | [diff] [blame] | 161 | #endif |
| 162 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 163 | #endif // ART_RUNTIME_ASM_SUPPORT_H_ |