From 9bf189228fdb0ec14b284f8bd543d5f9137997cc Mon Sep 17 00:00:00 2001 From: Jason Sams Date: Sat, 13 Apr 2013 19:48:36 -0700 Subject: [PATCH] Revert GC thread changes This is not quite a straight revery, some manual edits were necessary. The original CL didn't undergo sufficient design review or testing. Revert until the regressions can be sorted out. Bug 8585185 This reverts commit 6dacf8355a0692b52c49f603f43317772cb36175 This reverts commit f8c033db1edf36a0ab09568c3142054f0be2d1a1 Change-Id: Ie7215bdf881332e822603547e92f810f595077fc --- .../java/android/renderscript/Allocation.java | 18 +---- .../java/android/renderscript/BaseObj.java | 6 -- .../android/renderscript/RenderScript.java | 72 ------------------- .../android/renderscript/RenderScriptGL.java | 3 - .../java/android/renderscript/ScriptC.java | 2 - 5 files changed, 2 insertions(+), 99 deletions(-) diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java index ea29b7dc49cc3..5d1990a4b85e9 100644 --- a/graphics/java/android/renderscript/Allocation.java +++ b/graphics/java/android/renderscript/Allocation.java @@ -277,21 +277,13 @@ public class Allocation extends BaseObj { throw new RSIllegalArgumentException("Invalid usage combination."); } } - if (t != null) { - // don't need to account for USAGE_SHARED Allocations - if ((usage & USAGE_SHARED) == 0) { - int numBytes = t.getCount() * t.getElement().getBytesSize(); - rs.addAllocSizeForGC(numBytes); - mGCSize = numBytes; - } - } + mType = t; mUsage = usage; if (t != null) { updateCacheInfo(t); } - } private void validateIsInt32() { @@ -355,12 +347,6 @@ public class Allocation extends BaseObj { mType.updateFromNative(); updateCacheInfo(mType); } - // don't need to account for USAGE_SHARED Allocations - if ((mUsage & USAGE_SHARED) == 0) { - int numBytes = mType.getCount() * mType.getElement().getBytesSize(); - mRS.addAllocSizeForGC(numBytes); - mGCSize = numBytes; - } } /** @@ -1264,7 +1250,6 @@ public class Allocation extends BaseObj { if (type.getID(rs) == 0) { throw new RSInvalidStateException("Bad Type"); } - int id = rs.nAllocationCreateTyped(type.getID(rs), mips.mID, usage, 0); if (id == 0) { throw new RSRuntimeException("Allocation creation failed."); @@ -1414,6 +1399,7 @@ public class Allocation extends BaseObj { return alloc; } + int id = rs.nAllocationCreateFromBitmap(t.getID(rs), mips.mID, b, usage); if (id == 0) { throw new RSRuntimeException("Load failed."); diff --git a/graphics/java/android/renderscript/BaseObj.java b/graphics/java/android/renderscript/BaseObj.java index c2ebc9f79d6a3..f464f9bb1025a 100644 --- a/graphics/java/android/renderscript/BaseObj.java +++ b/graphics/java/android/renderscript/BaseObj.java @@ -71,9 +71,6 @@ public class BaseObj { private int mID; private boolean mDestroyed; private String mName; - - int mGCSize; - RenderScript mRS; /** @@ -138,9 +135,6 @@ public class BaseObj { throw new RSInvalidStateException("Object already destroyed."); } mDestroyed = true; - if (mGCSize != 0) { - mRS.removeAllocSizeForGC(mGCSize); - } mRS.nObjDestroy(mID); } diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java index 33639dc57d4fb..6f614c3767e9c 100644 --- a/graphics/java/android/renderscript/RenderScript.java +++ b/graphics/java/android/renderscript/RenderScript.java @@ -18,9 +18,7 @@ package android.renderscript; import java.io.File; import java.lang.reflect.Field; -import java.util.concurrent.locks.*; -import android.app.ActivityManager; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; @@ -804,8 +802,6 @@ public class RenderScript { int mContext; @SuppressWarnings({"FieldCanBeLocal"}) MessageThread mMessageThread; - GCThread mGCThread; - Element mElement_U8; Element mElement_I8; @@ -1095,60 +1091,6 @@ public class RenderScript { } } - static class GCThread extends Thread { - RenderScript mRS; - boolean mRun = true; - - long currentSize = 0; - long targetSize; // call System.gc after 512MB of allocs - - final Lock lock = new ReentrantLock(); - final Condition cond = lock.newCondition(); - - GCThread(RenderScript rs) { - super("RSGCThread"); - mRS = rs; - - } - - public void run() { - ActivityManager am = (ActivityManager)mRS.getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE); - ActivityManager.MemoryInfo meminfo = new ActivityManager.MemoryInfo(); - am.getMemoryInfo(meminfo); - targetSize = (long)(meminfo.totalMem * .5f); - - while(mRun) { - System.gc(); - lock.lock(); - try { - cond.awaitUninterruptibly(); - } finally { - lock.unlock(); - } - } - - Log.d(LOG_TAG, "GCThread exiting."); - } - - public synchronized void addAllocSize(long bytes) { - currentSize += bytes; - if (currentSize >= targetSize) { - lock.lock(); - try { - cond.signal(); - } finally { - lock.unlock(); - } - } - } - - public synchronized void removeAllocSize(long bytes) { - currentSize -= bytes; - } - - } - - RenderScript(Context ctx) { if (ctx != null) { mApplicationContext = ctx.getApplicationContext(); @@ -1171,15 +1113,6 @@ public class RenderScript { return create(ctx, sdkVersion, ContextType.NORMAL); } - void addAllocSizeForGC(int bytes) { - mGCThread.addAllocSize(bytes); - } - - void removeAllocSizeForGC(int bytes) { - mGCThread.removeAllocSize(bytes); - } - - /** * Create a basic RenderScript context. * @@ -1196,9 +1129,7 @@ public class RenderScript { throw new RSDriverException("Failed to create RS context."); } rs.mMessageThread = new MessageThread(rs); - rs.mGCThread = new GCThread(rs); rs.mMessageThread.start(); - rs.mGCThread.start(); return rs; } @@ -1253,11 +1184,8 @@ public class RenderScript { validate(); nContextDeinitToClient(mContext); mMessageThread.mRun = false; - mGCThread.mRun = false; - mGCThread.addAllocSize(0); try { mMessageThread.join(); - mGCThread.join(); } catch(InterruptedException e) { } diff --git a/graphics/java/android/renderscript/RenderScriptGL.java b/graphics/java/android/renderscript/RenderScriptGL.java index fad883873458e..52034b19e7062 100644 --- a/graphics/java/android/renderscript/RenderScriptGL.java +++ b/graphics/java/android/renderscript/RenderScriptGL.java @@ -198,9 +198,6 @@ public class RenderScriptGL extends RenderScript { } mMessageThread = new MessageThread(this); mMessageThread.start(); - mGCThread = new GCThread(this); - mGCThread.start(); - } /** diff --git a/graphics/java/android/renderscript/ScriptC.java b/graphics/java/android/renderscript/ScriptC.java index 2f69775a20ae9..221f76060bba5 100644 --- a/graphics/java/android/renderscript/ScriptC.java +++ b/graphics/java/android/renderscript/ScriptC.java @@ -60,8 +60,6 @@ public class ScriptC extends Script { throw new RSRuntimeException("Loading of ScriptC script failed."); } setID(id); - mGCSize = 2 * 1024 * 1024; - rs.addAllocSizeForGC(mGCSize); } /**