changeset 4379:9bcf6217a374

Merge
author lana
date Thu, 30 Jun 2011 14:18:40 -0700
parents bb481604e929 585cc4a4528d
children 5f3cd0cbad56 0a00216a858c 6bc0e1709d97 7ac6a297f9a0 0ec4b6498a69 c9956a6753fb 4b20375fe623
files src/share/classes/sun/misc/JavaxSecurityAuthKerberosAccess.java test/sun/security/ssl/com/sun/net/ssl/internal/ssl/InputRecord/InterruptedIO.java
diffstat 67 files changed, 2493 insertions(+), 1416 deletions(-) [+]
line wrap: on
line diff
--- a/make/common/Defs-embedded.gmk	Thu Jun 30 14:16:48 2011 -0700
+++ b/make/common/Defs-embedded.gmk	Thu Jun 30 14:18:40 2011 -0700
@@ -60,5 +60,10 @@
   endif
 endif
 
+# NIO Platform specific source file location
+ifdef CROSS_COMPILE_ARCH
+  NIO_PLATFORM_CLASSES_ROOT_DIR = $(CLOSED_PLATFORM_SRC)/classes/
+endif
+
 endif # JAVASE_EMBEDDED
 
--- a/make/common/shared/Defs.gmk	Thu Jun 30 14:16:48 2011 -0700
+++ b/make/common/shared/Defs.gmk	Thu Jun 30 14:18:40 2011 -0700
@@ -195,8 +195,8 @@
 endif
 
 ifndef JDK_MINOR_VERSION
-  JDK_MINOR_VERSION      = 7
-  PREVIOUS_MINOR_VERSION = 6
+  JDK_MINOR_VERSION      = 8
+  PREVIOUS_MINOR_VERSION = 7
 endif
 
 ifndef JDK_MICRO_VERSION
--- a/make/docs/Makefile	Thu Jun 30 14:16:48 2011 -0700
+++ b/make/docs/Makefile	Thu Jun 30 14:18:40 2011 -0700
@@ -223,6 +223,9 @@
 ifeq ($(JDK_MINOR_VERSION),6)
   JDK_IS_FCS = true
 endif
+ifeq ($(JDK_MINOR_VERSION),7)
+  JDK_IS_FCS = true
+endif
 ifeq ($(JDK_IS_FCS),false)
   ifneq ($(MILESTONE), fcs)
     DRAFT_HEADER = <br><strong>DRAFT&nbsp;$(MILESTONE)-$(BUILD_NUMBER)</strong>
--- a/make/java/nio/Makefile	Thu Jun 30 14:16:48 2011 -0700
+++ b/make/java/nio/Makefile	Thu Jun 30 14:18:40 2011 -0700
@@ -255,7 +255,7 @@
 	sun/nio/fs/LinuxWatchService.java \
 	sun/nio/fs/UnixCopyFile.java \
 	sun/nio/fs/UnixNativeDispatcher.java
-	
+
 FILES_gen += \
 	sun/nio/fs/UnixConstants.java
 endif # PLATFORM = linux
@@ -771,7 +771,7 @@
 #
 
 GEN_EX_SH = genExceptions.sh
- 
+
 GEN_EX_CMD = NAWK="$(NAWK)" SH="$(SH)" $(SH) $(GEN_EX_SH)
 
 $(CH_GEN)/%Exception.java: genExceptions.sh $(CH_SRC)/exceptions
@@ -820,14 +820,19 @@
 
 $(GENSOR_EXE) : $(TEMPDIR)/$(GENSOR_SRC)
 	$(prep-target)
-	($(CD) $(TEMPDIR); $(HOST_CC) $(CPPFLAGS) $(LDDFLAGS) \
+	($(CD) $(TEMPDIR); $(CC) $(CPPFLAGS) $(LDDFLAGS) \
 	   -o genSocketOptionRegistry$(EXE_SUFFIX) $(GENSOR_SRC))
 
+ifdef NIO_PLATFORM_CLASSES_ROOT_DIR
+$(SCH_GEN)/SocketOptionRegistry.java: $(NIO_PLATFORM_CLASSES_ROOT_DIR)/sun/nio/ch/SocketOptionRegistry-$(PLATFORM)-$(ARCH).java
+	$(prep-target)
+	$(CP) $< $@
+else 
 $(SCH_GEN)/SocketOptionRegistry.java: $(GENSOR_EXE)
 	$(prep-target)
 	NAWK="$(NAWK)" SH="$(SH)" $(SH) -e addNotices.sh "$(SOR_COPYRIGHT_YEARS)" > $@
 	$(GENSOR_EXE) >> $@
-
+endif
 #
 # Generated sun.nio.cs SingleByte classes
 #
@@ -851,12 +856,18 @@
 
 $(GENUC_EXE) : $(GENUC_SRC)
 	$(prep-target)
-	$(HOST_CC) $(CPPFLAGS) -o $@ $(GENUC_SRC)
+	$(CC) $(CPPFLAGS) -o $@ $(GENUC_SRC)
 
+ifdef NIO_PLATFORM_CLASSES_ROOT_DIR
+$(SFS_GEN)/UnixConstants.java: $(NIO_PLATFORM_CLASSES_ROOT_DIR)/sun/nio/fs/UnixConstants-$(PLATFORM)-$(ARCH).java
+	$(prep-target)
+	$(CP) $< $@
+else
 $(SFS_GEN)/UnixConstants.java: $(GENUC_EXE)
 	$(prep-target)
 	NAWK="$(NAWK)" SH="$(SH)" $(SH) -e addNotices.sh "$(GENUC_COPYRIGHT_YEARS)" > $@
 	$(GENUC_EXE) >> $@
+endif
 
 GENSC_SRC = $(PLATFORM_SRC)/native/sun/nio/fs/genSolarisConstants.c
 
@@ -867,11 +878,17 @@
 
 $(GENSC_EXE) : $(GENSC_SRC)
 	$(prep-target)
-	$(HOST_CC) $(CPPFLAGS) -o $@ $(GENSC_SRC)
+	$(CC) $(CPPFLAGS) -o $@ $(GENSC_SRC)
 
+ifdef NIO_PLATFORM_CLASSES_ROOT_DIR
+$(SFS_GEN)/SolarisConstants.java: $(NIO_PLATFORM_CLASSES_ROOT_DIR)/sun/nio/fs/SolarisConstants-$(PLATFORM)-$(ARCH).java
+	$(prep-target)
+	$(CP) $< $@
+else
 $(SFS_GEN)/SolarisConstants.java: $(GENSC_EXE)
 	$(prep-target)
 	NAWK="$(NAWK)" SH="$(SH)" $(SH) -e addNotices.sh "$(GENSC_COPYRIGHT_YEARS)" > $@
 	$(GENSC_EXE) >> $@
+endif
 
 .PHONY: sources 
--- a/src/share/classes/java/lang/Byte.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/src/share/classes/java/lang/Byte.java	Thu Jun 30 14:18:40 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -324,40 +324,45 @@
     }
 
     /**
-     * Returns the value of this {@code Byte} as a
-     * {@code short}.
+     * Returns the value of this {@code Byte} as a {@code short} after
+     * a widening primitive conversion.
+     * @jls 5.1.2 Widening Primitive Conversions
      */
     public short shortValue() {
         return (short)value;
     }
 
     /**
-     * Returns the value of this {@code Byte} as an
-     * {@code int}.
+     * Returns the value of this {@code Byte} as an {@code int} after
+     * a widening primitive conversion.
+     * @jls 5.1.2 Widening Primitive Conversions
      */
     public int intValue() {
         return (int)value;
     }
 
     /**
-     * Returns the value of this {@code Byte} as a
-     * {@code long}.
+     * Returns the value of this {@code Byte} as a {@code long} after
+     * a widening primitive conversion.
+     * @jls 5.1.2 Widening Primitive Conversions
      */
     public long longValue() {
         return (long)value;
     }
 
     /**
-     * Returns the value of this {@code Byte} as a
-     * {@code float}.
+     * Returns the value of this {@code Byte} as a {@code float} after
+     * a widening primitive conversion.
+     * @jls 5.1.2 Widening Primitive Conversions
      */
     public float floatValue() {
         return (float)value;
     }
 
     /**
-     * Returns the value of this {@code Byte} as a
-     * {@code double}.
+     * Returns the value of this {@code Byte} as a {@code double}
+     * after a widening primitive conversion.
+     * @jls 5.1.2 Widening Primitive Conversions
      */
     public double doubleValue() {
         return (double)value;
--- a/src/share/classes/java/lang/Double.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/src/share/classes/java/lang/Double.java	Thu Jun 30 14:18:40 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -634,11 +634,12 @@
     }
 
     /**
-     * Returns the value of this {@code Double} as a {@code byte} (by
-     * casting to a {@code byte}).
+     * Returns the value of this {@code Double} as a {@code byte}
+     * after a narrowing primitive conversion.
      *
      * @return  the {@code double} value represented by this object
      *          converted to type {@code byte}
+     * @jls 5.1.3 Narrowing Primitive Conversions
      * @since JDK1.1
      */
     public byte byteValue() {
@@ -646,11 +647,12 @@
     }
 
     /**
-     * Returns the value of this {@code Double} as a
-     * {@code short} (by casting to a {@code short}).
+     * Returns the value of this {@code Double} as a {@code short}
+     * after a narrowing primitive conversion.
      *
      * @return  the {@code double} value represented by this object
      *          converted to type {@code short}
+     * @jls 5.1.3 Narrowing Primitive Conversions
      * @since JDK1.1
      */
     public short shortValue() {
@@ -658,8 +660,9 @@
     }
 
     /**
-     * Returns the value of this {@code Double} as an
-     * {@code int} (by casting to type {@code int}).
+     * Returns the value of this {@code Double} as an {@code int}
+     * after a narrowing primitive conversion.
+     * @jls 5.1.3 Narrowing Primitive Conversions
      *
      * @return  the {@code double} value represented by this object
      *          converted to type {@code int}
@@ -669,22 +672,24 @@
     }
 
     /**
-     * Returns the value of this {@code Double} as a
-     * {@code long} (by casting to type {@code long}).
+     * Returns the value of this {@code Double} as a {@code long}
+     * after a narrowing primitive conversion.
      *
      * @return  the {@code double} value represented by this object
      *          converted to type {@code long}
+     * @jls 5.1.3 Narrowing Primitive Conversions
      */
     public long longValue() {
         return (long)value;
     }
 
     /**
-     * Returns the {@code float} value of this
-     * {@code Double} object.
+     * Returns the value of this {@code Double} as a {@code float}
+     * after a narrowing primitive conversion.
      *
      * @return  the {@code double} value represented by this object
      *          converted to type {@code float}
+     * @jls 5.1.3 Narrowing Primitive Conversions
      * @since JDK1.0
      */
     public float floatValue() {
@@ -692,8 +697,7 @@
     }
 
     /**
-     * Returns the {@code double} value of this
-     * {@code Double} object.
+     * Returns the {@code double} value of this {@code Double} object.
      *
      * @return the {@code double} value represented by this object
      */
--- a/src/share/classes/java/lang/Float.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/src/share/classes/java/lang/Float.java	Thu Jun 30 14:18:40 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -556,22 +556,24 @@
     }
 
     /**
-     * Returns the value of this {@code Float} as a {@code byte} (by
-     * casting to a {@code byte}).
+     * Returns the value of this {@code Float} as a {@code byte} after
+     * a narrowing primitive conversion.
      *
      * @return  the {@code float} value represented by this object
      *          converted to type {@code byte}
+     * @jls 5.1.3 Narrowing Primitive Conversions
      */
     public byte byteValue() {
         return (byte)value;
     }
 
     /**
-     * Returns the value of this {@code Float} as a {@code short} (by
-     * casting to a {@code short}).
+     * Returns the value of this {@code Float} as a {@code short}
+     * after a narrowing primitive conversion.
      *
      * @return  the {@code float} value represented by this object
      *          converted to type {@code short}
+     * @jls 5.1.3 Narrowing Primitive Conversions
      * @since JDK1.1
      */
     public short shortValue() {
@@ -579,22 +581,24 @@
     }
 
     /**
-     * Returns the value of this {@code Float} as an {@code int} (by
-     * casting to type {@code int}).
+     * Returns the value of this {@code Float} as an {@code int} after
+     * a narrowing primitive conversion.
      *
      * @return  the {@code float} value represented by this object
      *          converted to type {@code int}
+     * @jls 5.1.3 Narrowing Primitive Conversions
      */
     public int intValue() {
         return (int)value;
     }
 
     /**
-     * Returns value of this {@code Float} as a {@code long} (by
-     * casting to type {@code long}).
+     * Returns value of this {@code Float} as a {@code long} after a
+     * narrowing primitive conversion.
      *
      * @return  the {@code float} value represented by this object
      *          converted to type {@code long}
+     * @jls 5.1.3 Narrowing Primitive Conversions
      */
     public long longValue() {
         return (long)value;
@@ -610,11 +614,12 @@
     }
 
     /**
-     * Returns the {@code double} value of this {@code Float} object.
+     * Returns the value of this {@code Float} as a {@code double}
+     * after a widening primitive conversion.
      *
      * @return the {@code float} value represented by this
-     *         object is converted to type {@code double} and the
-     *         result of the conversion is returned.
+     *         object converted to type {@code double}
+     * @jls 5.1.2 Widening Primitive Conversions
      */
     public double doubleValue() {
         return (double)value;
--- a/src/share/classes/java/lang/Integer.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/src/share/classes/java/lang/Integer.java	Thu Jun 30 14:18:40 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -678,16 +678,18 @@
     }
 
     /**
-     * Returns the value of this {@code Integer} as a
-     * {@code byte}.
+     * Returns the value of this {@code Integer} as a {@code byte}
+     * after a narrowing primitive conversion.
+     * @jls 5.1.3 Narrowing Primitive Conversions
      */
     public byte byteValue() {
         return (byte)value;
     }
 
     /**
-     * Returns the value of this {@code Integer} as a
-     * {@code short}.
+     * Returns the value of this {@code Integer} as a {@code short}
+     * after a narrowing primitive conversion.
+     * @jls 5.1.3 Narrowing Primitive Conversions
      */
     public short shortValue() {
         return (short)value;
@@ -702,24 +704,27 @@
     }
 
     /**
-     * Returns the value of this {@code Integer} as a
-     * {@code long}.
+     * Returns the value of this {@code Integer} as a {@code long}
+     * after a widening primitive conversion.
+     * @jls 5.1.2 Widening Primitive Conversions
      */
     public long longValue() {
         return (long)value;
     }
 
     /**
-     * Returns the value of this {@code Integer} as a
-     * {@code float}.
+     * Returns the value of this {@code Integer} as a {@code float}
+     * after a widening primitive conversion.
+     * @jls 5.1.2 Widening Primitive Conversions
      */
     public float floatValue() {
         return (float)value;
     }
 
     /**
-     * Returns the value of this {@code Integer} as a
-     * {@code double}.
+     * Returns the value of this {@code Integer} as a {@code double}
+     * after a widening primitive conversion.
+     * @jls 5.1.2 Widening Primitive Conversions
      */
     public double doubleValue() {
         return (double)value;
--- a/src/share/classes/java/lang/Long.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/src/share/classes/java/lang/Long.java	Thu Jun 30 14:18:40 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1994, 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -703,24 +703,27 @@
     }
 
     /**
-     * Returns the value of this {@code Long} as a
-     * {@code byte}.
+     * Returns the value of this {@code Long} as a {@code byte} after
+     * a narrowing primitive conversion.
+     * @jls 5.1.3 Narrowing Primitive Conversions
      */
     public byte byteValue() {
         return (byte)value;
     }
 
     /**
-     * Returns the value of this {@code Long} as a
-     * {@code short}.
+     * Returns the value of this {@code Long} as a {@code short} after
+     * a narrowing primitive conversion.
+     * @jls 5.1.3 Narrowing Primitive Conversions
      */
     public short shortValue() {
         return (short)value;
     }
 
     /**
-     * Returns the value of this {@code Long} as an
-     * {@code int}.
+     * Returns the value of this {@code Long} as an {@code int} after
+     * a narrowing primitive conversion.
+     * @jls 5.1.3 Narrowing Primitive Conversions
      */
     public int intValue() {
         return (int)value;
@@ -735,16 +738,18 @@
     }
 
     /**
-     * Returns the value of this {@code Long} as a
-     * {@code float}.
+     * Returns the value of this {@code Long} as a {@code float} after
+     * a widening primitive conversion.
+     * @jls 5.1.2 Widening Primitive Conversions
      */
     public float floatValue() {
         return (float)value;
     }
 
     /**
-     * Returns the value of this {@code Long} as a
-     * {@code double}.
+     * Returns the value of this {@code Long} as a {@code double}
+     * after a widening primitive conversion.
+     * @jls 5.1.2 Widening Primitive Conversions
      */
     public double doubleValue() {
         return (double)value;
--- a/src/share/classes/java/lang/Number.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/src/share/classes/java/lang/Number.java	Thu Jun 30 14:18:40 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1994, 2001, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,69 +26,78 @@
 package java.lang;
 
 /**
- * The abstract class <code>Number</code> is the superclass of classes
- * <code>BigDecimal</code>, <code>BigInteger</code>,
- * <code>Byte</code>, <code>Double</code>, <code>Float</code>,
- * <code>Integer</code>, <code>Long</code>, and <code>Short</code>.
- * <p>
- * Subclasses of <code>Number</code> must provide methods to convert
- * the represented numeric value to <code>byte</code>, <code>double</code>,
- * <code>float</code>, <code>int</code>, <code>long</code>, and
- * <code>short</code>.
+ * The abstract class {@code Number} is the superclass of platform
+ * classes representing numeric values that are convertible to the
+ * primitive types {@code byte}, {@code double}, {@code float}, {@code
+ * int}, {@code long}, and {@code short}.
+ *
+ * The specific semantics of the conversion from the numeric value of
+ * a particular {@code Number} implementation to a given primitive
+ * type is defined by the {@code Number} implementation in question.
+ *
+ * For platform classes, the conversion is often analogous to a
+ * narrowing primitive conversion or a widening primitive conversion
+ * as defining in <cite>The Java&trade; Language Specification</cite>
+ * for converting between primitive types.  Therefore, conversions may
+ * lose information about the overall magnitude of a numeric value, may
+ * lose precision, and may even return a result of a different sign
+ * than the input.
+ *
+ * See the documentation of a given {@code Number} implementation for
+ * conversion details.
  *
  * @author      Lee Boynton
  * @author      Arthur van Hoff
- * @see     java.lang.Byte
- * @see     java.lang.Double
- * @see     java.lang.Float
- * @see     java.lang.Integer
- * @see     java.lang.Long
- * @see     java.lang.Short
+ * @jls 5.1.2 Widening Primitive Conversions
+ * @jls 5.1.3 Narrowing Primitive Conversions
  * @since   JDK1.0
  */
 public abstract class Number implements java.io.Serializable {
     /**
-     * Returns the value of the specified number as an <code>int</code>.
-     * This may involve rounding or truncation.
+     * Returns the value of the specified number as an {@code int},
+     * which may involve rounding or truncation.
      *
      * @return  the numeric value represented by this object after conversion
-     *          to type <code>int</code>.
+     *          to type {@code int}.
      */
     public abstract int intValue();
 
     /**
-     * Returns the value of the specified number as a <code>long</code>.
-     * This may involve rounding or truncation.
+     * Returns the value of the specified number as a {@code long},
+     * which may involve rounding or truncation.
      *
      * @return  the numeric value represented by this object after conversion
-     *          to type <code>long</code>.
+     *          to type {@code long}.
      */
     public abstract long longValue();
 
     /**
-     * Returns the value of the specified number as a <code>float</code>.
-     * This may involve rounding.
+     * Returns the value of the specified number as a {@code float},
+     * which may involve rounding.
      *
      * @return  the numeric value represented by this object after conversion
-     *          to type <code>float</code>.
+     *          to type {@code float}.
      */
     public abstract float floatValue();
 
     /**
-     * Returns the value of the specified number as a <code>double</code>.
-     * This may involve rounding.
+     * Returns the value of the specified number as a {@code double},
+     * which may involve rounding.
      *
      * @return  the numeric value represented by this object after conversion
-     *          to type <code>double</code>.
+     *          to type {@code double}.
      */
     public abstract double doubleValue();
 
     /**
-     * Returns the value of the specified number as a <code>byte</code>.
-     * This may involve rounding or truncation.
+     * Returns the value of the specified number as a {@code byte},
+     * which may involve rounding or truncation.
+     *
+     * <p>This implementation returns the result of {@link #intValue} cast
+     * to a {@code byte}.
      *
      * @return  the numeric value represented by this object after conversion
-     *          to type <code>byte</code>.
+     *          to type {@code byte}.
      * @since   JDK1.1
      */
     public byte byteValue() {
@@ -96,11 +105,14 @@
     }
 
     /**
-     * Returns the value of the specified number as a <code>short</code>.
-     * This may involve rounding or truncation.
+     * Returns the value of the specified number as a {@code short},
+     * which may involve rounding or truncation.
+     *
+     * <p>This implementation returns the result of {@link #intValue} cast
+     * to a {@code short}.
      *
      * @return  the numeric value represented by this object after conversion
-     *          to type <code>short</code>.
+     *          to type {@code short}.
      * @since   JDK1.1
      */
     public short shortValue() {
--- a/src/share/classes/java/lang/Short.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/src/share/classes/java/lang/Short.java	Thu Jun 30 14:18:40 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -321,8 +321,9 @@
     }
 
     /**
-     * Returns the value of this {@code Short} as a
-     * {@code byte}.
+     * Returns the value of this {@code Short} as a {@code byte} after
+     * a narrowing primitive conversion.
+     * @jls 5.1.3 Narrowing Primitive Conversions
      */
     public byte byteValue() {
         return (byte)value;
@@ -337,32 +338,36 @@
     }
 
     /**
-     * Returns the value of this {@code Short} as an
-     * {@code int}.
+     * Returns the value of this {@code Short} as an {@code int} after
+     * a widening primitive conversion.
+     * @jls 5.1.2 Widening Primitive Conversions
      */
     public int intValue() {
         return (int)value;
     }
 
     /**
-     * Returns the value of this {@code Short} as a
-     * {@code long}.
+     * Returns the value of this {@code Short} as a {@code long} after
+     * a widening primitive conversion.
+     * @jls 5.1.2 Widening Primitive Conversions
      */
     public long longValue() {
         return (long)value;
     }
 
     /**
-     * Returns the value of this {@code Short} as a
-     * {@code float}.
+     * Returns the value of this {@code Short} as a {@code float}
+     * after a widening primitive conversion.
+     * @jls 5.1.2 Widening Primitive Conversions
      */
     public float floatValue() {
         return (float)value;
     }
 
     /**
-     * Returns the value of this {@code Short} as a
-     * {@code double}.
+     * Returns the value of this {@code Short} as a {@code double}
+     * after a widening primitive conversion.
+     * @jls 5.1.2 Widening Primitive Conversions
      */
     public double doubleValue() {
         return (double)value;
--- a/src/share/classes/java/lang/annotation/IncompleteAnnotationException.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/src/share/classes/java/lang/annotation/IncompleteAnnotationException.java	Thu Jun 30 14:18:40 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -41,21 +41,23 @@
 public class IncompleteAnnotationException extends RuntimeException {
     private static final long serialVersionUID = 8445097402741811912L;
 
-    private Class annotationType;
+    private Class<? extends Annotation> annotationType;
     private String elementName;
 
-
     /**
      * Constructs an IncompleteAnnotationException to indicate that
      * the named element was missing from the specified annotation type.
      *
      * @param annotationType the Class object for the annotation type
      * @param elementName the name of the missing element
+     * @throws NullPointerException if either parameter is {@code null}
      */
     public IncompleteAnnotationException(
             Class<? extends Annotation> annotationType,
             String elementName) {
-        super(annotationType.getName() + " missing element " + elementName);
+        super(annotationType.getName().toString() +
+              " missing element " +
+              elementName.toString());
 
         this.annotationType = annotationType;
         this.elementName = elementName;
--- a/src/share/classes/java/lang/reflect/GenericSignatureFormatError.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/src/share/classes/java/lang/reflect/GenericSignatureFormatError.java	Thu Jun 30 14:18:40 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -35,4 +35,22 @@
  */
 public class GenericSignatureFormatError extends ClassFormatError {
     private static final long serialVersionUID = 6709919147137911034L;
+
+    /**
+     * Constructs a new {@code GenericSignatureFormatError}.
+     *
+     */
+    public GenericSignatureFormatError() {
+        super();
+    }
+
+    /**
+     * Constructs a new {@code GenericSignatureFormatError} with the
+     * specified message.
+     *
+     * @param message the detail message, may be {@code null}
+     */
+    public GenericSignatureFormatError(String message) {
+        super(message);
+    }
 }
--- a/src/share/classes/java/rmi/server/UID.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/src/share/classes/java/rmi/server/UID.java	Thu Jun 30 14:18:40 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -118,15 +118,17 @@
                 boolean done = false;
                 while (!done) {
                     long now = System.currentTimeMillis();
-                    if (now <= lastTime) {
+                    if (now == lastTime) {
                         // wait for time to change
                         try {
-                            Thread.currentThread().sleep(1);
+                            Thread.sleep(1);
                         } catch (InterruptedException e) {
                             interrupted = true;
                         }
                     } else {
-                        lastTime = now;
+                        // If system time has gone backwards increase
+                        // original by 1ms to maintain uniqueness
+                        lastTime = (now < lastTime) ? lastTime+1 : now;
                         lastCount = Short.MIN_VALUE;
                         done = true;
                     }
--- a/src/share/classes/java/util/Random.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/src/share/classes/java/util/Random.java	Thu Jun 30 14:18:40 2011 -0700
@@ -118,7 +118,13 @@
      * @see   #setSeed(long)
      */
     public Random(long seed) {
-        this.seed = new AtomicLong(initialScramble(seed));
+        if (getClass() == Random.class)
+            this.seed = new AtomicLong(initialScramble(seed));
+        else {
+            // subclass might have overriden setSeed
+            this.seed = new AtomicLong();
+            setSeed(seed);
+        }
     }
 
     private static long initialScramble(long seed) {
--- a/src/share/classes/java/util/concurrent/atomic/AtomicInteger.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/src/share/classes/java/util/concurrent/atomic/AtomicInteger.java	Thu Jun 30 14:18:40 2011 -0700
@@ -246,18 +246,37 @@
     }
 
 
+    /**
+     * Returns the value of this {@code AtomicInteger} as an
+     * {@code int}.
+     */
     public int intValue() {
         return get();
     }
 
+    /**
+     * Returns the value of this {@code AtomicInteger} as a {@code long}
+     * after a widening primitive conversion.
+     * @jls 5.1.2 Widening Primitive Conversions
+     */
     public long longValue() {
         return (long)get();
     }
 
+    /**
+     * Returns the value of this {@code AtomicInteger} as a {@code float}
+     * after a widening primitive conversion.
+     * @jls 5.1.2 Widening Primitive Conversions
+     */
     public float floatValue() {
         return (float)get();
     }
 
+    /**
+     * Returns the value of this {@code AtomicInteger} as a {@code double}
+     * after a widening primitive conversion.
+     * @jls 5.1.2 Widening Primitive Conversions
+     */
     public double doubleValue() {
         return (double)get();
     }
--- a/src/share/classes/java/util/concurrent/atomic/AtomicLong.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/src/share/classes/java/util/concurrent/atomic/AtomicLong.java	Thu Jun 30 14:18:40 2011 -0700
@@ -260,18 +260,37 @@
     }
 
 
+    /**
+     * Returns the value of this {@code AtomicLong} as an {@code int}
+     * after a narrowing primitive conversion.
+     * @jls 5.1.3 Narrowing Primitive Conversions
+     */
     public int intValue() {
         return (int)get();
     }
 
+    /**
+     * Returns the value of this {@code AtomicLong} as a {@code long}
+     * value.
+     */
     public long longValue() {
         return get();
     }
 
+    /**
+     * Returns the value of this {@code AtomicLong} as a {@code float}
+     * after a widening primitive conversion.
+     * @jls 5.1.2 Widening Primitive Conversions
+     */
     public float floatValue() {
         return (float)get();
     }
 
+    /**
+     * Returns the value of this {@code AtomicLong} as a {@code
+     * double} after a widening primitive conversion.
+     * @jls 5.1.2 Widening Primitive Conversions
+     */
     public double doubleValue() {
         return (double)get();
     }
--- a/src/share/classes/java/util/logging/Logger.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/src/share/classes/java/util/logging/Logger.java	Thu Jun 30 14:18:40 2011 -0700
@@ -251,7 +251,10 @@
     protected Logger(String name, String resourceBundleName) {
         this.manager = LogManager.getLogManager();
         if (resourceBundleName != null) {
-            // Note: we may get a MissingResourceException here.
+            // MissingResourceException or IllegalArgumentException can
+            // be thrown by setupResourceInfo(). Since this is the Logger
+            // constructor, the resourceBundleName field is null so
+            // IllegalArgumentException cannot happen here.
             setupResourceInfo(resourceBundleName);
         }
         this.name = name;
@@ -374,13 +377,10 @@
     public static Logger getLogger(String name, String resourceBundleName) {
         LogManager manager = LogManager.getLogManager();
         Logger result = manager.demandLogger(name);
-        if (result.resourceBundleName == null) {
-            // Note: we may get a MissingResourceException here.
-            result.setupResourceInfo(resourceBundleName);
-        } else if (!result.resourceBundleName.equals(resourceBundleName)) {
-            throw new IllegalArgumentException(result.resourceBundleName +
-                                " != " + resourceBundleName);
-        }
+
+        // MissingResourceException or IllegalArgumentException can be
+        // thrown by setupResourceInfo().
+        result.setupResourceInfo(resourceBundleName);
         return result;
     }
 
@@ -1353,14 +1353,29 @@
     }
 
     // Private utility method to initialize our one entry
-    // resource bundle cache.
+    // resource bundle name cache.
     // Note: for consistency reasons, we are careful to check
     // that a suitable ResourceBundle exists before setting the
-    // ResourceBundleName.
+    // resourceBundleName field.
+    // Synchronized to prevent races in setting the field.
     private synchronized void setupResourceInfo(String name) {
         if (name == null) {
             return;
         }
+
+        if (resourceBundleName != null) {
+            // this Logger already has a ResourceBundle
+
+            if (resourceBundleName.equals(name)) {
+                // the names match so there is nothing more to do
+                return;
+            }
+
+            // cannot change ResourceBundles once they are set
+            throw new IllegalArgumentException(
+                resourceBundleName + " != " + name);
+        }
+
         ResourceBundle rb = findResourceBundle(name);
         if (rb == null) {
             // We've failed to find an expected ResourceBundle.
--- a/src/share/classes/javax/security/auth/kerberos/JavaxSecurityAuthKerberosAccessImpl.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/src/share/classes/javax/security/auth/kerberos/JavaxSecurityAuthKerberosAccessImpl.java	Thu Jun 30 14:18:40 2011 -0700
@@ -25,7 +25,7 @@
 
 package javax.security.auth.kerberos;
 
-import sun.misc.JavaxSecurityAuthKerberosAccess;
+import sun.security.krb5.JavaxSecurityAuthKerberosAccess;
 import sun.security.krb5.EncryptionKey;
 import sun.security.krb5.PrincipalName;
 
--- a/src/share/classes/javax/security/auth/kerberos/KeyTab.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/src/share/classes/javax/security/auth/kerberos/KeyTab.java	Thu Jun 30 14:18:40 2011 -0700
@@ -27,8 +27,8 @@
 
 import java.io.File;
 import java.util.Objects;
-import sun.misc.SharedSecrets;
 import sun.security.krb5.EncryptionKey;
+import sun.security.krb5.KerberosSecrets;
 import sun.security.krb5.PrincipalName;
 import sun.security.krb5.RealmException;
 
@@ -74,9 +74,9 @@
     // is maintained in snapshot, this field is never "resolved".
     private final File file;
 
-    // Set up JavaxSecurityAuthKerberosAccess in SharedSecrets
+    // Set up JavaxSecurityAuthKerberosAccess in KerberosSecrets
     static {
-        SharedSecrets.setJavaxSecurityAuthKerberosAccess(
+        KerberosSecrets.setJavaxSecurityAuthKerberosAccess(
                 new JavaxSecurityAuthKerberosAccessImpl());
     }
 
--- a/src/share/classes/sun/launcher/resources/launcher.properties	Thu Jun 30 14:16:48 2011 -0700
+++ b/src/share/classes/sun/launcher/resources/launcher.properties	Thu Jun 30 14:18:40 2011 -0700
@@ -43,7 +43,7 @@
 \                  and ZIP archives to search for class files.\n\
 \    -D<name>=<value>\n\
 \                  set a system property\n\
-\    -verbose[:class|gc|jni]\n\
+\    -verbose:[class|gc|jni]\n\
 \                  enable verbose output\n\
 \    -version      print product version and exit\n\
 \    -version:<value>\n\
--- a/src/share/classes/sun/misc/JavaxSecurityAuthKerberosAccess.java	Thu Jun 30 14:16:48 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,43 +0,0 @@
-/*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package sun.misc;
-
-import javax.security.auth.kerberos.KeyTab;
-import sun.security.krb5.EncryptionKey;
-import sun.security.krb5.PrincipalName;
-
-/**
- * An unsafe tunnel to get non-public access to classes in the
- * javax.security.auth.kerberos package.
- */
-public interface JavaxSecurityAuthKerberosAccess {
-    /**
-     * Returns keys for a principal in a keytab.
-     * @return the keys, never null, can be empty.
-     */
-    public EncryptionKey[] keyTabGetEncryptionKeys(
-            KeyTab ktab, PrincipalName principal);
-}
--- a/src/share/classes/sun/misc/SharedSecrets.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/src/share/classes/sun/misc/SharedSecrets.java	Thu Jun 30 14:18:40 2011 -0700
@@ -29,7 +29,6 @@
 import java.io.Console;
 import java.io.FileDescriptor;
 import java.security.ProtectionDomain;
-import javax.security.auth.kerberos.KeyTab;
 
 import java.security.AccessController;
 
@@ -52,7 +51,6 @@
     private static JavaIOFileDescriptorAccess javaIOFileDescriptorAccess;
     private static JavaSecurityProtectionDomainAccess javaSecurityProtectionDomainAccess;
     private static JavaSecurityAccess javaSecurityAccess;
-    private static JavaxSecurityAuthKerberosAccess javaxSecurityAuthKerberosAccess;
 
     public static JavaUtilJarAccess javaUtilJarAccess() {
         if (javaUtilJarAccess == null) {
@@ -141,16 +139,4 @@
         }
         return javaSecurityAccess;
     }
-
-    public static void setJavaxSecurityAuthKerberosAccess
-            (JavaxSecurityAuthKerberosAccess jsaka) {
-        javaxSecurityAuthKerberosAccess = jsaka;
-    }
-
-    public static JavaxSecurityAuthKerberosAccess
-            getJavaxSecurityAuthKerberosAccess() {
-        if (javaxSecurityAuthKerberosAccess == null)
-            unsafe.ensureClassInitialized(KeyTab.class);
-        return javaxSecurityAuthKerberosAccess;
-    }
 }
--- a/src/share/classes/sun/security/jgss/krb5/Krb5Util.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/src/share/classes/sun/security/jgss/krb5/Krb5Util.java	Thu Jun 30 14:18:40 2011 -0700
@@ -44,7 +44,7 @@
 import java.util.List;
 import java.util.Objects;
 import java.util.Set;
-import sun.misc.SharedSecrets;
+import sun.security.krb5.KerberosSecrets;
 import sun.security.krb5.PrincipalName;
 /**
  * Utilities for obtaining and converting Kerberos tickets.
@@ -378,7 +378,7 @@
      */
     public static EncryptionKey[] keysFromJavaxKeyTab(
             KeyTab ktab, PrincipalName cname) {
-        return SharedSecrets.getJavaxSecurityAuthKerberosAccess().
+        return KerberosSecrets.getJavaxSecurityAuthKerberosAccess().
                 keyTabGetEncryptionKeys(ktab, cname);
     }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/sun/security/krb5/JavaxSecurityAuthKerberosAccess.java	Thu Jun 30 14:18:40 2011 -0700
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.security.krb5;
+
+import javax.security.auth.kerberos.KeyTab;
+import sun.security.krb5.EncryptionKey;
+import sun.security.krb5.PrincipalName;
+
+/**
+ * An unsafe tunnel to get non-public access to classes in the
+ * javax.security.auth.kerberos package.
+ */
+public interface JavaxSecurityAuthKerberosAccess {
+    /**
+     * Returns keys for a principal in a keytab.
+     * @return the keys, never null, can be empty.
+     */
+    public EncryptionKey[] keyTabGetEncryptionKeys(
+            KeyTab ktab, PrincipalName principal);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/sun/security/krb5/KerberosSecrets.java	Thu Jun 30 14:18:40 2011 -0700
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.security.krb5;
+
+import javax.security.auth.kerberos.KeyTab;
+import sun.misc.Unsafe;
+
+public class KerberosSecrets {
+    private static final Unsafe unsafe = Unsafe.getUnsafe();
+    private static JavaxSecurityAuthKerberosAccess javaxSecurityAuthKerberosAccess;
+
+    public static void setJavaxSecurityAuthKerberosAccess
+            (JavaxSecurityAuthKerberosAccess jsaka) {
+        javaxSecurityAuthKerberosAccess = jsaka;
+    }
+
+    public static JavaxSecurityAuthKerberosAccess
+            getJavaxSecurityAuthKerberosAccess() {
+        if (javaxSecurityAuthKerberosAccess == null)
+            unsafe.ensureClassInitialized(KeyTab.class);
+        return javaxSecurityAuthKerberosAccess;
+    }
+}
--- a/src/share/classes/sun/security/tools/KeyTool.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/src/share/classes/sun/security/tools/KeyTool.java	Thu Jun 30 14:18:40 2011 -0700
@@ -4193,15 +4193,11 @@
         return "Pair[" + fst + "," + snd + "]";
     }
 
-    private static boolean equals(Object x, Object y) {
-        return (x == null && y == null) || (x != null && x.equals(y));
-    }
-
     public boolean equals(Object other) {
         return
             other instanceof Pair &&
-            equals(fst, ((Pair)other).fst) &&
-            equals(snd, ((Pair)other).snd);
+            Objects.equals(fst, ((Pair)other).fst) &&
+            Objects.equals(snd, ((Pair)other).snd);
     }
 
     public int hashCode() {
--- a/src/share/classes/sun/security/x509/DistributionPoint.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/src/share/classes/sun/security/x509/DistributionPoint.java	Thu Jun 30 14:18:40 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -319,13 +319,6 @@
     }
 
     /**
-     * Utility function for a.equals(b) where both a and b may be null.
-     */
-    private static boolean equals(Object a, Object b) {
-        return (a == null) ? (b == null) : a.equals(b);
-    }
-
-    /**
      * Compare an object to this DistributionPoint for equality.
      *
      * @param obj Object to be compared to this
@@ -340,9 +333,9 @@
         }
         DistributionPoint other = (DistributionPoint)obj;
 
-        boolean equal = equals(this.fullName, other.fullName)
-                     && equals(this.relativeName, other.relativeName)
-                     && equals(this.crlIssuer, other.crlIssuer)
+        boolean equal = Objects.equals(this.fullName, other.fullName)
+                     && Objects.equals(this.relativeName, other.relativeName)
+                     && Objects.equals(this.crlIssuer, other.crlIssuer)
                      && Arrays.equals(this.reasonFlags, other.reasonFlags);
         return equal;
     }
--- a/src/share/classes/sun/security/x509/DistributionPointName.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/src/share/classes/sun/security/x509/DistributionPointName.java	Thu Jun 30 14:18:40 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -201,8 +201,8 @@
         }
         DistributionPointName other = (DistributionPointName)obj;
 
-        return equals(this.fullName, other.fullName) &&
-               equals(this.relativeName, other.relativeName);
+        return Objects.equals(this.fullName, other.fullName) &&
+               Objects.equals(this.relativeName, other.relativeName);
     }
 
     /**
@@ -239,11 +239,4 @@
 
         return sb.toString();
     }
-
-    /*
-     * Utility function for a.equals(b) where both a and b may be null.
-     */
-    private static boolean equals(Object a, Object b) {
-        return (a == null) ? (b == null) : a.equals(b);
-    }
 }
--- a/src/windows/classes/sun/security/krb5/internal/tools/Klist.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/src/windows/classes/sun/security/krb5/internal/tools/Klist.java	Thu Jun 30 14:18:40 2011 -0700
@@ -95,14 +95,17 @@
             }
             break;
         case 'k':
-            try {
-                KeyTab ktab = KeyTab.getInstance(klist.name);
-                klist.target = ktab;
-                klist.name = ktab.tabName();
-            } catch (Exception e) {
-                klist.displayMessage("KeyTab");
+            KeyTab ktab = KeyTab.getInstance(klist.name);
+            if (ktab.isMissing()) {
+                System.out.println("KeyTab " + klist.name + " not found.");
+                System.exit(-1);
+            } else if (!ktab.isValid()) {
+                System.out.println("KeyTab " + klist.name
+                        + " format not supported.");
                 System.exit(-1);
             }
+            klist.target = ktab;
+            klist.name = ktab.tabName();
             klist.displayTab();
             break;
         default:
--- a/test/Makefile	Thu Jun 30 14:16:48 2011 -0700
+++ b/test/Makefile	Thu Jun 30 14:18:40 2011 -0700
@@ -510,13 +510,17 @@
 
 # Stable samevm testruns (minus items from PROBLEM_LIST)
 JDK_ALL_TARGETS += jdk_nio3
-jdk_nio3: $(call TestDirs, com/sun/nio sun/nio)
+jdk_nio3: $(call TestDirs, sun/nio)
 	$(call RunSamevmBatch)
 
 # All nio tests
 jdk_nio: jdk_nio1 jdk_nio2 jdk_nio3
 	@$(SummaryInfo)
 
+# Stable samevm testruns (minus items from PROBLEM_LIST)
+jdk_sctp: $(call TestDirs, com/sun/nio/sctp)
+	$(call RunSamevmBatch)
+
 # Stable othervm testruns (minus items from PROBLEM_LIST)
 #   Using samevm has serious problems with these tests
 JDK_ALL_TARGETS += jdk_rmi
@@ -532,7 +536,7 @@
 #   Using samevm has serious problems with these tests
 JDK_ALL_TARGETS += jdk_security2
 jdk_security2: $(call TestDirs, javax/crypto com/sun/crypto)
-	$(call RunOthervmBatch)
+	$(call RunSamevmBatch)
 
 # Stable othervm testruns (minus items from PROBLEM_LIST)
 #   Using samevm has serious problems with these tests
--- a/test/ProblemList.txt	Thu Jun 30 14:16:48 2011 -0700
+++ b/test/ProblemList.txt	Thu Jun 30 14:18:40 2011 -0700
@@ -198,18 +198,6 @@
 # requires junit
 java/lang/invoke/InvokeDynamicPrintArgs.java                    generic-all
 
-# Times out on solaris 10 sparc
-java/lang/ClassLoader/Assert.java				generic-all
-
-# Solaris sparc, samevm, java.lang.Exception: Read from closed pipe hangs
-java/lang/Runtime/exec/SleepyCat.java				generic-all
-
-# Times out on solaris sparc -server
-java/lang/ThreadLocal/MemoryLeak.java			 	solaris-all
-
-# Windows X64, RuntimeException: MyThread expected to have RUNNABLE but got WAITING
-java/lang/Thread/ThreadStateTest.java				generic-all
-
 ############################################################################
 
 # jdk_management
@@ -296,7 +284,6 @@
 # jdk_misc
 
 # Need to be marked othervm, or changed to be samevm safe
-com/sun/jndi/ldap/ReadTimeoutTest.java				generic-all
 com/sun/jndi/rmi/registry/RegistryContext/UnbindIdempotent.java	generic-all
 
 # Need to be marked othervm, or changed to be samevm safe
@@ -380,30 +367,6 @@
 # 6963118
 java/nio/channels/Selector/Wakeup.java                          windows-all
 
-# 6959891
-com/sun/nio/sctp/SctpChannel/SocketOptionTests.java
-
-# Fails with -ea -esa, Assertion error, but only on Solaris 10 machines?
-com/sun/nio/sctp/SctpChannel/Send.java				generic-all
-com/sun/nio/sctp/SctpChannel/Shutdown.java			generic-all
-
-# Fails on OpenSolaris, IllegalStateException: Cannot add or remove addresses
-#    from a channel that is bound to the wildcard address
-com/sun/nio/sctp/SctpChannel/Bind.java				generic-all
-
-# Failed on OpenSolaris, java.lang.AssertionError: Unknown event type
-com/sun/nio/sctp/SctpChannel/Receive.java			generic-all
-
-# Solaris 11 gave assert error and "connection refused", samevm issues?
-com/sun/nio/sctp/SctpServerChannel/NonBlockingAccept.java 	generic-all
-
-# Fails with othervm on solaris 11 i586
-com/sun/nio/sctp/SctpChannel/CommUp.java			generic-all
-com/sun/nio/sctp/SctpChannel/Connect.java			generic-all
-com/sun/nio/sctp/SctpMultiChannel/Branch.java			generic-all
-com/sun/nio/sctp/SctpMultiChannel/Send.java			generic-all
-com/sun/nio/sctp/SctpMultiChannel/SocketOptionTests.java	generic-all
-
 ############################################################################
 
 # jdk_rmi
@@ -503,10 +466,6 @@
 sun/security/pkcs11/ec/TestECGenSpec.java			solaris-i586
 sun/security/pkcs11/ec/TestKeyFactory.java			solaris-i586
 
-# Unknown problem, could be a jtreg -samevm issue?
-#  Error while cleaning up threads after test
-java/security/Security/SynchronizedAccess.java			generic-all
-
 # Failing on Solaris X64 (-d64 -server) with:
 #  GSSException: Failure unspecified at GSS-API level
 #    (Mechanism level: Specified version of key is not available (44))
@@ -592,37 +551,9 @@
 # Various failures on Linux Fedora 9 X64, othervm mode
 sun/security/ssl/sanity/interop/ClientJSSEServerJSSE.java	generic-all
 
-# Linux i586 -server, buffer too short to hold shared secret?
-com/sun/crypto/provider/KeyAgreement/DHKeyAgreement2.java	generic-all
-
 # Solaris sparcv9: Failed to parse input emptysubject.jks: No such file or directory
 sun/security/tools/keytool/emptysubject.sh			generic-all
 
-# Timeout on solaris-sparcv9 or exception thrown
-com/sun/crypto/provider/Cipher/RSA/TestOAEP_KAT.java	 	solaris-all
-
-# Leaving file open: SerialVersion.current, windows samevm
-java/security/BasicPermission/SerialVersion.java		generic-all
-
-# Solaris 11 i586, these all fail with samevm, need to be othervm???
-java/security/BasicPermission/NullOrEmptyName.java		generic-all
-
-# Suspect missing close() on file PermClass.current, windows samevm cascade
-java/security/BasicPermission/PermClass.java			generic-all
-
-# Solaris 11 i586, these all fail with samevm, need to be othervm???
-java/security/KeyPairGenerator/Failover.java			generic-all
-java/security/Provider/DefaultPKCS11.java			generic-all
-java/security/SecureClassLoader/DefineClassByteBuffer.java	generic-all
-java/security/SecureRandom/GetAlgorithm.java			generic-all
-java/security/Security/removing/RemoveProviders.java		generic-all
-java/security/Signature/ByteBuffers.java			generic-all
-java/security/Signature/NONEwithRSA.java			generic-all
-java/security/Signature/SignWithOutputBuffer.java		generic-all
-java/security/Signature/TestInitSignWithMyOwnRandom.java	generic-all
-java/security/UnresolvedPermission/AccessorMethods.java		generic-all
-java/security/UnresolvedPermission/Equals.java			generic-all
-
 # Fails on OpenSolaris, missing classes, slow on Solaris sparc
 sun/security/ec/TestEC.java					generic-all
 
@@ -643,9 +574,6 @@
 sun/security/rsa/TestKeyPairGeneratorLength.java	 	solaris-all
 sun/security/rsa/TestSignatures.java			 	solaris-all
 
-# Timeout on solaris-sparc and i586 and x64, -client and -server
-sun/security/ssl/com/sun/net/ssl/internal/ssl/InputRecord/InterruptedIO.java solaris-all
-
 # Do not seem to run on windows machines? dll missing?
 sun/security/tools/jarsigner/emptymanifest.sh		 	windows-all
 
--- a/test/com/sun/crypto/provider/Cipher/DES/Sealtest.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/test/com/sun/crypto/provider/Cipher/DES/Sealtest.java	Thu Jun 30 14:18:40 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 0000000
+ * @bug 0000000 7055362
  * @summary Sealtest
  * @author Jan Luehe
  */
@@ -54,14 +54,16 @@
         SealedObject sealed = new SealedObject(kp.getPrivate(), c);
 
         // serialize
-        FileOutputStream fos = new FileOutputStream("sealed");
-        ObjectOutputStream oos = new ObjectOutputStream(fos);
-        oos.writeObject(sealed);
+        try (FileOutputStream fos = new FileOutputStream("sealed");
+                ObjectOutputStream oos = new ObjectOutputStream(fos)) {
+            oos.writeObject(sealed);
+        }
 
         // deserialize
-        FileInputStream fis = new FileInputStream("sealed");
-        ObjectInputStream ois = new ObjectInputStream(fis);
-        sealed = (SealedObject)ois.readObject();
+        try (FileInputStream fis = new FileInputStream("sealed");
+                ObjectInputStream ois = new ObjectInputStream(fis)) {
+            sealed = (SealedObject)ois.readObject();
+        }
 
         System.out.println(sealed.getAlgorithm());
 
--- a/test/com/sun/crypto/provider/Cipher/RSA/TestOAEP_KAT.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/test/com/sun/crypto/provider/Cipher/RSA/TestOAEP_KAT.java	Thu Jun 30 14:18:40 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 4894151
+ * @bug 4894151 7055362
  * @summary known answer test for OAEP encryption
  * @author Andreas Sterbenz
  */
@@ -62,60 +62,62 @@
         System.out.println("Testing provider " + provider.getName() + "...");
         Cipher c = Cipher.getInstance("RSA/ECB/OAEPwithSHA1andMGF1Padding", provider);
         KeyFactory kf = KeyFactory.getInstance("RSA", kfProvider);
-        InputStream in = new FileInputStream(new File(BASE, "oaep-vect.txt"));
-        BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF8"));
-        while (true) {
-            String line = reader.readLine();
-            if (line == null) {
-                break;
-            }
-            line = line.trim();
-            if (line.length() == 0) {
-                continue;
-            }
-            if (line.equals("# RSA modulus n:")) {
-                n = parseNumber(reader);
-            } else if (line.equals("# RSA public exponent e:")) {
-                e = parseNumber(reader);
-            } else if (line.equals("# RSA private exponent d:")) {
-                d = parseNumber(reader);
-            } else if (line.equals("# Prime p:")) {
-                p = parseNumber(reader);
-            } else if (line.equals("# Prime q:")) {
-                q = parseNumber(reader);
-            } else if (line.equals("# p's CRT exponent dP:")) {
-                pe = parseNumber(reader);
-            } else if (line.equals("# q's CRT exponent dQ:")) {
-                qe = parseNumber(reader);
-            } else if (line.equals("# CRT coefficient qInv:")) {
-                coeff = parseNumber(reader);
-            } else if (line.equals("# Message to be encrypted:")) {
-                plainText = parseBytes(reader);
-            } else if (line.equals("# Seed:")) {
-                seed = parseBytes(reader);
-            } else if (line.equals("# Encryption:")) {
-                cipherText = parseBytes(reader);
-                // do encryption test first
-                KeySpec pubSpec = new RSAPublicKeySpec(n, e);
-                PublicKey pubKey = kf.generatePublic(pubSpec);
-                c.init(Cipher.ENCRYPT_MODE, pubKey, new MyRandom(seed));
-                cipherText2 = c.doFinal(plainText);
-                if (Arrays.equals(cipherText2, cipherText) == false) {
-                    throw new Exception("Encryption mismatch");
+        try (InputStream in = new FileInputStream(new File(BASE, "oaep-vect.txt"));
+                BufferedReader reader =
+                        new BufferedReader(new InputStreamReader(in, "UTF8"))) {
+            while (true) {
+                String line = reader.readLine();
+                if (line == null) {
+                    break;
                 }
-                // followed by decryption test
-                KeySpec privSpec = new RSAPrivateCrtKeySpec(n, e, d, p, q, pe, qe, coeff);
-                PrivateKey privKey = kf.generatePrivate(privSpec);
-                c.init(Cipher.DECRYPT_MODE, privKey);
-                byte[] dec = c.doFinal(cipherText);
-                if (Arrays.equals(plainText, dec) == false) {
-                    throw new Exception("Decryption mismatch");
+                line = line.trim();
+                if (line.length() == 0) {
+                    continue;
                 }
-            } else if (line.startsWith("# ------------------------------")) {
-                // ignore, do not print
-            } else {
-                // unknown line (comment), print
-                System.out.println(": " + line);
+                if (line.equals("# RSA modulus n:")) {
+                    n = parseNumber(reader);
+                } else if (line.equals("# RSA public exponent e:")) {
+                    e = parseNumber(reader);
+                } else if (line.equals("# RSA private exponent d:")) {
+                    d = parseNumber(reader);
+                } else if (line.equals("# Prime p:")) {
+                    p = parseNumber(reader);
+                } else if (line.equals("# Prime q:")) {
+                    q = parseNumber(reader);
+                } else if (line.equals("# p's CRT exponent dP:")) {
+                    pe = parseNumber(reader);
+                } else if (line.equals("# q's CRT exponent dQ:")) {
+                    qe = parseNumber(reader);
+                } else if (line.equals("# CRT coefficient qInv:")) {
+                    coeff = parseNumber(reader);
+                } else if (line.equals("# Message to be encrypted:")) {
+                    plainText = parseBytes(reader);
+                } else if (line.equals("# Seed:")) {
+                    seed = parseBytes(reader);
+                } else if (line.equals("# Encryption:")) {
+                    cipherText = parseBytes(reader);
+                    // do encryption test first
+                    KeySpec pubSpec = new RSAPublicKeySpec(n, e);
+                    PublicKey pubKey = kf.generatePublic(pubSpec);
+                    c.init(Cipher.ENCRYPT_MODE, pubKey, new MyRandom(seed));
+                    cipherText2 = c.doFinal(plainText);
+                    if (Arrays.equals(cipherText2, cipherText) == false) {
+                        throw new Exception("Encryption mismatch");
+                    }
+                    // followed by decryption test
+                    KeySpec privSpec = new RSAPrivateCrtKeySpec(n, e, d, p, q, pe, qe, coeff);
+                    PrivateKey privKey = kf.generatePrivate(privSpec);
+                    c.init(Cipher.DECRYPT_MODE, privKey);
+                    byte[] dec = c.doFinal(cipherText);
+                    if (Arrays.equals(plainText, dec) == false) {
+                        throw new Exception("Decryption mismatch");
+                    }
+                } else if (line.startsWith("# ------------------------------")) {
+                    // ignore, do not print
+                } else {
+                    // unknown line (comment), print
+                    System.out.println(": " + line);
+                }
             }
         }
         long stop = System.currentTimeMillis();
--- a/test/com/sun/jndi/ldap/ReadTimeoutTest.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/test/com/sun/jndi/ldap/ReadTimeoutTest.java	Thu Jun 30 14:18:40 2011 -0700
@@ -23,7 +23,7 @@
 
 /**
  * @test
- * @bug 6176036
+ * @bug 6176036 7056489
  * @summary Read-timeout specification for LDAP operations
  */
 
@@ -37,40 +37,37 @@
 public class ReadTimeoutTest {
 
     public static void main(String[] args) throws Exception {
-
         boolean passed = false;
 
-        // Set up the environment for creating the initial context
-        Hashtable env = new Hashtable(11);
-        env.put(Context.INITIAL_CONTEXT_FACTORY,
-            "com.sun.jndi.ldap.LdapCtxFactory");
-        env.put("com.sun.jndi.ldap.read.timeout", "1000");
-        env.put(Context.PROVIDER_URL, "ldap://localhost:2001");
+        // create the server
+        try (Server server = Server.create()) {
+            // Set up the environment for creating the initial context
+            Hashtable<String,Object> env = new Hashtable<>(11);
+            env.put(Context.INITIAL_CONTEXT_FACTORY,
+                "com.sun.jndi.ldap.LdapCtxFactory");
+            env.put("com.sun.jndi.ldap.read.timeout", "1000");
+            env.put(Context.PROVIDER_URL, "ldap://localhost:" + server.port());
 
-        Server s = new Server();
-
-        try {
-
-            // start the server
-            s.start();
 
             // Create initial context
             DirContext ctx = new InitialDirContext(env);
-            System.out.println("LDAP Client: Connected to the Server");
+            try {
+                System.out.println("LDAP Client: Connected to the Server");
 
-            SearchControls scl = new SearchControls();
-            scl.setSearchScope(SearchControls.SUBTREE_SCOPE);
-            System.out.println("Performing Search");
-            NamingEnumeration answer =
-                ctx.search("ou=People,o=JNDITutorial", "(objectClass=*)", scl);
-
-            // Close the context when we're done
-            ctx.close();
+                SearchControls scl = new SearchControls();
+                scl.setSearchScope(SearchControls.SUBTREE_SCOPE);
+                System.out.println("Performing Search");
+                NamingEnumeration<SearchResult> answer =
+                    ctx.search("ou=People,o=JNDITutorial", "(objectClass=*)", scl);
+            } finally {
+                // Close the context when we're done
+                ctx.close();
+            }
         } catch (NamingException e) {
             passed = true;
             e.printStackTrace();
         }
-        s.interrupt();
+
         if (!passed) {
             throw new Exception("Read timeout test failed," +
                          " read timeout exception not thrown");
@@ -78,27 +75,39 @@
         System.out.println("The test PASSED");
     }
 
-    static class Server extends Thread {
+    static class Server implements Runnable, Closeable {
+        private final ServerSocket ss;
 
-        static int serverPort = 2001;
+        private Server(ServerSocket ss) {
+            this.ss = ss;
+        }
 
-        Server() {
+        static Server create() throws IOException {
+            Server server = new Server(new ServerSocket(0));
+            new Thread(server).start();
+            return server;
+        }
+
+        int port() {
+            return ss.getLocalPort();
         }
 
         public void run() {
-            try {
-                ServerSocket serverSock = new ServerSocket(serverPort);
-                Socket socket = serverSock.accept();
+            try (Socket s = ss.accept()) {
                 System.out.println("Server: Connection accepted");
-
-                BufferedInputStream bin = new BufferedInputStream(socket.
-                                getInputStream());
-                while (true) {
-                    bin.read();
-                }
+                BufferedInputStream bis = new BufferedInputStream(s.getInputStream());
+                byte[] buf = new byte[100];
+                int n;
+                do {
+                    n = bis.read(buf);
+                } while (n > 0);
             } catch (IOException e) {
                 // ignore
             }
+        }
+
+        public void close() throws IOException {
+            ss.close();
+        }
     }
 }
-}
--- a/test/com/sun/net/httpserver/bugs/B6373555.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/test/com/sun/net/httpserver/bugs/B6373555.java	Thu Jun 30 14:18:40 2011 -0700
@@ -43,14 +43,12 @@
     private static int port;
 
     private static volatile boolean error = false;
-    private static Object lock;
     static HttpServer httpServer;
     static ExecutorService pool, execs;
     static int NUM = 1000;
 
     public static void main(String[] args) throws Exception {
         try {
-            lock = new Object();
             if (args.length > 0) {
                 NUM = Integer.parseInt (args[0]);
             }
@@ -117,12 +115,6 @@
                     System.out.println("Doesn't match");
                     error = true;
                 }
-                synchronized(lock) {
-                    ++received;
-                    if ((received % 1000) == 0) {
-                        System.out.println("Received="+received);
-                    }
-                }
             }
             catch(Exception e) {
                 e.printStackTrace();
@@ -150,18 +142,12 @@
     private static HttpServer createHttpServer(ExecutorService execs)
         throws Exception {
         InetSocketAddress inetAddress = new InetSocketAddress(0);
-        HttpServer testServer = HttpServer.create(inetAddress, 5);
+        HttpServer testServer = HttpServer.create(inetAddress, 15);
         testServer.setExecutor(execs);
         HttpContext context = testServer.createContext("/test");
         context.setHandler(new HttpHandler() {
             public void handle(HttpExchange msg) {
                 try {
-                    synchronized(lock) {
-                        ++s_received;
-                            if ((s_received % 1000) == 0) {
-                            System.out.println("Received="+s_received);
-                        }
-                    }
                     String method = msg.getRequestMethod();
                         if (method.equals("POST")) {
                         InputStream is = msg.getRequestBody();
@@ -172,12 +158,6 @@
                         System.out.println("****** METHOD not handled ***** "+method);
                             System.out.println("Received="+s_received);
                     }
-                    synchronized(lock) {
-                        ++sent;
-                            if ((sent % 1000) == 0) {
-                            System.out.println("sent="+sent);
-                        }
-                    }
                 }
                 catch(Exception e) {
                     e.printStackTrace();
--- a/test/java/lang/ClassLoader/deadlock/TestOneWayDelegate.sh	Thu Jun 30 14:16:48 2011 -0700
+++ b/test/java/lang/ClassLoader/deadlock/TestOneWayDelegate.sh	Thu Jun 30 14:18:40 2011 -0700
@@ -25,7 +25,7 @@
 # @summary (cl) ClassLoader.loadClass locks all instances in chain 
 #          when delegating
 # 
-# @run shell/timeout=10 TestOneWayDelegate.sh
+# @run shell TestOneWayDelegate.sh
 
 # if running by hand on windows, change TESTSRC and TESTCLASSES to "."
 if [ "${TESTSRC}" = "" ] ; then
--- a/test/java/lang/Thread/ThreadStateTest.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/test/java/lang/Thread/ThreadStateTest.java	Thu Jun 30 14:18:40 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -34,21 +34,16 @@
  */
 
 import java.util.concurrent.locks.LockSupport;
-import java.util.concurrent.Semaphore;
+import java.util.concurrent.Phaser;
 
 public class ThreadStateTest {
+    // maximum number of retries when checking for thread state.
+    static final int MAX_RETRY = 500;
+
     private static boolean testFailed = false;
 
-    static class Lock {
-        private String name;
-        Lock(String name) {
-            this.name = name;
-        }
-        public String toString() {
-            return name;
-        }
-    }
-    private static Lock globalLock = new Lock("my lock");
+    // used to achieve waiting states
+    static final Object globalLock = new Object();
 
     public static void main(String[] argv) {
         // Call Thread.getState to force all initialization done
@@ -102,13 +97,27 @@
             System.out.println("Unexpected exception.");
             testFailed = true;
         }
+
         if (testFailed)
             throw new RuntimeException("TEST FAILED.");
         System.out.println("Test passed.");
     }
 
     private static void checkThreadState(Thread t, Thread.State expected) {
-        Thread.State state = t.getState();
+        // wait for the thread to transition to the expected state.
+        // There is a small window between the thread checking the state
+        // and the thread actual entering that state.
+        Thread.State state;
+        int retryCount=0;
+        while ((state = t.getState()) != expected && retryCount < MAX_RETRY) {
+            if (state != Thread.State.RUNNABLE) {
+                throw new RuntimeException("Thread not in expected state yet," +
+                        " but it should at least be RUNNABLE");
+            }
+            goSleep(10);
+            retryCount++;
+        }
+
         System.out.println("Checking thread state " + state);
         if (state == null) {
             throw new RuntimeException(t.getName() + " expected to have " +
@@ -121,13 +130,6 @@
         }
     }
 
-    private static String getLockName(Object lock) {
-        if (lock == null) return null;
-
-        return lock.getClass().getName() + '@' +
-            Integer.toHexString(System.identityHashCode(lock));
-    }
-
     private static void goSleep(long ms) {
         try {
             Thread.sleep(ms);
@@ -139,7 +141,9 @@
     }
 
     static class MyThread extends Thread {
-        private ThreadExecutionSynchronizer thrsync = new ThreadExecutionSynchronizer();
+        // Phaser to sync between the main thread putting
+        // this thread into various states
+        private Phaser phaser =  new Phaser(2);
 
         MyThread(String name) {
             super(name);
@@ -153,12 +157,14 @@
         private final int TIMED_PARKED = 5;
         private final int SLEEPING = 6;
         private final int TERMINATE = 7;
-        private int state = RUNNABLE;
+
+        private volatile int state = RUNNABLE;
 
         private boolean done = false;
         public void run() {
             // Signal main thread to continue.
-            thrsync.signal();
+            phaser.arriveAndAwaitAdvance();
+
             while (!done) {
                 switch (state) {
                     case RUNNABLE: {
@@ -172,7 +178,7 @@
                     }
                     case BLOCKED: {
                         // signal main thread.
-                        thrsync.signal();
+                        phaser.arrive();
                         System.out.println("  myThread is going to block.");
                         synchronized (globalLock) {
                             // finish blocking
@@ -183,7 +189,7 @@
                     case WAITING: {
                         synchronized (globalLock) {
                             // signal main thread.
-                            thrsync.signal();
+                            phaser.arrive();
                             System.out.println("  myThread is going to wait.");
                             try {
                                 globalLock.wait();
@@ -196,7 +202,7 @@
                     case TIMED_WAITING: {
                         synchronized (globalLock) {
                             // signal main thread.
-                            thrsync.signal();
+                            phaser.arrive();
                             System.out.println("  myThread is going to timed wait.");
                             try {
                                 globalLock.wait(10000);
@@ -208,7 +214,7 @@
                     }
                     case PARKED: {
                         // signal main thread.
-                        thrsync.signal();
+                        phaser.arrive();
                         System.out.println("  myThread is going to park.");
                         LockSupport.park();
                         // give a chance for the main thread to block
@@ -217,7 +223,7 @@
                     }
                     case TIMED_PARKED: {
                         // signal main thread.
-                        thrsync.signal();
+                        phaser.arrive();
                         System.out.println("  myThread is going to timed park.");
                         long deadline = System.currentTimeMillis() + 10000*1000;
                         LockSupport.parkUntil(deadline);
@@ -228,20 +234,19 @@
                     }
                     case SLEEPING: {
                         // signal main thread.
-                        thrsync.signal();
+                        phaser.arrive();
                         System.out.println("  myThread is going to sleep.");
                         try {
                             Thread.sleep(1000000);
                         } catch (InterruptedException e) {
                             // finish sleeping
-                            interrupted();
                         }
                         break;
                     }
                     case TERMINATE: {
                         done = true;
                         // signal main thread.
-                        thrsync.signal();
+                        phaser.arrive();
                         break;
                     }
                     default:
@@ -249,69 +254,66 @@
                 }
             }
         }
+
         public void waitUntilStarted() {
             // wait for MyThread.
-            thrsync.waitForSignal();
-            goSleep(10);
+            phaser.arriveAndAwaitAdvance();
         }
 
         public void goBlocked() {
             System.out.println("Waiting myThread to go blocked.");
             setState(BLOCKED);
-            // wait for MyThread to get blocked
-            thrsync.waitForSignal();
-            goSleep(20);
+            // wait for MyThread to get to a point just before being blocked
+            phaser.arriveAndAwaitAdvance();
         }
 
         public void goWaiting() {
             System.out.println("Waiting myThread to go waiting.");
             setState(WAITING);
-            // wait for  MyThread to wait on object.
-            thrsync.waitForSignal();
-            goSleep(20);
+            // wait for MyThread to get to just before wait on object.
+            phaser.arriveAndAwaitAdvance();
         }
+
         public void goTimedWaiting() {
             System.out.println("Waiting myThread to go timed waiting.");
             setState(TIMED_WAITING);
-            // wait for MyThread timed wait call.
-            thrsync.waitForSignal();
-            goSleep(20);
+            // wait for MyThread to get to just before timed wait call.
+            phaser.arriveAndAwaitAdvance();
         }
+
         public void goParked() {
             System.out.println("Waiting myThread to go parked.");
             setState(PARKED);
-            // wait for  MyThread state change to PARKED.
-            thrsync.waitForSignal();
-            goSleep(20);
+            // wait for MyThread to get to just before parked.
+            phaser.arriveAndAwaitAdvance();
         }
+
         public void goTimedParked() {
             System.out.println("Waiting myThread to go timed parked.");
             setState(TIMED_PARKED);
-            // wait for  MyThread.
-            thrsync.waitForSignal();
-            goSleep(20);
+            // wait for MyThread to get to just before timed park.
+            phaser.arriveAndAwaitAdvance();
         }
 
         public void goSleeping() {
             System.out.println("Waiting myThread to go sleeping.");
             setState(SLEEPING);
-            // wait for  MyThread.
-            thrsync.waitForSignal();
-            goSleep(20);
+            // wait for MyThread to get to just before sleeping
+            phaser.arriveAndAwaitAdvance();
         }
+
         public void terminate() {
             System.out.println("Waiting myThread to terminate.");
             setState(TERMINATE);
-            // wait for  MyThread.
-            thrsync.waitForSignal();
-            goSleep(20);
+            // wait for MyThread to get to just before terminate
+            phaser.arriveAndAwaitAdvance();
         }
 
         private void setState(int newState) {
             switch (state) {
                 case BLOCKED:
                     while (state == BLOCKED) {
-                        goSleep(20);
+                        goSleep(10);
                     }
                     state = newState;
                     break;
@@ -337,50 +339,4 @@
             }
         }
     }
-
-
-
-    static class ThreadExecutionSynchronizer {
-
-        private boolean  waiting;
-        private Semaphore semaphore;
-
-        public ThreadExecutionSynchronizer() {
-            semaphore = new Semaphore(1);
-        waiting = false;
-        }
-
-        // Synchronizes two threads execution points.
-        // Basically any thread could get scheduled to run and
-        // it is not possible to know which thread reaches expected
-        // execution point. So whichever thread reaches a execution
-        // point first wait for the second thread. When the second thread
-        // reaches the expected execution point will wake up
-        // the thread which is waiting here.
-        void stopOrGo() {
-        semaphore.acquireUninterruptibly(); // Thread can get blocked.
-        if (!waiting) {
-            waiting = true;
-            // Wait for second thread to enter this method.
-            while(!semaphore.hasQueuedThreads()) {
-                try {
-                    Thread.sleep(20);
-                } catch (InterruptedException xx) {}
-            }
-            semaphore.release();
-        } else {
-            waiting = false;
-            semaphore.release();
-        }
-        }
-
-        // Wrapper function just for code readability.
-        void waitForSignal() {
-        stopOrGo();
-        }
-
-        void signal() {
-        stopOrGo();
-        }
-    }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/lang/annotation/TestIncompleteAnnotationExceptionNPE.java	Thu Jun 30 14:18:40 2011 -0700
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug     7021922
+ * @summary Test null handling of IncompleteAnnotationException constructor
+ * @author  Joseph D. Darcy
+ */
+
+import java.lang.annotation.*;
+
+public class TestIncompleteAnnotationExceptionNPE {
+    public static void main(String... args) {
+        int errors = 0;
+        Class<? extends Annotation> annotationType = Annotation.class;
+        String elementName = "name";
+
+        try {
+            Object o = new IncompleteAnnotationException(null, null);
+            errors++;
+        } catch(NullPointerException npe) {
+            ; // Expected
+        }
+
+        try {
+            Object o = new IncompleteAnnotationException(annotationType, null);
+            errors++;
+        } catch(NullPointerException npe) {
+            ; // Expected
+        }
+
+        try {
+            Object o = new IncompleteAnnotationException(null, elementName);
+            errors++;
+        } catch(NullPointerException npe) {
+            ; // Expected
+        }
+
+        if (errors != 0)
+            throw new RuntimeException("Encountered " + errors +
+                                       " error(s) during construction.");
+    }
+}
--- a/test/java/lang/management/ManagementFactory/MBeanServerMXBeanUnsupportedTest.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/test/java/lang/management/ManagementFactory/MBeanServerMXBeanUnsupportedTest.java	Thu Jun 30 14:18:40 2011 -0700
@@ -29,7 +29,7 @@
  * @author Luis-Miguel Alventosa
  * @run clean MBeanServerMXBeanUnsupportedTest
  * @run build MBeanServerMXBeanUnsupportedTest
- * @run main MBeanServerMXBeanUnsupportedTest
+ * @run main/othervm MBeanServerMXBeanUnsupportedTest
  */
 
 import java.lang.management.ManagementFactory;
--- a/test/java/nio/channels/AsynchronousSocketChannel/Basic.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/test/java/nio/channels/AsynchronousSocketChannel/Basic.java	Thu Jun 30 14:18:40 2011 -0700
@@ -24,7 +24,7 @@
 /* @test
  * @bug 4607272 6842687 6878369 6944810 7023403
  * @summary Unit test for AsynchronousSocketChannel
- * @run main/timeout=600 Basic
+ * @run main Basic -skipSlowConnectTest
  */
 
 import java.nio.ByteBuffer;
@@ -34,12 +34,25 @@
 import java.util.Random;
 import java.util.concurrent.*;
 import java.util.concurrent.atomic.*;
+import java.io.Closeable;
 import java.io.IOException;
 
 public class Basic {
     static final Random rand = new Random();
 
+    static boolean skipSlowConnectTest = false;
+
     public static void main(String[] args) throws Exception {
+        for (String arg: args) {
+            switch (arg) {
+            case "-skipSlowConnectTest" :
+                skipSlowConnectTest = true;
+                break;
+            default:
+                throw new RuntimeException("Unrecognized argument: " + arg);
+            }
+        }
+
         testBind();
         testSocketOptions();
         testConnect();
@@ -54,7 +67,7 @@
         testShutdown();
     }
 
-    static class Server {
+    static class Server implements Closeable {
         private final ServerSocketChannel ssc;
         private final InetSocketAddress address;
 
@@ -74,10 +87,8 @@
             return ssc.accept();
         }
 
-        void close() {
-            try {
-                ssc.close();
-            } catch (IOException ignore) { }
+        public void close() throws IOException {
+            ssc.close();
         }
 
     }
@@ -85,28 +96,28 @@
     static void testBind() throws Exception {
         System.out.println("-- bind --");
 
-        AsynchronousSocketChannel ch = AsynchronousSocketChannel.open();
-        if (ch.getLocalAddress() != null)
-            throw new RuntimeException("Local address should be 'null'");
-        ch.bind(new InetSocketAddress(0));
+        try (AsynchronousSocketChannel ch = AsynchronousSocketChannel.open()) {
+            if (ch.getLocalAddress() != null)
+                throw new RuntimeException("Local address should be 'null'");
+            ch.bind(new InetSocketAddress(0));
 
-        // check local address after binding
-        InetSocketAddress local = (InetSocketAddress)ch.getLocalAddress();
-        if (local.getPort() == 0)
-            throw new RuntimeException("Unexpected port");
-        if (!local.getAddress().isAnyLocalAddress())
-            throw new RuntimeException("Not bound to a wildcard address");
+            // check local address after binding
+            InetSocketAddress local = (InetSocketAddress)ch.getLocalAddress();
+            if (local.getPort() == 0)
+                throw new RuntimeException("Unexpected port");
+            if (!local.getAddress().isAnyLocalAddress())
+                throw new RuntimeException("Not bound to a wildcard address");
 
-        // try to re-bind
-        try {
-            ch.bind(new InetSocketAddress(0));
-            throw new RuntimeException("AlreadyBoundException expected");
-        } catch (AlreadyBoundException x) {
+            // try to re-bind
+            try {
+                ch.bind(new InetSocketAddress(0));
+                throw new RuntimeException("AlreadyBoundException expected");
+            } catch (AlreadyBoundException x) {
+            }
         }
-        ch.close();
 
         // check ClosedChannelException
-        ch = AsynchronousSocketChannel.open();
+        AsynchronousSocketChannel ch = AsynchronousSocketChannel.open();
         ch.close();
         try {
             ch.bind(new InetSocketAddress(0));
@@ -118,109 +129,124 @@
     static void testSocketOptions() throws Exception {
         System.out.println("-- socket options --");
 
-        AsynchronousSocketChannel ch = AsynchronousSocketChannel.open()
-            .setOption(SO_RCVBUF, 128*1024)
-            .setOption(SO_SNDBUF, 128*1024)
-            .setOption(SO_REUSEADDR, true);
+        try (AsynchronousSocketChannel ch = AsynchronousSocketChannel.open()) {
+            ch.setOption(SO_RCVBUF, 128*1024)
+              .setOption(SO_SNDBUF, 128*1024)
+              .setOption(SO_REUSEADDR, true);
 
-        // check SO_SNDBUF/SO_RCVBUF limits
-        int before, after;
-        before = ch.getOption(SO_SNDBUF);
-        after = ch.setOption(SO_SNDBUF, Integer.MAX_VALUE).getOption(SO_SNDBUF);
-        if (after < before)
-            throw new RuntimeException("setOption caused SO_SNDBUF to decrease");
-        before = ch.getOption(SO_RCVBUF);
-        after = ch.setOption(SO_RCVBUF, Integer.MAX_VALUE).getOption(SO_RCVBUF);
-        if (after < before)
-            throw new RuntimeException("setOption caused SO_RCVBUF to decrease");
+            // check SO_SNDBUF/SO_RCVBUF limits
+            int before, after;
+            before = ch.getOption(SO_SNDBUF);
+            after = ch.setOption(SO_SNDBUF, Integer.MAX_VALUE).getOption(SO_SNDBUF);
+            if (after < before)
+                throw new RuntimeException("setOption caused SO_SNDBUF to decrease");
+            before = ch.getOption(SO_RCVBUF);
+            after = ch.setOption(SO_RCVBUF, Integer.MAX_VALUE).getOption(SO_RCVBUF);
+            if (after < before)
+                throw new RuntimeException("setOption caused SO_RCVBUF to decrease");
 
-        ch.bind(new InetSocketAddress(0));
+            ch.bind(new InetSocketAddress(0));
 
-        // default values
-        if ((Boolean)ch.getOption(SO_KEEPALIVE))
-            throw new RuntimeException("Default of SO_KEEPALIVE should be 'false'");
-        if ((Boolean)ch.getOption(TCP_NODELAY))
-            throw new RuntimeException("Default of TCP_NODELAY should be 'false'");
+            // default values
+            if (ch.getOption(SO_KEEPALIVE))
+                throw new RuntimeException("Default of SO_KEEPALIVE should be 'false'");
+            if (ch.getOption(TCP_NODELAY))
+                throw new RuntimeException("Default of TCP_NODELAY should be 'false'");
 
-        // set and check
-        if (!(Boolean)ch.setOption(SO_KEEPALIVE, true).getOption(SO_KEEPALIVE))
-            throw new RuntimeException("SO_KEEPALIVE did not change");
-        if (!(Boolean)ch.setOption(TCP_NODELAY, true).getOption(TCP_NODELAY))
-            throw new RuntimeException("SO_KEEPALIVE did not change");
+            // set and check
+            if (!ch.setOption(SO_KEEPALIVE, true).getOption(SO_KEEPALIVE))
+                throw new RuntimeException("SO_KEEPALIVE did not change");
+            if (!ch.setOption(TCP_NODELAY, true).getOption(TCP_NODELAY))
+                throw new RuntimeException("SO_KEEPALIVE did not change");
 
-        // read others (can't check as actual value is implementation dependent)
-        ch.getOption(SO_RCVBUF);
-        ch.getOption(SO_SNDBUF);
-
-        ch.close();
+            // read others (can't check as actual value is implementation dependent)
+            ch.getOption(SO_RCVBUF);
+            ch.getOption(SO_SNDBUF);
+        }
     }
 
     static void testConnect() throws Exception {
         System.out.println("-- connect --");
 
-        Server server = new Server();
-        AsynchronousSocketChannel ch = AsynchronousSocketChannel.open();
-        ch.connect(server.address()).get();
+        SocketAddress address;
 
-        // check local address
-        if (ch.getLocalAddress() == null)
-            throw new RuntimeException("Not bound to local address");
+        try (Server server = new Server()) {
+            address = server.address();
 
-        // check remote address
-        InetSocketAddress remote = (InetSocketAddress)ch.getRemoteAddress();
-        if (remote.getPort() != server.address().getPort())
-            throw new RuntimeException("Connected to unexpected port");
-        if (!remote.getAddress().equals(server.address().getAddress()))
-            throw new RuntimeException("Connected to unexpected address");
+            // connect to server and check local/remote addresses
+            try (AsynchronousSocketChannel ch = AsynchronousSocketChannel.open()) {
+                ch.connect(address).get();
+                // check local address
+                if (ch.getLocalAddress() == null)
+                    throw new RuntimeException("Not bound to local address");
 
-        // try to connect again
-        try {
-            ch.connect(server.address()).get();
-            throw new RuntimeException("AlreadyConnectedException expected");
-        } catch (AlreadyConnectedException x) {
+                // check remote address
+                InetSocketAddress remote = (InetSocketAddress)ch.getRemoteAddress();
+                if (remote.getPort() != server.address().getPort())
+                    throw new RuntimeException("Connected to unexpected port");
+                if (!remote.getAddress().equals(server.address().getAddress()))
+                    throw new RuntimeException("Connected to unexpected address");
+
+                // try to connect again
+                try {
+                    ch.connect(server.address()).get();
+                    throw new RuntimeException("AlreadyConnectedException expected");
+                } catch (AlreadyConnectedException x) {
+                }
+
+                // clean-up
+                server.accept().close();
+            }
+
+            // check that connect fails with ClosedChannelException
+            AsynchronousSocketChannel ch = AsynchronousSocketChannel.open();
+            ch.close();
+            try {
+                ch.connect(server.address()).get();
+                throw new RuntimeException("ExecutionException expected");
+            } catch (ExecutionException x) {
+                if (!(x.getCause() instanceof ClosedChannelException))
+                    throw new RuntimeException("Cause of ClosedChannelException expected");
+            }
+            final AtomicReference<Throwable> connectException = new AtomicReference<>();
+            ch.connect(server.address(), (Void)null, new CompletionHandler<Void,Void>() {
+                public void completed(Void result, Void att) {
+                }
+                public void failed(Throwable exc, Void att) {
+                    connectException.set(exc);
+                }
+            });
+            while (connectException.get() == null) {
+                Thread.sleep(100);
+            }
+            if (!(connectException.get() instanceof ClosedChannelException))
+                throw new RuntimeException("ClosedChannelException expected");
         }
-        ch.close();
-
-        // check that connect fails with ClosedChannelException)
-        ch = AsynchronousSocketChannel.open();
-        ch.close();
-        try {
-            ch.connect(server.address()).get();
-            throw new RuntimeException("ExecutionException expected");
-        } catch (ExecutionException x) {
-            if (!(x.getCause() instanceof ClosedChannelException))
-                throw new RuntimeException("Cause of ClosedChannelException expected");
-        }
-        final AtomicReference<Throwable> connectException =
-            new AtomicReference<Throwable>();
-        ch.connect(server.address(), (Void)null, new CompletionHandler<Void,Void>() {
-            public void completed(Void result, Void att) {
-            }
-            public void failed(Throwable exc, Void att) {
-                connectException.set(exc);
-            }
-        });
-        while (connectException.get() == null) {
-            Thread.sleep(100);
-        }
-        if (!(connectException.get() instanceof ClosedChannelException))
-            throw new RuntimeException("ClosedChannelException expected");
-
-        System.out.println("-- connect to non-existent host --");
 
         // test that failure to connect closes the channel
-        ch = AsynchronousSocketChannel.open();
-        try {
-            ch.connect(genSocketAddress()).get();
-        } catch (ExecutionException x) {
-            // failed to establish connection
-            if (ch.isOpen())
-                throw new RuntimeException("Channel should be closed");
-        } finally {
-            ch.close();
+        try (AsynchronousSocketChannel ch = AsynchronousSocketChannel.open()) {
+            try {
+                ch.connect(address).get();
+            } catch (ExecutionException x) {
+                // failed to establish connection
+                if (ch.isOpen())
+                    throw new RuntimeException("Channel should be closed");
+            }
         }
 
-        server.close();
+        // repeat test by connecting to a (probably) non-existent host. This
+        // improves the chance that the connect will not fail immediately.
+        if (!skipSlowConnectTest) {
+            try (AsynchronousSocketChannel ch = AsynchronousSocketChannel.open()) {
+                try {
+                    ch.connect(genSocketAddress()).get();
+                } catch (ExecutionException x) {
+                    // failed to establish connection
+                    if (ch.isOpen())
+                        throw new RuntimeException("Channel should be closed");
+                }
+            }
+        }
     }
 
     static void testCloseWhenPending() throws Exception {
@@ -249,466 +275,460 @@
 
         System.out.println("-- asynchronous close when reading --");
 
-        Server server = new Server();
-        ch = AsynchronousSocketChannel.open();
-        ch.connect(server.address()).get();
+        try (Server server = new Server()) {
+            ch = AsynchronousSocketChannel.open();
+            ch.connect(server.address()).get();
 
-        ByteBuffer dst = ByteBuffer.allocateDirect(100);
-        Future<Integer> result = ch.read(dst);
+            ByteBuffer dst = ByteBuffer.allocateDirect(100);
+            Future<Integer> result = ch.read(dst);
 
-        // attempt a second read - should fail with ReadPendingException
-        ByteBuffer buf = ByteBuffer.allocateDirect(100);
-        try {
-            ch.read(buf);
-            throw new RuntimeException("ReadPendingException expected");
-        } catch (ReadPendingException x) {
+            // attempt a second read - should fail with ReadPendingException
+            ByteBuffer buf = ByteBuffer.allocateDirect(100);
+            try {
+                ch.read(buf);
+                throw new RuntimeException("ReadPendingException expected");
+            } catch (ReadPendingException x) {
+            }
+
+            // close channel (should cause initial read to complete)
+            ch.close();
+            server.accept().close();
+
+            // check that AsynchronousCloseException is thrown
+            try {
+                result.get();
+                throw new RuntimeException("Should not read");
+            } catch (ExecutionException x) {
+                if (!(x.getCause() instanceof AsynchronousCloseException))
+                    throw new RuntimeException(x);
+            }
+
+            System.out.println("-- asynchronous close when writing --");
+
+            ch = AsynchronousSocketChannel.open();
+            ch.connect(server.address()).get();
+
+            final AtomicReference<Throwable> writeException =
+                new AtomicReference<Throwable>();
+
+            // write bytes to fill socket buffer
+            ch.write(genBuffer(), ch, new CompletionHandler<Integer,AsynchronousSocketChannel>() {
+                public void completed(Integer result, AsynchronousSocketChannel ch) {
+                    ch.write(genBuffer(), ch, this);
+                }
+                public void failed(Throwable x, AsynchronousSocketChannel ch) {
+                    writeException.set(x);
+                }
+            });
+
+            // give time for socket buffer to fill up.
+            Thread.sleep(5*1000);
+
+            //  attempt a concurrent write - should fail with WritePendingException
+            try {
+                ch.write(genBuffer());
+                throw new RuntimeException("WritePendingException expected");
+            } catch (WritePendingException x) {
+            }
+
+            // close channel - should cause initial write to complete
+            ch.close();
+            server.accept().close();
+
+            // wait for exception
+            while (writeException.get() == null) {
+                Thread.sleep(100);
+            }
+            if (!(writeException.get() instanceof AsynchronousCloseException))
+                throw new RuntimeException("AsynchronousCloseException expected");
         }
-
-        // close channel (should cause initial read to complete)
-        ch.close();
-
-        // check that AsynchronousCloseException is thrown
-        try {
-            result.get();
-            throw new RuntimeException("Should not read");
-        } catch (ExecutionException x) {
-            if (!(x.getCause() instanceof AsynchronousCloseException))
-                throw new RuntimeException(x);
-        }
-
-        System.out.println("-- asynchronous close when writing --");
-
-        ch = AsynchronousSocketChannel.open();
-        ch.connect(server.address()).get();
-
-        final AtomicReference<Throwable> writeException =
-            new AtomicReference<Throwable>();
-
-        // write bytes to fill socket buffer
-        ch.write(genBuffer(), ch, new CompletionHandler<Integer,AsynchronousSocketChannel>() {
-            public void completed(Integer result, AsynchronousSocketChannel ch) {
-                ch.write(genBuffer(), ch, this);
-            }
-            public void failed(Throwable x, AsynchronousSocketChannel ch) {
-                writeException.set(x);
-            }
-        });
-
-        // give time for socket buffer to fill up.
-        Thread.sleep(5*1000);
-
-        //  attempt a concurrent write - should fail with WritePendingException
-        try {
-            ch.write(genBuffer());
-            throw new RuntimeException("WritePendingException expected");
-        } catch (WritePendingException x) {
-        }
-
-        // close channel - should cause initial write to complete
-        ch.close();
-
-        // wait for exception
-        while (writeException.get() == null) {
-            Thread.sleep(100);
-        }
-        if (!(writeException.get() instanceof AsynchronousCloseException))
-            throw new RuntimeException("AsynchronousCloseException expected");
-
-        server.close();
     }
 
     static void testCancel() throws Exception {
         System.out.println("-- cancel --");
 
-        Server server = new Server();
+        try (Server server = new Server()) {
+            for (int i=0; i<2; i++) {
+                boolean mayInterruptIfRunning = (i == 0) ? false : true;
 
-        for (int i=0; i<2; i++) {
-            boolean mayInterruptIfRunning = (i == 0) ? false : true;
+                // establish loopback connection
+                AsynchronousSocketChannel ch = AsynchronousSocketChannel.open();
+                ch.connect(server.address()).get();
+                SocketChannel peer = server.accept();
 
-            // establish loopback connection
-            AsynchronousSocketChannel ch = AsynchronousSocketChannel.open();
-            ch.connect(server.address()).get();
-            SocketChannel peer = server.accept();
+                // start read operation
+                ByteBuffer buf = ByteBuffer.allocate(1);
+                Future<Integer> res = ch.read(buf);
 
-            // start read operation
-            ByteBuffer buf = ByteBuffer.allocate(1);
-            Future<Integer> res = ch.read(buf);
+                // cancel operation
+                boolean cancelled = res.cancel(mayInterruptIfRunning);
 
-            // cancel operation
-            boolean cancelled = res.cancel(mayInterruptIfRunning);
+                // check post-conditions
+                if (!res.isDone())
+                    throw new RuntimeException("isDone should return true");
+                if (res.isCancelled() != cancelled)
+                    throw new RuntimeException("isCancelled not consistent");
+                try {
+                    res.get();
+                    throw new RuntimeException("CancellationException expected");
+                } catch (CancellationException x) {
+                }
+                try {
+                    res.get(1, TimeUnit.SECONDS);
+                    throw new RuntimeException("CancellationException expected");
+                } catch (CancellationException x) {
+                }
 
-            // check post-conditions
-            if (!res.isDone())
-                throw new RuntimeException("isDone should return true");
-            if (res.isCancelled() != cancelled)
-                throw new RuntimeException("isCancelled not consistent");
-            try {
-                res.get();
-                throw new RuntimeException("CancellationException expected");
-            } catch (CancellationException x) {
+                // check that the cancel doesn't impact writing to the channel
+                if (!mayInterruptIfRunning) {
+                    buf = ByteBuffer.wrap("a".getBytes());
+                    ch.write(buf).get();
+                }
+
+                ch.close();
+                peer.close();
             }
-            try {
-                res.get(1, TimeUnit.SECONDS);
-                throw new RuntimeException("CancellationException expected");
-            } catch (CancellationException x) {
-            }
-
-            // check that the cancel doesn't impact writing to the channel
-            if (!mayInterruptIfRunning) {
-                buf = ByteBuffer.wrap("a".getBytes());
-                ch.write(buf).get();
-            }
-
-            ch.close();
-            peer.close();
         }
-
-        server.close();
     }
 
     static void testRead1() throws Exception {
         System.out.println("-- read (1) --");
 
-        Server server = new Server();
-        final AsynchronousSocketChannel ch = AsynchronousSocketChannel.open();
-        ch.connect(server.address()).get();
+        try (Server server = new Server()) {
+            final AsynchronousSocketChannel ch = AsynchronousSocketChannel.open();
+            ch.connect(server.address()).get();
 
-        // read with 0 bytes remaining should complete immediately
-        ByteBuffer buf = ByteBuffer.allocate(1);
-        buf.put((byte)0);
-        int n = ch.read(buf).get();
-        if (n != 0)
-            throw new RuntimeException("0 expected");
+            // read with 0 bytes remaining should complete immediately
+            ByteBuffer buf = ByteBuffer.allocate(1);
+            buf.put((byte)0);
+            int n = ch.read(buf).get();
+            if (n != 0)
+                throw new RuntimeException("0 expected");
 
-        // write bytes and close connection
-        SocketChannel sc = server.accept();
-        ByteBuffer src = genBuffer();
-        sc.setOption(StandardSocketOptions.SO_SNDBUF, src.remaining());
-        while (src.hasRemaining())
-            sc.write(src);
-        sc.close();
+            // write bytes and close connection
+            ByteBuffer src = genBuffer();
+            try (SocketChannel sc = server.accept()) {
+                sc.setOption(SO_SNDBUF, src.remaining());
+                while (src.hasRemaining())
+                    sc.write(src);
+            }
 
-        // reads should complete immediately
-        final ByteBuffer dst = ByteBuffer.allocateDirect(src.capacity() + 100);
-        final CountDownLatch latch = new CountDownLatch(1);
-        ch.read(dst, (Void)null, new CompletionHandler<Integer,Void>() {
-            public void completed(Integer result, Void att) {
-                int n = result;
-                if (n > 0) {
-                    ch.read(dst, (Void)null, this);
-                } else {
-                    latch.countDown();
+            // reads should complete immediately
+            final ByteBuffer dst = ByteBuffer.allocateDirect(src.capacity() + 100);
+            final CountDownLatch latch = new CountDownLatch(1);
+            ch.read(dst, (Void)null, new CompletionHandler<Integer,Void>() {
+                public void completed(Integer result, Void att) {
+                    int n = result;
+                    if (n > 0) {
+                        ch.read(dst, (Void)null, this);
+                    } else {
+                        latch.countDown();
+                    }
                 }
+                public void failed(Throwable exc, Void att) {
+                }
+            });
+
+            latch.await();
+
+            // check buffers
+            src.flip();
+            dst.flip();
+            if (!src.equals(dst)) {
+                throw new RuntimeException("Contents differ");
             }
-            public void failed(Throwable exc, Void att) {
+
+            // close channel
+            ch.close();
+
+            // check read fails with ClosedChannelException
+            try {
+                ch.read(dst).get();
+                throw new RuntimeException("ExecutionException expected");
+            } catch (ExecutionException x) {
+                if (!(x.getCause() instanceof ClosedChannelException))
+                    throw new RuntimeException("Cause of ClosedChannelException expected");
             }
-        });
-
-        latch.await();
-
-        // check buffers
-        src.flip();
-        dst.flip();
-        if (!src.equals(dst)) {
-            throw new RuntimeException("Contents differ");
         }
-
-        // close channel
-        ch.close();
-
-        // check read fails with ClosedChannelException
-        try {
-            ch.read(dst).get();
-            throw new RuntimeException("ExecutionException expected");
-        } catch (ExecutionException x) {
-            if (!(x.getCause() instanceof ClosedChannelException))
-                throw new RuntimeException("Cause of ClosedChannelException expected");
-        }
-
-        server.close();
     }
 
     static void testRead2() throws Exception {
         System.out.println("-- read (2) --");
 
-        Server server = new Server();
+        try (Server server = new Server()) {
+            final AsynchronousSocketChannel ch = AsynchronousSocketChannel.open();
+            ch.connect(server.address()).get();
+            SocketChannel sc = server.accept();
 
-        final AsynchronousSocketChannel ch = AsynchronousSocketChannel.open();
-        ch.connect(server.address()).get();
-        SocketChannel sc = server.accept();
+            ByteBuffer src = genBuffer();
 
-        ByteBuffer src = genBuffer();
+            // read until the buffer is full
+            final ByteBuffer dst = ByteBuffer.allocateDirect(src.capacity());
+            final CountDownLatch latch = new CountDownLatch(1);
+            ch.read(dst, (Void)null, new CompletionHandler<Integer,Void>() {
+                public void completed(Integer result, Void att) {
+                    if (dst.hasRemaining()) {
+                        ch.read(dst, (Void)null, this);
+                    } else {
+                        latch.countDown();
+                    }
+                }
+                public void failed(Throwable exc, Void att) {
+                }
+            });
 
-        // read until the buffer is full
-        final ByteBuffer dst = ByteBuffer.allocateDirect(src.capacity());
-        final CountDownLatch latch = new CountDownLatch(1);
-        ch.read(dst, (Void)null, new CompletionHandler<Integer,Void>() {
-            public void completed(Integer result, Void att) {
-                if (dst.hasRemaining()) {
-                    ch.read(dst, (Void)null, this);
-                } else {
-                    latch.countDown();
-                }
+            // trickle the writing
+            do {
+                int rem = src.remaining();
+                int size = (rem <= 100) ? rem : 50 + rand.nextInt(rem - 100);
+                ByteBuffer buf = ByteBuffer.allocate(size);
+                for (int i=0; i<size; i++)
+                    buf.put(src.get());
+                buf.flip();
+                Thread.sleep(50 + rand.nextInt(1500));
+                while (buf.hasRemaining())
+                    sc.write(buf);
+            } while (src.hasRemaining());
+
+            // wait until ascynrhonous reading has completed
+            latch.await();
+
+            // check buffers
+            src.flip();
+            dst.flip();
+            if (!src.equals(dst)) {
+               throw new RuntimeException("Contents differ");
             }
-            public void failed(Throwable exc, Void att) {
-            }
-        });
 
-        // trickle the writing
-        do {
-            int rem = src.remaining();
-            int size = (rem <= 100) ? rem : 50 + rand.nextInt(rem - 100);
-            ByteBuffer buf = ByteBuffer.allocate(size);
-            for (int i=0; i<size; i++)
-                buf.put(src.get());
-            buf.flip();
-            Thread.sleep(50 + rand.nextInt(1500));
-            while (buf.hasRemaining())
-                sc.write(buf);
-        } while (src.hasRemaining());
-
-        // wait until ascynrhonous reading has completed
-        latch.await();
-
-        // check buffers
-        src.flip();
-        dst.flip();
-        if (!src.equals(dst)) {
-           throw new RuntimeException("Contents differ");
+            sc.close();
+            ch.close();
         }
-
-        sc.close();
-        ch.close();
-        server.close();
     }
 
     // exercise scattering read
     static void testRead3() throws Exception {
         System.out.println("-- read (3) --");
 
-        Server server = new Server();
-        final AsynchronousSocketChannel ch = AsynchronousSocketChannel.open();
-        ch.connect(server.address()).get();
-        SocketChannel sc = server.accept();
+        try (Server server = new Server()) {
+            final AsynchronousSocketChannel ch = AsynchronousSocketChannel.open();
+            ch.connect(server.address()).get();
+            SocketChannel sc = server.accept();
 
-        ByteBuffer[] dsts = new ByteBuffer[3];
-        for (int i=0; i<dsts.length; i++) {
-            dsts[i] = ByteBuffer.allocateDirect(100);
+            ByteBuffer[] dsts = new ByteBuffer[3];
+            for (int i=0; i<dsts.length; i++) {
+                dsts[i] = ByteBuffer.allocateDirect(100);
+            }
+
+            // scattering read that completes ascynhronously
+            final CountDownLatch l1 = new CountDownLatch(1);
+            ch.read(dsts, 0, dsts.length, 0L, TimeUnit.SECONDS, (Void)null,
+                new CompletionHandler<Long,Void>() {
+                    public void completed(Long result, Void att) {
+                        long n = result;
+                        if (n <= 0)
+                            throw new RuntimeException("No bytes read");
+                        l1.countDown();
+                    }
+                    public void failed(Throwable exc, Void att) {
+                    }
+            });
+
+            // write some bytes
+            sc.write(genBuffer());
+
+            // read should now complete
+            l1.await();
+
+            // write more bytes
+            sc.write(genBuffer());
+
+            // read should complete immediately
+            for (int i=0; i<dsts.length; i++) {
+                dsts[i].rewind();
+            }
+
+            final CountDownLatch l2 = new CountDownLatch(1);
+            ch.read(dsts, 0, dsts.length, 0L, TimeUnit.SECONDS, (Void)null,
+                new CompletionHandler<Long,Void>() {
+                    public void completed(Long result, Void att) {
+                        long n = result;
+                        if (n <= 0)
+                            throw new RuntimeException("No bytes read");
+                        l2.countDown();
+                    }
+                    public void failed(Throwable exc, Void att) {
+                    }
+            });
+            l2.await();
+
+            ch.close();
+            sc.close();
         }
-
-        // scattering read that completes ascynhronously
-        final CountDownLatch l1 = new CountDownLatch(1);
-        ch.read(dsts, 0, dsts.length, 0L, TimeUnit.SECONDS, (Void)null,
-            new CompletionHandler<Long,Void>() {
-                public void completed(Long result, Void att) {
-                    long n = result;
-                    if (n <= 0)
-                        throw new RuntimeException("No bytes read");
-                    l1.countDown();
-                }
-                public void failed(Throwable exc, Void att) {
-                }
-        });
-
-        // write some bytes
-        sc.write(genBuffer());
-
-        // read should now complete
-        l1.await();
-
-        // write more bytes
-        sc.write(genBuffer());
-
-        // read should complete immediately
-        for (int i=0; i<dsts.length; i++) {
-            dsts[i].rewind();
-        }
-
-        final CountDownLatch l2 = new CountDownLatch(1);
-        ch.read(dsts, 0, dsts.length, 0L, TimeUnit.SECONDS, (Void)null,
-            new CompletionHandler<Long,Void>() {
-                public void completed(Long result, Void att) {
-                    long n = result;
-                    if (n <= 0)
-                        throw new RuntimeException("No bytes read");
-                    l2.countDown();
-                }
-                public void failed(Throwable exc, Void att) {
-                }
-        });
-        l2.await();
-
-        ch.close();
-        sc.close();
-        server.close();
     }
 
     static void testWrite1() throws Exception {
         System.out.println("-- write (1) --");
 
-        Server server = new Server();
-        final AsynchronousSocketChannel ch = AsynchronousSocketChannel.open();
-        ch.connect(server.address()).get();
-        SocketChannel sc = server.accept();
+        try (Server server = new Server()) {
+            final AsynchronousSocketChannel ch = AsynchronousSocketChannel.open();
+            ch.connect(server.address()).get();
+            SocketChannel sc = server.accept();
 
-        // write with 0 bytes remaining should complete immediately
-        ByteBuffer buf = ByteBuffer.allocate(1);
-        buf.put((byte)0);
-        int n = ch.write(buf).get();
-        if (n != 0)
-            throw new RuntimeException("0 expected");
+            // write with 0 bytes remaining should complete immediately
+            ByteBuffer buf = ByteBuffer.allocate(1);
+            buf.put((byte)0);
+            int n = ch.write(buf).get();
+            if (n != 0)
+                throw new RuntimeException("0 expected");
 
-        // write all bytes and close connection when done
-        final ByteBuffer src = genBuffer();
-        ch.write(src, (Void)null, new CompletionHandler<Integer,Void>() {
-            public void completed(Integer result, Void att) {
-                if (src.hasRemaining()) {
-                    ch.write(src, (Void)null, this);
-                } else {
-                    try {
-                        ch.close();
-                    } catch (IOException ignore) { }
+            // write all bytes and close connection when done
+            final ByteBuffer src = genBuffer();
+            ch.write(src, (Void)null, new CompletionHandler<Integer,Void>() {
+                public void completed(Integer result, Void att) {
+                    if (src.hasRemaining()) {
+                        ch.write(src, (Void)null, this);
+                    } else {
+                        try {
+                            ch.close();
+                        } catch (IOException ignore) { }
+                    }
                 }
+                public void failed(Throwable exc, Void att) {
+                }
+            });
+
+            // read to EOF or buffer full
+            ByteBuffer dst = ByteBuffer.allocateDirect(src.capacity() + 100);
+            do {
+                n = sc.read(dst);
+            } while (n > 0);
+            sc.close();
+
+            // check buffers
+            src.flip();
+            dst.flip();
+            if (!src.equals(dst)) {
+                throw new RuntimeException("Contents differ");
             }
-            public void failed(Throwable exc, Void att) {
+
+            // check write fails with ClosedChannelException
+            try {
+                ch.read(dst).get();
+                throw new RuntimeException("ExecutionException expected");
+            } catch (ExecutionException x) {
+                if (!(x.getCause() instanceof ClosedChannelException))
+                    throw new RuntimeException("Cause of ClosedChannelException expected");
             }
-        });
-
-        // read to EOF or buffer full
-        ByteBuffer dst = ByteBuffer.allocateDirect(src.capacity() + 100);
-        do {
-            n = sc.read(dst);
-        } while (n > 0);
-        sc.close();
-
-        // check buffers
-        src.flip();
-        dst.flip();
-        if (!src.equals(dst)) {
-            throw new RuntimeException("Contents differ");
         }
-
-        // check write fails with ClosedChannelException
-        try {
-            ch.read(dst).get();
-            throw new RuntimeException("ExecutionException expected");
-        } catch (ExecutionException x) {
-            if (!(x.getCause() instanceof ClosedChannelException))
-                throw new RuntimeException("Cause of ClosedChannelException expected");
-        }
-
-        server.close();
     }
 
     // exercise gathering write
     static void testWrite2() throws Exception {
         System.out.println("-- write (2) --");
 
-        Server server = new Server();
-        final AsynchronousSocketChannel ch = AsynchronousSocketChannel.open();
-        ch.connect(server.address()).get();
-        SocketChannel sc = server.accept();
+        try (Server server = new Server()) {
+            final AsynchronousSocketChannel ch = AsynchronousSocketChannel.open();
+            ch.connect(server.address()).get();
+            SocketChannel sc = server.accept();
 
-        // number of bytes written
-        final AtomicLong bytesWritten = new AtomicLong(0);
+            // number of bytes written
+            final AtomicLong bytesWritten = new AtomicLong(0);
 
-        // write buffers (should complete immediately)
-        ByteBuffer[] srcs = genBuffers(1);
-        final CountDownLatch l1 = new CountDownLatch(1);
-        ch.write(srcs, 0, srcs.length, 0L, TimeUnit.SECONDS, (Void)null,
-            new CompletionHandler<Long,Void>() {
-                public void completed(Long result, Void att) {
-                    long n = result;
-                    if (n <= 0)
-                        throw new RuntimeException("No bytes read");
-                    bytesWritten.addAndGet(n);
-                    l1.countDown();
-                }
-                public void failed(Throwable exc, Void att) {
-                }
-        });
-        l1.await();
+            // write buffers (should complete immediately)
+            ByteBuffer[] srcs = genBuffers(1);
+            final CountDownLatch l1 = new CountDownLatch(1);
+            ch.write(srcs, 0, srcs.length, 0L, TimeUnit.SECONDS, (Void)null,
+                new CompletionHandler<Long,Void>() {
+                    public void completed(Long result, Void att) {
+                        long n = result;
+                        if (n <= 0)
+                            throw new RuntimeException("No bytes read");
+                        bytesWritten.addAndGet(n);
+                        l1.countDown();
+                    }
+                    public void failed(Throwable exc, Void att) {
+                    }
+            });
+            l1.await();
 
-        // set to true to signal that no more buffers should be written
-        final AtomicBoolean continueWriting = new AtomicBoolean(true);
+            // set to true to signal that no more buffers should be written
+            final AtomicBoolean continueWriting = new AtomicBoolean(true);
 
-        // write until socket buffer is full so as to create the conditions
-        // for when a write does not complete immediately
-        srcs = genBuffers(1);
-        ch.write(srcs, 0, srcs.length, 0L, TimeUnit.SECONDS, (Void)null,
-            new CompletionHandler<Long,Void>() {
-                public void completed(Long result, Void att) {
-                    long n = result;
-                    if (n <= 0)
-                        throw new RuntimeException("No bytes written");
-                    bytesWritten.addAndGet(n);
-                    if (continueWriting.get()) {
-                        ByteBuffer[] srcs = genBuffers(8);
-                        ch.write(srcs, 0, srcs.length, 0L, TimeUnit.SECONDS,
-                            (Void)null, this);
+            // write until socket buffer is full so as to create the conditions
+            // for when a write does not complete immediately
+            srcs = genBuffers(1);
+            ch.write(srcs, 0, srcs.length, 0L, TimeUnit.SECONDS, (Void)null,
+                new CompletionHandler<Long,Void>() {
+                    public void completed(Long result, Void att) {
+                        long n = result;
+                        if (n <= 0)
+                            throw new RuntimeException("No bytes written");
+                        bytesWritten.addAndGet(n);
+                        if (continueWriting.get()) {
+                            ByteBuffer[] srcs = genBuffers(8);
+                            ch.write(srcs, 0, srcs.length, 0L, TimeUnit.SECONDS,
+                                (Void)null, this);
+                        }
                     }
-                }
-                public void failed(Throwable exc, Void att) {
-                }
-        });
+                    public void failed(Throwable exc, Void att) {
+                    }
+            });
 
-        // give time for socket buffer to fill up.
-        Thread.sleep(5*1000);
+            // give time for socket buffer to fill up.
+            Thread.sleep(5*1000);
 
-        // signal handler to stop further writing
-        continueWriting.set(false);
+            // signal handler to stop further writing
+            continueWriting.set(false);
 
-        // read until done
-        ByteBuffer buf = ByteBuffer.allocateDirect(4096);
-        long total = 0L;
-        do {
-            int n = sc.read(buf);
-            if (n <= 0)
-                throw new RuntimeException("No bytes read");
-            buf.rewind();
-            total += n;
-        } while (total < bytesWritten.get());
+            // read until done
+            ByteBuffer buf = ByteBuffer.allocateDirect(4096);
+            long total = 0L;
+            do {
+                int n = sc.read(buf);
+                if (n <= 0)
+                    throw new RuntimeException("No bytes read");
+                buf.rewind();
+                total += n;
+            } while (total < bytesWritten.get());
 
-        ch.close();
-        sc.close();
-        server.close();
+            ch.close();
+            sc.close();
+        }
     }
 
     static void testShutdown() throws Exception {
         System.out.println("-- shutdown--");
 
-        Server server = new Server();
-        AsynchronousSocketChannel ch = AsynchronousSocketChannel.open();
-        ch.connect(server.address()).get();
-        SocketChannel sc = server.accept();
+        try (Server server = new Server();
+             AsynchronousSocketChannel ch = AsynchronousSocketChannel.open())
+        {
+            ch.connect(server.address()).get();
+            try (SocketChannel peer = server.accept()) {
+                ByteBuffer buf = ByteBuffer.allocateDirect(1000);
+                int n;
 
-        ByteBuffer buf = ByteBuffer.allocateDirect(1000);
-        int n;
+                // check read
+                ch.shutdownInput();
+                n = ch.read(buf).get();
+                if (n != -1)
+                    throw new RuntimeException("-1 expected");
+                // check full with full buffer
+                buf.put(new byte[100]);
+                n = ch.read(buf).get();
+                if (n != -1)
+                    throw new RuntimeException("-1 expected");
 
-        // check read
-        ch.shutdownInput();
-        n = ch.read(buf).get();
-        if (n != -1)
-            throw new RuntimeException("-1 expected");
-        // check full with full buffer
-        buf.put(new byte[100]);
-        n = ch.read(buf).get();
-        if (n != -1)
-            throw new RuntimeException("-1 expected");
-
-        // check write
-        ch.shutdownOutput();
-        try {
-            ch.write(buf).get();
-            throw new RuntimeException("ClosedChannelException expected");
-        } catch (ExecutionException x) {
-            if (!(x.getCause() instanceof ClosedChannelException))
-                throw new RuntimeException("ClosedChannelException expected");
+                // check write
+                ch.shutdownOutput();
+                try {
+                    ch.write(buf).get();
+                    throw new RuntimeException("ClosedChannelException expected");
+                } catch (ExecutionException x) {
+                    if (!(x.getCause() instanceof ClosedChannelException))
+                        throw new RuntimeException("ClosedChannelException expected");
+                }
+            }
         }
-
-        sc.close();
-        ch.close();
-        server.close();
     }
 
     static void testTimeout() throws Exception {
@@ -720,88 +740,88 @@
     }
 
     static void testTimeout(final long timeout, final TimeUnit unit) throws Exception {
-        Server server = new Server();
-        AsynchronousSocketChannel ch = AsynchronousSocketChannel.open();
-        ch.connect(server.address()).get();
+        try (Server server = new Server()) {
+            AsynchronousSocketChannel ch = AsynchronousSocketChannel.open();
+            ch.connect(server.address()).get();
 
-        ByteBuffer dst = ByteBuffer.allocate(512);
+            ByteBuffer dst = ByteBuffer.allocate(512);
 
-        final AtomicReference<Throwable> readException = new AtomicReference<Throwable>();
+            final AtomicReference<Throwable> readException = new AtomicReference<Throwable>();
 
-        // this read should timeout if value is > 0
-        ch.read(dst, timeout, unit, null, new CompletionHandler<Integer,Void>() {
-            public void completed(Integer result, Void att) {
-                readException.set(new RuntimeException("Should not complete"));
+            // this read should timeout if value is > 0
+            ch.read(dst, timeout, unit, null, new CompletionHandler<Integer,Void>() {
+                public void completed(Integer result, Void att) {
+                    readException.set(new RuntimeException("Should not complete"));
+                }
+                public void failed(Throwable exc, Void att) {
+                    readException.set(exc);
+                }
+            });
+            if (timeout > 0L) {
+                // wait for exception
+                while (readException.get() == null) {
+                    Thread.sleep(100);
+                }
+                if (!(readException.get() instanceof InterruptedByTimeoutException))
+                    throw new RuntimeException("InterruptedByTimeoutException expected");
+
+                // after a timeout then further reading should throw unspecified runtime exception
+                boolean exceptionThrown = false;
+                try {
+                    ch.read(dst);
+                } catch (RuntimeException x) {
+                    exceptionThrown = true;
+                }
+                if (!exceptionThrown)
+                    throw new RuntimeException("RuntimeException expected after timeout.");
+            } else {
+                Thread.sleep(1000);
+                Throwable exc = readException.get();
+                if (exc != null)
+                    throw new RuntimeException(exc);
             }
-            public void failed(Throwable exc, Void att) {
-                readException.set(exc);
+
+            final AtomicReference<Throwable> writeException = new AtomicReference<Throwable>();
+
+            // write bytes to fill socket buffer
+            ch.write(genBuffer(), timeout, unit, ch,
+                new CompletionHandler<Integer,AsynchronousSocketChannel>()
+            {
+                public void completed(Integer result, AsynchronousSocketChannel ch) {
+                    ch.write(genBuffer(), timeout, unit, ch, this);
+                }
+                public void failed(Throwable exc, AsynchronousSocketChannel ch) {
+                    writeException.set(exc);
+                }
+            });
+            if (timeout > 0) {
+                // wait for exception
+                while (writeException.get() == null) {
+                    Thread.sleep(100);
+                }
+                if (!(writeException.get() instanceof InterruptedByTimeoutException))
+                    throw new RuntimeException("InterruptedByTimeoutException expected");
+
+                // after a timeout then further writing should throw unspecified runtime exception
+                boolean exceptionThrown = false;
+                try {
+                    ch.write(genBuffer());
+                } catch (RuntimeException x) {
+                    exceptionThrown = true;
+                }
+                if (!exceptionThrown)
+                    throw new RuntimeException("RuntimeException expected after timeout.");
+            } else {
+                Thread.sleep(1000);
+                Throwable exc = writeException.get();
+                if (exc != null)
+                    throw new RuntimeException(exc);
             }
-        });
-        if (timeout > 0L) {
-            // wait for exception
-            while (readException.get() == null) {
-                Thread.sleep(100);
-            }
-            if (!(readException.get() instanceof InterruptedByTimeoutException))
-                throw new RuntimeException("InterruptedByTimeoutException expected");
 
-            // after a timeout then further reading should throw unspecified runtime exception
-            boolean exceptionThrown = false;
-            try {
-                ch.read(dst);
-            } catch (RuntimeException x) {
-                exceptionThrown = true;
-            }
-            if (!exceptionThrown)
-                throw new RuntimeException("RuntimeException expected after timeout.");
-        } else {
-            Thread.sleep(1000);
-            Throwable exc = readException.get();
-            if (exc != null)
-                throw new RuntimeException(exc);
+            // clean-up
+            server.accept().close();
+            ch.close();
         }
-
-        final AtomicReference<Throwable> writeException = new AtomicReference<Throwable>();
-
-        // write bytes to fill socket buffer
-        ch.write(genBuffer(), timeout, unit, ch,
-            new CompletionHandler<Integer,AsynchronousSocketChannel>()
-        {
-            public void completed(Integer result, AsynchronousSocketChannel ch) {
-                ch.write(genBuffer(), timeout, unit, ch, this);
-            }
-            public void failed(Throwable exc, AsynchronousSocketChannel ch) {
-                writeException.set(exc);
-            }
-        });
-        if (timeout > 0) {
-            // wait for exception
-            while (writeException.get() == null) {
-                Thread.sleep(100);
-            }
-            if (!(writeException.get() instanceof InterruptedByTimeoutException))
-                throw new RuntimeException("InterruptedByTimeoutException expected");
-
-            // after a timeout then further writing should throw unspecified runtime exception
-            boolean exceptionThrown = false;
-            try {
-                ch.write(genBuffer());
-            } catch (RuntimeException x) {
-                exceptionThrown = true;
-            }
-            if (!exceptionThrown)
-                throw new RuntimeException("RuntimeException expected after timeout.");
-        } else {
-            Thread.sleep(1000);
-            Throwable exc = writeException.get();
-            if (exc != null)
-                throw new RuntimeException(exc);
-        }
-
-        // clean-up
-        server.accept().close();
-        ch.close();
-        server.close();
     }
 
     // returns ByteBuffer with random bytes
--- a/test/java/security/BasicPermission/PermClass.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/test/java/security/BasicPermission/PermClass.java	Thu Jun 30 14:18:40 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 4511601
+ * @bug 4511601 7054918
  * @summary BasicPermissionCollection does not set permClass
  *              during deserialization
  */
@@ -55,59 +55,66 @@
 
         // read in a 1.2.1 BasicPermissionCollection
         File sFile = new File(dir, "PermClass.1.2.1");
-        ObjectInputStream ois = new ObjectInputStream
-                (new FileInputStream(sFile));
-        PermissionCollection pc = (PermissionCollection)ois.readObject();
-        System.out.println("1.2.1 collection = " + pc);
+        try (FileInputStream fis = new FileInputStream(sFile);
+                ObjectInputStream ois = new ObjectInputStream(fis)) {
+            PermissionCollection pc = (PermissionCollection)ois.readObject();
+            System.out.println("1.2.1 collection = " + pc);
 
-        if (pc.implies(mp)) {
-            System.out.println("JDK 1.2.1 test passed");
-        } else {
-            throw new Exception("JDK 1.2.1 test failed");
+            if (pc.implies(mp)) {
+                System.out.println("JDK 1.2.1 test passed");
+            } else {
+                throw new Exception("JDK 1.2.1 test failed");
+            }
         }
 
         // read in a 1.3.1 BasicPermissionCollection
         sFile = new File(dir, "PermClass.1.3.1");
-        ois = new ObjectInputStream(new FileInputStream(sFile));
-        pc = (PermissionCollection)ois.readObject();
-        System.out.println("1.3.1 collection = " + pc);
+        try (FileInputStream fis = new FileInputStream(sFile);
+                ObjectInputStream ois = new ObjectInputStream(fis)) {
+            PermissionCollection pc = (PermissionCollection)ois.readObject();
+            System.out.println("1.3.1 collection = " + pc);
 
-        if (pc.implies(mp)) {
-            System.out.println("JDK 1.3.1 test passed");
-        } else {
-            throw new Exception("JDK 1.3.1 test failed");
+            if (pc.implies(mp)) {
+                System.out.println("JDK 1.3.1 test passed");
+            } else {
+                throw new Exception("JDK 1.3.1 test failed");
+            }
         }
 
         // read in a 1.4 BasicPermissionCollection
         sFile = new File(dir, "PermClass.1.4");
-        ois = new ObjectInputStream(new FileInputStream(sFile));
-        pc = (PermissionCollection)ois.readObject();
-        System.out.println("1.4 collection = " + pc);
+        try (FileInputStream fis = new FileInputStream(sFile);
+                ObjectInputStream ois = new ObjectInputStream(fis)) {
+            PermissionCollection pc = (PermissionCollection)ois.readObject();
+            System.out.println("1.4 collection = " + pc);
 
-        if (pc.implies(mp)) {
-            System.out.println("JDK 1.4 test 1 passed");
-        } else {
-            throw new Exception("JDK 1.4 test 1 failed");
+            if (pc.implies(mp)) {
+                System.out.println("JDK 1.4 test 1 passed");
+            } else {
+                throw new Exception("JDK 1.4 test 1 failed");
+            }
         }
 
         // write out current BasicPermissionCollection
         PermissionCollection bpc = mp.newPermissionCollection();
         bpc.add(mp);
         sFile = new File(dir, "PermClass.current");
-        ObjectOutputStream oos = new ObjectOutputStream
-                (new FileOutputStream("PermClass.current"));
-        oos.writeObject(bpc);
-        oos.close();
+        try (FileOutputStream fos = new FileOutputStream("PermClass.current");
+                ObjectOutputStream oos = new ObjectOutputStream(fos)) {
+            oos.writeObject(bpc);
+        }
 
         // read in current BasicPermissionCollection
-        ois = new ObjectInputStream(new FileInputStream("PermClass.current"));
-        pc = (PermissionCollection)ois.readObject();
-        System.out.println("current collection = " + pc);
+        try (FileInputStream fis = new FileInputStream("PermClass.current");
+                ObjectInputStream ois = new ObjectInputStream(fis)) {
+            PermissionCollection pc = (PermissionCollection)ois.readObject();
+            System.out.println("current collection = " + pc);
 
-        if (pc.implies(mp)) {
-            System.out.println("JDK 1.4 test 2 passed");
-        } else {
-            throw new Exception("JDK 1.4 test 2 failed");
+            if (pc.implies(mp)) {
+                System.out.println("JDK 1.4 test 2 passed");
+            } else {
+                throw new Exception("JDK 1.4 test 2 failed");
+            }
         }
     }
 }
--- a/test/java/security/BasicPermission/SerialVersion.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/test/java/security/BasicPermission/SerialVersion.java	Thu Jun 30 14:18:40 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 4502729
+ * @bug 4502729 7054918
  * @summary BasicPermissionCollection serial version UID incorrect
  */
 
@@ -36,40 +36,44 @@
         String dir = System.getProperty("test.src");
         File  sFile =  new File (dir,"SerialVersion.1.2.1");
         // read in a 1.2.1 BasicPermissionCollection
-        ObjectInputStream ois = new ObjectInputStream
-                (new FileInputStream(sFile));
-        PermissionCollection pc = (PermissionCollection)ois.readObject();
-        System.out.println("1.2.1 collection = " + pc);
+        try (FileInputStream fis = new FileInputStream(sFile);
+                ObjectInputStream ois = new ObjectInputStream(fis)) {
+            PermissionCollection pc = (PermissionCollection)ois.readObject();
+            System.out.println("1.2.1 collection = " + pc);
+        }
 
         // read in a 1.3.1 BasicPermissionCollection
         sFile =  new File (dir,"SerialVersion.1.3.1");
 
-        ois = new ObjectInputStream
-                (new FileInputStream(sFile));
-        pc = (PermissionCollection)ois.readObject();
-        System.out.println("1.3.1 collection = " + pc);
+        try (FileInputStream fis = new FileInputStream(sFile);
+                ObjectInputStream ois = new ObjectInputStream(fis)) {
+            PermissionCollection pc = (PermissionCollection)ois.readObject();
+            System.out.println("1.3.1 collection = " + pc);
+        }
 
         // read in a 1.4 BasicPermissionCollection
         sFile =  new File (dir,"SerialVersion.1.4");
-        ois = new ObjectInputStream
-                (new FileInputStream(sFile));
-        pc = (PermissionCollection)ois.readObject();
-        System.out.println("1.4 collection = " + pc);
+        try (FileInputStream fis = new FileInputStream(sFile);
+                ObjectInputStream ois = new ObjectInputStream(fis)) {
+            PermissionCollection pc = (PermissionCollection)ois.readObject();
+            System.out.println("1.4 collection = " + pc);
+        }
 
         // write out current BasicPermissionCollection
         MyPermission mp = new MyPermission("SerialVersionTest");
         PermissionCollection bpc = mp.newPermissionCollection();
         sFile =  new File (dir,"SerialVersion.current");
-        ObjectOutputStream oos = new ObjectOutputStream
-                (new FileOutputStream("SerialVersion.current"));
-        oos.writeObject(bpc);
-        oos.close();
+        try (FileOutputStream fos = new FileOutputStream("SerialVersion.current");
+                ObjectOutputStream oos = new ObjectOutputStream(fos)) {
+            oos.writeObject(bpc);
+        }
 
         // read in current BasicPermissionCollection
-        ois = new ObjectInputStream
-                (new FileInputStream("SerialVersion.current"));
-        pc = (PermissionCollection)ois.readObject();
-        System.out.println("current collection = " + pc);
+        try (FileInputStream fis = new FileInputStream("SerialVersion.current");
+                ObjectInputStream ois = new ObjectInputStream(fis)) {
+            PermissionCollection pc = (PermissionCollection)ois.readObject();
+            System.out.println("current collection = " + pc);
+        }
     }
 }
 
--- a/test/java/security/KeyFactory/Failover.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/test/java/security/KeyFactory/Failover.java	Thu Jun 30 14:18:40 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,8 @@
 
 /**
  * @test
- * @bug 4894125
+ * @bug 4894125 7054918
+ * @library ../testlibrary
  * @summary test that failover for KeyFactory works
  * @author Andreas Sterbenz
  */
@@ -37,6 +38,15 @@
 public class Failover {
 
     public static void main(String[] args) throws Exception {
+        ProvidersSnapshot snapshot = ProvidersSnapshot.create();
+        try {
+            main0(args);
+        } finally {
+            snapshot.restore();
+        }
+    }
+
+    public static void main0(String[] args) throws Exception {
         Security.insertProviderAt(new ProviderFail(), 1);
         Security.addProvider(new ProviderPass());
         System.out.println(Arrays.asList(Security.getProviders()));
--- a/test/java/security/KeyPairGenerator/Failover.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/test/java/security/KeyPairGenerator/Failover.java	Thu Jun 30 14:18:40 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,8 @@
 
 /**
  * @test
- * @bug 4894125
+ * @bug 4894125 7054918
+ * @library ../testlibrary
  * @summary test that failover for KeyPairGenerator works
  * @author Andreas Sterbenz
  */
@@ -37,6 +38,15 @@
 public class Failover {
 
     public static void main(String[] args) throws Exception {
+        ProvidersSnapshot snapshot = ProvidersSnapshot.create();
+        try {
+            main0(args);
+        } finally {
+            snapshot.restore();
+        }
+    }
+
+    public static void main0(String[] args) throws Exception {
         Security.insertProviderAt(new ProviderFail(), 1);
         Security.addProvider(new ProviderPass());
         System.out.println(Arrays.asList(Security.getProviders()));
--- a/test/java/security/Provider/ChangeProviders.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/test/java/security/Provider/ChangeProviders.java	Thu Jun 30 14:18:40 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,8 @@
 
 /*
  * @test
- * @bug 4856968
+ * @bug 4856968 7054918
+ * @library ../testlibrary
  * @summary make sure add/insert/removeProvider() work correctly
  * @author Andreas Sterbenz
  */
@@ -43,6 +44,15 @@
     }
 
     public static void main(String[] args) throws Exception {
+        ProvidersSnapshot snapshot = ProvidersSnapshot.create();
+        try {
+            main0(args);
+        } finally {
+            snapshot.restore();
+        }
+    }
+
+    public static void main0(String[] args) throws Exception {
         long start = System.currentTimeMillis();
         Provider p = new ChangeProviders();
 
--- a/test/java/security/Provider/GetInstance.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/test/java/security/Provider/GetInstance.java	Thu Jun 30 14:18:40 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,8 @@
 
 /*
  * @test
- * @bug 4856968
+ * @bug 4856968 7054918
+ * @library ../testlibrary
  * @summary make sure getInstance() works correctly, including failover
  *   and delayed provider selection for Signatures
  * @author Andreas Sterbenz
@@ -43,6 +44,15 @@
     }
 
     public static void main(String[] args) throws Exception {
+        ProvidersSnapshot snapshot = ProvidersSnapshot.create();
+        try {
+            main0(args);
+        } finally {
+            snapshot.restore();
+        }
+    }
+
+    public static void main0(String[] args) throws Exception {
         long start = System.currentTimeMillis();
 
         Provider foo = new FooProvider();
--- a/test/java/security/Provider/RemoveProvider.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/test/java/security/Provider/RemoveProvider.java	Thu Jun 30 14:18:40 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,8 @@
 
 /*
  * @test
- * @bug 4190873
+ * @bug 4190873 7054918
+ * @library ../testlibrary
  * @summary Make sure provider instance can be removed from list of registered
  * providers, and "entrySet", "keySet", and "values" methods don't loop
  * indefinitely.
@@ -34,6 +35,15 @@
 public class RemoveProvider {
 
     public static void main(String[] args) throws Exception {
+        ProvidersSnapshot snapshot = ProvidersSnapshot.create();
+        try {
+            main0(args);
+        } finally {
+            snapshot.restore();
+        }
+    }
+
+    public static void main0(String[] args) throws Exception {
 
         // Add provider 1
         Provider p1 = new MyProvider("name1",1,"");
--- a/test/java/security/Provider/Turkish.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/test/java/security/Provider/Turkish.java	Thu Jun 30 14:18:40 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,9 +23,8 @@
 
 /**
  * @test
- * @bug 6220064
+ * @bug 6220064 7054918
  * @summary make sure everything works ok in the Turkish local (dotted/dotless i problem)
- * @run main/othervm Turkish
  * @author Andreas Sterbenz
  */
 
@@ -41,54 +40,59 @@
         Provider p1 = new TProvider("T1");
         System.out.println(p1.getServices()); // trigger service parsing
 
-        Locale.setDefault(new Locale("tr", "TR"));
+        Locale loc = Locale.getDefault();
+        try {
+            Locale.setDefault(new Locale("tr", "TR"));
 
-        Provider p2 = new TProvider("T2");
-        System.out.println(p2.getServices()); // trigger service parsing
+            Provider p2 = new TProvider("T2");
+            System.out.println(p2.getServices()); // trigger service parsing
 
-        System.out.println(Signature.getInstance("MD5withRSA"));
-        System.out.println(Signature.getInstance("md5withrsa"));
-        System.out.println(Signature.getInstance("MD5WITHRSA"));
-        Service s1, s2;
-        s1 = p1.getService("Signature", "MD5withRSA");
-        check(s1, null);
-        check(s1, p1.getService("Signature", "md5withrsa"));
-        check(s1, p1.getService("Signature", "MD5WITHRSA"));
-        check(s1, p1.getService("Signature", "MD5RSA"));
-        check(s1, p1.getService("Signature", "md5rsa"));
-        check(s1, p1.getService("Signature", "MD5rsa"));
+            System.out.println(Signature.getInstance("MD5withRSA"));
+            System.out.println(Signature.getInstance("md5withrsa"));
+            System.out.println(Signature.getInstance("MD5WITHRSA"));
+            Service s1, s2;
+            s1 = p1.getService("Signature", "MD5withRSA");
+            check(s1, null);
+            check(s1, p1.getService("Signature", "md5withrsa"));
+            check(s1, p1.getService("Signature", "MD5WITHRSA"));
+            check(s1, p1.getService("Signature", "MD5RSA"));
+            check(s1, p1.getService("Signature", "md5rsa"));
+            check(s1, p1.getService("Signature", "MD5rsa"));
 
-        s1 = p1.getService("Signature", "SHAwithRSA");
-        check(s1, null);
-        check(s1, p1.getService("Signature", "shawithrsa"));
-        check(s1, p1.getService("Signature", "SHAWITHRSA"));
-        check(s1, p1.getService("Signature", "SHARSA"));
-        check(s1, p1.getService("Signature", "sharsa"));
-        check(s1, p1.getService("Signature", "SHArsa"));
-        check(s1, p1.getService("Signature", "SHA1RSA"));
-        check(s1, p1.getService("Signature", "sha1rsa"));
-        check(s1, p1.getService("Signature", "SHA1rsa"));
+            s1 = p1.getService("Signature", "SHAwithRSA");
+            check(s1, null);
+            check(s1, p1.getService("Signature", "shawithrsa"));
+            check(s1, p1.getService("Signature", "SHAWITHRSA"));
+            check(s1, p1.getService("Signature", "SHARSA"));
+            check(s1, p1.getService("Signature", "sharsa"));
+            check(s1, p1.getService("Signature", "SHArsa"));
+            check(s1, p1.getService("Signature", "SHA1RSA"));
+            check(s1, p1.getService("Signature", "sha1rsa"));
+            check(s1, p1.getService("Signature", "SHA1rsa"));
 
-        s1 = p2.getService("Signature", "MD5withRSA");
-        check(s1, null);
-        check(s1, p2.getService("Signature", "md5withrsa"));
-        check(s1, p2.getService("Signature", "MD5WITHRSA"));
-        check(s1, p2.getService("Signature", "MD5RSA"));
-        check(s1, p2.getService("Signature", "md5rsa"));
-        check(s1, p2.getService("Signature", "MD5rsa"));
+            s1 = p2.getService("Signature", "MD5withRSA");
+            check(s1, null);
+            check(s1, p2.getService("Signature", "md5withrsa"));
+            check(s1, p2.getService("Signature", "MD5WITHRSA"));
+            check(s1, p2.getService("Signature", "MD5RSA"));
+            check(s1, p2.getService("Signature", "md5rsa"));
+            check(s1, p2.getService("Signature", "MD5rsa"));
 
-        s1 = p2.getService("Signature", "SHAwithRSA");
-        check(s1, null);
-        check(s1, p2.getService("Signature", "shawithrsa"));
-        check(s1, p2.getService("Signature", "SHAWITHRSA"));
-        check(s1, p2.getService("Signature", "SHARSA"));
-        check(s1, p2.getService("Signature", "sharsa"));
-        check(s1, p2.getService("Signature", "SHArsa"));
-        check(s1, p2.getService("Signature", "SHA1RSA"));
-        check(s1, p2.getService("Signature", "sha1rsa"));
-        check(s1, p2.getService("Signature", "SHA1rsa"));
+            s1 = p2.getService("Signature", "SHAwithRSA");
+            check(s1, null);
+            check(s1, p2.getService("Signature", "shawithrsa"));
+            check(s1, p2.getService("Signature", "SHAWITHRSA"));
+            check(s1, p2.getService("Signature", "SHARSA"));
+            check(s1, p2.getService("Signature", "sharsa"));
+            check(s1, p2.getService("Signature", "SHArsa"));
+            check(s1, p2.getService("Signature", "SHA1RSA"));
+            check(s1, p2.getService("Signature", "sha1rsa"));
+            check(s1, p2.getService("Signature", "SHA1rsa"));
 
-        System.out.println("OK");
+            System.out.println("OK");
+        } finally {
+            Locale.setDefault(loc);
+        }
     }
 
     private static void check(Service s1, Service s2) throws Exception {
--- a/test/java/security/SecureClassLoader/DefineClassByteBuffer.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/test/java/security/SecureClassLoader/DefineClassByteBuffer.java	Thu Jun 30 14:18:40 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 4894899
+ * @bug 4894899 7054428
  * @summary Test various cases of passing java.nio.ByteBuffers
  * to defineClass().
  *
@@ -46,6 +46,17 @@
     }
 
     public static void main(String arg[]) throws Exception {
+
+        // Rename the compiled TestClass.class file to something else,
+        // otherwise it would be loaded by the parent class loader and
+        // DummyClassLoader will never be used, especially in /othervm mode.
+
+        File oldFile = new File(System.getProperty("test.classes", "."),
+                                  "TestClass.class");
+        File newFile = new File(System.getProperty("test.classes", "."),
+                                  "CLAZZ");
+        oldFile.renameTo(newFile);
+
         ClassLoader[] cls = new ClassLoader[DummyClassLoader.MAX_TYPE];
         for (int i = 0; i < cls.length; i++) {
             cls[i] = new DummyClassLoader(i);
@@ -54,7 +65,11 @@
         /* Create several instances of the class using different classloaders,
            which are using different types of ByteBuffer. */
         for (int i = 0; i < cls.length; i++) {
-          test(cls[i]);
+            test(cls[i]);
+        }
+
+        if (DummyClassLoader.count != cls.length) {
+             throw new Exception("DummyClassLoader not always used");
         }
     }
 
@@ -75,6 +90,8 @@
 
         int loaderType;
 
+        static int count = 0;
+
         DummyClassLoader(int loaderType) {
             this.loaderType = loaderType;
         }
@@ -84,10 +101,11 @@
         static ByteBuffer readClassFile(String name) {
             try {
                 File f = new File(System.getProperty("test.classes", "."),
-                                  name);
-                FileInputStream fin = new FileInputStream(f);
-                FileChannel fc = fin.getChannel();
-                return fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
+                                  "CLAZZ");
+                try (FileInputStream fin = new FileInputStream(f);
+                        FileChannel fc = fin.getChannel()) {
+                    return fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
+                }
             } catch (FileNotFoundException e) {
                 throw new RuntimeException("Can't open file: " + name, e);
             } catch (IOException e) {
@@ -101,12 +119,16 @@
                buffers. */
             buffers[MAPPED_BUFFER] = readClassFile(CLASS_NAME + ".class");
             byte[] array = new byte[buffers[MAPPED_BUFFER].limit()];
+            buffers[MAPPED_BUFFER].get(array);
+            buffers[MAPPED_BUFFER].flip();
 
             buffers[DIRECT_BUFFER] = ByteBuffer.allocateDirect(array.length);
             buffers[DIRECT_BUFFER].put(array);
+            buffers[DIRECT_BUFFER].flip();
 
             buffers[ARRAY_BUFFER] = ByteBuffer.allocate(array.length);
             buffers[ARRAY_BUFFER].put(array);
+            buffers[ARRAY_BUFFER].flip();
 
             buffers[WRAPPED_BUFFER] = ByteBuffer.wrap(array);
 
@@ -121,6 +143,7 @@
 
          public Class findClass(String name) {
              CodeSource cs = null;
+             count++;
              return defineClass(name, buffers[loaderType], cs);
          }
     } /* DummyClassLoader */
--- a/test/java/security/Security/ClassLoaderDeadlock/Deadlock2.sh	Thu Jun 30 14:16:48 2011 -0700
+++ b/test/java/security/Security/ClassLoaderDeadlock/Deadlock2.sh	Thu Jun 30 14:18:40 2011 -0700
@@ -1,7 +1,7 @@
 #!/bin/sh
 
 #
-# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 #
 # This code is free software; you can redistribute it and/or modify it
@@ -58,6 +58,10 @@
     PATHSEP=":"
     FILESEP="/"
     ;;
+  CYGWIN* )
+    PATHSEP=";"
+    FILESEP="/"
+    ;;
   Windows* )
     PATHSEP=";"
     FILESEP="\\"
--- a/test/java/security/Security/NoInstalledProviders.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/test/java/security/Security/NoInstalledProviders.java	Thu Jun 30 14:18:40 2011 -0700
@@ -23,7 +23,8 @@
 
 /*
  * @test
- * @bug 4273454 7052537
+ * @bug 4273454 7054918 7052537
+ * @library ../testlibrary
  * @summary Make sure getProviders(filter) doesn't throw NPE
  * @run main/othervm NoInstalledProviders
  */
@@ -32,7 +33,16 @@
 
 public class NoInstalledProviders {
 
-    public static void main(String[] argv) {
+    public static void main(String[] args) throws Exception {
+        ProvidersSnapshot snapshot = ProvidersSnapshot.create();
+        try {
+            main0(args);
+        } finally {
+            snapshot.restore();
+        }
+    }
+
+    public static void main0(String[] args) throws Exception {
 
         Provider[] provs = Security.getProviders();
         // make sure there are no providers in the system
--- a/test/java/security/Security/SynchronizedAccess.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/test/java/security/Security/SynchronizedAccess.java	Thu Jun 30 14:18:40 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,8 @@
 
 /*
  * @test
- * @bug 4162583
+ * @bug 4162583 7054918
+ * @library ../testlibrary
  * @summary Make sure Provider api implementations are synchronized properly
  */
 
@@ -31,7 +32,16 @@
 
 public class SynchronizedAccess {
 
-    public static void main(String[] args) {
+    public static void main(String[] args) throws Exception {
+        ProvidersSnapshot snapshot = ProvidersSnapshot.create();
+        try {
+            main0(args);
+        } finally {
+            snapshot.restore();
+        }
+    }
+
+    public static void main0(String[] args) throws Exception {
         AccessorThread[] acc = new AccessorThread[200];
         for (int i=0; i < acc.length; i++)
             acc[i] = new AccessorThread("thread"+i);
--- a/test/java/security/Security/removing/RemoveProviders.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/test/java/security/Security/removing/RemoveProviders.java	Thu Jun 30 14:18:40 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,8 @@
 
 /**
  * @test
- * @bug 4963416
+ * @bug 4963416 7054918
+ * @library ../../testlibrary
  * @summary make sure removeProvider() always works correctly
  * @author Andreas Sterbenz
  */
@@ -35,6 +36,15 @@
 public class RemoveProviders {
 
     public static void main(String[] args) throws Exception {
+        ProvidersSnapshot snapshot = ProvidersSnapshot.create();
+        try {
+            main0(args);
+        } finally {
+            snapshot.restore();
+        }
+    }
+
+    public static void main0(String[] args) throws Exception {
         Provider[] providers = Security.getProviders();
         System.out.println("Providers: " + Arrays.asList(providers));
 
--- a/test/java/security/UnresolvedPermission/Equals.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/test/java/security/UnresolvedPermission/Equals.java	Thu Jun 30 14:18:40 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,6 +24,7 @@
 /*
  * @test
  * @bug 4513737
+ * @run main/othervm Equals
  * @summary UnresolvedPermission.equals() throws NullPointerException
  */
 
--- a/test/java/security/spec/EllipticCurveMatch.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/test/java/security/spec/EllipticCurveMatch.java	Thu Jun 30 14:18:40 2011 -0700
@@ -25,13 +25,12 @@
  * @test
  * @bug 6738532
  * @summary Check EllipticCurve.equals() does not compare seed value of curve.
- * @run main/othervm EllipticCurveMatch
  * @author Mike StJohns
  */
 
 import java.security.spec.*;
 import java.math.BigInteger;
-import java.security.SecureRandom;
+import java.util.Random;
 
 public class EllipticCurveMatch {
     static String primeP256 =
@@ -45,7 +44,7 @@
 
     private static EllipticCurve addSeedToCurve(EllipticCurve curve)
     {
-        SecureRandom rand = new SecureRandom();
+        Random rand = new Random();
         byte[] seed = new byte[12];
         rand.nextBytes(seed);
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/security/testlibrary/ProvidersSnapshot.java	Thu Jun 30 14:18:40 2011 -0700
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.security.Provider;
+import java.security.Security;
+
+public class ProvidersSnapshot {
+
+    private Provider[] oldProviders;
+
+    private ProvidersSnapshot() {
+        oldProviders = Security.getProviders();
+    }
+
+    public static ProvidersSnapshot create() {
+        return new ProvidersSnapshot();
+    }
+
+    public void restore() {
+        Provider[] newProviders = Security.getProviders();
+        for (Provider p: newProviders) {
+            Security.removeProvider(p.getName());
+        }
+        for (Provider p: oldProviders) {
+            Security.addProvider(p);
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/util/logging/LoggerResourceBundleRace.java	Thu Jun 30 14:18:40 2011 -0700
@@ -0,0 +1,203 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug     7045594
+ * @summary ResourceBundle setting race in Logger.getLogger(name, rbName)
+ * @author  Daniel D. Daugherty
+ * @build RacingThreadsTest LoggerResourceBundleRace
+ * @run main LoggerResourceBundleRace
+ */
+
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.ListResourceBundle;
+import java.util.logging.Logger;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+
+public class LoggerResourceBundleRace extends RacingThreadsTest {
+    private final static int N_LOOPS   = 500000;   // # of race loops
+    private final static int N_SECS    = 15;       // # of secs to run test
+    // # of parallel threads; must match number of MyResources inner classes
+    private final static int N_THREADS = 3;
+
+    private final static String LOGGER_PREFIX = "myLogger-";
+    private final static String RESOURCE_PREFIX
+        = "LoggerResourceBundleRace$MyResources";
+    // these counters are AtomicInteger since any worker thread can increment
+    private final static AtomicInteger iaeCnt = new AtomicInteger();
+    private final static AtomicInteger worksCnt = new AtomicInteger();
+
+    Logger dummy;   // dummy Logger
+
+    LoggerResourceBundleRace(String name, int n_threads, int n_loops,
+        int n_secs) {
+        super(name, n_threads, n_loops, n_secs);
+    }
+
+
+    // Main test driver
+    //
+    public static void main(String[] args) {
+        LoggerResourceBundleRace test
+            = new LoggerResourceBundleRace("LoggerResourceBundleRace",
+                                           N_THREADS, N_LOOPS, N_SECS);
+        test.setVerbose(
+            Boolean.getBoolean("LoggerResourceBundleRace.verbose"));
+
+        DriverThread driver = new DriverThread(test);
+        MyWorkerThread[] workers = new MyWorkerThread[N_THREADS];
+        for (int i = 0; i < workers.length; i++) {
+            workers[i] = new MyWorkerThread(i, test);
+        }
+        test.runTest(driver, workers);
+    }
+
+    public void oneTimeDriverInit(DriverThread dt) {
+        super.oneTimeDriverInit(dt);
+        dummy = null;
+    }
+
+    public void perRaceDriverInit(DriverThread dt) {
+        super.perRaceDriverInit(dt);
+
+        // - allocate a new dummy Logger without a ResourceBundle;
+        //   this gives the racing threads less to do
+        // - reset the counters
+        dummy = Logger.getLogger(LOGGER_PREFIX + getLoopCnt());
+        iaeCnt.set(0);
+        worksCnt.set(0);
+    }
+
+    public void executeRace(WorkerThread wt) {
+        super.executeRace(wt);
+
+        Logger myLogger = null;
+        try {
+            MyWorkerThread mwt = (MyWorkerThread) wt;  // short hand
+
+            // Here is the race:
+            // - the target Logger object has already been created by
+            //   the DriverThread without a ResourceBundle name
+            // - in parallel, each WorkerThread calls Logger.getLogger()
+            //   with a different ResourceBundle name
+            // - Logger.getLogger() should only successfully set the
+            //   ResourceBundle name for one WorkerThread; all other
+            //   WorkerThread calls to Logger.getLogger() should throw
+            //   IllegalArgumentException
+            myLogger = Logger.getLogger(LOGGER_PREFIX + getLoopCnt(),
+                                        mwt.rbName);
+            if (myLogger.getResourceBundleName().equals(mwt.rbName)) {
+                // no exception and the ResourceBundle names match
+                worksCnt.incrementAndGet();  // ignore return
+            } else {
+                System.err.println(wt.getName()
+                    + ": ERROR: expected ResourceBundleName '"
+                    + mwt.rbName + "' does not match actual '"
+                    + myLogger.getResourceBundleName() + "'");
+                incAndGetFailCnt();  // ignore return
+            }
+        } catch (IllegalArgumentException iae) {
+            iaeCnt.incrementAndGet();  // ignore return
+        } catch (MissingResourceException mre) {
+            // This exception happens when N_THREADS above does not
+            // match the number of MyResources inner classes below.
+            // We exit since this is a coding error.
+            unexpectedException(wt, mre);
+            System.exit(2);
+        }
+    }
+
+    public void checkRaceResults(DriverThread dt) {
+        super.checkRaceResults(dt);
+
+        if (worksCnt.get() != 1) {
+            System.err.println(dt.getName() + ": ERROR: worksCnt should be 1"
+                + ": loopCnt=" + getLoopCnt() + ", worksCnt=" + worksCnt.get());
+            incAndGetFailCnt();  // ignore return
+        } else if (iaeCnt.get() != N_THREADS - 1) {
+            System.err.println(dt.getName() + ": ERROR: iaeCnt should be "
+                + (N_THREADS - 1) + ": loopCnt=" + getLoopCnt()
+                + ", iaeCnt=" + iaeCnt.get());
+            incAndGetFailCnt();  // ignore return
+        }
+    }
+
+    public void oneTimeDriverEpilog(DriverThread dt) {
+        super.oneTimeDriverEpilog(dt);
+
+        // Use the dummy Logger after the testing loop to make sure that
+        // dummy doesn't get optimized away in the testing loop.
+        dummy.info("This is a test message.");
+    }
+
+    // N_THREADS above must match number of MyResources inner classes
+    //
+    public static class MyResources0 extends ListResourceBundle {
+        final static Object[][] contents = {
+            {"sample1", "translation #1 for sample1"},
+            {"sample2", "translation #1 for sample2"},
+        };
+
+        public Object[][] getContents() {
+            return contents;
+        }
+    }
+
+    public static class MyResources1 extends ListResourceBundle {
+        final static Object[][] contents = {
+            {"sample1", "translation #2 for sample1"},
+            {"sample2", "translation #2 for sample2"},
+        };
+
+        public Object[][] getContents() {
+            return contents;
+        }
+    }
+
+    public static class MyResources2 extends ListResourceBundle {
+        final static Object[][] contents = {
+            {"sample1", "translation #3 for sample1"},
+            {"sample2", "translation #3 for sample2"},
+        };
+
+        public Object[][] getContents() {
+            return contents;
+        }
+    }
+
+
+    // WorkerThread with a thread specific ResourceBundle name
+    //
+    public static class MyWorkerThread extends WorkerThread {
+        public final String rbName;  // ResourceBundle name
+
+        MyWorkerThread(int workerNum, RacingThreadsTest test) {
+            super(workerNum, test);
+
+            rbName = RESOURCE_PREFIX + workerNum;
+        }
+    }
+}
--- a/test/java/util/logging/LoggingDeadlock3.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/test/java/util/logging/LoggingDeadlock3.java	Thu Jun 30 14:18:40 2011 -0700
@@ -27,7 +27,7 @@
  * @summary Calling LogManager.addLogger() and Logger.getLogger() cause deadlock
  * @author  Serguei Spitsyn
  * @build LoggingDeadlock3
- * @run main/timeout=15 LoggingDeadlock3
+ * @run main/timeout=80 LoggingDeadlock3
  */
 
 import java.io.*;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/util/logging/RacingThreadsTest.java	Thu Jun 30 14:18:40 2011 -0700
@@ -0,0 +1,687 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.BrokenBarrierException;
+import java.util.concurrent.CyclicBarrier;
+
+
+/**
+ * RacingThreadsTest is a support class for creating a test
+ * where multiple threads are needed to exercise a code path.
+ * The RacingThreadsTest class is typically used as follows:
+ * <ul>
+ * <li>
+ *     Extend RacingThreadsTest class in order to provide the test
+ *     specific variables and/or code, e.g., <br>
+ *     public class MyRacingThreadsTest extends RacingThreadsTest
+ * <li>
+ *     Use
+ *     "new MyRacingThreadsTest(name, n_threads, n_loops, n_secs)"
+ *     to create your test with the specified name and the specified
+ *     number of WorkerThreads that execute the test code in parallel
+ *     up to n_loops iterations or n_secs seconds.
+ * <li>
+ *     Use
+ *     "new DriverThread(test)"
+ *     to create the test DriverThread that manages all the
+ *     WorkerThreads. The DriverThread class can be extended to
+ *     provide test specific code and/or variables. However, that
+ *     is typically done in your test's subclass.
+ * <li>
+ *     Use
+ *     "new WorkerThread(workerNum, test)"
+ *     to create WorkerThread-workerNum that executes the test code.
+ *     The WorkerThread class can be extended to provide test thread
+ *     specific code and/or variables.
+ * <li>
+ *     Use
+ *     "RacingThreadsTest.runTest(driver, workers)"
+ *     to run the test. If the test fails, then a RuntimeException
+ *     is thrown.
+ * </ul>
+ *
+ * The RacingThreadsTest class provides many methods that can be
+ * overridden in order to provide test specific semantics at each
+ * identified test execution point. At a minimum, your test's
+ * subclass needs to override the
+ * "void executeRace(WorkerThread)"
+ * method in order to exercise your race condition and it needs to
+ * override the
+ * "void checkRaceResults(DriverThread)"
+ * method in order to check the results of the race. Your
+ * checkRaceResults() method should call the
+ * "int incAndGetFailCnt()"
+ * method when it detects a failure. It can also call the
+ * "void unexpectedException(Thread, Exception)"
+ * method if it detects an unexpected exception; this will cause
+ * an error message to be output and the failure count to be
+ * incremented. When the RacingThreadsTest.runTest() method is
+ * done running the races, if there is a non-zero failure count,
+ * then a RuntimeException will be thrown.
+ * <p>
+ * The RacingThreadsTest class uses three internal barriers to
+ * coordinate actions between the DriverThread and the WorkerThreads.
+ * These barriers should not be managed or used by your test's
+ * subclass and are only mentioned here to provide clarity about
+ * interactions between the DriverThread and the WorkerThreads.
+ * The following transaction diagram shows when the different
+ * RacingThreadsTest methods are called relative to the different
+ * barriers:
+ *
+ * <pre>
+ * DriverThread           WorkerThread-0         WorkerThread-N-1
+ * ---------------------  ---------------------  ---------------------
+ * run(workers)
+ * oneTimeDriverInit()
+ * &lt;start WorkerThreads&gt;  run()                  run()
+ * &lt;top of race loop&gt;     :                      :
+ * perRaceDriverInit()    oneTimeWorkerInit()    oneTimeWorkerInit()
+ * :                      &lt;top of race loop&gt;     &lt;top of race loop&gt;
+ * :                      perRaceWorkerInit()    perRaceWorkerInit()
+ * startBarrier           startBarrier           startBarrier
+ * :                      executeRace()          executeRace()
+ * finishBarrier          finishBarrier          finishBarrier
+ * checkRaceResults()     :                      :
+ * resetBarrier           resetBarrier           resetBarrier
+ * perRaceDriverEpilog()  perRaceWorkerEpilog()  perRaceWorkerEpilog()
+ * &lt;repeat race or done&gt;  &lt;repeat race or done&gt;  &lt;repeat race or done&gt;
+ * :                      oneTimeWorkerEpilog()  oneTimeWorkerEpilog()
+ * &lt;join WorkerThreads&gt;   &lt;WorkerThread ends&gt;    &lt;WorkerThread ends&gt;
+ * oneTimeDriverEpilog()
+ * &lt;DriverThread ends&gt;
+ * </pre>
+ *
+ * Just to be clear about the parallel parts of this infrastructure:
+ * <ul>
+ * <li>
+ *     After the DriverThread starts the WorkerThreads, the DriverThread
+ *     and the WorkerThreads are running in parallel until the startBarrier
+ *     is reached.
+ * <li>
+ *     After the WorkerThreads leave the startBarrier, they are running
+ *     the code in executeRace() in parallel which is the whole point
+ *     of this class.
+ * <li>
+ *     The DriverThread heads straight to the finishBarrier and waits for
+ *     the WorkerThreads to get there.
+ * <li>
+ *     After the DriverThread leaves the finishBarrier, it checks the
+ *     results of the race.
+ * <li>
+ *     The WorkerThreads head straight to the resetBarrier and wait for
+ *     the DriverThread to get there.
+ * <li>
+ *     If this is not the last race, then after the DriverThread and
+ *     WorkerThreads leave the resetBarrier, the DriverThread and the
+ *     WorkerThreads are running in parallel until the startBarrier
+ *     is reached.
+ * <li>
+ *     If this is the last race, then after the DriverThread and
+ *     WorkerThreads leave the resetBarrier, the DriverThread and the
+ *     WorkerThreads are running in parallel as each WorkerThread ends.
+ * <li>
+ *     The DriverThread waits for the WorkerThreads to end and
+ *     then it ends
+ * </ul>
+ *
+ * Once the DriverThread has ended, the RacingThreadsTest.runTest()
+ * method checks the failure count. If there were no failures, then
+ * a "Test PASSed" message is printed. Otherwise, the failure count
+ * is printed, a "Test FAILed" message is printed and a RuntimeException
+ * is thrown.
+ */
+public class RacingThreadsTest {
+    /**
+     * name of the test
+     */
+    public final String TEST_NAME;
+    /**
+     * maximum number of test iterations (race loops)
+     */
+    public final int N_LOOPS;
+    /**
+     * the maximum number of seconds to execute the test loop
+     */
+    public final int N_SECS;
+    /**
+     * number of WorkerThreads
+     */
+    public final int N_THREADS;
+
+    /**
+     * Creates a test with the specified name and the specified number
+     * of WorkerThreads that execute the test code in parallel up to
+     * n_loops iterations or n_secs seconds. The RacingThreadsTest
+     * class is extended in order to provide the test specific variables
+     * and/or code.
+     * @param name the name of the test
+     * @param n_threads the number of WorkerThreads
+     * @param n_loops the maximum number of test iterations
+     * @param n_secs the maximum number of seconds to execute the test loop
+     */
+    RacingThreadsTest(String name, int n_threads, int n_loops, int n_secs) {
+        TEST_NAME = name;
+        N_THREADS = n_threads;
+        N_LOOPS = n_loops;
+        N_SECS = n_secs;
+
+        finishBarrier = new CyclicBarrier(N_THREADS + 1);
+        resetBarrier = new CyclicBarrier(N_THREADS + 1);
+        startBarrier = new CyclicBarrier(N_THREADS + 1);
+    }
+
+
+    /**
+     * Entry point for exercising the RacingThreadsTest class.
+     */
+    public static void main(String[] args) {
+        // a dummy test:
+        // - 2 threads
+        // - 3 loops
+        // - 2 seconds
+        // - standard DriverThread
+        // - standard WorkerThread
+        RacingThreadsTest test = new RacingThreadsTest("dummy", 2, 3, 2);
+        DriverThread driver = new DriverThread(test);
+        WorkerThread[] workers = new WorkerThread[2];
+        for (int i = 0; i < workers.length; i++) {
+            workers[i] = new WorkerThread(i, test);
+        }
+        test.runTest(driver, workers);
+    }
+
+    private static volatile boolean done = false;  // test done flag
+
+    // # of fails; AtomicInteger since any WorkerThread can increment
+    private static final AtomicInteger failCnt = new AtomicInteger();
+    // # of loops; volatile is OK since only DriverThread increments
+    // but using AtomicInteger for consistency
+    private static final AtomicInteger loopCnt = new AtomicInteger();
+    private static boolean verbose
+        = Boolean.getBoolean("RacingThreadsTest.verbose");
+
+    // barriers for starting, finishing and resetting the race
+    private final CyclicBarrier finishBarrier;
+    private final CyclicBarrier resetBarrier;
+    private final CyclicBarrier startBarrier;
+
+
+    /**
+     * Get current done flag value.
+     * @return the current done flag value
+     */
+    public boolean getDone() {
+        return done;
+    }
+
+    /**
+     * Set done flag to specified value.
+     * @param v the new done flag value
+     */
+    public void setDone(boolean v) {
+        done = v;
+    }
+
+    /**
+     * Get current failure counter value.
+     * @return the current failure count
+     */
+    public int getFailCnt() {
+        return failCnt.get();
+    }
+
+    /**
+     * Increment and get current failure counter value.
+     * @return the current failure count after incrementing
+     */
+    public int incAndGetFailCnt() {
+        return failCnt.incrementAndGet();
+    }
+
+    /**
+     * Get current loop counter value.
+     * @return the current loop count
+     */
+    public int getLoopCnt() {
+        return loopCnt.get();
+    }
+
+    /**
+     * Increment and get current loop counter value.
+     * @return the current loop count after incrementing
+     */
+    public int incAndGetLoopCnt() {
+        return loopCnt.incrementAndGet();
+    }
+
+    /**
+     * Get current verbose flag value.
+     * @return the current verbose flag value
+     */
+    public boolean getVerbose() {
+        return verbose;
+    }
+
+    /**
+     * Set verbose flag to specified value.
+     * @param v the new verbose flag value
+     */
+    public void setVerbose(boolean v) {
+        verbose = v;
+    }
+
+    /**
+     * Run the test with the specified DriverThread and the
+     * specified WorkerThreads.
+     * @param driver the DriverThread for running the test
+     * @param workers the WorkerThreads for executing the race
+     * @exception RuntimeException the test has failed
+     */
+    public void runTest(DriverThread driver, WorkerThread[] workers) {
+        driver.run(workers);
+
+        try {
+            driver.join();
+        } catch (InterruptedException ie) {
+            unexpectedException(Thread.currentThread(), ie);
+            // fall through to test failed below
+        }
+
+        if (failCnt.get() == 0) {
+            System.out.println(TEST_NAME + ": Test PASSed.");
+        } else {
+            System.out.println(TEST_NAME + ": failCnt=" + failCnt.get());
+            System.out.println(TEST_NAME + ": Test FAILed.");
+            throw new RuntimeException("Test Failed");
+        }
+    }
+
+    /**
+     * Helper method for reporting an unexpected Exception and
+     * calling incAndGetFailCnt();
+     * @param t the Thread that caught the exception
+     * @param e the Exception that was caught
+     */
+    public void unexpectedException(Thread t, Exception e) {
+        System.err.println(t.getName() + ": ERROR: unexpected exception: " + e);
+        incAndGetFailCnt();  // ignore return
+    }
+
+
+    // The following methods are typically overridden by the subclass
+    // of RacingThreadsTest to provide test specific semantics at each
+    // identified test execution point:
+
+    /**
+     * Initialize 1-time items for the DriverThread.
+     * Called by the DriverThread before WorkerThreads are started.
+     * @param dt the DriverThread
+     */
+    public void oneTimeDriverInit(DriverThread dt) {
+        if (verbose)
+            System.out.println(dt.getName() + ": oneTimeDriverInit() called");
+    }
+
+    /**
+     * Initialize 1-time items for a WorkerThread. Called by a
+     * WorkerThread after oneTimeDriverInit() and before the
+     * WorkerThread checks in with startBarrier. May execute in
+     * parallel with perRaceDriverInit() or with another
+     * WorkerThread's oneTimeWorkerInit() call or another
+     * WorkerThread's perRaceWorkerInit() call.
+     * @param wt the WorkerThread
+     */
+    public void oneTimeWorkerInit(WorkerThread wt) {
+        if (verbose)
+            System.out.println(wt.getName() + ": oneTimeWorkerInit() called");
+    }
+
+    /**
+     * Initialize per-race items for the DriverThread. Called by the
+     * DriverThread before it checks in with startBarrier. May execute
+     * in parallel with oneTimeWorkerInit() and perRaceWorkerInit()
+     * calls. After any race except for the last race, this method may
+     * execute in parallel with perRaceWorkerEpilog().
+     * @param dt the DriverThread
+     */
+    public void perRaceDriverInit(DriverThread dt) {
+        if (verbose)
+            System.out.println(dt.getName() + ": perRaceDriverInit() called");
+    }
+
+    /**
+     * Initialize per-race items for a WorkerThread. Called by each
+     * WorkerThread before it checks in with startBarrier. On the first
+     * call, this method may execute in parallel with another
+     * WorkerThread's oneTimeWorkerInit() call. On any call, this method
+     * may execute in parallel with perRaceDriverInit() or another
+     * WorkerThread's perRaceWorkerInit() call. After any race except
+     * for the last race, this method may execute in parallel with
+     * perRaceDriverEpilog() or another WorkerThread's
+     * perRaceWorkerEpilog() call.
+     * @param wt the WorkerThread
+     */
+    public void perRaceWorkerInit(WorkerThread wt) {
+        if (verbose)
+            System.out.println(wt.getName() + ": perRaceWorkerInit() called");
+    }
+
+    /**
+     * Execute the race in a WorkerThread. Called by each WorkerThread
+     * after it has been released from startBarrier.
+     * @param wt the WorkerThread
+     */
+    public void executeRace(WorkerThread wt) {
+        if (verbose)
+            System.out.println(wt.getName() + ": executeRace() called");
+    }
+
+    /**
+     * Check race results in the DriverThread. Called by the DriverThread
+     * after it has been released from finishBarrier and before the
+     * DriverThread checks in with resetBarrier.
+     * @param dt the DriverThread
+     */
+    public void checkRaceResults(DriverThread dt) {
+        if (verbose)
+            System.out.println(dt.getName() + ": checkRaceResults() called");
+    }
+
+    /**
+     * Handle end-of-race items for the DriverThread. Called by the
+     * DriverThread after it has been released from resetBarrier and
+     * before the DriverThread checks in again with startBarrier. Can
+     * execute in parallel with perRaceWorkerEpilog(). If this is not
+     * the last race, can execute in parallel with perRaceWorkerInit().
+     * If this is the last race, can execute in parallel with
+     * oneTimeWorkerEpilog().
+     * @param dt the DriverThread
+     */
+    public void perRaceDriverEpilog(DriverThread dt) {
+        if (verbose)
+            System.out.println(dt.getName() + ": perRaceDriverEpilog() called");
+    }
+
+    /**
+     * Handle end-of-race items for a WorkerThread. Called by each
+     * WorkerThread after it has been released from resetBarrier and
+     * before the WorkerThread checks in again with startBarrier.
+     * Can execute in parallel with perRaceDriverEpilog() or another
+     * WorkerThread's perRaceWorkerEpilog() call. If this is not the
+     * last race, can execute in parallel with perRaceDriverInit(),
+     * or another WorkerThread's perRaceWorkerInit() call. If this
+     * is the last race, can execute in parallel with another
+     * WorkerThread's oneTimeWorkerEpilog() call.
+     * @param wt the WorkerThread
+     */
+    public void perRaceWorkerEpilog(WorkerThread wt) {
+        if (verbose)
+            System.out.println(wt.getName() + ": perRaceWorkerEpilog() called");
+    }
+
+    /**
+     * Handle end-of-test items for a WorkerThread. Called by each
+     * WorkerThread after it has detected that all races are done and
+     * before oneTimeDriverEpilog() is called. Can execute in parallel
+     * with perRaceDriverEpilog(), with another WorkerThread's
+     * perRaceWorkerEpilog() call or with another WorkerThread's
+     * oneTimeWorkerEpilog() call.
+     * @param wt the WorkerThread
+     */
+    public void oneTimeWorkerEpilog(WorkerThread wt) {
+        if (verbose)
+            System.out.println(wt.getName() + ": oneTimeWorkerEpilog() called");
+    }
+
+    /**
+     * Handle end-of-test items for the DriverThread. Called by the
+     * DriverThread after all the WorkerThreads have called
+     * oneTimeWorkerEpilog().
+     * @param dt the DriverThread
+     */
+    public void oneTimeDriverEpilog(DriverThread dt) {
+        if (verbose)
+            System.out.println(dt.getName() + ": oneTimeDriverEpilog() called");
+    }
+
+
+    /**
+     * DriverThread for executing the test.
+     */
+    public static class DriverThread extends Thread {
+        private final RacingThreadsTest test;
+
+        /**
+         * Create the test DriverThread that manages all the WorkerThreads.
+         * The DriverThread class can be extended to provide test specific
+         * variables and/or code. However, that is typically done in the
+         * subclass of RacingThreadsTest.
+         * @parameter test the RacingThreadsTest being run
+         */
+        DriverThread(RacingThreadsTest test) {
+            super("DriverThread");
+            this.test = test;
+        }
+
+        private void run(WorkerThread[] workers) {
+            System.out.println(getName() + ": is starting.");
+            System.out.println(getName() + ": # WorkerThreads: " + test.N_THREADS);
+            System.out.println(getName() + ": max # loops: " + test.N_LOOPS);
+            System.out.println(getName() + ": max # secs: " + test.N_SECS);
+
+            // initialize 1-time items for the DriverThread
+            test.oneTimeDriverInit(this);
+
+            // start all the threads
+            for (int i = 0; i < workers.length; i++) {
+                workers[i].start();
+            }
+
+            // All WorkerThreads call oneTimeWorkerInit() and
+            // perRaceWorkerInit() on the way to startBarrier.
+
+            long endTime = System.currentTimeMillis() + test.N_SECS * 1000;
+
+            for (; !test.getDone() && test.getLoopCnt() < test.N_LOOPS;
+                test.incAndGetLoopCnt()) {
+
+                if (test.getVerbose() && (test.N_LOOPS < 10 ||
+                    (test.getLoopCnt() % (test.N_LOOPS / 10)) == 0)) {
+                    System.out.println(getName() + ": race loop #"
+                        + test.getLoopCnt());
+                }
+
+                // initialize per-race items for the DriverThread
+                test.perRaceDriverInit(this);
+
+                try {
+                    // we've setup the race so start it when all
+                    // WorkerThreads get to the startBarrier
+                    test.startBarrier.await();
+                } catch (BrokenBarrierException bbe) {
+                    test.unexpectedException(this, bbe);
+                    return;
+                } catch (InterruptedException ie) {
+                    test.unexpectedException(this, ie);
+                    return;
+                }
+
+                // All WorkerThreads are racing via executeRace()
+                // at this point
+
+                // wait for all threads to finish the race
+                try {
+                    test.finishBarrier.await();
+                } catch (BrokenBarrierException bbe) {
+                    test.unexpectedException(this, bbe);
+                    return;
+                } catch (InterruptedException ie) {
+                    test.unexpectedException(this, ie);
+                    return;
+                }
+                // All WorkerThreads are heading to resetBarrier at this
+                // point so we can check the race results before we reset
+                // for another race (or bail because we are done).
+
+                test.checkRaceResults(this);
+
+                if (test.getLoopCnt() + 1 >= test.N_LOOPS ||
+                    System.currentTimeMillis() >= endTime) {
+                    // This is the last loop or we're out of time.
+                    // Let test threads know we are done before we release
+                    // them from resetBarrier
+                    test.setDone(true);
+                }
+
+                // release the WorkerThreads from resetBarrier
+                try {
+                    test.resetBarrier.await();
+                } catch (BrokenBarrierException bbe) {
+                    test.unexpectedException(this, bbe);
+                    return;
+                } catch (InterruptedException ie) {
+                    test.unexpectedException(this, ie);
+                    return;
+                }
+
+                // All WorkerThreads call perRaceWorkerEpilog(). If
+                // this is not the last loop, then all WorkerThreads
+                // will also call perRaceWorkerInit() on the way to
+                // startBarrier. If this is the last loop, then all
+                // WorkerThreads will call oneTimeWorkerEpilog() on
+                // their way to ending.
+
+                // handle end-of-race items for the DriverThread
+                test.perRaceDriverEpilog(this);
+            }
+
+            System.out.println(getName() + ": completed " + test.getLoopCnt()
+                + " race loops.");
+            if (test.getLoopCnt() < test.N_LOOPS) {
+                System.out.println(getName() + ": race stopped @ " + test.N_SECS
+                    + " seconds.");
+            }
+
+            for (int i = 0; i < workers.length; i++) {
+                try {
+                    workers[i].join();
+                } catch (InterruptedException ie) {
+                    test.unexpectedException(this, ie);
+                    return;
+                }
+            }
+
+            // handle end-of-test items for the DriverThread
+            test.oneTimeDriverEpilog(this);
+
+            System.out.println(getName() + ": is done.");
+        }
+    }
+
+
+    /**
+     * WorkerThread for executing the race.
+     */
+    public static class WorkerThread extends Thread {
+        private final RacingThreadsTest test;
+        private final int workerNum;
+
+        /**
+         * Creates WorkerThread-N that executes the test code. The
+         * WorkerThread class can be extended to provide test thread
+         * specific variables and/or code.
+         * @param workerNum the number for the new WorkerThread
+         * @parameter test the RacingThreadsTest being run
+         */
+        WorkerThread(int workerNum, RacingThreadsTest test) {
+            super("WorkerThread-" + workerNum);
+            this.test = test;
+            this.workerNum = workerNum;
+        }
+
+        /**
+         * get the WorkerThread's number
+         * @return the WorkerThread's number
+         */
+        public int getWorkerNum() {
+            return workerNum;
+        }
+
+        /**
+         * Run the race in a WorkerThread.
+         */
+        public void run() {
+            System.out.println(getName() + ": is running.");
+
+            // initialize 1-time items for the WorkerThread
+            test.oneTimeWorkerInit(this);
+
+            while (!test.getDone()) {
+                // initialize per-race items for the WorkerThread
+                test.perRaceWorkerInit(this);
+
+                try {
+                    test.startBarrier.await();  // wait for race to start
+                } catch (BrokenBarrierException bbe) {
+                    test.unexpectedException(this, bbe);
+                    return;
+                } catch (InterruptedException ie) {
+                    test.unexpectedException(this, ie);
+                    return;
+                }
+
+                // execute the race for the WorkerThread
+                test.executeRace(this);
+
+                try {
+                    test.finishBarrier.await();  // this thread is done
+                } catch (BrokenBarrierException bbe) {
+                    test.unexpectedException(this, bbe);
+                    return;
+                } catch (InterruptedException ie) {
+                    test.unexpectedException(this, ie);
+                    return;
+                }
+
+                try {
+                    test.resetBarrier.await();  // wait for race to reset
+                } catch (BrokenBarrierException bbe) {
+                    test.unexpectedException(this, bbe);
+                    return;
+                } catch (InterruptedException ie) {
+                    test.unexpectedException(this, ie);
+                    return;
+                }
+
+               // handle end-of-race items for the WorkerThread
+                test.perRaceWorkerEpilog(this);
+            }
+
+            // handle end-of-test items for the WorkerThread
+            test.oneTimeWorkerEpilog(this);
+
+            System.out.println(getName() + ": is ending.");
+        }
+    }
+}
--- a/test/javax/crypto/EncryptedPrivateKeyInfo/GetKeySpecException.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/test/javax/crypto/EncryptedPrivateKeyInfo/GetKeySpecException.java	Thu Jun 30 14:18:40 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,8 @@
 
 /**
  * @test
- * @bug 4508341
+ * @bug 4508341 7055362
+ * @library ../../../java/security/testlibrary
  * @summary Test the error conditions of
  * EncryptedPrivateKeyInfo.getKeySpec(...) methods.
  * @author Valerie Peng
@@ -97,7 +98,16 @@
         }
     }
 
-    public static void main(String[] argv) throws Exception {
+    public static void main(String[] args) throws Exception {
+        ProvidersSnapshot snapshot = ProvidersSnapshot.create();
+        try {
+            main0(args);
+        } finally {
+            snapshot.restore();
+        }
+    }
+
+    public static void main0(String[] args) throws Exception {
         if ((GOOD_PARAMS == null) || (BAD_PARAMS == null)) {
             throw new Exception("Static parameter generation failed");
         }
--- a/test/javax/crypto/JceSecurity/SunJCE_BC_LoadOrdering.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/test/javax/crypto/JceSecurity/SunJCE_BC_LoadOrdering.java	Thu Jun 30 14:18:40 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006, 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,8 @@
 
 /*
  * @test
- * @bug 6377058
+ * @bug 6377058 7055362
+ * @library ../../../java/security/testlibrary
  * @summary SunJCE depends on sun.security.provider.SignatureImpl
  * behaviour, BC can't load into 1st slot.
  * @author Brad R. Wetmore
@@ -35,7 +36,16 @@
 
 public class SunJCE_BC_LoadOrdering {
 
-    public static void main(String args[]) throws Exception {
+    public static void main(String[] args) throws Exception {
+        ProvidersSnapshot snapshot = ProvidersSnapshot.create();
+        try {
+            main0(args);
+        } finally {
+            snapshot.restore();
+        }
+    }
+
+    public static void main0(String[] args) throws Exception {
         /*
          * Generate a random key, and encrypt the data
          */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/sun/security/krb5/tools/ktmissing.sh	Thu Jun 30 14:18:40 2011 -0700
@@ -0,0 +1,51 @@
+#
+# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+# @test
+# @bug 7043737
+# @summary klist does not detect non-existing keytab
+# @run shell ktmissing.sh
+#
+
+OS=`uname -s`
+case "$OS" in
+  CYGWIN* )
+    FS="/"
+    ;;
+  Windows_* )
+    FS="\\"
+    ;;
+  * )
+    FS="/"
+    echo "Unsupported system!"
+    exit 0;
+    ;;
+esac
+
+${TESTJAVA}${FS}bin${FS}klist -k this_file_does_not_exist && exit 1
+
+echo ABC > this_is_not_a_keytab
+
+${TESTJAVA}${FS}bin${FS}klist -k this_is_not_a_keytab && exit 2
+
+exit 0
--- a/test/sun/security/pkcs11/fips/ClientJSSEServerJSSE.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/test/sun/security/pkcs11/fips/ClientJSSEServerJSSE.java	Thu Jun 30 14:18:40 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,10 +25,10 @@
  * @test
  * @bug 6313675 6323647
  * @summary Verify that all ciphersuites work in FIPS mode
+ * @library ..
  * @ignore JSSE supported cipher suites are changed with CR 6916074,
  *     need to update this test case in JDK 7 soon
  * @author Andreas Sterbenz
- * @library ..
  */
 
 import java.security.*;
--- a/test/sun/security/ssl/com/sun/net/ssl/internal/ssl/InputRecord/InterruptedIO.java	Thu Jun 30 14:16:48 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,183 +0,0 @@
-/*
- * Copyright (c) 2001, 2003, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/*
- * @test
- * @bug 4393337
- * @summary [TEST RUNS ON SOLARIS ONLY] Throw an InterruptedIOException
- * when read on SSLSocket is * interrupted.
- */
-
-import java.io.InputStream;
-import java.io.IOException;
-import java.io.InterruptedIOException;
-import java.net.Socket;
-import javax.net.ssl.*;
-
-/**
- * Interrupts an SSL socket that is blocked on a read. An
- * InterruptedIOException will be thrown and handled within the test if the
- * test completes correctly.
- */
-
-public class InterruptedIO {
-
-    /**
-     * Starts a client and a server thread. Gives the client enough time to
-     * block in a read, then interrupts it.
-     */
-    public static void main(String[] args) throws Exception {
-
-        String reason =
-            "Test valid only on SunOS.\n" +
-            "=========================\n" +
-            "It was determined that Thread.interrupt() could \n" +
-            "not be reliably return InterruptedIOException \n" +
-            "on non-Solaris implementations.  Thread.interrupt() \n" +
-            "API was updated in merlin (JDK 1.4) to reflect this.\n";
-        System.out.println(reason);
-
-        String osName = System.getProperty("os.name", "");
-        if (!osName.equalsIgnoreCase("SunOS")) {
-            System.out.println("Ignoring test on '" + osName + "'");
-            return;
-        }
-
-        String testRoot = System.getProperty("test.src", ".");
-        System.setProperty("javax.net.ssl.keyStore",
-                           testRoot +
-                           "/../../../../../../../etc/keystore");
-        System.setProperty("javax.net.ssl.keyStorePassword",
-                           "passphrase");
-        System.setProperty("javax.net.ssl.trustStore",
-                           testRoot +
-                           "/../../../../../../../etc/truststore");
-
-        Server server = new Server();
-        server.start();
-
-        Client client = new Client(server.getPort()); // Will do handshake
-        client.start(); // Will block in read
-
-        // sleep for 5 seconds
-        System.out.println("Main - Pausing for 5 seconds...");
-        Thread.sleep(5 * 1000);
-
-        System.out.println("Main - Interrupting client reader thread");
-        client.interrupt();
-        client.join(); // Wait for client thread to complete
-
-        if (client.failed())
-            throw new Exception("Main - Test InterruptedIO failed "
-                                + "on client side.");
-        else
-            System.out.println("Main - Test InterruptedIO successful!");
-    }
-
-    /**
-     * Accepts an incoming SSL Connection. Then blocks in a read.
-     */
-    static class Server extends Thread {
-
-        private SSLServerSocket ss;
-
-        public Server() throws Exception {
-            ss = (SSLServerSocket) SSLServerSocketFactory.getDefault().
-                createServerSocket(0);
-        }
-
-        public int getPort() {
-            return ss.getLocalPort();
-        }
-
-        public void run() {
-            try {
-                System.out.println("Server - Will accept connections on port "
-                                   + getPort());
-                Socket s = ss.accept();
-                InputStream is = s.getInputStream();
-                // We want the client to block so deadlock
-                is.read();
-            } catch (IOException e) {
-                // Happens when client closese connection.
-                // If an error occurs, Client will detect problem
-            }
-        }
-    }
-
-    /**
-     * Initiates an SSL connection to a server. Then blocks in a read. It
-     * should be interrupted by another thread. An InterruptedIOException
-     * is expected to be thrown.
-     */
-    static class Client extends Thread {
-
-        private SSLSocket socket;
-        private InputStream inStream;
-        private boolean failed = false;
-
-        public Client(int port) throws Exception {
-            socket = (SSLSocket) SSLSocketFactory.getDefault().
-                createSocket("localhost", port);
-            inStream = socket.getInputStream();
-            System.out.println("Client - "
-                               + "Connected to: localhost" + ":" + port);
-            System.out.println("Client - "
-                               + "Doing SSL Handshake...");
-            socket.startHandshake(); // Asynchronous call
-            System.out.println("Client - Done with SSL Handshake");
-        }
-
-        public void run() {
-
-            try {
-                System.out.println("Client - Reading from input stream ...");
-                if (inStream.read() == -1) {
-                    System.out.println("Client - End-of-stream detected");
-                    failed = true;
-                }
-            } catch (InterruptedIOException e) {
-                System.out.println("Client - "
-                                   + "As expected, InterruptedIOException "
-                                   + "was thrown. Message: "
-                                   + e.getMessage());
-            } catch (Exception e) {
-                System.out.println("Client - Unexpected exception:");
-                e.printStackTrace();
-                failed = true;
-            } finally {
-                try {
-                    socket.close();
-                } catch (IOException e) {
-                    // Squelch it
-                }
-            }
-        }
-
-        public boolean failed() {
-            return failed;
-        }
-
-    }
-
-}
--- a/test/tools/launcher/ExecutionEnvironment.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/test/tools/launcher/ExecutionEnvironment.java	Thu Jun 30 14:18:40 2011 -0700
@@ -299,8 +299,8 @@
 
         if (TestHelper.is32Bit) {
             tr = TestHelper.doExec(TestHelper.javaCmd, "-client", "-version");
-            if (!tr.matches("Java.*Client VM.*")) {
-                System.out.println("FAIL: the expected vm -client did launch");
+            if (!tr.matches(".*Client VM.*")) {
+                System.out.println("FAIL: the expected vm -client did not launch");
                 System.out.println(tr);
                 errors++;
             } else {
@@ -308,8 +308,8 @@
             }
         }
         tr = TestHelper.doExec(TestHelper.javaCmd, "-server", "-version");
-        if (!tr.matches("Java.*Server VM.*")) {
-            System.out.println("FAIL: the expected vm -server did launch");
+        if (!tr.matches(".*Server VM.*")) {
+            System.out.println("FAIL: the expected vm -server did not launch");
             System.out.println(tr);
             errors++;
         } else {
--- a/test/tools/launcher/VersionCheck.java	Thu Jun 30 14:16:48 2011 -0700
+++ b/test/tools/launcher/VersionCheck.java	Thu Jun 30 14:18:40 2011 -0700
@@ -132,7 +132,7 @@
         StringBuilder out = new StringBuilder();
         // remove the HotSpot line
         for (String x : alist) {
-            if (!x.contains("HotSpot")) {
+            if (!x.matches(".*Client.*VM.*|.*Server.*VM.*")) {
                 out = out.append(x + "\n");
             }
         }