Changeset 76af36f


Ignore:
Timestamp:
Sep 13, 2016, 4:21:26 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
4c1403c
Parents:
4ed70597
Message:

many small fixes in garbage collector, mostly RAII related

Location:
src/examples/gc_no_raii
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • src/examples/gc_no_raii/src/gcpointers.c

    r4ed70597 r76af36f  
    2525                check(obj);
    2626                check(is_valid(obj));
    27                 check(gc_is_managed(this) == gc_is_managed(obj->root_chain) || !obj->root_chain);
     27                check(!obj->root_chain || this->ptr == obj->root_chain->ptr);
     28                check(!obj->root_chain || gc_is_managed(this) == gc_is_managed(obj->root_chain));
    2829                this->next = obj->root_chain;
    2930                obj->root_chain = this;
     
    6970}
    7071
    71 gcpointer_t* gcpointer_assign(gcpointer_t* this, gcpointer_t* rhs)
     72gcpointer_t ?=?(gcpointer_t* this, gcpointer_t rhs)
    7273{
    73         if(this != rhs)
    74         {
    75                 unregister_ptr(this);
     74        unregister_ptr(this);
     75        this->ptr = rhs.ptr;
     76        register_ptr(this);
    7677
    77                 this->ptr = rhs->ptr;
    78 
    79                 register_ptr(this);
    80         }
    81 
    82         return this;
     78        return *this;
    8379}
    8480
     
    107103}
    108104
    109 forall(otype T) void ?{}(gcpointer(T)* this, gcpointer(T)* other) {
    110         (&this->internal) { other->internal };
     105forall(otype T) void ?{}(gcpointer(T)* this, gcpointer(T) other) {
     106        (&this->internal) { other.internal };
    111107}
    112108
     
    115111}
    116112
    117 // forall(otype T) gcpointer(T) ?=?(gcpointer(T) this, gcpointer(T) rhs);
     113forall(otype T) gcpointer(T) ?=?(gcpointer(T)* this, gcpointer(T) rhs) {
     114        this->internal = rhs.internal;
     115        return *this;
     116}
    118117//
    119118// forall(otype T) T *?(gcpointer(T) this);
  • src/examples/gc_no_raii/src/gcpointers.h

    r4ed70597 r76af36f  
    3333forall(otype T) void ?{}(gcpointer(T)* this);
    3434forall(otype T) void ?{}(gcpointer(T)* this, void* address);
    35 forall(otype T) void ?{}(gcpointer(T)* this, gcpointer(T)* other);
     35forall(otype T) void ?{}(gcpointer(T)* this, gcpointer(T) other);
    3636forall(otype T) void ^?{}(gcpointer(T)* this);
    3737forall(otype T) gcpointer(T) ?=?(gcpointer(T)* this, gcpointer(T) rhs);
  • src/examples/gc_no_raii/src/internal/card_table.h

    r4ed70597 r76af36f  
    77{
    88        size_t card = ( ((intptr_t)address) & CARDS_OFFSET_MASK ) >> CARDS_SIZE_EXP;
     9        checkf(card < CARDS_COUNT, (const char*)"%lu %lu = (%lx & %lx) >> %lu\n", (size_t)CARDS_COUNT, (size_t)card, (size_t)address, (size_t)CARDS_OFFSET_MASK, (size_t)CARDS_SIZE_EXP);
    910        check(card < CARDS_COUNT);
    1011        return card;
  • src/examples/gc_no_raii/src/internal/collector.h

    r4ed70597 r76af36f  
    11#pragma once
    22
    3 #include <stdlib>
     3#include <stdlib.h>
    44
    55#include "tools.h"
  • src/examples/gc_no_raii/src/internal/memory_pool.c

    r4ed70597 r76af36f  
    8787        intptr_t member_add = (intptr_t)member;
    8888        intptr_t start_obj;
    89         intptr_t start_obj_add;
    9089
    9190        do
     
    9594                check(card != 0 || start_obj);
    9695                card--;
    97                 start_obj_add = (intptr_t)start_obj;
    9896        }
    99         while(start_obj_add > member_add || start_obj_add != 0);
     97        while(start_obj > member_add || !(start_obj));
    10098
    10199        check( start_obj );
  • src/examples/gc_no_raii/src/internal/object_header.c

    r4ed70597 r76af36f  
    9090                while(root)
    9191                {
    92                         check(gc_get_object_ptr( (void*)root->ptr ) == this);
     92                        checkf(gc_get_object_ptr( (void*)root->ptr ) == this, (const char*)"Expected %lX got %lX\n", gc_get_object_ptr( (void*)root->ptr ), this);
    9393
    9494                        root = root->next;
     
    106106                return true;
    107107        }
     108        #else
     109        #error blarg
    108110#endif
  • src/examples/gc_no_raii/src/internal/object_header.h

    r4ed70597 r76af36f  
    4949
    5050#ifndef NDEBUG
    51         bool is_valid( struct gc_object_header* obj );
     51        bool is_valid(const gc_object_header* const this);
    5252#endif
  • src/examples/gc_no_raii/src/internal/state.c

    r4ed70597 r76af36f  
    7676gc_object_header* gc_get_object_for_ref(gc_state* state, void* member)
    7777{
     78        volatile int stage = 0;
    7879        intptr_t target = ((intptr_t)member);
    7980        if(!gc_is_in_heap(state, member)) return NULL;
     81        stage++;
    8082
    8183        gc_memory_pool* pool = gc_pool_of(member);
     84        stage++;
    8285        gc_pool_object_iterator it = gc_pool_iterator_for(pool, member);
     86        stage++;
    8387        gc_pool_object_iterator end = end(pool);
     88        stage++;
    8489
    8590        while(it != end)
    8691        {
    8792                gc_object_header* object = *it;
     93                check(object);
     94                check( is_valid(object) );
    8895                {
    8996                        intptr_t start = ((intptr_t)object);
     
    94101                        }
    95102                }
     103                stage++;
    96104                ++it;
    97105        }
     
    273281                        }
    274282
    275                         check(size + gc_pool_size_used(pool) == gc_pool_size_total(pool));
     283                        checkf(size + gc_pool_size_left(pool) == gc_pool_size_total(pool),
     284                                (const char*)"expected %lu + %lu == %lu\n",
     285                                (size_t)size,
     286                                (size_t)gc_pool_size_left(pool),
     287                                (size_t)gc_pool_size_total(pool));
    276288
    277289                        pool = pool->next;
  • src/examples/gc_no_raii/test/badlll.c

    r4ed70597 r76af36f  
    1111typedef gcpointer(List_t) LLL;
    1212
    13 #define MAX (1024 * 1024)
     13#define MAX (1024 * 1)
    1414
    1515LLL buildLLL(int sz)
    1616{
    1717        int i = 0;
    18         LLL ll0, lll, llc;
     18        LLL ll0;
    1919
    2020        gcmalloc( &ll0 );
    2121        List_t* ll0_ptr = get( &ll0 );
    2222        ll0_ptr->val = i;
    23         lll = ll0;
     23        LLL lll = ll0;
    2424
    2525        for (i = 1; i < sz; i++)
    2626        {
     27                LLL llc;
    2728                gcmalloc( &llc );
    2829                List_t* llc_ptr = get( &llc );
Note: See TracChangeset for help on using the changeset viewer.