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

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: Descrease scopes, ASSERT on handle allocation 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') | 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) 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 563 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 ~ApiNativeScope() { 635 ~ApiNativeScope() {
630 ASSERT(Current() == this); 636 ASSERT(Current() == this);
631 OSThread::SetThreadLocal(Api::api_native_key_, 0); 637 OSThread::SetThreadLocal(Api::api_native_key_, 0);
632 } 638 }
633 639
634 static inline ApiNativeScope* Current() { 640 static inline ApiNativeScope* Current() {
635 return reinterpret_cast<ApiNativeScope*>( 641 return reinterpret_cast<ApiNativeScope*>(
636 OSThread::GetThreadLocal(Api::api_native_key_)); 642 OSThread::GetThreadLocal(Api::api_native_key_));
637 } 643 }
638 644
639 Zone* zone() { return zone_.GetZone(); } 645 Zone* zone() {
646 Zone* result = zone_.GetZone();
647 ASSERT(result->handles()->CountScopedHandles() == 0);
648 ASSERT(result->handles()->CountZoneHandles() == 0);
649 return result;
650 }
640 651
641 private: 652 private:
642 ApiZone zone_; 653 ApiZone zone_;
643 }; 654 };
644 655
645 656
646 // Api growable arrays use a zone for allocation. The constructor 657 // Api growable arrays use a zone for allocation. The constructor
647 // picks the zone from the current isolate if in an isolate 658 // picks the zone from the current isolate if in an isolate
648 // environment. When outside an isolate environment it picks the zone 659 // environment. When outside an isolate environment it picks the zone
649 // from the current native scope. 660 // from the current native scope.
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
980 ref->set_peer(peer); 991 ref->set_peer(peer);
981 ref->set_callback(callback); 992 ref->set_callback(callback);
982 // This may trigger GC, so it must be called last. 993 // This may trigger GC, so it must be called last.
983 ref->SetExternalSize(external_size, isolate); 994 ref->SetExternalSize(external_size, isolate);
984 return ref; 995 return ref;
985 } 996 }
986 997
987 } // namespace dart 998 } // namespace dart
988 999
989 #endif // VM_DART_API_STATE_H_ 1000 #endif // VM_DART_API_STATE_H_
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/handles.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698