Граф коммитов

40 Коммитов

Автор SHA1 Сообщение Дата
Xuan Huang b8592a0609 Perform microtask checkpoints in ConsoleHost & REPL
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
2021-04-22 13:29:04 -07:00
Xuan Huang 07c4fcadb0 Task queue need to be flushed regardless of error
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
2021-04-22 13:29:04 -07:00
Xuan Huang fec76fd67a Rename REPL/ConsoleHost's notion of Job to Task
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
2021-04-22 13:29:04 -07:00
Aakash Patel 70e43dda90 Remove JIT
Summary:
The JIT code was experimental and no longer works properly.
Delete it.

Reviewed By: dulinriley

Differential Revision: D27302056

fbshipit-source-id: 9d46f9baff082d3bb89af7c2dd5cf34b01b6feb1
2021-03-25 12:50:58 -07:00
Neil Dhar 46c325308c Use std::make_unique (#458)
Summary:
Pull Request resolved: https://github.com/facebook/hermes/pull/458

Update all uses outside llvh to std::make_unique.

Reviewed By: dulinriley

Differential Revision: D26495331

fbshipit-source-id: a5f8a74ccc462a1ebe36bd7ee2675ba0f543bb6b
2021-02-23 19:51:53 -08:00
Tzvetan Mikov eaf1b66792 optionally record a trace of the last 8 instructions
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
2021-02-13 09:55:29 -08:00
Moti Zilberman c0cccb9c6e Allow taking heap timelines in ConsoleHost
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
2021-02-08 07:40:30 -08:00
Neil Dhar 9e1b2d9ffc Only register runtime when profiling is enabled
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
2021-01-19 23:54:33 -08:00
Neil Dhar 889abf1d6f Static API for sampling profiler
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
2021-01-13 07:36:24 -08:00
Neil Dhar 78e05ef730 Narrow root acceptor types
Summary:
Use RootAcceptor instead of RootAndSlotAcceptor in root marking
functions.

Reviewed By: dulinriley

Differential Revision: D25746361

fbshipit-source-id: 376ee55c8dfe45600959bd6302ebb997146b8d63
2021-01-04 17:33:48 -08:00
Neil Dhar abb119d3bf Move root overloads into RootAcceptor
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
2020-12-03 00:33:32 -08:00
Tzvetan Mikov 6d00d8c8cf check CallResult in setTimeout()
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
2020-11-30 21:17:10 -08:00
Xuan Huang 0812b40642 Add ConsoleHost functions to allow Promise polyfilling.
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
2020-10-15 11:42:35 -07:00
Riley Dulin 1d8d495fe6 Add cause to GCAnalyticsEvent
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
2020-09-18 10:35:14 -07:00
Tzvetan Mikov b8cf556d9e return type error in loadSegment
Summary: Ensure error conditions return error in loadSegment.

Reviewed By: avp

Differential Revision: D23613707

fbshipit-source-id: 86358666b3bd8f3057270bcde6b4e28e53c59f8a
2020-09-10 16:59:22 -07:00
Tzvetan Mikov 4f15a2e8af rename LLVM to LLVH
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
2020-07-01 04:39:48 -07:00
Aakash Patel b94d475946 Add a marker in installConsoleBindings.
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
2020-05-19 13:18:25 -07:00
Aakash Patel 8d8963f250 Clean up some includes in VM.
Summary: .

Reviewed By: tmikov

Differential Revision: D20877431

fbshipit-source-id: 72bc1c5c148982609b995f2d9e933457353fb7eb
2020-04-10 11:56:01 -07:00
Aakash Patel 45b85e15f6 Remove toHandle and overload makeHandle for PseudoHandle.
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
2020-02-21 16:30:55 -08:00
Riley Dulin de21c7bd5a Have heap snapshots throw std::system_error instead of return a bool
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
2020-02-12 17:11:27 -08:00
Tzvetan Mikov 611cac5669 Use internal fork of LLVM
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
2020-02-06 00:34:00 -08:00
Riley Dulin 521564b479 Move scriptID to the RuntimeModule itself
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
2019-12-20 20:05:55 -08:00
Kiwi Chen 6be64ad397 Cleanup some manual setup of DefinePropertyFlags
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
2019-12-12 19:23:33 -08:00
Riley Dulin f24ba53251 Remove compact parameter from heap snapshots
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
2019-10-31 14:47:22 -07:00
Tzvetan Mikov ee3830089e Fixes to the serializer
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
2019-10-16 22:13:58 -07:00
Andres Suarez fdd3817f87 Tidy up license headers [1/2]
Reviewed By: dulinriley

Differential Revision: D17858735

fbshipit-source-id: 52d28f92f791da8db6c671d9f75657c53f724f89
2019-10-15 12:34:49 -07:00
Daniel Andersson 0f1d9db068 Add "-stable-instruction-count" option for repeatable CPU instr. count
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
2019-10-14 17:09:05 -07:00
Tzvetan Mikov ecf72eef03 remove Runtime parameter of dynamic handle casts
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
2019-09-10 15:21:23 -07:00
Lun Liu 7c9b958aaf Tests for Serialization/Deserialization after user code.
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
2019-09-03 12:14:43 -07:00
Lun Liu 96ef748ad6 Add serializeVM() to trigger Serialization from js code.
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
2019-09-03 12:14:42 -07:00
Jeffrey Tan aa74fc3a5c Allow Debugger and TimeLimit share the same flag
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
2019-08-23 12:58:06 -07:00
Daniel Andersson 36a17412d2 Destroy Runtime when it throws a C++ exception
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
2019-08-22 10:26:06 -07:00
Lun Liu 3f9208438b Wrap Serialize/Deserialize code blocks in #ifdef.
Summary: Move Serialize/Deserialize code blocks in #ifdef sections. Add build mode.

Reviewed By: avp

Differential Revision: D16471743

fbshipit-source-id: e047e1ebed758a9d8e77abbf83a0ea973ab8109a
2019-08-08 00:05:15 -07:00
Lun Liu eca5299447 Serialize/Deserialize of VM states after global object initialization.
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
2019-08-08 00:05:14 -07:00
Daniel Andersson cab0dc7609 Add option to force GC before printing stats
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
2019-08-01 14:05:12 -07:00
Jeffrey Tan 4f2f52fbaf Catch and report any OOM/Timelimit exceptions in console mode
Summary: Catch and report any OOM/Timelimit exceptions in console mode

Reviewed By: davedets

Differential Revision: D16426187

fbshipit-source-id: a69c4966e588db006a04fc3e4ed941d80a49109b
2019-07-26 16:34:37 -07:00
Jeffrey Tan 78a597bf4b Add command line option in hermes console binary
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
2019-07-26 16:34:36 -07:00
Jeffrey Tan a8ae1d52cb Stop dumping debugging stack frames for sampling profiler
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
2019-07-23 18:30:59 -07:00
Riley Dulin a311b71ce1 Remove duplicate createHeapSnapshot function
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
2019-07-15 12:27:27 -07:00
Will Holen f22a18f67d Initial commit
fbshipit-source-id: 75e378602933ab4aa91677dfa509a67063e64516
2019-07-10 09:43:55 -07:00