JDK-8235594 : SA javascript support has been broken since 9
  • Type: Bug
  • Component: hotspot
  • Sub-Component: svc-agent
  • Affected Version: 9,10,11,12,13,14
  • Priority: P3
  • Status: Resolved
  • Resolution: Won't Fix
  • Submitted: 2019-12-09
  • Updated: 2023-08-02
  • Resolved: 2020-05-08
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Description
When you do an SA attach. You will see the following warning messages:

     Warning! JS Engine can't start, some commands will not be available.

If before the attach you first do a "verbose true" command, you will see the reason for the failure:

 java.lang.RuntimeException: javax.script.ScriptException: TypeError: so["has(java.lang.String)"] is not a function in sa.js at line number 133

This has been broken since 9 since because the Nashorn engine allows Java access only for public classes in exported packages of modules. SA does not export any API packages.

This also shows up when running SOQL and JSDB tools:

    java --add-modules jdk.hotspot.agent sun.jvm.hotspot.tools.soql.SOQL <pid>
    Warning: Nashorn engine is planned to be removed from a future JDK release
    javax.script.ScriptException: TypeError: sapkg.runtime.VM.getVM is not a function in sa.js at line number 54
    javax.script.ScriptException: TypeError: sapkg.runtime.VM.getVM is not a function in sa.js at line number 54
    java.lang.RuntimeException: javax.script.ScriptException: TypeError: so.getIds is not a function in sa.js at line number 147
Comments
Will not fix. Javascript support is being removed from SA by JDK-8244668. Support for the above clhsdb commands is being added by implementing them in java. See JDK-8240987.
08-05-2020

Nashorn engine is being removed (JEP: https://openjdk.java.net/jeps/372)
14-04-2020

Besides the jseval and jsload commands, the following clhsdb commands are written in javascript and therefore are not available without the javascript support: registerCommand("class", "class name", "jclass"); registerCommand("classes", "classes", "jclasses"); registerCommand("dumpclass", "dumpclass { address | name } [ directory ]", "dclass"); registerCommand("dumpheap", "dumpheap [ file ]", "dumpHeap"); registerCommand("mem", "mem address [ length ]", "printMem"); registerCommand("sysprops", "sysprops", "sysProps"); registerCommand("whatis", "whatis address", "printWhatis");
10-12-2019

We should probably consider removal of the javascript support. Possibly it should be disabled in the interim. One downside of the error is that with the changes I'm making with JDK-8234277, the clhsdb tests will always be run with "verbose true" and will and will always see the full exception backtrace of the javascript initialization failure. The tests still pass, but if they did happen to fail for some reason, the presence of the exception can be a red herring, and it would be best to not have it present.
09-12-2019

I can't find any official support for SA javascript support or for the SOQL and JSDB tools. Here's the only documentation support I can find for using javascript with SA (clhsdb) https://cr.openjdk.java.net/~minqi/6830717/raw_files/new/agent/doc/clhsdb.html And this is what I found for SOQL and JSDB: http://javatroubleshooting.blogspot.com/2015/12/serviceability-agent-part-3.html
09-12-2019