| 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 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without | 
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are | 
| 4 // met: | 4 // met: | 
| 5 // | 5 // | 
| 6 //     * Redistributions of source code must retain the above copyright | 6 //     * Redistributions of source code must retain the above copyright | 
| 7 //       notice, this list of conditions and the following disclaimer. | 7 //       notice, this list of conditions and the following disclaimer. | 
| 8 //     * Redistributions in binary form must reproduce the above | 8 //     * Redistributions in binary form must reproduce the above | 
| 9 //       copyright notice, this list of conditions and the following | 9 //       copyright notice, this list of conditions and the following | 
| 10 //       disclaimer in the documentation and/or other materials provided | 10 //       disclaimer in the documentation and/or other materials provided | 
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 129   char at(int i) { return data_[i]; } | 129   char at(int i) { return data_[i]; } | 
| 130   bool Compress(Compressor* compressor) { | 130   bool Compress(Compressor* compressor) { | 
| 131     ASSERT_EQ(-1, raw_size_); | 131     ASSERT_EQ(-1, raw_size_); | 
| 132     raw_size_ = data_.length(); | 132     raw_size_ = data_.length(); | 
| 133     if (!compressor->Compress(data_.ToVector())) return false; | 133     if (!compressor->Compress(data_.ToVector())) return false; | 
| 134     data_.Clear(); | 134     data_.Clear(); | 
| 135     data_.AddAll(*compressor->output()); | 135     data_.AddAll(*compressor->output()); | 
| 136     return true; | 136     return true; | 
| 137   } | 137   } | 
| 138   int raw_size() { return raw_size_; } | 138   int raw_size() { return raw_size_; } | 
|  | 139 | 
| 139  private: | 140  private: | 
| 140   i::List<char> data_; | 141   i::List<char> data_; | 
| 141   int raw_size_; | 142   int raw_size_; | 
| 142 }; | 143 }; | 
| 143 | 144 | 
| 144 | 145 | 
| 145 class CppByteSink : public PartialSnapshotSink { | 146 class CppByteSink : public PartialSnapshotSink { | 
| 146  public: | 147  public: | 
| 147   explicit CppByteSink(const char* snapshot_file) { | 148   explicit CppByteSink(const char* snapshot_file) { | 
| 148     fp_ = i::OS::FOpen(snapshot_file, "wb"); | 149     fp_ = i::OS::FOpen(snapshot_file, "wb"); | 
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 258     } else { | 259     } else { | 
| 259       fprintf(stderr, "bzlib error code: %d\n", result); | 260       fprintf(stderr, "bzlib error code: %d\n", result); | 
| 260       return false; | 261       return false; | 
| 261     } | 262     } | 
| 262   } | 263   } | 
| 263   virtual i::Vector<char>* output() { return output_; } | 264   virtual i::Vector<char>* output() { return output_; } | 
| 264 | 265 | 
| 265  private: | 266  private: | 
| 266   i::ScopedVector<char>* output_; | 267   i::ScopedVector<char>* output_; | 
| 267 }; | 268 }; | 
|  | 269 | 
|  | 270 | 
|  | 271 class BZip2Decompressor : public StartupDataDecompressor { | 
|  | 272  public: | 
|  | 273   virtual ~BZip2Decompressor() { } | 
|  | 274 | 
|  | 275  protected: | 
|  | 276   virtual int DecompressData(char* raw_data, | 
|  | 277                              int* raw_data_size, | 
|  | 278                              const char* compressed_data, | 
|  | 279                              int compressed_data_size) { | 
|  | 280     ASSERT_EQ(StartupData::kBZip2, | 
|  | 281               V8::GetCompressedStartupDataAlgorithm()); | 
|  | 282     unsigned int decompressed_size = *raw_data_size; | 
|  | 283     int result = | 
|  | 284         BZ2_bzBuffToBuffDecompress(raw_data, | 
|  | 285                                    &decompressed_size, | 
|  | 286                                    const_cast<char*>(compressed_data), | 
|  | 287                                    compressed_data_size, | 
|  | 288                                    0, 1); | 
|  | 289     if (result == BZ_OK) { | 
|  | 290       *raw_data_size = decompressed_size; | 
|  | 291     } | 
|  | 292     return result; | 
|  | 293   } | 
|  | 294 }; | 
| 268 #endif | 295 #endif | 
| 269 | 296 | 
| 270 | 297 | 
| 271 int main(int argc, char** argv) { | 298 int main(int argc, char** argv) { | 
| 272 #ifdef ENABLE_LOGGING_AND_PROFILING | 299 #ifdef ENABLE_LOGGING_AND_PROFILING | 
| 273   // By default, log code create information in the snapshot. | 300   // By default, log code create information in the snapshot. | 
| 274   i::FLAG_log_code = true; | 301   i::FLAG_log_code = true; | 
| 275 #endif | 302 #endif | 
| 276   // Print the usage if an error occurs when parsing the command line | 303   // Print the usage if an error occurs when parsing the command line | 
| 277   // flags or if the help flag is set. | 304   // flags or if the help flag is set. | 
| 278   int result = i::FlagList::SetFlagsFromCommandLine(&argc, argv, true); | 305   int result = i::FlagList::SetFlagsFromCommandLine(&argc, argv, true); | 
| 279   if (result > 0 || argc != 2 || i::FLAG_help) { | 306   if (result > 0 || argc != 2 || i::FLAG_help) { | 
| 280     ::printf("Usage: %s [flag] ... outfile\n", argv[0]); | 307     ::printf("Usage: %s [flag] ... outfile\n", argv[0]); | 
| 281     i::FlagList::PrintHelp(); | 308     i::FlagList::PrintHelp(); | 
| 282     return !i::FLAG_help; | 309     return !i::FLAG_help; | 
| 283   } | 310   } | 
|  | 311 #ifdef COMPRESS_STARTUP_DATA_BZ2 | 
|  | 312   BZip2Decompressor natives_decompressor; | 
|  | 313   int bz2_result = natives_decompressor.Decompress(); | 
|  | 314   if (bz2_result != BZ_OK) { | 
|  | 315     fprintf(stderr, "bzip error code: %d\n", bz2_result); | 
|  | 316     exit(1); | 
|  | 317   } | 
|  | 318 #endif | 
| 284   i::Serializer::Enable(); | 319   i::Serializer::Enable(); | 
| 285   Persistent<Context> context = v8::Context::New(); | 320   Persistent<Context> context = v8::Context::New(); | 
| 286   ASSERT(!context.IsEmpty()); | 321   ASSERT(!context.IsEmpty()); | 
| 287   // Make sure all builtin scripts are cached. | 322   // Make sure all builtin scripts are cached. | 
| 288   { HandleScope scope; | 323   { HandleScope scope; | 
| 289     for (int i = 0; i < i::Natives::GetBuiltinsCount(); i++) { | 324     for (int i = 0; i < i::Natives::GetBuiltinsCount(); i++) { | 
| 290       i::Isolate::Current()->bootstrapper()->NativesSourceLookup(i); | 325       i::Isolate::Current()->bootstrapper()->NativesSourceLookup(i); | 
| 291     } | 326     } | 
| 292   } | 327   } | 
| 293   // If we don't do this then we end up with a stray root pointing at the | 328   // If we don't do this then we end up with a stray root pointing at the | 
| (...skipping 25 matching lines...) Expand all  Loading... | 
| 319   sink.WriteSpaceUsed( | 354   sink.WriteSpaceUsed( | 
| 320       partial_ser.CurrentAllocationAddress(i::NEW_SPACE), | 355       partial_ser.CurrentAllocationAddress(i::NEW_SPACE), | 
| 321       partial_ser.CurrentAllocationAddress(i::OLD_POINTER_SPACE), | 356       partial_ser.CurrentAllocationAddress(i::OLD_POINTER_SPACE), | 
| 322       partial_ser.CurrentAllocationAddress(i::OLD_DATA_SPACE), | 357       partial_ser.CurrentAllocationAddress(i::OLD_DATA_SPACE), | 
| 323       partial_ser.CurrentAllocationAddress(i::CODE_SPACE), | 358       partial_ser.CurrentAllocationAddress(i::CODE_SPACE), | 
| 324       partial_ser.CurrentAllocationAddress(i::MAP_SPACE), | 359       partial_ser.CurrentAllocationAddress(i::MAP_SPACE), | 
| 325       partial_ser.CurrentAllocationAddress(i::CELL_SPACE), | 360       partial_ser.CurrentAllocationAddress(i::CELL_SPACE), | 
| 326       partial_ser.CurrentAllocationAddress(i::LO_SPACE)); | 361       partial_ser.CurrentAllocationAddress(i::LO_SPACE)); | 
| 327   return 0; | 362   return 0; | 
| 328 } | 363 } | 
| OLD | NEW | 
|---|