8129952: Ensure thread consistency
authorchegar
Wed, 20 Jan 2016 20:51:45 +0000
changeset 37583 60553c2df76e
parent 37582 1be93e82e442
child 37584 0cc00d7a0755
8129952: Ensure thread consistency Reviewed-by: alanb, ahgross, skoivu
jdk/src/java.base/share/classes/java/io/ObjectInputStream.java
--- a/jdk/src/java.base/share/classes/java/io/ObjectInputStream.java	Wed Jan 13 11:24:11 2016 -0800
+++ b/jdk/src/java.base/share/classes/java/io/ObjectInputStream.java	Wed Jan 20 20:51:45 2016 +0000
@@ -1915,6 +1915,8 @@
                 if (obj == null || handles.lookupException(passHandle) != null) {
                     defaultReadFields(null, slotDesc); // skip field values
                 } else if (slotDesc.hasReadObjectMethod()) {
+                    ThreadDeath t = null;
+                    boolean reset = false;
                     SerialCallbackContext oldContext = curContext;
                     if (oldContext != null)
                         oldContext.check();
@@ -1933,10 +1935,19 @@
                          */
                         handles.markException(passHandle, ex);
                     } finally {
-                        curContext.setUsed();
-                        if (oldContext!= null)
-                            oldContext.check();
-                        curContext = oldContext;
+                        do {
+                            try {
+                                curContext.setUsed();
+                                if (oldContext!= null)
+                                    oldContext.check();
+                                curContext = oldContext;
+                                reset = true;
+                            } catch (ThreadDeath x) {
+                                t = x;  // defer until reset is true
+                            }
+                        } while (!reset);
+                        if (t != null)
+                            throw t;
                     }
 
                     /*