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

Side by Side Diff: runtime/vm/thread_test.cc

Issue 2762323002: Reimplemented zone memory tracking to avoid race conditions that were causing crashes in the previo… (Closed)
Patch Set: Final change Created 3 years, 9 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 | « runtime/vm/thread.cc ('k') | runtime/vm/zone.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 #include "platform/assert.h" 5 #include "platform/assert.h"
6 #include "vm/isolate.h" 6 #include "vm/isolate.h"
7 #include "vm/lockers.h" 7 #include "vm/lockers.h"
8 #include "vm/unit_test.h" 8 #include "vm/unit_test.h"
9 #include "vm/profiler.h" 9 #include "vm/profiler.h"
10 #include "vm/safepoint.h" 10 #include "vm/safepoint.h"
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 Monitor* monitor_; 284 Monitor* monitor_;
285 intptr_t* done_count_; 285 intptr_t* done_count_;
286 bool* wait_; 286 bool* wait_;
287 }; 287 };
288 288
289 289
290 TEST_CASE(ManySimpleTasksWithZones) { 290 TEST_CASE(ManySimpleTasksWithZones) {
291 const int kTaskCount = 10; 291 const int kTaskCount = 10;
292 Monitor monitor; 292 Monitor monitor;
293 Monitor sync; 293 Monitor sync;
294 Thread* threads[kTaskCount + 1]; 294 Thread* threads[kTaskCount];
295 Isolate* isolate = Thread::Current()->isolate(); 295 Isolate* isolate = Thread::Current()->isolate();
296 intptr_t done_count = 0; 296 intptr_t done_count = 0;
297 bool wait = true; 297 bool wait = true;
298 threads[kTaskCount] = Thread::Current();
299 298
300 EXPECT(isolate->heap()->GrowthControlState()); 299 EXPECT(isolate->heap()->GrowthControlState());
301 isolate->heap()->DisableGrowthControl(); 300 isolate->heap()->DisableGrowthControl();
302 for (intptr_t i = 0; i < kTaskCount; i++) { 301 for (intptr_t i = 0; i < kTaskCount; i++) {
303 Dart::thread_pool()->Run(new SimpleTaskWithZoneAllocation( 302 Dart::thread_pool()->Run(new SimpleTaskWithZoneAllocation(
304 (i + 1), isolate, &threads[i], &sync, &monitor, &done_count, &wait)); 303 (i + 1), isolate, &threads[i], &sync, &monitor, &done_count, &wait));
305 } 304 }
306 // Wait until all spawned tasks finish their memory operations. 305 // Wait until all spawned tasks finish their memory operations.
307 { 306 {
308 MonitorLocker ml(&monitor); 307 MonitorLocker ml(&monitor);
309 while (done_count < kTaskCount) { 308 while (done_count < kTaskCount) {
310 ml.Wait(); 309 ml.Wait();
311 } 310 }
312 // Reset the done counter for use later. 311 // Reset the done counter for use later.
313 done_count = 0; 312 done_count = 0;
314 } 313 }
315 314
316 // Get the information for the current isolate. 315 // Get the information for the current isolate.
317 // We only need to check the current isolate since all tasks are spawned 316 // We only need to check the current isolate since all tasks are spawned
318 // inside this single isolate. 317 // inside this single isolate.
319 JSONStream stream; 318 JSONStream stream;
320 isolate->PrintJSON(&stream, false); 319 isolate->PrintJSON(&stream, false);
321 const char* json = stream.ToCString(); 320 const char* json = stream.ToCString();
322 321
323 Thread* current_thread = Thread::Current(); 322 Thread* current_thread = Thread::Current();
324 323
325 // Confirm all expected entries are in the JSON output. 324 // Confirm all expected entries are in the JSON output.
326 for (intptr_t i = 0; i < kTaskCount + 1; i++) { 325 for (intptr_t i = 0; i < kTaskCount; i++) {
327 Thread* thread = threads[i]; 326 Thread* thread = threads[i];
328 StackZone stack_zone(current_thread); 327 StackZone stack_zone(current_thread);
329 Zone* current_zone = current_thread->zone(); 328 Zone* current_zone = current_thread->zone();
330 329
331 // Check the thread exists and is the correct size. 330 // Check the thread exists and is the correct size.
332 char* thread_info_buf = 331 char* thread_info_buf = OS::SCreate(
333 OS::SCreate(current_zone, 332 current_zone,
334 "\"type\":\"_Thread\"," 333 "\"type\":\"_Thread\","
335 "\"id\":\"threads\\/%" Pd 334 "\"id\":\"threads\\/%" Pd
336 "\"," 335 "\","
337 "\"kind\":\"%s\"," 336 "\"kind\":\"%s\","
338 "\"_memoryHighWatermark\":\"%" Pu "\"", 337 "\"_zoneHighWatermark\":\"%" Pu
339 OSThread::ThreadIdToIntPtr(thread->os_thread()->trace_id()), 338 "\","
340 Thread::TaskKindToCString(thread->task_kind()), 339 "\"_zoneCapacity\":\"%" Pu "\"",
341 thread->memory_high_watermark()); 340 OSThread::ThreadIdToIntPtr(thread->os_thread()->trace_id()),
342 341 Thread::TaskKindToCString(thread->task_kind()),
342 thread->zone_high_watermark(), thread->current_zone_capacity());
343 EXPECT_SUBSTRING(thread_info_buf, json); 343 EXPECT_SUBSTRING(thread_info_buf, json);
344 } 344 }
345 345
346 // Unblock the tasks so they can finish. 346 // Unblock the tasks so they can finish.
347 { 347 {
348 MonitorLocker sync_ml(&sync); 348 MonitorLocker sync_ml(&sync);
349 wait = false; 349 wait = false;
350 sync_ml.NotifyAll(); 350 sync_ml.NotifyAll();
351 } 351 }
352 // Now wait for them all to exit before destroying the isolate. 352 // Now wait for them all to exit before destroying the isolate.
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 TransitionVMToBlocked transition(thread); 780 TransitionVMToBlocked transition(thread);
781 MonitorLocker ml(&done_monitor); 781 MonitorLocker ml(&done_monitor);
782 if (done) { 782 if (done) {
783 break; 783 break;
784 } 784 }
785 } 785 }
786 } 786 }
787 } 787 }
788 788
789 } // namespace dart 789 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/thread.cc ('k') | runtime/vm/zone.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698