Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 33 additions & 43 deletions src/coreclr/gc/gc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36272,40 +36272,35 @@ void gc_heap::make_unused_array (uint8_t* x, size_t size, BOOL clearp, BOOL rese
reset_memory (x, size);
}
}
#ifndef HOST_64BIT
((CObjectHeader*)x)->SetFree(size);

#ifdef HOST_64BIT
#else

#if BIGENDIAN
#error "This won't work on big endian platforms"
#endif

size_t size_as_object = (uint32_t)(size - free_object_base_size) + free_object_base_size;
//
// If the size is more than 4GB, we need to create multiple objects because of
// the Array::m_NumComponents is uint32_t and the high 32 bits of unused array
// size is ignored in regular object size computation.
//
uint8_t * tmp = x;
size_t remaining_size = size;

if (size_as_object < size)
while (remaining_size > UINT32_MAX)
{
//
// If the size is more than 4GB, we need to create multiple objects because of
// the Array::m_NumComponents is uint32_t and the high 32 bits of unused array
// size is ignored in regular object size computation.
//
uint8_t * tmp = x + size_as_object;
size_t remaining_size = size - size_as_object;

while (remaining_size > UINT32_MAX)
{
// Make sure that there will be at least Align(min_obj_size) left
size_t current_size = UINT32_MAX - get_alignment_constant (FALSE)
- Align (min_obj_size, get_alignment_constant (FALSE));
// Make sure that there will be at least Align(min_obj_size) left
size_t current_size = UINT32_MAX - get_alignment_constant (FALSE)
- Align (min_obj_size, get_alignment_constant (FALSE));

((CObjectHeader*)tmp)->SetFree(current_size);
((CObjectHeader*)tmp)->SetFree(current_size);

remaining_size -= current_size;
tmp += current_size;
}

((CObjectHeader*)tmp)->SetFree(remaining_size);
remaining_size -= current_size;
tmp += current_size;
}

((CObjectHeader*)tmp)->SetFree(remaining_size);
#endif

if (clearp)
Expand All @@ -36315,41 +36310,36 @@ void gc_heap::make_unused_array (uint8_t* x, size_t size, BOOL clearp, BOOL rese
// Clear memory set by make_unused_array.
void gc_heap::clear_unused_array (uint8_t* x, size_t size)
{
#ifndef HOST_64BIT
UNREFERENCED_PARAMETER(size);
// Also clear the sync block
*(((PTR_PTR)x)-1) = 0;

((CObjectHeader*)x)->UnsetFree();

#ifdef HOST_64BIT
#else

#if BIGENDIAN
#error "This won't work on big endian platforms"
#endif

// The memory could have been cleared in the meantime. We have to mirror the algorithm
// from make_unused_array since we cannot depend on the object sizes in memory.
size_t size_as_object = (uint32_t)(size - free_object_base_size) + free_object_base_size;
uint8_t * tmp = x;
size_t remaining_size = size;

if (size_as_object < size)
while (remaining_size > UINT32_MAX)
{
uint8_t * tmp = x + size_as_object;
size_t remaining_size = size - size_as_object;

while (remaining_size > UINT32_MAX)
{
size_t current_size = UINT32_MAX - get_alignment_constant (FALSE)
- Align (min_obj_size, get_alignment_constant (FALSE));

((CObjectHeader*)tmp)->UnsetFree();

remaining_size -= current_size;
tmp += current_size;
}
size_t current_size = UINT32_MAX - get_alignment_constant (FALSE)
- Align (min_obj_size, get_alignment_constant (FALSE));

*(((PTR_PTR)tmp)-1) = 0;
((CObjectHeader*)tmp)->UnsetFree();

remaining_size -= current_size;
tmp += current_size;
}
#else
UNREFERENCED_PARAMETER(size);

*(((PTR_PTR)tmp)-1) = 0;
((CObjectHeader*)tmp)->UnsetFree();
#endif
}

Expand Down