There is a specification of Java memory model.
And I want to dive into the source code to actually investigate how those mechanisms are implemented. (e.g., synchronized, volatile, ..., etc.)
But the codebase is so huge, I have no idea where to start with.
(http://www.java2s.com/Open-Source/Java-Document/CatalogJava-Document.htm)
Could anyone give me some clues? Thanks a lot!
When Java programs run on the JVM, objects are created on the heap, which is a portion of memory dedicated to the program. Eventually, some objects will no longer be needed. The garbage collector finds these unused objects and deletes them to free up memory.
The Java Memory Model (JMM) defines the allowable behavior of multithreaded programs, and therefore describes when such reorderings are possible. It places execution-time constraints on the relationship between threads and main memory in order to achieve consistent and reliable Java applications.
Java Memory Structure: JVM defines various run time data area which are used during execution of a program. Some of the areas are created by the JVM whereas some are created by the threads that are used in a program. However, the memory area created by JVM is destroyed only when the JVM exits.
Simply put, Metaspace is a new memory space – starting from the Java 8 version; it has replaced the older PermGen memory space. The most significant difference is how it handles memory allocation. Specifically, this native memory region grows automatically by default.
You might start by looking at the synchronizer.cpp class in the current version of the JDK. Prepare yourself a strong pot of coffee-- you've picked one of the most complex areas of the JVM to start delving into the source code.
If you haven't already done so, I would also suggest that you take a look at Bill Pugh's page on the Java Memory Model and Doug Lea's recommendations for compiler writers on implementing the Java memory model.
You may also glean something from running the debug JVM with the option turned on to output the JIT-compiled assembly which you can then inspect. (This won't tell you everything, but it might give you some pointers in: I think some of the things it prints will if nothing else give you some things to search for in the JDK source code...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With