Note also:
V8 generates extra debugging code in debug builds.  You can enable
disassembly for release builds by passing 'disassembler=on' to the SCons
build or defining the preprocessor macro ENABLE_DISASSEMBLER.

Much of the d8 shell is implemented in
JS.  If you want to inspect generated code and don't want to see the
disassembly for the shell functions, you can try instead using the
shell sample in v8/samples.

If you want to see the comments
emitted in the code, you have to use a debug build and pass the --debug-code
flag.

2009/6/2 Meryl Silverburgh <[email protected]>

>
> 2009/5/28 Søren Gjesse <[email protected]>:
> > The flag is --print-code which will print all code generated, and the
> flag
> > in only available for a debug build. When your first functions are
> compiled
> > you will see compilation of some internal stuff, and as a lot of the
> > builtins as lazily compiled you will see auxiliary code generation first
> > time some builtins are used. E.g. the function 'function
> > f(){"sss".indexOf('s')}' when run for the first time will cause parts of
> the
> > String implementation to get compiled as well (large parts of the String
> > implementation is in JavaScript). To avoid this and to see the code for
> your
> > functions "immediately" you can add the --nolazy flag as well to turn off
> > lazy compilation. Without lazy compilation all functions will be egerly
> > compiled when added and not on first use.
> >
>
> Thank you. Soren.
> I open v8_shell using '-print-code -nolazy' options.  And I just enter
> 'function f(){"sss".indexOf('s')}' at the d8 prompt.
>
> BUt why do I see 3 'Raw source' output below?
> --- Raw source ---
> (){"sss".indexOf('s')}
>
> --- Raw source ---
> function f(){"sss".indexOf('s')}
>
>
> --- Raw source ---
>
> ({"seq":3,"type":"event","event":"afterCompile","success":true,"body":{"script":{"handle":1,"type":"script","name":"(d8)","id":27,"lineOffset":0,"columnOffset":0,"lineCount":1,"source":"function
>
> f(){\"sss\".indexOf('s')}\n","sourceLength":33,"scriptType":2,"context":{"ref":0},"text":"(d8)
> (lines: 1)"}},"refs":[{"handle":0,"type":"context","text":"#<a
> ContextMirror>"}],"running":true})
>
>
>
> d8> function f(){"sss".indexOf('s')}
> --- Raw source ---
> (){"sss".indexOf('s')}
>
>
> --- Code ---
> kind = FUNCTION
> name = f
> Instructions (size = 124)
> 0x182a7c0     0  f7c701000000   test edi,0x1
> 0x182a7c6     6  0f850d000000   jnz 25  (0x182a7d9)
> 0x182a7cc    12  50             push eax
> 0x182a7cd    13  6828d82000     push 0x20d828
> 0x182a7d2    18  6a00           push 0x0
> 0x182a7d4    20  e827d7c4fe     call 0x477f00                ;; debug:
> statement 10
>                                                             ;; code:
> STUB, Runtime, RuntimeStub_Abort
> 0x182a7d9    25  8b47ff         mov eax,[edi+0xff]
> 0x182a7dc    28  8078079d       cmpb [eax+0x7],0x9d
> 0x182a7e0    32  0f840d000000   jz 51  (0x182a7f3)
> 0x182a7e6    38  50             push eax
> 0x182a7e7    39  6864d82000     push 0x20d864
> 0x182a7ec    44  6a00           push 0x0
> 0x182a7ee    46  e80dd7c4fe     call 0x477f00                ;; code:
> STUB, Runtime, RuntimeStub_Abort
> 0x182a7f3    51  55             push ebp
> 0x182a7f4    52  8bec           mov ebp,esp
> 0x182a7f6    54  56             push esi
> 0x182a7f7    55  57             push edi
> 0x182a7f8    56  3b25e8b32600   cmp esp,[0x26b3e8]
> 0x182a7fe    62  0f822e000000   jc 114  (0x182a832)
> 0x182a804    68  83ec0c         sub esp,0xc
> 0x182a807    71  c745f47d1f6001 mov [ebp+0xf4],0x1601f7d     ;;
> object: 0x1601f7d <String[7]: indexOf>
> 0x182a80e    78  c745f07de86001 mov [ebp+0xf0],0x160e87d     ;;
> object: 0x160e87d <String[3]: sss>
> 0x182a815    85  c745ecc5106001 mov [ebp+0xec],0x16010c5     ;;
> object: 0x16010c5 <String[1]: s>
> 0x182a81c    92  e8ffd8c4fe     call 0x478120                ;; debug:
> statement 13
>                                                             ;; debug:
> position 19
>                                                             ;; code:
> CALL_IC, UNINITIALIZED, argc = 1
> 0x182a821    97  8b75fc         mov esi,[ebp+0xfc]
> 0x182a824   100  83c404         add esp,0x4
> 0x182a827   103  b835016001     mov eax,0x1600135            ;;
> object: 0x1600135 <undefined>
> 0x182a82c   108  8be5           mov esp,ebp                  ;; debug:
> statement 32
>                                                             ;; js return
> 0x182a82e   110  5d             pop ebp
> 0x182a82f   111  c20400         ret 0x4
> 0x182a832   114  e829dcc4fe     call 0x478460                ;; debug:
> statement 10
>                                                             ;; code:
> STUB, StackCheck, minor: 0
> 0x182a837   119  8b7df8         mov edi,[ebp+0xf8]
> 0x182a83a   122  ebc8           jmp 68  (0x182a804)
>
> RelocInfo (size = 20)
> 0x182a7d4  statement position  (10)
> 0x182a7d5  code target (STUB)  (0x477f00)
> 0x182a7ef  code target (STUB)  (0x477f00)
> 0x182a80a  embedded object  (0x1601f7d <String[7]: indexOf>)
> 0x182a811  embedded object  (0x160e87d <String[3]: sss>)
> 0x182a818  embedded object  (0x16010c5 <String[1]: s>)
> 0x182a81c  statement position  (13)
> 0x182a81c  position  (19)
> 0x182a81d  code target (CALL_IC)  (0x478120)
> 0x182a828  embedded object  (0x1600135 <undefined>)
> 0x182a82c  statement position  (32)
> 0x182a82c  js return
> 0x182a832  statement position  (10)
> 0x182a833  code target (STUB)  (0x478460)
>
> --- Raw source ---
> function f(){"sss".indexOf('s')}
>
>
> --- Code ---
> kind = FUNCTION
> Instructions (size = 99)
> 0x182a8a0     0  f7c701000000   test edi,0x1
> 0x182a8a6     6  0f850d000000   jnz 25  (0x182a8b9)
> 0x182a8ac    12  50             push eax
> 0x182a8ad    13  6828d82000     push 0x20d828
> 0x182a8b2    18  6a00           push 0x0
> 0x182a8b4    20  e847d6c4fe     call 0x477f00                ;; debug:
> statement 0
>                                                             ;; code:
> STUB, Runtime, RuntimeStub_Abort
> 0x182a8b9    25  8b47ff         mov eax,[edi+0xff]
> 0x182a8bc    28  8078079d       cmpb [eax+0x7],0x9d
> 0x182a8c0    32  0f840d000000   jz 51  (0x182a8d3)
> 0x182a8c6    38  50             push eax
> 0x182a8c7    39  6864d82000     push 0x20d864
> 0x182a8cc    44  6a00           push 0x0
> 0x182a8ce    46  e82dd6c4fe     call 0x477f00                ;; code:
> STUB, Runtime, RuntimeStub_Abort
> 0x182a8d3    51  55             push ebp
> 0x182a8d4    52  8bec           mov ebp,esp
> 0x182a8d6    54  56             push esi
> 0x182a8d7    55  57             push edi
> 0x182a8d8    56  6879084501     push 0x1450879               ;;
> object: 0x1450879 <FixedArray[2]>
> 0x182a8dd    61  56             push esi
> 0x182a8de    62  6a00           push 0x0
> 0x182a8e0    64  e83b3ec5fe     call 0x47e720                ;; code:
> STUB, Runtime, RuntimeStub_DeclareGlobals
> 0x182a8e5    69  3b25e8b32600   cmp esp,[0x26b3e8]
> 0x182a8eb    75  0f820b000000   jc 92  (0x182a8fc)
> 0x182a8f1    81  b835016001     mov eax,0x1600135            ;;
> object: 0x1600135 <undefined>
> 0x182a8f6    86  8be5           mov esp,ebp                  ;; debug:
> statement 33
>                                                             ;; js return
> 0x182a8f8    88  5d             pop ebp
> 0x182a8f9    89  c20400         ret 0x4
> 0x182a8fc    92  e85fdbc4fe     call 0x478460                ;; debug:
> statement 0
>                                                             ;; code:
> STUB, StackCheck, minor: 0
> 0x182a901    97  ebee           jmp 81  (0x182a8f1)
>
> RelocInfo (size = 14)
> 0x182a8b4  statement position  (0)
> 0x182a8b5  code target (STUB)  (0x477f00)
> 0x182a8cf  code target (STUB)  (0x477f00)
> 0x182a8d9  embedded object  (0x1450879 <FixedArray[2]>)
> 0x182a8e1  code target (STUB)  (0x47e720)
> 0x182a8f2  embedded object  (0x1600135 <undefined>)
> 0x182a8f6  statement position  (33)
> 0x182a8f6  js return
> 0x182a8fc  statement position  (0)
> 0x182a8fd  code target (STUB)  (0x478460)
>
> --- Raw source ---
>
> ({"seq":3,"type":"event","event":"afterCompile","success":true,"body":{"script":{"handle":1,"type":"script","name":"(d8)","id":27,"lineOffset":0,"columnOffset":0,"lineCount":1,"source":"function
>
> f(){\"sss\".indexOf('s')}\n","sourceLength":33,"scriptType":2,"context":{"ref":0},"text":"(d8)
> (lines: 1)"}},"refs":[{"handle":0,"type":"context","text":"#<a
> ContextMirror>"}],"running":true})
>
> --- Code ---
> kind = FUNCTION
> Instructions (size = 148)
> 0x182a960     0  f7c701000000   test edi,0x1
> 0x182a966     6  0f850d000000   jnz 25  (0x182a979)
> 0x182a96c    12  50             push eax
> 0x182a96d    13  6828d82000     push 0x20d828
> 0x182a972    18  6a00           push 0x0
> 0x182a974    20  e887d5c4fe     call 0x477f00                ;; debug:
> statement 0
>                                                             ;; code:
> STUB, Runtime, RuntimeStub_Abort
> 0x182a979    25  8b47ff         mov eax,[edi+0xff]
> 0x182a97c    28  8078079d       cmpb [eax+0x7],0x9d
> 0x182a980    32  0f840d000000   jz 51  (0x182a993)
> 0x182a986    38  50             push eax
> 0x182a987    39  6864d82000     push 0x20d864
> 0x182a98c    44  6a00           push 0x0
> 0x182a98e    46  e86dd5c4fe     call 0x477f00                ;; code:
> STUB, Runtime, RuntimeStub_Abort
> 0x182a993    51  55             push ebp
> 0x182a994    52  8bec           mov ebp,esp
> 0x182a996    54  56             push esi
> 0x182a997    55  57             push edi
> 0x182a998    56  b835016001     mov eax,0x1600135            ;;
> object: 0x1600135 <undefined>
> 0x182a99d    61  50             push eax
> 0x182a99e    62  3b25e8b32600   cmp esp,[0x26b3e8]
> 0x182a9a4    68  0f8240000000   jc 138  (0x182a9ea)
> 0x182a9aa    74  8b7f17         mov edi,[edi+0x17]
> 0x182a9ad    77  8b471f         mov eax,[edi+0x1f]
> 0x182a9b0    80  3d35016001     cmp eax, 0x1600135           ;;
> object: 0x1600135 <undefined>
> 0x182a9b5    85  0f8414000000   jz 111  (0x182a9cf)
> 0x182a9bb    91  83ec04         sub esp,0x4
> 0x182a9be    94  8945f0         mov [ebp+0xf0],eax
> 0x182a9c1    97  e8fab5c6fe     call 0x495fc0                ;; code:
> STUB, Runtime, RuntimeStub_CloneLiteralBoilerplate
> 0x182a9c6   102  8945f4         mov [ebp+0xf4],eax
> 0x182a9c9   105  8be5           mov esp,ebp                  ;; js return
> 0x182a9cb   107  5d             pop ebp
> 0x182a9cc   108  c20400         ret 0x4
> 0x182a9cf   111  83ec0c         sub esp,0xc
> 0x182a9d2   114  897df0         mov [ebp+0xf0],edi
> 0x182a9d5   117  c745ec0c000000 mov [ebp+0xec],0xc
> 0x182a9dc   124  c745e8d9d54601 mov [ebp+0xe8],0x146d5d9     ;;
> object: 0x146d5d9 <FixedArray[14]>
> 0x182a9e3   131  e878a2c5fe     call 0x484c60                ;; code:
> STUB, Runtime, RuntimeStub_CreateObjectLiteralBoilerplate
> 0x182a9e8   136  ebd1           jmp 91  (0x182a9bb)
> 0x182a9ea   138  e871dac4fe     call 0x478460                ;; code:
> STUB, StackCheck, minor: 0
> 0x182a9ef   143  8b7df8         mov edi,[ebp+0xf8]
> 0x182a9f2   146  ebb6           jmp 74  (0x182a9aa)
>
> RelocInfo (size = 12)
> 0x182a974  statement position  (0)
> 0x182a975  code target (STUB)  (0x477f00)
> 0x182a98f  code target (STUB)  (0x477f00)
> 0x182a999  embedded object  (0x1600135 <undefined>)
> 0x182a9b1  embedded object  (0x1600135 <undefined>)
> 0x182a9c2  code target (STUB)  (0x495fc0)
> 0x182a9c9  js return
> 0x182a9df  embedded object  (0x146d5d9 <FixedArray[14]>)
> 0x182a9e4  code target (STUB)  (0x484c60)
> 0x182a9eb  code target (STUB)  (0x478460)
>
> d8>
>
>
>
>
> > Regards,
> > Søren
> >
> > On Wed, May 27, 2009 at 19:13, Mikhail Naganov <[email protected]>
> wrote:
> >>
> >> Actually, I don't see any switch in shell to print disassembler dump,
> >> but you can look into test/cctest/test-log-ia32.cc to see how it can
> >> be programmed.
> >>
> >> In a debug build, you can do the following:
> >>
> >>  v8::internal::Handle<v8::internal::JSFunction> func =
> >> CompileFunction(<your code>);
> >>  v8::internal::Code* func_code = func->code();
> >>  func_code->Print();
> >>
> >> But remember that functions are compiled lazily. If you've declared a
> >> function, it doesn't get compiled until the first call to it. Put all
> >> your code into top-level script if you want it to be compiled
> >> immediately.
> >>
> >> On Wed, May 27, 2009 at 20:22, silverburgh <[email protected]
> >
> >> wrote:
> >> >
> >> >
> >> > In here,
> >> > http://code.google.com/apis/v8/design.html
> >> > it dumps the machine code for 'point.x'.
> >> >
> >> > How can I dump the machine code for my JS file that I give to V8?
> >> >
> >> > Thank you.
> >> >
> >> >
> >> >
> >> > >
> >> >
> >>
> >> >>
> >
> >
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to