Loading graphics/java/android/renderscript/Allocation.java +2 −16 Original line number Diff line number Diff line Loading @@ -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() { Loading Loading @@ -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; } } /** Loading Loading @@ -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."); Loading Loading @@ -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."); Loading graphics/java/android/renderscript/BaseObj.java +0 −6 Original line number Diff line number Diff line Loading @@ -71,9 +71,6 @@ public class BaseObj { private int mID; private boolean mDestroyed; private String mName; int mGCSize; RenderScript mRS; /** Loading Loading @@ -138,9 +135,6 @@ public class BaseObj { throw new RSInvalidStateException("Object already destroyed."); } mDestroyed = true; if (mGCSize != 0) { mRS.removeAllocSizeForGC(mGCSize); } mRS.nObjDestroy(mID); } Loading graphics/java/android/renderscript/RenderScript.java +0 −72 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -804,8 +802,6 @@ public class RenderScript { int mContext; @SuppressWarnings({"FieldCanBeLocal"}) MessageThread mMessageThread; GCThread mGCThread; Element mElement_U8; Element mElement_I8; Loading Loading @@ -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(); Loading @@ -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. * Loading @@ -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; } Loading Loading @@ -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) { } Loading graphics/java/android/renderscript/RenderScriptGL.java +0 −3 Original line number Diff line number Diff line Loading @@ -198,9 +198,6 @@ public class RenderScriptGL extends RenderScript { } mMessageThread = new MessageThread(this); mMessageThread.start(); mGCThread = new GCThread(this); mGCThread.start(); } /** Loading graphics/java/android/renderscript/ScriptC.java +0 −2 Original line number Diff line number Diff line Loading @@ -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); } /** Loading Loading
graphics/java/android/renderscript/Allocation.java +2 −16 Original line number Diff line number Diff line Loading @@ -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() { Loading Loading @@ -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; } } /** Loading Loading @@ -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."); Loading Loading @@ -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."); Loading
graphics/java/android/renderscript/BaseObj.java +0 −6 Original line number Diff line number Diff line Loading @@ -71,9 +71,6 @@ public class BaseObj { private int mID; private boolean mDestroyed; private String mName; int mGCSize; RenderScript mRS; /** Loading Loading @@ -138,9 +135,6 @@ public class BaseObj { throw new RSInvalidStateException("Object already destroyed."); } mDestroyed = true; if (mGCSize != 0) { mRS.removeAllocSizeForGC(mGCSize); } mRS.nObjDestroy(mID); } Loading
graphics/java/android/renderscript/RenderScript.java +0 −72 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -804,8 +802,6 @@ public class RenderScript { int mContext; @SuppressWarnings({"FieldCanBeLocal"}) MessageThread mMessageThread; GCThread mGCThread; Element mElement_U8; Element mElement_I8; Loading Loading @@ -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(); Loading @@ -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. * Loading @@ -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; } Loading Loading @@ -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) { } Loading
graphics/java/android/renderscript/RenderScriptGL.java +0 −3 Original line number Diff line number Diff line Loading @@ -198,9 +198,6 @@ public class RenderScriptGL extends RenderScript { } mMessageThread = new MessageThread(this); mMessageThread.start(); mGCThread = new GCThread(this); mGCThread.start(); } /** Loading
graphics/java/android/renderscript/ScriptC.java +0 −2 Original line number Diff line number Diff line Loading @@ -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); } /** Loading