Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 Handle<Value> Shell::Int16Array(const Arguments& args) { | 261 Handle<Value> Shell::Int16Array(const Arguments& args) { |
| 262 return CreateExternalArray(args, kExternalShortArray, sizeof(int16_t)); | 262 return CreateExternalArray(args, kExternalShortArray, sizeof(int16_t)); |
| 263 } | 263 } |
| 264 | 264 |
| 265 | 265 |
| 266 Handle<Value> Shell::Uint16Array(const Arguments& args) { | 266 Handle<Value> Shell::Uint16Array(const Arguments& args) { |
| 267 return CreateExternalArray(args, kExternalUnsignedShortArray, | 267 return CreateExternalArray(args, kExternalUnsignedShortArray, |
| 268 sizeof(uint16_t)); | 268 sizeof(uint16_t)); |
| 269 } | 269 } |
| 270 | 270 |
| 271 | |
| 271 Handle<Value> Shell::Int32Array(const Arguments& args) { | 272 Handle<Value> Shell::Int32Array(const Arguments& args) { |
| 272 return CreateExternalArray(args, kExternalIntArray, sizeof(int32_t)); | 273 return CreateExternalArray(args, kExternalIntArray, sizeof(int32_t)); |
| 273 } | 274 } |
| 274 | 275 |
| 275 | 276 |
| 276 Handle<Value> Shell::Uint32Array(const Arguments& args) { | 277 Handle<Value> Shell::Uint32Array(const Arguments& args) { |
| 277 return CreateExternalArray(args, kExternalUnsignedIntArray, sizeof(uint32_t)); | 278 return CreateExternalArray(args, kExternalUnsignedIntArray, sizeof(uint32_t)); |
| 278 } | 279 } |
| 279 | 280 |
| 280 | 281 |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 478 size_t buckets) { | 479 size_t buckets) { |
| 479 return GetCounter(name, true); | 480 return GetCounter(name, true); |
| 480 } | 481 } |
| 481 | 482 |
| 482 | 483 |
| 483 void Shell::AddHistogramSample(void* histogram, int sample) { | 484 void Shell::AddHistogramSample(void* histogram, int sample) { |
| 484 Counter* counter = reinterpret_cast<Counter*>(histogram); | 485 Counter* counter = reinterpret_cast<Counter*>(histogram); |
| 485 counter->AddSample(sample); | 486 counter->AddSample(sample); |
| 486 } | 487 } |
| 487 | 488 |
| 489 void Shell::InstallUtilScript() { | |
| 490 Locker lock; | |
| 491 HandleScope scope; | |
| 492 Context::Scope utility_scope(utility_context_); | |
| 493 // Run the d8 shell utility script in the utility context | |
| 494 int source_index = i::NativesCollection<i::D8>::GetIndex("d8"); | |
| 495 i::Vector<const char> shell_source = | |
| 496 i::NativesCollection<i::D8>::GetRawScriptSource(source_index); | |
| 497 i::Vector<const char> shell_source_name = | |
| 498 i::NativesCollection<i::D8>::GetScriptName(source_index); | |
| 499 Handle<String> source = String::New(shell_source.start(), | |
| 500 shell_source.length()); | |
| 501 Handle<String> name = String::New(shell_source_name.start(), | |
| 502 shell_source_name.length()); | |
| 503 Handle<Script> script = Script::Compile(source, name); | |
| 504 script->Run(); | |
| 505 } | |
| 488 | 506 |
| 489 #ifdef COMPRESS_STARTUP_DATA_BZ2 | 507 #ifdef COMPRESS_STARTUP_DATA_BZ2 |
| 490 class BZip2Decompressor : public v8::StartupDataDecompressor { | 508 class BZip2Decompressor : public v8::StartupDataDecompressor { |
| 491 public: | 509 public: |
| 492 virtual ~BZip2Decompressor() { } | 510 virtual ~BZip2Decompressor() { } |
| 493 | 511 |
| 494 protected: | 512 protected: |
| 495 virtual int DecompressData(char* raw_data, | 513 virtual int DecompressData(char* raw_data, |
| 496 int* raw_data_size, | 514 int* raw_data_size, |
| 497 const char* compressed_data, | 515 const char* compressed_data, |
| 498 int compressed_data_size) { | 516 int compressed_data_size) { |
| 499 ASSERT_EQ(v8::StartupData::kBZip2, | 517 ASSERT_EQ(v8::StartupData::kBZip2, |
| 500 v8::V8::GetCompressedStartupDataAlgorithm()); | 518 v8::V8::GetCompressedStartupDataAlgorithm()); |
| 501 unsigned int decompressed_size = *raw_data_size; | 519 unsigned int decompressed_size = *raw_data_size; |
| 502 int result = | 520 int result = |
| 503 BZ2_bzBuffToBuffDecompress(raw_data, | 521 BZ2_bzBuffToBuffDecompress(raw_data, |
| 504 &decompressed_size, | 522 &decompressed_size, |
| 505 const_cast<char*>(compressed_data), | 523 const_cast<char*>(compressed_data), |
| 506 compressed_data_size, | 524 compressed_data_size, |
| 507 0, 1); | 525 0, 1); |
| 508 if (result == BZ_OK) { | 526 if (result == BZ_OK) { |
| 509 *raw_data_size = decompressed_size; | 527 *raw_data_size = decompressed_size; |
| 510 } | 528 } |
| 511 return result; | 529 return result; |
| 512 } | 530 } |
| 513 }; | 531 }; |
| 514 #endif | 532 #endif |
| 515 | 533 |
| 516 | 534 Handle<ObjectTemplate> Shell::CreateGlobalTemplate() { |
| 517 void Shell::Initialize() { | |
| 518 #ifdef COMPRESS_STARTUP_DATA_BZ2 | |
| 519 BZip2Decompressor startup_data_decompressor; | |
| 520 int bz2_result = startup_data_decompressor.Decompress(); | |
| 521 if (bz2_result != BZ_OK) { | |
| 522 fprintf(stderr, "bzip error code: %d\n", bz2_result); | |
| 523 exit(1); | |
| 524 } | |
| 525 #endif | |
| 526 | |
| 527 Shell::counter_map_ = new CounterMap(); | |
| 528 // Set up counters | |
| 529 if (i::StrLength(i::FLAG_map_counters) != 0) | |
| 530 MapCounters(i::FLAG_map_counters); | |
| 531 if (i::FLAG_dump_counters) { | |
| 532 V8::SetCounterFunction(LookupCounter); | |
| 533 V8::SetCreateHistogramFunction(CreateHistogram); | |
| 534 V8::SetAddHistogramSampleFunction(AddHistogramSample); | |
| 535 } | |
| 536 | |
| 537 // Initialize the global objects | |
| 538 HandleScope scope; | |
| 539 Handle<ObjectTemplate> global_template = ObjectTemplate::New(); | 535 Handle<ObjectTemplate> global_template = ObjectTemplate::New(); |
| 540 global_template->Set(String::New("print"), FunctionTemplate::New(Print)); | 536 global_template->Set(String::New("print"), FunctionTemplate::New(Print)); |
| 541 global_template->Set(String::New("write"), FunctionTemplate::New(Write)); | 537 global_template->Set(String::New("write"), FunctionTemplate::New(Write)); |
| 542 global_template->Set(String::New("read"), FunctionTemplate::New(Read)); | 538 global_template->Set(String::New("read"), FunctionTemplate::New(Read)); |
| 543 global_template->Set(String::New("readline"), | 539 global_template->Set(String::New("readline"), |
| 544 FunctionTemplate::New(ReadLine)); | 540 FunctionTemplate::New(ReadLine)); |
| 545 global_template->Set(String::New("load"), FunctionTemplate::New(Load)); | 541 global_template->Set(String::New("load"), FunctionTemplate::New(Load)); |
| 546 global_template->Set(String::New("quit"), FunctionTemplate::New(Quit)); | 542 global_template->Set(String::New("quit"), FunctionTemplate::New(Quit)); |
| 547 global_template->Set(String::New("version"), FunctionTemplate::New(Version)); | 543 global_template->Set(String::New("version"), FunctionTemplate::New(Version)); |
| 548 | 544 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 564 global_template->Set(String::New("Float64Array"), | 560 global_template->Set(String::New("Float64Array"), |
| 565 FunctionTemplate::New(Float64Array)); | 561 FunctionTemplate::New(Float64Array)); |
| 566 global_template->Set(String::New("PixelArray"), | 562 global_template->Set(String::New("PixelArray"), |
| 567 FunctionTemplate::New(PixelArray)); | 563 FunctionTemplate::New(PixelArray)); |
| 568 | 564 |
| 569 #ifdef LIVE_OBJECT_LIST | 565 #ifdef LIVE_OBJECT_LIST |
| 570 global_template->Set(String::New("lol_is_enabled"), Boolean::New(true)); | 566 global_template->Set(String::New("lol_is_enabled"), Boolean::New(true)); |
| 571 #else | 567 #else |
| 572 global_template->Set(String::New("lol_is_enabled"), Boolean::New(false)); | 568 global_template->Set(String::New("lol_is_enabled"), Boolean::New(false)); |
| 573 #endif | 569 #endif |
| 570 return global_template; | |
| 571 } | |
| 572 | |
| 573 void Shell::Initialize() { | |
| 574 #ifdef COMPRESS_STARTUP_DATA_BZ2 | |
| 575 BZip2Decompressor startup_data_decompressor; | |
| 576 int bz2_result = startup_data_decompressor.Decompress(); | |
| 577 if (bz2_result != BZ_OK) { | |
| 578 fprintf(stderr, "bzip error code: %d\n", bz2_result); | |
| 579 exit(1); | |
| 580 } | |
| 581 #endif | |
| 582 | |
| 583 Shell::counter_map_ = new CounterMap(); | |
| 584 // Set up counters | |
| 585 if (i::StrLength(i::FLAG_map_counters) != 0) | |
| 586 MapCounters(i::FLAG_map_counters); | |
| 587 if (i::FLAG_dump_counters) { | |
| 588 V8::SetCounterFunction(LookupCounter); | |
| 589 V8::SetCreateHistogramFunction(CreateHistogram); | |
| 590 V8::SetAddHistogramSampleFunction(AddHistogramSample); | |
| 591 } | |
| 592 | |
| 593 // Initialize the global objects | |
| 594 HandleScope scope; | |
| 595 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(); | |
| 574 | 596 |
|
Søren Thygesen Gjesse
2011/06/09 12:36:04
Can the adding of the "os" object be part of the C
Yang
2011/06/09 13:00:40
yes
| |
| 575 Handle<ObjectTemplate> os_templ = ObjectTemplate::New(); | 597 Handle<ObjectTemplate> os_templ = ObjectTemplate::New(); |
| 576 AddOSMethods(os_templ); | 598 AddOSMethods(os_templ); |
| 577 global_template->Set(String::New("os"), os_templ); | 599 global_template->Set(String::New("os"), os_templ); |
| 578 | 600 |
| 579 utility_context_ = Context::New(NULL, global_template); | 601 utility_context_ = Context::New(NULL, global_template); |
| 580 utility_context_->SetSecurityToken(Undefined()); | 602 utility_context_->SetSecurityToken(Undefined()); |
| 581 Context::Scope utility_scope(utility_context_); | 603 Context::Scope utility_scope(utility_context_); |
| 582 | 604 |
|
Søren Thygesen Gjesse
2011/06/09 12:36:04
Also can adding the arguments be part of CreateGlo
Yang
2011/06/09 13:00:40
I tried that. this would lead to crashes somehow.
| |
| 583 i::JSArguments js_args = i::FLAG_js_arguments; | 605 i::JSArguments js_args = i::FLAG_js_arguments; |
| 584 i::Handle<i::FixedArray> arguments_array = | 606 i::Handle<i::FixedArray> arguments_array = |
| 585 FACTORY->NewFixedArray(js_args.argc()); | 607 FACTORY->NewFixedArray(js_args.argc()); |
| 586 for (int j = 0; j < js_args.argc(); j++) { | 608 for (int j = 0; j < js_args.argc(); j++) { |
| 587 i::Handle<i::String> arg = | 609 i::Handle<i::String> arg = |
| 588 FACTORY->NewStringFromUtf8(i::CStrVector(js_args[j])); | 610 FACTORY->NewStringFromUtf8(i::CStrVector(js_args[j])); |
| 589 arguments_array->set(j, *arg); | 611 arguments_array->set(j, *arg); |
| 590 } | 612 } |
| 591 i::Handle<i::JSArray> arguments_jsarray = | 613 i::Handle<i::JSArray> arguments_jsarray = |
| 592 FACTORY->NewJSArrayWithElements(arguments_array); | 614 FACTORY->NewJSArrayWithElements(arguments_array); |
| 593 global_template->Set(String::New("arguments"), | 615 global_template->Set(String::New("arguments"), |
| 594 Utils::ToLocal(arguments_jsarray)); | 616 Utils::ToLocal(arguments_jsarray)); |
| 595 | 617 |
| 596 #ifdef ENABLE_DEBUGGER_SUPPORT | 618 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 597 // Install the debugger object in the utility scope | 619 // Install the debugger object in the utility scope |
| 598 i::Debug* debug = i::Isolate::Current()->debug(); | 620 i::Debug* debug = i::Isolate::Current()->debug(); |
| 599 debug->Load(); | 621 debug->Load(); |
| 600 i::Handle<i::JSObject> js_debug | 622 i::Handle<i::JSObject> js_debug |
| 601 = i::Handle<i::JSObject>(debug->debug_context()->global()); | 623 = i::Handle<i::JSObject>(debug->debug_context()->global()); |
| 602 utility_context_->Global()->Set(String::New("$debug"), | 624 utility_context_->Global()->Set(String::New("$debug"), |
| 603 Utils::ToLocal(js_debug)); | 625 Utils::ToLocal(js_debug)); |
| 604 #endif | 626 #endif |
| 627 } | |
| 605 | 628 |
| 606 // Run the d8 shell utility script in the utility context | |
| 607 int source_index = i::NativesCollection<i::D8>::GetIndex("d8"); | |
| 608 i::Vector<const char> shell_source | |
| 609 = i::NativesCollection<i::D8>::GetRawScriptSource(source_index); | |
| 610 i::Vector<const char> shell_source_name | |
| 611 = i::NativesCollection<i::D8>::GetScriptName(source_index); | |
| 612 Handle<String> source = String::New(shell_source.start(), | |
| 613 shell_source.length()); | |
| 614 Handle<String> name = String::New(shell_source_name.start(), | |
| 615 shell_source_name.length()); | |
| 616 Handle<Script> script = Script::Compile(source, name); | |
| 617 script->Run(); | |
| 618 | 629 |
| 619 // Mark the d8 shell script as native to avoid it showing up as normal source | 630 void Shell::RenewEvalContext() { |
|
Søren Thygesen Gjesse
2011/06/09 12:36:04
Is this last part of the installation of the utili
Yang
2011/06/09 13:00:40
Indeed. Must have gotten lost when I moved the cod
| |
| 620 // in the debugger. | 631 // Initialize the global objects |
| 621 i::Handle<i::Object> compiled_script = Utils::OpenHandle(*script); | 632 HandleScope scope; |
| 622 i::Handle<i::Script> script_object = compiled_script->IsJSFunction() | 633 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(); |
| 623 ? i::Handle<i::Script>(i::Script::cast( | |
| 624 i::JSFunction::cast(*compiled_script)->shared()->script())) | |
| 625 : i::Handle<i::Script>(i::Script::cast( | |
| 626 i::SharedFunctionInfo::cast(*compiled_script)->script())); | |
| 627 script_object->set_type(i::Smi::FromInt(i::Script::TYPE_NATIVE)); | |
| 628 | 634 |
| 629 // Create the evaluation context | 635 // (Re-)create the evaluation context |
| 636 if (!evaluation_context_.IsEmpty()) { | |
| 637 evaluation_context_.Dispose(); | |
| 638 } | |
| 630 evaluation_context_ = Context::New(NULL, global_template); | 639 evaluation_context_ = Context::New(NULL, global_template); |
| 631 evaluation_context_->SetSecurityToken(Undefined()); | 640 evaluation_context_->SetSecurityToken(Undefined()); |
| 632 | 641 |
| 633 #ifdef ENABLE_DEBUGGER_SUPPORT | 642 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 643 i::Debug* debug = i::Isolate::Current()->debug(); | |
| 644 debug->Load(); | |
| 645 | |
| 634 // Set the security token of the debug context to allow access. | 646 // Set the security token of the debug context to allow access. |
| 635 debug->debug_context()->set_security_token(HEAP->undefined_value()); | 647 debug->debug_context()->set_security_token(HEAP->undefined_value()); |
| 636 | 648 |
| 637 // Start the debugger agent if requested. | 649 // Start the debugger agent if requested. |
| 638 if (i::FLAG_debugger_agent) { | 650 if (i::FLAG_debugger_agent) { |
| 639 v8::Debug::EnableAgent("d8 shell", i::FLAG_debugger_port, true); | 651 v8::Debug::EnableAgent("d8 shell", i::FLAG_debugger_port, true); |
| 640 } | 652 } |
| 641 | 653 |
| 642 // Start the in-process debugger if requested. | 654 // Start the in-process debugger if requested. |
| 643 if (i::FLAG_debugger && !i::FLAG_debugger_agent) { | 655 if (i::FLAG_debugger && !i::FLAG_debugger_agent) { |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 755 private: | 767 private: |
| 756 int no_; | 768 int no_; |
| 757 i::Vector<const char> files_; | 769 i::Vector<const char> files_; |
| 758 }; | 770 }; |
| 759 | 771 |
| 760 | 772 |
| 761 void ShellThread::Run() { | 773 void ShellThread::Run() { |
| 762 // Prepare the context for this thread. | 774 // Prepare the context for this thread. |
| 763 Locker locker; | 775 Locker locker; |
| 764 HandleScope scope; | 776 HandleScope scope; |
| 765 Handle<ObjectTemplate> global_template = ObjectTemplate::New(); | 777 Handle<ObjectTemplate> global_template = Shell::CreateGlobalTemplate(); |
| 766 global_template->Set(String::New("print"), | |
| 767 FunctionTemplate::New(Shell::Print)); | |
| 768 global_template->Set(String::New("write"), | |
| 769 FunctionTemplate::New(Shell::Write)); | |
| 770 global_template->Set(String::New("read"), | |
| 771 FunctionTemplate::New(Shell::Read)); | |
| 772 global_template->Set(String::New("readline"), | |
| 773 FunctionTemplate::New(Shell::ReadLine)); | |
| 774 global_template->Set(String::New("load"), | |
| 775 FunctionTemplate::New(Shell::Load)); | |
| 776 global_template->Set(String::New("yield"), | |
| 777 FunctionTemplate::New(Shell::Yield)); | |
| 778 global_template->Set(String::New("version"), | |
| 779 FunctionTemplate::New(Shell::Version)); | |
| 780 | 778 |
| 781 char* ptr = const_cast<char*>(files_.start()); | 779 char* ptr = const_cast<char*> (files_.start()); |
| 782 while ((ptr != NULL) && (*ptr != '\0')) { | 780 while ((ptr != NULL) && (*ptr != '\0')) { |
| 783 // For each newline-separated line. | 781 // For each newline-separated line. |
| 784 char* next_line = ReadLine(ptr); | 782 char* next_line = ReadLine(ptr); |
| 785 | 783 |
| 786 if (*ptr == '#') { | 784 if (*ptr == '#') { |
| 787 // Skip comment lines. | 785 // Skip comment lines. |
| 788 ptr = next_line; | 786 ptr = next_line; |
| 789 continue; | 787 continue; |
| 790 } | 788 } |
| 791 | 789 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 809 } | 807 } |
| 810 | 808 |
| 811 Shell::ExecuteString(str, String::New(filename), false, false); | 809 Shell::ExecuteString(str, String::New(filename), false, false); |
| 812 } | 810 } |
| 813 | 811 |
| 814 thread_context.Dispose(); | 812 thread_context.Dispose(); |
| 815 ptr = next_line; | 813 ptr = next_line; |
| 816 } | 814 } |
| 817 } | 815 } |
| 818 | 816 |
| 819 | 817 int Shell::RunMain(int argc, char* argv[]) { |
| 820 int Shell::Main(int argc, char* argv[]) { | |
| 821 i::FlagList::SetFlagsFromCommandLine(&argc, argv, true); | |
| 822 if (i::FLAG_help) { | |
| 823 return 1; | |
| 824 } | |
| 825 Initialize(); | |
| 826 bool run_shell = (argc == 1); | |
| 827 | 818 |
| 828 // Default use preemption if threads are created. | 819 // Default use preemption if threads are created. |
| 829 bool use_preemption = true; | 820 bool use_preemption = true; |
| 830 | 821 |
| 831 // Default to use lowest possible thread preemption interval to test as many | 822 // Default to use lowest possible thread preemption interval to test as many |
| 832 // edgecases as possible. | 823 // edgecases as possible. |
| 833 int preemption_interval = 1; | 824 int preemption_interval = 1; |
| 834 | 825 |
| 835 i::List<i::Thread*> threads(1); | 826 i::List<i::Thread*> threads(1); |
| 836 | 827 |
| 837 { | 828 { |
| 838 // Acquire the V8 lock once initialization has finished. Since the thread | 829 // Since the thread below may spawn new threads accessing V8 holding the |
| 839 // below may spawn new threads accessing V8 holding the V8 lock here is | 830 // V8 lock here is mandatory. |
| 840 // mandatory. | |
| 841 Locker locker; | 831 Locker locker; |
| 832 RenewEvalContext(); | |
| 842 Context::Scope context_scope(evaluation_context_); | 833 Context::Scope context_scope(evaluation_context_); |
| 843 for (int i = 1; i < argc; i++) { | 834 for (int i = 1; i < argc; i++) { |
| 844 char* str = argv[i]; | 835 char* str = argv[i]; |
| 845 if (strcmp(str, "--shell") == 0) { | 836 if (strcmp(str, "--preemption") == 0) { |
| 846 run_shell = true; | |
| 847 } else if (strcmp(str, "--preemption") == 0) { | |
| 848 use_preemption = true; | 837 use_preemption = true; |
| 849 } else if (strcmp(str, "--no-preemption") == 0) { | 838 } else if (strcmp(str, "--no-preemption") == 0) { |
| 850 use_preemption = false; | 839 use_preemption = false; |
| 851 } else if (strcmp(str, "--preemption-interval") == 0) { | 840 } else if (strcmp(str, "--preemption-interval") == 0) { |
| 852 if (i + 1 < argc) { | 841 if (i + 1 < argc) { |
| 853 char* end = NULL; | 842 char* end = NULL; |
| 854 preemption_interval = strtol(argv[++i], &end, 10); // NOLINT | 843 preemption_interval = strtol(argv[++i], &end, 10); // NOLINT |
| 855 if (preemption_interval <= 0 || *end != '\0' || errno == ERANGE) { | 844 if (preemption_interval <= 0 || *end != '\0' || errno == ERANGE) { |
| 856 printf("Invalid value for --preemption-interval '%s'\n", argv[i]); | 845 printf("Invalid value for --preemption-interval '%s'\n", argv[i]); |
| 857 return 1; | 846 return 1; |
| 858 } | 847 } |
| 859 } else { | 848 } else { |
| 860 printf("Missing value for --preemption-interval\n"); | 849 printf("Missing value for --preemption-interval\n"); |
| 861 return 1; | 850 return 1; |
| 862 } | 851 } |
| 863 } else if (strcmp(str, "-f") == 0) { | 852 } else if (strcmp(str, "-f") == 0) { |
| 864 // Ignore any -f flags for compatibility with other stand-alone | 853 // Ignore any -f flags for compatibility with other stand-alone |
| 865 // JavaScript engines. | 854 // JavaScript engines. |
| 866 continue; | 855 continue; |
| 867 } else if (strncmp(str, "--", 2) == 0) { | 856 } else if (strncmp(str, "--", 2) == 0) { |
| 868 printf("Warning: unknown flag %s.\nTry --help for options\n", str); | 857 printf("Warning: unknown flag %s.\nTry --help for options\n", str); |
| 869 } else if (strcmp(str, "-e") == 0 && i + 1 < argc) { | 858 } else if (strcmp(str, "-e") == 0 && i + 1 < argc) { |
| 870 // Execute argument given to -e option directly. | 859 // Execute argument given to -e option directly. |
| 871 v8::HandleScope handle_scope; | 860 v8::HandleScope handle_scope; |
| 872 v8::Handle<v8::String> file_name = v8::String::New("unnamed"); | 861 v8::Handle<v8::String> file_name = v8::String::New("unnamed"); |
| 873 v8::Handle<v8::String> source = v8::String::New(argv[i + 1]); | 862 v8::Handle<v8::String> source = v8::String::New(argv[++i]); |
| 874 if (!ExecuteString(source, file_name, false, true)) { | 863 if (!ExecuteString(source, file_name, false, true)) { |
| 875 OnExit(); | 864 OnExit(); |
| 876 return 1; | 865 return 1; |
| 877 } | 866 } |
| 878 i++; | |
| 879 } else if (strcmp(str, "-p") == 0 && i + 1 < argc) { | 867 } else if (strcmp(str, "-p") == 0 && i + 1 < argc) { |
| 880 int size = 0; | 868 int size = 0; |
| 881 const char* files = ReadChars(argv[++i], &size); | 869 const char* files = ReadChars(argv[++i], &size); |
| 882 if (files == NULL) return 1; | 870 if (files == NULL) return 1; |
| 883 ShellThread* thread = | 871 ShellThread* thread = |
| 884 new ShellThread(i::Isolate::Current(), | 872 new ShellThread(i::Isolate::Current(), |
| 885 threads.length(), | 873 threads.length(), |
| 886 i::Vector<const char>(files, size)); | 874 i::Vector<const char>(files, size)); |
| 887 thread->Start(); | 875 thread->Start(); |
| 888 threads.Add(thread); | 876 threads.Add(thread); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 900 return 1; | 888 return 1; |
| 901 } | 889 } |
| 902 } | 890 } |
| 903 } | 891 } |
| 904 | 892 |
| 905 // Start preemption if threads have been created and preemption is enabled. | 893 // Start preemption if threads have been created and preemption is enabled. |
| 906 if (threads.length() > 0 && use_preemption) { | 894 if (threads.length() > 0 && use_preemption) { |
| 907 Locker::StartPreemption(preemption_interval); | 895 Locker::StartPreemption(preemption_interval); |
| 908 } | 896 } |
| 909 | 897 |
| 910 #ifdef ENABLE_DEBUGGER_SUPPORT | |
| 911 // Run the remote debugger if requested. | |
| 912 if (i::FLAG_remote_debugger) { | |
| 913 RunRemoteDebugger(i::FLAG_debugger_port); | |
| 914 return 0; | |
| 915 } | |
| 916 #endif | |
| 917 } | 898 } |
| 918 if (run_shell) | 899 |
| 919 RunShell(); | |
| 920 for (int i = 0; i < threads.length(); i++) { | 900 for (int i = 0; i < threads.length(); i++) { |
| 921 i::Thread* thread = threads[i]; | 901 i::Thread* thread = threads[i]; |
| 922 thread->Join(); | 902 thread->Join(); |
| 923 delete thread; | 903 delete thread; |
| 924 } | 904 } |
| 925 OnExit(); | 905 OnExit(); |
| 926 return 0; | 906 return 0; |
| 927 } | 907 } |
| 928 | 908 |
| 929 | 909 |
| 930 } // namespace v8 | 910 int Shell::Main(int argc, char* argv[]) { |
| 911 // Figure out if we're requested to stress the optimization | |
| 912 // infrastructure by running tests multiple times and forcing | |
| 913 // optimization in the last run. | |
| 914 bool FLAG_stress_opt = false; | |
| 915 bool FLAG_stress_deopt = false; | |
| 916 bool run_shell = (argc == 1); | |
| 917 | |
| 918 for (int i = 0; i < argc; i++) { | |
| 919 if (strcmp(argv[i], "--stress-opt") == 0) { | |
| 920 FLAG_stress_opt = true; | |
| 921 argv[i] = NULL; | |
| 922 } else if (strcmp(argv[i], "--stress-deopt") == 0) { | |
| 923 FLAG_stress_deopt = true; | |
| 924 argv[i] = NULL; | |
| 925 } else if (strcmp(argv[i], "--noalways-opt") == 0) { | |
| 926 // No support for stressing if we can't use --always-opt. | |
| 927 FLAG_stress_opt = false; | |
| 928 FLAG_stress_deopt = false; | |
| 929 } else if (strcmp(argv[i], "--shell") == 0) { | |
| 930 run_shell = true; | |
| 931 argv[i] = NULL; | |
| 932 } | |
| 933 } | |
| 934 | |
| 935 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); | |
| 936 | |
| 937 Initialize(); | |
| 938 | |
| 939 int result = 0; | |
| 940 if (FLAG_stress_opt || FLAG_stress_deopt) { | |
| 941 v8::Testing::SetStressRunType( | |
| 942 FLAG_stress_opt ? v8::Testing::kStressTypeOpt | |
| 943 : v8::Testing::kStressTypeDeopt); | |
| 944 int stress_runs = v8::Testing::GetStressRuns(); | |
| 945 for (int i = 0; i < stress_runs && result == 0; i++) { | |
| 946 printf("============ Stress %d/%d ============\n", i + 1, stress_runs); | |
| 947 v8::Testing::PrepareStressRun(i); | |
| 948 result = RunMain(argc, argv); | |
| 949 } | |
| 950 printf("======== Full Deoptimization =======\n"); | |
| 951 v8::Testing::DeoptimizeAll(); | |
| 952 } else { | |
| 953 result = RunMain(argc, argv); | |
| 954 } | |
| 955 | |
| 956 #ifdef ENABLE_DEBUGGER_SUPPORT | |
| 957 if (i::FLAG_remote_debugger) { | |
| 958 RunRemoteDebugger(i::FLAG_debugger_port); | |
| 959 return 0; | |
| 960 } | |
| 961 #endif | |
| 962 | |
| 963 if (run_shell) { | |
| 964 InstallUtilScript(); | |
| 965 RunShell(); | |
| 966 } | |
| 967 | |
| 968 v8::V8::Dispose(); | |
| 969 | |
| 970 return result; | |
| 971 | |
| 972 } | |
| 973 | |
| 974 } // namespace v8 | |
| 931 | 975 |
| 932 | 976 |
| 933 #ifndef GOOGLE3 | 977 #ifndef GOOGLE3 |
| 934 int main(int argc, char* argv[]) { | 978 int main(int argc, char* argv[]) { |
| 935 return v8::Shell::Main(argc, argv); | 979 return v8::Shell::Main(argc, argv); |
| 936 } | 980 } |
| 937 #endif | 981 #endif |
| OLD | NEW |