Unexpected ArithmeticException at sun.jvm.hotspot.utilities.CompactHashTable

KUBOTA Yuji kubota.yuji at gmail.com
Fri Dec 18 06:27:35 UTC 2015


Hi all,

I caught an unexpected java.lang.ArithmeticException by CLHSDB through
jhsdb as below.

-----
./jhsdb clhsdb --pid 16809
Attaching to process 16809, please wait...
hsdb> class java/lang/ArithmeticException
java/lang/ArithmeticException @0x0000000100011958
hsdb> class java
class not found: java
hsdb> class java/lang
Error: java.lang.ArithmeticException: / by zero
-----

I think that CLHSDB returns "class not found: java/lang". But
ArithmetricException is returned instead.
CLHSDB tries to search the given class name from the regular symbol
table and the shared symbol table.
And called the probe function of the shared symbol table does not
support a case of the empty bucket such as below expression

> long index = hash % bucketCount();

then, throws ArithmetricException.

The stack trace of this java.lang.ArithmeticException is here.
------
java.lang.ArithmeticException: / by zero
        at sun.jvm.hotspot.utilities.CompactHashTable.probe(CompactHashTable.java:89)
        at sun.jvm.hotspot.memory.SymbolTable.probe(SymbolTable.java:97)
        at sun.jvm.hotspot.memory.SymbolTable.probe(SymbolTable.java:75)
        at sun.jvm.hotspot.memory.SystemDictionary.find(SystemDictionary.java:149)
        at sun.jvm.hotspot.utilities.SystemDictionaryHelper.findInstanceKlass(SystemDictionaryHelper.java:107)
        at jdk.nashorn.internal.scripts.Script$Recompilation$2402$7541A$sa.main$jclass(sa.js:247)
        at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:625)
        at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:511)
        at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393)
        at jdk.nashorn.api.scripting.ScriptObjectMirror.callMember(ScriptObjectMirror.java:199)
        at jdk.nashorn.api.scripting.NashornScriptEngine.invokeImpl(NashornScriptEngine.java:383)
        at jdk.nashorn.api.scripting.NashornScriptEngine.invokeFunction(NashornScriptEngine.java:190)
        at sun.jvm.hotspot.utilities.soql.JSJavaScriptEngine.call(JSJavaScriptEngine.java:78)
        at sun.jvm.hotspot.CommandProcessor$52.doit(CommandProcessor.java:1755)
        at sun.jvm.hotspot.CommandProcessor.executeCommand(CommandProcessor.java:1951)
        at sun.jvm.hotspot.CommandProcessor.executeCommand(CommandProcessor.java:1921)
        at sun.jvm.hotspot.CommandProcessor.run(CommandProcessor.java:1801)
        at sun.jvm.hotspot.CLHSDB.run(CLHSDB.java:99)
        at sun.jvm.hotspot.CLHSDB.main(CLHSDB.java:40)
        at sun.jvm.hotspot.SALauncher.runCLHSDB(SALauncher.java:134)
        at sun.jvm.hotspot.SALauncher.main(SALauncher.java:334)
------

I have created a patch from jdk9/dev/hotspot (changeset:
9625:de592ea5f7ba) as below, and checked to return "class not found
java/lang" correctly. Please review it.

diff --git a/agent/src/share/classes/sun/jvm/hotspot/utilities/CompactHashTable.java
b/agent/src/share/classes/sun/jvm/hotspot/utilities/CompactHashTable.java
--- a/agent/src/share/classes/sun/jvm/hotspot/utilities/CompactHashTable.java
+++ b/agent/src/share/classes/sun/jvm/hotspot/utilities/CompactHashTable.java
@@ -86,6 +86,10 @@
     Address baseAddress = baseAddressField.getValue(addr);
     Address bucket = bucketsField.getValue(addr);
     Address bucketEnd = bucket;
+
+    if (bucketCount() == 0) {
+      return null;
+    }
     long index = hash % bucketCount();
     int bucketInfo = (int)bucket.getCIntegerAt(index * uintSize,
uintSize, true);
     int bucketOffset = bucketOffset(bucketInfo);


Thanks,
Yuji


More information about the serviceability-dev mailing list