# Monday, August 19, 2002
« No Title | Main | No Title »
No Title
I changed the XML remapping language to support Object.hashCode() & Object.toString() twiddling (see this previous posting for more info). It is now possible to specify which CIL code sequence should be substituted for a call to a method. Here is how Object.hashCode() looks:

<method type="instance" name="hashCode" sig="()I" access="public">
 
<override name="GetHashCode" />
  
<invokespecial>
   
<call class="System.Object name="GetHashCode" />
 
</invokespecial>
 
<invokevirtual>
   
<dup />
   
<isinst class="System.String" />
   
<brfalse name="skip" />
   
<call class="StringHelper" name="hashCode" />
   
<br name="end" />
   
<label name="skip" />
   
<callvirt class="System.Object name="GetHashCode" />
   
<label name="end" />
 
</invokevirtual>
</method>

Every virtual call (the invokevirtual bytecode) is converted into a test to see if the call is being done on a string, if so it calls StringHelper.hashCode(), if not, it calls System.Object.GetHashCode(). This isn't yet how it should be, because when it is known at compile time that the reference that hashCode() is called on isn't a string, then this test shouldn't be emitted. I still have to figure out a way to support this optimization.

Updated the binaries and source snaphots.

Monday, August 19, 2002 2:53:35 PM (W. Europe Daylight Time, UTC+02:00)  #    Comments [1]
Wednesday, August 21, 2002 8:25:20 AM (W. Europe Daylight Time, UTC+02:00)

You can also optimize the test away (in the other direction) if it's known at compile time that the object *is* a string. Or is that unnecessary since String provides its own GetHashCode implementation that will be invokespecialed already since it's a final class (or whatever the CLR equivalent of final is)?
Stuart
Comments are closed.