Skip to content

Commit

Permalink
deps: patch V8 to be API/ABI compatible with 7.8 (from 7.9)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
targos authored and MylesBorins committed Nov 21, 2019
1 parent 0d5de1a commit f17c794
Show file tree
Hide file tree
Showing 12 changed files with 156 additions and 143 deletions.
14 changes: 14 additions & 0 deletions deps/v8/include/v8-profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,20 @@ class V8_EXPORT CpuProfiler {
*/
CpuProfile* StopProfiling(Local<String> title);

/**
* Force collection of a sample. Must be called on the VM thread.
* Recording the forced sample does not contribute to the aggregated
* profile statistics.
*/
V8_DEPRECATED("Use static CollectSample(Isolate*) instead.")
void CollectSample();

/**
* Tells the profiler whether the embedder is idle.
*/
V8_DEPRECATED("Use Isolate::SetIdle(bool) instead.")
void SetIdle(bool is_idle);

/**
* Generate more detailed source positions to code objects. This results in
* better results when mapping profiling samples to script source.
Expand Down
64 changes: 45 additions & 19 deletions deps/v8/include/v8.h
Original file line number Diff line number Diff line change
Expand Up @@ -1275,8 +1275,9 @@ class V8_EXPORT SealHandleScope {

// --- Special objects ---


/**
* The superclass of objects that can reside on V8's heap.
* The superclass of values and API object templates.
*/
class V8_EXPORT Data {
private:
Expand Down Expand Up @@ -1423,7 +1424,7 @@ class V8_EXPORT UnboundScript {
/**
* A compiled JavaScript module, not yet tied to a Context.
*/
class V8_EXPORT UnboundModuleScript : public Data {
class V8_EXPORT UnboundModuleScript {
// Only used as a container for code caching.
};

Expand All @@ -1446,7 +1447,7 @@ class V8_EXPORT Location {
/**
* A compiled JavaScript module.
*/
class V8_EXPORT Module : public Data {
class V8_EXPORT Module {
public:
/**
* The different states a module can be in.
Expand Down Expand Up @@ -4644,37 +4645,47 @@ class V8_EXPORT CompiledWasmModule {
// An instance of WebAssembly.Module.
class V8_EXPORT WasmModuleObject : public Object {
public:
WasmModuleObject() = delete;

/**
* An opaque, native heap object for transferring wasm modules. It
* supports move semantics, and does not support copy semantics.
* TODO(wasm): Merge this with CompiledWasmModule once code sharing is always
* enabled.
*/
using TransferrableModule = CompiledWasmModule;
class TransferrableModule final {
public:
TransferrableModule(TransferrableModule&& src) = default;
TransferrableModule(const TransferrableModule& src) = delete;

TransferrableModule& operator=(TransferrableModule&& src) = default;
TransferrableModule& operator=(const TransferrableModule& src) = delete;

private:
typedef std::shared_ptr<internal::wasm::NativeModule> SharedModule;
friend class WasmModuleObject;
explicit TransferrableModule(SharedModule shared_module)
: shared_module_(std::move(shared_module)) {}
TransferrableModule(OwnedBuffer serialized, OwnedBuffer bytes)
: serialized_(std::move(serialized)), wire_bytes_(std::move(bytes)) {}

SharedModule shared_module_;
OwnedBuffer serialized_ = {nullptr, 0};
OwnedBuffer wire_bytes_ = {nullptr, 0};
};

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

/**
* Efficiently re-create a WasmModuleObject, without recompiling, from
* a TransferrableModule.
*/
V8_DEPRECATED("Use FromCompiledModule")
static MaybeLocal<WasmModuleObject> FromTransferrableModule(
Isolate* isolate, const TransferrableModule&);

/**
* Efficiently re-create a WasmModuleObject, without recompiling, from
* a CompiledWasmModule.
*/
static MaybeLocal<WasmModuleObject> FromCompiledModule(
Isolate* isolate, const CompiledWasmModule&);

/**
* Get the compiled module for this module object. The compiled module can be
* shared by several module objects.
Expand All @@ -4697,7 +4708,11 @@ class V8_EXPORT WasmModuleObject : public Object {
static MaybeLocal<WasmModuleObject> Compile(Isolate* isolate,
const uint8_t* start,
size_t length);
static MemorySpan<const uint8_t> AsReference(const OwnedBuffer& buff) {
return {buff.buffer.get(), buff.size};
}

WasmModuleObject();
static void CheckCast(Value* obj);
};

Expand Down Expand Up @@ -5053,6 +5068,12 @@ class V8_EXPORT ArrayBuffer : public Object {
*/
bool IsDetachable() const;

// TODO(913887): fix the use of 'neuter' in the API.
V8_DEPRECATED("Use IsDetachable() instead.")
inline bool IsNeuterable() const {
return IsDetachable();
}

/**
* Detaches this ArrayBuffer and all its views (typed arrays).
* Detaching sets the byte length of the buffer and all typed arrays to zero,
Expand All @@ -5061,6 +5082,10 @@ class V8_EXPORT ArrayBuffer : public Object {
*/
void Detach();

// TODO(913887): fix the use of 'neuter' in the API.
V8_DEPRECATED("Use Detach() instead.")
inline void Neuter() { Detach(); }

/**
* Make this ArrayBuffer external. The pointer to underlying memory block
* and byte length are returned as |Contents| structure. After ArrayBuffer
Expand Down Expand Up @@ -7670,9 +7695,7 @@ class V8_EXPORT EmbedderHeapTracer {
virtual void RegisterV8References(
const std::vector<std::pair<void*, void*> >& embedder_fields) = 0;

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

/**
* Called at the beginning of a GC cycle.
Expand Down Expand Up @@ -7849,7 +7872,6 @@ class V8_EXPORT Isolate {
create_histogram_callback(nullptr),
add_histogram_sample_callback(nullptr),
array_buffer_allocator(nullptr),
array_buffer_allocator_shared(),
external_references(nullptr),
allow_atomics_wait(true),
only_terminate_in_safe_scope(false) {}
Expand Down Expand Up @@ -7896,7 +7918,6 @@ class V8_EXPORT Isolate {
* management for the allocator instance.
*/
ArrayBuffer::Allocator* array_buffer_allocator;
std::shared_ptr<ArrayBuffer::Allocator> array_buffer_allocator_shared;

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

void SetArrayBufferAllocatorShared(
std::shared_ptr<ArrayBuffer::Allocator> allocator);


/**
* Stack-allocated class which sets the isolate for all operations
Expand Down Expand Up @@ -9192,6 +9216,8 @@ class V8_EXPORT V8 {
*/
static void SetFlagsFromString(const char* str);
static void SetFlagsFromString(const char* str, size_t length);
V8_DEPRECATED("use size_t version")
static void SetFlagsFromString(const char* str, int length);

/**
* Sets V8 flags from the command line.
Expand Down
80 changes: 50 additions & 30 deletions deps/v8/src/api/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,11 @@ void V8::SetFlagsFromString(const char* str, size_t length) {
i::FlagList::EnforceFlagImplications();
}

void V8::SetFlagsFromString(const char* str, int length) {
CHECK_LE(0, length);
SetFlagsFromString(str, static_cast<size_t>(length));
}

void V8::SetFlagsFromCommandLine(int* argc, char** argv, bool remove_flags) {
i::FlagList::SetFlagsFromCommandLine(argc, argv, remove_flags);
}
Expand Down Expand Up @@ -7111,7 +7116,21 @@ MemorySpan<const uint8_t> CompiledWasmModule::GetWireBytesRef() {

WasmModuleObject::TransferrableModule
WasmModuleObject::GetTransferrableModule() {
return GetCompiledModule();
if (i::FLAG_wasm_shared_code) {
i::Handle<i::WasmModuleObject> obj =
i::Handle<i::WasmModuleObject>::cast(Utils::OpenHandle(this));
return TransferrableModule(obj->shared_native_module());
} else {
CompiledWasmModule compiled_module = GetCompiledModule();
OwnedBuffer serialized_module = compiled_module.Serialize();
MemorySpan<const uint8_t> wire_bytes_ref =
compiled_module.GetWireBytesRef();
size_t wire_size = wire_bytes_ref.size();
std::unique_ptr<uint8_t[]> wire_bytes_copy(new uint8_t[wire_size]);
memcpy(wire_bytes_copy.get(), wire_bytes_ref.data(), wire_size);
return TransferrableModule(std::move(serialized_module),
{std::move(wire_bytes_copy), wire_size});
}
}

CompiledWasmModule WasmModuleObject::GetCompiledModule() {
Expand All @@ -7123,17 +7142,17 @@ CompiledWasmModule WasmModuleObject::GetCompiledModule() {
MaybeLocal<WasmModuleObject> WasmModuleObject::FromTransferrableModule(
Isolate* isolate,
const WasmModuleObject::TransferrableModule& transferrable_module) {
return FromCompiledModule(isolate, transferrable_module);
}

MaybeLocal<WasmModuleObject> WasmModuleObject::FromCompiledModule(
Isolate* isolate, const CompiledWasmModule& compiled_module) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
i::Handle<i::WasmModuleObject> module_object =
i_isolate->wasm_engine()->ImportNativeModule(
i_isolate, Utils::Open(compiled_module));
return Local<WasmModuleObject>::Cast(
Utils::ToLocal(i::Handle<i::JSObject>::cast(module_object)));
if (i::FLAG_wasm_shared_code) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
i::Handle<i::WasmModuleObject> module_object =
i_isolate->wasm_engine()->ImportNativeModule(
i_isolate, transferrable_module.shared_module_);
return Local<WasmModuleObject>::Cast(
Utils::ToLocal(i::Handle<i::JSObject>::cast(module_object)));
} else {
return Deserialize(isolate, AsReference(transferrable_module.serialized_),
AsReference(transferrable_module.wire_bytes_));
}
}

MaybeLocal<WasmModuleObject> WasmModuleObject::Deserialize(
Expand Down Expand Up @@ -8167,20 +8186,20 @@ Isolate* Isolate::Allocate() {
return reinterpret_cast<Isolate*>(i::Isolate::New());
}

void Isolate::SetArrayBufferAllocatorShared(
std::shared_ptr<ArrayBuffer::Allocator> allocator) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
CHECK_EQ(allocator.get(), isolate->array_buffer_allocator());
isolate->set_array_buffer_allocator_shared(std::move(allocator));
}

// static
// This is separate so that tests can provide a different |isolate|.
void Isolate::Initialize(Isolate* isolate,
const v8::Isolate::CreateParams& params) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
if (auto allocator = params.array_buffer_allocator_shared) {
CHECK(params.array_buffer_allocator == nullptr ||
params.array_buffer_allocator == allocator.get());
i_isolate->set_array_buffer_allocator(allocator.get());
i_isolate->set_array_buffer_allocator_shared(std::move(allocator));
} else {
CHECK_NOT_NULL(params.array_buffer_allocator);
i_isolate->set_array_buffer_allocator(params.array_buffer_allocator);
}
CHECK_NOT_NULL(params.array_buffer_allocator);
i_isolate->set_array_buffer_allocator(params.array_buffer_allocator);
if (params.snapshot_blob != nullptr) {
i_isolate->set_snapshot_blob(params.snapshot_blob);
} else {
Expand Down Expand Up @@ -10221,6 +10240,10 @@ void CpuProfiler::SetUsePreciseSampling(bool use_precise_sampling) {
use_precise_sampling);
}

void CpuProfiler::CollectSample() {
reinterpret_cast<i::CpuProfiler*>(this)->CollectSample();
}

void CpuProfiler::StartProfiling(Local<String> title,
CpuProfilingOptions options) {
reinterpret_cast<i::CpuProfiler*>(this)->StartProfiling(
Expand Down Expand Up @@ -10248,6 +10271,12 @@ CpuProfile* CpuProfiler::StopProfiling(Local<String> title) {
*Utils::OpenHandle(*title)));
}

void CpuProfiler::SetIdle(bool is_idle) {
i::CpuProfiler* profiler = reinterpret_cast<i::CpuProfiler*>(this);
i::Isolate* isolate = profiler->isolate();
isolate->SetIdle(is_idle);
}

void CpuProfiler::UseDetailedSourcePositionsForProfiling(Isolate* isolate) {
reinterpret_cast<i::Isolate*>(isolate)
->set_detailed_source_positions_for_profiling(true);
Expand Down Expand Up @@ -10639,15 +10668,6 @@ void EmbedderHeapTracer::DecreaseAllocatedSize(size_t bytes) {
}
}

void EmbedderHeapTracer::RegisterEmbedderReference(
const TracedReferenceBase<v8::Data>& ref) {
if (ref.IsEmpty()) return;

i::Heap* const heap = reinterpret_cast<i::Isolate*>(isolate_)->heap();
heap->RegisterExternallyReferencedObject(
reinterpret_cast<i::Address*>(ref.val_));
}

void EmbedderHeapTracer::RegisterEmbedderReference(
const TracedReferenceBase<v8::Value>& ref) {
if (ref.IsEmpty()) return;
Expand Down
5 changes: 0 additions & 5 deletions deps/v8/src/api/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,6 @@ class Utils {
return CompiledWasmModule{std::move(native_module)};
}

static inline const std::shared_ptr<i::wasm::NativeModule>& Open(
const CompiledWasmModule& compiled_module) {
return compiled_module.native_module_;
}

private:
static void ReportApiFailure(const char* location, const char* message);
};
Expand Down
10 changes: 6 additions & 4 deletions deps/v8/src/d8/d8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3329,7 +3329,7 @@ class Serializer : public ValueSerializer::Delegate {

size_t index = wasm_modules_.size();
wasm_modules_.emplace_back(isolate_, module);
data_->compiled_wasm_modules_.push_back(module->GetCompiledModule());
data_->transferrable_modules_.push_back(module->GetTransferrableModule());
return Just<uint32_t>(static_cast<uint32_t>(index));
}

Expand Down Expand Up @@ -3455,9 +3455,11 @@ class Deserializer : public ValueDeserializer::Delegate {
MaybeLocal<WasmModuleObject> GetWasmModuleFromId(
Isolate* isolate, uint32_t transfer_id) override {
DCHECK_NOT_NULL(data_);
if (transfer_id >= data_->compiled_wasm_modules().size()) return {};
return WasmModuleObject::FromCompiledModule(
isolate_, data_->compiled_wasm_modules().at(transfer_id));
if (transfer_id < data_->transferrable_modules().size()) {
return WasmModuleObject::FromTransferrableModule(
isolate_, data_->transferrable_modules().at(transfer_id));
}
return MaybeLocal<WasmModuleObject>();
}

private:
Expand Down
7 changes: 4 additions & 3 deletions deps/v8/src/d8/d8.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,9 @@ class SerializationData {
const std::vector<std::shared_ptr<v8::BackingStore>>& sab_backing_stores() {
return sab_backing_stores_;
}
const std::vector<CompiledWasmModule>& compiled_wasm_modules() {
return compiled_wasm_modules_;
const std::vector<WasmModuleObject::TransferrableModule>&
transferrable_modules() {
return transferrable_modules_;
}

private:
Expand All @@ -136,7 +137,7 @@ class SerializationData {
size_t size_;
std::vector<std::shared_ptr<v8::BackingStore>> backing_stores_;
std::vector<std::shared_ptr<v8::BackingStore>> sab_backing_stores_;
std::vector<CompiledWasmModule> compiled_wasm_modules_;
std::vector<WasmModuleObject::TransferrableModule> transferrable_modules_;

private:
friend class Serializer;
Expand Down
3 changes: 3 additions & 0 deletions deps/v8/src/flags/flag-definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,9 @@ DEFINE_BOOL(wasm_math_intrinsics, true,
DEFINE_BOOL(wasm_shared_engine, true,
"shares one wasm engine between all isolates within a process")
DEFINE_IMPLICATION(future, wasm_shared_engine)
DEFINE_BOOL(wasm_shared_code, true,
"shares code underlying a wasm module when it is transferred")
DEFINE_IMPLICATION(future, wasm_shared_code)
DEFINE_BOOL(wasm_trap_handler, true,
"use signal handlers to catch out of bounds memory access in wasm"
" (currently Linux x86_64 only)")
Expand Down
Loading

0 comments on commit f17c794

Please sign in to comment.