blob: 192b1241e5a227b55058d17f4c627d11ba30e74e [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);
56
57static bool entry_points_instrumented = false;
58static gc::AllocatorType entry_points_allocator = kMovingCollector ?
59 gc::kAllocatorTypeBumpPointer : gc::kAllocatorTypeFreeList;
60
61void SetQuickAllocEntryPointsAllocator(gc::AllocatorType allocator) {
62 entry_points_allocator = allocator;
63}
64
65void SetQuickAllocEntryPointsInstrumented(bool instrumented) {
66 entry_points_instrumented = instrumented;
67}
68
69void ResetQuickAllocEntryPoints(QuickEntryPoints* qpoints) {
70 switch (entry_points_allocator) {
71 case gc::kAllocatorTypeFreeList: {
72 SetQuickAllocEntryPoints(qpoints, entry_points_instrumented);
73 break;
74 }
75 case gc::kAllocatorTypeBumpPointer: {
76 SetQuickAllocEntryPoints_bump_pointer(qpoints, entry_points_instrumented);
77 break;
78 }
79 default: {
80 LOG(FATAL) << "Unimplemented";
81 }
82 }
83}
84
85} // namespace art