22 *
23 */
24
25 #ifndef SHARE_VM_SERVICES_VIRTUAL_MEMORY_TRACKER_HPP
26 #define SHARE_VM_SERVICES_VIRTUAL_MEMORY_TRACKER_HPP
27
28 #if INCLUDE_NMT
29
30 #include "memory/allocation.hpp"
31 #include "memory/metaspace.hpp"
32 #include "services/allocationSite.hpp"
33 #include "services/nmtCommon.hpp"
34 #include "utilities/linkedlist.hpp"
35 #include "utilities/nativeCallStack.hpp"
36 #include "utilities/ostream.hpp"
37
38
39 /*
40 * Virtual memory counter
41 */
42 class VirtualMemory VALUE_OBJ_CLASS_SPEC {
43 private:
44 size_t _reserved;
45 size_t _committed;
46
47 public:
48 VirtualMemory() : _reserved(0), _committed(0) { }
49
50 inline void reserve_memory(size_t sz) { _reserved += sz; }
51 inline void commit_memory (size_t sz) {
52 _committed += sz;
53 assert(_committed <= _reserved, "Sanity check");
54 }
55
56 inline void release_memory (size_t sz) {
57 assert(_reserved >= sz, "Negative amount");
58 _reserved -= sz;
59 }
60
61 inline void uncommit_memory(size_t sz) {
62 assert(_committed >= sz, "Negative amount");
160 as_snapshot()->by_type(to)->commit_memory(size);
161 }
162
163 static inline void snapshot(VirtualMemorySnapshot* s) {
164 as_snapshot()->copy_to(s);
165 }
166
167 static VirtualMemorySnapshot* as_snapshot() {
168 return (VirtualMemorySnapshot*)_snapshot;
169 }
170
171 private:
172 static size_t _snapshot[CALC_OBJ_SIZE_IN_TYPE(VirtualMemorySnapshot, size_t)];
173 };
174
175
176
177 /*
178 * A virtual memory region
179 */
180 class VirtualMemoryRegion VALUE_OBJ_CLASS_SPEC {
181 private:
182 address _base_address;
183 size_t _size;
184
185 public:
186 VirtualMemoryRegion(address addr, size_t size) :
187 _base_address(addr), _size(size) {
188 assert(addr != NULL, "Invalid address");
189 assert(size > 0, "Invalid size");
190 }
191
192 inline address base() const { return _base_address; }
193 inline address end() const { return base() + size(); }
194 inline size_t size() const { return _size; }
195
196 inline bool is_empty() const { return size() == 0; }
197
198 inline bool contain_address(address addr) const {
199 return (addr >= base() && addr < end());
200 }
|
22 *
23 */
24
25 #ifndef SHARE_VM_SERVICES_VIRTUAL_MEMORY_TRACKER_HPP
26 #define SHARE_VM_SERVICES_VIRTUAL_MEMORY_TRACKER_HPP
27
28 #if INCLUDE_NMT
29
30 #include "memory/allocation.hpp"
31 #include "memory/metaspace.hpp"
32 #include "services/allocationSite.hpp"
33 #include "services/nmtCommon.hpp"
34 #include "utilities/linkedlist.hpp"
35 #include "utilities/nativeCallStack.hpp"
36 #include "utilities/ostream.hpp"
37
38
39 /*
40 * Virtual memory counter
41 */
42 class VirtualMemory {
43 private:
44 size_t _reserved;
45 size_t _committed;
46
47 public:
48 VirtualMemory() : _reserved(0), _committed(0) { }
49
50 inline void reserve_memory(size_t sz) { _reserved += sz; }
51 inline void commit_memory (size_t sz) {
52 _committed += sz;
53 assert(_committed <= _reserved, "Sanity check");
54 }
55
56 inline void release_memory (size_t sz) {
57 assert(_reserved >= sz, "Negative amount");
58 _reserved -= sz;
59 }
60
61 inline void uncommit_memory(size_t sz) {
62 assert(_committed >= sz, "Negative amount");
160 as_snapshot()->by_type(to)->commit_memory(size);
161 }
162
163 static inline void snapshot(VirtualMemorySnapshot* s) {
164 as_snapshot()->copy_to(s);
165 }
166
167 static VirtualMemorySnapshot* as_snapshot() {
168 return (VirtualMemorySnapshot*)_snapshot;
169 }
170
171 private:
172 static size_t _snapshot[CALC_OBJ_SIZE_IN_TYPE(VirtualMemorySnapshot, size_t)];
173 };
174
175
176
177 /*
178 * A virtual memory region
179 */
180 class VirtualMemoryRegion {
181 private:
182 address _base_address;
183 size_t _size;
184
185 public:
186 VirtualMemoryRegion(address addr, size_t size) :
187 _base_address(addr), _size(size) {
188 assert(addr != NULL, "Invalid address");
189 assert(size > 0, "Invalid size");
190 }
191
192 inline address base() const { return _base_address; }
193 inline address end() const { return base() + size(); }
194 inline size_t size() const { return _size; }
195
196 inline bool is_empty() const { return size() == 0; }
197
198 inline bool contain_address(address addr) const {
199 return (addr >= base() && addr < end());
200 }
|