From d6e32b8147f26a32059ae86abc5f8e5c0ef92ac1 Mon Sep 17 00:00:00 2001 From: Andy McFadden Date: Wed, 2 Feb 2011 16:55:41 -0800 Subject: Ensure word atomicity in System.arraycopy The VM needs to ensure that updates to 16-bit and 32-bit fields and array elements happen atomically. System.arraycopy was calling memmmove(), which in bionic happens to copy a byte at a time. The new plan is to have bionic provide a platform-optimized memmove variant that makes guarantees about word sizes. If it is not present (either because it hasn't been written for the current platform, or we're not linking against bionic), we will use a trivial copy loop. We assume that the memmove-by-word implementation does whatever it needs to for best performance. For example, if the function determines that memcpy() is word-safe and will be faster, it can call that. The VM no longer makes assumptions about the internal workings of libc functions. I also rearranged the code to avoid making indirect calls, reading function addresses from memory, and using integer multiplication instructions when a simple shift will do. (gcc now generates the whole thing as one function.) Also, added some primitive array copy tests to 011-array-copy. Bug 3398352 Change-Id: I4677ee1c87998697a93e61f39a48b3f391e8e11b --- docs/porting-guide.html | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'docs') diff --git a/docs/porting-guide.html b/docs/porting-guide.html index 3e33d13ea..9b02d176d 100644 --- a/docs/porting-guide.html +++ b/docs/porting-guide.html @@ -26,8 +26,7 @@ build system is assumed.

The native code in the core libraries (chiefly libcore, but also dalvik/vm/native) is written in C/C++ and is expected -to work without modification in a Linux environment. Much of the code -comes directly from the Apache Harmony project. +to work without modification in a Linux environment.

The core libraries pull in code from many other projects, including OpenSSL, zlib, and ICU. These will also need to be ported before the VM @@ -349,6 +348,22 @@ debugger or toggle profiling. (A future test suite may include some tests for this.)

+ +

Other Performance Issues

+ +

+The System.arraycopy() function is heavily used. The +implementation relies on the bionic C library to provide a fast, +platform-optimized data copy function for arrays with elements wider +than one byte. If you're not using bionic, or your platform does not +have an implementation of this method, Dalvik will use correct but +sub-optimal algorithms instead. For best performance you will want +to provide your own version. +

+See the comments in dalvik/vm/native/java_lang_System.c +for details. +

+

Copyright © 2009 The Android Open Source Project
-- cgit v1.2.3