This is a mirror of official site: http://jasper-net.blogspot.com/

How to Detect if a Method is Overridden

| Monday, November 22, 2010
Suppose you want to know if (the class of) a particular object overrides a virtual method. For an example of this see OpenJDK's Thread.isCCLOverriden() (line 1573).

In Java the obvious way to do this would be to use reflection. On the CLR there is another way that is both more accurate1 and more efficient.

Here's the MSIL method from IKVM's java.lang.Thread.isCCLOverridden() implementation:

.method private hidebysig static bool isCCLOverridden(class java.lang.Thread A_0) cil managed
{
 ldftn      instance class java.lang.ClassLoader java.lang.Thread::getContextClassLoader()
 ldarg.0
 ldvirtftn  instance class java.lang.ClassLoader java.lang.Thread::getContextClassLoader()
 ceq
 ldftn      instance void java.lang.Thread::setContextClassLoader(class java.lang.ClassLoader)
 ldarg.0
 ldvirtftn  instance void java.lang.Thread::setContextClassLoader(class java.lang.ClassLoader)
 ceq
 and
 ldc.i4.0
 ceq
 ret
}
Instead of running a zillion instructions and accessing a lot of cold data for reflection, this simply leverages the information the JIT already has about virtual methods.

Here's the x86 code this turns into:

 push        ebp
 mov         ebp,esp
 push        esi
 push        ebx
 mov         esi,ecx
 push        258F58h
 mov         ecx,esi
 mov         edx,259240h
 call        JIT_VirtualFunctionPointer
 mov         edx,25DCA0h
 cmp         eax,edx
 sete        bl
 movzx       ebx,bl
 push        2591A0h
 mov         ecx,esi
 mov         edx,259240h
 call        JIT_VirtualFunctionPointer
 mov         edx,25DCB0h
 cmp         eax,edx
 sete        al


Read more: IKVM.NET Weblog

Posted via email from .NET Info

9 comments:

Anonymous said...

The Bowflex is often a quite functional bit of house fitness center
tools.

Also visit my blog; http://www.getfitnstrong.com/adjustable-dumbbells/7-reasons-adjustable-dumbbell-set/

Anonymous said...

This elliptical is capable of dealing with a wide assortment of various body kinds
and sizes, but it certainly will not get the job done for everyone.


Also visit my website; best adjustable dumbbells

Anonymous said...

It is possible to use a steadiness ball in location of a pounds bench, as
well as stability ball can be a wonderful tool for core work
outs, too, so you'll be able to get two in a person duty out of it; again, a moreover if you are tight on space.

My web page ... getfitnstrong.com

Anonymous said...

I'm able to feel my upper overall body acquiring a lot more robust and it truly is showing at the same time.

My web blog - bowflex selecttech 552 adjustable dumbbells

Anonymous said...

As being the globe receives progressively more busier, it is
really hard for us as really hard functioning persons to find time for
you to head into the health and fitness center to exercise.



Look into my web page bowflex selecttech 552 adjustable dumbbells pair

Anonymous said...

When you come to feel the necessity to hold on for stability,
cut down your pace and incline until you can stroll or run typically,
just as you'd outside.

My web-site; bowflex adjustable dumbbells

Anonymous said...

Also I would attempt to try to eat protein such as meat should you be not a vegetarian right after you're finished lifting weights as well as drink protein powder with water not milk with as minor body fat as you possibly can inside the protein, like whole whey protein powder and use a blender.

Here is my blog post; Website URL

Anonymous said...

Just mount in excess of the rope about the puller in the way you can pull it by means of
both ends in reverse path after which applying one particular arm you
can pull it together though pulley shall give stiff resistance on the other arm.


Here is my blog post :: bowflex dumbbells

Anonymous said...

The method is a thing that you could exercise with your lifestyle and never just read about it.


my website :: Get the facts