PrintGC
, PrintCompilation
, TraceClassLoading
, etc. Typically, they are included with command line options, for example, -XX:+PrintGCDetails
UnlockExperimentalVMOptions
command line UnlockExperimentalVMOptions
, for example, -XX:+UnlockExperimentalVMOptions -XX:+TrustFinalNonStaticFields
UnlockDiagnosticVMOptions
, for example, -XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly
PrintFlagsFinal
parameter: java -XX:+PrintFlagsFinal
com.sun.management:type=HotSpotDiagnostic
. import com.sun.management.HotSpotDiagnosticMXBean; import java.lang.management.ManagementFactory; import javax.management.MBeanServer; ... MBeanServer server = ManagementFactory.getPlatformMBeanServer(); HotSpotDiagnosticMXBean bean = ManagementFactory.newPlatformMXBeanProxy( server, "com.sun.management:type=HotSpotDiagnostic", HotSpotDiagnosticMXBean.class);
bean.getVMOption(String option)
will let you know the current value of the JVM option,bean.setVMOption(String option, String newValue)
- set a new one.manageable
.bean.getDiagnosticOptions()
method will return a list of all manageable
options. // JVM, ReentrantLock .. thread dump bean.setVMOption("PrintConcurrentLocks", "true");
libjvm.so
, and what address it is loaded at. This will help the proc virtual file system, in particular, the file /proc/self/maps
, which lists all regions of the virtual address space of the current process. Find in it a line ending in /libjvm.so
. 2b6707956000-2b67084b8000 r-xp 00000000 68:02 1823284 /usr/java/jdk1.7.0_40/jre/lib/amd64/server/libjvm.so
private String findJvmMaps() throws IOException { BufferedReader reader = new BufferedReader(new FileReader("/proc/self/maps")); try { for (String s; (s = reader.readLine()) != null; ) { if (s.endsWith("/libjvm.so")) { return s; } } throw new IOException("libjvm.so not found"); } finally { reader.close(); } }
libjvm.so
for reading. With the help of our open-source ELF parser, we find a symbol section in the library, where all the JVM flags are present among the symbols. Again, no hacks, just pure java. ElfReader elfReader = new ElfReader(jvmLibrary); ElfSymbolTable symtab = (ElfSymbolTable) elfReader.section(".symtab");
Unsafe.putInt
: private ElfSymbol findSymbol(String name) { for (ElfSymbol symbol : symtab) { if (name.equals(symbol.name()) && symbol.type() == ElfSymbol.STT_OBJECT) { return symbol; } } throw new NoSuchElementException("Symbol not found: " + name); } public void setIntFlag(String name, int value) { ElfSymbol symbol = findSymbol(name); unsafe.putInt(baseAddress + symbol.value(), value); } public void setBooleanFlag(String name, boolean value) { setIntFlag(name, value ? 1 : 0); }
Source: https://habr.com/ru/post/195004/
All Articles