OLD | NEW |
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 "include/dart_tools_api.h" | 7 #include "include/dart_tools_api.h" |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
10 #include "vm/clustered_snapshot.h" | 10 #include "vm/clustered_snapshot.h" |
(...skipping 1617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1628 EXPECT(Dart_IsError(result) == saved_enable_type_checks_mode); | 1628 EXPECT(Dart_IsError(result) == saved_enable_type_checks_mode); |
1629 Dart_ExitScope(); | 1629 Dart_ExitScope(); |
1630 } | 1630 } |
1631 Dart_ShutdownIsolate(); | 1631 Dart_ShutdownIsolate(); |
1632 free(full_snapshot); | 1632 free(full_snapshot); |
1633 free(script_snapshot); | 1633 free(script_snapshot); |
1634 } | 1634 } |
1635 | 1635 |
1636 | 1636 |
1637 UNIT_TEST_CASE(MismatchedSnapshotKinds) { | 1637 UNIT_TEST_CASE(MismatchedSnapshotKinds) { |
1638 const char* kScriptChars = | 1638 const char* kScriptChars = "main() { print('Hello, world!'); }"; |
1639 "main() { print('Hello, world!'); }"; | |
1640 Dart_Handle result; | 1639 Dart_Handle result; |
1641 | 1640 |
1642 uint8_t* buffer; | 1641 uint8_t* buffer; |
1643 intptr_t size; | 1642 intptr_t size; |
1644 intptr_t vm_isolate_snapshot_size; | 1643 intptr_t vm_isolate_snapshot_size; |
1645 uint8_t* isolate_snapshot = NULL; | 1644 uint8_t* isolate_snapshot = NULL; |
1646 intptr_t isolate_snapshot_size; | 1645 intptr_t isolate_snapshot_size; |
1647 uint8_t* full_snapshot = NULL; | 1646 uint8_t* full_snapshot = NULL; |
1648 uint8_t* script_snapshot = NULL; | 1647 uint8_t* script_snapshot = NULL; |
1649 | 1648 |
1650 bool saved_load_deferred_eagerly_mode = FLAG_load_deferred_eagerly; | 1649 bool saved_load_deferred_eagerly_mode = FLAG_load_deferred_eagerly; |
1651 FLAG_load_deferred_eagerly = true; | 1650 FLAG_load_deferred_eagerly = true; |
1652 bool saved_concurrent_sweep_mode = FLAG_concurrent_sweep; | 1651 bool saved_concurrent_sweep_mode = FLAG_concurrent_sweep; |
1653 FLAG_concurrent_sweep = false; | 1652 FLAG_concurrent_sweep = false; |
1654 { | 1653 { |
1655 // Start an Isolate, and create a full snapshot of it. | 1654 // Start an Isolate, and create a full snapshot of it. |
1656 TestIsolateScope __test_isolate__; | 1655 TestIsolateScope __test_isolate__; |
1657 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. | 1656 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. |
1658 | 1657 |
1659 // Write out the script snapshot. | 1658 // Write out the script snapshot. |
1660 result = Dart_CreateSnapshot(NULL, | 1659 result = Dart_CreateSnapshot(NULL, &vm_isolate_snapshot_size, |
1661 &vm_isolate_snapshot_size, | 1660 &isolate_snapshot, &isolate_snapshot_size); |
1662 &isolate_snapshot, | |
1663 &isolate_snapshot_size); | |
1664 EXPECT_VALID(result); | 1661 EXPECT_VALID(result); |
1665 full_snapshot = reinterpret_cast<uint8_t*>(malloc(isolate_snapshot_size)); | 1662 full_snapshot = reinterpret_cast<uint8_t*>(malloc(isolate_snapshot_size)); |
1666 memmove(full_snapshot, isolate_snapshot, isolate_snapshot_size); | 1663 memmove(full_snapshot, isolate_snapshot, isolate_snapshot_size); |
1667 Dart_ExitScope(); | 1664 Dart_ExitScope(); |
1668 } | 1665 } |
1669 FLAG_concurrent_sweep = saved_concurrent_sweep_mode; | 1666 FLAG_concurrent_sweep = saved_concurrent_sweep_mode; |
1670 FLAG_load_deferred_eagerly = saved_load_deferred_eagerly_mode; | 1667 FLAG_load_deferred_eagerly = saved_load_deferred_eagerly_mode; |
1671 | 1668 |
1672 { | 1669 { |
1673 // Create an Isolate using the full snapshot, load a script and create | 1670 // Create an Isolate using the full snapshot, load a script and create |
(...skipping 11 matching lines...) Expand all Loading... |
1685 EXPECT_VALID(result); | 1682 EXPECT_VALID(result); |
1686 script_snapshot = reinterpret_cast<uint8_t*>(malloc(size)); | 1683 script_snapshot = reinterpret_cast<uint8_t*>(malloc(size)); |
1687 memmove(script_snapshot, buffer, size); | 1684 memmove(script_snapshot, buffer, size); |
1688 Dart_ExitScope(); | 1685 Dart_ExitScope(); |
1689 Dart_ShutdownIsolate(); | 1686 Dart_ShutdownIsolate(); |
1690 } | 1687 } |
1691 | 1688 |
1692 { | 1689 { |
1693 // Use a script snapshot where a full snapshot is expected. | 1690 // Use a script snapshot where a full snapshot is expected. |
1694 char* error = NULL; | 1691 char* error = NULL; |
1695 Dart_Isolate isolate = Dart_CreateIsolate("script-uri", "main", | 1692 Dart_Isolate isolate = Dart_CreateIsolate( |
1696 script_snapshot, NULL, NULL, | 1693 "script-uri", "main", script_snapshot, NULL, NULL, &error); |
1697 &error); | |
1698 EXPECT(isolate == NULL); | 1694 EXPECT(isolate == NULL); |
1699 EXPECT(error != NULL); | 1695 EXPECT(error != NULL); |
1700 EXPECT_SUBSTRING("got 'script', expected 'core'", error); | 1696 EXPECT_SUBSTRING("got 'script', expected 'core'", error); |
1701 } | 1697 } |
1702 | 1698 |
1703 { | 1699 { |
1704 TestCase::CreateTestIsolateFromSnapshot(full_snapshot); | 1700 TestCase::CreateTestIsolateFromSnapshot(full_snapshot); |
1705 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. | 1701 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. |
1706 | 1702 |
1707 // Use a full snapshot where a script snapshot is expected. | 1703 // Use a full snapshot where a script snapshot is expected. |
1708 Dart_Handle result = Dart_LoadScriptFromSnapshot(full_snapshot, size); | 1704 Dart_Handle result = Dart_LoadScriptFromSnapshot(full_snapshot, size); |
1709 EXPECT_ERROR(result, "Dart_LoadScriptFromSnapshot expects parameter" | 1705 EXPECT_ERROR(result, |
1710 " 'buffer' to be a script type snapshot."); | 1706 "Dart_LoadScriptFromSnapshot expects parameter" |
| 1707 " 'buffer' to be a script type snapshot."); |
1711 | 1708 |
1712 Dart_ExitScope(); | 1709 Dart_ExitScope(); |
1713 } | 1710 } |
1714 Dart_ShutdownIsolate(); | 1711 Dart_ShutdownIsolate(); |
1715 free(full_snapshot); | 1712 free(full_snapshot); |
1716 free(script_snapshot); | 1713 free(script_snapshot); |
1717 } | 1714 } |
1718 | 1715 |
1719 | 1716 |
1720 #endif // !PRODUCT | 1717 #endif // !PRODUCT |
(...skipping 1310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3031 StackZone zone(Thread::Current()); | 3028 StackZone zone(Thread::Current()); |
3032 uint8_t* buffer; | 3029 uint8_t* buffer; |
3033 MessageWriter writer(&buffer, &zone_allocator, true); | 3030 MessageWriter writer(&buffer, &zone_allocator, true); |
3034 writer.WriteInlinedObjectHeader(kOmittedObjectId); | 3031 writer.WriteInlinedObjectHeader(kOmittedObjectId); |
3035 // For performance, we'd like single-byte headers when ids are omitted. | 3032 // For performance, we'd like single-byte headers when ids are omitted. |
3036 // If this starts failing, consider renumbering the snapshot ids. | 3033 // If this starts failing, consider renumbering the snapshot ids. |
3037 EXPECT_EQ(1, writer.BytesWritten()); | 3034 EXPECT_EQ(1, writer.BytesWritten()); |
3038 } | 3035 } |
3039 | 3036 |
3040 } // namespace dart | 3037 } // namespace dart |
OLD | NEW |