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

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: 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
« src/d8.h ('K') | « 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 ShellThread(int no, char* files)
Jakob Kummerow 2011/09/13 11:55:11 As discussed, let's add comments à la: // Takes ow
922 : Thread("d8:ShellThread"), 931 : Thread("d8:ShellThread"),
923 no_(no), files_(files) { } 932 no_(no), files_(files) { }
933 ~ShellThread() {
934 delete[] files_;
935 }
924 virtual void Run(); 936 virtual void Run();
925 private: 937 private:
926 int no_; 938 int no_;
927 i::Vector<const char> files_; 939 char* files_;
928 }; 940 };
929 941
930 942
931 void ShellThread::Run() { 943 void ShellThread::Run() {
932 char* ptr = const_cast<char*>(files_.start()); 944 char* ptr = files_;
933 while ((ptr != NULL) && (*ptr != '\0')) { 945 while ((ptr != NULL) && (*ptr != '\0')) {
934 // For each newline-separated line. 946 // For each newline-separated line.
935 char* next_line = ReadLine(ptr); 947 char* next_line = ReadLine(ptr);
936 948
937 if (*ptr == '#') { 949 if (*ptr == '#') {
938 // Skip comment lines. 950 // Skip comment lines.
939 ptr = next_line; 951 ptr = next_line;
940 continue; 952 continue;
941 } 953 }
942 954
943 // Prepare the context for this thread. 955 // Prepare the context for this thread.
944 Locker locker; 956 Locker locker;
945 HandleScope scope; 957 HandleScope outer_scope;
946 Persistent<Context> thread_context = Shell::CreateEvaluationContext(); 958 Persistent<Context> thread_context = Shell::CreateEvaluationContext();
947 Context::Scope context_scope(thread_context); 959 Context::Scope context_scope(thread_context);
948 960
949 while ((ptr != NULL) && (*ptr != '\0')) { 961 while ((ptr != NULL) && (*ptr != '\0')) {
962 HandleScope inner_scope;
950 char* filename = ptr; 963 char* filename = ptr;
951 ptr = ReadWord(ptr); 964 ptr = ReadWord(ptr);
952 965
953 // Skip empty strings. 966 // Skip empty strings.
954 if (strlen(filename) == 0) { 967 if (strlen(filename) == 0) {
955 break; 968 break;
Jakob Kummerow 2011/09/13 11:55:11 s/break/continue/
956 } 969 }
957 970
958 Handle<String> str = Shell::ReadFile(filename); 971 Handle<String> str = Shell::ReadFile(filename);
959 if (str.IsEmpty()) { 972 if (str.IsEmpty()) {
960 printf("WARNING: %s not found\n", filename); 973 printf("File '%s' not found\n", filename);
961 break; 974 Shell::Exit(1);
962 } 975 }
963 976
964 Shell::ExecuteString(str, String::New(filename), false, false); 977 Shell::ExecuteString(str, String::New(filename), false, false);
965 } 978 }
966 979
967 thread_context.Dispose(); 980 thread_context.Dispose();
968 ptr = next_line; 981 ptr = next_line;
969 } 982 }
970 } 983 }
971 #endif // V8_SHARED 984 #endif // V8_SHARED
972 985
973 986
974 SourceGroup::~SourceGroup() { 987 SourceGroup::~SourceGroup() {
975 #ifndef V8_SHARED 988 #ifndef V8_SHARED
976 delete next_semaphore_; 989 delete next_semaphore_;
977 next_semaphore_ = NULL; 990 next_semaphore_ = NULL;
978 delete done_semaphore_; 991 delete done_semaphore_;
979 done_semaphore_ = NULL; 992 done_semaphore_ = NULL;
980 delete thread_; 993 delete thread_;
981 thread_ = NULL; 994 thread_ = NULL;
982 #endif // V8_SHARED 995 #endif // V8_SHARED
983 } 996 }
984 997
985 998
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() { 999 void SourceGroup::Execute() {
996 for (int i = begin_offset_; i < end_offset_; ++i) { 1000 for (int i = begin_offset_; i < end_offset_; ++i) {
997 const char* arg = argv_[i]; 1001 const char* arg = argv_[i];
998 if (strcmp(arg, "-e") == 0 && i + 1 < end_offset_) { 1002 if (strcmp(arg, "-e") == 0 && i + 1 < end_offset_) {
999 // Execute argument given to -e option directly. 1003 // Execute argument given to -e option directly.
1000 HandleScope handle_scope; 1004 HandleScope handle_scope;
1001 Handle<String> file_name = String::New("unnamed"); 1005 Handle<String> file_name = String::New("unnamed");
1002 Handle<String> source = String::New(argv_[i + 1]); 1006 Handle<String> source = String::New(argv_[i + 1]);
1003 if (!Shell::ExecuteString(source, file_name, false, true)) { 1007 if (!Shell::ExecuteString(source, file_name, false, true)) {
1004 ExitShell(1); 1008 Shell::Exit(1);
1005 return;
1006 } 1009 }
1007 ++i; 1010 ++i;
1008 } else if (arg[0] == '-') { 1011 } else if (arg[0] == '-') {
1009 // Ignore other options. They have been parsed already. 1012 // Ignore other options. They have been parsed already.
1010 } else { 1013 } else {
1011 // Use all other arguments as names of files to load and run. 1014 // Use all other arguments as names of files to load and run.
1012 HandleScope handle_scope; 1015 HandleScope handle_scope;
1013 Handle<String> file_name = String::New(arg); 1016 Handle<String> file_name = String::New(arg);
1014 Handle<String> source = ReadFile(arg); 1017 Handle<String> source = ReadFile(arg);
1015 if (source.IsEmpty()) { 1018 if (source.IsEmpty()) {
1016 printf("Error reading '%s'\n", arg); 1019 printf("Error reading '%s'\n", arg);
1017 ExitShell(1); 1020 Shell::Exit(1);
1018 return;
1019 } 1021 }
1020 if (!Shell::ExecuteString(source, file_name, false, true)) { 1022 if (!Shell::ExecuteString(source, file_name, false, true)) {
1021 ExitShell(1); 1023 Shell::Exit(1);
1022 return;
1023 } 1024 }
1024 } 1025 }
1025 } 1026 }
1026 } 1027 }
1027 1028
1028 1029
1029 Handle<String> SourceGroup::ReadFile(const char* name) { 1030 Handle<String> SourceGroup::ReadFile(const char* name) {
1030 int size; 1031 int size;
1031 const char* chars = ReadChars(name, &size); 1032 const char* chars = ReadChars(name, &size);
1032 if (chars == NULL) return Handle<String>(); 1033 if (chars == NULL) return Handle<String>();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 if (thread_ == NULL) return; 1084 if (thread_ == NULL) return;
1084 if (Shell::options.last_run) { 1085 if (Shell::options.last_run) {
1085 thread_->Join(); 1086 thread_->Join();
1086 } else { 1087 } else {
1087 done_semaphore_->Wait(); 1088 done_semaphore_->Wait();
1088 } 1089 }
1089 } 1090 }
1090 #endif // V8_SHARED 1091 #endif // V8_SHARED
1091 1092
1092 1093
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[]) { 1094 bool Shell::SetOptions(int argc, char* argv[]) {
1104 for (int i = 0; i < argc; i++) { 1095 for (int i = 0; i < argc; i++) {
1105 if (strcmp(argv[i], "--stress-opt") == 0) { 1096 if (strcmp(argv[i], "--stress-opt") == 0) {
1106 options.stress_opt = true; 1097 options.stress_opt = true;
1107 argv[i] = NULL; 1098 argv[i] = NULL;
1108 } else if (strcmp(argv[i], "--stress-deopt") == 0) { 1099 } else if (strcmp(argv[i], "--stress-deopt") == 0) {
1109 options.stress_deopt = true; 1100 options.stress_deopt = true;
1110 argv[i] = NULL; 1101 argv[i] = NULL;
1111 } else if (strcmp(argv[i], "--noalways-opt") == 0) { 1102 } else if (strcmp(argv[i], "--noalways-opt") == 0) {
1112 // No support for stressing if we can't use --always-opt. 1103 // 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) { 1149 } else if (strcmp(argv[i], "-f") == 0) {
1159 // Ignore any -f flags for compatibility with other stand-alone 1150 // Ignore any -f flags for compatibility with other stand-alone
1160 // JavaScript engines. 1151 // JavaScript engines.
1161 continue; 1152 continue;
1162 } else if (strcmp(argv[i], "--isolate") == 0) { 1153 } else if (strcmp(argv[i], "--isolate") == 0) {
1163 #ifdef V8_SHARED 1154 #ifdef V8_SHARED
1164 printf("D8 with shared library does not support multi-threading\n"); 1155 printf("D8 with shared library does not support multi-threading\n");
1165 return false; 1156 return false;
1166 #endif // V8_SHARED 1157 #endif // V8_SHARED
1167 options.num_isolates++; 1158 options.num_isolates++;
1159 } else if (strcmp(argv[i], "-p") == 0) {
1160 options.num_parallel_files++;
1161 #ifdef V8_SHARED
1162 printf("D8 with shared library does not support multi-threading\n");
1163 return false;
1164 #endif // V8_SHARED
1168 } 1165 }
1169 #ifdef V8_SHARED 1166 #ifdef V8_SHARED
1170 else if (strcmp(argv[i], "--dump-counters") == 0) { 1167 else if (strcmp(argv[i], "--dump-counters") == 0) {
1171 printf("D8 with shared library does not include counters\n"); 1168 printf("D8 with shared library does not include counters\n");
1172 return false; 1169 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) { 1170 } else if (strcmp(argv[i], "--debugger") == 0) {
1177 printf("Javascript debugger not included\n"); 1171 printf("Javascript debugger not included\n");
1178 return false; 1172 return false;
1179 } 1173 }
1180 #endif // V8_SHARED 1174 #endif // V8_SHARED
1181 } 1175 }
1182 1176
1183 #ifndef V8_SHARED 1177 #ifndef V8_SHARED
1184 // Run parallel threads if we are not using --isolate 1178 // Run parallel threads if we are not using --isolate
1179 options.parallel_files = new char*[options.num_parallel_files];
1180 int parallel_files_set = 0;
1185 for (int i = 1; i < argc; i++) { 1181 for (int i = 1; i < argc; i++) {
1186 if (argv[i] == NULL) continue; 1182 if (argv[i] == NULL) continue;
1187 if (strcmp(argv[i], "-p") == 0 && i + 1 < argc) { 1183 if (strcmp(argv[i], "-p") == 0 && i + 1 < argc) {
1188 if (options.num_isolates > 1) { 1184 if (options.num_isolates > 1) {
1189 printf("-p is not compatible with --isolate\n"); 1185 printf("-p is not compatible with --isolate\n");
1190 return false; 1186 return false;
1191 } 1187 }
1192 argv[i] = NULL; 1188 argv[i] = NULL;
1193 if (options.parallel_files == NULL) { 1189 options.parallel_files[parallel_files_set++] = argv[++i];
Jakob Kummerow 2011/09/13 11:55:11 I'd prefer to have the increment operations on the
1194 options.parallel_files = new i::List<i::Vector<const char> >();
1195 }
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 char* files;
Jakob Kummerow 2011/09/13 11:55:11 We don't like uninitialized pointers. It's safe in
1227 { Locker lock(Isolate::GetCurrent());
1228 int size;
1229 files = ReadChars(options.parallel_files[i], &size);
1230 }
1231 if (files == NULL) {
1232 printf("File list '%s' not found\n", options.parallel_files[i]);
1233 Exit(1);
1234 }
1237 ShellThread* thread = new ShellThread(threads.length(), files); 1235 ShellThread* thread = new ShellThread(threads.length(), files);
1238 thread->Start(); 1236 thread->Start();
1239 threads.Add(thread); 1237 threads.Add(thread);
1240 } 1238 }
1241 1239 }
Jakob Kummerow 2011/09/13 11:55:11 +1 :-)
1242 for (int i = 1; i < options.num_isolates; ++i) { 1240 for (int i = 1; i < options.num_isolates; ++i) {
1243 options.isolate_sources[i].StartExecuteInThread(); 1241 options.isolate_sources[i].StartExecuteInThread();
1244 } 1242 }
1245 #endif // V8_SHARED 1243 #endif // V8_SHARED
1246 { // NOLINT 1244 { // NOLINT
1247 Locker lock; 1245 Locker lock;
1248 HandleScope scope; 1246 HandleScope scope;
1249 Persistent<Context> context = CreateEvaluationContext(); 1247 Persistent<Context> context = CreateEvaluationContext();
1250 { 1248 {
1251 Context::Scope cscope(context); 1249 Context::Scope cscope(context);
1252 options.isolate_sources[0].Execute(); 1250 options.isolate_sources[0].Execute();
1253 } 1251 }
1254 if (options.last_run) { 1252 if (options.last_run) {
1255 // Keep using the same context in the interactive shell 1253 // Keep using the same context in the interactive shell
1256 evaluation_context_ = context; 1254 evaluation_context_ = context;
1257 } else { 1255 } else {
1258 context.Dispose(); 1256 context.Dispose();
1259 } 1257 }
1260 1258
1261 #ifndef V8_SHARED 1259 #ifndef V8_SHARED
1262 // Start preemption if threads have been created and preemption is enabled. 1260 // Start preemption if threads have been created and preemption is enabled.
1263 if (options.parallel_files != NULL 1261 if (threads.length() > 0
1264 && threads.length() > 0
1265 && options.use_preemption) { 1262 && options.use_preemption) {
1266 Locker::StartPreemption(options.preemption_interval); 1263 Locker::StartPreemption(options.preemption_interval);
1267 } 1264 }
1268 #endif // V8_SHARED 1265 #endif // V8_SHARED
1269 } 1266 }
1270 1267
1271 #ifndef V8_SHARED 1268 #ifndef V8_SHARED
1272 for (int i = 1; i < options.num_isolates; ++i) { 1269 for (int i = 1; i < options.num_isolates; ++i) {
1273 options.isolate_sources[i].WaitForThread(); 1270 options.isolate_sources[i].WaitForThread();
1274 } 1271 }
1275 1272
1276 if (options.parallel_files != NULL) 1273 for (int i = 0; i < threads.length(); i++) {
1277 for (int i = 0; i < threads.length(); i++) { 1274 i::Thread* thread = threads[i];
1278 i::Thread* thread = threads[i]; 1275 thread->Join();
1279 thread->Join(); 1276 delete thread;
1280 delete thread; 1277 }
1281 } 1278
1279 if (threads.length() > 0
1280 && options.use_preemption) {
Jakob Kummerow 2011/09/13 11:55:11 Both conditions could go in one line, I think.
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
« src/d8.h ('K') | « src/d8.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698