Allocate just the right amount of memory that we need for this class's static fields, including fields inherited from the superclass.
Signed-off-by: Vegard Nossum <vegard.nos...@gmail.com> --- vm/class.c | 15 ++++++++++++--- 1 files changed, 12 insertions(+), 3 deletions(-) diff --git a/vm/class.c b/vm/class.c index acd1fa5..3560ba9 100644 --- a/vm/class.c +++ b/vm/class.c @@ -199,8 +199,7 @@ int vm_class_link(struct vm_class *vmc, const struct cafebabe_class *class) static_offset = 0; } - /* XXX: only static fields, right size, etc. */ - vmc->static_values = malloc(static_offset + class->fields_count * 8); + unsigned int static_size = 0; for (uint16_t i = 0; i < class->fields_count; ++i) { struct vm_field *vmf = &vmc->fields[i]; @@ -210,6 +209,16 @@ int vm_class_link(struct vm_class *vmc, const struct cafebabe_class *class) return -1; } + if (vm_field_is_static(vmf)) + static_size += 8; + } + + /* XXX: only static fields, right size, etc. */ + vmc->static_values = malloc(static_offset + static_size); + + for (uint16_t i = 0; i < class->fields_count; ++i) { + struct vm_field *vmf = &vmc->fields[i]; + if (vm_field_is_static(vmf)) { if (vm_field_init_static(vmf, static_offset)) { NOT_IMPLEMENTED; @@ -226,7 +235,7 @@ int vm_class_link(struct vm_class *vmc, const struct cafebabe_class *class) } vmc->object_size = offset; - vmc->static_size = static_offset; + vmc->static_size = static_offset + static_size; vmc->methods = malloc(sizeof(*vmc->methods) * class->methods_count); if (!vmc->methods) { -- 1.6.0.4 ------------------------------------------------------------------------------ _______________________________________________ Jatovm-devel mailing list Jatovm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jatovm-devel