summaryrefslogtreecommitdiffstats
path: root/libart
diff options
context:
space:
mode:
authorMathieu Chartier <mathieuc@google.com>2015-06-04 18:38:24 -0700
committerMathieu Chartier <mathieuc@google.com>2015-06-05 15:06:56 -0700
commit51855ccb72d01a28babedbaed70974d4f3697ab0 (patch)
treeb57ae5327fe974441d53c674d687d60e514ed1c4 /libart
parent438f476f72a90637b085db2bf8a9209ef6e903fe (diff)
downloadlibcore-51855ccb72d01a28babedbaed70974d4f3697ab0.zip
libcore-51855ccb72d01a28babedbaed70974d4f3697ab0.tar.gz
libcore-51855ccb72d01a28babedbaed70974d4f3697ab0.tar.bz2
Add VMRuntime.runFinalizationWithTimeout
Used by native allocations to prevent deadlocks. Bug: 21544853 Change-Id: I57b2f7ae8b74185922eb3c15ba0ab71a4d2348aa
Diffstat (limited to 'libart')
-rw-r--r--libart/src/main/java/dalvik/system/VMRuntime.java25
1 files changed, 25 insertions, 0 deletions
diff --git a/libart/src/main/java/dalvik/system/VMRuntime.java b/libart/src/main/java/dalvik/system/VMRuntime.java
index b885ed2..aa3f154 100644
--- a/libart/src/main/java/dalvik/system/VMRuntime.java
+++ b/libart/src/main/java/dalvik/system/VMRuntime.java
@@ -16,6 +16,7 @@
package dalvik.system;
+import java.lang.ref.FinalizerReference;
import java.util.HashMap;
import java.util.Map;
@@ -301,6 +302,30 @@ public final class VMRuntime {
*/
public native void registerNativeFree(int bytes);
+ /**
+ * Wait for objects to be finalized.
+ *
+ * If finalization takes longer than timeout, then the function returns before all objects are
+ * finalized.
+ *
+ * @param timeout
+ * timeout in nanoseconds of the maximum time to wait until all pending finalizers
+ * are run. If timeout is 0, then there is no timeout. Note that the timeout does
+ * not stop the finalization process, it merely stops the wait.
+ *
+ * @see #Runtime.runFinalization()
+ * @see #wait(long,int)
+ */
+ public static void runFinalization(long timeout) {
+ try {
+ FinalizerReference.finalizeAllEnqueued(timeout);
+ } catch (InterruptedException e) {
+ // Interrupt the current thread without actually throwing the InterruptionException
+ // for the caller.
+ Thread.currentThread().interrupt();
+ }
+ }
+
public native void requestConcurrentGC();
public native void concurrentGC();
public native void requestHeapTrim();