v8  3.25.30(node0.11.13)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
snapshot-common.cc
Go to the documentation of this file.
1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 // The common functionality when building with or without snapshots.
29 
30 #include "v8.h"
31 
32 #include "api.h"
33 #include "serialize.h"
34 #include "snapshot.h"
35 #include "platform.h"
36 
37 namespace v8 {
38 namespace internal {
39 
40 
41 static void ReserveSpaceForSnapshot(Deserializer* deserializer,
42  const char* file_name) {
43  int file_name_length = StrLength(file_name) + 10;
44  Vector<char> name = Vector<char>::New(file_name_length + 1);
45  OS::SNPrintF(name, "%s.size", file_name);
46  FILE* fp = OS::FOpen(name.start(), "r");
47  CHECK_NE(NULL, fp);
48  int new_size, pointer_size, data_size, code_size, map_size, cell_size,
49  property_cell_size;
50 #ifdef _MSC_VER
51  // Avoid warning about unsafe fscanf from MSVC.
52  // Please note that this is only fine if %c and %s are not being used.
53 #define fscanf fscanf_s
54 #endif
55  CHECK_EQ(1, fscanf(fp, "new %d\n", &new_size));
56  CHECK_EQ(1, fscanf(fp, "pointer %d\n", &pointer_size));
57  CHECK_EQ(1, fscanf(fp, "data %d\n", &data_size));
58  CHECK_EQ(1, fscanf(fp, "code %d\n", &code_size));
59  CHECK_EQ(1, fscanf(fp, "map %d\n", &map_size));
60  CHECK_EQ(1, fscanf(fp, "cell %d\n", &cell_size));
61  CHECK_EQ(1, fscanf(fp, "property cell %d\n", &property_cell_size));
62 #ifdef _MSC_VER
63 #undef fscanf
64 #endif
65  fclose(fp);
66  deserializer->set_reservation(NEW_SPACE, new_size);
67  deserializer->set_reservation(OLD_POINTER_SPACE, pointer_size);
68  deserializer->set_reservation(OLD_DATA_SPACE, data_size);
69  deserializer->set_reservation(CODE_SPACE, code_size);
70  deserializer->set_reservation(MAP_SPACE, map_size);
71  deserializer->set_reservation(CELL_SPACE, cell_size);
72  deserializer->set_reservation(PROPERTY_CELL_SPACE,
73  property_cell_size);
74  name.Dispose();
75 }
76 
77 
78 void Snapshot::ReserveSpaceForLinkedInSnapshot(Deserializer* deserializer) {
79  deserializer->set_reservation(NEW_SPACE, new_space_used_);
80  deserializer->set_reservation(OLD_POINTER_SPACE, pointer_space_used_);
81  deserializer->set_reservation(OLD_DATA_SPACE, data_space_used_);
82  deserializer->set_reservation(CODE_SPACE, code_space_used_);
83  deserializer->set_reservation(MAP_SPACE, map_space_used_);
84  deserializer->set_reservation(CELL_SPACE, cell_space_used_);
85  deserializer->set_reservation(PROPERTY_CELL_SPACE,
86  property_cell_space_used_);
87 }
88 
89 
90 bool Snapshot::Initialize(const char* snapshot_file) {
91  if (snapshot_file) {
92  int len;
93  byte* str = ReadBytes(snapshot_file, &len);
94  if (!str) return false;
95  bool success;
96  {
97  SnapshotByteSource source(str, len);
98  Deserializer deserializer(&source);
99  ReserveSpaceForSnapshot(&deserializer, snapshot_file);
100  success = V8::Initialize(&deserializer);
101  }
102  DeleteArray(str);
103  return success;
104  } else if (size_ > 0) {
105  ElapsedTimer timer;
106  if (FLAG_profile_deserialization) {
107  timer.Start();
108  }
109  SnapshotByteSource source(raw_data_, raw_size_);
110  Deserializer deserializer(&source);
111  ReserveSpaceForLinkedInSnapshot(&deserializer);
112  bool success = V8::Initialize(&deserializer);
113  if (FLAG_profile_deserialization) {
114  double ms = timer.Elapsed().InMillisecondsF();
115  PrintF("[Snapshot loading and deserialization took %0.3f ms]\n", ms);
116  }
117  return success;
118  }
119  return false;
120 }
121 
122 
124  return size_ != 0;
125 }
126 
127 
129  if (context_size_ == 0) {
130  return Handle<Context>();
131  }
132  SnapshotByteSource source(context_raw_data_,
133  context_raw_size_);
134  Deserializer deserializer(&source);
135  Object* root;
136  deserializer.set_reservation(NEW_SPACE, context_new_space_used_);
137  deserializer.set_reservation(OLD_POINTER_SPACE, context_pointer_space_used_);
138  deserializer.set_reservation(OLD_DATA_SPACE, context_data_space_used_);
139  deserializer.set_reservation(CODE_SPACE, context_code_space_used_);
140  deserializer.set_reservation(MAP_SPACE, context_map_space_used_);
141  deserializer.set_reservation(CELL_SPACE, context_cell_space_used_);
143  context_property_cell_space_used_);
144  deserializer.DeserializePartial(isolate, &root);
145  CHECK(root->IsContext());
146  return Handle<Context>(Context::cast(root));
147 }
148 
149 } } // namespace v8::internal
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter NULL
Definition: flags.cc:269
static bool Initialize(Deserializer *des)
Definition: v8.cc:61
#define CHECK_EQ(expected, value)
Definition: checks.h:252
void PrintF(const char *format,...)
Definition: v8utils.cc:40
static Context * cast(Object *context)
Definition: contexts.h:244
#define CHECK(condition)
Definition: checks.h:75
byte * ReadBytes(const char *filename, int *size, bool verbose)
Definition: v8utils.cc:163
void set_reservation(int space_number, int reservation)
Definition: serialize.h:333
uint8_t byte
Definition: globals.h:185
static Handle< Context > NewContextFromSnapshot(Isolate *isolate)
static FILE * FOpen(const char *path, const char *mode)
void DeserializePartial(Isolate *isolate, Object **root)
Definition: serialize.cc:844
static Vector< T > New(int length)
Definition: utils.h:406
#define CHECK_NE(unexpected, value)
Definition: checks.h:256
int StrLength(const char *string)
Definition: utils.h:253
static int SNPrintF(Vector< char > str, const char *format,...)
static bool HaveASnapshotToStartFrom()
const Register fp
void DeleteArray(T *array)
Definition: allocation.h:91
static bool Initialize(const char *snapshot_file=NULL)
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes number of stack frames inspected by the profiler percentage of ICs that must have type info to allow optimization extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long expose natives in global object expose freeBuffer extension expose gc extension under the specified name expose externalize string extension number of stack frames to capture disable builtin natives files print name of functions for which code is generated use random jit cookie to mask large constants trace lazy optimization use adaptive optimizations always try to OSR functions trace optimize function deoptimization minimum length for automatic enable preparsing maximum number of optimization attempts before giving up cache prototype transitions trace debugging JSON request response trace out of bounds accesses to external arrays trace_js_array_abuse automatically set the debug break flag when debugger commands are in the queue abort by crashing maximum length of function source code printed in a stack trace max size of the new max size of the old max size of executable always perform global GCs print one trace line following each garbage collection do not print trace line after scavenger collection print statistics of the maximum memory committed for the heap in name
Definition: flags.cc:505