Ernest Friedman-Hill wrote:The memory allocator is a core part of the JVM implementation; "new" is a bytecode instruction (actually, there are several of them for different kinds of object and array allocation) and as such, it's going to be written in the implementation language of the JVM, not Java. If it were written in Java, it would have to be runnning on a higher-level "meta-JVM" which invoked it. IBM had a research JVM written in Java; it of course ran on such a "meta-JVM".
"new" never just maps to the platform-native "new" operator of C++. The JVM needs to manage the heap much more closely than that arrangement would allow. Instead, the JVM grabs huge chunks of memory from the platform, and then divides it up into individual objects by itself.
EFH: Thank you very much! I never thought about OPCODEs until you mentioned. I thought "new" of Java mapped to "new" of C++.
thanks again!
@CR: IMO, this is still a Java question
I mentioned Android only because Jesper said the behavior was dependent on the implementation of the JVM; Android uses a Dalvik Virtual machine which is different from the JVMs that comes with the JDK.
I got my answer eitherways; thank you very much!