Skip to content

Commit ee7b621

Browse files
committed
update with changes done in the past few weeks, maily remapping from new to original addresses
1 parent 9cc65c2 commit ee7b621

13 files changed

+84
-22
lines changed

src/hotspot/share/gc/g1/c2/g1BarrierSetC2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ void G1BarrierSetC2::post_barrier(GraphKit* kit,
485485
Node* mapped;
486486
if (SanitizeGC) {
487487
mapped = __ make_leaf_call(mapNewAddrToOriginalAddr_Type(), CAST_FROM_FN_PTR(address,
488-
SanitizerGCMapper::mapNewAddrToOriginalAddr), "mapNewAddrToOriginalAddr", card_adr)->in(0);
488+
SanitizerGCMapper::mapNewAddrToOriginalAddr), "mapNewAddrToOriginalAddr", card_adr)->in(0);//->lookup(3); SANITIZE TODO
489489
} else {
490490
mapped = card_adr;
491491
}

src/hotspot/share/gc/g1/customMapper.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
ptrdiff_t SanitizerGCMapper::movedRegionOffset = 0;
44
const void* SanitizerGCMapper::movedRegionStart = nullptr;
55
const void* SanitizerGCMapper::movedRegionEnd = nullptr;
6+
const void* SanitizerGCMapper::originalRegionStart = nullptr;
7+
const void* SanitizerGCMapper::originalRegionEnd = nullptr;
68

79
// Since we can't use void* for pointer arithmetic, we need another pointer
810
// type, whose base element size is the unit for movedRegionOffset. We must use
@@ -12,23 +14,34 @@ const void* SanitizerGCMapper::movedRegionEnd = nullptr;
1214
using byte_ptr = const char*;
1315

1416
void SanitizerGCMapper::initializeMapping(const void* originalRegionStart,
15-
const void* movedRegionStart, const void* movedRegionEnd) {
17+
const void* originalRegionEnd, const void* movedRegionStart, const void* movedRegionEnd) {
1618
SanitizerGCMapper::movedRegionOffset =
1719
static_cast<byte_ptr>(originalRegionStart) -
1820
static_cast<byte_ptr>(movedRegionStart);
1921
SanitizerGCMapper::movedRegionStart = movedRegionStart;
2022
SanitizerGCMapper::movedRegionEnd = movedRegionEnd;
23+
SanitizerGCMapper::originalRegionStart = originalRegionStart;
24+
SanitizerGCMapper::originalRegionEnd = originalRegionEnd;
2125
}
2226

2327
const void* SanitizerGCMapper::mapNewAddrToOriginalAddr(const void* newAddr) {
2428
if (movedRegionOffset != 0 &&
25-
newAddr >= movedRegionStart && newAddr < movedRegionEnd) {
29+
newAddr >= movedRegionStart && newAddr <= movedRegionEnd) { // TODO
2630
return static_cast<byte_ptr>(newAddr) + movedRegionOffset;
2731
}
2832

2933
return newAddr;
3034
}
3135

36+
const void* SanitizerGCMapper::mapOriginalAddrToNewAddr(const void* originalAddr) {
37+
if (movedRegionOffset != 0 &&
38+
originalAddr >= originalRegionStart && originalAddr <= originalRegionEnd) {
39+
return static_cast<byte_ptr>(originalAddr) - movedRegionOffset;
40+
}
41+
42+
return originalAddr;
43+
}
44+
3245
void SanitizerGCMapper::testPrint(void* newAddr) {
3346
printf("---+++%p\n", newAddr);
3447
}

src/hotspot/share/gc/g1/customMapper.hpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,26 @@ class SanitizerGCMapper {
99
static ptrdiff_t movedRegionOffset;
1010
static const void* movedRegionStart;
1111
static const void* movedRegionEnd;
12+
static const void* originalRegionStart;
13+
static const void* originalRegionEnd;
1214

1315
public:
1416
static void initializeMapping(const void* originalRegionStart,
15-
const void* movedRegionStart, const void* movedRegionEnd);
17+
const void* originalRegionEnd, const void* movedRegionStart, const void* movedRegionEnd);
1618
static const void* mapNewAddrToOriginalAddr(const void* newAddr);
19+
static const void* mapOriginalAddrToNewAddr(const void *newAddr);
20+
1721
static void testPrint(void* newAddr);
1822
template <typename T> static inline void remapAddress(T &addr) {
1923
if (SanitizeGC) {
2024
addr = (T) mapNewAddrToOriginalAddr(addr);
2125
}
2226
}
27+
template <typename T> static inline void reverseRemapAddress(T &addr) {
28+
if (SanitizeGC) {
29+
addr = (T) mapOriginalAddrToNewAddr(addr);
30+
}
31+
}
2332
};
2433

2534
#endif //CUSTOMMAPPER_H

src/hotspot/share/gc/g1/g1BiasedArray.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "memory/memRegion.hpp"
3030
#include "utilities/debug.hpp"
3131
#include "utilities/powerOfTwo.hpp"
32+
#include "customMapper.hpp"
3233

3334
// Implements the common base functionality for arrays that contain provisions
3435
// for accessing its elements using a biased index.
@@ -129,6 +130,7 @@ class G1BiasedMappedArray : public G1BiasedMappedArrayBase {
129130
// Return the element of the given array that covers the given word in the
130131
// heap. Assumes the index is valid.
131132
T get_by_address(HeapWord* value) const {
133+
SanitizerGCMapper::remapAddress(value);
132134
idx_t biased_index = ((uintptr_t)value) >> this->shift_by();
133135
this->verify_biased_index(biased_index);
134136
return biased_base()[biased_index];

src/hotspot/share/gc/g1/g1ConcurrentMarkBitMap.inline.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@ inline bool G1CMBitMap::iterate(G1CMBitMapClosure* cl, MemRegion mr) {
3838
"Given MemRegion from " PTR_FORMAT " to " PTR_FORMAT " not contained in heap area",
3939
p2i(mr.start()), p2i(mr.end()));
4040

41+
// TODO SANITIZE
42+
// HeapWord* end = mr.end();
43+
// SanitizerGCMapper::remapAddress(end);
4144
BitMap::idx_t const end_offset = addr_to_offset(mr.end());
45+
46+
// HeapWord* start = mr.start();
47+
// SanitizerGCMapper::remapAddress(start);
4248
BitMap::idx_t offset = _bm.find_first_set_bit(addr_to_offset(mr.start()), end_offset);
4349

4450
while (offset < end_offset) {

src/hotspot/share/gc/g1/g1HeapRegion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void G1HeapRegion::move_this_region() {
7676
}
7777

7878
HeapWord* new_end = new_bottom + GrainWords;
79-
SanitizerGCMapper::initializeMapping(_bottom, new_bottom, new_end);
79+
SanitizerGCMapper::initializeMapping(_bottom, _end, new_bottom, new_end);
8080
_bottom = new_bottom;
8181
_top = new_bottom;
8282
_end = new_end;

src/hotspot/share/gc/g1/g1HeapRegionManager.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,13 @@ G1HeapRegion* HeapRegionManager::allocate_free_region(HeapRegionType type, uint
118118

119119
if (SanitizeGC) {
120120
// SANITIZER, printing of bottom, top and end
121-
printf("index: %d, _bottom: %p, _top: %p, _end: %p\n", hr->hrm_index(), hr->bottom(), hr->top(), hr->end());
121+
printf("REGION WITH INDEX: %d, _bottom: %p, _end: %p\n", hr->hrm_index(), hr->bottom(), hr->end());
122122

123123
// SANITIZER, moving the first region to different address
124124
if (!wasFirstTaken) {
125125
hr->move_this_region();
126-
printf("region with index %d was moved here:\n", hr->hrm_index());
127-
printf(" index: %d, _bottom: %p, _top: %p, _end: %p\n", hr->hrm_index(), hr->bottom(), hr->top(), hr->end());
126+
printf(" %d was moved here:\n", hr->hrm_index());
127+
printf(" index: %d, _bottom: %p, _end: %p\n", hr->hrm_index(), hr->bottom(), hr->end());
128128

129129
wasFirstTaken = true;
130130
}
@@ -716,19 +716,21 @@ void HeapRegionManager::verify() {
716716
num_committed++;
717717
G1HeapRegion* hr = _regions.get_by_index(i);
718718
guarantee(hr != nullptr, "invariant: i: %u", i);
719-
guarantee(!prev_committed || hr->bottom() == prev_end,
719+
HeapWord* hr_bottom = hr->bottom();
720+
SanitizerGCMapper::remapAddress(hr_bottom);
721+
guarantee(!prev_committed || hr_bottom == prev_end,
720722
"invariant i: %u " HR_FORMAT " prev_end: " PTR_FORMAT,
721723
i, HR_FORMAT_PARAMS(hr), p2i(prev_end));
722724
guarantee(hr->hrm_index() == i,
723725
"invariant: i: %u hrm_index(): %u", i, hr->hrm_index());
724726
// Asserts will fire if i is >= _length
725-
HeapWord* addr = hr->bottom();
726-
guarantee(addr_to_region(addr) == hr, "sanity");
727+
guarantee(addr_to_region(hr_bottom) == hr, "sanity");
727728
// We cannot check whether the region is part of a particular set: at the time
728729
// this method may be called, we have only completed allocation of the regions,
729730
// but not put into a region set.
730731
prev_committed = true;
731732
prev_end = hr->end();
733+
SanitizerGCMapper::remapAddress(prev_end);
732734
}
733735
for (uint i = _allocated_heapregions_length; i < reserved_length(); i++) {
734736
guarantee(_regions.get_by_index(i) == nullptr, "invariant i: %u", i);

src/hotspot/share/gc/g1/g1HeapVerifier.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ class VerifyRegionClosure: public HeapRegionClosure {
246246
}
247247

248248
bool do_heap_region(G1HeapRegion* r) {
249+
// TODO SANITIZE
249250
guarantee(!r->has_index_in_opt_cset(), "Region %u still has opt collection set index %u", r->hrm_index(), r->index_in_opt_cset());
250251
guarantee(!r->is_young() || r->rem_set()->is_complete(), "Remembered set for Young region %u must be complete, is %s", r->hrm_index(), r->rem_set()->get_state_str());
251252
// Humongous and old regions regions might be of any state, so can't check here.

src/hotspot/share/gc/shared/cardTable.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,21 @@ void CardTable::clear_MemRegion(MemRegion mr) {
212212
// Be conservative: only clean cards entirely contained within the
213213
// region.
214214
CardValue* cur;
215-
if (mr.start() == _whole_heap.start()) {
216-
cur = byte_for(mr.start());
215+
216+
HeapWord* start = mr.start();
217+
SanitizerGCMapper::remapAddress(start);
218+
219+
if (start == _whole_heap.start()) {
220+
cur = byte_for(start);
217221
} else {
218-
assert(mr.start() > _whole_heap.start(), "mr is not covered.");
219-
cur = byte_after(mr.start() - 1);
222+
assert(start > _whole_heap.start(), "mr is not covered.");
223+
cur = byte_after(start - 1);
220224
}
221-
CardValue* last = byte_after(mr.last());
225+
226+
HeapWord* mr_last = mr.last();
227+
SanitizerGCMapper::remapAddress(mr_last);
228+
229+
CardValue* last = byte_after(mr_last);
222230
memset(cur, clean_card, pointer_delta(last, cur, sizeof(CardValue)));
223231
}
224232

src/hotspot/share/gc/shared/markBitMap.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ void MarkBitMap::do_clear(MemRegion mr, bool large) {
5151
"Given range from " PTR_FORMAT " to " PTR_FORMAT " is completely outside the heap",
5252
p2i(mr.start()), p2i(mr.end()));
5353
// convert address range into offset range
54+
// TODO SANITIZE, maybe needs remapping
5455
size_t beg = addr_to_offset(intersection.start());
5556
size_t end = addr_to_offset(intersection.end());
5657
if (large) {

0 commit comments

Comments
 (0)