blob: 397655a8950914d058122b335368cd149281b547 [file] [log] [blame]
Ian Rogers57b86d42012-03-27 16:05:41 -07001/*
2 * Copyright (C) 2012 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
Mathieu Chartierd8891782014-03-02 13:28:37 -080017#include "entrypoints/quick/quick_alloc_entrypoints.h"
18
Mathieu Chartiere401d142015-04-22 13:56:20 -070019#include "art_method-inl.h"
Andreas Gampe542451c2016-07-26 09:02:02 -070020#include "base/enums.h"
Ian Rogers57b86d42012-03-27 16:05:41 -070021#include "callee_save_frame.h"
Andreas Gampea5b09a62016-11-17 15:21:22 -080022#include "dex_file_types.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070023#include "entrypoints/entrypoint_utils-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080024#include "mirror/class-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080025#include "mirror/object_array-inl.h"
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070026#include "mirror/object-inl.h"
Ian Rogers57b86d42012-03-27 16:05:41 -070027
28namespace art {
29
Hiroshi Yamauchieb1e9292014-08-06 12:41:15 -070030static constexpr bool kUseTlabFastPath = true;
31
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080032#define GENERATE_ENTRYPOINTS_FOR_ALLOCATOR_INST(suffix, suffix2, instrumented_bool, allocator_type) \
33extern "C" mirror::Object* artAllocObjectFromCode ##suffix##suffix2( \
Mathieu Chartiere401d142015-04-22 13:56:20 -070034 uint32_t type_idx, ArtMethod* method, Thread* self) \
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070035 REQUIRES_SHARED(Locks::mutator_lock_) { \
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070036 ScopedQuickEntrypointChecks sqec(self); \
Chih-Hung Hsiehfba39972016-05-11 11:26:48 -070037 if (kUseTlabFastPath && !(instrumented_bool) && (allocator_type) == gc::kAllocatorTypeTLAB) { \
Andreas Gampea5b09a62016-11-17 15:21:22 -080038 mirror::Class* klass = method->GetDexCacheResolvedType<false>(dex::TypeIndex(type_idx), \
39 kRuntimePointerSize); \
Hiroshi Yamauchieb1e9292014-08-06 12:41:15 -070040 if (LIKELY(klass != nullptr && klass->IsInitialized() && !klass->IsFinalizable())) { \
41 size_t byte_count = klass->GetObjectSize(); \
42 byte_count = RoundUp(byte_count, gc::space::BumpPointerSpace::kAlignment); \
43 mirror::Object* obj; \
44 if (LIKELY(byte_count < self->TlabSize())) { \
45 obj = self->AllocTlab(byte_count); \
46 DCHECK(obj != nullptr) << "AllocTlab can't fail"; \
47 obj->SetClass(klass); \
Hiroshi Yamauchi12b58b22016-11-01 11:55:29 -070048 if (kUseBakerReadBarrier) { \
49 obj->AssertReadBarrierState(); \
Hiroshi Yamauchieb1e9292014-08-06 12:41:15 -070050 } \
51 QuasiAtomic::ThreadFenceForConstructor(); \
52 return obj; \
53 } \
54 } \
55 } \
Andreas Gampea5b09a62016-11-17 15:21:22 -080056 return AllocObjectFromCode<false, instrumented_bool>(dex::TypeIndex(type_idx), \
57 method, \
58 self, \
59 allocator_type); \
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080060} \
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080061extern "C" mirror::Object* artAllocObjectFromCodeResolved##suffix##suffix2( \
Roland Levillain4b8f1ec2015-08-26 18:34:03 +010062 mirror::Class* klass, ArtMethod* method ATTRIBUTE_UNUSED, Thread* self) \
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070063 REQUIRES_SHARED(Locks::mutator_lock_) { \
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070064 ScopedQuickEntrypointChecks sqec(self); \
Chih-Hung Hsiehfba39972016-05-11 11:26:48 -070065 if (kUseTlabFastPath && !(instrumented_bool) && (allocator_type) == gc::kAllocatorTypeTLAB) { \
Hiroshi Yamauchieb1e9292014-08-06 12:41:15 -070066 if (LIKELY(klass->IsInitialized())) { \
67 size_t byte_count = klass->GetObjectSize(); \
68 byte_count = RoundUp(byte_count, gc::space::BumpPointerSpace::kAlignment); \
69 mirror::Object* obj; \
70 if (LIKELY(byte_count < self->TlabSize())) { \
71 obj = self->AllocTlab(byte_count); \
72 DCHECK(obj != nullptr) << "AllocTlab can't fail"; \
73 obj->SetClass(klass); \
Hiroshi Yamauchi12b58b22016-11-01 11:55:29 -070074 if (kUseBakerReadBarrier) { \
75 obj->AssertReadBarrierState(); \
Hiroshi Yamauchieb1e9292014-08-06 12:41:15 -070076 } \
77 QuasiAtomic::ThreadFenceForConstructor(); \
78 return obj; \
79 } \
80 } \
81 } \
Ian Rogers6a3c1fc2014-10-31 00:33:20 -070082 return AllocObjectFromCodeResolved<instrumented_bool>(klass, self, allocator_type); \
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080083} \
84extern "C" mirror::Object* artAllocObjectFromCodeInitialized##suffix##suffix2( \
Roland Levillain4b8f1ec2015-08-26 18:34:03 +010085 mirror::Class* klass, ArtMethod* method ATTRIBUTE_UNUSED, Thread* self) \
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070086 REQUIRES_SHARED(Locks::mutator_lock_) { \
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070087 ScopedQuickEntrypointChecks sqec(self); \
Chih-Hung Hsiehfba39972016-05-11 11:26:48 -070088 if (kUseTlabFastPath && !(instrumented_bool) && (allocator_type) == gc::kAllocatorTypeTLAB) { \
Hiroshi Yamauchieb1e9292014-08-06 12:41:15 -070089 size_t byte_count = klass->GetObjectSize(); \
90 byte_count = RoundUp(byte_count, gc::space::BumpPointerSpace::kAlignment); \
91 mirror::Object* obj; \
92 if (LIKELY(byte_count < self->TlabSize())) { \
93 obj = self->AllocTlab(byte_count); \
94 DCHECK(obj != nullptr) << "AllocTlab can't fail"; \
95 obj->SetClass(klass); \
Hiroshi Yamauchi12b58b22016-11-01 11:55:29 -070096 if (kUseBakerReadBarrier) { \
97 obj->AssertReadBarrierState(); \
Hiroshi Yamauchieb1e9292014-08-06 12:41:15 -070098 } \
99 QuasiAtomic::ThreadFenceForConstructor(); \
100 return obj; \
101 } \
102 } \
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700103 return AllocObjectFromCodeInitialized<instrumented_bool>(klass, self, allocator_type); \
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -0800104} \
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800105extern "C" mirror::Object* artAllocObjectFromCodeWithAccessCheck##suffix##suffix2( \
Mathieu Chartiere401d142015-04-22 13:56:20 -0700106 uint32_t type_idx, ArtMethod* method, Thread* self) \
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700107 REQUIRES_SHARED(Locks::mutator_lock_) { \
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700108 ScopedQuickEntrypointChecks sqec(self); \
Andreas Gampea5b09a62016-11-17 15:21:22 -0800109 return AllocObjectFromCode<true, instrumented_bool>(dex::TypeIndex(type_idx), \
110 method, \
111 self, \
112 allocator_type); \
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800113} \
114extern "C" mirror::Array* artAllocArrayFromCode##suffix##suffix2( \
Mathieu Chartiere401d142015-04-22 13:56:20 -0700115 uint32_t type_idx, int32_t component_count, ArtMethod* method, Thread* self) \
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700116 REQUIRES_SHARED(Locks::mutator_lock_) { \
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700117 ScopedQuickEntrypointChecks sqec(self); \
Andreas Gampea5b09a62016-11-17 15:21:22 -0800118 return AllocArrayFromCode<false, instrumented_bool>(dex::TypeIndex(type_idx), \
119 component_count, \
120 method, \
121 self, \
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800122 allocator_type); \
123} \
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800124extern "C" mirror::Array* artAllocArrayFromCodeResolved##suffix##suffix2( \
Mathieu Chartiere401d142015-04-22 13:56:20 -0700125 mirror::Class* klass, int32_t component_count, ArtMethod* method, Thread* self) \
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700126 REQUIRES_SHARED(Locks::mutator_lock_) { \
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700127 ScopedQuickEntrypointChecks sqec(self); \
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800128 return AllocArrayFromCodeResolved<false, instrumented_bool>(klass, component_count, method, self, \
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800129 allocator_type); \
130} \
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800131extern "C" mirror::Array* artAllocArrayFromCodeWithAccessCheck##suffix##suffix2( \
Mathieu Chartiere401d142015-04-22 13:56:20 -0700132 uint32_t type_idx, int32_t component_count, ArtMethod* method, Thread* self) \
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700133 REQUIRES_SHARED(Locks::mutator_lock_) { \
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700134 ScopedQuickEntrypointChecks sqec(self); \
Andreas Gampea5b09a62016-11-17 15:21:22 -0800135 return AllocArrayFromCode<true, instrumented_bool>(dex::TypeIndex(type_idx), \
136 component_count, \
137 method, \
138 self, \
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800139 allocator_type); \
140} \
141extern "C" mirror::Array* artCheckAndAllocArrayFromCode##suffix##suffix2( \
Mathieu Chartiere401d142015-04-22 13:56:20 -0700142 uint32_t type_idx, int32_t component_count, ArtMethod* method, Thread* self) \
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700143 REQUIRES_SHARED(Locks::mutator_lock_) { \
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700144 ScopedQuickEntrypointChecks sqec(self); \
Chih-Hung Hsiehfba39972016-05-11 11:26:48 -0700145 if (!(instrumented_bool)) { \
Andreas Gampea5b09a62016-11-17 15:21:22 -0800146 return CheckAndAllocArrayFromCode(dex::TypeIndex(type_idx), \
147 component_count, \
148 method, \
149 self, \
150 false, \
151 allocator_type); \
Hiroshi Yamauchicbbb0802013-11-21 12:42:36 -0800152 } else { \
Andreas Gampea5b09a62016-11-17 15:21:22 -0800153 return CheckAndAllocArrayFromCodeInstrumented(dex::TypeIndex(type_idx), \
154 component_count, \
155 method, \
156 self, \
157 false, \
158 allocator_type); \
Hiroshi Yamauchicbbb0802013-11-21 12:42:36 -0800159 } \
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800160} \
161extern "C" mirror::Array* artCheckAndAllocArrayFromCodeWithAccessCheck##suffix##suffix2( \
Mathieu Chartiere401d142015-04-22 13:56:20 -0700162 uint32_t type_idx, int32_t component_count, ArtMethod* method, Thread* self) \
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700163 REQUIRES_SHARED(Locks::mutator_lock_) { \
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700164 ScopedQuickEntrypointChecks sqec(self); \
Chih-Hung Hsiehfba39972016-05-11 11:26:48 -0700165 if (!(instrumented_bool)) { \
Andreas Gampea5b09a62016-11-17 15:21:22 -0800166 return CheckAndAllocArrayFromCode(dex::TypeIndex(type_idx), \
167 component_count, \
168 method, \
169 self, \
170 true, \
171 allocator_type); \
Hiroshi Yamauchicbbb0802013-11-21 12:42:36 -0800172 } else { \
Andreas Gampea5b09a62016-11-17 15:21:22 -0800173 return CheckAndAllocArrayFromCodeInstrumented(dex::TypeIndex(type_idx), \
174 component_count, \
175 method, \
176 self, \
177 true, \
178 allocator_type); \
Hiroshi Yamauchicbbb0802013-11-21 12:42:36 -0800179 } \
Jeff Hao848f70a2014-01-15 13:49:50 -0800180} \
181extern "C" mirror::String* artAllocStringFromBytesFromCode##suffix##suffix2( \
182 mirror::ByteArray* byte_array, int32_t high, int32_t offset, int32_t byte_count, \
183 Thread* self) \
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700184 REQUIRES_SHARED(Locks::mutator_lock_) { \
Jeff Hao848f70a2014-01-15 13:49:50 -0800185 ScopedQuickEntrypointChecks sqec(self); \
186 StackHandleScope<1> hs(self); \
187 Handle<mirror::ByteArray> handle_array(hs.NewHandle(byte_array)); \
188 return mirror::String::AllocFromByteArray<instrumented_bool>(self, byte_count, handle_array, \
189 offset, high, allocator_type); \
190} \
191extern "C" mirror::String* artAllocStringFromCharsFromCode##suffix##suffix2( \
192 int32_t offset, int32_t char_count, mirror::CharArray* char_array, Thread* self) \
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700193 REQUIRES_SHARED(Locks::mutator_lock_) { \
Jeff Hao848f70a2014-01-15 13:49:50 -0800194 StackHandleScope<1> hs(self); \
195 Handle<mirror::CharArray> handle_array(hs.NewHandle(char_array)); \
196 return mirror::String::AllocFromCharArray<instrumented_bool>(self, char_count, handle_array, \
197 offset, allocator_type); \
198} \
Chih-Hung Hsiehfba39972016-05-11 11:26:48 -0700199extern "C" mirror::String* artAllocStringFromStringFromCode##suffix##suffix2( /* NOLINT */ \
Jeff Hao848f70a2014-01-15 13:49:50 -0800200 mirror::String* string, Thread* self) \
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700201 REQUIRES_SHARED(Locks::mutator_lock_) { \
Jeff Hao848f70a2014-01-15 13:49:50 -0800202 StackHandleScope<1> hs(self); \
203 Handle<mirror::String> handle_string(hs.NewHandle(string)); \
204 return mirror::String::AllocFromString<instrumented_bool>(self, handle_string->GetLength(), \
205 handle_string, 0, allocator_type); \
Ian Rogers57b86d42012-03-27 16:05:41 -0700206}
207
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800208#define GENERATE_ENTRYPOINTS_FOR_ALLOCATOR(suffix, allocator_type) \
209 GENERATE_ENTRYPOINTS_FOR_ALLOCATOR_INST(suffix, Instrumented, true, allocator_type) \
210 GENERATE_ENTRYPOINTS_FOR_ALLOCATOR_INST(suffix, , false, allocator_type)
Ian Rogers57b86d42012-03-27 16:05:41 -0700211
Mathieu Chartiere6da9af2013-12-16 11:54:42 -0800212GENERATE_ENTRYPOINTS_FOR_ALLOCATOR(DlMalloc, gc::kAllocatorTypeDlMalloc)
213GENERATE_ENTRYPOINTS_FOR_ALLOCATOR(RosAlloc, gc::kAllocatorTypeRosAlloc)
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800214GENERATE_ENTRYPOINTS_FOR_ALLOCATOR(BumpPointer, gc::kAllocatorTypeBumpPointer)
Mathieu Chartier692fafd2013-11-29 17:24:40 -0800215GENERATE_ENTRYPOINTS_FOR_ALLOCATOR(TLAB, gc::kAllocatorTypeTLAB)
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800216GENERATE_ENTRYPOINTS_FOR_ALLOCATOR(Region, gc::kAllocatorTypeRegion)
217GENERATE_ENTRYPOINTS_FOR_ALLOCATOR(RegionTLAB, gc::kAllocatorTypeRegionTLAB)
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -0700218
Mathieu Chartierd8891782014-03-02 13:28:37 -0800219#define GENERATE_ENTRYPOINTS(suffix) \
Mathieu Chartiere401d142015-04-22 13:56:20 -0700220extern "C" void* art_quick_alloc_array##suffix(uint32_t, int32_t, ArtMethod* ref); \
221extern "C" void* art_quick_alloc_array_resolved##suffix(mirror::Class* klass, int32_t, ArtMethod* ref); \
222extern "C" void* art_quick_alloc_array_with_access_check##suffix(uint32_t, int32_t, ArtMethod* ref); \
223extern "C" void* art_quick_alloc_object##suffix(uint32_t type_idx, ArtMethod* ref); \
224extern "C" void* art_quick_alloc_object_resolved##suffix(mirror::Class* klass, ArtMethod* ref); \
225extern "C" void* art_quick_alloc_object_initialized##suffix(mirror::Class* klass, ArtMethod* ref); \
226extern "C" void* art_quick_alloc_object_with_access_check##suffix(uint32_t type_idx, ArtMethod* ref); \
227extern "C" void* art_quick_check_and_alloc_array##suffix(uint32_t, int32_t, ArtMethod* ref); \
228extern "C" void* art_quick_check_and_alloc_array_with_access_check##suffix(uint32_t, int32_t, ArtMethod* ref); \
Jeff Hao848f70a2014-01-15 13:49:50 -0800229extern "C" void* art_quick_alloc_string_from_bytes##suffix(void*, int32_t, int32_t, int32_t); \
230extern "C" void* art_quick_alloc_string_from_chars##suffix(int32_t, int32_t, void*); \
231extern "C" void* art_quick_alloc_string_from_string##suffix(void*); \
Mathieu Chartiere401d142015-04-22 13:56:20 -0700232extern "C" void* art_quick_alloc_array##suffix##_instrumented(uint32_t, int32_t, ArtMethod* ref); \
233extern "C" void* art_quick_alloc_array_resolved##suffix##_instrumented(mirror::Class* klass, int32_t, ArtMethod* ref); \
234extern "C" void* art_quick_alloc_array_with_access_check##suffix##_instrumented(uint32_t, int32_t, ArtMethod* ref); \
235extern "C" void* art_quick_alloc_object##suffix##_instrumented(uint32_t type_idx, ArtMethod* ref); \
236extern "C" void* art_quick_alloc_object_resolved##suffix##_instrumented(mirror::Class* klass, ArtMethod* ref); \
237extern "C" void* art_quick_alloc_object_initialized##suffix##_instrumented(mirror::Class* klass, ArtMethod* ref); \
238extern "C" void* art_quick_alloc_object_with_access_check##suffix##_instrumented(uint32_t type_idx, ArtMethod* ref); \
239extern "C" void* art_quick_check_and_alloc_array##suffix##_instrumented(uint32_t, int32_t, ArtMethod* ref); \
240extern "C" void* art_quick_check_and_alloc_array_with_access_check##suffix##_instrumented(uint32_t, int32_t, ArtMethod* ref); \
Jeff Hao848f70a2014-01-15 13:49:50 -0800241extern "C" void* art_quick_alloc_string_from_bytes##suffix##_instrumented(void*, int32_t, int32_t, int32_t); \
242extern "C" void* art_quick_alloc_string_from_chars##suffix##_instrumented(int32_t, int32_t, void*); \
243extern "C" void* art_quick_alloc_string_from_string##suffix##_instrumented(void*); \
Mathieu Chartierd8891782014-03-02 13:28:37 -0800244void SetQuickAllocEntryPoints##suffix(QuickEntryPoints* qpoints, bool instrumented) { \
245 if (instrumented) { \
246 qpoints->pAllocArray = art_quick_alloc_array##suffix##_instrumented; \
247 qpoints->pAllocArrayResolved = art_quick_alloc_array_resolved##suffix##_instrumented; \
248 qpoints->pAllocArrayWithAccessCheck = art_quick_alloc_array_with_access_check##suffix##_instrumented; \
249 qpoints->pAllocObject = art_quick_alloc_object##suffix##_instrumented; \
250 qpoints->pAllocObjectResolved = art_quick_alloc_object_resolved##suffix##_instrumented; \
251 qpoints->pAllocObjectInitialized = art_quick_alloc_object_initialized##suffix##_instrumented; \
252 qpoints->pAllocObjectWithAccessCheck = art_quick_alloc_object_with_access_check##suffix##_instrumented; \
253 qpoints->pCheckAndAllocArray = art_quick_check_and_alloc_array##suffix##_instrumented; \
254 qpoints->pCheckAndAllocArrayWithAccessCheck = art_quick_check_and_alloc_array_with_access_check##suffix##_instrumented; \
Jeff Hao848f70a2014-01-15 13:49:50 -0800255 qpoints->pAllocStringFromBytes = art_quick_alloc_string_from_bytes##suffix##_instrumented; \
256 qpoints->pAllocStringFromChars = art_quick_alloc_string_from_chars##suffix##_instrumented; \
257 qpoints->pAllocStringFromString = art_quick_alloc_string_from_string##suffix##_instrumented; \
Mathieu Chartierd8891782014-03-02 13:28:37 -0800258 } else { \
259 qpoints->pAllocArray = art_quick_alloc_array##suffix; \
260 qpoints->pAllocArrayResolved = art_quick_alloc_array_resolved##suffix; \
261 qpoints->pAllocArrayWithAccessCheck = art_quick_alloc_array_with_access_check##suffix; \
262 qpoints->pAllocObject = art_quick_alloc_object##suffix; \
263 qpoints->pAllocObjectResolved = art_quick_alloc_object_resolved##suffix; \
264 qpoints->pAllocObjectInitialized = art_quick_alloc_object_initialized##suffix; \
265 qpoints->pAllocObjectWithAccessCheck = art_quick_alloc_object_with_access_check##suffix; \
266 qpoints->pCheckAndAllocArray = art_quick_check_and_alloc_array##suffix; \
267 qpoints->pCheckAndAllocArrayWithAccessCheck = art_quick_check_and_alloc_array_with_access_check##suffix; \
Jeff Hao848f70a2014-01-15 13:49:50 -0800268 qpoints->pAllocStringFromBytes = art_quick_alloc_string_from_bytes##suffix; \
269 qpoints->pAllocStringFromChars = art_quick_alloc_string_from_chars##suffix; \
270 qpoints->pAllocStringFromString = art_quick_alloc_string_from_string##suffix; \
Mathieu Chartierd8891782014-03-02 13:28:37 -0800271 } \
272}
273
274// Generate the entrypoint functions.
Ian Rogersc3ccc102014-06-25 11:52:14 -0700275#if !defined(__APPLE__) || !defined(__LP64__)
Andreas Gampec8ccf682014-09-29 20:07:43 -0700276GENERATE_ENTRYPOINTS(_dlmalloc)
277GENERATE_ENTRYPOINTS(_rosalloc)
278GENERATE_ENTRYPOINTS(_bump_pointer)
279GENERATE_ENTRYPOINTS(_tlab)
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800280GENERATE_ENTRYPOINTS(_region)
281GENERATE_ENTRYPOINTS(_region_tlab)
Ian Rogersc3ccc102014-06-25 11:52:14 -0700282#endif
Mathieu Chartierd8891782014-03-02 13:28:37 -0800283
284static bool entry_points_instrumented = false;
285static gc::AllocatorType entry_points_allocator = gc::kAllocatorTypeDlMalloc;
286
287void SetQuickAllocEntryPointsAllocator(gc::AllocatorType allocator) {
288 entry_points_allocator = allocator;
289}
290
291void SetQuickAllocEntryPointsInstrumented(bool instrumented) {
292 entry_points_instrumented = instrumented;
293}
294
295void ResetQuickAllocEntryPoints(QuickEntryPoints* qpoints) {
Andreas Gampe48cc32c2015-04-07 02:53:04 +0000296#if !defined(__APPLE__) || !defined(__LP64__)
Ian Rogersde2db522014-11-04 14:43:18 -0800297 switch (entry_points_allocator) {
Mathieu Chartierd8891782014-03-02 13:28:37 -0800298 case gc::kAllocatorTypeDlMalloc: {
299 SetQuickAllocEntryPoints_dlmalloc(qpoints, entry_points_instrumented);
Ian Rogers7dc9c812014-11-04 15:10:55 -0800300 return;
Mathieu Chartierd8891782014-03-02 13:28:37 -0800301 }
302 case gc::kAllocatorTypeRosAlloc: {
303 SetQuickAllocEntryPoints_rosalloc(qpoints, entry_points_instrumented);
Ian Rogers7dc9c812014-11-04 15:10:55 -0800304 return;
Mathieu Chartierd8891782014-03-02 13:28:37 -0800305 }
306 case gc::kAllocatorTypeBumpPointer: {
307 CHECK(kMovingCollector);
308 SetQuickAllocEntryPoints_bump_pointer(qpoints, entry_points_instrumented);
Ian Rogers7dc9c812014-11-04 15:10:55 -0800309 return;
Mathieu Chartierd8891782014-03-02 13:28:37 -0800310 }
311 case gc::kAllocatorTypeTLAB: {
312 CHECK(kMovingCollector);
313 SetQuickAllocEntryPoints_tlab(qpoints, entry_points_instrumented);
Ian Rogers7dc9c812014-11-04 15:10:55 -0800314 return;
Mathieu Chartierd8891782014-03-02 13:28:37 -0800315 }
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800316 case gc::kAllocatorTypeRegion: {
317 CHECK(kMovingCollector);
318 SetQuickAllocEntryPoints_region(qpoints, entry_points_instrumented);
319 return;
320 }
321 case gc::kAllocatorTypeRegionTLAB: {
322 CHECK(kMovingCollector);
323 SetQuickAllocEntryPoints_region_tlab(qpoints, entry_points_instrumented);
324 return;
325 }
Andreas Gampe48cc32c2015-04-07 02:53:04 +0000326 default:
327 break;
Mathieu Chartierd8891782014-03-02 13:28:37 -0800328 }
Andreas Gampe48cc32c2015-04-07 02:53:04 +0000329#else
330 UNUSED(qpoints);
331#endif
332 UNIMPLEMENTED(FATAL);
Ian Rogersde2db522014-11-04 14:43:18 -0800333 UNREACHABLE();
Mathieu Chartierd8891782014-03-02 13:28:37 -0800334}
335
Ian Rogers57b86d42012-03-27 16:05:41 -0700336} // namespace art