/* Garbage Collector (GC) */
probe gc__begin (int generation);
probe gc__end (int generation);
+
+ probe gc__heap__alloc (void *addr, uintptr_t len);
+ probe gc__heap__free (void *addr, uintptr_t len);
};
#pragma D attributes Evolving/Evolving/Common provider mono provider
void
sgen_card_table_init (SgenRemeberedSet *remset)
{
- sgen_cardtable = sgen_alloc_os_memory (CARD_COUNT_IN_BYTES, TRUE, "card table");
+ sgen_cardtable = sgen_alloc_os_memory (CARD_COUNT_IN_BYTES, TRUE, FALSE, "card table");
#ifdef SGEN_HAVE_OVERLAPPING_CARDS
- sgen_shadow_cardtable = sgen_alloc_os_memory (CARD_COUNT_IN_BYTES, TRUE, "shadow card table");
+ sgen_shadow_cardtable = sgen_alloc_os_memory (CARD_COUNT_IN_BYTES, TRUE, FALSE, "shadow card table");
#endif
#ifdef HEAVY_STATISTICS
{
/*setup valid_nursery_objects*/
if (!valid_nursery_objects)
- valid_nursery_objects = sgen_alloc_os_memory (DEFAULT_NURSERY_SIZE, TRUE, "debugging data");
+ valid_nursery_objects = sgen_alloc_os_memory (DEFAULT_NURSERY_SIZE, TRUE, FALSE, "debugging data");
valid_nursery_object_count = 0;
sgen_scan_area_with_callback (nursery_section->data, nursery_section->end_data, setup_mono_sgen_scan_area_with_callback, NULL, FALSE);
void *p;
if (size > allocator_sizes [NUM_ALLOCATORS - 1]) {
- p = sgen_alloc_os_memory (size, TRUE, NULL);
+ p = sgen_alloc_os_memory (size, TRUE, FALSE, NULL);
if (!p)
sgen_assert_memory_alloc (NULL, description_for_type (type));
return p;
void
sgen_free_internal_dynamic (void *addr, size_t size, int type)
{
- int index;
-
if (!addr)
return;
- if (size > allocator_sizes [NUM_ALLOCATORS - 1])
- return sgen_free_os_memory (addr, size);
-
- index = index_for_size (size);
+ if (size > allocator_sizes [NUM_ALLOCATORS - 1]) {
+ sgen_free_os_memory (addr, size, FALSE);
+ return;
+ }
mono_lock_free_free (addr);
}
if (!sgen_memgov_try_alloc_space (LOS_SECTION_SIZE, SPACE_LOS))
return NULL;
- section = sgen_alloc_os_memory_aligned (LOS_SECTION_SIZE, LOS_SECTION_SIZE, TRUE, NULL);
+ section = sgen_alloc_os_memory_aligned (LOS_SECTION_SIZE, LOS_SECTION_SIZE, TRUE, TRUE, NULL);
if (!section)
return NULL;
size += sizeof (LOSObject);
size += pagesize - 1;
size &= ~(pagesize - 1);
- sgen_free_os_memory (obj, size);
+ sgen_free_os_memory (obj, size, TRUE);
sgen_memgov_release_space (size, SPACE_LOS);
} else {
free_los_section_memory (obj, size + sizeof (LOSObject));
#ifdef LOS_DUMMY
if (!los_segment)
- los_segment = sgen_alloc_os_memory (LOS_SEGMENT_SIZE, TRUE, NULL);
+ los_segment = sgen_alloc_os_memory (LOS_SEGMENT_SIZE, TRUE, TRUE, NULL);
los_segment_index = ALIGN_UP (los_segment_index);
obj = (LOSObject*)(los_segment + los_segment_index);
alloc_size += pagesize - 1;
alloc_size &= ~(pagesize - 1);
if (sgen_memgov_try_alloc_space (alloc_size, SPACE_LOS)) {
- obj = sgen_alloc_os_memory (alloc_size, TRUE, NULL);
+ obj = sgen_alloc_os_memory (alloc_size, TRUE, TRUE, NULL);
if (obj)
obj->huge_object = TRUE;
}
prev->next = next;
else
los_sections = next;
- sgen_free_os_memory (section, LOS_SECTION_SIZE);
+ sgen_free_os_memory (section, LOS_SECTION_SIZE, TRUE);
sgen_memgov_release_space (LOS_SECTION_SIZE, SPACE_LOS);
section = next;
--los_num_sections;
major_alloc_heap (mword nursery_size, mword nursery_align, int the_nursery_bits)
{
if (nursery_align)
- nursery_start = sgen_alloc_os_memory_aligned (nursery_size, nursery_align, TRUE, "nursery");
+ nursery_start = sgen_alloc_os_memory_aligned (nursery_size, nursery_align, TRUE, TRUE, "nursery");
else
- nursery_start = sgen_alloc_os_memory (nursery_size, TRUE, "nursery");
+ nursery_start = sgen_alloc_os_memory (nursery_size, TRUE, TRUE, "nursery");
nursery_end = nursery_start + nursery_size;
nursery_bits = the_nursery_bits;
GCMemSection *section;
int scan_starts;
- section = sgen_alloc_os_memory_aligned (MAJOR_SECTION_SIZE, MAJOR_SECTION_SIZE, TRUE, "major heap section");
+ section = sgen_alloc_os_memory_aligned (MAJOR_SECTION_SIZE, MAJOR_SECTION_SIZE, TRUE, TRUE, "major heap section");
section->next_data = section->data = (char*)section + SGEN_SIZEOF_GC_MEM_SECTION;
g_assert (!((mword)section->data & 7));
section->size = MAJOR_SECTION_SIZE - SGEN_SIZEOF_GC_MEM_SECTION;
DEBUG (3, fprintf (gc_debug_file, "Freed major section %p (%p-%p)\n", section, section->data, section->end_data));
sgen_free_internal_dynamic (section->scan_starts,
(section->size + SGEN_SCAN_START_SIZE - 1) / SGEN_SCAN_START_SIZE * sizeof (char*), INTERNAL_MEM_SCAN_STARTS);
- sgen_free_os_memory (section, MAJOR_SECTION_SIZE);
+ sgen_free_os_memory (section, MAJOR_SECTION_SIZE, TRUE);
--num_major_sections;
}
if (nursery_align)
g_assert (nursery_align % MS_BLOCK_SIZE == 0);
- nursery_start = sgen_alloc_os_memory_aligned (alloc_size, nursery_align ? nursery_align : MS_BLOCK_SIZE, TRUE, "heap");
+ nursery_start = sgen_alloc_os_memory_aligned (alloc_size, nursery_align ? nursery_align : MS_BLOCK_SIZE, TRUE, TRUE, "heap");
ms_heap_start = nursery_start + nursery_size;
ms_heap_end = ms_heap_start + major_heap_size;
{
char *start;
if (nursery_align)
- start = sgen_alloc_os_memory_aligned (nursery_size, nursery_align, TRUE, "nursery");
+ start = sgen_alloc_os_memory_aligned (nursery_size, nursery_align, TRUE, TRUE, "nursery");
else
- start = sgen_alloc_os_memory (nursery_size, TRUE, "nursery");
+ start = sgen_alloc_os_memory (nursery_size, TRUE, TRUE, "nursery");
return start;
}
retry:
if (!empty_blocks) {
- p = sgen_alloc_os_memory_aligned (MS_BLOCK_SIZE * MS_BLOCK_ALLOC_NUM, MS_BLOCK_SIZE, TRUE, "major heap section");
+ p = sgen_alloc_os_memory_aligned (MS_BLOCK_SIZE * MS_BLOCK_ALLOC_NUM, MS_BLOCK_SIZE, TRUE, TRUE, "major heap section");
for (i = 0; i < MS_BLOCK_ALLOC_NUM; ++i) {
block = p;
while (num_empty_blocks > section_reserve) {
void *next = *(void**)empty_blocks;
- sgen_free_os_memory (empty_blocks, MS_BLOCK_SIZE);
+ sgen_free_os_memory (empty_blocks, MS_BLOCK_SIZE, TRUE);
empty_blocks = next;
/*
* Needs not be atomic because this is running
#include "utils/mono-counters.h"
#include "utils/mono-mmap.h"
#include "utils/mono-logger-internal.h"
+#include "utils/dtrace.h"
#define MIN_MINOR_COLLECTION_ALLOWANCE ((mword)(DEFAULT_NURSERY_SIZE * default_allowance_nursery_size_ratio))
* This must not require any lock.
*/
void*
-sgen_alloc_os_memory (size_t size, int activate, const char *assert_description)
+sgen_alloc_os_memory (size_t size, int activate, gboolean is_heap_memory, const char *assert_description)
{
void *ptr = mono_valloc (0, size, prot_flags_for_activate (activate));
sgen_assert_memory_alloc (ptr, assert_description);
- if (ptr)
+ if (ptr) {
SGEN_ATOMIC_ADD_P (total_alloc, size);
+ if (is_heap_memory)
+ MONO_PROBE_GC_HEAP_ALLOC (ptr, size);
+ }
return ptr;
}
/* size must be a power of 2 */
void*
-sgen_alloc_os_memory_aligned (size_t size, mword alignment, gboolean activate, const char *assert_description)
+sgen_alloc_os_memory_aligned (size_t size, mword alignment, gboolean activate, gboolean is_heap_memory, const char *assert_description)
{
void *ptr = mono_valloc_aligned (size, alignment, prot_flags_for_activate (activate));
sgen_assert_memory_alloc (ptr, assert_description);
- if (ptr)
+ if (ptr) {
SGEN_ATOMIC_ADD_P (total_alloc, size);
+ if (is_heap_memory)
+ MONO_PROBE_GC_HEAP_ALLOC (ptr, size);
+ }
return ptr;
}
* Free the memory returned by sgen_alloc_os_memory (), returning it to the OS.
*/
void
-sgen_free_os_memory (void *addr, size_t size)
+sgen_free_os_memory (void *addr, size_t size, gboolean is_heap_memory)
{
mono_vfree (addr, size);
SGEN_ATOMIC_ADD_P (total_alloc, -size);
+ if (is_heap_memory)
+ MONO_PROBE_GC_HEAP_FREE (addr, size);
}
int64_t
/* OS memory allocation */
-void* sgen_alloc_os_memory (size_t size, int activate, const char *assert_description) MONO_INTERNAL;
-void* sgen_alloc_os_memory_aligned (size_t size, mword alignment, gboolean activate, const char *assert_description) MONO_INTERNAL;
-void sgen_free_os_memory (void *addr, size_t size) MONO_INTERNAL;
+void* sgen_alloc_os_memory (size_t size, int activate, gboolean is_heap_memory, const char *assert_description) MONO_INTERNAL;
+void* sgen_alloc_os_memory_aligned (size_t size, mword alignment, gboolean activate, gboolean is_heap_memory, const char *assert_description) MONO_INTERNAL;
+void sgen_free_os_memory (void *addr, size_t size, gboolean is_heap_memory) MONO_INTERNAL;
/* Error handling */
void sgen_assert_memory_alloc (void *ptr, const char *assert_description) MONO_INTERNAL;
#define LARGE_PINNED_MEM_HEADER_MAGIC 0x7d289f3a
+/* FIXME: Do we even need these anymore? Large objects are always
+ allocated in the LOS. */
typedef struct _LargePinnedMemHeader LargePinnedMemHeader;
struct _LargePinnedMemHeader {
guint32 magic;
int offset;
int size = SGEN_PINNED_CHUNK_SIZE;
- chunk = sgen_alloc_os_memory_aligned (size, size, TRUE, "pinned chunk");
+ chunk = sgen_alloc_os_memory_aligned (size, size, TRUE, TRUE, "pinned chunk");
chunk->block.role = MEMORY_ROLE_PINNED;
sgen_update_heap_boundaries ((mword)chunk, ((mword)chunk + size));
LargePinnedMemHeader *mh;
size += sizeof (LargePinnedMemHeader);
- mh = sgen_alloc_os_memory (size, TRUE, "large pinned object");
+ mh = sgen_alloc_os_memory (size, TRUE, TRUE, "large pinned object");
mh->magic = LARGE_PINNED_MEM_HEADER_MAGIC;
mh->size = size;
/* FIXME: do a CAS here */
g_assert (mh->size == size + sizeof (LargePinnedMemHeader));
/* FIXME: do a CAS */
large_pinned_bytes_alloced -= mh->size;
- sgen_free_os_memory (mh, mh->size);
+ sgen_free_os_memory (mh, mh->size, TRUE);
}
void
g_assert (buffer->index > 0);
fwrite (buffer->buffer, 1, buffer->index, binary_protocol_file);
- sgen_free_os_memory (buffer, sizeof (BinaryProtocolBuffer));
+ sgen_free_os_memory (buffer, sizeof (BinaryProtocolBuffer), FALSE);
}
void
if (buffer && buffer->index + length <= BINARY_PROTOCOL_BUFFER_SIZE)
return buffer;
- new_buffer = sgen_alloc_os_memory (sizeof (BinaryProtocolBuffer), TRUE, "debugging memory");
+ new_buffer = sgen_alloc_os_memory (sizeof (BinaryProtocolBuffer), TRUE, FALSE, "debugging memory");
new_buffer->next = buffer;
new_buffer->index = 0;
if (InterlockedCompareExchangePointer ((void**)&binary_protocol_buffers, new_buffer, buffer) != buffer) {
- sgen_free_os_memory (new_buffer, sizeof (BinaryProtocolBuffer));
+ sgen_free_os_memory (new_buffer, sizeof (BinaryProtocolBuffer), FALSE);
goto retry;
}
#define MONO_PROBE_GC_END_ENABLED() MONO_GC_END_ENABLED ()
+#define MONO_PROBE_GC_HEAP_ALLOC(addr,size) MONO_GC_HEAP_ALLOC ((addr), (size))
+#define MONO_PROBE_GC_HEAP_FREE(addr,size) MONO_GC_HEAP_FREE ((addr), (size))
+
#else
#define MONO_PROBE_GC_END_ENABLED() (0)
+#define MONO_PROBE_GC_HEAP_ALLOC(addr,size)
+#define MONO_PROBE_GC_HEAP_FREE(addr,size)
+
#endif
#endif