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

Unified Diff: runtime/vm/dart_api_impl.cc

Issue 905823002: Verify proper API use of acquire/release typed data (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/include/dart_api.h ('k') | runtime/vm/dart_api_state.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_api_impl.cc
===================================================================
--- runtime/vm/dart_api_impl.cc (revision 43108)
+++ runtime/vm/dart_api_impl.cc (working copy)
@@ -47,6 +47,8 @@
"Check function fingerprints");
DEFINE_FLAG(bool, trace_api, false,
"Trace invocation of API calls (debug mode only)");
+DEFINE_FLAG(bool, verify_acquired_data, false,
+ "Verify correct API acquire/release of typed data.");
ThreadLocalKey Api::api_native_key_ = OSThread::kUnsetThreadLocalKey;
Dart_Handle Api::true_handle_ = NULL;
@@ -3434,6 +3436,20 @@
*data = data_obj.DataAddr(offset_in_bytes);
}
}
+ if (FLAG_verify_acquired_data) {
+ // For now, we just verify that acquire/release are properly matched
+ // per object.
+ // TODO(koda): Copy internal data to/from a side buffer which is unmapped
+ // on release to catch use-after-release bugs.
+ const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object));
+ WeakTable* table = isolate->api_state()->acquired_table();
+ intptr_t current = table->GetValue(obj.raw());
+ if (current != 0) {
+ ASSERT(current == 1);
+ return Api::NewError("Data was already acquired for this object.");
+ }
+ table->SetValue(obj.raw(), 1);
+ }
return Api::Success();
}
@@ -3451,6 +3467,17 @@
isolate->DecrementNoGCScopeDepth();
END_NO_CALLBACK_SCOPE(isolate);
}
+ if (FLAG_verify_acquired_data) {
+ const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object));
+ WeakTable* table = isolate->api_state()->acquired_table();
+ intptr_t current = table->GetValue(obj.raw());
+ if (current != 1) {
+ ASSERT(current == 0);
+ return Api::NewError("Data was not acquired for this object.");
+ }
+ // Delete entry from table.
+ table->SetValue(obj.raw(), 0);
+ }
return Api::Success();
}
« no previous file with comments | « runtime/include/dart_api.h ('k') | runtime/vm/dart_api_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698