FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

now with both linear and persistent heap · moneytech/daScript@0cf2645 · GitHub

Commit 0cf2645

Browse files
committed
now with both linear and persistent heap
1 parent 29f0d89 commit 0cf2645

23 files changed

Lines changed: 147 additions & 124 deletions

‎examples/test/test_handles.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ vec4f new_and_init ( Context & context, SimNode_CallBase * call, vec4f * ) {
346346
return v_zero();
347347
}
348348
auto size = getTypeSize(typeInfo);
349-
auto data = context.heap.allocate(size);
349+
auto data = context.heap->allocate(size);
350350
if ( typeInfo->structType && typeInfo->structType->initializer!=-1 ) {
351351
auto fn = context.getFunction(typeInfo->structType->initializer);
352352
context.callWithCopyOnReturn(fn, nullptr, data, 0);

‎examples/test/unit_tests/new_delete.das‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// options log=true
22
// options log_infer_passes=true // log_nodes=false
33

4+
options persistent_heap = true
5+
46
require UnitTest
57

68
struct SomethingSmall

‎include/daScript/ast/ast.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,9 @@ namespace das
899899
// memory
900900
uint32_t stack = 16*1024; // 0 for unique stack
901901
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;
902905
// rtti
903906
bool rtti = false; // create extended RTTI
904907
// language

‎include/daScript/ast/ast_handle.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ namespace das
272272
char ** value = (char **) _value;
273273
*value = nullptr;
274274
}
275-
context.heap.free((char *)this, sizeof(VectorIterator));
275+
context.heap->free((char *)this, sizeof(VectorIterator));
276276
}
277277
VectorType * array;
278278
char * array_end = nullptr;

‎include/daScript/misc/memory_model.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ namespace das {
290290
LinearChunkAllocator() { }
291291
char * allocate ( uint32_t s );
292292
void free ( char * ptr, uint32_t s );
293+
char * reallocate ( char * ptr, uint32_t size, uint32_t nsize );
293294
virtual void reset ();
294295
char * allocateName ( const string & name );
295296
__forceinline bool isOwnPtrQnD ( const char * ptr ) const {
@@ -314,7 +315,6 @@ namespace das {
314315
void getStats ( uint32_t & depth, uint64_t & bytes, uint64_t & total ) const;
315316
public:
316317
function<int(int)> customGrow;
317-
protected:
318318
uint32_t initialSize = 65536;
319319
uint32_t alignMask = 15;
320320
HeapChunk * chunk = nullptr;

‎include/daScript/simulate/aot.h‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,14 +1016,14 @@ namespace das {
10161016
template <typename TT>
10171017
struct das_new {
10181018
static __forceinline TT * make ( Context * __context__ ) {
1019-
char * data = __context__->heap.allocate( sizeof(TT) );
1019+
char * data = __context__->heap->allocate( sizeof(TT) );
10201020
if ( !data ) __context__->throw_error("out of heap");
10211021
memset ( data, 0, sizeof(TT) );
10221022
return (TT *) data;
10231023
}
10241024
template <typename QQ>
10251025
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) );
10271027
if ( !data ) __context__->throw_error("out of heap");
10281028
*data = init();
10291029
return data;
@@ -1115,7 +1115,7 @@ namespace das {
11151115
template <typename TT>
11161116
struct das_delete_lambda_struct<TT *> {
11171117
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);
11191119
}
11201120
};
11211121

@@ -1125,7 +1125,7 @@ namespace das {
11251125
template <typename TT>
11261126
struct das_delete_ptr<TT *> {
11271127
static __forceinline void clear ( Context * __context__, TT * ptr ) {
1128-
__context__->heap.free((char *)ptr, sizeof(TT));
1128+
__context__->heap->free((char *)ptr, sizeof(TT));
11291129
}
11301130
};
11311131

@@ -1196,7 +1196,7 @@ namespace das {
11961196
if ( dim.data ) {
11971197
if ( !dim.lock ) {
11981198
uint32_t oldSize = dim.capacity*sizeof(TT);
1199-
__context__->heap.free(dim.data, oldSize);
1199+
__context__->heap->free(dim.data, oldSize);
12001200
} else {
12011201
__context__->throw_error("can't delete locked array");
12021202
}
@@ -1211,7 +1211,7 @@ namespace das {
12111211
if ( tab.data ) {
12121212
if ( !tab.lock ) {
12131213
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);
12151215
} else {
12161216
__context__->throw_error("can't delete locked table");
12171217
}
@@ -1279,7 +1279,7 @@ namespace das {
12791279
template <typename TT, typename AT, bool moveIt = false>
12801280
struct das_ascend {
12811281
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)) ) {
12831283
if ( typeInfo ) {
12841284
*((TypeInfo **)ptr) = typeInfo;
12851285
ptr += 16;
@@ -1331,7 +1331,7 @@ namespace das {
13311331
template <typename AT>
13321332
struct das_ascend<Lambda,AT,false> {
13331333
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)) ) {
13351335
if ( typeInfo ) {
13361336
*((TypeInfo **)ptr) = typeInfo;
13371337
ptr += 16;

‎include/daScript/simulate/aot_builtin.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ namespace das {
1616
void builtin_table_clear ( Table & arr, Context * context );
1717
vec4f _builtin_hash ( Context & context, SimNode_CallBase * call, vec4f * args );
1818
uint64_t heap_bytes_allocated ( Context * context );
19-
uint64_t heap_high_watermark ( Context * context );
2019
int32_t heap_depth ( Context * context );
2120
uint64_t string_heap_bytes_allocated ( Context * context );
22-
uint64_t string_heap_high_watermark ( Context * context );
2321
int32_t string_heap_depth ( Context * context );
2422
void builtin_table_lock ( const Table & arr, Context * context );
2523
void builtin_table_unlock ( const Table & arr, Context * context );

‎include/daScript/simulate/heap.h‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,24 +198,26 @@ namespace das {
198198
MemoryModel model;
199199
};
200200

201-
/*
202201
class LinearHeapAllocator : public AnyHeapAllocator {
203202
public:
204203
LinearHeapAllocator() {}
205204
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); }
207207
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(); }
209209
virtual uint64_t totalAlignedMemoryAllocated() const override { return model.totalAlignedMemoryAllocated(); }
210210
virtual void reset() override { model.reset(); }
211211
virtual void report() override;
212212
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"); }
214214
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; }
215218
protected:
216219
LinearChunkAllocator model;
217220
};
218-
*/
219221

220222
#if DAS_TRACK_ALLOCATIONS
221223
extern uint64_t g_tracker_string;

‎include/daScript/simulate/runtime_table.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ namespace das
153153
repeatIt:;
154154
Table newTab;
155155
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");
158158
if ( !newTab.data ) {
159159
context->throw_error("can't grow table, out of heap");
160160
return false;
@@ -193,7 +193,7 @@ namespace das
193193
}
194194
if (tab.capacity) {
195195
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);
197197
}
198198
swap ( newTab, tab );
199199
return true;

‎include/daScript/simulate/simulate.h‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ namespace das
183183
friend struct SimNode_TryCatch;
184184
friend class Program;
185185
public:
186-
Context(uint32_t stackSize = 16*1024);
186+
Context(uint32_t stackSize = 16*1024, bool ph = false);
187187
Context(const Context &);
188188
Context & operator = (const Context &) = delete;
189189
virtual ~Context();
@@ -223,7 +223,7 @@ namespace das
223223

224224
__forceinline void restartHeaps() {
225225
DAS_ASSERTF(insideContext==0,"can't reset heaps in locked context");
226-
heap.reset();
226+
heap->reset();
227227
stringHeap.reset();
228228
}
229229

@@ -523,7 +523,8 @@ namespace das
523523
public:
524524
uint64_t * annotationData = nullptr;
525525
PersistentStringAllocator stringHeap;
526-
PersistentHeapAllocator heap;
526+
smart_ptr<AnyHeapAllocator> heap;
527+
bool persistent = false;
527528
char * globals = nullptr;
528529
char * shared = nullptr;
529530
smart_ptr<ConstStringAllocator> constStringHeap;

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL