Click here to Skip to main content
15,910,358 members
Home / Discussions / C#
   

C#

 
AnswerRe: Is there a way in .NET to access the bytecode/IL/CLR that is currently running? Pin
PIEBALDconsult14-Apr-10 4:31
mvePIEBALDconsult14-Apr-10 4:31 
GeneralRe: Is there a way in .NET to access the bytecode/IL/CLR that is currently running? Pin
blackblizzard14-Apr-10 4:39
blackblizzard14-Apr-10 4:39 
GeneralRe: Is there a way in .NET to access the bytecode/IL/CLR that is currently running? Pin
PIEBALDconsult14-Apr-10 5:08
mvePIEBALDconsult14-Apr-10 5:08 
GeneralRe: Is there a way in .NET to access the bytecode/IL/CLR that is currently running? Pin
blackblizzard14-Apr-10 5:18
blackblizzard14-Apr-10 5:18 
GeneralRe: Is there a way in .NET to access the bytecode/IL/CLR that is currently running? Pin
PIEBALDconsult14-Apr-10 5:29
mvePIEBALDconsult14-Apr-10 5:29 
GeneralRe: Is there a way in .NET to access the bytecode/IL/CLR that is currently running? Pin
blackblizzard14-Apr-10 5:39
blackblizzard14-Apr-10 5:39 
AnswerRe: Is there a way in .NET to access the bytecode/IL/CLR that is currently running? Pin
Daniel Grunwald14-Apr-10 6:03
Daniel Grunwald14-Apr-10 6:03 
GeneralRe: Is there a way in .NET to access the bytecode/IL/CLR that is currently running? [modified] Pin
blackblizzard14-Apr-10 6:32
blackblizzard14-Apr-10 6:32 
Uhm... How did you get into my head? (or maybe they're the only two good options for this Big Grin | :-D )

I was currently thinking about doing a combination of the two things you mention: implementing the profiler API and modifying the bytecode with Cecil whenever a class is loaded. My current idea (not very pretty right now, until I find something better) is:

1. Get notified whenever a class is loaded. The profiler API has a callback method for this.
2. Weave (modify) the class, if I haven't already modified it.
3. Unload the old class.
4. Load the new class. (I think that in order to load it as if it were the old class I need to write it to the .dll and then reload it; I don't need to tell you, this is pretty ugly)

And then forget about monitoring the code because I have already injected the control code into the class.
If could replace the class in a more straightforward way, like you do in Java by implementing a ClassFileTransformer, that would be great. I'd rather not monitor the code and just rewrite classes as they are loaded, but I currently don't know how to do this. Any input on this front?

Daniel Grunwald wrote:
there are some limitations on what metadata you're allowed to change at run-time.

I don't need to change much, just replace the stfld or ldfld instruction with a call to a method that takes care of resolving any possible conflicts, logging, etc.

Daniel Grunwald wrote:

Are you trying to implement software transactional memory for .NET?

Yep.

Daniel Grunwald wrote:
Even using the powerful profiler API, you'll likely run into limitations (e.g. when .NET calls into native code), not to mention performance problems.

Tell me about it, I keep bumping into walls. I wish I had an alternative, but this is a project I was given and I can't really change it. It's an STM in C#. In fact, it's a pre-existing STM, so I don't get much choice on how it works, just on how (how?!?! Roll eyes | :rolleyes: ) I manage to get it to work.

Thanks for your answer. If it wasn't exactly what I was thinking about it would've been really helpful Laugh | :laugh: . (Where were you yesterday before I thought this up? Laugh | :laugh: )




EDIT: I've just found the profiling API callback method JITCompilationStarted, which looks way more appropriate for my purpose than the ClassLoadStarted/ClassLoadFinished ones that I planned to use. According to this resource[^] it will allow me to view and modify the IL before it's JITed, which is exactly what I need. I don't know how I had managed to overlook this method until now. (Granted, I only found out about the profiling API yesterday, but still)
modified on Wednesday, April 14, 2010 1:22 PM

QuestionGet output from console window (which is a different process) Pin
Programm3r13-Apr-10 20:19
Programm3r13-Apr-10 20:19 
AnswerRe: Get output from console window (which is a different process) Pin
Martin Jarvis13-Apr-10 20:44
Martin Jarvis13-Apr-10 20:44 
GeneralRe: Get output from console window (which is a different process) Pin
Programm3r13-Apr-10 20:56
Programm3r13-Apr-10 20:56 
AnswerRe: Get output from console window (which is a different process) Pin
Programm3r13-Apr-10 21:11
Programm3r13-Apr-10 21:11 
AnswerRe: Get output from console window (which is a different process) Pin
PIEBALDconsult14-Apr-10 3:24
mvePIEBALDconsult14-Apr-10 3:24 
Questiondrawing semi transparent boxes over richtextbox Pin
NarVish13-Apr-10 20:16
NarVish13-Apr-10 20:16 
QuestionWindows Forms Application versus Web Application Pin
polycom12313-Apr-10 19:28
polycom12313-Apr-10 19:28 
AnswerRe: Windows Forms Application versus Web Application Pin
Programm3r13-Apr-10 20:23
Programm3r13-Apr-10 20:23 
GeneralRe: Windows Forms Application versus Web Application Pin
polycom12313-Apr-10 20:49
polycom12313-Apr-10 20:49 
AnswerRe: Windows Forms Application versus Web Application Pin
Dan Mos14-Apr-10 3:50
Dan Mos14-Apr-10 3:50 
GeneralRe: Windows Forms Application versus Web Application Pin
polycom12314-Apr-10 18:19
polycom12314-Apr-10 18:19 
GeneralRe: Windows Forms Application versus Web Application Pin
Michael J. Eber16-Apr-10 21:02
Michael J. Eber16-Apr-10 21:02 
Questionhosting control in datagrid cell Pin
Member 59031013-Apr-10 19:20
Member 59031013-Apr-10 19:20 
AnswerRe: hosting control in datagrid cell Pin
Abhinav S13-Apr-10 19:28
Abhinav S13-Apr-10 19:28 
GeneralRe: hosting control in datagrid cell Pin
Member 59031013-Apr-10 19:58
Member 59031013-Apr-10 19:58 
AnswerRe: hosting control in datagrid cell Pin
nagendrathecoder13-Apr-10 21:23
nagendrathecoder13-Apr-10 21:23 
Questionuse the mobile phone as a webcam via bluetooth Pin
aditya58413-Apr-10 19:07
aditya58413-Apr-10 19:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.