Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 | |
Mathieu Chartier | d889178 | 2014-03-02 13:28:37 -0800 | [diff] [blame^] | 17 | #include "entrypoints/quick/quick_alloc_entrypoints.h" |
| 18 | |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 19 | #include "callee_save_frame.h" |
Ian Rogers | 7655f29 | 2013-07-29 11:07:13 -0700 | [diff] [blame] | 20 | #include "entrypoints/entrypoint_utils.h" |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 21 | #include "mirror/art_method-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 22 | #include "mirror/class-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 23 | #include "mirror/object_array-inl.h" |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 24 | #include "mirror/object-inl.h" |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 25 | |
| 26 | namespace art { |
| 27 | |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 28 | #define GENERATE_ENTRYPOINTS_FOR_ALLOCATOR_INST(suffix, suffix2, instrumented_bool, allocator_type) \ |
| 29 | extern "C" mirror::Object* artAllocObjectFromCode ##suffix##suffix2( \ |
| 30 | uint32_t type_idx, mirror::ArtMethod* method, Thread* self, mirror::ArtMethod** sp) \ |
| 31 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { \ |
| 32 | FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsOnly); \ |
| 33 | return AllocObjectFromCode<false, instrumented_bool>(type_idx, method, self, allocator_type); \ |
| 34 | } \ |
Hiroshi Yamauchi | be1ca55 | 2014-01-15 11:46:48 -0800 | [diff] [blame] | 35 | extern "C" mirror::Object* artAllocObjectFromCodeResolved##suffix##suffix2( \ |
| 36 | mirror::Class* klass, mirror::ArtMethod* method, Thread* self, mirror::ArtMethod** sp) \ |
| 37 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { \ |
| 38 | FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsOnly); \ |
| 39 | return AllocObjectFromCodeResolved<instrumented_bool>(klass, method, self, allocator_type); \ |
| 40 | } \ |
| 41 | extern "C" mirror::Object* artAllocObjectFromCodeInitialized##suffix##suffix2( \ |
| 42 | mirror::Class* klass, mirror::ArtMethod* method, Thread* self, mirror::ArtMethod** sp) \ |
| 43 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { \ |
| 44 | FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsOnly); \ |
| 45 | return AllocObjectFromCodeInitialized<instrumented_bool>(klass, method, self, allocator_type); \ |
| 46 | } \ |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 47 | extern "C" mirror::Object* artAllocObjectFromCodeWithAccessCheck##suffix##suffix2( \ |
| 48 | uint32_t type_idx, mirror::ArtMethod* method, Thread* self, mirror::ArtMethod** sp) \ |
| 49 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { \ |
| 50 | FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsOnly); \ |
| 51 | return AllocObjectFromCode<true, instrumented_bool>(type_idx, method, self, allocator_type); \ |
| 52 | } \ |
| 53 | extern "C" mirror::Array* artAllocArrayFromCode##suffix##suffix2( \ |
| 54 | uint32_t type_idx, mirror::ArtMethod* method, int32_t component_count, Thread* self, \ |
| 55 | mirror::ArtMethod** sp) \ |
| 56 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { \ |
| 57 | FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsOnly); \ |
| 58 | return AllocArrayFromCode<false, instrumented_bool>(type_idx, method, component_count, self, \ |
| 59 | allocator_type); \ |
| 60 | } \ |
Hiroshi Yamauchi | bb8f0ab | 2014-01-27 16:50:29 -0800 | [diff] [blame] | 61 | extern "C" mirror::Array* artAllocArrayFromCodeResolved##suffix##suffix2( \ |
| 62 | mirror::Class* klass, mirror::ArtMethod* method, int32_t component_count, Thread* self, \ |
| 63 | mirror::ArtMethod** sp) \ |
| 64 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { \ |
| 65 | FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsOnly); \ |
| 66 | return AllocArrayFromCodeResolved<false, instrumented_bool>(klass, method, component_count, self, \ |
| 67 | allocator_type); \ |
| 68 | } \ |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 69 | extern "C" mirror::Array* artAllocArrayFromCodeWithAccessCheck##suffix##suffix2( \ |
| 70 | uint32_t type_idx, mirror::ArtMethod* method, int32_t component_count, Thread* self, \ |
| 71 | mirror::ArtMethod** sp) \ |
| 72 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { \ |
| 73 | FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsOnly); \ |
| 74 | return AllocArrayFromCode<true, instrumented_bool>(type_idx, method, component_count, self, \ |
| 75 | allocator_type); \ |
| 76 | } \ |
| 77 | extern "C" mirror::Array* artCheckAndAllocArrayFromCode##suffix##suffix2( \ |
| 78 | uint32_t type_idx, mirror::ArtMethod* method, int32_t component_count, Thread* self, \ |
| 79 | mirror::ArtMethod** sp) \ |
| 80 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { \ |
| 81 | FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsOnly); \ |
Hiroshi Yamauchi | cbbb080 | 2013-11-21 12:42:36 -0800 | [diff] [blame] | 82 | if (!instrumented_bool) { \ |
| 83 | return CheckAndAllocArrayFromCode(type_idx, method, component_count, self, false, allocator_type); \ |
| 84 | } else { \ |
| 85 | return CheckAndAllocArrayFromCodeInstrumented(type_idx, method, component_count, self, false, allocator_type); \ |
| 86 | } \ |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 87 | } \ |
| 88 | extern "C" mirror::Array* artCheckAndAllocArrayFromCodeWithAccessCheck##suffix##suffix2( \ |
| 89 | uint32_t type_idx, mirror::ArtMethod* method, int32_t component_count, Thread* self, \ |
| 90 | mirror::ArtMethod** sp) \ |
| 91 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { \ |
| 92 | FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsOnly); \ |
Hiroshi Yamauchi | cbbb080 | 2013-11-21 12:42:36 -0800 | [diff] [blame] | 93 | if (!instrumented_bool) { \ |
| 94 | return CheckAndAllocArrayFromCode(type_idx, method, component_count, self, true, allocator_type); \ |
| 95 | } else { \ |
| 96 | return CheckAndAllocArrayFromCodeInstrumented(type_idx, method, component_count, self, true, allocator_type); \ |
| 97 | } \ |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 98 | } |
| 99 | |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 100 | #define GENERATE_ENTRYPOINTS_FOR_ALLOCATOR(suffix, allocator_type) \ |
| 101 | GENERATE_ENTRYPOINTS_FOR_ALLOCATOR_INST(suffix, Instrumented, true, allocator_type) \ |
| 102 | GENERATE_ENTRYPOINTS_FOR_ALLOCATOR_INST(suffix, , false, allocator_type) |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 103 | |
Mathieu Chartier | e6da9af | 2013-12-16 11:54:42 -0800 | [diff] [blame] | 104 | GENERATE_ENTRYPOINTS_FOR_ALLOCATOR(DlMalloc, gc::kAllocatorTypeDlMalloc) |
| 105 | GENERATE_ENTRYPOINTS_FOR_ALLOCATOR(RosAlloc, gc::kAllocatorTypeRosAlloc) |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 106 | GENERATE_ENTRYPOINTS_FOR_ALLOCATOR(BumpPointer, gc::kAllocatorTypeBumpPointer) |
Mathieu Chartier | 692fafd | 2013-11-29 17:24:40 -0800 | [diff] [blame] | 107 | GENERATE_ENTRYPOINTS_FOR_ALLOCATOR(TLAB, gc::kAllocatorTypeTLAB) |
Hiroshi Yamauchi | 3b4c189 | 2013-09-12 21:33:12 -0700 | [diff] [blame] | 108 | |
Mathieu Chartier | d889178 | 2014-03-02 13:28:37 -0800 | [diff] [blame^] | 109 | #define GENERATE_ENTRYPOINTS(suffix) \ |
| 110 | extern "C" void* art_quick_alloc_array##suffix(uint32_t, void*, int32_t); \ |
| 111 | extern "C" void* art_quick_alloc_array_resolved##suffix(void* klass, void*, int32_t); \ |
| 112 | extern "C" void* art_quick_alloc_array_with_access_check##suffix(uint32_t, void*, int32_t); \ |
| 113 | extern "C" void* art_quick_alloc_object##suffix(uint32_t type_idx, void* method); \ |
| 114 | extern "C" void* art_quick_alloc_object_resolved##suffix(void* klass, void* method); \ |
| 115 | extern "C" void* art_quick_alloc_object_initialized##suffix(void* klass, void* method); \ |
| 116 | extern "C" void* art_quick_alloc_object_with_access_check##suffix(uint32_t type_idx, void* method); \ |
| 117 | extern "C" void* art_quick_check_and_alloc_array##suffix(uint32_t, void*, int32_t); \ |
| 118 | extern "C" void* art_quick_check_and_alloc_array_with_access_check##suffix(uint32_t, void*, int32_t); \ |
| 119 | extern "C" void* art_quick_alloc_array##suffix##_instrumented(uint32_t, void*, int32_t); \ |
| 120 | extern "C" void* art_quick_alloc_array_resolved##suffix##_instrumented(void* klass, void*, int32_t); \ |
| 121 | extern "C" void* art_quick_alloc_array_with_access_check##suffix##_instrumented(uint32_t, void*, int32_t); \ |
| 122 | extern "C" void* art_quick_alloc_object##suffix##_instrumented(uint32_t type_idx, void* method); \ |
| 123 | extern "C" void* art_quick_alloc_object_resolved##suffix##_instrumented(void* klass, void* method); \ |
| 124 | extern "C" void* art_quick_alloc_object_initialized##suffix##_instrumented(void* klass, void* method); \ |
| 125 | extern "C" void* art_quick_alloc_object_with_access_check##suffix##_instrumented(uint32_t type_idx, void* method); \ |
| 126 | extern "C" void* art_quick_check_and_alloc_array##suffix##_instrumented(uint32_t, void*, int32_t); \ |
| 127 | extern "C" void* art_quick_check_and_alloc_array_with_access_check##suffix##_instrumented(uint32_t, void*, int32_t); \ |
| 128 | void SetQuickAllocEntryPoints##suffix(QuickEntryPoints* qpoints, bool instrumented) { \ |
| 129 | if (instrumented) { \ |
| 130 | qpoints->pAllocArray = art_quick_alloc_array##suffix##_instrumented; \ |
| 131 | qpoints->pAllocArrayResolved = art_quick_alloc_array_resolved##suffix##_instrumented; \ |
| 132 | qpoints->pAllocArrayWithAccessCheck = art_quick_alloc_array_with_access_check##suffix##_instrumented; \ |
| 133 | qpoints->pAllocObject = art_quick_alloc_object##suffix##_instrumented; \ |
| 134 | qpoints->pAllocObjectResolved = art_quick_alloc_object_resolved##suffix##_instrumented; \ |
| 135 | qpoints->pAllocObjectInitialized = art_quick_alloc_object_initialized##suffix##_instrumented; \ |
| 136 | qpoints->pAllocObjectWithAccessCheck = art_quick_alloc_object_with_access_check##suffix##_instrumented; \ |
| 137 | qpoints->pCheckAndAllocArray = art_quick_check_and_alloc_array##suffix##_instrumented; \ |
| 138 | qpoints->pCheckAndAllocArrayWithAccessCheck = art_quick_check_and_alloc_array_with_access_check##suffix##_instrumented; \ |
| 139 | } else { \ |
| 140 | qpoints->pAllocArray = art_quick_alloc_array##suffix; \ |
| 141 | qpoints->pAllocArrayResolved = art_quick_alloc_array_resolved##suffix; \ |
| 142 | qpoints->pAllocArrayWithAccessCheck = art_quick_alloc_array_with_access_check##suffix; \ |
| 143 | qpoints->pAllocObject = art_quick_alloc_object##suffix; \ |
| 144 | qpoints->pAllocObjectResolved = art_quick_alloc_object_resolved##suffix; \ |
| 145 | qpoints->pAllocObjectInitialized = art_quick_alloc_object_initialized##suffix; \ |
| 146 | qpoints->pAllocObjectWithAccessCheck = art_quick_alloc_object_with_access_check##suffix; \ |
| 147 | qpoints->pCheckAndAllocArray = art_quick_check_and_alloc_array##suffix; \ |
| 148 | qpoints->pCheckAndAllocArrayWithAccessCheck = art_quick_check_and_alloc_array_with_access_check##suffix; \ |
| 149 | } \ |
| 150 | } |
| 151 | |
| 152 | // Generate the entrypoint functions. |
| 153 | GENERATE_ENTRYPOINTS(_dlmalloc); |
| 154 | GENERATE_ENTRYPOINTS(_rosalloc); |
| 155 | GENERATE_ENTRYPOINTS(_bump_pointer); |
| 156 | GENERATE_ENTRYPOINTS(_tlab); |
| 157 | |
| 158 | static bool entry_points_instrumented = false; |
| 159 | static gc::AllocatorType entry_points_allocator = gc::kAllocatorTypeDlMalloc; |
| 160 | |
| 161 | void SetQuickAllocEntryPointsAllocator(gc::AllocatorType allocator) { |
| 162 | entry_points_allocator = allocator; |
| 163 | } |
| 164 | |
| 165 | void SetQuickAllocEntryPointsInstrumented(bool instrumented) { |
| 166 | entry_points_instrumented = instrumented; |
| 167 | } |
| 168 | |
| 169 | void ResetQuickAllocEntryPoints(QuickEntryPoints* qpoints) { |
| 170 | switch (entry_points_allocator) { |
| 171 | case gc::kAllocatorTypeDlMalloc: { |
| 172 | SetQuickAllocEntryPoints_dlmalloc(qpoints, entry_points_instrumented); |
| 173 | break; |
| 174 | } |
| 175 | case gc::kAllocatorTypeRosAlloc: { |
| 176 | SetQuickAllocEntryPoints_rosalloc(qpoints, entry_points_instrumented); |
| 177 | break; |
| 178 | } |
| 179 | case gc::kAllocatorTypeBumpPointer: { |
| 180 | CHECK(kMovingCollector); |
| 181 | SetQuickAllocEntryPoints_bump_pointer(qpoints, entry_points_instrumented); |
| 182 | break; |
| 183 | } |
| 184 | case gc::kAllocatorTypeTLAB: { |
| 185 | CHECK(kMovingCollector); |
| 186 | SetQuickAllocEntryPoints_tlab(qpoints, entry_points_instrumented); |
| 187 | break; |
| 188 | } |
| 189 | default: { |
| 190 | LOG(FATAL) << "Unimplemented"; |
| 191 | } |
| 192 | } |
| 193 | } |
| 194 | |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 195 | } // namespace art |