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 */ 16 17 #ifndef ART_RUNTIME_ASM_SUPPORT_H_ 18 #define ART_RUNTIME_ASM_SUPPORT_H_ 19 20 #include "heap_poisoning.h" 21 #include "read_barrier_config.h" 22 23 // To generate tests related to the constants in this header, either define ADD_TEST_EQ before 24 // including, or use asm_support_check.h. 25 #ifndef ADD_TEST_EQ // Allow #include-r to replace with their own. 26 #define DEFINED_ADD_TEST_EQ 1 27 #define ADD_TEST_EQ(x, y) 28 #endif 29 30 #if defined(__LP64__) 31 #define POINTER_SIZE_SHIFT 3 32 #define POINTER_SIZE art::PointerSize::k64 33 #else 34 #define POINTER_SIZE_SHIFT 2 35 #define POINTER_SIZE art::PointerSize::k32 36 #endif 37 ADD_TEST_EQ(static_cast<size_t>(1U << POINTER_SIZE_SHIFT), 38 static_cast<size_t>(__SIZEOF_POINTER__)) 39 40 // Import platform-independent constant defines from our autogenerated list. 41 // Export new defines (for assembly use) by editing cpp-define-generator def files. 42 #define DEFINE_CHECK_EQ ADD_TEST_EQ 43 #include "asm_support_gen.h" 44 #undef DEFINE_CHECK_EQ 45 46 // Offset of field Thread::tlsPtr_.exception. 47 #define THREAD_EXCEPTION_OFFSET (THREAD_CARD_TABLE_OFFSET + __SIZEOF_POINTER__) 48 ADD_TEST_EQ(THREAD_EXCEPTION_OFFSET, 49 art::Thread::ExceptionOffset<POINTER_SIZE>().Int32Value()) 50 51 // Offset of field Thread::tlsPtr_.managed_stack.top_quick_frame_. 52 #define THREAD_TOP_QUICK_FRAME_OFFSET (THREAD_CARD_TABLE_OFFSET + (3 * __SIZEOF_POINTER__)) 53 ADD_TEST_EQ(THREAD_TOP_QUICK_FRAME_OFFSET, 54 art::Thread::TopOfManagedStackOffset<POINTER_SIZE>().Int32Value()) 55 56 // Offset of field Thread::tlsPtr_.self. 57 #define THREAD_SELF_OFFSET (THREAD_CARD_TABLE_OFFSET + (9 * __SIZEOF_POINTER__)) 58 ADD_TEST_EQ(THREAD_SELF_OFFSET, 59 art::Thread::SelfOffset<POINTER_SIZE>().Int32Value()) 60 61 // Offset of field Thread::tlsPtr_.thread_local_pos. 62 #define THREAD_LOCAL_POS_OFFSET (THREAD_CARD_TABLE_OFFSET + 34 * __SIZEOF_POINTER__) 63 ADD_TEST_EQ(THREAD_LOCAL_POS_OFFSET, 64 art::Thread::ThreadLocalPosOffset<POINTER_SIZE>().Int32Value()) 65 // Offset of field Thread::tlsPtr_.thread_local_end. 66 #define THREAD_LOCAL_END_OFFSET (THREAD_LOCAL_POS_OFFSET + __SIZEOF_POINTER__) 67 ADD_TEST_EQ(THREAD_LOCAL_END_OFFSET, 68 art::Thread::ThreadLocalEndOffset<POINTER_SIZE>().Int32Value()) 69 // Offset of field Thread::tlsPtr_.thread_local_objects. 70 #define THREAD_LOCAL_OBJECTS_OFFSET (THREAD_LOCAL_END_OFFSET + 2 * __SIZEOF_POINTER__) 71 ADD_TEST_EQ(THREAD_LOCAL_OBJECTS_OFFSET, 72 art::Thread::ThreadLocalObjectsOffset<POINTER_SIZE>().Int32Value()) 73 74 // Offset of field Thread::tlsPtr_.mterp_current_ibase. 75 #define THREAD_CURRENT_IBASE_OFFSET \ 76 (THREAD_LOCAL_OBJECTS_OFFSET + __SIZEOF_SIZE_T__ + (1 + 162) * __SIZEOF_POINTER__) 77 ADD_TEST_EQ(THREAD_CURRENT_IBASE_OFFSET, 78 art::Thread::MterpCurrentIBaseOffset<POINTER_SIZE>().Int32Value()) 79 // Offset of field Thread::tlsPtr_.mterp_default_ibase. 80 #define THREAD_DEFAULT_IBASE_OFFSET (THREAD_CURRENT_IBASE_OFFSET + __SIZEOF_POINTER__) 81 ADD_TEST_EQ(THREAD_DEFAULT_IBASE_OFFSET, 82 art::Thread::MterpDefaultIBaseOffset<POINTER_SIZE>().Int32Value()) 83 // Offset of field Thread::tlsPtr_.mterp_alt_ibase. 84 #define THREAD_ALT_IBASE_OFFSET (THREAD_DEFAULT_IBASE_OFFSET + __SIZEOF_POINTER__) 85 ADD_TEST_EQ(THREAD_ALT_IBASE_OFFSET, 86 art::Thread::MterpAltIBaseOffset<POINTER_SIZE>().Int32Value()) 87 // Offset of field Thread::tlsPtr_.rosalloc_runs. 88 #define THREAD_ROSALLOC_RUNS_OFFSET (THREAD_ALT_IBASE_OFFSET + __SIZEOF_POINTER__) 89 ADD_TEST_EQ(THREAD_ROSALLOC_RUNS_OFFSET, 90 art::Thread::RosAllocRunsOffset<POINTER_SIZE>().Int32Value()) 91 // Offset of field Thread::tlsPtr_.thread_local_alloc_stack_top. 92 #define THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET (THREAD_ROSALLOC_RUNS_OFFSET + 16 * __SIZEOF_POINTER__) 93 ADD_TEST_EQ(THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET, 94 art::Thread::ThreadLocalAllocStackTopOffset<POINTER_SIZE>().Int32Value()) 95 // Offset of field Thread::tlsPtr_.thread_local_alloc_stack_end. 96 #define THREAD_LOCAL_ALLOC_STACK_END_OFFSET (THREAD_ROSALLOC_RUNS_OFFSET + 17 * __SIZEOF_POINTER__) 97 ADD_TEST_EQ(THREAD_LOCAL_ALLOC_STACK_END_OFFSET, 98 art::Thread::ThreadLocalAllocStackEndOffset<POINTER_SIZE>().Int32Value()) 99 100 // Offsets within ShadowFrame. 101 #define SHADOWFRAME_LINK_OFFSET 0 102 ADD_TEST_EQ(SHADOWFRAME_LINK_OFFSET, 103 static_cast<int32_t>(art::ShadowFrame::LinkOffset())) 104 #define SHADOWFRAME_METHOD_OFFSET (SHADOWFRAME_LINK_OFFSET + 1 * __SIZEOF_POINTER__) 105 ADD_TEST_EQ(SHADOWFRAME_METHOD_OFFSET, 106 static_cast<int32_t>(art::ShadowFrame::MethodOffset())) 107 #define SHADOWFRAME_RESULT_REGISTER_OFFSET (SHADOWFRAME_LINK_OFFSET + 2 * __SIZEOF_POINTER__) 108 ADD_TEST_EQ(SHADOWFRAME_RESULT_REGISTER_OFFSET, 109 static_cast<int32_t>(art::ShadowFrame::ResultRegisterOffset())) 110 #define SHADOWFRAME_DEX_PC_PTR_OFFSET (SHADOWFRAME_LINK_OFFSET + 3 * __SIZEOF_POINTER__) 111 ADD_TEST_EQ(SHADOWFRAME_DEX_PC_PTR_OFFSET, 112 static_cast<int32_t>(art::ShadowFrame::DexPCPtrOffset())) 113 #define SHADOWFRAME_DEX_INSTRUCTIONS_OFFSET (SHADOWFRAME_LINK_OFFSET + 4 * __SIZEOF_POINTER__) 114 ADD_TEST_EQ(SHADOWFRAME_DEX_INSTRUCTIONS_OFFSET, 115 static_cast<int32_t>(art::ShadowFrame::DexInstructionsOffset())) 116 #define SHADOWFRAME_LOCK_COUNT_DATA_OFFSET (SHADOWFRAME_LINK_OFFSET + 5 * __SIZEOF_POINTER__) 117 ADD_TEST_EQ(SHADOWFRAME_LOCK_COUNT_DATA_OFFSET, 118 static_cast<int32_t>(art::ShadowFrame::LockCountDataOffset())) 119 #define SHADOWFRAME_NUMBER_OF_VREGS_OFFSET (SHADOWFRAME_LINK_OFFSET + 6 * __SIZEOF_POINTER__) 120 ADD_TEST_EQ(SHADOWFRAME_NUMBER_OF_VREGS_OFFSET, 121 static_cast<int32_t>(art::ShadowFrame::NumberOfVRegsOffset())) 122 #define SHADOWFRAME_DEX_PC_OFFSET (SHADOWFRAME_NUMBER_OF_VREGS_OFFSET + 4) 123 ADD_TEST_EQ(SHADOWFRAME_DEX_PC_OFFSET, 124 static_cast<int32_t>(art::ShadowFrame::DexPCOffset())) 125 #define SHADOWFRAME_CACHED_HOTNESS_COUNTDOWN_OFFSET (SHADOWFRAME_NUMBER_OF_VREGS_OFFSET + 8) 126 ADD_TEST_EQ(SHADOWFRAME_CACHED_HOTNESS_COUNTDOWN_OFFSET, 127 static_cast<int32_t>(art::ShadowFrame::CachedHotnessCountdownOffset())) 128 #define SHADOWFRAME_HOTNESS_COUNTDOWN_OFFSET (SHADOWFRAME_NUMBER_OF_VREGS_OFFSET + 10) 129 ADD_TEST_EQ(SHADOWFRAME_HOTNESS_COUNTDOWN_OFFSET, 130 static_cast<int32_t>(art::ShadowFrame::HotnessCountdownOffset())) 131 #define SHADOWFRAME_VREGS_OFFSET (SHADOWFRAME_NUMBER_OF_VREGS_OFFSET + 16) 132 ADD_TEST_EQ(SHADOWFRAME_VREGS_OFFSET, 133 static_cast<int32_t>(art::ShadowFrame::VRegsOffset())) 134 135 #if defined(USE_BROOKS_READ_BARRIER) 136 #define MIRROR_OBJECT_HEADER_SIZE 16 137 #else 138 #define MIRROR_OBJECT_HEADER_SIZE 8 139 #endif 140 ADD_TEST_EQ(size_t(MIRROR_OBJECT_HEADER_SIZE), sizeof(art::mirror::Object)) 141 142 // Offsets within java.lang.Class. 143 #define MIRROR_CLASS_COMPONENT_TYPE_OFFSET (4 + MIRROR_OBJECT_HEADER_SIZE) 144 ADD_TEST_EQ(MIRROR_CLASS_COMPONENT_TYPE_OFFSET, 145 art::mirror::Class::ComponentTypeOffset().Int32Value()) 146 #define MIRROR_CLASS_IF_TABLE_OFFSET (16 + MIRROR_OBJECT_HEADER_SIZE) 147 ADD_TEST_EQ(MIRROR_CLASS_IF_TABLE_OFFSET, 148 art::mirror::Class::IfTableOffset().Int32Value()) 149 #define MIRROR_CLASS_ACCESS_FLAGS_OFFSET (56 + MIRROR_OBJECT_HEADER_SIZE) 150 ADD_TEST_EQ(MIRROR_CLASS_ACCESS_FLAGS_OFFSET, 151 art::mirror::Class::AccessFlagsOffset().Int32Value()) 152 #define MIRROR_CLASS_OBJECT_SIZE_OFFSET (88 + MIRROR_OBJECT_HEADER_SIZE) 153 ADD_TEST_EQ(MIRROR_CLASS_OBJECT_SIZE_OFFSET, 154 art::mirror::Class::ObjectSizeOffset().Int32Value()) 155 #define MIRROR_CLASS_OBJECT_SIZE_ALLOC_FAST_PATH_OFFSET (92 + MIRROR_OBJECT_HEADER_SIZE) 156 ADD_TEST_EQ(MIRROR_CLASS_OBJECT_SIZE_ALLOC_FAST_PATH_OFFSET, 157 art::mirror::Class::ObjectSizeAllocFastPathOffset().Int32Value()) 158 #define MIRROR_CLASS_OBJECT_PRIMITIVE_TYPE_OFFSET (96 + MIRROR_OBJECT_HEADER_SIZE) 159 ADD_TEST_EQ(MIRROR_CLASS_OBJECT_PRIMITIVE_TYPE_OFFSET, 160 art::mirror::Class::PrimitiveTypeOffset().Int32Value()) 161 #define MIRROR_CLASS_STATUS_OFFSET (104 + MIRROR_OBJECT_HEADER_SIZE) 162 ADD_TEST_EQ(MIRROR_CLASS_STATUS_OFFSET, 163 art::mirror::Class::StatusOffset().Int32Value()) 164 165 #define PRIMITIVE_TYPE_SIZE_SHIFT_SHIFT 16 166 ADD_TEST_EQ(PRIMITIVE_TYPE_SIZE_SHIFT_SHIFT, 167 static_cast<int>(art::mirror::Class::kPrimitiveTypeSizeShiftShift)) 168 169 // Array offsets. 170 #define MIRROR_ARRAY_LENGTH_OFFSET MIRROR_OBJECT_HEADER_SIZE 171 ADD_TEST_EQ(MIRROR_ARRAY_LENGTH_OFFSET, art::mirror::Array::LengthOffset().Int32Value()) 172 173 #define MIRROR_CHAR_ARRAY_DATA_OFFSET (4 + MIRROR_OBJECT_HEADER_SIZE) 174 ADD_TEST_EQ(MIRROR_CHAR_ARRAY_DATA_OFFSET, 175 art::mirror::Array::DataOffset(sizeof(uint16_t)).Int32Value()) 176 177 #define MIRROR_BOOLEAN_ARRAY_DATA_OFFSET MIRROR_CHAR_ARRAY_DATA_OFFSET 178 ADD_TEST_EQ(MIRROR_BOOLEAN_ARRAY_DATA_OFFSET, 179 art::mirror::Array::DataOffset(sizeof(uint8_t)).Int32Value()) 180 181 #define MIRROR_BYTE_ARRAY_DATA_OFFSET MIRROR_CHAR_ARRAY_DATA_OFFSET 182 ADD_TEST_EQ(MIRROR_BYTE_ARRAY_DATA_OFFSET, 183 art::mirror::Array::DataOffset(sizeof(int8_t)).Int32Value()) 184 185 #define MIRROR_SHORT_ARRAY_DATA_OFFSET MIRROR_CHAR_ARRAY_DATA_OFFSET 186 ADD_TEST_EQ(MIRROR_SHORT_ARRAY_DATA_OFFSET, 187 art::mirror::Array::DataOffset(sizeof(int16_t)).Int32Value()) 188 189 #define MIRROR_INT_ARRAY_DATA_OFFSET MIRROR_CHAR_ARRAY_DATA_OFFSET 190 ADD_TEST_EQ(MIRROR_INT_ARRAY_DATA_OFFSET, 191 art::mirror::Array::DataOffset(sizeof(int32_t)).Int32Value()) 192 193 #define MIRROR_WIDE_ARRAY_DATA_OFFSET (8 + MIRROR_OBJECT_HEADER_SIZE) 194 ADD_TEST_EQ(MIRROR_WIDE_ARRAY_DATA_OFFSET, 195 art::mirror::Array::DataOffset(sizeof(uint64_t)).Int32Value()) 196 197 #define MIRROR_OBJECT_ARRAY_DATA_OFFSET (4 + MIRROR_OBJECT_HEADER_SIZE) 198 ADD_TEST_EQ(MIRROR_OBJECT_ARRAY_DATA_OFFSET, 199 art::mirror::Array::DataOffset( 200 sizeof(art::mirror::HeapReference<art::mirror::Object>)).Int32Value()) 201 202 #define MIRROR_OBJECT_ARRAY_COMPONENT_SIZE 4 203 ADD_TEST_EQ(static_cast<size_t>(MIRROR_OBJECT_ARRAY_COMPONENT_SIZE), 204 sizeof(art::mirror::HeapReference<art::mirror::Object>)) 205 206 #define MIRROR_LONG_ARRAY_DATA_OFFSET (8 + MIRROR_OBJECT_HEADER_SIZE) 207 ADD_TEST_EQ(MIRROR_LONG_ARRAY_DATA_OFFSET, 208 art::mirror::Array::DataOffset(sizeof(uint64_t)).Int32Value()) 209 210 // Offsets within java.lang.String. 211 #define MIRROR_STRING_COUNT_OFFSET MIRROR_OBJECT_HEADER_SIZE 212 ADD_TEST_EQ(MIRROR_STRING_COUNT_OFFSET, art::mirror::String::CountOffset().Int32Value()) 213 214 #define MIRROR_STRING_VALUE_OFFSET (8 + MIRROR_OBJECT_HEADER_SIZE) 215 ADD_TEST_EQ(MIRROR_STRING_VALUE_OFFSET, art::mirror::String::ValueOffset().Int32Value()) 216 217 // String compression feature. 218 #define STRING_COMPRESSION_FEATURE 1 219 ADD_TEST_EQ(STRING_COMPRESSION_FEATURE, art::mirror::kUseStringCompression); 220 221 #ifdef DEFINED_ADD_TEST_EQ 222 #undef ADD_TEST_EQ 223 #undef DEFINED_ADD_TEST_EQ 224 #endif 225 226 #endif // ART_RUNTIME_ASM_SUPPORT_H_ 227