Skip to content

Commit abdce96

Browse files
Kudokmagiera
authored andcommitted
Upgrade to WebkitGTK 2.24.2 and workaround __clear_cache issue o… (#114)
# Summary This PR includes three major changes: 1. Enable JIT back Community reported sensible performance drop from the no-JIT version, so I'd like to enable JIT back. 2. Upgrade to WebKitGTK 2.24.2. This seems to fix previous JSC crashes on Samsung S7 Edge. This version includes JIT new bytecode format as described from WebKit blog: https://webkit.org/blog/9329/a-new-bytecode-format-for-javascriptcore/ After the major change, x86 JIT is not supported and arm32 support was contributed by WebKit community (Thanks to Igalia). From my understanding, original JSC crashes happen at `operationLinkDirectCall()`. After the new bytecode format, there is no direct link call from Baseline JIT. Since we've disabled DFG JIT and FTL JIT, there's no call flow that will hit to `operationLinkDirectCall()`. That is why no more similar crash happens. 3. Workaround for ARM Cortex-A53 cache flush instruction issue: This is from V8's workaround and I believe it is worth to apply into JSC Android as well. https://codereview.chromium.org/1921173004 ARM Cortex-A53 had some errata for original "cvau" instruction, and officially recommended to use "civac" instruction instead. LLVM compiler-rt's `__clear_cache` still uses "cvau" and my patch replaced to "civac". ## Test Plan 1. Run measure scripts on my Samsung Note 5. 2. Provide an [experimented version](https://www.npmjs.com/package/@kudo-ci/jsc-android/v/245459.9000.0) for community who previously reported JSC crash and seems no more crashes happened. ## Measurement Added "@kudo-ci/jsc-android@245459-no-dfg-jit" to previous measurement result. The new result could compared to 241213-no-dfg-jit version. There are some performance improvement from the comparison. https://docs.google.com/spreadsheets/d/1hqX3ai-NCpN_J6YQDTKnKNBctWnMFA6EyOdVhPvwUas/edit#gid=193471288 <img width="735" alt="Screen Shot 2019-06-24 at 11 46 00 PM" src="https://user-images.githubusercontent.com/46429/60032978-44a1c480-96da-11e9-9eca-863aae3efe05.png"> <img width="413" alt="Screen Shot 2019-06-24 at 11 45 16 PM" src="https://user-images.githubusercontent.com/46429/60032980-44a1c480-96da-11e9-8f41-df30fa74235b.png"> <img width="414" alt="Screen Shot 2019-06-24 at 11 45 08 PM" src="https://user-images.githubusercontent.com/46429/60032981-453a5b00-96da-11e9-92a3-63318a7bb5fa.png"> <img width="427" alt="Screen Shot 2019-06-24 at 11 45 00 PM" src="https://user-images.githubusercontent.com/46429/60032982-453a5b00-96da-11e9-8d63-453ecc94c827.png"> <img width="426" alt="Screen Shot 2019-06-24 at 11 44 56 PM" src="https://user-images.githubusercontent.com/46429/60032983-453a5b00-96da-11e9-86c4-e5db0f6d86a9.png">
1 parent c54f807 commit abdce96

16 files changed

+126
-106
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jsc-android",
3-
"version": "241213.2.0",
3+
"version": "245459.0.0",
44
"description": "Pre-build version of JavaScriptCore to be used by React Native apps",
55
"repository": {
66
"type": "git",
@@ -26,7 +26,7 @@
2626
"start": "./scripts/start.sh"
2727
},
2828
"config": {
29-
"webkitGTK": "2.22.6",
29+
"webkitGTK": "2.24.2",
3030
"chromiumICUCommit": "b34251f8b762f8e2112a89c587855ca4297fed96"
3131
}
3232
}

patches/jsc.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
--- target-org/webkit/Source/JavaScriptCore/CMakeLists.txt 2019-04-27 00:04:34.000000000 +0800
22
+++ target/webkit/Source/JavaScriptCore/CMakeLists.txt 2019-04-27 00:06:00.000000000 +0800
3-
@@ -1234,6 +1234,7 @@
3+
@@ -1304,6 +1304,7 @@
44
install(TARGETS JavaScriptCore DESTINATION "${LIB_INSTALL_DIR}")
55
endif ()
66
endif ()

patches/jsc_disable_icu.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
diff -aur target-org/webkit/Source/WTF/wtf/CMakeLists.txt target/webkit/Source/WTF/wtf/CMakeLists.txt
22
--- target-org/webkit/Source/WTF/wtf/CMakeLists.txt 2019-04-27 00:04:50.000000000 +0800
33
+++ target/webkit/Source/WTF/wtf/CMakeLists.txt 2019-04-27 00:14:29.000000000 +0800
4-
@@ -475,7 +475,6 @@
4+
@@ -482,7 +482,6 @@
55
list(APPEND WTF_SOURCES
66
unicode/CollatorDefault.cpp
77

patches/jsc_features.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
diff -aur target-org/webkit/CMakeLists.txt target/webkit/CMakeLists.txt
22
--- target-org/webkit/CMakeLists.txt 2017-12-22 19:18:43.000000000 +0200
33
+++ target/webkit/CMakeLists.txt 2018-06-14 15:41:59.000000000 +0300
4-
@@ -174,13 +174,13 @@
4+
@@ -177,13 +177,13 @@
55
add_subdirectory(Tools)
66
endif ()
77

@@ -42,7 +42,7 @@ diff -aur target-org/webkit/Source/cmake/OptionsJSCOnly.cmake target/webkit/Sour
4242
diff -aur target-org/webkit/Source/JavaScriptCore/CMakeLists.txt target/webkit/Source/JavaScriptCore/CMakeLists.txt
4343
--- target-org/webkit/Source/JavaScriptCore/CMakeLists.txt 2017-05-02 21:13:03.000000000 +0200
4444
+++ target/webkit/Source/JavaScriptCore/CMakeLists.txt 2017-07-11 11:34:55.962374878 +0200
45-
@@ -1221,7 +1225,7 @@
45+
@@ -1291,7 +1291,7 @@
4646
)
4747
target_include_directories(LLIntOffsetsExtractor SYSTEM PRIVATE ${JavaScriptCore_SYSTEM_INCLUDE_DIRECTORIES})
4848

patches/jsc_fix_arm64_jit_crash.patch

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
diff -aur target-org/webkit/Source/JavaScriptCore/assembler/ARM64Assembler.h target/webkit/Source/JavaScriptCore/assembler/ARM64Assembler.h
2+
--- target-org/webkit/Source/JavaScriptCore/assembler/ARM64Assembler.h 2019-06-18 21:49:21.000000000 +0800
3+
+++ target/webkit/Source/JavaScriptCore/assembler/ARM64Assembler.h 2019-06-19 15:14:46.000000000 +0800
4+
@@ -2863,7 +2863,36 @@
5+
6+
unsigned debugOffset() { return m_buffer.debugOffset(); }
7+
8+
-#if OS(LINUX) && COMPILER(GCC_COMPATIBLE)
9+
+#if defined(CUSTOMIZE_REACT_NATIVE) && CPU(ARM64)
10+
+ static inline void linuxPageFlush(uintptr_t start, uintptr_t end)
11+
+ {
12+
+ // NOTE(CUSTOMIZE_REACT_NATIVE): The code mostly copied from LLVM compiler-rt
13+
+ // https://github.com/llvm-mirror/compiler-rt/blob/ff75f2a0260b1940436a483413091c5770427c04/lib/builtins/clear_cache.c#L142
14+
+ // But only to modify "dc cvau" to "dc civac"
15+
+
16+
+ uint64_t xstart = (uint64_t)(uintptr_t)start;
17+
+ uint64_t xend = (uint64_t)(uintptr_t)end;
18+
+ uint64_t addr;
19+
+
20+
+ // Get Cache Type Info
21+
+ uint64_t ctr_el0;
22+
+ __asm __volatile("mrs %0, ctr_el0" : "=r"(ctr_el0));
23+
+
24+
+ // dc & ic instructions must use 64bit registers so we don't use
25+
+ // uintptr_t in case this runs in an IPL32 environment.
26+
+ const size_t dcache_line_size = 4 << ((ctr_el0 >> 16) & 15);
27+
+ for (addr = xstart & ~(dcache_line_size - 1); addr < xend;
28+
+ addr += dcache_line_size)
29+
+ __asm __volatile("dc civac, %0" ::"r"(addr));
30+
+ __asm __volatile("dsb ish");
31+
+
32+
+ const size_t icache_line_size = 4 << ((ctr_el0 >> 0) & 15);
33+
+ for (addr = xstart & ~(icache_line_size - 1); addr < xend;
34+
+ addr += icache_line_size)
35+
+ __asm __volatile("ic ivau, %0" ::"r"(addr));
36+
+ __asm __volatile("isb sy");
37+
+ }
38+
+#elif OS(LINUX) && COMPILER(GCC_COMPATIBLE)
39+
static inline void linuxPageFlush(uintptr_t begin, uintptr_t end)
40+
{
41+
__builtin___clear_cache(reinterpret_cast<char*>(begin), reinterpret_cast<char*>(end));

patches/jsc_fix_build_error_disable_dfg.patch

Lines changed: 0 additions & 71 deletions
This file was deleted.
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
diff -aur target-org/webkit/Source/WTF/wtf/linux/MemoryFootprintLinux.cpp target/webkit/Source/WTF/wtf/linux/MemoryFootprintLinux.cpp
2-
--- target-org/webkit/Source/WTF/wtf/linux/MemoryFootprintLinux.cpp 2018-11-11 23:05:48.000000000 +0800
3-
+++ target/webkit/Source/WTF/wtf/linux/MemoryFootprintLinux.cpp 2018-11-12 23:39:22.000000000 +0800
2+
--- target-org/webkit/Source/WTF/wtf/linux/MemoryFootprintLinux.cpp 2019-06-18 21:49:53.000000000 +0800
3+
+++ target/webkit/Source/WTF/wtf/linux/MemoryFootprintLinux.cpp 2019-06-18 22:44:39.000000000 +0800
44
@@ -23,6 +23,10 @@
55
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
66
*/
@@ -10,10 +10,11 @@ diff -aur target-org/webkit/Source/WTF/wtf/linux/MemoryFootprintLinux.cpp target
1010
+#if !defined(CUSTOMIZE_REACT_NATIVE)
1111
+
1212
#include "config.h"
13-
#include "MemoryFootprint.h"
13+
#include <wtf/MemoryFootprint.h>
1414

15-
@@ -107,3 +111,4 @@
15+
@@ -100,3 +104,5 @@
1616
}
1717

18-
}
18+
} // namespace WTF
19+
+
1920
+#endif // !defined(CUSTOMIZE_REACT_NATIVE)

patches/jsc_fix_build_error_log2.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
diff -aur target-org/webkit/Source/JavaScriptCore/Sources.txt target/webkit/Source/JavaScriptCore/Sources.txt
22
--- target-org/webkit/Source/JavaScriptCore/Sources.txt 2018-11-11 23:05:40.000000000 +0800
33
+++ target/webkit/Source/JavaScriptCore/Sources.txt 2018-11-12 00:03:26.000000000 +0800
4-
@@ -1045,3 +1045,6 @@
4+
@@ -1053,3 +1053,6 @@
55

66
// Derived Sources
77
yarr/YarrCanonicalizeUnicode.cpp
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
diff -aur target-org/webkit/Source/JavaScriptCore/assembler/PerfLog.cpp target/webkit/Source/JavaScriptCore/assembler/PerfLog.cpp
2+
--- target-org/webkit/Source/JavaScriptCore/assembler/PerfLog.cpp 2019-06-18 21:49:21.000000000 +0800
3+
+++ target/webkit/Source/JavaScriptCore/assembler/PerfLog.cpp 2019-06-18 23:12:38.000000000 +0800
4+
@@ -41,6 +41,10 @@
5+
#include <wtf/PageBlock.h>
6+
#include <wtf/ProcessID.h>
7+
8+
+#if defined(CUSTOMIZE_REACT_NATIVE)
9+
+#include <array>
10+
+#endif // defined(CUSTOMIZE_REACT_NATIVE)
11+
+
12+
namespace JSC {
13+
14+
namespace PerfLogInternal {
Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
1-
diff -aur target-org/webkit/Source/WTF/wtf/CheckedArithmetic.h target/webkit/Source/WTF/wtf/CheckedArithmetic.h
2-
--- target-org/webkit/Source/WTF/wtf/CheckedArithmetic.h 2018-07-26 17:00:09.000000000 +0800
3-
+++ target/webkit/Source/WTF/wtf/CheckedArithmetic.h 2019-04-12 12:03:55.000000000 +0800
4-
@@ -317,7 +317,7 @@
5-
1+
--- target-org/webkit/Source/WTF/wtf/CheckedArithmetic.h 2019-06-18 21:49:53.000000000 +0800
2+
+++ target/webkit/Source/WTF/wtf/CheckedArithmetic.h 2019-06-18 22:44:39.000000000 +0800
3+
@@ -360,7 +360,7 @@
4+
65
static inline bool multiply(LHS lhs, RHS rhs, ResultType& result) WARN_UNUSED_RETURN
76
{
8-
-#if COMPILER(GCC_OR_CLANG)
9-
+#if COMPILER(GCC_OR_CLANG) && CPU(ARM_THUMB2) && defined(NDEBUG)
7+
-#if COMPILER(GCC_COMPATIBLE)
8+
+#if COMPILER(GCC_COMPATIBLE) && CPU(ARM_THUMB2) && defined(NDEBUG)
109
ResultType temp;
1110
if (__builtin_mul_overflow(lhs, rhs, &temp))
1211
return false;
13-
@@ -390,7 +390,7 @@
14-
12+
@@ -433,7 +433,7 @@
13+
1514
static inline bool multiply(LHS lhs, RHS rhs, ResultType& result) WARN_UNUSED_RETURN
1615
{
17-
-#if COMPILER(GCC_OR_CLANG)
18-
+#if COMPILER(GCC_OR_CLANG) && CPU(ARM_THUMB2) && defined(NDEBUG)
16+
-#if COMPILER(GCC_COMPATIBLE)
17+
+#if COMPILER(GCC_COMPATIBLE) && CPU(ARM_THUMB2) && defined(NDEBUG)
1918
ResultType temp;
2019
if (__builtin_mul_overflow(lhs, rhs, &temp))
2120
return false;
22-
@@ -453,7 +453,7 @@
23-
21+
@@ -496,7 +496,7 @@
22+
2423
static inline bool multiply(int64_t lhs, int64_t rhs, ResultType& result)
2524
{
26-
-#if COMPILER(GCC_OR_CLANG)
27-
+#if COMPILER(GCC_OR_CLANG) && CPU(ARM_THUMB2) && defined(NDEBUG)
25+
-#if COMPILER(GCC_COMPATIBLE)
26+
+#if COMPILER(GCC_COMPATIBLE) && CPU(ARM_THUMB2) && defined(NDEBUG)
2827
ResultType temp;
2928
if (__builtin_mul_overflow(lhs, rhs, &temp))
3029
return false;

0 commit comments

Comments
 (0)