summaryrefslogtreecommitdiff
path: root/rs/java/android/renderscript/BaseObj.java
diff options
context:
space:
mode:
authorYang Ni <yangni@google.com>2016-03-24 09:40:32 -0700
committerYang Ni <yangni@google.com>2016-03-31 14:38:38 -0700
commiteb4dd08ec132f83745b8b28fa7da58eb4478b5b9 (patch)
tree0ebfc9e81548d6a1e7ec1907020946fa5af8bc83 /rs/java/android/renderscript/BaseObj.java
parent72dd79fa41fad71a14bb82eb830c927299d92d02 (diff)
Added CloseGuard for BaseObj
Bug: 27719830 To turn on warnings, apps have to add to their Activity.onCreate() method the following code. StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() .detectLeakedClosableObjects() .penaltyLog() .build()); For Slang generated ScriptC derived classes, we assume their constructors won't throw exceptions after calling the ScriptC constructor. In addition, ScriptIntrinsic derived classes do not seem to throw exceptions in their constructors either. Therefore, we can leave the guard.open() call in the Script constructor. This may be only an approximation, but allows us to add CloseGuard for script objects without making changes to slang. Change-Id: I77ed45239a60b85af5c811dee6c124fb53da9060
Diffstat (limited to 'rs/java/android/renderscript/BaseObj.java')
-rw-r--r--rs/java/android/renderscript/BaseObj.java13
1 files changed, 11 insertions, 2 deletions
diff --git a/rs/java/android/renderscript/BaseObj.java b/rs/java/android/renderscript/BaseObj.java
index 1372ab79e264..f95af1673730 100644
--- a/rs/java/android/renderscript/BaseObj.java
+++ b/rs/java/android/renderscript/BaseObj.java
@@ -16,6 +16,7 @@
package android.renderscript;
+import dalvik.system.CloseGuard;
import java.util.concurrent.locks.ReentrantReadWriteLock;
/**
@@ -69,6 +70,7 @@ public class BaseObj {
}
private long mID;
+ final CloseGuard guard = CloseGuard.get();
private boolean mDestroyed;
private String mName;
RenderScript mRS;
@@ -119,6 +121,7 @@ public class BaseObj {
}
if (shouldDestroy) {
+ guard.close();
// must include nObjDestroy in the critical section
ReentrantReadWriteLock.ReadLock rlock = mRS.mRWLock.readLock();
rlock.lock();
@@ -133,8 +136,14 @@ public class BaseObj {
}
protected void finalize() throws Throwable {
- helpDestroy();
- super.finalize();
+ try {
+ if (guard != null) {
+ guard.warnIfOpen();
+ }
+ helpDestroy();
+ } finally {
+ super.finalize();
+ }
}
/**