Mandated Export: Why?
Alex Buckley
alex.buckley at oracle.com
Thu Jul 21 23:59:19 UTC 2016
This isn't a JPMS issue per se; it's the JPMS following a broader pattern.
The distinction between ACC_SYNTHETIC and ACC_MANDATED was introduced by
the MethodParameters attribute in Java SE 8. It is extremely useful to
be able to distinguish between "something in the class file that a
compiler put there as an implementation artifact, to assist other class
files generated by the same compiler" (ACC_SYNTHETIC) and "something in
the class file that a compiler was required to put there by a JCP
specification, because for whatever reason the thing could not be
denoted in source code" (ACC_MANDATED). No-one should rely on the
presence or semantics of an ACC_SYNTHETIC artifact, but everyone can
rely on the presence and semantics of an ACC_MANDATED artifact. There's
a long history of ACC_SYNTHETIC being set for artifacts as if the former
description is appropriate when in fact the latter description is
appropriate; the prime example is fields of an enum type.
In principle, every artifact in the ClassFile structure should allow its
reason-for-being to be flagged. For modules, it's clear that the
JLS-defined dependency on java.base should be ACC_MANDATED, while a
dependency added by a tool (because the tool added classes to a module)
would be ACC_SYNTHETIC. There aren't yet any exports which would be
ACC_MANDATED, but exports added by a tool as in the previous sentence
would legitimately be ACC_SYNTHETIC.
Alex
On 7/21/2016 4:02 PM, Paul Benedict wrote:
> From the document that describes the binary module format for exports [1]:
>
> 0x1000 (ACC_SYNTHETIC)
> Indicates that the dependence was not explicitly or implicitly declared in
> the source of the module declaration.
>
> 0x8000 (ACC_MANDATED)
> Indicates the dependence was implicitly declared in the source of the
> module declaration.
>
> I'd like to find out why ACC_MANDATED is necessary because it seems
> ACC_SYNTHETIC is enough. What's keenly interesting is that the description
> of ACC_MANDATED is nearly the same to what the JVMS says about
> ACC_SYNTHETIC for a class: "it was generated by a compiler and does not
> appear in source code" [2].
>
> It appears something is incorrect with the description of these flags. What
> is ACC_MANDATED really for and how it is useful?
>
> [1] http://cr.openjdk.java.net/~mr/jigsaw/spec/lang-vm.html#jigsaw-2.3
> [2] https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html
>
> Cheers,
> Paul
>
More information about the jpms-spec-observers
mailing list