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

Side by Side Diff: src/api.cc

Issue 2433273002: [wasm] Avoid double-serializing the wire bytes (Closed)
Patch Set: externalize/internalize buffer 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 1065 matching lines...) Expand 10 before | Expand all | Expand 10 after
1076 } 1076 }
1077 1077
1078 1078
1079 void Template::Set(v8::Local<Name> name, v8::Local<Data> value, 1079 void Template::Set(v8::Local<Name> name, v8::Local<Data> value,
1080 v8::PropertyAttribute attribute) { 1080 v8::PropertyAttribute attribute) {
1081 auto templ = Utils::OpenHandle(this); 1081 auto templ = Utils::OpenHandle(this);
1082 i::Isolate* isolate = templ->GetIsolate(); 1082 i::Isolate* isolate = templ->GetIsolate();
1083 ENTER_V8(isolate); 1083 ENTER_V8(isolate);
1084 i::HandleScope scope(isolate); 1084 i::HandleScope scope(isolate);
1085 auto value_obj = Utils::OpenHandle(*value); 1085 auto value_obj = Utils::OpenHandle(*value);
1086 CHECK(!value_obj->IsJSReceiver() || value_obj->IsTemplateInfo()); 1086 CHECK(!value_obj->IsJSReceiver() || value_obj->IsTemplateInfo() ||
1087 value_obj->IsExternal());
1087 if (value_obj->IsObjectTemplateInfo()) { 1088 if (value_obj->IsObjectTemplateInfo()) {
1088 templ->set_serial_number(i::Smi::kZero); 1089 templ->set_serial_number(i::Smi::kZero);
1089 if (templ->IsFunctionTemplateInfo()) { 1090 if (templ->IsFunctionTemplateInfo()) {
1090 i::Handle<i::FunctionTemplateInfo>::cast(templ)->set_do_not_cache(true); 1091 i::Handle<i::FunctionTemplateInfo>::cast(templ)->set_do_not_cache(true);
1091 } 1092 }
1092 } 1093 }
1093 i::ApiNatives::AddDataProperty(isolate, templ, Utils::OpenHandle(*name), 1094 i::ApiNatives::AddDataProperty(isolate, templ, Utils::OpenHandle(*name),
1094 value_obj, 1095 value_obj,
1095 static_cast<i::PropertyAttributes>(attribute)); 1096 static_cast<i::PropertyAttributes>(attribute));
1096 } 1097 }
(...skipping 6121 matching lines...) Expand 10 before | Expand all | Expand 10 after
7218 i::WasmCompiledModuleSerializer::SerializeWasmModule(obj->GetIsolate(), 7219 i::WasmCompiledModuleSerializer::SerializeWasmModule(obj->GetIsolate(),
7219 compiled_part); 7220 compiled_part);
7220 script_data->ReleaseDataOwnership(); 7221 script_data->ReleaseDataOwnership();
7221 7222
7222 size_t size = static_cast<size_t>(script_data->length()); 7223 size_t size = static_cast<size_t>(script_data->length());
7223 return {std::unique_ptr<const uint8_t[]>(script_data->data()), size}; 7224 return {std::unique_ptr<const uint8_t[]>(script_data->data()), size};
7224 } 7225 }
7225 7226
7226 MaybeLocal<WasmCompiledModule> WasmCompiledModule::Deserialize( 7227 MaybeLocal<WasmCompiledModule> WasmCompiledModule::Deserialize(
7227 Isolate* isolate, 7228 Isolate* isolate,
7228 const WasmCompiledModule::CallerOwnedBuffer& serialized_module) { 7229 const WasmCompiledModule::CallerOwnedBuffer& serialized_module,
7230 const WasmCompiledModule::CallerOwnedBuffer& wire_bytes) {
7229 int size = static_cast<int>(serialized_module.second); 7231 int size = static_cast<int>(serialized_module.second);
7230 i::ScriptData sc(serialized_module.first, size); 7232 i::ScriptData sc(serialized_module.first, size);
7231 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 7233 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
7232 i::MaybeHandle<i::FixedArray> maybe_compiled_part = 7234 i::MaybeHandle<i::FixedArray> maybe_compiled_part =
7233 i::WasmCompiledModuleSerializer::DeserializeWasmModule(i_isolate, &sc); 7235 i::WasmCompiledModuleSerializer::DeserializeWasmModule(
7236 i_isolate, &sc,
7237 {wire_bytes.first, static_cast<int>(wire_bytes.second)});
7234 i::Handle<i::FixedArray> compiled_part; 7238 i::Handle<i::FixedArray> compiled_part;
7235 if (!maybe_compiled_part.ToHandle(&compiled_part)) { 7239 if (!maybe_compiled_part.ToHandle(&compiled_part)) {
7236 return MaybeLocal<WasmCompiledModule>(); 7240 return MaybeLocal<WasmCompiledModule>();
7237 } 7241 }
7238 i::Handle<i::wasm::WasmCompiledModule> compiled_module = 7242 i::Handle<i::wasm::WasmCompiledModule> compiled_module =
7239 handle(i::wasm::WasmCompiledModule::cast(*compiled_part)); 7243 handle(i::wasm::WasmCompiledModule::cast(*compiled_part));
7240 return Local<WasmCompiledModule>::Cast( 7244 return Local<WasmCompiledModule>::Cast(
7241 Utils::ToLocal(i::wasm::CreateWasmModuleObject( 7245 Utils::ToLocal(i::wasm::CreateWasmModuleObject(
7242 i_isolate, compiled_module, i::wasm::ModuleOrigin::kWasmOrigin))); 7246 i_isolate, compiled_module, i::wasm::ModuleOrigin::kWasmOrigin)));
7243 } 7247 }
7244 7248
7245 MaybeLocal<WasmCompiledModule> WasmCompiledModule::DeserializeOrCompile( 7249 MaybeLocal<WasmCompiledModule> WasmCompiledModule::DeserializeOrCompile(
7246 Isolate* isolate, 7250 Isolate* isolate,
7247 const WasmCompiledModule::CallerOwnedBuffer& serialized_module, 7251 const WasmCompiledModule::CallerOwnedBuffer& serialized_module,
7248 const WasmCompiledModule::CallerOwnedBuffer& wire_bytes) { 7252 const WasmCompiledModule::CallerOwnedBuffer& wire_bytes) {
7249 MaybeLocal<WasmCompiledModule> ret = Deserialize(isolate, serialized_module); 7253 MaybeLocal<WasmCompiledModule> ret =
7254 Deserialize(isolate, serialized_module, wire_bytes);
7250 if (!ret.IsEmpty()) { 7255 if (!ret.IsEmpty()) {
7251 // TODO(mtrofin): once we stop taking a dependency on Deserialize,
7252 // clean this up to avoid the back and forth between internal
7253 // and external representations.
7254 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
7255 i::Vector<const uint8_t> str(wire_bytes.first,
7256 static_cast<int>(wire_bytes.second));
7257 i::Handle<i::SeqOneByteString> wire_bytes_as_string(
7258 i::SeqOneByteString::cast(
7259 *i_isolate->factory()->NewStringFromOneByte(str).ToHandleChecked()),
7260 i_isolate);
7261
7262 i::Handle<i::JSObject> obj =
7263 i::Handle<i::JSObject>::cast(Utils::OpenHandle(*ret.ToLocalChecked()));
7264 i::Handle<i::wasm::WasmCompiledModule> compiled_part =
7265 i::handle(i::wasm::WasmCompiledModule::cast(obj->GetInternalField(0)));
7266 compiled_part->set_module_bytes(wire_bytes_as_string);
7267 return ret; 7256 return ret;
7268 } 7257 }
7269 return Compile(isolate, wire_bytes.first, wire_bytes.second); 7258 return Compile(isolate, wire_bytes.first, wire_bytes.second);
7270 } 7259 }
7271 7260
7272 MaybeLocal<WasmCompiledModule> WasmCompiledModule::Compile(Isolate* isolate, 7261 MaybeLocal<WasmCompiledModule> WasmCompiledModule::Compile(Isolate* isolate,
7273 const uint8_t* start, 7262 const uint8_t* start,
7274 size_t length) { 7263 size_t length) {
7275 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 7264 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
7276 i::wasm::ErrorThrower thrower(i_isolate, "WasmCompiledModule::Deserialize()"); 7265 i::wasm::ErrorThrower thrower(i_isolate, "WasmCompiledModule::Deserialize()");
(...skipping 2218 matching lines...) Expand 10 before | Expand all | Expand 10 after
9495 Address callback_address = 9484 Address callback_address =
9496 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 9485 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
9497 VMState<EXTERNAL> state(isolate); 9486 VMState<EXTERNAL> state(isolate);
9498 ExternalCallbackScope call_scope(isolate, callback_address); 9487 ExternalCallbackScope call_scope(isolate, callback_address);
9499 callback(info); 9488 callback(info);
9500 } 9489 }
9501 9490
9502 9491
9503 } // namespace internal 9492 } // namespace internal
9504 } // namespace v8 9493 } // namespace v8
OLDNEW
« no previous file with comments | « include/v8.h ('k') | src/assembler.h » ('j') | src/runtime/runtime-test.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698