This commit is contained in:
Yamozha
2021-04-02 02:24:13 +03:00
parent c23950b545
commit 7256d79e2c
31493 changed files with 3036630 additions and 0 deletions

View File

@ -0,0 +1,40 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#ifndef HERMES_PUBLIC_BUFFER_H
#define HERMES_PUBLIC_BUFFER_H
#include <cstddef>
#include <cstdint>
namespace hermes {
/// A generic buffer interface. E.g. for memmapped bytecode.
class Buffer {
public:
Buffer() : data_(nullptr), size_(0) {}
Buffer(const uint8_t *data, size_t size) : data_(data), size_(size) {}
virtual ~Buffer() {}
const uint8_t *data() const {
return data_;
};
size_t size() const {
return size_;
}
protected:
const uint8_t *data_ = nullptr;
size_t size_ = 0;
};
} // namespace hermes
#endif

View File

@ -0,0 +1,96 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#ifndef HERMES_PUBLIC_CRASHMANAGER_H
#define HERMES_PUBLIC_CRASHMANAGER_H
#include <cstddef>
#include <functional>
namespace hermes {
namespace vm {
/// A CrashManager provides functions that determine what memory and data is
/// included in dumps in case of crashes.
class CrashManager {
public:
/// CallbackKey is the type of an identifier for a callback supplied to the
/// CrashManager.
using CallbackKey = int;
/// Type for the callback function invoked on crash. The fd supplied is a raw
/// file stream an implementation should write a JSON object to.
using CallbackFunc = std::function<void(int fd)>;
/// Registers some memory to be included in any crash dump that occurs.
/// \param mem A pointer to allocated memory. It must be unregistered
/// before being freed.
/// \param length The number of bytes the memory controls.
virtual void registerMemory(void *mem, size_t length) = 0;
/// Unregisters some memory from being included in any crash dump that occurs.
virtual void unregisterMemory(void *mem) = 0;
/// Registers custom data to be included in any crash dump that occurs.
/// Calling \c setCustomData on the same key twice will overwrite the previous
/// value.
/// \param key A tag to look for in the custom data output. Distinguishes
/// between multiple values.
/// \param val The value to store for the given key.
virtual void setCustomData(const char *key, const char *val) = 0;
/// If the given \p key has an associated custom data string, remove the
/// association.
virtual void removeCustomData(const char *key) = 0;
/// Registers a function to be called after a crash has occurred. This
/// function can examine memory and serialize this to a JSON output stream.
/// Implmentations decide where the stream is routed to.
/// \param callback A function to called after a crash.
/// \return A CallbackKey representing the function you provided. Pass this
/// key into unregisterCallback when it that callback is no longer needed.
virtual CallbackKey registerCallback(CallbackFunc callback) = 0;
/// Unregisters a previously registered callback. After this function returns,
/// the previously registered function will not be executed by this
/// CrashManager during a crash.
virtual void unregisterCallback(CallbackKey key) = 0;
/// the heap information.
struct HeapInformation {
/// The amount of memory that is currently in use
size_t used_{0};
/// The amount of memory that can currently be allocated
/// before a full GC is triggered.
size_t size_{0};
};
/// Record the heap information.
/// \param heapInfo The current heap information
virtual void setHeapInfo(const HeapInformation &heapInfo) = 0;
virtual ~CrashManager() {}
};
/// A CrashManager that does nothing.
class NopCrashManager final : public CrashManager {
public:
void registerMemory(void *, size_t) override {}
void unregisterMemory(void *) override {}
void setCustomData(const char *, const char *) override {}
void removeCustomData(const char *) override {}
CallbackKey registerCallback(CallbackFunc /*callback*/) override {
return 0;
}
void unregisterCallback(CallbackKey /*key*/) override {}
void setHeapInfo(const HeapInformation & /*heapInfo*/) override {}
~NopCrashManager() {}
};
} // namespace vm
} // namespace hermes
#endif

View File

@ -0,0 +1,148 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#ifndef HERMES_PUBLIC_CTORCONFIG_H
#define HERMES_PUBLIC_CTORCONFIG_H
#include <utility>
/// Defines a new class, called \p NAME representing a constructor config, and
/// an associated builder class.
///
/// The fields of the class (along with their types and default values) are
/// encoded in the \p FIELDS parameter, and any logic to be run whilst building
/// the config can be passed as a code block in \p BUILD_BODY.
///
/// Example:
///
/// Suppose we wish to define a configuration class called Foo, with the
/// following fields and default values:
///
/// int A = 0;
/// int B = 42;
/// std::string C = "hello";
///
/// Such that the value in A is at most the length of \c C.
///
/// We can do so with the following declaration:
///
/// " #define FIELDS(F) \ "
/// " F(int, A) \ "
/// " F(int, B, 42) \ "
/// " F(std::string, C, "hello") "
/// " "
/// " _HERMES_CTORCONFIG_STRUCT(Foo, FIELDS, { "
/// " A_ = std::min(A_, C_.length()); "
/// " }); "
///
/// N.B.
/// - The definition of A does not mention any value -- meaning it is
/// default initialised.
/// - References to the fields in the validation logic have a trailling
/// underscore.
///
#define _HERMES_CTORCONFIG_STRUCT(NAME, FIELDS, BUILD_BODY) \
class NAME { \
FIELDS(_HERMES_CTORCONFIG_FIELD_DECL); \
\
public: \
class Builder; \
friend Builder; \
FIELDS(_HERMES_CTORCONFIG_GETTER); \
\
/* returns a Builder that starts with the current config. */ \
inline Builder rebuild() const; \
\
private: \
inline void doBuild(const Builder &builder); \
}; \
\
class NAME::Builder { \
NAME config_; \
\
FIELDS(_HERMES_CTORCONFIG_FIELD_EXPLICIT_BOOL_DECL); \
\
public: \
Builder() = default; \
\
explicit Builder(const NAME &config) : config_(config){}; \
\
inline const NAME build() { \
config_.doBuild(*this); \
return config_; \
} \
\
/* The explicitly set fields of \p newconfig update \
* the corresponding fields of \p this. */ \
inline Builder update(const NAME::Builder &newConfig); \
\
FIELDS(_HERMES_CTORCONFIG_SETTER); \
FIELDS(_HERMES_CTORCONFIG_FIELD_EXPLICIT_BOOL_ACCESSOR); \
}; \
\
NAME::Builder NAME::rebuild() const { \
return Builder(*this); \
} \
\
NAME::Builder NAME::Builder::update(const NAME::Builder &newConfig) { \
FIELDS(_HERMES_CTORCONFIG_UPDATE); \
return *this; \
} \
\
void NAME::doBuild(const NAME::Builder &builder) { \
(void)builder; \
BUILD_BODY \
}
/// Helper Macros
#define _HERMES_CTORCONFIG_FIELD_DECL(CX, TYPE, NAME, ...) \
TYPE NAME##_{__VA_ARGS__};
/// This ignores the first and trailing arguments, and defines a member
/// indicating whether field NAME was set explicitly.
#define _HERMES_CTORCONFIG_FIELD_EXPLICIT_BOOL_DECL(CX, TYPE, NAME, ...) \
bool NAME##Explicit_{false};
/// This defines an accessor for the "Explicit_" fields defined above.
#define _HERMES_CTORCONFIG_FIELD_EXPLICIT_BOOL_ACCESSOR(CX, TYPE, NAME, ...) \
bool has##NAME() const { \
return NAME##Explicit_; \
}
/// Placeholder token for fields whose defaults are not constexpr, to make the
/// listings more readable.
#define HERMES_NON_CONSTEXPR
#define _HERMES_CTORCONFIG_GETTER(CX, TYPE, NAME, ...) \
inline TYPE get##NAME() const { \
return NAME##_; \
} \
static CX TYPE getDefault##NAME() { \
/* Instead of parens around TYPE (non-standard) */ \
using TypeAsSingleToken = TYPE; \
return TypeAsSingleToken{__VA_ARGS__}; \
}
#define _HERMES_CTORCONFIG_SETTER(CX, TYPE, NAME, ...) \
inline auto with##NAME(TYPE NAME)->decltype(*this) { \
config_.NAME##_ = std::move(NAME); \
NAME##Explicit_ = true; \
return *this; \
}
#define _HERMES_CTORCONFIG_BUILDER_GETTER(CX, TYPE, NAME, ...) \
TYPE get##NAME() const { \
return config_.NAME##_; \
}
#define _HERMES_CTORCONFIG_UPDATE(CX, TYPE, NAME, ...) \
if (newConfig.has##NAME()) { \
with##NAME(newConfig.config_.get##NAME()); \
}
#endif // HERMES_PUBLIC_CTORCONFIG_H

View File

@ -0,0 +1,192 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#ifndef HERMES_PUBLIC_DEBUGGERTYPES_H
#define HERMES_PUBLIC_DEBUGGERTYPES_H
#include <string>
#include <vector>
namespace hermes {
namespace vm {
class Debugger;
}
} // namespace hermes
namespace facebook {
namespace hermes {
namespace debugger {
class ProgramState;
/// Strings in the Debugger are UTF-8 encoded. When converting from a JavaScript
/// string, valid UTF-16 surrogate pairs are decoded. Surrogate halves are
/// converted into the Unicode replacement character.
using String = std::string;
/// Debugging entities like breakpoints are identified by a unique ID. The
/// Debugger will not re-use IDs even across different entity types. 0 is an
/// invalid ID.
using BreakpointID = uint64_t;
// NOTE: Can't be kInvalidID due to a clash with MacTypes.h's define kInvalidID.
constexpr uint64_t kInvalidBreakpoint = 0;
/// Scripts when loaded are identified by a script ID.
/// These are not reused within one invocation of the VM.
using ScriptID = uint32_t;
/// A SourceLocation is a small value-type representing a location in a source
/// file.
constexpr uint32_t kInvalidLocation = ~0u;
struct SourceLocation {
/// Line in the source.
uint32_t line = kInvalidLocation;
/// Column in the source.
uint32_t column = kInvalidLocation;
/// Identifier of the source file.
ScriptID fileId = kInvalidLocation;
/// Name of the source file.
String fileName;
};
/// CallFrameInfo is a value type representing an entry in a call stack.
struct CallFrameInfo {
/// Name of the function executing in this frame.
String functionName;
/// Source location of the program counter for this frame.
SourceLocation location;
};
/// StackTrace represents a list of call frames, either in the current execution
/// or captured in an exception.
struct StackTrace {
/// \return the number of call frames.
uint32_t callFrameCount() const {
return frames_.size();
}
/// \return call frame info at a given index. 0 represents the topmost
/// (current) frame on the call stack.
CallFrameInfo callFrameForIndex(uint32_t index) const {
return frames_.at(index);
}
StackTrace() {}
private:
explicit StackTrace(std::vector<CallFrameInfo> frames)
: frames_(std::move(frames)){};
friend ProgramState;
friend ::hermes::vm::Debugger;
std::vector<CallFrameInfo> frames_;
};
/// ExceptionDetails is a value type describing an exception.
struct ExceptionDetails {
/// Textual description of the exception.
String text;
/// Location where the exception was thrown.
SourceLocation location;
/// Get the stack trace associated with the exception.
const StackTrace &getStackTrace() const {
return stackTrace_;
}
private:
friend ::hermes::vm::Debugger;
StackTrace stackTrace_;
};
/// A list of possible reasons for a Pause.
enum class PauseReason {
ScriptLoaded, /// A script file was loaded, and the debugger has requested
/// pausing after script load.
DebuggerStatement, /// A debugger; statement was hit.
Breakpoint, /// A breakpoint was hit.
StepFinish, /// A Step operation completed.
Exception, /// An Exception was thrown.
AsyncTrigger, /// The Pause is the result of triggerAsyncPause().
EvalComplete, /// An eval() function finished.
};
/// When stepping, the mode with which to step.
enum class StepMode {
Into, /// Enter into any function calls.
Over, /// Skip over any function calls.
Out, /// Step until the current function exits.
};
/// When setting pause on throw, this specifies when to pause.
enum class PauseOnThrowMode {
None, /// Never pause on exceptions.
Uncaught, /// Only pause on uncaught exceptions.
All, /// Pause any time an exception is thrown.
};
/// When requesting an async break, this specifies whether it was an implicit
/// break from the inspector or a user-requested explicit break.
enum class AsyncPauseKind {
/// Implicit pause to allow movement of jsi::Value types between threads.
/// The user will not be running commands and the inspector will immediately
/// request a Continue.
Implicit,
/// Explicit pause requested by the user.
/// Clears any stepping state and allows the user to run their own commands.
Explicit,
};
/// A type representing depth in a lexical scope chain.
using ScopeDepth = uint32_t;
/// Information about lexical entities (for now, just variable names).
struct LexicalInfo {
/// \return the number of scopes.
ScopeDepth getScopesCount() const {
return variableCountsByScope_.size();
}
/// \return the number of variables in a given scope.
uint32_t getVariablesCountInScope(ScopeDepth depth) const {
return variableCountsByScope_.at(depth);
}
private:
friend ::hermes::vm::Debugger;
std::vector<uint32_t> variableCountsByScope_;
};
/// Information about a breakpoint.
struct BreakpointInfo {
/// ID of the breakpoint.
/// kInvalidBreakpoint if the info is not valid.
BreakpointID id;
/// Whether the breakpoint is enabled.
bool enabled;
/// Whether the breakpoint has been resolved.
bool resolved;
/// The originally requested location of the breakpoint.
SourceLocation requestedLocation;
/// The resolved location of the breakpoint if resolved is true.
SourceLocation resolvedLocation;
};
} // namespace debugger
} // namespace hermes
} // namespace facebook
#endif

View File

@ -0,0 +1,188 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#ifndef HERMES_PUBLIC_GCCONFIG_H
#define HERMES_PUBLIC_GCCONFIG_H
#include "hermes/Public/CtorConfig.h"
#include "hermes/Public/GCTripwireContext.h"
#include "hermes/Public/MemoryEventTracker.h"
#include <algorithm>
#include <cassert>
#include <chrono>
#include <cstdint>
#include <functional>
#include <limits>
#include <memory>
#include <string>
namespace hermes {
namespace vm {
/// A type big enough to accomodate the entire allocated address space.
/// Individual allocations are always 'uint32_t', but on a 64-bit machine we
/// might want to accommodate a larger total heap (or not, in which case we keep
/// it 32-bit).
using gcheapsize_t = uint32_t;
struct GCAnalyticsEvent {
std::string runtimeDescription;
std::string gcKind;
std::string collectionType;
std::chrono::milliseconds duration;
std::chrono::milliseconds cpuDuration;
uint64_t preAllocated;
uint64_t preSize;
uint64_t postAllocated;
uint64_t postSize;
double survivalRatio;
};
/// Parameters to control a tripwire function called when the live set size
/// surpasses a given threshold after collections. Check documentation in
/// README.md
#define GC_TRIPWIRE_FIELDS(F) \
/* If the heap size is above this threshold after a collection, the tripwire \
* is triggered. */ \
F(constexpr, gcheapsize_t, Limit, std::numeric_limits<gcheapsize_t>::max()) \
\
/* The callback to call when the tripwire is considered triggered. */ \
F(HERMES_NON_CONSTEXPR, \
std::function<void(GCTripwireContext &)>, \
Callback, \
nullptr) \
/* GC_TRIPWIRE_FIELDS END */
_HERMES_CTORCONFIG_STRUCT(GCTripwireConfig, GC_TRIPWIRE_FIELDS, {});
#undef HEAP_TRIPWIRE_FIELDS
#define GC_HANDLESAN_FIELDS(F) \
/* The probability with which the GC should keep moving the heap */ \
/* to detect stale GC handles. */ \
F(constexpr, double, SanitizeRate, 0.0) \
/* Random seed to use for basis of decisions whether or not to */ \
/* sanitize. A negative value will mean a seed will be chosen at */ \
/* random. */ \
F(constexpr, int64_t, RandomSeed, -1) \
/* GC_HANDLESAN_FIELDS END */
_HERMES_CTORCONFIG_STRUCT(GCSanitizeConfig, GC_HANDLESAN_FIELDS, {});
#undef GC_HANDLESAN_FIELDS
/// How aggressively to return unused memory to the OS.
enum ReleaseUnused {
kReleaseUnusedNone = 0, /// Don't try to release unused memory.
kReleaseUnusedOld, /// Only old gen, on full collections.
kReleaseUnusedYoungOnFull, /// Also young gen, but only on full collections.
kReleaseUnusedYoungAlways /// Also young gen, also on young gen collections.
};
enum class GCEventKind {
CollectionStart,
CollectionEnd,
};
/// Parameters for GC Initialisation. Check documentation in README.md
/// constexpr indicates that the default value is constexpr.
#define GC_FIELDS(F) \
/* Minimum heap size hint. */ \
F(constexpr, gcheapsize_t, MinHeapSize, 0) \
\
/* Initial heap size hint. */ \
F(constexpr, gcheapsize_t, InitHeapSize, 32 << 20) \
\
/* Maximum heap size hint. */ \
F(constexpr, gcheapsize_t, MaxHeapSize, 512 << 20) \
\
/* Sizing heuristic: fraction of heap to be occupied by live data. */ \
F(constexpr, double, OccupancyTarget, 0.5) \
\
/* Number of consecutive full collections considered to be an OOM. */ \
F(constexpr, \
unsigned, \
EffectiveOOMThreshold, \
std::numeric_limits<unsigned>::max()) \
\
/* Sanitizer configuration for the GC. */ \
F(constexpr, GCSanitizeConfig, SanitizeConfig) \
\
/* Whether the GC should spread allocations across all its "spaces". */ \
F(constexpr, bool, ShouldRandomizeAllocSpace, false) \
\
/* Whether to Keep track of GC Statistics. */ \
F(constexpr, bool, ShouldRecordStats, false) \
\
/* How aggressively to return unused memory to the OS. */ \
F(constexpr, ReleaseUnused, ShouldReleaseUnused, kReleaseUnusedOld) \
\
/* Name for this heap in logs. */ \
F(HERMES_NON_CONSTEXPR, std::string, Name, "") \
\
/* Configuration for the Heap Tripwire. */ \
F(HERMES_NON_CONSTEXPR, GCTripwireConfig, TripwireConfig) \
\
/* Whether to (initially) allocate from the young gen (true) or the */ \
/* old gen (false). */ \
F(constexpr, bool, AllocInYoung, true) \
\
/* Whether to revert, if necessary, to young-gen allocation at TTI. */ \
F(constexpr, bool, RevertToYGAtTTI, false) \
\
/* Whether to use mprotect on GC metadata between GCs. */ \
F(constexpr, bool, ProtectMetadata, false) \
\
/* Whether to track allocation traces starting in the Runtime ctor. */ \
F(constexpr, bool, AllocationLocationTrackerFromStart, false) \
\
/* Pointer to the memory profiler (Memory Event Tracker). */ \
F(HERMES_NON_CONSTEXPR, \
std::shared_ptr<MemoryEventTracker>, \
MemEventTracker, \
nullptr) \
\
/* Callout for an analytics event. */ \
F(HERMES_NON_CONSTEXPR, \
std::function<void(const GCAnalyticsEvent &)>, \
AnalyticsCallback, \
nullptr) \
\
/* Called at GC events (see GCEventKind enum for the list). The */ \
/* second argument contains human-readable details about the event. */ \
/* NOTE: The function MUST NOT invoke any methods on the Runtime. */ \
F(HERMES_NON_CONSTEXPR, \
std::function<void(GCEventKind, const char *)>, \
Callback, \
nullptr) \
/* GC_FIELDS END */
_HERMES_CTORCONFIG_STRUCT(GCConfig, GC_FIELDS, {
if (builder.hasMinHeapSize()) {
if (builder.hasInitHeapSize()) {
// If both are specified, normalize the initial size up to the minimum,
// if necessary.
InitHeapSize_ = std::max(MinHeapSize_, InitHeapSize_);
} else {
// If the minimum is set explicitly, but the initial heap size is not,
// use the minimum as the initial size.
InitHeapSize_ = MinHeapSize_;
}
}
assert(InitHeapSize_ >= MinHeapSize_);
// Make sure the max is at least the Init.
MaxHeapSize_ = std::max(InitHeapSize_, MaxHeapSize_);
});
#undef GC_FIELDS
} // namespace vm
} // namespace hermes
#endif // HERMES_PUBLIC_GCCONFIG_H

View File

@ -0,0 +1,34 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#ifndef HERMES_PUBLIC_GCTRIPWIRECONTEXT_H
#define HERMES_PUBLIC_GCTRIPWIRECONTEXT_H
#include <string>
#include <system_error>
namespace hermes {
namespace vm {
/// Interface passed to the GC tripwire callback when it fires.
class GCTripwireContext {
public:
virtual ~GCTripwireContext() = default;
/// Captures the heap to a file
///
/// \param path to save the heap capture
///
/// \return Empty error code if the heap capture succeeded, else a real error
/// code.
virtual std::error_code createSnapshotToFile(const std::string &path) = 0;
};
} // namespace vm
} // namespace hermes
#endif // HERMES_PUBLIC_GCTRIPWIRECONTEXT_H

View File

@ -0,0 +1,30 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#ifndef HERMES_VM_PROFILER_MEMORYEVENTTRACKER_H
#define HERMES_VM_PROFILER_MEMORYEVENTTRACKER_H
#include <cstdint>
namespace hermes {
namespace vm {
/// This is the interface for the memory profiler that will track
/// allocations, calls, returns, moves, and deletes. It should
/// be inhertied from and implemented to the profilign needs, i.e
/// to a file, to a different format, to JSON, etc.
class MemoryEventTracker {
public:
virtual ~MemoryEventTracker() = default;
// Emit an allocation of a cell with kind `kind` and allocated
// size `size`.
virtual void emitAlloc(uint32_t kind, uint32_t size) = 0;
};
} // namespace vm
} // namespace hermes
#endif // HERMES_VM_PROFILER_MEMORYEVENTTRACKER_H

View File

@ -0,0 +1,136 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#ifndef HERMES_PUBLIC_RUNTIMECONFIG_H
#define HERMES_PUBLIC_RUNTIMECONFIG_H
#include "hermes/Public/CrashManager.h"
#include "hermes/Public/CtorConfig.h"
#include "hermes/Public/GCConfig.h"
#include <memory>
#ifdef HERMESVM_SERIALIZE
#include <vector>
namespace llvm {
class MemoryBuffer;
class raw_ostream;
} // namespace llvm
#endif
namespace hermes {
namespace vm {
class PinnedHermesValue;
#ifdef HERMESVM_SERIALIZE
class Serializer;
class Deserializer;
#endif
// Parameters for Runtime initialisation. Check documentation in README.md
// constexpr indicates that the default value is constexpr.
#define RUNTIME_FIELDS_BASE(F) \
/* Parameters to be passed on to the GC. */ \
F(HERMES_NON_CONSTEXPR, vm::GCConfig, GCConfig) \
\
/* Pre-allocated Register Stack */ \
F(constexpr, PinnedHermesValue *, RegisterStack, nullptr) \
\
/* Register Stack Size */ \
F(constexpr, unsigned, MaxNumRegisters, 1024 * 1024) \
\
/* Whether or not the JIT is enabled */ \
F(constexpr, bool, EnableJIT, false) \
\
/* Whether to allow eval and Function ctor */ \
F(constexpr, bool, EnableEval, true) \
\
/* Whether to verify the IR generated by eval and Function ctor */ \
F(constexpr, bool, VerifyEvalIR, false) \
\
/* Support for ES6 Proxy. */ \
F(constexpr, bool, ES6Proxy, false) \
\
/* Support for ES6 Symbol. */ \
F(constexpr, bool, ES6Symbol, true) \
\
/* Trace non-deterministic JS behavior */ \
F(constexpr, bool, TraceEnvironmentInteractions, false) \
\
/* Enable sampling certain statistics. */ \
F(constexpr, bool, EnableSampledStats, false) \
\
/* Whether to enable sampling profiler */ \
F(constexpr, bool, EnableSampleProfiling, false) \
\
/* Whether to randomize stack placement etc. */ \
F(constexpr, bool, RandomizeMemoryLayout, false) \
\
/* Eagerly read bytecode into page cache. */ \
F(constexpr, unsigned, BytecodeWarmupPercent, 0) \
\
/* Signal-based I/O tracking. Slows down execution. If enabled, */ \
/* all bytecode buffers > 64 kB passed to Hermes must be mmap:ed. */ \
F(constexpr, bool, TrackIO, false) \
\
/* Enable contents of HermesInternal */ \
F(constexpr, bool, EnableHermesInternal, true) \
\
/* Enable methods exposed to JS for testing */ \
F(constexpr, bool, EnableHermesInternalTestMethods, false) \
\
/* Allows Function.toString() to return the original source code */ \
/* if available. For this to work code must have been compiled at */ \
/* runtime with CompileFlags::allowFunctionToStringWithRuntimeSource set. */ \
F(constexpr, bool, AllowFunctionToStringWithRuntimeSource, false) \
\
/* An interface for managing crashes. */ \
F(HERMES_NON_CONSTEXPR, \
std::shared_ptr<CrashManager>, \
CrashMgr, \
new NopCrashManager) \
\
/* The flags passed from a VM experiment */ \
F(constexpr, uint32_t, VMExperimentFlags, 0) \
/* RUNTIME_FIELDS END */
#ifdef HERMESVM_SERIALIZE
using ExternalPointersVectorFunction = std::vector<void *>();
#define RUNTIME_FIELDS_SD(F) \
/* Should serialize after initialization */ \
F(HERMES_NON_CONSTEXPR, \
std::shared_ptr<llvm::raw_ostream>, \
SerializeAfterInitFile, \
nullptr) \
/* Should deserialize instead of initialization */ \
F(HERMES_NON_CONSTEXPR, \
std::shared_ptr<llvm::MemoryBuffer>, \
DeserializeFile, \
nullptr) \
/* A function to get pointer values not visible to Runtime. e.g. \
* function pointers defined in ConsoleHost*/ \
F(constexpr, \
ExternalPointersVectorFunction *, \
ExternalPointersVectorCallBack, \
nullptr)
#define RUNTIME_FIELDS(F) \
RUNTIME_FIELDS_BASE(F) \
RUNTIME_FIELDS_SD(F)
#else // ifndef HERMESVM_SERIALIZE
#define RUNTIME_FIELDS(F) RUNTIME_FIELDS_BASE(F)
#endif // HERMESVM_SERIALIZE
_HERMES_CTORCONFIG_STRUCT(RuntimeConfig, RUNTIME_FIELDS, {});
#undef RUNTIME_FIELDS
} // namespace vm
} // namespace hermes
#endif // HERMES_PUBLIC_RUNTIMECONFIG_H