Author: lupus
Date: 2007-10-08 04:37:41 -0400 (Mon, 08 Oct 2007)
New Revision: 87080

Modified:
   trunk/mono/mono/utils/ChangeLog
   trunk/mono/mono/utils/mono-codeman.c
   trunk/mono/mono/utils/mono-codeman.h
Log:


Mon Oct 8 10:51:29 CEST 2007 Paolo Molaro <[EMAIL PROTECTED]>

        * mono-codeman.c, mono-codeman.h: fixed alignment code to not
        be wasteful, Added documentation. Added mono_code_manager_size ()
        to gather statistics info about a code manager.



Modified: trunk/mono/mono/utils/ChangeLog
===================================================================
--- trunk/mono/mono/utils/ChangeLog     2007-10-08 08:10:20 UTC (rev 87079)
+++ trunk/mono/mono/utils/ChangeLog     2007-10-08 08:37:41 UTC (rev 87080)
@@ -1,4 +1,10 @@
 
+Mon Oct 8 10:51:29 CEST 2007 Paolo Molaro <[EMAIL PROTECTED]>
+
+       * mono-codeman.c, mono-codeman.h: fixed alignment code to not
+       be wasteful, Added documentation. Added mono_code_manager_size ()
+       to gather statistics info about a code manager.
+
 Mon Oct 8 10:21:47 CEST 2007 Paolo Molaro <[EMAIL PROTECTED]>
 
        * mono-counters.h, mono-counters.c: better formatting of the output

Modified: trunk/mono/mono/utils/mono-codeman.c
===================================================================
--- trunk/mono/mono/utils/mono-codeman.c        2007-10-08 08:10:20 UTC (rev 
87079)
+++ trunk/mono/mono/utils/mono-codeman.c        2007-10-08 08:37:41 UTC (rev 
87080)
@@ -62,6 +62,17 @@
        CodeChunk *full;
 };
 
+/**
+ * mono_code_manager_new:
+ *
+ * Creates a new code manager. A code manager can be used to allocate memory
+ * suitable for storing native code that can be later executed.
+ * A code manager allocates memory from the operating system in large chunks
+ * (typically 64KB in size) so that many methods can be allocated inside them
+ * close together, improving cache locality.
+ *
+ * Returns: the new code manager
+ */
 MonoCodeManager* 
 mono_code_manager_new (void)
 {
@@ -74,6 +85,15 @@
        return cman;
 }
 
+/**
+ * mono_code_manager_new_dynamic:
+ *
+ * Creates a new code manager suitable for holding native code that can be
+ * used for single or small methods that need to be deallocated independently
+ * of other native code.
+ *
+ * Returns: the new code manager
+ */
 MonoCodeManager* 
 mono_code_manager_new_dynamic (void)
 {
@@ -110,6 +130,12 @@
        }
 }
 
+/**
+ * mono_code_manager_destroy:
+ * @cman: a code manager
+ *
+ * Free all the memory associated with the code manager @cman.
+ */
 void
 mono_code_manager_destroy (MonoCodeManager *cman)
 {
@@ -118,7 +144,14 @@
        free (cman);
 }
 
-/* fill all the memory with the 0x2a (42) value */
+/**
+ * mono_code_manager_invalidate:
+ * @cman: a code manager
+ *
+ * Fill all the memory with an invalid native code value
+ * so that any attempt to execute code allocated in the code
+ * manager @cman will fail. This is used for debugging purposes.
+ */
 void             
 mono_code_manager_invalidate (MonoCodeManager *cman)
 {
@@ -136,6 +169,15 @@
                memset (chunk->data, fill_value, chunk->size);
 }
 
+/**
+ * mono_code_manager_foreach:
+ * @cman: a code manager
+ * @func: a callback function pointer
+ * @user_data: additional data to pass to @func
+ *
+ * Invokes the callback @func for each different chunk of memory allocated
+ * in the code manager @cman.
+ */
 void
 mono_code_manager_foreach (MonoCodeManager *cman, MonoCodeManagerFunc func, 
void *user_data)
 {
@@ -253,13 +295,22 @@
        return chunk;
 }
 
+/**
+ * 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)
 {
        CodeChunk *chunk, *prev;
        void *ptr;
        
-       size += MIN_ALIGN;
+       size += MIN_ALIGN - 1;
        size &= ~ (MIN_ALIGN - 1);
 
        if (cman->dynamic) {
@@ -307,16 +358,23 @@
        return ptr;
 }
 
-/* 
- * if we reserved too much room for a method and we didn't allocate
- * already from the code manager, we can get back the excess allocation.
+/**
+ * mono_code_manager_commit:
+ * @cman: a code manager
+ * @data: the pointer returned by mono_code_manager_reserve ()
+ * @size: the size requested in the call to mono_code_manager_reserve ()
+ * @newsize: the new size to reserve
+ *
+ * If we reserved too much room for a method and we didn't allocate
+ * already from the code manager, we can get back the excess allocation
+ * for later use in the code manager.
  */
 void
 mono_code_manager_commit (MonoCodeManager *cman, void *data, int size, int 
newsize)
 {
-       newsize += MIN_ALIGN;
+       newsize += MIN_ALIGN - 1;
        newsize &= ~ (MIN_ALIGN - 1);
-       size += MIN_ALIGN;
+       size += MIN_ALIGN - 1;
        size &= ~ (MIN_ALIGN - 1);
 
        if (cman->current && (size != newsize) && (data == cman->current->data 
+ cman->current->pos - size)) {
@@ -324,3 +382,33 @@
        }
 }
 
+/**
+ * mono_code_manager_size:
+ * @cman: a code manager
+ * @used_size: pointer to an integer for the result
+ *
+ * This function can be used to get statistics about a code manager:
+ * the integer pointed to by @used_size will contain how much
+ * memory is actually used inside the code managed @cman.
+ *
+ * Returns: the amount of memory allocated in @cman
+ */
+int
+mono_code_manager_size (MonoCodeManager *cman, int *used_size)
+{
+       CodeChunk *chunk;
+       guint32 size = 0;
+       guint32 used = 0;
+       for (chunk = cman->current; chunk; chunk = chunk->next) {
+               size += chunk->size;
+               used += chunk->pos;
+       }
+       for (chunk = cman->full; chunk; chunk = chunk->next) {
+               size += chunk->size;
+               used += chunk->pos;
+       }
+       if (used_size)
+               *used_size = used;
+       return size;
+}
+

Modified: trunk/mono/mono/utils/mono-codeman.h
===================================================================
--- trunk/mono/mono/utils/mono-codeman.h        2007-10-08 08:10:20 UTC (rev 
87079)
+++ trunk/mono/mono/utils/mono-codeman.h        2007-10-08 08:37:41 UTC (rev 
87080)
@@ -10,6 +10,7 @@
 
 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);
 
 /* find the extra block allocated to resolve branches close to code */
 typedef int    (*MonoCodeManagerFunc)      (void *data, int csize, int size, 
void *user_data);

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to