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

Side by Side Diff: runtime/vm/dart_api_impl_test.cc

Issue 177733002: Revert r32930 (Add more timing information in the VM to track time...) (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/dart_entry.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 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_debugger_api.h" 7 #include "include/dart_debugger_api.h"
8 #include "include/dart_mirrors_api.h" 8 #include "include/dart_mirrors_api.h"
9 #include "include/dart_native_api.h" 9 #include "include/dart_native_api.h"
10 #include "platform/assert.h" 10 #include "platform/assert.h"
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 // Different objects. 536 // Different objects.
537 EXPECT(!Dart_IdentityEquals(five, seven)); 537 EXPECT(!Dart_IdentityEquals(five, seven));
538 538
539 // Case where identical() is not the same as pointer equality. 539 // Case where identical() is not the same as pointer equality.
540 Dart_Handle nan1 = Dart_NewDouble(NAN); 540 Dart_Handle nan1 = Dart_NewDouble(NAN);
541 Dart_Handle nan2 = Dart_NewDouble(NAN); 541 Dart_Handle nan2 = Dart_NewDouble(NAN);
542 EXPECT(Dart_IdentityEquals(nan1, nan2)); 542 EXPECT(Dart_IdentityEquals(nan1, nan2));
543 543
544 // Non-instance objects. 544 // Non-instance objects.
545 { 545 {
546 Isolate* isolate = Isolate::Current();
547 DARTSCOPE(isolate);
546 Dart_Handle lib1 = Dart_LookupLibrary(dart_core); 548 Dart_Handle lib1 = Dart_LookupLibrary(dart_core);
547 Dart_Handle lib2 = Dart_LookupLibrary(dart_mirrors); 549 Dart_Handle lib2 = Dart_LookupLibrary(dart_mirrors);
548 550
549 EXPECT(Dart_IdentityEquals(lib1, lib1)); 551 EXPECT(Dart_IdentityEquals(lib1, lib1));
550 EXPECT(Dart_IdentityEquals(lib2, lib2)); 552 EXPECT(Dart_IdentityEquals(lib2, lib2));
551 EXPECT(!Dart_IdentityEquals(lib1, lib2)); 553 EXPECT(!Dart_IdentityEquals(lib1, lib2));
552 554
553 // Mix instance and non-instance. 555 // Mix instance and non-instance.
554 EXPECT(!Dart_IdentityEquals(lib1, nan1)); 556 EXPECT(!Dart_IdentityEquals(lib1, nan1));
555 EXPECT(!Dart_IdentityEquals(nan1, lib1)); 557 EXPECT(!Dart_IdentityEquals(nan1, lib1));
(...skipping 1224 matching lines...) Expand 10 before | Expand all | Expand 10 after
1780 TestIsolateScope __test_isolate__; 1782 TestIsolateScope __test_isolate__;
1781 1783
1782 Isolate* isolate = Isolate::Current(); 1784 Isolate* isolate = Isolate::Current();
1783 EXPECT(isolate != NULL); 1785 EXPECT(isolate != NULL);
1784 ApiState* state = isolate->api_state(); 1786 ApiState* state = isolate->api_state();
1785 EXPECT(state != NULL); 1787 EXPECT(state != NULL);
1786 ApiLocalScope* scope = state->top_scope(); 1788 ApiLocalScope* scope = state->top_scope();
1787 Dart_EnterScope(); 1789 Dart_EnterScope();
1788 { 1790 {
1789 EXPECT(state->top_scope() != NULL); 1791 EXPECT(state->top_scope() != NULL);
1790 HANDLESCOPE(isolate); 1792 DARTSCOPE(isolate);
1791 const String& str1 = String::Handle(String::New("Test String")); 1793 const String& str1 = String::Handle(String::New("Test String"));
1792 Dart_Handle ref = Api::NewHandle(isolate, str1.raw()); 1794 Dart_Handle ref = Api::NewHandle(isolate, str1.raw());
1793 String& str2 = String::Handle(); 1795 String& str2 = String::Handle();
1794 str2 ^= Api::UnwrapHandle(ref); 1796 str2 ^= Api::UnwrapHandle(ref);
1795 EXPECT(str1.Equals(str2)); 1797 EXPECT(str1.Equals(str2));
1796 } 1798 }
1797 Dart_ExitScope(); 1799 Dart_ExitScope();
1798 EXPECT(scope == state->top_scope()); 1800 EXPECT(scope == state->top_scope());
1799 } 1801 }
1800 1802
1801 1803
1802 // Unit test for creating and deleting persistent handles. 1804 // Unit test for creating and deleting persistent handles.
1803 UNIT_TEST_CASE(PersistentHandles) { 1805 UNIT_TEST_CASE(PersistentHandles) {
1804 const char* kTestString1 = "Test String1"; 1806 const char* kTestString1 = "Test String1";
1805 const char* kTestString2 = "Test String2"; 1807 const char* kTestString2 = "Test String2";
1806 TestCase::CreateTestIsolate(); 1808 TestCase::CreateTestIsolate();
1807 Isolate* isolate = Isolate::Current(); 1809 Isolate* isolate = Isolate::Current();
1808 EXPECT(isolate != NULL); 1810 EXPECT(isolate != NULL);
1809 ApiState* state = isolate->api_state(); 1811 ApiState* state = isolate->api_state();
1810 EXPECT(state != NULL); 1812 EXPECT(state != NULL);
1811 ApiLocalScope* scope = state->top_scope(); 1813 ApiLocalScope* scope = state->top_scope();
1812 Dart_PersistentHandle handles[2000]; 1814 Dart_PersistentHandle handles[2000];
1813 Dart_EnterScope(); 1815 Dart_EnterScope();
1814 { 1816 {
1815 HANDLESCOPE(isolate); 1817 DARTSCOPE(isolate);
1816 Dart_Handle ref1 = Api::NewHandle(isolate, String::New(kTestString1)); 1818 Dart_Handle ref1 = Api::NewHandle(isolate, String::New(kTestString1));
1817 for (int i = 0; i < 1000; i++) { 1819 for (int i = 0; i < 1000; i++) {
1818 handles[i] = Dart_NewPersistentHandle(ref1); 1820 handles[i] = Dart_NewPersistentHandle(ref1);
1819 } 1821 }
1820 Dart_EnterScope(); 1822 Dart_EnterScope();
1821 Dart_Handle ref2 = Api::NewHandle(isolate, String::New(kTestString2)); 1823 Dart_Handle ref2 = Api::NewHandle(isolate, String::New(kTestString2));
1822 for (int i = 1000; i < 2000; i++) { 1824 for (int i = 1000; i < 2000; i++) {
1823 handles[i] = Dart_NewPersistentHandle(ref2); 1825 handles[i] = Dart_NewPersistentHandle(ref2);
1824 } 1826 }
1825 for (int i = 500; i < 1500; i++) { 1827 for (int i = 500; i < 1500; i++) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1867 1869
1868 // Test that we are able to create a persistent handle from a 1870 // Test that we are able to create a persistent handle from a
1869 // persistent handle. 1871 // persistent handle.
1870 UNIT_TEST_CASE(NewPersistentHandle_FromPersistentHandle) { 1872 UNIT_TEST_CASE(NewPersistentHandle_FromPersistentHandle) {
1871 TestIsolateScope __test_isolate__; 1873 TestIsolateScope __test_isolate__;
1872 1874
1873 Isolate* isolate = Isolate::Current(); 1875 Isolate* isolate = Isolate::Current();
1874 EXPECT(isolate != NULL); 1876 EXPECT(isolate != NULL);
1875 ApiState* state = isolate->api_state(); 1877 ApiState* state = isolate->api_state();
1876 EXPECT(state != NULL); 1878 EXPECT(state != NULL);
1879 DARTSCOPE(isolate);
1877 1880
1878 // Start with a known persistent handle. 1881 // Start with a known persistent handle.
1879 Dart_PersistentHandle obj1 = Dart_NewPersistentHandle(Dart_True()); 1882 Dart_PersistentHandle obj1 = Dart_NewPersistentHandle(Dart_True());
1880 EXPECT(state->IsValidPersistentHandle(obj1)); 1883 EXPECT(state->IsValidPersistentHandle(obj1));
1881 1884
1882 // And use it to allocate a second persistent handle. 1885 // And use it to allocate a second persistent handle.
1883 Dart_Handle obj2 = Dart_HandleFromPersistent(obj1); 1886 Dart_Handle obj2 = Dart_HandleFromPersistent(obj1);
1884 Dart_PersistentHandle obj3 = Dart_NewPersistentHandle(obj2); 1887 Dart_PersistentHandle obj3 = Dart_NewPersistentHandle(obj2);
1885 EXPECT(state->IsValidPersistentHandle(obj3)); 1888 EXPECT(state->IsValidPersistentHandle(obj3));
1886 1889
(...skipping 10 matching lines...) Expand all
1897 // Test that we can assign to a persistent handle. 1900 // Test that we can assign to a persistent handle.
1898 UNIT_TEST_CASE(AssignToPersistentHandle) { 1901 UNIT_TEST_CASE(AssignToPersistentHandle) {
1899 const char* kTestString1 = "Test String1"; 1902 const char* kTestString1 = "Test String1";
1900 const char* kTestString2 = "Test String2"; 1903 const char* kTestString2 = "Test String2";
1901 TestIsolateScope __test_isolate__; 1904 TestIsolateScope __test_isolate__;
1902 1905
1903 Isolate* isolate = Isolate::Current(); 1906 Isolate* isolate = Isolate::Current();
1904 EXPECT(isolate != NULL); 1907 EXPECT(isolate != NULL);
1905 ApiState* state = isolate->api_state(); 1908 ApiState* state = isolate->api_state();
1906 EXPECT(state != NULL); 1909 EXPECT(state != NULL);
1907 HANDLESCOPE(isolate); 1910 DARTSCOPE(isolate);
1908 String& str = String::Handle(); 1911 String& str = String::Handle();
1909 1912
1910 // Start with a known persistent handle. 1913 // Start with a known persistent handle.
1911 Dart_Handle ref1 = Api::NewHandle(isolate, String::New(kTestString1)); 1914 Dart_Handle ref1 = Api::NewHandle(isolate, String::New(kTestString1));
1912 Dart_PersistentHandle obj = Dart_NewPersistentHandle(ref1); 1915 Dart_PersistentHandle obj = Dart_NewPersistentHandle(ref1);
1913 EXPECT(state->IsValidPersistentHandle(obj)); 1916 EXPECT(state->IsValidPersistentHandle(obj));
1914 str ^= Api::UnwrapAsPersistentHandle(obj)->raw(); 1917 str ^= Api::UnwrapAsPersistentHandle(obj)->raw();
1915 EXPECT(str.Equals(kTestString1)); 1918 EXPECT(str.Equals(kTestString1));
1916 1919
1917 // Now create another local handle and assign it to the persistent handle. 1920 // Now create another local handle and assign it to the persistent handle.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1962 Dart_EnterScope(); 1965 Dart_EnterScope();
1963 1966
1964 // Create an object in new space. 1967 // Create an object in new space.
1965 Dart_Handle new_ref = NewString("new string"); 1968 Dart_Handle new_ref = NewString("new string");
1966 EXPECT_VALID(new_ref); 1969 EXPECT_VALID(new_ref);
1967 1970
1968 // Create an object in old space. 1971 // Create an object in old space.
1969 Dart_Handle old_ref; 1972 Dart_Handle old_ref;
1970 { 1973 {
1971 Isolate* isolate = Isolate::Current(); 1974 Isolate* isolate = Isolate::Current();
1972 HANDLESCOPE(isolate); 1975 DARTSCOPE(isolate);
1973 old_ref = Api::NewHandle(isolate, String::New("old string", Heap::kOld)); 1976 old_ref = Api::NewHandle(isolate, String::New("old string", Heap::kOld));
1974 EXPECT_VALID(old_ref); 1977 EXPECT_VALID(old_ref);
1975 } 1978 }
1976 1979
1977 // Create a weak ref to the new space object. 1980 // Create a weak ref to the new space object.
1978 weak_new_ref = Dart_NewWeakPersistentHandle(new_ref, NULL, NULL); 1981 weak_new_ref = Dart_NewWeakPersistentHandle(new_ref, NULL, NULL);
1979 EXPECT_VALID(AsHandle(weak_new_ref)); 1982 EXPECT_VALID(AsHandle(weak_new_ref));
1980 EXPECT(!Dart_IsNull(AsHandle(weak_new_ref))); 1983 EXPECT(!Dart_IsNull(AsHandle(weak_new_ref)));
1981 1984
1982 // Create a weak ref to the old space object. 1985 // Create a weak ref to the old space object.
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
2124 Dart_WeakPersistentHandle strong_weak = NULL; 2127 Dart_WeakPersistentHandle strong_weak = NULL;
2125 2128
2126 Dart_WeakPersistentHandle weak1 = NULL; 2129 Dart_WeakPersistentHandle weak1 = NULL;
2127 Dart_WeakPersistentHandle weak2 = NULL; 2130 Dart_WeakPersistentHandle weak2 = NULL;
2128 Dart_WeakPersistentHandle weak3 = NULL; 2131 Dart_WeakPersistentHandle weak3 = NULL;
2129 Dart_WeakPersistentHandle weak4 = NULL; 2132 Dart_WeakPersistentHandle weak4 = NULL;
2130 2133
2131 Dart_EnterScope(); 2134 Dart_EnterScope();
2132 { 2135 {
2133 Isolate* isolate = Isolate::Current(); 2136 Isolate* isolate = Isolate::Current();
2137 DARTSCOPE(isolate);
2138
2134 Dart_Handle local = Api::NewHandle( 2139 Dart_Handle local = Api::NewHandle(
2135 isolate, String::New("strongly reachable", Heap::kOld)); 2140 isolate, String::New("strongly reachable", Heap::kOld));
2136 strong = Dart_NewPersistentHandle(local); 2141 strong = Dart_NewPersistentHandle(local);
2137 strong_weak = Dart_NewWeakPersistentHandle(local, NULL, NULL); 2142 strong_weak = Dart_NewWeakPersistentHandle(local, NULL, NULL);
2138 EXPECT_VALID(AsHandle(strong)); 2143 EXPECT_VALID(AsHandle(strong));
2139 EXPECT(!Dart_IsNull(AsHandle(strong))); 2144 EXPECT(!Dart_IsNull(AsHandle(strong)));
2140 2145
2141 weak1 = Dart_NewWeakPersistentHandle( 2146 weak1 = Dart_NewWeakPersistentHandle(
2142 Api::NewHandle(isolate, String::New("weakly reachable 1", Heap::kOld)), 2147 Api::NewHandle(isolate, String::New("weakly reachable 1", Heap::kOld)),
2143 NULL, NULL); 2148 NULL, NULL);
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
2340 } 2345 }
2341 2346
2342 2347
2343 TEST_CASE(PrologueWeakPersistentHandles) { 2348 TEST_CASE(PrologueWeakPersistentHandles) {
2344 Dart_WeakPersistentHandle old_pwph = NULL; 2349 Dart_WeakPersistentHandle old_pwph = NULL;
2345 Dart_WeakPersistentHandle new_pwph = NULL; 2350 Dart_WeakPersistentHandle new_pwph = NULL;
2346 2351
2347 Dart_EnterScope(); 2352 Dart_EnterScope();
2348 { 2353 {
2349 Isolate* isolate = Isolate::Current(); 2354 Isolate* isolate = Isolate::Current();
2355 DARTSCOPE(isolate);
2350 new_pwph = Dart_NewPrologueWeakPersistentHandle( 2356 new_pwph = Dart_NewPrologueWeakPersistentHandle(
2351 Api::NewHandle(isolate, 2357 Api::NewHandle(isolate,
2352 String::New("new space prologue weak", Heap::kNew)), 2358 String::New("new space prologue weak", Heap::kNew)),
2353 NULL, NULL); 2359 NULL, NULL);
2354 EXPECT_VALID(AsHandle(new_pwph)); 2360 EXPECT_VALID(AsHandle(new_pwph));
2355 EXPECT(!Dart_IsNull(AsHandle(new_pwph))); 2361 EXPECT(!Dart_IsNull(AsHandle(new_pwph)));
2356 old_pwph = Dart_NewPrologueWeakPersistentHandle( 2362 old_pwph = Dart_NewPrologueWeakPersistentHandle(
2357 Api::NewHandle(isolate, 2363 Api::NewHandle(isolate,
2358 String::New("old space prologue weak", Heap::kOld)), 2364 String::New("old space prologue weak", Heap::kOld)),
2359 NULL, NULL); 2365 NULL, NULL);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
2426 Dart_PersistentHandle strong = NULL; 2432 Dart_PersistentHandle strong = NULL;
2427 Dart_WeakPersistentHandle strong_weak = NULL; 2433 Dart_WeakPersistentHandle strong_weak = NULL;
2428 2434
2429 Dart_WeakPersistentHandle weak1 = NULL; 2435 Dart_WeakPersistentHandle weak1 = NULL;
2430 Dart_WeakPersistentHandle weak2 = NULL; 2436 Dart_WeakPersistentHandle weak2 = NULL;
2431 Dart_WeakPersistentHandle weak3 = NULL; 2437 Dart_WeakPersistentHandle weak3 = NULL;
2432 2438
2433 Dart_EnterScope(); 2439 Dart_EnterScope();
2434 { 2440 {
2435 Isolate* isolate = Isolate::Current(); 2441 Isolate* isolate = Isolate::Current();
2442 DARTSCOPE(isolate);
2443
2436 Dart_Handle local = Api::NewHandle( 2444 Dart_Handle local = Api::NewHandle(
2437 isolate, String::New("strongly reachable", Heap::kOld)); 2445 isolate, String::New("strongly reachable", Heap::kOld));
2438 strong = Dart_NewPersistentHandle(local); 2446 strong = Dart_NewPersistentHandle(local);
2439 strong_weak = Dart_NewWeakPersistentHandle(local, NULL, NULL); 2447 strong_weak = Dart_NewWeakPersistentHandle(local, NULL, NULL);
2440 2448
2441 EXPECT(!Dart_IsNull(AsHandle(strong))); 2449 EXPECT(!Dart_IsNull(AsHandle(strong)));
2442 EXPECT_VALID(AsHandle(strong)); 2450 EXPECT_VALID(AsHandle(strong));
2443 EXPECT(!Dart_IsNull(AsHandle(strong_weak))); 2451 EXPECT(!Dart_IsNull(AsHandle(strong_weak)));
2444 EXPECT_VALID(AsHandle(strong_weak)); 2452 EXPECT_VALID(AsHandle(strong_weak));
2445 EXPECT(Dart_IdentityEquals(AsHandle(strong), AsHandle(strong_weak))) 2453 EXPECT(Dart_IdentityEquals(AsHandle(strong), AsHandle(strong_weak)))
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
2530 Dart_PersistentHandle strong = NULL; 2538 Dart_PersistentHandle strong = NULL;
2531 Dart_WeakPersistentHandle strong_weak = NULL; 2539 Dart_WeakPersistentHandle strong_weak = NULL;
2532 2540
2533 Dart_WeakPersistentHandle weak1 = NULL; 2541 Dart_WeakPersistentHandle weak1 = NULL;
2534 Dart_WeakPersistentHandle weak2 = NULL; 2542 Dart_WeakPersistentHandle weak2 = NULL;
2535 Dart_WeakPersistentHandle weak3 = NULL; 2543 Dart_WeakPersistentHandle weak3 = NULL;
2536 2544
2537 Dart_EnterScope(); 2545 Dart_EnterScope();
2538 { 2546 {
2539 Isolate* isolate = Isolate::Current(); 2547 Isolate* isolate = Isolate::Current();
2548 DARTSCOPE(isolate);
2549
2540 Dart_Handle local = Api::NewHandle( 2550 Dart_Handle local = Api::NewHandle(
2541 isolate, String::New("strongly reachable", Heap::kOld)); 2551 isolate, String::New("strongly reachable", Heap::kOld));
2542 strong = Dart_NewPersistentHandle(local); 2552 strong = Dart_NewPersistentHandle(local);
2543 strong_weak = Dart_NewWeakPersistentHandle(local, NULL, NULL); 2553 strong_weak = Dart_NewWeakPersistentHandle(local, NULL, NULL);
2544 2554
2545 EXPECT(!Dart_IsNull(AsHandle(strong))); 2555 EXPECT(!Dart_IsNull(AsHandle(strong)));
2546 EXPECT_VALID(AsHandle(strong)); 2556 EXPECT_VALID(AsHandle(strong));
2547 EXPECT(!Dart_IsNull(AsHandle(strong_weak))); 2557 EXPECT(!Dart_IsNull(AsHandle(strong_weak)));
2548 EXPECT_VALID(AsHandle(strong_weak)); 2558 EXPECT_VALID(AsHandle(strong_weak));
2549 EXPECT(Dart_IdentityEquals(AsHandle(strong), AsHandle(strong_weak))) 2559 EXPECT(Dart_IdentityEquals(AsHandle(strong), AsHandle(strong_weak)))
(...skipping 1095 matching lines...) Expand 10 before | Expand all | Expand 10 after
3645 result = Dart_CreateNativeWrapperClass( 3655 result = Dart_CreateNativeWrapperClass(
3646 lib, 3656 lib,
3647 NewString("NativeFieldsWrapper"), 3657 NewString("NativeFieldsWrapper"),
3648 kNumNativeFields); 3658 kNumNativeFields);
3649 3659
3650 // Load up a test script in the test library. 3660 // Load up a test script in the test library.
3651 3661
3652 // Invoke a function which returns an object of type NativeFields. 3662 // Invoke a function which returns an object of type NativeFields.
3653 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); 3663 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL);
3654 EXPECT_VALID(result); 3664 EXPECT_VALID(result);
3655 HANDLESCOPE(Isolate::Current()); 3665 DARTSCOPE(Isolate::Current());
3656 Instance& obj = Instance::Handle(); 3666 Instance& obj = Instance::Handle();
3657 obj ^= Api::UnwrapHandle(result); 3667 obj ^= Api::UnwrapHandle(result);
3658 const Class& cls = Class::Handle(obj.clazz()); 3668 const Class& cls = Class::Handle(obj.clazz());
3659 // We expect the newly created "NativeFields" object to have 3669 // We expect the newly created "NativeFields" object to have
3660 // 2 dart instance fields (fld1, fld2) and a reference to the native fields. 3670 // 2 dart instance fields (fld1, fld2) and a reference to the native fields.
3661 // Hence the size of an instance of "NativeFields" should be 3671 // Hence the size of an instance of "NativeFields" should be
3662 // (1 + 2) * kWordSize + size of object header. 3672 // (1 + 2) * kWordSize + size of object header.
3663 // We check to make sure the instance size computed by the VM matches 3673 // We check to make sure the instance size computed by the VM matches
3664 // our expectations. 3674 // our expectations.
3665 intptr_t header_size = sizeof(RawObject); 3675 intptr_t header_size = sizeof(RawObject);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
3714 Dart_Handle result; 3724 Dart_Handle result;
3715 const int kNumNativeFields = 2; 3725 const int kNumNativeFields = 2;
3716 3726
3717 // Load up a test script in the test library. 3727 // Load up a test script in the test library.
3718 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, 3728 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars,
3719 native_field_lookup); 3729 native_field_lookup);
3720 3730
3721 // Invoke a function which returns an object of type NativeFields. 3731 // Invoke a function which returns an object of type NativeFields.
3722 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); 3732 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL);
3723 EXPECT_VALID(result); 3733 EXPECT_VALID(result);
3724 HANDLESCOPE(Isolate::Current()); 3734 DARTSCOPE(Isolate::Current());
3725 Instance& obj = Instance::Handle(); 3735 Instance& obj = Instance::Handle();
3726 obj ^= Api::UnwrapHandle(result); 3736 obj ^= Api::UnwrapHandle(result);
3727 const Class& cls = Class::Handle(obj.clazz()); 3737 const Class& cls = Class::Handle(obj.clazz());
3728 // We expect the newly created "NativeFields" object to have 3738 // We expect the newly created "NativeFields" object to have
3729 // 2 dart instance fields (fld1, fld2) and a reference to the native fields. 3739 // 2 dart instance fields (fld1, fld2) and a reference to the native fields.
3730 // Hence the size of an instance of "NativeFields" should be 3740 // Hence the size of an instance of "NativeFields" should be
3731 // (1 + 2) * kWordSize + size of object header. 3741 // (1 + 2) * kWordSize + size of object header.
3732 // We check to make sure the instance size computed by the VM matches 3742 // We check to make sure the instance size computed by the VM matches
3733 // our expectations. 3743 // our expectations.
3734 intptr_t header_size = sizeof(RawObject); 3744 intptr_t header_size = sizeof(RawObject);
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
4054 " static const int fld4 = 10;\n" 4064 " static const int fld4 = 10;\n"
4055 "}\n" 4065 "}\n"
4056 "NativeFields testMain1() {\n" 4066 "NativeFields testMain1() {\n"
4057 " NativeFields obj = new NativeFields(10, 20);\n" 4067 " NativeFields obj = new NativeFields(10, 20);\n"
4058 " return obj;\n" 4068 " return obj;\n"
4059 "}\n" 4069 "}\n"
4060 "Function testMain2() {\n" 4070 "Function testMain2() {\n"
4061 " return () {};\n" 4071 " return () {};\n"
4062 "}\n"; 4072 "}\n";
4063 Dart_Handle result; 4073 Dart_Handle result;
4074 DARTSCOPE(Isolate::Current());
4064 4075
4065 // Create a test library and Load up a test script in it. 4076 // Create a test library and Load up a test script in it.
4066 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 4077 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
4067 4078
4068 // Invoke a function which returns an object of type NativeFields. 4079 // Invoke a function which returns an object of type NativeFields.
4069 Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain1"), 0, NULL); 4080 Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain1"), 0, NULL);
4070 EXPECT_VALID(retobj); 4081 EXPECT_VALID(retobj);
4071 4082
4072 // Now access and set various native instance fields of the returned object. 4083 // Now access and set various native instance fields of the returned object.
4073 // All of these tests are expected to return failure as there are no 4084 // 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
4131 " var port = new RawReceivePort();\n" 4142 " var port = new RawReceivePort();\n"
4132 " var obj = new Test(1,2);\n" 4143 " var obj = new Test(1,2);\n"
4133 " var msg = [obj, port.sendPort];\n" 4144 " var msg = [obj, port.sendPort];\n"
4134 " var snd = Isolate.spawn(echo, msg);\n" 4145 " var snd = Isolate.spawn(echo, msg);\n"
4135 " port.handler = (msg) {\n" 4146 " port.handler = (msg) {\n"
4136 " port.close();\n" 4147 " port.close();\n"
4137 " print('from worker ${msg}');\n" 4148 " print('from worker ${msg}');\n"
4138 " };\n" 4149 " };\n"
4139 "}\n"; 4150 "}\n";
4140 4151
4152 DARTSCOPE(Isolate::Current());
4153
4141 // Create a test library and Load up a test script in it. 4154 // Create a test library and Load up a test script in it.
4142 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 4155 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
4143 4156
4144 // Invoke 'main' which should spawn an isolate and try to send an 4157 // Invoke 'main' which should spawn an isolate and try to send an
4145 // object with native fields over to the spawned isolate. This 4158 // object with native fields over to the spawned isolate. This
4146 // should result in an unhandled exception which is checked. 4159 // should result in an unhandled exception which is checked.
4147 Dart_Handle retobj = Dart_Invoke(lib, NewString("main"), 0, NULL); 4160 Dart_Handle retobj = Dart_Invoke(lib, NewString("main"), 0, NULL);
4148 EXPECT(Dart_IsError(retobj)); 4161 EXPECT(Dart_IsError(retobj));
4149 } 4162 }
4150 4163
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after
4801 " static const int fld4 = 10;\n" 4814 " static const int fld4 = 10;\n"
4802 "}\n" 4815 "}\n"
4803 "Function testMain1() {\n" 4816 "Function testMain1() {\n"
4804 " InvokeClosure obj = new InvokeClosure(10, 20);\n" 4817 " InvokeClosure obj = new InvokeClosure(10, 20);\n"
4805 " return obj.method1(10);\n" 4818 " return obj.method1(10);\n"
4806 "}\n" 4819 "}\n"
4807 "Function testMain2() {\n" 4820 "Function testMain2() {\n"
4808 " return InvokeClosure.method2(10);\n" 4821 " return InvokeClosure.method2(10);\n"
4809 "}\n"; 4822 "}\n";
4810 Dart_Handle result; 4823 Dart_Handle result;
4824 DARTSCOPE(Isolate::Current());
4811 4825
4812 // Create a test library and Load up a test script in it. 4826 // Create a test library and Load up a test script in it.
4813 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 4827 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
4814 4828
4815 // Invoke a function which returns a closure. 4829 // Invoke a function which returns a closure.
4816 Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain1"), 0, NULL); 4830 Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain1"), 0, NULL);
4817 EXPECT_VALID(retobj); 4831 EXPECT_VALID(retobj);
4818 4832
4819 EXPECT(Dart_IsClosure(retobj)); 4833 EXPECT(Dart_IsClosure(retobj));
4820 EXPECT(!Dart_IsClosure(Dart_NewInteger(101))); 4834 EXPECT(!Dart_IsClosure(Dart_NewInteger(101)));
(...skipping 1718 matching lines...) Expand 10 before | Expand all | Expand 10 after
6539 const int kInterruptCount = 10; 6553 const int kInterruptCount = 10;
6540 static int interrupt_count = 0; 6554 static int interrupt_count = 0;
6541 static bool IsolateInterruptTestCallback() { 6555 static bool IsolateInterruptTestCallback() {
6542 OS::Print(" ========== Interrupt callback called #%d\n", interrupt_count + 1); 6556 OS::Print(" ========== Interrupt callback called #%d\n", interrupt_count + 1);
6543 { 6557 {
6544 MonitorLocker ml(sync); 6558 MonitorLocker ml(sync);
6545 interrupt_count++; 6559 interrupt_count++;
6546 ml.Notify(); 6560 ml.Notify();
6547 } 6561 }
6548 if (interrupt_count == kInterruptCount) { 6562 if (interrupt_count == kInterruptCount) {
6549 START_TIMER(Isolate::Current(), time_native_execution);
6550 Dart_EnterScope(); 6563 Dart_EnterScope();
6551 Dart_Handle lib = Dart_LookupLibrary(NewString(TestCase::url())); 6564 Dart_Handle lib = Dart_LookupLibrary(NewString(TestCase::url()));
6552 EXPECT_VALID(lib); 6565 EXPECT_VALID(lib);
6553 Dart_Handle exc = NewString("foo"); 6566 Dart_Handle exc = NewString("foo");
6554 EXPECT_VALID(exc); 6567 EXPECT_VALID(exc);
6555 Dart_Handle result = Dart_ThrowException(exc); 6568 Dart_Handle result = Dart_ThrowException(exc);
6556 EXPECT_VALID(result); 6569 EXPECT_VALID(result);
6557 UNREACHABLE(); // Dart_ThrowException only returns if it gets an error. 6570 UNREACHABLE(); // Dart_ThrowException only returns if it gets an error.
6558 return false; 6571 return false;
6559 } 6572 }
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
7136 } 7149 }
7137 7150
7138 7151
7139 // Allocates an object in new space and assigns it a peer. Allows the 7152 // Allocates an object in new space and assigns it a peer. Allows the
7140 // peer referent to be garbage collected and checks that the count of 7153 // peer referent to be garbage collected and checks that the count of
7141 // peer objects is decremented by one. 7154 // peer objects is decremented by one.
7142 TEST_CASE(CollectOneNewSpacePeer) { 7155 TEST_CASE(CollectOneNewSpacePeer) {
7143 Isolate* isolate = Isolate::Current(); 7156 Isolate* isolate = Isolate::Current();
7144 Dart_EnterScope(); 7157 Dart_EnterScope();
7145 { 7158 {
7159 DARTSCOPE(isolate);
7146 Dart_Handle str = NewString("a string"); 7160 Dart_Handle str = NewString("a string");
7147 EXPECT_VALID(str); 7161 EXPECT_VALID(str);
7148 EXPECT(Dart_IsString(str)); 7162 EXPECT(Dart_IsString(str));
7149 EXPECT_EQ(0, isolate->heap()->PeerCount()); 7163 EXPECT_EQ(0, isolate->heap()->PeerCount());
7150 void* out = &out; 7164 void* out = &out;
7151 EXPECT_VALID(Dart_GetPeer(str, &out)); 7165 EXPECT_VALID(Dart_GetPeer(str, &out));
7152 EXPECT(out == NULL); 7166 EXPECT(out == NULL);
7153 int peer = 1234; 7167 int peer = 1234;
7154 EXPECT_VALID(Dart_SetPeer(str, &peer)); 7168 EXPECT_VALID(Dart_SetPeer(str, &peer));
7155 EXPECT_EQ(1, isolate->heap()->PeerCount()); 7169 EXPECT_EQ(1, isolate->heap()->PeerCount());
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
7208 } 7222 }
7209 7223
7210 7224
7211 // Allocates two objects in new space and assigns them a peer. Allow 7225 // Allocates two objects in new space and assigns them a peer. Allow
7212 // the peer referents to be garbage collected and check that the count 7226 // the peer referents to be garbage collected and check that the count
7213 // of peer objects is decremented by two. 7227 // of peer objects is decremented by two.
7214 TEST_CASE(CollectTwoNewSpacePeers) { 7228 TEST_CASE(CollectTwoNewSpacePeers) {
7215 Isolate* isolate = Isolate::Current(); 7229 Isolate* isolate = Isolate::Current();
7216 Dart_EnterScope(); 7230 Dart_EnterScope();
7217 { 7231 {
7232 DARTSCOPE(isolate);
7218 Dart_Handle s1 = NewString("s1"); 7233 Dart_Handle s1 = NewString("s1");
7219 EXPECT_VALID(s1); 7234 EXPECT_VALID(s1);
7220 EXPECT(Dart_IsString(s1)); 7235 EXPECT(Dart_IsString(s1));
7221 EXPECT_EQ(0, isolate->heap()->PeerCount()); 7236 EXPECT_EQ(0, isolate->heap()->PeerCount());
7222 void* o1 = &o1; 7237 void* o1 = &o1;
7223 EXPECT(Dart_GetPeer(s1, &o1)); 7238 EXPECT(Dart_GetPeer(s1, &o1));
7224 EXPECT(o1 == NULL); 7239 EXPECT(o1 == NULL);
7225 int p1 = 1234; 7240 int p1 = 1234;
7226 EXPECT_VALID(Dart_SetPeer(s1, &p1)); 7241 EXPECT_VALID(Dart_SetPeer(s1, &p1));
7227 EXPECT_EQ(1, isolate->heap()->PeerCount()); 7242 EXPECT_EQ(1, isolate->heap()->PeerCount());
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
7291 EXPECT(out == NULL); 7306 EXPECT(out == NULL);
7292 int peer = 1234; 7307 int peer = 1234;
7293 EXPECT_VALID(Dart_SetPeer(str, &peer)); 7308 EXPECT_VALID(Dart_SetPeer(str, &peer));
7294 out = &out; 7309 out = &out;
7295 EXPECT(Dart_GetPeer(str, &out)); 7310 EXPECT(Dart_GetPeer(str, &out));
7296 EXPECT(out == reinterpret_cast<void*>(&peer)); 7311 EXPECT(out == reinterpret_cast<void*>(&peer));
7297 EXPECT_EQ(1, isolate->heap()->PeerCount()); 7312 EXPECT_EQ(1, isolate->heap()->PeerCount());
7298 isolate->heap()->CollectGarbage(Heap::kNew); 7313 isolate->heap()->CollectGarbage(Heap::kNew);
7299 isolate->heap()->CollectGarbage(Heap::kNew); 7314 isolate->heap()->CollectGarbage(Heap::kNew);
7300 { 7315 {
7301 HANDLESCOPE(isolate); 7316 DARTSCOPE(isolate);
7302 String& handle = String::Handle(); 7317 String& handle = String::Handle();
7303 handle ^= Api::UnwrapHandle(str); 7318 handle ^= Api::UnwrapHandle(str);
7304 EXPECT(handle.IsOld()); 7319 EXPECT(handle.IsOld());
7305 } 7320 }
7306 EXPECT_VALID(Dart_GetPeer(str, &out)); 7321 EXPECT_VALID(Dart_GetPeer(str, &out));
7307 EXPECT(out == reinterpret_cast<void*>(&peer)); 7322 EXPECT(out == reinterpret_cast<void*>(&peer));
7308 EXPECT_EQ(1, isolate->heap()->PeerCount()); 7323 EXPECT_EQ(1, isolate->heap()->PeerCount());
7309 EXPECT_VALID(Dart_SetPeer(str, NULL)); 7324 EXPECT_VALID(Dart_SetPeer(str, NULL));
7310 out = &out; 7325 out = &out;
7311 EXPECT_VALID(Dart_GetPeer(str, &out)); 7326 EXPECT_VALID(Dart_GetPeer(str, &out));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
7344 } 7359 }
7345 7360
7346 7361
7347 // Allocates an object in old space and assigns it a peer. Allow the 7362 // Allocates an object in old space and assigns it a peer. Allow the
7348 // peer referent to be garbage collected and check that the count of 7363 // peer referent to be garbage collected and check that the count of
7349 // peer objects is decremented by one. 7364 // peer objects is decremented by one.
7350 TEST_CASE(CollectOneOldSpacePeer) { 7365 TEST_CASE(CollectOneOldSpacePeer) {
7351 Isolate* isolate = Isolate::Current(); 7366 Isolate* isolate = Isolate::Current();
7352 Dart_EnterScope(); 7367 Dart_EnterScope();
7353 { 7368 {
7354 HANDLESCOPE(isolate); 7369 DARTSCOPE(isolate);
7355 Dart_Handle str = Api::NewHandle(isolate, String::New("str", Heap::kOld)); 7370 Dart_Handle str = Api::NewHandle(isolate, String::New("str", Heap::kOld));
7356 EXPECT_VALID(str); 7371 EXPECT_VALID(str);
7357 EXPECT(Dart_IsString(str)); 7372 EXPECT(Dart_IsString(str));
7358 EXPECT_EQ(0, isolate->heap()->PeerCount()); 7373 EXPECT_EQ(0, isolate->heap()->PeerCount());
7359 void* out = &out; 7374 void* out = &out;
7360 EXPECT(Dart_GetPeer(str, &out)); 7375 EXPECT(Dart_GetPeer(str, &out));
7361 EXPECT(out == NULL); 7376 EXPECT(out == NULL);
7362 int peer = 1234; 7377 int peer = 1234;
7363 EXPECT_VALID(Dart_SetPeer(str, &peer)); 7378 EXPECT_VALID(Dart_SetPeer(str, &peer));
7364 EXPECT_EQ(1, isolate->heap()->PeerCount()); 7379 EXPECT_EQ(1, isolate->heap()->PeerCount());
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
7420 } 7435 }
7421 7436
7422 7437
7423 // Allocates two objects in old space and assigns them a peer. Allows 7438 // Allocates two objects in old space and assigns them a peer. Allows
7424 // the peer referents to be garbage collected and checks that the 7439 // the peer referents to be garbage collected and checks that the
7425 // count of peer objects is decremented by two. 7440 // count of peer objects is decremented by two.
7426 TEST_CASE(CollectTwoOldSpacePeers) { 7441 TEST_CASE(CollectTwoOldSpacePeers) {
7427 Isolate* isolate = Isolate::Current(); 7442 Isolate* isolate = Isolate::Current();
7428 Dart_EnterScope(); 7443 Dart_EnterScope();
7429 { 7444 {
7430 HANDLESCOPE(isolate); 7445 DARTSCOPE(isolate);
7431 Dart_Handle s1 = Api::NewHandle(isolate, String::New("s1", Heap::kOld)); 7446 Dart_Handle s1 = Api::NewHandle(isolate, String::New("s1", Heap::kOld));
7432 EXPECT_VALID(s1); 7447 EXPECT_VALID(s1);
7433 EXPECT(Dart_IsString(s1)); 7448 EXPECT(Dart_IsString(s1));
7434 EXPECT_EQ(0, isolate->heap()->PeerCount()); 7449 EXPECT_EQ(0, isolate->heap()->PeerCount());
7435 void* o1 = &o1; 7450 void* o1 = &o1;
7436 EXPECT(Dart_GetPeer(s1, &o1)); 7451 EXPECT(Dart_GetPeer(s1, &o1));
7437 EXPECT(o1 == NULL); 7452 EXPECT(o1 == NULL);
7438 int p1 = 1234; 7453 int p1 = 1234;
7439 EXPECT_VALID(Dart_SetPeer(s1, &p1)); 7454 EXPECT_VALID(Dart_SetPeer(s1, &p1));
7440 EXPECT_EQ(1, isolate->heap()->PeerCount()); 7455 EXPECT_EQ(1, isolate->heap()->PeerCount());
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
7897 NewString("main"), 7912 NewString("main"),
7898 1, 7913 1,
7899 dart_args); 7914 dart_args);
7900 int64_t value = 0; 7915 int64_t value = 0;
7901 result = Dart_IntegerToInt64(result, &value); 7916 result = Dart_IntegerToInt64(result, &value);
7902 EXPECT_VALID(result); 7917 EXPECT_VALID(result);
7903 EXPECT_EQ(6, value); 7918 EXPECT_EQ(6, value);
7904 } 7919 }
7905 7920
7906 } // namespace dart 7921 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/dart_entry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698