blob: 4cdb3f226fc0661cf12a85c56b3c752d56b5c8ed [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); \
24extern "C" void* art_quick_alloc_object_with_access_check##suffix(uint32_t type_idx, void* method); \
25extern "C" void* art_quick_check_and_alloc_array##suffix(uint32_t, void*, int32_t); \
26extern "C" void* art_quick_check_and_alloc_array_with_access_check##suffix(uint32_t, void*, int32_t); \
27extern "C" void* art_quick_alloc_array##suffix##_instrumented(uint32_t, void*, int32_t); \
28extern "C" void* art_quick_alloc_array_with_access_check##suffix##_instrumented(uint32_t, void*, int32_t); \
29extern "C" void* art_quick_alloc_object##suffix##_instrumented(uint32_t type_idx, void* method); \
30extern "C" void* art_quick_alloc_object_with_access_check##suffix##_instrumented(uint32_t type_idx, void* method); \
31extern "C" void* art_quick_check_and_alloc_array##suffix##_instrumented(uint32_t, void*, int32_t); \
32extern "C" void* art_quick_check_and_alloc_array_with_access_check##suffix##_instrumented(uint32_t, void*, int32_t); \
33void SetQuickAllocEntryPoints##suffix(QuickEntryPoints* qpoints, bool instrumented) { \
34 if (instrumented) { \
35 qpoints->pAllocArray = art_quick_alloc_array##suffix##_instrumented; \
36 qpoints->pAllocArrayWithAccessCheck = art_quick_alloc_array_with_access_check##suffix##_instrumented; \
37 qpoints->pAllocObject = art_quick_alloc_object##suffix##_instrumented; \
38 qpoints->pAllocObjectWithAccessCheck = art_quick_alloc_object_with_access_check##suffix##_instrumented; \
39 qpoints->pCheckAndAllocArray = art_quick_check_and_alloc_array##suffix##_instrumented; \
40 qpoints->pCheckAndAllocArrayWithAccessCheck = art_quick_check_and_alloc_array_with_access_check##suffix##_instrumented; \
41 } else { \
42 qpoints->pAllocArray = art_quick_alloc_array##suffix; \
43 qpoints->pAllocArrayWithAccessCheck = art_quick_alloc_array_with_access_check##suffix; \
44 qpoints->pAllocObject = art_quick_alloc_object##suffix; \
45 qpoints->pAllocObjectWithAccessCheck = art_quick_alloc_object_with_access_check##suffix; \
46 qpoints->pCheckAndAllocArray = art_quick_check_and_alloc_array##suffix; \
47 qpoints->pCheckAndAllocArrayWithAccessCheck = art_quick_check_and_alloc_array_with_access_check##suffix; \
48 } \
49}
50
51namespace art {
52
53// Generate the entrypoint functions.
54GENERATE_ENTRYPOINTS();
55GENERATE_ENTRYPOINTS(_bump_pointer);
Mathieu Chartier692fafd2013-11-29 17:24:40 -080056GENERATE_ENTRYPOINTS(_tlab);
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080057
58static bool entry_points_instrumented = false;
59static gc::AllocatorType entry_points_allocator = kMovingCollector ?
60 gc::kAllocatorTypeBumpPointer : gc::kAllocatorTypeFreeList;
61
62void SetQuickAllocEntryPointsAllocator(gc::AllocatorType allocator) {
63 entry_points_allocator = allocator;
64}
65
66void SetQuickAllocEntryPointsInstrumented(bool instrumented) {
67 entry_points_instrumented = instrumented;
68}
69
70void ResetQuickAllocEntryPoints(QuickEntryPoints* qpoints) {
71 switch (entry_points_allocator) {
72 case gc::kAllocatorTypeFreeList: {
73 SetQuickAllocEntryPoints(qpoints, entry_points_instrumented);
74 break;
75 }
76 case gc::kAllocatorTypeBumpPointer: {
77 SetQuickAllocEntryPoints_bump_pointer(qpoints, entry_points_instrumented);
78 break;
79 }
Mathieu Chartier692fafd2013-11-29 17:24:40 -080080 case gc::kAllocatorTypeTLAB: {
81 SetQuickAllocEntryPoints_tlab(qpoints, entry_points_instrumented);
82 break;
83 }
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080084 default: {
85 LOG(FATAL) << "Unimplemented";
86 }
87 }
88}
89
90} // namespace art