When you explicitly set the JVM’s -xx :MaxTenuringThreshold to 20, you get an Error:
java -XX:MaxTenuringThreshold=20 Test
MaxTenuringThreshold of 20 is invalid; must be between 0 and 15
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit
Copy the code
Why cannot the MaxTenuringThreshold parameter be set to 20? Why does it have to be between 0 and 15? We couldn’t even start the JVM to run our code!! Ps: If you don’t know the meaning of this parameter, please consult Baidu.
ObjectHeader32
ObjectHeader64
ObjectHeader64Coops Note: Coops is an object pointer compression technique and is beyond the scope of this article.
In both 32-bit and 64-bit machines, the age in Mark Word is only 4bits, so the maximum representation of age in base 2 is 1111, which is 15 in decimal.
You can see it here! The maximum age of the object can only be set to 15, that is, the default is to avoid 15 YGC promotions to the old age.
Run the code again to verify our conclusion:
java -XX:MaxTenuringThreshold=15 Test
// ---------------output--------------
// hello world
Copy the code
OK, successfully run the first line of code in our programmer career!!