Chromium Code Reviews| 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 20 matching lines...) Expand all Loading... | |
| 31 bool success = isolate->Init(&deserializer); | 31 bool success = isolate->Init(&deserializer); |
| 32 if (FLAG_profile_deserialization) { | 32 if (FLAG_profile_deserialization) { |
| 33 double ms = timer.Elapsed().InMillisecondsF(); | 33 double ms = timer.Elapsed().InMillisecondsF(); |
| 34 int bytes = startup_data.length(); | 34 int bytes = startup_data.length(); |
| 35 PrintF("[Deserializing isolate (%d bytes) took %0.3f ms]\n", bytes, ms); | 35 PrintF("[Deserializing isolate (%d bytes) took %0.3f ms]\n", bytes, ms); |
| 36 } | 36 } |
| 37 return success; | 37 return success; |
| 38 } | 38 } |
| 39 | 39 |
| 40 | 40 |
| 41 Handle<Context> Snapshot::NewContextFromSnapshot(Isolate* isolate) { | 41 MaybeHandle<Context> Snapshot::NewContextFromSnapshot( |
| 42 Isolate* isolate, Handle<FixedArray>* outdated_contexts_out) { | |
| 42 if (!HaveASnapshotToStartFrom()) return Handle<Context>(); | 43 if (!HaveASnapshotToStartFrom()) return Handle<Context>(); |
| 43 base::ElapsedTimer timer; | 44 base::ElapsedTimer timer; |
| 44 if (FLAG_profile_deserialization) timer.Start(); | 45 if (FLAG_profile_deserialization) timer.Start(); |
| 45 | 46 |
| 46 const v8::StartupData blob = SnapshotBlob(); | 47 const v8::StartupData blob = SnapshotBlob(); |
| 47 Vector<const byte> context_data = ExtractContextData(&blob); | 48 Vector<const byte> context_data = ExtractContextData(&blob); |
| 48 SnapshotData snapshot_data(context_data); | 49 SnapshotData snapshot_data(context_data); |
| 49 Deserializer deserializer(&snapshot_data); | 50 Deserializer deserializer(&snapshot_data); |
| 50 Object* root; | 51 |
| 51 deserializer.DeserializePartial(isolate, &root); | 52 MaybeHandle<Object> maybe_context = |
| 52 CHECK(root->IsContext()); | 53 deserializer.DeserializePartial(isolate, outdated_contexts_out); |
| 54 Handle<Object> result; | |
| 55 if (!maybe_context.ToHandle(&result)) return MaybeHandle<Context>(); | |
| 56 CHECK(result->IsContext()); | |
|
jochen (gone - plz use gerrit)
2015/01/12 19:57:10
maybe also check that the outdated contexts is a f
Yang
2015/01/13 08:20:11
Added the check to DeserializePartial, where its c
| |
| 53 if (FLAG_profile_deserialization) { | 57 if (FLAG_profile_deserialization) { |
| 54 double ms = timer.Elapsed().InMillisecondsF(); | 58 double ms = timer.Elapsed().InMillisecondsF(); |
| 55 int bytes = context_data.length(); | 59 int bytes = context_data.length(); |
| 56 PrintF("[Deserializing context (%d bytes) took %0.3f ms]\n", bytes, ms); | 60 PrintF("[Deserializing context (%d bytes) took %0.3f ms]\n", bytes, ms); |
| 57 } | 61 } |
| 58 return Handle<Context>(Context::cast(root)); | 62 return Handle<Context>::cast(result); |
| 59 } | 63 } |
| 60 | 64 |
| 61 | 65 |
| 62 v8::StartupData Snapshot::CreateSnapshotBlob( | 66 v8::StartupData Snapshot::CreateSnapshotBlob( |
| 63 const Vector<const byte> startup_data, | 67 const Vector<const byte> startup_data, |
| 64 const Vector<const byte> context_data) { | 68 const Vector<const byte> context_data) { |
| 65 int startup_length = startup_data.length(); | 69 int startup_length = startup_data.length(); |
| 66 int context_length = context_data.length(); | 70 int context_length = context_data.length(); |
| 67 int context_offset = kIntSize + startup_length; | 71 int context_offset = kIntSize + startup_length; |
| 68 int length = context_offset + context_length; | 72 int length = context_offset + context_length; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 92 int startup_length; | 96 int startup_length; |
| 93 memcpy(&startup_length, data->data, kIntSize); | 97 memcpy(&startup_length, data->data, kIntSize); |
| 94 int context_offset = kIntSize + startup_length; | 98 int context_offset = kIntSize + startup_length; |
| 95 const byte* context_data = | 99 const byte* context_data = |
| 96 reinterpret_cast<const byte*>(data->data + context_offset); | 100 reinterpret_cast<const byte*>(data->data + context_offset); |
| 97 DCHECK_LT(context_offset, data->raw_size); | 101 DCHECK_LT(context_offset, data->raw_size); |
| 98 int context_length = data->raw_size - context_offset; | 102 int context_length = data->raw_size - context_offset; |
| 99 return Vector<const byte>(context_data, context_length); | 103 return Vector<const byte>(context_data, context_length); |
| 100 } | 104 } |
| 101 } } // namespace v8::internal | 105 } } // namespace v8::internal |
| OLD | NEW |