summaryrefslogtreecommitdiffstats
path: root/jdisc_core
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@yahoo-inc.com>2017-07-17 13:52:43 +0200
committerBjørn Christian Seime <bjorncs@yahoo-inc.com>2017-07-17 13:54:04 +0200
commit441197acb9f207afbbc67bbcb93aa95def71d000 (patch)
tree45805499270d23e20707c9fc6023770128d925f2 /jdisc_core
parentd977da45ba86d878f25eba4cd692af7b93cf5eb5 (diff)
Ensure that phantom references are enqueued to reference queue
Diffstat (limited to 'jdisc_core')
-rw-r--r--jdisc_core/src/main/java/com/yahoo/jdisc/core/ActiveContainerDeactivationWatchdog.java7
-rw-r--r--jdisc_core/src/test/java/com/yahoo/jdisc/core/ActiveContainerDeactivationWatchdogTest.java3
2 files changed, 7 insertions, 3 deletions
diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/core/ActiveContainerDeactivationWatchdog.java b/jdisc_core/src/main/java/com/yahoo/jdisc/core/ActiveContainerDeactivationWatchdog.java
index 90e2049a868..c6355c93648 100644
--- a/jdisc_core/src/main/java/com/yahoo/jdisc/core/ActiveContainerDeactivationWatchdog.java
+++ b/jdisc_core/src/main/java/com/yahoo/jdisc/core/ActiveContainerDeactivationWatchdog.java
@@ -67,7 +67,7 @@ class ActiveContainerDeactivationWatchdog implements ActiveContainerMetrics, Aut
WATCHDOG_FREQUENCY.getSeconds(),
WATCHDOG_FREQUENCY.getSeconds(),
TimeUnit.SECONDS);
- this.scheduler.scheduleAtFixedRate(System::gc,
+ this.scheduler.scheduleAtFixedRate(ActiveContainerDeactivationWatchdog::triggerGc,
GC_TRIGGER_FREQUENCY.getSeconds(),
GC_TRIGGER_FREQUENCY.getSeconds(),
TimeUnit.SECONDS);
@@ -121,6 +121,11 @@ class ActiveContainerDeactivationWatchdog implements ActiveContainerMetrics, Aut
}
}
+ private static void triggerGc() {
+ System.gc();
+ System.runFinalization(); // this is required to trigger enqueuing of phantom references on some Linux systems
+ }
+
private void enforceDestructionOfGarbageCollectedContainers() {
ActiveContainerPhantomReference reference;
while ((reference = (ActiveContainerPhantomReference) garbageCollectedContainers.poll()) != null) {
diff --git a/jdisc_core/src/test/java/com/yahoo/jdisc/core/ActiveContainerDeactivationWatchdogTest.java b/jdisc_core/src/test/java/com/yahoo/jdisc/core/ActiveContainerDeactivationWatchdogTest.java
index 05207728c88..a618b82c5ec 100644
--- a/jdisc_core/src/test/java/com/yahoo/jdisc/core/ActiveContainerDeactivationWatchdogTest.java
+++ b/jdisc_core/src/test/java/com/yahoo/jdisc/core/ActiveContainerDeactivationWatchdogTest.java
@@ -6,7 +6,6 @@ import com.yahoo.jdisc.ResourceReference;
import com.yahoo.jdisc.statistics.ActiveContainerMetrics;
import com.yahoo.jdisc.test.TestDriver;
import com.yahoo.test.ManualClock;
-import org.junit.Ignore;
import org.junit.Test;
import java.lang.ref.WeakReference;
@@ -69,7 +68,6 @@ public class ActiveContainerDeactivationWatchdogTest {
}
@Test
- @Ignore("JVM does not give any guarantee when phantom references will be enqueued to reference queues")
public void deactivated_container_destructed_if_its_reference_counter_is_nonzero() {
ExecutorMock executor = new ExecutorMock();
ActiveContainerDeactivationWatchdog watchdog =
@@ -87,6 +85,7 @@ public class ActiveContainerDeactivationWatchdogTest {
WeakReference<ActiveContainer> containerWeakReference = new WeakReference<>(container);
container = null; // make container instance collectable by GC
System.gc();
+ System.runFinalization(); // this is required to trigger enqueuing of phantom references on some Linux systems
assertNull("Container is not GCed - probably because the watchdog has a concrete reference to it",
containerWeakReference.get());