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 26 template<bool kThreadSafe> 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 } 31 void* m; 32 if (kThreadSafe) { 33 m = AllocFromRun(self, size, bytes_allocated); 34 } else { 35 m = AllocFromRunThreadUnsafe(self, size, bytes_allocated); 36 } 37 // Check if the returned memory is really all zero. 38 if (kCheckZeroMemory && m != nullptr) { 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_ 52