Erlang JIT and loaded code

61 views
Skip to first unread message

Vitor Rocha

unread,
Apr 19, 2022, 1:18:03 AM4/19/22
to erlang-q...@erlang.org
Hello,

Given the code is compiled to native during startup time with the new JIT (beamasm) approach, (1) how do I know if my code is actually being executed as interpreted or native?

(2) If I compile a module inside Erlang's shell, using the `c:c/1` function, is the module going to be compiled to native too? Will its execution be switched to native?

(3) Where is stored the generated beamasm native code? I would like to get its size in bytes?

--
Atenciosamente,
Vitor Rocha da Silva

Lukas Larsson

unread,
Apr 25, 2022, 5:13:35 AM4/25/22
to Vitor Rocha, Erlang Questions
Hello!

On Tue, Apr 19, 2022 at 7:17 AM Vitor Rocha <vito...@gmail.com> wrote:
(1) how do I know if my code is actually being executed as interpreted or native?

All code loaded from .beam files are run natively if the VM supports JIT compilation.
 
(2) If I compile a module inside Erlang's shell, using the `c:c/1` function, is the module going to be compiled to native too? Will its execution be switched to native?

There is no difference in how it is compiled, it will always be translated into native code when loaded.
 
(3) Where is stored the generated beamasm native code? I would like to get its size in bytes?

It is stored in memory of the VM. You can get a file dump of the native code by passing `+JDdump true` when starting `erl`. There is no way to get the loaded memory size of a single module, but you can get a relatively close value by checking what `erlang:memory(code)` returns before and after the module is loaded.

Vitor Rocha

unread,
Apr 26, 2022, 1:35:59 AM4/26/22
to Lukas Larsson, Erlang Questions
Thanks for the answer, Lukas.

Giving a bit more context: I'm doing a benchmarking research on Erlang JIT, similar to what ErLLVM did.

I managed to get the code size (I suppose) from internal structures:
  • erl_module_instance->code_length (for emulator and asm)
  • erl_module_instance->hipe_code->text_segment_size (for HiPE and ErLLVM)
Does that make sense or are those values unrelated?

Leo Liu

unread,
Apr 26, 2022, 2:12:04 AM4/26/22
to erlang-q...@erlang.org
On 2022-04-25 11:13 +0200, Lukas Larsson wrote:
> It is stored in memory of the VM. You can get a file dump of the native
> code by passing `+JDdump true` when starting `erl`. There is no way to get
> the loaded memory size of a single module, but you can get a relatively
> close value by checking what `erlang:memory(code)` returns before and after
> the module is loaded.

+JDdump true is useful but last time I tried it it dumped asm for all
modules in current directory. Has there been any improvements? Thanks.

Leo

Lukas Larsson

unread,
Apr 26, 2022, 3:57:32 AM4/26/22
to Vitor Rocha, Erlang Questions
On Tue, Apr 26, 2022 at 7:36 AM Vitor Rocha <vito...@gmail.com> wrote:
I managed to get the code size (I suppose) from internal structures:
  • erl_module_instance->code_length (for emulator and asm)
  • erl_module_instance->hipe_code->text_segment_size (for HiPE and ErLLVM)
Does that make sense or are those values unrelated?

I think those values make sense to compare.

Looking through the code I actually found a way to get the size of the modules. If you do Ctrl+C to enter break mode and then type `l` you will get a listing of all modules and their size in bytes. Not sure if that functionality works for hipe code or not.

Lukas Larsson

unread,
Apr 26, 2022, 4:05:27 AM4/26/22
to Leo Liu, Erlang Questions
No, there has not been any improvements. One of the limiting factors here is that we must do the dump as the code is loaded, we cannot dump it after the fact. If you have any suggestions about what improvements we should make, please open an issue on github.
 

Leo

Reply all
Reply to author
Forward
0 new messages