From 441fcf13f3bbfd2fb9de273d3d552aad2a7ae9af Mon Sep 17 00:00:00 2001 From: Vasu Nori Date: Tue, 7 Sep 2010 22:12:38 -0700 Subject: remove some useless code and add some code to aid in debugging Change-Id: Ie532848b82dde57cc7a7017661679ece06ca606e --- core/java/android/database/sqlite/SQLiteClosable.java | 15 +++++++++++++-- core/java/android/database/sqlite/SQLiteCompiledSql.java | 9 --------- core/java/android/database/sqlite/SQLiteProgram.java | 10 ---------- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/core/java/android/database/sqlite/SQLiteClosable.java b/core/java/android/database/sqlite/SQLiteClosable.java index 1830f6c84498..21d2ab0aa6e3 100644 --- a/core/java/android/database/sqlite/SQLiteClosable.java +++ b/core/java/android/database/sqlite/SQLiteClosable.java @@ -30,6 +30,7 @@ public abstract class SQLiteClosable { public void acquireReference() { synchronized(mLock) { + checkRefCount(); if (mReferenceCount <= 0) { throw new IllegalStateException( "attempt to re-open an already-closed object: " + getObjInfo()); @@ -40,6 +41,7 @@ public abstract class SQLiteClosable { public void releaseReference() { synchronized(mLock) { + checkRefCount(); mReferenceCount--; if (mReferenceCount == 0) { onAllReferencesReleased(); @@ -49,6 +51,7 @@ public abstract class SQLiteClosable { public void releaseReferenceFromContainer() { synchronized(mLock) { + checkRefCount(); mReferenceCount--; if (mReferenceCount == 0) { onAllReferencesReleasedFromContainer(); @@ -63,8 +66,7 @@ public abstract class SQLiteClosable { if (this instanceof SQLiteDatabase) { buff.append("database = "); buff.append(((SQLiteDatabase)this).getPath()); - } else if (this instanceof SQLiteProgram || this instanceof SQLiteStatement || - this instanceof SQLiteQuery) { + } else if (this instanceof SQLiteProgram) { buff.append("mSql = "); buff.append(((SQLiteProgram)this).mSql); } else if (this instanceof CursorWindow) { @@ -74,4 +76,13 @@ public abstract class SQLiteClosable { buff.append(") "); return buff.toString(); } + + private void checkRefCount() { + if (SQLiteDebug.DEBUG_ACTIVE_CURSOR_FINALIZATION) { + if (mReferenceCount > 1000) { + throw new IllegalStateException("refcount: " + mReferenceCount + ", " + + getObjInfo()); + } + } + } } diff --git a/core/java/android/database/sqlite/SQLiteCompiledSql.java b/core/java/android/database/sqlite/SQLiteCompiledSql.java index 9541380f67c5..0b5a4dff3d4d 100644 --- a/core/java/android/database/sqlite/SQLiteCompiledSql.java +++ b/core/java/android/database/sqlite/SQLiteCompiledSql.java @@ -92,9 +92,6 @@ import android.util.Log; // Note that native_finalize() checks to make sure that nStatement is // non-null before destroying it. if (nStatement != 0) { - if (SQLiteDebug.DEBUG_ACTIVE_CURSOR_FINALIZATION) { - Log.v(TAG, "closed and deallocated DbObj (id#" + nStatement +")"); - } mDatabase.finalizeStatementLater(nStatement); nStatement = 0; } @@ -109,16 +106,10 @@ import android.util.Log; return false; } mInUse = true; - if (SQLiteDebug.DEBUG_ACTIVE_CURSOR_FINALIZATION) { - Log.v(TAG, "Acquired DbObj (id#" + nStatement + ") from DB cache"); - } return true; } /* package */ synchronized void release() { - if (SQLiteDebug.DEBUG_ACTIVE_CURSOR_FINALIZATION) { - Log.v(TAG, "Released DbObj (id#" + nStatement + ") back to DB cache"); - } mInUse = false; } diff --git a/core/java/android/database/sqlite/SQLiteProgram.java b/core/java/android/database/sqlite/SQLiteProgram.java index 5e08aed1184c..bcb0c48b6453 100644 --- a/core/java/android/database/sqlite/SQLiteProgram.java +++ b/core/java/android/database/sqlite/SQLiteProgram.java @@ -130,10 +130,6 @@ public abstract class SQLiteProgram extends SQLiteClosable { // make sure it is acquired by me. mCompiledSql.acquire(); mDatabase.addToCompiledQueries(mSql, mCompiledSql); - if (SQLiteDebug.DEBUG_ACTIVE_CURSOR_FINALIZATION) { - Log.v(TAG, "Created DbObj (id#" + mCompiledSql.nStatement + - ") for sql: " + mSql); - } } else { // it is already in compiled-sql cache. // try to acquire the object. @@ -144,12 +140,6 @@ public abstract class SQLiteProgram extends SQLiteClosable { // CompiledSql object. create a new one. // finalize it when I am done with it in "this" object. mCompiledSql = new SQLiteCompiledSql(mDatabase, mSql); - if (SQLiteDebug.DEBUG_ACTIVE_CURSOR_FINALIZATION) { - Log.v(TAG, "** possible bug ** Created NEW DbObj (id#" + - mCompiledSql.nStatement + - ") because the previously created DbObj (id#" + last + - ") was not released for sql:" + mSql); - } // since it is not in the cache, no need to acquire() it. } } -- cgit v1.2.3-59-g8ed1b