| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 // The common functionality when building with or without snapshots. | 5 // The common functionality when building with or without snapshots. |
| 6 | 6 |
| 7 #include "src/v8.h" | 7 #include "src/v8.h" |
| 8 | 8 |
| 9 #include "src/api.h" | 9 #include "src/api.h" |
| 10 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 if (FLAG_profile_deserialization) { | 47 if (FLAG_profile_deserialization) { |
| 48 double ms = timer.Elapsed().InMillisecondsF(); | 48 double ms = timer.Elapsed().InMillisecondsF(); |
| 49 int bytes = startup_data.length(); | 49 int bytes = startup_data.length(); |
| 50 PrintF("[Deserializing isolate (%d bytes) took %0.3f ms]\n", bytes, ms); | 50 PrintF("[Deserializing isolate (%d bytes) took %0.3f ms]\n", bytes, ms); |
| 51 } | 51 } |
| 52 return success; | 52 return success; |
| 53 } | 53 } |
| 54 | 54 |
| 55 | 55 |
| 56 MaybeHandle<Context> Snapshot::NewContextFromSnapshot( | 56 MaybeHandle<Context> Snapshot::NewContextFromSnapshot( |
| 57 Isolate* isolate, Handle<FixedArray>* outdated_contexts_out) { | 57 Isolate* isolate, Handle<JSGlobalProxy> global_proxy, |
| 58 Handle<FixedArray>* outdated_contexts_out) { |
| 58 if (!HaveASnapshotToStartFrom()) return Handle<Context>(); | 59 if (!HaveASnapshotToStartFrom()) return Handle<Context>(); |
| 59 base::ElapsedTimer timer; | 60 base::ElapsedTimer timer; |
| 60 if (FLAG_profile_deserialization) timer.Start(); | 61 if (FLAG_profile_deserialization) timer.Start(); |
| 61 | 62 |
| 62 const v8::StartupData blob = SnapshotBlob(); | 63 const v8::StartupData blob = SnapshotBlob(); |
| 63 Vector<const byte> context_data = ExtractContextData(&blob); | 64 Vector<const byte> context_data = ExtractContextData(&blob); |
| 64 SnapshotData snapshot_data(context_data); | 65 SnapshotData snapshot_data(context_data); |
| 65 Deserializer deserializer(&snapshot_data); | 66 Deserializer deserializer(&snapshot_data); |
| 66 | 67 |
| 67 MaybeHandle<Object> maybe_context = | 68 MaybeHandle<Object> maybe_context = deserializer.DeserializePartial( |
| 68 deserializer.DeserializePartial(isolate, outdated_contexts_out); | 69 isolate, global_proxy, outdated_contexts_out); |
| 69 Handle<Object> result; | 70 Handle<Object> result; |
| 70 if (!maybe_context.ToHandle(&result)) return MaybeHandle<Context>(); | 71 if (!maybe_context.ToHandle(&result)) return MaybeHandle<Context>(); |
| 71 CHECK(result->IsContext()); | 72 CHECK(result->IsContext()); |
| 72 // If the snapshot does not contain a custom script, we need to update | 73 // If the snapshot does not contain a custom script, we need to update |
| 73 // the global object for exactly one context. | 74 // the global object for exactly one context. |
| 74 CHECK(EmbedsScript() || (*outdated_contexts_out)->length() == 1); | 75 CHECK(EmbedsScript() || (*outdated_contexts_out)->length() == 1); |
| 75 if (FLAG_profile_deserialization) { | 76 if (FLAG_profile_deserialization) { |
| 76 double ms = timer.Elapsed().InMillisecondsF(); | 77 double ms = timer.Elapsed().InMillisecondsF(); |
| 77 int bytes = context_data.length(); | 78 int bytes = context_data.length(); |
| 78 PrintF("[Deserializing context (%d bytes) took %0.3f ms]\n", bytes, ms); | 79 PrintF("[Deserializing context (%d bytes) took %0.3f ms]\n", bytes, ms); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 int startup_length; | 124 int startup_length; |
| 124 memcpy(&startup_length, data->data + kStartupLengthOffset, kIntSize); | 125 memcpy(&startup_length, data->data + kStartupLengthOffset, kIntSize); |
| 125 int context_offset = ContextOffset(startup_length); | 126 int context_offset = ContextOffset(startup_length); |
| 126 const byte* context_data = | 127 const byte* context_data = |
| 127 reinterpret_cast<const byte*>(data->data + context_offset); | 128 reinterpret_cast<const byte*>(data->data + context_offset); |
| 128 DCHECK_LT(context_offset, data->raw_size); | 129 DCHECK_LT(context_offset, data->raw_size); |
| 129 int context_length = data->raw_size - context_offset; | 130 int context_length = data->raw_size - context_offset; |
| 130 return Vector<const byte>(context_data, context_length); | 131 return Vector<const byte>(context_data, context_length); |
| 131 } | 132 } |
| 132 } } // namespace v8::internal | 133 } } // namespace v8::internal |
| OLD | NEW |