diff --git a/argon/lang/parser2/node/node.h b/argon/lang/parser2/node/node.h index 392c53e8..2762d56d 100644 --- a/argon/lang/parser2/node/node.h +++ b/argon/lang/parser2/node/node.h @@ -269,10 +269,7 @@ const argon::vm::datatype::TypeInfo *argon::lang::parser2::ExtName = &alias##Ast T *NewNode(const TypeInfo *t_info, bool gc, NodeType node_type) { T *node; - if (!gc) - node = MakeObject(t_info); - else - node = MakeGCObject(t_info, false); + node = !gc ? MakeObject(t_info) : MakeGCObject(t_info); if (node == nullptr) return nullptr; @@ -283,6 +280,9 @@ const argon::vm::datatype::TypeInfo *argon::lang::parser2::ExtName = &alias##Ast *((NodeType *) n_obj) = node_type; + if (gc) + argon::vm::memory::Track((ArObject *) node); + return node; } diff --git a/argon/vm/datatype/arobject.h b/argon/vm/datatype/arobject.h index 749fd229..8f404d9d 100644 --- a/argon/vm/datatype/arobject.h +++ b/argon/vm/datatype/arobject.h @@ -111,13 +111,13 @@ namespace argon::vm::datatype { } template - T *MakeGCObject(const TypeInfo *type, bool track) { - return (T *) memory::GCNew(type, track); + T *MakeGCObject(const TypeInfo *type) { + return (T *) memory::GCNew(type, false); } template - T *MakeGCObject(TypeInfo *type, bool track) { - auto *ret = (T *) memory::GCNew(type, track); + T *MakeGCObject(TypeInfo *type) { + auto *ret = (T *) memory::GCNew(type, false); if (ret != nullptr) IncRef(type); diff --git a/argon/vm/datatype/chan.cpp b/argon/vm/datatype/chan.cpp index a98c64d7..a9636ee9 100644 --- a/argon/vm/datatype/chan.cpp +++ b/argon/vm/datatype/chan.cpp @@ -270,7 +270,7 @@ bool argon::vm::datatype::ChanWrite(Chan *chan, ArObject *value) { } Chan *argon::vm::datatype::ChanNew(ArObject *defval, unsigned int backlog) { - auto *chan = MakeGCObject(type_chan_, false); + auto *chan = MakeGCObject(type_chan_); if (chan != nullptr) { if ((chan->queue = (ArObject **) argon::vm::memory::Alloc(backlog * sizeof(void *))) == nullptr) { diff --git a/argon/vm/datatype/dict.cpp b/argon/vm/datatype/dict.cpp index f1ad625e..3f00b684 100644 --- a/argon/vm/datatype/dict.cpp +++ b/argon/vm/datatype/dict.cpp @@ -277,7 +277,7 @@ ArObject *dict_compare(Dict *self, ArObject *other, CompareMode mode) { } ArObject *dict_iter(Dict *self, bool reverse) { - auto *li = MakeGCObject(type_dict_iterator_, true); + auto *li = MakeGCObject(type_dict_iterator_); if (li != nullptr) { std::shared_lock _(self->rwlock); @@ -291,6 +291,8 @@ ArObject *dict_iter(Dict *self, bool reverse) { li->cursor->ref++; li->reverse = reverse; + + argon::vm::memory::Track((ArObject*)li); } return (ArObject *) li; @@ -631,7 +633,7 @@ Dict *argon::vm::datatype::DictMerge(Dict *dict1, Dict *dict2, bool clone) { } Dict *argon::vm::datatype::DictNew() { - auto *dict = MakeGCObject(type_dict_, false); + auto *dict = MakeGCObject(type_dict_); if (dict != nullptr) { if (!dict->hmap.Initialize()) { @@ -719,7 +721,7 @@ Dict *argon::vm::datatype::DictNew(ArObject *object) { } Dict *argon::vm::datatype::DictNew(unsigned int size) { - auto *dict = MakeGCObject(type_dict_, false); + auto *dict = MakeGCObject(type_dict_); if (dict != nullptr) { if (!dict->hmap.Initialize(size)) { diff --git a/argon/vm/datatype/function.cpp b/argon/vm/datatype/function.cpp index a21d1b6c..e8a67825 100644 --- a/argon/vm/datatype/function.cpp +++ b/argon/vm/datatype/function.cpp @@ -186,7 +186,7 @@ bool FunctionCheckParams(const PCheck *pcheck, ArObject **args, ArSize count) { } Function *FunctionClone(const Function *func) { - auto *fn = MakeGCObject(type_function_, false); + auto *fn = MakeGCObject(type_function_); if (fn != nullptr) { if (func->IsNative()) @@ -213,7 +213,7 @@ Function *FunctionClone(const Function *func) { } Function *FunctionNew(String *name, String *doc, unsigned short arity, FunctionFlags flags) { - auto *fn = MakeGCObject(type_function_, false); + auto *fn = MakeGCObject(type_function_); if (fn != nullptr) { fn->name = IncRef(name); diff --git a/argon/vm/datatype/future.cpp b/argon/vm/datatype/future.cpp index 0729fb04..11d28f59 100644 --- a/argon/vm/datatype/future.cpp +++ b/argon/vm/datatype/future.cpp @@ -80,7 +80,7 @@ bool argon::vm::datatype::FutureAWait(Future *future) { } Future *argon::vm::datatype::FutureNew() { - auto *future = MakeGCObject(type_future_, false); + auto *future = MakeGCObject(type_future_); if (future != nullptr) { future->value = nullptr; diff --git a/argon/vm/datatype/iterator.h b/argon/vm/datatype/iterator.h index 5a46ca05..b939ebf7 100644 --- a/argon/vm/datatype/iterator.h +++ b/argon/vm/datatype/iterator.h @@ -60,6 +60,8 @@ namespace argon::vm::datatype { } inline void IteratorTrace(IteratorGeneric *self, Void_UnaryOp trace){ + std::unique_lock _(self->lock); + trace(self->iterable); } diff --git a/argon/vm/datatype/list.cpp b/argon/vm/datatype/list.cpp index 3111aecf..64815009 100644 --- a/argon/vm/datatype/list.cpp +++ b/argon/vm/datatype/list.cpp @@ -499,7 +499,7 @@ ArObject *list_compare(List *self, ArObject *other, CompareMode mode) { } ArObject *list_iter(List *self, bool reverse) { - auto *li = MakeGCObject(type_list_iterator_, true); + auto *li = MakeGCObject(type_list_iterator_); if (li != nullptr) { new(&li->lock)std::mutex; @@ -507,6 +507,8 @@ ArObject *list_iter(List *self, bool reverse) { li->iterable = IncRef(self); li->index = 0; li->reverse = reverse; + + argon::vm::memory::Track((ArObject *) li); } return (ArObject *) li; @@ -817,7 +819,7 @@ List *ListFromIterable(List **dest, ArObject *iterable) { } List *argon::vm::datatype::ListNew(ArSize capacity) { - auto *list = MakeGCObject(type_list_, false); + auto *list = MakeGCObject(type_list_); if (list != nullptr) { list->objects = nullptr; diff --git a/argon/vm/datatype/module.cpp b/argon/vm/datatype/module.cpp index 4b1c358a..bfff17cd 100644 --- a/argon/vm/datatype/module.cpp +++ b/argon/vm/datatype/module.cpp @@ -347,7 +347,7 @@ Module *argon::vm::datatype::ModuleNew(const ModuleInit *init) { } Module *argon::vm::datatype::ModuleNew(String *name, String *doc) { - auto *mod = MakeGCObject(type_module_, true); + auto *mod = MakeGCObject(type_module_); if (mod != nullptr) { mod->fini = nullptr; @@ -368,6 +368,8 @@ Module *argon::vm::datatype::ModuleNew(String *name, String *doc) { Release(mod); return nullptr; } + + memory::Track((ArObject *) mod); } return mod; diff --git a/argon/vm/datatype/namespace.cpp b/argon/vm/datatype/namespace.cpp index f20b8120..9d322ddb 100644 --- a/argon/vm/datatype/namespace.cpp +++ b/argon/vm/datatype/namespace.cpp @@ -317,7 +317,7 @@ List *argon::vm::datatype::NamespaceKeysToList(Namespace *ns, AttributeFlag matc } Namespace *argon::vm::datatype::NamespaceNew() { - auto *ns = MakeGCObject(&NamespaceType, true); + auto *ns = MakeGCObject(&NamespaceType); if (ns != nullptr) { if (!ns->ns.Initialize()) { @@ -327,6 +327,8 @@ Namespace *argon::vm::datatype::NamespaceNew() { } new(&ns->rwlock)sync::RecursiveSharedMutex(); + + memory::Track((ArObject*)ns); } return ns; diff --git a/argon/vm/datatype/option.cpp b/argon/vm/datatype/option.cpp index 2cd7023c..73ba283c 100644 --- a/argon/vm/datatype/option.cpp +++ b/argon/vm/datatype/option.cpp @@ -135,7 +135,7 @@ TypeInfo OptionType = { const TypeInfo *argon::vm::datatype::type_option_ = &OptionType; Option *argon::vm::datatype::OptionNew(ArObject *value) { - auto *opt = MakeGCObject