E N D
The preceding is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract.It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.
Java Support Fairy Tales Misha Bykov, OracleNikita Lipsky, Excelsior LLC
Fairy Tales (Program Agenda) • Mysterious JVM Crash • Face Control • JNI Issues • Multithreading Problems • Java Specification Ignoring Consequences
Mysterious JVM Crash Hotspot Log File # A fatal error has been detected by the Java Runtime Environment: # # SIGSEGV (0xb) at pc=0xff380700, pid=583, tid=3156104 # # JRE version: 6.0_16-b01 # Java VM: Java HotSpot(TM) Server VM (14.2-b01 mixedmode) # Problematicframe: # C [libc_psr.so.1+0x700] memcpy+0x2f8
Mysterious JVM Crash What’s going on? • Is the problem in native code? • Is this issue related to any Operating System failure? • Is this a memory problem? • Could this be an issue with libc_psr.so.1? • Processor Specific Runtime • Specific Implementation of memcpy To be continued…
Face Control Issue XStream(xstream-1.1.3.jar) throws com.thoughtworks.xstream.converters.reflection. ObjectAccessException: Invalid final field xmltest.Main.theValue
Face Control Reason private boolean canUseSun14ReflectionProvider(){ return (isSun() ||isApple() ||isHPUX() ||isIBM() ||isBlackdown()) && is14() &&loadClass("sun.misc.Unsafe") != null; } No Oracle & Excelsior in the “white list“
Face Control Resolution Values for java.vm.vendor: Sun Microsystems (Oracle HotSpot for Java SE 6) Sun-Oracle Java SE licensee Excelsior LLC (Excelsior JET)
Sun Oracle Renaming • Issue: Eclipse just STOPs working with OutOfMemoryError. • Reason: COMPANY_NAME field in java.dll changed to, “Oracle Corporation”.
Mysterious JVM Crash Dig Into the Hotspot Log File Stack: [0xb0c00000,0xb0c80000], sp=0xb0c7c890, free space=498k Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code) C [libc_psr.so.1+0x700] memcpy+0x2f8 C [libzip.so+0xd19c] C [libzip.so+0x2380] ZIP_GetEntry+0xe4 C [libzip.so+0x2800] Java_java_util_zip_ZipFile_getEntry+0xc4 j java.util.zip.ZipFile.getEntry(JLjava/lang/String;Z)J+0 j java.util.zip.ZipFile.getEntry(JLjava/lang/String;Z)J+0 j java.util.zip.ZipFile.getEntry(Ljava/lang/String;)Ljava/util/zip/ZipEntry;+31 j java.util.jar.JarFile.getEntry(Ljava/lang/String;)Ljava/util/zip/ZipEntry;+2 j java.util.jar.JarFile.getJarEntry(Ljava/lang/String;)Ljava/util/jar/JarEntry;+2 ...
Mysterious JVM Crash The situation looks weird • Could this be an issue with libzip.so? • HotSpot log stack trace shows java.util.jar.JarFileusage • The user reported “no jar usage”, but JVM crashed • No one performed “jar” operations from the Java program • Why the interpreted code shows “jar” and “zip”? To be continued…
JNI Crashes Any SIGFAULT in JNI code looks like JVM Crash int* p = 0; … (*p) = 0; -> # A fatal error has been detected by the Java Runtime Environment: # # SIGSEGV (0xb) at pc=0x00007f096d096942, pid=12102, tid=139678234564352 #
JNI Misuses • Incorrect usage of JNI: • CallObjectMethod instead of CallIntMethod • Improper arguments types or/and their count • JNI local reference avoidness (loosing Java objects) • AttachCurrentThread/DetachCurrentThreadpairness • … Thumb rule: launch with –Xcheck:jni
Mysterious JVM Crash Root Cause On Solaris and Linux platforms an application might crash in java.util.zip.ZipFile'snative code if a in-use zip file is being overwritten by other part of the application and mmap is used to map the zipfile'scentral directory into the memory.
Mysterious JVM Crash Observations • This kind of use scenario (overwrite your own file is till being used by yourself) definitely is a programming error. • One of the solutions is to always make a defensive copy before open the zip/jar file or always to check the availability of the zip/jar file before each and every access. To be continued…
Multithreading Issues public static boolean changed = false; What’s wrong with this program? Does “Thread 1” stop?
Multithreading Issues public static volatile boolean changed = false; And never forget about JMM!
Deadlocks • Faster JVM can reveal (potential) deadlocks
Mysterious JVM Crash What really happened? • The user scenario was to replace jars in a JVM classpath when that JVM is still running. • This situation caused the JVM crash
Mysterious JVM Crash Recommendations • Do not upgrade Java when JVM is still running • Restart the applications for all updates to .jar files, even if the particular update doesn't touch any class actually used by the application. • When replacing the jar files try to remove them first and the copy new files to that place. • The property sun.zip.disableMemoryMapping can be used to disable the mmapping of the central directory.
Order of class members • Class.getDeclaredFields, Class.getDeclaredMethods, • Class.getDeclaredConstructors • Java specification: “…The elements in the array returned are not sorted and are not in any particular order.”
Order of class members • Who ever ignored that rule: • JNA • JBoss • Eclipse
JRE shape dependence • JVM specification does not define the JRE shape • It can be no jre/bin/java at all!
Summary • There are funny stories around JVM with technical aspects. • This session demonstrated some typical cases, which look like bugs in JVM, but are actually not. • Java support teams and users might use this knowledge in order to save time working with future customer issues.