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 "bin/builtin.h" | 5 #include "bin/builtin.h" |
6 #include "include/dart_api.h" | 6 #include "include/dart_api.h" |
7 #include "include/dart_mirrors_api.h" | 7 #include "include/dart_mirrors_api.h" |
8 #include "include/dart_native_api.h" | 8 #include "include/dart_native_api.h" |
9 #include "include/dart_tools_api.h" | 9 #include "include/dart_tools_api.h" |
10 #include "platform/assert.h" | 10 #include "platform/assert.h" |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 EXPECT(Dart_IsError(result)); | 367 EXPECT(Dart_IsError(result)); |
368 | 368 |
369 Dart_SetReturnValue(args, Dart_NewInteger(42)); | 369 Dart_SetReturnValue(args, Dart_NewInteger(42)); |
370 Dart_ExitScope(); | 370 Dart_ExitScope(); |
371 } | 371 } |
372 | 372 |
373 | 373 |
374 static Dart_NativeFunction CurrentStackTraceNativeLookup( | 374 static Dart_NativeFunction CurrentStackTraceNativeLookup( |
375 Dart_Handle name, int argument_count, bool* auto_setup_scope) { | 375 Dart_Handle name, int argument_count, bool* auto_setup_scope) { |
376 ASSERT(auto_setup_scope != NULL); | 376 ASSERT(auto_setup_scope != NULL); |
377 *auto_setup_scope = false; | 377 *auto_setup_scope = true; |
378 return reinterpret_cast<Dart_NativeFunction>(&CurrentStackTraceNative); | 378 return reinterpret_cast<Dart_NativeFunction>(&CurrentStackTraceNative); |
379 } | 379 } |
380 | 380 |
381 | 381 |
382 TEST_CASE(CurrentStacktraceInfo) { | 382 TEST_CASE(CurrentStacktraceInfo) { |
383 const char* kScriptChars = | 383 const char* kScriptChars = |
384 "inspectStack() native 'CurrentStackTraceNatve';\n" | 384 "inspectStack() native 'CurrentStackTraceNatve';\n" |
385 "foo(n) => n == 1 ? inspectStack() : foo(n-1);\n" | 385 "foo(n) => n == 1 ? inspectStack() : foo(n-1);\n" |
386 "testMain() => foo(50);\n"; | 386 "testMain() => foo(50);\n"; |
387 | 387 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 EXPECT(Dart_IsError(result)); | 508 EXPECT(Dart_IsError(result)); |
509 result = Dart_PropagateError(result); | 509 result = Dart_PropagateError(result); |
510 EXPECT_VALID(result); // We do not expect to reach here. | 510 EXPECT_VALID(result); // We do not expect to reach here. |
511 UNREACHABLE(); | 511 UNREACHABLE(); |
512 } | 512 } |
513 | 513 |
514 | 514 |
515 static Dart_NativeFunction PropagateError_native_lookup( | 515 static Dart_NativeFunction PropagateError_native_lookup( |
516 Dart_Handle name, int argument_count, bool* auto_setup_scope) { | 516 Dart_Handle name, int argument_count, bool* auto_setup_scope) { |
517 ASSERT(auto_setup_scope != NULL); | 517 ASSERT(auto_setup_scope != NULL); |
518 *auto_setup_scope = false; | 518 *auto_setup_scope = true; |
519 return reinterpret_cast<Dart_NativeFunction>(&PropagateErrorNative); | 519 return reinterpret_cast<Dart_NativeFunction>(&PropagateErrorNative); |
520 } | 520 } |
521 | 521 |
522 | 522 |
523 TEST_CASE(Dart_PropagateError) { | 523 TEST_CASE(Dart_PropagateError) { |
524 const char* kScriptChars = | 524 const char* kScriptChars = |
525 "raiseCompileError() {\n" | 525 "raiseCompileError() {\n" |
526 " return missing_semicolon\n" | 526 " return missing_semicolon\n" |
527 "}\n" | 527 "}\n" |
528 "\n" | 528 "\n" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 EXPECT(!Dart_IdentityEquals(five, mint)); | 608 EXPECT(!Dart_IdentityEquals(five, mint)); |
609 EXPECT(!Dart_IdentityEquals(abc, xyz)); | 609 EXPECT(!Dart_IdentityEquals(abc, xyz)); |
610 | 610 |
611 // Case where identical() is not the same as pointer equality. | 611 // Case where identical() is not the same as pointer equality. |
612 Dart_Handle nan1 = Dart_NewDouble(NAN); | 612 Dart_Handle nan1 = Dart_NewDouble(NAN); |
613 Dart_Handle nan2 = Dart_NewDouble(NAN); | 613 Dart_Handle nan2 = Dart_NewDouble(NAN); |
614 EXPECT(Dart_IdentityEquals(nan1, nan2)); | 614 EXPECT(Dart_IdentityEquals(nan1, nan2)); |
615 | 615 |
616 // Non-instance objects. | 616 // Non-instance objects. |
617 { | 617 { |
618 DARTSCOPE(thread); | 618 CHECK_API_SCOPE(thread); |
| 619 HANDLESCOPE(thread); |
619 Dart_Handle lib1 = Dart_LookupLibrary(dart_core); | 620 Dart_Handle lib1 = Dart_LookupLibrary(dart_core); |
620 Dart_Handle lib2 = Dart_LookupLibrary(dart_mirrors); | 621 Dart_Handle lib2 = Dart_LookupLibrary(dart_mirrors); |
621 | 622 |
622 EXPECT(Dart_IdentityEquals(lib1, lib1)); | 623 EXPECT(Dart_IdentityEquals(lib1, lib1)); |
623 EXPECT(Dart_IdentityEquals(lib2, lib2)); | 624 EXPECT(Dart_IdentityEquals(lib2, lib2)); |
624 EXPECT(!Dart_IdentityEquals(lib1, lib2)); | 625 EXPECT(!Dart_IdentityEquals(lib1, lib2)); |
625 | 626 |
626 // Mix instance and non-instance. | 627 // Mix instance and non-instance. |
627 EXPECT(!Dart_IdentityEquals(lib1, nan1)); | 628 EXPECT(!Dart_IdentityEquals(lib1, nan1)); |
628 EXPECT(!Dart_IdentityEquals(nan1, lib1)); | 629 EXPECT(!Dart_IdentityEquals(nan1, lib1)); |
(...skipping 24 matching lines...) Expand all Loading... |
653 | 654 |
654 // Note abc and abc_again are not required to have equal identity hashes. | 655 // Note abc and abc_again are not required to have equal identity hashes. |
655 | 656 |
656 // Case where identical() is not the same as pointer equality. | 657 // Case where identical() is not the same as pointer equality. |
657 Dart_Handle nan1 = Dart_NewDouble(NAN); | 658 Dart_Handle nan1 = Dart_NewDouble(NAN); |
658 Dart_Handle nan2 = Dart_NewDouble(NAN); | 659 Dart_Handle nan2 = Dart_NewDouble(NAN); |
659 EXPECT_EQ(Dart_IdentityHash(nan1), Dart_IdentityHash(nan2)); | 660 EXPECT_EQ(Dart_IdentityHash(nan1), Dart_IdentityHash(nan2)); |
660 | 661 |
661 // Non-instance objects. | 662 // Non-instance objects. |
662 { | 663 { |
663 DARTSCOPE(thread); | 664 CHECK_API_SCOPE(thread); |
| 665 HANDLESCOPE(thread); |
664 Dart_Handle lib1 = Dart_LookupLibrary(dart_core); | 666 Dart_Handle lib1 = Dart_LookupLibrary(dart_core); |
665 Dart_Handle lib2 = Dart_LookupLibrary(dart_mirrors); | 667 Dart_Handle lib2 = Dart_LookupLibrary(dart_mirrors); |
666 | 668 |
667 EXPECT_EQ(Dart_IdentityHash(lib1), Dart_IdentityHash(lib1)); | 669 EXPECT_EQ(Dart_IdentityHash(lib1), Dart_IdentityHash(lib1)); |
668 EXPECT_EQ(Dart_IdentityHash(lib2), Dart_IdentityHash(lib2)); | 670 EXPECT_EQ(Dart_IdentityHash(lib2), Dart_IdentityHash(lib2)); |
669 } | 671 } |
670 } | 672 } |
671 | 673 |
672 | 674 |
673 TEST_CASE(ObjectEquals) { | 675 TEST_CASE(ObjectEquals) { |
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1175 Dart_Handle obj16 = Dart_NewExternalUTF16String( | 1177 Dart_Handle obj16 = Dart_NewExternalUTF16String( |
1176 data16, | 1178 data16, |
1177 ARRAY_SIZE(data16), | 1179 ARRAY_SIZE(data16), |
1178 &peer16, | 1180 &peer16, |
1179 ExternalStringCallbackFinalizer); | 1181 ExternalStringCallbackFinalizer); |
1180 EXPECT_VALID(obj16); | 1182 EXPECT_VALID(obj16); |
1181 | 1183 |
1182 Dart_ExitScope(); | 1184 Dart_ExitScope(); |
1183 } | 1185 } |
1184 | 1186 |
1185 EXPECT_EQ(40, peer8); | 1187 { |
1186 EXPECT_EQ(41, peer16); | 1188 TransitionNativeToVM transition(thread); |
1187 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 1189 EXPECT_EQ(40, peer8); |
1188 EXPECT_EQ(40, peer8); | 1190 EXPECT_EQ(41, peer16); |
1189 EXPECT_EQ(41, peer16); | 1191 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
1190 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); | 1192 EXPECT_EQ(40, peer8); |
1191 EXPECT_EQ(80, peer8); | 1193 EXPECT_EQ(41, peer16); |
1192 EXPECT_EQ(82, peer16); | 1194 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); |
| 1195 EXPECT_EQ(80, peer8); |
| 1196 EXPECT_EQ(82, peer16); |
| 1197 } |
1193 } | 1198 } |
1194 | 1199 |
1195 | 1200 |
1196 TEST_CASE(ExternalStringPretenure) { | 1201 TEST_CASE(ExternalStringPretenure) { |
1197 { | 1202 { |
1198 Dart_EnterScope(); | 1203 Dart_EnterScope(); |
1199 static const uint8_t big_data8[16*MB] = {0, }; | 1204 static const uint8_t big_data8[16*MB] = {0, }; |
1200 Dart_Handle big8 = Dart_NewExternalLatin1String( | 1205 Dart_Handle big8 = Dart_NewExternalLatin1String( |
1201 big_data8, | 1206 big_data8, |
1202 ARRAY_SIZE(big_data8), | 1207 ARRAY_SIZE(big_data8), |
(...skipping 14 matching lines...) Expand all Loading... |
1217 NULL); | 1222 NULL); |
1218 EXPECT_VALID(small8); | 1223 EXPECT_VALID(small8); |
1219 static const uint16_t small_data16[] = {'b', 'a', 'r'}; | 1224 static const uint16_t small_data16[] = {'b', 'a', 'r'}; |
1220 Dart_Handle small16 = Dart_NewExternalUTF16String( | 1225 Dart_Handle small16 = Dart_NewExternalUTF16String( |
1221 small_data16, | 1226 small_data16, |
1222 ARRAY_SIZE(small_data16), | 1227 ARRAY_SIZE(small_data16), |
1223 NULL, | 1228 NULL, |
1224 NULL); | 1229 NULL); |
1225 EXPECT_VALID(small16); | 1230 EXPECT_VALID(small16); |
1226 { | 1231 { |
1227 DARTSCOPE(thread); | 1232 CHECK_API_SCOPE(thread); |
| 1233 HANDLESCOPE(thread); |
1228 String& handle = String::Handle(); | 1234 String& handle = String::Handle(); |
1229 handle ^= Api::UnwrapHandle(big8); | 1235 handle ^= Api::UnwrapHandle(big8); |
1230 EXPECT(handle.IsOld()); | 1236 EXPECT(handle.IsOld()); |
1231 handle ^= Api::UnwrapHandle(big16); | 1237 handle ^= Api::UnwrapHandle(big16); |
1232 EXPECT(handle.IsOld()); | 1238 EXPECT(handle.IsOld()); |
1233 handle ^= Api::UnwrapHandle(small8); | 1239 handle ^= Api::UnwrapHandle(small8); |
1234 EXPECT(handle.IsNew()); | 1240 EXPECT(handle.IsNew()); |
1235 handle ^= Api::UnwrapHandle(small16); | 1241 handle ^= Api::UnwrapHandle(small16); |
1236 EXPECT(handle.IsNew()); | 1242 EXPECT(handle.IsNew()); |
1237 } | 1243 } |
(...skipping 13 matching lines...) Expand all Loading... |
1251 kBigLength); | 1257 kBigLength); |
1252 EXPECT_VALID(big); | 1258 EXPECT_VALID(big); |
1253 static const int kSmallLength = 16*KB/8; | 1259 static const int kSmallLength = 16*KB/8; |
1254 int64_t* small_data = new int64_t[kSmallLength](); | 1260 int64_t* small_data = new int64_t[kSmallLength](); |
1255 Dart_Handle small = Dart_NewExternalTypedData( | 1261 Dart_Handle small = Dart_NewExternalTypedData( |
1256 Dart_TypedData_kInt64, | 1262 Dart_TypedData_kInt64, |
1257 small_data, | 1263 small_data, |
1258 kSmallLength); | 1264 kSmallLength); |
1259 EXPECT_VALID(small); | 1265 EXPECT_VALID(small); |
1260 { | 1266 { |
1261 DARTSCOPE(thread); | 1267 CHECK_API_SCOPE(thread); |
| 1268 HANDLESCOPE(thread); |
1262 ExternalTypedData& handle = ExternalTypedData::Handle(); | 1269 ExternalTypedData& handle = ExternalTypedData::Handle(); |
1263 handle ^= Api::UnwrapHandle(big); | 1270 handle ^= Api::UnwrapHandle(big); |
1264 EXPECT(handle.IsOld()); | 1271 EXPECT(handle.IsOld()); |
1265 handle ^= Api::UnwrapHandle(small); | 1272 handle ^= Api::UnwrapHandle(small); |
1266 EXPECT(handle.IsNew()); | 1273 EXPECT(handle.IsNew()); |
1267 } | 1274 } |
1268 Dart_ExitScope(); | 1275 Dart_ExitScope(); |
1269 delete[] big_data; | 1276 delete[] big_data; |
1270 delete[] small_data; | 1277 delete[] small_data; |
1271 } | 1278 } |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1726 EXPECT_EQ(Dart_TypedData_kByteData, Dart_GetTypeOfTypedData(byte_data)); | 1733 EXPECT_EQ(Dart_TypedData_kByteData, Dart_GetTypeOfTypedData(byte_data)); |
1727 Dart_SetReturnValue(args, byte_data); | 1734 Dart_SetReturnValue(args, byte_data); |
1728 Dart_ExitScope(); | 1735 Dart_ExitScope(); |
1729 } | 1736 } |
1730 | 1737 |
1731 | 1738 |
1732 static Dart_NativeFunction ByteDataNativeResolver(Dart_Handle name, | 1739 static Dart_NativeFunction ByteDataNativeResolver(Dart_Handle name, |
1733 int arg_count, | 1740 int arg_count, |
1734 bool* auto_setup_scope) { | 1741 bool* auto_setup_scope) { |
1735 ASSERT(auto_setup_scope != NULL); | 1742 ASSERT(auto_setup_scope != NULL); |
1736 *auto_setup_scope = false; | 1743 *auto_setup_scope = true; |
1737 return &ByteDataNativeFunction; | 1744 return &ByteDataNativeFunction; |
1738 } | 1745 } |
1739 | 1746 |
1740 | 1747 |
1741 TEST_CASE(ByteDataAccess) { | 1748 TEST_CASE(ByteDataAccess) { |
1742 const char* kScriptChars = | 1749 const char* kScriptChars = |
1743 "import 'dart:typed_data';\n" | 1750 "import 'dart:typed_data';\n" |
1744 "class Expect {\n" | 1751 "class Expect {\n" |
1745 " static equals(a, b) {\n" | 1752 " static equals(a, b) {\n" |
1746 " if (a != b) {\n" | 1753 " if (a != b) {\n" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1788 EXPECT_EQ(Dart_TypedData_kByteData, | 1795 EXPECT_EQ(Dart_TypedData_kByteData, |
1789 Dart_GetTypeOfTypedData(external_byte_data)); | 1796 Dart_GetTypeOfTypedData(external_byte_data)); |
1790 Dart_SetReturnValue(args, external_byte_data); | 1797 Dart_SetReturnValue(args, external_byte_data); |
1791 Dart_ExitScope(); | 1798 Dart_ExitScope(); |
1792 } | 1799 } |
1793 | 1800 |
1794 | 1801 |
1795 static Dart_NativeFunction ExternalByteDataNativeResolver( | 1802 static Dart_NativeFunction ExternalByteDataNativeResolver( |
1796 Dart_Handle name, int arg_count, bool* auto_setup_scope) { | 1803 Dart_Handle name, int arg_count, bool* auto_setup_scope) { |
1797 ASSERT(auto_setup_scope != NULL); | 1804 ASSERT(auto_setup_scope != NULL); |
1798 *auto_setup_scope = false; | 1805 *auto_setup_scope = true; |
1799 return &ExternalByteDataNativeFunction; | 1806 return &ExternalByteDataNativeFunction; |
1800 } | 1807 } |
1801 | 1808 |
1802 | 1809 |
1803 TEST_CASE(ExternalByteDataAccess) { | 1810 TEST_CASE(ExternalByteDataAccess) { |
1804 // TODO(asiva): Once we have getInt16LE and getInt16BE support use the | 1811 // TODO(asiva): Once we have getInt16LE and getInt16BE support use the |
1805 // appropriate getter instead of the host endian format used now. | 1812 // appropriate getter instead of the host endian format used now. |
1806 const char* kScriptChars = | 1813 const char* kScriptChars = |
1807 "import 'dart:typed_data';\n" | 1814 "import 'dart:typed_data';\n" |
1808 "class Expect {\n" | 1815 "class Expect {\n" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1862 EXPECT_EQ(Dart_TypedData_kByteData, | 1869 EXPECT_EQ(Dart_TypedData_kByteData, |
1863 Dart_GetTypeOfTypedData(external_byte_data)); | 1870 Dart_GetTypeOfTypedData(external_byte_data)); |
1864 Dart_SetReturnValue(args, external_byte_data); | 1871 Dart_SetReturnValue(args, external_byte_data); |
1865 Dart_ExitScope(); | 1872 Dart_ExitScope(); |
1866 } | 1873 } |
1867 | 1874 |
1868 | 1875 |
1869 static Dart_NativeFunction OptExternalByteDataNativeResolver( | 1876 static Dart_NativeFunction OptExternalByteDataNativeResolver( |
1870 Dart_Handle name, int arg_count, bool* auto_setup_scope) { | 1877 Dart_Handle name, int arg_count, bool* auto_setup_scope) { |
1871 ASSERT(auto_setup_scope != NULL); | 1878 ASSERT(auto_setup_scope != NULL); |
1872 *auto_setup_scope = false; | 1879 *auto_setup_scope = true; |
1873 return &OptExternalByteDataNativeFunction; | 1880 return &OptExternalByteDataNativeFunction; |
1874 } | 1881 } |
1875 | 1882 |
1876 | 1883 |
1877 TEST_CASE(OptimizedExternalByteDataAccess) { | 1884 TEST_CASE(OptimizedExternalByteDataAccess) { |
1878 const char* kScriptChars = | 1885 const char* kScriptChars = |
1879 "import 'dart:typed_data';\n" | 1886 "import 'dart:typed_data';\n" |
1880 "class Expect {\n" | 1887 "class Expect {\n" |
1881 " static equals(a, b) {\n" | 1888 " static equals(a, b) {\n" |
1882 " if (a != b) {\n" | 1889 " if (a != b) {\n" |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2304 uint8_t data[] = { 1, 2, 3, 4 }; | 2311 uint8_t data[] = { 1, 2, 3, 4 }; |
2305 Dart_Handle obj = Dart_NewExternalTypedData( | 2312 Dart_Handle obj = Dart_NewExternalTypedData( |
2306 Dart_TypedData_kUint8, | 2313 Dart_TypedData_kUint8, |
2307 data, | 2314 data, |
2308 ARRAY_SIZE(data)); | 2315 ARRAY_SIZE(data)); |
2309 Dart_NewWeakPersistentHandle( | 2316 Dart_NewWeakPersistentHandle( |
2310 obj, &peer, sizeof(data), ExternalTypedDataFinalizer); | 2317 obj, &peer, sizeof(data), ExternalTypedDataFinalizer); |
2311 EXPECT_VALID(obj); | 2318 EXPECT_VALID(obj); |
2312 Dart_ExitScope(); | 2319 Dart_ExitScope(); |
2313 } | 2320 } |
2314 EXPECT(peer == 0); | 2321 { |
2315 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2322 TransitionNativeToVM transition(thread); |
2316 EXPECT(peer == 0); | 2323 EXPECT(peer == 0); |
2317 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); | 2324 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
2318 EXPECT(peer == 42); | 2325 EXPECT(peer == 0); |
| 2326 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); |
| 2327 EXPECT(peer == 42); |
| 2328 } |
2319 } | 2329 } |
2320 | 2330 |
2321 | 2331 |
2322 static void CheckFloat32x4Data(Dart_Handle obj) { | 2332 static void CheckFloat32x4Data(Dart_Handle obj) { |
2323 void* raw_data = NULL; | 2333 void* raw_data = NULL; |
2324 intptr_t len; | 2334 intptr_t len; |
2325 Dart_TypedData_Type type; | 2335 Dart_TypedData_Type type; |
2326 EXPECT_VALID(Dart_TypedDataAcquireData(obj, &type, &raw_data, &len)); | 2336 EXPECT_VALID(Dart_TypedDataAcquireData(obj, &type, &raw_data, &len)); |
2327 EXPECT_EQ(Dart_TypedData_kFloat32x4, type); | 2337 EXPECT_EQ(Dart_TypedData_kFloat32x4, type); |
2328 EXPECT_EQ(len, 10); | 2338 EXPECT_EQ(len, 10); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2360 // Dart_NewExternalTypedData. | 2370 // Dart_NewExternalTypedData. |
2361 Dart_EnterScope(); | 2371 Dart_EnterScope(); |
2362 { | 2372 { |
2363 Dart_Handle lcl = Dart_NewExternalTypedData( | 2373 Dart_Handle lcl = Dart_NewExternalTypedData( |
2364 Dart_TypedData_kFloat32x4, data, 10); | 2374 Dart_TypedData_kFloat32x4, data, 10); |
2365 Dart_NewWeakPersistentHandle( | 2375 Dart_NewWeakPersistentHandle( |
2366 lcl, &peer, sizeof(data), ExternalTypedDataFinalizer); | 2376 lcl, &peer, sizeof(data), ExternalTypedDataFinalizer); |
2367 CheckFloat32x4Data(lcl); | 2377 CheckFloat32x4Data(lcl); |
2368 } | 2378 } |
2369 Dart_ExitScope(); | 2379 Dart_ExitScope(); |
2370 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); | 2380 { |
2371 EXPECT(peer == 42); | 2381 TransitionNativeToVM transition(thread); |
| 2382 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); |
| 2383 EXPECT(peer == 42); |
| 2384 } |
2372 } | 2385 } |
2373 | 2386 |
2374 | 2387 |
2375 // Unit test for entering a scope, creating a local handle and exiting | 2388 // Unit test for entering a scope, creating a local handle and exiting |
2376 // the scope. | 2389 // the scope. |
2377 UNIT_TEST_CASE(EnterExitScope) { | 2390 UNIT_TEST_CASE(EnterExitScope) { |
2378 TestIsolateScope __test_isolate__; | 2391 TestIsolateScope __test_isolate__; |
2379 | 2392 |
2380 Thread* thread = Thread::Current(); | 2393 Thread* thread = Thread::Current(); |
2381 EXPECT(thread != NULL); | 2394 EXPECT(thread != NULL); |
2382 ApiLocalScope* scope = thread->api_top_scope(); | 2395 ApiLocalScope* scope = thread->api_top_scope(); |
2383 Dart_EnterScope(); | 2396 Dart_EnterScope(); |
2384 { | 2397 { |
2385 EXPECT(thread->api_top_scope() != NULL); | 2398 EXPECT(thread->api_top_scope() != NULL); |
2386 DARTSCOPE(Thread::Current()); | 2399 HANDLESCOPE(thread); |
2387 const String& str1 = String::Handle(String::New("Test String")); | 2400 const String& str1 = String::Handle(String::New("Test String")); |
2388 Dart_Handle ref = Api::NewHandle(thread, str1.raw()); | 2401 Dart_Handle ref = Api::NewHandle(thread, str1.raw()); |
2389 String& str2 = String::Handle(); | 2402 String& str2 = String::Handle(); |
2390 str2 ^= Api::UnwrapHandle(ref); | 2403 str2 ^= Api::UnwrapHandle(ref); |
2391 EXPECT(str1.Equals(str2)); | 2404 EXPECT(str1.Equals(str2)); |
2392 } | 2405 } |
2393 Dart_ExitScope(); | 2406 Dart_ExitScope(); |
2394 EXPECT(scope == thread->api_top_scope()); | 2407 EXPECT(scope == thread->api_top_scope()); |
2395 } | 2408 } |
2396 | 2409 |
2397 | 2410 |
2398 // Unit test for creating and deleting persistent handles. | 2411 // Unit test for creating and deleting persistent handles. |
2399 UNIT_TEST_CASE(PersistentHandles) { | 2412 UNIT_TEST_CASE(PersistentHandles) { |
2400 const char* kTestString1 = "Test String1"; | 2413 const char* kTestString1 = "Test String1"; |
2401 const char* kTestString2 = "Test String2"; | 2414 const char* kTestString2 = "Test String2"; |
2402 TestCase::CreateTestIsolate(); | 2415 TestCase::CreateTestIsolate(); |
2403 Thread* thread = Thread::Current(); | 2416 Thread* thread = Thread::Current(); |
2404 Isolate* isolate = thread->isolate(); | 2417 Isolate* isolate = thread->isolate(); |
2405 EXPECT(isolate != NULL); | 2418 EXPECT(isolate != NULL); |
2406 ApiState* state = isolate->api_state(); | 2419 ApiState* state = isolate->api_state(); |
2407 EXPECT(state != NULL); | 2420 EXPECT(state != NULL); |
2408 ApiLocalScope* scope = thread->api_top_scope(); | 2421 ApiLocalScope* scope = thread->api_top_scope(); |
2409 Dart_PersistentHandle handles[2000]; | 2422 Dart_PersistentHandle handles[2000]; |
2410 Dart_EnterScope(); | 2423 Dart_EnterScope(); |
2411 { | 2424 { |
2412 DARTSCOPE(Thread::Current()); | 2425 CHECK_API_SCOPE(thread); |
| 2426 HANDLESCOPE(thread); |
2413 Dart_Handle ref1 = Api::NewHandle(thread, String::New(kTestString1)); | 2427 Dart_Handle ref1 = Api::NewHandle(thread, String::New(kTestString1)); |
2414 for (int i = 0; i < 1000; i++) { | 2428 for (int i = 0; i < 1000; i++) { |
2415 handles[i] = Dart_NewPersistentHandle(ref1); | 2429 handles[i] = Dart_NewPersistentHandle(ref1); |
2416 } | 2430 } |
2417 Dart_EnterScope(); | 2431 Dart_EnterScope(); |
2418 Dart_Handle ref2 = Api::NewHandle(thread, String::New(kTestString2)); | 2432 Dart_Handle ref2 = Api::NewHandle(thread, String::New(kTestString2)); |
2419 for (int i = 1000; i < 2000; i++) { | 2433 for (int i = 1000; i < 2000; i++) { |
2420 handles[i] = Dart_NewPersistentHandle(ref2); | 2434 handles[i] = Dart_NewPersistentHandle(ref2); |
2421 } | 2435 } |
2422 for (int i = 500; i < 1500; i++) { | 2436 for (int i = 500; i < 1500; i++) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2464 | 2478 |
2465 // Test that we are able to create a persistent handle from a | 2479 // Test that we are able to create a persistent handle from a |
2466 // persistent handle. | 2480 // persistent handle. |
2467 UNIT_TEST_CASE(NewPersistentHandle_FromPersistentHandle) { | 2481 UNIT_TEST_CASE(NewPersistentHandle_FromPersistentHandle) { |
2468 TestIsolateScope __test_isolate__; | 2482 TestIsolateScope __test_isolate__; |
2469 | 2483 |
2470 Isolate* isolate = Isolate::Current(); | 2484 Isolate* isolate = Isolate::Current(); |
2471 EXPECT(isolate != NULL); | 2485 EXPECT(isolate != NULL); |
2472 ApiState* state = isolate->api_state(); | 2486 ApiState* state = isolate->api_state(); |
2473 EXPECT(state != NULL); | 2487 EXPECT(state != NULL); |
2474 DARTSCOPE(Thread::Current()); | 2488 Thread* thread = Thread::Current(); |
| 2489 CHECK_API_SCOPE(thread); |
| 2490 HANDLESCOPE(thread); |
2475 | 2491 |
2476 // Start with a known persistent handle. | 2492 // Start with a known persistent handle. |
2477 Dart_PersistentHandle obj1 = Dart_NewPersistentHandle(Dart_True()); | 2493 Dart_PersistentHandle obj1 = Dart_NewPersistentHandle(Dart_True()); |
2478 EXPECT(state->IsValidPersistentHandle(obj1)); | 2494 EXPECT(state->IsValidPersistentHandle(obj1)); |
2479 | 2495 |
2480 // And use it to allocate a second persistent handle. | 2496 // And use it to allocate a second persistent handle. |
2481 Dart_Handle obj2 = Dart_HandleFromPersistent(obj1); | 2497 Dart_Handle obj2 = Dart_HandleFromPersistent(obj1); |
2482 Dart_PersistentHandle obj3 = Dart_NewPersistentHandle(obj2); | 2498 Dart_PersistentHandle obj3 = Dart_NewPersistentHandle(obj2); |
2483 EXPECT(state->IsValidPersistentHandle(obj3)); | 2499 EXPECT(state->IsValidPersistentHandle(obj3)); |
2484 | 2500 |
2485 // Make sure that the value transferred. | 2501 // Make sure that the value transferred. |
2486 Dart_Handle obj4 = Dart_HandleFromPersistent(obj3); | 2502 Dart_Handle obj4 = Dart_HandleFromPersistent(obj3); |
2487 EXPECT(Dart_IsBoolean(obj4)); | 2503 EXPECT(Dart_IsBoolean(obj4)); |
2488 bool value = false; | 2504 bool value = false; |
2489 Dart_Handle result = Dart_BooleanValue(obj4, &value); | 2505 Dart_Handle result = Dart_BooleanValue(obj4, &value); |
2490 EXPECT_VALID(result); | 2506 EXPECT_VALID(result); |
2491 EXPECT(value); | 2507 EXPECT(value); |
2492 } | 2508 } |
2493 | 2509 |
2494 | 2510 |
2495 // Test that we can assign to a persistent handle. | 2511 // Test that we can assign to a persistent handle. |
2496 UNIT_TEST_CASE(AssignToPersistentHandle) { | 2512 UNIT_TEST_CASE(AssignToPersistentHandle) { |
2497 const char* kTestString1 = "Test String1"; | 2513 const char* kTestString1 = "Test String1"; |
2498 const char* kTestString2 = "Test String2"; | 2514 const char* kTestString2 = "Test String2"; |
2499 TestIsolateScope __test_isolate__; | 2515 TestIsolateScope __test_isolate__; |
2500 | 2516 |
2501 DARTSCOPE(Thread::Current()); | 2517 Thread* T = Thread::Current(); |
| 2518 CHECK_API_SCOPE(T); |
| 2519 HANDLESCOPE(T); |
2502 Isolate* isolate = T->isolate(); | 2520 Isolate* isolate = T->isolate(); |
2503 EXPECT(isolate != NULL); | 2521 EXPECT(isolate != NULL); |
2504 ApiState* state = isolate->api_state(); | 2522 ApiState* state = isolate->api_state(); |
2505 EXPECT(state != NULL); | 2523 EXPECT(state != NULL); |
2506 String& str = String::Handle(); | 2524 String& str = String::Handle(); |
2507 | 2525 |
2508 // Start with a known persistent handle. | 2526 // Start with a known persistent handle. |
2509 Dart_Handle ref1 = Api::NewHandle(T, String::New(kTestString1)); | 2527 Dart_Handle ref1 = Api::NewHandle(T, String::New(kTestString1)); |
2510 Dart_PersistentHandle obj = Dart_NewPersistentHandle(ref1); | 2528 Dart_PersistentHandle obj = Dart_NewPersistentHandle(ref1); |
2511 EXPECT(state->IsValidPersistentHandle(obj)); | 2529 EXPECT(state->IsValidPersistentHandle(obj)); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2574 { | 2592 { |
2575 Dart_EnterScope(); | 2593 Dart_EnterScope(); |
2576 | 2594 |
2577 // Create an object in new space. | 2595 // Create an object in new space. |
2578 Dart_Handle new_ref = NewString("new string"); | 2596 Dart_Handle new_ref = NewString("new string"); |
2579 EXPECT_VALID(new_ref); | 2597 EXPECT_VALID(new_ref); |
2580 | 2598 |
2581 // Create an object in old space. | 2599 // Create an object in old space. |
2582 Dart_Handle old_ref; | 2600 Dart_Handle old_ref; |
2583 { | 2601 { |
2584 DARTSCOPE(Thread::Current()); | 2602 CHECK_API_SCOPE(thread); |
| 2603 HANDLESCOPE(thread); |
2585 old_ref = Api::NewHandle(thread, String::New("old string", Heap::kOld)); | 2604 old_ref = Api::NewHandle(thread, String::New("old string", Heap::kOld)); |
2586 EXPECT_VALID(old_ref); | 2605 EXPECT_VALID(old_ref); |
2587 } | 2606 } |
2588 | 2607 |
2589 // Create a weak ref to the new space object. | 2608 // Create a weak ref to the new space object. |
2590 weak_new_ref = Dart_NewWeakPersistentHandle(new_ref, | 2609 weak_new_ref = Dart_NewWeakPersistentHandle(new_ref, |
2591 NULL, | 2610 NULL, |
2592 0, | 2611 0, |
2593 WeakPersistentHandleCallback); | 2612 WeakPersistentHandleCallback); |
2594 EXPECT_VALID(AsHandle(weak_new_ref)); | 2613 EXPECT_VALID(AsHandle(weak_new_ref)); |
2595 EXPECT(!Dart_IsNull(AsHandle(weak_new_ref))); | 2614 EXPECT(!Dart_IsNull(AsHandle(weak_new_ref))); |
2596 | 2615 |
2597 // Create a weak ref to the old space object. | 2616 // Create a weak ref to the old space object. |
2598 weak_old_ref = Dart_NewWeakPersistentHandle(old_ref, | 2617 weak_old_ref = Dart_NewWeakPersistentHandle(old_ref, |
2599 NULL, | 2618 NULL, |
2600 0, | 2619 0, |
2601 WeakPersistentHandleCallback); | 2620 WeakPersistentHandleCallback); |
2602 EXPECT_VALID(AsHandle(weak_old_ref)); | 2621 EXPECT_VALID(AsHandle(weak_old_ref)); |
2603 EXPECT(!Dart_IsNull(AsHandle(weak_old_ref))); | 2622 EXPECT(!Dart_IsNull(AsHandle(weak_old_ref))); |
2604 | 2623 |
2605 // Garbage collect new space. | 2624 { |
2606 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); | 2625 TransitionNativeToVM transition(thread); |
| 2626 // Garbage collect new space. |
| 2627 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); |
| 2628 } |
2607 | 2629 |
2608 // Nothing should be invalidated or cleared. | 2630 // Nothing should be invalidated or cleared. |
2609 EXPECT_VALID(new_ref); | 2631 EXPECT_VALID(new_ref); |
2610 EXPECT(!Dart_IsNull(new_ref)); | 2632 EXPECT(!Dart_IsNull(new_ref)); |
2611 EXPECT_VALID(old_ref); | 2633 EXPECT_VALID(old_ref); |
2612 EXPECT(!Dart_IsNull(old_ref)); | 2634 EXPECT(!Dart_IsNull(old_ref)); |
2613 | 2635 |
2614 EXPECT_VALID(AsHandle(weak_new_ref)); | 2636 EXPECT_VALID(AsHandle(weak_new_ref)); |
2615 EXPECT(!Dart_IsNull(AsHandle(weak_new_ref))); | 2637 EXPECT(!Dart_IsNull(AsHandle(weak_new_ref))); |
2616 EXPECT(Dart_IdentityEquals(new_ref, AsHandle(weak_new_ref))); | 2638 EXPECT(Dart_IdentityEquals(new_ref, AsHandle(weak_new_ref))); |
2617 | 2639 |
2618 EXPECT_VALID(AsHandle(weak_old_ref)); | 2640 EXPECT_VALID(AsHandle(weak_old_ref)); |
2619 EXPECT(!Dart_IsNull(AsHandle(weak_old_ref))); | 2641 EXPECT(!Dart_IsNull(AsHandle(weak_old_ref))); |
2620 EXPECT(Dart_IdentityEquals(old_ref, AsHandle(weak_old_ref))); | 2642 EXPECT(Dart_IdentityEquals(old_ref, AsHandle(weak_old_ref))); |
2621 | 2643 |
2622 // Garbage collect old space. | 2644 { |
2623 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2645 TransitionNativeToVM transition(thread); |
| 2646 // Garbage collect old space. |
| 2647 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 2648 } |
2624 | 2649 |
2625 // Nothing should be invalidated or cleared. | 2650 // Nothing should be invalidated or cleared. |
2626 EXPECT_VALID(new_ref); | 2651 EXPECT_VALID(new_ref); |
2627 EXPECT(!Dart_IsNull(new_ref)); | 2652 EXPECT(!Dart_IsNull(new_ref)); |
2628 EXPECT_VALID(old_ref); | 2653 EXPECT_VALID(old_ref); |
2629 EXPECT(!Dart_IsNull(old_ref)); | 2654 EXPECT(!Dart_IsNull(old_ref)); |
2630 | 2655 |
2631 EXPECT_VALID(AsHandle(weak_new_ref)); | 2656 EXPECT_VALID(AsHandle(weak_new_ref)); |
2632 EXPECT(!Dart_IsNull(AsHandle(weak_new_ref))); | 2657 EXPECT(!Dart_IsNull(AsHandle(weak_new_ref))); |
2633 EXPECT(Dart_IdentityEquals(new_ref, AsHandle(weak_new_ref))); | 2658 EXPECT(Dart_IdentityEquals(new_ref, AsHandle(weak_new_ref))); |
2634 | 2659 |
2635 EXPECT_VALID(AsHandle(weak_old_ref)); | 2660 EXPECT_VALID(AsHandle(weak_old_ref)); |
2636 EXPECT(!Dart_IsNull(AsHandle(weak_old_ref))); | 2661 EXPECT(!Dart_IsNull(AsHandle(weak_old_ref))); |
2637 EXPECT(Dart_IdentityEquals(old_ref, AsHandle(weak_old_ref))); | 2662 EXPECT(Dart_IdentityEquals(old_ref, AsHandle(weak_old_ref))); |
2638 | 2663 |
2639 // Delete local (strong) references. | 2664 // Delete local (strong) references. |
2640 Dart_ExitScope(); | 2665 Dart_ExitScope(); |
2641 } | 2666 } |
2642 | 2667 |
2643 // Garbage collect new space again. | 2668 { |
2644 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); | 2669 TransitionNativeToVM transition(thread); |
| 2670 // Garbage collect new space again. |
| 2671 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); |
| 2672 } |
2645 | 2673 |
2646 { | 2674 { |
2647 Dart_EnterScope(); | 2675 Dart_EnterScope(); |
2648 // Weak ref to new space object should now be cleared. | 2676 // Weak ref to new space object should now be cleared. |
2649 EXPECT(weak_new_ref == NULL); | 2677 EXPECT(weak_new_ref == NULL); |
2650 EXPECT_VALID(AsHandle(weak_old_ref)); | 2678 EXPECT_VALID(AsHandle(weak_old_ref)); |
2651 EXPECT(!Dart_IsNull(AsHandle(weak_old_ref))); | 2679 EXPECT(!Dart_IsNull(AsHandle(weak_old_ref))); |
2652 Dart_ExitScope(); | 2680 Dart_ExitScope(); |
2653 } | 2681 } |
2654 | 2682 |
2655 // Garbage collect old space again. | 2683 { |
2656 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2684 TransitionNativeToVM transition(thread); |
| 2685 // Garbage collect old space again. |
| 2686 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 2687 } |
2657 | 2688 |
2658 { | 2689 { |
2659 Dart_EnterScope(); | 2690 Dart_EnterScope(); |
2660 // Weak ref to old space object should now be cleared. | 2691 // Weak ref to old space object should now be cleared. |
2661 EXPECT(weak_new_ref == NULL); | 2692 EXPECT(weak_new_ref == NULL); |
2662 EXPECT(weak_old_ref == NULL); | 2693 EXPECT(weak_old_ref == NULL); |
2663 Dart_ExitScope(); | 2694 Dart_ExitScope(); |
2664 } | 2695 } |
2665 | 2696 |
2666 // Garbage collect one last time to revisit deleted handles. | 2697 { |
2667 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); | 2698 TransitionNativeToVM transition(thread); |
2668 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2699 // Garbage collect one last time to revisit deleted handles. |
| 2700 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); |
| 2701 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 2702 } |
2669 } | 2703 } |
2670 | 2704 |
2671 | 2705 |
2672 static void WeakPersistentHandlePeerFinalizer(void* isolate_callback_data, | 2706 static void WeakPersistentHandlePeerFinalizer(void* isolate_callback_data, |
2673 Dart_WeakPersistentHandle handle, | 2707 Dart_WeakPersistentHandle handle, |
2674 void* peer) { | 2708 void* peer) { |
2675 *static_cast<int*>(peer) = 42; | 2709 *static_cast<int*>(peer) = 42; |
2676 } | 2710 } |
2677 | 2711 |
2678 | 2712 |
2679 TEST_CASE(WeakPersistentHandleCallback) { | 2713 TEST_CASE(WeakPersistentHandleCallback) { |
2680 Dart_WeakPersistentHandle weak_ref = NULL; | 2714 Dart_WeakPersistentHandle weak_ref = NULL; |
2681 int peer = 0; | 2715 int peer = 0; |
2682 { | 2716 { |
2683 Dart_EnterScope(); | 2717 Dart_EnterScope(); |
2684 Dart_Handle obj = NewString("new string"); | 2718 Dart_Handle obj = NewString("new string"); |
2685 EXPECT_VALID(obj); | 2719 EXPECT_VALID(obj); |
2686 weak_ref = Dart_NewWeakPersistentHandle(obj, &peer, 0, | 2720 weak_ref = Dart_NewWeakPersistentHandle(obj, &peer, 0, |
2687 WeakPersistentHandlePeerFinalizer); | 2721 WeakPersistentHandlePeerFinalizer); |
2688 EXPECT_VALID(AsHandle(weak_ref)); | 2722 EXPECT_VALID(AsHandle(weak_ref)); |
2689 EXPECT(peer == 0); | 2723 EXPECT(peer == 0); |
2690 Dart_ExitScope(); | 2724 Dart_ExitScope(); |
2691 } | 2725 } |
2692 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2726 { |
2693 EXPECT(peer == 0); | 2727 TransitionNativeToVM transition(thread); |
2694 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); | 2728 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
2695 EXPECT(peer == 42); | 2729 EXPECT(peer == 0); |
| 2730 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); |
| 2731 EXPECT(peer == 42); |
| 2732 } |
2696 } | 2733 } |
2697 | 2734 |
2698 | 2735 |
2699 TEST_CASE(WeakPersistentHandleNoCallback) { | 2736 TEST_CASE(WeakPersistentHandleNoCallback) { |
2700 Dart_WeakPersistentHandle weak_ref = NULL; | 2737 Dart_WeakPersistentHandle weak_ref = NULL; |
2701 int peer = 0; | 2738 int peer = 0; |
2702 { | 2739 { |
2703 Dart_EnterScope(); | 2740 Dart_EnterScope(); |
2704 Dart_Handle obj = NewString("new string"); | 2741 Dart_Handle obj = NewString("new string"); |
2705 EXPECT_VALID(obj); | 2742 EXPECT_VALID(obj); |
2706 weak_ref = Dart_NewWeakPersistentHandle(obj, &peer, 0, | 2743 weak_ref = Dart_NewWeakPersistentHandle(obj, &peer, 0, |
2707 WeakPersistentHandlePeerFinalizer); | 2744 WeakPersistentHandlePeerFinalizer); |
2708 Dart_ExitScope(); | 2745 Dart_ExitScope(); |
2709 } | 2746 } |
2710 // A finalizer is not invoked on a deleted handle. Therefore, the | 2747 // A finalizer is not invoked on a deleted handle. Therefore, the |
2711 // peer value should not change after the referent is collected. | 2748 // peer value should not change after the referent is collected. |
2712 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current()); | 2749 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current()); |
2713 Dart_DeleteWeakPersistentHandle(isolate, weak_ref); | 2750 Dart_DeleteWeakPersistentHandle(isolate, weak_ref); |
2714 EXPECT(peer == 0); | 2751 EXPECT(peer == 0); |
2715 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2752 { |
2716 EXPECT(peer == 0); | 2753 TransitionNativeToVM transition(thread); |
2717 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); | 2754 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
2718 EXPECT(peer == 0); | 2755 EXPECT(peer == 0); |
| 2756 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); |
| 2757 EXPECT(peer == 0); |
| 2758 } |
2719 } | 2759 } |
2720 | 2760 |
2721 | 2761 |
2722 UNIT_TEST_CASE(WeakPersistentHandlesCallbackShutdown) { | 2762 UNIT_TEST_CASE(WeakPersistentHandlesCallbackShutdown) { |
2723 TestCase::CreateTestIsolate(); | 2763 TestCase::CreateTestIsolate(); |
2724 Dart_EnterScope(); | 2764 Dart_EnterScope(); |
2725 Dart_Handle ref = Dart_True(); | 2765 Dart_Handle ref = Dart_True(); |
2726 int peer = 1234; | 2766 int peer = 1234; |
2727 Dart_NewWeakPersistentHandle(ref, | 2767 Dart_NewWeakPersistentHandle(ref, |
2728 &peer, | 2768 &peer, |
(...skipping 29 matching lines...) Expand all Loading... |
2758 Dart_Handle obj = NewString("strongly referenced string"); | 2798 Dart_Handle obj = NewString("strongly referenced string"); |
2759 EXPECT_VALID(obj); | 2799 EXPECT_VALID(obj); |
2760 strong_ref = Dart_NewPersistentHandle(obj); | 2800 strong_ref = Dart_NewPersistentHandle(obj); |
2761 weak2 = Dart_NewWeakPersistentHandle(obj, | 2801 weak2 = Dart_NewWeakPersistentHandle(obj, |
2762 NULL, | 2802 NULL, |
2763 kWeak2ExternalSize, | 2803 kWeak2ExternalSize, |
2764 NopCallback); | 2804 NopCallback); |
2765 EXPECT_VALID(AsHandle(strong_ref)); | 2805 EXPECT_VALID(AsHandle(strong_ref)); |
2766 Dart_ExitScope(); | 2806 Dart_ExitScope(); |
2767 } | 2807 } |
2768 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2808 { |
2769 EXPECT(heap->ExternalInWords(Heap::kNew) == | 2809 TransitionNativeToVM transition(thread); |
2770 (kWeak1ExternalSize + kWeak2ExternalSize) / kWordSize); | 2810 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
2771 // Collect weakly referenced string, and promote strongly referenced string. | 2811 EXPECT(heap->ExternalInWords(Heap::kNew) == |
2772 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); | 2812 (kWeak1ExternalSize + kWeak2ExternalSize) / kWordSize); |
2773 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); | 2813 // Collect weakly referenced string, and promote strongly referenced string. |
2774 EXPECT(heap->ExternalInWords(Heap::kNew) == 0); | 2814 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); |
2775 EXPECT(heap->ExternalInWords(Heap::kOld) == kWeak2ExternalSize / kWordSize); | 2815 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); |
| 2816 EXPECT(heap->ExternalInWords(Heap::kNew) == 0); |
| 2817 EXPECT(heap->ExternalInWords(Heap::kOld) == kWeak2ExternalSize / kWordSize); |
| 2818 } |
2776 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current()); | 2819 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current()); |
2777 Dart_DeleteWeakPersistentHandle(isolate, weak1); | 2820 Dart_DeleteWeakPersistentHandle(isolate, weak1); |
2778 Dart_DeleteWeakPersistentHandle(isolate, weak2); | 2821 Dart_DeleteWeakPersistentHandle(isolate, weak2); |
2779 Dart_DeletePersistentHandle(strong_ref); | 2822 Dart_DeletePersistentHandle(strong_ref); |
2780 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2823 { |
2781 EXPECT(heap->ExternalInWords(Heap::kOld) == 0); | 2824 TransitionNativeToVM transition(thread); |
| 2825 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 2826 EXPECT(heap->ExternalInWords(Heap::kOld) == 0); |
| 2827 } |
2782 } | 2828 } |
2783 | 2829 |
2784 | 2830 |
2785 TEST_CASE(WeakPersistentHandleExternalAllocationSizeNewspaceGC) { | 2831 TEST_CASE(WeakPersistentHandleExternalAllocationSizeNewspaceGC) { |
2786 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current()); | 2832 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current()); |
2787 Heap* heap = Isolate::Current()->heap(); | 2833 Heap* heap = Isolate::Current()->heap(); |
2788 Dart_WeakPersistentHandle weak1 = NULL; | 2834 Dart_WeakPersistentHandle weak1 = NULL; |
2789 // Large enough to exceed any new space limit. Not actually allocated. | 2835 // Large enough to exceed any new space limit. Not actually allocated. |
2790 const intptr_t kWeak1ExternalSize = 500 * MB; | 2836 const intptr_t kWeak1ExternalSize = 500 * MB; |
2791 { | 2837 { |
2792 Dart_EnterScope(); | 2838 Dart_EnterScope(); |
2793 Dart_Handle obj = NewString("weakly referenced string"); | 2839 Dart_Handle obj = NewString("weakly referenced string"); |
2794 EXPECT_VALID(obj); | 2840 EXPECT_VALID(obj); |
2795 // Triggers a scavenge immediately, since kWeak1ExternalSize is above limit. | 2841 // Triggers a scavenge immediately, since kWeak1ExternalSize is above limit. |
2796 weak1 = Dart_NewWeakPersistentHandle(obj, | 2842 weak1 = Dart_NewWeakPersistentHandle(obj, |
2797 NULL, | 2843 NULL, |
2798 kWeak1ExternalSize, | 2844 kWeak1ExternalSize, |
2799 NopCallback); | 2845 NopCallback); |
2800 EXPECT_VALID(AsHandle(weak1)); | 2846 EXPECT_VALID(AsHandle(weak1)); |
2801 // ... but the object is still alive and not yet promoted, so external size | 2847 // ... but the object is still alive and not yet promoted, so external size |
2802 // in new space is still above the limit. Thus, even the following tiny | 2848 // in new space is still above the limit. Thus, even the following tiny |
2803 // external allocation will trigger another scavenge. | 2849 // external allocation will trigger another scavenge. |
2804 Dart_WeakPersistentHandle trigger = | 2850 Dart_WeakPersistentHandle trigger = |
2805 Dart_NewWeakPersistentHandle(obj, NULL, 1, NopCallback); | 2851 Dart_NewWeakPersistentHandle(obj, NULL, 1, NopCallback); |
2806 EXPECT_VALID(AsHandle(trigger)); | 2852 EXPECT_VALID(AsHandle(trigger)); |
2807 Dart_DeleteWeakPersistentHandle(isolate, trigger); | 2853 Dart_DeleteWeakPersistentHandle(isolate, trigger); |
2808 // After the two scavenges above, 'obj' should now be promoted, hence its | 2854 // After the two scavenges above, 'obj' should now be promoted, hence its |
2809 // external size charged to old space. | 2855 // external size charged to old space. |
2810 { | 2856 { |
2811 DARTSCOPE(thread); | 2857 CHECK_API_SCOPE(thread); |
| 2858 HANDLESCOPE(thread); |
2812 String& handle = String::Handle(thread->zone()); | 2859 String& handle = String::Handle(thread->zone()); |
2813 handle ^= Api::UnwrapHandle(obj); | 2860 handle ^= Api::UnwrapHandle(obj); |
2814 EXPECT(handle.IsOld()); | 2861 EXPECT(handle.IsOld()); |
2815 } | 2862 } |
2816 EXPECT(heap->ExternalInWords(Heap::kNew) == 0); | 2863 EXPECT(heap->ExternalInWords(Heap::kNew) == 0); |
2817 EXPECT(heap->ExternalInWords(Heap::kOld) == kWeak1ExternalSize / kWordSize); | 2864 EXPECT(heap->ExternalInWords(Heap::kOld) == kWeak1ExternalSize / kWordSize); |
2818 Dart_ExitScope(); | 2865 Dart_ExitScope(); |
2819 } | 2866 } |
2820 Dart_DeleteWeakPersistentHandle(isolate, weak1); | 2867 Dart_DeleteWeakPersistentHandle(isolate, weak1); |
2821 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2868 { |
2822 EXPECT(heap->ExternalInWords(Heap::kOld) == 0); | 2869 TransitionNativeToVM transition(thread); |
| 2870 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 2871 EXPECT(heap->ExternalInWords(Heap::kOld) == 0); |
| 2872 } |
2823 } | 2873 } |
2824 | 2874 |
2825 | 2875 |
2826 TEST_CASE(WeakPersistentHandleExternalAllocationSizeOldspaceGC) { | 2876 TEST_CASE(WeakPersistentHandleExternalAllocationSizeOldspaceGC) { |
2827 // Check that external allocation in old space can trigger GC. | 2877 // Check that external allocation in old space can trigger GC. |
2828 Isolate* isolate = Isolate::Current(); | 2878 Isolate* isolate = Isolate::Current(); |
2829 Dart_EnterScope(); | 2879 Dart_EnterScope(); |
2830 Dart_Handle live = Api::NewHandle(thread, String::New("live", Heap::kOld)); | 2880 Dart_Handle live = Api::NewHandle(thread, String::New("live", Heap::kOld)); |
2831 EXPECT_VALID(live); | 2881 EXPECT_VALID(live); |
2832 Dart_WeakPersistentHandle weak = NULL; | 2882 Dart_WeakPersistentHandle weak = NULL; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2879 zero, NULL, kWeak2ExternalSize, NopCallback); | 2929 zero, NULL, kWeak2ExternalSize, NopCallback); |
2880 EXPECT_VALID(AsHandle(weak2)); | 2930 EXPECT_VALID(AsHandle(weak2)); |
2881 // Both should be charged to old space. | 2931 // Both should be charged to old space. |
2882 EXPECT(heap->ExternalInWords(Heap::kOld) == | 2932 EXPECT(heap->ExternalInWords(Heap::kOld) == |
2883 (kWeak1ExternalSize + kWeak2ExternalSize) / kWordSize); | 2933 (kWeak1ExternalSize + kWeak2ExternalSize) / kWordSize); |
2884 Dart_ExitScope(); | 2934 Dart_ExitScope(); |
2885 } | 2935 } |
2886 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current()); | 2936 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current()); |
2887 Dart_DeleteWeakPersistentHandle(isolate, weak1); | 2937 Dart_DeleteWeakPersistentHandle(isolate, weak1); |
2888 Dart_DeleteWeakPersistentHandle(isolate, weak2); | 2938 Dart_DeleteWeakPersistentHandle(isolate, weak2); |
2889 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2939 { |
2890 EXPECT_EQ(0, heap->ExternalInWords(Heap::kOld)); | 2940 TransitionNativeToVM transition(thread); |
| 2941 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 2942 EXPECT_EQ(0, heap->ExternalInWords(Heap::kOld)); |
| 2943 } |
2891 } | 2944 } |
2892 | 2945 |
2893 | 2946 |
2894 static Dart_WeakPersistentHandle weak1 = NULL; | 2947 static Dart_WeakPersistentHandle weak1 = NULL; |
2895 static Dart_WeakPersistentHandle weak2 = NULL; | 2948 static Dart_WeakPersistentHandle weak2 = NULL; |
2896 static Dart_WeakPersistentHandle weak3 = NULL; | 2949 static Dart_WeakPersistentHandle weak3 = NULL; |
2897 | 2950 |
2898 | 2951 |
2899 static void ImplicitReferencesCallback(void* isolate_callback_data, | 2952 static void ImplicitReferencesCallback(void* isolate_callback_data, |
2900 Dart_WeakPersistentHandle handle, | 2953 Dart_WeakPersistentHandle handle, |
2901 void* peer) { | 2954 void* peer) { |
2902 if (handle == weak1) { | 2955 if (handle == weak1) { |
2903 weak1 = NULL; | 2956 weak1 = NULL; |
2904 } else if (handle == weak2) { | 2957 } else if (handle == weak2) { |
2905 weak2 = NULL; | 2958 weak2 = NULL; |
2906 } else if (handle == weak3) { | 2959 } else if (handle == weak3) { |
2907 weak3 = NULL; | 2960 weak3 = NULL; |
2908 } | 2961 } |
2909 } | 2962 } |
2910 | 2963 |
2911 | 2964 |
2912 TEST_CASE(ImplicitReferencesOldSpace) { | 2965 TEST_CASE(ImplicitReferencesOldSpace) { |
2913 Dart_PersistentHandle strong = NULL; | 2966 Dart_PersistentHandle strong = NULL; |
2914 Dart_WeakPersistentHandle strong_weak = NULL; | 2967 Dart_WeakPersistentHandle strong_weak = NULL; |
2915 | 2968 |
2916 Dart_EnterScope(); | 2969 Dart_EnterScope(); |
2917 { | 2970 { |
2918 DARTSCOPE(Thread::Current()); | 2971 CHECK_API_SCOPE(thread); |
| 2972 HANDLESCOPE(thread); |
2919 | 2973 |
2920 Dart_Handle local = Api::NewHandle( | 2974 Dart_Handle local = Api::NewHandle( |
2921 thread, String::New("strongly reachable", Heap::kOld)); | 2975 thread, String::New("strongly reachable", Heap::kOld)); |
2922 strong = Dart_NewPersistentHandle(local); | 2976 strong = Dart_NewPersistentHandle(local); |
2923 strong_weak = Dart_NewWeakPersistentHandle(local, NULL, 0, NopCallback); | 2977 strong_weak = Dart_NewWeakPersistentHandle(local, NULL, 0, NopCallback); |
2924 | 2978 |
2925 EXPECT(!Dart_IsNull(AsHandle(strong))); | 2979 EXPECT(!Dart_IsNull(AsHandle(strong))); |
2926 EXPECT_VALID(AsHandle(strong)); | 2980 EXPECT_VALID(AsHandle(strong)); |
2927 EXPECT(!Dart_IsNull(AsHandle(strong_weak))); | 2981 EXPECT(!Dart_IsNull(AsHandle(strong_weak))); |
2928 EXPECT_VALID(AsHandle(strong_weak)); | 2982 EXPECT_VALID(AsHandle(strong_weak)); |
(...skipping 21 matching lines...) Expand all Loading... |
2950 | 3004 |
2951 { | 3005 { |
2952 Dart_EnterScope(); | 3006 Dart_EnterScope(); |
2953 EXPECT_VALID(AsHandle(strong_weak)); | 3007 EXPECT_VALID(AsHandle(strong_weak)); |
2954 EXPECT_VALID(AsHandle(weak1)); | 3008 EXPECT_VALID(AsHandle(weak1)); |
2955 EXPECT_VALID(AsHandle(weak2)); | 3009 EXPECT_VALID(AsHandle(weak2)); |
2956 EXPECT_VALID(AsHandle(weak3)); | 3010 EXPECT_VALID(AsHandle(weak3)); |
2957 Dart_ExitScope(); | 3011 Dart_ExitScope(); |
2958 } | 3012 } |
2959 | 3013 |
2960 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); | 3014 { |
| 3015 TransitionNativeToVM transition(thread); |
| 3016 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); |
| 3017 } |
2961 | 3018 |
2962 { | 3019 { |
2963 Dart_EnterScope(); | 3020 Dart_EnterScope(); |
2964 // New space collection should not affect old space objects | 3021 // New space collection should not affect old space objects |
2965 EXPECT_VALID(AsHandle(strong_weak)); | 3022 EXPECT_VALID(AsHandle(strong_weak)); |
2966 EXPECT(!Dart_IsNull(AsHandle(weak1))); | 3023 EXPECT(!Dart_IsNull(AsHandle(weak1))); |
2967 EXPECT(!Dart_IsNull(AsHandle(weak2))); | 3024 EXPECT(!Dart_IsNull(AsHandle(weak2))); |
2968 EXPECT(!Dart_IsNull(AsHandle(weak3))); | 3025 EXPECT(!Dart_IsNull(AsHandle(weak3))); |
2969 Dart_ExitScope(); | 3026 Dart_ExitScope(); |
2970 } | 3027 } |
2971 } | 3028 } |
2972 | 3029 |
2973 | 3030 |
2974 TEST_CASE(ImplicitReferencesNewSpace) { | 3031 TEST_CASE(ImplicitReferencesNewSpace) { |
2975 Dart_PersistentHandle strong = NULL; | 3032 Dart_PersistentHandle strong = NULL; |
2976 Dart_WeakPersistentHandle strong_weak = NULL; | 3033 Dart_WeakPersistentHandle strong_weak = NULL; |
2977 | 3034 |
2978 | 3035 |
2979 Dart_EnterScope(); | 3036 Dart_EnterScope(); |
2980 { | 3037 { |
2981 DARTSCOPE(Thread::Current()); | 3038 CHECK_API_SCOPE(thread); |
| 3039 HANDLESCOPE(thread); |
2982 | 3040 |
2983 Dart_Handle local = Api::NewHandle( | 3041 Dart_Handle local = Api::NewHandle( |
2984 thread, String::New("strongly reachable", Heap::kOld)); | 3042 thread, String::New("strongly reachable", Heap::kOld)); |
2985 strong = Dart_NewPersistentHandle(local); | 3043 strong = Dart_NewPersistentHandle(local); |
2986 strong_weak = Dart_NewWeakPersistentHandle(local, NULL, 0, NopCallback); | 3044 strong_weak = Dart_NewWeakPersistentHandle(local, NULL, 0, NopCallback); |
2987 | 3045 |
2988 EXPECT(!Dart_IsNull(AsHandle(strong))); | 3046 EXPECT(!Dart_IsNull(AsHandle(strong))); |
2989 EXPECT_VALID(AsHandle(strong)); | 3047 EXPECT_VALID(AsHandle(strong)); |
2990 EXPECT(!Dart_IsNull(AsHandle(strong_weak))); | 3048 EXPECT(!Dart_IsNull(AsHandle(strong_weak))); |
2991 EXPECT_VALID(AsHandle(strong_weak)); | 3049 EXPECT_VALID(AsHandle(strong_weak)); |
(...skipping 21 matching lines...) Expand all Loading... |
3013 | 3071 |
3014 { | 3072 { |
3015 Dart_EnterScope(); | 3073 Dart_EnterScope(); |
3016 EXPECT_VALID(AsHandle(strong_weak)); | 3074 EXPECT_VALID(AsHandle(strong_weak)); |
3017 EXPECT_VALID(AsHandle(weak1)); | 3075 EXPECT_VALID(AsHandle(weak1)); |
3018 EXPECT_VALID(AsHandle(weak2)); | 3076 EXPECT_VALID(AsHandle(weak2)); |
3019 EXPECT_VALID(AsHandle(weak3)); | 3077 EXPECT_VALID(AsHandle(weak3)); |
3020 Dart_ExitScope(); | 3078 Dart_ExitScope(); |
3021 } | 3079 } |
3022 | 3080 |
3023 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 3081 { |
| 3082 TransitionNativeToVM transition(thread); |
| 3083 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 3084 } |
3024 | 3085 |
3025 { | 3086 { |
3026 Dart_EnterScope(); | 3087 Dart_EnterScope(); |
3027 // Old space collection should not affect old space objects. | 3088 // Old space collection should not affect old space objects. |
3028 EXPECT(!Dart_IsNull(AsHandle(weak1))); | 3089 EXPECT(!Dart_IsNull(AsHandle(weak1))); |
3029 EXPECT(!Dart_IsNull(AsHandle(weak2))); | 3090 EXPECT(!Dart_IsNull(AsHandle(weak2))); |
3030 EXPECT(!Dart_IsNull(AsHandle(weak3))); | 3091 EXPECT(!Dart_IsNull(AsHandle(weak3))); |
3031 Dart_ExitScope(); | 3092 Dart_ExitScope(); |
3032 } | 3093 } |
3033 } | 3094 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3091 EXPECT(Dart_IsError(Dart_SetGcCallbacks(&PrologueCallbackTimes2, NULL))); | 3152 EXPECT(Dart_IsError(Dart_SetGcCallbacks(&PrologueCallbackTimes2, NULL))); |
3092 EXPECT(Dart_IsError(Dart_SetGcCallbacks(NULL, &EpilogueCallbackTimes4))); | 3153 EXPECT(Dart_IsError(Dart_SetGcCallbacks(NULL, &EpilogueCallbackTimes4))); |
3093 } | 3154 } |
3094 | 3155 |
3095 | 3156 |
3096 TEST_CASE(SingleGarbageCollectionCallback) { | 3157 TEST_CASE(SingleGarbageCollectionCallback) { |
3097 // Add a prologue callback. | 3158 // Add a prologue callback. |
3098 EXPECT_VALID(Dart_SetGcCallbacks(&PrologueCallbackTimes2, | 3159 EXPECT_VALID(Dart_SetGcCallbacks(&PrologueCallbackTimes2, |
3099 &EpilogueCallbackNOP)); | 3160 &EpilogueCallbackNOP)); |
3100 | 3161 |
3101 // Garbage collect new space ignoring callbacks. This should not | 3162 { |
3102 // invoke the prologue callback. No status values should change. | 3163 TransitionNativeToVM transition(thread); |
3103 global_prologue_callback_status = 3; | |
3104 global_epilogue_callback_status = 7; | |
3105 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); | |
3106 EXPECT_EQ(3, global_prologue_callback_status); | |
3107 EXPECT_EQ(7, global_epilogue_callback_status); | |
3108 | 3164 |
3109 // Garbage collect new space invoking callbacks. This should | 3165 // Garbage collect new space ignoring callbacks. This should not |
3110 // invoke the prologue callback. No status values should change. | 3166 // invoke the prologue callback. No status values should change. |
3111 global_prologue_callback_status = 3; | 3167 global_prologue_callback_status = 3; |
3112 global_epilogue_callback_status = 7; | 3168 global_epilogue_callback_status = 7; |
3113 GCTestHelper::CollectNewSpace(Heap::kInvokeApiCallbacks); | 3169 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); |
3114 EXPECT_EQ(6, global_prologue_callback_status); | 3170 EXPECT_EQ(3, global_prologue_callback_status); |
3115 EXPECT_EQ(7, global_epilogue_callback_status); | 3171 EXPECT_EQ(7, global_epilogue_callback_status); |
| 3172 |
| 3173 // Garbage collect new space invoking callbacks. This should |
| 3174 // invoke the prologue callback. No status values should change. |
| 3175 global_prologue_callback_status = 3; |
| 3176 global_epilogue_callback_status = 7; |
| 3177 GCTestHelper::CollectNewSpace(Heap::kInvokeApiCallbacks); |
| 3178 EXPECT_EQ(6, global_prologue_callback_status); |
| 3179 EXPECT_EQ(7, global_epilogue_callback_status); |
3116 | 3180 |
3117 // Garbage collect old space ignoring callbacks. This should invoke | 3181 // Garbage collect old space ignoring callbacks. This should invoke |
3118 // the prologue callback. The prologue status value should change. | 3182 // the prologue callback. The prologue status value should change. |
3119 global_prologue_callback_status = 3; | 3183 global_prologue_callback_status = 3; |
3120 global_epilogue_callback_status = 7; | 3184 global_epilogue_callback_status = 7; |
3121 Isolate::Current()->heap()->CollectGarbage(Heap::kOld, | 3185 Isolate::Current()->heap()->CollectGarbage(Heap::kOld, |
3122 Heap::kIgnoreApiCallbacks, | 3186 Heap::kIgnoreApiCallbacks, |
3123 Heap::kGCTestCase); | 3187 Heap::kGCTestCase); |
3124 EXPECT_EQ(3, global_prologue_callback_status); | 3188 EXPECT_EQ(3, global_prologue_callback_status); |
3125 EXPECT_EQ(7, global_epilogue_callback_status); | 3189 EXPECT_EQ(7, global_epilogue_callback_status); |
3126 | 3190 |
3127 // Garbage collect old space. This should invoke the prologue | 3191 // Garbage collect old space. This should invoke the prologue |
3128 // callback. The prologue status value should change. | 3192 // callback. The prologue status value should change. |
3129 global_prologue_callback_status = 3; | 3193 global_prologue_callback_status = 3; |
3130 global_epilogue_callback_status = 7; | 3194 global_epilogue_callback_status = 7; |
3131 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 3195 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
3132 EXPECT_EQ(6, global_prologue_callback_status); | 3196 EXPECT_EQ(6, global_prologue_callback_status); |
3133 EXPECT_EQ(7, global_epilogue_callback_status); | 3197 EXPECT_EQ(7, global_epilogue_callback_status); |
3134 | 3198 |
3135 // Garbage collect old space again. Callbacks are persistent so the | 3199 // Garbage collect old space again. Callbacks are persistent so the |
3136 // prologue status value should change again. | 3200 // prologue status value should change again. |
3137 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 3201 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
3138 EXPECT_EQ(12, global_prologue_callback_status); | 3202 EXPECT_EQ(12, global_prologue_callback_status); |
3139 EXPECT_EQ(7, global_epilogue_callback_status); | 3203 EXPECT_EQ(7, global_epilogue_callback_status); |
| 3204 } |
3140 | 3205 |
3141 // Add an epilogue callback. | 3206 // Add an epilogue callback. |
3142 EXPECT_VALID(Dart_SetGcCallbacks(NULL, NULL)); | 3207 EXPECT_VALID(Dart_SetGcCallbacks(NULL, NULL)); |
3143 EXPECT_VALID(Dart_SetGcCallbacks(&PrologueCallbackTimes2, | 3208 EXPECT_VALID(Dart_SetGcCallbacks(&PrologueCallbackTimes2, |
3144 &EpilogueCallbackTimes4)); | 3209 &EpilogueCallbackTimes4)); |
3145 | 3210 |
3146 // Garbage collect new space. This should not invoke the prologue | 3211 { |
3147 // or the epilogue callback. No status values should change. | 3212 TransitionNativeToVM transition(thread); |
3148 global_prologue_callback_status = 3; | 3213 // Garbage collect new space. This should not invoke the prologue |
3149 global_epilogue_callback_status = 7; | 3214 // or the epilogue callback. No status values should change. |
3150 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); | 3215 global_prologue_callback_status = 3; |
3151 EXPECT_EQ(3, global_prologue_callback_status); | 3216 global_epilogue_callback_status = 7; |
3152 EXPECT_EQ(7, global_epilogue_callback_status); | 3217 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); |
| 3218 EXPECT_EQ(3, global_prologue_callback_status); |
| 3219 EXPECT_EQ(7, global_epilogue_callback_status); |
3153 | 3220 |
3154 // Garbage collect new space. This should invoke the prologue and | 3221 // Garbage collect new space. This should invoke the prologue and |
3155 // the epilogue callback. The prologue and epilogue status values | 3222 // the epilogue callback. The prologue and epilogue status values |
3156 // should change. | 3223 // should change. |
3157 GCTestHelper::CollectNewSpace(Heap::kInvokeApiCallbacks); | 3224 GCTestHelper::CollectNewSpace(Heap::kInvokeApiCallbacks); |
3158 EXPECT_EQ(6, global_prologue_callback_status); | 3225 EXPECT_EQ(6, global_prologue_callback_status); |
3159 EXPECT_EQ(28, global_epilogue_callback_status); | 3226 EXPECT_EQ(28, global_epilogue_callback_status); |
3160 | 3227 |
3161 // Garbage collect old space. This should invoke the prologue and | 3228 // Garbage collect old space. This should invoke the prologue and |
3162 // the epilogue callbacks. The prologue and epilogue status values | 3229 // the epilogue callbacks. The prologue and epilogue status values |
3163 // should change. | 3230 // should change. |
3164 global_prologue_callback_status = 3; | 3231 global_prologue_callback_status = 3; |
3165 global_epilogue_callback_status = 7; | 3232 global_epilogue_callback_status = 7; |
3166 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 3233 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
3167 EXPECT_EQ(6, global_prologue_callback_status); | 3234 EXPECT_EQ(6, global_prologue_callback_status); |
3168 EXPECT_EQ(28, global_epilogue_callback_status); | 3235 EXPECT_EQ(28, global_epilogue_callback_status); |
3169 | 3236 |
3170 // Garbage collect old space again without invoking callbacks. | 3237 // Garbage collect old space again without invoking callbacks. |
3171 // Nothing should change. | 3238 // Nothing should change. |
3172 Isolate::Current()->heap()->CollectGarbage(Heap::kOld, | 3239 Isolate::Current()->heap()->CollectGarbage(Heap::kOld, |
3173 Heap::kIgnoreApiCallbacks, | 3240 Heap::kIgnoreApiCallbacks, |
3174 Heap::kGCTestCase); | 3241 Heap::kGCTestCase); |
3175 EXPECT_EQ(6, global_prologue_callback_status); | 3242 EXPECT_EQ(6, global_prologue_callback_status); |
3176 EXPECT_EQ(28, global_epilogue_callback_status); | 3243 EXPECT_EQ(28, global_epilogue_callback_status); |
3177 | 3244 |
3178 // Garbage collect old space again. Callbacks are persistent so the | 3245 // Garbage collect old space again. Callbacks are persistent so the |
3179 // prologue and epilogue status values should change again. | 3246 // prologue and epilogue status values should change again. |
3180 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 3247 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
3181 EXPECT_EQ(12, global_prologue_callback_status); | 3248 EXPECT_EQ(12, global_prologue_callback_status); |
3182 EXPECT_EQ(112, global_epilogue_callback_status); | 3249 EXPECT_EQ(112, global_epilogue_callback_status); |
| 3250 } |
3183 | 3251 |
3184 // Remove the prologue and epilogue callbacks | 3252 // Remove the prologue and epilogue callbacks |
3185 EXPECT_VALID(Dart_SetGcCallbacks(NULL, NULL)); | 3253 EXPECT_VALID(Dart_SetGcCallbacks(NULL, NULL)); |
3186 | 3254 |
3187 // Garbage collect old space. No callbacks should be invoked. No | 3255 { |
3188 // status values should change. | 3256 TransitionNativeToVM transition(thread); |
3189 global_prologue_callback_status = 3; | 3257 // Garbage collect old space. No callbacks should be invoked. No |
3190 global_epilogue_callback_status = 7; | 3258 // status values should change. |
3191 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 3259 global_prologue_callback_status = 3; |
3192 EXPECT_EQ(3, global_prologue_callback_status); | 3260 global_epilogue_callback_status = 7; |
3193 EXPECT_EQ(7, global_epilogue_callback_status); | 3261 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 3262 EXPECT_EQ(3, global_prologue_callback_status); |
| 3263 EXPECT_EQ(7, global_epilogue_callback_status); |
| 3264 } |
3194 } | 3265 } |
3195 | 3266 |
3196 | 3267 |
3197 // Unit test for creating multiple scopes and local handles within them. | 3268 // Unit test for creating multiple scopes and local handles within them. |
3198 // Ensure that the local handles get all cleaned out when exiting the | 3269 // Ensure that the local handles get all cleaned out when exiting the |
3199 // scope. | 3270 // scope. |
3200 UNIT_TEST_CASE(LocalHandles) { | 3271 UNIT_TEST_CASE(LocalHandles) { |
3201 TestCase::CreateTestIsolate(); | 3272 TestCase::CreateTestIsolate(); |
3202 Thread* thread = Thread::Current(); | 3273 Thread* thread = Thread::Current(); |
3203 Isolate* isolate = thread->isolate(); | 3274 Isolate* isolate = thread->isolate(); |
(...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3968 kNumNativeFields); | 4039 kNumNativeFields); |
3969 EXPECT_VALID(result); | 4040 EXPECT_VALID(result); |
3970 result = Dart_FinalizeLoading(false); | 4041 result = Dart_FinalizeLoading(false); |
3971 EXPECT_VALID(result); | 4042 EXPECT_VALID(result); |
3972 | 4043 |
3973 // Load up a test script in the test library. | 4044 // Load up a test script in the test library. |
3974 | 4045 |
3975 // Invoke a function which returns an object of type NativeFields. | 4046 // Invoke a function which returns an object of type NativeFields. |
3976 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 4047 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
3977 EXPECT_VALID(result); | 4048 EXPECT_VALID(result); |
3978 DARTSCOPE(Thread::Current()); | 4049 CHECK_API_SCOPE(thread); |
| 4050 HANDLESCOPE(thread); |
3979 Instance& obj = Instance::Handle(); | 4051 Instance& obj = Instance::Handle(); |
3980 obj ^= Api::UnwrapHandle(result); | 4052 obj ^= Api::UnwrapHandle(result); |
3981 const Class& cls = Class::Handle(obj.clazz()); | 4053 const Class& cls = Class::Handle(obj.clazz()); |
3982 // We expect the newly created "NativeFields" object to have | 4054 // We expect the newly created "NativeFields" object to have |
3983 // 2 dart instance fields (fld1, fld2) and a reference to the native fields. | 4055 // 2 dart instance fields (fld1, fld2) and a reference to the native fields. |
3984 // Hence the size of an instance of "NativeFields" should be | 4056 // Hence the size of an instance of "NativeFields" should be |
3985 // (1 + 2) * kWordSize + size of object header. | 4057 // (1 + 2) * kWordSize + size of object header. |
3986 // We check to make sure the instance size computed by the VM matches | 4058 // We check to make sure the instance size computed by the VM matches |
3987 // our expectations. | 4059 // our expectations. |
3988 intptr_t header_size = sizeof(RawObject); | 4060 intptr_t header_size = sizeof(RawObject); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4038 Dart_Handle result; | 4110 Dart_Handle result; |
4039 const int kNumNativeFields = 2; | 4111 const int kNumNativeFields = 2; |
4040 | 4112 |
4041 // Load up a test script in the test library. | 4113 // Load up a test script in the test library. |
4042 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, | 4114 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, |
4043 native_field_lookup); | 4115 native_field_lookup); |
4044 | 4116 |
4045 // Invoke a function which returns an object of type NativeFields. | 4117 // Invoke a function which returns an object of type NativeFields. |
4046 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 4118 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
4047 EXPECT_VALID(result); | 4119 EXPECT_VALID(result); |
4048 DARTSCOPE(Thread::Current()); | 4120 CHECK_API_SCOPE(thread); |
| 4121 HANDLESCOPE(thread); |
4049 Instance& obj = Instance::Handle(); | 4122 Instance& obj = Instance::Handle(); |
4050 obj ^= Api::UnwrapHandle(result); | 4123 obj ^= Api::UnwrapHandle(result); |
4051 const Class& cls = Class::Handle(obj.clazz()); | 4124 const Class& cls = Class::Handle(obj.clazz()); |
4052 // We expect the newly created "NativeFields" object to have | 4125 // We expect the newly created "NativeFields" object to have |
4053 // 2 dart instance fields (fld1, fld2) and a reference to the native fields. | 4126 // 2 dart instance fields (fld1, fld2) and a reference to the native fields. |
4054 // Hence the size of an instance of "NativeFields" should be | 4127 // Hence the size of an instance of "NativeFields" should be |
4055 // (1 + 2) * kWordSize + size of object header. | 4128 // (1 + 2) * kWordSize + size of object header. |
4056 // We check to make sure the instance size computed by the VM matches | 4129 // We check to make sure the instance size computed by the VM matches |
4057 // our expectations. | 4130 // our expectations. |
4058 intptr_t header_size = sizeof(RawObject); | 4131 intptr_t header_size = sizeof(RawObject); |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4382 " static const int fld4 = 10;\n" | 4455 " static const int fld4 = 10;\n" |
4383 "}\n" | 4456 "}\n" |
4384 "NativeFields testMain1() {\n" | 4457 "NativeFields testMain1() {\n" |
4385 " NativeFields obj = new NativeFields(10, 20);\n" | 4458 " NativeFields obj = new NativeFields(10, 20);\n" |
4386 " return obj;\n" | 4459 " return obj;\n" |
4387 "}\n" | 4460 "}\n" |
4388 "Function testMain2() {\n" | 4461 "Function testMain2() {\n" |
4389 " return () {};\n" | 4462 " return () {};\n" |
4390 "}\n"; | 4463 "}\n"; |
4391 Dart_Handle result; | 4464 Dart_Handle result; |
4392 DARTSCOPE(Thread::Current()); | 4465 CHECK_API_SCOPE(thread); |
| 4466 HANDLESCOPE(thread); |
4393 | 4467 |
4394 // Create a test library and Load up a test script in it. | 4468 // Create a test library and Load up a test script in it. |
4395 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 4469 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
4396 | 4470 |
4397 // Invoke a function which returns an object of type NativeFields. | 4471 // Invoke a function which returns an object of type NativeFields. |
4398 Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain1"), 0, NULL); | 4472 Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain1"), 0, NULL); |
4399 EXPECT_VALID(retobj); | 4473 EXPECT_VALID(retobj); |
4400 | 4474 |
4401 // Now access and set various native instance fields of the returned object. | 4475 // Now access and set various native instance fields of the returned object. |
4402 // All of these tests are expected to return failure as there are no | 4476 // All of these tests are expected to return failure as there are no |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4460 " var port = new RawReceivePort();\n" | 4534 " var port = new RawReceivePort();\n" |
4461 " var obj = new Test(1,2);\n" | 4535 " var obj = new Test(1,2);\n" |
4462 " var msg = [obj, port.sendPort];\n" | 4536 " var msg = [obj, port.sendPort];\n" |
4463 " var snd = Isolate.spawn(echo, msg);\n" | 4537 " var snd = Isolate.spawn(echo, msg);\n" |
4464 " port.handler = (msg) {\n" | 4538 " port.handler = (msg) {\n" |
4465 " port.close();\n" | 4539 " port.close();\n" |
4466 " print('from worker ${msg}');\n" | 4540 " print('from worker ${msg}');\n" |
4467 " };\n" | 4541 " };\n" |
4468 "}\n"; | 4542 "}\n"; |
4469 | 4543 |
4470 DARTSCOPE(Thread::Current()); | 4544 CHECK_API_SCOPE(thread); |
| 4545 HANDLESCOPE(thread); |
4471 | 4546 |
4472 // Create a test library and Load up a test script in it. | 4547 // Create a test library and Load up a test script in it. |
4473 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 4548 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
4474 | 4549 |
4475 // Invoke 'main' which should spawn an isolate and try to send an | 4550 // Invoke 'main' which should spawn an isolate and try to send an |
4476 // object with native fields over to the spawned isolate. This | 4551 // object with native fields over to the spawned isolate. This |
4477 // should result in an unhandled exception which is checked. | 4552 // should result in an unhandled exception which is checked. |
4478 Dart_Handle retobj = Dart_Invoke(lib, NewString("main"), 0, NULL); | 4553 Dart_Handle retobj = Dart_Invoke(lib, NewString("main"), 0, NULL); |
4479 EXPECT(Dart_IsError(retobj)); | 4554 EXPECT(Dart_IsError(retobj)); |
4480 } | 4555 } |
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5169 " static const int fld4 = 10;\n" | 5244 " static const int fld4 = 10;\n" |
5170 "}\n" | 5245 "}\n" |
5171 "Function testMain1() {\n" | 5246 "Function testMain1() {\n" |
5172 " InvokeClosure obj = new InvokeClosure(10, 20);\n" | 5247 " InvokeClosure obj = new InvokeClosure(10, 20);\n" |
5173 " return obj.method1(10);\n" | 5248 " return obj.method1(10);\n" |
5174 "}\n" | 5249 "}\n" |
5175 "Function testMain2() {\n" | 5250 "Function testMain2() {\n" |
5176 " return InvokeClosure.method2(10);\n" | 5251 " return InvokeClosure.method2(10);\n" |
5177 "}\n"; | 5252 "}\n"; |
5178 Dart_Handle result; | 5253 Dart_Handle result; |
5179 DARTSCOPE(Thread::Current()); | 5254 CHECK_API_SCOPE(thread); |
| 5255 HANDLESCOPE(thread); |
5180 | 5256 |
5181 // Create a test library and Load up a test script in it. | 5257 // Create a test library and Load up a test script in it. |
5182 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 5258 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
5183 | 5259 |
5184 // Invoke a function which returns a closure. | 5260 // Invoke a function which returns a closure. |
5185 Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain1"), 0, NULL); | 5261 Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain1"), 0, NULL); |
5186 EXPECT_VALID(retobj); | 5262 EXPECT_VALID(retobj); |
5187 | 5263 |
5188 EXPECT(Dart_IsClosure(retobj)); | 5264 EXPECT(Dart_IsClosure(retobj)); |
5189 EXPECT(!Dart_IsClosure(Dart_NewInteger(101))); | 5265 EXPECT(!Dart_IsClosure(Dart_NewInteger(101))); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5222 Dart_EnterScope(); | 5298 Dart_EnterScope(); |
5223 Dart_ThrowException(NewString("Hello from ExceptionNative!")); | 5299 Dart_ThrowException(NewString("Hello from ExceptionNative!")); |
5224 UNREACHABLE(); | 5300 UNREACHABLE(); |
5225 } | 5301 } |
5226 | 5302 |
5227 | 5303 |
5228 static Dart_NativeFunction native_lookup(Dart_Handle name, | 5304 static Dart_NativeFunction native_lookup(Dart_Handle name, |
5229 int argument_count, | 5305 int argument_count, |
5230 bool* auto_setup_scope) { | 5306 bool* auto_setup_scope) { |
5231 ASSERT(auto_setup_scope != NULL); | 5307 ASSERT(auto_setup_scope != NULL); |
5232 *auto_setup_scope = false; | 5308 *auto_setup_scope = true; |
5233 return reinterpret_cast<Dart_NativeFunction>(&ExceptionNative); | 5309 return reinterpret_cast<Dart_NativeFunction>(&ExceptionNative); |
5234 } | 5310 } |
5235 | 5311 |
5236 | 5312 |
5237 TEST_CASE(ThrowException) { | 5313 TEST_CASE(ThrowException) { |
5238 const char* kScriptChars = | 5314 const char* kScriptChars = |
5239 "int test() native \"ThrowException_native\";"; | 5315 "int test() native \"ThrowException_native\";"; |
5240 Dart_Handle result; | 5316 Dart_Handle result; |
5241 intptr_t size = thread->ZoneSizeInBytes(); | 5317 intptr_t size = thread->ZoneSizeInBytes(); |
5242 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. | 5318 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5468 int count = Dart_GetNativeArgumentCount(args); | 5544 int count = Dart_GetNativeArgumentCount(args); |
5469 Dart_SetReturnValue(args, Dart_NewInteger(count)); | 5545 Dart_SetReturnValue(args, Dart_NewInteger(count)); |
5470 Dart_ExitScope(); | 5546 Dart_ExitScope(); |
5471 } | 5547 } |
5472 | 5548 |
5473 | 5549 |
5474 static Dart_NativeFunction gnac_lookup(Dart_Handle name, | 5550 static Dart_NativeFunction gnac_lookup(Dart_Handle name, |
5475 int argument_count, | 5551 int argument_count, |
5476 bool* auto_setup_scope) { | 5552 bool* auto_setup_scope) { |
5477 ASSERT(auto_setup_scope != NULL); | 5553 ASSERT(auto_setup_scope != NULL); |
5478 *auto_setup_scope = false; | 5554 *auto_setup_scope = true; |
5479 return reinterpret_cast<Dart_NativeFunction>(&NativeArgumentCounter); | 5555 return reinterpret_cast<Dart_NativeFunction>(&NativeArgumentCounter); |
5480 } | 5556 } |
5481 | 5557 |
5482 | 5558 |
5483 TEST_CASE(GetNativeArgumentCount) { | 5559 TEST_CASE(GetNativeArgumentCount) { |
5484 const char* kScriptChars = | 5560 const char* kScriptChars = |
5485 "class MyObject {" | 5561 "class MyObject {" |
5486 " int method1(int i, int j) native 'Name_Does_Not_Matter';" | 5562 " int method1(int i, int j) native 'Name_Does_Not_Matter';" |
5487 "}" | 5563 "}" |
5488 "testMain() {" | 5564 "testMain() {" |
(...skipping 2472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7961 } | 8037 } |
7962 | 8038 |
7963 | 8039 |
7964 // Allocates an object in new space and assigns it a peer. Allows the | 8040 // Allocates an object in new space and assigns it a peer. Allows the |
7965 // peer referent to be garbage collected and checks that the count of | 8041 // peer referent to be garbage collected and checks that the count of |
7966 // peer objects is decremented by one. | 8042 // peer objects is decremented by one. |
7967 TEST_CASE(CollectOneNewSpacePeer) { | 8043 TEST_CASE(CollectOneNewSpacePeer) { |
7968 Isolate* isolate = Isolate::Current(); | 8044 Isolate* isolate = Isolate::Current(); |
7969 Dart_EnterScope(); | 8045 Dart_EnterScope(); |
7970 { | 8046 { |
7971 DARTSCOPE(Thread::Current()); | 8047 CHECK_API_SCOPE(thread); |
| 8048 HANDLESCOPE(thread); |
7972 Dart_Handle str = NewString("a string"); | 8049 Dart_Handle str = NewString("a string"); |
7973 EXPECT_VALID(str); | 8050 EXPECT_VALID(str); |
7974 EXPECT(Dart_IsString(str)); | 8051 EXPECT(Dart_IsString(str)); |
7975 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 8052 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
7976 void* out = &out; | 8053 void* out = &out; |
7977 EXPECT_VALID(Dart_GetPeer(str, &out)); | 8054 EXPECT_VALID(Dart_GetPeer(str, &out)); |
7978 EXPECT(out == NULL); | 8055 EXPECT(out == NULL); |
7979 int peer = 1234; | 8056 int peer = 1234; |
7980 EXPECT_VALID(Dart_SetPeer(str, &peer)); | 8057 EXPECT_VALID(Dart_SetPeer(str, &peer)); |
7981 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 8058 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
7982 out = &out; | 8059 out = &out; |
7983 EXPECT_VALID(Dart_GetPeer(str, &out)); | 8060 EXPECT_VALID(Dart_GetPeer(str, &out)); |
7984 EXPECT(out == reinterpret_cast<void*>(&peer)); | 8061 EXPECT(out == reinterpret_cast<void*>(&peer)); |
7985 isolate->heap()->CollectGarbage(Heap::kNew); | 8062 { |
7986 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 8063 TransitionNativeToVM transition(thread); |
| 8064 isolate->heap()->CollectGarbage(Heap::kNew); |
| 8065 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
| 8066 } |
7987 out = &out; | 8067 out = &out; |
7988 EXPECT_VALID(Dart_GetPeer(str, &out)); | 8068 EXPECT_VALID(Dart_GetPeer(str, &out)); |
7989 EXPECT(out == reinterpret_cast<void*>(&peer)); | 8069 EXPECT(out == reinterpret_cast<void*>(&peer)); |
7990 } | 8070 } |
7991 Dart_ExitScope(); | 8071 Dart_ExitScope(); |
7992 isolate->heap()->CollectGarbage(Heap::kNew); | 8072 { |
7993 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 8073 TransitionNativeToVM transition(thread); |
| 8074 isolate->heap()->CollectGarbage(Heap::kNew); |
| 8075 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
| 8076 } |
7994 } | 8077 } |
7995 | 8078 |
7996 | 8079 |
7997 // Allocates two objects in new space and assigns them peers. Removes | 8080 // Allocates two objects in new space and assigns them peers. Removes |
7998 // the peers and checks that the count of peer objects is decremented | 8081 // the peers and checks that the count of peer objects is decremented |
7999 // by two. | 8082 // by two. |
8000 TEST_CASE(TwoNewSpacePeers) { | 8083 TEST_CASE(TwoNewSpacePeers) { |
8001 Isolate* isolate = Isolate::Current(); | 8084 Isolate* isolate = Isolate::Current(); |
8002 Dart_Handle s1 = NewString("s1"); | 8085 Dart_Handle s1 = NewString("s1"); |
8003 EXPECT_VALID(s1); | 8086 EXPECT_VALID(s1); |
(...skipping 30 matching lines...) Expand all Loading... |
8034 } | 8117 } |
8035 | 8118 |
8036 | 8119 |
8037 // Allocates two objects in new space and assigns them a peer. Allow | 8120 // Allocates two objects in new space and assigns them a peer. Allow |
8038 // the peer referents to be garbage collected and check that the count | 8121 // the peer referents to be garbage collected and check that the count |
8039 // of peer objects is decremented by two. | 8122 // of peer objects is decremented by two. |
8040 TEST_CASE(CollectTwoNewSpacePeers) { | 8123 TEST_CASE(CollectTwoNewSpacePeers) { |
8041 Isolate* isolate = Isolate::Current(); | 8124 Isolate* isolate = Isolate::Current(); |
8042 Dart_EnterScope(); | 8125 Dart_EnterScope(); |
8043 { | 8126 { |
8044 DARTSCOPE(Thread::Current()); | 8127 CHECK_API_SCOPE(thread); |
| 8128 HANDLESCOPE(thread); |
8045 Dart_Handle s1 = NewString("s1"); | 8129 Dart_Handle s1 = NewString("s1"); |
8046 EXPECT_VALID(s1); | 8130 EXPECT_VALID(s1); |
8047 EXPECT(Dart_IsString(s1)); | 8131 EXPECT(Dart_IsString(s1)); |
8048 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 8132 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
8049 void* o1 = &o1; | 8133 void* o1 = &o1; |
8050 EXPECT(Dart_GetPeer(s1, &o1)); | 8134 EXPECT(Dart_GetPeer(s1, &o1)); |
8051 EXPECT(o1 == NULL); | 8135 EXPECT(o1 == NULL); |
8052 int p1 = 1234; | 8136 int p1 = 1234; |
8053 EXPECT_VALID(Dart_SetPeer(s1, &p1)); | 8137 EXPECT_VALID(Dart_SetPeer(s1, &p1)); |
8054 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 8138 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
8055 EXPECT_VALID(Dart_GetPeer(s1, &o1)); | 8139 EXPECT_VALID(Dart_GetPeer(s1, &o1)); |
8056 EXPECT(o1 == reinterpret_cast<void*>(&p1)); | 8140 EXPECT(o1 == reinterpret_cast<void*>(&p1)); |
8057 Dart_Handle s2 = NewString("s2"); | 8141 Dart_Handle s2 = NewString("s2"); |
8058 EXPECT_VALID(s2); | 8142 EXPECT_VALID(s2); |
8059 EXPECT(Dart_IsString(s2)); | 8143 EXPECT(Dart_IsString(s2)); |
8060 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 8144 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
8061 void* o2 = &o2; | 8145 void* o2 = &o2; |
8062 EXPECT(Dart_GetPeer(s2, &o2)); | 8146 EXPECT(Dart_GetPeer(s2, &o2)); |
8063 EXPECT(o2 == NULL); | 8147 EXPECT(o2 == NULL); |
8064 int p2 = 5678; | 8148 int p2 = 5678; |
8065 EXPECT_VALID(Dart_SetPeer(s2, &p2)); | 8149 EXPECT_VALID(Dart_SetPeer(s2, &p2)); |
8066 EXPECT_EQ(2, isolate->heap()->PeerCount()); | 8150 EXPECT_EQ(2, isolate->heap()->PeerCount()); |
8067 EXPECT_VALID(Dart_GetPeer(s2, &o2)); | 8151 EXPECT_VALID(Dart_GetPeer(s2, &o2)); |
8068 EXPECT(o2 == reinterpret_cast<void*>(&p2)); | 8152 EXPECT(o2 == reinterpret_cast<void*>(&p2)); |
8069 } | 8153 } |
8070 Dart_ExitScope(); | 8154 Dart_ExitScope(); |
8071 isolate->heap()->CollectGarbage(Heap::kNew); | 8155 { |
8072 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 8156 TransitionNativeToVM transition(thread); |
| 8157 isolate->heap()->CollectGarbage(Heap::kNew); |
| 8158 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
| 8159 } |
8073 } | 8160 } |
8074 | 8161 |
8075 | 8162 |
8076 // Allocates several objects in new space. Performs successive | 8163 // Allocates several objects in new space. Performs successive |
8077 // garbage collections and checks that the peer count is stable. | 8164 // garbage collections and checks that the peer count is stable. |
8078 TEST_CASE(CopyNewSpacePeers) { | 8165 TEST_CASE(CopyNewSpacePeers) { |
8079 const int kPeerCount = 10; | 8166 const int kPeerCount = 10; |
8080 Isolate* isolate = Isolate::Current(); | 8167 Isolate* isolate = Isolate::Current(); |
8081 Dart_Handle s[kPeerCount]; | 8168 Dart_Handle s[kPeerCount]; |
8082 for (int i = 0; i < kPeerCount; ++i) { | 8169 for (int i = 0; i < kPeerCount; ++i) { |
8083 s[i] = NewString("a string"); | 8170 s[i] = NewString("a string"); |
8084 EXPECT_VALID(s[i]); | 8171 EXPECT_VALID(s[i]); |
8085 EXPECT(Dart_IsString(s[i])); | 8172 EXPECT(Dart_IsString(s[i])); |
8086 void* o = &o; | 8173 void* o = &o; |
8087 EXPECT_VALID(Dart_GetPeer(s[i], &o)); | 8174 EXPECT_VALID(Dart_GetPeer(s[i], &o)); |
8088 EXPECT(o == NULL); | 8175 EXPECT(o == NULL); |
8089 } | 8176 } |
8090 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 8177 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
8091 int p[kPeerCount]; | 8178 int p[kPeerCount]; |
8092 for (int i = 0; i < kPeerCount; ++i) { | 8179 for (int i = 0; i < kPeerCount; ++i) { |
8093 EXPECT_VALID(Dart_SetPeer(s[i], &p[i])); | 8180 EXPECT_VALID(Dart_SetPeer(s[i], &p[i])); |
8094 EXPECT_EQ(i + 1, isolate->heap()->PeerCount()); | 8181 EXPECT_EQ(i + 1, isolate->heap()->PeerCount()); |
8095 void* o = &o; | 8182 void* o = &o; |
8096 EXPECT_VALID(Dart_GetPeer(s[i], &o)); | 8183 EXPECT_VALID(Dart_GetPeer(s[i], &o)); |
8097 EXPECT(o == reinterpret_cast<void*>(&p[i])); | 8184 EXPECT(o == reinterpret_cast<void*>(&p[i])); |
8098 } | 8185 } |
8099 EXPECT_EQ(kPeerCount, isolate->heap()->PeerCount()); | 8186 EXPECT_EQ(kPeerCount, isolate->heap()->PeerCount()); |
8100 isolate->heap()->CollectGarbage(Heap::kNew); | 8187 { |
8101 EXPECT_EQ(kPeerCount, isolate->heap()->PeerCount()); | 8188 TransitionNativeToVM transition(thread); |
8102 isolate->heap()->CollectGarbage(Heap::kNew); | 8189 isolate->heap()->CollectGarbage(Heap::kNew); |
8103 EXPECT_EQ(kPeerCount, isolate->heap()->PeerCount()); | 8190 EXPECT_EQ(kPeerCount, isolate->heap()->PeerCount()); |
| 8191 isolate->heap()->CollectGarbage(Heap::kNew); |
| 8192 EXPECT_EQ(kPeerCount, isolate->heap()->PeerCount()); |
| 8193 } |
8104 } | 8194 } |
8105 | 8195 |
8106 | 8196 |
8107 // Allocates an object in new space and assigns it a peer. Promotes | 8197 // Allocates an object in new space and assigns it a peer. Promotes |
8108 // the peer to old space. Removes the peer and check that the count | 8198 // the peer to old space. Removes the peer and check that the count |
8109 // of peer objects is decremented by one. | 8199 // of peer objects is decremented by one. |
8110 TEST_CASE(OnePromotedPeer) { | 8200 TEST_CASE(OnePromotedPeer) { |
8111 Isolate* isolate = Isolate::Current(); | 8201 Isolate* isolate = Isolate::Current(); |
8112 Dart_Handle str = NewString("a string"); | 8202 Dart_Handle str = NewString("a string"); |
8113 EXPECT_VALID(str); | 8203 EXPECT_VALID(str); |
8114 EXPECT(Dart_IsString(str)); | 8204 EXPECT(Dart_IsString(str)); |
8115 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 8205 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
8116 void* out = &out; | 8206 void* out = &out; |
8117 EXPECT(Dart_GetPeer(str, &out)); | 8207 EXPECT(Dart_GetPeer(str, &out)); |
8118 EXPECT(out == NULL); | 8208 EXPECT(out == NULL); |
8119 int peer = 1234; | 8209 int peer = 1234; |
8120 EXPECT_VALID(Dart_SetPeer(str, &peer)); | 8210 EXPECT_VALID(Dart_SetPeer(str, &peer)); |
8121 out = &out; | 8211 out = &out; |
8122 EXPECT(Dart_GetPeer(str, &out)); | 8212 EXPECT(Dart_GetPeer(str, &out)); |
8123 EXPECT(out == reinterpret_cast<void*>(&peer)); | 8213 EXPECT(out == reinterpret_cast<void*>(&peer)); |
8124 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 8214 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
8125 isolate->heap()->CollectGarbage(Heap::kNew); | |
8126 isolate->heap()->CollectGarbage(Heap::kNew); | |
8127 { | 8215 { |
8128 DARTSCOPE(Thread::Current()); | 8216 TransitionNativeToVM transition(thread); |
| 8217 isolate->heap()->CollectGarbage(Heap::kNew); |
| 8218 isolate->heap()->CollectGarbage(Heap::kNew); |
| 8219 } |
| 8220 { |
| 8221 CHECK_API_SCOPE(thread); |
| 8222 HANDLESCOPE(thread); |
8129 String& handle = String::Handle(); | 8223 String& handle = String::Handle(); |
8130 handle ^= Api::UnwrapHandle(str); | 8224 handle ^= Api::UnwrapHandle(str); |
8131 EXPECT(handle.IsOld()); | 8225 EXPECT(handle.IsOld()); |
8132 } | 8226 } |
8133 EXPECT_VALID(Dart_GetPeer(str, &out)); | 8227 EXPECT_VALID(Dart_GetPeer(str, &out)); |
8134 EXPECT(out == reinterpret_cast<void*>(&peer)); | 8228 EXPECT(out == reinterpret_cast<void*>(&peer)); |
8135 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 8229 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
8136 EXPECT_VALID(Dart_SetPeer(str, NULL)); | 8230 EXPECT_VALID(Dart_SetPeer(str, NULL)); |
8137 out = &out; | 8231 out = &out; |
8138 EXPECT_VALID(Dart_GetPeer(str, &out)); | 8232 EXPECT_VALID(Dart_GetPeer(str, &out)); |
(...skipping 13 matching lines...) Expand all Loading... |
8152 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 8246 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
8153 void* out = &out; | 8247 void* out = &out; |
8154 EXPECT(Dart_GetPeer(str, &out)); | 8248 EXPECT(Dart_GetPeer(str, &out)); |
8155 EXPECT(out == NULL); | 8249 EXPECT(out == NULL); |
8156 int peer = 1234; | 8250 int peer = 1234; |
8157 EXPECT_VALID(Dart_SetPeer(str, &peer)); | 8251 EXPECT_VALID(Dart_SetPeer(str, &peer)); |
8158 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 8252 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
8159 out = &out; | 8253 out = &out; |
8160 EXPECT_VALID(Dart_GetPeer(str, &out)); | 8254 EXPECT_VALID(Dart_GetPeer(str, &out)); |
8161 EXPECT(out == reinterpret_cast<void*>(&peer)); | 8255 EXPECT(out == reinterpret_cast<void*>(&peer)); |
8162 isolate->heap()->CollectGarbage(Heap::kOld); | 8256 { |
8163 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 8257 TransitionNativeToVM transition(thread); |
| 8258 isolate->heap()->CollectGarbage(Heap::kOld); |
| 8259 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
| 8260 } |
8164 EXPECT_VALID(Dart_GetPeer(str, &out)); | 8261 EXPECT_VALID(Dart_GetPeer(str, &out)); |
8165 EXPECT(out == reinterpret_cast<void*>(&peer)); | 8262 EXPECT(out == reinterpret_cast<void*>(&peer)); |
8166 EXPECT_VALID(Dart_SetPeer(str, NULL)); | 8263 EXPECT_VALID(Dart_SetPeer(str, NULL)); |
8167 out = &out; | 8264 out = &out; |
8168 EXPECT_VALID(Dart_GetPeer(str, &out)); | 8265 EXPECT_VALID(Dart_GetPeer(str, &out)); |
8169 EXPECT(out == NULL); | 8266 EXPECT(out == NULL); |
8170 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 8267 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
8171 } | 8268 } |
8172 | 8269 |
8173 | 8270 |
8174 // Allocates an object in old space and assigns it a peer. Allow the | 8271 // Allocates an object in old space and assigns it a peer. Allow the |
8175 // peer referent to be garbage collected and check that the count of | 8272 // peer referent to be garbage collected and check that the count of |
8176 // peer objects is decremented by one. | 8273 // peer objects is decremented by one. |
8177 TEST_CASE(CollectOneOldSpacePeer) { | 8274 TEST_CASE(CollectOneOldSpacePeer) { |
8178 Isolate* isolate = Isolate::Current(); | 8275 Isolate* isolate = Isolate::Current(); |
8179 Dart_EnterScope(); | 8276 Dart_EnterScope(); |
8180 { | 8277 { |
8181 DARTSCOPE(Thread::Current()); | 8278 Thread* T = Thread::Current(); |
| 8279 CHECK_API_SCOPE(T); |
| 8280 HANDLESCOPE(T); |
8182 Dart_Handle str = Api::NewHandle(T, String::New("str", Heap::kOld)); | 8281 Dart_Handle str = Api::NewHandle(T, String::New("str", Heap::kOld)); |
8183 EXPECT_VALID(str); | 8282 EXPECT_VALID(str); |
8184 EXPECT(Dart_IsString(str)); | 8283 EXPECT(Dart_IsString(str)); |
8185 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 8284 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
8186 void* out = &out; | 8285 void* out = &out; |
8187 EXPECT(Dart_GetPeer(str, &out)); | 8286 EXPECT(Dart_GetPeer(str, &out)); |
8188 EXPECT(out == NULL); | 8287 EXPECT(out == NULL); |
8189 int peer = 1234; | 8288 int peer = 1234; |
8190 EXPECT_VALID(Dart_SetPeer(str, &peer)); | 8289 EXPECT_VALID(Dart_SetPeer(str, &peer)); |
8191 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 8290 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
8192 out = &out; | 8291 out = &out; |
8193 EXPECT_VALID(Dart_GetPeer(str, &out)); | 8292 EXPECT_VALID(Dart_GetPeer(str, &out)); |
8194 EXPECT(out == reinterpret_cast<void*>(&peer)); | 8293 EXPECT(out == reinterpret_cast<void*>(&peer)); |
8195 isolate->heap()->CollectGarbage(Heap::kOld); | 8294 { |
8196 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 8295 TransitionNativeToVM transition(thread); |
| 8296 isolate->heap()->CollectGarbage(Heap::kOld); |
| 8297 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
| 8298 } |
8197 EXPECT_VALID(Dart_GetPeer(str, &out)); | 8299 EXPECT_VALID(Dart_GetPeer(str, &out)); |
8198 EXPECT(out == reinterpret_cast<void*>(&peer)); | 8300 EXPECT(out == reinterpret_cast<void*>(&peer)); |
8199 } | 8301 } |
8200 Dart_ExitScope(); | 8302 Dart_ExitScope(); |
8201 isolate->heap()->CollectGarbage(Heap::kOld); | 8303 { |
8202 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 8304 TransitionNativeToVM transition(thread); |
| 8305 isolate->heap()->CollectGarbage(Heap::kOld); |
| 8306 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
| 8307 } |
8203 } | 8308 } |
8204 | 8309 |
8205 | 8310 |
8206 // Allocates two objects in old space and assigns them peers. Removes | 8311 // Allocates two objects in old space and assigns them peers. Removes |
8207 // the peers and checks that the count of peer objects is decremented | 8312 // the peers and checks that the count of peer objects is decremented |
8208 // by two. | 8313 // by two. |
8209 TEST_CASE(TwoOldSpacePeers) { | 8314 TEST_CASE(TwoOldSpacePeers) { |
8210 Isolate* isolate = Isolate::Current(); | 8315 Isolate* isolate = Isolate::Current(); |
8211 Dart_Handle s1 = Api::NewHandle(thread, String::New("s1", Heap::kOld)); | 8316 Dart_Handle s1 = Api::NewHandle(thread, String::New("s1", Heap::kOld)); |
8212 EXPECT_VALID(s1); | 8317 EXPECT_VALID(s1); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8247 } | 8352 } |
8248 | 8353 |
8249 | 8354 |
8250 // Allocates two objects in old space and assigns them a peer. Allows | 8355 // Allocates two objects in old space and assigns them a peer. Allows |
8251 // the peer referents to be garbage collected and checks that the | 8356 // the peer referents to be garbage collected and checks that the |
8252 // count of peer objects is decremented by two. | 8357 // count of peer objects is decremented by two. |
8253 TEST_CASE(CollectTwoOldSpacePeers) { | 8358 TEST_CASE(CollectTwoOldSpacePeers) { |
8254 Isolate* isolate = Isolate::Current(); | 8359 Isolate* isolate = Isolate::Current(); |
8255 Dart_EnterScope(); | 8360 Dart_EnterScope(); |
8256 { | 8361 { |
8257 DARTSCOPE(Thread::Current()); | 8362 Thread* T = Thread::Current(); |
| 8363 CHECK_API_SCOPE(T); |
| 8364 HANDLESCOPE(T); |
8258 Dart_Handle s1 = Api::NewHandle(T, String::New("s1", Heap::kOld)); | 8365 Dart_Handle s1 = Api::NewHandle(T, String::New("s1", Heap::kOld)); |
8259 EXPECT_VALID(s1); | 8366 EXPECT_VALID(s1); |
8260 EXPECT(Dart_IsString(s1)); | 8367 EXPECT(Dart_IsString(s1)); |
8261 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 8368 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
8262 void* o1 = &o1; | 8369 void* o1 = &o1; |
8263 EXPECT(Dart_GetPeer(s1, &o1)); | 8370 EXPECT(Dart_GetPeer(s1, &o1)); |
8264 EXPECT(o1 == NULL); | 8371 EXPECT(o1 == NULL); |
8265 int p1 = 1234; | 8372 int p1 = 1234; |
8266 EXPECT_VALID(Dart_SetPeer(s1, &p1)); | 8373 EXPECT_VALID(Dart_SetPeer(s1, &p1)); |
8267 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 8374 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
8268 o1 = &o1; | 8375 o1 = &o1; |
8269 EXPECT_VALID(Dart_GetPeer(s1, &o1)); | 8376 EXPECT_VALID(Dart_GetPeer(s1, &o1)); |
8270 EXPECT(o1 == reinterpret_cast<void*>(&p1)); | 8377 EXPECT(o1 == reinterpret_cast<void*>(&p1)); |
8271 Dart_Handle s2 = Api::NewHandle(T, String::New("s2", Heap::kOld)); | 8378 Dart_Handle s2 = Api::NewHandle(T, String::New("s2", Heap::kOld)); |
8272 EXPECT_VALID(s2); | 8379 EXPECT_VALID(s2); |
8273 EXPECT(Dart_IsString(s2)); | 8380 EXPECT(Dart_IsString(s2)); |
8274 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 8381 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
8275 void* o2 = &o2; | 8382 void* o2 = &o2; |
8276 EXPECT(Dart_GetPeer(s2, &o2)); | 8383 EXPECT(Dart_GetPeer(s2, &o2)); |
8277 EXPECT(o2 == NULL); | 8384 EXPECT(o2 == NULL); |
8278 int p2 = 5678; | 8385 int p2 = 5678; |
8279 EXPECT_VALID(Dart_SetPeer(s2, &p2)); | 8386 EXPECT_VALID(Dart_SetPeer(s2, &p2)); |
8280 EXPECT_EQ(2, isolate->heap()->PeerCount()); | 8387 EXPECT_EQ(2, isolate->heap()->PeerCount()); |
8281 o2 = &o2; | 8388 o2 = &o2; |
8282 EXPECT_VALID(Dart_GetPeer(s2, &o2)); | 8389 EXPECT_VALID(Dart_GetPeer(s2, &o2)); |
8283 EXPECT(o2 == reinterpret_cast<void*>(&p2)); | 8390 EXPECT(o2 == reinterpret_cast<void*>(&p2)); |
8284 } | 8391 } |
8285 Dart_ExitScope(); | 8392 Dart_ExitScope(); |
8286 isolate->heap()->CollectGarbage(Heap::kOld); | 8393 { |
8287 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 8394 TransitionNativeToVM transition(thread); |
| 8395 isolate->heap()->CollectGarbage(Heap::kOld); |
| 8396 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
| 8397 } |
8288 } | 8398 } |
8289 | 8399 |
8290 | 8400 |
8291 // Test API call to make strings external. | 8401 // Test API call to make strings external. |
8292 static void MakeExternalCback(void* peer) { | 8402 static void MakeExternalCback(void* peer) { |
8293 *static_cast<int*>(peer) *= 2; | 8403 *static_cast<int*>(peer) *= 2; |
8294 } | 8404 } |
8295 | 8405 |
8296 | 8406 |
8297 TEST_CASE(MakeExternalString) { | 8407 TEST_CASE(MakeExternalString) { |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8484 EXPECT(Dart_IdentityEquals(str, symbol_str)); | 8594 EXPECT(Dart_IdentityEquals(str, symbol_str)); |
8485 for (intptr_t i = 0; i < length; i++) { | 8595 for (intptr_t i = 0; i < length; i++) { |
8486 EXPECT_EQ(symbol_ascii[i], ext_symbol_ascii[i]); | 8596 EXPECT_EQ(symbol_ascii[i], ext_symbol_ascii[i]); |
8487 } | 8597 } |
8488 | 8598 |
8489 Dart_ExitScope(); | 8599 Dart_ExitScope(); |
8490 } | 8600 } |
8491 EXPECT_EQ(40, peer8); | 8601 EXPECT_EQ(40, peer8); |
8492 EXPECT_EQ(41, peer16); | 8602 EXPECT_EQ(41, peer16); |
8493 EXPECT_EQ(42, canonical_str_peer); | 8603 EXPECT_EQ(42, canonical_str_peer); |
8494 Isolate::Current()->heap()->CollectAllGarbage(); | 8604 { |
| 8605 TransitionNativeToVM transition(thread); |
| 8606 Isolate::Current()->heap()->CollectAllGarbage(); |
| 8607 } |
8495 EXPECT_EQ(80, peer8); | 8608 EXPECT_EQ(80, peer8); |
8496 EXPECT_EQ(82, peer16); | 8609 EXPECT_EQ(82, peer16); |
8497 EXPECT_EQ(42, canonical_str_peer); // "*" Symbol is not removed on GC. | 8610 EXPECT_EQ(42, canonical_str_peer); // "*" Symbol is not removed on GC. |
8498 } | 8611 } |
8499 | 8612 |
8500 | 8613 |
8501 TEST_CASE(ExternalizeConstantStrings) { | 8614 TEST_CASE(ExternalizeConstantStrings) { |
8502 const char* kScriptChars = | 8615 const char* kScriptChars = |
8503 "String testMain() {\n" | 8616 "String testMain() {\n" |
8504 " return 'constant string';\n" | 8617 " return 'constant string';\n" |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8596 &ExternalStringDeoptimize_Finalize); | 8709 &ExternalStringDeoptimize_Finalize); |
8597 EXPECT_VALID(result); | 8710 EXPECT_VALID(result); |
8598 EXPECT(Dart_IsExternalString(result)); | 8711 EXPECT(Dart_IsExternalString(result)); |
8599 Dart_ExitScope(); | 8712 Dart_ExitScope(); |
8600 } | 8713 } |
8601 | 8714 |
8602 | 8715 |
8603 static Dart_NativeFunction ExternalStringDeoptimize_native_lookup( | 8716 static Dart_NativeFunction ExternalStringDeoptimize_native_lookup( |
8604 Dart_Handle name, int argument_count, bool* auto_setup_scope) { | 8717 Dart_Handle name, int argument_count, bool* auto_setup_scope) { |
8605 ASSERT(auto_setup_scope != NULL); | 8718 ASSERT(auto_setup_scope != NULL); |
8606 *auto_setup_scope = false; | 8719 *auto_setup_scope = true; |
8607 return reinterpret_cast<Dart_NativeFunction>(&A_change_str_native); | 8720 return reinterpret_cast<Dart_NativeFunction>(&A_change_str_native); |
8608 } | 8721 } |
8609 | 8722 |
8610 | 8723 |
8611 // Do not use guarding mechanism on externalizable classes, since their class | 8724 // Do not use guarding mechanism on externalizable classes, since their class |
8612 // can change on the fly, | 8725 // can change on the fly, |
8613 TEST_CASE(GuardExternalizedString) { | 8726 TEST_CASE(GuardExternalizedString) { |
8614 const char* kScriptChars = | 8727 const char* kScriptChars = |
8615 "main() {\n" | 8728 "main() {\n" |
8616 " var a = new A('hello');\n" | 8729 " var a = new A('hello');\n" |
(...skipping 943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9560 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); | 9673 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); |
9561 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); | 9674 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); |
9562 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); | 9675 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); |
9563 | 9676 |
9564 // Heartbeat test for new events. | 9677 // Heartbeat test for new events. |
9565 EXPECT_SUBSTRING("\"name\":\"TestVMDuration2\"", buffer); | 9678 EXPECT_SUBSTRING("\"name\":\"TestVMDuration2\"", buffer); |
9566 EXPECT_SUBSTRING("\"function\":\"::_bar\"", buffer); | 9679 EXPECT_SUBSTRING("\"function\":\"::_bar\"", buffer); |
9567 } | 9680 } |
9568 | 9681 |
9569 } // namespace dart | 9682 } // namespace dart |
OLD | NEW |