Loading core/java/android/database/sqlite/SQLiteConnection.java +0 −2 Original line number Diff line number Diff line Loading @@ -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); Loading core/java/android/database/sqlite/SQLiteDebug.java +0 −1 Original line number Diff line number Diff line Loading @@ -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; Loading core/java/android/database/sqlite/SQLiteGlobal.java +10 −32 Original line number Diff line number Diff line Loading @@ -22,44 +22,27 @@ 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. Loading @@ -67,12 +50,7 @@ public final class SQLiteGlobal { * @return The number of bytes that were freed. */ public static int releaseMemory() { synchronized (sLock) { if (!sInitialized) { return 0; } return nativeReleaseMemory(sSoftHeapLimit); } return nativeReleaseMemory(); } /** Loading core/jni/android_database_SQLiteGlobal.cpp +19 −8 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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)); } Loading core/jni/android_util_Log.cpp +24 −15 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ #include "JNIHelp.h" #include "utils/misc.h" #include "android_runtime/AndroidRuntime.h" #include "android_util_Log.h" #define MIN(a,b) ((a<b)?a:b) Loading Loading @@ -56,40 +57,48 @@ static int toLevel(const char* value) return levels.info; } static jboolean android_util_Log_isLoggable(JNIEnv* env, jobject clazz, jstring tag, jint level) { int len; char key[PROPERTY_KEY_MAX]; static jboolean isLoggable(const char* tag, jint level) { String8 key; key.append(LOG_NAMESPACE); key.append(tag); char buf[PROPERTY_VALUE_MAX]; if (property_get(key.string(), buf, "") <= 0) { return false; } int logLevel = toLevel(buf); return logLevel >= 0 && level >= logLevel; } static jboolean android_util_Log_isLoggable(JNIEnv* env, jobject clazz, jstring tag, jint level) { if (tag == NULL) { return false; } jboolean result = false; const char* chars = env->GetStringUTFChars(tag, NULL); if (!chars) { return false; } jboolean result = false; if ((strlen(chars)+sizeof(LOG_NAMESPACE)) > PROPERTY_KEY_MAX) { char buf2[200]; snprintf(buf2, sizeof(buf2), "Log tag \"%s\" exceeds limit of %d characters\n", chars, PROPERTY_KEY_MAX - sizeof(LOG_NAMESPACE)); // release the chars! env->ReleaseStringUTFChars(tag, chars); jniThrowException(env, "java/lang/IllegalArgumentException", buf2); return false; } else { strncpy(key, LOG_NAMESPACE, sizeof(LOG_NAMESPACE)-1); strcpy(key + sizeof(LOG_NAMESPACE) - 1, chars); result = isLoggable(chars, level); } env->ReleaseStringUTFChars(tag, chars); return result; } len = property_get(key, buf, ""); int logLevel = toLevel(buf); return (logLevel >= 0 && level >= logLevel) ? true : false; bool android_util_Log_isVerboseLogEnabled(const char* tag) { return isLoggable(tag, levels.verbose); } /* Loading Loading
core/java/android/database/sqlite/SQLiteConnection.java +0 −2 Original line number Diff line number Diff line Loading @@ -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); Loading
core/java/android/database/sqlite/SQLiteDebug.java +0 −1 Original line number Diff line number Diff line Loading @@ -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; Loading
core/java/android/database/sqlite/SQLiteGlobal.java +10 −32 Original line number Diff line number Diff line Loading @@ -22,44 +22,27 @@ 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. Loading @@ -67,12 +50,7 @@ public final class SQLiteGlobal { * @return The number of bytes that were freed. */ public static int releaseMemory() { synchronized (sLock) { if (!sInitialized) { return 0; } return nativeReleaseMemory(sSoftHeapLimit); } return nativeReleaseMemory(); } /** Loading
core/jni/android_database_SQLiteGlobal.cpp +19 −8 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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)); } Loading
core/jni/android_util_Log.cpp +24 −15 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ #include "JNIHelp.h" #include "utils/misc.h" #include "android_runtime/AndroidRuntime.h" #include "android_util_Log.h" #define MIN(a,b) ((a<b)?a:b) Loading Loading @@ -56,40 +57,48 @@ static int toLevel(const char* value) return levels.info; } static jboolean android_util_Log_isLoggable(JNIEnv* env, jobject clazz, jstring tag, jint level) { int len; char key[PROPERTY_KEY_MAX]; static jboolean isLoggable(const char* tag, jint level) { String8 key; key.append(LOG_NAMESPACE); key.append(tag); char buf[PROPERTY_VALUE_MAX]; if (property_get(key.string(), buf, "") <= 0) { return false; } int logLevel = toLevel(buf); return logLevel >= 0 && level >= logLevel; } static jboolean android_util_Log_isLoggable(JNIEnv* env, jobject clazz, jstring tag, jint level) { if (tag == NULL) { return false; } jboolean result = false; const char* chars = env->GetStringUTFChars(tag, NULL); if (!chars) { return false; } jboolean result = false; if ((strlen(chars)+sizeof(LOG_NAMESPACE)) > PROPERTY_KEY_MAX) { char buf2[200]; snprintf(buf2, sizeof(buf2), "Log tag \"%s\" exceeds limit of %d characters\n", chars, PROPERTY_KEY_MAX - sizeof(LOG_NAMESPACE)); // release the chars! env->ReleaseStringUTFChars(tag, chars); jniThrowException(env, "java/lang/IllegalArgumentException", buf2); return false; } else { strncpy(key, LOG_NAMESPACE, sizeof(LOG_NAMESPACE)-1); strcpy(key + sizeof(LOG_NAMESPACE) - 1, chars); result = isLoggable(chars, level); } env->ReleaseStringUTFChars(tag, chars); return result; } len = property_get(key, buf, ""); int logLevel = toLevel(buf); return (logLevel >= 0 && level >= logLevel) ? true : false; bool android_util_Log_isVerboseLogEnabled(const char* tag) { return isLoggable(tag, levels.verbose); } /* Loading