Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / April 2006

Tip: Looking for answers? Try searching our database.

Force Rejit of a method

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dinis Cruz - 20 Apr 2006 00:21 GMT
Hello, Is there a way to force the ReJit of a method?

One of the demos that I do in my 'Rooting the CLR' presentation is to do
real time MSIL patching.

The problem is that I need to apply the 'patches' before the JIT has
occurred, unless (hence my question) I am able to dynamically either:
    - ReJit a method
    - Mark a method as not Jitted (whereby it is Jitted the next time that
method is invoked)

Looking at the symbols of a CLR dll (can't remember the name now) I
know that there is a internal way to do this on the CLR (after all (if I
remember correctly) that is one of the methods available to the GC to
reclaim memory).

Thanks,

Dinis Cruz
Owasp .Net Project
www.owasp.net
Laura T. - 20 Apr 2006 15:42 GMT
I don't know how you "patch" the methods, but I have used MethodRental class
from System.Reflection.Emit.
It has JitImmediate and JitOnDemand methods to recompile methods.

Laura.

> Hello, Is there a way to force the ReJit of a method?
>
[quoted text clipped - 17 lines]
> Owasp .Net Project
> www.owasp.net
Dinis Cruz - 24 Apr 2006 22:40 GMT
Hello Laura,

There are two types of patches that I do in my demos (both using direct
memory writes (after unlocking the relevant memory pages)).

1) Unmanaged patch - Re-Writing Assembly code directly on the method's
code. Used for example to patch the CLR so that you can load 'corrupted
Strong Named Assemblies'

2) MSIL patch - Re-Write MSIL on .Net methods. If you know the exact
location of the method this is a simple case of replacing the existing
MSIL code with the new one (although at the moment I am limited to the
size of the original MSIL code (there are some guys who did a very
interesting research on 'self healing code' which had a solution for
this problem))

Regarding JitImmediate and JitOnDemand, I have not looked at them, but I
don't think they will allow me to do what I want to do (which is to
patch managed methods that are already loaded in memory)

Best Regards

Dinis Cruz
Owasp .Net Project
www.owasp.net

> I don't know how you "patch" the methods, but I have used MethodRental class
> from System.Reflection.Emit.
[quoted text clipped - 23 lines]
>> Owasp .Net Project
>> www.owasp.net
cody - 25 Apr 2006 09:10 GMT
IMO you cannot jit a method with is already loaded you first have to unload
the assembly where the code belongs to and then reload it with
assembly.load.

> Hello Laura,
>
[quoted text clipped - 50 lines]
>>> Owasp .Net Project
>>> www.owasp.net
drjflam@gmail.com - 29 Apr 2006 01:26 GMT
Use ICorProfilerInfo::SetFunctionReJIT().

-John
http://www.iunknown.com
Dinis Cruz - 30 Apr 2006 00:48 GMT
Does this works on an application where the .Net Profiler is not activated?

I have used the .Net Profiler in the past (see the .NetMon tool I wrote
for Foundstone) and the biggest annoyance that I had, was the fact that
I could not use the Profiler functionality (for example the ability to
trace function flow execution) on projects that where not started with
the Profiler activated.

Dinis Cruz
Owasp .Net Project
www.owasp.net

> Use ICorProfilerInfo::SetFunctionReJIT().
>
> -John
> http://www.iunknown.com

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.