blob: 0fad82266c7430f36b0751d6f3c0c421b6b7ce0e [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); \
22extern "C" void* art_quick_alloc_array_with_access_check##suffix(uint32_t, void*, int32_t); \
23extern "C" void* art_quick_alloc_object##suffix(uint32_t type_idx, void* method); \
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080024extern "C" void* art_quick_alloc_object_resolved##suffix(void* klass, void* method); \
25extern "C" void* art_quick_alloc_object_initialized##suffix(void* klass, void* method); \
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080026extern "C" void* art_quick_alloc_object_with_access_check##suffix(uint32_t type_idx, void* method); \
27extern "C" void* art_quick_check_and_alloc_array##suffix(uint32_t, void*, int32_t); \
28extern "C" void* art_quick_check_and_alloc_array_with_access_check##suffix(uint32_t, void*, int32_t); \
29extern "C" void* art_quick_alloc_array##suffix##_instrumented(uint32_t, void*, int32_t); \
30extern "C" void* art_quick_alloc_array_with_access_check##suffix##_instrumented(uint32_t, void*, int32_t); \
31extern "C" void* art_quick_alloc_object##suffix##_instrumented(uint32_t type_idx, void* method); \
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080032extern "C" void* art_quick_alloc_object_resolved##suffix##_instrumented(void* klass, void* method); \
33extern "C" void* art_quick_alloc_object_initialized##suffix##_instrumented(void* klass, void* method); \
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080034extern "C" void* art_quick_alloc_object_with_access_check##suffix##_instrumented(uint32_t type_idx, void* method); \
35extern "C" void* art_quick_check_and_alloc_array##suffix##_instrumented(uint32_t, void*, int32_t); \
36extern "C" void* art_quick_check_and_alloc_array_with_access_check##suffix##_instrumented(uint32_t, void*, int32_t); \
37void SetQuickAllocEntryPoints##suffix(QuickEntryPoints* qpoints, bool instrumented) { \
38 if (instrumented) { \
39 qpoints->pAllocArray = art_quick_alloc_array##suffix##_instrumented; \
40 qpoints->pAllocArrayWithAccessCheck = art_quick_alloc_array_with_access_check##suffix##_instrumented; \
41 qpoints->pAllocObject = art_quick_alloc_object##suffix##_instrumented; \
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080042 qpoints->pAllocObjectResolved = art_quick_alloc_object_resolved##suffix##_instrumented; \
43 qpoints->pAllocObjectInitialized = art_quick_alloc_object_initialized##suffix##_instrumented; \
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080044 qpoints->pAllocObjectWithAccessCheck = art_quick_alloc_object_with_access_check##suffix##_instrumented; \
45 qpoints->pCheckAndAllocArray = art_quick_check_and_alloc_array##suffix##_instrumented; \
46 qpoints->pCheckAndAllocArrayWithAccessCheck = art_quick_check_and_alloc_array_with_access_check##suffix##_instrumented; \
47 } else { \
48 qpoints->pAllocArray = art_quick_alloc_array##suffix; \
49 qpoints->pAllocArrayWithAccessCheck = art_quick_alloc_array_with_access_check##suffix; \
50 qpoints->pAllocObject = art_quick_alloc_object##suffix; \
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080051 qpoints->pAllocObjectResolved = art_quick_alloc_object_resolved##suffix; \
52 qpoints->pAllocObjectInitialized = art_quick_alloc_object_initialized##suffix; \
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080053 qpoints->pAllocObjectWithAccessCheck = art_quick_alloc_object_with_access_check##suffix; \
54 qpoints->pCheckAndAllocArray = art_quick_check_and_alloc_array##suffix; \
55 qpoints->pCheckAndAllocArrayWithAccessCheck = art_quick_check_and_alloc_array_with_access_check##suffix; \
56 } \
57}
58
59namespace art {
60
61// Generate the entrypoint functions.
Mathieu Chartiere6da9af2013-12-16 11:54:42 -080062GENERATE_ENTRYPOINTS(_dlmalloc);
63GENERATE_ENTRYPOINTS(_rosalloc);
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080064GENERATE_ENTRYPOINTS(_bump_pointer);
Mathieu Chartier692fafd2013-11-29 17:24:40 -080065GENERATE_ENTRYPOINTS(_tlab);
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080066
67static bool entry_points_instrumented = false;
Mathieu Chartiere6da9af2013-12-16 11:54:42 -080068static gc::AllocatorType entry_points_allocator = gc::kAllocatorTypeDlMalloc;
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080069
70void SetQuickAllocEntryPointsAllocator(gc::AllocatorType allocator) {
71 entry_points_allocator = allocator;
72}
73
74void SetQuickAllocEntryPointsInstrumented(bool instrumented) {
75 entry_points_instrumented = instrumented;
76}
77
78void ResetQuickAllocEntryPoints(QuickEntryPoints* qpoints) {
79 switch (entry_points_allocator) {
Mathieu Chartiere6da9af2013-12-16 11:54:42 -080080 case gc::kAllocatorTypeDlMalloc: {
81 SetQuickAllocEntryPoints_dlmalloc(qpoints, entry_points_instrumented);
82 break;
83 }
84 case gc::kAllocatorTypeRosAlloc: {
85 SetQuickAllocEntryPoints_rosalloc(qpoints, entry_points_instrumented);
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080086 break;
87 }
88 case gc::kAllocatorTypeBumpPointer: {
Mathieu Chartiere6da9af2013-12-16 11:54:42 -080089 CHECK(kMovingCollector);
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080090 SetQuickAllocEntryPoints_bump_pointer(qpoints, entry_points_instrumented);
91 break;
92 }
Mathieu Chartier692fafd2013-11-29 17:24:40 -080093 case gc::kAllocatorTypeTLAB: {
Mathieu Chartiere6da9af2013-12-16 11:54:42 -080094 CHECK(kMovingCollector);
Mathieu Chartier692fafd2013-11-29 17:24:40 -080095 SetQuickAllocEntryPoints_tlab(qpoints, entry_points_instrumented);
96 break;
97 }
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080098 default: {
99 LOG(FATAL) << "Unimplemented";
100 }
101 }
102}
103
104} // namespace art