6161import com .oracle .truffle .api .CompilerAsserts ;
6262import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
6363import com .oracle .truffle .api .dsl .Cached ;
64- import com .oracle .truffle .api .dsl .Cached .Exclusive ;
6564import com .oracle .truffle .api .dsl .Cached .Shared ;
6665import com .oracle .truffle .api .dsl .CachedLanguage ;
6766import com .oracle .truffle .api .interop .ExceptionType ;
@@ -198,17 +197,12 @@ public Object[] getMessageArgs() {
198197 }
199198
200199 @ TruffleBoundary
201- public String getFormattedMessage (PythonObjectLibrary lib ) {
202- final Object clazz ;
203- if (lib == null ) {
204- clazz = PythonObjectLibrary .getUncached ().getLazyPythonClass (this );
205- } else {
206- clazz = lib .getLazyPythonClass (this );
207- }
200+ public String getFormattedMessage (PythonObjectLibrary baseExceptionLib , PythonObjectLibrary argsLib ) {
201+ final Object clazz = baseExceptionLib .getLazyPythonClass (this );
208202 String typeName = GetNameNode .doSlowPath (clazz );
209203 if (args == null ) {
210204 if (messageArgs != null && messageArgs .length > 0 ) {
211- return typeName + ": " + FORMATTER .format (lib , messageFormat , getMessageArgs ());
205+ return typeName + ": " + FORMATTER .format (argsLib , messageFormat , getMessageArgs ());
212206 } else if (hasMessageFormat ) {
213207 return typeName + ": " + messageFormat ;
214208 } else {
@@ -287,7 +281,8 @@ boolean isException() {
287281 @ ExportMessage
288282 RuntimeException throwException (
289283 @ Cached PRaiseNode raiseNode ,
290- @ CachedLanguage PythonLanguage language , @ Exclusive @ Cached GilNode gil ) {
284+ @ CachedLanguage PythonLanguage language ,
285+ @ Shared ("gil" ) @ Cached GilNode gil ) {
291286 boolean mustRelease = gil .acquire ();
292287 try {
293288 throw raiseNode .raiseExceptionObject (this , language );
@@ -298,7 +293,8 @@ RuntimeException throwException(
298293
299294 @ ExportMessage
300295 ExceptionType getExceptionType (
301- @ CachedLibrary ("this" ) PythonObjectLibrary lib , @ Exclusive @ Cached GilNode gil ) {
296+ @ CachedLibrary ("this" ) PythonObjectLibrary lib ,
297+ @ Shared ("gil" ) @ Cached GilNode gil ) {
302298 boolean mustRelease = gil .acquire ();
303299 try {
304300 Object clazz = lib .getLazyPythonClass (this );
@@ -332,10 +328,12 @@ boolean hasExceptionMessage() {
332328 }
333329
334330 @ ExportMessage
335- String getExceptionMessage (@ CachedLibrary ("this" ) PythonObjectLibrary lib , @ Exclusive @ Cached GilNode gil ) {
331+ String getExceptionMessage (@ CachedLibrary ("this" ) PythonObjectLibrary lib ,
332+ @ CachedLibrary (limit = "3" ) PythonObjectLibrary argsLib ,
333+ @ Shared ("gil" ) @ Cached GilNode gil ) {
336334 boolean mustRelease = gil .acquire ();
337335 try {
338- return getFormattedMessage (lib );
336+ return getFormattedMessage (lib , argsLib );
339337 } finally {
340338 gil .release (mustRelease );
341339 }
@@ -345,7 +343,8 @@ String getExceptionMessage(@CachedLibrary("this") PythonObjectLibrary lib, @Excl
345343 int getExceptionExitStatus (
346344 @ CachedLibrary (limit = "2" ) PythonObjectLibrary lib ,
347345 @ Cached ReadAttributeFromDynamicObjectNode readNode ,
348- @ Shared ("unsupportedProfile" ) @ Cached BranchProfile unsupportedProfile , @ Exclusive @ Cached GilNode gil ) throws UnsupportedMessageException {
346+ @ Shared ("unsupportedProfile" ) @ Cached BranchProfile unsupportedProfile ,
347+ @ Shared ("gil" ) @ Cached GilNode gil ) throws UnsupportedMessageException {
349348 boolean mustRelease = gil .acquire ();
350349 try {
351350 if (getExceptionType (lib , gil ) == ExceptionType .EXIT ) {
@@ -368,7 +367,7 @@ int getExceptionExitStatus(
368367 }
369368
370369 @ ExportMessage
371- boolean hasExceptionCause (@ Exclusive @ Cached GilNode gil ) {
370+ boolean hasExceptionCause (@ Shared ( "gil" ) @ Cached GilNode gil ) {
372371 boolean mustRelease = gil .acquire ();
373372 try {
374373 return cause != null || (!suppressContext && context != null );
@@ -379,7 +378,8 @@ boolean hasExceptionCause(@Exclusive @Cached GilNode gil) {
379378
380379 @ ExportMessage
381380 Object getExceptionCause (
382- @ Shared ("unsupportedProfile" ) @ Cached BranchProfile unsupportedProfile , @ Exclusive @ Cached GilNode gil ) throws UnsupportedMessageException {
381+ @ Shared ("unsupportedProfile" ) @ Cached BranchProfile unsupportedProfile ,
382+ @ Shared ("gil" ) @ Cached GilNode gil ) throws UnsupportedMessageException {
383383 boolean mustRelease = gil .acquire ();
384384 try {
385385 if (cause != null ) {
0 commit comments