comparison slides/2018/05/08/slide.md @ 43:fc5259b6167e

auto-Update generated slides by script
author Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Mon, 14 May 2018 15:36:32 +0900
parents 7c19d3c0d027
children
comparison
equal deleted inserted replaced
42:7c19d3c0d027 43:fc5259b6167e
2 author: Takahiro Shimizu 2 author: Takahiro Shimizu
3 profile: 3 profile:
4 lang: Japanese 4 lang: Japanese
5 5
6 6
7 # 研究目的
8 - Perl5の後継言語として開発されているPerl6はMoarVMと呼ばれるVMを搭載している.
9 - Perl6はMoarVM,JVM,JavaScript上で動くRakudoと呼ばれる実装と,コンパイラ開発者用のサブセットであるNQPが主な実装となっている.
10 - 現在Perl6及びMoarVMは全体的な速度がPerl5と比較し低下しており,実務として利用できるレベルに達していない.
11 - さらにPerl6の実装自体巨大なcase-switch文など見通しが悪くなっている.
12 - この問題を解決するために現在当研究室で開発している継続を中心にしたContinuation based Cを用いて改良を行う
13 - CbCの設計理念からVMの実装と親和性が高い事も推測できる為,実際にCbCを用いてどのようにVMが実装できるかを検証する
14
7 # 研究内容 15 # 研究内容
8 - Perl5の後継言語として開発されているPerl6はMoarVMと呼ばれるVMを搭載している. 16 - MoarVMの主にCase文をCbCに書き換える
9 - Perl6はMoarVM,JVM上で動くRakudoと呼ばれる実装と,コンパイラ開発者用のサブセットであるNQPが主な実装となっている. 17 - ちょっと早くしたい
10 - 現在Perl6及びMoarVMは全体的な速度がPerl5と比較し低下しており,実務として利用できるレベルに達していない.
11 - またPerl6の実装自体巨大なcase-switch文など見通しが悪くなっている.
12 - 本研究では継続を中心に開発されたContinuation based Cを用いてMoarVMの改良を検討する.
13 18
14 # 今週の進捗 19 # 今週の進捗
15 20
16 - dalmoreでCbCgccでMoarVM/NQPが動きました 21 - YAPC::EUで発表されたMoarVMの資料を読んでいました
22 - cf. http://www.jnthn.net/papers/2013-yapceu-moarvm.pdf
23 - MoarVMの実装を読み始めました
24 - mercurialにMoarVMをあげました
25 - オープンソースカンファレンスについては何も出来てないです…
26 - 進捗管理君を書いてました
17 27
18 # MoarVMのclone 28 # 6model
19 29
20 - MoarVMをgithubからcloneする 30 - Perl6のオブジェクトパターン
31 - `Object`
32 - `Stable`
33 - How(Meta-object)
34 - REPR
35 - WHAT
36 - WHO
37 - Method キャッシュ
38 - 型キャッシュ
39 - `Flags,owner`
40 - `GC stuff`
41 - `<body>`からなる
42
43 # CbCの書き換え
44
45 - case文の書き換え
46 - なるべく巨大なものを選択
47 - spesh以下のファイルが比較的巨大なcase文
48 - `static void optimize_bb_switch`
49 - `spesh/optimize.c`
50 - 最適化のスイッチ部分
51 - かなり巨大
52 - 他には
53 - `containers.c`
54 - `serialization.c`
55 - unicodeの文字処理部分
56
57 # 書き換えている箇所
58
59 ```c
60 static void optimize_bb_switch(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshBB *bb,
61 MVMSpeshPlanned *p) {
62 MVMSpeshCallInfo arg_info;
63 /* Look for instructions that are interesting to optimize. */
64 MVMSpeshIns *ins = bb->first_ins;
65 while (ins) {
66 switch (ins->info->opcode) {
67 case MVM_SSA_PHI:
68 analyze_phi(tc, g, ins);
69 break;
70 case MVM_OP_set:
71 copy_facts(tc, g, ins->operands[0], ins->operands[1]);
72 break;
73 case MVM_OP_isnull:
74 optimize_isnull(tc, g, bb, ins);
75 break;
76 case MVM_OP_istrue:
77 case MVM_OP_isfalse:
78 optimize_istrue_isfalse(tc, g, bb, ins);
79 break;
80 case MVM_OP_if_i:
81 case MVM_OP_unless_i:
82 case MVM_OP_if_n:
83 case MVM_OP_unless_n:
84 optimize_iffy(tc, g, ins, bb);
85 break;
86 case MVM_OP_if_o:
87 case MVM_OP_unless_o:
88 optimize_object_conditional(tc, g, ins, bb);
89 break;
90 case MVM_OP_not_i:
91 optimize_not_i(tc, g, ins, bb);
92 break;
93 case MVM_OP_prepargs:
94 arg_info.cs = g->sf->body.cu->body.callsites[ins->operands[0].callsite_idx];
95 arg_info.prepargs_ins = ins;
96 arg_info.prepargs_bb = bb;
97 break;
98 case MVM_OP_arg_i:
99 case MVM_OP_arg_n:
100 case MVM_OP_arg_s:
101 case MVM_OP_arg_o: {
21 102
22 ``` 103 ```
23 $ git clone https://github.com/MoarVM/MoarVM.git 104
105 # 現在
106
107 - case文の書き換えの部分をどうするか悩んでいます
108
109 ```c
110
111 //XXX TODO 書き換えてる
112 __code optimize_bb_switch_cbc(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshBB *bb,
113 MVMSpeshPlanned *p) {
114 MVMSpeshCallInfo arg_info;
115 /* Look for instructions that are interesting to optimize. */
116 MVMSpeshIns *ins = bb->first_ins;
117
118 if (ins){
119 goto optimize_bb_switch_cbc_ins(ins->next);
120 }
121 }
122
123 __code optimize_bb_switch_cbc_ins(MVMSpeshIns *ins){
124
125 if (ins){
126 goto optimize_bb_switch_cbc_ins(ins->next);
127 }
128
129
130 goto optimize_bb_switch_cbc_ins(ins->next);
131 }
132
24 ``` 133 ```
25 134
26 # MoarVMのmake 135 # 今週のTODO
27 136
28 - Perlの`Configure.pl`を叩いてMakefileを生成する 137 - case文をどうにかして書き換える
29 - 別のディレクトリからは叩け無い仕様に成っていた 138 - 試しにコンパイル
30
31 ```
32 ./Configure.pl --cc /usr/local/x86-cbc/bin/gcc --debug --compiler gcc --prefix=/mnt/dalmore-home/one/src/build_perl6/MoarVM`
33 ```
34
35 - オプション
36 - cc
37 - コンパイラのパスを設定する
38 - debug
39 - debugオプション
40 - compiler
41 - コンパイラの種類を指定する
42 - gcc, clang, clをサポートしている
43 - toolchain <toolchain>
44 - "posix", "gnu", "bsd" and "msvc"のツールチェインを選択可能
45 - prefix
46 - make installの先を指定
47
48 # llvmでの実行
49
50 ```
51 (dalmore) ./Configure.pl --cc /usr/local/cbclang/bin/clang
52 ```
53
54 - セグフォで死ぬ
55
56 ```
57 0. Program arguments: /net/open/CentOS/local/cbclang/bin/clang-7.0 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -disable-free -main-f
58 ile-name io.c -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse
59 -init-array -target-cpu x86-64 -dwarf-column-info -debug-info-kind=limited -dwarf-version=4 -debugger-tuning=gdb -momit-leaf-frame-pointer -c
60 overage-notes-file /mnt/dalmore-home/one/src/MoarVM/src/platform/posix/io.gcno -resource-dir /net/open/CentOS/local/cbclang/lib/clang/7.0.0 -
61 D NDEBUG -D _REENTRANT -D _FILE_OFFSET_BITS=64 -D DEBUG_HELPERS -D MVM_TRACING=0 -D MVM_CGOTO=1 -D MVM_RDTSCP=1 -D MVM_BUILD_SHARED -I 3rdpar
62 ty/libuv/include -I 3rdparty/libuv/src -I 3rdparty/libatomicops/src -I 3rdparty/libtommath -I 3rdparty/dyncall/dynload -I 3rdparty/dyncall/dy
63 ncall -I 3rdparty/dyncall/dyncallback -I 3rdparty/sha1 -I 3rdparty/tinymt -I 3rdparty/dynasm -I 3rdparty/cmp -I 3rdparty -I src -internal-isy
64 stem /usr/local/include -internal-isystem /net/open/CentOS/local/cbclang/lib/clang/7.0.0/include -internal-externc-isystem /include -internal
65 -externc-isystem /usr/include -O3 -Werror=declaration-after-statement -Werror=pointer-arith -fdebug-compilation-dir /mnt/dalmore-home/one/src
66 /MoarVM -ferror-limit 19 -fmessage-length 136 -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-sl
67 p -o src/platform/posix/io.o -x c src/platform/posix/io.c
68 1. <eof> parser at end of file
69 clang-7.0: error: unable to execute command: Segmentation fault
70 clang-7.0: error: clang frontend command failed due to signal (use -v to see invocation)
71 clang version 7.0.0
72 Target: x86_64-unknown-linux-gnu
73 Thread model: posix
74 InstalledDir: /usr/local/cbclang/bin
75 clang-7.0: note: diagnostic msg: PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, a
76 nd associated run script.
77 clang-7.0: note: diagnostic msg:
78 ********************
79
80 PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
81 Preprocessed source(s) and associated run script(s) are located at:
82 clang-7.0: note: diagnostic msg: /tmp/io-e696e2.c
83 clang-7.0: note: diagnostic msg: /tmp/io-e696e2.sh
84 clang-7.0: note: diagnostic msg:
85
86 ********************
87 ```
88
89 # make
90
91 ```
92 $ make -j 50 && make install
93 ```
94
95 - 何故かsrc側にもmoarのバイナリが生成された
96 - `/mnt/dalmore-home/one/src/build_perl6/MoarVM/bin`にMoarのバイナリが生成
97
98
99 # NQPのmake
100
101
102 ```
103 +dalmore+one ./Configure.pl --prefix=/mnt/dalmore-home/one/src/build_perl6/nqp --backends=moar --with-moar=/mnt/dalmore-home/one/src/build_perl6/MoarVM/bin/moar
104 ```
105
106 - オプション
107 - `prefix`
108 - ビルド先
109 - `backends`
110 - NQPが走るVMを選択する
111 - `--with-moar`
112 - MoarVMを使う場合MoarVMのパス
113
114 # バージョン
115
116 ```
117 Creating tools/build/install-jvm-runner.pl ...
118
119 ===SORRY!===
120 Found /mnt/dalmore-home/one/src/build_perl6/MoarVM/bin/moar version 2018.04-1-g577857a, which is too old. Wanted at least 2018.04-18-ge7d79d8
121 69
122
123 No suitable MoarVM (moar executable) found using the --prefix
124 (You can get a MoarVM built automatically with --gen-moar.)
125 ```
126
127 - MoarVMとバージョンが異なるらしくエラーが発生した
128
129 ```
130 /mnt/dalmore-home/one/src/build_perl6/MoarVM/bin/moar --libpath=src/vm/moar/stage0 src/vm/moar/stage0/nqp.moarvm --bootstrap --module-path=ge
131 n/moar/stage1 --setting-path=gen/moar/stage1 \
132 --setting=NQPCORE --no-regex-lib --target=mbc \
133 --output=gen/moar/stage1/NQPP6QRegex.moarvm gen/moar/stage1/NQPP6QRegex.nqp
134 /usr/bin/perl -MExtUtils::Command -e mkpath gen/moar/stage1/gen
135 /usr/bin/perl tools/build/gen-version.pl /mnt/dalmore-home/one/src/build_perl6/nqp /mnt/dalmore-home/one/src/build_perl6/nqp/share/nqp/lib >
136 gen/moar/stage1/nqp-config.nqp
137 Can't locate Digest/SHA.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl
138 5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at tools/build/gen-version.pl line 9.
139 BEGIN failed--compilation aborted at tools/build/gen-version.pl line 9.
140 make: *** [gen/moar/stage1/nqp.moarvm] Error 2
141 ```
142
143 - バージョンを更新したところ`Digest::SHA`が入っていないエラーが発生した
144
145 # Perlモジュールの追加
146
147 - 最近のPerlのモジュールinstallツールのcpanmをoneにいれました
148 - `yum install perl-devel`を実行してperlのコアモジュールを追加した
149 - `curl -L https://cpanmin.us | perl - --sudo App::cpanminus `
150 - `cpanm --force Digest::SHA`
151
152
153 # MacOSX上でのgccのエラー
154
155 ```
156 $./Configure.pl --prefix=/Users/anatofuz/workspace/cr/Basic/build_perl6 --cc /Users/anatofuz/workspace/cr/build_gcc/bin/gcc --compiler gcc
157 ```
158
159 これを実行すると
160
161 ```
162 compiling 3rdparty/libuv/src/unix/darwin-proctitle.o
163 compiling 3rdparty/libuv/src/unix/fsevents.o
164 In file included from /System/Library/Frameworks/Security.framework/Headers/AuthSession.h:32:0,
165 from /System/Library/Frameworks/Security.framework/Headers/Security.h:43,
166 from /System/Library/Frameworks/CoreServices.framework/Frameworks/OSServices.framework/Headers/CSIdentity.h:43,
167 from /System/Library/Frameworks/CoreServices.framework/Frameworks/OSServices.framework/Headers/OSServices.h:27,
168 from /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Headers/IconsCore.h:23,
169 from /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Headers/LaunchServices.h:22,
170 from /System/Library/Frameworks/CoreServices.framework/Headers/CoreServices.h:39,
171 from /System/Library/Frameworks/ApplicationServices.framework/Headers/ApplicationServices.h:23,
172 from 3rdparty/libuv/src/unix/darwin-proctitle.c:33:
173 /System/Library/Frameworks/Security.framework/Headers/Authorization.h:193:7: error: variably modified 'bytes' at file scope
174 char bytes[kAuthorizationExternalFormLength];
175 ^~~~~
176 In file included from /System/Library/Frameworks/Security.framework/Headers/AuthSession.h:32:0,
177 from /System/Library/Frameworks/Security.framework/Headers/Security.h:43,
178 from /System/Library/Frameworks/CoreServices.framework/Frameworks/OSServices.framework/Headers/CSIdentity.h:43,
179 from /System/Library/Frameworks/CoreServices.framework/Frameworks/OSServices.framework/Headers/OSServices.h:27,
180 from /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Headers/IconsCore.h:23,
181 from /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Headers/LaunchServices.h:22,
182 from /System/Library/Frameworks/CoreServices.framework/Headers/CoreServices.h:39,
183 from 3rdparty/libuv/src/unix/fsevents.c:49:
184 /System/Library/Frameworks/Security.framework/Headers/Authorization.h:193:7: error: variably modified 'bytes' at file scope
185 char bytes[kAuthorizationExternalFormLength];
186 ^~~~~
187 make: *** [3rdparty/libuv/src/unix/fsevents.o] Error 1
188 make: *** Waiting for unfinished jobs....
189 In file included from /System/Library/Frameworks/CoreGraphics.framework/Headers/CGContext.h:18:0,
190 from /System/Library/Frameworks/CoreGraphics.framework/Headers/CGBitmapContext.h:9,
191 from /System/Library/Frameworks/CoreGraphics.framework/Headers/CoreGraphics.h:11,
192 from /System/Library/Frameworks/ApplicationServices.framework/Headers/ApplicationServices.h:35,
193 from 3rdparty/libuv/src/unix/darwin-proctitle.c:33:
194 /System/Library/Frameworks/CoreGraphics.framework/Headers/CGFont.h:53:40: error: initializer element is not constant
195 static const CGFontIndex kCGGlyphMax = kCGFontIndexMax;
196 ^~~~~~~~~~~~~~~
197 In file included from /System/Library/Frameworks/CoreGraphics.framework/Headers/CGContext.h:21:0,
198 from /System/Library/Frameworks/CoreGraphics.framework/Headers/CGBitmapContext.h:9,
199 from /System/Library/Frameworks/CoreGraphics.framework/Headers/CoreGraphics.h:11,
200 from /System/Library/Frameworks/ApplicationServices.framework/Headers/ApplicationServices.h:35,
201 from 3rdparty/libuv/src/unix/darwin-proctitle.c:33:
202 /System/Library/Frameworks/CoreGraphics.framework/Headers/CGPath.h:391:15: error: expected identifier or '(' before '^' token
203 typedef void (^CGPathApplyBlock)(const CGPathElement * element);
204 ^
205 /System/Library/Frameworks/CoreGraphics.framework/Headers/CGPath.h:393:53: error: unknown type name 'CGPathApplyBlock'
206 CG_EXTERN void CGPathApplyWithBlock(CGPathRef path, CGPathApplyBlock CF_NOESCAPE block)
207 ^~~~~~~~~~~~~~~~
208 make: *** [3rdparty/libuv/src/unix/darwin-proctitle.o] Error 1
209 ```
210
211
212 とフレームワークのコンパイルエラーが発生する.
213 これはbrew経由で入れたgcc-7でも発生した