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

Side by Side Diff: src/api.cc

Issue 2762163002: Revert of [wasm] Transferrable modules (Closed)
Patch Set: 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
3137 void* ValueSerializer::Delegate::ReallocateBufferMemory(void* old_buffer, 3132 void* ValueSerializer::Delegate::ReallocateBufferMemory(void* old_buffer,
3138 size_t size, 3133 size_t size,
3139 size_t* actual_size) { 3134 size_t* actual_size) {
3140 *actual_size = size; 3135 *actual_size = size;
3141 return realloc(old_buffer, size); 3136 return realloc(old_buffer, size);
3142 } 3137 }
3143 3138
3144 void ValueSerializer::Delegate::FreeBufferMemory(void* buffer) { 3139 void ValueSerializer::Delegate::FreeBufferMemory(void* buffer) {
3145 return free(buffer); 3140 return free(buffer);
3146 } 3141 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
3215 3210
3216 MaybeLocal<Object> ValueDeserializer::Delegate::ReadHostObject( 3211 MaybeLocal<Object> ValueDeserializer::Delegate::ReadHostObject(
3217 Isolate* v8_isolate) { 3212 Isolate* v8_isolate) {
3218 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); 3213 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
3219 isolate->ScheduleThrow(*isolate->factory()->NewError( 3214 isolate->ScheduleThrow(*isolate->factory()->NewError(
3220 isolate->error_function(), 3215 isolate->error_function(),
3221 i::MessageTemplate::kDataCloneDeserializationError)); 3216 i::MessageTemplate::kDataCloneDeserializationError));
3222 return MaybeLocal<Object>(); 3217 return MaybeLocal<Object>();
3223 } 3218 }
3224 3219
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
3234 struct ValueDeserializer::PrivateData { 3220 struct ValueDeserializer::PrivateData {
3235 PrivateData(i::Isolate* i, i::Vector<const uint8_t> data, Delegate* delegate) 3221 PrivateData(i::Isolate* i, i::Vector<const uint8_t> data, Delegate* delegate)
3236 : isolate(i), deserializer(i, data, delegate) {} 3222 : isolate(i), deserializer(i, data, delegate) {}
3237 i::Isolate* isolate; 3223 i::Isolate* isolate;
3238 i::ValueDeserializer deserializer; 3224 i::ValueDeserializer deserializer;
3239 bool has_aborted = false; 3225 bool has_aborted = false;
3240 bool supports_legacy_wire_format = false; 3226 bool supports_legacy_wire_format = false;
3241 }; 3227 };
3242 3228
3243 ValueDeserializer::ValueDeserializer(Isolate* isolate, const uint8_t* data, 3229 ValueDeserializer::ValueDeserializer(Isolate* isolate, const uint8_t* data,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
3286 } 3272 }
3287 3273
3288 return Just(true); 3274 return Just(true);
3289 } 3275 }
3290 3276
3291 void ValueDeserializer::SetSupportsLegacyWireFormat( 3277 void ValueDeserializer::SetSupportsLegacyWireFormat(
3292 bool supports_legacy_wire_format) { 3278 bool supports_legacy_wire_format) {
3293 private_->supports_legacy_wire_format = supports_legacy_wire_format; 3279 private_->supports_legacy_wire_format = supports_legacy_wire_format;
3294 } 3280 }
3295 3281
3296 void ValueDeserializer::SetExpectInlineWasm(bool expect_inline_wasm) {
3297 private_->deserializer.set_expect_inline_wasm(expect_inline_wasm);
3298 }
3299
3300 uint32_t ValueDeserializer::GetWireFormatVersion() const { 3282 uint32_t ValueDeserializer::GetWireFormatVersion() const {
3301 CHECK(!private_->has_aborted); 3283 CHECK(!private_->has_aborted);
3302 return private_->deserializer.GetWireFormatVersion(); 3284 return private_->deserializer.GetWireFormatVersion();
3303 } 3285 }
3304 3286
3305 MaybeLocal<Value> ValueDeserializer::ReadValue(Local<Context> context) { 3287 MaybeLocal<Value> ValueDeserializer::ReadValue(Local<Context> context) {
3306 CHECK(!private_->has_aborted); 3288 CHECK(!private_->has_aborted);
3307 PREPARE_FOR_EXECUTION(context, ValueDeserializer, ReadValue, Value); 3289 PREPARE_FOR_EXECUTION(context, ValueDeserializer, ReadValue, Value);
3308 i::MaybeHandle<i::Object> result; 3290 i::MaybeHandle<i::Object> result;
3309 if (GetWireFormatVersion() > 0) { 3291 if (GetWireFormatVersion() > 0) {
(...skipping 4211 matching lines...) Expand 10 before | Expand all | Expand 10 after
7521 7503
7522 Local<String> WasmCompiledModule::GetWasmWireBytes() { 7504 Local<String> WasmCompiledModule::GetWasmWireBytes() {
7523 i::Handle<i::JSObject> obj = 7505 i::Handle<i::JSObject> obj =
7524 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this)); 7506 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this));
7525 i::Handle<i::WasmCompiledModule> compiled_part = 7507 i::Handle<i::WasmCompiledModule> compiled_part =
7526 i::handle(i::WasmCompiledModule::cast(obj->GetEmbedderField(0))); 7508 i::handle(i::WasmCompiledModule::cast(obj->GetEmbedderField(0)));
7527 i::Handle<i::String> wire_bytes(compiled_part->module_bytes()); 7509 i::Handle<i::String> wire_bytes(compiled_part->module_bytes());
7528 return Local<String>::Cast(Utils::ToLocal(wire_bytes)); 7510 return Local<String>::Cast(Utils::ToLocal(wire_bytes));
7529 } 7511 }
7530 7512
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
7561 WasmCompiledModule::SerializedModule WasmCompiledModule::Serialize() { 7513 WasmCompiledModule::SerializedModule WasmCompiledModule::Serialize() {
7562 i::Handle<i::JSObject> obj = 7514 i::Handle<i::JSObject> obj =
7563 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this)); 7515 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this));
7564 i::Handle<i::WasmCompiledModule> compiled_part = 7516 i::Handle<i::WasmCompiledModule> compiled_part =
7565 i::handle(i::WasmCompiledModule::cast(obj->GetEmbedderField(0))); 7517 i::handle(i::WasmCompiledModule::cast(obj->GetEmbedderField(0)));
7566 7518
7567 std::unique_ptr<i::ScriptData> script_data = 7519 std::unique_ptr<i::ScriptData> script_data =
7568 i::WasmCompiledModuleSerializer::SerializeWasmModule(obj->GetIsolate(), 7520 i::WasmCompiledModuleSerializer::SerializeWasmModule(obj->GetIsolate(),
7569 compiled_part); 7521 compiled_part);
7570 script_data->ReleaseDataOwnership(); 7522 script_data->ReleaseDataOwnership();
(...skipping 2723 matching lines...) Expand 10 before | Expand all | Expand 10 after
10294 Address callback_address = 10246 Address callback_address =
10295 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 10247 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
10296 VMState<EXTERNAL> state(isolate); 10248 VMState<EXTERNAL> state(isolate);
10297 ExternalCallbackScope call_scope(isolate, callback_address); 10249 ExternalCallbackScope call_scope(isolate, callback_address);
10298 callback(info); 10250 callback(info);
10299 } 10251 }
10300 10252
10301 10253
10302 } // namespace internal 10254 } // namespace internal
10303 } // namespace v8 10255 } // 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