Compare commits

...
Author SHA1 Message Date
[email protected] c4e14ad8a4 Removed old test. 2019-06-17 11:33:09 -04:00
[email protected] f2c22c8ac4 Reverted white space changes to sgen-mono because it creates a big diff. 2019-06-14 13:29:04 -04:00
[email protected] c256a0fa80 Reverted trailing whitespace removal fro icall because it created a massive diff. 2019-06-14 13:26:33 -04:00
[email protected] 2885957720 Increased allocation in test. 2019-06-14 12:54:55 -04:00
[email protected] 74658ba46b Removed trailing whitespace. 2019-06-14 12:54:01 -04:00
[email protected] c9b277cd3b Removed extra whitespace. 2019-06-14 12:48:06 -04:00
[email protected] dd7f7d0976 Style issues. 2019-06-14 11:33:48 -04:00
[email protected] 1d0fc47618 Warmed up allocation in test. 2019-06-13 17:09:04 -04:00
[email protected] e3d1a191c2 Removed printfs. 2019-06-13 15:45:03 -04:00
[email protected] 94749fe6fb Removed more double counting. 2019-06-12 17:45:07 -04:00
[email protected] 3699cf07ae Removed some double counts. 2019-06-12 17:40:41 -04:00
[email protected] a0fe1a09e8 Fixed a bunch of errors in GCTest 2019-06-11 16:03:01 -04:00
[email protected] 274118e6b8 Added test for gc alloc count to corelib build. 2019-06-11 15:16:11 -04:00
[email protected] 39ed1bce7b Fixed things in GCTest.cs 2019-06-10 18:29:53 -04:00
[email protected] b6f92c45d2 Added tests for get bytes allocated. 2019-06-10 18:12:58 -04:00
[email protected] 066e0029af Removed unecessary size subtraction; used tlab_next as the end of allocated region in tlab. 2019-06-10 15:18:08 -04:00
[email protected] 0912bc0f6e Recorded allocation when tlabs are cleared. 2019-06-07 14:07:42 -04:00
[email protected] 0cc69fd165 Added counter increments to sgen_try_alloc_obj_nolock 2019-06-06 16:06:31 -04:00
[email protected] 7a75b4d9d5 Added counter increments to sgen_try_alloc_obj_nolock 2019-06-06 15:57:10 -04:00
[email protected] 7514f01302 Removed extra field I added to mono thread; unecessary declaration in mono-gc.h 2019-06-06 15:01:35 -04:00
[email protected] 013eacaf86 Removed macro. 2019-06-06 14:37:52 -04:00
[email protected] 5fc3062411 Increment counter on more allocaiton paths. 2019-06-06 13:56:54 -04:00
[email protected] fd15f967dc Added dummy method to null and boehm gc. 2019-06-05 21:08:07 -04:00
[email protected] f919f3d3db Updated icall to point at the new interface. 2019-06-05 16:32:19 -04:00
[email protected] 20e8a6dab6 Made total bytes allocated go through gc interface. 2019-06-04 17:19:40 -04:00
[email protected] 5761c3f874 Fixed typo in attribute. 2019-06-04 13:44:31 -04:00
[email protected] 223cf0bd19 Removed redundant icall. 2019-06-04 11:52:01 -04:00
[email protected] 54f317467e Added call into threads.c 2019-06-03 16:45:55 -04:00
[email protected] f63f78022c Merged changes from master
Merge branch 'master' of github.com:mono/mono into naricc/allocated_bytes
2019-06-03 15:37:51 -04:00
[email protected] 3f44389aad Merge branch 'master' of github.com:mono/mono into naricc/allocated_bytes 2019-05-31 15:02:08 -04:00
[email protected] b2b9703239 Made sgen-alloc retrieve stuf out of MonoThreadInfo 2019-05-30 17:16:40 -04:00
[email protected] 1b56a9eb8b Merge branch 'master' of github.com:mono/mono into naricc/allocated_bytes
Merging from master
2019-05-30 15:30:24 -04:00
[email protected] 70ecd9ea56 Commiting changes before I fork the repo. 2019-05-30 14:56:58 -04:00
[email protected] 5115ab0100 Put things in icall-def.h in proper alphabetical order. 2019-05-29 15:34:53 -04:00
[email protected] 1df089428c Moved declartion of GetAllocatedBytes. 2019-05-29 15:10:05 -04:00
Nathan Ricci 766b9f4616 More implementation. 2019-05-28 18:16:09 -04:00
Nathan Ricci bc29c2a6e1 More impelemtation for get allocated bytes. 2019-05-24 15:02:33 -04:00
Nathan Ricci adb22ab81d Added the scaffolding for the call into the runtime. 2019-05-23 17:54:10 -04:00
9 changed files with 161 additions and 9 deletions

No files matched your search

+95 -1
View File
@@ -34,6 +34,60 @@ using NUnit.Framework;
namespace MonoTests.System {
public interface SizedObject
{
long ExpectedSize();
}
public class NoPointer : SizedObject
{
public long ExpectedSize()
{
return 2 * IntPtr.Size;
}
}
public class TwoPointer : SizedObject
{
public object field1;
public object field2;
public long ExpectedSize()
{
return 4*IntPtr.Size;
}
}
public class FourPointer : SizedObject
{
public object field1;
public object field2;
public object field3;
public object field4;
public long ExpectedSize()
{
return 6*IntPtr.Size;
}
}
public class EightPointer : SizedObject
{
public object field1;
public object field2;
public object fiedl3;
public object field4;
public object field5;
public object field6;
public object field7;
public object field8;
public long ExpectedSize()
{
return (long)(10*IntPtr.Size);
}
}
[TestFixture]
public class GCTest {
class MyFinalizeObject
@@ -71,5 +125,45 @@ namespace MonoTests.System {
Assert.IsTrue (t.Wait (5000));
}
}
[Test]
public static void TestGetBytesAllocatedForCurrentThread()
{
Func<SizedObject>[] objectAllocators = {
() => new NoPointer(),
() => new TwoPointer(),
() => new FourPointer(),
() => new EightPointer()
};
Random r = new Random();
// Methods trigger allocation when first run.
// So this code warms up allocation before measuring.
for (int i = 0; i < objectAllocators.Length; i++)
{
Console.WriteLine(objectAllocators[i]().ExpectedSize());
}
Console.WriteLine(r.Next(1, 10));
Assert.AreEqual(1L, 1L);
// End warmup
long expectedSize = 0;
long bytesBeforeAlloc = GC.GetAllocatedBytesForCurrentThread();
for (int i = 0; i < 10000000; i++)
{
expectedSize += objectAllocators[r.Next(0, objectAllocators.Length) ]().ExpectedSize();
}
long bytesAfterAlloc = GC.GetAllocatedBytesForCurrentThread();
Assert.AreEqual(expectedSize, bytesAfterAlloc - bytesBeforeAlloc);
}
}
}
+1
View File
@@ -86,6 +86,7 @@ System/EnumTest.cs
System/EnvironmentTest.cs
System/ExceptionTest.cs
System/FloatingPointFormatterTest.cs
System.GC/GCtest.cs
System.Globalization/CalendarTest.cs
System.Globalization/CompareInfoTest.cs
System.Globalization/CultureInfoTest.cs
+6
View File
@@ -311,6 +311,12 @@ mono_gc_max_generation (void)
return 0;
}
gint64
mono_gc_get_allocated_bytes_for_current_thread (void)
{
return 0;
}
/**
* mono_gc_get_generation:
* \param object a managed object
+2
View File
@@ -311,6 +311,8 @@ void* mono_gc_invoke_with_gc_lock (MonoGCLockedCallbackFunc func, void *data);
int mono_gc_get_los_limit (void);
int64_t mono_gc_get_allocated_bytes_for_current_thread (void);
guint8* mono_gc_get_card_table (int *shift_bits, gpointer *card_mask);
guint8* mono_gc_get_target_card_table (int *shift_bits, target_mgreg_t *card_mask);
gboolean mono_gc_card_table_nursery_check (void);
+1 -1
View File
@@ -9174,7 +9174,7 @@ ves_icall_System_GC_GetMaxGeneration (void)
gint64
ves_icall_System_GC_GetAllocatedBytesForCurrentThread (void)
{
return 0; // TODO: implement https://github.com/mono/mono/issues/8397
return mono_gc_get_allocated_bytes_for_current_thread ();
}
void
+6
View File
@@ -67,6 +67,12 @@ mono_gc_max_generation (void)
return 0;
}
gint64
mono_gc_get_allocated_bytes_for_current_thread (void)
{
return 0;
}
int
mono_gc_get_generation (MonoObject *object)
{
+10
View File
@@ -2486,6 +2486,16 @@ mono_gc_get_los_limit (void)
return SGEN_MAX_SMALL_OBJ_SIZE;
}
int64_t
mono_gc_get_allocated_bytes_for_current_thread (void)
{
SgenThreadInfo* info;
info = mono_thread_info_current ();
/*There are some more allocated bytes in the current tlab that have not been recorded yet */
return info->total_bytes_allocated + info->tlab_next - info->tlab_start;
}
gpointer
sgen_client_default_metadata (void)
{
+37 -7
View File
@@ -51,7 +51,7 @@ static guint64 stat_bytes_alloced_los = 0;
/*
* Allocation is done from a Thread Local Allocation Buffer (TLAB). TLABs are allocated
* from nursery fragments.
* tlab_next is the pointer to the space inside the TLAB where the next object will
* tlab_next is the pointer to the space inside the TLAB where the next object will
* be allocated.
* tlab_temp_end is the pointer to the end of the temporary space reserved for
* the allocation: it allows us to set the scan starts at reasonable intervals.
@@ -63,10 +63,17 @@ static guint64 stat_bytes_alloced_los = 0;
#define TLAB_TEMP_END (__thread_info__->tlab_temp_end)
#define TLAB_REAL_END (__thread_info__->tlab_real_end)
static void
increment_thread_allocation_counter (size_t byte_size)
{
mono_thread_info_current ()->total_bytes_allocated += byte_size;
}
static GCObject*
alloc_degraded (GCVTable vtable, size_t size, gboolean for_mature)
{
GCObject *p;
increment_thread_allocation_counter (size);
if (!for_mature) {
sgen_client_degraded_allocation ();
@@ -124,7 +131,7 @@ sgen_alloc_obj_nolock (GCVTable vtable, size_t size)
char *new_next;
size_t real_size = size;
TLAB_ACCESS_INIT;
CANARIFY_SIZE(size);
HEAVY_STAT (++stat_objects_alloced);
@@ -168,6 +175,9 @@ sgen_alloc_obj_nolock (GCVTable vtable, size_t size)
if (real_size > SGEN_MAX_SMALL_OBJ_SIZE) {
p = (void **)sgen_los_alloc_large_inner (vtable, ALIGN_UP (real_size));
if (p) {
increment_thread_allocation_counter (size);
}
} else {
/* tlab_next and tlab_temp_end are TLS vars so accessing them might be expensive */
@@ -191,7 +201,7 @@ sgen_alloc_obj_nolock (GCVTable vtable, size_t size)
/* Slow path */
/* there are two cases: the object is too big or we run out of space in the TLAB */
/* we also reach here when the thread does its first allocation after a minor
/* we also reach here when the thread does its first allocation after a minor
* collection, since the tlab_ variables are initialized to NULL.
* there can be another case (from ORP), if we cooperate with the runtime a bit:
* objects that need finalizers can have the high bit set in their size
@@ -201,12 +211,13 @@ sgen_alloc_obj_nolock (GCVTable vtable, size_t size)
*/
if (TLAB_NEXT >= TLAB_REAL_END) {
int available_in_tlab;
/*
/*
* Run out of space in the TLAB. When this happens, some amount of space
* remains in the TLAB, but not enough to satisfy the current allocation
* request. Currently, we retire the TLAB in all cases, later we could
* keep it if the remaining space is above a treshold, and satisfy the
* allocation directly from the nursery.
* request. We keep the TLAB for future allocations if the remaining
* space is above a treshold, and satisfy the allocation directly
* from the nursery. Otherwise, we attempt to get a new TLAB from the
* nursery and allocate into it.
*/
TLAB_NEXT -= size;
/* when running in degraded mode, we continue allocing that way
@@ -240,6 +251,10 @@ sgen_alloc_obj_nolock (GCVTable vtable, size_t size)
sgen_ensure_free_space (real_size, GENERATION_NURSERY);
if (!sgen_degraded_mode)
p = (void **)sgen_nursery_alloc (size);
if (p)
increment_thread_allocation_counter (size);
}
if (!p)
return alloc_degraded (vtable, size, TRUE);
@@ -261,6 +276,8 @@ sgen_alloc_obj_nolock (GCVTable vtable, size_t size)
if (!p)
return alloc_degraded (vtable, size, TRUE);
increment_thread_allocation_counter (TLAB_NEXT - TLAB_START);
/* Allocate a new TLAB from the current nursery fragment */
TLAB_START = (char*)p;
TLAB_NEXT = TLAB_START;
@@ -315,9 +332,12 @@ sgen_try_alloc_obj_nolock (GCVTable vtable, size_t size)
if (G_UNLIKELY (size > sgen_tlab_size)) {
/* Allocate directly from the nursery */
p = (void **)sgen_nursery_alloc (size);
if (!p)
return NULL;
increment_thread_allocation_counter (size);
sgen_set_nursery_scan_start ((char*)p);
/*FIXME we should use weak memory ops here. Should help specially on x86. */
@@ -350,6 +370,7 @@ sgen_try_alloc_obj_nolock (GCVTable vtable, size_t size)
if (!p)
return NULL;
increment_thread_allocation_counter (size);
zero_tlab_if_necessary (p, size);
} else {
size_t alloc_size = 0;
@@ -360,6 +381,8 @@ sgen_try_alloc_obj_nolock (GCVTable vtable, size_t size)
if (!p)
return NULL;
increment_thread_allocation_counter (TLAB_NEXT - TLAB_START);
TLAB_START = (char*)new_next;
TLAB_NEXT = new_next + size;
TLAB_REAL_END = new_next + alloc_size;
@@ -435,6 +458,7 @@ sgen_alloc_obj_pinned (GCVTable vtable, size_t size)
{
GCObject *p;
if (!SGEN_CAN_ALIGN_UP (size))
return NULL;
size = ALIGN_UP (size);
@@ -450,6 +474,7 @@ sgen_alloc_obj_pinned (GCVTable vtable, size_t size)
}
if (G_LIKELY (p)) {
SGEN_LOG (6, "Allocated pinned object %p, vtable: %p (%s), size: %zd", p, vtable, sgen_client_vtable_get_name (vtable), size);
increment_thread_allocation_counter (size);
sgen_binary_protocol_alloc_pinned (p, vtable, size, sgen_client_get_provenance ());
}
UNLOCK_GC;
@@ -469,6 +494,10 @@ sgen_alloc_obj_mature (GCVTable vtable, size_t size)
res = alloc_degraded (vtable, size, TRUE);
UNLOCK_GC;
if (res) {
increment_thread_allocation_counter (size);
}
return res;
}
@@ -480,6 +509,7 @@ sgen_clear_tlabs (void)
{
FOREACH_THREAD_ALL (info) {
/* A new TLAB will be allocated when the thread does its first allocation */
info->total_bytes_allocated += info->tlab_next - info->tlab_start;
info->tlab_start = NULL;
info->tlab_next = NULL;
info->tlab_temp_end = NULL;
+3
View File
@@ -414,6 +414,9 @@ struct _SgenThreadInfo {
char *tlab_next;
char *tlab_temp_end;
char *tlab_real_end;
/* Total bytes allocated by this thread in its lifetime so far. */
gint64 total_bytes_allocated;
};
gboolean sgen_is_worker_thread (MonoNativeThreadId thread);