目前的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

V8https://github.com/v8/v8

V8_titaniumhttps://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.