Can anyone interpret this C++ code (from OpenJDK6) into plain English?

拈花ヽ惹草 提交于 2019-12-05 16:51:12

It is a JNI wrapper for the CAS API, with memory barriers for IA64 architecture.

edit: for a description of CAS:

Compare dest with compare value and if they match assign exchange value to dest.

It is an atomic operation which means no other processor can change the value of dest whilst the operation executes.

Typical problems that can occur without atomic operations are listed here, the "ABA problem"

http://en.wikipedia.org/wiki/ABA_problem

Why would you use a CAS function?

Easy example is a counter, if you have multiple threads incrementing a counter consider what the increment process does:

int i;
read the value of i
add one to the current value
save the value back to i.

What happens when another processor reads the value of i and saves i + 1 before this processor has completed?

You end up with i + 1 instead of i + 2.

Here are some interprets about

  • What's an oop, and why should they be compressed?


An "oop", or "ordinary object pointer" in HotSpot parlance is a managed pointer to an object. It is normally the same size as a native machine pointer, which means 64 bits on an LP64 system. On an ILP32 system, there is a maximum heap size of somewhat less than 4Gb, which is not enough for many applications.

  • Which oops are compressed?

In an ILP32-mode JVM, or if the UseCompressedOops flag is turned off in LP64 mode, all oops are the native machine word size.

If UseCompressedOops is true, the following oops in the heap will be compressed:

•the klass field of every object •every oop instance field •every element of an oop array (objArray)

For details, looks into this sun wiki

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!