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

Side by Side Diff: src/d8.cc

Issue 7134040: added --stress-opt option to d8 (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: included suggestions Created 9 years, 6 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
« no previous file with comments | « src/d8.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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::InstallUtilityScript() {
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
506 // Mark the d8 shell script as native to avoid it showing up as normal source
507 // in the debugger.
508 i::Handle<i::Object> compiled_script = Utils::OpenHandle(*script);
509 i::Handle<i::Script> script_object = compiled_script->IsJSFunction()
510 ? i::Handle<i::Script>(i::Script::cast(
511 i::JSFunction::cast(*compiled_script)->shared()->script()))
512 : i::Handle<i::Script>(i::Script::cast(
513 i::SharedFunctionInfo::cast(*compiled_script)->script()));
514 script_object->set_type(i::Smi::FromInt(i::Script::TYPE_NATIVE));
515 }
488 516
489 #ifdef COMPRESS_STARTUP_DATA_BZ2 517 #ifdef COMPRESS_STARTUP_DATA_BZ2
490 class BZip2Decompressor : public v8::StartupDataDecompressor { 518 class BZip2Decompressor : public v8::StartupDataDecompressor {
491 public: 519 public:
492 virtual ~BZip2Decompressor() { } 520 virtual ~BZip2Decompressor() { }
493 521
494 protected: 522 protected:
495 virtual int DecompressData(char* raw_data, 523 virtual int DecompressData(char* raw_data,
496 int* raw_data_size, 524 int* raw_data_size,
497 const char* compressed_data, 525 const char* compressed_data,
498 int compressed_data_size) { 526 int compressed_data_size) {
499 ASSERT_EQ(v8::StartupData::kBZip2, 527 ASSERT_EQ(v8::StartupData::kBZip2,
500 v8::V8::GetCompressedStartupDataAlgorithm()); 528 v8::V8::GetCompressedStartupDataAlgorithm());
501 unsigned int decompressed_size = *raw_data_size; 529 unsigned int decompressed_size = *raw_data_size;
502 int result = 530 int result =
503 BZ2_bzBuffToBuffDecompress(raw_data, 531 BZ2_bzBuffToBuffDecompress(raw_data,
504 &decompressed_size, 532 &decompressed_size,
505 const_cast<char*>(compressed_data), 533 const_cast<char*>(compressed_data),
506 compressed_data_size, 534 compressed_data_size,
507 0, 1); 535 0, 1);
508 if (result == BZ_OK) { 536 if (result == BZ_OK) {
509 *raw_data_size = decompressed_size; 537 *raw_data_size = decompressed_size;
510 } 538 }
511 return result; 539 return result;
512 } 540 }
513 }; 541 };
514 #endif 542 #endif
515 543
516 544 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(); 545 Handle<ObjectTemplate> global_template = ObjectTemplate::New();
540 global_template->Set(String::New("print"), FunctionTemplate::New(Print)); 546 global_template->Set(String::New("print"), FunctionTemplate::New(Print));
541 global_template->Set(String::New("write"), FunctionTemplate::New(Write)); 547 global_template->Set(String::New("write"), FunctionTemplate::New(Write));
542 global_template->Set(String::New("read"), FunctionTemplate::New(Read)); 548 global_template->Set(String::New("read"), FunctionTemplate::New(Read));
543 global_template->Set(String::New("readline"), 549 global_template->Set(String::New("readline"),
544 FunctionTemplate::New(ReadLine)); 550 FunctionTemplate::New(ReadLine));
545 global_template->Set(String::New("load"), FunctionTemplate::New(Load)); 551 global_template->Set(String::New("load"), FunctionTemplate::New(Load));
546 global_template->Set(String::New("quit"), FunctionTemplate::New(Quit)); 552 global_template->Set(String::New("quit"), FunctionTemplate::New(Quit));
547 global_template->Set(String::New("version"), FunctionTemplate::New(Version)); 553 global_template->Set(String::New("version"), FunctionTemplate::New(Version));
548 554
(...skipping 20 matching lines...) Expand all
569 #ifdef LIVE_OBJECT_LIST 575 #ifdef LIVE_OBJECT_LIST
570 global_template->Set(String::New("lol_is_enabled"), Boolean::New(true)); 576 global_template->Set(String::New("lol_is_enabled"), Boolean::New(true));
571 #else 577 #else
572 global_template->Set(String::New("lol_is_enabled"), Boolean::New(false)); 578 global_template->Set(String::New("lol_is_enabled"), Boolean::New(false));
573 #endif 579 #endif
574 580
575 Handle<ObjectTemplate> os_templ = ObjectTemplate::New(); 581 Handle<ObjectTemplate> os_templ = ObjectTemplate::New();
576 AddOSMethods(os_templ); 582 AddOSMethods(os_templ);
577 global_template->Set(String::New("os"), os_templ); 583 global_template->Set(String::New("os"), os_templ);
578 584
585 return global_template;
586 }
587
588 void Shell::Initialize() {
589 #ifdef COMPRESS_STARTUP_DATA_BZ2
590 BZip2Decompressor startup_data_decompressor;
591 int bz2_result = startup_data_decompressor.Decompress();
592 if (bz2_result != BZ_OK) {
593 fprintf(stderr, "bzip error code: %d\n", bz2_result);
594 exit(1);
595 }
596 #endif
597
598 Shell::counter_map_ = new CounterMap();
599 // Set up counters
600 if (i::StrLength(i::FLAG_map_counters) != 0)
601 MapCounters(i::FLAG_map_counters);
602 if (i::FLAG_dump_counters) {
603 V8::SetCounterFunction(LookupCounter);
604 V8::SetCreateHistogramFunction(CreateHistogram);
605 V8::SetAddHistogramSampleFunction(AddHistogramSample);
606 }
607
608 // Initialize the global objects
609 HandleScope scope;
610 Handle<ObjectTemplate> global_template = CreateGlobalTemplate();
611
579 utility_context_ = Context::New(NULL, global_template); 612 utility_context_ = Context::New(NULL, global_template);
580 utility_context_->SetSecurityToken(Undefined()); 613 utility_context_->SetSecurityToken(Undefined());
581 Context::Scope utility_scope(utility_context_); 614 Context::Scope utility_scope(utility_context_);
582 615
583 i::JSArguments js_args = i::FLAG_js_arguments; 616 i::JSArguments js_args = i::FLAG_js_arguments;
584 i::Handle<i::FixedArray> arguments_array = 617 i::Handle<i::FixedArray> arguments_array =
585 FACTORY->NewFixedArray(js_args.argc()); 618 FACTORY->NewFixedArray(js_args.argc());
586 for (int j = 0; j < js_args.argc(); j++) { 619 for (int j = 0; j < js_args.argc(); j++) {
Søren Thygesen Gjesse 2011/06/09 13:16:18 Something happened to the intention here.
587 i::Handle<i::String> arg = 620 i::Handle<i::String> arg =
588 FACTORY->NewStringFromUtf8(i::CStrVector(js_args[j])); 621 FACTORY->NewStringFromUtf8(i::CStrVector(js_args[j]));
589 arguments_array->set(j, *arg); 622 arguments_array->set(j, *arg);
590 } 623 }
591 i::Handle<i::JSArray> arguments_jsarray = 624 i::Handle<i::JSArray> arguments_jsarray =
Søren Thygesen Gjesse 2011/06/09 13:16:18 Ditto.
592 FACTORY->NewJSArrayWithElements(arguments_array); 625 FACTORY->NewJSArrayWithElements(arguments_array);
593 global_template->Set(String::New("arguments"), 626 global_template->Set(String::New("arguments"),
Søren Thygesen Gjesse 2011/06/09 13:16:18 Ditto.
594 Utils::ToLocal(arguments_jsarray)); 627 Utils::ToLocal(arguments_jsarray));
595 628
596 #ifdef ENABLE_DEBUGGER_SUPPORT 629 #ifdef ENABLE_DEBUGGER_SUPPORT
597 // Install the debugger object in the utility scope 630 // Install the debugger object in the utility scope
598 i::Debug* debug = i::Isolate::Current()->debug(); 631 i::Debug* debug = i::Isolate::Current()->debug();
599 debug->Load(); 632 debug->Load();
600 i::Handle<i::JSObject> js_debug 633 i::Handle<i::JSObject> js_debug
601 = i::Handle<i::JSObject>(debug->debug_context()->global()); 634 = i::Handle<i::JSObject>(debug->debug_context()->global());
602 utility_context_->Global()->Set(String::New("$debug"), 635 utility_context_->Global()->Set(String::New("$debug"),
603 Utils::ToLocal(js_debug)); 636 Utils::ToLocal(js_debug));
604 #endif 637 #endif
638 }
605 639
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 640
619 // Mark the d8 shell script as native to avoid it showing up as normal source 641 void Shell::RenewEvaluationContext() {
620 // in the debugger. 642 // Initialize the global objects
621 i::Handle<i::Object> compiled_script = Utils::OpenHandle(*script); 643 HandleScope scope;
622 i::Handle<i::Script> script_object = compiled_script->IsJSFunction() 644 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 645
629 // Create the evaluation context 646 // (Re-)create the evaluation context
647 if (!evaluation_context_.IsEmpty()) {
648 evaluation_context_.Dispose();
649 }
630 evaluation_context_ = Context::New(NULL, global_template); 650 evaluation_context_ = Context::New(NULL, global_template);
631 evaluation_context_->SetSecurityToken(Undefined()); 651 evaluation_context_->SetSecurityToken(Undefined());
632 652
633 #ifdef ENABLE_DEBUGGER_SUPPORT 653 #ifdef ENABLE_DEBUGGER_SUPPORT
654 i::Debug* debug = i::Isolate::Current()->debug();
655 debug->Load();
656
634 // Set the security token of the debug context to allow access. 657 // Set the security token of the debug context to allow access.
635 debug->debug_context()->set_security_token(HEAP->undefined_value()); 658 debug->debug_context()->set_security_token(HEAP->undefined_value());
636 659
637 // Start the debugger agent if requested. 660 // Start the debugger agent if requested.
638 if (i::FLAG_debugger_agent) { 661 if (i::FLAG_debugger_agent) {
639 v8::Debug::EnableAgent("d8 shell", i::FLAG_debugger_port, true); 662 v8::Debug::EnableAgent("d8 shell", i::FLAG_debugger_port, true);
640 } 663 }
641 664
642 // Start the in-process debugger if requested. 665 // Start the in-process debugger if requested.
643 if (i::FLAG_debugger && !i::FLAG_debugger_agent) { 666 if (i::FLAG_debugger && !i::FLAG_debugger_agent) {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 private: 778 private:
756 int no_; 779 int no_;
757 i::Vector<const char> files_; 780 i::Vector<const char> files_;
758 }; 781 };
759 782
760 783
761 void ShellThread::Run() { 784 void ShellThread::Run() {
762 // Prepare the context for this thread. 785 // Prepare the context for this thread.
763 Locker locker; 786 Locker locker;
764 HandleScope scope; 787 HandleScope scope;
765 Handle<ObjectTemplate> global_template = ObjectTemplate::New(); 788 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 789
781 char* ptr = const_cast<char*>(files_.start()); 790 char* ptr = const_cast<char*> (files_.start());
782 while ((ptr != NULL) && (*ptr != '\0')) { 791 while ((ptr != NULL) && (*ptr != '\0')) {
783 // For each newline-separated line. 792 // For each newline-separated line.
784 char* next_line = ReadLine(ptr); 793 char* next_line = ReadLine(ptr);
785 794
786 if (*ptr == '#') { 795 if (*ptr == '#') {
787 // Skip comment lines. 796 // Skip comment lines.
788 ptr = next_line; 797 ptr = next_line;
789 continue; 798 continue;
790 } 799 }
791 800
(...skipping 17 matching lines...) Expand all
809 } 818 }
810 819
811 Shell::ExecuteString(str, String::New(filename), false, false); 820 Shell::ExecuteString(str, String::New(filename), false, false);
812 } 821 }
813 822
814 thread_context.Dispose(); 823 thread_context.Dispose();
815 ptr = next_line; 824 ptr = next_line;
816 } 825 }
817 } 826 }
818 827
819 828 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
828 // Default use preemption if threads are created. 829 // Default use preemption if threads are created.
829 bool use_preemption = true; 830 bool use_preemption = true;
830 831
831 // Default to use lowest possible thread preemption interval to test as many 832 // Default to use lowest possible thread preemption interval to test as many
832 // edgecases as possible. 833 // edgecases as possible.
833 int preemption_interval = 1; 834 int preemption_interval = 1;
834 835
835 i::List<i::Thread*> threads(1); 836 i::List<i::Thread*> threads(1);
836 837
837 { 838 {
838 // Acquire the V8 lock once initialization has finished. Since the thread 839 // 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 840 // V8 lock here is mandatory.
840 // mandatory.
841 Locker locker; 841 Locker locker;
842 RenewEvaluationContext();
842 Context::Scope context_scope(evaluation_context_); 843 Context::Scope context_scope(evaluation_context_);
843 for (int i = 1; i < argc; i++) { 844 for (int i = 1; i < argc; i++) {
844 char* str = argv[i]; 845 char* str = argv[i];
845 if (strcmp(str, "--shell") == 0) { 846 if (strcmp(str, "--preemption") == 0) {
846 run_shell = true;
847 } else if (strcmp(str, "--preemption") == 0) {
848 use_preemption = true; 847 use_preemption = true;
849 } else if (strcmp(str, "--no-preemption") == 0) { 848 } else if (strcmp(str, "--no-preemption") == 0) {
850 use_preemption = false; 849 use_preemption = false;
851 } else if (strcmp(str, "--preemption-interval") == 0) { 850 } else if (strcmp(str, "--preemption-interval") == 0) {
852 if (i + 1 < argc) { 851 if (i + 1 < argc) {
853 char* end = NULL; 852 char* end = NULL;
854 preemption_interval = strtol(argv[++i], &end, 10); // NOLINT 853 preemption_interval = strtol(argv[++i], &end, 10); // NOLINT
855 if (preemption_interval <= 0 || *end != '\0' || errno == ERANGE) { 854 if (preemption_interval <= 0 || *end != '\0' || errno == ERANGE) {
856 printf("Invalid value for --preemption-interval '%s'\n", argv[i]); 855 printf("Invalid value for --preemption-interval '%s'\n", argv[i]);
857 return 1; 856 return 1;
858 } 857 }
859 } else { 858 } else {
860 printf("Missing value for --preemption-interval\n"); 859 printf("Missing value for --preemption-interval\n");
861 return 1; 860 return 1;
862 } 861 }
863 } else if (strcmp(str, "-f") == 0) { 862 } else if (strcmp(str, "-f") == 0) {
864 // Ignore any -f flags for compatibility with other stand-alone 863 // Ignore any -f flags for compatibility with other stand-alone
865 // JavaScript engines. 864 // JavaScript engines.
866 continue; 865 continue;
867 } else if (strncmp(str, "--", 2) == 0) { 866 } else if (strncmp(str, "--", 2) == 0) {
868 printf("Warning: unknown flag %s.\nTry --help for options\n", str); 867 printf("Warning: unknown flag %s.\nTry --help for options\n", str);
869 } else if (strcmp(str, "-e") == 0 && i + 1 < argc) { 868 } else if (strcmp(str, "-e") == 0 && i + 1 < argc) {
870 // Execute argument given to -e option directly. 869 // Execute argument given to -e option directly.
871 v8::HandleScope handle_scope; 870 v8::HandleScope handle_scope;
872 v8::Handle<v8::String> file_name = v8::String::New("unnamed"); 871 v8::Handle<v8::String> file_name = v8::String::New("unnamed");
873 v8::Handle<v8::String> source = v8::String::New(argv[i + 1]); 872 v8::Handle<v8::String> source = v8::String::New(argv[++i]);
874 if (!ExecuteString(source, file_name, false, true)) { 873 if (!ExecuteString(source, file_name, false, true)) {
875 OnExit(); 874 OnExit();
876 return 1; 875 return 1;
877 } 876 }
878 i++;
879 } else if (strcmp(str, "-p") == 0 && i + 1 < argc) { 877 } else if (strcmp(str, "-p") == 0 && i + 1 < argc) {
880 int size = 0; 878 int size = 0;
881 const char* files = ReadChars(argv[++i], &size); 879 const char* files = ReadChars(argv[++i], &size);
882 if (files == NULL) return 1; 880 if (files == NULL) return 1;
883 ShellThread* thread = 881 ShellThread* thread =
884 new ShellThread(i::Isolate::Current(), 882 new ShellThread(i::Isolate::Current(),
885 threads.length(), 883 threads.length(),
886 i::Vector<const char>(files, size)); 884 i::Vector<const char>(files, size));
887 thread->Start(); 885 thread->Start();
888 threads.Add(thread); 886 threads.Add(thread);
(...skipping 11 matching lines...) Expand all
900 return 1; 898 return 1;
901 } 899 }
902 } 900 }
903 } 901 }
904 902
905 // Start preemption if threads have been created and preemption is enabled. 903 // Start preemption if threads have been created and preemption is enabled.
906 if (threads.length() > 0 && use_preemption) { 904 if (threads.length() > 0 && use_preemption) {
907 Locker::StartPreemption(preemption_interval); 905 Locker::StartPreemption(preemption_interval);
908 } 906 }
909 907
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 } 908 }
918 if (run_shell) 909
919 RunShell();
920 for (int i = 0; i < threads.length(); i++) { 910 for (int i = 0; i < threads.length(); i++) {
921 i::Thread* thread = threads[i]; 911 i::Thread* thread = threads[i];
922 thread->Join(); 912 thread->Join();
923 delete thread; 913 delete thread;
924 } 914 }
925 OnExit(); 915 OnExit();
926 return 0; 916 return 0;
927 } 917 }
928 918
929 919
930 } // namespace v8 920 int Shell::Main(int argc, char* argv[]) {
921 // Figure out if we're requested to stress the optimization
922 // infrastructure by running tests multiple times and forcing
923 // optimization in the last run.
924 bool FLAG_stress_opt = false;
925 bool FLAG_stress_deopt = false;
926 bool run_shell = (argc == 1);
927
928 for (int i = 0; i < argc; i++) {
929 if (strcmp(argv[i], "--stress-opt") == 0) {
930 FLAG_stress_opt = true;
931 argv[i] = NULL;
932 } else if (strcmp(argv[i], "--stress-deopt") == 0) {
933 FLAG_stress_deopt = true;
934 argv[i] = NULL;
935 } else if (strcmp(argv[i], "--noalways-opt") == 0) {
936 // No support for stressing if we can't use --always-opt.
937 FLAG_stress_opt = false;
938 FLAG_stress_deopt = false;
939 } else if (strcmp(argv[i], "--shell") == 0) {
940 run_shell = true;
941 argv[i] = NULL;
942 }
943 }
944
945 v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
946
947 Initialize();
948
949 int result = 0;
950 if (FLAG_stress_opt || FLAG_stress_deopt) {
951 v8::Testing::SetStressRunType(
952 FLAG_stress_opt ? v8::Testing::kStressTypeOpt
953 : v8::Testing::kStressTypeDeopt);
954 int stress_runs = v8::Testing::GetStressRuns();
955 for (int i = 0; i < stress_runs && result == 0; i++) {
956 printf("============ Stress %d/%d ============\n", i + 1, stress_runs);
957 v8::Testing::PrepareStressRun(i);
958 result = RunMain(argc, argv);
959 }
960 printf("======== Full Deoptimization =======\n");
961 v8::Testing::DeoptimizeAll();
962 } else {
963 result = RunMain(argc, argv);
964 }
965
966 #ifdef ENABLE_DEBUGGER_SUPPORT
967 if (i::FLAG_remote_debugger) {
968 RunRemoteDebugger(i::FLAG_debugger_port);
969 return 0;
970 }
971 #endif
972
973 if (run_shell) {
974 InstallUtilityScript();
975 RunShell();
976 }
977
978 v8::V8::Dispose();
979
980 return result;
981 }
982
983 } // namespace v8
931 984
932 985
933 #ifndef GOOGLE3 986 #ifndef GOOGLE3
934 int main(int argc, char* argv[]) { 987 int main(int argc, char* argv[]) {
935 return v8::Shell::Main(argc, argv); 988 return v8::Shell::Main(argc, argv);
936 } 989 }
937 #endif 990 #endif
OLDNEW
« no previous file with comments | « src/d8.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698