Ignore:
Timestamp:
May 4, 2016, 10:45:18 AM (8 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
eb4f201
Parents:
8a74081
Message:

fixed compilation of garbage collector

Location:
src/examples/gc_no_raii/src/internal
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/examples/gc_no_raii/src/internal/memory_pool.c

    r8a74081 r4ef8fb3  
    33#include <stdlib>
    44
    5 // const size_t gc_pool_header_size = (size_t)(  &(((gc_memory_pool*)NULL)->start_p) );
     5#include "object_header.h"
     6
     7const size_t gc_pool_header_size = (size_t)(  &(((gc_memory_pool*)NULL)->start_p) );
    68
    79void ctor(gc_memory_pool *const this, size_t size, gc_memory_pool* next, gc_memory_pool* mirror, uint8_t type)
     
    1113        this->type_code = type;
    1214
    13         card_table_t* new = malloc();
     15        card_table_t* new = (card_table_t*)malloc(sizeof(card_table_t));
    1416        this->cards = new;
    1517        ctor(this->cards);
     
    1820        this->free_p = this->start_p;
    1921
    20         // check(gc_pool_of(this) == this);
    21         // check(this->cards);
    22         // gc_reset_pool(this);
     22        check(gc_pool_of(this) == this);
     23        check(this->cards);
     24        gc_reset_pool(this);
    2325}
    2426
    25 // void dtor(gc_memory_pool *const this)
    26 // {
    27 //      dtor(this->cards);
    28 //      free(this->cards);
    29 // }
    30 //
    31 // void gc_reset_pool(gc_memory_pool *const this)
    32 // {
    33 //      this->free_p = this->start_p;
    34 //      #if _DEBUG
    35 //              memset(this->start_p, 0xCD, gc_pool_total_size(this));
    36 //      #endif
    37 //
    38 //      check(this->cards);
    39 //      reset(this->cards);
    40 //
    41 //      check(gc_pool_size_left(this) == gc_pool_total_size(this));
    42 // }
    43 //
    44 // void* gc_pool_allocate(gc_memory_pool *const this, size_t size, bool zero)
    45 // {
    46 //      void* ret = this->free_p;
    47 //
    48 //      this->free_p += size;
    49 //
    50 //      if (zero) memset(ret, 0x00, size);
    51 //
    52 //      check(this->cards);
    53 //      register_object(this->cards, ret);
    54 //
    55 //      return ret;
    56 // }
    57 //
    58 // gc_pool_object_iterator gc_pool_iterator_for(gc_memory_pool* const this, void* member)
    59 // {
    60 //      size_t card = card_of(member);
    61 //      intptr_t member_add = (intptr_t)member;
    62 //      void* start_obj;
    63 //      intptr_t start_obj_add;
    64 //
    65 //      do
    66 //      {
    67 //              check(card < CARDS_COUNT);
    68 //              start_obj = object_at(this->cards, card);
    69 //              check(card != 0 || start_obj);
    70 //              card--;
    71 //              start_obj_add = (intptr_t)start_obj;
    72 //      }
    73 //      while(start_obj_add > member_add || start_obj_add != 0);
    74 //
    75 //      check(start_obj);
    76 //
    77 //      gc_pool_object_iterator it;
    78 //      ctor( &it,
    79 //              (gc_object_header*)start_obj
    80 //              #if _DEBUG
    81 //                      , (intptr_t)this->start_p
    82 //                      , (intptr_t)this->free_p
    83 //              #endif
    84 //      );
    85 //      return it;
    86 // }
    87 //
    88 // void ctor(
    89 //              gc_pool_object_iterator* const this,
    90 //              struct gc_object_header* start_object
    91 //              #if _DEBUG
    92 //                      , intptr_t pool_start
    93 //                      , intptr_t pool_end
    94 //              #endif
    95 //      )
    96 // {
    97 //      this->object = start_object;
    98 //      #if _DEBUG
    99 //              this->lower_limit = pool_start;
    100 //              this->upper_limit = pool_end;
    101 //      #endif
    102 //
    103 //      check( ((intptr_t)start_object) >= lower_limit );
    104 //      check( ((intptr_t)start_object) <= upper_limit );
    105 // }
    106 //
    107 // bool ?!=?(const gc_pool_object_iterator lhs, const gc_pool_object_iterator rhs)
    108 // {
    109 //      return lhs.object != rhs.object;
    110 // }
    111 //
    112 // gc_pool_object_iterator begin(gc_memory_pool* const this)
    113 // {
    114 //      gc_pool_object_iterator it;
    115 //      ctor( &it,
    116 //              (gc_object_header*)this->start_p,
    117 //              #if _DEBUG
    118 //                      , (intptr_t)this->start_p
    119 //                      , (intptr_t)this->free_p
    120 //              #endif
    121 //      );
    122 //      return it;
    123 // }
    124 //
    125 // gc_pool_object_iterator end(gc_memory_pool* const this)
    126 // {
    127 //      gc_pool_object_iterator it;
    128 //      ctor( &it,
    129 //              (gc_object_header*)this->free_p,
    130 //              #if _DEBUG
    131 //                      , (intptr_t)this->start_p
    132 //                      , (intptr_t)this->free_p
    133 //              #endif
    134 //      );
    135 //      return it;
    136 // }
    137 //
    138 // gc_pool_object_iterator* ++?(gc_pool_object_iterator* it)
    139 // {
    140 //      intptr_t next_ptr = ((intptr_t)it->object) + it->object->size;
    141 //      check(next_ptr > lower_limit);
    142 //      check(next_ptr <= upper_limit);
    143 //
    144 //      gc_object_header* next_obj = ((gc_object_header*)next_ptr);
    145 //      check(next_ptr == upper_limit || is_valide(next_obj));
    146 //
    147 //      it->object = next_obj;
    148 //      return it;
    149 // }
    150 //
    151 // const struct gc_object_header* *?(const gc_pool_object_iterator it)
    152 // {
    153 //      return it.object;
    154 // }
    155 //
    156 // struct gc_object_header* *?(gc_pool_object_iterator it)
    157 // {
    158 //      return it.object;
    159 // }
     27void dtor(gc_memory_pool *const this)
     28{
     29        dtor(this->cards);
     30        free(this->cards);
     31}
     32
     33void gc_reset_pool(gc_memory_pool *const this)
     34{
     35        this->free_p = this->start_p;
     36        #if _DEBUG
     37                memset(this->start_p, 0xCD, gc_pool_total_size(this));
     38        #endif
     39
     40        check(this->cards);
     41        reset(this->cards);
     42
     43        check(gc_pool_size_left(this) == gc_pool_total_size(this));
     44}
     45
     46void* gc_pool_allocate(gc_memory_pool *const this, size_t size, bool zero)
     47{
     48        void* ret = this->free_p;
     49
     50        this->free_p += size;
     51
     52        if (zero) memset(ret, 0x00, size);
     53
     54        check(this->cards);
     55        register_object(this->cards, ret);
     56
     57        return ret;
     58}
     59
     60void ctor(
     61                gc_pool_object_iterator* const this,
     62                struct gc_object_header* start_object
     63                #if _DEBUG
     64                        , intptr_t pool_start
     65                        , intptr_t pool_end
     66                #endif
     67        )
     68{
     69        this->object = start_object;
     70        #if _DEBUG
     71                this->lower_limit = pool_start;
     72                this->upper_limit = pool_end;
     73        #endif
     74
     75        check( ((intptr_t)start_object) >= lower_limit );
     76        check( ((intptr_t)start_object) <= upper_limit );
     77}
     78
     79gc_pool_object_iterator gc_pool_iterator_for(gc_memory_pool* const this, void* member)
     80{
     81        size_t card = card_of(member);
     82        intptr_t member_add = (intptr_t)member;
     83        void* start_obj;
     84        intptr_t start_obj_add;
     85
     86        do
     87        {
     88                check(card < CARDS_COUNT);
     89                start_obj = object_at(this->cards, card);
     90                check(card != 0 || start_obj);
     91                card--;
     92                start_obj_add = (intptr_t)start_obj;
     93        }
     94        while(start_obj_add > member_add || start_obj_add != 0);
     95
     96        check(start_obj);
     97       
     98        struct gc_object_header* start_obj_typed = (struct gc_object_header*)start_obj;
     99
     100        gc_pool_object_iterator it;
     101        ctor( &it,
     102                start_obj_typed,
     103                #if _DEBUG
     104                        , (intptr_t)this->start_p
     105                        , (intptr_t)this->free_p
     106                #endif
     107        );
     108        return it;
     109}
     110
     111bool ?!=?(const gc_pool_object_iterator lhs, const gc_pool_object_iterator rhs)
     112{
     113        return lhs.object != rhs.object;
     114}
     115
     116gc_pool_object_iterator begin(gc_memory_pool* const this)
     117{
     118        struct gc_object_header* start_obj = (struct gc_object_header*)this->start_p;
     119        gc_pool_object_iterator it;
     120        ctor( &it,
     121                start_obj,
     122                #if _DEBUG
     123                        , (intptr_t)this->start_p
     124                        , (intptr_t)this->free_p
     125                #endif
     126        );
     127        return it;
     128}
     129
     130gc_pool_object_iterator end(gc_memory_pool* const this)
     131{
     132        gc_pool_object_iterator it;
     133        ctor( &it,
     134                (struct gc_object_header*)this->free_p,
     135                #if _DEBUG
     136                        , (intptr_t)this->start_p
     137                        , (intptr_t)this->free_p
     138                #endif
     139        );
     140        return it;
     141}
     142
     143gc_pool_object_iterator* ++?(gc_pool_object_iterator* it)
     144{
     145        struct gc_object_header* object = it->object;
     146        intptr_t next_ptr = ((intptr_t)object) + object->size;
     147        check(next_ptr > lower_limit);
     148        check(next_ptr <= upper_limit);
     149
     150        struct gc_object_header* next_obj = ((struct gc_object_header*)next_ptr);
     151        check(next_ptr == upper_limit || is_valide(next_obj));
     152
     153        it->object = next_obj;
     154        return it;
     155}
     156
     157const struct gc_object_header* *?(const gc_pool_object_iterator it)
     158{
     159        return it.object;
     160}
     161
     162struct gc_object_header* *?(gc_pool_object_iterator it)
     163{
     164        return it.object;
     165}
  • src/examples/gc_no_raii/src/internal/state.c

    r8a74081 r4ef8fb3  
    1010
    1111//gc internal includes
     12#include "collector.h"
    1213#include "globals.h"
    1314#include "memory_pool.h"
    1415#include "object_header.h"
     16#include "tools/worklist.h"
    1517
    1618void gc_state_swap(gc_state *const this);
  • src/examples/gc_no_raii/src/internal/state.h

    r8a74081 r4ef8fb3  
    77#include "vector.h"
    88
    9 // typedef vector(struct gc_memory_pool*, heap_allocator(struct gc_memory_pool*)) pools_table_t;
     9typedef vector(struct gc_memory_pool*, heap_allocator(struct gc_memory_pool*)) pools_table_t;
    1010
    1111struct gc_state
     
    1919        size_t used_space;
    2020
    21         // pools_table_t        pools_table;
     21        pools_table_t   pools_table;
    2222        size_t          pools_table_count;
    2323};
Note: See TracChangeset for help on using the changeset viewer.