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

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, 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/heap.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 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);
2318 // Triggers a scavenge immediately, since kWeak1ExternalSize is above limit.
2316 weak1 = Dart_NewWeakPersistentHandle(obj, 2319 weak1 = Dart_NewWeakPersistentHandle(obj,
2317 NULL, 2320 NULL,
2318 kWeak1ExternalSize, 2321 kWeak1ExternalSize,
2319 NopCallback); 2322 NopCallback);
2320 EXPECT_VALID(AsHandle(weak1)); 2323 EXPECT_VALID(AsHandle(weak1));
2321 // While new space is "full" of external data, any allocation will 2324 // ... but the object is still alive and not yet promoted, so external size
2322 // trigger GC, so after two of them, obj should be promoted. 2325 // in new space is still above the limit. Thus, even the following tiny
2323 Dart_Handle trigger1 = NewString("trigger1"); 2326 // external allocation will trigger another scavenge.
2324 EXPECT_VALID(trigger1); 2327 Dart_WeakPersistentHandle trigger =
2325 Dart_Handle trigger2 = NewString("trigger2"); 2328 Dart_NewWeakPersistentHandle(obj, NULL, 1, NopCallback);
2326 EXPECT_VALID(trigger2); 2329 EXPECT_VALID(AsHandle(trigger));
2330 Dart_DeleteWeakPersistentHandle(isolate, trigger);
2331 // After the two scavenges above, 'obj' should now be promoted, hence its
2332 // external size charged to old space.
2327 { 2333 {
2328 DARTSCOPE(Isolate::Current()); 2334 DARTSCOPE(Isolate::Current());
2329 String& handle = String::Handle(); 2335 String& handle = String::Handle();
2330 handle ^= Api::UnwrapHandle(obj); 2336 handle ^= Api::UnwrapHandle(obj);
2331 EXPECT(handle.IsOld()); 2337 EXPECT(handle.IsOld());
2332 } 2338 }
2333 EXPECT(heap->ExternalInWords(Heap::kNew) == 0); 2339 EXPECT(heap->ExternalInWords(Heap::kNew) == 0);
2334 EXPECT(heap->ExternalInWords(Heap::kOld) == kWeak1ExternalSize / kWordSize); 2340 EXPECT(heap->ExternalInWords(Heap::kOld) == kWeak1ExternalSize / kWordSize);
2335 Dart_ExitScope(); 2341 Dart_ExitScope();
2336 } 2342 }
2337 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current());
2338 Dart_DeleteWeakPersistentHandle(isolate, weak1); 2343 Dart_DeleteWeakPersistentHandle(isolate, weak1);
2339 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); 2344 Isolate::Current()->heap()->CollectGarbage(Heap::kOld);
2340 EXPECT(heap->ExternalInWords(Heap::kOld) == 0); 2345 EXPECT(heap->ExternalInWords(Heap::kOld) == 0);
2341 } 2346 }
2342 2347
2343 2348
2344 TEST_CASE(WeakPersistentHandleExternalAllocationSizeOddReferents) { 2349 TEST_CASE(WeakPersistentHandleExternalAllocationSizeOddReferents) {
2345 Heap* heap = Isolate::Current()->heap(); 2350 Heap* heap = Isolate::Current()->heap();
2346 Dart_WeakPersistentHandle weak1 = NULL; 2351 Dart_WeakPersistentHandle weak1 = NULL;
2347 static const intptr_t kWeak1ExternalSize = 1 * KB; 2352 static const intptr_t kWeak1ExternalSize = 1 * KB;
(...skipping 5734 matching lines...) Expand 10 before | Expand all | Expand 10 after
8082 NewString("main"), 8087 NewString("main"),
8083 1, 8088 1,
8084 dart_args); 8089 dart_args);
8085 int64_t value = 0; 8090 int64_t value = 0;
8086 result = Dart_IntegerToInt64(result, &value); 8091 result = Dart_IntegerToInt64(result, &value);
8087 EXPECT_VALID(result); 8092 EXPECT_VALID(result);
8088 EXPECT_EQ(6, value); 8093 EXPECT_EQ(6, value);
8089 } 8094 }
8090 8095
8091 } // namespace dart 8096 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698