MoarVM

MoarVM

#author(“2018-12-04T10:50:22+00:00”,“game”,“game”)

# MoarVM

# 鍕夊挤銇欍倠

Rakudo and NQP internals

# 銈ゃ兂銈广儓銉笺儷鏂规硶

  • 銇俱仛銇疢ercurial銉儩銈搞儓銉倐銇椼亸銇疓itHub銇嬨倝MoarVM銈掑彇寰
1
% hg clone ssh://one@http://www.cr.ie.u-ryukyu.ac.jp/hg/Members/anatofuz/MoarVM/ (淇濆瓨鍏堛傛寚瀹氥仐銇亜鍫村悎./MoarVM銇仾銈)
  • GitHub銇嬨倝銇牬鍚
1
 % git clone git@github.com:MoarVM/MoarVM.git
  • 浜堛倎銈ゃ兂銈广儓銉笺儷鍏堛伄銉囥偅銉偗銉堛儶銈掍綔銇c仸銇娿亸
  • build
1
% ./Configure.pl --cc /usr/local/x86-cbc/bin/gcc --debug --no-optimize --compiler gcc --prefix=/mnt/dalmore-home/one/src/build_perl6/MoarVM
  • 鍚勩偑銉椼偡銉с兂

    • cc
      • 銈炽兂銉戙偆銉┿伄銉戙偣銈掕ō瀹氥仚銈
    • debug
      • debug銈儣銈枫儳銉
    • compiler
      • 銈炽兂銉戙偆銉┿伄绋銈掓寚瀹氥仚銈
      • gcc, clang, cl銈掋偟銉濄兗銉堛仐銇︺亜銈
    • toolchain
      • “posix”, “gnu”, “bsd” and “msvc"銇儎銉笺儷銉併偋銈ゃ兂銈掗伕鎶炲彲鑳
    • prefix
      • make install銇厛銈掓寚瀹
  • make

1
% make -j 50 && make install

# NQP

Perl6銇偟銉栥偦銉冦儓锛嶱erl6銇疦QP銇ц杩般仌銈屻仸銇勩倠

# build鏂规硶

1
%./Configure.pl --prefix=/mnt/dalmore-home/one/src/build_perl6/nqp --backends=moar --with-moar=/mnt/dalm    ore-home/one/src/build_perl6/MoarVM/bin/moar

銇撱伄commit銉忋儍銈枫儱銇悎銈忋仜銈

銆45ab6e373b4168071a5b3fb806cf37e8d02c13d0

# CbC闁㈤

# CodeSegment銇嬨倝閫氬父銇枹鏁般倰鍛笺伋鍑恒仚闅涖伄纰鸿獚銇欍倠銉濄偆銉炽儓

閫氬父銇枹鏁般亱銈塁odeSegment銇玤oto銇椼仧寰屻伀CodeSegment鍋淬仹閫氬父銇枹鏁般倰鍛笺伋鍑恒仚銇ㄣ偣銈裤儍銈儩銈ゃ兂銈(rst)銇孌ataSegement銇儭銉€儶闋樺煙銈堛倞涓嬨伀銇忋倠鍙兘鎬с亴銇傘倠锛

銈炽兂銉戙偆銉┿伄銉愩偘銇伄銇с偝銉炽儜銈ゃ儵銈掓不銇欍亱DataSegement銈掍竴搴﹂枹鏁般倰绲岀敱銇曘仜銇odeSegment銇Щ琛屻仚銈嬨倛銇嗐伀鏇搞亶鎻涖亪銈

# Original銇畁qp銇嬨倝moarvm銉愩偆銉堛偝銉笺儔銈掑嚭鍔涖仚銈

CbC鍋淬伄nqp銇玞d銇

1
%cbc-tools/create_test2moarvm.zsh t/nativecall

vmtest銇腑銇敓鎴愩仌銈屻倠

銈枫偋銉偣銈儶銉椼儓涓仹銇

1
 ${ORIGIN_NQP}/nqp --target=mbc --output="001-hoge.t.moarvm" 001-hoge.t

銈掑疅琛屻仐銇︺亜銈

# 瀹熻銇椼仸銇勩倠銈儦銈炽兗銉夈倰纰鸿獚銇欍倠鏂规硶

# CbC

CbC銇с伅cbc-interp.cbc銇у畾缇┿仐銇︺亜銈媍bc_*銈儦銈炽兗銉夈伀瀵惧繙銇椼仸銇勩倠銉兗銉併兂 銇撱倢銈夈伅cbc_next绲岀敱銇у懠銇般倢銈嬨伄銇с仢銇撱伀break point銈掓浉銇戙仸dump銇欍倠

1
2
3
4
5
6
7
8
9
(gdb) b cbc_next
Breakpoint 2 at 0x7ffff7560288: file src/core/cbc-interp.cbc, line 61.
(gdb) command 2
Type commands for breakpoint(s) 2, one per line.
End with a line saying just "end".
>p CODES[*(MVMuint16 *)i->cur_op]
>p *(MVMuint16 *)i->cur_op
>c
>end

script銈炽優銉炽儔銈掋亱銇戙仸neter鎶笺仚銇ㄣ儹銈般伀鍑烘潵銈

# Origin

銈儦銈炽兗銉夈伅銉┿儥銉仹椋涖伓銇仹NEXT銇優銈儹銇玠ummy銇枹鏁般倰銇勩倢銇︺仢銇撱伀break point

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
(gdb) b dummy
Function "dummy" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (dummy) pending.
(gdb) command 1
Type commands for breakpoint(s) 1, one per line.
End with a line saying just "end".
>up
>p *(MVMuint16 *)(cur_op)
>c
>end

# 闁㈡暟鍚嶃亱銉愩偆銉堛偝銉笺儔鐣彿銇у紩銇忓牬鍚

nqp鍋淬伄cbc-tools銈掍娇銇

1
2
3
4
$perl trans2opcode.pl 98
   cbc_neg_n
$perl trans2opcode.pl cbc_neg_n
    98

# Moarbytecode銇甦ump

1
%./moar --dump hoge.moar

# MoarVMbytecode銇嬨倝MoarVM銇甦ebug

1
% cbc-tools/debug-moar.sh vmtest/src/001-backend.t.moar

# MoarvmBytecode銇嬨倝銇甆QP銇儐銈广儓

1
2
% cbc-tools/check-nqp-test.sh vmtest/src/001-backend.t.moar
% cbc-tools/check-cbc-nqp-test.sh vmtest/src/001-backend.t.moar

# CbCNQP涓鏂夈儐銈广儓

1
% $cbc-tools/this.sh vmtest/nqp

# NQP(Original)銉嗐偣銉

1
% $cbc-tools/this.sh vmtest/nqp ori

# 銉嗐偣銉堛偒銉愩儸銉冦偢

1
 $ perl cbc-tools/dotest_coverage.pl

# MoarVM銇究鍒┿儎銉笺儷

# 銉囥儛銉冦偓鍐呫仹dissass

1
   MVM_dump_bytecode
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
   (lldb) p MVM_dump_bytecode
   (void (*)(MVMThreadContext *)) $143 = 0x0000000100121b50 
   (libmoar.so`MVM_dump_bytecode at bytecodedump.c:505)
   (lldb) p MVM_dump_bytecode(tc)
   00000      checkarity         2, 2
   00001      param_rp_o         loc_0_obj, 0
   00002      param_rp_o         loc_1_obj, 1
   00003      paramnamesused
        annotation: gen/moar/stage2/QAST.nqp:6682
   00004      decont             loc_2_obj, loc_0_obj
   00005      decont             loc_4_obj, loc_2_obj
   00006      findmeth           loc_3_obj, loc_4_obj, 'node_hash'
   00007      prepargs           Callsite_0
   00008      arg_o              0, loc_2_obj
   00009      invoke_o           loc_2_obj, loc_3_obj
   00010      masttocu           loc_2_obj, loc_1_obj, loc_2_obj
   00011   -> return_o           loc_2_obj
   (lldb)

# 銈广偪銉冦偗銉堛儸銉笺偣銇〃绀

1
   MVM_dump_backtrace 

nqp鍋淬仹error銇椼仧闅涖伀dump銇曘倢銈媌ack trace

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
   
   (gdb) p  MVM_dump_backtrace(tc)
      at gen/moar/stage2/QAST.nqp:6682  (../nqp/src/vm/moar/stage0/QAST.moarvm:assemble_and_load)
    from gen/moar/stage2/NQPHLL.nqp:455  (../nqp/src/vm/moar/stage0/NQPHLL.moarvm:mbc)
    from gen/moar/stage2/NQPHLL.nqp:1794  (../nqp/src/vm/moar/stage0/NQPHLL.moarvm:execute_stage)
    from gen/moar/stage2/NQPHLL.nqp:1830  (../nqp/src/vm/moar/stage0/NQPHLL.moarvm:run)
    from gen/moar/stage2/NQPHLL.nqp:1833  (../nqp/src/vm/moar/stage0/NQPHLL.moarvm:)
    from gen/moar/stage2/NQPHLL.nqp:1819  (../nqp/src/vm/moar/stage0/NQPHLL.moarvm:compile)
    from gen/moar/stage2/NQPHLL.nqp:1519  (../nqp/src/vm/moar/stage0/NQPHLL.moarvm:eval)
    from gen/moar/stage2/NQPHLL.nqp:1453  (../nqp/src/vm/moar/stage0/NQPHLL.moarvm:)
    from gen/moar/stage2/NQPHLL.nqp:1432  (../nqp/src/vm/moar/stage0/NQPHLL.moarvm:interactive)
    from gen/moar/stage2/NQPHLL.nqp:1661  (../nqp/src/vm/moar/stage0/NQPHLL.moarvm:command_eval)
    from gen/moar/stage2/NQPHLL.nqp:1625  (../nqp/src/vm/moar/stage0/NQPHLL.moarvm:command_line)
    from gen/moar/stage2/NQP.nqp:4124  (../nqp/src/vm/moar/stage0/nqp.moarvm:MAIN)
    from gen/moar/stage2/NQP.nqp:4119  (../nqp/src/vm/moar/stage0/nqp.moarvm:<mainline>)
    from <unknown>:1  (../nqp/src/vm/moar/stage0/nqp.moarvm:<main>)
    from <unknown>:1  (../nqp/src/vm/moar/stage0/nqp.moarvm:<entry>)
    $32 = void
Licensed under CC BY-NC-SA 4.0
comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy