diff options
author | Serban Constantinescu <serban.constantinescu@arm.com> | 2013-10-03 16:56:48 +0100 |
---|---|---|
committer | Steve Kondik <shade@chemlab.org> | 2013-12-20 15:32:49 -0800 |
commit | 177fb5ad85309640e7ce1336207aea2faa47612f (patch) | |
tree | 5b1f3af60c035e95b6fcaacadb3ffd0675886e5d /vm | |
parent | ddfbe106bb9c2b6c51ec1d9bc4070710cba65582 (diff) | |
download | android_dalvik-177fb5ad85309640e7ce1336207aea2faa47612f.tar.gz android_dalvik-177fb5ad85309640e7ce1336207aea2faa47612f.tar.bz2 android_dalvik-177fb5ad85309640e7ce1336207aea2faa47612f.zip |
Dalvik: Ensure that the array length complies with the final specifier
JSR-133, which Android 4 should comply with, "final" fields should be
visible to all threads at the time the constructor exits, regardless of
synchronization. This behaviour should also apply to the array lengths
as they are regarded as equivalent in behaviour to "final" fields.
Non-final fields require explicit synchronization in Java for them to be
accessed correctly.
The Dalvik VM in Android ensures constructors for ordinary object behave
properly by inserting a memory barrier ("DMB") on their return if the
object's class has a "final" field.
The issue, however, is that while Dalivk inserts a barrier in
constructors, it doesn't during array create. A barrier ought to be
inserted in order to ensure an array's length is visible when the array
itself can be observed by other threads.
In order for Dalvik to be correct in respect to JSR-133 and the ARM
memory model, it should be modified to have a memory barrier after an
array is allocated and initialized, before it is visible to other
threads.
Change-Id: I329656139264552bbd7cacd8c743b694ee2e0bb8
Signed-off-by: Stuart Monteith <Stuart.Monteith@arm.com>
Signed-off-by: Serban Constantinescu <serban.constantinescu@arm.com>
Diffstat (limited to 'vm')
-rw-r--r-- | vm/oo/Array.cpp | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/vm/oo/Array.cpp b/vm/oo/Array.cpp index ce4a5e2ca..bcce31241 100644 --- a/vm/oo/Array.cpp +++ b/vm/oo/Array.cpp @@ -59,6 +59,7 @@ static ArrayObject* allocArray(ClassObject* arrayClass, size_t length, if (newArray != NULL) { DVM_OBJECT_INIT(newArray, arrayClass); newArray->length = length; + ANDROID_MEMBAR_STORE(); dvmTrackAllocation(arrayClass, totalSize); // Add barrier to force all metadata writes to main memory to complete ANDROID_MEMBAR_FULL(); |