diff options
author | cnsun <cnsun@google.com> | 2017-06-28 18:05:48 +0200 |
---|---|---|
committer | Marcel Hlopko <hlopko@google.com> | 2017-06-29 09:31:57 +0200 |
commit | 8740ca6bd0f4156aaf663c482bc3e9c7ebb2c556 (patch) | |
tree | f2a05eb23192d8c236dbfe6da5e9ada5d9763a95 /third_party | |
parent | c251b05375808fe2e22a1931853603e76043c932 (diff) |
Access interface constants to explicitly trigger the execution of interface
initializers. The problem is that when we desugar default methods, the static
intializer of interface will not be executed. The JVM spec says that if an
interface has default methods, then when it is loaded, it will also be
initialized. After we desugar such an interface, its default methods are
removed, and when we load the interface, the <clinit> will not be executed.
This CL checks whether an interface has default methods and fields. If yes (needs to be initialized when the interface is loaded), it injects field access code
to access the interface fields in the <clinit> of the companion class.
We also create a constant $$CONSTANT$$ in the companion class.
Then for all the classes that implement the interface, we inject GETSTATIC in the class <clinit> to the $$CONSTANT$$ of the companion class of the interface. This indirection is to avoid the IllegalAccessError when the interface is package private.
Note that accessing an arbitrary interface field does not guarantee the
interface will be initialized. We need to access the field that is initialized
in the interface static initializer.
RELNOTES: None
PiperOrigin-RevId: 160414671
Diffstat (limited to 'third_party')
0 files changed, 0 insertions, 0 deletions