Hiroshi Yamauchi | 50b2928 | 2013-07-30 13:58:37 -0700 | [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 | #ifndef ART_RUNTIME_GC_SPACE_DLMALLOC_SPACE_INL_H_ |
| 18 | #define ART_RUNTIME_GC_SPACE_DLMALLOC_SPACE_INL_H_ |
| 19 | |
| 20 | #include "dlmalloc_space.h" |
Hiroshi Yamauchi | cf58d4a | 2013-09-26 14:21:22 -0700 | [diff] [blame^] | 21 | #include "thread.h" |
Hiroshi Yamauchi | 50b2928 | 2013-07-30 13:58:37 -0700 | [diff] [blame] | 22 | |
| 23 | namespace art { |
| 24 | namespace gc { |
| 25 | namespace space { |
| 26 | |
| 27 | inline mirror::Object* DlMallocSpace::AllocNonvirtual(Thread* self, size_t num_bytes, |
| 28 | size_t* bytes_allocated) { |
| 29 | mirror::Object* obj; |
| 30 | { |
| 31 | MutexLock mu(self, lock_); |
Hiroshi Yamauchi | cf58d4a | 2013-09-26 14:21:22 -0700 | [diff] [blame^] | 32 | obj = AllocWithoutGrowthLocked(self, num_bytes, bytes_allocated); |
Hiroshi Yamauchi | 50b2928 | 2013-07-30 13:58:37 -0700 | [diff] [blame] | 33 | } |
Hiroshi Yamauchi | 3b4c189 | 2013-09-12 21:33:12 -0700 | [diff] [blame] | 34 | if (LIKELY(obj != NULL)) { |
Hiroshi Yamauchi | 50b2928 | 2013-07-30 13:58:37 -0700 | [diff] [blame] | 35 | // Zero freshly allocated memory, done while not holding the space's lock. |
| 36 | memset(obj, 0, num_bytes); |
| 37 | } |
| 38 | return obj; |
| 39 | } |
| 40 | |
Hiroshi Yamauchi | cf58d4a | 2013-09-26 14:21:22 -0700 | [diff] [blame^] | 41 | inline mirror::Object* DlMallocSpace::AllocWithoutGrowthLocked(Thread* /*self*/, size_t num_bytes, |
| 42 | size_t* bytes_allocated) { |
Hiroshi Yamauchi | 50b2928 | 2013-07-30 13:58:37 -0700 | [diff] [blame] | 43 | mirror::Object* result = reinterpret_cast<mirror::Object*>(mspace_malloc(mspace_, num_bytes)); |
Hiroshi Yamauchi | 3b4c189 | 2013-09-12 21:33:12 -0700 | [diff] [blame] | 44 | if (LIKELY(result != NULL)) { |
Hiroshi Yamauchi | 50b2928 | 2013-07-30 13:58:37 -0700 | [diff] [blame] | 45 | if (kDebugSpaces) { |
| 46 | CHECK(Contains(result)) << "Allocation (" << reinterpret_cast<void*>(result) |
| 47 | << ") not in bounds of allocation space " << *this; |
| 48 | } |
| 49 | size_t allocation_size = AllocationSizeNonvirtual(result); |
Mathieu Chartier | eb5710e | 2013-07-25 15:19:42 -0700 | [diff] [blame] | 50 | DCHECK(bytes_allocated != NULL); |
| 51 | *bytes_allocated = allocation_size; |
Hiroshi Yamauchi | 50b2928 | 2013-07-30 13:58:37 -0700 | [diff] [blame] | 52 | } |
| 53 | return result; |
| 54 | } |
| 55 | |
| 56 | } // namespace space |
| 57 | } // namespace gc |
| 58 | } // namespace art |
| 59 | |
| 60 | #endif // ART_RUNTIME_GC_SPACE_DLMALLOC_SPACE_INL_H_ |