JDK-8189199 : Minimal ConstantDynamic support
  • Type: CSR
  • Component: hotspot
  • Sub-Component: runtime
  • Priority: P2
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 11
  • Submitted: 2017-10-11
  • Updated: 2018-03-12
  • Resolved: 2018-01-30
Related Reports
CSR :  
Description
Summary
-------

Implement [JEP 309](http://openjdk.java.net/jeps/309) by properly parsing and resolving new `CONSTANT_Dynamic` constants in JVM class files used by Hotspot.

The draft VM specification may be found by the Change Review Request (CSR) issue JDK-8189199 that is associated with the main development issue.

Problem
-------

Static arguments to bootstrap methods are drawn from a very limited language: the arguments can only be primitive numbers, strings, Classes, MethodHandles, or MethodTypes. Many applications would be helped by greater expressive freedom.

Some applications of `invokedynamic` consist merely of loading a single, cached value (a `ConstantCallSite` wrapping a `MethodHandles.constant`). It would be more natural in these cases to `ldc` the value directly.


Solution
--------

A new `CONSTANT_Dynamic` constant pool entry uses a bootstrap method to dynamically compute a value at resolution time. It shares much of the structure and behavior of `invokedynamic` call site resolution, but uses a _field_ descriptor in its `NameAndType`, and represents a value of the given type rather than a `CallSite`.


Specification
-------------

Updates to the Java Virtual Machine Specification are attached. Some small changes may be forthcoming before finalizing this proposal.

Some descriptive changes to the `java.lang.invoke` API documentation will also be attached before finalizing.

Comments
Hamlin, thanks for the careful reading. Those references have been fixed in JVMS and the fixes will be part of the umbrella JSR (JSR 384).
12-03-2018

in attachment constant-dynamic.html which was uploaded at 2018-01-18, most of "call site specifier" are removed or replaced with "dynamically-computed call site", but there are still some left unchanged. would it be clear to replace all "call site specifier" with "dynamically-computed call site"? following are some of unchanged "call site specifier": "T specifies the method descriptor in the call site specifier." "order of the values must be consistent with the method descriptor in the call site specifier." "If this specific dynamic call site completed resolution of its call site specifier" "it implies that the method descriptor in the call site specifier is semantically equal to"
09-03-2018

Moving to approved.
30-01-2018

Attached is a side-by-side diff (left = old, right = new) of the j.l.invoke package documentation (which is non-normative and defers to the VM specification for normative definitions).
24-01-2018

The Description section notes "Some descriptive changes to the java.lang.invoke API documentation will also be attached before finalizing." However, the attachment only seems to include JVMS updates. Is an update update still planning for this CSR?
24-01-2018

A (tentatively) final description of JVMS changes is attached.
19-01-2018

I've since filed JDK-8190736, which centralizes the documentation about class file versions and Java SE versions.
21-11-2017

Moving to provisional. Agree that a single Java SE/JDK version <=> latest class file version supported table would be preferable to listing the class file version and JDK in multiple locations.
17-11-2017

Added http://cr.openjdk.java.net/~jrose/jvm/constant-dynamic-jrose.html which refactors and clarifies some parts of Dan's draft of http://cr.openjdk.java.net/~dlsmith/constant-dynamic.html The clarifications are about errors thrown around edge cases, such as circular dependencies, and about permitted implementation options (the "as if" rules). The refactoring is around the treatment of arguments and return values to the BSM. By shifting the BSM call specification to use invokeWithArguments, non-essential arity restrictions are incidentally lifted, which was difficult to do in the previous treatment.
27-10-2017

Note for reviewers: the spec changes document contains very helpful text in the grey boxes explaining some rational for the changes.
12-10-2017