[Mono-list] Reference runtime internal variable in managed code
Paolo Molaro
lupus@ximian.com
Thu, 28 Aug 2003 17:08:54 +0200
On 08/26/03 Derek Woo wrote:
> Sorry for being unclear. I am working in the context of adaptive
> optimization. Maybe I would use a small example:
>
> Method mthA {
>
> // Call some method B here
> }
>
> What I want to do is have the JIT patch the code of mthA as it is compiling
> it such that it becomes:
>
> Method mthA {
>
> if (condition) {
> // Call some method C
> }
> else {
> // Call some method B here
> }
> }
Wouldn't it make more sense to just change method C to read:
if (condition) {
call method B;
return;
}
... normal method C code ...
This way you keep code expansion low and it's easier to implement in the
JIT, since it's just stuff you can do in the prolog, for example.
> Now there are some requirement:
> 1. "condition" is a reference to internal data of the runtime, e.g. the
> execution count of a method, or some info that is collected from the
> profiler.
> 2. The condition check is done as "mthA" is actually executing.
>
> Basically, the runtime passed a reference of some data, to a piece of user
> code. And the user code checked that data for some condition.
>
> I can certainly do the patching in "mono_method_to_ir()". But the problem is
> how I can enable such condition check from user code to internal data
> structure of the runtime. And do it quickly.
You can do it in three ways:
*) in mono_method_to_ir () by generating the intermediate code directly
(this also means it will be portable). This is the reccomended way.
*) you can do it in mini-x86.c in emit_prolog: hackish non portable way.
*) you can do it using wrappers, like it's done for some methods in
metadata/marshal.c. It's portable, but you need to generate IL code and
it's more cumbersome and runtime-heavy.
I suggest the first way to do it. You may want to grep for coverage_info
in mini.c to see how a static unmanaged variable is accessed in the
internal representation. There are plenty of examples there on how to
call a method as well.
lupus
--
-----------------------------------------------------------------
lupus@debian.org debian/rules
lupus@ximian.com Monkeys do it better