diff --git a/.hgtags b/.hgtags index 966c17a5710..cbaa3d31764 100644 --- a/.hgtags +++ b/.hgtags @@ -100,3 +100,5 @@ a4e6aa1f45ad23a6f083ed98d970b5006ea4d292 jdk7-b116 142129d8599d1f56b29387e7f9a5fad53b6d61df jdk7-b123 aa894c225b1a517b665ac2a58295217ea2245134 jdk7-b124 f658ec2730fa29323c36d23c27e54c7219ef5e16 jdk7-b125 +f1df068076986679ea1105532a65529d63a89060 jdk7-b126 +f83cd8bd35c678f94e526990e03dc838d0ec2717 jdk7-b127 diff --git a/.hgtags-top-repo b/.hgtags-top-repo index 5bdac4ada74..3e2de35b9c2 100644 --- a/.hgtags-top-repo +++ b/.hgtags-top-repo @@ -100,3 +100,5 @@ f1591eed71f64f6eba79fb7426f5616cc4dfea73 jdk7-b122 ed6950da30cf1e8904b4bdb034d471647942271f jdk7-b123 024a6755895bf91b5a3c98984c89ee018efbf538 jdk7-b124 5c4df7e992775c102f08e9f1c0a124b324641b70 jdk7-b125 +b566d490905691787f8931f69947a92c67c6d5e4 jdk7-b126 +bd70f76b0309068f157ae759c36eac8f2c6d098e jdk7-b127 diff --git a/Makefile b/Makefile index 7c5b2db01c0..2aec754e6f8 100644 --- a/Makefile +++ b/Makefile @@ -29,15 +29,6 @@ ifndef TOPDIR TOPDIR:=. endif -# Openjdk sources (only used if SKIP_OPENJDK_BUILD!=true) -OPENJDK_SOURCETREE=$(TOPDIR)/openjdk -OPENJDK_BUILDDIR:=$(shell \ - if [ -r $(OPENJDK_SOURCETREE)/Makefile ]; then \ - echo "$(OPENJDK_SOURCETREE)"; \ - else \ - echo "."; \ - fi) - ifndef JDK_TOPDIR JDK_TOPDIR=$(TOPDIR)/jdk endif @@ -70,7 +61,7 @@ include ./make/deploy-rules.gmk all:: @$(START_ECHO) -all:: openjdk_check sanity +all:: sanity ifeq ($(SKIP_FASTDEBUG_BUILD), false) all:: fastdebug_build @@ -80,10 +71,6 @@ ifeq ($(SKIP_DEBUG_BUILD), false) all:: debug_build endif -ifneq ($(SKIP_OPENJDK_BUILD), true) - all:: openjdk_build -endif - all:: all_product_build all:: @@ -267,81 +254,6 @@ product_build:: build_product_image debug_build:: build_debug_image fastdebug_build:: build_fastdebug_image -# Check on whether we really can build the openjdk, need source etc. -openjdk_check: FRC -ifneq ($(SKIP_OPENJDK_BUILD), true) - @$(ECHO) " " - @$(ECHO) "=================================================" - @if [ ! -r $(OPENJDK_BUILDDIR)/Makefile ] ; then \ - $(ECHO) "ERROR: No openjdk source tree available at: $(OPENJDK_BUILDDIR)"; \ - exit 1; \ - else \ - $(ECHO) "OpenJDK will be built after JDK is built"; \ - $(ECHO) " OPENJDK_BUILDDIR=$(OPENJDK_BUILDDIR)"; \ - fi - @$(ECHO) "=================================================" - @$(ECHO) " " -endif - -# If we have bundle rules, we have a chance here to do a complete cycle -# build, of production and open build. -# FIXUP: We should create the openjdk source bundle and build that? -# But how do we reliable create or get at a formal openjdk source tree? -# The one we have needs to be trimmed of built bits and closed dirs. -# The repositories might not be available. -# The openjdk source bundle is probably not available. - -ifneq ($(SKIP_OPENJDK_BUILD), true) - ifeq ($(BUILD_JDK), true) - ifeq ($(BUNDLE_RULES_AVAILABLE), true) - -OPENJDK_OUTPUTDIR=$(ABS_OUTPUTDIR)/open-output -OPENJDK_BUILD_NAME \ - = openjdk-$(JDK_MINOR_VERSION)-$(BUILD_NUMBER)-$(PLATFORM)-$(ARCH)-$(BUNDLE_DATE) -OPENJDK_BUILD_BINARY_ZIP=$(ABS_BIN_BUNDLEDIR)/$(OPENJDK_BUILD_NAME).zip -BUILT_IMAGE=$(ABS_OUTPUTDIR)/j2sdk-image -ifeq ($(PLATFORM)$(ARCH_DATA_MODEL),solaris64) - OPENJDK_BOOTDIR=$(BOOTDIR) - OPENJDK_IMPORTJDK=$(JDK_IMPORT_PATH) -else - OPENJDK_BOOTDIR=$(BUILT_IMAGE) - OPENJDK_IMPORTJDK=$(BUILT_IMAGE) -endif - -openjdk_build: - @$(START_ECHO) - @$(ECHO) " " - @$(ECHO) "=================================================" - @$(ECHO) "Starting openjdk build" - @$(ECHO) " Using: ALT_JDK_DEVTOOLS_DIR=$(JDK_DEVTOOLS_DIR)" - @$(ECHO) "=================================================" - @$(ECHO) " " - $(RM) -r $(OPENJDK_OUTPUTDIR) - $(MKDIR) -p $(OPENJDK_OUTPUTDIR) - ($(CD) $(OPENJDK_BUILDDIR) && $(MAKE) \ - OPENJDK=true \ - GENERATE_DOCS=false \ - ALT_JDK_DEVTOOLS_DIR=$(JDK_DEVTOOLS_DIR) \ - ALT_OUTPUTDIR=$(OPENJDK_OUTPUTDIR) \ - ALT_BOOTDIR=$(OPENJDK_BOOTDIR) \ - ALT_JDK_IMPORT_PATH=$(OPENJDK_IMPORTJDK) \ - product_build ) - $(RM) $(OPENJDK_BUILD_BINARY_ZIP) - ( $(CD) $(OPENJDK_OUTPUTDIR)/j2sdk-image && \ - $(ZIPEXE) -q -r $(OPENJDK_BUILD_BINARY_ZIP) .) - $(RM) -r $(OPENJDK_OUTPUTDIR) - @$(ECHO) " " - @$(ECHO) "=================================================" - @$(ECHO) "Finished openjdk build" - @$(ECHO) " Binary Bundle: $(OPENJDK_BUILD_BINARY_ZIP)" - @$(ECHO) "=================================================" - @$(ECHO) " " - @$(FINISH_ECHO) - - endif - endif -endif - clobber:: $(RM) -r $(OUTPUTDIR)/* $(RM) -r $(OUTPUTDIR)/../$(PLATFORM)-$(ARCH)-debug/* @@ -448,7 +360,6 @@ CACERTS_FILE.desc = Location of certificates file DEVTOOLS_PATH.desc = Directory containing zip and gnumake CUPS_HEADERS_PATH.desc = Include directory location for CUPS header files DXSDK_PATH.desc = Root directory of DirectX SDK -MSVCRT_DLL_PATH.desc = Directory containing mscvrt.dll # Make variables to print out (description and value) VARIABLE_PRINTVAL_LIST += \ @@ -477,12 +388,10 @@ VARIABLE_CHECKFIL_LIST += \ ifeq ($(PLATFORM), windows) VARIABLE_PRINTVAL_LIST += \ - DXSDK_PATH \ - MSVCRT_DLL_PATH + DXSDK_PATH VARIABLE_CHECKDIR_LIST += \ - DXSDK_PATH \ - MSVCRT_DLL_PATH + DXSDK_PATH endif diff --git a/README-builds.html b/README-builds.html index e48aaff3612..f98260ceca4 100644 --- a/README-builds.html +++ b/README-builds.html @@ -1414,14 +1414,14 @@ but it's normally found via the DirectX environment variable DXSDK_DIR. - MSVCR100.DLL + MSVCR100.DLL
The OpenJDK build requires access to a redistributable MSVCR100.DLL. This is usually picked up automatically from the redist directories of Visual Studio 2010. If this cannot be found set the - ALT_MSVCRT_DLL_PATH + ALT_MSVCRNN_DLL_PATH variable to the location of this file.@@ -1671,15 +1671,10 @@ variable DXSDK_DIR, failing that, look in C:/DXSDK. -
+ * This platform extension is only available to a thread + * implementation that supports this extension. + * + * @author Paul Hohensee + * @since 6u25 + */ + +public interface ThreadMXBean extends java.lang.management.ThreadMXBean { + /** + * Returns the total CPU time for each thread whose ID is + * in the input array {@code ids} in nanoseconds. + * The returned values are of nanoseconds precision but + * not necessarily nanoseconds accuracy. + *
+ * This method is equivalent to calling the + * {@link ThreadMXBean#getThreadCpuTime(long)} + * method for each thread ID in the input array {@code ids} and setting the + * returned value in the corresponding element of the returned array. + * + * @param ids an array of thread IDs. + * @return an array of long values, each of which is the amount of CPU + * time the thread whose ID is in the corresponding element of the input + * array of IDs has used, + * if the thread of a specified ID exists, the thread is alive, + * and CPU time measurement is enabled; + * {@code -1} otherwise. + * + * @throws NullPointerException if {@code ids} is {@code null} + * @throws IllegalArgumentException if any element in the input array + * {@code ids} is {@code <=} {@code 0}. + * @throws java.lang.UnsupportedOperationException if the Java + * virtual machine implementation does not support CPU time + * measurement. + * + * @see ThreadMXBean#getThreadCpuTime(long) + * @see #getThreadUserTime + * @see ThreadMXBean#isThreadCpuTimeSupported + * @see ThreadMXBean#isThreadCpuTimeEnabled + * @see ThreadMXBean#setThreadCpuTimeEnabled + */ + public long[] getThreadCpuTime(long[] ids); + + /** + * Returns the CPU time that each thread whose ID is in the input array + * {@code ids} has executed in user mode in nanoseconds. + * The returned values are of nanoseconds precision but + * not necessarily nanoseconds accuracy. + *
+ * This method is equivalent to calling the + * {@link ThreadMXBean#getThreadUserTime(long)} + * method for each thread ID in the input array {@code ids} and setting the + * returned value in the corresponding element of the returned array. + * + * @param ids an array of thread IDs. + * @return an array of long values, each of which is the amount of user + * mode CPU time the thread whose ID is in the corresponding element of + * the input array of IDs has used, + * if the thread of a specified ID exists, the thread is alive, + * and CPU time measurement is enabled; + * {@code -1} otherwise. + * + * @throws NullPointerException if {@code ids} is {@code null} + * @throws IllegalArgumentException if any element in the input array + * {@code ids} is {@code <=} {@code 0}. + * @throws java.lang.UnsupportedOperationException if the Java + * virtual machine implementation does not support CPU time + * measurement. + * + * @see ThreadMXBean#getThreadUserTime(long) + * @see #getThreadCpuTime + * @see ThreadMXBean#isThreadCpuTimeSupported + * @see ThreadMXBean#isThreadCpuTimeEnabled + * @see ThreadMXBean#setThreadCpuTimeEnabled + */ + public long[] getThreadUserTime(long[] ids); + + /** + * Returns an approximation of the total amount of memory, in bytes, + * allocated in heap memory for the thread of the specified ID. + * The returned value is an approximation because some Java virtual machine + * implementations may use object allocation mechanisms that result in a + * delay between the time an object is allocated and the time its size is + * recorded. + *
+ * If the thread of the specified ID is not alive or does not exist, + * this method returns {@code -1}. If thread memory allocation measurement + * is disabled, this method returns {@code -1}. + * A thread is alive if it has been started and has not yet died. + *
+ * If thread memory allocation measurement is enabled after the thread has + * started, the Java virtual machine implementation may choose any time up + * to and including the time that the capability is enabled as the point + * where thread memory allocation measurement starts. + * + * @param id the thread ID of a thread + * @return an approximation of the total memory allocated, in bytes, in + * heap memory for a thread of the specified ID + * if the thread of the specified ID exists, the thread is alive, + * and thread memory allocation measurement is enabled; + * {@code -1} otherwise. + * + * @throws IllegalArgumentException if {@code id} {@code <=} {@code 0}. + * @throws java.lang.UnsupportedOperationException if the Java virtual + * machine implementation does not support thread memory allocation + * measurement. + * + * @see #isThreadAllocatedMemorySupported + * @see #isThreadAllocatedMemoryEnabled + * @see #setThreadAllocatedMemoryEnabled + */ + public long getThreadAllocatedBytes(long id); + + /** + * Returns an approximation of the total amount of memory, in bytes, + * allocated in heap memory for each thread whose ID is in the input + * array {@code ids}. + * The returned values are approximations because some Java virtual machine + * implementations may use object allocation mechanisms that result in a + * delay between the time an object is allocated and the time its size is + * recorded. + *
+ * This method is equivalent to calling the
+ * {@link #getThreadAllocatedBytes(long)}
+ * method for each thread ID in the input array {@code ids} and setting the
+ * returned value in the corresponding element of the returned array.
+ *
+ * @param ids an array of thread IDs.
+ * @return an array of long values, each of which is an approximation of
+ * the total memory allocated, in bytes, in heap memory for the thread
+ * whose ID is in the corresponding element of the input array of IDs.
+ *
+ * @throws NullPointerException if {@code ids} is {@code null}
+ * @throws IllegalArgumentException if any element in the input array
+ * {@code ids} is {@code <=} {@code 0}.
+ * @throws java.lang.UnsupportedOperationException if the Java virtual
+ * machine implementation does not support thread memory allocation
+ * measurement.
+ *
+ * @see #getThreadAllocatedBytes(long)
+ * @see #isThreadAllocatedMemorySupported
+ * @see #isThreadAllocatedMemoryEnabled
+ * @see #setThreadAllocatedMemoryEnabled
+ */
+ public long[] getThreadAllocatedBytes(long[] ids);
+
+ /**
+ * Tests if the Java virtual machine implementation supports thread memory
+ * allocation measurement.
+ *
+ * @return
+ * {@code true}
+ * if the Java virtual machine implementation supports thread memory
+ * allocation measurement;
+ * {@code false} otherwise.
+ */
+ public boolean isThreadAllocatedMemorySupported();
+
+ /**
+ * Tests if thread memory allocation measurement is enabled.
+ *
+ * @return {@code true} if thread memory allocation measurement is enabled;
+ * {@code false} otherwise.
+ *
+ * @throws java.lang.UnsupportedOperationException if the Java virtual
+ * machine does not support thread memory allocation measurement.
+ *
+ * @see #isThreadAllocatedMemorySupported
+ */
+ public boolean isThreadAllocatedMemoryEnabled();
+
+ /**
+ * Enables or disables thread memory allocation measurement. The default
+ * is platform dependent.
+ *
+ * @param enable {@code true} to enable;
+ * {@code false} to disable.
+ *
+ * @throws java.lang.UnsupportedOperationException if the Java virtual
+ * machine does not support thread memory allocation measurement.
+ *
+ * @throws java.lang.SecurityException if a security manager
+ * exists and the caller does not have
+ * ManagementPermission("control").
+ *
+ * @see #isThreadAllocatedMemorySupported
+ */
+ public void setThreadAllocatedMemoryEnabled(boolean enable);
+}
diff --git a/jdk/src/share/classes/com/sun/script/javascript/RhinoScriptEngine.java b/jdk/src/share/classes/com/sun/script/javascript/RhinoScriptEngine.java
index 4c21fdb0c80..6688ec65ab2 100644
--- a/jdk/src/share/classes/com/sun/script/javascript/RhinoScriptEngine.java
+++ b/jdk/src/share/classes/com/sun/script/javascript/RhinoScriptEngine.java
@@ -223,7 +223,9 @@ public final class RhinoScriptEngine extends AbstractScriptEngine
} catch (RhinoException re) {
if (DEBUG) re.printStackTrace();
int line = (line = re.lineNumber()) == 0 ? -1 : line;
- throw new ScriptException(re.toString(), re.sourceName(), line);
+ ScriptException se = new ScriptException(re.toString(), re.sourceName(), line);
+ se.initCause(re);
+ throw se;
} finally {
cx.exit();
}
@@ -257,6 +259,8 @@ public final class RhinoScriptEngine extends AbstractScriptEngine
" str = 'null'; \n" +
" } \n" +
" var out = context.getWriter(); \n" +
+ " if (!(out instanceof java.io.PrintWriter))\n" +
+ " out = new java.io.PrintWriter(out); \n" +
" out.print(String(str)); \n" +
" if (newline) out.print('\\n'); \n" +
" out.flush(); \n" +
diff --git a/jdk/src/share/classes/com/sun/security/auth/PolicyFile.java b/jdk/src/share/classes/com/sun/security/auth/PolicyFile.java
index fa9caf79e53..2005f044052 100644
--- a/jdk/src/share/classes/com/sun/security/auth/PolicyFile.java
+++ b/jdk/src/share/classes/com/sun/security/auth/PolicyFile.java
@@ -1180,7 +1180,7 @@ public class PolicyFile extends javax.security.auth.Policy {
// Done
return certs;
- ArrayList
socksProxyHost (default: <non>)
+
socksProxyHost (default: <none>)
The hostname, or address, of the proxy server.
socksProxyPort (default: 1080)
The port number of the proxy server.
socksProxyVersion (default: 5)
+ The version of the SOCKS protocol supported by the server. The
+ default is 5
indicating SOCKS V5, alternatively
+ 4
can be specified for SOCKS V4. Setting the property
+ to values other than these leads to unspecified behavior.
java.net.socks.username (default: <none>)
Username to use if the SOCKSv5 server asks for authentication
and no java.net.Authenticator instance was found.
Care must be exercised if this method is used on collections that - * do not comply with the general contract for Collection. + * do not comply with the general contract for {@code Collection}. * Implementations may elect to iterate over either collection and test * for containment in the other collection (or to perform any equivalent * computation). If either collection uses a nonstandard equality test - * (as does a {@link SortedSet} whose ordering is not compatible with - * equals, or the key set of an {@link IdentityHashMap}), both + * (as does a {@link SortedSet} whose ordering is not compatible with + * equals, or the key set of an {@link IdentityHashMap}), both * collections must use the same nonstandard equality test, or the * result of this method is undefined. * + *
Care must also be exercised when using collections that have + * restrictions on the elements that they may contain. Collection + * implementations are allowed to throw exceptions for any operation + * involving elements they deem ineligible. For absolute safety the + * specified collections should contain only elements which are + * eligible elements for both collections. + * *
Note that it is permissible to pass the same collection in both - * parameters, in which case the method will return true if and only if - * the collection is empty. + * parameters, in which case the method will return {@code true} if and + * only if the collection is empty. * * @param c1 a collection * @param c2 a collection - * @throws NullPointerException if either collection is null + * @return {@code true} if the two specified collections have no + * elements in common. + * @throws NullPointerException if either collection is {@code null}. + * @throws NullPointerException if one collection contains a {@code null} + * element and {@code null} is not an eligible element for the other collection. + * (optional) + * @throws ClassCastException if one collection contains an element that is + * of a type which is ineligible for the other collection. (optional) * @since 1.5 */ public static boolean disjoint(Collection> c1, Collection> c2) { - /* - * We're going to iterate through c1 and test for inclusion in c2. - * If c1 is a Set and c2 isn't, swap the collections. Otherwise, - * place the shorter collection in c1. Hopefully this heuristic - * will minimize the cost of the operation. - */ - if ((c1 instanceof Set) && !(c2 instanceof Set) || - (c1.size() > c2.size())) { - Collection> tmp = c1; - c1 = c2; - c2 = tmp; + // The collection to be used for contains(). Preference is given to + // the collection who's contains() has lower O() complexity. + Collection> contains = c2; + // The collection to be iterated. If the collections' contains() impl + // are of different O() complexity, the collection with slower + // contains() will be used for iteration. For collections who's + // contains() are of the same complexity then best performance is + // achieved by iterating the smaller collection. + Collection> iterate = c1; + + // Performance optimization cases. The heuristics: + // 1. Generally iterate over c1. + // 2. If c1 is a Set then iterate over c2. + // 3. If either collection is empty then result is always true. + // 4. Iterate over the smaller Collection. + if (c1 instanceof Set) { + // Use c1 for contains as a Set's contains() is expected to perform + // better than O(N/2) + iterate = c2; + contains = c1; + } else if (!(c2 instanceof Set)) { + // Both are mere Collections. Iterate over smaller collection. + // Example: If c1 contains 3 elements and c2 contains 50 elements and + // assuming contains() requires ceiling(N/2) comparisons then + // checking for all c1 elements in c2 would require 75 comparisons + // (3 * ceiling(50/2)) vs. checking all c2 elements in c1 requiring + // 100 comparisons (50 * ceiling(3/2)). + int c1size = c1.size(); + int c2size = c2.size(); + if (c1size == 0 || c2size == 0) { + // At least one collection is empty. Nothing will match. + return true; + } + + if (c1size > c2size) { + iterate = c2; + contains = c1; + } } - for (Object e : c1) - if (c2.contains(e)) + for (Object e : iterate) { + if (contains.contains(e)) { + // Found a common element. Collections are not disjoint. return false; + } + } + + // No common elements were found. return true; } diff --git a/jdk/src/share/classes/java/util/Formatter.java b/jdk/src/share/classes/java/util/Formatter.java index 316135ed0fa..6c9ead3b7f0 100644 --- a/jdk/src/share/classes/java/util/Formatter.java +++ b/jdk/src/share/classes/java/util/Formatter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, 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,6 +41,8 @@ import java.math.BigInteger; import java.math.MathContext; import java.math.RoundingMode; import java.nio.charset.Charset; +import java.nio.charset.IllegalCharsetNameException; +import java.nio.charset.UnsupportedCharsetException; import java.text.DateFormatSymbols; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; @@ -1838,22 +1840,53 @@ import sun.misc.FormattedFloatingDecimal; */ public final class Formatter implements Closeable, Flushable { private Appendable a; - private Locale l; + private final Locale l; private IOException lastException; - private char zero = '0'; + private final char zero; private static double scaleUp; // 1 (sign) + 19 (max # sig digits) + 1 ('.') + 1 ('e') + 1 (sign) // + 3 (max # exp digits) + 4 (error) = 30 private static final int MAX_FD_CHARS = 30; - // Initialize internal data. - private void init(Appendable a, Locale l) { + /** + * Returns a charset object for the given charset name. + * @throws NullPointerException is csn is null + * @throws UnsupportedEncodingException if the charset is not supported + */ + private static Charset toCharset(String csn) + throws UnsupportedEncodingException + { + Objects.nonNull(csn, "charsetName"); + try { + return Charset.forName(csn); + } catch (IllegalCharsetNameException|UnsupportedCharsetException unused) { + // UnsupportedEncodingException should be thrown + throw new UnsupportedEncodingException(csn); + } + } + + private static final Appendable nonNullAppendable(Appendable a) { + if (a == null) + return new StringBuilder(); + + return a; + } + + /* Private constructors */ + private Formatter(Locale l, Appendable a) { this.a = a; this.l = l; - setZero(); + this.zero = getZero(l); + } + + private Formatter(Charset charset, Locale l, File file) + throws FileNotFoundException + { + this(l, + new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), charset))); } /** @@ -1867,7 +1900,7 @@ public final class Formatter implements Closeable, Flushable { * virtual machine. */ public Formatter() { - init(new StringBuilder(), Locale.getDefault(Locale.Category.FORMAT)); + this(Locale.getDefault(Locale.Category.FORMAT), new StringBuilder()); } /** @@ -1881,9 +1914,7 @@ public final class Formatter implements Closeable, Flushable { * {@code null} then a {@link StringBuilder} will be created. */ public Formatter(Appendable a) { - if (a == null) - a = new StringBuilder(); - init(a, Locale.getDefault(Locale.Category.FORMAT)); + this(Locale.getDefault(Locale.Category.FORMAT), nonNullAppendable(a)); } /** @@ -1900,7 +1931,7 @@ public final class Formatter implements Closeable, Flushable { * is applied. */ public Formatter(Locale l) { - init(new StringBuilder(), l); + this(l, new StringBuilder()); } /** @@ -1916,9 +1947,7 @@ public final class Formatter implements Closeable, Flushable { * is applied. */ public Formatter(Appendable a, Locale l) { - if (a == null) - a = new StringBuilder(); - init(a, l); + this(l, nonNullAppendable(a)); } /** @@ -1949,8 +1978,8 @@ public final class Formatter implements Closeable, Flushable { * creating the file */ public Formatter(String fileName) throws FileNotFoundException { - init(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName))), - Locale.getDefault(Locale.Category.FORMAT)); + this(Locale.getDefault(Locale.Category.FORMAT), + new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName)))); } /** @@ -2025,8 +2054,7 @@ public final class Formatter implements Closeable, Flushable { public Formatter(String fileName, String csn, Locale l) throws FileNotFoundException, UnsupportedEncodingException { - init(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), csn)), - l); + this(toCharset(csn), l, new File(fileName)); } /** @@ -2057,8 +2085,8 @@ public final class Formatter implements Closeable, Flushable { * creating the file */ public Formatter(File file) throws FileNotFoundException { - init(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file))), - Locale.getDefault(Locale.Category.FORMAT)); + this(Locale.getDefault(Locale.Category.FORMAT), + new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file)))); } /** @@ -2133,8 +2161,7 @@ public final class Formatter implements Closeable, Flushable { public Formatter(File file, String csn, Locale l) throws FileNotFoundException, UnsupportedEncodingException { - init(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), csn)), - l); + this(toCharset(csn), l, file); } /** @@ -2151,9 +2178,8 @@ public final class Formatter implements Closeable, Flushable { * The stream to use as the destination of this formatter. */ public Formatter(PrintStream ps) { - if (ps == null) - throw new NullPointerException(); - init((Appendable)ps, Locale.getDefault(Locale.Category.FORMAT)); + this(Locale.getDefault(Locale.Category.FORMAT), + (Appendable)Objects.nonNull(ps)); } /** @@ -2171,8 +2197,8 @@ public final class Formatter implements Closeable, Flushable { * The output will be buffered. */ public Formatter(OutputStream os) { - init(new BufferedWriter(new OutputStreamWriter(os)), - Locale.getDefault(Locale.Category.FORMAT)); + this(Locale.getDefault(Locale.Category.FORMAT), + new BufferedWriter(new OutputStreamWriter(os))); } /** @@ -2222,13 +2248,15 @@ public final class Formatter implements Closeable, Flushable { public Formatter(OutputStream os, String csn, Locale l) throws UnsupportedEncodingException { - init(new BufferedWriter(new OutputStreamWriter(os, csn)), l); + this(l, new BufferedWriter(new OutputStreamWriter(os, csn))); } - private void setZero() { + private static char getZero(Locale l) { if ((l != null) && !l.equals(Locale.US)) { DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(l); - zero = dfs.getZeroDigit(); + return dfs.getZeroDigit(); + } else { + return '0'; } } diff --git a/jdk/src/share/classes/java/util/LinkedList.java b/jdk/src/share/classes/java/util/LinkedList.java index fbf8f5f92ce..e4d0ddc0787 100644 --- a/jdk/src/share/classes/java/util/LinkedList.java +++ b/jdk/src/share/classes/java/util/LinkedList.java @@ -26,9 +26,9 @@ package java.util; /** - * Linked list implementation of the {@link List} and {@link Deque} interfaces. - * Implements all optional operations, and permits all elements (including - * {@code null}). + * Doubly-linked list implementation of the {@code List} and {@code Deque} + * interfaces. Implements all optional list operations, and permits all + * elements (including {@code null}). * *
All of the operations perform as could be expected for a doubly-linked
* list. Operations that index into the list will traverse the list from
@@ -249,7 +249,7 @@ public class LinkedList This is a classic "bounded buffer", in which a
* fixed-sized array holds elements inserted by producers and
* extracted by consumers. Once created, the capacity cannot be
- * increased. Attempts to put an element into a full queue
- * will result in the operation blocking; attempts to take an
+ * changed. Attempts to {@code put} an element into a full queue
+ * will result in the operation blocking; attempts to {@code take} an
* element from an empty queue will similarly block.
*
- * This class supports an optional fairness policy for ordering
+ * This class supports an optional fairness policy for ordering
* waiting producer and consumer threads. By default, this ordering
* is not guaranteed. However, a queue constructed with fairness set
- * to true grants threads access in FIFO order. Fairness
+ * to {@code true} grants threads access in FIFO order. Fairness
* generally decreases throughput but reduces variability and avoids
* starvation.
*
@@ -83,14 +83,17 @@ public class ArrayBlockingQueue Note that you cannot always tell if an attempt to insert
- * an element will succeed by inspecting remainingCapacity
+ * an element will succeed by inspecting {@code remainingCapacity}
* because it may be the case that another thread is about to
* insert or remove an element.
*/
@@ -431,59 +446,56 @@ public class ArrayBlockingQueue Removal of interior elements in circular array based queues
+ * is an intrinsically slow and disruptive operation, so should
+ * be undertaken only in exceptional circumstances, ideally
+ * only when the queue is known not to be accessible by other
+ * threads.
+ *
* @param o element to be removed from this queue, if present
- * @return true if this queue changed as a result of the call
+ * @return {@code true} if this queue changed as a result of the call
*/
public boolean remove(Object o) {
if (o == null) return false;
- final E[] items = this.items;
+ final Object[] items = this.items;
final ReentrantLock lock = this.lock;
lock.lock();
try {
- int i = takeIndex;
- int k = 0;
- for (;;) {
- if (k++ >= count)
- return false;
+ for (int i = takeIndex, k = count; k > 0; i = inc(i), k--) {
if (o.equals(items[i])) {
removeAt(i);
return true;
}
- i = inc(i);
}
-
+ return false;
} finally {
lock.unlock();
}
}
/**
- * Returns true if this queue contains the specified element.
- * More formally, returns true if and only if this queue contains
- * at least one element e such that o.equals(e).
+ * Returns {@code true} if this queue contains the specified element.
+ * More formally, returns {@code true} if and only if this queue contains
+ * at least one element {@code e} such that {@code o.equals(e)}.
*
* @param o object to be checked for containment in this queue
- * @return true if this queue contains the specified element
+ * @return {@code true} if this queue contains the specified element
*/
public boolean contains(Object o) {
if (o == null) return false;
- final E[] items = this.items;
+ final Object[] items = this.items;
final ReentrantLock lock = this.lock;
lock.lock();
try {
- int i = takeIndex;
- int k = 0;
- while (k++ < count) {
+ for (int i = takeIndex, k = count; k > 0; i = inc(i), k--)
if (o.equals(items[i]))
return true;
- i = inc(i);
- }
return false;
} finally {
lock.unlock();
@@ -504,17 +516,14 @@ public class ArrayBlockingQueue If this queue fits in the specified array with room to spare
* (i.e., the array has more elements than this queue), the element in
* the array immediately following the end of the queue is set to
- * null.
+ * {@code null}.
*
* Like the {@link #toArray()} method, this method acts as bridge between
* array-based and collection-based APIs. Further, this method allows
* precise control over the runtime type of the output array, and may,
* under certain circumstances, be used to save allocation costs.
*
- * Suppose x is a queue known to contain only strings.
+ * Suppose {@code x} is a queue known to contain only strings.
* The following code can be used to dump the queue into a newly
- * allocated array of String:
+ * allocated array of {@code String}:
*
* The returned {@code Iterator} is a "weakly consistent" iterator that
+ * will never throw {@link java.util.ConcurrentModificationException
+ * ConcurrentModificationException},
* and guarantees to traverse elements as they existed upon
* construction of the iterator, and may (but is not guaranteed to)
* reflect any modifications subsequent to construction.
@@ -702,83 +714,65 @@ public class ArrayBlockingQueue This method is equivalent to {@link #add}.
*
@@ -889,8 +893,9 @@ public class ConcurrentLinkedDeque This method is equivalent to {@link #add}.
*
- * @return {@code true} always
+ * @return {@code true} (as specified by {@link Deque#offerLast})
* @throws NullPointerException if the specified element is null
*/
public boolean offerLast(E e) {
@@ -983,6 +989,7 @@ public class ConcurrentLinkedDeque
* String[] y = x.toArray(new String[0]);
*
- * Note that toArray(new Object[0]) is identical in function to
- * toArray().
+ * Note that {@code toArray(new Object[0])} is identical in function to
+ * {@code toArray()}.
*
* @param a the array into which the elements of the queue are to
* be stored, if it is big enough; otherwise, a new array of the
@@ -557,24 +566,20 @@ public class ArrayBlockingQueue