Skip to content

Commit

Permalink
Use RuntimeConfig for microtasks
Browse files Browse the repository at this point in the history
Summary:
Changelog:
[general][change] - Use RuntimeConfig instead of VM Experiment Flag to set up the micro task queue.

Reviewed By: neildhar

Differential Revision: D37353947

fbshipit-source-id: 5c8f35c0a79d70cb0d234e881e55058cffb44ac8
  • Loading branch information
Michael Anthony Leon authored and facebook-github-bot committed Jul 14, 2022
1 parent fb435a7 commit 0ee7e45
Show file tree
Hide file tree
Showing 18 changed files with 37 additions and 16 deletions.
1 change: 1 addition & 0 deletions API/hermes/SynthTrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ SynthTrace::SynthTrace(
json_->emitKeyValue("ES6Promise", conf.getES6Promise());
json_->emitKeyValue("ES6Proxy", conf.getES6Proxy());
json_->emitKeyValue("Intl", conf.getIntl());
json_->emitKeyValue("MicrotasksQueue", conf.getMicrotaskQueue());
json_->emitKeyValue("enableSampledStats", conf.getEnableSampledStats());
json_->emitKeyValue("vmExperimentFlags", conf.getVMExperimentFlags());
json_->closeDict();
Expand Down
3 changes: 3 additions & 0 deletions API/hermes/SynthTraceParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ ::hermes::vm::RuntimeConfig::Builder getRuntimeConfig(JSONObject *rtConfig) {
if (auto *intl = rtConfig->get("Intl")) {
conf.withIntl(llvh::cast<JSONBoolean>(intl)->getValue());
}
if (auto *microtasks = rtConfig->get("MicrotasksQueue")) {
conf.withMicrotaskQueue(llvh::cast<JSONBoolean>(microtasks)->getValue());
}
if (auto *enableSampledStats = rtConfig->get("enableSampledStats")) {
conf.withEnableSampledStats(
llvh::cast<JSONBoolean>(enableSampledStats)->getValue());
Expand Down
2 changes: 1 addition & 1 deletion API/hermes/hermes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1511,7 +1511,7 @@ jsi::Value HermesRuntimeImpl::evaluateJavaScript(
}

bool HermesRuntimeImpl::drainMicrotasks(int maxMicrotasksHint) {
if (runtime_.useJobQueue()) {
if (runtime_.hasMicrotaskQueue()) {
checkStatus(runtime_.drainJobs());
}
// \c drainJobs is currently an unbounded execution, hence no exceptions
Expand Down
2 changes: 1 addition & 1 deletion include/hermes/ConsoleHost/ConsoleHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ namespace microtask {
/// until there was no errors (implying queue exhaustiveness).
/// Note that exceptions are directly printed to stderr.
inline void performCheckpoint(vm::Runtime &runtime) {
if (!runtime.useJobQueue())
if (!runtime.hasMicrotaskQueue())
return;

while (LLVM_UNLIKELY(runtime.drainJobs() == vm::ExecutionStatus::EXCEPTION)) {
Expand Down
6 changes: 6 additions & 0 deletions include/hermes/ConsoleHost/RuntimeFlags.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ static opt<bool> Intl(
init(RuntimeConfig::getDefaultIntl()),
cat(RuntimeCategory));

static opt<bool> MicrotaskQueue(
"Xmicrotask-queue",
desc("Enable support for using microtasks"),
init(RuntimeConfig::getDefaultMicrotaskQueue()),
cat(RuntimeCategory));

static llvh::cl::opt<bool> StopAfterInit(
"stop-after-module-init",
llvh::cl::desc("Exit once module loading is finished. Useful "
Expand Down
7 changes: 5 additions & 2 deletions include/hermes/VM/Runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -849,8 +849,8 @@ class Runtime : public PointerBase,
return hasArrayBuffer_;
}

bool useJobQueue() const {
return getVMExperimentFlags() & experiments::JobQueue;
bool hasMicrotaskQueue() const {
return hasMicrotaskQueue_;
}

bool builtinsAreFrozen() const {
Expand Down Expand Up @@ -1117,6 +1117,9 @@ class Runtime : public PointerBase,
/// Set to true if we should enable ArrayBuffer, DataView and typed arrays.
const bool hasArrayBuffer_;

/// Set to true if we are using microtasks.
const bool hasMicrotaskQueue_;

/// Set to true if we should randomize stack placement etc.
const bool shouldRandomizeMemoryLayout_;

Expand Down
2 changes: 1 addition & 1 deletion include/hermes/VM/VMExperiments.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ enum {
// GenGC = 1 << 11,
// HadesTimedIncremental = 1 << 12,
CrashTrace = 1 << 13,
JobQueue = 1 << 14,
// JobQueue = 1 << 14,
};

/// Set of flags for active VM experiments.
Expand Down
2 changes: 1 addition & 1 deletion lib/VM/JSLib/HermesInternal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ hermesInternalHasPromise(void *, Runtime &runtime, NativeArgs args) {

CallResult<HermesValue>
hermesInternalUseEngineQueue(void *, Runtime &runtime, NativeArgs args) {
return HermesValue::encodeBoolValue(runtime.useJobQueue());
return HermesValue::encodeBoolValue(runtime.hasMicrotaskQueue());
}

/// \code
Expand Down
1 change: 1 addition & 0 deletions lib/VM/Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ Runtime::Runtime(
hasES6Proxy_(runtimeConfig.getES6Proxy()),
hasIntl_(runtimeConfig.getIntl()),
hasArrayBuffer_(runtimeConfig.getArrayBuffer()),
hasMicrotaskQueue_(runtimeConfig.getMicrotaskQueue()),
shouldRandomizeMemoryLayout_(runtimeConfig.getRandomizeMemoryLayout()),
bytecodeWarmupPercent_(runtimeConfig.getBytecodeWarmupPercent()),
trackIO_(runtimeConfig.getTrackIO()),
Expand Down
3 changes: 3 additions & 0 deletions public/hermes/Public/RuntimeConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ class PinnedHermesValue;
/* Support for ArrayBuffer, DataView and typed arrays. */ \
F(constexpr, bool, ArrayBuffer, true) \
\
/* Support for using microtasks. */ \
F(constexpr, bool, MicrotaskQueue, false) \
\
/* Enable synth trace. */ \
F(constexpr, bool, TraceEnabled, false) \
\
Expand Down
2 changes: 1 addition & 1 deletion test/hermes/console-host-job-throw.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

// RUN: %hermes -Xvm-experiment-flags=16384 %s 2>&1 | %FileCheck --match-full-lines %s
// RUN: %hermes -Xmicrotask-queue %s 2>&1 | %FileCheck --match-full-lines %s

print("ConsoleHost job throws");
// CHECK-LABEL: ConsoleHost job throws
Expand Down
2 changes: 1 addition & 1 deletion test/hermes/promise-jobs-scheduled-in-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

// RUN: %hermes %s | %FileCheck --match-full-lines --check-prefix=TASK %s
// RUN: %hermes -Xvm-experiment-flags=16384 %s | %FileCheck --match-full-lines --check-prefix=MICROTASK %s
// RUN: %hermes -Xmicrotask-queue %s | %FileCheck --match-full-lines --check-prefix=MICROTASK %s

print('promise jobs scheduled in scripts');
// CHECK-LABEL: promise jobs scheduled in scripts
Expand Down
2 changes: 1 addition & 1 deletion test/hermes/promise-jobs-scheduled-in-tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

// RUN: %hermes %s | %FileCheck --match-full-lines --check-prefix=TASK %s
// RUN: %hermes -Xvm-experiment-flags=16384 %s | %FileCheck --match-full-lines --check-prefix=MICROTASK %s
// RUN: %hermes -Xmicrotask-queue %s | %FileCheck --match-full-lines --check-prefix=MICROTASK %s

print('promise jobs scheduled in tasks');
// CHECK-LABEL: promise jobs scheduled in tasks
Expand Down
2 changes: 1 addition & 1 deletion test/hermes/promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

// RUN: %hermes -Xes6-promise %s | %FileCheck --match-full-lines %s
// RUN: %hermes -Xvm-experiment-flags=16384 %s | %FileCheck --match-full-lines %s
// RUN: %hermes -Xmicrotask-queue %s | %FileCheck --match-full-lines %s
// RUN: %hermesc -O -emit-binary -out %t.hbc %s && %hermes -Xes6-promise %t.hbc | %FileCheck --match-full-lines %s

print('promise');
Expand Down
2 changes: 2 additions & 0 deletions tools/hermes/hermes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ static int executeHBCBytecodeFromCL(
.withES6Promise(cl::ES6Promise)
.withES6Proxy(cl::ES6Proxy)
.withIntl(cl::Intl)
.withMicrotaskQueue(cl::MicrotaskQueue)
.withEnableSampleProfiling(cl::SampleProfiling)
.withRandomizeMemoryLayout(cl::RandomizeMemoryLayout)
.withTrackIO(cl::TrackBytecodeIO)
Expand Down Expand Up @@ -165,6 +166,7 @@ static vm::RuntimeConfig getReplRuntimeConfig() {
.withES6Promise(cl::ES6Promise)
.withES6Proxy(cl::ES6Proxy)
.withIntl(cl::Intl)
.withMicrotaskQueue(cl::MicrotaskQueue)
.withEnableHermesInternal(cl::EnableHermesInternal)
.withEnableHermesInternalTestMethods(cl::EnableHermesInternalTestMethods)
.build();
Expand Down
1 change: 1 addition & 0 deletions tools/hvm/hvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ int main(int argc, char **argv) {
.withES6Promise(cl::ES6Promise)
.withES6Proxy(cl::ES6Proxy)
.withIntl(cl::Intl)
.withMicrotaskQueue(cl::MicrotaskQueue)
.withTrackIO(cl::TrackBytecodeIO)
.withEnableHermesInternal(cl::EnableHermesInternal)
.withEnableHermesInternalTestMethods(
Expand Down
11 changes: 5 additions & 6 deletions unittests/API/SynthTraceTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1070,12 +1070,11 @@ TEST_F(SynthTraceReplayTest, SetPropertyReplay) {

struct JobQueueReplayTest : public SynthTraceReplayTest {
JobQueueReplayTest()
: SynthTraceReplayTest(
::hermes::vm::RuntimeConfig::Builder()
.withTraceEnabled(true)
.withEnableHermesInternal(true)
.withVMExperimentFlags(::hermes::vm::experiments::JobQueue)
.build()) {}
: SynthTraceReplayTest(::hermes::vm::RuntimeConfig::Builder()
.withTraceEnabled(true)
.withEnableHermesInternal(true)
.withMicrotaskQueue(true)
.build()) {}
};

TEST_F(JobQueueReplayTest, DrainSingleMicrotask) {
Expand Down
2 changes: 2 additions & 0 deletions utils/testsuite/testsuite.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ def showStatus(filename):

es6_args = ["-Xes6-promise", "-Xes6-proxy"]
extra_run_args = ["-Xhermes-internal-test-methods"]
useMicrotasksFlag = ["-Xmicrotask-queue"]

extra_compile_flags = ["-fno-static-builtins"]

Expand Down Expand Up @@ -708,6 +709,7 @@ def runTest(
+ es6_args
+ extra_run_args
+ disableHandleSanFlag
+ useMicrotasksFlag
)
if lazy:
args.append("-lazy")
Expand Down

0 comments on commit 0ee7e45

Please sign in to comment.