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

Side by Side Diff: runtime/vm/isolate.cc

Issue 1439483003: - Add an OSThread structure which is the generic TLS structure for all C++ (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: code-review Created 5 years, 1 month 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
« no previous file with comments | « runtime/vm/isolate.h ('k') | runtime/vm/log.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 (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/isolate.h" 5 #include "vm/isolate.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "include/dart_native_api.h" 8 #include "include/dart_native_api.h"
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "platform/json.h" 10 #include "platform/json.h"
(...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 api_state_(NULL), 759 api_state_(NULL),
760 debugger_(NULL), 760 debugger_(NULL),
761 resume_request_(false), 761 resume_request_(false),
762 last_resume_timestamp_(OS::GetCurrentTimeMillis()), 762 last_resume_timestamp_(OS::GetCurrentTimeMillis()),
763 has_compiled_code_(false), 763 has_compiled_code_(false),
764 flags_(), 764 flags_(),
765 random_(), 765 random_(),
766 simulator_(NULL), 766 simulator_(NULL),
767 mutex_(new Mutex()), 767 mutex_(new Mutex()),
768 saved_stack_limit_(0), 768 saved_stack_limit_(0),
769 stack_base_(0),
770 stack_overflow_flags_(0), 769 stack_overflow_flags_(0),
771 stack_overflow_count_(0), 770 stack_overflow_count_(0),
772 message_handler_(NULL), 771 message_handler_(NULL),
773 spawn_state_(NULL), 772 spawn_state_(NULL),
774 is_runnable_(false), 773 is_runnable_(false),
775 gc_prologue_callback_(NULL), 774 gc_prologue_callback_(NULL),
776 gc_epilogue_callback_(NULL), 775 gc_epilogue_callback_(NULL),
777 defer_finalization_count_(0), 776 defer_finalization_count_(0),
778 deopt_context_(NULL), 777 deopt_context_(NULL),
779 compiler_stats_(NULL), 778 compiler_stats_(NULL),
(...skipping 11 matching lines...) Expand all
791 registered_service_extension_handlers_(GrowableObjectArray::null()), 790 registered_service_extension_handlers_(GrowableObjectArray::null()),
792 metrics_list_head_(NULL), 791 metrics_list_head_(NULL),
793 compilation_allowed_(true), 792 compilation_allowed_(true),
794 all_classes_finalized_(false), 793 all_classes_finalized_(false),
795 next_(NULL), 794 next_(NULL),
796 pause_loop_monitor_(NULL), 795 pause_loop_monitor_(NULL),
797 cha_invalidation_gen_(kInvalidGen), 796 cha_invalidation_gen_(kInvalidGen),
798 field_invalidation_gen_(kInvalidGen), 797 field_invalidation_gen_(kInvalidGen),
799 prefix_invalidation_gen_(kInvalidGen) { 798 prefix_invalidation_gen_(kInvalidGen) {
800 flags_.CopyFrom(api_flags); 799 flags_.CopyFrom(api_flags);
801 Thread::Current()->set_vm_tag(VMTag::kEmbedderTagId); 800 // TODO(asiva): A Thread is not available here, need to figure out
801 // how the vm_tag (kEmbedderTagId) can be set, these tags need to
802 // move to the OSThread structure.
802 set_user_tag(UserTags::kDefaultUserTag); 803 set_user_tag(UserTags::kDefaultUserTag);
803 } 804 }
804 805
805 #undef REUSABLE_HANDLE_SCOPE_INIT 806 #undef REUSABLE_HANDLE_SCOPE_INIT
806 #undef REUSABLE_HANDLE_INITIALIZERS 807 #undef REUSABLE_HANDLE_INITIALIZERS
807 808
808 Isolate::~Isolate() { 809 Isolate::~Isolate() {
809 free(name_); 810 free(name_);
810 free(debugger_name_); 811 free(debugger_name_);
811 delete store_buffer_; 812 delete store_buffer_;
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
980 } 981 }
981 set_debugger_name(name_prefix); 982 set_debugger_name(name_prefix);
982 if (ServiceIsolate::NameEquals(name_prefix)) { 983 if (ServiceIsolate::NameEquals(name_prefix)) {
983 name_ = strdup(name_prefix); 984 name_ = strdup(name_prefix);
984 return; 985 return;
985 } 986 }
986 name_ = OS::SCreate(NULL, "%s-%" Pd64 "", name_prefix, main_port()); 987 name_ = OS::SCreate(NULL, "%s-%" Pd64 "", name_prefix, main_port());
987 } 988 }
988 989
989 990
990 // TODO(5411455): Use flag to override default value and Validate the
991 // stack size by querying OS.
992 uword Isolate::GetSpecifiedStackSize() {
993 ASSERT(Isolate::kStackSizeBuffer < OSThread::GetMaxStackSize());
994 uword stack_size = OSThread::GetMaxStackSize() - Isolate::kStackSizeBuffer;
995 return stack_size;
996 }
997
998
999 void Isolate::SetStackLimitFromStackBase(uword stack_base) { 991 void Isolate::SetStackLimitFromStackBase(uword stack_base) {
1000 // Set stack base.
1001 stack_base_ = stack_base;
1002
1003 // Set stack limit. 992 // Set stack limit.
1004 #if defined(USING_SIMULATOR) 993 #if defined(USING_SIMULATOR)
1005 // Ignore passed-in native stack top and use Simulator stack top. 994 // Ignore passed-in native stack top and use Simulator stack top.
1006 Simulator* sim = Simulator::Current(); // May allocate a simulator. 995 Simulator* sim = Simulator::Current(); // May allocate a simulator.
1007 ASSERT(simulator() == sim); // This isolate's simulator is the current one. 996 ASSERT(simulator() == sim); // This isolate's simulator is the current one.
1008 stack_base = sim->StackTop(); 997 stack_base = sim->StackTop();
1009 // The overflow area is accounted for by the simulator. 998 // The overflow area is accounted for by the simulator.
1010 #endif 999 #endif
1011 SetStackLimit(stack_base - GetSpecifiedStackSize()); 1000 SetStackLimit(stack_base - OSThread::GetSpecifiedStackSize());
1012 } 1001 }
1013 1002
1014 1003
1015 void Isolate::SetStackLimit(uword limit) { 1004 void Isolate::SetStackLimit(uword limit) {
1016 // The isolate setting the stack limit is not necessarily the isolate which 1005 // The isolate setting the stack limit is not necessarily the isolate which
1017 // the stack limit is being set on. 1006 // the stack limit is being set on.
1018 MutexLocker ml(mutex_); 1007 MutexLocker ml(mutex_);
1019 if (stack_limit_ == saved_stack_limit_) { 1008 if (stack_limit_ == saved_stack_limit_) {
1020 // No interrupt pending, set stack_limit_ too. 1009 // No interrupt pending, set stack_limit_ too.
1021 stack_limit_ = limit; 1010 stack_limit_ = limit;
1022 } 1011 }
1023 saved_stack_limit_ = limit; 1012 saved_stack_limit_ = limit;
1024 } 1013 }
1025 1014
1026 1015
1027 void Isolate::ClearStackLimit() { 1016 void Isolate::ClearStackLimit() {
1028 SetStackLimit(~static_cast<uword>(0)); 1017 SetStackLimit(~static_cast<uword>(0));
1029 stack_base_ = 0;
1030 } 1018 }
1031 1019
1032 1020
1033 bool Isolate::GetProfilerStackBounds(uword* lower, uword* upper) const {
1034 uword stack_upper = stack_base_;
1035 if (stack_upper == 0) {
1036 return false;
1037 }
1038 uword stack_lower = stack_upper - GetSpecifiedStackSize();
1039 *lower = stack_lower;
1040 *upper = stack_upper;
1041 return true;
1042 }
1043
1044
1045 void Isolate::ScheduleInterrupts(uword interrupt_bits) { 1021 void Isolate::ScheduleInterrupts(uword interrupt_bits) {
1046 MutexLocker ml(mutex_); 1022 MutexLocker ml(mutex_);
1047 ASSERT((interrupt_bits & ~kInterruptsMask) == 0); // Must fit in mask. 1023 ASSERT((interrupt_bits & ~kInterruptsMask) == 0); // Must fit in mask.
1048 if (stack_limit_ == saved_stack_limit_) { 1024 if (stack_limit_ == saved_stack_limit_) {
1049 stack_limit_ = (~static_cast<uword>(0)) & ~kInterruptsMask; 1025 stack_limit_ = (~static_cast<uword>(0)) & ~kInterruptsMask;
1050 } 1026 }
1051 stack_limit_ |= interrupt_bits; 1027 stack_limit_ |= interrupt_bits;
1052 } 1028 }
1053 1029
1054 1030
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
1315 PortMap::PostMessage(msg); 1291 PortMap::PostMessage(msg);
1316 } 1292 }
1317 } 1293 }
1318 return listeners.Length() > 0; 1294 return listeners.Length() > 0;
1319 } 1295 }
1320 1296
1321 1297
1322 static MessageHandler::MessageStatus RunIsolate(uword parameter) { 1298 static MessageHandler::MessageStatus RunIsolate(uword parameter) {
1323 Isolate* isolate = reinterpret_cast<Isolate*>(parameter); 1299 Isolate* isolate = reinterpret_cast<Isolate*>(parameter);
1324 IsolateSpawnState* state = NULL; 1300 IsolateSpawnState* state = NULL;
1325 Thread* thread = Thread::Current();
1326 { 1301 {
1327 // TODO(turnidge): Is this locking required here at all anymore? 1302 // TODO(turnidge): Is this locking required here at all anymore?
1328 MutexLocker ml(isolate->mutex()); 1303 MutexLocker ml(isolate->mutex());
1329 state = isolate->spawn_state(); 1304 state = isolate->spawn_state();
1330 } 1305 }
1331 { 1306 {
1332 StartIsolateScope start_scope(isolate); 1307 StartIsolateScope start_scope(isolate);
1308 Thread* thread = Thread::Current();
1333 ASSERT(thread->isolate() == isolate); 1309 ASSERT(thread->isolate() == isolate);
1334 StackZone zone(thread); 1310 StackZone zone(thread);
1335 HandleScope handle_scope(thread); 1311 HandleScope handle_scope(thread);
1336 1312
1337 // If particular values were requested for this newly spawned isolate, then 1313 // If particular values were requested for this newly spawned isolate, then
1338 // they are set here before the isolate starts executing user code. 1314 // they are set here before the isolate starts executing user code.
1339 isolate->SetErrorsFatal(state->errors_are_fatal()); 1315 isolate->SetErrorsFatal(state->errors_are_fatal());
1340 if (state->on_exit_port() != ILLEGAL_PORT) { 1316 if (state->on_exit_port() != ILLEGAL_PORT) {
1341 const SendPort& listener = 1317 const SendPort& listener =
1342 SendPort::Handle(SendPort::New(state->on_exit_port())); 1318 SendPort::Handle(SendPort::New(state->on_exit_port()));
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1425 } 1401 }
1426 return MessageHandler::kOK; 1402 return MessageHandler::kOK;
1427 } 1403 }
1428 1404
1429 1405
1430 static void ShutdownIsolate(uword parameter) { 1406 static void ShutdownIsolate(uword parameter) {
1431 Isolate* isolate = reinterpret_cast<Isolate*>(parameter); 1407 Isolate* isolate = reinterpret_cast<Isolate*>(parameter);
1432 { 1408 {
1433 // Print the error if there is one. This may execute dart code to 1409 // Print the error if there is one. This may execute dart code to
1434 // print the exception object, so we need to use a StartIsolateScope. 1410 // print the exception object, so we need to use a StartIsolateScope.
1411 StartIsolateScope start_scope(isolate);
1435 Thread* thread = Thread::Current(); 1412 Thread* thread = Thread::Current();
1436 StartIsolateScope start_scope(isolate);
1437 ASSERT(thread->isolate() == isolate); 1413 ASSERT(thread->isolate() == isolate);
1438 StackZone zone(thread); 1414 StackZone zone(thread);
1439 HandleScope handle_scope(thread); 1415 HandleScope handle_scope(thread);
1440 const Error& error = Error::Handle(isolate->object_store()->sticky_error()); 1416 const Error& error = Error::Handle(isolate->object_store()->sticky_error());
1441 if (!error.IsNull() && !error.IsUnwindError()) { 1417 if (!error.IsNull() && !error.IsUnwindError()) {
1442 OS::PrintErr("in ShutdownIsolate: %s\n", error.ToErrorCString()); 1418 OS::PrintErr("in ShutdownIsolate: %s\n", error.ToErrorCString());
1443 } 1419 }
1444 Dart::RunShutdownCallback(); 1420 Dart::RunShutdownCallback();
1445 } 1421 }
1446 // Shut the isolate down. 1422 // Shut the isolate down.
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
1695 if (heap_ != NULL) { 1671 if (heap_ != NULL) {
1696 PageSpace* old_space = heap_->old_space(); 1672 PageSpace* old_space = heap_->old_space();
1697 MonitorLocker ml(old_space->tasks_lock()); 1673 MonitorLocker ml(old_space->tasks_lock());
1698 ASSERT(old_space->tasks() == 0); 1674 ASSERT(old_space->tasks() == 0);
1699 } 1675 }
1700 #endif 1676 #endif
1701 1677
1702 // TODO(5411455): For now just make sure there are no current isolates 1678 // TODO(5411455): For now just make sure there are no current isolates
1703 // as we are shutting down the isolate. 1679 // as we are shutting down the isolate.
1704 Thread::ExitIsolate(); 1680 Thread::ExitIsolate();
1705 // All threads should have exited by now.
1706 thread_registry()->CheckNotScheduled(this);
1707 } 1681 }
1708 1682
1709 1683
1710 Dart_IsolateCreateCallback Isolate::create_callback_ = NULL; 1684 Dart_IsolateCreateCallback Isolate::create_callback_ = NULL;
1711 Dart_IsolateInterruptCallback Isolate::interrupt_callback_ = NULL; 1685 Dart_IsolateInterruptCallback Isolate::interrupt_callback_ = NULL;
1712 Dart_IsolateUnhandledExceptionCallback 1686 Dart_IsolateUnhandledExceptionCallback
1713 Isolate::unhandled_exception_callback_ = NULL; 1687 Isolate::unhandled_exception_callback_ = NULL;
1714 Dart_IsolateShutdownCallback Isolate::shutdown_callback_ = NULL; 1688 Dart_IsolateShutdownCallback Isolate::shutdown_callback_ = NULL;
1715 Dart_FileOpenCallback Isolate::file_open_callback_ = NULL; 1689 Dart_FileOpenCallback Isolate::file_open_callback_ = NULL;
1716 Dart_FileReadCallback Isolate::file_read_callback_ = NULL; 1690 Dart_FileReadCallback Isolate::file_read_callback_ = NULL;
(...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after
2530 } 2504 }
2531 2505
2532 2506
2533 RawInstance* IsolateSpawnState::BuildMessage(Thread* thread) { 2507 RawInstance* IsolateSpawnState::BuildMessage(Thread* thread) {
2534 return DeserializeObject(thread, 2508 return DeserializeObject(thread,
2535 serialized_message_, serialized_message_len_); 2509 serialized_message_, serialized_message_len_);
2536 } 2510 }
2537 2511
2538 2512
2539 } // namespace dart 2513 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/isolate.h ('k') | runtime/vm/log.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698