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

Side by Side Diff: src/api.cc

Issue 2748473004: [wasm] Transferrable modules (Closed)
Patch Set: feedback Created 3 years, 9 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
« no previous file with comments | « include/v8.h ('k') | src/value-serializer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 3111 matching lines...) Expand 10 before | Expand all | Expand 10 after
3122 3122
3123 Maybe<uint32_t> ValueSerializer::Delegate::GetSharedArrayBufferId( 3123 Maybe<uint32_t> ValueSerializer::Delegate::GetSharedArrayBufferId(
3124 Isolate* v8_isolate, Local<SharedArrayBuffer> shared_array_buffer) { 3124 Isolate* v8_isolate, Local<SharedArrayBuffer> shared_array_buffer) {
3125 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); 3125 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
3126 isolate->ScheduleThrow(*isolate->factory()->NewError( 3126 isolate->ScheduleThrow(*isolate->factory()->NewError(
3127 isolate->error_function(), i::MessageTemplate::kDataCloneError, 3127 isolate->error_function(), i::MessageTemplate::kDataCloneError,
3128 Utils::OpenHandle(*shared_array_buffer))); 3128 Utils::OpenHandle(*shared_array_buffer)));
3129 return Nothing<uint32_t>(); 3129 return Nothing<uint32_t>();
3130 } 3130 }
3131 3131
3132 Maybe<uint32_t> ValueSerializer::Delegate::GetWasmModuleTransferId(
3133 Isolate* v8_isolate, Local<WasmCompiledModule> module) {
3134 return Nothing<uint32_t>();
3135 }
3136
3132 void* ValueSerializer::Delegate::ReallocateBufferMemory(void* old_buffer, 3137 void* ValueSerializer::Delegate::ReallocateBufferMemory(void* old_buffer,
3133 size_t size, 3138 size_t size,
3134 size_t* actual_size) { 3139 size_t* actual_size) {
3135 *actual_size = size; 3140 *actual_size = size;
3136 return realloc(old_buffer, size); 3141 return realloc(old_buffer, size);
3137 } 3142 }
3138 3143
3139 void ValueSerializer::Delegate::FreeBufferMemory(void* buffer) { 3144 void ValueSerializer::Delegate::FreeBufferMemory(void* buffer) {
3140 return free(buffer); 3145 return free(buffer);
3141 } 3146 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
3210 3215
3211 MaybeLocal<Object> ValueDeserializer::Delegate::ReadHostObject( 3216 MaybeLocal<Object> ValueDeserializer::Delegate::ReadHostObject(
3212 Isolate* v8_isolate) { 3217 Isolate* v8_isolate) {
3213 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); 3218 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
3214 isolate->ScheduleThrow(*isolate->factory()->NewError( 3219 isolate->ScheduleThrow(*isolate->factory()->NewError(
3215 isolate->error_function(), 3220 isolate->error_function(),
3216 i::MessageTemplate::kDataCloneDeserializationError)); 3221 i::MessageTemplate::kDataCloneDeserializationError));
3217 return MaybeLocal<Object>(); 3222 return MaybeLocal<Object>();
3218 } 3223 }
3219 3224
3225 MaybeLocal<WasmCompiledModule> ValueDeserializer::Delegate::GetWasmModuleFromId(
3226 Isolate* v8_isolate, uint32_t id) {
3227 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
3228 isolate->ScheduleThrow(*isolate->factory()->NewError(
3229 isolate->error_function(),
3230 i::MessageTemplate::kDataCloneDeserializationError));
3231 return MaybeLocal<WasmCompiledModule>();
3232 }
3233
3220 struct ValueDeserializer::PrivateData { 3234 struct ValueDeserializer::PrivateData {
3221 PrivateData(i::Isolate* i, i::Vector<const uint8_t> data, Delegate* delegate) 3235 PrivateData(i::Isolate* i, i::Vector<const uint8_t> data, Delegate* delegate)
3222 : isolate(i), deserializer(i, data, delegate) {} 3236 : isolate(i), deserializer(i, data, delegate) {}
3223 i::Isolate* isolate; 3237 i::Isolate* isolate;
3224 i::ValueDeserializer deserializer; 3238 i::ValueDeserializer deserializer;
3225 bool has_aborted = false; 3239 bool has_aborted = false;
3226 bool supports_legacy_wire_format = false; 3240 bool supports_legacy_wire_format = false;
3227 }; 3241 };
3228 3242
3229 ValueDeserializer::ValueDeserializer(Isolate* isolate, const uint8_t* data, 3243 ValueDeserializer::ValueDeserializer(Isolate* isolate, const uint8_t* data,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
3272 } 3286 }
3273 3287
3274 return Just(true); 3288 return Just(true);
3275 } 3289 }
3276 3290
3277 void ValueDeserializer::SetSupportsLegacyWireFormat( 3291 void ValueDeserializer::SetSupportsLegacyWireFormat(
3278 bool supports_legacy_wire_format) { 3292 bool supports_legacy_wire_format) {
3279 private_->supports_legacy_wire_format = supports_legacy_wire_format; 3293 private_->supports_legacy_wire_format = supports_legacy_wire_format;
3280 } 3294 }
3281 3295
3296 void ValueDeserializer::SetExpectInlineWasm(bool expect_inline_wasm) {
3297 private_->deserializer.set_expect_inline_wasm(expect_inline_wasm);
3298 }
3299
3282 uint32_t ValueDeserializer::GetWireFormatVersion() const { 3300 uint32_t ValueDeserializer::GetWireFormatVersion() const {
3283 CHECK(!private_->has_aborted); 3301 CHECK(!private_->has_aborted);
3284 return private_->deserializer.GetWireFormatVersion(); 3302 return private_->deserializer.GetWireFormatVersion();
3285 } 3303 }
3286 3304
3287 MaybeLocal<Value> ValueDeserializer::ReadValue(Local<Context> context) { 3305 MaybeLocal<Value> ValueDeserializer::ReadValue(Local<Context> context) {
3288 CHECK(!private_->has_aborted); 3306 CHECK(!private_->has_aborted);
3289 PREPARE_FOR_EXECUTION(context, ValueDeserializer, ReadValue, Value); 3307 PREPARE_FOR_EXECUTION(context, ValueDeserializer, ReadValue, Value);
3290 i::MaybeHandle<i::Object> result; 3308 i::MaybeHandle<i::Object> result;
3291 if (GetWireFormatVersion() > 0) { 3309 if (GetWireFormatVersion() > 0) {
(...skipping 4211 matching lines...) Expand 10 before | Expand all | Expand 10 after
7503 7521
7504 Local<String> WasmCompiledModule::GetWasmWireBytes() { 7522 Local<String> WasmCompiledModule::GetWasmWireBytes() {
7505 i::Handle<i::JSObject> obj = 7523 i::Handle<i::JSObject> obj =
7506 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this)); 7524 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this));
7507 i::Handle<i::WasmCompiledModule> compiled_part = 7525 i::Handle<i::WasmCompiledModule> compiled_part =
7508 i::handle(i::WasmCompiledModule::cast(obj->GetEmbedderField(0))); 7526 i::handle(i::WasmCompiledModule::cast(obj->GetEmbedderField(0)));
7509 i::Handle<i::String> wire_bytes(compiled_part->module_bytes()); 7527 i::Handle<i::String> wire_bytes(compiled_part->module_bytes());
7510 return Local<String>::Cast(Utils::ToLocal(wire_bytes)); 7528 return Local<String>::Cast(Utils::ToLocal(wire_bytes));
7511 } 7529 }
7512 7530
7531 // Currently, wasm modules are bound, both to Isolate and to
7532 // the Context they were created in. The currently-supported means to
7533 // decontextualize and then re-contextualize a module is via
7534 // serialization/deserialization.
7535 WasmCompiledModule::TransferrableModule
7536 WasmCompiledModule::GetTransferrableModule() {
7537 i::DisallowHeapAllocation no_gc;
7538 WasmCompiledModule::SerializedModule compiled_part = Serialize();
7539
7540 Local<String> wire_bytes = GetWasmWireBytes();
7541 size_t wire_size = static_cast<size_t>(wire_bytes->Length());
7542 uint8_t* bytes = new uint8_t[wire_size];
7543 wire_bytes->WriteOneByte(bytes, 0, wire_bytes->Length());
7544
7545 return TransferrableModule(
7546 std::move(compiled_part),
7547 std::make_pair(
7548 std::unique_ptr<const uint8_t[]>(const_cast<const uint8_t*>(bytes)),
7549 wire_size));
7550 }
7551
7552 MaybeLocal<WasmCompiledModule> WasmCompiledModule::FromTransferrableModule(
7553 Isolate* isolate,
7554 const WasmCompiledModule::TransferrableModule& transferrable_module) {
7555 MaybeLocal<WasmCompiledModule> ret =
7556 Deserialize(isolate, AsCallerOwned(transferrable_module.compiled_code),
7557 AsCallerOwned(transferrable_module.wire_bytes));
7558 return ret;
7559 }
7560
7513 WasmCompiledModule::SerializedModule WasmCompiledModule::Serialize() { 7561 WasmCompiledModule::SerializedModule WasmCompiledModule::Serialize() {
7514 i::Handle<i::JSObject> obj = 7562 i::Handle<i::JSObject> obj =
7515 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this)); 7563 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this));
7516 i::Handle<i::WasmCompiledModule> compiled_part = 7564 i::Handle<i::WasmCompiledModule> compiled_part =
7517 i::handle(i::WasmCompiledModule::cast(obj->GetEmbedderField(0))); 7565 i::handle(i::WasmCompiledModule::cast(obj->GetEmbedderField(0)));
7518 7566
7519 std::unique_ptr<i::ScriptData> script_data = 7567 std::unique_ptr<i::ScriptData> script_data =
7520 i::WasmCompiledModuleSerializer::SerializeWasmModule(obj->GetIsolate(), 7568 i::WasmCompiledModuleSerializer::SerializeWasmModule(obj->GetIsolate(),
7521 compiled_part); 7569 compiled_part);
7522 script_data->ReleaseDataOwnership(); 7570 script_data->ReleaseDataOwnership();
(...skipping 2723 matching lines...) Expand 10 before | Expand all | Expand 10 after
10246 Address callback_address = 10294 Address callback_address =
10247 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 10295 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
10248 VMState<EXTERNAL> state(isolate); 10296 VMState<EXTERNAL> state(isolate);
10249 ExternalCallbackScope call_scope(isolate, callback_address); 10297 ExternalCallbackScope call_scope(isolate, callback_address);
10250 callback(info); 10298 callback(info);
10251 } 10299 }
10252 10300
10253 10301
10254 } // namespace internal 10302 } // namespace internal
10255 } // namespace v8 10303 } // namespace v8
OLDNEW
« no previous file with comments | « include/v8.h ('k') | src/value-serializer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698