Commit fc479d51 authored by Bill Budge's avatar Bill Budge Committed by Commit Bot

[api] Change Wasm ModuleCompiled notification

- Removes ModuleCompiledCallback typedef and Set function.
- Adds WasmStreaming::Client abstraction and Set function.

Bug: chromium:719172
Change-Id: I8a207b628394a7660bda73cde560da1e461248a7
Reviewed-on: https://chromium-review.googlesource.com/c/1377450Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Commit-Queue: Bill Budge <bbudge@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58454}
parent 644b26e6
...@@ -4453,6 +4453,19 @@ class V8_EXPORT WasmStreaming final { ...@@ -4453,6 +4453,19 @@ class V8_EXPORT WasmStreaming final {
public: public:
class WasmStreamingImpl; class WasmStreamingImpl;
/**
* Client to receive streaming event notifications.
*/
class Client {
public:
virtual ~Client() = default;
/**
* Passes the fully compiled module to the client. This can be used to
* implement code caching.
*/
virtual void OnModuleCompiled(CompiledWasmModule compiled_module) = 0;
};
explicit WasmStreaming(std::unique_ptr<WasmStreamingImpl> impl); explicit WasmStreaming(std::unique_ptr<WasmStreamingImpl> impl);
~WasmStreaming(); ~WasmStreaming();
...@@ -4478,28 +4491,20 @@ class V8_EXPORT WasmStreaming final { ...@@ -4478,28 +4491,20 @@ class V8_EXPORT WasmStreaming final {
void Abort(MaybeLocal<Value> exception); void Abort(MaybeLocal<Value> exception);
/** /**
* Callback for module compiled notifications. |data| is the identifier * Passes previously compiled module bytes. This must be called before
* passed to {SetModuleCompiledCallback}, |compiled_module| is the result. * {OnBytesReceived}, {Finish}, or {Abort}. Returns true if the module bytes
*/ * can be used, false otherwise. The buffer passed via {bytes} and {size}
typedef void (*ModuleCompiledCallback)(intptr_t data,
CompiledWasmModule compiled_module);
/**
* Sets a callback for when compilation of the Wasm module has been completed
* to the highest tier. |data| will be passed as the first callback parameter.
*/
void SetModuleCompiledCallback(ModuleCompiledCallback callback,
intptr_t data);
/**
* Passes previously compiled module bytes. This must be called before calling
* any non-static methods of this class. Returns true if the module bytes can
* be used, false otherwise. The buffer passed into {SetCompiledModuleBytes}
* is owned by the caller. If {SetCompiledModuleBytes} returns true, the * is owned by the caller. If {SetCompiledModuleBytes} returns true, the
* buffer must remain valid until either {Finish} or {Abort} completes. * buffer must remain valid until either {Finish} or {Abort} completes.
*/ */
bool SetCompiledModuleBytes(const uint8_t* bytes, size_t size); bool SetCompiledModuleBytes(const uint8_t* bytes, size_t size);
/**
* Sets the client object that will receive streaming event notifications.
* This must be called before {OnBytesReceived}, {Finish}, or {Abort}.
*/
void SetClient(std::shared_ptr<Client> client);
/** /**
* Unpacks a {WasmStreaming} object wrapped in a {Managed} for the embedder. * Unpacks a {WasmStreaming} object wrapped in a {Managed} for the embedder.
* Since the embedder is on the other side of the API, it cannot unpack the * Since the embedder is on the other side of the API, it cannot unpack the
......
...@@ -157,8 +157,7 @@ void StreamingDecoder::NotifyRuntimeObjectsCreated( ...@@ -157,8 +157,7 @@ void StreamingDecoder::NotifyRuntimeObjectsCreated(
auto* comp_state = module_object->native_module()->compilation_state(); auto* comp_state = module_object->native_module()->compilation_state();
comp_state->AddCallback(TopTierCompiledCallback{ comp_state->AddCallback(TopTierCompiledCallback{
std::move(native_module), std::move(module_compiled_callback_)}); std::move(native_module), std::move(module_compiled_callback_)});
// The callback took ownership of the callback: module_compiled_callback_ = {};
DCHECK_NULL(module_compiled_callback_);
} }
// An abstract class to share code among the states which decode VarInts. This // An abstract class to share code among the states which decode VarInts. This
......
...@@ -59,22 +59,20 @@ class WasmStreaming::WasmStreamingImpl { ...@@ -59,22 +59,20 @@ class WasmStreaming::WasmStreamingImpl {
Utils::OpenHandle(*exception.ToLocalChecked())); Utils::OpenHandle(*exception.ToLocalChecked()));
} }
void SetModuleCompiledCallback(ModuleCompiledCallback callback,
intptr_t data) {
// Wrap the embedder callback here so we can also wrap the result as a
// Local<WasmModuleObject> here.
streaming_decoder_->SetModuleCompiledCallback(
[callback,
data](const std::shared_ptr<i::wasm::NativeModule>& native_module) {
callback(data, Utils::Convert(native_module));
});
}
bool SetCompiledModuleBytes(const uint8_t* bytes, size_t size) { bool SetCompiledModuleBytes(const uint8_t* bytes, size_t size) {
if (!i::wasm::IsSupportedVersion({bytes, size})) return false; if (!i::wasm::IsSupportedVersion({bytes, size})) return false;
return streaming_decoder_->SetCompiledModuleBytes({bytes, size}); return streaming_decoder_->SetCompiledModuleBytes({bytes, size});
} }
void SetClient(std::shared_ptr<Client> client) {
// There are no other event notifications so just pass client to decoder.
// Wrap the client with a callback here so we can also wrap the result.
streaming_decoder_->SetModuleCompiledCallback(
[client](const std::shared_ptr<i::wasm::NativeModule>& native_module) {
client->OnModuleCompiled(Utils::Convert(native_module));
});
}
private: private:
Isolate* isolate_ = nullptr; Isolate* isolate_ = nullptr;
std::shared_ptr<internal::wasm::StreamingDecoder> streaming_decoder_; std::shared_ptr<internal::wasm::StreamingDecoder> streaming_decoder_;
...@@ -98,15 +96,14 @@ void WasmStreaming::Abort(MaybeLocal<Value> exception) { ...@@ -98,15 +96,14 @@ void WasmStreaming::Abort(MaybeLocal<Value> exception) {
impl_->Abort(exception); impl_->Abort(exception);
} }
void WasmStreaming::SetModuleCompiledCallback(ModuleCompiledCallback callback,
intptr_t data) {
impl_->SetModuleCompiledCallback(callback, data);
}
bool WasmStreaming::SetCompiledModuleBytes(const uint8_t* bytes, size_t size) { bool WasmStreaming::SetCompiledModuleBytes(const uint8_t* bytes, size_t size) {
return impl_->SetCompiledModuleBytes(bytes, size); return impl_->SetCompiledModuleBytes(bytes, size);
} }
void WasmStreaming::SetClient(std::shared_ptr<Client> client) {
impl_->SetClient(client);
}
// static // static
std::shared_ptr<WasmStreaming> WasmStreaming::Unpack(Isolate* isolate, std::shared_ptr<WasmStreaming> WasmStreaming::Unpack(Isolate* isolate,
Local<Value> value) { Local<Value> value) {
......
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