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
(cherry picked from commit eb4dd08ec1)
This commit is contained in:
Yang Ni
2016-03-24 09:40:32 -07:00
parent 15d4b5aae8
commit 6484b6be5c
11 changed files with 42 additions and 2 deletions

View File

@@ -148,6 +148,8 @@ public final class ScriptGroup extends BaseObj {
fieldIDs, values, sizes, depClosures, depFieldIDs);
setID(id);
guard.open("destroy");
}
Closure(RenderScript rs, Script.InvokeID invokeID,
@@ -181,6 +183,8 @@ public final class ScriptGroup extends BaseObj {
values, sizes);
setID(id);
guard.open("destroy");
}
private void retrieveValueAndDependenceInfo(RenderScript rs,
@@ -382,6 +386,7 @@ public final class ScriptGroup extends BaseObj {
ScriptGroup(long id, RenderScript rs) {
super(id, rs);
guard.open("destroy");
}
ScriptGroup(RenderScript rs, String name, List<Closure> closures,
@@ -398,6 +403,7 @@ public final class ScriptGroup extends BaseObj {
}
long id = rs.nScriptGroup2Create(name, RenderScript.getCachePath(), closureIDs);
setID(id);
guard.open("destroy");
}
/**