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

Side by Side Diff: src/d8.cc

Issue 286903004: Remove usage of Locker/Unlocker where possible. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 7 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 | « samples/lineprocessor.cc ('k') | src/d8-readline.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 Handle<String> Shell::ReadFromStdin(Isolate* isolate) { 465 Handle<String> Shell::ReadFromStdin(Isolate* isolate) {
466 static const int kBufferSize = 256; 466 static const int kBufferSize = 256;
467 char buffer[kBufferSize]; 467 char buffer[kBufferSize];
468 Handle<String> accumulator = String::NewFromUtf8(isolate, ""); 468 Handle<String> accumulator = String::NewFromUtf8(isolate, "");
469 int length; 469 int length;
470 while (true) { 470 while (true) {
471 // Continue reading if the line ends with an escape '\\' or the line has 471 // Continue reading if the line ends with an escape '\\' or the line has
472 // not been fully read into the buffer yet (does not end with '\n'). 472 // not been fully read into the buffer yet (does not end with '\n').
473 // If fgets gets an error, just give up. 473 // If fgets gets an error, just give up.
474 char* input = NULL; 474 char* input = NULL;
475 { // Release lock for blocking input. 475 input = fgets(buffer, kBufferSize, stdin);
476 Unlocker unlock(isolate);
477 input = fgets(buffer, kBufferSize, stdin);
478 }
479 if (input == NULL) return Handle<String>(); 476 if (input == NULL) return Handle<String>();
480 length = static_cast<int>(strlen(buffer)); 477 length = static_cast<int>(strlen(buffer));
481 if (length == 0) { 478 if (length == 0) {
482 return accumulator; 479 return accumulator;
483 } else if (buffer[length-1] != '\n') { 480 } else if (buffer[length-1] != '\n') {
484 accumulator = String::Concat( 481 accumulator = String::Concat(
485 accumulator, 482 accumulator,
486 String::NewFromUtf8(isolate, buffer, String::kNormalString, length)); 483 String::NewFromUtf8(isolate, buffer, String::kNormalString, length));
487 } else if (length > 1 && buffer[length-2] == '\\') { 484 } else if (length > 1 && buffer[length-2] == '\\') {
488 buffer[length-2] = '\n'; 485 buffer[length-2] = '\n';
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 } 727 }
731 728
732 729
733 void Shell::AddHistogramSample(void* histogram, int sample) { 730 void Shell::AddHistogramSample(void* histogram, int sample) {
734 Counter* counter = reinterpret_cast<Counter*>(histogram); 731 Counter* counter = reinterpret_cast<Counter*>(histogram);
735 counter->AddSample(sample); 732 counter->AddSample(sample);
736 } 733 }
737 734
738 735
739 void Shell::InstallUtilityScript(Isolate* isolate) { 736 void Shell::InstallUtilityScript(Isolate* isolate) {
740 Locker lock(isolate);
741 HandleScope scope(isolate); 737 HandleScope scope(isolate);
742 // If we use the utility context, we have to set the security tokens so that 738 // If we use the utility context, we have to set the security tokens so that
743 // utility, evaluation and debug context can all access each other. 739 // utility, evaluation and debug context can all access each other.
744 v8::Local<v8::Context> utility_context = 740 v8::Local<v8::Context> utility_context =
745 v8::Local<v8::Context>::New(isolate, utility_context_); 741 v8::Local<v8::Context>::New(isolate, utility_context_);
746 v8::Local<v8::Context> evaluation_context = 742 v8::Local<v8::Context> evaluation_context =
747 v8::Local<v8::Context>::New(isolate, evaluation_context_); 743 v8::Local<v8::Context>::New(isolate, evaluation_context_);
748 utility_context->SetSecurityToken(Undefined(isolate)); 744 utility_context->SetSecurityToken(Undefined(isolate));
749 evaluation_context->SetSecurityToken(Undefined(isolate)); 745 evaluation_context->SetSecurityToken(Undefined(isolate));
750 v8::Context::Scope context_scope(utility_context); 746 v8::Context::Scope context_scope(utility_context);
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
897 V8::SetCreateHistogramFunction(CreateHistogram); 893 V8::SetCreateHistogramFunction(CreateHistogram);
898 V8::SetAddHistogramSampleFunction(AddHistogramSample); 894 V8::SetAddHistogramSampleFunction(AddHistogramSample);
899 } 895 }
900 #endif // !V8_SHARED 896 #endif // !V8_SHARED
901 } 897 }
902 898
903 899
904 void Shell::InitializeDebugger(Isolate* isolate) { 900 void Shell::InitializeDebugger(Isolate* isolate) {
905 if (options.test_shell) return; 901 if (options.test_shell) return;
906 #ifndef V8_SHARED 902 #ifndef V8_SHARED
907 Locker lock(isolate);
908 HandleScope scope(isolate); 903 HandleScope scope(isolate);
909 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(isolate); 904 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(isolate);
910 utility_context_.Reset(isolate, 905 utility_context_.Reset(isolate,
911 Context::New(isolate, NULL, global_template)); 906 Context::New(isolate, NULL, global_template));
912 #endif // !V8_SHARED 907 #endif // !V8_SHARED
913 } 908 }
914 909
915 910
916 Local<Context> Shell::CreateEvaluationContext(Isolate* isolate) { 911 Local<Context> Shell::CreateEvaluationContext(Isolate* isolate) {
917 #ifndef V8_SHARED 912 #ifndef V8_SHARED
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 if (fstat(fileno(file), &file_stat) != 0) return NULL; 1019 if (fstat(fileno(file), &file_stat) != 0) return NULL;
1025 bool is_regular_file = ((file_stat.st_mode & S_IFREG) != 0); 1020 bool is_regular_file = ((file_stat.st_mode & S_IFREG) != 0);
1026 if (is_regular_file) return file; 1021 if (is_regular_file) return file;
1027 fclose(file); 1022 fclose(file);
1028 return NULL; 1023 return NULL;
1029 #endif 1024 #endif
1030 } 1025 }
1031 1026
1032 1027
1033 static char* ReadChars(Isolate* isolate, const char* name, int* size_out) { 1028 static char* ReadChars(Isolate* isolate, const char* name, int* size_out) {
1034 // Release the V8 lock while reading files.
1035 v8::Unlocker unlocker(isolate);
1036 FILE* file = FOpen(name, "rb"); 1029 FILE* file = FOpen(name, "rb");
1037 if (file == NULL) return NULL; 1030 if (file == NULL) return NULL;
1038 1031
1039 fseek(file, 0, SEEK_END); 1032 fseek(file, 0, SEEK_END);
1040 int size = ftell(file); 1033 int size = ftell(file);
1041 rewind(file); 1034 rewind(file);
1042 1035
1043 char* chars = new char[size + 1]; 1036 char* chars = new char[size + 1];
1044 chars[size] = '\0'; 1037 chars[size] = '\0';
1045 for (int i = 0; i < size;) { 1038 for (int i = 0; i < size;) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1105 char* chars = ReadChars(isolate, name, &size); 1098 char* chars = ReadChars(isolate, name, &size);
1106 if (chars == NULL) return Handle<String>(); 1099 if (chars == NULL) return Handle<String>();
1107 Handle<String> result = 1100 Handle<String> result =
1108 String::NewFromUtf8(isolate, chars, String::kNormalString, size); 1101 String::NewFromUtf8(isolate, chars, String::kNormalString, size);
1109 delete[] chars; 1102 delete[] chars;
1110 return result; 1103 return result;
1111 } 1104 }
1112 1105
1113 1106
1114 void Shell::RunShell(Isolate* isolate) { 1107 void Shell::RunShell(Isolate* isolate) {
1115 Locker locker(isolate);
1116 HandleScope outer_scope(isolate); 1108 HandleScope outer_scope(isolate);
1117 v8::Local<v8::Context> context = 1109 v8::Local<v8::Context> context =
1118 v8::Local<v8::Context>::New(isolate, evaluation_context_); 1110 v8::Local<v8::Context>::New(isolate, evaluation_context_);
1119 v8::Context::Scope context_scope(context); 1111 v8::Context::Scope context_scope(context);
1120 PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate)); 1112 PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate));
1121 Handle<String> name = String::NewFromUtf8(isolate, "(d8)"); 1113 Handle<String> name = String::NewFromUtf8(isolate, "(d8)");
1122 LineEditor* console = LineEditor::Get(); 1114 LineEditor* console = LineEditor::Get();
1123 printf("V8 version %s [console: %s]\n", V8::GetVersion(), console->name()); 1115 printf("V8 version %s [console: %s]\n", V8::GetVersion(), console->name());
1124 console->Open(isolate); 1116 console->Open(isolate);
1125 while (true) { 1117 while (true) {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1197 return i::Thread::Options("IsolateThread", 2 * MB); 1189 return i::Thread::Options("IsolateThread", 2 * MB);
1198 } 1190 }
1199 1191
1200 1192
1201 void SourceGroup::ExecuteInThread() { 1193 void SourceGroup::ExecuteInThread() {
1202 Isolate* isolate = Isolate::New(); 1194 Isolate* isolate = Isolate::New();
1203 do { 1195 do {
1204 next_semaphore_.Wait(); 1196 next_semaphore_.Wait();
1205 { 1197 {
1206 Isolate::Scope iscope(isolate); 1198 Isolate::Scope iscope(isolate);
1207 Locker lock(isolate);
1208 { 1199 {
1209 HandleScope scope(isolate); 1200 HandleScope scope(isolate);
1210 PerIsolateData data(isolate); 1201 PerIsolateData data(isolate);
1211 Local<Context> context = Shell::CreateEvaluationContext(isolate); 1202 Local<Context> context = Shell::CreateEvaluationContext(isolate);
1212 { 1203 {
1213 Context::Scope cscope(context); 1204 Context::Scope cscope(context);
1214 PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate)); 1205 PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate));
1215 Execute(isolate); 1206 Execute(isolate);
1216 } 1207 }
1217 } 1208 }
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1344 return true; 1335 return true;
1345 } 1336 }
1346 1337
1347 1338
1348 int Shell::RunMain(Isolate* isolate, int argc, char* argv[]) { 1339 int Shell::RunMain(Isolate* isolate, int argc, char* argv[]) {
1349 #ifndef V8_SHARED 1340 #ifndef V8_SHARED
1350 for (int i = 1; i < options.num_isolates; ++i) { 1341 for (int i = 1; i < options.num_isolates; ++i) {
1351 options.isolate_sources[i].StartExecuteInThread(); 1342 options.isolate_sources[i].StartExecuteInThread();
1352 } 1343 }
1353 #endif // !V8_SHARED 1344 #endif // !V8_SHARED
1354 { // NOLINT 1345 {
1355 Locker lock(isolate); 1346 HandleScope scope(isolate);
1347 Local<Context> context = CreateEvaluationContext(isolate);
1348 if (options.last_run) {
1349 // Keep using the same context in the interactive shell.
1350 evaluation_context_.Reset(isolate, context);
1351 #ifndef V8_SHARED
1352 // If the interactive debugger is enabled make sure to activate
1353 // it before running the files passed on the command line.
1354 if (i::FLAG_debugger) {
1355 InstallUtilityScript(isolate);
1356 }
1357 #endif // !V8_SHARED
1358 }
1356 { 1359 {
1357 HandleScope scope(isolate); 1360 Context::Scope cscope(context);
1358 Local<Context> context = CreateEvaluationContext(isolate); 1361 PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate));
1359 if (options.last_run) { 1362 options.isolate_sources[0].Execute(isolate);
1360 // Keep using the same context in the interactive shell.
1361 evaluation_context_.Reset(isolate, context);
1362 #ifndef V8_SHARED
1363 // If the interactive debugger is enabled make sure to activate
1364 // it before running the files passed on the command line.
1365 if (i::FLAG_debugger) {
1366 InstallUtilityScript(isolate);
1367 }
1368 #endif // !V8_SHARED
1369 }
1370 {
1371 Context::Scope cscope(context);
1372 PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate));
1373 options.isolate_sources[0].Execute(isolate);
1374 }
1375 } 1363 }
1376 if (!options.last_run) { 1364 }
1377 if (options.send_idle_notification) { 1365 if (!options.last_run) {
1378 const int kLongIdlePauseInMs = 1000; 1366 if (options.send_idle_notification) {
1379 V8::ContextDisposedNotification(); 1367 const int kLongIdlePauseInMs = 1000;
1380 V8::IdleNotification(kLongIdlePauseInMs); 1368 V8::ContextDisposedNotification();
1381 } 1369 V8::IdleNotification(kLongIdlePauseInMs);
1382 } 1370 }
1383 } 1371 }
1384 1372
1385 #ifndef V8_SHARED 1373 #ifndef V8_SHARED
1386 for (int i = 1; i < options.num_isolates; ++i) { 1374 for (int i = 1; i < options.num_isolates; ++i) {
1387 options.isolate_sources[i].WaitForThread(); 1375 options.isolate_sources[i].WaitForThread();
1388 } 1376 }
1389 #endif // !V8_SHARED 1377 #endif // !V8_SHARED
1390 return 0; 1378 return 0;
1391 } 1379 }
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
1557 } 1545 }
1558 1546
1559 } // namespace v8 1547 } // namespace v8
1560 1548
1561 1549
1562 #ifndef GOOGLE3 1550 #ifndef GOOGLE3
1563 int main(int argc, char* argv[]) { 1551 int main(int argc, char* argv[]) {
1564 return v8::Shell::Main(argc, argv); 1552 return v8::Shell::Main(argc, argv);
1565 } 1553 }
1566 #endif 1554 #endif
OLDNEW
« no previous file with comments | « samples/lineprocessor.cc ('k') | src/d8-readline.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698