blob: 31610a3d71fa6286afcc0839b99c4a1f82dd10da [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
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 Rogers9651f422011-09-19 20:26:07 -070016
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_RUNTIME_ASM_SUPPORT_H_
18#define ART_RUNTIME_ASM_SUPPORT_H_
Ian Rogers9651f422011-09-19 20:26:07 -070019
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070020#if defined(__cplusplus)
Mathieu Chartiere401d142015-04-22 13:56:20 -070021#include "art_method.h"
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -070022#include "gc/allocator/rosalloc.h"
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -080023#include "lock_word.h"
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070024#include "mirror/class.h"
25#include "mirror/string.h"
26#include "runtime.h"
27#include "thread.h"
28#endif
29
Hiroshi Yamauchi800ac2d2014-04-02 17:32:54 -070030#include "read_barrier_c.h"
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -080031
Zheng Xu69a50302015-04-14 20:04:41 +080032#if defined(__arm__) || defined(__mips__)
33// In quick code for ARM and MIPS we make poor use of registers and perform frequent suspend
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070034// checks in the event of loop back edges. The SUSPEND_CHECK_INTERVAL constant is loaded into a
35// register at the point of an up-call or after handling a suspend check. It reduces the number of
36// loads of the TLS suspend check value by the given amount (turning it into a decrement and compare
37// of a register). This increases the time for a thread to respond to requests from GC and the
38// debugger, damaging GC performance and creating other unwanted artifacts. For example, this count
39// has the effect of making loops and Java code look cold in profilers, where the count is reset
40// impacts where samples will occur. Reducing the count as much as possible improves profiler
41// accuracy in tools like traceview.
42// TODO: get a compiler that can do a proper job of loop optimization and remove this.
buzbee72be1cd2014-11-11 22:48:59 -080043#define SUSPEND_CHECK_INTERVAL 96
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070044#endif
45
46#if defined(__cplusplus)
47
48#ifndef ADD_TEST_EQ // Allow #include-r to replace with their own.
49#define ADD_TEST_EQ(x, y) CHECK_EQ(x, y);
50#endif
51
52static inline void CheckAsmSupportOffsetsAndSizes() {
53#else
54#define ADD_TEST_EQ(x, y)
55#endif
56
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -070057#if defined(__LP64__)
58#define POINTER_SIZE_SHIFT 3
59#else
60#define POINTER_SIZE_SHIFT 2
61#endif
62ADD_TEST_EQ(static_cast<size_t>(1U << POINTER_SIZE_SHIFT),
63 static_cast<size_t>(__SIZEOF_POINTER__))
64
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070065// Size of references to the heap on the stack.
66#define STACK_REFERENCE_SIZE 4
67ADD_TEST_EQ(static_cast<size_t>(STACK_REFERENCE_SIZE), sizeof(art::StackReference<art::mirror::Object>))
68
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -070069// Size of heap references
70#define COMPRESSED_REFERENCE_SIZE 4
71ADD_TEST_EQ(static_cast<size_t>(COMPRESSED_REFERENCE_SIZE),
72 sizeof(art::mirror::CompressedReference<art::mirror::Object>))
73
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -070074#define COMPRESSED_REFERENCE_SIZE_SHIFT 2
75ADD_TEST_EQ(static_cast<size_t>(1U << COMPRESSED_REFERENCE_SIZE_SHIFT),
76 static_cast<size_t>(COMPRESSED_REFERENCE_SIZE))
77
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070078// Note: these callee save methods loads require read barriers.
79// Offset of field Runtime::callee_save_methods_[kSaveAll]
80#define RUNTIME_SAVE_ALL_CALLEE_SAVE_FRAME_OFFSET 0
81ADD_TEST_EQ(static_cast<size_t>(RUNTIME_SAVE_ALL_CALLEE_SAVE_FRAME_OFFSET),
82 art::Runtime::GetCalleeSaveMethodOffset(art::Runtime::kSaveAll))
83
84// Offset of field Runtime::callee_save_methods_[kRefsOnly]
Mathieu Chartiere401d142015-04-22 13:56:20 -070085#define RUNTIME_REFS_ONLY_CALLEE_SAVE_FRAME_OFFSET 8
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070086ADD_TEST_EQ(static_cast<size_t>(RUNTIME_REFS_ONLY_CALLEE_SAVE_FRAME_OFFSET),
87 art::Runtime::GetCalleeSaveMethodOffset(art::Runtime::kRefsOnly))
88
89// Offset of field Runtime::callee_save_methods_[kRefsAndArgs]
Mathieu Chartiere401d142015-04-22 13:56:20 -070090#define RUNTIME_REFS_AND_ARGS_CALLEE_SAVE_FRAME_OFFSET (2 * 8)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070091ADD_TEST_EQ(static_cast<size_t>(RUNTIME_REFS_AND_ARGS_CALLEE_SAVE_FRAME_OFFSET),
92 art::Runtime::GetCalleeSaveMethodOffset(art::Runtime::kRefsAndArgs))
93
94// Offset of field Thread::tls32_.state_and_flags.
95#define THREAD_FLAGS_OFFSET 0
96ADD_TEST_EQ(THREAD_FLAGS_OFFSET,
97 art::Thread::ThreadFlagsOffset<__SIZEOF_POINTER__>().Int32Value())
98
99// Offset of field Thread::tls32_.thin_lock_thread_id.
100#define THREAD_ID_OFFSET 12
101ADD_TEST_EQ(THREAD_ID_OFFSET,
102 art::Thread::ThinLockIdOffset<__SIZEOF_POINTER__>().Int32Value())
103
104// Offset of field Thread::tlsPtr_.card_table.
Sebastien Hertz07474662015-08-25 15:12:33 +0000105#define THREAD_CARD_TABLE_OFFSET 128
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700106ADD_TEST_EQ(THREAD_CARD_TABLE_OFFSET,
107 art::Thread::CardTableOffset<__SIZEOF_POINTER__>().Int32Value())
108
109// Offset of field Thread::tlsPtr_.exception.
110#define THREAD_EXCEPTION_OFFSET (THREAD_CARD_TABLE_OFFSET + __SIZEOF_POINTER__)
111ADD_TEST_EQ(THREAD_EXCEPTION_OFFSET,
112 art::Thread::ExceptionOffset<__SIZEOF_POINTER__>().Int32Value())
113
114// Offset of field Thread::tlsPtr_.managed_stack.top_quick_frame_.
115#define THREAD_TOP_QUICK_FRAME_OFFSET (THREAD_CARD_TABLE_OFFSET + (3 * __SIZEOF_POINTER__))
116ADD_TEST_EQ(THREAD_TOP_QUICK_FRAME_OFFSET,
117 art::Thread::TopOfManagedStackOffset<__SIZEOF_POINTER__>().Int32Value())
118
Roland Levillainca80ecc2015-07-22 17:19:28 +0100119// Offset of field Thread::tlsPtr_.self.
Andreas Gampe449357d2015-06-01 22:29:51 -0700120#define THREAD_SELF_OFFSET (THREAD_CARD_TABLE_OFFSET + (9 * __SIZEOF_POINTER__))
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700121ADD_TEST_EQ(THREAD_SELF_OFFSET,
122 art::Thread::SelfOffset<__SIZEOF_POINTER__>().Int32Value())
Ian Rogers4a510d82011-10-09 14:30:24 -0700123
Roland Levillainca80ecc2015-07-22 17:19:28 +0100124// Offset of field Thread::tlsPtr_.thread_local_pos.
Roland Levillain7c1559a2015-12-15 10:55:36 +0000125#define THREAD_LOCAL_POS_OFFSET (THREAD_CARD_TABLE_OFFSET + 169 * __SIZEOF_POINTER__)
Hiroshi Yamauchie01a5202015-03-19 12:35:04 -0700126ADD_TEST_EQ(THREAD_LOCAL_POS_OFFSET,
127 art::Thread::ThreadLocalPosOffset<__SIZEOF_POINTER__>().Int32Value())
Roland Levillainca80ecc2015-07-22 17:19:28 +0100128// Offset of field Thread::tlsPtr_.thread_local_end.
Hiroshi Yamauchie01a5202015-03-19 12:35:04 -0700129#define THREAD_LOCAL_END_OFFSET (THREAD_LOCAL_POS_OFFSET + __SIZEOF_POINTER__)
130ADD_TEST_EQ(THREAD_LOCAL_END_OFFSET,
131 art::Thread::ThreadLocalEndOffset<__SIZEOF_POINTER__>().Int32Value())
Roland Levillainca80ecc2015-07-22 17:19:28 +0100132// Offset of field Thread::tlsPtr_.thread_local_objects.
Hiroshi Yamauchie01a5202015-03-19 12:35:04 -0700133#define THREAD_LOCAL_OBJECTS_OFFSET (THREAD_LOCAL_POS_OFFSET + 2 * __SIZEOF_POINTER__)
134ADD_TEST_EQ(THREAD_LOCAL_OBJECTS_OFFSET,
135 art::Thread::ThreadLocalObjectsOffset<__SIZEOF_POINTER__>().Int32Value())
buzbee1452bee2015-03-06 14:43:04 -0800136// Offset of field Thread::tlsPtr_.mterp_current_ibase.
137#define THREAD_CURRENT_IBASE_OFFSET (THREAD_LOCAL_POS_OFFSET + 3 * __SIZEOF_POINTER__)
138ADD_TEST_EQ(THREAD_CURRENT_IBASE_OFFSET,
139 art::Thread::MterpCurrentIBaseOffset<__SIZEOF_POINTER__>().Int32Value())
140// Offset of field Thread::tlsPtr_.mterp_default_ibase.
141#define THREAD_DEFAULT_IBASE_OFFSET (THREAD_LOCAL_POS_OFFSET + 4 * __SIZEOF_POINTER__)
142ADD_TEST_EQ(THREAD_DEFAULT_IBASE_OFFSET,
143 art::Thread::MterpDefaultIBaseOffset<__SIZEOF_POINTER__>().Int32Value())
144// Offset of field Thread::tlsPtr_.mterp_alt_ibase.
145#define THREAD_ALT_IBASE_OFFSET (THREAD_LOCAL_POS_OFFSET + 5 * __SIZEOF_POINTER__)
146ADD_TEST_EQ(THREAD_ALT_IBASE_OFFSET,
147 art::Thread::MterpAltIBaseOffset<__SIZEOF_POINTER__>().Int32Value())
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -0700148// Offset of field Thread::tlsPtr_.rosalloc_runs.
buzbee1452bee2015-03-06 14:43:04 -0800149#define THREAD_ROSALLOC_RUNS_OFFSET (THREAD_LOCAL_POS_OFFSET + 6 * __SIZEOF_POINTER__)
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -0700150ADD_TEST_EQ(THREAD_ROSALLOC_RUNS_OFFSET,
151 art::Thread::RosAllocRunsOffset<__SIZEOF_POINTER__>().Int32Value())
152// Offset of field Thread::tlsPtr_.thread_local_alloc_stack_top.
153#define THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET (THREAD_ROSALLOC_RUNS_OFFSET + 34 * __SIZEOF_POINTER__)
154ADD_TEST_EQ(THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET,
155 art::Thread::ThreadLocalAllocStackTopOffset<__SIZEOF_POINTER__>().Int32Value())
156// Offset of field Thread::tlsPtr_.thread_local_alloc_stack_end.
157#define THREAD_LOCAL_ALLOC_STACK_END_OFFSET (THREAD_ROSALLOC_RUNS_OFFSET + 35 * __SIZEOF_POINTER__)
158ADD_TEST_EQ(THREAD_LOCAL_ALLOC_STACK_END_OFFSET,
159 art::Thread::ThreadLocalAllocStackEndOffset<__SIZEOF_POINTER__>().Int32Value())
Hiroshi Yamauchie01a5202015-03-19 12:35:04 -0700160
buzbee1452bee2015-03-06 14:43:04 -0800161// Offsets within ShadowFrame.
162#define SHADOWFRAME_LINK_OFFSET 0
163ADD_TEST_EQ(SHADOWFRAME_LINK_OFFSET,
164 static_cast<int32_t>(art::ShadowFrame::LinkOffset()))
165#define SHADOWFRAME_METHOD_OFFSET (SHADOWFRAME_LINK_OFFSET + 1 * __SIZEOF_POINTER__)
166ADD_TEST_EQ(SHADOWFRAME_METHOD_OFFSET,
167 static_cast<int32_t>(art::ShadowFrame::MethodOffset()))
168#define SHADOWFRAME_RESULT_REGISTER_OFFSET (SHADOWFRAME_LINK_OFFSET + 2 * __SIZEOF_POINTER__)
169ADD_TEST_EQ(SHADOWFRAME_RESULT_REGISTER_OFFSET,
170 static_cast<int32_t>(art::ShadowFrame::ResultRegisterOffset()))
171#define SHADOWFRAME_DEX_PC_PTR_OFFSET (SHADOWFRAME_LINK_OFFSET + 3 * __SIZEOF_POINTER__)
172ADD_TEST_EQ(SHADOWFRAME_DEX_PC_PTR_OFFSET,
173 static_cast<int32_t>(art::ShadowFrame::DexPCPtrOffset()))
174#define SHADOWFRAME_CODE_ITEM_OFFSET (SHADOWFRAME_LINK_OFFSET + 4 * __SIZEOF_POINTER__)
175ADD_TEST_EQ(SHADOWFRAME_CODE_ITEM_OFFSET,
176 static_cast<int32_t>(art::ShadowFrame::CodeItemOffset()))
177#define SHADOWFRAME_LOCK_COUNT_DATA_OFFSET (SHADOWFRAME_LINK_OFFSET + 5 * __SIZEOF_POINTER__)
178ADD_TEST_EQ(SHADOWFRAME_LOCK_COUNT_DATA_OFFSET,
179 static_cast<int32_t>(art::ShadowFrame::LockCountDataOffset()))
180#define SHADOWFRAME_NUMBER_OF_VREGS_OFFSET (SHADOWFRAME_LINK_OFFSET + 6 * __SIZEOF_POINTER__)
181ADD_TEST_EQ(SHADOWFRAME_NUMBER_OF_VREGS_OFFSET,
182 static_cast<int32_t>(art::ShadowFrame::NumberOfVRegsOffset()))
183#define SHADOWFRAME_DEX_PC_OFFSET (SHADOWFRAME_NUMBER_OF_VREGS_OFFSET + 4)
184ADD_TEST_EQ(SHADOWFRAME_DEX_PC_OFFSET,
185 static_cast<int32_t>(art::ShadowFrame::DexPCOffset()))
186#define SHADOWFRAME_VREGS_OFFSET (SHADOWFRAME_NUMBER_OF_VREGS_OFFSET + 8)
187ADD_TEST_EQ(SHADOWFRAME_VREGS_OFFSET,
188 static_cast<int32_t>(art::ShadowFrame::VRegsOffset()))
189
190// Offsets within CodeItem
191#define CODEITEM_INSNS_OFFSET 16
192ADD_TEST_EQ(CODEITEM_INSNS_OFFSET,
193 static_cast<int32_t>(OFFSETOF_MEMBER(art::DexFile::CodeItem, insns_)))
194
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700195// Offsets within java.lang.Object.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700196#define MIRROR_OBJECT_CLASS_OFFSET 0
197ADD_TEST_EQ(MIRROR_OBJECT_CLASS_OFFSET, art::mirror::Object::ClassOffset().Int32Value())
198#define MIRROR_OBJECT_LOCK_WORD_OFFSET 4
199ADD_TEST_EQ(MIRROR_OBJECT_LOCK_WORD_OFFSET, art::mirror::Object::MonitorOffset().Int32Value())
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700200
Hiroshi Yamauchi60f63f52015-04-23 16:12:40 -0700201#if defined(USE_BROOKS_READ_BARRIER)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700202#define MIRROR_OBJECT_HEADER_SIZE 16
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -0800203#else
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700204#define MIRROR_OBJECT_HEADER_SIZE 8
205#endif
206ADD_TEST_EQ(size_t(MIRROR_OBJECT_HEADER_SIZE), sizeof(art::mirror::Object))
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -0800207
208// Offsets within java.lang.Class.
Narayan Kamathd1ef4362015-11-12 11:49:06 +0000209#define MIRROR_CLASS_COMPONENT_TYPE_OFFSET (8 + MIRROR_OBJECT_HEADER_SIZE)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700210ADD_TEST_EQ(MIRROR_CLASS_COMPONENT_TYPE_OFFSET,
211 art::mirror::Class::ComponentTypeOffset().Int32Value())
Przemyslaw Szczepaniak121b25e2015-11-20 11:24:33 +0000212#define MIRROR_CLASS_ACCESS_FLAGS_OFFSET (36 + MIRROR_OBJECT_HEADER_SIZE)
Hiroshi Yamauchie01a5202015-03-19 12:35:04 -0700213ADD_TEST_EQ(MIRROR_CLASS_ACCESS_FLAGS_OFFSET,
214 art::mirror::Class::AccessFlagsOffset().Int32Value())
Alex Light9c557292015-12-17 15:48:01 -0800215#define MIRROR_CLASS_OBJECT_SIZE_OFFSET (100 + MIRROR_OBJECT_HEADER_SIZE)
Hiroshi Yamauchie01a5202015-03-19 12:35:04 -0700216ADD_TEST_EQ(MIRROR_CLASS_OBJECT_SIZE_OFFSET,
217 art::mirror::Class::ObjectSizeOffset().Int32Value())
Alex Light9c557292015-12-17 15:48:01 -0800218#define MIRROR_CLASS_STATUS_OFFSET (112 + MIRROR_OBJECT_HEADER_SIZE)
Hiroshi Yamauchie01a5202015-03-19 12:35:04 -0700219ADD_TEST_EQ(MIRROR_CLASS_STATUS_OFFSET,
220 art::mirror::Class::StatusOffset().Int32Value())
221
222#define MIRROR_CLASS_STATUS_INITIALIZED 10
223ADD_TEST_EQ(static_cast<uint32_t>(MIRROR_CLASS_STATUS_INITIALIZED),
224 static_cast<uint32_t>(art::mirror::Class::kStatusInitialized))
225#define ACCESS_FLAGS_CLASS_IS_FINALIZABLE 0x80000000
226ADD_TEST_EQ(static_cast<uint32_t>(ACCESS_FLAGS_CLASS_IS_FINALIZABLE),
Mathieu Chartier52a7f5c2015-08-18 18:35:52 -0700227 static_cast<uint32_t>(art::kAccClassIsFinalizable))
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -0800228
229// Array offsets.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700230#define MIRROR_ARRAY_LENGTH_OFFSET MIRROR_OBJECT_HEADER_SIZE
231ADD_TEST_EQ(MIRROR_ARRAY_LENGTH_OFFSET, art::mirror::Array::LengthOffset().Int32Value())
232
233#define MIRROR_CHAR_ARRAY_DATA_OFFSET (4 + MIRROR_OBJECT_HEADER_SIZE)
234ADD_TEST_EQ(MIRROR_CHAR_ARRAY_DATA_OFFSET,
235 art::mirror::Array::DataOffset(sizeof(uint16_t)).Int32Value())
236
buzbee1452bee2015-03-06 14:43:04 -0800237#define MIRROR_BOOLEAN_ARRAY_DATA_OFFSET MIRROR_CHAR_ARRAY_DATA_OFFSET
238ADD_TEST_EQ(MIRROR_BOOLEAN_ARRAY_DATA_OFFSET,
239 art::mirror::Array::DataOffset(sizeof(uint8_t)).Int32Value())
240
241#define MIRROR_BYTE_ARRAY_DATA_OFFSET MIRROR_CHAR_ARRAY_DATA_OFFSET
242ADD_TEST_EQ(MIRROR_BYTE_ARRAY_DATA_OFFSET,
243 art::mirror::Array::DataOffset(sizeof(int8_t)).Int32Value())
244
245#define MIRROR_SHORT_ARRAY_DATA_OFFSET MIRROR_CHAR_ARRAY_DATA_OFFSET
246ADD_TEST_EQ(MIRROR_SHORT_ARRAY_DATA_OFFSET,
247 art::mirror::Array::DataOffset(sizeof(int16_t)).Int32Value())
248
249#define MIRROR_INT_ARRAY_DATA_OFFSET MIRROR_CHAR_ARRAY_DATA_OFFSET
250ADD_TEST_EQ(MIRROR_INT_ARRAY_DATA_OFFSET,
251 art::mirror::Array::DataOffset(sizeof(int32_t)).Int32Value())
252
253#define MIRROR_WIDE_ARRAY_DATA_OFFSET (8 + MIRROR_OBJECT_HEADER_SIZE)
254ADD_TEST_EQ(MIRROR_WIDE_ARRAY_DATA_OFFSET,
255 art::mirror::Array::DataOffset(sizeof(uint64_t)).Int32Value())
256
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700257#define MIRROR_OBJECT_ARRAY_DATA_OFFSET (4 + MIRROR_OBJECT_HEADER_SIZE)
258ADD_TEST_EQ(MIRROR_OBJECT_ARRAY_DATA_OFFSET,
259 art::mirror::Array::DataOffset(
260 sizeof(art::mirror::HeapReference<art::mirror::Object>)).Int32Value())
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -0800261
Hiroshi Yamauchie01a5202015-03-19 12:35:04 -0700262#define MIRROR_OBJECT_ARRAY_COMPONENT_SIZE 4
263ADD_TEST_EQ(static_cast<size_t>(MIRROR_OBJECT_ARRAY_COMPONENT_SIZE),
264 sizeof(art::mirror::HeapReference<art::mirror::Object>))
265
Mathieu Chartiere401d142015-04-22 13:56:20 -0700266#define MIRROR_LONG_ARRAY_DATA_OFFSET (8 + MIRROR_OBJECT_HEADER_SIZE)
267ADD_TEST_EQ(MIRROR_LONG_ARRAY_DATA_OFFSET,
268 art::mirror::Array::DataOffset(sizeof(uint64_t)).Int32Value())
269
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -0800270// Offsets within java.lang.String.
Jeff Hao848f70a2014-01-15 13:49:50 -0800271#define MIRROR_STRING_COUNT_OFFSET MIRROR_OBJECT_HEADER_SIZE
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700272ADD_TEST_EQ(MIRROR_STRING_COUNT_OFFSET, art::mirror::String::CountOffset().Int32Value())
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -0800273
Jeff Hao848f70a2014-01-15 13:49:50 -0800274#define MIRROR_STRING_VALUE_OFFSET (8 + MIRROR_OBJECT_HEADER_SIZE)
275ADD_TEST_EQ(MIRROR_STRING_VALUE_OFFSET, art::mirror::String::ValueOffset().Int32Value())
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700276
277// Offsets within java.lang.reflect.ArtMethod.
Vladimir Marko05792b92015-08-03 11:56:49 +0100278#define ART_METHOD_DEX_CACHE_METHODS_OFFSET_32 20
279ADD_TEST_EQ(ART_METHOD_DEX_CACHE_METHODS_OFFSET_32,
280 art::ArtMethod::DexCacheResolvedMethodsOffset(4).Int32Value())
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700281
Vladimir Marko05792b92015-08-03 11:56:49 +0100282#define ART_METHOD_DEX_CACHE_METHODS_OFFSET_64 24
283ADD_TEST_EQ(ART_METHOD_DEX_CACHE_METHODS_OFFSET_64,
284 art::ArtMethod::DexCacheResolvedMethodsOffset(8).Int32Value())
285
286#define ART_METHOD_DEX_CACHE_TYPES_OFFSET_32 24
287ADD_TEST_EQ(ART_METHOD_DEX_CACHE_TYPES_OFFSET_32,
288 art::ArtMethod::DexCacheResolvedTypesOffset(4).Int32Value())
289
290#define ART_METHOD_DEX_CACHE_TYPES_OFFSET_64 32
291ADD_TEST_EQ(ART_METHOD_DEX_CACHE_TYPES_OFFSET_64,
292 art::ArtMethod::DexCacheResolvedTypesOffset(8).Int32Value())
Hiroshi Yamauchie01a5202015-03-19 12:35:04 -0700293
Nicolas Geoffray7bf2b4f2015-07-08 10:11:59 +0000294#define ART_METHOD_QUICK_CODE_OFFSET_32 32
Mathieu Chartiere401d142015-04-22 13:56:20 -0700295ADD_TEST_EQ(ART_METHOD_QUICK_CODE_OFFSET_32,
296 art::ArtMethod::EntryPointFromQuickCompiledCodeOffset(4).Int32Value())
Mathieu Chartier2d721012014-11-10 11:08:06 -0800297
Vladimir Marko05792b92015-08-03 11:56:49 +0100298#define ART_METHOD_QUICK_CODE_OFFSET_64 48
Mathieu Chartiere401d142015-04-22 13:56:20 -0700299ADD_TEST_EQ(ART_METHOD_QUICK_CODE_OFFSET_64,
300 art::ArtMethod::EntryPointFromQuickCompiledCodeOffset(8).Int32Value())
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700301
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800302#define LOCK_WORD_STATE_SHIFT 30
303ADD_TEST_EQ(LOCK_WORD_STATE_SHIFT, static_cast<int32_t>(art::LockWord::kStateShift))
304
305#define LOCK_WORD_STATE_MASK 0xC0000000
306ADD_TEST_EQ(LOCK_WORD_STATE_MASK, static_cast<uint32_t>(art::LockWord::kStateMaskShifted))
307
308#define LOCK_WORD_READ_BARRIER_STATE_SHIFT 28
309ADD_TEST_EQ(LOCK_WORD_READ_BARRIER_STATE_SHIFT,
310 static_cast<int32_t>(art::LockWord::kReadBarrierStateShift))
311
312#define LOCK_WORD_READ_BARRIER_STATE_MASK 0x30000000
313ADD_TEST_EQ(LOCK_WORD_READ_BARRIER_STATE_MASK,
314 static_cast<int32_t>(art::LockWord::kReadBarrierStateMaskShifted))
315
316#define LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED 0xCFFFFFFF
317ADD_TEST_EQ(LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED,
318 static_cast<uint32_t>(art::LockWord::kReadBarrierStateMaskShiftedToggled))
319
320#define LOCK_WORD_THIN_LOCK_COUNT_ONE 65536
321ADD_TEST_EQ(LOCK_WORD_THIN_LOCK_COUNT_ONE, static_cast<int32_t>(art::LockWord::kThinLockCountOne))
322
Hiroshi Yamauchie01a5202015-03-19 12:35:04 -0700323#define OBJECT_ALIGNMENT_MASK 7
324ADD_TEST_EQ(static_cast<size_t>(OBJECT_ALIGNMENT_MASK), art::kObjectAlignment - 1)
325
326#define OBJECT_ALIGNMENT_MASK_TOGGLED 0xFFFFFFF8
327ADD_TEST_EQ(static_cast<uint32_t>(OBJECT_ALIGNMENT_MASK_TOGGLED),
328 ~static_cast<uint32_t>(art::kObjectAlignment - 1))
329
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -0700330#define ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE 128
331ADD_TEST_EQ(ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE,
332 static_cast<int32_t>(art::gc::allocator::RosAlloc::kMaxThreadLocalBracketSize))
333
334#define ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT 4
335ADD_TEST_EQ(ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT,
336 static_cast<int32_t>(art::gc::allocator::RosAlloc::kBracketQuantumSizeShift))
337
338#define ROSALLOC_BRACKET_QUANTUM_SIZE_MASK 15
339ADD_TEST_EQ(ROSALLOC_BRACKET_QUANTUM_SIZE_MASK,
340 static_cast<int32_t>(art::gc::allocator::RosAlloc::kBracketQuantumSize - 1))
341
342#define ROSALLOC_BRACKET_QUANTUM_SIZE_MASK_TOGGLED32 0xfffffff0
343ADD_TEST_EQ(static_cast<uint32_t>(ROSALLOC_BRACKET_QUANTUM_SIZE_MASK_TOGGLED32),
344 ~static_cast<uint32_t>(art::gc::allocator::RosAlloc::kBracketQuantumSize - 1))
345
346#define ROSALLOC_BRACKET_QUANTUM_SIZE_MASK_TOGGLED64 0xfffffffffffffff0
347ADD_TEST_EQ(static_cast<uint64_t>(ROSALLOC_BRACKET_QUANTUM_SIZE_MASK_TOGGLED64),
348 ~static_cast<uint64_t>(art::gc::allocator::RosAlloc::kBracketQuantumSize - 1))
349
350#define ROSALLOC_RUN_FREE_LIST_OFFSET 8
351ADD_TEST_EQ(ROSALLOC_RUN_FREE_LIST_OFFSET,
352 static_cast<int32_t>(art::gc::allocator::RosAlloc::RunFreeListOffset()))
353
354#define ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET 0
355ADD_TEST_EQ(ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET,
356 static_cast<int32_t>(art::gc::allocator::RosAlloc::RunFreeListHeadOffset()))
357
358#define ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET 16
359ADD_TEST_EQ(ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET,
360 static_cast<int32_t>(art::gc::allocator::RosAlloc::RunFreeListSizeOffset()))
361
362#define ROSALLOC_SLOT_NEXT_OFFSET 0
363ADD_TEST_EQ(ROSALLOC_SLOT_NEXT_OFFSET,
364 static_cast<int32_t>(art::gc::allocator::RosAlloc::RunSlotNextOffset()))
365// Assert this so that we can avoid zeroing the next field by installing the class pointer.
366ADD_TEST_EQ(ROSALLOC_SLOT_NEXT_OFFSET, MIRROR_OBJECT_CLASS_OFFSET)
367
buzbee1452bee2015-03-06 14:43:04 -0800368#define THREAD_SUSPEND_REQUEST 1
369ADD_TEST_EQ(THREAD_SUSPEND_REQUEST, static_cast<int32_t>(art::kSuspendRequest))
370
371#define THREAD_CHECKPOINT_REQUEST 2
372ADD_TEST_EQ(THREAD_CHECKPOINT_REQUEST, static_cast<int32_t>(art::kCheckpointRequest))
373
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700374#if defined(__cplusplus)
375} // End of CheckAsmSupportOffsets.
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -0800376#endif
377
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700378#endif // ART_RUNTIME_ASM_SUPPORT_H_