File tree 2 files changed +16
-6
lines changed
impl/src/main/java/io/perfmark/impl
2 files changed +16
-6
lines changed Original file line number Diff line number Diff line change @@ -77,10 +77,15 @@ public static final class PerfMarkImpl extends Impl {
77
77
problems [2 ] = t ;
78
78
}
79
79
}
80
- if (gen == null ) {
81
- generator = new NoopGenerator ();
82
- } else {
80
+ if (gen != null ) {
83
81
generator = gen ;
82
+ } else {
83
+ // This magic incantation avoids loading the NoopGenerator class. When PerfMarkImpl is
84
+ // being verified, the JVM needs to load NoopGenerator to see that it actually is a
85
+ // Generator. By doing a cast here, Java pushes the verification to when this branch is
86
+ // actually taken, which is uncommon. Avoid reflectively loading the class, which may
87
+ // make binary shrinkers drop the NoopGenerator class.
88
+ generator = (Generator ) (Object ) new NoopGenerator ();
84
89
}
85
90
86
91
boolean startEnabled = false ;
Original file line number Diff line number Diff line change @@ -90,10 +90,15 @@ public final class Storage {
90
90
problems [2 ] = t ;
91
91
}
92
92
}
93
- if (provider == null ) {
94
- markRecorderProvider = new NoopMarkRecorderProvider ();
95
- } else {
93
+ if (provider != null ) {
96
94
markRecorderProvider = provider ;
95
+ } else {
96
+ // This magic incantation avoids loading the NoopMarkRecorderProvider class. When Storage
97
+ // is being verified, the JVM needs to load NoopMarkRecorderProvider to see that it actually
98
+ // is a MarkRecorderProvider. By doing a cast here, Java pushes the verification to when
99
+ // this branch is actually taken, which is uncommon. Avoid reflectively loading the class,
100
+ // which may make binary shrinkers drop the NoopMarkRecorderProvider class.
101
+ markRecorderProvider = (MarkRecorderProvider ) (Object ) new NoopMarkRecorderProvider ();
97
102
}
98
103
try {
99
104
if (Boolean .getBoolean ("io.perfmark.PerfMark.debug" )) {
You can’t perform that action at this time.
0 commit comments