test/java/lang/ref/OOMEInReferenceHandler.java
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File jdk Sdiff test/java/lang/ref

test/java/lang/ref/OOMEInReferenceHandler.java

Print this page




   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /**
  25  * @test
  26  * @bug 7038914
  27  * @summary Verify that the reference handler does not die after an OOME allocating the InterruptedException object
  28  * @run main/othervm -Xmx16M -XX:-UseTLAB OOMEInReferenceHandler
  29  * @author peter.levart@gmail.com
  30  */
  31 
  32 import java.lang.ref.*;
  33 
  34 public class OOMEInReferenceHandler {
  35      static Object[] fillHeap() {
  36          Object[] first = null, last = null;
  37          int size = 1 << 20;
  38          while (size > 0) {
  39              try {
  40                  Object[] array = new Object[size];
  41                  if (first == null) {
  42                      first = array;
  43                  } else {
  44                      last[0] = array;
  45                  }
  46                  last = array;


  90 
  91          // release waste & referent
  92          waste = null;
  93          referent = null;
  94 
  95          // wait at most 10 seconds for success or failure
  96          for (int i = 0; i < 20; i++) {
  97              if (refQueue.poll() != null) {
  98                  // Reference Handler thread still working -> success
  99                  return;
 100              }
 101              System.gc();
 102              Thread.sleep(500L); // wait a little to allow GC to do it's work before allocating objects
 103              if (!referenceHandlerThread.isAlive()) {
 104                  // Reference Handler thread died -> failure
 105                  throw new Exception("Reference Handler thread died.");
 106              }
 107          }
 108 
 109          // no sure answer after 10 seconds
 110          throw new IllegalStateException("Reference Handler thread stuck.");
 111      }
 112 }


   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /**
  25  * @test
  26  * @bug 7038914 8016341
  27  * @summary Verify that the reference handler does not die after an OOME allocating the InterruptedException object
  28  * @run main/othervm -Xmx16M -XX:-UseTLAB OOMEInReferenceHandler
  29  * @author peter.levart@gmail.com
  30  */
  31 
  32 import java.lang.ref.*;
  33 
  34 public class OOMEInReferenceHandler {
  35      static Object[] fillHeap() {
  36          Object[] first = null, last = null;
  37          int size = 1 << 20;
  38          while (size > 0) {
  39              try {
  40                  Object[] array = new Object[size];
  41                  if (first == null) {
  42                      first = array;
  43                  } else {
  44                      last[0] = array;
  45                  }
  46                  last = array;


  90 
  91          // release waste & referent
  92          waste = null;
  93          referent = null;
  94 
  95          // wait at most 10 seconds for success or failure
  96          for (int i = 0; i < 20; i++) {
  97              if (refQueue.poll() != null) {
  98                  // Reference Handler thread still working -> success
  99                  return;
 100              }
 101              System.gc();
 102              Thread.sleep(500L); // wait a little to allow GC to do it's work before allocating objects
 103              if (!referenceHandlerThread.isAlive()) {
 104                  // Reference Handler thread died -> failure
 105                  throw new Exception("Reference Handler thread died.");
 106              }
 107          }
 108 
 109          // no sure answer after 10 seconds
 110          throw new IllegalStateException("Reference Handler thread stuck. weakRef.get(): " + weakRef.get()); 
 111      }
 112 }
test/java/lang/ref/OOMEInReferenceHandler.java
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File