RFR: CODETOOLS-7902812: Fields can still be default initialized if class has only static intializers
Aleksey Shipilev
shade at openjdk.java.net
Wed Dec 16 10:51:04 UTC 2020
On Wed, 16 Dec 2020 10:35:37 GMT, Volker Simonis <simonis at openjdk.org> wrote:
> `JCStressTestProcessor` processes a jcstress test `X.java` and generates the corresponding `X_jcstress.java` wrapper class. In this class it generates a `jcstress_consume()` method which resets the status of the stress test after every iteration. If the initial `X.java` stress test class only has primitive fields, a default constructor and no instance initializer, it's fields can be simply reset to default values. Otherwise the method allocates a completely new `X` object.
>
> The current check for default initialization of fields makes no distinction between instance and static (i.e. class) initializers and rejects default initialization of fields in the presence of each of them. Fields can however still be default initialized if a class only has static initializers. This saves some allocations and GC-cycles mostly for the VarHandle tests where the VarHandles are commonly initialized in static initializers.
Good find! Looks good, except for minor stylistic nit.
jcstress-core/src/main/java/org/openjdk/jcstress/infra/processors/JCStressTestProcessor.java line 683:
> 681: if (b.isStatic()) continue;
> 682: // no instance initializers of any kind
> 683: return false;
I would write it as:
if (member.getKind() == Tree.Kind.BLOCK) {
BlockTree b = (BlockTree)member;
// no instance initializers of any kind
if (!b.isStatic()) return false;
}
...to match the style of the method.
-------------
Marked as reviewed by shade (Committer).
PR: https://git.openjdk.java.net/jcstress/pull/5
More information about the jcstress-dev
mailing list