Home | History | Annotate | Download | only in src
      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 #include "src/isolate.h"
      6 
      7 #ifndef V8_SNAPSHOT_H_
      8 #define V8_SNAPSHOT_H_
      9 
     10 namespace v8 {
     11 namespace internal {
     12 
     13 class Snapshot {
     14  public:
     15   // Initialize the VM from the given snapshot file. If snapshot_file is
     16   // NULL, use the internal snapshot instead. Returns false if no snapshot
     17   // could be found.
     18   static bool Initialize(const char* snapshot_file = NULL);
     19 
     20   static bool HaveASnapshotToStartFrom();
     21 
     22   // Create a new context using the internal partial snapshot.
     23   static Handle<Context> NewContextFromSnapshot(Isolate* isolate);
     24 
     25   // Returns whether or not the snapshot is enabled.
     26   static bool IsEnabled() { return size_ != 0; }
     27 
     28   // Write snapshot to the given file. Returns true if snapshot was written
     29   // successfully.
     30   static bool WriteToFile(const char* snapshot_file);
     31 
     32   static const byte* data() { return data_; }
     33   static int size() { return size_; }
     34   static int raw_size() { return raw_size_; }
     35   static void set_raw_data(const byte* raw_data) {
     36     raw_data_ = raw_data;
     37   }
     38   static const byte* context_data() { return context_data_; }
     39   static int context_size() { return context_size_; }
     40   static int context_raw_size() { return context_raw_size_; }
     41   static void set_context_raw_data(
     42       const byte* context_raw_data) {
     43     context_raw_data_ = context_raw_data;
     44   }
     45 
     46  private:
     47   static const byte data_[];
     48   static const byte* raw_data_;
     49   static const byte context_data_[];
     50   static const byte* context_raw_data_;
     51   static const int new_space_used_;
     52   static const int pointer_space_used_;
     53   static const int data_space_used_;
     54   static const int code_space_used_;
     55   static const int map_space_used_;
     56   static const int cell_space_used_;
     57   static const int property_cell_space_used_;
     58   static const int context_new_space_used_;
     59   static const int context_pointer_space_used_;
     60   static const int context_data_space_used_;
     61   static const int context_code_space_used_;
     62   static const int context_map_space_used_;
     63   static const int context_cell_space_used_;
     64   static const int context_property_cell_space_used_;
     65   static const int size_;
     66   static const int raw_size_;
     67   static const int context_size_;
     68   static const int context_raw_size_;
     69 
     70   static void ReserveSpaceForLinkedInSnapshot(Deserializer* deserializer);
     71 
     72   DISALLOW_IMPLICIT_CONSTRUCTORS(Snapshot);
     73 };
     74 
     75 } }  // namespace v8::internal
     76 
     77 #endif  // V8_SNAPSHOT_H_
     78