目前的Titanium SDK一直使用JS解釋引擎V8。
在2.1.4版本的SDK以後,使用的V8版本是3.9.24.29,在github上顯示,其發佈時間爲2012-03-23: Version 3.9.24。
爲了使Titanium的核心組件保持最新,我最近研究瞭如何升級SDK編譯時使用的V8 lib,各位可以參考下文的內容來構造libV8。
1,準備工作
編譯V8需要一臺運行Macos或者Linux操作系統的計算機,本文以Macos爲例。
首先需要獲取構造所需要的各種dependencies
V8:https://github.com/v8/v8
V8_titanium:https://github.com/appcelerator/v8_titanium
此外,還需要android sdk android-9以上,android-ndk-r6b以上
將V8源碼解壓到V8_titanium目錄的V8子目錄下面。
2,構造V8
新版的V8已經推薦使用scons構造,轉而使用gpy,所以,要正確的生成我們需要的libV8,需要在構造腳本添加以下命令行:
scons -j $NUM_CPUS mode=$BUILD_MODE $BUILD_SIMULATOR snapshot=on armeabi=$ARMEABI I_know_I_should_build_with_GYP=yes || exit 1
|
scons -j $NUM_CPUS mode=$BUILD_MODE snapshot=$SNAPSHOT library=static arch=$BUILD_ARCH os=linux usepthread=off android=on armeabi=$ARMEABI I_know_I_should_build_with_GYP=yes || exit 1
|
修改後,使用如下命令來構造V8:
sh build_v8.sh -j 4 -n ~/android-ndk-r8c/ -p android-9 -l all
|
其中,需要使用
-n參數指定android-ndk的路徑;
-l參數指定目標平臺,例如x86、armeabi、armeabiv7a等
-p參數指定android-sdk版本
-j參數指定編譯使用的處理器內核個數
另外,可以使用-s開關允許snapshot來加速js性能,但是編譯速度會降低。
編譯後的二進制文件輸出路徑爲build/release
要使用此版本的V8,還需要將其打包發佈,方法爲:
sh build_v8.sh -j 4 -n ~/android-ndk-r8c/ -t
|
運行成功後會在輸出目錄生成一個壓縮文件 libv8-3.17.16-release.tar.bz2
3,使用
要使用新版本的V8 for titanium,要將libv8-3.17.16-release.tar.bz2複製到 titanium_mobile 工程(SDK項目)的 titanium_mobile/dist/android/libv8/3.9.24.29/release 目錄(此目錄在成功的編譯過TitaniumSDK後纔會生成),仿照3.9.24.29將其解壓好。
爲了不改動構造配置,最簡單的使用方式是直接將其覆蓋3.9.24.29版本的目錄,
之後方可編譯Titanium SDK
4,附記
3.9.24.29版本至3.17.16版之間的變化(摘錄自V8 changelog):、
我覺得比較有意義的更改已經標紅。
2013-03-21: Version 3.17.15
Performance and stability improvements on all platforms.
2013-03-20: Version 3.17.14
Use internal memcpy when initializing code objects.
(Chromium issue 196330)
2013-03-15: Version 3.17.11
Fixed huge heap snapshot when a heavily shared context has many
variables. (Chromium issue 145687)
2013-02-13: Version 3.17.0
Enabled parallel sweeping.
2013-02-04: Version 3.16.13
Fixed clearing of dead dependent codes and verifing of weak
embedded maps on full GC. (Chromium issue 172488,172489)
Made the arm port build cleanly with Clang.
2013-01-09: Version 3.16.3
Improved GC performance when moving parts of a FixedArray (issue 2452).
2012-12-07: Version 3.15.10
Enabled optimisation of functions inside eval. (issue 2315)
2012-11-16: Version 3.15.4
Perform CPU sampling by CPU sampling thread only iff processing thread
is not running. (issue 2364)
2012-11-12: Version 3.15.2
ES6: Added support for size to Set and Map (issue 2395)
2012-10-31: Version 3.15.0
Loosened aligned code target requirement on ARM (issue 2380)
Fixed JSON.parse to treat leading zeros correctly.
(Chromium issue 158185)
2012-10-22: Version 3.14.5
Speeded up function deoptimization by avoiding quadratic pass over
optimized function list. (Chromium issue 155270)
Always invoke the default Array.sort functions from builtin functions.
(issue 2372)
2012-10-10: Version 3.14.2
ARM: allowed VFP3 instructions when hardfloat is enabled.
(Chromium issue 152506)
2012-07-27: Version 3.12.17
Always set the callee's context when calling a function from optimized
code.
(Chromium issue 138887)
2012-07-24: Version 3.12.15
Enabled building d8 for Android on Mac.
Enabled building and testing V8 on Android IA.
Fixed transcendental cache on ARM in optimized code (issue 2234).
2012-07-06: Version 3.12.9
Correctly advance the scanner when scanning unicode regexp flag.
(Chromium issue 136084)
2012-05-18: Version 3.11.3
Disable optimization for functions that have scopes that cannot be
reconstructed from the context chain. (issue 2071)
2012-05-03: Version 3.10.8
Fixed idle notifications to perform a round of incremental GCs
after context disposal. (issue 2107)
2012-04-10: Version 3.10.1
Fixed performance bug with lazy initialization (Chromium issue
118686).
Optimized regular expressions.