| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -346,7 +346,7 @@ vec4f new_and_init ( Context & context, SimNode_CallBase * call, vec4f * ) { | |||
| 346 | 346 | return v_zero(); | |
| 347 | 347 | } | |
| 348 | 348 | auto size = getTypeSize(typeInfo); | |
| 349 | - auto data = context.heap.allocate(size); | ||
| 349 | + auto data = context.heap->allocate(size); | ||
| 350 | 350 | if ( typeInfo->structType && typeInfo->structType->initializer!=-1 ) { | |
| 351 | 351 | auto fn = context.getFunction(typeInfo->structType->initializer); | |
| 352 | 352 | context.callWithCopyOnReturn(fn, nullptr, data, 0); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,8 @@ | |||
| 1 | 1 | // options log=true | |
| 2 | 2 | // options log_infer_passes=true // log_nodes=false | |
| 3 | 3 | ||
| 4 | + options persistent_heap = true | ||
| 5 | + | ||
| 4 | 6 | require UnitTest | |
| 5 | 7 | ||
| 6 | 8 | struct SomethingSmall | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -899,6 +899,9 @@ namespace das | |||
| 899 | 899 | // memory | |
| 900 | 900 | uint32_t stack = 16*1024; // 0 for unique stack | |
| 901 | 901 | bool intern_strings = false; // use string interning lookup for regular string heap | |
| 902 | + bool persistent_heap = false; | ||
| 903 | + uint32_t heap_size_hint = 65536; | ||
| 904 | + uint32_t string_heap_size_hint = 65536; | ||
| 902 | 905 | // rtti | |
| 903 | 906 | bool rtti = false; // create extended RTTI | |
| 904 | 907 | // language | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -272,7 +272,7 @@ namespace das | |||
| 272 | 272 | char ** value = (char **) _value; | |
| 273 | 273 | *value = nullptr; | |
| 274 | 274 | } | |
| 275 | - context.heap.free((char *)this, sizeof(VectorIterator)); | ||
| 275 | + context.heap->free((char *)this, sizeof(VectorIterator)); | ||
| 276 | 276 | } | |
| 277 | 277 | VectorType * array; | |
| 278 | 278 | char * array_end = nullptr; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -290,6 +290,7 @@ namespace das { | |||
| 290 | 290 | LinearChunkAllocator() { } | |
| 291 | 291 | char * allocate ( uint32_t s ); | |
| 292 | 292 | void free ( char * ptr, uint32_t s ); | |
| 293 | + char * reallocate ( char * ptr, uint32_t size, uint32_t nsize ); | ||
| 293 | 294 | virtual void reset (); | |
| 294 | 295 | char * allocateName ( const string & name ); | |
| 295 | 296 | __forceinline bool isOwnPtrQnD ( const char * ptr ) const { | |
@@ -314,7 +315,6 @@ namespace das { | |||
| 314 | 315 | void getStats ( uint32_t & depth, uint64_t & bytes, uint64_t & total ) const; | |
| 315 | 316 | public: | |
| 316 | 317 | function<int(int)> customGrow; | |
| 317 | - protected: | ||
| 318 | 318 | uint32_t initialSize = 65536; | |
| 319 | 319 | uint32_t alignMask = 15; | |
| 320 | 320 | HeapChunk * chunk = nullptr; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1016,14 +1016,14 @@ namespace das { | |||
| 1016 | 1016 | template <typename TT> | |
| 1017 | 1017 | struct das_new { | |
| 1018 | 1018 | static __forceinline TT * make ( Context * __context__ ) { | |
| 1019 | - char * data = __context__->heap.allocate( sizeof(TT) ); | ||
| 1019 | + char * data = __context__->heap->allocate( sizeof(TT) ); | ||
| 1020 | 1020 | if ( !data ) __context__->throw_error("out of heap"); | |
| 1021 | 1021 | memset ( data, 0, sizeof(TT) ); | |
| 1022 | 1022 | return (TT *) data; | |
| 1023 | 1023 | } | |
| 1024 | 1024 | template <typename QQ> | |
| 1025 | 1025 | static __forceinline TT * make_and_init ( Context * __context__, QQ && init ) { | |
| 1026 | - TT * data = (TT *) __context__->heap.allocate( sizeof(TT) ); | ||
| 1026 | + TT * data = (TT *) __context__->heap->allocate( sizeof(TT) ); | ||
| 1027 | 1027 | if ( !data ) __context__->throw_error("out of heap"); | |
| 1028 | 1028 | *data = init(); | |
| 1029 | 1029 | return data; | |
@@ -1115,7 +1115,7 @@ namespace das { | |||
| 1115 | 1115 | template <typename TT> | |
| 1116 | 1116 | struct das_delete_lambda_struct<TT *> { | |
| 1117 | 1117 | static __forceinline void clear ( Context * __context__, TT * ptr ) { | |
| 1118 | - __context__->heap.free(((char *)ptr)-16, sizeof(TT)+16); | ||
| 1118 | + __context__->heap->free(((char *)ptr)-16, sizeof(TT)+16); | ||
| 1119 | 1119 | } | |
| 1120 | 1120 | }; | |
| 1121 | 1121 | ||
@@ -1125,7 +1125,7 @@ namespace das { | |||
| 1125 | 1125 | template <typename TT> | |
| 1126 | 1126 | struct das_delete_ptr<TT *> { | |
| 1127 | 1127 | static __forceinline void clear ( Context * __context__, TT * ptr ) { | |
| 1128 | - __context__->heap.free((char *)ptr, sizeof(TT)); | ||
| 1128 | + __context__->heap->free((char *)ptr, sizeof(TT)); | ||
| 1129 | 1129 | } | |
| 1130 | 1130 | }; | |
| 1131 | 1131 | ||
@@ -1196,7 +1196,7 @@ namespace das { | |||
| 1196 | 1196 | if ( dim.data ) { | |
| 1197 | 1197 | if ( !dim.lock ) { | |
| 1198 | 1198 | uint32_t oldSize = dim.capacity*sizeof(TT); | |
| 1199 | - __context__->heap.free(dim.data, oldSize); | ||
| 1199 | + __context__->heap->free(dim.data, oldSize); | ||
| 1200 | 1200 | } else { | |
| 1201 | 1201 | __context__->throw_error("can't delete locked array"); | |
| 1202 | 1202 | } | |
@@ -1211,7 +1211,7 @@ namespace das { | |||
| 1211 | 1211 | if ( tab.data ) { | |
| 1212 | 1212 | if ( !tab.lock ) { | |
| 1213 | 1213 | uint32_t oldSize = tab.capacity*(sizeof(TKey)+sizeof(TVal)+sizeof(uint32_t)); | |
| 1214 | - __context__->heap.free(tab.data, oldSize); | ||
| 1214 | + __context__->heap->free(tab.data, oldSize); | ||
| 1215 | 1215 | } else { | |
| 1216 | 1216 | __context__->throw_error("can't delete locked table"); | |
| 1217 | 1217 | } | |
@@ -1279,7 +1279,7 @@ namespace das { | |||
| 1279 | 1279 | template <typename TT, typename AT, bool moveIt = false> | |
| 1280 | 1280 | struct das_ascend { | |
| 1281 | 1281 | static __forceinline TT * make(Context * __context__,TypeInfo * typeInfo,const AT & init) { | |
| 1282 | - if ( char * ptr = (char *)__context__->heap.allocate(sizeof(AT)+ (typeInfo ? 16 : 0)) ) { | ||
| 1282 | + if ( char * ptr = (char *)__context__->heap->allocate(sizeof(AT)+ (typeInfo ? 16 : 0)) ) { | ||
| 1283 | 1283 | if ( typeInfo ) { | |
| 1284 | 1284 | *((TypeInfo **)ptr) = typeInfo; | |
| 1285 | 1285 | ptr += 16; | |
@@ -1331,7 +1331,7 @@ namespace das { | |||
| 1331 | 1331 | template <typename AT> | |
| 1332 | 1332 | struct das_ascend<Lambda,AT,false> { | |
| 1333 | 1333 | static __forceinline Lambda make(Context * __context__,TypeInfo * typeInfo,const AT & init) { | |
| 1334 | - if ( char * ptr = (char *)__context__->heap.allocate(sizeof(AT)+ (typeInfo ? 16 : 0)) ) { | ||
| 1334 | + if ( char * ptr = (char *)__context__->heap->allocate(sizeof(AT)+ (typeInfo ? 16 : 0)) ) { | ||
| 1335 | 1335 | if ( typeInfo ) { | |
| 1336 | 1336 | *((TypeInfo **)ptr) = typeInfo; | |
| 1337 | 1337 | ptr += 16; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,10 +16,8 @@ namespace das { | |||
| 16 | 16 | void builtin_table_clear ( Table & arr, Context * context ); | |
| 17 | 17 | vec4f _builtin_hash ( Context & context, SimNode_CallBase * call, vec4f * args ); | |
| 18 | 18 | uint64_t heap_bytes_allocated ( Context * context ); | |
| 19 | - uint64_t heap_high_watermark ( Context * context ); | ||
| 20 | 19 | int32_t heap_depth ( Context * context ); | |
| 21 | 20 | uint64_t string_heap_bytes_allocated ( Context * context ); | |
| 22 | - uint64_t string_heap_high_watermark ( Context * context ); | ||
| 23 | 21 | int32_t string_heap_depth ( Context * context ); | |
| 24 | 22 | void builtin_table_lock ( const Table & arr, Context * context ); | |
| 25 | 23 | void builtin_table_unlock ( const Table & arr, Context * context ); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -198,24 +198,26 @@ namespace das { | |||
| 198 | 198 | MemoryModel model; | |
| 199 | 199 | }; | |
| 200 | 200 | ||
| 201 | - /* | ||
| 202 | 201 | class LinearHeapAllocator : public AnyHeapAllocator { | |
| 203 | 202 | public: | |
| 204 | 203 | LinearHeapAllocator() {} | |
| 205 | 204 | virtual char * allocate ( uint32_t size ) override { return model.allocate(size); } | |
| 206 | - virtual void free ( char * ptr ) override { return model.free(ptr); } | ||
| 205 | + virtual void free ( char * ptr, uint32_t size ) override { model.free(ptr,size); } | ||
| 206 | + virtual char * reallocate ( char * ptr, uint32_t oldSize, uint32_t newSize ) override { return model.reallocate(ptr,oldSize,newSize); } | ||
| 207 | 207 | virtual int depth() const override { return model.depth(); } | |
| 208 | - virtual uint64_t bytesAllocated() const override {} return model.bytesAllocated(); } | ||
| 208 | + virtual uint64_t bytesAllocated() const override { return model.bytesAllocated(); } | ||
| 209 | 209 | virtual uint64_t totalAlignedMemoryAllocated() const override { return model.totalAlignedMemoryAllocated(); } | |
| 210 | 210 | virtual void reset() override { model.reset(); } | |
| 211 | 211 | virtual void report() override; | |
| 212 | 212 | virtual bool mark() override { return false; } | |
| 213 | - virtual void mark ( const char *, uint32_t ) override { DAS_ASSERT(0 && "not supported"); } | ||
| 213 | + virtual void mark ( char *, uint32_t ) override { DAS_ASSERT(0 && "not supported"); } | ||
| 214 | 214 | virtual void sweep() override { DAS_ASSERT(0 && "not supported"); } | |
| 215 | + virtual bool isOwnPtr ( char * ptr, uint32_t ) override { return model.isOwnPtr(ptr); } | ||
| 216 | + virtual void setInitialSize ( uint32_t size ) override { model.setInitialSize(size); } | ||
| 217 | + virtual int32_t getInitialSize() const override { return model.initialSize; } | ||
| 215 | 218 | protected: | |
| 216 | 219 | LinearChunkAllocator model; | |
| 217 | 220 | }; | |
| 218 | - */ | ||
| 219 | 221 | ||
| 220 | 222 | #if DAS_TRACK_ALLOCATIONS | |
| 221 | 223 | extern uint64_t g_tracker_string; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -153,8 +153,8 @@ namespace das | |||
| 153 | 153 | repeatIt:; | |
| 154 | 154 | Table newTab; | |
| 155 | 155 | uint32_t memSize = newCapacity * (valueTypeSize + sizeof(KeyType) + sizeof(uint32_t)); | |
| 156 | - newTab.data = (char *) context->heap.allocate(memSize); | ||
| 157 | - context->heap.mark_comment(newTab.data, "table"); | ||
| 156 | + newTab.data = (char *) context->heap->allocate(memSize); | ||
| 157 | + context->heap->mark_comment(newTab.data, "table"); | ||
| 158 | 158 | if ( !newTab.data ) { | |
| 159 | 159 | context->throw_error("can't grow table, out of heap"); | |
| 160 | 160 | return false; | |
@@ -193,7 +193,7 @@ namespace das | |||
| 193 | 193 | } | |
| 194 | 194 | if (tab.capacity) { | |
| 195 | 195 | uint32_t oldSize = tab.capacity * (valueTypeSize + sizeof(KeyType) + sizeof(uint32_t)); | |
| 196 | - context->heap.free(tab.data, oldSize); | ||
| 196 | + context->heap->free(tab.data, oldSize); | ||
| 197 | 197 | } | |
| 198 | 198 | swap ( newTab, tab ); | |
| 199 | 199 | return true; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -183,7 +183,7 @@ namespace das | |||
| 183 | 183 | friend struct SimNode_TryCatch; | |
| 184 | 184 | friend class Program; | |
| 185 | 185 | public: | |
| 186 | - Context(uint32_t stackSize = 16*1024); | ||
| 186 | + Context(uint32_t stackSize = 16*1024, bool ph = false); | ||
| 187 | 187 | Context(const Context &); | |
| 188 | 188 | Context & operator = (const Context &) = delete; | |
| 189 | 189 | virtual ~Context(); | |
@@ -223,7 +223,7 @@ namespace das | |||
| 223 | 223 | ||
| 224 | 224 | __forceinline void restartHeaps() { | |
| 225 | 225 | DAS_ASSERTF(insideContext==0,"can't reset heaps in locked context"); | |
| 226 | - heap.reset(); | ||
| 226 | + heap->reset(); | ||
| 227 | 227 | stringHeap.reset(); | |
| 228 | 228 | } | |
| 229 | 229 | ||
@@ -523,7 +523,8 @@ namespace das | |||
| 523 | 523 | public: | |
| 524 | 524 | uint64_t * annotationData = nullptr; | |
| 525 | 525 | PersistentStringAllocator stringHeap; | |
| 526 | - PersistentHeapAllocator heap; | ||
| 526 | + smart_ptr<AnyHeapAllocator> heap; | ||
| 527 | + bool persistent = false; | ||
| 527 | 528 | char * globals = nullptr; | |
| 528 | 529 | char * shared = nullptr; | |
| 529 | 530 | smart_ptr<ConstStringAllocator> constStringHeap; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments