Keep CLASS->obj_alloc_size at 0 This makes sure that Init_Obj doesn't reset any values when bootstrapping.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/70f2562d Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/70f2562d Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/70f2562d Branch: refs/heads/master Commit: 70f2562db5dbd3614b8a6b36f2a1562cdf7f9e05 Parents: 7528af4 Author: Nick Wellnhofer <wellnho...@aevum.de> Authored: Thu Mar 10 20:48:58 2016 +0100 Committer: Nick Wellnhofer <wellnho...@aevum.de> Committed: Thu Mar 10 21:49:25 2016 +0100 ---------------------------------------------------------------------- runtime/core/Clownfish/Class.c | 35 ++++++++++----------------------- runtime/go/clownfish/class_test.go | 4 ++-- 2 files changed, 12 insertions(+), 27 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/70f2562d/runtime/core/Clownfish/Class.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Class.c b/runtime/core/Clownfish/Class.c index bfa9978..86fe7c1 100644 --- a/runtime/core/Clownfish/Class.c +++ b/runtime/core/Clownfish/Class.c @@ -93,14 +93,6 @@ Class_bootstrap(const cfish_ClassSpec *specs, size_t num_specs, // Needed to calculate size of subclasses. klass->class_alloc_size = class_alloc_size; - if (spec->klass == &CLASS) { - // `obj_alloc_size` is used by Init_Obj to zero the object. In the - // next pass, this method is called to initialize the Class - // objects. The Class struct is zeroed already, so this isn't - // crucial, but let's set the correct value here. - klass->obj_alloc_size = offsetof(Class, vtable); - } - // Initialize the global pointer to the Class. if (!Atomic_cas_ptr((void**)spec->klass, NULL, klass)) { // Another thread beat us to it. @@ -138,26 +130,15 @@ Class_bootstrap(const cfish_ClassSpec *specs, size_t num_specs, } } - // Init_Obj clears all klass ivars, so `class_alloc_size` must be - // recalculated. + // CLASS->obj_alloc_size is always 0, so Init_Obj doesn't clear any + // values set in the previous pass or by another thread. Class_Init_Obj_IMP(CLASS, klass); - uint32_t novel_offset = parent - ? parent->class_alloc_size - : offsetof(Class, vtable); - uint32_t class_alloc_size = novel_offset - + spec->num_novel_meths - * sizeof(cfish_method_t); - - klass->parent = parent; - klass->parcel_id = parcel_id; - klass->class_alloc_size = class_alloc_size; + klass->parent = parent; + klass->parcel_id = parcel_id; - if (klass == CLASS) { - // Don't account for vtable array. - klass->obj_alloc_size = offsetof(Class, vtable); - } - else { + // CLASS->obj_alloc_size must stay at 0. + if (klass != CLASS) { klass->obj_alloc_size = ivars_offset + spec->ivars_size; } if (cfish_Class_bootstrap_hook1 != NULL) { @@ -195,6 +176,10 @@ Class_bootstrap(const cfish_ClassSpec *specs, size_t num_specs, Class_Override_IMP(klass, mspec->func, *mspec->offset); } + uint32_t novel_offset = parent + ? parent->class_alloc_size + : offsetof(Class, vtable); + for (size_t i = 0; i < spec->num_novel_meths; ++i) { const NovelMethSpec *mspec = &novel_specs[num_novel++]; *mspec->offset = novel_offset; http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/70f2562d/runtime/go/clownfish/class_test.go ---------------------------------------------------------------------- diff --git a/runtime/go/clownfish/class_test.go b/runtime/go/clownfish/class_test.go index ebd3a68..b96b1e0 100644 --- a/runtime/go/clownfish/class_test.go +++ b/runtime/go/clownfish/class_test.go @@ -36,8 +36,8 @@ func TestClassGetParent(t *testing.T) { func TestClassGetObjAllocSize(t *testing.T) { intClass := FetchClass("Clownfish::Integer") - classClass := FetchClass("Clownfish::Class") - if intClass.GetObjAllocSize() >= classClass.GetObjAllocSize() { + objClass := FetchClass("Clownfish::Obj") + if intClass.GetObjAllocSize() <= objClass.GetObjAllocSize() { t.Error("Unexpected result for getObjAllocSize") } }