| 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 1098 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1109 ArrayBuffer::New(isolate, data->data, length); | 1109 ArrayBuffer::New(isolate, data->data, length); |
| 1110 data->handle.Reset(isolate, buffer); | 1110 data->handle.Reset(isolate, buffer); |
| 1111 data->handle.SetWeak(data, ReadBufferWeakCallback); | 1111 data->handle.SetWeak(data, ReadBufferWeakCallback); |
| 1112 data->handle.MarkIndependent(); | 1112 data->handle.MarkIndependent(); |
| 1113 isolate->AdjustAmountOfExternalAllocatedMemory(length); | 1113 isolate->AdjustAmountOfExternalAllocatedMemory(length); |
| 1114 | 1114 |
| 1115 args.GetReturnValue().Set(buffer); | 1115 args.GetReturnValue().Set(buffer); |
| 1116 } | 1116 } |
| 1117 | 1117 |
| 1118 | 1118 |
| 1119 #ifndef V8_SHARED | |
| 1120 static char* ReadToken(char* data, char token) { | |
| 1121 char* next = i::OS::StrChr(data, token); | |
| 1122 if (next != NULL) { | |
| 1123 *next = '\0'; | |
| 1124 return (next + 1); | |
| 1125 } | |
| 1126 | |
| 1127 return NULL; | |
| 1128 } | |
| 1129 | |
| 1130 | |
| 1131 static char* ReadLine(char* data) { | |
| 1132 return ReadToken(data, '\n'); | |
| 1133 } | |
| 1134 | |
| 1135 | |
| 1136 static char* ReadWord(char* data) { | |
| 1137 return ReadToken(data, ' '); | |
| 1138 } | |
| 1139 #endif // !V8_SHARED | |
| 1140 | |
| 1141 | |
| 1142 // Reads a file into a v8 string. | 1119 // Reads a file into a v8 string. |
| 1143 Handle<String> Shell::ReadFile(Isolate* isolate, const char* name) { | 1120 Handle<String> Shell::ReadFile(Isolate* isolate, const char* name) { |
| 1144 int size = 0; | 1121 int size = 0; |
| 1145 char* chars = ReadChars(isolate, name, &size); | 1122 char* chars = ReadChars(isolate, name, &size); |
| 1146 if (chars == NULL) return Handle<String>(); | 1123 if (chars == NULL) return Handle<String>(); |
| 1147 Handle<String> result = | 1124 Handle<String> result = |
| 1148 String::NewFromUtf8(isolate, chars, String::kNormalString, size); | 1125 String::NewFromUtf8(isolate, chars, String::kNormalString, size); |
| 1149 delete[] chars; | 1126 delete[] chars; |
| 1150 return result; | 1127 return result; |
| 1151 } | 1128 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1165 while (true) { | 1142 while (true) { |
| 1166 HandleScope inner_scope(isolate); | 1143 HandleScope inner_scope(isolate); |
| 1167 Handle<String> input = console->Prompt(Shell::kPrompt); | 1144 Handle<String> input = console->Prompt(Shell::kPrompt); |
| 1168 if (input.IsEmpty()) break; | 1145 if (input.IsEmpty()) break; |
| 1169 ExecuteString(isolate, input, name, true, true); | 1146 ExecuteString(isolate, input, name, true, true); |
| 1170 } | 1147 } |
| 1171 printf("\n"); | 1148 printf("\n"); |
| 1172 } | 1149 } |
| 1173 | 1150 |
| 1174 | 1151 |
| 1175 #ifndef V8_SHARED | |
| 1176 class ShellThread : public i::Thread { | |
| 1177 public: | |
| 1178 // Takes ownership of the underlying char array of |files|. | |
| 1179 ShellThread(Isolate* isolate, char* files) | |
| 1180 : Thread("d8:ShellThread"), | |
| 1181 isolate_(isolate), files_(files) { } | |
| 1182 | |
| 1183 ~ShellThread() { | |
| 1184 delete[] files_; | |
| 1185 } | |
| 1186 | |
| 1187 virtual void Run(); | |
| 1188 private: | |
| 1189 Isolate* isolate_; | |
| 1190 char* files_; | |
| 1191 }; | |
| 1192 | |
| 1193 | |
| 1194 void ShellThread::Run() { | |
| 1195 char* ptr = files_; | |
| 1196 while ((ptr != NULL) && (*ptr != '\0')) { | |
| 1197 // For each newline-separated line. | |
| 1198 char* next_line = ReadLine(ptr); | |
| 1199 | |
| 1200 if (*ptr == '#') { | |
| 1201 // Skip comment lines. | |
| 1202 ptr = next_line; | |
| 1203 continue; | |
| 1204 } | |
| 1205 | |
| 1206 // Prepare the context for this thread. | |
| 1207 Locker locker(isolate_); | |
| 1208 HandleScope outer_scope(isolate_); | |
| 1209 Local<Context> thread_context = | |
| 1210 Shell::CreateEvaluationContext(isolate_); | |
| 1211 Context::Scope context_scope(thread_context); | |
| 1212 PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate_)); | |
| 1213 | |
| 1214 while ((ptr != NULL) && (*ptr != '\0')) { | |
| 1215 HandleScope inner_scope(isolate_); | |
| 1216 char* filename = ptr; | |
| 1217 ptr = ReadWord(ptr); | |
| 1218 | |
| 1219 // Skip empty strings. | |
| 1220 if (strlen(filename) == 0) { | |
| 1221 continue; | |
| 1222 } | |
| 1223 | |
| 1224 Handle<String> str = Shell::ReadFile(isolate_, filename); | |
| 1225 if (str.IsEmpty()) { | |
| 1226 printf("File '%s' not found\n", filename); | |
| 1227 Shell::Exit(1); | |
| 1228 } | |
| 1229 | |
| 1230 Shell::ExecuteString( | |
| 1231 isolate_, str, String::NewFromUtf8(isolate_, filename), false, false); | |
| 1232 } | |
| 1233 | |
| 1234 ptr = next_line; | |
| 1235 } | |
| 1236 } | |
| 1237 #endif // !V8_SHARED | |
| 1238 | |
| 1239 | |
| 1240 SourceGroup::~SourceGroup() { | 1152 SourceGroup::~SourceGroup() { |
| 1241 #ifndef V8_SHARED | 1153 #ifndef V8_SHARED |
| 1242 delete thread_; | 1154 delete thread_; |
| 1243 thread_ = NULL; | 1155 thread_ = NULL; |
| 1244 #endif // !V8_SHARED | 1156 #endif // !V8_SHARED |
| 1245 } | 1157 } |
| 1246 | 1158 |
| 1247 | 1159 |
| 1248 void SourceGroup::Execute(Isolate* isolate) { | 1160 void SourceGroup::Execute(Isolate* isolate) { |
| 1249 bool exception_was_thrown = false; | 1161 bool exception_was_thrown = false; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1353 | 1265 |
| 1354 | 1266 |
| 1355 void SetFlagsFromString(const char* flags) { | 1267 void SetFlagsFromString(const char* flags) { |
| 1356 v8::V8::SetFlagsFromString(flags, static_cast<int>(strlen(flags))); | 1268 v8::V8::SetFlagsFromString(flags, static_cast<int>(strlen(flags))); |
| 1357 } | 1269 } |
| 1358 | 1270 |
| 1359 | 1271 |
| 1360 bool Shell::SetOptions(int argc, char* argv[]) { | 1272 bool Shell::SetOptions(int argc, char* argv[]) { |
| 1361 bool logfile_per_isolate = false; | 1273 bool logfile_per_isolate = false; |
| 1362 for (int i = 0; i < argc; i++) { | 1274 for (int i = 0; i < argc; i++) { |
| 1363 // Turn '_' into '-'. | |
| 1364 // for (char* c = arg; *c != '\0'; c++) if (*c == '_') *c = '-'; | |
| 1365 if (strcmp(argv[i], "--stress-opt") == 0) { | 1275 if (strcmp(argv[i], "--stress-opt") == 0) { |
| 1366 options.stress_opt = true; | 1276 options.stress_opt = true; |
| 1367 argv[i] = NULL; | 1277 argv[i] = NULL; |
| 1368 } else if (strcmp(argv[i], "--nostress-opt") == 0) { | 1278 } else if (strcmp(argv[i], "--nostress-opt") == 0) { |
| 1369 options.stress_opt = false; | 1279 options.stress_opt = false; |
| 1370 argv[i] = NULL; | 1280 argv[i] = NULL; |
| 1371 } else if (strcmp(argv[i], "--stress-deopt") == 0) { | 1281 } else if (strcmp(argv[i], "--stress-deopt") == 0) { |
| 1372 options.stress_deopt = true; | 1282 options.stress_deopt = true; |
| 1373 argv[i] = NULL; | 1283 argv[i] = NULL; |
| 1374 } else if (strcmp(argv[i], "--mock-arraybuffer-allocator") == 0) { | 1284 } else if (strcmp(argv[i], "--mock-arraybuffer-allocator") == 0) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1393 } else if (strcmp(argv[i], "-f") == 0) { | 1303 } else if (strcmp(argv[i], "-f") == 0) { |
| 1394 // Ignore any -f flags for compatibility with other stand-alone | 1304 // Ignore any -f flags for compatibility with other stand-alone |
| 1395 // JavaScript engines. | 1305 // JavaScript engines. |
| 1396 continue; | 1306 continue; |
| 1397 } else if (strcmp(argv[i], "--isolate") == 0) { | 1307 } else if (strcmp(argv[i], "--isolate") == 0) { |
| 1398 #ifdef V8_SHARED | 1308 #ifdef V8_SHARED |
| 1399 printf("D8 with shared library does not support multi-threading\n"); | 1309 printf("D8 with shared library does not support multi-threading\n"); |
| 1400 return false; | 1310 return false; |
| 1401 #endif // V8_SHARED | 1311 #endif // V8_SHARED |
| 1402 options.num_isolates++; | 1312 options.num_isolates++; |
| 1403 } else if (strcmp(argv[i], "-p") == 0) { | |
| 1404 #ifdef V8_SHARED | |
| 1405 printf("D8 with shared library does not support multi-threading\n"); | |
| 1406 return false; | |
| 1407 #else | |
| 1408 options.num_parallel_files++; | |
| 1409 #endif // V8_SHARED | |
| 1410 } else if (strcmp(argv[i], "--dump-heap-constants") == 0) { | 1313 } else if (strcmp(argv[i], "--dump-heap-constants") == 0) { |
| 1411 #ifdef V8_SHARED | 1314 #ifdef V8_SHARED |
| 1412 printf("D8 with shared library does not support constant dumping\n"); | 1315 printf("D8 with shared library does not support constant dumping\n"); |
| 1413 return false; | 1316 return false; |
| 1414 #else | 1317 #else |
| 1415 options.dump_heap_constants = true; | 1318 options.dump_heap_constants = true; |
| 1416 argv[i] = NULL; | 1319 argv[i] = NULL; |
| 1417 #endif // V8_SHARED | 1320 #endif // V8_SHARED |
| 1418 } else if (strcmp(argv[i], "--throws") == 0) { | 1321 } else if (strcmp(argv[i], "--throws") == 0) { |
| 1419 options.expected_to_throw = true; | 1322 options.expected_to_throw = true; |
| 1420 argv[i] = NULL; | 1323 argv[i] = NULL; |
| 1421 } else if (strncmp(argv[i], "--icu-data-file=", 16) == 0) { | 1324 } else if (strncmp(argv[i], "--icu-data-file=", 16) == 0) { |
| 1422 options.icu_data_file = argv[i] + 16; | 1325 options.icu_data_file = argv[i] + 16; |
| 1423 argv[i] = NULL; | 1326 argv[i] = NULL; |
| 1424 } | 1327 } |
| 1425 #ifdef V8_SHARED | 1328 #ifdef V8_SHARED |
| 1426 else if (strcmp(argv[i], "--dump-counters") == 0) { | 1329 else if (strcmp(argv[i], "--dump-counters") == 0) { |
| 1427 printf("D8 with shared library does not include counters\n"); | 1330 printf("D8 with shared library does not include counters\n"); |
| 1428 return false; | 1331 return false; |
| 1429 } else if (strcmp(argv[i], "--debugger") == 0) { | 1332 } else if (strcmp(argv[i], "--debugger") == 0) { |
| 1430 printf("Javascript debugger not included\n"); | 1333 printf("Javascript debugger not included\n"); |
| 1431 return false; | 1334 return false; |
| 1432 } | 1335 } |
| 1433 #endif // V8_SHARED | 1336 #endif // V8_SHARED |
| 1434 } | 1337 } |
| 1435 | 1338 |
| 1436 #ifndef V8_SHARED | |
| 1437 // Run parallel threads if we are not using --isolate | |
| 1438 options.parallel_files = new char*[options.num_parallel_files]; | |
| 1439 int parallel_files_set = 0; | |
| 1440 for (int i = 1; i < argc; i++) { | |
| 1441 if (argv[i] == NULL) continue; | |
| 1442 if (strcmp(argv[i], "-p") == 0 && i + 1 < argc) { | |
| 1443 if (options.num_isolates > 1) { | |
| 1444 printf("-p is not compatible with --isolate\n"); | |
| 1445 return false; | |
| 1446 } | |
| 1447 argv[i] = NULL; | |
| 1448 i++; | |
| 1449 options.parallel_files[parallel_files_set] = argv[i]; | |
| 1450 parallel_files_set++; | |
| 1451 argv[i] = NULL; | |
| 1452 } | |
| 1453 } | |
| 1454 if (parallel_files_set != options.num_parallel_files) { | |
| 1455 printf("-p requires a file containing a list of files as parameter\n"); | |
| 1456 return false; | |
| 1457 } | |
| 1458 #endif // !V8_SHARED | |
| 1459 | |
| 1460 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); | 1339 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); |
| 1461 | 1340 |
| 1462 // Set up isolated source groups. | 1341 // Set up isolated source groups. |
| 1463 options.isolate_sources = new SourceGroup[options.num_isolates]; | 1342 options.isolate_sources = new SourceGroup[options.num_isolates]; |
| 1464 SourceGroup* current = options.isolate_sources; | 1343 SourceGroup* current = options.isolate_sources; |
| 1465 current->Begin(argv, 1); | 1344 current->Begin(argv, 1); |
| 1466 for (int i = 1; i < argc; i++) { | 1345 for (int i = 1; i < argc; i++) { |
| 1467 const char* str = argv[i]; | 1346 const char* str = argv[i]; |
| 1468 if (strcmp(str, "--isolate") == 0) { | 1347 if (strcmp(str, "--isolate") == 0) { |
| 1469 current->End(i); | 1348 current->End(i); |
| 1470 current++; | 1349 current++; |
| 1471 current->Begin(argv, i + 1); | 1350 current->Begin(argv, i + 1); |
| 1472 } else if (strncmp(argv[i], "--", 2) == 0) { | 1351 } else if (strncmp(argv[i], "--", 2) == 0) { |
| 1473 printf("Warning: unknown flag %s.\nTry --help for options\n", argv[i]); | 1352 printf("Warning: unknown flag %s.\nTry --help for options\n", argv[i]); |
| 1474 } | 1353 } |
| 1475 } | 1354 } |
| 1476 current->End(argc); | 1355 current->End(argc); |
| 1477 | 1356 |
| 1478 if (!logfile_per_isolate && options.num_isolates) { | 1357 if (!logfile_per_isolate && options.num_isolates) { |
| 1479 SetFlagsFromString("--nologfile_per_isolate"); | 1358 SetFlagsFromString("--nologfile_per_isolate"); |
| 1480 } | 1359 } |
| 1481 | 1360 |
| 1482 return true; | 1361 return true; |
| 1483 } | 1362 } |
| 1484 | 1363 |
| 1485 | 1364 |
| 1486 int Shell::RunMain(Isolate* isolate, int argc, char* argv[]) { | 1365 int Shell::RunMain(Isolate* isolate, int argc, char* argv[]) { |
| 1487 #ifndef V8_SHARED | 1366 #ifndef V8_SHARED |
| 1488 i::List<i::Thread*> threads(1); | |
| 1489 if (options.parallel_files != NULL) { | |
| 1490 for (int i = 0; i < options.num_parallel_files; i++) { | |
| 1491 char* files = NULL; | |
| 1492 { Locker lock(isolate); | |
| 1493 int size = 0; | |
| 1494 files = ReadChars(isolate, options.parallel_files[i], &size); | |
| 1495 } | |
| 1496 if (files == NULL) { | |
| 1497 printf("File list '%s' not found\n", options.parallel_files[i]); | |
| 1498 Exit(1); | |
| 1499 } | |
| 1500 ShellThread* thread = new ShellThread(isolate, files); | |
| 1501 thread->Start(); | |
| 1502 threads.Add(thread); | |
| 1503 } | |
| 1504 } | |
| 1505 for (int i = 1; i < options.num_isolates; ++i) { | 1367 for (int i = 1; i < options.num_isolates; ++i) { |
| 1506 options.isolate_sources[i].StartExecuteInThread(); | 1368 options.isolate_sources[i].StartExecuteInThread(); |
| 1507 } | 1369 } |
| 1508 #endif // !V8_SHARED | 1370 #endif // !V8_SHARED |
| 1509 { // NOLINT | 1371 { // NOLINT |
| 1510 Locker lock(isolate); | 1372 Locker lock(isolate); |
| 1511 { | 1373 { |
| 1512 HandleScope scope(isolate); | 1374 HandleScope scope(isolate); |
| 1513 Local<Context> context = CreateEvaluationContext(isolate); | 1375 Local<Context> context = CreateEvaluationContext(isolate); |
| 1514 if (options.last_run) { | 1376 if (options.last_run) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1534 V8::ContextDisposedNotification(); | 1396 V8::ContextDisposedNotification(); |
| 1535 V8::IdleNotification(kLongIdlePauseInMs); | 1397 V8::IdleNotification(kLongIdlePauseInMs); |
| 1536 } | 1398 } |
| 1537 } | 1399 } |
| 1538 } | 1400 } |
| 1539 | 1401 |
| 1540 #ifndef V8_SHARED | 1402 #ifndef V8_SHARED |
| 1541 for (int i = 1; i < options.num_isolates; ++i) { | 1403 for (int i = 1; i < options.num_isolates; ++i) { |
| 1542 options.isolate_sources[i].WaitForThread(); | 1404 options.isolate_sources[i].WaitForThread(); |
| 1543 } | 1405 } |
| 1544 | |
| 1545 for (int i = 0; i < threads.length(); i++) { | |
| 1546 i::Thread* thread = threads[i]; | |
| 1547 thread->Join(); | |
| 1548 delete thread; | |
| 1549 } | |
| 1550 #endif // !V8_SHARED | 1406 #endif // !V8_SHARED |
| 1551 return 0; | 1407 return 0; |
| 1552 } | 1408 } |
| 1553 | 1409 |
| 1554 | 1410 |
| 1555 #ifndef V8_SHARED | 1411 #ifndef V8_SHARED |
| 1556 static void DumpHeapConstants(i::Isolate* isolate) { | 1412 static void DumpHeapConstants(i::Isolate* isolate) { |
| 1557 i::Heap* heap = isolate->heap(); | 1413 i::Heap* heap = isolate->heap(); |
| 1558 | 1414 |
| 1559 // Dump the INSTANCE_TYPES table to the console. | 1415 // Dump the INSTANCE_TYPES table to the console. |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1728 } | 1584 } |
| 1729 | 1585 |
| 1730 } // namespace v8 | 1586 } // namespace v8 |
| 1731 | 1587 |
| 1732 | 1588 |
| 1733 #ifndef GOOGLE3 | 1589 #ifndef GOOGLE3 |
| 1734 int main(int argc, char* argv[]) { | 1590 int main(int argc, char* argv[]) { |
| 1735 return v8::Shell::Main(argc, argv); | 1591 return v8::Shell::Main(argc, argv); |
| 1736 } | 1592 } |
| 1737 #endif | 1593 #endif |
| OLD | NEW |