Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(526)

Side by Side Diff: src/api.cc

Issue 2433273002: [wasm] Avoid double-serializing the wire bytes (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/api.h" 5 #include "src/api.h"
6 6
7 #include <string.h> // For memcpy, strlen. 7 #include <string.h> // For memcpy, strlen.
8 #ifdef V8_USE_ADDRESS_SANITIZER 8 #ifdef V8_USE_ADDRESS_SANITIZER
9 #include <sanitizer/asan_interface.h> 9 #include <sanitizer/asan_interface.h>
10 #endif // V8_USE_ADDRESS_SANITIZER 10 #endif // V8_USE_ADDRESS_SANITIZER
(...skipping 7197 matching lines...) Expand 10 before | Expand all | Expand 10 after
7208 i::WasmCompiledModuleSerializer::SerializeWasmModule(obj->GetIsolate(), 7208 i::WasmCompiledModuleSerializer::SerializeWasmModule(obj->GetIsolate(),
7209 compiled_part); 7209 compiled_part);
7210 script_data->ReleaseDataOwnership(); 7210 script_data->ReleaseDataOwnership();
7211 7211
7212 size_t size = static_cast<size_t>(script_data->length()); 7212 size_t size = static_cast<size_t>(script_data->length());
7213 return {std::unique_ptr<const uint8_t[]>(script_data->data()), size}; 7213 return {std::unique_ptr<const uint8_t[]>(script_data->data()), size};
7214 } 7214 }
7215 7215
7216 MaybeLocal<WasmCompiledModule> WasmCompiledModule::Deserialize( 7216 MaybeLocal<WasmCompiledModule> WasmCompiledModule::Deserialize(
7217 Isolate* isolate, 7217 Isolate* isolate,
7218 const WasmCompiledModule::SerializedModule& serialized_module) { 7218 const WasmCompiledModule::CallerOwnedBuffer& serialized_module,
7219 return Deserialize(isolate, 7219 const WasmCompiledModule::CallerOwnedBuffer& wire_bytes) {
7220 {serialized_module.first.get(), serialized_module.second});
7221 }
7222
7223 MaybeLocal<WasmCompiledModule> WasmCompiledModule::Deserialize(
7224 Isolate* isolate,
7225 const WasmCompiledModule::CallerOwnedBuffer& serialized_module) {
7226 int size = static_cast<int>(serialized_module.second); 7220 int size = static_cast<int>(serialized_module.second);
7227 i::ScriptData sc(serialized_module.first, size); 7221 i::ScriptData sc(serialized_module.first, size);
7228 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 7222 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
7229 i::MaybeHandle<i::FixedArray> maybe_compiled_part = 7223 i::MaybeHandle<i::FixedArray> maybe_compiled_part =
7230 i::WasmCompiledModuleSerializer::DeserializeWasmModule(i_isolate, &sc); 7224 i::WasmCompiledModuleSerializer::DeserializeWasmModule(
7225 i_isolate, &sc,
7226 {wire_bytes.first, static_cast<int>(wire_bytes.second)});
7231 i::Handle<i::FixedArray> compiled_part; 7227 i::Handle<i::FixedArray> compiled_part;
7232 if (!maybe_compiled_part.ToHandle(&compiled_part)) { 7228 if (!maybe_compiled_part.ToHandle(&compiled_part)) {
7233 return MaybeLocal<WasmCompiledModule>(); 7229 return MaybeLocal<WasmCompiledModule>();
7234 } 7230 }
7235 i::Handle<i::wasm::WasmCompiledModule> compiled_module = 7231 i::Handle<i::wasm::WasmCompiledModule> compiled_module =
7236 handle(i::wasm::WasmCompiledModule::cast(*compiled_part)); 7232 handle(i::wasm::WasmCompiledModule::cast(*compiled_part));
7237 return Local<WasmCompiledModule>::Cast( 7233 return Local<WasmCompiledModule>::Cast(
7238 Utils::ToLocal(i::wasm::CreateWasmModuleObject( 7234 Utils::ToLocal(i::wasm::CreateWasmModuleObject(
7239 i_isolate, compiled_module, i::wasm::ModuleOrigin::kWasmOrigin))); 7235 i_isolate, compiled_module, i::wasm::ModuleOrigin::kWasmOrigin)));
7240 } 7236 }
7241 7237
7242 MaybeLocal<WasmCompiledModule> WasmCompiledModule::DeserializeOrCompile( 7238 MaybeLocal<WasmCompiledModule> WasmCompiledModule::DeserializeOrCompile(
7243 Isolate* isolate, 7239 Isolate* isolate,
7244 const WasmCompiledModule::CallerOwnedBuffer& serialized_module, 7240 const WasmCompiledModule::CallerOwnedBuffer& serialized_module,
7245 const WasmCompiledModule::CallerOwnedBuffer& wire_bytes) { 7241 const WasmCompiledModule::CallerOwnedBuffer& wire_bytes) {
7246 MaybeLocal<WasmCompiledModule> ret = Deserialize(isolate, serialized_module); 7242 MaybeLocal<WasmCompiledModule> ret =
7243 Deserialize(isolate, serialized_module, wire_bytes);
7247 if (!ret.IsEmpty()) { 7244 if (!ret.IsEmpty()) {
7248 // TODO(mtrofin): once we stop taking a dependency on Deserialize,
7249 // clean this up to avoid the back and forth between internal
7250 // and external representations.
7251 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
7252 i::Vector<const uint8_t> str(wire_bytes.first,
7253 static_cast<int>(wire_bytes.second));
7254 i::Handle<i::SeqOneByteString> wire_bytes_as_string(
7255 i::SeqOneByteString::cast(
7256 *i_isolate->factory()->NewStringFromOneByte(str).ToHandleChecked()),
7257 i_isolate);
7258
7259 i::Handle<i::JSObject> obj =
7260 i::Handle<i::JSObject>::cast(Utils::OpenHandle(*ret.ToLocalChecked()));
7261 i::Handle<i::wasm::WasmCompiledModule> compiled_part =
7262 i::handle(i::wasm::WasmCompiledModule::cast(obj->GetInternalField(0)));
7263 compiled_part->set_module_bytes(wire_bytes_as_string);
7264 return ret; 7245 return ret;
7265 } 7246 }
7266 return Compile(isolate, wire_bytes.first, wire_bytes.second); 7247 return Compile(isolate, wire_bytes.first, wire_bytes.second);
7267 } 7248 }
7268 7249
7269 MaybeLocal<WasmCompiledModule> WasmCompiledModule::Compile(Isolate* isolate, 7250 MaybeLocal<WasmCompiledModule> WasmCompiledModule::Compile(Isolate* isolate,
7270 const uint8_t* start, 7251 const uint8_t* start,
7271 size_t length) { 7252 size_t length) {
7272 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 7253 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
7273 i::wasm::ErrorThrower thrower(i_isolate, "WasmCompiledModule::Deserialize()"); 7254 i::wasm::ErrorThrower thrower(i_isolate, "WasmCompiledModule::Deserialize()");
(...skipping 2218 matching lines...) Expand 10 before | Expand all | Expand 10 after
9492 Address callback_address = 9473 Address callback_address =
9493 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 9474 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
9494 VMState<EXTERNAL> state(isolate); 9475 VMState<EXTERNAL> state(isolate);
9495 ExternalCallbackScope call_scope(isolate, callback_address); 9476 ExternalCallbackScope call_scope(isolate, callback_address);
9496 callback(info); 9477 callback(info);
9497 } 9478 }
9498 9479
9499 9480
9500 } // namespace internal 9481 } // namespace internal
9501 } // namespace v8 9482 } // namespace v8
OLDNEW
« no previous file with comments | « include/v8.h ('k') | src/runtime/runtime.h » ('j') | src/runtime/runtime-test.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698