Trick behind JVM’s compressed Oops

For a detailed explanation of compressed oops, see the “Compressed oops in the Hotspot JVM” article by John Rose @ Oracle. The TL;DR version is: on modern computer architectures, memory addresses are byte addresses, Java object references are addresses that point to the start of a word1, on a 64-bit machine, word alignment means that … Read more

how to choose the jvm heap size?

My question is how to choose the min and max values, and the difference between the two (should max-min be small or big?) Short answer: don’t guess, profile your application. jconsole can give you useful high-level data such as a feeling for the main resident set vs. the transient data that we normally allocate and … Read more

how to retransform a class at runtime

Short Answer Don’t iterate through all the loaded classes from Instrumentation. Instead, just examine the class name passed in to the transformer and if it matches your target class, then transform it. Otherwise, simply return the passed classfileBuffer unmodified. Make the set up calls outside the transformer, (i.e. in your case, do the following from … Read more

Getting the parameters of a running JVM

You can use jps like: jps -lvm It prints something like: 4050 com.intellij.idea.Main -Xms128m -Xmx512m -XX:MaxPermSize=250m -ea -Xbootclasspath/a:../lib/boot.jar -Djb.restart.code=88 4667 sun.tools.jps.Jps -lvm -Dapplication.home=/opt/java/jdk1.6.0_22 -Xms8m

Java Memory explained (SUN JVM)

Here’s a list of resources I had noted down. Some of these explain how the heap/garbage collection works and some have details on how to configure everything. IBM How does garbage collection work? Detailed description of garbage collection Generational and concurrent garbage collection Sun Turbo-charging Java HotSpot Virtual Machine, v1.4.x to Improve the Performance and … Read more

How can I add a Javaagent to a JVM without stopping the JVM?

See Starting a Java agent after program start. It links to http://dhruba.name/2010/02/07/creation-dynamic-loading-and-instrumentation-with-javaagents/ that under “Dynamic loading of a javaagent at runtime” provides working example: public static void loadAgent() throws Exception { String nameOfRunningVM = ManagementFactory.getRuntimeMXBean().getName(); String pid = nameOfRunningVM.substring(0, nameOfRunningVM.indexOf(‘@’)); VirtualMachine vm = VirtualMachine.attach(pid); vm.loadAgent(jarFilePath, “”); vm.detach(); } Note that Java 9 requires -Djdk.attach.allowAttachSelf=true to … Read more

Release java memory for OS at runtime

I have posted my test results over there. Basically, MaxHeapFreeRatio is not respected by every GC implementation, and, to make it worse, it seems to be necessary that there is enough heap activity in order to trigger it in a timely manner, ie. could be that you require 2 full GC runs to actually release … Read more

JVM choices on Windows Mobile

JVM Choices for Windows CE in general (including Pocket PC and Windows Mobile): CrE-ME Mysaifu Skelmir CEEJ If you’re looking to have a common code base between WinMo and Symbina, you might also look at Red Five Labs. They have a Symbian runtime that allows you to run COmpact Framework apps, so you could have … Read more