Summary:
This diff implement the "perform a microtask checkpoint" algorithm
as library functions under `namespace microtask` in `ConsoleHost.h`,
shared by `ConsoleHost.cpp` and `repl.cpp`.
It's currently behind the same experiment flag to be consistent
with the Promise internal bytecode.
Reviewed By: avp
Differential Revision: D27549343
fbshipit-source-id: bfb705150f7d0df0369ce1c5f6bc7b1daaf6f4ee
Summary:
Currently, task queue are flushed after errors thrown in REPL but
not ConsoleHost, resulting in different behaviors.
This diff change the ConsoleHost to flush the queue regardless
whether an error was thrown, making `hermes` CLI behavior closer
to other engine, Web Browsers, and Node.
Reviewed By: avp
Differential Revision: D27549344
fbshipit-source-id: 905665428aaf499b80fcbcd8ea940fc46dc8252a
Summary:
Since Hermes now implemented the ECMA-262 notion of Job, the
existing uses of name `job` in the REPL/ConsoleHost need to be
renamed to the standard name `task` to disambiguate.
Reviewed By: avp
Differential Revision: D27549345
fbshipit-source-id: cd17cbc44a77ff03c1ca452c2883b3e136c8ffa7
Summary:
The JIT code was experimental and no longer works properly.
Delete it.
Reviewed By: dulinriley
Differential Revision: D27302056
fbshipit-source-id: 9d46f9baff082d3bb89af7c2dd5cf34b01b6feb1
Summary:
The "crash trace" records:
- Segment ID, source URL and source hash of the runtime module of the
latest bytecode function
- File-relative offsets and the opcodes of the last eight instructions.
To compile in the new functionality, there is a new build mode
controlled by the preprocessor define `HERMESVM_CRASH_TRACE`. It must be
set to `1` to enable it (because we check the value in C++ code).
In CMake there is an option with the same name, in Buck the mode is
called `hermes.crash_trace`.
Once compiled in, at runtime it is controlled by
`vm::experiments::CrashTrace = 1 << 13`. From the CLI:
hermes -Xvm-experiment-flags=8192 file.hbc
When enabled, execution time increased by about 45%.
Reviewed By: neildhar
Differential Revision: D26323871
fbshipit-source-id: c203046eefd05f9643d3e6d69a8fb9198d511e66
Summary: Adds a `-Xheap-timeline` option to the Hermes CLI which enables heap allocation tracking at startup. This is useful for getting a simple heap timeline from a minimal Hermes integration and iterating on tools that consume this data.
Reviewed By: dulinriley
Differential Revision: D26016961
fbshipit-source-id: 3f58e5f3c64633af010cdec53fc1e1dffa433c47
Summary:
Only register a runtime with the sampling profiler on startup if the
RuntimeConfig says so. To avoid breaking any existing code, set it to
true by default.
Since the config is now true by default, we should explicitly pass
the command line sampling profiler flag to ConsoleHost.cpp.
Reviewed By: tmikov
Differential Revision: D25896384
fbshipit-source-id: a13b6e16370604f466774ea768bc174a322ec386
Summary:
Make some sampling profiler methods static, by calling `getInstance`
internally. These static functions will be the "public" API for the
sampling profiler.
Later diffs will separate out the global state, so making these
functions static is a way of hiding the implementation details of the
sampling profiler.
Reviewed By: dulinriley
Differential Revision: D25728898
fbshipit-source-id: f9f2773dd0501de86299240ae020ff6c0af1fef1
Summary:
Move all overloads used for handling roots into `RootAcceptor`.
Create a new `RootAndSlotAcceptor` that inherits from both
`RootAcceptor` and `SlotAcceptor`, and can be used for most GC
acceptors.
Reviewed By: dulinriley
Differential Revision: D25277113
fbshipit-source-id: 1dda2c2934f0bb844fe5a6d06700b1812e3f81ef
Summary:
Every CallResult should be checked before using. This one wasn't, so we
would crash if an exception had been thrown.
Add a test.
Reviewed By: neildhar, avp
Differential Revision: D25237078
fbshipit-source-id: da47e6d4e03c0b1b8ba048bf070ae0098549a0e0
Summary:
The `Promise` polyfill requires `setTimeout` and `setImmediate`
to function properly. Add simple versions of these which simply
enqueue onto a job queue which is repeatedly drained until empty.
This allows us to make Hermes aware of `Promise` without changing
any actual functionality in any existing hosts (i.e. RN).
Note that because these functions are only set on ConsoleHost,
users such as RN still use their existing event loop and timer structure,
which allows us to simply swap to a Promise implementation that Hermes
is aware of without incurring any extra cost of changing code outside
of this one specific polyfill.
Reviewed By: tmikov
Differential Revision: D20225268
fbshipit-source-id: fd4a518cf7adaab6bf860f8d44b8190a866116af
Summary:
When logging when a GC occurs, it's good to know if the GC was forced,
or was part of the natural allocation paths. This allows us to see if
there are too many forced GCs in apps.
Reviewed By: neildhar
Differential Revision: D23737916
fbshipit-source-id: fd8d6068bed14197b752c3a012f72c1309bc8311
Summary:
Change the LLVH include path from `llvm/` to `llvh/`, rename the namespace to
`llvh`. This should eliminate any conflicts with the "real" LLVM.
(Note: this ignores all push blocking failures!)
Reviewed By: dulinriley
Differential Revision: D22202846
fbshipit-source-id: bbcabd8439e03e1457939ef5a8dad19f1d1a2f5c
Summary:
`installConsoleBindings` calls `defineOwnProperty` a lot.
If we add enough calls to `installConsoleBindings`, the handle count
will overflow.
Fix this by adding a marker in `defineGlobalFunc` to avoid handle
proliferation.
Reviewed By: dulinriley
Differential Revision: D21645003
fbshipit-source-id: 0b0047e1665f126985126bf6f322c58f45f5d74c
Summary:
Converting `PseudoHandle` to `Handle` required a `toHandle` function
which didn't follow the pattern for any other Handle creation functions.
Remove `toHandle` and add an overload to `HandleRootOwner::makeHandle`
which allows for the same functionality.
Reviewed By: tmikov
Differential Revision: D19437464
fbshipit-source-id: 40cbab42fd3f008fd319160cf4dd2e0a8c886e64
Summary:
Instead of returning a `bool` which gives no information about the cause of the error,
return `void` and throw when there's some error.
Another alternative is returning `std::error_code`, but that's less flexible than throwing, and
this API already supports throwing.
Changelog: [Internal]
Reviewed By: jbower-fb
Differential Revision: D19170033
fbshipit-source-id: 870cd996a1a53c94524455f31765c1da99f57a1d
Summary:
Place a fork of LLVM git rev c179d7b006348005d2da228aed4c3c251590baa3
under `external/llvh`(1) and modify the CMake build to use it.
I am calling it a "fork", because it is not all of LLVM. Only the parts
that are used by Hermes are included, which at this time is only parts
of `libLLVMSupporrt`. Most(2) of LLVM build scripts are removed, and it
is treated just as another ordinary library.
(1) Why `llvh`? To be able to coexist with instances of the "real" LLVM,
we must change the namespace, all public symbols containing the `llvm`
string and the include directory name. `llvh` seemed as good a name as
any. I also considered `llvm-h` and `h-llvm`, but the problem is that
they are a superstring of `llvm` so it becomes harder to search for the
`llvm` string.
Note that the actual rename will happen in a follow up diff. It would be
a massive patch.
(2) libLLVMSupport relies on pretty elaborate feature detection scripts,
which would be painful to duplicate, so for now I have preserved them
under external/llvh/cmake.
Unfortunately turning LLVM into an ordinary library is not enough, since
we were implicitly relying on a lot of functionality provided by the
LLVM build scripts. Things like setting default warning flags, easily
turning exceptions on and off, etc.
I attempted to replace it with Hermes equivalents, which are now
provided by `cmake/Hermes.cmake`:
- `add_llvm_library/tool()` is replaced by `add_hermes_library/tool()`.
- Several `LLVM_xxx` variables are replaced my similar `HERMES_xxx`
ones.
As a result, building Hermes now requires only checking it out, and
running CMake and Ninja. It is a vastly simpler process than before.
== Limitations
- CMake LTO and ASAN builds aren't supported yet.
- The JIT requires the "real" LLVM for disassembly.
Reviewed By: avp
Differential Revision: D19658656
fbshipit-source-id: 5094d2af45e343973b1aab02c550a18b2bf93a06
Summary:
The script ID for a `RuntimeModule` was set and maintained by the debugger before,
but other callers might want to access this information.
Instead make it a field on `RuntimeModule`.
Note that in the case of lazy compilation, the script ID is only set on the root module, so make sure
to always access the script ID from there first.
Reviewed By: willholen
Differential Revision: D18740080
fbshipit-source-id: 8228bd1a780acb9352bd5a2a672c33b0d7d252c1
Summary: There are 2 static methods for creating commonly used DefinePropertyFlags. This change calls them instead of manually setting the flags where applicable.
Reviewed By: dulinriley
Differential Revision: D18969078
fbshipit-source-id: 9aedbd5c7ccdf8efb0a2a66346ea3fd7b2d34fa9
Summary:
This parameter used to be useful for a custom format hermes was developing,
but since Hermes now outputs the Chrome format it isn't useful.
Chrome actually disallows prettified JSON, and requires a special version that is faster to parse.
Therefore, `compact` was the only supported mode.
Changelog: [Internal] Remove compact parameter from `createSnapshotToFile`
Reviewed By: willholen
Differential Revision: D17726742
fbshipit-source-id: 6f39af9046dff2f3b4fba822312a9a89c939ed89
Summary:
The serializer wasn't buildable with CMake and had some compilation
errors when enabled. There was one actual bug: a missing "break;" when
deserializing an IdentifierTable entry.
Reviewed By: kodafb
Differential Revision: D17896920
fbshipit-source-id: a967cc5604a858306e5e60f0273438a5eb1550f5
Summary:
Add a (hidden) option `-stable-instruction-count` to be used for testing only. It makes the VM try hard to execute the same number of CPU instructions across repeated invocations of the same JS. It currently does this by silencing stats logging (since printing time measurements is problematic), and fixing the seed for Math.random. It does *not* handle Date, which is still a possible source of non-determinism, unless it's mocked as part of a synthetic trace.
One use case is to track down which change, from a large stack or time interval, affects instruction counts more than expected.
Reviewed By: dulinriley
Differential Revision: D17907769
fbshipit-source-id: d2ca6d5943ad5396753d94a9072e405c1035d495
Summary:
Dynamic handle casts used to need a `Runtime *` parameter, in
order to be able to get to a nullptr PinnedHermesValue.
Move constant instances of PinnedHermesValue to the data segment,
eliminating the need of the parameter. This causes a lot of changes, but
they are trivial.
Reviewed By: kodafb
Differential Revision: D17277964
fbshipit-source-id: 1a79725cdfc4c3ef6ac18358d24b598aaeff98b3
Summary:
Added tests for serialization/deserialization after user code. Note:
Most GCCells have their own test, but some GCCells like HiddenClass and
PropertyAccessor are implicitly tested with other tests.
Reviewed By: avp
Differential Revision: D16773021
fbshipit-source-id: 2c58820f475655c0734e0208e77a723133f40cf8
Summary:
To be able to trigger Serialization after user code, add serializeVM to allow
user to call `serializeVM(string filename, function() {/*resumed;*/})` to start a Serialization. When deserialize, we will resume to execute the function closure after reconstructing the Runtime.
Also allow Serializer/Deserializer to map external pointers to relocation ids.
Reviewed By: avp
Differential Revision: D16523696
fbshipit-source-id: 31a8bad51e98ae569c4b713653db560346800f01
Summary:
Remove build mode for TimeLimit and allow debugger and timelimit to co-exist by sharing the same flag.
It also uses uncatchable JS error instead of C++ exception for time limit.
Reviewed By: davedets, ridiculousfish
Differential Revision: D16657227
fbshipit-source-id: 5c923128940062f01f78f25031cd596df8fcbd66
Summary: When running in CLI mode and execution throws a C++ exception (e.g. due to HERMESVM_EXCEPTION_ON_OOM), ensure that the stack is unwound enough to destroy the Runtime instance before calling exit. Otherwise, leak sanitizers will (rightly) say that we leaked everything.
Reviewed By: davedets
Differential Revision: D16919914
fbshipit-source-id: ba2b2d96ca2e87bc861afc592b7933535111ef6b
Summary:
Now we put everything together and are able to Serialize/Deserialize the VM right after global
object initialization. Serialize/Deserialize currently implemented as flags that takes a string to
specify the file to write to/read from.
Tests will be provided in a later commit in the stack.
Reviewed By: dulinriley
Differential Revision: D16273383
fbshipit-source-id: 9f325aed822b1888cfe6090260fb05515a1288c6
Summary:
Add option to force GC before printing stats when running a synth trace on the command-line. This allows measuring the live data when execution stopped at some interesting marker (under "heapInfo"->"Allocated bytes"). This enables estimating the impact of a diff on the live size of an application (rather than just total allocation, or allocated after the last organic collection).
Also add it for the hermes command-line tool, mostly for consistency.
Reviewed By: dulinriley
Differential Revision: D16603771
fbshipit-source-id: 69421e623a0cdc72e2071ee980fa100d0b2d6ded
Summary:
1. Introduce a new `-time-limit` command line option as the entrypoint to this feature.
2. Enforce debugger and timelimit features can't be used at the same time.
3. Use this feature from console binary
Reviewed By: davedets
Differential Revision: D16425598
fbshipit-source-id: c59e83ca74b999b9fc67e0e9b6f4649c22f06e03
Summary:
We call `dumpSampledStack` to dump the stack frames in more readable format in console mode for debugging purpose. However, this makes the output mixed with chrome trace format output.
This diff removes the `dumpSampledStack` call.
Reviewed By: dulinriley
Differential Revision: D16451992
fbshipit-source-id: 842856272c219bd56ac5c8cc94ab84a3736df882
Summary:
`HermesInternal.createHeapSnapshot` had duplicated functionality with `createHeapSnapshot`
which was defined in the Hermes CLI.
Delete `HermesInternal.createHeapSnapshot` to avoid confusion, and to avoid exposing it in production
scenarios (which don’t even have “stderr”).
Reviewed By: avp
Differential Revision: D16172171
fbshipit-source-id: ab904946dc94f156d31f726a72dbccf3e05672a8