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

Side by Side Diff: src/api.cc

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

Powered by Google App Engine
This is Rietveld 408576698