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

Side by Side Diff: src/d8.cc

Issue 7891005: Fixing parallel execution in d8 (with -p) and some memory leaks. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Applied suggestions. Created 9 years, 3 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 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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 Handle<Value> Shell::Write(const Arguments& args) { 196 Handle<Value> Shell::Write(const Arguments& args) {
197 for (int i = 0; i < args.Length(); i++) { 197 for (int i = 0; i < args.Length(); i++) {
198 HandleScope handle_scope; 198 HandleScope handle_scope;
199 if (i != 0) { 199 if (i != 0) {
200 printf(" "); 200 printf(" ");
201 } 201 }
202 v8::String::Utf8Value str(args[i]); 202 v8::String::Utf8Value str(args[i]);
203 int n = static_cast<int>(fwrite(*str, sizeof(**str), str.length(), stdout)); 203 int n = static_cast<int>(fwrite(*str, sizeof(**str), str.length(), stdout));
204 if (n != str.length()) { 204 if (n != str.length()) {
205 printf("Error in fwrite\n"); 205 printf("Error in fwrite\n");
206 exit(1); 206 Exit(1);
207 } 207 }
208 } 208 }
209 return Undefined(); 209 return Undefined();
210 } 210 }
211 211
212 212
213 Handle<Value> Shell::EnableProfiler(const Arguments& args) { 213 Handle<Value> Shell::EnableProfiler(const Arguments& args) {
214 V8::ResumeProfiler(); 214 V8::ResumeProfiler();
215 return Undefined(); 215 return Undefined();
216 } 216 }
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 } 514 }
515 515
516 516
517 void Shell::MapCounters(const char* name) { 517 void Shell::MapCounters(const char* name) {
518 counters_file_ = i::OS::MemoryMappedFile::create( 518 counters_file_ = i::OS::MemoryMappedFile::create(
519 name, sizeof(CounterCollection), &local_counters_); 519 name, sizeof(CounterCollection), &local_counters_);
520 void* memory = (counters_file_ == NULL) ? 520 void* memory = (counters_file_ == NULL) ?
521 NULL : counters_file_->memory(); 521 NULL : counters_file_->memory();
522 if (memory == NULL) { 522 if (memory == NULL) {
523 printf("Could not map counters file %s\n", name); 523 printf("Could not map counters file %s\n", name);
524 exit(1); 524 Exit(1);
525 } 525 }
526 counters_ = static_cast<CounterCollection*>(memory); 526 counters_ = static_cast<CounterCollection*>(memory);
527 V8::SetCounterFunction(LookupCounter); 527 V8::SetCounterFunction(LookupCounter);
528 V8::SetCreateHistogramFunction(CreateHistogram); 528 V8::SetCreateHistogramFunction(CreateHistogram);
529 V8::SetAddHistogramSampleFunction(AddHistogramSample); 529 V8::SetAddHistogramSampleFunction(AddHistogramSample);
530 } 530 }
531 531
532 532
533 int CounterMap::Hash(const char* name) { 533 int CounterMap::Hash(const char* name) {
534 int h = 0; 534 int h = 0;
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 return global_template; 711 return global_template;
712 } 712 }
713 713
714 714
715 void Shell::Initialize() { 715 void Shell::Initialize() {
716 #ifdef COMPRESS_STARTUP_DATA_BZ2 716 #ifdef COMPRESS_STARTUP_DATA_BZ2
717 BZip2Decompressor startup_data_decompressor; 717 BZip2Decompressor startup_data_decompressor;
718 int bz2_result = startup_data_decompressor.Decompress(); 718 int bz2_result = startup_data_decompressor.Decompress();
719 if (bz2_result != BZ_OK) { 719 if (bz2_result != BZ_OK) {
720 fprintf(stderr, "bzip error code: %d\n", bz2_result); 720 fprintf(stderr, "bzip error code: %d\n", bz2_result);
721 exit(1); 721 Exit(1);
722 } 722 }
723 #endif 723 #endif
724 724
725 #ifndef V8_SHARED 725 #ifndef V8_SHARED
726 Shell::counter_map_ = new CounterMap(); 726 Shell::counter_map_ = new CounterMap();
727 // Set up counters 727 // Set up counters
728 if (i::StrLength(i::FLAG_map_counters) != 0) 728 if (i::StrLength(i::FLAG_map_counters) != 0)
729 MapCounters(i::FLAG_map_counters); 729 MapCounters(i::FLAG_map_counters);
730 if (i::FLAG_dump_counters) { 730 if (i::FLAG_dump_counters) {
731 V8::SetCounterFunction(LookupCounter); 731 V8::SetCounterFunction(LookupCounter);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 } 773 }
774 i::Handle<i::JSArray> arguments_jsarray = 774 i::Handle<i::JSArray> arguments_jsarray =
775 FACTORY->NewJSArrayWithElements(arguments_array); 775 FACTORY->NewJSArrayWithElements(arguments_array);
776 context->Global()->Set(String::New("arguments"), 776 context->Global()->Set(String::New("arguments"),
777 Utils::ToLocal(arguments_jsarray)); 777 Utils::ToLocal(arguments_jsarray));
778 #endif // V8_SHARED 778 #endif // V8_SHARED
779 return context; 779 return context;
780 } 780 }
781 781
782 782
783 void Shell::Exit(int exit_code) {
784 // Use _exit instead of exit to avoid races between isolate
785 // threads and static destructors.
786 fflush(stdout);
787 fflush(stderr);
788 _exit(exit_code);
789 }
790
791
783 #ifndef V8_SHARED 792 #ifndef V8_SHARED
784 void Shell::OnExit() { 793 void Shell::OnExit() {
785 if (i::FLAG_dump_counters) { 794 if (i::FLAG_dump_counters) {
786 printf("+----------------------------------------+-------------+\n"); 795 printf("+----------------------------------------+-------------+\n");
787 printf("| Name | Value |\n"); 796 printf("| Name | Value |\n");
788 printf("+----------------------------------------+-------------+\n"); 797 printf("+----------------------------------------+-------------+\n");
789 for (CounterMap::Iterator i(counter_map_); i.More(); i.Next()) { 798 for (CounterMap::Iterator i(counter_map_); i.More(); i.Next()) {
790 Counter* counter = i.CurrentValue(); 799 Counter* counter = i.CurrentValue();
791 if (counter->is_histogram()) { 800 if (counter->is_histogram()) {
792 printf("| c:%-36s | %11i |\n", i.CurrentKey(), counter->count()); 801 printf("| c:%-36s | %11i |\n", i.CurrentKey(), counter->count());
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 ExecuteString(String::New(buffer), name, true, true); 920 ExecuteString(String::New(buffer), name, true, true);
912 } 921 }
913 #endif // V8_SHARED 922 #endif // V8_SHARED
914 printf("\n"); 923 printf("\n");
915 } 924 }
916 925
917 926
918 #ifndef V8_SHARED 927 #ifndef V8_SHARED
919 class ShellThread : public i::Thread { 928 class ShellThread : public i::Thread {
920 public: 929 public:
921 ShellThread(int no, i::Vector<const char> files) 930 // Takes ownership of the underlying char array of |files|.
931 ShellThread(int no, i::SmartArrayPointer<char> files)
922 : Thread("d8:ShellThread"), 932 : Thread("d8:ShellThread"),
923 no_(no), files_(files) { } 933 no_(no), files_(files) { }
924 virtual void Run(); 934 virtual void Run();
925 private: 935 private:
926 int no_; 936 int no_;
927 i::Vector<const char> files_; 937 i::SmartArrayPointer<char> files_;
928 }; 938 };
929 939
930 940
931 void ShellThread::Run() { 941 void ShellThread::Run() {
932 char* ptr = const_cast<char*>(files_.start()); 942 char* ptr = *files_;
933 while ((ptr != NULL) && (*ptr != '\0')) { 943 while ((ptr != NULL) && (*ptr != '\0')) {
934 // For each newline-separated line. 944 // For each newline-separated line.
935 char* next_line = ReadLine(ptr); 945 char* next_line = ReadLine(ptr);
936 946
937 if (*ptr == '#') { 947 if (*ptr == '#') {
938 // Skip comment lines. 948 // Skip comment lines.
939 ptr = next_line; 949 ptr = next_line;
940 continue; 950 continue;
941 } 951 }
942 952
943 // Prepare the context for this thread. 953 // Prepare the context for this thread.
944 Locker locker; 954 Locker locker;
945 HandleScope scope; 955 HandleScope outer_scope;
946 Persistent<Context> thread_context = Shell::CreateEvaluationContext(); 956 Persistent<Context> thread_context = Shell::CreateEvaluationContext();
947 Context::Scope context_scope(thread_context); 957 Context::Scope context_scope(thread_context);
948 958
949 while ((ptr != NULL) && (*ptr != '\0')) { 959 while ((ptr != NULL) && (*ptr != '\0')) {
960 HandleScope inner_scope;
950 char* filename = ptr; 961 char* filename = ptr;
951 ptr = ReadWord(ptr); 962 ptr = ReadWord(ptr);
952 963
953 // Skip empty strings. 964 // Skip empty strings.
954 if (strlen(filename) == 0) { 965 if (strlen(filename) == 0) {
955 break; 966 continue;
956 } 967 }
957 968
958 Handle<String> str = Shell::ReadFile(filename); 969 Handle<String> str = Shell::ReadFile(filename);
959 if (str.IsEmpty()) { 970 if (str.IsEmpty()) {
960 printf("WARNING: %s not found\n", filename); 971 printf("File '%s' not found\n", filename);
961 break; 972 Shell::Exit(1);
962 } 973 }
963 974
964 Shell::ExecuteString(str, String::New(filename), false, false); 975 Shell::ExecuteString(str, String::New(filename), false, false);
965 } 976 }
966 977
967 thread_context.Dispose(); 978 thread_context.Dispose();
968 ptr = next_line; 979 ptr = next_line;
969 } 980 }
970 } 981 }
971 #endif // V8_SHARED 982 #endif // V8_SHARED
972 983
973 984
974 SourceGroup::~SourceGroup() { 985 SourceGroup::~SourceGroup() {
975 #ifndef V8_SHARED 986 #ifndef V8_SHARED
976 delete next_semaphore_; 987 delete next_semaphore_;
977 next_semaphore_ = NULL; 988 next_semaphore_ = NULL;
978 delete done_semaphore_; 989 delete done_semaphore_;
979 done_semaphore_ = NULL; 990 done_semaphore_ = NULL;
980 delete thread_; 991 delete thread_;
981 thread_ = NULL; 992 thread_ = NULL;
982 #endif // V8_SHARED 993 #endif // V8_SHARED
983 } 994 }
984 995
985 996
986 void SourceGroup::ExitShell(int exit_code) {
987 // Use _exit instead of exit to avoid races between isolate
988 // threads and static destructors.
989 fflush(stdout);
990 fflush(stderr);
991 _exit(exit_code);
992 }
993
994
995 void SourceGroup::Execute() { 997 void SourceGroup::Execute() {
996 for (int i = begin_offset_; i < end_offset_; ++i) { 998 for (int i = begin_offset_; i < end_offset_; ++i) {
997 const char* arg = argv_[i]; 999 const char* arg = argv_[i];
998 if (strcmp(arg, "-e") == 0 && i + 1 < end_offset_) { 1000 if (strcmp(arg, "-e") == 0 && i + 1 < end_offset_) {
999 // Execute argument given to -e option directly. 1001 // Execute argument given to -e option directly.
1000 HandleScope handle_scope; 1002 HandleScope handle_scope;
1001 Handle<String> file_name = String::New("unnamed"); 1003 Handle<String> file_name = String::New("unnamed");
1002 Handle<String> source = String::New(argv_[i + 1]); 1004 Handle<String> source = String::New(argv_[i + 1]);
1003 if (!Shell::ExecuteString(source, file_name, false, true)) { 1005 if (!Shell::ExecuteString(source, file_name, false, true)) {
1004 ExitShell(1); 1006 Shell::Exit(1);
1005 return;
1006 } 1007 }
1007 ++i; 1008 ++i;
1008 } else if (arg[0] == '-') { 1009 } else if (arg[0] == '-') {
1009 // Ignore other options. They have been parsed already. 1010 // Ignore other options. They have been parsed already.
1010 } else { 1011 } else {
1011 // Use all other arguments as names of files to load and run. 1012 // Use all other arguments as names of files to load and run.
1012 HandleScope handle_scope; 1013 HandleScope handle_scope;
1013 Handle<String> file_name = String::New(arg); 1014 Handle<String> file_name = String::New(arg);
1014 Handle<String> source = ReadFile(arg); 1015 Handle<String> source = ReadFile(arg);
1015 if (source.IsEmpty()) { 1016 if (source.IsEmpty()) {
1016 printf("Error reading '%s'\n", arg); 1017 printf("Error reading '%s'\n", arg);
1017 ExitShell(1); 1018 Shell::Exit(1);
1018 return;
1019 } 1019 }
1020 if (!Shell::ExecuteString(source, file_name, false, true)) { 1020 if (!Shell::ExecuteString(source, file_name, false, true)) {
1021 ExitShell(1); 1021 Shell::Exit(1);
1022 return;
1023 } 1022 }
1024 } 1023 }
1025 } 1024 }
1026 } 1025 }
1027 1026
1028 1027
1029 Handle<String> SourceGroup::ReadFile(const char* name) { 1028 Handle<String> SourceGroup::ReadFile(const char* name) {
1030 int size; 1029 int size;
1031 const char* chars = ReadChars(name, &size); 1030 const char* chars = ReadChars(name, &size);
1032 if (chars == NULL) return Handle<String>(); 1031 if (chars == NULL) return Handle<String>();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 if (thread_ == NULL) return; 1082 if (thread_ == NULL) return;
1084 if (Shell::options.last_run) { 1083 if (Shell::options.last_run) {
1085 thread_->Join(); 1084 thread_->Join();
1086 } else { 1085 } else {
1087 done_semaphore_->Wait(); 1086 done_semaphore_->Wait();
1088 } 1087 }
1089 } 1088 }
1090 #endif // V8_SHARED 1089 #endif // V8_SHARED
1091 1090
1092 1091
1093 ShellOptions::~ShellOptions() {
1094 delete[] isolate_sources;
1095 isolate_sources = NULL;
1096 #ifndef V8_SHARED
1097 delete parallel_files;
1098 parallel_files = NULL;
1099 #endif // V8_SHARED
1100 }
1101
1102
1103 bool Shell::SetOptions(int argc, char* argv[]) { 1092 bool Shell::SetOptions(int argc, char* argv[]) {
1104 for (int i = 0; i < argc; i++) { 1093 for (int i = 0; i < argc; i++) {
1105 if (strcmp(argv[i], "--stress-opt") == 0) { 1094 if (strcmp(argv[i], "--stress-opt") == 0) {
1106 options.stress_opt = true; 1095 options.stress_opt = true;
1107 argv[i] = NULL; 1096 argv[i] = NULL;
1108 } else if (strcmp(argv[i], "--stress-deopt") == 0) { 1097 } else if (strcmp(argv[i], "--stress-deopt") == 0) {
1109 options.stress_deopt = true; 1098 options.stress_deopt = true;
1110 argv[i] = NULL; 1099 argv[i] = NULL;
1111 } else if (strcmp(argv[i], "--noalways-opt") == 0) { 1100 } else if (strcmp(argv[i], "--noalways-opt") == 0) {
1112 // No support for stressing if we can't use --always-opt. 1101 // No support for stressing if we can't use --always-opt.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1158 } else if (strcmp(argv[i], "-f") == 0) { 1147 } else if (strcmp(argv[i], "-f") == 0) {
1159 // Ignore any -f flags for compatibility with other stand-alone 1148 // Ignore any -f flags for compatibility with other stand-alone
1160 // JavaScript engines. 1149 // JavaScript engines.
1161 continue; 1150 continue;
1162 } else if (strcmp(argv[i], "--isolate") == 0) { 1151 } else if (strcmp(argv[i], "--isolate") == 0) {
1163 #ifdef V8_SHARED 1152 #ifdef V8_SHARED
1164 printf("D8 with shared library does not support multi-threading\n"); 1153 printf("D8 with shared library does not support multi-threading\n");
1165 return false; 1154 return false;
1166 #endif // V8_SHARED 1155 #endif // V8_SHARED
1167 options.num_isolates++; 1156 options.num_isolates++;
1157 } else if (strcmp(argv[i], "-p") == 0) {
1158 options.num_parallel_files++;
1159 #ifdef V8_SHARED
1160 printf("D8 with shared library does not support multi-threading\n");
1161 return false;
1162 #endif // V8_SHARED
1168 } 1163 }
1169 #ifdef V8_SHARED 1164 #ifdef V8_SHARED
1170 else if (strcmp(argv[i], "--dump-counters") == 0) { 1165 else if (strcmp(argv[i], "--dump-counters") == 0) {
1171 printf("D8 with shared library does not include counters\n"); 1166 printf("D8 with shared library does not include counters\n");
1172 return false; 1167 return false;
1173 } else if (strcmp(argv[i], "-p") == 0) {
1174 printf("D8 with shared library does not support multi-threading\n");
1175 return false;
1176 } else if (strcmp(argv[i], "--debugger") == 0) { 1168 } else if (strcmp(argv[i], "--debugger") == 0) {
1177 printf("Javascript debugger not included\n"); 1169 printf("Javascript debugger not included\n");
1178 return false; 1170 return false;
1179 } 1171 }
1180 #endif // V8_SHARED 1172 #endif // V8_SHARED
1181 } 1173 }
1182 1174
1183 #ifndef V8_SHARED 1175 #ifndef V8_SHARED
1184 // Run parallel threads if we are not using --isolate 1176 // Run parallel threads if we are not using --isolate
1177 options.parallel_files = new char*[options.num_parallel_files];
1178 int parallel_files_set = 0;
1185 for (int i = 1; i < argc; i++) { 1179 for (int i = 1; i < argc; i++) {
1186 if (argv[i] == NULL) continue; 1180 if (argv[i] == NULL) continue;
1187 if (strcmp(argv[i], "-p") == 0 && i + 1 < argc) { 1181 if (strcmp(argv[i], "-p") == 0 && i + 1 < argc) {
1188 if (options.num_isolates > 1) { 1182 if (options.num_isolates > 1) {
1189 printf("-p is not compatible with --isolate\n"); 1183 printf("-p is not compatible with --isolate\n");
1190 return false; 1184 return false;
1191 } 1185 }
1192 argv[i] = NULL; 1186 argv[i] = NULL;
1193 if (options.parallel_files == NULL) { 1187 i++;
1194 options.parallel_files = new i::List<i::Vector<const char> >(); 1188 options.parallel_files[parallel_files_set] = argv[i];
1195 } 1189 parallel_files_set++;
1196 int size = 0;
1197 const char* files = ReadChars(argv[++i], &size);
1198 if (files == NULL) {
1199 printf("-p option incomplete\n");
1200 return false;
1201 }
1202 argv[i] = NULL; 1190 argv[i] = NULL;
1203 options.parallel_files->Add(i::Vector<const char>(files, size));
1204 delete[] files;
1205 } 1191 }
1206 } 1192 }
1193 if (parallel_files_set != options.num_parallel_files) {
1194 printf("-p requires a file containing a list of files as parameter\n");
1195 return false;
1196 }
1207 #endif // V8_SHARED 1197 #endif // V8_SHARED
1208 1198
1209 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); 1199 v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
1210 1200
1211 // Set up isolated source groups. 1201 // Set up isolated source groups.
1212 options.isolate_sources = new SourceGroup[options.num_isolates]; 1202 options.isolate_sources = new SourceGroup[options.num_isolates];
1213 SourceGroup* current = options.isolate_sources; 1203 SourceGroup* current = options.isolate_sources;
1214 current->Begin(argv, 1); 1204 current->Begin(argv, 1);
1215 for (int i = 1; i < argc; i++) { 1205 for (int i = 1; i < argc; i++) {
1216 const char* str = argv[i]; 1206 const char* str = argv[i];
1217 if (strcmp(str, "--isolate") == 0) { 1207 if (strcmp(str, "--isolate") == 0) {
1218 current->End(i); 1208 current->End(i);
1219 current++; 1209 current++;
1220 current->Begin(argv, i + 1); 1210 current->Begin(argv, i + 1);
1221 } else if (strncmp(argv[i], "--", 2) == 0) { 1211 } else if (strncmp(argv[i], "--", 2) == 0) {
1222 printf("Warning: unknown flag %s.\nTry --help for options\n", argv[i]); 1212 printf("Warning: unknown flag %s.\nTry --help for options\n", argv[i]);
1223 } 1213 }
1224 } 1214 }
1225 current->End(argc); 1215 current->End(argc);
1226 1216
1227 return true; 1217 return true;
1228 } 1218 }
1229 1219
1230 1220
1231 int Shell::RunMain(int argc, char* argv[]) { 1221 int Shell::RunMain(int argc, char* argv[]) {
1232 #ifndef V8_SHARED 1222 #ifndef V8_SHARED
1233 i::List<i::Thread*> threads(1); 1223 i::List<i::Thread*> threads(1);
1234 if (options.parallel_files != NULL) 1224 if (options.parallel_files != NULL) {
1235 for (int i = 0; i < options.parallel_files->length(); i++) { 1225 for (int i = 0; i < options.num_parallel_files; i++) {
1236 i::Vector<const char> files = options.parallel_files->at(i); 1226 i::SmartArrayPointer<char> files;
Jakob Kummerow 2011/09/13 13:08:03 This will delete the contents of |files| when it g
1227 { Locker lock(Isolate::GetCurrent());
1228 int size = 0;
1229 files = i::SmartArrayPointer<char>(
1230 ReadChars(options.parallel_files[i], &size));
1231 }
1232 if (files.is_empty()) {
1233 printf("File list '%s' not found\n", options.parallel_files[i]);
1234 Exit(1);
1235 }
1237 ShellThread* thread = new ShellThread(threads.length(), files); 1236 ShellThread* thread = new ShellThread(threads.length(), files);
1238 thread->Start(); 1237 thread->Start();
1239 threads.Add(thread); 1238 threads.Add(thread);
1240 } 1239 }
1241 1240 }
1242 for (int i = 1; i < options.num_isolates; ++i) { 1241 for (int i = 1; i < options.num_isolates; ++i) {
1243 options.isolate_sources[i].StartExecuteInThread(); 1242 options.isolate_sources[i].StartExecuteInThread();
1244 } 1243 }
1245 #endif // V8_SHARED 1244 #endif // V8_SHARED
1246 { // NOLINT 1245 { // NOLINT
1247 Locker lock; 1246 Locker lock;
1248 HandleScope scope; 1247 HandleScope scope;
1249 Persistent<Context> context = CreateEvaluationContext(); 1248 Persistent<Context> context = CreateEvaluationContext();
1250 { 1249 {
1251 Context::Scope cscope(context); 1250 Context::Scope cscope(context);
1252 options.isolate_sources[0].Execute(); 1251 options.isolate_sources[0].Execute();
1253 } 1252 }
1254 if (options.last_run) { 1253 if (options.last_run) {
1255 // Keep using the same context in the interactive shell 1254 // Keep using the same context in the interactive shell
1256 evaluation_context_ = context; 1255 evaluation_context_ = context;
1257 } else { 1256 } else {
1258 context.Dispose(); 1257 context.Dispose();
1259 } 1258 }
1260 1259
1261 #ifndef V8_SHARED 1260 #ifndef V8_SHARED
1262 // Start preemption if threads have been created and preemption is enabled. 1261 // Start preemption if threads have been created and preemption is enabled.
1263 if (options.parallel_files != NULL 1262 if (threads.length() > 0
1264 && threads.length() > 0
1265 && options.use_preemption) { 1263 && options.use_preemption) {
1266 Locker::StartPreemption(options.preemption_interval); 1264 Locker::StartPreemption(options.preemption_interval);
1267 } 1265 }
1268 #endif // V8_SHARED 1266 #endif // V8_SHARED
1269 } 1267 }
1270 1268
1271 #ifndef V8_SHARED 1269 #ifndef V8_SHARED
1272 for (int i = 1; i < options.num_isolates; ++i) { 1270 for (int i = 1; i < options.num_isolates; ++i) {
1273 options.isolate_sources[i].WaitForThread(); 1271 options.isolate_sources[i].WaitForThread();
1274 } 1272 }
1275 1273
1276 if (options.parallel_files != NULL) 1274 for (int i = 0; i < threads.length(); i++) {
1277 for (int i = 0; i < threads.length(); i++) { 1275 i::Thread* thread = threads[i];
1278 i::Thread* thread = threads[i]; 1276 thread->Join();
1279 thread->Join(); 1277 delete thread;
1280 delete thread; 1278 }
1281 } 1279
1280 if (threads.length() > 0 && options.use_preemption) {
1281 Locker lock;
1282 Locker::StopPreemption();
1283 }
1282 #endif // V8_SHARED 1284 #endif // V8_SHARED
1283 return 0; 1285 return 0;
1284 } 1286 }
1285 1287
1286 1288
1287 int Shell::Main(int argc, char* argv[]) { 1289 int Shell::Main(int argc, char* argv[]) {
1288 if (!SetOptions(argc, argv)) return 1; 1290 if (!SetOptions(argc, argv)) return 1;
1289 Initialize(); 1291 Initialize();
1290 1292
1291 int result = 0; 1293 int result = 0;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1338 } 1340 }
1339 1341
1340 } // namespace v8 1342 } // namespace v8
1341 1343
1342 1344
1343 #ifndef GOOGLE3 1345 #ifndef GOOGLE3
1344 int main(int argc, char* argv[]) { 1346 int main(int argc, char* argv[]) {
1345 return v8::Shell::Main(argc, argv); 1347 return v8::Shell::Main(argc, argv);
1346 } 1348 }
1347 #endif 1349 #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