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

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

Issue 2006793002: VM: Fix race between background compiler and guarded cid update. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: rework how we invalidate background compiled code Created 4 years, 6 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
« no previous file with comments | « runtime/vm/isolate.h ('k') | runtime/vm/jit_optimizer.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/text_buffer.h" 10 #include "platform/text_buffer.h"
(...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 sticky_error_(Error::null()), 815 sticky_error_(Error::null()),
816 background_compiler_(NULL), 816 background_compiler_(NULL),
817 background_compiler_disabled_depth_(0), 817 background_compiler_disabled_depth_(0),
818 pending_service_extension_calls_(GrowableObjectArray::null()), 818 pending_service_extension_calls_(GrowableObjectArray::null()),
819 registered_service_extension_handlers_(GrowableObjectArray::null()), 819 registered_service_extension_handlers_(GrowableObjectArray::null()),
820 metrics_list_head_(NULL), 820 metrics_list_head_(NULL),
821 compilation_allowed_(true), 821 compilation_allowed_(true),
822 all_classes_finalized_(false), 822 all_classes_finalized_(false),
823 next_(NULL), 823 next_(NULL),
824 pause_loop_monitor_(NULL), 824 pause_loop_monitor_(NULL),
825 field_invalidation_gen_(kInvalidGen),
826 loading_invalidation_gen_(kInvalidGen), 825 loading_invalidation_gen_(kInvalidGen),
827 top_level_parsing_count_(0), 826 top_level_parsing_count_(0),
828 field_list_mutex_(new Mutex()), 827 field_list_mutex_(new Mutex()),
829 boxed_field_list_(GrowableObjectArray::null()), 828 boxed_field_list_(GrowableObjectArray::null()),
830 disabling_field_list_(GrowableObjectArray::null()),
831 spawn_count_monitor_(new Monitor()), 829 spawn_count_monitor_(new Monitor()),
832 spawn_count_(0), 830 spawn_count_(0),
833 has_attempted_reload_(false), 831 has_attempted_reload_(false),
834 no_reload_scope_depth_(0), 832 no_reload_scope_depth_(0),
835 reload_context_(NULL) { 833 reload_context_(NULL) {
836 NOT_IN_PRODUCT(FlagsCopyFrom(api_flags)); 834 NOT_IN_PRODUCT(FlagsCopyFrom(api_flags));
837 // TODO(asiva): A Thread is not available here, need to figure out 835 // TODO(asiva): A Thread is not available here, need to figure out
838 // how the vm_tag (kEmbedderTagId) can be set, these tags need to 836 // how the vm_tag (kEmbedderTagId) can be set, these tags need to
839 // move to the OSThread structure. 837 // move to the OSThread structure.
840 set_user_tag(UserTags::kDefaultUserTag); 838 set_user_tag(UserTags::kDefaultUserTag);
(...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after
1759 // Visit the registered service extension handlers. 1757 // Visit the registered service extension handlers.
1760 visitor->VisitPointer( 1758 visitor->VisitPointer(
1761 reinterpret_cast<RawObject**>(&registered_service_extension_handlers_)); 1759 reinterpret_cast<RawObject**>(&registered_service_extension_handlers_));
1762 1760
1763 // Visit the boxed_field_list_. 1761 // Visit the boxed_field_list_.
1764 // 'boxed_field_list_' access via mutator and background compilation threads 1762 // 'boxed_field_list_' access via mutator and background compilation threads
1765 // is guarded with a monitor. This means that we can visit it only 1763 // is guarded with a monitor. This means that we can visit it only
1766 // when at safepoint or the field_list_mutex_ lock has been taken. 1764 // when at safepoint or the field_list_mutex_ lock has been taken.
1767 visitor->VisitPointer(reinterpret_cast<RawObject**>(&boxed_field_list_)); 1765 visitor->VisitPointer(reinterpret_cast<RawObject**>(&boxed_field_list_));
1768 1766
1769 // Visit the disabling_field_list.
1770 // 'disabling_field_list_' access via mutator and background compilation
1771 // threads is guarded with a monitor. This means that we can visit it only
1772 // when at safepoint or the field_list_mutex_ lock has been taken.
1773 visitor->VisitPointer(reinterpret_cast<RawObject**>(&disabling_field_list_));
1774
1775 // Visit objects in the debugger. 1767 // Visit objects in the debugger.
1776 if (FLAG_support_debugger) { 1768 if (FLAG_support_debugger) {
1777 debugger()->VisitObjectPointers(visitor); 1769 debugger()->VisitObjectPointers(visitor);
1778 } 1770 }
1779 1771
1780 NOT_IN_PRODUCT( 1772 NOT_IN_PRODUCT(
1781 // Visit objects that are being used for isolate reload. 1773 // Visit objects that are being used for isolate reload.
1782 if (reload_context() != NULL) { 1774 if (reload_context() != NULL) {
1783 reload_context()->VisitObjectPointers(visitor); 1775 reload_context()->VisitObjectPointers(visitor);
1784 } 1776 }
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
2013 pending_service_extension_calls_ = value.raw(); 2005 pending_service_extension_calls_ = value.raw();
2014 } 2006 }
2015 2007
2016 2008
2017 void Isolate::set_registered_service_extension_handlers( 2009 void Isolate::set_registered_service_extension_handlers(
2018 const GrowableObjectArray& value) { 2010 const GrowableObjectArray& value) {
2019 registered_service_extension_handlers_ = value.raw(); 2011 registered_service_extension_handlers_ = value.raw();
2020 } 2012 }
2021 2013
2022 2014
2023 // Used by mutator thread to notify background compiler which fields
2024 // triggered code invalidation.
2025 void Isolate::AddDisablingField(const Field& field) {
2026 ASSERT(Thread::Current()->IsMutatorThread());
2027 SafepointMutexLocker ml(field_list_mutex_);
2028 if (disabling_field_list_ == GrowableObjectArray::null()) {
2029 disabling_field_list_ = GrowableObjectArray::New(Heap::kOld);
2030 }
2031 const GrowableObjectArray& array =
2032 GrowableObjectArray::Handle(disabling_field_list_);
2033 array.Add(field, Heap::kOld);
2034 }
2035
2036
2037 RawField* Isolate::GetDisablingField() {
2038 ASSERT(Compiler::IsBackgroundCompilation() &&
2039 (!Isolate::Current()->HasMutatorThread() ||
2040 Isolate::Current()->mutator_thread()->IsAtSafepoint()));
2041 ASSERT(Thread::Current()->IsAtSafepoint());
2042 if (disabling_field_list_ == GrowableObjectArray::null()) {
2043 return Field::null();
2044 }
2045 const GrowableObjectArray& array =
2046 GrowableObjectArray::Handle(disabling_field_list_);
2047 if (array.Length() == 0) {
2048 return Field::null();
2049 }
2050 return Field::RawCast(array.RemoveLast());
2051 }
2052
2053
2054 void Isolate::ClearDisablingFieldList() {
2055 MutexLocker ml(field_list_mutex_);
2056 if (disabling_field_list_ == GrowableObjectArray::null()) {
2057 return;
2058 }
2059 const GrowableObjectArray& array =
2060 GrowableObjectArray::Handle(disabling_field_list_);
2061 if (array.Length() > 0) {
2062 array.SetLength(0);
2063 }
2064 }
2065
2066
2067 void Isolate::AddDeoptimizingBoxedField(const Field& field) { 2015 void Isolate::AddDeoptimizingBoxedField(const Field& field) {
2068 ASSERT(Compiler::IsBackgroundCompilation()); 2016 ASSERT(Compiler::IsBackgroundCompilation());
2069 ASSERT(field.IsOriginal()); 2017 ASSERT(field.IsOriginal());
2070 // The enclosed code allocates objects and can potentially trigger a GC, 2018 // The enclosed code allocates objects and can potentially trigger a GC,
2071 // ensure that we account for safepoints when grabbing the lock. 2019 // ensure that we account for safepoints when grabbing the lock.
2072 SafepointMutexLocker ml(field_list_mutex_); 2020 SafepointMutexLocker ml(field_list_mutex_);
2073 if (boxed_field_list_ == GrowableObjectArray::null()) { 2021 if (boxed_field_list_ == GrowableObjectArray::null()) {
2074 boxed_field_list_ = GrowableObjectArray::New(Heap::kOld); 2022 boxed_field_list_ = GrowableObjectArray::New(Heap::kOld);
2075 } 2023 }
2076 const GrowableObjectArray& array = 2024 const GrowableObjectArray& array =
(...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after
2842 void IsolateSpawnState::DecrementSpawnCount() { 2790 void IsolateSpawnState::DecrementSpawnCount() {
2843 ASSERT(spawn_count_monitor_ != NULL); 2791 ASSERT(spawn_count_monitor_ != NULL);
2844 ASSERT(spawn_count_ != NULL); 2792 ASSERT(spawn_count_ != NULL);
2845 MonitorLocker ml(spawn_count_monitor_); 2793 MonitorLocker ml(spawn_count_monitor_);
2846 ASSERT(*spawn_count_ > 0); 2794 ASSERT(*spawn_count_ > 0);
2847 *spawn_count_ = *spawn_count_ - 1; 2795 *spawn_count_ = *spawn_count_ - 1;
2848 ml.Notify(); 2796 ml.Notify();
2849 } 2797 }
2850 2798
2851 } // namespace dart 2799 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/isolate.h ('k') | runtime/vm/jit_optimizer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698