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 3 // found in the LICENSE file. 4 5 // Used for building with external snapshots. 6 7 #include "src/snapshot/snapshot.h" 8 9 #include "src/base/platform/mutex.h" 10 #include "src/init/v8.h" // for V8::Initialize 11 #include "src/snapshot/snapshot-source-sink.h" 12 13 #ifndef V8_USE_EXTERNAL_STARTUP_DATA 14 #error snapshot-external.cc is used only for the external snapshot build. 15 #endif // V8_USE_EXTERNAL_STARTUP_DATA 16 17 18 namespace v8 { 19 namespace internal { 20 21 static base::LazyMutex external_startup_data_mutex = LAZY_MUTEX_INITIALIZER; 22 static v8::StartupData external_startup_blob = {nullptr, 0}; 23 SetSnapshotFromFile(StartupData * snapshot_blob)24void SetSnapshotFromFile(StartupData* snapshot_blob) { 25 base::MutexGuard lock_guard(external_startup_data_mutex.Pointer()); 26 DCHECK(snapshot_blob); 27 DCHECK(snapshot_blob->data); 28 DCHECK_GT(snapshot_blob->raw_size, 0); 29 DCHECK(!external_startup_blob.data); 30 DCHECK(Snapshot::SnapshotIsValid(snapshot_blob)); 31 external_startup_blob = *snapshot_blob; 32 } 33 34 DefaultSnapshotBlob()35const v8::StartupData* Snapshot::DefaultSnapshotBlob() { 36 base::MutexGuard lock_guard(external_startup_data_mutex.Pointer()); 37 return &external_startup_blob; 38 } 39 } // namespace internal 40 } // namespace v8 41