From: Jean Privat Date: Sat, 29 Nov 2014 00:59:23 +0000 (-0500) Subject: Merge: Attributes access in nitvm X-Git-Tag: v0.6.11~3 X-Git-Url: http://nitlanguage.org Merge: Attributes access in nitvm Accessing attributes in the nitvm is now implemented by a faster mechanism than perfect hashing. Attribute access is now implemented by two different techniques: - perfect hashing, slow but multiple-inheritance compatible - direct access, fast but only compatible with single inheritance For a given access to an attribute, we try to use direct access if possible, i.e. if this attribute is always at the same position in objects. If this attribute has multiple position in objects, we need to use perfect hashing. Non-contractual perfs: the nitvm is now a little faster than before and these two different implementations will allow to work on optimization protocols in the futur. Pull-Request: #943 Reviewed-by: Jean Privat Reviewed-by: Alexandre Terrasa --- 29827ae90993e6be78fd3983755ce1c0d2f9860e diff --cc src/vm.nit index 75868c6,65e03a1..3494602 --- a/src/vm.nit +++ b/src/vm.nit @@@ -260,6 -267,18 +267,18 @@@ class VirtualMachine super NaiveInterpr return res; `} + # Return the attribute value in `instance` with a direct access (SST) - # `instance` is the attributes array of the receiver - # `offset` is the absolute offset of this attribute ++ # * `instance` is the attributes array of the receiver ++ # * `offset` is the absolute offset of this attribute + private fun read_attribute_sst(instance: Pointer, offset: Int): Instance `{ + /* We can make a direct access to the attribute value + because this attribute is always at the same position + for the class of this receiver */ + Instance res = ((Instance *)instance)[offset]; + + return res; + `} + # Replace in `recv` the value of the attribute `mproperty` by `value` redef fun write_attribute(mproperty: MAttribute, recv: Instance, value: Instance) do @@@ -291,6 -316,16 +316,16 @@@ 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 ++ # * `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 @@@ -547,13 -591,13 +591,13 @@@ redef class MClas return res end - # Update positions of self class in `parent` + # Update positions of the class `cl` - # `attributes_offset`: absolute offset of introduced attributes - # `methods_offset`: absolute offset of introduced methods + # * `attributes_offset`: absolute offset of introduced attributes + # * `methods_offset`: absolute offset of introduced methods - private fun update_positions(attributes_offsets: Int, methods_offset:Int, parent: MClass) + private fun update_positions(attributes_offsets: Int, methods_offset:Int, cl: MClass) do - parent.positions_attributes[self] = attributes_offsets - parent.positions_methods[self] = methods_offset + positions_attributes[cl] = attributes_offsets + positions_methods[cl] = methods_offset end end