Skip to content

Commit c042bbc

Browse files
committed
Add profiles for unsupported message
1 parent 7f8b9c5 commit c042bbc

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/PBaseException.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import com.oracle.truffle.api.CompilerAsserts;
6161
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
6262
import com.oracle.truffle.api.dsl.Cached;
63+
import com.oracle.truffle.api.dsl.Cached.Shared;
6364
import com.oracle.truffle.api.dsl.CachedLanguage;
6465
import com.oracle.truffle.api.interop.ExceptionType;
6566
import com.oracle.truffle.api.interop.InteropLibrary;
@@ -68,6 +69,7 @@
6869
import com.oracle.truffle.api.library.ExportLibrary;
6970
import com.oracle.truffle.api.library.ExportMessage;
7071
import com.oracle.truffle.api.object.Shape;
72+
import com.oracle.truffle.api.profiles.BranchProfile;
7173

7274
@ExportLibrary(InteropLibrary.class)
7375
public final class PBaseException extends PythonObject {
@@ -314,7 +316,8 @@ String getExceptionMessage(@CachedLibrary("this") PythonObjectLibrary lib) {
314316
@ExportMessage
315317
int getExceptionExitStatus(
316318
@CachedLibrary("this") PythonObjectLibrary lib,
317-
@Cached ReadAttributeFromDynamicObjectNode readNode) throws UnsupportedMessageException {
319+
@Cached ReadAttributeFromDynamicObjectNode readNode,
320+
@Shared("unsupportedProfile") @Cached BranchProfile unsupportedProfile) throws UnsupportedMessageException {
318321
if (getExceptionType(lib) == ExceptionType.EXIT) {
319322
try {
320323
// Avoiding getattr because this message shouldn't have side-effects
@@ -327,6 +330,7 @@ int getExceptionExitStatus(
327330
return 1;
328331
}
329332
}
333+
unsupportedProfile.enter();
330334
throw UnsupportedMessageException.create();
331335
}
332336

@@ -336,13 +340,15 @@ boolean hasExceptionCause() {
336340
}
337341

338342
@ExportMessage
339-
Object getExceptionCause() throws UnsupportedMessageException {
343+
Object getExceptionCause(
344+
@Shared("unsupportedProfile") @Cached BranchProfile unsupportedProfile) throws UnsupportedMessageException {
340345
if (cause != null) {
341346
return cause;
342347
}
343348
if (!suppressContext && context != null) {
344349
return context;
345350
}
351+
unsupportedProfile.enter();
346352
throw UnsupportedMessageException.create();
347353
}
348354
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/exception/PException.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import com.oracle.truffle.api.Truffle;
5858
import com.oracle.truffle.api.TruffleStackTrace;
5959
import com.oracle.truffle.api.TruffleStackTraceElement;
60+
import com.oracle.truffle.api.dsl.Cached;
6061
import com.oracle.truffle.api.exception.AbstractTruffleException;
6162
import com.oracle.truffle.api.frame.VirtualFrame;
6263
import com.oracle.truffle.api.interop.ExceptionType;
@@ -66,6 +67,7 @@
6667
import com.oracle.truffle.api.library.ExportLibrary;
6768
import com.oracle.truffle.api.library.ExportMessage;
6869
import com.oracle.truffle.api.nodes.Node;
70+
import com.oracle.truffle.api.profiles.BranchProfile;
6971
import com.oracle.truffle.api.source.SourceSection;
7072

7173
/**
@@ -364,10 +366,12 @@ boolean hasSourceLocation() {
364366
}
365367

366368
@ExportMessage(name = "getSourceLocation")
367-
SourceSection getExceptionSourceLocation() throws UnsupportedMessageException {
369+
SourceSection getExceptionSourceLocation(
370+
@Cached BranchProfile unsupportedProfile) throws UnsupportedMessageException {
368371
if (hasSourceLocation()) {
369372
return getLocation().getEncapsulatingSourceSection();
370373
}
374+
unsupportedProfile.enter();
371375
throw UnsupportedMessageException.create();
372376
}
373377

0 commit comments

Comments
 (0)