@nativue/core 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Package.swift +26 -2
- package/android/build.gradle.kts +2 -2
- package/cli/nativue.mjs +20 -20
- package/cli/symbolicate.mjs +3 -5
- package/ios/Bridge.swift +132 -100
- package/ios/JavaScriptRuntime/JavaScriptRuntime.mm +231 -0
- package/ios/JavaScriptRuntime/include/NativueJavaScriptRuntime.h +29 -0
- package/ios/JavaScriptRuntime/vendor/hermes/LICENSE +21 -0
- package/ios/JavaScriptRuntime/vendor/hermes/Public/CrashManager.h +107 -0
- package/ios/JavaScriptRuntime/vendor/hermes/Public/CtorConfig.h +145 -0
- package/ios/JavaScriptRuntime/vendor/hermes/Public/GCConfig.h +211 -0
- package/ios/JavaScriptRuntime/vendor/hermes/Public/GCTripwireContext.h +40 -0
- package/ios/JavaScriptRuntime/vendor/hermes/Public/HermesExport.h +14 -0
- package/ios/JavaScriptRuntime/vendor/hermes/Public/RuntimeConfig.h +141 -0
- package/ios/JavaScriptRuntime/vendor/hermes/Public/SamplingProfiler.h +270 -0
- package/ios/JavaScriptRuntime/vendor/hermes/hermes.h +242 -0
- package/package.json +1 -1
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include "hermes/Public/CtorConfig.h"
|
|
11
|
+
#include "hermes/Public/GCTripwireContext.h"
|
|
12
|
+
|
|
13
|
+
#include <algorithm>
|
|
14
|
+
#include <cassert>
|
|
15
|
+
#include <chrono>
|
|
16
|
+
#include <cstdint>
|
|
17
|
+
#include <functional>
|
|
18
|
+
#include <limits>
|
|
19
|
+
#include <memory>
|
|
20
|
+
#include <string>
|
|
21
|
+
#include <vector>
|
|
22
|
+
|
|
23
|
+
namespace hermes {
|
|
24
|
+
namespace vm {
|
|
25
|
+
|
|
26
|
+
/// A type big enough to accomodate the entire allocated address space.
|
|
27
|
+
/// Individual allocations are always 'uint32_t', but on a 64-bit machine, when
|
|
28
|
+
/// compressed pointer is OFF, we want to accommodate a larger total heap.
|
|
29
|
+
using gcheapsize_t = size_t;
|
|
30
|
+
|
|
31
|
+
/// Represents a value before and after an event.
|
|
32
|
+
/// NOTE: Not a std::pair because using the names are more readable than first
|
|
33
|
+
/// and second.
|
|
34
|
+
struct BeforeAndAfter {
|
|
35
|
+
uint64_t before;
|
|
36
|
+
uint64_t after;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
struct GCAnalyticsEvent {
|
|
40
|
+
/// The same value as \p Name from GCConfig. Stored here for simplicity of
|
|
41
|
+
/// the API since this is passed in callbacks that might not be able to store
|
|
42
|
+
/// the name. For a given Runtime, this will be the same value every time.
|
|
43
|
+
std::string runtimeDescription;
|
|
44
|
+
|
|
45
|
+
/// The kind of GC this was. For a given Runtime, this will be the same value
|
|
46
|
+
/// every time.
|
|
47
|
+
std::string gcKind;
|
|
48
|
+
|
|
49
|
+
/// The type of collection that ran, typically differentiating a "young"
|
|
50
|
+
/// generation GC and an "old" generation GC. When other values say they're
|
|
51
|
+
/// "scoped to the collectionType", it means that for a generation GC
|
|
52
|
+
/// they're only reporting the numbers for that generation.
|
|
53
|
+
std::string collectionType;
|
|
54
|
+
|
|
55
|
+
/// The cause of this GC. Can be an arbitrary string describing the cause.
|
|
56
|
+
/// Typically "natural" is used to mean that the GC decided it was time, and
|
|
57
|
+
/// other causes mean it was forced by some other condition.
|
|
58
|
+
std::string cause;
|
|
59
|
+
|
|
60
|
+
/// The wall time a collection took from start to end.
|
|
61
|
+
std::chrono::milliseconds duration;
|
|
62
|
+
|
|
63
|
+
/// The CPU time a collection took from start to end. This time measure will
|
|
64
|
+
/// exclude time waiting on disk, mutexes, or time spent not scheduled to run.
|
|
65
|
+
std::chrono::milliseconds cpuDuration;
|
|
66
|
+
|
|
67
|
+
/// The number of bytes allocated in the heap before and after the collection.
|
|
68
|
+
/// measurement does not include fragmentation, and is the same as the sum of
|
|
69
|
+
/// all sizes in calls to \p GC::makeA into that generation (including any
|
|
70
|
+
/// rounding up the GC does).
|
|
71
|
+
/// The value is scoped to the \p collectionType.
|
|
72
|
+
BeforeAndAfter allocated;
|
|
73
|
+
|
|
74
|
+
/// The number of bytes in use by the heap before and after the collection.
|
|
75
|
+
/// This measurement can include fragmentation if the \p gcKind has that
|
|
76
|
+
/// concept.
|
|
77
|
+
/// The value is scoped to the \p collectionType.
|
|
78
|
+
BeforeAndAfter size;
|
|
79
|
+
|
|
80
|
+
/// The number of bytes external to the JS heap before and after the
|
|
81
|
+
/// collection.
|
|
82
|
+
/// The value is scoped to the \p collectionType.
|
|
83
|
+
BeforeAndAfter external;
|
|
84
|
+
|
|
85
|
+
/// The ratio of cells that survived the collection to all cells before
|
|
86
|
+
/// the collection. Note that this is in term of sizes of cells, not the
|
|
87
|
+
/// numbers of cells. Excludes any cells not in direct use by the JS program,
|
|
88
|
+
/// such as FillerCell or FreelistCell.
|
|
89
|
+
/// The value is scoped to the \p collectionType.
|
|
90
|
+
double survivalRatio;
|
|
91
|
+
|
|
92
|
+
/// A list of metadata tags to annotate this event with.
|
|
93
|
+
std::vector<std::string> tags;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/// Parameters to control a tripwire function called when the live set size
|
|
97
|
+
/// surpasses a given threshold after collections. Check documentation in
|
|
98
|
+
/// README.md
|
|
99
|
+
#define GC_TRIPWIRE_FIELDS(F) \
|
|
100
|
+
/* If the heap size is above this threshold after a collection, the tripwire \
|
|
101
|
+
* is triggered. */ \
|
|
102
|
+
F(constexpr, gcheapsize_t, Limit, std::numeric_limits<gcheapsize_t>::max()) \
|
|
103
|
+
\
|
|
104
|
+
/* The callback to call when the tripwire is considered triggered. */ \
|
|
105
|
+
F(HERMES_NON_CONSTEXPR, \
|
|
106
|
+
std::function<void(GCTripwireContext &)>, \
|
|
107
|
+
Callback, \
|
|
108
|
+
nullptr) \
|
|
109
|
+
/* GC_TRIPWIRE_FIELDS END */
|
|
110
|
+
|
|
111
|
+
_HERMES_CTORCONFIG_STRUCT(GCTripwireConfig, GC_TRIPWIRE_FIELDS, {})
|
|
112
|
+
|
|
113
|
+
#undef HEAP_TRIPWIRE_FIELDS
|
|
114
|
+
|
|
115
|
+
#define GC_HANDLESAN_FIELDS(F) \
|
|
116
|
+
/* The probability with which the GC should keep moving the heap */ \
|
|
117
|
+
/* to detect stale GC handles. */ \
|
|
118
|
+
F(constexpr, double, SanitizeRate, 0.0) \
|
|
119
|
+
/* Random seed to use for basis of decisions whether or not to */ \
|
|
120
|
+
/* sanitize. A negative value will mean a seed will be chosen at */ \
|
|
121
|
+
/* random. */ \
|
|
122
|
+
F(constexpr, int64_t, RandomSeed, -1) \
|
|
123
|
+
/* GC_HANDLESAN_FIELDS END */
|
|
124
|
+
|
|
125
|
+
_HERMES_CTORCONFIG_STRUCT(GCSanitizeConfig, GC_HANDLESAN_FIELDS, {})
|
|
126
|
+
|
|
127
|
+
#undef GC_HANDLESAN_FIELDS
|
|
128
|
+
|
|
129
|
+
/// How aggressively to return unused memory to the OS.
|
|
130
|
+
enum ReleaseUnused {
|
|
131
|
+
kReleaseUnusedNone = 0, /// Don't try to release unused memory.
|
|
132
|
+
kReleaseUnusedOld, /// Only old gen, on full collections.
|
|
133
|
+
kReleaseUnusedYoungOnFull, /// Also young gen, but only on full collections.
|
|
134
|
+
kReleaseUnusedYoungAlways /// Also young gen, also on young gen collections.
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
enum class GCEventKind {
|
|
138
|
+
CollectionStart,
|
|
139
|
+
CollectionEnd,
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
/// Parameters for GC Initialisation. Check documentation in README.md
|
|
143
|
+
/// constexpr indicates that the default value is constexpr.
|
|
144
|
+
#define GC_FIELDS(F) \
|
|
145
|
+
/* Initial heap size hint. */ \
|
|
146
|
+
F(constexpr, gcheapsize_t, InitHeapSize, 32 << 20) \
|
|
147
|
+
\
|
|
148
|
+
/* Maximum heap size hint. */ \
|
|
149
|
+
F(constexpr, gcheapsize_t, MaxHeapSize, 3u << 30) \
|
|
150
|
+
\
|
|
151
|
+
/* Sizing heuristic: fraction of heap to be occupied by live data. */ \
|
|
152
|
+
F(constexpr, double, OccupancyTarget, 0.5) \
|
|
153
|
+
\
|
|
154
|
+
/* Number of consecutive full collections considered to be an OOM. */ \
|
|
155
|
+
F(constexpr, \
|
|
156
|
+
unsigned, \
|
|
157
|
+
EffectiveOOMThreshold, \
|
|
158
|
+
std::numeric_limits<unsigned>::max()) \
|
|
159
|
+
\
|
|
160
|
+
/* Sanitizer configuration for the GC. */ \
|
|
161
|
+
F(constexpr, GCSanitizeConfig, SanitizeConfig) \
|
|
162
|
+
\
|
|
163
|
+
/* Whether to Keep track of GC Statistics. */ \
|
|
164
|
+
F(constexpr, bool, ShouldRecordStats, false) \
|
|
165
|
+
\
|
|
166
|
+
/* How aggressively to return unused memory to the OS. */ \
|
|
167
|
+
F(constexpr, ReleaseUnused, ShouldReleaseUnused, kReleaseUnusedOld) \
|
|
168
|
+
\
|
|
169
|
+
/* Name for this heap in logs. */ \
|
|
170
|
+
F(HERMES_NON_CONSTEXPR, std::string, Name, "") \
|
|
171
|
+
\
|
|
172
|
+
/* Configuration for the Heap Tripwire. */ \
|
|
173
|
+
F(HERMES_NON_CONSTEXPR, GCTripwireConfig, TripwireConfig) \
|
|
174
|
+
\
|
|
175
|
+
/* Whether to (initially) allocate from the young gen (true) or the */ \
|
|
176
|
+
/* old gen (false). */ \
|
|
177
|
+
F(constexpr, bool, AllocInYoung, true) \
|
|
178
|
+
\
|
|
179
|
+
/* Whether to fill the YG with invalid data after each collection. */ \
|
|
180
|
+
F(constexpr, bool, OverwriteDeadYGObjects, false) \
|
|
181
|
+
\
|
|
182
|
+
/* Whether to revert, if necessary, to young-gen allocation at TTI. */ \
|
|
183
|
+
F(constexpr, bool, RevertToYGAtTTI, false) \
|
|
184
|
+
\
|
|
185
|
+
/* Whether to use mprotect on GC metadata between GCs. */ \
|
|
186
|
+
F(constexpr, bool, ProtectMetadata, false) \
|
|
187
|
+
\
|
|
188
|
+
/* Callout for an analytics event. */ \
|
|
189
|
+
F(HERMES_NON_CONSTEXPR, \
|
|
190
|
+
std::function<void(const GCAnalyticsEvent &)>, \
|
|
191
|
+
AnalyticsCallback, \
|
|
192
|
+
nullptr) \
|
|
193
|
+
\
|
|
194
|
+
/* Called at GC events (see GCEventKind enum for the list). The */ \
|
|
195
|
+
/* second argument contains human-readable details about the event. */ \
|
|
196
|
+
/* NOTE: The function MUST NOT invoke any methods on the Runtime. */ \
|
|
197
|
+
F(HERMES_NON_CONSTEXPR, \
|
|
198
|
+
std::function<void(GCEventKind, const char *)>, \
|
|
199
|
+
Callback, \
|
|
200
|
+
nullptr) \
|
|
201
|
+
/* GC_FIELDS END */
|
|
202
|
+
|
|
203
|
+
_HERMES_CTORCONFIG_STRUCT(GCConfig, GC_FIELDS, {
|
|
204
|
+
// Make sure the max is at least the Init.
|
|
205
|
+
MaxHeapSize_ = std::max(InitHeapSize_, MaxHeapSize_);
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
#undef GC_FIELDS
|
|
209
|
+
|
|
210
|
+
} // namespace vm
|
|
211
|
+
} // namespace hermes
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include <hermes/Public/HermesExport.h>
|
|
11
|
+
|
|
12
|
+
#include <iosfwd>
|
|
13
|
+
#include <string>
|
|
14
|
+
#include <system_error>
|
|
15
|
+
|
|
16
|
+
namespace hermes {
|
|
17
|
+
namespace vm {
|
|
18
|
+
|
|
19
|
+
/// Interface passed to the GC tripwire callback when it fires.
|
|
20
|
+
class HERMES_EXPORT GCTripwireContext {
|
|
21
|
+
public:
|
|
22
|
+
virtual ~GCTripwireContext();
|
|
23
|
+
|
|
24
|
+
/// Captures the heap to a file.
|
|
25
|
+
/// \param path to save the heap capture.
|
|
26
|
+
/// \return Empty error code if the heap capture succeeded, else a real error
|
|
27
|
+
/// code.
|
|
28
|
+
virtual std::error_code createSnapshotToFile(const std::string &path) = 0;
|
|
29
|
+
|
|
30
|
+
/// Captures the heap to a stream.
|
|
31
|
+
/// \param os stream to save the heap capture to.
|
|
32
|
+
/// \return Empty error code if the heap capture succeeded, else a real error
|
|
33
|
+
/// code.
|
|
34
|
+
virtual std::error_code createSnapshot(
|
|
35
|
+
std::ostream &os,
|
|
36
|
+
bool captureNumericValue) = 0;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
} // namespace vm
|
|
40
|
+
} // namespace hermes
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#ifndef HERMES_EXPORT
|
|
9
|
+
#ifdef _MSC_VER
|
|
10
|
+
#define HERMES_EXPORT __declspec(dllexport)
|
|
11
|
+
#else // _MSC_VER
|
|
12
|
+
#define HERMES_EXPORT __attribute__((visibility("default")))
|
|
13
|
+
#endif // _MSC_VER
|
|
14
|
+
#endif // !defined(HERMES_EXPORT)
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include "hermes/Public/CrashManager.h"
|
|
11
|
+
#include "hermes/Public/CtorConfig.h"
|
|
12
|
+
#include "hermes/Public/GCConfig.h"
|
|
13
|
+
|
|
14
|
+
#include <cstdint>
|
|
15
|
+
#include <memory>
|
|
16
|
+
|
|
17
|
+
namespace hermes {
|
|
18
|
+
namespace vm {
|
|
19
|
+
|
|
20
|
+
enum CompilationMode {
|
|
21
|
+
SmartCompilation,
|
|
22
|
+
ForceEagerCompilation,
|
|
23
|
+
ForceLazyCompilation
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
enum class SynthTraceMode : int8_t {
|
|
27
|
+
None,
|
|
28
|
+
Replaying,
|
|
29
|
+
Tracing,
|
|
30
|
+
TracingAndReplaying,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
class PinnedHermesValue;
|
|
34
|
+
|
|
35
|
+
// Parameters for Runtime initialisation. Check documentation in README.md
|
|
36
|
+
// constexpr indicates that the default value is constexpr.
|
|
37
|
+
#define RUNTIME_FIELDS(F) \
|
|
38
|
+
/* Parameters to be passed on to the GC. */ \
|
|
39
|
+
F(HERMES_NON_CONSTEXPR, vm::GCConfig, GCConfig) \
|
|
40
|
+
\
|
|
41
|
+
/* Pre-allocated Register Stack */ \
|
|
42
|
+
F(constexpr, PinnedHermesValue *, RegisterStack, nullptr) \
|
|
43
|
+
\
|
|
44
|
+
/* Register Stack Size */ \
|
|
45
|
+
F(constexpr, unsigned, MaxNumRegisters, 128 * 1024) \
|
|
46
|
+
\
|
|
47
|
+
/* Native stack remaining before assuming overflow */ \
|
|
48
|
+
F(constexpr, unsigned, NativeStackGap, 64 * 1024) \
|
|
49
|
+
\
|
|
50
|
+
/* Whether or not the JIT is enabled */ \
|
|
51
|
+
F(constexpr, bool, EnableJIT, false) \
|
|
52
|
+
\
|
|
53
|
+
/* Whether to allow eval and Function ctor */ \
|
|
54
|
+
F(constexpr, bool, EnableEval, true) \
|
|
55
|
+
\
|
|
56
|
+
/* Whether to verify the IR generated by eval and Function ctor */ \
|
|
57
|
+
F(constexpr, bool, VerifyEvalIR, false) \
|
|
58
|
+
\
|
|
59
|
+
/* Whether to optimize the code inside eval and Function ctor */ \
|
|
60
|
+
F(constexpr, bool, OptimizedEval, false) \
|
|
61
|
+
\
|
|
62
|
+
/* Whether to emit async break check instructions in eval code */ \
|
|
63
|
+
F(constexpr, bool, AsyncBreakCheckInEval, true) \
|
|
64
|
+
\
|
|
65
|
+
/* Support for ES6 Proxy. */ \
|
|
66
|
+
F(constexpr, bool, ES6Proxy, true) \
|
|
67
|
+
\
|
|
68
|
+
/* Support for ES6 block scoping. */ \
|
|
69
|
+
F(constexpr, bool, ES6BlockScoping, false) \
|
|
70
|
+
\
|
|
71
|
+
/* Support for async generators in eval. */ \
|
|
72
|
+
F(constexpr, bool, EnableAsyncGenerators, false) \
|
|
73
|
+
\
|
|
74
|
+
/* Support for ECMA-402 Intl APIs. */ \
|
|
75
|
+
F(constexpr, bool, Intl, true) \
|
|
76
|
+
\
|
|
77
|
+
/* Support for using microtasks. */ \
|
|
78
|
+
F(constexpr, bool, MicrotaskQueue, false) \
|
|
79
|
+
\
|
|
80
|
+
/* Runtime set up for synth trace. */ \
|
|
81
|
+
F(constexpr, SynthTraceMode, SynthTraceMode, SynthTraceMode::None) \
|
|
82
|
+
\
|
|
83
|
+
/* Enable sampling certain statistics. */ \
|
|
84
|
+
F(constexpr, bool, EnableSampledStats, false) \
|
|
85
|
+
\
|
|
86
|
+
/* Whether to enable automatic sampling profiler registration */ \
|
|
87
|
+
F(constexpr, bool, EnableSampleProfiling, false) \
|
|
88
|
+
\
|
|
89
|
+
/* Whether to randomize stack placement etc. */ \
|
|
90
|
+
F(constexpr, bool, RandomizeMemoryLayout, false) \
|
|
91
|
+
\
|
|
92
|
+
/* Eagerly read bytecode into page cache. */ \
|
|
93
|
+
F(constexpr, unsigned, BytecodeWarmupPercent, 0) \
|
|
94
|
+
\
|
|
95
|
+
/* Signal-based I/O tracking. Slows down execution. If enabled, */ \
|
|
96
|
+
/* all bytecode buffers > 64 kB passed to Hermes must be mmap:ed. */ \
|
|
97
|
+
F(constexpr, bool, TrackIO, false) \
|
|
98
|
+
\
|
|
99
|
+
/* Enable contents of HermesInternal */ \
|
|
100
|
+
F(constexpr, bool, EnableHermesInternal, true) \
|
|
101
|
+
\
|
|
102
|
+
/* Enable methods exposed to JS for testing */ \
|
|
103
|
+
F(constexpr, bool, EnableHermesInternalTestMethods, false) \
|
|
104
|
+
\
|
|
105
|
+
/* Choose lazy/eager compilation mode. */ \
|
|
106
|
+
F(constexpr, \
|
|
107
|
+
CompilationMode, \
|
|
108
|
+
CompilationMode, \
|
|
109
|
+
CompilationMode::SmartCompilation) \
|
|
110
|
+
\
|
|
111
|
+
/* Choose whether generators are enabled. */ \
|
|
112
|
+
F(constexpr, bool, EnableGenerator, true) \
|
|
113
|
+
\
|
|
114
|
+
/* An interface for managing crashes. */ \
|
|
115
|
+
F(HERMES_NON_CONSTEXPR, \
|
|
116
|
+
std::shared_ptr<CrashManager>, \
|
|
117
|
+
CrashMgr, \
|
|
118
|
+
new NopCrashManager) \
|
|
119
|
+
\
|
|
120
|
+
/* The flags passed from a VM experiment */ \
|
|
121
|
+
F(constexpr, uint32_t, VMExperimentFlags, 0) \
|
|
122
|
+
\
|
|
123
|
+
/* Force JIT compilation on all functions. */ \
|
|
124
|
+
F(constexpr, bool, ForceJIT, false) \
|
|
125
|
+
\
|
|
126
|
+
/* JIT compilation threshold (number of calls before JIT'ing). */ \
|
|
127
|
+
F(constexpr, uint32_t, JITThreshold, 1 << 5) \
|
|
128
|
+
\
|
|
129
|
+
/* JIT memory limit, after which no more code will be JIT'ed. */ \
|
|
130
|
+
F(constexpr, uint32_t, JITMemoryLimit, 32u << 20) \
|
|
131
|
+
\
|
|
132
|
+
/* Increase compliance with test262 (stricter checks at runtime). */ \
|
|
133
|
+
F(constexpr, bool, Test262, false) \
|
|
134
|
+
/* RUNTIME_FIELDS END */
|
|
135
|
+
|
|
136
|
+
_HERMES_CTORCONFIG_STRUCT(RuntimeConfig, RUNTIME_FIELDS, {})
|
|
137
|
+
|
|
138
|
+
#undef RUNTIME_FIELDS
|
|
139
|
+
|
|
140
|
+
} // namespace vm
|
|
141
|
+
} // namespace hermes
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include <hermes/Public/HermesExport.h>
|
|
11
|
+
|
|
12
|
+
#include <cstdint>
|
|
13
|
+
#include <deque>
|
|
14
|
+
#include <memory>
|
|
15
|
+
#include <optional>
|
|
16
|
+
#include <string>
|
|
17
|
+
#include <variant>
|
|
18
|
+
#include <vector>
|
|
19
|
+
|
|
20
|
+
namespace facebook {
|
|
21
|
+
namespace hermes {
|
|
22
|
+
namespace sampling_profiler {
|
|
23
|
+
|
|
24
|
+
/// Helper-class that represents a pair of iterators, which form a range to
|
|
25
|
+
/// iterate over.
|
|
26
|
+
template <typename Iterator>
|
|
27
|
+
class Range {
|
|
28
|
+
public:
|
|
29
|
+
Range(Iterator begin, Iterator end) : begin_(begin), end_(end) {}
|
|
30
|
+
|
|
31
|
+
Iterator begin() const {
|
|
32
|
+
return begin_;
|
|
33
|
+
}
|
|
34
|
+
Iterator end() const {
|
|
35
|
+
return end_;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private:
|
|
39
|
+
Iterator begin_;
|
|
40
|
+
Iterator end_;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/// Helper for creating Range and deducing the type based on input.
|
|
44
|
+
template <typename Iterator>
|
|
45
|
+
Range<Iterator> makeRange(Iterator begin, Iterator end) {
|
|
46
|
+
return Range<Iterator>(begin, end);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/// JavaScript function frame. Guaranteed to have function name, potentially
|
|
50
|
+
/// an empty string, if function is anonymous or if function names were filtered
|
|
51
|
+
/// out during bytecode compilation. Could have scriptId, url, line and column
|
|
52
|
+
/// numbers, if debug source location is available.
|
|
53
|
+
class HERMES_EXPORT ProfileSampleCallStackJSFunctionFrame {
|
|
54
|
+
public:
|
|
55
|
+
explicit ProfileSampleCallStackJSFunctionFrame(
|
|
56
|
+
std::string_view functionName,
|
|
57
|
+
uint32_t scriptId,
|
|
58
|
+
const std::optional<std::string_view> &scriptUrl = std::nullopt,
|
|
59
|
+
const std::optional<uint32_t> &lineNumber = std::nullopt,
|
|
60
|
+
const std::optional<uint32_t> &columnNumber = std::nullopt)
|
|
61
|
+
: functionName_(functionName),
|
|
62
|
+
scriptId_(scriptId),
|
|
63
|
+
scriptUrl_(scriptUrl),
|
|
64
|
+
lineNumber_(lineNumber),
|
|
65
|
+
columnNumber_(columnNumber) {}
|
|
66
|
+
|
|
67
|
+
/// \return name of the function that represents call frame.
|
|
68
|
+
std::string_view getFunctionName() const {
|
|
69
|
+
return functionName_;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/// \return id of the corresponding script in the VM.
|
|
73
|
+
uint32_t getScriptId() const {
|
|
74
|
+
return scriptId_;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
bool hasScriptUrl() const {
|
|
78
|
+
return scriptUrl_.has_value();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/// \return source url of the corresponding script in the VM.
|
|
82
|
+
std::string_view getScriptUrl() const {
|
|
83
|
+
return scriptUrl_.value();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
bool hasFunctionLineNumber() const {
|
|
87
|
+
return lineNumber_.has_value();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/// \return 1-based line number of the location where the function definition
|
|
91
|
+
/// starts.
|
|
92
|
+
uint32_t getFunctionLineNumber() const {
|
|
93
|
+
return lineNumber_.value();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
bool hasFunctionColumnNumber() const {
|
|
97
|
+
return columnNumber_.has_value();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/// \return 1-based column number of the location where the function
|
|
101
|
+
/// definition starts.
|
|
102
|
+
uint32_t getFunctionColumnNumber() const {
|
|
103
|
+
return columnNumber_.value();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
private:
|
|
107
|
+
std::string_view functionName_;
|
|
108
|
+
uint32_t scriptId_;
|
|
109
|
+
std::optional<std::string_view> scriptUrl_;
|
|
110
|
+
std::optional<uint32_t> lineNumber_;
|
|
111
|
+
std::optional<uint32_t> columnNumber_;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
/// Native (Hermes) function frame. Example: implementation of a built-in
|
|
115
|
+
/// Array.prototype.map.
|
|
116
|
+
class HERMES_EXPORT ProfileSampleCallStackNativeFunctionFrame {
|
|
117
|
+
public:
|
|
118
|
+
explicit ProfileSampleCallStackNativeFunctionFrame(
|
|
119
|
+
std::string_view functionName)
|
|
120
|
+
: functionName_(functionName) {}
|
|
121
|
+
|
|
122
|
+
/// \return name of the function that represents call frame.
|
|
123
|
+
std::string_view getFunctionName() const {
|
|
124
|
+
return functionName_;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
private:
|
|
128
|
+
std::string_view functionName_;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
/// Host function frame. Native functions defined by the integrator. Example:
|
|
132
|
+
/// for React Native, this could be performance.measure or console.log.
|
|
133
|
+
class HERMES_EXPORT ProfileSampleCallStackHostFunctionFrame {
|
|
134
|
+
public:
|
|
135
|
+
explicit ProfileSampleCallStackHostFunctionFrame(
|
|
136
|
+
std::string_view functionName)
|
|
137
|
+
: functionName_(functionName) {}
|
|
138
|
+
|
|
139
|
+
/// \return name of the function that represents call frame.
|
|
140
|
+
std::string_view getFunctionName() const {
|
|
141
|
+
return functionName_;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
private:
|
|
145
|
+
std::string_view functionName_;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
/// Frame that suspends the execution of the VM: could be GC, Debugger or
|
|
149
|
+
/// combination of them.
|
|
150
|
+
class HERMES_EXPORT ProfileSampleCallStackSuspendFrame {
|
|
151
|
+
public:
|
|
152
|
+
/// Subtype of the Suspend frame.
|
|
153
|
+
enum class SuspendFrameKind {
|
|
154
|
+
GC, /// Frame that suspends the execution of the VM due to GC.
|
|
155
|
+
Debugger, /// Frame that suspends the execution of the VM due to debugger.
|
|
156
|
+
Multiple, /// Multiple suspensions have occurred.
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
explicit ProfileSampleCallStackSuspendFrame(
|
|
160
|
+
const SuspendFrameKind suspendFrameKind)
|
|
161
|
+
: suspendFrameKind_(suspendFrameKind) {}
|
|
162
|
+
|
|
163
|
+
/// \return subtype of the suspend frame.
|
|
164
|
+
SuspendFrameKind getSuspendFrameKind() const {
|
|
165
|
+
return suspendFrameKind_;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
private:
|
|
169
|
+
SuspendFrameKind suspendFrameKind_;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
/// Variant of all possible call stack frames options.
|
|
173
|
+
using ProfileSampleCallStackFrame = std::variant<
|
|
174
|
+
ProfileSampleCallStackSuspendFrame,
|
|
175
|
+
ProfileSampleCallStackNativeFunctionFrame,
|
|
176
|
+
ProfileSampleCallStackHostFunctionFrame,
|
|
177
|
+
ProfileSampleCallStackJSFunctionFrame>;
|
|
178
|
+
|
|
179
|
+
/// A pair of a timestamp and a snapshot of the call stack at this point in
|
|
180
|
+
/// time.
|
|
181
|
+
class HERMES_EXPORT ProfileSample {
|
|
182
|
+
public:
|
|
183
|
+
using CallStackFrameIterator =
|
|
184
|
+
std::vector<ProfileSampleCallStackFrame>::const_iterator;
|
|
185
|
+
|
|
186
|
+
ProfileSample(
|
|
187
|
+
uint64_t timestamp,
|
|
188
|
+
uint64_t threadId,
|
|
189
|
+
std::vector<ProfileSampleCallStackFrame> callStack)
|
|
190
|
+
: timestamp_(timestamp),
|
|
191
|
+
threadId_(threadId),
|
|
192
|
+
callStack_(std::move(callStack)) {}
|
|
193
|
+
|
|
194
|
+
/// \return serialized unix timestamp in microseconds granularity. The
|
|
195
|
+
/// moment when this sample was recorded.
|
|
196
|
+
uint64_t getTimestamp() const {
|
|
197
|
+
return timestamp_;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/// \return thread id where sample was recorded.
|
|
201
|
+
uint64_t getThreadId() const {
|
|
202
|
+
return threadId_;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/// \return a pair of iterators that can be used for iterating over call stack
|
|
206
|
+
/// frames, the order will be from callee to caller.
|
|
207
|
+
Range<CallStackFrameIterator> getCallStackFramesRange() const {
|
|
208
|
+
return makeRange(callStack_.begin(), callStack_.end());
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/// \return the number of frames inside the call stack of this sample.
|
|
212
|
+
size_t getCallStackFramesCount() const {
|
|
213
|
+
return callStack_.size();
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
private:
|
|
217
|
+
/// When the call stack snapshot was taken (μs).
|
|
218
|
+
uint64_t timestamp_;
|
|
219
|
+
/// Thread id where sample was recorded.
|
|
220
|
+
uint64_t threadId_;
|
|
221
|
+
/// Snapshot of the call stack. The first element of the vector is
|
|
222
|
+
/// the lowest frame in the stack.
|
|
223
|
+
std::vector<ProfileSampleCallStackFrame> callStack_;
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
/// Contains relevant information about the sampled trace from start to finish.
|
|
227
|
+
class HERMES_EXPORT Profile {
|
|
228
|
+
public:
|
|
229
|
+
using SampleIterator = std::vector<ProfileSample>::const_iterator;
|
|
230
|
+
|
|
231
|
+
Profile(
|
|
232
|
+
std::vector<ProfileSample> samples,
|
|
233
|
+
std::unique_ptr<std::deque<std::string>> stringStorage)
|
|
234
|
+
: samples_(std::move(samples)),
|
|
235
|
+
stringStorage_(std::move(stringStorage)) {}
|
|
236
|
+
|
|
237
|
+
Profile(Profile &&) = default;
|
|
238
|
+
Profile &operator=(Profile &&) = default;
|
|
239
|
+
|
|
240
|
+
/// Not copyable, maintains the ownership of the storage of strings.
|
|
241
|
+
Profile(const Profile &) = delete;
|
|
242
|
+
Profile &operator=(const Profile &) = delete;
|
|
243
|
+
|
|
244
|
+
~Profile() = default;
|
|
245
|
+
|
|
246
|
+
/// \return a pair of iterators that can be used for iterating over recorded
|
|
247
|
+
/// samples, will happen in chronological order.
|
|
248
|
+
Range<SampleIterator> getSamplesRange() const {
|
|
249
|
+
return makeRange(samples_.begin(), samples_.end());
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/// \return the number of recorded samples.
|
|
253
|
+
size_t getSamplesCount() const {
|
|
254
|
+
return samples_.size();
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
private:
|
|
258
|
+
/// List of recorded samples, should be chronologically sorted.
|
|
259
|
+
std::vector<ProfileSample> samples_;
|
|
260
|
+
/// Smart pointer to the string storage, owns the strings.
|
|
261
|
+
/// Frames inside this Profile keep a reference to the storage and know how to
|
|
262
|
+
/// get std::string_view to the actual string.
|
|
263
|
+
/// The storage lifetime is tied to the lifetime of the Profile. Samples and
|
|
264
|
+
/// Frames should not outlive the Profile.
|
|
265
|
+
std::unique_ptr<std::deque<std::string>> stringStorage_;
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
} // namespace sampling_profiler
|
|
269
|
+
} // namespace hermes
|
|
270
|
+
} // namespace facebook
|