Ian Rogers | 6fac447 | 2014-02-25 17:01:10 -0800 | [diff] [blame] | 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_VALGRIND_MALLOC_SPACE_H_ |
| 18 | #define ART_RUNTIME_GC_SPACE_VALGRIND_MALLOC_SPACE_H_ |
| 19 | |
| 20 | #include "malloc_space.h" |
| 21 | |
| 22 | #include <valgrind.h> |
| 23 | |
| 24 | namespace art { |
| 25 | namespace gc { |
| 26 | namespace space { |
| 27 | |
| 28 | // A specialization of DlMallocSpace/RosAllocSpace that places valgrind red zones around |
| 29 | // allocations. |
| 30 | template <typename BaseMallocSpaceType, typename AllocatorType> |
| 31 | class ValgrindMallocSpace FINAL : public BaseMallocSpaceType { |
| 32 | public: |
| 33 | mirror::Object* AllocWithGrowth(Thread* self, size_t num_bytes, size_t* bytes_allocated, |
| 34 | size_t* usable_size) OVERRIDE; |
| 35 | mirror::Object* Alloc(Thread* self, size_t num_bytes, size_t* bytes_allocated, |
| 36 | size_t* usable_size) OVERRIDE; |
| 37 | |
| 38 | size_t AllocationSize(mirror::Object* obj, size_t* usable_size) OVERRIDE; |
| 39 | |
| 40 | size_t Free(Thread* self, mirror::Object* ptr) OVERRIDE |
| 41 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 42 | |
| 43 | size_t FreeList(Thread* self, size_t num_ptrs, mirror::Object** ptrs) OVERRIDE |
| 44 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 45 | |
Mathieu Chartier | 661974a | 2014-01-09 11:23:53 -0800 | [diff] [blame] | 46 | void RegisterRecentFree(mirror::Object* ptr) OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame^] | 47 | UNUSED(ptr); |
Mathieu Chartier | 661974a | 2014-01-09 11:23:53 -0800 | [diff] [blame] | 48 | } |
| 49 | |
Ian Rogers | 6fac447 | 2014-02-25 17:01:10 -0800 | [diff] [blame] | 50 | ValgrindMallocSpace(const std::string& name, MemMap* mem_map, AllocatorType allocator, |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 51 | uint8_t* begin, uint8_t* end, uint8_t* limit, size_t growth_limit, |
Mathieu Chartier | 31f4414 | 2014-04-08 14:40:03 -0700 | [diff] [blame] | 52 | size_t initial_size, bool can_move_objects, size_t starting_size); |
Ian Rogers | 6fac447 | 2014-02-25 17:01:10 -0800 | [diff] [blame] | 53 | virtual ~ValgrindMallocSpace() {} |
| 54 | |
| 55 | private: |
| 56 | DISALLOW_COPY_AND_ASSIGN(ValgrindMallocSpace); |
| 57 | }; |
| 58 | |
| 59 | } // namespace space |
| 60 | } // namespace gc |
| 61 | } // namespace art |
| 62 | |
| 63 | #endif // ART_RUNTIME_GC_SPACE_VALGRIND_MALLOC_SPACE_H_ |