Skip to content

Commit

Permalink
Move the background marking of UOH objects inside more space lock (do…
Browse files Browse the repository at this point in the history
  • Loading branch information
cshung committed Aug 4, 2023
1 parent 25f2f62 commit bb0be13
Showing 1 changed file with 35 additions and 31 deletions.
66 changes: 35 additions & 31 deletions src/coreclr/gc/gc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16692,6 +16692,41 @@ void gc_heap::adjust_limit_clr (uint8_t* start, size_t limit_size, size_t size,
// - ephemeral_heap_segment may change due to other threads allocating
heap_segment* gen0_segment = ephemeral_heap_segment;

#ifdef BACKGROUND_GC
{
if (uoh_p && gc_heap::background_running_p())
{
uint8_t* obj = acontext->alloc_ptr;
uint8_t* result = obj;
uint8_t* current_lowest_address = background_saved_lowest_address;
uint8_t* current_highest_address = background_saved_highest_address;

if (current_c_gc_state == c_gc_state_planning)
{
dprintf (3, ("Concurrent allocation of a large object %zx",
(size_t)obj));
//mark the new block specially so we know it is a new object
if ((result < current_highest_address) && (result >= current_lowest_address))
{
#ifdef DOUBLY_LINKED_FL
heap_segment* seg = seg_mapping_table_segment_of (result);
// if bgc_allocated is 0 it means it was allocated during bgc sweep,
// and since sweep does not look at this seg we cannot set the mark array bit.
uint8_t* background_allocated = heap_segment_background_allocated(seg);
if (background_allocated != 0)
#endif //DOUBLY_LINKED_FL
{
dprintf(3, ("Setting mark bit at address %zx",
(size_t)(&mark_array[mark_word_of(result)])));

mark_array_set_marked(result);
}
}
}
}
}
#endif //BACKGROUND_GC

// check if space to clear is all dirty from prior use or only partially
if ((seg == 0) || (clear_limit <= heap_segment_used (seg)))
{
Expand Down Expand Up @@ -44559,37 +44594,6 @@ CObjectHeader* gc_heap::allocate_uoh_object (size_t jsize, uint32_t flags, int g

CObjectHeader* obj = (CObjectHeader*)result;

#ifdef BACKGROUND_GC
if (gc_heap::background_running_p())
{
uint8_t* current_lowest_address = background_saved_lowest_address;
uint8_t* current_highest_address = background_saved_highest_address;

if (current_c_gc_state == c_gc_state_planning)
{
dprintf (3, ("Concurrent allocation of a large object %zx",
(size_t)obj));
//mark the new block specially so we know it is a new object
if ((result < current_highest_address) && (result >= current_lowest_address))
{
#ifdef DOUBLY_LINKED_FL
heap_segment* seg = seg_mapping_table_segment_of (result);
// if bgc_allocated is 0 it means it was allocated during bgc sweep,
// and since sweep does not look at this seg we cannot set the mark array bit.
uint8_t* background_allocated = heap_segment_background_allocated(seg);
if (background_allocated != 0)
#endif //DOUBLY_LINKED_FL
{
dprintf(3, ("Setting mark bit at address %zx",
(size_t)(&mark_array[mark_word_of(result)])));

mark_array_set_marked(result);
}
}
}
}
#endif //BACKGROUND_GC

assert (obj != 0);
assert ((size_t)obj == Align ((size_t)obj, align_const));

Expand Down

0 comments on commit bb0be13

Please sign in to comment.