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

Side by Side Diff: src/api.cc

Issue 2748473004: [wasm] Transferrable modules (Closed)
Patch Set: Transferrable modules 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 3125 matching lines...) Expand 10 before | Expand all | Expand 10 after
3136 3136
3137 Maybe<uint32_t> ValueSerializer::Delegate::GetSharedArrayBufferId( 3137 Maybe<uint32_t> ValueSerializer::Delegate::GetSharedArrayBufferId(
3138 Isolate* v8_isolate, Local<SharedArrayBuffer> shared_array_buffer) { 3138 Isolate* v8_isolate, Local<SharedArrayBuffer> shared_array_buffer) {
3139 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); 3139 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
3140 isolate->ScheduleThrow(*isolate->factory()->NewError( 3140 isolate->ScheduleThrow(*isolate->factory()->NewError(
3141 isolate->error_function(), i::MessageTemplate::kDataCloneError, 3141 isolate->error_function(), i::MessageTemplate::kDataCloneError,
3142 Utils::OpenHandle(*shared_array_buffer))); 3142 Utils::OpenHandle(*shared_array_buffer)));
3143 return Nothing<uint32_t>(); 3143 return Nothing<uint32_t>();
3144 } 3144 }
3145 3145
3146 Maybe<uint32_t> ValueSerializer::Delegate::GetWasmModuleTransferId(
3147 Isolate* v8_isolate, Local<WasmCompiledModule> module) {
3148 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
3149 isolate->ScheduleThrow(*isolate->factory()->NewError(
3150 isolate->error_function(), i::MessageTemplate::kDataCloneError,
3151 Utils::OpenHandle(*module)));
3152 return Nothing<uint32_t>();
3153 }
3154
3146 void* ValueSerializer::Delegate::ReallocateBufferMemory(void* old_buffer, 3155 void* ValueSerializer::Delegate::ReallocateBufferMemory(void* old_buffer,
3147 size_t size, 3156 size_t size,
3148 size_t* actual_size) { 3157 size_t* actual_size) {
3149 *actual_size = size; 3158 *actual_size = size;
3150 return realloc(old_buffer, size); 3159 return realloc(old_buffer, size);
3151 } 3160 }
3152 3161
3153 void ValueSerializer::Delegate::FreeBufferMemory(void* buffer) { 3162 void ValueSerializer::Delegate::FreeBufferMemory(void* buffer) {
3154 return free(buffer); 3163 return free(buffer);
3155 } 3164 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
3224 3233
3225 MaybeLocal<Object> ValueDeserializer::Delegate::ReadHostObject( 3234 MaybeLocal<Object> ValueDeserializer::Delegate::ReadHostObject(
3226 Isolate* v8_isolate) { 3235 Isolate* v8_isolate) {
3227 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); 3236 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
3228 isolate->ScheduleThrow(*isolate->factory()->NewError( 3237 isolate->ScheduleThrow(*isolate->factory()->NewError(
3229 isolate->error_function(), 3238 isolate->error_function(),
3230 i::MessageTemplate::kDataCloneDeserializationError)); 3239 i::MessageTemplate::kDataCloneDeserializationError));
3231 return MaybeLocal<Object>(); 3240 return MaybeLocal<Object>();
3232 } 3241 }
3233 3242
3243 MaybeLocal<WasmCompiledModule> ValueDeserializer::Delegate::GetWasmModuleFromId(
3244 Isolate* v8_isolate, uint32_t id) {
3245 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
3246 isolate->ScheduleThrow(*isolate->factory()->NewError(
3247 isolate->error_function(),
3248 i::MessageTemplate::kDataCloneDeserializationError));
3249 return MaybeLocal<WasmCompiledModule>();
3250 }
3251
3234 struct ValueDeserializer::PrivateData { 3252 struct ValueDeserializer::PrivateData {
3235 PrivateData(i::Isolate* i, i::Vector<const uint8_t> data, Delegate* delegate) 3253 PrivateData(i::Isolate* i, i::Vector<const uint8_t> data, Delegate* delegate)
3236 : isolate(i), deserializer(i, data, delegate) {} 3254 : isolate(i), deserializer(i, data, delegate) {}
3237 i::Isolate* isolate; 3255 i::Isolate* isolate;
3238 i::ValueDeserializer deserializer; 3256 i::ValueDeserializer deserializer;
3239 bool has_aborted = false; 3257 bool has_aborted = false;
3240 bool supports_legacy_wire_format = false; 3258 bool supports_legacy_wire_format = false;
3241 }; 3259 };
3242 3260
3243 ValueDeserializer::ValueDeserializer(Isolate* isolate, const uint8_t* data, 3261 ValueDeserializer::ValueDeserializer(Isolate* isolate, const uint8_t* data,
(...skipping 4268 matching lines...) Expand 10 before | Expand all | Expand 10 after
7512 7530
7513 Local<String> WasmCompiledModule::GetWasmWireBytes() { 7531 Local<String> WasmCompiledModule::GetWasmWireBytes() {
7514 i::Handle<i::JSObject> obj = 7532 i::Handle<i::JSObject> obj =
7515 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this)); 7533 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this));
7516 i::Handle<i::WasmCompiledModule> compiled_part = 7534 i::Handle<i::WasmCompiledModule> compiled_part =
7517 i::handle(i::WasmCompiledModule::cast(obj->GetInternalField(0))); 7535 i::handle(i::WasmCompiledModule::cast(obj->GetInternalField(0)));
7518 i::Handle<i::String> wire_bytes(compiled_part->module_bytes()); 7536 i::Handle<i::String> wire_bytes(compiled_part->module_bytes());
7519 return Local<String>::Cast(Utils::ToLocal(wire_bytes)); 7537 return Local<String>::Cast(Utils::ToLocal(wire_bytes));
7520 } 7538 }
7521 7539
7540 // Currently, wasm modules are bound, both to Isolate and to
7541 // the Context they were created in. The currently-supported means to
7542 // decontextualize and then re-contextualize a module is via
7543 // serialization/deserialization.
7544 WasmCompiledModule::TransferrableModule
7545 WasmCompiledModule::AsTransferrableModule() {
7546 i::DisallowHeapAllocation no_gc;
7547 WasmCompiledModule::SerializedModule compiled_part = Serialize();
7548
7549 Local<String> wire_bytes = GetWasmWireBytes();
7550 size_t wire_size = static_cast<size_t>(wire_bytes->Length());
7551 uint8_t* bytes = new uint8_t[wire_size];
7552 wire_bytes->WriteOneByte(bytes, 0, wire_bytes->Length());
7553
7554 return TransferrableModule(
7555 std::move(compiled_part),
7556 std::make_pair(
7557 std::unique_ptr<const uint8_t[]>(const_cast<const uint8_t*>(bytes)),
7558 wire_size));
7559 }
7560
7561 MaybeLocal<WasmCompiledModule> WasmCompiledModule::FromTransferrableModule(
7562 Isolate* isolate,
7563 WasmCompiledModule::TransferrableModule& transferrable_module) {
7564 MaybeLocal<WasmCompiledModule> ret =
7565 Deserialize(isolate, AsCallerOwned(transferrable_module.compiled_code),
7566 AsCallerOwned(transferrable_module.wire_bytes));
7567 return ret;
7568 }
7569
7522 WasmCompiledModule::SerializedModule WasmCompiledModule::Serialize() { 7570 WasmCompiledModule::SerializedModule WasmCompiledModule::Serialize() {
7523 i::Handle<i::JSObject> obj = 7571 i::Handle<i::JSObject> obj =
7524 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this)); 7572 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this));
7525 i::Handle<i::WasmCompiledModule> compiled_part = 7573 i::Handle<i::WasmCompiledModule> compiled_part =
7526 i::handle(i::WasmCompiledModule::cast(obj->GetInternalField(0))); 7574 i::handle(i::WasmCompiledModule::cast(obj->GetInternalField(0)));
7527 7575
7528 std::unique_ptr<i::ScriptData> script_data = 7576 std::unique_ptr<i::ScriptData> script_data =
7529 i::WasmCompiledModuleSerializer::SerializeWasmModule(obj->GetIsolate(), 7577 i::WasmCompiledModuleSerializer::SerializeWasmModule(obj->GetIsolate(),
7530 compiled_part); 7578 compiled_part);
7531 script_data->ReleaseDataOwnership(); 7579 script_data->ReleaseDataOwnership();
(...skipping 2711 matching lines...) Expand 10 before | Expand all | Expand 10 after
10243 Address callback_address = 10291 Address callback_address =
10244 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 10292 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
10245 VMState<EXTERNAL> state(isolate); 10293 VMState<EXTERNAL> state(isolate);
10246 ExternalCallbackScope call_scope(isolate, callback_address); 10294 ExternalCallbackScope call_scope(isolate, callback_address);
10247 callback(info); 10295 callback(info);
10248 } 10296 }
10249 10297
10250 10298
10251 } // namespace internal 10299 } // namespace internal
10252 } // namespace v8 10300 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698