1 /*
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"
21
22 namespace art {
23 namespace gc {
24 namespace space {
25
AllocNonvirtual(Thread * self,size_t num_bytes,size_t * bytes_allocated)26 inline mirror::Object* DlMallocSpace::AllocNonvirtual(Thread* self, size_t num_bytes,
27 size_t* bytes_allocated) {
28 mirror::Object* obj;
29 {
30 MutexLock mu(self, lock_);
31 obj = AllocWithoutGrowthLocked(num_bytes, bytes_allocated);
32 }
33 if (obj != NULL) {
34 // Zero freshly allocated memory, done while not holding the space's lock.
35 memset(obj, 0, num_bytes);
36 }
37 return obj;
38 }
39
AllocWithoutGrowthLocked(size_t num_bytes,size_t * bytes_allocated)40 inline mirror::Object* DlMallocSpace::AllocWithoutGrowthLocked(size_t num_bytes, size_t* bytes_allocated) {
41 mirror::Object* result = reinterpret_cast<mirror::Object*>(mspace_malloc(mspace_, num_bytes));
42 if (result != NULL) {
43 if (kDebugSpaces) {
44 CHECK(Contains(result)) << "Allocation (" << reinterpret_cast<void*>(result)
45 << ") not in bounds of allocation space " << *this;
46 }
47 size_t allocation_size = AllocationSizeNonvirtual(result);
48 DCHECK(bytes_allocated != NULL);
49 *bytes_allocated = allocation_size;
50 num_bytes_allocated_ += allocation_size;
51 total_bytes_allocated_ += allocation_size;
52 ++total_objects_allocated_;
53 ++num_objects_allocated_;
54 }
55 return result;
56 }
57
58 } // namespace space
59 } // namespace gc
60 } // namespace art
61
62 #endif // ART_RUNTIME_GC_SPACE_DLMALLOC_SPACE_INL_H_
63