blob: c69ca48de8a581ed3f18908fb8cc6cd7638b0b32 [file] [log] [blame]
Hiroshi Yamauchi3c2856e2013-11-22 13:42:53 -08001/*
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
22namespace art {
23namespace gc {
24namespace allocator {
25
Mathieu Chartier0651d412014-04-29 14:37:57 -070026template<bool kThreadSafe>
Hiroshi Yamauchi3c2856e2013-11-22 13:42:53 -080027inline 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 Chartier0651d412014-04-29 14:37:57 -070031 void* m;
32 if (kThreadSafe) {
33 m = AllocFromRun(self, size, bytes_allocated);
34 } else {
35 m = AllocFromRunThreadUnsafe(self, size, bytes_allocated);
36 }
Hiroshi Yamauchi3c2856e2013-11-22 13:42:53 -080037 // Check if the returned memory is really all zero.
Mathieu Chartier73d1e172014-04-11 17:53:48 -070038 if (kCheckZeroMemory && m != nullptr) {
Hiroshi Yamauchi3c2856e2013-11-22 13:42:53 -080039 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_