Skip to content

Commit f17c794

Browse files
targosMylesBorins
authored andcommitted
deps: patch V8 to be API/ABI compatible with 7.8 (from 7.9)
Revert "[cpu-profiler] Removed deprecated methods, advance deprecation" This reverts commit abf47eee04ccd4634cf46e75d0a00ff816d56b7e. Revert "api: Rely on v8::Data base type for garbage collection support" This reverts commit 55be65da1597926416e5546d95ac723419e4c8ef. Revert "[cleanup] Remove deprecated Neuter API calls" This reverts commit 0f067efe6908c9785d1aa69e488c57d5a3c36841. Revert "[api] Remove deprecated method" This reverts commit ebe753234a3c868a58429f1d096397b229a96388. Revert "[wasm] Remove obsolete --no-wasm-shared-code flag This reverts commit 6f8381958cb7808a2ba12e72617e8249a86117d2. Remove array_buffer_allocator_shared from Isolate::CreateParams. Co-authored-by: Anna Henningsen <[email protected]> PR-URL: #30513 Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Myles Borins <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 0d5de1a commit f17c794

12 files changed

+156
-143
lines changed

deps/v8/include/v8-profiler.h

+14
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,20 @@ class V8_EXPORT CpuProfiler {
371371
*/
372372
CpuProfile* StopProfiling(Local<String> title);
373373

374+
/**
375+
* Force collection of a sample. Must be called on the VM thread.
376+
* Recording the forced sample does not contribute to the aggregated
377+
* profile statistics.
378+
*/
379+
V8_DEPRECATED("Use static CollectSample(Isolate*) instead.")
380+
void CollectSample();
381+
382+
/**
383+
* Tells the profiler whether the embedder is idle.
384+
*/
385+
V8_DEPRECATED("Use Isolate::SetIdle(bool) instead.")
386+
void SetIdle(bool is_idle);
387+
374388
/**
375389
* Generate more detailed source positions to code objects. This results in
376390
* better results when mapping profiling samples to script source.

deps/v8/include/v8.h

+45-19
Original file line numberDiff line numberDiff line change
@@ -1275,8 +1275,9 @@ class V8_EXPORT SealHandleScope {
12751275

12761276
// --- Special objects ---
12771277

1278+
12781279
/**
1279-
* The superclass of objects that can reside on V8's heap.
1280+
* The superclass of values and API object templates.
12801281
*/
12811282
class V8_EXPORT Data {
12821283
private:
@@ -1423,7 +1424,7 @@ class V8_EXPORT UnboundScript {
14231424
/**
14241425
* A compiled JavaScript module, not yet tied to a Context.
14251426
*/
1426-
class V8_EXPORT UnboundModuleScript : public Data {
1427+
class V8_EXPORT UnboundModuleScript {
14271428
// Only used as a container for code caching.
14281429
};
14291430

@@ -1446,7 +1447,7 @@ class V8_EXPORT Location {
14461447
/**
14471448
* A compiled JavaScript module.
14481449
*/
1449-
class V8_EXPORT Module : public Data {
1450+
class V8_EXPORT Module {
14501451
public:
14511452
/**
14521453
* The different states a module can be in.
@@ -4644,37 +4645,47 @@ class V8_EXPORT CompiledWasmModule {
46444645
// An instance of WebAssembly.Module.
46454646
class V8_EXPORT WasmModuleObject : public Object {
46464647
public:
4647-
WasmModuleObject() = delete;
4648-
46494648
/**
46504649
* An opaque, native heap object for transferring wasm modules. It
46514650
* supports move semantics, and does not support copy semantics.
4651+
* TODO(wasm): Merge this with CompiledWasmModule once code sharing is always
4652+
* enabled.
46524653
*/
4653-
using TransferrableModule = CompiledWasmModule;
4654+
class TransferrableModule final {
4655+
public:
4656+
TransferrableModule(TransferrableModule&& src) = default;
4657+
TransferrableModule(const TransferrableModule& src) = delete;
4658+
4659+
TransferrableModule& operator=(TransferrableModule&& src) = default;
4660+
TransferrableModule& operator=(const TransferrableModule& src) = delete;
4661+
4662+
private:
4663+
typedef std::shared_ptr<internal::wasm::NativeModule> SharedModule;
4664+
friend class WasmModuleObject;
4665+
explicit TransferrableModule(SharedModule shared_module)
4666+
: shared_module_(std::move(shared_module)) {}
4667+
TransferrableModule(OwnedBuffer serialized, OwnedBuffer bytes)
4668+
: serialized_(std::move(serialized)), wire_bytes_(std::move(bytes)) {}
4669+
4670+
SharedModule shared_module_;
4671+
OwnedBuffer serialized_ = {nullptr, 0};
4672+
OwnedBuffer wire_bytes_ = {nullptr, 0};
4673+
};
46544674

46554675
/**
46564676
* Get an in-memory, non-persistable, and context-independent (meaning,
46574677
* suitable for transfer to another Isolate and Context) representation
46584678
* of this wasm compiled module.
46594679
*/
4660-
V8_DEPRECATED("Use GetCompiledModule")
46614680
TransferrableModule GetTransferrableModule();
46624681

46634682
/**
46644683
* Efficiently re-create a WasmModuleObject, without recompiling, from
46654684
* a TransferrableModule.
46664685
*/
4667-
V8_DEPRECATED("Use FromCompiledModule")
46684686
static MaybeLocal<WasmModuleObject> FromTransferrableModule(
46694687
Isolate* isolate, const TransferrableModule&);
46704688

4671-
/**
4672-
* Efficiently re-create a WasmModuleObject, without recompiling, from
4673-
* a CompiledWasmModule.
4674-
*/
4675-
static MaybeLocal<WasmModuleObject> FromCompiledModule(
4676-
Isolate* isolate, const CompiledWasmModule&);
4677-
46784689
/**
46794690
* Get the compiled module for this module object. The compiled module can be
46804691
* shared by several module objects.
@@ -4697,7 +4708,11 @@ class V8_EXPORT WasmModuleObject : public Object {
46974708
static MaybeLocal<WasmModuleObject> Compile(Isolate* isolate,
46984709
const uint8_t* start,
46994710
size_t length);
4711+
static MemorySpan<const uint8_t> AsReference(const OwnedBuffer& buff) {
4712+
return {buff.buffer.get(), buff.size};
4713+
}
47004714

4715+
WasmModuleObject();
47014716
static void CheckCast(Value* obj);
47024717
};
47034718

@@ -5053,6 +5068,12 @@ class V8_EXPORT ArrayBuffer : public Object {
50535068
*/
50545069
bool IsDetachable() const;
50555070

5071+
// TODO(913887): fix the use of 'neuter' in the API.
5072+
V8_DEPRECATED("Use IsDetachable() instead.")
5073+
inline bool IsNeuterable() const {
5074+
return IsDetachable();
5075+
}
5076+
50565077
/**
50575078
* Detaches this ArrayBuffer and all its views (typed arrays).
50585079
* Detaching sets the byte length of the buffer and all typed arrays to zero,
@@ -5061,6 +5082,10 @@ class V8_EXPORT ArrayBuffer : public Object {
50615082
*/
50625083
void Detach();
50635084

5085+
// TODO(913887): fix the use of 'neuter' in the API.
5086+
V8_DEPRECATED("Use Detach() instead.")
5087+
inline void Neuter() { Detach(); }
5088+
50645089
/**
50655090
* Make this ArrayBuffer external. The pointer to underlying memory block
50665091
* and byte length are returned as |Contents| structure. After ArrayBuffer
@@ -7670,9 +7695,7 @@ class V8_EXPORT EmbedderHeapTracer {
76707695
virtual void RegisterV8References(
76717696
const std::vector<std::pair<void*, void*> >& embedder_fields) = 0;
76727697

7673-
V8_DEPRECATE_SOON("Use version taking TracedReferenceBase<v8::Data> argument")
76747698
void RegisterEmbedderReference(const TracedReferenceBase<v8::Value>& ref);
7675-
void RegisterEmbedderReference(const TracedReferenceBase<v8::Data>& ref);
76767699

76777700
/**
76787701
* Called at the beginning of a GC cycle.
@@ -7849,7 +7872,6 @@ class V8_EXPORT Isolate {
78497872
create_histogram_callback(nullptr),
78507873
add_histogram_sample_callback(nullptr),
78517874
array_buffer_allocator(nullptr),
7852-
array_buffer_allocator_shared(),
78537875
external_references(nullptr),
78547876
allow_atomics_wait(true),
78557877
only_terminate_in_safe_scope(false) {}
@@ -7896,7 +7918,6 @@ class V8_EXPORT Isolate {
78967918
* management for the allocator instance.
78977919
*/
78987920
ArrayBuffer::Allocator* array_buffer_allocator;
7899-
std::shared_ptr<ArrayBuffer::Allocator> array_buffer_allocator_shared;
79007921

79017922
/**
79027923
* Specifies an optional nullptr-terminated array of raw addresses in the
@@ -7918,6 +7939,9 @@ class V8_EXPORT Isolate {
79187939
bool only_terminate_in_safe_scope;
79197940
};
79207941

7942+
void SetArrayBufferAllocatorShared(
7943+
std::shared_ptr<ArrayBuffer::Allocator> allocator);
7944+
79217945

79227946
/**
79237947
* Stack-allocated class which sets the isolate for all operations
@@ -9192,6 +9216,8 @@ class V8_EXPORT V8 {
91929216
*/
91939217
static void SetFlagsFromString(const char* str);
91949218
static void SetFlagsFromString(const char* str, size_t length);
9219+
V8_DEPRECATED("use size_t version")
9220+
static void SetFlagsFromString(const char* str, int length);
91959221

91969222
/**
91979223
* Sets V8 flags from the command line.

deps/v8/src/api/api.cc

+50-30
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,11 @@ void V8::SetFlagsFromString(const char* str, size_t length) {
907907
i::FlagList::EnforceFlagImplications();
908908
}
909909

910+
void V8::SetFlagsFromString(const char* str, int length) {
911+
CHECK_LE(0, length);
912+
SetFlagsFromString(str, static_cast<size_t>(length));
913+
}
914+
910915
void V8::SetFlagsFromCommandLine(int* argc, char** argv, bool remove_flags) {
911916
i::FlagList::SetFlagsFromCommandLine(argc, argv, remove_flags);
912917
}
@@ -7111,7 +7116,21 @@ MemorySpan<const uint8_t> CompiledWasmModule::GetWireBytesRef() {
71117116

71127117
WasmModuleObject::TransferrableModule
71137118
WasmModuleObject::GetTransferrableModule() {
7114-
return GetCompiledModule();
7119+
if (i::FLAG_wasm_shared_code) {
7120+
i::Handle<i::WasmModuleObject> obj =
7121+
i::Handle<i::WasmModuleObject>::cast(Utils::OpenHandle(this));
7122+
return TransferrableModule(obj->shared_native_module());
7123+
} else {
7124+
CompiledWasmModule compiled_module = GetCompiledModule();
7125+
OwnedBuffer serialized_module = compiled_module.Serialize();
7126+
MemorySpan<const uint8_t> wire_bytes_ref =
7127+
compiled_module.GetWireBytesRef();
7128+
size_t wire_size = wire_bytes_ref.size();
7129+
std::unique_ptr<uint8_t[]> wire_bytes_copy(new uint8_t[wire_size]);
7130+
memcpy(wire_bytes_copy.get(), wire_bytes_ref.data(), wire_size);
7131+
return TransferrableModule(std::move(serialized_module),
7132+
{std::move(wire_bytes_copy), wire_size});
7133+
}
71157134
}
71167135

71177136
CompiledWasmModule WasmModuleObject::GetCompiledModule() {
@@ -7123,17 +7142,17 @@ CompiledWasmModule WasmModuleObject::GetCompiledModule() {
71237142
MaybeLocal<WasmModuleObject> WasmModuleObject::FromTransferrableModule(
71247143
Isolate* isolate,
71257144
const WasmModuleObject::TransferrableModule& transferrable_module) {
7126-
return FromCompiledModule(isolate, transferrable_module);
7127-
}
7128-
7129-
MaybeLocal<WasmModuleObject> WasmModuleObject::FromCompiledModule(
7130-
Isolate* isolate, const CompiledWasmModule& compiled_module) {
7131-
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
7132-
i::Handle<i::WasmModuleObject> module_object =
7133-
i_isolate->wasm_engine()->ImportNativeModule(
7134-
i_isolate, Utils::Open(compiled_module));
7135-
return Local<WasmModuleObject>::Cast(
7136-
Utils::ToLocal(i::Handle<i::JSObject>::cast(module_object)));
7145+
if (i::FLAG_wasm_shared_code) {
7146+
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
7147+
i::Handle<i::WasmModuleObject> module_object =
7148+
i_isolate->wasm_engine()->ImportNativeModule(
7149+
i_isolate, transferrable_module.shared_module_);
7150+
return Local<WasmModuleObject>::Cast(
7151+
Utils::ToLocal(i::Handle<i::JSObject>::cast(module_object)));
7152+
} else {
7153+
return Deserialize(isolate, AsReference(transferrable_module.serialized_),
7154+
AsReference(transferrable_module.wire_bytes_));
7155+
}
71377156
}
71387157

71397158
MaybeLocal<WasmModuleObject> WasmModuleObject::Deserialize(
@@ -8167,20 +8186,20 @@ Isolate* Isolate::Allocate() {
81678186
return reinterpret_cast<Isolate*>(i::Isolate::New());
81688187
}
81698188

8189+
void Isolate::SetArrayBufferAllocatorShared(
8190+
std::shared_ptr<ArrayBuffer::Allocator> allocator) {
8191+
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
8192+
CHECK_EQ(allocator.get(), isolate->array_buffer_allocator());
8193+
isolate->set_array_buffer_allocator_shared(std::move(allocator));
8194+
}
8195+
81708196
// static
81718197
// This is separate so that tests can provide a different |isolate|.
81728198
void Isolate::Initialize(Isolate* isolate,
81738199
const v8::Isolate::CreateParams& params) {
81748200
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
8175-
if (auto allocator = params.array_buffer_allocator_shared) {
8176-
CHECK(params.array_buffer_allocator == nullptr ||
8177-
params.array_buffer_allocator == allocator.get());
8178-
i_isolate->set_array_buffer_allocator(allocator.get());
8179-
i_isolate->set_array_buffer_allocator_shared(std::move(allocator));
8180-
} else {
8181-
CHECK_NOT_NULL(params.array_buffer_allocator);
8182-
i_isolate->set_array_buffer_allocator(params.array_buffer_allocator);
8183-
}
8201+
CHECK_NOT_NULL(params.array_buffer_allocator);
8202+
i_isolate->set_array_buffer_allocator(params.array_buffer_allocator);
81848203
if (params.snapshot_blob != nullptr) {
81858204
i_isolate->set_snapshot_blob(params.snapshot_blob);
81868205
} else {
@@ -10221,6 +10240,10 @@ void CpuProfiler::SetUsePreciseSampling(bool use_precise_sampling) {
1022110240
use_precise_sampling);
1022210241
}
1022310242

10243+
void CpuProfiler::CollectSample() {
10244+
reinterpret_cast<i::CpuProfiler*>(this)->CollectSample();
10245+
}
10246+
1022410247
void CpuProfiler::StartProfiling(Local<String> title,
1022510248
CpuProfilingOptions options) {
1022610249
reinterpret_cast<i::CpuProfiler*>(this)->StartProfiling(
@@ -10248,6 +10271,12 @@ CpuProfile* CpuProfiler::StopProfiling(Local<String> title) {
1024810271
*Utils::OpenHandle(*title)));
1024910272
}
1025010273

10274+
void CpuProfiler::SetIdle(bool is_idle) {
10275+
i::CpuProfiler* profiler = reinterpret_cast<i::CpuProfiler*>(this);
10276+
i::Isolate* isolate = profiler->isolate();
10277+
isolate->SetIdle(is_idle);
10278+
}
10279+
1025110280
void CpuProfiler::UseDetailedSourcePositionsForProfiling(Isolate* isolate) {
1025210281
reinterpret_cast<i::Isolate*>(isolate)
1025310282
->set_detailed_source_positions_for_profiling(true);
@@ -10639,15 +10668,6 @@ void EmbedderHeapTracer::DecreaseAllocatedSize(size_t bytes) {
1063910668
}
1064010669
}
1064110670

10642-
void EmbedderHeapTracer::RegisterEmbedderReference(
10643-
const TracedReferenceBase<v8::Data>& ref) {
10644-
if (ref.IsEmpty()) return;
10645-
10646-
i::Heap* const heap = reinterpret_cast<i::Isolate*>(isolate_)->heap();
10647-
heap->RegisterExternallyReferencedObject(
10648-
reinterpret_cast<i::Address*>(ref.val_));
10649-
}
10650-
1065110671
void EmbedderHeapTracer::RegisterEmbedderReference(
1065210672
const TracedReferenceBase<v8::Value>& ref) {
1065310673
if (ref.IsEmpty()) return;

deps/v8/src/api/api.h

-5
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,6 @@ class Utils {
276276
return CompiledWasmModule{std::move(native_module)};
277277
}
278278

279-
static inline const std::shared_ptr<i::wasm::NativeModule>& Open(
280-
const CompiledWasmModule& compiled_module) {
281-
return compiled_module.native_module_;
282-
}
283-
284279
private:
285280
static void ReportApiFailure(const char* location, const char* message);
286281
};

deps/v8/src/d8/d8.cc

+6-4
Original file line numberDiff line numberDiff line change
@@ -3329,7 +3329,7 @@ class Serializer : public ValueSerializer::Delegate {
33293329

33303330
size_t index = wasm_modules_.size();
33313331
wasm_modules_.emplace_back(isolate_, module);
3332-
data_->compiled_wasm_modules_.push_back(module->GetCompiledModule());
3332+
data_->transferrable_modules_.push_back(module->GetTransferrableModule());
33333333
return Just<uint32_t>(static_cast<uint32_t>(index));
33343334
}
33353335

@@ -3455,9 +3455,11 @@ class Deserializer : public ValueDeserializer::Delegate {
34553455
MaybeLocal<WasmModuleObject> GetWasmModuleFromId(
34563456
Isolate* isolate, uint32_t transfer_id) override {
34573457
DCHECK_NOT_NULL(data_);
3458-
if (transfer_id >= data_->compiled_wasm_modules().size()) return {};
3459-
return WasmModuleObject::FromCompiledModule(
3460-
isolate_, data_->compiled_wasm_modules().at(transfer_id));
3458+
if (transfer_id < data_->transferrable_modules().size()) {
3459+
return WasmModuleObject::FromTransferrableModule(
3460+
isolate_, data_->transferrable_modules().at(transfer_id));
3461+
}
3462+
return MaybeLocal<WasmModuleObject>();
34613463
}
34623464

34633465
private:

deps/v8/src/d8/d8.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,9 @@ class SerializationData {
123123
const std::vector<std::shared_ptr<v8::BackingStore>>& sab_backing_stores() {
124124
return sab_backing_stores_;
125125
}
126-
const std::vector<CompiledWasmModule>& compiled_wasm_modules() {
127-
return compiled_wasm_modules_;
126+
const std::vector<WasmModuleObject::TransferrableModule>&
127+
transferrable_modules() {
128+
return transferrable_modules_;
128129
}
129130

130131
private:
@@ -136,7 +137,7 @@ class SerializationData {
136137
size_t size_;
137138
std::vector<std::shared_ptr<v8::BackingStore>> backing_stores_;
138139
std::vector<std::shared_ptr<v8::BackingStore>> sab_backing_stores_;
139-
std::vector<CompiledWasmModule> compiled_wasm_modules_;
140+
std::vector<WasmModuleObject::TransferrableModule> transferrable_modules_;
140141

141142
private:
142143
friend class Serializer;

deps/v8/src/flags/flag-definitions.h

+3
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,9 @@ DEFINE_BOOL(wasm_math_intrinsics, true,
733733
DEFINE_BOOL(wasm_shared_engine, true,
734734
"shares one wasm engine between all isolates within a process")
735735
DEFINE_IMPLICATION(future, wasm_shared_engine)
736+
DEFINE_BOOL(wasm_shared_code, true,
737+
"shares code underlying a wasm module when it is transferred")
738+
DEFINE_IMPLICATION(future, wasm_shared_code)
736739
DEFINE_BOOL(wasm_trap_handler, true,
737740
"use signal handlers to catch out of bounds memory access in wasm"
738741
" (currently Linux x86_64 only)")

0 commit comments

Comments
 (0)