Permalink
Browse files

[sgen]Improve fatal OOM messaging to include the requested amount.

  • Loading branch information...
1 parent 01ea58c commit 7e51317a2fd271b2349e9c3bc1ed358e3e9a29ed @kumpera kumpera committed Dec 7, 2012
@@ -882,6 +882,7 @@ mono_metadata_locate_token (MonoImage *meta, guint32 token)
const char *
mono_metadata_string_heap (MonoImage *meta, guint32 index)
{
+ g_assert (index < meta->heap_strings.size);
g_return_val_if_fail (index < meta->heap_strings.size, "");
return meta->heap_strings.data + index;
}
@@ -896,6 +897,7 @@ mono_metadata_string_heap (MonoImage *meta, guint32 index)
const char *
mono_metadata_user_string (MonoImage *meta, guint32 index)
{
+ g_assert (index < meta->heap_us.size);
g_return_val_if_fail (index < meta->heap_us.size, "");
return meta->heap_us.data + index;
}
@@ -910,6 +912,7 @@ mono_metadata_user_string (MonoImage *meta, guint32 index)
const char *
mono_metadata_blob_heap (MonoImage *meta, guint32 index)
{
+ g_assert (index < meta->heap_blob.size);
g_return_val_if_fail (index < meta->heap_blob.size, "");/*FIXME shouldn't we return NULL and check for index == 0?*/
return meta->heap_blob.data + index;
}
@@ -127,15 +127,15 @@ sgen_alloc_internal_dynamic (size_t size, int type, gboolean assert_on_failure)
if (size > allocator_sizes [NUM_ALLOCATORS - 1]) {
p = sgen_alloc_os_memory (size, SGEN_ALLOC_INTERNAL | SGEN_ALLOC_ACTIVATE, NULL);
if (!p)
- sgen_assert_memory_alloc (NULL, description_for_type (type));
+ sgen_assert_memory_alloc (NULL, size, description_for_type (type));
return p;
}
index = index_for_size (size);
p = mono_lock_free_alloc (&allocators [index]);
if (!p)
- sgen_assert_memory_alloc (NULL, description_for_type (type));
+ sgen_assert_memory_alloc (NULL, size, description_for_type (type));
memset (p, 0, size);
return p;
}
@@ -283,11 +283,11 @@ prot_flags_for_activate (int activate)
}
void
-sgen_assert_memory_alloc (void *ptr, const char *assert_description)
+sgen_assert_memory_alloc (void *ptr, size_t requested_size, const char *assert_description)
{
if (ptr || !assert_description)
return;
- fprintf (stderr, "Error: Garbage collector could not allocate memory for %s.\n", assert_description);
+ fprintf (stderr, "Error: Garbage collector could not allocate %zu bytes of memory for %s.\n", requested_size, assert_description);
exit (1);
}
@@ -303,7 +303,7 @@ sgen_alloc_os_memory (size_t size, SgenAllocFlags flags, const char *assert_desc
g_assert (!(flags & ~(SGEN_ALLOC_HEAP | SGEN_ALLOC_ACTIVATE)));
ptr = mono_valloc (0, size, prot_flags_for_activate (flags & SGEN_ALLOC_ACTIVATE));
- sgen_assert_memory_alloc (ptr, assert_description);
+ sgen_assert_memory_alloc (ptr, size, assert_description);
if (ptr) {
SGEN_ATOMIC_ADD_P (total_alloc, size);
if (flags & SGEN_ALLOC_HEAP)
@@ -321,7 +321,7 @@ sgen_alloc_os_memory_aligned (size_t size, mword alignment, SgenAllocFlags flags
g_assert (!(flags & ~(SGEN_ALLOC_HEAP | SGEN_ALLOC_ACTIVATE)));
ptr = mono_valloc_aligned (size, alignment, prot_flags_for_activate (flags & SGEN_ALLOC_ACTIVATE));
- sgen_assert_memory_alloc (ptr, assert_description);
+ sgen_assert_memory_alloc (ptr, size, assert_description);
if (ptr) {
SGEN_ATOMIC_ADD_P (total_alloc, size);
if (flags & SGEN_ALLOC_HEAP)
@@ -56,7 +56,7 @@ void* sgen_alloc_os_memory_aligned (size_t size, mword alignment, SgenAllocFlags
void sgen_free_os_memory (void *addr, size_t size, SgenAllocFlags flags) MONO_INTERNAL;
/* Error handling */
-void sgen_assert_memory_alloc (void *ptr, const char *assert_description) MONO_INTERNAL;
+void sgen_assert_memory_alloc (void *ptr, size_t requested_size, const char *assert_description) MONO_INTERNAL;
#endif

0 comments on commit 7e51317

Please sign in to comment.