diff options
author | Jeff Brown <jeffbrown@google.com> | 2012-01-20 14:07:59 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-01-20 14:07:59 -0800 |
commit | 1bf599a01e7ad720150d8cc12416ba67bebd74c9 (patch) | |
tree | db2d5edc57a18a125f1576987b1daf119862d142 /core/jni/android_database_SQLiteGlobal.cpp | |
parent | 2f9510ca50b0fd2925bc7e349f76136ed403a386 (diff) | |
parent | 4b57553e693c9705e8363d3e0e9d881261b3e6fa (diff) | |
download | frameworks_base-1bf599a01e7ad720150d8cc12416ba67bebd74c9.zip frameworks_base-1bf599a01e7ad720150d8cc12416ba67bebd74c9.tar.gz frameworks_base-1bf599a01e7ad720150d8cc12416ba67bebd74c9.tar.bz2 |
Merge "Initialize SQLite as part of the android runtime."
Diffstat (limited to 'core/jni/android_database_SQLiteGlobal.cpp')
-rw-r--r-- | core/jni/android_database_SQLiteGlobal.cpp | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/core/jni/android_database_SQLiteGlobal.cpp b/core/jni/android_database_SQLiteGlobal.cpp index 82cae5a..9301183 100644 --- a/core/jni/android_database_SQLiteGlobal.cpp +++ b/core/jni/android_database_SQLiteGlobal.cpp @@ -24,9 +24,16 @@ #include <sqlite3_android.h> #include "android_database_SQLiteCommon.h" +#include "android_util_Log.h" namespace android { +// Limit heap 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. +static const int SOFT_HEAP_LIMIT = 8 * 1024 * 1024; + + // Called each time a message is logged. static void sqliteLogCallback(void* data, int iErrCode, const char* zMsg) { bool verboseLog = !!data; @@ -40,37 +47,41 @@ static void sqliteLogCallback(void* data, int iErrCode, const char* zMsg) { } // Sets the global SQLite configuration. -// This must be called before any other SQLite functions are called. */ -static void nativeConfig(JNIEnv* env, jclass clazz, jboolean verboseLog, jint softHeapLimit) { +// This must be called before any other SQLite functions are called. +static void sqliteInitialize() { // Enable multi-threaded mode. In this mode, SQLite is safe to use by multiple // threads as long as no two threads use the same database connection at the same // time (which we guarantee in the SQLite database wrappers). sqlite3_config(SQLITE_CONFIG_MULTITHREAD); // Redirect SQLite log messages to the Android log. + bool verboseLog = android_util_Log_isVerboseLogEnabled(SQLITE_LOG_TAG); sqlite3_config(SQLITE_CONFIG_LOG, &sqliteLogCallback, verboseLog ? (void*)1 : NULL); // The soft heap limit prevents the page cache allocations from growing // beyond the given limit, no matter what the max page cache sizes are // set to. The limit does not, as of 3.5.0, affect any other allocations. - sqlite3_soft_heap_limit(softHeapLimit); + sqlite3_soft_heap_limit(SOFT_HEAP_LIMIT); + + // Initialize SQLite. + sqlite3_initialize(); } -static jint nativeReleaseMemory(JNIEnv* env, jclass clazz, jint bytesToFree) { - return sqlite3_release_memory(bytesToFree); +static jint nativeReleaseMemory(JNIEnv* env, jclass clazz) { + return sqlite3_release_memory(SOFT_HEAP_LIMIT); } static JNINativeMethod sMethods[] = { /* name, signature, funcPtr */ - { "nativeConfig", "(ZI)V", - (void*)nativeConfig }, - { "nativeReleaseMemory", "(I)I", + { "nativeReleaseMemory", "()I", (void*)nativeReleaseMemory }, }; int register_android_database_SQLiteGlobal(JNIEnv *env) { + sqliteInitialize(); + return AndroidRuntime::registerNativeMethods(env, "android/database/sqlite/SQLiteGlobal", sMethods, NELEM(sMethods)); } |