Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame^] | 1 | /* |
| 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) \ |
| 21 | extern "C" void* art_quick_alloc_array##suffix(uint32_t, void*, int32_t); \ |
| 22 | extern "C" void* art_quick_alloc_array_with_access_check##suffix(uint32_t, void*, int32_t); \ |
| 23 | extern "C" void* art_quick_alloc_object##suffix(uint32_t type_idx, void* method); \ |
| 24 | extern "C" void* art_quick_alloc_object_with_access_check##suffix(uint32_t type_idx, void* method); \ |
| 25 | extern "C" void* art_quick_check_and_alloc_array##suffix(uint32_t, void*, int32_t); \ |
| 26 | extern "C" void* art_quick_check_and_alloc_array_with_access_check##suffix(uint32_t, void*, int32_t); \ |
| 27 | extern "C" void* art_quick_alloc_array##suffix##_instrumented(uint32_t, void*, int32_t); \ |
| 28 | extern "C" void* art_quick_alloc_array_with_access_check##suffix##_instrumented(uint32_t, void*, int32_t); \ |
| 29 | extern "C" void* art_quick_alloc_object##suffix##_instrumented(uint32_t type_idx, void* method); \ |
| 30 | extern "C" void* art_quick_alloc_object_with_access_check##suffix##_instrumented(uint32_t type_idx, void* method); \ |
| 31 | extern "C" void* art_quick_check_and_alloc_array##suffix##_instrumented(uint32_t, void*, int32_t); \ |
| 32 | extern "C" void* art_quick_check_and_alloc_array_with_access_check##suffix##_instrumented(uint32_t, void*, int32_t); \ |
| 33 | void 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 | |
| 51 | namespace art { |
| 52 | |
| 53 | // Generate the entrypoint functions. |
| 54 | GENERATE_ENTRYPOINTS(); |
| 55 | GENERATE_ENTRYPOINTS(_bump_pointer); |
| 56 | |
| 57 | static bool entry_points_instrumented = false; |
| 58 | static gc::AllocatorType entry_points_allocator = kMovingCollector ? |
| 59 | gc::kAllocatorTypeBumpPointer : gc::kAllocatorTypeFreeList; |
| 60 | |
| 61 | void SetQuickAllocEntryPointsAllocator(gc::AllocatorType allocator) { |
| 62 | entry_points_allocator = allocator; |
| 63 | } |
| 64 | |
| 65 | void SetQuickAllocEntryPointsInstrumented(bool instrumented) { |
| 66 | entry_points_instrumented = instrumented; |
| 67 | } |
| 68 | |
| 69 | void 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 |