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); \ |
Hiroshi Yamauchi | be1ca55 | 2014-01-15 11:46:48 -0800 | [diff] [blame] | 24 | extern "C" void* art_quick_alloc_object_resolved##suffix(void* klass, void* method); \ |
| 25 | extern "C" void* art_quick_alloc_object_initialized##suffix(void* klass, void* method); \ |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 26 | extern "C" void* art_quick_alloc_object_with_access_check##suffix(uint32_t type_idx, void* method); \ |
| 27 | extern "C" void* art_quick_check_and_alloc_array##suffix(uint32_t, void*, int32_t); \ |
| 28 | extern "C" void* art_quick_check_and_alloc_array_with_access_check##suffix(uint32_t, void*, int32_t); \ |
| 29 | extern "C" void* art_quick_alloc_array##suffix##_instrumented(uint32_t, void*, int32_t); \ |
| 30 | extern "C" void* art_quick_alloc_array_with_access_check##suffix##_instrumented(uint32_t, void*, int32_t); \ |
| 31 | extern "C" void* art_quick_alloc_object##suffix##_instrumented(uint32_t type_idx, void* method); \ |
Hiroshi Yamauchi | be1ca55 | 2014-01-15 11:46:48 -0800 | [diff] [blame] | 32 | extern "C" void* art_quick_alloc_object_resolved##suffix##_instrumented(void* klass, void* method); \ |
| 33 | extern "C" void* art_quick_alloc_object_initialized##suffix##_instrumented(void* klass, void* method); \ |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 34 | extern "C" void* art_quick_alloc_object_with_access_check##suffix##_instrumented(uint32_t type_idx, void* method); \ |
| 35 | extern "C" void* art_quick_check_and_alloc_array##suffix##_instrumented(uint32_t, void*, int32_t); \ |
| 36 | extern "C" void* art_quick_check_and_alloc_array_with_access_check##suffix##_instrumented(uint32_t, void*, int32_t); \ |
| 37 | void 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 Yamauchi | be1ca55 | 2014-01-15 11:46:48 -0800 | [diff] [blame] | 42 | qpoints->pAllocObjectResolved = art_quick_alloc_object_resolved##suffix##_instrumented; \ |
| 43 | qpoints->pAllocObjectInitialized = art_quick_alloc_object_initialized##suffix##_instrumented; \ |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 44 | 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 Yamauchi | be1ca55 | 2014-01-15 11:46:48 -0800 | [diff] [blame] | 51 | qpoints->pAllocObjectResolved = art_quick_alloc_object_resolved##suffix; \ |
| 52 | qpoints->pAllocObjectInitialized = art_quick_alloc_object_initialized##suffix; \ |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 53 | 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 | |
| 59 | namespace art { |
| 60 | |
| 61 | // Generate the entrypoint functions. |
Mathieu Chartier | e6da9af | 2013-12-16 11:54:42 -0800 | [diff] [blame] | 62 | GENERATE_ENTRYPOINTS(_dlmalloc); |
| 63 | GENERATE_ENTRYPOINTS(_rosalloc); |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 64 | GENERATE_ENTRYPOINTS(_bump_pointer); |
Mathieu Chartier | 692fafd | 2013-11-29 17:24:40 -0800 | [diff] [blame] | 65 | GENERATE_ENTRYPOINTS(_tlab); |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 66 | |
| 67 | static bool entry_points_instrumented = false; |
Mathieu Chartier | e6da9af | 2013-12-16 11:54:42 -0800 | [diff] [blame] | 68 | static gc::AllocatorType entry_points_allocator = gc::kAllocatorTypeDlMalloc; |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 69 | |
| 70 | void SetQuickAllocEntryPointsAllocator(gc::AllocatorType allocator) { |
| 71 | entry_points_allocator = allocator; |
| 72 | } |
| 73 | |
| 74 | void SetQuickAllocEntryPointsInstrumented(bool instrumented) { |
| 75 | entry_points_instrumented = instrumented; |
| 76 | } |
| 77 | |
| 78 | void ResetQuickAllocEntryPoints(QuickEntryPoints* qpoints) { |
| 79 | switch (entry_points_allocator) { |
Mathieu Chartier | e6da9af | 2013-12-16 11:54:42 -0800 | [diff] [blame] | 80 | 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 Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 86 | break; |
| 87 | } |
| 88 | case gc::kAllocatorTypeBumpPointer: { |
Mathieu Chartier | e6da9af | 2013-12-16 11:54:42 -0800 | [diff] [blame] | 89 | CHECK(kMovingCollector); |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 90 | SetQuickAllocEntryPoints_bump_pointer(qpoints, entry_points_instrumented); |
| 91 | break; |
| 92 | } |
Mathieu Chartier | 692fafd | 2013-11-29 17:24:40 -0800 | [diff] [blame] | 93 | case gc::kAllocatorTypeTLAB: { |
Mathieu Chartier | e6da9af | 2013-12-16 11:54:42 -0800 | [diff] [blame] | 94 | CHECK(kMovingCollector); |
Mathieu Chartier | 692fafd | 2013-11-29 17:24:40 -0800 | [diff] [blame] | 95 | SetQuickAllocEntryPoints_tlab(qpoints, entry_points_instrumented); |
| 96 | break; |
| 97 | } |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 98 | default: { |
| 99 | LOG(FATAL) << "Unimplemented"; |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | } // namespace art |