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

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

Issue 226973003: Simpler, more consistent triggering of old GC; also, use external in policy. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 8 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 | « no previous file | runtime/vm/dart_api_state.h » ('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 // TODO(zra): Remove when tests are ready to enable. 5 // TODO(zra): Remove when tests are ready to enable.
6 #include "platform/globals.h" 6 #include "platform/globals.h"
7 #if !defined(TARGET_ARCH_ARM64) 7 #if !defined(TARGET_ARCH_ARM64)
8 8
9 #include "bin/builtin.h" 9 #include "bin/builtin.h"
10 #include "include/dart_api.h" 10 #include "include/dart_api.h"
(...skipping 2293 matching lines...) Expand 10 before | Expand all | Expand 10 after
2304 // Promoting the string should transfer the external size to old. 2304 // Promoting the string should transfer the external size to old.
2305 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); 2305 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks);
2306 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); 2306 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks);
2307 EXPECT(heap->ExternalInWords(Heap::kNew) == 0); 2307 EXPECT(heap->ExternalInWords(Heap::kNew) == 0);
2308 EXPECT(heap->ExternalInWords(Heap::kOld) == kWeakExternalSize / kWordSize); 2308 EXPECT(heap->ExternalInWords(Heap::kOld) == kWeakExternalSize / kWordSize);
2309 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); 2309 Isolate::Current()->heap()->CollectGarbage(Heap::kOld);
2310 EXPECT(heap->ExternalInWords(Heap::kOld) == 0); 2310 EXPECT(heap->ExternalInWords(Heap::kOld) == 0);
2311 } 2311 }
2312 2312
2313 2313
2314 TEST_CASE(WeakPersistentHandleExternalAllocationSizeOversized) { 2314 TEST_CASE(WeakPersistentHandleExternalAllocationSizeNewspaceGC) {
2315 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current()); 2315 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current());
2316 Heap* heap = Isolate::Current()->heap(); 2316 Heap* heap = Isolate::Current()->heap();
2317 Dart_WeakPersistentHandle weak1 = NULL; 2317 Dart_WeakPersistentHandle weak1 = NULL;
2318 // Large enough to exceed any new space limit. Not actually allocated. 2318 // Large enough to exceed any new space limit. Not actually allocated.
2319 const intptr_t kWeak1ExternalSize = 500 * MB; 2319 const intptr_t kWeak1ExternalSize = 500 * MB;
2320 { 2320 {
2321 Dart_EnterScope(); 2321 Dart_EnterScope();
2322 Dart_Handle obj = NewString("weakly referenced string"); 2322 Dart_Handle obj = NewString("weakly referenced string");
2323 EXPECT_VALID(obj); 2323 EXPECT_VALID(obj);
2324 // Triggers a scavenge immediately, since kWeak1ExternalSize is above limit. 2324 // Triggers a scavenge immediately, since kWeak1ExternalSize is above limit.
(...skipping 20 matching lines...) Expand all
2345 EXPECT(heap->ExternalInWords(Heap::kNew) == 0); 2345 EXPECT(heap->ExternalInWords(Heap::kNew) == 0);
2346 EXPECT(heap->ExternalInWords(Heap::kOld) == kWeak1ExternalSize / kWordSize); 2346 EXPECT(heap->ExternalInWords(Heap::kOld) == kWeak1ExternalSize / kWordSize);
2347 Dart_ExitScope(); 2347 Dart_ExitScope();
2348 } 2348 }
2349 Dart_DeleteWeakPersistentHandle(isolate, weak1); 2349 Dart_DeleteWeakPersistentHandle(isolate, weak1);
2350 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); 2350 Isolate::Current()->heap()->CollectGarbage(Heap::kOld);
2351 EXPECT(heap->ExternalInWords(Heap::kOld) == 0); 2351 EXPECT(heap->ExternalInWords(Heap::kOld) == 0);
2352 } 2352 }
2353 2353
2354 2354
2355 TEST_CASE(WeakPersistentHandleExternalAllocationSizeOldspaceGC) {
2356 // Check that external allocation in old space can trigger GC.
2357 Isolate* isolate = Isolate::Current();
2358 Dart_EnterScope();
2359 Dart_Handle live = Api::NewHandle(isolate, String::New("live", Heap::kOld));
2360 EXPECT_VALID(live);
2361 Dart_WeakPersistentHandle weak = NULL;
2362 const intptr_t kSmallExternalSize = 1 * KB;
2363 {
2364 Dart_EnterScope();
2365 Dart_Handle dead = Api::NewHandle(isolate, String::New("dead", Heap::kOld));
2366 EXPECT_VALID(dead);
2367 weak = Dart_NewWeakPersistentHandle(dead,
2368 NULL,
2369 kSmallExternalSize,
2370 NopCallback);
2371 EXPECT_VALID(AsHandle(weak));
2372 Dart_ExitScope();
2373 }
2374 EXPECT_EQ(kSmallExternalSize,
Ivan Posva 2014/04/18 16:11:26 You might want to verify how much external size th
koda 2014/04/18 16:38:18 Done.
2375 isolate->heap()->ExternalInWords(Heap::kOld) * kWordSize);
2376 // Large enough to trigger GC in old space. Not actually allocated.
2377 const intptr_t kHugeExternalSize = 1000 * MB;
2378 Dart_NewWeakPersistentHandle(live,
2379 NULL,
2380 kHugeExternalSize,
2381 NopCallback);
2382 // Expect small garbage to be collected.
2383 EXPECT_EQ(kHugeExternalSize,
2384 isolate->heap()->ExternalInWords(Heap::kOld) * kWordSize);
2385 Dart_DeleteWeakPersistentHandle(reinterpret_cast<Dart_Isolate>(isolate),
2386 weak);
2387 Dart_ExitScope();
2388 }
2389
2390
2355 TEST_CASE(WeakPersistentHandleExternalAllocationSizeOddReferents) { 2391 TEST_CASE(WeakPersistentHandleExternalAllocationSizeOddReferents) {
2356 Heap* heap = Isolate::Current()->heap(); 2392 Heap* heap = Isolate::Current()->heap();
2357 Dart_WeakPersistentHandle weak1 = NULL; 2393 Dart_WeakPersistentHandle weak1 = NULL;
2358 static const intptr_t kWeak1ExternalSize = 1 * KB; 2394 static const intptr_t kWeak1ExternalSize = 1 * KB;
2359 Dart_WeakPersistentHandle weak2 = NULL; 2395 Dart_WeakPersistentHandle weak2 = NULL;
2360 static const intptr_t kWeak2ExternalSize = 2 * KB; 2396 static const intptr_t kWeak2ExternalSize = 2 * KB;
2361 { 2397 {
2362 Dart_EnterScope(); 2398 Dart_EnterScope();
2363 Dart_Handle dart_null = Dart_Null(); // VM heap object. 2399 Dart_Handle dart_null = Dart_True(); // VM heap object.
Ivan Posva 2014/04/18 16:11:26 Why?
koda 2014/04/18 16:38:18 I assume you mean "Why the change from 'null' to '
2364 EXPECT_VALID(dart_null); 2400 EXPECT_VALID(dart_null);
2365 weak1 = Dart_NewWeakPersistentHandle( 2401 weak1 = Dart_NewWeakPersistentHandle(
2366 dart_null, NULL, kWeak1ExternalSize, NopCallback); 2402 dart_null, NULL, kWeak1ExternalSize, NopCallback);
2367 EXPECT_VALID(AsHandle(weak1)); 2403 EXPECT_VALID(AsHandle(weak1));
2368 Dart_Handle zero = Dart_NewInteger(0); // Smi. 2404 Dart_Handle zero = Dart_NewInteger(0); // Smi.
2369 EXPECT_VALID(dart_null); 2405 EXPECT_VALID(dart_null);
2370 weak2 = Dart_NewWeakPersistentHandle( 2406 weak2 = Dart_NewWeakPersistentHandle(
2371 zero, NULL, kWeak2ExternalSize, NopCallback); 2407 zero, NULL, kWeak2ExternalSize, NopCallback);
2372 EXPECT_VALID(AsHandle(weak2)); 2408 EXPECT_VALID(AsHandle(weak2));
2373 // Both should be charged to old space. 2409 // Both should be charged to old space.
2374 EXPECT(heap->ExternalInWords(Heap::kOld) == 2410 EXPECT(heap->ExternalInWords(Heap::kOld) ==
2375 (kWeak1ExternalSize + kWeak2ExternalSize) / kWordSize); 2411 (kWeak1ExternalSize + kWeak2ExternalSize) / kWordSize);
2376 Dart_ExitScope(); 2412 Dart_ExitScope();
2377 } 2413 }
2378 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current()); 2414 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current());
2379 Dart_DeleteWeakPersistentHandle(isolate, weak1); 2415 Dart_DeleteWeakPersistentHandle(isolate, weak1);
2380 Dart_DeleteWeakPersistentHandle(isolate, weak2); 2416 Dart_DeleteWeakPersistentHandle(isolate, weak2);
2381 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); 2417 Isolate::Current()->heap()->CollectGarbage(Heap::kOld);
2382 EXPECT(heap->ExternalInWords(Heap::kOld) == 0); 2418 EXPECT_EQ(0, heap->ExternalInWords(Heap::kOld));
2383 } 2419 }
2384 2420
2385 2421
2386 static Dart_WeakPersistentHandle weak1 = NULL; 2422 static Dart_WeakPersistentHandle weak1 = NULL;
2387 static Dart_WeakPersistentHandle weak2 = NULL; 2423 static Dart_WeakPersistentHandle weak2 = NULL;
2388 static Dart_WeakPersistentHandle weak3 = NULL; 2424 static Dart_WeakPersistentHandle weak3 = NULL;
2389 static Dart_WeakPersistentHandle weak4 = NULL; 2425 static Dart_WeakPersistentHandle weak4 = NULL;
2390 2426
2391 2427
2392 static void ObjectGroupsCallback(void* isolate_callback_data, 2428 static void ObjectGroupsCallback(void* isolate_callback_data,
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
2685 { 2721 {
2686 Dart_EnterScope(); 2722 Dart_EnterScope();
2687 // Both prologue weak handles should be preserved. 2723 // Both prologue weak handles should be preserved.
2688 EXPECT(!Dart_IsNull(AsHandle(new_pwph))); 2724 EXPECT(!Dart_IsNull(AsHandle(new_pwph)));
2689 EXPECT(!Dart_IsNull(AsHandle(old_pwph))); 2725 EXPECT(!Dart_IsNull(AsHandle(old_pwph)));
2690 Dart_ExitScope(); 2726 Dart_ExitScope();
2691 } 2727 }
2692 2728
2693 // Garbage collect old space without invoking API callbacks. 2729 // Garbage collect old space without invoking API callbacks.
2694 Isolate::Current()->heap()->CollectGarbage(Heap::kOld, 2730 Isolate::Current()->heap()->CollectGarbage(Heap::kOld,
2695 Heap::kIgnoreApiCallbacks); 2731 Heap::kIgnoreApiCallbacks,
2732 Heap::kGCTestCase);
2696 2733
2697 { 2734 {
2698 Dart_EnterScope(); 2735 Dart_EnterScope();
2699 // Both prologue weak handles should be preserved. 2736 // Both prologue weak handles should be preserved.
2700 EXPECT(!Dart_IsNull(AsHandle(new_pwph))); 2737 EXPECT(!Dart_IsNull(AsHandle(new_pwph)));
2701 EXPECT(!Dart_IsNull(AsHandle(old_pwph))); 2738 EXPECT(!Dart_IsNull(AsHandle(old_pwph)));
2702 Dart_ExitScope(); 2739 Dart_ExitScope();
2703 } 2740 }
2704 2741
2705 // Garbage collect new space invoking API callbacks. 2742 // Garbage collect new space invoking API callbacks.
2706 GCTestHelper::CollectNewSpace(Heap::kInvokeApiCallbacks); 2743 GCTestHelper::CollectNewSpace(Heap::kInvokeApiCallbacks);
2707 2744
2708 { 2745 {
2709 Dart_EnterScope(); 2746 Dart_EnterScope();
2710 // The prologue weak handle with a new space referent should now be 2747 // The prologue weak handle with a new space referent should now be
2711 // cleared. The old space referent should be preserved. 2748 // cleared. The old space referent should be preserved.
2712 EXPECT(new_pwph == NULL); 2749 EXPECT(new_pwph == NULL);
2713 EXPECT(!Dart_IsNull(AsHandle(old_pwph))); 2750 EXPECT(!Dart_IsNull(AsHandle(old_pwph)));
2714 Dart_ExitScope(); 2751 Dart_ExitScope();
2715 } 2752 }
2716 2753
2717 Isolate::Current()->heap()->CollectGarbage(Heap::kOld, 2754 Isolate::Current()->heap()->CollectGarbage(Heap::kOld,
2718 Heap::kInvokeApiCallbacks); 2755 Heap::kInvokeApiCallbacks,
2756 Heap::kGCTestCase);
2719 2757
2720 { 2758 {
2721 Dart_EnterScope(); 2759 Dart_EnterScope();
2722 // The prologue weak handle with an old space referent should now be 2760 // The prologue weak handle with an old space referent should now be
2723 // cleared. The new space referent should remain cleared. 2761 // cleared. The new space referent should remain cleared.
2724 EXPECT(new_pwph == NULL); 2762 EXPECT(new_pwph == NULL);
2725 EXPECT(old_pwph == NULL); 2763 EXPECT(old_pwph == NULL);
2726 Dart_ExitScope(); 2764 Dart_ExitScope();
2727 } 2765 }
2728 } 2766 }
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
3015 global_epilogue_callback_status = 7; 3053 global_epilogue_callback_status = 7;
3016 GCTestHelper::CollectNewSpace(Heap::kInvokeApiCallbacks); 3054 GCTestHelper::CollectNewSpace(Heap::kInvokeApiCallbacks);
3017 EXPECT_EQ(6, global_prologue_callback_status); 3055 EXPECT_EQ(6, global_prologue_callback_status);
3018 EXPECT_EQ(7, global_epilogue_callback_status); 3056 EXPECT_EQ(7, global_epilogue_callback_status);
3019 3057
3020 // Garbage collect old space ignoring callbacks. This should invoke 3058 // Garbage collect old space ignoring callbacks. This should invoke
3021 // the prologue callback. The prologue status value should change. 3059 // the prologue callback. The prologue status value should change.
3022 global_prologue_callback_status = 3; 3060 global_prologue_callback_status = 3;
3023 global_epilogue_callback_status = 7; 3061 global_epilogue_callback_status = 7;
3024 Isolate::Current()->heap()->CollectGarbage(Heap::kOld, 3062 Isolate::Current()->heap()->CollectGarbage(Heap::kOld,
3025 Heap::kIgnoreApiCallbacks); 3063 Heap::kIgnoreApiCallbacks,
3064 Heap::kGCTestCase);
3026 EXPECT_EQ(3, global_prologue_callback_status); 3065 EXPECT_EQ(3, global_prologue_callback_status);
3027 EXPECT_EQ(7, global_epilogue_callback_status); 3066 EXPECT_EQ(7, global_epilogue_callback_status);
3028 3067
3029 // Garbage collect old space. This should invoke the prologue 3068 // Garbage collect old space. This should invoke the prologue
3030 // callback. The prologue status value should change. 3069 // callback. The prologue status value should change.
3031 global_prologue_callback_status = 3; 3070 global_prologue_callback_status = 3;
3032 global_epilogue_callback_status = 7; 3071 global_epilogue_callback_status = 7;
3033 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); 3072 Isolate::Current()->heap()->CollectGarbage(Heap::kOld);
3034 EXPECT_EQ(6, global_prologue_callback_status); 3073 EXPECT_EQ(6, global_prologue_callback_status);
3035 EXPECT_EQ(7, global_epilogue_callback_status); 3074 EXPECT_EQ(7, global_epilogue_callback_status);
(...skipping 29 matching lines...) Expand all
3065 // should change. 3104 // should change.
3066 global_prologue_callback_status = 3; 3105 global_prologue_callback_status = 3;
3067 global_epilogue_callback_status = 7; 3106 global_epilogue_callback_status = 7;
3068 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); 3107 Isolate::Current()->heap()->CollectGarbage(Heap::kOld);
3069 EXPECT_EQ(6, global_prologue_callback_status); 3108 EXPECT_EQ(6, global_prologue_callback_status);
3070 EXPECT_EQ(28, global_epilogue_callback_status); 3109 EXPECT_EQ(28, global_epilogue_callback_status);
3071 3110
3072 // Garbage collect old space again without invoking callbacks. 3111 // Garbage collect old space again without invoking callbacks.
3073 // Nothing should change. 3112 // Nothing should change.
3074 Isolate::Current()->heap()->CollectGarbage(Heap::kOld, 3113 Isolate::Current()->heap()->CollectGarbage(Heap::kOld,
3075 Heap::kIgnoreApiCallbacks); 3114 Heap::kIgnoreApiCallbacks,
3115 Heap::kGCTestCase);
3076 EXPECT_EQ(6, global_prologue_callback_status); 3116 EXPECT_EQ(6, global_prologue_callback_status);
3077 EXPECT_EQ(28, global_epilogue_callback_status); 3117 EXPECT_EQ(28, global_epilogue_callback_status);
3078 3118
3079 // Garbage collect old space again. Callbacks are persistent so the 3119 // Garbage collect old space again. Callbacks are persistent so the
3080 // prologue and epilogue status values should change again. 3120 // prologue and epilogue status values should change again.
3081 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); 3121 Isolate::Current()->heap()->CollectGarbage(Heap::kOld);
3082 EXPECT_EQ(12, global_prologue_callback_status); 3122 EXPECT_EQ(12, global_prologue_callback_status);
3083 EXPECT_EQ(112, global_epilogue_callback_status); 3123 EXPECT_EQ(112, global_epilogue_callback_status);
3084 3124
3085 // Remove the prologue and epilogue callbacks 3125 // Remove the prologue and epilogue callbacks
(...skipping 5010 matching lines...) Expand 10 before | Expand all | Expand 10 after
8096 dart_args); 8136 dart_args);
8097 int64_t value = 0; 8137 int64_t value = 0;
8098 result = Dart_IntegerToInt64(result, &value); 8138 result = Dart_IntegerToInt64(result, &value);
8099 EXPECT_VALID(result); 8139 EXPECT_VALID(result);
8100 EXPECT_EQ(6, value); 8140 EXPECT_EQ(6, value);
8101 } 8141 }
8102 8142
8103 } // namespace dart 8143 } // namespace dart
8104 8144
8105 #endif // !defined(TARGET_ARCH_ARM64) 8145 #endif // !defined(TARGET_ARCH_ARM64)
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/dart_api_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698