Author: lupus
Date: 2007-10-08 05:46:23 -0400 (Mon, 08 Oct 2007)
New Revision: 87084
Modified:
trunk/mono/mono/utils/ChangeLog
trunk/mono/mono/utils/mono-codeman.c
trunk/mono/mono/utils/mono-codeman.h
Log:
Mon Oct 8 11:47:44 CEST 2007 Paolo Molaro <[EMAIL PROTECTED]>
* mono-codeman.c, mono-codeman.h: added a function to be able
to specify alignment per-allocation. Changed the code to align
the starting position instead of the size, which wouldn't work
with variable-alignment.
Modified: trunk/mono/mono/utils/ChangeLog
===================================================================
--- trunk/mono/mono/utils/ChangeLog 2007-10-08 09:27:17 UTC (rev 87083)
+++ trunk/mono/mono/utils/ChangeLog 2007-10-08 09:46:23 UTC (rev 87084)
@@ -1,4 +1,11 @@
+Mon Oct 8 11:47:44 CEST 2007 Paolo Molaro <[EMAIL PROTECTED]>
+
+ * mono-codeman.c, mono-codeman.h: added a function to be able
+ to specify alignment per-allocation. Changed the code to align
+ the starting position instead of the size, which wouldn't work
+ with variable-alignment.
+
Mon Oct 8 10:51:29 CEST 2007 Paolo Molaro <[EMAIL PROTECTED]>
* mono-codeman.c, mono-codeman.h: fixed alignment code to not
Modified: trunk/mono/mono/utils/mono-codeman.c
===================================================================
--- trunk/mono/mono/utils/mono-codeman.c 2007-10-08 09:27:17 UTC (rev
87083)
+++ trunk/mono/mono/utils/mono-codeman.c 2007-10-08 09:46:23 UTC (rev
87084)
@@ -62,6 +62,8 @@
CodeChunk *full;
};
+#define ALIGN_INT(val,alignment) (((val) + (alignment - 1)) & ~(alignment - 1))
+
/**
* mono_code_manager_new:
*
@@ -247,7 +249,7 @@
/* does it make sense to use the mmap-like API? */
if (flags == CODE_FLAG_MALLOC) {
- ptr = malloc (chunk_size);
+ ptr = malloc (chunk_size + MIN_ALIGN - 1);
if (!ptr)
return NULL;
} else {
@@ -299,20 +301,23 @@
* mono_code_manager_reserve:
* @cman: a code manager
* @size: size of memory to allocate
+ * @alignment: power of two alignment value
*
* Allocates at least @size bytes of memory inside the code manager @cman.
*
* Returns: the pointer to the allocated memory or #NULL on failure
*/
void*
-mono_code_manager_reserve (MonoCodeManager *cman, int size)
+mono_code_manager_reserve_align (MonoCodeManager *cman, int size, int
alignment)
{
CodeChunk *chunk, *prev;
void *ptr;
-
- size += MIN_ALIGN - 1;
- size &= ~ (MIN_ALIGN - 1);
+ /* eventually allow bigger alignments, but we need to fix the dynamic
alloc code to
+ * handle this before
+ */
+ g_assert (alignment <= MIN_ALIGN);
+
if (cman->dynamic) {
++mono_stats.dynamic_code_alloc_count;
mono_stats.dynamic_code_bytes_count += size;
@@ -325,7 +330,8 @@
}
for (chunk = cman->current; chunk; chunk = chunk->next) {
- if (chunk->pos + size <= chunk->size) {
+ if (ALIGN_INT (chunk->pos, alignment) + size <= chunk->size) {
+ chunk->pos = ALIGN_INT (chunk->pos, alignment);
ptr = chunk->data + chunk->pos;
chunk->pos += size;
return ptr;
@@ -353,12 +359,28 @@
return NULL;
chunk->next = cman->current;
cman->current = chunk;
+ chunk->pos = ALIGN_INT (chunk->pos, alignment);
ptr = chunk->data + chunk->pos;
chunk->pos += size;
return ptr;
}
/**
+ * mono_code_manager_reserve:
+ * @cman: a code manager
+ * @size: size of memory to allocate
+ *
+ * Allocates at least @size bytes of memory inside the code manager @cman.
+ *
+ * Returns: the pointer to the allocated memory or #NULL on failure
+ */
+void*
+mono_code_manager_reserve (MonoCodeManager *cman, int size)
+{
+ return mono_code_manager_reserve_align (cman, size, MIN_ALIGN);
+}
+
+/**
* mono_code_manager_commit:
* @cman: a code manager
* @data: the pointer returned by mono_code_manager_reserve ()
@@ -372,10 +394,7 @@
void
mono_code_manager_commit (MonoCodeManager *cman, void *data, int size, int
newsize)
{
- newsize += MIN_ALIGN - 1;
- newsize &= ~ (MIN_ALIGN - 1);
- size += MIN_ALIGN - 1;
- size &= ~ (MIN_ALIGN - 1);
+ g_assert (newsize <= size);
if (cman->current && (size != newsize) && (data == cman->current->data
+ cman->current->pos - size)) {
cman->current->pos -= size - newsize;
Modified: trunk/mono/mono/utils/mono-codeman.h
===================================================================
--- trunk/mono/mono/utils/mono-codeman.h 2007-10-08 09:27:17 UTC (rev
87083)
+++ trunk/mono/mono/utils/mono-codeman.h 2007-10-08 09:46:23 UTC (rev
87084)
@@ -8,6 +8,8 @@
void mono_code_manager_destroy (MonoCodeManager *cman);
void mono_code_manager_invalidate (MonoCodeManager *cman);
+void* mono_code_manager_reserve_align (MonoCodeManager *cman, int
size, int alignment);
+
void* mono_code_manager_reserve (MonoCodeManager *cman, int size);
void mono_code_manager_commit (MonoCodeManager *cman, void *data,
int size, int newsize);
int mono_code_manager_size (MonoCodeManager *cman, int
*used_size);
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches