From c85f0b65a9fc2e1a060732944241a1d164baa140 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Julien=20Pag=C3=A8s?= Date: Fri, 5 Dec 2014 10:02:01 -0500 Subject: [PATCH] nitvm: Subtyping test is now implemented with direct access MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Julien Pagès --- src/vm.nit | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/vm.nit b/src/vm.nit index 1f6d574..b9a37c4 100644 --- a/src/vm.nit +++ b/src/vm.nit @@ -123,11 +123,12 @@ class VirtualMachine super NaiveInterpreter var super_id = sup.mclass.vtable.id var mask = sub.mclass.vtable.mask - return inter_is_subtype(super_id, mask, sub.mclass.vtable.internal_vtable) + # For now, we always use perfect hashing for subtyping test + return inter_is_subtype_ph(super_id, mask, sub.mclass.vtable.internal_vtable) end # Subtyping test with perfect hashing - private fun inter_is_subtype(id: Int, mask:Int, vtable: Pointer): Bool `{ + private fun inter_is_subtype_ph(id: Int, mask:Int, vtable: Pointer): Bool `{ // hv is the position in hashtable int hv = id & mask; @@ -138,6 +139,14 @@ class VirtualMachine super NaiveInterpreter return *offset == id; `} + # Subtyping test with Cohen test (direct access) + private fun inter_is_subtype_sst(id: Int, position: Int, vtable: Pointer): Bool `{ + // Direct access to the position given in parameter + int tableid = (long unsigned int)((long int *)vtable)[position]; + + return id == tableid; + `} + # Redef init_instance to simulate the loading of a class redef fun init_instance(recv: Instance) do @@ -364,6 +373,10 @@ redef class MClass # True when the class is effectively loaded by the vm, false otherwise var loaded: Bool = false + # Color for Cohen subtyping test : the absolute position of the id + # of this class in virtual tables + var color: Int + # For each loaded subclass, keep the position of the group of attributes # introduced by self class in the object var positions_attributes: HashMap[MClass, Int] = new HashMap[MClass, Int] @@ -433,6 +446,9 @@ redef class MClass allocate_vtable(v, ids, nb_methods, nb_attributes, offset_attributes, offset_methods) loaded = true + # Set the absolute position of the identifier of this class in the virtual table + color = offset_methods - 2 + # The virtual table now needs to be filled with pointer to methods superclasses.add(self) for cl in superclasses do -- 1.7.9.5