summaryrefslogtreecommitdiffstats
path: root/core/java/android/database/sqlite
diff options
context:
space:
mode:
authorJeff Brown <jeffbrown@google.com>2012-01-20 12:34:34 -0800
committerJeff Brown <jeffbrown@google.com>2012-01-20 13:08:03 -0800
commit4b57553e693c9705e8363d3e0e9d881261b3e6fa (patch)
treeb6468f5b5a28610452b1748c421f4766e07f3182 /core/java/android/database/sqlite
parent8592baa347f5874b4f36713b6ca2edcedbb3f071 (diff)
downloadframeworks_base-4b57553e693c9705e8363d3e0e9d881261b3e6fa.zip
frameworks_base-4b57553e693c9705e8363d3e0e9d881261b3e6fa.tar.gz
frameworks_base-4b57553e693c9705e8363d3e0e9d881261b3e6fa.tar.bz2
Initialize SQLite as part of the android runtime.
This ensures that the SQLite library is always correctly configured and initialized before other framework or application code has a chance to use it. This is important because initialization has to happen at most once so we need to get it right and prevent races. This change makes it possible to omit the SQLite auto-initialization workaround from the SQLite library, potentially saving a few cycles here and there. Change-Id: Ifbed8685ee44aa1e9c0b391e233b0257fa738e4f
Diffstat (limited to 'core/java/android/database/sqlite')
-rw-r--r--core/java/android/database/sqlite/SQLiteConnection.java2
-rw-r--r--core/java/android/database/sqlite/SQLiteDebug.java1
-rw-r--r--core/java/android/database/sqlite/SQLiteGlobal.java42
3 files changed, 10 insertions, 35 deletions
diff --git a/core/java/android/database/sqlite/SQLiteConnection.java b/core/java/android/database/sqlite/SQLiteConnection.java
index 2ea936e..72f62fd 100644
--- a/core/java/android/database/sqlite/SQLiteConnection.java
+++ b/core/java/android/database/sqlite/SQLiteConnection.java
@@ -194,8 +194,6 @@ public final class SQLiteConnection {
}
private void open() {
- SQLiteGlobal.initializeOnce();
-
mConnectionPtr = nativeOpen(mConfiguration.path, mConfiguration.openFlags,
mConfiguration.label,
SQLiteDebug.DEBUG_SQL_STATEMENTS, SQLiteDebug.DEBUG_SQL_TIME);
diff --git a/core/java/android/database/sqlite/SQLiteDebug.java b/core/java/android/database/sqlite/SQLiteDebug.java
index 95350ba..204483d 100644
--- a/core/java/android/database/sqlite/SQLiteDebug.java
+++ b/core/java/android/database/sqlite/SQLiteDebug.java
@@ -138,7 +138,6 @@ public final class SQLiteDebug {
*/
public static PagerStats getDatabaseInfo() {
PagerStats stats = new PagerStats();
- SQLiteGlobal.initializeOnce();
nativeGetPagerStats(stats);
stats.dbStats = SQLiteDatabase.getDbStats();
return stats;
diff --git a/core/java/android/database/sqlite/SQLiteGlobal.java b/core/java/android/database/sqlite/SQLiteGlobal.java
index 5e129be..dbefd63 100644
--- a/core/java/android/database/sqlite/SQLiteGlobal.java
+++ b/core/java/android/database/sqlite/SQLiteGlobal.java
@@ -22,57 +22,35 @@ import android.os.StatFs;
* Provides access to SQLite functions that affect all database connection,
* such as memory management.
*
+ * The native code associated with SQLiteGlobal is also sets global configuration options
+ * using sqlite3_config() then calls sqlite3_initialize() to ensure that the SQLite
+ * library is properly initialized exactly once before any other framework or application
+ * code has a chance to run.
+ *
+ * Verbose SQLite logging is enabled if the "log.tag.SQLiteLog" property is set to "V".
+ * (per {@link SQLiteDebug#DEBUG_SQL_LOG}).
+ *
* @hide
*/
public final class SQLiteGlobal {
private static final String TAG = "SQLiteGlobal";
private static final Object sLock = new Object();
- private static boolean sInitialized;
- private static int sSoftHeapLimit;
private static int sDefaultPageSize;
- private static native void nativeConfig(boolean verboseLog, int softHeapLimit);
- private static native int nativeReleaseMemory(int bytesToFree);
+ private static native int nativeReleaseMemory();
private SQLiteGlobal() {
}
/**
- * Initializes global SQLite settings the first time it is called.
- * Should be called before opening the first (or any) database.
- * Does nothing on repeated subsequent calls.
- */
- public static void initializeOnce() {
- synchronized (sLock) {
- if (!sInitialized) {
- sInitialized = true;
-
- // Limit to 8MB for now. This is 4 times the maximum cursor window
- // size, as has been used by the original code in SQLiteDatabase for
- // a long time.
- // TODO: We really do need to test whether this helps or hurts us.
- sSoftHeapLimit = 8 * 1024 * 1024;
-
- // Configure SQLite.
- nativeConfig(SQLiteDebug.DEBUG_SQL_LOG, sSoftHeapLimit);
- }
- }
- }
-
- /**
* Attempts to release memory by pruning the SQLite page cache and other
* internal data structures.
*
* @return The number of bytes that were freed.
*/
public static int releaseMemory() {
- synchronized (sLock) {
- if (!sInitialized) {
- return 0;
- }
- return nativeReleaseMemory(sSoftHeapLimit);
- }
+ return nativeReleaseMemory();
}
/**