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

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

Issue 211593004: Reduce GC from external allocation. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 9 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/heap.cc » ('j') | runtime/vm/heap.cc » ('J')
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 2288 matching lines...) Expand 10 before | Expand all | Expand 10 after
2299 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); 2299 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks);
2300 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); 2300 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks);
2301 EXPECT(heap->ExternalInWords(Heap::kNew) == 0); 2301 EXPECT(heap->ExternalInWords(Heap::kNew) == 0);
2302 EXPECT(heap->ExternalInWords(Heap::kOld) == kWeakExternalSize / kWordSize); 2302 EXPECT(heap->ExternalInWords(Heap::kOld) == kWeakExternalSize / kWordSize);
2303 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); 2303 Isolate::Current()->heap()->CollectGarbage(Heap::kOld);
2304 EXPECT(heap->ExternalInWords(Heap::kOld) == 0); 2304 EXPECT(heap->ExternalInWords(Heap::kOld) == 0);
2305 } 2305 }
2306 2306
2307 2307
2308 TEST_CASE(WeakPersistentHandleExternalAllocationSizeOversized) { 2308 TEST_CASE(WeakPersistentHandleExternalAllocationSizeOversized) {
2309 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current());
2309 Heap* heap = Isolate::Current()->heap(); 2310 Heap* heap = Isolate::Current()->heap();
2310 Dart_WeakPersistentHandle weak1 = NULL; 2311 Dart_WeakPersistentHandle weak1 = NULL;
2311 const intptr_t kWeak1ExternalSize = 100 * MB; 2312 // Large enough to exceed any new space limit. Not actually allocated.
2313 const intptr_t kWeak1ExternalSize = 500 * MB;
2312 { 2314 {
2313 Dart_EnterScope(); 2315 Dart_EnterScope();
2314 Dart_Handle obj = NewString("weakly referenced string"); 2316 Dart_Handle obj = NewString("weakly referenced string");
2315 EXPECT_VALID(obj); 2317 EXPECT_VALID(obj);
2316 weak1 = Dart_NewWeakPersistentHandle(obj, 2318 weak1 = Dart_NewWeakPersistentHandle(obj,
Ivan Posva 2014/03/27 21:18:16 Please add comments where you would expect GC, and
koda 2014/03/27 22:11:13 Done.
2317 NULL, 2319 NULL,
2318 kWeak1ExternalSize, 2320 kWeak1ExternalSize,
2319 NopCallback); 2321 NopCallback);
2320 EXPECT_VALID(AsHandle(weak1)); 2322 EXPECT_VALID(AsHandle(weak1));
2321 // While new space is "full" of external data, any allocation will 2323 // While external size in new space is above limit, any external allocation
2322 // trigger GC, so after two of them, obj should be promoted. 2324 // in new space will trigger GC, so after one more, obj should be promoted.
2323 Dart_Handle trigger1 = NewString("trigger1"); 2325 Dart_WeakPersistentHandle trigger =
2324 EXPECT_VALID(trigger1); 2326 Dart_NewWeakPersistentHandle(obj, NULL, 1, NopCallback);
2325 Dart_Handle trigger2 = NewString("trigger2"); 2327 EXPECT_VALID(AsHandle(trigger));
2326 EXPECT_VALID(trigger2); 2328 Dart_DeleteWeakPersistentHandle(isolate, trigger);
2327 { 2329 {
2328 DARTSCOPE(Isolate::Current()); 2330 DARTSCOPE(Isolate::Current());
2329 String& handle = String::Handle(); 2331 String& handle = String::Handle();
2330 handle ^= Api::UnwrapHandle(obj); 2332 handle ^= Api::UnwrapHandle(obj);
2331 EXPECT(handle.IsOld()); 2333 EXPECT(handle.IsOld());
2332 } 2334 }
2333 EXPECT(heap->ExternalInWords(Heap::kNew) == 0); 2335 EXPECT(heap->ExternalInWords(Heap::kNew) == 0);
2334 EXPECT(heap->ExternalInWords(Heap::kOld) == kWeak1ExternalSize / kWordSize); 2336 EXPECT(heap->ExternalInWords(Heap::kOld) == kWeak1ExternalSize / kWordSize);
2335 Dart_ExitScope(); 2337 Dart_ExitScope();
2336 } 2338 }
2337 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current());
2338 Dart_DeleteWeakPersistentHandle(isolate, weak1); 2339 Dart_DeleteWeakPersistentHandle(isolate, weak1);
2339 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); 2340 Isolate::Current()->heap()->CollectGarbage(Heap::kOld);
2340 EXPECT(heap->ExternalInWords(Heap::kOld) == 0); 2341 EXPECT(heap->ExternalInWords(Heap::kOld) == 0);
2341 } 2342 }
2342 2343
2343 2344
2344 TEST_CASE(WeakPersistentHandleExternalAllocationSizeOddReferents) { 2345 TEST_CASE(WeakPersistentHandleExternalAllocationSizeOddReferents) {
2345 Heap* heap = Isolate::Current()->heap(); 2346 Heap* heap = Isolate::Current()->heap();
2346 Dart_WeakPersistentHandle weak1 = NULL; 2347 Dart_WeakPersistentHandle weak1 = NULL;
2347 static const intptr_t kWeak1ExternalSize = 1 * KB; 2348 static const intptr_t kWeak1ExternalSize = 1 * KB;
(...skipping 5734 matching lines...) Expand 10 before | Expand all | Expand 10 after
8082 NewString("main"), 8083 NewString("main"),
8083 1, 8084 1,
8084 dart_args); 8085 dart_args);
8085 int64_t value = 0; 8086 int64_t value = 0;
8086 result = Dart_IntegerToInt64(result, &value); 8087 result = Dart_IntegerToInt64(result, &value);
8087 EXPECT_VALID(result); 8088 EXPECT_VALID(result);
8088 EXPECT_EQ(6, value); 8089 EXPECT_EQ(6, value);
8089 } 8090 }
8090 8091
8091 } // namespace dart 8092 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/heap.cc » ('j') | runtime/vm/heap.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698