History log of /frameworks/base/core/java/android/util/LruCache.java
Revision Date Author Comments (<<< Hide modified files) (Show modified files >>>)
a1226a7a8a9923fb230ca5657c249aa4f7fdbe43 20-Feb-2014 Narayan Kamath <narayan@google.com> Make LruCache.resize(int) public

bug: https://code.google.com/p/android/issues/detail?id=65062
bug: https://code.google.com/p/android/issues/detail?id=35349
Change-Id: Ia271bc45ba2b4c0f81b61b6147be5530ee2dfd67
/frameworks/base/core/java/android/util/LruCache.java
d96b585f5c40ee0d1232630ac0124d4610341577 28-Jul-2012 Jeff Sharkey <jsharkey@android.com> Add trimToSize() to public API.

Bug: 6602490
Bug: http://code.google.com/p/android/issues/detail?id=35349
Change-Id: Ib3bc7fee05bb0edc375ebee1c40a1d7bd82e2a17
/frameworks/base/core/java/android/util/LruCache.java
e5360fbf3efe85427f7e7f59afe7bbeddb4949ac 01-Nov-2011 Jeff Brown <jeffbrown@google.com> Rewrite SQLite database wrappers.

The main theme of this change is encapsulation. This change
preserves all existing functionality but the implementation
is now much cleaner.

Instead of a "database lock", access to the database is treated
as a resource acquisition problem. If a thread's owns a database
connection, then it can access the database; otherwise, it must
acquire a database connection first, and potentially wait for other
threads to give up theirs. The SQLiteConnectionPool encapsulates
the details of how connections are created, configured, acquired,
released and disposed.

One new feature is that SQLiteConnectionPool can make scheduling
decisions about which thread should next acquire a database
connection when there is contention among threads. The factors
considered include wait queue ordering (fairness among peers),
whether the connection is needed for an interactive operation
(unfairness on behalf of the UI), and whether the primary connection
is needed or if any old connection will do. Thus one goal of the
new SQLiteConnectionPool is to improve the utilization of
database connections.

To emulate some quirks of the old "database lock," we introduce
the concept of the primary database connection. The primary
database connection is the one that is typically used to perform
write operations to the database. When a thread holds the primary
database connection, it effectively prevents other threads from
modifying the database (although they can still read). What's
more, those threads will block when they try to acquire the primary
connection, which provides the same kind of mutual exclusion
features that the old "database lock" had. (In truth, we
probably don't need to be requiring use of the primary database
connection in as many places as we do now, but we can seek to refine
that behavior in future patches.)

Another significant change is that native sqlite3_stmt objects
(prepared statements) are fully encapsulated by the SQLiteConnection
object that owns them. This ensures that the connection can
finalize (destroy) all extant statements that belong to a database
connection when the connection is closed. (In the original code,
this was very complicated because the sqlite3_stmt objects were
managed by SQLiteCompiledSql objects which had different lifetime
from the original SQLiteDatabase that created them. Worse, the
SQLiteCompiledSql finalizer method couldn't actually destroy the
sqlite3_stmt objects because it ran on the finalizer thread and
therefore could not guarantee that it could acquire the database
lock in order to do the work. This resulted in some rather
tortured logic involving a list of pending finalizable statements
and a high change of deadlocks or leaks.)

Because sqlite3_stmt objects never escape the confines of the
SQLiteConnection that owns them, we can also greatly simplify
the design of the SQLiteProgram, SQLiteQuery and SQLiteStatement
objects. They no longer have to wrangle a native sqlite3_stmt
object pointer and manage its lifecycle. So now all they do
is hold bind arguments and provide a fancy API.

All of the JNI glue related to managing database connections
and performing transactions is now bound to SQLiteConnection
(rather than being scattered everywhere). This makes sense because
SQLiteConnection owns the native sqlite3 object, so it is the
only class in the system that can interact with the native
SQLite database directly. Encapsulation for the win.

One particularly tricky part of this change is managing the
ownership of SQLiteConnection objects. At any given time,
a SQLiteConnection is either owned by a SQLiteConnectionPool
or by a SQLiteSession. SQLiteConnections should never be leaked,
but we handle that case too (and yell about it with CloseGuard).

A SQLiteSession object is responsible for acquiring and releasing
a SQLiteConnection object on behalf of a single thread as needed.
For example, the session acquires a connection when a transaction
begins and releases it when finished. If the session cannot
acquire a connection immediately, then the requested operation
blocks until a connection becomes available.

SQLiteSessions are thread-local. A SQLiteDatabase assigns a
distinct session to each thread that performs database operations.
This is very very important. First, it prevents two threads
from trying to use the same SQLiteConnection at the same time
(because two threads can't share the same session).
Second, it prevents a single thread from trying to acquire two
SQLiteConnections simultaneously from the same database (because
a single thread can't have two sessions for the same database which,
in addition to being greedy, could result in a deadlock).

There is strict layering between the various database objects,
objects at lower layers are not aware of objects at higher layers.
Moreover, objects at higher layers generally own objects at lower
layers and are responsible for ensuring they are properly disposed
when no longer needed (good for the environment).

API layer: SQLiteDatabase, SQLiteProgram, SQLiteQuery, SQLiteStatement.
Session layer: SQLiteSession.
Connection layer: SQLiteConnectionPool, SQLiteConnection.
Native layer: JNI glue.

By avoiding cyclic dependencies between layers, we make the
architecture much more intelligible, maintainable and robust.

Finally, this change adds a great deal of new debugging information.
It is now possible to view a list of the most recent database
operations including how long they took to run using
"adb shell dumpsys dbinfo". (Because most of the interesting
work happens in SQLiteConnection, it is easy to add debugging
instrumentation to track all database operations in one place.)

Change-Id: Iffb4ce72d8bcf20b4e087d911da6aa84d2f15297
/frameworks/base/core/java/android/util/LruCache.java
02db1b6c0081fe442534c8955c0c927c9ddccd46 17-Nov-2011 Jesse Wilson <jessewilson@google.com> Add a link from LruCache to the Android support package (compatibility library).

Change-Id: Ibd16410856cd8a0a991b4a403fedd9ac4e1ecaad
/frameworks/base/core/java/android/util/LruCache.java
a460c1871e594b8fc68f41f2694c04dd619032c5 16-Mar-2011 Jesse Wilson <jessewilson@google.com> Fix a bogus comment on LruCache.hitCount()

Change-Id: I219b65bd73b85a414c21d4c4abe59296c9c5945a
/frameworks/base/core/java/android/util/LruCache.java
c4e6209c5294da5cbca75eafd0ba5d4c3ed9a5b1 26-Feb-2011 Jesse Wilson <jessewilson@google.com> Remove deprecated and unused entryEvicted method.

Change-Id: Id2ac0913968099eb0c8dfa762b87082ba6bd9cd9
http://b/3461302
/frameworks/base/core/java/android/util/LruCache.java
7db1b40a03ff04ac8b49b3b53839b3c5d1c6f16a 26-Feb-2011 Jesse Wilson <jessewilson@google.com> Callback on any removal, not just evictions.

Don't hold locks while running create or remove callbacks. That gets a bit
ugly because it means a create could be unwanted by the time it returns.

Change-Id: I14b2b3ed41a446750f8ee5a7e35cb8d801c4ce6d
http://b/3461302
/frameworks/base/core/java/android/util/LruCache.java
56b6ad3e28f9f86fb3186c96ddd8754e190afdf0 11-Feb-2011 Jesse Wilson <jessewilson@google.com> Add a new method, LruCache.remove

Change-Id: Iae78a2ed4d719d4f14a4677ecb6fe5bc823bb660
http://b/3184897
/frameworks/base/core/java/android/util/LruCache.java
dfe515e49ae8a0275012b56a4a79d2dfcc017db2 11-Feb-2011 Jesse Wilson <jessewilson@google.com> Remove LruCache.setMaxSize().

Dynamically changing a max cache size is clumsy; almost everyone
should set this when they create the cache.

Fix SQLiteDatabase to copy entries into a new cache when the size
is changed. In pratice this will always be immediately after the
SQLiteDatabase is created. Since the cache field is no longer
final, change the guard on the cache field to the SQLiteDatabase
instance itself.

Change-Id: I4e325f06edc551636723568a52770c0982e2d945
/frameworks/base/core/java/android/util/LruCache.java
c2c9a2492cc99e20d23d2d92df061f35a8b14304 11-Feb-2011 Jesse Wilson <jessewilson@google.com> Don't add setMaxSize() to the LruCache API. But do add maxSize().

Change-Id: I9697ab29491dabe85c2400defdde16b9abcd003a
/frameworks/base/core/java/android/util/LruCache.java
9b5a93550f3853b229ae9cfb5f6cf33091478023 10-Feb-2011 Jesse Wilson <jessewilson@google.com> Adopt LRU cache in SQLite.

Change-Id: I6b43dd8843d41726254bea3a175fe28f5f061ed7
http://b/3184897
/frameworks/base/core/java/android/util/LruCache.java
34895b09db3679c7d4e80d21198847d316e6b0c3 10-Feb-2011 Jesse Wilson <jessewilson@google.com> Document that LruCache is threadsafe.

Change-Id: Iae1421b8c768000e56806f6cd74aef7c69a78973
http://b/3184897
/frameworks/base/core/java/android/util/LruCache.java
543146a82b87b33973743cbd1880e899ebba30f5 08-Feb-2011 Jesse Wilson <jessewilson@google.com> Remove @Override that chokes Doclava.

Change-Id: I160aa2209d148c48f4ab8f4dc42ab77d300919de
/frameworks/base/core/java/android/util/LruCache.java
e2c1f4a0ee026e7a2a15d198dc3be4529896e9f6 07-Feb-2011 Jesse Wilson <jessewilson@google.com> New LRU cache class.

Change-Id: I0e6ea1e489c684b876aebd5857c6f16a21048a8d
http://b/3184897
/frameworks/base/core/java/android/util/LruCache.java