Ignore:
Timestamp:
Apr 21, 2016, 4:54:33 PM (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:
8a74081
Parents:
8c8b614
Message:

1 error left

Location:
src/examples/gc_no_raii/src/internal
Files:
2 added
8 edited

Legend:

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

    r8c8b614 r16cfd8c  
    11#include "collector.h"
    22
    3 #include <stdbool.h>
    4 #include <stdint.h>
    5 #include <stdlib.h>
     3#ifdef __cforall
     4extern "C" {
     5#endif
    66#include <string.h>
    7 
    8 #include <fstream>
     7#ifdef __cforall
     8}
     9#endif
    910
    1011#include "state.h"
     
    138139
    139140                intptr_t* ref = &field->ptr;
    140                 // push_back(worklist, ref);
     141                push_back(worklist, ref);
    141142
    142143                field = field->next;
  • src/examples/gc_no_raii/src/internal/collector.h

    r8c8b614 r16cfd8c  
    11#pragma once
    22
    3 #include <stddef.h>
    4 #include <stdint.h>
     3#include <stdlib>
    54
    65#include "tools.h"
     
    1413#include "tools/worklist.h"
    1514
    16 inline bool gc_is_managed(void* address)
     15static inline bool gc_is_managed(void* address)
    1716{
    1817        return gc_is_in_heap(gc_get_state(), address);
    1918}
    2019
    21 inline gc_object_header* gc_get_object_ptr(void* ptr)
     20static inline gc_object_header* gc_get_object_ptr(void* ptr)
    2221{
    2322        void* clean = gc_get_aligned_ptr(ptr);
     
    2524}
    2625
    27 inline struct gc_memory_pool* gc_pool_of(void* address)
     26static inline struct gc_memory_pool* gc_pool_of(void* address)
    2827{
    2928        return (struct gc_memory_pool*)(((intptr_t)address) & POOL_PTR_MASK);
    3029}
    3130
    32 inline void gc_conditional_collect()
     31static inline void gc_conditional_collect()
    3332{
    3433        if(gc_needs_collect(gc_get_state()))
  • src/examples/gc_no_raii/src/internal/gc_tools.h

    r8c8b614 r16cfd8c  
    77#include "globals.h"
    88
    9 inline bool gc_is_aligned(void* address)
     9static inline bool gc_is_aligned(void* address)
    1010{
    1111        return (((intptr_t)address) & (~OBJECT_PTR_MASK)) == 0;
    1212}
    1313
    14 inline void* gc_get_aligned_ptr(void* address)
     14static inline void* gc_get_aligned_ptr(void* address)
    1515{
    1616        return (void*)(((intptr_t)address) & (OBJECT_PTR_MASK));
    1717}
    1818
    19 inline void* gc_write_aligned_ptr(void** reference, void* address)
     19static inline void* gc_write_aligned_ptr(void** reference, void* address)
    2020{
    2121        size_t ref_last_bits = ((intptr_t)*reference) & (~OBJECT_PTR_MASK);
     
    2828}
    2929
    30 inline size_t gc_compute_size(size_t size)
     30static inline size_t gc_compute_size(size_t size)
    3131{
    3232        size_t word_size = ((size - 1) / OBJECT_ALLIGNMENT) + 1;
  • src/examples/gc_no_raii/src/internal/memory_pool.h

    r8c8b614 r16cfd8c  
    11#pragma once
    22
     3extern "C" {
     4#include <stdbool.h>
    35#include <stdint.h>
     6}
    47
    58#include "tools.h"
    69
    7 // #include "card_table.h"
    8 #include "collector.h"
     10#include "card_table.h"
    911#include "globals.h"
    10 
    11 typedef int cardtable_ptr_t;
     12#include "state.h"
    1213
    1314struct gc_memory_pool
     
    1819        uint8_t type_code;
    1920
    20         cardtable_ptr_t cards;
     21        card_table_t* cards;
    2122
    2223        uint8_t* end_p;
     
    2526};
    2627
    27 void gc_memory_pool_ctor(gc_memory_pool *const this,
    28         size_t size,
    29         gc_memory_pool* next,
    30         gc_memory_pool* mirror,
    31      uint8_t type
     28void ctor(      gc_memory_pool *const this,
     29                size_t size,
     30                gc_memory_pool* next,
     31                gc_memory_pool* mirror,
     32                uint8_t type
    3233        );
     34
     35void dtor(gc_memory_pool *const this);
    3336
    3437struct gc_pool_object_iterator
    3538{
    36 
    3739        struct gc_object_header* object;
    3840        #if _DEBUG
     
    4345
    4446
    45 void gc_pool_object_iterator_ctor(
     47void ctor(
     48                gc_pool_object_iterator* const this,
    4649                struct gc_object_header* start_object
    4750                #if _DEBUG
     
    5356bool ?!=?(const gc_pool_object_iterator lhs, const gc_pool_object_iterator rhs);
    5457
    55 gc_pool_object_iterator begin(gc_memory_pool* const);
     58gc_pool_object_iterator begin(gc_memory_pool* const this);
    5659gc_pool_object_iterator end(gc_memory_pool* const);
    5760
     
    6164struct gc_object_header* *?(gc_pool_object_iterator it);
    6265
    63 inline bool gc_pool_is_from_space(const gc_memory_pool* pool)
     66static inline bool gc_pool_is_from_space(const gc_memory_pool* pool)
    6467{
    6568        return gc_from_space_code(gc_get_state()) == pool->type_code;
    6669}
    6770
    68 void gc_reset_pool(gc_memory_pool* pool);
     71void gc_reset_pool(gc_memory_pool* const pool);
    6972
    70 inline size_t gc_pool_size_used(const gc_memory_pool* pool)
     73static inline size_t gc_pool_size_used(const gc_memory_pool* pool)
    7174{
    7275        return pool->free_p - pool->start_p;
    7376}
    7477
    75 inline size_t gc_pool_size_total(const gc_memory_pool* pool)
     78static inline size_t gc_pool_size_total(const gc_memory_pool* pool)
    7679{
    7780        return pool->end_p - pool->start_p;
    7881}
    7982
    80 inline size_t gc_pool_size_left(const gc_memory_pool* pool)
     83static inline size_t gc_pool_size_left(const gc_memory_pool* pool)
    8184{
    8285        return pool->end_p - pool->free_p;
    8386}
    8487
    85 void* gc_pool_allocate(gc_memory_pool* pool, size_t size, bool zero);
     88void* gc_pool_allocate(gc_memory_pool* const pool, size_t size, bool zero);
    8689
    87 gc_pool_object_iterator gc_pool_iterator_for(gc_memory_pool* pool, void* member);
    88 
    89 gc_pool_object_iterator gc_pool_end(gc_memory_pool* pool);
     90gc_pool_object_iterator gc_pool_iterator_for(gc_memory_pool* const pool, void* member);
  • src/examples/gc_no_raii/src/internal/object_header.c

    r8c8b614 r16cfd8c  
    66#include "gcpointers.h"
    77
    8 placement_copy_ctor(void* address, const gc_object_header* const other)
     8void ctor(gc_object_header* const this, size_t inSize)
    99{
    10         gc_object_header* const this = (gc_object_header*)address;
    1110        #if _DEBUG
    1211                this->canary_start = CANARY_VALUE;
    1312        #endif
     13
     14        this->size = inSize;
     15        this->root_chain = NULL;
     16        this->type_chain = NULL;
     17        this->forward = NULL;
     18        this->is_forwarded = false;
     19
     20        #if _DEBUG
     21                this->canary_end = CANARY_VALUE;
     22        #endif
     23}
     24
     25void copy_ctor(gc_object_header* const this, const gc_object_header* const other)
     26{
     27        #if _DEBUG
     28                this->canary_start = CANARY_VALUE;
     29        #endif
     30
    1431        this->size = other->size;
    1532        this->root_chain = other->root_chain;
     
    1734        this->forward = NULL;
    1835        this->is_forwarded = false;
     36
    1937        #if _DEBUG
    2038                this->canary_end = CANARY_VALUE;
    2139        #endif
     40
     41        gcpointer_t* root = this->root_chain;
     42        while(root)
    2243        {
    23                 gcpointer_t* root = this->root_chain;
    24                 while(root)
    25                 {
    26                         check(get_object_ptr(root->ptr) == other);
    27                         intptr_t int_this = (intptr_t)this;
    28                         intptr_t int_next = int_this + sizeof(gc_object_header);
    29                         intptr_t* root_ptr = root->ptr;
    30                         *root_ptr = int_next;
     44                check(get_object_ptr(root->ptr) == other);
     45                root->ptr = ((intptr_t)this) + sizeof(gc_object_header);
    3146
    32                         check(get_object_ptr(root->ptr) == this);
    33                         root = root->next;
    34                 }
     47                check(get_object_ptr(root->ptr) == this);
     48                root = root->next;
     49        }
    3550
    36                 gcpointer_t* type = other->type_chain;
     51        gcpointer_t* type = other->type_chain;
    3752
    38                 while(type)
    39                 {
    40                         check((intptr_t)type < (intptr_t)((intptr_t)other + other->size));
     53        while(type)
     54        {
     55                check((intptr_t)type < (intptr_t)((intptr_t)other + other->size));
    4156
    42                         size_t offset = (intptr_t)type - (intptr_t)other;
    43                         check(offset < size);
     57                size_t offset = (intptr_t)type - (intptr_t)other;
     58                check(offset < size);
    4459
    45                         gcpointer_t* member_ptr = (gcpointer_t*)( (intptr_t)this + offset );
     60                gcpointer_t* member_ptr = (gcpointer_t*)( (intptr_t)this + offset );
    4661
    47                         if(!this->type_chain) this->type_chain = member_ptr;
     62                if(!this->type_chain) this->type_chain = member_ptr;
    4863
    49                         size_t next_offset = type->next ? (intptr_t)type->next - (intptr_t)other : 0;
    50                         check(next_offset < size);
     64                size_t next_offset = type->next ? (intptr_t)type->next - (intptr_t)other : 0;
     65                check(next_offset < size);
    5166
    52                         gcpointer_t* next_ptr = type->next ? (gcpointer_t*)((intptr_t)this + next_offset) : NULL;
     67                gcpointer_t* next_ptr = type->next ? (gcpointer_t*)((intptr_t)this + next_offset) : NULL;
    5368
    54                         member_ptr->ptr = type->ptr;
    55                         member_ptr->next = next_ptr;
     69                member_ptr->ptr = type->ptr;
     70                member_ptr->next = next_ptr;
    5671
    57                         type = type->next;
    58                 }
     72                type = type->next;
     73        }
    5974
    60                 check(is_valide(this));
    61         }
     75        check(is_valide(this));
    6276}
    6377
  • src/examples/gc_no_raii/src/internal/object_header.h

    r8c8b614 r16cfd8c  
    3030};
    3131
    32 gc_object_header* placement_ctor(void* address, size_t size);
    33 gc_object_header* placement_copy_ctor(void* address, const gc_object_header* const other);
     32void ctor(gc_object_header* const this, size_t size);
     33void copy_ctor(gc_object_header* const this, const gc_object_header* const other);
     34
     35static inline gc_object_header* placement_ctor(void* address, size_t size)
     36{
     37        gc_object_header* const this = (gc_object_header* const) address;
     38        ctor(this, size);
     39        return this;
     40}
     41
     42static inline gc_object_header* placement_copy_ctor(void* address, const gc_object_header* const other)
     43{
     44        gc_object_header* const this = (gc_object_header* const) address;
     45        copy_ctor(this, other);
     46        return this;
     47}
  • src/examples/gc_no_raii/src/internal/state.c

    r8c8b614 r16cfd8c  
    1212#include "globals.h"
    1313#include "memory_pool.h"
    14 // #include "memory_pool_iterator.h"
    1514#include "object_header.h"
    1615
     
    4645}
    4746
    48 bool gc_state_is_in_heap(const gc_state* const this, void* address)
     47void dtor(gc_state *const this)
     48{
     49        dtor(&this->pools_table);
     50        this->is_initialized = false;
     51}
     52
     53bool gc_is_in_heap(const gc_state* const this, const void* const address)
    4954{
    5055        gc_memory_pool* target_pool = gc_pool_of(address);
     
    5661}
    5762
    58 bool gc_state_is_in_to_space(const gc_state* const this, void* address)
     63bool gc_is_in_to_space(const gc_state* const this, const void* const address)
    5964{
    6065        gc_memory_pool* target_pool = gc_pool_of(address);
     
    7378        gc_memory_pool* pool = gc_pool_of(member);
    7479        gc_pool_object_iterator it = gc_pool_iterator_for(pool, member);
    75         gc_pool_object_iterator end = gc_pool_end(pool);
     80        gc_pool_object_iterator end = end(pool);
    7681
    7782        while(it != end)
     
    9499}
    95100
    96 void* gc_try_allocate(gc_state *const this, size_t size)
     101void* gc_try_allocate(gc_state* const this, size_t size)
    97102{
    98103        gc_memory_pool* pool = this->from_space;
     
    109114}
    110115
    111 void gc_state_allocate_pool(gc_state *const this)
     116void gc_allocate_pool(gc_state *const this)
    112117{
    113118        gc_memory_pool* old_from_space = this->from_space;
     
    117122      this->to_space = (gc_memory_pool*)(pal_allocPool(POOL_SIZE_BYTES, 1));
    118123
    119       gc_memory_pool_ctor(this->from_space, POOL_SIZE_BYTES, old_from_space, this->to_space,   this->from_code);
    120       gc_memory_pool_ctor(this->to_space,   POOL_SIZE_BYTES, old_to_space,   this->from_space, (~this->from_code) & 0x01);
     124      ctor(this->from_space, POOL_SIZE_BYTES, old_from_space, this->to_space,   this->from_code);
     125      ctor(this->to_space,   POOL_SIZE_BYTES, old_to_space,   this->from_space, (~this->from_code) & 0x01);
    121126
    122127        this->total_space += gc_pool_size_used(this->from_space);
     
    126131}
    127132
    128 void gc_state_collect(gc_state* const this)
     133void gc_collect(gc_state* const this)
    129134{
    130135        // DEBUG("collecting");
     
    149154        gc_state_calc_usage(this);
    150155
    151         if(gc_needs_collect(this)) gc_state_allocate_pool(this);
     156        if(gc_needs_collect(this)) gc_allocate_pool(this);
    152157
    153158        // DEBUG("done");
     
    281286                        while(potential_ref < (void**)pool->m_free)
    282287                        {
    283                                 check(!gc_is_in_heap(*potential_ref));
     288                                check(!gc_is_in_heap(this, *potential_ref));
    284289                                potential_ref++;
    285290                        }
  • src/examples/gc_no_raii/src/internal/state.h

    r8c8b614 r16cfd8c  
    77#include "vector.h"
    88
    9 typedef vector(struct gc_memory_pool*, heap_allocator(struct gc_memory_pool*)) pools_table_t;
     9// typedef 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};
    2424
    25 void ctor(struct gc_state* state);
     25void ctor(gc_state* const state);
     26
     27void dtor(gc_state* const state);
    2628
    2729gc_state* gc_get_state();
    2830
    29 inline bool gc_needs_collect(gc_state* state)
     31static inline bool gc_needs_collect(gc_state* state)
    3032{
    3133        return state->used_space * 2 > state->total_space;
    3234}
    3335
    34 void gc_collect(gc_state* state);
     36void gc_collect(gc_state* const this);
    3537
    36 void* gc_try_allocate(gc_state* state, size_t size);
     38void* gc_try_allocate(gc_state* const this, size_t size);
    3739
    38 void gc_allocate_pool(gc_state* state);
     40void gc_allocate_pool(gc_state* const state);
    3941
    40 bool gc_is_in_heap(const gc_state* state, void* address);
     42bool gc_is_in_heap(const gc_state* const state, const void* const address);
    4143
    42 bool gc_is_in_to_space(const gc_state* state, void* address);
     44bool gc_is_in_to_space(const gc_state* const state, const void* const address);
    4345
    44 inline uint8_t gc_from_space_code(const gc_state *const this)
     46static inline uint8_t gc_from_space_code(const gc_state *const this)
    4547{
    4648        return this->from_code;
     
    4951struct gc_object_header* gc_get_object_for_ref(gc_state* state, void*);
    5052
    51 inline void gc_register_allocation(gc_state* state, size_t size)
     53static inline void gc_register_allocation(gc_state* state, size_t size)
    5254{
    5355        state->used_space += size;
Note: See TracChangeset for help on using the changeset viewer.