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

Side by Side Diff: runtime/vm/dart_api_state.h

Issue 2762323002: Reimplemented zone memory tracking to avoid race conditions that were causing crashes in the previo… (Closed)
Patch Set: Final change Created 3 years, 9 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 #ifndef RUNTIME_VM_DART_API_STATE_H_ 5 #ifndef RUNTIME_VM_DART_API_STATE_H_
6 #define RUNTIME_VM_DART_API_STATE_H_ 6 #define RUNTIME_VM_DART_API_STATE_H_
7 7
8 #include "include/dart_api.h" 8 #include "include/dart_api.h"
9 9
10 #include "platform/utils.h" 10 #include "platform/utils.h"
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 669
670 class ApiNativeScope { 670 class ApiNativeScope {
671 public: 671 public:
672 ApiNativeScope() { 672 ApiNativeScope() {
673 // Currently no support for nesting native scopes. 673 // Currently no support for nesting native scopes.
674 ASSERT(Current() == NULL); 674 ASSERT(Current() == NULL);
675 OSThread::SetThreadLocal(Api::api_native_key_, 675 OSThread::SetThreadLocal(Api::api_native_key_,
676 reinterpret_cast<uword>(this)); 676 reinterpret_cast<uword>(this));
677 // We manually increment the memory usage counter since there is memory 677 // We manually increment the memory usage counter since there is memory
678 // initially allocated within the zone on creation. 678 // initially allocated within the zone on creation.
679 IncrementNativeScopeMemoryUsage(zone_.GetZone()->CapacityInBytes()); 679 IncrementNativeScopeMemoryCapacity(zone_.GetZone()->CapacityInBytes());
680 } 680 }
681 681
682 ~ApiNativeScope() { 682 ~ApiNativeScope() {
683 ASSERT(Current() == this); 683 ASSERT(Current() == this);
684 OSThread::SetThreadLocal(Api::api_native_key_, 0); 684 OSThread::SetThreadLocal(Api::api_native_key_, 0);
685 // We must also manually decrement the memory usage counter since the native 685 // We must also manually decrement the memory usage counter since the native
686 // is still holding it's initial memory and ~Zone() won't be able to 686 // is still holding it's initial memory and ~Zone() won't be able to
687 // determine which memory usage counter to decrement. 687 // determine which memory usage counter to decrement.
688 DecrementNativeScopeMemoryUsage(zone_.GetZone()->CapacityInBytes()); 688 DecrementNativeScopeMemoryCapacity(zone_.GetZone()->CapacityInBytes());
689 } 689 }
690 690
691 static inline ApiNativeScope* Current() { 691 static inline ApiNativeScope* Current() {
692 return reinterpret_cast<ApiNativeScope*>( 692 return reinterpret_cast<ApiNativeScope*>(
693 OSThread::GetThreadLocal(Api::api_native_key_)); 693 OSThread::GetThreadLocal(Api::api_native_key_));
694 } 694 }
695 695
696 static intptr_t current_memory_usage() { return current_memory_usage_; } 696 static uintptr_t current_memory_usage() { return current_memory_usage_; }
697 697
698 static void IncrementNativeScopeMemoryUsage(intptr_t size) { 698 static void IncrementNativeScopeMemoryCapacity(intptr_t size) {
699 AtomicOperations::IncrementBy(&current_memory_usage_, size); 699 AtomicOperations::IncrementBy(&current_memory_usage_, size);
700 } 700 }
701 701
702 static void DecrementNativeScopeMemoryUsage(intptr_t size) { 702 static void DecrementNativeScopeMemoryCapacity(intptr_t size) {
703 AtomicOperations::DecrementBy(&current_memory_usage_, size); 703 AtomicOperations::DecrementBy(&current_memory_usage_, size);
704 } 704 }
705 705
706 Zone* zone() { 706 Zone* zone() {
707 Zone* result = zone_.GetZone(); 707 Zone* result = zone_.GetZone();
708 ASSERT(result->handles()->CountScopedHandles() == 0); 708 ASSERT(result->handles()->CountScopedHandles() == 0);
709 ASSERT(result->handles()->CountZoneHandles() == 0); 709 ASSERT(result->handles()->CountZoneHandles() == 0);
710 return result; 710 return result;
711 } 711 }
712 712
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
863 ref->set_callback(callback); 863 ref->set_callback(callback);
864 ref->set_is_queued_for_finalization(false); 864 ref->set_is_queued_for_finalization(false);
865 // This may trigger GC, so it must be called last. 865 // This may trigger GC, so it must be called last.
866 ref->SetExternalSize(external_size, isolate); 866 ref->SetExternalSize(external_size, isolate);
867 return ref; 867 return ref;
868 } 868 }
869 869
870 } // namespace dart 870 } // namespace dart
871 871
872 #endif // RUNTIME_VM_DART_API_STATE_H_ 872 #endif // RUNTIME_VM_DART_API_STATE_H_
OLDNEW
« no previous file with comments | « runtime/observatory/tests/service/get_zone_memory_info_rpc_test.dart ('k') | runtime/vm/json_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698