summaryrefslogtreecommitdiff
path: root/deps/v8/src/mksnapshot.cc
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2009-11-18 15:25:58 +0100
committerRyan Dahl <ry@tinyclouds.org>2009-11-18 15:28:54 +0100
commit728d8a37f471afaeaa6af19823f9da8c41f1f65a (patch)
tree21e014089ff0bfb7d493691620ab9eee51176d28 /deps/v8/src/mksnapshot.cc
parent8195e0f7232fed3d6a3a2cc8464fec5e36f4433c (diff)
downloadnode-728d8a37f471afaeaa6af19823f9da8c41f1f65a.tar.gz
Upgrade v8 to 2.0
(With just one change: remove -Werror)
Diffstat (limited to 'deps/v8/src/mksnapshot.cc')
-rw-r--r--deps/v8/src/mksnapshot.cc106
1 files changed, 44 insertions, 62 deletions
diff --git a/deps/v8/src/mksnapshot.cc b/deps/v8/src/mksnapshot.cc
index 80789ebbe..eb743f81f 100644
--- a/deps/v8/src/mksnapshot.cc
+++ b/deps/v8/src/mksnapshot.cc
@@ -87,57 +87,53 @@ class CounterCollection {
// We statically allocate a set of local counters to be used if we
// don't want to store the stats in a memory-mapped file
static CounterCollection local_counters;
-static CounterCollection* counters = &local_counters;
typedef std::map<std::string, int*> CounterMap;
typedef std::map<std::string, int*>::iterator CounterMapIterator;
static CounterMap counter_table_;
-// Callback receiver when v8 has a counter to track.
-static int* counter_callback(const char* name) {
- std::string counter = name;
- // See if this counter name is already known.
- if (counter_table_.find(counter) != counter_table_.end())
- return counter_table_[counter];
-
- Counter* ctr = counters->GetNextCounter();
- if (ctr == NULL) return NULL;
- int* ptr = ctr->Bind(name);
- counter_table_[counter] = ptr;
- return ptr;
-}
+class CppByteSink : public i::SnapshotByteSink {
+ public:
+ explicit CppByteSink(const char* snapshot_file) : bytes_written_(0) {
+ fp_ = i::OS::FOpen(snapshot_file, "wb");
+ if (fp_ == NULL) {
+ i::PrintF("Unable to write to snapshot file \"%s\"\n", snapshot_file);
+ exit(1);
+ }
+ fprintf(fp_, "// Autogenerated snapshot file. Do not edit.\n\n");
+ fprintf(fp_, "#include \"v8.h\"\n");
+ fprintf(fp_, "#include \"platform.h\"\n\n");
+ fprintf(fp_, "#include \"snapshot.h\"\n\n");
+ fprintf(fp_, "namespace v8 {\nnamespace internal {\n\n");
+ fprintf(fp_, "const byte Snapshot::data_[] = {");
+ }
-// Write C++ code that defines Snapshot::snapshot_ to contain the snapshot
-// to the file given by filename. Only the first size chars are written.
-static int WriteInternalSnapshotToFile(const char* filename,
- const v8::internal::byte* bytes,
- int size) {
- FILE* f = i::OS::FOpen(filename, "wb");
- if (f == NULL) {
- i::OS::PrintError("Cannot open file %s for reading.\n", filename);
- return 0;
+ virtual ~CppByteSink() {
+ if (fp_ != NULL) {
+ fprintf(fp_, "};\n\n");
+ fprintf(fp_, "int Snapshot::size_ = %d;\n\n", bytes_written_);
+ fprintf(fp_, "} } // namespace v8::internal\n");
+ fclose(fp_);
+ }
}
- fprintf(f, "// Autogenerated snapshot file. Do not edit.\n\n");
- fprintf(f, "#include \"v8.h\"\n");
- fprintf(f, "#include \"platform.h\"\n\n");
- fprintf(f, "#include \"snapshot.h\"\n\n");
- fprintf(f, "namespace v8 {\nnamespace internal {\n\n");
- fprintf(f, "const byte Snapshot::data_[] = {");
- int written = 0;
- written += fprintf(f, "0x%x", bytes[0]);
- for (int i = 1; i < size; ++i) {
- written += fprintf(f, ",0x%x", bytes[i]);
- // The following is needed to keep the line length low on Visual C++:
- if (i % 512 == 0) fprintf(f, "\n");
+
+ virtual void Put(int byte, const char* description) {
+ if (bytes_written_ != 0) {
+ fprintf(fp_, ",");
+ }
+ fprintf(fp_, "%d", byte);
+ bytes_written_++;
+ if ((bytes_written_ & 0x3f) == 0) {
+ fprintf(fp_, "\n");
+ }
}
- fprintf(f, "};\n\n");
- fprintf(f, "int Snapshot::size_ = %d;\n\n", size);
- fprintf(f, "} } // namespace v8::internal\n");
- fclose(f);
- return written;
-}
+
+ private:
+ FILE* fp_;
+ int bytes_written_;
+};
int main(int argc, char** argv) {
@@ -153,34 +149,20 @@ int main(int argc, char** argv) {
i::FlagList::PrintHelp();
return !i::FLAG_help;
}
-
- v8::V8::SetCounterFunction(counter_callback);
- v8::HandleScope scope;
-
- const int kExtensionCount = 1;
- const char* extension_list[kExtensionCount] = { "v8/gc" };
- v8::ExtensionConfiguration extensions(kExtensionCount, extension_list);
-
i::Serializer::Enable();
- v8::Context::New(&extensions);
-
+ Persistent<Context> context = v8::Context::New();
// Make sure all builtin scripts are cached.
{ HandleScope scope;
for (int i = 0; i < i::Natives::GetBuiltinsCount(); i++) {
i::Bootstrapper::NativesSourceLookup(i);
}
}
- // Get rid of unreferenced scripts with a global GC.
- i::Heap::CollectAllGarbage(false);
- i::Serializer ser;
+ context.Dispose();
+ CppByteSink sink(argv[1]);
+ i::Serializer ser(&sink);
+ // This results in a somewhat smaller snapshot, probably because it gets rid
+ // of some things that are cached between garbage collections.
+ i::Heap::CollectAllGarbage(true);
ser.Serialize();
- v8::internal::byte* bytes;
- int len;
- ser.Finalize(&bytes, &len);
-
- WriteInternalSnapshotToFile(argv[1], bytes, len);
-
- i::DeleteArray(bytes);
-
return 0;
}