Skip to content

Commit ac978dd

Browse files
Improve UninterruptibleAnnotationChecker.
1 parent becaadc commit ac978dd

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/UninterruptibleAnnotationChecker.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import com.oracle.svm.core.NeverInline;
4646
import com.oracle.svm.core.SubstrateOptions;
4747
import com.oracle.svm.core.Uninterruptible;
48+
import com.oracle.svm.core.classinitialization.EnsureClassInitializedNode;
4849
import com.oracle.svm.core.feature.AutomaticallyRegisteredImageSingleton;
4950
import com.oracle.svm.core.option.HostedOptionKey;
5051
import com.oracle.svm.core.os.RawFileOperationSupport;
@@ -73,8 +74,7 @@ private static UninterruptibleAnnotationChecker singleton() {
7374

7475
public static void checkAfterParsing(ResolvedJavaMethod method, StructuredGraph graph) {
7576
if (Uninterruptible.Utils.isUninterruptible(method) && graph != null) {
76-
singleton().checkNoAllocation(method, graph);
77-
singleton().checkNoSynchronization(method, graph);
77+
singleton().checkGraph(method, graph);
7878
}
7979
}
8080

@@ -134,12 +134,6 @@ private void checkSpecifiedOptions(HostedMethod method, Uninterruptible annotati
134134
}
135135

136136
if (annotation.mayBeInlined()) {
137-
if (!annotation.reason().equals(Uninterruptible.CALLED_FROM_UNINTERRUPTIBLE_CODE) && !AnnotationAccess.isAnnotationPresent(method, AlwaysInline.class)) {
138-
violations.add("Method " + method.format("%H.%n(%p)") + " is annotated with @Uninterruptible('mayBeInlined = true') which allows the method to be inlined into interruptible code. " +
139-
"If the method has an inherent reason for being uninterruptible, besides being called from uninterruptible code, then please remove 'mayBeInlined = true'. " +
140-
"Otherwise, use the following reason: '" + Uninterruptible.CALLED_FROM_UNINTERRUPTIBLE_CODE + "'");
141-
}
142-
143137
if (AnnotationAccess.isAnnotationPresent(method, NeverInline.class)) {
144138
violations.add("Method " + method.format("%H.%n(%p)") +
145139
" is annotated with conflicting annotations: @Uninterruptible('mayBeInlined = true') and @NeverInline");
@@ -151,6 +145,14 @@ private void checkSpecifiedOptions(HostedMethod method, Uninterruptible annotati
151145
}
152146
}
153147

148+
if (annotation.mayBeInlined() && annotation.calleeMustBe()) {
149+
if (!annotation.reason().equals(Uninterruptible.CALLED_FROM_UNINTERRUPTIBLE_CODE) && !AnnotationAccess.isAnnotationPresent(method, AlwaysInline.class)) {
150+
violations.add("Method " + method.format("%H.%n(%p)") + " is annotated with @Uninterruptible('mayBeInlined = true') which allows the method to be inlined into interruptible code. " +
151+
"If the method has an inherent reason for being uninterruptible, besides being called from uninterruptible code, then please remove 'mayBeInlined = true'. " +
152+
"Otherwise, use the following reason: '" + Uninterruptible.CALLED_FROM_UNINTERRUPTIBLE_CODE + "'");
153+
}
154+
}
155+
154156
if (!annotation.mayBeInlined() && !annotation.callerMustBe() && AnnotationAccess.isAnnotationPresent(method, AlwaysInline.class)) {
155157
violations.add("Method " + method.format("%H.%n(%p)") +
156158
" is annotated with @Uninterruptible and @AlwaysInline. If the method may be inlined into interruptible code, please specify 'mayBeInlined = true'. Otherwise, specify 'callerMustBe = true'.");
@@ -259,18 +261,14 @@ private void checkCallers(HostedMethod caller, Uninterruptible callerAnnotation,
259261
}
260262
}
261263

262-
private void checkNoAllocation(ResolvedJavaMethod method, StructuredGraph graph) {
264+
private void checkGraph(ResolvedJavaMethod method, StructuredGraph graph) {
263265
for (Node node : graph.getNodes()) {
264266
if (isAllocationNode(node)) {
265267
violations.add("Uninterruptible method " + method.format("%H.%n(%p)") + " is not allowed to allocate.");
266-
}
267-
}
268-
}
269-
270-
private void checkNoSynchronization(ResolvedJavaMethod method, StructuredGraph graph) {
271-
for (Node node : graph.getNodes()) {
272-
if (node instanceof MonitorEnterNode) {
268+
} else if (node instanceof MonitorEnterNode) {
273269
violations.add("Uninterruptible method " + method.format("%H.%n(%p)") + " is not allowed to use 'synchronized'.");
270+
} else if (node instanceof EnsureClassInitializedNode) {
271+
violations.add("Uninterruptible method " + method.format("%H.%n(%p)") + " not allowed to do class initialization.");
274272
}
275273
}
276274
}

0 commit comments

Comments
 (0)