Nashorn JSON.parse() - java.lang.OutOfMemoryError: Java heap space - JDK8u60

≯℡__Kan透↙ 提交于 2019-12-22 09:48:03

问题


Nashron Release notes claims they fixed the JSON parser bugs, but I am still able to produce a (different) bug on new patch 8u60. This time it is OutOfMemoryError.

Refer the attached JSON [1] (it is typically a Category & Subcategory relation). When I try to invoke JSON.parse() it is failing.

[1] http://jsfiddle.net/manivannandsekaran/rfftavkz/

  1. I tried to increase the heap size, didn't help, instead of getting the OOM Exception quickly, it delayed bit.
  2. When I replace all the integer key with Alpahnumberic, the entire parsing time is super fast. [2]

[2] https://jsfiddle.net/manivannandsekaran/8yw3ojmu/

It is almost 4 months we waited to get the original bug fixed, now again the new path introduced a another bug (it is really frustrating, I am not sure how these bugs are get escaped from regression). Is there any workaround available? Is it possible to override default JSON parser with other well known JSON parsers (like GSON or Jackson).

Here the stack trace of failure from JJS.

jjs> load("catsubcat/test.js")
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
        at jdk.nashorn.internal.runtime.arrays.IntArrayData.toObjectArray(IntArrayData.java:138)
        at jdk.nashorn.internal.runtime.arrays.IntArrayData.convertToObject(IntArrayData.java:180)
        at jdk.nashorn.internal.runtime.arrays.IntArrayData.convert(IntArrayData.java:192)
        at jdk.nashorn.internal.runtime.arrays.IntArrayData.set(IntArrayData.java:243)
        at jdk.nashorn.internal.runtime.arrays.ArrayFilter.set(ArrayFilter.java:99)
        at jdk.nashorn.internal.runtime.arrays.DeletedRangeArrayFilter.set(DeletedRangeArrayFilter.java:144)
        at jdk.nashorn.internal.parser.JSONParser.addArrayElement(JSONParser.java:246)
        at jdk.nashorn.internal.parser.JSONParser.parseObject(JSONParser.java:210)
        at jdk.nashorn.internal.parser.JSONParser.parseLiteral(JSONParser.java:165)
        at jdk.nashorn.internal.parser.JSONParser.parseObject(JSONParser.java:207)
        at jdk.nashorn.internal.parser.JSONParser.parseLiteral(JSONParser.java:165)
        at jdk.nashorn.internal.parser.JSONParser.parseObject(JSONParser.java:207)
        at jdk.nashorn.internal.parser.JSONParser.parseLiteral(JSONParser.java:165)
        at jdk.nashorn.internal.parser.JSONParser.parse(JSONParser.java:148)
        at jdk.nashorn.internal.runtime.JSONFunctions.parse(JSONFunctions.java:80)
        at jdk.nashorn.internal.objects.NativeJSON.parse(NativeJSON.java:105)
        at java.lang.invoke.LambdaForm$DMH/1880587981.invokeStatic_L3_L(LambdaForm$DMH)
        at java.lang.invoke.LambdaForm$BMH/1095293768.reinvoke(LambdaForm$BMH)
        at java.lang.invoke.LambdaForm$MH/1411892748.exactInvoker(LambdaForm$MH)
        at java.lang.invoke.LambdaForm$MH/22805895.linkToCallSite(LambdaForm$MH)
        at jdk.nashorn.internal.scripts.Script$5$test.:program(file:catsubcat/test.js:1)
        at java.lang.invoke.LambdaForm$DMH/1323165413.invokeStatic_LL_L(LambdaForm$DMH)
        at java.lang.invoke.LambdaForm$MH/653687670.invokeExact_MT(LambdaForm$MH)
        at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:640)
        at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:228)
        at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393)
        at jdk.nashorn.internal.runtime.Context.evaluateSource(Context.java:1219)
        at jdk.nashorn.internal.runtime.Context.load(Context.java:841)
        at jdk.nashorn.internal.objects.Global.load(Global.java:1536)
        at java.lang.invoke.LambdaForm$DMH/1323165413.invokeStatic_LL_L(LambdaForm$DMH)
        at java.lang.invoke.LambdaForm$BMH/1413378318.reinvoke(LambdaForm$BMH)
        at java.lang.invoke.LambdaForm$reinvoker/40472007.dontInline(LambdaForm$reinvoker)

回答1:


The problem is just that Nashorn switches to sparse array representation too late. I filed a bug for this: https://bugs.openjdk.java.net/browse/JDK-8137281



来源:https://stackoverflow.com/questions/32787100/nashorn-json-parse-java-lang-outofmemoryerror-java-heap-space-jdk8u60

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!