Question about MarkOop

Viacheslav Kovalevskyi viacheslav at b0noi.com
Fri Dec 26 21:13:32 UTC 2014


Hi!

My name is Viacheslav, I’m making presentation about Java synchronization to my friends and I realized that I have some gaps in understanding of MarkOop object nature. I was not able to figure out all answers on my own from source code and documentation. If someone can help or at least point the right direction it would be awesome!

Here is link to markOop.hpp file that is representing revision of JDK (8b132) that I’m using: [1]

I’m executing stupid and simple program that shows Java object layout on screen: [2] before and during synchronization. I’m using Java Object Layout tool for this([3]).

Here are results of first 2 outputs that I see in console:

com.b0noi.java.analyzer.AnalyzerTest.Test1 object internals:
 OFFSET  SIZE  TYPE DESCRIPTION                    VALUE
      0     4       (object header)                0d 00 00 00 (0000 1101 0000 0000 0000 0000 0000 0000)
      4     4       (object header)                00 00 00 00 (0000 0000 0000 0000 0000 0000 0000 0000)
      8     4       (object header)                32 62 01 f8 (0011 0010 0110 0010 0000 0001 1111 1000)
…

com.b0noi.java.analyzerAnalyzerTest.Test1 object internals:
 OFFSET  SIZE  TYPE DESCRIPTION                    VALUE
      0     4       (object header)                0d 70 00 1a (0000 1101 0111 0000 0000 0000 0001 1010)
      4     4       (object header)                9b 7f 00 00 (1001 1011 0111 1111 0000 0000 0000 0000)
      8     4       (object header)                32 62 01 f8 (0011 0010 0110 0010 0000 0001 1111 1000)
…

My hardware:
CPU: i5 x64
RAM: 16GB

OS:
Mac OS 10.10

From what I can understand COOPS is switched of on my system. And according to the documentation in markOop file ([1]) my layout should be one from this:
        //  unused:25 hash:31 -->| unused:1   age:4    biased_lock:1 lock:2 (normal object)
        //  JavaThread*:54 epoch:2 unused:1   age:4    biased_lock:1 lock:2 (biased object)

first output of my program should represent this line (object normal, without baised):
        //  unused:25 hash:31 -->| unused:1   age:4    biased_lock:1 lock:2 (normal object)

second output of my program should represent this line (object inside synchronization block, should be baised):
        //  JavaThread*:54 epoch:2 unused:1   age:4    biased_lock:1 lock:2 (biased object)

However in both case real life values looks not as they should according to layout documentation. 

In first case (before synchronization), real life:
 OFFSET  SIZE  TYPE DESCRIPTION                    VALUE
      0     4       (object header)                0d 00 00 00 (0000 1101 0000 0000 0000 0000 0000 0000)
      4     4       (object header)                00 00 00 00 (0000 0000 0000 0000 0000 0000 0000 0000)
…
according to dict this is: 
        //  unused:25 hash:31 -->| unused:1   age:4    biased_lock:1 lock:2 (normal object)

question: why we have this strange first byte (0000 1101)? According to layout doc it should be unused, and I assume field with zeros?

Second case is even funnier, real life:
 OFFSET  SIZE  TYPE DESCRIPTION                    VALUE
      0     4       (object header)                0d 70 00 1a (0000 1101 0111 0000 0000 0000 0001 1010)
      4     4       (object header)                9b 7f 00 00 (1001 1011 0111 1111 0000 0000 0000 0000)
…
according to dict this is: 
        //  JavaThread*:54 epoch:2 unused:1   age:4    biased_lock:1 lock:2 (biased object)

question: why first byte remains the same, looks like Thread pointer was written to the different offset then it should (according to the doc). Also the first byte remains the same. Layout is totally inconsistent with documentation.

Can someone give me a hint or a direction where to dig. 

Sorry if this is a wrong mail list to ask this type of question. If this is the case, can someone point me to the right one. Thank you in advance.

Links:
[1] http://hg.openjdk.java.net/jdk8/jdk8/hotspot/file/tip/src/share/vm/oops/markOop.hpp <http://hg.openjdk.java.net/jdk8/jdk8/hotspot/file/tip/src/share/vm/oops/markOop.hpp>
[2] https://github.com/b0noI/JavaAnalyzer/blob/master/src/test/java/com/b0noi/java/analyzer/AnalyzerTest.java <https://github.com/b0noI/JavaAnalyzer/blob/master/src/test/java/com/b0noi/java/analyzer/AnalyzerTest.java>
[3] http://openjdk.java.net/projects/code-tools/jol/ <http://openjdk.java.net/projects/code-tools/jol/>

---
Viacheslav Kovalevskyi
viacheslav at b0noi.com





More information about the hotspot-runtime-dev mailing list