0xdevalias / devalias.net

Source for devalias.net
http://www.devalias.net/
49 stars 10 forks source link

[DeepDive] JavaScript/ECMAScript, V8, Node, WebAssembly, embedded JavaScript, etc #25

Open 0xdevalias opened 4 years ago

0xdevalias commented 4 years ago

V8

V8 implements ECMAScript and WebAssembly, and runs on Windows 7 or later, macOS 10.12+, and Linux systems that use x64, IA-32, ARM, or MIPS processors. V8 can run standalone, or can be embedded into any C++ application.

V8 compiles and executes JavaScript source code, handles memory allocation for objects, and garbage collects objects it no longer needs. V8’s stop-the-world, generational, accurate garbage collector is one of the keys to V8’s performance.

JavaScript / ECMAScript / TC39

Profiling JavaScript

WebAssembly

AssemblyScript

See Also

Babel

Chrome

JavaScript on Java (JVM, JDK, GraalVM, etc)

(Originally written as a comment on https://github.com/jimkyndemeyer/js-graphql-intellij-plugin/issues/296#issuecomment-658522151))

I decided to do a little googling to see what the state of JavaScript in JVM is these days.

Rhino is the original JavaScript engine for JVM that I remember hearing about, but it seems it is still maintained, with a stable release in January 2020

Between Java 8 and 11, Nashorn was the JavaScript engine shipped with the JDK, but it is deprecated since Java 11, with GraalVM as the suggested replacement.

GraalVM supports many different programming languages on top of the JVM, of which JavaScript is one of them:

  • GraalVM JavaScript: ECMAScript 2019 compliant JavaScript runtime, with support for Node.js

In the JavaScript & Node.js section of the docs on the main GraalVM website it claims even more updated compatibility:

  • GraalVM is ECMAScript 2020 compliant and fully compatible with a diverse range of active Node.js (npm) modules. More than 100,000 npm packages are regularly tested and are compatible with GraalVM, including modules like express, react, async, request, browserify, grunt, mocha, and underscore. The latest release of GraalVM is based on Node.js version 12.15.0.

The main docs page talks about the various methods of being able to use GrallVM features, of which the most relevant here is as a library (jar files) rather than as a runtime:

  • Libraries (jar files)

    • GraalVM Compiler – a dynamic just-in-time (JIT) compiler that improves efficiency and speed of applications through unique approaches to code analysis and optimization.

    • JavaScript interpreter – an ECMAScript compliant JavaScript engine.

While you can apparently get a GraalVM-based replacement of the standard Java JDK, it's also possible to use it as a jar dependency on the standard JDK:

The GraalVM GraalJS repo is on GitHub, and they also have documentation on how to use it with a standard (non-GraalVM) JDK as part of a maven project, or just by referencing the jar files.


There are also various methods for 'calling out' to the hosting system's node, if a non-fully-native-JVM solution is considered acceptable; eg:

Another potential method could be to run node to parse the JS config files, and then export a more Java friendly 'intermediary' config file, that this lib could then read from.

Unsorted