Changeset d67a9a1 for src/examples/gc_no_raii/src/internal
- Timestamp:
- Jan 20, 2016, 1:53:17 PM (9 years ago)
- 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:
- 00ede9e
- Parents:
- 08a40fd
- Location:
- src/examples/gc_no_raii/src/internal
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/examples/gc_no_raii/src/internal/collector.c
r08a40fd rd67a9a1 1 1 #include "collector.h" 2 2 3 #include <stdbool.h> 3 4 #include <stdint.h> 4 5 #include <stdlib.h> … … 7 8 #include "fstream.h" 8 9 9 #include "gc_tools.h" 10 #include "state.h" 11 // #include "memory_pool.h" 10 #include "memory_pool.h" 12 11 13 12 void* gc_finish_alloc_block(void* block, size_t actual_size, size_t target_size); … … 69 68 gc_object_header* obj = gc_object_header_placement_ctor(header, actual_size); 70 69 71 (void)obj; //remove unsused warning since this is for debug70 // (void)obj; //remove unsused warning since this is for debug 72 71 check(obj == get_object_ptr(data)); 73 72 … … 77 76 } 78 77 79 // void process_reference(void** ref, std::vector<void**>&worklist)80 //{81 // check(!gc::gc_get_state().is_in_heap(ref));82 // 83 // if(gc_object_header* ptr = get_object_ptr(*ref)) 84 // { 85 // if(!ptr->is_forwarded) 86 // { 87 // copy_object(ptr); 88 // 89 // scan_object(ptr->forward, worklist); 90 // 91 // assign_reference(ref, ptr->forward); 92 // } 93 // else 94 // { 95 // //duplication to help debug 96 // assign_reference(ref, ptr->forward); 97 // } 98 //}99 //}100 // 101 // void assign_reference(void** ref, gc_object_header* ptr) 102 // { 103 // void* address = (void*)(((intptr_t)ptr) + sizeof(gc_object_header)); 104 // 105 // write_aligned_ptr(ref, address); 106 // } 107 // 108 // gc_object_header* copy_object(gc_object_header* ptr) 109 // { 110 // check(!ptr->forward); 111 // check(!ptr->is_forwarded);112 // check(pool_of(ptr)->is_from_space());113 // 114 // memory_pool* pool = pool_of(ptr)->mirror(); 115 // 116 // void* new_block = pool->allocate(ptr->size, false); 117 // 118 // std::memcpy(new_block, ptr, ptr->size); 119 // 120 // gc_object_header* fwd_ptr = new (new_block) gc_object_header(ptr); 121 // 122 // ptr->forward = fwd_ptr; 123 // ptr->is_forwarded = true;124 // 125 // return fwd_ptr; 126 // } 127 // 128 // void scan_object(gc_object_header* object, std::vector<void**>& worklist) 129 // { 130 // gcpointer_base* type = object->type_chain; 131 // while(type) 132 // { 133 // check(((intptr_t)type) > ((intptr_t)object)); 134 // check(((intptr_t)type) < ((intptr_t)((intptr_t)object) + object->size));135 // 136 // check(gc::gc_get_state().is_in_to_space(&type->m_ptr)); 137 // 138 // worklist.push_back(&type->m_ptr); 139 // 140 // type = type->m_next; 141 // } 142 //}143 // }; 78 void gc_process_reference(void** ref, worklist_t* worklist) 79 { 80 check(!gc_is_in_heap(gc_get_state(), ref)); 81 82 gc_object_header* ptr = gc_get_object_ptr(*ref); 83 if(ptr) 84 { 85 if(!ptr->is_forwarded) 86 { 87 gc_copy_object(ptr); 88 89 gc_scan_object(ptr->forward, worklist); 90 91 gc_assign_reference(ref, ptr->forward); 92 } 93 else 94 { 95 //duplication to help debug 96 gc_assign_reference(ref, ptr->forward); 97 } 98 } 99 } 100 101 void gc_assign_reference(void** ref, gc_object_header* ptr) 102 { 103 void* address = (void*)(((intptr_t)ptr) + sizeof(gc_object_header)); 104 105 gc_write_aligned_ptr(ref, address); 106 } 107 108 gc_object_header* gc_copy_object(gc_object_header* ptr) 109 { 110 check(!ptr->forward); 111 check(!ptr->is_forwarded); 112 check(gc_is_from_space(gc_pool_of(ptr))); 113 114 gc_memory_pool* pool = gc_pool_of(ptr)->mirror; 115 116 void* new_block = gc_pool_allocate(pool, ptr->size, true); 117 118 memcpy(new_block, ptr, ptr->size); 119 120 gc_object_header* fwd_ptr = gc_object_header_placement_copy_ctor(new_block, ptr); 121 122 ptr->forward = fwd_ptr; 123 ptr->is_forwarded = true; 124 125 return fwd_ptr; 126 } 127 128 void gc_scan_object(gc_object_header* object, worklist_t* worklist) 129 { 130 gcpointer_t* field = object->type_chain; 131 while(field) 132 { 133 check(((intptr_t)field) > ((intptr_t)object)); 134 check(((intptr_t)field) < ((intptr_t)((intptr_t)object) + object->size)); 135 136 check(gc_is_in_to_space(gc_get_state(), &type->ptr)); 137 138 push_back(worklist, &field->ptr); 139 140 field = field->next; 141 } 142 } -
src/examples/gc_no_raii/src/internal/collector.h
r08a40fd rd67a9a1 12 12 #include "internal/object_header.h" 13 13 #include "internal/state.h" 14 15 typedef int worklist_t; 14 #include "tools/worklist.h" 16 15 17 16 inline bool gc_is_managed(void* address) … … 26 25 } 27 26 28 inline gc_memory_pool* pool_of(void* address)27 inline gc_memory_pool* gc_pool_of(void* address) 29 28 { 30 29 return (struct gc_memory_pool*)(((intptr_t)address) & POOL_PTR_MASK); -
src/examples/gc_no_raii/src/internal/object_header.h
r08a40fd rd67a9a1 31 31 32 32 gc_object_header* gc_object_header_placement_ctor(void* address, size_t size); 33 gc_object_header* gc_object_header_placement_copy_ctor(void* address, gc_object_header* other); -
src/examples/gc_no_raii/src/internal/state.c
r08a40fd rd67a9a1 1 1 #include "state.h" 2 3 #include <stdlib.h> 2 4 3 5 //general purpouse includes … … 9 11 //gc internal includes 10 12 // #include "globals.h" 11 //#include "memory_pool.h"13 #include "memory_pool.h" 12 14 // #include "memory_pool_iterator.h" 13 15 // #include "object_header.h" … … 22 24 // bool no_from_space_ref(gc_state* state); 23 25 // #endif 24 // 25 // void gc_state_ctor(gc_state* state) 26 // { 27 // state->from_code(0) 28 // state->to_space(nullptr) 29 // state->from_space(nullptr) 30 // state->total_space(0) 31 // state->used_space(0) 32 // state->pools_table() 33 // 34 // gc_allocate_pool(gc_state* state); 35 // } 36 // 26 27 void gc_state_ctor(gc_state* state) 28 { 29 state->from_code = 0; 30 state->to_space = NULL; 31 state->from_space = NULL; 32 state->total_space = 0; 33 state->used_space = 0; 34 // state->pools_table(); 35 36 gc_allocate_pool(state); 37 38 state->is_initialized = true; 39 } 40 37 41 // bool state::is_in_heap(void* address) const 38 42 // { 39 // memory_pool* target_pool = pool_of(address);43 // memory_pool* target_pool = gc_pool_of(address); 40 44 // 41 45 // auto first = pools_table.cbegin(); … … 44 48 // return result != last && (*result)->is_from_space(); 45 49 // } 46 // 50 47 51 // bool state::is_in_to_space(void* address) const 48 52 // { … … 55 59 // } 56 60 // 57 // object_header* state::get_object_for_ref(void* member)58 //{59 // intptr_t target = intptr_t(member);60 // if(!is_in_heap(member)) return nullptr;61 // 62 // memory_pool* pool =pool_of(member);63 // auto it = pool->iterator_for(member);64 // auto end = pool->end();65 // 66 //while(it != end)67 //{68 //object_header* object = *it;69 //{70 // intptr_t start = intptr_t(object);71 // intptr_t end = intptr_t(start + object->size);72 //if(start < target && end > target)73 //{74 //return object;75 //}76 //}77 //++it;78 //}79 // 80 //checkf(false, "is_in_heap() and iterator_for() return inconsistent data");81 //abort();82 // return nullptr;83 //}61 gc_object_header* gc_get_object_for_ref(gc_state* state, void* member) 62 { 63 intptr_t target = ((intptr_t)member); 64 if(!gc_is_in_heap(state, member)) return NULL; 65 66 gc_memory_pool* pool = gc_pool_of(member); 67 gc_pool_object_iterator it = gc_pool_iterator_for(pool, member); 68 gc_pool_object_iterator end = gc_pool_end(pool); 69 70 while(it != end) 71 { 72 gc_object_header* object = *it; 73 { 74 intptr_t start = ((intptr_t)object); 75 intptr_t end = ((intptr_t)start + object->size); 76 if(start < target && end > target) 77 { 78 return object; 79 } 80 } 81 ++it; 82 } 83 84 checkf(false, "is_in_heap() and iterator_for() return inconsistent data"); 85 abort(); 86 return NULL; 87 } 84 88 // 85 89 // void* state::try_allocate(size_t size) -
src/examples/gc_no_raii/src/internal/state.h
r08a40fd rd67a9a1 16 16 size_t used_space; 17 17 18 const struct memory_pool* pools_table;19 size_t pools_table_count;18 // const struct memory_pool* pools_table; 19 // size_t pools_table_count; 20 20 }; 21 21
Note: See TracChangeset
for help on using the changeset viewer.