| 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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 if (ctr == NULL) return NULL; | 107 if (ctr == NULL) return NULL; |
| 108 int* ptr = ctr->Bind(name); | 108 int* ptr = ctr->Bind(name); |
| 109 counter_table_[counter] = ptr; | 109 counter_table_[counter] = ptr; |
| 110 return ptr; | 110 return ptr; |
| 111 } | 111 } |
| 112 | 112 |
| 113 | 113 |
| 114 // Write C++ code that defines Snapshot::snapshot_ to contain the snapshot | 114 // Write C++ code that defines Snapshot::snapshot_ to contain the snapshot |
| 115 // to the file given by filename. Only the first size chars are written. | 115 // to the file given by filename. Only the first size chars are written. |
| 116 static int WriteInternalSnapshotToFile(const char* filename, | 116 static int WriteInternalSnapshotToFile(const char* filename, |
| 117 const char* str, | 117 const v8::internal::byte* bytes, |
| 118 int size) { | 118 int size) { |
| 119 FILE* f = i::OS::FOpen(filename, "wb"); | 119 FILE* f = i::OS::FOpen(filename, "wb"); |
| 120 if (f == NULL) { | 120 if (f == NULL) { |
| 121 i::OS::PrintError("Cannot open file %s for reading.\n", filename); | 121 i::OS::PrintError("Cannot open file %s for reading.\n", filename); |
| 122 return 0; | 122 return 0; |
| 123 } | 123 } |
| 124 fprintf(f, "// Autogenerated snapshot file. Do not edit.\n\n"); | 124 fprintf(f, "// Autogenerated snapshot file. Do not edit.\n\n"); |
| 125 fprintf(f, "#include \"v8.h\"\n"); | 125 fprintf(f, "#include \"v8.h\"\n"); |
| 126 fprintf(f, "#include \"platform.h\"\n\n"); | 126 fprintf(f, "#include \"platform.h\"\n\n"); |
| 127 fprintf(f, "#include \"snapshot.h\"\n\n"); | 127 fprintf(f, "#include \"snapshot.h\"\n\n"); |
| 128 fprintf(f, "namespace v8 {\nnamespace internal {\n\n"); | 128 fprintf(f, "namespace v8 {\nnamespace internal {\n\n"); |
| 129 fprintf(f, "const char Snapshot::data_[] = {"); | 129 fprintf(f, "const byte Snapshot::data_[] = {"); |
| 130 int written = 0; | 130 int written = 0; |
| 131 written += fprintf(f, "%i", str[0]); | 131 written += fprintf(f, "0x%x", bytes[0]); |
| 132 for (int i = 1; i < size; ++i) { | 132 for (int i = 1; i < size; ++i) { |
| 133 written += fprintf(f, ",%i", str[i]); | 133 written += fprintf(f, ",0x%x", bytes[i]); |
| 134 // The following is needed to keep the line length low on Visual C++: | 134 // The following is needed to keep the line length low on Visual C++: |
| 135 if (i % 512 == 0) fprintf(f, "\n"); | 135 if (i % 512 == 0) fprintf(f, "\n"); |
| 136 } | 136 } |
| 137 fprintf(f, "};\n\n"); | 137 fprintf(f, "};\n\n"); |
| 138 fprintf(f, "int Snapshot::size_ = %d;\n\n", size); | 138 fprintf(f, "int Snapshot::size_ = %d;\n\n", size); |
| 139 fprintf(f, "} } // namespace v8::internal\n"); | 139 fprintf(f, "} } // namespace v8::internal\n"); |
| 140 fclose(f); | 140 fclose(f); |
| 141 return written; | 141 return written; |
| 142 } | 142 } |
| 143 | 143 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 167 // Make sure all builtin scripts are cached. | 167 // Make sure all builtin scripts are cached. |
| 168 { HandleScope scope; | 168 { HandleScope scope; |
| 169 for (int i = 0; i < i::Natives::GetBuiltinsCount(); i++) { | 169 for (int i = 0; i < i::Natives::GetBuiltinsCount(); i++) { |
| 170 i::Bootstrapper::NativesSourceLookup(i); | 170 i::Bootstrapper::NativesSourceLookup(i); |
| 171 } | 171 } |
| 172 } | 172 } |
| 173 // Get rid of unreferenced scripts with a global GC. | 173 // Get rid of unreferenced scripts with a global GC. |
| 174 i::Heap::CollectAllGarbage(); | 174 i::Heap::CollectAllGarbage(); |
| 175 i::Serializer ser; | 175 i::Serializer ser; |
| 176 ser.Serialize(); | 176 ser.Serialize(); |
| 177 char* str; | 177 v8::internal::byte* bytes; |
| 178 int len; | 178 int len; |
| 179 ser.Finalize(&str, &len); | 179 ser.Finalize(&bytes, &len); |
| 180 | 180 |
| 181 WriteInternalSnapshotToFile(argv[1], str, len); | 181 WriteInternalSnapshotToFile(argv[1], bytes, len); |
| 182 | 182 |
| 183 i::DeleteArray(str); | 183 i::DeleteArray(bytes); |
| 184 | 184 |
| 185 return 0; | 185 return 0; |
| 186 } | 186 } |
| OLD | NEW |