1 /* 2 * Copyright (C) 2014 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_MEMORY_TOOL_MALLOC_SPACE_H_ 18 #define ART_RUNTIME_GC_SPACE_MEMORY_TOOL_MALLOC_SPACE_H_ 19 20 #include "malloc_space.h" 21 22 namespace art { 23 namespace gc { 24 namespace space { 25 26 // A specialization of DlMallocSpace/RosAllocSpace that places memory tool red 27 // zones around allocations. 28 template <typename BaseMallocSpaceType, 29 size_t kMemoryToolRedZoneBytes, 30 bool kAdjustForRedzoneInAllocSize, 31 bool kUseObjSizeForUsable> 32 class MemoryToolMallocSpace FINAL : public BaseMallocSpaceType { 33 public: 34 mirror::Object* AllocWithGrowth(Thread* self, size_t num_bytes, size_t* bytes_allocated, 35 size_t* usable_size, size_t* bytes_tl_bulk_allocated) 36 OVERRIDE; 37 mirror::Object* Alloc(Thread* self, size_t num_bytes, size_t* bytes_allocated, 38 size_t* usable_size, size_t* bytes_tl_bulk_allocated) OVERRIDE; 39 mirror::Object* AllocThreadUnsafe(Thread* self, size_t num_bytes, size_t* bytes_allocated, 40 size_t* usable_size, size_t* bytes_tl_bulk_allocated) 41 OVERRIDE REQUIRES(Locks::mutator_lock_); 42 43 size_t AllocationSize(mirror::Object* obj, size_t* usable_size) OVERRIDE; 44 45 size_t Free(Thread* self, mirror::Object* ptr) OVERRIDE 46 SHARED_REQUIRES(Locks::mutator_lock_); 47 48 size_t FreeList(Thread* self, size_t num_ptrs, mirror::Object** ptrs) OVERRIDE 49 SHARED_REQUIRES(Locks::mutator_lock_); 50 RegisterRecentFree(mirror::Object * ptr ATTRIBUTE_UNUSED)51 void RegisterRecentFree(mirror::Object* ptr ATTRIBUTE_UNUSED) OVERRIDE {} 52 53 size_t MaxBytesBulkAllocatedFor(size_t num_bytes) OVERRIDE; 54 55 template <typename... Params> 56 MemoryToolMallocSpace(MemMap* mem_map, size_t initial_size, Params... params); ~MemoryToolMallocSpace()57 virtual ~MemoryToolMallocSpace() {} 58 59 private: 60 DISALLOW_COPY_AND_ASSIGN(MemoryToolMallocSpace); 61 }; 62 63 } // namespace space 64 } // namespace gc 65 } // namespace art 66 67 #endif // ART_RUNTIME_GC_SPACE_MEMORY_TOOL_MALLOC_SPACE_H_ 68