Loading core/java/android/database/CursorWindow.java +10 −2 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package android.database; import android.content.res.Resources; import android.database.sqlite.SQLiteClosable; import android.os.IBinder; import android.os.Parcel; Loading @@ -25,6 +26,13 @@ import android.os.Parcelable; * A buffer containing multiple cursor rows. */ public class CursorWindow extends SQLiteClosable implements Parcelable { /** The cursor window size. resource xml file specifies the value in kB. * convert it to bytes here by multiplying with 1024. */ private static final int sCursorWindowSize = Resources.getSystem().getInteger( com.android.internal.R.integer.config_cursorWindowSize) * 1024; /** The pointer to the native window class */ @SuppressWarnings("unused") private int nWindow; Loading @@ -38,7 +46,7 @@ public class CursorWindow extends SQLiteClosable implements Parcelable { */ public CursorWindow(boolean localWindow) { mStartPos = 0; native_init(localWindow); native_init(sCursorWindowSize, localWindow); } /** Loading Loading @@ -574,7 +582,7 @@ public class CursorWindow extends SQLiteClosable implements Parcelable { private native IBinder native_getBinder(); /** Does the native side initialization for an empty window */ private native void native_init(boolean localOnly); private native void native_init(int cursorWindowSize, boolean localOnly); /** Does the native side initialization with an existing binder from another process */ private native void native_init(IBinder nativeBinder); Loading core/java/android/database/sqlite/SQLiteDatabase.java +16 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package android.database.sqlite; import android.app.AppGlobals; import android.content.ContentValues; import android.content.res.Resources; import android.database.Cursor; import android.database.DatabaseErrorHandler; import android.database.DatabaseUtils; Loading Loading @@ -1963,6 +1964,15 @@ public class SQLiteDatabase extends SQLiteClosable { // If the caller sets errorHandler = null, then use default errorhandler. mErrorHandler = (errorHandler == null) ? new DefaultDatabaseErrorHandler() : errorHandler; mConnectionNum = connectionNum; /* sqlite soft heap limit http://www.sqlite.org/c3ref/soft_heap_limit64.html * set it to 4 times the default cursor window size. * TODO what is an appropriate value, considring the WAL feature which could burn * a lot of memory with many connections to the database. needs testing to figure out * optimal value for this. */ int limit = Resources.getSystem().getInteger( com.android.internal.R.integer.config_cursorWindowSize) * 1024 * 4; native_setSqliteSoftHeapLimit(limit); } /** Loading Loading @@ -2670,4 +2680,10 @@ public class SQLiteDatabase extends SQLiteClosable { * @param statementId statement to be finzlied by sqlite */ private final native void native_finalize(int statementId); /** * set sqlite soft heap limit * http://www.sqlite.org/c3ref/soft_heap_limit64.html */ private native void native_setSqliteSoftHeapLimit(int softHeapLimit); } core/jni/android_database_CursorWindow.cpp +4 −3 Original line number Diff line number Diff line Loading @@ -50,13 +50,14 @@ CursorWindow * get_window_from_object(JNIEnv * env, jobject javaWindow) return GET_WINDOW(env, javaWindow); } static void native_init_empty(JNIEnv * env, jobject object, jboolean localOnly) static void native_init_empty(JNIEnv * env, jobject object, jint cursorWindowSize, jboolean localOnly) { uint8_t * data; size_t size; CursorWindow * window; window = new CursorWindow(MAX_WINDOW_SIZE); window = new CursorWindow(cursorWindowSize); if (!window) { jniThrowException(env, "java/lang/RuntimeException", "No memory for native window object"); return; Loading Loading @@ -614,7 +615,7 @@ static jint getType_native(JNIEnv* env, jobject object, jint row, jint column) static JNINativeMethod sMethods[] = { /* name, signature, funcPtr */ {"native_init", "(Z)V", (void *)native_init_empty}, {"native_init", "(IZ)V", (void *)native_init_empty}, {"native_init", "(Landroid/os/IBinder;)V", (void *)native_init_memory}, {"native_getBinder", "()Landroid/os/IBinder;", (void *)native_getBinder}, {"native_clear", "()V", (void *)native_clear}, Loading core/jni/android_database_SQLiteDatabase.cpp +8 −3 Original line number Diff line number Diff line Loading @@ -46,7 +46,6 @@ #define UTF16_STORAGE 0 #define INVALID_VERSION -1 #define SQLITE_SOFT_HEAP_LIMIT (4 * 1024 * 1024) #define ANDROID_TABLE "android_metadata" /* uncomment the next line to force-enable logging of all statements */ // #define DB_LOG_STATEMENTS Loading @@ -66,6 +65,7 @@ enum { static jfieldID offset_db_handle; static jmethodID method_custom_function_callback; static jclass string_class = NULL; static jint sSqliteSoftHeapLimit = 0; static char *createStr(const char *path, short extra) { int len = strlen(path) + extra; Loading Loading @@ -129,7 +129,7 @@ static void dbopen(JNIEnv* env, jobject object, jstring pathString, jint flags) // 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(SQLITE_SOFT_HEAP_LIMIT); sqlite3_soft_heap_limit(sSqliteSoftHeapLimit); // Set the default busy handler to retry for 1000ms and then return SQLITE_BUSY err = sqlite3_busy_timeout(handle, 1000 /* ms */); Loading Loading @@ -379,10 +379,14 @@ done: if (meta != NULL) sqlite3_free_table(meta); } static void native_setSqliteSoftHeapLimit(JNIEnv* env, jobject clazz, jint limit) { sSqliteSoftHeapLimit = limit; } static jint native_releaseMemory(JNIEnv *env, jobject clazz) { // Attempt to release as much memory from the return sqlite3_release_memory(SQLITE_SOFT_HEAP_LIMIT); return sqlite3_release_memory(sSqliteSoftHeapLimit); } static void native_finalize(JNIEnv* env, jobject object, jint statementId) Loading Loading @@ -466,6 +470,7 @@ static JNINativeMethod sMethods[] = {"enableSqlProfiling", "(Ljava/lang/String;S)V", (void *)enableSqlProfiling}, {"native_setLocale", "(Ljava/lang/String;I)V", (void *)native_setLocale}, {"native_getDbLookaside", "()I", (void *)native_getDbLookaside}, {"native_setSqliteSoftHeapLimit", "(I)V", (void *)native_setSqliteSoftHeapLimit}, {"releaseMemory", "()I", (void *)native_releaseMemory}, {"native_finalize", "(I)V", (void *)native_finalize}, {"native_addCustomFunction", Loading core/res/res/values/config.xml +3 −0 Original line number Diff line number Diff line Loading @@ -515,4 +515,7 @@ Build.MODEL. The format string shall not be escaped. --> <string name="config_useragentprofile_url"></string> <!-- When a database query is executed, the results retuned are paginated in pages of size (in KB) indicated by this value --> <integer name="config_cursorWindowSize">2048</integer> </resources> Loading
core/java/android/database/CursorWindow.java +10 −2 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package android.database; import android.content.res.Resources; import android.database.sqlite.SQLiteClosable; import android.os.IBinder; import android.os.Parcel; Loading @@ -25,6 +26,13 @@ import android.os.Parcelable; * A buffer containing multiple cursor rows. */ public class CursorWindow extends SQLiteClosable implements Parcelable { /** The cursor window size. resource xml file specifies the value in kB. * convert it to bytes here by multiplying with 1024. */ private static final int sCursorWindowSize = Resources.getSystem().getInteger( com.android.internal.R.integer.config_cursorWindowSize) * 1024; /** The pointer to the native window class */ @SuppressWarnings("unused") private int nWindow; Loading @@ -38,7 +46,7 @@ public class CursorWindow extends SQLiteClosable implements Parcelable { */ public CursorWindow(boolean localWindow) { mStartPos = 0; native_init(localWindow); native_init(sCursorWindowSize, localWindow); } /** Loading Loading @@ -574,7 +582,7 @@ public class CursorWindow extends SQLiteClosable implements Parcelable { private native IBinder native_getBinder(); /** Does the native side initialization for an empty window */ private native void native_init(boolean localOnly); private native void native_init(int cursorWindowSize, boolean localOnly); /** Does the native side initialization with an existing binder from another process */ private native void native_init(IBinder nativeBinder); Loading
core/java/android/database/sqlite/SQLiteDatabase.java +16 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package android.database.sqlite; import android.app.AppGlobals; import android.content.ContentValues; import android.content.res.Resources; import android.database.Cursor; import android.database.DatabaseErrorHandler; import android.database.DatabaseUtils; Loading Loading @@ -1963,6 +1964,15 @@ public class SQLiteDatabase extends SQLiteClosable { // If the caller sets errorHandler = null, then use default errorhandler. mErrorHandler = (errorHandler == null) ? new DefaultDatabaseErrorHandler() : errorHandler; mConnectionNum = connectionNum; /* sqlite soft heap limit http://www.sqlite.org/c3ref/soft_heap_limit64.html * set it to 4 times the default cursor window size. * TODO what is an appropriate value, considring the WAL feature which could burn * a lot of memory with many connections to the database. needs testing to figure out * optimal value for this. */ int limit = Resources.getSystem().getInteger( com.android.internal.R.integer.config_cursorWindowSize) * 1024 * 4; native_setSqliteSoftHeapLimit(limit); } /** Loading Loading @@ -2670,4 +2680,10 @@ public class SQLiteDatabase extends SQLiteClosable { * @param statementId statement to be finzlied by sqlite */ private final native void native_finalize(int statementId); /** * set sqlite soft heap limit * http://www.sqlite.org/c3ref/soft_heap_limit64.html */ private native void native_setSqliteSoftHeapLimit(int softHeapLimit); }
core/jni/android_database_CursorWindow.cpp +4 −3 Original line number Diff line number Diff line Loading @@ -50,13 +50,14 @@ CursorWindow * get_window_from_object(JNIEnv * env, jobject javaWindow) return GET_WINDOW(env, javaWindow); } static void native_init_empty(JNIEnv * env, jobject object, jboolean localOnly) static void native_init_empty(JNIEnv * env, jobject object, jint cursorWindowSize, jboolean localOnly) { uint8_t * data; size_t size; CursorWindow * window; window = new CursorWindow(MAX_WINDOW_SIZE); window = new CursorWindow(cursorWindowSize); if (!window) { jniThrowException(env, "java/lang/RuntimeException", "No memory for native window object"); return; Loading Loading @@ -614,7 +615,7 @@ static jint getType_native(JNIEnv* env, jobject object, jint row, jint column) static JNINativeMethod sMethods[] = { /* name, signature, funcPtr */ {"native_init", "(Z)V", (void *)native_init_empty}, {"native_init", "(IZ)V", (void *)native_init_empty}, {"native_init", "(Landroid/os/IBinder;)V", (void *)native_init_memory}, {"native_getBinder", "()Landroid/os/IBinder;", (void *)native_getBinder}, {"native_clear", "()V", (void *)native_clear}, Loading
core/jni/android_database_SQLiteDatabase.cpp +8 −3 Original line number Diff line number Diff line Loading @@ -46,7 +46,6 @@ #define UTF16_STORAGE 0 #define INVALID_VERSION -1 #define SQLITE_SOFT_HEAP_LIMIT (4 * 1024 * 1024) #define ANDROID_TABLE "android_metadata" /* uncomment the next line to force-enable logging of all statements */ // #define DB_LOG_STATEMENTS Loading @@ -66,6 +65,7 @@ enum { static jfieldID offset_db_handle; static jmethodID method_custom_function_callback; static jclass string_class = NULL; static jint sSqliteSoftHeapLimit = 0; static char *createStr(const char *path, short extra) { int len = strlen(path) + extra; Loading Loading @@ -129,7 +129,7 @@ static void dbopen(JNIEnv* env, jobject object, jstring pathString, jint flags) // 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(SQLITE_SOFT_HEAP_LIMIT); sqlite3_soft_heap_limit(sSqliteSoftHeapLimit); // Set the default busy handler to retry for 1000ms and then return SQLITE_BUSY err = sqlite3_busy_timeout(handle, 1000 /* ms */); Loading Loading @@ -379,10 +379,14 @@ done: if (meta != NULL) sqlite3_free_table(meta); } static void native_setSqliteSoftHeapLimit(JNIEnv* env, jobject clazz, jint limit) { sSqliteSoftHeapLimit = limit; } static jint native_releaseMemory(JNIEnv *env, jobject clazz) { // Attempt to release as much memory from the return sqlite3_release_memory(SQLITE_SOFT_HEAP_LIMIT); return sqlite3_release_memory(sSqliteSoftHeapLimit); } static void native_finalize(JNIEnv* env, jobject object, jint statementId) Loading Loading @@ -466,6 +470,7 @@ static JNINativeMethod sMethods[] = {"enableSqlProfiling", "(Ljava/lang/String;S)V", (void *)enableSqlProfiling}, {"native_setLocale", "(Ljava/lang/String;I)V", (void *)native_setLocale}, {"native_getDbLookaside", "()I", (void *)native_getDbLookaside}, {"native_setSqliteSoftHeapLimit", "(I)V", (void *)native_setSqliteSoftHeapLimit}, {"releaseMemory", "()I", (void *)native_releaseMemory}, {"native_finalize", "(I)V", (void *)native_finalize}, {"native_addCustomFunction", Loading
core/res/res/values/config.xml +3 −0 Original line number Diff line number Diff line Loading @@ -515,4 +515,7 @@ Build.MODEL. The format string shall not be escaped. --> <string name="config_useragentprofile_url"></string> <!-- When a database query is executed, the results retuned are paginated in pages of size (in KB) indicated by this value --> <integer name="config_cursorWindowSize">2048</integer> </resources>