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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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 #include "platform/globals.h" 5 #include "platform/globals.h"
6 6
7 #include "vm/assembler.h" 7 #include "vm/assembler.h"
8 #include "vm/bigint_operations.h" 8 #include "vm/bigint_operations.h"
9 #include "vm/class_finalizer.h" 9 #include "vm/class_finalizer.h"
10 #include "vm/dart_api_impl.h" 10 #include "vm/dart_api_impl.h"
(...skipping 4151 matching lines...) Expand 10 before | Expand all | Expand 10 after
4162 4162
4163 // Truncation, limit is in u-escape 4163 // Truncation, limit is in u-escape
4164 result = Dart_GetField(lib, NewString("toolong3")); 4164 result = Dart_GetField(lib, NewString("toolong3"));
4165 EXPECT_VALID(result); 4165 EXPECT_VALID(result);
4166 obj ^= Api::UnwrapHandle(result); 4166 obj ^= Api::UnwrapHandle(result);
4167 EXPECT_STREQ("\"012345678901234567890123456789\"...", 4167 EXPECT_STREQ("\"012345678901234567890123456789\"...",
4168 obj.ToUserCString(40)); 4168 obj.ToUserCString(40));
4169 } 4169 }
4170 4170
4171 4171
4172 class JSONTypeVerifier : public ObjectVisitor { 4172 class ObjectAccumulator : public ObjectVisitor {
4173 public: 4173 public:
4174 JSONTypeVerifier() : ObjectVisitor(Isolate::Current()) {} 4174 explicit ObjectAccumulator(GrowableArray<Object*>* objects)
4175 virtual ~JSONTypeVerifier() { } 4175 : ObjectVisitor(Isolate::Current()), objects_(objects) {}
4176 virtual ~ObjectAccumulator() { }
4176 virtual void VisitObject(RawObject* obj) { 4177 virtual void VisitObject(RawObject* obj) {
4177 // Free-list elements cannot even be wrapped in handles. 4178 // Free-list elements cannot even be wrapped in handles.
4178 if (obj->IsFreeListElement()) { 4179 if (obj->IsFreeListElement()) {
4179 return; 4180 return;
4180 } 4181 }
4181 Object& handle = Object::Handle(obj); 4182 Object& handle = Object::Handle(obj);
4182 // Skip some common simple objects to run in reasonable time. 4183 // Skip some common simple objects to run in reasonable time.
4183 if (handle.IsString() || 4184 if (handle.IsString() ||
4184 handle.IsArray() || 4185 handle.IsArray() ||
4185 handle.IsLiteralToken()) { 4186 handle.IsLiteralToken()) {
4186 return; 4187 return;
4187 } 4188 }
4188 JSONStream js; 4189 objects_->Add(&handle);
4189 handle.PrintJSON(&js, false);
4190 EXPECT_SUBSTRING("\"type\":", js.ToCString());
4191 } 4190 }
4191 private:
4192 GrowableArray<Object*>* objects_;
4192 }; 4193 };
4193 4194
4194 4195
4195 TEST_CASE(PrintJSON) { 4196 TEST_CASE(PrintJSON) {
4196 Heap* heap = Isolate::Current()->heap(); 4197 Heap* heap = Isolate::Current()->heap();
4197 heap->CollectAllGarbage(); 4198 heap->CollectAllGarbage();
4198 JSONTypeVerifier verifier; 4199 GrowableArray<Object*> objects;
4199 heap->IterateObjects(&verifier); 4200 ObjectAccumulator acc(&objects);
4201 heap->IterateObjects(&acc);
4202 for (intptr_t i = 0; i < objects.length(); ++i) {
4203 JSONStream js;
4204 objects[i]->PrintJSON(&js, false);
4205 EXPECT_SUBSTRING("\"type\":", js.ToCString());
4206 }
4200 } 4207 }
4201 4208
4202 4209
4203 TEST_CASE(InstanceEquality) { 4210 TEST_CASE(InstanceEquality) {
4204 // Test that Instance::OperatorEquals can call a user-defined operator==. 4211 // Test that Instance::OperatorEquals can call a user-defined operator==.
4205 const char* kScript = 4212 const char* kScript =
4206 "class A {\n" 4213 "class A {\n"
4207 " bool operator==(A other) { return true; }\n" 4214 " bool operator==(A other) { return true; }\n"
4208 "}\n" 4215 "}\n"
4209 "main() {\n" 4216 "main() {\n"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
4245 EXPECT_VALID(h_result); 4252 EXPECT_VALID(h_result);
4246 Integer& result = Integer::Handle(); 4253 Integer& result = Integer::Handle();
4247 result ^= Api::UnwrapHandle(h_result); 4254 result ^= Api::UnwrapHandle(h_result);
4248 String& foo = String::Handle(String::New("foo")); 4255 String& foo = String::Handle(String::New("foo"));
4249 Integer& expected = Integer::Handle(); 4256 Integer& expected = Integer::Handle();
4250 expected ^= foo.HashCode(); 4257 expected ^= foo.HashCode();
4251 EXPECT(result.IsIdenticalTo(expected)); 4258 EXPECT(result.IsIdenticalTo(expected));
4252 } 4259 }
4253 4260
4254 } // namespace dart 4261 } // namespace dart
OLDNEW
« 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