diff --git a/src/coreclr/gc/gc.cpp b/src/coreclr/gc/gc.cpp index 03d8ef466b4db3..996e868ee3ca86 100644 --- a/src/coreclr/gc/gc.cpp +++ b/src/coreclr/gc/gc.cpp @@ -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) @@ -36315,12 +36310,12 @@ 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" @@ -36328,28 +36323,23 @@ void gc_heap::clear_unused_array (uint8_t* x, size_t size) // 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 }