Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: samples/shell.cc

Issue 6901090: Add support for startup data (snapshot) compression. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 10 matching lines...) Expand all
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #include <v8.h> 28 #include <v8.h>
29 #include <v8-testing.h> 29 #include <v8-testing.h>
30 #include <assert.h> 30 #include <assert.h>
31 #ifdef COMPRESS_STARTUP_DATA_BZ2
Søren Thygesen Gjesse 2011/04/29 06:50:29 Should this support be added to D8 as well? The pr
mnaganov (inactive) 2011/04/29 12:07:58 I think, this doesn't make much sense for D8 eithe
32 #include <bzlib.h>
33 #endif
31 #include <fcntl.h> 34 #include <fcntl.h>
32 #include <string.h> 35 #include <string.h>
33 #include <stdio.h> 36 #include <stdio.h>
34 #include <stdlib.h> 37 #include <stdlib.h>
35 38
36 // When building with V8 in a shared library we cannot use functions which 39 // When building with V8 in a shared library we cannot use functions which
37 // is not explicitly a part of the public V8 API. This extensive use of 40 // is not explicitly a part of the public V8 API. This extensive use of
38 // #ifndef USING_V8_SHARED/#endif is a hack until we can resolve whether to 41 // #ifndef USING_V8_SHARED/#endif is a hack until we can resolve whether to
39 // still use the shell sample for testing or change to use the developer 42 // still use the shell sample for testing or change to use the developer
40 // shell d8 TODO(1272). 43 // shell d8 TODO(1272).
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 FLAG_stress_deopt = true; 295 FLAG_stress_deopt = true;
293 argv[i] = NULL; 296 argv[i] = NULL;
294 } else if (strcmp(argv[i], "--noalways-opt") == 0) { 297 } else if (strcmp(argv[i], "--noalways-opt") == 0) {
295 // No support for stressing if we can't use --always-opt. 298 // No support for stressing if we can't use --always-opt.
296 FLAG_stress_opt = false; 299 FLAG_stress_opt = false;
297 FLAG_stress_deopt = false; 300 FLAG_stress_deopt = false;
298 break; 301 break;
299 } 302 }
300 } 303 }
301 304
305 #ifdef COMPRESS_STARTUP_DATA_BZ2
306 int compressed_data_count = v8::V8::GetCompressedStartupDataCount();
307 v8::StartupData* compressed_data = new v8::StartupData[compressed_data_count];
308 v8::V8::GetCompressedStartupData(compressed_data);
309 for (int i = 0; i < compressed_data_count; ++i) {
310 char* decompressed = new char[compressed_data[i].decompressed_size];
311 unsigned int decompressed_size;
312 int result =
313 BZ2_bzBuffToBuffDecompress(decompressed,
314 &decompressed_size,
315 const_cast<char*>(compressed_data[i].data),
316 compressed_data[i].compressed_size,
317 0, 1);
318 if (result != BZ_OK) {
319 fprintf(stderr, "bzip error code: %d\n", result);
320 exit(1);
321 }
322 compressed_data[i].data = decompressed;
323 compressed_data[i].decompressed_size = decompressed_size;
324 }
325 v8::V8::SetDecompressedStartupData(compressed_data);
326 #endif // COMPRESS_STARTUP_DATA_BZ2
327
302 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); 328 v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
303 int result = 0; 329 int result = 0;
304 if (FLAG_stress_opt || FLAG_stress_deopt) { 330 if (FLAG_stress_opt || FLAG_stress_deopt) {
305 v8::Testing::SetStressRunType(FLAG_stress_opt 331 v8::Testing::SetStressRunType(FLAG_stress_opt
306 ? v8::Testing::kStressTypeOpt 332 ? v8::Testing::kStressTypeOpt
307 : v8::Testing::kStressTypeDeopt); 333 : v8::Testing::kStressTypeDeopt);
308 int stress_runs = v8::Testing::GetStressRuns(); 334 int stress_runs = v8::Testing::GetStressRuns();
309 for (int i = 0; i < stress_runs && result == 0; i++) { 335 for (int i = 0; i < stress_runs && result == 0; i++) {
310 printf("============ Stress %d/%d ============\n", 336 printf("============ Stress %d/%d ============\n",
311 i + 1, stress_runs); 337 i + 1, stress_runs);
312 v8::Testing::PrepareStressRun(i); 338 v8::Testing::PrepareStressRun(i);
313 last_run = (i == stress_runs - 1); 339 last_run = (i == stress_runs - 1);
314 result = RunMain(argc, argv); 340 result = RunMain(argc, argv);
315 } 341 }
316 printf("======== Full Deoptimization =======\n"); 342 printf("======== Full Deoptimization =======\n");
317 v8::Testing::DeoptimizeAll(); 343 v8::Testing::DeoptimizeAll();
318 } else { 344 } else {
319 result = RunMain(argc, argv); 345 result = RunMain(argc, argv);
320 } 346 }
321 v8::V8::Dispose(); 347 v8::V8::Dispose();
348
349 #ifdef COMPRESS_STARTUP_DATA_BZ2
350 for (int i = 0; i < compressed_data_count; ++i) {
351 delete[] compressed_data[i].data;
352 }
353 delete[] compressed_data;
354 #endif // COMPRESS_STARTUP_DATA_BZ2
355
322 return result; 356 return result;
323 } 357 }
324 358
325 359
326 // Extracts a C string from a V8 Utf8Value. 360 // Extracts a C string from a V8 Utf8Value.
327 const char* ToCString(const v8::String::Utf8Value& value) { 361 const char* ToCString(const v8::String::Utf8Value& value) {
328 return *value ? *value : "<string conversion failed>"; 362 return *value ? *value : "<string conversion failed>";
329 } 363 }
330 364
331 365
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 printf("^"); 668 printf("^");
635 } 669 }
636 printf("\n"); 670 printf("\n");
637 v8::String::Utf8Value stack_trace(try_catch->StackTrace()); 671 v8::String::Utf8Value stack_trace(try_catch->StackTrace());
638 if (stack_trace.length() > 0) { 672 if (stack_trace.length() > 0) {
639 const char* stack_trace_string = ToCString(stack_trace); 673 const char* stack_trace_string = ToCString(stack_trace);
640 printf("%s\n", stack_trace_string); 674 printf("%s\n", stack_trace_string);
641 } 675 }
642 } 676 }
643 } 677 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698