blob: 9363f81cfef0d696999c2564dc0361965a25db76 [file] [log] [blame]
Mathieu Chartiercbb2d202013-11-14 17:45:16 -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 */
16
17#include "entrypoints/quick/quick_entrypoints.h"
18#include "gc/heap.h"
19
20#define GENERATE_ENTRYPOINTS(suffix) \
21extern "C" void* art_quick_alloc_array##suffix(uint32_t, void*, int32_t); \
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -080022extern "C" void* art_quick_alloc_array_resolved##suffix(void* klass, void*, int32_t); \
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080023extern "C" void* art_quick_alloc_array_with_access_check##suffix(uint32_t, void*, int32_t); \
24extern "C" void* art_quick_alloc_object##suffix(uint32_t type_idx, void* method); \
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080025extern "C" void* art_quick_alloc_object_resolved##suffix(void* klass, void* method); \
26extern "C" void* art_quick_alloc_object_initialized##suffix(void* klass, void* method); \
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080027extern "C" void* art_quick_alloc_object_with_access_check##suffix(uint32_t type_idx, void* method); \
28extern "C" void* art_quick_check_and_alloc_array##suffix(uint32_t, void*, int32_t); \
29extern "C" void* art_quick_check_and_alloc_array_with_access_check##suffix(uint32_t, void*, int32_t); \
30extern "C" void* art_quick_alloc_array##suffix##_instrumented(uint32_t, void*, int32_t); \
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -080031extern "C" void* art_quick_alloc_array_resolved##suffix##_instrumented(void* klass, void*, int32_t); \
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080032extern "C" void* art_quick_alloc_array_with_access_check##suffix##_instrumented(uint32_t, void*, int32_t); \
33extern "C" void* art_quick_alloc_object##suffix##_instrumented(uint32_t type_idx, void* method); \
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080034extern "C" void* art_quick_alloc_object_resolved##suffix##_instrumented(void* klass, void* method); \
35extern "C" void* art_quick_alloc_object_initialized##suffix##_instrumented(void* klass, void* method); \
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080036extern "C" void* art_quick_alloc_object_with_access_check##suffix##_instrumented(uint32_t type_idx, void* method); \
37extern "C" void* art_quick_check_and_alloc_array##suffix##_instrumented(uint32_t, void*, int32_t); \
38extern "C" void* art_quick_check_and_alloc_array_with_access_check##suffix##_instrumented(uint32_t, void*, int32_t); \
39void SetQuickAllocEntryPoints##suffix(QuickEntryPoints* qpoints, bool instrumented) { \
40 if (instrumented) { \
41 qpoints->pAllocArray = art_quick_alloc_array##suffix##_instrumented; \
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -080042 qpoints->pAllocArrayResolved = art_quick_alloc_array_resolved##suffix##_instrumented; \
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080043 qpoints->pAllocArrayWithAccessCheck = art_quick_alloc_array_with_access_check##suffix##_instrumented; \
44 qpoints->pAllocObject = art_quick_alloc_object##suffix##_instrumented; \
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080045 qpoints->pAllocObjectResolved = art_quick_alloc_object_resolved##suffix##_instrumented; \
46 qpoints->pAllocObjectInitialized = art_quick_alloc_object_initialized##suffix##_instrumented; \
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080047 qpoints->pAllocObjectWithAccessCheck = art_quick_alloc_object_with_access_check##suffix##_instrumented; \
48 qpoints->pCheckAndAllocArray = art_quick_check_and_alloc_array##suffix##_instrumented; \
49 qpoints->pCheckAndAllocArrayWithAccessCheck = art_quick_check_and_alloc_array_with_access_check##suffix##_instrumented; \
50 } else { \
51 qpoints->pAllocArray = art_quick_alloc_array##suffix; \
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -080052 qpoints->pAllocArrayResolved = art_quick_alloc_array_resolved##suffix; \
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080053 qpoints->pAllocArrayWithAccessCheck = art_quick_alloc_array_with_access_check##suffix; \
54 qpoints->pAllocObject = art_quick_alloc_object##suffix; \
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080055 qpoints->pAllocObjectResolved = art_quick_alloc_object_resolved##suffix; \
56 qpoints->pAllocObjectInitialized = art_quick_alloc_object_initialized##suffix; \
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080057 qpoints->pAllocObjectWithAccessCheck = art_quick_alloc_object_with_access_check##suffix; \
58 qpoints->pCheckAndAllocArray = art_quick_check_and_alloc_array##suffix; \
59 qpoints->pCheckAndAllocArrayWithAccessCheck = art_quick_check_and_alloc_array_with_access_check##suffix; \
60 } \
61}
62
63namespace art {
64
65// Generate the entrypoint functions.
Mathieu Chartiere6da9af2013-12-16 11:54:42 -080066GENERATE_ENTRYPOINTS(_dlmalloc);
67GENERATE_ENTRYPOINTS(_rosalloc);
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080068GENERATE_ENTRYPOINTS(_bump_pointer);
Mathieu Chartier692fafd2013-11-29 17:24:40 -080069GENERATE_ENTRYPOINTS(_tlab);
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080070
71static bool entry_points_instrumented = false;
Mathieu Chartiere6da9af2013-12-16 11:54:42 -080072static gc::AllocatorType entry_points_allocator = gc::kAllocatorTypeDlMalloc;
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080073
74void SetQuickAllocEntryPointsAllocator(gc::AllocatorType allocator) {
75 entry_points_allocator = allocator;
76}
77
78void SetQuickAllocEntryPointsInstrumented(bool instrumented) {
79 entry_points_instrumented = instrumented;
80}
81
82void ResetQuickAllocEntryPoints(QuickEntryPoints* qpoints) {
83 switch (entry_points_allocator) {
Mathieu Chartiere6da9af2013-12-16 11:54:42 -080084 case gc::kAllocatorTypeDlMalloc: {
85 SetQuickAllocEntryPoints_dlmalloc(qpoints, entry_points_instrumented);
86 break;
87 }
88 case gc::kAllocatorTypeRosAlloc: {
89 SetQuickAllocEntryPoints_rosalloc(qpoints, entry_points_instrumented);
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080090 break;
91 }
92 case gc::kAllocatorTypeBumpPointer: {
Mathieu Chartiere6da9af2013-12-16 11:54:42 -080093 CHECK(kMovingCollector);
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080094 SetQuickAllocEntryPoints_bump_pointer(qpoints, entry_points_instrumented);
95 break;
96 }
Mathieu Chartier692fafd2013-11-29 17:24:40 -080097 case gc::kAllocatorTypeTLAB: {
Mathieu Chartiere6da9af2013-12-16 11:54:42 -080098 CHECK(kMovingCollector);
Mathieu Chartier692fafd2013-11-29 17:24:40 -080099 SetQuickAllocEntryPoints_tlab(qpoints, entry_points_instrumented);
100 break;
101 }
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800102 default: {
103 LOG(FATAL) << "Unimplemented";
104 }
105 }
106}
107
108} // namespace art