blob: ccc0f3ded528b7c950cd347654cf478df5966efa [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( \
30 uint32_t type_idx, mirror::ArtMethod* method, Thread* self, mirror::ArtMethod** sp) \
31 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { \
32 FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsOnly); \
33 return AllocObjectFromCode<false, instrumented_bool>(type_idx, method, self, allocator_type); \
34} \
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080035extern "C" mirror::Object* artAllocObjectFromCodeResolved##suffix##suffix2( \
36 mirror::Class* klass, mirror::ArtMethod* method, Thread* self, mirror::ArtMethod** sp) \
37 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { \
38 FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsOnly); \
39 return AllocObjectFromCodeResolved<instrumented_bool>(klass, method, self, allocator_type); \
40} \
41extern "C" mirror::Object* artAllocObjectFromCodeInitialized##suffix##suffix2( \
42 mirror::Class* klass, mirror::ArtMethod* method, Thread* self, mirror::ArtMethod** sp) \
43 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { \
44 FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsOnly); \
45 return AllocObjectFromCodeInitialized<instrumented_bool>(klass, method, self, allocator_type); \
46} \
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080047extern "C" mirror::Object* artAllocObjectFromCodeWithAccessCheck##suffix##suffix2( \
48 uint32_t type_idx, mirror::ArtMethod* method, Thread* self, mirror::ArtMethod** sp) \
49 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { \
50 FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsOnly); \
51 return AllocObjectFromCode<true, instrumented_bool>(type_idx, method, self, allocator_type); \
52} \
53extern "C" mirror::Array* artAllocArrayFromCode##suffix##suffix2( \
54 uint32_t type_idx, mirror::ArtMethod* method, int32_t component_count, Thread* self, \
55 mirror::ArtMethod** sp) \
56 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { \
57 FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsOnly); \
58 return AllocArrayFromCode<false, instrumented_bool>(type_idx, method, component_count, self, \
59 allocator_type); \
60} \
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -080061extern "C" mirror::Array* artAllocArrayFromCodeResolved##suffix##suffix2( \
62 mirror::Class* klass, mirror::ArtMethod* method, int32_t component_count, Thread* self, \
63 mirror::ArtMethod** sp) \
64 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { \
65 FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsOnly); \
66 return AllocArrayFromCodeResolved<false, instrumented_bool>(klass, method, component_count, self, \
67 allocator_type); \
68} \
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080069extern "C" mirror::Array* artAllocArrayFromCodeWithAccessCheck##suffix##suffix2( \
70 uint32_t type_idx, mirror::ArtMethod* method, int32_t component_count, Thread* self, \
71 mirror::ArtMethod** sp) \
72 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { \
73 FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsOnly); \
74 return AllocArrayFromCode<true, instrumented_bool>(type_idx, method, component_count, self, \
75 allocator_type); \
76} \
77extern "C" mirror::Array* artCheckAndAllocArrayFromCode##suffix##suffix2( \
78 uint32_t type_idx, mirror::ArtMethod* method, int32_t component_count, Thread* self, \
79 mirror::ArtMethod** sp) \
80 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { \
81 FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsOnly); \
Hiroshi Yamauchicbbb0802013-11-21 12:42:36 -080082 if (!instrumented_bool) { \
83 return CheckAndAllocArrayFromCode(type_idx, method, component_count, self, false, allocator_type); \
84 } else { \
85 return CheckAndAllocArrayFromCodeInstrumented(type_idx, method, component_count, self, false, allocator_type); \
86 } \
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080087} \
88extern "C" mirror::Array* artCheckAndAllocArrayFromCodeWithAccessCheck##suffix##suffix2( \
89 uint32_t type_idx, mirror::ArtMethod* method, int32_t component_count, Thread* self, \
90 mirror::ArtMethod** sp) \
91 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { \
92 FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsOnly); \
Hiroshi Yamauchicbbb0802013-11-21 12:42:36 -080093 if (!instrumented_bool) { \
94 return CheckAndAllocArrayFromCode(type_idx, method, component_count, self, true, allocator_type); \
95 } else { \
96 return CheckAndAllocArrayFromCodeInstrumented(type_idx, method, component_count, self, true, allocator_type); \
97 } \
Ian Rogers57b86d42012-03-27 16:05:41 -070098}
99
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800100#define GENERATE_ENTRYPOINTS_FOR_ALLOCATOR(suffix, allocator_type) \
101 GENERATE_ENTRYPOINTS_FOR_ALLOCATOR_INST(suffix, Instrumented, true, allocator_type) \
102 GENERATE_ENTRYPOINTS_FOR_ALLOCATOR_INST(suffix, , false, allocator_type)
Ian Rogers57b86d42012-03-27 16:05:41 -0700103
Mathieu Chartiere6da9af2013-12-16 11:54:42 -0800104GENERATE_ENTRYPOINTS_FOR_ALLOCATOR(DlMalloc, gc::kAllocatorTypeDlMalloc)
105GENERATE_ENTRYPOINTS_FOR_ALLOCATOR(RosAlloc, gc::kAllocatorTypeRosAlloc)
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800106GENERATE_ENTRYPOINTS_FOR_ALLOCATOR(BumpPointer, gc::kAllocatorTypeBumpPointer)
Mathieu Chartier692fafd2013-11-29 17:24:40 -0800107GENERATE_ENTRYPOINTS_FOR_ALLOCATOR(TLAB, gc::kAllocatorTypeTLAB)
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -0700108
Mathieu Chartierd8891782014-03-02 13:28:37 -0800109#define GENERATE_ENTRYPOINTS(suffix) \
110extern "C" void* art_quick_alloc_array##suffix(uint32_t, void*, int32_t); \
111extern "C" void* art_quick_alloc_array_resolved##suffix(void* klass, void*, int32_t); \
112extern "C" void* art_quick_alloc_array_with_access_check##suffix(uint32_t, void*, int32_t); \
113extern "C" void* art_quick_alloc_object##suffix(uint32_t type_idx, void* method); \
114extern "C" void* art_quick_alloc_object_resolved##suffix(void* klass, void* method); \
115extern "C" void* art_quick_alloc_object_initialized##suffix(void* klass, void* method); \
116extern "C" void* art_quick_alloc_object_with_access_check##suffix(uint32_t type_idx, void* method); \
117extern "C" void* art_quick_check_and_alloc_array##suffix(uint32_t, void*, int32_t); \
118extern "C" void* art_quick_check_and_alloc_array_with_access_check##suffix(uint32_t, void*, int32_t); \
119extern "C" void* art_quick_alloc_array##suffix##_instrumented(uint32_t, void*, int32_t); \
120extern "C" void* art_quick_alloc_array_resolved##suffix##_instrumented(void* klass, void*, int32_t); \
121extern "C" void* art_quick_alloc_array_with_access_check##suffix##_instrumented(uint32_t, void*, int32_t); \
122extern "C" void* art_quick_alloc_object##suffix##_instrumented(uint32_t type_idx, void* method); \
123extern "C" void* art_quick_alloc_object_resolved##suffix##_instrumented(void* klass, void* method); \
124extern "C" void* art_quick_alloc_object_initialized##suffix##_instrumented(void* klass, void* method); \
125extern "C" void* art_quick_alloc_object_with_access_check##suffix##_instrumented(uint32_t type_idx, void* method); \
126extern "C" void* art_quick_check_and_alloc_array##suffix##_instrumented(uint32_t, void*, int32_t); \
127extern "C" void* art_quick_check_and_alloc_array_with_access_check##suffix##_instrumented(uint32_t, void*, int32_t); \
128void SetQuickAllocEntryPoints##suffix(QuickEntryPoints* qpoints, bool instrumented) { \
129 if (instrumented) { \
130 qpoints->pAllocArray = art_quick_alloc_array##suffix##_instrumented; \
131 qpoints->pAllocArrayResolved = art_quick_alloc_array_resolved##suffix##_instrumented; \
132 qpoints->pAllocArrayWithAccessCheck = art_quick_alloc_array_with_access_check##suffix##_instrumented; \
133 qpoints->pAllocObject = art_quick_alloc_object##suffix##_instrumented; \
134 qpoints->pAllocObjectResolved = art_quick_alloc_object_resolved##suffix##_instrumented; \
135 qpoints->pAllocObjectInitialized = art_quick_alloc_object_initialized##suffix##_instrumented; \
136 qpoints->pAllocObjectWithAccessCheck = art_quick_alloc_object_with_access_check##suffix##_instrumented; \
137 qpoints->pCheckAndAllocArray = art_quick_check_and_alloc_array##suffix##_instrumented; \
138 qpoints->pCheckAndAllocArrayWithAccessCheck = art_quick_check_and_alloc_array_with_access_check##suffix##_instrumented; \
139 } else { \
140 qpoints->pAllocArray = art_quick_alloc_array##suffix; \
141 qpoints->pAllocArrayResolved = art_quick_alloc_array_resolved##suffix; \
142 qpoints->pAllocArrayWithAccessCheck = art_quick_alloc_array_with_access_check##suffix; \
143 qpoints->pAllocObject = art_quick_alloc_object##suffix; \
144 qpoints->pAllocObjectResolved = art_quick_alloc_object_resolved##suffix; \
145 qpoints->pAllocObjectInitialized = art_quick_alloc_object_initialized##suffix; \
146 qpoints->pAllocObjectWithAccessCheck = art_quick_alloc_object_with_access_check##suffix; \
147 qpoints->pCheckAndAllocArray = art_quick_check_and_alloc_array##suffix; \
148 qpoints->pCheckAndAllocArrayWithAccessCheck = art_quick_check_and_alloc_array_with_access_check##suffix; \
149 } \
150}
151
152// Generate the entrypoint functions.
153GENERATE_ENTRYPOINTS(_dlmalloc);
154GENERATE_ENTRYPOINTS(_rosalloc);
155GENERATE_ENTRYPOINTS(_bump_pointer);
156GENERATE_ENTRYPOINTS(_tlab);
157
158static bool entry_points_instrumented = false;
159static gc::AllocatorType entry_points_allocator = gc::kAllocatorTypeDlMalloc;
160
161void SetQuickAllocEntryPointsAllocator(gc::AllocatorType allocator) {
162 entry_points_allocator = allocator;
163}
164
165void SetQuickAllocEntryPointsInstrumented(bool instrumented) {
166 entry_points_instrumented = instrumented;
167}
168
169void ResetQuickAllocEntryPoints(QuickEntryPoints* qpoints) {
170 switch (entry_points_allocator) {
171 case gc::kAllocatorTypeDlMalloc: {
172 SetQuickAllocEntryPoints_dlmalloc(qpoints, entry_points_instrumented);
173 break;
174 }
175 case gc::kAllocatorTypeRosAlloc: {
176 SetQuickAllocEntryPoints_rosalloc(qpoints, entry_points_instrumented);
177 break;
178 }
179 case gc::kAllocatorTypeBumpPointer: {
180 CHECK(kMovingCollector);
181 SetQuickAllocEntryPoints_bump_pointer(qpoints, entry_points_instrumented);
182 break;
183 }
184 case gc::kAllocatorTypeTLAB: {
185 CHECK(kMovingCollector);
186 SetQuickAllocEntryPoints_tlab(qpoints, entry_points_instrumented);
187 break;
188 }
189 default: {
190 LOG(FATAL) << "Unimplemented";
191 }
192 }
193}
194
Ian Rogers57b86d42012-03-27 16:05:41 -0700195} // namespace art