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

Side by Side Diff: src/api.cc

Issue 2395793003: [wasm] Support recompilation if deserialization fails. (Closed)
Patch Set: Feedback 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
« no previous file with comments | « include/v8.h ('k') | src/snapshot/code-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 7166 matching lines...) Expand 10 before | Expand all | Expand 10 after
7177 PREPARE_FOR_EXECUTION(context, Proxy, New, Proxy); 7177 PREPARE_FOR_EXECUTION(context, Proxy, New, Proxy);
7178 i::Handle<i::JSReceiver> target = Utils::OpenHandle(*local_target); 7178 i::Handle<i::JSReceiver> target = Utils::OpenHandle(*local_target);
7179 i::Handle<i::JSReceiver> handler = Utils::OpenHandle(*local_handler); 7179 i::Handle<i::JSReceiver> handler = Utils::OpenHandle(*local_handler);
7180 Local<Proxy> result; 7180 Local<Proxy> result;
7181 has_pending_exception = 7181 has_pending_exception =
7182 !ToLocal<Proxy>(i::JSProxy::New(isolate, target, handler), &result); 7182 !ToLocal<Proxy>(i::JSProxy::New(isolate, target, handler), &result);
7183 RETURN_ON_FAILED_EXECUTION(Proxy); 7183 RETURN_ON_FAILED_EXECUTION(Proxy);
7184 RETURN_ESCAPED(result); 7184 RETURN_ESCAPED(result);
7185 } 7185 }
7186 7186
7187 Local<String> WasmCompiledModule::GetUncompiledBytes() {
7188 i::Handle<i::JSObject> obj =
7189 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this));
7190 i::Handle<i::wasm::WasmCompiledModule> compiled_part =
7191 i::handle(i::wasm::WasmCompiledModule::cast(obj->GetInternalField(0)));
7192 return Local<String>::Cast(Utils::ToLocal(compiled_part->module_bytes()));
7193 }
7194
7187 WasmCompiledModule::SerializedModule WasmCompiledModule::Serialize() { 7195 WasmCompiledModule::SerializedModule WasmCompiledModule::Serialize() {
7188 i::Handle<i::JSObject> obj = 7196 i::Handle<i::JSObject> obj =
7189 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this)); 7197 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this));
7190 i::Handle<i::FixedArray> compiled_part = 7198 i::Handle<i::wasm::WasmCompiledModule> compiled_part =
7191 i::handle(i::FixedArray::cast(obj->GetInternalField(0))); 7199 i::handle(i::wasm::WasmCompiledModule::cast(obj->GetInternalField(0)));
7200
7201 i::Handle<i::String> uncompiled_bytes = compiled_part->module_bytes();
7202 compiled_part->reset_module_bytes();
7192 std::unique_ptr<i::ScriptData> script_data = 7203 std::unique_ptr<i::ScriptData> script_data =
7193 i::WasmCompiledModuleSerializer::SerializeWasmModule(obj->GetIsolate(), 7204 i::WasmCompiledModuleSerializer::SerializeWasmModule(obj->GetIsolate(),
7194 compiled_part); 7205 compiled_part);
7206 compiled_part->set_module_bytes(uncompiled_bytes);
7195 script_data->ReleaseDataOwnership(); 7207 script_data->ReleaseDataOwnership();
7208
7196 size_t size = static_cast<size_t>(script_data->length()); 7209 size_t size = static_cast<size_t>(script_data->length());
7197 return {std::unique_ptr<const uint8_t[]>(script_data->data()), size}; 7210 return {std::unique_ptr<const uint8_t[]>(script_data->data()), size};
7198 } 7211 }
7199 7212
7200 MaybeLocal<WasmCompiledModule> WasmCompiledModule::Deserialize( 7213 MaybeLocal<WasmCompiledModule> WasmCompiledModule::Deserialize(
7201 Isolate* isolate, 7214 Isolate* isolate,
7202 const WasmCompiledModule::SerializedModule& serialized_data) { 7215 const WasmCompiledModule::SerializedModule& serialized_data) {
7203 int size = static_cast<int>(serialized_data.second); 7216 int size = static_cast<int>(serialized_data.second);
7204 i::ScriptData sc(serialized_data.first.get(), size); 7217 i::ScriptData sc(serialized_data.first.get(), size);
7205 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 7218 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
7206 i::MaybeHandle<i::FixedArray> maybe_compiled_part = 7219 i::MaybeHandle<i::FixedArray> maybe_compiled_part =
7207 i::WasmCompiledModuleSerializer::DeserializeWasmModule(i_isolate, &sc); 7220 i::WasmCompiledModuleSerializer::DeserializeWasmModule(i_isolate, &sc);
7208 i::Handle<i::FixedArray> compiled_part; 7221 i::Handle<i::FixedArray> compiled_part;
7209 if (!maybe_compiled_part.ToHandle(&compiled_part)) { 7222 if (!maybe_compiled_part.ToHandle(&compiled_part)) {
7210 return MaybeLocal<WasmCompiledModule>(); 7223 return MaybeLocal<WasmCompiledModule>();
7211 } 7224 }
7225 i::Handle<i::wasm::WasmCompiledModule> compiled_module =
7226 handle(i::wasm::WasmCompiledModule::cast(*compiled_part));
7212 return Local<WasmCompiledModule>::Cast( 7227 return Local<WasmCompiledModule>::Cast(
7213 Utils::ToLocal(i::wasm::CreateCompiledModuleObject( 7228 Utils::ToLocal(i::wasm::CreateCompiledModuleObject(
7214 i_isolate, compiled_part, i::wasm::ModuleOrigin::kWasmOrigin))); 7229 i_isolate, compiled_module, i::wasm::ModuleOrigin::kWasmOrigin)));
7230 }
7231
7232 MaybeLocal<WasmCompiledModule> WasmCompiledModule::DeserializeOrCompile(
7233 Isolate* isolate,
7234 const WasmCompiledModule::SerializedModule& serialized_data,
7235 Local<String> uncompiled_bytes) {
7236 MaybeLocal<WasmCompiledModule> ret = Deserialize(isolate, serialized_data);
7237 if (!ret.IsEmpty()) return ret;
7238 return Compile(isolate, uncompiled_bytes);
7239 }
7240
7241 MaybeLocal<WasmCompiledModule> WasmCompiledModule::Compile(
7242 Isolate* isolate, Local<String> bytes) {
7243 i::Handle<i::String> module_bytes = Utils::OpenHandle(*bytes);
7244 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
7245 i::wasm::ErrorThrower thrower(i_isolate, "WasmCompiledModule::Deserialize()");
7246 i::SeqOneByteString* data = i::SeqOneByteString::cast(*module_bytes);
7247 i::MaybeHandle<i::JSObject> maybe_compiled =
7248 i::wasm::CreateModuleObjectFromBytes(
7249 i_isolate, data->GetChars(), data->GetChars() + data->length(),
titzer 2016/10/07 07:52:55 This code is getting a raw pointer to the bytes of
Clemens Hammacher 2016/10/07 10:49:24 Landed: https://codereview.chromium.org/2402633002
7250 &thrower, i::wasm::ModuleOrigin::kWasmOrigin);
7251 if (maybe_compiled.is_null()) return MaybeLocal<WasmCompiledModule>();
7252 return Local<WasmCompiledModule>::Cast(
7253 Utils::ToLocal(maybe_compiled.ToHandleChecked()));
7215 } 7254 }
7216 7255
7217 // static 7256 // static
7218 v8::ArrayBuffer::Allocator* v8::ArrayBuffer::Allocator::NewDefaultAllocator() { 7257 v8::ArrayBuffer::Allocator* v8::ArrayBuffer::Allocator::NewDefaultAllocator() {
7219 return new ArrayBufferAllocator(); 7258 return new ArrayBufferAllocator();
7220 } 7259 }
7221 7260
7222 bool v8::ArrayBuffer::IsExternal() const { 7261 bool v8::ArrayBuffer::IsExternal() const {
7223 return Utils::OpenHandle(this)->is_external(); 7262 return Utils::OpenHandle(this)->is_external();
7224 } 7263 }
(...skipping 2151 matching lines...) Expand 10 before | Expand all | Expand 10 after
9376 Address callback_address = 9415 Address callback_address =
9377 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 9416 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
9378 VMState<EXTERNAL> state(isolate); 9417 VMState<EXTERNAL> state(isolate);
9379 ExternalCallbackScope call_scope(isolate, callback_address); 9418 ExternalCallbackScope call_scope(isolate, callback_address);
9380 callback(info); 9419 callback(info);
9381 } 9420 }
9382 9421
9383 9422
9384 } // namespace internal 9423 } // namespace internal
9385 } // namespace v8 9424 } // namespace v8
OLDNEW
« no previous file with comments | « include/v8.h ('k') | src/snapshot/code-serializer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698