@@ -1105,10 +1105,28 @@ public Object call() {
11051105 new Thread (new Runnable () {
11061106 @ Override
11071107 public void run () {
1108- ThreadJob <?>.JobResult <?> result = job .getResult ();
1109- writeMethodResult (reply , context , result );
1108+ boolean entered = false ;
11101109 CommandResult commandResult = new CommandResult (reply );
1111- connection .handleReply (packet , commandResult );
1110+ try {
1111+ ThreadJob <?>.JobResult <?> result = job .getResult ();
1112+ writeMethodResult (reply , context , result );
1113+ } catch (Throwable t ) {
1114+ entered = controller .enterTruffleContext ();
1115+ reply .errorCode (ErrorCodes .INTERNAL );
1116+ // Checkstyle: stop allow error output
1117+ if (entered ) {
1118+ LOGGER .warning (() -> "Internal Espresso error: " + t );
1119+ } else {
1120+ System .err .println ("Internal Espresso error: " + t .getMessage ());
1121+ }
1122+ t .printStackTrace ();
1123+ // Checkstyle: resume allow error output
1124+ } finally {
1125+ connection .handleReply (packet , commandResult );
1126+ if (entered ) {
1127+ controller .leaveTruffleContext ();
1128+ }
1129+ }
11121130 }
11131131 }).start ();
11141132 } catch (Throwable t ) {
@@ -1269,10 +1287,28 @@ public Object call() throws Exception {
12691287 new Thread (new Runnable () {
12701288 @ Override
12711289 public void run () {
1272- ThreadJob <?>.JobResult <?> result = job .getResult ();
1273- writeMethodResult (reply , context , result );
1290+ boolean entered = false ;
12741291 CommandResult commandResult = new CommandResult (reply );
1275- connection .handleReply (packet , commandResult );
1292+ try {
1293+ ThreadJob <?>.JobResult <?> result = job .getResult ();
1294+ writeMethodResult (reply , context , result );
1295+ } catch (Throwable t ) {
1296+ entered = controller .enterTruffleContext ();
1297+ reply .errorCode (ErrorCodes .INTERNAL );
1298+ // Checkstyle: stop allow error output
1299+ if (entered ) {
1300+ LOGGER .warning (() -> "Internal Espresso error: " + t );
1301+ } else {
1302+ System .err .println ("Internal Espresso error: " + t .getMessage ());
1303+ }
1304+ t .printStackTrace ();
1305+ // Checkstyle: resume allow error output
1306+ } finally {
1307+ connection .handleReply (packet , commandResult );
1308+ if (entered ) {
1309+ controller .leaveTruffleContext ();
1310+ }
1311+ }
12761312 }
12771313 }).start ();
12781314 } catch (Throwable t ) {
@@ -1749,10 +1785,28 @@ public Object call() throws Exception {
17491785 new Thread (new Runnable () {
17501786 @ Override
17511787 public void run () {
1752- ThreadJob <?>.JobResult <?> result = job .getResult ();
1753- writeMethodResult (reply , context , result );
1788+ boolean entered = false ;
17541789 CommandResult commandResult = new CommandResult (reply );
1755- connection .handleReply (packet , commandResult );
1790+ try {
1791+ ThreadJob <?>.JobResult <?> result = job .getResult ();
1792+ writeMethodResult (reply , context , result );
1793+ } catch (Throwable t ) {
1794+ entered = controller .enterTruffleContext ();
1795+ reply .errorCode (ErrorCodes .INTERNAL );
1796+ // Checkstyle: stop allow error output
1797+ if (entered ) {
1798+ LOGGER .warning (() -> "Internal Espresso error: " + t );
1799+ } else {
1800+ System .err .println ("Internal Espresso error: " + t .getMessage ());
1801+ }
1802+ t .printStackTrace ();
1803+ // Checkstyle: resume allow error output
1804+ } finally {
1805+ connection .handleReply (packet , commandResult );
1806+ if (entered ) {
1807+ controller .leaveTruffleContext ();
1808+ }
1809+ }
17561810 }
17571811 }).start ();
17581812 } catch (Throwable t ) {
@@ -2974,31 +3028,24 @@ public static void writeValue(byte tag, Object value, PacketStream reply, boolea
29743028 }
29753029
29763030 private static void writeMethodResult (PacketStream reply , JDWPContext context , ThreadJob <?>.JobResult <?> result ) {
2977- try {
2978- if (result .getException () != null ) {
2979- LOGGER .fine (() -> "method threw exception" );
2980- reply .writeByte (TagConstants .OBJECT );
2981- reply .writeLong (0 );
2982- reply .writeByte (TagConstants .OBJECT );
2983- Object guestException = context .getGuestException (result .getException ());
2984- reply .writeLong (context .getIds ().getIdAsLong (guestException ));
2985- } else {
2986- Object value = context .toGuest (result .getResult ());
2987- if (value != null ) {
2988- byte tag = context .getTag (value );
2989- writeValue (tag , value , reply , true , context );
2990- } else { // return value is null
2991- reply .writeByte (TagConstants .OBJECT );
2992- reply .writeLong (0 );
2993- }
2994- // no exception, so zero object ID
3031+ if (result .getException () != null ) {
3032+ reply .writeByte (TagConstants .OBJECT );
3033+ reply .writeLong (0 );
3034+ reply .writeByte (TagConstants .OBJECT );
3035+ Object guestException = context .getGuestException (result .getException ());
3036+ reply .writeLong (context .getIds ().getIdAsLong (guestException ));
3037+ } else {
3038+ Object value = context .toGuest (result .getResult ());
3039+ if (value != null ) {
3040+ byte tag = context .getTag (value );
3041+ writeValue (tag , value , reply , true , context );
3042+ } else { // return value is null
29953043 reply .writeByte (TagConstants .OBJECT );
29963044 reply .writeLong (0 );
29973045 }
2998- } catch (Throwable t ) {
2999- LOGGER .warning (() -> "Internal Espresso error: " + t );
3000- LOGGER .throwing (JDWP .class .getName (), "writeMethodResult" , t );
3001- reply .errorCode (ErrorCodes .INTERNAL );
3046+ // no exception, so zero object ID
3047+ reply .writeByte (TagConstants .OBJECT );
3048+ reply .writeLong (0 );
30023049 }
30033050 }
30043051
0 commit comments