chakra-core / ChakraCore

ChakraCore is an open source Javascript engine with a C API.
MIT License
9.1k stars 1.2k forks source link

Support macOS ARM64 (Apple silicon) without JIT #6869

Closed rhuanjl closed 1 year ago

rhuanjl commented 1 year ago

This is a working port of ChakraCore for Apple Silicon, though jit support requires further work and will be left for a follow up PR.

Work done:

ref: #6860

@ppenzin

rhuanjl commented 1 year ago

This may be just about there for --no-jit We still don't have online ARM64 CI but... here's the offline test results:

############# ChakraCore Test Suite #############
Testing Debug build
Using 8 threads

############# Starting disable_jit tests #############
  exclude: exclude_interpreted
  exclude: slow
  exclude: exclude_xplat
  exclude: fails_disable_jit
  exclude: fails_interpreted
  exclude: require_winglob
  exclude: require_simd
  exclude: exclude_x64
  exclude: exclude_debug
  exclude: exclude_disable_jit
  exclude: exclude_amd64
  exclude: fail
  exclude: exclude_mac
  exclude: require_backend

############ Results for disable_jit tests ###########
262: passed 1, failed 0
Array: passed 124, failed 0
Basics: passed 51, failed 0
BigInt: passed 11, failed 0
Boolean: passed 3, failed 0
Bugs: passed 102, failed 0
Closures: passed 29, failed 0
ControlFlow: passed 17, failed 0
Conversions: passed 5, failed 0
Date: passed 10, failed 0
Debugger: passed 19, failed 0
DebuggerCommon: passed 207, failed 0
DynamicCode: passed 1, failed 0
EH: passed 40, failed 0
Error: passed 25, failed 0
Function: passed 77, failed 0
GlobalFunctions: passed 14, failed 0
InlineCaches: passed 24, failed 0
Intl: passed 16, failed 0
JSON: passed 16, failed 0
LetConst: passed 63, failed 0
Lib: passed 11, failed 0
Math: passed 9, failed 0
Miscellaneous: passed 10, failed 0
Number: passed 11, failed 0
Object: passed 65, failed 0
Operators: passed 29, failed 0
Prototypes: passed 9, failed 0
RWC: passed 1, failed 0
RegAlloc: passed 1, failed 0
Regex: passed 41, failed 0
Scanner: passed 3, failed 0
StackTrace: passed 18, failed 0
Strings: passed 43, failed 0
TTBasic: passed 142, failed 0
TTExecuteBasic: passed 28, failed 0
TaggedIntegers: passed 23, failed 0
TryCatch: passed 1, failed 0
UnifiedRegex: passed 22, failed 0
UnitTestFramework: passed 1, failed 0
es5: passed 59, failed 0
es6: passed 244, failed 0
es6module: passed 31, failed 0
es7: passed 24, failed 0
fieldopts: passed 122, failed 0
loop: passed 10, failed 0
strict: passed 107, failed 0
switchStatement: passed 26, failed 0
typedarray: passed 60, failed 0
utf8: passed 9, failed 0
----------------------------
Total: passed 2015, failed 0
Time taken for disable_jit tests: 227.45 seconds
rhuanjl commented 1 year ago

Found and enabled working arm CI (Cirrus CI) - will need additional configurations, currently it's just testing a no-jit Test build. Everything is looking promising.

The Jit still needs some work - the calling convention is different so the function prologue and epilogue code is not usable nor is the code for generating a Call. Hopefully total diff to fix this will only be ~200 lines but it's complex stuff.

pleath commented 1 year ago

I don't know whether this has come up before, but to run jitted code on a non-Windows target the JIT will also need to generate whatever exception info the ABI requires, i.e., the equivalent of pdata + xdata.

rhuanjl commented 1 year ago

I don't know whether this has come up before, but to run jitted code on a non-Windows target the JIT will also need to generate whatever exception info the ABI requires, i.e., the equivalent of pdata + xdata.

I'd seen in the source tree that I'd need to look at this but haven't given it much thought yet - I have been (perhaps naively) hoping that it will not be too hard to figure out once I have the basic functionality of the jit working - the relevant logic is there for apple/linux on amd64 which I hope to be able to model off of.

rhuanjl commented 1 year ago

FYI for anyone following this, considering the size/scale of this I'm going to try and clean it up, sort out the license and style issues (and possibly get it to work on linux arm64 too which should be a small step) then land it without JIT support for now, I intent to continue to work on the JIT as a follow up.

rhuanjl commented 1 year ago

@ppenzin I have had some difficulty getting a functional arm64 linux vm going so leaving this as just macOS arm64 support for now - also as discussed, leaving the JIT for the time being.

Allowing for linux support and Jit support as future work I think this is ready. Please could you review what's here?

ppenzin commented 1 year ago

One more suggestion, but overall looks good.