blob: dde74de87ae4a56529fd1508c689dc11856a5cc2 [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
Ian Rogers57b86d42012-03-27 16:05:41 -070019#include "callee_save_frame.h"
Ian Rogers7655f292013-07-29 11:07:13 -070020#include "entrypoints/entrypoint_utils.h"
Brian Carlstromea46f952013-07-30 01:26:50 -070021#include "mirror/art_method-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080022#include "mirror/class-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080023#include "mirror/object_array-inl.h"
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070024#include "mirror/object-inl.h"
Ian Rogers57b86d42012-03-27 16:05:41 -070025
26namespace art {
27
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080028#define GENERATE_ENTRYPOINTS_FOR_ALLOCATOR_INST(suffix, suffix2, instrumented_bool, allocator_type) \
29extern "C" mirror::Object* artAllocObjectFromCode ##suffix##suffix2( \
Andreas Gampecf4035a2014-05-28 22:43:01 -070030 uint32_t type_idx, mirror::ArtMethod* method, Thread* self, \
31 StackReference<mirror::ArtMethod>* sp) \
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080032 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { \
33 FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsOnly); \
34 return AllocObjectFromCode<false, instrumented_bool>(type_idx, method, self, allocator_type); \
35} \
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080036extern "C" mirror::Object* artAllocObjectFromCodeResolved##suffix##suffix2( \
Andreas Gampecf4035a2014-05-28 22:43:01 -070037 mirror::Class* klass, mirror::ArtMethod* method, Thread* self, \
38 StackReference<mirror::ArtMethod>* sp) \
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080039 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { \
40 FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsOnly); \
41 return AllocObjectFromCodeResolved<instrumented_bool>(klass, method, self, allocator_type); \
42} \
43extern "C" mirror::Object* artAllocObjectFromCodeInitialized##suffix##suffix2( \
Andreas Gampecf4035a2014-05-28 22:43:01 -070044 mirror::Class* klass, mirror::ArtMethod* method, Thread* self, \
45 StackReference<mirror::ArtMethod>* sp) \
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080046 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { \
47 FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsOnly); \
48 return AllocObjectFromCodeInitialized<instrumented_bool>(klass, method, self, allocator_type); \
49} \
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080050extern "C" mirror::Object* artAllocObjectFromCodeWithAccessCheck##suffix##suffix2( \
Andreas Gampecf4035a2014-05-28 22:43:01 -070051 uint32_t type_idx, mirror::ArtMethod* method, Thread* self, \
52 StackReference<mirror::ArtMethod>* sp) \
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080053 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { \
54 FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsOnly); \
55 return AllocObjectFromCode<true, instrumented_bool>(type_idx, method, self, allocator_type); \
56} \
57extern "C" mirror::Array* artAllocArrayFromCode##suffix##suffix2( \
58 uint32_t type_idx, mirror::ArtMethod* method, int32_t component_count, Thread* self, \
Andreas Gampecf4035a2014-05-28 22:43:01 -070059 StackReference<mirror::ArtMethod>* sp) \
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080060 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { \
61 FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsOnly); \
62 return AllocArrayFromCode<false, instrumented_bool>(type_idx, method, component_count, self, \
63 allocator_type); \
64} \
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -080065extern "C" mirror::Array* artAllocArrayFromCodeResolved##suffix##suffix2( \
66 mirror::Class* klass, mirror::ArtMethod* method, int32_t component_count, Thread* self, \
Andreas Gampecf4035a2014-05-28 22:43:01 -070067 StackReference<mirror::ArtMethod>* sp) \
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -080068 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { \
69 FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsOnly); \
70 return AllocArrayFromCodeResolved<false, instrumented_bool>(klass, method, component_count, self, \
71 allocator_type); \
72} \
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080073extern "C" mirror::Array* artAllocArrayFromCodeWithAccessCheck##suffix##suffix2( \
74 uint32_t type_idx, mirror::ArtMethod* method, int32_t component_count, Thread* self, \
Andreas Gampecf4035a2014-05-28 22:43:01 -070075 StackReference<mirror::ArtMethod>* sp) \
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080076 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { \
77 FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsOnly); \
78 return AllocArrayFromCode<true, instrumented_bool>(type_idx, method, component_count, self, \
79 allocator_type); \
80} \
81extern "C" mirror::Array* artCheckAndAllocArrayFromCode##suffix##suffix2( \
82 uint32_t type_idx, mirror::ArtMethod* method, int32_t component_count, Thread* self, \
Andreas Gampecf4035a2014-05-28 22:43:01 -070083 StackReference<mirror::ArtMethod>* sp) \
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080084 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { \
85 FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsOnly); \
Hiroshi Yamauchicbbb0802013-11-21 12:42:36 -080086 if (!instrumented_bool) { \
87 return CheckAndAllocArrayFromCode(type_idx, method, component_count, self, false, allocator_type); \
88 } else { \
89 return CheckAndAllocArrayFromCodeInstrumented(type_idx, method, component_count, self, false, allocator_type); \
90 } \
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080091} \
92extern "C" mirror::Array* artCheckAndAllocArrayFromCodeWithAccessCheck##suffix##suffix2( \
93 uint32_t type_idx, mirror::ArtMethod* method, int32_t component_count, Thread* self, \
Andreas Gampecf4035a2014-05-28 22:43:01 -070094 StackReference<mirror::ArtMethod>* sp) \
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080095 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { \
96 FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsOnly); \
Hiroshi Yamauchicbbb0802013-11-21 12:42:36 -080097 if (!instrumented_bool) { \
98 return CheckAndAllocArrayFromCode(type_idx, method, component_count, self, true, allocator_type); \
99 } else { \
100 return CheckAndAllocArrayFromCodeInstrumented(type_idx, method, component_count, self, true, allocator_type); \
101 } \
Ian Rogers57b86d42012-03-27 16:05:41 -0700102}
103
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800104#define GENERATE_ENTRYPOINTS_FOR_ALLOCATOR(suffix, allocator_type) \
105 GENERATE_ENTRYPOINTS_FOR_ALLOCATOR_INST(suffix, Instrumented, true, allocator_type) \
106 GENERATE_ENTRYPOINTS_FOR_ALLOCATOR_INST(suffix, , false, allocator_type)
Ian Rogers57b86d42012-03-27 16:05:41 -0700107
Mathieu Chartiere6da9af2013-12-16 11:54:42 -0800108GENERATE_ENTRYPOINTS_FOR_ALLOCATOR(DlMalloc, gc::kAllocatorTypeDlMalloc)
109GENERATE_ENTRYPOINTS_FOR_ALLOCATOR(RosAlloc, gc::kAllocatorTypeRosAlloc)
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800110GENERATE_ENTRYPOINTS_FOR_ALLOCATOR(BumpPointer, gc::kAllocatorTypeBumpPointer)
Mathieu Chartier692fafd2013-11-29 17:24:40 -0800111GENERATE_ENTRYPOINTS_FOR_ALLOCATOR(TLAB, gc::kAllocatorTypeTLAB)
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -0700112
Mathieu Chartierd8891782014-03-02 13:28:37 -0800113#define GENERATE_ENTRYPOINTS(suffix) \
114extern "C" void* art_quick_alloc_array##suffix(uint32_t, void*, int32_t); \
115extern "C" void* art_quick_alloc_array_resolved##suffix(void* klass, void*, int32_t); \
116extern "C" void* art_quick_alloc_array_with_access_check##suffix(uint32_t, void*, int32_t); \
117extern "C" void* art_quick_alloc_object##suffix(uint32_t type_idx, void* method); \
118extern "C" void* art_quick_alloc_object_resolved##suffix(void* klass, void* method); \
119extern "C" void* art_quick_alloc_object_initialized##suffix(void* klass, void* method); \
120extern "C" void* art_quick_alloc_object_with_access_check##suffix(uint32_t type_idx, void* method); \
121extern "C" void* art_quick_check_and_alloc_array##suffix(uint32_t, void*, int32_t); \
122extern "C" void* art_quick_check_and_alloc_array_with_access_check##suffix(uint32_t, void*, int32_t); \
123extern "C" void* art_quick_alloc_array##suffix##_instrumented(uint32_t, void*, int32_t); \
124extern "C" void* art_quick_alloc_array_resolved##suffix##_instrumented(void* klass, void*, int32_t); \
125extern "C" void* art_quick_alloc_array_with_access_check##suffix##_instrumented(uint32_t, void*, int32_t); \
126extern "C" void* art_quick_alloc_object##suffix##_instrumented(uint32_t type_idx, void* method); \
127extern "C" void* art_quick_alloc_object_resolved##suffix##_instrumented(void* klass, void* method); \
128extern "C" void* art_quick_alloc_object_initialized##suffix##_instrumented(void* klass, void* method); \
129extern "C" void* art_quick_alloc_object_with_access_check##suffix##_instrumented(uint32_t type_idx, void* method); \
130extern "C" void* art_quick_check_and_alloc_array##suffix##_instrumented(uint32_t, void*, int32_t); \
131extern "C" void* art_quick_check_and_alloc_array_with_access_check##suffix##_instrumented(uint32_t, void*, int32_t); \
132void SetQuickAllocEntryPoints##suffix(QuickEntryPoints* qpoints, bool instrumented) { \
133 if (instrumented) { \
134 qpoints->pAllocArray = art_quick_alloc_array##suffix##_instrumented; \
135 qpoints->pAllocArrayResolved = art_quick_alloc_array_resolved##suffix##_instrumented; \
136 qpoints->pAllocArrayWithAccessCheck = art_quick_alloc_array_with_access_check##suffix##_instrumented; \
137 qpoints->pAllocObject = art_quick_alloc_object##suffix##_instrumented; \
138 qpoints->pAllocObjectResolved = art_quick_alloc_object_resolved##suffix##_instrumented; \
139 qpoints->pAllocObjectInitialized = art_quick_alloc_object_initialized##suffix##_instrumented; \
140 qpoints->pAllocObjectWithAccessCheck = art_quick_alloc_object_with_access_check##suffix##_instrumented; \
141 qpoints->pCheckAndAllocArray = art_quick_check_and_alloc_array##suffix##_instrumented; \
142 qpoints->pCheckAndAllocArrayWithAccessCheck = art_quick_check_and_alloc_array_with_access_check##suffix##_instrumented; \
143 } else { \
144 qpoints->pAllocArray = art_quick_alloc_array##suffix; \
145 qpoints->pAllocArrayResolved = art_quick_alloc_array_resolved##suffix; \
146 qpoints->pAllocArrayWithAccessCheck = art_quick_alloc_array_with_access_check##suffix; \
147 qpoints->pAllocObject = art_quick_alloc_object##suffix; \
148 qpoints->pAllocObjectResolved = art_quick_alloc_object_resolved##suffix; \
149 qpoints->pAllocObjectInitialized = art_quick_alloc_object_initialized##suffix; \
150 qpoints->pAllocObjectWithAccessCheck = art_quick_alloc_object_with_access_check##suffix; \
151 qpoints->pCheckAndAllocArray = art_quick_check_and_alloc_array##suffix; \
152 qpoints->pCheckAndAllocArrayWithAccessCheck = art_quick_check_and_alloc_array_with_access_check##suffix; \
153 } \
154}
155
156// Generate the entrypoint functions.
Ian Rogersc3ccc102014-06-25 11:52:14 -0700157#if !defined(__APPLE__) || !defined(__LP64__)
Mathieu Chartierd8891782014-03-02 13:28:37 -0800158GENERATE_ENTRYPOINTS(_dlmalloc);
159GENERATE_ENTRYPOINTS(_rosalloc);
160GENERATE_ENTRYPOINTS(_bump_pointer);
161GENERATE_ENTRYPOINTS(_tlab);
Ian Rogersc3ccc102014-06-25 11:52:14 -0700162#endif
Mathieu Chartierd8891782014-03-02 13:28:37 -0800163
164static bool entry_points_instrumented = false;
165static gc::AllocatorType entry_points_allocator = gc::kAllocatorTypeDlMalloc;
166
167void SetQuickAllocEntryPointsAllocator(gc::AllocatorType allocator) {
168 entry_points_allocator = allocator;
169}
170
171void SetQuickAllocEntryPointsInstrumented(bool instrumented) {
172 entry_points_instrumented = instrumented;
173}
174
175void ResetQuickAllocEntryPoints(QuickEntryPoints* qpoints) {
176 switch (entry_points_allocator) {
Ian Rogersc3ccc102014-06-25 11:52:14 -0700177#if !defined(__APPLE__) || !defined(__LP64__)
Mathieu Chartierd8891782014-03-02 13:28:37 -0800178 case gc::kAllocatorTypeDlMalloc: {
179 SetQuickAllocEntryPoints_dlmalloc(qpoints, entry_points_instrumented);
180 break;
181 }
182 case gc::kAllocatorTypeRosAlloc: {
183 SetQuickAllocEntryPoints_rosalloc(qpoints, entry_points_instrumented);
184 break;
185 }
186 case gc::kAllocatorTypeBumpPointer: {
187 CHECK(kMovingCollector);
188 SetQuickAllocEntryPoints_bump_pointer(qpoints, entry_points_instrumented);
189 break;
190 }
191 case gc::kAllocatorTypeTLAB: {
192 CHECK(kMovingCollector);
193 SetQuickAllocEntryPoints_tlab(qpoints, entry_points_instrumented);
194 break;
195 }
Ian Rogersc3ccc102014-06-25 11:52:14 -0700196#endif
Mathieu Chartierd8891782014-03-02 13:28:37 -0800197 default: {
198 LOG(FATAL) << "Unimplemented";
199 }
200 }
201}
202
Ian Rogers57b86d42012-03-27 16:05:41 -0700203} // namespace art