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

Unified Diff: runtime/vm/dart_api_impl_test.cc

Issue 2012973002: Background finalization. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 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/dart_api_state.h » ('j') | runtime/vm/dart_api_state.h » ('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 fcc4e79cd8cc88cc39f412f13ed1490c827bd007..870be8122b574e2352c28957a37070529cfe673b 100644
--- a/runtime/vm/dart_api_impl_test.cc
+++ b/runtime/vm/dart_api_impl_test.cc
@@ -1206,6 +1206,27 @@ TEST_CASE(MalformedStringToUTF8) {
}
+// Helper class to ensure new gen GC is triggered without any side effects.
+// The normal call to CollectGarbage(Heap::kNew) could potentially trigger
+// an old gen collection if there is a promotion failure and this could
+// perturb the test.
+class GCTestHelper : public AllStatic {
+ public:
+ static void CollectNewSpace(Heap::ApiCallbacks api_callbacks) {
+ bool invoke_api_callbacks = (api_callbacks == Heap::kInvokeApiCallbacks);
+ Isolate::Current()->heap()->new_space()->Scavenge(invoke_api_callbacks);
+ }
+
+ static void WaitForFinalizationTasks() {
+ Heap* heap = Isolate::Current()->heap();
+ MonitorLocker ml(heap->finalization_tasks_lock());
+ while (heap->finalization_tasks() > 0) {
+ ml.Wait();
siva 2016/06/02 20:18:05 Should this be WaitWithSafepointCheck(...) here?
rmacnak 2016/06/03 01:08:30 Done.
+ }
+ }
+};
+
+
static void ExternalStringCallbackFinalizer(void* peer) {
*static_cast<int*>(peer) *= 2;
}
@@ -1242,9 +1263,11 @@ TEST_CASE(ExternalStringCallback) {
EXPECT_EQ(40, peer8);
EXPECT_EQ(41, peer16);
Isolate::Current()->heap()->CollectGarbage(Heap::kOld);
+ GCTestHelper::WaitForFinalizationTasks();
EXPECT_EQ(40, peer8);
EXPECT_EQ(41, peer16);
Isolate::Current()->heap()->CollectGarbage(Heap::kNew);
+ GCTestHelper::WaitForFinalizationTasks();
EXPECT_EQ(80, peer8);
EXPECT_EQ(82, peer16);
}
@@ -2381,8 +2404,10 @@ TEST_CASE(ExternalTypedDataCallback) {
TransitionNativeToVM transition(thread);
EXPECT(peer == 0);
Isolate::Current()->heap()->CollectGarbage(Heap::kOld);
+ GCTestHelper::WaitForFinalizationTasks();
EXPECT(peer == 0);
Isolate::Current()->heap()->CollectGarbage(Heap::kNew);
+ GCTestHelper::WaitForFinalizationTasks();
EXPECT(peer == 42);
}
}
@@ -2439,6 +2464,7 @@ TEST_CASE(Float32x4List) {
{
TransitionNativeToVM transition(thread);
Isolate::Current()->heap()->CollectGarbage(Heap::kNew);
+ GCTestHelper::WaitForFinalizationTasks();
EXPECT(peer == 42);
}
}
@@ -2601,19 +2627,6 @@ UNIT_TEST_CASE(AssignToPersistentHandle) {
}
-// Helper class to ensure new gen GC is triggered without any side effects.
-// The normal call to CollectGarbage(Heap::kNew) could potentially trigger
-// an old gen collection if there is a promotion failure and this could
-// perturb the test.
-class GCTestHelper : public AllStatic {
- public:
- static void CollectNewSpace(Heap::ApiCallbacks api_callbacks) {
- bool invoke_api_callbacks = (api_callbacks == Heap::kInvokeApiCallbacks);
- Isolate::Current()->heap()->new_space()->Scavenge(invoke_api_callbacks);
- }
-};
-
-
static Dart_Handle AsHandle(Dart_PersistentHandle weak) {
return Dart_HandleFromPersistent(weak);
}
@@ -2728,6 +2741,7 @@ TEST_CASE(WeakPersistentHandle) {
TransitionNativeToVM transition(thread);
// Garbage collect new space again.
GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks);
+ GCTestHelper::WaitForFinalizationTasks();
}
{
@@ -2743,6 +2757,7 @@ TEST_CASE(WeakPersistentHandle) {
TransitionNativeToVM transition(thread);
// Garbage collect old space again.
Isolate::Current()->heap()->CollectGarbage(Heap::kOld);
+ GCTestHelper::WaitForFinalizationTasks();
}
{
@@ -2787,6 +2802,7 @@ TEST_CASE(WeakPersistentHandleCallback) {
Isolate::Current()->heap()->CollectGarbage(Heap::kOld);
EXPECT(peer == 0);
GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks);
+ GCTestHelper::WaitForFinalizationTasks();
EXPECT(peer == 42);
}
}
@@ -2813,6 +2829,7 @@ TEST_CASE(WeakPersistentHandleNoCallback) {
Isolate::Current()->heap()->CollectGarbage(Heap::kOld);
EXPECT(peer == 0);
GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks);
+ GCTestHelper::WaitForFinalizationTasks();
EXPECT(peer == 0);
}
}
@@ -2873,6 +2890,7 @@ TEST_CASE(WeakPersistentHandleExternalAllocationSize) {
// Collect weakly referenced string, and promote strongly referenced string.
GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks);
GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks);
+ GCTestHelper::WaitForFinalizationTasks();
EXPECT(heap->ExternalInWords(Heap::kNew) == 0);
EXPECT(heap->ExternalInWords(Heap::kOld) == kWeak2ExternalSize / kWordSize);
}
@@ -2883,6 +2901,7 @@ TEST_CASE(WeakPersistentHandleExternalAllocationSize) {
{
TransitionNativeToVM transition(thread);
Isolate::Current()->heap()->CollectGarbage(Heap::kOld);
+ GCTestHelper::WaitForFinalizationTasks();
EXPECT(heap->ExternalInWords(Heap::kOld) == 0);
}
}
@@ -2928,6 +2947,7 @@ TEST_CASE(WeakPersistentHandleExternalAllocationSizeNewspaceGC) {
{
TransitionNativeToVM transition(thread);
Isolate::Current()->heap()->CollectGarbage(Heap::kOld);
+ GCTestHelper::WaitForFinalizationTasks();
EXPECT(heap->ExternalInWords(Heap::kOld) == 0);
}
}
« no previous file with comments | « no previous file | runtime/vm/dart_api_state.h » ('j') | runtime/vm/dart_api_state.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698