Re: Erlang JIT and loaded code
Lukas Larsson <[email protected]> Tue, 26 Apr 2022 09:57:09 +0200
| Newsgroups | gmane.comp.lang.erlang.general |
|---|---|
| Message-ID | <CAP3zBqNzJq21E9jmKZw4XyMwq=eVGH_yf9XeWzJsr7q-qGO5kQ@mail.gmail.com> |
--000000000000d9770105dd8a0a65 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Apr 26, 2022 at 7:36 AM Vitor Rocha <[email protected]> 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. > Em seg., 25 de abr. de 2022 =C3=A0s 06:13, Lukas Larsson <[email protected]= g> > escreveu: > >> Hello! >> >> On Tue, Apr 19, 2022 at 7:17 AM Vitor Rocha <[email protected]> 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 g= et >> 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 af= ter >> the module is loaded. >> >> >>> >>> -- >>> Atenciosamente, >>> Vitor Rocha da Silva >>> >> > > -- > Atenciosamente, > Vitor Rocha da Silva > --000000000000d9770105dd8a0a65 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div dir=3D"ltr"><br></div><br><div class=3D"gmail_quote">= <div dir=3D"ltr" class=3D"gmail_attr">On Tue, Apr 26, 2022 at 7:36 AM Vitor= Rocha <<a href=3D"mailto:[email protected]">[email protected]</a>&g= t; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0p= x 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div d= ir=3D"ltr"><div>I managed to get the code size (I suppose) from internal st= ructures:<br></div><div><ul><li>erl_module_instance->code_length (for em= ulator and asm)</li><li>erl_module_instance->hipe_code->text_segment_= size (for HiPE and ErLLVM)</li></ul><div>Does that make sense or are those = values unrelated?<br></div></div></div></blockquote><div><br></div><div>I t= hink those values make sense to compare.</div><div><br></div><div>Looking t= hrough the code I actually found a way to get the size of the modules. If y= ou do Ctrl+C to enter break mode and then type `l` you will get a listing o= f all modules and their size in bytes. Not sure if that functionality works= for hipe code or not.</div><div><br></div><blockquote class=3D"gmail_quote= " style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);= padding-left:1ex"><div dir=3D"ltr"><div><div></div></div></div><br><div cla= ss=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">Em seg., 25 de abr= . de 2022 =C3=A0s 06:13, Lukas Larsson <<a href=3D"mailto:[email protected]= rg" target=3D"_blank">[email protected]</a>> escreveu:<br></div><blockquo= te class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px = solid rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr"><div>Hello!</div>= <br><div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Tue= , Apr 19, 2022 at 7:17 AM Vitor Rocha <<a href=3D"mailto:vitor.vrs@gmail= .com" target=3D"_blank">[email protected]</a>> wrote:<br></div><blockq= uote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1p= x solid rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr"><div>(1) how do= I know if my code is actually being executed as interpreted or native?</di= v></div></blockquote><div><br></div><div>All code loaded from .beam files a= re run natively if the VM supports JIT compilation.</div><div>=C2=A0</div><= blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-l= eft:1px solid rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr"><div>(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 s= witched to native?<br></div></div></blockquote><div><br></div><div>There is= no=C2=A0difference in how it is compiled, it will always be translated int= o native code when loaded.</div><div>=C2=A0</div><blockquote class=3D"gmail= _quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204= ,204);padding-left:1ex"><div dir=3D"ltr"><div></div><div>(3) Where is store= d the generated beamasm native code? I would like to get its size in bytes?= <br></div></div></blockquote><div><br></div><div>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 s= ingle module, but you can get a relatively close value by checking what `er= lang:memory(code)` returns before and after the module is loaded.</div><div= >=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px = 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir=3D"= ltr"><div><br></div><div>-- <br><div dir=3D"ltr"><span style=3D"font-family= :"trebuchet ms",sans-serif">Atenciosamente,<br>Vitor Rocha da Sil= va</span><br></div></div></div> </blockquote></div></div> </blockquote></div><br clear=3D"all"><br>-- <br><div dir=3D"ltr"><span styl= e=3D"font-family:"trebuchet ms",sans-serif">Atenciosamente,<br>Vi= tor Rocha da Silva</span><br></div> </blockquote></div></div> --000000000000d9770105dd8a0a65--