(Collections.nCopies(
attrIndexLimit[i], (Attribute.Layout)null)));
}
diff --git a/jdk/src/share/classes/com/sun/management/ThreadMXBean.java b/jdk/src/share/classes/com/sun/management/ThreadMXBean.java
new file mode 100644
index 00000000000..f5a9a5b9a0d
--- /dev/null
+++ b/jdk/src/share/classes/com/sun/management/ThreadMXBean.java
@@ -0,0 +1,221 @@
+/*
+ * 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 com.sun.management;
+
+import java.util.Map;
+
+/**
+ * Platform-specific management interface for the thread system
+ * of the Java virtual machine.
+ *
+ * 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 userCertList = new ArrayList();
+ ArrayList userCertList = new ArrayList<>();
i = 0;
while (i < certs.length) {
userCertList.add(certs[i]);
diff --git a/jdk/src/share/classes/com/sun/security/auth/callback/DialogCallbackHandler.java b/jdk/src/share/classes/com/sun/security/auth/callback/DialogCallbackHandler.java
index 63212fafb87..5f217190417 100644
--- a/jdk/src/share/classes/com/sun/security/auth/callback/DialogCallbackHandler.java
+++ b/jdk/src/share/classes/com/sun/security/auth/callback/DialogCallbackHandler.java
@@ -99,10 +99,10 @@ public class DialogCallbackHandler implements CallbackHandler {
throws UnsupportedCallbackException
{
/* Collect messages to display in the dialog */
- final List messages = new ArrayList(3);
+ final List messages = new ArrayList<>(3);
/* Collection actions to perform if the user clicks OK */
- final List okActions = new ArrayList(2);
+ final List okActions = new ArrayList<>(2);
ConfirmationInfo confirmation = new ConfirmationInfo();
diff --git a/jdk/src/share/classes/com/sun/security/auth/login/ConfigFile.java b/jdk/src/share/classes/com/sun/security/auth/login/ConfigFile.java
index ad186566fee..b3689ff21a0 100644
--- a/jdk/src/share/classes/com/sun/security/auth/login/ConfigFile.java
+++ b/jdk/src/share/classes/com/sun/security/auth/login/ConfigFile.java
@@ -152,7 +152,7 @@ public class ConfigFile extends javax.security.auth.login.Configuration {
// new configuration
HashMap> newConfig =
- new HashMap>();
+ new HashMap<>();
if (url != null) {
@@ -392,8 +392,7 @@ public class ConfigFile extends javax.security.auth.login.Configuration {
String moduleClass;
String sflag;
AppConfigurationEntry.LoginModuleControlFlag controlFlag;
- LinkedList configEntries =
- new LinkedList();
+ LinkedList configEntries = new LinkedList<>();
// application name
appName = st.sval;
@@ -433,7 +432,7 @@ public class ConfigFile extends javax.security.auth.login.Configuration {
}
// get the args
- HashMap options = new HashMap();
+ HashMap options = new HashMap<>();
String key;
String value;
while (peek(";") == false) {
diff --git a/jdk/src/share/classes/com/sun/security/auth/module/JndiLoginModule.java b/jdk/src/share/classes/com/sun/security/auth/module/JndiLoginModule.java
index 59a19849df4..cede6b64062 100644
--- a/jdk/src/share/classes/com/sun/security/auth/module/JndiLoginModule.java
+++ b/jdk/src/share/classes/com/sun/security/auth/module/JndiLoginModule.java
@@ -184,7 +184,7 @@ public class JndiLoginModule implements LoginModule {
private UnixNumericUserPrincipal UIDPrincipal;
private UnixNumericGroupPrincipal GIDPrincipal;
private LinkedList supplementaryGroups =
- new LinkedList();
+ new LinkedList<>();
// initial state
private Subject subject;
diff --git a/jdk/src/share/classes/com/sun/security/auth/module/KeyStoreLoginModule.java b/jdk/src/share/classes/com/sun/security/auth/module/KeyStoreLoginModule.java
index ff6185e3877..f2199ed890c 100644
--- a/jdk/src/share/classes/com/sun/security/auth/module/KeyStoreLoginModule.java
+++ b/jdk/src/share/classes/com/sun/security/auth/module/KeyStoreLoginModule.java
@@ -658,8 +658,7 @@ public class KeyStoreLoginModule implements LoginModule {
throw new FailedLoginException(
"Unable to find X.509 certificate chain in keystore");
} else {
- LinkedList certList =
- new LinkedList();
+ LinkedList certList = new LinkedList<>();
for (int i=0; i < fromKeyStore.length; i++) {
certList.add(fromKeyStore[i]);
}
diff --git a/jdk/src/share/classes/com/sun/security/auth/module/SolarisLoginModule.java b/jdk/src/share/classes/com/sun/security/auth/module/SolarisLoginModule.java
index 2767b9a4a22..cca9be6564d 100644
--- a/jdk/src/share/classes/com/sun/security/auth/module/SolarisLoginModule.java
+++ b/jdk/src/share/classes/com/sun/security/auth/module/SolarisLoginModule.java
@@ -76,7 +76,7 @@ public class SolarisLoginModule implements LoginModule {
private SolarisNumericUserPrincipal UIDPrincipal;
private SolarisNumericGroupPrincipal GIDPrincipal;
private LinkedList supplementaryGroups =
- new LinkedList();
+ new LinkedList<>();
/**
* Initialize this LoginModule
.
diff --git a/jdk/src/share/classes/com/sun/security/auth/module/UnixLoginModule.java b/jdk/src/share/classes/com/sun/security/auth/module/UnixLoginModule.java
index a29153fb6a9..6f9a443f30a 100644
--- a/jdk/src/share/classes/com/sun/security/auth/module/UnixLoginModule.java
+++ b/jdk/src/share/classes/com/sun/security/auth/module/UnixLoginModule.java
@@ -70,7 +70,7 @@ public class UnixLoginModule implements LoginModule {
private UnixNumericUserPrincipal UIDPrincipal;
private UnixNumericGroupPrincipal GIDPrincipal;
private LinkedList supplementaryGroups =
- new LinkedList();
+ new LinkedList<>();
/**
* Initialize this LoginModule
.
diff --git a/jdk/src/share/classes/java/awt/geom/CubicCurve2D.java b/jdk/src/share/classes/java/awt/geom/CubicCurve2D.java
index 766e383ffb0..9f8042229d2 100644
--- a/jdk/src/share/classes/java/awt/geom/CubicCurve2D.java
+++ b/jdk/src/share/classes/java/awt/geom/CubicCurve2D.java
@@ -1387,203 +1387,13 @@ public abstract class CubicCurve2D implements Shape, Cloneable {
return false;
}
- // Trivially accept if either endpoint is inside the rectangle
- // (not on its border since it may end there and not go inside)
- // Record where they lie with respect to the rectangle.
- // -1 => left, 0 => inside, 1 => right
- double x1 = getX1();
- double y1 = getY1();
- int x1tag = getTag(x1, x, x+w);
- int y1tag = getTag(y1, y, y+h);
- if (x1tag == INSIDE && y1tag == INSIDE) {
- return true;
- }
- double x2 = getX2();
- double y2 = getY2();
- int x2tag = getTag(x2, x, x+w);
- int y2tag = getTag(y2, y, y+h);
- if (x2tag == INSIDE && y2tag == INSIDE) {
- return true;
- }
-
- double ctrlx1 = getCtrlX1();
- double ctrly1 = getCtrlY1();
- double ctrlx2 = getCtrlX2();
- double ctrly2 = getCtrlY2();
- int ctrlx1tag = getTag(ctrlx1, x, x+w);
- int ctrly1tag = getTag(ctrly1, y, y+h);
- int ctrlx2tag = getTag(ctrlx2, x, x+w);
- int ctrly2tag = getTag(ctrly2, y, y+h);
-
- // Trivially reject if all points are entirely to one side of
- // the rectangle.
- if (x1tag < INSIDE && x2tag < INSIDE &&
- ctrlx1tag < INSIDE && ctrlx2tag < INSIDE)
- {
- return false; // All points left
- }
- if (y1tag < INSIDE && y2tag < INSIDE &&
- ctrly1tag < INSIDE && ctrly2tag < INSIDE)
- {
- return false; // All points above
- }
- if (x1tag > INSIDE && x2tag > INSIDE &&
- ctrlx1tag > INSIDE && ctrlx2tag > INSIDE)
- {
- return false; // All points right
- }
- if (y1tag > INSIDE && y2tag > INSIDE &&
- ctrly1tag > INSIDE && ctrly2tag > INSIDE)
- {
- return false; // All points below
- }
-
- // Test for endpoints on the edge where either the segment
- // or the curve is headed "inwards" from them
- // Note: These tests are a superset of the fast endpoint tests
- // above and thus repeat those tests, but take more time
- // and cover more cases
- if (inwards(x1tag, x2tag, ctrlx1tag) &&
- inwards(y1tag, y2tag, ctrly1tag))
- {
- // First endpoint on border with either edge moving inside
- return true;
- }
- if (inwards(x2tag, x1tag, ctrlx2tag) &&
- inwards(y2tag, y1tag, ctrly2tag))
- {
- // Second endpoint on border with either edge moving inside
- return true;
- }
-
- // Trivially accept if endpoints span directly across the rectangle
- boolean xoverlap = (x1tag * x2tag <= 0);
- boolean yoverlap = (y1tag * y2tag <= 0);
- if (x1tag == INSIDE && x2tag == INSIDE && yoverlap) {
- return true;
- }
- if (y1tag == INSIDE && y2tag == INSIDE && xoverlap) {
- return true;
- }
-
- // We now know that both endpoints are outside the rectangle
- // but the 4 points are not all on one side of the rectangle.
- // Therefore the curve cannot be contained inside the rectangle,
- // but the rectangle might be contained inside the curve, or
- // the curve might intersect the boundary of the rectangle.
-
- double[] eqn = new double[4];
- double[] res = new double[4];
- if (!yoverlap) {
- // Both y coordinates for the closing segment are above or
- // below the rectangle which means that we can only intersect
- // if the curve crosses the top (or bottom) of the rectangle
- // in more than one place and if those crossing locations
- // span the horizontal range of the rectangle.
- fillEqn(eqn, (y1tag < INSIDE ? y : y+h), y1, ctrly1, ctrly2, y2);
- int num = solveCubic(eqn, res);
- num = evalCubic(res, num, true, true, null,
- x1, ctrlx1, ctrlx2, x2);
- // odd counts imply the crossing was out of [0,1] bounds
- // otherwise there is no way for that part of the curve to
- // "return" to meet its endpoint
- return (num == 2 &&
- getTag(res[0], x, x+w) * getTag(res[1], x, x+w) <= 0);
- }
-
- // Y ranges overlap. Now we examine the X ranges
- if (!xoverlap) {
- // Both x coordinates for the closing segment are left of
- // or right of the rectangle which means that we can only
- // intersect if the curve crosses the left (or right) edge
- // of the rectangle in more than one place and if those
- // crossing locations span the vertical range of the rectangle.
- fillEqn(eqn, (x1tag < INSIDE ? x : x+w), x1, ctrlx1, ctrlx2, x2);
- int num = solveCubic(eqn, res);
- num = evalCubic(res, num, true, true, null,
- y1, ctrly1, ctrly2, y2);
- // odd counts imply the crossing was out of [0,1] bounds
- // otherwise there is no way for that part of the curve to
- // "return" to meet its endpoint
- return (num == 2 &&
- getTag(res[0], y, y+h) * getTag(res[1], y, y+h) <= 0);
- }
-
- // The X and Y ranges of the endpoints overlap the X and Y
- // ranges of the rectangle, now find out how the endpoint
- // line segment intersects the Y range of the rectangle
- double dx = x2 - x1;
- double dy = y2 - y1;
- double k = y2 * x1 - x2 * y1;
- int c1tag, c2tag;
- if (y1tag == INSIDE) {
- c1tag = x1tag;
- } else {
- c1tag = getTag((k + dx * (y1tag < INSIDE ? y : y+h)) / dy, x, x+w);
- }
- if (y2tag == INSIDE) {
- c2tag = x2tag;
- } else {
- c2tag = getTag((k + dx * (y2tag < INSIDE ? y : y+h)) / dy, x, x+w);
- }
- // If the part of the line segment that intersects the Y range
- // of the rectangle crosses it horizontally - trivially accept
- if (c1tag * c2tag <= 0) {
- return true;
- }
-
- // Now we know that both the X and Y ranges intersect and that
- // the endpoint line segment does not directly cross the rectangle.
- //
- // We can almost treat this case like one of the cases above
- // where both endpoints are to one side, except that we may
- // get one or three intersections of the curve with the vertical
- // side of the rectangle. This is because the endpoint segment
- // accounts for the other intersection in an even pairing. Thus,
- // with the endpoint crossing we end up with 2 or 4 total crossings.
- //
- // (Remember there is overlap in both the X and Y ranges which
- // means that the segment itself must cross at least one vertical
- // edge of the rectangle - in particular, the "near vertical side"
- // - leaving an odd number of intersections for the curve.)
- //
- // Now we calculate the y tags of all the intersections on the
- // "near vertical side" of the rectangle. We will have one with
- // the endpoint segment, and one or three with the curve. If
- // any pair of those vertical intersections overlap the Y range
- // of the rectangle, we have an intersection. Otherwise, we don't.
-
- // c1tag = vertical intersection class of the endpoint segment
- //
- // Choose the y tag of the endpoint that was not on the same
- // side of the rectangle as the subsegment calculated above.
- // Note that we can "steal" the existing Y tag of that endpoint
- // since it will be provably the same as the vertical intersection.
- c1tag = ((c1tag * x1tag <= 0) ? y1tag : y2tag);
-
- // Now we have to calculate an array of solutions of the curve
- // with the "near vertical side" of the rectangle. Then we
- // need to sort the tags and do a pairwise range test to see
- // if either of the pairs of crossings spans the Y range of
- // the rectangle.
- //
- // Note that the c2tag can still tell us which vertical edge
- // to test against.
- fillEqn(eqn, (c2tag < INSIDE ? x : x+w), x1, ctrlx1, ctrlx2, x2);
- int num = solveCubic(eqn, res);
- num = evalCubic(res, num, true, true, null, y1, ctrly1, ctrly2, y2);
-
- // Now put all of the tags into a bucket and sort them. There
- // is an intersection iff one of the pairs of tags "spans" the
- // Y range of the rectangle.
- int tags[] = new int[num+1];
- for (int i = 0; i < num; i++) {
- tags[i] = getTag(res[i], y, y+h);
- }
- tags[num] = c1tag;
- Arrays.sort(tags);
- return ((num >= 1 && tags[0] * tags[1] <= 0) ||
- (num >= 3 && tags[2] * tags[3] <= 0));
+ int numCrossings = rectCrossings(x, y, w, h);
+ // the intended return value is
+ // numCrossings != 0 || numCrossings == Curve.RECT_INTERSECTS
+ // but if (numCrossings != 0) numCrossings == INTERSECTS won't matter
+ // and if !(numCrossings != 0) then numCrossings == 0, so
+ // numCrossings != RECT_INTERSECT
+ return numCrossings != 0;
}
/**
@@ -1602,20 +1412,32 @@ public abstract class CubicCurve2D implements Shape, Cloneable {
if (w <= 0 || h <= 0) {
return false;
}
- // Assertion: Cubic curves closed by connecting their
- // endpoints form either one or two convex halves with
- // the closing line segment as an edge of both sides.
- if (!(contains(x, y) &&
- contains(x + w, y) &&
- contains(x + w, y + h) &&
- contains(x, y + h))) {
- return false;
+
+ int numCrossings = rectCrossings(x, y, w, h);
+ return !(numCrossings == 0 || numCrossings == Curve.RECT_INTERSECTS);
+ }
+
+ private int rectCrossings(double x, double y, double w, double h) {
+ int crossings = 0;
+ if (!(getX1() == getX2() && getY1() == getY2())) {
+ crossings = Curve.rectCrossingsForLine(crossings,
+ x, y,
+ x+w, y+h,
+ getX1(), getY1(),
+ getX2(), getY2());
+ if (crossings == Curve.RECT_INTERSECTS) {
+ return crossings;
+ }
}
- // Either the rectangle is entirely inside one of the convex
- // halves or it crosses from one to the other, in which case
- // it must intersect the closing line segment.
- Rectangle2D rect = new Rectangle2D.Double(x, y, w, h);
- return !rect.intersectsLine(getX1(), getY1(), getX2(), getY2());
+ // we call this with the curve's direction reversed, because we wanted
+ // to call rectCrossingsForLine first, because it's cheaper.
+ return Curve.rectCrossingsForCubic(crossings,
+ x, y,
+ x+w, y+h,
+ getX2(), getY2(),
+ getCtrlX2(), getCtrlY2(),
+ getCtrlX1(), getCtrlY1(),
+ getX1(), getY1(), 0);
}
/**
diff --git a/jdk/src/share/classes/java/io/ObjectStreamClass.java b/jdk/src/share/classes/java/io/ObjectStreamClass.java
index 2d3e2055860..74608db0c1c 100644
--- a/jdk/src/share/classes/java/io/ObjectStreamClass.java
+++ b/jdk/src/share/classes/java/io/ObjectStreamClass.java
@@ -329,7 +329,7 @@ public class ObjectStreamClass implements Serializable {
entry = th;
}
if (future.set(entry)) {
- Caches.localDescs.put(key, new SoftReference<>(entry));
+ Caches.localDescs.put(key, new SoftReference(entry));
} else {
// nested lookup call already set future
entry = future.get();
@@ -2118,7 +2118,7 @@ public class ObjectStreamClass implements Serializable {
entry = th;
}
future.set(entry);
- Caches.reflectors.put(key, new SoftReference<>(entry));
+ Caches.reflectors.put(key, new SoftReference(entry));
}
if (entry instanceof FieldReflector) {
diff --git a/jdk/src/share/classes/java/io/PrintStream.java b/jdk/src/share/classes/java/io/PrintStream.java
index 2f4168aaf78..9ed3ff6f910 100644
--- a/jdk/src/share/classes/java/io/PrintStream.java
+++ b/jdk/src/share/classes/java/io/PrintStream.java
@@ -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
@@ -27,7 +27,9 @@ package java.io;
import java.util.Formatter;
import java.util.Locale;
-
+import java.nio.charset.Charset;
+import java.nio.charset.IllegalCharsetNameException;
+import java.nio.charset.UnsupportedCharsetException;
/**
* A PrintStream
adds functionality to another output stream,
@@ -56,7 +58,7 @@ public class PrintStream extends FilterOutputStream
implements Appendable, Closeable
{
- private boolean autoFlush = false;
+ private final boolean autoFlush;
private boolean trouble = false;
private Formatter formatter;
@@ -67,6 +69,60 @@ public class PrintStream extends FilterOutputStream
private BufferedWriter textOut;
private OutputStreamWriter charOut;
+ /**
+ * nonNull is explicitly declared here so as not to create an extra
+ * dependency on java.util.Objects.nonNull. PrintStream is loaded
+ * early during system initialization.
+ */
+ private static T nonNull(T obj, String message) {
+ if (obj == null)
+ throw new NullPointerException(message);
+ return obj;
+ }
+
+ /**
+ * 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
+ {
+ nonNull(csn, "charsetName");
+ try {
+ return Charset.forName(csn);
+ } catch (IllegalCharsetNameException|UnsupportedCharsetException unused) {
+ // UnsupportedEncodingException should be thrown
+ throw new UnsupportedEncodingException(csn);
+ }
+ }
+
+ /* Private constructors */
+ private PrintStream(boolean autoFlush, OutputStream out) {
+ super(out);
+ this.autoFlush = autoFlush;
+ this.charOut = new OutputStreamWriter(this);
+ this.textOut = new BufferedWriter(charOut);
+ }
+
+ private PrintStream(boolean autoFlush, OutputStream out, Charset charset) {
+ super(out);
+ this.autoFlush = autoFlush;
+ this.charOut = new OutputStreamWriter(this, charset);
+ this.textOut = new BufferedWriter(charOut);
+ }
+
+ /* Variant of the private constructor so that the given charset name
+ * can be verified before evaluating the OutputStream argument. Used
+ * by constructors creating a FileOutputStream that also take a
+ * charset name.
+ */
+ private PrintStream(boolean autoFlush, Charset charset, OutputStream out)
+ throws UnsupportedEncodingException
+ {
+ this(autoFlush, out, charset);
+ }
+
/**
* Creates a new print stream. This stream will not flush automatically.
*
@@ -79,27 +135,6 @@ public class PrintStream extends FilterOutputStream
this(out, false);
}
- /* Initialization is factored into a private constructor (note the swapped
- * parameters so that this one isn't confused with the public one) and a
- * separate init method so that the following two public constructors can
- * share code. We use a separate init method so that the constructor that
- * takes an encoding will throw an NPE for a null stream before it throws
- * an UnsupportedEncodingException for an unsupported encoding.
- */
-
- private PrintStream(boolean autoFlush, OutputStream out)
- {
- super(out);
- if (out == null)
- throw new NullPointerException("Null output stream");
- this.autoFlush = autoFlush;
- }
-
- private void init(OutputStreamWriter osw) {
- this.charOut = osw;
- this.textOut = new BufferedWriter(osw);
- }
-
/**
* Creates a new print stream.
*
@@ -113,8 +148,7 @@ public class PrintStream extends FilterOutputStream
* @see java.io.PrintWriter#PrintWriter(java.io.OutputStream, boolean)
*/
public PrintStream(OutputStream out, boolean autoFlush) {
- this(autoFlush, out);
- init(new OutputStreamWriter(this));
+ this(autoFlush, nonNull(out, "Null output stream"));
}
/**
@@ -138,8 +172,9 @@ public class PrintStream extends FilterOutputStream
public PrintStream(OutputStream out, boolean autoFlush, String encoding)
throws UnsupportedEncodingException
{
- this(autoFlush, out);
- init(new OutputStreamWriter(this, encoding));
+ this(autoFlush,
+ nonNull(out, "Null output stream"),
+ toCharset(encoding));
}
/**
@@ -171,7 +206,6 @@ public class PrintStream extends FilterOutputStream
*/
public PrintStream(String fileName) throws FileNotFoundException {
this(false, new FileOutputStream(fileName));
- init(new OutputStreamWriter(this));
}
/**
@@ -210,8 +244,8 @@ public class PrintStream extends FilterOutputStream
public PrintStream(String fileName, String csn)
throws FileNotFoundException, UnsupportedEncodingException
{
- this(false, new FileOutputStream(fileName));
- init(new OutputStreamWriter(this, csn));
+ // ensure charset is checked before the file is opened
+ this(false, toCharset(csn), new FileOutputStream(fileName));
}
/**
@@ -243,7 +277,6 @@ public class PrintStream extends FilterOutputStream
*/
public PrintStream(File file) throws FileNotFoundException {
this(false, new FileOutputStream(file));
- init(new OutputStreamWriter(this));
}
/**
@@ -282,8 +315,8 @@ public class PrintStream extends FilterOutputStream
public PrintStream(File file, String csn)
throws FileNotFoundException, UnsupportedEncodingException
{
- this(false, new FileOutputStream(file));
- init(new OutputStreamWriter(this, csn));
+ // ensure charset is checked before the file is opened
+ this(false, toCharset(csn), new FileOutputStream(file));
}
/** Check to make sure that the stream has not been closed */
diff --git a/jdk/src/share/classes/java/io/PrintWriter.java b/jdk/src/share/classes/java/io/PrintWriter.java
index afce0f89d4d..16044567065 100644
--- a/jdk/src/share/classes/java/io/PrintWriter.java
+++ b/jdk/src/share/classes/java/io/PrintWriter.java
@@ -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
@@ -25,8 +25,12 @@
package java.io;
+import java.util.Objects;
import java.util.Formatter;
import java.util.Locale;
+import java.nio.charset.Charset;
+import java.nio.charset.IllegalCharsetNameException;
+import java.nio.charset.UnsupportedCharsetException;
/**
* Prints formatted representations of objects to a text-output stream. This
@@ -59,7 +63,7 @@ public class PrintWriter extends Writer {
*/
protected Writer out;
- private boolean autoFlush = false;
+ private final boolean autoFlush;
private boolean trouble = false;
private Formatter formatter;
private PrintStream psOut = null;
@@ -68,7 +72,24 @@ public class PrintWriter extends Writer {
* Line separator string. This is the value of the line.separator
* property at the moment that the stream was created.
*/
- private String lineSeparator;
+ private final String lineSeparator;
+
+ /**
+ * 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);
+ }
+ }
/**
* Creates a new PrintWriter, without automatic line flushing.
@@ -164,6 +185,14 @@ public class PrintWriter extends Writer {
false);
}
+ /* Private constructor */
+ private PrintWriter(Charset charset, File file)
+ throws FileNotFoundException
+ {
+ this(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), charset)),
+ false);
+ }
+
/**
* Creates a new PrintWriter, without automatic line flushing, with the
* specified file name and charset. This convenience constructor creates
@@ -200,8 +229,7 @@ public class PrintWriter extends Writer {
public PrintWriter(String fileName, String csn)
throws FileNotFoundException, UnsupportedEncodingException
{
- this(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), csn)),
- false);
+ this(toCharset(csn), new File(fileName));
}
/**
@@ -272,8 +300,7 @@ public class PrintWriter extends Writer {
public PrintWriter(File file, String csn)
throws FileNotFoundException, UnsupportedEncodingException
{
- this(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), csn)),
- false);
+ this(toCharset(csn), file);
}
/** Checks to make sure that the stream has not been closed */
diff --git a/jdk/src/share/classes/java/lang/AutoCloseable.java b/jdk/src/share/classes/java/lang/AutoCloseable.java
index a44f5840cd7..f18de8cd5fb 100644
--- a/jdk/src/share/classes/java/lang/AutoCloseable.java
+++ b/jdk/src/share/classes/java/lang/AutoCloseable.java
@@ -1,5 +1,5 @@
/*
- * 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
@@ -33,7 +33,7 @@ package java.lang;
*/
public interface AutoCloseable {
/**
- * Close this resource, relinquishing any underlying resources.
+ * Closes this resource, relinquishing any underlying resources.
* This method is invoked automatically by the {@code
* try}-with-resources statement.
*
@@ -48,6 +48,10 @@ public interface AutoCloseable {
* visible side effect, unlike {@code Closeable.close} which is
* required to have no effect if called more than once.
*
+ * However, while not required to be idempotent, implementers of
+ * this interface are strongly encouraged to make their {@code
+ * close} methods idempotent.
+ *
* @throws Exception if this resource cannot be closed
*/
void close() throws Exception;
diff --git a/jdk/src/share/classes/java/lang/StringCoding.java b/jdk/src/share/classes/java/lang/StringCoding.java
index 42849479fcc..4043d5d2a89 100644
--- a/jdk/src/share/classes/java/lang/StringCoding.java
+++ b/jdk/src/share/classes/java/lang/StringCoding.java
@@ -67,7 +67,7 @@ class StringCoding {
}
private static void set(ThreadLocal