native CompiledMethod format

0 views
Skip to first unread message

Gerardo Richarte

unread,
Nov 5, 2008, 9:16:49 PM11/5/08
to moebius-proje...@googlegroups.com
Hi all, here I'm sending an email I sent to the Exupery list,
I'm still interested in answers, this time, from a Moebious
perspective :)

=======

Hi, for some time I've been wondering how the native code for
CompiledMethods is arranged, and I have a few specific questions. Any
pointers to info will be very much welcome

Are the native opcodes maintained in Smalltalk objects or in external
memory?

and then:

Generally, how are CompiledMethods fixed after a Garbage Collection?

for example, how are references to other objects handled?
are calls to other methods somehow inlined (I mean, direct calls, not
through lookups), and if so, how are this inlined direct calls solved
when native code moves around (if it's stored in Object Memory)

I know that by reading the code I can learn all this, but my need
for info is not so serious :)

=======

If you are curious on what Exupery does, here's the answer from Bryce:

Native machine code is stored in external memory. This avoids the
problem with the GC moving it and also allows the memory to be
allocated as executable.

Machine code is generated in a ByteArray then copied into the code
cache (external memory) then reallocated by Smalltalk.

======

thanks a lot!
richie

Igor Stasenko

unread,
Nov 6, 2008, 2:17:45 AM11/6/08
to moebius-proje...@googlegroups.com
2008/11/6 Gerardo Richarte <ge...@corest.com>:

>
> Hi all, here I'm sending an email I sent to the Exupery list,
> I'm still interested in answers, this time, from a Moebious
> perspective :)
>
> =======
>
> Hi, for some time I've been wondering how the native code for
> CompiledMethods is arranged, and I have a few specific questions. Any
> pointers to info will be very much welcome
>
> Are the native opcodes maintained in Smalltalk objects or in external
> memory?
>
> and then:
>
> Generally, how are CompiledMethods fixed after a Garbage Collection?
>
> for example, how are references to other objects handled?
> are calls to other methods somehow inlined (I mean, direct calls, not
> through lookups), and if so, how are this inlined direct calls solved
> when native code moves around (if it's stored in Object Memory)
>
> I know that by reading the code I can learn all this, but my need
> for info is not so serious :)
>

You don't have to read a code, just take a look on wiki page:
http://code.google.com/p/moebius-st/wiki/NativeMethods

In short:
a compiled method having own format, and its native code accessing
literals through compiled method instance oop, which held on stack.
This allows to generate position independent code , e.g. you can
relocate the compiled method as any other object.

There are just one issue which need to be dealt with:
once you relocated a method, you need to check if there are return
address held on stack, pointing to this method's body.
But i think this will not cause much problems, since each stack frame
having reference to its method oop, and in this way we can detect if
return pointer needs fixage.

So far, current design shows what we want to achieve, but there is no
GC implementation, no memory manager. All these things need to be
implemented :)

> =======
>
> If you are curious on what Exupery does, here's the answer from Bryce:
>
> Native machine code is stored in external memory. This avoids the
> problem with the GC moving it and also allows the memory to be
> allocated as executable.
>
> Machine code is generated in a ByteArray then copied into the code
> cache (external memory) then reallocated by Smalltalk.
>

Yes, i know how Exupery generates the code (at least most important things).

> ======
>
> thanks a lot!
> richie
>
>
> >
>


--
Best regards,
Igor Stasenko AKA sig.

Igor Stasenko

unread,
Nov 6, 2008, 2:18:56 AM11/6/08
to moebius-proje...@googlegroups.com
> You don't have to read a code, just take a look on wiki page:
> http://code.google.com/p/moebius-st/wiki/NativeMethods

oops, wrong link

a description of compiled methods is here
http://code.google.com/p/moebius-st/wiki/CompiledMethod

Reply all
Reply to author
Forward
0 new messages