blob: a35e05b87b6d0a52ca7f0aa584eea6ea5d6f425a [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)
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 Yamauchi800ac2d2014-04-02 17:32:54 -070028#include "read_barrier_c.h"
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -080029
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070030#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
50static 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
57ADD_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
62ADD_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__
67ADD_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__)
72ADD_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
77ADD_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
82ADD_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
87ADD_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__)
92ADD_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__))
97ADD_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__))
102ADD_TEST_EQ(THREAD_SELF_OFFSET,
103 art::Thread::SelfOffset<__SIZEOF_POINTER__>().Int32Value())
Ian Rogers4a510d82011-10-09 14:30:24 -0700104
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700105// Offsets within java.lang.Object.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700106#define MIRROR_OBJECT_CLASS_OFFSET 0
107ADD_TEST_EQ(MIRROR_OBJECT_CLASS_OFFSET, art::mirror::Object::ClassOffset().Int32Value())
108#define MIRROR_OBJECT_LOCK_WORD_OFFSET 4
109ADD_TEST_EQ(MIRROR_OBJECT_LOCK_WORD_OFFSET, art::mirror::Object::MonitorOffset().Int32Value())
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700110
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700111#if defined(USE_BAKER_OR_BROOKS_READ_BARRIER)
112#define MIRROR_OBJECT_HEADER_SIZE 16
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -0800113#else
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700114#define MIRROR_OBJECT_HEADER_SIZE 8
115#endif
116ADD_TEST_EQ(size_t(MIRROR_OBJECT_HEADER_SIZE), sizeof(art::mirror::Object))
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -0800117
118// Offsets within java.lang.Class.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700119#define MIRROR_CLASS_COMPONENT_TYPE_OFFSET (4 + MIRROR_OBJECT_HEADER_SIZE)
120ADD_TEST_EQ(MIRROR_CLASS_COMPONENT_TYPE_OFFSET,
121 art::mirror::Class::ComponentTypeOffset().Int32Value())
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -0800122
123// Array offsets.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700124#define MIRROR_ARRAY_LENGTH_OFFSET MIRROR_OBJECT_HEADER_SIZE
125ADD_TEST_EQ(MIRROR_ARRAY_LENGTH_OFFSET, art::mirror::Array::LengthOffset().Int32Value())
126
127#define MIRROR_CHAR_ARRAY_DATA_OFFSET (4 + MIRROR_OBJECT_HEADER_SIZE)
128ADD_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)
132ADD_TEST_EQ(MIRROR_OBJECT_ARRAY_DATA_OFFSET,
133 art::mirror::Array::DataOffset(
134 sizeof(art::mirror::HeapReference<art::mirror::Object>)).Int32Value())
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -0800135
136// Offsets within java.lang.String.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700137#define MIRROR_STRING_VALUE_OFFSET MIRROR_OBJECT_HEADER_SIZE
138ADD_TEST_EQ(MIRROR_STRING_VALUE_OFFSET, art::mirror::String::ValueOffset().Int32Value())
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -0800139
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700140#define MIRROR_STRING_COUNT_OFFSET (4 + MIRROR_OBJECT_HEADER_SIZE)
141ADD_TEST_EQ(MIRROR_STRING_COUNT_OFFSET, art::mirror::String::CountOffset().Int32Value())
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -0800142
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700143#define MIRROR_STRING_OFFSET_OFFSET (12 + MIRROR_OBJECT_HEADER_SIZE)
144ADD_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)
148ADD_TEST_EQ(MIRROR_ART_METHOD_DEX_CACHE_METHODS_OFFSET,
149 art::mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value())
150
Mathieu Chartiereace4582014-11-24 18:29:54 -0800151#define MIRROR_ART_METHOD_QUICK_CODE_OFFSET_32 (36 + MIRROR_OBJECT_HEADER_SIZE)
Mathieu Chartier2d721012014-11-10 11:08:06 -0800152ADD_TEST_EQ(MIRROR_ART_METHOD_QUICK_CODE_OFFSET_32,
153 art::mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(4).Int32Value())
154
Mathieu Chartier2d721012014-11-10 11:08:06 -0800155#define MIRROR_ART_METHOD_QUICK_CODE_OFFSET_64 (48 + MIRROR_OBJECT_HEADER_SIZE)
156ADD_TEST_EQ(MIRROR_ART_METHOD_QUICK_CODE_OFFSET_64,
157 art::mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(8).Int32Value())
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700158
159#if defined(__cplusplus)
160} // End of CheckAsmSupportOffsets.
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -0800161#endif
162
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700163#endif // ART_RUNTIME_ASM_SUPPORT_H_