Commit 5e2fda25 authored by Jakob Gruber's avatar Jakob Gruber Committed by Commit Bot

[nojit] Add a builtins entry table to IsolateData

In preparation for upcoming work on Torque function pointers.

This table will be used to look up the entry address in order to call
there directly without going through the (on-heap) trampoline.

Bug: v8:7777
Change-Id: If713430c843e85371a5aaef8a3bfb5da9e0ea903
Reviewed-on: https://chromium-review.googlesource.com/c/1378172Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58245}
parent 21440dd3
...@@ -253,6 +253,15 @@ bool Builtins::IsWasmRuntimeStub(int index) { ...@@ -253,6 +253,15 @@ bool Builtins::IsWasmRuntimeStub(int index) {
UNREACHABLE(); UNREACHABLE();
} }
// static
void Builtins::UpdateBuiltinEntryTable(Isolate* isolate) {
Heap* heap = isolate->heap();
Address* builtin_entry_table = isolate->builtin_entry_table();
for (int i = 0; i < builtin_count; i++) {
builtin_entry_table[i] = heap->builtin(i)->InstructionStart();
}
}
namespace { namespace {
class OffHeapTrampolineGenerator { class OffHeapTrampolineGenerator {
......
...@@ -125,13 +125,24 @@ class Builtins { ...@@ -125,13 +125,24 @@ class Builtins {
// True, iff the given builtin contains no isolate-specific code and can be // True, iff the given builtin contains no isolate-specific code and can be
// embedded into the binary. // embedded into the binary.
static bool IsIsolateIndependent(int index) { return true; } static constexpr bool kAllBuiltinsAreIsolateIndependent = true;
static constexpr bool AllBuiltinsAreIsolateIndependent() {
return kAllBuiltinsAreIsolateIndependent;
}
static constexpr bool IsIsolateIndependent(int index) {
STATIC_ASSERT(kAllBuiltinsAreIsolateIndependent);
return kAllBuiltinsAreIsolateIndependent;
}
// Wasm runtime stubs are treated specially by wasm. To guarantee reachability // Wasm runtime stubs are treated specially by wasm. To guarantee reachability
// through near jumps, their code is completely copied into a fresh off-heap // through near jumps, their code is completely copied into a fresh off-heap
// area. // area.
static bool IsWasmRuntimeStub(int index); static bool IsWasmRuntimeStub(int index);
// Updates the table of builtin entry points based on the current contents of
// the builtins table.
static void UpdateBuiltinEntryTable(Isolate* isolate);
bool is_initialized() const { return initialized_; } bool is_initialized() const { return initialized_; }
// Used by SetupIsolateDelegate and Deserializer. // Used by SetupIsolateDelegate and Deserializer.
......
...@@ -3905,6 +3905,15 @@ void Heap::IterateBuiltins(RootVisitor* v) { ...@@ -3905,6 +3905,15 @@ void Heap::IterateBuiltins(RootVisitor* v) {
v->VisitRootPointer(Root::kBuiltins, Builtins::name(i), v->VisitRootPointer(Root::kBuiltins, Builtins::name(i),
FullObjectSlot(builtin_address(i))); FullObjectSlot(builtin_address(i)));
} }
#ifdef V8_EMBEDDED_BUILTINS
// The entry table does not need to be updated if all builtins are embedded.
STATIC_ASSERT(Builtins::AllBuiltinsAreIsolateIndependent());
#else
// If builtins are not embedded, they may move and thus the entry table must
// be updated.
// TODO(v8:6666): Remove once builtins are embedded unconditionally.
Builtins::UpdateBuiltinEntryTable(isolate());
#endif // V8_EMBEDDED_BUILTINS
} }
// TODO(1236194): Since the heap size is configurable on the command line // TODO(1236194): Since the heap size is configurable on the command line
......
...@@ -93,6 +93,7 @@ class IsolateData final { ...@@ -93,6 +93,7 @@ class IsolateData final {
return &external_reference_table_; return &external_reference_table_;
} }
Address* builtin_entry_table() { return builtin_entry_table_; }
Address* builtins() { return builtins_; } Address* builtins() { return builtins_; }
private: private:
...@@ -104,6 +105,7 @@ class IsolateData final { ...@@ -104,6 +105,7 @@ class IsolateData final {
V(kExternalMemoryAtLastMarkCompactOffset, kInt64Size) \ V(kExternalMemoryAtLastMarkCompactOffset, kInt64Size) \
V(kRootsTableOffset, RootsTable::kEntriesCount* kPointerSize) \ V(kRootsTableOffset, RootsTable::kEntriesCount* kPointerSize) \
V(kExternalReferenceTableOffset, ExternalReferenceTable::kSizeInBytes) \ V(kExternalReferenceTableOffset, ExternalReferenceTable::kSizeInBytes) \
V(kBuiltinEntryTableOffset, Builtins::builtin_count* kSystemPointerSize) \
V(kBuiltinsTableOffset, Builtins::builtin_count* kPointerSize) \ V(kBuiltinsTableOffset, Builtins::builtin_count* kPointerSize) \
V(kVirtualCallTargetRegisterOffset, kPointerSize) \ V(kVirtualCallTargetRegisterOffset, kPointerSize) \
V(kFastCCallCallerFPOffset, kPointerSize) \ V(kFastCCallCallerFPOffset, kPointerSize) \
...@@ -138,6 +140,11 @@ class IsolateData final { ...@@ -138,6 +140,11 @@ class IsolateData final {
ExternalReferenceTable external_reference_table_; ExternalReferenceTable external_reference_table_;
// The entry points for all builtins. This corresponds to
// Code::InstructionStart() for each Code object in the builtins table below.
// The entry table is in IsolateData for easy access through kRootRegister.
Address builtin_entry_table_[Builtins::builtin_count] = {};
// The entries in this array are tagged pointers to Code objects. // The entries in this array are tagged pointers to Code objects.
Address builtins_[Builtins::builtin_count] = {}; Address builtins_[Builtins::builtin_count] = {};
......
...@@ -3320,6 +3320,9 @@ bool Isolate::Init(StartupDeserializer* des) { ...@@ -3320,6 +3320,9 @@ bool Isolate::Init(StartupDeserializer* des) {
delete setup_delegate_; delete setup_delegate_;
setup_delegate_ = nullptr; setup_delegate_ = nullptr;
// Initialize the builtin entry table.
Builtins::UpdateBuiltinEntryTable(this);
if (FLAG_print_builtin_code) builtins()->PrintBuiltinCode(); if (FLAG_print_builtin_code) builtins()->PrintBuiltinCode();
if (FLAG_print_builtin_size) builtins()->PrintBuiltinSize(); if (FLAG_print_builtin_size) builtins()->PrintBuiltinSize();
......
...@@ -1020,6 +1020,7 @@ class Isolate final : private HiddenFactory { ...@@ -1020,6 +1020,7 @@ class Isolate final : private HiddenFactory {
return isolate_data()->external_reference_table(); return isolate_data()->external_reference_table();
} }
Address* builtin_entry_table() { return isolate_data_.builtin_entry_table(); }
V8_INLINE Address* builtins_table() { return isolate_data_.builtins(); } V8_INLINE Address* builtins_table() { return isolate_data_.builtins(); }
StubCache* load_stub_cache() { return load_stub_cache_; } StubCache* load_stub_cache() { return load_stub_cache_; }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment