blob: a6b010a2a135edeea47d3637b4ed053d7fb3cb6f [file] [log] [blame]
Ian Rogers6fac4472014-02-25 17:01:10 -08001/*
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
24namespace art {
25namespace gc {
26namespace space {
27
28// A specialization of DlMallocSpace/RosAllocSpace that places valgrind red zones around
29// allocations.
Andreas Gamped7576322014-10-24 22:13:45 -070030template <typename BaseMallocSpaceType,
31 size_t kValgrindRedZoneBytes,
32 bool kAdjustForRedzoneInAllocSize,
33 bool kUseObjSizeForUsable>
Ian Rogers6fac4472014-02-25 17:01:10 -080034class ValgrindMallocSpace FINAL : public BaseMallocSpaceType {
35 public:
36 mirror::Object* AllocWithGrowth(Thread* self, size_t num_bytes, size_t* bytes_allocated,
Hiroshi Yamauchi4460a842015-03-09 11:57:48 -070037 size_t* usable_size, size_t* bytes_tl_bulk_allocated)
38 OVERRIDE;
Ian Rogers6fac4472014-02-25 17:01:10 -080039 mirror::Object* Alloc(Thread* self, size_t num_bytes, size_t* bytes_allocated,
Hiroshi Yamauchi4460a842015-03-09 11:57:48 -070040 size_t* usable_size, size_t* bytes_tl_bulk_allocated) OVERRIDE;
Andreas Gampe24a5a302014-11-21 19:45:53 -080041 mirror::Object* AllocThreadUnsafe(Thread* self, size_t num_bytes, size_t* bytes_allocated,
Hiroshi Yamauchi4460a842015-03-09 11:57:48 -070042 size_t* usable_size, size_t* bytes_tl_bulk_allocated)
43 OVERRIDE EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers6fac4472014-02-25 17:01:10 -080044
45 size_t AllocationSize(mirror::Object* obj, size_t* usable_size) OVERRIDE;
46
47 size_t Free(Thread* self, mirror::Object* ptr) OVERRIDE
48 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
49
50 size_t FreeList(Thread* self, size_t num_ptrs, mirror::Object** ptrs) OVERRIDE
51 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
52
Mathieu Chartier661974a2014-01-09 11:23:53 -080053 void RegisterRecentFree(mirror::Object* ptr) OVERRIDE {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -070054 UNUSED(ptr);
Mathieu Chartier661974a2014-01-09 11:23:53 -080055 }
56
Hiroshi Yamauchi4460a842015-03-09 11:57:48 -070057 size_t MaxBytesBulkAllocatedFor(size_t num_bytes) OVERRIDE;
58
Andreas Gamped7576322014-10-24 22:13:45 -070059 template <typename... Params>
60 explicit ValgrindMallocSpace(MemMap* mem_map, size_t initial_size, Params... params);
Ian Rogers6fac4472014-02-25 17:01:10 -080061 virtual ~ValgrindMallocSpace() {}
62
63 private:
64 DISALLOW_COPY_AND_ASSIGN(ValgrindMallocSpace);
65};
66
67} // namespace space
68} // namespace gc
69} // namespace art
70
71#endif // ART_RUNTIME_GC_SPACE_VALGRIND_MALLOC_SPACE_H_