|
28 | 28 | #include "gc/z/zVirtualMemory.hpp" |
29 | 29 | #include "nmt/memflags.hpp" |
30 | 30 | #include "nmt/memTracker.hpp" |
| 31 | +#include "nmt/memoryFileTracker.hpp" |
31 | 32 | #include "utilities/nativeCallStack.hpp" |
32 | 33 |
|
33 | | -ZNMT::Reservation ZNMT::_reservations[ZMaxVirtualReservations] = {}; |
34 | | -size_t ZNMT::_num_reservations = 0; |
| 34 | +MemoryFileTracker::MemoryFile* ZNMT::_device = nullptr; |
35 | 35 |
|
36 | | -size_t ZNMT::reservation_index(zoffset offset, size_t* offset_in_reservation) { |
37 | | - assert(_num_reservations > 0, "at least one reservation must exist"); |
38 | | - |
39 | | - size_t index = 0; |
40 | | - *offset_in_reservation = untype(offset); |
41 | | - for (; index < _num_reservations; ++index) { |
42 | | - const size_t reservation_size = _reservations[index]._size; |
43 | | - if (*offset_in_reservation < reservation_size) { |
44 | | - break; |
45 | | - } |
46 | | - *offset_in_reservation -= reservation_size; |
47 | | - } |
48 | | - |
49 | | - assert(index != _num_reservations, "failed to find reservation index"); |
50 | | - return index; |
51 | | -} |
52 | | - |
53 | | -void ZNMT::process_fake_mapping(zoffset offset, size_t size, bool commit) { |
54 | | - // In order to satisfy NTM's requirement of an 1:1 mapping between committed |
55 | | - // and reserved addresses, a fake mapping from the offset into the reservation |
56 | | - // is used. |
57 | | - // |
58 | | - // These mappings from |
59 | | - // [offset, offset + size) -> {[virtual address range], ...} |
60 | | - // are stable after the heap has been reserved. No commits proceed any |
61 | | - // reservations. Committing and uncommitting the same [offset, offset + size) |
62 | | - // range will result in same virtual memory ranges. |
63 | | - |
64 | | - size_t left_to_process = size; |
65 | | - size_t offset_in_reservation; |
66 | | - for (size_t i = reservation_index(offset, &offset_in_reservation); i < _num_reservations; ++i) { |
67 | | - const zaddress_unsafe reservation_start = _reservations[i]._start; |
68 | | - const size_t reservation_size = _reservations[i]._size; |
69 | | - const size_t sub_range_size = MIN2(left_to_process, reservation_size - offset_in_reservation); |
70 | | - const uintptr_t sub_range_addr = untype(reservation_start) + offset_in_reservation; |
71 | | - |
72 | | - // commit / uncommit memory |
73 | | - if (commit) { |
74 | | - MemTracker::record_virtual_memory_commit((void*)sub_range_addr, sub_range_size, CALLER_PC); |
75 | | - } else { |
76 | | - ThreadCritical tc; |
77 | | - MemTracker::record_virtual_memory_uncommit((address)sub_range_addr, sub_range_size); |
78 | | - } |
79 | | - |
80 | | - left_to_process -= sub_range_size; |
81 | | - if (left_to_process == 0) { |
82 | | - // Processed all nmt registrations |
83 | | - return; |
84 | | - } |
85 | | - |
86 | | - offset_in_reservation = 0; |
87 | | - } |
88 | | - |
89 | | - assert(left_to_process == 0, "everything was not commited"); |
| 36 | +void ZNMT::initialize() { |
| 37 | + _device = MemTracker::register_file("ZGC heap backing file"); |
90 | 38 | } |
91 | 39 |
|
92 | 40 | void ZNMT::reserve(zaddress_unsafe start, size_t size) { |
93 | | - assert(_num_reservations < ZMaxVirtualReservations, "too many reservations"); |
94 | | - // Keep track of the reservations made in order to create fake mappings |
95 | | - // between the reserved and commited memory. |
96 | | - // See details in ZNMT::process_fake_mapping |
97 | | - _reservations[_num_reservations++] = {start, size}; |
98 | | - |
99 | | - MemTracker::record_virtual_memory_reserve((void*)untype(start), size, CALLER_PC, mtJavaHeap); |
| 41 | + MemTracker::record_virtual_memory_reserve((address)untype(start), size, CALLER_PC, mtJavaHeap); |
100 | 42 | } |
101 | 43 |
|
102 | 44 | void ZNMT::commit(zoffset offset, size_t size) { |
103 | | - // NMT expects a 1-to-1 mapping between virtual and physical memory. |
104 | | - // ZGC can temporarily have multiple virtual addresses pointing to |
105 | | - // the same physical memory. |
106 | | - // |
107 | | - // When this function is called we don't know where in the virtual memory |
108 | | - // this physical memory will be mapped. So we fake the virtual memory |
109 | | - // address by mapping the physical offset into offsets in the reserved |
110 | | - // memory space. |
111 | | - process_fake_mapping(offset, size, true); |
| 45 | + MemTracker::allocate_memory_in(ZNMT::_device, untype(offset), size, CALLER_PC, mtJavaHeap); |
112 | 46 | } |
113 | 47 |
|
114 | 48 | void ZNMT::uncommit(zoffset offset, size_t size) { |
115 | | - // We fake the virtual memory address by mapping the physical offset |
116 | | - // into offsets in the reserved memory space. |
117 | | - // See comment in ZNMT::commit |
118 | | - process_fake_mapping(offset, size, false); |
| 49 | + MemTracker::free_memory_in(ZNMT::_device, untype(offset), size); |
| 50 | +} |
| 51 | + |
| 52 | +void ZNMT::map(zaddress_unsafe addr, size_t size, zoffset offset) { |
| 53 | + // NMT doesn't track mappings at the moment. |
| 54 | +} |
| 55 | + |
| 56 | +void ZNMT::unmap(zaddress_unsafe addr, size_t size) { |
| 57 | + // NMT doesn't track mappings at the moment. |
119 | 58 | } |
0 commit comments