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

Unified Diff: runtime/vm/dart_api_impl_test.cc

Issue 9956138: Process weak reference sets when a scavenge invokes the API callbacks. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/vm/scavenger.h » ('j') | runtime/vm/scavenger.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_api_impl_test.cc
diff --git a/runtime/vm/dart_api_impl_test.cc b/runtime/vm/dart_api_impl_test.cc
index 49b5a9c7745dadee2ff54f84ec7fee9e61f04448..e2a43de1799e5ed62ed0d3f6e25e6ec0070d8229 100644
--- a/runtime/vm/dart_api_impl_test.cc
+++ b/runtime/vm/dart_api_impl_test.cc
@@ -1619,7 +1619,7 @@ TEST_CASE(PrologueWeakPersistentHandles) {
}
-TEST_CASE(ImplicitReferences) {
+TEST_CASE(OldSpaceImplicitReferences) {
Dart_Handle strong = Dart_Null();
EXPECT(Dart_IsNull(strong));
@@ -1705,6 +1705,86 @@ TEST_CASE(ImplicitReferences) {
}
+TEST_CASE(NewSpaceImplicitReferences) {
+ Dart_Handle strong = Dart_Null();
+ EXPECT(Dart_IsNull(strong));
+
+ Dart_Handle weak1 = Dart_Null();
+ EXPECT(Dart_IsNull(weak1));
+
+ Dart_Handle weak2 = Dart_Null();
+ EXPECT(Dart_IsNull(weak2));
+
+ Dart_Handle weak3 = Dart_Null();
+ EXPECT(Dart_IsNull(weak3));
+
+
+ Dart_EnterScope();
+ {
+ DARTSCOPE(Isolate::Current());
+ String& str = String::Handle();
+
+ str ^= String::New("strongly reachable", Heap::kNew);
+ strong = Dart_NewPersistentHandle(Api::NewLocalHandle(str));
+ EXPECT(!Dart_IsNull(strong));
+ EXPECT_VALID(strong);
+
+ str ^= String::New("weakly reachable 1", Heap::kNew);
+ weak1 = Dart_NewWeakPersistentHandle(Api::NewLocalHandle(str), NULL, NULL);
+ EXPECT(!Dart_IsNull(weak1));
+ EXPECT_VALID(weak1);
+
+ str ^= String::New("weakly reachable 2", Heap::kNew);
+ weak2 = Dart_NewWeakPersistentHandle(Api::NewLocalHandle(str), NULL, NULL);
+ EXPECT(!Dart_IsNull(weak2));
+ EXPECT_VALID(weak2);
+
+ str ^= String::New("weakly reachable 3", Heap::kNew);
+ weak3 = Dart_NewWeakPersistentHandle(Api::NewLocalHandle(str), NULL, NULL);
+ EXPECT(!Dart_IsNull(weak3));
+ EXPECT_VALID(weak3);
+ }
+ Dart_ExitScope();
+
+ EXPECT_VALID(strong);
+
+ EXPECT_VALID(weak1);
+ EXPECT_VALID(weak2);
+ EXPECT_VALID(weak3);
+
+ Isolate::Current()->heap()->CollectGarbage(Heap::kOld);
+
+ // Old space collection should not affect old space objects.
+ EXPECT(!Dart_IsNull(weak1));
+ EXPECT(!Dart_IsNull(weak2));
+ EXPECT(!Dart_IsNull(weak3));
+
+ // A strongly referenced key should preserve all the values.
+ {
+ Dart_Handle keys[] = { strong };
+ Dart_Handle values[] = { weak1, weak2, weak3 };
+ EXPECT_VALID(Dart_NewWeakReferenceSet(keys, ARRAY_SIZE(keys),
+ values, ARRAY_SIZE(values)));
+
+ Isolate::Current()->heap()->CollectGarbage(Heap::kNew,
+ Heap::kInvokeApiCallbacks);
+ }
+
+ // All weak references should be preserved.
+ EXPECT(!Dart_IsNull(weak1));
+ EXPECT(!Dart_IsNull(weak2));
+ EXPECT(!Dart_IsNull(weak3));
+
+ Isolate::Current()->heap()->CollectGarbage(Heap::kNew,
+ Heap::kIgnoreApiCallbacks);
+
+ // No weak references should be preserved.
+ EXPECT(Dart_IsNull(weak1));
+ EXPECT(Dart_IsNull(weak2));
+ EXPECT(Dart_IsNull(weak3));
+}
+
+
static int global_prologue_callback_status;
« no previous file with comments | « no previous file | runtime/vm/scavenger.h » ('j') | runtime/vm/scavenger.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698