blob: f6c9d3c144fe80ed9796aac55b505c560983d849 [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
Andreas Gamped7576322014-10-24 22:13:45 -070026inline ALWAYS_INLINE bool RosAlloc::ShouldCheckZeroMemory() {
27 return kCheckZeroMemory && !running_on_valgrind_;
28}
29
Mathieu Chartier0651d412014-04-29 14:37:57 -070030template<bool kThreadSafe>
Hiroshi Yamauchi3c2856e2013-11-22 13:42:53 -080031inline ALWAYS_INLINE void* RosAlloc::Alloc(Thread* self, size_t size, size_t* bytes_allocated) {
32 if (UNLIKELY(size > kLargeSizeThreshold)) {
33 return AllocLargeObject(self, size, bytes_allocated);
34 }
Mathieu Chartier0651d412014-04-29 14:37:57 -070035 void* m;
36 if (kThreadSafe) {
37 m = AllocFromRun(self, size, bytes_allocated);
38 } else {
39 m = AllocFromRunThreadUnsafe(self, size, bytes_allocated);
40 }
Hiroshi Yamauchi3c2856e2013-11-22 13:42:53 -080041 // Check if the returned memory is really all zero.
Andreas Gamped7576322014-10-24 22:13:45 -070042 if (ShouldCheckZeroMemory() && m != nullptr) {
Ian Rogers13735952014-10-08 12:43:28 -070043 uint8_t* bytes = reinterpret_cast<uint8_t*>(m);
Hiroshi Yamauchi3c2856e2013-11-22 13:42:53 -080044 for (size_t i = 0; i < size; ++i) {
45 DCHECK_EQ(bytes[i], 0);
46 }
47 }
48 return m;
49}
50
51} // namespace allocator
52} // namespace gc
53} // namespace art
54
55#endif // ART_RUNTIME_GC_ALLOCATOR_ROSALLOC_INL_H_