I am working on Android projects that are associated with many concurrent programs, and I am going to implement some custom materials for interaction between threads (one of java.util.concurent is not suitable for my purposes).
Concurrent programming is not easy in general, but with Dalvik it seems even more complicated. To get the correct code, you need to know some specific things and that where the problem arises with Dalvik. I just can't find the detailed documentation for Dalvik VM. Most Android resources (even developer.android.com are focused on the platform API and do not provide any in-depth information about some non-trivial (or low-level) things).
For example, to which editor of the Java language specification does Dalvik VM correspond? Depending on the response, the handling of volatile variables is different and affects any parallel code that uses volatile variables.
There are already some related questions:
- Is the Dalvik memory model the same as Java?
- Double lock check in Android
and some fadden answers are very useful, but I still want to get a more detailed and complete understanding of the issue at hand.
So, under the raw questions that interest me (I will update the list if necessary when the answers to previous questions come):
- Where can I find detailed information about the Dalvik VM that can provide answers to the questions below?
- Which edition of the Java language specification does Dalvik VM comply with?
- If the answer to (2) is the “third edition”, then how complete is the support for the Dalviks Java Memory Model in this specification? And especially, how full is the support for the semantics of
volatile variables? In the Double Lock Check in Android fadden, specify the following comment:
Yeah. With the addition of the “volatile” keyword, this will work on uniprocessor (all versions of Android) and SMP (3.0 “cell” and later)
Does this mean that the Samsung Galaxy SII , which has a dual-core processor, but only Android 2.3, can execute parallel code incorrectly? (Of course, Galaxy is just an example, a question about any multi-core device with a platform up to Android 3.0)
Is the Dalvik memory model the same as Java? fadden provides an answer with the following sentence:
Dalvik version is currently not true for JSR-133
Does this mean that any existing correct parallel Java code may not work correctly on any version of Android released prior to the date of publication of this comment?
Update # 1: reply to @gnat comment (too long for comment)
@gnat leave a comment:
@Alexey Dalvik does not match any JLS release because matching requires a JCK transfer, which is not an option for Dalvik. Does this mean that you can’t even use the standard Java compiler, since it complies with the standard specification? does it matter? if so, how?
Well, my question was somehow controversial. I actually meant that JLS are not only rules for implementing Java compilers, but also implicit recommendations for any JVM implementations. Indeed, JLS, for example, claims that reading and writing certain types are atomic operations. This is not very interesting for the compiler, because the read / write is translated into just one operation code. But for any JVM implementation, it is very important to correctly implement these opcodes. Now you have to understand what I'm talking about. Although Dalvik accepts and executes programs compiled with the standard Java compiler, there is no guarantee that they will execute correctly (as expected) just because no one (except maybe Dalvik developers) knows if all the JLS functions used in program, Dalvik.
It's clear that JCK is not an option for Dalvik, and that's fine, but programmers really need to know which JLS functions they can rely on when they execute their Dalvik code. But in the documentation there are no words about it. Although you can expect the simplest operators like =, +, -, *, etc. What do you expect about nontrivial functions, such as the semantics of volatile variables (which differs in the 2nd and 3rd releases of JLS)? And the last - these are not the most non-trivial things that you can find in JLS and especially in the Java Memory Model.