Author: heimdall
Date: Fri Aug 12 18:50:35 2005
New Revision: 8934

Modified:
   branches/gmc/include/parrot/headers.h
   branches/gmc/include/parrot/pobj.h
   branches/gmc/include/parrot/smallobject.h
   branches/gmc/include/parrot/stacks.h
   branches/gmc/lib/Parrot/Pmc2c.pm
   branches/gmc/src/gc_gmc.c
   branches/gmc/src/headers.c
   branches/gmc/src/jit_debug.c
   branches/gmc/src/smallobject.c
Log:
Object allocation almost works, it seems to be only lacking gc_gmc_more_objects
when no more memory is available.


Modified: branches/gmc/include/parrot/headers.h
==============================================================================
--- branches/gmc/include/parrot/headers.h       (original)
+++ branches/gmc/include/parrot/headers.h       Fri Aug 12 18:50:35 2005
@@ -34,6 +34,7 @@ struct Small_Object_Pool *get_bufferlike
 struct Small_Object_Pool *make_bufferlike_pool(Interp *interpreter, size_t 
unit_size);
 /* header creation functions */
 PMC *new_pmc_header(Interp *interpreter, UINTVAL flags);
+PMC *new_pmc_typed_header(Interp *interpreter, UINTVAL flags, INTVAL 
base_type);
 void add_pmc_ext(Interp *interpreter, PMC *pmc);
 STRING *new_string_header(Interp *interpreter, UINTVAL flags);
 Buffer *new_buffer_header(Interp *interpreter);

Modified: branches/gmc/include/parrot/pobj.h
==============================================================================
--- branches/gmc/include/parrot/pobj.h  (original)
+++ branches/gmc/include/parrot/pobj.h  Fri Aug 12 18:50:35 2005
@@ -87,17 +87,43 @@ typedef struct pobj_t {
 } pobj_t;
 
 /* plain Buffer is the smallest Parrot Obj */
+#if PARROT_GC_GMC
+
+
+/* TODO: Change to a real pmc_body type. */
+#define DEFAULT_BODY UnionVal
+#define PMC_BODY DEFAULT_BODY
+
+
+/* Hack for the get_FLAGS macro to be happy. */
+typedef struct flags_holder {
+    Parrot_UInt flags;
+#if ! DISABLE_GC_DEBUG
+    UINTVAL _pobj_version;
+#endif
+} flags_holder;
+
+
+typedef struct Buffer {
+    PMC_BODY *body;
+    flags_holder obj;
+} Buffer;
+
+#else
+
 typedef struct Buffer {
     pobj_t obj;
 } Buffer;
 
+#endif
+
 typedef Buffer PObj;
 
 #if PARROT_GC_GMC
 
-#define PObj_bufstart(pmc)    (pmc)->obj.u._b._bufstart
-#define PObj_buflen(pmc)      (pmc)->obj.u._b._buflen
 #define PMC_body(pmc)         (pmc)->body
+#define PObj_bufstart(pmc)    PMC_body(pmc)->_b._bufstart
+#define PObj_buflen(pmc)      PMC_body(pmc)->_b._buflen
 #define PMC_struct_val(pmc)   PMC_body(pmc)->_ptrs._struct_val
 #define PMC_pmc_val(pmc)      PMC_body(pmc)->_ptrs._pmc_val
 #define PMC_int_val(pmc)      PMC_body(pmc)->_i._int_val
@@ -140,7 +166,12 @@ typedef enum {
 } parrot_string_representation_t;
 
 struct parrot_string_t {
+#if PARROT_GC_GMC
+    PMC_BODY *body;
+    flags_holder obj;
+#else
     pobj_t obj;
+#endif
     UINTVAL bufused;
     void *strstart;
     UINTVAL strlen;
@@ -161,15 +192,8 @@ struct parrot_string_t {
 #define PMC_DATA_IN_EXT 1
 
 
-/* TODO: Change to a real pmc_body type. */
-#if PARROT_GC_GMC
-#define DEFAULT_BODY UnionVal
-#define PMC_BODY DEFAULT_BODY
 
-/* Hack for the get_FLAGS macro to be happy. */
-typedef struct flags_holder {
-    Parrot_UInt flags;
-} flags_holder;
+#if PARROT_GC_GMC
 #endif
 
 struct PMC {

Modified: branches/gmc/include/parrot/smallobject.h
==============================================================================
--- branches/gmc/include/parrot/smallobject.h   (original)
+++ branches/gmc/include/parrot/smallobject.h   Fri Aug 12 18:50:35 2005
@@ -150,6 +150,7 @@ typedef enum gmc_flags {
 
 
 /* Macros for access from header. */
+#define Gmc_PMC_hdr_get_BODY(pmc_hdr)              
((PMC_BODY*)((char*)(pmc_hdr) + sizeof(Gc_gmc_hdr)))
 #define Gmc_PMC_hdr_get_FLAGS(pmc_hdr)             ((pmc_hdr)->gmc_flags)
 #define Gmc_PMC_hdr_get_PMC(pmc_hdr)               ((pmc_hdr)->pmc)
 #define Gmc_PMC_hdr_flag_TEST(flag, pmc_hdr)       
(Gmc_PMC_hdr_get_FLAGS(pmc_hdr) & (Gmc_ ## flag ## _FLAG))
@@ -158,7 +159,7 @@ typedef enum gmc_flags {
                                                          ~(UINTVAL)(Gmc_ ## 
flag ## _FLAG))
 
 /* Macros for access from body. */
-#define Gmc_PMC_body_get_HDR(pmc_body)             ((Gc_gmc_hdr*)((pmc_body) - 
sizeof(Gc_gmc_hdr)))
+#define Gmc_PMC_body_get_HDR(pmc_body)             
((Gc_gmc_hdr*)((char*)(pmc_body) - sizeof(Gc_gmc_hdr)))
 #define Gmc_PMC_body_get_FLAGS(pmc_body)           
Gmc_PMC_hdr_get_FLAGS(Gmc_PMC_body_get_hdr(pmc_body))
 #define Gmc_PMC_body_get_PMC(pmc_body)             
Gmc_PMC_hdr_get_PMC(Gmc_PMC_body_get_hdr(pmc_body))
 #define Gmc_PMC_body_flag_TEST(flag, pmc_body)     Gmc_PMC_hdr_flag_TEST(flag, 
Gmc_PMC_body_get_hdr(pmc_body))

Modified: branches/gmc/include/parrot/stacks.h
==============================================================================
--- branches/gmc/include/parrot/stacks.h        (original)
+++ branches/gmc/include/parrot/stacks.h        Fri Aug 12 18:50:35 2005
@@ -24,7 +24,11 @@ typedef struct Stack_Entry {
 } Stack_Entry_t;
 
 typedef struct Stack_Chunk {
+#if PARROT_GC_GMC
+    PMC_BODY *body;
+#else
     pobj_t obj;
+#endif
     int size;
     const char * name;
     struct Stack_Chunk *prev;

Modified: branches/gmc/lib/Parrot/Pmc2c.pm
==============================================================================
--- branches/gmc/lib/Parrot/Pmc2c.pm    (original)
+++ branches/gmc/lib/Parrot/Pmc2c.pm    Fri Aug 12 18:50:35 2005
@@ -845,7 +845,7 @@ Parrot_${classname}_class_init(Parrot_In
         $enum_name,    /* base_type */
         NULL,  /* whoami */
         $vtbl_flag, /* flags */
-       0,      /* size */
+       8,      /* size of pmc_body (sizeof(UnionVal) for now) */
         NULL,   /* does_str */
         NULL,   /* isa_str */
         NULL,   /* class */

Modified: branches/gmc/src/gc_gmc.c
==============================================================================
--- branches/gmc/src/gc_gmc.c   (original)
+++ branches/gmc/src/gc_gmc.c   Fri Aug 12 18:50:35 2005
@@ -8,6 +8,7 @@ static void *gc_gmc_get_free_typed_objec
 static void *gc_gmc_get_free_object(Interp*, struct Small_Object_Pool*);
 static void gc_gmc_alloc_objects(Interp*, struct Small_Object_Pool*);
 static void gc_gmc_more_objects(Interp*, struct Small_Object_Pool*);
+static void gc_gmc_more_pmc_bodies(Interp *, struct Small_Object_Pool*);
 
 
 /* Determines the size of a PMC according to its base_type. */
@@ -21,15 +22,6 @@ gc_gmc_get_PMC_size(Interp *interpreter,
 }
 
 
-/* Determines if a PMC is an aggregate or not. */
-static INTVAL
-gc_gmc_is_aggreg_PMC(Interp *interpreter, INTVAL base_type)
-{
-    /* TODO: find it with the base_type. */
-    return 0;
-}
-
-
 /* Allocates and initializes a generation, but does not plug it to the pool 
yet. */
 static Gc_gmc_gen *
 gc_gmc_gen_init(Interp *interpreter)
@@ -233,11 +225,11 @@ gc_gmc_alloc_objects(Interp *interpreter
 #endif
 }
 
-void
-gc_gmc_more_objects(Interp *interpreter,
+static void
+gc_gmc_fake_more_objects(Interp *interpreter,
        struct Small_Object_Pool *pool)
 {
-#ifdef GMC_DEBUG
+#ifndef GMC_DEBUG
     fprintf (stderr, "GMC: I want more objects !\n");
 #endif
 }
@@ -252,10 +244,12 @@ static void *
 gc_gmc_get_free_object_of_size(Interp *interpreter,
        struct Small_Object_Pool *pool, size_t size, INTVAL aggreg)
 {
-  void *ptr;
+  void *pmc_body;
+  void *pmc;
   Gc_gmc *gc = pool->gc;
   Gc_gmc_gen *gen;
 
+  /* Allocate the pmc_body */
   gen = (aggreg) ? gc->yng_lst : gc->old_lst;
 
   /* Should we use the next generation ? */
@@ -264,22 +258,43 @@ gc_gmc_get_free_object_of_size(Interp *i
 
   /* Do we need more generations ? */
   if (!gen)
-    (*pool->more_objects) (interpreter, pool);
+    gc_gmc_more_pmc_bodies (interpreter, pool);
 
   gc->old_lst = gen;
 
-  ptr = gen->fst_free;
-  gen->fst_free = (void*)((INTVAL)ptr + size);
+  pmc_body = gen->fst_free;
+  gen->fst_free = (void*)((INTVAL)pmc_body + size);
   gen->remaining -= size;
 
 #ifdef GMC_DEBUG
   fprintf (stderr, "Allocating %s PMC of size %d\n", (aggreg) ? "aggregate" : 
"non-aggregate", size);
 #endif
 
-  return ptr;
+  /* Allocate the PMC* */
+
+  /* if we don't have any objects */
+  if (!pool->free_list)
+      (*pool->more_objects) (interpreter, pool);
+  
+  pmc = pool->free_list;
+  fprintf (stderr, "===============\n");
+  fprintf (stderr, "PMC found at %p\n", pmc);
+  fprintf (stderr, "Next PMC at %p\n", *(void**)pmc);
+  fprintf (stderr, "Next Next PMC at %p\n", **(void***)pmc);
+  fprintf (stderr, "---------------\n");
+  pool->free_list = *(void **)pmc;
+  --pool->num_free_objects;
+  PMC_body((PMC*)pmc) = Gmc_PMC_hdr_get_BODY(pmc_body);
+
+  Gmc_PMC_hdr_get_PMC((Gc_gmc_hdr*)pmc_body) = pmc;
+
+  fprintf (stderr, "Next PMC at %p\n", pool->free_list);
+  fprintf (stderr, "Next Next PMC at %p\n", *(void**)pool->free_list);
+  return pmc;
 }
 
 
+
 /* Here we allocate a PObj, as it is non-typed. */
 /* This function should not be called anywhere if possible. */
 void *
@@ -305,12 +320,39 @@ gc_gmc_get_free_typed_object(Interp *int
 {
     Gc_gmc *gc = pool->gc;
     size_t size = sizeof(Gc_gmc_hdr) + gc_gmc_get_PMC_size(interpreter, 
base_type);
-    INTVAL aggreg = gc_gmc_is_aggreg_PMC(interpreter, base_type);
+    VTABLE *vtable = Parrot_base_vtables[base_type];
+    INTVAL aggreg = vtable->flags & VTABLE_PMC_NEEDS_EXT;
     
     return gc_gmc_get_free_object_of_size (interpreter, pool, size, aggreg);
 }
 
 
+static void
+gc_gmc_more_pmc_bodies (Interp *interpreter,
+       struct Small_Object_Pool *pool)
+{
+}
+
+
+/* Quick and dirty for now, no GC run at all. */
+/* XXX: structures must change, because no free is possible with what's here */
+static void
+gc_gmc_more_objects(Interp *interpreter,
+       struct Small_Object_Pool *pool)
+{
+#define NUM_NEW_OBJ 512
+        void *fst = mem_sys_allocate(NUM_NEW_OBJ * pool->object_size);
+       int i;
+       char *obj;
+       for (i = 0, obj = (char*)fst; i < NUM_NEW_OBJ; i++, obj += 
pool->object_size)
+           *(void**)obj = obj + pool->object_size;
+       *(void**)obj = NULL;
+       pool->free_list = fst;
+       pool->num_free_objects += NUM_NEW_OBJ;
+#ifndef GMC_DEBUG
+       fprintf(stderr, "Allocating %d more objects of size %d beginning at 
%p\n", NUM_NEW_OBJ, pool->object_size, fst);
+#endif
+}
 
 
 #endif /* PARROT_GC_GMC */

Modified: branches/gmc/src/headers.c
==============================================================================
--- branches/gmc/src/headers.c  (original)
+++ branches/gmc/src/headers.c  Fri Aug 12 18:50:35 2005
@@ -58,6 +58,7 @@ get_free_buffer(Interp *interpreter,
     /* don't mess around with flags */
     PObj_bufstart(buffer) = NULL;
     PObj_buflen(buffer) = 0;
+    fprintf (stderr, "Allocated buffer at %p, bufstart at %p, buflen at %p\n", 
buffer, &PObj_bufstart(buffer), &PObj_buflen(buffer));
 
     if (pool->object_size  - GC_HEADER_SIZE > sizeof(PObj))
         memset(buffer + 1, 0,
@@ -415,6 +416,7 @@ new_string_header(Interp *interpreter, U
             interpreter->arena_base->string_header_pool);
     PObj_get_FLAGS(string) |= flags | PObj_is_string_FLAG;
     SET_NULL(string->strstart);
+    fprintf (stderr, "Allocated new string header at %p, strstart at %p\n", 
string, &string->strstart);
     return string;
 }
 

Modified: branches/gmc/src/jit_debug.c
==============================================================================
--- branches/gmc/src/jit_debug.c        (original)
+++ branches/gmc/src/jit_debug.c        Fri Aug 12 18:50:35 2005
@@ -155,8 +155,13 @@ write_types(FILE *stabs)
                 "strstart:(0,15),%d,%d;"        /* fake a char* */
                 ";\""
                 "," N_LSYM ",0,0,0\n", i++, BYTE_SIZE(STRING),
+#if PARROT_GC_GMC
+                BIT_OFFSET(STRING, body->_b._bufstart), BIT_SIZE(void*),
+                BIT_OFFSET(STRING, body->_b._buflen), BIT_SIZE(size_t),
+#else
                 BIT_OFFSET(STRING, obj.u._b._bufstart), BIT_SIZE(void*),
                 BIT_OFFSET(STRING, obj.u._b._buflen), BIT_SIZE(size_t),
+#endif
                 BIT_OFFSET(STRING, obj.flags), BIT_SIZE(UINTVAL),
                 BIT_OFFSET(STRING, bufused), BIT_SIZE(UINTVAL),
                 BIT_OFFSET(STRING, strstart), BIT_SIZE(void*)

Modified: branches/gmc/src/smallobject.c
==============================================================================
--- branches/gmc/src/smallobject.c      (original)
+++ branches/gmc/src/smallobject.c      Fri Aug 12 18:50:35 2005
@@ -463,10 +463,20 @@ new_small_object_pool(Interp *interprete
 void
 gc_pmc_ext_pool_init(Interp *interpreter, struct Small_Object_Pool *pool)
 {
+#if PARROT_GC_GMC
+    /* PMC_ext are scheduled for removal anyway, so use these functions
+     * in the meantime. */
+    struct Small_Object_Pool *pmc_pool = interpreter->arena_base->pmc_pool;
+    pool->add_free_object = pmc_pool->add_free_object;
+    pool->get_free_object = pmc_pool->get_free_object;
+    pool->alloc_objects   = pmc_pool->alloc_objects;
+    pool->more_objects    = pmc_pool->more_objects;
+#else
     pool->add_free_object = gc_ms_add_free_object;
     pool->get_free_object = gc_ms_get_free_object;
     pool->alloc_objects   = gc_ms_alloc_objects;
     pool->more_objects    = gc_ms_alloc_objects;
+#endif
 }
 
 static void

Reply via email to