blob: 5de4265dc2d62dffe0015b9e7423304c5eabcda5 [file] [log] [blame]
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -07001/*
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
Hiroshi Yamauchi3c2856e2013-11-22 13:42:53 -080020#include "gc/allocator/rosalloc-inl.h"
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -070021#include "rosalloc_space.h"
22#include "thread.h"
23
24namespace art {
25namespace gc {
26namespace space {
27
28inline mirror::Object* RosAllocSpace::AllocNonvirtual(Thread* self, size_t num_bytes,
29 size_t* bytes_allocated) {
30 mirror::Object* obj;
31 obj = AllocWithoutGrowthLocked(self, num_bytes, bytes_allocated);
32 // RosAlloc zeroes memory internally.
33 return obj;
34}
35
36inline mirror::Object* RosAllocSpace::AllocWithoutGrowthLocked(Thread* self, size_t num_bytes,
37 size_t* bytes_allocated) {
38 size_t rosalloc_size = 0;
Hiroshi Yamauchi4ce1f002013-11-18 14:49:09 -080039 mirror::Object* result = reinterpret_cast<mirror::Object*>(
40 rosalloc_for_alloc_->Alloc(self, num_bytes,
41 &rosalloc_size));
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -070042 if (LIKELY(result != NULL)) {
43 if (kDebugSpaces) {
44 CHECK(Contains(result)) << "Allocation (" << reinterpret_cast<void*>(result)
45 << ") not in bounds of allocation space " << *this;
46 }
47 DCHECK(bytes_allocated != NULL);
48 *bytes_allocated = rosalloc_size;
49 }
50 return result;
51}
52
53} // namespace space
54} // namespace gc
55} // namespace art
56
57#endif // ART_RUNTIME_GC_SPACE_ROSALLOC_SPACE_INL_H_