dotgnu-general
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [DotGNU]Morphing java code to IL


From: Rhys Weatherley
Subject: Re: [DotGNU]Morphing java code to IL
Date: Sun, 23 Sep 2001 11:47:31 +1000

Gopal V wrote:

>   This code is for bypassing the actual bytecode of the method. I think I may
>   be able to hack this and generate an IL code for each Bytecode . I got stuck
>   there .

You don't want to do this.  Trust me.  JVM bytecode
is very different in structure to IL, even though it looks
similar.  Local variables are the hardest.  IL explicitly
tags locals with their types.  JVM doesn't - the type
is determined by looking for the first place in the
method where the variable is assigned.

To convert into IL, you need to figure out the type to
put into the IL method body.  This involves a deep
amount of dynamic flow analysis that is way, way,
way, beyond the scope of the "image" library.  In
a regular JVM, the bytecoder verifier does this
analysis, and it is a pretty complex piece of code.

>   so how do you add an ILMethodCode attribute to an ILMethod ?.
>   and how do you create a new ILMethodCode ?
>   ( pnet hasn't got an API for making new ILMethodCodes as far as I know )

At present, the caller passes an ILMethodCode
structure to ILMethodGetCode, which fills it in
with the details.  It isn't created by the loader.

Loading method code blocks at load time will cause
severe locality problems on paged virtual memory systems.
As a general rule, you should avoid using a page of
memory until you absolutely need it.  The "method code"
system is designed not to get the body of a method
until absolutely the last minute.

Skipping the attributes is the correct thing for the loader
to do, because it doesn't care about the contents of the
attributes at that point.

What you need to do is remember the start of the attribute
block somewhere in the ILMethod structure.  The "rva"
field can perhaps be used for this purpose.  Then, when
ILMethodGetCode is called, it needs to check for the
IL_META_METHODIMPL_JAVA flag on the method.
If this flag is present, it will parse through the attributes
that start at the RVA, and then return the details.

However, do not attempt to convert the bytecodes into
IL.  Instead, just return the raw code to the caller.  It is
the responsibility of the caller, such as the disassembler,
to interpret the bytecodes appropriately.  I've been
planning for some time to add Java method bodies to
ilasm and ildasm.  I actually want it to work this way,
to support the C# compiler's JVM mode.

If you really want to build a JVM->IL converter, then
do it as a separate program.  It would call the function
ILMethodGetCode to get the Java method body, and
then would perform dynamic flow analysis to figure out
the local variables prior to conversion.  But be warned:
it is a _lot_ harder than it looks.

Cheers,

Rhys.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]