Prev Next

Java / GraalVM Interview questions

Explain the execution flow of a polyglot call between Java and JavaScript on GraalVM?

A polyglot call walks through several layers before returning a result back to Java host code.

sequenceDiagram
  participant Host as Java Host Code
  participant Ctx as polyglot.Context
  participant JS as GraalJS (Truffle)
  participant Graal as Graal Compiler
  Host->>Ctx: context.eval("js", source)
  Ctx->>JS: parse source into Truffle AST
  JS->>JS: interpret AST nodes, specialize on types
  JS->>Graal: hot nodes handed off for partial evaluation
  Graal-->>JS: optimized machine code installed
  JS-->>Ctx: result value produced
  Ctx-->>Host: wrapped as org.graalvm.polyglot.Value
  1. Java host code calls context.eval("js", source), handing the JavaScript source string to the Context.
  2. GraalJS, a Truffle interpreter, parses it into an AST and begins tree-walking execution, with nodes specializing themselves based on observed operand types.
  3. Once a code path is hot, the Graal compiler partially evaluates the interpreter against that specific AST, producing optimized machine code.
  4. The final result is wrapped in a Value object and handed back to the Java host, which can convert it to a native Java type or a proxying interface.

Calls in the opposite direction (JavaScript calling into Java objects) work symmetrically, going through the same Context's host-access policy.

What does context.eval('js', source) do?
What type wraps the result returned to Java host code?

More Related questions...

What is GraalVM? What are the main components of GraalVM? What is Native Image in GraalVM? What is the Graal compiler? What is the purpose of Substrate VM? What are the editions of GraalVM? How do you install GraalVM using SDKMAN? How do you apply the gu utility to manage components? Define polyglot programming in the context of GraalVM? Describe the Truffle language implementation framework? List the languages GraalVM can run? What is ahead-of-time (AOT) compilation? What are the benefits of using GraalVM Native Image? What is a fallback image? Describe reflection configuration in native image? What is class initialization at build time? How do you set GraalVM as your default JDK? How do you generate a native executable with native-image? What is the purpose of the Graal compiler's tiered execution? Define the Graal compiler's JIT role within HotSpot? What are the types of GraalVM components installable via gu? Describe the polyglot Context API? What is the purpose of Truffle's Partial Evaluation? Explain the purpose of resource-config.json in native image? What is the purpose of the reachability metadata repository? Why is GraalVM's JIT compiler often faster than the default HotSpot C2 compiler? What is the difference between GraalVM Community and Enterprise editions? When should you choose Native Image over running on the JVM? How does the native-image build process work end-to-end? Why doesn't Native Image support dynamic class loading by default? How do you troubleshoot "ClassNotFoundException" in a native image at runtime? What is the difference between build-time and run-time class initialization? How can you optimize native image build time for large applications? Why should you use Profile-Guided Optimization (PGO) with Native Image? How does escape analysis work in the Graal compiler? Explain the execution flow of a polyglot call between Java and JavaScript on GraalVM? What happens when you use Java dynamic proxies with Native Image? Why is heap size configuration different for native image versus a JVM? How do you troubleshoot missing reflection metadata errors during native image build? Explain the internal working of Truffle's AST specialization? Difference between Espresso and running native Java bytecode on the JVM? Why doesn't Native Image support arbitrary bytecode generation at runtime? How can you optimize the memory footprint of a native image executable? Explain the lifecycle of a Truffle language implementation from parsing to execution? Difference between GraalVM Native Image and traditional Docker-based JVM deployment for startup time? How does GraalVM's deoptimization mechanism work when a speculative optimization fails? When would you choose GraalVM Enterprise's G1 GC support over Community's Serial GC for native image? How do you debug a native image application when standard Java debuggers don't attach? Explain the internal working of the Graal compiler's speculative optimizations? Why is GraalVM particularly well suited for serverless and microservices workloads?
Show more question and Answers...


Comments & Discussions