Thread: [Ikvm-developers] HashMap Performance Issue
Brought to you by:
jfrijters
From: xiang l. <sea...@gm...> - 2011-05-09 07:23:42
|
Hi, I am looking at a HashMap performance issue. In the Java code, the key used in the Hashmap has its hashCode overridden. But when I looked into the reversed C# code of java.util.HashMap implementation. Since the Key is java.lang.Object, the overridden version is not used, see below. It actuall calls Object.instancehelper_hashCode. which calls GetHashCode() in ture if the object is not a String, equals method has the same issue in HashMap .NET implementation. [MethodImpl(MethodImplOptions.NoInlining), Signature("(Ljava/lang/Object;)TV;"), LineNumberTable(new byte[] { 160, 0xc9, 0x63, 0x69, 0x6c, 0x75, 0xa3, 0x7d, 0xe7, 0x3d, 0xe9, 0x45 })] public override object get(object key) { if (key == null) { return this.getForNullKey(); } int num = hash(Object.instancehelper_hashCode(key)); for (Entry entry = this.table[indexFor(num, this.table.Length)]; entry != null; entry = entry.next) { object obj2; if ((entry.hash == num) && (((obj2 = entry.key) == key) || Object.instancehelper_equals(key, obj2))) { return entry.value; } } return null; } I would want the .NET version use the same hashCode and equals function, but I have no idea of resolving this issue, Is this a bug or some issue we already know? Could a map.xml be used to preserve hashCode method which means no rediection of the call? Any idea? Please help. Thanks, Sean |
From: Jeroen F. <je...@su...> - 2011-05-09 07:41:27
|
Hi, The overridden version *is* used, because java.lang.Object.hashCode() overrides System.Object.GetHashCode(). Regards, Jeroen > -----Original Message----- > From: xiang liu [mailto:sea...@gm...] > Sent: Monday, May 09, 2011 9:24 AM > To: Ikv...@li... > Subject: [Ikvm-developers] HashMap Performance Issue > > Hi, > > I am looking at a HashMap performance issue. In the Java code, the key > used in the Hashmap has its hashCode overridden. But when I looked into > the reversed C# code of java.util.HashMap implementation. Since the Key > is java.lang.Object, the overridden version is not used, see below. It > actuall calls > > Object.instancehelper_hashCode. which calls GetHashCode() in ture if the > object is not a String, equals method has the same issue in HashMap .NET > implementation. > > [MethodImpl(MethodImplOptions.NoInlining), > Signature("(Ljava/lang/Object;)TV;"), LineNumberTable(new byte[] { 160, > 0xc9, 0x63, 0x69, 0x6c, 0x75, 0xa3, 0x7d, 0xe7, 0x3d, 0xe9, 0x45 })] > public override object get(object key) { > if (key == null) > { > return this.getForNullKey(); > } > int num = hash(Object.instancehelper_hashCode(key)); > for (Entry entry = this.table[indexFor(num, this.table.Length)]; > entry != null; entry = entry.next) > { > object obj2; > if ((entry.hash == num) && (((obj2 = entry.key) == key) || > Object.instancehelper_equals(key, obj2))) > { > return entry.value; > } > } > return null; > } > > > I would want the .NET version use the same hashCode and equals function, > but I have no idea of resolving this issue, Is this a bug or some issue > we already know? Could a map.xml be used to preserve hashCode method > which means no rediection of the call? > > Any idea? Please help. > > Thanks, > > Sean > > ------------------------------------------------------------------------ > ------ > WhatsUp Gold - Download Free Network Management Software The most > intuitive, comprehensive, and cost-effective network management toolset > available today. Delivers lowest initial acquisition cost and overall > TCO of any competing solution. > http://p.sf.net/sfu/whatsupgold-sd > _______________________________________________ > Ikvm-developers mailing list > Ikv...@li... > https://lists.sourceforge.net/lists/listinfo/ikvm-developers |
From: Sean L. <sea...@gm...> - 2011-05-09 07:56:27
|
Hi, Jeroen, Thanks for your quick reply. I am not sure I understood what you meant. Here is the code I copied from .NET Reflector. Both of the methods simply call System.Object.GetHashCode(). [HideFromJava <http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://IKVM.Runtime:0.47.4142.0/IKVM.Attributes.HideFromJavaAttribute/.ctor%28%29>,EditorBrowsable <http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://System:2.0.0.0:b77a5c561934e089/System.ComponentModel.EditorBrowsableAttribute/.ctor%28System.ComponentModel.EditorBrowsableState%29>(EditorBrowsableState <http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://System:4.0.0.0:b77a5c561934e089/System.ComponentModel.EditorBrowsableState>.Never <http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://System:4.0.0.0:b77a5c561934e089/System.ComponentModel.EditorBrowsableState/Never>)] public int <http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Int32> *GetHashCode <http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://IKVM.OpenJDK.Core:0.47.4142.0/java.lang.Object/GetHashCode%28%29:Int32>*() { return this.GetHashCode <http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Object/GetHashCode%28%29:Int32>(); } public virtual int <http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Int32> *hashCode <http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://IKVM.OpenJDK.Core:0.47.4142.0/java.lang.Object/hashCode%28%29:Int32>*() { return base.GetHashCode <http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Object/GetHashCode%28%29:Int32>(); } Has anyone reported that IKVM HashMap is much slower than the original java implementation. In my case, IKVM version took 5 times as the Java version did. Thanks, Sean On 5/9/2011 3:41 PM, Jeroen Frijters wrote: > Hi, > > The overridden version *is* used, because java.lang.Object.hashCode() overrides System.Object.GetHashCode(). > > Regards, > Jeroen > >> -----Original Message----- >> From: xiang liu [mailto:sea...@gm...] >> Sent: Monday, May 09, 2011 9:24 AM >> To: Ikv...@li... >> Subject: [Ikvm-developers] HashMap Performance Issue >> >> Hi, >> >> I am looking at a HashMap performance issue. In the Java code, the key >> used in the Hashmap has its hashCode overridden. But when I looked into >> the reversed C# code of java.util.HashMap implementation. Since the Key >> is java.lang.Object, the overridden version is not used, see below. It >> actuall calls >> >> Object.instancehelper_hashCode. which calls GetHashCode() in ture if the >> object is not a String, equals method has the same issue in HashMap .NET >> implementation. >> >> [MethodImpl(MethodImplOptions.NoInlining), >> Signature("(Ljava/lang/Object;)TV;"), LineNumberTable(new byte[] { 160, >> 0xc9, 0x63, 0x69, 0x6c, 0x75, 0xa3, 0x7d, 0xe7, 0x3d, 0xe9, 0x45 })] >> public override object get(object key) { >> if (key == null) >> { >> return this.getForNullKey(); >> } >> int num = hash(Object.instancehelper_hashCode(key)); >> for (Entry entry = this.table[indexFor(num, this.table.Length)]; >> entry != null; entry = entry.next) >> { >> object obj2; >> if ((entry.hash == num)&& (((obj2 = entry.key) == key) || >> Object.instancehelper_equals(key, obj2))) >> { >> return entry.value; >> } >> } >> return null; >> } >> >> >> I would want the .NET version use the same hashCode and equals function, >> but I have no idea of resolving this issue, Is this a bug or some issue >> we already know? Could a map.xml be used to preserve hashCode method >> which means no rediection of the call? >> >> Any idea? Please help. >> >> Thanks, >> >> Sean >> >> ------------------------------------------------------------------------ >> ------ >> WhatsUp Gold - Download Free Network Management Software The most >> intuitive, comprehensive, and cost-effective network management toolset >> available today. Delivers lowest initial acquisition cost and overall >> TCO of any competing solution. >> http://p.sf.net/sfu/whatsupgold-sd >> _______________________________________________ >> Ikvm-developers mailing list >> Ikv...@li... >> https://lists.sourceforge.net/lists/listinfo/ikvm-developers |
From: Jeroen F. <je...@su...> - 2011-05-09 08:00:40
|
Hi, Reflector is not a helpful tool to understand IKVM.NET, it does not accurately reflect the IL. Use ILDASM instead. Here's what ILDASM shows for java.lang.Object.hashCode(): .method public hidebysig newslot strict virtual instance int32 hashCode() cil managed { .override [mscorlib]System.Object::GetHashCode .maxstack 8 IL_0000: ldarg.0 IL_0001: call instance int32 [mscorlib]System.Object::GetHashCode() IL_0006: ret } The relevant line is ".override [mscorlib]System.Object::GetHashCode". If you have a performance problem, please try to provide an isolated test case, that gives the highest chance of getting it improved. Regards, Jeroen > -----Original Message----- > From: Sean Liu [mailto:sea...@gm...] > Sent: Monday, May 09, 2011 9:56 AM > To: Jeroen Frijters > Cc: Ikv...@li... > Subject: Re: [Ikvm-developers] HashMap Performance Issue > > Hi, Jeroen, > > Thanks for your quick reply. > > I am not sure I understood what you meant. Here is the code I copied > from .NET Reflector. Both of the methods simply call > System.Object.GetHashCode(). > > > [HideFromJava > <http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://IKVM.Runt > ime:0.47.4142.0/IKVM.Attributes.HideFromJavaAttribute/.ctor%28%29> , > EditorBrowsable > <http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://System:2. > 0.0.0:b77a5c561934e089/System.ComponentModel.EditorBrowsableAttribute/.c > tor%28System.ComponentModel.EditorBrowsableState%29> > (EditorBrowsableState > <http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://System:4. > 0.0.0:b77a5c561934e089/System.ComponentModel.EditorBrowsableState> > .Never > <http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://System:4. > 0.0.0:b77a5c561934e089/System.Com > ponentModel.EditorBrowsableState/Never> )] public int > <http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib: > 2.0.0.0:b77a5c561934e089/System.Int32> GetHashCode > <http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://IKVM.Open > JDK.Core:0.47.4142.0/java.lang.Object/GetHashCode%28%29:Int32> () { > return this.GetHashCode > <http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib: > 2.0.0.0:b77a5c561934e089/System.Object/GetHashCode%28%29:Int32> (); } > > public virtual int > <http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib: > 2.0.0.0:b77a5c561934e089/System.Int32> hashCode > <http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://IKVM.Open > JDK.Core:0.47.4142.0/java.lang.Object/hashCode%28%29:Int32> () { > return base.GetHashCode > <http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib: > 2.0.0.0:b77a5c561934e089/System.Object/GetHashCode%28%29:Int32> (); } > > Has anyone reported that IKVM HashMap is much slower than the original > java implementation. In my case, IKVM version took 5 times as the Java > version did. > > Thanks, > > Sean > > On 5/9/2011 3:41 PM, Jeroen Frijters wrote: > > Hi, > > The overridden version *is* used, because > java.lang.Object.hashCode() overrides System.Object.GetHashCode(). > > Regards, > Jeroen > > > -----Original Message----- > From: xiang liu [mailto:sea...@gm...] > Sent: Monday, May 09, 2011 9:24 AM > To: Ikv...@li... > Subject: [Ikvm-developers] HashMap Performance Issue > > Hi, > > I am looking at a HashMap performance issue. In the Java > code, the key > used in the Hashmap has its hashCode overridden. But when I > looked into > the reversed C# code of java.util.HashMap implementation. > Since the Key > is java.lang.Object, the overridden version is not used, see > below. It > actuall calls > > Object.instancehelper_hashCode. which calls GetHashCode() in > ture if the > object is not a String, equals method has the same issue in > HashMap .NET > implementation. > > [MethodImpl(MethodImplOptions.NoInlining), > Signature("(Ljava/lang/Object;)TV;"), LineNumberTable(new > byte[] { 160, > 0xc9, 0x63, 0x69, 0x6c, 0x75, 0xa3, 0x7d, 0xe7, 0x3d, 0xe9, > 0x45 })] > public override object get(object key) { > if (key == null) > { > return this.getForNullKey(); > } > int num = hash(Object.instancehelper_hashCode(key)); > for (Entry entry = this.table[indexFor(num, > this.table.Length)]; > entry != null; entry = entry.next) > { > object obj2; > if ((entry.hash == num) && (((obj2 = entry.key) == > key) || > Object.instancehelper_equals(key, obj2))) > { > return entry.value; > } > } > return null; > } > > > I would want the .NET version use the same hashCode and > equals function, > but I have no idea of resolving this issue, Is this a bug or > some issue > we already know? Could a map.xml be used to preserve hashCode > method > which means no rediection of the call? > > Any idea? Please help. > > Thanks, > > Sean > > ------------------------------------------------------------- > ----------- > ------ > WhatsUp Gold - Download Free Network Management Software The > most > intuitive, comprehensive, and cost-effective network > management toolset > available today. Delivers lowest initial acquisition cost > and overall > TCO of any competing solution. > http://p.sf.net/sfu/whatsupgold-sd > _______________________________________________ > Ikvm-developers mailing list > Ikv...@li... > https://lists.sourceforge.net/lists/listinfo/ikvm-developers > > > |
From: Sean L. <sea...@gm...> - 2011-05-09 08:33:48
|
Hi, Jeroen, You were right, Refector did not show it correctly. There must be something else which does not work correctly to cause the performance issue, my use case is too complicated, I will try to provide a similar but simple test case. Thanks a lot. Sean On 5/9/2011 4:00 PM, Jeroen Frijters wrote: > Hi, > > Reflector is not a helpful tool to understand IKVM.NET, it does not accurately reflect the IL. Use ILDASM instead. > > Here's what ILDASM shows for java.lang.Object.hashCode(): > > .method public hidebysig newslot strict virtual > instance int32 hashCode() cil managed > { > .override [mscorlib]System.Object::GetHashCode > .maxstack 8 > IL_0000: ldarg.0 > IL_0001: call instance int32 [mscorlib]System.Object::GetHashCode() > IL_0006: ret > } > > The relevant line is ".override [mscorlib]System.Object::GetHashCode". > > If you have a performance problem, please try to provide an isolated test case, that gives the highest chance of getting it improved. > > Regards, > Jeroen > >> -----Original Message----- >> From: Sean Liu [mailto:sea...@gm...] >> Sent: Monday, May 09, 2011 9:56 AM >> To: Jeroen Frijters >> Cc: Ikv...@li... >> Subject: Re: [Ikvm-developers] HashMap Performance Issue >> >> Hi, Jeroen, >> >> Thanks for your quick reply. >> >> I am not sure I understood what you meant. Here is the code I copied >> from .NET Reflector. Both of the methods simply call >> System.Object.GetHashCode(). >> >> >> [HideFromJava >> <http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://IKVM.Runt >> ime:0.47.4142.0/IKVM.Attributes.HideFromJavaAttribute/.ctor%28%29> , >> EditorBrowsable >> <http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://System:2. >> 0.0.0:b77a5c561934e089/System.ComponentModel.EditorBrowsableAttribute/.c >> tor%28System.ComponentModel.EditorBrowsableState%29> >> (EditorBrowsableState >> <http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://System:4. >> 0.0.0:b77a5c561934e089/System.ComponentModel.EditorBrowsableState> >> .Never >> <http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://System:4. >> 0.0.0:b77a5c561934e089/System.Com >> ponentModel.EditorBrowsableState/Never> )] public int >> <http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib: >> 2.0.0.0:b77a5c561934e089/System.Int32> GetHashCode >> <http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://IKVM.Open >> JDK.Core:0.47.4142.0/java.lang.Object/GetHashCode%28%29:Int32> () { >> return this.GetHashCode >> <http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib: >> 2.0.0.0:b77a5c561934e089/System.Object/GetHashCode%28%29:Int32> (); } >> >> public virtual int >> <http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib: >> 2.0.0.0:b77a5c561934e089/System.Int32> hashCode >> <http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://IKVM.Open >> JDK.Core:0.47.4142.0/java.lang.Object/hashCode%28%29:Int32> () { >> return base.GetHashCode >> <http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib: >> 2.0.0.0:b77a5c561934e089/System.Object/GetHashCode%28%29:Int32> (); } >> >> Has anyone reported that IKVM HashMap is much slower than the original >> java implementation. In my case, IKVM version took 5 times as the Java >> version did. >> >> Thanks, >> >> Sean >> >> On 5/9/2011 3:41 PM, Jeroen Frijters wrote: >> >> Hi, >> >> The overridden version *is* used, because >> java.lang.Object.hashCode() overrides System.Object.GetHashCode(). >> >> Regards, >> Jeroen >> >> >> -----Original Message----- >> From: xiang liu [mailto:sea...@gm...] >> Sent: Monday, May 09, 2011 9:24 AM >> To: Ikv...@li... >> Subject: [Ikvm-developers] HashMap Performance Issue >> >> Hi, >> >> I am looking at a HashMap performance issue. In the Java >> code, the key >> used in the Hashmap has its hashCode overridden. But when I >> looked into >> the reversed C# code of java.util.HashMap implementation. >> Since the Key >> is java.lang.Object, the overridden version is not used, see >> below. It >> actuall calls >> >> Object.instancehelper_hashCode. which calls GetHashCode() in >> ture if the >> object is not a String, equals method has the same issue in >> HashMap .NET >> implementation. >> >> [MethodImpl(MethodImplOptions.NoInlining), >> Signature("(Ljava/lang/Object;)TV;"), LineNumberTable(new >> byte[] { 160, >> 0xc9, 0x63, 0x69, 0x6c, 0x75, 0xa3, 0x7d, 0xe7, 0x3d, 0xe9, >> 0x45 })] >> public override object get(object key) { >> if (key == null) >> { >> return this.getForNullKey(); >> } >> int num = hash(Object.instancehelper_hashCode(key)); >> for (Entry entry = this.table[indexFor(num, >> this.table.Length)]; >> entry != null; entry = entry.next) >> { >> object obj2; >> if ((entry.hash == num)&& (((obj2 = entry.key) == >> key) || >> Object.instancehelper_equals(key, obj2))) >> { >> return entry.value; >> } >> } >> return null; >> } >> >> >> I would want the .NET version use the same hashCode and >> equals function, >> but I have no idea of resolving this issue, Is this a bug or >> some issue >> we already know? Could a map.xml be used to preserve hashCode >> method >> which means no rediection of the call? >> >> Any idea? Please help. >> >> Thanks, >> >> Sean >> >> ------------------------------------------------------------- >> ----------- >> ------ >> WhatsUp Gold - Download Free Network Management Software The >> most >> intuitive, comprehensive, and cost-effective network >> management toolset >> available today. Delivers lowest initial acquisition cost >> and overall >> TCO of any competing solution. >> http://p.sf.net/sfu/whatsupgold-sd >> _______________________________________________ >> Ikvm-developers mailing list >> Ikv...@li... >> https://lists.sourceforge.net/lists/listinfo/ikvm-developers >> >> >> > |