Skip to content

Commit

Permalink
Do not mark pointer-free heap blocks in soft-dirty VDB mode
Browse files Browse the repository at this point in the history
* checksums.c [SOFT_VDB] (GC_update_check_page): Do not call
GC_was_faulted() if HBLK_IS_FREE(hhdr).
* os_dep.c [CHECKSUMS && !GWW_VDB && !PROC_VDB] (GC_or_pages): Do not
define even if SOFT_VDB.
* os_dep.c [SOFT_VDB && DEBUG_DIRTY_BITS] (soft_set_grungy_pages):
Refine printed message depending on is_static_root; print the message
for each heap block except for pointer-free and unused (free) ones.
* os_dep.c [SOFT_VDB] (soft_set_grungy_pages): Declare hhdr and b local
variables; call GET_HDR() unless is_static_root; do not call PHT_HASH()
and set_pht_entry_from_index() if not is_static_root and hhdr is NULL
or HBLK_IS_FREE(hhdr) or IS_PTRFREE(hhdr); remove
UNUSED_ARG(is_static_root).
* os_dep.c [SOFT_VDB && CHECKSUMS] (soft_set_grungy_pages): Call
set_pht_entry_from_index(GC_written_pages) unless is_static_root.
* os_dep.c [SOFT_VDB && CHECKSUMS] (GC_soft_read_dirty): Do not call
GC_or_pages(GC_written_pages).
  • Loading branch information
ivmai committed Jan 29, 2024
1 parent bb1bb32 commit 6f6dc05
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
3 changes: 3 additions & 0 deletions checksums.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ STATIC void GC_update_check_page(struct hblk *h, int index)
b = FORWARDED_ADDR(b, hhdr);
}
if (pe -> new_valid && hhdr != NULL && !IS_PTRFREE(hhdr)
# ifdef SOFT_VDB
&& !HBLK_IS_FREE(hhdr)
# endif
&& pe -> old_sum != pe -> new_sum) {
if (!GC_page_was_dirty(h) || !GC_page_was_ever_dirty(h)) {
GC_bool was_faulted = GC_was_faulted(h);
Expand Down
39 changes: 29 additions & 10 deletions os_dep.c
Original file line number Diff line number Diff line change
Expand Up @@ -2934,15 +2934,14 @@ GC_API GC_push_other_roots_proc GC_CALL GC_get_push_other_roots(void)
* MPROTECT_VDB may be defined as a fallback strategy.
*/

#if (defined(CHECKSUMS) && (defined(GWW_VDB) || defined(SOFT_VDB))) \
|| defined(PROC_VDB)
#if (defined(CHECKSUMS) && defined(GWW_VDB)) || defined(PROC_VDB)
/* Add all pages in pht2 to pht1. */
STATIC void GC_or_pages(page_hash_table pht1, const word *pht2)
{
unsigned i;
for (i = 0; i < PHT_SIZE; i++) pht1[i] |= pht2[i];
}
#endif /* CHECKSUMS && (GWW_VDB || SOFT_VDB) || PROC_VDB */
#endif /* CHECKSUMS && GWW_VDB || PROC_VDB */

#ifdef GWW_VDB

Expand Down Expand Up @@ -4030,10 +4029,35 @@ GC_INLINE void GC_proc_read_dirty(GC_bool output_unneeded)
/* If the bit is set, the respective PTE was written to */
/* since clearing the soft-dirty bits. */
# ifdef DEBUG_DIRTY_BITS
GC_log_printf("dirty page at: %p\n", (void *)vaddr);
if (is_static_root)
GC_log_printf("static root dirty page at: %p\n", (void *)vaddr);
# endif
for (h = (struct hblk *)vaddr; (word)h < (word)next_vaddr; h++) {
word index = PHT_HASH(h);
word index;

# ifdef CHECKSUMS
index = PHT_HASH(h);
# endif
if (!is_static_root) {
struct hblk *b;
hdr *hhdr;

# ifdef CHECKSUMS
set_pht_entry_from_index(GC_written_pages, index);
# endif
GET_HDR(h, hhdr);
if (NULL == hhdr) continue;
for (b = h; IS_FORWARDING_ADDR_OR_NIL(hhdr); hhdr = HDR(b)) {
b = FORWARDED_ADDR(b, hhdr);
}
if (HBLK_IS_FREE(hhdr) || IS_PTRFREE(hhdr)) continue;
# ifdef DEBUG_DIRTY_BITS
GC_log_printf("dirty page (hblk) at: %p\n", (void *)h);
# endif
}
# ifndef CHECKSUMS
index = PHT_HASH(h);
# endif
set_pht_entry_from_index(GC_grungy_pages, index);
}
} else {
Expand All @@ -4050,8 +4074,6 @@ GC_INLINE void GC_proc_read_dirty(GC_bool output_unneeded)
ABORT("Inconsistent soft-dirty against mprotect dirty bits");
}
}
# else
UNUSED_ARG(is_static_root);
# endif
}
/* Read the next portion of pagemap file if incomplete. */
Expand Down Expand Up @@ -4093,9 +4115,6 @@ GC_INLINE void GC_proc_read_dirty(GC_bool output_unneeded)
GC_heap_sects[i+1].hs_start : NULL,
FALSE);
}
# ifdef CHECKSUMS
GC_or_pages(GC_written_pages, GC_grungy_pages);
# endif

# ifndef NO_VDB_FOR_STATIC_ROOTS
for (i = 0; (int)i < n_root_sets; ++i) {
Expand Down

0 comments on commit 6f6dc05

Please sign in to comment.