From 1864f47d038922397651049ba709c6ab9a4b7827 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Julien=20Pag=C3=A8s?= Date: Thu, 27 Nov 2014 14:17:44 +0100 Subject: [PATCH] nitvm: Attributes access is fully functionnal with direct access when possible MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Julien Pagès --- src/vm.nit | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/vm.nit b/src/vm.nit index d745909..65e03a1 100644 --- a/src/vm.nit +++ b/src/vm.nit @@ -284,11 +284,17 @@ class VirtualMachine super NaiveInterpreter do assert recv isa MutableInstance - var id = mproperty.intro_mclassdef.mclass.vtable.id - # Replace the old value of mproperty in recv - write_attribute_ph(recv.internal_attributes, recv.vtable.internal_vtable, + if mproperty.intro_mclassdef.mclass.positions_attributes[recv.mtype.as(MClassType).mclass] != -1 then + # if this attribute class has an unique position for this receiver, then use direct access + write_attribute_sst(recv.internal_attributes, mproperty.absolute_offset, value) + else + # Otherwise, use perfect hashing to replace the old value + var id = mproperty.intro_mclassdef.mclass.vtable.id + + write_attribute_ph(recv.internal_attributes, recv.vtable.internal_vtable, recv.vtable.mask, id, mproperty.offset, value) + end end # Replace the value of an attribute in an instance @@ -310,6 +316,16 @@ class VirtualMachine super NaiveInterpreter Instance_incr_ref(value); `} + # Replace the value of an attribute in an instance with direct access + # `instance` is the attributes array of the receiver + # `offset` is the absolute offset of this attribute + # `value` is the new value for this attribute + private fun write_attribute_sst(instance: Pointer, offset: Int, value: Instance) `{ + // Direct access to the position with the absolute offset + ((Instance *)instance)[offset] = value; + Instance_incr_ref(value); + `} + # Is the attribute `mproperty` initialized in the instance `recv`? redef fun isset_attribute(mproperty: MAttribute, recv: Instance): Bool do -- 1.7.9.5