rosalloc-inl.h revision 13735955f39b3b304c37d2b2840663c131262c18
13c2856e939f3daa7a95a1f8cb70f47e7a621db3cHiroshi Yamauchi/* 23c2856e939f3daa7a95a1f8cb70f47e7a621db3cHiroshi Yamauchi * Copyright (C) 2013 The Android Open Source Project 33c2856e939f3daa7a95a1f8cb70f47e7a621db3cHiroshi Yamauchi * 43c2856e939f3daa7a95a1f8cb70f47e7a621db3cHiroshi Yamauchi * Licensed under the Apache License, Version 2.0 (the "License"); 53c2856e939f3daa7a95a1f8cb70f47e7a621db3cHiroshi Yamauchi * you may not use this file except in compliance with the License. 63c2856e939f3daa7a95a1f8cb70f47e7a621db3cHiroshi Yamauchi * You may obtain a copy of the License at 73c2856e939f3daa7a95a1f8cb70f47e7a621db3cHiroshi Yamauchi * 83c2856e939f3daa7a95a1f8cb70f47e7a621db3cHiroshi Yamauchi * http://www.apache.org/licenses/LICENSE-2.0 93c2856e939f3daa7a95a1f8cb70f47e7a621db3cHiroshi Yamauchi * 103c2856e939f3daa7a95a1f8cb70f47e7a621db3cHiroshi Yamauchi * Unless required by applicable law or agreed to in writing, software 113c2856e939f3daa7a95a1f8cb70f47e7a621db3cHiroshi Yamauchi * distributed under the License is distributed on an "AS IS" BASIS, 123c2856e939f3daa7a95a1f8cb70f47e7a621db3cHiroshi Yamauchi * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 133c2856e939f3daa7a95a1f8cb70f47e7a621db3cHiroshi Yamauchi * See the License for the specific language governing permissions and 143c2856e939f3daa7a95a1f8cb70f47e7a621db3cHiroshi Yamauchi * limitations under the License. 153c2856e939f3daa7a95a1f8cb70f47e7a621db3cHiroshi Yamauchi */ 163c2856e939f3daa7a95a1f8cb70f47e7a621db3cHiroshi Yamauchi 173c2856e939f3daa7a95a1f8cb70f47e7a621db3cHiroshi Yamauchi#ifndef ART_RUNTIME_GC_ALLOCATOR_ROSALLOC_INL_H_ 183c2856e939f3daa7a95a1f8cb70f47e7a621db3cHiroshi Yamauchi#define ART_RUNTIME_GC_ALLOCATOR_ROSALLOC_INL_H_ 193c2856e939f3daa7a95a1f8cb70f47e7a621db3cHiroshi Yamauchi 203c2856e939f3daa7a95a1f8cb70f47e7a621db3cHiroshi Yamauchi#include "rosalloc.h" 213c2856e939f3daa7a95a1f8cb70f47e7a621db3cHiroshi Yamauchi 223c2856e939f3daa7a95a1f8cb70f47e7a621db3cHiroshi Yamauchinamespace art { 233c2856e939f3daa7a95a1f8cb70f47e7a621db3cHiroshi Yamauchinamespace gc { 243c2856e939f3daa7a95a1f8cb70f47e7a621db3cHiroshi Yamauchinamespace allocator { 253c2856e939f3daa7a95a1f8cb70f47e7a621db3cHiroshi Yamauchi 260651d41e41341fb2e9ef3ee41dc1f1bfc832dbbbMathieu Chartiertemplate<bool kThreadSafe> 273c2856e939f3daa7a95a1f8cb70f47e7a621db3cHiroshi Yamauchiinline ALWAYS_INLINE void* RosAlloc::Alloc(Thread* self, size_t size, size_t* bytes_allocated) { 283c2856e939f3daa7a95a1f8cb70f47e7a621db3cHiroshi Yamauchi if (UNLIKELY(size > kLargeSizeThreshold)) { 293c2856e939f3daa7a95a1f8cb70f47e7a621db3cHiroshi Yamauchi return AllocLargeObject(self, size, bytes_allocated); 303c2856e939f3daa7a95a1f8cb70f47e7a621db3cHiroshi Yamauchi } 310651d41e41341fb2e9ef3ee41dc1f1bfc832dbbbMathieu Chartier void* m; 320651d41e41341fb2e9ef3ee41dc1f1bfc832dbbbMathieu Chartier if (kThreadSafe) { 330651d41e41341fb2e9ef3ee41dc1f1bfc832dbbbMathieu Chartier m = AllocFromRun(self, size, bytes_allocated); 340651d41e41341fb2e9ef3ee41dc1f1bfc832dbbbMathieu Chartier } else { 350651d41e41341fb2e9ef3ee41dc1f1bfc832dbbbMathieu Chartier m = AllocFromRunThreadUnsafe(self, size, bytes_allocated); 360651d41e41341fb2e9ef3ee41dc1f1bfc832dbbbMathieu Chartier } 373c2856e939f3daa7a95a1f8cb70f47e7a621db3cHiroshi Yamauchi // Check if the returned memory is really all zero. 3873d1e17b3afc7d5e56184f90bf819dc64956448aMathieu Chartier if (kCheckZeroMemory && m != nullptr) { 3913735955f39b3b304c37d2b2840663c131262c18Ian Rogers uint8_t* bytes = reinterpret_cast<uint8_t*>(m); 403c2856e939f3daa7a95a1f8cb70f47e7a621db3cHiroshi Yamauchi for (size_t i = 0; i < size; ++i) { 413c2856e939f3daa7a95a1f8cb70f47e7a621db3cHiroshi Yamauchi DCHECK_EQ(bytes[i], 0); 423c2856e939f3daa7a95a1f8cb70f47e7a621db3cHiroshi Yamauchi } 433c2856e939f3daa7a95a1f8cb70f47e7a621db3cHiroshi Yamauchi } 443c2856e939f3daa7a95a1f8cb70f47e7a621db3cHiroshi Yamauchi return m; 453c2856e939f3daa7a95a1f8cb70f47e7a621db3cHiroshi Yamauchi} 463c2856e939f3daa7a95a1f8cb70f47e7a621db3cHiroshi Yamauchi 473c2856e939f3daa7a95a1f8cb70f47e7a621db3cHiroshi Yamauchi} // namespace allocator 483c2856e939f3daa7a95a1f8cb70f47e7a621db3cHiroshi Yamauchi} // namespace gc 493c2856e939f3daa7a95a1f8cb70f47e7a621db3cHiroshi Yamauchi} // namespace art 503c2856e939f3daa7a95a1f8cb70f47e7a621db3cHiroshi Yamauchi 513c2856e939f3daa7a95a1f8cb70f47e7a621db3cHiroshi Yamauchi#endif // ART_RUNTIME_GC_ALLOCATOR_ROSALLOC_INL_H_ 52