Skip to content

Commit

Permalink
[sgen-binprot,sgen-gray-queue] Add binary_protocol_gray_(en|de)queue …
Browse files Browse the repository at this point in the history
…and call them on object enqueuing and dequeuing
  • Loading branch information
luhenry committed Jun 26, 2014
1 parent 470dd7b commit f2a6fb7
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 6 deletions.
23 changes: 18 additions & 5 deletions mono/metadata/sgen-gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ typedef struct _SgenThreadInfo SgenThreadInfo;
#include <mono/metadata/sgen-gray.h>
#include <mono/metadata/sgen-hash-table.h>
#include <mono/metadata/sgen-bridge.h>
#include <mono/metadata/sgen-protocol.h>

/* The method used to clear the nursery */
/* Clearing at nursery collections is the safest, but has bad interactions with caches.
Expand Down Expand Up @@ -352,10 +353,15 @@ GRAY_OBJECT_ENQUEUE (SgenGrayQueue *queue, char* obj)
#if defined(SGEN_GRAY_OBJECT_ENQUEUE) || SGEN_MAX_DEBUG_LEVEL >= 9
sgen_gray_object_enqueue (queue, obj);
#else
if (G_UNLIKELY (!queue->first || queue->cursor == GRAY_LAST_CURSOR_POSITION (queue->first)))
if (G_UNLIKELY (!queue->first || queue->cursor == GRAY_LAST_CURSOR_POSITION (queue->first))) {
sgen_gray_object_enqueue (queue, obj);
else
} else {
*++queue->cursor = obj;
#ifdef SGEN_HEAVY_BINARY_PROTOCOL
binary_protocol_gray_enqueue (queue, queue->cursor, obj);
#endif
}

PREFETCH (obj);
#endif
}
Expand All @@ -366,12 +372,19 @@ GRAY_OBJECT_DEQUEUE (SgenGrayQueue *queue, char** obj)
#if defined(SGEN_GRAY_OBJECT_ENQUEUE) || SGEN_MAX_DEBUG_LEVEL >= 9
*obj = sgen_gray_object_enqueue (queue);
#else
if (!queue->first)
if (!queue->first) {
*obj = NULL;
else if (G_UNLIKELY (queue->cursor == GRAY_FIRST_CURSOR_POSITION (queue->first)))
#ifdef SGEN_HEAVY_BINARY_PROTOCOL
binary_protocol_gray_dequeue (queue, queue->cursor, *obj);
#endif
} else if (G_UNLIKELY (queue->cursor == GRAY_FIRST_CURSOR_POSITION (queue->first))) {
*obj = sgen_gray_object_dequeue (queue);
else
} else {
*obj = *queue->cursor--;
#ifdef SGEN_HEAVY_BINARY_PROTOCOL
binary_protocol_gray_dequeue (queue, queue->cursor + 1, *obj);
#endif
}
#endif
}

Expand Down
9 changes: 9 additions & 0 deletions mono/metadata/sgen-gray.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "metadata/sgen-gc.h"
#include "utils/mono-counters.h"
#include "sgen-protocol.h"

#define GRAY_QUEUE_LENGTH_LIMIT 64

Expand Down Expand Up @@ -104,6 +105,10 @@ sgen_gray_object_enqueue (SgenGrayQueue *queue, char *obj)
STATE_ASSERT (queue->first, GRAY_QUEUE_SECTION_STATE_ENQUEUED);
SGEN_ASSERT (9, queue->cursor <= GRAY_LAST_CURSOR_POSITION (queue->first), "gray queue %p overflow, first %p, cursor %p", queue, queue->first, queue->cursor);
*++queue->cursor = obj;

#ifdef SGEN_HEAVY_BINARY_PROTOCOL
binary_protocol_gray_enqueue (queue, queue->cursor, obj);
#endif
}

char*
Expand All @@ -119,6 +124,10 @@ sgen_gray_object_dequeue (SgenGrayQueue *queue)

obj = *queue->cursor--;

#ifdef SGEN_HEAVY_BINARY_PROTOCOL
binary_protocol_gray_dequeue (queue, queue->cursor + 1, obj);
#endif

if (G_UNLIKELY (queue->cursor == (char**)queue->first->objects - 1)) {
GrayQueueSection *section = queue->first;
queue->first = section->next;
Expand Down
14 changes: 14 additions & 0 deletions mono/metadata/sgen-protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,20 @@ binary_protocol_dislink_process_staged (gpointer link, gpointer obj, int index)
SGenProtocolDislinkProcessStaged entry = { link, obj, index };
protocol_entry (SGEN_PROTOCOL_DISLINK_PROCESS_STAGED, &entry, sizeof (SGenProtocolDislinkProcessStaged));
}

void
binary_protocol_gray_enqueue (gpointer queue, gpointer cursor, gpointer value)
{
SGenProtocolGrayQueue entry = { queue, cursor, value };
protocol_entry (SGEN_PROTOCOL_GRAY_ENQUEUE, &entry, sizeof (SGenProtocolGrayQueue));
}

void
binary_protocol_gray_dequeue (gpointer queue, gpointer cursor, gpointer value)
{
SGenProtocolGrayQueue entry = { queue, cursor, value };
protocol_entry (SGEN_PROTOCOL_GRAY_DEQUEUE, &entry, sizeof (SGenProtocolGrayQueue));
}
#endif

#endif /* HAVE_SGEN_GC */
14 changes: 13 additions & 1 deletion mono/metadata/sgen-protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ enum {
SGEN_PROTOCOL_DISLINK_UPDATE_STAGED,
SGEN_PROTOCOL_DISLINK_PROCESS_STAGED,
SGEN_PROTOCOL_DOMAIN_UNLOAD_BEGIN,
SGEN_PROTOCOL_DOMAIN_UNLOAD_END
SGEN_PROTOCOL_DOMAIN_UNLOAD_END,
SGEN_PROTOCOL_GRAY_ENQUEUE,
SGEN_PROTOCOL_GRAY_DEQUEUE,
};

typedef struct {
Expand Down Expand Up @@ -224,6 +226,12 @@ typedef struct {
gpointer domain;
} SGenProtocolDomainUnload;

typedef struct {
gpointer queue;
gpointer cursor;
gpointer value;
} SGenProtocolGrayQueue;

/* missing: finalizers, roots, non-store wbarriers */

void binary_protocol_init (const char *filename) MONO_INTERNAL;
Expand Down Expand Up @@ -277,6 +285,8 @@ void binary_protocol_card_scan (gpointer start, int size) MONO_INTERNAL;
void binary_protocol_dislink_update (gpointer link, gpointer obj, int track, int staged) MONO_INTERNAL;
void binary_protocol_dislink_update_staged (gpointer link, gpointer obj, int track, int index) MONO_INTERNAL;
void binary_protocol_dislink_process_staged (gpointer link, gpointer obj, int index) MONO_INTERNAL;
void binary_protocol_gray_enqueue (gpointer queue, gpointer cursor, gpointer value) MONO_INTERNAL;
void binary_protocol_gray_dequeue (gpointer queue, gpointer cursor, gpointer value) MONO_INTERNAL;

#else

Expand All @@ -299,6 +309,8 @@ void binary_protocol_dislink_process_staged (gpointer link, gpointer obj, int in
#define binary_protocol_dislink_update(link,obj,track,staged)
#define binary_protocol_dislink_update_staged(link,obj,track,index)
#define binary_protocol_dislink_process_staged(link,obj,index)
#define binary_protocol_gray_enqueue(queue,cursor,value)
#define binary_protocol_gray_dequeue(queue,cursor,value)

#endif

Expand Down
22 changes: 22 additions & 0 deletions tools/sgen/sgen-grep-binprot.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ read_entry (FILE *in, void **data)
case SGEN_PROTOCOL_DISLINK_PROCESS_STAGED: size = sizeof (SGenProtocolDislinkProcessStaged); break;
case SGEN_PROTOCOL_DOMAIN_UNLOAD_BEGIN: size = sizeof (SGenProtocolDomainUnload); break;
case SGEN_PROTOCOL_DOMAIN_UNLOAD_END: size = sizeof (SGenProtocolDomainUnload); break;
case SGEN_PROTOCOL_GRAY_ENQUEUE: size = sizeof (SGenProtocolGrayQueue); break;
case SGEN_PROTOCOL_GRAY_DEQUEUE: size = sizeof (SGenProtocolGrayQueue); break;
default: assert (0);
}

Expand Down Expand Up @@ -91,6 +93,8 @@ is_always_match (int type)
case SGEN_PROTOCOL_CEMENT_RESET:
case SGEN_PROTOCOL_DOMAIN_UNLOAD_BEGIN:
case SGEN_PROTOCOL_DOMAIN_UNLOAD_END:
case SGEN_PROTOCOL_GRAY_ENQUEUE:
case SGEN_PROTOCOL_GRAY_DEQUEUE:
return TRUE;
default:
return FALSE;
Expand Down Expand Up @@ -292,6 +296,16 @@ print_entry (int type, void *data)
printf ("dislink_unload_end domain %p\n", entry->domain);
break;
}
case SGEN_PROTOCOL_GRAY_ENQUEUE: {
SGenProtocolGrayQueue *entry = data;
printf ("enqueue queue %p cursor %p value %p\n", entry->queue, entry->cursor, entry->value);
break;
}
case SGEN_PROTOCOL_GRAY_DEQUEUE: {
SGenProtocolGrayQueue *entry = data;
printf ("dequeue queue %p cursor %p value %p\n", entry->queue, entry->cursor, entry->value);
break;
}
default:
assert (0);
}
Expand Down Expand Up @@ -379,6 +393,14 @@ is_match (gpointer ptr, int type, void *data)
SGenProtocolDislinkProcessStaged *entry = data;
return ptr == entry->obj || ptr == entry->link;
}
case SGEN_PROTOCOL_GRAY_ENQUEUE: {
SGenProtocolGrayQueue *entry = data;
return ptr == entry->cursor || ptr == entry->value;
}
case SGEN_PROTOCOL_GRAY_DEQUEUE: {
SGenProtocolGrayQueue *entry = data;
return ptr == entry->cursor || ptr == entry->value;
}
default:
if (is_always_match (type))
return TRUE;
Expand Down

0 comments on commit f2a6fb7

Please sign in to comment.