| 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 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3994 kNumNativeFields); | 4065 kNumNativeFields); |
| 3995 EXPECT_VALID(result); | 4066 EXPECT_VALID(result); |
| 3996 result = Dart_FinalizeLoading(false); | 4067 result = Dart_FinalizeLoading(false); |
| 3997 EXPECT_VALID(result); | 4068 EXPECT_VALID(result); |
| 3998 | 4069 |
| 3999 // Load up a test script in the test library. | 4070 // Load up a test script in the test library. |
| 4000 | 4071 |
| 4001 // Invoke a function which returns an object of type NativeFields. | 4072 // Invoke a function which returns an object of type NativeFields. |
| 4002 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 4073 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
| 4003 EXPECT_VALID(result); | 4074 EXPECT_VALID(result); |
| 4004 DARTSCOPE(Thread::Current()); | 4075 CHECK_API_SCOPE(thread); |
| 4076 HANDLESCOPE(thread); |
| 4005 Instance& obj = Instance::Handle(); | 4077 Instance& obj = Instance::Handle(); |
| 4006 obj ^= Api::UnwrapHandle(result); | 4078 obj ^= Api::UnwrapHandle(result); |
| 4007 const Class& cls = Class::Handle(obj.clazz()); | 4079 const Class& cls = Class::Handle(obj.clazz()); |
| 4008 // We expect the newly created "NativeFields" object to have | 4080 // We expect the newly created "NativeFields" object to have |
| 4009 // 2 dart instance fields (fld1, fld2) and a reference to the native fields. | 4081 // 2 dart instance fields (fld1, fld2) and a reference to the native fields. |
| 4010 // Hence the size of an instance of "NativeFields" should be | 4082 // Hence the size of an instance of "NativeFields" should be |
| 4011 // (1 + 2) * kWordSize + size of object header. | 4083 // (1 + 2) * kWordSize + size of object header. |
| 4012 // We check to make sure the instance size computed by the VM matches | 4084 // We check to make sure the instance size computed by the VM matches |
| 4013 // our expectations. | 4085 // our expectations. |
| 4014 intptr_t header_size = sizeof(RawObject); | 4086 intptr_t header_size = sizeof(RawObject); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4064 Dart_Handle result; | 4136 Dart_Handle result; |
| 4065 const int kNumNativeFields = 2; | 4137 const int kNumNativeFields = 2; |
| 4066 | 4138 |
| 4067 // Load up a test script in the test library. | 4139 // Load up a test script in the test library. |
| 4068 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, | 4140 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, |
| 4069 native_field_lookup); | 4141 native_field_lookup); |
| 4070 | 4142 |
| 4071 // Invoke a function which returns an object of type NativeFields. | 4143 // Invoke a function which returns an object of type NativeFields. |
| 4072 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 4144 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
| 4073 EXPECT_VALID(result); | 4145 EXPECT_VALID(result); |
| 4074 DARTSCOPE(Thread::Current()); | 4146 CHECK_API_SCOPE(thread); |
| 4147 HANDLESCOPE(thread); |
| 4075 Instance& obj = Instance::Handle(); | 4148 Instance& obj = Instance::Handle(); |
| 4076 obj ^= Api::UnwrapHandle(result); | 4149 obj ^= Api::UnwrapHandle(result); |
| 4077 const Class& cls = Class::Handle(obj.clazz()); | 4150 const Class& cls = Class::Handle(obj.clazz()); |
| 4078 // We expect the newly created "NativeFields" object to have | 4151 // We expect the newly created "NativeFields" object to have |
| 4079 // 2 dart instance fields (fld1, fld2) and a reference to the native fields. | 4152 // 2 dart instance fields (fld1, fld2) and a reference to the native fields. |
| 4080 // Hence the size of an instance of "NativeFields" should be | 4153 // Hence the size of an instance of "NativeFields" should be |
| 4081 // (1 + 2) * kWordSize + size of object header. | 4154 // (1 + 2) * kWordSize + size of object header. |
| 4082 // We check to make sure the instance size computed by the VM matches | 4155 // We check to make sure the instance size computed by the VM matches |
| 4083 // our expectations. | 4156 // our expectations. |
| 4084 intptr_t header_size = sizeof(RawObject); | 4157 intptr_t header_size = sizeof(RawObject); |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4408 " static const int fld4 = 10;\n" | 4481 " static const int fld4 = 10;\n" |
| 4409 "}\n" | 4482 "}\n" |
| 4410 "NativeFields testMain1() {\n" | 4483 "NativeFields testMain1() {\n" |
| 4411 " NativeFields obj = new NativeFields(10, 20);\n" | 4484 " NativeFields obj = new NativeFields(10, 20);\n" |
| 4412 " return obj;\n" | 4485 " return obj;\n" |
| 4413 "}\n" | 4486 "}\n" |
| 4414 "Function testMain2() {\n" | 4487 "Function testMain2() {\n" |
| 4415 " return () {};\n" | 4488 " return () {};\n" |
| 4416 "}\n"; | 4489 "}\n"; |
| 4417 Dart_Handle result; | 4490 Dart_Handle result; |
| 4418 DARTSCOPE(Thread::Current()); | 4491 CHECK_API_SCOPE(thread); |
| 4492 HANDLESCOPE(thread); |
| 4419 | 4493 |
| 4420 // Create a test library and Load up a test script in it. | 4494 // Create a test library and Load up a test script in it. |
| 4421 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 4495 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 4422 | 4496 |
| 4423 // Invoke a function which returns an object of type NativeFields. | 4497 // Invoke a function which returns an object of type NativeFields. |
| 4424 Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain1"), 0, NULL); | 4498 Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain1"), 0, NULL); |
| 4425 EXPECT_VALID(retobj); | 4499 EXPECT_VALID(retobj); |
| 4426 | 4500 |
| 4427 // Now access and set various native instance fields of the returned object. | 4501 // Now access and set various native instance fields of the returned object. |
| 4428 // All of these tests are expected to return failure as there are no | 4502 // 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... |
| 4486 " var port = new RawReceivePort();\n" | 4560 " var port = new RawReceivePort();\n" |
| 4487 " var obj = new Test(1,2);\n" | 4561 " var obj = new Test(1,2);\n" |
| 4488 " var msg = [obj, port.sendPort];\n" | 4562 " var msg = [obj, port.sendPort];\n" |
| 4489 " var snd = Isolate.spawn(echo, msg);\n" | 4563 " var snd = Isolate.spawn(echo, msg);\n" |
| 4490 " port.handler = (msg) {\n" | 4564 " port.handler = (msg) {\n" |
| 4491 " port.close();\n" | 4565 " port.close();\n" |
| 4492 " print('from worker ${msg}');\n" | 4566 " print('from worker ${msg}');\n" |
| 4493 " };\n" | 4567 " };\n" |
| 4494 "}\n"; | 4568 "}\n"; |
| 4495 | 4569 |
| 4496 DARTSCOPE(Thread::Current()); | 4570 CHECK_API_SCOPE(thread); |
| 4571 HANDLESCOPE(thread); |
| 4497 | 4572 |
| 4498 // Create a test library and Load up a test script in it. | 4573 // Create a test library and Load up a test script in it. |
| 4499 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 4574 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 4500 | 4575 |
| 4501 // Invoke 'main' which should spawn an isolate and try to send an | 4576 // Invoke 'main' which should spawn an isolate and try to send an |
| 4502 // object with native fields over to the spawned isolate. This | 4577 // object with native fields over to the spawned isolate. This |
| 4503 // should result in an unhandled exception which is checked. | 4578 // should result in an unhandled exception which is checked. |
| 4504 Dart_Handle retobj = Dart_Invoke(lib, NewString("main"), 0, NULL); | 4579 Dart_Handle retobj = Dart_Invoke(lib, NewString("main"), 0, NULL); |
| 4505 EXPECT(Dart_IsError(retobj)); | 4580 EXPECT(Dart_IsError(retobj)); |
| 4506 } | 4581 } |
| (...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5195 " static const int fld4 = 10;\n" | 5270 " static const int fld4 = 10;\n" |
| 5196 "}\n" | 5271 "}\n" |
| 5197 "Function testMain1() {\n" | 5272 "Function testMain1() {\n" |
| 5198 " InvokeClosure obj = new InvokeClosure(10, 20);\n" | 5273 " InvokeClosure obj = new InvokeClosure(10, 20);\n" |
| 5199 " return obj.method1(10);\n" | 5274 " return obj.method1(10);\n" |
| 5200 "}\n" | 5275 "}\n" |
| 5201 "Function testMain2() {\n" | 5276 "Function testMain2() {\n" |
| 5202 " return InvokeClosure.method2(10);\n" | 5277 " return InvokeClosure.method2(10);\n" |
| 5203 "}\n"; | 5278 "}\n"; |
| 5204 Dart_Handle result; | 5279 Dart_Handle result; |
| 5205 DARTSCOPE(Thread::Current()); | 5280 CHECK_API_SCOPE(thread); |
| 5281 HANDLESCOPE(thread); |
| 5206 | 5282 |
| 5207 // Create a test library and Load up a test script in it. | 5283 // Create a test library and Load up a test script in it. |
| 5208 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 5284 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 5209 | 5285 |
| 5210 // Invoke a function which returns a closure. | 5286 // Invoke a function which returns a closure. |
| 5211 Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain1"), 0, NULL); | 5287 Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain1"), 0, NULL); |
| 5212 EXPECT_VALID(retobj); | 5288 EXPECT_VALID(retobj); |
| 5213 | 5289 |
| 5214 EXPECT(Dart_IsClosure(retobj)); | 5290 EXPECT(Dart_IsClosure(retobj)); |
| 5215 EXPECT(!Dart_IsClosure(Dart_NewInteger(101))); | 5291 EXPECT(!Dart_IsClosure(Dart_NewInteger(101))); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5248 Dart_EnterScope(); | 5324 Dart_EnterScope(); |
| 5249 Dart_ThrowException(NewString("Hello from ExceptionNative!")); | 5325 Dart_ThrowException(NewString("Hello from ExceptionNative!")); |
| 5250 UNREACHABLE(); | 5326 UNREACHABLE(); |
| 5251 } | 5327 } |
| 5252 | 5328 |
| 5253 | 5329 |
| 5254 static Dart_NativeFunction native_lookup(Dart_Handle name, | 5330 static Dart_NativeFunction native_lookup(Dart_Handle name, |
| 5255 int argument_count, | 5331 int argument_count, |
| 5256 bool* auto_setup_scope) { | 5332 bool* auto_setup_scope) { |
| 5257 ASSERT(auto_setup_scope != NULL); | 5333 ASSERT(auto_setup_scope != NULL); |
| 5258 *auto_setup_scope = false; | 5334 *auto_setup_scope = true; |
| 5259 return reinterpret_cast<Dart_NativeFunction>(&ExceptionNative); | 5335 return reinterpret_cast<Dart_NativeFunction>(&ExceptionNative); |
| 5260 } | 5336 } |
| 5261 | 5337 |
| 5262 | 5338 |
| 5263 TEST_CASE(ThrowException) { | 5339 TEST_CASE(ThrowException) { |
| 5264 const char* kScriptChars = | 5340 const char* kScriptChars = |
| 5265 "int test() native \"ThrowException_native\";"; | 5341 "int test() native \"ThrowException_native\";"; |
| 5266 Dart_Handle result; | 5342 Dart_Handle result; |
| 5267 intptr_t size = thread->ZoneSizeInBytes(); | 5343 intptr_t size = thread->ZoneSizeInBytes(); |
| 5268 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. | 5344 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5494 int count = Dart_GetNativeArgumentCount(args); | 5570 int count = Dart_GetNativeArgumentCount(args); |
| 5495 Dart_SetReturnValue(args, Dart_NewInteger(count)); | 5571 Dart_SetReturnValue(args, Dart_NewInteger(count)); |
| 5496 Dart_ExitScope(); | 5572 Dart_ExitScope(); |
| 5497 } | 5573 } |
| 5498 | 5574 |
| 5499 | 5575 |
| 5500 static Dart_NativeFunction gnac_lookup(Dart_Handle name, | 5576 static Dart_NativeFunction gnac_lookup(Dart_Handle name, |
| 5501 int argument_count, | 5577 int argument_count, |
| 5502 bool* auto_setup_scope) { | 5578 bool* auto_setup_scope) { |
| 5503 ASSERT(auto_setup_scope != NULL); | 5579 ASSERT(auto_setup_scope != NULL); |
| 5504 *auto_setup_scope = false; | 5580 *auto_setup_scope = true; |
| 5505 return reinterpret_cast<Dart_NativeFunction>(&NativeArgumentCounter); | 5581 return reinterpret_cast<Dart_NativeFunction>(&NativeArgumentCounter); |
| 5506 } | 5582 } |
| 5507 | 5583 |
| 5508 | 5584 |
| 5509 TEST_CASE(GetNativeArgumentCount) { | 5585 TEST_CASE(GetNativeArgumentCount) { |
| 5510 const char* kScriptChars = | 5586 const char* kScriptChars = |
| 5511 "class MyObject {" | 5587 "class MyObject {" |
| 5512 " int method1(int i, int j) native 'Name_Does_Not_Matter';" | 5588 " int method1(int i, int j) native 'Name_Does_Not_Matter';" |
| 5513 "}" | 5589 "}" |
| 5514 "testMain() {" | 5590 "testMain() {" |
| (...skipping 2472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7987 } | 8063 } |
| 7988 | 8064 |
| 7989 | 8065 |
| 7990 // Allocates an object in new space and assigns it a peer. Allows the | 8066 // Allocates an object in new space and assigns it a peer. Allows the |
| 7991 // peer referent to be garbage collected and checks that the count of | 8067 // peer referent to be garbage collected and checks that the count of |
| 7992 // peer objects is decremented by one. | 8068 // peer objects is decremented by one. |
| 7993 TEST_CASE(CollectOneNewSpacePeer) { | 8069 TEST_CASE(CollectOneNewSpacePeer) { |
| 7994 Isolate* isolate = Isolate::Current(); | 8070 Isolate* isolate = Isolate::Current(); |
| 7995 Dart_EnterScope(); | 8071 Dart_EnterScope(); |
| 7996 { | 8072 { |
| 7997 DARTSCOPE(Thread::Current()); | 8073 CHECK_API_SCOPE(thread); |
| 8074 HANDLESCOPE(thread); |
| 7998 Dart_Handle str = NewString("a string"); | 8075 Dart_Handle str = NewString("a string"); |
| 7999 EXPECT_VALID(str); | 8076 EXPECT_VALID(str); |
| 8000 EXPECT(Dart_IsString(str)); | 8077 EXPECT(Dart_IsString(str)); |
| 8001 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 8078 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
| 8002 void* out = &out; | 8079 void* out = &out; |
| 8003 EXPECT_VALID(Dart_GetPeer(str, &out)); | 8080 EXPECT_VALID(Dart_GetPeer(str, &out)); |
| 8004 EXPECT(out == NULL); | 8081 EXPECT(out == NULL); |
| 8005 int peer = 1234; | 8082 int peer = 1234; |
| 8006 EXPECT_VALID(Dart_SetPeer(str, &peer)); | 8083 EXPECT_VALID(Dart_SetPeer(str, &peer)); |
| 8007 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 8084 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
| 8008 out = &out; | 8085 out = &out; |
| 8009 EXPECT_VALID(Dart_GetPeer(str, &out)); | 8086 EXPECT_VALID(Dart_GetPeer(str, &out)); |
| 8010 EXPECT(out == reinterpret_cast<void*>(&peer)); | 8087 EXPECT(out == reinterpret_cast<void*>(&peer)); |
| 8011 isolate->heap()->CollectGarbage(Heap::kNew); | 8088 { |
| 8012 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 8089 TransitionNativeToVM transition(thread); |
| 8090 isolate->heap()->CollectGarbage(Heap::kNew); |
| 8091 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
| 8092 } |
| 8013 out = &out; | 8093 out = &out; |
| 8014 EXPECT_VALID(Dart_GetPeer(str, &out)); | 8094 EXPECT_VALID(Dart_GetPeer(str, &out)); |
| 8015 EXPECT(out == reinterpret_cast<void*>(&peer)); | 8095 EXPECT(out == reinterpret_cast<void*>(&peer)); |
| 8016 } | 8096 } |
| 8017 Dart_ExitScope(); | 8097 Dart_ExitScope(); |
| 8018 isolate->heap()->CollectGarbage(Heap::kNew); | 8098 { |
| 8019 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 8099 TransitionNativeToVM transition(thread); |
| 8100 isolate->heap()->CollectGarbage(Heap::kNew); |
| 8101 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
| 8102 } |
| 8020 } | 8103 } |
| 8021 | 8104 |
| 8022 | 8105 |
| 8023 // Allocates two objects in new space and assigns them peers. Removes | 8106 // Allocates two objects in new space and assigns them peers. Removes |
| 8024 // the peers and checks that the count of peer objects is decremented | 8107 // the peers and checks that the count of peer objects is decremented |
| 8025 // by two. | 8108 // by two. |
| 8026 TEST_CASE(TwoNewSpacePeers) { | 8109 TEST_CASE(TwoNewSpacePeers) { |
| 8027 Isolate* isolate = Isolate::Current(); | 8110 Isolate* isolate = Isolate::Current(); |
| 8028 Dart_Handle s1 = NewString("s1"); | 8111 Dart_Handle s1 = NewString("s1"); |
| 8029 EXPECT_VALID(s1); | 8112 EXPECT_VALID(s1); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 8060 } | 8143 } |
| 8061 | 8144 |
| 8062 | 8145 |
| 8063 // Allocates two objects in new space and assigns them a peer. Allow | 8146 // Allocates two objects in new space and assigns them a peer. Allow |
| 8064 // the peer referents to be garbage collected and check that the count | 8147 // the peer referents to be garbage collected and check that the count |
| 8065 // of peer objects is decremented by two. | 8148 // of peer objects is decremented by two. |
| 8066 TEST_CASE(CollectTwoNewSpacePeers) { | 8149 TEST_CASE(CollectTwoNewSpacePeers) { |
| 8067 Isolate* isolate = Isolate::Current(); | 8150 Isolate* isolate = Isolate::Current(); |
| 8068 Dart_EnterScope(); | 8151 Dart_EnterScope(); |
| 8069 { | 8152 { |
| 8070 DARTSCOPE(Thread::Current()); | 8153 CHECK_API_SCOPE(thread); |
| 8154 HANDLESCOPE(thread); |
| 8071 Dart_Handle s1 = NewString("s1"); | 8155 Dart_Handle s1 = NewString("s1"); |
| 8072 EXPECT_VALID(s1); | 8156 EXPECT_VALID(s1); |
| 8073 EXPECT(Dart_IsString(s1)); | 8157 EXPECT(Dart_IsString(s1)); |
| 8074 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 8158 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
| 8075 void* o1 = &o1; | 8159 void* o1 = &o1; |
| 8076 EXPECT(Dart_GetPeer(s1, &o1)); | 8160 EXPECT(Dart_GetPeer(s1, &o1)); |
| 8077 EXPECT(o1 == NULL); | 8161 EXPECT(o1 == NULL); |
| 8078 int p1 = 1234; | 8162 int p1 = 1234; |
| 8079 EXPECT_VALID(Dart_SetPeer(s1, &p1)); | 8163 EXPECT_VALID(Dart_SetPeer(s1, &p1)); |
| 8080 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 8164 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
| 8081 EXPECT_VALID(Dart_GetPeer(s1, &o1)); | 8165 EXPECT_VALID(Dart_GetPeer(s1, &o1)); |
| 8082 EXPECT(o1 == reinterpret_cast<void*>(&p1)); | 8166 EXPECT(o1 == reinterpret_cast<void*>(&p1)); |
| 8083 Dart_Handle s2 = NewString("s2"); | 8167 Dart_Handle s2 = NewString("s2"); |
| 8084 EXPECT_VALID(s2); | 8168 EXPECT_VALID(s2); |
| 8085 EXPECT(Dart_IsString(s2)); | 8169 EXPECT(Dart_IsString(s2)); |
| 8086 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 8170 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
| 8087 void* o2 = &o2; | 8171 void* o2 = &o2; |
| 8088 EXPECT(Dart_GetPeer(s2, &o2)); | 8172 EXPECT(Dart_GetPeer(s2, &o2)); |
| 8089 EXPECT(o2 == NULL); | 8173 EXPECT(o2 == NULL); |
| 8090 int p2 = 5678; | 8174 int p2 = 5678; |
| 8091 EXPECT_VALID(Dart_SetPeer(s2, &p2)); | 8175 EXPECT_VALID(Dart_SetPeer(s2, &p2)); |
| 8092 EXPECT_EQ(2, isolate->heap()->PeerCount()); | 8176 EXPECT_EQ(2, isolate->heap()->PeerCount()); |
| 8093 EXPECT_VALID(Dart_GetPeer(s2, &o2)); | 8177 EXPECT_VALID(Dart_GetPeer(s2, &o2)); |
| 8094 EXPECT(o2 == reinterpret_cast<void*>(&p2)); | 8178 EXPECT(o2 == reinterpret_cast<void*>(&p2)); |
| 8095 } | 8179 } |
| 8096 Dart_ExitScope(); | 8180 Dart_ExitScope(); |
| 8097 isolate->heap()->CollectGarbage(Heap::kNew); | 8181 { |
| 8098 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 8182 TransitionNativeToVM transition(thread); |
| 8183 isolate->heap()->CollectGarbage(Heap::kNew); |
| 8184 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
| 8185 } |
| 8099 } | 8186 } |
| 8100 | 8187 |
| 8101 | 8188 |
| 8102 // Allocates several objects in new space. Performs successive | 8189 // Allocates several objects in new space. Performs successive |
| 8103 // garbage collections and checks that the peer count is stable. | 8190 // garbage collections and checks that the peer count is stable. |
| 8104 TEST_CASE(CopyNewSpacePeers) { | 8191 TEST_CASE(CopyNewSpacePeers) { |
| 8105 const int kPeerCount = 10; | 8192 const int kPeerCount = 10; |
| 8106 Isolate* isolate = Isolate::Current(); | 8193 Isolate* isolate = Isolate::Current(); |
| 8107 Dart_Handle s[kPeerCount]; | 8194 Dart_Handle s[kPeerCount]; |
| 8108 for (int i = 0; i < kPeerCount; ++i) { | 8195 for (int i = 0; i < kPeerCount; ++i) { |
| 8109 s[i] = NewString("a string"); | 8196 s[i] = NewString("a string"); |
| 8110 EXPECT_VALID(s[i]); | 8197 EXPECT_VALID(s[i]); |
| 8111 EXPECT(Dart_IsString(s[i])); | 8198 EXPECT(Dart_IsString(s[i])); |
| 8112 void* o = &o; | 8199 void* o = &o; |
| 8113 EXPECT_VALID(Dart_GetPeer(s[i], &o)); | 8200 EXPECT_VALID(Dart_GetPeer(s[i], &o)); |
| 8114 EXPECT(o == NULL); | 8201 EXPECT(o == NULL); |
| 8115 } | 8202 } |
| 8116 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 8203 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
| 8117 int p[kPeerCount]; | 8204 int p[kPeerCount]; |
| 8118 for (int i = 0; i < kPeerCount; ++i) { | 8205 for (int i = 0; i < kPeerCount; ++i) { |
| 8119 EXPECT_VALID(Dart_SetPeer(s[i], &p[i])); | 8206 EXPECT_VALID(Dart_SetPeer(s[i], &p[i])); |
| 8120 EXPECT_EQ(i + 1, isolate->heap()->PeerCount()); | 8207 EXPECT_EQ(i + 1, isolate->heap()->PeerCount()); |
| 8121 void* o = &o; | 8208 void* o = &o; |
| 8122 EXPECT_VALID(Dart_GetPeer(s[i], &o)); | 8209 EXPECT_VALID(Dart_GetPeer(s[i], &o)); |
| 8123 EXPECT(o == reinterpret_cast<void*>(&p[i])); | 8210 EXPECT(o == reinterpret_cast<void*>(&p[i])); |
| 8124 } | 8211 } |
| 8125 EXPECT_EQ(kPeerCount, isolate->heap()->PeerCount()); | 8212 EXPECT_EQ(kPeerCount, isolate->heap()->PeerCount()); |
| 8126 isolate->heap()->CollectGarbage(Heap::kNew); | 8213 { |
| 8127 EXPECT_EQ(kPeerCount, isolate->heap()->PeerCount()); | 8214 TransitionNativeToVM transition(thread); |
| 8128 isolate->heap()->CollectGarbage(Heap::kNew); | 8215 isolate->heap()->CollectGarbage(Heap::kNew); |
| 8129 EXPECT_EQ(kPeerCount, isolate->heap()->PeerCount()); | 8216 EXPECT_EQ(kPeerCount, isolate->heap()->PeerCount()); |
| 8217 isolate->heap()->CollectGarbage(Heap::kNew); |
| 8218 EXPECT_EQ(kPeerCount, isolate->heap()->PeerCount()); |
| 8219 } |
| 8130 } | 8220 } |
| 8131 | 8221 |
| 8132 | 8222 |
| 8133 // Allocates an object in new space and assigns it a peer. Promotes | 8223 // Allocates an object in new space and assigns it a peer. Promotes |
| 8134 // the peer to old space. Removes the peer and check that the count | 8224 // the peer to old space. Removes the peer and check that the count |
| 8135 // of peer objects is decremented by one. | 8225 // of peer objects is decremented by one. |
| 8136 TEST_CASE(OnePromotedPeer) { | 8226 TEST_CASE(OnePromotedPeer) { |
| 8137 Isolate* isolate = Isolate::Current(); | 8227 Isolate* isolate = Isolate::Current(); |
| 8138 Dart_Handle str = NewString("a string"); | 8228 Dart_Handle str = NewString("a string"); |
| 8139 EXPECT_VALID(str); | 8229 EXPECT_VALID(str); |
| 8140 EXPECT(Dart_IsString(str)); | 8230 EXPECT(Dart_IsString(str)); |
| 8141 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 8231 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
| 8142 void* out = &out; | 8232 void* out = &out; |
| 8143 EXPECT(Dart_GetPeer(str, &out)); | 8233 EXPECT(Dart_GetPeer(str, &out)); |
| 8144 EXPECT(out == NULL); | 8234 EXPECT(out == NULL); |
| 8145 int peer = 1234; | 8235 int peer = 1234; |
| 8146 EXPECT_VALID(Dart_SetPeer(str, &peer)); | 8236 EXPECT_VALID(Dart_SetPeer(str, &peer)); |
| 8147 out = &out; | 8237 out = &out; |
| 8148 EXPECT(Dart_GetPeer(str, &out)); | 8238 EXPECT(Dart_GetPeer(str, &out)); |
| 8149 EXPECT(out == reinterpret_cast<void*>(&peer)); | 8239 EXPECT(out == reinterpret_cast<void*>(&peer)); |
| 8150 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 8240 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
| 8151 isolate->heap()->CollectGarbage(Heap::kNew); | |
| 8152 isolate->heap()->CollectGarbage(Heap::kNew); | |
| 8153 { | 8241 { |
| 8154 DARTSCOPE(Thread::Current()); | 8242 TransitionNativeToVM transition(thread); |
| 8243 isolate->heap()->CollectGarbage(Heap::kNew); |
| 8244 isolate->heap()->CollectGarbage(Heap::kNew); |
| 8245 } |
| 8246 { |
| 8247 CHECK_API_SCOPE(thread); |
| 8248 HANDLESCOPE(thread); |
| 8155 String& handle = String::Handle(); | 8249 String& handle = String::Handle(); |
| 8156 handle ^= Api::UnwrapHandle(str); | 8250 handle ^= Api::UnwrapHandle(str); |
| 8157 EXPECT(handle.IsOld()); | 8251 EXPECT(handle.IsOld()); |
| 8158 } | 8252 } |
| 8159 EXPECT_VALID(Dart_GetPeer(str, &out)); | 8253 EXPECT_VALID(Dart_GetPeer(str, &out)); |
| 8160 EXPECT(out == reinterpret_cast<void*>(&peer)); | 8254 EXPECT(out == reinterpret_cast<void*>(&peer)); |
| 8161 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 8255 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
| 8162 EXPECT_VALID(Dart_SetPeer(str, NULL)); | 8256 EXPECT_VALID(Dart_SetPeer(str, NULL)); |
| 8163 out = &out; | 8257 out = &out; |
| 8164 EXPECT_VALID(Dart_GetPeer(str, &out)); | 8258 EXPECT_VALID(Dart_GetPeer(str, &out)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 8178 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 8272 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
| 8179 void* out = &out; | 8273 void* out = &out; |
| 8180 EXPECT(Dart_GetPeer(str, &out)); | 8274 EXPECT(Dart_GetPeer(str, &out)); |
| 8181 EXPECT(out == NULL); | 8275 EXPECT(out == NULL); |
| 8182 int peer = 1234; | 8276 int peer = 1234; |
| 8183 EXPECT_VALID(Dart_SetPeer(str, &peer)); | 8277 EXPECT_VALID(Dart_SetPeer(str, &peer)); |
| 8184 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 8278 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
| 8185 out = &out; | 8279 out = &out; |
| 8186 EXPECT_VALID(Dart_GetPeer(str, &out)); | 8280 EXPECT_VALID(Dart_GetPeer(str, &out)); |
| 8187 EXPECT(out == reinterpret_cast<void*>(&peer)); | 8281 EXPECT(out == reinterpret_cast<void*>(&peer)); |
| 8188 isolate->heap()->CollectGarbage(Heap::kOld); | 8282 { |
| 8189 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 8283 TransitionNativeToVM transition(thread); |
| 8284 isolate->heap()->CollectGarbage(Heap::kOld); |
| 8285 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
| 8286 } |
| 8190 EXPECT_VALID(Dart_GetPeer(str, &out)); | 8287 EXPECT_VALID(Dart_GetPeer(str, &out)); |
| 8191 EXPECT(out == reinterpret_cast<void*>(&peer)); | 8288 EXPECT(out == reinterpret_cast<void*>(&peer)); |
| 8192 EXPECT_VALID(Dart_SetPeer(str, NULL)); | 8289 EXPECT_VALID(Dart_SetPeer(str, NULL)); |
| 8193 out = &out; | 8290 out = &out; |
| 8194 EXPECT_VALID(Dart_GetPeer(str, &out)); | 8291 EXPECT_VALID(Dart_GetPeer(str, &out)); |
| 8195 EXPECT(out == NULL); | 8292 EXPECT(out == NULL); |
| 8196 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 8293 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
| 8197 } | 8294 } |
| 8198 | 8295 |
| 8199 | 8296 |
| 8200 // Allocates an object in old space and assigns it a peer. Allow the | 8297 // Allocates an object in old space and assigns it a peer. Allow the |
| 8201 // peer referent to be garbage collected and check that the count of | 8298 // peer referent to be garbage collected and check that the count of |
| 8202 // peer objects is decremented by one. | 8299 // peer objects is decremented by one. |
| 8203 TEST_CASE(CollectOneOldSpacePeer) { | 8300 TEST_CASE(CollectOneOldSpacePeer) { |
| 8204 Isolate* isolate = Isolate::Current(); | 8301 Isolate* isolate = Isolate::Current(); |
| 8205 Dart_EnterScope(); | 8302 Dart_EnterScope(); |
| 8206 { | 8303 { |
| 8207 DARTSCOPE(Thread::Current()); | 8304 Thread* T = Thread::Current(); |
| 8305 CHECK_API_SCOPE(T); |
| 8306 HANDLESCOPE(T); |
| 8208 Dart_Handle str = Api::NewHandle(T, String::New("str", Heap::kOld)); | 8307 Dart_Handle str = Api::NewHandle(T, String::New("str", Heap::kOld)); |
| 8209 EXPECT_VALID(str); | 8308 EXPECT_VALID(str); |
| 8210 EXPECT(Dart_IsString(str)); | 8309 EXPECT(Dart_IsString(str)); |
| 8211 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 8310 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
| 8212 void* out = &out; | 8311 void* out = &out; |
| 8213 EXPECT(Dart_GetPeer(str, &out)); | 8312 EXPECT(Dart_GetPeer(str, &out)); |
| 8214 EXPECT(out == NULL); | 8313 EXPECT(out == NULL); |
| 8215 int peer = 1234; | 8314 int peer = 1234; |
| 8216 EXPECT_VALID(Dart_SetPeer(str, &peer)); | 8315 EXPECT_VALID(Dart_SetPeer(str, &peer)); |
| 8217 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 8316 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
| 8218 out = &out; | 8317 out = &out; |
| 8219 EXPECT_VALID(Dart_GetPeer(str, &out)); | 8318 EXPECT_VALID(Dart_GetPeer(str, &out)); |
| 8220 EXPECT(out == reinterpret_cast<void*>(&peer)); | 8319 EXPECT(out == reinterpret_cast<void*>(&peer)); |
| 8221 isolate->heap()->CollectGarbage(Heap::kOld); | 8320 { |
| 8222 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 8321 TransitionNativeToVM transition(thread); |
| 8322 isolate->heap()->CollectGarbage(Heap::kOld); |
| 8323 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
| 8324 } |
| 8223 EXPECT_VALID(Dart_GetPeer(str, &out)); | 8325 EXPECT_VALID(Dart_GetPeer(str, &out)); |
| 8224 EXPECT(out == reinterpret_cast<void*>(&peer)); | 8326 EXPECT(out == reinterpret_cast<void*>(&peer)); |
| 8225 } | 8327 } |
| 8226 Dart_ExitScope(); | 8328 Dart_ExitScope(); |
| 8227 isolate->heap()->CollectGarbage(Heap::kOld); | 8329 { |
| 8228 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 8330 TransitionNativeToVM transition(thread); |
| 8331 isolate->heap()->CollectGarbage(Heap::kOld); |
| 8332 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
| 8333 } |
| 8229 } | 8334 } |
| 8230 | 8335 |
| 8231 | 8336 |
| 8232 // Allocates two objects in old space and assigns them peers. Removes | 8337 // Allocates two objects in old space and assigns them peers. Removes |
| 8233 // the peers and checks that the count of peer objects is decremented | 8338 // the peers and checks that the count of peer objects is decremented |
| 8234 // by two. | 8339 // by two. |
| 8235 TEST_CASE(TwoOldSpacePeers) { | 8340 TEST_CASE(TwoOldSpacePeers) { |
| 8236 Isolate* isolate = Isolate::Current(); | 8341 Isolate* isolate = Isolate::Current(); |
| 8237 Dart_Handle s1 = Api::NewHandle(thread, String::New("s1", Heap::kOld)); | 8342 Dart_Handle s1 = Api::NewHandle(thread, String::New("s1", Heap::kOld)); |
| 8238 EXPECT_VALID(s1); | 8343 EXPECT_VALID(s1); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8273 } | 8378 } |
| 8274 | 8379 |
| 8275 | 8380 |
| 8276 // Allocates two objects in old space and assigns them a peer. Allows | 8381 // Allocates two objects in old space and assigns them a peer. Allows |
| 8277 // the peer referents to be garbage collected and checks that the | 8382 // the peer referents to be garbage collected and checks that the |
| 8278 // count of peer objects is decremented by two. | 8383 // count of peer objects is decremented by two. |
| 8279 TEST_CASE(CollectTwoOldSpacePeers) { | 8384 TEST_CASE(CollectTwoOldSpacePeers) { |
| 8280 Isolate* isolate = Isolate::Current(); | 8385 Isolate* isolate = Isolate::Current(); |
| 8281 Dart_EnterScope(); | 8386 Dart_EnterScope(); |
| 8282 { | 8387 { |
| 8283 DARTSCOPE(Thread::Current()); | 8388 Thread* T = Thread::Current(); |
| 8389 CHECK_API_SCOPE(T); |
| 8390 HANDLESCOPE(T); |
| 8284 Dart_Handle s1 = Api::NewHandle(T, String::New("s1", Heap::kOld)); | 8391 Dart_Handle s1 = Api::NewHandle(T, String::New("s1", Heap::kOld)); |
| 8285 EXPECT_VALID(s1); | 8392 EXPECT_VALID(s1); |
| 8286 EXPECT(Dart_IsString(s1)); | 8393 EXPECT(Dart_IsString(s1)); |
| 8287 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 8394 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
| 8288 void* o1 = &o1; | 8395 void* o1 = &o1; |
| 8289 EXPECT(Dart_GetPeer(s1, &o1)); | 8396 EXPECT(Dart_GetPeer(s1, &o1)); |
| 8290 EXPECT(o1 == NULL); | 8397 EXPECT(o1 == NULL); |
| 8291 int p1 = 1234; | 8398 int p1 = 1234; |
| 8292 EXPECT_VALID(Dart_SetPeer(s1, &p1)); | 8399 EXPECT_VALID(Dart_SetPeer(s1, &p1)); |
| 8293 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 8400 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
| 8294 o1 = &o1; | 8401 o1 = &o1; |
| 8295 EXPECT_VALID(Dart_GetPeer(s1, &o1)); | 8402 EXPECT_VALID(Dart_GetPeer(s1, &o1)); |
| 8296 EXPECT(o1 == reinterpret_cast<void*>(&p1)); | 8403 EXPECT(o1 == reinterpret_cast<void*>(&p1)); |
| 8297 Dart_Handle s2 = Api::NewHandle(T, String::New("s2", Heap::kOld)); | 8404 Dart_Handle s2 = Api::NewHandle(T, String::New("s2", Heap::kOld)); |
| 8298 EXPECT_VALID(s2); | 8405 EXPECT_VALID(s2); |
| 8299 EXPECT(Dart_IsString(s2)); | 8406 EXPECT(Dart_IsString(s2)); |
| 8300 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 8407 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
| 8301 void* o2 = &o2; | 8408 void* o2 = &o2; |
| 8302 EXPECT(Dart_GetPeer(s2, &o2)); | 8409 EXPECT(Dart_GetPeer(s2, &o2)); |
| 8303 EXPECT(o2 == NULL); | 8410 EXPECT(o2 == NULL); |
| 8304 int p2 = 5678; | 8411 int p2 = 5678; |
| 8305 EXPECT_VALID(Dart_SetPeer(s2, &p2)); | 8412 EXPECT_VALID(Dart_SetPeer(s2, &p2)); |
| 8306 EXPECT_EQ(2, isolate->heap()->PeerCount()); | 8413 EXPECT_EQ(2, isolate->heap()->PeerCount()); |
| 8307 o2 = &o2; | 8414 o2 = &o2; |
| 8308 EXPECT_VALID(Dart_GetPeer(s2, &o2)); | 8415 EXPECT_VALID(Dart_GetPeer(s2, &o2)); |
| 8309 EXPECT(o2 == reinterpret_cast<void*>(&p2)); | 8416 EXPECT(o2 == reinterpret_cast<void*>(&p2)); |
| 8310 } | 8417 } |
| 8311 Dart_ExitScope(); | 8418 Dart_ExitScope(); |
| 8312 isolate->heap()->CollectGarbage(Heap::kOld); | 8419 { |
| 8313 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 8420 TransitionNativeToVM transition(thread); |
| 8421 isolate->heap()->CollectGarbage(Heap::kOld); |
| 8422 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
| 8423 } |
| 8314 } | 8424 } |
| 8315 | 8425 |
| 8316 | 8426 |
| 8317 // Test API call to make strings external. | 8427 // Test API call to make strings external. |
| 8318 static void MakeExternalCback(void* peer) { | 8428 static void MakeExternalCback(void* peer) { |
| 8319 *static_cast<int*>(peer) *= 2; | 8429 *static_cast<int*>(peer) *= 2; |
| 8320 } | 8430 } |
| 8321 | 8431 |
| 8322 | 8432 |
| 8323 TEST_CASE(MakeExternalString) { | 8433 TEST_CASE(MakeExternalString) { |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8510 EXPECT(Dart_IdentityEquals(str, symbol_str)); | 8620 EXPECT(Dart_IdentityEquals(str, symbol_str)); |
| 8511 for (intptr_t i = 0; i < length; i++) { | 8621 for (intptr_t i = 0; i < length; i++) { |
| 8512 EXPECT_EQ(symbol_ascii[i], ext_symbol_ascii[i]); | 8622 EXPECT_EQ(symbol_ascii[i], ext_symbol_ascii[i]); |
| 8513 } | 8623 } |
| 8514 | 8624 |
| 8515 Dart_ExitScope(); | 8625 Dart_ExitScope(); |
| 8516 } | 8626 } |
| 8517 EXPECT_EQ(40, peer8); | 8627 EXPECT_EQ(40, peer8); |
| 8518 EXPECT_EQ(41, peer16); | 8628 EXPECT_EQ(41, peer16); |
| 8519 EXPECT_EQ(42, canonical_str_peer); | 8629 EXPECT_EQ(42, canonical_str_peer); |
| 8520 Isolate::Current()->heap()->CollectAllGarbage(); | 8630 { |
| 8631 TransitionNativeToVM transition(thread); |
| 8632 Isolate::Current()->heap()->CollectAllGarbage(); |
| 8633 } |
| 8521 EXPECT_EQ(80, peer8); | 8634 EXPECT_EQ(80, peer8); |
| 8522 EXPECT_EQ(82, peer16); | 8635 EXPECT_EQ(82, peer16); |
| 8523 EXPECT_EQ(42, canonical_str_peer); // "*" Symbol is not removed on GC. | 8636 EXPECT_EQ(42, canonical_str_peer); // "*" Symbol is not removed on GC. |
| 8524 } | 8637 } |
| 8525 | 8638 |
| 8526 | 8639 |
| 8527 TEST_CASE(ExternalizeConstantStrings) { | 8640 TEST_CASE(ExternalizeConstantStrings) { |
| 8528 const char* kScriptChars = | 8641 const char* kScriptChars = |
| 8529 "String testMain() {\n" | 8642 "String testMain() {\n" |
| 8530 " return 'constant string';\n" | 8643 " return 'constant string';\n" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8622 &ExternalStringDeoptimize_Finalize); | 8735 &ExternalStringDeoptimize_Finalize); |
| 8623 EXPECT_VALID(result); | 8736 EXPECT_VALID(result); |
| 8624 EXPECT(Dart_IsExternalString(result)); | 8737 EXPECT(Dart_IsExternalString(result)); |
| 8625 Dart_ExitScope(); | 8738 Dart_ExitScope(); |
| 8626 } | 8739 } |
| 8627 | 8740 |
| 8628 | 8741 |
| 8629 static Dart_NativeFunction ExternalStringDeoptimize_native_lookup( | 8742 static Dart_NativeFunction ExternalStringDeoptimize_native_lookup( |
| 8630 Dart_Handle name, int argument_count, bool* auto_setup_scope) { | 8743 Dart_Handle name, int argument_count, bool* auto_setup_scope) { |
| 8631 ASSERT(auto_setup_scope != NULL); | 8744 ASSERT(auto_setup_scope != NULL); |
| 8632 *auto_setup_scope = false; | 8745 *auto_setup_scope = true; |
| 8633 return reinterpret_cast<Dart_NativeFunction>(&A_change_str_native); | 8746 return reinterpret_cast<Dart_NativeFunction>(&A_change_str_native); |
| 8634 } | 8747 } |
| 8635 | 8748 |
| 8636 | 8749 |
| 8637 // Do not use guarding mechanism on externalizable classes, since their class | 8750 // Do not use guarding mechanism on externalizable classes, since their class |
| 8638 // can change on the fly, | 8751 // can change on the fly, |
| 8639 TEST_CASE(GuardExternalizedString) { | 8752 TEST_CASE(GuardExternalizedString) { |
| 8640 const char* kScriptChars = | 8753 const char* kScriptChars = |
| 8641 "main() {\n" | 8754 "main() {\n" |
| 8642 " var a = new A('hello');\n" | 8755 " var a = new A('hello');\n" |
| (...skipping 943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9586 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); | 9699 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); |
| 9587 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); | 9700 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); |
| 9588 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); | 9701 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); |
| 9589 | 9702 |
| 9590 // Heartbeat test for new events. | 9703 // Heartbeat test for new events. |
| 9591 EXPECT_SUBSTRING("\"name\":\"TestVMDuration2\"", buffer); | 9704 EXPECT_SUBSTRING("\"name\":\"TestVMDuration2\"", buffer); |
| 9592 EXPECT_SUBSTRING("\"function\":\"::_bar\"", buffer); | 9705 EXPECT_SUBSTRING("\"function\":\"::_bar\"", buffer); |
| 9593 } | 9706 } |
| 9594 | 9707 |
| 9595 } // namespace dart | 9708 } // namespace dart |
| OLD | NEW |