OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 | 5 |
6 // Defined when linking against shared lib on Windows. | 6 // Defined when linking against shared lib on Windows. |
7 #if defined(USING_V8_SHARED) && !defined(V8_SHARED) | 7 #if defined(USING_V8_SHARED) && !defined(V8_SHARED) |
8 #define V8_SHARED | 8 #define V8_SHARED |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 1172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1183 #ifndef V8_SHARED | 1183 #ifndef V8_SHARED |
1184 i::Thread::Options SourceGroup::GetThreadOptions() { | 1184 i::Thread::Options SourceGroup::GetThreadOptions() { |
1185 // On some systems (OSX 10.6) the stack size default is 0.5Mb or less | 1185 // On some systems (OSX 10.6) the stack size default is 0.5Mb or less |
1186 // which is not enough to parse the big literal expressions used in tests. | 1186 // which is not enough to parse the big literal expressions used in tests. |
1187 // The stack size should be at least StackGuard::kLimitSize + some | 1187 // The stack size should be at least StackGuard::kLimitSize + some |
1188 // OS-specific padding for thread startup code. 2Mbytes seems to be enough. | 1188 // OS-specific padding for thread startup code. 2Mbytes seems to be enough. |
1189 return i::Thread::Options("IsolateThread", 2 * MB); | 1189 return i::Thread::Options("IsolateThread", 2 * MB); |
1190 } | 1190 } |
1191 | 1191 |
1192 | 1192 |
| 1193 void SuggestivelyAskForAggressiveGC() { |
| 1194 if (Shell::options.send_idle_notification) { |
| 1195 const int kLongIdlePauseInMs = 1000; |
| 1196 V8::ContextDisposedNotification(); |
| 1197 V8::IdleNotification(kLongIdlePauseInMs); |
| 1198 } |
| 1199 if (Shell::options.invoke_weak_callbacks) { |
| 1200 // By sending a low memory notifications, we will try hard to collect |
| 1201 // all garbage and will therefore also invoke all weak callbacks of |
| 1202 // actually unreachable persistent handles. |
| 1203 V8::LowMemoryNotification(); |
| 1204 } |
| 1205 } |
| 1206 |
| 1207 |
1193 void SourceGroup::ExecuteInThread() { | 1208 void SourceGroup::ExecuteInThread() { |
1194 Isolate* isolate = Isolate::New(); | 1209 Isolate* isolate = Isolate::New(); |
1195 do { | 1210 do { |
1196 next_semaphore_.Wait(); | 1211 next_semaphore_.Wait(); |
1197 { | 1212 { |
1198 Isolate::Scope iscope(isolate); | 1213 Isolate::Scope iscope(isolate); |
1199 { | 1214 { |
1200 HandleScope scope(isolate); | 1215 HandleScope scope(isolate); |
1201 PerIsolateData data(isolate); | 1216 PerIsolateData data(isolate); |
1202 Local<Context> context = Shell::CreateEvaluationContext(isolate); | 1217 Local<Context> context = Shell::CreateEvaluationContext(isolate); |
1203 { | 1218 { |
1204 Context::Scope cscope(context); | 1219 Context::Scope cscope(context); |
1205 PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate)); | 1220 PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate)); |
1206 Execute(isolate); | 1221 Execute(isolate); |
1207 } | 1222 } |
1208 } | 1223 } |
1209 if (Shell::options.send_idle_notification) { | 1224 SuggestivelyAskForAggressiveGC(); |
1210 const int kLongIdlePauseInMs = 1000; | |
1211 V8::ContextDisposedNotification(); | |
1212 V8::IdleNotification(kLongIdlePauseInMs); | |
1213 } | |
1214 } | 1225 } |
1215 done_semaphore_.Signal(); | 1226 done_semaphore_.Signal(); |
1216 } while (!Shell::options.last_run); | 1227 } while (!Shell::options.last_run); |
| 1228 |
1217 isolate->Dispose(); | 1229 isolate->Dispose(); |
1218 } | 1230 } |
1219 | 1231 |
1220 | 1232 |
1221 void SourceGroup::StartExecuteInThread() { | 1233 void SourceGroup::StartExecuteInThread() { |
1222 if (thread_ == NULL) { | 1234 if (thread_ == NULL) { |
1223 thread_ = new IsolateThread(this); | 1235 thread_ = new IsolateThread(this); |
1224 thread_->Start(); | 1236 thread_->Start(); |
1225 } | 1237 } |
1226 next_semaphore_.Signal(); | 1238 next_semaphore_.Signal(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1267 argv[i] = NULL; | 1279 argv[i] = NULL; |
1268 } else if (strcmp(argv[i], "--shell") == 0) { | 1280 } else if (strcmp(argv[i], "--shell") == 0) { |
1269 options.interactive_shell = true; | 1281 options.interactive_shell = true; |
1270 argv[i] = NULL; | 1282 argv[i] = NULL; |
1271 } else if (strcmp(argv[i], "--test") == 0) { | 1283 } else if (strcmp(argv[i], "--test") == 0) { |
1272 options.test_shell = true; | 1284 options.test_shell = true; |
1273 argv[i] = NULL; | 1285 argv[i] = NULL; |
1274 } else if (strcmp(argv[i], "--send-idle-notification") == 0) { | 1286 } else if (strcmp(argv[i], "--send-idle-notification") == 0) { |
1275 options.send_idle_notification = true; | 1287 options.send_idle_notification = true; |
1276 argv[i] = NULL; | 1288 argv[i] = NULL; |
| 1289 } else if (strcmp(argv[i], "--invoke-weak-callbacks") == 0) { |
| 1290 options.invoke_weak_callbacks = true; |
| 1291 // TODO(jochen) See issue 3351 |
| 1292 options.send_idle_notification = true; |
| 1293 argv[i] = NULL; |
1277 } else if (strcmp(argv[i], "-f") == 0) { | 1294 } else if (strcmp(argv[i], "-f") == 0) { |
1278 // Ignore any -f flags for compatibility with other stand-alone | 1295 // Ignore any -f flags for compatibility with other stand-alone |
1279 // JavaScript engines. | 1296 // JavaScript engines. |
1280 continue; | 1297 continue; |
1281 } else if (strcmp(argv[i], "--isolate") == 0) { | 1298 } else if (strcmp(argv[i], "--isolate") == 0) { |
1282 #ifdef V8_SHARED | 1299 #ifdef V8_SHARED |
1283 printf("D8 with shared library does not support multi-threading\n"); | 1300 printf("D8 with shared library does not support multi-threading\n"); |
1284 return false; | 1301 return false; |
1285 #endif // V8_SHARED | 1302 #endif // V8_SHARED |
1286 options.num_isolates++; | 1303 options.num_isolates++; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1355 InstallUtilityScript(isolate); | 1372 InstallUtilityScript(isolate); |
1356 } | 1373 } |
1357 #endif // !V8_SHARED | 1374 #endif // !V8_SHARED |
1358 } | 1375 } |
1359 { | 1376 { |
1360 Context::Scope cscope(context); | 1377 Context::Scope cscope(context); |
1361 PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate)); | 1378 PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate)); |
1362 options.isolate_sources[0].Execute(isolate); | 1379 options.isolate_sources[0].Execute(isolate); |
1363 } | 1380 } |
1364 } | 1381 } |
1365 if (options.send_idle_notification) { | 1382 SuggestivelyAskForAggressiveGC(); |
1366 const int kLongIdlePauseInMs = 1000; | |
1367 V8::ContextDisposedNotification(); | |
1368 V8::IdleNotification(kLongIdlePauseInMs); | |
1369 } | |
1370 | 1383 |
1371 #ifndef V8_SHARED | 1384 #ifndef V8_SHARED |
1372 for (int i = 1; i < options.num_isolates; ++i) { | 1385 for (int i = 1; i < options.num_isolates; ++i) { |
1373 options.isolate_sources[i].WaitForThread(); | 1386 options.isolate_sources[i].WaitForThread(); |
1374 } | 1387 } |
1375 #endif // !V8_SHARED | 1388 #endif // !V8_SHARED |
1376 return 0; | 1389 return 0; |
1377 } | 1390 } |
1378 | 1391 |
1379 | 1392 |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1542 } | 1555 } |
1543 | 1556 |
1544 } // namespace v8 | 1557 } // namespace v8 |
1545 | 1558 |
1546 | 1559 |
1547 #ifndef GOOGLE3 | 1560 #ifndef GOOGLE3 |
1548 int main(int argc, char* argv[]) { | 1561 int main(int argc, char* argv[]) { |
1549 return v8::Shell::Main(argc, argv); | 1562 return v8::Shell::Main(argc, argv); |
1550 } | 1563 } |
1551 #endif | 1564 #endif |
OLD | NEW |