Hiroshi Yamauchi | 3c2856e | 2013-11-22 13:42:53 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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_ALLOCATOR_ROSALLOC_INL_H_ |
| 18 | #define ART_RUNTIME_GC_ALLOCATOR_ROSALLOC_INL_H_ |
| 19 | |
| 20 | #include "rosalloc.h" |
| 21 | |
| 22 | namespace art { |
| 23 | namespace gc { |
| 24 | namespace allocator { |
| 25 | |
Mathieu Chartier | 0651d41 | 2014-04-29 14:37:57 -0700 | [diff] [blame] | 26 | template<bool kThreadSafe> |
Hiroshi Yamauchi | 3c2856e | 2013-11-22 13:42:53 -0800 | [diff] [blame] | 27 | inline ALWAYS_INLINE void* RosAlloc::Alloc(Thread* self, size_t size, size_t* bytes_allocated) { |
| 28 | if (UNLIKELY(size > kLargeSizeThreshold)) { |
| 29 | return AllocLargeObject(self, size, bytes_allocated); |
| 30 | } |
Mathieu Chartier | 0651d41 | 2014-04-29 14:37:57 -0700 | [diff] [blame] | 31 | void* m; |
| 32 | if (kThreadSafe) { |
| 33 | m = AllocFromRun(self, size, bytes_allocated); |
| 34 | } else { |
| 35 | m = AllocFromRunThreadUnsafe(self, size, bytes_allocated); |
| 36 | } |
Hiroshi Yamauchi | 3c2856e | 2013-11-22 13:42:53 -0800 | [diff] [blame] | 37 | // Check if the returned memory is really all zero. |
Mathieu Chartier | 73d1e17 | 2014-04-11 17:53:48 -0700 | [diff] [blame] | 38 | if (kCheckZeroMemory && m != nullptr) { |
Hiroshi Yamauchi | 3c2856e | 2013-11-22 13:42:53 -0800 | [diff] [blame] | 39 | byte* bytes = reinterpret_cast<byte*>(m); |
| 40 | for (size_t i = 0; i < size; ++i) { |
| 41 | DCHECK_EQ(bytes[i], 0); |
| 42 | } |
| 43 | } |
| 44 | return m; |
| 45 | } |
| 46 | |
| 47 | } // namespace allocator |
| 48 | } // namespace gc |
| 49 | } // namespace art |
| 50 | |
| 51 | #endif // ART_RUNTIME_GC_ALLOCATOR_ROSALLOC_INL_H_ |