summaryrefslogtreecommitdiffstats
path: root/vm/DvmDex.h
diff options
context:
space:
mode:
authorAndy McFadden <fadden@android.com>2010-06-28 16:21:20 -0700
committerAndy McFadden <fadden@android.com>2010-06-30 07:48:17 -0700
commitfb119e6cf8b47d53f024cae889487a17eacbf19f (patch)
treebedc7bd8b86ee86a4a22f1b7a8d5b3ec0a5106ab /vm/DvmDex.h
parent36b125993fdd80d20f1d00dfac931102d446e65c (diff)
downloadandroid_dalvik-fb119e6cf8b47d53f024cae889487a17eacbf19f.tar.gz
android_dalvik-fb119e6cf8b47d53f024cae889487a17eacbf19f.tar.bz2
android_dalvik-fb119e6cf8b47d53f024cae889487a17eacbf19f.zip
Emit volatile field access instructions.
Easier said than done. The trick is that we need to ensure that the instruction replacement happens even if the verifier and optimizer are not enabled in dexopt. We're currently doing the -wide-volatile replacement during verification, but that's not so great, since we collapse things like iget-byte and iget-char into a single iget-volatile, losing the field width. We could recover it from the field declaration, but doing it during verification is really just sort of wrong to begin with. The substitution isn't technically an "optimization", but it's easiest to do it during the opt pass, and we already have a convenient "is optimized" flag that helps ensure that we do the replacement pass exactly once. Optimizing at run time means making a private copy of shared pages, because the pages are mapped shared/read-only out of the DEX file. We could use up a lot of physical memory if we applied all possible optimizations, so we need a notion of "essential" and "non-essential" optimizations. If we're not running in dexopt, we only do the essential ones, which should leave most methods untouched. Replacement of 32-bit instructions is only strictly necessary when we're building for SMP. On a uniprocessor, the 32-bit operations are inherently atomic, and memory barriers aren't required. However, the JIT may benefit from having volatile accesses identified by opcode. Since the current branch doesn't support any SMP products, I'm enabling the instruction generation for all platforms so that we can give it some exercise. While making this change I noticed that the exclusion mechanism for breakpoints and optimization/verification was only serving to avoid a data race (e.g. breakpoint being overwritten by an instruction rewrite). It wasn't guaranteed to prevent races when two threads toggled pages between read-write and read-only while making an update, since a 4K page can hold code for more than one class. This has been corrected by adding a mutex. This change: - Introduces the notion of essential vs. non-essential optimizations. - Adds generation of 32-bit *-volatile instructions for all platforms. - Moves generation of *-wide-volatile from the verifier to the optimizer. - Allows the optimizer to modify code at run time. - Tweaks optimizeMethod() for "best effort" rather than "fail early". - Adds a DEX-granularity mutex to the bytecode update functions. This also begins the removal of PROFILE_FIELD_ACCESS, which hasn't been used for much and is mostly just in the way. Change-Id: I4ac9fa5e1ac5f9a1d106c662c3deee90d62895aa
Diffstat (limited to 'vm/DvmDex.h')
-rw-r--r--vm/DvmDex.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/vm/DvmDex.h b/vm/DvmDex.h
index 9f3903aee..803be1f00 100644
--- a/vm/DvmDex.h
+++ b/vm/DvmDex.h
@@ -59,6 +59,9 @@ typedef struct DvmDex {
/* shared memory region with file contents */
MemMapping memMap;
+
+ /* lock ensuring mutual exclusion during updates */
+ pthread_mutex_t modLock;
} DvmDex;