Changeset 08a40fd for src/examples/gc_no_raii
- Timestamp:
- Jan 19, 2016, 4:17:14 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:
- d67a9a1
- Parents:
- 6be0cf9
- Location:
- src/examples/gc_no_raii
- Files:
-
- 3 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/examples/gc_no_raii/src/internal/collector.c
r6be0cf9 r08a40fd 2 2 3 3 #include <stdint.h> 4 #include <stdlib.h> 4 5 #include <string.h> 5 6 … … 8 9 #include "gc_tools.h" 9 10 #include "state.h" 10 #include "memory_pool.h"11 // #include "memory_pool.h" 11 12 12 13 void* gc_finish_alloc_block(void* block, size_t actual_size, size_t target_size); … … 18 19 19 20 bool managed = gc_is_managed(target); 20 gc_object_header* obj = gc_get_object_ptr( target->ptr);21 gc_object_header* obj = gc_get_object_ptr((void*)target->ptr); 21 22 22 23 check(gc_is_valide(obj)); … … 37 38 check(size < POOL_SIZE_BYTES); 38 39 39 void* block = nullptr;40 void* block = NULL; 40 41 gc_state* gc = gc_get_state(); 41 42 42 if(( block = gc_try_allocate(gc, size))) return gc_finish_alloc_block(block, size, target_size);43 if((intptr_t)(block = gc_try_allocate(gc, size))) return gc_finish_alloc_block(block, size, target_size); 43 44 44 45 gc_collect(gc); 45 46 46 if(( block = gc_try_allocate(gc, size))) return gc_finish_alloc_block(block, size, target_size);47 if((intptr_t)(block = gc_try_allocate(gc, size))) return gc_finish_alloc_block(block, size, target_size); 47 48 48 49 gc_allocate_pool(gc); 49 50 50 if(( block = gc_try_allocate(gc, size))) return gc_finish_alloc_block(block, size, target_size);51 if((intptr_t)(block = gc_try_allocate(gc, size))) return gc_finish_alloc_block(block, size, target_size); 51 52 52 53 ofstream_stderr() | "ERROR: allocation in new pool failed" | endl; 53 54 abort(); 54 55 55 return nullptr;56 return NULL; 56 57 } 57 58 58 59 void* gc_finish_alloc_block(void* block, size_t actual_size, size_t target_size) 59 60 { 60 void* data = (void*)( intptr_t(block) + sizeof(object_header));61 void* data = (void*)(((intptr_t)block) + sizeof(gc_object_header)); 61 62 void* header = block; 62 63 63 check( intptr_t(data) > intptr_t(block));64 check( intptr_t(data) >= intptr_t(header));64 check(((intptr_t)data) > ((intptr_t)block)); 65 check(((intptr_t)data) >= ((intptr_t)header)); 65 66 check(is_aligned(data)); 66 check( intptr_t(data) + target_size <= intptr_t(block) + actual_size);67 check(((intptr_t)data) + target_size <= ((intptr_t)block) + actual_size); 67 68 68 object_header* obj = gc_object_header_placement_ctor(header, actual_size);69 gc_object_header* obj = gc_object_header_placement_ctor(header, actual_size); 69 70 70 71 (void)obj; //remove unsused warning since this is for debug 71 72 check(obj == get_object_ptr(data)); 72 73 73 gc_register_allocation(g et_state(), actual_size);74 gc_register_allocation(gc_get_state(), actual_size); 74 75 75 76 return data; … … 78 79 // void process_reference(void** ref, std::vector<void**>& worklist) 79 80 // { 80 // check(!gc::g et_state().is_in_heap(ref));81 // check(!gc::gc_get_state().is_in_heap(ref)); 81 82 // 82 // if( object_header* ptr = get_object_ptr(*ref))83 // if(gc_object_header* ptr = get_object_ptr(*ref)) 83 84 // { 84 85 // if(!ptr->is_forwarded) … … 98 99 // } 99 100 // 100 // void assign_reference(void** ref, object_header* ptr)101 // void assign_reference(void** ref, gc_object_header* ptr) 101 102 // { 102 // void* address = (void*)( intptr_t(ptr) + sizeof(object_header));103 // void* address = (void*)(((intptr_t)ptr) + sizeof(gc_object_header)); 103 104 // 104 105 // write_aligned_ptr(ref, address); 105 106 // } 106 107 // 107 // object_header* copy_object(object_header* ptr)108 // gc_object_header* copy_object(gc_object_header* ptr) 108 109 // { 109 110 // check(!ptr->forward); … … 117 118 // std::memcpy(new_block, ptr, ptr->size); 118 119 // 119 // object_header* fwd_ptr = new (new_block)object_header(ptr);120 // gc_object_header* fwd_ptr = new (new_block) gc_object_header(ptr); 120 121 // 121 122 // ptr->forward = fwd_ptr; … … 125 126 // } 126 127 // 127 // void scan_object( object_header* object, std::vector<void**>& worklist)128 // void scan_object(gc_object_header* object, std::vector<void**>& worklist) 128 129 // { 129 130 // gcpointer_base* type = object->type_chain; 130 131 // while(type) 131 132 // { 132 // check( intptr_t(type) > intptr_t(object));133 // check( intptr_t(type) < intptr_t(intptr_t(object) + object->size));133 // check(((intptr_t)type) > ((intptr_t)object)); 134 // check(((intptr_t)type) < ((intptr_t)((intptr_t)object) + object->size)); 134 135 // 135 // check(gc::g et_state().is_in_to_space(&type->m_ptr));136 // check(gc::gc_get_state().is_in_to_space(&type->m_ptr)); 136 137 // 137 138 // worklist.push_back(&type->m_ptr);
Note: See TracChangeset
for help on using the changeset viewer.