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

Side by Side Diff: vm/snapshot_test.cc

Issue 8673002: - Refactor the isolate callback mechanism to also include creation of the (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: '' Created 9 years 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 | « vm/isolate_win.cc ('k') | vm/thread_macos.cc » ('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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 "vm/snapshot.h" 5 #include "vm/snapshot.h"
6 6
7 #include "vm/assert.h" 7 #include "vm/assert.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/unit_test.h" 10 #include "vm/unit_test.h"
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 " return obj;\n" 325 " return obj;\n"
326 " }\n" 326 " }\n"
327 "}\n"; 327 "}\n";
328 Dart_Handle result; 328 Dart_Handle result;
329 329
330 uint8_t* buffer; 330 uint8_t* buffer;
331 331
332 // Start an Isolate, load a script and create a full snapshot. 332 // Start an Isolate, load a script and create a full snapshot.
333 Timer timer1(true, "Snapshot_test"); 333 Timer timer1(true, "Snapshot_test");
334 timer1.Start(); 334 timer1.Start();
335 Dart_CreateIsolate(NULL, NULL);
336 { 335 {
337 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 336 TestIsolateScope __test_isolate__;
338 337
339 // Create a test library and Load up a test script in it. 338 // Create a test library and Load up a test script in it.
340 TestCase::LoadTestScript(kScriptChars, NULL); 339 TestCase::LoadTestScript(kScriptChars, NULL);
341 timer1.Stop(); 340 timer1.Stop();
342 OS::PrintErr("Without Snapshot: %dus\n", timer1.TotalElapsedTime()); 341 OS::PrintErr("Without Snapshot: %dus\n", timer1.TotalElapsedTime());
343 342
344 // Write snapshot with object content. 343 // Write snapshot with object content.
345 Isolate* isolate = Isolate::Current(); 344 Isolate* isolate = Isolate::Current();
346 Zone zone(isolate); 345 Zone zone(isolate);
347 HandleScope scope(isolate); 346 HandleScope scope(isolate);
348 SnapshotWriter writer(true, &buffer, &allocator); 347 SnapshotWriter writer(true, &buffer, &allocator);
349 writer.WriteFullSnapshot(); 348 writer.WriteFullSnapshot();
350
351 Dart_ExitScope(); // Exit the Dart API scope.
352 } 349 }
353 Dart_ShutdownIsolate();
354 350
355 // Now Create another isolate using the snapshot and execute a method 351 // Now Create another isolate using the snapshot and execute a method
356 // from the script. 352 // from the script.
357 Timer timer2(true, "Snapshot_test"); 353 Timer timer2(true, "Snapshot_test");
358 timer2.Start(); 354 timer2.Start();
359 Dart_CreateIsolate(buffer, NULL); 355 TestCase::CreateTestIsolateFromSnapshot(buffer);
360 { 356 {
361 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 357 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
362 timer2.Stop(); 358 timer2.Stop();
363 OS::PrintErr("From Snapshot: %dus\n", timer2.TotalElapsedTime()); 359 OS::PrintErr("From Snapshot: %dus\n", timer2.TotalElapsedTime());
364 360
365 // Invoke a function which returns an object. 361 // Invoke a function which returns an object.
366 result = Dart_InvokeStatic(TestCase::lib(), 362 result = Dart_InvokeStatic(TestCase::lib(),
367 Dart_NewString("FieldsTest"), 363 Dart_NewString("FieldsTest"),
368 Dart_NewString("testMain"), 364 Dart_NewString("testMain"),
369 0, 365 0,
370 NULL); 366 NULL);
371 EXPECT_VALID(result); 367 EXPECT_VALID(result);
372 368 Dart_ExitScope();
373 Dart_ExitScope(); // Exit the Dart API scope.
374 } 369 }
375 Dart_ShutdownIsolate(); 370 Dart_ShutdownIsolate();
376
377 free(buffer); 371 free(buffer);
378 } 372 }
379 373
380 374
381 UNIT_TEST_CASE(FullSnapshot1) { 375 UNIT_TEST_CASE(FullSnapshot1) {
382 // This buffer has to be static for this to compile with Visual Studio. 376 // This buffer has to be static for this to compile with Visual Studio.
383 // If it is not static compilation of this file with Visual Studio takes 377 // If it is not static compilation of this file with Visual Studio takes
384 // more than 30 minutes! 378 // more than 30 minutes!
385 static const char kFullSnapshotScriptChars[] = { 379 static const char kFullSnapshotScriptChars[] = {
386 #include "snapshot_test.dat" 380 #include "snapshot_test.dat"
387 }; 381 };
388 const char* kScriptChars = kFullSnapshotScriptChars; 382 const char* kScriptChars = kFullSnapshotScriptChars;
389 383
390 uint8_t* buffer; 384 uint8_t* buffer;
391 385
392 // Start an Isolate, load a script and create a full snapshot. 386 // Start an Isolate, load a script and create a full snapshot.
393 Timer timer1(true, "Snapshot_test"); 387 Timer timer1(true, "Snapshot_test");
394 timer1.Start(); 388 timer1.Start();
395 Dart_CreateIsolate(NULL, NULL);
396 { 389 {
397 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 390 TestIsolateScope __test_isolate__;
391
398 Isolate* isolate = Isolate::Current(); 392 Isolate* isolate = Isolate::Current();
399 Zone zone(isolate); 393 Zone zone(isolate);
400 HandleScope scope(isolate); 394 HandleScope scope(isolate);
401 395
402 // Create a test library and Load up a test script in it. 396 // Create a test library and Load up a test script in it.
403 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 397 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
404 ClassFinalizer::FinalizePendingClasses(); 398 ClassFinalizer::FinalizePendingClasses();
405 timer1.Stop(); 399 timer1.Stop();
406 OS::PrintErr("Without Snapshot: %dus\n", timer1.TotalElapsedTime()); 400 OS::PrintErr("Without Snapshot: %dus\n", timer1.TotalElapsedTime());
407 401
408 // Write snapshot with object content. 402 // Write snapshot with object content.
409 SnapshotWriter writer(true, &buffer, &allocator); 403 SnapshotWriter writer(true, &buffer, &allocator);
410 writer.WriteFullSnapshot(); 404 writer.WriteFullSnapshot();
411 405
412 // Invoke a function which returns an object. 406 // Invoke a function which returns an object.
413 Dart_Handle result = Dart_InvokeStatic(lib, 407 Dart_Handle result = Dart_InvokeStatic(lib,
414 Dart_NewString("FieldsTest"), 408 Dart_NewString("FieldsTest"),
415 Dart_NewString("testMain"), 409 Dart_NewString("testMain"),
416 0, 410 0,
417 NULL); 411 NULL);
418 EXPECT_VALID(result); 412 EXPECT_VALID(result);
419
420 Dart_ExitScope(); // Exit the Dart API scope.
421 } 413 }
422 Dart_ShutdownIsolate();
423 414
424 // Now Create another isolate using the snapshot and execute a method 415 // Now Create another isolate using the snapshot and execute a method
425 // from the script. 416 // from the script.
426 Timer timer2(true, "Snapshot_test"); 417 Timer timer2(true, "Snapshot_test");
427 timer2.Start(); 418 timer2.Start();
428 Dart_CreateIsolate(buffer, NULL); 419 TestCase::CreateTestIsolateFromSnapshot(buffer);
429 { 420 {
430 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 421 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
431 timer2.Stop(); 422 timer2.Stop();
432 OS::PrintErr("From Snapshot: %dus\n", timer2.TotalElapsedTime()); 423 OS::PrintErr("From Snapshot: %dus\n", timer2.TotalElapsedTime());
433 424
434 // Invoke a function which returns an object. 425 // Invoke a function which returns an object.
435 Dart_Handle result = Dart_InvokeStatic(TestCase::lib(), 426 Dart_Handle result = Dart_InvokeStatic(TestCase::lib(),
436 Dart_NewString("FieldsTest"), 427 Dart_NewString("FieldsTest"),
437 Dart_NewString("testMain"), 428 Dart_NewString("testMain"),
438 0, 429 0,
439 NULL); 430 NULL);
440 if (Dart_IsError(result)) { 431 if (Dart_IsError(result)) {
441 // Print the error. It is probably an unhandled exception. 432 // Print the error. It is probably an unhandled exception.
442 fprintf(stderr, "%s\n", Dart_GetError(result)); 433 fprintf(stderr, "%s\n", Dart_GetError(result));
443 } 434 }
444 EXPECT_VALID(result); 435 EXPECT_VALID(result);
445 436 Dart_ExitScope();
446 Dart_ExitScope(); // Exit the Dart API scope.
447 } 437 }
448 Dart_ShutdownIsolate(); 438 Dart_ShutdownIsolate();
449
450 free(buffer); 439 free(buffer);
451 } 440 }
452 #endif // TARGET_ARCH_IA32. 441 #endif // TARGET_ARCH_IA32.
453 442
454 } // namespace dart 443 } // namespace dart
OLDNEW
« no previous file with comments | « vm/isolate_win.cc ('k') | vm/thread_macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698