Skip to content

Commit

Permalink
Always execute InternalBytecode.
Browse files Browse the repository at this point in the history
Summary:
InternalBytecode is now always executed. The current compiled JS code are only
the header and footer placeholders. But this will change up the stack once we
include `Promise.js`.

File ID in snapshot / stack traces / debugger are bumped by one due to the
internal bytecode JS file always being the 1st.

Also, the need of always pre-compiling internal bytecode implies that building
the VM now depends on building the compiler for host.

Reviewed By: dulinriley

Differential Revision: D19886900

fbshipit-source-id: 0b6090e2543c8ff070ac6643d691c857f6303e0f
  • Loading branch information
Huxpro authored and facebook-github-bot committed Oct 15, 2020
1 parent 8ffb43e commit a6eec98
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 28 deletions.
2 changes: 1 addition & 1 deletion lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ add_subdirectory(BCGen)
add_subdirectory(ConsoleHost)
add_subdirectory(Regex)
add_subdirectory(Platform)
# TODO: add_subdirectory(InternalBytecode)
add_subdirectory(InternalBytecode)
5 changes: 0 additions & 5 deletions lib/InternalBytecode/InternalBytecode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ namespace hermes {
namespace vm {

llvh::ArrayRef<uint8_t> getInternalBytecode() {
// TODO: remove the guard
#if 0
static const uint8_t InternalBytecode[] = {
#ifdef HERMES_CMAKE_BUILD
#include "InternalBytecode.inc"
Expand All @@ -22,9 +20,6 @@ llvh::ArrayRef<uint8_t> getInternalBytecode() {
};

return llvh::makeArrayRef(InternalBytecode, sizeof(InternalBytecode));
#else
return llvh::ArrayRef<uint8_t>{};
#endif
}
} // namespace vm
} // namespace hermes
2 changes: 1 addition & 1 deletion lib/VM/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ set(link_libs
hermesPlatform
hermesPlatformIntl
hermesHBCBackend
# TODO: hermesInternalBytecode
hermesInternalBytecode
dtoa
${CORE_FOUNDATION}
)
Expand Down
16 changes: 8 additions & 8 deletions lib/VM/Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,18 +326,21 @@ Runtime::Runtime(
}
#endif // HERMESVM_SERIALIZE

// BB Profiler need to be ready before running internal bytecode.
#ifdef HERMESVM_PROFILER_BB
inlineCacheProfiler_.setHiddenClassArray(
ignoreAllocationFailure(JSArray::create(this, 4, 4)).get());
#endif

// Execute our internal bytecode.
codeCoverageProfiler_->disable();
runInternalBytecode();
codeCoverageProfiler_->enable();

LLVM_DEBUG(llvh::dbgs() << "Runtime initialized\n");

samplingProfiler_ = SamplingProfiler::getInstance();
samplingProfiler_->registerRuntime(this);

#ifdef HERMESVM_PROFILER_BB
inlineCacheProfiler_.setHiddenClassArray(
ignoreAllocationFailure(JSArray::create(this, 4, 4)).get());
#endif
}

Runtime::~Runtime() {
Expand Down Expand Up @@ -1005,8 +1008,6 @@ ExecutionStatus Runtime::loadSegment(
}

void Runtime::runInternalBytecode() {
// TODO: remove the guard
#if 0
auto module = getInternalBytecode();
auto bcProvider = hbc::BCProviderFromBuffer::createBCProviderFromBuffer(
llvh::make_unique<Buffer>(module.data(), module.size()))
Expand All @@ -1025,7 +1026,6 @@ void Runtime::runInternalBytecode() {
assert(
res != ExecutionStatus::EXCEPTION && "Internal bytecode threw exception");
(void)res;
#endif
}

void Runtime::printException(llvh::raw_ostream &os, Handle<> valueHandle) {
Expand Down
2 changes: 1 addition & 1 deletion test/debugger/lazy-sourcemap.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/debugger/lazy-sourcemap.js.debug
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
sourceMap 1
sourceMap 2
continue
2 changes: 1 addition & 1 deletion test/debugger/sourcemap.js.debug
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
sourceMap 1
sourceMap 2
continue
4 changes: 2 additions & 2 deletions unittests/API/HeapSnapshotAPITest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ TEST_P(HeapSnapshotAPITest, HeapTimeline) {
stackTreeNode->second->buildStackTrace(traceFunctionInfos, strings),
R"#(
(root)(0) @ (0):0:0
global(1) @ test.js(1):1:1
alloc(2) @ test.js(1):1:27)#");
global(1) @ test.js(2):1:1
alloc(2) @ test.js(2):1:27)#");
}

INSTANTIATE_TEST_CASE_P(
Expand Down
16 changes: 8 additions & 8 deletions unittests/VMRuntime/HeapSnapshotTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -951,10 +951,10 @@ baz();
fooStackStr.c_str(),
R"#(
(root)(0) @ (0):0:0
global(1) @ test.js(1):2:1
global(2) @ test.js(1):11:4
baz(7) @ test.js(1):9:19
foo(8) @ test.js(1):3:20)#");
global(1) @ test.js(2):2:1
global(2) @ test.js(2):11:4
baz(7) @ test.js(2):9:19
foo(8) @ test.js(2):3:20)#");

auto barAllocNode = FIND_NODE_FOR_ID(barObjID, nodes, strings);
auto barStackTreeNode = idNodeMap.find(barAllocNode.traceNodeID);
Expand All @@ -965,10 +965,10 @@ foo(8) @ test.js(1):3:20)#");
barStackStr.c_str(),
R"#(
(root)(0) @ (0):0:0
global(1) @ test.js(1):2:1
global(2) @ test.js(1):11:4
baz(3) @ test.js(1):9:31
bar(4) @ test.js(1):6:20)#");
global(1) @ test.js(2):2:1
global(2) @ test.js(2):11:4
baz(3) @ test.js(2):9:31
bar(4) @ test.js(2):6:20)#");
}
#endif // HERMES_ENABLE_DEBUGGER

Expand Down
4 changes: 4 additions & 0 deletions unittests/VMRuntime/StackTracesTreeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ static std::string stackTraceToJSON(StackTracesTree &tree) {
json.closeDict();
continue;
}
llvh::StringRef scriptName{stringTable[curNode->sourceLoc.scriptName]};
if (scriptName.contains("InternalBytecode")) {
continue;
}
json.openDict();
json.emitKeyValue("name", stringTable[curNode->name]);
json.emitKeyValue("scriptName", stringTable[curNode->sourceLoc.scriptName]);
Expand Down

0 comments on commit a6eec98

Please sign in to comment.