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;
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
# 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]
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