Skip to content

When enumerating the roots nextElement can fail with: Cannot read property "getInstanceId" from null #484

@swpalmer

Description

@swpalmer

Describe the bug
Using OQL on a heap dump generated from open JDK 17.0.5 the following script will fail with the mentioned error after several thousand iterations of the loop. I added a simple counter to terminate the loop earlier and could read through most of the 20,000+ roots before it failed at 17,026.

var roots = heap.roots();
while(roots.hasMoreElements()) {
  var root = roots.nextElement();
}

To Reproduce
Steps to reproduce the behavior:

  1. Grab a heap dump
  2. Go to the OQL Console
    3.Enter the above script and run it
  3. See error

Expected behavior
The loop should always complete without errors.

VisualVM log

INFO [org.graalvm.visualvm.heapviewer.oql.OQLQueryExecutor]: Error executing OQL
TypeError: Cannot read property "getInstanceId" from null
	at <js> wrapRoot(<eval>:170:5336-5364)
	at <js> wrapJavaValue(<eval>:288:8698-8712)
	at <js> nextElement(<eval>:1293:41929-41953)
	at org.graalvm.polyglot.Value.invokeMember(Value.java:932)
	at com.oracle.truffle.host.adapters.Enumeration$$Adapter.nextElement(Unknown Source)
	at <js> printHistogram(<eval>:11:243-261)
	at <js> :program(<eval>:1:0-15)
	at org.graalvm.polyglot.Context.eval(Context.java:379)
	at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:458)
	at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.access$400(GraalJSScriptEngine.java:83)
	at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine$10.eval(GraalJSScriptEngine.java:628)
	at java.scripting/javax.script.CompiledScript.eval(CompiledScript.java:107)
	at org.graalvm.visualvm.lib.profiler.oql.engine.api.impl.OQLEngineImpl.evalScript(OQLEngineImpl.java:340)
	at org.graalvm.visualvm.lib.profiler.oql.engine.api.impl.OQLEngineImpl.executeQuery(OQLEngineImpl.java:106)
	at org.graalvm.visualvm.lib.profiler.oql.engine.api.OQLEngine.executeQuery(OQLEngine.java:97)
	at org.graalvm.visualvm.heapviewer.oql.OQLQueryExecutor$3.run(OQLQueryExecutor.java:301)
	at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1418)
	at org.netbeans.modules.openide.util.GlobalLookup.execute(GlobalLookup.java:45)
	at org.openide.util.lookup.Lookups.executeWith(Lookups.java:278)
	at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2033)
Caused: javax.script.ScriptException
	at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.toScriptException(GraalJSScriptEngine.java:483)
	at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:460)
	at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.access$400(GraalJSScriptEngine.java:83)
	at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine$10.eval(GraalJSScriptEngine.java:628)
	at java.scripting/javax.script.CompiledScript.eval(CompiledScript.java:107)
	at org.graalvm.visualvm.lib.profiler.oql.engine.api.impl.OQLEngineImpl.evalScript(OQLEngineImpl.java:340)
	at org.graalvm.visualvm.lib.profiler.oql.engine.api.impl.OQLEngineImpl.executeQuery(OQLEngineImpl.java:106)
Caused: org.graalvm.visualvm.lib.profiler.oql.engine.api.OQLException
	at org.graalvm.visualvm.lib.profiler.oql.engine.api.impl.OQLEngineImpl.executeQuery(OQLEngineImpl.java:109)
	at org.graalvm.visualvm.lib.profiler.oql.engine.api.OQLEngine.executeQuery(OQLEngine.java:97)
[catch] at org.graalvm.visualvm.heapviewer.oql.OQLQueryExecutor$3.run(OQLQueryExecutor.java:301)
	at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1418)
	at org.netbeans.modules.openide.util.GlobalLookup.execute(GlobalLookup.java:45)
	at org.openide.util.lookup.Lookups.executeWith(Lookups.java:278)
	at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2033)

Desktop (please complete the following information):

  • OS: Windows 11
  • JDK version VisualVM running on JDK 19.0.1, Heapdump from a JDK 17.0.5 JVM
  • Version 2.1.5

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions