2002-02-19 Dietmar Maurer <dietmar@ximian.com>
authorDietmar Maurer <dietmar@mono-cvs.ximian.com>
Tue, 19 Feb 2002 06:01:21 +0000 (06:01 -0000)
committerDietmar Maurer <dietmar@mono-cvs.ximian.com>
Tue, 19 Feb 2002 06:01:21 +0000 (06:01 -0000)
* appdomain.c (mono_domain_transfer_object): impl. hack for Arrays
and String - but we will need generic marshalling support in the
future.

* object.c (mono_string_new_utf16): bug fix: use char[] instead of
String[].

svn path=/trunk/mono/; revision=2494

16 files changed:
mono/interpreter/interp.c
mono/jit/Makefile.am
mono/jit/debug.c
mono/jit/jit.c
mono/jit/jit.h
mono/jit/mempool.c [deleted file]
mono/jit/mempool.h [deleted file]
mono/jit/x86.brg
mono/metadata/ChangeLog
mono/metadata/Makefile.am
mono/metadata/appdomain.c
mono/metadata/appdomain.h
mono/metadata/icall.c
mono/metadata/mempool.c
mono/metadata/object.c
mono/tests/appdomain.cs

index 35f8df2b1d6891b26c3f57ba8cf3601d4fe22102..1d6421c220ce20c4d3f23ea6c82f0addac4085d0 100644 (file)
@@ -3822,7 +3822,7 @@ main (int argc, char *argv [])
        mono_network_cleanup ();
        mono_thread_cleanup ();
 
-       //mono_domain_unload (domain);
+       mono_domain_unload (domain, TRUE);
 
 #if DEBUG_INTERP
        if (ocount) {
index 5288980a9e5580a542544125d4ab487e8a9b6083..a9f581cddee5f43032865b9f56bfd511bc452671 100644 (file)
@@ -16,8 +16,6 @@ mono_SOURCES =                        \
        regset.c                \
        debug.h                 \
        debug.c                 \
-       mempool.h               \
-       mempool.c               \
        jit.c
 
 mono_LDADD =                           \
index 96c4e81a318b6fb08e2c968e6dceadd08d79fcc7..ada49bb3505483be71a8445f696ad7263594a799 100644 (file)
@@ -235,7 +235,7 @@ mono_debug_add_method (MonoDebugHandle* debug, MonoFlowGraph *cfg)
        fprintf (info->f, ".stabs \"%s:F(0,%d)\",36,0,%d,%p\n", name, sig->ret->type, line, cfg->start);
 
        /* params */
-       mono_method_get_param_names (cfg->method, names);
+       mono_method_get_param_names (cfg->method, (const char **)names);
        if (sig->hasthis)
                fprintf (info->f, ".stabs \"this:p(0,%d)=(0,%d)\",160,0,%d,%d\n", info->next_idx++, klass->byval_arg.type, line, 8); /* FIXME */
        for (i = 0; i < sig->param_count; ++i) {
index 4ac1f1f6d46b5d2cd72b62012adc3619d9b5707a..54b5d5ff3fa37097e98cc4bd3485734640aed1f9 100644 (file)
@@ -3420,7 +3420,7 @@ main (int argc, char *argv [])
        mono_network_cleanup();
        mono_thread_cleanup();
 
-       // mono_domain_unload (domain);
+       mono_domain_unload (domain, TRUE);
 
        return retval;
 }
index a9b8287a3bc9dd1316a03c2044c60ff2828248dc..eb4c78103d4551c59c732ada7c1de7dee13b7ef5 100644 (file)
@@ -6,9 +6,9 @@
 #include <mono/metadata/loader.h>
 #include <mono/metadata/object.h>
 #include <mono/metadata/exception.h>
+#include <mono/metadata/mempool.h>
 
 #include "regset.h"
-#include "mempool.h"
 
 #define ISSTRUCT(t) (!t->byref && t->type == MONO_TYPE_VALUETYPE && !t->data.klass->enumtype)
 
@@ -112,7 +112,6 @@ typedef struct {
        guint32  used_regs;
        unsigned num_clauses;
        MonoJitExceptionInfo *clauses;
-
 } MonoJitInfo;
 
 typedef GArray MonoJitInfoTable;
diff --git a/mono/jit/mempool.c b/mono/jit/mempool.c
deleted file mode 100644 (file)
index 525cdd3..0000000
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * mempool.c: efficient memory allocation
- *
- * MonoMemPool is for fast allocation of memory. We free
- * all memory when the pool is destroyed.
- *
- * Author:
- *   Dietmar Maurer (dietmar@ximian.com)
- *
- * (C) 2001 Ximian, Inc.
- */
-
-#include <config.h>
-#include <glib.h>
-#include <string.h>
-
-#include "jit.h"
-
-/*
- * MonoMemPool is for fast allocation of memory. We free
- * all memory when the pool is destroyed.
- */
-
-#if SIZEOF_VOID_P > SIZEOF_LONG
-#define MEM_ALIGN     SIZEOF_VOID_P
-#else
-#define MEM_ALIGN     SIZEOF_LONG
-#endif
-
-#define MONO_MEMPOOL_PAGESIZE 8192
-
-struct _MonoMemPool {
-       MonoMemPool *next;
-       gint rest;
-       gpointer pos;
-};
-
-/**
- * mono_mempool_new:
- *
- * Returns: a new memory pool.
- */
-MonoMemPool *
-mono_mempool_new ()
-{
-
-       MonoMemPool *pool = g_malloc (MONO_MEMPOOL_PAGESIZE);
-       pool->next = NULL;
-       pool->pos = (gpointer)pool + sizeof (MonoMemPool);
-       pool->rest = MONO_MEMPOOL_PAGESIZE - sizeof (MonoMemPool);
-       return pool;
-}
-
-/**
- * mono_mempool_destroy:
- * @pool: the momory pool to destroy
- *
- * Free all memory associated with this pool.
- */
-void
-mono_mempool_destroy (MonoMemPool *pool)
-{
-       MonoMemPool *p, *n;
-
-       p = pool;
-       while (p) {
-               n = p->next;
-               g_free (p);
-               p = n;
-       }
-}
-
-/**
- * mono_mempool_alloc:
- * @pool: the momory pool to destroy
- * @size: size of the momory block
- *
- * Allocates a new block of memory in @pool. @size must 
- * be smaller than 256.
- *
- * Returns: the address of a newly allocated memory block.
- */
-gpointer
-mono_mempool_alloc (MonoMemPool *pool, guint size)
-{
-       gpointer rval;
-       
-       g_assert (pool != NULL);
-
-       if (size >= 4096) {
-               MonoMemPool *np = g_malloc (sizeof (MonoMemPool) + size);
-               np->next = pool->next;
-               pool->next = np;
-               return (gpointer)np + sizeof (MonoMemPool);
-       }
-
-       size = (size + MEM_ALIGN - 1) & ~(MEM_ALIGN - 1);
-
-       if (pool->rest < size) {
-               MonoMemPool *np = g_malloc (MONO_MEMPOOL_PAGESIZE);
-               np->next = pool->next;
-               pool->next = np;
-               pool->pos = (gpointer)np + sizeof (MonoMemPool);
-               pool->rest = MONO_MEMPOOL_PAGESIZE - sizeof (MonoMemPool);
-       }
-
-       rval = pool->pos;
-       pool->rest -= size;
-       pool->pos += size;
-
-       return rval;
-}
-
-/**
- * mono_mempool_alloc0:
- *
- * same as mono_mempool_alloc, but fills memory with zero.
- */
-gpointer
-mono_mempool_alloc0 (MonoMemPool *pool, guint size)
-{
-       gpointer rval = mono_mempool_alloc (pool, size);
-       memset (rval, 0, size);
-       return rval;
-}
-
diff --git a/mono/jit/mempool.h b/mono/jit/mempool.h
deleted file mode 100644 (file)
index 36df629..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-#ifndef _MONO_MEMPOOL_H_
-#define _MONO_MEMPOOL_H_
-
-typedef struct _MonoMemPool MonoMemPool;
-
-MonoMemPool *
-mono_mempool_new           (void);
-
-void
-mono_mempool_destroy       (MonoMemPool *pool);
-
-gpointer
-mono_mempool_alloc         (MonoMemPool *pool, guint size);
-
-gpointer
-mono_mempool_alloc0        (MonoMemPool *pool, guint size);
-
-#endif
index 24167e4e1d092e43c357875d7dc01f67db02a997..cbda4ea319de303a7c412cf89a18a5df59491ffc 100644 (file)
@@ -22,7 +22,6 @@
 #include <mono/arch/x86/x86-codegen.h>
 
 #include "regset.h"
-#include "mempool.h"
 #include "jit.h"
 
 #define MBTREE_TYPE  MBTree
index 19d821e15f687fbb42c8e98315df091ed78dfc1a..b871c4cbdb13b24d078107b017054120dd5c9ebd 100644 (file)
@@ -1,3 +1,18 @@
+2002-02-19  Dietmar Maurer  <dietmar@ximian.com>
+
+       * appdomain.c (mono_domain_transfer_object): impl. hack for Arrays
+       and String - but we will need generic marshalling support in the
+       future. 
+
+       * object.c (mono_string_new_utf16): bug fix: use char[] instead of
+       String[].
+
+2002-02-18  Dietmar Maurer  <dietmar@ximian.com>
+
+       * object.c (mono_array_clone): use alloca() instead of g_malloc  
+       for sizes
+
+       * appdomain.c (mono_domain_unload): impl.
 
 Mon Feb 18 15:52:20 CET 2002 Paolo Molaro <lupus@ximian.com>
 
index f15c286d7229925b42431fdbd8b011e3ce8c5828..73d25fdfe2e0a42ee30964b6cd893b30fc41ccd3 100644 (file)
@@ -37,6 +37,8 @@ libmetadata_a_SOURCES = \
        exception.h     \
        unicode.c       \
        unicode.h       \
+       mempool.h       \
+       mempool.c       \
        appdomain.h     \
        appdomain.c
 
index ab5a85981d4da24c9a2bd7430ae794f76f073b6e..3a29a13adbad6d9429243d709f4f7aaf1c74cb16 100644 (file)
@@ -56,6 +56,7 @@ mono_create_domain ()
        domain->setup = NULL;
        domain->friendly_name = NULL;
 
+       domain->mp = mono_mempool_new ();
        domain->env = g_hash_table_new (g_str_hash, g_str_equal);
        domain->assemblies = g_hash_table_new (g_str_hash, g_str_equal);
        domain->class_vtable_hash = g_hash_table_new (NULL, NULL);
@@ -65,6 +66,8 @@ mono_create_domain ()
        return domain;
 }
 
+MonoDomain *mono_root_domain = NULL;
+
 /**
  * mono_init:
  * 
@@ -90,6 +93,7 @@ mono_init ()
        appdomain_thread_id = TlsAlloc ();
 
        domain = mono_create_domain ();
+       mono_root_domain = domain;
 
        TlsSetValue (appdomain_thread_id, domain);
 
@@ -234,9 +238,54 @@ ves_icall_System_AppDomainSetup_InitAppDomainSetup (MonoAppDomainSetup *setup)
 static MonoObject *
 mono_domain_transfer_object (MonoDomain *src, MonoDomain *dst, MonoObject *obj)
 {
+       MonoClass *klass;
+       MonoObject *res;        
+
+       if (!obj)
+               return NULL;
+
+       g_assert (obj->vtable->domain == src);
+
        /* fixme: transfer an object from one domain into another */
-       g_assert_not_reached ();
-       return obj;
+
+       klass = obj->vtable->klass;
+
+       if (MONO_CLASS_IS_ARRAY (klass)) {
+               MonoArray *ao = (MonoArray *)obj;
+               int esize, ecount, i;
+               guint32 *sizes;
+               
+               sizes = alloca (klass->rank * sizeof(guint32) * 2);
+               esize = mono_array_element_size (klass);
+               ecount = 1;
+               for (i = 0; i < klass->rank; ++i) {
+                       sizes [i] = ao->bounds [i].length;
+                       ecount *= ao->bounds [i].length;
+                       sizes [i + klass->rank] = ao->bounds [i].lower_bound;
+               }
+               res = (MonoObject *)mono_array_new_full (dst, klass, sizes, sizes + klass->rank);
+               if (klass->element_class->valuetype) {
+                       memcpy (res, (char *)ao + sizeof(MonoArray), esize * ecount);
+               } else {
+                       g_assert (esize == sizeof (gpointer));
+                       for (i = 0; i < ecount; i++) {
+                               int offset = sizeof (MonoArray) + esize * i;
+                               gpointer *src_ea = (gpointer *)((char *)ao + offset);
+                               gpointer *dst_ea = (gpointer *)((char *)res + offset);
+
+                               *dst_ea = mono_domain_transfer_object (src, dst, *src_ea);
+                       }
+               }
+       } else if (klass == mono_defaults.string_class) {
+               MonoString *str = (MonoString *)obj;
+               res = (MonoObject *)mono_string_new_utf16 (dst, 
+                       (const guint16 *)str->c_str->vector, str->length); 
+       } else {
+               // fixme: we need generic marshalling code here */
+               g_assert_not_reached ();
+       }
+       
+       return res;
 }
 
 MonoObject *
@@ -440,7 +489,7 @@ ves_icall_System_AppDomain_LoadAssembly (MonoAppDomain *ad,  MonoReflectionAssem
 void
 ves_icall_System_AppDomain_Unload (MonoAppDomain *ad)
 {
-       mono_domain_unload (ad->data);
+       mono_domain_unload (ad->data, FALSE);
 }
 
 /**
@@ -473,10 +522,35 @@ mono_domain_assembly_open (MonoDomain *domain, char *name)
        return ass;
 }
 
+static void
+remove_assembly (gpointer key, gpointer value, gpointer user_data)
+{
+       mono_assembly_close ((MonoAssembly *)value);
+}
+
 void
-mono_domain_unload (MonoDomain *domain)
+mono_domain_unload (MonoDomain *domain, gboolean force)
 {
-       g_warning ("Domain unloading not yet implemented");
+       if ((domain == mono_root_domain) && !force) {
+               g_warning ("cant unload root domain");
+               return;
+       }
+
+       g_hash_table_foreach (domain->assemblies, remove_assembly, NULL);
+
+       g_hash_table_destroy (domain->env);
+       g_hash_table_destroy (domain->assemblies);
+       g_hash_table_destroy (domain->class_vtable_hash);
+       g_hash_table_destroy (domain->jit_code_hash);
+       g_hash_table_destroy (domain->ldstr_table);
+       mono_mempool_destroy (domain->mp);
+       
+       // fixme: anything else required ? */
+
+       g_free (domain);
+
+       if ((domain == mono_root_domain))
+               mono_root_domain = NULL;
 }
 
 gint32
@@ -488,6 +562,7 @@ ves_icall_System_AppDomain_ExecuteAssembly (MonoAppDomain *ad, MonoString *file,
        MonoImage *image;
        MonoCLIImageInfo *iinfo;
        MonoMethod *method;
+       MonoObject *margs;
        char *filename;
        gint32 res;
 
@@ -509,7 +584,8 @@ ves_icall_System_AppDomain_ExecuteAssembly (MonoAppDomain *ad, MonoString *file,
        if (!method)
                g_error ("No entry point method found in %s", image->name);
 
-       res = mono_runtime_exec_main (method, args);
+       margs = mono_domain_transfer_object (cdom, ad->data, (MonoObject *)args);
+       res = mono_runtime_exec_main (method, (MonoArray *)margs);
 
        mono_domain_set (cdom);
 
index c3ba0be22b2786302a2585e6c3c51de28326881b..5992da79bc4a197092d573fa534ac1ce95fa06e1 100644 (file)
@@ -15,6 +15,7 @@
 
 #include <mono/metadata/object.h>
 #include <mono/metadata/reflection.h>
+#include <mono/metadata/mempool.h>
 
 /* This is a copy of System.AppDomainSetup */
 typedef struct {
@@ -36,13 +37,14 @@ typedef struct _MonoAppDomain MonoAppDomain;
 
 struct _MonoDomain {
        MonoAppDomain *domain;
-       GHashTable *env;
-       GHashTable *assemblies;
+       MonoMemPool   *mp;
+       GHashTable    *env;
+       GHashTable    *assemblies;
        MonoAppDomainSetup *setup;
-       MonoString *friendly_name;
-       GHashTable *ldstr_table;
-       GHashTable *class_vtable_hash;
-       GHashTable *jit_code_hash;
+       MonoString    *friendly_name;
+       GHashTable    *ldstr_table;
+       GHashTable    *class_vtable_hash;
+       GHashTable    *jit_code_hash;
 };
 
 /* This is a copy of System.AppDomain */
@@ -51,6 +53,8 @@ struct _MonoAppDomain {
        MonoDomain *data;
 };
 
+extern MonoDomain *mono_root_domain;
+
 MonoDomain *
 mono_init (void);
 
@@ -64,7 +68,7 @@ MonoAssembly *
 mono_domain_assembly_open (MonoDomain *domain, char *name);
 
 void
-mono_domain_unload (MonoDomain *domain);
+mono_domain_unload (MonoDomain *domain, gboolean force);
 
 void
 ves_icall_System_AppDomainSetup_InitAppDomainSetup (MonoAppDomainSetup *setup);
index da6465bb8478cff1c5cb43c4590a8bd20320d86a..2459a65fb868153f00ba387130e0bb430ad08c89 100644 (file)
@@ -107,7 +107,7 @@ ves_icall_System_Array_SetValue (MonoObject *this, MonoObject *value,
 }
 
 static void
-ves_icall_System_Array_CreateInstance ()
+ves_icall_System_Array_CreateInstanceImpl ()
 {
        g_warning ("not implemented");
        g_assert_not_reached ();
@@ -442,7 +442,7 @@ ves_icall_get_type_info (MonoType *type, MonoTypeInfo *info)
 
 static MonoObject*
 ves_icall_InternalInvoke (MonoReflectionMethod *method, MonoObject *this, MonoArray *params) {
-       MonoMethodSignature *sig = method->method->signature;
+       //MonoMethodSignature *sig = method->method->signature;
 
        /*
         * Do we need to copy the values so that the called method can't change them?
@@ -935,7 +935,7 @@ static gpointer icall_map [] = {
        "System.Array::GetRank",          ves_icall_System_Array_GetRank,
        "System.Array::GetLength",        ves_icall_System_Array_GetLength,
        "System.Array::GetLowerBound",    ves_icall_System_Array_GetLowerBound,
-       "System.Array::CreateInstance",   ves_icall_System_Array_CreateInstance,
+       "System.Array::CreateInstanceImpl",   ves_icall_System_Array_CreateInstanceImpl,
        "System.Array::FastCopy",         ves_icall_System_Array_FastCopy,
        "System.Array::Clone",            mono_array_clone,
 
index 525cdd3a8525916e5b1bfc988ed4ccbfee6424ea..78e81dd4ac05b9a767b566abee9a467e35a0dd7a 100644 (file)
@@ -14,7 +14,7 @@
 #include <glib.h>
 #include <string.h>
 
-#include "jit.h"
+#include "mempool.h"
 
 /*
  * MonoMemPool is for fast allocation of memory. We free
index 11f6e03eecd348ef09ecc318246d44e31159173c..879de601aed55352d73be5a4b9201a348707d671 100644 (file)
@@ -150,7 +150,7 @@ mono_array_clone (MonoArray *array)
        guint32 *sizes;
        MonoClass *klass = array->obj.vtable->klass;
        
-       sizes = g_malloc (klass->rank * sizeof(guint32) * 2);
+       sizes = alloca (klass->rank * sizeof(guint32) * 2);
        size = mono_array_element_size (klass);
        for (i = 0; i < klass->rank; ++i) {
                sizes [i] = array->bounds [i].length;
@@ -240,7 +240,7 @@ mono_string_new_utf16 (MonoDomain *domain, const guint16 *text, gint32 len)
        s = (MonoString*)mono_object_new (domain, mono_defaults.string_class);
        g_assert (s != NULL);
 
-       ca = (MonoArray *)mono_array_new (domain, mono_defaults.string_class, len);
+       ca = (MonoArray *)mono_array_new (domain, mono_defaults.char_class, len);
        g_assert (ca != NULL);
        
        s->c_str = ca;
index a6cdfcd1f313af6c05796cbf895cd94b82a4aa43..e15bbd37d7b2d0b9c2dee77161cc4a85eedf5996 100644 (file)
@@ -16,7 +16,7 @@ class Container {
 
                string[] args = { "test0", "test1" };
                
-               newDomain.ExecuteAssembly ("jit-int.exe");
+               newDomain.ExecuteAssembly ("jit-int.exe", null, args);
 
                Console.WriteLine ("Ready");
        }