Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/env-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,23 @@ void Environment::set_process_exit_handler(
#undef V
#undef VM

inline v8::Local<v8::Symbol> IsolateData::ffi_fast_arguments_symbol() const {
return ffi_fast_arguments_symbol_.Get(isolate_);
}
inline void IsolateData::set_ffi_fast_arguments_symbol(
v8::Local<v8::Symbol> value) {
CHECK(ffi_fast_arguments_symbol_.IsEmpty());
ffi_fast_arguments_symbol_.Set(isolate_, value);
}
inline v8::Local<v8::Symbol> IsolateData::ffi_fast_buffer_invoke_symbol() const {
return ffi_fast_buffer_invoke_symbol_.Get(isolate_);
}
inline void IsolateData::set_ffi_fast_buffer_invoke_symbol(
v8::Local<v8::Symbol> value) {
CHECK(ffi_fast_buffer_invoke_symbol_.IsEmpty());
ffi_fast_buffer_invoke_symbol_.Set(isolate_, value);
}

#define VP(PropertyName, StringValue) V(v8::Private, PropertyName)
#define VY(PropertyName, StringValue) V(v8::Symbol, PropertyName)
#define VS(PropertyName, StringValue) V(v8::String, PropertyName)
Expand All @@ -881,6 +898,21 @@ void Environment::set_process_exit_handler(
#undef VY
#undef VP

inline v8::Local<v8::Symbol> Environment::ffi_fast_arguments_symbol() const {
return isolate_data()->ffi_fast_arguments_symbol();
}
inline void Environment::set_ffi_fast_arguments_symbol(
v8::Local<v8::Symbol> value) {
isolate_data()->set_ffi_fast_arguments_symbol(value);
}
inline v8::Local<v8::Symbol> Environment::ffi_fast_buffer_invoke_symbol() const {
return isolate_data()->ffi_fast_buffer_invoke_symbol();
}
inline void Environment::set_ffi_fast_buffer_invoke_symbol(
v8::Local<v8::Symbol> value) {
isolate_data()->set_ffi_fast_buffer_invoke_symbol(value);
}

#define V(Name, label, _, __) \
inline v8::Local<v8::String> Environment::Name##_permission_string() const { \
return isolate_data()->Name##_permission_string(); \
Expand Down
20 changes: 20 additions & 0 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,17 @@ class NODE_EXTERN_PRIVATE IsolateData : public MemoryRetainer {

inline v8::Local<v8::String> async_wrap_provider(int index) const;

// Symbols used by the FFI fast-call API to key per-function metadata on raw
// FFI functions. Kept out of env_properties.h so they are created lazily at
// runtime, not while the startup snapshot is built (allocating Symbols during
// serialization advances the isolate's identity-hash RNG, which can shift the
// snapshot hashes for Object.prototype/Function.prototype and make a function
// map and a plain-object map collide in V8's NormalizedMapCache).
inline v8::Local<v8::Symbol> ffi_fast_arguments_symbol() const;
inline void set_ffi_fast_arguments_symbol(v8::Local<v8::Symbol> value);
inline v8::Local<v8::Symbol> ffi_fast_buffer_invoke_symbol() const;
inline void set_ffi_fast_buffer_invoke_symbol(v8::Local<v8::Symbol> value);

size_t max_young_gen_size = 1;
std::unordered_map<const char*, v8::Eternal<v8::String>> static_str_map;

Expand Down Expand Up @@ -245,6 +256,9 @@ class NODE_EXTERN_PRIVATE IsolateData : public MemoryRetainer {
PERMISSIONS(V)
#undef V

v8::Eternal<v8::Symbol> ffi_fast_arguments_symbol_;
v8::Eternal<v8::Symbol> ffi_fast_buffer_invoke_symbol_;

// Keep a list of all Persistent strings used for AsyncWrap Provider types.
std::array<v8::Eternal<v8::String>, AsyncWrap::PROVIDERS_LENGTH>
async_wrap_providers_;
Expand Down Expand Up @@ -892,6 +906,12 @@ class Environment final : public MemoryRetainer {
#undef VY
#undef VP

// Runtime-created FFI fast-call API Symbols (see IsolateData).
inline v8::Local<v8::Symbol> ffi_fast_arguments_symbol() const;
inline void set_ffi_fast_arguments_symbol(v8::Local<v8::Symbol> value);
inline v8::Local<v8::Symbol> ffi_fast_buffer_invoke_symbol() const;
inline void set_ffi_fast_buffer_invoke_symbol(v8::Local<v8::Symbol> value);

#define V(Name, label, _, __) \
inline v8::Local<v8::String> Name##_permission_string() const;
PERMISSIONS(V)
Expand Down
2 changes: 0 additions & 2 deletions src/env_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@
V(ffi_sb_invoke_slow_symbol, "ffi_sb_invoke_slow_symbol") \
V(ffi_sb_arguments_symbol, "ffi_sb_arguments_symbol") \
V(ffi_sb_return_symbol, "ffi_sb_return_symbol") \
V(ffi_fast_arguments_symbol, "ffi_fast_arguments_symbol") \
V(ffi_fast_buffer_invoke_symbol, "ffi_fast_buffer_invoke_symbol") \
V(constructor_key_symbol, "constructor_key_symbol") \
V(handle_onclose_symbol, "handle_onclose") \
V(no_message_symbol, "no_message_symbol") \
Expand Down
16 changes: 15 additions & 1 deletion src/node_ffi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1378,7 +1378,21 @@ static void Initialize(Local<Object> target,
env->ffi_sb_return_symbol())
.Check();
// Fast API wrappers use separate metadata Symbols so pointer-conversion
// routing does not depend on SharedBuffer internals.
// routing does not depend on SharedBuffer internals. These are created here
// (at runtime, on first `internalBinding('ffi')`) instead of being declared
// in env_properties.h, so they are not allocated while the startup snapshot
// is being built. Allocating Symbols during snapshot serialization advances
// the isolate's identity-hash RNG and shifts the identity hashes baked into
// the snapshot for Object.prototype / Function.prototype, which can make a
// function map and a plain-object map collide in V8's NormalizedMapCache.
if (env->ffi_fast_arguments_symbol().IsEmpty()) {
env->set_ffi_fast_arguments_symbol(v8::Symbol::New(
isolate, FIXED_ONE_BYTE_STRING(isolate, "ffi_fast_arguments_symbol")));
}
if (env->ffi_fast_buffer_invoke_symbol().IsEmpty()) {
env->set_ffi_fast_buffer_invoke_symbol(v8::Symbol::New(
isolate, FIXED_ONE_BYTE_STRING(isolate, "ffi_fast_buffer_invoke_symbol")));
}
target
->Set(context,
FIXED_ONE_BYTE_STRING(isolate, "kFastArguments"),
Expand Down
Loading