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

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

Issue 1191443008: Assert no VM handles are created in the zone that belongs to a ApiNativeScopes. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Fix null isolate. Created 5 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 | « no previous file | runtime/vm/handles.h » ('j') | runtime/vm/snapshot_test.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 VM_DART_API_STATE_H_ 5 #ifndef VM_DART_API_STATE_H_
6 #define VM_DART_API_STATE_H_ 6 #define 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 OS::PrintErr("*** Starting a new Api zone 0x%" Px "(0x%" Px ")\n", 46 OS::PrintErr("*** Starting a new Api zone 0x%" Px "(0x%" Px ")\n",
47 reinterpret_cast<intptr_t>(this), 47 reinterpret_cast<intptr_t>(this),
48 reinterpret_cast<intptr_t>(&zone_)); 48 reinterpret_cast<intptr_t>(&zone_));
49 } 49 }
50 #endif 50 #endif
51 } 51 }
52 52
53 // Delete all memory associated with the zone. 53 // Delete all memory associated with the zone.
54 ~ApiZone() { 54 ~ApiZone() {
55 Isolate* isolate = Isolate::Current(); 55 Isolate* isolate = Isolate::Current();
56 #if defined(DEBUG)
57 if (isolate == NULL) {
58 ASSERT(zone_.handles()->CountScopedHandles() == 0);
59 ASSERT(zone_.handles()->CountZoneHandles() == 0);
60 }
61 #endif
56 if ((isolate != NULL) && (isolate->current_zone() == &zone_)) { 62 if ((isolate != NULL) && (isolate->current_zone() == &zone_)) {
57 isolate->set_current_zone(zone_.previous_); 63 isolate->set_current_zone(zone_.previous_);
58 } 64 }
59 #ifdef DEBUG 65 #ifdef DEBUG
60 if (FLAG_trace_zones) { 66 if (FLAG_trace_zones) {
61 OS::PrintErr("*** Deleting Api zone 0x%" Px "(0x%" Px ")\n", 67 OS::PrintErr("*** Deleting Api zone 0x%" Px "(0x%" Px ")\n",
62 reinterpret_cast<intptr_t>(this), 68 reinterpret_cast<intptr_t>(this),
63 reinterpret_cast<intptr_t>(&zone_)); 69 reinterpret_cast<intptr_t>(&zone_));
64 } 70 }
65 #endif 71 #endif
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 ~ApiNativeScope() { 631 ~ApiNativeScope() {
626 ASSERT(Current() == this); 632 ASSERT(Current() == this);
627 OSThread::SetThreadLocal(Api::api_native_key_, 0); 633 OSThread::SetThreadLocal(Api::api_native_key_, 0);
628 } 634 }
629 635
630 static inline ApiNativeScope* Current() { 636 static inline ApiNativeScope* Current() {
631 return reinterpret_cast<ApiNativeScope*>( 637 return reinterpret_cast<ApiNativeScope*>(
632 OSThread::GetThreadLocal(Api::api_native_key_)); 638 OSThread::GetThreadLocal(Api::api_native_key_));
633 } 639 }
634 640
635 Zone* zone() { return zone_.GetZone(); } 641 Zone* zone() {
642 Zone* result = zone_.GetZone();
643 ASSERT(result->handles()->CountScopedHandles() == 0);
644 ASSERT(result->handles()->CountZoneHandles() == 0);
645 return result;
646 }
636 647
637 private: 648 private:
638 ApiZone zone_; 649 ApiZone zone_;
639 }; 650 };
640 651
641 652
642 // Api growable arrays use a zone for allocation. The constructor 653 // Api growable arrays use a zone for allocation. The constructor
643 // picks the zone from the current isolate if in an isolate 654 // picks the zone from the current isolate if in an isolate
644 // environment. When outside an isolate environment it picks the zone 655 // environment. When outside an isolate environment it picks the zone
645 // from the current native scope. 656 // from the current native scope.
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 ref->set_peer(peer); 987 ref->set_peer(peer);
977 ref->set_callback(callback); 988 ref->set_callback(callback);
978 // This may trigger GC, so it must be called last. 989 // This may trigger GC, so it must be called last.
979 ref->SetExternalSize(external_size, isolate); 990 ref->SetExternalSize(external_size, isolate);
980 return ref; 991 return ref;
981 } 992 }
982 993
983 } // namespace dart 994 } // namespace dart
984 995
985 #endif // VM_DART_API_STATE_H_ 996 #endif // VM_DART_API_STATE_H_
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/handles.h » ('j') | runtime/vm/snapshot_test.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698