Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 961 Shell::ExecuteString(str, String::New(filename), false, false); | 961 Shell::ExecuteString(str, String::New(filename), false, false); |
| 962 } | 962 } |
| 963 | 963 |
| 964 thread_context.Dispose(); | 964 thread_context.Dispose(); |
| 965 ptr = next_line; | 965 ptr = next_line; |
| 966 } | 966 } |
| 967 } | 967 } |
| 968 #endif // V8_SHARED | 968 #endif // V8_SHARED |
| 969 | 969 |
| 970 | 970 |
| 971 SourceGroup::~SourceGroup() { | |
| 972 delete next_semaphore_; | |
| 973 next_semaphore_ = NULL; | |
| 974 delete done_semaphore_; | |
| 975 done_semaphore_ = NULL; | |
| 976 delete thread_; | |
| 977 thread_ = NULL; | |
| 978 } | |
| 979 | |
| 980 | |
| 971 void SourceGroup::ExitShell(int exit_code) { | 981 void SourceGroup::ExitShell(int exit_code) { |
| 972 // Use _exit instead of exit to avoid races between isolate | 982 // Use _exit instead of exit to avoid races between isolate |
| 973 // threads and static destructors. | 983 // threads and static destructors. |
| 974 fflush(stdout); | 984 fflush(stdout); |
| 975 fflush(stderr); | 985 fflush(stderr); |
| 976 _exit(exit_code); | 986 _exit(exit_code); |
| 977 } | 987 } |
| 978 | 988 |
| 979 | 989 |
| 980 void SourceGroup::Execute() { | 990 void SourceGroup::Execute() { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1030 // The stack size should be at least StackGuard::kLimitSize + some | 1040 // The stack size should be at least StackGuard::kLimitSize + some |
| 1031 // OS-specific padding for thread startup code. | 1041 // OS-specific padding for thread startup code. |
| 1032 options.stack_size = 2 << 20; // 2 Mb seems to be enough | 1042 options.stack_size = 2 << 20; // 2 Mb seems to be enough |
| 1033 return options; | 1043 return options; |
| 1034 } | 1044 } |
| 1035 | 1045 |
| 1036 | 1046 |
| 1037 void SourceGroup::ExecuteInThread() { | 1047 void SourceGroup::ExecuteInThread() { |
| 1038 Isolate* isolate = Isolate::New(); | 1048 Isolate* isolate = Isolate::New(); |
| 1039 do { | 1049 do { |
| 1040 if (!next_semaphore_.is_empty()) next_semaphore_->Wait(); | 1050 if (next_semaphore_ != NULL) next_semaphore_->Wait(); |
| 1041 { | 1051 { |
| 1042 Isolate::Scope iscope(isolate); | 1052 Isolate::Scope iscope(isolate); |
| 1043 Locker lock(isolate); | 1053 Locker lock(isolate); |
| 1044 HandleScope scope; | 1054 HandleScope scope; |
| 1045 Persistent<Context> context = Shell::CreateEvaluationContext(); | 1055 Persistent<Context> context = Shell::CreateEvaluationContext(); |
| 1046 { | 1056 { |
| 1047 Context::Scope cscope(context); | 1057 Context::Scope cscope(context); |
| 1048 Execute(); | 1058 Execute(); |
| 1049 } | 1059 } |
| 1050 context.Dispose(); | 1060 context.Dispose(); |
| 1051 } | 1061 } |
| 1052 if (!done_semaphore_.is_empty()) done_semaphore_->Signal(); | 1062 if (done_semaphore_ != NULL) done_semaphore_->Signal(); |
| 1053 } while (!Shell::options.last_run); | 1063 } while (!Shell::options.last_run); |
| 1054 isolate->Dispose(); | 1064 isolate->Dispose(); |
| 1055 } | 1065 } |
| 1056 | 1066 |
| 1057 | 1067 |
| 1058 void SourceGroup::StartExecuteInThread() { | 1068 void SourceGroup::StartExecuteInThread() { |
| 1059 if (thread_.is_empty()) { | 1069 if (thread_ == NULL) { |
| 1060 thread_ = i::SmartPointer<i::Thread>(new IsolateThread(this)); | 1070 thread_ = new IsolateThread(this); |
| 1061 thread_->Start(); | 1071 thread_->Start(); |
| 1062 } | 1072 } |
| 1063 next_semaphore_->Signal(); | 1073 next_semaphore_->Signal(); |
| 1064 } | 1074 } |
| 1065 | 1075 |
| 1066 | 1076 |
| 1067 void SourceGroup::WaitForThread() { | 1077 void SourceGroup::WaitForThread() { |
| 1068 if (thread_.is_empty()) return; | 1078 if (thread_ == NULL) return; |
| 1069 if (Shell::options.last_run) { | 1079 if (Shell::options.last_run) { |
| 1070 thread_->Join(); | 1080 thread_->Join(); |
| 1081 thread_ = NULL; | |
|
Vitaly Repeshko
2011/09/08 22:56:40
Ooops, didn't notice this edit. This looks wrong.
tfarina
2011/09/08 22:58:18
Double-free? It was here before the SmartPointer c
| |
| 1071 } else { | 1082 } else { |
| 1072 done_semaphore_->Wait(); | 1083 done_semaphore_->Wait(); |
| 1073 } | 1084 } |
| 1074 } | 1085 } |
| 1075 #endif // V8_SHARED | 1086 #endif // V8_SHARED |
| 1076 | 1087 |
| 1077 | 1088 |
| 1078 bool Shell::SetOptions(int argc, char* argv[]) { | 1089 bool Shell::SetOptions(int argc, char* argv[]) { |
| 1079 for (int i = 0; i < argc; i++) { | 1090 for (int i = 0; i < argc; i++) { |
| 1080 if (strcmp(argv[i], "--stress-opt") == 0) { | 1091 if (strcmp(argv[i], "--stress-opt") == 0) { |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1313 } | 1324 } |
| 1314 | 1325 |
| 1315 } // namespace v8 | 1326 } // namespace v8 |
| 1316 | 1327 |
| 1317 | 1328 |
| 1318 #ifndef GOOGLE3 | 1329 #ifndef GOOGLE3 |
| 1319 int main(int argc, char* argv[]) { | 1330 int main(int argc, char* argv[]) { |
| 1320 return v8::Shell::Main(argc, argv); | 1331 return v8::Shell::Main(argc, argv); |
| 1321 } | 1332 } |
| 1322 #endif | 1333 #endif |
| OLD | NEW |