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_SPACE_ROSALLOC_SPACE_INL_H_
18 #define ART_RUNTIME_GC_SPACE_ROSALLOC_SPACE_INL_H_
19
20 #include "rosalloc_space.h"
21
22 #include "base/memory_tool.h"
23 #include "gc/allocator/rosalloc-inl.h"
24 #include "gc/space/memory_tool_settings.h"
25 #include "thread.h"
26
27 namespace art {
28 namespace gc {
29 namespace space {
30
31 template<bool kThreadSafe>
AllocCommon(Thread * self,size_t num_bytes,size_t * bytes_allocated,size_t * usable_size,size_t * bytes_tl_bulk_allocated)32 inline mirror::Object* RosAllocSpace::AllocCommon(Thread* self, size_t num_bytes,
33 size_t* bytes_allocated, size_t* usable_size,
34 size_t* bytes_tl_bulk_allocated) {
35 size_t rosalloc_bytes_allocated = 0;
36 size_t rosalloc_usable_size = 0;
37 size_t rosalloc_bytes_tl_bulk_allocated = 0;
38 if (!kThreadSafe) {
39 Locks::mutator_lock_->AssertExclusiveHeld(self);
40 }
41 mirror::Object* result = reinterpret_cast<mirror::Object*>(
42 rosalloc_->Alloc<kThreadSafe>(self, num_bytes, &rosalloc_bytes_allocated,
43 &rosalloc_usable_size,
44 &rosalloc_bytes_tl_bulk_allocated));
45 if (LIKELY(result != nullptr)) {
46 if (kDebugSpaces) {
47 CHECK(Contains(result)) << "Allocation (" << reinterpret_cast<void*>(result)
48 << ") not in bounds of allocation space " << *this;
49 }
50 DCHECK(bytes_allocated != nullptr);
51 *bytes_allocated = rosalloc_bytes_allocated;
52 DCHECK_EQ(rosalloc_usable_size, rosalloc_->UsableSize(result));
53 if (usable_size != nullptr) {
54 *usable_size = rosalloc_usable_size;
55 }
56 DCHECK(bytes_tl_bulk_allocated != nullptr);
57 *bytes_tl_bulk_allocated = rosalloc_bytes_tl_bulk_allocated;
58 }
59 return result;
60 }
61
CanAllocThreadLocal(Thread * self,size_t num_bytes)62 inline bool RosAllocSpace::CanAllocThreadLocal(Thread* self, size_t num_bytes) {
63 return rosalloc_->CanAllocFromThreadLocalRun(self, num_bytes);
64 }
65
AllocThreadLocal(Thread * self,size_t num_bytes,size_t * bytes_allocated)66 inline mirror::Object* RosAllocSpace::AllocThreadLocal(Thread* self, size_t num_bytes,
67 size_t* bytes_allocated) {
68 DCHECK(bytes_allocated != nullptr);
69 return reinterpret_cast<mirror::Object*>(
70 rosalloc_->AllocFromThreadLocalRun(self, num_bytes, bytes_allocated));
71 }
72
MaxBytesBulkAllocatedForNonvirtual(size_t num_bytes)73 inline size_t RosAllocSpace::MaxBytesBulkAllocatedForNonvirtual(size_t num_bytes) {
74 return rosalloc_->MaxBytesBulkAllocatedFor(num_bytes);
75 }
76
77 } // namespace space
78 } // namespace gc
79 } // namespace art
80
81 #endif // ART_RUNTIME_GC_SPACE_ROSALLOC_SPACE_INL_H_
82