| 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 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 EXPECT(!Dart_IdentityEquals(five, mint)); | 609 EXPECT(!Dart_IdentityEquals(five, mint)); |
| 610 EXPECT(!Dart_IdentityEquals(abc, xyz)); | 610 EXPECT(!Dart_IdentityEquals(abc, xyz)); |
| 611 | 611 |
| 612 // Case where identical() is not the same as pointer equality. | 612 // Case where identical() is not the same as pointer equality. |
| 613 Dart_Handle nan1 = Dart_NewDouble(NAN); | 613 Dart_Handle nan1 = Dart_NewDouble(NAN); |
| 614 Dart_Handle nan2 = Dart_NewDouble(NAN); | 614 Dart_Handle nan2 = Dart_NewDouble(NAN); |
| 615 EXPECT(Dart_IdentityEquals(nan1, nan2)); | 615 EXPECT(Dart_IdentityEquals(nan1, nan2)); |
| 616 | 616 |
| 617 // Non-instance objects. | 617 // Non-instance objects. |
| 618 { | 618 { |
| 619 Isolate* isolate = Isolate::Current(); | 619 DARTSCOPE(Thread::Current()); |
| 620 DARTSCOPE(isolate); | |
| 621 Dart_Handle lib1 = Dart_LookupLibrary(dart_core); | 620 Dart_Handle lib1 = Dart_LookupLibrary(dart_core); |
| 622 Dart_Handle lib2 = Dart_LookupLibrary(dart_mirrors); | 621 Dart_Handle lib2 = Dart_LookupLibrary(dart_mirrors); |
| 623 | 622 |
| 624 EXPECT(Dart_IdentityEquals(lib1, lib1)); | 623 EXPECT(Dart_IdentityEquals(lib1, lib1)); |
| 625 EXPECT(Dart_IdentityEquals(lib2, lib2)); | 624 EXPECT(Dart_IdentityEquals(lib2, lib2)); |
| 626 EXPECT(!Dart_IdentityEquals(lib1, lib2)); | 625 EXPECT(!Dart_IdentityEquals(lib1, lib2)); |
| 627 | 626 |
| 628 // Mix instance and non-instance. | 627 // Mix instance and non-instance. |
| 629 EXPECT(!Dart_IdentityEquals(lib1, nan1)); | 628 EXPECT(!Dart_IdentityEquals(lib1, nan1)); |
| 630 EXPECT(!Dart_IdentityEquals(nan1, lib1)); | 629 EXPECT(!Dart_IdentityEquals(nan1, lib1)); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 655 | 654 |
| 656 // 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. |
| 657 | 656 |
| 658 // Case where identical() is not the same as pointer equality. | 657 // Case where identical() is not the same as pointer equality. |
| 659 Dart_Handle nan1 = Dart_NewDouble(NAN); | 658 Dart_Handle nan1 = Dart_NewDouble(NAN); |
| 660 Dart_Handle nan2 = Dart_NewDouble(NAN); | 659 Dart_Handle nan2 = Dart_NewDouble(NAN); |
| 661 EXPECT_EQ(Dart_IdentityHash(nan1), Dart_IdentityHash(nan2)); | 660 EXPECT_EQ(Dart_IdentityHash(nan1), Dart_IdentityHash(nan2)); |
| 662 | 661 |
| 663 // Non-instance objects. | 662 // Non-instance objects. |
| 664 { | 663 { |
| 665 Isolate* isolate = Isolate::Current(); | 664 DARTSCOPE(Thread::Current()); |
| 666 DARTSCOPE(isolate); | |
| 667 Dart_Handle lib1 = Dart_LookupLibrary(dart_core); | 665 Dart_Handle lib1 = Dart_LookupLibrary(dart_core); |
| 668 Dart_Handle lib2 = Dart_LookupLibrary(dart_mirrors); | 666 Dart_Handle lib2 = Dart_LookupLibrary(dart_mirrors); |
| 669 | 667 |
| 670 EXPECT_EQ(Dart_IdentityHash(lib1), Dart_IdentityHash(lib1)); | 668 EXPECT_EQ(Dart_IdentityHash(lib1), Dart_IdentityHash(lib1)); |
| 671 EXPECT_EQ(Dart_IdentityHash(lib2), Dart_IdentityHash(lib2)); | 669 EXPECT_EQ(Dart_IdentityHash(lib2), Dart_IdentityHash(lib2)); |
| 672 } | 670 } |
| 673 } | 671 } |
| 674 | 672 |
| 675 | 673 |
| 676 TEST_CASE(ObjectEquals) { | 674 TEST_CASE(ObjectEquals) { |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1168 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 1166 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 1169 EXPECT_EQ(40, peer8); | 1167 EXPECT_EQ(40, peer8); |
| 1170 EXPECT_EQ(41, peer16); | 1168 EXPECT_EQ(41, peer16); |
| 1171 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); | 1169 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); |
| 1172 EXPECT_EQ(80, peer8); | 1170 EXPECT_EQ(80, peer8); |
| 1173 EXPECT_EQ(82, peer16); | 1171 EXPECT_EQ(82, peer16); |
| 1174 } | 1172 } |
| 1175 | 1173 |
| 1176 | 1174 |
| 1177 TEST_CASE(ExternalStringPretenure) { | 1175 TEST_CASE(ExternalStringPretenure) { |
| 1178 Isolate* isolate = Isolate::Current(); | |
| 1179 { | 1176 { |
| 1180 Dart_EnterScope(); | 1177 Dart_EnterScope(); |
| 1181 static const uint8_t big_data8[16*MB] = {0, }; | 1178 static const uint8_t big_data8[16*MB] = {0, }; |
| 1182 Dart_Handle big8 = Dart_NewExternalLatin1String( | 1179 Dart_Handle big8 = Dart_NewExternalLatin1String( |
| 1183 big_data8, | 1180 big_data8, |
| 1184 ARRAY_SIZE(big_data8), | 1181 ARRAY_SIZE(big_data8), |
| 1185 NULL, | 1182 NULL, |
| 1186 NULL); | 1183 NULL); |
| 1187 EXPECT_VALID(big8); | 1184 EXPECT_VALID(big8); |
| 1188 static const uint16_t big_data16[16*MB/2] = {0, }; | 1185 static const uint16_t big_data16[16*MB/2] = {0, }; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1199 NULL); | 1196 NULL); |
| 1200 EXPECT_VALID(small8); | 1197 EXPECT_VALID(small8); |
| 1201 static const uint16_t small_data16[] = {'b', 'a', 'r'}; | 1198 static const uint16_t small_data16[] = {'b', 'a', 'r'}; |
| 1202 Dart_Handle small16 = Dart_NewExternalUTF16String( | 1199 Dart_Handle small16 = Dart_NewExternalUTF16String( |
| 1203 small_data16, | 1200 small_data16, |
| 1204 ARRAY_SIZE(small_data16), | 1201 ARRAY_SIZE(small_data16), |
| 1205 NULL, | 1202 NULL, |
| 1206 NULL); | 1203 NULL); |
| 1207 EXPECT_VALID(small16); | 1204 EXPECT_VALID(small16); |
| 1208 { | 1205 { |
| 1209 DARTSCOPE(isolate); | 1206 DARTSCOPE(Thread::Current()); |
| 1210 String& handle = String::Handle(); | 1207 String& handle = String::Handle(); |
| 1211 handle ^= Api::UnwrapHandle(big8); | 1208 handle ^= Api::UnwrapHandle(big8); |
| 1212 EXPECT(handle.IsOld()); | 1209 EXPECT(handle.IsOld()); |
| 1213 handle ^= Api::UnwrapHandle(big16); | 1210 handle ^= Api::UnwrapHandle(big16); |
| 1214 EXPECT(handle.IsOld()); | 1211 EXPECT(handle.IsOld()); |
| 1215 handle ^= Api::UnwrapHandle(small8); | 1212 handle ^= Api::UnwrapHandle(small8); |
| 1216 EXPECT(handle.IsNew()); | 1213 EXPECT(handle.IsNew()); |
| 1217 handle ^= Api::UnwrapHandle(small16); | 1214 handle ^= Api::UnwrapHandle(small16); |
| 1218 EXPECT(handle.IsNew()); | 1215 EXPECT(handle.IsNew()); |
| 1219 } | 1216 } |
| 1220 Dart_ExitScope(); | 1217 Dart_ExitScope(); |
| 1221 } | 1218 } |
| 1222 } | 1219 } |
| 1223 | 1220 |
| 1224 | 1221 |
| 1225 TEST_CASE(ExternalTypedDataPretenure) { | 1222 TEST_CASE(ExternalTypedDataPretenure) { |
| 1226 Isolate* isolate = Isolate::Current(); | |
| 1227 { | 1223 { |
| 1228 Dart_EnterScope(); | 1224 Dart_EnterScope(); |
| 1229 static const int kBigLength = 16*MB/8; | 1225 static const int kBigLength = 16*MB/8; |
| 1230 int64_t* big_data = new int64_t[kBigLength](); | 1226 int64_t* big_data = new int64_t[kBigLength](); |
| 1231 Dart_Handle big = Dart_NewExternalTypedData( | 1227 Dart_Handle big = Dart_NewExternalTypedData( |
| 1232 Dart_TypedData_kInt64, | 1228 Dart_TypedData_kInt64, |
| 1233 big_data, | 1229 big_data, |
| 1234 kBigLength); | 1230 kBigLength); |
| 1235 EXPECT_VALID(big); | 1231 EXPECT_VALID(big); |
| 1236 static const int kSmallLength = 16*KB/8; | 1232 static const int kSmallLength = 16*KB/8; |
| 1237 int64_t* small_data = new int64_t[kSmallLength](); | 1233 int64_t* small_data = new int64_t[kSmallLength](); |
| 1238 Dart_Handle small = Dart_NewExternalTypedData( | 1234 Dart_Handle small = Dart_NewExternalTypedData( |
| 1239 Dart_TypedData_kInt64, | 1235 Dart_TypedData_kInt64, |
| 1240 small_data, | 1236 small_data, |
| 1241 kSmallLength); | 1237 kSmallLength); |
| 1242 EXPECT_VALID(small); | 1238 EXPECT_VALID(small); |
| 1243 { | 1239 { |
| 1244 DARTSCOPE(isolate); | 1240 DARTSCOPE(Thread::Current()); |
| 1245 ExternalTypedData& handle = ExternalTypedData::Handle(); | 1241 ExternalTypedData& handle = ExternalTypedData::Handle(); |
| 1246 handle ^= Api::UnwrapHandle(big); | 1242 handle ^= Api::UnwrapHandle(big); |
| 1247 EXPECT(handle.IsOld()); | 1243 EXPECT(handle.IsOld()); |
| 1248 handle ^= Api::UnwrapHandle(small); | 1244 handle ^= Api::UnwrapHandle(small); |
| 1249 EXPECT(handle.IsNew()); | 1245 EXPECT(handle.IsNew()); |
| 1250 } | 1246 } |
| 1251 Dart_ExitScope(); | 1247 Dart_ExitScope(); |
| 1252 delete[] big_data; | 1248 delete[] big_data; |
| 1253 delete[] small_data; | 1249 delete[] small_data; |
| 1254 } | 1250 } |
| (...skipping 1106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2361 TestIsolateScope __test_isolate__; | 2357 TestIsolateScope __test_isolate__; |
| 2362 | 2358 |
| 2363 Isolate* isolate = Isolate::Current(); | 2359 Isolate* isolate = Isolate::Current(); |
| 2364 EXPECT(isolate != NULL); | 2360 EXPECT(isolate != NULL); |
| 2365 ApiState* state = isolate->api_state(); | 2361 ApiState* state = isolate->api_state(); |
| 2366 EXPECT(state != NULL); | 2362 EXPECT(state != NULL); |
| 2367 ApiLocalScope* scope = state->top_scope(); | 2363 ApiLocalScope* scope = state->top_scope(); |
| 2368 Dart_EnterScope(); | 2364 Dart_EnterScope(); |
| 2369 { | 2365 { |
| 2370 EXPECT(state->top_scope() != NULL); | 2366 EXPECT(state->top_scope() != NULL); |
| 2371 DARTSCOPE(isolate); | 2367 DARTSCOPE(Thread::Current()); |
| 2372 const String& str1 = String::Handle(String::New("Test String")); | 2368 const String& str1 = String::Handle(String::New("Test String")); |
| 2373 Dart_Handle ref = Api::NewHandle(isolate, str1.raw()); | 2369 Dart_Handle ref = Api::NewHandle(isolate, str1.raw()); |
| 2374 String& str2 = String::Handle(); | 2370 String& str2 = String::Handle(); |
| 2375 str2 ^= Api::UnwrapHandle(ref); | 2371 str2 ^= Api::UnwrapHandle(ref); |
| 2376 EXPECT(str1.Equals(str2)); | 2372 EXPECT(str1.Equals(str2)); |
| 2377 } | 2373 } |
| 2378 Dart_ExitScope(); | 2374 Dart_ExitScope(); |
| 2379 EXPECT(scope == state->top_scope()); | 2375 EXPECT(scope == state->top_scope()); |
| 2380 } | 2376 } |
| 2381 | 2377 |
| 2382 | 2378 |
| 2383 // Unit test for creating and deleting persistent handles. | 2379 // Unit test for creating and deleting persistent handles. |
| 2384 UNIT_TEST_CASE(PersistentHandles) { | 2380 UNIT_TEST_CASE(PersistentHandles) { |
| 2385 const char* kTestString1 = "Test String1"; | 2381 const char* kTestString1 = "Test String1"; |
| 2386 const char* kTestString2 = "Test String2"; | 2382 const char* kTestString2 = "Test String2"; |
| 2387 TestCase::CreateTestIsolate(); | 2383 TestCase::CreateTestIsolate(); |
| 2388 Isolate* isolate = Isolate::Current(); | 2384 Isolate* isolate = Isolate::Current(); |
| 2389 EXPECT(isolate != NULL); | 2385 EXPECT(isolate != NULL); |
| 2390 ApiState* state = isolate->api_state(); | 2386 ApiState* state = isolate->api_state(); |
| 2391 EXPECT(state != NULL); | 2387 EXPECT(state != NULL); |
| 2392 ApiLocalScope* scope = state->top_scope(); | 2388 ApiLocalScope* scope = state->top_scope(); |
| 2393 Dart_PersistentHandle handles[2000]; | 2389 Dart_PersistentHandle handles[2000]; |
| 2394 Dart_EnterScope(); | 2390 Dart_EnterScope(); |
| 2395 { | 2391 { |
| 2396 DARTSCOPE(isolate); | 2392 DARTSCOPE(Thread::Current()); |
| 2397 Dart_Handle ref1 = Api::NewHandle(isolate, String::New(kTestString1)); | 2393 Dart_Handle ref1 = Api::NewHandle(isolate, String::New(kTestString1)); |
| 2398 for (int i = 0; i < 1000; i++) { | 2394 for (int i = 0; i < 1000; i++) { |
| 2399 handles[i] = Dart_NewPersistentHandle(ref1); | 2395 handles[i] = Dart_NewPersistentHandle(ref1); |
| 2400 } | 2396 } |
| 2401 Dart_EnterScope(); | 2397 Dart_EnterScope(); |
| 2402 Dart_Handle ref2 = Api::NewHandle(isolate, String::New(kTestString2)); | 2398 Dart_Handle ref2 = Api::NewHandle(isolate, String::New(kTestString2)); |
| 2403 for (int i = 1000; i < 2000; i++) { | 2399 for (int i = 1000; i < 2000; i++) { |
| 2404 handles[i] = Dart_NewPersistentHandle(ref2); | 2400 handles[i] = Dart_NewPersistentHandle(ref2); |
| 2405 } | 2401 } |
| 2406 for (int i = 500; i < 1500; i++) { | 2402 for (int i = 500; i < 1500; i++) { |
| 2407 Dart_DeletePersistentHandle(handles[i]); | 2403 Dart_DeletePersistentHandle(handles[i]); |
| 2408 } | 2404 } |
| 2409 for (int i = 500; i < 1000; i++) { | 2405 for (int i = 500; i < 1000; i++) { |
| 2410 handles[i] = Dart_NewPersistentHandle(ref2); | 2406 handles[i] = Dart_NewPersistentHandle(ref2); |
| 2411 } | 2407 } |
| 2412 for (int i = 1000; i < 1500; i++) { | 2408 for (int i = 1000; i < 1500; i++) { |
| 2413 handles[i] = Dart_NewPersistentHandle(ref1); | 2409 handles[i] = Dart_NewPersistentHandle(ref1); |
| 2414 } | 2410 } |
| 2415 VERIFY_ON_TRANSITION; | 2411 VERIFY_ON_TRANSITION; |
| 2416 Dart_ExitScope(); | 2412 Dart_ExitScope(); |
| 2417 } | 2413 } |
| 2418 Dart_ExitScope(); | 2414 Dart_ExitScope(); |
| 2419 { | 2415 { |
| 2420 StackZone zone(isolate); | 2416 StackZone zone(isolate); |
| 2421 HANDLESCOPE(isolate); | 2417 HANDLESCOPE(Thread::Current()); |
| 2422 for (int i = 0; i < 500; i++) { | 2418 for (int i = 0; i < 500; i++) { |
| 2423 String& str = String::Handle(); | 2419 String& str = String::Handle(); |
| 2424 str ^= PersistentHandle::Cast(handles[i])->raw(); | 2420 str ^= PersistentHandle::Cast(handles[i])->raw(); |
| 2425 EXPECT(str.Equals(kTestString1)); | 2421 EXPECT(str.Equals(kTestString1)); |
| 2426 } | 2422 } |
| 2427 for (int i = 500; i < 1000; i++) { | 2423 for (int i = 500; i < 1000; i++) { |
| 2428 String& str = String::Handle(); | 2424 String& str = String::Handle(); |
| 2429 str ^= PersistentHandle::Cast(handles[i])->raw(); | 2425 str ^= PersistentHandle::Cast(handles[i])->raw(); |
| 2430 EXPECT(str.Equals(kTestString2)); | 2426 EXPECT(str.Equals(kTestString2)); |
| 2431 } | 2427 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2448 | 2444 |
| 2449 // Test that we are able to create a persistent handle from a | 2445 // Test that we are able to create a persistent handle from a |
| 2450 // persistent handle. | 2446 // persistent handle. |
| 2451 UNIT_TEST_CASE(NewPersistentHandle_FromPersistentHandle) { | 2447 UNIT_TEST_CASE(NewPersistentHandle_FromPersistentHandle) { |
| 2452 TestIsolateScope __test_isolate__; | 2448 TestIsolateScope __test_isolate__; |
| 2453 | 2449 |
| 2454 Isolate* isolate = Isolate::Current(); | 2450 Isolate* isolate = Isolate::Current(); |
| 2455 EXPECT(isolate != NULL); | 2451 EXPECT(isolate != NULL); |
| 2456 ApiState* state = isolate->api_state(); | 2452 ApiState* state = isolate->api_state(); |
| 2457 EXPECT(state != NULL); | 2453 EXPECT(state != NULL); |
| 2458 DARTSCOPE(isolate); | 2454 DARTSCOPE(Thread::Current()); |
| 2459 | 2455 |
| 2460 // Start with a known persistent handle. | 2456 // Start with a known persistent handle. |
| 2461 Dart_PersistentHandle obj1 = Dart_NewPersistentHandle(Dart_True()); | 2457 Dart_PersistentHandle obj1 = Dart_NewPersistentHandle(Dart_True()); |
| 2462 EXPECT(state->IsValidPersistentHandle(obj1)); | 2458 EXPECT(state->IsValidPersistentHandle(obj1)); |
| 2463 | 2459 |
| 2464 // And use it to allocate a second persistent handle. | 2460 // And use it to allocate a second persistent handle. |
| 2465 Dart_Handle obj2 = Dart_HandleFromPersistent(obj1); | 2461 Dart_Handle obj2 = Dart_HandleFromPersistent(obj1); |
| 2466 Dart_PersistentHandle obj3 = Dart_NewPersistentHandle(obj2); | 2462 Dart_PersistentHandle obj3 = Dart_NewPersistentHandle(obj2); |
| 2467 EXPECT(state->IsValidPersistentHandle(obj3)); | 2463 EXPECT(state->IsValidPersistentHandle(obj3)); |
| 2468 | 2464 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2479 // Test that we can assign to a persistent handle. | 2475 // Test that we can assign to a persistent handle. |
| 2480 UNIT_TEST_CASE(AssignToPersistentHandle) { | 2476 UNIT_TEST_CASE(AssignToPersistentHandle) { |
| 2481 const char* kTestString1 = "Test String1"; | 2477 const char* kTestString1 = "Test String1"; |
| 2482 const char* kTestString2 = "Test String2"; | 2478 const char* kTestString2 = "Test String2"; |
| 2483 TestIsolateScope __test_isolate__; | 2479 TestIsolateScope __test_isolate__; |
| 2484 | 2480 |
| 2485 Isolate* isolate = Isolate::Current(); | 2481 Isolate* isolate = Isolate::Current(); |
| 2486 EXPECT(isolate != NULL); | 2482 EXPECT(isolate != NULL); |
| 2487 ApiState* state = isolate->api_state(); | 2483 ApiState* state = isolate->api_state(); |
| 2488 EXPECT(state != NULL); | 2484 EXPECT(state != NULL); |
| 2489 DARTSCOPE(isolate); | 2485 DARTSCOPE(Thread::Current()); |
| 2490 String& str = String::Handle(); | 2486 String& str = String::Handle(); |
| 2491 | 2487 |
| 2492 // Start with a known persistent handle. | 2488 // Start with a known persistent handle. |
| 2493 Dart_Handle ref1 = Api::NewHandle(isolate, String::New(kTestString1)); | 2489 Dart_Handle ref1 = Api::NewHandle(isolate, String::New(kTestString1)); |
| 2494 Dart_PersistentHandle obj = Dart_NewPersistentHandle(ref1); | 2490 Dart_PersistentHandle obj = Dart_NewPersistentHandle(ref1); |
| 2495 EXPECT(state->IsValidPersistentHandle(obj)); | 2491 EXPECT(state->IsValidPersistentHandle(obj)); |
| 2496 str ^= PersistentHandle::Cast(obj)->raw(); | 2492 str ^= PersistentHandle::Cast(obj)->raw(); |
| 2497 EXPECT(str.Equals(kTestString1)); | 2493 EXPECT(str.Equals(kTestString1)); |
| 2498 | 2494 |
| 2499 // Now create another local handle and assign it to the persistent handle. | 2495 // Now create another local handle and assign it to the persistent handle. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2559 Dart_EnterScope(); | 2555 Dart_EnterScope(); |
| 2560 | 2556 |
| 2561 // Create an object in new space. | 2557 // Create an object in new space. |
| 2562 Dart_Handle new_ref = NewString("new string"); | 2558 Dart_Handle new_ref = NewString("new string"); |
| 2563 EXPECT_VALID(new_ref); | 2559 EXPECT_VALID(new_ref); |
| 2564 | 2560 |
| 2565 // Create an object in old space. | 2561 // Create an object in old space. |
| 2566 Dart_Handle old_ref; | 2562 Dart_Handle old_ref; |
| 2567 { | 2563 { |
| 2568 Isolate* isolate = Isolate::Current(); | 2564 Isolate* isolate = Isolate::Current(); |
| 2569 DARTSCOPE(isolate); | 2565 DARTSCOPE(Thread::Current()); |
| 2570 old_ref = Api::NewHandle(isolate, String::New("old string", Heap::kOld)); | 2566 old_ref = Api::NewHandle(isolate, String::New("old string", Heap::kOld)); |
| 2571 EXPECT_VALID(old_ref); | 2567 EXPECT_VALID(old_ref); |
| 2572 } | 2568 } |
| 2573 | 2569 |
| 2574 // Create a weak ref to the new space object. | 2570 // Create a weak ref to the new space object. |
| 2575 weak_new_ref = Dart_NewWeakPersistentHandle(new_ref, | 2571 weak_new_ref = Dart_NewWeakPersistentHandle(new_ref, |
| 2576 NULL, | 2572 NULL, |
| 2577 0, | 2573 0, |
| 2578 WeakPersistentHandleCallback); | 2574 WeakPersistentHandleCallback); |
| 2579 EXPECT_VALID(AsHandle(weak_new_ref)); | 2575 EXPECT_VALID(AsHandle(weak_new_ref)); |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2814 // ... but the object is still alive and not yet promoted, so external size | 2810 // ... but the object is still alive and not yet promoted, so external size |
| 2815 // in new space is still above the limit. Thus, even the following tiny | 2811 // in new space is still above the limit. Thus, even the following tiny |
| 2816 // external allocation will trigger another scavenge. | 2812 // external allocation will trigger another scavenge. |
| 2817 Dart_WeakPersistentHandle trigger = | 2813 Dart_WeakPersistentHandle trigger = |
| 2818 Dart_NewWeakPersistentHandle(obj, NULL, 1, NopCallback); | 2814 Dart_NewWeakPersistentHandle(obj, NULL, 1, NopCallback); |
| 2819 EXPECT_VALID(AsHandle(trigger)); | 2815 EXPECT_VALID(AsHandle(trigger)); |
| 2820 Dart_DeleteWeakPersistentHandle(isolate, trigger); | 2816 Dart_DeleteWeakPersistentHandle(isolate, trigger); |
| 2821 // After the two scavenges above, 'obj' should now be promoted, hence its | 2817 // After the two scavenges above, 'obj' should now be promoted, hence its |
| 2822 // external size charged to old space. | 2818 // external size charged to old space. |
| 2823 { | 2819 { |
| 2824 DARTSCOPE(Isolate::Current()); | 2820 DARTSCOPE(thread); |
| 2825 String& handle = String::Handle(); | 2821 String& handle = String::Handle(thread->zone()); |
| 2826 handle ^= Api::UnwrapHandle(obj); | 2822 handle ^= Api::UnwrapHandle(obj); |
| 2827 EXPECT(handle.IsOld()); | 2823 EXPECT(handle.IsOld()); |
| 2828 } | 2824 } |
| 2829 EXPECT(heap->ExternalInWords(Heap::kNew) == 0); | 2825 EXPECT(heap->ExternalInWords(Heap::kNew) == 0); |
| 2830 EXPECT(heap->ExternalInWords(Heap::kOld) == kWeak1ExternalSize / kWordSize); | 2826 EXPECT(heap->ExternalInWords(Heap::kOld) == kWeak1ExternalSize / kWordSize); |
| 2831 Dart_ExitScope(); | 2827 Dart_ExitScope(); |
| 2832 } | 2828 } |
| 2833 Dart_DeleteWeakPersistentHandle(isolate, weak1); | 2829 Dart_DeleteWeakPersistentHandle(isolate, weak1); |
| 2834 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2830 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 2835 EXPECT(heap->ExternalInWords(Heap::kOld) == 0); | 2831 EXPECT(heap->ExternalInWords(Heap::kOld) == 0); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2925 } | 2921 } |
| 2926 | 2922 |
| 2927 | 2923 |
| 2928 TEST_CASE(ObjectGroups) { | 2924 TEST_CASE(ObjectGroups) { |
| 2929 Dart_PersistentHandle strong = NULL; | 2925 Dart_PersistentHandle strong = NULL; |
| 2930 Dart_WeakPersistentHandle strong_weak = NULL; | 2926 Dart_WeakPersistentHandle strong_weak = NULL; |
| 2931 | 2927 |
| 2932 Dart_EnterScope(); | 2928 Dart_EnterScope(); |
| 2933 { | 2929 { |
| 2934 Isolate* isolate = Isolate::Current(); | 2930 Isolate* isolate = Isolate::Current(); |
| 2935 DARTSCOPE(isolate); | 2931 DARTSCOPE(Thread::Current()); |
| 2936 | 2932 |
| 2937 Dart_Handle local = Api::NewHandle( | 2933 Dart_Handle local = Api::NewHandle( |
| 2938 isolate, String::New("strongly reachable", Heap::kOld)); | 2934 isolate, String::New("strongly reachable", Heap::kOld)); |
| 2939 strong = Dart_NewPersistentHandle(local); | 2935 strong = Dart_NewPersistentHandle(local); |
| 2940 strong_weak = Dart_NewWeakPersistentHandle(local, NULL, 0, NopCallback); | 2936 strong_weak = Dart_NewWeakPersistentHandle(local, NULL, 0, NopCallback); |
| 2941 EXPECT_VALID(AsHandle(strong)); | 2937 EXPECT_VALID(AsHandle(strong)); |
| 2942 EXPECT(!Dart_IsNull(AsHandle(strong))); | 2938 EXPECT(!Dart_IsNull(AsHandle(strong))); |
| 2943 | 2939 |
| 2944 weak1 = Dart_NewWeakPersistentHandle( | 2940 weak1 = Dart_NewWeakPersistentHandle( |
| 2945 Api::NewHandle(isolate, String::New("weakly reachable 1", Heap::kOld)), | 2941 Api::NewHandle(isolate, String::New("weakly reachable 1", Heap::kOld)), |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3167 } | 3163 } |
| 3168 | 3164 |
| 3169 | 3165 |
| 3170 TEST_CASE(DuplicateWeakReferenceSetEntries) { | 3166 TEST_CASE(DuplicateWeakReferenceSetEntries) { |
| 3171 Isolate* isolate = Isolate::Current(); | 3167 Isolate* isolate = Isolate::Current(); |
| 3172 Dart_PersistentHandle strong = NULL; | 3168 Dart_PersistentHandle strong = NULL; |
| 3173 Dart_WeakPersistentHandle weak = NULL; // A weak handle to strong. | 3169 Dart_WeakPersistentHandle weak = NULL; // A weak handle to strong. |
| 3174 | 3170 |
| 3175 Dart_EnterScope(); | 3171 Dart_EnterScope(); |
| 3176 { | 3172 { |
| 3177 DARTSCOPE(isolate); | 3173 DARTSCOPE(Thread::Current()); |
| 3178 | 3174 |
| 3179 // Strong handle to keep the reference set alive. | 3175 // Strong handle to keep the reference set alive. |
| 3180 Dart_Handle local = Api::NewHandle(isolate, String::New("string")); | 3176 Dart_Handle local = Api::NewHandle(isolate, String::New("string")); |
| 3181 strong = Dart_NewPersistentHandle(local); | 3177 strong = Dart_NewPersistentHandle(local); |
| 3182 EXPECT_VALID(AsHandle(strong)); | 3178 EXPECT_VALID(AsHandle(strong)); |
| 3183 EXPECT(!Dart_IsNull(AsHandle(strong))); | 3179 EXPECT(!Dart_IsNull(AsHandle(strong))); |
| 3184 // Corresponding weak handle to use as key and duplicated value. | 3180 // Corresponding weak handle to use as key and duplicated value. |
| 3185 weak = Dart_NewWeakPersistentHandle(local, NULL, 0, NopCallback); | 3181 weak = Dart_NewWeakPersistentHandle(local, NULL, 0, NopCallback); |
| 3186 EXPECT_VALID(AsHandle(weak)); | 3182 EXPECT_VALID(AsHandle(weak)); |
| 3187 EXPECT(!Dart_IsNull(AsHandle(weak))); | 3183 EXPECT(!Dart_IsNull(AsHandle(weak))); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3220 } else if (handle == new_pwph) { | 3216 } else if (handle == new_pwph) { |
| 3221 new_pwph = NULL; | 3217 new_pwph = NULL; |
| 3222 } | 3218 } |
| 3223 } | 3219 } |
| 3224 | 3220 |
| 3225 | 3221 |
| 3226 TEST_CASE(PrologueWeakPersistentHandles) { | 3222 TEST_CASE(PrologueWeakPersistentHandles) { |
| 3227 Dart_EnterScope(); | 3223 Dart_EnterScope(); |
| 3228 { | 3224 { |
| 3229 Isolate* isolate = Isolate::Current(); | 3225 Isolate* isolate = Isolate::Current(); |
| 3230 DARTSCOPE(isolate); | 3226 DARTSCOPE(Thread::Current()); |
| 3231 new_pwph = Dart_NewPrologueWeakPersistentHandle( | 3227 new_pwph = Dart_NewPrologueWeakPersistentHandle( |
| 3232 Api::NewHandle(isolate, | 3228 Api::NewHandle(isolate, |
| 3233 String::New("new space prologue weak", Heap::kNew)), | 3229 String::New("new space prologue weak", Heap::kNew)), |
| 3234 NULL, 0, PrologueWeakHandleCallback); | 3230 NULL, 0, PrologueWeakHandleCallback); |
| 3235 EXPECT_VALID(AsHandle(new_pwph)); | 3231 EXPECT_VALID(AsHandle(new_pwph)); |
| 3236 EXPECT(!Dart_IsNull(AsHandle(new_pwph))); | 3232 EXPECT(!Dart_IsNull(AsHandle(new_pwph))); |
| 3237 old_pwph = Dart_NewPrologueWeakPersistentHandle( | 3233 old_pwph = Dart_NewPrologueWeakPersistentHandle( |
| 3238 Api::NewHandle(isolate, | 3234 Api::NewHandle(isolate, |
| 3239 String::New("old space prologue weak", Heap::kOld)), | 3235 String::New("old space prologue weak", Heap::kOld)), |
| 3240 NULL, 0, PrologueWeakHandleCallback); | 3236 NULL, 0, PrologueWeakHandleCallback); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3318 } | 3314 } |
| 3319 | 3315 |
| 3320 | 3316 |
| 3321 TEST_CASE(ImplicitReferencesOldSpace) { | 3317 TEST_CASE(ImplicitReferencesOldSpace) { |
| 3322 Dart_PersistentHandle strong = NULL; | 3318 Dart_PersistentHandle strong = NULL; |
| 3323 Dart_WeakPersistentHandle strong_weak = NULL; | 3319 Dart_WeakPersistentHandle strong_weak = NULL; |
| 3324 | 3320 |
| 3325 Dart_EnterScope(); | 3321 Dart_EnterScope(); |
| 3326 { | 3322 { |
| 3327 Isolate* isolate = Isolate::Current(); | 3323 Isolate* isolate = Isolate::Current(); |
| 3328 DARTSCOPE(isolate); | 3324 DARTSCOPE(Thread::Current()); |
| 3329 | 3325 |
| 3330 Dart_Handle local = Api::NewHandle( | 3326 Dart_Handle local = Api::NewHandle( |
| 3331 isolate, String::New("strongly reachable", Heap::kOld)); | 3327 isolate, String::New("strongly reachable", Heap::kOld)); |
| 3332 strong = Dart_NewPersistentHandle(local); | 3328 strong = Dart_NewPersistentHandle(local); |
| 3333 strong_weak = Dart_NewWeakPersistentHandle(local, NULL, 0, NopCallback); | 3329 strong_weak = Dart_NewWeakPersistentHandle(local, NULL, 0, NopCallback); |
| 3334 | 3330 |
| 3335 EXPECT(!Dart_IsNull(AsHandle(strong))); | 3331 EXPECT(!Dart_IsNull(AsHandle(strong))); |
| 3336 EXPECT_VALID(AsHandle(strong)); | 3332 EXPECT_VALID(AsHandle(strong)); |
| 3337 EXPECT(!Dart_IsNull(AsHandle(strong_weak))); | 3333 EXPECT(!Dart_IsNull(AsHandle(strong_weak))); |
| 3338 EXPECT_VALID(AsHandle(strong_weak)); | 3334 EXPECT_VALID(AsHandle(strong_weak)); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3429 | 3425 |
| 3430 | 3426 |
| 3431 TEST_CASE(ImplicitReferencesNewSpace) { | 3427 TEST_CASE(ImplicitReferencesNewSpace) { |
| 3432 Dart_PersistentHandle strong = NULL; | 3428 Dart_PersistentHandle strong = NULL; |
| 3433 Dart_WeakPersistentHandle strong_weak = NULL; | 3429 Dart_WeakPersistentHandle strong_weak = NULL; |
| 3434 | 3430 |
| 3435 | 3431 |
| 3436 Dart_EnterScope(); | 3432 Dart_EnterScope(); |
| 3437 { | 3433 { |
| 3438 Isolate* isolate = Isolate::Current(); | 3434 Isolate* isolate = Isolate::Current(); |
| 3439 DARTSCOPE(isolate); | 3435 DARTSCOPE(Thread::Current()); |
| 3440 | 3436 |
| 3441 Dart_Handle local = Api::NewHandle( | 3437 Dart_Handle local = Api::NewHandle( |
| 3442 isolate, String::New("strongly reachable", Heap::kOld)); | 3438 isolate, String::New("strongly reachable", Heap::kOld)); |
| 3443 strong = Dart_NewPersistentHandle(local); | 3439 strong = Dart_NewPersistentHandle(local); |
| 3444 strong_weak = Dart_NewWeakPersistentHandle(local, NULL, 0, NopCallback); | 3440 strong_weak = Dart_NewWeakPersistentHandle(local, NULL, 0, NopCallback); |
| 3445 | 3441 |
| 3446 EXPECT(!Dart_IsNull(AsHandle(strong))); | 3442 EXPECT(!Dart_IsNull(AsHandle(strong))); |
| 3447 EXPECT_VALID(AsHandle(strong)); | 3443 EXPECT_VALID(AsHandle(strong)); |
| 3448 EXPECT(!Dart_IsNull(AsHandle(strong_weak))); | 3444 EXPECT(!Dart_IsNull(AsHandle(strong_weak))); |
| 3449 EXPECT_VALID(AsHandle(strong_weak)); | 3445 EXPECT_VALID(AsHandle(strong_weak)); |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3693 UNIT_TEST_CASE(LocalHandles) { | 3689 UNIT_TEST_CASE(LocalHandles) { |
| 3694 TestCase::CreateTestIsolate(); | 3690 TestCase::CreateTestIsolate(); |
| 3695 Isolate* isolate = Isolate::Current(); | 3691 Isolate* isolate = Isolate::Current(); |
| 3696 EXPECT(isolate != NULL); | 3692 EXPECT(isolate != NULL); |
| 3697 ApiState* state = isolate->api_state(); | 3693 ApiState* state = isolate->api_state(); |
| 3698 EXPECT(state != NULL); | 3694 EXPECT(state != NULL); |
| 3699 ApiLocalScope* scope = state->top_scope(); | 3695 ApiLocalScope* scope = state->top_scope(); |
| 3700 Dart_Handle handles[300]; | 3696 Dart_Handle handles[300]; |
| 3701 { | 3697 { |
| 3702 StackZone zone(isolate); | 3698 StackZone zone(isolate); |
| 3703 HANDLESCOPE(isolate); | 3699 HANDLESCOPE(Thread::Current()); |
| 3704 Smi& val = Smi::Handle(); | 3700 Smi& val = Smi::Handle(); |
| 3705 | 3701 |
| 3706 // Start a new scope and allocate some local handles. | 3702 // Start a new scope and allocate some local handles. |
| 3707 Dart_EnterScope(); | 3703 Dart_EnterScope(); |
| 3708 for (int i = 0; i < 100; i++) { | 3704 for (int i = 0; i < 100; i++) { |
| 3709 handles[i] = Api::NewHandle(isolate, Smi::New(i)); | 3705 handles[i] = Api::NewHandle(isolate, Smi::New(i)); |
| 3710 } | 3706 } |
| 3711 EXPECT_EQ(100, state->CountLocalHandles()); | 3707 EXPECT_EQ(100, state->CountLocalHandles()); |
| 3712 for (int i = 0; i < 100; i++) { | 3708 for (int i = 0; i < 100; i++) { |
| 3713 val ^= Api::UnwrapHandle(handles[i]); | 3709 val ^= Api::UnwrapHandle(handles[i]); |
| (...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4464 kNumNativeFields); | 4460 kNumNativeFields); |
| 4465 EXPECT_VALID(result); | 4461 EXPECT_VALID(result); |
| 4466 result = Dart_FinalizeLoading(false); | 4462 result = Dart_FinalizeLoading(false); |
| 4467 EXPECT_VALID(result); | 4463 EXPECT_VALID(result); |
| 4468 | 4464 |
| 4469 // Load up a test script in the test library. | 4465 // Load up a test script in the test library. |
| 4470 | 4466 |
| 4471 // Invoke a function which returns an object of type NativeFields. | 4467 // Invoke a function which returns an object of type NativeFields. |
| 4472 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 4468 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
| 4473 EXPECT_VALID(result); | 4469 EXPECT_VALID(result); |
| 4474 DARTSCOPE(Isolate::Current()); | 4470 DARTSCOPE(Thread::Current()); |
| 4475 Instance& obj = Instance::Handle(); | 4471 Instance& obj = Instance::Handle(); |
| 4476 obj ^= Api::UnwrapHandle(result); | 4472 obj ^= Api::UnwrapHandle(result); |
| 4477 const Class& cls = Class::Handle(obj.clazz()); | 4473 const Class& cls = Class::Handle(obj.clazz()); |
| 4478 // We expect the newly created "NativeFields" object to have | 4474 // We expect the newly created "NativeFields" object to have |
| 4479 // 2 dart instance fields (fld1, fld2) and a reference to the native fields. | 4475 // 2 dart instance fields (fld1, fld2) and a reference to the native fields. |
| 4480 // Hence the size of an instance of "NativeFields" should be | 4476 // Hence the size of an instance of "NativeFields" should be |
| 4481 // (1 + 2) * kWordSize + size of object header. | 4477 // (1 + 2) * kWordSize + size of object header. |
| 4482 // We check to make sure the instance size computed by the VM matches | 4478 // We check to make sure the instance size computed by the VM matches |
| 4483 // our expectations. | 4479 // our expectations. |
| 4484 intptr_t header_size = sizeof(RawObject); | 4480 intptr_t header_size = sizeof(RawObject); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4534 Dart_Handle result; | 4530 Dart_Handle result; |
| 4535 const int kNumNativeFields = 2; | 4531 const int kNumNativeFields = 2; |
| 4536 | 4532 |
| 4537 // Load up a test script in the test library. | 4533 // Load up a test script in the test library. |
| 4538 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, | 4534 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, |
| 4539 native_field_lookup); | 4535 native_field_lookup); |
| 4540 | 4536 |
| 4541 // Invoke a function which returns an object of type NativeFields. | 4537 // Invoke a function which returns an object of type NativeFields. |
| 4542 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 4538 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
| 4543 EXPECT_VALID(result); | 4539 EXPECT_VALID(result); |
| 4544 DARTSCOPE(Isolate::Current()); | 4540 DARTSCOPE(Thread::Current()); |
| 4545 Instance& obj = Instance::Handle(); | 4541 Instance& obj = Instance::Handle(); |
| 4546 obj ^= Api::UnwrapHandle(result); | 4542 obj ^= Api::UnwrapHandle(result); |
| 4547 const Class& cls = Class::Handle(obj.clazz()); | 4543 const Class& cls = Class::Handle(obj.clazz()); |
| 4548 // We expect the newly created "NativeFields" object to have | 4544 // We expect the newly created "NativeFields" object to have |
| 4549 // 2 dart instance fields (fld1, fld2) and a reference to the native fields. | 4545 // 2 dart instance fields (fld1, fld2) and a reference to the native fields. |
| 4550 // Hence the size of an instance of "NativeFields" should be | 4546 // Hence the size of an instance of "NativeFields" should be |
| 4551 // (1 + 2) * kWordSize + size of object header. | 4547 // (1 + 2) * kWordSize + size of object header. |
| 4552 // We check to make sure the instance size computed by the VM matches | 4548 // We check to make sure the instance size computed by the VM matches |
| 4553 // our expectations. | 4549 // our expectations. |
| 4554 intptr_t header_size = sizeof(RawObject); | 4550 intptr_t header_size = sizeof(RawObject); |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4878 " static const int fld4 = 10;\n" | 4874 " static const int fld4 = 10;\n" |
| 4879 "}\n" | 4875 "}\n" |
| 4880 "NativeFields testMain1() {\n" | 4876 "NativeFields testMain1() {\n" |
| 4881 " NativeFields obj = new NativeFields(10, 20);\n" | 4877 " NativeFields obj = new NativeFields(10, 20);\n" |
| 4882 " return obj;\n" | 4878 " return obj;\n" |
| 4883 "}\n" | 4879 "}\n" |
| 4884 "Function testMain2() {\n" | 4880 "Function testMain2() {\n" |
| 4885 " return () {};\n" | 4881 " return () {};\n" |
| 4886 "}\n"; | 4882 "}\n"; |
| 4887 Dart_Handle result; | 4883 Dart_Handle result; |
| 4888 DARTSCOPE(Isolate::Current()); | 4884 DARTSCOPE(Thread::Current()); |
| 4889 | 4885 |
| 4890 // Create a test library and Load up a test script in it. | 4886 // Create a test library and Load up a test script in it. |
| 4891 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 4887 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 4892 | 4888 |
| 4893 // Invoke a function which returns an object of type NativeFields. | 4889 // Invoke a function which returns an object of type NativeFields. |
| 4894 Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain1"), 0, NULL); | 4890 Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain1"), 0, NULL); |
| 4895 EXPECT_VALID(retobj); | 4891 EXPECT_VALID(retobj); |
| 4896 | 4892 |
| 4897 // Now access and set various native instance fields of the returned object. | 4893 // Now access and set various native instance fields of the returned object. |
| 4898 // All of these tests are expected to return failure as there are no | 4894 // 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... |
| 4956 " var port = new RawReceivePort();\n" | 4952 " var port = new RawReceivePort();\n" |
| 4957 " var obj = new Test(1,2);\n" | 4953 " var obj = new Test(1,2);\n" |
| 4958 " var msg = [obj, port.sendPort];\n" | 4954 " var msg = [obj, port.sendPort];\n" |
| 4959 " var snd = Isolate.spawn(echo, msg);\n" | 4955 " var snd = Isolate.spawn(echo, msg);\n" |
| 4960 " port.handler = (msg) {\n" | 4956 " port.handler = (msg) {\n" |
| 4961 " port.close();\n" | 4957 " port.close();\n" |
| 4962 " print('from worker ${msg}');\n" | 4958 " print('from worker ${msg}');\n" |
| 4963 " };\n" | 4959 " };\n" |
| 4964 "}\n"; | 4960 "}\n"; |
| 4965 | 4961 |
| 4966 DARTSCOPE(Isolate::Current()); | 4962 DARTSCOPE(Thread::Current()); |
| 4967 | 4963 |
| 4968 // Create a test library and Load up a test script in it. | 4964 // Create a test library and Load up a test script in it. |
| 4969 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 4965 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 4970 | 4966 |
| 4971 // Invoke 'main' which should spawn an isolate and try to send an | 4967 // Invoke 'main' which should spawn an isolate and try to send an |
| 4972 // object with native fields over to the spawned isolate. This | 4968 // object with native fields over to the spawned isolate. This |
| 4973 // should result in an unhandled exception which is checked. | 4969 // should result in an unhandled exception which is checked. |
| 4974 Dart_Handle retobj = Dart_Invoke(lib, NewString("main"), 0, NULL); | 4970 Dart_Handle retobj = Dart_Invoke(lib, NewString("main"), 0, NULL); |
| 4975 EXPECT(Dart_IsError(retobj)); | 4971 EXPECT(Dart_IsError(retobj)); |
| 4976 } | 4972 } |
| (...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5657 " static const int fld4 = 10;\n" | 5653 " static const int fld4 = 10;\n" |
| 5658 "}\n" | 5654 "}\n" |
| 5659 "Function testMain1() {\n" | 5655 "Function testMain1() {\n" |
| 5660 " InvokeClosure obj = new InvokeClosure(10, 20);\n" | 5656 " InvokeClosure obj = new InvokeClosure(10, 20);\n" |
| 5661 " return obj.method1(10);\n" | 5657 " return obj.method1(10);\n" |
| 5662 "}\n" | 5658 "}\n" |
| 5663 "Function testMain2() {\n" | 5659 "Function testMain2() {\n" |
| 5664 " return InvokeClosure.method2(10);\n" | 5660 " return InvokeClosure.method2(10);\n" |
| 5665 "}\n"; | 5661 "}\n"; |
| 5666 Dart_Handle result; | 5662 Dart_Handle result; |
| 5667 DARTSCOPE(Isolate::Current()); | 5663 DARTSCOPE(Thread::Current()); |
| 5668 | 5664 |
| 5669 // Create a test library and Load up a test script in it. | 5665 // Create a test library and Load up a test script in it. |
| 5670 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 5666 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 5671 | 5667 |
| 5672 // Invoke a function which returns a closure. | 5668 // Invoke a function which returns a closure. |
| 5673 Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain1"), 0, NULL); | 5669 Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain1"), 0, NULL); |
| 5674 EXPECT_VALID(retobj); | 5670 EXPECT_VALID(retobj); |
| 5675 | 5671 |
| 5676 EXPECT(Dart_IsClosure(retobj)); | 5672 EXPECT(Dart_IsClosure(retobj)); |
| 5677 EXPECT(!Dart_IsClosure(Dart_NewInteger(101))); | 5673 EXPECT(!Dart_IsClosure(Dart_NewInteger(101))); |
| (...skipping 2572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8250 } | 8246 } |
| 8251 | 8247 |
| 8252 | 8248 |
| 8253 // Allocates an object in new space and assigns it a peer. Allows the | 8249 // Allocates an object in new space and assigns it a peer. Allows the |
| 8254 // peer referent to be garbage collected and checks that the count of | 8250 // peer referent to be garbage collected and checks that the count of |
| 8255 // peer objects is decremented by one. | 8251 // peer objects is decremented by one. |
| 8256 TEST_CASE(CollectOneNewSpacePeer) { | 8252 TEST_CASE(CollectOneNewSpacePeer) { |
| 8257 Isolate* isolate = Isolate::Current(); | 8253 Isolate* isolate = Isolate::Current(); |
| 8258 Dart_EnterScope(); | 8254 Dart_EnterScope(); |
| 8259 { | 8255 { |
| 8260 DARTSCOPE(isolate); | 8256 DARTSCOPE(Thread::Current()); |
| 8261 Dart_Handle str = NewString("a string"); | 8257 Dart_Handle str = NewString("a string"); |
| 8262 EXPECT_VALID(str); | 8258 EXPECT_VALID(str); |
| 8263 EXPECT(Dart_IsString(str)); | 8259 EXPECT(Dart_IsString(str)); |
| 8264 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 8260 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
| 8265 void* out = &out; | 8261 void* out = &out; |
| 8266 EXPECT_VALID(Dart_GetPeer(str, &out)); | 8262 EXPECT_VALID(Dart_GetPeer(str, &out)); |
| 8267 EXPECT(out == NULL); | 8263 EXPECT(out == NULL); |
| 8268 int peer = 1234; | 8264 int peer = 1234; |
| 8269 EXPECT_VALID(Dart_SetPeer(str, &peer)); | 8265 EXPECT_VALID(Dart_SetPeer(str, &peer)); |
| 8270 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 8266 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8323 } | 8319 } |
| 8324 | 8320 |
| 8325 | 8321 |
| 8326 // Allocates two objects in new space and assigns them a peer. Allow | 8322 // Allocates two objects in new space and assigns them a peer. Allow |
| 8327 // the peer referents to be garbage collected and check that the count | 8323 // the peer referents to be garbage collected and check that the count |
| 8328 // of peer objects is decremented by two. | 8324 // of peer objects is decremented by two. |
| 8329 TEST_CASE(CollectTwoNewSpacePeers) { | 8325 TEST_CASE(CollectTwoNewSpacePeers) { |
| 8330 Isolate* isolate = Isolate::Current(); | 8326 Isolate* isolate = Isolate::Current(); |
| 8331 Dart_EnterScope(); | 8327 Dart_EnterScope(); |
| 8332 { | 8328 { |
| 8333 DARTSCOPE(isolate); | 8329 DARTSCOPE(Thread::Current()); |
| 8334 Dart_Handle s1 = NewString("s1"); | 8330 Dart_Handle s1 = NewString("s1"); |
| 8335 EXPECT_VALID(s1); | 8331 EXPECT_VALID(s1); |
| 8336 EXPECT(Dart_IsString(s1)); | 8332 EXPECT(Dart_IsString(s1)); |
| 8337 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 8333 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
| 8338 void* o1 = &o1; | 8334 void* o1 = &o1; |
| 8339 EXPECT(Dart_GetPeer(s1, &o1)); | 8335 EXPECT(Dart_GetPeer(s1, &o1)); |
| 8340 EXPECT(o1 == NULL); | 8336 EXPECT(o1 == NULL); |
| 8341 int p1 = 1234; | 8337 int p1 = 1234; |
| 8342 EXPECT_VALID(Dart_SetPeer(s1, &p1)); | 8338 EXPECT_VALID(Dart_SetPeer(s1, &p1)); |
| 8343 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 8339 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8407 EXPECT(out == NULL); | 8403 EXPECT(out == NULL); |
| 8408 int peer = 1234; | 8404 int peer = 1234; |
| 8409 EXPECT_VALID(Dart_SetPeer(str, &peer)); | 8405 EXPECT_VALID(Dart_SetPeer(str, &peer)); |
| 8410 out = &out; | 8406 out = &out; |
| 8411 EXPECT(Dart_GetPeer(str, &out)); | 8407 EXPECT(Dart_GetPeer(str, &out)); |
| 8412 EXPECT(out == reinterpret_cast<void*>(&peer)); | 8408 EXPECT(out == reinterpret_cast<void*>(&peer)); |
| 8413 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 8409 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
| 8414 isolate->heap()->CollectGarbage(Heap::kNew); | 8410 isolate->heap()->CollectGarbage(Heap::kNew); |
| 8415 isolate->heap()->CollectGarbage(Heap::kNew); | 8411 isolate->heap()->CollectGarbage(Heap::kNew); |
| 8416 { | 8412 { |
| 8417 DARTSCOPE(isolate); | 8413 DARTSCOPE(Thread::Current()); |
| 8418 String& handle = String::Handle(); | 8414 String& handle = String::Handle(); |
| 8419 handle ^= Api::UnwrapHandle(str); | 8415 handle ^= Api::UnwrapHandle(str); |
| 8420 EXPECT(handle.IsOld()); | 8416 EXPECT(handle.IsOld()); |
| 8421 } | 8417 } |
| 8422 EXPECT_VALID(Dart_GetPeer(str, &out)); | 8418 EXPECT_VALID(Dart_GetPeer(str, &out)); |
| 8423 EXPECT(out == reinterpret_cast<void*>(&peer)); | 8419 EXPECT(out == reinterpret_cast<void*>(&peer)); |
| 8424 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 8420 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
| 8425 EXPECT_VALID(Dart_SetPeer(str, NULL)); | 8421 EXPECT_VALID(Dart_SetPeer(str, NULL)); |
| 8426 out = &out; | 8422 out = &out; |
| 8427 EXPECT_VALID(Dart_GetPeer(str, &out)); | 8423 EXPECT_VALID(Dart_GetPeer(str, &out)); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8460 } | 8456 } |
| 8461 | 8457 |
| 8462 | 8458 |
| 8463 // Allocates an object in old space and assigns it a peer. Allow the | 8459 // Allocates an object in old space and assigns it a peer. Allow the |
| 8464 // peer referent to be garbage collected and check that the count of | 8460 // peer referent to be garbage collected and check that the count of |
| 8465 // peer objects is decremented by one. | 8461 // peer objects is decremented by one. |
| 8466 TEST_CASE(CollectOneOldSpacePeer) { | 8462 TEST_CASE(CollectOneOldSpacePeer) { |
| 8467 Isolate* isolate = Isolate::Current(); | 8463 Isolate* isolate = Isolate::Current(); |
| 8468 Dart_EnterScope(); | 8464 Dart_EnterScope(); |
| 8469 { | 8465 { |
| 8470 DARTSCOPE(isolate); | 8466 DARTSCOPE(Thread::Current()); |
| 8471 Dart_Handle str = Api::NewHandle(isolate, String::New("str", Heap::kOld)); | 8467 Dart_Handle str = Api::NewHandle(isolate, String::New("str", Heap::kOld)); |
| 8472 EXPECT_VALID(str); | 8468 EXPECT_VALID(str); |
| 8473 EXPECT(Dart_IsString(str)); | 8469 EXPECT(Dart_IsString(str)); |
| 8474 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 8470 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
| 8475 void* out = &out; | 8471 void* out = &out; |
| 8476 EXPECT(Dart_GetPeer(str, &out)); | 8472 EXPECT(Dart_GetPeer(str, &out)); |
| 8477 EXPECT(out == NULL); | 8473 EXPECT(out == NULL); |
| 8478 int peer = 1234; | 8474 int peer = 1234; |
| 8479 EXPECT_VALID(Dart_SetPeer(str, &peer)); | 8475 EXPECT_VALID(Dart_SetPeer(str, &peer)); |
| 8480 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 8476 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8536 } | 8532 } |
| 8537 | 8533 |
| 8538 | 8534 |
| 8539 // Allocates two objects in old space and assigns them a peer. Allows | 8535 // Allocates two objects in old space and assigns them a peer. Allows |
| 8540 // the peer referents to be garbage collected and checks that the | 8536 // the peer referents to be garbage collected and checks that the |
| 8541 // count of peer objects is decremented by two. | 8537 // count of peer objects is decremented by two. |
| 8542 TEST_CASE(CollectTwoOldSpacePeers) { | 8538 TEST_CASE(CollectTwoOldSpacePeers) { |
| 8543 Isolate* isolate = Isolate::Current(); | 8539 Isolate* isolate = Isolate::Current(); |
| 8544 Dart_EnterScope(); | 8540 Dart_EnterScope(); |
| 8545 { | 8541 { |
| 8546 DARTSCOPE(isolate); | 8542 DARTSCOPE(Thread::Current()); |
| 8547 Dart_Handle s1 = Api::NewHandle(isolate, String::New("s1", Heap::kOld)); | 8543 Dart_Handle s1 = Api::NewHandle(isolate, String::New("s1", Heap::kOld)); |
| 8548 EXPECT_VALID(s1); | 8544 EXPECT_VALID(s1); |
| 8549 EXPECT(Dart_IsString(s1)); | 8545 EXPECT(Dart_IsString(s1)); |
| 8550 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 8546 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
| 8551 void* o1 = &o1; | 8547 void* o1 = &o1; |
| 8552 EXPECT(Dart_GetPeer(s1, &o1)); | 8548 EXPECT(Dart_GetPeer(s1, &o1)); |
| 8553 EXPECT(o1 == NULL); | 8549 EXPECT(o1 == NULL); |
| 8554 int p1 = 1234; | 8550 int p1 = 1234; |
| 8555 EXPECT_VALID(Dart_SetPeer(s1, &p1)); | 8551 EXPECT_VALID(Dart_SetPeer(s1, &p1)); |
| 8556 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 8552 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
| (...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9415 // Heartbeat test. | 9411 // Heartbeat test. |
| 9416 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); | 9412 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); |
| 9417 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); | 9413 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); |
| 9418 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); | 9414 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); |
| 9419 | 9415 |
| 9420 // Free buffer allocated by AppendStreamConsumer | 9416 // Free buffer allocated by AppendStreamConsumer |
| 9421 free(data.buffer); | 9417 free(data.buffer); |
| 9422 } | 9418 } |
| 9423 | 9419 |
| 9424 } // namespace dart | 9420 } // namespace dart |
| OLD | NEW |