• Home
Name Date Size #Lines LOC

..--

figures/12-May-2024-

README.mdD12-May-2024246 95

README_zh.mdD12-May-202434.7 KiB710562

development-example.mdD12-May-202413.6 KiB317244

environment-setup-and-compilation.mdD12-May-20241.4 KiB5236

overview-zh.mdD12-May-20243.9 KiB5332

overview.mdD12-May-20245.3 KiB5229

using-the-toolchain.mdD12-May-202417 KiB246222

README.md

1# ArkCompiler JS Runtime Usage Guide
2
3-   [Overview](overview.md)
4-   [Environment Setup and Compilation](environment-setup-and-compilation.md)
5-   [Development Example](development-example.md)
6-   [Using the Toolchain](using-the-toolchain.md)
7
8
9

README_zh.md

1# 方舟运行时使用指南
2
3## 方舟编译器简介
4
5方舟编译器(ArkCompiler)是为支持多种编程语言、多种芯片平台的联合编译、运行而设计的统一编译运行时平台。
6
7* ArkCompiler主要分成两个部分:编译工具链与运行时。
8* ArkCompiler eTS Runtime主要由四个子系统组成:Core Subsystem、Execution Subsystem、Compiler Subsystem、Runtime subsystem。
9* ArkCompiler 的设计特点:原生支持类型、并发模型优化与并发API、安全。
10
11要了解虚拟机的详细设计请参考 [概述](overview-zh.md)
12
13## 环境搭建和编译
14
15### 环境配置
16
17#### 搭建Ubuntu环境
18
19- 初始环境软件安装(Ubuntu版本推荐18.04或20.04)
20
21  ```
22  sudo apt-get update
23  sudo apt-get upgrade
24  sudo apt-get install git-lfs git bison flex gnupg build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses-dev x11proto-core-dev libx11-dev libc++1 lib32z1-dev ccache libgl1-mesa-dev libxml2-utils xsltproc unzip m4 libtinfo5 bc npm genext2fs liblz4-tool libssl-dev ruby openjdk-8-jre-headless gdb python3-pip libelf-dev libxcursor-dev libxrandr-dev libxinerama-dev
25  ```
26
27  详细Ubuntu安装搭建请参考 [搭建Ubuntu环境](https://developer.huawei.com/consumer/cn/training/course/video/C101639988048536240)
28
29#### 源码获取
30
31  下载源码请参考 [下载说明](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/get-code/sourcecode-acquire.md)
32
33### 代码编译
34
35    注意:下列命令需在源码根目录下执行
36
371. 首次编译:
38
39   ```
40   ./build.sh --product-name rk3568
41   ```
422. 首次编译后增量编译方舟运行时:
43
44   编译linux-x86版本:
45
46   ```
47   ./build.sh --product-name rk3568 --build-target ark_js_host_linux_tools_packages
48   ```
49
50   编译oh-arm64版本:
51
52   ```
53   ./build.sh --product-name rk3568 --gn-args use_musl=true --target-cpu arm64 --build-target ark_js_packages
54   ```
55
56   编译oh-arm32版本:
57
58   ```
59   ./build.sh --product-name rk3568 --build-target  ark_js_packages
60   ```
613. 首次编译后增量编译方舟前端:
62
63   ```
64   ./build.sh --product-name rk3568 --build-target ets_frontend_build
65   ```
66
67   更多编译命令请参考 [编译命令](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/subsystems/subsys-arkcompiler-guide.md)
68
69**说明**:上述编译命令为release版本,编译debug版本需增加编译选项:--gn-args is_debug=true。
70
71方舟相关的二进制文件在如下路径:
72
73```
74out/rk3568/arkcompiler/runtime_core/
75out/rk3568/arkcompiler/ets_frontend/
76out/rk3568/arkcompiler/ets_runtime/
77out/rk3568/clang_x64/arkcompiler/runtime_core/
78out/rk3568/clang_x64/arkcompiler/ets_frontend/
79out/rk3568/clang_x64/arkcompiler/ets_runtime
80```
81
82## 开发实例
83
84本章节将介绍基于方舟运行时的开发测试实例。
85
86### HelloWorld
87
88#### 运行前准备
89
90* 编译编译方舟运行时和方舟前端
91
92  ```
93  ./build.sh --product-name rk3568 --build-target ark_js_host_linux_tools_packages --build-target ets_frontend_build
94  ```
95
96#### 运行hello-world.js
97
98新建hello-world.js文件,写入以下源码:
99
100```
101print("Hello World!!!");
102```
103
104运行步骤:
105
1061. 通过方舟前端生成hello-world.abc文件,编译命令:
107
108   ```
109   node --expose-gc /your_code_path/out/rk3568/clang_x64/arkcompiler/ets_frontend/build/src/index.js hello-world.js
110   ```
111   **注意**:使用node编译abc过程遇到ENOENT错误,运行如下命令进行修复
112
113    ```
114    npm cache clean --force
115    cd /your_code_path/arkcompiler/ets_frontend/ts2panda
116    npm install
117    cd /your_code_path/out/rk3568/clang_x64/arkcompiler/ets_frontend/build
118    npm install
119    ```
1202. 执行hello-world.abc文件:
121
122   1. 设置搜索路径:
123
124      ```
125      export LD_LIBRARY_PATH=/your_code_path/out/rk3568/clang_x64/arkcompiler/ets_runtime:/your_code_path/out/rk3568/clang_x64/global/i18n_standard:/your_code_path/prebuilts/clang/ohos/linux-x86_64/llvm/lib:/your_code_path/out/rk3568/clang_x64/thirdparty/zlib
126      ```
127   2. 执行ark\_js\_vm:
128
129      ```
130      /your_code_path/out/rk3568/clang_x64/arkcompiler/ets_runtime/ark_js_vm hello-world.abc
131      ```
132
133      执行结果如下:
134
135      ```
136      Hello World!!!
137      ```
138
139**说明**:此处“_your_code_path_”为源码目录路径。
140
141#### 反汇编hello-world.abc
142
143编译生成反汇编工具:
144
145```
146./build.sh --product-name rk3568 --build-target ark_host_linux_tools_packages
147```
148
149执行如下命令,结果输出到output.pa文件中:
150
151```
152/your_code_path/out/rk3568/clang_x64/arkcompiler/runtime_core/ark_disasm hello-world.abc output.pa
153```
154
155hello-world.abc反汇编结果如下:
156
157```
158#
159# source binary: hello-world.abc
160#
161
162# ====================
163# LITERALS
164
165# ====================
166# RECORDS
167
168.record _ESAnnotation <external>
169
170.record _ESModuleMode {
171	u8 isModule
172}
173
174# ====================
175# METHODS
176
177.function any func_main_0_any_any_any_any_(any a0, any a1, any a2) <static> {
178	mov v2, a2
179	mov v1, a1
180	mov v0, a0
181	builtin.acc
182	sta v5
183	builtin.idi "print", 0x0 // 加载print函数
184	sta v3
185	lda.str "Hello World!!!"  // 加载Hello World!!!字符串
186	sta v4
187	builtin.tern3 v3, v4  // 调用print函数
188	builtin.acc
189}
190```
191
192### 运行Test262测试用例
193
194#### 运行前准备
195
1961. 编译方舟运行时,编译命令:
197
198```
199./build.sh --product-name rk3568 --build-target ark_js_host_linux_tools_packages
200```
201
2022. 编译方舟前端,编译命令:
203
204```
205./build.sh --product-name rk3568 --build-target ets_frontend_build
206```
207
208**说明**:编译命令执行路径为项目根目录。
209
210#### 运行Test262
211
212运行run\_test262.py脚本,下载及运行Test262用例。
213
214命令行格式:
215
216```
217python3 test262/run_test262.py [options]
218```
219
220执行路径为:项目根目录/arkcompiler/ets_frontend221
222<table><thead align="left"><tr id="row101462717303"><th class="cellrowborder" valign="top" width="50%" id="mcps1.1.3.1.1"><p id="p51552743010"><a name="p51552743010"></a><a name="p51552743010"></a>选项</p>
223</th>
224<th class="cellrowborder" valign="top" width="50%" id="mcps1.1.3.1.2"><p id="p11592710304"><a name="p11592710304"></a><a name="p11592710304"></a>描述</p>
225</th>
226</tr>
227</thead>
228<tbody><tr id="row2015172763014"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p171592710306"><a name="p171592710306"></a><a name="p171592710306"></a>--h,--help</p>
229</td>
230<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p13151527133011"><a name="p13151527133011"></a><a name="p13151527133011"></a>帮助提示</p>
231</td>
232</tr>
233<tr id="row1015527173015"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p1615182712308"><a name="p1615182712308"></a><a name="p1615182712308"></a>--dir  DIR</p>
234</td>
235<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p9556101593120"><a name="p9556101593120"></a><a name="p9556101593120"></a>选定要测试的目录</p>
236</td>
237</tr>
238<tr id="row1015112763020"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p1815182733012"><a name="p1815182733012"></a><a name="p1815182733012"></a>--file  FILE</p>
239</td>
240<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p1615627173019"><a name="p1615627173019"></a><a name="p1615627173019"></a>选定要测试的文件</p>
241</td>
242</tr>
243<tr id="row131515277307"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p111572716304"><a name="p111572716304"></a><a name="p111572716304"></a>--mode  [{1, 2, 3}]</p>
244</td>
245<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p1655718513105"><a name="p1655718513105"></a><a name="p1655718513105"></a>模式选择,1:仅默认值;2:仅严格模式;3:默认模式和严格模式</p>
246</td>
247</tr>
248<tr id="row1815112753020"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p2151927193015"><a name="p2151927193015"></a><a name="p2151927193015"></a>--es51</p>
249</td>
250<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p1715312588115"><a name="p1715312588115"></a><a name="p1715312588115"></a>运行Test262 ES5.1版本</p>
251</td>
252</tr>
253<tr id="row1915182703012"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p17151527133017"><a name="p17151527133017"></a><a name="p17151527133017"></a>--es2015  [{all, only}]</p>
254</td>
255<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p15761152983113"><a name="p15761152983113"></a><a name="p15761152983113"></a>运行Test262 ES2015版本,all:包含的所有用例;only:仅包括ES2015</p>
256</td>
257</tr>
258<tr id="row10924204611109"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p18924846111013"><a name="p18924846111013"></a><a name="p18924846111013"></a>--esnext</p>
259</td>
260<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p15495042191410"><a name="p15495042191410"></a><a name="p15495042191410"></a>运行Test262-ES.next</p>
261</td>
262</tr>
263<tr id="row5161145010105"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p716125071020"><a name="p716125071020"></a><a name="p716125071020"></a>--engine  FILE</p>
264</td>
265<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p121612050181014"><a name="p121612050181014"></a><a name="p121612050181014"></a>运行测试的其他引擎,指定二进制文件(如:d8,hermes,jsc,qjs...)</p>
266</td>
267</tr>
268<tr id="row1325585931120"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p112561595112"><a name="p112561595112"></a><a name="p112561595112"></a>--babel</p>
269</td>
270<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p32561959111112"><a name="p32561959111112"></a><a name="p32561959111112"></a>是否使用Babel转换</p>
271</td>
272</tr>
273<tr id="row95230818126"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p12523158191210"><a name="p12523158191210"></a><a name="p12523158191210"></a>--timeout  TIMEOUT</p>
274</td>
275<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p65233871210"><a name="p65233871210"></a><a name="p65233871210"></a>设置测试超时时间(以毫秒为单位)</p>
276</td>
277</tr>
278<tr id="row474911612120"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p1274912166123"><a name="p1274912166123"></a><a name="p1274912166123"></a>--threads  THREADS</p>
279</td>
280<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p4749121631210"><a name="p4749121631210"></a><a name="p4749121631210"></a>设置并行运行线程数</p>
281</td>
282</tr>
283<tr id="row561512363122"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p26152036191218"><a name="p26152036191218"></a><a name="p26152036191218"></a>--hostArgs  HOSTARGS</p>
284</td>
285<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p156151636161215"><a name="p156151636161215"></a><a name="p156151636161215"></a>传递给eshost主机的命令行参数</p>
286</td>
287</tr>
288<tr id="row77091648111210"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p18709164871213"><a name="p18709164871213"></a><a name="p18709164871213"></a>--ark-tool  ARK_TOOL</p>
289</td>
290<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p16709194812126"><a name="p16709194812126"></a><a name="p16709194812126"></a>方舟运行时的二进制工具</p>
291</td>
292</tr>
293<tr id="row3767145231210"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p3767155201216"><a name="p3767155201216"></a><a name="p3767155201216"></a>--ark-frontend-tool  ARK_FRONTEND_TOOL</p>
294</td>
295<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p4767195251220"><a name="p4767195251220"></a><a name="p4767195251220"></a>方舟前端转换工具</p>
296</td>
297</tr>
298<tr id="row753817001311"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p553870111318"><a name="p553870111318"></a><a name="p553870111318"></a>--libs-dir  LIBS_DIR</p>
299</td>
300<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p35384041313"><a name="p35384041313"></a><a name="p35384041313"></a>依赖so的路径集合,通过“:”分割</p>
301</td>
302</tr>
303<tr id="row08504716135"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p11851747161314"><a name="p11851747161314"></a><a name="p11851747161314"></a>--ark-frontend  [{ts2panda, es2panda}]</p>
304</td>
305<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p1085144712137"><a name="p1085144712137"></a><a name="p1085144712137"></a>指定前端</p>
306</td>
307</tr>
308</tbody>
309</table>
310
311#### 测试运行示例
312
313- 运行ES51测试用例:
314
315  ```
316   python3 test262/run_test262.py --es51
317  ```
318- 仅运行ES2015测试用例:
319
320  ```
321   python3 test262/run_test262.py --es2015
322  ```
323- 仅运行ES2021测试用例:
324
325  ```
326   python3 test262/run_test262.py --es2021 only
327
328  ```
329- 运行ES2015和ES51和ES2021所有测试用例:
330
331  ```
332   python3 test262/run_test262.py --es2021 all
333  ```
334- 运行单一测试用例:
335
336  ```
337   python3 test262/run_test262.py --file test262/data/test_es5/language/statements/break/12.8-1.js
338  ```
339- 运行某目录下所有测试用例:
340
341  ```
342   python3 test262/run_test262.py --dir test262/data/test_es5/language/statements
343  ```
344- 使用\`babel\`把单个测试用例转换成es5后再运行:
345
346  ```
347   python3 test262/run_test262.py  --babel --file test262/data/test_es5/language/statements/break/12.8-1.js
348  ```
349
350#### 测试输出
351
352Test262所有用例的测试结果位于项目根目录/arkcompiler/ets_frontend/out下。shell中测试输出结果如下:
353
354```
355$python3 test262/run_test262.py --file test262/data/test_es2015/built-ins/Array/15.4.5.1-5-1.js
356
357Wait a moment..........
358Test command:
359node
360        test262/harness/bin/run.js
361        --hostType=panda
362        --hostPath=python3
363        --hostArgs='-B test262/run_sunspider.py --ark-tool=/your_code_path/out/rk3568/clang_x64/arkcompiler/ets_runtime/ark_js_vm --ark-frontend-tool=/your_code_path/out/rk3568/clang_x64/arkcompiler/ets_frontend/build/src/index.js --libs-dir=/your_code_path/out/rk3568/clang_x64/global/i18n:/your_code_path/prebuilts/clang/ohos/linux-x86_64/llvm/lib:/your_code_path/out/rk3568/clang_x64/thirdparty/zlib/ --ark-frontend=ts2panda'
364        --threads=15
365        --mode=only strict mode
366        --timeout=60000
367        --tempDir=build/test262
368        --test262Dir=test262/data
369        --saveCompiledTests
370        test262/data/test_es5/language/statements/break/12.8-1.js
371
372PASS test262/data/test_es2015/built-ins/Array/15.4.5.1-5-1.js (strict mode)
373Ran 1 tests
3741 passed
3750 failed
376used time is: 0:01:04.439642
377```
378
379### AOT执行
380
381#### 运行前准备
382
383* 编译生成AOT编译器:
384
385  ```
386  ./build.sh --product-name rk3568  --build-target ets_frontend_build --build-target ark_js_host_linux_tools_packages --build-target ark_host_linux_tools_packages
387  ```
388
389#### 运行hello-world.ts
390
391新建hello-world.ts文件,写入以下源码:
392
393```
394declare function print(arg:any):string;
395print('Hello World!!!')
396```
397
398运行步骤:
399
4001. 通过方舟前端生成hello-world.abc文件,编译命令:
401
402   ```
403   node --expose-gc /your_code_path/out/rk3568/clang_x64/arkcompiler/ets_frontend/build/src/index.js -m --merge-abc test1/test.ts
404   ```
4052. 执行hello-world.abc文件:
406
407   1. 设置搜索路径:
408
409      ```
410      export LD_LIBRARY_PATH=/your_code_path/out/rk3568/clang_x64/arkcompiler/ets_runtime:/your_code_path/out/rk3568/clang_x64/global/i18n_standard:/your_code_path/prebuilts/clang/ohos/linux-x86_64/llvm/lib:/your_code_path/out/rk3568/clang_x64/thirdparty/icu:/your_code_path/out/rk3568/clang_x64/thirdparty/zlib
411      ```
412   2. 通过AOT编译器生成an和ai文件:
413
414      ```
415      /your_code_path/out/rk3568/clang_x64/arkcompiler/ets_runtime/ark_aot_compiler  --aot-file=./hello-world hello-world.abc
416      ```
417   3. 执行ark\_js\_vm:
418
419      ```
420      /your_code_path/out/rk3568/clang_x64/arkcompiler/ets_runtime/ark_js_vm --aot-file=./hello-world --entry-point=hello-world hello-world.abc
421      ```
422
423      执行结果如下:
424
425      ```
426      Hello World!!!
427      ```
428
429**说明**:此处“_your_code_path_”为源码目录路径。
430
431## 工具链使用
432
433方舟前端工具采用命令行交互方式,支持将ArkTS代码转换为方舟字节码,使其能够在方舟运行时上运行。支持Windows/Linux/Mac平台。
434
435### ArkTS字节码编译工具概述
436
437使用前端工具将ArkTS文件转换为方舟字节码文件。方舟前端工具在linux平台上可通过全量编译或指定编译前端工具链获取。
438
439构建编译:
440
441```
442$ ./build.sh --product-name rk3568 --build-target ark_ts2abc_build
443```
444
445安装 `node`和 `npm`后, 使用前端工具:
446
447```
448$ cd out/rk3568/clang_x64/arkcompiler/ets_frontend/build
449$ npm install
450$ node --expose-gc src/index.js [选项] file.js
451```
452
453<table><thead align="left"><tr id="row19706343164411"><th class="cellrowborder" valign="top" width="15.29152915291529%" id="mcps1.1.6.1.1"><p id="p1970694310447"><a name="p1970694310447"></a><a name="p1970694310447"></a>选项</p>
454</th>
455<th class="cellrowborder" valign="top" width="6.830683068306829%" id="mcps1.1.6.1.2"><p id="p9548142314456"><a name="p9548142314456"></a><a name="p9548142314456"></a>缩写</p>
456</th>
457<th class="cellrowborder" valign="top" width="44.34443444344434%" id="mcps1.1.6.1.3"><p id="p170614318449"><a name="p170614318449"></a><a name="p170614318449"></a>描述</p>
458</th>
459<th class="cellrowborder" valign="top" width="26.01260126012601%" id="mcps1.1.6.1.4"><p id="p1841257144811"><a name="p1841257144811"></a><a name="p1841257144811"></a>取值范围</p>
460</th>
461<th class="cellrowborder" valign="top" width="7.520752075207521%" id="mcps1.1.6.1.5"><p id="p15894191313495"><a name="p15894191313495"></a><a name="p15894191313495"></a>默认值</p>
462</th>
463</tr>
464</thead>
465<tbody><tr id="row770684312444"><td class="cellrowborder" valign="top" width="15.29152915291529%" headers="mcps1.1.6.1.1 "><p id="p0706154312447"><a name="p0706154312447"></a><a name="p0706154312447"></a>--modules</p>
466</td>
467<td class="cellrowborder" valign="top" width="6.830683068306829%" headers="mcps1.1.6.1.2 "><p id="p1654810236457"><a name="p1654810236457"></a><a name="p1654810236457"></a>-m</p>
468</td>
469<td class="cellrowborder" valign="top" width="44.34443444344434%" headers="mcps1.1.6.1.3 "><p id="p12451427144913"><a name="p12451427144913"></a><a name="p12451427144913"></a>按照Module方式编译</p>
470</td>
471<td class="cellrowborder" valign="top" width="26.01260126012601%" headers="mcps1.1.6.1.4 "><p id="p6415710488"><a name="p6415710488"></a><a name="p6415710488"></a>-</p>
472</td>
473<td class="cellrowborder" valign="top" width="7.520752075207521%" headers="mcps1.1.6.1.5 "><p id="p389411314490"><a name="p389411314490"></a><a name="p389411314490"></a>-</p>
474</td>
475</tr>
476<tr id="row8707114315446"><td class="cellrowborder" valign="top" width="15.29152915291529%" headers="mcps1.1.6.1.1 "><p id="p7707134344416"><a name="p7707134344416"></a><a name="p7707134344416"></a>--debug-log</p>
477</td>
478<td class="cellrowborder" valign="top" width="6.830683068306829%" headers="mcps1.1.6.1.2 "><p id="p15481123194512"><a name="p15481123194512"></a><a name="p15481123194512"></a>-l</p>
479</td>
480<td class="cellrowborder" valign="top" width="44.34443444344434%" headers="mcps1.1.6.1.3 "><p id="p1988112617501"><a name="p1988112617501"></a><a name="p1988112617501"></a>使能log信息</p>
481</td>
482<td class="cellrowborder" valign="top" width="26.01260126012601%" headers="mcps1.1.6.1.4 "><p id="p34135724819"><a name="p34135724819"></a><a name="p34135724819"></a>-</p>
483</td>
484<td class="cellrowborder" valign="top" width="7.520752075207521%" headers="mcps1.1.6.1.5 "><p id="p16894813204919"><a name="p16894813204919"></a><a name="p16894813204919"></a>-</p>
485</td>
486</tr>
487<tr id="row1770734394411"><td class="cellrowborder" valign="top" width="15.29152915291529%" headers="mcps1.1.6.1.1 "><p id="p11549171604510"><a name="p11549171604510"></a><a name="p11549171604510"></a>--dump-assembly</p>
488</td>
489<td class="cellrowborder" valign="top" width="6.830683068306829%" headers="mcps1.1.6.1.2 "><p id="p1654815237456"><a name="p1654815237456"></a><a name="p1654815237456"></a>-a</p>
490</td>
491<td class="cellrowborder" valign="top" width="44.34443444344434%" headers="mcps1.1.6.1.3 "><p id="p1024452794916"><a name="p1024452794916"></a><a name="p1024452794916"></a>输出为可读文本格式的字节码文件</p>
492</td>
493<td class="cellrowborder" valign="top" width="26.01260126012601%" headers="mcps1.1.6.1.4 "><p id="p184145774817"><a name="p184145774817"></a><a name="p184145774817"></a>-</p>
494</td>
495<td class="cellrowborder" valign="top" width="7.520752075207521%" headers="mcps1.1.6.1.5 "><p id="p20894101319494"><a name="p20894101319494"></a><a name="p20894101319494"></a>-</p>
496</td>
497</tr>
498<tr id="row17707643124417"><td class="cellrowborder" valign="top" width="15.29152915291529%" headers="mcps1.1.6.1.1 "><p id="p1270714432449"><a name="p1270714432449"></a><a name="p1270714432449"></a>--debug</p>
499</td>
500<td class="cellrowborder" valign="top" width="6.830683068306829%" headers="mcps1.1.6.1.2 "><p id="p1548172334510"><a name="p1548172334510"></a><a name="p1548172334510"></a>-d</p>
501</td>
502<td class="cellrowborder" valign="top" width="44.34443444344434%" headers="mcps1.1.6.1.3 "><p id="p32437275490"><a name="p32437275490"></a><a name="p32437275490"></a>携带debug信息</p>
503</td>
504<td class="cellrowborder" valign="top" width="26.01260126012601%" headers="mcps1.1.6.1.4 "><p id="p134185718488"><a name="p134185718488"></a><a name="p134185718488"></a>-</p>
505</td>
506<td class="cellrowborder" valign="top" width="7.520752075207521%" headers="mcps1.1.6.1.5 "><p id="p5894613104916"><a name="p5894613104916"></a><a name="p5894613104916"></a>-</p>
507</td>
508</tr>
509<tr id="row14707184314419"><td class="cellrowborder" valign="top" width="15.29152915291529%" headers="mcps1.1.6.1.1 "><p id="p5707194311449"><a name="p5707194311449"></a><a name="p5707194311449"></a>--show-statistics</p>
510</td>
511<td class="cellrowborder" valign="top" width="6.830683068306829%" headers="mcps1.1.6.1.2 "><p id="p1954872319456"><a name="p1954872319456"></a><a name="p1954872319456"></a>-s</p>
512</td>
513<td class="cellrowborder" valign="top" width="44.34443444344434%" headers="mcps1.1.6.1.3 "><p id="p16224102744913"><a name="p16224102744913"></a><a name="p16224102744913"></a>显示字节码相关的统计信息</p>
514</td>
515<td class="cellrowborder" valign="top" width="26.01260126012601%" headers="mcps1.1.6.1.4 "><p id="p154195704813"><a name="p154195704813"></a><a name="p154195704813"></a>-</p>
516</td>
517<td class="cellrowborder" valign="top" width="7.520752075207521%" headers="mcps1.1.6.1.5 "><p id="p19894131304917"><a name="p19894131304917"></a><a name="p19894131304917"></a>-</p>
518</td>
519</tr>
520<tr id="row768813216460"><td class="cellrowborder" valign="top" width="15.29152915291529%" headers="mcps1.1.6.1.1 "><p id="p20688113244612"><a name="p20688113244612"></a><a name="p20688113244612"></a>--output</p>
521</td>
522<td class="cellrowborder" valign="top" width="6.830683068306829%" headers="mcps1.1.6.1.2 "><p id="p1468863218469"><a name="p1468863218469"></a><a name="p1468863218469"></a>-o</p>
523</td>
524<td class="cellrowborder" valign="top" width="44.34443444344434%" headers="mcps1.1.6.1.3 "><p id="p1468814324461"><a name="p1468814324461"></a><a name="p1468814324461"></a>输出文件路径</p>
525</td>
526<td class="cellrowborder" valign="top" width="26.01260126012601%" headers="mcps1.1.6.1.4 "><p id="p12624825135117"><a name="p12624825135117"></a><a name="p12624825135117"></a>-</p>
527</td>
528<td class="cellrowborder" valign="top" width="7.520752075207521%" headers="mcps1.1.6.1.5 "><p id="p1989431344920"><a name="p1989431344920"></a><a name="p1989431344920"></a>-</p>
529</td>
530</tr>
531<tr id="row6445636154611"><td class="cellrowborder" valign="top" width="15.29152915291529%" headers="mcps1.1.6.1.1 "><p id="p64451436124618"><a name="p64451436124618"></a><a name="p64451436124618"></a>--timeout</p>
532</td>
533<td class="cellrowborder" valign="top" width="6.830683068306829%" headers="mcps1.1.6.1.2 "><p id="p1445113611468"><a name="p1445113611468"></a><a name="p1445113611468"></a>-t</p>
534</td>
535<td class="cellrowborder" valign="top" width="44.34443444344434%" headers="mcps1.1.6.1.3 "><p id="p1044510362466"><a name="p1044510362466"></a><a name="p1044510362466"></a>超时门限</p>
536</td>
537<td class="cellrowborder" valign="top" width="26.01260126012601%" headers="mcps1.1.6.1.4 "><p id="p745572486"><a name="p745572486"></a><a name="p745572486"></a>-</p>
538</td>
539<td class="cellrowborder" valign="top" width="7.520752075207521%" headers="mcps1.1.6.1.5 "><p id="p7894111310494"><a name="p7894111310494"></a><a name="p7894111310494"></a>-</p>
540</td>
541</tr>
542<tr id="row1978841614720"><td class="cellrowborder" valign="top" width="15.29152915291529%" headers="mcps1.1.6.1.1 "><p id="p0788141614716"><a name="p0788141614716"></a><a name="p0788141614716"></a>--help</p>
543</td>
544<td class="cellrowborder" valign="top" width="6.830683068306829%" headers="mcps1.1.6.1.2 "><p id="p207884169473"><a name="p207884169473"></a><a name="p207884169473"></a>-h</p>
545</td>
546<td class="cellrowborder" valign="top" width="44.34443444344434%" headers="mcps1.1.6.1.3 "><p id="p178821634716"><a name="p178821634716"></a><a name="p178821634716"></a>帮助提示</p>
547</td>
548<td class="cellrowborder" valign="top" width="26.01260126012601%" headers="mcps1.1.6.1.4 "><p id="p1341757114819"><a name="p1341757114819"></a><a name="p1341757114819"></a>-</p>
549</td>
550<td class="cellrowborder" valign="top" width="7.520752075207521%" headers="mcps1.1.6.1.5 "><p id="p208946134499"><a name="p208946134499"></a><a name="p208946134499"></a>-</p>
551</td>
552</tr>
553<tr id="row14354103234714"><td class="cellrowborder" valign="top" width="15.29152915291529%" headers="mcps1.1.6.1.1 "><p id="p1235410329479"><a name="p1235410329479"></a><a name="p1235410329479"></a>--bc-version</p>
554</td>
555<td class="cellrowborder" valign="top" width="6.830683068306829%" headers="mcps1.1.6.1.2 "><p id="p63541832124712"><a name="p63541832124712"></a><a name="p63541832124712"></a>-v</p>
556</td>
557<td class="cellrowborder" valign="top" width="44.34443444344434%" headers="mcps1.1.6.1.3 "><p id="p14354832134715"><a name="p14354832134715"></a><a name="p14354832134715"></a>输出当前字节码版本</p>
558</td>
559<td class="cellrowborder" valign="top" width="26.01260126012601%" headers="mcps1.1.6.1.4 "><p id="p16410577487"><a name="p16410577487"></a><a name="p16410577487"></a>-</p>
560</td>
561<td class="cellrowborder" valign="top" width="7.520752075207521%" headers="mcps1.1.6.1.5 "><p id="p14894201364911"><a name="p14894201364911"></a><a name="p14894201364911"></a>-</p>
562</td>
563</tr>
564<tr id="row246823515473"><td class="cellrowborder" valign="top" width="15.29152915291529%" headers="mcps1.1.6.1.1 "><p id="p1346883524711"><a name="p1346883524711"></a><a name="p1346883524711"></a>--bc-min-version</p>
565</td>
566<td class="cellrowborder" valign="top" width="6.830683068306829%" headers="mcps1.1.6.1.2 ">  </td>
567<td class="cellrowborder" valign="top" width="44.34443444344434%" headers="mcps1.1.6.1.3 "><p id="p17469123534711"><a name="p17469123534711"></a><a name="p17469123534711"></a>输出支持的最低字节码版本</p>
568</td>
569<td class="cellrowborder" valign="top" width="26.01260126012601%" headers="mcps1.1.6.1.4 "><p id="p195557124818"><a name="p195557124818"></a><a name="p195557124818"></a>-</p>
570</td>
571<td class="cellrowborder" valign="top" width="7.520752075207521%" headers="mcps1.1.6.1.5 "><p id="p11894141354919"><a name="p11894141354919"></a><a name="p11894141354919"></a>-</p>
572</td>
573</tr>
574</tbody>
575</table>
576
577### 反汇编器工具概述
578
579工具名称为ark\_disasm,用于将二进制格式的方舟字节码文件转换为文本格式的方舟字节码文件。
580
581编译生成反汇编工具:
582
583```
584./build.sh --product-name rk3568 --build-target ark_host_linux_tools_packages
585```
586
587命令行格式:
588
589```
590ark_disasm [选项] 输入文件 输出文件
591```
592
593<table><thead align="left"><tr id="row125182553217"><th class="cellrowborder" valign="top" width="50%" id="mcps1.1.3.1.1"><p id="p175162514327"><a name="p175162514327"></a><a name="p175162514327"></a>选项</p>
594</th>
595<th class="cellrowborder" valign="top" width="50%" id="mcps1.1.3.1.2"><p id="p6512255324"><a name="p6512255324"></a><a name="p6512255324"></a>描述</p>
596</th>
597</tr>
598</thead>
599<tbody><tr id="row5511825103218"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p45172513326"><a name="p45172513326"></a><a name="p45172513326"></a>--debug</p>
600</td>
601<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p1245695053215"><a name="p1245695053215"></a><a name="p1245695053215"></a>使能调试信息, 如果没有指定"--debug-file", 输出形式将会是标准输出。默认值是false</p>
602</td>
603</tr>
604<tr id="row951112515321"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p451192515323"><a name="p451192515323"></a><a name="p451192515323"></a>--debug-file</p>
605</td>
606<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p175142583210"><a name="p175142583210"></a><a name="p175142583210"></a>调试信息输出文件路径,默认为std::cout</p>
607</td>
608</tr>
609<tr id="row951112515321"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p451192515323"><a name="p451192515323"></a><a name="p451192515323"></a>--skip-string-literals</p>
610</td>
611<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p175142583210"><a name="p175142583210"></a><a name="p175142583210"></a>将字符串用对应的string_ID代替,可以减少输出文件的大小。默认值是false</p>
612</td>
613</tr>
614<tr id="row951112515321"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p451192515323"><a name="p451192515323"></a><a name="p451192515323"></a>--quiet</p>
615</td>
616<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p175142583210"><a name="p175142583210"></a><a name="p175142583210"></a>打开所有--skip-*选项。默认值是false</p>
617</td>
618</tr>
619<tr id="row45116253325"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p85116259328"><a name="p85116259328"></a><a name="p85116259328"></a>--help</p>
620</td>
621<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p1348135833214"><a name="p1348135833214"></a><a name="p1348135833214"></a>帮助提示</p>
622</td>
623</tr>
624<tr id="row194197407327"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p154205401325"><a name="p154205401325"></a><a name="p154205401325"></a>--verbose</p>
625</td>
626<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p369871173312"><a name="p369871173312"></a><a name="p369871173312"></a>输出更多关于类和方法在文件中的信息。默认值是false</p>
627</td>
628</tr>
629</tbody>
630</table>
631
632输入文件:二进制格式的方舟字节码
633
634输出文件:文本格式的方舟字节码
635
636### AOT工具概述
637
638AOT为Ahead Of Time的简称,也即提前编译,能够在Host端将字节码提前编译成Target端可运行的机器码,这样字节码可以获得充分编译优化,从而加速Target端的运行速度。
639
640编译生成aot编译器:
641
642```
643./build.sh --product-name rk3568 --build-target ark_js_host_linux_tools_packages
644```
645
646命令行格式:
647
648```
649ark_aot_compiler [选项] 输入文件
650```
651
652| 选项                          | 描述                                                                                |
653| -----------------------       | ----------------------------------------------------------------------------------- |
654| --aot-file                    | AOT输出文件的路径(不需要文件后缀)。默认值:“aot_file”                             |
655| --compiler-opt-type-lowering  | 利用类型信息,生成优化级别更高的机器码。默认值:“true”                              |
656| --compiler-opt-max-method     | 设置AOT编译方法的大小阈值,当方法的大小超过该值时,则不进行编译。默认值:“32KB”     |
657| --compiler-opt-level          | 设置AOT的优化级别。默认值:“3”                                                      |
658| --compiler-log                | AOT的日志选项,可打印出AOT生成的IR图、汇编码等信息。默认值“none”                    |
659| --compiler-log-snapshot       | 打印与序列化有关的日志信息。默认值“false”                                           |
660| --compiler-log-time           | 打印AOT过程中各个优化pass的耗时情况。默认值值“false”                                |
661
662
663输入文件:二进制格式的方舟字节码
664
665输出文件:直接执行的机器码的an文件、存储序列化后ConstPool的ai文件(输出文件路径需使用--aot-file选项指定)
666
667### PGO工具概述
668
669PGO为Profile-guided optimization的简称,也即配置文件引导的优化。该工具能够记录应用启动和性能场景中的高频(热点)函数,并将信息记录于对应的PGO Profiler文件。AOT编译器则可通过这些信息决策部分函数进行编译,从而在基本不影响应用运行性能的情况下,缩短编译时间,减少.an文件的大小。
670
671编译生成aot编译器和ark js虚拟机
672
673```
674./build.sh --product-name rk3568 --build-target ark_js_host_linux_tools_packages
675```
676
677### 生成PGO Profiler文件
678
679命令行格式:
680
681```
682ark_js_vm [选项] 输入文件
683```
684
685| 选项                    | 描述                                                                                |
686| ----------------------- | ----------------------------------------------------------------------------------- |
687| --enable-pgo-profiler   | 开启pgo工具。默认值:“false”                                                    |
688| --pgo-profiler-path     | pgo profiler文件的保存路径。默认值:当前路径                                     |
689| --pgo-hotness-threshold | 热点函数的阈值,当函数的调用次数大于该值,则认为是热点函数。默认值:“2”             |
690
691输入文件:二进制格式的方舟字节码
692
693输出文件:保存有热点函数信息的ap文件
694
695### 基于PGO Profiler的AOT编译
696
697命令行格式:
698
699```
700ark_aot_compiler [选项] 输入文件
701```
702| 选项                    | 描述                                                                                |
703| ----------------------- | ----------------------------------------------------------------------------------- |
704| --pgo-profiler-path     | pgo profiler文件路径。默认值:“none”                                     |
705| --pgo-hotness-threshold | 使能pgo编译的函数调用次数阈值,profile文件中记录的调用次数大于该阈值的函数才会进行编译。默认值:“2”|
706
707输入文件:二进制格式的方舟字节码,ap文件
708
709输出文件:直接执行的机器码的an文件(基于pgo)
710