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

Unified Diff: runtime/vm/object_test.cc

Issue 496043002: Avoid calling potentially-allocating PrintJSON methods when iterating over heap. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 4 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/object_test.cc
===================================================================
--- runtime/vm/object_test.cc (revision 39459)
+++ runtime/vm/object_test.cc (working copy)
@@ -4169,10 +4169,11 @@
}
-class JSONTypeVerifier : public ObjectVisitor {
+class ObjectAccumulator : public ObjectVisitor {
public:
- JSONTypeVerifier() : ObjectVisitor(Isolate::Current()) {}
- virtual ~JSONTypeVerifier() { }
+ explicit ObjectAccumulator(GrowableArray<Object*>* objects)
+ : ObjectVisitor(Isolate::Current()), objects_(objects) {}
+ virtual ~ObjectAccumulator() { }
virtual void VisitObject(RawObject* obj) {
// Free-list elements cannot even be wrapped in handles.
if (obj->IsFreeListElement()) {
@@ -4185,18 +4186,24 @@
handle.IsLiteralToken()) {
return;
}
- JSONStream js;
- handle.PrintJSON(&js, false);
- EXPECT_SUBSTRING("\"type\":", js.ToCString());
+ objects_->Add(&handle);
}
+ private:
+ GrowableArray<Object*>* objects_;
};
TEST_CASE(PrintJSON) {
Heap* heap = Isolate::Current()->heap();
heap->CollectAllGarbage();
- JSONTypeVerifier verifier;
- heap->IterateObjects(&verifier);
+ GrowableArray<Object*> objects;
+ ObjectAccumulator acc(&objects);
+ heap->IterateObjects(&acc);
+ for (intptr_t i = 0; i < objects.length(); ++i) {
+ JSONStream js;
+ objects[i]->PrintJSON(&js, false);
+ EXPECT_SUBSTRING("\"type\":", js.ToCString());
+ }
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698