blob: fbbba1faf28a9d2e2b4e87db383a847b19330182 [file] [log] [blame]
Hiroshi Yamauchi50b29282013-07-30 13:58:37 -07001/*
2 * Copyright (C) 2011 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_DLMALLOC_SPACE_INL_H_
18#define ART_RUNTIME_GC_SPACE_DLMALLOC_SPACE_INL_H_
19
20#include "dlmalloc_space.h"
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -070021#include "thread.h"
Hiroshi Yamauchi50b29282013-07-30 13:58:37 -070022
23namespace art {
24namespace gc {
25namespace space {
26
27inline mirror::Object* DlMallocSpace::AllocNonvirtual(Thread* self, size_t num_bytes,
28 size_t* bytes_allocated) {
29 mirror::Object* obj;
30 {
31 MutexLock mu(self, lock_);
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -070032 obj = AllocWithoutGrowthLocked(self, num_bytes, bytes_allocated);
Hiroshi Yamauchi50b29282013-07-30 13:58:37 -070033 }
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -070034 if (LIKELY(obj != NULL)) {
Hiroshi Yamauchi50b29282013-07-30 13:58:37 -070035 // Zero freshly allocated memory, done while not holding the space's lock.
36 memset(obj, 0, num_bytes);
37 }
38 return obj;
39}
40
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -070041inline mirror::Object* DlMallocSpace::AllocWithoutGrowthLocked(Thread* /*self*/, size_t num_bytes,
42 size_t* bytes_allocated) {
Hiroshi Yamauchi50b29282013-07-30 13:58:37 -070043 mirror::Object* result = reinterpret_cast<mirror::Object*>(mspace_malloc(mspace_, num_bytes));
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -070044 if (LIKELY(result != NULL)) {
Hiroshi Yamauchi50b29282013-07-30 13:58:37 -070045 if (kDebugSpaces) {
46 CHECK(Contains(result)) << "Allocation (" << reinterpret_cast<void*>(result)
47 << ") not in bounds of allocation space " << *this;
48 }
49 size_t allocation_size = AllocationSizeNonvirtual(result);
Mathieu Chartiereb5710e2013-07-25 15:19:42 -070050 DCHECK(bytes_allocated != NULL);
51 *bytes_allocated = allocation_size;
Hiroshi Yamauchi50b29282013-07-30 13:58:37 -070052 }
53 return result;
54}
55
56} // namespace space
57} // namespace gc
58} // namespace art
59
60#endif // ART_RUNTIME_GC_SPACE_DLMALLOC_SPACE_INL_H_