From cd65f6f9739f4bf09fa9e14433acc203ec3c907f Mon Sep 17 00:00:00 2001 From: Xue-Lei Andrew Fan Date: Thu, 29 Aug 2013 18:58:18 -0700 Subject: [PATCH 001/210] 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII Reviewed-by: michaelm --- jdk/src/share/classes/java/net/IDN.java | 40 +++++----- jdk/test/java/net/IDN/UseSTD3ASCIIRules.java | 80 ++++++++++++++++++++ 2 files changed, 99 insertions(+), 21 deletions(-) create mode 100644 jdk/test/java/net/IDN/UseSTD3ASCIIRules.java diff --git a/jdk/src/share/classes/java/net/IDN.java b/jdk/src/share/classes/java/net/IDN.java index ed2f3a38159..34642b9824c 100644 --- a/jdk/src/share/classes/java/net/IDN.java +++ b/jdk/src/share/classes/java/net/IDN.java @@ -292,13 +292,17 @@ public final class IDN { if (useSTD3ASCIIRules) { for (int i = 0; i < dest.length(); i++) { int c = dest.charAt(i); - if (!isLDHChar(c)) { - throw new IllegalArgumentException("Contains non-LDH characters"); + if (isNonLDHAsciiCodePoint(c)) { + throw new IllegalArgumentException( + "Contains non-LDH ASCII characters"); } } - if (dest.charAt(0) == '-' || dest.charAt(dest.length() - 1) == '-') { - throw new IllegalArgumentException("Has leading or trailing hyphen"); + if (dest.charAt(0) == '-' || + dest.charAt(dest.length() - 1) == '-') { + + throw new IllegalArgumentException( + "Has leading or trailing hyphen"); } } @@ -401,26 +405,20 @@ public final class IDN { // // LDH stands for "letter/digit/hyphen", with characters restricted to the // 26-letter Latin alphabet , the digits <0-9>, and the hyphen - // <-> - // non-LDH = 0..0x2C, 0x2E..0x2F, 0x3A..0x40, 0x56..0x60, 0x7B..0x7F + // <->. + // Non LDH refers to characters in the ASCII range, but which are not + // letters, digits or the hypen. // - private static boolean isLDHChar(int ch){ - // high runner case - if(ch > 0x007A){ - return false; - } - //['-' '0'..'9' 'A'..'Z' 'a'..'z'] - if((ch == 0x002D) || - (0x0030 <= ch && ch <= 0x0039) || - (0x0041 <= ch && ch <= 0x005A) || - (0x0061 <= ch && ch <= 0x007A) - ){ - return true; - } - return false; + // non-LDH = 0..0x2C, 0x2E..0x2F, 0x3A..0x40, 0x5B..0x60, 0x7B..0x7F + // + private static boolean isNonLDHAsciiCodePoint(int ch){ + return (0x0000 <= ch && ch <= 0x002C) || + (0x002E <= ch && ch <= 0x002F) || + (0x003A <= ch && ch <= 0x0040) || + (0x005B <= ch && ch <= 0x0060) || + (0x007B <= ch && ch <= 0x007F); } - // // search dots in a string and return the index of that character; // or if there is no dots, return the length of input string diff --git a/jdk/test/java/net/IDN/UseSTD3ASCIIRules.java b/jdk/test/java/net/IDN/UseSTD3ASCIIRules.java new file mode 100644 index 00000000000..0afc4a912ca --- /dev/null +++ b/jdk/test/java/net/IDN/UseSTD3ASCIIRules.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2013, 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 8023881 + * @summary IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode + * in IDN.toASCII + */ + +import java.net.*; + +public class UseSTD3ASCIIRules { + + public static void main(String[] args) throws Exception { + // Per Section 4.1, RFC 3490, if the UseSTD3ASCIIRules flag is set, + // then perform these checks: + // + // (a) Verify the absence of non-LDH ASCII code points; that is, the + // absence of 0..2C, 2E..2F, 3A..40, 5B..60, and 7B..7F. + // + // (b) Verify the absence of leading and trailing hyphen-minus; that + // is, the absence of U+002D at the beginning and end of the + // sequence. + String[] illegalNames = { + "www.example.com-", + "-www.example.com", + "-www.example.com-", + "www.ex\u002Cmple.com", + "www.ex\u007Bmple.com", + "www.ex\u007Fmple.com" + }; + + String[] legalNames = { + "www.ex-ample.com", + "www.ex\u002Dmple.com", // www.ex-mple.com + "www.ex\u007Ample.com", // www.exzmple.com + "www.ex\u3042mple.com", // www.xn--exmple-j43e.com + "www.\u3042\u3044\u3046.com", // www.xn--l8jeg.com + "www.\u793A\u4F8B.com" // www.xn--fsq092h.com + }; + + for (String name : illegalNames) { + try { + System.out.println("Convering illegal IDN: " + name); + IDN.toASCII(name, IDN.USE_STD3_ASCII_RULES); + throw new Exception( + "Expected to get IllegalArgumentException for " + name); + } catch (IllegalArgumentException iae) { + // That's the right behavior. + } + } + + for (String name : legalNames) { + System.out.println("Convering legal IDN: " + name); + System.out.println("\tThe ACE form is: " + + IDN.toASCII(name, IDN.USE_STD3_ASCII_RULES)); + } + } +} From dbca0a2b8590e59b65e4bb9adfff1d92d96f3757 Mon Sep 17 00:00:00 2001 From: Shanliang Jiang Date: Fri, 30 Aug 2013 12:49:41 +0200 Subject: [PATCH 002/210] 6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed Reviewed-by: egahlin, jbachorik, dfuchs, dholmes --- .../management/remote/rmi/RMIConnector.java | 33 +++-- .../RMIConnectorInternalMapTest.java | 122 ++++++++++++++++++ .../RMIConnectorNullSubjectConnTest.java | 105 +++++++++++++++ 3 files changed, 250 insertions(+), 10 deletions(-) create mode 100644 jdk/test/javax/management/remote/mandatory/connection/RMIConnectorInternalMapTest.java create mode 100644 jdk/test/javax/management/remote/mandatory/connection/RMIConnectorNullSubjectConnTest.java diff --git a/jdk/src/share/classes/javax/management/remote/rmi/RMIConnector.java b/jdk/src/share/classes/javax/management/remote/rmi/RMIConnector.java index 53e6754e6ed..4868b94b2ff 100644 --- a/jdk/src/share/classes/javax/management/remote/rmi/RMIConnector.java +++ b/jdk/src/share/classes/javax/management/remote/rmi/RMIConnector.java @@ -405,14 +405,7 @@ public class RMIConnector implements JMXConnector, Serializable, JMXAddressable throw new IOException("Not connected"); } - MBeanServerConnection rmbsc = rmbscMap.get(delegationSubject); - if (rmbsc != null) { - return rmbsc; - } - - rmbsc = new RemoteMBeanServerConnection(delegationSubject); - rmbscMap.put(delegationSubject, rmbsc); - return rmbsc; + return getConnectionWithSubject(delegationSubject); } public void @@ -1831,7 +1824,7 @@ public class RMIConnector implements JMXConnector, Serializable, JMXAddressable // Initialization of transient variables. private void initTransients() { - rmbscMap = new WeakHashMap(); + rmbscMap = new WeakHashMap>(); connected = false; terminated = false; @@ -2011,6 +2004,25 @@ public class RMIConnector implements JMXConnector, Serializable, JMXAddressable private final ClassLoader loader; } + private MBeanServerConnection getConnectionWithSubject(Subject delegationSubject) { + MBeanServerConnection conn = null; + + if (delegationSubject == null) { + if (nullSubjectConnRef == null + || (conn = nullSubjectConnRef.get()) == null) { + conn = new RemoteMBeanServerConnection(null); + nullSubjectConnRef = new WeakReference(conn); + } + } else { + WeakReference wr = rmbscMap.get(delegationSubject); + if (wr == null || (conn = wr.get()) == null) { + conn = new RemoteMBeanServerConnection(delegationSubject); + rmbscMap.put(delegationSubject, new WeakReference(conn)); + } + } + return conn; + } + /* The following section of code avoids a class loading problem with RMI. The problem is that an RMI stub, when deserializing @@ -2551,7 +2563,8 @@ public class RMIConnector implements JMXConnector, Serializable, JMXAddressable private transient long clientNotifSeqNo = 0; - private transient WeakHashMap rmbscMap; + private transient WeakHashMap> rmbscMap; + private transient WeakReference nullSubjectConnRef = null; private transient RMINotifClient rmiNotifClient; // = new RMINotifClient(new Integer(0)); diff --git a/jdk/test/javax/management/remote/mandatory/connection/RMIConnectorInternalMapTest.java b/jdk/test/javax/management/remote/mandatory/connection/RMIConnectorInternalMapTest.java new file mode 100644 index 00000000000..86efed134f3 --- /dev/null +++ b/jdk/test/javax/management/remote/mandatory/connection/RMIConnectorInternalMapTest.java @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2013, 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.lang.management.ManagementFactory; +import java.lang.ref.WeakReference; +import java.lang.reflect.Field; +import java.util.Collections; +import java.util.Map; +import javax.management.MBeanServer; +import javax.management.MBeanServerConnection; +import javax.management.remote.JMXConnector; +import javax.management.remote.JMXConnectorFactory; +import javax.management.remote.JMXConnectorServer; +import javax.management.remote.JMXConnectorServerFactory; +import javax.management.remote.JMXPrincipal; +import javax.management.remote.JMXServiceURL; +import javax.management.remote.rmi.RMIConnector; +import javax.security.auth.Subject; + +/* + * @test + * @bug 6566891 + * @summary Check no memory leak on RMIConnector's rmbscMap + * @author Shanliang JIANG + * @run clean RMIConnectorInternalMapTest + * @run build RMIConnectorInternalMapTest + * @run main RMIConnectorInternalMapTest + */ + +public class RMIConnectorInternalMapTest { + public static void main(String[] args) throws Exception { + System.out.println("---RMIConnectorInternalMapTest starting..."); + + JMXConnectorServer connectorServer = null; + JMXConnector connectorClient = null; + + try { + MBeanServer mserver = ManagementFactory.getPlatformMBeanServer(); + JMXServiceURL serverURL = new JMXServiceURL("rmi", "localhost", 0); + connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(serverURL, null, mserver); + connectorServer.start(); + + JMXServiceURL serverAddr = connectorServer.getAddress(); + connectorClient = JMXConnectorFactory.connect(serverAddr, null); + connectorClient.connect(); + + Field rmbscMapField = RMIConnector.class.getDeclaredField("rmbscMap"); + rmbscMapField.setAccessible(true); + Map> map = + (Map>) rmbscMapField.get(connectorClient); + if (map != null && !map.isEmpty()) { // failed + throw new RuntimeException("RMIConnector's rmbscMap must be empty at the initial time."); + } + + Subject delegationSubject = + new Subject(true, + Collections.singleton(new JMXPrincipal("delegate")), + Collections.EMPTY_SET, + Collections.EMPTY_SET); + MBeanServerConnection mbsc1 = + connectorClient.getMBeanServerConnection(delegationSubject); + MBeanServerConnection mbsc2 = + connectorClient.getMBeanServerConnection(delegationSubject); + + if (mbsc1 == null) { + throw new RuntimeException("Got null connection."); + } + if (mbsc1 != mbsc2) { + throw new RuntimeException("Not got same connection with a same subject."); + } + + map = (Map>) rmbscMapField.get(connectorClient); + if (map == null || map.isEmpty()) { // failed + throw new RuntimeException("RMIConnector's rmbscMap has wrong size " + + "after creating a delegated connection."); + } + + delegationSubject = null; + mbsc1 = null; + mbsc2 = null; + + int i = 0; + while (!map.isEmpty() && i++ < 60) { + System.gc(); + Thread.sleep(100); + } + System.out.println("---GC times: " + i); + + if (!map.isEmpty()) { + throw new RuntimeException("Failed to clean RMIConnector's rmbscMap"); + } else { + System.out.println("---RMIConnectorInternalMapTest: PASSED!"); + } + } finally { + try { + connectorClient.close(); + connectorServer.stop(); + } catch (Exception e) { + } + } + } +} diff --git a/jdk/test/javax/management/remote/mandatory/connection/RMIConnectorNullSubjectConnTest.java b/jdk/test/javax/management/remote/mandatory/connection/RMIConnectorNullSubjectConnTest.java new file mode 100644 index 00000000000..7b5224e9b92 --- /dev/null +++ b/jdk/test/javax/management/remote/mandatory/connection/RMIConnectorNullSubjectConnTest.java @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2013, 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.lang.management.ManagementFactory; +import java.lang.ref.WeakReference; +import java.lang.reflect.Field; +import javax.management.MBeanServer; +import javax.management.MBeanServerConnection; +import javax.management.remote.JMXConnector; +import javax.management.remote.JMXConnectorFactory; +import javax.management.remote.JMXConnectorServer; +import javax.management.remote.JMXConnectorServerFactory; +import javax.management.remote.JMXServiceURL; +import javax.management.remote.rmi.RMIConnector; + +/* + * @test + * @bug 6566891 + * @summary Check no memory leak on RMIConnector's nullSubjectConn + * @author Shanliang JIANG + * @run clean RMIConnectorNullSubjectConnTest + * @run build RMIConnectorNullSubjectConnTest + * @run main RMIConnectorNullSubjectConnTest + */ + +public class RMIConnectorNullSubjectConnTest { + public static void main(String[] args) throws Exception { + System.out.println("---RMIConnectorNullSubjectConnTest starting..."); + + JMXConnectorServer connectorServer = null; + JMXConnector connectorClient = null; + + try { + MBeanServer mserver = ManagementFactory.getPlatformMBeanServer(); + JMXServiceURL serverURL = new JMXServiceURL("rmi", "localhost", 0); + connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(serverURL, null, mserver); + connectorServer.start(); + + JMXServiceURL serverAddr = connectorServer.getAddress(); + connectorClient = JMXConnectorFactory.connect(serverAddr, null); + connectorClient.connect(); + + Field nullSubjectConnField = RMIConnector.class.getDeclaredField("nullSubjectConnRef"); + nullSubjectConnField.setAccessible(true); + + WeakReference weak = + (WeakReference)nullSubjectConnField.get(connectorClient); + + if (weak != null && weak.get() != null) { + throw new RuntimeException("nullSubjectConnRef must be null at initial time."); + } + + MBeanServerConnection conn1 = connectorClient.getMBeanServerConnection(null); + MBeanServerConnection conn2 = connectorClient.getMBeanServerConnection(null); + if (conn1 == null) { + throw new RuntimeException("A connection with null subject should not be null."); + } else if (conn1 != conn2) { + throw new RuntimeException("The 2 connections with null subject are not equal."); + } + + conn1 = null; + conn2 = null; + int i = 1; + do { + System.gc(); + Thread.sleep(100); + weak = (WeakReference)nullSubjectConnField.get(connectorClient); + } while ((weak != null && weak.get() != null) && i++ < 60); + + System.out.println("---GC times: " + i); + + if (weak != null && weak.get() != null) { + throw new RuntimeException("Failed to clean RMIConnector's nullSubjectConn"); + } else { + System.out.println("---RMIConnectorNullSubjectConnTest: PASSED!"); + } + } finally { + try { + connectorClient.close(); + connectorServer.stop(); + } catch (Exception e) { + } + } + } +} From d6854baa4e31c6d02fa25ca51e6d8dd1b539e6ea Mon Sep 17 00:00:00 2001 From: Dan Xu Date: Fri, 30 Aug 2013 16:45:45 -0700 Subject: [PATCH 003/210] 8023765: Improve MaxPathLength.java testcase and reduce its test load 7160013: java/io/File/MaxPathLength.java fails Reviewed-by: alanb --- jdk/test/ProblemList.txt | 7 --- jdk/test/java/io/File/MaxPathLength.java | 67 ++++++++++++++---------- 2 files changed, 39 insertions(+), 35 deletions(-) diff --git a/jdk/test/ProblemList.txt b/jdk/test/ProblemList.txt index 1f594fe3d3b..26c4eb54a55 100644 --- a/jdk/test/ProblemList.txt +++ b/jdk/test/ProblemList.txt @@ -205,13 +205,6 @@ sun/net/www/http/HttpClient/ProxyTest.java generic-all ############################################################################ -# jdk_io - -# 7160013 -#java/io/File/MaxPathLength.java windows-all - -############################################################################ - # jdk_nio # 6963118 diff --git a/jdk/test/java/io/File/MaxPathLength.java b/jdk/test/java/io/File/MaxPathLength.java index 7ec379cf1d1..9fd6183f36d 100644 --- a/jdk/test/java/io/File/MaxPathLength.java +++ b/jdk/test/java/io/File/MaxPathLength.java @@ -22,7 +22,7 @@ */ /* @test - @bug 4759207 4403166 4165006 4403166 6182812 6274272 + @bug 4759207 4403166 4165006 4403166 6182812 6274272 7160013 @summary Test to see if win32 path length can be greater than 260 */ @@ -37,6 +37,10 @@ public class MaxPathLength { "areallylongfilenamethatsforsur"; private static boolean isWindows = false; + private final static int MAX_LENGTH = 256; + + private static int counter = 0; + public static void main(String[] args) throws Exception { String osName = System.getProperty("os.name"); if (osName.startsWith("Windows")) { @@ -45,33 +49,39 @@ public class MaxPathLength { for (int i = 4; i < 7; i++) { String name = fileName; - while (name.length() < 256) { + while (name.length() < MAX_LENGTH) { testLongPath (i, name, false); testLongPath (i, name, true); - name += "A"; + name = getNextName(name); } } // test long paths on windows + // And these long pathes cannot be handled on Solaris and Mac platforms if (isWindows) { String name = fileName; - while (name.length() < 256) { + while (name.length() < MAX_LENGTH) { testLongPath (20, name, false); testLongPath (20, name, true); - name += "A"; + name = getNextName(name); } } } + private static String getNextName(String fName) { + return (fName.length() < MAX_LENGTH/2) ? fName + fName + : fName + "A"; + } + static void testLongPath(int max, String fn, boolean tryAbsolute) throws Exception { String[] created = new String[max]; String pathString = "."; for (int i = 0; i < max -1; i++) { - pathString = pathString + pathComponent; + pathString = pathString + pathComponent + (counter++); created[max - 1 -i] = pathString; - } + File dirFile = new File(pathString); File f = new File(pathString + sep + fn); @@ -88,9 +98,10 @@ public class MaxPathLength { System.err.println("Warning: Test directory structure exists already!"); return; } - Files.createDirectories(dirFile.toPath()); try { + Files.createDirectories(dirFile.toPath()); + if (tryAbsolute) dirFile = new File(dirFile.getCanonicalPath()); if (!dirFile.isDirectory()) @@ -99,6 +110,7 @@ public class MaxPathLength { if (!f.createNewFile()) { throw new RuntimeException ("File.createNewFile() failed"); } + if (!f.exists()) throw new RuntimeException ("File.exists() failed"); if (!f.isFile()) @@ -107,11 +119,14 @@ public class MaxPathLength { throw new RuntimeException ("File.canRead() failed"); if (!f.canWrite()) throw new RuntimeException ("File.canWrite() failed"); + if (!f.delete()) throw new RuntimeException ("File.delete() failed"); + FileOutputStream fos = new FileOutputStream(f); fos.write(1); fos.close(); + if (f.length() != 1) throw new RuntimeException ("File.length() failed"); long time = System.currentTimeMillis(); @@ -148,30 +163,26 @@ public class MaxPathLength { throw new RuntimeException ("File.renameTo() failed for lenth=" + abPath.length()); } - return; + } else { + if (!nf.canRead()) + throw new RuntimeException ("Renamed file is not readable"); + if (!nf.canWrite()) + throw new RuntimeException ("Renamed file is not writable"); + if (nf.length() != 1) + throw new RuntimeException ("Renamed file's size is not correct"); + if (!nf.renameTo(f)) { + created[0] = nf.getPath(); + } + /* add a script to test these two if we got a regression later + if (!f.setReadOnly()) + throw new RuntimeException ("File.setReadOnly() failed"); + f.deleteOnExit(); + */ } - if (!nf.canRead()) - throw new RuntimeException ("Renamed file is not readable"); - if (!nf.canWrite()) - throw new RuntimeException ("Renamed file is not writable"); - if (nf.length() != 1) - throw new RuntimeException ("Renamed file's size is not correct"); - nf.renameTo(f); - /* add a script to test these two if we got a regression later - if (!f.setReadOnly()) - throw new RuntimeException ("File.setReadOnly() failed"); - f.deleteOnExit(); - */ } finally { // Clean up for (int i = 0; i < max; i++) { - pathString = created[i]; - // Only works with completex canonical paths - File df = new File(pathString); - pathString = df.getCanonicalPath(); - df = new File(pathString); - if (!df.delete()) - System.out.printf("Delete failed->%s\n", pathString); + Files.deleteIfExists((new File(created[i])).toPath()); } } } From 1cff90b3353b16370bd7784ab1f2dd52367d3d1f Mon Sep 17 00:00:00 2001 From: Xue-Lei Andrew Fan Date: Sun, 1 Sep 2013 20:00:03 -0700 Subject: [PATCH 004/210] 8024068: sun/security/ssl/javax/net/ssl/ServerName/IllegalSNIName.java fails Reviewed-by: weijun --- .../security/ssl/javax/net/ssl/ServerName/IllegalSNIName.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jdk/test/sun/security/ssl/javax/net/ssl/ServerName/IllegalSNIName.java b/jdk/test/sun/security/ssl/javax/net/ssl/ServerName/IllegalSNIName.java index 4d5460739cd..a6a6912c0aa 100644 --- a/jdk/test/sun/security/ssl/javax/net/ssl/ServerName/IllegalSNIName.java +++ b/jdk/test/sun/security/ssl/javax/net/ssl/ServerName/IllegalSNIName.java @@ -34,7 +34,7 @@ public class IllegalSNIName { public static void main(String[] args) throws Exception { String[] illegalNames = { - "example\u3003\u3002com", + "example\u3002\u3002com", "example..com", "com\u3002", "com.", From ff0317b09805c47be8bf6a09cc07150c2dcea4e6 Mon Sep 17 00:00:00 2001 From: Chris Hegarty Date: Mon, 2 Sep 2013 14:02:35 +0100 Subject: [PATCH 005/210] 8024103: AtomicLongArray getAndAccumulate/accumulateAndGet have int type for new value arg Reviewed-by: alanb, psandoz --- .../classes/java/util/concurrent/atomic/AtomicLongArray.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jdk/src/share/classes/java/util/concurrent/atomic/AtomicLongArray.java b/jdk/src/share/classes/java/util/concurrent/atomic/AtomicLongArray.java index bf7aa6ecca8..28174a586ff 100644 --- a/jdk/src/share/classes/java/util/concurrent/atomic/AtomicLongArray.java +++ b/jdk/src/share/classes/java/util/concurrent/atomic/AtomicLongArray.java @@ -303,7 +303,7 @@ public class AtomicLongArray implements java.io.Serializable { * @return the previous value * @since 1.8 */ - public final long getAndAccumulate(int i, int x, + public final long getAndAccumulate(int i, long x, LongBinaryOperator accumulatorFunction) { long offset = checkedByteOffset(i); long prev, next; @@ -329,7 +329,7 @@ public class AtomicLongArray implements java.io.Serializable { * @return the updated value * @since 1.8 */ - public final long accumulateAndGet(int i, int x, + public final long accumulateAndGet(int i, long x, LongBinaryOperator accumulatorFunction) { long offset = checkedByteOffset(i); long prev, next; From b81e7785d1fd24ed0833d7b14b04a9383734cfcd Mon Sep 17 00:00:00 2001 From: Daniel Fuchs Date: Mon, 2 Sep 2013 18:28:50 +0200 Subject: [PATCH 006/210] 8016127: NLS: logging.properties translatability recommendation 8024131: Issues with cached localizedLevelName in java.util.logging.Level This fix updates logging.properties resource bundles to follow internationalization guidelines. It also fixes a caching issue with localizedLevelName. The regression test that was added needs both fixes to pass. Reviewed-by: mchung, alanb --- .../classes/java/util/logging/Level.java | 72 +++++++++++- .../util/logging/resources/logging.properties | 18 +-- .../logging/resources/logging_de.properties | 18 +-- .../logging/resources/logging_es.properties | 18 +-- .../logging/resources/logging_fr.properties | 18 +-- .../logging/resources/logging_it.properties | 18 +-- .../logging/resources/logging_ja.properties | 12 +- .../logging/resources/logging_ko.properties | 18 +-- .../resources/logging_pt_BR.properties | 18 +-- .../logging/resources/logging_sv.properties | 18 +-- .../resources/logging_zh_CN.properties | 18 +-- .../resources/logging_zh_TW.properties | 12 +- .../java/util/logging/LocalizedLevelName.java | 103 ++++++++++++++++++ 13 files changed, 262 insertions(+), 99 deletions(-) create mode 100644 jdk/test/java/util/logging/LocalizedLevelName.java diff --git a/jdk/src/share/classes/java/util/logging/Level.java b/jdk/src/share/classes/java/util/logging/Level.java index 6847518ce02..936925624e4 100644 --- a/jdk/src/share/classes/java/util/logging/Level.java +++ b/jdk/src/share/classes/java/util/logging/Level.java @@ -27,6 +27,7 @@ package java.util.logging; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.ResourceBundle; @@ -63,7 +64,7 @@ import java.util.ResourceBundle; */ public class Level implements java.io.Serializable { - private static String defaultBundle = "sun.util.logging.resources.logging"; + private static final String defaultBundle = "sun.util.logging.resources.logging"; /** * @serial The non-localized name of the level. @@ -81,7 +82,8 @@ public class Level implements java.io.Serializable { private final String resourceBundleName; // localized level name - private String localizedLevelName; + private transient String localizedLevelName; + private transient Locale cachedLocale; /** * OFF is a special level that can be used to turn off logging. @@ -209,6 +211,7 @@ public class Level implements java.io.Serializable { this.value = value; this.resourceBundleName = resourceBundleName; this.localizedLevelName = resourceBundleName == null ? name : null; + this.cachedLocale = null; KnownLevel.add(this); } @@ -250,17 +253,71 @@ public class Level implements java.io.Serializable { return this.name; } - final synchronized String getLocalizedLevelName() { + private String computeLocalizedLevelName(Locale newLocale) { + ResourceBundle rb = ResourceBundle.getBundle(resourceBundleName, newLocale); + final String localizedName = rb.getString(name); + + final boolean isDefaultBundle = defaultBundle.equals(resourceBundleName); + if (!isDefaultBundle) return localizedName; + + // This is a trick to determine whether the name has been translated + // or not. If it has not been translated, we need to use Locale.ROOT + // when calling toUpperCase(). + final Locale rbLocale = rb.getLocale(); + final Locale locale = + Locale.ROOT.equals(rbLocale) + || name.equals(localizedName.toUpperCase(Locale.ROOT)) + ? Locale.ROOT : rbLocale; + + // ALL CAPS in a resource bundle's message indicates no translation + // needed per Oracle translation guideline. To workaround this + // in Oracle JDK implementation, convert the localized level name + // to uppercase for compatibility reason. + return Locale.ROOT.equals(locale) ? name : localizedName.toUpperCase(locale); + } + + // Avoid looking up the localizedLevelName twice if we already + // have it. + final String getCachedLocalizedLevelName() { + if (localizedLevelName != null) { - return localizedLevelName; + if (cachedLocale != null) { + if (cachedLocale.equals(Locale.getDefault())) { + // OK: our cached value was looked up with the same + // locale. We can use it. + return localizedLevelName; + } + } } + if (resourceBundleName == null) { + // No resource bundle: just use the name. + return name; + } + + // We need to compute the localized name. + // Either because it's the first time, or because our cached + // value is for a different locale. Just return null. + return null; + } + + final synchronized String getLocalizedLevelName() { + + // See if we have a cached localized name + final String cachedLocalizedName = getCachedLocalizedLevelName(); + if (cachedLocalizedName != null) { + return cachedLocalizedName; + } + + // No cached localized name or cache invalid. + // Need to compute the localized name. + final Locale newLocale = Locale.getDefault(); try { - ResourceBundle rb = ResourceBundle.getBundle(resourceBundleName); - localizedLevelName = rb.getString(name); + localizedLevelName = computeLocalizedLevelName(newLocale); } catch (Exception ex) { localizedLevelName = name; } + cachedLocale = newLocale; return localizedLevelName; } @@ -318,6 +375,7 @@ public class Level implements java.io.Serializable { * * @return the non-localized name of the Level, for example "INFO". */ + @Override public final String toString() { return name; } @@ -420,6 +478,7 @@ public class Level implements java.io.Serializable { * Compare two objects for value equality. * @return true if and only if the two objects have the same level value. */ + @Override public boolean equals(Object ox) { try { Level lx = (Level)ox; @@ -433,6 +492,7 @@ public class Level implements java.io.Serializable { * Generate a hashcode. * @return a hashcode based on the level value */ + @Override public int hashCode() { return this.value; } diff --git a/jdk/src/share/classes/sun/util/logging/resources/logging.properties b/jdk/src/share/classes/sun/util/logging/resources/logging.properties index da17c47f8fd..248b4d7fcbe 100644 --- a/jdk/src/share/classes/sun/util/logging/resources/logging.properties +++ b/jdk/src/share/classes/sun/util/logging/resources/logging.properties @@ -27,20 +27,20 @@ # these are the same as the non-localized level name. # The following ALL CAPS words should be translated. -ALL=ALL +ALL=All # The following ALL CAPS words should be translated. -SEVERE=SEVERE +SEVERE=Severe # The following ALL CAPS words should be translated. -WARNING=WARNING +WARNING=Warning # The following ALL CAPS words should be translated. -INFO=INFO +INFO=Info # The following ALL CAPS words should be translated. -CONFIG= CONFIG +CONFIG= Config # The following ALL CAPS words should be translated. -FINE=FINE +FINE=Fine # The following ALL CAPS words should be translated. -FINER=FINER +FINER=Finer # The following ALL CAPS words should be translated. -FINEST=FINEST +FINEST=Finest # The following ALL CAPS words should be translated. -OFF=OFF +OFF=Off diff --git a/jdk/src/share/classes/sun/util/logging/resources/logging_de.properties b/jdk/src/share/classes/sun/util/logging/resources/logging_de.properties index da17c47f8fd..1aa8ef4e22c 100644 --- a/jdk/src/share/classes/sun/util/logging/resources/logging_de.properties +++ b/jdk/src/share/classes/sun/util/logging/resources/logging_de.properties @@ -27,20 +27,20 @@ # these are the same as the non-localized level name. # The following ALL CAPS words should be translated. -ALL=ALL +ALL=Alle # The following ALL CAPS words should be translated. -SEVERE=SEVERE +SEVERE=Schwerwiegend # The following ALL CAPS words should be translated. -WARNING=WARNING +WARNING=Warnung # The following ALL CAPS words should be translated. -INFO=INFO +INFO=Information # The following ALL CAPS words should be translated. -CONFIG= CONFIG +CONFIG= Konfiguration # The following ALL CAPS words should be translated. -FINE=FINE +FINE=Fein # The following ALL CAPS words should be translated. -FINER=FINER +FINER=Feiner # The following ALL CAPS words should be translated. -FINEST=FINEST +FINEST=Am feinsten # The following ALL CAPS words should be translated. -OFF=OFF +OFF=Deaktiviert diff --git a/jdk/src/share/classes/sun/util/logging/resources/logging_es.properties b/jdk/src/share/classes/sun/util/logging/resources/logging_es.properties index da17c47f8fd..90de2e88238 100644 --- a/jdk/src/share/classes/sun/util/logging/resources/logging_es.properties +++ b/jdk/src/share/classes/sun/util/logging/resources/logging_es.properties @@ -27,20 +27,20 @@ # these are the same as the non-localized level name. # The following ALL CAPS words should be translated. -ALL=ALL +ALL=Todo # The following ALL CAPS words should be translated. -SEVERE=SEVERE +SEVERE=Grave # The following ALL CAPS words should be translated. -WARNING=WARNING +WARNING=Advertencia # The following ALL CAPS words should be translated. -INFO=INFO +INFO=Informaci\u00F3n # The following ALL CAPS words should be translated. -CONFIG= CONFIG +CONFIG= Configurar # The following ALL CAPS words should be translated. -FINE=FINE +FINE=Detallado # The following ALL CAPS words should be translated. -FINER=FINER +FINER=Muy Detallado # The following ALL CAPS words should be translated. -FINEST=FINEST +FINEST=M\u00E1s Detallado # The following ALL CAPS words should be translated. -OFF=OFF +OFF=Desactivado diff --git a/jdk/src/share/classes/sun/util/logging/resources/logging_fr.properties b/jdk/src/share/classes/sun/util/logging/resources/logging_fr.properties index da17c47f8fd..af34d6fa414 100644 --- a/jdk/src/share/classes/sun/util/logging/resources/logging_fr.properties +++ b/jdk/src/share/classes/sun/util/logging/resources/logging_fr.properties @@ -27,20 +27,20 @@ # these are the same as the non-localized level name. # The following ALL CAPS words should be translated. -ALL=ALL +ALL=Tout # The following ALL CAPS words should be translated. -SEVERE=SEVERE +SEVERE=Grave # The following ALL CAPS words should be translated. -WARNING=WARNING +WARNING=Avertissement # The following ALL CAPS words should be translated. -INFO=INFO +INFO=Infos # The following ALL CAPS words should be translated. -CONFIG= CONFIG +CONFIG= Config # The following ALL CAPS words should be translated. -FINE=FINE +FINE=Pr\u00E9cis # The following ALL CAPS words should be translated. -FINER=FINER +FINER=Plus pr\u00E9cis # The following ALL CAPS words should be translated. -FINEST=FINEST +FINEST=Le plus pr\u00E9cis # The following ALL CAPS words should be translated. -OFF=OFF +OFF=D\u00E9sactiv\u00E9 diff --git a/jdk/src/share/classes/sun/util/logging/resources/logging_it.properties b/jdk/src/share/classes/sun/util/logging/resources/logging_it.properties index da17c47f8fd..73a3b5c59cf 100644 --- a/jdk/src/share/classes/sun/util/logging/resources/logging_it.properties +++ b/jdk/src/share/classes/sun/util/logging/resources/logging_it.properties @@ -27,20 +27,20 @@ # these are the same as the non-localized level name. # The following ALL CAPS words should be translated. -ALL=ALL +ALL=Tutto # The following ALL CAPS words should be translated. -SEVERE=SEVERE +SEVERE=Grave # The following ALL CAPS words should be translated. -WARNING=WARNING +WARNING=Avvertenza # The following ALL CAPS words should be translated. -INFO=INFO +INFO=Informazioni # The following ALL CAPS words should be translated. -CONFIG= CONFIG +CONFIG= Configurazione # The following ALL CAPS words should be translated. -FINE=FINE +FINE=Buono # The following ALL CAPS words should be translated. -FINER=FINER +FINER=Migliore # The following ALL CAPS words should be translated. -FINEST=FINEST +FINEST=Ottimale # The following ALL CAPS words should be translated. -OFF=OFF +OFF=Non attivo diff --git a/jdk/src/share/classes/sun/util/logging/resources/logging_ja.properties b/jdk/src/share/classes/sun/util/logging/resources/logging_ja.properties index 980c33549c5..60358d1c86e 100644 --- a/jdk/src/share/classes/sun/util/logging/resources/logging_ja.properties +++ b/jdk/src/share/classes/sun/util/logging/resources/logging_ja.properties @@ -29,18 +29,18 @@ # The following ALL CAPS words should be translated. ALL=\u3059\u3079\u3066 # The following ALL CAPS words should be translated. -SEVERE=SEVERE +SEVERE=\u91CD\u5927 # The following ALL CAPS words should be translated. -WARNING=WARNING +WARNING=\u8B66\u544A # The following ALL CAPS words should be translated. INFO=\u60C5\u5831 # The following ALL CAPS words should be translated. -CONFIG= CONFIG +CONFIG= \u69CB\u6210 # The following ALL CAPS words should be translated. -FINE=\u8A73\u7D30\u30EC\u30D9\u30EB(\u4F4E) +FINE=\u666E\u901A # The following ALL CAPS words should be translated. -FINER=FINER +FINER=\u8A73\u7D30 # The following ALL CAPS words should be translated. -FINEST=FINEST +FINEST=\u6700\u3082\u8A73\u7D30 # The following ALL CAPS words should be translated. OFF=\u30AA\u30D5 diff --git a/jdk/src/share/classes/sun/util/logging/resources/logging_ko.properties b/jdk/src/share/classes/sun/util/logging/resources/logging_ko.properties index da17c47f8fd..6d5dc551e67 100644 --- a/jdk/src/share/classes/sun/util/logging/resources/logging_ko.properties +++ b/jdk/src/share/classes/sun/util/logging/resources/logging_ko.properties @@ -27,20 +27,20 @@ # these are the same as the non-localized level name. # The following ALL CAPS words should be translated. -ALL=ALL +ALL=\uBAA8\uB450 # The following ALL CAPS words should be translated. -SEVERE=SEVERE +SEVERE=\uC2EC\uAC01 # The following ALL CAPS words should be translated. -WARNING=WARNING +WARNING=\uACBD\uACE0 # The following ALL CAPS words should be translated. -INFO=INFO +INFO=\uC815\uBCF4 # The following ALL CAPS words should be translated. -CONFIG= CONFIG +CONFIG= \uAD6C\uC131 # The following ALL CAPS words should be translated. -FINE=FINE +FINE=\uBBF8\uC138 # The following ALL CAPS words should be translated. -FINER=FINER +FINER=\uBCF4\uB2E4 \uBBF8\uC138 # The following ALL CAPS words should be translated. -FINEST=FINEST +FINEST=\uAC00\uC7A5 \uBBF8\uC138 # The following ALL CAPS words should be translated. -OFF=OFF +OFF=\uD574\uC81C diff --git a/jdk/src/share/classes/sun/util/logging/resources/logging_pt_BR.properties b/jdk/src/share/classes/sun/util/logging/resources/logging_pt_BR.properties index da17c47f8fd..29229f2c7c1 100644 --- a/jdk/src/share/classes/sun/util/logging/resources/logging_pt_BR.properties +++ b/jdk/src/share/classes/sun/util/logging/resources/logging_pt_BR.properties @@ -27,20 +27,20 @@ # these are the same as the non-localized level name. # The following ALL CAPS words should be translated. -ALL=ALL +ALL=Tudo # The following ALL CAPS words should be translated. -SEVERE=SEVERE +SEVERE=Grave # The following ALL CAPS words should be translated. -WARNING=WARNING +WARNING=Advert\u00EAncia # The following ALL CAPS words should be translated. -INFO=INFO +INFO=Informa\u00E7\u00F5es # The following ALL CAPS words should be translated. -CONFIG= CONFIG +CONFIG= Configura\u00E7\u00E3o # The following ALL CAPS words should be translated. -FINE=FINE +FINE=Detalhado # The following ALL CAPS words should be translated. -FINER=FINER +FINER=Mais Detalhado # The following ALL CAPS words should be translated. -FINEST=FINEST +FINEST=O Mais Detalhado # The following ALL CAPS words should be translated. -OFF=OFF +OFF=Desativado diff --git a/jdk/src/share/classes/sun/util/logging/resources/logging_sv.properties b/jdk/src/share/classes/sun/util/logging/resources/logging_sv.properties index 4c8dd1d2dcb..b7607863ffb 100644 --- a/jdk/src/share/classes/sun/util/logging/resources/logging_sv.properties +++ b/jdk/src/share/classes/sun/util/logging/resources/logging_sv.properties @@ -27,20 +27,20 @@ # these are the same as the non-localized level name. # The following ALL CAPS words should be translated. -ALL=ALLA +ALL=Alla # The following ALL CAPS words should be translated. -SEVERE=SEVERE +SEVERE=Allvarlig # The following ALL CAPS words should be translated. -WARNING=WARNING +WARNING=Varning # The following ALL CAPS words should be translated. -INFO=INFO +INFO=Info # The following ALL CAPS words should be translated. -CONFIG= CONFIG +CONFIG= Konfig # The following ALL CAPS words should be translated. -FINE=FINE +FINE=Fin # The following ALL CAPS words should be translated. -FINER=FINER +FINER=Finare # The following ALL CAPS words should be translated. -FINEST=FINEST +FINEST=Finaste # The following ALL CAPS words should be translated. -OFF=OFF +OFF=Av diff --git a/jdk/src/share/classes/sun/util/logging/resources/logging_zh_CN.properties b/jdk/src/share/classes/sun/util/logging/resources/logging_zh_CN.properties index da17c47f8fd..67dd2b8b50a 100644 --- a/jdk/src/share/classes/sun/util/logging/resources/logging_zh_CN.properties +++ b/jdk/src/share/classes/sun/util/logging/resources/logging_zh_CN.properties @@ -27,20 +27,20 @@ # these are the same as the non-localized level name. # The following ALL CAPS words should be translated. -ALL=ALL +ALL=\u5168\u90E8 # The following ALL CAPS words should be translated. -SEVERE=SEVERE +SEVERE=\u4E25\u91CD # The following ALL CAPS words should be translated. -WARNING=WARNING +WARNING=\u8B66\u544A # The following ALL CAPS words should be translated. -INFO=INFO +INFO=\u4FE1\u606F # The following ALL CAPS words should be translated. -CONFIG= CONFIG +CONFIG= \u914D\u7F6E # The following ALL CAPS words should be translated. -FINE=FINE +FINE=\u8BE6\u7EC6 # The following ALL CAPS words should be translated. -FINER=FINER +FINER=\u8F83\u8BE6\u7EC6 # The following ALL CAPS words should be translated. -FINEST=FINEST +FINEST=\u975E\u5E38\u8BE6\u7EC6 # The following ALL CAPS words should be translated. -OFF=OFF +OFF=\u7981\u7528 diff --git a/jdk/src/share/classes/sun/util/logging/resources/logging_zh_TW.properties b/jdk/src/share/classes/sun/util/logging/resources/logging_zh_TW.properties index d7ad070a69e..4875bc825c1 100644 --- a/jdk/src/share/classes/sun/util/logging/resources/logging_zh_TW.properties +++ b/jdk/src/share/classes/sun/util/logging/resources/logging_zh_TW.properties @@ -27,20 +27,20 @@ # these are the same as the non-localized level name. # The following ALL CAPS words should be translated. -ALL=\u6240\u6709 +ALL=\u5168\u90E8 # The following ALL CAPS words should be translated. -SEVERE=SEVERE +SEVERE=\u56B4\u91CD # The following ALL CAPS words should be translated. -WARNING=WARNING +WARNING=\u8B66\u544A # The following ALL CAPS words should be translated. INFO=\u8CC7\u8A0A # The following ALL CAPS words should be translated. -CONFIG= CONFIG +CONFIG= \u7D44\u614B # The following ALL CAPS words should be translated. FINE=\u8A73\u7D30 # The following ALL CAPS words should be translated. -FINER=FINER +FINER=\u8F03\u8A73\u7D30 # The following ALL CAPS words should be translated. -FINEST=FINEST +FINEST=\u6700\u8A73\u7D30 # The following ALL CAPS words should be translated. OFF=\u95DC\u9589 diff --git a/jdk/test/java/util/logging/LocalizedLevelName.java b/jdk/test/java/util/logging/LocalizedLevelName.java new file mode 100644 index 00000000000..cdb425a294f --- /dev/null +++ b/jdk/test/java/util/logging/LocalizedLevelName.java @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2013, 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.*; +import java.util.logging.*; + +/* + * @test + * @bug 8016127 8024131 + * @summary test logging.properties localized + * @run main/othervm LocalizedLevelName + */ + +public class LocalizedLevelName { + private static Object[] namesMap = { + "SEVERE", Locale.ENGLISH, "Severe", Level.SEVERE, + "WARNING", Locale.FRENCH, "Avertissement", Level.WARNING, + "INFO", Locale.ITALIAN, "Informazioni", Level.INFO, + "SEVERE", Locale.FRENCH, "Grave", Level.SEVERE, + "CONFIG", Locale.GERMAN, "Konfiguration", Level.CONFIG, + "ALL", Locale.ROOT, "All", Level.ALL, + "SEVERE", Locale.ROOT, "Severe", Level.SEVERE, + "WARNING", Locale.ROOT, "Warning", Level.WARNING, + "CONFIG", Locale.ROOT, "Config", Level.CONFIG, + "INFO", Locale.ROOT, "Info", Level.INFO, + "FINE", Locale.ROOT, "Fine", Level.FINE, + "FINER", Locale.ROOT, "Finer", Level.FINER, + "FINEST", Locale.ROOT, "Finest", Level.FINEST + }; + + public static void main(String args[]) throws Exception { + Locale defaultLocale = Locale.getDefault(); + for (int i=0; i localized(" + Locale.ENGLISH + ", " + + key + ")=" + en); + System.out.println(" => localized(" + locale + ", " + key + + ")=" + other); + if (!key.equals(en.toUpperCase(Locale.ROOT))) { + throw new RuntimeException("Expect " + key + + " equals upperCase(" + en + ")"); + } + if (!Locale.ENGLISH.equals(locale) && !Locale.ROOT.equals(locale) + && key.equals(other.toUpperCase(Locale.ROOT))) { + throw new RuntimeException("Expect " + key + + " not equals upperCase(" + other +")"); + } + if ((Locale.ENGLISH.equals(locale) || Locale.ROOT.equals(locale)) + && !key.equals(other.toUpperCase(Locale.ROOT))) { + throw new RuntimeException("Expect " + key + + " equals upperCase(" + other +")"); + } + if (!other.equals(expectedTranslation)) { + throw new RuntimeException("Expected \"" + expectedTranslation + + "\" for '" + locale + "' but got \"" + other + "\""); + } + Locale.setDefault(locale); + final String levelName = level.getLocalizedName(); + System.out.println("Level.getLocalizedName() is: " + levelName); + if (!levelName.equals(other.toUpperCase(locale))) { + throw new RuntimeException("Expected \"" + + other.toUpperCase(locale) + "\" for '" + + locale + "' but got \"" + levelName + "\""); + } + Locale.setDefault(defaultLocale); + } + } + + private static final String RBNAME = "sun.util.logging.resources.logging"; + private static String getLocalizedMessage(Locale locale, String key) { + ResourceBundle rb = ResourceBundle.getBundle(RBNAME, locale); + return rb.getString(key); + } +} From f4dda09731a2ceb1a6a633589f14a7a68828eeeb Mon Sep 17 00:00:00 2001 From: Erik Gahlin Date: Mon, 2 Sep 2013 16:03:34 +0200 Subject: [PATCH 007/210] 7172176: java/jconsole test/sun/tools/jconsole/ImmutableResourceTest.sh failing Reviewed-by: mchung, mfang --- .../classes/sun/tools/jconsole/Resources.java | 6 +- jdk/test/ProblemList.txt | 4 - .../tools/jconsole/ImmutableResourceTest.java | 60 --- .../tools/jconsole/ImmutableResourceTest.sh | 111 ----- .../sun/tools/jconsole/ResourceCheckTest.java | 469 +++++------------- .../sun/tools/jconsole/ResourceCheckTest.sh | 4 +- 6 files changed, 118 insertions(+), 536 deletions(-) delete mode 100644 jdk/test/sun/tools/jconsole/ImmutableResourceTest.java delete mode 100644 jdk/test/sun/tools/jconsole/ImmutableResourceTest.sh diff --git a/jdk/src/share/classes/sun/tools/jconsole/Resources.java b/jdk/src/share/classes/sun/tools/jconsole/Resources.java index 785be24d2e6..20af2e9f9e9 100644 --- a/jdk/src/share/classes/sun/tools/jconsole/Resources.java +++ b/jdk/src/share/classes/sun/tools/jconsole/Resources.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2013, 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 @@ -30,7 +30,7 @@ import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.text.MessageFormat; import java.util.Collections; -import java.util.HashMap; +import java.util.IdentityHashMap; import java.util.Map; import java.util.MissingResourceException; import java.util.ResourceBundle; @@ -40,7 +40,7 @@ import java.util.ResourceBundle; */ public final class Resources { private static Map MNEMONIC_LOOKUP = Collections - .synchronizedMap(new HashMap()); + .synchronizedMap(new IdentityHashMap()); private Resources() { throw new AssertionError(); diff --git a/jdk/test/ProblemList.txt b/jdk/test/ProblemList.txt index 26c4eb54a55..1ac61aa2c3f 100644 --- a/jdk/test/ProblemList.txt +++ b/jdk/test/ProblemList.txt @@ -305,10 +305,6 @@ sun/security/krb5/auto/BadKdc4.java solaris-sparcv9 # 6461635 com/sun/tools/attach/BasicTests.sh generic-all -# 7172176 -sun/tools/jconsole/ResourceCheckTest.sh generic-all -sun/tools/jconsole/ImmutableResourceTest.sh generic-all - # 7132203 sun/jvmstat/monitor/MonitoredVm/CR6672135.java generic-all diff --git a/jdk/test/sun/tools/jconsole/ImmutableResourceTest.java b/jdk/test/sun/tools/jconsole/ImmutableResourceTest.java deleted file mode 100644 index 082776667a4..00000000000 --- a/jdk/test/sun/tools/jconsole/ImmutableResourceTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2005, 2007, 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. - */ - -/** - * - * - * This isn't the test case: ImmutableResourceTest.sh is. - * Refer to ImmutableResourceTest.sh when running this test. - * - * @bug 6287579 - * @summary SubClasses of ListResourceBundle should fix getContents() - */ -import java.util.ResourceBundle; - -public class ImmutableResourceTest { - - public static void main(String[] args) throws Exception { - - /* Reach under the covers and get the message strings */ - sun.tools.jconsole.resources.JConsoleResources jcr = - new sun.tools.jconsole.resources.JConsoleResources (); - Object [][] testData = jcr.getContents(); - - /* Shred our copy of the message strings */ - for (int ii = 0; ii < testData.length; ii++) { - testData[ii][0] = "xxx"; - testData[ii][1] = "yyy"; - } - - /* - * Try a lookup for the shredded key. - * If this is successful we have a problem. - */ - String ss = sun.tools.jconsole.Resources.getText("xxx"); - if ("yyy".equals(ss)) { - throw new Exception ("SubClasses of ListResourceBundle should fix getContents()"); - } - System.out.println("...Finished."); - } -} diff --git a/jdk/test/sun/tools/jconsole/ImmutableResourceTest.sh b/jdk/test/sun/tools/jconsole/ImmutableResourceTest.sh deleted file mode 100644 index dedf21271b0..00000000000 --- a/jdk/test/sun/tools/jconsole/ImmutableResourceTest.sh +++ /dev/null @@ -1,111 +0,0 @@ -# -# Copyright (c) 2005, 2012, 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 6287579 -# @summary SubClasses of ListResourceBundle should fix getContents() -# -# @run shell ImmutableResourceTest.sh - -# Beginning of subroutines: -status=1 - -#Call this from anywhere to fail the test with an error message -# usage: fail "reason why the test failed" -fail() - { echo "The test failed :-(" - echo "$*" 1>&2 - echo "exit status was $status" - exit $status - } #end of fail() - -#Call this from anywhere to pass the test with a message -# usage: pass "reason why the test passed if applicable" -pass() - { echo "The test passed!!!" - echo "$*" 1>&2 - exit 0 - } #end of pass() - -# end of subroutines - -# The beginning of the script proper - -OS=`uname -s` -case "$OS" in - SunOS | Linux | Darwin ) - PATHSEP=":" - ;; - - Windows* | CYGWIN*) - PATHSEP=";" - ;; - - # catch all other OSs - * ) - echo "Unrecognized system! $OS" - fail "Unrecognized system! $OS" - ;; -esac - -TARGETCLASS="ImmutableResourceTest" -if [ -z "${TESTJAVA}" ] ; then - # TESTJAVA is not set, so the test is running stand-alone. - # TESTJAVA holds the path to the root directory of the build of the JDK - # to be tested. That is, any java files run explicitly in this shell - # should use TESTJAVA in the path to the java interpreter. - # So, we'll set this to the JDK spec'd on the command line. If none - # is given on the command line, tell the user that and use a default. - # THIS IS THE JDK BEING TESTED. - if [ -n "$1" ] ; then - TESTJAVA=$1 - else - TESTJAVA=$JAVA_HOME - fi - TESTSRC=. - TESTCLASSES=. - #Deal with .class files: -fi -# -echo "JDK under test is: $TESTJAVA" -# -CP="-classpath ${TESTCLASSES}${PATHSEP}${TESTJAVA}/lib/jconsole.jar" -# Compile the test class using the classpath we need: -# -env -# -set -vx -# -#Compile. jconsole.jar is required on the classpath. -${TESTJAVA}/bin/javac -d "${TESTCLASSES}" ${CP} -g \ - "${TESTSRC}"/"${TARGETCLASS}".java -# -#Run the test class, again with the classpath we need: -${TESTJAVA}/bin/java ${CP} ${TARGETCLASS} -status=$? -echo "test status was: $status" -if [ $status -eq "0" ]; - then pass "" - - else fail "unspecified test failure" -fi diff --git a/jdk/test/sun/tools/jconsole/ResourceCheckTest.java b/jdk/test/sun/tools/jconsole/ResourceCheckTest.java index 6d4e27be860..1ed5bb642c7 100644 --- a/jdk/test/sun/tools/jconsole/ResourceCheckTest.java +++ b/jdk/test/sun/tools/jconsole/ResourceCheckTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2013, 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,377 +27,134 @@ * This isn't the test case: ResourceCheckTest.sh is. * Refer to ResourceCheckTest.sh when running this test. * - * @bug 5008856 5023573 5024917 5062569 + * @bug 5008856 5023573 5024917 5062569 7172176 * @summary 'missing resource key' error for key = "Operating system" */ -import java.awt.event.KeyEvent; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Locale; +import java.util.ResourceBundle; +import sun.tools.jconsole.Messages; import sun.tools.jconsole.Resources; +/* + * Ensures that there is a one-to-one mapping between constants in the + * Message class and the keys in the sun.tools.jconsole.resources.messages + * bundle. + * + * An error will be thrown if there is a: + * + * - key in the resource bundle that doesn't have a public static field with + * the same name in the Message class. + * + * - public static field in the Message class that doesn't have a key with + * the same name in the resource bundle. + * + * - message with a mnemonic identifier(&) for which a mnemonic can't + * be looked up using Resources#getMnemonicInt(). + * + */ public class ResourceCheckTest { + private static final String MISSING_RESOURCE_KEY_PREFIX = "missing message for"; + private static final String RESOURCE_BUNDLE = "sun.tools.jconsole.resources.messages"; + private static final String NEW_LINE = String.format("%n"); - public static void main(String[] args){ - Object [][] testData = { - {"<", "", "", "", ""}, - {"<<", "", "", "", ""}, - {">", "", "", "", ""}, - {" 1 day", "", "", "", ""}, - {" 1 hour", "", "", "", ""}, - {" 1 min", "", "", "", ""}, - {" 1 month", "", "", "", ""}, - {" 1 year", "", "", "", ""}, - {" 2 hours", "", "", "", ""}, - {" 3 hours", "", "", "", ""}, - {" 3 months", "", "", "", ""}, - {" 5 min", "", "", "", ""}, - {" 6 hours", "", "", "", ""}, - {" 6 months", "", "", "", ""}, - {" 7 days", "", "", "", ""}, - {"10 min", "", "", "", ""}, - {"12 hours", "", "", "", ""}, - {"30 min", "", "", "", ""}, - {"ACTION", "", "", "", ""}, - {"ACTION_INFO", "", "", "", ""}, - {"All", "", "", "", ""}, - {"Architecture", "", "", "", ""}, - {"Attribute", "", "", "", ""}, - {"Attribute value", "", "", "", ""}, - {"Attribute values", "", "", "", ""}, - {"Attributes", "", "", "", ""}, - {"Blank", "", "", "", ""}, - {"BlockedCount WaitedCount", "BlockedCount", "WaitedCount", "", ""}, - {"Boot class path", "", "", "", ""}, - {"BorderedComponent.moreOrLessButton.toolTip", "", "", "", ""}, - {"Close", "", "", "", ""}, - {"CPU Usage", "", "", "", ""}, - {"CPUUsageFormat","PhonyPercentage", "", "", ""}, - {"Cancel", "", "", "", ""}, - {"Cascade", "", "", "", ""}, - {"Cascade.mnemonic", "", "", "", ""}, - {"Chart:", "", "", "", ""}, - {"Chart:.mnemonic", "", "", "", ""}, - {"ClassTab.infoLabelFormat", "LoadedCount", "UnloadedCount", "TotalCount", ""}, - {"ClassTab.loadedClassesPlotter.accessibleName", "", "", "", ""}, - {"Class path", "", "", "", ""}, - {"Classes", "", "", "", ""}, - {"ClassName", "", "", "", ""}, - {"Column.Name", "", "", "", ""}, - {"Column.PID", "", "", "", ""}, - {"Committed", "", "", "", ""}, - {"Committed memory", "", "", "", ""}, - {"Committed virtual memory", "", "", "", ""}, - {"Compiler", "", "", "", ""}, - {"Connect...", "", "", "", ""}, - {"Connect", "", "", "", ""}, - {"Connect.mnemonic", "", "", "", ""}, - {"ConnectDialog.connectButton.toolTip", "", "", "", ""}, - {"ConnectDialog.accessibleDescription", "", "", "", ""}, - {"ConnectDialog.masthead.accessibleName", "", "", "", ""}, - {"ConnectDialog.masthead.title", "", "", "", ""}, - {"ConnectDialog.statusBar.accessibleName", "", "", "", ""}, - {"ConnectDialog.title", "", "", "", ""}, - {"Connected. Click to disconnect.", "", "", "", ""}, - {"connectingTo1", "PhonyConnectionName", "", "", ""}, - {"connectingTo2", "PhonyConnectionName", "", "", ""}, - {"connectionFailed1", "", "", "", ""}, - {"connectionFailed2", "PhonyConnectionName", "", "", ""}, - {"connectionLost1", "", "", "", ""}, - {"connectionLost2", "PhonyConnectionName", "", "", ""}, - {"Connection failed", "", "", "", ""}, - {"Connection", "", "", "", ""}, - {"Connection.mnemonic", "", "", "", ""}, - {"Connection name", "", "", "", ""}, - {"ConnectionName (disconnected)", "Phony", "Phony", "", ""}, - {"Constructor", "", "", "", ""}, - {"Create", "Phony", "Phony", "", ""}, - {"Current classes loaded", "", "", "", ""}, - {"Current heap size", "", "", "", ""}, - {"Current value", "PhonyValue", "", "", ""}, - {"Daemon threads", "", "", "", ""}, - {"deadlockAllTab", "", "", "", ""}, - {"deadlockTab", "", "", "", ""}, - {"deadlockTabN", "PhonyInt", "", "", ""}, - {"Description", "", "", "", ""}, - {"Descriptor", "", "", "", ""}, - {"Details", "", "", "", ""}, - {"Detect Deadlock", "", "", "", ""}, - {"Detect Deadlock.mnemonic", "", "", "", ""}, - {"Detect Deadlock.toolTip", "", "", "", ""}, - {"Dimension is not supported:", "", "", "", ""}, - {"Discard chart", "", "", "", ""}, - {"Disconnected. Click to connect.", "", "", "", ""}, - {"Double click to expand/collapse", "", "", "", ""}, - {"Double click to visualize", "", "", "", ""}, - {"DurationDaysHoursMinutes", 0, 13, 54, ""}, - {"DurationDaysHoursMinutes", 1, 13, 54, ""}, - {"DurationDaysHoursMinutes", 2, 13, 54, ""}, - {"DurationDaysHoursMinutes", 1024, 13, 45, ""}, - {"DurationHoursMinutes", 0, 13, "", ""}, - {"DurationHoursMinutes", 1, 0, "", ""}, - {"DurationHoursMinutes", 1, 1, "", ""}, - {"DurationHoursMinutes", 2, 42, "", ""}, - {"DurationMinutes", 0, "", "", ""}, - {"DurationMinutes", 1, "", "", ""}, - {"DurationMinutes", 2, "", "", ""}, - {"DurationSeconds", 0, "", "", ""}, - {"DurationSeconds", 1, "", "", ""}, - {"DurationSeconds", 2, "", "", ""}, - {"Empty array", "", "", "", ""}, - {"Error", "", "", "", ""}, - {"Error: MBeans already exist", "", "", "", ""}, - {"Error: MBeans do not exist", "", "", "", ""}, - {"Event", "", "", "", ""}, - {"Exit", "", "", "", ""}, - {"Exit.mnemonic", "", "", "", ""}, - {"expand", "", "", "", ""}, - {"Fail to load plugin", "", "", "", ""}, - {"FileChooser.fileExists.cancelOption", "", "", "", ""}, - {"FileChooser.fileExists.message", "PhonyFileName", "", "", ""}, - {"FileChooser.fileExists.okOption", "", "", "", ""}, - {"FileChooser.fileExists.title", "", "", "", ""}, - {"FileChooser.savedFile", "PhonyFilePath", "PhonyFileSize", "", ""}, - {"FileChooser.saveFailed.message", "PhonyFilePath", "PhonyMessage", "", ""}, - {"FileChooser.saveFailed.title", "", "", "", ""}, - {"Free physical memory", "", "", "", ""}, - {"Free swap space", "", "", "", ""}, - {"Garbage collector", "", "", "", ""}, - {"GC time", "", "", "", ""}, - {"GC time details", 54, "Phony", 11, ""}, - {"GcInfo", "Phony", -1, 768, ""}, - {"GcInfo", "Phony", 0, 768, ""}, - {"GcInfo", "Phony", 1, 768, ""}, - {"Heap", "", "", "", ""}, - {"Heap Memory Usage", "", "", "", ""}, - {"Help.AboutDialog.accessibleDescription", "", "", "", ""}, - {"Help.AboutDialog.jConsoleVersion", "DummyVersion", "", "", ""}, - {"Help.AboutDialog.javaVersion", "DummyVersion", "", "", ""}, - {"Help.AboutDialog.masthead.accessibleName", "", "", "", ""}, - {"Help.AboutDialog.masthead.title", "", "", "", ""}, - {"Help.AboutDialog.title", "", "", "", ""}, - {"Help.AboutDialog.userGuideLink", "DummyMessage", "", "", ""}, - {"Help.AboutDialog.userGuideLink.mnemonic", "", "", "", ""}, - {"Help.AboutDialog.userGuideLink.url", "DummyURL", "", "", ""}, - {"HelpMenu.About.title", "", "", "", ""}, - {"HelpMenu.About.title.mnemonic", "", "", "", ""}, - {"HelpMenu.UserGuide.title", "", "", "", ""}, - {"HelpMenu.UserGuide.title.mnemonic", "", "", "", ""}, - {"HelpMenu.title", "", "", "", ""}, - {"HelpMenu.title.mnemonic", "", "", "", ""}, - {"Hotspot MBeans...", "", "", "", ""}, - {"Hotspot MBeans....mnemonic", "", "", "", ""}, - {"Hotspot MBeans.dialog.accessibleDescription", "", "", "", ""}, - {"Impact", "", "", "", ""}, - {"Info", "", "", "", ""}, - {"INFO", "", "", "", ""}, - {"Invalid plugin path", "", "", "", ""}, - {"Invalid URL", "", "", "", ""}, - {"Is", "", "", "", ""}, - {"Java Monitoring & Management Console", "", "", "", ""}, - {"Java Virtual Machine", "", "", "", ""}, - {"JConsole: ", "", "", "", ""}, - {"JConsole.accessibleDescription", "", "", "", ""}, - {"JConsole version", "PhonyVersion", "", "", ""}, - {"JIT compiler", "", "", "", ""}, - {"Library path", "", "", "", ""}, - {"Live Threads", "", "", "", ""}, - {"Loaded", "", "", "", ""}, - {"Local Process:", "", "", "", ""}, - {"Local Process:.mnemonic", "", "", "", ""}, - {"Manage Hotspot MBeans in: ", "", "", "", ""}, - {"Management Not Enabled", "", "", "", ""}, - {"Management Will Be Enabled", "", "", "", ""}, - {"Masthead.font", "", "", "", ""}, - {"Max", "", "", "", ""}, - {"Max", "", "", "", ""}, - {"Maximum heap size", "", "", "", ""}, - {"MBeanAttributeInfo", "", "", "", ""}, - {"MBeanInfo", "", "", "", ""}, - {"MBeanNotificationInfo", "", "", "", ""}, - {"MBeanOperationInfo", "", "", "", ""}, - {"MBeans", "", "", "", ""}, - {"MBeansTab.clearNotificationsButton", "", "", "", ""}, - {"MBeansTab.clearNotificationsButton.mnemonic", "", "", "", ""}, - {"MBeansTab.clearNotificationsButton.toolTip", "", "", "", ""}, - {"MBeansTab.compositeNavigationMultiple", 0, 0, "", ""}, - {"MBeansTab.compositeNavigationSingle", "", "", "", ""}, - {"MBeansTab.refreshAttributesButton", "", "", "", ""}, - {"MBeansTab.refreshAttributesButton.mnemonic", "", "", "", ""}, - {"MBeansTab.refreshAttributesButton.toolTip", "", "", "", ""}, - {"MBeansTab.subscribeNotificationsButton", "", "", "", ""}, - {"MBeansTab.subscribeNotificationsButton.mnemonic", "", "", "", ""}, - {"MBeansTab.subscribeNotificationsButton.toolTip", "", "", "", ""}, - {"MBeansTab.tabularNavigationMultiple", 0, 0, "", ""}, - {"MBeansTab.tabularNavigationSingle", "", "", "", ""}, - {"MBeansTab.unsubscribeNotificationsButton", "", "", "", ""}, - {"MBeansTab.unsubscribeNotificationsButton.mnemonic", "", "", "", ""}, - {"MBeansTab.unsubscribeNotificationsButton.toolTip", "", "", "", ""}, - {"Memory", "", "", "", ""}, - {"MemoryPoolLabel", "PhonyMemoryPool", "", "", ""}, - {"MemoryTab.heapPlotter.accessibleName", "", "", "", ""}, - {"MemoryTab.infoLabelFormat", "UsedCount", "CommittedCount", "MaxCount", ""}, - {"MemoryTab.nonHeapPlotter.accessibleName", "", "", "", ""}, - {"MemoryTab.poolChart.aboveThreshold", "Threshold", "", "", ""}, - {"MemoryTab.poolChart.accessibleName", "", "", "", ""}, - {"MemoryTab.poolChart.belowThreshold", "Threshold", "", "", ""}, - {"MemoryTab.poolPlotter.accessibleName", "PhonyMemoryPool", "", "", ""}, - {"Message", "", "", "", ""}, - {"Method successfully invoked", "", "", "", ""}, - {"Monitor locked", "", "", "", ""}, - {"Minimize All", "", "", "", ""}, - {"Minimize All.mnemonic", "", "", "", ""}, - {"Name", "", "", "", ""}, - {"Name and Build", "PhonyName", "PhonyBuild", "", ""}, - {"Name Build and Mode", "PhonyName", "PhonyBuild", "PhonyMode", ""}, - {"Name State", "PhonyName", "PhonyState", "", ""}, - {"Name State LockName", "PhonyName", "PhonyState", "PhonyLock", ""}, - {"Name State LockName LockOwner", "PhonyName", "PhonyState", "PhonyLock", "PhonyOwner"}, - {"New Connection...", "", "", "", ""}, - {"New Connection....mnemonic", "", "", "", ""}, - {"No deadlock detected", "", "", "", ""}, - {"Non-Heap", "", "", "", ""}, - {"Non-Heap Memory Usage", "", "", "", ""}, - {"Notification", "", "", "", ""}, - {"Notification buffer", "", "", "", ""}, - {"Notifications", "", "", "", ""}, - {"NotifTypes", "", "", "", ""}, - {"Number of Loaded Classes", "", "", "", ""}, - {"Number of processors", "", "", "", ""}, - {"Number of Threads", "", "", "", ""}, - {"ObjectName", "", "", "", ""}, - {"Operating System", "", "", "", ""}, - {"Operation", "", "", "", ""}, - {"Operation invocation", "", "", "", ""}, - {"Operation return value", "", "", "", ""}, - {"Operations", "", "", "", ""}, - {"Overview", "", "", "", ""}, - {"OverviewPanel.plotter.accessibleName", "PhonyPlotter", "", "", ""}, - {"Parameter", "", "", "", ""}, - {"Password: ", "", "", "", ""}, - {"Password: .mnemonic", "", "", "", ""}, - {"Password.accessibleName", "", "", "", ""}, - {"Peak", "", "", "", ""}, - {"Perform GC", "", "", "", ""}, - {"Perform GC.mnemonic", "", "", "", ""}, - {"Perform GC.toolTip", "", "", "", ""}, - {"Plotter.accessibleName", "", "", "", ""}, - {"Plotter.accessibleName.keyAndValue", "Key", "Value", "", ""}, - {"Plotter.accessibleName.noData", "", "", "", ""}, - {"Plotter.saveAsMenuItem", "", "", "", ""}, - {"Plotter.saveAsMenuItem.mnemonic", "", "", "", ""}, - {"Plotter.timeRangeMenu", "", "", "", ""}, - {"Plotter.timeRangeMenu.mnemonic", "", "", "", ""}, - {"plot", "", "", "", ""}, - {"Problem adding listener", "", "", "", ""}, - {"Problem displaying MBean", "", "", "", ""}, - {"Problem invoking", "", "", "", ""}, - {"Problem removing listener", "", "", "", ""}, - {"Problem setting attribute", "", "", "", ""}, - {"Process CPU time", "", "", "", ""}, - {"Readable", "", "", "", ""}, - {"Reconnect", "", "", "", ""}, - {"Remote Process:", "", "", "", ""}, - {"Remote Process:.mnemonic", "", "", "", ""}, - {"Remote Process.textField.accessibleName", "", "", "", ""}, - {"remoteTF.usage", "", "", "", ""}, - {"Restore All", "", "", "", ""}, - {"Restore All.mnemonic", "", "", "", ""}, - {"ReturnType", "", "", "", ""}, - {"SeqNum", "", "", "", ""}, - {"Size Bytes", 512, "", "", ""}, - {"Size Gb", 512, "", "", ""}, - {"Size Kb", 512, "", "", ""}, - {"Size Mb", 512, "", "", ""}, - {"Source", "", "", "", ""}, - {"Stack trace", "", "", "", ""}, - {"SummaryTab.headerDateTimeFormat", "", "", "", ""}, - {"SummaryTab.pendingFinalization.label", "", "", "", ""}, - {"SummaryTab.pendingFinalization.value", "ObjectCount", "", "", ""}, - {"SummaryTab.tabName", "", "", "", ""}, - {"SummaryTab.vmVersion", "VMName", "VMVersion", "", ""}, - {"ThreadTab.infoLabelFormat", "LiveCount", "PeakCount", "TotalCount", ""}, - {"ThreadTab.threadInfo.accessibleName", "", "", "", ""}, - {"ThreadTab.threadPlotter.accessibleName", "", "", "", ""}, - {"Threads", "", "", "", ""}, - {"Threshold", "", "", "", ""}, - {"Tile", "", "", "", ""}, - {"Tile.mnemonic", "", "", "", ""}, - {"Time", "", "", "", ""}, - {"Time Range:", "", "", "", ""}, - {"Time Range:.mnemonic", "", "", "", ""}, - {"TimeStamp", "", "", "", ""}, - {"Total classes loaded", "", "", "", ""}, - {"Total classes unloaded", "", "", "", ""}, - {"Total compile time", "", "", "", ""}, - {"Total Loaded", "", "", "", ""}, - {"Total physical memory", "", "", "", ""}, - {"Total swap space", "", "", "", ""}, - {"Total threads started", "", "", "", ""}, - {"Type", "", "", "", ""}, - {"Unavailable", "", "", "", ""}, - {"UNKNOWN", "", "", "", ""}, - {"Unregister", "", "", "", ""}, - {"Uptime", "", "", "", ""}, - {"Usage Threshold", "", "", "", ""}, - {"Used", "", "", "", ""}, - {"Username: ", "", "", "", ""}, - {"Username: .mnemonic", "", "", "", ""}, - {"Username.accessibleName", "", "", "", ""}, - {"UserData", "", "", "", ""}, - {"Value", "", "", "", ""}, - {"Vendor", "", "", "", ""}, - {"Verbose Output", "", "", "", ""}, - {"Verbose Output.toolTip", "", "", "", ""}, - {"visualize", "", "", "", ""}, - {"VM", "", "", "", ""}, - {"VMInternalFrame.accessibleDescription", "", "", "", ""}, - {"VM arguments", "", "", "", ""}, - {"Virtual Machine", "", "", "", ""}, - {"Window", "", "", "", ""}, - {"Window.mnemonic", "", "", "", ""}, - {"Writable", "", "", "", ""}, - {"zz usage text", "PhonyName", "", "", ""}, - }; - //boolean verbose = false; - boolean verbose = true; - - long badLookups = 0; - System.out.println("Start..."); - for (int ii = 0; ii < testData.length; ii++) { - String key = (String)testData[ii][0]; - - if (key.endsWith(".mnemonic")) { - String baseKey = key.substring(0, key.length() - ".mnemonic".length()); - int mnemonic = Resources.getMnemonicInt(baseKey); - if (mnemonic == 0) { - badLookups++; - System.out.println("****lookup failed for key = " + key); + public static void main(String... args) { + List errors = new ArrayList<>(); + // Ensure that all Message fields have a corresponding key/value + // in the resource bundle and that mnemonics can be looked + // up where applicable. + ResourceBundle rb = ResourceBundle.getBundle(RESOURCE_BUNDLE); + for (Field field : Messages.class.getFields()) { + if (isResourceKeyField(field)) { + String resourceKey = field.getName(); + String message = readField(field); + if (message.startsWith(MISSING_RESOURCE_KEY_PREFIX)) { + errors.add("Can't find message (and perhaps mnemonic) for " + + Messages.class.getSimpleName() + "." + + resourceKey + " in resource bundle."); } else { - if (verbose) { - System.out.println(" mnemonic: " + KeyEvent.getKeyText(mnemonic)); + String resourceMessage = rb.getString(resourceKey); + if (hasMnemonicIdentifier(resourceMessage)) { + int mi = Resources.getMnemonicInt(message); + if (mi == 0) { + errors.add("Could not look up mnemonic for message '" + + message + "'."); + } } } - continue; } + } - String ss = Resources.getText(key, - testData[ii][1], - testData[ii][2], - testData[ii][3], - testData[ii][4]); - if (ss.startsWith("missing resource key")) { - badLookups++; - System.out.println("****lookup failed for key = " + key); - } else { - if (verbose) { - System.out.println(" " + ss); + // Ensure that there is Message class field for every resource key. + for (String key : Collections.list(rb.getKeys())) { + try { + Messages.class.getField(key); + } catch (NoSuchFieldException nfe) { + errors.add("Can't find static field (" + + Messages.class.getSimpleName() + "." + key + + ") matching '" + key + + "' in resource bundle. Unused message?"); + } + } + + if (errors.size() > 0) { + throwError(errors); + } + } + + private static String readField(Field field) { + try { + return (String) field.get(null); + } catch (IllegalArgumentException | IllegalAccessException e) { + throw new Error("Could not access field " + field.getName() + + " when trying to read resource message."); + } + } + + private static boolean isResourceKeyField(Field field) { + int modifiers = field.getModifiers(); + return Modifier.isPublic(modifiers) && Modifier.isStatic(modifiers); + } + + private static boolean hasMnemonicIdentifier(String s) { + for (int i = 0; i < s.length() - 1; i++) { + if (s.charAt(i) == '&') { + if (s.charAt(i + 1) != '&') { + return true; + } else { + i++; } } } - if (badLookups > 0) { - throw new Error ("Resource lookup failed " + badLookups + - " time(s); Test failed"); + return false; + } + + private static void throwError(List errors) { + StringBuffer buffer = new StringBuffer(); + buffer.append("Found "); + buffer.append(errors.size()); + buffer.append(" error(s) when checking one-to-one mapping "); + buffer.append("between Message and resource bundle keys in "); + buffer.append(RESOURCE_BUNDLE); + buffer.append(" with "); + buffer.append(Locale.getDefault()); + buffer.append(" locale."); + buffer.append(NEW_LINE); + int errorIndex = 1; + for (String error : errors) { + buffer.append("Error "); + buffer.append(errorIndex); + buffer.append(": "); + buffer.append(error); + buffer.append(NEW_LINE); + errorIndex++; } - System.out.println("...Finished."); + throw new Error(buffer.toString()); } } diff --git a/jdk/test/sun/tools/jconsole/ResourceCheckTest.sh b/jdk/test/sun/tools/jconsole/ResourceCheckTest.sh index bec63a7992f..01c2e4b6f01 100644 --- a/jdk/test/sun/tools/jconsole/ResourceCheckTest.sh +++ b/jdk/test/sun/tools/jconsole/ResourceCheckTest.sh @@ -1,5 +1,5 @@ # -# Copyright (c) 2004, 2007, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2004, 2013, 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 @@ -54,7 +54,7 @@ pass() OS=`uname -s` case "$OS" in - SunOS | Linux ) + SunOS | Linux | Darwin) PATHSEP=":" ;; From 9b5513a8e8d82a40dacc910ddfa3d88bdecb6887 Mon Sep 17 00:00:00 2001 From: Mike Duigou Date: Tue, 3 Sep 2013 11:29:12 -0700 Subject: [PATCH 008/210] 8024015: TEST.groups: move jdk/lambda tests from jdk_other to jdk_lang Reviewed-by: alanb, mchung --- jdk/test/TEST.groups | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jdk/test/TEST.groups b/jdk/test/TEST.groups index 0674bdc1d91..ed70cbf6704 100644 --- a/jdk/test/TEST.groups +++ b/jdk/test/TEST.groups @@ -27,6 +27,7 @@ jdk_lang = \ sun/invoke \ sun/misc \ sun/reflect \ + jdk/lambda \ vm jdk_util = \ @@ -133,7 +134,6 @@ jdk_other = \ javax/xml \ -javax/xml/crypto \ jdk/asm \ - jdk/lambda \ com/sun/jndi \ com/sun/corba \ lib/testlibrary \ From f7b61b93f1d44b921df005f950e5836fad15c8cc Mon Sep 17 00:00:00 2001 From: Brian Goetz Date: Wed, 28 Aug 2013 14:13:03 -0700 Subject: [PATCH 009/210] 8022176: Weaken contract of java.lang.AutoCloseable Reviewed-by: alanb, martin, mduigou, psandoz --- .../classes/java/lang/AutoCloseable.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/jdk/src/share/classes/java/lang/AutoCloseable.java b/jdk/src/share/classes/java/lang/AutoCloseable.java index ce0fffe5939..be47cd0835f 100644 --- a/jdk/src/share/classes/java/lang/AutoCloseable.java +++ b/jdk/src/share/classes/java/lang/AutoCloseable.java @@ -26,7 +26,24 @@ package java.lang; /** - * A resource that must be closed when it is no longer needed. + * An object that may hold resources (such as file or socket handles) + * until it is closed. The {@link #close()} method of an {@code AutoCloseable} + * object is called automatically when exiting a {@code + * try}-with-resources block for which the object has been declared in + * the resource specification header. This construction ensures prompt + * release, avoiding resource exhaustion exceptions and errors that + * may otherwise occur. + * + * @apiNote + *

It is possible, and in fact common, for a base class to + * implement AutoCloseable even though not all of its subclasses or + * instances will hold releasable resources. For code that must operate + * in complete generality, or when it is known that the {@code AutoCloseable} + * instance requires resource release, it is recommended to use {@code + * try}-with-resources constructions. However, when using facilities such as + * {@link java.util.stream.Stream} that support both I/O-based and + * non-I/O-based forms, {@code try}-with-resources blocks are in + * general unnecessary when using non-I/O-based forms. * * @author Josh Bloch * @since 1.7 From 45d26c95711c9e57c51394ceeb10fd69d320c62a Mon Sep 17 00:00:00 2001 From: Henry Jen Date: Tue, 3 Sep 2013 11:44:34 -0700 Subject: [PATCH 010/210] 8024178: Difference in Stream.collect(Collector) methods located in jdk8 and jdk8-lambda repos Reviewed-by: mduigou --- jdk/src/share/classes/java/util/stream/DelegatingStream.java | 2 +- jdk/src/share/classes/java/util/stream/ReferencePipeline.java | 2 +- jdk/src/share/classes/java/util/stream/Stream.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/jdk/src/share/classes/java/util/stream/DelegatingStream.java b/jdk/src/share/classes/java/util/stream/DelegatingStream.java index 2dab1a4430c..fbe7735a515 100644 --- a/jdk/src/share/classes/java/util/stream/DelegatingStream.java +++ b/jdk/src/share/classes/java/util/stream/DelegatingStream.java @@ -209,7 +209,7 @@ public class DelegatingStream implements Stream { } @Override - public R collect(Collector collector) { + public R collect(Collector collector) { return delegate.collect(collector); } diff --git a/jdk/src/share/classes/java/util/stream/ReferencePipeline.java b/jdk/src/share/classes/java/util/stream/ReferencePipeline.java index 1fffff48b18..6c6fe647ee9 100644 --- a/jdk/src/share/classes/java/util/stream/ReferencePipeline.java +++ b/jdk/src/share/classes/java/util/stream/ReferencePipeline.java @@ -493,7 +493,7 @@ abstract class ReferencePipeline @Override @SuppressWarnings("unchecked") - public final R collect(Collector collector) { + public final R collect(Collector collector) { A container; if (isParallel() && (collector.characteristics().contains(Collector.Characteristics.CONCURRENT)) diff --git a/jdk/src/share/classes/java/util/stream/Stream.java b/jdk/src/share/classes/java/util/stream/Stream.java index 59d703b118e..1071b20110e 100644 --- a/jdk/src/share/classes/java/util/stream/Stream.java +++ b/jdk/src/share/classes/java/util/stream/Stream.java @@ -657,7 +657,7 @@ public interface Stream extends BaseStream> { * @see #collect(Supplier, BiConsumer, BiConsumer) * @see Collectors */ - R collect(Collector collector); + R collect(Collector collector); /** * Returns the minimum element of this stream according to the provided From 7bc062de1deb8ae4c5cca937970e1fb5794946d0 Mon Sep 17 00:00:00 2001 From: Brian Goetz Date: Tue, 3 Sep 2013 12:16:01 -0700 Subject: [PATCH 011/210] 8017513: Support for closeable streams 8022237: j.u.s.BaseStream.onClose() has an issue in implementation or requires spec clarification 8022572: Same exception instances thrown from j.u.stream.Stream.onClose() handlers are not listed as suppressed BaseStream implements AutoCloseable; Remove CloseableStream and DelegatingStream Reviewed-by: alanb, mduigou, psandoz --- .../share/classes/java/nio/file/Files.java | 298 +++++++++++------- .../java/util/stream/AbstractPipeline.java | 44 ++- .../classes/java/util/stream/BaseStream.java | 32 +- .../java/util/stream/CloseableStream.java | 57 ---- .../java/util/stream/DelegatingStream.java | 270 ---------------- .../java/util/stream/DoublePipeline.java | 9 +- .../java/util/stream/DoubleStream.java | 6 +- .../classes/java/util/stream/IntPipeline.java | 9 +- .../classes/java/util/stream/IntStream.java | 6 +- .../java/util/stream/LongPipeline.java | 9 +- .../classes/java/util/stream/LongStream.java | 6 +- .../java/util/stream/ReferencePipeline.java | 36 ++- .../classes/java/util/stream/Stream.java | 6 +- .../classes/java/util/stream/Streams.java | 57 ++++ jdk/test/java/nio/file/Files/StreamTest.java | 103 +++--- .../util/stream/DoubleStreamTestScenario.java | 3 +- .../util/stream/IntStreamTestScenario.java | 3 +- .../util/stream/LongStreamTestScenario.java | 3 +- .../java/util/stream/StreamTestScenario.java | 3 +- .../java/util/stream/StreamCloseTest.java | 166 ++++++++++ 20 files changed, 578 insertions(+), 548 deletions(-) delete mode 100644 jdk/src/share/classes/java/util/stream/CloseableStream.java delete mode 100644 jdk/src/share/classes/java/util/stream/DelegatingStream.java create mode 100644 jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/StreamCloseTest.java diff --git a/jdk/src/share/classes/java/nio/file/Files.java b/jdk/src/share/classes/java/nio/file/Files.java index 721184c1533..f084040c179 100644 --- a/jdk/src/share/classes/java/nio/file/Files.java +++ b/jdk/src/share/classes/java/nio/file/Files.java @@ -25,34 +25,56 @@ package java.nio.file; -import java.nio.file.attribute.*; -import java.nio.file.spi.FileSystemProvider; -import java.nio.file.spi.FileTypeDetector; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.Closeable; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.Reader; +import java.io.UncheckedIOException; +import java.io.Writer; import java.nio.channels.Channels; import java.nio.channels.FileChannel; import java.nio.channels.SeekableByteChannel; -import java.io.Closeable; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.Reader; -import java.io.Writer; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.io.IOException; -import java.io.UncheckedIOException; -import java.util.*; -import java.util.function.BiPredicate; -import java.util.stream.CloseableStream; -import java.util.stream.DelegatingStream; -import java.util.stream.Stream; -import java.util.stream.StreamSupport; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.nio.charset.Charset; import java.nio.charset.CharsetDecoder; import java.nio.charset.CharsetEncoder; +import java.nio.file.attribute.BasicFileAttributeView; +import java.nio.file.attribute.BasicFileAttributes; +import java.nio.file.attribute.DosFileAttributes; +import java.nio.file.attribute.FileAttribute; +import java.nio.file.attribute.FileAttributeView; +import java.nio.file.attribute.FileOwnerAttributeView; +import java.nio.file.attribute.FileStoreAttributeView; +import java.nio.file.attribute.FileTime; +import java.nio.file.attribute.PosixFileAttributeView; +import java.nio.file.attribute.PosixFileAttributes; +import java.nio.file.attribute.PosixFilePermission; +import java.nio.file.attribute.UserPrincipal; +import java.nio.file.spi.FileSystemProvider; +import java.nio.file.spi.FileTypeDetector; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.EnumSet; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.ServiceLoader; +import java.util.Set; +import java.util.Spliterator; +import java.util.Spliterators; +import java.util.function.BiPredicate; +import java.util.stream.Stream; +import java.util.stream.StreamSupport; /** * This class consists exclusively of static methods that operate on files, @@ -74,6 +96,21 @@ public final class Files { return path.getFileSystem().provider(); } + /** + * Convert a Closeable to a Runnable by converting checked IOException + * to UncheckedIOException + */ + private static Runnable asUncheckedRunnable(Closeable c) { + return () -> { + try { + c.close(); + } + catch (IOException e) { + throw new UncheckedIOException(e); + } + }; + } + // -- File contents -- /** @@ -3228,29 +3265,7 @@ public final class Files { // -- Stream APIs -- /** - * Implementation of CloseableStream - */ - private static class DelegatingCloseableStream extends DelegatingStream - implements CloseableStream - { - private final Closeable closeable; - - DelegatingCloseableStream(Closeable c, Stream delegate) { - super(delegate); - this.closeable = c; - } - - public void close() { - try { - closeable.close(); - } catch (IOException ex) { - throw new UncheckedIOException(ex); - } - } - } - - /** - * Return a lazily populated {@code CloseableStream}, the elements of + * Return a lazily populated {@code Stream}, the elements of * which are the entries in the directory. The listing is not recursive. * *

The elements of the stream are {@link Path} objects that are @@ -3264,10 +3279,13 @@ public final class Files { * reflect updates to the directory that occur after returning from this * method. * - *

When not using the try-with-resources construct, then the stream's - * {@link CloseableStream#close close} method should be invoked after the - * operation is completed so as to free any resources held for the open - * directory. Operating on a closed stream behaves as if the end of stream + *

The returned stream encapsulates a {@link DirectoryStream}. + * If timely disposal of file system resources is required, the + * {@code try}-with-resources construct should be used to ensure that the + * stream's {@link Stream#close close} method is invoked after the stream + * operations are completed. + * + *

Operating on a closed stream behaves as if the end of stream * has been reached. Due to read-ahead, one or more elements may be * returned after the stream has been closed. * @@ -3278,7 +3296,7 @@ public final class Files { * * @param dir The path to the directory * - * @return The {@code CloseableStream} describing the content of the + * @return The {@code Stream} describing the content of the * directory * * @throws NotDirectoryException @@ -3294,43 +3312,54 @@ public final class Files { * @see #newDirectoryStream(Path) * @since 1.8 */ - public static CloseableStream list(Path dir) throws IOException { + public static Stream list(Path dir) throws IOException { DirectoryStream ds = Files.newDirectoryStream(dir); - final Iterator delegate = ds.iterator(); + try { + final Iterator delegate = ds.iterator(); - // Re-wrap DirectoryIteratorException to UncheckedIOException - Iterator it = new Iterator() { - public boolean hasNext() { - try { - return delegate.hasNext(); - } catch (DirectoryIteratorException e) { - throw new UncheckedIOException(e.getCause()); + // Re-wrap DirectoryIteratorException to UncheckedIOException + Iterator it = new Iterator() { + @Override + public boolean hasNext() { + try { + return delegate.hasNext(); + } catch (DirectoryIteratorException e) { + throw new UncheckedIOException(e.getCause()); + } } - } - public Path next() { - try { - return delegate.next(); - } catch (DirectoryIteratorException e) { - throw new UncheckedIOException(e.getCause()); + @Override + public Path next() { + try { + return delegate.next(); + } catch (DirectoryIteratorException e) { + throw new UncheckedIOException(e.getCause()); + } } - } - }; + }; - Stream s = StreamSupport.stream( - Spliterators.spliteratorUnknownSize(it, Spliterator.DISTINCT), - false); - return new DelegatingCloseableStream<>(ds, s); + return StreamSupport.stream(Spliterators.spliteratorUnknownSize(it, Spliterator.DISTINCT), false) + .onClose(asUncheckedRunnable(ds)); + } catch (Error|RuntimeException e) { + try { + ds.close(); + } catch (IOException ex) { + try { + e.addSuppressed(ex); + } catch (Throwable ignore) {} + } + throw e; + } } /** - * Return a {@code CloseableStream} that is lazily populated with {@code + * Return a {@code Stream} that is lazily populated with {@code * Path} by walking the file tree rooted at a given starting file. The * file tree is traversed depth-first, the elements in the stream * are {@link Path} objects that are obtained as if by {@link * Path#resolve(Path) resolving} the relative path against {@code start}. * *

The {@code stream} walks the file tree as elements are consumed. - * The {@code CloseableStream} returned is guaranteed to have at least one + * The {@code Stream} returned is guaranteed to have at least one * element, the starting file itself. For each file visited, the stream * attempts to read its {@link BasicFileAttributes}. If the file is a * directory and can be opened successfully, entries in the directory, and @@ -3370,10 +3399,11 @@ public final class Files { *

When a security manager is installed and it denies access to a file * (or directory), then it is ignored and not included in the stream. * - *

When not using the try-with-resources construct, then the stream's - * {@link CloseableStream#close close} method should be invoked after the - * operation is completed so as to free any resources held for the open - * directory. Operate the stream after it is closed will throw an + *

The returned stream encapsulates one or more {@link DirectoryStream}s. + * If timely disposal of file system resources is required, the + * {@code try}-with-resources construct should be used to ensure that the + * stream's {@link Stream#close close} method is invoked after the stream + * operations are completed. Operating on a closed stream will result in an * {@link java.lang.IllegalStateException}. * *

If an {@link IOException} is thrown when accessing the directory @@ -3388,7 +3418,7 @@ public final class Files { * @param options * options to configure the traversal * - * @return the {@link CloseableStream} of {@link Path} + * @return the {@link Stream} of {@link Path} * * @throws IllegalArgumentException * if the {@code maxDepth} parameter is negative @@ -3401,21 +3431,22 @@ public final class Files { * if an I/O error is thrown when accessing the starting file. * @since 1.8 */ - public static CloseableStream walk(Path start, int maxDepth, - FileVisitOption... options) - throws IOException - { + public static Stream walk(Path start, int maxDepth, + FileVisitOption... options) + throws IOException { FileTreeIterator iterator = new FileTreeIterator(start, maxDepth, options); - - Stream s = StreamSupport.stream( - Spliterators.spliteratorUnknownSize(iterator, Spliterator.DISTINCT), - false). - map(entry -> entry.file()); - return new DelegatingCloseableStream<>(iterator, s); + try { + return StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.DISTINCT), false) + .onClose(iterator::close) + .map(entry -> entry.file()); + } catch (Error|RuntimeException e) { + iterator.close(); + throw e; + } } /** - * Return a {@code CloseableStream} that is lazily populated with {@code + * Return a {@code Stream} that is lazily populated with {@code * Path} by walking the file tree rooted at a given starting file. The * file tree is traversed depth-first, the elements in the stream * are {@link Path} objects that are obtained as if by {@link @@ -3428,12 +3459,19 @@ public final class Files { * * In other words, it visits all levels of the file tree. * + *

The returned stream encapsulates one or more {@link DirectoryStream}s. + * If timely disposal of file system resources is required, the + * {@code try}-with-resources construct should be used to ensure that the + * stream's {@link Stream#close close} method is invoked after the stream + * operations are completed. Operating on a closed stream will result in an + * {@link java.lang.IllegalStateException}. + * * @param start * the starting file * @param options * options to configure the traversal * - * @return the {@link CloseableStream} of {@link Path} + * @return the {@link Stream} of {@link Path} * * @throws SecurityException * If the security manager denies access to the starting file. @@ -3446,15 +3484,14 @@ public final class Files { * @see #walk(Path, int, FileVisitOption...) * @since 1.8 */ - public static CloseableStream walk(Path start, - FileVisitOption... options) - throws IOException - { + public static Stream walk(Path start, + FileVisitOption... options) + throws IOException { return walk(start, Integer.MAX_VALUE, options); } /** - * Return a {@code CloseableStream} that is lazily populated with {@code + * Return a {@code Stream} that is lazily populated with {@code * Path} by searching for files in a file tree rooted at a given starting * file. * @@ -3463,12 +3500,19 @@ public final class Files { * {@link BiPredicate} is invoked with its {@link Path} and {@link * BasicFileAttributes}. The {@code Path} object is obtained as if by * {@link Path#resolve(Path) resolving} the relative path against {@code - * start} and is only included in the returned {@link CloseableStream} if + * start} and is only included in the returned {@link Stream} if * the {@code BiPredicate} returns true. Compare to calling {@link * java.util.stream.Stream#filter filter} on the {@code Stream} * returned by {@code walk} method, this method may be more efficient by * avoiding redundant retrieval of the {@code BasicFileAttributes}. * + *

The returned stream encapsulates one or more {@link DirectoryStream}s. + * If timely disposal of file system resources is required, the + * {@code try}-with-resources construct should be used to ensure that the + * stream's {@link Stream#close close} method is invoked after the stream + * operations are completed. Operating on a closed stream will result in an + * {@link java.lang.IllegalStateException}. + * *

If an {@link IOException} is thrown when accessing the directory * after returned from this method, it is wrapped in an {@link * UncheckedIOException} which will be thrown from the method that caused @@ -3484,7 +3528,7 @@ public final class Files { * @param options * options to configure the traversal * - * @return the {@link CloseableStream} of {@link Path} + * @return the {@link Stream} of {@link Path} * * @throws IllegalArgumentException * if the {@code maxDepth} parameter is negative @@ -3499,24 +3543,25 @@ public final class Files { * @see #walk(Path, int, FileVisitOption...) * @since 1.8 */ - public static CloseableStream find(Path start, - int maxDepth, - BiPredicate matcher, - FileVisitOption... options) - throws IOException - { + public static Stream find(Path start, + int maxDepth, + BiPredicate matcher, + FileVisitOption... options) + throws IOException { FileTreeIterator iterator = new FileTreeIterator(start, maxDepth, options); - - Stream s = StreamSupport.stream( - Spliterators.spliteratorUnknownSize(iterator, Spliterator.DISTINCT), - false). - filter(entry -> matcher.test(entry.file(), entry.attributes())). - map(entry -> entry.file()); - return new DelegatingCloseableStream<>(iterator, s); + try { + return StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.DISTINCT), false) + .onClose(iterator::close) + .filter(entry -> matcher.test(entry.file(), entry.attributes())) + .map(entry -> entry.file()); + } catch (Error|RuntimeException e) { + iterator.close(); + throw e; + } } /** - * Read all lines from a file as a {@code CloseableStream}. Unlike {@link + * Read all lines from a file as a {@code Stream}. Unlike {@link * #readAllLines(Path, Charset) readAllLines}, this method does not read * all lines into a {@code List}, but instead populates lazily as the stream * is consumed. @@ -3528,22 +3573,24 @@ public final class Files { *

After this method returns, then any subsequent I/O exception that * occurs while reading from the file or when a malformed or unmappable byte * sequence is read, is wrapped in an {@link UncheckedIOException} that will - * be thrown form the + * be thrown from the * {@link java.util.stream.Stream} method that caused the read to take * place. In case an {@code IOException} is thrown when closing the file, * it is also wrapped as an {@code UncheckedIOException}. * - *

When not using the try-with-resources construct, then stream's - * {@link CloseableStream#close close} method should be invoked after - * operation is completed so as to free any resources held for the open - * file. + *

The returned stream encapsulates a {@link Reader}. If timely + * disposal of file system resources is required, the try-with-resources + * construct should be used to ensure that the stream's + * {@link Stream#close close} method is invoked after the stream operations + * are completed. + * * * @param path * the path to the file * @param cs * the charset to use for decoding * - * @return the lines from the file as a {@code CloseableStream} + * @return the lines from the file as a {@code Stream} * * @throws IOException * if an I/O error occurs opening the file @@ -3557,10 +3604,19 @@ public final class Files { * @see java.io.BufferedReader#lines() * @since 1.8 */ - public static CloseableStream lines(Path path, Charset cs) - throws IOException - { + public static Stream lines(Path path, Charset cs) throws IOException { BufferedReader br = Files.newBufferedReader(path, cs); - return new DelegatingCloseableStream<>(br, br.lines()); + try { + return br.lines().onClose(asUncheckedRunnable(br)); + } catch (Error|RuntimeException e) { + try { + br.close(); + } catch (IOException ex) { + try { + e.addSuppressed(ex); + } catch (Throwable ignore) {} + } + throw e; + } } } diff --git a/jdk/src/share/classes/java/util/stream/AbstractPipeline.java b/jdk/src/share/classes/java/util/stream/AbstractPipeline.java index 3b2f5bdc5f7..dd60c2520e4 100644 --- a/jdk/src/share/classes/java/util/stream/AbstractPipeline.java +++ b/jdk/src/share/classes/java/util/stream/AbstractPipeline.java @@ -71,6 +71,9 @@ import java.util.function.Supplier; */ abstract class AbstractPipeline> extends PipelineHelper implements BaseStream { + private static final String MSG_STREAM_LINKED = "stream has already been operated upon or closed"; + private static final String MSG_CONSUMED = "source already consumed or closed"; + /** * Backlink to the head of the pipeline chain (self if this is the source * stage). @@ -137,6 +140,8 @@ abstract class AbstractPipeline> */ private boolean sourceAnyStateful; + private Runnable sourceCloseAction; + /** * True if pipeline is parallel, otherwise the pipeline is sequential; only * valid for the source stage. @@ -195,7 +200,7 @@ abstract class AbstractPipeline> */ AbstractPipeline(AbstractPipeline previousStage, int opFlags) { if (previousStage.linkedOrConsumed) - throw new IllegalStateException("stream has already been operated upon"); + throw new IllegalStateException(MSG_STREAM_LINKED); previousStage.linkedOrConsumed = true; previousStage.nextStage = this; @@ -221,7 +226,7 @@ abstract class AbstractPipeline> final R evaluate(TerminalOp terminalOp) { assert getOutputShape() == terminalOp.inputShape(); if (linkedOrConsumed) - throw new IllegalStateException("stream has already been operated upon"); + throw new IllegalStateException(MSG_STREAM_LINKED); linkedOrConsumed = true; return isParallel() @@ -238,7 +243,7 @@ abstract class AbstractPipeline> @SuppressWarnings("unchecked") final Node evaluateToArrayNode(IntFunction generator) { if (linkedOrConsumed) - throw new IllegalStateException("stream has already been operated upon"); + throw new IllegalStateException(MSG_STREAM_LINKED); linkedOrConsumed = true; // If the last intermediate operation is stateful then @@ -266,7 +271,7 @@ abstract class AbstractPipeline> throw new IllegalStateException(); if (linkedOrConsumed) - throw new IllegalStateException("stream has already been operated upon"); + throw new IllegalStateException(MSG_STREAM_LINKED); linkedOrConsumed = true; if (sourceStage.sourceSpliterator != null) { @@ -282,7 +287,7 @@ abstract class AbstractPipeline> return s; } else { - throw new IllegalStateException("source already consumed"); + throw new IllegalStateException(MSG_CONSUMED); } } @@ -302,12 +307,35 @@ abstract class AbstractPipeline> return (S) this; } + @Override + public void close() { + linkedOrConsumed = true; + sourceSupplier = null; + sourceSpliterator = null; + if (sourceStage.sourceCloseAction != null) { + Runnable closeAction = sourceStage.sourceCloseAction; + sourceStage.sourceCloseAction = null; + closeAction.run(); + } + } + + @Override + @SuppressWarnings("unchecked") + public S onClose(Runnable closeHandler) { + Runnable existingHandler = sourceStage.sourceCloseAction; + sourceStage.sourceCloseAction = + (existingHandler == null) + ? closeHandler + : Streams.composeWithExceptions(existingHandler, closeHandler); + return (S) this; + } + // Primitive specialization use co-variant overrides, hence is not final @Override @SuppressWarnings("unchecked") public Spliterator spliterator() { if (linkedOrConsumed) - throw new IllegalStateException("stream has already been operated upon"); + throw new IllegalStateException(MSG_STREAM_LINKED); linkedOrConsumed = true; if (this == sourceStage) { @@ -324,7 +352,7 @@ abstract class AbstractPipeline> return lazySpliterator(s); } else { - throw new IllegalStateException("source already consumed"); + throw new IllegalStateException(MSG_CONSUMED); } } else { @@ -424,7 +452,7 @@ abstract class AbstractPipeline> sourceStage.sourceSupplier = null; } else { - throw new IllegalStateException("source already consumed"); + throw new IllegalStateException(MSG_CONSUMED); } if (isParallel()) { diff --git a/jdk/src/share/classes/java/util/stream/BaseStream.java b/jdk/src/share/classes/java/util/stream/BaseStream.java index 94dbc7de73f..9c87a309098 100644 --- a/jdk/src/share/classes/java/util/stream/BaseStream.java +++ b/jdk/src/share/classes/java/util/stream/BaseStream.java @@ -35,7 +35,8 @@ import java.util.Spliterator; * @param type of stream implementing {@code BaseStream} * @since 1.8 */ -public interface BaseStream> { +public interface BaseStream> + extends AutoCloseable { /** * Returns an iterator for the elements of this stream. * @@ -103,4 +104,33 @@ public interface BaseStream> { * @return an unordered stream */ S unordered(); + + /** + * Returns an equivalent stream with an additional close handler. Close + * handlers are run when the {@link #close()} method + * is called on the stream, and are executed in the order they were + * added. All close handlers are run, even if earlier close handlers throw + * exceptions. If any close handler throws an exception, the first + * exception thrown will be relayed to the caller of {@code close()}, with + * any remaining exceptions added to that exception as suppressed exceptions + * (unless one of the remaining exceptions is the same exception as the + * first exception, since an exception cannot suppress itself.) May + * return itself. + * + *

This is an intermediate + * operation. + * + * @param closeHandler A task to execute when the stream is closed + * @return a stream with a handler that is run if the stream is closed + */ + S onClose(Runnable closeHandler); + + /** + * Closes this stream, causing all close handlers for this stream pipeline + * to be called. + * + * @see AutoCloseable#close() + */ + @Override + void close(); } diff --git a/jdk/src/share/classes/java/util/stream/CloseableStream.java b/jdk/src/share/classes/java/util/stream/CloseableStream.java deleted file mode 100644 index bbcce516f99..00000000000 --- a/jdk/src/share/classes/java/util/stream/CloseableStream.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2013, 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 java.util.stream; - -/** - * A {@code CloseableStream} is a {@code Stream} that can be closed. - * The close method is invoked to release resources that the object is - * holding (such as open files). - * - * @param The type of stream elements - * @since 1.8 - */ -public interface CloseableStream extends Stream, AutoCloseable { - - /** - * Closes this resource, relinquishing any underlying resources. - * This method is invoked automatically on objects managed by the - * {@code try}-with-resources statement. Does nothing if called when - * the resource has already been closed. - * - * This method does not allow throwing checked {@code Exception}s like - * {@link AutoCloseable#close() AutoCloseable.close()}. Cases where the - * close operation may fail require careful attention by implementers. It - * is strongly advised to relinquish the underlying resources and to - * internally mark the resource as closed. The {@code close} - * method is unlikely to be invoked more than once and so this ensures - * that the resources are released in a timely manner. Furthermore it - * reduces problems that could arise when the resource wraps, or is - * wrapped, by another resource. - * - * @see AutoCloseable#close() - */ - void close(); -} diff --git a/jdk/src/share/classes/java/util/stream/DelegatingStream.java b/jdk/src/share/classes/java/util/stream/DelegatingStream.java deleted file mode 100644 index fbe7735a515..00000000000 --- a/jdk/src/share/classes/java/util/stream/DelegatingStream.java +++ /dev/null @@ -1,270 +0,0 @@ -/* - * Copyright (c) 2013, 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 java.util.stream; - -import java.util.Comparator; -import java.util.Iterator; -import java.util.Objects; -import java.util.Optional; -import java.util.Spliterator; -import java.util.function.BiConsumer; -import java.util.function.BiFunction; -import java.util.function.BinaryOperator; -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.function.IntFunction; -import java.util.function.Predicate; -import java.util.function.Supplier; -import java.util.function.ToDoubleFunction; -import java.util.function.ToIntFunction; -import java.util.function.ToLongFunction; - -/** - * A {@code Stream} implementation that delegates operations to another {@code - * Stream}. - * - * @param type of stream elements for this stream and underlying delegate - * stream - * - * @since 1.8 - */ -public class DelegatingStream implements Stream { - final private Stream delegate; - - /** - * Construct a {@code Stream} that delegates operations to another {@code - * Stream}. - * - * @param delegate the underlying {@link Stream} to which we delegate all - * {@code Stream} methods - * @throws NullPointerException if the delegate is null - */ - public DelegatingStream(Stream delegate) { - this.delegate = Objects.requireNonNull(delegate); - } - - // -- BaseStream methods -- - - @Override - public Spliterator spliterator() { - return delegate.spliterator(); - } - - @Override - public boolean isParallel() { - return delegate.isParallel(); - } - - @Override - public Iterator iterator() { - return delegate.iterator(); - } - - // -- Stream methods -- - - @Override - public Stream filter(Predicate predicate) { - return delegate.filter(predicate); - } - - @Override - public Stream map(Function mapper) { - return delegate.map(mapper); - } - - @Override - public IntStream mapToInt(ToIntFunction mapper) { - return delegate.mapToInt(mapper); - } - - @Override - public LongStream mapToLong(ToLongFunction mapper) { - return delegate.mapToLong(mapper); - } - - @Override - public DoubleStream mapToDouble(ToDoubleFunction mapper) { - return delegate.mapToDouble(mapper); - } - - @Override - public Stream flatMap(Function> mapper) { - return delegate.flatMap(mapper); - } - - @Override - public IntStream flatMapToInt(Function mapper) { - return delegate.flatMapToInt(mapper); - } - - @Override - public LongStream flatMapToLong(Function mapper) { - return delegate.flatMapToLong(mapper); - } - - @Override - public DoubleStream flatMapToDouble(Function mapper) { - return delegate.flatMapToDouble(mapper); - } - - @Override - public Stream distinct() { - return delegate.distinct(); - } - - @Override - public Stream sorted() { - return delegate.sorted(); - } - - @Override - public Stream sorted(Comparator comparator) { - return delegate.sorted(comparator); - } - - @Override - public void forEach(Consumer action) { - delegate.forEach(action); - } - - @Override - public void forEachOrdered(Consumer action) { - delegate.forEachOrdered(action); - } - - @Override - public Stream peek(Consumer consumer) { - return delegate.peek(consumer); - } - - @Override - public Stream limit(long maxSize) { - return delegate.limit(maxSize); - } - - @Override - public Stream substream(long startingOffset) { - return delegate.substream(startingOffset); - } - - @Override - public Stream substream(long startingOffset, long endingOffset) { - return delegate.substream(startingOffset, endingOffset); - } - - @Override - public A[] toArray(IntFunction generator) { - return delegate.toArray(generator); - } - - @Override - public Object[] toArray() { - return delegate.toArray(); - } - - @Override - public T reduce(T identity, BinaryOperator accumulator) { - return delegate.reduce(identity, accumulator); - } - - @Override - public Optional reduce(BinaryOperator accumulator) { - return delegate.reduce(accumulator); - } - - @Override - public U reduce(U identity, BiFunction accumulator, - BinaryOperator combiner) { - return delegate.reduce(identity, accumulator, combiner); - } - - @Override - public R collect(Supplier resultFactory, - BiConsumer accumulator, - BiConsumer combiner) { - return delegate.collect(resultFactory, accumulator, combiner); - } - - @Override - public R collect(Collector collector) { - return delegate.collect(collector); - } - - @Override - public Optional max(Comparator comparator) { - return delegate.max(comparator); - } - - @Override - public Optional min(Comparator comparator) { - return delegate.min(comparator); - } - - @Override - public long count() { - return delegate.count(); - } - - @Override - public boolean anyMatch(Predicate predicate) { - return delegate.anyMatch(predicate); - } - - @Override - public boolean allMatch(Predicate predicate) { - return delegate.allMatch(predicate); - } - - @Override - public boolean noneMatch(Predicate predicate) { - return delegate.noneMatch(predicate); - } - - @Override - public Optional findFirst() { - return delegate.findFirst(); - } - - @Override - public Optional findAny() { - return delegate.findAny(); - } - - @Override - public Stream unordered() { - return delegate.unordered(); - } - - @Override - public Stream sequential() { - return delegate.sequential(); - } - - @Override - public Stream parallel() { - return delegate.parallel(); - } -} diff --git a/jdk/src/share/classes/java/util/stream/DoublePipeline.java b/jdk/src/share/classes/java/util/stream/DoublePipeline.java index f894fa0abb9..75981d5801f 100644 --- a/jdk/src/share/classes/java/util/stream/DoublePipeline.java +++ b/jdk/src/share/classes/java/util/stream/DoublePipeline.java @@ -266,10 +266,11 @@ abstract class DoublePipeline @Override public void accept(double t) { - // We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it - DoubleStream result = mapper.apply(t); - if (result != null) - result.sequential().forEach(i -> downstream.accept(i)); + try (DoubleStream result = mapper.apply(t)) { + // We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it + if (result != null) + result.sequential().forEach(i -> downstream.accept(i)); + } } }; } diff --git a/jdk/src/share/classes/java/util/stream/DoubleStream.java b/jdk/src/share/classes/java/util/stream/DoubleStream.java index 93a83991e0b..bf356926154 100644 --- a/jdk/src/share/classes/java/util/stream/DoubleStream.java +++ b/jdk/src/share/classes/java/util/stream/DoubleStream.java @@ -752,7 +752,8 @@ public interface DoubleStream extends BaseStream { * elements of a first {@code DoubleStream} succeeded by all the elements of the * second {@code DoubleStream}. The resulting stream is ordered if both * of the input streams are ordered, and parallel if either of the input - * streams is parallel. + * streams is parallel. When the resulting stream is closed, the close + * handlers for both input streams are invoked. * * @param a the first stream * @param b the second stream to concatenate on to end of the first stream @@ -764,7 +765,8 @@ public interface DoubleStream extends BaseStream { Spliterator.OfDouble split = new Streams.ConcatSpliterator.OfDouble( a.spliterator(), b.spliterator()); - return StreamSupport.doubleStream(split, a.isParallel() || b.isParallel()); + DoubleStream stream = StreamSupport.doubleStream(split, a.isParallel() || b.isParallel()); + return stream.onClose(Streams.composedClose(a, b)); } /** diff --git a/jdk/src/share/classes/java/util/stream/IntPipeline.java b/jdk/src/share/classes/java/util/stream/IntPipeline.java index f7dc79317d3..f35bc1d7a8e 100644 --- a/jdk/src/share/classes/java/util/stream/IntPipeline.java +++ b/jdk/src/share/classes/java/util/stream/IntPipeline.java @@ -302,10 +302,11 @@ abstract class IntPipeline @Override public void accept(int t) { - // We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it - IntStream result = mapper.apply(t); - if (result != null) - result.sequential().forEach(i -> downstream.accept(i)); + try (IntStream result = mapper.apply(t)) { + // We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it + if (result != null) + result.sequential().forEach(i -> downstream.accept(i)); + } } }; } diff --git a/jdk/src/share/classes/java/util/stream/IntStream.java b/jdk/src/share/classes/java/util/stream/IntStream.java index 883b03cbd3d..c107ca46de9 100644 --- a/jdk/src/share/classes/java/util/stream/IntStream.java +++ b/jdk/src/share/classes/java/util/stream/IntStream.java @@ -806,7 +806,8 @@ public interface IntStream extends BaseStream { * elements of a first {@code IntStream} succeeded by all the elements of the * second {@code IntStream}. The resulting stream is ordered if both * of the input streams are ordered, and parallel if either of the input - * streams is parallel. + * streams is parallel. When the resulting stream is closed, the close + * handlers for both input streams are invoked. * * @param a the first stream * @param b the second stream to concatenate on to end of the first stream @@ -818,7 +819,8 @@ public interface IntStream extends BaseStream { Spliterator.OfInt split = new Streams.ConcatSpliterator.OfInt( a.spliterator(), b.spliterator()); - return StreamSupport.intStream(split, a.isParallel() || b.isParallel()); + IntStream stream = StreamSupport.intStream(split, a.isParallel() || b.isParallel()); + return stream.onClose(Streams.composedClose(a, b)); } /** diff --git a/jdk/src/share/classes/java/util/stream/LongPipeline.java b/jdk/src/share/classes/java/util/stream/LongPipeline.java index 3c199feab59..a59ec3f5f00 100644 --- a/jdk/src/share/classes/java/util/stream/LongPipeline.java +++ b/jdk/src/share/classes/java/util/stream/LongPipeline.java @@ -283,10 +283,11 @@ abstract class LongPipeline @Override public void accept(long t) { - // We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it - LongStream result = mapper.apply(t); - if (result != null) - result.sequential().forEach(i -> downstream.accept(i)); + try (LongStream result = mapper.apply(t)) { + // We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it + if (result != null) + result.sequential().forEach(i -> downstream.accept(i)); + } } }; } diff --git a/jdk/src/share/classes/java/util/stream/LongStream.java b/jdk/src/share/classes/java/util/stream/LongStream.java index 8fce0d68d65..e64c67204dc 100644 --- a/jdk/src/share/classes/java/util/stream/LongStream.java +++ b/jdk/src/share/classes/java/util/stream/LongStream.java @@ -812,7 +812,8 @@ public interface LongStream extends BaseStream { * elements of a first {@code LongStream} succeeded by all the elements of the * second {@code LongStream}. The resulting stream is ordered if both * of the input streams are ordered, and parallel if either of the input - * streams is parallel. + * streams is parallel. When the resulting stream is closed, the close + * handlers for both input streams are invoked. * * @param a the first stream * @param b the second stream to concatenate on to end of the first stream @@ -824,7 +825,8 @@ public interface LongStream extends BaseStream { Spliterator.OfLong split = new Streams.ConcatSpliterator.OfLong( a.spliterator(), b.spliterator()); - return StreamSupport.longStream(split, a.isParallel() || b.isParallel()); + LongStream stream = StreamSupport.longStream(split, a.isParallel() || b.isParallel()); + return stream.onClose(Streams.composedClose(a, b)); } /** diff --git a/jdk/src/share/classes/java/util/stream/ReferencePipeline.java b/jdk/src/share/classes/java/util/stream/ReferencePipeline.java index 6c6fe647ee9..42d711f4b2b 100644 --- a/jdk/src/share/classes/java/util/stream/ReferencePipeline.java +++ b/jdk/src/share/classes/java/util/stream/ReferencePipeline.java @@ -264,10 +264,11 @@ abstract class ReferencePipeline @Override public void accept(P_OUT u) { - // We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it - Stream result = mapper.apply(u); - if (result != null) - result.sequential().forEach(downstream); + try (Stream result = mapper.apply(u)) { + // We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it + if (result != null) + result.sequential().forEach(downstream); + } } }; } @@ -291,10 +292,11 @@ abstract class ReferencePipeline @Override public void accept(P_OUT u) { - // We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it - IntStream result = mapper.apply(u); - if (result != null) - result.sequential().forEach(downstreamAsInt); + try (IntStream result = mapper.apply(u)) { + // We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it + if (result != null) + result.sequential().forEach(downstreamAsInt); + } } }; } @@ -318,10 +320,11 @@ abstract class ReferencePipeline @Override public void accept(P_OUT u) { - // We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it - DoubleStream result = mapper.apply(u); - if (result != null) - result.sequential().forEach(downstreamAsDouble); + try (DoubleStream result = mapper.apply(u)) { + // We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it + if (result != null) + result.sequential().forEach(downstreamAsDouble); + } } }; } @@ -345,10 +348,11 @@ abstract class ReferencePipeline @Override public void accept(P_OUT u) { - // We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it - LongStream result = mapper.apply(u); - if (result != null) - result.sequential().forEach(downstreamAsLong); + try (LongStream result = mapper.apply(u)) { + // We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it + if (result != null) + result.sequential().forEach(downstreamAsLong); + } } }; } diff --git a/jdk/src/share/classes/java/util/stream/Stream.java b/jdk/src/share/classes/java/util/stream/Stream.java index 1071b20110e..715729f24a7 100644 --- a/jdk/src/share/classes/java/util/stream/Stream.java +++ b/jdk/src/share/classes/java/util/stream/Stream.java @@ -891,7 +891,8 @@ public interface Stream extends BaseStream> { * elements of a first {@code Stream} succeeded by all the elements of the * second {@code Stream}. The resulting stream is ordered if both * of the input streams are ordered, and parallel if either of the input - * streams is parallel. + * streams is parallel. When the resulting stream is closed, the close + * handlers for both input streams are invoked. * * @param The type of stream elements * @param a the first stream @@ -906,7 +907,8 @@ public interface Stream extends BaseStream> { @SuppressWarnings("unchecked") Spliterator split = new Streams.ConcatSpliterator.OfRef<>( (Spliterator) a.spliterator(), (Spliterator) b.spliterator()); - return StreamSupport.stream(split, a.isParallel() || b.isParallel()); + Stream stream = StreamSupport.stream(split, a.isParallel() || b.isParallel()); + return stream.onClose(Streams.composedClose(a, b)); } /** diff --git a/jdk/src/share/classes/java/util/stream/Streams.java b/jdk/src/share/classes/java/util/stream/Streams.java index 15c3dcae497..8af33f2b3c2 100644 --- a/jdk/src/share/classes/java/util/stream/Streams.java +++ b/jdk/src/share/classes/java/util/stream/Streams.java @@ -833,4 +833,61 @@ final class Streams { } } } + + /** + * Given two Runnables, return a Runnable that executes both in sequence, + * even if the first throws an exception, and if both throw exceptions, add + * any exceptions thrown by the second as suppressed exceptions of the first. + */ + static Runnable composeWithExceptions(Runnable a, Runnable b) { + return new Runnable() { + @Override + public void run() { + try { + a.run(); + } + catch (Throwable e1) { + try { + b.run(); + } + catch (Throwable e2) { + try { + e1.addSuppressed(e2); + } catch (Throwable ignore) {} + } + throw e1; + } + b.run(); + } + }; + } + + /** + * Given two streams, return a Runnable that + * executes both of their {@link BaseStream#close} methods in sequence, + * even if the first throws an exception, and if both throw exceptions, add + * any exceptions thrown by the second as suppressed exceptions of the first. + */ + static Runnable composedClose(BaseStream a, BaseStream b) { + return new Runnable() { + @Override + public void run() { + try { + a.close(); + } + catch (Throwable e1) { + try { + b.close(); + } + catch (Throwable e2) { + try { + e1.addSuppressed(e2); + } catch (Throwable ignore) {} + } + throw e1; + } + b.close(); + } + }; + } } diff --git a/jdk/test/java/nio/file/Files/StreamTest.java b/jdk/test/java/nio/file/Files/StreamTest.java index b5ff2977257..5304492f1db 100644 --- a/jdk/test/java/nio/file/Files/StreamTest.java +++ b/jdk/test/java/nio/file/Files/StreamTest.java @@ -43,14 +43,13 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.attribute.BasicFileAttributes; import java.util.Arrays; -import java.util.Comparator; import java.util.Iterator; import java.util.List; import java.util.Objects; import java.util.Set; import java.util.TreeSet; import java.util.function.BiPredicate; -import java.util.stream.CloseableStream; +import java.util.stream.Stream; import java.util.stream.Collectors; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; @@ -138,14 +137,14 @@ public class StreamTest { } public void testBasic() { - try (CloseableStream s = Files.list(testFolder)) { - Object[] actual = s.sorted(Comparator.naturalOrder()).toArray(); + try (Stream s = Files.list(testFolder)) { + Object[] actual = s.sorted().toArray(); assertEquals(actual, level1); } catch (IOException ioe) { fail("Unexpected IOException"); } - try (CloseableStream s = Files.list(testFolder.resolve("empty"))) { + try (Stream s = Files.list(testFolder.resolve("empty"))) { int count = s.mapToInt(p -> 1).reduce(0, Integer::sum); assertEquals(count, 0, "Expect empty stream."); } catch (IOException ioe) { @@ -154,8 +153,8 @@ public class StreamTest { } public void testWalk() { - try (CloseableStream s = Files.walk(testFolder)) { - Object[] actual = s.sorted(Comparator.naturalOrder()).toArray(); + try (Stream s = Files.walk(testFolder)) { + Object[] actual = s.sorted().toArray(); assertEquals(actual, all); } catch (IOException ioe) { fail("Unexpected IOException"); @@ -163,9 +162,9 @@ public class StreamTest { } public void testWalkOneLevel() { - try (CloseableStream s = Files.walk(testFolder, 1)) { + try (Stream s = Files.walk(testFolder, 1)) { Object[] actual = s.filter(path -> ! path.equals(testFolder)) - .sorted(Comparator.naturalOrder()) + .sorted() .toArray(); assertEquals(actual, level1); } catch (IOException ioe) { @@ -176,8 +175,8 @@ public class StreamTest { public void testWalkFollowLink() { // If link is not supported, the directory structure won't have link. // We still want to test the behavior with FOLLOW_LINKS option. - try (CloseableStream s = Files.walk(testFolder, FileVisitOption.FOLLOW_LINKS)) { - Object[] actual = s.sorted(Comparator.naturalOrder()).toArray(); + try (Stream s = Files.walk(testFolder, FileVisitOption.FOLLOW_LINKS)) { + Object[] actual = s.sorted().toArray(); assertEquals(actual, all_folowLinks); } catch (IOException ioe) { fail("Unexpected IOException"); @@ -185,7 +184,7 @@ public class StreamTest { } private void validateFileSystemLoopException(Path start, Path... causes) { - try (CloseableStream s = Files.walk(start, FileVisitOption.FOLLOW_LINKS)) { + try (Stream s = Files.walk(start, FileVisitOption.FOLLOW_LINKS)) { try { int count = s.mapToInt(p -> 1).reduce(0, Integer::sum); fail("Should got FileSystemLoopException, but got " + count + "elements."); @@ -282,28 +281,28 @@ public class StreamTest { public void testFind() throws IOException { PathBiPredicate pred = new PathBiPredicate((path, attrs) -> true); - try (CloseableStream s = Files.find(testFolder, Integer.MAX_VALUE, pred)) { + try (Stream s = Files.find(testFolder, Integer.MAX_VALUE, pred)) { Set result = s.collect(Collectors.toCollection(TreeSet::new)); assertEquals(pred.visited(), all); assertEquals(result.toArray(new Path[0]), pred.visited()); } pred = new PathBiPredicate((path, attrs) -> attrs.isSymbolicLink()); - try (CloseableStream s = Files.find(testFolder, Integer.MAX_VALUE, pred)) { + try (Stream s = Files.find(testFolder, Integer.MAX_VALUE, pred)) { s.forEach(path -> assertTrue(Files.isSymbolicLink(path))); assertEquals(pred.visited(), all); } pred = new PathBiPredicate((path, attrs) -> path.getFileName().toString().startsWith("e")); - try (CloseableStream s = Files.find(testFolder, Integer.MAX_VALUE, pred)) { + try (Stream s = Files.find(testFolder, Integer.MAX_VALUE, pred)) { s.forEach(path -> assertEquals(path.getFileName().toString(), "empty")); assertEquals(pred.visited(), all); } pred = new PathBiPredicate((path, attrs) -> path.getFileName().toString().startsWith("l") && attrs.isRegularFile()); - try (CloseableStream s = Files.find(testFolder, Integer.MAX_VALUE, pred)) { + try (Stream s = Files.find(testFolder, Integer.MAX_VALUE, pred)) { s.forEach(path -> fail("Expect empty stream")); assertEquals(pred.visited(), all); } @@ -317,14 +316,14 @@ public class StreamTest { try { // zero lines assertTrue(Files.size(tmpfile) == 0, "File should be empty"); - try (CloseableStream s = Files.lines(tmpfile, US_ASCII)) { + try (Stream s = Files.lines(tmpfile, US_ASCII)) { assertEquals(s.mapToInt(l -> 1).reduce(0, Integer::sum), 0, "No line expected"); } // one line byte[] hi = { (byte)'h', (byte)'i' }; Files.write(tmpfile, hi); - try (CloseableStream s = Files.lines(tmpfile, US_ASCII)) { + try (Stream s = Files.lines(tmpfile, US_ASCII)) { List lines = s.collect(Collectors.toList()); assertTrue(lines.size() == 1, "One line expected"); assertTrue(lines.get(0).equals("hi"), "'Hi' expected"); @@ -334,7 +333,7 @@ public class StreamTest { List expected = Arrays.asList("hi", "there"); Files.write(tmpfile, expected, US_ASCII); assertTrue(Files.size(tmpfile) > 0, "File is empty"); - try (CloseableStream s = Files.lines(tmpfile, US_ASCII)) { + try (Stream s = Files.lines(tmpfile, US_ASCII)) { List lines = s.collect(Collectors.toList()); assertTrue(lines.equals(expected), "Unexpected lines"); } @@ -342,7 +341,7 @@ public class StreamTest { // MalformedInputException byte[] bad = { (byte)0xff, (byte)0xff }; Files.write(tmpfile, bad); - try (CloseableStream s = Files.lines(tmpfile, US_ASCII)) { + try (Stream s = Files.lines(tmpfile, US_ASCII)) { try { List lines = s.collect(Collectors.toList()); throw new RuntimeException("UncheckedIOException expected"); @@ -378,7 +377,7 @@ public class StreamTest { fsp.setFaultyMode(false); Path fakeRoot = fs.getRoot(); try { - try (CloseableStream s = Files.list(fakeRoot)) { + try (Stream s = Files.list(fakeRoot)) { s.forEach(path -> assertEquals(path.getFileName().toString(), "DirectoryIteratorException")); } } catch (UncheckedIOException uioe) { @@ -398,7 +397,7 @@ public class StreamTest { } try { - try (CloseableStream s = Files.list(fakeRoot)) { + try (Stream s = Files.list(fakeRoot)) { s.forEach(path -> fail("should not get here")); } } catch (UncheckedIOException uioe) { @@ -427,12 +426,12 @@ public class StreamTest { try { fsp.setFaultyMode(false); Path fakeRoot = fs.getRoot(); - try (CloseableStream s = Files.list(fakeRoot.resolve("dir2"))) { + try (Stream s = Files.list(fakeRoot.resolve("dir2"))) { // only one file s.forEach(path -> assertEquals(path.getFileName().toString(), "IOException")); } - try (CloseableStream s = Files.walk(fakeRoot.resolve("empty"))) { + try (Stream s = Files.walk(fakeRoot.resolve("empty"))) { String[] result = s.map(path -> path.getFileName().toString()) .toArray(String[]::new); // ordered as depth-first @@ -440,13 +439,13 @@ public class StreamTest { } fsp.setFaultyMode(true); - try (CloseableStream s = Files.list(fakeRoot.resolve("dir2"))) { + try (Stream s = Files.list(fakeRoot.resolve("dir2"))) { s.forEach(path -> fail("should have caused exception")); } catch (UncheckedIOException uioe) { assertTrue(uioe.getCause() instanceof FaultyFileSystem.FaultyException); } - try (CloseableStream s = Files.walk(fakeRoot.resolve("empty"))) { + try (Stream s = Files.walk(fakeRoot.resolve("empty"))) { String[] result = s.map(path -> path.getFileName().toString()) .toArray(String[]::new); fail("should not reach here due to IOException"); @@ -454,7 +453,7 @@ public class StreamTest { assertTrue(uioe.getCause() instanceof FaultyFileSystem.FaultyException); } - try (CloseableStream s = Files.walk( + try (Stream s = Files.walk( fakeRoot.resolve("empty").resolve("IOException"))) { String[] result = s.map(path -> path.getFileName().toString()) @@ -502,20 +501,20 @@ public class StreamTest { fsp.setFaultyMode(false); Path fakeRoot = fs.getRoot(); // validate setting - try (CloseableStream s = Files.list(fakeRoot.resolve("empty"))) { + try (Stream s = Files.list(fakeRoot.resolve("empty"))) { String[] result = s.map(path -> path.getFileName().toString()) .toArray(String[]::new); assertEqualsNoOrder(result, new String[] { "SecurityException", "sample" }); } - try (CloseableStream s = Files.walk(fakeRoot.resolve("dir2"))) { + try (Stream s = Files.walk(fakeRoot.resolve("dir2"))) { String[] result = s.map(path -> path.getFileName().toString()) .toArray(String[]::new); assertEqualsNoOrder(result, new String[] { "dir2", "SecurityException", "fileInSE", "file" }); } if (supportsLinks) { - try (CloseableStream s = Files.list(fakeRoot.resolve("dir"))) { + try (Stream s = Files.list(fakeRoot.resolve("dir"))) { String[] result = s.map(path -> path.getFileName().toString()) .toArray(String[]::new); assertEqualsNoOrder(result, new String[] { "d1", "f1", "lnDir2", "SecurityException", "lnDirSE", "lnFileSE" }); @@ -525,13 +524,13 @@ public class StreamTest { // execute test fsp.setFaultyMode(true); // ignore file cause SecurityException - try (CloseableStream s = Files.walk(fakeRoot.resolve("empty"))) { + try (Stream s = Files.walk(fakeRoot.resolve("empty"))) { String[] result = s.map(path -> path.getFileName().toString()) .toArray(String[]::new); assertEqualsNoOrder(result, new String[] { "empty", "sample" }); } // skip folder cause SecurityException - try (CloseableStream s = Files.walk(fakeRoot.resolve("dir2"))) { + try (Stream s = Files.walk(fakeRoot.resolve("dir2"))) { String[] result = s.map(path -> path.getFileName().toString()) .toArray(String[]::new); assertEqualsNoOrder(result, new String[] { "dir2", "file" }); @@ -539,14 +538,14 @@ public class StreamTest { if (supportsLinks) { // not following links - try (CloseableStream s = Files.walk(fakeRoot.resolve("dir"))) { + try (Stream s = Files.walk(fakeRoot.resolve("dir"))) { String[] result = s.map(path -> path.getFileName().toString()) .toArray(String[]::new); assertEqualsNoOrder(result, new String[] { "dir", "d1", "f1", "lnDir2", "lnDirSE", "lnFileSE" }); } // following links - try (CloseableStream s = Files.walk(fakeRoot.resolve("dir"), FileVisitOption.FOLLOW_LINKS)) { + try (Stream s = Files.walk(fakeRoot.resolve("dir"), FileVisitOption.FOLLOW_LINKS)) { String[] result = s.map(path -> path.getFileName().toString()) .toArray(String[]::new); // ?? Should fileInSE show up? @@ -556,19 +555,19 @@ public class StreamTest { } // list instead of walk - try (CloseableStream s = Files.list(fakeRoot.resolve("empty"))) { + try (Stream s = Files.list(fakeRoot.resolve("empty"))) { String[] result = s.map(path -> path.getFileName().toString()) .toArray(String[]::new); assertEqualsNoOrder(result, new String[] { "sample" }); } - try (CloseableStream s = Files.list(fakeRoot.resolve("dir2"))) { + try (Stream s = Files.list(fakeRoot.resolve("dir2"))) { String[] result = s.map(path -> path.getFileName().toString()) .toArray(String[]::new); assertEqualsNoOrder(result, new String[] { "file" }); } // root cause SecurityException should be reported - try (CloseableStream s = Files.walk( + try (Stream s = Files.walk( fakeRoot.resolve("dir2").resolve("SecurityException"))) { String[] result = s.map(path -> path.getFileName().toString()) @@ -579,7 +578,7 @@ public class StreamTest { } // Walk a file cause SecurityException, we should get SE - try (CloseableStream s = Files.walk( + try (Stream s = Files.walk( fakeRoot.resolve("dir").resolve("SecurityException"))) { String[] result = s.map(path -> path.getFileName().toString()) @@ -590,7 +589,7 @@ public class StreamTest { } // List a file cause SecurityException, we should get SE as cannot read attribute - try (CloseableStream s = Files.list( + try (Stream s = Files.list( fakeRoot.resolve("dir2").resolve("SecurityException"))) { String[] result = s.map(path -> path.getFileName().toString()) @@ -600,7 +599,7 @@ public class StreamTest { assertTrue(se.getCause() instanceof FaultyFileSystem.FaultyException); } - try (CloseableStream s = Files.list( + try (Stream s = Files.list( fakeRoot.resolve("dir").resolve("SecurityException"))) { String[] result = s.map(path -> path.getFileName().toString()) @@ -627,7 +626,7 @@ public class StreamTest { } public void testConstructException() { - try (CloseableStream s = Files.lines(testFolder.resolve("notExist"), Charset.forName("UTF-8"))) { + try (Stream s = Files.lines(testFolder.resolve("notExist"), Charset.forName("UTF-8"))) { s.forEach(l -> fail("File is not even exist!")); } catch (IOException ioe) { assertTrue(ioe instanceof NoSuchFileException); @@ -635,24 +634,26 @@ public class StreamTest { } public void testClosedStream() throws IOException { - try (CloseableStream s = Files.list(testFolder)) { + try (Stream s = Files.list(testFolder)) { s.close(); - Object[] actual = s.sorted(Comparator.naturalOrder()).toArray(); - assertTrue(actual.length <= level1.length); - } - - try (CloseableStream s = Files.walk(testFolder)) { - s.close(); - Object[] actual = s.sorted(Comparator.naturalOrder()).toArray(); + Object[] actual = s.sorted().toArray(); fail("Operate on closed stream should throw IllegalStateException"); } catch (IllegalStateException ex) { // expected } - try (CloseableStream s = Files.find(testFolder, Integer.MAX_VALUE, + try (Stream s = Files.walk(testFolder)) { + s.close(); + Object[] actual = s.sorted().toArray(); + fail("Operate on closed stream should throw IllegalStateException"); + } catch (IllegalStateException ex) { + // expected + } + + try (Stream s = Files.find(testFolder, Integer.MAX_VALUE, (p, attr) -> true)) { s.close(); - Object[] actual = s.sorted(Comparator.naturalOrder()).toArray(); + Object[] actual = s.sorted().toArray(); fail("Operate on closed stream should throw IllegalStateException"); } catch (IllegalStateException ex) { // expected diff --git a/jdk/test/java/util/stream/bootlib/java/util/stream/DoubleStreamTestScenario.java b/jdk/test/java/util/stream/bootlib/java/util/stream/DoubleStreamTestScenario.java index d4459cf0c9b..43b99973dd2 100644 --- a/jdk/test/java/util/stream/bootlib/java/util/stream/DoubleStreamTestScenario.java +++ b/jdk/test/java/util/stream/bootlib/java/util/stream/DoubleStreamTestScenario.java @@ -40,7 +40,7 @@ import java.util.function.Function; @SuppressWarnings({"rawtypes", "unchecked"}) public enum DoubleStreamTestScenario implements OpTestCase.BaseStreamTestScenario { - STREAM_FOR_EACH(false) { + STREAM_FOR_EACH_WITH_CLOSE(false) { > void _run(TestData data, DoubleConsumer b, Function m) { DoubleStream s = m.apply(data.stream()); @@ -48,6 +48,7 @@ public enum DoubleStreamTestScenario implements OpTestCase.BaseStreamTestScenari s = s.sequential(); } s.forEach(b); + s.close(); } }, diff --git a/jdk/test/java/util/stream/bootlib/java/util/stream/IntStreamTestScenario.java b/jdk/test/java/util/stream/bootlib/java/util/stream/IntStreamTestScenario.java index f399cdeef25..4127a7b5a81 100644 --- a/jdk/test/java/util/stream/bootlib/java/util/stream/IntStreamTestScenario.java +++ b/jdk/test/java/util/stream/bootlib/java/util/stream/IntStreamTestScenario.java @@ -40,7 +40,7 @@ import java.util.function.IntConsumer; @SuppressWarnings({"rawtypes", "unchecked"}) public enum IntStreamTestScenario implements OpTestCase.BaseStreamTestScenario { - STREAM_FOR_EACH(false) { + STREAM_FOR_EACH_WITH_CLOSE(false) { > void _run(TestData data, IntConsumer b, Function m) { IntStream s = m.apply(data.stream()); @@ -48,6 +48,7 @@ public enum IntStreamTestScenario implements OpTestCase.BaseStreamTestScenario { s = s.sequential(); } s.forEach(b); + s.close(); } }, diff --git a/jdk/test/java/util/stream/bootlib/java/util/stream/LongStreamTestScenario.java b/jdk/test/java/util/stream/bootlib/java/util/stream/LongStreamTestScenario.java index 3010745a55d..0a334bc0261 100644 --- a/jdk/test/java/util/stream/bootlib/java/util/stream/LongStreamTestScenario.java +++ b/jdk/test/java/util/stream/bootlib/java/util/stream/LongStreamTestScenario.java @@ -40,7 +40,7 @@ import java.util.function.LongConsumer; @SuppressWarnings({"rawtypes", "unchecked"}) public enum LongStreamTestScenario implements OpTestCase.BaseStreamTestScenario { - STREAM_FOR_EACH(false) { + STREAM_FOR_EACH_WITH_CLOSE(false) { > void _run(TestData data, LongConsumer b, Function m) { LongStream s = m.apply(data.stream()); @@ -48,6 +48,7 @@ public enum LongStreamTestScenario implements OpTestCase.BaseStreamTestScenario s = s.sequential(); } s.forEach(b); + s.close(); } }, diff --git a/jdk/test/java/util/stream/bootlib/java/util/stream/StreamTestScenario.java b/jdk/test/java/util/stream/bootlib/java/util/stream/StreamTestScenario.java index b1abd4320db..d1a446234a7 100644 --- a/jdk/test/java/util/stream/bootlib/java/util/stream/StreamTestScenario.java +++ b/jdk/test/java/util/stream/bootlib/java/util/stream/StreamTestScenario.java @@ -39,7 +39,7 @@ import java.util.function.Function; @SuppressWarnings({"rawtypes", "unchecked"}) public enum StreamTestScenario implements OpTestCase.BaseStreamTestScenario { - STREAM_FOR_EACH(false) { + STREAM_FOR_EACH_WITH_CLOSE(false) { > void _run(TestData data, Consumer b, Function> m) { Stream s = m.apply(data.stream()); @@ -47,6 +47,7 @@ public enum StreamTestScenario implements OpTestCase.BaseStreamTestScenario { s = s.sequential(); } s.forEach(b); + s.close(); } }, diff --git a/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/StreamCloseTest.java b/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/StreamCloseTest.java new file mode 100644 index 00000000000..51ffd4b9010 --- /dev/null +++ b/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/StreamCloseTest.java @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2013, 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. + */ +package org.openjdk.tests.java.util.stream; + +import java.util.Arrays; +import java.util.stream.OpTestCase; +import java.util.stream.Stream; + +import org.testng.annotations.Test; + +import static java.util.stream.LambdaTestHelpers.countTo; + +/** + * StreamCloseTest + * + * @author Brian Goetz + */ +@Test(groups = { "serialization-hostile" }) +public class StreamCloseTest extends OpTestCase { + public void testEmptyCloseHandler() { + try (Stream ints = countTo(100).stream()) { + ints.forEach(i -> {}); + } + } + + public void testOneCloseHandler() { + final boolean[] holder = new boolean[1]; + Runnable closer = () -> { holder[0] = true; }; + + try (Stream ints = countTo(100).stream()) { + ints.onClose(closer); + ints.forEach(i -> {}); + } + assertTrue(holder[0]); + + Arrays.fill(holder, false); + try (Stream ints = countTo(100).stream().onClose(closer)) { + ints.forEach(i -> {}); + } + assertTrue(holder[0]); + + Arrays.fill(holder, false); + try (Stream ints = countTo(100).stream().filter(e -> true).onClose(closer)) { + ints.forEach(i -> {}); + } + assertTrue(holder[0]); + + Arrays.fill(holder, false); + try (Stream ints = countTo(100).stream().filter(e -> true).onClose(closer).filter(e -> true)) { + ints.forEach(i -> {}); + } + assertTrue(holder[0]); + } + + public void testTwoCloseHandlers() { + final boolean[] holder = new boolean[2]; + Runnable close1 = () -> { holder[0] = true; }; + Runnable close2 = () -> { holder[1] = true; }; + + try (Stream ints = countTo(100).stream()) { + ints.onClose(close1).onClose(close2); + ints.forEach(i -> {}); + } + assertTrue(holder[0] && holder[1]); + + Arrays.fill(holder, false); + try (Stream ints = countTo(100).stream().onClose(close1).onClose(close2)) { + ints.forEach(i -> {}); + } + assertTrue(holder[0] && holder[1]); + + Arrays.fill(holder, false); + try (Stream ints = countTo(100).stream().filter(e -> true).onClose(close1).onClose(close2)) { + ints.forEach(i -> {}); + } + assertTrue(holder[0] && holder[1]); + + Arrays.fill(holder, false); + try (Stream ints = countTo(100).stream().filter(e -> true).onClose(close1).onClose(close2).filter(e -> true)) { + ints.forEach(i -> {}); + } + assertTrue(holder[0] && holder[1]); + } + + public void testCascadedExceptions() { + final boolean[] holder = new boolean[3]; + boolean caught = false; + Runnable close1 = () -> { holder[0] = true; throw new RuntimeException("1"); }; + Runnable close2 = () -> { holder[1] = true; throw new RuntimeException("2"); }; + Runnable close3 = () -> { holder[2] = true; throw new RuntimeException("3"); }; + + try (Stream ints = countTo(100).stream()) { + ints.onClose(close1).onClose(close2).onClose(close3); + ints.forEach(i -> {}); + } + catch (RuntimeException e) { + assertCascaded(e, 3); + assertTrue(holder[0] && holder[1] && holder[2]); + caught = true; + } + assertTrue(caught); + + Arrays.fill(holder, false); + caught = false; + try (Stream ints = countTo(100).stream().onClose(close1).onClose(close2).onClose(close3)) { + ints.forEach(i -> {}); + } + catch (RuntimeException e) { + assertCascaded(e, 3); + assertTrue(holder[0] && holder[1] && holder[2]); + caught = true; + } + assertTrue(caught); + + caught = false; + Arrays.fill(holder, false); + try (Stream ints = countTo(100).stream().filter(e -> true).onClose(close1).onClose(close2).onClose(close3)) { + ints.forEach(i -> {}); + } + catch (RuntimeException e) { + assertCascaded(e, 3); + assertTrue(holder[0] && holder[1] && holder[2]); + caught = true; + } + assertTrue(caught); + + caught = false; + Arrays.fill(holder, false); + try (Stream ints = countTo(100).stream().filter(e -> true).onClose(close1).onClose(close2).filter(e -> true).onClose(close3)) { + ints.forEach(i -> {}); + } + catch (RuntimeException e) { + assertCascaded(e, 3); + assertTrue(holder[0] && holder[1] && holder[2]); + caught = true; + } + assertTrue(caught); + } + + private void assertCascaded(RuntimeException e, int n) { + assertTrue(e.getMessage().equals("1")); + assertTrue(e.getSuppressed().length == n - 1); + for (int i=0; i Date: Tue, 3 Sep 2013 22:37:07 +0100 Subject: [PATCH 012/210] 8017195: Introduce option to setKeepAlive parameter on CORBA sockets Reviewed-by: chegar, msheppar --- .../sun/corba/transport/KeepAliveSockets.java | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 jdk/test/com/sun/corba/transport/KeepAliveSockets.java diff --git a/jdk/test/com/sun/corba/transport/KeepAliveSockets.java b/jdk/test/com/sun/corba/transport/KeepAliveSockets.java new file mode 100644 index 00000000000..4d9b9d97855 --- /dev/null +++ b/jdk/test/com/sun/corba/transport/KeepAliveSockets.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2013, 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 8017195 + * @summary Introduce option to setKeepAlive parameter on CORBA sockets + * + * @run main/othervm KeepAliveSockets + * @run main/othervm -Dcom.sun.CORBA.transport.enableTcpKeepAlive KeepAliveSockets + * @run main/othervm -Dcom.sun.CORBA.transport.enableTcpKeepAlive=true KeepAliveSockets + * @run main/othervm -Dcom.sun.CORBA.transport.enableTcpKeepAlive=false KeepAliveSockets + */ + +import java.lang.*; +import java.net.InetSocketAddress; +import java.net.Socket; +import java.nio.channels.ServerSocketChannel; +import java.util.*; +import com.sun.corba.se.impl.orb.*; + +import com.sun.corba.se.impl.transport.*; + +public class KeepAliveSockets { + + public static void main(String[] args) throws Exception { + + boolean keepAlive = false; + String prop = System.getProperty("com.sun.CORBA.transport.enableTcpKeepAlive"); + if (prop != null) + keepAlive = !"false".equalsIgnoreCase(prop); + + DefaultSocketFactoryImpl sfImpl = new DefaultSocketFactoryImpl(); + ORBImpl orb = new ORBImpl(); + orb.set_parameters(null); + sfImpl.setORB(orb); + + ServerSocketChannel ssc = ServerSocketChannel.open(); + ssc.socket().bind(new InetSocketAddress(0)); + + InetSocketAddress isa = new InetSocketAddress("localhost", ssc.socket().getLocalPort()); + Socket s = sfImpl.createSocket("ignore", isa); + System.out.println("Received factory socket" + s); + if (keepAlive != s.getKeepAlive()) + throw new RuntimeException("KeepAlive value not honoured in CORBA socket"); + } + +} From 25af2121aa224df049dbf1dbc50dc869523bdeed Mon Sep 17 00:00:00 2001 From: Henry Jen Date: Tue, 3 Sep 2013 16:05:45 -0700 Subject: [PATCH 013/210] 8023997: j.l.String.join(java.lang.CharSequence, java.lang.Iterable) sample doesn't compile and is incorrect Reviewed-by: alanb --- jdk/src/share/classes/java/lang/String.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jdk/src/share/classes/java/lang/String.java b/jdk/src/share/classes/java/lang/String.java index 651a85017ed..e9d75afbbce 100644 --- a/jdk/src/share/classes/java/lang/String.java +++ b/jdk/src/share/classes/java/lang/String.java @@ -2457,8 +2457,8 @@ public final class String * String message = String.join(" ", strings); * //message returned is: "Java is cool" * - * Set strings = new HashSet<>(); - * Strings.add("Java"); strings.add("is"); + * Set strings = new LinkedHashSet<>(); + * strings.add("Java"); strings.add("is"); * strings.add("very"); strings.add("cool"); * String message = String.join("-", strings); * //message returned is: "Java-is-very-cool" From 7fc1c28757b950e48af2058b2bb7c45f7c9979b2 Mon Sep 17 00:00:00 2001 From: David Holmes Date: Tue, 3 Sep 2013 23:47:27 -0400 Subject: [PATCH 014/210] 8024140: [TESTBUG] Profile based regression test groups for jdk repo Reviewed-by: alanb, chegar --- jdk/test/TEST.groups | 338 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 338 insertions(+) diff --git a/jdk/test/TEST.groups b/jdk/test/TEST.groups index ed70cbf6704..a59b38853ff 100644 --- a/jdk/test/TEST.groups +++ b/jdk/test/TEST.groups @@ -212,3 +212,341 @@ jdk_desktop = \ :jdk_swing \ :jdk_sound \ :jdk_imageio + +############################################################################### +# Profile-based Test Group Definitions +# +# These groups define the tests that cover the different possible runtimes: +# - compact1, compact2, compact3, full JRE, JDK +# +# In addition they support testing of the minimal VM on compact1 and compact2. +# Essentially this defines groups based around the specified API's and VM +# services available in the runtime. +# +# The groups are defined hierarchically in two forms: +# - The need_xxx groups list all the tests that have a dependency on +# a specific profile. This is either because it tests a feature in +# that profile, or the test infrastructure uses a feature in that +# profile. +# - The primary groups are defined in terms of the other primary groups +# combined with the needs_xxx groups (including and excluding them as +# appropriate). For example the jre can run all tests from compact3, plus +# those from needs_jre, but excluding those from need_jdk. +# +# The bottom group defines all the actual tests to be considered, simply +# by listing the top-level test directories. + +# Full JDK can run all tests +# +jdk = \ + :jre \ + :needs_jdk + +# Tests that require a full JDK to execute. Either they test a feature +# only in the JDK or they use tools that are only in the JDK. The latter +# can be resolved in some cases by using tools from the compile-jdk. +# +needs_jdk = \ + :jdk_jdi \ + com/sun/tools \ + demo \ + sun/security/tools/jarsigner \ + sun/rmi/rmic \ + sun/tools \ + sun/jvmstat \ + tools \ + com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.java \ + java/io/Serializable/serialver \ + java/lang/invoke/lambda/LambdaAccessControlDoPrivilegedTest.java \ + java/lang/invoke/lambda/LambdaAccessControlTest.java \ + java/lang/System/MacEncoding/TestFileEncoding.java \ + java/net/URLClassLoader/closetest/GetResourceAsStream.java \ + java/util/Collections/EmptyIterator.java \ + java/util/concurrent/locks/Lock/TimedAcquireLeak.java \ + java/util/jar/Manifest/CreateManifest.java \ + java/util/jar/JarInputStream/ExtraFileInMetaInf.java \ + java/util/logging/AnonLoggerWeakRefLeak.sh \ + java/util/logging/LoggerWeakRefLeak.sh \ + java/util/zip/3GBZipFiles.sh \ + jdk/lambda/FDTest.java \ + jdk/lambda/separate/Compiler.java \ + sun/management/jdp/JdpTest.sh \ + sun/management/jmxremote/bootstrap/JvmstatCountersTest.java \ + sun/management/jmxremote/bootstrap/LocalManagementTest.sh \ + sun/misc/JarIndex/metaInfFilenames/Basic.java \ + sun/misc/JarIndex/JarIndexMergeForClassLoaderTest.java \ + sun/reflect/CallerSensitive/CallerSensitiveFinder.java \ + sun/reflect/CallerSensitive/MissingCallerSensitive.java \ + sun/security/util/Resources/NewNamesFormat.java \ + vm/verifier/defaultMethods/DefaultMethodRegressionTestsRun.java + +# JRE adds further tests to compact3 +# +jre = \ + :compact3 \ + :needs_jre \ + -:needs_jdk + +# Tests that require the full JRE +# +needs_jre = \ + :needs_charsets \ + :jdk_desktop \ + com/sun/corba \ + com/sun/jndi/cosnaming \ + sun/net/ftp \ + sun/net/www/protocol/ftp \ + sun/security/tools/policytool \ + java/net/URI/URItoURLTest.java \ + java/net/URL/URIToURLTest.java \ + java/net/URLConnection/HandleContentTypeWithAttrs.java \ + java/security/Security/ClassLoaderDeadlock/ClassLoaderDeadlock.sh \ + java/security/Security/ClassLoaderDeadlock/Deadlock.sh \ + java/util/logging/Listeners.java \ + java/util/logging/ListenersWithSM.java \ + java/util/ResourceBundle/Control/Bug6530694.java \ + java/text/Bidi/BidiConformance.java \ + java/text/Bidi/BidiEmbeddingTest.java \ + java/text/Bidi/Bug6665028.java \ + java/text/Bidi/Bug7042148.java \ + java/text/Bidi/Bug7051769.java \ + javax/crypto/Cipher/CipherStreamClose.java \ + javax/management/monitor/AttributeArbitraryDataTypeTest.java \ + jdk/lambda/vm/InterfaceAccessFlagsTest.java \ + sun/misc/URLClassPath/ClassnameCharTest.java + +# Tests dependent on the optional charsets.jar +# These are isolated for easy exclusions +# +needs_charsets = \ + java/io/OutputStreamWriter/TestWrite.java \ + java/nio/charset/RemovingSunIO/SunioAlias.java \ + java/nio/charset/coders/Check.java \ + java/nio/charset/Charset/CharsetContainmentTest.java \ + java/nio/charset/Charset/Contains.java \ + java/nio/charset/Charset/NIOCharsetAvailabilityTest.java \ + java/nio/charset/Charset/RegisteredCharsets.java \ + java/nio/charset/CharsetEncoder/Flush.java \ + java/nio/charset/coders/CheckSJISMappingProp.sh \ + java/nio/charset/coders/ResetISO2022JP.java \ + java/util/Locale/InternationalBAT.java \ + java/util/Locale/LocaleProviders.sh \ + java/util/Calendar/CldrFormatNamesTest.java \ + java/util/TimeZone/CLDRDisplayNamesTest.java \ + java/util/zip/ZipCoding.java \ + sun/nio/cs/EucJpLinux0212.java \ + sun/nio/cs/EUCJPUnderflowDecodeTest.java \ + sun/nio/cs/EuroConverter.java \ + sun/nio/cs/JISAutoDetectTest.java \ + sun/nio/cs/OLD/TestIBMDB.java \ + sun/nio/cs/SJISCanEncode.java \ + sun/nio/cs/Test6254467.java \ + sun/nio/cs/TestCompoundTest.java \ + sun/nio/cs/TestCp834_SBCS.java \ + sun/nio/cs/TestEUC_TW.java \ + sun/nio/cs/TestISO2022CNDecoder.java \ + sun/nio/cs/TestISO2022JPEncoder.java \ + sun/nio/cs/TestISO2022JPSubBytes.java \ + sun/nio/cs/TestIllegalSJIS.java \ + sun/nio/cs/TestJIS0208Decoder.java \ + sun/nio/cs/TestJIS0212Decoder.java \ + sun/nio/cs/TestMiscEUC_JP.java \ + sun/nio/cs/TestSJIS0213_SM.java \ + sun/nio/cs/BufferUnderflowEUCTWTest.java \ + sun/nio/cs/CheckCaseInsensitiveEncAliases.java \ + sun/nio/cs/CheckHistoricalNames.java \ + sun/nio/cs/EucJpLinuxDecoderRecoveryTest.java \ + sun/nio/cs/HWKatakanaMS932EncodeTest.java \ + sun/nio/cs/ISCIITest.java \ + sun/nio/cs/LatinCharReplacementTWTest.java \ + sun/nio/cs/NIOJISAutoDetectTest.java \ + sun/nio/cs/StreamEncoderClose.java \ + sun/nio/cs/SurrogateGB18030Test.java \ + sun/nio/cs/SurrogateTestEUCTW.java \ + sun/nio/cs/SurrogateTestHKSCS.java \ + sun/nio/cs/TestConverterDroppedCharacters.java \ + sun/nio/cs/TestCp93xSISO.java \ + sun/nio/cs/TestIBM1364.java \ + sun/nio/cs/TestIBMBugs.java \ + sun/nio/cs/TestIllegalISO2022Esc.java \ + sun/nio/cs/TestISO2022JP.java \ + sun/nio/cs/TestMS5022X.java \ + sun/nio/cs/TestSJIS0213.java \ + sun/nio/cs/TestTrailingEscapesISO2022JP.java \ + sun/nio/cs/TestUni2HKSCS.java \ + sun/nio/cs/ZeroedByteArrayEUCTWTest.java + +# Compact 3 adds further tests to compact2 +# +compact3 = \ + :compact2 \ + :needs_compact3 \ + -:needs_jre \ + -:needs_jdk + + +# Tests that require compact3 API's +# +needs_compact3 = \ + :jdk_instrument \ + :jdk_jmx \ + :jdk_management \ + :jdk_sctp \ + com/sun/jndi \ + com/sun/org/apache/xml/internal/security \ + com/sun/security/auth \ + com/sun/security/sasl \ + com/sun/security/jgss \ + com/sun/tracing \ + java/util/prefs \ + javax/naming \ + javax/security \ + javax/smartcardio \ + javax/sql/rowset \ + javax/xml/crypto \ + sun/security/acl \ + sun/security/jgss \ + sun/security/krb5 \ + java/lang/System/MacEncoding/TestFileEncoding.java \ + java/nio/channels/AsynchronousSocketChannel/Leaky.java \ + java/security/PermissionCollection/Concurrent.java \ + java/security/Principal/Implies.java \ + java/security/cert/GetInstance.java \ + java/util/logging/DrainFindDeadlockTest.java \ + java/util/logging/LoggingMXBeanTest.java \ + sun/net/www/http/KeepAliveCache/B5045306.java \ + sun/security/provider/PolicyFile/Alias.java \ + sun/security/provider/PolicyFile/Comparator.java \ + sun/security/provider/PolicyFile/SelfWildcard.java \ + sun/security/ssl/com/sun/net/ssl/internal/ssl/SSLEngineImpl/SSLEngineDeadlock.java \ + sun/security/util/Oid/OidFormat.java \ + sun/security/util/Resources/Format.java \ + sun/security/util/Resources/NewNamesFormat.java + +# Compact 2 adds full VM tests +compact2 = \ + :compact2_minimal \ + :compact1 \ + :needs_full_vm_compact2 \ + -:needs_compact3 \ + -:needs_jre \ + -:needs_jdk + +# Tests that require compact2 API's and a full VM +# +needs_full_vm_compact2 = + +# Minimal VM on Compact 2 adds in some compact2 tests +# +compact2_minimal = \ + :compact1_minimal \ + :needs_compact2 \ + -:needs_compact3 \ + -:needs_jre \ + -:needs_jdk + +# Tests that require compact2 API's +# +needs_compact2 = \ + :jdk_rmi \ + :jdk_time \ + com/sun/org/apache \ + com/sun/net/httpserver \ + java/sql \ + javax/sql \ + javax/xml \ + jdk/lambda \ + sun/net/www/http \ + sun/net/www/protocol/http \ + java/io/BufferedReader/Lines.java \ + java/lang/reflect/DefaultStaticTest/DefaultStaticInvokeTest.java \ + java/lang/CharSequence/DefaultTest.java \ + java/lang/IntegralPrimitiveToString.java \ + java/lang/PrimitiveSumMinMaxTest.java \ + java/lang/String/StringJoinTest.java \ + java/lang/Thread/StopThrowable.java \ + java/net/Authenticator/Deadlock.java \ + java/net/CookieHandler/LocalHostCookie.java \ + java/net/CookieHandler/CookieManagerTest.java \ + java/net/CookieHandler/EmptyCookieHeader.java \ + java/net/HttpCookie/IllegalCookieNameTest.java \ + java/net/HttpURLConnection/UnmodifiableMaps.java \ + java/net/HttpURLPermission/URLTest.java \ + java/net/ResponseCache/Test.java \ + java/net/URLClassLoader/ClassLoad.java \ + java/net/URLClassLoader/closetest/CloseTest.java \ + java/nio/Buffer/Chars.java \ + java/nio/file/Files/StreamTest.java \ + java/security/BasicPermission/Wildcard.java \ + java/util/Arrays/ParallelPrefix.java \ + java/util/Arrays/SetAllTest.java \ + java/util/BitSet/BitSetStreamTest.java \ + java/util/Collection/CollectionDefaults.java \ + java/util/Collection/ListDefaults.java \ + java/util/Collections/CheckedIdentityMap.java \ + java/util/Collections/CheckedMapBash.java \ + java/util/Collections/CheckedSetBash.java \ + java/util/Collections/EmptyCollectionSerialization.java \ + java/util/Collections/EmptyNavigableMap.java \ + java/util/Collections/EmptyNavigableSet.java \ + java/util/Collections/UnmodifiableMapEntrySet.java \ + java/util/Comparator/BasicTest.java \ + java/util/Comparator/TypeTest.java \ + java/util/Iterator/IteratorDefaults.java \ + java/util/Iterator/PrimitiveIteratorDefaults.java \ + java/util/Map/BasicSerialization.java \ + java/util/Map/Defaults.java \ + java/util/Map/EntryComparators.java \ + java/util/Optional/Basic.java \ + java/util/Optional/BasicDouble.java \ + java/util/Optional/BasicInt.java \ + java/util/Optional/BasicLong.java \ + java/util/Random/RandomStreamTest.java \ + java/util/ResourceBundle/Bug6359330.java \ + java/util/Spliterator/SpliteratorCharacteristics.java \ + java/util/Spliterator/SpliteratorCollisions.java \ + java/util/Spliterator/SpliteratorLateBindingFailFastTest.java \ + java/util/Spliterator/SpliteratorTraversingAndSplittingTest.java \ + java/util/StringJoiner/MergeTest.java \ + java/util/StringJoiner/StringJoinerTest.java \ + java/util/concurrent/atomic/AtomicReferenceTest.java \ + java/util/function/BinaryOperator/BasicTest.java \ + java/util/logging/LoggerSupplierAPIsTest.java \ + java/util/zip/ZipFile/StreamZipEntriesTest.java \ + java/util/zip/ZipFile/DeleteTempJar.java \ + javax/crypto/Cipher/CipherStreamClose.java \ + sun/misc/URLClassPath/ClassnameCharTest.java \ + sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/HttpsCreateSockTest.java \ + sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/HttpsSocketFacTest.java + +# Compact 1 adds full VM tests +# +compact1 = \ + :compact1_minimal \ + :needs_full_vm_compact1 \ + -:needs_compact2 \ + -:needs_full_vm_compact2 \ + -:needs_compact3 \ + -:needs_jre \ + -:needs_jdk + +# Tests that require compact1 API's and a full VM +# +needs_full_vm_compact1 = + +# All tests that run on the most minimal configuration: Minimal VM on Compact 1 +compact1_minimal = \ + com \ + java \ + javax \ + jdk \ + lib \ + sample \ + sun \ + vm \ + -:needs_full_vm_compact1 \ + -:needs_full_vm_compact2 \ + -:needs_compact2 \ + -:needs_compact3 \ + -:needs_jre \ + -:needs_jdk From 59440ee0bef7cce9a5f528e7840d098b89e9fc43 Mon Sep 17 00:00:00 2001 From: John Rose Date: Tue, 3 Sep 2013 21:42:56 -0700 Subject: [PATCH 015/210] 8008688: Make MethodHandleInfo public A major overhaul to MethodHandleInfo and method handles in general. Reviewed-by: vlivanov, twisti --- .../AbstractValidatingLambdaMetafactory.java | 2 +- .../java/lang/invoke/InfoFromMemberName.java | 145 ++++ .../classes/java/lang/invoke/Invokers.java | 2 + .../classes/java/lang/invoke/MemberName.java | 41 +- .../java/lang/invoke/MethodHandle.java | 40 +- .../java/lang/invoke/MethodHandleImpl.java | 75 +- .../java/lang/invoke/MethodHandleInfo.java | 286 +++++-- .../java/lang/invoke/MethodHandleNatives.java | 63 +- .../java/lang/invoke/MethodHandles.java | 93 ++- .../java/lang/invoke/SerializedLambda.java | 2 +- .../java/lang/invoke/7087570/Test7087570.java | 130 +-- .../java/lang/invoke/RevealDirectTest.java | 753 ++++++++++++++++++ .../java/lang/invoke/jtreg.security.policy | 9 + 13 files changed, 1437 insertions(+), 204 deletions(-) create mode 100644 jdk/src/share/classes/java/lang/invoke/InfoFromMemberName.java create mode 100644 jdk/test/java/lang/invoke/RevealDirectTest.java create mode 100644 jdk/test/java/lang/invoke/jtreg.security.policy diff --git a/jdk/src/share/classes/java/lang/invoke/AbstractValidatingLambdaMetafactory.java b/jdk/src/share/classes/java/lang/invoke/AbstractValidatingLambdaMetafactory.java index 79b3b69fcf3..92a44a048f3 100644 --- a/jdk/src/share/classes/java/lang/invoke/AbstractValidatingLambdaMetafactory.java +++ b/jdk/src/share/classes/java/lang/invoke/AbstractValidatingLambdaMetafactory.java @@ -124,7 +124,7 @@ import static sun.invoke.util.Wrapper.isWrapperType; this.samMethodType = samMethodType; this.implMethod = implMethod; - this.implInfo = new MethodHandleInfo(implMethod); + this.implInfo = caller.revealDirect(implMethod); // @@@ Temporary work-around pending resolution of 8005119 this.implKind = (implInfo.getReferenceKind() == MethodHandleInfo.REF_invokeSpecial) ? MethodHandleInfo.REF_invokeVirtual diff --git a/jdk/src/share/classes/java/lang/invoke/InfoFromMemberName.java b/jdk/src/share/classes/java/lang/invoke/InfoFromMemberName.java new file mode 100644 index 00000000000..0ecd005a8d3 --- /dev/null +++ b/jdk/src/share/classes/java/lang/invoke/InfoFromMemberName.java @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2012, 2013, 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 java.lang.invoke; + +import java.security.*; +import java.lang.reflect.*; +import java.lang.invoke.MethodHandleNatives.Constants; +import java.lang.invoke.MethodHandles.Lookup; +import static java.lang.invoke.MethodHandleStatics.*; + +/* + * Auxiliary to MethodHandleInfo, wants to nest in MethodHandleInfo but must be non-public. + */ +/*non-public*/ +final +class InfoFromMemberName implements MethodHandleInfo { + private final MemberName member; + private final int referenceKind; + + InfoFromMemberName(Lookup lookup, MemberName member, byte referenceKind) { + assert(member.isResolved() || member.isMethodHandleInvoke()); + assert(member.referenceKindIsConsistentWith(referenceKind)); + this.member = member; + this.referenceKind = referenceKind; + } + + @Override + public Class getDeclaringClass() { + return member.getDeclaringClass(); + } + + @Override + public String getName() { + return member.getName(); + } + + @Override + public MethodType getMethodType() { + return member.getMethodOrFieldType(); + } + + @Override + public int getModifiers() { + return member.getModifiers(); + } + + @Override + public int getReferenceKind() { + return referenceKind; + } + + @Override + public String toString() { + return MethodHandleInfo.toString(getReferenceKind(), getDeclaringClass(), getName(), getMethodType()); + } + + @Override + public T reflectAs(Class expected, Lookup lookup) { + if (member.isMethodHandleInvoke() && !member.isVarargs()) { + // This member is an instance of a signature-polymorphic method, which cannot be reflected + // A method handle invoker can come in either of two forms: + // A generic placeholder (present in the source code, and varargs) + // and a signature-polymorphic instance (synthetic and not varargs). + // For more information see comments on {@link MethodHandleNatives#linkMethod}. + throw new IllegalArgumentException("cannot reflect signature polymorphic method"); + } + Member mem = AccessController.doPrivileged(new PrivilegedAction() { + public Member run() { + try { + return reflectUnchecked(); + } catch (ReflectiveOperationException ex) { + throw new IllegalArgumentException(ex); + } + } + }); + try { + Class defc = getDeclaringClass(); + byte refKind = (byte) getReferenceKind(); + lookup.checkAccess(refKind, defc, convertToMemberName(refKind, mem)); + } catch (IllegalAccessException ex) { + throw new IllegalArgumentException(ex); + } + return expected.cast(mem); + } + + private Member reflectUnchecked() throws ReflectiveOperationException { + byte refKind = (byte) getReferenceKind(); + Class defc = getDeclaringClass(); + boolean isPublic = Modifier.isPublic(getModifiers()); + if (MethodHandleNatives.refKindIsMethod(refKind)) { + if (isPublic) + return defc.getMethod(getName(), getMethodType().parameterArray()); + else + return defc.getDeclaredMethod(getName(), getMethodType().parameterArray()); + } else if (MethodHandleNatives.refKindIsConstructor(refKind)) { + if (isPublic) + return defc.getConstructor(getMethodType().parameterArray()); + else + return defc.getDeclaredConstructor(getMethodType().parameterArray()); + } else if (MethodHandleNatives.refKindIsField(refKind)) { + if (isPublic) + return defc.getField(getName()); + else + return defc.getDeclaredField(getName()); + } else { + throw new IllegalArgumentException("referenceKind="+refKind); + } + } + + private static MemberName convertToMemberName(byte refKind, Member mem) throws IllegalAccessException { + if (mem instanceof Method) { + boolean wantSpecial = (refKind == REF_invokeSpecial); + return new MemberName((Method) mem, wantSpecial); + } else if (mem instanceof Constructor) { + return new MemberName((Constructor) mem); + } else if (mem instanceof Field) { + boolean isSetter = (refKind == REF_putField || refKind == REF_putStatic); + return new MemberName((Field) mem, isSetter); + } + throw new InternalError(mem.getClass().getName()); + } +} diff --git a/jdk/src/share/classes/java/lang/invoke/Invokers.java b/jdk/src/share/classes/java/lang/invoke/Invokers.java index 8d8e019d722..0ef6078b6b5 100644 --- a/jdk/src/share/classes/java/lang/invoke/Invokers.java +++ b/jdk/src/share/classes/java/lang/invoke/Invokers.java @@ -87,6 +87,7 @@ class Invokers { lform = invokeForm(mtype, true, MethodTypeForm.LF_EX_INVOKER); invoker = SimpleMethodHandle.make(invokerType, lform); } + invoker = invoker.withInternalMemberName(MemberName.makeMethodHandleInvoke("invokeExact", mtype)); assert(checkInvoker(invoker)); exactInvoker = invoker; return invoker; @@ -110,6 +111,7 @@ class Invokers { lform = invokeForm(mtype, true, MethodTypeForm.LF_GEN_INVOKER); invoker = SimpleMethodHandle.make(invokerType, lform); } + invoker = invoker.withInternalMemberName(MemberName.makeMethodHandleInvoke("invoke", mtype)); assert(checkInvoker(invoker)); generalInvoker = invoker; return invoker; diff --git a/jdk/src/share/classes/java/lang/invoke/MemberName.java b/jdk/src/share/classes/java/lang/invoke/MemberName.java index dfb468417d6..910574befe7 100644 --- a/jdk/src/share/classes/java/lang/invoke/MemberName.java +++ b/jdk/src/share/classes/java/lang/invoke/MemberName.java @@ -320,14 +320,18 @@ import java.util.Objects; /** Utility method to query if this member is a method handle invocation (invoke or invokeExact). */ public boolean isMethodHandleInvoke() { - final int bits = Modifier.NATIVE | Modifier.FINAL; + final int bits = MH_INVOKE_MODS; final int negs = Modifier.STATIC; if (testFlags(bits | negs, bits) && clazz == MethodHandle.class) { - return name.equals("invoke") || name.equals("invokeExact"); + return isMethodHandleInvokeName(name); } return false; } + public static boolean isMethodHandleInvokeName(String name) { + return name.equals("invoke") || name.equals("invokeExact"); + } + private static final int MH_INVOKE_MODS = Modifier.NATIVE | Modifier.FINAL | Modifier.PUBLIC; /** Utility method to query the modifier flags of this member. */ public boolean isStatic() { @@ -482,12 +486,27 @@ import java.util.Objects; m.getClass(); // NPE check // fill in vmtarget, vmindex while we have m in hand: MethodHandleNatives.init(this, m); + if (clazz == null) { // MHN.init failed + if (m.getDeclaringClass() == MethodHandle.class && + isMethodHandleInvokeName(m.getName())) { + // The JVM did not reify this signature-polymorphic instance. + // Need a special case here. + // See comments on MethodHandleNatives.linkMethod. + MethodType type = MethodType.methodType(m.getReturnType(), m.getParameterTypes()); + int flags = flagsMods(IS_METHOD, m.getModifiers(), REF_invokeVirtual); + init(MethodHandle.class, m.getName(), type, flags); + if (isMethodHandleInvoke()) + return; + } + throw new LinkageError(m.toString()); + } assert(isResolved() && this.clazz != null); this.name = m.getName(); if (this.type == null) this.type = new Object[] { m.getReturnType(), m.getParameterTypes() }; if (wantSpecial) { - assert(!isAbstract()) : this; + if (isAbstract()) + throw new AbstractMethodError(this.toString()); if (getReferenceKind() == REF_invokeVirtual) changeReferenceKind(REF_invokeSpecial, REF_invokeVirtual); else if (getReferenceKind() == REF_invokeInterface) @@ -562,6 +581,22 @@ import java.util.Objects; initResolved(true); } + /** + * Create a name for a signature-polymorphic invoker. + * This is a placeholder for a signature-polymorphic instance + * (of MH.invokeExact, etc.) that the JVM does not reify. + * See comments on {@link MethodHandleNatives#linkMethod}. + */ + static MemberName makeMethodHandleInvoke(String name, MethodType type) { + return makeMethodHandleInvoke(name, type, MH_INVOKE_MODS | SYNTHETIC); + } + static MemberName makeMethodHandleInvoke(String name, MethodType type, int mods) { + MemberName mem = new MemberName(MethodHandle.class, name, type, REF_invokeVirtual); + mem.flags |= mods; // it's not resolved, but add these modifiers anyway + assert(mem.isMethodHandleInvoke()) : mem; + return mem; + } + // bare-bones constructor; the JVM will fill it in MemberName() { } diff --git a/jdk/src/share/classes/java/lang/invoke/MethodHandle.java b/jdk/src/share/classes/java/lang/invoke/MethodHandle.java index df784d35e5b..408cbd08abc 100644 --- a/jdk/src/share/classes/java/lang/invoke/MethodHandle.java +++ b/jdk/src/share/classes/java/lang/invoke/MethodHandle.java @@ -1284,6 +1284,11 @@ assertEquals("[three, thee, tee]", asListFix.invoke((Object)argv).toString()); return null; // DMH returns DMH.member } + /*non-public*/ + MethodHandle withInternalMemberName(MemberName member) { + return MethodHandleImpl.makeWrappedMember(this, member); + } + /*non-public*/ boolean isInvokeSpecial() { return false; // DMH.Special returns true @@ -1356,7 +1361,7 @@ assertEquals("[three, thee, tee]", asListFix.invoke((Object)argv).toString()); MethodHandle rebind() { // Bind 'this' into a new invoker, of the known class BMH. MethodType type2 = type(); - LambdaForm form2 = reinvokerForm(type2.basicType()); + LambdaForm form2 = reinvokerForm(this); // form2 = lambda (bmh, arg*) { thismh = bmh[0]; invokeBasic(thismh, arg*) } return BoundMethodHandle.bindSingle(type2, form2, this); } @@ -1369,23 +1374,38 @@ assertEquals("[three, thee, tee]", asListFix.invoke((Object)argv).toString()); /** Create a LF which simply reinvokes a target of the given basic type. * The target MH must override {@link #reinvokerTarget} to provide the target. */ - static LambdaForm reinvokerForm(MethodType mtype) { - mtype = mtype.basicType(); + static LambdaForm reinvokerForm(MethodHandle target) { + MethodType mtype = target.type().basicType(); LambdaForm reinvoker = mtype.form().cachedLambdaForm(MethodTypeForm.LF_REINVOKE); if (reinvoker != null) return reinvoker; - MethodHandle MH_invokeBasic = MethodHandles.basicInvoker(mtype); + if (mtype.parameterSlotCount() >= MethodType.MAX_MH_ARITY) + return makeReinvokerForm(target.type(), target); // cannot cache this + reinvoker = makeReinvokerForm(mtype, null); + return mtype.form().setCachedLambdaForm(MethodTypeForm.LF_REINVOKE, reinvoker); + } + private static LambdaForm makeReinvokerForm(MethodType mtype, MethodHandle customTargetOrNull) { + boolean customized = (customTargetOrNull != null); + MethodHandle MH_invokeBasic = customized ? null : MethodHandles.basicInvoker(mtype); final int THIS_BMH = 0; final int ARG_BASE = 1; final int ARG_LIMIT = ARG_BASE + mtype.parameterCount(); int nameCursor = ARG_LIMIT; - final int NEXT_MH = nameCursor++; + final int NEXT_MH = customized ? -1 : nameCursor++; final int REINVOKE = nameCursor++; LambdaForm.Name[] names = LambdaForm.arguments(nameCursor - ARG_LIMIT, mtype.invokerType()); - names[NEXT_MH] = new LambdaForm.Name(NF_reinvokerTarget, names[THIS_BMH]); - Object[] targetArgs = Arrays.copyOfRange(names, THIS_BMH, ARG_LIMIT, Object[].class); - targetArgs[0] = names[NEXT_MH]; // overwrite this MH with next MH - names[REINVOKE] = new LambdaForm.Name(MH_invokeBasic, targetArgs); - return mtype.form().setCachedLambdaForm(MethodTypeForm.LF_REINVOKE, new LambdaForm("BMH.reinvoke", ARG_LIMIT, names)); + Object[] targetArgs; + MethodHandle targetMH; + if (customized) { + targetArgs = Arrays.copyOfRange(names, ARG_BASE, ARG_LIMIT, Object[].class); + targetMH = customTargetOrNull; + } else { + names[NEXT_MH] = new LambdaForm.Name(NF_reinvokerTarget, names[THIS_BMH]); + targetArgs = Arrays.copyOfRange(names, THIS_BMH, ARG_LIMIT, Object[].class); + targetArgs[0] = names[NEXT_MH]; // overwrite this MH with next MH + targetMH = MethodHandles.basicInvoker(mtype); + } + names[REINVOKE] = new LambdaForm.Name(targetMH, targetArgs); + return new LambdaForm("BMH.reinvoke", ARG_LIMIT, names); } private static final LambdaForm.NamedFunction NF_reinvokerTarget; diff --git a/jdk/src/share/classes/java/lang/invoke/MethodHandleImpl.java b/jdk/src/share/classes/java/lang/invoke/MethodHandleImpl.java index 04eda964966..5ab7f7adb7b 100644 --- a/jdk/src/share/classes/java/lang/invoke/MethodHandleImpl.java +++ b/jdk/src/share/classes/java/lang/invoke/MethodHandleImpl.java @@ -317,7 +317,7 @@ import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP; private MethodHandle cache; AsVarargsCollector(MethodHandle target, MethodType type, Class arrayType) { - super(type, reinvokerForm(type)); + super(type, reinvokerForm(target)); this.target = target; this.arrayType = arrayType; this.cache = target.asCollector(arrayType, 0); @@ -778,16 +778,27 @@ import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP; } static Empty throwException(T t) throws T { throw t; } - static MethodHandle FAKE_METHOD_HANDLE_INVOKE; - static - MethodHandle fakeMethodHandleInvoke(MemberName method) { - MethodType type = method.getInvocationType(); - assert(type.equals(MethodType.methodType(Object.class, Object[].class))); - MethodHandle mh = FAKE_METHOD_HANDLE_INVOKE; + static MethodHandle[] FAKE_METHOD_HANDLE_INVOKE = new MethodHandle[2]; + static MethodHandle fakeMethodHandleInvoke(MemberName method) { + int idx; + assert(method.isMethodHandleInvoke()); + switch (method.getName()) { + case "invoke": idx = 0; break; + case "invokeExact": idx = 1; break; + default: throw new InternalError(method.getName()); + } + MethodHandle mh = FAKE_METHOD_HANDLE_INVOKE[idx]; if (mh != null) return mh; - mh = throwException(type.insertParameterTypes(0, UnsupportedOperationException.class)); + MethodType type = MethodType.methodType(Object.class, UnsupportedOperationException.class, + MethodHandle.class, Object[].class); + mh = throwException(type); mh = mh.bindTo(new UnsupportedOperationException("cannot reflectively invoke MethodHandle")); - FAKE_METHOD_HANDLE_INVOKE = mh; + if (!method.getInvocationType().equals(mh.type())) + throw new InternalError(method.toString()); + mh = mh.withInternalMemberName(method); + mh = mh.asVarargsCollector(Object[].class); + assert(method.isVarargs()); + FAKE_METHOD_HANDLE_INVOKE[idx] = mh; return mh; } @@ -821,7 +832,7 @@ import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP; MethodHandle vamh = prepareForInvoker(mh); // Cache the result of makeInjectedInvoker once per argument class. MethodHandle bccInvoker = CV_makeInjectedInvoker.get(hostClass); - return restoreToType(bccInvoker.bindTo(vamh), mh.type()); + return restoreToType(bccInvoker.bindTo(vamh), mh.type(), mh.internalMemberName()); } private static MethodHandle makeInjectedInvoker(Class hostClass) { @@ -876,8 +887,11 @@ import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP; } // Undo the adapter effect of prepareForInvoker: - private static MethodHandle restoreToType(MethodHandle vamh, MethodType type) { - return vamh.asCollector(Object[].class, type.parameterCount()).asType(type); + private static MethodHandle restoreToType(MethodHandle vamh, MethodType type, MemberName member) { + MethodHandle mh = vamh.asCollector(Object[].class, type.parameterCount()); + mh = mh.asType(type); + mh = mh.withInternalMemberName(member); + return mh; } private static final MethodHandle MH_checkCallerClass; @@ -939,4 +953,41 @@ import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP; } } } + + + /** This subclass allows a wrapped method handle to be re-associated with an arbitrary member name. */ + static class WrappedMember extends MethodHandle { + private final MethodHandle target; + private final MemberName member; + + private WrappedMember(MethodHandle target, MethodType type, MemberName member) { + super(type, reinvokerForm(target)); + this.target = target; + this.member = member; + } + + @Override + MethodHandle reinvokerTarget() { + return target; + } + @Override + MemberName internalMemberName() { + return member; + } + @Override + boolean isInvokeSpecial() { + return target.isInvokeSpecial(); + } + @Override + MethodHandle viewAsType(MethodType newType) { + return new WrappedMember(target, newType, member); + } + } + + static MethodHandle makeWrappedMember(MethodHandle target, MemberName member) { + if (member.equals(target.internalMemberName())) + return target; + return new WrappedMember(target, target.type(), member); + } + } diff --git a/jdk/src/share/classes/java/lang/invoke/MethodHandleInfo.java b/jdk/src/share/classes/java/lang/invoke/MethodHandleInfo.java index 380ca59b6e1..72fd8e91035 100644 --- a/jdk/src/share/classes/java/lang/invoke/MethodHandleInfo.java +++ b/jdk/src/share/classes/java/lang/invoke/MethodHandleInfo.java @@ -24,80 +24,246 @@ */ package java.lang.invoke; + +import java.lang.reflect.*; +import java.util.*; import java.lang.invoke.MethodHandleNatives.Constants; +import java.lang.invoke.MethodHandles.Lookup; +import static java.lang.invoke.MethodHandleStatics.*; /** - * Cracking (reflecting) method handles back into their constituent symbolic parts. + * A symbolic reference obtained by cracking a method handle into its consitutent symbolic parts. + * To crack a direct method handle, call {@link Lookup#revealDirect Lookup.revealDirect}. + *

+ * A direct method handle represents a method, constructor, or field without + * any intervening argument bindings or other transformations. + * The method, constructor, or field referred to by a direct method handle is called + * its underlying member. + * Direct method handles may be obtained in any of these ways: + *

+ * In all of these cases, it is possible to crack the resulting direct method handle + * to recover a symbolic reference for the underlying method, constructor, or field. + * Cracking must be done via a {@code Lookup} object equivalent to that which created + * the target method handle, or which has enough access permissions to recreate + * an equivalent method handle. * + *

Reference kinds

+ * The Lookup Factory Methods + * correspond to all major use cases for methods, constructors, and fields. + * These use cases may be distinguished using small integers as follows: + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
reference kinddescriptive namescopememberbehavior
{@code 1}{@code REF_getField}{@code class}{@code FT f;}{@code (T) this.f;}
{@code 2}{@code REF_getStatic}{@code class} or {@code interface}{@code static}
{@code FT f;}
{@code (T) C.f;}
{@code 3}{@code REF_putField}{@code class}{@code FT f;}{@code this.f = x;}
{@code 4}{@code REF_putStatic}{@code class}{@code static}
{@code FT f;}
{@code C.f = arg;}
{@code 5}{@code REF_invokeVirtual}{@code class}{@code T m(A*);}{@code (T) this.m(arg*);}
{@code 6}{@code REF_invokeStatic}{@code class} or {@code interface}{@code static}
{@code T m(A*);}
{@code (T) C.m(arg*);}
{@code 7}{@code REF_invokeSpecial}{@code class} or {@code interface}{@code T m(A*);}{@code (T) super.m(arg*);}
{@code 8}{@code REF_newInvokeSpecial}{@code class}{@code C(A*);}{@code new C(arg*);}
{@code 9}{@code REF_invokeInterface}{@code interface}{@code T m(A*);}{@code (T) this.m(arg*);}
+ * @since 1.8 */ -final class MethodHandleInfo { - public static final int - REF_getField = Constants.REF_getField, - REF_getStatic = Constants.REF_getStatic, - REF_putField = Constants.REF_putField, - REF_putStatic = Constants.REF_putStatic, - REF_invokeVirtual = Constants.REF_invokeVirtual, - REF_invokeStatic = Constants.REF_invokeStatic, - REF_invokeSpecial = Constants.REF_invokeSpecial, - REF_newInvokeSpecial = Constants.REF_newInvokeSpecial, - REF_invokeInterface = Constants.REF_invokeInterface; +public +interface MethodHandleInfo { + /** + * A direct method handle reference kind, + * as defined in the table above. + */ + public static final int + REF_getField = Constants.REF_getField, + REF_getStatic = Constants.REF_getStatic, + REF_putField = Constants.REF_putField, + REF_putStatic = Constants.REF_putStatic, + REF_invokeVirtual = Constants.REF_invokeVirtual, + REF_invokeStatic = Constants.REF_invokeStatic, + REF_invokeSpecial = Constants.REF_invokeSpecial, + REF_newInvokeSpecial = Constants.REF_newInvokeSpecial, + REF_invokeInterface = Constants.REF_invokeInterface; - private final Class declaringClass; - private final String name; - private final MethodType methodType; - private final int referenceKind; + /** + * Returns the reference kind of the cracked method handle, which in turn + * determines whether the method handle's underlying member was a constructor, method, or field. + * See the table above for definitions. + * @return the integer code for the kind of reference used to access the underlying member + */ + public int getReferenceKind(); - public MethodHandleInfo(MethodHandle mh) { - MemberName mn = mh.internalMemberName(); - if (mn == null) throw new IllegalArgumentException("not a direct method handle"); - this.declaringClass = mn.getDeclaringClass(); - this.name = mn.getName(); - this.methodType = mn.getMethodOrFieldType(); - byte refKind = mn.getReferenceKind(); - if (refKind == REF_invokeSpecial && !mh.isInvokeSpecial()) - // Devirtualized method invocation is usually formally virtual. - refKind = REF_invokeVirtual; - this.referenceKind = refKind; - } + /** + * Returns the class in which the cracked method handle's underlying member was defined. + * @return the declaring class of the underlying member + */ + public Class getDeclaringClass(); - public Class getDeclaringClass() { - return declaringClass; - } + /** + * Returns the name of the cracked method handle's underlying member. + * This is {@code "<init>"} if the underlying member was a constructor, + * else it is a simple method name or field name. + * @return the simple name of the underlying member + */ + public String getName(); - public String getName() { - return name; - } + /** + * Returns the nominal type of the cracked symbolic reference, expressed as a method type. + * If the reference is to a constructor, the return type will be {@code void}. + * If it is to a non-static method, the method type will not mention the {@code this} parameter. + * If it is to a field and the requested access is to read the field, + * the method type will have no parameters and return the field type. + * If it is to a field and the requested access is to write the field, + * the method type will have one parameter of the field type and return {@code void}. + *

+ * Note that original direct method handle may include a leading {@code this} parameter, + * or (in the case of a constructor) will replace the {@code void} return type + * with the constructed class. + * The nominal type does not include any {@code this} parameter, + * and (in the case of a constructor) will return {@code void}. + * @return the type of the underlying member, expressed as a method type + */ + public MethodType getMethodType(); - public MethodType getMethodType() { - return methodType; - } + // Utility methods. + // NOTE: class/name/type and reference kind constitute a symbolic reference + // member and modifiers are an add-on, derived from Core Reflection (or the equivalent) - public int getModifiers() { - return -1; //TODO - } + /** + * Reflects the underlying member as a method, constructor, or field object. + * If the underlying member is public, it is reflected as if by + * {@code getMethod}, {@code getConstructor}, or {@code getField}. + * Otherwise, it is reflected as if by + * {@code getDeclaredMethod}, {@code getDeclaredConstructor}, or {@code getDeclaredField}. + * The underlying member must be accessible to the given lookup object. + * @param the desired type of the result, either {@link Member} or a subtype + * @param expected a class object representing the desired result type {@code T} + * @param lookup the lookup object that created this MethodHandleInfo, or one with equivalent access privileges + * @return a reference to the method, constructor, or field object + * @exception ClassCastException if the member is not of the expected type + * @exception NullPointerException if either argument is {@code null} + * @exception IllegalArgumentException if the underlying member is not accessible to the given lookup object + */ + public T reflectAs(Class expected, Lookup lookup); - public int getReferenceKind() { - return referenceKind; - } + /** + * Returns the access modifiers of the underlying member. + * @return the Java language modifiers for underlying member, + * or -1 if the member cannot be accessed + * @see Modifier + * @see reflectAs + */ + public int getModifiers(); - static String getReferenceKindString(int referenceKind) { - switch (referenceKind) { - case REF_getField: return "getfield"; - case REF_getStatic: return "getstatic"; - case REF_putField: return "putfield"; - case REF_putStatic: return "putstatic"; - case REF_invokeVirtual: return "invokevirtual"; - case REF_invokeStatic: return "invokestatic"; - case REF_invokeSpecial: return "invokespecial"; - case REF_newInvokeSpecial: return "newinvokespecial"; - case REF_invokeInterface: return "invokeinterface"; - default: return "UNKNOWN_REFENCE_KIND" + "[" + referenceKind + "]"; - } + /** + * Determines if the underlying member was a variable arity method or constructor. + * Such members are represented by method handles that are varargs collectors. + * @implSpec + * This produces a result equivalent to: + *

{@code
+     *     getReferenceKind() >= REF_invokeVirtual && Modifier.isTransient(getModifiers())
+     * }
+ * + * + * @return {@code true} if and only if the underlying member was declared with variable arity. + */ + // spelling derived from java.lang.reflect.Executable, not MethodHandle.isVarargsCollector + public default boolean isVarArgs() { + // fields are never varargs: + if (MethodHandleNatives.refKindIsField((byte) getReferenceKind())) + return false; + // not in the public API: Modifier.VARARGS + final int ACC_VARARGS = 0x00000080; // from JVMS 4.6 (Table 4.20) + assert(ACC_VARARGS == Modifier.TRANSIENT); + return Modifier.isTransient(getModifiers()); } - @Override - public String toString() { - return String.format("%s %s.%s:%s", getReferenceKindString(referenceKind), - declaringClass.getName(), name, methodType); + /** + * Returns the descriptive name of the given reference kind, + * as defined in the table above. + * The conventional prefix "REF_" is omitted. + * @param referenceKind an integer code for a kind of reference used to access a class member + * @return a mixed-case string such as {@code "getField"} + * @exception IllegalArgumentException if the argument is not a valid + * reference kind number + */ + public static String referenceKindToString(int referenceKind) { + if (!MethodHandleNatives.refKindIsValid(referenceKind)) + throw newIllegalArgumentException("invalid reference kind", referenceKind); + return MethodHandleNatives.refKindName((byte)referenceKind); + } + + /** + * Returns a string representation for a {@code MethodHandleInfo}, + * given the four parts of its symbolic reference. + * This is defined to be of the form {@code "RK C.N:MT"}, where {@code RK} is the + * {@linkplain #referenceKindToString reference kind string} for {@code kind}, + * {@code C} is the {@linkplain java.lang.Class#getName name} of {@code defc} + * {@code N} is the {@code name}, and + * {@code MT} is the {@code type}. + * These four values may be obtained from the + * {@linkplain #getReferenceKind reference kind}, + * {@linkplain #getDeclaringClass declaring class}, + * {@linkplain #getName member name}, + * and {@linkplain #getMethodType method type} + * of a {@code MethodHandleInfo} object. + * + * @implSpec + * This produces a result equivalent to: + *
{@code
+     *     String.format("%s %s.%s:%s", referenceKindToString(kind), defc.getName(), name, type)
+     * }
+ * + * @param kind the {@linkplain #getReferenceKind reference kind} part of the symbolic reference + * @param defc the {@linkplain #getDeclaringClass declaring class} part of the symbolic reference + * @param name the {@linkplain #getName member name} part of the symbolic reference + * @param type the {@linkplain #getMethodType method type} part of the symbolic reference + * @return a string of the form {@code "RK C.N:MT"} + * @exception IllegalArgumentException if the first argument is not a valid + * reference kind number + * @exception NullPointerException if any reference argument is {@code null} + */ + public static String toString(int kind, Class defc, String name, MethodType type) { + Objects.requireNonNull(name); Objects.requireNonNull(type); + return String.format("%s %s.%s:%s", referenceKindToString(kind), defc.getName(), name, type); } } diff --git a/jdk/src/share/classes/java/lang/invoke/MethodHandleNatives.java b/jdk/src/share/classes/java/lang/invoke/MethodHandleNatives.java index 06e61a7dd8b..4f83e82158c 100644 --- a/jdk/src/share/classes/java/lang/invoke/MethodHandleNatives.java +++ b/jdk/src/share/classes/java/lang/invoke/MethodHandleNatives.java @@ -205,6 +205,9 @@ class MethodHandleNatives { static boolean refKindIsMethod(byte refKind) { return !refKindIsField(refKind) && (refKind != REF_newInvokeSpecial); } + static boolean refKindIsConstructor(byte refKind) { + return (refKind == REF_newInvokeSpecial); + } static boolean refKindHasReceiver(byte refKind) { assert(refKindIsValid(refKind)); return (refKind & 1) != 0; @@ -313,7 +316,65 @@ class MethodHandleNatives { * The method assumes the following arguments on the stack: * 0: the method handle being invoked * 1-N: the arguments to the method handle invocation - * N+1: an implicitly added type argument (the given MethodType) + * N+1: an optional, implicitly added argument (typically the given MethodType) + *

+ * The nominal method at such a call site is an instance of + * a signature-polymorphic method (see @PolymorphicSignature). + * Such method instances are user-visible entities which are + * "split" from the generic placeholder method in {@code MethodHandle}. + * (Note that the placeholder method is not identical with any of + * its instances. If invoked reflectively, is guaranteed to throw an + * {@code UnsupportedOperationException}.) + * If the signature-polymorphic method instance is ever reified, + * it appears as a "copy" of the original placeholder + * (a native final member of {@code MethodHandle}) except + * that its type descriptor has shape required by the instance, + * and the method instance is not varargs. + * The method instance is also marked synthetic, since the + * method (by definition) does not appear in Java source code. + *

+ * The JVM is allowed to reify this method as instance metadata. + * For example, {@code invokeBasic} is always reified. + * But the JVM may instead call {@code linkMethod}. + * If the result is an * ordered pair of a {@code (method, appendix)}, + * the method gets all the arguments (0..N inclusive) + * plus the appendix (N+1), and uses the appendix to complete the call. + * In this way, one reusable method (called a "linker method") + * can perform the function of any number of polymorphic instance + * methods. + *

+ * Linker methods are allowed to be weakly typed, with any or + * all references rewritten to {@code Object} and any primitives + * (except {@code long}/{@code float}/{@code double}) + * rewritten to {@code int}. + * A linker method is trusted to return a strongly typed result, + * according to the specific method type descriptor of the + * signature-polymorphic instance it is emulating. + * This can involve (as necessary) a dynamic check using + * data extracted from the appendix argument. + *

+ * The JVM does not inspect the appendix, other than to pass + * it verbatim to the linker method at every call. + * This means that the JDK runtime has wide latitude + * for choosing the shape of each linker method and its + * corresponding appendix. + * Linker methods should be generated from {@code LambdaForm}s + * so that they do not become visible on stack traces. + *

+ * The {@code linkMethod} call is free to omit the appendix + * (returning null) and instead emulate the required function + * completely in the linker method. + * As a corner case, if N==255, no appendix is possible. + * In this case, the method returned must be custom-generated to + * to perform any needed type checking. + *

+ * If the JVM does not reify a method at a call site, but instead + * calls {@code linkMethod}, the corresponding call represented + * in the bytecodes may mention a valid method which is not + * representable with a {@code MemberName}. + * Therefore, use cases for {@code linkMethod} tend to correspond to + * special cases in reflective code such as {@code findVirtual} + * or {@code revealDirect}. */ static MemberName linkMethod(Class callerClass, int refKind, Class defc, String name, Object type, diff --git a/jdk/src/share/classes/java/lang/invoke/MethodHandles.java b/jdk/src/share/classes/java/lang/invoke/MethodHandles.java index 78b01215636..f0f9447e001 100644 --- a/jdk/src/share/classes/java/lang/invoke/MethodHandles.java +++ b/jdk/src/share/classes/java/lang/invoke/MethodHandles.java @@ -26,8 +26,6 @@ package java.lang.invoke; import java.lang.reflect.*; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.List; import java.util.ArrayList; import java.util.Arrays; @@ -54,6 +52,7 @@ import sun.security.util.SecurityConstants; * *

* @author John Rose, JSR 292 EG + * @since 1.7 */ public class MethodHandles { @@ -96,6 +95,38 @@ public class MethodHandles { return Lookup.PUBLIC_LOOKUP; } + /** + * Performs an unchecked "crack" of a direct method handle. + * The result is as if the user had obtained a lookup object capable enough + * to crack the target method handle, called + * {@link java.lang.invoke.MethodHandles.Lookup#revealDirect Lookup.revealDirect} + * on the target to obtain its symbolic reference, and then called + * {@link java.lang.invoke.MethodHandleInfo#reflectAs MethodHandleInfo.reflectAs} + * to resolve the symbolic reference to a member. + *

+ * If there is a security manager, its {@code checkPermission} method + * is called with a {@code ReflectPermission("suppressAccessChecks")} permission. + * @param the desired type of the result, either {@link Member} or a subtype + * @param target a direct method handle to crack into symbolic reference components + * @param expected a class object representing the desired result type {@code T} + * @return a reference to the method, constructor, or field object + * @exception SecurityException if the caller is not privileged to call {@code setAccessible} + * @exception NullPointerException if either argument is {@code null} + * @exception IllegalArgumentException if the target is not a direct method handle + * @exception ClassCastException if the member is not of the expected type + * @since 1.8 + */ + public static T + reflectAs(Class expected, MethodHandle target) { + SecurityManager smgr = System.getSecurityManager(); + if (smgr != null) smgr.checkPermission(ACCESS_PERMISSION); + Lookup lookup = Lookup.IMPL_LOOKUP; // use maximally privileged lookup + return lookup.revealDirect(target).reflectAs(expected, lookup); + } + // Copied from AccessibleObject, as used by Method.setAccessible, etc.: + static final private java.security.Permission ACCESS_PERMISSION = + new ReflectPermission("suppressAccessChecks"); + /** * A lookup object is a factory for creating method handles, * when the creation requires access checking. @@ -647,6 +678,7 @@ public class MethodHandles { return invoker(type); if ("invokeExact".equals(name)) return exactInvoker(type); + assert(!MemberName.isMethodHandleInvokeName(name)); return null; } @@ -892,6 +924,10 @@ return mh1; * @throws NullPointerException if the argument is null */ public MethodHandle unreflect(Method m) throws IllegalAccessException { + if (m.getDeclaringClass() == MethodHandle.class) { + MethodHandle mh = unreflectForMH(m); + if (mh != null) return mh; + } MemberName method = new MemberName(m); byte refKind = method.getReferenceKind(); if (refKind == REF_invokeSpecial) @@ -900,6 +936,12 @@ return mh1; Lookup lookup = m.isAccessible() ? IMPL_LOOKUP : this; return lookup.getDirectMethod(refKind, method.getDeclaringClass(), method, findBoundCallerClass(method)); } + private MethodHandle unreflectForMH(Method m) { + // these names require special lookups because they throw UnsupportedOperationException + if (MemberName.isMethodHandleInvokeName(m.getName())) + return MethodHandleImpl.fakeMethodHandleInvoke(new MemberName(m)); + return null; + } /** * Produces a method handle for a reflected method. @@ -1004,6 +1046,46 @@ return mh1; return unreflectField(f, true); } + /** + * Cracks a direct method handle created by this lookup object or a similar one. + * Security and access checks are performed to ensure that this lookup object + * is capable of reproducing the target method handle. + * This means that the cracking may fail if target is a direct method handle + * but was created by an unrelated lookup object. + * @param target a direct method handle to crack into symbolic reference components + * @return a symbolic reference which can be used to reconstruct this method handle from this lookup object + * @exception SecurityException if a security manager is present and it + * refuses access + * @throws IllegalArgumentException if the target is not a direct method handle or if access checking fails + * @exception NullPointerException if the target is {@code null} + * @since 1.8 + */ + public MethodHandleInfo revealDirect(MethodHandle target) { + MemberName member = target.internalMemberName(); + if (member == null || (!member.isResolved() && !member.isMethodHandleInvoke())) + throw newIllegalArgumentException("not a direct method handle"); + Class defc = member.getDeclaringClass(); + byte refKind = member.getReferenceKind(); + assert(MethodHandleNatives.refKindIsValid(refKind)); + if (refKind == REF_invokeSpecial && !target.isInvokeSpecial()) + // Devirtualized method invocation is usually formally virtual. + // To avoid creating extra MemberName objects for this common case, + // we encode this extra degree of freedom using MH.isInvokeSpecial. + refKind = REF_invokeVirtual; + if (refKind == REF_invokeVirtual && defc.isInterface()) + // Symbolic reference is through interface but resolves to Object method (toString, etc.) + refKind = REF_invokeInterface; + // Check SM permissions and member access before cracking. + try { + checkSecurityManager(defc, member); + checkAccess(refKind, defc, member); + } catch (IllegalAccessException ex) { + throw new IllegalArgumentException(ex); + } + // Produce the handle to the results. + return new InfoFromMemberName(this, member, refKind); + } + /// Helper methods, all package-private. MemberName resolveOrFail(byte refKind, Class refc, String name, Class type) throws NoSuchFieldException, IllegalAccessException { @@ -1201,12 +1283,12 @@ return mh1; private MethodHandle getDirectMethodCommon(byte refKind, Class refc, MemberName method, boolean doRestrict, Class callerClass) throws IllegalAccessException { checkMethod(refKind, refc, method); - if (method.isMethodHandleInvoke()) - return fakeMethodHandleInvoke(method); + assert(!method.isMethodHandleInvoke()); Class refcAsSuper; if (refKind == REF_invokeSpecial && refc != lookupClass() && + !refc.isInterface() && refc != (refcAsSuper = lookupClass().getSuperclass()) && refc.isAssignableFrom(lookupClass())) { assert(!method.getName().equals("")); // not this code path @@ -1234,9 +1316,6 @@ return mh1; mh = restrictReceiver(method, mh, lookupClass()); return mh; } - private MethodHandle fakeMethodHandleInvoke(MemberName method) { - return throwException(method.getReturnType(), UnsupportedOperationException.class); - } private MethodHandle maybeBindCaller(MemberName method, MethodHandle mh, Class callerClass) throws IllegalAccessException { diff --git a/jdk/src/share/classes/java/lang/invoke/SerializedLambda.java b/jdk/src/share/classes/java/lang/invoke/SerializedLambda.java index a775fc43e34..9be96ff685b 100644 --- a/jdk/src/share/classes/java/lang/invoke/SerializedLambda.java +++ b/jdk/src/share/classes/java/lang/invoke/SerializedLambda.java @@ -225,7 +225,7 @@ public final class SerializedLambda implements Serializable { @Override public String toString() { - String implKind=MethodHandleInfo.getReferenceKindString(implMethodKind); + String implKind=MethodHandleInfo.referenceKindToString(implMethodKind); return String.format("SerializedLambda[%s=%s, %s=%s.%s:%s, " + "%s=%s %s.%s:%s, %s=%s, %s=%d]", "capturingClass", capturingClass, diff --git a/jdk/test/java/lang/invoke/7087570/Test7087570.java b/jdk/test/java/lang/invoke/7087570/Test7087570.java index 572faccdf5a..732467b8c62 100644 --- a/jdk/test/java/lang/invoke/7087570/Test7087570.java +++ b/jdk/test/java/lang/invoke/7087570/Test7087570.java @@ -35,20 +35,9 @@ import java.util.*; import static java.lang.invoke.MethodHandles.*; import static java.lang.invoke.MethodType.*; +import static java.lang.invoke.MethodHandleInfo.*; public class Test7087570 { - // XXX may remove the following constant declarations when MethodHandleInfo is made public - private static final int - REF_getField = 1, - REF_getStatic = 2, - REF_putField = 3, - REF_putStatic = 4, - REF_invokeVirtual = 5, - REF_invokeStatic = 6, - REF_invokeSpecial = 7, - REF_newInvokeSpecial = 8, - REF_invokeInterface = 9, - REF_LIMIT = 10; private static final TestMethodData[] TESTS = new TestMethodData[] { // field accessors @@ -87,17 +76,17 @@ public class Test7087570 { } private static void doTest(MethodHandle mh, TestMethodData testMethod) { - Object mhi = newMethodHandleInfo(mh); + MethodHandleInfo mhi = LOOKUP.revealDirect(mh); System.out.printf("%s.%s: %s, nominal refKind: %s, actual refKind: %s\n", testMethod.clazz.getName(), testMethod.name, testMethod.methodType, - REF_KIND_NAMES[testMethod.referenceKind], - REF_KIND_NAMES[getReferenceKind(mhi)]); - assertEquals(testMethod.name, getName(mhi)); - assertEquals(testMethod.methodType, getMethodType(mhi)); - assertEquals(testMethod.declaringClass, getDeclaringClass(mhi)); + referenceKindToString(testMethod.referenceKind), + referenceKindToString(mhi.getReferenceKind())); + assertEquals(testMethod.name, mhi.getName()); + assertEquals(testMethod.methodType, mhi.getMethodType()); + assertEquals(testMethod.declaringClass, mhi.getDeclaringClass()); assertEquals(testMethod.referenceKind == REF_invokeSpecial, isInvokeSpecial(mh)); - assertRefKindEquals(testMethod.referenceKind, getReferenceKind(mhi)); + assertRefKindEquals(testMethod.referenceKind, mhi.getReferenceKind()); } private static void testWithLookup() throws Throwable { @@ -122,50 +111,8 @@ public class Test7087570 { return methodType(void.class, clazz); } - private static final String[] REF_KIND_NAMES = { - "MH::invokeBasic", - "REF_getField", "REF_getStatic", "REF_putField", "REF_putStatic", - "REF_invokeVirtual", "REF_invokeStatic", "REF_invokeSpecial", - "REF_newInvokeSpecial", "REF_invokeInterface" - }; - private static final Lookup LOOKUP = lookup(); - // XXX may remove the following reflective logic when MethodHandleInfo is made public - private static final MethodHandle MH_IS_INVOKESPECIAL; - private static final MethodHandle MHI_CONSTRUCTOR; - private static final MethodHandle MHI_GET_NAME; - private static final MethodHandle MHI_GET_METHOD_TYPE; - private static final MethodHandle MHI_GET_DECLARING_CLASS; - private static final MethodHandle MHI_GET_REFERENCE_KIND; - - static { - try { - // This is white box testing. Use reflection to grab private implementation bits. - String magicName = "IMPL_LOOKUP"; - Field magicLookup = MethodHandles.Lookup.class.getDeclaredField(magicName); - // This unit test will fail if a security manager is installed. - magicLookup.setAccessible(true); - // Forbidden fruit... - Lookup directInvokeLookup = (Lookup) magicLookup.get(null); - Class mhiClass = Class.forName("java.lang.invoke.MethodHandleInfo", false, MethodHandle.class.getClassLoader()); - MH_IS_INVOKESPECIAL = directInvokeLookup - .findVirtual(MethodHandle.class, "isInvokeSpecial", methodType(boolean.class)); - MHI_CONSTRUCTOR = directInvokeLookup - .findConstructor(mhiClass, methodType(void.class, MethodHandle.class)); - MHI_GET_NAME = directInvokeLookup - .findVirtual(mhiClass, "getName", methodType(String.class)); - MHI_GET_METHOD_TYPE = directInvokeLookup - .findVirtual(mhiClass, "getMethodType", methodType(MethodType.class)); - MHI_GET_DECLARING_CLASS = directInvokeLookup - .findVirtual(mhiClass, "getDeclaringClass", methodType(Class.class)); - MHI_GET_REFERENCE_KIND = directInvokeLookup - .findVirtual(mhiClass, "getReferenceKind", methodType(int.class)); - } catch (ReflectiveOperationException ex) { - throw new Error(ex); - } - } - private static class TestMethodData { final Class clazz; final String name; @@ -208,7 +155,9 @@ public class Test7087570 { return LOOKUP.findStatic(testMethod.clazz, testMethod.name, testMethod.methodType); case REF_invokeSpecial: Class thisClass = LOOKUP.lookupClass(); - return LOOKUP.findSpecial(testMethod.clazz, testMethod.name, testMethod.methodType, thisClass); + MethodHandle smh = LOOKUP.findSpecial(testMethod.clazz, testMethod.name, testMethod.methodType, thisClass); + noteInvokeSpecial(smh); + return smh; case REF_newInvokeSpecial: return LOOKUP.findConstructor(testMethod.clazz, testMethod.methodType); default: @@ -238,7 +187,9 @@ public class Test7087570 { case REF_invokeSpecial: { Method m = testMethod.clazz.getDeclaredMethod(testMethod.name, testMethod.methodType.parameterArray()); Class thisClass = LOOKUP.lookupClass(); - return LOOKUP.unreflectSpecial(m, thisClass); + MethodHandle smh = LOOKUP.unreflectSpecial(m, thisClass); + noteInvokeSpecial(smh); + return smh; } case REF_newInvokeSpecial: { Constructor c = testMethod.clazz.getDeclaredConstructor(testMethod.methodType.parameterArray()); @@ -249,59 +200,20 @@ public class Test7087570 { } } - private static Object newMethodHandleInfo(MethodHandle mh) { - try { - return MHI_CONSTRUCTOR.invoke(mh); - } catch (Throwable ex) { - throw new Error(ex); - } + private static List specialMethodHandles = new ArrayList<>(); + private static void noteInvokeSpecial(MethodHandle mh) { + specialMethodHandles.add(mh); + assert(isInvokeSpecial(mh)); } - private static boolean isInvokeSpecial(MethodHandle mh) { - try { - return (boolean) MH_IS_INVOKESPECIAL.invokeExact(mh); - } catch (Throwable ex) { - throw new Error(ex); - } - } - - private static String getName(Object mhi) { - try { - return (String) MHI_GET_NAME.invoke(mhi); - } catch (Throwable ex) { - throw new Error(ex); - } - } - - private static MethodType getMethodType(Object mhi) { - try { - return (MethodType) MHI_GET_METHOD_TYPE.invoke(mhi); - } catch (Throwable ex) { - throw new Error(ex); - } - } - - private static Class getDeclaringClass(Object mhi) { - try { - return (Class) MHI_GET_DECLARING_CLASS.invoke(mhi); - } catch (Throwable ex) { - throw new Error(ex); - } - } - - private static int getReferenceKind(Object mhi) { - try { - return (int) MHI_GET_REFERENCE_KIND.invoke(mhi); - } catch (Throwable ex) { - throw new Error(ex); - } + return specialMethodHandles.contains(mh); } private static void assertRefKindEquals(int expect, int observed) { if (expect == observed) return; - String msg = "expected " + REF_KIND_NAMES[(int) expect] + - " but observed " + REF_KIND_NAMES[(int) observed]; + String msg = "expected " + referenceKindToString(expect) + + " but observed " + referenceKindToString(observed); System.out.println("FAILED: " + msg); throw new AssertionError(msg); } diff --git a/jdk/test/java/lang/invoke/RevealDirectTest.java b/jdk/test/java/lang/invoke/RevealDirectTest.java new file mode 100644 index 00000000000..f05b19077c1 --- /dev/null +++ b/jdk/test/java/lang/invoke/RevealDirectTest.java @@ -0,0 +1,753 @@ +/* + * Copyright (c) 2013, 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. + */ + +/* + * @test + * @summary verify Lookup.revealDirect on a variety of input handles + * @compile -XDignore.symbol.file RevealDirectTest.java + * @run junit/othervm -ea -esa test.java.lang.invoke.RevealDirectTest + * + * @test + * @summary verify Lookup.revealDirect on a variety of input handles, with security manager + * @run main/othervm/policy=jtreg.security.policy/secure=java.lang.SecurityManager -ea -esa test.java.lang.invoke.RevealDirectTest + */ + +/* To run manually: + * $ $JAVA8X_HOME/bin/javac -cp $JUNIT4_JAR -d ../../../.. -XDignore.symbol.file RevealDirectTest.java + * $ $JAVA8X_HOME/bin/java -cp $JUNIT4_JAR:../../../.. -ea -esa org.junit.runner.JUnitCore test.java.lang.invoke.RevealDirectTest + * $ $JAVA8X_HOME/bin/java -cp $JUNIT4_JAR:../../../.. -ea -esa -Djava.security.manager test.java.lang.invoke.RevealDirectTest + */ + +package test.java.lang.invoke; + +import java.lang.reflect.*; +import java.lang.invoke.*; +import static java.lang.invoke.MethodHandles.*; +import static java.lang.invoke.MethodType.*; +import static java.lang.invoke.MethodHandleInfo.*; +import java.util.*; +import static org.junit.Assert.*; +import org.junit.*; + +public class RevealDirectTest { + public static void main(String... av) throws Throwable { + // Run the @Test methods explicitly, in case we don't want to use the JUnitCore driver. + // This appears to be necessary when running with a security manager. + Throwable fail = null; + for (Method test : RevealDirectTest.class.getDeclaredMethods()) { + if (!test.isAnnotationPresent(Test.class)) continue; + try { + test.invoke(new RevealDirectTest()); + } catch (Throwable ex) { + if (ex instanceof InvocationTargetException) + ex = ex.getCause(); + if (fail == null) fail = ex; + System.out.println("Testcase: "+test.getName() + +"("+test.getDeclaringClass().getName() + +"):\tCaused an ERROR"); + System.out.println(ex); + ex.printStackTrace(System.out); + } + } + if (fail != null) throw fail; + } + + public interface SimpleSuperInterface { + public abstract int getInt(); + public static void printAll(String... args) { + System.out.println(Arrays.toString(args)); + } + public int NICE_CONSTANT = 42; + } + public interface SimpleInterface extends SimpleSuperInterface { + default float getFloat() { return getInt(); } + public static void printAll(String[] args) { + System.out.println(Arrays.toString(args)); + } + } + public static class Simple implements SimpleInterface, Cloneable { + public int intField; + public final int finalField; + private static String stringField; + public int getInt() { return NICE_CONSTANT; } + private static Number getNum() { return 804; } + public Simple clone() { + try { + return (Simple) super.clone(); + } catch (CloneNotSupportedException ex) { + throw new RuntimeException(ex); + } + } + Simple() { finalField = -NICE_CONSTANT; } + private static Lookup localLookup() { return lookup(); } + private static List members() { return getMembers(lookup().lookupClass()); }; + } + + static boolean VERBOSE = false; + + @Test public void testSimple() throws Throwable { + if (VERBOSE) System.out.println("@Test testSimple"); + testOnMembers("testSimple", Simple.members(), Simple.localLookup()); + } + @Test public void testPublicLookup() throws Throwable { + if (VERBOSE) System.out.println("@Test testPublicLookup"); + List mems = publicOnly(Simple.members()); + Lookup pubLookup = publicLookup(), privLookup = Simple.localLookup(); + testOnMembers("testPublicLookup/1", mems, pubLookup); + // reveal using publicLookup: + testOnMembers("testPublicLookup/2", mems, privLookup, pubLookup); + // lookup using publicLookup, but reveal using private: + testOnMembers("testPublicLookup/3", mems, pubLookup, privLookup); + } + @Test public void testPublicLookupNegative() throws Throwable { + if (VERBOSE) System.out.println("@Test testPublicLookupNegative"); + List mems = nonPublicOnly(Simple.members()); + Lookup pubLookup = publicLookup(), privLookup = Simple.localLookup(); + testOnMembersNoLookup("testPublicLookupNegative/1", mems, pubLookup); + testOnMembersNoReveal("testPublicLookupNegative/2", mems, privLookup, pubLookup); + testOnMembersNoReflect("testPublicLookupNegative/3", mems, privLookup, pubLookup); + } + @Test public void testJavaLangClass() throws Throwable { + if (VERBOSE) System.out.println("@Test testJavaLangClass"); + List mems = callerSensitive(false, publicOnly(getMembers(Class.class))); + mems = limit(20, mems); + testOnMembers("testJavaLangClass", mems, Simple.localLookup()); + } + @Test public void testCallerSensitive() throws Throwable { + if (VERBOSE) System.out.println("@Test testCallerSensitive"); + List mems = union(getMembers(MethodHandles.class, "lookup"), + getMembers(Method.class, "invoke"), + getMembers(Field.class, "get", "set", "getLong"), + getMembers(Class.class)); + mems = callerSensitive(true, publicOnly(mems)); + mems = limit(10, mems); + testOnMembers("testCallerSensitive", mems, Simple.localLookup()); + } + @Test public void testCallerSensitiveNegative() throws Throwable { + if (VERBOSE) System.out.println("@Test testCallerSensitiveNegative"); + List mems = union(getMembers(MethodHandles.class, "lookup"), + getMembers(Class.class, "forName"), + getMembers(Method.class, "invoke")); + mems = callerSensitive(true, publicOnly(mems)); + // CS methods cannot be looked up with publicLookup + testOnMembersNoLookup("testCallerSensitiveNegative", mems, publicLookup()); + } + @Test public void testMethodHandleNatives() throws Throwable { + if (VERBOSE) System.out.println("@Test testMethodHandleNatives"); + List mems = getMembers(MethodHandle.class, "invoke", "invokeExact"); + testOnMembers("testMethodHandleNatives", mems, Simple.localLookup()); + } + @Test public void testMethodHandleInvokes() throws Throwable { + if (VERBOSE) System.out.println("@Test testMethodHandleInvokes"); + List types = new ArrayList<>(); + Class[] someParamTypes = { void.class, int.class, Object.class, Object[].class }; + for (Class rt : someParamTypes) { + for (Class p0 : someParamTypes) { + if (p0 == void.class) { types.add(methodType(rt)); continue; } + for (Class p1 : someParamTypes) { + if (p1 == void.class) { types.add(methodType(rt, p0)); continue; } + for (Class p2 : someParamTypes) { + if (p2 == void.class) { types.add(methodType(rt, p0, p1)); continue; } + types.add(methodType(rt, p0, p1, p2)); + } + } + } + } + List mems = union(getPolyMembers(MethodHandle.class, "invoke", types), + getPolyMembers(MethodHandle.class, "invokeExact", types)); + testOnMembers("testMethodHandleInvokes/1", mems, Simple.localLookup()); + testOnMembers("testMethodHandleInvokes/2", mems, publicLookup()); + } + + static List getPolyMembers(Class cls, String name, List types) { + assert(cls == MethodHandle.class); + ArrayList mems = new ArrayList<>(); + for (MethodType type : types) { + mems.add(new SignaturePolymorphicMethod(name, type)); + } + return mems; + } + static List getMembers(Class cls) { + return getMembers(cls, (String[]) null); + } + static List getMembers(Class cls, String... onlyNames) { + List names = (onlyNames == null || onlyNames.length == 0 ? null : Arrays.asList(onlyNames)); + ArrayList res = new ArrayList<>(); + for (Class sup : getSupers(cls)) { + res.addAll(getDeclaredMembers(sup, "getDeclaredFields")); + res.addAll(getDeclaredMembers(sup, "getDeclaredMethods")); + res.addAll(getDeclaredMembers(sup, "getDeclaredConstructors")); + } + res = new ArrayList<>(new LinkedHashSet<>(res)); + for (int i = 0; i < res.size(); i++) { + Member mem = res.get(i); + if (!canBeReached(mem, cls) || + res.indexOf(mem) != i || + mem.isSynthetic() || + (names != null && !names.contains(mem.getName())) + ) { + res.remove(i--); + } + } + return res; + } + static List> getSupers(Class cls) { + ArrayList> res = new ArrayList<>(); + ArrayList> intfs = new ArrayList<>(); + for (Class sup = cls; sup != null; sup = sup.getSuperclass()) { + res.add(sup); + for (Class intf : cls.getInterfaces()) { + if (!intfs.contains(intf)) + intfs.add(intf); + } + } + for (int i = 0; i < intfs.size(); i++) { + for (Class intf : intfs.get(i).getInterfaces()) { + if (!intfs.contains(intf)) + intfs.add(intf); + } + } + res.addAll(intfs); + //System.out.println("getSupers => "+res); + return res; + } + static boolean hasSM() { + return (System.getSecurityManager() != null); + } + static List getDeclaredMembers(Class cls, String accessor) { + Member[] mems = {}; + Method getter = getMethod(Class.class, accessor); + if (hasSM()) { + try { + mems = (Member[]) invokeMethod(getter, cls); + } catch (SecurityException ex) { + //if (VERBOSE) ex.printStackTrace(); + accessor = accessor.replace("Declared", ""); + getter = getMethod(Class.class, accessor); + if (VERBOSE) System.out.println("replaced accessor: "+getter); + } + } + if (mems.length == 0) { + try { + mems = (Member[]) invokeMethod(getter, cls); + } catch (SecurityException ex) { + ex.printStackTrace(); + } + } + if (VERBOSE) System.out.println(accessor+" "+cls.getName()+" => "+mems.length+" members"); + return Arrays.asList(mems); + } + static Method getMethod(Class cls, String name) { + try { + return cls.getMethod(name); + } catch (ReflectiveOperationException ex) { + throw new AssertionError(ex); + } + } + static Object invokeMethod(Method m, Object recv, Object... args) { + try { + return m.invoke(recv, args); + } catch (InvocationTargetException ex) { + Throwable ex2 = ex.getCause(); + if (ex2 instanceof RuntimeException) throw (RuntimeException) ex2; + if (ex2 instanceof Error) throw (Error) ex2; + throw new AssertionError(ex); + } catch (ReflectiveOperationException ex) { + throw new AssertionError(ex); + } + } + + static List limit(int len, List mems) { + if (mems.size() <= len) return mems; + return mems.subList(0, len); + } + @SafeVarargs + static List union(List mems, List... mem2s) { + for (List mem2 : mem2s) { + for (Member m : mem2) { + if (!mems.contains(m)) + mems.add(m); + } + } + return mems; + } + static List callerSensitive(boolean cond, List members) { + for (Iterator i = members.iterator(); i.hasNext(); ) { + Member mem = i.next(); + if (isCallerSensitive(mem) != cond) + i.remove(); + } + if (members.isEmpty()) throw new AssertionError("trivial result"); + return members; + } + static boolean isCallerSensitive(Member mem) { + if (!(mem instanceof AnnotatedElement)) return false; + AnnotatedElement ae = (AnnotatedElement) mem; + if (CS_CLASS != null) + return ae.isAnnotationPresent(sun.reflect.CallerSensitive.class); + for (java.lang.annotation.Annotation a : ae.getDeclaredAnnotations()) { + if (a.toString().contains(".CallerSensitive")) + return true; + } + return false; + } + static final Class CS_CLASS; + static { + Class c = null; + try { + c = sun.reflect.CallerSensitive.class; + } catch (SecurityException | LinkageError ex) { + } + CS_CLASS = c; + } + static List publicOnly(List members) { + return removeMods(members, Modifier.PUBLIC, 0); + } + static List nonPublicOnly(List members) { + return removeMods(members, Modifier.PUBLIC, -1); + } + static List removeMods(List members, int mask, int bits) { + int publicMods = (mask & Modifier.PUBLIC); + members = new ArrayList<>(members); + for (Iterator i = members.iterator(); i.hasNext(); ) { + Member mem = i.next(); + int mods = mem.getModifiers(); + if ((publicMods & mods) != 0 && + (publicMods & mem.getDeclaringClass().getModifiers()) == 0) + mods -= publicMods; + if ((mods & mask) == (bits & mask)) + i.remove(); + } + return members; + } + + void testOnMembers(String tname, List mems, Lookup lookup, Lookup... lookups) throws Throwable { + if (VERBOSE) System.out.println("testOnMembers "+mems); + Lookup revLookup = (lookups.length > 0) ? lookups[0] : null; + if (revLookup == null) revLookup = lookup; + Lookup refLookup = (lookups.length > 1) ? lookups[1] : null; + if (refLookup == null) refLookup = lookup; + assert(lookups.length <= 2); + testOnMembersImpl(tname, mems, lookup, revLookup, refLookup, NO_FAIL); + } + void testOnMembersNoLookup(String tname, List mems, Lookup lookup) throws Throwable { + if (VERBOSE) System.out.println("testOnMembersNoLookup "+mems); + testOnMembersImpl(tname, mems, lookup, null, null, FAIL_LOOKUP); + } + void testOnMembersNoReveal(String tname, List mems, + Lookup lookup, Lookup negLookup) throws Throwable { + if (VERBOSE) System.out.println("testOnMembersNoReveal "+mems); + testOnMembersImpl(tname, mems, lookup, negLookup, null, FAIL_REVEAL); + } + void testOnMembersNoReflect(String tname, List mems, + Lookup lookup, Lookup negLookup) throws Throwable { + if (VERBOSE) System.out.println("testOnMembersNoReflect "+mems); + testOnMembersImpl(tname, mems, lookup, lookup, negLookup, FAIL_REFLECT); + } + void testOnMembersImpl(String tname, List mems, + Lookup lookup, + Lookup revLookup, + Lookup refLookup, + int failureMode) throws Throwable { + Throwable fail = null; + int failCount = 0; + failureModeCounts = new int[FAIL_MODE_COUNT]; + long tm0 = System.currentTimeMillis(); + for (Member mem : mems) { + try { + testWithMember(mem, lookup, revLookup, refLookup, failureMode); + } catch (Throwable ex) { + if (fail == null) fail = ex; + if (++failCount > 10) { System.out.println("*** FAIL: too many failures"); break; } + System.out.println("*** FAIL: "+mem+" => "+ex); + if (VERBOSE) ex.printStackTrace(System.out); + } + } + long tm1 = System.currentTimeMillis(); + System.out.printf("@Test %s executed %s tests in %d ms", + tname, testKinds(failureModeCounts), (tm1-tm0)).println(); + if (fail != null) throw fail; + } + static String testKinds(int[] modes) { + int pos = modes[0], neg = -pos; + for (int n : modes) neg += n; + if (neg == 0) return pos + " positive"; + String negs = ""; + for (int n : modes) negs += "/"+n; + negs = negs.replaceFirst("/"+pos+"/", ""); + negs += " negative"; + if (pos == 0) return negs; + return pos + " positive, " + negs; + } + static class SignaturePolymorphicMethod implements Member { // non-reflected instance of MH.invoke* + final String name; + final MethodType type; + SignaturePolymorphicMethod(String name, MethodType type) { + this.name = name; + this.type = type; + } + public String toString() { + String typeStr = type.toString(); + if (isVarArgs()) typeStr = typeStr.replaceFirst("\\[\\])$", "...)"); + return (Modifier.toString(getModifiers()) + +typeStr.substring(0, typeStr.indexOf('('))+" " + +getDeclaringClass().getTypeName()+"." + +getName()+typeStr.substring(typeStr.indexOf('('))); + } + public boolean equals(Object x) { + return (x instanceof SignaturePolymorphicMethod && equals((SignaturePolymorphicMethod)x)); + } + public boolean equals(SignaturePolymorphicMethod that) { + return this.name.equals(that.name) && this.type.equals(that.type); + } + public int hashCode() { + return name.hashCode() * 31 + type.hashCode(); + } + public Class getDeclaringClass() { return MethodHandle.class; } + public String getName() { return name; } + public MethodType getMethodType() { return type; } + public int getModifiers() { return Modifier.PUBLIC | Modifier.FINAL | Modifier.NATIVE | SYNTHETIC; } + public boolean isVarArgs() { return Modifier.isTransient(getModifiers()); } + public boolean isSynthetic() { return true; } + public Class getReturnType() { return type.returnType(); } + public Class[] getParameterTypes() { return type.parameterArray(); } + static final int SYNTHETIC = 0x00001000; + } + static class UnreflectResult { // a tuple + final MethodHandle mh; + final Throwable ex; + final byte kind; + final Member mem; + final int var; + UnreflectResult(MethodHandle mh, byte kind, Member mem, int var) { + this.mh = mh; + this.ex = null; + this.kind = kind; + this.mem = mem; + this.var = var; + } + UnreflectResult(Throwable ex, byte kind, Member mem, int var) { + this.mh = null; + this.ex = ex; + this.kind = kind; + this.mem = mem; + this.var = var; + } + public String toString() { + return toInfoString()+"/v"+var; + } + public String toInfoString() { + return String.format("%s %s.%s:%s", MethodHandleInfo.referenceKindToString(kind), + mem.getDeclaringClass().getName(), name(mem), type(mem, kind)); + } + static String name(Member mem) { + if (mem instanceof Constructor) return ""; + return mem.getName(); + } + static MethodType type(Member mem, byte kind) { + if (mem instanceof Field) { + Class type = ((Field)mem).getType(); + if (kind == REF_putStatic || kind == REF_putField) + return methodType(void.class, type); + return methodType(type); + } else if (mem instanceof SignaturePolymorphicMethod) { + return ((SignaturePolymorphicMethod)mem).getMethodType(); + } + Class[] params = ((Executable)mem).getParameterTypes(); + if (mem instanceof Constructor) + return methodType(void.class, params); + Class type = ((Method)mem).getReturnType(); + return methodType(type, params); + } + } + static UnreflectResult unreflectMember(Lookup lookup, Member mem, int variation) { + byte[] refKind = {0}; + try { + return unreflectMemberOrThrow(lookup, mem, variation, refKind); + } catch (ReflectiveOperationException|SecurityException ex) { + return new UnreflectResult(ex, refKind[0], mem, variation); + } + } + static UnreflectResult unreflectMemberOrThrow(Lookup lookup, Member mem, int variation, + byte[] refKind) throws ReflectiveOperationException { + Class cls = lookup.lookupClass(); + Class defc = mem.getDeclaringClass(); + String name = mem.getName(); + int mods = mem.getModifiers(); + boolean isStatic = Modifier.isStatic(mods); + MethodHandle mh = null; + byte kind = 0; + if (mem instanceof Method) { + Method m = (Method) mem; + MethodType type = methodType(m.getReturnType(), m.getParameterTypes()); + boolean canBeSpecial = (!isStatic && + (lookup.lookupModes() & Modifier.PRIVATE) != 0 && + defc.isAssignableFrom(cls) && + (!defc.isInterface() || Arrays.asList(cls.getInterfaces()).contains(defc))); + if (variation >= 2) + kind = REF_invokeSpecial; + else if (isStatic) + kind = REF_invokeStatic; + else if (defc.isInterface()) + kind = REF_invokeInterface; + else + kind = REF_invokeVirtual; + refKind[0] = kind; + switch (variation) { + case 0: + mh = lookup.unreflect(m); + break; + case 1: + if (defc == MethodHandle.class && + !isStatic && + m.isVarArgs() && + Modifier.isFinal(mods) && + Modifier.isNative(mods)) { + break; + } + if (isStatic) + mh = lookup.findStatic(defc, name, type); + else + mh = lookup.findVirtual(defc, name, type); + break; + case 2: + if (!canBeSpecial) + break; + mh = lookup.unreflectSpecial(m, lookup.lookupClass()); + break; + case 3: + if (!canBeSpecial) + break; + mh = lookup.findSpecial(defc, name, type, lookup.lookupClass()); + break; + } + } else if (mem instanceof SignaturePolymorphicMethod) { + SignaturePolymorphicMethod m = (SignaturePolymorphicMethod) mem; + MethodType type = methodType(m.getReturnType(), m.getParameterTypes()); + kind = REF_invokeVirtual; + refKind[0] = kind; + switch (variation) { + case 0: + mh = lookup.findVirtual(defc, name, type); + break; + } + } else if (mem instanceof Constructor) { + name = ""; // not used + Constructor m = (Constructor) mem; + MethodType type = methodType(void.class, m.getParameterTypes()); + kind = REF_newInvokeSpecial; + refKind[0] = kind; + switch (variation) { + case 0: + mh = lookup.unreflectConstructor(m); + break; + case 1: + mh = lookup.findConstructor(defc, type); + break; + } + } else if (mem instanceof Field) { + Field m = (Field) mem; + Class type = m.getType(); + boolean canHaveSetter = !Modifier.isFinal(mods); + if (variation >= 2) + kind = (byte)(isStatic ? REF_putStatic : REF_putField); + else + kind = (byte)(isStatic ? REF_getStatic : REF_getField); + refKind[0] = kind; + switch (variation) { + case 0: + mh = lookup.unreflectGetter(m); + break; + case 1: + if (isStatic) + mh = lookup.findStaticGetter(defc, name, type); + else + mh = lookup.findGetter(defc, name, type); + break; + case 3: + if (!canHaveSetter) + break; + mh = lookup.unreflectSetter(m); + break; + case 2: + if (!canHaveSetter) + break; + if (isStatic) + mh = lookup.findStaticSetter(defc, name, type); + else + mh = lookup.findSetter(defc, name, type); + break; + } + } else { + throw new IllegalArgumentException(String.valueOf(mem)); + } + if (mh == null) + // ran out of valid variations; return null to caller + return null; + return new UnreflectResult(mh, kind, mem, variation); + } + static boolean canBeReached(Member mem, Class cls) { + Class defc = mem.getDeclaringClass(); + String name = mem.getName(); + int mods = mem.getModifiers(); + if (mem instanceof Constructor) { + name = ""; // according to 292 spec. + } + if (defc == cls) + return true; + if (name.startsWith("<")) + return false; // only my own constructors + if (Modifier.isPrivate(mods)) + return false; // only my own constructors + if (defc.getPackage() == cls.getPackage()) + return true; // package access or greater OK + if (Modifier.isPublic(mods)) + return true; // publics always OK + if (Modifier.isProtected(mods) && defc.isAssignableFrom(cls)) + return true; // protected OK + return false; + } + static boolean consistent(UnreflectResult res, MethodHandleInfo info) { + assert(res.mh != null); + assertEquals(res.kind, info.getReferenceKind()); + assertEquals(res.mem.getModifiers(), info.getModifiers()); + assertEquals(res.mem.getDeclaringClass(), info.getDeclaringClass()); + String expectName = res.mem.getName(); + if (res.kind == REF_newInvokeSpecial) + expectName = ""; + assertEquals(expectName, info.getName()); + MethodType expectType = res.mh.type(); + if ((res.kind & 1) == (REF_getField & 1)) + expectType = expectType.dropParameterTypes(0, 1); + if (res.kind == REF_newInvokeSpecial) + expectType = expectType.changeReturnType(void.class); + assertEquals(expectType, info.getMethodType()); + assertEquals(res.mh.isVarargsCollector(), isVarArgs(info)); + assertEquals(res.toInfoString(), info.toString()); + assertEquals(res.toInfoString(), MethodHandleInfo.toString(info.getReferenceKind(), info.getDeclaringClass(), info.getName(), info.getMethodType())); + return true; + } + static boolean isVarArgs(MethodHandleInfo info) { + return info.isVarArgs(); + } + static boolean consistent(Member mem, Member mem2) { + assertEquals(mem, mem2); + return true; + } + static boolean consistent(MethodHandleInfo info, MethodHandleInfo info2) { + assertEquals(info.getReferenceKind(), info2.getReferenceKind()); + assertEquals(info.getModifiers(), info2.getModifiers()); + assertEquals(info.getDeclaringClass(), info2.getDeclaringClass()); + assertEquals(info.getName(), info2.getName()); + assertEquals(info.getMethodType(), info2.getMethodType()); + assertEquals(isVarArgs(info), isVarArgs(info)); + return true; + } + static boolean consistent(MethodHandle mh, MethodHandle mh2) { + assertEquals(mh.type(), mh2.type()); + assertEquals(mh.isVarargsCollector(), mh2.isVarargsCollector()); + return true; + } + int[] failureModeCounts; + static final int NO_FAIL=0, FAIL_LOOKUP=1, FAIL_REVEAL=2, FAIL_REFLECT=3, FAIL_MODE_COUNT=4; + void testWithMember(Member mem, + Lookup lookup, // initial lookup of member => MH + Lookup revLookup, // reveal MH => info + Lookup refLookup, // reflect info => member + int failureMode) throws Throwable { + boolean expectEx1 = (failureMode == FAIL_LOOKUP); // testOnMembersNoLookup + boolean expectEx2 = (failureMode == FAIL_REVEAL); // testOnMembersNoReveal + boolean expectEx3 = (failureMode == FAIL_REFLECT); // testOnMembersNoReflect + for (int variation = 0; ; variation++) { + UnreflectResult res = unreflectMember(lookup, mem, variation); + failureModeCounts[failureMode] += 1; + if (variation == 0) assert(res != null); + if (res == null) break; + if (VERBOSE && variation == 0) + System.out.println("from "+mem.getDeclaringClass().getSimpleName()); + MethodHandle mh = res.mh; + Throwable ex1 = res.ex; + if (VERBOSE) System.out.println(" "+variation+": "+res+" << "+(mh != null ? mh : ex1)); + if (expectEx1 && ex1 != null) + continue; // this is OK; we expected that lookup to fail + if (expectEx1) + throw new AssertionError("unexpected lookup for negative test"); + if (ex1 != null && !expectEx1) { + if (failureMode != NO_FAIL) + throw new AssertionError("unexpected lookup failure for negative test", ex1); + throw ex1; + } + MethodHandleInfo info; + try { + info = revLookup.revealDirect(mh); + if (expectEx2) throw new AssertionError("unexpected revelation for negative test"); + } catch (Throwable ex2) { + if (VERBOSE) System.out.println(" "+variation+": "+res+" => "+mh.getClass().getName()+" => (EX2)"+ex2); + if (expectEx2) + continue; // this is OK; we expected the reflect to fail + if (failureMode != NO_FAIL) + throw new AssertionError("unexpected revelation failure for negative test", ex2); + throw ex2; + } + assert(consistent(res, info)); + Member mem2; + try { + mem2 = info.reflectAs(Member.class, refLookup); + if (expectEx3) throw new AssertionError("unexpected reflection for negative test"); + assert(!(mem instanceof SignaturePolymorphicMethod)); + } catch (IllegalArgumentException ex3) { + if (VERBOSE) System.out.println(" "+variation+": "+info+" => (EX3)"+ex3); + if (expectEx3) + continue; // this is OK; we expected the reflect to fail + if (mem instanceof SignaturePolymorphicMethod) + continue; // this is OK; we cannot reflect MH.invokeExact(a,b,c) + if (failureMode != NO_FAIL) + throw new AssertionError("unexpected reflection failure for negative test", ex3); + throw ex3; + } + assert(consistent(mem, mem2)); + UnreflectResult res2 = unreflectMember(lookup, mem2, variation); + MethodHandle mh2 = res2.mh; + assert(consistent(mh, mh2)); + MethodHandleInfo info2 = lookup.revealDirect(mh2); + assert(consistent(info, info2)); + assert(consistent(res, info2)); + Member mem3; + if (hasSM()) + mem3 = info2.reflectAs(Member.class, lookup); + else + mem3 = MethodHandles.reflectAs(Member.class, mh2); + assert(consistent(mem2, mem3)); + if (hasSM()) { + try { + MethodHandles.reflectAs(Member.class, mh2); + throw new AssertionError("failed to throw on "+mem3); + } catch (SecurityException ex3) { + // OK... + } + } + } + } +} diff --git a/jdk/test/java/lang/invoke/jtreg.security.policy b/jdk/test/java/lang/invoke/jtreg.security.policy new file mode 100644 index 00000000000..d32c7af9b3f --- /dev/null +++ b/jdk/test/java/lang/invoke/jtreg.security.policy @@ -0,0 +1,9 @@ +/* + * security policy used by the test process + * must allow file reads so that jtreg itself can run + */ + +grant { + // standard test activation permissions + permission java.io.FilePermission "*", "read"; +}; From 1f2ba9f2286e0de55a160f5d15a9db64e7024f06 Mon Sep 17 00:00:00 2001 From: Paul Sandoz Date: Mon, 12 Aug 2013 12:22:10 +0200 Subject: [PATCH 016/210] 8024182: test/java/util/Arrays/SetAllTest.java fails to compile due to recent compiler changes Use explicit lambda due to javac simplfying rules for overload resolution with implicit lambdas Reviewed-by: alanb, mduigou --- jdk/test/java/util/Arrays/SetAllTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jdk/test/java/util/Arrays/SetAllTest.java b/jdk/test/java/util/Arrays/SetAllTest.java index 2388a7bfd55..528d3c57b54 100644 --- a/jdk/test/java/util/Arrays/SetAllTest.java +++ b/jdk/test/java/util/Arrays/SetAllTest.java @@ -167,13 +167,13 @@ public class SetAllTest { public void testStringSetNulls() { String[] ar = new String[2]; try { - Arrays.setAll(null, i -> "X"); + Arrays.setAll(null, (IntFunction) i -> "X"); fail("Arrays.setAll(null, foo) should throw NPE"); } catch (NullPointerException npe) { // expected } try { - Arrays.parallelSetAll(null, i -> "X"); + Arrays.parallelSetAll(null, (IntFunction) i -> "X"); fail("Arrays.parallelSetAll(null, foo) should throw NPE"); } catch (NullPointerException npe) { // expected From 30f059b5fce32e14fc0cb890b8a950be5e582356 Mon Sep 17 00:00:00 2001 From: Erik Helin Date: Mon, 12 Aug 2013 17:37:02 +0200 Subject: [PATCH 017/210] 8015107: NPG: Use consistent naming for metaspace concepts Reviewed-by: coleenp, mgerdin, hseigel --- .../classes/sun/jvm/hotspot/runtime/VM.java | 2 +- .../sun/jvm/hotspot/tools/HeapSummary.java | 24 ++++----- .../cpu/sparc/vm/c1_LIRAssembler_sparc.cpp | 8 +-- .../cpu/sparc/vm/c1_MacroAssembler_sparc.cpp | 4 +- .../src/cpu/sparc/vm/macroAssembler_sparc.cpp | 18 +++---- hotspot/src/cpu/sparc/vm/sparc.ad | 8 +-- .../src/cpu/sparc/vm/stubGenerator_sparc.cpp | 6 +-- .../src/cpu/sparc/vm/vtableStubs_sparc.cpp | 4 +- hotspot/src/cpu/x86/vm/c1_FrameMap_x86.hpp | 2 +- .../src/cpu/x86/vm/c1_LIRAssembler_x86.cpp | 20 ++++---- .../src/cpu/x86/vm/c1_LIRGenerator_x86.cpp | 4 +- .../src/cpu/x86/vm/c1_MacroAssembler_x86.cpp | 8 +-- hotspot/src/cpu/x86/vm/macroAssembler_x86.cpp | 24 ++++----- hotspot/src/cpu/x86/vm/vtableStubs_x86_64.cpp | 4 +- hotspot/src/cpu/x86/vm/x86_64.ad | 6 +-- .../concurrentMarkSweepGeneration.cpp | 4 +- hotspot/src/share/vm/memory/metaspace.cpp | 32 ++++++------ hotspot/src/share/vm/memory/metaspace.hpp | 4 +- .../src/share/vm/memory/metaspaceCounters.cpp | 4 +- hotspot/src/share/vm/memory/universe.cpp | 2 +- hotspot/src/share/vm/memory/universe.hpp | 6 +-- hotspot/src/share/vm/oops/arrayOop.hpp | 2 +- hotspot/src/share/vm/oops/instanceOop.hpp | 4 +- hotspot/src/share/vm/oops/oop.inline.hpp | 18 +++---- hotspot/src/share/vm/opto/cfgnode.cpp | 2 +- hotspot/src/share/vm/opto/compile.cpp | 4 +- hotspot/src/share/vm/opto/connode.cpp | 2 +- hotspot/src/share/vm/opto/library_call.cpp | 2 +- hotspot/src/share/vm/opto/live.cpp | 2 +- hotspot/src/share/vm/opto/macro.cpp | 2 +- hotspot/src/share/vm/opto/memnode.cpp | 4 +- hotspot/src/share/vm/opto/type.cpp | 2 +- hotspot/src/share/vm/runtime/arguments.cpp | 44 +++++++++-------- hotspot/src/share/vm/runtime/globals.hpp | 10 ++-- hotspot/src/share/vm/services/memoryPool.cpp | 2 +- .../src/share/vm/services/memoryService.cpp | 2 +- .../arguments/TestCompressedClassFlags.java | 49 +++++++++++++++++++ ...> CompressedClassSpaceSizeInJmapHeap.java} | 14 +++--- .../gc/metaspace/TestMetaspaceMemoryPool.java | 4 +- .../metaspace/TestMetaspacePerfCounters.java | 14 +++--- .../CDSCompressedKPtrs.java | 6 +-- .../CDSCompressedKPtrsError.java | 16 +++--- .../CompressedKlassPointerAndOops.java | 4 +- 43 files changed, 228 insertions(+), 175 deletions(-) create mode 100644 hotspot/test/gc/arguments/TestCompressedClassFlags.java rename hotspot/test/gc/metaspace/{ClassMetaspaceSizeInJmapHeap.java => CompressedClassSpaceSizeInJmapHeap.java} (83%) diff --git a/hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/VM.java b/hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/VM.java index f84da894ac2..319d2430af2 100644 --- a/hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/VM.java +++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/VM.java @@ -792,7 +792,7 @@ public class VM { public boolean isCompressedKlassPointersEnabled() { if (compressedKlassPointersEnabled == null) { - Flag flag = getCommandLineFlag("UseCompressedKlassPointers"); + Flag flag = getCommandLineFlag("UseCompressedClassPointers"); compressedKlassPointersEnabled = (flag == null) ? Boolean.FALSE: (flag.getBool()? Boolean.TRUE: Boolean.FALSE); } diff --git a/hotspot/agent/src/share/classes/sun/jvm/hotspot/tools/HeapSummary.java b/hotspot/agent/src/share/classes/sun/jvm/hotspot/tools/HeapSummary.java index a0123dd4c99..daab682aaef 100644 --- a/hotspot/agent/src/share/classes/sun/jvm/hotspot/tools/HeapSummary.java +++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/tools/HeapSummary.java @@ -66,18 +66,18 @@ public class HeapSummary extends Tool { printGCAlgorithm(flagMap); System.out.println(); System.out.println("Heap Configuration:"); - printValue("MinHeapFreeRatio = ", getFlagValue("MinHeapFreeRatio", flagMap)); - printValue("MaxHeapFreeRatio = ", getFlagValue("MaxHeapFreeRatio", flagMap)); - printValMB("MaxHeapSize = ", getFlagValue("MaxHeapSize", flagMap)); - printValMB("NewSize = ", getFlagValue("NewSize", flagMap)); - printValMB("MaxNewSize = ", getFlagValue("MaxNewSize", flagMap)); - printValMB("OldSize = ", getFlagValue("OldSize", flagMap)); - printValue("NewRatio = ", getFlagValue("NewRatio", flagMap)); - printValue("SurvivorRatio = ", getFlagValue("SurvivorRatio", flagMap)); - printValMB("MetaspaceSize = ", getFlagValue("MetaspaceSize", flagMap)); - printValMB("ClassMetaspaceSize = ", getFlagValue("ClassMetaspaceSize", flagMap)); - printValMB("MaxMetaspaceSize = ", getFlagValue("MaxMetaspaceSize", flagMap)); - printValMB("G1HeapRegionSize = ", HeapRegion.grainBytes()); + printValue("MinHeapFreeRatio = ", getFlagValue("MinHeapFreeRatio", flagMap)); + printValue("MaxHeapFreeRatio = ", getFlagValue("MaxHeapFreeRatio", flagMap)); + printValMB("MaxHeapSize = ", getFlagValue("MaxHeapSize", flagMap)); + printValMB("NewSize = ", getFlagValue("NewSize", flagMap)); + printValMB("MaxNewSize = ", getFlagValue("MaxNewSize", flagMap)); + printValMB("OldSize = ", getFlagValue("OldSize", flagMap)); + printValue("NewRatio = ", getFlagValue("NewRatio", flagMap)); + printValue("SurvivorRatio = ", getFlagValue("SurvivorRatio", flagMap)); + printValMB("MetaspaceSize = ", getFlagValue("MetaspaceSize", flagMap)); + printValMB("CompressedClassSpaceSize = ", getFlagValue("CompressedClassSpaceSize", flagMap)); + printValMB("MaxMetaspaceSize = ", getFlagValue("MaxMetaspaceSize", flagMap)); + printValMB("G1HeapRegionSize = ", HeapRegion.grainBytes()); System.out.println(); System.out.println("Heap Usage:"); diff --git a/hotspot/src/cpu/sparc/vm/c1_LIRAssembler_sparc.cpp b/hotspot/src/cpu/sparc/vm/c1_LIRAssembler_sparc.cpp index 12d51571ccb..cb4c04a388b 100644 --- a/hotspot/src/cpu/sparc/vm/c1_LIRAssembler_sparc.cpp +++ b/hotspot/src/cpu/sparc/vm/c1_LIRAssembler_sparc.cpp @@ -105,7 +105,7 @@ bool LIR_Assembler::is_single_instruction(LIR_Op* op) { if (src->is_address() && !src->is_stack() && (src->type() == T_OBJECT || src->type() == T_ARRAY)) return false; } - if (UseCompressedKlassPointers) { + if (UseCompressedClassPointers) { if (src->is_address() && !src->is_stack() && src->type() == T_ADDRESS && src->as_address_ptr()->disp() == oopDesc::klass_offset_in_bytes()) return false; } @@ -963,7 +963,7 @@ int LIR_Assembler::load(Register base, int offset, LIR_Opr to_reg, BasicType typ case T_METADATA: __ ld_ptr(base, offset, to_reg->as_register()); break; case T_ADDRESS: #ifdef _LP64 - if (offset == oopDesc::klass_offset_in_bytes() && UseCompressedKlassPointers) { + if (offset == oopDesc::klass_offset_in_bytes() && UseCompressedClassPointers) { __ lduw(base, offset, to_reg->as_register()); __ decode_klass_not_null(to_reg->as_register()); } else @@ -2208,7 +2208,7 @@ void LIR_Assembler::emit_arraycopy(LIR_OpArrayCopy* op) { // We don't know the array types are compatible if (basic_type != T_OBJECT) { // Simple test for basic type arrays - if (UseCompressedKlassPointers) { + if (UseCompressedClassPointers) { // We don't need decode because we just need to compare __ lduw(src, oopDesc::klass_offset_in_bytes(), tmp); __ lduw(dst, oopDesc::klass_offset_in_bytes(), tmp2); @@ -2342,7 +2342,7 @@ void LIR_Assembler::emit_arraycopy(LIR_OpArrayCopy* op) { // but not necessarily exactly of type default_type. Label known_ok, halt; metadata2reg(op->expected_type()->constant_encoding(), tmp); - if (UseCompressedKlassPointers) { + if (UseCompressedClassPointers) { // tmp holds the default type. It currently comes uncompressed after the // load of a constant, so encode it. __ encode_klass_not_null(tmp); diff --git a/hotspot/src/cpu/sparc/vm/c1_MacroAssembler_sparc.cpp b/hotspot/src/cpu/sparc/vm/c1_MacroAssembler_sparc.cpp index bf4074b30fd..6d10ab81aaf 100644 --- a/hotspot/src/cpu/sparc/vm/c1_MacroAssembler_sparc.cpp +++ b/hotspot/src/cpu/sparc/vm/c1_MacroAssembler_sparc.cpp @@ -186,7 +186,7 @@ void C1_MacroAssembler::initialize_header(Register obj, Register klass, Register set((intx)markOopDesc::prototype(), t1); } st_ptr(t1, obj, oopDesc::mark_offset_in_bytes()); - if (UseCompressedKlassPointers) { + if (UseCompressedClassPointers) { // Save klass mov(klass, t1); encode_klass_not_null(t1); @@ -196,7 +196,7 @@ void C1_MacroAssembler::initialize_header(Register obj, Register klass, Register } if (len->is_valid()) { st(len, obj, arrayOopDesc::length_offset_in_bytes()); - } else if (UseCompressedKlassPointers) { + } else if (UseCompressedClassPointers) { // otherwise length is in the class gap store_klass_gap(G0, obj); } diff --git a/hotspot/src/cpu/sparc/vm/macroAssembler_sparc.cpp b/hotspot/src/cpu/sparc/vm/macroAssembler_sparc.cpp index d2c4e3b0261..9f1f2e53371 100644 --- a/hotspot/src/cpu/sparc/vm/macroAssembler_sparc.cpp +++ b/hotspot/src/cpu/sparc/vm/macroAssembler_sparc.cpp @@ -3911,7 +3911,7 @@ void MacroAssembler::load_klass(Register src_oop, Register klass) { // The number of bytes in this code is used by // MachCallDynamicJavaNode::ret_addr_offset() // if this changes, change that. - if (UseCompressedKlassPointers) { + if (UseCompressedClassPointers) { lduw(src_oop, oopDesc::klass_offset_in_bytes(), klass); decode_klass_not_null(klass); } else { @@ -3920,7 +3920,7 @@ void MacroAssembler::load_klass(Register src_oop, Register klass) { } void MacroAssembler::store_klass(Register klass, Register dst_oop) { - if (UseCompressedKlassPointers) { + if (UseCompressedClassPointers) { assert(dst_oop != klass, "not enough registers"); encode_klass_not_null(klass); st(klass, dst_oop, oopDesc::klass_offset_in_bytes()); @@ -3930,7 +3930,7 @@ void MacroAssembler::store_klass(Register klass, Register dst_oop) { } void MacroAssembler::store_klass_gap(Register s, Register d) { - if (UseCompressedKlassPointers) { + if (UseCompressedClassPointers) { assert(s != d, "not enough registers"); st(s, d, oopDesc::klass_gap_offset_in_bytes()); } @@ -4089,7 +4089,7 @@ void MacroAssembler::decode_heap_oop_not_null(Register src, Register dst) { } void MacroAssembler::encode_klass_not_null(Register r) { - assert (UseCompressedKlassPointers, "must be compressed"); + assert (UseCompressedClassPointers, "must be compressed"); assert(Universe::narrow_klass_base() != NULL, "narrow_klass_base should be initialized"); assert(r != G6_heapbase, "bad register choice"); set((intptr_t)Universe::narrow_klass_base(), G6_heapbase); @@ -4105,7 +4105,7 @@ void MacroAssembler::encode_klass_not_null(Register src, Register dst) { if (src == dst) { encode_klass_not_null(src); } else { - assert (UseCompressedKlassPointers, "must be compressed"); + assert (UseCompressedClassPointers, "must be compressed"); assert(Universe::narrow_klass_base() != NULL, "narrow_klass_base should be initialized"); set((intptr_t)Universe::narrow_klass_base(), dst); sub(src, dst, dst); @@ -4119,7 +4119,7 @@ void MacroAssembler::encode_klass_not_null(Register src, Register dst) { // generated by decode_klass_not_null() and reinit_heapbase(). Hence, if // the instructions they generate change, then this method needs to be updated. int MacroAssembler::instr_size_for_decode_klass_not_null() { - assert (UseCompressedKlassPointers, "only for compressed klass ptrs"); + assert (UseCompressedClassPointers, "only for compressed klass ptrs"); // set + add + set int num_instrs = insts_for_internal_set((intptr_t)Universe::narrow_klass_base()) + 1 + insts_for_internal_set((intptr_t)Universe::narrow_ptrs_base()); @@ -4135,7 +4135,7 @@ int MacroAssembler::instr_size_for_decode_klass_not_null() { void MacroAssembler::decode_klass_not_null(Register r) { // Do not add assert code to this unless you change vtableStubs_sparc.cpp // pd_code_size_limit. - assert (UseCompressedKlassPointers, "must be compressed"); + assert (UseCompressedClassPointers, "must be compressed"); assert(Universe::narrow_klass_base() != NULL, "narrow_klass_base should be initialized"); assert(r != G6_heapbase, "bad register choice"); set((intptr_t)Universe::narrow_klass_base(), G6_heapbase); @@ -4151,7 +4151,7 @@ void MacroAssembler::decode_klass_not_null(Register src, Register dst) { } else { // Do not add assert code to this unless you change vtableStubs_sparc.cpp // pd_code_size_limit. - assert (UseCompressedKlassPointers, "must be compressed"); + assert (UseCompressedClassPointers, "must be compressed"); assert(Universe::narrow_klass_base() != NULL, "narrow_klass_base should be initialized"); if (Universe::narrow_klass_shift() != 0) { assert((src != G6_heapbase) && (dst != G6_heapbase), "bad register choice"); @@ -4167,7 +4167,7 @@ void MacroAssembler::decode_klass_not_null(Register src, Register dst) { } void MacroAssembler::reinit_heapbase() { - if (UseCompressedOops || UseCompressedKlassPointers) { + if (UseCompressedOops || UseCompressedClassPointers) { if (Universe::heap() != NULL) { set((intptr_t)Universe::narrow_ptrs_base(), G6_heapbase); } else { diff --git a/hotspot/src/cpu/sparc/vm/sparc.ad b/hotspot/src/cpu/sparc/vm/sparc.ad index a72bffdadeb..58c113a0c1a 100644 --- a/hotspot/src/cpu/sparc/vm/sparc.ad +++ b/hotspot/src/cpu/sparc/vm/sparc.ad @@ -557,7 +557,7 @@ int MachCallDynamicJavaNode::ret_addr_offset() { int entry_offset = InstanceKlass::vtable_start_offset() + vtable_index*vtableEntry::size(); int v_off = entry_offset*wordSize + vtableEntry::method_offset_in_bytes(); int klass_load_size; - if (UseCompressedKlassPointers) { + if (UseCompressedClassPointers) { assert(Universe::heap() != NULL, "java heap should be initialized"); klass_load_size = MacroAssembler::instr_size_for_decode_klass_not_null() + 1*BytesPerInstWord; } else { @@ -1657,7 +1657,7 @@ uint BoxLockNode::size(PhaseRegAlloc *ra_) const { void MachUEPNode::format( PhaseRegAlloc *ra_, outputStream *st ) const { st->print_cr("\nUEP:"); #ifdef _LP64 - if (UseCompressedKlassPointers) { + if (UseCompressedClassPointers) { assert(Universe::heap() != NULL, "java heap should be initialized"); st->print_cr("\tLDUW [R_O0 + oopDesc::klass_offset_in_bytes],R_G5\t! Inline cache check - compressed klass"); st->print_cr("\tSET Universe::narrow_klass_base,R_G6_heap_base"); @@ -1897,7 +1897,7 @@ bool Matcher::narrow_oop_use_complex_address() { bool Matcher::narrow_klass_use_complex_address() { NOT_LP64(ShouldNotCallThis()); - assert(UseCompressedKlassPointers, "only for compressed klass code"); + assert(UseCompressedClassPointers, "only for compressed klass code"); return false; } @@ -2561,7 +2561,7 @@ encode %{ int off = __ offset(); __ load_klass(O0, G3_scratch); int klass_load_size; - if (UseCompressedKlassPointers) { + if (UseCompressedClassPointers) { assert(Universe::heap() != NULL, "java heap should be initialized"); klass_load_size = MacroAssembler::instr_size_for_decode_klass_not_null() + 1*BytesPerInstWord; } else { diff --git a/hotspot/src/cpu/sparc/vm/stubGenerator_sparc.cpp b/hotspot/src/cpu/sparc/vm/stubGenerator_sparc.cpp index 214940cdbfb..612ae118ee4 100644 --- a/hotspot/src/cpu/sparc/vm/stubGenerator_sparc.cpp +++ b/hotspot/src/cpu/sparc/vm/stubGenerator_sparc.cpp @@ -2945,7 +2945,7 @@ class StubGenerator: public StubCodeGenerator { BLOCK_COMMENT("arraycopy argument klass checks"); // get src->klass() - if (UseCompressedKlassPointers) { + if (UseCompressedClassPointers) { __ delayed()->nop(); // ??? not good __ load_klass(src, G3_src_klass); } else { @@ -2980,7 +2980,7 @@ class StubGenerator: public StubCodeGenerator { // Load 32-bits signed value. Use br() instruction with it to check icc. __ lduw(G3_src_klass, lh_offset, G5_lh); - if (UseCompressedKlassPointers) { + if (UseCompressedClassPointers) { __ load_klass(dst, G4_dst_klass); } // Handle objArrays completely differently... @@ -2988,7 +2988,7 @@ class StubGenerator: public StubCodeGenerator { __ set(objArray_lh, O5_temp); __ cmp(G5_lh, O5_temp); __ br(Assembler::equal, false, Assembler::pt, L_objArray); - if (UseCompressedKlassPointers) { + if (UseCompressedClassPointers) { __ delayed()->nop(); } else { __ delayed()->ld_ptr(dst, oopDesc::klass_offset_in_bytes(), G4_dst_klass); diff --git a/hotspot/src/cpu/sparc/vm/vtableStubs_sparc.cpp b/hotspot/src/cpu/sparc/vm/vtableStubs_sparc.cpp index 39663758035..ce19d4d7e7b 100644 --- a/hotspot/src/cpu/sparc/vm/vtableStubs_sparc.cpp +++ b/hotspot/src/cpu/sparc/vm/vtableStubs_sparc.cpp @@ -218,13 +218,13 @@ int VtableStub::pd_code_size_limit(bool is_vtable_stub) { // ld;ld;ld,jmp,nop const int basic = 5*BytesPerInstWord + // shift;add for load_klass (only shift with zero heap based) - (UseCompressedKlassPointers ? + (UseCompressedClassPointers ? MacroAssembler::instr_size_for_decode_klass_not_null() : 0); return basic + slop; } else { const int basic = (28 LP64_ONLY(+ 6)) * BytesPerInstWord + // shift;add for load_klass (only shift with zero heap based) - (UseCompressedKlassPointers ? + (UseCompressedClassPointers ? MacroAssembler::instr_size_for_decode_klass_not_null() : 0); return (basic + slop); } diff --git a/hotspot/src/cpu/x86/vm/c1_FrameMap_x86.hpp b/hotspot/src/cpu/x86/vm/c1_FrameMap_x86.hpp index ea5d6d39da6..2d1b5f1f3c7 100644 --- a/hotspot/src/cpu/x86/vm/c1_FrameMap_x86.hpp +++ b/hotspot/src/cpu/x86/vm/c1_FrameMap_x86.hpp @@ -148,7 +148,7 @@ static int adjust_reg_range(int range) { // Reduce the number of available regs (to free r12) in case of compressed oops - if (UseCompressedOops || UseCompressedKlassPointers) return range - 1; + if (UseCompressedOops || UseCompressedClassPointers) return range - 1; return range; } diff --git a/hotspot/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp b/hotspot/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp index 334d0cc92db..735d343898f 100644 --- a/hotspot/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp +++ b/hotspot/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp @@ -341,7 +341,7 @@ int LIR_Assembler::check_icache() { Register receiver = FrameMap::receiver_opr->as_register(); Register ic_klass = IC_Klass; const int ic_cmp_size = LP64_ONLY(10) NOT_LP64(9); - const bool do_post_padding = VerifyOops || UseCompressedKlassPointers; + const bool do_post_padding = VerifyOops || UseCompressedClassPointers; if (!do_post_padding) { // insert some nops so that the verified entry point is aligned on CodeEntryAlignment while ((__ offset() + ic_cmp_size) % CodeEntryAlignment != 0) { @@ -1263,7 +1263,7 @@ void LIR_Assembler::mem2reg(LIR_Opr src, LIR_Opr dest, BasicType type, LIR_Patch break; case T_ADDRESS: - if (UseCompressedKlassPointers && addr->disp() == oopDesc::klass_offset_in_bytes()) { + if (UseCompressedClassPointers && addr->disp() == oopDesc::klass_offset_in_bytes()) { __ movl(dest->as_register(), from_addr); } else { __ movptr(dest->as_register(), from_addr); @@ -1371,7 +1371,7 @@ void LIR_Assembler::mem2reg(LIR_Opr src, LIR_Opr dest, BasicType type, LIR_Patch __ verify_oop(dest->as_register()); } else if (type == T_ADDRESS && addr->disp() == oopDesc::klass_offset_in_bytes()) { #ifdef _LP64 - if (UseCompressedKlassPointers) { + if (UseCompressedClassPointers) { __ decode_klass_not_null(dest->as_register()); } #endif @@ -1716,7 +1716,7 @@ void LIR_Assembler::emit_typecheck_helper(LIR_OpTypeCheck *op, Label* success, L } else if (obj == klass_RInfo) { klass_RInfo = dst; } - if (k->is_loaded() && !UseCompressedKlassPointers) { + if (k->is_loaded() && !UseCompressedClassPointers) { select_different_registers(obj, dst, k_RInfo, klass_RInfo); } else { Rtmp1 = op->tmp3()->as_register(); @@ -1754,7 +1754,7 @@ void LIR_Assembler::emit_typecheck_helper(LIR_OpTypeCheck *op, Label* success, L // get object class // not a safepoint as obj null check happens earlier #ifdef _LP64 - if (UseCompressedKlassPointers) { + if (UseCompressedClassPointers) { __ load_klass(Rtmp1, obj); __ cmpptr(k_RInfo, Rtmp1); } else { @@ -3294,7 +3294,7 @@ void LIR_Assembler::emit_arraycopy(LIR_OpArrayCopy* op) { // We don't know the array types are compatible if (basic_type != T_OBJECT) { // Simple test for basic type arrays - if (UseCompressedKlassPointers) { + if (UseCompressedClassPointers) { __ movl(tmp, src_klass_addr); __ cmpl(tmp, dst_klass_addr); } else { @@ -3456,21 +3456,21 @@ void LIR_Assembler::emit_arraycopy(LIR_OpArrayCopy* op) { Label known_ok, halt; __ mov_metadata(tmp, default_type->constant_encoding()); #ifdef _LP64 - if (UseCompressedKlassPointers) { + if (UseCompressedClassPointers) { __ encode_klass_not_null(tmp); } #endif if (basic_type != T_OBJECT) { - if (UseCompressedKlassPointers) __ cmpl(tmp, dst_klass_addr); + if (UseCompressedClassPointers) __ cmpl(tmp, dst_klass_addr); else __ cmpptr(tmp, dst_klass_addr); __ jcc(Assembler::notEqual, halt); - if (UseCompressedKlassPointers) __ cmpl(tmp, src_klass_addr); + if (UseCompressedClassPointers) __ cmpl(tmp, src_klass_addr); else __ cmpptr(tmp, src_klass_addr); __ jcc(Assembler::equal, known_ok); } else { - if (UseCompressedKlassPointers) __ cmpl(tmp, dst_klass_addr); + if (UseCompressedClassPointers) __ cmpl(tmp, dst_klass_addr); else __ cmpptr(tmp, dst_klass_addr); __ jcc(Assembler::equal, known_ok); __ cmpptr(src, dst); diff --git a/hotspot/src/cpu/x86/vm/c1_LIRGenerator_x86.cpp b/hotspot/src/cpu/x86/vm/c1_LIRGenerator_x86.cpp index e6638581bcf..308befddc77 100644 --- a/hotspot/src/cpu/x86/vm/c1_LIRGenerator_x86.cpp +++ b/hotspot/src/cpu/x86/vm/c1_LIRGenerator_x86.cpp @@ -1239,7 +1239,7 @@ void LIRGenerator::do_CheckCast(CheckCast* x) { } LIR_Opr reg = rlock_result(x); LIR_Opr tmp3 = LIR_OprFact::illegalOpr; - if (!x->klass()->is_loaded() || UseCompressedKlassPointers) { + if (!x->klass()->is_loaded() || UseCompressedClassPointers) { tmp3 = new_register(objectType); } __ checkcast(reg, obj.result(), x->klass(), @@ -1261,7 +1261,7 @@ void LIRGenerator::do_InstanceOf(InstanceOf* x) { } obj.load_item(); LIR_Opr tmp3 = LIR_OprFact::illegalOpr; - if (!x->klass()->is_loaded() || UseCompressedKlassPointers) { + if (!x->klass()->is_loaded() || UseCompressedClassPointers) { tmp3 = new_register(objectType); } __ instanceof(reg, obj.result(), x->klass(), diff --git a/hotspot/src/cpu/x86/vm/c1_MacroAssembler_x86.cpp b/hotspot/src/cpu/x86/vm/c1_MacroAssembler_x86.cpp index d9ae6ce5de5..805fe5a48ca 100644 --- a/hotspot/src/cpu/x86/vm/c1_MacroAssembler_x86.cpp +++ b/hotspot/src/cpu/x86/vm/c1_MacroAssembler_x86.cpp @@ -157,7 +157,7 @@ void C1_MacroAssembler::initialize_header(Register obj, Register klass, Register movptr(Address(obj, oopDesc::mark_offset_in_bytes ()), (int32_t)(intptr_t)markOopDesc::prototype()); } #ifdef _LP64 - if (UseCompressedKlassPointers) { // Take care not to kill klass + if (UseCompressedClassPointers) { // Take care not to kill klass movptr(t1, klass); encode_klass_not_null(t1); movl(Address(obj, oopDesc::klass_offset_in_bytes()), t1); @@ -171,7 +171,7 @@ void C1_MacroAssembler::initialize_header(Register obj, Register klass, Register movl(Address(obj, arrayOopDesc::length_offset_in_bytes()), len); } #ifdef _LP64 - else if (UseCompressedKlassPointers) { + else if (UseCompressedClassPointers) { xorptr(t1, t1); store_klass_gap(obj, t1); } @@ -334,7 +334,7 @@ void C1_MacroAssembler::inline_cache_check(Register receiver, Register iCache) { assert(!MacroAssembler::needs_explicit_null_check(oopDesc::klass_offset_in_bytes()), "must add explicit null check"); int start_offset = offset(); - if (UseCompressedKlassPointers) { + if (UseCompressedClassPointers) { load_klass(rscratch1, receiver); cmpptr(rscratch1, iCache); } else { @@ -345,7 +345,7 @@ void C1_MacroAssembler::inline_cache_check(Register receiver, Register iCache) { jump_cc(Assembler::notEqual, RuntimeAddress(SharedRuntime::get_ic_miss_stub())); const int ic_cmp_size = LP64_ONLY(10) NOT_LP64(9); - assert(UseCompressedKlassPointers || offset() - start_offset == ic_cmp_size, "check alignment in emit_method_entry"); + assert(UseCompressedClassPointers || offset() - start_offset == ic_cmp_size, "check alignment in emit_method_entry"); } diff --git a/hotspot/src/cpu/x86/vm/macroAssembler_x86.cpp b/hotspot/src/cpu/x86/vm/macroAssembler_x86.cpp index b331f694959..fed50ef4286 100644 --- a/hotspot/src/cpu/x86/vm/macroAssembler_x86.cpp +++ b/hotspot/src/cpu/x86/vm/macroAssembler_x86.cpp @@ -1635,7 +1635,7 @@ void MacroAssembler::call_VM_base(Register oop_result, #ifdef ASSERT // TraceBytecodes does not use r12 but saves it over the call, so don't verify // r12 is the heapbase. - LP64_ONLY(if ((UseCompressedOops || UseCompressedKlassPointers) && !TraceBytecodes) verify_heapbase("call_VM_base: heap base corrupted?");) + LP64_ONLY(if ((UseCompressedOops || UseCompressedClassPointers) && !TraceBytecodes) verify_heapbase("call_VM_base: heap base corrupted?");) #endif // ASSERT assert(java_thread != oop_result , "cannot use the same register for java_thread & oop_result"); @@ -4802,7 +4802,7 @@ void MacroAssembler::restore_cpu_control_state_after_jni() { void MacroAssembler::load_klass(Register dst, Register src) { #ifdef _LP64 - if (UseCompressedKlassPointers) { + if (UseCompressedClassPointers) { movl(dst, Address(src, oopDesc::klass_offset_in_bytes())); decode_klass_not_null(dst); } else @@ -4817,7 +4817,7 @@ void MacroAssembler::load_prototype_header(Register dst, Register src) { void MacroAssembler::store_klass(Register dst, Register src) { #ifdef _LP64 - if (UseCompressedKlassPointers) { + if (UseCompressedClassPointers) { encode_klass_not_null(src); movl(Address(dst, oopDesc::klass_offset_in_bytes()), src); } else @@ -4892,7 +4892,7 @@ void MacroAssembler::store_heap_oop_null(Address dst) { #ifdef _LP64 void MacroAssembler::store_klass_gap(Register dst, Register src) { - if (UseCompressedKlassPointers) { + if (UseCompressedClassPointers) { // Store to klass gap in destination movl(Address(dst, oopDesc::klass_gap_offset_in_bytes()), src); } @@ -5075,7 +5075,7 @@ void MacroAssembler::encode_klass_not_null(Register dst, Register src) { // when (Universe::heap() != NULL). Hence, if the instructions they // generate change, then this method needs to be updated. int MacroAssembler::instr_size_for_decode_klass_not_null() { - assert (UseCompressedKlassPointers, "only for compressed klass ptrs"); + assert (UseCompressedClassPointers, "only for compressed klass ptrs"); // mov64 + addq + shlq? + mov64 (for reinit_heapbase()). return (Universe::narrow_klass_shift() == 0 ? 20 : 24); } @@ -5085,7 +5085,7 @@ int MacroAssembler::instr_size_for_decode_klass_not_null() { void MacroAssembler::decode_klass_not_null(Register r) { // Note: it will change flags assert(Universe::narrow_klass_base() != NULL, "Base should be initialized"); - assert (UseCompressedKlassPointers, "should only be used for compressed headers"); + assert (UseCompressedClassPointers, "should only be used for compressed headers"); assert(r != r12_heapbase, "Decoding a klass in r12"); // Cannot assert, unverified entry point counts instructions (see .ad file) // vtableStubs also counts instructions in pd_code_size_limit. @@ -5103,7 +5103,7 @@ void MacroAssembler::decode_klass_not_null(Register r) { void MacroAssembler::decode_klass_not_null(Register dst, Register src) { // Note: it will change flags assert(Universe::narrow_klass_base() != NULL, "Base should be initialized"); - assert (UseCompressedKlassPointers, "should only be used for compressed headers"); + assert (UseCompressedClassPointers, "should only be used for compressed headers"); if (dst == src) { decode_klass_not_null(dst); } else { @@ -5141,7 +5141,7 @@ void MacroAssembler::set_narrow_oop(Address dst, jobject obj) { } void MacroAssembler::set_narrow_klass(Register dst, Klass* k) { - assert (UseCompressedKlassPointers, "should only be used for compressed headers"); + assert (UseCompressedClassPointers, "should only be used for compressed headers"); assert (oop_recorder() != NULL, "this assembler needs an OopRecorder"); int klass_index = oop_recorder()->find_index(k); RelocationHolder rspec = metadata_Relocation::spec(klass_index); @@ -5149,7 +5149,7 @@ void MacroAssembler::set_narrow_klass(Register dst, Klass* k) { } void MacroAssembler::set_narrow_klass(Address dst, Klass* k) { - assert (UseCompressedKlassPointers, "should only be used for compressed headers"); + assert (UseCompressedClassPointers, "should only be used for compressed headers"); assert (oop_recorder() != NULL, "this assembler needs an OopRecorder"); int klass_index = oop_recorder()->find_index(k); RelocationHolder rspec = metadata_Relocation::spec(klass_index); @@ -5175,7 +5175,7 @@ void MacroAssembler::cmp_narrow_oop(Address dst, jobject obj) { } void MacroAssembler::cmp_narrow_klass(Register dst, Klass* k) { - assert (UseCompressedKlassPointers, "should only be used for compressed headers"); + assert (UseCompressedClassPointers, "should only be used for compressed headers"); assert (oop_recorder() != NULL, "this assembler needs an OopRecorder"); int klass_index = oop_recorder()->find_index(k); RelocationHolder rspec = metadata_Relocation::spec(klass_index); @@ -5183,7 +5183,7 @@ void MacroAssembler::cmp_narrow_klass(Register dst, Klass* k) { } void MacroAssembler::cmp_narrow_klass(Address dst, Klass* k) { - assert (UseCompressedKlassPointers, "should only be used for compressed headers"); + assert (UseCompressedClassPointers, "should only be used for compressed headers"); assert (oop_recorder() != NULL, "this assembler needs an OopRecorder"); int klass_index = oop_recorder()->find_index(k); RelocationHolder rspec = metadata_Relocation::spec(klass_index); @@ -5191,7 +5191,7 @@ void MacroAssembler::cmp_narrow_klass(Address dst, Klass* k) { } void MacroAssembler::reinit_heapbase() { - if (UseCompressedOops || UseCompressedKlassPointers) { + if (UseCompressedOops || UseCompressedClassPointers) { if (Universe::heap() != NULL) { if (Universe::narrow_oop_base() == NULL) { MacroAssembler::xorptr(r12_heapbase, r12_heapbase); diff --git a/hotspot/src/cpu/x86/vm/vtableStubs_x86_64.cpp b/hotspot/src/cpu/x86/vm/vtableStubs_x86_64.cpp index 518da23eb60..5f5f94f41a5 100644 --- a/hotspot/src/cpu/x86/vm/vtableStubs_x86_64.cpp +++ b/hotspot/src/cpu/x86/vm/vtableStubs_x86_64.cpp @@ -211,11 +211,11 @@ int VtableStub::pd_code_size_limit(bool is_vtable_stub) { if (is_vtable_stub) { // Vtable stub size return (DebugVtables ? 512 : 24) + (CountCompiledCalls ? 13 : 0) + - (UseCompressedKlassPointers ? MacroAssembler::instr_size_for_decode_klass_not_null() : 0); + (UseCompressedClassPointers ? MacroAssembler::instr_size_for_decode_klass_not_null() : 0); } else { // Itable stub size return (DebugVtables ? 512 : 74) + (CountCompiledCalls ? 13 : 0) + - (UseCompressedKlassPointers ? MacroAssembler::instr_size_for_decode_klass_not_null() : 0); + (UseCompressedClassPointers ? MacroAssembler::instr_size_for_decode_klass_not_null() : 0); } // In order to tune these parameters, run the JVM with VM options // +PrintMiscellaneous and +WizardMode to see information about diff --git a/hotspot/src/cpu/x86/vm/x86_64.ad b/hotspot/src/cpu/x86/vm/x86_64.ad index f550208e94d..ed13b3da1d1 100644 --- a/hotspot/src/cpu/x86/vm/x86_64.ad +++ b/hotspot/src/cpu/x86/vm/x86_64.ad @@ -1391,7 +1391,7 @@ uint BoxLockNode::size(PhaseRegAlloc *ra_) const #ifndef PRODUCT void MachUEPNode::format(PhaseRegAlloc* ra_, outputStream* st) const { - if (UseCompressedKlassPointers) { + if (UseCompressedClassPointers) { st->print_cr("movl rscratch1, [j_rarg0 + oopDesc::klass_offset_in_bytes()]\t# compressed klass"); st->print_cr("\tdecode_klass_not_null rscratch1, rscratch1"); st->print_cr("\tcmpq rax, rscratch1\t # Inline cache check"); @@ -1408,7 +1408,7 @@ void MachUEPNode::emit(CodeBuffer& cbuf, PhaseRegAlloc* ra_) const { MacroAssembler masm(&cbuf); uint insts_size = cbuf.insts_size(); - if (UseCompressedKlassPointers) { + if (UseCompressedClassPointers) { masm.load_klass(rscratch1, j_rarg0); masm.cmpptr(rax, rscratch1); } else { @@ -1557,7 +1557,7 @@ bool Matcher::narrow_oop_use_complex_address() { } bool Matcher::narrow_klass_use_complex_address() { - assert(UseCompressedKlassPointers, "only for compressed klass code"); + assert(UseCompressedClassPointers, "only for compressed klass code"); return (LogKlassAlignmentInBytes <= 3); } diff --git a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp index 04b550c718b..2fc6edd34df 100644 --- a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp +++ b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp @@ -230,7 +230,7 @@ ConcurrentMarkSweepGeneration::ConcurrentMarkSweepGeneration( // depends on this property. debug_only( FreeChunk* junk = NULL; - assert(UseCompressedKlassPointers || + assert(UseCompressedClassPointers || junk->prev_addr() == (void*)(oop(junk)->klass_addr()), "Offset of FreeChunk::_prev within FreeChunk must match" " that of OopDesc::_klass within OopDesc"); @@ -1407,7 +1407,7 @@ ConcurrentMarkSweepGeneration::par_promote(int thread_num, assert(!((FreeChunk*)obj_ptr)->is_free(), "Error, block will look free but show wrong size"); OrderAccess::storestore(); - if (UseCompressedKlassPointers) { + if (UseCompressedClassPointers) { // Copy gap missed by (aligned) header size calculation below obj->set_klass_gap(old->klass_gap()); } diff --git a/hotspot/src/share/vm/memory/metaspace.cpp b/hotspot/src/share/vm/memory/metaspace.cpp index cd46888c9c2..1c5cec84d5f 100644 --- a/hotspot/src/share/vm/memory/metaspace.cpp +++ b/hotspot/src/share/vm/memory/metaspace.cpp @@ -423,7 +423,7 @@ class VirtualSpaceList : public CHeapObj { // Can this virtual list allocate >1 spaces? Also, used to determine // whether to allocate unlimited small chunks in this virtual space bool _is_class; - bool can_grow() const { return !is_class() || !UseCompressedKlassPointers; } + bool can_grow() const { return !is_class() || !UseCompressedClassPointers; } // Sum of space in all virtual spaces and number of virtual spaces size_t _virtual_space_total; @@ -2836,7 +2836,7 @@ void Metaspace::set_narrow_klass_base_and_shift(address metaspace_base, address // to work with compressed klass pointers. bool Metaspace::can_use_cds_with_metaspace_addr(char* metaspace_base, address cds_base) { assert(cds_base != 0 && UseSharedSpaces, "Only use with CDS"); - assert(UseCompressedKlassPointers, "Only use with CompressedKlassPtrs"); + assert(UseCompressedClassPointers, "Only use with CompressedKlassPtrs"); address lower_base = MIN2((address)metaspace_base, cds_base); address higher_address = MAX2((address)(cds_base + FileMapInfo::shared_spaces_size()), (address)(metaspace_base + class_metaspace_size())); @@ -2846,7 +2846,7 @@ bool Metaspace::can_use_cds_with_metaspace_addr(char* metaspace_base, address cd // Try to allocate the metaspace at the requested addr. void Metaspace::allocate_metaspace_compressed_klass_ptrs(char* requested_addr, address cds_base) { assert(using_class_space(), "called improperly"); - assert(UseCompressedKlassPointers, "Only use with CompressedKlassPtrs"); + assert(UseCompressedClassPointers, "Only use with CompressedKlassPtrs"); assert(class_metaspace_size() < KlassEncodingMetaspaceMax, "Metaspace size is too big"); @@ -2869,9 +2869,9 @@ void Metaspace::allocate_metaspace_compressed_klass_ptrs(char* requested_addr, a // If no successful allocation then try to allocate the space anywhere. If // that fails then OOM doom. At this point we cannot try allocating the - // metaspace as if UseCompressedKlassPointers is off because too much - // initialization has happened that depends on UseCompressedKlassPointers. - // So, UseCompressedKlassPointers cannot be turned off at this point. + // metaspace as if UseCompressedClassPointers is off because too much + // initialization has happened that depends on UseCompressedClassPointers. + // So, UseCompressedClassPointers cannot be turned off at this point. if (!metaspace_rs.is_reserved()) { metaspace_rs = ReservedSpace(class_metaspace_size(), os::vm_allocation_granularity(), false); @@ -2904,12 +2904,12 @@ void Metaspace::allocate_metaspace_compressed_klass_ptrs(char* requested_addr, a } } -// For UseCompressedKlassPointers the class space is reserved above the top of +// For UseCompressedClassPointers the class space is reserved above the top of // the Java heap. The argument passed in is at the base of the compressed space. void Metaspace::initialize_class_space(ReservedSpace rs) { // The reserved space size may be bigger because of alignment, esp with UseLargePages - assert(rs.size() >= ClassMetaspaceSize, - err_msg(SIZE_FORMAT " != " UINTX_FORMAT, rs.size(), ClassMetaspaceSize)); + assert(rs.size() >= CompressedClassSpaceSize, + err_msg(SIZE_FORMAT " != " UINTX_FORMAT, rs.size(), CompressedClassSpaceSize)); assert(using_class_space(), "Must be using class space"); _class_space_list = new VirtualSpaceList(rs); } @@ -2921,7 +2921,7 @@ void Metaspace::global_initialize() { int max_alignment = os::vm_page_size(); size_t cds_total = 0; - set_class_metaspace_size(align_size_up(ClassMetaspaceSize, + set_class_metaspace_size(align_size_up(CompressedClassSpaceSize, os::vm_allocation_granularity())); MetaspaceShared::set_max_alignment(max_alignment); @@ -2941,8 +2941,8 @@ void Metaspace::global_initialize() { #ifdef _LP64 // Set the compressed klass pointer base so that decoding of these pointers works // properly when creating the shared archive. - assert(UseCompressedOops && UseCompressedKlassPointers, - "UseCompressedOops and UseCompressedKlassPointers must be set"); + assert(UseCompressedOops && UseCompressedClassPointers, + "UseCompressedOops and UseCompressedClassPointers must be set"); Universe::set_narrow_klass_base((address)_space_list->current_virtual_space()->bottom()); if (TraceMetavirtualspaceAllocation && Verbose) { gclog_or_tty->print_cr("Setting_narrow_klass_base to Address: " PTR_FORMAT, @@ -2979,7 +2979,7 @@ void Metaspace::global_initialize() { } #ifdef _LP64 - // If UseCompressedKlassPointers is set then allocate the metaspace area + // If UseCompressedClassPointers is set then allocate the metaspace area // above the heap and above the CDS area (if it exists). if (using_class_space()) { if (UseSharedSpaces) { @@ -2997,7 +2997,7 @@ void Metaspace::global_initialize() { // on the medium chunk list. The next chunk will be small and progress // from there. This size calculated by -version. _first_class_chunk_word_size = MIN2((size_t)MediumChunk*6, - (ClassMetaspaceSize/BytesPerWord)*2); + (CompressedClassSpaceSize/BytesPerWord)*2); _first_class_chunk_word_size = align_word_size_up(_first_class_chunk_word_size); // Arbitrarily set the initial virtual space to a multiple // of the boot class loader size. @@ -3064,7 +3064,7 @@ size_t Metaspace::align_word_size_up(size_t word_size) { MetaWord* Metaspace::allocate(size_t word_size, MetadataType mdtype) { // DumpSharedSpaces doesn't use class metadata area (yet) - // Also, don't use class_vsm() unless UseCompressedKlassPointers is true. + // Also, don't use class_vsm() unless UseCompressedClassPointers is true. if (mdtype == ClassType && using_class_space()) { return class_vsm()->allocate(word_size); } else { @@ -3213,7 +3213,7 @@ Metablock* Metaspace::allocate(ClassLoaderData* loader_data, size_t word_size, MetaspaceAux::dump(gclog_or_tty); } // -XX:+HeapDumpOnOutOfMemoryError and -XX:OnOutOfMemoryError support - const char* space_string = (mdtype == ClassType) ? "Class Metadata space" : + const char* space_string = (mdtype == ClassType) ? "Compressed class space" : "Metadata space"; report_java_out_of_memory(space_string); diff --git a/hotspot/src/share/vm/memory/metaspace.hpp b/hotspot/src/share/vm/memory/metaspace.hpp index 88f089494d3..591acf30075 100644 --- a/hotspot/src/share/vm/memory/metaspace.hpp +++ b/hotspot/src/share/vm/memory/metaspace.hpp @@ -213,9 +213,9 @@ class Metaspace : public CHeapObj { void iterate(AllocRecordClosure *closure); - // Return TRUE only if UseCompressedKlassPointers is True and DumpSharedSpaces is False. + // Return TRUE only if UseCompressedClassPointers is True and DumpSharedSpaces is False. static bool using_class_space() { - return NOT_LP64(false) LP64_ONLY(UseCompressedKlassPointers && !DumpSharedSpaces); + return NOT_LP64(false) LP64_ONLY(UseCompressedClassPointers && !DumpSharedSpaces); } }; diff --git a/hotspot/src/share/vm/memory/metaspaceCounters.cpp b/hotspot/src/share/vm/memory/metaspaceCounters.cpp index eb7bebd28b6..32eda2b4ed8 100644 --- a/hotspot/src/share/vm/memory/metaspaceCounters.cpp +++ b/hotspot/src/share/vm/memory/metaspaceCounters.cpp @@ -109,7 +109,7 @@ size_t CompressedClassSpaceCounters::calculate_capacity() { } void CompressedClassSpaceCounters::update_performance_counters() { - if (UsePerfData && UseCompressedKlassPointers) { + if (UsePerfData && UseCompressedClassPointers) { assert(_perf_counters != NULL, "Should be initialized"); size_t capacity = calculate_capacity(); @@ -125,7 +125,7 @@ void CompressedClassSpaceCounters::initialize_performance_counters() { assert(_perf_counters == NULL, "Should only be initialized once"); const char* ns = "compressedclassspace"; - if (UseCompressedKlassPointers) { + if (UseCompressedClassPointers) { size_t min_capacity = MetaspaceAux::min_chunk_size(); size_t capacity = calculate_capacity(); size_t max_capacity = MetaspaceAux::reserved_in_bytes(_class_type); diff --git a/hotspot/src/share/vm/memory/universe.cpp b/hotspot/src/share/vm/memory/universe.cpp index 143c0c00c45..d0f34b33ae1 100644 --- a/hotspot/src/share/vm/memory/universe.cpp +++ b/hotspot/src/share/vm/memory/universe.cpp @@ -1028,7 +1028,7 @@ bool universe_post_init() { msg = java_lang_String::create_from_str("Metadata space", CHECK_false); java_lang_Throwable::set_message(Universe::_out_of_memory_error_metaspace, msg()); - msg = java_lang_String::create_from_str("Class Metadata space", CHECK_false); + msg = java_lang_String::create_from_str("Compressed class space", CHECK_false); java_lang_Throwable::set_message(Universe::_out_of_memory_error_class_metaspace, msg()); msg = java_lang_String::create_from_str("Requested array size exceeds VM limit", CHECK_false); diff --git a/hotspot/src/share/vm/memory/universe.hpp b/hotspot/src/share/vm/memory/universe.hpp index a8b541d03a1..4c698f95174 100644 --- a/hotspot/src/share/vm/memory/universe.hpp +++ b/hotspot/src/share/vm/memory/universe.hpp @@ -181,7 +181,7 @@ class Universe: AllStatic { // For UseCompressedOops. static struct NarrowPtrStruct _narrow_oop; - // For UseCompressedKlassPointers. + // For UseCompressedClassPointers. static struct NarrowPtrStruct _narrow_klass; static address _narrow_ptrs_base; @@ -229,7 +229,7 @@ class Universe: AllStatic { _narrow_oop._base = base; } static void set_narrow_klass_base(address base) { - assert(UseCompressedKlassPointers, "no compressed klass ptrs?"); + assert(UseCompressedClassPointers, "no compressed klass ptrs?"); _narrow_klass._base = base; } static void set_narrow_oop_use_implicit_null_checks(bool use) { @@ -353,7 +353,7 @@ class Universe: AllStatic { static int narrow_oop_shift() { return _narrow_oop._shift; } static bool narrow_oop_use_implicit_null_checks() { return _narrow_oop._use_implicit_null_checks; } - // For UseCompressedKlassPointers + // For UseCompressedClassPointers static address narrow_klass_base() { return _narrow_klass._base; } static bool is_narrow_klass_base(void* addr) { return (narrow_klass_base() == (address)addr); } static int narrow_klass_shift() { return _narrow_klass._shift; } diff --git a/hotspot/src/share/vm/oops/arrayOop.hpp b/hotspot/src/share/vm/oops/arrayOop.hpp index 806b7b7289a..0e5ceffe35a 100644 --- a/hotspot/src/share/vm/oops/arrayOop.hpp +++ b/hotspot/src/share/vm/oops/arrayOop.hpp @@ -65,7 +65,7 @@ class arrayOopDesc : public oopDesc { // declared nonstatic fields in arrayOopDesc if not compressed, otherwise // it occupies the second half of the _klass field in oopDesc. static int length_offset_in_bytes() { - return UseCompressedKlassPointers ? klass_gap_offset_in_bytes() : + return UseCompressedClassPointers ? klass_gap_offset_in_bytes() : sizeof(arrayOopDesc); } diff --git a/hotspot/src/share/vm/oops/instanceOop.hpp b/hotspot/src/share/vm/oops/instanceOop.hpp index 9ebb9d4720b..bdac1992e6f 100644 --- a/hotspot/src/share/vm/oops/instanceOop.hpp +++ b/hotspot/src/share/vm/oops/instanceOop.hpp @@ -37,9 +37,9 @@ class instanceOopDesc : public oopDesc { // If compressed, the offset of the fields of the instance may not be aligned. static int base_offset_in_bytes() { - // offset computation code breaks if UseCompressedKlassPointers + // offset computation code breaks if UseCompressedClassPointers // only is true - return (UseCompressedOops && UseCompressedKlassPointers) ? + return (UseCompressedOops && UseCompressedClassPointers) ? klass_gap_offset_in_bytes() : sizeof(instanceOopDesc); } diff --git a/hotspot/src/share/vm/oops/oop.inline.hpp b/hotspot/src/share/vm/oops/oop.inline.hpp index 9a6c1e1787b..f1823f2e2b1 100644 --- a/hotspot/src/share/vm/oops/oop.inline.hpp +++ b/hotspot/src/share/vm/oops/oop.inline.hpp @@ -69,7 +69,7 @@ inline markOop oopDesc::cas_set_mark(markOop new_mark, markOop old_mark) { } inline Klass* oopDesc::klass() const { - if (UseCompressedKlassPointers) { + if (UseCompressedClassPointers) { return Klass::decode_klass_not_null(_metadata._compressed_klass); } else { return _metadata._klass; @@ -78,7 +78,7 @@ inline Klass* oopDesc::klass() const { inline Klass* oopDesc::klass_or_null() const volatile { // can be NULL in CMS - if (UseCompressedKlassPointers) { + if (UseCompressedClassPointers) { return Klass::decode_klass(_metadata._compressed_klass); } else { return _metadata._klass; @@ -86,19 +86,19 @@ inline Klass* oopDesc::klass_or_null() const volatile { } inline int oopDesc::klass_gap_offset_in_bytes() { - assert(UseCompressedKlassPointers, "only applicable to compressed klass pointers"); + assert(UseCompressedClassPointers, "only applicable to compressed klass pointers"); return oopDesc::klass_offset_in_bytes() + sizeof(narrowKlass); } inline Klass** oopDesc::klass_addr() { // Only used internally and with CMS and will not work with // UseCompressedOops - assert(!UseCompressedKlassPointers, "only supported with uncompressed klass pointers"); + assert(!UseCompressedClassPointers, "only supported with uncompressed klass pointers"); return (Klass**) &_metadata._klass; } inline narrowKlass* oopDesc::compressed_klass_addr() { - assert(UseCompressedKlassPointers, "only called by compressed klass pointers"); + assert(UseCompressedClassPointers, "only called by compressed klass pointers"); return &_metadata._compressed_klass; } @@ -106,7 +106,7 @@ inline void oopDesc::set_klass(Klass* k) { // since klasses are promoted no store check is needed assert(Universe::is_bootstrapping() || k != NULL, "must be a real Klass*"); assert(Universe::is_bootstrapping() || k->is_klass(), "not a Klass*"); - if (UseCompressedKlassPointers) { + if (UseCompressedClassPointers) { *compressed_klass_addr() = Klass::encode_klass_not_null(k); } else { *klass_addr() = k; @@ -118,7 +118,7 @@ inline int oopDesc::klass_gap() const { } inline void oopDesc::set_klass_gap(int v) { - if (UseCompressedKlassPointers) { + if (UseCompressedClassPointers) { *(int*)(((intptr_t)this) + klass_gap_offset_in_bytes()) = v; } } @@ -126,7 +126,7 @@ inline void oopDesc::set_klass_gap(int v) { inline void oopDesc::set_klass_to_list_ptr(oop k) { // This is only to be used during GC, for from-space objects, so no // barrier is needed. - if (UseCompressedKlassPointers) { + if (UseCompressedClassPointers) { _metadata._compressed_klass = (narrowKlass)encode_heap_oop(k); // may be null (parnew overflow handling) } else { _metadata._klass = (Klass*)(address)k; @@ -135,7 +135,7 @@ inline void oopDesc::set_klass_to_list_ptr(oop k) { inline oop oopDesc::list_ptr_from_klass() { // This is only to be used during GC, for from-space objects. - if (UseCompressedKlassPointers) { + if (UseCompressedClassPointers) { return decode_heap_oop((narrowOop)_metadata._compressed_klass); } else { // Special case for GC diff --git a/hotspot/src/share/vm/opto/cfgnode.cpp b/hotspot/src/share/vm/opto/cfgnode.cpp index 4185ada5d1c..36347fb9202 100644 --- a/hotspot/src/share/vm/opto/cfgnode.cpp +++ b/hotspot/src/share/vm/opto/cfgnode.cpp @@ -1932,7 +1932,7 @@ Node *PhiNode::Ideal(PhaseGVN *phase, bool can_reshape) { #ifdef _LP64 // Push DecodeN/DecodeNKlass down through phi. // The rest of phi graph will transform by split EncodeP node though phis up. - if ((UseCompressedOops || UseCompressedKlassPointers) && can_reshape && progress == NULL) { + if ((UseCompressedOops || UseCompressedClassPointers) && can_reshape && progress == NULL) { bool may_push = true; bool has_decodeN = false; bool is_decodeN = false; diff --git a/hotspot/src/share/vm/opto/compile.cpp b/hotspot/src/share/vm/opto/compile.cpp index b426bcce1a2..69b6ca05c84 100644 --- a/hotspot/src/share/vm/opto/compile.cpp +++ b/hotspot/src/share/vm/opto/compile.cpp @@ -2631,7 +2631,7 @@ void Compile::final_graph_reshaping_impl( Node *n, Final_Reshape_Counts &frc) { addp->in(AddPNode::Base) == n->in(AddPNode::Base), "Base pointers must match" ); #ifdef _LP64 - if ((UseCompressedOops || UseCompressedKlassPointers) && + if ((UseCompressedOops || UseCompressedClassPointers) && addp->Opcode() == Op_ConP && addp == n->in(AddPNode::Base) && n->in(AddPNode::Offset)->is_Con()) { @@ -3018,7 +3018,7 @@ void Compile::final_graph_reshaping_walk( Node_Stack &nstack, Node *root, Final_ // Skip next transformation if compressed oops are not used. if ((UseCompressedOops && !Matcher::gen_narrow_oop_implicit_null_checks()) || - (!UseCompressedOops && !UseCompressedKlassPointers)) + (!UseCompressedOops && !UseCompressedClassPointers)) return; // Go over safepoints nodes to skip DecodeN/DecodeNKlass nodes for debug edges. diff --git a/hotspot/src/share/vm/opto/connode.cpp b/hotspot/src/share/vm/opto/connode.cpp index eb343a822e5..b59025ad4f3 100644 --- a/hotspot/src/share/vm/opto/connode.cpp +++ b/hotspot/src/share/vm/opto/connode.cpp @@ -630,7 +630,7 @@ const Type *EncodePKlassNode::Value( PhaseTransform *phase ) const { if (t == Type::TOP) return Type::TOP; assert (t != TypePtr::NULL_PTR, "null klass?"); - assert(UseCompressedKlassPointers && t->isa_klassptr(), "only klass ptr here"); + assert(UseCompressedClassPointers && t->isa_klassptr(), "only klass ptr here"); return t->make_narrowklass(); } diff --git a/hotspot/src/share/vm/opto/library_call.cpp b/hotspot/src/share/vm/opto/library_call.cpp index 60525d73ef7..d3f5e18440c 100644 --- a/hotspot/src/share/vm/opto/library_call.cpp +++ b/hotspot/src/share/vm/opto/library_call.cpp @@ -4199,7 +4199,7 @@ void LibraryCallKit::copy_to_clone(Node* obj, Node* alloc_obj, Node* obj_size, b // 12 - 64-bit VM, compressed klass // 16 - 64-bit VM, normal klass if (base_off % BytesPerLong != 0) { - assert(UseCompressedKlassPointers, ""); + assert(UseCompressedClassPointers, ""); if (is_array) { // Exclude length to copy by 8 bytes words. base_off += sizeof(int); diff --git a/hotspot/src/share/vm/opto/live.cpp b/hotspot/src/share/vm/opto/live.cpp index 280d22204c2..70bcd8549c9 100644 --- a/hotspot/src/share/vm/opto/live.cpp +++ b/hotspot/src/share/vm/opto/live.cpp @@ -321,7 +321,7 @@ void PhaseChaitin::verify_base_ptrs( ResourceArea *a ) const { #ifdef _LP64 UseCompressedOops && check->as_Mach()->ideal_Opcode() == Op_CastPP || UseCompressedOops && check->as_Mach()->ideal_Opcode() == Op_DecodeN || - UseCompressedKlassPointers && check->as_Mach()->ideal_Opcode() == Op_DecodeNKlass || + UseCompressedClassPointers && check->as_Mach()->ideal_Opcode() == Op_DecodeNKlass || #endif check->as_Mach()->ideal_Opcode() == Op_LoadP || check->as_Mach()->ideal_Opcode() == Op_LoadKlass)) { diff --git a/hotspot/src/share/vm/opto/macro.cpp b/hotspot/src/share/vm/opto/macro.cpp index 137c529ed0c..06bf9e608c0 100644 --- a/hotspot/src/share/vm/opto/macro.cpp +++ b/hotspot/src/share/vm/opto/macro.cpp @@ -2191,7 +2191,7 @@ void PhaseMacroExpand::expand_lock_node(LockNode *lock) { Node* k_adr = basic_plus_adr(obj, oopDesc::klass_offset_in_bytes()); klass_node = transform_later( LoadKlassNode::make(_igvn, mem, k_adr, _igvn.type(k_adr)->is_ptr()) ); #ifdef _LP64 - if (UseCompressedKlassPointers && klass_node->is_DecodeNKlass()) { + if (UseCompressedClassPointers && klass_node->is_DecodeNKlass()) { assert(klass_node->in(1)->Opcode() == Op_LoadNKlass, "sanity"); klass_node->in(1)->init_req(0, ctrl); } else diff --git a/hotspot/src/share/vm/opto/memnode.cpp b/hotspot/src/share/vm/opto/memnode.cpp index aa03b5ff6c5..01deaf07701 100644 --- a/hotspot/src/share/vm/opto/memnode.cpp +++ b/hotspot/src/share/vm/opto/memnode.cpp @@ -1971,7 +1971,7 @@ Node *LoadKlassNode::make( PhaseGVN& gvn, Node *mem, Node *adr, const TypePtr* a assert(adr_type != NULL, "expecting TypeKlassPtr"); #ifdef _LP64 if (adr_type->is_ptr_to_narrowklass()) { - assert(UseCompressedKlassPointers, "no compressed klasses"); + assert(UseCompressedClassPointers, "no compressed klasses"); Node* load_klass = gvn.transform(new (C) LoadNKlassNode(ctl, mem, adr, at, tk->make_narrowklass())); return new (C) DecodeNKlassNode(load_klass, load_klass->bottom_type()->make_ptr()); } @@ -2309,7 +2309,7 @@ StoreNode* StoreNode::make( PhaseGVN& gvn, Node* ctl, Node* mem, Node* adr, cons val = gvn.transform(new (C) EncodePNode(val, val->bottom_type()->make_narrowoop())); return new (C) StoreNNode(ctl, mem, adr, adr_type, val); } else if (adr->bottom_type()->is_ptr_to_narrowklass() || - (UseCompressedKlassPointers && val->bottom_type()->isa_klassptr() && + (UseCompressedClassPointers && val->bottom_type()->isa_klassptr() && adr->bottom_type()->isa_rawptr())) { val = gvn.transform(new (C) EncodePKlassNode(val, val->bottom_type()->make_narrowklass())); return new (C) StoreNKlassNode(ctl, mem, adr, adr_type, val); diff --git a/hotspot/src/share/vm/opto/type.cpp b/hotspot/src/share/vm/opto/type.cpp index fabcf1cad16..5fa6bfa8815 100644 --- a/hotspot/src/share/vm/opto/type.cpp +++ b/hotspot/src/share/vm/opto/type.cpp @@ -2381,7 +2381,7 @@ TypeOopPtr::TypeOopPtr( TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int #ifdef _LP64 if (_offset != 0) { if (_offset == oopDesc::klass_offset_in_bytes()) { - _is_ptr_to_narrowklass = UseCompressedKlassPointers; + _is_ptr_to_narrowklass = UseCompressedClassPointers; } else if (klass() == NULL) { // Array with unknown body type assert(this->isa_aryptr(), "only arrays without klass"); diff --git a/hotspot/src/share/vm/runtime/arguments.cpp b/hotspot/src/share/vm/runtime/arguments.cpp index d8a6f90eeef..fbce8b6b695 100644 --- a/hotspot/src/share/vm/runtime/arguments.cpp +++ b/hotspot/src/share/vm/runtime/arguments.cpp @@ -1439,7 +1439,7 @@ void Arguments::set_use_compressed_oops() { if (UseCompressedOops && !FLAG_IS_DEFAULT(UseCompressedOops)) { warning("Max heap size too large for Compressed Oops"); FLAG_SET_DEFAULT(UseCompressedOops, false); - FLAG_SET_DEFAULT(UseCompressedKlassPointers, false); + FLAG_SET_DEFAULT(UseCompressedClassPointers, false); } } #endif // _LP64 @@ -1452,22 +1452,22 @@ void Arguments::set_use_compressed_oops() { void Arguments::set_use_compressed_klass_ptrs() { #ifndef ZERO #ifdef _LP64 - // UseCompressedOops must be on for UseCompressedKlassPointers to be on. + // UseCompressedOops must be on for UseCompressedClassPointers to be on. if (!UseCompressedOops) { - if (UseCompressedKlassPointers) { - warning("UseCompressedKlassPointers requires UseCompressedOops"); + if (UseCompressedClassPointers) { + warning("UseCompressedClassPointers requires UseCompressedOops"); } - FLAG_SET_DEFAULT(UseCompressedKlassPointers, false); + FLAG_SET_DEFAULT(UseCompressedClassPointers, false); } else { - // Turn on UseCompressedKlassPointers too - if (FLAG_IS_DEFAULT(UseCompressedKlassPointers)) { - FLAG_SET_ERGO(bool, UseCompressedKlassPointers, true); + // Turn on UseCompressedClassPointers too + if (FLAG_IS_DEFAULT(UseCompressedClassPointers)) { + FLAG_SET_ERGO(bool, UseCompressedClassPointers, true); } - // Check the ClassMetaspaceSize to make sure we use compressed klass ptrs. - if (UseCompressedKlassPointers) { - if (ClassMetaspaceSize > KlassEncodingMetaspaceMax) { - warning("Class metaspace size is too large for UseCompressedKlassPointers"); - FLAG_SET_DEFAULT(UseCompressedKlassPointers, false); + // Check the CompressedClassSpaceSize to make sure we use compressed klass ptrs. + if (UseCompressedClassPointers) { + if (CompressedClassSpaceSize > KlassEncodingMetaspaceMax) { + warning("CompressedClassSpaceSize is too large for UseCompressedClassPointers"); + FLAG_SET_DEFAULT(UseCompressedClassPointers, false); } } } @@ -2148,8 +2148,8 @@ bool Arguments::check_vm_args_consistency() { status = status && verify_object_alignment(); - status = status && verify_interval(ClassMetaspaceSize, 1*M, 3*G, - "ClassMetaspaceSize"); + status = status && verify_interval(CompressedClassSpaceSize, 1*M, 3*G, + "CompressedClassSpaceSize"); status = status && verify_interval(MarkStackSizeMax, 1, (max_jint - 1), "MarkStackSizeMax"); @@ -3274,13 +3274,13 @@ void Arguments::set_shared_spaces_flags() { } UseSharedSpaces = false; #ifdef _LP64 - if (!UseCompressedOops || !UseCompressedKlassPointers) { + if (!UseCompressedOops || !UseCompressedClassPointers) { vm_exit_during_initialization( - "Cannot dump shared archive when UseCompressedOops or UseCompressedKlassPointers is off.", NULL); + "Cannot dump shared archive when UseCompressedOops or UseCompressedClassPointers is off.", NULL); } } else { - // UseCompressedOops and UseCompressedKlassPointers must be on for UseSharedSpaces. - if (!UseCompressedOops || !UseCompressedKlassPointers) { + // UseCompressedOops and UseCompressedClassPointers must be on for UseSharedSpaces. + if (!UseCompressedOops || !UseCompressedClassPointers) { no_shared_spaces(); } #endif @@ -3581,7 +3581,7 @@ jint Arguments::parse(const JavaVMInitArgs* args) { FLAG_SET_DEFAULT(ProfileInterpreter, false); FLAG_SET_DEFAULT(UseBiasedLocking, false); LP64_ONLY(FLAG_SET_DEFAULT(UseCompressedOops, false)); - LP64_ONLY(FLAG_SET_DEFAULT(UseCompressedKlassPointers, false)); + LP64_ONLY(FLAG_SET_DEFAULT(UseCompressedClassPointers, false)); #endif // CC_INTERP #ifdef COMPILER2 @@ -3610,6 +3610,10 @@ jint Arguments::parse(const JavaVMInitArgs* args) { DebugNonSafepoints = true; } + if (FLAG_IS_CMDLINE(CompressedClassSpaceSize) && !UseCompressedClassPointers) { + warning("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used"); + } + #ifndef PRODUCT if (CompileTheWorld) { // Force NmethodSweeper to sweep whole CodeCache each time. diff --git a/hotspot/src/share/vm/runtime/globals.hpp b/hotspot/src/share/vm/runtime/globals.hpp index c9bcbe1f4d3..2633bf21265 100644 --- a/hotspot/src/share/vm/runtime/globals.hpp +++ b/hotspot/src/share/vm/runtime/globals.hpp @@ -443,8 +443,8 @@ class CommandLineFlags { "Use 32-bit object references in 64-bit VM " \ "lp64_product means flag is always constant in 32 bit VM") \ \ - lp64_product(bool, UseCompressedKlassPointers, false, \ - "Use 32-bit klass pointers in 64-bit VM " \ + lp64_product(bool, UseCompressedClassPointers, false, \ + "Use 32-bit class pointers in 64-bit VM " \ "lp64_product means flag is always constant in 32 bit VM") \ \ notproduct(bool, CheckCompressedOops, true, \ @@ -3039,9 +3039,9 @@ class CommandLineFlags { product(uintx, MaxMetaspaceSize, max_uintx, \ "Maximum size of Metaspaces (in bytes)") \ \ - product(uintx, ClassMetaspaceSize, 1*G, \ - "Maximum size of InstanceKlass area in Metaspace used for " \ - "UseCompressedKlassPointers") \ + product(uintx, CompressedClassSpaceSize, 1*G, \ + "Maximum size of class area in Metaspace when compressed " \ + "class pointers are used") \ \ product(uintx, MinHeapFreeRatio, 40, \ "Min percentage of heap free after GC to avoid expansion") \ diff --git a/hotspot/src/share/vm/services/memoryPool.cpp b/hotspot/src/share/vm/services/memoryPool.cpp index 777b8b8f382..7a17f0bd138 100644 --- a/hotspot/src/share/vm/services/memoryPool.cpp +++ b/hotspot/src/share/vm/services/memoryPool.cpp @@ -280,7 +280,7 @@ size_t MetaspacePool::calculate_max_size() const { } CompressedKlassSpacePool::CompressedKlassSpacePool() : - MemoryPool("Compressed Class Space", NonHeap, capacity_in_bytes(), ClassMetaspaceSize, true, false) { } + MemoryPool("Compressed Class Space", NonHeap, capacity_in_bytes(), CompressedClassSpaceSize, true, false) { } size_t CompressedKlassSpacePool::used_in_bytes() { return MetaspaceAux::allocated_used_bytes(Metaspace::ClassType); diff --git a/hotspot/src/share/vm/services/memoryService.cpp b/hotspot/src/share/vm/services/memoryService.cpp index bf0fb9cad24..6508cd2086a 100644 --- a/hotspot/src/share/vm/services/memoryService.cpp +++ b/hotspot/src/share/vm/services/memoryService.cpp @@ -409,7 +409,7 @@ void MemoryService::add_metaspace_memory_pools() { mgr->add_pool(_metaspace_pool); _pools_list->append(_metaspace_pool); - if (UseCompressedKlassPointers) { + if (UseCompressedClassPointers) { _compressed_class_pool = new CompressedKlassSpacePool(); mgr->add_pool(_compressed_class_pool); _pools_list->append(_compressed_class_pool); diff --git a/hotspot/test/gc/arguments/TestCompressedClassFlags.java b/hotspot/test/gc/arguments/TestCompressedClassFlags.java new file mode 100644 index 00000000000..4135debd89c --- /dev/null +++ b/hotspot/test/gc/arguments/TestCompressedClassFlags.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2013, 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 com.oracle.java.testlibrary.*; + +/* + * @test + * @bug 8015107 + * @summary Tests that VM prints a warning when -XX:CompressedClassSpaceSize + * is used together with -XX:-UseCompressedClassPointers + * @library /testlibrary + */ +public class TestCompressedClassFlags { + public static void main(String[] args) throws Exception { + if (Platform.is64bit()) { + OutputAnalyzer output = runJava("-XX:CompressedClassSpaceSize=1g", + "-XX:-UseCompressedClassPointers", + "-version"); + output.shouldContain("warning"); + output.shouldNotContain("error"); + output.shouldHaveExitValue(0); + } + } + + private static OutputAnalyzer runJava(String ... args) throws Exception { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args); + return new OutputAnalyzer(pb.start()); + } +} diff --git a/hotspot/test/gc/metaspace/ClassMetaspaceSizeInJmapHeap.java b/hotspot/test/gc/metaspace/CompressedClassSpaceSizeInJmapHeap.java similarity index 83% rename from hotspot/test/gc/metaspace/ClassMetaspaceSizeInJmapHeap.java rename to hotspot/test/gc/metaspace/CompressedClassSpaceSizeInJmapHeap.java index b3258466a2d..8152a9eb1ca 100644 --- a/hotspot/test/gc/metaspace/ClassMetaspaceSizeInJmapHeap.java +++ b/hotspot/test/gc/metaspace/CompressedClassSpaceSizeInJmapHeap.java @@ -22,11 +22,11 @@ */ /* - * @test ClassMetaspaceSizeInJmapHeap + * @test CompressedClassSpaceSizeInJmapHeap * @bug 8004924 - * @summary Checks that jmap -heap contains the flag ClassMetaspaceSize + * @summary Checks that jmap -heap contains the flag CompressedClassSpaceSize * @library /testlibrary - * @run main/othervm -XX:ClassMetaspaceSize=50m ClassMetaspaceSizeInJmapHeap + * @run main/othervm -XX:CompressedClassSpaceSize=50m CompressedClassSpaceSizeInJmapHeap */ import com.oracle.java.testlibrary.*; @@ -35,7 +35,7 @@ import java.io.File; import java.nio.charset.Charset; import java.util.List; -public class ClassMetaspaceSizeInJmapHeap { +public class CompressedClassSpaceSizeInJmapHeap { public static void main(String[] args) throws Exception { String pid = Integer.toString(ProcessTools.getProcessId()); @@ -44,16 +44,16 @@ public class ClassMetaspaceSizeInJmapHeap { .addToolArg(pid); ProcessBuilder pb = new ProcessBuilder(jmap.getCommand()); - File out = new File("ClassMetaspaceSizeInJmapHeap.stdout.txt"); + File out = new File("CompressedClassSpaceSizeInJmapHeap.stdout.txt"); pb.redirectOutput(out); - File err = new File("ClassMetaspaceSizeInJmapHeap.stderr.txt"); + File err = new File("CompressedClassSpaceSizeInJmapHeap.stderr.txt"); pb.redirectError(err); run(pb); OutputAnalyzer output = new OutputAnalyzer(read(out)); - output.shouldContain("ClassMetaspaceSize = 52428800 (50.0MB)"); + output.shouldContain("CompressedClassSpaceSize = 52428800 (50.0MB)"); out.delete(); } diff --git a/hotspot/test/gc/metaspace/TestMetaspaceMemoryPool.java b/hotspot/test/gc/metaspace/TestMetaspaceMemoryPool.java index 440f91cbd85..105ba240ddf 100644 --- a/hotspot/test/gc/metaspace/TestMetaspaceMemoryPool.java +++ b/hotspot/test/gc/metaspace/TestMetaspaceMemoryPool.java @@ -36,8 +36,8 @@ import java.lang.management.ManagementFactory; * MemoryManagerMXBean is created. * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops TestMetaspaceMemoryPool * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:MaxMetaspaceSize=60m TestMetaspaceMemoryPool - * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedKlassPointers TestMetaspaceMemoryPool - * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedKlassPointers -XX:ClassMetaspaceSize=60m TestMetaspaceMemoryPool + * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedClassPointers TestMetaspaceMemoryPool + * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedClassPointers -XX:CompressedClassSpaceSize=60m TestMetaspaceMemoryPool */ public class TestMetaspaceMemoryPool { public static void main(String[] args) { diff --git a/hotspot/test/gc/metaspace/TestMetaspacePerfCounters.java b/hotspot/test/gc/metaspace/TestMetaspacePerfCounters.java index 26934249a7c..9672d90a5d0 100644 --- a/hotspot/test/gc/metaspace/TestMetaspacePerfCounters.java +++ b/hotspot/test/gc/metaspace/TestMetaspacePerfCounters.java @@ -33,13 +33,13 @@ import static com.oracle.java.testlibrary.Asserts.*; * @summary Tests that performance counters for metaspace and compressed class * space exists and works. * - * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-UseCompressedKlassPointers -XX:+UsePerfData -XX:+UseSerialGC TestMetaspacePerfCounters - * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-UseCompressedKlassPointers -XX:+UsePerfData -XX:+UseParallelGC -XX:+UseParallelOldGC TestMetaspacePerfCounters - * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-UseCompressedKlassPointers -XX:+UsePerfData -XX:+UseG1GC TestMetaspacePerfCounters + * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-UseCompressedClassPointers -XX:+UsePerfData -XX:+UseSerialGC TestMetaspacePerfCounters + * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-UseCompressedClassPointers -XX:+UsePerfData -XX:+UseParallelGC -XX:+UseParallelOldGC TestMetaspacePerfCounters + * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-UseCompressedClassPointers -XX:+UsePerfData -XX:+UseG1GC TestMetaspacePerfCounters * - * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedKlassPointers -XX:+UsePerfData -XX:+UseSerialGC TestMetaspacePerfCounters - * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedKlassPointers -XX:+UsePerfData -XX:+UseParallelGC -XX:+UseParallelOldGC TestMetaspacePerfCounters - * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedKlassPointers -XX:+UsePerfData -XX:+UseG1GC TestMetaspacePerfCounters + * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedClassPointers -XX:+UsePerfData -XX:+UseSerialGC TestMetaspacePerfCounters + * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedClassPointers -XX:+UsePerfData -XX:+UseParallelGC -XX:+UseParallelOldGC TestMetaspacePerfCounters + * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedClassPointers -XX:+UsePerfData -XX:+UseG1GC TestMetaspacePerfCounters */ public class TestMetaspacePerfCounters { public static Class fooClass = null; @@ -99,6 +99,6 @@ public class TestMetaspacePerfCounters { } private static boolean isUsingCompressedClassPointers() { - return Platform.is64bit() && InputArguments.contains("-XX:+UseCompressedKlassPointers"); + return Platform.is64bit() && InputArguments.contains("-XX:+UseCompressedClassPointers"); } } diff --git a/hotspot/test/runtime/CDSCompressedKPtrs/CDSCompressedKPtrs.java b/hotspot/test/runtime/CDSCompressedKPtrs/CDSCompressedKPtrs.java index 4ce2e82c771..c32c05ebd27 100644 --- a/hotspot/test/runtime/CDSCompressedKPtrs/CDSCompressedKPtrs.java +++ b/hotspot/test/runtime/CDSCompressedKPtrs/CDSCompressedKPtrs.java @@ -24,7 +24,7 @@ /* * @test * @bug 8003424 - * @summary Testing UseCompressedKlassPointers with CDS + * @summary Testing UseCompressedClassPointers with CDS * @library /testlibrary * @run main CDSCompressedKPtrs */ @@ -36,7 +36,7 @@ public class CDSCompressedKPtrs { ProcessBuilder pb; if (Platform.is64bit()) { pb = ProcessTools.createJavaProcessBuilder( - "-XX:+UseCompressedKlassPointers", "-XX:+UseCompressedOops", + "-XX:+UseCompressedClassPointers", "-XX:+UseCompressedOops", "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=./sample.jsa", "-Xshare:dump"); OutputAnalyzer output = new OutputAnalyzer(pb.start()); try { @@ -44,7 +44,7 @@ public class CDSCompressedKPtrs { output.shouldHaveExitValue(0); pb = ProcessTools.createJavaProcessBuilder( - "-XX:+UseCompressedKlassPointers", "-XX:+UseCompressedOops", + "-XX:+UseCompressedClassPointers", "-XX:+UseCompressedOops", "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=./sample.jsa", "-Xshare:on", "-version"); output = new OutputAnalyzer(pb.start()); output.shouldContain("sharing"); diff --git a/hotspot/test/runtime/CDSCompressedKPtrs/CDSCompressedKPtrsError.java b/hotspot/test/runtime/CDSCompressedKPtrs/CDSCompressedKPtrsError.java index b2cb84ac988..05b4ac9af28 100644 --- a/hotspot/test/runtime/CDSCompressedKPtrs/CDSCompressedKPtrsError.java +++ b/hotspot/test/runtime/CDSCompressedKPtrs/CDSCompressedKPtrsError.java @@ -24,7 +24,7 @@ /* * @test * @bug 8003424 - * @summary Test that cannot use CDS if UseCompressedKlassPointers is turned off. + * @summary Test that cannot use CDS if UseCompressedClassPointers is turned off. * @library /testlibrary * @run main CDSCompressedKPtrsError */ @@ -36,7 +36,7 @@ public class CDSCompressedKPtrsError { ProcessBuilder pb; if (Platform.is64bit()) { pb = ProcessTools.createJavaProcessBuilder( - "-XX:+UseCompressedOops", "-XX:+UseCompressedKlassPointers", "-XX:+UnlockDiagnosticVMOptions", + "-XX:+UseCompressedOops", "-XX:+UseCompressedClassPointers", "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=./sample.jsa", "-Xshare:dump"); OutputAnalyzer output = new OutputAnalyzer(pb.start()); try { @@ -44,21 +44,21 @@ public class CDSCompressedKPtrsError { output.shouldHaveExitValue(0); pb = ProcessTools.createJavaProcessBuilder( - "-XX:-UseCompressedKlassPointers", "-XX:-UseCompressedOops", + "-XX:-UseCompressedClassPointers", "-XX:-UseCompressedOops", "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=./sample.jsa", "-Xshare:on", "-version"); output = new OutputAnalyzer(pb.start()); output.shouldContain("Unable to use shared archive"); output.shouldHaveExitValue(0); pb = ProcessTools.createJavaProcessBuilder( - "-XX:-UseCompressedKlassPointers", "-XX:+UseCompressedOops", + "-XX:-UseCompressedClassPointers", "-XX:+UseCompressedOops", "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=./sample.jsa", "-Xshare:on", "-version"); output = new OutputAnalyzer(pb.start()); output.shouldContain("Unable to use shared archive"); output.shouldHaveExitValue(0); pb = ProcessTools.createJavaProcessBuilder( - "-XX:+UseCompressedKlassPointers", "-XX:-UseCompressedOops", + "-XX:+UseCompressedClassPointers", "-XX:-UseCompressedOops", "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=./sample.jsa", "-Xshare:on", "-version"); output = new OutputAnalyzer(pb.start()); output.shouldContain("Unable to use shared archive"); @@ -71,19 +71,19 @@ public class CDSCompressedKPtrsError { // Test bad options with -Xshare:dump. pb = ProcessTools.createJavaProcessBuilder( - "-XX:-UseCompressedOops", "-XX:+UseCompressedKlassPointers", "-XX:+UnlockDiagnosticVMOptions", + "-XX:-UseCompressedOops", "-XX:+UseCompressedClassPointers", "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=./sample.jsa", "-Xshare:dump"); output = new OutputAnalyzer(pb.start()); output.shouldContain("Cannot dump shared archive"); pb = ProcessTools.createJavaProcessBuilder( - "-XX:+UseCompressedOops", "-XX:-UseCompressedKlassPointers", "-XX:+UnlockDiagnosticVMOptions", + "-XX:+UseCompressedOops", "-XX:-UseCompressedClassPointers", "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=./sample.jsa", "-Xshare:dump"); output = new OutputAnalyzer(pb.start()); output.shouldContain("Cannot dump shared archive"); pb = ProcessTools.createJavaProcessBuilder( - "-XX:-UseCompressedOops", "-XX:-UseCompressedKlassPointers", "-XX:+UnlockDiagnosticVMOptions", + "-XX:-UseCompressedOops", "-XX:-UseCompressedClassPointers", "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=./sample.jsa", "-Xshare:dump"); output = new OutputAnalyzer(pb.start()); output.shouldContain("Cannot dump shared archive"); diff --git a/hotspot/test/runtime/CompressedOops/CompressedKlassPointerAndOops.java b/hotspot/test/runtime/CompressedOops/CompressedKlassPointerAndOops.java index dd0c26d9f10..228d8cb6a7a 100644 --- a/hotspot/test/runtime/CompressedOops/CompressedKlassPointerAndOops.java +++ b/hotspot/test/runtime/CompressedOops/CompressedKlassPointerAndOops.java @@ -25,7 +25,7 @@ * @test * @bug 8000968 * @key regression - * @summary NPG: UseCompressedKlassPointers asserts with ObjectAlignmentInBytes=32 + * @summary NPG: UseCompressedClassPointers asserts with ObjectAlignmentInBytes=32 * @library /testlibrary */ @@ -52,7 +52,7 @@ public class CompressedKlassPointerAndOops { OutputAnalyzer output; pb = ProcessTools.createJavaProcessBuilder( - "-XX:+UseCompressedKlassPointers", + "-XX:+UseCompressedClassPointers", "-XX:+UseCompressedOops", "-XX:ObjectAlignmentInBytes=" + alignment, "-version"); From 9e84a85d64267b06197c4228e433d4e3335c3f33 Mon Sep 17 00:00:00 2001 From: Vadim Pakhnushev Date: Fri, 23 Aug 2013 14:13:38 +0400 Subject: [PATCH 018/210] 8023052: JVM crash in native layout Reviewed-by: bae, prr --- jdk/src/share/native/sun/font/layout/SunLayoutEngine.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/jdk/src/share/native/sun/font/layout/SunLayoutEngine.cpp b/jdk/src/share/native/sun/font/layout/SunLayoutEngine.cpp index b32f2601b4d..8036a64c4be 100644 --- a/jdk/src/share/native/sun/font/layout/SunLayoutEngine.cpp +++ b/jdk/src/share/native/sun/font/layout/SunLayoutEngine.cpp @@ -179,6 +179,10 @@ JNIEXPORT void JNICALL Java_sun_font_SunLayoutEngine_nativeLayout FontInstanceAdapter fia(env, font2d, strike, mat, 72, 72, (le_int32) upem, (TTLayoutTableCache *) layoutTables); LEErrorCode success = LE_NO_ERROR; LayoutEngine *engine = LayoutEngine::layoutEngineFactory(&fia, script, lang, typo_flags & TYPO_MASK, success); + if (engine == NULL) { + env->SetIntField(gvdata, gvdCountFID, -1); // flag failure + return; + } if (min < 0) min = 0; if (max < min) max = min; /* defensive coding */ // have to copy, yuck, since code does upcalls now. this will be soooo slow From d7bccbe430f48c15086f89ffad1f5e87369de03d Mon Sep 17 00:00:00 2001 From: Jonathan Gibbons Date: Thu, 29 Aug 2013 19:19:23 -0700 Subject: [PATCH 019/210] 8023833: Replace direct use of AnnotatedType in javadoc code Reviewed-by: darcy --- .../classes/com/sun/tools/javadoc/AnnotatedTypeImpl.java | 6 +++--- .../share/classes/com/sun/tools/javadoc/TypeMaker.java | 9 +++------ .../classes/com/sun/tools/javadoc/TypeVariableImpl.java | 2 +- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/langtools/src/share/classes/com/sun/tools/javadoc/AnnotatedTypeImpl.java b/langtools/src/share/classes/com/sun/tools/javadoc/AnnotatedTypeImpl.java index a49dc8a3134..eb49e10f79a 100644 --- a/langtools/src/share/classes/com/sun/tools/javadoc/AnnotatedTypeImpl.java +++ b/langtools/src/share/classes/com/sun/tools/javadoc/AnnotatedTypeImpl.java @@ -40,7 +40,7 @@ import com.sun.tools.javac.util.List; public class AnnotatedTypeImpl extends AbstractTypeImpl implements AnnotatedType { - AnnotatedTypeImpl(DocEnv env, com.sun.tools.javac.code.Type.AnnotatedType type) { + AnnotatedTypeImpl(DocEnv env, com.sun.tools.javac.code.Type type) { super(env, type); } @@ -50,7 +50,7 @@ public class AnnotatedTypeImpl */ @Override public AnnotationDesc[] annotations() { - List tas = ((com.sun.tools.javac.code.Type.AnnotatedType)type).typeAnnotations; + List tas = type.getAnnotationMirrors(); if (tas == null || tas.isEmpty()) { return new AnnotationDesc[0]; @@ -65,7 +65,7 @@ public class AnnotatedTypeImpl @Override public com.sun.javadoc.Type underlyingType() { - return TypeMaker.getType(env, ((com.sun.tools.javac.code.Type.AnnotatedType)type).underlyingType, true, false); + return TypeMaker.getType(env, type.unannotatedType(), true, false); } @Override diff --git a/langtools/src/share/classes/com/sun/tools/javadoc/TypeMaker.java b/langtools/src/share/classes/com/sun/tools/javadoc/TypeMaker.java index 721d33b7b4c..de4d54a651d 100644 --- a/langtools/src/share/classes/com/sun/tools/javadoc/TypeMaker.java +++ b/langtools/src/share/classes/com/sun/tools/javadoc/TypeMaker.java @@ -63,10 +63,8 @@ public class TypeMaker { t = env.types.erasure(t); } - if (considerAnnotations && - t.isAnnotated()) { - Type.AnnotatedType at = (Type.AnnotatedType) t; - return new AnnotatedTypeImpl(env, at); + if (considerAnnotations && t.isAnnotated()) { + return new AnnotatedTypeImpl(env, t); } switch (t.getTag()) { @@ -143,8 +141,7 @@ public class TypeMaker { static String getTypeString(DocEnv env, Type t, boolean full) { // TODO: should annotations be included here? if (t.isAnnotated()) { - Type.AnnotatedType at = (Type.AnnotatedType)t; - t = at.underlyingType; + t = t.unannotatedType(); } switch (t.getTag()) { case ARRAY: diff --git a/langtools/src/share/classes/com/sun/tools/javadoc/TypeVariableImpl.java b/langtools/src/share/classes/com/sun/tools/javadoc/TypeVariableImpl.java index 3840c916ee4..48f97088ebc 100644 --- a/langtools/src/share/classes/com/sun/tools/javadoc/TypeVariableImpl.java +++ b/langtools/src/share/classes/com/sun/tools/javadoc/TypeVariableImpl.java @@ -140,7 +140,7 @@ public class TypeVariableImpl extends AbstractTypeImpl implements TypeVariable { if (!type.isAnnotated()) { return new AnnotationDesc[0]; } - List tas = ((com.sun.tools.javac.code.Type.AnnotatedType) type).typeAnnotations; + List tas = type.getAnnotationMirrors(); AnnotationDesc res[] = new AnnotationDesc[tas.length()]; int i = 0; for (Attribute.Compound a : tas) { From 9811410a0015461d29ec294c6542a69a62a72744 Mon Sep 17 00:00:00 2001 From: Jennifer Godinez Date: Fri, 30 Aug 2013 09:10:30 -0700 Subject: [PATCH 020/210] 8017469: [macosx] Printing problem using ja and zh_CN locales Reviewed-by: prr, jchen --- jdk/src/macosx/native/sun/awt/CTextPipe.m | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/jdk/src/macosx/native/sun/awt/CTextPipe.m b/jdk/src/macosx/native/sun/awt/CTextPipe.m index d9bf48afd92..f6510f204ae 100644 --- a/jdk/src/macosx/native/sun/awt/CTextPipe.m +++ b/jdk/src/macosx/native/sun/awt/CTextPipe.m @@ -145,11 +145,6 @@ void JavaCT_DrawGlyphVector BOOL saved = false; - /* Save and restore of graphics context is done before the iteration. - This seems to work using our test case (see bug ID 7158350) so we are restoring it at - the end of the for loop. If we find out that save/restore outside the loop - doesn't work on all cases then we will move the Save/Restore inside the loop.*/ - CGContextSaveGState(cgRef); CGAffineTransform invTx = CGAffineTransformInvert(strike->fTx); NSUInteger i; @@ -226,7 +221,9 @@ void JavaCT_DrawGlyphVector } // reset the font on the context after striking a unicode with CoreText - CGContextRestoreGState(cgRef); + if (saved) { + CGContextRestoreGState(cgRef); + } } // Using the Quartz Surface Data context, draw a hot-substituted character run From d5c4be9c658afddd0e33458cd4498fbcb65dcb98 Mon Sep 17 00:00:00 2001 From: Phil Race Date: Fri, 30 Aug 2013 10:25:55 -0700 Subject: [PATCH 021/210] 4673406: RFE: Java Printing: Provide a way to display win32 printer driver's dialog Reviewed-by: jgodinez, bae --- .../sun/print/DocumentPropertiesUI.java | 62 ++++ .../classes/sun/print/PrinterJobWrapper.java | 60 ++++ .../classes/sun/print/RasterPrinterJob.java | 4 + .../classes/sun/print/ServiceDialog.java | 32 +- .../classes/sun/awt/windows/WPrinterJob.java | 315 +++++++++++++++++- .../classes/sun/print/Win32MediaTray.java | 4 + .../classes/sun/print/Win32PrintService.java | 93 +++++- .../native/sun/windows/awt_PrintControl.cpp | 6 + .../native/sun/windows/awt_PrintControl.h | 2 +- .../native/sun/windows/awt_PrintJob.cpp | 167 +++++++++- 10 files changed, 721 insertions(+), 24 deletions(-) create mode 100644 jdk/src/share/classes/sun/print/DocumentPropertiesUI.java create mode 100644 jdk/src/share/classes/sun/print/PrinterJobWrapper.java diff --git a/jdk/src/share/classes/sun/print/DocumentPropertiesUI.java b/jdk/src/share/classes/sun/print/DocumentPropertiesUI.java new file mode 100644 index 00000000000..9938e8b3951 --- /dev/null +++ b/jdk/src/share/classes/sun/print/DocumentPropertiesUI.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2013, 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.print; + +import java.awt.Window; +import java.awt.print.PrinterJob; +import javax.print.PrintService; +import javax.print.ServiceUIFactory; +import javax.print.attribute.PrintRequestAttributeSet; + +public abstract class DocumentPropertiesUI { + + /** + * For Win32 doc properties sheet. + */ + public static final int + DOCUMENTPROPERTIES_ROLE = ServiceUIFactory.RESERVED_UIROLE +100; + + /** + * Name of (this) abstract class for Document Properties. + */ + public static final String + DOCPROPERTIESCLASSNAME = DocumentPropertiesUI.class.getName(); + + /** + * Invokes whatever code is needed to display a native dialog + * with the specified owner. The owner should be the cross-platform + * dialog. If the user cancels the dialog the return value is null. + * A non-null return value is always a new attribute set (or is it?) + * The cross-platform dialog may need to be updated to reflect the + * updated properties. + */ + public abstract PrintRequestAttributeSet + showDocumentProperties(PrinterJob job, + Window owner, + PrintService service, + PrintRequestAttributeSet aset); + +} diff --git a/jdk/src/share/classes/sun/print/PrinterJobWrapper.java b/jdk/src/share/classes/sun/print/PrinterJobWrapper.java new file mode 100644 index 00000000000..343da0baa77 --- /dev/null +++ b/jdk/src/share/classes/sun/print/PrinterJobWrapper.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2013, 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.print; + +import java.awt.print.PrinterJob; +import javax.print.attribute.PrintRequestAttribute; + +public class PrinterJobWrapper implements PrintRequestAttribute { + + private static final long serialVersionUID = -8792124426995707237L; + + private PrinterJob job; + + public PrinterJobWrapper(PrinterJob job) { + this.job = job; + } + + public PrinterJob getPrinterJob() { + return job; + } + + public final Class getCategory() { + return PrinterJobWrapper.class; + } + + public final String getName() { + return "printerjob-wrapper"; + } + + public String toString() { + return "printerjob-wrapper: " + job.toString(); + } + + public int hashCode() { + return job.hashCode(); + } +} diff --git a/jdk/src/share/classes/sun/print/RasterPrinterJob.java b/jdk/src/share/classes/sun/print/RasterPrinterJob.java index 1752016288e..37865e3246c 100644 --- a/jdk/src/share/classes/sun/print/RasterPrinterJob.java +++ b/jdk/src/share/classes/sun/print/RasterPrinterJob.java @@ -903,6 +903,9 @@ public abstract class RasterPrinterJob extends PrinterJob { int x = bounds.x+bounds.width/3; int y = bounds.y+bounds.height/3; PrintService newService; + // temporarily add an attribute pointing back to this job. + PrinterJobWrapper jobWrapper = new PrinterJobWrapper(this); + attributes.add(jobWrapper); try { newService = ServiceUI.printDialog(gc, x, y, @@ -915,6 +918,7 @@ public abstract class RasterPrinterJob extends PrinterJob { DocFlavor.SERVICE_FORMATTED.PAGEABLE, attributes); } + attributes.remove(PrinterJobWrapper.class); if (newService == null) { return false; diff --git a/jdk/src/share/classes/sun/print/ServiceDialog.java b/jdk/src/share/classes/sun/print/ServiceDialog.java index 82703406aa9..bdfd5ba1242 100644 --- a/jdk/src/share/classes/sun/print/ServiceDialog.java +++ b/jdk/src/share/classes/sun/print/ServiceDialog.java @@ -46,6 +46,7 @@ import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.awt.event.WindowEvent; import java.awt.event.WindowAdapter; +import java.awt.print.PrinterJob; import java.io.File; import java.io.FilePermission; import java.io.IOException; @@ -119,8 +120,6 @@ public class ServiceDialog extends JDialog implements ActionListener { private AppearancePanel pnlAppearance; private boolean isAWT = false; - - static { initResource(); } @@ -801,9 +800,32 @@ public class ServiceDialog extends JDialog implements ActionListener { if (dialog != null) { dialog.show(); } else { - // REMIND: may want to notify the user why we're - // disabling the button - btnProperties.setEnabled(false); + DocumentPropertiesUI docPropertiesUI = null; + try { + docPropertiesUI = + (DocumentPropertiesUI)uiFactory.getUI + (DocumentPropertiesUI.DOCUMENTPROPERTIES_ROLE, + DocumentPropertiesUI.DOCPROPERTIESCLASSNAME); + } catch (Exception ex) { + } + if (docPropertiesUI != null) { + PrinterJobWrapper wrapper = (PrinterJobWrapper) + asCurrent.get(PrinterJobWrapper.class); + if (wrapper == null) { + return; // should not happen, defensive only. + } + PrinterJob job = wrapper.getPrinterJob(); + if (job == null) { + return; // should not happen, defensive only. + } + PrintRequestAttributeSet newAttrs = + docPropertiesUI.showDocumentProperties + (job, ServiceDialog.this, psCurrent, asCurrent); + if (newAttrs != null) { + asCurrent.addAll(newAttrs); + updatePanels(); + } + } } } } diff --git a/jdk/src/windows/classes/sun/awt/windows/WPrinterJob.java b/jdk/src/windows/classes/sun/awt/windows/WPrinterJob.java index 897e8f1baf1..519a0be422e 100644 --- a/jdk/src/windows/classes/sun/awt/windows/WPrinterJob.java +++ b/jdk/src/windows/classes/sun/awt/windows/WPrinterJob.java @@ -179,6 +179,7 @@ public class WPrinterJob extends RasterPrinterJob implements DisposerTarget { private static final int SET_RES_LOW = 0x00000080; private static final int SET_COLOR = 0x00000200; private static final int SET_ORIENTATION = 0x00004000; + private static final int SET_COLLATED = 0x00008000; /** * Values must match those defined in wingdi.h & commdlg.h @@ -189,10 +190,33 @@ public class WPrinterJob extends RasterPrinterJob implements DisposerTarget { private static final int PD_NOSELECTION = 0x00000004; private static final int PD_COLLATE = 0x00000010; private static final int PD_PRINTTOFILE = 0x00000020; - private static final int DM_ORIENTATION = 0x00000001; - private static final int DM_PRINTQUALITY = 0x00000400; - private static final int DM_COLOR = 0x00000800; - private static final int DM_DUPLEX = 0x00001000; + private static final int DM_ORIENTATION = 0x00000001; + private static final int DM_PAPERSIZE = 0x00000002; + private static final int DM_COPIES = 0x00000100; + private static final int DM_DEFAULTSOURCE = 0x00000200; + private static final int DM_PRINTQUALITY = 0x00000400; + private static final int DM_COLOR = 0x00000800; + private static final int DM_DUPLEX = 0x00001000; + private static final int DM_YRESOLUTION = 0x00002000; + private static final int DM_COLLATE = 0x00008000; + + private static final short DMCOLLATE_FALSE = 0; + private static final short DMCOLLATE_TRUE = 1; + + private static final short DMORIENT_PORTRAIT = 1; + private static final short DMORIENT_LANDSCAPE = 2; + + private static final short DMCOLOR_MONOCHROME = 1; + private static final short DMCOLOR_COLOR = 2; + + private static final short DMRES_DRAFT = -1; + private static final short DMRES_LOW = -2; + private static final short DMRES_MEDIUM = -3; + private static final short DMRES_HIGH = -4; + + private static final short DMDUP_SIMPLEX = 1; + private static final short DMDUP_VERTICAL = 2; + private static final short DMDUP_HORIZONTAL = 3; /** * Pageable MAX pages @@ -592,13 +616,23 @@ public class WPrinterJob extends RasterPrinterJob implements DisposerTarget { } driverDoesMultipleCopies = false; driverDoesCollation = false; - setNativePrintService(service.getName()); + setNativePrintServiceIfNeeded(service.getName()); } /* associates this job with the specified native service */ private native void setNativePrintService(String name) throws PrinterException; + private String lastNativeService = null; + private void setNativePrintServiceIfNeeded(String name) + throws PrinterException { + + if (name != null && !(name.equals(lastNativeService))) { + setNativePrintService(name); + lastNativeService = name; + } + } + public PrintService getPrintService() { if (myService == null) { String printerName = getNativePrintService(); @@ -616,7 +650,7 @@ public class WPrinterJob extends RasterPrinterJob implements DisposerTarget { myService = PrintServiceLookup.lookupDefaultPrintService(); if (myService != null) { try { - setNativePrintService(myService.getName()); + setNativePrintServiceIfNeeded(myService.getName()); } catch (Exception e) { myService = null; } @@ -1754,8 +1788,13 @@ public class WPrinterJob extends RasterPrinterJob implements DisposerTarget { mAttMediaSizeName = ((Win32PrintService)myService).findPaperID(msn); } - private void setWin32MediaAttrib(int dmIndex, int width, int length) { - MediaSizeName msn = + private void addPaperSize(PrintRequestAttributeSet aset, + int dmIndex, int width, int length) { + + if (aset == null) { + return; + } + MediaSizeName msn = ((Win32PrintService)myService).findWin32Media(dmIndex); if (msn == null) { msn = ((Win32PrintService)myService). @@ -1763,10 +1802,12 @@ public class WPrinterJob extends RasterPrinterJob implements DisposerTarget { } if (msn != null) { - if (attributes != null) { - attributes.add(msn); - } + aset.add(msn); } + } + + private void setWin32MediaAttrib(int dmIndex, int width, int length) { + addPaperSize(attributes, dmIndex, width, length); mAttMediaSizeName = dmIndex; } @@ -1788,7 +1829,7 @@ public class WPrinterJob extends RasterPrinterJob implements DisposerTarget { // no equivalent predefined value mAttMediaTray = 7; // DMBIN_AUTO } else if (attr == MediaTray.TOP) { - mAttMediaTray =1; // DMBIN_UPPER + mAttMediaTray = 1; // DMBIN_UPPER } else { if (attr instanceof Win32MediaTray) { mAttMediaTray = ((Win32MediaTray)attr).winID; @@ -1914,6 +1955,254 @@ public class WPrinterJob extends RasterPrinterJob implements DisposerTarget { } } + private static final class DevModeValues { + int dmFields; + short copies; + short collate; + short color; + short duplex; + short orient; + short paper; + short bin; + short xres_quality; + short yres; + } + + private void getDevModeValues(PrintRequestAttributeSet aset, + DevModeValues info) { + + Copies c = (Copies)aset.get(Copies.class); + if (c != null) { + info.dmFields |= DM_COPIES; + info.copies = (short)c.getValue(); + } + + SheetCollate sc = (SheetCollate)aset.get(SheetCollate.class); + if (sc != null) { + info.dmFields |= DM_COLLATE; + info.collate = (sc == SheetCollate.COLLATED) ? + DMCOLLATE_TRUE : DMCOLLATE_FALSE; + } + + Chromaticity ch = (Chromaticity)aset.get(Chromaticity.class); + if (ch != null) { + info.dmFields |= DM_COLOR; + if (ch == Chromaticity.COLOR) { + info.color = DMCOLOR_COLOR; + } else { + info.color = DMCOLOR_MONOCHROME; + } + } + + Sides s = (Sides)aset.get(Sides.class); + if (s != null) { + info.dmFields |= DM_DUPLEX; + if (s == Sides.TWO_SIDED_LONG_EDGE) { + info.duplex = DMDUP_VERTICAL; + } else if (s == Sides.TWO_SIDED_SHORT_EDGE) { + info.duplex = DMDUP_HORIZONTAL; + } else { // Sides.ONE_SIDED + info.duplex = DMDUP_SIMPLEX; + } + } + + OrientationRequested or = + (OrientationRequested)aset.get(OrientationRequested.class); + if (or != null) { + info.dmFields |= DM_ORIENTATION; + info.orient = (or == OrientationRequested.LANDSCAPE) + ? DMORIENT_LANDSCAPE : DMORIENT_PORTRAIT; + } + + Media m = (Media)aset.get(Media.class); + if (m instanceof MediaSizeName) { + info.dmFields |= DM_PAPERSIZE; + MediaSizeName msn = (MediaSizeName)m; + info.paper = + (short)((Win32PrintService)myService).findPaperID(msn); + } + + MediaTray mt = null; + if (m instanceof MediaTray) { + mt = (MediaTray)m; + } + if (mt == null) { + SunAlternateMedia sam = + (SunAlternateMedia)aset.get(SunAlternateMedia.class); + if (sam != null && (sam.getMedia() instanceof MediaTray)) { + mt = (MediaTray)sam.getMedia(); + } + } + + if (mt != null) { + info.dmFields |= DM_DEFAULTSOURCE; + info.bin = (short)(((Win32PrintService)myService).findTrayID(mt)); + } + + PrintQuality q = (PrintQuality)aset.get(PrintQuality.class); + if (q != null) { + info.dmFields |= DM_PRINTQUALITY; + if (q == PrintQuality.DRAFT) { + info.xres_quality = DMRES_DRAFT; + } else if (q == PrintQuality.HIGH) { + info.xres_quality = DMRES_HIGH; + } else { + info.xres_quality = DMRES_MEDIUM; + } + } + + PrinterResolution r = + (PrinterResolution)aset.get(PrinterResolution.class); + if (r != null) { + info.dmFields |= DM_PRINTQUALITY | DM_YRESOLUTION; + info.xres_quality = + (short)r.getCrossFeedResolution(PrinterResolution.DPI); + info.yres = (short)r.getFeedResolution(PrinterResolution.DPI); + } + } + + /* This method is called from native to update the values in the + * attribute set which originates from the cross-platform dialog, + * but updated by the native DocumentPropertiesUI which updates the + * devmode. This syncs the devmode back in to the attributes so that + * we can update the cross-platform dialog. + * The attribute set here is a temporary one installed whilst this + * happens, + */ + private final void setJobAttributes(PrintRequestAttributeSet attributes, + int fields, int values, + short copies, + short dmPaperSize, + short dmPaperWidth, + short dmPaperLength, + short dmDefaultSource, + short xRes, + short yRes) { + + if (attributes == null) { + return; + } + + if ((fields & DM_COPIES) != 0) { + attributes.add(new Copies(copies)); + } + + if ((fields & DM_COLLATE) != 0) { + if ((values & SET_COLLATED) != 0) { + attributes.add(SheetCollate.COLLATED); + } else { + attributes.add(SheetCollate.UNCOLLATED); + } + } + + if ((fields & DM_ORIENTATION) != 0) { + if ((values & SET_ORIENTATION) != 0) { + attributes.add(OrientationRequested.LANDSCAPE); + } else { + attributes.add(OrientationRequested.PORTRAIT); + } + } + + if ((fields & DM_COLOR) != 0) { + if ((values & SET_COLOR) != 0) { + attributes.add(Chromaticity.COLOR); + } else { + attributes.add(Chromaticity.MONOCHROME); + } + } + + if ((fields & DM_PRINTQUALITY) != 0) { + /* value < 0 indicates quality setting. + * value > 0 indicates X resolution. In that case + * hopefully we will also find y-resolution specified. + * If its not, assume its the same as x-res. + * Maybe Java code should try to reconcile this against + * the printers claimed set of supported resolutions. + */ + if (xRes < 0) { + PrintQuality quality; + if ((values & SET_RES_LOW) != 0) { + quality = PrintQuality.DRAFT; + } else if ((fields & SET_RES_HIGH) != 0) { + quality = PrintQuality.HIGH; + } else { + quality = PrintQuality.NORMAL; + } + attributes.add(quality); + } else if (xRes > 0 && yRes > 0) { + attributes.add( + new PrinterResolution(xRes, yRes, PrinterResolution.DPI)); + } + } + + if ((fields & DM_DUPLEX) != 0) { + Sides sides; + if ((values & SET_DUP_VERTICAL) != 0) { + sides = Sides.TWO_SIDED_LONG_EDGE; + } else if ((values & SET_DUP_HORIZONTAL) != 0) { + sides = Sides.TWO_SIDED_SHORT_EDGE; + } else { + sides = Sides.ONE_SIDED; + } + attributes.add(sides); + } + + if ((fields & DM_PAPERSIZE) != 0) { + addPaperSize(attributes, dmPaperSize, dmPaperWidth, dmPaperLength); + } + + if ((fields & DM_DEFAULTSOURCE) != 0) { + MediaTray tray = + ((Win32PrintService)myService).findMediaTray(dmDefaultSource); + attributes.add(new SunAlternateMedia(tray)); + } + } + + private native boolean showDocProperties(long hWnd, + PrintRequestAttributeSet aset, + int dmFields, + short copies, + short collate, + short color, + short duplex, + short orient, + short paper, + short bin, + short xres_quality, + short yres); + + @SuppressWarnings("deprecation") + public PrintRequestAttributeSet + showDocumentProperties(Window owner, + PrintService service, + PrintRequestAttributeSet aset) + { + try { + setNativePrintServiceIfNeeded(service.getName()); + } catch (PrinterException e) { + } + long hWnd = ((WWindowPeer)(owner.getPeer())).getHWnd(); + DevModeValues info = new DevModeValues(); + getDevModeValues(aset, info); + boolean ok = + showDocProperties(hWnd, aset, + info.dmFields, + info.copies, + info.collate, + info.color, + info.duplex, + info.orient, + info.paper, + info.bin, + info.xres_quality, + info.yres); + + if (ok) { + return aset; + } else { + return null; + } + } /* Printer Resolution. See also getXRes() and getYRes() */ private final void setResolutionDPI(int xres, int yres) { @@ -1956,7 +2245,7 @@ public class WPrinterJob extends RasterPrinterJob implements DisposerTarget { } //** END Functions called by native code for querying/updating attributes - } + } class PrintToFileErrorDialog extends Dialog implements ActionListener{ public PrintToFileErrorDialog(Frame parent, String title, String message, diff --git a/jdk/src/windows/classes/sun/print/Win32MediaTray.java b/jdk/src/windows/classes/sun/print/Win32MediaTray.java index ecafcef5668..2f2cafce035 100644 --- a/jdk/src/windows/classes/sun/print/Win32MediaTray.java +++ b/jdk/src/windows/classes/sun/print/Win32MediaTray.java @@ -70,6 +70,10 @@ public class Win32MediaTray extends MediaTray { winEnumTable.add(this); } + public int getDMBinID() { + return winID; + } + private static final String[] myStringTable ={ "Manual-Envelope", "Automatic-Feeder", diff --git a/jdk/src/windows/classes/sun/print/Win32PrintService.java b/jdk/src/windows/classes/sun/print/Win32PrintService.java index c42de1ae7df..73e89269285 100644 --- a/jdk/src/windows/classes/sun/print/Win32PrintService.java +++ b/jdk/src/windows/classes/sun/print/Win32PrintService.java @@ -25,6 +25,8 @@ package sun.print; +import java.awt.Window; +import java.awt.print.PrinterJob; import java.io.File; import java.net.URI; import java.net.URISyntaxException; @@ -39,6 +41,7 @@ import javax.print.attribute.AttributeSet; import javax.print.attribute.AttributeSetUtilities; import javax.print.attribute.EnumSyntax; import javax.print.attribute.HashAttributeSet; +import javax.print.attribute.PrintRequestAttributeSet; import javax.print.attribute.PrintServiceAttribute; import javax.print.attribute.PrintServiceAttributeSet; import javax.print.attribute.HashPrintServiceAttributeSet; @@ -69,6 +72,7 @@ import javax.print.attribute.standard.PrintQuality; import javax.print.attribute.standard.PrinterResolution; import javax.print.attribute.standard.SheetCollate; import javax.print.event.PrintServiceAttributeListener; +import sun.awt.windows.WPrinterJob; public class Win32PrintService implements PrintService, AttributeUpdater, SunPrinterJobService { @@ -282,6 +286,22 @@ public class Win32PrintService implements PrintService, AttributeUpdater, return 0; } + public int findTrayID(MediaTray tray) { + + getMediaTrays(); // make sure they are initialised. + + if (tray instanceof Win32MediaTray) { + Win32MediaTray winTray = (Win32MediaTray)tray; + return winTray.getDMBinID(); + } + for (int id=0; id= 1 && dmBin <= dmPaperBinToPrintService.length) { return dmPaperBinToPrintService[dmBin-1]; @@ -673,7 +693,6 @@ public class Win32PrintService implements PrintService, AttributeUpdater, return arr2; } - private PrinterIsAcceptingJobs getPrinterIsAcceptingJobs() { if (getJobStatus(printer, 2) != 1) { return PrinterIsAcceptingJobs.NOT_ACCEPTING_JOBS; @@ -1596,8 +1615,76 @@ public class Win32PrintService implements PrintService, AttributeUpdater, } } - public ServiceUIFactory getServiceUIFactory() { - return null; + private Win32DocumentPropertiesUI docPropertiesUI = null; + + private static class Win32DocumentPropertiesUI + extends DocumentPropertiesUI { + + Win32PrintService service; + + private Win32DocumentPropertiesUI(Win32PrintService s) { + service = s; + } + + public PrintRequestAttributeSet + showDocumentProperties(PrinterJob job, + Window owner, + PrintService service, + PrintRequestAttributeSet aset) { + + if (!(job instanceof WPrinterJob)) { + return null; + } + WPrinterJob wJob = (WPrinterJob)job; + return wJob.showDocumentProperties(owner, service, aset); + } + } + + private synchronized DocumentPropertiesUI getDocumentPropertiesUI() { + return new Win32DocumentPropertiesUI(this); + } + + private static class Win32ServiceUIFactory extends ServiceUIFactory { + + Win32PrintService service; + + Win32ServiceUIFactory(Win32PrintService s) { + service = s; + } + + public Object getUI(int role, String ui) { + if (role <= ServiceUIFactory.MAIN_UIROLE) { + return null; + } + if (role == DocumentPropertiesUI.DOCUMENTPROPERTIES_ROLE && + DocumentPropertiesUI.DOCPROPERTIESCLASSNAME.equals(ui)) + { + return service.getDocumentPropertiesUI(); + } + throw new IllegalArgumentException("Unsupported role"); + } + + public String[] getUIClassNamesForRole(int role) { + + if (role <= ServiceUIFactory.MAIN_UIROLE) { + return null; + } + if (role == DocumentPropertiesUI.DOCUMENTPROPERTIES_ROLE) { + String[] names = new String[0]; + names[0] = DocumentPropertiesUI.DOCPROPERTIESCLASSNAME; + return names; + } + throw new IllegalArgumentException("Unsupported role"); + } + } + + private Win32ServiceUIFactory uiFactory = null; + + public synchronized ServiceUIFactory getServiceUIFactory() { + if (uiFactory == null) { + uiFactory = new Win32ServiceUIFactory(this); + } + return uiFactory; } public String toString() { diff --git a/jdk/src/windows/native/sun/windows/awt_PrintControl.cpp b/jdk/src/windows/native/sun/windows/awt_PrintControl.cpp index 71a08d3df33..07dd90fcf2c 100644 --- a/jdk/src/windows/native/sun/windows/awt_PrintControl.cpp +++ b/jdk/src/windows/native/sun/windows/awt_PrintControl.cpp @@ -81,6 +81,7 @@ jmethodID AwtPrintControl::setToPageID; jmethodID AwtPrintControl::setNativeAttID; jmethodID AwtPrintControl::setRangeCopiesID; jmethodID AwtPrintControl::setResID; +jmethodID AwtPrintControl::setJobAttributesID; BOOL AwtPrintControl::IsSupportedLevel(HANDLE hPrinter, DWORD dwLevel) { @@ -297,6 +298,10 @@ void AwtPrintControl::initIDs(JNIEnv *env, jclass cls) AwtPrintControl::setPrinterID = env->GetMethodID(cls, "setPrinterNameAttrib", "(Ljava/lang/String;)V"); + AwtPrintControl::setJobAttributesID = + env->GetMethodID(cls, "setJobAttributes", + "(Ljavax/print/attribute/PrintRequestAttributeSet;IISSSSSSS)V"); + DASSERT(AwtPrintControl::driverDoesMultipleCopiesID != NULL); DASSERT(AwtPrintControl::getPrintDCID != NULL); DASSERT(AwtPrintControl::setPrintDCID != NULL); @@ -327,6 +332,7 @@ void AwtPrintControl::initIDs(JNIEnv *env, jclass cls) DASSERT(AwtPrintControl::getSidesID != NULL); DASSERT(AwtPrintControl::getSelectID != NULL); DASSERT(AwtPrintControl::getPrintToFileEnabledID != NULL); + DASSERT(AwtPrintControl::setJobAttributesID != NULL); CATCH_BAD_ALLOC; diff --git a/jdk/src/windows/native/sun/windows/awt_PrintControl.h b/jdk/src/windows/native/sun/windows/awt_PrintControl.h index 2e3fbaf2e60..e8b7415f305 100644 --- a/jdk/src/windows/native/sun/windows/awt_PrintControl.h +++ b/jdk/src/windows/native/sun/windows/awt_PrintControl.h @@ -47,7 +47,6 @@ public: static jmethodID setDevmodeID; static jmethodID getDevnamesID; static jmethodID setDevnamesID; - static jmethodID getWin32MediaID; static jmethodID setWin32MediaID; static jmethodID getWin32MediaTrayID; @@ -73,6 +72,7 @@ public: static jmethodID setNativeAttID; static jmethodID setRangeCopiesID; static jmethodID setResID; + static jmethodID setJobAttributesID; static void initIDs(JNIEnv *env, jclass cls); static BOOL FindPrinter(jstring printerName, LPBYTE pPrinterEnum, diff --git a/jdk/src/windows/native/sun/windows/awt_PrintJob.cpp b/jdk/src/windows/native/sun/windows/awt_PrintJob.cpp index a2deb14b58c..c19e4306114 100644 --- a/jdk/src/windows/native/sun/windows/awt_PrintJob.cpp +++ b/jdk/src/windows/native/sun/windows/awt_PrintJob.cpp @@ -329,6 +329,156 @@ static int CALLBACK fontEnumProcA(ENUMLOGFONTEXA *logfont, static int embolden(int currentWeight); static BOOL getPrintableArea(HDC pdc, HANDLE hDevMode, RectDouble *margin); + + +/************************************************************************ + * DocumentProperties native support + */ + +/* Values must match those defined in WPrinterJob.java */ +static const DWORD SET_COLOR = 0x00000200; +static const DWORD SET_ORIENTATION = 0x00004000; +static const DWORD SET_COLLATED = 0x00008000; +static const DWORD SET_DUP_VERTICAL = 0x00000010; +static const DWORD SET_DUP_HORIZONTAL = 0x00000020; +static const DWORD SET_RES_HIGH = 0x00000040; +static const DWORD SET_RES_LOW = 0x00000080; + +/* + * Copy DEVMODE state back into JobAttributes. + */ + +static void UpdateJobAttributes(JNIEnv *env, + jobject wJob, + jobject attrSet, + DEVMODE *devmode) { + + DWORD dmValues = 0; + int xRes = 0, yRes = 0; + + if (devmode->dmFields & DM_COLOR) { + if (devmode->dmColor == DMCOLOR_COLOR) { + dmValues |= SET_COLOR; + } + } + + if (devmode->dmFields & DM_ORIENTATION) { + if (devmode->dmOrientation == DMORIENT_LANDSCAPE) { + dmValues |= SET_ORIENTATION; + } + } + + if (devmode->dmFields & DM_COLLATE && + devmode->dmCollate == DMCOLLATE_TRUE) { + dmValues |= SET_COLLATED; + } + + if (devmode->dmFields & DM_PRINTQUALITY) { + /* value < 0 indicates quality setting. + * value > 0 indicates X resolution. In that case + * hopefully we will also find y-resolution specified. + * If its not, assume its the same as x-res. + * Maybe Java code should try to reconcile this against + * the printers claimed set of supported resolutions. + */ + if (devmode->dmPrintQuality < 0) { + if (devmode->dmPrintQuality == DMRES_HIGH) { + dmValues |= SET_RES_HIGH; + } else if ((devmode->dmPrintQuality == DMRES_LOW) || + (devmode->dmPrintQuality == DMRES_DRAFT)) { + dmValues |= SET_RES_LOW; + } + /* else if (devmode->dmPrintQuality == DMRES_MEDIUM) + * will set to NORMAL. + */ + } else { + xRes = devmode->dmPrintQuality; + yRes = (devmode->dmFields & DM_YRESOLUTION) ? + devmode->dmYResolution : devmode->dmPrintQuality; + } + } + + if (devmode->dmFields & DM_DUPLEX) { + if (devmode->dmDuplex == DMDUP_HORIZONTAL) { + dmValues |= SET_DUP_HORIZONTAL; + } else if (devmode->dmDuplex == DMDUP_VERTICAL) { + dmValues |= SET_DUP_VERTICAL; + } + } + + env->CallVoidMethod(wJob, AwtPrintControl::setJobAttributesID, attrSet, + devmode->dmFields, dmValues, devmode->dmCopies, + devmode->dmPaperSize, devmode->dmPaperWidth, + devmode->dmPaperLength, devmode->dmDefaultSource, + xRes, yRes); + +} + +JNIEXPORT jboolean JNICALL +Java_sun_awt_windows_WPrinterJob_showDocProperties(JNIEnv *env, + jobject wJob, + jlong hWndParent, + jobject attrSet, + jint dmFields, + jshort copies, + jshort collate, + jshort color, + jshort duplex, + jshort orient, + jshort paper, + jshort bin, + jshort xres_quality, + jshort yres) +{ + TRY; + + HGLOBAL hDevMode = AwtPrintControl::getPrintHDMode(env, wJob); + HGLOBAL hDevNames = AwtPrintControl::getPrintHDName(env, wJob); + DEVMODE *devmode = NULL; + DEVNAMES *devnames = NULL; + LONG rval = IDCANCEL; + jboolean ret = JNI_FALSE; + + if (hDevMode != NULL && hDevNames != NULL) { + devmode = (DEVMODE *)::GlobalLock(hDevMode); + devnames = (DEVNAMES *)::GlobalLock(hDevNames); + + LPTSTR lpdevnames = (LPTSTR)devnames; + // No need to call _tcsdup as we won't unlock until we are done. + LPTSTR printerName = lpdevnames+devnames->wDeviceOffset; + LPTSTR portName = lpdevnames+devnames->wOutputOffset; + + HANDLE hPrinter; + if (::OpenPrinter(printerName, &hPrinter, NULL) == TRUE) { + devmode->dmFields |= dmFields; + devmode->dmCopies = copies; + devmode->dmCollate = collate; + devmode->dmColor = color; + devmode->dmDuplex = duplex; + devmode->dmOrientation = orient; + devmode->dmPrintQuality = xres_quality; + devmode->dmYResolution = yres; + devmode->dmPaperSize = paper; + devmode->dmDefaultSource = bin; + + rval = ::DocumentProperties((HWND)hWndParent, + hPrinter, printerName, devmode, devmode, + DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT); + if (rval == IDOK) { + UpdateJobAttributes(env, wJob, attrSet, devmode); + ret = JNI_TRUE; + } + VERIFY(::ClosePrinter(hPrinter)); + } + ::GlobalUnlock(hDevNames); + ::GlobalUnlock(hDevMode); + } + + return ret; + + CATCH_BAD_ALLOC_RET(0); +} + /************************************************************************ * WPageDialog native methods */ @@ -732,7 +882,6 @@ Java_sun_awt_windows_WPrinterJob_validatePaper(JNIEnv *env, jobject self, memset(&pd, 0, sizeof(PRINTDLG)); pd.lStructSize = sizeof(PRINTDLG); pd.Flags = PD_RETURNDEFAULT | PD_RETURNDC; - if (::PrintDlg(&pd)) { printDC = pd.hDC; hDevMode = pd.hDevMode; @@ -792,8 +941,19 @@ Java_sun_awt_windows_WPrinterJob_validatePaper(JNIEnv *env, jobject self, jint imgPixelWid = GetDeviceCaps(printDC, HORZRES); jint imgPixelHgt = GetDeviceCaps(printDC, VERTRES); + // The DC may be obtained when we first selected the printer as a + // result of a call to setNativePrintService. + // If the Devmode was obtained later on from the DocumentProperties dialog + // the DC won't have been updated and its settings may be for PORTRAIT. + // This may happen in other cases too, but was observed for the above. + // To get a DC compatible with this devmode we should really call + // CreateDC() again to get a DC for the devmode we are using. + // The changes for that are a lot more risk, so to minimise that + // risk, assume its not LANDSCAPE unless width > height, even if the + // devmode says its LANDSCAPE. // if the values were obtained from a rotated device, swap. - if (getOrientationFromDevMode2(hDevMode) == DMORIENT_LANDSCAPE) { + if ((getOrientationFromDevMode2(hDevMode) == DMORIENT_LANDSCAPE) && + (imgPixelWid > imgPixelHgt)) { jint tmp; tmp = xPixelRes; xPixelRes = yPixelRes; @@ -941,6 +1101,9 @@ Java_sun_awt_windows_WPrinterJob_initPrinter(JNIEnv *env, jobject self) { setBooleanField(env, self, DRIVER_COLLATE_STR, JNI_FALSE); } + if (dmFields & DM_COPIES) { + setBooleanField(env, self, DRIVER_COPIES_STR, JNI_TRUE); + } } CATCH_BAD_ALLOC; From 4449fa0c56dadde1625c0211c0de0ea41e9332c7 Mon Sep 17 00:00:00 2001 From: Jonathan Gibbons Date: Fri, 30 Aug 2013 11:48:36 -0700 Subject: [PATCH 022/210] 8023700: Use non breaking space in various labels Reviewed-by: bpatel --- .../html/AnnotationTypeWriterImpl.java | 4 +- .../doclets/formats/html/ClassWriterImpl.java | 4 +- .../formats/html/markup/HtmlWriter.java | 41 ++++++++++++++----- .../testNavigation/TestNavigation.java | 18 ++++---- .../javadoc/testProfiles/TestProfiles.java | 24 +++++------ 5 files changed, 56 insertions(+), 35 deletions(-) diff --git a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/AnnotationTypeWriterImpl.java b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/AnnotationTypeWriterImpl.java index 869bc75f89c..c1c4c9d40e6 100644 --- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/AnnotationTypeWriterImpl.java +++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/AnnotationTypeWriterImpl.java @@ -118,7 +118,7 @@ public class AnnotationTypeWriterImpl extends SubWriterHolderWriter if (prev != null) { Content prevLink = getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.CLASS, prev.asClassDoc()) - .label(configuration.getText("doclet.Prev_Class")).strong(true)); + .label(prevclassLabel).strong(true)); li = HtmlTree.LI(prevLink); } else @@ -136,7 +136,7 @@ public class AnnotationTypeWriterImpl extends SubWriterHolderWriter if (next != null) { Content nextLink = getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.CLASS, next.asClassDoc()) - .label(configuration.getText("doclet.Next_Class")).strong(true)); + .label(nextclassLabel).strong(true)); li = HtmlTree.LI(nextLink); } else diff --git a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/ClassWriterImpl.java b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/ClassWriterImpl.java index 25f0f618af9..7899445dd4a 100644 --- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/ClassWriterImpl.java +++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/ClassWriterImpl.java @@ -126,7 +126,7 @@ public class ClassWriterImpl extends SubWriterHolderWriter if (prev != null) { Content prevLink = getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.CLASS, prev) - .label(configuration.getText("doclet.Prev_Class")).strong(true)); + .label(prevclassLabel).strong(true)); li = HtmlTree.LI(prevLink); } else @@ -144,7 +144,7 @@ public class ClassWriterImpl extends SubWriterHolderWriter if (next != null) { Content nextLink = getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.CLASS, next) - .label(configuration.getText("doclet.Next_Class")).strong(true)); + .label(nextclassLabel).strong(true)); li = HtmlTree.LI(nextLink); } else diff --git a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlWriter.java b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlWriter.java index 5369733893b..36becd2e7ef 100644 --- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlWriter.java +++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlWriter.java @@ -203,27 +203,27 @@ public class HtmlWriter { useLabel = getResource("doclet.navClassUse"); prevLabel = getResource("doclet.Prev"); nextLabel = getResource("doclet.Next"); - prevclassLabel = getResource("doclet.Prev_Class"); - nextclassLabel = getResource("doclet.Next_Class"); + prevclassLabel = getNonBreakResource("doclet.Prev_Class"); + nextclassLabel = getNonBreakResource("doclet.Next_Class"); summaryLabel = getResource("doclet.Summary"); detailLabel = getResource("doclet.Detail"); framesLabel = getResource("doclet.Frames"); - noframesLabel = getResource("doclet.No_Frames"); + noframesLabel = getNonBreakResource("doclet.No_Frames"); treeLabel = getResource("doclet.Tree"); classLabel = getResource("doclet.Class"); deprecatedLabel = getResource("doclet.navDeprecated"); deprecatedPhrase = getResource("doclet.Deprecated"); - allclassesLabel = getResource("doclet.All_Classes"); - allpackagesLabel = getResource("doclet.All_Packages"); - allprofilesLabel = getResource("doclet.All_Profiles"); + allclassesLabel = getNonBreakResource("doclet.All_Classes"); + allpackagesLabel = getNonBreakResource("doclet.All_Packages"); + allprofilesLabel = getNonBreakResource("doclet.All_Profiles"); indexLabel = getResource("doclet.Index"); helpLabel = getResource("doclet.Help"); seeLabel = getResource("doclet.See"); descriptionLabel = getResource("doclet.Description"); - prevpackageLabel = getResource("doclet.Prev_Package"); - nextpackageLabel = getResource("doclet.Next_Package"); - prevprofileLabel = getResource("doclet.Prev_Profile"); - nextprofileLabel = getResource("doclet.Next_Profile"); + prevpackageLabel = getNonBreakResource("doclet.Prev_Package"); + nextpackageLabel = getNonBreakResource("doclet.Next_Package"); + prevprofileLabel = getNonBreakResource("doclet.Prev_Profile"); + nextprofileLabel = getNonBreakResource("doclet.Next_Profile"); packagesLabel = getResource("doclet.Packages"); profilesLabel = getResource("doclet.Profiles"); methodDetailsLabel = getResource("doclet.Method_Detail"); @@ -256,6 +256,27 @@ public class HtmlWriter { return configuration.getResource(key); } + /** + * Get the configuration string as a content, replacing spaces + * with non-breaking spaces. + * + * @param key the key to look for in the configuration file + * @return a content tree for the text + */ + public Content getNonBreakResource(String key) { + String text = configuration.getText(key); + Content c = configuration.newContent(); + int start = 0; + int p; + while ((p = text.indexOf(" ", start)) != -1) { + c.addContent(text.substring(start, p)); + c.addContent(RawHtml.nbsp); + start = p + 1; + } + c.addContent(text.substring(start)); + return c; + } + /** * Get the configuration string as a content. * diff --git a/langtools/test/com/sun/javadoc/testNavigation/TestNavigation.java b/langtools/test/com/sun/javadoc/testNavigation/TestNavigation.java index 9fefe1b7869..d533d98c289 100644 --- a/langtools/test/com/sun/javadoc/testNavigation/TestNavigation.java +++ b/langtools/test/com/sun/javadoc/testNavigation/TestNavigation.java @@ -23,7 +23,7 @@ /* * @test - * @bug 4131628 4664607 7025314 + * @bug 4131628 4664607 7025314 8023700 * @summary Make sure the Next/Prev Class links iterate through all types. * Make sure the navagation is 2 columns, not 3. * @author jamieh @@ -45,20 +45,20 @@ public class TestNavigation extends JavadocTester { //Input for string search tests. private static final String[][] TEST = { - {BUG_ID + FS + "pkg" + FS + "A.html", "

  • Prev Class
  • "}, + {BUG_ID + FS + "pkg" + FS + "A.html", "
  • Prev Class
  • "}, {BUG_ID + FS + "pkg" + FS + "A.html", - "Next Class"}, + "Next Class"}, {BUG_ID + FS + "pkg" + FS + "C.html", - "Prev Class"}, + "Prev Class"}, {BUG_ID + FS + "pkg" + FS + "C.html", - "Next Class"}, + "Next Class"}, {BUG_ID + FS + "pkg" + FS + "E.html", - "Prev Class"}, + "Prev Class"}, {BUG_ID + FS + "pkg" + FS + "E.html", - "Next Class"}, + "Next Class"}, {BUG_ID + FS + "pkg" + FS + "I.html", - "Prev Class"}, - {BUG_ID + FS + "pkg" + FS + "I.html", "
  • Next Class
  • "}, + "Prev Class"}, + {BUG_ID + FS + "pkg" + FS + "I.html", "
  • Next Class
  • "}, // Test for 4664607 {BUG_ID + FS + "pkg" + FS + "I.html", "" + NL + diff --git a/langtools/test/com/sun/javadoc/testProfiles/TestProfiles.java b/langtools/test/com/sun/javadoc/testProfiles/TestProfiles.java index 7d878d7ecd3..5f84abfe7ba 100644 --- a/langtools/test/com/sun/javadoc/testProfiles/TestProfiles.java +++ b/langtools/test/com/sun/javadoc/testProfiles/TestProfiles.java @@ -23,7 +23,7 @@ /* * @test - * @bug 8006124 8009684 8016921 + * @bug 8006124 8009684 8016921 8023700 * @summary Test javadoc support for profiles. * @author Bhavesh Patel * @library ../lib/ @@ -49,7 +49,7 @@ public class TestProfiles extends JavadocTester { // Tests for profile-overview-frame.html listing all profiles. {PROFILE_BUG_ID + FS + "profile-overview-frame.html", "All Packages" + + "target=\"packageListFrame\">All Packages" }, {PROFILE_BUG_ID + FS + "profile-overview-frame.html", "
  • " @@ -58,8 +58,8 @@ public class TestProfiles extends JavadocTester { // Tests for profileName-frame.html listing all packages in a profile. {PROFILE_BUG_ID + FS + "compact2-frame.html", "" - + "All PackagesAll Profiles" + + "All PackagesAll Profiles" }, {PROFILE_BUG_ID + FS + "compact2-frame.html", "
  • Prev Profile
  • " + NL - + "
  • Next Profile
  • " + "
  • Prev Profile
  • " + NL + + "
  • Next Profile
  • " }, {PROFILE_BUG_ID + FS + "compact2-summary.html", "

    Profile compact2

    " @@ -87,7 +87,7 @@ public class TestProfiles extends JavadocTester { // Tests for profileName-package-summary.html listing the summary for a // package in a profile. {PROFILE_BUG_ID + FS + "pkg5" + FS + "compact3-package-summary.html", - "
  • Prev Package" + "
  • Prev Package" + "
  • " }, {PROFILE_BUG_ID + FS + "pkg5" + FS + "compact3-package-summary.html", @@ -96,7 +96,7 @@ public class TestProfiles extends JavadocTester { //Test for "overview-frame.html" showing the "All Profiles" link. {PROFILE_BUG_ID + FS + "overview-frame.html", "All Profiles" + + "target=\"packageListFrame\">All Profiles" }, //Test for "className.html" showing the profile information for the type. {PROFILE_BUG_ID + FS + "pkg2" + FS + "Class1Pkg2.html", @@ -143,12 +143,12 @@ public class TestProfiles extends JavadocTester { private static final String[][] PACKAGES_NEGATED_TEST = { {PACKAGE_BUG_ID + FS + "profile-overview-frame.html", "All Packages" + + "target=\"packageListFrame\">All Packages" }, {PACKAGE_BUG_ID + FS + "compact2-frame.html", "" - + "All PackagesAll Profiles" + + "All PackagesAll Profiles" }, {PACKAGE_BUG_ID + FS + "pkg2" + FS + "compact2-package-frame.html", "" @@ -163,7 +163,7 @@ public class TestProfiles extends JavadocTester { }, {PACKAGE_BUG_ID + FS + "overview-frame.html", "All Profiles" + + "target=\"packageListFrame\">All Profiles" }, {PACKAGE_BUG_ID + FS + "pkg2" + FS + "Class1Pkg2.html", "
    compact1, compact2, compact3
    " From 3dd18b5d8cd96bccc3021b319fd4c179589dc52b Mon Sep 17 00:00:00 2001 From: Jonathan Gibbons Date: Fri, 30 Aug 2013 15:14:51 -0700 Subject: [PATCH 023/210] 8024093: Two *.rej files checked in to langtools/test directory Reviewed-by: mchung --- .../javac/diags/examples/MrefStat.java.rej | 34 ----------------- .../javac/diags/examples/MrefStat1.java.rej | 37 ------------------- 2 files changed, 71 deletions(-) delete mode 100644 langtools/test/tools/javac/diags/examples/MrefStat.java.rej delete mode 100644 langtools/test/tools/javac/diags/examples/MrefStat1.java.rej diff --git a/langtools/test/tools/javac/diags/examples/MrefStat.java.rej b/langtools/test/tools/javac/diags/examples/MrefStat.java.rej deleted file mode 100644 index f5286e5a2d2..00000000000 --- a/langtools/test/tools/javac/diags/examples/MrefStat.java.rej +++ /dev/null @@ -1,34 +0,0 @@ ---- MrefStat.java -+++ MrefStat.java -@@ -0,0 +1,31 @@ -+/* -+ * Copyright (c) 2013, 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. -+ */ -+ -+// key: compiler.note.mref.stat -+// options: -XDdumpLambdaToMethodStats -+ -+class MrefStat { -+ Runnable r = MrefStat::m; -+ -+ static void m() { } -+} diff --git a/langtools/test/tools/javac/diags/examples/MrefStat1.java.rej b/langtools/test/tools/javac/diags/examples/MrefStat1.java.rej deleted file mode 100644 index b247270db53..00000000000 --- a/langtools/test/tools/javac/diags/examples/MrefStat1.java.rej +++ /dev/null @@ -1,37 +0,0 @@ ---- MrefStat1.java -+++ MrefStat1.java -@@ -0,0 +1,34 @@ -+/* -+ * Copyright (c) 2013, 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. -+ */ -+ -+// key: compiler.note.mref.stat.1 -+// options: -XDdumpLambdaToMethodStats -+ -+class MrefStat1 { -+ -+ void m() { } -+ -+ static class Sub extends MrefStat1 { -+ Runnable r = super::m; -+ } -+} From 2b932655644d10b5e6826eada40961dee77fc098 Mon Sep 17 00:00:00 2001 From: Bhavesh Patel Date: Fri, 30 Aug 2013 15:59:33 -0700 Subject: [PATCH 024/210] 7198273: RFE : Javadoc Accessibility : Hyperlinks should contain text or an image with alt text Reviewed-by: jjg --- .../doclets/formats/html/HtmlDocletWriter.java | 16 ++++++++-------- .../doclets/formats/html/markup/HtmlStyle.java | 1 + .../internal/toolkit/resources/stylesheet.css | 6 ++++++ .../sun/javadoc/AccessSkipNav/AccessSkipNav.java | 10 +++++----- .../javadoc/testNavigation/TestNavigation.java | 7 +++---- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java index 8dcf113e3f3..c55ff564f2f 100644 --- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java +++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java @@ -502,16 +502,17 @@ public class HtmlDocletWriter extends HtmlDocWriter { if (!configuration.nonavbar) { String allClassesId = "allclasses_"; HtmlTree navDiv = new HtmlTree(HtmlTag.DIV); + Content skipNavLinks = configuration.getResource("doclet.Skip_navigation_links"); if (header) { body.addContent(HtmlConstants.START_OF_TOP_NAVBAR); navDiv.addStyle(HtmlStyle.topNav); allClassesId += "navbar_top"; Content a = getMarkerAnchor("navbar_top"); + //WCAG - Hyperlinks should contain text or an image with alt text - for AT tools navDiv.addContent(a); - Content skipLinkContent = getHyperLink(DocLink.fragment("skip-navbar_top"), - HtmlTree.EMPTY, - configuration.getText("doclet.Skip_navigation_links"), - ""); + Content skipLinkContent = HtmlTree.DIV(HtmlStyle.skipNav, getHyperLink( + DocLink.fragment("skip-navbar_top"), skipNavLinks, + skipNavLinks.toString(), "")); navDiv.addContent(skipLinkContent); } else { body.addContent(HtmlConstants.START_OF_BOTTOM_NAVBAR); @@ -519,10 +520,9 @@ public class HtmlDocletWriter extends HtmlDocWriter { allClassesId += "navbar_bottom"; Content a = getMarkerAnchor("navbar_bottom"); navDiv.addContent(a); - Content skipLinkContent = getHyperLink(DocLink.fragment("skip-navbar_bottom"), - HtmlTree.EMPTY, - configuration.getText("doclet.Skip_navigation_links"), - ""); + Content skipLinkContent = HtmlTree.DIV(HtmlStyle.skipNav, getHyperLink( + DocLink.fragment("skip-navbar_bottom"), skipNavLinks, + skipNavLinks.toString(), "")); navDiv.addContent(skipLinkContent); } if (header) { diff --git a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlStyle.java b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlStyle.java index c20ac4c5d5f..5bf1c3259fe 100644 --- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlStyle.java +++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlStyle.java @@ -68,6 +68,7 @@ public enum HtmlStyle { packageSummary, rowColor, serializedFormContainer, + skipNav, sourceContainer, sourceLineNo, strong, diff --git a/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/resources/stylesheet.css b/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/resources/stylesheet.css index b2adb742b81..c264d66b303 100644 --- a/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/resources/stylesheet.css +++ b/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/resources/stylesheet.css @@ -180,6 +180,12 @@ ul.subNavList li{ margin: auto 5px; border:1px solid #c9aa44; } +.skipNav { + position:absolute; + top:auto; + left:-9999px; + overflow:hidden; + } /* Page header and footer styles */ diff --git a/langtools/test/com/sun/javadoc/AccessSkipNav/AccessSkipNav.java b/langtools/test/com/sun/javadoc/AccessSkipNav/AccessSkipNav.java index d88329cb5db..6ad89feb8bf 100644 --- a/langtools/test/com/sun/javadoc/AccessSkipNav/AccessSkipNav.java +++ b/langtools/test/com/sun/javadoc/AccessSkipNav/AccessSkipNav.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2013, 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 4638136 + * @bug 4638136 7198273 * @summary Add ability to skip over nav bar for accessibility * @author dkramer * @run main AccessSkipNav @@ -42,7 +42,7 @@ import java.io.*; */ public class AccessSkipNav { - private static final String BUGID = "4638136"; + private static final String BUGID = "4638136 - 7198273"; private static final String BUGNAME = "AccessSkipNav"; private static final String FS = System.getProperty("file.separator"); private static final String PS = System.getProperty("path.separator"); @@ -86,7 +86,7 @@ public class AccessSkipNav { // Testing only for the presence of the and // Top navbar - { "", + { "Skip navigation links", TMPDEST_DIR1 + "p1" + FS + "C1.html" }, // Top navbar @@ -95,7 +95,7 @@ public class AccessSkipNav { TMPDEST_DIR1 + "p1" + FS + "C1.html" }, // Bottom navbar - { "", + { "Skip navigation links", TMPDEST_DIR1 + "p1" + FS + "C1.html" }, // Bottom navbar diff --git a/langtools/test/com/sun/javadoc/testNavigation/TestNavigation.java b/langtools/test/com/sun/javadoc/testNavigation/TestNavigation.java index d533d98c289..4466eb87d0e 100644 --- a/langtools/test/com/sun/javadoc/testNavigation/TestNavigation.java +++ b/langtools/test/com/sun/javadoc/testNavigation/TestNavigation.java @@ -23,13 +23,12 @@ /* * @test - * @bug 4131628 4664607 7025314 8023700 + * @bug 4131628 4664607 7025314 8023700 7198273 * @summary Make sure the Next/Prev Class links iterate through all types. * Make sure the navagation is 2 columns, not 3. * @author jamieh * @library ../lib/ - * @build JavadocTester - * @build TestNavigation + * @build JavadocTester TestNavigation * @run main TestNavigation */ @@ -61,7 +60,7 @@ public class TestNavigation extends JavadocTester { {BUG_ID + FS + "pkg" + FS + "I.html", "
  • Next Class
  • "}, // Test for 4664607 {BUG_ID + FS + "pkg" + FS + "I.html", - "
    " + NL + + "" + NL + "" + NL + "" + NL + ""} }; private static final String[][] NEGATED_TEST = NO_TEST; From 5793c3a33c6142e27dfe21b66770c52d309fd36a Mon Sep 17 00:00:00 2001 From: Bhavesh Patel Date: Fri, 30 Aug 2013 16:16:28 -0700 Subject: [PATCH 025/210] 8015882: Javadoc prints NPE when using Taglet Reviewed-by: jjg --- .../toolkit/taglets/LegacyTaglet.java | 8 +- .../com/sun/javadoc/testLegacyTaglet/C.java | 10 +- .../sun/javadoc/testLegacyTaglet/Check.java | 143 ++++++++++++++++++ .../testLegacyTaglet/TestLegacyTaglet.java | 22 +-- 4 files changed, 172 insertions(+), 11 deletions(-) create mode 100644 langtools/test/com/sun/javadoc/testLegacyTaglet/Check.java diff --git a/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/LegacyTaglet.java b/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/LegacyTaglet.java index 2691c2b4ab3..2dfce45c157 100644 --- a/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/LegacyTaglet.java +++ b/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/LegacyTaglet.java @@ -130,7 +130,13 @@ public class LegacyTaglet implements Taglet { public Content getTagletOutput(Doc holder, TagletWriter writer) throws IllegalArgumentException { Content output = writer.getOutputInstance(); - output.addContent(new RawHtml(legacyTaglet.toString(holder.tags(getName())))); + Tag[] tags = holder.tags(getName()); + if (tags.length > 0) { + String tagString = legacyTaglet.toString(tags); + if (tagString != null) { + output.addContent(new RawHtml(tagString)); + } + } return output; } } diff --git a/langtools/test/com/sun/javadoc/testLegacyTaglet/C.java b/langtools/test/com/sun/javadoc/testLegacyTaglet/C.java index d5370c2dcd6..6de5ca31ef1 100644 --- a/langtools/test/com/sun/javadoc/testLegacyTaglet/C.java +++ b/langtools/test/com/sun/javadoc/testLegacyTaglet/C.java @@ -25,5 +25,13 @@ /** * This is an {@underline underline}. * @todo Finish this class. + * @check Check this. */ -public class C {} +public class C { + + /** + * @todo Tag in Method. + */ + public void mtd() { + } +} diff --git a/langtools/test/com/sun/javadoc/testLegacyTaglet/Check.java b/langtools/test/com/sun/javadoc/testLegacyTaglet/Check.java new file mode 100644 index 00000000000..a294603b99a --- /dev/null +++ b/langtools/test/com/sun/javadoc/testLegacyTaglet/Check.java @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2013, 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 com.sun.tools.doclets.Taglet; +import com.sun.javadoc.*; +import java.util.Map; + +public class Check implements Taglet { + + private static final String TAG_NAME = "check"; + private static final String TAG_HEADER = "Check:"; + + /** + * Return true since the tag can be used in package documentation. + * + * @return true since the tag can be used in package documentation. + */ + public boolean inPackage() { + return true; + } + + /** + * Return true since the tag can be used in overview documentation. + * + * @return true since the tag can be used in overview documentation. + */ + public boolean inOverview() { + return true; + } + + /** + * Return true since the tag can be used in type (class/interface) + * documentation. + * + * @return true since the tag can be used in type (class/interface) + * documentation. + */ + public boolean inType() { + return true; + } + + /** + * Return true since the tag can be used in constructor documentation. + * + * @return true since the tag can be used in constructor documentation. + */ + public boolean inConstructor() { + return true; + } + + /** + * Return true since the tag can be used in field documentation. + * + * @return true since the tag can be used in field documentation. + */ + public boolean inField() { + return true; + } + + /** + * Return true since the tag can be used in method documentation. + * + * @return true since the tag can be used in method documentation. + */ + public boolean inMethod() { + return true; + } + + /** + * Return false since the tag is not an inline tag. + * + * @return false since the tag is not an inline tag. + */ + public boolean isInlineTag() { + return false; + } + + /** + * Register this taglet. + * + * @param tagletMap the map to register this tag to. + */ + @SuppressWarnings("unchecked") + public static void register(Map tagletMap) { + Check tag = new Check(); + Taglet t = (Taglet) tagletMap.get(tag.getName()); + if (t != null) { + tagletMap.remove(tag.getName()); + } + tagletMap.put(tag.getName(), tag); + } + + /** + * Return the name of this custom tag. + * + * @return the name of this tag. + */ + public String getName() { + return TAG_NAME; + } + + /** + * Given the tag representation of this custom tag, return its string + * representation. + * + * @param tag the tag representation of this custom tag. + */ + public String toString(Tag tag) { + return "
    " + TAG_HEADER + ":
    " + tag.text() + + "
    \n"; + } + + /** + * Given an array of tags representing this custom tag, return its string + * representation. + * + * @param tags the array of tags representing of this custom tag. + * @return null to test if the javadoc throws an exception or not. + */ + public String toString(Tag[] tags) { + return null; + } +} diff --git a/langtools/test/com/sun/javadoc/testLegacyTaglet/TestLegacyTaglet.java b/langtools/test/com/sun/javadoc/testLegacyTaglet/TestLegacyTaglet.java index 8e1790de54a..f86c998e809 100644 --- a/langtools/test/com/sun/javadoc/testLegacyTaglet/TestLegacyTaglet.java +++ b/langtools/test/com/sun/javadoc/testLegacyTaglet/TestLegacyTaglet.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2013, 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,32 +23,33 @@ /* * @test - * @bug 4638723 + * @bug 4638723 8015882 * @summary Test to ensure that the refactored version of the standard * doclet still works with Taglets that implement the 1.4.0 interface. * @author jamieh * @library ../lib/ - * @compile ../lib/JavadocTester.java - * @compile TestLegacyTaglet.java - * @compile ToDoTaglet.java - * @compile UnderlineTaglet.java + * @compile ../lib/JavadocTester.java TestLegacyTaglet.java ToDoTaglet.java UnderlineTaglet.java Check.java * @run main TestLegacyTaglet */ public class TestLegacyTaglet extends JavadocTester { - private static final String BUG_ID = "4638723"; + private static final String BUG_ID = "4638723-8015882"; private static final String[] ARGS = new String[] {"-d", BUG_ID, "-sourcepath", SRC_DIR, - "-tagletpath", SRC_DIR, "-taglet", "ToDoTaglet", + "-tagletpath", SRC_DIR, "-taglet", "ToDoTaglet", "-taglet", "Check", "-taglet", "UnderlineTaglet", SRC_DIR + FS + "C.java"}; private static final String[][] TEST = new String[][] { {BUG_ID + FS + "C.html", "This is an underline"}, {BUG_ID + FS + "C.html", "
    To Do:
    " + - "
    Finish this class.
    "}}; + "Finish this class."}, + {BUG_ID + FS + "C.html", + "
    To Do:
    " + + "
    Tag in Method.
    "} + }; private static final String[][] NEGATED_TEST = NO_TEST; @@ -59,6 +60,9 @@ public class TestLegacyTaglet extends JavadocTester { public static void main(String[] args) { TestLegacyTaglet tester = new TestLegacyTaglet(); run(tester, ARGS, TEST, NEGATED_TEST); + if (tester.getErrorOutput().contains("NullPointerException")) { + throw new AssertionError("javadoc threw NullPointerException"); + } tester.printSummary(); } From 4cf2250826682bc71b3119301b23658f19931a9b Mon Sep 17 00:00:00 2001 From: Jonathan Gibbons Date: Fri, 30 Aug 2013 16:27:08 -0700 Subject: [PATCH 026/210] 8008367: Sub-packages missing from Profiles javadoc Reviewed-by: bpatel --- .../internal/toolkit/Configuration.java | 72 ++++++++++--------- 1 file changed, 39 insertions(+), 33 deletions(-) diff --git a/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java b/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java index 32b7648e34b..0337840d248 100644 --- a/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java +++ b/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java @@ -383,35 +383,44 @@ public abstract class Configuration { DocErrorReporter reporter); private void initProfiles() throws IOException { - profiles = Profiles.read(new File(profilespath)); - // Generate profiles documentation only is profilespath is set and if - // profiles is not null and profiles count is 1 or more. - showProfiles = (!profilespath.isEmpty() && profiles != null && - profiles.getProfileCount() > 0); - } + if (profilespath.isEmpty()) + return; - private void initProfilePackages() throws IOException { - profilePackages = new HashMap(); - ArrayList results; - Map packageIndex = new HashMap(); - for (int i = 0; i < packages.length; i++) { - PackageDoc pkg = packages[i]; - packageIndex.put(pkg.name(), pkg); - } - for (int i = 1; i < profiles.getProfileCount(); i++) { - Set profPkgs = profiles.getPackages(i); - results = new ArrayList(); - for (String packageName : profPkgs) { - packageName = packageName.replace("/", "."); - PackageDoc profPkg = packageIndex.get(packageName); - if (profPkg != null) { - results.add(profPkg); - } + profiles = Profiles.read(new File(profilespath)); + + // Group the packages to be documented by the lowest profile (if any) + // in which each appears + Map> interimResults = + new EnumMap>(Profile.class); + for (Profile p: Profile.values()) + interimResults.put(p, new ArrayList()); + + for (PackageDoc pkg: packages) { + // the getProfile method takes a type name, not a package name, + // but isn't particularly fussy about the simple name -- so just use * + int i = profiles.getProfile(pkg.name().replace(".", "/") + "/*"); + Profile p = Profile.lookup(i); + if (p != null) { + List pkgs = interimResults.get(p); + pkgs.add(pkg); } - Collections.sort(results); - PackageDoc[] profilePkgs = results.toArray(new PackageDoc[]{}); - profilePackages.put(Profile.lookup(i).name, profilePkgs); } + + // Build the profilePackages structure used by the doclet + profilePackages = new HashMap(); + List prev = Collections.emptyList(); + for (Map.Entry> e: interimResults.entrySet()) { + Profile p = e.getKey(); + List pkgs = e.getValue(); + pkgs.addAll(prev); // each profile contains all lower profiles + Collections.sort(pkgs); + profilePackages.put(p.name, pkgs.toArray(new PackageDoc[pkgs.size()])); + prev = pkgs; + } + + // Generate profiles documentation if any profile contains any + // of the packages to be documented. + showProfiles = !prev.isEmpty(); } private void initPackageArray() { @@ -534,13 +543,10 @@ public abstract class Configuration { public void setOptions() throws Fault { initPackageArray(); setOptions(root.options()); - if (!profilespath.isEmpty()) { - try { - initProfiles(); - initProfilePackages(); - } catch (Exception e) { - throw new DocletAbortException(e); - } + try { + initProfiles(); + } catch (Exception e) { + throw new DocletAbortException(e); } setSpecificDocletOptions(root.options()); } From b8f8cab5f46da79d63c1b701d345d224e3b55cb7 Mon Sep 17 00:00:00 2001 From: Bhavesh Patel Date: Fri, 30 Aug 2013 16:38:54 -0700 Subject: [PATCH 027/210] 8022738: doclet should only generate functional interface text if source >= 8 Reviewed-by: jjg --- .../com/sun/tools/javadoc/ClassDocImpl.java | 2 +- .../classes/com/sun/tools/javadoc/DocEnv.java | 6 ++++ .../testLambdaFeature/TestLambdaFeature.java | 22 +++++++++++--- .../testLambdaFeature/pkg1/FuncInf.java | 29 +++++++++++++++++++ 4 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 langtools/test/com/sun/javadoc/testLambdaFeature/pkg1/FuncInf.java diff --git a/langtools/src/share/classes/com/sun/tools/javadoc/ClassDocImpl.java b/langtools/src/share/classes/com/sun/tools/javadoc/ClassDocImpl.java index 79580f60fb5..160ccbceb10 100644 --- a/langtools/src/share/classes/com/sun/tools/javadoc/ClassDocImpl.java +++ b/langtools/src/share/classes/com/sun/tools/javadoc/ClassDocImpl.java @@ -289,7 +289,7 @@ public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc { } public boolean isFunctionalInterface() { - return env.types.isFunctionalInterface(tsym); + return env.types.isFunctionalInterface(tsym) && env.source.allowLambda(); } /** diff --git a/langtools/src/share/classes/com/sun/tools/javadoc/DocEnv.java b/langtools/src/share/classes/com/sun/tools/javadoc/DocEnv.java index 3a1c891984e..d0ff14b70ea 100644 --- a/langtools/src/share/classes/com/sun/tools/javadoc/DocEnv.java +++ b/langtools/src/share/classes/com/sun/tools/javadoc/DocEnv.java @@ -123,6 +123,11 @@ public class DocEnv { */ private boolean silent = false; + /** + * The source language version. + */ + protected Source source; + /** * Constructor * @@ -144,6 +149,7 @@ public class DocEnv { // Default. Should normally be reset with setLocale. this.doclocale = new DocLocale(this, "", breakiterator); + source = Source.instance(context); } public void setSilent(boolean silent) { diff --git a/langtools/test/com/sun/javadoc/testLambdaFeature/TestLambdaFeature.java b/langtools/test/com/sun/javadoc/testLambdaFeature/TestLambdaFeature.java index 7a157ffc17d..151549b57a2 100644 --- a/langtools/test/com/sun/javadoc/testLambdaFeature/TestLambdaFeature.java +++ b/langtools/test/com/sun/javadoc/testLambdaFeature/TestLambdaFeature.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2013, 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 8004893 + * @bug 8004893 8022738 * @summary Make sure that the lambda feature changes work fine in * javadoc. * @author bpatel @@ -35,11 +35,15 @@ public class TestLambdaFeature extends JavadocTester { //Test information. - private static final String BUG_ID = "8004893"; + private static final String BUG_ID = "8004893-8022738"; //Javadoc arguments. private static final String[] ARGS = new String[] { - "-d", BUG_ID, "-sourcepath", SRC_DIR, "pkg" + "-d", BUG_ID, "-sourcepath", SRC_DIR, "pkg", "pkg1" + }; + + private static final String[] ARGS_1 = new String[] { + "-d", BUG_ID + "-2", "-sourcepath", SRC_DIR, "-source", "1.5", "pkg1" }; //Input for string search tests. @@ -60,6 +64,11 @@ public class TestLambdaFeature extends JavadocTester { "Default Methods" + " "}, {BUG_ID + FS + "pkg" + FS + "A.html", + "
    " + NL + "
    Functional Interface:
    " + NL + + "
    This is a functional interface and can therefore be used as " + + "the assignment target for a lambda expression or method " + + "reference.
    " + NL + "
    "}, + {BUG_ID + FS + "pkg1" + FS + "FuncInf.html", "
    " + NL + "
    Functional Interface:
    " + NL + "
    This is a functional interface and can therefore be used as " + "the assignment target for a lambda expression or method " + @@ -75,6 +84,10 @@ public class TestLambdaFeature extends JavadocTester { {BUG_ID + FS + "pkg" + FS + "B.html", "
    " + NL + "
    Functional Interface:
    "} }; + private static final String[][] NEGATED_TEST_1 = { + {BUG_ID + "-2" + FS + "pkg1" + FS + "FuncInf.html", + "
    " + NL + "
    Functional Interface:
    "} + }; /** * The entry point of the test. @@ -83,6 +96,7 @@ public class TestLambdaFeature extends JavadocTester { public static void main(String[] args) { TestLambdaFeature tester = new TestLambdaFeature(); run(tester, ARGS, TEST, NEGATED_TEST); + run(tester, ARGS_1, NO_TEST, NEGATED_TEST_1); tester.printSummary(); } diff --git a/langtools/test/com/sun/javadoc/testLambdaFeature/pkg1/FuncInf.java b/langtools/test/com/sun/javadoc/testLambdaFeature/pkg1/FuncInf.java new file mode 100644 index 00000000000..566acf596ca --- /dev/null +++ b/langtools/test/com/sun/javadoc/testLambdaFeature/pkg1/FuncInf.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013, 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. + */ + +package pkg1; + +public interface FuncInf { + + V call() throws Exception; +} From 433728650249fb0fe2b92ab5692d7257daaeb0fd Mon Sep 17 00:00:00 2001 From: Evgeniya Stepanova Date: Fri, 30 Aug 2013 17:36:47 -0700 Subject: [PATCH 028/210] 8015663: Need to supply tests to provide javadoc for profiles support code coverage Reviewed-by: jjg --- .../javadoc/testProfiles/TestProfiles.java | 52 +++++++++- .../TestProfilesConfiguration.java | 94 +++++++++++++++++++ .../javadoc/testProfiles/pkg2/Class1Pkg2.java | 2 +- .../javadoc/testProfiles/pkg2/ClassError.java | 31 ++++++ .../testProfiles/pkg2/ClassException.java | 31 ++++++ .../pkgDeprecated/Class1PkgDeprecated.java | 36 +++++++ .../pkgDeprecated/package-info.java | 29 ++++++ .../testProfiles/profile-rtjar-includes.txt | 3 +- 8 files changed, 273 insertions(+), 5 deletions(-) create mode 100644 langtools/test/com/sun/javadoc/testProfiles/TestProfilesConfiguration.java create mode 100644 langtools/test/com/sun/javadoc/testProfiles/pkg2/ClassError.java create mode 100644 langtools/test/com/sun/javadoc/testProfiles/pkg2/ClassException.java create mode 100644 langtools/test/com/sun/javadoc/testProfiles/pkgDeprecated/Class1PkgDeprecated.java create mode 100644 langtools/test/com/sun/javadoc/testProfiles/pkgDeprecated/package-info.java diff --git a/langtools/test/com/sun/javadoc/testProfiles/TestProfiles.java b/langtools/test/com/sun/javadoc/testProfiles/TestProfiles.java index 5f84abfe7ba..8dda141791c 100644 --- a/langtools/test/com/sun/javadoc/testProfiles/TestProfiles.java +++ b/langtools/test/com/sun/javadoc/testProfiles/TestProfiles.java @@ -25,7 +25,7 @@ * @test * @bug 8006124 8009684 8016921 8023700 * @summary Test javadoc support for profiles. - * @author Bhavesh Patel + * @author Bhavesh Patel, Evgeniya Stepanova * @library ../lib/ * @build JavadocTester TestProfiles * @run main TestProfiles @@ -38,8 +38,9 @@ public class TestProfiles extends JavadocTester { private static final String PACKAGE_BUG_ID = BUG_ID + "-2"; //Javadoc arguments. private static final String[] ARGS1 = new String[]{ - "-d", PROFILE_BUG_ID, "-sourcepath", SRC_DIR, "-Xprofilespath", SRC_DIR + FS - + "profile-rtjar-includes.txt", "pkg1", "pkg2", "pkg3", "pkg4", "pkg5" + "-d", PROFILE_BUG_ID, "-sourcepath", SRC_DIR, "-Xprofilespath", + SRC_DIR + FS + "profile-rtjar-includes.txt", "pkg1", "pkg2", + "pkg3", "pkg4", "pkg5", "pkgDeprecated" }; private static final String[] ARGS2 = new String[]{ "-d", PACKAGE_BUG_ID, "-sourcepath", SRC_DIR, "pkg1", "pkg2", "pkg3", "pkg4", "pkg5" @@ -113,6 +114,49 @@ public class TestProfiles extends JavadocTester { "target=\"classFrame\">compact2" + NL + "
  • compact3
  • " + NL + "" + }, + //Test deprecated class in profiles + {PROFILE_BUG_ID + FS + "compact1-summary.html","" + + "Class1Pkg2" + + NL + "Deprecated" + }, + {PROFILE_BUG_ID + FS + "deprecated-list.html","" + + "pkg2.Class1Pkg2" + + NL +"
    Class1Pkg2. This class is deprecated
    " + }, + //Test deprecated package in profile + {PROFILE_BUG_ID + FS + "deprecated-list.html","" + + "pkgDeprecated" + + NL +"
    This package is Deprecated." + + " Use pkg1.
    " + }, + {PROFILE_BUG_ID + FS + "pkgDeprecated" + FS + "package-summary.html", + "
    Deprecated." + + NL + "
    This package is Deprecated." + + " Use pkg1.
    " + }, + // need to add teststring when JDK-8015496 will be fixed + //Test exception in profiles + {PROFILE_BUG_ID + FS + "compact1-summary.html","" + + NL + "" + NL + "" + NL + "" + NL + "" + NL + "" + NL + "" + NL + "" + + NL + "" + }, + //Test errors in profiles + {PROFILE_BUG_ID + FS + "compact1-summary.html", + "
    Exception Summary" + + " 
    Exception" + + "Description
    ClassException
    " + + NL + "" + NL + "" + NL + "" + NL + "" + NL + "" + NL + "" + + NL + "" + NL + "" } }; private static final String[][] PROFILES_NEGATED_TEST = { @@ -125,6 +169,8 @@ public class TestProfiles extends JavadocTester { {PROFILE_BUG_ID + FS + "pkg4" + FS + "compact2-package-frame.html", "
  • Anno1Pkg4
  • " + }, + {PROFILE_BUG_ID + FS + "compact1-summary.html","
  • Use
  • " } }; private static final String[][] PACKAGES_TEST = { diff --git a/langtools/test/com/sun/javadoc/testProfiles/TestProfilesConfiguration.java b/langtools/test/com/sun/javadoc/testProfiles/TestProfilesConfiguration.java new file mode 100644 index 00000000000..140728e1ac5 --- /dev/null +++ b/langtools/test/com/sun/javadoc/testProfiles/TestProfilesConfiguration.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2013, 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 8006124 8009684 8015663 + * @summary Test javadoc options support for profiles. + * @author Evgeniya Stepanova + * @library ../lib/ + * @build JavadocTester TestProfilesConfiguration + * @run main TestProfilesConfiguration + */ +public class TestProfilesConfiguration extends JavadocTester { + + //Test information. + private static final String BUG_ID = "8006124-8009684"; + private static final String PROFILE_CONFIGURATION_BUG_ID = BUG_ID + "-3"; + //Javadoc arguments. + private static final String[] ARGS3 = new String[]{ + "-d", PROFILE_CONFIGURATION_BUG_ID, "-sourcepath", SRC_DIR, "-nocomment", + "-keywords", "-Xprofilespath", SRC_DIR + FS + "profile-rtjar-includes.txt", + "-doctitle", "Simple doctitle", "-use", "pkg3", "pkg1", "pkg2", "pkg4", + "pkg5", "-packagesheader", "Simple packages header","pkgDeprecated" + }; + private static final String[][] PROFILES_CONFIGURATION_TEST = { + //-use option test string fo profile view page + {PROFILE_CONFIGURATION_BUG_ID + FS + "compact1-summary.html","
  • Use
  • " + }, + //-doctitle option test string + {PROFILE_CONFIGURATION_BUG_ID + FS + "overview-summary.html", + "
    " + NL + "

    Simple doctitle

    " + }, + //-packagesheader option test string fo profiles + {PROFILE_CONFIGURATION_BUG_ID + FS + "profile-overview-frame.html", + "

    Simple packages header

    " + }, + //-keywords option test string for profiles + {PROFILE_CONFIGURATION_BUG_ID + FS + "compact1-summary.html", + "" + } + }; + private static final String[][] PROFILES_CONFIGURATION_NEGATED_TEST = { + //-nocomments option test string + {PROFILE_CONFIGURATION_BUG_ID + FS + "compact1-summary.html", + "
    Class1Pkg2.
    " + } + }; + + /** + * The entry point of the test. + * + * @param args the array of command line arguments. + */ + public static void main(String[] args) { + TestProfilesConfiguration tester = new TestProfilesConfiguration(); + run(tester, ARGS3, PROFILES_CONFIGURATION_TEST, + PROFILES_CONFIGURATION_NEGATED_TEST); + tester.printSummary(); + } + + /** + * {@inheritDoc} + */ + public String getBugId() { + return BUG_ID; + } + + /** + * {@inheritDoc} + */ + public String getBugName() { + return getClass().getName(); + } +} diff --git a/langtools/test/com/sun/javadoc/testProfiles/pkg2/Class1Pkg2.java b/langtools/test/com/sun/javadoc/testProfiles/pkg2/Class1Pkg2.java index afa13d8444e..935bd3643ae 100644 --- a/langtools/test/com/sun/javadoc/testProfiles/pkg2/Class1Pkg2.java +++ b/langtools/test/com/sun/javadoc/testProfiles/pkg2/Class1Pkg2.java @@ -24,7 +24,7 @@ package pkg2; /** - * Another test class. + * @deprecated Class1Pkg2. This class is deprecated * * @author Bhavesh Patel */ diff --git a/langtools/test/com/sun/javadoc/testProfiles/pkg2/ClassError.java b/langtools/test/com/sun/javadoc/testProfiles/pkg2/ClassError.java new file mode 100644 index 00000000000..427b8f9c896 --- /dev/null +++ b/langtools/test/com/sun/javadoc/testProfiles/pkg2/ClassError.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013, 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. + */ + +package pkg2; + +/** + * Simple error class. + * + * @author Evgeniya Stepanova + */ +public class ClassError extends Error {} diff --git a/langtools/test/com/sun/javadoc/testProfiles/pkg2/ClassException.java b/langtools/test/com/sun/javadoc/testProfiles/pkg2/ClassException.java new file mode 100644 index 00000000000..d56412e7da2 --- /dev/null +++ b/langtools/test/com/sun/javadoc/testProfiles/pkg2/ClassException.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013, 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. + */ + +package pkg2; + +/** + * Simple exception class. + * + * @author Evgeniya Stepanova + */ +public class ClassException extends Exception {} diff --git a/langtools/test/com/sun/javadoc/testProfiles/pkgDeprecated/Class1PkgDeprecated.java b/langtools/test/com/sun/javadoc/testProfiles/pkgDeprecated/Class1PkgDeprecated.java new file mode 100644 index 00000000000..51475499286 --- /dev/null +++ b/langtools/test/com/sun/javadoc/testProfiles/pkgDeprecated/Class1PkgDeprecated.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013, 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. + */ + +package pkgDeprecated; + +/** + * Simple deprecated class of deprecated package. + * + * @author Evgeniya Stepanova + */ +public class Class1PkgDeprecated { + + public void method(int t) { + return null; + } +} diff --git a/langtools/test/com/sun/javadoc/testProfiles/pkgDeprecated/package-info.java b/langtools/test/com/sun/javadoc/testProfiles/pkgDeprecated/package-info.java new file mode 100644 index 00000000000..0cc070077cb --- /dev/null +++ b/langtools/test/com/sun/javadoc/testProfiles/pkgDeprecated/package-info.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013, 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. + */ + +/** + * Deprecated package. + * + * @deprecated This package is Deprecated. Use pkg1. + */ +package pkgDeprecated; diff --git a/langtools/test/com/sun/javadoc/testProfiles/profile-rtjar-includes.txt b/langtools/test/com/sun/javadoc/testProfiles/profile-rtjar-includes.txt index 9460b3f985b..eff8d14b438 100644 --- a/langtools/test/com/sun/javadoc/testProfiles/profile-rtjar-includes.txt +++ b/langtools/test/com/sun/javadoc/testProfiles/profile-rtjar-includes.txt @@ -1,5 +1,6 @@ PROFILE_1_RTJAR_INCLUDE_PACKAGES := \ - pkg2 + pkg2 \ + pkgDeprecated PROFILE_1_RTJAR_INCLUDE_TYPES := \ pkg3/Class1Pkg3.class From 24f306c761ab39cb76b22ddb28fee77074d3c0ef Mon Sep 17 00:00:00 2001 From: Clemens Eisserer Date: Sun, 1 Sep 2013 09:38:03 -0700 Subject: [PATCH 029/210] 7189452: XRender pipeline does ignore source-surface offset for text rendering Reviewed-by: prr, bae --- jdk/src/solaris/classes/sun/font/XRTextRenderer.java | 2 +- .../solaris/classes/sun/java2d/xr/XRBackendNative.java | 9 +++++---- .../classes/sun/java2d/xr/XRCompositeManager.java | 8 ++++---- jdk/src/solaris/native/sun/java2d/x11/XRBackendNative.c | 7 ++++--- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/jdk/src/solaris/classes/sun/font/XRTextRenderer.java b/jdk/src/solaris/classes/sun/font/XRTextRenderer.java index c2aa27b43e0..308de3ab300 100644 --- a/jdk/src/solaris/classes/sun/font/XRTextRenderer.java +++ b/jdk/src/solaris/classes/sun/font/XRTextRenderer.java @@ -142,7 +142,7 @@ public class XRTextRenderer extends GlyphListPipe { } int maskFormat = containsLCDGlyphs ? XRUtils.PictStandardARGB32 : XRUtils.PictStandardA8; - maskBuffer.compositeText(x11sd.picture, 0, maskFormat, eltList); + maskBuffer.compositeText(x11sd, (int) gl.getX(), (int) gl.getY(), 0, maskFormat, eltList); eltList.clear(); } finally { diff --git a/jdk/src/solaris/classes/sun/java2d/xr/XRBackendNative.java b/jdk/src/solaris/classes/sun/java2d/xr/XRBackendNative.java index a6ffd0defcd..205ff13c6fc 100644 --- a/jdk/src/solaris/classes/sun/java2d/xr/XRBackendNative.java +++ b/jdk/src/solaris/classes/sun/java2d/xr/XRBackendNative.java @@ -267,8 +267,9 @@ public class XRBackendNative implements XRBackend { private static native void XRenderCompositeTextNative(int op, int src, int dst, - long maskFormat, int[] eltArray, - int[] glyphIDs, int eltCnt, int glyphCnt); + int srcX, int srcY, long maskFormat, + int[] eltArray, int[] glyphIDs, int eltCnt, + int glyphCnt); public int XRenderCreateGlyphSet(int formatID) { return XRenderCreateGlyphSetNative(getFormatPtr(formatID)); @@ -278,11 +279,11 @@ public class XRBackendNative implements XRBackend { public void XRenderCompositeText(byte op, int src, int dst, int maskFormatID, - int src2, int src3, int dst2, int dst3, + int sx, int sy, int dx, int dy, int glyphset, GrowableEltArray elts) { GrowableIntArray glyphs = elts.getGlyphs(); - XRenderCompositeTextNative(op, src, dst, 0, elts.getArray(), + XRenderCompositeTextNative(op, src, dst, sx, sy, 0, elts.getArray(), glyphs.getArray(), elts.getSize(), glyphs.getSize()); } diff --git a/jdk/src/solaris/classes/sun/java2d/xr/XRCompositeManager.java b/jdk/src/solaris/classes/sun/java2d/xr/XRCompositeManager.java index 1264d539611..b1c2ef08065 100644 --- a/jdk/src/solaris/classes/sun/java2d/xr/XRCompositeManager.java +++ b/jdk/src/solaris/classes/sun/java2d/xr/XRCompositeManager.java @@ -295,10 +295,10 @@ public class XRCompositeManager { sy, 0, 0, dx, dy, w, h); } - public void compositeText(int dst, int glyphSet, int maskFormat, - GrowableEltArray elts) { - con.XRenderCompositeText(compRule, src.picture, dst, maskFormat, 0, 0, - 0, 0, glyphSet, elts); + public void compositeText(XRSurfaceData dst, int sx, int sy, + int glyphSet, int maskFormat, GrowableEltArray elts) { + con.XRenderCompositeText(compRule, src.picture, dst.picture, + maskFormat, sx, sy, 0, 0, glyphSet, elts); } public XRColor getMaskColor() { diff --git a/jdk/src/solaris/native/sun/java2d/x11/XRBackendNative.c b/jdk/src/solaris/native/sun/java2d/x11/XRBackendNative.c index 75d1cd2f4d2..cbcf0c357e3 100644 --- a/jdk/src/solaris/native/sun/java2d/x11/XRBackendNative.c +++ b/jdk/src/solaris/native/sun/java2d/x11/XRBackendNative.c @@ -911,8 +911,9 @@ Java_sun_java2d_xr_XRBackendNative_XRenderCreateGlyphSetNative JNIEXPORT void JNICALL Java_sun_java2d_xr_XRBackendNative_XRenderCompositeTextNative - (JNIEnv *env, jclass cls, jint op, jint src, jint dst, jlong maskFmt, - jintArray eltArray, jintArray glyphIDArray, jint eltCnt, jint glyphCnt) { + (JNIEnv *env, jclass cls, jint op, jint src, jint dst, + jint sx, jint sy, jlong maskFmt, jintArray eltArray, + jintArray glyphIDArray, jint eltCnt, jint glyphCnt) { jint i; jint *ids; jint *elts; @@ -991,7 +992,7 @@ Java_sun_java2d_xr_XRBackendNative_XRenderCompositeTextNative XRenderCompositeText32(awt_display, op, (Picture) src, (Picture) dst, (XRenderPictFormat *) jlong_to_ptr(maskFmt), - 0, 0, 0, 0, xelts, eltCnt); + sx, sy, 0, 0, xelts, eltCnt); (*env)->ReleasePrimitiveArrayCritical(env, glyphIDArray, ids, JNI_ABORT); (*env)->ReleasePrimitiveArrayCritical(env, eltArray, elts, JNI_ABORT); From 0fb014c2b3cff00c15e9e7cb6653818d061216e9 Mon Sep 17 00:00:00 2001 From: Paul Sandoz Date: Wed, 4 Sep 2013 09:34:25 +0200 Subject: [PATCH 030/210] 8023463: Improvements to HashMap/LinkedHashMap use of bins/buckets and trees (red/black) 8012913: LinkedHashMap key/value/entry spliterators should report ORDERED Co-authored-by: Doug Lea Reviewed-by: mduigou, forax, bchristi, alanb --- jdk/src/share/classes/java/util/HashMap.java | 4155 +++++++---------- .../classes/java/util/LinkedHashMap.java | 608 ++- .../java/lang/reflect/Generics/Probe.java | 6 +- .../java/util/Map/CheckRandomHashSeed.java | 2 - .../java/util/Map/InPlaceOpsCollisions.java | 1 - .../java/util/Map/MapBinToFromTreeTest.java | 240 + .../util/Map/TreeBinSplitBackToEntries.java | 255 - .../SpliteratorCharacteristics.java | 107 +- 8 files changed, 2429 insertions(+), 2945 deletions(-) create mode 100644 jdk/test/java/util/Map/MapBinToFromTreeTest.java delete mode 100644 jdk/test/java/util/Map/TreeBinSplitBackToEntries.java diff --git a/jdk/src/share/classes/java/util/HashMap.java b/jdk/src/share/classes/java/util/HashMap.java index 8dfafac8642..a6a7d152b5f 100644 --- a/jdk/src/share/classes/java/util/HashMap.java +++ b/jdk/src/share/classes/java/util/HashMap.java @@ -25,13 +25,14 @@ package java.util; -import java.io.*; +import java.io.IOException; +import java.io.InvalidObjectException; +import java.io.Serializable; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; -import java.util.concurrent.ThreadLocalRandom; import java.util.function.BiConsumer; -import java.util.function.Consumer; import java.util.function.BiFunction; +import java.util.function.Consumer; import java.util.function.Function; /** @@ -63,20 +64,25 @@ import java.util.function.Function; * structures are rebuilt) so that the hash table has approximately twice the * number of buckets. * - *

    As a general rule, the default load factor (.75) offers a good tradeoff - * between time and space costs. Higher values decrease the space overhead - * but increase the lookup cost (reflected in most of the operations of the - * HashMap class, including get and put). The - * expected number of entries in the map and its load factor should be taken - * into account when setting its initial capacity, so as to minimize the - * number of rehash operations. If the initial capacity is greater - * than the maximum number of entries divided by the load factor, no - * rehash operations will ever occur. + *

    As a general rule, the default load factor (.75) offers a good + * tradeoff between time and space costs. Higher values decrease the + * space overhead but increase the lookup cost (reflected in most of + * the operations of the HashMap class, including + * get and put). The expected number of entries in + * the map and its load factor should be taken into account when + * setting its initial capacity, so as to minimize the number of + * rehash operations. If the initial capacity is greater than the + * maximum number of entries divided by the load factor, no rehash + * operations will ever occur. * - *

    If many mappings are to be stored in a HashMap instance, - * creating it with a sufficiently large capacity will allow the mappings to - * be stored more efficiently than letting it perform automatic rehashing as - * needed to grow the table. + *

    If many mappings are to be stored in a HashMap + * instance, creating it with a sufficiently large capacity will allow + * the mappings to be stored more efficiently than letting it perform + * automatic rehashing as needed to grow the table. Note that using + * many keys with the same {@code hashCode()} is a sure way to slow + * down performance of any hash table. To ameliorate impact, when keys + * are {@link Comparable}, this class may use comparison order among + * keys to help break ties. * *

    Note that this implementation is not synchronized. * If multiple threads access a hash map concurrently, and at least one of @@ -128,11 +134,100 @@ import java.util.function.Function; * @see Hashtable * @since 1.2 */ +public class HashMap extends AbstractMap + implements Map, Cloneable, Serializable { -public class HashMap - extends AbstractMap - implements Map, Cloneable, Serializable -{ + private static final long serialVersionUID = 362498820763181265L; + + /* + * Implementation notes. + * + * This map usually acts as a binned (bucketed) hash table, but + * when bins get too large, they are transformed into bins of + * TreeNodes, each structured similarly to those in + * java.util.TreeMap. Most methods try to use normal bins, but + * relay to TreeNode methods when applicable (simply by checking + * instanceof a node). Bins of TreeNodes may be traversed and + * used like any others, but additionally support faster lookup + * when overpopulated. However, since the vast majority of bins in + * normal use are not overpopulated, checking for existence of + * tree bins may be delayed in the course of table methods. + * + * Tree bins (i.e., bins whose elements are all TreeNodes) are + * ordered primarily by hashCode, but in the case of ties, if two + * elements are of the same "class C implements Comparable", + * type then their compareTo method is used for ordering. (We + * conservatively check generic types via reflection to validate + * this -- see method comparableClassFor). The added complexity + * of tree bins is worthwhile in providing worst-case O(log n) + * operations when keys either have distinct hashes or are + * orderable, Thus, performance degrades gracefully under + * accidental or malicious usages in which hashCode() methods + * return values that are poorly distributed, as well as those in + * which many keys share a hashCode, so long as they are also + * Comparable. (If neither of these apply, we may waste about a + * factor of two in time and space compared to taking no + * precautions. But the only known cases stem from poor user + * programming practices that are already so slow that this makes + * little difference.) + * + * Because TreeNodes are about twice the size of regular nodes, we + * use them only when bins contain enough nodes to warrant use + * (see TREEIFY_THRESHOLD). And when they become too small (due to + * removal or resizing) they are converted back to plain bins. In + * usages with well-distributed user hashCodes, tree bins are + * rarely used. Ideally, under random hashCodes, the frequency of + * nodes in bins follows a Poisson distribution + * (http://en.wikipedia.org/wiki/Poisson_distribution) with a + * parameter of about 0.5 on average for the default resizing + * threshold of 0.75, although with a large variance because of + * resizing granularity. Ignoring variance, the expected + * occurrences of list size k are (exp(-0.5) * pow(0.5, k) / + * factorial(k)). The first values are: + * + * 0: 0.60653066 + * 1: 0.30326533 + * 2: 0.07581633 + * 3: 0.01263606 + * 4: 0.00157952 + * 5: 0.00015795 + * 6: 0.00001316 + * 7: 0.00000094 + * 8: 0.00000006 + * more: less than 1 in ten million + * + * The root of a tree bin is normally its first node. However, + * sometimes (currently only upon Iterator.remove), the root might + * be elsewhere, but can be recovered following parent links + * (method TreeNode.root()). + * + * All applicable internal methods accept a hash code as an + * argument (as normally supplied from a public method), allowing + * them to call each other without recomputing user hashCodes. + * Most internal methods also accept a "tab" argument, that is + * normally the current table, but may be a new or old one when + * resizing or converting. + * + * When bin lists are treeified, split, or untreeified, we keep + * them in the same relative access/traversal order (i.e., field + * Node.next) to better preserve locality, and to slightly + * simplify handling of splits and traversals that invoke + * iterator.remove. When using comparators on insertion, to keep a + * total ordering (or as close as is required here) across + * rebalancings, we compare classes and identityHashCodes as + * tie-breakers. + * + * The use and transitions among plain vs tree modes is + * complicated by the existence of subclass LinkedHashMap. See + * below for hook methods defined to be invoked upon insertion, + * removal and access that allow LinkedHashMap internals to + * otherwise remain independent of these mechanics. (This also + * requires that a map instance be passed to some utility methods + * that may create new nodes.) + * + * The concurrent-programming-like SSA-based coding style helps + * avoid aliasing errors amid all of the twisty pointer operations. + */ /** * The default initial capacity - MUST be a power of two. @@ -152,35 +247,164 @@ public class HashMap static final float DEFAULT_LOAD_FACTOR = 0.75f; /** - * An empty table instance to share when the table is not inflated. + * The bin count threshold for using a tree rather than list for a + * bin. Bins are converted to trees when adding an element to a + * bin with at least this many nodes. The value must be greater + * than 2 and should be at least 8 to mesh with assumptions in + * tree removal about conversion back to plain bins upon + * shrinkage. */ - static final Object[] EMPTY_TABLE = {}; + static final int TREEIFY_THRESHOLD = 8; /** - * The table, resized as necessary. Length MUST Always be a power of two. + * The bin count threshold for untreeifying a (split) bin during a + * resize operation. Should be less than TREEIFY_THRESHOLD, and at + * most 6 to mesh with shrinkage detection under removal. */ - transient Object[] table = EMPTY_TABLE; + static final int UNTREEIFY_THRESHOLD = 6; + + /** + * The smallest table capacity for which bins may be treeified. + * (Otherwise the table is resized if too many nodes in a bin.) + * Should be at least 4 * TREEIFY_THRESHOLD to avoid conflicts + * between resizing and treeification thresholds. + */ + static final int MIN_TREEIFY_CAPACITY = 64; + + /** + * Basic hash bin node, used for most entries. (See below for + * TreeNode subclass, and in LinkedHashMap for its Entry subclass.) + */ + static class Node implements Map.Entry { + final int hash; + final K key; + V value; + Node next; + + Node(int hash, K key, V value, Node next) { + this.hash = hash; + this.key = key; + this.value = value; + this.next = next; + } + + public final K getKey() { return key; } + public final V getValue() { return value; } + public final String toString() { return key + "=" + value; } + + public final int hashCode() { + return Objects.hashCode(key) ^ Objects.hashCode(value); + } + + public final V setValue(V newValue) { + V oldValue = value; + value = newValue; + return oldValue; + } + + public final boolean equals(Object o) { + if (o == this) + return true; + if (o instanceof Map.Entry) { + Map.Entry e = (Map.Entry)o; + if (Objects.equals(key, e.getKey()) && + Objects.equals(value, e.getValue())) + return true; + } + return false; + } + } + + /* ---------------- Static utilities -------------- */ + + /** + * Computes key.hashCode() and spreads (XORs) higher bits of hash + * to lower. Because the table uses power-of-two masking, sets of + * hashes that vary only in bits above the current mask will + * always collide. (Among known examples are sets of Float keys + * holding consecutive whole numbers in small tables.) So we + * apply a transform that spreads the impact of higher bits + * downward. There is a tradeoff between speed, utility, and + * quality of bit-spreading. Because many common sets of hashes + * are already reasonably distributed (so don't benefit from + * spreading), and because we use trees to handle large sets of + * collisions in bins, we just XOR some shifted bits in the + * cheapest possible way to reduce systematic lossage, as well as + * to incorporate impact of the highest bits that would otherwise + * never be used in index calculations because of table bounds. + */ + static final int hash(Object key) { + int h; + return (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16); + } + + /** + * Returns x's Class if it is of the form "class C implements + * Comparable", else null. + */ + static Class comparableClassFor(Object x) { + if (x instanceof Comparable) { + Class c; Type[] ts, as; Type t; ParameterizedType p; + if ((c = x.getClass()) == String.class) // bypass checks + return c; + if ((ts = c.getGenericInterfaces()) != null) { + for (int i = 0; i < ts.length; ++i) { + if (((t = ts[i]) instanceof ParameterizedType) && + ((p = (ParameterizedType)t).getRawType() == + Comparable.class) && + (as = p.getActualTypeArguments()) != null && + as.length == 1 && as[0] == c) // type arg is c + return c; + } + } + } + return null; + } + + /** + * Returns k.compareTo(x) if x matches kc (k's screened comparable + * class), else 0. + */ + @SuppressWarnings({"rawtypes","unchecked"}) // for cast to Comparable + static int compareComparables(Class kc, Object k, Object x) { + return (x == null || x.getClass() != kc ? 0 : + ((Comparable)k).compareTo(x)); + } + + /** + * Returns a power of two size for the given target capacity. + */ + static final int tableSizeFor(int cap) { + int n = cap - 1; + n |= n >>> 1; + n |= n >>> 2; + n |= n >>> 4; + n |= n >>> 8; + n |= n >>> 16; + return (n < 0) ? 1 : (n >= MAXIMUM_CAPACITY) ? MAXIMUM_CAPACITY : n + 1; + } + + /* ---------------- Fields -------------- */ + + /** + * The table, initialized on first use, and resized as + * necessary. When allocated, length is always a power of two. + * (We also tolerate length zero in some operations to allow + * bootstrapping mechanics that are currently not needed.) + */ + transient Node[] table; + + /** + * Holds cached entrySet(). Note that AbstractMap fields are used + * for keySet() and values(). + */ + transient Set> entrySet; /** * The number of key-value mappings contained in this map. */ transient int size; - /** - * The next size value at which to resize (capacity * load factor). - * @serial - */ - // If table == EMPTY_TABLE then this is the initial capacity at which the - // table will be created when inflated. - int threshold; - - /** - * The load factor for the hash table. - * - * @serial - */ - final float loadFactor; - /** * The number of times this HashMap has been structurally modified * Structural modifications are those that change the number of mappings in @@ -191,627 +415,24 @@ public class HashMap transient int modCount; /** - * Holds values which can't be initialized until after VM is booted. - */ - private static class Holder { - static final sun.misc.Unsafe UNSAFE; - - /** - * Offset of "final" hashSeed field we must set in - * readObject() method. - */ - static final long HASHSEED_OFFSET; - - static final boolean USE_HASHSEED; - - static { - String hashSeedProp = java.security.AccessController.doPrivileged( - new sun.security.action.GetPropertyAction( - "jdk.map.useRandomSeed")); - boolean localBool = (null != hashSeedProp) - ? Boolean.parseBoolean(hashSeedProp) : false; - USE_HASHSEED = localBool; - - if (USE_HASHSEED) { - try { - UNSAFE = sun.misc.Unsafe.getUnsafe(); - HASHSEED_OFFSET = UNSAFE.objectFieldOffset( - HashMap.class.getDeclaredField("hashSeed")); - } catch (NoSuchFieldException | SecurityException e) { - throw new InternalError("Failed to record hashSeed offset", e); - } - } else { - UNSAFE = null; - HASHSEED_OFFSET = 0; - } - } - } - - /* - * A randomizing value associated with this instance that is applied to - * hash code of keys to make hash collisions harder to find. + * The next size value at which to resize (capacity * load factor). * - * Non-final so it can be set lazily, but be sure not to set more than once. + * @serial */ - transient final int hashSeed; - - /* - * TreeBin/TreeNode code from CHM doesn't handle the null key. Store the - * null key entry here. - */ - transient Entry nullKeyEntry = null; - - /* - * In order to improve performance under high hash-collision conditions, - * HashMap will switch to storing a bin's entries in a balanced tree - * (TreeBin) instead of a linked-list once the number of entries in the bin - * passes a certain threshold (TreeBin.TREE_THRESHOLD), if at least one of - * the keys in the bin implements Comparable. This technique is borrowed - * from ConcurrentHashMap. - */ - - /* - * Code based on CHMv8 - * - * Node type for TreeBin - */ - final static class TreeNode { - TreeNode parent; // red-black tree links - TreeNode left; - TreeNode right; - TreeNode prev; // needed to unlink next upon deletion - boolean red; - final HashMap.Entry entry; - - TreeNode(HashMap.Entry entry, Object next, TreeNode parent) { - this.entry = entry; - this.entry.next = next; - this.parent = parent; - } - } + // (The javadoc description is true upon serialization. + // Additionally, if the table array has not been allocated, this + // field holds the initial array capacity, or zero signifying + // DEFAULT_INITIAL_CAPACITY.) + int threshold; /** - * Returns a Class for the given object of the form "class C - * implements Comparable", if one exists, else null. See the TreeBin - * docs, below, for explanation. - */ - static Class comparableClassFor(Object x) { - Class c, s, cmpc; Type[] ts, as; Type t; ParameterizedType p; - if ((c = x.getClass()) == String.class) // bypass checks - return c; - if ((cmpc = Comparable.class).isAssignableFrom(c)) { - while (cmpc.isAssignableFrom(s = c.getSuperclass())) - c = s; // find topmost comparable class - if ((ts = c.getGenericInterfaces()) != null) { - for (int i = 0; i < ts.length; ++i) { - if (((t = ts[i]) instanceof ParameterizedType) && - ((p = (ParameterizedType)t).getRawType() == cmpc) && - (as = p.getActualTypeArguments()) != null && - as.length == 1 && as[0] == c) // type arg is c - return c; - } - } - } - return null; - } - - /* - * Code based on CHMv8 + * The load factor for the hash table. * - * A specialized form of red-black tree for use in bins - * whose size exceeds a threshold. - * - * TreeBins use a special form of comparison for search and - * related operations (which is the main reason we cannot use - * existing collections such as TreeMaps). TreeBins contain - * Comparable elements, but may contain others, as well as - * elements that are Comparable but not necessarily Comparable - * for the same T, so we cannot invoke compareTo among them. To - * handle this, the tree is ordered primarily by hash value, then - * by Comparable.compareTo order if applicable. On lookup at a - * node, if elements are not comparable or compare as 0 then both - * left and right children may need to be searched in the case of - * tied hash values. (This corresponds to the full list search - * that would be necessary if all elements were non-Comparable and - * had tied hashes.) The red-black balancing code is updated from - * pre-jdk-collections - * (http://gee.cs.oswego.edu/dl/classes/collections/RBCell.java) - * based in turn on Cormen, Leiserson, and Rivest "Introduction to - * Algorithms" (CLR). + * @serial */ - final class TreeBin { - /* - * The bin count threshold for using a tree rather than list for a bin. The - * value reflects the approximate break-even point for using tree-based - * operations. - */ - static final int TREE_THRESHOLD = 16; + final float loadFactor; - TreeNode root; // root of tree - TreeNode first; // head of next-pointer list - - /* - * Split a TreeBin into lo and hi parts and install in given table. - * - * Existing Entrys are re-used, which maintains the before/after links for - * LinkedHashMap.Entry. - * - * No check for Comparable, though this is the same as CHM. - */ - final void splitTreeBin(Object[] newTable, int i, TreeBin loTree, TreeBin hiTree) { - TreeBin oldTree = this; - int bit = newTable.length >>> 1; - int loCount = 0, hiCount = 0; - TreeNode e = oldTree.first; - TreeNode next; - - // This method is called when the table has just increased capacity, - // so indexFor() is now taking one additional bit of hash into - // account ("bit"). Entries in this TreeBin now belong in one of - // two bins, "i" or "i+bit", depending on if the new top bit of the - // hash is set. The trees for the two bins are loTree and hiTree. - // If either tree ends up containing fewer than TREE_THRESHOLD - // entries, it is converted back to a linked list. - while (e != null) { - // Save entry.next - it will get overwritten in putTreeNode() - next = (TreeNode)e.entry.next; - - int h = e.entry.hash; - K k = (K) e.entry.key; - V v = e.entry.value; - if ((h & bit) == 0) { - ++loCount; - // Re-using e.entry - loTree.putTreeNode(h, k, v, e.entry); - } else { - ++hiCount; - hiTree.putTreeNode(h, k, v, e.entry); - } - // Iterate using the saved 'next' - e = next; - } - if (loCount < TREE_THRESHOLD) { // too small, convert back to list - HashMap.Entry loEntry = null; - TreeNode p = loTree.first; - while (p != null) { - @SuppressWarnings("unchecked") - TreeNode savedNext = (TreeNode) p.entry.next; - p.entry.next = loEntry; - loEntry = p.entry; - p = savedNext; - } - // assert newTable[i] == null; - newTable[i] = loEntry; - } else { - // assert newTable[i] == null; - newTable[i] = loTree; - } - if (hiCount < TREE_THRESHOLD) { // too small, convert back to list - HashMap.Entry hiEntry = null; - TreeNode p = hiTree.first; - while (p != null) { - @SuppressWarnings("unchecked") - TreeNode savedNext = (TreeNode) p.entry.next; - p.entry.next = hiEntry; - hiEntry = p.entry; - p = savedNext; - } - // assert newTable[i + bit] == null; - newTable[i + bit] = hiEntry; - } else { - // assert newTable[i + bit] == null; - newTable[i + bit] = hiTree; - } - } - - /* - * Popuplate the TreeBin with entries from the linked list e - * - * Assumes 'this' is a new/empty TreeBin - * - * Note: no check for Comparable - * Note: I believe this changes iteration order - */ - @SuppressWarnings("unchecked") - void populate(HashMap.Entry e) { - // assert root == null; - // assert first == null; - HashMap.Entry next; - while (e != null) { - // Save entry.next - it will get overwritten in putTreeNode() - next = (HashMap.Entry)e.next; - // Re-using Entry e will maintain before/after in LinkedHM - putTreeNode(e.hash, (K)e.key, (V)e.value, e); - // Iterate using the saved 'next' - e = next; - } - } - - /** - * Copied from CHMv8 - * From CLR - */ - private void rotateLeft(TreeNode p) { - if (p != null) { - TreeNode r = p.right, pp, rl; - if ((rl = p.right = r.left) != null) { - rl.parent = p; - } - if ((pp = r.parent = p.parent) == null) { - root = r; - } else if (pp.left == p) { - pp.left = r; - } else { - pp.right = r; - } - r.left = p; - p.parent = r; - } - } - - /** - * Copied from CHMv8 - * From CLR - */ - private void rotateRight(TreeNode p) { - if (p != null) { - TreeNode l = p.left, pp, lr; - if ((lr = p.left = l.right) != null) { - lr.parent = p; - } - if ((pp = l.parent = p.parent) == null) { - root = l; - } else if (pp.right == p) { - pp.right = l; - } else { - pp.left = l; - } - l.right = p; - p.parent = l; - } - } - - /** - * Returns the TreeNode (or null if not found) for the given - * key. A front-end for recursive version. - */ - final TreeNode getTreeNode(int h, K k) { - return getTreeNode(h, k, root, comparableClassFor(k)); - } - - /** - * Returns the TreeNode (or null if not found) for the given key - * starting at given root. - */ - @SuppressWarnings("unchecked") - final TreeNode getTreeNode (int h, K k, TreeNode p, Class cc) { - // assert k != null; - while (p != null) { - int dir, ph; Object pk; - if ((ph = p.entry.hash) != h) - dir = (h < ph) ? -1 : 1; - else if ((pk = p.entry.key) == k || k.equals(pk)) - return p; - else if (cc == null || comparableClassFor(pk) != cc || - (dir = ((Comparable)k).compareTo(pk)) == 0) { - // assert pk != null; - TreeNode r, pl, pr; // check both sides - if ((pr = p.right) != null && - (r = getTreeNode(h, k, pr, cc)) != null) - return r; - else if ((pl = p.left) != null) - dir = -1; - else // nothing there - break; - } - p = (dir > 0) ? p.right : p.left; - } - return null; - } - - /* - * Finds or adds a node. - * - * 'entry' should be used to recycle an existing Entry (e.g. in the case - * of converting a linked-list bin to a TreeBin). - * If entry is null, a new Entry will be created for the new TreeNode - * - * @return the TreeNode containing the mapping, or null if a new - * TreeNode was added - */ - @SuppressWarnings("unchecked") - TreeNode putTreeNode(int h, K k, V v, HashMap.Entry entry) { - // assert k != null; - //if (entry != null) { - // assert h == entry.hash; - // assert k == entry.key; - // assert v == entry.value; - // } - Class cc = comparableClassFor(k); - TreeNode pp = root, p = null; - int dir = 0; - while (pp != null) { // find existing node or leaf to insert at - int ph; Object pk; - p = pp; - if ((ph = p.entry.hash) != h) - dir = (h < ph) ? -1 : 1; - else if ((pk = p.entry.key) == k || k.equals(pk)) - return p; - else if (cc == null || comparableClassFor(pk) != cc || - (dir = ((Comparable)k).compareTo(pk)) == 0) { - TreeNode r, pr; - if ((pr = p.right) != null && - (r = getTreeNode(h, k, pr, cc)) != null) - return r; - else // continue left - dir = -1; - } - pp = (dir > 0) ? p.right : p.left; - } - - // Didn't find the mapping in the tree, so add it - TreeNode f = first; - TreeNode x; - if (entry != null) { - x = new TreeNode(entry, f, p); - } else { - x = new TreeNode(newEntry(h, k, v, null), f, p); - } - first = x; - - if (p == null) { - root = x; - } else { // attach and rebalance; adapted from CLR - TreeNode xp, xpp; - if (f != null) { - f.prev = x; - } - if (dir <= 0) { - p.left = x; - } else { - p.right = x; - } - x.red = true; - while (x != null && (xp = x.parent) != null && xp.red - && (xpp = xp.parent) != null) { - TreeNode xppl = xpp.left; - if (xp == xppl) { - TreeNode y = xpp.right; - if (y != null && y.red) { - y.red = false; - xp.red = false; - xpp.red = true; - x = xpp; - } else { - if (x == xp.right) { - rotateLeft(x = xp); - xpp = (xp = x.parent) == null ? null : xp.parent; - } - if (xp != null) { - xp.red = false; - if (xpp != null) { - xpp.red = true; - rotateRight(xpp); - } - } - } - } else { - TreeNode y = xppl; - if (y != null && y.red) { - y.red = false; - xp.red = false; - xpp.red = true; - x = xpp; - } else { - if (x == xp.left) { - rotateRight(x = xp); - xpp = (xp = x.parent) == null ? null : xp.parent; - } - if (xp != null) { - xp.red = false; - if (xpp != null) { - xpp.red = true; - rotateLeft(xpp); - } - } - } - } - } - TreeNode r = root; - if (r != null && r.red) { - r.red = false; - } - } - return null; - } - - /* - * From CHMv8 - * - * Removes the given node, that must be present before this - * call. This is messier than typical red-black deletion code - * because we cannot swap the contents of an interior node - * with a leaf successor that is pinned by "next" pointers - * that are accessible independently of lock. So instead we - * swap the tree linkages. - */ - final void deleteTreeNode(TreeNode p) { - TreeNode next = (TreeNode) p.entry.next; // unlink traversal pointers - TreeNode pred = p.prev; - if (pred == null) { - first = next; - } else { - pred.entry.next = next; - } - if (next != null) { - next.prev = pred; - } - TreeNode replacement; - TreeNode pl = p.left; - TreeNode pr = p.right; - if (pl != null && pr != null) { - TreeNode s = pr, sl; - while ((sl = s.left) != null) // find successor - { - s = sl; - } - boolean c = s.red; - s.red = p.red; - p.red = c; // swap colors - TreeNode sr = s.right; - TreeNode pp = p.parent; - if (s == pr) { // p was s's direct parent - p.parent = s; - s.right = p; - } else { - TreeNode sp = s.parent; - if ((p.parent = sp) != null) { - if (s == sp.left) { - sp.left = p; - } else { - sp.right = p; - } - } - if ((s.right = pr) != null) { - pr.parent = s; - } - } - p.left = null; - if ((p.right = sr) != null) { - sr.parent = p; - } - if ((s.left = pl) != null) { - pl.parent = s; - } - if ((s.parent = pp) == null) { - root = s; - } else if (p == pp.left) { - pp.left = s; - } else { - pp.right = s; - } - replacement = sr; - } else { - replacement = (pl != null) ? pl : pr; - } - TreeNode pp = p.parent; - if (replacement == null) { - if (pp == null) { - root = null; - return; - } - replacement = p; - } else { - replacement.parent = pp; - if (pp == null) { - root = replacement; - } else if (p == pp.left) { - pp.left = replacement; - } else { - pp.right = replacement; - } - p.left = p.right = p.parent = null; - } - if (!p.red) { // rebalance, from CLR - TreeNode x = replacement; - while (x != null) { - TreeNode xp, xpl; - if (x.red || (xp = x.parent) == null) { - x.red = false; - break; - } - if (x == (xpl = xp.left)) { - TreeNode sib = xp.right; - if (sib != null && sib.red) { - sib.red = false; - xp.red = true; - rotateLeft(xp); - sib = (xp = x.parent) == null ? null : xp.right; - } - if (sib == null) { - x = xp; - } else { - TreeNode sl = sib.left, sr = sib.right; - if ((sr == null || !sr.red) - && (sl == null || !sl.red)) { - sib.red = true; - x = xp; - } else { - if (sr == null || !sr.red) { - if (sl != null) { - sl.red = false; - } - sib.red = true; - rotateRight(sib); - sib = (xp = x.parent) == null ? - null : xp.right; - } - if (sib != null) { - sib.red = (xp == null) ? false : xp.red; - if ((sr = sib.right) != null) { - sr.red = false; - } - } - if (xp != null) { - xp.red = false; - rotateLeft(xp); - } - x = root; - } - } - } else { // symmetric - TreeNode sib = xpl; - if (sib != null && sib.red) { - sib.red = false; - xp.red = true; - rotateRight(xp); - sib = (xp = x.parent) == null ? null : xp.left; - } - if (sib == null) { - x = xp; - } else { - TreeNode sl = sib.left, sr = sib.right; - if ((sl == null || !sl.red) - && (sr == null || !sr.red)) { - sib.red = true; - x = xp; - } else { - if (sl == null || !sl.red) { - if (sr != null) { - sr.red = false; - } - sib.red = true; - rotateLeft(sib); - sib = (xp = x.parent) == null ? - null : xp.left; - } - if (sib != null) { - sib.red = (xp == null) ? false : xp.red; - if ((sl = sib.left) != null) { - sl.red = false; - } - } - if (xp != null) { - xp.red = false; - rotateRight(xp); - } - x = root; - } - } - } - } - } - if (p == replacement && (pp = p.parent) != null) { - if (p == pp.left) // detach pointers - { - pp.left = null; - } else if (p == pp.right) { - pp.right = null; - } - p.parent = null; - } - } - } + /* ---------------- Public operations -------------- */ /** * Constructs an empty HashMap with the specified initial @@ -832,9 +453,7 @@ public class HashMap throw new IllegalArgumentException("Illegal load factor: " + loadFactor); this.loadFactor = loadFactor; - threshold = initialCapacity; - hashSeed = initHashSeed(); - init(); + this.threshold = tableSizeFor(initialCapacity); } /** @@ -853,7 +472,7 @@ public class HashMap * (16) and the default load factor (0.75). */ public HashMap() { - this(DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR); + this.loadFactor = DEFAULT_LOAD_FACTOR; // all other fields defaulted } /** @@ -866,79 +485,35 @@ public class HashMap * @throws NullPointerException if the specified map is null */ public HashMap(Map m) { - this(Math.max((int) (m.size() / DEFAULT_LOAD_FACTOR) + 1, - DEFAULT_INITIAL_CAPACITY), DEFAULT_LOAD_FACTOR); - inflateTable(threshold); - - putAllForCreate(m); - // assert size == m.size(); - } - - private static int roundUpToPowerOf2(int number) { - // assert number >= 0 : "number must be non-negative"; - return number >= MAXIMUM_CAPACITY - ? MAXIMUM_CAPACITY - : (number > 1) ? Integer.highestOneBit((number - 1) << 1) : 1; + this.loadFactor = DEFAULT_LOAD_FACTOR; + putMapEntries(m, false); } /** - * Inflates the table. + * Implements Map.putAll and Map constructor + * + * @param m the map + * @param evict false when initially constructing this map, else + * true (relayed to method afterNodeInsertion). */ - private void inflateTable(int toSize) { - // Find a power of 2 >= toSize - int capacity = roundUpToPowerOf2(toSize); - - threshold = (int) Math.min(capacity * loadFactor, MAXIMUM_CAPACITY + 1); - table = new Object[capacity]; - } - - // internal utilities - - /** - * Initialization hook for subclasses. This method is called - * in all constructors and pseudo-constructors (clone, readObject) - * after HashMap has been initialized but before any entries have - * been inserted. (In the absence of this method, readObject would - * require explicit knowledge of subclasses.) - */ - void init() { - } - - /** - * Return an initial value for the hashSeed, or 0 if the random seed is not - * enabled. - */ - final int initHashSeed() { - if (sun.misc.VM.isBooted() && Holder.USE_HASHSEED) { - int seed = ThreadLocalRandom.current().nextInt(); - return (seed != 0) ? seed : 1; + final void putMapEntries(Map m, boolean evict) { + int s = m.size(); + if (s > 0) { + if (table == null) { // pre-size + float ft = ((float)s / loadFactor) + 1.0F; + int t = ((ft < (float)MAXIMUM_CAPACITY) ? + (int)ft : MAXIMUM_CAPACITY); + if (t > threshold) + threshold = tableSizeFor(t); + } + else if (s > threshold) + resize(); + for (Map.Entry e : m.entrySet()) { + K key = e.getKey(); + V value = e.getValue(); + putVal(hash(key), key, value, false, evict); + } } - return 0; - } - - /** - * Retrieve object hash code and applies a supplemental hash function to the - * result hash, which defends against poor quality hash functions. This is - * critical because HashMap uses power-of-two length hash tables, that - * otherwise encounter collisions for hashCodes that do not differ - * in lower bits. - */ - final int hash(Object k) { - int h = hashSeed ^ k.hashCode(); - - // This function ensures that hashCodes that differ only by - // constant multiples at each bit position have a bounded - // number of collisions (approximately 8 at default load factor). - h ^= (h >>> 20) ^ (h >>> 12); - return h ^ (h >>> 7) ^ (h >>> 4); - } - - /** - * Returns index for hash code h. - */ - static int indexFor(int h, int length) { - // assert Integer.bitCount(length) == 1 : "length must be a non-zero power of 2"; - return h & (length-1); } /** @@ -976,18 +551,36 @@ public class HashMap * * @see #put(Object, Object) */ - @SuppressWarnings("unchecked") public V get(Object key) { - Entry entry = getEntry(key); - - return null == entry ? null : entry.getValue(); + Node e; + return (e = getNode(hash(key), key)) == null ? null : e.value; } - @Override - public V getOrDefault(Object key, V defaultValue) { - Entry entry = getEntry(key); - - return (entry == null) ? defaultValue : entry.getValue(); + /** + * Implements Map.get and related methods + * + * @param hash hash for key + * @param key the key + * @return the node, or null if none + */ + final Node getNode(int hash, Object key) { + Node[] tab; Node first, e; int n; K k; + if ((tab = table) != null && (n = tab.length) > 0 && + (first = tab[(n - 1) & hash]) != null) { + if (first.hash == hash && // always check first node + ((k = first.key) == key || (key != null && key.equals(k)))) + return first; + if ((e = first.next) != null) { + if (first instanceof TreeNode) + return ((TreeNode)first).getTreeNode(hash, key); + do { + if (e.hash == hash && + ((k = e.key) == key || (key != null && key.equals(k)))) + return e; + } while ((e = e.next) != null); + } + } + return null; } /** @@ -999,48 +592,9 @@ public class HashMap * key. */ public boolean containsKey(Object key) { - return getEntry(key) != null; + return getNode(hash(key), key) != null; } - /** - * Returns the entry associated with the specified key in the - * HashMap. Returns null if the HashMap contains no mapping - * for the key. - */ - @SuppressWarnings("unchecked") - final Entry getEntry(Object key) { - if (size == 0) { - return null; - } - if (key == null) { - return nullKeyEntry; - } - int hash = hash(key); - int bin = indexFor(hash, table.length); - - if (table[bin] instanceof Entry) { - Entry e = (Entry) table[bin]; - for (; e != null; e = (Entry)e.next) { - Object k; - if (e.hash == hash && - ((k = e.key) == key || key.equals(k))) { - return e; - } - } - } else if (table[bin] != null) { - TreeBin e = (TreeBin)table[bin]; - TreeNode p = e.getTreeNode(hash, (K)key); - if (p != null) { - // assert p.entry.hash == hash && p.entry.key.equals(key); - return (Entry)p.entry; - } else { - return null; - } - } - return null; - } - - /** * Associates the specified value with the specified key in this map. * If the map previously contained a mapping for the key, the old @@ -1053,202 +607,169 @@ public class HashMap * (A null return can also indicate that the map * previously associated null with key.) */ - @SuppressWarnings("unchecked") public V put(K key, V value) { - if (table == EMPTY_TABLE) { - inflateTable(threshold); - } - if (key == null) - return putForNullKey(value); - int hash = hash(key); - int i = indexFor(hash, table.length); - boolean checkIfNeedTree = false; // Might we convert bin to a TreeBin? + return putVal(hash(key), key, value, false, true); + } - if (table[i] instanceof Entry) { - // Bin contains ordinary Entries. Search for key in the linked list - // of entries, counting the number of entries. Only check for - // TreeBin conversion if the list size is >= TREE_THRESHOLD. - // (The conversion still may not happen if the table gets resized.) - int listSize = 0; - Entry e = (Entry) table[i]; - for (; e != null; e = (Entry)e.next) { - Object k; - if (e.hash == hash && ((k = e.key) == key || key.equals(k))) { - V oldValue = e.value; - e.value = value; - e.recordAccess(this); - return oldValue; + /** + * Implements Map.put and related methods + * + * @param hash hash for key + * @param key the key + * @param value the value to put + * @param onlyIfAbsent if true, don't change existing value + * @param evict if false, the table is in creation mode. + * @return previous value, or null if none + */ + final V putVal(int hash, K key, V value, boolean onlyIfAbsent, + boolean evict) { + Node[] tab; Node p; int n, i; + if (size > threshold || (tab = table) == null || + (n = tab.length) == 0) + n = (tab = resize()).length; + if ((p = tab[i = (n - 1) & hash]) == null) + tab[i] = newNode(hash, key, value, null); + else { + Node e; K k; + if (p.hash == hash && + ((k = p.key) == key || (key != null && key.equals(k)))) + e = p; + else if (p instanceof TreeNode) + e = ((TreeNode)p).putTreeVal(this, tab, hash, key, value); + else { + for (int binCount = 0; ; ++binCount) { + if ((e = p.next) == null) { + p.next = newNode(hash, key, value, null); + if (binCount >= TREEIFY_THRESHOLD - 1) // -1 for 1st + treeifyBin(tab, hash); + break; + } + if (e.hash == hash && + ((k = e.key) == key || (key != null && key.equals(k)))) + break; + p = e; } - listSize++; } - // Didn't find, so fall through and call addEntry() to add the - // Entry and check for TreeBin conversion. - checkIfNeedTree = listSize >= TreeBin.TREE_THRESHOLD; - } else if (table[i] != null) { - TreeBin e = (TreeBin)table[i]; - TreeNode p = e.putTreeNode(hash, key, value, null); - if (p == null) { // putTreeNode() added a new node - modCount++; - size++; - if (size >= threshold) { - resize(2 * table.length); - } - return null; - } else { // putTreeNode() found an existing node - Entry pEntry = (Entry)p.entry; - V oldVal = pEntry.value; - pEntry.value = value; - pEntry.recordAccess(this); - return oldVal; + if (e != null) { // existing mapping for key + V oldValue = e.value; + if (!onlyIfAbsent || oldValue == null) + e.value = value; + afterNodeAccess(e); + return oldValue; } } - modCount++; - addEntry(hash, key, value, i, checkIfNeedTree); + ++modCount; + ++size; + afterNodeInsertion(evict); return null; } /** - * Offloaded version of put for null keys + * Initializes or doubles table size. If null, allocates in + * accord with initial capacity target held in field threshold. + * Otherwise, because we are using power-of-two expansion, the + * elements from each bin must either stay at same index, or move + * with a power of two offset in the new table. + * + * @return the table */ - private V putForNullKey(V value) { - if (nullKeyEntry != null) { - V oldValue = nullKeyEntry.value; - nullKeyEntry.value = value; - nullKeyEntry.recordAccess(this); - return oldValue; + final Node[] resize() { + Node[] oldTab = table; + int oldCap = (oldTab == null) ? 0 : oldTab.length; + int oldThr = threshold; + int newCap, newThr = 0; + if (oldCap > 0) { + if (oldCap >= MAXIMUM_CAPACITY) { + threshold = Integer.MAX_VALUE; + return oldTab; + } + else if ((newCap = oldCap << 1) < MAXIMUM_CAPACITY && + oldCap >= DEFAULT_INITIAL_CAPACITY) + newThr = oldThr << 1; // double threshold } - modCount++; - size++; // newEntry() skips size++ - nullKeyEntry = newEntry(0, null, value, null); - return null; - } - - private void putForCreateNullKey(V value) { - // Look for preexisting entry for key. This will never happen for - // clone or deserialize. It will only happen for construction if the - // input Map is a sorted map whose ordering is inconsistent w/ equals. - if (nullKeyEntry != null) { - nullKeyEntry.value = value; - } else { - nullKeyEntry = newEntry(0, null, value, null); - size++; + else if (oldThr > 0) // initial capacity was placed in threshold + newCap = oldThr; + else { // zero initial threshold signifies using defaults + newCap = DEFAULT_INITIAL_CAPACITY; + newThr = (int)(DEFAULT_LOAD_FACTOR * DEFAULT_INITIAL_CAPACITY); } - } - - - /** - * This method is used instead of put by constructors and - * pseudoconstructors (clone, readObject). It does not resize the table, - * check for comodification, etc, though it will convert bins to TreeBins - * as needed. It calls createEntry rather than addEntry. - */ - @SuppressWarnings("unchecked") - private void putForCreate(K key, V value) { - if (null == key) { - putForCreateNullKey(value); - return; + if (newThr == 0) { + float ft = (float)newCap * loadFactor; + newThr = (newCap < MAXIMUM_CAPACITY && ft < (float)MAXIMUM_CAPACITY ? + (int)ft : Integer.MAX_VALUE); } - int hash = hash(key); - int i = indexFor(hash, table.length); - boolean checkIfNeedTree = false; // Might we convert bin to a TreeBin? - - /** - * Look for preexisting entry for key. This will never happen for - * clone or deserialize. It will only happen for construction if the - * input Map is a sorted map whose ordering is inconsistent w/ equals. - */ - if (table[i] instanceof Entry) { - int listSize = 0; - Entry e = (Entry) table[i]; - for (; e != null; e = (Entry)e.next) { - Object k; - if (e.hash == hash && ((k = e.key) == key || key.equals(k))) { - e.value = value; - return; + threshold = newThr; + @SuppressWarnings({"rawtypes","unchecked"}) + Node[] newTab = (Node[])new Node[newCap]; + table = newTab; + if (oldTab != null) { + for (int j = 0; j < oldCap; ++j) { + Node e; + if ((e = oldTab[j]) != null) { + oldTab[j] = null; + if (e.next == null) + newTab[e.hash & (newCap - 1)] = e; + else if (e instanceof TreeNode) + ((TreeNode)e).split(this, newTab, j, oldCap); + else { // preserve order + Node loHead = null, loTail = null; + Node hiHead = null, hiTail = null; + Node next; + do { + next = e.next; + if ((e.hash & oldCap) == 0) { + if (loTail == null) + loHead = e; + else + loTail.next = e; + loTail = e; + } + else { + if (hiTail == null) + hiHead = e; + else + hiTail.next = e; + hiTail = e; + } + } while ((e = next) != null); + if (loTail != null) { + loTail.next = null; + newTab[j] = loHead; + } + if (hiTail != null) { + hiTail.next = null; + newTab[j + oldCap] = hiHead; + } + } } - listSize++; } - // Didn't find, fall through to createEntry(). - // Check for conversion to TreeBin done via createEntry(). - checkIfNeedTree = listSize >= TreeBin.TREE_THRESHOLD; - } else if (table[i] != null) { - TreeBin e = (TreeBin)table[i]; - TreeNode p = e.putTreeNode(hash, key, value, null); - if (p != null) { - p.entry.setValue(value); // Found an existing node, set value - } else { - size++; // Added a new TreeNode, so update size - } - // don't need modCount++/check for resize - just return - return; } - - createEntry(hash, key, value, i, checkIfNeedTree); - } - - private void putAllForCreate(Map m) { - for (Map.Entry e : m.entrySet()) - putForCreate(e.getKey(), e.getValue()); + return newTab; } /** - * Rehashes the contents of this map into a new array with a - * larger capacity. This method is called automatically when the - * number of keys in this map reaches its threshold. - * - * If current capacity is MAXIMUM_CAPACITY, this method does not - * resize the map, but sets threshold to Integer.MAX_VALUE. - * This has the effect of preventing future calls. - * - * @param newCapacity the new capacity, MUST be a power of two; - * must be greater than current capacity unless current - * capacity is MAXIMUM_CAPACITY (in which case value - * is irrelevant). + * Replaces all linked nodes in bin at index for given hash unless + * table is too small, in which case resizes instead. */ - void resize(int newCapacity) { - Object[] oldTable = table; - int oldCapacity = oldTable.length; - if (oldCapacity == MAXIMUM_CAPACITY) { - threshold = Integer.MAX_VALUE; - return; - } - - Object[] newTable = new Object[newCapacity]; - transfer(newTable); - table = newTable; - threshold = (int)Math.min(newCapacity * loadFactor, MAXIMUM_CAPACITY + 1); - } - - /** - * Transfers all entries from current table to newTable. - * - * Assumes newTable is larger than table - */ - @SuppressWarnings("unchecked") - void transfer(Object[] newTable) { - Object[] src = table; - // assert newTable.length > src.length : "newTable.length(" + - // newTable.length + ") expected to be > src.length("+src.length+")"; - int newCapacity = newTable.length; - for (int j = 0; j < src.length; j++) { - if (src[j] instanceof Entry) { - // Assume: since wasn't TreeBin before, won't need TreeBin now - Entry e = (Entry) src[j]; - while (null != e) { - Entry next = (Entry)e.next; - int i = indexFor(e.hash, newCapacity); - e.next = (Entry) newTable[i]; - newTable[i] = e; - e = next; + final void treeifyBin(Node[] tab, int hash) { + int n, index; Node e; + if (tab == null || (n = tab.length) < MIN_TREEIFY_CAPACITY) + resize(); + else if ((e = tab[index = (n - 1) & hash]) != null) { + TreeNode hd = null, tl = null; + do { + TreeNode p = replacementTreeNode(e, null); + if (tl == null) + hd = p; + else { + p.prev = tl; + tl.next = p; } - } else if (src[j] != null) { - TreeBin e = (TreeBin) src[j]; - TreeBin loTree = new TreeBin(); - TreeBin hiTree = new TreeBin(); - e.splitTreeBin(newTable, j, loTree, hiTree); - } + tl = p; + } while ((e = e.next) != null); + if ((tab[index] = hd) != null) + hd.treeify(tab); } - Arrays.fill(table, null); } /** @@ -1260,30 +781,8 @@ public class HashMap * @throws NullPointerException if the specified map is null */ public void putAll(Map m) { - int numKeysToBeAdded = m.size(); - if (numKeysToBeAdded == 0) - return; - - if (table == EMPTY_TABLE) { - inflateTable((int) Math.max(numKeysToBeAdded * loadFactor, threshold)); - } - - /* - * Expand the map if the map if the number of mappings to be added - * is greater than or equal to threshold. This is conservative; the - * obvious condition is (m.size() + size) >= threshold, but this - * condition could result in a map with twice the appropriate capacity, - * if the keys to be added overlap with the keys already in this map. - * By using the conservative calculation, we subject ourself - * to at most one extra resize. - */ - if (numKeysToBeAdded > threshold && table.length < MAXIMUM_CAPACITY) { - resize(table.length * 2); - } - - for (Map.Entry e : m.entrySet()) - put(e.getKey(), e.getValue()); - } + putMapEntries(m, true); + } /** * Removes the mapping for the specified key from this map if present. @@ -1295,834 +794,74 @@ public class HashMap * previously associated null with key.) */ public V remove(Object key) { - Entry e = removeEntryForKey(key); - return (e == null ? null : e.value); - } - - // optimized implementations of default methods in Map - - @Override - public void forEach(BiConsumer action) { - Objects.requireNonNull(action); - final int expectedModCount = modCount; - if (nullKeyEntry != null) { - forEachNullKey(expectedModCount, action); - } - Object[] tab = this.table; - for (int index = 0; index < tab.length; index++) { - Object item = tab[index]; - if (item == null) { - continue; - } - if (item instanceof HashMap.TreeBin) { - eachTreeNode(expectedModCount, ((TreeBin)item).first, action); - continue; - } - @SuppressWarnings("unchecked") - Entry entry = (Entry)item; - while (entry != null) { - action.accept(entry.key, entry.value); - entry = (Entry)entry.next; - - if (expectedModCount != modCount) { - throw new ConcurrentModificationException(); - } - } - } - } - - private void eachTreeNode(int expectedModCount, TreeNode node, BiConsumer action) { - while (node != null) { - @SuppressWarnings("unchecked") - Entry entry = (Entry)node.entry; - action.accept(entry.key, entry.value); - node = (TreeNode)entry.next; - - if (expectedModCount != modCount) { - throw new ConcurrentModificationException(); - } - } - } - - private void forEachNullKey(int expectedModCount, BiConsumer action) { - action.accept(null, nullKeyEntry.value); - - if (expectedModCount != modCount) { - throw new ConcurrentModificationException(); - } - } - - @Override - public void replaceAll(BiFunction function) { - Objects.requireNonNull(function); - final int expectedModCount = modCount; - if (nullKeyEntry != null) { - replaceforNullKey(expectedModCount, function); - } - Object[] tab = this.table; - for (int index = 0; index < tab.length; index++) { - Object item = tab[index]; - if (item == null) { - continue; - } - if (item instanceof HashMap.TreeBin) { - replaceEachTreeNode(expectedModCount, ((TreeBin)item).first, function); - continue; - } - @SuppressWarnings("unchecked") - Entry entry = (Entry)item; - while (entry != null) { - entry.value = function.apply(entry.key, entry.value); - entry = (Entry)entry.next; - - if (expectedModCount != modCount) { - throw new ConcurrentModificationException(); - } - } - } - } - - private void replaceEachTreeNode(int expectedModCount, TreeNode node, BiFunction function) { - while (node != null) { - @SuppressWarnings("unchecked") - Entry entry = (Entry)node.entry; - entry.value = function.apply(entry.key, entry.value); - node = (TreeNode)entry.next; - - if (expectedModCount != modCount) { - throw new ConcurrentModificationException(); - } - } - } - - private void replaceforNullKey(int expectedModCount, BiFunction function) { - nullKeyEntry.value = function.apply(null, nullKeyEntry.value); - - if (expectedModCount != modCount) { - throw new ConcurrentModificationException(); - } - } - - @Override - public V putIfAbsent(K key, V value) { - if (table == EMPTY_TABLE) { - inflateTable(threshold); - } - if (key == null) { - if (nullKeyEntry == null || nullKeyEntry.value == null) { - putForNullKey(value); - return null; - } else { - return nullKeyEntry.value; - } - } - int hash = hash(key); - int i = indexFor(hash, table.length); - boolean checkIfNeedTree = false; // Might we convert bin to a TreeBin? - - if (table[i] instanceof Entry) { - int listSize = 0; - Entry e = (Entry) table[i]; - for (; e != null; e = (Entry)e.next) { - if (e.hash == hash && Objects.equals(e.key, key)) { - if (e.value != null) { - return e.value; - } - e.value = value; - e.recordAccess(this); - return null; - } - listSize++; - } - // Didn't find, so fall through and call addEntry() to add the - // Entry and check for TreeBin conversion. - checkIfNeedTree = listSize >= TreeBin.TREE_THRESHOLD; - } else if (table[i] != null) { - TreeBin e = (TreeBin)table[i]; - TreeNode p = e.putTreeNode(hash, key, value, null); - if (p == null) { // not found, putTreeNode() added a new node - modCount++; - size++; - if (size >= threshold) { - resize(2 * table.length); - } - return null; - } else { // putTreeNode() found an existing node - Entry pEntry = (Entry)p.entry; - V oldVal = pEntry.value; - if (oldVal == null) { // only replace if maps to null - pEntry.value = value; - pEntry.recordAccess(this); - } - return oldVal; - } - } - modCount++; - addEntry(hash, key, value, i, checkIfNeedTree); - return null; - } - - @Override - public boolean remove(Object key, Object value) { - if (size == 0) { - return false; - } - if (key == null) { - if (nullKeyEntry != null && - Objects.equals(nullKeyEntry.value, value)) { - removeNullKey(); - return true; - } - return false; - } - int hash = hash(key); - int i = indexFor(hash, table.length); - - if (table[i] instanceof Entry) { - @SuppressWarnings("unchecked") - Entry prev = (Entry) table[i]; - Entry e = prev; - while (e != null) { - @SuppressWarnings("unchecked") - Entry next = (Entry) e.next; - if (e.hash == hash && Objects.equals(e.key, key)) { - if (!Objects.equals(e.value, value)) { - return false; - } - modCount++; - size--; - if (prev == e) - table[i] = next; - else - prev.next = next; - e.recordRemoval(this); - return true; - } - prev = e; - e = next; - } - } else if (table[i] != null) { - TreeBin tb = ((TreeBin) table[i]); - TreeNode p = tb.getTreeNode(hash, (K)key); - if (p != null) { - Entry pEntry = (Entry)p.entry; - // assert pEntry.key.equals(key); - if (Objects.equals(pEntry.value, value)) { - modCount++; - size--; - tb.deleteTreeNode(p); - pEntry.recordRemoval(this); - if (tb.root == null || tb.first == null) { - // assert tb.root == null && tb.first == null : - // "TreeBin.first and root should both be null"; - // TreeBin is now empty, we should blank this bin - table[i] = null; - } - return true; - } - } - } - return false; - } - - @Override - public boolean replace(K key, V oldValue, V newValue) { - if (size == 0) { - return false; - } - if (key == null) { - if (nullKeyEntry != null && - Objects.equals(nullKeyEntry.value, oldValue)) { - putForNullKey(newValue); - return true; - } - return false; - } - int hash = hash(key); - int i = indexFor(hash, table.length); - - if (table[i] instanceof Entry) { - @SuppressWarnings("unchecked") - Entry e = (Entry) table[i]; - for (; e != null; e = (Entry)e.next) { - if (e.hash == hash && Objects.equals(e.key, key) && Objects.equals(e.value, oldValue)) { - e.value = newValue; - e.recordAccess(this); - return true; - } - } - return false; - } else if (table[i] != null) { - TreeBin tb = ((TreeBin) table[i]); - TreeNode p = tb.getTreeNode(hash, key); - if (p != null) { - Entry pEntry = (Entry)p.entry; - // assert pEntry.key.equals(key); - if (Objects.equals(pEntry.value, oldValue)) { - pEntry.value = newValue; - pEntry.recordAccess(this); - return true; - } - } - } - return false; - } - - @Override - public V replace(K key, V value) { - if (size == 0) { - return null; - } - if (key == null) { - if (nullKeyEntry != null) { - return putForNullKey(value); - } - return null; - } - int hash = hash(key); - int i = indexFor(hash, table.length); - if (table[i] instanceof Entry) { - @SuppressWarnings("unchecked") - Entry e = (Entry)table[i]; - for (; e != null; e = (Entry)e.next) { - if (e.hash == hash && Objects.equals(e.key, key)) { - V oldValue = e.value; - e.value = value; - e.recordAccess(this); - return oldValue; - } - } - - return null; - } else if (table[i] != null) { - TreeBin tb = ((TreeBin) table[i]); - TreeNode p = tb.getTreeNode(hash, key); - if (p != null) { - Entry pEntry = (Entry)p.entry; - // assert pEntry.key.equals(key); - V oldValue = pEntry.value; - pEntry.value = value; - pEntry.recordAccess(this); - return oldValue; - } - } - return null; - } - - @Override - public V computeIfAbsent(K key, Function mappingFunction) { - if (table == EMPTY_TABLE) { - inflateTable(threshold); - } - if (key == null) { - if (nullKeyEntry == null || nullKeyEntry.value == null) { - V newValue = mappingFunction.apply(key); - if (newValue != null) { - putForNullKey(newValue); - } - return newValue; - } - return nullKeyEntry.value; - } - int hash = hash(key); - int i = indexFor(hash, table.length); - boolean checkIfNeedTree = false; // Might we convert bin to a TreeBin? - - if (table[i] instanceof Entry) { - int listSize = 0; - @SuppressWarnings("unchecked") - Entry e = (Entry)table[i]; - for (; e != null; e = (Entry)e.next) { - if (e.hash == hash && Objects.equals(e.key, key)) { - V oldValue = e.value; - if (oldValue == null) { - V newValue = mappingFunction.apply(key); - if (newValue != null) { - e.value = newValue; - e.recordAccess(this); - } - return newValue; - } - return oldValue; - } - listSize++; - } - // Didn't find, fall through to call the mapping function - checkIfNeedTree = listSize >= TreeBin.TREE_THRESHOLD; - } else if (table[i] != null) { - TreeBin e = (TreeBin)table[i]; - V value = mappingFunction.apply(key); - if (value == null) { // Return the existing value, if any - TreeNode p = e.getTreeNode(hash, key); - if (p != null) { - return (V) p.entry.value; - } - return null; - } else { // Put the new value into the Tree, if absent - TreeNode p = e.putTreeNode(hash, key, value, null); - if (p == null) { // not found, new node was added - modCount++; - size++; - if (size >= threshold) { - resize(2 * table.length); - } - return value; - } else { // putTreeNode() found an existing node - Entry pEntry = (Entry)p.entry; - V oldVal = pEntry.value; - if (oldVal == null) { // only replace if maps to null - pEntry.value = value; - pEntry.recordAccess(this); - return value; - } - return oldVal; - } - } - } - V newValue = mappingFunction.apply(key); - if (newValue != null) { // add Entry and check for TreeBin conversion - modCount++; - addEntry(hash, key, newValue, i, checkIfNeedTree); - } - - return newValue; - } - - @Override - public V computeIfPresent(K key, BiFunction remappingFunction) { - if (size == 0) { - return null; - } - if (key == null) { - V oldValue; - if (nullKeyEntry != null && (oldValue = nullKeyEntry.value) != null) { - V newValue = remappingFunction.apply(key, oldValue); - if (newValue != null ) { - putForNullKey(newValue); - return newValue; - } else { - removeNullKey(); - } - } - return null; - } - int hash = hash(key); - int i = indexFor(hash, table.length); - if (table[i] instanceof Entry) { - @SuppressWarnings("unchecked") - Entry prev = (Entry)table[i]; - Entry e = prev; - while (e != null) { - Entry next = (Entry)e.next; - if (e.hash == hash && Objects.equals(e.key, key)) { - V oldValue = e.value; - if (oldValue == null) - break; - V newValue = remappingFunction.apply(key, oldValue); - if (newValue == null) { - modCount++; - size--; - if (prev == e) - table[i] = next; - else - prev.next = next; - e.recordRemoval(this); - } else { - e.value = newValue; - e.recordAccess(this); - } - return newValue; - } - prev = e; - e = next; - } - } else if (table[i] != null) { - TreeBin tb = (TreeBin)table[i]; - TreeNode p = tb.getTreeNode(hash, key); - if (p != null) { - Entry pEntry = (Entry)p.entry; - // assert pEntry.key.equals(key); - V oldValue = pEntry.value; - if (oldValue != null) { - V newValue = remappingFunction.apply(key, oldValue); - if (newValue == null) { // remove mapping - modCount++; - size--; - tb.deleteTreeNode(p); - pEntry.recordRemoval(this); - if (tb.root == null || tb.first == null) { - // assert tb.root == null && tb.first == null : - // "TreeBin.first and root should both be null"; - // TreeBin is now empty, we should blank this bin - table[i] = null; - } - } else { - pEntry.value = newValue; - pEntry.recordAccess(this); - } - return newValue; - } - } - } - return null; - } - - @Override - public V compute(K key, BiFunction remappingFunction) { - if (table == EMPTY_TABLE) { - inflateTable(threshold); - } - if (key == null) { - V oldValue = nullKeyEntry == null ? null : nullKeyEntry.value; - V newValue = remappingFunction.apply(key, oldValue); - if (newValue != oldValue || (oldValue == null && nullKeyEntry != null)) { - if (newValue == null) { - removeNullKey(); - } else { - putForNullKey(newValue); - } - } - return newValue; - } - int hash = hash(key); - int i = indexFor(hash, table.length); - boolean checkIfNeedTree = false; // Might we convert bin to a TreeBin? - - if (table[i] instanceof Entry) { - int listSize = 0; - @SuppressWarnings("unchecked") - Entry prev = (Entry)table[i]; - Entry e = prev; - - while (e != null) { - Entry next = (Entry)e.next; - if (e.hash == hash && Objects.equals(e.key, key)) { - V oldValue = e.value; - V newValue = remappingFunction.apply(key, oldValue); - if (newValue != oldValue || oldValue == null) { - if (newValue == null) { - modCount++; - size--; - if (prev == e) - table[i] = next; - else - prev.next = next; - e.recordRemoval(this); - } else { - e.value = newValue; - e.recordAccess(this); - } - } - return newValue; - } - prev = e; - e = next; - listSize++; - } - checkIfNeedTree = listSize >= TreeBin.TREE_THRESHOLD; - } else if (table[i] != null) { - TreeBin tb = (TreeBin)table[i]; - TreeNode p = tb.getTreeNode(hash, key); - V oldValue = p == null ? null : (V)p.entry.value; - V newValue = remappingFunction.apply(key, oldValue); - if (newValue != oldValue || (oldValue == null && p != null)) { - if (newValue == null) { - Entry pEntry = (Entry)p.entry; - modCount++; - size--; - tb.deleteTreeNode(p); - pEntry.recordRemoval(this); - if (tb.root == null || tb.first == null) { - // assert tb.root == null && tb.first == null : - // "TreeBin.first and root should both be null"; - // TreeBin is now empty, we should blank this bin - table[i] = null; - } - } else { - if (p != null) { // just update the value - Entry pEntry = (Entry)p.entry; - pEntry.value = newValue; - pEntry.recordAccess(this); - } else { // need to put new node - p = tb.putTreeNode(hash, key, newValue, null); - // assert p == null; // should have added a new node - modCount++; - size++; - if (size >= threshold) { - resize(2 * table.length); - } - } - } - } - return newValue; - } - - V newValue = remappingFunction.apply(key, null); - if (newValue != null) { - modCount++; - addEntry(hash, key, newValue, i, checkIfNeedTree); - } - - return newValue; - } - - @Override - public V merge(K key, V value, BiFunction remappingFunction) { - if (table == EMPTY_TABLE) { - inflateTable(threshold); - } - if (key == null) { - V oldValue = nullKeyEntry == null ? null : nullKeyEntry.value; - V newValue = oldValue == null ? value : remappingFunction.apply(oldValue, value); - if (newValue != null) { - putForNullKey(newValue); - } else if (nullKeyEntry != null) { - removeNullKey(); - } - return newValue; - } - int hash = hash(key); - int i = indexFor(hash, table.length); - boolean checkIfNeedTree = false; // Might we convert bin to a TreeBin? - - if (table[i] instanceof Entry) { - int listSize = 0; - @SuppressWarnings("unchecked") - Entry prev = (Entry)table[i]; - Entry e = prev; - - while (e != null) { - Entry next = (Entry)e.next; - if (e.hash == hash && Objects.equals(e.key, key)) { - V oldValue = e.value; - V newValue = (oldValue == null) ? value : - remappingFunction.apply(oldValue, value); - if (newValue == null) { - modCount++; - size--; - if (prev == e) - table[i] = next; - else - prev.next = next; - e.recordRemoval(this); - } else { - e.value = newValue; - e.recordAccess(this); - } - return newValue; - } - prev = e; - e = next; - listSize++; - } - // Didn't find, so fall through and (maybe) call addEntry() to add - // the Entry and check for TreeBin conversion. - checkIfNeedTree = listSize >= TreeBin.TREE_THRESHOLD; - } else if (table[i] != null) { - TreeBin tb = (TreeBin)table[i]; - TreeNode p = tb.getTreeNode(hash, key); - V oldValue = p == null ? null : (V)p.entry.value; - V newValue = (oldValue == null) ? value : - remappingFunction.apply(oldValue, value); - if (newValue == null) { - if (p != null) { - Entry pEntry = (Entry)p.entry; - modCount++; - size--; - tb.deleteTreeNode(p); - pEntry.recordRemoval(this); - - if (tb.root == null || tb.first == null) { - // assert tb.root == null && tb.first == null : - // "TreeBin.first and root should both be null"; - // TreeBin is now empty, we should blank this bin - table[i] = null; - } - } - return null; - } else if (newValue != oldValue) { - if (p != null) { // just update the value - Entry pEntry = (Entry)p.entry; - pEntry.value = newValue; - pEntry.recordAccess(this); - } else { // need to put new node - p = tb.putTreeNode(hash, key, newValue, null); - // assert p == null; // should have added a new node - modCount++; - size++; - if (size >= threshold) { - resize(2 * table.length); - } - } - } - return newValue; - } - if (value != null) { - modCount++; - addEntry(hash, key, value, i, checkIfNeedTree); - } - return value; - } - - // end of optimized implementations of default methods in Map - - /** - * Removes and returns the entry associated with the specified key - * in the HashMap. Returns null if the HashMap contains no mapping - * for this key. - * - * We don't bother converting TreeBins back to Entry lists if the bin falls - * back below TREE_THRESHOLD, but we do clear bins when removing the last - * TreeNode in a TreeBin. - */ - final Entry removeEntryForKey(Object key) { - if (size == 0) { - return null; - } - if (key == null) { - if (nullKeyEntry != null) { - return removeNullKey(); - } - return null; - } - int hash = hash(key); - int i = indexFor(hash, table.length); - - if (table[i] instanceof Entry) { - @SuppressWarnings("unchecked") - Entry prev = (Entry)table[i]; - Entry e = prev; - - while (e != null) { - @SuppressWarnings("unchecked") - Entry next = (Entry) e.next; - if (e.hash == hash && Objects.equals(e.key, key)) { - modCount++; - size--; - if (prev == e) - table[i] = next; - else - prev.next = next; - e.recordRemoval(this); - return e; - } - prev = e; - e = next; - } - } else if (table[i] != null) { - TreeBin tb = ((TreeBin) table[i]); - TreeNode p = tb.getTreeNode(hash, (K)key); - if (p != null) { - Entry pEntry = (Entry)p.entry; - // assert pEntry.key.equals(key); - modCount++; - size--; - tb.deleteTreeNode(p); - pEntry.recordRemoval(this); - if (tb.root == null || tb.first == null) { - // assert tb.root == null && tb.first == null : - // "TreeBin.first and root should both be null"; - // TreeBin is now empty, we should blank this bin - table[i] = null; - } - return pEntry; - } - } - return null; + Node e; + return (e = removeNode(hash(key), key, null, false, true)) == null ? + null : e.value; } /** - * Special version of remove for EntrySet using {@code Map.Entry.equals()} - * for matching. + * Implements Map.remove and related methods + * + * @param hash hash for key + * @param key the key + * @param value the value to match if matchValue, else ignored + * @param matchValue if true only remove if value is equal + * @param movable if false do not move other nodes while removing + * @return the node, or null if none */ - final Entry removeMapping(Object o) { - if (size == 0 || !(o instanceof Map.Entry)) - return null; - - Map.Entry entry = (Map.Entry) o; - Object key = entry.getKey(); - - if (key == null) { - if (entry.equals(nullKeyEntry)) { - return removeNullKey(); - } - return null; - } - - int hash = hash(key); - int i = indexFor(hash, table.length); - - if (table[i] instanceof Entry) { - @SuppressWarnings("unchecked") - Entry prev = (Entry)table[i]; - Entry e = prev; - - while (e != null) { - @SuppressWarnings("unchecked") - Entry next = (Entry)e.next; - if (e.hash == hash && e.equals(entry)) { - modCount++; - size--; - if (prev == e) - table[i] = next; - else - prev.next = next; - e.recordRemoval(this); - return e; + final Node removeNode(int hash, Object key, Object value, + boolean matchValue, boolean movable) { + Node[] tab; Node p; int n, index; + if ((tab = table) != null && (n = tab.length) > 0 && + (p = tab[index = (n - 1) & hash]) != null) { + Node node = null, e; K k; V v; + if (p.hash == hash && + ((k = p.key) == key || (key != null && key.equals(k)))) + node = p; + else if ((e = p.next) != null) { + if (p instanceof TreeNode) + node = ((TreeNode)p).getTreeNode(hash, key); + else { + do { + if (e.hash == hash && + ((k = e.key) == key || + (key != null && key.equals(k)))) { + node = e; + break; + } + p = e; + } while ((e = e.next) != null); } - prev = e; - e = next; } - } else if (table[i] != null) { - TreeBin tb = ((TreeBin) table[i]); - TreeNode p = tb.getTreeNode(hash, (K)key); - if (p != null && p.entry.equals(entry)) { - @SuppressWarnings("unchecked") - Entry pEntry = (Entry)p.entry; - // assert pEntry.key.equals(key); - modCount++; - size--; - tb.deleteTreeNode(p); - pEntry.recordRemoval(this); - if (tb.root == null || tb.first == null) { - // assert tb.root == null && tb.first == null : - // "TreeBin.first and root should both be null"; - // TreeBin is now empty, we should blank this bin - table[i] = null; - } - return pEntry; + if (node != null && (!matchValue || (v = node.value) == value || + (value != null && value.equals(v)))) { + if (node instanceof TreeNode) + ((TreeNode)node).removeTreeNode(this, tab, movable); + else if (node == p) + tab[index] = node.next; + else + p.next = node.next; + ++modCount; + --size; + afterNodeRemoval(node); + return node; } } return null; } - /* - * Remove the mapping for the null key, and update internal accounting - * (size, modcount, recordRemoval, etc). - * - * Assumes nullKeyEntry is non-null. - */ - private Entry removeNullKey() { - // assert nullKeyEntry != null; - Entry retVal = nullKeyEntry; - modCount++; - size--; - retVal.recordRemoval(this); - nullKeyEntry = null; - return retVal; - } - /** * Removes all of the mappings from this map. * The map will be empty after this call returns. */ public void clear() { + Node[] tab; modCount++; - if (nullKeyEntry != null) { - nullKeyEntry = null; + if ((tab = table) != null && size > 0) { + size = 0; + for (int i = 0; i < tab.length; ++i) + tab[i] = null; } - Arrays.fill(table, null); - size = 0; } /** @@ -2134,351 +873,19 @@ public class HashMap * specified value */ public boolean containsValue(Object value) { - if (value == null) { - return containsNullValue(); - } - Object[] tab = table; - for (int i = 0; i < tab.length; i++) { - if (tab[i] instanceof Entry) { - Entry e = (Entry)tab[i]; - for (; e != null; e = (Entry)e.next) { - if (value.equals(e.value)) { + Node[] tab; V v; + if ((tab = table) != null && size > 0) { + for (int i = 0; i < tab.length; ++i) { + for (Node e = tab[i]; e != null; e = e.next) { + if ((v = e.value) == value || + (value != null && value.equals(v))) return true; - } - } - } else if (tab[i] != null) { - TreeBin e = (TreeBin)tab[i]; - TreeNode p = e.first; - for (; p != null; p = (TreeNode) p.entry.next) { - if (value == p.entry.value || value.equals(p.entry.value)) { - return true; - } } } } - // Didn't find value in table - could be in nullKeyEntry - return (nullKeyEntry != null && (value == nullKeyEntry.value || - value.equals(nullKeyEntry.value))); + return false; } - /** - * Special-case code for containsValue with null argument - */ - private boolean containsNullValue() { - Object[] tab = table; - for (int i = 0; i < tab.length; i++) { - if (tab[i] instanceof Entry) { - Entry e = (Entry)tab[i]; - for (; e != null; e = (Entry)e.next) { - if (e.value == null) { - return true; - } - } - } else if (tab[i] != null) { - TreeBin e = (TreeBin)tab[i]; - TreeNode p = e.first; - for (; p != null; p = (TreeNode) p.entry.next) { - if (p.entry.value == null) { - return true; - } - } - } - } - // Didn't find value in table - could be in nullKeyEntry - return (nullKeyEntry != null && nullKeyEntry.value == null); - } - - /** - * Returns a shallow copy of this HashMap instance: the keys and - * values themselves are not cloned. - * - * @return a shallow copy of this map - */ - @SuppressWarnings("unchecked") - public Object clone() { - HashMap result = null; - try { - result = (HashMap)super.clone(); - } catch (CloneNotSupportedException e) { - // assert false; - } - if (result.table != EMPTY_TABLE) { - result.inflateTable(Math.min( - (int) Math.min( - size * Math.min(1 / loadFactor, 4.0f), - // we have limits... - HashMap.MAXIMUM_CAPACITY), - table.length)); - } - result.entrySet = null; - result.modCount = 0; - result.size = 0; - result.nullKeyEntry = null; - result.init(); - result.putAllForCreate(this); - - return result; - } - - static class Entry implements Map.Entry { - final K key; - V value; - Object next; // an Entry, or a TreeNode - final int hash; - - /** - * Creates new entry. - */ - Entry(int h, K k, V v, Object n) { - value = v; - next = n; - key = k; - hash = h; - } - - public final K getKey() { - return key; - } - - public final V getValue() { - return value; - } - - public final V setValue(V newValue) { - V oldValue = value; - value = newValue; - return oldValue; - } - - public final boolean equals(Object o) { - if (!(o instanceof Map.Entry)) - return false; - Map.Entry e = (Map.Entry)o; - Object k1 = getKey(); - Object k2 = e.getKey(); - if (k1 == k2 || (k1 != null && k1.equals(k2))) { - Object v1 = getValue(); - Object v2 = e.getValue(); - if (v1 == v2 || (v1 != null && v1.equals(v2))) - return true; - } - return false; - } - - public final int hashCode() { - return Objects.hashCode(getKey()) ^ Objects.hashCode(getValue()); - } - - public final String toString() { - return getKey() + "=" + getValue(); - } - - /** - * This method is invoked whenever the value in an entry is - * overwritten for a key that's already in the HashMap. - */ - void recordAccess(HashMap m) { - } - - /** - * This method is invoked whenever the entry is - * removed from the table. - */ - void recordRemoval(HashMap m) { - } - } - - void addEntry(int hash, K key, V value, int bucketIndex) { - addEntry(hash, key, value, bucketIndex, true); - } - - /** - * Adds a new entry with the specified key, value and hash code to - * the specified bucket. It is the responsibility of this - * method to resize the table if appropriate. The new entry is then - * created by calling createEntry(). - * - * Subclass overrides this to alter the behavior of put method. - * - * If checkIfNeedTree is false, it is known that this bucket will not need - * to be converted to a TreeBin, so don't bothering checking. - * - * Assumes key is not null. - */ - void addEntry(int hash, K key, V value, int bucketIndex, boolean checkIfNeedTree) { - // assert key != null; - if ((size >= threshold) && (null != table[bucketIndex])) { - resize(2 * table.length); - hash = hash(key); - bucketIndex = indexFor(hash, table.length); - } - createEntry(hash, key, value, bucketIndex, checkIfNeedTree); - } - - /** - * Called by addEntry(), and also used when creating entries - * as part of Map construction or "pseudo-construction" (cloning, - * deserialization). This version does not check for resizing of the table. - * - * This method is responsible for converting a bucket to a TreeBin once - * TREE_THRESHOLD is reached. However if checkIfNeedTree is false, it is known - * that this bucket will not need to be converted to a TreeBin, so don't - * bother checking. The new entry is constructed by calling newEntry(). - * - * Assumes key is not null. - * - * Note: buckets already converted to a TreeBin don't call this method, but - * instead call TreeBin.putTreeNode() to create new entries. - */ - void createEntry(int hash, K key, V value, int bucketIndex, boolean checkIfNeedTree) { - // assert key != null; - @SuppressWarnings("unchecked") - Entry e = (Entry)table[bucketIndex]; - table[bucketIndex] = newEntry(hash, key, value, e); - size++; - - if (checkIfNeedTree) { - int listSize = 0; - for (e = (Entry) table[bucketIndex]; e != null; e = (Entry)e.next) { - listSize++; - if (listSize >= TreeBin.TREE_THRESHOLD) { // Convert to TreeBin - if (comparableClassFor(key) != null) { - TreeBin t = new TreeBin(); - t.populate((Entry)table[bucketIndex]); - table[bucketIndex] = t; - } - break; - } - } - } - } - - /* - * Factory method to create a new Entry object. - */ - Entry newEntry(int hash, K key, V value, Object next) { - return new HashMap.Entry<>(hash, key, value, next); - } - - - private abstract class HashIterator implements Iterator { - Object next; // next entry to return, an Entry or a TreeNode - int expectedModCount; // For fast-fail - int index; // current slot - Object current; // current entry, an Entry or a TreeNode - - HashIterator() { - expectedModCount = modCount; - if (size > 0) { // advance to first entry - if (nullKeyEntry != null) { - // assert nullKeyEntry.next == null; - // This works with nextEntry(): nullKeyEntry isa Entry, and - // e.next will be null, so we'll hit the findNextBin() call. - next = nullKeyEntry; - } else { - findNextBin(); - } - } - } - - public final boolean hasNext() { - return next != null; - } - - @SuppressWarnings("unchecked") - final Entry nextEntry() { - if (modCount != expectedModCount) { - throw new ConcurrentModificationException(); - } - Object e = next; - Entry retVal; - - if (e == null) - throw new NoSuchElementException(); - - if (e instanceof TreeNode) { // TreeBin - retVal = (Entry)((TreeNode)e).entry; - next = retVal.next; - } else { - retVal = (Entry)e; - next = ((Entry)e).next; - } - - if (next == null) { // Move to next bin - findNextBin(); - } - current = e; - return retVal; - } - - public void remove() { - if (current == null) - throw new IllegalStateException(); - if (modCount != expectedModCount) - throw new ConcurrentModificationException(); - K k; - - if (current instanceof Entry) { - k = ((Entry)current).key; - } else { - k = ((Entry)((TreeNode)current).entry).key; - - } - current = null; - HashMap.this.removeEntryForKey(k); - expectedModCount = modCount; - } - - /* - * Set 'next' to the first entry of the next non-empty bin in the table - */ - private void findNextBin() { - // assert next == null; - Object[] t = table; - - while (index < t.length && (next = t[index++]) == null) - ; - if (next instanceof HashMap.TreeBin) { // Point to the first TreeNode - next = ((TreeBin) next).first; - // assert next != null; // There should be no empty TreeBins - } - } - } - - private final class ValueIterator extends HashIterator { - public V next() { - return nextEntry().value; - } - } - - private final class KeyIterator extends HashIterator { - public K next() { - return nextEntry().getKey(); - } - } - - private final class EntryIterator extends HashIterator> { - public Map.Entry next() { - return nextEntry(); - } - } - - // Subclass overrides these to alter behavior of views' iterator() method - Iterator newKeyIterator() { - return new KeyIterator(); - } - Iterator newValueIterator() { - return new ValueIterator(); - } - Iterator> newEntryIterator() { - return new EntryIterator(); - } - - - // Views - - private transient Set> entrySet = null; - /** * Returns a {@link Set} view of the keys contained in this map. * The set is backed by the map, so changes to the map are @@ -2491,35 +898,38 @@ public class HashMap * removeAll, retainAll, and clear * operations. It does not support the add or addAll * operations. + * + * @return a set view of the keys contained in this map */ public Set keySet() { - Set ks = keySet; - return (ks != null ? ks : (keySet = new KeySet())); + Set ks; + return (ks = keySet) == null ? (keySet = new KeySet()) : ks; } - private final class KeySet extends AbstractSet { - public Iterator iterator() { - return newKeyIterator(); + final class KeySet extends AbstractSet { + public final int size() { return size; } + public final void clear() { HashMap.this.clear(); } + public final Iterator iterator() { return new KeyIterator(); } + public final boolean contains(Object o) { return containsKey(o); } + public final boolean remove(Object key) { + return removeNode(hash(key), key, null, false, true) != null; } - public int size() { - return size; + public final Spliterator spliterator() { + return new KeySpliterator(HashMap.this, 0, -1, 0, 0); } - public boolean contains(Object o) { - return containsKey(o); - } - public boolean remove(Object o) { - return HashMap.this.removeEntryForKey(o) != null; - } - public void clear() { - HashMap.this.clear(); - } - - public Spliterator spliterator() { - if (HashMap.this.getClass() == HashMap.class) - return new KeySpliterator(HashMap.this, 0, -1, 0, 0); - else - return Spliterators.spliterator - (this, Spliterator.SIZED | Spliterator.DISTINCT); + public final void forEach(Consumer action) { + Node[] tab; + if (action == null) + throw new NullPointerException(); + if (size > 0 && (tab = table) != null) { + int mc = modCount; + for (int i = 0; i < tab.length; ++i) { + for (Node e = tab[i]; e != null; e = e.next) + action.accept(e.key); + } + if (modCount != mc) + throw new ConcurrentModificationException(); + } } } @@ -2535,32 +945,35 @@ public class HashMap * Collection.remove, removeAll, * retainAll and clear operations. It does not * support the add or addAll operations. + * + * @return a view of the values contained in this map */ public Collection values() { - Collection vs = values; - return (vs != null ? vs : (values = new Values())); + Collection vs; + return (vs = values) == null ? (values = new Values()) : vs; } - private final class Values extends AbstractCollection { - public Iterator iterator() { - return newValueIterator(); + final class Values extends AbstractCollection { + public final int size() { return size; } + public final void clear() { HashMap.this.clear(); } + public final Iterator iterator() { return new ValueIterator(); } + public final boolean contains(Object o) { return containsValue(o); } + public final Spliterator spliterator() { + return new ValueSpliterator(HashMap.this, 0, -1, 0, 0); } - public int size() { - return size; - } - public boolean contains(Object o) { - return containsValue(o); - } - public void clear() { - HashMap.this.clear(); - } - - public Spliterator spliterator() { - if (HashMap.this.getClass() == HashMap.class) - return new ValueSpliterator(HashMap.this, 0, -1, 0, 0); - else - return Spliterators.spliterator - (this, Spliterator.SIZED); + public final void forEach(Consumer action) { + Node[] tab; + if (action == null) + throw new NullPointerException(); + if (size > 0 && (tab = table) != null) { + int mc = modCount; + for (int i = 0; i < tab.length; ++i) { + for (Node e = tab[i]; e != null; e = e.next) + action.accept(e.value); + } + if (modCount != mc) + throw new ConcurrentModificationException(); + } } } @@ -2581,42 +994,324 @@ public class HashMap * @return a set view of the mappings contained in this map */ public Set> entrySet() { - return entrySet0(); + Set> es; + return (es = entrySet) == null ? (entrySet = new EntrySet()) : es; } - private Set> entrySet0() { - Set> es = entrySet; - return es != null ? es : (entrySet = new EntrySet()); - } - - private final class EntrySet extends AbstractSet> { - public Iterator> iterator() { - return newEntryIterator(); + final class EntrySet extends AbstractSet> { + public final int size() { return size; } + public final void clear() { HashMap.this.clear(); } + public final Iterator> iterator() { + return new EntryIterator(); } - public boolean contains(Object o) { + public final boolean contains(Object o) { if (!(o instanceof Map.Entry)) return false; Map.Entry e = (Map.Entry) o; - Entry candidate = getEntry(e.getKey()); + Object key = e.getKey(); + Node candidate = getNode(hash(key), key); return candidate != null && candidate.equals(e); } - public boolean remove(Object o) { - return removeMapping(o) != null; + public final boolean remove(Object o) { + if (o instanceof Map.Entry) { + Map.Entry e = (Map.Entry) o; + Object key = e.getKey(); + Object value = e.getValue(); + return removeNode(hash(key), key, value, true, true) != null; + } + return false; } - public int size() { - return size; + public final Spliterator> spliterator() { + return new EntrySpliterator(HashMap.this, 0, -1, 0, 0); } - public void clear() { - HashMap.this.clear(); + public final void forEach(Consumer> action) { + Node[] tab; + if (action == null) + throw new NullPointerException(); + if (size > 0 && (tab = table) != null) { + int mc = modCount; + for (int i = 0; i < tab.length; ++i) { + for (Node e = tab[i]; e != null; e = e.next) + action.accept(e); + } + if (modCount != mc) + throw new ConcurrentModificationException(); + } } + } - public Spliterator> spliterator() { - if (HashMap.this.getClass() == HashMap.class) - return new EntrySpliterator(HashMap.this, 0, -1, 0, 0); - else - return Spliterators.spliterator - (this, Spliterator.SIZED | Spliterator.DISTINCT); + // Overrides of JDK8 Map extension methods + + public V getOrDefault(Object key, V defaultValue) { + Node e; + return (e = getNode(hash(key), key)) == null ? defaultValue : e.value; + } + + public V putIfAbsent(K key, V value) { + return putVal(hash(key), key, value, true, true); + } + + public boolean remove(Object key, Object value) { + return removeNode(hash(key), key, value, true, true) != null; + } + + public boolean replace(K key, V oldValue, V newValue) { + Node e; V v; + if ((e = getNode(hash(key), key)) != null && + ((v = e.value) == oldValue || (v != null && v.equals(oldValue)))) { + e.value = newValue; + afterNodeAccess(e); + return true; } + return false; + } + + public V replace(K key, V value) { + Node e; + if ((e = getNode(hash(key), key)) != null) { + V oldValue = e.value; + e.value = value; + afterNodeAccess(e); + return oldValue; + } + return null; + } + + public V computeIfAbsent(K key, + Function mappingFunction) { + if (mappingFunction == null) + throw new NullPointerException(); + int hash = hash(key); + Node[] tab; Node first; int n, i; + int binCount = 0; + TreeNode t = null; + Node old = null; + if (size > threshold || (tab = table) == null || + (n = tab.length) == 0) + n = (tab = resize()).length; + if ((first = tab[i = (n - 1) & hash]) != null) { + if (first instanceof TreeNode) + old = (t = (TreeNode)first).getTreeNode(hash, key); + else { + Node e = first; K k; + do { + if (e.hash == hash && + ((k = e.key) == key || (key != null && key.equals(k)))) { + old = e; + break; + } + ++binCount; + } while ((e = e.next) != null); + } + V oldValue; + if (old != null && (oldValue = old.value) != null) { + afterNodeAccess(old); + return oldValue; + } + } + V v = mappingFunction.apply(key); + if (old != null) { + old.value = v; + afterNodeAccess(old); + return v; + } + else if (v == null) + return null; + else if (t != null) + t.putTreeVal(this, tab, hash, key, v); + else { + tab[i] = newNode(hash, key, v, first); + if (binCount >= TREEIFY_THRESHOLD - 1) + treeifyBin(tab, hash); + } + ++modCount; + ++size; + afterNodeInsertion(true); + return v; + } + + public V computeIfPresent(K key, + BiFunction remappingFunction) { + Node e; V oldValue; + int hash = hash(key); + if ((e = getNode(hash, key)) != null && + (oldValue = e.value) != null) { + V v = remappingFunction.apply(key, oldValue); + if (v != null) { + e.value = v; + afterNodeAccess(e); + return v; + } + else + removeNode(hash, key, null, false, true); + } + return null; + } + + public V compute(K key, + BiFunction remappingFunction) { + if (remappingFunction == null) + throw new NullPointerException(); + int hash = hash(key); + Node[] tab; Node first; int n, i; + int binCount = 0; + TreeNode t = null; + Node old = null; + if (size > threshold || (tab = table) == null || + (n = tab.length) == 0) + n = (tab = resize()).length; + if ((first = tab[i = (n - 1) & hash]) != null) { + if (first instanceof TreeNode) + old = (t = (TreeNode)first).getTreeNode(hash, key); + else { + Node e = first; K k; + do { + if (e.hash == hash && + ((k = e.key) == key || (key != null && key.equals(k)))) { + old = e; + break; + } + ++binCount; + } while ((e = e.next) != null); + } + } + V oldValue = (old == null) ? null : old.value; + V v = remappingFunction.apply(key, oldValue); + if (old != null) { + if (v != null) { + old.value = v; + afterNodeAccess(old); + } + else + removeNode(hash, key, null, false, true); + } + else if (v != null) { + if (t != null) + t.putTreeVal(this, tab, hash, key, v); + else { + tab[i] = newNode(hash, key, v, first); + if (binCount >= TREEIFY_THRESHOLD - 1) + treeifyBin(tab, hash); + } + ++modCount; + ++size; + afterNodeInsertion(true); + } + return v; + } + + public V merge(K key, V value, + BiFunction remappingFunction) { + if (remappingFunction == null) + throw new NullPointerException(); + int hash = hash(key); + Node[] tab; Node first; int n, i; + int binCount = 0; + TreeNode t = null; + Node old = null; + if (size > threshold || (tab = table) == null || + (n = tab.length) == 0) + n = (tab = resize()).length; + if ((first = tab[i = (n - 1) & hash]) != null) { + if (first instanceof TreeNode) + old = (t = (TreeNode)first).getTreeNode(hash, key); + else { + Node e = first; K k; + do { + if (e.hash == hash && + ((k = e.key) == key || (key != null && key.equals(k)))) { + old = e; + break; + } + ++binCount; + } while ((e = e.next) != null); + } + } + if (old != null) { + V v = remappingFunction.apply(old.value, value); + if (v != null) { + old.value = v; + afterNodeAccess(old); + } + else + removeNode(hash, key, null, false, true); + return v; + } + if (value != null) { + if (t != null) + t.putTreeVal(this, tab, hash, key, value); + else { + tab[i] = newNode(hash, key, value, first); + if (binCount >= TREEIFY_THRESHOLD - 1) + treeifyBin(tab, hash); + } + ++modCount; + ++size; + afterNodeInsertion(true); + } + return value; + } + + public void forEach(BiConsumer action) { + Node[] tab; + if (action == null) + throw new NullPointerException(); + if (size > 0 && (tab = table) != null) { + int mc = modCount; + for (int i = 0; i < tab.length; ++i) { + for (Node e = tab[i]; e != null; e = e.next) + action.accept(e.key, e.value); + } + if (modCount != mc) + throw new ConcurrentModificationException(); + } + } + + public void replaceAll(BiFunction function) { + Node[] tab; + if (function == null) + throw new NullPointerException(); + if (size > 0 && (tab = table) != null) { + int mc = modCount; + for (int i = 0; i < tab.length; ++i) { + for (Node e = tab[i]; e != null; e = e.next) { + e.value = function.apply(e.key, e.value); + } + } + if (modCount != mc) + throw new ConcurrentModificationException(); + } + } + + /* ------------------------------------------------------------ */ + // Cloning and serialization + + /** + * Returns a shallow copy of this HashMap instance: the keys and + * values themselves are not cloned. + * + * @return a shallow copy of this map + */ + @SuppressWarnings("unchecked") + public Object clone() { + HashMap result; + try { + result = (HashMap)super.clone(); + } catch (CloneNotSupportedException e) { + // this shouldn't happen, since we are Cloneable + throw new InternalError(e); + } + result.reinitialize(); + result.putMapEntries(this, false); + return result; + } + + // These methods are also used when serializing HashSets + final float loadFactor() { return loadFactor; } + final int capacity() { + return (table != null) ? table.length : + (threshold > 0) ? threshold : + DEFAULT_INITIAL_CAPACITY; } /** @@ -2631,118 +1326,143 @@ public class HashMap * emitted in no particular order. */ private void writeObject(java.io.ObjectOutputStream s) - throws IOException - { + throws IOException { + int buckets = capacity(); // Write out the threshold, loadfactor, and any hidden stuff s.defaultWriteObject(); - - // Write out number of buckets - if (table==EMPTY_TABLE) { - s.writeInt(roundUpToPowerOf2(threshold)); - } else { - s.writeInt(table.length); - } - - // Write out size (number of Mappings) + s.writeInt(buckets); s.writeInt(size); - - // Write out keys and values (alternating) - if (size > 0) { - for(Map.Entry e : entrySet0()) { - s.writeObject(e.getKey()); - s.writeObject(e.getValue()); - } - } + internalWriteEntries(s); } - private static final long serialVersionUID = 362498820763181265L; - /** * Reconstitute the {@code HashMap} instance from a stream (i.e., * deserialize it). */ private void readObject(java.io.ObjectInputStream s) - throws IOException, ClassNotFoundException - { + throws IOException, ClassNotFoundException { // Read in the threshold (ignored), loadfactor, and any hidden stuff s.defaultReadObject(); - if (loadFactor <= 0 || Float.isNaN(loadFactor)) { + reinitialize(); + if (loadFactor <= 0 || Float.isNaN(loadFactor)) throw new InvalidObjectException("Illegal load factor: " + - loadFactor); - } - - // set other fields that need values - if (Holder.USE_HASHSEED) { - int seed = ThreadLocalRandom.current().nextInt(); - Holder.UNSAFE.putIntVolatile(this, Holder.HASHSEED_OFFSET, - (seed != 0) ? seed : 1); - } - table = EMPTY_TABLE; - - // Read in number of buckets - s.readInt(); // ignored. - - // Read number of mappings - int mappings = s.readInt(); + loadFactor); + s.readInt(); // Read and ignore number of buckets + int mappings = s.readInt(); // Read number of mappings (size) if (mappings < 0) throw new InvalidObjectException("Illegal mappings count: " + - mappings); + mappings); + else if (mappings > 0) { // (if zero, use defaults) + // Size the table using given load factor only if within + // range of 0.25...4.0 + float lf = Math.min(Math.max(0.25f, loadFactor), 4.0f); + float fc = (float)mappings / lf + 1.0f; + int cap = ((fc < DEFAULT_INITIAL_CAPACITY) ? + DEFAULT_INITIAL_CAPACITY : + (fc >= MAXIMUM_CAPACITY) ? + MAXIMUM_CAPACITY : + tableSizeFor((int)fc)); + float ft = (float)cap * lf; + threshold = ((cap < MAXIMUM_CAPACITY && ft < MAXIMUM_CAPACITY) ? + (int)ft : Integer.MAX_VALUE); + @SuppressWarnings({"rawtypes","unchecked"}) + Node[] tab = (Node[])new Node[cap]; + table = tab; - // capacity chosen by number of mappings and desired load (if >= 0.25) - int capacity = (int) Math.min( - mappings * Math.min(1 / loadFactor, 4.0f), - // we have limits... - HashMap.MAXIMUM_CAPACITY); - - // allocate the bucket array; - if (mappings > 0) { - inflateTable(capacity); - } else { - threshold = capacity; - } - - init(); // Give subclass a chance to do its thing. - - // Read the keys and values, and put the mappings in the HashMap - for (int i=0; i next; // next entry to return + Node current; // current entry + int expectedModCount; // for fast-fail + int index; // current slot + + HashIterator() { + expectedModCount = modCount; + Node[] t = table; + current = next = null; + index = 0; + if (t != null && size > 0) { // advance to first entry + do {} while (index < t.length && (next = t[index++]) == null); + } + } + + public final boolean hasNext() { + return next != null; + } + + final Node nextNode() { + Node[] t; + Node e = next; + if (modCount != expectedModCount) + throw new ConcurrentModificationException(); + if (e == null) + throw new NoSuchElementException(); + if ((next = (current = e).next) == null && (t = table) != null) { + do {} while (index < t.length && (next = t[index++]) == null); + } + return e; + } + + public final void remove() { + Node p = current; + if (p == null) + throw new IllegalStateException(); + if (modCount != expectedModCount) + throw new ConcurrentModificationException(); + current = null; + K key = p.key; + removeNode(hash(key), key, null, false, false); + expectedModCount = modCount; + } + } + + final class KeyIterator extends HashIterator + implements Iterator { + public final K next() { return nextNode().key; } + } + + final class ValueIterator extends HashIterator + implements Iterator { + public final V next() { return nextNode().value; } + } + + final class EntryIterator extends HashIterator + implements Iterator> { + public final Map.Entry next() { return nextNode(); } + } + + /* ------------------------------------------------------------ */ + // spliterators - /** - * Standin until HM overhaul; based loosely on Weak and Identity HM. - */ static class HashMapSpliterator { final HashMap map; - Object current; // current node, can be Entry or TreeNode + Node current; // current node int index; // current index, modified on advance/split int fence; // one past last index int est; // size estimate int expectedModCount; // for comodification checks - boolean acceptedNull; // Have we accepted the null key? - // Without this, we can't distinguish - // between being at the very beginning (and - // needing to accept null), or being at the - // end of the list in bin 0. In both cases, - // current == null && index == 0. HashMapSpliterator(HashMap m, int origin, - int fence, int est, - int expectedModCount) { + int fence, int est, + int expectedModCount) { this.map = m; this.index = origin; this.fence = fence; this.est = est; this.expectedModCount = expectedModCount; - this.acceptedNull = false; } final int getFence() { // initialize fence and size on first use @@ -2751,7 +1471,8 @@ public class HashMap HashMap m = map; est = m.size; expectedModCount = m.modCount; - hi = fence = m.table.length; + Node[] tab = m.table; + hi = fence = (tab == null) ? 0 : tab.length; } return hi; } @@ -2772,56 +1493,33 @@ public class HashMap public KeySpliterator trySplit() { int hi = getFence(), lo = index, mid = (lo + hi) >>> 1; - if (lo >= mid || current != null) { - return null; - } else { - KeySpliterator retVal = new KeySpliterator(map, lo, - index = mid, est >>>= 1, expectedModCount); - // Only 'this' Spliterator chould check for null. - retVal.acceptedNull = true; - return retVal; - } + return (lo >= mid || current != null) ? null : + new KeySpliterator(map, lo, index = mid, est >>>= 1, + expectedModCount); } - @SuppressWarnings("unchecked") public void forEachRemaining(Consumer action) { int i, hi, mc; if (action == null) throw new NullPointerException(); HashMap m = map; - Object[] tab = m.table; + Node[] tab = m.table; if ((hi = fence) < 0) { mc = expectedModCount = m.modCount; - hi = fence = tab.length; + hi = fence = (tab == null) ? 0 : tab.length; } else mc = expectedModCount; - - if (!acceptedNull) { - acceptedNull = true; - if (m.nullKeyEntry != null) { - action.accept(m.nullKeyEntry.key); - } - } - if (tab.length >= hi && (i = index) >= 0 && - (i < (index = hi) || current != null)) { - Object p = current; + if (tab != null && tab.length >= hi && + (i = index) >= 0 && (i < (index = hi) || current != null)) { + Node p = current; current = null; do { - if (p == null) { + if (p == null) p = tab[i++]; - if (p instanceof HashMap.TreeBin) { - p = ((HashMap.TreeBin)p).first; - } - } else { - HashMap.Entry entry; - if (p instanceof HashMap.Entry) { - entry = (HashMap.Entry)p; - } else { - entry = (HashMap.Entry)((TreeNode)p).entry; - } - action.accept(entry.key); - p = entry.next; + else { + action.accept(p.key); + p = p.next; } } while (p != null || i < hi); if (m.modCount != mc) @@ -2829,39 +1527,18 @@ public class HashMap } } - @SuppressWarnings("unchecked") public boolean tryAdvance(Consumer action) { int hi; if (action == null) throw new NullPointerException(); - Object[] tab = map.table; - hi = getFence(); - - if (!acceptedNull) { - acceptedNull = true; - if (map.nullKeyEntry != null) { - action.accept(map.nullKeyEntry.key); - if (map.modCount != expectedModCount) - throw new ConcurrentModificationException(); - return true; - } - } - if (tab.length >= hi && index >= 0) { + Node[] tab = map.table; + if (tab != null && tab.length >= (hi = getFence()) && index >= 0) { while (current != null || index < hi) { - if (current == null) { + if (current == null) current = tab[index++]; - if (current instanceof HashMap.TreeBin) { - current = ((HashMap.TreeBin)current).first; - } - } else { - HashMap.Entry entry; - if (current instanceof HashMap.Entry) { - entry = (HashMap.Entry)current; - } else { - entry = (HashMap.Entry)((TreeNode)current).entry; - } - K k = entry.key; - current = entry.next; + else { + K k = current.key; + current = current.next; action.accept(k); if (map.modCount != expectedModCount) throw new ConcurrentModificationException(); @@ -2888,56 +1565,33 @@ public class HashMap public ValueSpliterator trySplit() { int hi = getFence(), lo = index, mid = (lo + hi) >>> 1; - if (lo >= mid || current != null) { - return null; - } else { - ValueSpliterator retVal = new ValueSpliterator(map, - lo, index = mid, est >>>= 1, expectedModCount); - // Only 'this' Spliterator chould check for null. - retVal.acceptedNull = true; - return retVal; - } + return (lo >= mid || current != null) ? null : + new ValueSpliterator(map, lo, index = mid, est >>>= 1, + expectedModCount); } - @SuppressWarnings("unchecked") public void forEachRemaining(Consumer action) { int i, hi, mc; if (action == null) throw new NullPointerException(); HashMap m = map; - Object[] tab = m.table; + Node[] tab = m.table; if ((hi = fence) < 0) { mc = expectedModCount = m.modCount; - hi = fence = tab.length; + hi = fence = (tab == null) ? 0 : tab.length; } else mc = expectedModCount; - - if (!acceptedNull) { - acceptedNull = true; - if (m.nullKeyEntry != null) { - action.accept(m.nullKeyEntry.value); - } - } - if (tab.length >= hi && (i = index) >= 0 && - (i < (index = hi) || current != null)) { - Object p = current; + if (tab != null && tab.length >= hi && + (i = index) >= 0 && (i < (index = hi) || current != null)) { + Node p = current; current = null; do { - if (p == null) { + if (p == null) p = tab[i++]; - if (p instanceof HashMap.TreeBin) { - p = ((HashMap.TreeBin)p).first; - } - } else { - HashMap.Entry entry; - if (p instanceof HashMap.Entry) { - entry = (HashMap.Entry)p; - } else { - entry = (HashMap.Entry)((TreeNode)p).entry; - } - action.accept(entry.value); - p = entry.next; + else { + action.accept(p.value); + p = p.next; } } while (p != null || i < hi); if (m.modCount != mc) @@ -2945,39 +1599,18 @@ public class HashMap } } - @SuppressWarnings("unchecked") public boolean tryAdvance(Consumer action) { int hi; if (action == null) throw new NullPointerException(); - Object[] tab = map.table; - hi = getFence(); - - if (!acceptedNull) { - acceptedNull = true; - if (map.nullKeyEntry != null) { - action.accept(map.nullKeyEntry.value); - if (map.modCount != expectedModCount) - throw new ConcurrentModificationException(); - return true; - } - } - if (tab.length >= hi && index >= 0) { + Node[] tab = map.table; + if (tab != null && tab.length >= (hi = getFence()) && index >= 0) { while (current != null || index < hi) { - if (current == null) { + if (current == null) current = tab[index++]; - if (current instanceof HashMap.TreeBin) { - current = ((HashMap.TreeBin)current).first; - } - } else { - HashMap.Entry entry; - if (current instanceof HashMap.Entry) { - entry = (Entry)current; - } else { - entry = (Entry)((TreeNode)current).entry; - } - V v = entry.value; - current = entry.next; + else { + V v = current.value; + current = current.next; action.accept(v); if (map.modCount != expectedModCount) throw new ConcurrentModificationException(); @@ -3003,57 +1636,33 @@ public class HashMap public EntrySpliterator trySplit() { int hi = getFence(), lo = index, mid = (lo + hi) >>> 1; - if (lo >= mid || current != null) { - return null; - } else { - EntrySpliterator retVal = new EntrySpliterator(map, - lo, index = mid, est >>>= 1, expectedModCount); - // Only 'this' Spliterator chould check for null. - retVal.acceptedNull = true; - return retVal; - } + return (lo >= mid || current != null) ? null : + new EntrySpliterator(map, lo, index = mid, est >>>= 1, + expectedModCount); } - @SuppressWarnings("unchecked") public void forEachRemaining(Consumer> action) { int i, hi, mc; if (action == null) throw new NullPointerException(); HashMap m = map; - Object[] tab = m.table; + Node[] tab = m.table; if ((hi = fence) < 0) { mc = expectedModCount = m.modCount; - hi = fence = tab.length; + hi = fence = (tab == null) ? 0 : tab.length; } else mc = expectedModCount; - - if (!acceptedNull) { - acceptedNull = true; - if (m.nullKeyEntry != null) { - action.accept(m.nullKeyEntry); - } - } - if (tab.length >= hi && (i = index) >= 0 && - (i < (index = hi) || current != null)) { - Object p = current; + if (tab != null && tab.length >= hi && + (i = index) >= 0 && (i < (index = hi) || current != null)) { + Node p = current; current = null; do { - if (p == null) { + if (p == null) p = tab[i++]; - if (p instanceof HashMap.TreeBin) { - p = ((HashMap.TreeBin)p).first; - } - } else { - HashMap.Entry entry; - if (p instanceof HashMap.Entry) { - entry = (HashMap.Entry)p; - } else { - entry = (HashMap.Entry)((TreeNode)p).entry; - } - action.accept(entry); - p = entry.next; - + else { + action.accept(p); + p = p.next; } } while (p != null || i < hi); if (m.modCount != mc) @@ -3061,38 +1670,18 @@ public class HashMap } } - @SuppressWarnings("unchecked") public boolean tryAdvance(Consumer> action) { int hi; if (action == null) throw new NullPointerException(); - Object[] tab = map.table; - hi = getFence(); - - if (!acceptedNull) { - acceptedNull = true; - if (map.nullKeyEntry != null) { - action.accept(map.nullKeyEntry); - if (map.modCount != expectedModCount) - throw new ConcurrentModificationException(); - return true; - } - } - if (tab.length >= hi && index >= 0) { + Node[] tab = map.table; + if (tab != null && tab.length >= (hi = getFence()) && index >= 0) { while (current != null || index < hi) { - if (current == null) { + if (current == null) current = tab[index++]; - if (current instanceof HashMap.TreeBin) { - current = ((HashMap.TreeBin)current).first; - } - } else { - HashMap.Entry e; - if (current instanceof HashMap.Entry) { - e = (Entry)current; - } else { - e = (Entry)((TreeNode)current).entry; - } - current = e.next; + else { + Node e = current; + current = current.next; action.accept(e); if (map.modCount != expectedModCount) throw new ConcurrentModificationException(); @@ -3108,4 +1697,664 @@ public class HashMap Spliterator.DISTINCT; } } + + /* ------------------------------------------------------------ */ + // LinkedHashMap support + + + /* + * The following package-protected methods are designed to be + * overridden by LinkedHashMap, but not by any other subclass. + * Nearly all other internal methods are also package-protected + * but are declared final, so can be used by LinkedHashMap, view + * classes, and HashSet. + */ + + // Create a regular (non-tree) node + Node newNode(int hash, K key, V value, Node next) { + return new Node(hash, key, value, next); + } + + // For conversion from TreeNodes to plain nodes + Node replacementNode(Node p, Node next) { + return new Node(p.hash, p.key, p.value, next); + } + + // Create a tree bin node + TreeNode newTreeNode(int hash, K key, V value, Node next) { + return new TreeNode(hash, key, value, next); + } + + // For treeifyBin + TreeNode replacementTreeNode(Node p, Node next) { + return new TreeNode(p.hash, p.key, p.value, next); + } + + /** + * Reset to initial default state. Called by clone and readObject. + */ + void reinitialize() { + table = null; + entrySet = null; + keySet = null; + values = null; + modCount = 0; + threshold = 0; + size = 0; + } + + // Callbacks to allow LinkedHashMap post-actions + void afterNodeAccess(Node p) { } + void afterNodeInsertion(boolean evict) { } + void afterNodeRemoval(Node p) { } + + // Called only from writeObject, to ensure compatible ordering. + void internalWriteEntries(java.io.ObjectOutputStream s) throws IOException { + Node[] tab; + if (size > 0 && (tab = table) != null) { + for (int i = 0; i < tab.length; ++i) { + for (Node e = tab[i]; e != null; e = e.next) { + s.writeObject(e.key); + s.writeObject(e.value); + } + } + } + } + + /* ------------------------------------------------------------ */ + // Tree bins + + /** + * Entry for Tree bins. Extends LinkedHashMap.Entry (which in turn + * extends Node) so can be used as extension of either regular or + * linked node. + */ + static final class TreeNode extends LinkedHashMap.Entry { + TreeNode parent; // red-black tree links + TreeNode left; + TreeNode right; + TreeNode prev; // needed to unlink next upon deletion + boolean red; + TreeNode(int hash, K key, V val, Node next) { + super(hash, key, val, next); + } + + /** + * Returns root of tree containing this node. + */ + final TreeNode root() { + for (TreeNode r = this, p;;) { + if ((p = r.parent) == null) + return r; + r = p; + } + } + + /** + * Ensures that the given root is the first node of its bin. + */ + static void moveRootToFront(Node[] tab, TreeNode root) { + int n; + if (root != null && tab != null && (n = tab.length) > 0) { + int index = (n - 1) & root.hash; + TreeNode first = (TreeNode)tab[index]; + if (root != first) { + Node rn; + tab[index] = root; + TreeNode rp = root.prev; + if ((rn = root.next) != null) + ((TreeNode)rn).prev = rp; + if (rp != null) + rp.next = rn; + if (first != null) + first.prev = root; + root.next = first; + root.prev = null; + } + assert checkInvariants(root); + } + } + + /** + * Finds the node starting at root p with the given hash and key. + * The kc argument caches comparableClassFor(key) upon first use + * comparing keys. + */ + final TreeNode find(int h, Object k, Class kc) { + TreeNode p = this; + do { + int ph, dir; K pk; + TreeNode pl = p.left, pr = p.right, q; + if ((ph = p.hash) > h) + p = pl; + else if (ph < h) + p = pr; + else if ((pk = p.key) == k || (k != null && k.equals(pk))) + return p; + else if (pl == null) + p = pr; + else if (pr == null) + p = pl; + else if ((kc != null || + (kc = comparableClassFor(k)) != null) && + (dir = compareComparables(kc, k, pk)) != 0) + p = (dir < 0) ? pl : pr; + else if ((q = pr.find(h, k, kc)) != null) + return q; + else + p = pl; + } while (p != null); + return null; + } + + /** + * Calls find for root node. + */ + final TreeNode getTreeNode(int h, Object k) { + return ((parent != null) ? root() : this).find(h, k, null); + } + + /** + * Tie-breaking utility for ordering insertions when equal + * hashCodes and non-comparable. We don't require a total + * order, just a consistent insertion rule to maintain + * equivalence across rebalancings. Tie-breaking further than + * necessary simplifies testing a bit. + */ + static int tieBreakOrder(Object a, Object b) { + int d; + if (a == null || b == null || + (d = a.getClass().getName(). + compareTo(b.getClass().getName())) == 0) + d = (System.identityHashCode(a) <= System.identityHashCode(b) ? + -1 : 1); + return d; + } + + /** + * Forms tree of the nodes linked from this node. + * @return root of tree + */ + final void treeify(Node[] tab) { + TreeNode root = null; + for (TreeNode x = this, next; x != null; x = next) { + next = (TreeNode)x.next; + x.left = x.right = null; + if (root == null) { + x.parent = null; + x.red = false; + root = x; + } + else { + K k = x.key; + int h = x.hash; + Class kc = null; + for (TreeNode p = root;;) { + int dir, ph; + K pk = p.key; + if ((ph = p.hash) > h) + dir = -1; + else if (ph < h) + dir = 1; + else if ((kc == null && + (kc = comparableClassFor(k)) == null) || + (dir = compareComparables(kc, k, pk)) == 0) + dir = tieBreakOrder(k, pk); + + TreeNode xp = p; + if ((p = (dir <= 0) ? p.left : p.right) == null) { + x.parent = xp; + if (dir <= 0) + xp.left = x; + else + xp.right = x; + root = balanceInsertion(root, x); + break; + } + } + } + } + moveRootToFront(tab, root); + } + + /** + * Returns a list of non-TreeNodes replacing those linked from + * this node. + */ + final Node untreeify(HashMap map) { + Node hd = null, tl = null; + for (Node q = this; q != null; q = q.next) { + Node p = map.replacementNode(q, null); + if (tl == null) + hd = p; + else + tl.next = p; + tl = p; + } + return hd; + } + + /** + * Tree version of putVal. + */ + final TreeNode putTreeVal(HashMap map, Node[] tab, + int h, K k, V v) { + Class kc = null; + boolean searched = false; + TreeNode root = (parent != null) ? root() : this; + for (TreeNode p = root;;) { + int dir, ph; K pk; + if ((ph = p.hash) > h) + dir = -1; + else if (ph < h) + dir = 1; + else if ((pk = p.key) == k || (pk != null && k.equals(pk))) + return p; + else if ((kc == null && + (kc = comparableClassFor(k)) == null) || + (dir = compareComparables(kc, k, pk)) == 0) { + if (!searched) { + TreeNode q, ch; + searched = true; + if (((ch = p.left) != null && + (q = ch.find(h, k, kc)) != null) || + ((ch = p.right) != null && + (q = ch.find(h, k, kc)) != null)) + return q; + } + dir = tieBreakOrder(k, pk); + } + + TreeNode xp = p; + if ((p = (dir <= 0) ? p.left : p.right) == null) { + Node xpn = xp.next; + TreeNode x = map.newTreeNode(h, k, v, xpn); + if (dir <= 0) + xp.left = x; + else + xp.right = x; + xp.next = x; + x.parent = x.prev = xp; + if (xpn != null) + ((TreeNode)xpn).prev = x; + moveRootToFront(tab, balanceInsertion(root, x)); + return null; + } + } + } + + /** + * Removes the given node, that must be present before this call. + * This is messier than typical red-black deletion code because we + * cannot swap the contents of an interior node with a leaf + * successor that is pinned by "next" pointers that are accessible + * independently during traversal. So instead we swap the tree + * linkages. If the current tree appears to have too few nodes, + * the bin is converted back to a plain bin. (The test triggers + * somewhere between 2 and 6 nodes, depending on tree structure). + */ + final void removeTreeNode(HashMap map, Node[] tab, + boolean movable) { + int n; + if (tab == null || (n = tab.length) == 0) + return; + int index = (n - 1) & hash; + TreeNode first = (TreeNode)tab[index], root = first, rl; + TreeNode succ = (TreeNode)next, pred = prev; + if (pred == null) + tab[index] = first = succ; + else + pred.next = succ; + if (succ != null) + succ.prev = pred; + if (first == null) + return; + if (root.parent != null) + root = root.root(); + if (root == null || root.right == null || + (rl = root.left) == null || rl.left == null) { + tab[index] = first.untreeify(map); // too small + return; + } + TreeNode p = this, pl = left, pr = right, replacement; + if (pl != null && pr != null) { + TreeNode s = pr, sl; + while ((sl = s.left) != null) // find successor + s = sl; + boolean c = s.red; s.red = p.red; p.red = c; // swap colors + TreeNode sr = s.right; + TreeNode pp = p.parent; + if (s == pr) { // p was s's direct parent + p.parent = s; + s.right = p; + } + else { + TreeNode sp = s.parent; + if ((p.parent = sp) != null) { + if (s == sp.left) + sp.left = p; + else + sp.right = p; + } + if ((s.right = pr) != null) + pr.parent = s; + } + p.left = null; + if ((p.right = sr) != null) + sr.parent = p; + if ((s.left = pl) != null) + pl.parent = s; + if ((s.parent = pp) == null) + root = s; + else if (p == pp.left) + pp.left = s; + else + pp.right = s; + if (sr != null) + replacement = sr; + else + replacement = p; + } + else if (pl != null) + replacement = pl; + else if (pr != null) + replacement = pr; + else + replacement = p; + if (replacement != p) { + TreeNode pp = replacement.parent = p.parent; + if (pp == null) + root = replacement; + else if (p == pp.left) + pp.left = replacement; + else + pp.right = replacement; + p.left = p.right = p.parent = null; + } + + TreeNode r = p.red ? root : balanceDeletion(root, replacement); + + if (replacement == p) { // detach + TreeNode pp = p.parent; + p.parent = null; + if (pp != null) { + if (p == pp.left) + pp.left = null; + else if (p == pp.right) + pp.right = null; + } + } + if (movable) + moveRootToFront(tab, r); + } + + /** + * Splits nodes in a tree bin into lower and upper tree bins, + * or untreeifies if now too small. Called only from resize; + * see above discussion about split bits and indices. + * + * @param map the map + * @param tab the table for recording bin heads + * @param index the index of the table being split + * @param bit the bit of hash to split on + */ + final void split(HashMap map, Node[] tab, int index, int bit) { + TreeNode b = this; + // Relink into lo and hi lists, preserving order + TreeNode loHead = null, loTail = null; + TreeNode hiHead = null, hiTail = null; + int lc = 0, hc = 0; + for (TreeNode e = b, next; e != null; e = next) { + next = (TreeNode)e.next; + e.next = null; + if ((e.hash & bit) == 0) { + if ((e.prev = loTail) == null) + loHead = e; + else + loTail.next = e; + loTail = e; + ++lc; + } + else { + if ((e.prev = hiTail) == null) + hiHead = e; + else + hiTail.next = e; + hiTail = e; + ++hc; + } + } + + if (loHead != null) { + if (lc <= UNTREEIFY_THRESHOLD) + tab[index] = loHead.untreeify(map); + else { + tab[index] = loHead; + if (hiHead != null) // (else is already treeified) + loHead.treeify(tab); + } + } + if (hiHead != null) { + if (hc <= UNTREEIFY_THRESHOLD) + tab[index + bit] = hiHead.untreeify(map); + else { + tab[index + bit] = hiHead; + if (loHead != null) + hiHead.treeify(tab); + } + } + } + + /* ------------------------------------------------------------ */ + // Red-black tree methods, all adapted from CLR + + static TreeNode rotateLeft(TreeNode root, + TreeNode p) { + TreeNode r, pp, rl; + if (p != null && (r = p.right) != null) { + if ((rl = p.right = r.left) != null) + rl.parent = p; + if ((pp = r.parent = p.parent) == null) + (root = r).red = false; + else if (pp.left == p) + pp.left = r; + else + pp.right = r; + r.left = p; + p.parent = r; + } + return root; + } + + static TreeNode rotateRight(TreeNode root, + TreeNode p) { + TreeNode l, pp, lr; + if (p != null && (l = p.left) != null) { + if ((lr = p.left = l.right) != null) + lr.parent = p; + if ((pp = l.parent = p.parent) == null) + (root = l).red = false; + else if (pp.right == p) + pp.right = l; + else + pp.left = l; + l.right = p; + p.parent = l; + } + return root; + } + + static TreeNode balanceInsertion(TreeNode root, + TreeNode x) { + x.red = true; + for (TreeNode xp, xpp, xppl, xppr;;) { + if ((xp = x.parent) == null) { + x.red = false; + return x; + } + else if (!xp.red || (xpp = xp.parent) == null) + return root; + if (xp == (xppl = xpp.left)) { + if ((xppr = xpp.right) != null && xppr.red) { + xppr.red = false; + xp.red = false; + xpp.red = true; + x = xpp; + } + else { + if (x == xp.right) { + root = rotateLeft(root, x = xp); + xpp = (xp = x.parent) == null ? null : xp.parent; + } + if (xp != null) { + xp.red = false; + if (xpp != null) { + xpp.red = true; + root = rotateRight(root, xpp); + } + } + } + } + else { + if (xppl != null && xppl.red) { + xppl.red = false; + xp.red = false; + xpp.red = true; + x = xpp; + } + else { + if (x == xp.left) { + root = rotateRight(root, x = xp); + xpp = (xp = x.parent) == null ? null : xp.parent; + } + if (xp != null) { + xp.red = false; + if (xpp != null) { + xpp.red = true; + root = rotateLeft(root, xpp); + } + } + } + } + } + } + + static TreeNode balanceDeletion(TreeNode root, + TreeNode x) { + for (TreeNode xp, xpl, xpr;;) { + if (x == null || x == root) + return root; + else if ((xp = x.parent) == null) { + x.red = false; + return x; + } + else if (x.red) { + x.red = false; + return root; + } + else if ((xpl = xp.left) == x) { + if ((xpr = xp.right) != null && xpr.red) { + xpr.red = false; + xp.red = true; + root = rotateLeft(root, xp); + xpr = (xp = x.parent) == null ? null : xp.right; + } + if (xpr == null) + x = xp; + else { + TreeNode sl = xpr.left, sr = xpr.right; + if ((sr == null || !sr.red) && + (sl == null || !sl.red)) { + xpr.red = true; + x = xp; + } + else { + if (sr == null || !sr.red) { + if (sl != null) + sl.red = false; + xpr.red = true; + root = rotateRight(root, xpr); + xpr = (xp = x.parent) == null ? + null : xp.right; + } + if (xpr != null) { + xpr.red = (xp == null) ? false : xp.red; + if ((sr = xpr.right) != null) + sr.red = false; + } + if (xp != null) { + xp.red = false; + root = rotateLeft(root, xp); + } + x = root; + } + } + } + else { // symmetric + if (xpl != null && xpl.red) { + xpl.red = false; + xp.red = true; + root = rotateRight(root, xp); + xpl = (xp = x.parent) == null ? null : xp.left; + } + if (xpl == null) + x = xp; + else { + TreeNode sl = xpl.left, sr = xpl.right; + if ((sl == null || !sl.red) && + (sr == null || !sr.red)) { + xpl.red = true; + x = xp; + } + else { + if (sl == null || !sl.red) { + if (sr != null) + sr.red = false; + xpl.red = true; + root = rotateLeft(root, xpl); + xpl = (xp = x.parent) == null ? + null : xp.left; + } + if (xpl != null) { + xpl.red = (xp == null) ? false : xp.red; + if ((sl = xpl.left) != null) + sl.red = false; + } + if (xp != null) { + xp.red = false; + root = rotateRight(root, xp); + } + x = root; + } + } + } + } + } + + /** + * Recursive invariant check + */ + static boolean checkInvariants(TreeNode t) { + TreeNode tp = t.parent, tl = t.left, tr = t.right, + tb = t.prev, tn = (TreeNode)t.next; + if (tb != null && tb.next != t) + return false; + if (tn != null && tn.prev != t) + return false; + if (tp != null && t != tp.left && t != tp.right) + return false; + if (tl != null && (tl.parent != t || tl.hash > t.hash)) + return false; + if (tr != null && (tr.parent != t || tr.hash < t.hash)) + return false; + if (t.red && tl != null && tl.red && tr != null && tr.red) + return false; + if (tl != null && !checkInvariants(tl)) + return false; + if (tr != null && !checkInvariants(tr)) + return false; + return true; + } + } + } diff --git a/jdk/src/share/classes/java/util/LinkedHashMap.java b/jdk/src/share/classes/java/util/LinkedHashMap.java index feb1005b2aa..0e4fc73f0df 100644 --- a/jdk/src/share/classes/java/util/LinkedHashMap.java +++ b/jdk/src/share/classes/java/util/LinkedHashMap.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2013, 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,9 +24,12 @@ */ package java.util; -import java.io.*; + +import java.util.function.Consumer; import java.util.function.BiConsumer; import java.util.function.BiFunction; +import java.io.Serializable; +import java.io.IOException; /** *

    Hash table and linked list implementation of the Map interface, @@ -57,9 +60,9 @@ import java.util.function.BiFunction; * order they were presented.) * *

    A special {@link #LinkedHashMap(int,float,boolean) constructor} is - * provided to create a LinkedHashMap whose order of iteration is the - * order in which its entries were last accessed, from least-recently accessed - * to most-recently (access-order). This kind of map is well-suited to + * provided to create a linked hash map whose order of iteration is the order + * in which its entries were last accessed, from least-recently accessed to + * most-recently (access-order). This kind of map is well-suited to * building LRU caches. Invoking the put or get method * results in an access to the corresponding entry (assuming it exists after * the invocation completes). The putAll method generates one entry @@ -155,18 +158,53 @@ import java.util.function.BiFunction; * @see Hashtable * @since 1.4 */ - public class LinkedHashMap extends HashMap implements Map { + /* + * Implementation note. A previous version of this class was + * internally structured a little differently. Because superclass + * HashMap now uses trees for some of its nodes, class + * LinkedHashMap.Entry is now treated as intermediary node class + * that can also be converted to tree form. The name of this + * class, LinkedHashMap.Entry, is confusing in several ways in its + * current context, but cannot be changed. Otherwise, even though + * it is not exported outside this package, some existing source + * code is known to have relied on a symbol resolution corner case + * rule in calls to removeEldestEntry that suppressed compilation + * errors due to ambiguous usages. So, we keep the name to + * preserve unmodified compilability. + * + * The changes in node classes also require using two fields + * (head, tail) rather than a pointer to a header node to maintain + * the doubly-linked before/after list. This class also + * previously used a different style of callback methods upon + * access, insertion, and removal. + */ + + /** + * HashMap.Node subclass for normal LinkedHashMap entries. + */ + static class Entry extends HashMap.Node { + Entry before, after; + Entry(int hash, K key, V value, Node next) { + super(hash, key, value, next); + } + } + private static final long serialVersionUID = 3801124242820219131L; /** - * The head of the doubly linked list. + * The head (eldest) of the doubly linked list. */ - private transient Entry header; + transient LinkedHashMap.Entry head; + + /** + * The tail (youngest) of the doubly linked list. + */ + transient LinkedHashMap.Entry tail; /** * The iteration ordering method for this linked hash map: true @@ -174,7 +212,125 @@ public class LinkedHashMap * * @serial */ - private final boolean accessOrder; + final boolean accessOrder; + + // internal utilities + + // link at the end of list + private void linkNodeLast(LinkedHashMap.Entry p) { + LinkedHashMap.Entry last = tail; + tail = p; + if (last == null) + head = p; + else { + p.before = last; + last.after = p; + } + } + + // apply src's links to dst + private void transferLinks(LinkedHashMap.Entry src, + LinkedHashMap.Entry dst) { + LinkedHashMap.Entry b = dst.before = src.before; + LinkedHashMap.Entry a = dst.after = src.after; + if (b == null) + head = dst; + else + b.after = dst; + if (a == null) + tail = dst; + else + a.before = dst; + } + + // overrides of HashMap hook methods + + void reinitialize() { + super.reinitialize(); + head = tail = null; + } + + Node newNode(int hash, K key, V value, Node e) { + LinkedHashMap.Entry p = + new LinkedHashMap.Entry(hash, key, value, e); + linkNodeLast(p); + return p; + } + + Node replacementNode(Node p, Node next) { + LinkedHashMap.Entry q = (LinkedHashMap.Entry)p; + LinkedHashMap.Entry t = + new LinkedHashMap.Entry(q.hash, q.key, q.value, next); + transferLinks(q, t); + return t; + } + + TreeNode newTreeNode(int hash, K key, V value, Node next) { + TreeNode p = new TreeNode(hash, key, value, next); + linkNodeLast(p); + return p; + } + + TreeNode replacementTreeNode(Node p, Node next) { + LinkedHashMap.Entry q = (LinkedHashMap.Entry)p; + TreeNode t = new TreeNode(q.hash, q.key, q.value, next); + transferLinks(q, t); + return t; + } + + void afterNodeRemoval(Node e) { // unlink + LinkedHashMap.Entry p = + (LinkedHashMap.Entry)e, b = p.before, a = p.after; + p.before = p.after = null; + if (b == null) + head = a; + else + b.after = a; + if (a == null) + tail = b; + else + a.before = b; + } + + void afterNodeInsertion(boolean evict) { // possibly remove eldest + LinkedHashMap.Entry first; + if (evict && (first = head) != null && removeEldestEntry(first)) { + K key = first.key; + removeNode(hash(key), key, null, false, true); + } + } + + void afterNodeAccess(Node e) { // move node to last + LinkedHashMap.Entry last; + if (accessOrder && (last = tail) != e) { + LinkedHashMap.Entry p = + (LinkedHashMap.Entry)e, b = p.before, a = p.after; + p.after = null; + if (b == null) + head = a; + else + b.after = a; + if (a != null) + a.before = b; + else + last = b; + if (last == null) + head = p; + else { + p.before = last; + last.after = p; + } + tail = p; + ++modCount; + } + } + + void internalWriteEntries(java.io.ObjectOutputStream s) throws IOException { + for (LinkedHashMap.Entry e = head; e != null; e = e.after) { + s.writeObject(e.key); + s.writeObject(e.value); + } + } /** * Constructs an empty insertion-ordered LinkedHashMap instance @@ -221,8 +377,9 @@ public class LinkedHashMap * @throws NullPointerException if the specified map is null */ public LinkedHashMap(Map m) { - super(m); + super(); accessOrder = false; + putMapEntries(m, false); } /** @@ -243,16 +400,6 @@ public class LinkedHashMap this.accessOrder = accessOrder; } - /** - * Called by superclass constructors and pseudoconstructors (clone, - * readObject) before any entries are inserted into the map. Initializes - * the chain. - */ - @Override - void init() { - header = new Entry<>(-1, null, null, null); - header.before = header.after = header; - } /** * Returns true if this map maps one or more keys to the @@ -263,15 +410,10 @@ public class LinkedHashMap * specified value */ public boolean containsValue(Object value) { - // Overridden to take advantage of faster iterator - if (value==null) { - for (Entry e = header.after; e != header; e = e.after) - if (e.value==null) - return true; - } else { - for (Entry e = header.after; e != header; e = e.after) - if (value.equals(e.value)) - return true; + for (LinkedHashMap.Entry e = head; e != null; e = e.after) { + V v = e.value; + if (v == value || (value != null && value.equals(v))) + return true; } return false; } @@ -292,10 +434,11 @@ public class LinkedHashMap * distinguish these two cases. */ public V get(Object key) { - Entry e = (Entry)getEntry(key); - if (e == null) + Node e; + if ((e = getNode(hash(key), key)) == null) return null; - e.recordAccess(this); + if (accessOrder) + afterNodeAccess(e); return e.value; } @@ -305,163 +448,7 @@ public class LinkedHashMap */ public void clear() { super.clear(); - header.before = header.after = header; - } - - @Override - public void forEach(BiConsumer action) { - Objects.requireNonNull(action); - int expectedModCount = modCount; - for (Entry entry = header.after; entry != header; entry = entry.after) { - action.accept(entry.key, entry.value); - - if (expectedModCount != modCount) { - throw new ConcurrentModificationException(); - } - } - } - - @Override - public void replaceAll(BiFunction function) { - Objects.requireNonNull(function); - int expectedModCount = modCount; - for (Entry entry = header.after; entry != header; entry = entry.after) { - entry.value = function.apply(entry.key, entry.value); - - if (expectedModCount != modCount) { - throw new ConcurrentModificationException(); - } - } - } - - /** - * LinkedHashMap entry. - */ - private static class Entry extends HashMap.Entry { - // These fields comprise the doubly linked list used for iteration. - Entry before, after; - - Entry(int hash, K key, V value, Object next) { - super(hash, key, value, next); - } - - /** - * Removes this entry from the linked list. - */ - private void remove() { - before.after = after; - after.before = before; - } - - /** - * Inserts this entry before the specified existing entry in the list. - */ - private void addBefore(Entry existingEntry) { - after = existingEntry; - before = existingEntry.before; - before.after = this; - after.before = this; - } - - /** - * This method is invoked by the superclass whenever the value - * of a pre-existing entry is read by Map.get or modified by Map.put. - * If the enclosing Map is access-ordered, it moves the entry - * to the end of the list; otherwise, it does nothing. - */ - void recordAccess(HashMap m) { - LinkedHashMap lm = (LinkedHashMap)m; - if (lm.accessOrder) { - lm.modCount++; - remove(); - addBefore(lm.header); - } - } - - void recordRemoval(HashMap m) { - remove(); - } - } - - private abstract class LinkedHashIterator implements Iterator { - Entry nextEntry = header.after; - Entry lastReturned = null; - - /** - * The modCount value that the iterator believes that the backing - * List should have. If this expectation is violated, the iterator - * has detected concurrent modification. - */ - int expectedModCount = modCount; - - public boolean hasNext() { - return nextEntry != header; - } - - public void remove() { - if (lastReturned == null) - throw new IllegalStateException(); - if (modCount != expectedModCount) - throw new ConcurrentModificationException(); - - LinkedHashMap.this.remove(lastReturned.key); - lastReturned = null; - expectedModCount = modCount; - } - - Entry nextEntry() { - if (modCount != expectedModCount) - throw new ConcurrentModificationException(); - if (nextEntry == header) - throw new NoSuchElementException(); - - Entry e = lastReturned = nextEntry; - nextEntry = e.after; - return e; - } - } - - private class KeyIterator extends LinkedHashIterator { - public K next() { return nextEntry().getKey(); } - } - - private class ValueIterator extends LinkedHashIterator { - public V next() { return nextEntry().value; } - } - - private class EntryIterator extends LinkedHashIterator> { - public Map.Entry next() { return nextEntry(); } - } - - // These Overrides alter the behavior of superclass view iterator() methods - Iterator newKeyIterator() { return new KeyIterator(); } - Iterator newValueIterator() { return new ValueIterator(); } - Iterator> newEntryIterator() { return new EntryIterator(); } - - /** - * This override alters behavior of superclass put method. It causes newly - * allocated entry to get inserted at the end of the linked list and - * removes the eldest entry if appropriate. - */ - @Override - void addEntry(int hash, K key, V value, int bucketIndex, boolean checkIfNeedTree) { - super.addEntry(hash, key, value, bucketIndex, checkIfNeedTree); - - // Remove eldest entry if instructed - Entry eldest = header.after; - if (removeEldestEntry(eldest)) { - removeEntryForKey(eldest.key); - } - } - - /* - * Create a new LinkedHashMap.Entry and setup the before/after pointers - */ - @Override - HashMap.Entry newEntry(int hash, K key, V value, Object next) { - Entry newEntry = new Entry<>(hash, key, value, next); - newEntry.addBefore(header); - return newEntry; + head = tail = null; } /** @@ -475,13 +462,13 @@ public class LinkedHashMap *

    Sample use: this override will allow the map to grow up to 100 * entries and then delete the eldest entry each time a new entry is * added, maintaining a steady state of 100 entries. - *

    {@code
    +     * 
          *     private static final int MAX_ENTRIES = 100;
          *
          *     protected boolean removeEldestEntry(Map.Entry eldest) {
    -     *        return size() > MAX_ENTRIES;
    +     *        return size() > MAX_ENTRIES;
          *     }
    -     * }
    + *
    * *

    This method typically does not modify the map in any way, * instead allowing the map to modify itself as directed by its @@ -508,4 +495,241 @@ public class LinkedHashMap protected boolean removeEldestEntry(Map.Entry eldest) { return false; } + + /** + * Returns a {@link Set} view of the keys contained in this map. + * The set is backed by the map, so changes to the map are + * reflected in the set, and vice-versa. If the map is modified + * while an iteration over the set is in progress (except through + * the iterator's own remove operation), the results of + * the iteration are undefined. The set supports element removal, + * which removes the corresponding mapping from the map, via the + * Iterator.remove, Set.remove, + * removeAll, retainAll, and clear + * operations. It does not support the add or addAll + * operations. + * Its {@link Spliterator} typically provides faster sequential + * performance but much poorer parallel performance than that of + * {@code HashMap}. + * + * @return a set view of the keys contained in this map + */ + public Set keySet() { + Set ks; + return (ks = keySet) == null ? (keySet = new LinkedKeySet()) : ks; + } + + final class LinkedKeySet extends AbstractSet { + public final int size() { return size; } + public final void clear() { LinkedHashMap.this.clear(); } + public final Iterator iterator() { + return new LinkedKeyIterator(); + } + public final boolean contains(Object o) { return containsKey(o); } + public final boolean remove(Object key) { + return removeNode(hash(key), key, null, false, true) != null; + } + public final Spliterator spliterator() { + return Spliterators.spliterator(this, Spliterator.SIZED | + Spliterator.ORDERED | + Spliterator.DISTINCT); + } + public final void forEach(Consumer action) { + if (action == null) + throw new NullPointerException(); + int mc = modCount; + for (LinkedHashMap.Entry e = head; e != null; e = e.after) + action.accept(e.key); + if (modCount != mc) + throw new ConcurrentModificationException(); + } + } + + /** + * Returns a {@link Collection} view of the values contained in this map. + * The collection is backed by the map, so changes to the map are + * reflected in the collection, and vice-versa. If the map is + * modified while an iteration over the collection is in progress + * (except through the iterator's own remove operation), + * the results of the iteration are undefined. The collection + * supports element removal, which removes the corresponding + * mapping from the map, via the Iterator.remove, + * Collection.remove, removeAll, + * retainAll and clear operations. It does not + * support the add or addAll operations. + * Its {@link Spliterator} typically provides faster sequential + * performance but much poorer parallel performance than that of + * {@code HashMap}. + * + * @return a view of the values contained in this map + */ + public Collection values() { + Collection vs; + return (vs = values) == null ? (values = new LinkedValues()) : vs; + } + + final class LinkedValues extends AbstractCollection { + public final int size() { return size; } + public final void clear() { LinkedHashMap.this.clear(); } + public final Iterator iterator() { + return new LinkedValueIterator(); + } + public final boolean contains(Object o) { return containsValue(o); } + public final Spliterator spliterator() { + return Spliterators.spliterator(this, Spliterator.SIZED | + Spliterator.ORDERED); + } + public final void forEach(Consumer action) { + if (action == null) + throw new NullPointerException(); + int mc = modCount; + for (LinkedHashMap.Entry e = head; e != null; e = e.after) + action.accept(e.value); + if (modCount != mc) + throw new ConcurrentModificationException(); + } + } + + /** + * Returns a {@link Set} view of the mappings contained in this map. + * The set is backed by the map, so changes to the map are + * reflected in the set, and vice-versa. If the map is modified + * while an iteration over the set is in progress (except through + * the iterator's own remove operation, or through the + * setValue operation on a map entry returned by the + * iterator) the results of the iteration are undefined. The set + * supports element removal, which removes the corresponding + * mapping from the map, via the Iterator.remove, + * Set.remove, removeAll, retainAll and + * clear operations. It does not support the + * add or addAll operations. + * Its {@link Spliterator} typically provides faster sequential + * performance but much poorer parallel performance than that of + * {@code HashMap}. + * + * @return a set view of the mappings contained in this map + */ + public Set> entrySet() { + Set> es; + return (es = entrySet) == null ? (entrySet = new LinkedEntrySet()) : es; + } + + final class LinkedEntrySet extends AbstractSet> { + public final int size() { return size; } + public final void clear() { LinkedHashMap.this.clear(); } + public final Iterator> iterator() { + return new LinkedEntryIterator(); + } + public final boolean contains(Object o) { + if (!(o instanceof Map.Entry)) + return false; + Map.Entry e = (Map.Entry) o; + Object key = e.getKey(); + Node candidate = getNode(hash(key), key); + return candidate != null && candidate.equals(e); + } + public final boolean remove(Object o) { + if (o instanceof Map.Entry) { + Map.Entry e = (Map.Entry) o; + Object key = e.getKey(); + Object value = e.getValue(); + return removeNode(hash(key), key, value, true, true) != null; + } + return false; + } + public final Spliterator> spliterator() { + return Spliterators.spliterator(this, Spliterator.SIZED | + Spliterator.ORDERED | + Spliterator.DISTINCT); + } + public final void forEach(Consumer> action) { + if (action == null) + throw new NullPointerException(); + int mc = modCount; + for (LinkedHashMap.Entry e = head; e != null; e = e.after) + action.accept(e); + if (modCount != mc) + throw new ConcurrentModificationException(); + } + } + + // Map overrides + + public void forEach(BiConsumer action) { + if (action == null) + throw new NullPointerException(); + int mc = modCount; + for (LinkedHashMap.Entry e = head; e != null; e = e.after) + action.accept(e.key, e.value); + if (modCount != mc) + throw new ConcurrentModificationException(); + } + + public void replaceAll(BiFunction function) { + if (function == null) + throw new NullPointerException(); + int mc = modCount; + for (LinkedHashMap.Entry e = head; e != null; e = e.after) + e.value = function.apply(e.key, e.value); + if (modCount != mc) + throw new ConcurrentModificationException(); + } + + // Iterators + + abstract class LinkedHashIterator { + LinkedHashMap.Entry next; + LinkedHashMap.Entry current; + int expectedModCount; + + LinkedHashIterator() { + next = head; + expectedModCount = modCount; + current = null; + } + + public final boolean hasNext() { + return next != null; + } + + final LinkedHashMap.Entry nextNode() { + LinkedHashMap.Entry e = next; + if (modCount != expectedModCount) + throw new ConcurrentModificationException(); + if (e == null) + throw new NoSuchElementException(); + current = e; + next = e.after; + return e; + } + + public final void remove() { + Node p = current; + if (p == null) + throw new IllegalStateException(); + if (modCount != expectedModCount) + throw new ConcurrentModificationException(); + current = null; + K key = p.key; + removeNode(hash(key), key, null, false, false); + expectedModCount = modCount; + } + } + + final class LinkedKeyIterator extends LinkedHashIterator + implements Iterator { + public final K next() { return nextNode().getKey(); } + } + + final class LinkedValueIterator extends LinkedHashIterator + implements Iterator { + public final V next() { return nextNode().value; } + } + + final class LinkedEntryIterator extends LinkedHashIterator + implements Iterator> { + public final Map.Entry next() { return nextNode(); } + } + + } diff --git a/jdk/test/java/lang/reflect/Generics/Probe.java b/jdk/test/java/lang/reflect/Generics/Probe.java index 1cdd5af3bdd..ebd98465e0c 100644 --- a/jdk/test/java/lang/reflect/Generics/Probe.java +++ b/jdk/test/java/lang/reflect/Generics/Probe.java @@ -50,9 +50,9 @@ import static java.util.Arrays.*; "java.util.HashMap$EntryIterator", "java.util.HashMap$KeyIterator", "java.util.HashMap$ValueIterator", - "java.util.LinkedHashMap$EntryIterator", - "java.util.LinkedHashMap$KeyIterator", - "java.util.LinkedHashMap$ValueIterator"}) + "java.util.LinkedHashMap$LinkedEntryIterator", + "java.util.LinkedHashMap$LinkedKeyIterator", + "java.util.LinkedHashMap$LinkedValueIterator"}) public class Probe { public static void main (String... args) throws Throwable { Classes classesAnnotation = (Probe.class).getAnnotation(Classes.class); diff --git a/jdk/test/java/util/Map/CheckRandomHashSeed.java b/jdk/test/java/util/Map/CheckRandomHashSeed.java index 5395ec999ee..2acf1bc8c9c 100644 --- a/jdk/test/java/util/Map/CheckRandomHashSeed.java +++ b/jdk/test/java/util/Map/CheckRandomHashSeed.java @@ -53,8 +53,6 @@ public class CheckRandomHashSeed { throw new Error("Error in test setup: " + (expectRandom ? "" : "not " ) + "expecting random hashSeed, but " + PROP_NAME + " is " + (propSet ? "" : "not ") + "enabled"); } - testMap(new HashMap()); - testMap(new LinkedHashMap()); testMap(new WeakHashMap()); testMap(new Hashtable()); } diff --git a/jdk/test/java/util/Map/InPlaceOpsCollisions.java b/jdk/test/java/util/Map/InPlaceOpsCollisions.java index 4a755bd4415..e24ba6ac508 100644 --- a/jdk/test/java/util/Map/InPlaceOpsCollisions.java +++ b/jdk/test/java/util/Map/InPlaceOpsCollisions.java @@ -25,7 +25,6 @@ * @test * @bug 8005698 * @run main InPlaceOpsCollisions -shortrun - * @run main/othervm -Djdk.map.randomseed=true InPlaceOpsCollisions -shortrun * @summary Ensure overrides of in-place operations in Maps behave well with lots of collisions. * @author Brent Christian */ diff --git a/jdk/test/java/util/Map/MapBinToFromTreeTest.java b/jdk/test/java/util/Map/MapBinToFromTreeTest.java new file mode 100644 index 00000000000..0b40a4ef16e --- /dev/null +++ b/jdk/test/java/util/Map/MapBinToFromTreeTest.java @@ -0,0 +1,240 @@ +/* + * Copyright (c) 2013, 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 org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import java.util.Collection; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.BiConsumer; +import java.util.stream.Collector; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +import static org.testng.Assert.assertEquals; + +/* + * @test + * @bug 8023463 + * @summary Test the case where a bin is treeified and vice verser + * @run testng MapBinToFromTreeTest + */ + +@Test +public class MapBinToFromTreeTest { + + // Initial capacity of map + // Should be >= the map capacity for treeifiying, see HashMap/ConcurrentMap.MIN_TREEIFY_CAPACITY + static final int INITIAL_CAPACITY = 64; + + // Maximum size of map + // Should be > the treeify threshold, see HashMap/ConcurrentMap.TREEIFY_THRESHOLD + // Should be > INITIAL_CAPACITY to ensure resize occurs + static final int SIZE = 256; + + // Load factor of map + // A value 1.0 will ensure that a new threshold == capacity + static final float LOAD_FACTOR = 1.0f; + + @DataProvider(name = "maps") + static Object[][] mapProvider() { + return new Object[][] { + // Pass in the class name as a description for test reporting + // purposes + { HashMap.class.getName(), new HashMap(INITIAL_CAPACITY, LOAD_FACTOR) }, + { LinkedHashMap.class.getName(), new LinkedHashMap(INITIAL_CAPACITY, LOAD_FACTOR) }, + { ConcurrentHashMap.class.getName(), new ConcurrentHashMap(INITIAL_CAPACITY, LOAD_FACTOR) }, + }; + } + + @Test(dataProvider = "maps") + public void testPutThenGet(String d, Map m) { + put(SIZE, m, (i, s) -> { + for (int j = 0; j < s; j++) { + assertEquals(m.get(new HashCodeInteger(j)).intValue(), j, + String.format("Map.get(%d)", j)); + } + }); + } + + @Test(dataProvider = "maps") + public void testPutThenTraverse(String d, Map m) { + Collector> c = getCollector(m); + + put(SIZE, m, (i, s) -> { + // Note that it is OK to collect to a Set (HashSet) as long as + // integer values are used since these tests only check for + // collisions and other tests will verify more general functionality + Collection actual = m.keySet().stream().map(e -> e.value).collect(c); + Collection expected = IntStream.range(0, s).boxed().collect(c); + assertEquals(actual, expected, "Map.keySet()"); + }); + } + + @Test(dataProvider = "maps") + public void testRemoveThenGet(String d, Map m) { + put(SIZE, m, (i, s) -> { }); + + remove(m, (i, s) -> { + for (int j = i + 1; j < SIZE; j++) { + assertEquals(m.get(new HashCodeInteger(j)).intValue(), j, + String.format("Map.get(%d)", j)); + } + }); + } + + @Test(dataProvider = "maps") + public void testRemoveThenTraverse(String d, Map m) { + put(SIZE, m, (i, s) -> { }); + + Collector> c = getCollector(m); + + remove(m, (i, s) -> { + Collection actual = m.keySet().stream().map(e -> e.value).collect(c); + Collection expected = IntStream.range(i + 1, SIZE).boxed().collect(c); + assertEquals(actual, expected, "Map.keySet()"); + }); + } + + @Test(dataProvider = "maps") + public void testUntreeifyOnResizeWithGet(String d, Map m) { + // Fill the map with 64 entries grouped into 4 buckets + put(INITIAL_CAPACITY, m, (i, s) -> { }); + + for (int i = INITIAL_CAPACITY; i < SIZE; i++) { + // Add further entries in the 0'th bucket so as not to disturb + // other buckets, entries of which may be distributed and/or + // the bucket untreeified on resize + m.put(new HashCodeInteger(i, 0), i); + + for (int j = 0; j < INITIAL_CAPACITY; j++) { + assertEquals(m.get(new HashCodeInteger(j)).intValue(), j, + String.format("Map.get(%d) < INITIAL_CAPACITY", j)); + } + for (int j = INITIAL_CAPACITY; j <= i; j++) { + assertEquals(m.get(new HashCodeInteger(j, 0)).intValue(), j, + String.format("Map.get(%d) >= INITIAL_CAPACITY", j)); + } + } + } + + @Test(dataProvider = "maps") + public void testUntreeifyOnResizeWithTraverse(String d, Map m) { + // Fill the map with 64 entries grouped into 4 buckets + put(INITIAL_CAPACITY, m, (i, s) -> { }); + + Collector> c = getCollector(m); + + for (int i = INITIAL_CAPACITY; i < SIZE; i++) { + // Add further entries in the 0'th bucket so as not to disturb + // other buckets, entries of which may be distributed and/or + // the bucket untreeified on resize + m.put(new HashCodeInteger(i, 0), i); + + Collection actual = m.keySet().stream().map(e -> e.value).collect(c); + Collection expected = IntStream.rangeClosed(0, i).boxed().collect(c); + assertEquals(actual, expected, "Key set"); + } + } + + Collector> getCollector(Map m) { + Collector> collector = m instanceof LinkedHashMap + ? Collectors.toList() + : Collectors.toSet(); + return collector; + } + + void put(int size, Map m, BiConsumer c) { + for (int i = 0; i < size; i++) { + m.put(new HashCodeInteger(i), i); + + c.accept(i, m.size()); + } + } + + void remove(Map m, BiConsumer c) { + int size = m.size(); + // Remove all elements thus ensuring at some point trees will be + // converting back to bins + for (int i = 0; i < size; i++) { + m.remove(new HashCodeInteger(i)); + + c.accept(i, m.size()); + } + } + + final static class HashCodeInteger implements Comparable { + final int value; + + final int hashcode; + + HashCodeInteger(int value) { + this(value, hash(value)); + } + + HashCodeInteger(int value, int hashcode) { + this.value = value; + this.hashcode = hashcode; + } + + static int hash(int i) { + // Assuming 64 entries with keys from 0 to 63 then a map: + // - of capacity 64 will have 4 buckets with 16 entries per-bucket + // - of capacity 128 will have 8 buckets with 8 entries per-bucket + // - of capacity 256 will have 16 buckets with 4 entries per-bucket + // + // Re-sizing will result in re-distribution, doubling the buckets + // and reducing the entries by half. This will result in + // untreeifying when the number of entries is less than untreeify + // threshold (see HashMap/ConcurrentMap.UNTREEIFY_THRESHOLD) + return (i % 4) + (i / 4) * INITIAL_CAPACITY; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof HashCodeInteger) { + HashCodeInteger other = (HashCodeInteger) obj; + return other.value == value; + } + return false; + } + + @Override + public int hashCode() { + return hashcode; + } + + @Override + public int compareTo(HashCodeInteger o) { + return value - o.value; + } + + @Override + public String toString() { + return Integer.toString(value); + } + } +} diff --git a/jdk/test/java/util/Map/TreeBinSplitBackToEntries.java b/jdk/test/java/util/Map/TreeBinSplitBackToEntries.java deleted file mode 100644 index 6093147a24d..00000000000 --- a/jdk/test/java/util/Map/TreeBinSplitBackToEntries.java +++ /dev/null @@ -1,255 +0,0 @@ -/* - * Copyright (c) 2013, 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.*; -import java.lang.reflect.Field; - -/* - * @test - * @bug 8005698 - * @summary Test the case where TreeBin.splitTreeBin() converts a bin back to an Entry list - * @run main TreeBinSplitBackToEntries unused - * @author Brent Christian - */ - -public class TreeBinSplitBackToEntries { - private static int EXPECTED_TREE_THRESHOLD = 16; - - // Easiest if this covers one bit higher then 'bit' in splitTreeBin() on the - // call where the TreeBin is converted back to an Entry list - private static int HASHMASK = 0x7F; - private static boolean verbose = false; - private static boolean fastFail = false; - private static boolean failed = false; - - static void printlnIfVerbose(String msg) { - if (verbose) {System.out.println(msg); } - } - - public static void main(String[] args) { - for (String arg : args) { - switch(arg) { - case "-verbose": - verbose = true; - break; - case "-fastfail": - fastFail = true; - break; - } - } - checkTreeThreshold(); - testMapHiTree(); - testMapLoTree(); - if (failed) { - System.out.println("Test Failed"); - System.exit(1); - } else { - System.out.println("Test Passed"); - } - } - - public static void checkTreeThreshold() { - int threshold = -1; - try { - Class treeBinClass = Class.forName("java.util.HashMap$TreeBin"); - Field treeThreshold = treeBinClass.getDeclaredField("TREE_THRESHOLD"); - treeThreshold.setAccessible(true); - threshold = treeThreshold.getInt(treeBinClass); - } catch (ClassNotFoundException|NoSuchFieldException|IllegalAccessException e) { - e.printStackTrace(); - throw new Error("Problem accessing TreeBin.TREE_THRESHOLD", e); - } - check("Expected TREE_THRESHOLD: " + EXPECTED_TREE_THRESHOLD +", found: " + threshold, - threshold == EXPECTED_TREE_THRESHOLD); - printlnIfVerbose("TREE_THRESHOLD: " + threshold); - } - - public static void testMapHiTree() { - Object[][] mapKeys = makeHiTreeTestData(); - testMapsForKeys(mapKeys, "hiTree"); - } - - public static void testMapLoTree() { - Object[][] mapKeys = makeLoTreeTestData(); - - testMapsForKeys(mapKeys, "loTree"); - } - - public static void testMapsForKeys(Object[][] mapKeys, String desc) { - // loop through data sets - for (Object[] keys_desc : mapKeys) { - Map[] maps = (Map[]) new Map[]{ - new HashMap<>(4, 0.8f), - new LinkedHashMap<>(4, 0.8f), - }; - // for each map type. - for (Map map : maps) { - Object[] keys = (Object[]) keys_desc[1]; - System.out.println(desc + ": testPutThenGet() for " + map.getClass()); - testPutThenGet(map, keys); - } - } - } - - private static void testPutThenGet(Map map, T[] keys) { - for (T key : keys) { - printlnIfVerbose("put()ing 0x" + Integer.toHexString(Integer.parseInt(key.toString())) + ", hashCode=" + Integer.toHexString(key.hashCode())); - map.put(key, key); - } - for (T key : keys) { - check("key: 0x" + Integer.toHexString(Integer.parseInt(key.toString())) + " not found in resulting " + map.getClass().getSimpleName(), map.get(key) != null); - } - } - - /* Data to force a non-empty loTree in TreeBin.splitTreeBin() to be converted back - * into an Entry list - */ - private static Object[][] makeLoTreeTestData() { - HashableInteger COLLIDING_OBJECTS[] = new HashableInteger[] { - new HashableInteger( 0x23, HASHMASK), - new HashableInteger( 0x123, HASHMASK), - new HashableInteger( 0x323, HASHMASK), - new HashableInteger( 0x523, HASHMASK), - - new HashableInteger( 0x723, HASHMASK), - new HashableInteger( 0x923, HASHMASK), - new HashableInteger( 0xB23, HASHMASK), - new HashableInteger( 0xD23, HASHMASK), - - new HashableInteger( 0xF23, HASHMASK), - new HashableInteger( 0xF123, HASHMASK), - new HashableInteger( 0x1023, HASHMASK), - new HashableInteger( 0x1123, HASHMASK), - - new HashableInteger( 0x1323, HASHMASK), - new HashableInteger( 0x1523, HASHMASK), - new HashableInteger( 0x1723, HASHMASK), - new HashableInteger( 0x1923, HASHMASK), - - new HashableInteger( 0x1B23, HASHMASK), - new HashableInteger( 0x1D23, HASHMASK), - new HashableInteger( 0x3123, HASHMASK), - new HashableInteger( 0x3323, HASHMASK), - new HashableInteger( 0x3523, HASHMASK), - - new HashableInteger( 0x3723, HASHMASK), - new HashableInteger( 0x1001, HASHMASK), - new HashableInteger( 0x4001, HASHMASK), - new HashableInteger( 0x1, HASHMASK), - }; - return new Object[][] { - new Object[]{"Colliding Objects", COLLIDING_OBJECTS}, - }; - } - - /* Data to force the hiTree in TreeBin.splitTreeBin() to be converted back - * into an Entry list - */ - private static Object[][] makeHiTreeTestData() { - HashableInteger COLLIDING_OBJECTS[] = new HashableInteger[] { - new HashableInteger( 0x1, HASHMASK), - new HashableInteger( 0x101, HASHMASK), - new HashableInteger( 0x301, HASHMASK), - new HashableInteger( 0x501, HASHMASK), - new HashableInteger( 0x701, HASHMASK), - - new HashableInteger( 0x1001, HASHMASK), - new HashableInteger( 0x1101, HASHMASK), - new HashableInteger( 0x1301, HASHMASK), - - new HashableInteger( 0x1501, HASHMASK), - new HashableInteger( 0x1701, HASHMASK), - new HashableInteger( 0x4001, HASHMASK), - new HashableInteger( 0x4101, HASHMASK), - new HashableInteger( 0x4301, HASHMASK), - - new HashableInteger( 0x4501, HASHMASK), - new HashableInteger( 0x4701, HASHMASK), - new HashableInteger( 0x8001, HASHMASK), - new HashableInteger( 0x8101, HASHMASK), - - - new HashableInteger( 0x8301, HASHMASK), - new HashableInteger( 0x8501, HASHMASK), - new HashableInteger( 0x8701, HASHMASK), - new HashableInteger( 0x9001, HASHMASK), - - new HashableInteger( 0x23, HASHMASK), - new HashableInteger( 0x123, HASHMASK), - new HashableInteger( 0x323, HASHMASK), - new HashableInteger( 0x523, HASHMASK), - }; - return new Object[][] { - new Object[]{"Colliding Objects", COLLIDING_OBJECTS}, - }; - } - - static void check(String desc, boolean cond) { - if (!cond) { - fail(desc); - } - } - - static void fail(String msg) { - failed = true; - (new Error("Failure: " + msg)).printStackTrace(System.err); - if (fastFail) { - System.exit(1); - } - } - - final static class HashableInteger implements Comparable { - final int value; - final int hashmask; //yes duplication - - HashableInteger(int value, int hashmask) { - this.value = value; - this.hashmask = hashmask; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof HashableInteger) { - HashableInteger other = (HashableInteger) obj; - return other.value == value; - } - return false; - } - - @Override - public int hashCode() { - // This version ANDs the mask - return value & hashmask; - } - - @Override - public int compareTo(HashableInteger o) { - return value - o.value; - } - - @Override - public String toString() { - return Integer.toString(value); - } - } -} diff --git a/jdk/test/java/util/Spliterator/SpliteratorCharacteristics.java b/jdk/test/java/util/Spliterator/SpliteratorCharacteristics.java index bb0b7ecd976..3c74ce29dc1 100644 --- a/jdk/test/java/util/Spliterator/SpliteratorCharacteristics.java +++ b/jdk/test/java/util/Spliterator/SpliteratorCharacteristics.java @@ -23,7 +23,7 @@ /** * @test - * @bug 8020156 8020009 8022326 + * @bug 8020156 8020009 8022326 8012913 * @run testng SpliteratorCharacteristics */ @@ -32,6 +32,10 @@ import org.testng.annotations.Test; import java.util.Arrays; import java.util.Collection; import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; import java.util.SortedMap; @@ -47,7 +51,27 @@ import static org.testng.Assert.*; @Test public class SpliteratorCharacteristics { - // TreeMap + public void testHashMap() { + assertMapCharacteristics(new HashMap<>(), + Spliterator.SIZED | Spliterator.DISTINCT); + } + + public void testHashSet() { + assertSetCharacteristics(new HashSet<>(), + Spliterator.SIZED | Spliterator.DISTINCT); + } + + public void testLinkedHashMap() { + assertMapCharacteristics(new LinkedHashMap<>(), + Spliterator.SIZED | Spliterator.DISTINCT | + Spliterator.ORDERED); + } + + public void testLinkedHashSet() { + assertSetCharacteristics(new LinkedHashSet<>(), + Spliterator.SIZED | Spliterator.DISTINCT | + Spliterator.ORDERED); + } public void testTreeMap() { assertSortedMapCharacteristics(new TreeMap<>(), @@ -61,9 +85,6 @@ public class SpliteratorCharacteristics { Spliterator.SORTED | Spliterator.ORDERED); } - - // TreeSet - public void testTreeSet() { assertSortedSetCharacteristics(new TreeSet<>(), Spliterator.SIZED | Spliterator.DISTINCT | @@ -76,9 +97,6 @@ public class SpliteratorCharacteristics { Spliterator.SORTED | Spliterator.ORDERED); } - - // ConcurrentSkipListMap - public void testConcurrentSkipListMap() { assertSortedMapCharacteristics(new ConcurrentSkipListMap<>(), Spliterator.CONCURRENT | Spliterator.NONNULL | @@ -93,9 +111,6 @@ public class SpliteratorCharacteristics { Spliterator.ORDERED); } - - // ConcurrentSkipListSet - public void testConcurrentSkipListSet() { assertSortedSetCharacteristics(new ConcurrentSkipListSet<>(), Spliterator.CONCURRENT | Spliterator.NONNULL | @@ -113,35 +128,58 @@ public class SpliteratorCharacteristics { // - void assertSortedMapCharacteristics(SortedMap m, int keyCharacteristics) { + + void assertMapCharacteristics(Map m, int keyCharacteristics) { + assertMapCharacteristics(m, keyCharacteristics, 0); + } + + void assertMapCharacteristics(Map m, int keyCharacteristics, int notValueCharacteristics) { initMap(m); - boolean hasComparator = m.comparator() != null; + assertCharacteristics(m.keySet(), keyCharacteristics); + + assertCharacteristics(m.values(), + keyCharacteristics & ~(Spliterator.DISTINCT | notValueCharacteristics)); + + assertCharacteristics(m.entrySet(), keyCharacteristics); + + if ((keyCharacteristics & Spliterator.SORTED) == 0) { + assertISEComparator(m.keySet()); + assertISEComparator(m.values()); + assertISEComparator(m.entrySet()); + } + } + + void assertSetCharacteristics(Set s, int keyCharacteristics) { + initSet(s); + + assertCharacteristics(s, keyCharacteristics); + + if ((keyCharacteristics & Spliterator.SORTED) == 0) { + assertISEComparator(s); + } + } + + void assertSortedMapCharacteristics(SortedMap m, int keyCharacteristics) { + assertMapCharacteristics(m, keyCharacteristics, Spliterator.SORTED); Set keys = m.keySet(); - assertCharacteristics(keys, keyCharacteristics); - if (hasComparator) { + if (m.comparator() != null) { assertNotNullComparator(keys); } else { assertNullComparator(keys); } - assertCharacteristics(m.values(), - keyCharacteristics & ~(Spliterator.DISTINCT | Spliterator.SORTED)); assertISEComparator(m.values()); - assertCharacteristics(m.entrySet(), keyCharacteristics); assertNotNullComparator(m.entrySet()); } void assertSortedSetCharacteristics(SortedSet s, int keyCharacteristics) { - initSet(s); + assertSetCharacteristics(s, keyCharacteristics); - boolean hasComparator = s.comparator() != null; - - assertCharacteristics(s, keyCharacteristics); - if (hasComparator) { + if (s.comparator() != null) { assertNotNullComparator(s); } else { @@ -161,27 +199,18 @@ public class SpliteratorCharacteristics { } void assertCharacteristics(Collection c, int expectedCharacteristics) { - assertCharacteristics(c.spliterator(), expectedCharacteristics); - } - - void assertCharacteristics(Spliterator s, int expectedCharacteristics) { - assertTrue(s.hasCharacteristics(expectedCharacteristics)); + assertTrue(c.spliterator().hasCharacteristics(expectedCharacteristics), + "Spliterator characteristics"); } void assertNullComparator(Collection c) { - assertNullComparator(c.spliterator()); - } - - void assertNullComparator(Spliterator s) { - assertNull(s.getComparator()); + assertNull(c.spliterator().getComparator(), + "Comparator of Spliterator of Collection"); } void assertNotNullComparator(Collection c) { - assertNotNullComparator(c.spliterator()); - } - - void assertNotNullComparator(Spliterator s) { - assertNotNull(s.getComparator()); + assertNotNull(c.spliterator().getComparator(), + "Comparator of Spliterator of Collection"); } void assertISEComparator(Collection c) { @@ -196,6 +225,6 @@ public class SpliteratorCharacteristics { catch (IllegalStateException e) { caught = true; } - assertTrue(caught); + assertTrue(caught, "Throwing IllegalStateException"); } } From cc84e69bec97b188b4b93a74a3d9f104d71cda08 Mon Sep 17 00:00:00 2001 From: Alan Bateman Date: Wed, 4 Sep 2013 11:40:23 +0100 Subject: [PATCH 031/210] 8008981: Deprecate SecurityManager checkTopLevelWindow, checkSystemClipboardAccess, checkAwtEventQueueAccess Reviewed-by: anthony, art, mchung --- .../macosx/classes/sun/lwawt/LWToolkit.java | 3 +- .../share/classes/java/awt/TextComponent.java | 3 +- jdk/src/share/classes/java/awt/Toolkit.java | 36 ++---- jdk/src/share/classes/java/awt/Window.java | 80 ++++++-------- .../classes/java/awt/event/InputEvent.java | 3 +- .../classes/java/lang/SecurityManager.java | 21 ++++ .../classes/sun/applet/AppletSecurity.java | 2 +- .../sun/awt/dnd/SunDropTargetContextPeer.java | 3 +- .../classes/sun/swing/SwingUtilities2.java | 2 +- .../solaris/classes/sun/awt/X11/XToolkit.java | 5 +- .../classes/sun/awt/windows/WToolkit.java | 3 +- jdk/test/java/awt/security/Permissions.java | 103 ++++++++++++++++++ 12 files changed, 181 insertions(+), 83 deletions(-) create mode 100644 jdk/test/java/awt/security/Permissions.java diff --git a/jdk/src/macosx/classes/sun/lwawt/LWToolkit.java b/jdk/src/macosx/classes/sun/lwawt/LWToolkit.java index fb7032f0b74..9765066d9d2 100644 --- a/jdk/src/macosx/classes/sun/lwawt/LWToolkit.java +++ b/jdk/src/macosx/classes/sun/lwawt/LWToolkit.java @@ -38,6 +38,7 @@ import java.util.*; import sun.awt.*; import sun.lwawt.macosx.*; import sun.print.*; +import sun.security.util.SecurityConstants; public abstract class LWToolkit extends SunToolkit implements Runnable { @@ -502,7 +503,7 @@ public abstract class LWToolkit extends SunToolkit implements Runnable { public Clipboard getSystemClipboard() { SecurityManager security = System.getSecurityManager(); if (security != null) { - security.checkSystemClipboardAccess(); + security.checkPermission(SecurityConstants.AWT.ACCESS_CLIPBOARD_PERMISSION); } synchronized (this) { diff --git a/jdk/src/share/classes/java/awt/TextComponent.java b/jdk/src/share/classes/java/awt/TextComponent.java index 7a6cd26bbf3..483657fd4ce 100644 --- a/jdk/src/share/classes/java/awt/TextComponent.java +++ b/jdk/src/share/classes/java/awt/TextComponent.java @@ -35,6 +35,7 @@ import java.text.BreakIterator; import javax.swing.text.AttributeSet; import javax.accessibility.*; import java.awt.im.InputMethodRequests; +import sun.security.util.SecurityConstants; /** * The TextComponent class is the superclass of @@ -728,7 +729,7 @@ public class TextComponent extends Component implements Accessible { SecurityManager sm = System.getSecurityManager(); if (sm == null) return true; try { - sm.checkSystemClipboardAccess(); + sm.checkPermission(SecurityConstants.AWT.ACCESS_CLIPBOARD_PERMISSION); return true; } catch (SecurityException e) {} return false; diff --git a/jdk/src/share/classes/java/awt/Toolkit.java b/jdk/src/share/classes/java/awt/Toolkit.java index 92bedb7580b..32f0adab3bc 100644 --- a/jdk/src/share/classes/java/awt/Toolkit.java +++ b/jdk/src/share/classes/java/awt/Toolkit.java @@ -1270,12 +1270,8 @@ public abstract class Toolkit { *

    * Each actual implementation of this method should first check if there * is a security manager installed. If there is, the method should call - * the security manager's checkSystemClipboardAccess method - * to ensure it's ok to to access the system clipboard. If the default - * implementation of checkSystemClipboardAccess is used (that - * is, that method is not overriden), then this results in a call to the - * security manager's checkPermission method with an - * AWTPermission("accessClipboard") permission. + * the security manager's {@link SecurityManager#checkPermission + * checkPermission} method to check {@code AWTPermission("accessClipboard")}. * * @return the system Clipboard * @exception HeadlessException if GraphicsEnvironment.isHeadless() @@ -1318,14 +1314,9 @@ public abstract class Toolkit { * system selection Clipboard as described above. *

    * Each actual implementation of this method should first check if there - * is a SecurityManager installed. If there is, the method - * should call the SecurityManager's - * checkSystemClipboardAccess method to ensure that client - * code has access the system selection. If the default implementation of - * checkSystemClipboardAccess is used (that is, if the method - * is not overridden), then this results in a call to the - * SecurityManager's checkPermission method with - * an AWTPermission("accessClipboard") permission. + * is a security manager installed. If there is, the method should call + * the security manager's {@link SecurityManager#checkPermission + * checkPermission} method to check {@code AWTPermission("accessClipboard")}. * * @return the system selection as a Clipboard, or * null if the native platform does not support a @@ -1699,25 +1690,20 @@ public abstract class Toolkit { * therefore not assume that the EventQueue instance returned * by this method will be shared by other applets or the system. * - *

    First, if there is a security manager, its - * checkAwtEventQueueAccess - * method is called. - * If the default implementation of checkAwtEventQueueAccess - * is used (that is, that method is not overriden), then this results in - * a call to the security manager's checkPermission method - * with an AWTPermission("accessEventQueue") permission. + *

    If there is a security manager then its + * {@link SecurityManager#checkPermission checkPermission} method + * is called to check {@code AWTPermission("accessEventQueue")}. * * @return the EventQueue object * @throws SecurityException - * if a security manager exists and its {@link - * java.lang.SecurityManager#checkAwtEventQueueAccess} - * method denies access to the EventQueue + * if a security manager is set and it denies access to + * the {@code EventQueue} * @see java.awt.AWTPermission */ public final EventQueue getSystemEventQueue() { SecurityManager security = System.getSecurityManager(); if (security != null) { - security.checkAwtEventQueueAccess(); + security.checkPermission(SecurityConstants.AWT.CHECK_AWT_EVENTQUEUE_PERMISSION); } return getSystemEventQueueImpl(); } diff --git a/jdk/src/share/classes/java/awt/Window.java b/jdk/src/share/classes/java/awt/Window.java index 4076939c7f0..c10a3b277a8 100644 --- a/jdk/src/share/classes/java/awt/Window.java +++ b/jdk/src/share/classes/java/awt/Window.java @@ -195,10 +195,9 @@ public class Window extends Container implements Accessible { /** * This represents the warning message that is * to be displayed in a non secure window. ie : - * a window that has a security manager installed for - * which calling SecurityManager.checkTopLevelWindow() - * is false. This message can be displayed anywhere in - * the window. + * a window that has a security manager installed that denies + * {@code AWTPermission("showWindowWithoutWarningBanner")}. + * This message can be displayed anywhere in the window. * * @serial * @see #getWarningString @@ -417,11 +416,10 @@ public class Window extends Container implements Accessible { * Constructs a new, initially invisible window in default size with the * specified {@code GraphicsConfiguration}. *

    - * If there is a security manager, this method first calls - * the security manager's {@code checkTopLevelWindow} - * method with {@code this} - * as its argument to determine whether or not the window - * must be displayed with a warning banner. + * If there is a security manager, then it is invoked to check + * {@code AWTPermission("showWindowWithoutWarningBanner")} + * to determine whether or not the window must be displayed with + * a warning banner. * * @param gc the {@code GraphicsConfiguration} of the target screen * device. If {@code gc} is {@code null}, the system default @@ -432,7 +430,6 @@ public class Window extends Container implements Accessible { * {@code GraphicsEnvironment.isHeadless()} returns {@code true} * * @see java.awt.GraphicsEnvironment#isHeadless - * @see java.lang.SecurityManager#checkTopLevelWindow */ Window(GraphicsConfiguration gc) { init(gc); @@ -511,25 +508,16 @@ public class Window extends Container implements Accessible { /** * Constructs a new, initially invisible window in the default size. - * - *

    First, if there is a security manager, its - * {@code checkTopLevelWindow} - * method is called with {@code this} - * as its argument - * to see if it's ok to display the window without a warning banner. - * If the default implementation of {@code checkTopLevelWindow} - * is used (that is, that method is not overriden), then this results in - * a call to the security manager's {@code checkPermission} method - * with an {@code AWTPermission("showWindowWithoutWarningBanner")} - * permission. It that method raises a SecurityException, - * {@code checkTopLevelWindow} returns false, otherwise it - * returns true. If it returns false, a warning banner is created. + *

    + * If there is a security manager set, it is invoked to check + * {@code AWTPermission("showWindowWithoutWarningBanner")}. + * If that check fails with a {@code SecurityException} then a warning + * banner is created. * * @exception HeadlessException when * {@code GraphicsEnvironment.isHeadless()} returns {@code true} * * @see java.awt.GraphicsEnvironment#isHeadless - * @see java.lang.SecurityManager#checkTopLevelWindow */ Window() throws HeadlessException { GraphicsEnvironment.checkHeadless(); @@ -541,11 +529,10 @@ public class Window extends Container implements Accessible { * {@code Frame} as its owner. The window will not be focusable * unless its owner is showing on the screen. *

    - * If there is a security manager, this method first calls - * the security manager's {@code checkTopLevelWindow} - * method with {@code this} - * as its argument to determine whether or not the window - * must be displayed with a warning banner. + * If there is a security manager set, it is invoked to check + * {@code AWTPermission("showWindowWithoutWarningBanner")}. + * If that check fails with a {@code SecurityException} then a warning + * banner is created. * * @param owner the {@code Frame} to act as owner or {@code null} * if this window has no owner @@ -555,7 +542,6 @@ public class Window extends Container implements Accessible { * {@code GraphicsEnvironment.isHeadless} returns {@code true} * * @see java.awt.GraphicsEnvironment#isHeadless - * @see java.lang.SecurityManager#checkTopLevelWindow * @see #isShowing */ public Window(Frame owner) { @@ -570,11 +556,10 @@ public class Window extends Container implements Accessible { * unless its nearest owning {@code Frame} or {@code Dialog} * is showing on the screen. *

    - * If there is a security manager, this method first calls - * the security manager's {@code checkTopLevelWindow} - * method with {@code this} - * as its argument to determine whether or not the window - * must be displayed with a warning banner. + * If there is a security manager set, it is invoked to check + * {@code AWTPermission("showWindowWithoutWarningBanner")}. + * If that check fails with a {@code SecurityException} then a + * warning banner is created. * * @param owner the {@code Window} to act as owner or * {@code null} if this window has no owner @@ -585,7 +570,6 @@ public class Window extends Container implements Accessible { * {@code true} * * @see java.awt.GraphicsEnvironment#isHeadless - * @see java.lang.SecurityManager#checkTopLevelWindow * @see #isShowing * * @since 1.2 @@ -603,11 +587,10 @@ public class Window extends Container implements Accessible { * its nearest owning {@code Frame} or {@code Dialog} * is showing on the screen. *

    - * If there is a security manager, this method first calls - * the security manager's {@code checkTopLevelWindow} - * method with {@code this} - * as its argument to determine whether or not the window - * must be displayed with a warning banner. + * If there is a security manager set, it is invoked to check + * {@code AWTPermission("showWindowWithoutWarningBanner")}. If that + * check fails with a {@code SecurityException} then a warning banner + * is created. * * @param owner the window to act as owner or {@code null} * if this window has no owner @@ -621,7 +604,6 @@ public class Window extends Container implements Accessible { * {@code true} * * @see java.awt.GraphicsEnvironment#isHeadless - * @see java.lang.SecurityManager#checkTopLevelWindow * @see GraphicsConfiguration#getBounds * @see #isShowing * @since 1.3 @@ -1362,10 +1344,9 @@ public class Window extends Container implements Accessible { * Gets the warning string that is displayed with this window. * If this window is insecure, the warning string is displayed * somewhere in the visible area of the window. A window is - * insecure if there is a security manager, and the security - * manager's {@code checkTopLevelWindow} method returns - * {@code false} when this window is passed to it as an - * argument. + * insecure if there is a security manager and the security + * manager denies + * {@code AWTPermission("showWindowWithoutWarningBanner")}. *

    * If the window is secure, then {@code getWarningString} * returns {@code null}. If the window is insecure, this @@ -1373,7 +1354,6 @@ public class Window extends Container implements Accessible { * {@code awt.appletWarning} * and returns the string value of that property. * @return the warning string for this window. - * @see java.lang.SecurityManager#checkTopLevelWindow(java.lang.Object) */ public final String getWarningString() { return warningString; @@ -1383,10 +1363,12 @@ public class Window extends Container implements Accessible { warningString = null; SecurityManager sm = System.getSecurityManager(); if (sm != null) { - if (!sm.checkTopLevelWindow(this)) { + try { + sm.checkPermission(SecurityConstants.AWT.TOPLEVEL_WINDOW_PERMISSION); + } catch (SecurityException se) { // make sure the privileged action is only // for getting the property! We don't want the - // above checkTopLevelWindow call to always succeed! + // above checkPermission call to always succeed! warningString = AccessController.doPrivileged( new GetPropertyAction("awt.appletWarning", "Java Applet Window")); diff --git a/jdk/src/share/classes/java/awt/event/InputEvent.java b/jdk/src/share/classes/java/awt/event/InputEvent.java index 078b1a16d6a..24965d20caf 100644 --- a/jdk/src/share/classes/java/awt/event/InputEvent.java +++ b/jdk/src/share/classes/java/awt/event/InputEvent.java @@ -33,6 +33,7 @@ import java.util.Arrays; import sun.awt.AWTAccessor; import sun.util.logging.PlatformLogger; +import sun.security.util.SecurityConstants; /** * The root event class for all component-level input events. @@ -350,7 +351,7 @@ public abstract class InputEvent extends ComponentEvent { SecurityManager sm = System.getSecurityManager(); if (sm != null) { try { - sm.checkSystemClipboardAccess(); + sm.checkPermission(SecurityConstants.AWT.ACCESS_CLIPBOARD_PERMISSION); b = true; } catch (SecurityException se) { if (logger.isLoggable(PlatformLogger.Level.FINE)) { diff --git a/jdk/src/share/classes/java/lang/SecurityManager.java b/jdk/src/share/classes/java/lang/SecurityManager.java index 34be905bd02..3565082033c 100644 --- a/jdk/src/share/classes/java/lang/SecurityManager.java +++ b/jdk/src/share/classes/java/lang/SecurityManager.java @@ -1336,9 +1336,16 @@ class SecurityManager { * top-level windows; false otherwise. * @exception NullPointerException if the window argument is * null. + * @deprecated The dependency on {@code AWTPermission} creates an + * impediment to future modularization of the Java platform. + * Users of this method should instead invoke + * {@link #checkPermission} directly. + * This method will be changed in a future release to check + * the permission {@code java.security.AllPermission}. * @see java.awt.Window * @see #checkPermission(java.security.Permission) checkPermission */ + @Deprecated public boolean checkTopLevelWindow(Object window) { if (window == null) { throw new NullPointerException("window can't be null"); @@ -1398,8 +1405,15 @@ class SecurityManager { * @since JDK1.1 * @exception SecurityException if the calling thread does not have * permission to access the system clipboard. + * @deprecated The dependency on {@code AWTPermission} creates an + * impediment to future modularization of the Java platform. + * Users of this method should instead invoke + * {@link #checkPermission} directly. + * This method will be changed in a future release to check + * the permission {@code java.security.AllPermission}. * @see #checkPermission(java.security.Permission) checkPermission */ + @Deprecated public void checkSystemClipboardAccess() { Permission perm = SecurityConstants.AWT.ACCESS_CLIPBOARD_PERMISSION; if (perm == null) { @@ -1427,8 +1441,15 @@ class SecurityManager { * @since JDK1.1 * @exception SecurityException if the calling thread does not have * permission to access the AWT event queue. + * @deprecated The dependency on {@code AWTPermission} creates an + * impediment to future modularization of the Java platform. + * Users of this method should instead invoke + * {@link #checkPermission} directly. + * This method will be changed in a future release to check + * the permission {@code java.security.AllPermission}. * @see #checkPermission(java.security.Permission) checkPermission */ + @Deprecated public void checkAwtEventQueueAccess() { Permission perm = SecurityConstants.AWT.CHECK_AWT_EVENTQUEUE_PERMISSION; if (perm == null) { diff --git a/jdk/src/share/classes/sun/applet/AppletSecurity.java b/jdk/src/share/classes/sun/applet/AppletSecurity.java index 4bd67decbcc..b6a71f7b910 100644 --- a/jdk/src/share/classes/sun/applet/AppletSecurity.java +++ b/jdk/src/share/classes/sun/applet/AppletSecurity.java @@ -314,7 +314,7 @@ class AppletSecurity extends AWTSecurityManager { // If we're about to allow access to the main EventQueue, // and anything untrusted is on the class context stack, // disallow access. - super.checkAwtEventQueueAccess(); + super.checkPermission(SecurityConstants.AWT.CHECK_AWT_EVENTQUEUE_PERMISSION); } } // checkAwtEventQueueAccess() diff --git a/jdk/src/share/classes/sun/awt/dnd/SunDropTargetContextPeer.java b/jdk/src/share/classes/sun/awt/dnd/SunDropTargetContextPeer.java index efbf14f1a6a..ed5b2b8b97b 100644 --- a/jdk/src/share/classes/sun/awt/dnd/SunDropTargetContextPeer.java +++ b/jdk/src/share/classes/sun/awt/dnd/SunDropTargetContextPeer.java @@ -57,6 +57,7 @@ import sun.awt.AppContext; import sun.awt.SunToolkit; import sun.awt.datatransfer.DataTransferer; import sun.awt.datatransfer.ToolkitThreadBlockedHandler; +import sun.security.util.SecurityConstants; /** *

    @@ -225,7 +226,7 @@ public abstract class SunDropTargetContextPeer implements DropTargetContextPeer, SecurityManager sm = System.getSecurityManager(); try { if (!dropInProcess && sm != null) { - sm.checkSystemClipboardAccess(); + sm.checkPermission(SecurityConstants.AWT.ACCESS_CLIPBOARD_PERMISSION); } } catch (Exception e) { Thread currentThread = Thread.currentThread(); diff --git a/jdk/src/share/classes/sun/swing/SwingUtilities2.java b/jdk/src/share/classes/sun/swing/SwingUtilities2.java index a1903f2bdd2..6bbbf0a5687 100644 --- a/jdk/src/share/classes/sun/swing/SwingUtilities2.java +++ b/jdk/src/share/classes/sun/swing/SwingUtilities2.java @@ -1184,7 +1184,7 @@ public class SwingUtilities2 { canAccess = true; } else { try { - sm.checkSystemClipboardAccess(); + sm.checkPermission(SecurityConstants.AWT.ACCESS_CLIPBOARD_PERMISSION); canAccess = true; } catch (SecurityException e) { } diff --git a/jdk/src/solaris/classes/sun/awt/X11/XToolkit.java b/jdk/src/solaris/classes/sun/awt/X11/XToolkit.java index 32eceaae3be..9b4daa1cef6 100644 --- a/jdk/src/solaris/classes/sun/awt/X11/XToolkit.java +++ b/jdk/src/solaris/classes/sun/awt/X11/XToolkit.java @@ -54,6 +54,7 @@ import sun.print.PrintJob2D; import sun.security.action.GetPropertyAction; import sun.security.action.GetBooleanAction; import sun.util.logging.PlatformLogger; +import sun.security.util.SecurityConstants; public final class XToolkit extends UNIXToolkit implements Runnable { private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XToolkit"); @@ -1152,7 +1153,7 @@ public final class XToolkit extends UNIXToolkit implements Runnable { public Clipboard getSystemClipboard() { SecurityManager security = System.getSecurityManager(); if (security != null) { - security.checkSystemClipboardAccess(); + security.checkPermission(SecurityConstants.AWT.ACCESS_CLIPBOARD_PERMISSION); } synchronized (this) { if (clipboard == null) { @@ -1165,7 +1166,7 @@ public final class XToolkit extends UNIXToolkit implements Runnable { public Clipboard getSystemSelection() { SecurityManager security = System.getSecurityManager(); if (security != null) { - security.checkSystemClipboardAccess(); + security.checkPermission(SecurityConstants.AWT.ACCESS_CLIPBOARD_PERMISSION); } synchronized (this) { if (selection == null) { diff --git a/jdk/src/windows/classes/sun/awt/windows/WToolkit.java b/jdk/src/windows/classes/sun/awt/windows/WToolkit.java index 25b88f384cf..0f67ffe0a50 100644 --- a/jdk/src/windows/classes/sun/awt/windows/WToolkit.java +++ b/jdk/src/windows/classes/sun/awt/windows/WToolkit.java @@ -64,6 +64,7 @@ import sun.font.FontManagerFactory; import sun.font.SunFontManager; import sun.misc.PerformanceLogger; import sun.util.logging.PlatformLogger; +import sun.security.util.SecurityConstants; public class WToolkit extends SunToolkit implements Runnable { @@ -681,7 +682,7 @@ public class WToolkit extends SunToolkit implements Runnable { public Clipboard getSystemClipboard() { SecurityManager security = System.getSecurityManager(); if (security != null) { - security.checkSystemClipboardAccess(); + security.checkPermission(SecurityConstants.AWT.ACCESS_CLIPBOARD_PERMISSION); } synchronized (this) { if (clipboard == null) { diff --git a/jdk/test/java/awt/security/Permissions.java b/jdk/test/java/awt/security/Permissions.java new file mode 100644 index 00000000000..3f0a3ad24e3 --- /dev/null +++ b/jdk/test/java/awt/security/Permissions.java @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2013, 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 8008981 + * @summary Test that selected Toolkit and Window methods/constructors do + * the appropriate permission check + * @run main/othervm Permissions + */ + +import java.awt.AWTPermission; +import java.awt.Frame; +import java.awt.GraphicsConfiguration; +import java.awt.Toolkit; +import java.awt.Window; +import java.util.ArrayList; +import java.util.List; +import java.security.Permission; + +public class Permissions { + + static class MySecurityManager extends SecurityManager { + private List permissionsChecked = new ArrayList<>(); + + static MySecurityManager install() { + MySecurityManager sm = new MySecurityManager(); + System.setSecurityManager(sm); + return sm; + } + + @Override + public void checkPermission(Permission perm) { + permissionsChecked.add(perm); + } + + void prepare(String msg) { + System.out.println(msg); + permissionsChecked.clear(); + } + + /** + * Checks the security manager's checkPermission method was invoked + * to check the given permission and target name. + */ + void assertChecked(Class type, String name) { + for (Permission perm: permissionsChecked) { + if (type.isInstance(perm) && perm.getName().equals(name)) + return; + } + throw new RuntimeException(type.getName() + "(\"" + name + "\") not checked"); + } + } + + public static void main(String[] args) { + MySecurityManager sm = MySecurityManager.install(); + + Toolkit toolkit = Toolkit.getDefaultToolkit(); + + sm.prepare("Toolkit.getSystemClipboard()"); + toolkit.getSystemClipboard(); + sm.assertChecked(AWTPermission.class, "accessClipboard"); + + sm.prepare("Toolkit.getSystemEventQueue()"); + toolkit.getSystemEventQueue(); + sm.assertChecked(AWTPermission.class, "accessEventQueue"); + + sm.prepare("Toolkit.getSystemSelection()"); + toolkit.getSystemSelection(); + //sm.assertChecked(AWTPermission.class, "accessClipboard"); + + sm.prepare("Window(Frame)"); + new Window((Frame)null); + sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner"); + + sm.prepare("Window(Window)"); + new Window((Window)null); + sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner"); + + sm.prepare("Window(Window,GraphicsConfiguration)"); + new Window((Window)null, (GraphicsConfiguration)null); + sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner"); + } +} From ac101a9d997181c3be91383172841301401091f2 Mon Sep 17 00:00:00 2001 From: Daniel Fuchs Date: Wed, 4 Sep 2013 15:32:59 +0200 Subject: [PATCH 032/210] 6823527: java.util.logging.Handler has thread safety issues Reviewed-by: dholmes, mchung --- .../java/util/logging/ConsoleHandler.java | 5 ++- .../java/util/logging/FileHandler.java | 13 +++++-- .../classes/java/util/logging/Handler.java | 34 ++++++++++++------- .../java/util/logging/MemoryHandler.java | 11 +++--- .../java/util/logging/SocketHandler.java | 3 +- .../java/util/logging/StreamHandler.java | 10 ++++-- 6 files changed, 50 insertions(+), 26 deletions(-) diff --git a/jdk/src/share/classes/java/util/logging/ConsoleHandler.java b/jdk/src/share/classes/java/util/logging/ConsoleHandler.java index a8b4bc4f0cd..36ef6be6801 100644 --- a/jdk/src/share/classes/java/util/logging/ConsoleHandler.java +++ b/jdk/src/share/classes/java/util/logging/ConsoleHandler.java @@ -26,9 +26,6 @@ package java.util.logging; -import java.io.*; -import java.net.*; - /** * This Handler publishes log records to System.err. * By default the SimpleFormatter is used to generate brief summaries. @@ -114,6 +111,7 @@ public class ConsoleHandler extends StreamHandler { * @param record description of the log event. A null record is * silently ignored and is not published */ + @Override public void publish(LogRecord record) { super.publish(record); flush(); @@ -124,6 +122,7 @@ public class ConsoleHandler extends StreamHandler { * to close the output stream. That is, we do not * close System.err. */ + @Override public void close() { flush(); } diff --git a/jdk/src/share/classes/java/util/logging/FileHandler.java b/jdk/src/share/classes/java/util/logging/FileHandler.java index 52360c206ee..b2ac0d9d3e0 100644 --- a/jdk/src/share/classes/java/util/logging/FileHandler.java +++ b/jdk/src/share/classes/java/util/logging/FileHandler.java @@ -149,7 +149,7 @@ public class FileHandler extends StreamHandler { private FileChannel lockFileChannel; private File files[]; private static final int MAX_LOCKS = 100; - private static java.util.HashMap locks = new java.util.HashMap<>(); + private static final java.util.HashMap locks = new java.util.HashMap<>(); /** * A metered stream is a subclass of OutputStream that @@ -157,7 +157,7 @@ public class FileHandler extends StreamHandler { * (b) keeps track of how many bytes have been written */ private class MeteredStream extends OutputStream { - OutputStream out; + final OutputStream out; int written; MeteredStream(OutputStream out, int written) { @@ -165,25 +165,30 @@ public class FileHandler extends StreamHandler { this.written = written; } + @Override public void write(int b) throws IOException { out.write(b); written++; } + @Override public void write(byte buff[]) throws IOException { out.write(buff); written += buff.length; } + @Override public void write(byte buff[], int off, int len) throws IOException { out.write(buff,off,len); written += len; } + @Override public void flush() throws IOException { out.flush(); } + @Override public void close() throws IOException { out.close(); } @@ -607,6 +612,7 @@ public class FileHandler extends StreamHandler { * @param record description of the log event. A null record is * silently ignored and is not published */ + @Override public synchronized void publish(LogRecord record) { if (!isLoggable(record)) { return; @@ -620,6 +626,7 @@ public class FileHandler extends StreamHandler { // currently being called from untrusted code. // So it is safe to raise privilege here. AccessController.doPrivileged(new PrivilegedAction() { + @Override public Object run() { rotate(); return null; @@ -634,6 +641,7 @@ public class FileHandler extends StreamHandler { * @exception SecurityException if a security manager exists and if * the caller does not have LoggingPermission("control"). */ + @Override public synchronized void close() throws SecurityException { super.close(); // Unlock any lock file. @@ -656,6 +664,7 @@ public class FileHandler extends StreamHandler { private static class InitializationErrorManager extends ErrorManager { Exception lastException; + @Override public void error(String msg, Exception ex, int code) { lastException = ex; } diff --git a/jdk/src/share/classes/java/util/logging/Handler.java b/jdk/src/share/classes/java/util/logging/Handler.java index a8c3eb4b036..1cc7b43c7de 100644 --- a/jdk/src/share/classes/java/util/logging/Handler.java +++ b/jdk/src/share/classes/java/util/logging/Handler.java @@ -47,12 +47,20 @@ import java.io.UnsupportedEncodingException; public abstract class Handler { private static final int offValue = Level.OFF.intValue(); - private LogManager manager = LogManager.getLogManager(); - private Filter filter; - private Formatter formatter; - private Level logLevel = Level.ALL; - private ErrorManager errorManager = new ErrorManager(); - private String encoding; + private final LogManager manager = LogManager.getLogManager(); + + // We're using volatile here to avoid synchronizing getters, which + // would prevent other threads from calling isLoggable() + // while publish() is executing. + // On the other hand, setters will be synchronized to exclude concurrent + // execution with more complex methods, such as StreamHandler.publish(). + // We wouldn't want 'level' to be changed by another thread in the middle + // of the execution of a 'publish' call. + private volatile Filter filter; + private volatile Formatter formatter; + private volatile Level logLevel = Level.ALL; + private volatile ErrorManager errorManager = new ErrorManager(); + private volatile String encoding; // Package private support for security checking. When sealed // is true, we access check updates to the class. @@ -110,7 +118,7 @@ public abstract class Handler { * @exception SecurityException if a security manager exists and if * the caller does not have LoggingPermission("control"). */ - public void setFormatter(Formatter newFormatter) throws SecurityException { + public synchronized void setFormatter(Formatter newFormatter) throws SecurityException { checkPermission(); // Check for a null pointer: newFormatter.getClass(); @@ -138,7 +146,7 @@ public abstract class Handler { * @exception UnsupportedEncodingException if the named encoding is * not supported. */ - public void setEncoding(String encoding) + public synchronized void setEncoding(String encoding) throws SecurityException, java.io.UnsupportedEncodingException { checkPermission(); if (encoding != null) { @@ -174,7 +182,7 @@ public abstract class Handler { * @exception SecurityException if a security manager exists and if * the caller does not have LoggingPermission("control"). */ - public void setFilter(Filter newFilter) throws SecurityException { + public synchronized void setFilter(Filter newFilter) throws SecurityException { checkPermission(); filter = newFilter; } @@ -198,7 +206,7 @@ public abstract class Handler { * @exception SecurityException if a security manager exists and if * the caller does not have LoggingPermission("control"). */ - public void setErrorManager(ErrorManager em) { + public synchronized void setErrorManager(ErrorManager em) { checkPermission(); if (em == null) { throw new NullPointerException(); @@ -264,7 +272,7 @@ public abstract class Handler { * than this level will be discarded. * @return the level of messages being logged. */ - public synchronized Level getLevel() { + public Level getLevel() { return logLevel; } @@ -282,11 +290,11 @@ public abstract class Handler { * */ public boolean isLoggable(LogRecord record) { - int levelValue = getLevel().intValue(); + final int levelValue = getLevel().intValue(); if (record.getLevel().intValue() < levelValue || levelValue == offValue) { return false; } - Filter filter = getFilter(); + final Filter filter = getFilter(); if (filter == null) { return true; } diff --git a/jdk/src/share/classes/java/util/logging/MemoryHandler.java b/jdk/src/share/classes/java/util/logging/MemoryHandler.java index ddf72c2a1e1..684ff8f8573 100644 --- a/jdk/src/share/classes/java/util/logging/MemoryHandler.java +++ b/jdk/src/share/classes/java/util/logging/MemoryHandler.java @@ -88,7 +88,7 @@ package java.util.logging; public class MemoryHandler extends Handler { private final static int DEFAULT_SIZE = 1000; - private Level pushLevel; + private volatile Level pushLevel; private int size; private Handler target; private LogRecord buffer[]; @@ -188,6 +188,7 @@ public class MemoryHandler extends Handler { * @param record description of the log event. A null record is * silently ignored and is not published */ + @Override public synchronized void publish(LogRecord record) { if (!isLoggable(record)) { return; @@ -227,6 +228,7 @@ public class MemoryHandler extends Handler { * Note that the current contents of the MemoryHandler * buffer are not written out. That requires a "push". */ + @Override public void flush() { target.flush(); } @@ -238,6 +240,7 @@ public class MemoryHandler extends Handler { * @exception SecurityException if a security manager exists and if * the caller does not have LoggingPermission("control"). */ + @Override public void close() throws SecurityException { target.close(); setLevel(Level.OFF); @@ -252,11 +255,10 @@ public class MemoryHandler extends Handler { * @exception SecurityException if a security manager exists and if * the caller does not have LoggingPermission("control"). */ - public void setPushLevel(Level newLevel) throws SecurityException { + public synchronized void setPushLevel(Level newLevel) throws SecurityException { if (newLevel == null) { throw new NullPointerException(); } - LogManager manager = LogManager.getLogManager(); checkPermission(); pushLevel = newLevel; } @@ -266,7 +268,7 @@ public class MemoryHandler extends Handler { * * @return the value of the pushLevel */ - public synchronized Level getPushLevel() { + public Level getPushLevel() { return pushLevel; } @@ -283,6 +285,7 @@ public class MemoryHandler extends Handler { * @return true if the LogRecord would be logged. * */ + @Override public boolean isLoggable(LogRecord record) { return super.isLoggable(record); } diff --git a/jdk/src/share/classes/java/util/logging/SocketHandler.java b/jdk/src/share/classes/java/util/logging/SocketHandler.java index d7f2f31adbd..0d7f2ceedf4 100644 --- a/jdk/src/share/classes/java/util/logging/SocketHandler.java +++ b/jdk/src/share/classes/java/util/logging/SocketHandler.java @@ -82,7 +82,6 @@ public class SocketHandler extends StreamHandler { private Socket sock; private String host; private int port; - private String portProperty; // Private method to configure a SocketHandler from LogManager // properties and/or default values as specified in the class @@ -177,6 +176,7 @@ public class SocketHandler extends StreamHandler { * @exception SecurityException if a security manager exists and if * the caller does not have LoggingPermission("control"). */ + @Override public synchronized void close() throws SecurityException { super.close(); if (sock != null) { @@ -195,6 +195,7 @@ public class SocketHandler extends StreamHandler { * @param record description of the log event. A null record is * silently ignored and is not published */ + @Override public synchronized void publish(LogRecord record) { if (!isLoggable(record)) { return; diff --git a/jdk/src/share/classes/java/util/logging/StreamHandler.java b/jdk/src/share/classes/java/util/logging/StreamHandler.java index 96dff8c9df0..b3f23743611 100644 --- a/jdk/src/share/classes/java/util/logging/StreamHandler.java +++ b/jdk/src/share/classes/java/util/logging/StreamHandler.java @@ -73,10 +73,9 @@ import java.io.*; */ public class StreamHandler extends Handler { - private LogManager manager = LogManager.getLogManager(); private OutputStream output; private boolean doneHeader; - private Writer writer; + private volatile Writer writer; // Private method to configure a StreamHandler from LogManager // properties and/or default values as specified in the class @@ -169,7 +168,8 @@ public class StreamHandler extends Handler { * @exception UnsupportedEncodingException if the named encoding is * not supported. */ - public void setEncoding(String encoding) + @Override + public synchronized void setEncoding(String encoding) throws SecurityException, java.io.UnsupportedEncodingException { super.setEncoding(encoding); if (output == null) { @@ -201,6 +201,7 @@ public class StreamHandler extends Handler { * @param record description of the log event. A null record is * silently ignored and is not published */ + @Override public synchronized void publish(LogRecord record) { if (!isLoggable(record)) { return; @@ -240,6 +241,7 @@ public class StreamHandler extends Handler { * @return true if the LogRecord would be logged. * */ + @Override public boolean isLoggable(LogRecord record) { if (writer == null || record == null) { return false; @@ -250,6 +252,7 @@ public class StreamHandler extends Handler { /** * Flush any buffered messages. */ + @Override public synchronized void flush() { if (writer != null) { try { @@ -294,6 +297,7 @@ public class StreamHandler extends Handler { * @exception SecurityException if a security manager exists and if * the caller does not have LoggingPermission("control"). */ + @Override public synchronized void close() throws SecurityException { flushAndClose(); } From a0c3d88fba62b486273b94a1b742fba9d2199cd7 Mon Sep 17 00:00:00 2001 From: Daniel Fuchs Date: Wed, 4 Sep 2013 16:22:22 +0200 Subject: [PATCH 033/210] 8019853: Break logging and AWT circular dependency Break logging and AWT circular dependency, which was at the root cause for 8023258 - Logger.getLogger() after ImageIO.read() returns different logger instance Reviewed-by: mchung, art --- .../classes/java/util/logging/LogManager.java | 38 +++++----- jdk/src/share/classes/sun/awt/AppContext.java | 66 ++++++++++++---- .../share/classes/sun/misc/JavaAWTAccess.java | 14 ++-- .../share/classes/sun/misc/SharedSecrets.java | 2 +- .../util/logging/TestAppletLoggerContext.java | 19 ++--- .../TestLoggingWithMainAppContext.java | 75 +++++++++++++++++++ 6 files changed, 159 insertions(+), 55 deletions(-) create mode 100644 jdk/test/java/util/logging/TestLoggingWithMainAppContext.java diff --git a/jdk/src/share/classes/java/util/logging/LogManager.java b/jdk/src/share/classes/java/util/logging/LogManager.java index 0d63468b3cc..717e52990e1 100644 --- a/jdk/src/share/classes/java/util/logging/LogManager.java +++ b/jdk/src/share/classes/java/util/logging/LogManager.java @@ -391,6 +391,9 @@ public class LogManager { } } + // LoggerContext maps from AppContext + private static WeakHashMap contextsMap = null; + // Returns the LoggerContext for the user code (i.e. application or AppContext). // Loggers are isolated from each AppContext. private LoggerContext getUserContext() { @@ -399,33 +402,28 @@ public class LogManager { SecurityManager sm = System.getSecurityManager(); JavaAWTAccess javaAwtAccess = SharedSecrets.getJavaAWTAccess(); if (sm != null && javaAwtAccess != null) { + // for each applet, it has its own LoggerContext isolated from others synchronized (javaAwtAccess) { - // AppContext.getAppContext() returns the system AppContext if called - // from a system thread but Logger.getLogger might be called from - // an applet code. Instead, find the AppContext of the applet code - // from the execution stack. - Object ecx = javaAwtAccess.getExecutionContext(); - if (ecx == null) { - // fall back to thread group seach of AppContext - ecx = javaAwtAccess.getContext(); - } + // find the AppContext of the applet code + // will be null if we are in the main app context. + final Object ecx = javaAwtAccess.getAppletContext(); if (ecx != null) { - context = (LoggerContext)javaAwtAccess.get(ecx, LoggerContext.class); + if (contextsMap == null) { + contextsMap = new WeakHashMap<>(); + } + context = contextsMap.get(ecx); if (context == null) { - if (javaAwtAccess.isMainAppContext()) { - context = userContext; - } else { - // Create a new LoggerContext for the applet. - // The new logger context has its requiresDefaultLoggers - // flag set to true - so that these loggers will be - // lazily added when the context is firt accessed. - context = new LoggerContext(true); - } - javaAwtAccess.put(ecx, LoggerContext.class, context); + // Create a new LoggerContext for the applet. + // The new logger context has its requiresDefaultLoggers + // flag set to true - so that these loggers will be + // lazily added when the context is firt accessed. + context = new LoggerContext(true); + contextsMap.put(ecx, context); } } } } + // for standalone app, return userContext return context != null ? context : userContext; } diff --git a/jdk/src/share/classes/sun/awt/AppContext.java b/jdk/src/share/classes/sun/awt/AppContext.java index d4ed6525ad8..dbdc920dd5f 100644 --- a/jdk/src/share/classes/sun/awt/AppContext.java +++ b/jdk/src/share/classes/sun/awt/AppContext.java @@ -838,21 +838,59 @@ public final class AppContext { public boolean isMainAppContext() { return (numAppContexts.get() == 1 && mainAppContext != null); } - public Object getContext() { - return getAppContext(); - } - public Object getExecutionContext() { - return getExecutionAppContext(); - } - public Object get(Object context, Object key) { - return ((AppContext)context).get(key); - } - public void put(Object context, Object key, Object value) { - ((AppContext)context).put(key, value); - } - public void remove(Object context, Object key) { - ((AppContext)context).remove(key); + + /** + * Returns the AppContext used for applet logging isolation, or null if + * the default global context can be used. + * If there's no applet, or if the caller is a stand alone application, + * or running in the main app context, returns null. + * Otherwise, returns the AppContext of the calling applet. + * @return null if the global default context can be used, + * an AppContext otherwise. + **/ + public Object getAppletContext() { + // There's no AppContext: return null. + // No need to call getAppContext() if numAppContext == 0: + // it means that no AppContext has been created yet, and + // we don't want to trigger the creation of a main app + // context since we don't need it. + if (numAppContexts.get() == 0) return null; + + // Get the context from the security manager + AppContext ecx = getExecutionAppContext(); + + // Not sure we really need to re-check numAppContexts here. + // If all applets have gone away then we could have a + // numAppContexts coming back to 0. So we recheck + // it here because we don't want to trigger the + // creation of a main AppContext in that case. + // This is probably not 100% MT-safe but should reduce + // the window of opportunity in which that issue could + // happen. + if (numAppContexts.get() > 0) { + // Defaults to thread group caching. + // This is probably not required as we only really need + // isolation in a deployed applet environment, in which + // case ecx will not be null when we reach here + // However it helps emulate the deployed environment, + // in tests for instance. + ecx = ecx != null ? ecx : getAppContext(); + } + + // getAppletContext() may be called when initializing the main + // app context - in which case mainAppContext will still be + // null. To work around this issue we simply use + // AppContext.threadGroup.getParent() == null instead, since + // mainAppContext is the only AppContext which should have + // the root TG as its thread group. + // See: JDK-8023258 + final boolean isMainAppContext = ecx == null + || mainAppContext == ecx + || mainAppContext == null && ecx.threadGroup.getParent() == null; + + return isMainAppContext ? null : ecx; } + }); } } diff --git a/jdk/src/share/classes/sun/misc/JavaAWTAccess.java b/jdk/src/share/classes/sun/misc/JavaAWTAccess.java index e64a38b22c9..e0d3c384584 100644 --- a/jdk/src/share/classes/sun/misc/JavaAWTAccess.java +++ b/jdk/src/share/classes/sun/misc/JavaAWTAccess.java @@ -26,14 +26,16 @@ package sun.misc; public interface JavaAWTAccess { - public Object getContext(); - public Object getExecutionContext(); - public Object get(Object context, Object key); - public void put(Object context, Object key, Object value); - public void remove(Object context, Object key); + // Returns the AppContext used for applet logging isolation, or null if + // no isolation is required. + // If there's no applet, or if the caller is a stand alone application, + // or running in the main app context, returns null. + // Otherwise, returns the AppContext of the calling applet. + public Object getAppletContext(); - // convenience methods whose context is the object returned by getContext() + // convenience methods to cache objects in the current thread group's + // AppContext public Object get(Object key); public void put(Object key, Object value); public void remove(Object key); diff --git a/jdk/src/share/classes/sun/misc/SharedSecrets.java b/jdk/src/share/classes/sun/misc/SharedSecrets.java index 9248afa5ed3..bc2ab2e9ea6 100644 --- a/jdk/src/share/classes/sun/misc/SharedSecrets.java +++ b/jdk/src/share/classes/sun/misc/SharedSecrets.java @@ -170,7 +170,7 @@ public class SharedSecrets { public static JavaAWTAccess getJavaAWTAccess() { // this may return null in which case calling code needs to // provision for. - if (javaAWTAccess == null || javaAWTAccess.getContext() == null) { + if (javaAWTAccess == null) { return null; } return javaAWTAccess; diff --git a/jdk/test/java/util/logging/TestAppletLoggerContext.java b/jdk/test/java/util/logging/TestAppletLoggerContext.java index c7f3d4f4991..82c39381fe8 100644 --- a/jdk/test/java/util/logging/TestAppletLoggerContext.java +++ b/jdk/test/java/util/logging/TestAppletLoggerContext.java @@ -110,28 +110,19 @@ public class TestAppletLoggerContext { } TestExc exc; - TestExc global = new TestExc(); @Override - public Object getContext() { return active ? global : null; } + public Object getAppletContext() { return active ? exc : null; } @Override - public Object getExecutionContext() { return active ? exc : null; } + public Object get(Object o) { return exc.get(o); } @Override - public Object get(Object o, Object o1) { return TestExc.exc(o).get(o1); } + public void put(Object o, Object o1) { exc.put(o, o1); } @Override - public void put(Object o, Object o1, Object o2) { TestExc.exc(o).put(o1, o2); } - @Override - public void remove(Object o, Object o1) { TestExc.exc(o).remove(o1); } - @Override - public Object get(Object o) { return global.get(o); } - @Override - public void put(Object o, Object o1) { global.put(o, o1); } - @Override - public void remove(Object o) { global.remove(o); } + public void remove(Object o) { exc.remove(o); } @Override public boolean isDisposed() { return false; } @Override - public boolean isMainAppContext() { return exc == null; } + public boolean isMainAppContext() { return !active || exc == null; } } final static JavaAWTAccessStub javaAwtAccess = new JavaAWTAccessStub(); diff --git a/jdk/test/java/util/logging/TestLoggingWithMainAppContext.java b/jdk/test/java/util/logging/TestLoggingWithMainAppContext.java new file mode 100644 index 00000000000..5489acee22a --- /dev/null +++ b/jdk/test/java/util/logging/TestLoggingWithMainAppContext.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2013, 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.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.logging.Logger; +import javax.imageio.ImageIO; + +/** + * @test + * @bug 8019853 8023258 + * @summary Test that the default user context is used when in the main + * application context. This test must not be run in same VM or agent + * VM mode: it would not test the intended behavior. + * @run main/othervm TestLoggingWithMainAppContext + */ +public class TestLoggingWithMainAppContext { + + public static void main(String[] args) throws IOException { + System.out.println("Creating loggers."); + + // These loggers will be created in the default user context. + final Logger foo1 = Logger.getLogger( "foo" ); + final Logger bar1 = Logger.getLogger( "foo.bar" ); + if (bar1.getParent() != foo1) { + throw new RuntimeException("Parent logger of bar1 "+bar1+" is not "+foo1); + } + System.out.println("bar1.getParent() is the same as foo1"); + + // Set a security manager + System.setSecurityManager(new SecurityManager()); + System.out.println("Now running with security manager"); + + // Triggers the creation of the main AppContext + ByteArrayInputStream is = new ByteArrayInputStream(new byte[] { 0, 1 }); + ImageIO.read(is); // triggers calls to system loggers & creation of main AppContext + + // verify that we're still using the default user context + final Logger bar2 = Logger.getLogger( "foo.bar" ); + if (bar1 != bar2) { + throw new RuntimeException("bar2 "+bar2+" is not the same as bar1 "+bar1); + } + System.out.println("bar2 is the same as bar1"); + if (bar2.getParent() != foo1) { + throw new RuntimeException("Parent logger of bar2 "+bar2+" is not foo1 "+foo1); + } + System.out.println("bar2.getParent() is the same as foo1"); + final Logger foo2 = Logger.getLogger("foo"); + if (foo1 != foo2) { + throw new RuntimeException("foo2 "+foo2+" is not the same as foo1 "+foo1); + } + System.out.println("foo2 is the same as foo1"); + + System.out.println("Test passed."); + } +} From e447689d41cc514db2c7f292785f6a22d7540609 Mon Sep 17 00:00:00 2001 From: Xueming Shen Date: Wed, 4 Sep 2013 12:35:22 -0700 Subject: [PATCH 034/210] 6341345: (spec) Console.reader() should make it clear that the reader requires line termination To clarify the spec Reviewed-by: alanb --- jdk/src/share/classes/java/io/Console.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/jdk/src/share/classes/java/io/Console.java b/jdk/src/share/classes/java/io/Console.java index c100f8a0ccd..292e42eec7c 100644 --- a/jdk/src/share/classes/java/io/Console.java +++ b/jdk/src/share/classes/java/io/Console.java @@ -124,9 +124,11 @@ public final class Console implements Flushable * {@link java.io.Reader#read(java.nio.CharBuffer) read(java.nio.CharBuffer)} * on the returned object will not read in characters beyond the line * bound for each invocation, even if the destination buffer has space for - * more characters. A line bound is considered to be any one of a line feed - * ('\n'), a carriage return ('\r'), a carriage return - * followed immediately by a linefeed, or an end of stream. + * more characters. The {@code Reader}'s {@code read} methods may block if a + * line bound has not been entered or reached on the console's input device. + * A line bound is considered to be any one of a line feed ('\n'), + * a carriage return ('\r'), a carriage return followed immediately + * by a linefeed, or an end of stream. * * @return The reader associated with this console */ From db444fae3e243cfce00515d993f582d83e5f8768 Mon Sep 17 00:00:00 2001 From: Xueming Shen Date: Wed, 4 Sep 2013 12:37:41 -0700 Subject: [PATCH 035/210] 7186632: NLS t13y issue on jar.properties file To remove the redundant backslash Reviewed-by: naoto --- jdk/src/share/classes/sun/tools/jar/resources/jar.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jdk/src/share/classes/sun/tools/jar/resources/jar.properties b/jdk/src/share/classes/sun/tools/jar/resources/jar.properties index 852cac2889a..c8e8d9aecec 100644 --- a/jdk/src/share/classes/sun/tools/jar/resources/jar.properties +++ b/jdk/src/share/classes/sun/tools/jar/resources/jar.properties @@ -61,7 +61,7 @@ out.create=\ out.extracted=\ extracted: {0} out.inflated=\ - \ \inflated: {0} + \ inflated: {0} out.size=\ (in = {0}) (out= {1}) From b5cd24ccc9fda567c7a25c8088974b3a77800551 Mon Sep 17 00:00:00 2001 From: Robert Field Date: Wed, 4 Sep 2013 19:47:26 -0700 Subject: [PATCH 036/210] 8020816: Metafactory crashes on code with method reference 8021050: MethodHandleInfo throws exception when method handle is to a method with @CallerSensitive Fixed by 8008688 - this is a test to confirm the above fixed Reviewed-by: vlivanov --- .../MethodReferenceTestCallerSensitive.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 jdk/test/jdk/lambda/MethodReferenceTestCallerSensitive.java diff --git a/jdk/test/jdk/lambda/MethodReferenceTestCallerSensitive.java b/jdk/test/jdk/lambda/MethodReferenceTestCallerSensitive.java new file mode 100644 index 00000000000..805a6a203cb --- /dev/null +++ b/jdk/test/jdk/lambda/MethodReferenceTestCallerSensitive.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2013, 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 org.testng.annotations.Test; + +import java.lang.reflect.Field; +import java.util.function.Function; + + +/** + * @author Robert Field + */ + +@Test +public class MethodReferenceTestCallerSensitive { + + private static void getF(T arg) { + Function,Field[]> firstFunction = Class::getFields; + } + + public void testConstructorReferenceVarArgs() { + getF("Hello World"); + } + +} From 02d81bbc68127319cde94e6183557571484b6773 Mon Sep 17 00:00:00 2001 From: Jaroslav Bachorik Date: Thu, 5 Sep 2013 13:04:17 +0200 Subject: [PATCH 037/210] 8023464: test/closed/sun/tracing/ProviderProxyTest.java failing Don't rely on assertions when an Exception suits better Reviewed-by: alanb, dfuchs, sjiang --- jdk/src/share/classes/sun/tracing/ProviderSkeleton.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/jdk/src/share/classes/sun/tracing/ProviderSkeleton.java b/jdk/src/share/classes/sun/tracing/ProviderSkeleton.java index 2a5bc360430..f68f2650b35 100644 --- a/jdk/src/share/classes/sun/tracing/ProviderSkeleton.java +++ b/jdk/src/share/classes/sun/tracing/ProviderSkeleton.java @@ -164,7 +164,10 @@ public abstract class ProviderSkeleton implements InvocationHandler, Provider { declaringClass == Object.class) { return method.invoke(this, args); } else { - assert false; + // assert false : "this should never happen" + // reaching here would indicate a breach + // in security in the higher layers + throw new SecurityException(); } } catch (IllegalAccessException e) { assert false; From ea3200b7843e90ac8280feb04ce25a9482be548e Mon Sep 17 00:00:00 2001 From: Jaroslav Bachorik Date: Thu, 5 Sep 2013 14:34:22 +0200 Subject: [PATCH 038/210] 8004179: Few of test/java/lang/management/ThreadMXBean/* tests don't clean up the created threads Just run those tests in "othervm" mode. Reviewed-by: alanb, dfuchs, sjiang --- jdk/test/java/lang/management/ThreadMXBean/LockedMonitors.java | 2 +- .../java/lang/management/ThreadMXBean/LockedSynchronizers.java | 2 +- .../java/lang/management/ThreadMXBean/MyOwnSynchronizer.java | 2 +- .../java/lang/management/ThreadMXBean/SharedSynchronizer.java | 2 +- .../lang/management/ThreadMXBean/SynchronizationStatistics.java | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/jdk/test/java/lang/management/ThreadMXBean/LockedMonitors.java b/jdk/test/java/lang/management/ThreadMXBean/LockedMonitors.java index 5c9747eaf9e..a693d71a841 100644 --- a/jdk/test/java/lang/management/ThreadMXBean/LockedMonitors.java +++ b/jdk/test/java/lang/management/ThreadMXBean/LockedMonitors.java @@ -37,7 +37,7 @@ * @build Barrier * @build LockingThread * @build ThreadDump - * @run main LockedMonitors + * @run main/othervm LockedMonitors */ import java.lang.management.*; diff --git a/jdk/test/java/lang/management/ThreadMXBean/LockedSynchronizers.java b/jdk/test/java/lang/management/ThreadMXBean/LockedSynchronizers.java index b732d43f311..0fc35325926 100644 --- a/jdk/test/java/lang/management/ThreadMXBean/LockedSynchronizers.java +++ b/jdk/test/java/lang/management/ThreadMXBean/LockedSynchronizers.java @@ -33,7 +33,7 @@ * @build Barrier * @build SynchronizerLockingThread * @build ThreadDump - * @run main LockedSynchronizers + * @run main/othervm LockedSynchronizers */ import java.lang.management.*; diff --git a/jdk/test/java/lang/management/ThreadMXBean/MyOwnSynchronizer.java b/jdk/test/java/lang/management/ThreadMXBean/MyOwnSynchronizer.java index 3968a5aab6f..c102583ddbf 100644 --- a/jdk/test/java/lang/management/ThreadMXBean/MyOwnSynchronizer.java +++ b/jdk/test/java/lang/management/ThreadMXBean/MyOwnSynchronizer.java @@ -30,7 +30,7 @@ * * @build Barrier * @build ThreadDump - * @run main MyOwnSynchronizer + * @run main/othervm MyOwnSynchronizer */ import java.lang.management.*; diff --git a/jdk/test/java/lang/management/ThreadMXBean/SharedSynchronizer.java b/jdk/test/java/lang/management/ThreadMXBean/SharedSynchronizer.java index 6f5065dda03..6fc9e9ee0e5 100644 --- a/jdk/test/java/lang/management/ThreadMXBean/SharedSynchronizer.java +++ b/jdk/test/java/lang/management/ThreadMXBean/SharedSynchronizer.java @@ -28,7 +28,7 @@ * in shared mode which has no owner when a thread is parked. * @author Mandy Chung * - * @run main SharedSynchronizer + * @run main/othervm SharedSynchronizer */ diff --git a/jdk/test/java/lang/management/ThreadMXBean/SynchronizationStatistics.java b/jdk/test/java/lang/management/ThreadMXBean/SynchronizationStatistics.java index ae65ca924a2..e03042864c9 100644 --- a/jdk/test/java/lang/management/ThreadMXBean/SynchronizationStatistics.java +++ b/jdk/test/java/lang/management/ThreadMXBean/SynchronizationStatistics.java @@ -30,7 +30,7 @@ * * @ignore 6309226 * @build Semaphore - * @run main SynchronizationStatistics + * @run main/othervm SynchronizationStatistics */ import java.lang.management.*; From b1127783de054ea3c5ee6b719aa8aa9fe739003c Mon Sep 17 00:00:00 2001 From: Naoto Sato Date: Thu, 5 Sep 2013 10:14:53 -0700 Subject: [PATCH 039/210] 8023943: Method description fix for String.toLower/UpperCase() methods Reviewed-by: okutsu --- jdk/src/share/classes/java/lang/String.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jdk/src/share/classes/java/lang/String.java b/jdk/src/share/classes/java/lang/String.java index e9d75afbbce..2231aa3bb71 100644 --- a/jdk/src/share/classes/java/lang/String.java +++ b/jdk/src/share/classes/java/lang/String.java @@ -2652,7 +2652,7 @@ public final class String * returns {@code "t\u005Cu0131tle"}, where '\u005Cu0131' is the * LATIN SMALL LETTER DOTLESS I character. * To obtain correct results for locale insensitive strings, use - * {@code toLowerCase(Locale.ENGLISH)}. + * {@code toLowerCase(Locale.ROOT)}. *

    * @return the {@code String}, converted to lowercase. * @see java.lang.String#toLowerCase(Locale) @@ -2815,7 +2815,7 @@ public final class String * returns {@code "T\u005Cu0130TLE"}, where '\u005Cu0130' is the * LATIN CAPITAL LETTER I WITH DOT ABOVE character. * To obtain correct results for locale insensitive strings, use - * {@code toUpperCase(Locale.ENGLISH)}. + * {@code toUpperCase(Locale.ROOT)}. *

    * @return the {@code String}, converted to uppercase. * @see java.lang.String#toUpperCase(Locale) From a277d40ead556c15e1869475da44cb00cd1ccf78 Mon Sep 17 00:00:00 2001 From: Vlaidmir Ivanov Date: Thu, 5 Sep 2013 14:58:49 -0700 Subject: [PATCH 040/210] 8024283: 10 nashorn tests fail with similar stack trace InternalError with cause being NoClassDefFoundError Fix pre-existing 292 bug tickled by combo of nashorn code and MethodHandleInfo changes Reviewed-by: jrose --- .../classes/java/lang/invoke/InvokerBytecodeGenerator.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/jdk/src/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java b/jdk/src/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java index 3ddf5d4c1c5..6228c07b7b0 100644 --- a/jdk/src/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java +++ b/jdk/src/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java @@ -612,6 +612,12 @@ class InvokerBytecodeGenerator { return false; // inner class of some sort if (cls.getClassLoader() != MethodHandle.class.getClassLoader()) return false; // not on BCP + MethodType mtype = member.getMethodOrFieldType(); + if (!isStaticallyNameable(mtype.returnType())) + return false; + for (Class ptype : mtype.parameterArray()) + if (!isStaticallyNameable(ptype)) + return false; if (!member.isPrivate() && VerifyAccess.isSamePackage(MethodHandle.class, cls)) return true; // in java.lang.invoke package if (member.isPublic() && isStaticallyNameable(cls)) From 37709e319182570f4f11fca0726a1d530ee7aba8 Mon Sep 17 00:00:00 2001 From: John Rose Date: Fri, 6 Sep 2013 00:43:00 -0700 Subject: [PATCH 041/210] 8024260: 10 closed/java/lang/invoke/* tests failing after overhaul to MethodHandleInfo Reviewed-by: vlivanov, briangoetz --- .../share/classes/java/lang/invoke/MethodHandle.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/jdk/src/share/classes/java/lang/invoke/MethodHandle.java b/jdk/src/share/classes/java/lang/invoke/MethodHandle.java index 408cbd08abc..613d223fe2a 100644 --- a/jdk/src/share/classes/java/lang/invoke/MethodHandle.java +++ b/jdk/src/share/classes/java/lang/invoke/MethodHandle.java @@ -1286,7 +1286,17 @@ assertEquals("[three, thee, tee]", asListFix.invoke((Object)argv).toString()); /*non-public*/ MethodHandle withInternalMemberName(MemberName member) { - return MethodHandleImpl.makeWrappedMember(this, member); + if (member != null) { + return MethodHandleImpl.makeWrappedMember(this, member); + } else if (internalMemberName() == null) { + // The required internaMemberName is null, and this MH (like most) doesn't have one. + return this; + } else { + // The following case is rare. Mask the internalMemberName by wrapping the MH in a BMH. + MethodHandle result = rebind(); + assert (result.internalMemberName() == null); + return result; + } } /*non-public*/ From 61000f0c4b9dda6152dc37e0f49fd5bceb8eb530 Mon Sep 17 00:00:00 2001 From: Jaroslav Bachorik Date: Fri, 6 Sep 2013 10:03:16 +0200 Subject: [PATCH 042/210] 6815130: Intermittent ThreadMXBean/Locks.java test failure Preventing stale reads from ThreadExecutionSynchronizer.waiting flag Reviewed-by: dholmes, mchung, dfuchs --- .../lang/management/ThreadMXBean/Locks.java | 23 +++++++++---------- .../ThreadExecutionSynchronizer.java | 6 ++--- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/jdk/test/java/lang/management/ThreadMXBean/Locks.java b/jdk/test/java/lang/management/ThreadMXBean/Locks.java index 5969aebc6d0..c078dccd62d 100644 --- a/jdk/test/java/lang/management/ThreadMXBean/Locks.java +++ b/jdk/test/java/lang/management/ThreadMXBean/Locks.java @@ -193,16 +193,18 @@ public class Locks { public CheckerThread() { super("CheckerThread"); } + + private void waitForState(Thread.State state) { + thrsync.waitForSignal(); + while (waiter.getState() != state) { + goSleep(10); + } + } + public void run() { synchronized (ready) { // wait until WaitingThread about to wait for objC - thrsync.waitForSignal(); - - int retryCount = 0; - while (waiter.getState() != Thread.State.WAITING - && retryCount++ < 500) { - goSleep(100); - } + waitForState(Thread.State.WAITING); checkBlockedObject(waiter, objC, null, Thread.State.WAITING); synchronized (objC) { @@ -211,16 +213,13 @@ public class Locks { // wait for waiter thread to about to enter // synchronized object ready. - thrsync.waitForSignal(); - // give chance for waiter thread to get blocked on - // object ready. - goSleep(50); + waitForState(Thread.State.BLOCKED); checkBlockedObject(waiter, ready, this, Thread.State.BLOCKED); } // wait for signal from waiting thread that it is about // wait for objC. - thrsync.waitForSignal(); + waitForState(Thread.State.WAITING); synchronized(objC) { checkBlockedObject(waiter, objC, Thread.currentThread(), Thread.State.WAITING); objC.notify(); diff --git a/jdk/test/java/lang/management/ThreadMXBean/ThreadExecutionSynchronizer.java b/jdk/test/java/lang/management/ThreadMXBean/ThreadExecutionSynchronizer.java index dc887829bdf..6cba7e73521 100644 --- a/jdk/test/java/lang/management/ThreadMXBean/ThreadExecutionSynchronizer.java +++ b/jdk/test/java/lang/management/ThreadMXBean/ThreadExecutionSynchronizer.java @@ -23,7 +23,7 @@ /* * - * @summary Thiseclass is used to synchronize execution off two threads. + * @summary This class is used to synchronize execution of two threads. * @author Swamy Venkataramanappa */ @@ -31,8 +31,8 @@ import java.util.concurrent.Semaphore; public class ThreadExecutionSynchronizer { - private boolean waiting; - private Semaphore semaphore; + private volatile boolean waiting; + private final Semaphore semaphore; public ThreadExecutionSynchronizer() { semaphore = new Semaphore(1); From 8007590d3bc9e355ca133f54d05f6e183d78c60f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20Borggr=C3=A9n-Franck?= Date: Fri, 6 Sep 2013 14:20:12 +0200 Subject: [PATCH 043/210] 5047859: (reflect) Class.getField can't find String[].length Reviewed-by: darcy, mchung --- jdk/src/share/classes/java/lang/Class.java | 71 ++++++++++++------- .../java/lang/Class/getField/ArrayLength.java | 64 +++++++++++++++++ 2 files changed, 108 insertions(+), 27 deletions(-) create mode 100644 jdk/test/java/lang/Class/getField/ArrayLength.java diff --git a/jdk/src/share/classes/java/lang/Class.java b/jdk/src/share/classes/java/lang/Class.java index a3c962e0838..b8af59b7ae5 100644 --- a/jdk/src/share/classes/java/lang/Class.java +++ b/jdk/src/share/classes/java/lang/Class.java @@ -1484,22 +1484,24 @@ public final class Class implements java.io.Serializable, /** * Returns an array containing {@code Field} objects reflecting all * the accessible public fields of the class or interface represented by - * this {@code Class} object. The elements in the array returned are - * not sorted and are not in any particular order. This method returns an - * array of length 0 if the class or interface has no accessible public - * fields, or if it represents an array class, a primitive type, or void. + * this {@code Class} object. * - *

    Specifically, if this {@code Class} object represents a class, - * this method returns the public fields of this class and of all its - * superclasses. If this {@code Class} object represents an - * interface, this method returns the fields of this interface and of all - * its superinterfaces. + *

    If this {@code Class} object represents a class or interface with no + * no accessible public fields, then this method returns an array of length + * 0. * - *

    The implicit length field for array class is not reflected by this - * method. User code should use the methods of class {@code Array} to - * manipulate arrays. + *

    If this {@code Class} object represents a class, then this method + * returns the public fields of the class and of all its superclasses. * - *

    See The Java Language Specification, sections 8.2 and 8.3. + *

    If this {@code Class} object represents an interface, then this + * method returns the fields of the interface and of all its + * superinterfaces. + * + *

    If this {@code Class} object represents an array type, a primitive + * type, or void, then this method returns an array of length 0. + * + *

    The elements in the array returned are not sorted and are not in any + * particular order. * * @return the array of {@code Field} objects representing the * public fields @@ -1512,6 +1514,8 @@ public final class Class implements java.io.Serializable, * of this class. * * @since JDK1.1 + * @jls 8.2 Class Members + * @jls 8.3 Field Declarations */ @CallerSensitive public Field[] getFields() throws SecurityException { @@ -1595,13 +1599,14 @@ public final class Class implements java.io.Serializable, /** - * Returns a {@code Field} object that reflects the specified public - * member field of the class or interface represented by this - * {@code Class} object. The {@code name} parameter is a - * {@code String} specifying the simple name of the desired field. + * Returns a {@code Field} object that reflects the specified public member + * field of the class or interface represented by this {@code Class} + * object. The {@code name} parameter is a {@code String} specifying the + * simple name of the desired field. * *

    The field to be reflected is determined by the algorithm that - * follows. Let C be the class represented by this object: + * follows. Let C be the class or interface represented by this object: + * *

      *
    1. If C declares a public field with the name specified, that is the * field to be reflected.
    2. @@ -1614,7 +1619,8 @@ public final class Class implements java.io.Serializable, * is thrown. *
    * - *

    See The Java Language Specification, sections 8.2 and 8.3. + *

    If this {@code Class} object represents an array type, then this + * method does not find the {@code length} field of the array type. * * @param name the field name * @return the {@code Field} object of this class specified by @@ -1631,6 +1637,8 @@ public final class Class implements java.io.Serializable, * of this class. * * @since JDK1.1 + * @jls 8.2 Class Members + * @jls 8.3 Field Declarations */ @CallerSensitive public Field getField(String name) @@ -1800,12 +1808,15 @@ public final class Class implements java.io.Serializable, * declared by the class or interface represented by this * {@code Class} object. This includes public, protected, default * (package) access, and private fields, but excludes inherited fields. - * The elements in the array returned are not sorted and are not in any - * particular order. This method returns an array of length 0 if the class - * or interface declares no fields, or if this {@code Class} object - * represents a primitive type, an array class, or void. * - *

    See The Java Language Specification, sections 8.2 and 8.3. + *

    If this {@code Class} object represents a class or interface with no + * declared fields, then this method returns an array of length 0. + * + *

    If this {@code Class} object represents an array type, a primitive + * type, or void, then this method returns an array of length 0. + * + *

    The elements in the array returned are not sorted and are not in any + * particular order. * * @return the array of {@code Field} objects representing all the * declared fields of this class @@ -1831,6 +1842,8 @@ public final class Class implements java.io.Serializable, * * * @since JDK1.1 + * @jls 8.2 Class Members + * @jls 8.3 Field Declarations */ @CallerSensitive public Field[] getDeclaredFields() throws SecurityException { @@ -1935,9 +1948,11 @@ public final class Class implements java.io.Serializable, /** * Returns a {@code Field} object that reflects the specified declared * field of the class or interface represented by this {@code Class} - * object. The {@code name} parameter is a {@code String} that - * specifies the simple name of the desired field. Note that this method - * will not reflect the {@code length} field of an array class. + * object. The {@code name} parameter is a {@code String} that specifies + * the simple name of the desired field. + * + *

    If this {@code Class} object represents an array type, then this + * method does not find the {@code length} field of the array type. * * @param name the name of the field * @return the {@code Field} object for the specified field in this @@ -1967,6 +1982,8 @@ public final class Class implements java.io.Serializable, * * * @since JDK1.1 + * @jls 8.2 Class Members + * @jls 8.3 Field Declarations */ @CallerSensitive public Field getDeclaredField(String name) diff --git a/jdk/test/java/lang/Class/getField/ArrayLength.java b/jdk/test/java/lang/Class/getField/ArrayLength.java new file mode 100644 index 00000000000..c03a772c043 --- /dev/null +++ b/jdk/test/java/lang/Class/getField/ArrayLength.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2013, 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 5047859 + * @summary verify that for an array type class instance, getField("length") + * throws an exception, and getFields() does not contain a Field for + * 'length' + */ + +import java.lang.reflect.Field; + +public class ArrayLength { + public static void main(String [] args) { + int failed = 0; + + try { + new String[0].getClass().getField("length"); + failed++; + System.out.println("getField(\"length\") should throw NoSuchFieldException"); + } catch (NoSuchFieldException e) { + } + try { + new String[0].getClass().getDeclaredField("length"); + failed++; + System.out.println("getDeclaredField(\"length\") should throw NoSuchFieldException"); + } catch (NoSuchFieldException e) { + } + + if (new String[0].getClass().getFields().length != 0) { + failed++; + System.out.println("getFields() for an array type should return a zero length array"); + } + + if (new String[0].getClass().getDeclaredFields().length != 0) { + failed++; + System.out.println("getDeclaredFields() for an array type should return a zero length array"); + } + + if (failed != 0) + throw new RuntimeException("Test failed see log for details"); + } +} From 8b9c8247a80ff8d9954024e12177adf1eba71fff Mon Sep 17 00:00:00 2001 From: Xue-Lei Andrew Fan Date: Sat, 7 Sep 2013 17:05:22 -0700 Subject: [PATCH 044/210] 7188657: There should be a way to reorder the JSSE ciphers Reviewed-by: weijun, wetmore --- .../classes/javax/net/ssl/SSLParameters.java | 36 +- .../classes/sun/security/ssl/Handshaker.java | 31 +- .../sun/security/ssl/SSLEngineImpl.java | 10 + .../sun/security/ssl/SSLServerSocketImpl.java | 13 +- .../sun/security/ssl/SSLSocketImpl.java | 14 +- .../sun/security/ssl/ServerHandshaker.java | 17 +- .../SSLParameters/UseCipherSuitesOrder.java | 357 ++++++++++++++++++ 7 files changed, 466 insertions(+), 12 deletions(-) create mode 100644 jdk/test/sun/security/ssl/javax/net/ssl/SSLParameters/UseCipherSuitesOrder.java diff --git a/jdk/src/share/classes/javax/net/ssl/SSLParameters.java b/jdk/src/share/classes/javax/net/ssl/SSLParameters.java index 1dc6f3315d0..5e0d403cd39 100644 --- a/jdk/src/share/classes/javax/net/ssl/SSLParameters.java +++ b/jdk/src/share/classes/javax/net/ssl/SSLParameters.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2013, 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 @@ -40,7 +40,7 @@ import java.util.LinkedHashMap; * the list of protocols to be allowed, the endpoint identification * algorithm during SSL/TLS handshaking, the Server Name Indication (SNI), * the algorithm constraints and whether SSL/TLS servers should request - * or require client authentication. + * or require client authentication, etc. *

    * SSLParameters can be created via the constructors in this class. * Objects can also be obtained using the getSSLParameters() @@ -73,13 +73,14 @@ public class SSLParameters { private AlgorithmConstraints algorithmConstraints; private Map sniNames = null; private Map sniMatchers = null; + private boolean preferLocalCipherSuites; /** * Constructs SSLParameters. *

    * The values of cipherSuites, protocols, cryptographic algorithm * constraints, endpoint identification algorithm, server names and - * server name matchers are set to null, + * server name matchers are set to null, useCipherSuitesOrder, * wantClientAuth and needClientAuth are set to false. */ public SSLParameters() { @@ -434,5 +435,34 @@ public class SSLParameters { return null; } + + /** + * Sets whether the local cipher suites preference should be honored. + * + * @param honorOrder whether local cipher suites order in + * {@code #getCipherSuites} should be honored during + * SSL/TLS handshaking. + * + * @see #getUseCipherSuitesOrder() + * + * @since 1.8 + */ + public final void setUseCipherSuitesOrder(boolean honorOrder) { + this.preferLocalCipherSuites = honorOrder; + } + + /** + * Returns whether the local cipher suites preference should be honored. + * + * @return whether local cipher suites order in {@code #getCipherSuites} + * should be honored during SSL/TLS handshaking. + * + * @see #setUseCipherSuitesOrder(boolean) + * + * @since 1.8 + */ + public final boolean getUseCipherSuitesOrder() { + return preferLocalCipherSuites; + } } diff --git a/jdk/src/share/classes/sun/security/ssl/Handshaker.java b/jdk/src/share/classes/sun/security/ssl/Handshaker.java index 17b1f92ac74..a92320451e0 100644 --- a/jdk/src/share/classes/sun/security/ssl/Handshaker.java +++ b/jdk/src/share/classes/sun/security/ssl/Handshaker.java @@ -145,6 +145,14 @@ abstract class Handshaker { /* True if it's OK to start a new SSL session */ boolean enableNewSession; + // Whether local cipher suites preference should be honored during + // handshaking? + // + // Note that in this provider, this option only applies to server side. + // Local cipher suites preference is always honored in client side in + // this provider. + boolean preferLocalCipherSuites = false; + // Temporary storage for the individual keys. Set by // calculateConnectionKeys() and cleared once the ciphers are // activated. @@ -462,6 +470,13 @@ abstract class Handshaker { this.sniMatchers = sniMatchers; } + /** + * Sets the cipher suites preference. + */ + void setUseCipherSuitesOrder(boolean on) { + this.preferLocalCipherSuites = on; + } + /** * Prior to handshaking, activate the handshake and initialize the version, * input stream and output stream. @@ -533,7 +548,9 @@ abstract class Handshaker { } /** - * Check if the given ciphersuite is enabled and available. + * Check if the given ciphersuite is enabled and available within the + * current active cipher suites. + * * Does not check if the required server certificates are available. */ boolean isNegotiable(CipherSuite s) { @@ -541,7 +558,17 @@ abstract class Handshaker { activeCipherSuites = getActiveCipherSuites(); } - return activeCipherSuites.contains(s) && s.isNegotiable(); + return isNegotiable(activeCipherSuites, s); + } + + /** + * Check if the given ciphersuite is enabled and available within the + * proposed cipher suite list. + * + * Does not check if the required server certificates are available. + */ + final static boolean isNegotiable(CipherSuiteList proposed, CipherSuite s) { + return proposed.contains(s) && s.isNegotiable(); } /** diff --git a/jdk/src/share/classes/sun/security/ssl/SSLEngineImpl.java b/jdk/src/share/classes/sun/security/ssl/SSLEngineImpl.java index c2e94f3b401..5302b6147b4 100644 --- a/jdk/src/share/classes/sun/security/ssl/SSLEngineImpl.java +++ b/jdk/src/share/classes/sun/security/ssl/SSLEngineImpl.java @@ -319,6 +319,12 @@ final public class SSLEngineImpl extends SSLEngine { */ private boolean isFirstAppOutputRecord = true; + /* + * Whether local cipher suites preference in server side should be + * honored during handshaking? + */ + private boolean preferLocalCipherSuites = false; + /* * Class and subclass dynamic debugging support */ @@ -470,6 +476,7 @@ final public class SSLEngineImpl extends SSLEngine { protocolVersion, connectionState == cs_HANDSHAKE, secureRenegotiation, clientVerifyData, serverVerifyData); handshaker.setSNIMatchers(sniMatchers); + handshaker.setUseCipherSuitesOrder(preferLocalCipherSuites); } else { handshaker = new ClientHandshaker(this, sslContext, enabledProtocols, @@ -2074,6 +2081,7 @@ final public class SSLEngineImpl extends SSLEngine { params.setAlgorithmConstraints(algorithmConstraints); params.setSNIMatchers(sniMatchers); params.setServerNames(serverNames); + params.setUseCipherSuitesOrder(preferLocalCipherSuites); return params; } @@ -2088,6 +2096,7 @@ final public class SSLEngineImpl extends SSLEngine { // the super implementation does not handle the following parameters identificationProtocol = params.getEndpointIdentificationAlgorithm(); algorithmConstraints = params.getAlgorithmConstraints(); + preferLocalCipherSuites = params.getUseCipherSuitesOrder(); List sniNames = params.getServerNames(); if (sniNames != null) { @@ -2104,6 +2113,7 @@ final public class SSLEngineImpl extends SSLEngine { handshaker.setAlgorithmConstraints(algorithmConstraints); if (roleIsServer) { handshaker.setSNIMatchers(sniMatchers); + handshaker.setUseCipherSuitesOrder(preferLocalCipherSuites); } else { handshaker.setSNIServerNames(serverNames); } diff --git a/jdk/src/share/classes/sun/security/ssl/SSLServerSocketImpl.java b/jdk/src/share/classes/sun/security/ssl/SSLServerSocketImpl.java index 0e0edf18e4a..464bab23ad4 100644 --- a/jdk/src/share/classes/sun/security/ssl/SSLServerSocketImpl.java +++ b/jdk/src/share/classes/sun/security/ssl/SSLServerSocketImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2013, 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 @@ -92,6 +92,12 @@ class SSLServerSocketImpl extends SSLServerSocket Collection sniMatchers = Collections.emptyList(); + /* + * Whether local cipher suites preference in server side should be + * honored during handshaking? + */ + private boolean preferLocalCipherSuites = false; + /** * Create an SSL server socket on a port, using a non-default * authentication context and a specified connection backlog. @@ -304,6 +310,8 @@ class SSLServerSocketImpl extends SSLServerSocket params.setEndpointIdentificationAlgorithm(identificationProtocol); params.setAlgorithmConstraints(algorithmConstraints); params.setSNIMatchers(sniMatchers); + params.setUseCipherSuitesOrder(preferLocalCipherSuites); + return params; } @@ -318,6 +326,7 @@ class SSLServerSocketImpl extends SSLServerSocket // the super implementation does not handle the following parameters identificationProtocol = params.getEndpointIdentificationAlgorithm(); algorithmConstraints = params.getAlgorithmConstraints(); + preferLocalCipherSuites = params.getUseCipherSuitesOrder(); Collection matchers = params.getSNIMatchers(); if (matchers != null) { sniMatchers = params.getSNIMatchers(); @@ -334,7 +343,7 @@ class SSLServerSocketImpl extends SSLServerSocket SSLSocketImpl s = new SSLSocketImpl(sslContext, useServerMode, enabledCipherSuites, doClientAuth, enableSessionCreation, enabledProtocols, identificationProtocol, algorithmConstraints, - sniMatchers); + sniMatchers, preferLocalCipherSuites); implAccept(s); s.doneConnect(); diff --git a/jdk/src/share/classes/sun/security/ssl/SSLSocketImpl.java b/jdk/src/share/classes/sun/security/ssl/SSLSocketImpl.java index dfe612966e0..4d591e3d7a5 100644 --- a/jdk/src/share/classes/sun/security/ssl/SSLSocketImpl.java +++ b/jdk/src/share/classes/sun/security/ssl/SSLSocketImpl.java @@ -377,6 +377,12 @@ final public class SSLSocketImpl extends BaseSSLSocketImpl { */ private ByteArrayOutputStream heldRecordBuffer = null; + /* + * Whether local cipher suites preference in server side should be + * honored during handshaking? + */ + private boolean preferLocalCipherSuites = false; + // // CONSTRUCTORS AND INITIALIZATION CODE // @@ -482,7 +488,8 @@ final public class SSLSocketImpl extends BaseSSLSocketImpl { boolean sessionCreation, ProtocolList protocols, String identificationProtocol, AlgorithmConstraints algorithmConstraints, - Collection sniMatchers) throws IOException { + Collection sniMatchers, + boolean preferLocalCipherSuites) throws IOException { super(); doClientAuth = clientAuth; @@ -490,6 +497,7 @@ final public class SSLSocketImpl extends BaseSSLSocketImpl { this.identificationProtocol = identificationProtocol; this.algorithmConstraints = algorithmConstraints; this.sniMatchers = sniMatchers; + this.preferLocalCipherSuites = preferLocalCipherSuites; init(context, serverMode); /* @@ -1284,6 +1292,7 @@ final public class SSLSocketImpl extends BaseSSLSocketImpl { protocolVersion, connectionState == cs_HANDSHAKE, secureRenegotiation, clientVerifyData, serverVerifyData); handshaker.setSNIMatchers(sniMatchers); + handshaker.setUseCipherSuitesOrder(preferLocalCipherSuites); } else { handshaker = new ClientHandshaker(this, sslContext, enabledProtocols, @@ -2502,6 +2511,7 @@ final public class SSLSocketImpl extends BaseSSLSocketImpl { params.setAlgorithmConstraints(algorithmConstraints); params.setSNIMatchers(sniMatchers); params.setServerNames(serverNames); + params.setUseCipherSuitesOrder(preferLocalCipherSuites); return params; } @@ -2516,6 +2526,7 @@ final public class SSLSocketImpl extends BaseSSLSocketImpl { // the super implementation does not handle the following parameters identificationProtocol = params.getEndpointIdentificationAlgorithm(); algorithmConstraints = params.getAlgorithmConstraints(); + preferLocalCipherSuites = params.getUseCipherSuitesOrder(); List sniNames = params.getServerNames(); if (sniNames != null) { @@ -2532,6 +2543,7 @@ final public class SSLSocketImpl extends BaseSSLSocketImpl { handshaker.setAlgorithmConstraints(algorithmConstraints); if (roleIsServer) { handshaker.setSNIMatchers(sniMatchers); + handshaker.setUseCipherSuitesOrder(preferLocalCipherSuites); } else { handshaker.setSNIServerNames(serverNames); } diff --git a/jdk/src/share/classes/sun/security/ssl/ServerHandshaker.java b/jdk/src/share/classes/sun/security/ssl/ServerHandshaker.java index e317e1f18c5..23b806f33e2 100644 --- a/jdk/src/share/classes/sun/security/ssl/ServerHandshaker.java +++ b/jdk/src/share/classes/sun/security/ssl/ServerHandshaker.java @@ -932,8 +932,18 @@ final class ServerHandshaker extends Handshaker { * the cipherSuite and keyExchange variables. */ private void chooseCipherSuite(ClientHello mesg) throws IOException { - for (CipherSuite suite : mesg.getCipherSuites().collection()) { - if (isNegotiable(suite) == false) { + CipherSuiteList prefered; + CipherSuiteList proposed; + if (preferLocalCipherSuites) { + prefered = getActiveCipherSuites(); + proposed = mesg.getCipherSuites(); + } else { + prefered = mesg.getCipherSuites(); + proposed = getActiveCipherSuites(); + } + + for (CipherSuite suite : prefered.collection()) { + if (isNegotiable(proposed, suite) == false) { continue; } @@ -948,8 +958,7 @@ final class ServerHandshaker extends Handshaker { } return; } - fatalSE(Alerts.alert_handshake_failure, - "no cipher suites in common"); + fatalSE(Alerts.alert_handshake_failure, "no cipher suites in common"); } /** diff --git a/jdk/test/sun/security/ssl/javax/net/ssl/SSLParameters/UseCipherSuitesOrder.java b/jdk/test/sun/security/ssl/javax/net/ssl/SSLParameters/UseCipherSuitesOrder.java new file mode 100644 index 00000000000..c25d74c7d2c --- /dev/null +++ b/jdk/test/sun/security/ssl/javax/net/ssl/SSLParameters/UseCipherSuitesOrder.java @@ -0,0 +1,357 @@ +/* + * Copyright (c) 2013, 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. + */ + +// +// SunJSSE does not support dynamic system properties, no way to re-use +// system properties in samevm/agentvm mode. +// + +/* + * @test + * @bug 7188657 + * @summary There should be a way to reorder the JSSE ciphers + * @run main/othervm UseCipherSuitesOrder + * TLS_RSA_WITH_AES_128_CBC_SHA,SSL_RSA_WITH_RC4_128_SHA + */ + +import java.io.*; +import java.net.*; +import javax.net.ssl.*; +import java.util.Arrays; + +public class UseCipherSuitesOrder { + + /* + * ============================================================= + * Set the various variables needed for the tests, then + * specify what tests to run on each side. + */ + + /* + * Should we run the client or server in a separate thread? + * Both sides can throw exceptions, but do you have a preference + * as to which side should be the main thread. + */ + static boolean separateServerThread = false; + + /* + * Where do we find the keystores? + */ + static String pathToStores = "../../../../etc"; + static String keyStoreFile = "keystore"; + static String trustStoreFile = "truststore"; + static String passwd = "passphrase"; + + /* + * Is the server ready to serve? + */ + volatile static boolean serverReady = false; + + /* + * Turn on SSL debugging? + */ + static boolean debug = false; + + /* + * If the client or server is doing some kind of object creation + * that the other side depends on, and that thread prematurely + * exits, you may experience a hang. The test harness will + * terminate all hung threads after its timeout has expired, + * currently 3 minutes by default, but you might try to be + * smart about it.... + */ + + /* + * Define the server side of the test. + * + * If the server prematurely exits, serverReady will be set to true + * to avoid infinite hangs. + */ + void doServerSide() throws Exception { + SSLServerSocketFactory sslssf = + (SSLServerSocketFactory) SSLServerSocketFactory.getDefault(); + SSLServerSocket sslServerSocket = + (SSLServerSocket) sslssf.createServerSocket(serverPort); + serverPort = sslServerSocket.getLocalPort(); + + // use local cipher suites preference + SSLParameters params = sslServerSocket.getSSLParameters(); + params.setUseCipherSuitesOrder(true); + params.setCipherSuites(srvEnabledCipherSuites); + sslServerSocket.setSSLParameters(params); + + /* + * Signal Client, we're ready for his connect. + */ + serverReady = true; + + SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept(); + InputStream sslIS = sslSocket.getInputStream(); + OutputStream sslOS = sslSocket.getOutputStream(); + + sslIS.read(); + sslOS.write(85); + sslOS.flush(); + + SSLSession session = sslSocket.getSession(); + if (!srvEnabledCipherSuites[0].equals(session.getCipherSuite())) { + throw new Exception( + "Expected to negotiate " + srvEnabledCipherSuites[0] + + " , but not " + session.getCipherSuite()); + } + + sslSocket.close(); + } + + /* + * Define the client side of the test. + * + * If the server prematurely exits, serverReady will be set to true + * to avoid infinite hangs. + */ + void doClientSide() throws Exception { + + /* + * Wait for server to get started. + */ + while (!serverReady) { + Thread.sleep(50); + } + + SSLSocketFactory sslsf = + (SSLSocketFactory) SSLSocketFactory.getDefault(); + SSLSocket sslSocket = (SSLSocket) + sslsf.createSocket("localhost", serverPort); + sslSocket.setEnabledCipherSuites(cliEnabledCipherSuites); + + InputStream sslIS = sslSocket.getInputStream(); + OutputStream sslOS = sslSocket.getOutputStream(); + + sslOS.write(280); + sslOS.flush(); + sslIS.read(); + + sslSocket.close(); + } + + // client enabled cipher suites + private static String[] cliEnabledCipherSuites; + + // server enabled cipher suites + private static String[] srvEnabledCipherSuites; + + private static void parseArguments(String[] args) throws Exception { + if (args.length != 1) { + System.out.println("Usage: java UseCipherSuitesOrder ciphersuites"); + System.out.println("\tciphersuites: " + + "a list of enabled cipher suites, separated with comma"); + throw new Exception("Incorrect usage"); + } + + cliEnabledCipherSuites = args[0].split(","); + + if (cliEnabledCipherSuites.length < 2) { + throw new Exception("Need to enable at least two cipher suites"); + } + + // Only need to use 2 cipher suites in server side. + srvEnabledCipherSuites = Arrays.copyOf( + cliEnabledCipherSuites, 2); + + // Reverse the cipher suite preference in server side. + srvEnabledCipherSuites[0] = cliEnabledCipherSuites[1]; + srvEnabledCipherSuites[1] = cliEnabledCipherSuites[0]; + } + + /* + * ============================================================= + * The remainder is just support stuff + */ + + // use any free port by default + volatile int serverPort = 0; + + volatile Exception serverException = null; + volatile Exception clientException = null; + + public static void main(String[] args) throws Exception { + // parse the arguments + parseArguments(args); + + String keyFilename = + System.getProperty("test.src", ".") + "/" + pathToStores + + "/" + keyStoreFile; + String trustFilename = + System.getProperty("test.src", ".") + "/" + pathToStores + + "/" + trustStoreFile; + + System.setProperty("javax.net.ssl.keyStore", keyFilename); + System.setProperty("javax.net.ssl.keyStorePassword", passwd); + System.setProperty("javax.net.ssl.trustStore", trustFilename); + System.setProperty("javax.net.ssl.trustStorePassword", passwd); + + if (debug) + System.setProperty("javax.net.debug", "all"); + + /* + * Start the tests. + */ + new UseCipherSuitesOrder(); + } + + Thread clientThread = null; + Thread serverThread = null; + + /* + * Primary constructor, used to drive remainder of the test. + * + * Fork off the other side, then do your work. + */ + UseCipherSuitesOrder() throws Exception { + Exception startException = null; + try { + if (separateServerThread) { + startServer(true); + startClient(false); + } else { + startClient(true); + startServer(false); + } + } catch (Exception e) { + startException = e; + } + + /* + * Wait for other side to close down. + */ + if (separateServerThread) { + if (serverThread != null) { + serverThread.join(); + } + } else { + if (clientThread != null) { + clientThread.join(); + } + } + + /* + * When we get here, the test is pretty much over. + * Which side threw the error? + */ + Exception local; + Exception remote; + + if (separateServerThread) { + remote = serverException; + local = clientException; + } else { + remote = clientException; + local = serverException; + } + + Exception exception = null; + + /* + * Check various exception conditions. + */ + if ((local != null) && (remote != null)) { + // If both failed, return the curthread's exception. + local.initCause(remote); + exception = local; + } else if (local != null) { + exception = local; + } else if (remote != null) { + exception = remote; + } else if (startException != null) { + exception = startException; + } + + /* + * If there was an exception *AND* a startException, + * output it. + */ + if (exception != null) { + if (exception != startException && startException != null) { + exception.addSuppressed(startException); + } + throw exception; + } + + // Fall-through: no exception to throw! + } + + void startServer(boolean newThread) throws Exception { + if (newThread) { + serverThread = new Thread() { + public void run() { + try { + doServerSide(); + } catch (Exception e) { + /* + * Our server thread just died. + * + * Release the client, if not active already... + */ + System.err.println("Server died..."); + serverReady = true; + serverException = e; + } + } + }; + serverThread.start(); + } else { + try { + doServerSide(); + } catch (Exception e) { + serverException = e; + } finally { + serverReady = true; + } + } + } + + void startClient(boolean newThread) throws Exception { + if (newThread) { + clientThread = new Thread() { + public void run() { + try { + doClientSide(); + } catch (Exception e) { + /* + * Our client thread just died. + */ + System.err.println("Client died..."); + clientException = e; + } + } + }; + clientThread.start(); + } else { + try { + doClientSide(); + } catch (Exception e) { + clientException = e; + } + } + } +} From a4c7971bdb559d5b0e8d09f145da3a25c78f5dce Mon Sep 17 00:00:00 2001 From: Weijun Wang Date: Mon, 9 Sep 2013 11:08:20 +0800 Subject: [PATCH 045/210] 8024046: Test sun/security/krb5/runNameEquals.sh failed on 7u45 Embedded linux-ppc* Reviewed-by: xuelei --- jdk/test/sun/security/krb5/runNameEquals.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/jdk/test/sun/security/krb5/runNameEquals.sh b/jdk/test/sun/security/krb5/runNameEquals.sh index 6db90c35315..b9cfb08d8b5 100644 --- a/jdk/test/sun/security/krb5/runNameEquals.sh +++ b/jdk/test/sun/security/krb5/runNameEquals.sh @@ -22,7 +22,7 @@ # # @test -# @bug 6317711 6944847 +# @bug 6317711 6944847 8024046 # @summary Ensure the GSSName has the correct impl which respects # the contract for equals and hashCode across different configurations. @@ -56,6 +56,15 @@ case "$OS" in PATHSEP=":" FILESEP="/" NATIVE=true + # Not all *nix has native GSS libs installed + krb5-config --libs gssapi 2> /dev/null + if [ $? != 0 ]; then + # Fedora has a different path + /usr/kerberos/bin/krb5-config --libs gssapi 2> /dev/null + if [ $? != 0 ]; then + NATIVE=false + fi + fi ;; CYGWIN* ) PATHSEP=";" From 33dbc2d51c62d6e6657ffbf64c026426bd6f072c Mon Sep 17 00:00:00 2001 From: Daniel Fuchs Date: Mon, 9 Sep 2013 13:59:51 +0200 Subject: [PATCH 046/210] 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship 8021003: java/util/logging/Logger/getGlobal/TestGetGlobalConcurrent.java fails intermittently 8019945: test/java/util/logging/LogManagerInstanceTest.java failing intermittently This fix untangles the class initialization of Logger and LogManager, and also cleans up the relationship between LogManager, LoggerContext, and Logger, which were at the root cause of some intermittent test failures. Reviewed-by: mchung, martin, plevart --- .../classes/java/util/logging/LogManager.java | 310 ++++++++++++------ .../classes/java/util/logging/Logger.java | 42 ++- .../Logger/getGlobal/TestGetGlobal.java | 10 +- .../getGlobal/TestGetGlobalConcurrent.java | 26 +- .../java/util/logging/Logger/getGlobal/policy | 1 + .../java/util/logging/ParentLoggersTest.java | 2 +- .../util/logging/TestAppletLoggerContext.java | 151 ++++----- 7 files changed, 334 insertions(+), 208 deletions(-) diff --git a/jdk/src/share/classes/java/util/logging/LogManager.java b/jdk/src/share/classes/java/util/logging/LogManager.java index 717e52990e1..8596cbeb8fe 100644 --- a/jdk/src/share/classes/java/util/logging/LogManager.java +++ b/jdk/src/share/classes/java/util/logging/LogManager.java @@ -144,7 +144,7 @@ import sun.misc.SharedSecrets; public class LogManager { // The global LogManager object - private static LogManager manager; + private static final LogManager manager; private Properties props = new Properties(); private final static Level defaultLevel = Level.INFO; @@ -156,8 +156,10 @@ public class LogManager { // LoggerContext for system loggers and user loggers private final LoggerContext systemContext = new SystemLoggerContext(); private final LoggerContext userContext = new LoggerContext(); - private Logger rootLogger; - + // non final field - make it volatile to make sure that other threads + // will see the new value once ensureLogManagerInitialized() has finished + // executing. + private volatile Logger rootLogger; // Have we done the primordial reading of the configuration file? // (Must be done after a suitable amount of java.lang.System // initialization has been done) @@ -169,58 +171,35 @@ public class LogManager { private boolean deathImminent; static { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - String cname = null; - try { - cname = System.getProperty("java.util.logging.manager"); - if (cname != null) { - try { - Class clz = ClassLoader.getSystemClassLoader().loadClass(cname); - manager = (LogManager) clz.newInstance(); - } catch (ClassNotFoundException ex) { - Class clz = Thread.currentThread().getContextClassLoader().loadClass(cname); - manager = (LogManager) clz.newInstance(); - } + manager = AccessController.doPrivileged(new PrivilegedAction() { + @Override + public LogManager run() { + LogManager mgr = null; + String cname = null; + try { + cname = System.getProperty("java.util.logging.manager"); + if (cname != null) { + try { + Class clz = ClassLoader.getSystemClassLoader() + .loadClass(cname); + mgr = (LogManager) clz.newInstance(); + } catch (ClassNotFoundException ex) { + Class clz = Thread.currentThread() + .getContextClassLoader().loadClass(cname); + mgr = (LogManager) clz.newInstance(); } - } catch (Exception ex) { - System.err.println("Could not load Logmanager \"" + cname + "\""); - ex.printStackTrace(); } - if (manager == null) { - manager = new LogManager(); - } - - // Create and retain Logger for the root of the namespace. - manager.rootLogger = manager.new RootLogger(); - // since by design the global manager's userContext and - // systemContext don't have their requiresDefaultLoggers - // flag set - we make sure to add the root logger to - // the global manager's default contexts here. - manager.addLogger(manager.rootLogger); - manager.systemContext.addLocalLogger(manager.rootLogger, false); - manager.userContext.addLocalLogger(manager.rootLogger, false); - - // Adding the global Logger. Doing so in the Logger. - // would deadlock with the LogManager.. - // Do not call Logger.getGlobal() here as this might trigger - // the deadlock too. - @SuppressWarnings("deprecation") - final Logger global = Logger.global; - global.setLogManager(manager); - - // Make sure the global logger will be registered in the - // global manager's default contexts. - manager.addLogger(global); - manager.systemContext.addLocalLogger(global, false); - manager.userContext.addLocalLogger(global, false); - - // We don't call readConfiguration() here, as we may be running - // very early in the JVM startup sequence. Instead readConfiguration - // will be called lazily in getLogManager(). - return null; + } catch (Exception ex) { + System.err.println("Could not load Logmanager \"" + cname + "\""); + ex.printStackTrace(); } - }); + if (mgr == null) { + mgr = new LogManager(); + } + return mgr; + + } + }); } @@ -235,6 +214,7 @@ public class LogManager { this.setContextClassLoader(null); } + @Override public void run() { // This is to ensure the LogManager. is completed // before synchronized block. Otherwise deadlocks are possible. @@ -270,13 +250,104 @@ public class LogManager { } } + /** + * Lazy initialization: if this instance of manager is the global + * manager then this method will read the initial configuration and + * add the root logger and global logger by calling addLogger(). + * + * Note that it is subtly different from what we do in LoggerContext. + * In LoggerContext we're patching up the logger context tree in order to add + * the root and global logger *to the context tree*. + * + * For this to work, addLogger() must have already have been called + * once on the LogManager instance for the default logger being + * added. + * + * This is why ensureLogManagerInitialized() needs to be called before + * any logger is added to any logger context. + * + */ + private boolean initializedCalled = false; + private volatile boolean initializationDone = false; + final void ensureLogManagerInitialized() { + final LogManager owner = this; + if (initializationDone || owner != manager) { + // we don't want to do this twice, and we don't want to do + // this on private manager instances. + return; + } + + // Maybe another thread has called ensureLogManagerInitialized() + // before us and is still executing it. If so we will block until + // the log manager has finished initialized, then acquire the monitor, + // notice that initializationDone is now true and return. + // Otherwise - we have come here first! We will acquire the monitor, + // see that initializationDone is still false, and perform the + // initialization. + // + synchronized(this) { + // If initializedCalled is true it means that we're already in + // the process of initializing the LogManager in this thread. + // There has been a recursive call to ensureLogManagerInitialized(). + final boolean isRecursiveInitialization = (initializedCalled == true); + + assert initializedCalled || !initializationDone + : "Initialization can't be done if initialized has not been called!"; + + if (isRecursiveInitialization || initializationDone) { + // If isRecursiveInitialization is true it means that we're + // already in the process of initializing the LogManager in + // this thread. There has been a recursive call to + // ensureLogManagerInitialized(). We should not proceed as + // it would lead to infinite recursion. + // + // If initializationDone is true then it means the manager + // has finished initializing; just return: we're done. + return; + } + // Calling addLogger below will in turn call requiresDefaultLogger() + // which will call ensureLogManagerInitialized(). + // We use initializedCalled to break the recursion. + initializedCalled = true; + try { + AccessController.doPrivileged(new PrivilegedAction() { + @Override + public Object run() { + assert rootLogger == null; + assert initializedCalled && !initializationDone; + + // Read configuration. + owner.readPrimordialConfiguration(); + + // Create and retain Logger for the root of the namespace. + owner.rootLogger = owner.new RootLogger(); + owner.addLogger(owner.rootLogger); + + // Adding the global Logger. + // Do not call Logger.getGlobal() here as this might trigger + // subtle inter-dependency issues. + @SuppressWarnings("deprecation") + final Logger global = Logger.global; + + // Make sure the global logger will be registered in the + // global manager + owner.addLogger(global); + return null; + } + }); + } finally { + initializationDone = true; + } + } + } + /** * Returns the global LogManager object. * @return the global LogManager object */ public static LogManager getLogManager() { if (manager != null) { - manager.readPrimordialConfiguration(); + manager.ensureLogManagerInitialized(); } return manager; } @@ -295,6 +366,7 @@ public class LogManager { try { AccessController.doPrivileged(new PrivilegedExceptionAction() { + @Override public Void run() throws Exception { readConfiguration(); @@ -304,8 +376,7 @@ public class LogManager { } }); } catch (Exception ex) { - // System.err.println("Can't read logging configuration:"); - // ex.printStackTrace(); + assert false : "Exception raised while reading logging configuration: " + ex; } } } @@ -392,7 +463,7 @@ public class LogManager { } // LoggerContext maps from AppContext - private static WeakHashMap contextsMap = null; + private WeakHashMap contextsMap = null; // Returns the LoggerContext for the user code (i.e. application or AppContext). // Loggers are isolated from each AppContext. @@ -414,10 +485,7 @@ public class LogManager { context = contextsMap.get(ecx); if (context == null) { // Create a new LoggerContext for the applet. - // The new logger context has its requiresDefaultLoggers - // flag set to true - so that these loggers will be - // lazily added when the context is firt accessed. - context = new LoggerContext(true); + context = new LoggerContext(); contextsMap.put(ecx, context); } } @@ -427,9 +495,14 @@ public class LogManager { return context != null ? context : userContext; } + // The system context. + final LoggerContext getSystemContext() { + return systemContext; + } + private List contexts() { List cxs = new ArrayList<>(); - cxs.add(systemContext); + cxs.add(getSystemContext()); cxs.add(getUserContext()); return cxs; } @@ -450,7 +523,7 @@ public class LogManager { Logger result = getLogger(name); if (result == null) { // only allocate the new logger once - Logger newLogger = new Logger(name, resourceBundleName, caller); + Logger newLogger = new Logger(name, resourceBundleName, caller, this); do { if (addLogger(newLogger)) { // We successfully added the new Logger that we @@ -477,7 +550,7 @@ public class LogManager { Logger demandSystemLogger(String name, String resourceBundleName) { // Add a system logger in the system context's namespace - final Logger sysLogger = systemContext.demandLogger(name, resourceBundleName); + final Logger sysLogger = getSystemContext().demandLogger(name, resourceBundleName); // Add the system logger to the LogManager's namespace if not exist // so that there is only one single logger of the given name. @@ -501,6 +574,7 @@ public class LogManager { // if logger already exists but handlers not set final Logger l = logger; AccessController.doPrivileged(new PrivilegedAction() { + @Override public Void run() { for (Handler hdl : l.getHandlers()) { sysLogger.addHandler(hdl); @@ -519,24 +593,52 @@ public class LogManager { // doesn't exist in the user context, it'll also be added to the user context. // The user context is queried by the user code and all other loggers are // added in the user context. - static class LoggerContext { + class LoggerContext { // Table of named Loggers that maps names to Loggers. private final Hashtable namedLoggers = new Hashtable<>(); // Tree of named Loggers private final LogNode root; - private final boolean requiresDefaultLoggers; private LoggerContext() { - this(false); - } - private LoggerContext(boolean requiresDefaultLoggers) { this.root = new LogNode(null, this); - this.requiresDefaultLoggers = requiresDefaultLoggers; + } + + + // Tells whether default loggers are required in this context. + // If true, the default loggers will be lazily added. + final boolean requiresDefaultLoggers() { + final boolean requiresDefaultLoggers = (getOwner() == manager); + if (requiresDefaultLoggers) { + getOwner().ensureLogManagerInitialized(); + } + return requiresDefaultLoggers; + } + + // This context's LogManager. + final LogManager getOwner() { + return LogManager.this; + } + + // This context owner's root logger, which if not null, and if + // the context requires default loggers, will be added to the context + // logger's tree. + final Logger getRootLogger() { + return getOwner().rootLogger; + } + + // The global logger, which if not null, and if + // the context requires default loggers, will be added to the context + // logger's tree. + final Logger getGlobalLogger() { + @SuppressWarnings("deprecated") // avoids initialization cycles. + final Logger global = Logger.global; + return global; } Logger demandLogger(String name, String resourceBundleName) { // a LogManager subclass may have its own implementation to add and // get a Logger. So delegate to the LogManager to do the work. - return manager.demandLogger(name, resourceBundleName, null); + final LogManager owner = getOwner(); + return owner.demandLogger(name, resourceBundleName, null); } @@ -548,10 +650,10 @@ public class LogManager { // or getLoggerNames() // private void ensureInitialized() { - if (requiresDefaultLoggers) { + if (requiresDefaultLoggers()) { // Ensure that the root and global loggers are set. - ensureDefaultLogger(manager.rootLogger); - ensureDefaultLogger(Logger.global); + ensureDefaultLogger(getRootLogger()); + ensureDefaultLogger(getGlobalLogger()); } } @@ -580,13 +682,13 @@ public class LogManager { // before adding 'logger'. // private void ensureAllDefaultLoggers(Logger logger) { - if (requiresDefaultLoggers) { + if (requiresDefaultLoggers()) { final String name = logger.getName(); if (!name.isEmpty()) { - ensureDefaultLogger(manager.rootLogger); - } - if (!Logger.GLOBAL_LOGGER_NAME.equals(name)) { - ensureDefaultLogger(Logger.global); + ensureDefaultLogger(getRootLogger()); + if (!Logger.GLOBAL_LOGGER_NAME.equals(name)) { + ensureDefaultLogger(getGlobalLogger()); + } } } } @@ -598,8 +700,8 @@ public class LogManager { // This check is simple sanity: we do not want that this // method be called for anything else than Logger.global // or owner.rootLogger. - if (!requiresDefaultLoggers || logger == null - || logger != Logger.global && logger != manager.rootLogger) { + if (!requiresDefaultLoggers() || logger == null + || logger != Logger.global && logger != LogManager.this.rootLogger) { // the case where we have a non null logger which is neither // Logger.global nor manager.rootLogger indicates a serious @@ -625,7 +727,7 @@ public class LogManager { boolean addLocalLogger(Logger logger) { // no need to add default loggers if it's not required - return addLocalLogger(logger, requiresDefaultLoggers); + return addLocalLogger(logger, requiresDefaultLoggers()); } // Add a logger to this context. This method will only set its level @@ -663,11 +765,13 @@ public class LogManager { // We're adding a new logger. // Note that we are creating a weak reference here. - ref = manager.new LoggerWeakRef(logger); + final LogManager owner = getOwner(); + logger.setLogManager(owner); + ref = owner.new LoggerWeakRef(logger); namedLoggers.put(name, ref); // Apply any initial level defined for the new logger. - Level level = manager.getLevelProperty(name + ".level", null); + Level level = owner.getLevelProperty(name + ".level", null); if (level != null) { doSetLevel(logger, level); } @@ -719,10 +823,12 @@ public class LogManager { // If logger.getUseParentHandlers() returns 'true' and any of the logger's // parents have levels or handlers defined, make sure they are instantiated. private void processParentHandlers(final Logger logger, final String name) { + final LogManager owner = getOwner(); AccessController.doPrivileged(new PrivilegedAction() { + @Override public Void run() { - if (logger != manager.rootLogger) { - boolean useParent = manager.getBooleanProperty(name + ".useParentHandlers", true); + if (logger != owner.rootLogger) { + boolean useParent = owner.getBooleanProperty(name + ".useParentHandlers", true); if (!useParent) { logger.setUseParentHandlers(false); } @@ -738,8 +844,8 @@ public class LogManager { break; } String pname = name.substring(0, ix2); - if (manager.getProperty(pname + ".level") != null || - manager.getProperty(pname + ".handlers") != null) { + if (owner.getProperty(pname + ".level") != null || + owner.getProperty(pname + ".handlers") != null) { // This pname has a level/handlers definition. // Make sure it exists. demandLogger(pname, null); @@ -779,16 +885,17 @@ public class LogManager { } } - static class SystemLoggerContext extends LoggerContext { + final class SystemLoggerContext extends LoggerContext { // Add a system logger in the system context's namespace as well as // in the LogManager's namespace if not exist so that there is only // one single logger of the given name. System loggers are visible // to applications unless a logger of the same name has been added. + @Override Logger demandLogger(String name, String resourceBundleName) { Logger result = findLogger(name); if (result == null) { // only allocate the new system logger once - Logger newLogger = new Logger(name, resourceBundleName); + Logger newLogger = new Logger(name, resourceBundleName, null, getOwner()); do { if (addLocalLogger(newLogger)) { // We successfully added the new Logger that we @@ -822,6 +929,7 @@ public class LogManager { final String handlersPropertyName) { AccessController.doPrivileged(new PrivilegedAction() { + @Override public Object run() { String names[] = parseClassNames(handlersPropertyName); for (int i = 0; i < names.length; i++) { @@ -1014,6 +1122,7 @@ public class LogManager { // There is a security manager. Raise privilege before // calling setLevel. AccessController.doPrivileged(new PrivilegedAction() { + @Override public Object run() { logger.setLevel(level); return null; @@ -1032,6 +1141,7 @@ public class LogManager { // There is a security manager. Raise privilege before // calling setParent. AccessController.doPrivileged(new PrivilegedAction() { + @Override public Object run() { logger.setParent(parent); return null; @@ -1129,14 +1239,9 @@ public class LogManager { f = new File(f, "logging.properties"); fname = f.getCanonicalPath(); } - InputStream in = new FileInputStream(fname); - BufferedInputStream bin = new BufferedInputStream(in); - try { + try (final InputStream in = new FileInputStream(fname)) { + final BufferedInputStream bin = new BufferedInputStream(in); readConfiguration(bin); - } finally { - if (in != null) { - in.close(); - } } } @@ -1201,7 +1306,7 @@ public class LogManager { } hands = hands.trim(); int ix = 0; - Vector result = new Vector<>(); + final List result = new ArrayList<>(); while (ix < hands.length()) { int end = ix; while (end < hands.length()) { @@ -1471,28 +1576,35 @@ public class LogManager { // We use a subclass of Logger for the root logger, so // that we only instantiate the global handlers when they // are first needed. - private class RootLogger extends Logger { + private final class RootLogger extends Logger { private RootLogger() { - super("", null); + // We do not call the protected Logger two args constructor here, + // to avoid calling LogManager.getLogManager() from within the + // RootLogger constructor. + super("", null, null, LogManager.this); setLevel(defaultLevel); } + @Override public void log(LogRecord record) { // Make sure that the global handlers have been instantiated. initializeGlobalHandlers(); super.log(record); } + @Override public void addHandler(Handler h) { initializeGlobalHandlers(); super.addHandler(h); } + @Override public void removeHandler(Handler h) { initializeGlobalHandlers(); super.removeHandler(h); } + @Override public Handler[] getHandlers() { initializeGlobalHandlers(); return super.getHandlers(); diff --git a/jdk/src/share/classes/java/util/logging/Logger.java b/jdk/src/share/classes/java/util/logging/Logger.java index a7f0cc2cd4a..1393ba2aa0d 100644 --- a/jdk/src/share/classes/java/util/logging/Logger.java +++ b/jdk/src/share/classes/java/util/logging/Logger.java @@ -245,14 +245,26 @@ public class Logger { // In order to finish the initialization of the global logger, we // will therefore call LogManager.getLogManager() here. // - // Care must be taken *not* to call Logger.getGlobal() in - // LogManager static initializers in order to avoid such - // deadlocks. - // - if (global != null && global.manager == null) { - // Complete initialization of the global Logger. - global.manager = LogManager.getLogManager(); - } + // To prevent race conditions we also need to call + // LogManager.getLogManager() unconditionally here. + // Indeed we cannot rely on the observed value of global.manager, + // because global.manager will become not null somewhere during + // the initialization of LogManager. + // If two threads are calling getGlobal() concurrently, one thread + // will see global.manager null and call LogManager.getLogManager(), + // but the other thread could come in at a time when global.manager + // is already set although ensureLogManagerInitialized is not finished + // yet... + // Calling LogManager.getLogManager() unconditionally will fix that. + + LogManager.getLogManager(); + + // Now the global LogManager should be initialized, + // and the global logger should have been added to + // it, unless we were called within the constructor of a LogManager + // subclass installed as LogManager, in which case global.manager + // would still be null, and global will be lazily initialized later on. + return global; } @@ -298,11 +310,11 @@ public class Logger { * no corresponding resource can be found. */ protected Logger(String name, String resourceBundleName) { - this(name, resourceBundleName, null); + this(name, resourceBundleName, null, LogManager.getLogManager()); } - Logger(String name, String resourceBundleName, Class caller) { - this.manager = LogManager.getLogManager(); + Logger(String name, String resourceBundleName, Class caller, LogManager manager) { + this.manager = manager; setupResourceInfo(resourceBundleName, caller); this.name = name; levelValue = Level.INFO.intValue(); @@ -332,8 +344,8 @@ public class Logger { levelValue = Level.INFO.intValue(); } - // It is called from the LogManager. to complete - // initialization of the global Logger. + // It is called from LoggerContext.addLocalLogger() when the logger + // is actually added to a LogManager. void setLogManager(LogManager manager) { this.manager = manager; } @@ -558,7 +570,7 @@ public class Logger { // cleanup some Loggers that have been GC'ed manager.drainLoggerRefQueueBounded(); Logger result = new Logger(null, resourceBundleName, - Reflection.getCallerClass()); + Reflection.getCallerClass(), manager); result.anonymous = true; Logger root = manager.getLogger(""); result.doSetParent(root); @@ -1798,7 +1810,7 @@ public class Logger { if (parent == null) { throw new NullPointerException(); } - manager.checkPermission(); + checkPermission(); doSetParent(parent); } diff --git a/jdk/test/java/util/logging/Logger/getGlobal/TestGetGlobal.java b/jdk/test/java/util/logging/Logger/getGlobal/TestGetGlobal.java index dd901ed5f92..4c6b39b0acd 100644 --- a/jdk/test/java/util/logging/Logger/getGlobal/TestGetGlobal.java +++ b/jdk/test/java/util/logging/Logger/getGlobal/TestGetGlobal.java @@ -57,6 +57,12 @@ public class TestGetGlobal { } public static void main(String... args) { + final String manager = System.getProperty("java.util.logging.manager", null); + + final String description = "TestGetGlobal" + + (System.getSecurityManager() == null ? " " : + " -Djava.security.manager ") + + (manager == null ? "" : "-Djava.util.logging.manager=" + manager); Logger.global.info(messages[0]); // at this point LogManager is not // initialized yet, so this message should not appear. @@ -67,7 +73,9 @@ public class TestGetGlobal { final List expected = Arrays.asList(Arrays.copyOfRange(messages, 1, messages.length)); if (!testgetglobal.HandlerImpl.received.equals(expected)) { - throw new Error("Unexpected message list: "+testgetglobal.HandlerImpl.received+" vs "+ expected); + System.err.println("Test case failed: " + description); + throw new Error("Unexpected message list: "+testgetglobal.HandlerImpl.received+" vs "+ expected + + "\n\t"+description); } } } diff --git a/jdk/test/java/util/logging/Logger/getGlobal/TestGetGlobalConcurrent.java b/jdk/test/java/util/logging/Logger/getGlobal/TestGetGlobalConcurrent.java index 4ef38ce3611..e3f9d1d8872 100644 --- a/jdk/test/java/util/logging/Logger/getGlobal/TestGetGlobalConcurrent.java +++ b/jdk/test/java/util/logging/Logger/getGlobal/TestGetGlobalConcurrent.java @@ -22,17 +22,18 @@ */ import java.util.Arrays; import java.util.List; +import java.util.logging.Level; import java.util.logging.Logger; /** * @test - * @bug 7184195 - * @summary checks that java.util.logging.Logger.getGlobal().info() logs without configuration + * @bug 7184195 8021003 + * @summary Test that the global logger can log with no configuration when accessed from multiple threads. * @build TestGetGlobalConcurrent testgetglobal.HandlerImpl testgetglobal.LogManagerImpl1 testgetglobal.LogManagerImpl2 testgetglobal.LogManagerImpl3 testgetglobal.BadLogManagerImpl testgetglobal.DummyLogManagerImpl * @run main/othervm/timeout=10 TestGetGlobalConcurrent * @run main/othervm/timeout=10/policy=policy -Djava.security.manager TestGetGlobalConcurrent - * @run main/othervm/timeout=10 -Djava.util.logging.manager=testgetglobal.LogManagerImpl TestGetGlobalConcurrent - * @run main/othervm/timeout=10/policy=policy -Djava.security.manager -Djava.util.logging.manager=testgetglobal.LogManagerImpl TestGetGlobalConcurrent + * @run main/othervm/timeout=10 -Djava.util.logging.manager=testgetglobal.LogManagerImpl1 TestGetGlobalConcurrent + * @run main/othervm/timeout=10/policy=policy -Djava.security.manager -Djava.util.logging.manager=testgetglobal.LogManagerImpl1 TestGetGlobalConcurrent * @run main/othervm/timeout=10 -Djava.util.logging.manager=testgetglobal.LogManagerImpl2 TestGetGlobalConcurrent * @run main/othervm/timeout=10/policy=policy -Djava.security.manager -Djava.util.logging.manager=testgetglobal.LogManagerImpl2 TestGetGlobalConcurrent * @run main/othervm/timeout=10 -Djava.util.logging.manager=testgetglobal.LogManagerImpl3 TestGetGlobalConcurrent @@ -69,7 +70,6 @@ public class TestGetGlobalConcurrent { // initialize the LogManager - and thus this message should appear. Logger.global.info(messages[i+1]); // Now that the LogManager is // initialized, this message should appear too. - final List expected = Arrays.asList(Arrays.copyOfRange(messages, i, i+2)); if (!testgetglobal.HandlerImpl.received.containsAll(expected)) { fail(new Error("Unexpected message list: "+testgetglobal.HandlerImpl.received+" vs "+ expected)); @@ -82,7 +82,6 @@ public class TestGetGlobalConcurrent { // initialize the LogManager - and thus this message should appear. Logger.global.info(messages[i+1]); // Now that the LogManager is // initialized, this message should appear too. - final List expected = Arrays.asList(Arrays.copyOfRange(messages, i, i+2)); if (!testgetglobal.HandlerImpl.received.containsAll(expected)) { fail(new Error("Unexpected message list: "+testgetglobal.HandlerImpl.received+" vs "+ expected)); @@ -96,7 +95,6 @@ public class TestGetGlobalConcurrent { // initialize the LogManager - and thus this message should appear. Logger.global.info(messages[i+1]); // Now that the LogManager is // initialized, this message should appear too. - final List expected = Arrays.asList(Arrays.copyOfRange(messages, i, i+2)); if (!testgetglobal.HandlerImpl.received.containsAll(expected)) { fail(new Error("Unexpected message list: "+testgetglobal.HandlerImpl.received+" vs "+ expected)); @@ -150,8 +148,17 @@ public class TestGetGlobalConcurrent { public void run() { test4(); } } + static String description = "Unknown"; + public static void main(String... args) throws Exception { + final String manager = System.getProperty("java.util.logging.manager", null); + + description = "TestGetGlobalConcurrent" + + (System.getSecurityManager() == null ? " " : + " -Djava.security.manager ") + + (manager == null ? "" : "-Djava.util.logging.manager=" + manager); + final Thread t1 = new Thread(new WaitAndRun(new Run1()), "test1"); final Thread t2 = new Thread(new WaitAndRun(new Run2()), "test2"); final Thread t3 = new Thread(new WaitAndRun(new Run3()), "test3"); @@ -169,14 +176,13 @@ public class TestGetGlobalConcurrent { final List expected = Arrays.asList(Arrays.copyOfRange(messages, 1, 3)); if (!testgetglobal.HandlerImpl.received.containsAll(expected)) { - throw new Error("Unexpected message list: "+testgetglobal.HandlerImpl.received+" vs "+ expected); + fail(new Error("Unexpected message list: "+testgetglobal.HandlerImpl.received+" vs "+ expected)); } - t1.join(); t2.join(); t3.join(); t4.join(); if (failed != null) { - throw new Error("Test failed.", failed); + throw new Error("Test failed: "+description, failed); } System.out.println("Test passed"); diff --git a/jdk/test/java/util/logging/Logger/getGlobal/policy b/jdk/test/java/util/logging/Logger/getGlobal/policy index bcb7cde0da3..fad24d0b814 100644 --- a/jdk/test/java/util/logging/Logger/getGlobal/policy +++ b/jdk/test/java/util/logging/Logger/getGlobal/policy @@ -1,6 +1,7 @@ grant { permission java.util.PropertyPermission "java.util.logging.config.file", "write"; permission java.util.PropertyPermission "test.src", "read"; + permission java.util.PropertyPermission "java.util.logging.manager", "read"; permission java.lang.RuntimePermission "setContextClassLoader"; permission java.lang.RuntimePermission "shutdownHooks"; permission java.util.logging.LoggingPermission "control"; diff --git a/jdk/test/java/util/logging/ParentLoggersTest.java b/jdk/test/java/util/logging/ParentLoggersTest.java index 72d5ddadc0f..a5070a375e3 100644 --- a/jdk/test/java/util/logging/ParentLoggersTest.java +++ b/jdk/test/java/util/logging/ParentLoggersTest.java @@ -29,7 +29,7 @@ * @author ss45998 * * @build ParentLoggersTest - * @run main/othervm ParentLoggersTest + * @run main ParentLoggersTest */ /* diff --git a/jdk/test/java/util/logging/TestAppletLoggerContext.java b/jdk/test/java/util/logging/TestAppletLoggerContext.java index 82c39381fe8..3db67543245 100644 --- a/jdk/test/java/util/logging/TestAppletLoggerContext.java +++ b/jdk/test/java/util/logging/TestAppletLoggerContext.java @@ -38,7 +38,7 @@ import sun.misc.SharedSecrets; /* * @test - * @bug 8017174 8010727 + * @bug 8017174 8010727 8019945 * @summary NPE when using Logger.getAnonymousLogger or * LogManager.getLogManager().getLogger * @@ -432,45 +432,36 @@ public class TestAppletLoggerContext { assertNull(manager.getLogger("")); assertNull(manager.getLogger("")); - Bridge.changeContext(); + for (int j = 0; j<3; j++) { + Bridge.changeContext(); - // this is not a supported configuration: - // We are in an applet context with several log managers. - // We however need to check our assumptions... + // this is not a supported configuration: + // We are in an applet context with several log managers. + // We however need to check our assumptions... - // Applet context => root logger and global logger are not null. - // root == LogManager.getLogManager().rootLogger - // global == Logger.global + // Applet context => root logger and global logger should also be null. - Logger logger3 = manager.getLogger(Logger.GLOBAL_LOGGER_NAME); - Logger logger3b = manager.getLogger(Logger.GLOBAL_LOGGER_NAME); - assertNotNull(logger3); - assertNotNull(logger3b); - Logger expected = (System.getSecurityManager() != null - ? Logger.getGlobal() - : global); - assertEquals(logger3, expected); // in applet context, we will not see - // the LogManager's custom global logger added above... - assertEquals(logger3b, expected); // in applet context, we will not see - // the LogManager's custom global logger added above... - Logger global2 = new Bridge.CustomLogger(Logger.GLOBAL_LOGGER_NAME); - manager.addLogger(global2); // adding a global logger will not work in applet context - // we will always get back the global logger. - // this could be considered as a bug... - Logger logger4 = manager.getLogger(Logger.GLOBAL_LOGGER_NAME); - Logger logger4b = manager.getLogger(Logger.GLOBAL_LOGGER_NAME); - assertNotNull(logger4); - assertNotNull(logger4b); - assertEquals(logger4, expected); // adding a global logger will not work in applet context - assertEquals(logger4b, expected); // adding a global logger will not work in applet context + Logger expected = (System.getSecurityManager() == null ? global : null); + Logger logger3 = manager.getLogger(Logger.GLOBAL_LOGGER_NAME); + Logger logger3b = manager.getLogger(Logger.GLOBAL_LOGGER_NAME); + assertEquals(expected, logger3); + assertEquals(expected, logger3b); + Logger global2 = new Bridge.CustomLogger(Logger.GLOBAL_LOGGER_NAME); + manager.addLogger(global2); + Logger logger4 = manager.getLogger(Logger.GLOBAL_LOGGER_NAME); + Logger logger4b = manager.getLogger(Logger.GLOBAL_LOGGER_NAME); + assertNotNull(logger4); + assertNotNull(logger4b); + expected = (System.getSecurityManager() == null ? global : global2);; + assertEquals(logger4, expected); + assertEquals(logger4b, expected); - Logger logger5 = manager.getLogger(""); - Logger logger5b = manager.getLogger(""); - Logger expectedRoot = (System.getSecurityManager() != null - ? LogManager.getLogManager().getLogger("") - : null); - assertEquals(logger5, expectedRoot); - assertEquals(logger5b, expectedRoot); + Logger logger5 = manager.getLogger(""); + Logger logger5b = manager.getLogger(""); + Logger expectedRoot = null; + assertEquals(logger5, expectedRoot); + assertEquals(logger5b, expectedRoot); + } } } @@ -511,57 +502,53 @@ public class TestAppletLoggerContext { assertEquals(logger4, root); assertEquals(logger4b, root); - Bridge.changeContext(); + for (int j = 0 ; j < 3 ; j++) { + Bridge.changeContext(); - // this is not a supported configuration: - // We are in an applet context with several log managers. - // We haowever need to check our assumptions... + // this is not a supported configuration: + // We are in an applet context with several log managers. + // We however need to check our assumptions... - // Applet context => root logger and global logger are not null. - // root == LogManager.getLogManager().rootLogger - // global == Logger.global + // Applet context => root logger and global logger should also be null. - Logger logger5 = manager.getLogger(""); - Logger logger5b = manager.getLogger(""); - Logger expectedRoot = (System.getSecurityManager() != null - ? LogManager.getLogManager().getLogger("") - : root); + Logger logger5 = manager.getLogger(""); + Logger logger5b = manager.getLogger(""); + Logger expectedRoot = (System.getSecurityManager() == null ? root : null); + assertEquals(logger5, expectedRoot); + assertEquals(logger5b, expectedRoot); - assertNotNull(logger5); - assertNotNull(logger5b); - assertEquals(logger5, expectedRoot); - assertEquals(logger5b, expectedRoot); - if (System.getSecurityManager() != null) { - assertNotEquals(logger5, root); - assertNotEquals(logger5b, root); + if (System.getSecurityManager() != null) { + assertNull(manager.getLogger(Logger.GLOBAL_LOGGER_NAME)); + } else { + assertEquals(global, manager.getLogger(Logger.GLOBAL_LOGGER_NAME)); + } + + Logger global2 = new Bridge.CustomLogger(Logger.GLOBAL_LOGGER_NAME); + manager.addLogger(global2); + Logger logger6 = manager.getLogger(Logger.GLOBAL_LOGGER_NAME); + Logger logger6b = manager.getLogger(Logger.GLOBAL_LOGGER_NAME); + Logger expectedGlobal = (System.getSecurityManager() == null ? global : global2); + + assertNotNull(logger6); + assertNotNull(logger6b); + assertEquals(logger6, expectedGlobal); + assertEquals(logger6b, expectedGlobal); + if (System.getSecurityManager() != null) { + assertNull(manager.getLogger("")); + } else { + assertEquals(root, manager.getLogger("")); + } + + Logger root2 = new Bridge.CustomLogger(""); + manager.addLogger(root2); + expectedRoot = (System.getSecurityManager() == null ? root : root2); + Logger logger7 = manager.getLogger(""); + Logger logger7b = manager.getLogger(""); + assertNotNull(logger7); + assertNotNull(logger7b); + assertEquals(logger7, expectedRoot); + assertEquals(logger7b, expectedRoot); } - - Logger global2 = new Bridge.CustomLogger(Logger.GLOBAL_LOGGER_NAME); - manager.addLogger(global2); // adding a global logger will not work in applet context - // we will always get back the global logger. - // this could be considered as a bug... - Logger logger6 = manager.getLogger(Logger.GLOBAL_LOGGER_NAME); - Logger logger6b = manager.getLogger(Logger.GLOBAL_LOGGER_NAME); - Logger expectedGlobal = (System.getSecurityManager() != null - ? Logger.getGlobal() - : global); - assertNotNull(logger6); - assertNotNull(logger6b); - assertEquals(logger6, expectedGlobal); // adding a global logger will not work in applet context - assertEquals(logger6b, expectedGlobal); // adding a global logger will not work in applet context - - Logger root2 = new Bridge.CustomLogger(""); - manager.addLogger(root2); // adding a root logger will not work in applet context - // we will always get back the default manager's root logger. - // this could be considered as a bug... - Logger logger7 = manager.getLogger(""); - Logger logger7b = manager.getLogger(""); - assertNotNull(logger7); - assertNotNull(logger7b); - assertEquals(logger7, expectedRoot); // adding a global logger will not work in applet context - assertEquals(logger7b, expectedRoot); // adding a global logger will not work in applet context - assertNotEquals(logger7, root2); - assertNotEquals(logger7b, root2); } } From 92c43dcb6a22965b79e8617764056f5c9d6faff5 Mon Sep 17 00:00:00 2001 From: Mark Sheppard Date: Fri, 6 Sep 2013 15:00:59 +0100 Subject: [PATCH 047/210] 8023326: [TESTBUG] java/net/CookieHandler/LocalHostCookie.java misplaced try/finally Amended test to be more robust to set of potential exceptions thrown Reviewed-by: chegar, khazra --- jdk/test/java/net/CookieHandler/LocalHostCookie.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/jdk/test/java/net/CookieHandler/LocalHostCookie.java b/jdk/test/java/net/CookieHandler/LocalHostCookie.java index ac8d61622ef..56db947126e 100644 --- a/jdk/test/java/net/CookieHandler/LocalHostCookie.java +++ b/jdk/test/java/net/CookieHandler/LocalHostCookie.java @@ -72,7 +72,9 @@ public class LocalHostCookie { } } } finally { - s.stopServer(); + if (s != null) { + s.stopServer(); + } } } @@ -96,7 +98,9 @@ public class LocalHostCookie { } public void stopServer() { - server.stop(0); + if (server != null) { + server.stop(0); + } } } From 23d61e9b454d1b6d27a2337193f54831f36a62d1 Mon Sep 17 00:00:00 2001 From: Sean Mullan Date: Fri, 6 Sep 2013 12:04:18 -0400 Subject: [PATCH 048/210] 8023362: Don't allow soft-fail behavior if OCSP responder returns "unauthorized" Reviewed-by: vinnie, xuelei --- .../security/cert/PKIXRevocationChecker.java | 3 +- .../provider/certpath/OCSPResponse.java | 2 +- .../OcspUnauthorized.java | 103 ++++++++++++++++++ 3 files changed, 105 insertions(+), 3 deletions(-) create mode 100644 jdk/test/java/security/cert/PKIXRevocationChecker/OcspUnauthorized.java diff --git a/jdk/src/share/classes/java/security/cert/PKIXRevocationChecker.java b/jdk/src/share/classes/java/security/cert/PKIXRevocationChecker.java index d0e2ee02986..b667397c8e5 100644 --- a/jdk/src/share/classes/java/security/cert/PKIXRevocationChecker.java +++ b/jdk/src/share/classes/java/security/cert/PKIXRevocationChecker.java @@ -300,8 +300,7 @@ public abstract class PKIXRevocationChecker extends PKIXCertPathChecker { *
  • The CRL or OCSP response cannot be obtained because of a * network error. *
  • The OCSP responder returns one of the following errors - * specified in section 2.3 of RFC 2560: internalError, tryLater, - * or unauthorized. + * specified in section 2.3 of RFC 2560: internalError or tryLater. *
    * Note that these conditions apply to both OCSP and CRLs, and unless * the {@code NO_FALLBACK} option is set, the revocation check is diff --git a/jdk/src/share/classes/sun/security/provider/certpath/OCSPResponse.java b/jdk/src/share/classes/sun/security/provider/certpath/OCSPResponse.java index 5580dc70b88..955d63b57f3 100644 --- a/jdk/src/share/classes/sun/security/provider/certpath/OCSPResponse.java +++ b/jdk/src/share/classes/sun/security/provider/certpath/OCSPResponse.java @@ -385,12 +385,12 @@ public final class OCSPResponse { switch (responseStatus) { case SUCCESSFUL: break; - case UNAUTHORIZED: case TRY_LATER: case INTERNAL_ERROR: throw new CertPathValidatorException( "OCSP response error: " + responseStatus, null, null, -1, BasicReason.UNDETERMINED_REVOCATION_STATUS); + case UNAUTHORIZED: default: throw new CertPathValidatorException("OCSP response error: " + responseStatus); diff --git a/jdk/test/java/security/cert/PKIXRevocationChecker/OcspUnauthorized.java b/jdk/test/java/security/cert/PKIXRevocationChecker/OcspUnauthorized.java new file mode 100644 index 00000000000..83f19248959 --- /dev/null +++ b/jdk/test/java/security/cert/PKIXRevocationChecker/OcspUnauthorized.java @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2013, 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 8023362 + * @summary Make sure Ocsp UNAUTHORIZED response is treated as failure when + * SOFT_FAIL option is set + */ + +import java.io.ByteArrayInputStream; +import java.security.cert.*; +import java.security.cert.PKIXRevocationChecker.Option; +import java.util.Base64; +import java.util.Collections; +import java.util.EnumSet; + +public class OcspUnauthorized { + + private final static String OCSP_RESPONSE = "MAMKAQY="; + + private final static String EE_CERT = + "MIICADCCAWmgAwIBAgIEOvxUmjANBgkqhkiG9w0BAQQFADAqMQswCQYDVQQGEwJ1czE" + + "MMAoGA1UEChMDc3VuMQ0wCwYDVQQLEwRsYWJzMB4XDTAxMDUxNDIwNDQyMVoXDTI4MD" + + "kyOTIwNDQyMVowOTELMAkGA1UEBhMCdXMxDDAKBgNVBAoTA3N1bjENMAsGA1UECxMEb" + + "GFiczENMAsGA1UECxMEaXNyZzCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA4MmP" + + "GDriFJ+OhDlTuLpHzPy0nawDKyIYUJPZmU9M/pCAUbZewAOyAXGPYVU1og2ZiO9tWBi" + + "ZBeJGoFHEkkhfeqSVb2PsRckiXvPZ3AiSVmdX0uD/a963abmhRMYB1gDO2+jBe3F/DU" + + "pHwpyThchy8tYUMh7Gr7+m/8FwZbdbSpMCAwEAAaMkMCIwDwYDVR0PAQH/BAUDAwekA" + + "DAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBBAUAA4GBAME3fmXvES0FVDXSD1iC" + + "TJLf86kUy3H+uMG7h5pOQmcfF1o9PVWlNByVf4r2b4GRgftPQ3Ao0SAvq1aSkW7YpkN" + + "pcartYqNk2E5brPajOC0v+Pkxf/g/pkRTT6Zp+9erGQF4Ta62q0iwOyc3FovSbh0Ph2" + + "WidZRP4qUG5I6JmGkI"; + + private final static String TRUST_ANCHOR = + "MIICIzCCAYygAwIBAgIEOvxT7DANBgkqhkiG9w0BAQQFADAbMQswCQYDVQQGEwJ1czE" + + "MMAoGA1UEChMDc3VuMB4XDTAxMDUxNDIxMDQyOVoXDTI4MDkyOTIxMDQyOVowKjELMA" + + "kGA1UEBhMCdXMxDDAKBgNVBAoTA3N1bjENMAsGA1UECxMEbGFiczCBnzANBgkqhkiG9" + + "w0BAQEFAAOBjQAwgYkCgYEA0/16V87rhznCM0y7IqyGcfQBentG+PglA+1hiqCuQY/A" + + "jFiDKr5N+LpcfU28P41E4M+DSDrMIEe4JchRcXeJY6aIVhpOveVV9mgtBaEKlsScrIJ" + + "zmVqM07PG9JENg2FibECnB5TNUSfVbFKfvtAqaZ7Pc971oZVoIePBWnfKV9kCAwEAAa" + + "NlMGMwPwYDVR0eAQH/BDUwM6AxMC+kKjELMAkGA1UEBhMCdXMxDDAKBgNVBAoTA3N1b" + + "jENMAsGA1UECxMEbGFic4ABAzAPBgNVHQ8BAf8EBQMDB6QAMA8GA1UdEwEB/wQFMAMB" + + "Af8wDQYJKoZIhvcNAQEEBQADgYEAfJ5HWd7K5PmX0+Vbsux4SYhoaejDwwgS43BRNa+" + + "AmFq9LIZ+ZcjBMVte8Y3sJF+nz9+1qBaUhNhbaECCqsgmWSwvI+0kUzJXL89k9AdQ8m" + + "AYf6CB6+kaZQBgrdSdqSGz3tCVa2MIK8wmb0ROM40oJ7vt3qSwgFi3UTltxkFfwQ0="; + + private static CertificateFactory cf; + private static Base64.Decoder base64Decoder = Base64.getDecoder(); + + public static void main(String[] args) throws Exception { + cf = CertificateFactory.getInstance("X.509"); + X509Certificate taCert = getX509Cert(TRUST_ANCHOR); + X509Certificate eeCert = getX509Cert(EE_CERT); + CertPath cp = cf.generateCertPath(Collections.singletonList(eeCert)); + + CertPathValidator cpv = CertPathValidator.getInstance("PKIX"); + PKIXRevocationChecker prc = + (PKIXRevocationChecker)cpv.getRevocationChecker(); + prc.setOptions(EnumSet.of(Option.SOFT_FAIL, Option.NO_FALLBACK)); + byte[] response = base64Decoder.decode(OCSP_RESPONSE); + + prc.setOcspResponses(Collections.singletonMap(eeCert, response)); + + TrustAnchor ta = new TrustAnchor(taCert, null); + PKIXParameters params = new PKIXParameters(Collections.singleton(ta)); + + params.addCertPathChecker(prc); + + try { + cpv.validate(cp, params); + throw new Exception("FAILED: expected CertPathValidatorException"); + } catch (CertPathValidatorException cpve) { + cpve.printStackTrace(); + } + } + + private static X509Certificate getX509Cert(String enc) throws Exception { + byte[] bytes = base64Decoder.decode(enc); + ByteArrayInputStream is = new ByteArrayInputStream(bytes); + return (X509Certificate)cf.generateCertificate(is); + } +} From ab579cbd5f466139fa402f5dae5512a72f5ce2a9 Mon Sep 17 00:00:00 2001 From: Mark Sheppard Date: Mon, 9 Sep 2013 13:44:30 +0100 Subject: [PATCH 049/210] 8021372: NetworkInterface.getNetworkInterfaces() returns duplicate hardware address Amended src/windows/native/java/net/NetworkInterface_winXP.c to "properly" handle Ipv6IfIndex Reviewed-by: chegar, dsamersoff --- .../native/java/net/NetworkInterface_winXP.c | 19 ++- .../UniqueMacAddressesTest.java | 129 ++++++++++++++++++ 2 files changed, 141 insertions(+), 7 deletions(-) create mode 100644 jdk/test/java/net/NetworkInterface/UniqueMacAddressesTest.java diff --git a/jdk/src/windows/native/java/net/NetworkInterface_winXP.c b/jdk/src/windows/native/java/net/NetworkInterface_winXP.c index 1078d826afa..414f5c701d3 100644 --- a/jdk/src/windows/native/java/net/NetworkInterface_winXP.c +++ b/jdk/src/windows/native/java/net/NetworkInterface_winXP.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2013, 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 @@ -82,7 +82,6 @@ static int getAdapters (JNIEnv *env, IP_ADAPTER_ADDRESSES **adapters) { IP_ADAPTER_ADDRESSES *adapterInfo; ULONG len; adapterInfo = (IP_ADAPTER_ADDRESSES *)malloc (bufsize); - if (adapterInfo == NULL) { JNU_ThrowByName(env, "java/lang/OutOfMemoryError", "Native heap allocation failure"); return -1; @@ -160,8 +159,12 @@ IP_ADAPTER_ADDRESSES *getAdapter (JNIEnv *env, jint index) { ptr = adapterInfo; ret = NULL; while (ptr != NULL) { - // IPv4 interface - if (ptr->Ipv6IfIndex == index) { + // in theory the IPv4 index and the IPv6 index can be the same + // where an interface is enabled for v4 and v6 + // IfIndex == 0 IPv4 not available on this interface + // Ipv6IfIndex == 0 IPv6 not available on this interface + if (((ptr->IfIndex != 0)&&(ptr->IfIndex == index)) || + ((ptr->Ipv6IfIndex !=0) && (ptr->Ipv6IfIndex == index))) { ret = (IP_ADAPTER_ADDRESSES *) malloc(sizeof(IP_ADAPTER_ADDRESSES)); if (ret == NULL) { free(adapterInfo); @@ -172,6 +175,7 @@ IP_ADAPTER_ADDRESSES *getAdapter (JNIEnv *env, jint index) { //copy the memory and break out of the while loop. memcpy(ret, ptr, sizeof(IP_ADAPTER_ADDRESSES)); break; + } ptr=ptr->Next; } @@ -192,7 +196,6 @@ int getAllInterfacesAndAddresses (JNIEnv *env, netif **netifPP) int tun=0, net=0; *netifPP = NULL; - /* * Get the IPv4 interfaces. This information is the same * as what previous JDK versions would return. @@ -264,7 +267,7 @@ int getAllInterfacesAndAddresses (JNIEnv *env, netif **netifPP) * set the index to the IPv6 index and add the * IPv6 addresses */ - nif->index = ptr->Ipv6IfIndex; + nif->ipv6Index = ptr->Ipv6IfIndex; c = getAddrsFromAdapter(ptr, &nif->addrs); nif->naddrs += c; break; @@ -309,6 +312,9 @@ int getAllInterfacesAndAddresses (JNIEnv *env, netif **netifPP) strcpy (nif->name, newname); wcscpy ((PWCHAR)nif->displayName, ptr->FriendlyName); nif->dNameIsUnicode = TRUE; + + // the java.net.NetworkInterface abstraction only has index + // so the Ipv6IfIndex needs to map onto index nif->index = ptr->Ipv6IfIndex; nif->ipv6Index = ptr->Ipv6IfIndex; nif->hasIpv6Address = TRUE; @@ -487,7 +493,6 @@ static jobject createNetworkInterfaceXP(JNIEnv *env, netif *ifs) (*env)->SetObjectField(env, netifObj, ni_nameID, name); (*env)->SetObjectField(env, netifObj, ni_displayNameID, displayName); (*env)->SetIntField(env, netifObj, ni_indexID, ifs->index); - /* * Get the IP addresses for this interface if necessary * Note that 0 is a valid number of addresses. diff --git a/jdk/test/java/net/NetworkInterface/UniqueMacAddressesTest.java b/jdk/test/java/net/NetworkInterface/UniqueMacAddressesTest.java new file mode 100644 index 00000000000..c2f5c495c73 --- /dev/null +++ b/jdk/test/java/net/NetworkInterface/UniqueMacAddressesTest.java @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2013, 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.net.InetAddress; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Enumeration; +import java.util.List; + + +/* + * @test + * @bug 8021372 + * @summary Tests that the MAC addresses returned by NetworkInterface.getNetworkInterfaces are unique for each adapter. + * + */ +public class UniqueMacAddressesTest { + + public static void main(String[] args) throws Exception { + new UniqueMacAddressesTest().execute(); + System.out.println("UniqueMacAddressesTest: OK"); + } + + public UniqueMacAddressesTest() { + System.out.println("UniqueMacAddressesTest: start "); + } + + public void execute() throws Exception { + Enumeration networkInterfaces; + boolean areMacAddressesUnique = false; + List networkInterfaceList = new ArrayList(); + networkInterfaces = NetworkInterface.getNetworkInterfaces(); + + // build a list of NetworkInterface objects to test MAC address + // uniqueness + createNetworkInterfaceList(networkInterfaces, networkInterfaceList); + areMacAddressesUnique = checkMacAddressesAreUnique(networkInterfaceList); + if (!areMacAddressesUnique) { + throw new RuntimeException("mac address uniqueness test failed"); + } + } + + private boolean checkMacAddressesAreUnique ( + List networkInterfaces) throws Exception { + boolean uniqueMacAddresses = true; + for (NetworkInterface networkInterface : networkInterfaces) { + for (NetworkInterface comparisonNetIf : networkInterfaces) { + System.out.println("Comparing netif " + + networkInterface.getName() + " and netif " + + comparisonNetIf.getName()); + if (testMacAddressesEqual(networkInterface, comparisonNetIf)) { + uniqueMacAddresses = false; + break; + } + } + if (uniqueMacAddresses != true) + break; + } + return uniqueMacAddresses; + } + + private boolean testMacAddressesEqual(NetworkInterface netIf1, + NetworkInterface netIf2) throws Exception { + + byte[] rawMacAddress1 = null; + byte[] rawMacAddress2 = null; + boolean macAddressesEqual = false; + if (!netIf1.getName().equals(netIf2.getName())) { + System.out.println("compare hardware addresses " + + createMacAddressString(netIf1) + " and " + createMacAddressString(netIf2)); + rawMacAddress1 = netIf1.getHardwareAddress(); + rawMacAddress2 = netIf2.getHardwareAddress(); + macAddressesEqual = Arrays.equals(rawMacAddress1, rawMacAddress2); + } else { + // same interface + macAddressesEqual = false; + } + return macAddressesEqual; + } + + private String createMacAddressString (NetworkInterface netIf) throws Exception { + byte[] macAddr = netIf.getHardwareAddress(); + StringBuilder sb = new StringBuilder(); + if (macAddr != null) { + for (int i = 0; i < macAddr.length; i++) { + sb.append(String.format("%02X%s", macAddr[i], + (i < macAddr.length - 1) ? "-" : "")); + } + } + return sb.toString(); + } + + private void createNetworkInterfaceList(Enumeration nis, + List networkInterfaceList) throws Exception { + byte[] macAddr = null; + NetworkInterface netIf = null; + while (nis.hasMoreElements()) { + netIf = (NetworkInterface) nis.nextElement(); + macAddr = netIf.getHardwareAddress(); + if (macAddr != null) { + System.out + .println("Adding NetworkInterface " + netIf.getName()); + networkInterfaceList.add(netIf); + } + } + } +} From aefe8c12c047da8a4753780397be14ff5d390975 Mon Sep 17 00:00:00 2001 From: Jason Uh Date: Mon, 9 Sep 2013 10:52:56 -0700 Subject: [PATCH 050/210] 8024432: Fix doclint issues in java.security Reviewed-by: darcy, mullan --- .../java/security/AccessController.java | 24 +++++++++++++++++++ .../java/security/AlgorithmParameters.java | 1 + .../java/security/AlgorithmParametersSpi.java | 2 ++ .../classes/java/security/KeyFactory.java | 2 ++ .../classes/java/security/KeyFactorySpi.java | 2 ++ .../share/classes/java/security/KeyStore.java | 1 + .../classes/java/security/Principal.java | 3 ++- .../security/cert/CertPathBuilderSpi.java | 2 ++ .../security/cert/CertPathValidatorSpi.java | 2 ++ .../security/cert/PKIXRevocationChecker.java | 3 +++ .../RSAMultiPrimePrivateCrtKey.java | 7 +++++- .../security/interfaces/RSAPrivateCrtKey.java | 7 +++++- .../security/interfaces/RSAPrivateKey.java | 7 +++++- .../security/interfaces/RSAPublicKey.java | 7 +++++- 14 files changed, 65 insertions(+), 5 deletions(-) diff --git a/jdk/src/share/classes/java/security/AccessController.java b/jdk/src/share/classes/java/security/AccessController.java index ed103a9186d..a7d089958fe 100644 --- a/jdk/src/share/classes/java/security/AccessController.java +++ b/jdk/src/share/classes/java/security/AccessController.java @@ -279,6 +279,9 @@ public final class AccessController { *

    Note that any DomainCombiner associated with the current * AccessControlContext will be ignored while the action is performed. * + * @param the type of the value returned by the PrivilegedAction's + * {@code run} method. + * * @param action the action to be performed. * * @return the value returned by the action's {@code run} method. @@ -305,6 +308,9 @@ public final class AccessController { *

    This method preserves the current AccessControlContext's * DomainCombiner (which may be null) while the action is performed. * + * @param the type of the value returned by the PrivilegedAction's + * {@code run} method. + * * @param action the action to be performed. * * @return the value returned by the action's {@code run} method. @@ -344,6 +350,8 @@ public final class AccessController { * {@link java.security.SecurityPermission}, then the action is performed * with no permissions. * + * @param the type of the value returned by the PrivilegedAction's + * {@code run} method. * @param action the action to be performed. * @param context an access control context * representing the restriction to be applied to the @@ -377,6 +385,8 @@ public final class AccessController { * If the action's {@code run} method throws an (unchecked) exception, * it will propagate through this method. * + * @param the type of the value returned by the PrivilegedAction's + * {@code run} method. * @param action the action to be performed. * @param context an access control context * representing the restriction to be applied to the @@ -429,6 +439,8 @@ public final class AccessController { *

    This method preserves the current AccessControlContext's * DomainCombiner (which may be null) while the action is performed. * + * @param the type of the value returned by the PrivilegedAction's + * {@code run} method. * @param action the action to be performed. * @param context an access control context * representing the restriction to be applied to the @@ -479,6 +491,9 @@ public final class AccessController { *

    Note that any DomainCombiner associated with the current * AccessControlContext will be ignored while the action is performed. * + * @param the type of the value returned by the + * PrivilegedExceptionAction's {@code run} method. + * * @param action the action to be performed * * @return the value returned by the action's {@code run} method @@ -509,6 +524,9 @@ public final class AccessController { *

    This method preserves the current AccessControlContext's * DomainCombiner (which may be null) while the action is performed. * + * @param the type of the value returned by the + * PrivilegedExceptionAction's {@code run} method. + * * @param action the action to be performed. * * @return the value returned by the action's {@code run} method @@ -585,6 +603,8 @@ public final class AccessController { * {@link java.security.SecurityPermission}, then the action is performed * with no permissions. * + * @param the type of the value returned by the + * PrivilegedExceptionAction's {@code run} method. * @param action the action to be performed * @param context an access control context * representing the restriction to be applied to the @@ -622,6 +642,8 @@ public final class AccessController { * If the action's {@code run} method throws an (unchecked) exception, * it will propagate through this method. * + * @param the type of the value returned by the + * PrivilegedExceptionAction's {@code run} method. * @param action the action to be performed. * @param context an access control context * representing the restriction to be applied to the @@ -676,6 +698,8 @@ public final class AccessController { *

    This method preserves the current AccessControlContext's * DomainCombiner (which may be null) while the action is performed. * + * @param the type of the value returned by the + * PrivilegedExceptionAction's {@code run} method. * @param action the action to be performed. * @param context an access control context * representing the restriction to be applied to the diff --git a/jdk/src/share/classes/java/security/AlgorithmParameters.java b/jdk/src/share/classes/java/security/AlgorithmParameters.java index c603a196c9f..b548fcb64c8 100644 --- a/jdk/src/share/classes/java/security/AlgorithmParameters.java +++ b/jdk/src/share/classes/java/security/AlgorithmParameters.java @@ -324,6 +324,7 @@ public class AlgorithmParameters { * parameters should be returned in an instance of the * {@code DSAParameterSpec} class. * + * @param the type of the parameter specification to be returrned * @param paramSpec the specification class in which * the parameters should be returned. * diff --git a/jdk/src/share/classes/java/security/AlgorithmParametersSpi.java b/jdk/src/share/classes/java/security/AlgorithmParametersSpi.java index be231a4cafe..282493b97b9 100644 --- a/jdk/src/share/classes/java/security/AlgorithmParametersSpi.java +++ b/jdk/src/share/classes/java/security/AlgorithmParametersSpi.java @@ -102,6 +102,8 @@ public abstract class AlgorithmParametersSpi { * parameters should be returned in an instance of the * {@code DSAParameterSpec} class. * + * @param the type of the parameter specification to be returned + * * @param paramSpec the specification class in which * the parameters should be returned. * diff --git a/jdk/src/share/classes/java/security/KeyFactory.java b/jdk/src/share/classes/java/security/KeyFactory.java index 0eb6b754107..8e761ff41f7 100644 --- a/jdk/src/share/classes/java/security/KeyFactory.java +++ b/jdk/src/share/classes/java/security/KeyFactory.java @@ -395,6 +395,8 @@ public class KeyFactory { * key material should be returned in an instance of the * {@code DSAPublicKeySpec} class. * + * @param the type of the key specification to be returned + * * @param key the key. * * @param keySpec the specification class in which diff --git a/jdk/src/share/classes/java/security/KeyFactorySpi.java b/jdk/src/share/classes/java/security/KeyFactorySpi.java index 877c3a11be1..5ee7f458931 100644 --- a/jdk/src/share/classes/java/security/KeyFactorySpi.java +++ b/jdk/src/share/classes/java/security/KeyFactorySpi.java @@ -106,6 +106,8 @@ public abstract class KeyFactorySpi { * key material should be returned in an instance of the * {@code DSAPublicKeySpec} class. * + * @param the type of the key specification to be returned + * * @param key the key. * * @param keySpec the specification class in which diff --git a/jdk/src/share/classes/java/security/KeyStore.java b/jdk/src/share/classes/java/security/KeyStore.java index c363d0719f7..187683baa50 100644 --- a/jdk/src/share/classes/java/security/KeyStore.java +++ b/jdk/src/share/classes/java/security/KeyStore.java @@ -1753,6 +1753,7 @@ public class KeyStore { /** * Returns the KeyStore described by this object. * + * @return the {@code KeyStore} described by this object * @exception KeyStoreException if an error occured during the * operation, for example if the KeyStore could not be * instantiated or loaded diff --git a/jdk/src/share/classes/java/security/Principal.java b/jdk/src/share/classes/java/security/Principal.java index 48938cfdd07..a538e707ee7 100644 --- a/jdk/src/share/classes/java/security/Principal.java +++ b/jdk/src/share/classes/java/security/Principal.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2013, 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 @@ -81,6 +81,7 @@ public interface Principal { *

    Subclasses may override this with a different implementation, if * necessary. * + * @param subject the {@code Subject} * @return true if {@code subject} is non-null and is * implied by this principal, or false otherwise. * @since 1.8 diff --git a/jdk/src/share/classes/java/security/cert/CertPathBuilderSpi.java b/jdk/src/share/classes/java/security/cert/CertPathBuilderSpi.java index 87908c03bd9..e7755411797 100644 --- a/jdk/src/share/classes/java/security/cert/CertPathBuilderSpi.java +++ b/jdk/src/share/classes/java/security/cert/CertPathBuilderSpi.java @@ -87,6 +87,8 @@ public abstract class CertPathBuilderSpi { * service providers, this method cannot be abstract and by default throws * an {@code UnsupportedOperationException}. * + * @return a {@code CertPathChecker} that this implementation uses to + * check the revocation status of certificates * @throws UnsupportedOperationException if this method is not supported * @since 1.8 */ diff --git a/jdk/src/share/classes/java/security/cert/CertPathValidatorSpi.java b/jdk/src/share/classes/java/security/cert/CertPathValidatorSpi.java index 50ad9c85c9b..02d503c9e62 100644 --- a/jdk/src/share/classes/java/security/cert/CertPathValidatorSpi.java +++ b/jdk/src/share/classes/java/security/cert/CertPathValidatorSpi.java @@ -97,6 +97,8 @@ public abstract class CertPathValidatorSpi { * service providers, this method cannot be abstract and by default throws * an {@code UnsupportedOperationException}. * + * @return a {@code CertPathChecker} that this implementation uses to + * check the revocation status of certificates * @throws UnsupportedOperationException if this method is not supported * @since 1.8 */ diff --git a/jdk/src/share/classes/java/security/cert/PKIXRevocationChecker.java b/jdk/src/share/classes/java/security/cert/PKIXRevocationChecker.java index b667397c8e5..3046a03ed23 100644 --- a/jdk/src/share/classes/java/security/cert/PKIXRevocationChecker.java +++ b/jdk/src/share/classes/java/security/cert/PKIXRevocationChecker.java @@ -103,6 +103,9 @@ public abstract class PKIXRevocationChecker extends PKIXCertPathChecker { private Map ocspResponses = Collections.emptyMap(); private Set

    {@code
    + *     int sum = widgets.stream()
    + *                      .filter(w -> w.getColor() == RED)
    + *                      .mapToInt(w -> w.getWeight())
    + *                      .sum();
    + * }
    + * + * In this example, {@code widgets} is a {@code Collection}. We create + * a stream of {@code Widget} objects via {@link Collection#stream Collection.stream()}, + * filter it to produce a stream containing only the red widgets, and then + * transform it into a stream of {@code int} values representing the weight of + * each red widget. Then this stream is summed to produce a total weight. + * + *

    To perform a computation, stream + * operations are composed into a + * stream pipeline. A stream pipeline consists of a source (which + * might be an array, a collection, a generator function, an IO channel, + * etc), zero or more intermediate operations (which transform a + * stream into another stream, such as {@link Stream#filter(Predicate)}), and a + * terminal operation (which produces a result or side-effect, such + * as {@link IntStream#sum()} or {@link IntStream#forEach(IntConsumer)}). + * Streams are lazy; computation on the source data is only performed when the + * terminal operation is initiated, and source elements are consumed only + * as needed. + * + *

    Collections and streams, while bearing some superficial similarities, + * have different goals. Collections are primarily concerned with the efficient + * management of, and access to, their elements. By contrast, streams do not + * provide a means to directly access or manipulate their elements, and are + * instead concerned with declaratively describing their source and the + * computational operations which will be performed in aggregate on that source. + * However, if the provided stream operations do not offer the desired + * functionality, the {@link #iterator()} and {@link #spliterator()} operations + * can be used to perform a controlled traversal. + * + *

    A stream pipeline, like the "widgets" example above, can be viewed as + * a query on the stream source. Unless the source was explicitly + * designed for concurrent modification (such as a {@link ConcurrentHashMap}), + * unpredictable or erroneous behavior may result from modifying the stream + * source while it is being queried. + * + *

    Most stream operations accept parameters that describe user-specified + * behavior, such as the lambda expression {@code w -> w.getWeight()} passed to + * {@code mapToInt} in the example above. Such parameters are always instances + * of a functional interface such + * as {@link java.util.function.Function}, and are often lambda expressions or + * method references. These parameters can never be null, should not modify the + * stream source, and should be + * effectively stateless + * (their result should not depend on any state that might change during + * execution of the stream pipeline.) + * + *

    A stream should be operated on (invoking an intermediate or terminal stream + * operation) only once. This rules out, for example, "forked" streams, where + * the same source feeds two or more pipelines, or multiple traversals of the + * same stream. A stream implementation may throw {@link IllegalStateException} + * if it detects that the stream is being reused. However, since some stream + * operations may return their receiver rather than a new stream object, it may + * not be possible to detect reuse in all cases. + * + *

    Streams have a {@link #close()} method and implement {@link AutoCloseable}, + * but nearly all stream instances do not actually need to be closed after use. + * Generally, only streams whose source is an IO channel (such as those returned + * by {@link Files#lines(Path, Charset)}) will require closing. Most streams + * are backed by collections, arrays, or generating functions, which require no + * special resource management. (If a stream does require closing, it can be + * declared as a resource in a {@code try}-with-resources statement.) + * + *

    Stream pipelines may execute either sequentially or in + * parallel. This + * execution mode is a property of the stream. Streams are created + * with an initial choice of sequential or parallel execution. (For example, + * {@link Collection#stream() Collection.stream()} creates a sequential stream, + * and {@link Collection#parallelStream() Collection.parallelStream()} creates + * a parallel one.) This choice of execution mode may be modified by the + * {@link #sequential()} or {@link #parallel()} methods, and may be queried with + * the {@link #isParallel()} method. + * + * @param the type of the stream elements + * @param the type of of the stream implementing {@code BaseStream} * @since 1.8 + * @see java.util.stream */ public interface BaseStream> extends AutoCloseable { @@ -58,14 +145,11 @@ public interface BaseStream> Spliterator spliterator(); /** - * Returns whether this stream, when executed, would execute in parallel - * (assuming no further modification of the stream, such as appending - * further intermediate operations or changing its parallelism). Calling - * this method after invoking an intermediate or terminal stream operation - * method may yield unpredictable results. + * Returns whether this stream, if a terminal operation were to be executed, + * would execute in parallel. Calling this method after invoking an + * terminal stream operation method may yield unpredictable results. * * @return {@code true} if this stream would execute in parallel if executed - * without further modification otherwise {@code false} */ boolean isParallel(); @@ -96,7 +180,8 @@ public interface BaseStream> /** * Returns an equivalent stream that is * unordered. May return - * itself if the stream was already unordered. + * itself, either because the stream was already unordered, or because + * the underlying stream state was modified to be unordered. * *

    This is an intermediate * operation. diff --git a/jdk/src/share/classes/java/util/stream/Collector.java b/jdk/src/share/classes/java/util/stream/Collector.java index 49629176032..e409d569808 100644 --- a/jdk/src/share/classes/java/util/stream/Collector.java +++ b/jdk/src/share/classes/java/util/stream/Collector.java @@ -26,6 +26,7 @@ package java.util.stream; import java.util.Collections; import java.util.EnumSet; +import java.util.Objects; import java.util.Set; import java.util.function.BiConsumer; import java.util.function.BinaryOperator; @@ -33,71 +34,74 @@ import java.util.function.Function; import java.util.function.Supplier; /** - * A reduction operation that - * folds input elements into a mutable result container, optionally transforming + * A mutable reduction operation that + * accumulates input elements into a mutable result container, optionally transforming * the accumulated result into a final representation after all input elements - * have been processed. + * have been processed. Reduction operations can be performed either sequentially + * or in parallel. * *

    Examples of mutable reduction operations include: * accumulating elements into a {@code Collection}; concatenating * strings using a {@code StringBuilder}; computing summary information about * elements such as sum, min, max, or average; computing "pivot table" summaries - * such as "maximum valued transaction by seller", etc. Reduction operations - * can be performed either sequentially or in parallel. - * - *

    The following are examples of using the predefined {@code Collector} - * implementations in {@link Collectors} with the {@code Stream} API to perform - * mutable reduction tasks: - *

    {@code
    - *     // Accumulate names into a List
    - *     List list = people.stream().map(Person::getName).collect(Collectors.toList());
    - *
    - *     // Accumulate names into a TreeSet
    - *     Set list = people.stream().map(Person::getName).collect(Collectors.toCollection(TreeSet::new));
    - *
    - *     // Convert elements to strings and concatenate them, separated by commas
    - *     String joined = things.stream()
    - *                           .map(Object::toString)
    - *                           .collect(Collectors.joining(", "));
    - *
    - *     // Find highest-paid employee
    - *     Employee highestPaid = employees.stream()
    - *                                     .collect(Collectors.maxBy(Comparators.comparing(Employee::getSalary)))
    - *                                     .get();
    - *
    - *     // Group employees by department
    - *     Map> byDept
    - *         = employees.stream()
    - *                    .collect(Collectors.groupingBy(Employee::getDepartment));
    - *
    - *     // Find highest-paid employee by department
    - *     Map> highestPaidByDept
    - *         = employees.stream()
    - *                    .collect(Collectors.groupingBy(Employee::getDepartment,
    - *                                                   Collectors.maxBy(Comparators.comparing(Employee::getSalary))));
    - *
    - *     // Partition students into passing and failing
    - *     Map> passingFailing =
    - *         students.stream()
    - *                 .collect(Collectors.partitioningBy(s -> s.getGrade() >= PASS_THRESHOLD));
    - *
    - * }
    + * such as "maximum valued transaction by seller", etc. The class {@link Collectors} + * provides implementations of many common mutable reductions. * *

    A {@code Collector} is specified by four functions that work together to * accumulate entries into a mutable result container, and optionally perform - * a final transform on the result. They are: creation of a new result container, - * incorporating a new data element into a result container, combining two - * result containers into one, and performing a final transform on the container. - * The combiner function is used during parallel operations, where - * subsets of the input are accumulated into separate result - * containers, and then the subresults merged into a combined result. The - * combiner function may merge one set of subresults into the other and return - * that, or it may return a new object to describe the combined results. + * a final transform on the result. They are:

      + *
    • creation of a new result container ({@link #supplier()})
    • + *
    • incorporating a new data element into a result container ({@link #accumulator()})
    • + *
    • combining two result containers into one ({@link #combiner()})
    • + *
    • performing an optional final transform on the container ({@link #finisher()})
    • + *
    * *

    Collectors also have a set of characteristics, such as - * {@link Characteristics#CONCURRENT}. These characteristics provide - * hints that can be used by a reduction implementation to provide better - * performance. + * {@link Characteristics#CONCURRENT}, that provide hints that can be used by a + * reduction implementation to provide better performance. + * + *

    A sequential implementation of a reduction using a collector would + * create a single result container using the supplier function, and invoke the + * accumulator function once for each input element. A parallel implementation + * would partition the input, create a result container for each partition, + * accumulate the contents of each partition into a subresult for that partition, + * and then use the combiner function to merge the subresults into a combined + * result. + * + *

    To ensure that sequential and parallel executions produce equivalent + * results, the collector functions must satisfy an identity and an + * associativity constraints. + * + *

    The identity constraint says that for any partially accumulated result, + * combining it with an empty result container must produce an equivalent + * result. That is, for a partially accumulated result {@code a} that is the + * result of any series of accumulator and combiner invocations, {@code a} must + * be equivalent to {@code combiner.apply(a, supplier.get())}. + * + *

    The associativity constraint says that splitting the computation must + * produce an equivalent result. That is, for any input elements {@code t1} + * and {@code t2}, the results {@code r1} and {@code r2} in the computation + * below must be equivalent: + *

    {@code
    + *     A a1 = supplier.get();
    + *     accumulator.accept(a1, t1);
    + *     accumulator.accept(a1, t2);
    + *     R r1 = finisher.apply(a1);  // result without splitting
    + *
    + *     A a2 = supplier.get();
    + *     accumulator.accept(a2, t1);
    + *     A a3 = supplier.get();
    + *     accumulator.accept(a3, t2);
    + *     R r2 = finisher.apply(combiner.apply(a2, a3));  // result with splitting
    + * } 
    + * + *

    For collectors that do not have the {@code UNORDERED} characteristic, + * two accumulated results {@code a1} and {@code a2} are equivalent if + * {@code finisher.apply(a1).equals(finisher.apply(a2))}. For unordered + * collectors, equivalence is relaxed to allow for non-equality related to + * differences in order. (For example, an unordered collector that accumulated + * elements to a {@code List} would consider two lists equivalent if they + * contained the same elements, ignoring order.) * *

    Libraries that implement reduction based on {@code Collector}, such as * {@link Stream#collect(Collector)}, must adhere to the following constraints: @@ -132,6 +136,20 @@ import java.util.function.Supplier; * originating data is unordered.

  • * * + *

    In addition to the predefined implementations in {@link Collectors}, the + * static factory methods {@link #of(Supplier, BiConsumer, BinaryOperator, Characteristics...)} + * can be used to construct collectors. For example, you could create a collector + * that accumulates widgets into a {@code TreeSet} with: + * + *

    {@code
    + *     Collector> intoSet =
    + *         Collector.of(TreeSet::new, TreeSet::add,
    + *                      (left, right) -> { left.addAll(right); return left; });
    + * }
    + * + * (This behavior is also implemented by the predefined collector + * {@link Collectors#toCollection(Supplier)}). + * * @apiNote * Performing a reduction operation with a {@code Collector} should produce a * result equivalent to: @@ -144,27 +162,35 @@ import java.util.function.Supplier; * *

    However, the library is free to partition the input, perform the reduction * on the partitions, and then use the combiner function to combine the partial - * results to achieve a parallel reduction. Depending on the specific reduction + * results to achieve a parallel reduction. (Depending on the specific reduction * operation, this may perform better or worse, depending on the relative cost - * of the accumulator and combiner functions. + * of the accumulator and combiner functions.) * - *

    An example of an operation that can be easily modeled by {@code Collector} - * is accumulating elements into a {@code TreeSet}. In this case, the {@code - * resultSupplier()} function is {@code () -> new Treeset()}, the - * {@code accumulator} function is - * {@code (set, element) -> set.add(element) }, and the combiner - * function is {@code (left, right) -> { left.addAll(right); return left; }}. - * (This behavior is implemented by - * {@code Collectors.toCollection(TreeSet::new)}). + *

    Collectors are designed to be composed; many of the methods + * in {@link Collectors} are functions that take a collector and produce + * a new collector. For example, given the following collector that computes + * the sum of the salaries of a stream of employees: * - * TODO Associativity and commutativity + *

    {@code
    + *     Collector summingSalaries
    + *         = Collectors.summingInt(Employee::getSalary))
    + * }
    + * + * If we wanted to create a collector to tabulate the sum of salaries by + * department, we could reuse the "sum of salaries" logic using + * {@link Collectors#groupingBy(Function, Collector)}: + * + *
    {@code
    + *     Collector> summingSalariesByDept
    + *         = Collectors.groupingBy(Employee::getDepartment, summingSalaries);
    + * }
    * * @see Stream#collect(Collector) * @see Collectors * * @param the type of input elements to the reduction operation * @param the mutable accumulation type of the reduction operation (often - * hidden as an implementation detail) + * hidden as an implementation detail) * @param the result type of the reduction operation * @since 1.8 */ @@ -177,25 +203,25 @@ public interface Collector { Supplier supplier(); /** - * A function that folds a new value into a mutable result container. + * A function that folds a value into a mutable result container. * - * @return a function which folds a new value into a mutable result container + * @return a function which folds a value into a mutable result container */ BiConsumer accumulator(); /** * A function that accepts two partial results and merges them. The * combiner function may fold state from one argument into the other and - * return that, or may return a new result object. + * return that, or may return a new result container. * - * @return a function which combines two partial results into a cumulative + * @return a function which combines two partial results into a combined * result */ BinaryOperator combiner(); /** * Perform the final transformation from the intermediate accumulation type - * {@code A} to the final result representation {@code R}. + * {@code A} to the final result type {@code R}. * *

    If the characteristic {@code IDENTITY_TRANSFORM} is * set, this function may be presumed to be an identity transform with an @@ -228,12 +254,17 @@ public interface Collector { * @param The type of input elements for the new collector * @param The type of intermediate accumulation result, and final result, * for the new collector + * @throws NullPointerException if any argument is null * @return the new {@code Collector} */ public static Collector of(Supplier supplier, BiConsumer accumulator, BinaryOperator combiner, Characteristics... characteristics) { + Objects.requireNonNull(supplier); + Objects.requireNonNull(accumulator); + Objects.requireNonNull(combiner); + Objects.requireNonNull(characteristics); Set cs = (characteristics.length == 0) ? Collectors.CH_ID : Collections.unmodifiableSet(EnumSet.of(Collector.Characteristics.IDENTITY_FINISH, @@ -254,6 +285,7 @@ public interface Collector { * @param The type of input elements for the new collector * @param The intermediate accumulation type of the new collector * @param The final result type of the new collector + * @throws NullPointerException if any argument is null * @return the new {@code Collector} */ public static Collector of(Supplier supplier, @@ -261,6 +293,11 @@ public interface Collector { BinaryOperator combiner, Function finisher, Characteristics... characteristics) { + Objects.requireNonNull(supplier); + Objects.requireNonNull(accumulator); + Objects.requireNonNull(combiner); + Objects.requireNonNull(finisher); + Objects.requireNonNull(characteristics); Set cs = Collectors.CH_NOID; if (characteristics.length > 0) { cs = EnumSet.noneOf(Characteristics.class); @@ -288,8 +325,9 @@ public interface Collector { CONCURRENT, /** - * Indicates that the result container has no intrinsic order, such as - * a {@link Set}. + * Indicates that the collection operation does not commit to preserving + * the encounter order of input elements. (This might be true if the + * result container has no intrinsic order, such as a {@link Set}.) */ UNORDERED, diff --git a/jdk/src/share/classes/java/util/stream/Collectors.java b/jdk/src/share/classes/java/util/stream/Collectors.java index bdbd8ad0774..00f7c866311 100644 --- a/jdk/src/share/classes/java/util/stream/Collectors.java +++ b/jdk/src/share/classes/java/util/stream/Collectors.java @@ -62,37 +62,35 @@ import java.util.function.ToLongFunction; * operations, such as accumulating elements into collections, summarizing * elements according to various criteria, etc. * - *

    The following are examples of using the predefined {@code Collector} - * implementations in {@link Collectors} with the {@code Stream} API to perform - * mutable reduction tasks: + *

    The following are examples of using the predefined collectors to perform + * common mutable reduction tasks: * *

    {@code
      *     // Accumulate names into a List
      *     List list = people.stream().map(Person::getName).collect(Collectors.toList());
      *
      *     // Accumulate names into a TreeSet
    - *     Set list = people.stream().map(Person::getName).collect(Collectors.toCollection(TreeSet::new));
    + *     Set set = people.stream().map(Person::getName).collect(Collectors.toCollection(TreeSet::new));
      *
      *     // Convert elements to strings and concatenate them, separated by commas
      *     String joined = things.stream()
      *                           .map(Object::toString)
      *                           .collect(Collectors.joining(", "));
      *
    - *     // Find highest-paid employee
    - *     Employee highestPaid = employees.stream()
    - *                                     .collect(Collectors.maxBy(Comparator.comparing(Employee::getSalary)))
    - *                                     .get();
    + *     // Compute sum of salaries of employee
    + *     int total = employees.stream()
    + *                          .collect(Collectors.summingInt(Employee::getSalary)));
      *
      *     // Group employees by department
      *     Map> byDept
      *         = employees.stream()
      *                    .collect(Collectors.groupingBy(Employee::getDepartment));
      *
    - *     // Find highest-paid employee by department
    - *     Map> highestPaidByDept
    + *     // Compute sum of salaries by department
    + *     Map totalByDept
      *         = employees.stream()
      *                    .collect(Collectors.groupingBy(Employee::getDepartment,
    - *                                                   Collectors.maxBy(Comparator.comparing(Employee::getSalary))));
    + *                                                   Collectors.summingInt(Employee::getSalary)));
      *
      *     // Partition students into passing and failing
      *     Map> passingFailing =
    @@ -101,8 +99,6 @@ import java.util.function.ToLongFunction;
      *
      * }
    * - * TODO explanation of parallel collection - * * @since 1.8 */ public final class Collectors { @@ -222,7 +218,8 @@ public final class Collectors { /** * Returns a {@code Collector} that accumulates the input elements into a * new {@code List}. There are no guarantees on the type, mutability, - * serializability, or thread-safety of the {@code List} returned. + * serializability, or thread-safety of the {@code List} returned; if more + * control over the returned {@code List} is required, use {@link #toCollection(Supplier)}. * * @param the type of the input elements * @return a {@code Collector} which collects all the input elements into a @@ -238,7 +235,9 @@ public final class Collectors { /** * Returns a {@code Collector} that accumulates the input elements into a * new {@code Set}. There are no guarantees on the type, mutability, - * serializability, or thread-safety of the {@code Set} returned. + * serializability, or thread-safety of the {@code Set} returned; if more + * control over the returned {@code Set} is required, use + * {@link #toCollection(Supplier)}. * *

    This is an {@link Collector.Characteristics#UNORDERED unordered} * Collector. @@ -903,7 +902,7 @@ public final class Collectors { * where the city names are sorted: *

    {@code
          *     ConcurrentMap> namesByCity
    -     *         = people.stream().collect(groupingByConcurrent(Person::getCity, ConcurrentSkipListMap::new,
    +     *         = people.stream().collect(groupingByConcurrent(Person::getCity,
          *                                                        mapping(Person::getLastName, toSet())));
          * }
    * diff --git a/jdk/src/share/classes/java/util/stream/DoublePipeline.java b/jdk/src/share/classes/java/util/stream/DoublePipeline.java index 75981d5801f..43b3d04bed9 100644 --- a/jdk/src/share/classes/java/util/stream/DoublePipeline.java +++ b/jdk/src/share/classes/java/util/stream/DoublePipeline.java @@ -313,8 +313,8 @@ abstract class DoublePipeline } @Override - public final DoubleStream peek(DoubleConsumer consumer) { - Objects.requireNonNull(consumer); + public final DoubleStream peek(DoubleConsumer action) { + Objects.requireNonNull(action); return new StatelessOp(this, StreamShape.DOUBLE_VALUE, 0) { @Override @@ -322,7 +322,7 @@ abstract class DoublePipeline return new Sink.ChainedDouble(sink) { @Override public void accept(double t) { - consumer.accept(t); + action.accept(t); downstream.accept(t); } }; @@ -436,14 +436,14 @@ abstract class DoublePipeline } @Override - public final R collect(Supplier resultFactory, + public final R collect(Supplier supplier, ObjDoubleConsumer accumulator, BiConsumer combiner) { BinaryOperator operator = (left, right) -> { combiner.accept(left, right); return left; }; - return evaluate(ReduceOps.makeDouble(resultFactory, accumulator, operator)); + return evaluate(ReduceOps.makeDouble(supplier, accumulator, operator)); } @Override diff --git a/jdk/src/share/classes/java/util/stream/DoubleStream.java b/jdk/src/share/classes/java/util/stream/DoubleStream.java index bf356926154..f10092ac7a5 100644 --- a/jdk/src/share/classes/java/util/stream/DoubleStream.java +++ b/jdk/src/share/classes/java/util/stream/DoubleStream.java @@ -24,13 +24,18 @@ */ package java.util.stream; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.Arrays; +import java.util.Collection; import java.util.DoubleSummaryStatistics; import java.util.Objects; import java.util.OptionalDouble; import java.util.PrimitiveIterator; import java.util.Spliterator; import java.util.Spliterators; +import java.util.concurrent.ConcurrentHashMap; import java.util.function.BiConsumer; import java.util.function.DoubleBinaryOperator; import java.util.function.DoubleConsumer; @@ -45,40 +50,87 @@ import java.util.function.ObjDoubleConsumer; import java.util.function.Supplier; /** - * A sequence of primitive double elements supporting sequential and parallel - * bulk operations. Streams support lazy intermediate operations (transforming - * a stream to another stream) such as {@code filter} and {@code map}, and terminal - * operations (consuming the contents of a stream to produce a result or - * side-effect), such as {@code forEach}, {@code findFirst}, and {@code - * iterator}. Once an operation has been performed on a stream, it - * is considered consumed and no longer usable for other operations. + * A sequence of elements supporting sequential and parallel aggregate + * operations. The following example illustrates an aggregate operation using + * {@link Stream} and {@link DoubleStream}: * - *

    For sequential stream pipelines, all operations are performed in the - * encounter order of the pipeline - * source, if the pipeline source has a defined encounter order. + *

    {@code
    + *     double sum = widgets.stream()
    + *                         .filter(w -> w.getColor() == RED)
    + *                         .mapToDouble(w -> w.getWeight())
    + *                         .sum();
    + * }
    * - *

    For parallel stream pipelines, unless otherwise specified, intermediate - * stream operations preserve the - * encounter order of their source, and terminal operations - * respect the encounter order of their source, if the source - * has an encounter order. Provided that and parameters to stream operations - * satisfy the non-interference - * requirements, and excepting differences arising from the absence of - * a defined encounter order, the result of a stream pipeline should be the - * stable across multiple executions of the same operations on the same source. - * However, the timing and thread in which side-effects occur (for those - * operations which are allowed to produce side-effects, such as - * {@link #forEach(DoubleConsumer)}), are explicitly nondeterministic for parallel - * execution of stream pipelines. + * In this example, {@code widgets} is a {@code Collection}. We create + * a stream of {@code Widget} objects via {@link Collection#stream Collection.stream()}, + * filter it to produce a stream containing only the red widgets, and then + * transform it into a stream of {@code double} values representing the weight of + * each red widget. Then this stream is summed to produce a total weight. * - *

    Unless otherwise noted, passing a {@code null} argument to any stream - * method may result in a {@link NullPointerException}. + *

    To perform a computation, stream + * operations are composed into a + * stream pipeline. A stream pipeline consists of a source (which + * might be an array, a collection, a generator function, an IO channel, + * etc), zero or more intermediate operations (which transform a + * stream into another stream, such as {@link DoubleStream#filter(DoublePredicate)}), and a + * terminal operation (which produces a result or side-effect, such + * as {@link DoubleStream#sum()} or {@link DoubleStream#forEach(DoubleConsumer)}. + * Streams are lazy; computation on the source data is only performed when the + * terminal operation is initiated, and source elements are consumed only + * as needed. * - * @apiNote - * Streams are not data structures; they do not manage the storage for their - * elements, nor do they support access to individual elements. However, - * you can use the {@link #iterator()} or {@link #spliterator()} operations to - * perform a controlled traversal. + *

    Collections and streams, while bearing some superficial similarities, + * have different goals. Collections are primarily concerned with the efficient + * management of, and access to, their elements. By contrast, streams do not + * provide a means to directly access or manipulate their elements, and are + * instead concerned with declaratively describing their source and the + * computational operations which will be performed in aggregate on that source. + * However, if the provided stream operations do not offer the desired + * functionality, the {@link #iterator()} and {@link #spliterator()} operations + * can be used to perform a controlled traversal. + * + *

    A stream pipeline, like the "widgets" example above, can be viewed as + * a query on the stream source. Unless the source was explicitly + * designed for concurrent modification (such as a {@link ConcurrentHashMap}), + * unpredictable or erroneous behavior may result from modifying the stream + * source while it is being queried. + * + *

    Most stream operations accept parameters that describe user-specified + * behavior, such as the lambda expression {@code w -> w.getWeight()} passed to + * {@code mapToDouble} in the example above. Such parameters are always instances + * of a functional interface such + * as {@link java.util.function.Function}, and are often lambda expressions or + * method references. These parameters can never be null, should not modify the + * stream source, and should be + * effectively stateless + * (their result should not depend on any state that might change during + * execution of the stream pipeline.) + * + *

    A stream should be operated on (invoking an intermediate or terminal stream + * operation) only once. This rules out, for example, "forked" streams, where + * the same source feeds two or more pipelines, or multiple traversals of the + * same stream. A stream implementation may throw {@link IllegalStateException} + * if it detects that the stream is being reused. However, since some stream + * operations may return their receiver rather than a new stream object, it may + * not be possible to detect reuse in all cases. + * + *

    Streams have a {@link #close()} method and implement {@link AutoCloseable}, + * but nearly all stream instances do not actually need to be closed after use. + * Generally, only streams whose source is an IO channel (such as those returned + * by {@link Files#lines(Path, Charset)}) will require closing. Most streams + * are backed by collections, arrays, or generating functions, which require no + * special resource management. (If a stream does require closing, it can be + * declared as a resource in a {@code try}-with-resources statement.) + * + *

    Stream pipelines may execute either sequentially or in + * parallel. This + * execution mode is a property of the stream. Streams are created + * with an initial choice of sequential or parallel execution. (For example, + * {@link Collection#stream() Collection.stream()} creates a sequential stream, + * and {@link Collection#parallelStream() Collection.parallelStream()} creates + * a parallel one.) This choice of execution mode may be modified by the + * {@link #sequential()} or {@link #parallel()} methods, and may be queried with + * the {@link #isParallel()} method. * * @since 1.8 * @see java.util.stream @@ -159,22 +211,13 @@ public interface DoubleStream extends BaseStream { /** * Returns a stream consisting of the results of replacing each element of * this stream with the contents of the stream produced by applying the - * provided mapping function to each element. + * provided mapping function to each element. (If the result of the mapping + * function is {@code null}, this is treated as if the result was an empty + * stream.) * *

    This is an intermediate * operation. * - * @apiNote - * The {@code flatMap()} operation has the effect of applying a one-to-many - * tranformation to the elements of the stream, and then flattening the - * resulting elements into a new stream. For example, if {@code orders} - * is a stream of purchase orders, and each purchase order contains a - * collection of line items, then the following produces a stream of line - * items: - *

    {@code
    -     *     orderStream.flatMap(order -> order.getLineItems().stream())...
    -     * }
    - * * @param mapper a * non-interfering, stateless function to apply to * each element which produces an {@code DoubleStream} of new @@ -226,18 +269,18 @@ public interface DoubleStream extends BaseStream { *
    {@code
          *     list.stream()
          *         .filter(filteringFunction)
    -     *         .peek(e -> {System.out.println("Filtered value: " + e); });
    +     *         .peek(e -> System.out.println("Filtered value: " + e));
          *         .map(mappingFunction)
    -     *         .peek(e -> {System.out.println("Mapped value: " + e); });
    +     *         .peek(e -> System.out.println("Mapped value: " + e));
          *         .collect(Collectors.toDoubleSummaryStastistics());
          * }
    * - * @param consumer a + * @param action a * non-interfering action to perform on the elements as * they are consumed from the stream * @return the new stream */ - DoubleStream peek(DoubleConsumer consumer); + DoubleStream peek(DoubleConsumer action); /** * Returns a stream consisting of the elements of this stream, truncated @@ -254,8 +297,8 @@ public interface DoubleStream extends BaseStream { /** * Returns a stream consisting of the remaining elements of this stream - * after indexing {@code startInclusive} elements into the stream. If the - * {@code startInclusive} index lies past the end of this stream then an + * after discarding the first {@code startInclusive} elements of the stream. + * If this stream contains fewer than {@code startInclusive} elements then an * empty stream will be returned. * *

    This is a stateful @@ -269,10 +312,10 @@ public interface DoubleStream extends BaseStream { /** * Returns a stream consisting of the remaining elements of this stream - * after indexing {@code startInclusive} elements into the stream and - * truncated to contain no more than {@code endExclusive - startInclusive} - * elements. If the {@code startInclusive} index lies past the end - * of this stream then an empty stream will be returned. + * after discarding the first {@code startInclusive} elements and truncating + * the result to be no longer than {@code endExclusive - startInclusive} + * elements in length. If this stream contains fewer than + * {@code startInclusive} elements then an empty stream will be returned. * *

    This is a short-circuiting * stateful intermediate operation. @@ -421,12 +464,12 @@ public interface DoubleStream extends BaseStream { /** * Performs a mutable * reduction operation on the elements of this stream. A mutable - * reduction is one in which the reduced value is a mutable value holder, + * reduction is one in which the reduced value is a mutable result container, * such as an {@code ArrayList}, and elements are incorporated by updating - * the state of the result, rather than by replacing the result. This + * the state of the result rather than by replacing the result. This * produces a result equivalent to: *

    {@code
    -     *     R result = resultFactory.get();
    +     *     R result = supplier.get();
          *     for (double element : this stream)
          *         accumulator.accept(result, element);
          *     return result;
    @@ -440,10 +483,9 @@ public interface DoubleStream extends BaseStream {
          * operation.
          *
          * @param  type of the result
    -     * @param resultFactory a function that creates a new result container.
    -     *                      For a parallel execution, this function may be
    -     *                      called multiple times and must return a fresh value
    -     *                      each time.
    +     * @param supplier a function that creates a new result container. For a
    +     *                 parallel execution, this function may be called
    +     *                 multiple times and must return a fresh value each time.
          * @param accumulator an associative
          *                    non-interfering,
          *                    stateless function for incorporating an additional
    @@ -455,7 +497,7 @@ public interface DoubleStream extends BaseStream {
          * @return the result of the reduction
          * @see Stream#collect(Supplier, BiConsumer, BiConsumer)
          */
    -     R collect(Supplier resultFactory,
    +     R collect(Supplier supplier,
                       ObjDoubleConsumer accumulator,
                       BiConsumer combiner);
     
    @@ -467,12 +509,15 @@ public interface DoubleStream extends BaseStream {
          * yield more accurate results.  If any stream element is a {@code NaN} or
          * the sum is at any point a {@code NaN} then the sum will be {@code NaN}.
          * This is a special case of a
    -     * reduction and is
    +     * reduction and is
          * equivalent to:
          * 
    {@code
          *     return reduce(0, Double::sum);
          * }
    * + *

    This is a terminal + * operation. + * * @return the sum of elements in this stream */ double sum(); @@ -483,12 +528,15 @@ public interface DoubleStream extends BaseStream { * element will be {@code Double.NaN} if any stream element was NaN. Unlike * the numerical comparison operators, this method considers negative zero * to be strictly smaller than positive zero. This is a special case of a - * reduction and is + * reduction and is * equivalent to: *

    {@code
          *     return reduce(Double::min);
          * }
    * + *

    This is a terminal + * operation. + * * @return an {@code OptionalDouble} containing the minimum element of this * stream, or an empty optional if the stream is empty */ @@ -501,12 +549,15 @@ public interface DoubleStream extends BaseStream { * the numerical comparison operators, this method considers negative zero * to be strictly smaller than positive zero. This is a * special case of a - * reduction and is + * reduction and is * equivalent to: *

    {@code
          *     return reduce(Double::max);
          * }
    * + *

    This is a terminal + * operation. + * * @return an {@code OptionalDouble} containing the maximum element of this * stream, or an empty optional if the stream is empty */ @@ -514,7 +565,7 @@ public interface DoubleStream extends BaseStream { /** * Returns the count of elements in this stream. This is a special case of - * a reduction and is + * a reduction and is * equivalent to: *

    {@code
          *     return mapToLong(e -> 1L).sum();
    @@ -535,7 +586,10 @@ public interface DoubleStream extends BaseStream {
          * magnitude tend to yield more accurate results. If any recorded value is
          * a {@code NaN} or the sum is at any point a {@code NaN} then the average
          * will be {@code NaN}. This is a special case of a
    -     * reduction.
    +     * reduction.
    +     *
    +     * 

    This is a terminal + * operation. * * @return an {@code OptionalDouble} containing the average element of this * stream, or an empty optional if the stream is empty @@ -545,7 +599,10 @@ public interface DoubleStream extends BaseStream { /** * Returns a {@code DoubleSummaryStatistics} describing various summary data * about the elements of this stream. This is a special - * case of a reduction. + * case of a reduction. + * + *

    This is a terminal + * operation. * * @return a {@code DoubleSummaryStatistics} describing various summary data * about the elements of this stream @@ -602,9 +659,8 @@ public interface DoubleStream extends BaseStream { /** * Returns an {@link OptionalDouble} describing the first element of this - * stream (in the encounter order), or an empty {@code OptionalDouble} if - * the stream is empty. If the stream has no encounter order, then any - * element may be returned. + * stream, or an empty {@code OptionalDouble} if the stream is empty. If + * the stream has no encounter order, then any element may be returned. * *

    This is a short-circuiting * terminal operation. @@ -624,8 +680,8 @@ public interface DoubleStream extends BaseStream { *

    The behavior of this operation is explicitly nondeterministic; it is * free to select any element in the stream. This is to allow for maximal * performance in parallel operations; the cost is that multiple invocations - * on the same source may not return the same result. (If the first element - * in the encounter order is desired, use {@link #findFirst()} instead.) + * on the same source may not return the same result. (If a stable result + * is desired, use {@link #findFirst()} instead.) * * @return an {@code OptionalDouble} describing some element of this stream, * or an empty {@code OptionalDouble} if the stream is empty @@ -637,6 +693,9 @@ public interface DoubleStream extends BaseStream { * Returns a {@code Stream} consisting of the elements of this stream, * boxed to {@code Double}. * + *

    This is an intermediate + * operation. + * * @return a {@code Stream} consistent of the elements of this stream, * each boxed to a {@code Double} */ @@ -686,7 +745,7 @@ public interface DoubleStream extends BaseStream { } /** - * Returns a sequential stream whose elements are the specified values. + * Returns a sequential ordered stream whose elements are the specified values. * * @param values the elements of the new stream * @return the new stream @@ -696,7 +755,7 @@ public interface DoubleStream extends BaseStream { } /** - * Returns an infinite sequential {@code DoubleStream} produced by iterative + * Returns an infinite sequential ordered {@code DoubleStream} produced by iterative * application of a function {@code f} to an initial element {@code seed}, * producing a {@code Stream} consisting of {@code seed}, {@code f(seed)}, * {@code f(f(seed))}, etc. @@ -734,8 +793,8 @@ public interface DoubleStream extends BaseStream { } /** - * Returns a sequential {@code DoubleStream} where each element is - * generated by an {@code DoubleSupplier}. This is suitable for generating + * Returns a sequential stream where each element is generated by + * the provided {@code DoubleSupplier}. This is suitable for generating * constant streams, streams of random elements, etc. * * @param s the {@code DoubleSupplier} for generated elements @@ -748,16 +807,16 @@ public interface DoubleStream extends BaseStream { } /** - * Creates a lazy concatenated {@code DoubleStream} whose elements are all the - * elements of a first {@code DoubleStream} succeeded by all the elements of the - * second {@code DoubleStream}. The resulting stream is ordered if both + * Creates a lazily concatenated stream whose elements are all the + * elements of the first stream followed by all the elements of the + * second stream. The resulting stream is ordered if both * of the input streams are ordered, and parallel if either of the input * streams is parallel. When the resulting stream is closed, the close * handlers for both input streams are invoked. * * @param a the first stream - * @param b the second stream to concatenate on to end of the first stream - * @return the concatenation of the two streams + * @param b the second stream + * @return the concatenation of the two input streams */ public static DoubleStream concat(DoubleStream a, DoubleStream b) { Objects.requireNonNull(a); @@ -772,9 +831,9 @@ public interface DoubleStream extends BaseStream { /** * A mutable builder for a {@code DoubleStream}. * - *

    A stream builder has a lifecycle, where it starts in a building - * phase, during which elements can be added, and then transitions to a - * built phase, after which elements may not be added. The built phase + *

    A stream builder has a lifecycle, which starts in a building + * phase, during which elements can be added, and then transitions to a built + * phase, after which elements may not be added. The built phase * begins when the {@link #build()} method is called, which creates an * ordered stream whose elements are the elements that were added to the * stream builder, in the order they were added. diff --git a/jdk/src/share/classes/java/util/stream/IntPipeline.java b/jdk/src/share/classes/java/util/stream/IntPipeline.java index f35bc1d7a8e..13f7e0a9731 100644 --- a/jdk/src/share/classes/java/util/stream/IntPipeline.java +++ b/jdk/src/share/classes/java/util/stream/IntPipeline.java @@ -349,8 +349,8 @@ abstract class IntPipeline } @Override - public final IntStream peek(IntConsumer consumer) { - Objects.requireNonNull(consumer); + public final IntStream peek(IntConsumer action) { + Objects.requireNonNull(action); return new StatelessOp(this, StreamShape.INT_VALUE, 0) { @Override @@ -358,7 +358,7 @@ abstract class IntPipeline return new Sink.ChainedInt(sink) { @Override public void accept(int t) { - consumer.accept(t); + action.accept(t); downstream.accept(t); } }; @@ -473,14 +473,14 @@ abstract class IntPipeline } @Override - public final R collect(Supplier resultFactory, + public final R collect(Supplier supplier, ObjIntConsumer accumulator, BiConsumer combiner) { BinaryOperator operator = (left, right) -> { combiner.accept(left, right); return left; }; - return evaluate(ReduceOps.makeInt(resultFactory, accumulator, operator)); + return evaluate(ReduceOps.makeInt(supplier, accumulator, operator)); } @Override diff --git a/jdk/src/share/classes/java/util/stream/IntStream.java b/jdk/src/share/classes/java/util/stream/IntStream.java index c107ca46de9..07f9ab5dc78 100644 --- a/jdk/src/share/classes/java/util/stream/IntStream.java +++ b/jdk/src/share/classes/java/util/stream/IntStream.java @@ -24,7 +24,11 @@ */ package java.util.stream; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.Arrays; +import java.util.Collection; import java.util.IntSummaryStatistics; import java.util.Objects; import java.util.OptionalDouble; @@ -32,6 +36,7 @@ import java.util.OptionalInt; import java.util.PrimitiveIterator; import java.util.Spliterator; import java.util.Spliterators; +import java.util.concurrent.ConcurrentHashMap; import java.util.function.BiConsumer; import java.util.function.Function; import java.util.function.IntBinaryOperator; @@ -46,40 +51,87 @@ import java.util.function.ObjIntConsumer; import java.util.function.Supplier; /** - * A sequence of primitive integer elements supporting sequential and parallel - * bulk operations. Streams support lazy intermediate operations (transforming - * a stream to another stream) such as {@code filter} and {@code map}, and terminal - * operations (consuming the contents of a stream to produce a result or - * side-effect), such as {@code forEach}, {@code findFirst}, and {@code - * iterator}. Once an operation has been performed on a stream, it - * is considered consumed and no longer usable for other operations. + * A sequence of elements supporting sequential and parallel aggregate + * operations. The following example illustrates an aggregate operation using + * {@link Stream} and {@link IntStream}: * - *

    For sequential stream pipelines, all operations are performed in the - * encounter order of the pipeline - * source, if the pipeline source has a defined encounter order. + *

    {@code
    + *     int sum = widgets.stream()
    + *                      .filter(w -> w.getColor() == RED)
    + *                      .mapToInt(w -> w.getWeight())
    + *                      .sum();
    + * }
    * - *

    For parallel stream pipelines, unless otherwise specified, intermediate - * stream operations preserve the - * encounter order of their source, and terminal operations - * respect the encounter order of their source, if the source - * has an encounter order. Provided that and parameters to stream operations - * satisfy the non-interference - * requirements, and excepting differences arising from the absence of - * a defined encounter order, the result of a stream pipeline should be the - * stable across multiple executions of the same operations on the same source. - * However, the timing and thread in which side-effects occur (for those - * operations which are allowed to produce side-effects, such as - * {@link #forEach(IntConsumer)}), are explicitly nondeterministic for parallel - * execution of stream pipelines. + * In this example, {@code widgets} is a {@code Collection}. We create + * a stream of {@code Widget} objects via {@link Collection#stream Collection.stream()}, + * filter it to produce a stream containing only the red widgets, and then + * transform it into a stream of {@code int} values representing the weight of + * each red widget. Then this stream is summed to produce a total weight. * - *

    Unless otherwise noted, passing a {@code null} argument to any stream - * method may result in a {@link NullPointerException}. + *

    To perform a computation, stream + * operations are composed into a + * stream pipeline. A stream pipeline consists of a source (which + * might be an array, a collection, a generator function, an IO channel, + * etc), zero or more intermediate operations (which transform a + * stream into another stream, such as {@link IntStream#filter(IntPredicate)}), and a + * terminal operation (which produces a result or side-effect, such + * as {@link IntStream#sum()} or {@link IntStream#forEach(IntConsumer)}). + * Streams are lazy; computation on the source data is only performed when the + * terminal operation is initiated, and source elements are consumed only + * as needed. * - * @apiNote - * Streams are not data structures; they do not manage the storage for their - * elements, nor do they support access to individual elements. However, - * you can use the {@link #iterator()} or {@link #spliterator()} operations to - * perform a controlled traversal. + *

    Collections and streams, while bearing some superficial similarities, + * have different goals. Collections are primarily concerned with the efficient + * management of, and access to, their elements. By contrast, streams do not + * provide a means to directly access or manipulate their elements, and are + * instead concerned with declaratively describing their source and the + * computational operations which will be performed in aggregate on that source. + * However, if the provided stream operations do not offer the desired + * functionality, the {@link #iterator()} and {@link #spliterator()} operations + * can be used to perform a controlled traversal. + * + *

    A stream pipeline, like the "widgets" example above, can be viewed as + * a query on the stream source. Unless the source was explicitly + * designed for concurrent modification (such as a {@link ConcurrentHashMap}), + * unpredictable or erroneous behavior may result from modifying the stream + * source while it is being queried. + * + *

    Most stream operations accept parameters that describe user-specified + * behavior, such as the lambda expression {@code w -> w.getWeight()} passed to + * {@code mapToInt} in the example above. Such parameters are always instances + * of a functional interface such + * as {@link java.util.function.Function}, and are often lambda expressions or + * method references. These parameters can never be null, should not modify the + * stream source, and should be + * effectively stateless + * (their result should not depend on any state that might change during + * execution of the stream pipeline.) + * + *

    A stream should be operated on (invoking an intermediate or terminal stream + * operation) only once. This rules out, for example, "forked" streams, where + * the same source feeds two or more pipelines, or multiple traversals of the + * same stream. A stream implementation may throw {@link IllegalStateException} + * if it detects that the stream is being reused. However, since some stream + * operations may return their receiver rather than a new stream object, it may + * not be possible to detect reuse in all cases. + * + *

    Streams have a {@link #close()} method and implement {@link AutoCloseable}, + * but nearly all stream instances do not actually need to be closed after use. + * Generally, only streams whose source is an IO channel (such as those returned + * by {@link Files#lines(Path, Charset)}) will require closing. Most streams + * are backed by collections, arrays, or generating functions, which require no + * special resource management. (If a stream does require closing, it can be + * declared as a resource in a {@code try}-with-resources statement.) + * + *

    Stream pipelines may execute either sequentially or in + * parallel. This + * execution mode is a property of the stream. Streams are created + * with an initial choice of sequential or parallel execution. (For example, + * {@link Collection#stream() Collection.stream()} creates a sequential stream, + * and {@link Collection#parallelStream() Collection.parallelStream()} creates + * a parallel one.) This choice of execution mode may be modified by the + * {@link #sequential()} or {@link #parallel()} methods, and may be queried with + * the {@link #isParallel()} method. * * @since 1.8 * @see java.util.stream @@ -160,22 +212,13 @@ public interface IntStream extends BaseStream { /** * Returns a stream consisting of the results of replacing each element of * this stream with the contents of the stream produced by applying the - * provided mapping function to each element. + * provided mapping function to each element. (If the result of the mapping + * function is {@code null}, this is treated as if the result was an empty + * stream.) * *

    This is an intermediate * operation. * - * @apiNote - * The {@code flatMap()} operation has the effect of applying a one-to-many - * tranformation to the elements of the stream, and then flattening the - * resulting elements into a new stream. For example, if {@code orders} - * is a stream of purchase orders, and each purchase order contains a - * collection of line items, then the following produces a stream of line - * items: - *

    {@code
    -     *     orderStream.flatMap(order -> order.getLineItems().stream())...
    -     * }
    - * * @param mapper a * non-interfering, stateless function to apply to * each element which produces an {@code IntStream} of new @@ -224,18 +267,18 @@ public interface IntStream extends BaseStream { *
    {@code
          *     list.stream()
          *         .filter(filteringFunction)
    -     *         .peek(e -> {System.out.println("Filtered value: " + e); });
    +     *         .peek(e -> System.out.println("Filtered value: " + e));
          *         .map(mappingFunction)
    -     *         .peek(e -> {System.out.println("Mapped value: " + e); });
    +     *         .peek(e -> System.out.println("Mapped value: " + e));
          *         .collect(Collectors.toIntSummaryStastistics());
          * }
    * - * @param consumer a - * non-interfering action to perform on the elements as - * they are consumed from the stream + * @param action a + * non-interfering action to perform on the elements as + * they are consumed from the stream * @return the new stream */ - IntStream peek(IntConsumer consumer); + IntStream peek(IntConsumer action); /** * Returns a stream consisting of the elements of this stream, truncated @@ -252,8 +295,8 @@ public interface IntStream extends BaseStream { /** * Returns a stream consisting of the remaining elements of this stream - * after indexing {@code startInclusive} elements into the stream. If the - * {@code startInclusive} index lies past the end of this stream then an + * after discarding the first {@code startInclusive} elements of the stream. + * If this stream contains fewer than {@code startInclusive} elements then an * empty stream will be returned. * *

    This is a stateful @@ -267,10 +310,10 @@ public interface IntStream extends BaseStream { /** * Returns a stream consisting of the remaining elements of this stream - * after indexing {@code startInclusive} elements into the stream and - * truncated to contain no more than {@code endExclusive - startInclusive} - * elements. If the {@code startInclusive} index lies past the end - * of this stream then an empty stream will be returned. + * after discarding the first {@code startInclusive} elements and truncating + * the result to be no longer than {@code endExclusive - startInclusive} + * elements in length. If this stream contains fewer than + * {@code startInclusive} elements then an empty stream will be returned. * *

    This is a short-circuiting * stateful intermediate operation. @@ -419,12 +462,12 @@ public interface IntStream extends BaseStream { /** * Performs a mutable * reduction operation on the elements of this stream. A mutable - * reduction is one in which the reduced value is a mutable value holder, + * reduction is one in which the reduced value is a mutable result container, * such as an {@code ArrayList}, and elements are incorporated by updating - * the state of the result, rather than by replacing the result. This + * the state of the result rather than by replacing the result. This * produces a result equivalent to: *

    {@code
    -     *     R result = resultFactory.get();
    +     *     R result = supplier.get();
          *     for (int element : this stream)
          *         accumulator.accept(result, element);
          *     return result;
    @@ -437,10 +480,9 @@ public interface IntStream extends BaseStream {
          * operation.
          *
          * @param  type of the result
    -     * @param resultFactory a function that creates a new result container.
    -     *                      For a parallel execution, this function may be
    -     *                      called multiple times and must return a fresh value
    -     *                      each time.
    +     * @param supplier a function that creates a new result container. For a
    +     *                 parallel execution, this function may be called
    +     *                 multiple times and must return a fresh value each time.
          * @param accumulator an associative
          *                    non-interfering,
          *                    stateless function for incorporating an additional
    @@ -452,18 +494,21 @@ public interface IntStream extends BaseStream {
          * @return the result of the reduction
          * @see Stream#collect(Supplier, BiConsumer, BiConsumer)
          */
    -     R collect(Supplier resultFactory,
    +     R collect(Supplier supplier,
                       ObjIntConsumer accumulator,
                       BiConsumer combiner);
     
         /**
          * Returns the sum of elements in this stream.  This is a special case
    -     * of a reduction
    +     * of a reduction
          * and is equivalent to:
          * 
    {@code
          *     return reduce(0, Integer::sum);
          * }
    * + *

    This is a terminal + * operation. + * * @return the sum of elements in this stream */ int sum(); @@ -471,7 +516,7 @@ public interface IntStream extends BaseStream { /** * Returns an {@code OptionalInt} describing the minimum element of this * stream, or an empty optional if this stream is empty. This is a special - * case of a reduction + * case of a reduction * and is equivalent to: *

    {@code
          *     return reduce(Integer::min);
    @@ -479,7 +524,6 @@ public interface IntStream extends BaseStream {
          *
          * 

    This is a terminal operation. * - * @return an {@code OptionalInt} containing the minimum element of this * stream, or an empty {@code OptionalInt} if the stream is empty */ @@ -488,7 +532,7 @@ public interface IntStream extends BaseStream { /** * Returns an {@code OptionalInt} describing the maximum element of this * stream, or an empty optional if this stream is empty. This is a special - * case of a reduction + * case of a reduction * and is equivalent to: *

    {@code
          *     return reduce(Integer::max);
    @@ -504,7 +548,7 @@ public interface IntStream extends BaseStream {
     
         /**
          * Returns the count of elements in this stream.  This is a special case of
    -     * a reduction and is
    +     * a reduction and is
          * equivalent to:
          * 
    {@code
          *     return mapToLong(e -> 1L).sum();
    @@ -520,7 +564,10 @@ public interface IntStream extends BaseStream {
          * Returns an {@code OptionalDouble} describing the arithmetic mean of elements of
          * this stream, or an empty optional if this stream is empty.  This is a
          * special case of a
    -     * reduction.
    +     * reduction.
    +     *
    +     * 

    This is a terminal + * operation. * * @return an {@code OptionalDouble} containing the average element of this * stream, or an empty optional if the stream is empty @@ -530,7 +577,10 @@ public interface IntStream extends BaseStream { /** * Returns an {@code IntSummaryStatistics} describing various * summary data about the elements of this stream. This is a special - * case of a reduction. + * case of a reduction. + * + *

    This is a terminal + * operation. * * @return an {@code IntSummaryStatistics} describing various summary data * about the elements of this stream @@ -587,9 +637,8 @@ public interface IntStream extends BaseStream { /** * Returns an {@link OptionalInt} describing the first element of this - * stream (in the encounter order), or an empty {@code OptionalInt} if the - * stream is empty. If the stream has no encounter order, then any element - * may be returned. + * stream, or an empty {@code OptionalInt} if the stream is empty. If the + * stream has no encounter order, then any element may be returned. * *

    This is a short-circuiting * terminal operation. @@ -609,8 +658,8 @@ public interface IntStream extends BaseStream { *

    The behavior of this operation is explicitly nondeterministic; it is * free to select any element in the stream. This is to allow for maximal * performance in parallel operations; the cost is that multiple invocations - * on the same source may not return the same result. (If the first element - * in the encounter order is desired, use {@link #findFirst()} instead.) + * on the same source may not return the same result. (If a stable result + * is desired, use {@link #findFirst()} instead.) * * @return an {@code OptionalInt} describing some element of this stream, or * an empty {@code OptionalInt} if the stream is empty @@ -622,6 +671,9 @@ public interface IntStream extends BaseStream { * Returns a {@code LongStream} consisting of the elements of this stream, * converted to {@code long}. * + *

    This is an intermediate + * operation. + * * @return a {@code LongStream} consisting of the elements of this stream, * converted to {@code long} */ @@ -631,6 +683,9 @@ public interface IntStream extends BaseStream { * Returns a {@code DoubleStream} consisting of the elements of this stream, * converted to {@code double}. * + *

    This is an intermediate + * operation. + * * @return a {@code DoubleStream} consisting of the elements of this stream, * converted to {@code double} */ @@ -640,6 +695,9 @@ public interface IntStream extends BaseStream { * Returns a {@code Stream} consisting of the elements of this stream, * each boxed to an {@code Integer}. * + *

    This is an intermediate + * operation. + * * @return a {@code Stream} consistent of the elements of this stream, * each boxed to an {@code Integer} */ @@ -688,7 +746,7 @@ public interface IntStream extends BaseStream { } /** - * Returns a sequential stream whose elements are the specified values. + * Returns a sequential ordered stream whose elements are the specified values. * * @param values the elements of the new stream * @return the new stream @@ -698,7 +756,7 @@ public interface IntStream extends BaseStream { } /** - * Returns an infinite sequential {@code IntStream} produced by iterative + * Returns an infinite sequential ordered {@code IntStream} produced by iterative * application of a function {@code f} to an initial element {@code seed}, * producing a {@code Stream} consisting of {@code seed}, {@code f(seed)}, * {@code f(f(seed))}, etc. @@ -736,8 +794,8 @@ public interface IntStream extends BaseStream { } /** - * Returns a sequential {@code IntStream} where each element is - * generated by an {@code IntSupplier}. This is suitable for generating + * Returns a sequential stream where each element is generated by + * the provided {@code IntSupplier}. This is suitable for generating * constant streams, streams of random elements, etc. * * @param s the {@code IntSupplier} for generated elements @@ -750,7 +808,7 @@ public interface IntStream extends BaseStream { } /** - * Returns a sequential {@code IntStream} from {@code startInclusive} + * Returns a sequential ordered {@code IntStream} from {@code startInclusive} * (inclusive) to {@code endExclusive} (exclusive) by an incremental step of * {@code 1}. * @@ -776,7 +834,7 @@ public interface IntStream extends BaseStream { } /** - * Returns a sequential {@code IntStream} from {@code startInclusive} + * Returns a sequential ordered {@code IntStream} from {@code startInclusive} * (inclusive) to {@code endInclusive} (inclusive) by an incremental step of * {@code 1}. * @@ -802,16 +860,16 @@ public interface IntStream extends BaseStream { } /** - * Creates a lazy concatenated {@code IntStream} whose elements are all the - * elements of a first {@code IntStream} succeeded by all the elements of the - * second {@code IntStream}. The resulting stream is ordered if both + * Creates a lazily concatenated stream whose elements are all the + * elements of the first stream followed by all the elements of the + * second stream. The resulting stream is ordered if both * of the input streams are ordered, and parallel if either of the input * streams is parallel. When the resulting stream is closed, the close * handlers for both input streams are invoked. * * @param a the first stream - * @param b the second stream to concatenate on to end of the first stream - * @return the concatenation of the two streams + * @param b the second stream + * @return the concatenation of the two input streams */ public static IntStream concat(IntStream a, IntStream b) { Objects.requireNonNull(a); @@ -826,9 +884,9 @@ public interface IntStream extends BaseStream { /** * A mutable builder for an {@code IntStream}. * - *

    A stream builder has a lifecycle, where it starts in a building - * phase, during which elements can be added, and then transitions to a - * built phase, after which elements may not be added. The built phase + *

    A stream builder has a lifecycle, which starts in a building + * phase, during which elements can be added, and then transitions to a built + * phase, after which elements may not be added. The built phase * begins when the {@link #build()} method is called, which creates an * ordered stream whose elements are the elements that were added to the * stream builder, in the order they were added. diff --git a/jdk/src/share/classes/java/util/stream/LongPipeline.java b/jdk/src/share/classes/java/util/stream/LongPipeline.java index a59ec3f5f00..5ed030e02a1 100644 --- a/jdk/src/share/classes/java/util/stream/LongPipeline.java +++ b/jdk/src/share/classes/java/util/stream/LongPipeline.java @@ -330,8 +330,8 @@ abstract class LongPipeline } @Override - public final LongStream peek(LongConsumer consumer) { - Objects.requireNonNull(consumer); + public final LongStream peek(LongConsumer action) { + Objects.requireNonNull(action); return new StatelessOp(this, StreamShape.LONG_VALUE, 0) { @Override @@ -339,7 +339,7 @@ abstract class LongPipeline return new Sink.ChainedLong(sink) { @Override public void accept(long t) { - consumer.accept(t); + action.accept(t); downstream.accept(t); } }; @@ -455,14 +455,14 @@ abstract class LongPipeline } @Override - public final R collect(Supplier resultFactory, + public final R collect(Supplier supplier, ObjLongConsumer accumulator, BiConsumer combiner) { BinaryOperator operator = (left, right) -> { combiner.accept(left, right); return left; }; - return evaluate(ReduceOps.makeLong(resultFactory, accumulator, operator)); + return evaluate(ReduceOps.makeLong(supplier, accumulator, operator)); } @Override diff --git a/jdk/src/share/classes/java/util/stream/LongStream.java b/jdk/src/share/classes/java/util/stream/LongStream.java index e64c67204dc..ca61d2f200e 100644 --- a/jdk/src/share/classes/java/util/stream/LongStream.java +++ b/jdk/src/share/classes/java/util/stream/LongStream.java @@ -24,7 +24,11 @@ */ package java.util.stream; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.Arrays; +import java.util.Collection; import java.util.LongSummaryStatistics; import java.util.Objects; import java.util.OptionalDouble; @@ -32,6 +36,7 @@ import java.util.OptionalLong; import java.util.PrimitiveIterator; import java.util.Spliterator; import java.util.Spliterators; +import java.util.concurrent.ConcurrentHashMap; import java.util.function.BiConsumer; import java.util.function.Function; import java.util.function.LongBinaryOperator; @@ -46,40 +51,87 @@ import java.util.function.ObjLongConsumer; import java.util.function.Supplier; /** - * A sequence of primitive long elements supporting sequential and parallel - * bulk operations. Streams support lazy intermediate operations (transforming - * a stream to another stream) such as {@code filter} and {@code map}, and terminal - * operations (consuming the contents of a stream to produce a result or - * side-effect), such as {@code forEach}, {@code findFirst}, and {@code - * iterator}. Once an operation has been performed on a stream, it - * is considered consumed and no longer usable for other operations. + * A sequence of elements supporting sequential and parallel aggregate + * operations. The following example illustrates an aggregate operation using + * {@link Stream} and {@link LongStream}: * - *

    For sequential stream pipelines, all operations are performed in the - * encounter order of the pipeline - * source, if the pipeline source has a defined encounter order. + *

    {@code
    + *     long sum = widgets.stream()
    + *                       .filter(w -> w.getColor() == RED)
    + *                       .mapToLong(w -> w.getWeight())
    + *                       .sum();
    + * }
    * - *

    For parallel stream pipelines, unless otherwise specified, intermediate - * stream operations preserve the - * encounter order of their source, and terminal operations - * respect the encounter order of their source, if the source - * has an encounter order. Provided that and parameters to stream operations - * satisfy the non-interference - * requirements, and excepting differences arising from the absence of - * a defined encounter order, the result of a stream pipeline should be the - * stable across multiple executions of the same operations on the same source. - * However, the timing and thread in which side-effects occur (for those - * operations which are allowed to produce side-effects, such as - * {@link #forEach(LongConsumer)}), are explicitly nondeterministic for parallel - * execution of stream pipelines. + * In this example, {@code widgets} is a {@code Collection}. We create + * a stream of {@code Widget} objects via {@link Collection#stream Collection.stream()}, + * filter it to produce a stream containing only the red widgets, and then + * transform it into a stream of {@code long} values representing the weight of + * each red widget. Then this stream is summed to produce a total weight. * - *

    Unless otherwise noted, passing a {@code null} argument to any stream - * method may result in a {@link NullPointerException}. + *

    To perform a computation, stream + * operations are composed into a + * stream pipeline. A stream pipeline consists of a source (which + * might be an array, a collection, a generator function, an IO channel, + * etc), zero or more intermediate operations (which transform a + * stream into another stream, such as {@link LongStream#filter(LongPredicate)}), and a + * terminal operation (which produces a result or side-effect, such + * as {@link LongStream#sum()} or {@link LongStream#forEach(LongConsumer)}). + * Streams are lazy; computation on the source data is only performed when the + * terminal operation is initiated, and source elements are consumed only + * as needed. * - * @apiNote - * Streams are not data structures; they do not manage the storage for their - * elements, nor do they support access to individual elements. However, - * you can use the {@link #iterator()} or {@link #spliterator()} operations to - * perform a controlled traversal. + *

    Collections and streams, while bearing some superficial similarities, + * have different goals. Collections are primarily concerned with the efficient + * management of, and access to, their elements. By contrast, streams do not + * provide a means to directly access or manipulate their elements, and are + * instead concerned with declaratively describing their source and the + * computational operations which will be performed in aggregate on that source. + * However, if the provided stream operations do not offer the desired + * functionality, the {@link #iterator()} and {@link #spliterator()} operations + * can be used to perform a controlled traversal. + * + *

    A stream pipeline, like the "widgets" example above, can be viewed as + * a query on the stream source. Unless the source was explicitly + * designed for concurrent modification (such as a {@link ConcurrentHashMap}), + * unpredictable or erroneous behavior may result from modifying the stream + * source while it is being queried. + * + *

    Most stream operations accept parameters that describe user-specified + * behavior, such as the lambda expression {@code w -> w.getWeight()} passed to + * {@code mapToLong} in the example above. Such parameters are always instances + * of a functional interface such + * as {@link java.util.function.Function}, and are often lambda expressions or + * method references. These parameters can never be null, should not modify the + * stream source, and should be + * effectively stateless + * (their result should not depend on any state that might change during + * execution of the stream pipeline.) + * + *

    A stream should be operated on (invoking an intermediate or terminal stream + * operation) only once. This rules out, for example, "forked" streams, where + * the same source feeds two or more pipelines, or multiple traversals of the + * same stream. A stream implementation may throw {@link IllegalStateException} + * if it detects that the stream is being reused. However, since some stream + * operations may return their receiver rather than a new stream object, it may + * not be possible to detect reuse in all cases. + * + *

    Streams have a {@link #close()} method and implement {@link AutoCloseable}, + * but nearly all stream instances do not actually need to be closed after use. + * Generally, only streams whose source is an IO channel (such as those returned + * by {@link Files#lines(Path, Charset)}) will require closing. Most streams + * are backed by collections, arrays, or generating functions, which require no + * special resource management. (If a stream does require closing, it can be + * declared as a resource in a {@code try}-with-resources statement.) + * + *

    Stream pipelines may execute either sequentially or in + * parallel. This + * execution mode is a property of the stream. Streams are created + * with an initial choice of sequential or parallel execution. (For example, + * {@link Collection#stream() Collection.stream()} creates a sequential stream, + * and {@link Collection#parallelStream() Collection.parallelStream()} creates + * a parallel one.) This choice of execution mode may be modified by the + * {@link #sequential()} or {@link #parallel()} methods, and may be queried with + * the {@link #isParallel()} method. * * @since 1.8 * @see java.util.stream @@ -160,22 +212,13 @@ public interface LongStream extends BaseStream { /** * Returns a stream consisting of the results of replacing each element of * this stream with the contents of the stream produced by applying the - * provided mapping function to each element. + * provided mapping function to each element. (If the result of the mapping + * function is {@code null}, this is treated as if the result was an empty + * stream.) * *

    This is an intermediate * operation. * - * @apiNote - * The {@code flatMap()} operation has the effect of applying a one-to-many - * tranformation to the elements of the stream, and then flattening the - * resulting elements into a new stream. For example, if {@code orders} - * is a stream of purchase orders, and each purchase order contains a - * collection of line items, then the following produces a stream of line - * items: - *

    {@code
    -     *     orderStream.flatMap(order -> order.getLineItems().stream())...
    -     * }
    - * * @param mapper a * non-interfering, stateless function to apply to * each element which produces an {@code LongStream} of new @@ -224,18 +267,18 @@ public interface LongStream extends BaseStream { *
    {@code
          *     list.stream()
          *         .filter(filteringFunction)
    -     *         .peek(e -> {System.out.println("Filtered value: " + e); });
    +     *         .peek(e -> System.out.println("Filtered value: " + e));
          *         .map(mappingFunction)
    -     *         .peek(e -> {System.out.println("Mapped value: " + e); });
    +     *         .peek(e -> System.out.println("Mapped value: " + e));
          *         .collect(Collectors.toLongSummaryStastistics());
          * }
    * - * @param consumer a - * non-interfering action to perform on the elements as - * they are consumed from the stream + * @param action a + * non-interfering action to perform on the elements as + * they are consumed from the stream * @return the new stream */ - LongStream peek(LongConsumer consumer); + LongStream peek(LongConsumer action); /** * Returns a stream consisting of the elements of this stream, truncated @@ -252,8 +295,8 @@ public interface LongStream extends BaseStream { /** * Returns a stream consisting of the remaining elements of this stream - * after indexing {@code startInclusive} elements into the stream. If the - * {@code startInclusive} index lies past the end of this stream then an + * after discarding the first {@code startInclusive} elements of the stream. + * If this stream contains fewer than {@code startInclusive} elements then an * empty stream will be returned. * *

    This is a stateful @@ -267,10 +310,10 @@ public interface LongStream extends BaseStream { /** * Returns a stream consisting of the remaining elements of this stream - * after indexing {@code startInclusive} elements into the stream and - * truncated to contain no more than {@code endExclusive - startInclusive} - * elements. If the {@code startInclusive} index lies past the end - * of this stream then an empty stream will be returned. + * after discarding the first {@code startInclusive} elements and truncating + * the result to be no longer than {@code endExclusive - startInclusive} + * elements in length. If this stream contains fewer than + * {@code startInclusive} elements then an empty stream will be returned. * *

    This is a short-circuiting * stateful intermediate operation. @@ -419,12 +462,12 @@ public interface LongStream extends BaseStream { /** * Performs a mutable * reduction operation on the elements of this stream. A mutable - * reduction is one in which the reduced value is a mutable value holder, + * reduction is one in which the reduced value is a mutable result container, * such as an {@code ArrayList}, and elements are incorporated by updating - * the state of the result, rather than by replacing the result. This + * the state of the result rather than by replacing the result. This * produces a result equivalent to: *

    {@code
    -     *     R result = resultFactory.get();
    +     *     R result = supplier.get();
          *     for (long element : this stream)
          *         accumulator.accept(result, element);
          *     return result;
    @@ -437,10 +480,9 @@ public interface LongStream extends BaseStream {
          * operation.
          *
          * @param  type of the result
    -     * @param resultFactory a function that creates a new result container.
    -     *                      For a parallel execution, this function may be
    -     *                      called multiple times and must return a fresh value
    -     *                      each time.
    +     * @param supplier a function that creates a new result container. For a
    +     *                 parallel execution, this function may be called
    +     *                 multiple times and must return a fresh value each time.
          * @param accumulator an associative
          *                    non-interfering,
          *                    stateless function for incorporating an additional
    @@ -452,18 +494,21 @@ public interface LongStream extends BaseStream {
          * @return the result of the reduction
          * @see Stream#collect(Supplier, BiConsumer, BiConsumer)
          */
    -     R collect(Supplier resultFactory,
    +     R collect(Supplier supplier,
                       ObjLongConsumer accumulator,
                       BiConsumer combiner);
     
         /**
          * Returns the sum of elements in this stream.  This is a special case
    -     * of a reduction
    +     * of a reduction
          * and is equivalent to:
          * 
    {@code
          *     return reduce(0, Long::sum);
          * }
    * + *

    This is a terminal + * operation. + * * @return the sum of elements in this stream */ long sum(); @@ -471,7 +516,7 @@ public interface LongStream extends BaseStream { /** * Returns an {@code OptionalLong} describing the minimum element of this * stream, or an empty optional if this stream is empty. This is a special - * case of a reduction + * case of a reduction * and is equivalent to: *

    {@code
          *     return reduce(Long::min);
    @@ -479,7 +524,6 @@ public interface LongStream extends BaseStream {
          *
          * 

    This is a terminal operation. * - * @return an {@code OptionalLong} containing the minimum element of this * stream, or an empty {@code OptionalLong} if the stream is empty */ @@ -488,7 +532,7 @@ public interface LongStream extends BaseStream { /** * Returns an {@code OptionalLong} describing the maximum element of this * stream, or an empty optional if this stream is empty. This is a special - * case of a reduction + * case of a reduction * and is equivalent to: *

    {@code
          *     return reduce(Long::max);
    @@ -504,7 +548,7 @@ public interface LongStream extends BaseStream {
     
         /**
          * Returns the count of elements in this stream.  This is a special case of
    -     * a reduction and is
    +     * a reduction and is
          * equivalent to:
          * 
    {@code
          *     return map(e -> 1L).sum();
    @@ -520,7 +564,10 @@ public interface LongStream extends BaseStream {
          * Returns an {@code OptionalDouble} describing the arithmetic mean of elements of
          * this stream, or an empty optional if this stream is empty.  This is a
          * special case of a
    -     * reduction.
    +     * reduction.
    +     *
    +     * 

    This is a terminal + * operation. * * @return an {@code OptionalDouble} containing the average element of this * stream, or an empty optional if the stream is empty @@ -530,7 +577,10 @@ public interface LongStream extends BaseStream { /** * Returns a {@code LongSummaryStatistics} describing various summary data * about the elements of this stream. This is a special case of a - * reduction. + * reduction. + * + *

    This is a terminal + * operation. * * @return a {@code LongSummaryStatistics} describing various summary data * about the elements of this stream @@ -587,9 +637,8 @@ public interface LongStream extends BaseStream { /** * Returns an {@link OptionalLong} describing the first element of this - * stream (in the encounter order), or an empty {@code OptionalLong} if the - * stream is empty. If the stream has no encounter order, then any element - * may be returned. + * stream, or an empty {@code OptionalLong} if the stream is empty. If the + * stream has no encounter order, then any element may be returned. * *

    This is a short-circuiting * terminal operation. @@ -609,8 +658,8 @@ public interface LongStream extends BaseStream { *

    The behavior of this operation is explicitly nondeterministic; it is * free to select any element in the stream. This is to allow for maximal * performance in parallel operations; the cost is that multiple invocations - * on the same source may not return the same result. (If the first element - * in the encounter order is desired, use {@link #findFirst()} instead.) + * on the same source may not return the same result. (If a stable result + * is desired, use {@link #findFirst()} instead.) * * @return an {@code OptionalLong} describing some element of this stream, * or an empty {@code OptionalLong} if the stream is empty @@ -622,6 +671,9 @@ public interface LongStream extends BaseStream { * Returns a {@code DoubleStream} consisting of the elements of this stream, * converted to {@code double}. * + *

    This is an intermediate + * operation. + * * @return a {@code DoubleStream} consisting of the elements of this stream, * converted to {@code double} */ @@ -631,6 +683,9 @@ public interface LongStream extends BaseStream { * Returns a {@code Stream} consisting of the elements of this stream, * each boxed to a {@code Long}. * + *

    This is an intermediate + * operation. + * * @return a {@code Stream} consistent of the elements of this stream, * each boxed to {@code Long} */ @@ -679,7 +734,7 @@ public interface LongStream extends BaseStream { } /** - * Returns a sequential stream whose elements are the specified values. + * Returns a sequential ordered stream whose elements are the specified values. * * @param values the elements of the new stream * @return the new stream @@ -689,7 +744,7 @@ public interface LongStream extends BaseStream { } /** - * Returns an infinite sequential {@code LongStream} produced by iterative + * Returns an infinite sequential ordered {@code LongStream} produced by iterative * application of a function {@code f} to an initial element {@code seed}, * producing a {@code Stream} consisting of {@code seed}, {@code f(seed)}, * {@code f(f(seed))}, etc. @@ -727,9 +782,9 @@ public interface LongStream extends BaseStream { } /** - * Returns a sequential {@code LongStream} where each element is generated - * by a {@code LongSupplier}. This is suitable for generating constant - * streams, streams of random elements, etc. + * Returns a sequential stream where each element is generated by + * the provided {@code LongSupplier}. This is suitable for generating + * constant streams, streams of random elements, etc. * * @param s the {@code LongSupplier} for generated elements * @return a new sequential {@code LongStream} @@ -741,7 +796,7 @@ public interface LongStream extends BaseStream { } /** - * Returns a sequential {@code LongStream} from {@code startInclusive} + * Returns a sequential ordered {@code LongStream} from {@code startInclusive} * (inclusive) to {@code endExclusive} (exclusive) by an incremental step of * {@code 1}. * @@ -774,7 +829,7 @@ public interface LongStream extends BaseStream { } /** - * Returns a sequential {@code LongStream} from {@code startInclusive} + * Returns a sequential ordered {@code LongStream} from {@code startInclusive} * (inclusive) to {@code endInclusive} (inclusive) by an incremental step of * {@code 1}. * @@ -808,16 +863,16 @@ public interface LongStream extends BaseStream { } /** - * Creates a lazy concatenated {@code LongStream} whose elements are all the - * elements of a first {@code LongStream} succeeded by all the elements of the - * second {@code LongStream}. The resulting stream is ordered if both + * Creates a lazily concatenated stream whose elements are all the + * elements of the first stream followed by all the elements of the + * second stream. The resulting stream is ordered if both * of the input streams are ordered, and parallel if either of the input * streams is parallel. When the resulting stream is closed, the close * handlers for both input streams are invoked. * * @param a the first stream - * @param b the second stream to concatenate on to end of the first stream - * @return the concatenation of the two streams + * @param b the second stream + * @return the concatenation of the two input streams */ public static LongStream concat(LongStream a, LongStream b) { Objects.requireNonNull(a); @@ -832,9 +887,9 @@ public interface LongStream extends BaseStream { /** * A mutable builder for a {@code LongStream}. * - *

    A stream builder has a lifecycle, where it starts in a building - * phase, during which elements can be added, and then transitions to a - * built phase, after which elements may not be added. The built phase + *

    A stream builder has a lifecycle, which starts in a building + * phase, during which elements can be added, and then transitions to a built + * phase, after which elements may not be added. The built phase begins * begins when the {@link #build()} method is called, which creates an * ordered stream whose elements are the elements that were added to the * stream builder, in the order they were added. diff --git a/jdk/src/share/classes/java/util/stream/PipelineHelper.java b/jdk/src/share/classes/java/util/stream/PipelineHelper.java index 6824e3b3179..f510131d6ec 100644 --- a/jdk/src/share/classes/java/util/stream/PipelineHelper.java +++ b/jdk/src/share/classes/java/util/stream/PipelineHelper.java @@ -28,7 +28,7 @@ import java.util.Spliterator; import java.util.function.IntFunction; /** - * Helper class for executing + * Helper class for executing * stream pipelines, capturing all of the information about a stream * pipeline (output shape, intermediate operations, stream flags, parallelism, * etc) in one place. diff --git a/jdk/src/share/classes/java/util/stream/ReferencePipeline.java b/jdk/src/share/classes/java/util/stream/ReferencePipeline.java index 42d711f4b2b..9d6aa59c8a7 100644 --- a/jdk/src/share/classes/java/util/stream/ReferencePipeline.java +++ b/jdk/src/share/classes/java/util/stream/ReferencePipeline.java @@ -170,6 +170,7 @@ abstract class ReferencePipeline } @Override + @SuppressWarnings("unchecked") public void accept(P_OUT u) { if (predicate.test(u)) downstream.accept(u); @@ -263,6 +264,7 @@ abstract class ReferencePipeline } @Override + @SuppressWarnings("unchecked") public void accept(P_OUT u) { try (Stream result = mapper.apply(u)) { // We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it @@ -360,16 +362,17 @@ abstract class ReferencePipeline } @Override - public final Stream peek(Consumer tee) { - Objects.requireNonNull(tee); + public final Stream peek(Consumer action) { + Objects.requireNonNull(action); return new StatelessOp(this, StreamShape.REFERENCE, 0) { @Override Sink opWrapSink(int flags, Sink sink) { return new Sink.ChainedReference(sink) { @Override + @SuppressWarnings("unchecked") public void accept(P_OUT u) { - tee.accept(u); + action.accept(u); downstream.accept(u); } }; @@ -515,10 +518,10 @@ abstract class ReferencePipeline } @Override - public final R collect(Supplier resultFactory, + public final R collect(Supplier supplier, BiConsumer accumulator, BiConsumer combiner) { - return evaluate(ReduceOps.makeRef(resultFactory, accumulator, combiner)); + return evaluate(ReduceOps.makeRef(supplier, accumulator, combiner)); } @Override diff --git a/jdk/src/share/classes/java/util/stream/Stream.java b/jdk/src/share/classes/java/util/stream/Stream.java index 715729f24a7..4a9f05f5103 100644 --- a/jdk/src/share/classes/java/util/stream/Stream.java +++ b/jdk/src/share/classes/java/util/stream/Stream.java @@ -24,13 +24,18 @@ */ package java.util.stream; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.Arrays; +import java.util.Collection; import java.util.Comparator; import java.util.Iterator; import java.util.Objects; import java.util.Optional; import java.util.Spliterator; import java.util.Spliterators; +import java.util.concurrent.ConcurrentHashMap; import java.util.function.BiConsumer; import java.util.function.BiFunction; import java.util.function.BinaryOperator; @@ -44,51 +49,90 @@ import java.util.function.ToIntFunction; import java.util.function.ToLongFunction; import java.util.function.UnaryOperator; -// @@@ Specification to-do list @@@ -// - Describe the difference between sequential and parallel streams -// - More general information about reduce, better definitions for associativity, more description of -// how reduce employs parallelism, more examples -// - Role of stream flags in various operations, specifically ordering -// - Whether each op preserves encounter order -// @@@ Specification to-do list @@@ - /** - * A sequence of elements supporting sequential and parallel bulk operations. - * Streams support lazy intermediate operations (transforming a stream to - * another stream) such as {@code filter} and {@code map}, and terminal - * operations (consuming the contents of a stream to produce a result or - * side-effect), such as {@code forEach}, {@code findFirst}, and {@code - * iterator}. Once an operation has been performed on a stream, it - * is considered consumed and no longer usable for other operations. + * A sequence of elements supporting sequential and parallel aggregate + * operations. The following example illustrates an aggregate operation using + * {@link Stream} and {@link IntStream}: * - *

    For sequential stream pipelines, all operations are performed in the - * encounter order of the pipeline - * source, if the pipeline source has a defined encounter order. + *

    {@code
    + *     int sum = widgets.stream()
    + *                      .filter(w -> w.getColor() == RED)
    + *                      .mapToInt(w -> w.getWeight())
    + *                      .sum();
    + * }
    * - *

    For parallel stream pipelines, unless otherwise specified, intermediate - * stream operations preserve the - * encounter order of their source, and terminal operations - * respect the encounter order of their source, if the source - * has an encounter order. Provided that and parameters to stream operations - * satisfy the non-interference - * requirements, and excepting differences arising from the absence of - * a defined encounter order, the result of a stream pipeline should be the - * stable across multiple executions of the same operations on the same source. - * However, the timing and thread in which side-effects occur (for those - * operations which are allowed to produce side-effects, such as - * {@link #forEach(Consumer)}), are explicitly nondeterministic for parallel - * execution of stream pipelines. + * In this example, {@code widgets} is a {@code Collection}. We create + * a stream of {@code Widget} objects via {@link Collection#stream Collection.stream()}, + * filter it to produce a stream containing only the red widgets, and then + * transform it into a stream of {@code int} values representing the weight of + * each red widget. Then this stream is summed to produce a total weight. * - *

    Unless otherwise noted, passing a {@code null} argument to any stream - * method may result in a {@link NullPointerException}. + *

    To perform a computation, stream + * operations are composed into a + * stream pipeline. A stream pipeline consists of a source (which + * might be an array, a collection, a generator function, an I/O channel, + * etc), zero or more intermediate operations (which transform a + * stream into another stream, such as {@link Stream#filter(Predicate)}), and a + * terminal operation (which produces a result or side-effect, such + * as {@link Stream#count()} or {@link Stream#forEach(Consumer)}). + * Streams are lazy; computation on the source data is only performed when the + * terminal operation is initiated, and source elements are consumed only + * as needed. * - * @apiNote - * Streams are not data structures; they do not manage the storage for their - * elements, nor do they support access to individual elements. However, - * you can use the {@link #iterator()} or {@link #spliterator()} operations to - * perform a controlled traversal. + *

    Collections and streams, while bearing some superficial similarities, + * have different goals. Collections are primarily concerned with the efficient + * management of, and access to, their elements. By contrast, streams do not + * provide a means to directly access or manipulate their elements, and are + * instead concerned with declaratively describing their source and the + * computational operations which will be performed in aggregate on that source. + * However, if the provided stream operations do not offer the desired + * functionality, the {@link #iterator()} and {@link #spliterator()} operations + * can be used to perform a controlled traversal. * - * @param type of elements + *

    A stream pipeline, like the "widgets" example above, can be viewed as + * a query on the stream source. Unless the source was explicitly + * designed for concurrent modification (such as a {@link ConcurrentHashMap}), + * unpredictable or erroneous behavior may result from modifying the stream + * source while it is being queried. + * + *

    Most stream operations accept parameters that describe user-specified + * behavior, such as the lambda expression {@code w -> w.getWeight()} passed to + * {@code mapToInt} in the example above. Such parameters are always instances + * of a functional interface such + * as {@link java.util.function.Function}, and are often lambda expressions or + * method references. These parameters can never be null, should not modify the + * stream source, and should be + * effectively stateless + * (their result should not depend on any state that might change during + * execution of the stream pipeline.) + * + *

    A stream should be operated on (invoking an intermediate or terminal stream + * operation) only once. This rules out, for example, "forked" streams, where + * the same source feeds two or more pipelines, or multiple traversals of the + * same stream. A stream implementation may throw {@link IllegalStateException} + * if it detects that the stream is being reused. However, since some stream + * operations may return their receiver rather than a new stream object, it may + * not be possible to detect reuse in all cases. + * + *

    Streams have a {@link #close()} method and implement {@link AutoCloseable}, + * but nearly all stream instances do not actually need to be closed after use. + * Generally, only streams whose source is an IO channel (such as those returned + * by {@link Files#lines(Path, Charset)}) will require closing. Most streams + * are backed by collections, arrays, or generating functions, which require no + * special resource management. (If a stream does require closing, it can be + * declared as a resource in a {@code try}-with-resources statement.) + * + *

    Stream pipelines may execute either sequentially or in + * parallel. This + * execution mode is a property of the stream. Streams are created + * with an initial choice of sequential or parallel execution. (For example, + * {@link Collection#stream() Collection.stream()} creates a sequential stream, + * and {@link Collection#parallelStream() Collection.parallelStream()} creates + * a parallel one.) This choice of execution mode may be modified by the + * {@link #sequential()} or {@link #parallel()} methods, and may be queried with + * the {@link #isParallel()} method. + * + * @param the type of the stream elements * @since 1.8 * @see java.util.stream */ @@ -168,9 +212,9 @@ public interface Stream extends BaseStream> { /** * Returns a stream consisting of the results of replacing each element of * this stream with the contents of the stream produced by applying the - * provided mapping function to each element. If the result of the mapping - * function is {@code null}, this is treated as if the result is an empty - * stream. + * provided mapping function to each element. (If the result of the mapping + * function is {@code null}, this is treated as if the result was an empty + * stream.) * *

    This is an intermediate * operation. @@ -197,9 +241,9 @@ public interface Stream extends BaseStream> { /** * Returns an {@code IntStream} consisting of the results of replacing each * element of this stream with the contents of the stream produced by - * applying the provided mapping function to each element. If the result of - * the mapping function is {@code null}, this is treated as if the result is - * an empty stream. + * applying the provided mapping function to each element. (If the result + * of the mapping function is {@code null}, this is treated as if the result + * was an empty stream.) * *

    This is an intermediate * operation. @@ -214,9 +258,9 @@ public interface Stream extends BaseStream> { /** * Returns a {@code LongStream} consisting of the results of replacing each * element of this stream with the contents of the stream produced - * by applying the provided mapping function to each element. If the result - * of the mapping function is {@code null}, this is treated as if the - * result is an empty stream. + * by applying the provided mapping function to each element. (If the result + * of the mapping function is {@code null}, this is treated as if the result + * was an empty stream.) * *

    This is an intermediate * operation. @@ -231,9 +275,9 @@ public interface Stream extends BaseStream> { /** * Returns a {@code DoubleStream} consisting of the results of replacing each * element of this stream with the contents of the stream produced - * by applying the provided mapping function to each element. If the result + * by applying the provided mapping function to each element. (If the result * of the mapping function is {@code null}, this is treated as if the result - * is an empty stream. + * was an empty stream.) * *

    This is an intermediate * operation. @@ -260,7 +304,7 @@ public interface Stream extends BaseStream> { * Returns a stream consisting of the elements of this stream, sorted * according to natural order. If the elements of this stream are not * {@code Comparable}, a {@code java.lang.ClassCastException} may be thrown - * when the stream pipeline is executed. + * when the terminal operation is executed. * *

    This is a stateful * intermediate operation. @@ -301,18 +345,18 @@ public interface Stream extends BaseStream> { *

    {@code
          *     list.stream()
          *         .filter(filteringFunction)
    -     *         .peek(e -> {System.out.println("Filtered value: " + e); });
    +     *         .peek(e -> System.out.println("Filtered value: " + e));
          *         .map(mappingFunction)
    -     *         .peek(e -> {System.out.println("Mapped value: " + e); });
    +     *         .peek(e -> System.out.println("Mapped value: " + e));
          *         .collect(Collectors.intoList());
          * }
    * - * @param consumer a + * @param action a * non-interfering action to perform on the elements as * they are consumed from the stream * @return the new stream */ - Stream peek(Consumer consumer); + Stream peek(Consumer action); /** * Returns a stream consisting of the elements of this stream, truncated @@ -329,8 +373,8 @@ public interface Stream extends BaseStream> { /** * Returns a stream consisting of the remaining elements of this stream - * after indexing {@code startInclusive} elements into the stream. If the - * {@code startInclusive} index lies past the end of this stream then an + * after discarding the first {@code startInclusive} elements of the stream. + * If this stream contains fewer than {@code startInclusive} elements then an * empty stream will be returned. * *

    This is a stateful @@ -344,10 +388,10 @@ public interface Stream extends BaseStream> { /** * Returns a stream consisting of the remaining elements of this stream - * after indexing {@code startInclusive} elements into the stream and - * truncated to contain no more than {@code endExclusive - startInclusive} - * elements. If the {@code startInclusive} index lies past the end - * of this stream then an empty stream will be returned. + * after discarding the first {@code startInclusive} elements and truncating + * the result to be no longer than {@code endExclusive - startInclusive} + * elements in length. If this stream contains fewer than + * {@code startInclusive} elements then an empty stream will be returned. * *

    This is a short-circuiting * stateful intermediate operation. @@ -405,11 +449,23 @@ public interface Stream extends BaseStream> { /** * Returns an array containing the elements of this stream, using the - * provided {@code generator} function to allocate the returned array. + * provided {@code generator} function to allocate the returned array, as + * well as any additional arrays that might be required for a partitioned + * execution or for resizing. * *

    This is a terminal * operation. * + * @apiNote + * The generator function takes an integer, which is the size of the + * desired array, and produces an array of the desired size. This can be + * concisely expressed with an array constructor reference: + *

    {@code
    +     *     Person[] men = people.stream()
    +     *                          .filter(p -> p.getGender() == MALE)
    +     *                          .toArray(Person[]::new);
    +     * }
    + * * @param the element type of the resulting array * @param generator a function which produces a new array of the desired * type and the provided length @@ -451,7 +507,7 @@ public interface Stream extends BaseStream> { * Integer sum = integers.reduce(0, (a, b) -> a+b); * }
    * - * or more compactly: + * or: * *
    {@code
          *     Integer sum = integers.reduce(0, Integer::sum);
    @@ -501,7 +557,8 @@ public interface Stream extends BaseStream> {
          * @param accumulator an associative
          *                    non-interfering,
          *                    stateless function for combining two values
    -     * @return the result of the reduction
    +     * @return an {@link Optional} describing the result of the reduction
    +     * @throws NullPointerException if the result of the reduction is null
          * @see #reduce(Object, BinaryOperator)
          * @see #min(java.util.Comparator)
          * @see #max(java.util.Comparator)
    @@ -511,7 +568,7 @@ public interface Stream extends BaseStream> {
         /**
          * Performs a reduction on the
          * elements of this stream, using the provided identity, accumulation
    -     * function, and a combining functions.  This is equivalent to:
    +     * function, and combining functions.  This is equivalent to:
          * 
    {@code
          *     U result = identity;
          *     for (T element : this stream)
    @@ -537,8 +594,8 @@ public interface Stream extends BaseStream> {
          * by an explicit combination of {@code map} and {@code reduce} operations.
          * The {@code accumulator} function acts as a fused mapper and accumulator,
          * which can sometimes be more efficient than separate mapping and reduction,
    -     * such as in the case where knowing the previously reduced value allows you
    -     * to avoid some computation.
    +     * such as when knowing the previously reduced value allows you to avoid
    +     * some computation.
          *
          * @param  The type of the result
          * @param identity the identity value for the combiner function
    @@ -561,12 +618,12 @@ public interface Stream extends BaseStream> {
         /**
          * Performs a mutable
          * reduction operation on the elements of this stream.  A mutable
    -     * reduction is one in which the reduced value is a mutable value holder,
    +     * reduction is one in which the reduced value is a mutable result container,
          * such as an {@code ArrayList}, and elements are incorporated by updating
    -     * the state of the result, rather than by replacing the result.  This
    +     * the state of the result rather than by replacing the result.  This
          * produces a result equivalent to:
          * 
    {@code
    -     *     R result = resultFactory.get();
    +     *     R result = supplier.get();
          *     for (T element : this stream)
          *         accumulator.accept(result, element);
          *     return result;
    @@ -579,10 +636,11 @@ public interface Stream extends BaseStream> {
          * operation.
          *
          * @apiNote There are many existing classes in the JDK whose signatures are
    -     * a good match for use as arguments to {@code collect()}.  For example,
    -     * the following will accumulate strings into an ArrayList:
    +     * well-suited for use with method references as arguments to {@code collect()}.
    +     * For example, the following will accumulate strings into an {@code ArrayList}:
          * 
    {@code
    -     *     List asList = stringStream.collect(ArrayList::new, ArrayList::add, ArrayList::addAll);
    +     *     List asList = stringStream.collect(ArrayList::new, ArrayList::add,
    +     *                                                ArrayList::addAll);
          * }
    * *

    The following will take a stream of strings and concatenates them into a @@ -594,10 +652,9 @@ public interface Stream extends BaseStream> { * }

    * * @param type of the result - * @param resultFactory a function that creates a new result container. - * For a parallel execution, this function may be - * called multiple times and must return a fresh value - * each time. + * @param supplier a function that creates a new result container. For a + * parallel execution, this function may be called + * multiple times and must return a fresh value each time. * @param accumulator an associative * non-interfering, * stateless function for incorporating an additional @@ -608,24 +665,24 @@ public interface Stream extends BaseStream> { * must be compatible with the accumulator function * @return the result of the reduction */ - R collect(Supplier resultFactory, + R collect(Supplier supplier, BiConsumer accumulator, BiConsumer combiner); /** * Performs a mutable * reduction operation on the elements of this stream using a - * {@code Collector} object to describe the reduction. A {@code Collector} + * {@code Collector}. A {@code Collector} * encapsulates the functions used as arguments to * {@link #collect(Supplier, BiConsumer, BiConsumer)}, allowing for reuse of - * collection strategies, and composition of collect operations such as + * collection strategies and composition of collect operations such as * multiple-level grouping or partitioning. * *

    This is a terminal * operation. * *

    When executed in parallel, multiple intermediate results may be - * instantiated, populated, and merged, so as to maintain isolation of + * instantiated, populated, and merged so as to maintain isolation of * mutable data structures. Therefore, even when executed in parallel * with non-thread-safe data structures (such as {@code ArrayList}), no * additional synchronization is needed for a parallel reduction. @@ -638,16 +695,16 @@ public interface Stream extends BaseStream> { * *

    The following will classify {@code Person} objects by city: *

    {@code
    -     *     Map> peopleByCity
    -     *         = personStream.collect(Collectors.groupBy(Person::getCity));
    +     *     Map> peopleByCity
    +     *         = personStream.collect(Collectors.groupingBy(Person::getCity));
          * }
    * *

    The following will classify {@code Person} objects by state and city, * cascading two {@code Collector}s together: *

    {@code
    -     *     Map>> peopleByStateAndCity
    -     *         = personStream.collect(Collectors.groupBy(Person::getState,
    -     *                                                   Collectors.groupBy(Person::getCity)));
    +     *     Map>> peopleByStateAndCity
    +     *         = personStream.collect(Collectors.groupingBy(Person::getState,
    +     *                                                      Collectors.groupingBy(Person::getCity)));
          * }
    * * @param the type of the result @@ -662,7 +719,7 @@ public interface Stream extends BaseStream> { /** * Returns the minimum element of this stream according to the provided * {@code Comparator}. This is a special case of a - * reduction. + * reduction. * *

    This is a terminal operation. * @@ -671,13 +728,14 @@ public interface Stream extends BaseStream> { * elements of this stream * @return an {@code Optional} describing the minimum element of this stream, * or an empty {@code Optional} if the stream is empty + * @throws NullPointerException if the minimum element is null */ Optional min(Comparator comparator); /** * Returns the maximum element of this stream according to the provided * {@code Comparator}. This is a special case of a - * reduction. + * reduction. * *

    This is a terminal * operation. @@ -687,12 +745,13 @@ public interface Stream extends BaseStream> { * elements of this stream * @return an {@code Optional} describing the maximum element of this stream, * or an empty {@code Optional} if the stream is empty + * @throws NullPointerException if the maximum element is null */ Optional max(Comparator comparator); /** * Returns the count of elements in this stream. This is a special case of - * a reduction and is + * a reduction and is * equivalent to: *

    {@code
          *     return mapToLong(e -> 1L).sum();
    @@ -753,10 +812,9 @@ public interface Stream extends BaseStream> {
         boolean noneMatch(Predicate predicate);
     
         /**
    -     * Returns an {@link Optional} describing the first element of this stream
    -     * (in the encounter order), or an empty {@code Optional} if the stream is
    -     * empty.  If the stream has no encounter order, then any element may be
    -     * returned.
    +     * Returns an {@link Optional} describing the first element of this stream,
    +     * or an empty {@code Optional} if the stream is empty.  If the stream has
    +     * no encounter order, then any element may be returned.
          *
          * 

    This is a short-circuiting * terminal operation. @@ -777,8 +835,8 @@ public interface Stream extends BaseStream> { *

    The behavior of this operation is explicitly nondeterministic; it is * free to select any element in the stream. This is to allow for maximal * performance in parallel operations; the cost is that multiple invocations - * on the same source may not return the same result. (If the first element - * in the encounter order is desired, use {@link #findFirst()} instead.) + * on the same source may not return the same result. (If a stable result + * is desired, use {@link #findFirst()} instead.) * * @return an {@code Optional} describing some element of this stream, or an * empty {@code Optional} if the stream is empty @@ -821,20 +879,20 @@ public interface Stream extends BaseStream> { } /** - * Returns a sequential stream whose elements are the specified values. + * Returns a sequential ordered stream whose elements are the specified values. * * @param the type of stream elements * @param values the elements of the new stream * @return the new stream */ @SafeVarargs - @SuppressWarnings("varargs") // Creating a stream from an array is safe + @SuppressWarnings("varargs") public static Stream of(T... values) { return Arrays.stream(values); } /** - * Returns an infinite sequential {@code Stream} produced by iterative + * Returns an infinite sequential ordered {@code Stream} produced by iterative * application of a function {@code f} to an initial element {@code seed}, * producing a {@code Stream} consisting of {@code seed}, {@code f(seed)}, * {@code f(f(seed))}, etc. @@ -872,8 +930,8 @@ public interface Stream extends BaseStream> { } /** - * Returns a sequential {@code Stream} where each element is - * generated by a {@code Supplier}. This is suitable for generating + * Returns a sequential stream where each element is generated by + * the provided {@code Supplier}. This is suitable for generating * constant streams, streams of random elements, etc. * * @param the type of stream elements @@ -887,17 +945,16 @@ public interface Stream extends BaseStream> { } /** - * Creates a lazy concatenated {@code Stream} whose elements are all the - * elements of a first {@code Stream} succeeded by all the elements of the - * second {@code Stream}. The resulting stream is ordered if both + * Creates a lazily concatenated stream whose elements are all the + * elements of the first stream followed by all the elements of the + * second stream. The resulting stream is ordered if both * of the input streams are ordered, and parallel if either of the input * streams is parallel. When the resulting stream is closed, the close * handlers for both input streams are invoked. * * @param The type of stream elements * @param a the first stream - * @param b the second stream to concatenate on to end of the first - * stream + * @param b the second stream * @return the concatenation of the two input streams */ public static Stream concat(Stream a, Stream b) { @@ -917,7 +974,7 @@ public interface Stream extends BaseStream> { * {@code Builder} (without the copying overhead that comes from using * an {@code ArrayList} as a temporary buffer.) * - *

    A {@code Stream.Builder} has a lifecycle, where it starts in a building + *

    A stream builder has a lifecycle, which starts in a building * phase, during which elements can be added, and then transitions to a built * phase, after which elements may not be added. The built phase begins * when the {@link #build()} method is called, which creates an ordered diff --git a/jdk/src/share/classes/java/util/stream/StreamSpliterators.java b/jdk/src/share/classes/java/util/stream/StreamSpliterators.java index 4a62803b56b..f7b78422ebe 100644 --- a/jdk/src/share/classes/java/util/stream/StreamSpliterators.java +++ b/jdk/src/share/classes/java/util/stream/StreamSpliterators.java @@ -1456,4 +1456,5 @@ class StreamSpliterators { } } } -} \ No newline at end of file +} + diff --git a/jdk/src/share/classes/java/util/stream/StreamSupport.java b/jdk/src/share/classes/java/util/stream/StreamSupport.java index f6e04b0a51a..6feadd1db21 100644 --- a/jdk/src/share/classes/java/util/stream/StreamSupport.java +++ b/jdk/src/share/classes/java/util/stream/StreamSupport.java @@ -32,12 +32,8 @@ import java.util.function.Supplier; * Low-level utility methods for creating and manipulating streams. * *

    This class is mostly for library writers presenting stream views - * of their data structures; most static stream methods for end users are in - * {@link Streams}. - * - *

    Unless otherwise stated, streams are created as sequential - * streams. A sequential stream can be transformed into a parallel stream by - * calling the {@code parallel()} method on the created stream. + * of data structures; most static stream methods intended for end users are in + * the various {@code Stream} classes. * * @since 1.8 */ @@ -80,7 +76,7 @@ public final class StreamSupport { * {@code Supplier} of {@code Spliterator}. * *

    The {@link Supplier#get()} method will be invoked on the supplier no - * more than once, and after the terminal operation of the stream pipeline + * more than once, and only after the terminal operation of the stream pipeline * commences. * *

    For spliterators that report a characteristic of {@code IMMUTABLE} @@ -88,7 +84,7 @@ public final class StreamSupport { * late-binding, it is likely * more efficient to use {@link #stream(java.util.Spliterator, boolean)} * instead. - * The use of a {@code Supplier} in this form provides a level of + *

    The use of a {@code Supplier} in this form provides a level of * indirection that reduces the scope of potential interference with the * source. Since the supplier is only invoked after the terminal operation * commences, any modifications to the source up to the start of the @@ -148,7 +144,7 @@ public final class StreamSupport { * {@code Supplier} of {@code Spliterator.OfInt}. * *

    The {@link Supplier#get()} method will be invoked on the supplier no - * more than once, and after the terminal operation of the stream pipeline + * more than once, and only after the terminal operation of the stream pipeline * commences. * *

    For spliterators that report a characteristic of {@code IMMUTABLE} @@ -156,7 +152,7 @@ public final class StreamSupport { * late-binding, it is likely * more efficient to use {@link #intStream(java.util.Spliterator.OfInt, boolean)} * instead. - * The use of a {@code Supplier} in this form provides a level of + *

    The use of a {@code Supplier} in this form provides a level of * indirection that reduces the scope of potential interference with the * source. Since the supplier is only invoked after the terminal operation * commences, any modifications to the source up to the start of the @@ -215,7 +211,7 @@ public final class StreamSupport { * {@code Supplier} of {@code Spliterator.OfLong}. * *

    The {@link Supplier#get()} method will be invoked on the supplier no - * more than once, and after the terminal operation of the stream pipeline + * more than once, and only after the terminal operation of the stream pipeline * commences. * *

    For spliterators that report a characteristic of {@code IMMUTABLE} @@ -223,7 +219,7 @@ public final class StreamSupport { * late-binding, it is likely * more efficient to use {@link #longStream(java.util.Spliterator.OfLong, boolean)} * instead. - * The use of a {@code Supplier} in this form provides a level of + *

    The use of a {@code Supplier} in this form provides a level of * indirection that reduces the scope of potential interference with the * source. Since the supplier is only invoked after the terminal operation * commences, any modifications to the source up to the start of the @@ -282,7 +278,7 @@ public final class StreamSupport { * {@code Supplier} of {@code Spliterator.OfDouble}. * *

    The {@link Supplier#get()} method will be invoked on the supplier no - * more than once, and after the terminal operation of the stream pipeline + * more than once, and only after the terminal operation of the stream pipeline * commences. * *

    For spliterators that report a characteristic of {@code IMMUTABLE} @@ -290,7 +286,7 @@ public final class StreamSupport { * late-binding, it is likely * more efficient to use {@link #doubleStream(java.util.Spliterator.OfDouble, boolean)} * instead. - * The use of a {@code Supplier} in this form provides a level of + *

    The use of a {@code Supplier} in this form provides a level of * indirection that reduces the scope of potential interference with the * source. Since the supplier is only invoked after the terminal operation * commences, any modifications to the source up to the start of the diff --git a/jdk/src/share/classes/java/util/stream/package-info.java b/jdk/src/share/classes/java/util/stream/package-info.java index 46d033e38cd..2c01847ace3 100644 --- a/jdk/src/share/classes/java/util/stream/package-info.java +++ b/jdk/src/share/classes/java/util/stream/package-info.java @@ -24,347 +24,484 @@ */ /** - *

    java.util.stream

    - * - * Classes to support functional-style operations on streams of values, as in the following: + * Classes to support functional-style operations on streams of elements, such + * as map-reduce transformations on collections. For example: * *
    {@code
    - *     int sumOfWeights = blocks.stream().filter(b -> b.getColor() == RED)
    - *                                       .mapToInt(b -> b.getWeight())
    - *                                       .sum();
    + *     int sum = widgets.stream()
    + *                      .filter(b -> b.getColor() == RED)
    + *                      .mapToInt(b -> b.getWeight())
    + *                      .sum();
      * }
    * - *

    Here we use {@code blocks}, which might be a {@code Collection}, as a source for a stream, - * and then perform a filter-map-reduce ({@code sum()} is an example of a reduction - * operation) on the stream to obtain the sum of the weights of the red blocks. + *

    Here we use {@code widgets}, a {@code Collection}, + * as a source for a stream, and then perform a filter-map-reduce on the stream + * to obtain the sum of the weights of the red widgets. (Summation is an + * example of a reduction + * operation.) * - *

    The key abstraction used in this approach is {@link java.util.stream.Stream}, as well as its primitive - * specializations {@link java.util.stream.IntStream}, {@link java.util.stream.LongStream}, - * and {@link java.util.stream.DoubleStream}. Streams differ from Collections in several ways: + *

    The key abstraction introduced in this package is stream. The + * classes {@link java.util.stream.Stream}, {@link java.util.stream.IntStream}, + * {@link java.util.stream.LongStream}, and {@link java.util.stream.DoubleStream} + * are streams over objects and the primitive {@code int}, {@code long} and + * {@code double} types. Streams differ from collections in several ways: * *

      - *
    • No storage. A stream is not a data structure that stores elements; instead, they - * carry values from a source (which could be a data structure, a generator, an IO channel, etc) - * through a pipeline of computational operations.
    • - *
    • Functional in nature. An operation on a stream produces a result, but does not modify - * its underlying data source. For example, filtering a {@code Stream} produces a new {@code Stream}, - * rather than removing elements from the underlying source.
    • - *
    • Laziness-seeking. Many stream operations, such as filtering, mapping, or duplicate removal, - * can be implemented lazily, exposing opportunities for optimization. (For example, "find the first - * {@code String} matching a pattern" need not examine all the input strings.) Stream operations - * are divided into intermediate ({@code Stream}-producing) operations and terminal (value-producing) - * operations; all intermediate operations are lazy.
    • - *
    • Possibly unbounded. While collections have a finite size, streams need not. Operations - * such as {@code limit(n)} or {@code findFirst()} can allow computations on infinite streams - * to complete in finite time.
    • + *
    • No storage. A stream is not a data structure that stores elements; + * instead, it conveys elements from a source such as a data structure, + * an array, a generator function, or an I/O channel, through a pipeline of + * computational operations.
    • + *
    • Functional in nature. An operation on a stream produces a result, + * but does not modify its source. For example, filtering a {@code Stream} + * obtained from a collection produces a new {@code Stream} without the + * filtered elements, rather than removing elements from the source + * collection.
    • + *
    • Laziness-seeking. Many stream operations, such as filtering, mapping, + * or duplicate removal, can be implemented lazily, exposing opportunities + * for optimization. For example, "find the first {@code String} with + * three consecutive vowels" need not examine all the input strings. + * Stream operations are divided into intermediate ({@code Stream}-producing) + * operations and terminal (value- or side-effect-producing) operations. + * Intermediate operations are always lazy.
    • + *
    • Possibly unbounded. While collections have a finite size, streams + * need not. Short-circuting operations such as {@code limit(n)} or + * {@code findFirst()} can allow computations on infinite streams to + * complete in finite time.
    • + *
    • Consumable. The elements of a stream are only visited once during + * the life of a stream. Like an {@link java.util.Iterator}, a new stream + * must be generated to revisit the same elements of the source. + *
    • *
    * - *

    Stream pipelines

    + * Streams can be obtained in a number of ways. Some examples include: + *
      + *
    • From a {@link java.util.Collection} via the {@code stream()} and + * {@code parallelStream()} methods;
    • + *
    • From an array via {@link java.util.Arrays#stream(Object[])};
    • + *
    • From static factory methods on the stream classes, such as + * {@link java.util.stream.Stream#of(Object[])}, + * {@link java.util.stream.IntStream#range(int, int)} + * or {@link java.util.stream.Stream#iterate(Object, UnaryOperator)};
    • + *
    • The lines of a file can be obtained from {@link java.io.BufferedReader#lines()};
    • + *
    • Streams of file paths can be obtained from methods in {@link java.nio.file.Files};
    • + *
    • Streams of random numbers can be obtained from {@link java.util.Random#ints()};
    • + *
    • Numerous other stream-bearing methods in the JDK, including + * {@link java.util.BitSet#stream()}, + * {@link java.util.regex.Pattern#splitAsStream(java.lang.CharSequence)}, + * and {@link java.util.jar.JarFile#stream()}.
    • + *
    * - *

    Streams are used to create pipelines of operations. A - * complete stream pipeline has several components: a source (which may be a {@code Collection}, - * an array, a generator function, or an IO channel); zero or more intermediate operations - * such as {@code Stream.filter} or {@code Stream.map}; and a terminal operation such - * as {@code Stream.forEach} or {@code java.util.stream.Stream.reduce}. Stream operations may take as parameters - * function values (which are often lambda expressions, but could be method references - * or objects) which parameterize the behavior of the operation, such as a {@code Predicate} - * passed to the {@code Stream#filter} method. + *

    Additional stream sources can be provided by third-party libraries using + * these techniques. * - *

    Intermediate operations return a new {@code Stream}. They are lazy; executing an - * intermediate operation such as {@link java.util.stream.Stream#filter Stream.filter} does - * not actually perform any filtering, instead creating a new {@code Stream} that, when - * traversed, contains the elements of the initial {@code Stream} that match the - * given {@code Predicate}. Consuming elements from the stream source does not - * begin until the terminal operation is executed. + *

    Stream operations and pipelines

    * - *

    Terminal operations consume the {@code Stream} and produce a result or a side-effect. - * After a terminal operation is performed, the stream can no longer be used and you must - * return to the data source, or select a new data source, to get a new stream. For example, - * obtaining the sum of weights of all red blocks, and then of all blue blocks, requires a - * filter-map-reduce on two different streams: - *

    {@code
    - *     int sumOfRedWeights  = blocks.stream().filter(b -> b.getColor() == RED)
    - *                                           .mapToInt(b -> b.getWeight())
    - *                                           .sum();
    - *     int sumOfBlueWeights = blocks.stream().filter(b -> b.getColor() == BLUE)
    - *                                           .mapToInt(b -> b.getWeight())
    - *                                           .sum();
    - * }
    + *

    Stream operations are + * divided into intermediate and terminal operations, and are + * combined to form stream pipelines. A stream pipeline consists of a + * source (such as a {@code Collection}, an array, a generator function, or an + * I/O channel); followed by zero or more intermediate operations such + * as {@code Stream.filter} or {@code Stream.map}; and a terminal + * operation such as {@code Stream.forEach} or {@code Stream.reduce}. * - *

    However, there are other techniques that allow you to obtain both results in a single - * pass if multiple traversal is impractical or inefficient. TODO provide link + *

    Intermediate operations return a new stream. They are always + * lazy; executing an intermediate operation such as + * {@code filter()} does not actually perform any filtering, but instead + * creates a new stream that, when traversed, contains the elements of + * the initial stream that match the given predicate. Traversal + * of the pipeline source does not begin until the terminal operation of the + * pipeline is executed. * - *

    Stream operations

    + *

    Terminal operations, such as {@code Stream.forEach} or + * {@code IntStream.sum}, may traverse the stream to produce a result or a + * side-effect. After the terminal operation is performed, the stream pipeline + * is considered consumed, and can no longer be used; if you need to traverse + * the same data source again, you must return to the data source to get a new + * stream. In almost all cases, terminal operations are eager, + * completing their traversal of the data source and processing of the pipeline + * before returning. Only the terminal operations {@code iterator()} and + * {@code spliterator()} are not; these are provided as an "escape hatch" to enable + * arbitrary client-controlled pipeline traversals in the event that the + * existing operations are not sufficient to the task. * - *

    Intermediate stream operation (such as {@code filter} or {@code sorted}) always produce a - * new {@code Stream}, and are alwayslazy. Executing a lazy operations does not - * trigger processing of the stream contents; all processing is deferred until the terminal - * operation commences. Processing streams lazily allows for significant efficiencies; in a - * pipeline such as the filter-map-sum example above, filtering, mapping, and addition can be - * fused into a single pass, with minimal intermediate state. Laziness also enables us to avoid - * examining all the data when it is not necessary; for operations such as "find the first - * string longer than 1000 characters", one need not examine all the input strings, just enough - * to find one that has the desired characteristics. (This behavior becomes even more important - * when the input stream is infinite and not merely large.) + *

    Processing streams lazily allows for significant efficiencies; in a + * pipeline such as the filter-map-sum example above, filtering, mapping, and + * summing can be fused into a single pass on the data, with minimal + * intermediate state. Laziness also allows avoiding examining all the data + * when it is not necessary; for operations such as "find the first string + * longer than 1000 characters", it is only necessary to examine just enough + * strings to find one that has the desired characteristics without examining + * all of the strings available from the source. (This behavior becomes even + * more important when the input stream is infinite and not merely large.) * - *

    Intermediate operations are further divided into stateless and stateful - * operations. Stateless operations retain no state from previously seen values when processing - * a new value; examples of stateless intermediate operations include {@code filter} and - * {@code map}. Stateful operations may incorporate state from previously seen elements in - * processing new values; examples of stateful intermediate operations include {@code distinct} - * and {@code sorted}. Stateful operations may need to process the entire input before - * producing a result; for example, one cannot produce any results from sorting a stream until - * one has seen all elements of the stream. As a result, under parallel computation, some - * pipelines containing stateful intermediate operations have to be executed in multiple passes. - * Pipelines containing exclusively stateless intermediate operations can be processed in a - * single pass, whether sequential or parallel. + *

    Intermediate operations are further divided into stateless + * and stateful operations. Stateless operations, such as {@code filter} + * and {@code map}, retain no state from previously seen element when processing + * a new element -- each element can be processed + * independently of operations on other elements. Stateful operations, such as + * {@code distinct} and {@code sorted}, may incorporate state from previously + * seen elements when processing new elements. * - *

    Further, some operations are deemed short-circuiting operations. An intermediate - * operation is short-circuiting if, when presented with infinite input, it may produce a - * finite stream as a result. A terminal operation is short-circuiting if, when presented with - * infinite input, it may terminate in finite time. (Having a short-circuiting operation is a - * necessary, but not sufficient, condition for the processing of an infinite stream to - * terminate normally in finite time.) + *

    Stateful operations may need to process the entire input + * before producing a result. For example, one cannot produce any results from + * sorting a stream until one has seen all elements of the stream. As a result, + * under parallel computation, some pipelines containing stateful intermediate + * operations may require multiple passes on the data or may need to buffer + * significant data. Pipelines containing exclusively stateless intermediate + * operations can be processed in a single pass, whether sequential or parallel, + * with minimal data buffering. * - * Terminal operations (such as {@code forEach} or {@code findFirst}) are always eager - * (they execute completely before returning), and produce a non-{@code Stream} result, such - * as a primitive value or a {@code Collection}, or have side-effects. + *

    Further, some operations are deemed short-circuiting operations. + * An intermediate operation is short-circuiting if, when presented with + * infinite input, it may produce a finite stream as a result. A terminal + * operation is short-circuiting if, when presented with infinite input, it may + * terminate in finite time. Having a short-circuiting operation in the pipeline + * is a necessary, but not sufficient, condition for the processing of an infinite + * stream to terminate normally in finite time. * *

    Parallelism

    * - *

    By recasting aggregate operations as a pipeline of operations on a stream of values, many - * aggregate operations can be more easily parallelized. A {@code Stream} can execute either - * in serial or in parallel. When streams are created, they are either created as sequential - * or parallel streams; the parallel-ness of streams can also be switched by the - * {@link java.util.stream Stream#sequential()} and {@link java.util.stream.Stream#parallel()} - * operations. The {@code Stream} implementations in the JDK create serial streams unless - * parallelism is explicitly requested. For example, {@code Collection} has methods + *

    Processing elements with an explicit {@code for-}loop is inherently serial. + * Streams facilitate parallel execution by reframing the computation as a pipeline of + * aggregate operations, rather than as imperative operations on each individual + * element. All streams operations can execute either in serial or in parallel. + * The stream implementations in the JDK create serial streams unless parallelism is + * explicitly requested. For example, {@code Collection} has methods * {@link java.util.Collection#stream} and {@link java.util.Collection#parallelStream}, - * which produce sequential and parallel streams respectively; other stream-bearing methods - * such as {@link java.util.stream.IntStream#range(int, int)} produce sequential - * streams but these can be efficiently parallelized by calling {@code parallel()} on the - * result. The set of operations on serial and parallel streams is identical. To execute the - * "sum of weights of blocks" query in parallel, we would do: + * which produce sequential and parallel streams respectively; other + * stream-bearing methods such as {@link java.util.stream.IntStream#range(int, int)} + * produce sequential streams but these streams can be efficiently parallelized by + * invoking their {@link java.util.stream.BaseStream#parallel()} method. + * To execute the prior "sum of weights of widgets" query in parallel, we would + * do: * *

    {@code
    - *     int sumOfWeights = blocks.parallelStream().filter(b -> b.getColor() == RED)
    - *                                               .mapToInt(b -> b.getWeight())
    - *                                               .sum();
    + *     int sumOfWeights = widgets.}{@code parallelStream()}{@code .filter(b -> b.getColor() == RED)
    + *                                                .mapToInt(b -> b.getWeight())
    + *                                                .sum();
      * }
    * - *

    The only difference between the serial and parallel versions of this example code is - * the creation of the initial {@code Stream}. Whether a {@code Stream} will execute in serial - * or parallel can be determined by the {@code Stream#isParallel} method. When the terminal - * operation is initiated, the entire stream pipeline is either executed sequentially or in - * parallel, determined by the last operation that affected the stream's serial-parallel - * orientation (which could be the stream source, or the {@code sequential()} or - * {@code parallel()} methods.) + *

    The only difference between the serial and parallel versions of this + * example is the creation of the initial stream, using "{@code parallelStream()}" + * instead of "{@code stream()}". When the terminal operation is initiated, + * the stream pipeline is executed sequentially or in parallel depending on the + * orientation of the stream on which it is invoked. Whether a stream will execute in serial or + * parallel can be determined with the {@code isParallel()} method, and the + * orientation of a stream can be modified with the + * {@link java.util.stream.BaseStream#sequential()} and + * {@link java.util.stream.BaseStream#parallel()} operations. When the terminal + * operation is initiated, the stream pipeline is executed sequentially or in + * parallel depending on the mode of the stream on which it is invoked. * - *

    In order for the results of parallel operations to be deterministic and consistent with - * their serial equivalent, the function values passed into the various stream operations should - * be stateless. + *

    Except for operations identified as explicitly nondeterministic, such + * as {@code findAny()}, whether a stream executes sequentially or in parallel + * should not change the result of the computation. * - *

    Ordering

    - * - *

    Streams may or may not have an encounter order. An encounter - * order specifies the order in which elements are provided by the stream to the - * operations pipeline. Whether or not there is an encounter order depends on - * the source, the intermediate operations, and the terminal operation. - * Certain stream sources (such as {@code List} or arrays) are intrinsically - * ordered, whereas others (such as {@code HashSet}) are not. Some intermediate - * operations may impose an encounter order on an otherwise unordered stream, - * such as {@link java.util.stream.Stream#sorted()}, and others may render an - * ordered stream unordered (such as {@link java.util.stream.Stream#unordered()}). - * Some terminal operations may ignore encounter order, such as - * {@link java.util.stream.Stream#forEach}. - * - *

    If a Stream is ordered, most operations are constrained to operate on the - * elements in their encounter order; if the source of a stream is a {@code List} - * containing {@code [1, 2, 3]}, then the result of executing {@code map(x -> x*2)} - * must be {@code [2, 4, 6]}. However, if the source has no defined encounter - * order, than any of the six permutations of the values {@code [2, 4, 6]} would - * be a valid result. Many operations can still be efficiently parallelized even - * under ordering constraints. - * - *

    For sequential streams, ordering is only relevant to the determinism - * of operations performed repeatedly on the same source. (An {@code ArrayList} - * is constrained to iterate elements in order; a {@code HashSet} is not, and - * repeated iteration might produce a different order.) - * - *

    For parallel streams, relaxing the ordering constraint can enable - * optimized implementation for some operations. For example, duplicate - * filtration on an ordered stream must completely process the first partition - * before it can return any elements from a subsequent partition, even if those - * elements are available earlier. On the other hand, without the constraint of - * ordering, duplicate filtration can be done more efficiently by using - * a shared {@code ConcurrentHashSet}. There will be cases where the stream - * is structurally ordered (the source is ordered and the intermediate - * operations are order-preserving), but the user does not particularly care - * about the encounter order. In some cases, explicitly de-ordering the stream - * with the {@link java.util.stream.Stream#unordered()} method may result in - * improved parallel performance for some stateful or terminal operations. + *

    Most stream operations accept parameters that describe user-specified + * behavior, which are often lambda expressions. To preserve correct behavior, + * these behavioral parameters must be non-interfering, and in + * most cases must be stateless. Such parameters are always instances + * of a functional interface such + * as {@link java.util.function.Function}, and are often lambda expressions or + * method references. * *

    Non-interference

    * - * The {@code java.util.stream} package enables you to execute possibly-parallel - * bulk-data operations over a variety of data sources, including even non-thread-safe - * collections such as {@code ArrayList}. This is possible only if we can - * prevent interference with the data source during the execution of a - * stream pipeline. (Execution begins when the terminal operation is invoked, and ends - * when the terminal operation completes.) For most data sources, preventing interference - * means ensuring that the data source is not modified at all during the execution - * of the stream pipeline. (Some data sources, such as concurrent collections, are - * specifically designed to handle concurrent modification.) + * Streams enable you to execute possibly-parallel aggregate operations over a + * variety of data sources, including even non-thread-safe collections such as + * {@code ArrayList}. This is possible only if we can prevent + * interference with the data source during the execution of a stream + * pipeline. Except for the escape-hatch operations {@code iterator()} and + * {@code spliterator()}, execution begins when the terminal operation is + * invoked, and ends when the terminal operation completes. For most data + * sources, preventing interference means ensuring that the data source is + * not modified at all during the execution of the stream pipeline. + * The notable exception to this are streams whose sources are concurrent + * collections, which are specifically designed to handle concurrent modification. * - *

    Accordingly, lambda expressions (or other objects implementing the appropriate functional - * interface) passed to stream methods should never modify the stream's data source. An - * implementation is said to interfere with the data source if it modifies, or causes - * to be modified, the stream's data source. The need for non-interference applies to all - * pipelines, not just parallel ones. Unless the stream source is concurrent, modifying a - * stream's data source during execution of a stream pipeline can cause exceptions, incorrect - * answers, or nonconformant results. + *

    Accordingly, behavioral parameters passed to stream methods should never + * modify the stream's data source. An implementation is said to + * interfere with the data source if it modifies, or causes to be + * modified, the stream's data source. The need for non-interference applies + * to all pipelines, not just parallel ones. Unless the stream source is + * concurrent, modifying a stream's data source during execution of a stream + * pipeline can cause exceptions, incorrect answers, or nonconformant behavior. + * + *

    Results may be nondeterministic or incorrect if the behavioral + * parameters of stream operations are stateful. A stateful lambda + * (or other object implementing the appropriate functional interface) is one + * whose result depends on any state which might change during the execution + * of the stream pipeline. An example of a stateful lambda is: * - *

    Further, results may be nondeterministic or incorrect if the lambda expressions passed to - * stream operations are stateful. A stateful lambda (or other object implementing the - * appropriate functional interface) is one whose result depends on any state which might change - * during the execution of the stream pipeline. An example of a stateful lambda is: *

    {@code
      *     Set seen = Collections.synchronizedSet(new HashSet<>());
      *     stream.parallel().map(e -> { if (seen.add(e)) return 0; else return e; })...
      * }
    - * Here, if the mapping operation is performed in parallel, the results for the same input - * could vary from run to run, due to thread scheduling differences, whereas, with a stateless - * lambda expression the results would always be the same. + * + * Here, if the mapping operation is performed in parallel, the results for the + * same input could vary from run to run, due to thread scheduling differences, + * whereas, with a stateless lambda expression the results would always be the + * same. + * + * For well-behaved stream sources, the source can be modified before the + * terminal operation commences and those modifications will be reflected in + * the covered elements. For example, consider the following code: + * + *
    {@code
    + *     List l = new ArrayList(Arrays.asList("one", "two"));
    + *     Stream sl = l.stream();
    + *     l.add("three");
    + *     String s = sl.collect(joining(" "));
    + * }
    + * + * First a list is created consisting of two strings: "one"; and "two". Then a + * stream is created from that list. Next the list is modified by adding a third + * string: "three". Finally the elements of the stream are collected and joined + * together. Since the list was modified before the terminal {@code collect} + * operation commenced the result will be a string of "one two three". All the + * streams returned from JDK collections, and most other JDK classes, + * are well-behaved in this manner; for streams generated by other libraries, see + * Low-level stream + * construction for requirements for building well-behaved streams. + * + *

    Some streams, particularly those whose stream sources are concurrent, can + * tolerate concurrent modification during execution of a stream pipeline. + * However, in no case -- even if the stream source is concurrent -- should + * behavioral parameters to stream operations modify the stream source. Modifying + * the stream source from within the stream source may cause pipeline execution + * to fail to terminate, produce inaccurate results, or throw exceptions. + * The following example shows inappropriate interference with the source: + *

    {@code
    + *     // Don't do this!
    + *     List l = new ArrayList(Arrays.asList("one", "two"));
    + *     Stream sl = l.stream();
    + *     String s = sl.peek(s -> l.add("BAD LAMBDA")).collect(joining(" "));
    + * }
    * *

    Side-effects

    * + * Side-effects in behavioral parameters to stream operations are, in general, + * discouraged, as they can often lead to unwitting violations of the + * statelessness requirement, as well as other thread-safety hazards. Many + * computations where one might be tempted to use side effects can be more + * safely and efficiently expressed without side-effects, such as using + * reduction instead of mutable + * accumulators. However, side-effects such as using {@code println()} for debugging + * purposes are usually harmless. A small number of stream operations, such as + * {@code forEach()} and {@code peek()}, can operate only via side-effects; + * these should be used with care. + * + *

    As an example of how to transform a stream pipeline that inappropriately + * uses side-effects to one that does not, the following code searches a stream + * of strings for those matching a given regular expression, and puts the + * matches in a list. + * + *

    {@code
    + *     ArrayList results = new ArrayList<>();
    + *     stream.filter(s -> pattern.matcher(s).matches())
    + *           .forEach(s -> results.add(s));  // Unnecessary use of side-effects!
    + * }
    + * + * This code unnecessarily uses side-effects. If executed in parallel, the + * non-thread-safety of {@code ArrayList} would cause incorrect results, and + * adding needed synchronization would cause contention, undermining the + * benefit of parallelism. Furthermore, using side-effects here is completely + * unnecessary; the {@code forEach()} can simply be replaced with a reduction + * operation that is safer, more efficient, and more amenable to + * parallelization: + * + *
    {@code
    + *     Listresults =
    + *         stream.filter(s -> pattern.matcher(s).matches())
    + *               .collect(Collectors.toList());  // No side-effects!
    + * }
    + * + *

    Ordering

    + * + *

    Streams may or may not have a defined encounter order. Whether + * or not a stream has an encounter order depends on the source and the + * intermediate operations. Certain stream sources (such as {@code List} or + * arrays) are intrinsically ordered, whereas others (such as {@code HashSet}) + * are not. Some intermediate operations, such as {@code sorted()}, may impose + * an encounter order on an otherwise unordered stream, and others may render an + * ordered stream unordered, such as {@link java.util.stream.BaseStream#unordered()}. + * Further, some terminal operations may ignore encounter order, such as + * {@code forEach()}. + * + *

    If a stream is ordered, most operations are constrained to operate on the + * elements in their encounter order; if the source of a stream is a {@code List} + * containing {@code [1, 2, 3]}, then the result of executing {@code map(x -> x*2)} + * must be {@code [2, 4, 6]}. However, if the source has no defined encounter + * order, then any permutation of the values {@code [2, 4, 6]} would be a valid + * result. + * + *

    For sequential streams, the presence or absence of an encounter order does + * not affect performance, only determinism. If a stream is ordered, repeated + * execution of identical stream pipelines on an identical source will produce + * an identical result; if it is not ordered, repeated execution might produce + * different results. + * + *

    For parallel streams, relaxing the ordering constraint can sometimes enable + * more efficient execution. Certain aggregate operations, + * such as filtering duplicates ({@code distinct()}) or grouped reductions + * ({@code Collectors.groupingBy()}) can be implemented more efficiently if ordering of elements + * is not relevant. Similarly, operations that are intrinsically tied to encounter order, + * such as {@code limit()}, may require + * buffering to ensure proper ordering, undermining the benefit of parallelism. + * In cases where the stream has an encounter order, but the user does not + * particularly care about that encounter order, explicitly de-ordering + * the stream with {@link java.util.stream.BaseStream#unordered() unordered()} may + * improve parallel performance for some stateful or terminal operations. + * However, most stream pipelines, such as the "sum of weight of blocks" example + * above, still parallelize efficiently even under ordering constraints. + * *

    Reduction operations

    * - * A reduction operation takes a stream of elements and processes them in a way - * that reduces to a single value or summary description, such as finding the sum or maximum - * of a set of numbers. (In more complex scenarios, the reduction operation might need to - * extract data from the elements before reducing that data to a single value, such as - * finding the sum of weights of a set of blocks. This would require extracting the weight - * from each block before summing up the weights.) + * A reduction operation (also called a fold) takes a sequence + * of input elements and combines them into a single summary result by repeated + * application of a combining operation, such as finding the sum or maximum of + * a set of numbers, or accumulating elements into a list. The streams classes have + * multiple forms of general reduction operations, called + * {@link java.util.stream.Stream#reduce(java.util.function.BinaryOperator) reduce()} + * and {@link java.util.stream.Stream#collect(java.util.stream.Collector) collect()}, + * as well as multiple specialized reduction forms such as + * {@link java.util.stream.IntStream#sum() sum()}, {@link java.util.stream.IntStream#max() max()}, + * or {@link java.util.stream.IntStream#count() count()}. * - *

    Of course, such operations can be readily implemented as simple sequential loops, as in: + *

    Of course, such operations can be readily implemented as simple sequential + * loops, as in: *

    {@code
      *    int sum = 0;
      *    for (int x : numbers) {
      *       sum += x;
      *    }
      * }
    - * However, there may be a significant advantage to preferring a {@link java.util.stream.Stream#reduce reduce operation} - * over a mutative accumulation such as the above -- a properly constructed reduce operation is - * inherently parallelizable so long as the - * {@link java.util.function.BinaryOperator reduction operaterator} - * has the right characteristics. Specifically the operator must be - * associative. For example, given a - * stream of numbers for which we want to find the sum, we can write: + * However, there are good reasons to prefer a reduce operation + * over a mutative accumulation such as the above. Not only is a reduction + * "more abstract" -- it operates on the stream as a whole rather than individual + * elements -- but a properly constructed reduce operation is inherently + * parallelizable, so long as the function(s) used to process the elements + * are associative and + * stateless. + * For example, given a stream of numbers for which we want to find the sum, we + * can write: *
    {@code
    - *    int sum = numbers.reduce(0, (x,y) -> x+y);
    + *    int sum = numbers.stream().reduce(0, (x,y) -> x+y);
      * }
    - * or more succinctly: + * or: *
    {@code
    - *    int sum = numbers.reduce(0, Integer::sum);
    + *    int sum = numbers.stream().reduce(0, Integer::sum);
      * }
    * - *

    (The primitive specializations of {@link java.util.stream.Stream}, such as - * {@link java.util.stream.IntStream}, even have convenience methods for common reductions, - * such as {@link java.util.stream.IntStream#sum() sum} and {@link java.util.stream.IntStream#max() max}, - * which are implemented as simple wrappers around reduce.) - * - *

    Reduction parallellizes well since the implementation of {@code reduce} can operate on - * subsets of the stream in parallel, and then combine the intermediate results to get the final - * correct answer. Even if you were to use a parallelizable form of the - * {@link java.util.stream.Stream#forEach(Consumer) forEach()} method - * in place of the original for-each loop above, you would still have to provide thread-safe - * updates to the shared accumulating variable {@code sum}, and the required synchronization - * would likely eliminate any performance gain from parallelism. Using a {@code reduce} method - * instead removes all of the burden of parallelizing the reduction operation, and the library - * can provide an efficient parallel implementation with no additional synchronization needed. - * - *

    The "blocks" examples shown earlier shows how reduction combines with other operations - * to replace for loops with bulk operations. If {@code blocks} is a collection of {@code Block} - * objects, which have a {@code getWeight} method, we can find the heaviest block with: + *

    These reduction operations can run safely in parallel with almost no + * modification: *

    {@code
    - *     OptionalInt heaviest = blocks.stream()
    - *                                  .mapToInt(Block::getWeight)
    - *                                  .reduce(Integer::max);
    + *    int sum = numbers.parallelStream().reduce(0, Integer::sum);
      * }
    * - *

    In its more general form, a {@code reduce} operation on elements of type {@code } - * yielding a result of type {@code } requires three parameters: + *

    Reduction parallellizes well because the implementation + * can operate on subsets of the data in parallel, and then combine the + * intermediate results to get the final correct answer. (Even if the language + * had a "parallel for-each" construct, the mutative accumulation approach would + * still required the developer to provide + * thread-safe updates to the shared accumulating variable {@code sum}, and + * the required synchronization would then likely eliminate any performance gain from + * parallelism.) Using {@code reduce()} instead removes all of the + * burden of parallelizing the reduction operation, and the library can provide + * an efficient parallel implementation with no additional synchronization + * required. + * + *

    The "widgets" examples shown earlier shows how reduction combines with + * other operations to replace for loops with bulk operations. If {@code widgets} + * is a collection of {@code Widget} objects, which have a {@code getWeight} method, + * we can find the heaviest widget with: + *

    {@code
    + *     OptionalInt heaviest = widgets.parallelStream()
    + *                                   .mapToInt(Widget::getWeight)
    + *                                   .max();
    + * }
    + * + *

    In its more general form, a {@code reduce} operation on elements of type + * {@code } yielding a result of type {@code } requires three parameters: *

    {@code
      *  U reduce(U identity,
    - *              BiFunction accumlator,
    + *              BiFunction accumulator,
      *              BinaryOperator combiner);
      * }
    - * Here, the identity element is both an initial seed for the reduction, and a default - * result if there are no elements. The accumulator function takes a partial result and - * the next element, and produce a new partial result. The combiner function combines - * the partial results of two accumulators to produce a new partial result, and eventually the - * final result. + * Here, the identity element is both an initial seed value for the reduction + * and a default result if there are no input elements. The accumulator + * function takes a partial result and the next element, and produces a new + * partial result. The combiner function combines two partial results + * to produce a new partial result. (The combiner is necessary in parallel + * reductions, where the input is partitioned, a partial accumulation computed + * for each partition, and then the partial results are combined to produce a + * final result.) * - *

    This form is a generalization of the two-argument form, and is also a generalization of - * the map-reduce construct illustrated above. If we wanted to re-cast the simple {@code sum} - * example using the more general form, {@code 0} would be the identity element, while - * {@code Integer::sum} would be both the accumulator and combiner. For the sum-of-weights - * example, this could be re-cast as: + *

    More formally, the {@code identity} value must be an identity for + * the combiner function. This means that for all {@code u}, + * {@code combiner.apply(identity, u)} is equal to {@code u}. Additionally, the + * {@code combiner} function must be associative and + * must be compatible with the {@code accumulator} function: for all {@code u} + * and {@code t}, {@code combiner.apply(u, accumulator.apply(identity, t))} must + * be {@code equals()} to {@code accumulator.apply(u, t)}. + * + *

    The three-argument form is a generalization of the two-argument form, + * incorporating a mapping step into the accumulation step. We could + * re-cast the simple sum-of-weights example using the more general form as + * follows: *

    {@code
    - *     int sumOfWeights = blocks.stream().reduce(0,
    - *                                               (sum, b) -> sum + b.getWeight())
    - *                                               Integer::sum);
    + *     int sumOfWeights = widgets.stream()
    + *                               .reduce(0,
    + *                                       (sum, b) -> sum + b.getWeight())
    + *                                       Integer::sum);
      * }
    - * though the map-reduce form is more readable and generally preferable. The generalized form - * is provided for cases where significant work can be optimized away by combining mapping and - * reducing into a single function. + * though the explicit map-reduce form is more readable and therefore should + * usually be preferred. The generalized form is provided for cases where + * significant work can be optimized away by combining mapping and reducing + * into a single function. * - *

    More formally, the {@code identity} value must be an identity for the combiner - * function. This means that for all {@code u}, {@code combiner.apply(identity, u)} is equal - * to {@code u}. Additionally, the {@code combiner} function must be - * associative and must be compatible with the {@code accumulator} - * function; for all {@code u} and {@code t}, the following must hold: - *

    {@code
    - *     combiner.apply(u, accumulator.apply(identity, t)) == accumulator.apply(u, t)
    - * }
    + *

    Mutable reduction

    * - *

    Mutable Reduction

    - * - * A mutable reduction operation is similar to an ordinary reduction, in that it reduces - * a stream of values to a single value, but instead of producing a distinct single-valued result, it - * mutates a general result container, such as a {@code Collection} or {@code StringBuilder}, + * A mutable reduction operation accumulates input elements into a + * mutable result container, such as a {@code Collection} or {@code StringBuilder}, * as it processes the elements in the stream. * - *

    For example, if we wanted to take a stream of strings and concatenate them into a single - * long string, we could achieve this with ordinary reduction: + *

    If we wanted to take a stream of strings and concatenate them into a + * single long string, we could achieve this with ordinary reduction: *

    {@code
      *     String concatenated = strings.reduce("", String::concat)
      * }
    * - * We would get the desired result, and it would even work in parallel. However, we might not - * be happy about the performance! Such an implementation would do a great deal of string - * copying, and the run time would be O(n^2) in the number of elements. A more - * performant approach would be to accumulate the results into a {@link java.lang.StringBuilder}, which - * is a mutable container for accumulating strings. We can use the same technique to + *

    We would get the desired result, and it would even work in parallel. However, + * we might not be happy about the performance! Such an implementation would do + * a great deal of string copying, and the run time would be O(n^2) in + * the number of characters. A more performant approach would be to accumulate + * the results into a {@link java.lang.StringBuilder}, which is a mutable + * container for accumulating strings. We can use the same technique to * parallelize mutable reduction as we do with ordinary reduction. * - *

    The mutable reduction operation is called {@link java.util.stream.Stream#collect(Collector) collect()}, as it - * collects together the desired results into a result container such as {@code StringBuilder}. - * A {@code collect} operation requires three things: a factory function which will construct - * new instances of the result container, an accumulating function that will update a result - * container by incorporating a new element, and a combining function that can take two - * result containers and merge their contents. The form of this is very similar to the general + *

    The mutable reduction operation is called + * {@link java.util.stream.Stream#collect(Collector) collect()}, + * as it collects together the desired results into a result container such + * as a {@code Collection}. + * A {@code collect} operation requires three functions: + * a factory function to construct new instances of the result container, an + * accumulator function to incorporate an input element into a result + * container, and a combining function to merge the contents of one result + * container into another. The form of this is very similar to the general * form of ordinary reduction: *

    {@code
      *  R collect(Supplier resultFactory,
      *               BiConsumer accumulator,
      *               BiConsumer combiner);
      * }
    - * As with {@code reduce()}, the benefit of expressing {@code collect} in this abstract way is - * that it is directly amenable to parallelization: we can accumulate partial results in parallel - * and then combine them. For example, to collect the String representations of the elements - * in a stream into an {@code ArrayList}, we could write the obvious sequential for-each form: + *

    As with {@code reduce()}, a benefit of expressing {@code collect} in this + * abstract way is that it is directly amenable to parallelization: we can + * accumulate partial results in parallel and then combine them, so long as the + * accumulation and combining functions satisfy the appropriate requirements. + * For example, to collect the String representations of the elements in a + * stream into an {@code ArrayList}, we could write the obvious sequential + * for-each form: *

    {@code
      *     ArrayList strings = new ArrayList<>();
      *     for (T element : stream) {
    @@ -377,92 +514,107 @@
      *                                                (c, e) -> c.add(e.toString()),
      *                                                (c1, c2) -> c1.addAll(c2));
      * }
    - * or, noting that we have buried a mapping operation inside the accumulator function, more - * succinctly as: + * or, pulling the mapping operation out of the accumulator function, we could + * express it more succinctly as: *
    {@code
    - *     ArrayList strings = stream.map(Object::toString)
    - *                                       .collect(ArrayList::new, ArrayList::add, ArrayList::addAll);
    + *     List strings = stream.map(Object::toString)
    + *                                  .collect(ArrayList::new, ArrayList::add, ArrayList::addAll);
      * }
    - * Here, our supplier is just the {@link java.util.ArrayList#ArrayList() ArrayList constructor}, the - * accumulator adds the stringified element to an {@code ArrayList}, and the combiner simply - * uses {@link java.util.ArrayList#addAll addAll} to copy the strings from one container into the other. + * Here, our supplier is just the {@link java.util.ArrayList#ArrayList() + * ArrayList constructor}, the accumulator adds the stringified element to an + * {@code ArrayList}, and the combiner simply uses {@link java.util.ArrayList#addAll addAll} + * to copy the strings from one container into the other. * - *

    As with the regular reduction operation, the ability to parallelize only comes if an - * associativity condition is met. The {@code combiner} is associative - * if for result containers {@code r1}, {@code r2}, and {@code r3}: + *

    The three aspects of {@code collect} -- supplier, accumulator, and combiner -- + * are tightly coupled. We can use the abstraction of + * of a {@link java.util.stream.Collector} to capture all three aspects. + * The above example for collecting strings into a {@code List} can be rewritten + * using a standard {@code Collector} as: *

    {@code
    - *    combiner.accept(r1, r2);
    - *    combiner.accept(r1, r3);
    - * }
    - * is equivalent to - *
    {@code
    - *    combiner.accept(r2, r3);
    - *    combiner.accept(r1, r2);
    - * }
    - * where equivalence means that {@code r1} is left in the same state (according to the meaning - * of {@link java.lang.Object#equals equals} for the element types). Similarly, the {@code resultFactory} - * must act as an identity with respect to the {@code combiner} so that for any result - * container {@code r}: - *
    {@code
    - *     combiner.accept(r, resultFactory.get());
    - * }
    - * does not modify the state of {@code r} (again according to the meaning of - * {@link java.lang.Object#equals equals}). Finally, the {@code accumulator} and {@code combiner} must be - * compatible such that for a result container {@code r} and element {@code t}: - *
    {@code
    - *    r2 = resultFactory.get();
    - *    accumulator.accept(r2, t);
    - *    combiner.accept(r, r2);
    - * }
    - * is equivalent to: - *
    {@code
    - *    accumulator.accept(r,t);
    - * }
    - * where equivalence means that {@code r} is left in the same state (again according to the - * meaning of {@link java.lang.Object#equals equals}). - * - *

    The three aspects of {@code collect}: supplier, accumulator, and combiner, are often very - * tightly coupled, and it is convenient to introduce the notion of a {@link java.util.stream.Collector} as - * being an object that embodies all three aspects. There is a {@link java.util.stream.Stream#collect(Collector) collect} - * method that simply takes a {@code Collector} and returns the resulting container. - * The above example for collecting strings into a {@code List} can be rewritten using a - * standard {@code Collector} as: - *

    {@code
    - *     ArrayList strings = stream.map(Object::toString)
    - *                                       .collect(Collectors.toList());
    + *     List strings = stream.map(Object::toString)
    + *                                  .collect(Collectors.toList());
      * }
    * - *

    Reduction, Concurrency, and Ordering

    + *

    Packaging mutable reductions into a Collector has another advantage: + * composability. The class {@link java.util.stream.Collectors} contains a + * number of predefined factories for collectors, including combinators + * that transform one collector into another. For example, suppose we have a + * collector that computes the sum of the salaries of a stream of + * employees, as follows: * - * With some complex reduction operations, for example a collect that produces a - * {@code Map}, such as: + *

    {@code
    + *     Collector summingSalaries
    + *         = Collectors.summingInt(Employee::getSalary);
    + * } 
    + * + * (The {@code ?} for the second type parameter merely indicates that we don't + * care about the intermediate representation used by this collector.) + * If we wanted to create a collector to tabulate the sum of salaries by + * department, we could reuse {@code summingSalaries} using + * {@link java.util.stream.Collectors#groupingBy(java.util.function.Function, java.util.stream.Collector) groupingBy}: + * + *
    {@code
    + *     Map salariesByDept
    + *         = employees.stream().collect(Collectors.groupingBy(Employee::getDepartment,
    + *                                                            summingSalaries));
    + * } 
    + * + *

    As with the regular reduction operation, {@code collect()} operations can + * only be parallelized if appropriate conditions are met. For any partially accumulated result, + * combining it with an empty result container must produce an equivalent + * result. That is, for a partially accumulated result {@code p} that is the + * result of any series of accumulator and combiner invocations, {@code p} must + * be equivalent to {@code combiner.apply(p, supplier.get())}. + * + *

    Further, however the computation is split, it must produce an equivalent + * result. For any input elements {@code t1} and {@code t2}, the results + * {@code r1} and {@code r2} in the computation below must be equivalent: + *

    {@code
    + *     A a1 = supplier.get();
    + *     accumulator.accept(a1, t1);
    + *     accumulator.accept(a1, t2);
    + *     R r1 = finisher.apply(a1);  // result without splitting
    + *
    + *     A a2 = supplier.get();
    + *     accumulator.accept(a2, t1);
    + *     A a3 = supplier.get();
    + *     accumulator.accept(a3, t2);
    + *     R r2 = finisher.apply(combiner.apply(a2, a3));  // result with splitting
    + * } 
    + * + *

    Here, equivalence generally means according to {@link java.lang.Object#equals(Object)}. + * but in some cases equivalence may be relaxed to account for differences in + * order. + * + *

    Reduction, concurrency, and ordering

    + * + * With some complex reduction operations, for example a {@code collect()} that + * produces a {@code Map}, such as: *
    {@code
      *     Map> salesByBuyer
      *         = txns.parallelStream()
      *               .collect(Collectors.groupingBy(Transaction::getBuyer));
      * }
    - * (where {@link java.util.stream.Collectors#groupingBy} is a utility function - * that returns a {@link java.util.stream.Collector} for grouping sets of elements based on some key) * it may actually be counterproductive to perform the operation in parallel. * This is because the combining step (merging one {@code Map} into another by key) * can be expensive for some {@code Map} implementations. * *

    Suppose, however, that the result container used in this reduction * was a concurrently modifiable collection -- such as a - * {@link java.util.concurrent.ConcurrentHashMap ConcurrentHashMap}. In that case, - * the parallel invocations of the accumulator could actually deposit their results - * concurrently into the same shared result container, eliminating the need for the combiner to - * merge distinct result containers. This potentially provides a boost - * to the parallel execution performance. We call this a concurrent reduction. + * {@link java.util.concurrent.ConcurrentHashMap}. In that case, the parallel + * invocations of the accumulator could actually deposit their results + * concurrently into the same shared result container, eliminating the need for + * the combiner to merge distinct result containers. This potentially provides + * a boost to the parallel execution performance. We call this a concurrent + * reduction. * - *

    A {@link java.util.stream.Collector} that supports concurrent reduction is marked with the - * {@link java.util.stream.Collector.Characteristics#CONCURRENT} characteristic. - * Having a concurrent collector is a necessary condition for performing a - * concurrent reduction, but that alone is not sufficient. If you imagine multiple - * accumulators depositing results into a shared container, the order in which - * results are deposited is non-deterministic. Consequently, a concurrent reduction - * is only possible if ordering is not important for the stream being processed. - * The {@link java.util.stream.Stream#collect(Collector)} + *

    A {@link java.util.stream.Collector} that supports concurrent reduction is + * marked with the {@link java.util.stream.Collector.Characteristics#CONCURRENT} + * characteristic. However, a concurrent collection also has a downside. If + * multiple threads are depositing results concurrently into a shared container, + * the order in which results are deposited is non-deterministic. Consequently, + * a concurrent reduction is only possible if ordering is not important for the + * stream being processed. The {@link java.util.stream.Stream#collect(Collector)} * implementation will only perform a concurrent reduction if *

      *
    • The stream is parallel;
    • @@ -472,15 +624,16 @@ *
    • Either the stream is unordered, or the collector has the * {@link java.util.stream.Collector.Characteristics#UNORDERED} characteristic. *
    - * For example: + * You can ensure the stream is unordered by using the + * {@link java.util.stream.BaseStream#unordered()} method. For example: *
    {@code
      *     Map> salesByBuyer
      *         = txns.parallelStream()
      *               .unordered()
      *               .collect(groupingByConcurrent(Transaction::getBuyer));
      * }
    - * (where {@link java.util.stream.Collectors#groupingByConcurrent} is the concurrent companion - * to {@code groupingBy}). + * (where {@link java.util.stream.Collectors#groupingByConcurrent} is the + * concurrent equivalent of {@code groupingBy}). * *

    Note that if it is important that the elements for a given key appear in the * order they appear in the source, then we cannot use a concurrent reduction, @@ -488,79 +641,77 @@ * be constrained to implement either a sequential reduction or a merge-based * parallel reduction. * - *

    Associativity

    + *

    Associativity

    * - * An operator or function {@code op} is associative if the following holds: + * An operator or function {@code op} is associative if the following + * holds: *
    {@code
      *     (a op b) op c == a op (b op c)
      * }
    - * The importance of this to parallel evaluation can be seen if we expand this to four terms: + * The importance of this to parallel evaluation can be seen if we expand this + * to four terms: *
    {@code
      *     a op b op c op d == (a op b) op (c op d)
      * }
    - * So we can evaluate {@code (a op b)} in parallel with {@code (c op d)} and then invoke {@code op} on - * the results. - * TODO what does associative mean for mutative combining functions? - * FIXME: we described mutative associativity above. + * So we can evaluate {@code (a op b)} in parallel with {@code (c op d)}, and + * then invoke {@code op} on the results. * - *

    Stream sources

    - * TODO where does this section go? + *

    Examples of associative operations include numeric addition, min, and max, + * and string concatenation. * - * XXX - change to section to stream construction gradually introducing more - * complex ways to construct - * - construction from Collection - * - construction from Iterator - * - construction from array - * - construction from generators - * - construction from spliterator + *

    Low-level stream construction

    * - * XXX - the following is quite low-level but important aspect of stream constriction + * So far, all the stream examples have used methods like + * {@link java.util.Collection#stream()} or {@link java.util.Arrays#stream(Object[])} + * to obtain a stream. How are those stream-bearing methods implemented? * - *

    A pipeline is initially constructed from a spliterator (see {@link java.util.Spliterator}) supplied by a stream source. - * The spliterator covers elements of the source and provides element traversal operations - * for a possibly-parallel computation. See methods on {@link java.util.stream.Streams} for construction - * of pipelines using spliterators. + *

    The class {@link java.util.stream.StreamSupport} has a number of low-level + * methods for creating a stream, all using some form of a {@link java.util.Spliterator}. + * A spliterator is the parallel analogue of an {@link java.util.Iterator}; it + * describes a (possibly infinite) collection of elements, with support for + * sequentially advancing, bulk traversal, and splitting off some portion of the + * input into another spliterator which can be processed in parallel. At the + * lowest level, all streams are driven by a spliterator. * - *

    A source may directly supply a spliterator. If so, the spliterator is traversed, split, or queried - * for estimated size after, and never before, the terminal operation commences. It is strongly recommended - * that the spliterator report a characteristic of {@code IMMUTABLE} or {@code CONCURRENT}, or be - * late-binding and not bind to the elements it covers until traversed, split or queried for - * estimated size. + *

    There are a number of implementation choices in implementing a spliterator, + * nearly all of which are tradeoffs between simplicity of implementation and + * runtime performance of streams using that spliterator. The simplest, but + * least performant, way to create a spliterator is to create one from an iterator + * using {@link java.util.Spliterators#spliteratorUnknownSize(java.util.Iterator, int)}. + * While such a spliterator will work, it will likely offer poor parallel + * performance, since we have lost sizing information (how big is the underlying + * data set), as well as being constrained to a simplistic splitting algorithm. * - *

    If a source cannot directly supply a recommended spliterator then it may indirectly supply a spliterator - * using a {@code Supplier}. The spliterator is obtained from the supplier after, and never before, the terminal + *

    A higher-quality spliterator will provide balanced and known-size splits, + * accurate sizing information, and a number of other + * {@link java.util.Spliterator#characteristics() characteristics} of the + * spliterator or data that can be used by implementations to optimize + * execution. + * + *

    Spliterators for mutable data sources have an additional challenge; timing + * of binding to the data, since the data could change between the time the + * spliterator is created and the time the stream pipeline is executed. Ideally, + * a spliterator for a stream would report a characteristic of {@code IMMUTABLE} + * or {@code CONCURRENT}; if not it should be late-binding. + * If a source cannot directly supply a recommended spliterator, it may + * indirectly supply a spliterator using a {@code Supplier}, and construct a + * stream via the {@code Supplier}-accepting versions of + * {@link java.util.stream.StreamSupport#stream(Supplier, int, boolean) stream()}. + * The spliterator is obtained from the supplier only after the terminal * operation of the stream pipeline commences. * - *

    Such requirements significantly reduce the scope of potential interference to the interval starting - * with the commencing of the terminal operation and ending with the producing a result or side-effect. See - * Non-Interference for - * more details. + *

    These requirements significantly reduce the scope of potential interference + * between mutations of the stream source and execution of stream pipelines. + * Streams based on spliterators with the desired characteristics, or those using + * the Supplier-based factory forms, are immune to modifications of the data + * source prior to commencement of the terminal operation (provided the behavioral + * parameters to the stream operations meet the required criteria for non-interference + * and statelessness). See Non-Interference + * for more details. * - * XXX - move the following to the non-interference section - * - *

    A source can be modified before the terminal operation commences and those modifications will be reflected in - * the covered elements. Afterwards, and depending on the properties of the source, further modifications - * might not be reflected and the throwing of a {@code ConcurrentModificationException} may occur. - * - *

    For example, consider the following code: - *

    {@code
    - *     List l = new ArrayList(Arrays.asList("one", "two"));
    - *     Stream sl = l.stream();
    - *     l.add("three");
    - *     String s = sl.collect(joining(" "));
    - * }
    - * First a list is created consisting of two strings: "one"; and "two". Then a stream is created from that list. - * Next the list is modified by adding a third string: "three". Finally the elements of the stream are collected - * and joined together. Since the list was modified before the terminal {@code collect} operation commenced - * the result will be a string of "one two three". However, if the list is modified after the terminal operation - * commences, as in: - *
    {@code
    - *     List l = new ArrayList(Arrays.asList("one", "two"));
    - *     Stream sl = l.stream();
    - *     String s = sl.peek(s -> l.add("BAD LAMBDA")).collect(joining(" "));
    - * }
    - * then a {@code ConcurrentModificationException} will be thrown since the {@code peek} operation will attempt - * to add the string "BAD LAMBDA" to the list after the terminal operation has commenced. + * @since 1.8 */ - package java.util.stream; + +import java.util.function.BinaryOperator; +import java.util.function.UnaryOperator; From 28d455529e7bc76985029e762442edd824125e10 Mon Sep 17 00:00:00 2001 From: Dmitry Nadezhin Date: Wed, 11 Sep 2013 17:07:35 -0700 Subject: [PATCH 071/210] 8010430: Math.round has surprising behavior for odd values of ulp 1 If the effective floating point exponent is zero return the significand including the implicit 1-bit. Reviewed-by: bpb, darcy, gls --- jdk/src/share/classes/java/lang/Math.java | 66 ++++++++++++++--- .../share/classes/java/lang/StrictMath.java | 4 +- jdk/test/java/lang/Math/RoundTests.java | 71 ++++++++++++++++++- 3 files changed, 126 insertions(+), 15 deletions(-) diff --git a/jdk/src/share/classes/java/lang/Math.java b/jdk/src/share/classes/java/lang/Math.java index ae83e4265ad..98e901ac942 100644 --- a/jdk/src/share/classes/java/lang/Math.java +++ b/jdk/src/share/classes/java/lang/Math.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1994, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1994, 2013, 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 @@ -646,7 +646,7 @@ public final class Math { /** * Returns the closest {@code int} to the argument, with ties - * rounding up. + * rounding to positive infinity. * *

    * Special cases: @@ -665,15 +665,37 @@ public final class Math { * @see java.lang.Integer#MIN_VALUE */ public static int round(float a) { - if (a != 0x1.fffffep-2f) // greatest float value less than 0.5 - return (int)floor(a + 0.5f); - else - return 0; + int intBits = Float.floatToRawIntBits(a); + int biasedExp = (intBits & FloatConsts.EXP_BIT_MASK) + >> (FloatConsts.SIGNIFICAND_WIDTH - 1); + int shift = (FloatConsts.SIGNIFICAND_WIDTH - 2 + + FloatConsts.EXP_BIAS) - biasedExp; + if ((shift & -32) == 0) { // shift >= 0 && shift < 32 + // a is a finite number such that pow(2,-32) <= ulp(a) < 1 + int r = ((intBits & FloatConsts.SIGNIF_BIT_MASK) + | (FloatConsts.SIGNIF_BIT_MASK + 1)); + if (intBits < 0) { + r = -r; + } + // In the comments below each Java expression evaluates to the value + // the corresponding mathematical expression: + // (r) evaluates to a / ulp(a) + // (r >> shift) evaluates to floor(a * 2) + // ((r >> shift) + 1) evaluates to floor((a + 1/2) * 2) + // (((r >> shift) + 1) >> 1) evaluates to floor(a + 1/2) + return ((r >> shift) + 1) >> 1; + } else { + // a is either + // - a finite number with abs(a) < exp(2,FloatConsts.SIGNIFICAND_WIDTH-32) < 1/2 + // - a finite number with ulp(a) >= 1 and hence a is a mathematical integer + // - an infinity or NaN + return (int) a; + } } /** * Returns the closest {@code long} to the argument, with ties - * rounding up. + * rounding to positive infinity. * *

    Special cases: *

    • If the argument is NaN, the result is 0. @@ -692,10 +714,32 @@ public final class Math { * @see java.lang.Long#MIN_VALUE */ public static long round(double a) { - if (a != 0x1.fffffffffffffp-2) // greatest double value less than 0.5 - return (long)floor(a + 0.5d); - else - return 0; + long longBits = Double.doubleToRawLongBits(a); + long biasedExp = (longBits & DoubleConsts.EXP_BIT_MASK) + >> (DoubleConsts.SIGNIFICAND_WIDTH - 1); + long shift = (DoubleConsts.SIGNIFICAND_WIDTH - 2 + + DoubleConsts.EXP_BIAS) - biasedExp; + if ((shift & -64) == 0) { // shift >= 0 && shift < 64 + // a is a finite number such that pow(2,-64) <= ulp(a) < 1 + long r = ((longBits & DoubleConsts.SIGNIF_BIT_MASK) + | (DoubleConsts.SIGNIF_BIT_MASK + 1)); + if (longBits < 0) { + r = -r; + } + // In the comments below each Java expression evaluates to the value + // the corresponding mathematical expression: + // (r) evaluates to a / ulp(a) + // (r >> shift) evaluates to floor(a * 2) + // ((r >> shift) + 1) evaluates to floor((a + 1/2) * 2) + // (((r >> shift) + 1) >> 1) evaluates to floor(a + 1/2) + return ((r >> shift) + 1) >> 1; + } else { + // a is either + // - a finite number with abs(a) < exp(2,DoubleConsts.SIGNIFICAND_WIDTH-64) < 1/2 + // - a finite number with ulp(a) >= 1 and hence a is a mathematical integer + // - an infinity or NaN + return (long) a; + } } private static final class RandomNumberGeneratorHolder { diff --git a/jdk/src/share/classes/java/lang/StrictMath.java b/jdk/src/share/classes/java/lang/StrictMath.java index 52336484e75..ae4af2bcac8 100644 --- a/jdk/src/share/classes/java/lang/StrictMath.java +++ b/jdk/src/share/classes/java/lang/StrictMath.java @@ -633,7 +633,7 @@ public final class StrictMath { /** * Returns the closest {@code int} to the argument, with ties - * rounding up. + * rounding to positive infinity. * *

      Special cases: *

      • If the argument is NaN, the result is 0. @@ -656,7 +656,7 @@ public final class StrictMath { /** * Returns the closest {@code long} to the argument, with ties - * rounding up. + * rounding to positive infinity. * *

        Special cases: *

        • If the argument is NaN, the result is 0. diff --git a/jdk/test/java/lang/Math/RoundTests.java b/jdk/test/java/lang/Math/RoundTests.java index 9994e97df85..cae190f9770 100644 --- a/jdk/test/java/lang/Math/RoundTests.java +++ b/jdk/test/java/lang/Math/RoundTests.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2013, 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 6430675 + * @bug 6430675 8010430 * @summary Check for correct implementation of {Math, StrictMath}.round */ public class RoundTests { @@ -32,6 +32,8 @@ public class RoundTests { failures += testNearFloatHalfCases(); failures += testNearDoubleHalfCases(); + failures += testUnityULPCases(); + failures += testSpecialCases(); if (failures > 0) { System.err.println("Testing {Math, StrictMath}.round incurred " @@ -95,4 +97,69 @@ public class RoundTests { return failures; } + + private static int testUnityULPCases() { + int failures = 0; + for (float sign : new float[]{-1, 1}) { + for (float v1 : new float[]{1 << 23, 1 << 24}) { + for (int k = -5; k <= 5; k++) { + float value = (v1 + k) * sign; + float actual = Math.round(value); + failures += Tests.test("Math.round", value, actual, value); + } + } + } + + if (failures != 0) { + System.out.println(); + } + + for (double sign : new double[]{-1, 1}) { + for (double v1 : new double[]{1L << 52, 1L << 53}) { + for (int k = -5; k <= 5; k++) { + double value = (v1 + k) * sign; + double actual = Math.round(value); + failures += Tests.test("Math.round", value, actual, value); + } + } + } + + return failures; + } + + private static int testSpecialCases() { + int failures = 0; + + failures += Tests.test("Math.round", Float.NaN, Math.round(Float.NaN), 0.0F); + failures += Tests.test("Math.round", Float.POSITIVE_INFINITY, + Math.round(Float.POSITIVE_INFINITY), Integer.MAX_VALUE); + failures += Tests.test("Math.round", Float.NEGATIVE_INFINITY, + Math.round(Float.NEGATIVE_INFINITY), Integer.MIN_VALUE); + failures += Tests.test("Math.round", -(float)Integer.MIN_VALUE, + Math.round(-(float)Integer.MIN_VALUE), Integer.MAX_VALUE); + failures += Tests.test("Math.round", (float) Integer.MIN_VALUE, + Math.round((float) Integer.MIN_VALUE), Integer.MIN_VALUE); + failures += Tests.test("Math.round", 0F, Math.round(0F), 0.0F); + failures += Tests.test("Math.round", Float.MIN_VALUE, + Math.round(Float.MIN_VALUE), 0.0F); + failures += Tests.test("Math.round", -Float.MIN_VALUE, + Math.round(-Float.MIN_VALUE), 0.0F); + + failures += Tests.test("Math.round", Double.NaN, Math.round(Double.NaN), 0.0); + failures += Tests.test("Math.round", Double.POSITIVE_INFINITY, + Math.round(Double.POSITIVE_INFINITY), Long.MAX_VALUE); + failures += Tests.test("Math.round", Double.NEGATIVE_INFINITY, + Math.round(Double.NEGATIVE_INFINITY), Long.MIN_VALUE); + failures += Tests.test("Math.round", -(double)Long.MIN_VALUE, + Math.round(-(double)Long.MIN_VALUE), Long.MAX_VALUE); + failures += Tests.test("Math.round", (double) Long.MIN_VALUE, + Math.round((double) Long.MIN_VALUE), Long.MIN_VALUE); + failures += Tests.test("Math.round", 0, Math.round(0), 0.0); + failures += Tests.test("Math.round", Double.MIN_VALUE, + Math.round(Double.MIN_VALUE), 0.0); + failures += Tests.test("Math.round", -Double.MIN_VALUE, + Math.round(-Double.MIN_VALUE), 0.0); + + return failures; + } } From f6e4c46294b1a9df3f613bd4f14d6a6fc6b7c30f Mon Sep 17 00:00:00 2001 From: Shanliang Jiang Date: Fri, 13 Sep 2013 10:48:12 +0200 Subject: [PATCH 072/210] 8023669: MBean*Info.hashCode : NPE Reviewed-by: dholmes, dfuchs, jbachorik --- .../javax/management/MBeanAttributeInfo.java | 3 +- .../management/MBeanConstructorInfo.java | 7 +- .../classes/javax/management/MBeanInfo.java | 20 +- .../javax/management/MBeanOperationInfo.java | 3 +- .../javax/management/MBeanParameterInfo.java | 3 +- .../MBeanInfo/MBeanInfoHashCodeNPETest.java | 176 ++++++++++++++++++ 6 files changed, 190 insertions(+), 22 deletions(-) create mode 100644 jdk/test/javax/management/MBeanInfo/MBeanInfoHashCodeNPETest.java diff --git a/jdk/src/share/classes/javax/management/MBeanAttributeInfo.java b/jdk/src/share/classes/javax/management/MBeanAttributeInfo.java index d99b9f7b8ad..a70fb3a3571 100644 --- a/jdk/src/share/classes/javax/management/MBeanAttributeInfo.java +++ b/jdk/src/share/classes/javax/management/MBeanAttributeInfo.java @@ -30,6 +30,7 @@ import java.security.AccessController; import com.sun.jmx.mbeanserver.GetPropertyAction; import com.sun.jmx.mbeanserver.Introspector; +import java.util.Objects; /** @@ -301,7 +302,7 @@ public class MBeanAttributeInfo extends MBeanFeatureInfo implements Cloneable { right and we needlessly hashed in the description and parameter array. */ public int hashCode() { - return getName().hashCode() ^ getType().hashCode(); + return Objects.hash(getName(), getType()); } private static boolean isIs(Method getter) { diff --git a/jdk/src/share/classes/javax/management/MBeanConstructorInfo.java b/jdk/src/share/classes/javax/management/MBeanConstructorInfo.java index c2bbe5ef886..ad2176367d2 100644 --- a/jdk/src/share/classes/javax/management/MBeanConstructorInfo.java +++ b/jdk/src/share/classes/javax/management/MBeanConstructorInfo.java @@ -29,6 +29,7 @@ import com.sun.jmx.mbeanserver.Introspector; import java.lang.annotation.Annotation; import java.lang.reflect.Constructor; import java.util.Arrays; +import java.util.Objects; /** * Describes a constructor exposed by an MBean. Instances of this @@ -203,11 +204,7 @@ public class MBeanConstructorInfo extends MBeanFeatureInfo implements Cloneable quite long and yet the same between constructors. Likewise for the descriptor. */ public int hashCode() { - int hash = getName().hashCode(); - MBeanParameterInfo[] sig = fastGetSignature(); - for (int i = 0; i < sig.length; i++) - hash ^= sig[i].hashCode(); - return hash; + return Objects.hash(getName()) ^ Arrays.hashCode(fastGetSignature()); } private static MBeanParameterInfo[] constructorSignature(Constructor cn) { diff --git a/jdk/src/share/classes/javax/management/MBeanInfo.java b/jdk/src/share/classes/javax/management/MBeanInfo.java index ed04c347b70..f4a9581c520 100644 --- a/jdk/src/share/classes/javax/management/MBeanInfo.java +++ b/jdk/src/share/classes/javax/management/MBeanInfo.java @@ -36,6 +36,7 @@ import java.util.Map; import java.util.WeakHashMap; import java.security.AccessController; import java.security.PrivilegedAction; +import java.util.Objects; import static javax.management.ImmutableDescriptor.nonNullDescriptor; @@ -515,24 +516,15 @@ public class MBeanInfo implements Cloneable, Serializable, DescriptorRead { if (hashCode != 0) return hashCode; - hashCode = - getClassName().hashCode() ^ - getDescriptor().hashCode() ^ - arrayHashCode(fastGetAttributes()) ^ - arrayHashCode(fastGetOperations()) ^ - arrayHashCode(fastGetConstructors()) ^ - arrayHashCode(fastGetNotifications()); + hashCode = Objects.hash(getClassName(), getDescriptor()) + ^ Arrays.hashCode(fastGetAttributes()) + ^ Arrays.hashCode(fastGetOperations()) + ^ Arrays.hashCode(fastGetConstructors()) + ^ Arrays.hashCode(fastGetNotifications()); return hashCode; } - private static int arrayHashCode(Object[] array) { - int hash = 0; - for (int i = 0; i < array.length; i++) - hash ^= array[i].hashCode(); - return hash; - } - /** * Cached results of previous calls to arrayGettersSafe. This is * a WeakHashMap so that we don't prevent a class from being diff --git a/jdk/src/share/classes/javax/management/MBeanOperationInfo.java b/jdk/src/share/classes/javax/management/MBeanOperationInfo.java index 66b13a94ef0..8effa04f8d8 100644 --- a/jdk/src/share/classes/javax/management/MBeanOperationInfo.java +++ b/jdk/src/share/classes/javax/management/MBeanOperationInfo.java @@ -29,6 +29,7 @@ import com.sun.jmx.mbeanserver.Introspector; import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.Arrays; +import java.util.Objects; /** * Describes a management operation exposed by an MBean. Instances of @@ -309,7 +310,7 @@ public class MBeanOperationInfo extends MBeanFeatureInfo implements Cloneable { parameter array. */ @Override public int hashCode() { - return getName().hashCode() ^ getReturnType().hashCode(); + return Objects.hash(getName(), getReturnType()); } private static MBeanParameterInfo[] methodSignature(Method method) { diff --git a/jdk/src/share/classes/javax/management/MBeanParameterInfo.java b/jdk/src/share/classes/javax/management/MBeanParameterInfo.java index ec5a31fc93e..df3d59087df 100644 --- a/jdk/src/share/classes/javax/management/MBeanParameterInfo.java +++ b/jdk/src/share/classes/javax/management/MBeanParameterInfo.java @@ -25,6 +25,7 @@ package javax.management; +import java.util.Objects; /** * Describes an argument of an operation exposed by an MBean. @@ -143,6 +144,6 @@ public class MBeanParameterInfo extends MBeanFeatureInfo implements Cloneable { } public int hashCode() { - return getName().hashCode() ^ getType().hashCode(); + return Objects.hash(getName(), getType()); } } diff --git a/jdk/test/javax/management/MBeanInfo/MBeanInfoHashCodeNPETest.java b/jdk/test/javax/management/MBeanInfo/MBeanInfoHashCodeNPETest.java new file mode 100644 index 00000000000..bb35da38ba6 --- /dev/null +++ b/jdk/test/javax/management/MBeanInfo/MBeanInfoHashCodeNPETest.java @@ -0,0 +1,176 @@ +/* + * Copyright (c) 2013, 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 javax.management.MBeanAttributeInfo; +import javax.management.MBeanConstructorInfo; +import javax.management.MBeanInfo; +import javax.management.MBeanNotificationInfo; +import javax.management.MBeanOperationInfo; +import javax.management.MBeanParameterInfo; +import javax.management.modelmbean.DescriptorSupport; +import javax.management.openmbean.SimpleType; + +/* + * @test + * @bug 8023669 + * @summary Test that hashCode()throws NullPointerException + * @author Shanliang JIANG + * @run clean MBeanInfoHashCodeNPETest + * @run build MBeanInfoHashCodeNPETest + * @run main MBeanInfoHashCodeNPETest + */ +public class MBeanInfoHashCodeNPETest { + private static int failed = 0; + + public static void main(String[] args) throws Exception { + System.out.println("---MBeanInfoHashCodeNPETest-main ..."); + + // ---- + System.out.println("\n---Testing on MBeanAttributeInfo..."); + MBeanAttributeInfo mbeanAttributeInfo = new MBeanAttributeInfo( + null, SimpleType.INTEGER.getClassName(), "description", true, true, false); + test(mbeanAttributeInfo, "class name"); + + mbeanAttributeInfo = new MBeanAttributeInfo( + "name", null, "description", true, true, false); + test(mbeanAttributeInfo, "type"); + + mbeanAttributeInfo = new MBeanAttributeInfo( + "name", SimpleType.INTEGER.getClassName(), null, true, true, false); + test(mbeanAttributeInfo, "description"); + + // ---- + System.out.println("\n---Testing on MBeanConstructorInfo..."); + MBeanConstructorInfo mbeanConstructorInfo = new MBeanConstructorInfo( + null, "", new MBeanParameterInfo[]{}, new DescriptorSupport()); + test(mbeanConstructorInfo, "name"); + + mbeanConstructorInfo = new MBeanConstructorInfo( + "", null, new MBeanParameterInfo[]{}, new DescriptorSupport()); + test(mbeanConstructorInfo, "description"); + + mbeanConstructorInfo = new MBeanConstructorInfo( + "", "", null, new DescriptorSupport()); + test(mbeanConstructorInfo, "MBeanParameterInfo"); + + mbeanConstructorInfo = new MBeanConstructorInfo( + "", "", new MBeanParameterInfo[]{}, null); + test(mbeanConstructorInfo, "descriptor"); + + // ---- + System.out.println("\n---Testing on MBeanOperationInfo..."); + MBeanOperationInfo mbeanOperationInfo = new MBeanOperationInfo( + null, "description", new MBeanParameterInfo[]{}, "type", 1, new DescriptorSupport()); + test(mbeanOperationInfo, "name"); + + mbeanOperationInfo = new MBeanOperationInfo( + "name", null, new MBeanParameterInfo[]{}, "type", 1, new DescriptorSupport()); + test(mbeanOperationInfo, "description"); + + mbeanOperationInfo = new MBeanOperationInfo( + "name", "description", null, "type", 1, new DescriptorSupport()); + test(mbeanOperationInfo, "MBeanParameterInfo"); + + mbeanOperationInfo = new MBeanOperationInfo( + "name", "description", new MBeanParameterInfo[]{}, null, 1, new DescriptorSupport()); + test(mbeanOperationInfo, "type"); + + mbeanOperationInfo = new MBeanOperationInfo( + "name", "description", new MBeanParameterInfo[]{}, "type", -1, new DescriptorSupport()); + test(mbeanOperationInfo, "native impact"); + + mbeanOperationInfo = new MBeanOperationInfo( + "name", "description", new MBeanParameterInfo[]{}, "type", 1, null); + test(mbeanOperationInfo, "Descriptor"); + + // ---- + System.out.println("\n---Testing on MBeanParameterInfo..."); + MBeanParameterInfo mbeanParameterInfo = new MBeanParameterInfo( + null, "type", "description", new DescriptorSupport()); + test(mbeanParameterInfo, "name"); + + mbeanParameterInfo = new MBeanParameterInfo( + "name", null, "description", new DescriptorSupport()); + test(mbeanParameterInfo, "description"); + + mbeanParameterInfo = new MBeanParameterInfo( + "name", "type", null, new DescriptorSupport()); + test(mbeanParameterInfo, "description"); + + mbeanParameterInfo = new MBeanParameterInfo( + "name", "type", "description", null); + test(mbeanParameterInfo, "Descriptor"); + + // ---- + System.out.println("\n---Testing on MBeanInfo..."); + String className = "toto"; + String description = "titi"; + MBeanAttributeInfo[] attrInfos = new MBeanAttributeInfo[]{}; + MBeanConstructorInfo[] constrInfos = new MBeanConstructorInfo[]{}; + MBeanOperationInfo[] operaInfos = new MBeanOperationInfo[]{}; + MBeanNotificationInfo[] notifInfos = new MBeanNotificationInfo[]{}; + + MBeanInfo minfo = new MBeanInfo(null, description, attrInfos, constrInfos, operaInfos, notifInfos); + test(minfo, "class name"); + + minfo = new MBeanInfo(className, description, attrInfos, constrInfos, operaInfos, notifInfos); + test(minfo, "name"); + + minfo = new MBeanInfo(className, null, attrInfos, constrInfos, operaInfos, notifInfos); + test(minfo, "description"); + + minfo = new MBeanInfo(className, description, null, constrInfos, operaInfos, notifInfos); + test(minfo, "attrInfos"); + + minfo = new MBeanInfo(className, description, attrInfos, constrInfos, null, notifInfos); + test(minfo, "operaInfos"); + + minfo = new MBeanInfo(className, description, attrInfos, constrInfos, operaInfos, null); + test(minfo, "notifInfos"); + + Thread.sleep(100); + if (failed > 0) { + throw new RuntimeException("Test failed: "+failed); + } else { + System.out.println("---Test: PASSED"); + } + } + + private static void test(Object obj, String param) { + try { + obj.hashCode(); + System.out.println("OK: "+obj.getClass().getSimpleName()+".hashCode worked with a null "+param); + } catch (NullPointerException npe) { + System.out.println("--->KO!!! "+obj.getClass().getSimpleName()+".hashCode got NPE with a null "+param); + failed++; + } + + try { + obj.toString(); + System.out.println("OK: "+obj.getClass().getSimpleName()+".toString worked with a null "+param); + } catch (NullPointerException npe) { + System.out.println("--->KO!!! "+obj.getClass().getSimpleName()+".toString got NPE."); + failed++; + } + } +} From 276b809ff474d3655f6b3d9786dd20fc4a47664f Mon Sep 17 00:00:00 2001 From: Brent Christian Date: Thu, 12 Sep 2013 14:22:53 -0700 Subject: [PATCH 073/210] 8024009: Remove jdk.map.useRandomSeed system property Removed usage of hashSeed in Hashtable & WeakHashMap, and removed tests Reviewed-by: alanb, mduigou --- .../share/classes/java/util/Hashtable.java | 104 +++--------------- .../share/classes/java/util/WeakHashMap.java | 39 +------ .../java/util/Map/CheckRandomHashSeed.java | 91 --------------- jdk/test/java/util/Map/Collisions.java | 2 - 4 files changed, 19 insertions(+), 217 deletions(-) delete mode 100644 jdk/test/java/util/Map/CheckRandomHashSeed.java diff --git a/jdk/src/share/classes/java/util/Hashtable.java b/jdk/src/share/classes/java/util/Hashtable.java index 518bd17f5b7..dc50e9393ee 100644 --- a/jdk/src/share/classes/java/util/Hashtable.java +++ b/jdk/src/share/classes/java/util/Hashtable.java @@ -168,68 +168,6 @@ public class Hashtable /** use serialVersionUID from JDK 1.0.2 for interoperability */ private static final long serialVersionUID = 1421746759512286392L; - private static class Holder { - // Unsafe mechanics - /** - * - */ - static final sun.misc.Unsafe UNSAFE; - - /** - * Offset of "final" hashSeed field we must set in - * readObject() method. - */ - static final long HASHSEED_OFFSET; - - static final boolean USE_HASHSEED; - - static { - String hashSeedProp = java.security.AccessController.doPrivileged( - new sun.security.action.GetPropertyAction( - "jdk.map.useRandomSeed")); - boolean localBool = (null != hashSeedProp) - ? Boolean.parseBoolean(hashSeedProp) : false; - USE_HASHSEED = localBool; - - if (USE_HASHSEED) { - try { - UNSAFE = sun.misc.Unsafe.getUnsafe(); - HASHSEED_OFFSET = UNSAFE.objectFieldOffset( - Hashtable.class.getDeclaredField("hashSeed")); - } catch (NoSuchFieldException | SecurityException e) { - throw new InternalError("Failed to record hashSeed offset", e); - } - } else { - UNSAFE = null; - HASHSEED_OFFSET = 0; - } - } - } - - /** - * A randomizing value associated with this instance that is applied to - * hash code of keys to make hash collisions harder to find. - * - * Non-final so it can be set lazily, but be sure not to set more than once. - */ - transient final int hashSeed; - - /** - * Return an initial value for the hashSeed, or 0 if the random seed is not - * enabled. - */ - final int initHashSeed() { - if (sun.misc.VM.isBooted() && Holder.USE_HASHSEED) { - int seed = ThreadLocalRandom.current().nextInt(); - return (seed != 0) ? seed : 1; - } - return 0; - } - - private int hash(Object k) { - return hashSeed ^ k.hashCode(); - } - /** * Constructs a new, empty hashtable with the specified initial * capacity and the specified load factor. @@ -251,7 +189,6 @@ public class Hashtable this.loadFactor = loadFactor; table = new Entry[initialCapacity]; threshold = (int)Math.min(initialCapacity * loadFactor, MAX_ARRAY_SIZE + 1); - hashSeed = initHashSeed(); } /** @@ -395,7 +332,7 @@ public class Hashtable */ public synchronized boolean containsKey(Object key) { Entry tab[] = table; - int hash = hash(key); + int hash = key.hashCode(); int index = (hash & 0x7FFFFFFF) % tab.length; for (Entry e = tab[index] ; e != null ; e = e.next) { if ((e.hash == hash) && e.key.equals(key)) { @@ -423,7 +360,7 @@ public class Hashtable @SuppressWarnings("unchecked") public synchronized V get(Object key) { Entry tab[] = table; - int hash = hash(key); + int hash = key.hashCode(); int index = (hash & 0x7FFFFFFF) % tab.length; for (Entry e = tab[index] ; e != null ; e = e.next) { if ((e.hash == hash) && e.key.equals(key)) { @@ -488,7 +425,7 @@ public class Hashtable rehash(); tab = table; - hash = hash(key); + hash = key.hashCode(); index = (hash & 0x7FFFFFFF) % tab.length; } @@ -524,7 +461,7 @@ public class Hashtable // Makes sure the key is not already in the hashtable. Entry tab[] = table; - int hash = hash(key); + int hash = key.hashCode(); int index = (hash & 0x7FFFFFFF) % tab.length; @SuppressWarnings("unchecked") Entry entry = (Entry)tab[index]; @@ -551,7 +488,7 @@ public class Hashtable */ public synchronized V remove(Object key) { Entry tab[] = table; - int hash = hash(key); + int hash = key.hashCode(); int index = (hash & 0x7FFFFFFF) % tab.length; @SuppressWarnings("unchecked") Entry e = (Entry)tab[index]; @@ -760,7 +697,7 @@ public class Hashtable Map.Entry entry = (Map.Entry)o; Object key = entry.getKey(); Entry[] tab = table; - int hash = hash(key); + int hash = key.hashCode(); int index = (hash & 0x7FFFFFFF) % tab.length; for (Entry e = tab[index]; e != null; e = e.next) @@ -775,7 +712,7 @@ public class Hashtable Map.Entry entry = (Map.Entry) o; Object key = entry.getKey(); Entry[] tab = table; - int hash = hash(key); + int hash = key.hashCode(); int index = (hash & 0x7FFFFFFF) % tab.length; @SuppressWarnings("unchecked") @@ -975,7 +912,7 @@ public class Hashtable // Makes sure the key is not already in the hashtable. Entry tab[] = table; - int hash = hash(key); + int hash = key.hashCode(); int index = (hash & 0x7FFFFFFF) % tab.length; @SuppressWarnings("unchecked") Entry entry = (Entry)tab[index]; @@ -998,7 +935,7 @@ public class Hashtable Objects.requireNonNull(value); Entry tab[] = table; - int hash = hash(key); + int hash = key.hashCode(); int index = (hash & 0x7FFFFFFF) % tab.length; @SuppressWarnings("unchecked") Entry e = (Entry)tab[index]; @@ -1021,7 +958,7 @@ public class Hashtable @Override public synchronized boolean replace(K key, V oldValue, V newValue) { Entry tab[] = table; - int hash = hash(key); + int hash = key.hashCode(); int index = (hash & 0x7FFFFFFF) % tab.length; @SuppressWarnings("unchecked") Entry e = (Entry)tab[index]; @@ -1041,7 +978,7 @@ public class Hashtable @Override public synchronized V replace(K key, V value) { Entry tab[] = table; - int hash = hash(key); + int hash = key.hashCode(); int index = (hash & 0x7FFFFFFF) % tab.length; @SuppressWarnings("unchecked") Entry e = (Entry)tab[index]; @@ -1060,7 +997,7 @@ public class Hashtable Objects.requireNonNull(mappingFunction); Entry tab[] = table; - int hash = hash(key); + int hash = key.hashCode(); int index = (hash & 0x7FFFFFFF) % tab.length; @SuppressWarnings("unchecked") Entry e = (Entry)tab[index]; @@ -1084,7 +1021,7 @@ public class Hashtable Objects.requireNonNull(remappingFunction); Entry tab[] = table; - int hash = hash(key); + int hash = key.hashCode(); int index = (hash & 0x7FFFFFFF) % tab.length; @SuppressWarnings("unchecked") Entry e = (Entry)tab[index]; @@ -1113,7 +1050,7 @@ public class Hashtable Objects.requireNonNull(remappingFunction); Entry tab[] = table; - int hash = hash(key); + int hash = key.hashCode(); int index = (hash & 0x7FFFFFFF) % tab.length; @SuppressWarnings("unchecked") Entry e = (Entry)tab[index]; @@ -1148,7 +1085,7 @@ public class Hashtable Objects.requireNonNull(remappingFunction); Entry tab[] = table; - int hash = hash(key); + int hash = key.hashCode(); int index = (hash & 0x7FFFFFFF) % tab.length; @SuppressWarnings("unchecked") Entry e = (Entry)tab[index]; @@ -1228,13 +1165,6 @@ public class Hashtable // Read in the length, threshold, and loadfactor s.defaultReadObject(); - // set hashMask - if (Holder.USE_HASHSEED) { - int seed = ThreadLocalRandom.current().nextInt(); - Holder.UNSAFE.putIntVolatile(this, Holder.HASHSEED_OFFSET, - (seed != 0) ? seed : 1); - } - // Read the original length of the array and number of elements int origlength = s.readInt(); int elements = s.readInt(); @@ -1282,7 +1212,7 @@ public class Hashtable } // Makes sure the key is not already in the hashtable. // This should not happen in deserialized version. - int hash = hash(key); + int hash = key.hashCode(); int index = (hash & 0x7FFFFFFF) % tab.length; for (Entry e = tab[index] ; e != null ; e = e.next) { if ((e.hash == hash) && e.key.equals(key)) { @@ -1347,7 +1277,7 @@ public class Hashtable } public int hashCode() { - return (Objects.hashCode(key) ^ Objects.hashCode(value)); + return hash ^ Objects.hashCode(value); } public String toString() { diff --git a/jdk/src/share/classes/java/util/WeakHashMap.java b/jdk/src/share/classes/java/util/WeakHashMap.java index 0299d296638..81f74be8e9e 100644 --- a/jdk/src/share/classes/java/util/WeakHashMap.java +++ b/jdk/src/share/classes/java/util/WeakHashMap.java @@ -190,39 +190,6 @@ public class WeakHashMap */ int modCount; - private static class Holder { - static final boolean USE_HASHSEED; - - static { - String hashSeedProp = java.security.AccessController.doPrivileged( - new sun.security.action.GetPropertyAction( - "jdk.map.useRandomSeed")); - boolean localBool = (null != hashSeedProp) - ? Boolean.parseBoolean(hashSeedProp) : false; - USE_HASHSEED = localBool; - } - } - - /** - * A randomizing value associated with this instance that is applied to - * hash code of keys to make hash collisions harder to find. - * - * Non-final so it can be set lazily, but be sure not to set more than once. - */ - transient int hashSeed; - - /** - * Initialize the hashing mask value. - */ - final void initHashSeed() { - if (sun.misc.VM.isBooted() && Holder.USE_HASHSEED) { - // Do not set hashSeed more than once! - // assert hashSeed == 0; - int seed = ThreadLocalRandom.current().nextInt(); - hashSeed = (seed != 0) ? seed : 1; - } - } - @SuppressWarnings("unchecked") private Entry[] newTable(int n) { return (Entry[]) new Entry[n]; @@ -253,7 +220,6 @@ public class WeakHashMap table = newTable(capacity); this.loadFactor = loadFactor; threshold = (int)(capacity * loadFactor); - initHashSeed(); } /** @@ -329,7 +295,7 @@ public class WeakHashMap * in lower bits. */ final int hash(Object k) { - int h = hashSeed ^ k.hashCode(); + int h = k.hashCode(); // This function ensures that hashCodes that differ only by // constant multiples at each bit position have a bounded @@ -783,8 +749,7 @@ public class WeakHashMap public int hashCode() { K k = getKey(); V v = getValue(); - return ((k==null ? 0 : k.hashCode()) ^ - (v==null ? 0 : v.hashCode())); + return Objects.hashCode(k) ^ Objects.hashCode(v); } public String toString() { diff --git a/jdk/test/java/util/Map/CheckRandomHashSeed.java b/jdk/test/java/util/Map/CheckRandomHashSeed.java deleted file mode 100644 index 2acf1bc8c9c..00000000000 --- a/jdk/test/java/util/Map/CheckRandomHashSeed.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2013, 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 8005698 - * @summary Check operation of jdk.map.useRandomSeed property - * @run main CheckRandomHashSeed - * @run main/othervm -Djdk.map.useRandomSeed=false CheckRandomHashSeed - * @run main/othervm -Djdk.map.useRandomSeed=bogus CheckRandomHashSeed - * @run main/othervm -Djdk.map.useRandomSeed=true CheckRandomHashSeed true - * @author Brent Christian - */ -import java.lang.reflect.Field; -import java.util.Map; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Hashtable; -import java.util.WeakHashMap; - -public class CheckRandomHashSeed { - private final static String PROP_NAME = "jdk.map.useRandomSeed"; - static boolean expectRandom = false; - - public static void main(String[] args) { - if (args.length > 0 && args[0].equals("true")) { - expectRandom = true; - } - String hashSeedProp = System.getProperty(PROP_NAME); - boolean propSet = (null != hashSeedProp) - ? Boolean.parseBoolean(hashSeedProp) : false; - if (expectRandom != propSet) { - throw new Error("Error in test setup: " + (expectRandom ? "" : "not " ) + "expecting random hashSeed, but " + PROP_NAME + " is " + (propSet ? "" : "not ") + "enabled"); - } - - testMap(new WeakHashMap()); - testMap(new Hashtable()); - } - - private static void testMap(Map map) { - int hashSeed = getHashSeed(map); - boolean hashSeedIsZero = (hashSeed == 0); - - if (expectRandom != hashSeedIsZero) { - System.out.println("Test passed for " + map.getClass().getSimpleName() + " - expectRandom: " + expectRandom + ", hashSeed: " + hashSeed); - } else { - throw new Error ("Test FAILED for " + map.getClass().getSimpleName() + " - expectRandom: " + expectRandom + ", hashSeed: " + hashSeed); - } - } - - private static int getHashSeed(Map map) { - try { - if (map instanceof HashMap || map instanceof LinkedHashMap) { - map.put("Key", "Value"); - Field hashSeedField = HashMap.class.getDeclaredField("hashSeed"); - hashSeedField.setAccessible(true); - int hashSeed = hashSeedField.getInt(map); - return hashSeed; - } else { - map.put("Key", "Value"); - Field hashSeedField = map.getClass().getDeclaredField("hashSeed"); - hashSeedField.setAccessible(true); - int hashSeed = hashSeedField.getInt(map); - return hashSeed; - } - } catch(Exception e) { - e.printStackTrace(); - throw new Error(e); - } - } -} diff --git a/jdk/test/java/util/Map/Collisions.java b/jdk/test/java/util/Map/Collisions.java index b7170791777..05e9e1f95e0 100644 --- a/jdk/test/java/util/Map/Collisions.java +++ b/jdk/test/java/util/Map/Collisions.java @@ -25,8 +25,6 @@ * @test * @bug 7126277 * @run main Collisions -shortrun - * @run main/othervm -Djdk.map.althashing.threshold=0 Collisions -shortrun - * @run main/othervm -Djdk.map.useRandomSeed=true Collisions -shortrun * @summary Ensure Maps behave well with lots of hashCode() collisions. * @author Mike Duigou */ From 767ab8c9ae5c20f2be376b3b49768d000d37d8ae Mon Sep 17 00:00:00 2001 From: Mark Sheppard Date: Fri, 13 Sep 2013 12:20:53 +0100 Subject: [PATCH 074/210] 8024675: java/net/NetworkInterface/UniqueMacAddressesTest.java fails on Windows Amended test to add active, i.e. isUp(), NetworkInterfaces to test list Reviewed-by: alanb, chegar --- .../NetworkInterface/UniqueMacAddressesTest.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/jdk/test/java/net/NetworkInterface/UniqueMacAddressesTest.java b/jdk/test/java/net/NetworkInterface/UniqueMacAddressesTest.java index c2f5c495c73..4017c0702ed 100644 --- a/jdk/test/java/net/NetworkInterface/UniqueMacAddressesTest.java +++ b/jdk/test/java/net/NetworkInterface/UniqueMacAddressesTest.java @@ -118,11 +118,14 @@ public class UniqueMacAddressesTest { NetworkInterface netIf = null; while (nis.hasMoreElements()) { netIf = (NetworkInterface) nis.nextElement(); - macAddr = netIf.getHardwareAddress(); - if (macAddr != null) { - System.out - .println("Adding NetworkInterface " + netIf.getName()); - networkInterfaceList.add(netIf); + if (netIf.isUp()) { + macAddr = netIf.getHardwareAddress(); + if (macAddr != null) { + System.out.println("Adding NetworkInterface " + + netIf.getName() + " with mac address " + + createMacAddressString(netIf)); + networkInterfaceList.add(netIf); + } } } } From b59dc6762ed4fd9fa1d9285cdf8d1bc6e9277fa1 Mon Sep 17 00:00:00 2001 From: Mike Duigou Date: Fri, 13 Sep 2013 11:18:44 -0700 Subject: [PATCH 075/210] 8021591: Additional explicit null checks Reviewed-by: psandoz, alanb --- .../share/classes/java/util/Collections.java | 1 + .../share/classes/java/util/Hashtable.java | 3 + .../classes/java/util/IdentityHashMap.java | 2 + jdk/src/share/classes/java/util/Map.java | 9 +- jdk/src/share/classes/java/util/TreeMap.java | 2 +- .../util/concurrent/ConcurrentHashMap.java | 3 + .../classes/javax/security/auth/Subject.java | 4 +- .../util/Collection/CollectionDefaults.java | 108 ++++-- jdk/test/java/util/Collection/MOAT.java | 2 - .../testlibrary/CollectionAsserts.java | 58 ++-- .../testlibrary/CollectionSupplier.java | 309 +++++++----------- .../ExtendsAbstractCollection.java | 86 +++++ .../testlibrary/ExtendsAbstractList.java | 101 ++++++ .../testlibrary/ExtendsAbstractSet.java | 85 +++++ .../{Collection => List}/ListDefaults.java | 95 +++--- jdk/test/java/util/Map/Defaults.java | 46 ++- 16 files changed, 604 insertions(+), 310 deletions(-) create mode 100644 jdk/test/java/util/Collection/testlibrary/ExtendsAbstractCollection.java create mode 100644 jdk/test/java/util/Collection/testlibrary/ExtendsAbstractList.java create mode 100644 jdk/test/java/util/Collection/testlibrary/ExtendsAbstractSet.java rename jdk/test/java/util/{Collection => List}/ListDefaults.java (88%) diff --git a/jdk/src/share/classes/java/util/Collections.java b/jdk/src/share/classes/java/util/Collections.java index 2404b4fc9ad..947b6282db4 100644 --- a/jdk/src/share/classes/java/util/Collections.java +++ b/jdk/src/share/classes/java/util/Collections.java @@ -3900,6 +3900,7 @@ public class Collections { return batchRemove(c, true); } private boolean batchRemove(Collection c, boolean complement) { + Objects.requireNonNull(c); boolean modified = false; Iterator> it = iterator(); while (it.hasNext()) { diff --git a/jdk/src/share/classes/java/util/Hashtable.java b/jdk/src/share/classes/java/util/Hashtable.java index dc50e9393ee..b97a8e361bb 100644 --- a/jdk/src/share/classes/java/util/Hashtable.java +++ b/jdk/src/share/classes/java/util/Hashtable.java @@ -957,6 +957,8 @@ public class Hashtable @Override public synchronized boolean replace(K key, V oldValue, V newValue) { + Objects.requireNonNull(oldValue); + Objects.requireNonNull(newValue); Entry tab[] = table; int hash = key.hashCode(); int index = (hash & 0x7FFFFFFF) % tab.length; @@ -977,6 +979,7 @@ public class Hashtable @Override public synchronized V replace(K key, V value) { + Objects.requireNonNull(value); Entry tab[] = table; int hash = key.hashCode(); int index = (hash & 0x7FFFFFFF) % tab.length; diff --git a/jdk/src/share/classes/java/util/IdentityHashMap.java b/jdk/src/share/classes/java/util/IdentityHashMap.java index a4bdc4b9efd..40808213894 100644 --- a/jdk/src/share/classes/java/util/IdentityHashMap.java +++ b/jdk/src/share/classes/java/util/IdentityHashMap.java @@ -997,6 +997,7 @@ public class IdentityHashMap * behavior when c is a smaller "normal" (non-identity-based) Set. */ public boolean removeAll(Collection c) { + Objects.requireNonNull(c); boolean modified = false; for (Iterator i = iterator(); i.hasNext(); ) { if (c.contains(i.next())) { @@ -1212,6 +1213,7 @@ public class IdentityHashMap * behavior when c is a smaller "normal" (non-identity-based) Set. */ public boolean removeAll(Collection c) { + Objects.requireNonNull(c); boolean modified = false; for (Iterator> i = iterator(); i.hasNext(); ) { if (c.contains(i.next())) { diff --git a/jdk/src/share/classes/java/util/Map.java b/jdk/src/share/classes/java/util/Map.java index 321233e6f8d..4340e6d9c8f 100644 --- a/jdk/src/share/classes/java/util/Map.java +++ b/jdk/src/share/classes/java/util/Map.java @@ -805,6 +805,10 @@ public interface Map { * return false; * }
    * + * The default implementation does not throw NullPointerException + * for maps that do not support null values if oldValue is null unless + * newValue is also null. + * * @param key key with which the specified value is associated * @param oldValue value expected to be associated with the specified key * @param newValue value to be associated with the specified key @@ -814,8 +818,11 @@ public interface Map { * (optional) * @throws ClassCastException if the class of a specified key or value * prevents it from being stored in this map - * @throws NullPointerException if a specified key or value is null, + * @throws NullPointerException if a specified key or newValue is null, * and this map does not permit null keys or values + * @throws NullPointerException if oldValue is null and this map does not + * permit null values + * (optional) * @throws IllegalArgumentException if some property of a specified key * or value prevents it from being stored in this map * @since 1.8 diff --git a/jdk/src/share/classes/java/util/TreeMap.java b/jdk/src/share/classes/java/util/TreeMap.java index 9a4681d771a..740456b7ecb 100644 --- a/jdk/src/share/classes/java/util/TreeMap.java +++ b/jdk/src/share/classes/java/util/TreeMap.java @@ -1012,7 +1012,7 @@ public class TreeMap int expectedModCount = modCount; for (Entry e = getFirstEntry(); e != null; e = successor(e)) { - e.value = Objects.requireNonNull(function.apply(e.key, e.value)); + e.value = function.apply(e.key, e.value); if (expectedModCount != modCount) { throw new ConcurrentModificationException(); diff --git a/jdk/src/share/classes/java/util/concurrent/ConcurrentHashMap.java b/jdk/src/share/classes/java/util/concurrent/ConcurrentHashMap.java index 1936e244946..9476bc411ba 100644 --- a/jdk/src/share/classes/java/util/concurrent/ConcurrentHashMap.java +++ b/jdk/src/share/classes/java/util/concurrent/ConcurrentHashMap.java @@ -49,6 +49,7 @@ import java.util.Hashtable; import java.util.Iterator; import java.util.Map; import java.util.NoSuchElementException; +import java.util.Objects; import java.util.Set; import java.util.Spliterator; import java.util.concurrent.ConcurrentMap; @@ -4410,6 +4411,7 @@ public class ConcurrentHashMap extends AbstractMap } public final boolean removeAll(Collection c) { + Objects.requireNonNull(c); boolean modified = false; for (Iterator it = iterator(); it.hasNext();) { if (c.contains(it.next())) { @@ -4421,6 +4423,7 @@ public class ConcurrentHashMap extends AbstractMap } public final boolean retainAll(Collection c) { + Objects.requireNonNull(c); boolean modified = false; for (Iterator it = iterator(); it.hasNext();) { if (!c.contains(it.next())) { diff --git a/jdk/src/share/classes/javax/security/auth/Subject.java b/jdk/src/share/classes/javax/security/auth/Subject.java index d5e4240a40a..ba6bda71f66 100644 --- a/jdk/src/share/classes/javax/security/auth/Subject.java +++ b/jdk/src/share/classes/javax/security/auth/Subject.java @@ -1186,7 +1186,7 @@ public final class Subject implements java.io.Serializable { } public boolean removeAll(Collection c) { - + Objects.requireNonNull(c); boolean modified = false; final Iterator e = iterator(); while (e.hasNext()) { @@ -1222,7 +1222,7 @@ public final class Subject implements java.io.Serializable { } public boolean retainAll(Collection c) { - + Objects.requireNonNull(c); boolean modified = false; boolean retain = false; final Iterator e = iterator(); diff --git a/jdk/test/java/util/Collection/CollectionDefaults.java b/jdk/test/java/util/Collection/CollectionDefaults.java index 36fd8da5469..594b67adae8 100644 --- a/jdk/test/java/util/Collection/CollectionDefaults.java +++ b/jdk/test/java/util/Collection/CollectionDefaults.java @@ -21,15 +21,19 @@ * questions. */ +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.Set; +import java.util.SortedSet; + import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -38,43 +42,68 @@ import static org.testng.Assert.fail; import java.util.TreeMap; import java.util.TreeSet; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentSkipListMap; import java.util.function.Predicate; +import java.util.function.Supplier; /** * @test - * @library testlibrary - * @build CollectionAsserts CollectionSupplier - * @run testng CollectionDefaults * @summary Unit tests for extension methods on Collection + * @library testlibrary + * @build CollectionAsserts CollectionSupplier ExtendsAbstractSet ExtendsAbstractCollection + * @run testng CollectionDefaults */ public class CollectionDefaults { public static final Predicate pEven = x -> 0 == x % 2; public static final Predicate pOdd = x -> 1 == x % 2; - private static final String[] SET_CLASSES = { - "java.util.HashSet", - "java.util.LinkedHashSet", - "java.util.TreeSet" + @SuppressWarnings("unchecked") + private static final Supplier[] TEST_CLASSES = { + // Collection + ExtendsAbstractCollection::new, + + // Lists + java.util.ArrayList::new, + java.util.LinkedList::new, + java.util.Vector::new, + java.util.concurrent.CopyOnWriteArrayList::new, + ExtendsAbstractList::new, + + // Sets + java.util.HashSet::new, + java.util.LinkedHashSet::new, + java.util.TreeSet::new, + java.util.concurrent.ConcurrentSkipListSet::new, + java.util.concurrent.CopyOnWriteArraySet::new, + ExtendsAbstractSet::new }; private static final int SIZE = 100; @DataProvider(name="setProvider", parallel=true) - public static Object[][] setCases() { + public static Iterator setCases() { final List cases = new LinkedList<>(); cases.add(new Object[] { new HashSet<>() }); cases.add(new Object[] { new LinkedHashSet<>() }); cases.add(new Object[] { new TreeSet<>() }); + cases.add(new Object[] { new java.util.concurrent.ConcurrentSkipListSet<>() }); + cases.add(new Object[] { new java.util.concurrent.CopyOnWriteArraySet<>() }); + + cases.add(new Object[] { new ExtendsAbstractSet<>() }); cases.add(new Object[] { Collections.newSetFromMap(new HashMap<>()) }); cases.add(new Object[] { Collections.newSetFromMap(new LinkedHashMap()) }); cases.add(new Object[] { Collections.newSetFromMap(new TreeMap<>()) }); + cases.add(new Object[] { Collections.newSetFromMap(new ConcurrentHashMap<>()) }); + cases.add(new Object[] { Collections.newSetFromMap(new ConcurrentSkipListMap<>()) }); - cases.add(new Object[] { new HashSet(){{add(42);}} }); - cases.add(new Object[] { new LinkedHashSet(){{add(42);}} }); - cases.add(new Object[] { new TreeSet(){{add(42);}} }); - return cases.toArray(new Object[0][cases.size()]); + cases.add(new Object[] { new HashSet(){{add(42);}} }); + cases.add(new Object[] { new ExtendsAbstractSet(){{add(42);}} }); + cases.add(new Object[] { new LinkedHashSet(){{add(42);}} }); + cases.add(new Object[] { new TreeSet(){{add(42);}} }); + return cases.iterator(); } @Test(dataProvider = "setProvider") @@ -82,57 +111,66 @@ public class CollectionDefaults { try { set.forEach(null); fail("expected NPE not thrown"); - } catch (NullPointerException npe) {} + } catch (NullPointerException expected) { + ; // expected + } try { set.removeIf(null); fail("expected NPE not thrown"); - } catch (NullPointerException npe) {} + } catch (NullPointerException expected) { + ; // expected + } } @Test public void testForEach() throws Exception { - final CollectionSupplier supplier = new CollectionSupplier(SET_CLASSES, SIZE); - for (final CollectionSupplier.TestCase test : supplier.get()) { - final Set original = ((Set) test.original); - final Set set = ((Set) test.collection); + final CollectionSupplier> supplier = new CollectionSupplier((Supplier>[]) TEST_CLASSES, SIZE); + + for (final CollectionSupplier.TestCase> test : supplier.get()) { + final Collection original = test.expected; + final Collection set = test.collection; try { set.forEach(null); fail("expected NPE not thrown"); - } catch (NullPointerException npe) {} - if (test.className.equals("java.util.HashSet")) { - CollectionAsserts.assertContentsUnordered(set, original); + } catch (NullPointerException expected) { + ; // expected + } + if (set instanceof Set && !((set instanceof SortedSet) || (set instanceof LinkedHashSet))) { + CollectionAsserts.assertContentsUnordered(set, original, test.toString()); } else { - CollectionAsserts.assertContents(set, original); + CollectionAsserts.assertContents(set, original, test.toString()); } final List actual = new LinkedList<>(); set.forEach(actual::add); - if (test.className.equals("java.util.HashSet")) { - CollectionAsserts.assertContentsUnordered(actual, set); - CollectionAsserts.assertContentsUnordered(actual, original); + if (set instanceof Set && !((set instanceof SortedSet) || (set instanceof LinkedHashSet))) { + CollectionAsserts.assertContentsUnordered(actual, set, test.toString()); + CollectionAsserts.assertContentsUnordered(actual, original, test.toString()); } else { - CollectionAsserts.assertContents(actual, set); - CollectionAsserts.assertContents(actual, original); + CollectionAsserts.assertContents(actual, set, test.toString()); + CollectionAsserts.assertContents(actual, original, test.toString()); } } } @Test public void testRemoveIf() throws Exception { - final CollectionSupplier supplier = new CollectionSupplier(SET_CLASSES, SIZE); - for (final CollectionSupplier.TestCase test : supplier.get()) { - final Set original = ((Set) test.original); - final Set set = ((Set) test.collection); + final CollectionSupplier> supplier = new CollectionSupplier((Supplier>[]) TEST_CLASSES, SIZE); + for (final CollectionSupplier.TestCase> test : supplier.get()) { + final Collection original = test.expected; + final Collection set = test.collection; try { set.removeIf(null); fail("expected NPE not thrown"); - } catch (NullPointerException npe) {} - if (test.className.equals("java.util.HashSet")) { - CollectionAsserts.assertContentsUnordered(set, original); + } catch (NullPointerException expected) { + ; // expected + } + if (set instanceof Set && !((set instanceof SortedSet) || (set instanceof LinkedHashSet))) { + CollectionAsserts.assertContentsUnordered(set, original, test.toString()); } else { - CollectionAsserts.assertContents(set, original); + CollectionAsserts.assertContents(set, original, test.toString()); } set.removeIf(pEven); diff --git a/jdk/test/java/util/Collection/MOAT.java b/jdk/test/java/util/Collection/MOAT.java index 37720016c3c..a039461e2b7 100644 --- a/jdk/test/java/util/Collection/MOAT.java +++ b/jdk/test/java/util/Collection/MOAT.java @@ -400,8 +400,6 @@ public class MOAT { // If add(null) succeeds, contains(null) & remove(null) should succeed //---------------------------------------------------------------- private static void testNullElement(Collection c) { - // !!!! 5018849: (coll) TreeSet.contains(null) does not agree with Javadoc - if (c instanceof TreeSet) return; try { check(c.add(null)); diff --git a/jdk/test/java/util/Collection/testlibrary/CollectionAsserts.java b/jdk/test/java/util/Collection/testlibrary/CollectionAsserts.java index a03f975152e..575dc796204 100644 --- a/jdk/test/java/util/Collection/testlibrary/CollectionAsserts.java +++ b/jdk/test/java/util/Collection/testlibrary/CollectionAsserts.java @@ -41,6 +41,10 @@ import static org.testng.Assert.fail; */ public class CollectionAsserts { + private CollectionAsserts() { + // no instances + } + public static void assertCountSum(Iterable it, int count, int sum) { assertCountSum(it.iterator(), count, sum); } @@ -117,10 +121,18 @@ public class CollectionAsserts { } public static void assertContents(Iterable actual, Iterable expected) { - assertContents(actual.iterator(), expected.iterator()); + assertContents(actual, expected, null); + } + + public static void assertContents(Iterable actual, Iterable expected, String msg) { + assertContents(actual.iterator(), expected.iterator(), msg); } public static void assertContents(Iterator actual, Iterator expected) { + assertContents(actual, expected, null); + } + + public static void assertContents(Iterator actual, Iterator expected, String msg) { List history = new ArrayList<>(); while (expected.hasNext()) { @@ -128,20 +140,23 @@ public class CollectionAsserts { List expectedData = new ArrayList<>(history); while (expected.hasNext()) expectedData.add(expected.next()); - fail(String.format("Premature end of data; expected=%s, found=%s", expectedData, history)); + fail(String.format("%s Premature end of data; expected=%s, found=%s", + (msg == null ? "" : msg), expectedData, history)); } T a = actual.next(); T e = expected.next(); history.add(a); if (!Objects.equals(a, e)) - fail(String.format("Data mismatch; preceding=%s, nextExpected=%s, nextFound=%s", history, e, a)); + fail(String.format("%s Data mismatch; preceding=%s, nextExpected=%s, nextFound=%s", + (msg == null ? "" : msg), history, e, a)); } if (actual.hasNext()) { List rest = new ArrayList<>(); while (actual.hasNext()) rest.add(actual.next()); - fail(String.format("Unexpected data %s after %s", rest, history)); + fail(String.format("%s Unexpected data %s after %s", + (msg == null ? "" : msg), rest, history)); } } @@ -151,30 +166,21 @@ public class CollectionAsserts { assertContents(actual, Arrays.asList(expected).iterator()); } - public static boolean equalsContentsUnordered(Iterable a, Iterable b) { - Set sa = new HashSet<>(); - for (T t : a) { - sa.add(t); - } - - Set sb = new HashSet<>(); - for (T t : b) { - sb.add(t); - } - - return Objects.equals(sa, sb); + public static> void assertContentsUnordered(Iterable actual, Iterable expected) { + assertContentsUnordered(actual, expected, null); } - public static> void assertContentsUnordered(Iterable actual, Iterable expected) { - ArrayList one = new ArrayList<>(); - for (T t : actual) - one.add(t); - ArrayList two = new ArrayList<>(); - for (T t : expected) - two.add(t); - Collections.sort(one); - Collections.sort(two); - assertContents(one, two); + public static> void assertContentsUnordered(Iterable actual, Iterable expected, String msg) { + List allExpected = new ArrayList<>(); + for (T t : expected) { + allExpected.add(t); + } + + for (T t : actual) { + assertTrue(allExpected.remove(t), msg + " element '" + String.valueOf(t) + "' not found"); + } + + assertTrue(allExpected.isEmpty(), msg + "expected contained additional elements"); } static void assertSplitContents(Iterable> splits, Iterable list) { diff --git a/jdk/test/java/util/Collection/testlibrary/CollectionSupplier.java b/jdk/test/java/util/Collection/testlibrary/CollectionSupplier.java index c26aaa7385f..37b3e53739c 100644 --- a/jdk/test/java/util/Collection/testlibrary/CollectionSupplier.java +++ b/jdk/test/java/util/Collection/testlibrary/CollectionSupplier.java @@ -29,13 +29,11 @@ import java.util.Arrays; import java.util.LinkedList; import java.util.List; import java.util.Random; -import java.util.Set; import org.testng.TestException; import static org.testng.Assert.assertTrue; -import java.lang.reflect.Constructor; import java.util.Collection; import java.util.Collections; import java.util.function.Supplier; @@ -44,73 +42,61 @@ import java.util.function.Supplier; * @library * @summary A Supplier of test cases for Collection tests */ -public final class CollectionSupplier implements Supplier> { +public final class CollectionSupplier> implements Supplier>> { - private final String[] classNames; + private final Supplier[] classes; private final int size; /** * A Collection test case. */ - public static final class TestCase { + public static final class TestCase> { /** * The name of the test case. */ public final String name; - /** - * Class name of the instantiated Collection. - */ - public final String className; - /** * Unmodifiable reference collection, useful for comparisons. */ - public final Collection original; + public final List expected; /** * A modifiable test collection. */ - public final Collection collection; + public final C collection; /** * Create a Collection test case. + * * @param name name of the test case - * @param className class name of the instantiated collection - * @param original reference collection + * @param expected reference collection * @param collection the modifiable test collection */ - public TestCase(String name, String className, - Collection original, Collection collection) { + public TestCase(String name, C collection) { this.name = name; - this.className = className; - this.original = - List.class.isAssignableFrom(original.getClass()) ? - Collections.unmodifiableList((List) original) : - Set.class.isAssignableFrom(original.getClass()) ? - Collections.unmodifiableSet((Set) original) : - Collections.unmodifiableCollection(original); + this.expected = Collections.unmodifiableList( + Arrays.asList(collection.toArray(new Integer[0]))); this.collection = collection; } @Override public String toString() { - return name + " " + className + - "\n original: " + original + - "\n target: " + collection; + return name + " " + collection.getClass().toString(); } } /** * Shuffle a list using a PRNG with known seed for repeatability + * * @param list the list to be shuffled */ public static void shuffle(final List list) { // PRNG with known seed for repeatable tests final Random prng = new Random(13); final int size = list.size(); - for (int i=0; i < size; i++) { + for (int i = 0; i < size; i++) { // random index in interval [i, size) final int j = i + prng.nextInt(size - i); // swap elements at indices i & j @@ -127,178 +113,133 @@ public final class CollectionSupplier implements Supplier[] classes, int size) { + this.classes = Arrays.copyOf(classes, classes.length); this.size = size; } @Override - public Iterable get() { - try { - return getThrows(); - } catch (Exception e) { - throw new TestException(e); - } - } + public Iterable> get() { + final Collection> cases = new LinkedList<>(); + for (final Supplier type : classes) { + try { + final Collection empty = type.get(); + cases.add(new TestCase("empty", empty)); - private Iterable getThrows() throws Exception { - final Collection collections = new LinkedList<>(); - for (final String className : classNames) { - @SuppressWarnings("unchecked") - final Class> type = - (Class>) Class.forName(className); - final Constructor> - defaultConstructor = type.getConstructor(); - final Constructor> - copyConstructor = type.getConstructor(Collection.class); + final Collection single = type.get(); + single.add(42); + cases.add(new TestCase("single", single)); - final Collection empty = defaultConstructor.newInstance(); - collections.add(new TestCase("empty", - className, - copyConstructor.newInstance(empty), - empty)); - - final Collection single = defaultConstructor.newInstance(); - single.add(42); - collections.add(new TestCase("single", - className, - copyConstructor.newInstance(single), - single)); - - final Collection regular = defaultConstructor.newInstance(); - for (int i=0; i < size; i++) { - regular.add(i); - } - collections.add(new TestCase("regular", - className, - copyConstructor.newInstance(regular), - regular)); - - final Collection reverse = defaultConstructor.newInstance(); - for (int i=size; i >= 0; i--) { - reverse.add(i); - } - collections.add(new TestCase("reverse", - className, - copyConstructor.newInstance(reverse), - reverse)); - - final Collection odds = defaultConstructor.newInstance(); - for (int i=0; i < size; i++) { - odds.add((i * 2) + 1); - } - collections.add(new TestCase("odds", - className, - copyConstructor.newInstance(odds), - odds)); - - final Collection evens = defaultConstructor.newInstance(); - for (int i=0; i < size; i++) { - evens.add(i * 2); - } - collections.add(new TestCase("evens", - className, - copyConstructor.newInstance(evens), - evens)); - - final Collection fibonacci = defaultConstructor.newInstance(); - int prev2 = 0; - int prev1 = 1; - for (int i=0; i < size; i++) { - final int n = prev1 + prev2; - if (n < 0) { // stop on overflow - break; + final Collection regular = type.get(); + for (int i = 0; i < size; i++) { + regular.add(i); } - fibonacci.add(n); - prev2 = prev1; - prev1 = n; - } - collections.add(new TestCase("fibonacci", - className, - copyConstructor.newInstance(fibonacci), - fibonacci)); + cases.add(new TestCase("regular", regular)); + + final Collection reverse = type.get(); + for (int i = size; i >= 0; i--) { + reverse.add(i); + } + cases.add(new TestCase("reverse", reverse)); + + final Collection odds = type.get(); + for (int i = 0; i < size; i++) { + odds.add((i * 2) + 1); + } + cases.add(new TestCase("odds", odds)); + + final Collection evens = type.get(); + for (int i = 0; i < size; i++) { + evens.add(i * 2); + } + cases.add(new TestCase("evens", evens)); + + final Collection fibonacci = type.get(); + int prev2 = 0; + int prev1 = 1; + for (int i = 0; i < size; i++) { + final int n = prev1 + prev2; + if (n < 0) { // stop on overflow + break; + } + fibonacci.add(n); + prev2 = prev1; + prev1 = n; + } + cases.add(new TestCase("fibonacci", fibonacci)); // variants where the size of the backing storage != reported size - // created by removing half of the elements + // created by removing half of the elements + final Collection emptyWithSlack = type.get(); + emptyWithSlack.add(42); + assertTrue(emptyWithSlack.remove(42)); + cases.add(new TestCase("emptyWithSlack", emptyWithSlack)); - final Collection emptyWithSlack = defaultConstructor.newInstance(); - emptyWithSlack.add(42); - assertTrue(emptyWithSlack.remove(42)); - collections.add(new TestCase("emptyWithSlack", - className, - copyConstructor.newInstance(emptyWithSlack), - emptyWithSlack)); + final Collection singleWithSlack = type.get(); + singleWithSlack.add(42); + singleWithSlack.add(43); + assertTrue(singleWithSlack.remove(43)); + cases.add(new TestCase("singleWithSlack", singleWithSlack)); - final Collection singleWithSlack = defaultConstructor.newInstance(); - singleWithSlack.add(42); - singleWithSlack.add(43); - assertTrue(singleWithSlack.remove(43)); - collections.add(new TestCase("singleWithSlack", - className, - copyConstructor.newInstance(singleWithSlack), - singleWithSlack)); - - final Collection regularWithSlack = defaultConstructor.newInstance(); - for (int i=0; i < (2 * size); i++) { - regularWithSlack.add(i); - } - assertTrue(regularWithSlack.removeIf((x) -> {return x >= size;})); - collections.add(new TestCase("regularWithSlack", - className, - copyConstructor.newInstance(regularWithSlack), - regularWithSlack)); - - final Collection reverseWithSlack = defaultConstructor.newInstance(); - for (int i=2 * size; i >= 0; i--) { - reverseWithSlack.add(i); - } - assertTrue(reverseWithSlack.removeIf((x) -> {return x < size;})); - collections.add(new TestCase("reverseWithSlack", - className, - copyConstructor.newInstance(reverseWithSlack), - reverseWithSlack)); - - final Collection oddsWithSlack = defaultConstructor.newInstance(); - for (int i = 0; i < 2 * size; i++) { - oddsWithSlack.add((i * 2) + 1); - } - assertTrue(oddsWithSlack.removeIf((x) -> {return x >= size;})); - collections.add(new TestCase("oddsWithSlack", - className, - copyConstructor.newInstance(oddsWithSlack), - oddsWithSlack)); - - final Collection evensWithSlack = defaultConstructor.newInstance(); - for (int i = 0; i < 2 * size; i++) { - evensWithSlack.add(i * 2); - } - assertTrue(evensWithSlack.removeIf((x) -> {return x >= size;})); - collections.add(new TestCase("evensWithSlack", - className, - copyConstructor.newInstance(evensWithSlack), - evensWithSlack)); - - final Collection fibonacciWithSlack = defaultConstructor.newInstance(); - prev2 = 0; - prev1 = 1; - for (int i=0; i < size; i++) { - final int n = prev1 + prev2; - if (n < 0) { // stop on overflow - break; + final Collection regularWithSlack = type.get(); + for (int i = 0; i < (2 * size); i++) { + regularWithSlack.add(i); } - fibonacciWithSlack.add(n); - prev2 = prev1; - prev1 = n; - } - assertTrue(fibonacciWithSlack.removeIf((x) -> {return x < 20;})); - collections.add(new TestCase("fibonacciWithSlack", - className, - copyConstructor.newInstance(fibonacciWithSlack), - fibonacciWithSlack)); + assertTrue(regularWithSlack.removeIf((x) -> { + return x >= size; + })); + cases.add(new TestCase("regularWithSlack", regularWithSlack)); + final Collection reverseWithSlack = type.get(); + for (int i = 2 * size; i >= 0; i--) { + reverseWithSlack.add(i); + } + assertTrue(reverseWithSlack.removeIf((x) -> { + return x < size; + })); + cases.add(new TestCase("reverseWithSlack", reverseWithSlack)); + + final Collection oddsWithSlack = type.get(); + for (int i = 0; i < 2 * size; i++) { + oddsWithSlack.add((i * 2) + 1); + } + assertTrue(oddsWithSlack.removeIf((x) -> { + return x >= size; + })); + cases.add(new TestCase("oddsWithSlack", oddsWithSlack)); + + final Collection evensWithSlack = type.get(); + for (int i = 0; i < 2 * size; i++) { + evensWithSlack.add(i * 2); + } + assertTrue(evensWithSlack.removeIf((x) -> { + return x >= size; + })); + cases.add(new TestCase("evensWithSlack", evensWithSlack)); + + final Collection fibonacciWithSlack = type.get(); + prev2 = 0; + prev1 = 1; + for (int i = 0; i < size; i++) { + final int n = prev1 + prev2; + if (n < 0) { // stop on overflow + break; + } + fibonacciWithSlack.add(n); + prev2 = prev1; + prev1 = n; + } + assertTrue(fibonacciWithSlack.removeIf((x) -> { + return x < 20; + })); + cases.add(new TestCase("fibonacciWithSlack", + fibonacciWithSlack)); + } catch (Exception failed) { + throw new TestException(failed); + } } - return collections; + return cases; } } diff --git a/jdk/test/java/util/Collection/testlibrary/ExtendsAbstractCollection.java b/jdk/test/java/util/Collection/testlibrary/ExtendsAbstractCollection.java new file mode 100644 index 00000000000..a22d3d75d15 --- /dev/null +++ b/jdk/test/java/util/Collection/testlibrary/ExtendsAbstractCollection.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2012, 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.AbstractCollection; +import java.util.HashSet; +import java.util.AbstractSet; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.function.Supplier; + +/** + * @library + * + * A simple mutable collection implementation that provides only default + * implementations of all methods. ie. none of the Collection interface default + * methods have overridden implementations. + * + * @param type of collection elements + */ +public class ExtendsAbstractCollection extends AbstractCollection { + + protected final Collection coll; + + public ExtendsAbstractCollection() { + this(ArrayList::new); + } + + public ExtendsAbstractCollection(Collection source) { + this(); + coll.addAll(source); + } + + protected ExtendsAbstractCollection(Supplier> backer) { + this.coll = backer.get(); + } + + public boolean add(E element) { + return coll.add(element); + } + + public boolean remove(Object element) { + return coll.remove(element); + } + + public Iterator iterator() { + return new Iterator() { + Iterator source = coll.iterator(); + + public boolean hasNext() { + return source.hasNext(); + } + + public E next() { + return source.next(); + } + + public void remove() { + source.remove(); + } + }; + } + + public int size() { + return coll.size(); + } +} diff --git a/jdk/test/java/util/Collection/testlibrary/ExtendsAbstractList.java b/jdk/test/java/util/Collection/testlibrary/ExtendsAbstractList.java new file mode 100644 index 00000000000..fb2af523d44 --- /dev/null +++ b/jdk/test/java/util/Collection/testlibrary/ExtendsAbstractList.java @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2012, 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.ArrayList; +import java.util.AbstractList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.function.Supplier; + +/** + * @library + * + * A simple mutable list implementation that provides only default + * implementations of all methods. ie. none of the List interface default + * methods have overridden implementations. + * + * @param type of list elements + */ +public class ExtendsAbstractList extends AbstractList { + + protected final List list; + + public ExtendsAbstractList() { + this(ArrayList::new); + } + + protected ExtendsAbstractList(Supplier> supplier) { + this.list = supplier.get(); + } + + public ExtendsAbstractList(Collection source) { + this(); + addAll(source); + } + + public boolean add(E element) { + return list.add(element); + } + + public E get(int index) { + return list.get(index); + } + + public boolean remove(Object element) { + return list.remove(element); + } + + public E set(int index, E element) { + return list.set(index, element); + } + + public void add(int index, E element) { + list.add(index, element); + } + + public E remove(int index) { + return list.remove(index); + } + + public Iterator iterator() { + return new Iterator() { + Iterator source = list.iterator(); + + public boolean hasNext() { + return source.hasNext(); + } + + public E next() { + return source.next(); + } + + public void remove() { + source.remove(); + } + }; + } + + public int size() { + return list.size(); + } +} diff --git a/jdk/test/java/util/Collection/testlibrary/ExtendsAbstractSet.java b/jdk/test/java/util/Collection/testlibrary/ExtendsAbstractSet.java new file mode 100644 index 00000000000..23661a357a9 --- /dev/null +++ b/jdk/test/java/util/Collection/testlibrary/ExtendsAbstractSet.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2012, 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.HashSet; +import java.util.AbstractSet; +import java.util.Collection; +import java.util.Iterator; +import java.util.Set; +import java.util.function.Supplier; + +/** + * @library + * + * A simple mutable set implementation that provides only default + * implementations of all methods. ie. none of the Set interface default methods + * have overridden implementations. + * + * @param type of set members + */ +public class ExtendsAbstractSet extends AbstractSet { + + protected final Set set; + + public ExtendsAbstractSet() { + this(HashSet::new); + } + + public ExtendsAbstractSet(Collection source) { + this(); + addAll(source); + } + + protected ExtendsAbstractSet(Supplier> backer) { + this.set = backer.get(); + } + + public boolean add(E element) { + return set.add(element); + } + + public boolean remove(Object element) { + return set.remove(element); + } + + public Iterator iterator() { + return new Iterator() { + Iterator source = set.iterator(); + + public boolean hasNext() { + return source.hasNext(); + } + + public E next() { + return source.next(); + } + + public void remove() { + source.remove(); + } + }; + } + + public int size() { + return set.size(); + } +} diff --git a/jdk/test/java/util/Collection/ListDefaults.java b/jdk/test/java/util/List/ListDefaults.java similarity index 88% rename from jdk/test/java/util/Collection/ListDefaults.java rename to jdk/test/java/util/List/ListDefaults.java index 0d7a29152f6..76734b4e4be 100644 --- a/jdk/test/java/util/Collection/ListDefaults.java +++ b/jdk/test/java/util/List/ListDefaults.java @@ -28,8 +28,6 @@ import java.util.Comparator; import java.util.List; import java.util.LinkedList; import java.util.Stack; -import java.util.TreeMap; -import java.util.TreeSet; import java.util.Vector; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.atomic.AtomicBoolean; @@ -46,28 +44,30 @@ import static org.testng.Assert.fail; import java.lang.reflect.Constructor; import java.util.ConcurrentModificationException; import java.util.function.Predicate; +import java.util.function.Supplier; /** * @test - * @bug 8023367 - * @library testlibrary - * @build CollectionAsserts CollectionSupplier - * @run testng ListDefaults * @summary Unit tests for extension methods on List + * @bug 8023367 + * @library ../Collection/testlibrary + * @build CollectionAsserts CollectionSupplier ExtendsAbstractList + * @run testng ListDefaults */ public class ListDefaults { - private static final String[] LIST_CLASSES = { - "java.util.ArrayList", - "java.util.LinkedList", - "java.util.Vector", - "java.util.concurrent.CopyOnWriteArrayList" - }; + private static final Supplier[] LIST_CLASSES = { + java.util.ArrayList::new, + java.util.LinkedList::new, + java.util.Vector::new, + java.util.concurrent.CopyOnWriteArrayList::new, + ExtendsAbstractList::new + }; - private static final String[] LIST_CME_CLASSES = { - "java.util.ArrayList", - "java.util.Vector" - }; + private static final Supplier[] LIST_CME_CLASSES = { + java.util.ArrayList::new, + java.util.Vector::new + }; private static final Predicate pEven = x -> 0 == x % 2; private static final Predicate pOdd = x -> 1 == x % 2; @@ -139,13 +139,9 @@ public class ListDefaults { @Test public void testForEach() throws Exception { - final CollectionSupplier supplier = new CollectionSupplier(LIST_CLASSES, SIZE); - for (final CollectionSupplier.TestCase test : supplier.get()) { - final List original = ((List) test.original); - final List list = ((List) test.collection); - } - for (final CollectionSupplier.TestCase test : supplier.get()) { - final List original = ((List) test.original); + final CollectionSupplier> supplier = new CollectionSupplier((Supplier>[])LIST_CLASSES, SIZE); + for (final CollectionSupplier.TestCase> test : supplier.get()) { + final List original = ((List) test.expected); final List list = ((List) test.collection); try { @@ -182,10 +178,9 @@ public class ListDefaults { @Test public void testRemoveIf() throws Exception { - final CollectionSupplier supplier = new CollectionSupplier(LIST_CLASSES, SIZE); - - for (final CollectionSupplier.TestCase test : supplier.get()) { - final List original = ((List) test.original); + final CollectionSupplier> supplier = new CollectionSupplier((Supplier>[])LIST_CLASSES, SIZE); + for (final CollectionSupplier.TestCase> test : supplier.get()) { + final List original = ((List) test.expected); final List list = ((List) test.collection); try { @@ -201,7 +196,7 @@ public class ListDefaults { } for (final CollectionSupplier.TestCase test : supplier.get()) { - final List original = ((List) test.original); + final List original = ((List) test.expected); final List list = ((List) test.collection); list.removeIf(pOdd); for (int i : list) { @@ -217,7 +212,7 @@ public class ListDefaults { } for (final CollectionSupplier.TestCase test : supplier.get()) { - final List original = ((List) test.original); + final List original = ((List) test.expected); final List list = ((List) test.collection); final List listCopy = new ArrayList<>(list); if (original.size() > SUBLIST_SIZE) { @@ -274,9 +269,9 @@ public class ListDefaults { @Test public void testReplaceAll() throws Exception { final int scale = 3; - final CollectionSupplier supplier = new CollectionSupplier(LIST_CLASSES, SIZE); - for (final CollectionSupplier.TestCase test : supplier.get()) { - final List original = ((List) test.original); + final CollectionSupplier> supplier = new CollectionSupplier((Supplier>[])LIST_CLASSES, SIZE); + for (final CollectionSupplier.TestCase> test : supplier.get()) { + final List original = ((List) test.expected); final List list = ((List) test.collection); try { @@ -329,9 +324,9 @@ public class ListDefaults { @Test public void testSort() throws Exception { - final CollectionSupplier supplier = new CollectionSupplier(LIST_CLASSES, SIZE); - for (final CollectionSupplier.TestCase test : supplier.get()) { - final List original = ((List) test.original); + final CollectionSupplier> supplier = new CollectionSupplier((Supplier>[])LIST_CLASSES, SIZE); + for (final CollectionSupplier.TestCase> test : supplier.get()) { + final List original = ((List) test.expected); final List list = ((List) test.collection); CollectionSupplier.shuffle(list); list.sort(Integer::compare); @@ -378,17 +373,15 @@ public class ListDefaults { } @SuppressWarnings("unchecked") - final Class> type = - (Class>) Class.forName(test.className); - final Constructor> defaultConstructor = type.getConstructor(); + final Constructor> defaultConstructor = ((Class>)test.collection.getClass()).getConstructor(); final List incomparables = (List) defaultConstructor.newInstance(); - for (int i=0; i < test.original.size(); i++) { + for (int i=0; i < test.expected.size(); i++) { incomparables.add(new AtomicInteger(i)); } CollectionSupplier.shuffle(incomparables); incomparables.sort(ATOMIC_INTEGER_COMPARATOR); - for (int i=0; i < test.original.size(); i++) { + for (int i=0; i < test.expected.size(); i++) { assertEquals(i, incomparables.get(i).intValue()); } @@ -427,9 +420,10 @@ public class ListDefaults { @Test public void testForEachThrowsCME() throws Exception { - final CollectionSupplier supplier = new CollectionSupplier(LIST_CME_CLASSES, SIZE); - for (final CollectionSupplier.TestCase test : supplier.get()) { + final CollectionSupplier> supplier = new CollectionSupplier((Supplier>[])LIST_CME_CLASSES, SIZE); + for (final CollectionSupplier.TestCase> test : supplier.get()) { final List list = ((List) test.collection); + if (list.size() <= 1) { continue; } @@ -448,9 +442,11 @@ public class ListDefaults { @Test public void testRemoveIfThrowsCME() throws Exception { - final CollectionSupplier supplier = new CollectionSupplier(LIST_CME_CLASSES, SIZE); - for (final CollectionSupplier.TestCase test : supplier.get()) { + final CollectionSupplier> supplier = new CollectionSupplier((Supplier>[])LIST_CME_CLASSES, SIZE); + for (final CollectionSupplier.TestCase> test : supplier.get()) { + final List original = ((List) test.expected); final List list = ((List) test.collection); + if (list.size() <= 1) { continue; } @@ -469,9 +465,10 @@ public class ListDefaults { @Test public void testReplaceAllThrowsCME() throws Exception { - final CollectionSupplier supplier = new CollectionSupplier(LIST_CME_CLASSES, SIZE); - for (final CollectionSupplier.TestCase test : supplier.get()) { + final CollectionSupplier> supplier = new CollectionSupplier((Supplier>[])LIST_CME_CLASSES, SIZE); + for (final CollectionSupplier.TestCase> test : supplier.get()) { final List list = ((List) test.collection); + if (list.size() <= 1) { continue; } @@ -490,9 +487,10 @@ public class ListDefaults { @Test public void testSortThrowsCME() throws Exception { - final CollectionSupplier supplier = new CollectionSupplier(LIST_CME_CLASSES, SIZE); - for (final CollectionSupplier.TestCase test : supplier.get()) { + final CollectionSupplier> supplier = new CollectionSupplier((Supplier>[])LIST_CME_CLASSES, SIZE); + for (final CollectionSupplier.TestCase> test : supplier.get()) { final List list = ((List) test.collection); + if (list.size() <= 1) { continue; } @@ -520,6 +518,7 @@ public class ListDefaults { cases.add(new Object[] { new LinkedList<>(Arrays.asList(DATA)) }); cases.add(new Object[] { new Vector<>(Arrays.asList(DATA)) }); cases.add(new Object[] { new CopyOnWriteArrayList<>(Arrays.asList(DATA)) }); + cases.add(new Object[] { new ExtendsAbstractList<>(Arrays.asList(DATA)) }); return cases.toArray(new Object[0][cases.size()]); } diff --git a/jdk/test/java/util/Map/Defaults.java b/jdk/test/java/util/Map/Defaults.java index 48a93525b7f..82470019048 100644 --- a/jdk/test/java/util/Map/Defaults.java +++ b/jdk/test/java/util/Map/Defaults.java @@ -155,7 +155,7 @@ public class Defaults { assertThrows( () -> { map.replaceAll((k,v) -> null); }, NullPointerException.class, - description); + description + " should not allow replacement with null value"); } @Test(dataProvider = "Map rw=true keys=withNull values=withNull") @@ -194,6 +194,15 @@ public class Defaults { assertSame(map.get(null), EXTRA_VALUE); } + @Test(dataProvider = "Map rw=true keys=nonNull values=nonNull") + public void testReplaceKVNoNulls(String description, Map map) { + assertTrue(map.containsKey(FIRST_KEY), "expected key missing"); + assertSame(map.get(FIRST_KEY), FIRST_VALUE, "found wrong value"); + assertThrows( () -> {map.replace(FIRST_KEY, null);}, NullPointerException.class, description + ": should throw NPE"); + assertSame(map.replace(FIRST_KEY, EXTRA_VALUE), FIRST_VALUE, description + ": replaced wrong value"); + assertSame(map.get(FIRST_KEY), EXTRA_VALUE, "found wrong value"); + } + @Test(dataProvider = "Map rw=true keys=all values=all") public void testReplaceKV(String description, Map map) { assertTrue(map.containsKey(KEYS[1])); @@ -224,6 +233,16 @@ public class Defaults { assertSame(map.get(null), EXTRA_VALUE); } + @Test(dataProvider = "Map rw=true keys=nonNull values=nonNull") + public void testReplaceKVVNoNulls(String description, Map map) { + assertTrue(map.containsKey(FIRST_KEY), "expected key missing"); + assertSame(map.get(FIRST_KEY), FIRST_VALUE, "found wrong value"); + assertThrows( () -> {map.replace(FIRST_KEY, FIRST_VALUE, null);}, NullPointerException.class, description + ": should throw NPE"); + assertThrows( () -> {if (!map.replace(FIRST_KEY, null, EXTRA_VALUE)) throw new NullPointerException("default returns false rather than throwing");}, NullPointerException.class, description + ": should throw NPE"); + assertTrue(map.replace(FIRST_KEY, FIRST_VALUE, EXTRA_VALUE), description + ": replaced wrong value"); + assertSame(map.get(FIRST_KEY), EXTRA_VALUE, "found wrong value"); + } + @Test(dataProvider = "Map rw=true keys=all values=all") public void testReplaceKVV(String description, Map map) { assertTrue(map.containsKey(KEYS[1])); @@ -470,6 +489,9 @@ public class Defaults { VALUES[each] = String.valueOf(each); } } + + private static final IntegerEnum FIRST_KEY = KEYS[0]; + private static final String FIRST_VALUE = VALUES[0]; private static final IntegerEnum EXTRA_KEY = IntegerEnum.EXTRA_KEY; private static final String EXTRA_VALUE = String.valueOf(TEST_SIZE); @@ -583,6 +605,8 @@ public class Defaults { return Arrays.asList( // null key hostile new Object[]{"EnumMap", makeMap(() -> new EnumMap(IntegerEnum.class), false, nulls)}, + new Object[]{"TreeMap", makeMap(TreeMap::new, false, nulls)}, + new Object[]{"ExtendsAbstractMap(TreeMap)", makeMap(() -> {return new ExtendsAbstractMap(new TreeMap());}, false, nulls)}, new Object[]{"Collections.synchronizedMap(EnumMap)", Collections.synchronizedMap(makeMap(() -> new EnumMap(IntegerEnum.class), false, nulls))} ); } @@ -591,10 +615,11 @@ public class Defaults { return Arrays.asList( // null key and value hostile new Object[]{"Hashtable", makeMap(Hashtable::new, false, false)}, - new Object[]{"TreeMap", makeMap(TreeMap::new, false, false)}, new Object[]{"ConcurrentHashMap", makeMap(ConcurrentHashMap::new, false, false)}, new Object[]{"ConcurrentSkipListMap", makeMap(ConcurrentSkipListMap::new, false, false)}, + new Object[]{"Collections.synchronizedMap(ConcurrentHashMap)", Collections.synchronizedMap(makeMap(ConcurrentHashMap::new, false, false))}, new Object[]{"Collections.checkedMap(ConcurrentHashMap)", Collections.checkedMap(makeMap(ConcurrentHashMap::new, false, false), IntegerEnum.class, String.class)}, + new Object[]{"ExtendsAbstractMap(ConcurrentHashMap)", makeMap(() -> {return new ExtendsAbstractMap(new ConcurrentHashMap());}, false, false)}, new Object[]{"ImplementsConcurrentMap", makeMap(ImplementsConcurrentMap::new, false, false)} ); } @@ -641,18 +666,17 @@ public class Defaults { } public static void assertThrows(Thrower thrower, Class throwable, String message) { - Throwable result; + Throwable thrown; try { thrower.run(); - result = null; + thrown = null; } catch (Throwable caught) { - result = caught; + thrown = caught; } - assertInstance(result, throwable, - (null != message) - ? message - : "Failed to throw " + throwable.getCanonicalName()); + assertInstance(thrown, throwable, + ((null != message) ? message : "") + + " Failed to throw " + throwable.getCanonicalName()); } public static void assertThrows(Class throwable, String message, Thrower... throwers) { @@ -661,11 +685,11 @@ public class Defaults { } } - public static void assertInstance(T actual, Class expected) { + public static void assertInstance(Object actual, Class expected) { assertInstance(expected.isInstance(actual), null); } - public static void assertInstance(T actual, Class expected, String message) { + public static void assertInstance(Object actual, Class expected, String message) { assertTrue(expected.isInstance(actual), message); } From c712fac717b3874071b41400865f070b4fa77868 Mon Sep 17 00:00:00 2001 From: Mike Duigou Date: Fri, 13 Sep 2013 11:19:13 -0700 Subject: [PATCH 076/210] 8024014: TEST.groups - split sub-groups for jdk_collections, jdk_stream, jdk_concurrent, jdk_util_other from jdk_util Reviewed-by: mchung, dholmes, alanb --- jdk/test/TEST.groups | 58 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/jdk/test/TEST.groups b/jdk/test/TEST.groups index a59b38853ff..23c9a833209 100644 --- a/jdk/test/TEST.groups +++ b/jdk/test/TEST.groups @@ -20,6 +20,7 @@ # questions. # +# java.lang package and VM runtime support jdk_lang = \ java/lang \ -java/lang/management \ @@ -30,9 +31,64 @@ jdk_lang = \ jdk/lambda \ vm +# All of the java.util package jdk_util = \ + :jdk_util_other \ + :jdk_collections \ + :jdk_concurrent \ + :jdk_stream + +# All util components not part of some other util category +jdk_util_other = \ java/util \ - sun/util + sun/util \ + -:jdk_collections \ + -:jdk_concurrent \ + -:jdk_stream + +# java.util.concurrent (JSR-166) +# Maintained by JSR-166 EG (Doug Lea et al) +# Deque and PriorityQueue are also generally maintained by JSR-166 +jdk_concurrent = \ + java/util/concurrent \ + java/util/Deque \ + java/util/PriorityQueue + +# Java Collections Framework +jdk_collections = \ + java/util/AbstractCollection \ + java/util/AbstractList \ + java/util/AbstractMap \ + java/util/AbstractSequentialList \ + java/util/ArrayList \ + java/util/Arrays \ + java/util/BitSet \ + java/util/Collection \ + java/util/Collections \ + java/util/EnumMap \ + java/util/EnumSet \ + java/util/Comparator \ + java/util/Iterator \ + java/util/HashMap \ + java/util/Hashtable \ + java/util/IdentityHashMap \ + java/util/List \ + java/util/LinkedHashMap \ + java/util/LinkedHashSet \ + java/util/LinkedList \ + java/util/Map \ + java/util/NavigableMap \ + java/util/TimSort \ + java/util/TreeMap \ + java/util/Vector \ + java/util/WeakHashMap + +# java.util.stream (JSR-335) +jdk_stream = \ + java/util/Optional \ + java/util/SummaryStatistics \ + java/util/function \ + java/util/stream jdk_math = \ java/math From ac02958e79178cd05ac03c31757921a9268745c2 Mon Sep 17 00:00:00 2001 From: Brent Christian Date: Fri, 13 Sep 2013 11:26:44 -0700 Subject: [PATCH 077/210] 7199674: (props) user.home property does not return an accessible location in sandboxed environment [macosx] On MacOS X set user.home to value of NSHomeDirectory() Reviewed-by: alanb, ddehaven, mduigou --- jdk/make/common/Defs-macosx.gmk | 10 ++++------ jdk/make/java/java/Makefile | 1 + jdk/makefiles/CompileNativeLibraries.gmk | 2 ++ .../solaris/native/java/lang/java_props_macosx.c | 14 +++++++++++++- .../solaris/native/java/lang/java_props_macosx.h | 1 + jdk/src/solaris/native/java/lang/java_props_md.c | 9 ++++++++- 6 files changed, 29 insertions(+), 8 deletions(-) diff --git a/jdk/make/common/Defs-macosx.gmk b/jdk/make/common/Defs-macosx.gmk index 1b7aaa8ae20..befd2cfed5b 100644 --- a/jdk/make/common/Defs-macosx.gmk +++ b/jdk/make/common/Defs-macosx.gmk @@ -397,12 +397,10 @@ else INCLUDE_SA = true endif -ifdef CROSS_COMPILE_ARCH - # X11 headers are not under /usr/include - OTHER_CFLAGS += -I$(OPENWIN_HOME)/include - OTHER_CXXFLAGS += -I$(OPENWIN_HOME)/include - OTHER_CPPFLAGS += -I$(OPENWIN_HOME)/include -endif +# X11 headers are not under /usr/include +OTHER_CFLAGS += -I$(OPENWIN_HOME)/include +OTHER_CXXFLAGS += -I$(OPENWIN_HOME)/include +OTHER_CPPFLAGS += -I$(OPENWIN_HOME)/include LIB_LOCATION ?= $(LIBDIR) diff --git a/jdk/make/java/java/Makefile b/jdk/make/java/java/Makefile index 829cf933001..d2a663f9ae0 100644 --- a/jdk/make/java/java/Makefile +++ b/jdk/make/java/java/Makefile @@ -105,6 +105,7 @@ FILES_java += java/util/prefs/MacOSXPreferences.java \ java/util/prefs/MacOSXPreferencesFactory.java CFLAGS_$(VARIANT)/java_props_md.o = -Os -x objective-c +CFLAGS_$(VARIANT)/java_props_macosx.o = -Os -x objective-c endif # diff --git a/jdk/makefiles/CompileNativeLibraries.gmk b/jdk/makefiles/CompileNativeLibraries.gmk index 656ee3c4841..d507c92a594 100644 --- a/jdk/makefiles/CompileNativeLibraries.gmk +++ b/jdk/makefiles/CompileNativeLibraries.gmk @@ -211,6 +211,7 @@ ifneq ($(OPENJDK_TARGET_OS),macosx) LIBJAVA_EXCLUDE_FILES += java_props_macosx.c else BUILD_LIBJAVA_java_props_md.c_CFLAGS:=-x objective-c + BUILD_LIBJAVA_java_props_macosx.c_CFLAGS:=-x objective-c endif ifeq ($(OPENJDK_TARGET_OS),windows) @@ -252,6 +253,7 @@ $(eval $(call SetupNativeCompilation,BUILD_LIBJAVA,\ LDFLAGS_SUFFIX_linux:=$(LIBDL) $(BUILD_LIBFDLIBM),\ LDFLAGS_SUFFIX_macosx:=-L$(JDK_OUTPUTDIR)/objs/ -lfdlibm \ -framework CoreFoundation \ + -framework Foundation \ -framework Security -framework SystemConfiguration, \ LDFLAGS_SUFFIX_windows:=-export:winFileHandleOpen -export:handleLseek \ jvm.lib $(BUILD_LIBFDLIBM) $(WIN_VERIFY_LIB) \ diff --git a/jdk/src/solaris/native/java/lang/java_props_macosx.c b/jdk/src/solaris/native/java/lang/java_props_macosx.c index f9ad2e474b1..13fc80d3052 100644 --- a/jdk/src/solaris/native/java/lang/java_props_macosx.c +++ b/jdk/src/solaris/native/java/lang/java_props_macosx.c @@ -31,6 +31,7 @@ #include #include #include +#include #include "java_props_macosx.h" @@ -271,9 +272,20 @@ static char * createConvertedException(CFStringRef cf_original) { return c_exception; } +/* + * Method for fetching the user.home path and storing it in the property list. + * For signed .apps running in the Mac App Sandbox, user.home is set to the + * app's sandbox container. + */ +void setUserHome(java_props_t *sprops) { + if (sprops == NULL) { return; } + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + sprops->user_home = createUTF8CString((CFStringRef)NSHomeDirectory()); + [pool drain]; +} /* - * Method for fetching proxy info and storing it in the propery list. + * Method for fetching proxy info and storing it in the property list. */ void setProxyProperties(java_props_t *sProps) { if (sProps == NULL) return; diff --git a/jdk/src/solaris/native/java/lang/java_props_macosx.h b/jdk/src/solaris/native/java/lang/java_props_macosx.h index b311804835d..19ec220ed4b 100644 --- a/jdk/src/solaris/native/java/lang/java_props_macosx.h +++ b/jdk/src/solaris/native/java/lang/java_props_macosx.h @@ -27,6 +27,7 @@ char *setupMacOSXLocale(int cat); void setOSNameAndVersion(java_props_t *sprops); +void setUserHome(java_props_t *sprops); void setProxyProperties(java_props_t *sProps); enum PreferredToolkit_enum { diff --git a/jdk/src/solaris/native/java/lang/java_props_md.c b/jdk/src/solaris/native/java/lang/java_props_md.c index 58e5e4543d7..dba053e8f4a 100644 --- a/jdk/src/solaris/native/java/lang/java_props_md.c +++ b/jdk/src/solaris/native/java/lang/java_props_md.c @@ -591,7 +591,14 @@ GetJavaProperties(JNIEnv *env) { struct passwd *pwent = getpwuid(getuid()); sprops.user_name = pwent ? strdup(pwent->pw_name) : "?"; - sprops.user_home = pwent ? strdup(pwent->pw_dir) : "?"; +#ifdef MACOSX + setUserHome(&sprops); +#else + sprops.user_home = pwent ? strdup(pwent->pw_dir) : NULL; +#endif + if (sprops.user_home == NULL) { + sprops.user_home = "?"; + } } /* User TIMEZONE */ From 320e8d21e860d431a21d98f6c44956a7f790e3e4 Mon Sep 17 00:00:00 2001 From: Lance Andersen Date: Fri, 13 Sep 2013 19:10:31 -0400 Subject: [PATCH 078/210] 8014967: EBehavior of DriverManager.registerDriver(dr) is unspecified if driver is null Reviewed-by: alanb --- jdk/src/share/classes/java/sql/DriverManager.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/jdk/src/share/classes/java/sql/DriverManager.java b/jdk/src/share/classes/java/sql/DriverManager.java index 797a920d230..bd16f92de7b 100644 --- a/jdk/src/share/classes/java/sql/DriverManager.java +++ b/jdk/src/share/classes/java/sql/DriverManager.java @@ -326,6 +326,7 @@ public class DriverManager { * @param driver the new JDBC Driver that is to be registered with the * {@code DriverManager} * @exception SQLException if a database access error occurs + * @exception NullPointerException if {@code driver} is null */ public static synchronized void registerDriver(java.sql.Driver driver) throws SQLException { @@ -345,6 +346,7 @@ public class DriverManager { * @param da the {@code DriverAction} implementation to be used when * {@code DriverManager#deregisterDriver} is called * @exception SQLException if a database access error occurs + * @exception NullPointerException if {@code driver} is null */ public static synchronized void registerDriver(java.sql.Driver driver, DriverAction da) From 9bed48236a0b365c5478d5df85fc820eca1dc3f2 Mon Sep 17 00:00:00 2001 From: Henry Jen Date: Fri, 6 Sep 2013 15:36:00 -0700 Subject: [PATCH 079/210] 8024825: Some fixes are missing from java.util.stream spec update Reviewed-by: mduigou --- .../java/util/stream/ReferencePipeline.java | 3 - .../classes/java/util/stream/Stream.java | 6 +- .../java/util/stream/package-info.java | 142 +++++++++--------- 3 files changed, 78 insertions(+), 73 deletions(-) diff --git a/jdk/src/share/classes/java/util/stream/ReferencePipeline.java b/jdk/src/share/classes/java/util/stream/ReferencePipeline.java index 9d6aa59c8a7..0efd978f21c 100644 --- a/jdk/src/share/classes/java/util/stream/ReferencePipeline.java +++ b/jdk/src/share/classes/java/util/stream/ReferencePipeline.java @@ -170,7 +170,6 @@ abstract class ReferencePipeline } @Override - @SuppressWarnings("unchecked") public void accept(P_OUT u) { if (predicate.test(u)) downstream.accept(u); @@ -264,7 +263,6 @@ abstract class ReferencePipeline } @Override - @SuppressWarnings("unchecked") public void accept(P_OUT u) { try (Stream result = mapper.apply(u)) { // We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it @@ -370,7 +368,6 @@ abstract class ReferencePipeline Sink opWrapSink(int flags, Sink sink) { return new Sink.ChainedReference(sink) { @Override - @SuppressWarnings("unchecked") public void accept(P_OUT u) { action.accept(u); downstream.accept(u); diff --git a/jdk/src/share/classes/java/util/stream/Stream.java b/jdk/src/share/classes/java/util/stream/Stream.java index 4a9f05f5103..a48d59d39d9 100644 --- a/jdk/src/share/classes/java/util/stream/Stream.java +++ b/jdk/src/share/classes/java/util/stream/Stream.java @@ -567,8 +567,8 @@ public interface Stream extends BaseStream> { /** * Performs a reduction on the - * elements of this stream, using the provided identity, accumulation - * function, and combining functions. This is equivalent to: + * elements of this stream, using the provided identity, accumulation and + * combining functions. This is equivalent to: *
    {@code
          *     U result = identity;
          *     for (T element : this stream)
    @@ -886,7 +886,7 @@ public interface Stream extends BaseStream> {
          * @return the new stream
          */
         @SafeVarargs
    -    @SuppressWarnings("varargs")
    +    @SuppressWarnings("varargs") // Creating a stream from an array is safe
         public static Stream of(T... values) {
             return Arrays.stream(values);
         }
    diff --git a/jdk/src/share/classes/java/util/stream/package-info.java b/jdk/src/share/classes/java/util/stream/package-info.java
    index 2c01847ace3..440054eb468 100644
    --- a/jdk/src/share/classes/java/util/stream/package-info.java
    +++ b/jdk/src/share/classes/java/util/stream/package-info.java
    @@ -64,7 +64,7 @@
      *     operations and terminal (value- or side-effect-producing) operations.
      *     Intermediate operations are always lazy.
      *     
  • Possibly unbounded. While collections have a finite size, streams - * need not. Short-circuting operations such as {@code limit(n)} or + * need not. Short-circuiting operations such as {@code limit(n)} or * {@code findFirst()} can allow computations on infinite streams to * complete in finite time.
  • *
  • Consumable. The elements of a stream are only visited once during @@ -96,13 +96,13 @@ * *

    Stream operations and pipelines

    * - *

    Stream operations are - * divided into intermediate and terminal operations, and are - * combined to form stream pipelines. A stream pipeline consists of a - * source (such as a {@code Collection}, an array, a generator function, or an - * I/O channel); followed by zero or more intermediate operations such - * as {@code Stream.filter} or {@code Stream.map}; and a terminal - * operation such as {@code Stream.forEach} or {@code Stream.reduce}. + *

    Stream operations are divided into intermediate and + * terminal operations, and are combined to form stream + * pipelines. A stream pipeline consists of a source (such as a + * {@code Collection}, an array, a generator function, or an I/O channel); + * followed by zero or more intermediate operations such as + * {@code Stream.filter} or {@code Stream.map}; and a terminal operation such + * as {@code Stream.forEach} or {@code Stream.reduce}. * *

    Intermediate operations return a new stream. They are always * lazy; executing an intermediate operation such as @@ -176,9 +176,10 @@ * do: * *

    {@code
    - *     int sumOfWeights = widgets.}{@code parallelStream()}{@code .filter(b -> b.getColor() == RED)
    - *                                                .mapToInt(b -> b.getWeight())
    - *                                                .sum();
    + *     int sumOfWeights = widgets.}parallelStream(){@code
    + *                               .filter(b -> b.getColor() == RED)
    + *                               .mapToInt(b -> b.getWeight())
    + *                               .sum();
      * }
    * *

    The only difference between the serial and parallel versions of this @@ -485,13 +486,13 @@ * as it collects together the desired results into a result container such * as a {@code Collection}. * A {@code collect} operation requires three functions: - * a factory function to construct new instances of the result container, an + * a supplier function to construct new instances of the result container, an * accumulator function to incorporate an input element into a result * container, and a combining function to merge the contents of one result * container into another. The form of this is very similar to the general * form of ordinary reduction: *

    {@code
    - *  R collect(Supplier resultFactory,
    + *  R collect(Supplier supplier,
      *               BiConsumer accumulator,
      *               BiConsumer combiner);
      * }
    @@ -525,10 +526,10 @@ * {@code ArrayList}, and the combiner simply uses {@link java.util.ArrayList#addAll addAll} * to copy the strings from one container into the other. * - *

    The three aspects of {@code collect} -- supplier, accumulator, and combiner -- - * are tightly coupled. We can use the abstraction of - * of a {@link java.util.stream.Collector} to capture all three aspects. - * The above example for collecting strings into a {@code List} can be rewritten + *

    The three aspects of {@code collect} -- supplier, accumulator, and + * combiner -- are tightly coupled. We can use the abstraction of a + * {@link java.util.stream.Collector} to capture all three aspects. The + * above example for collecting strings into a {@code List} can be rewritten * using a standard {@code Collector} as: *

    {@code
      *     List strings = stream.map(Object::toString)
    @@ -545,7 +546,7 @@
      * 
    {@code
      *     Collector summingSalaries
      *         = Collectors.summingInt(Employee::getSalary);
    - * } 
    + * }
    * * (The {@code ?} for the second type parameter merely indicates that we don't * care about the intermediate representation used by this collector.) @@ -557,14 +558,15 @@ * Map salariesByDept * = employees.stream().collect(Collectors.groupingBy(Employee::getDepartment, * summingSalaries)); - * }
  • + * }
    * *

    As with the regular reduction operation, {@code collect()} operations can - * only be parallelized if appropriate conditions are met. For any partially accumulated result, - * combining it with an empty result container must produce an equivalent - * result. That is, for a partially accumulated result {@code p} that is the - * result of any series of accumulator and combiner invocations, {@code p} must - * be equivalent to {@code combiner.apply(p, supplier.get())}. + * only be parallelized if appropriate conditions are met. For any partially + * accumulated result, combining it with an empty result container must + * produce an equivalent result. That is, for a partially accumulated result + * {@code p} that is the result of any series of accumulator and combiner + * invocations, {@code p} must be equivalent to + * {@code combiner.apply(p, supplier.get())}. * *

    Further, however the computation is split, it must produce an equivalent * result. For any input elements {@code t1} and {@code t2}, the results @@ -580,7 +582,7 @@ * A a3 = supplier.get(); * accumulator.accept(a3, t2); * R r2 = finisher.apply(combiner.apply(a2, a3)); // result with splitting - * }

    + * }
    * *

    Here, equivalence generally means according to {@link java.lang.Object#equals(Object)}. * but in some cases equivalence may be relaxed to account for differences in @@ -596,8 +598,8 @@ * .collect(Collectors.groupingBy(Transaction::getBuyer)); * }

    * it may actually be counterproductive to perform the operation in parallel. - * This is because the combining step (merging one {@code Map} into another by key) - * can be expensive for some {@code Map} implementations. + * This is because the combining step (merging one {@code Map} into another by + * key) can be expensive for some {@code Map} implementations. * *

    Suppose, however, that the result container used in this reduction * was a concurrently modifiable collection -- such as a @@ -605,8 +607,8 @@ * invocations of the accumulator could actually deposit their results * concurrently into the same shared result container, eliminating the need for * the combiner to merge distinct result containers. This potentially provides - * a boost to the parallel execution performance. We call this a concurrent - * reduction. + * a boost to the parallel execution performance. We call this a + * concurrent reduction. * *

    A {@link java.util.stream.Collector} that supports concurrent reduction is * marked with the {@link java.util.stream.Collector.Characteristics#CONCURRENT} @@ -635,11 +637,11 @@ * (where {@link java.util.stream.Collectors#groupingByConcurrent} is the * concurrent equivalent of {@code groupingBy}). * - *

    Note that if it is important that the elements for a given key appear in the - * order they appear in the source, then we cannot use a concurrent reduction, - * as ordering is one of the casualties of concurrent insertion. We would then - * be constrained to implement either a sequential reduction or a merge-based - * parallel reduction. + *

    Note that if it is important that the elements for a given key appear in + * the order they appear in the source, then we cannot use a concurrent + * reduction, as ordering is one of the casualties of concurrent insertion. + * We would then be constrained to implement either a sequential reduction or + * a merge-based parallel reduction. * *

    Associativity

    * @@ -656,8 +658,8 @@ * So we can evaluate {@code (a op b)} in parallel with {@code (c op d)}, and * then invoke {@code op} on the results. * - *

    Examples of associative operations include numeric addition, min, and max, - * and string concatenation. + *

    Examples of associative operations include numeric addition, min, and + * max, and string concatenation. * *

    Low-level stream construction

    * @@ -665,48 +667,54 @@ * {@link java.util.Collection#stream()} or {@link java.util.Arrays#stream(Object[])} * to obtain a stream. How are those stream-bearing methods implemented? * - *

    The class {@link java.util.stream.StreamSupport} has a number of low-level - * methods for creating a stream, all using some form of a {@link java.util.Spliterator}. - * A spliterator is the parallel analogue of an {@link java.util.Iterator}; it - * describes a (possibly infinite) collection of elements, with support for - * sequentially advancing, bulk traversal, and splitting off some portion of the - * input into another spliterator which can be processed in parallel. At the - * lowest level, all streams are driven by a spliterator. + *

    The class {@link java.util.stream.StreamSupport} has a number of + * low-level methods for creating a stream, all using some form of a + * {@link java.util.Spliterator}. A spliterator is the parallel analogue of an + * {@link java.util.Iterator}; it describes a (possibly infinite) collection of + * elements, with support for sequentially advancing, bulk traversal, and + * splitting off some portion of the input into another spliterator which can + * be processed in parallel. At the lowest level, all streams are driven by a + * spliterator. * - *

    There are a number of implementation choices in implementing a spliterator, - * nearly all of which are tradeoffs between simplicity of implementation and - * runtime performance of streams using that spliterator. The simplest, but - * least performant, way to create a spliterator is to create one from an iterator - * using {@link java.util.Spliterators#spliteratorUnknownSize(java.util.Iterator, int)}. + *

    There are a number of implementation choices in implementing a + * spliterator, nearly all of which are tradeoffs between simplicity of + * implementation and runtime performance of streams using that spliterator. + * The simplest, but least performant, way to create a spliterator is to + * create one from an iterator using + * {@link java.util.Spliterators#spliteratorUnknownSize(java.util.Iterator, int)}. * While such a spliterator will work, it will likely offer poor parallel - * performance, since we have lost sizing information (how big is the underlying - * data set), as well as being constrained to a simplistic splitting algorithm. + * performance, since we have lost sizing information (how big is the + * underlying data set), as well as being constrained to a simplistic + * splitting algorithm. * - *

    A higher-quality spliterator will provide balanced and known-size splits, - * accurate sizing information, and a number of other + *

    A higher-quality spliterator will provide balanced and known-size + * splits, accurate sizing information, and a number of other * {@link java.util.Spliterator#characteristics() characteristics} of the * spliterator or data that can be used by implementations to optimize * execution. * - *

    Spliterators for mutable data sources have an additional challenge; timing - * of binding to the data, since the data could change between the time the - * spliterator is created and the time the stream pipeline is executed. Ideally, - * a spliterator for a stream would report a characteristic of {@code IMMUTABLE} - * or {@code CONCURRENT}; if not it should be late-binding. - * If a source cannot directly supply a recommended spliterator, it may - * indirectly supply a spliterator using a {@code Supplier}, and construct a - * stream via the {@code Supplier}-accepting versions of + *

    Spliterators for mutable data sources have an additional challenge; + * timing of binding to the data, since the data could change between the time + * the spliterator is created and the time the stream pipeline is executed. + * Ideally, a spliterator for a stream would report a characteristic of + + * {@code IMMUTABLE} or {@code CONCURRENT}; if not it should be + * late-binding. If a source + * cannot directly supply a recommended spliterator, it may indirectly supply + * a spliterator using a {@code Supplier}, and construct a stream via the + * {@code Supplier}-accepting versions of * {@link java.util.stream.StreamSupport#stream(Supplier, int, boolean) stream()}. * The spliterator is obtained from the supplier only after the terminal * operation of the stream pipeline commences. * - *

    These requirements significantly reduce the scope of potential interference - * between mutations of the stream source and execution of stream pipelines. - * Streams based on spliterators with the desired characteristics, or those using - * the Supplier-based factory forms, are immune to modifications of the data - * source prior to commencement of the terminal operation (provided the behavioral - * parameters to the stream operations meet the required criteria for non-interference - * and statelessness). See Non-Interference + *

    These requirements significantly reduce the scope of potential + * interference between mutations of the stream source and execution of stream + * pipelines. Streams based on spliterators with the desired characteristics, + * or those using the Supplier-based factory forms, are immune to + * modifications of the data source prior to commencement of the terminal + * operation (provided the behavioral parameters to the stream operations meet + * the required criteria for non-interference and statelessness). See + * Non-Interference * for more details. * * @since 1.8 From e2940a0e2548efe210a16a66d3dd040207db2387 Mon Sep 17 00:00:00 2001 From: Roger Riggs Date: Sat, 14 Sep 2013 13:55:04 -0400 Subject: [PATCH 080/210] 8023639: Difference between LocalTime.now(Clock.systemDefaultZone()) and LocalTime.now() executed successively is more than 100 000 000 nanoseconds for slow machines Test timed out on a slow machine; it is not a conformance test and should be in the test subtree Reviewed-by: darcy, sherman --- .../java/time/tck/java/time/TCKLocalTime.java | 11 ---------- .../time/test/java/time/TestLocalTime.java | 21 +++++++++++++++++++ 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/jdk/test/java/time/tck/java/time/TCKLocalTime.java b/jdk/test/java/time/tck/java/time/TCKLocalTime.java index e0ef94cdadc..dbba80d1cec 100644 --- a/jdk/test/java/time/tck/java/time/TCKLocalTime.java +++ b/jdk/test/java/time/tck/java/time/TCKLocalTime.java @@ -282,17 +282,6 @@ public class TCKLocalTime extends AbstractDateTimeTest { check(LocalTime.MAX, 23, 59, 59, 999999999); } - //----------------------------------------------------------------------- - // now() - //----------------------------------------------------------------------- - @Test - public void now() { - LocalTime expected = LocalTime.now(Clock.systemDefaultZone()); - LocalTime test = LocalTime.now(); - long diff = Math.abs(test.toNanoOfDay() - expected.toNanoOfDay()); - assertTrue(diff < 100000000); // less than 0.1 secs - } - //----------------------------------------------------------------------- // now(ZoneId) //----------------------------------------------------------------------- diff --git a/jdk/test/java/time/test/java/time/TestLocalTime.java b/jdk/test/java/time/test/java/time/TestLocalTime.java index ddd7b0f572e..d7f04ab5af6 100644 --- a/jdk/test/java/time/test/java/time/TestLocalTime.java +++ b/jdk/test/java/time/test/java/time/TestLocalTime.java @@ -61,7 +61,9 @@ package test.java.time; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertSame; +import static org.testng.Assert.assertTrue; +import java.time.Clock; import java.time.LocalTime; import org.testng.annotations.Test; @@ -176,4 +178,23 @@ public class TestLocalTime extends AbstractTest { } } + //----------------------------------------------------------------------- + // now() + //----------------------------------------------------------------------- + @Test + public void now() { + // Warmup the TimeZone data so the following test does not include + // one-time initialization + LocalTime expected = LocalTime.now(Clock.systemDefaultZone()); + + expected = LocalTime.now(Clock.systemDefaultZone()); + LocalTime test = LocalTime.now(); + long diff = test.toNanoOfDay() - expected.toNanoOfDay(); + if (diff < 0) { + // Adjust if for rollover around midnight + diff += 24 * 60 * 60 * 1_000_000_000L; // Nanos Per Day + } + assertTrue(diff < 500000000); // less than 0.5 secs + } + } From e763c78a79d31afd5b9ce9fb04a808dc4f837a4c Mon Sep 17 00:00:00 2001 From: Roger Riggs Date: Sat, 14 Sep 2013 13:55:06 -0400 Subject: [PATCH 081/210] 8023556: Update javadoc for start of Meiji era Correct the javadoc in JapaneseEra.MEIJI to match the implementation Reviewed-by: darcy, sherman --- .../classes/java/time/chrono/JapaneseEra.java | 2 +- .../time/test/java/time/TestLocalTime.java | 27 +++++++++++++------ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/jdk/src/share/classes/java/time/chrono/JapaneseEra.java b/jdk/src/share/classes/java/time/chrono/JapaneseEra.java index 46eee0b59f8..2dbbde3aac2 100644 --- a/jdk/src/share/classes/java/time/chrono/JapaneseEra.java +++ b/jdk/src/share/classes/java/time/chrono/JapaneseEra.java @@ -104,7 +104,7 @@ public final class JapaneseEra static final sun.util.calendar.Era[] ERA_CONFIG; /** - * The singleton instance for the 'Meiji' era (1868-09-08 - 1912-07-29) + * The singleton instance for the 'Meiji' era (1868-01-01 - 1912-07-29) * which has the value -1. */ public static final JapaneseEra MEIJI = new JapaneseEra(-1, LocalDate.of(1868, 1, 1)); diff --git a/jdk/test/java/time/test/java/time/TestLocalTime.java b/jdk/test/java/time/test/java/time/TestLocalTime.java index d7f04ab5af6..8e25a85f198 100644 --- a/jdk/test/java/time/test/java/time/TestLocalTime.java +++ b/jdk/test/java/time/test/java/time/TestLocalTime.java @@ -73,6 +73,9 @@ import org.testng.annotations.Test; */ @Test public class TestLocalTime extends AbstractTest { + static final long NANOS_PER_SECOND = 1_000_000_000L; + static final long NANOS_PER_MINUTE = 60 * NANOS_PER_SECOND; + static final long NANOS_PER_DAY = 24 * 60 * NANOS_PER_MINUTE; //----------------------------------------------------------------------- @Test @@ -182,19 +185,27 @@ public class TestLocalTime extends AbstractTest { // now() //----------------------------------------------------------------------- @Test + @SuppressWarnings("unused") public void now() { // Warmup the TimeZone data so the following test does not include // one-time initialization - LocalTime expected = LocalTime.now(Clock.systemDefaultZone()); + LocalTime.now(Clock.systemDefaultZone()); - expected = LocalTime.now(Clock.systemDefaultZone()); - LocalTime test = LocalTime.now(); - long diff = test.toNanoOfDay() - expected.toNanoOfDay(); - if (diff < 0) { - // Adjust if for rollover around midnight - diff += 24 * 60 * 60 * 1_000_000_000L; // Nanos Per Day + long diff = Integer.MAX_VALUE; + for (int i = 0; i < 2; i++) { + LocalTime expected = LocalTime.now(Clock.systemDefaultZone()); + LocalTime test = LocalTime.now(); + diff = test.toNanoOfDay() - expected.toNanoOfDay(); + // Normalize for wrap-around midnight + diff = Math.floorMod(NANOS_PER_DAY + diff, NANOS_PER_DAY); + if (diff < 100000000) { + break; + } + // A second iteration may be needed if the clock changed + // due to a DST change between the two calls to now. } - assertTrue(diff < 500000000); // less than 0.5 secs + assertTrue(diff < 100000000, // less than 0.1 sec + "LocalTime.now vs LocalTime.now(Clock.systemDefaultZone()) not close"); } } From bef51c4a0895b8b525ee33d22281fdf56eea8431 Mon Sep 17 00:00:00 2001 From: Paul Sandoz Date: Mon, 2 Sep 2013 11:59:57 +0200 Subject: [PATCH 082/210] 8010293: java/util/concurrent/ConcurrentHashMap/toArray.java fails intermittently Co-authored-by: Doug Lea Co-authored-by: Peter Levart Reviewed-by: forax, chegar, alanb --- .../util/concurrent/ConcurrentHashMap.java | 302 ++++++++++++------ .../concurrent/ConcurrentHashMap/toArray.java | 64 ++-- 2 files changed, 241 insertions(+), 125 deletions(-) diff --git a/jdk/src/share/classes/java/util/concurrent/ConcurrentHashMap.java b/jdk/src/share/classes/java/util/concurrent/ConcurrentHashMap.java index 9476bc411ba..c8c52a76ffd 100644 --- a/jdk/src/share/classes/java/util/concurrent/ConcurrentHashMap.java +++ b/jdk/src/share/classes/java/util/concurrent/ConcurrentHashMap.java @@ -374,27 +374,26 @@ public class ConcurrentHashMap extends AbstractMap * The table is resized when occupancy exceeds a percentage * threshold (nominally, 0.75, but see below). Any thread * noticing an overfull bin may assist in resizing after the - * initiating thread allocates and sets up the replacement - * array. However, rather than stalling, these other threads may - * proceed with insertions etc. The use of TreeBins shields us - * from the worst case effects of overfilling while resizes are in + * initiating thread allocates and sets up the replacement array. + * However, rather than stalling, these other threads may proceed + * with insertions etc. The use of TreeBins shields us from the + * worst case effects of overfilling while resizes are in * progress. Resizing proceeds by transferring bins, one by one, - * from the table to the next table. To enable concurrency, the - * next table must be (incrementally) prefilled with place-holders - * serving as reverse forwarders to the old table. Because we are - * using power-of-two expansion, the elements from each bin must - * either stay at same index, or move with a power of two - * offset. We eliminate unnecessary node creation by catching - * cases where old nodes can be reused because their next fields - * won't change. On average, only about one-sixth of them need - * cloning when a table doubles. The nodes they replace will be - * garbage collectable as soon as they are no longer referenced by - * any reader thread that may be in the midst of concurrently - * traversing table. Upon transfer, the old table bin contains - * only a special forwarding node (with hash field "MOVED") that - * contains the next table as its key. On encountering a - * forwarding node, access and update operations restart, using - * the new table. + * from the table to the next table. However, threads claim small + * blocks of indices to transfer (via field transferIndex) before + * doing so, reducing contention. Because we are using + * power-of-two expansion, the elements from each bin must either + * stay at same index, or move with a power of two offset. We + * eliminate unnecessary node creation by catching cases where old + * nodes can be reused because their next fields won't change. On + * average, only about one-sixth of them need cloning when a table + * doubles. The nodes they replace will be garbage collectable as + * soon as they are no longer referenced by any reader thread that + * may be in the midst of concurrently traversing table. Upon + * transfer, the old table bin contains only a special forwarding + * node (with hash field "MOVED") that contains the next table as + * its key. On encountering a forwarding node, access and update + * operations restart, using the new table. * * Each bin transfer requires its bin lock, which can stall * waiting for locks while resizing. However, because other @@ -402,13 +401,19 @@ public class ConcurrentHashMap extends AbstractMap * locks, average aggregate waits become shorter as resizing * progresses. The transfer operation must also ensure that all * accessible bins in both the old and new table are usable by any - * traversal. This is arranged by proceeding from the last bin - * (table.length - 1) up towards the first. Upon seeing a - * forwarding node, traversals (see class Traverser) arrange to - * move to the new table without revisiting nodes. However, to - * ensure that no intervening nodes are skipped, bin splitting can - * only begin after the associated reverse-forwarders are in - * place. + * traversal. This is arranged in part by proceeding from the + * last bin (table.length - 1) up towards the first. Upon seeing + * a forwarding node, traversals (see class Traverser) arrange to + * move to the new table without revisiting nodes. To ensure that + * no intervening nodes are skipped even when moved out of order, + * a stack (see class TableStack) is created on first encounter of + * a forwarding node during a traversal, to maintain its place if + * later processing the current table. The need for these + * save/restore mechanics is relatively rare, but when one + * forwarding node is encountered, typically many more will be. + * So Traversers use a simple caching scheme to avoid creating so + * many new TableStack nodes. (Thanks to Peter Levart for + * suggesting use of a stack here.) * * The traversal scheme also applies to partial traversals of * ranges of bins (via an alternate Traverser constructor) @@ -776,11 +781,6 @@ public class ConcurrentHashMap extends AbstractMap */ private transient volatile int transferIndex; - /** - * The least available table index to split while resizing. - */ - private transient volatile int transferOrigin; - /** * Spinlock (locked via CAS) used when resizing and/or creating CounterCells. */ @@ -1377,7 +1377,8 @@ public class ConcurrentHashMap extends AbstractMap } int segmentShift = 32 - sshift; int segmentMask = ssize - 1; - @SuppressWarnings("unchecked") Segment[] segments = (Segment[]) + @SuppressWarnings("unchecked") + Segment[] segments = (Segment[]) new Segment[DEFAULT_CONCURRENCY_LEVEL]; for (int i = 0; i < segments.length; ++i) segments[i] = new Segment(LOAD_FACTOR); @@ -1420,8 +1421,10 @@ public class ConcurrentHashMap extends AbstractMap long size = 0L; Node p = null; for (;;) { - @SuppressWarnings("unchecked") K k = (K) s.readObject(); - @SuppressWarnings("unchecked") V v = (V) s.readObject(); + @SuppressWarnings("unchecked") + K k = (K) s.readObject(); + @SuppressWarnings("unchecked") + V v = (V) s.readObject(); if (k != null && v != null) { p = new Node(spread(k.hashCode()), k, v, p); ++size; @@ -1439,8 +1442,8 @@ public class ConcurrentHashMap extends AbstractMap int sz = (int)size; n = tableSizeFor(sz + (sz >>> 1) + 1); } - @SuppressWarnings({"rawtypes","unchecked"}) - Node[] tab = (Node[])new Node[n]; + @SuppressWarnings("unchecked") + Node[] tab = (Node[])new Node[n]; int mask = n - 1; long added = 0L; while (p != null) { @@ -2200,8 +2203,8 @@ public class ConcurrentHashMap extends AbstractMap try { if ((tab = table) == null || tab.length == 0) { int n = (sc > 0) ? sc : DEFAULT_CAPACITY; - @SuppressWarnings({"rawtypes","unchecked"}) - Node[] nt = (Node[])new Node[n]; + @SuppressWarnings("unchecked") + Node[] nt = (Node[])new Node[n]; table = tab = nt; sc = n - (n >>> 2); } @@ -2246,7 +2249,7 @@ public class ConcurrentHashMap extends AbstractMap while (s >= (long)(sc = sizeCtl) && (tab = table) != null && tab.length < MAXIMUM_CAPACITY) { if (sc < 0) { - if (sc == -1 || transferIndex <= transferOrigin || + if (sc == -1 || transferIndex <= 0 || (nt = nextTable) == null) break; if (U.compareAndSwapInt(this, SIZECTL, sc, sc - 1)) @@ -2266,10 +2269,13 @@ public class ConcurrentHashMap extends AbstractMap Node[] nextTab; int sc; if ((f instanceof ForwardingNode) && (nextTab = ((ForwardingNode)f).nextTable) != null) { - if (nextTab == nextTable && tab == table && - transferIndex > transferOrigin && (sc = sizeCtl) < -1 && - U.compareAndSwapInt(this, SIZECTL, sc, sc - 1)) - transfer(tab, nextTab); + while (transferIndex > 0 && nextTab == nextTable && + (sc = sizeCtl) < -1) { + if (U.compareAndSwapInt(this, SIZECTL, sc, sc - 1)) { + transfer(tab, nextTab); + break; + } + } return nextTab; } return table; @@ -2291,8 +2297,8 @@ public class ConcurrentHashMap extends AbstractMap if (U.compareAndSwapInt(this, SIZECTL, sc, -1)) { try { if (table == tab) { - @SuppressWarnings({"rawtypes","unchecked"}) - Node[] nt = (Node[])new Node[n]; + @SuppressWarnings("unchecked") + Node[] nt = (Node[])new Node[n]; table = nt; sc = n - (n >>> 2); } @@ -2319,36 +2325,27 @@ public class ConcurrentHashMap extends AbstractMap stride = MIN_TRANSFER_STRIDE; // subdivide range if (nextTab == null) { // initiating try { - @SuppressWarnings({"rawtypes","unchecked"}) - Node[] nt = (Node[])new Node[n << 1]; + @SuppressWarnings("unchecked") + Node[] nt = (Node[])new Node[n << 1]; nextTab = nt; } catch (Throwable ex) { // try to cope with OOME sizeCtl = Integer.MAX_VALUE; return; } nextTable = nextTab; - transferOrigin = n; transferIndex = n; - ForwardingNode rev = new ForwardingNode(tab); - for (int k = n; k > 0;) { // progressively reveal ready slots - int nextk = (k > stride) ? k - stride : 0; - for (int m = nextk; m < k; ++m) - nextTab[m] = rev; - for (int m = n + nextk; m < n + k; ++m) - nextTab[m] = rev; - U.putOrderedInt(this, TRANSFERORIGIN, k = nextk); - } } int nextn = nextTab.length; ForwardingNode fwd = new ForwardingNode(nextTab); boolean advance = true; boolean finishing = false; // to ensure sweep before committing nextTab for (int i = 0, bound = 0;;) { - int nextIndex, nextBound, fh; Node f; + Node f; int fh; while (advance) { + int nextIndex, nextBound; if (--i >= bound || finishing) advance = false; - else if ((nextIndex = transferIndex) <= transferOrigin) { + else if ((nextIndex = transferIndex) <= 0) { i = -1; advance = false; } @@ -2362,29 +2359,22 @@ public class ConcurrentHashMap extends AbstractMap } } if (i < 0 || i >= n || i + n >= nextn) { + int sc; if (finishing) { nextTable = null; table = nextTab; sizeCtl = (n << 1) - (n >>> 1); return; } - for (int sc;;) { - if (U.compareAndSwapInt(this, SIZECTL, sc = sizeCtl, ++sc)) { - if (sc != -1) - return; - finishing = advance = true; - i = n; // recheck before commit - break; - } - } - } - else if ((f = tabAt(tab, i)) == null) { - if (casTabAt(tab, i, null, fwd)) { - setTabAt(nextTab, i, null); - setTabAt(nextTab, i + n, null); - advance = true; + if (U.compareAndSwapInt(this, SIZECTL, sc = sizeCtl, ++sc)) { + if (sc != -1) + return; + finishing = advance = true; + i = n; // recheck before commit } } + else if ((f = tabAt(tab, i)) == null) + advance = casTabAt(tab, i, null, fwd); else if ((fh = f.hash) == MOVED) advance = true; // already processed else { @@ -3223,6 +3213,18 @@ public class ConcurrentHashMap extends AbstractMap /* ----------------Table Traversal -------------- */ + /** + * Records the table, its length, and current traversal index for a + * traverser that must process a region of a forwarded table before + * proceeding with current table. + */ + static final class TableStack { + int length; + int index; + Node[] tab; + TableStack next; + } + /** * Encapsulates traversal for methods such as containsValue; also * serves as a base class for other iterators and spliterators. @@ -3247,6 +3249,7 @@ public class ConcurrentHashMap extends AbstractMap static class Traverser { Node[] tab; // current table; updated if resized Node next; // the next entry to use + TableStack stack, spare; // to save/restore on ForwardingNodes int index; // index of bin to use next int baseIndex; // current index of initial table int baseLimit; // index bound for initial table @@ -3268,16 +3271,17 @@ public class ConcurrentHashMap extends AbstractMap if ((e = next) != null) e = e.next; for (;;) { - Node[] t; int i, n; K ek; // must use locals in checks + Node[] t; int i, n; // must use locals in checks if (e != null) return next = e; if (baseIndex >= baseLimit || (t = tab) == null || (n = t.length) <= (i = index) || i < 0) return next = null; - if ((e = tabAt(t, index)) != null && e.hash < 0) { + if ((e = tabAt(t, i)) != null && e.hash < 0) { if (e instanceof ForwardingNode) { tab = ((ForwardingNode)e).nextTable; e = null; + pushState(t, i, n); continue; } else if (e instanceof TreeBin) @@ -3285,10 +3289,49 @@ public class ConcurrentHashMap extends AbstractMap else e = null; } - if ((index += baseSize) >= n) - index = ++baseIndex; // visit upper slots if present + if (stack != null) + recoverState(n); + else if ((index = i + baseSize) >= n) + index = ++baseIndex; // visit upper slots if present } } + + /** + * Saves traversal state upon encountering a forwarding node. + */ + private void pushState(Node[] t, int i, int n) { + TableStack s = spare; // reuse if possible + if (s != null) + spare = s.next; + else + s = new TableStack(); + s.tab = t; + s.length = n; + s.index = i; + s.next = stack; + stack = s; + } + + /** + * Possibly pops traversal state. + * + * @param n length of current table + */ + private void recoverState(int n) { + TableStack s; int len; + while ((s = stack) != null && (index += (len = s.length)) >= n) { + n = len; + index = s.index; + tab = s.tab; + s.tab = null; + TableStack next = s.next; + s.next = spare; // save for reuse + stack = next; + spare = s; + } + if (s == null && (index += baseSize) >= n) + index = ++baseIndex; + } } /** @@ -4722,6 +4765,7 @@ public class ConcurrentHashMap extends AbstractMap abstract static class BulkTask extends CountedCompleter { Node[] tab; // same as Traverser Node next; + TableStack stack, spare; int index; int baseIndex; int baseLimit; @@ -4750,16 +4794,17 @@ public class ConcurrentHashMap extends AbstractMap if ((e = next) != null) e = e.next; for (;;) { - Node[] t; int i, n; K ek; // must use locals in checks + Node[] t; int i, n; if (e != null) return next = e; if (baseIndex >= baseLimit || (t = tab) == null || (n = t.length) <= (i = index) || i < 0) return next = null; - if ((e = tabAt(t, index)) != null && e.hash < 0) { + if ((e = tabAt(t, i)) != null && e.hash < 0) { if (e instanceof ForwardingNode) { tab = ((ForwardingNode)e).nextTable; e = null; + pushState(t, i, n); continue; } else if (e instanceof TreeBin) @@ -4767,10 +4812,41 @@ public class ConcurrentHashMap extends AbstractMap else e = null; } - if ((index += baseSize) >= n) - index = ++baseIndex; // visit upper slots if present + if (stack != null) + recoverState(n); + else if ((index = i + baseSize) >= n) + index = ++baseIndex; } } + + private void pushState(Node[] t, int i, int n) { + TableStack s = spare; + if (s != null) + spare = s.next; + else + s = new TableStack(); + s.tab = t; + s.length = n; + s.index = i; + s.next = stack; + stack = s; + } + + private void recoverState(int n) { + TableStack s; int len; + while ((s = stack) != null && (index += (len = s.length)) >= n) { + n = len; + index = s.index; + tab = s.tab; + s.tab = null; + TableStack next = s.next; + s.next = spare; // save for reuse + stack = next; + spare = s; + } + if (s == null && (index += baseSize) >= n) + index = ++baseIndex; + } } /* @@ -5229,7 +5305,8 @@ public class ConcurrentHashMap extends AbstractMap result = r; CountedCompleter c; for (c = firstComplete(); c != null; c = c.nextComplete()) { - @SuppressWarnings("unchecked") ReduceKeysTask + @SuppressWarnings("unchecked") + ReduceKeysTask t = (ReduceKeysTask)c, s = t.rights; while (s != null) { @@ -5276,7 +5353,8 @@ public class ConcurrentHashMap extends AbstractMap result = r; CountedCompleter c; for (c = firstComplete(); c != null; c = c.nextComplete()) { - @SuppressWarnings("unchecked") ReduceValuesTask + @SuppressWarnings("unchecked") + ReduceValuesTask t = (ReduceValuesTask)c, s = t.rights; while (s != null) { @@ -5321,7 +5399,8 @@ public class ConcurrentHashMap extends AbstractMap result = r; CountedCompleter c; for (c = firstComplete(); c != null; c = c.nextComplete()) { - @SuppressWarnings("unchecked") ReduceEntriesTask + @SuppressWarnings("unchecked") + ReduceEntriesTask t = (ReduceEntriesTask)c, s = t.rights; while (s != null) { @@ -5374,7 +5453,8 @@ public class ConcurrentHashMap extends AbstractMap result = r; CountedCompleter c; for (c = firstComplete(); c != null; c = c.nextComplete()) { - @SuppressWarnings("unchecked") MapReduceKeysTask + @SuppressWarnings("unchecked") + MapReduceKeysTask t = (MapReduceKeysTask)c, s = t.rights; while (s != null) { @@ -5427,7 +5507,8 @@ public class ConcurrentHashMap extends AbstractMap result = r; CountedCompleter c; for (c = firstComplete(); c != null; c = c.nextComplete()) { - @SuppressWarnings("unchecked") MapReduceValuesTask + @SuppressWarnings("unchecked") + MapReduceValuesTask t = (MapReduceValuesTask)c, s = t.rights; while (s != null) { @@ -5480,7 +5561,8 @@ public class ConcurrentHashMap extends AbstractMap result = r; CountedCompleter c; for (c = firstComplete(); c != null; c = c.nextComplete()) { - @SuppressWarnings("unchecked") MapReduceEntriesTask + @SuppressWarnings("unchecked") + MapReduceEntriesTask t = (MapReduceEntriesTask)c, s = t.rights; while (s != null) { @@ -5533,7 +5615,8 @@ public class ConcurrentHashMap extends AbstractMap result = r; CountedCompleter c; for (c = firstComplete(); c != null; c = c.nextComplete()) { - @SuppressWarnings("unchecked") MapReduceMappingsTask + @SuppressWarnings("unchecked") + MapReduceMappingsTask t = (MapReduceMappingsTask)c, s = t.rights; while (s != null) { @@ -5585,7 +5668,8 @@ public class ConcurrentHashMap extends AbstractMap result = r; CountedCompleter c; for (c = firstComplete(); c != null; c = c.nextComplete()) { - @SuppressWarnings("unchecked") MapReduceKeysToDoubleTask + @SuppressWarnings("unchecked") + MapReduceKeysToDoubleTask t = (MapReduceKeysToDoubleTask)c, s = t.rights; while (s != null) { @@ -5634,7 +5718,8 @@ public class ConcurrentHashMap extends AbstractMap result = r; CountedCompleter c; for (c = firstComplete(); c != null; c = c.nextComplete()) { - @SuppressWarnings("unchecked") MapReduceValuesToDoubleTask + @SuppressWarnings("unchecked") + MapReduceValuesToDoubleTask t = (MapReduceValuesToDoubleTask)c, s = t.rights; while (s != null) { @@ -5683,7 +5768,8 @@ public class ConcurrentHashMap extends AbstractMap result = r; CountedCompleter c; for (c = firstComplete(); c != null; c = c.nextComplete()) { - @SuppressWarnings("unchecked") MapReduceEntriesToDoubleTask + @SuppressWarnings("unchecked") + MapReduceEntriesToDoubleTask t = (MapReduceEntriesToDoubleTask)c, s = t.rights; while (s != null) { @@ -5732,7 +5818,8 @@ public class ConcurrentHashMap extends AbstractMap result = r; CountedCompleter c; for (c = firstComplete(); c != null; c = c.nextComplete()) { - @SuppressWarnings("unchecked") MapReduceMappingsToDoubleTask + @SuppressWarnings("unchecked") + MapReduceMappingsToDoubleTask t = (MapReduceMappingsToDoubleTask)c, s = t.rights; while (s != null) { @@ -5781,7 +5868,8 @@ public class ConcurrentHashMap extends AbstractMap result = r; CountedCompleter c; for (c = firstComplete(); c != null; c = c.nextComplete()) { - @SuppressWarnings("unchecked") MapReduceKeysToLongTask + @SuppressWarnings("unchecked") + MapReduceKeysToLongTask t = (MapReduceKeysToLongTask)c, s = t.rights; while (s != null) { @@ -5830,7 +5918,8 @@ public class ConcurrentHashMap extends AbstractMap result = r; CountedCompleter c; for (c = firstComplete(); c != null; c = c.nextComplete()) { - @SuppressWarnings("unchecked") MapReduceValuesToLongTask + @SuppressWarnings("unchecked") + MapReduceValuesToLongTask t = (MapReduceValuesToLongTask)c, s = t.rights; while (s != null) { @@ -5879,7 +5968,8 @@ public class ConcurrentHashMap extends AbstractMap result = r; CountedCompleter c; for (c = firstComplete(); c != null; c = c.nextComplete()) { - @SuppressWarnings("unchecked") MapReduceEntriesToLongTask + @SuppressWarnings("unchecked") + MapReduceEntriesToLongTask t = (MapReduceEntriesToLongTask)c, s = t.rights; while (s != null) { @@ -5928,7 +6018,8 @@ public class ConcurrentHashMap extends AbstractMap result = r; CountedCompleter c; for (c = firstComplete(); c != null; c = c.nextComplete()) { - @SuppressWarnings("unchecked") MapReduceMappingsToLongTask + @SuppressWarnings("unchecked") + MapReduceMappingsToLongTask t = (MapReduceMappingsToLongTask)c, s = t.rights; while (s != null) { @@ -5977,7 +6068,8 @@ public class ConcurrentHashMap extends AbstractMap result = r; CountedCompleter c; for (c = firstComplete(); c != null; c = c.nextComplete()) { - @SuppressWarnings("unchecked") MapReduceKeysToIntTask + @SuppressWarnings("unchecked") + MapReduceKeysToIntTask t = (MapReduceKeysToIntTask)c, s = t.rights; while (s != null) { @@ -6026,7 +6118,8 @@ public class ConcurrentHashMap extends AbstractMap result = r; CountedCompleter c; for (c = firstComplete(); c != null; c = c.nextComplete()) { - @SuppressWarnings("unchecked") MapReduceValuesToIntTask + @SuppressWarnings("unchecked") + MapReduceValuesToIntTask t = (MapReduceValuesToIntTask)c, s = t.rights; while (s != null) { @@ -6075,7 +6168,8 @@ public class ConcurrentHashMap extends AbstractMap result = r; CountedCompleter c; for (c = firstComplete(); c != null; c = c.nextComplete()) { - @SuppressWarnings("unchecked") MapReduceEntriesToIntTask + @SuppressWarnings("unchecked") + MapReduceEntriesToIntTask t = (MapReduceEntriesToIntTask)c, s = t.rights; while (s != null) { @@ -6124,7 +6218,8 @@ public class ConcurrentHashMap extends AbstractMap result = r; CountedCompleter c; for (c = firstComplete(); c != null; c = c.nextComplete()) { - @SuppressWarnings("unchecked") MapReduceMappingsToIntTask + @SuppressWarnings("unchecked") + MapReduceMappingsToIntTask t = (MapReduceMappingsToIntTask)c, s = t.rights; while (s != null) { @@ -6140,7 +6235,6 @@ public class ConcurrentHashMap extends AbstractMap private static final sun.misc.Unsafe U; private static final long SIZECTL; private static final long TRANSFERINDEX; - private static final long TRANSFERORIGIN; private static final long BASECOUNT; private static final long CELLSBUSY; private static final long CELLVALUE; @@ -6155,8 +6249,6 @@ public class ConcurrentHashMap extends AbstractMap (k.getDeclaredField("sizeCtl")); TRANSFERINDEX = U.objectFieldOffset (k.getDeclaredField("transferIndex")); - TRANSFERORIGIN = U.objectFieldOffset - (k.getDeclaredField("transferOrigin")); BASECOUNT = U.objectFieldOffset (k.getDeclaredField("baseCount")); CELLSBUSY = U.objectFieldOffset diff --git a/jdk/test/java/util/concurrent/ConcurrentHashMap/toArray.java b/jdk/test/java/util/concurrent/ConcurrentHashMap/toArray.java index 0280c0c4658..81108ac9c55 100644 --- a/jdk/test/java/util/concurrent/ConcurrentHashMap/toArray.java +++ b/jdk/test/java/util/concurrent/ConcurrentHashMap/toArray.java @@ -23,39 +23,53 @@ /* * @test - * @bug 4486658 + * @bug 4486658 8010293 * @summary thread safety of toArray methods of subCollections * @author Martin Buchholz */ -import java.util.*; -import java.util.concurrent.*; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.IntStream; -public class toArray { +public class ToArray { public static void main(String[] args) throws Throwable { + // Execute a number of times to increase the probability of + // failure if there is an issue + for (int i = 0; i < 16; i++) { + executeTest(); + } + } + + static void executeTest() throws Throwable { final Throwable throwable[] = new Throwable[1]; - final int maxSize = 1000; - final ConcurrentHashMap m - = new ConcurrentHashMap(); + final ConcurrentHashMap m = new ConcurrentHashMap<>(); - final Thread t1 = new Thread() { public void run() { - for (int i = 0; i < maxSize; i++) - m.put(i,i);}}; + // Number of workers equal to the number of processors + // Each worker will put globally unique keys into the map + final int nWorkers = Runtime.getRuntime().availableProcessors(); + final int sizePerWorker = 1024; + final int maxSize = nWorkers * sizePerWorker; - final Thread t2 = new Thread() { - public Throwable exception = null; + // The foreman keeps checking that the size of the arrays + // obtained from the key and value sets is never less than the + // previously observed size and is never greater than the maximum size + // NOTE: these size constraints are not specific to toArray and are + // applicable to any form of traversal of the collection views + CompletableFuture foreman = CompletableFuture.runAsync(new Runnable() { private int prevSize = 0; private boolean checkProgress(Object[] a) { int size = a.length; if (size < prevSize) throw new RuntimeException("WRONG WAY"); - if (size > maxSize) throw new RuntimeException("OVERSHOOT"); + if (size > maxSize) throw new RuntimeException("OVERSHOOT"); if (size == maxSize) return true; prevSize = size; return false; } + @Override public void run() { try { Integer[] empty = new Integer[0]; @@ -65,15 +79,25 @@ public class toArray { if (checkProgress(m.values().toArray(empty))) return; if (checkProgress(m.keySet().toArray(empty))) return; } - } catch (Throwable t) { - throwable[0] = t; - }}}; + } + catch (Throwable t) { + throwable[0] = t; + } + } + }); - t2.start(); - t1.start(); + // Create workers + // Each worker will put globally unique keys into the map + CompletableFuture[] workers = IntStream.range(0, nWorkers). + mapToObj(w -> CompletableFuture.runAsync(() -> { + for (int i = 0, o = w * sizePerWorker; i < sizePerWorker; i++) + m.put(o + i, i); + })). + toArray(CompletableFuture[]::new); - t1.join(); - t2.join(); + // Wait for workers and then foreman to complete + CompletableFuture.allOf(workers).join(); + foreman.join(); if (throwable[0] != null) throw throwable[0]; From 0382c78ff16d02de16679d80d2753740c3750d0b Mon Sep 17 00:00:00 2001 From: Maurizio Cimadamore Date: Mon, 2 Sep 2013 22:38:36 +0100 Subject: [PATCH 083/210] 8016177: structural most specific and stuckness Reviewed-by: jjg, vromero --- .../com/sun/tools/javac/code/Flags.java | 5 + .../com/sun/tools/javac/code/Lint.java | 5 + .../com/sun/tools/javac/code/Types.java | 2 +- .../com/sun/tools/javac/comp/Attr.java | 51 +-- .../com/sun/tools/javac/comp/Check.java | 80 +++- .../sun/tools/javac/comp/DeferredAttr.java | 361 ++++++++++++----- .../com/sun/tools/javac/comp/Infer.java | 382 +++++++++++++----- .../com/sun/tools/javac/comp/Resolve.java | 101 +++-- .../tools/javac/resources/compiler.properties | 13 +- .../com/sun/tools/javac/tree/JCTree.java | 7 + .../com/sun/tools/javac/util/GraphUtils.java | 41 +- .../com/sun/tools/javac/util/List.java | 13 + .../Diagnostics/compressed/T8012003c.out | 1 - .../diags/examples/BadArgTypesInLambda.java | 3 - .../IncompatibleArgTypesInMethodRef.java | 1 + ...java => PotentiallyAmbiguousOverload.java} | 21 +- .../tools/javac/lambda/8016177/T8016177a.java | 45 +++ .../tools/javac/lambda/8016177/T8016177a.out | 8 + .../tools/javac/lambda/8016177/T8016177b.java | 34 ++ .../tools/javac/lambda/8016177/T8016177b.out | 2 + .../tools/javac/lambda/8016177/T8016177c.java | 47 +++ .../tools/javac/lambda/8016177/T8016177c.out | 4 + .../tools/javac/lambda/8016177/T8016177d.java | 58 +++ .../tools/javac/lambda/8016177/T8016177e.java | 46 +++ .../tools/javac/lambda/8016177/T8016177f.java | 94 +++++ .../tools/javac/lambda/8016177/T8016177g.java | 37 ++ .../tools/javac/lambda/8016177/T8016177g.out | 2 + .../test/tools/javac/lambda/BadRecovery.out | 3 +- .../javac/lambda/ErroneousLambdaExpr.java | 3 +- .../javac/lambda/ErroneousLambdaExpr.out | 2 + .../tools/javac/lambda/MethodReference22.out | 14 +- .../tools/javac/lambda/MethodReference23.out | 4 +- .../tools/javac/lambda/MethodReference41.java | 29 +- .../tools/javac/lambda/MethodReference41.out | 4 + .../tools/javac/lambda/MethodReference42.java | 30 +- .../tools/javac/lambda/MethodReference42.out | 4 + .../tools/javac/lambda/MethodReference43.java | 34 +- .../tools/javac/lambda/MethodReference43.out | 5 + .../tools/javac/lambda/MethodReference44.java | 30 +- .../tools/javac/lambda/MethodReference44.out | 4 + .../tools/javac/lambda/MethodReference46.java | 30 +- .../tools/javac/lambda/MethodReference46.out | 4 + .../tools/javac/lambda/MethodReference47.java | 12 +- .../tools/javac/lambda/MethodReference47.out | 2 +- .../tools/javac/lambda/MethodReference48.java | 30 +- .../tools/javac/lambda/MethodReference48.out | 3 + .../tools/javac/lambda/MethodReference70.out | 2 +- .../tools/javac/lambda/MethodReference71.out | 2 +- .../tools/javac/lambda/MostSpecific04.java | 19 +- .../tools/javac/lambda/MostSpecific04.out | 2 + .../tools/javac/lambda/MostSpecific05.java | 19 +- .../tools/javac/lambda/MostSpecific05.out | 2 + .../tools/javac/lambda/MostSpecific08.java | 12 +- .../tools/javac/lambda/MostSpecific08.out | 4 + .../test/tools/javac/lambda/TargetType01.java | 2 +- .../test/tools/javac/lambda/TargetType01.out | 3 + .../test/tools/javac/lambda/TargetType02.java | 29 +- .../test/tools/javac/lambda/TargetType02.out | 3 + .../test/tools/javac/lambda/TargetType10.java | 4 +- .../test/tools/javac/lambda/TargetType10.out | 2 - .../test/tools/javac/lambda/TargetType21.java | 4 +- .../test/tools/javac/lambda/TargetType21.out | 10 +- .../test/tools/javac/lambda/TargetType24.java | 9 +- .../test/tools/javac/lambda/TargetType24.out | 16 +- .../test/tools/javac/lambda/TargetType26.out | 2 +- .../test/tools/javac/lambda/TargetType27.out | 2 +- .../test/tools/javac/lambda/TargetType39.out | 4 +- .../test/tools/javac/lambda/TargetType43.out | 3 +- .../test/tools/javac/lambda/TargetType66.java | 4 +- .../test/tools/javac/lambda/TargetType66.out | 9 +- .../StructuralMostSpecificTest.java | 20 +- .../lambda/typeInference/InferenceTest5.java | 122 ------ ...enceTest_neg5.java => InferenceTest6.java} | 8 +- .../typeInference/InferenceTest_neg1_2.out | 7 +- .../typeInference/InferenceTest_neg5.out | 2 - .../combo/TypeInferenceComboTest.java | 7 +- 76 files changed, 1377 insertions(+), 668 deletions(-) rename langtools/test/tools/javac/diags/examples/{CyclicInference.java => PotentiallyAmbiguousOverload.java} (75%) create mode 100644 langtools/test/tools/javac/lambda/8016177/T8016177a.java create mode 100644 langtools/test/tools/javac/lambda/8016177/T8016177a.out create mode 100644 langtools/test/tools/javac/lambda/8016177/T8016177b.java create mode 100644 langtools/test/tools/javac/lambda/8016177/T8016177b.out create mode 100644 langtools/test/tools/javac/lambda/8016177/T8016177c.java create mode 100644 langtools/test/tools/javac/lambda/8016177/T8016177c.out create mode 100644 langtools/test/tools/javac/lambda/8016177/T8016177d.java create mode 100644 langtools/test/tools/javac/lambda/8016177/T8016177e.java create mode 100644 langtools/test/tools/javac/lambda/8016177/T8016177f.java create mode 100644 langtools/test/tools/javac/lambda/8016177/T8016177g.java create mode 100644 langtools/test/tools/javac/lambda/8016177/T8016177g.out create mode 100644 langtools/test/tools/javac/lambda/ErroneousLambdaExpr.out create mode 100644 langtools/test/tools/javac/lambda/MethodReference41.out create mode 100644 langtools/test/tools/javac/lambda/MethodReference42.out create mode 100644 langtools/test/tools/javac/lambda/MethodReference43.out create mode 100644 langtools/test/tools/javac/lambda/MethodReference44.out create mode 100644 langtools/test/tools/javac/lambda/MethodReference46.out create mode 100644 langtools/test/tools/javac/lambda/MethodReference48.out create mode 100644 langtools/test/tools/javac/lambda/MostSpecific04.out create mode 100644 langtools/test/tools/javac/lambda/MostSpecific05.out create mode 100644 langtools/test/tools/javac/lambda/MostSpecific08.out create mode 100644 langtools/test/tools/javac/lambda/TargetType01.out create mode 100644 langtools/test/tools/javac/lambda/TargetType02.out delete mode 100644 langtools/test/tools/javac/lambda/TargetType10.out delete mode 100644 langtools/test/tools/javac/lambda/typeInference/InferenceTest5.java rename langtools/test/tools/javac/lambda/typeInference/{InferenceTest_neg5.java => InferenceTest6.java} (76%) delete mode 100644 langtools/test/tools/javac/lambda/typeInference/InferenceTest_neg5.out diff --git a/langtools/src/share/classes/com/sun/tools/javac/code/Flags.java b/langtools/src/share/classes/com/sun/tools/javac/code/Flags.java index 12acc8dc27e..b2da2807363 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/code/Flags.java +++ b/langtools/src/share/classes/com/sun/tools/javac/code/Flags.java @@ -266,6 +266,11 @@ public class Flags { */ public static final long THROWS = 1L<<47; + /** + * Flag that marks potentially ambiguous overloads + */ + public static final long POTENTIALLY_AMBIGUOUS = 1L<<48; + /** Modifier masks. */ public static final int diff --git a/langtools/src/share/classes/com/sun/tools/javac/code/Lint.java b/langtools/src/share/classes/com/sun/tools/javac/code/Lint.java index a6956f341ec..fb0ea30429f 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/code/Lint.java +++ b/langtools/src/share/classes/com/sun/tools/javac/code/Lint.java @@ -174,6 +174,11 @@ public class Lint */ OPTIONS("options"), + /** + * Warn about issues regarding method overloads. + */ + OVERLOADS("overloads"), + /** * Warn about issues regarding method overrides. */ diff --git a/langtools/src/share/classes/com/sun/tools/javac/code/Types.java b/langtools/src/share/classes/com/sun/tools/javac/code/Types.java index 06744bf6d06..0d060b60bb7 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/code/Types.java +++ b/langtools/src/share/classes/com/sun/tools/javac/code/Types.java @@ -3055,7 +3055,7 @@ public class Types { /** * Does t have the same bounds for quantified variables as s? */ - boolean hasSameBounds(ForAll t, ForAll s) { + public boolean hasSameBounds(ForAll t, ForAll s) { List l1 = t.tvars; List l2 = s.tvars; while (l1.nonEmpty() && l2.nonEmpty() && diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java b/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java index 6ef409d9339..ad0d5003144 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java @@ -2396,35 +2396,11 @@ public class Attr extends JCTree.Visitor { new ResultInfo(VAL, lambdaType.getReturnType(), funcContext); localEnv.info.returnResult = bodyResultInfo; - Log.DeferredDiagnosticHandler lambdaDeferredHandler = new Log.DeferredDiagnosticHandler(log); - try { - if (that.getBodyKind() == JCLambda.BodyKind.EXPRESSION) { - attribTree(that.getBody(), localEnv, bodyResultInfo); - } else { - JCBlock body = (JCBlock)that.body; - attribStats(body.stats, localEnv); - } - - if (resultInfo.checkContext.deferredAttrContext().mode == AttrMode.SPECULATIVE) { - //check for errors in lambda body - for (JCDiagnostic deferredDiag : lambdaDeferredHandler.getDiagnostics()) { - if (deferredDiag.getKind() == JCDiagnostic.Kind.ERROR) { - resultInfo.checkContext - .report(that, diags.fragment("bad.arg.types.in.lambda", TreeInfo.types(that.params), - deferredDiag)); //hidden diag parameter - //we mark the lambda as erroneous - this is crucial in the recovery step - //as parameter-dependent type error won't be reported in that stage, - //meaning that a lambda will be deemed erroeneous only if there is - //a target-independent error (which will cause method diagnostic - //to be skipped). - result = that.type = types.createErrorType(target); - return; - } - } - } - } finally { - lambdaDeferredHandler.reportDeferredDiagnostics(); - log.popDiagnosticHandler(lambdaDeferredHandler); + if (that.getBodyKind() == JCLambda.BodyKind.EXPRESSION) { + attribTree(that.getBody(), localEnv, bodyResultInfo); + } else { + JCBlock body = (JCBlock)that.body; + attribStats(body.stats, localEnv); } result = check(that, target, VAL, resultInfo); @@ -3731,7 +3707,7 @@ public class Attr extends JCTree.Visitor { * Check that method arguments conform to its instantiation. **/ public Type checkMethod(Type site, - Symbol sym, + final Symbol sym, ResultInfo resultInfo, Env env, final List argtrees, @@ -3820,8 +3796,19 @@ public class Attr extends JCTree.Visitor { resultInfo.checkContext.report(env.tree.pos(), ex.getDiagnostic()); return types.createErrorType(site); } catch (Resolve.InapplicableMethodException ex) { - Assert.error(ex.getDiagnostic().getMessage(Locale.getDefault())); - return null; + final JCDiagnostic diag = ex.getDiagnostic(); + Resolve.InapplicableSymbolError errSym = rs.new InapplicableSymbolError(null) { + @Override + protected Pair errCandidate() { + return new Pair(sym, diag); + } + }; + List argtypes2 = Type.map(argtypes, + rs.new ResolveDeferredRecoveryMap(AttrMode.CHECK, sym, env.info.pendingResolutionPhase)); + JCDiagnostic errDiag = errSym.getDiagnostic(JCDiagnostic.DiagnosticType.ERROR, + env.tree, sym, site, sym.name, argtypes2, typeargtypes); + log.report(errDiag); + return types.createErrorType(site); } } diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java b/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java index 1bb051b1461..5529627ed90 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java @@ -2368,7 +2368,10 @@ public class Check { //for each method m1 that is overridden (directly or indirectly) //by method 'sym' in 'site'... for (Symbol m1 : types.membersClosure(site, false).getElementsByName(sym.name, cf)) { - if (!sym.overrides(m1, site.tsym, types, false)) continue; + if (!sym.overrides(m1, site.tsym, types, false)) { + checkPotentiallyAmbiguousOverloads(pos, site, sym, (MethodSymbol)m1); + continue; + } //...check each method m2 that is a member of 'site' for (Symbol m2 : types.membersClosure(site, false).getElementsByName(sym.name, cf)) { if (m2 == m1) continue; @@ -2406,14 +2409,17 @@ public class Check { for (Symbol s : types.membersClosure(site, true).getElementsByName(sym.name, cf)) { //if (i) the signature of 'sym' is not a subsignature of m1 (seen as //a member of 'site') and (ii) 'sym' has the same erasure as m1, issue an error - if (!types.isSubSignature(sym.type, types.memberType(site, s), allowStrictMethodClashCheck) && - types.hasSameArgs(s.erasure(types), sym.erasure(types))) { - log.error(pos, - "name.clash.same.erasure.no.hide", - sym, sym.location(), - s, s.location()); - return; - } + if (!types.isSubSignature(sym.type, types.memberType(site, s), allowStrictMethodClashCheck)) { + if (types.hasSameArgs(s.erasure(types), sym.erasure(types))) { + log.error(pos, + "name.clash.same.erasure.no.hide", + sym, sym.location(), + s, s.location()); + return; + } else { + checkPotentiallyAmbiguousOverloads(pos, site, sym, (MethodSymbol)s); + } + } } } @@ -2496,6 +2502,62 @@ public class Check { } } + /** + * Report warnings for potentially ambiguous method declarations. Two declarations + * are potentially ambiguous if they feature two unrelated functional interface + * in same argument position (in which case, a call site passing an implicit + * lambda would be ambiguous). + */ + void checkPotentiallyAmbiguousOverloads(DiagnosticPosition pos, Type site, + MethodSymbol msym1, MethodSymbol msym2) { + if (msym1 != msym2 && + allowDefaultMethods && + lint.isEnabled(LintCategory.OVERLOADS) && + (msym1.flags() & POTENTIALLY_AMBIGUOUS) == 0 && + (msym2.flags() & POTENTIALLY_AMBIGUOUS) == 0) { + Type mt1 = types.memberType(site, msym1); + Type mt2 = types.memberType(site, msym2); + //if both generic methods, adjust type variables + if (mt1.hasTag(FORALL) && mt2.hasTag(FORALL) && + types.hasSameBounds((ForAll)mt1, (ForAll)mt2)) { + mt2 = types.subst(mt2, ((ForAll)mt2).tvars, ((ForAll)mt1).tvars); + } + //expand varargs methods if needed + int maxLength = Math.max(mt1.getParameterTypes().length(), mt2.getParameterTypes().length()); + List args1 = rs.adjustArgs(mt1.getParameterTypes(), msym1, maxLength, true); + List args2 = rs.adjustArgs(mt2.getParameterTypes(), msym2, maxLength, true); + //if arities don't match, exit + if (args1.length() != args2.length()) return; + boolean potentiallyAmbiguous = false; + while (args1.nonEmpty() && args2.nonEmpty()) { + Type s = args1.head; + Type t = args2.head; + if (!types.isSubtype(t, s) && !types.isSubtype(s, t)) { + if (types.isFunctionalInterface(s) && types.isFunctionalInterface(t) && + types.findDescriptorType(s).getParameterTypes().length() > 0 && + types.findDescriptorType(s).getParameterTypes().length() == + types.findDescriptorType(t).getParameterTypes().length()) { + potentiallyAmbiguous = true; + } else { + break; + } + } + args1 = args1.tail; + args2 = args2.tail; + } + if (potentiallyAmbiguous) { + //we found two incompatible functional interfaces with same arity + //this means a call site passing an implicit lambda would be ambigiuous + msym1.flags_field |= POTENTIALLY_AMBIGUOUS; + msym2.flags_field |= POTENTIALLY_AMBIGUOUS; + log.warning(LintCategory.OVERLOADS, pos, "potentially.ambiguous.overload", + msym1, msym1.location(), + msym2, msym2.location()); + return; + } + } + } + /** Report a conflict between a user symbol and a synthetic symbol. */ private void syntheticError(DiagnosticPosition pos, Symbol sym) { diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java b/langtools/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java index 6b7cfdd37ee..4db110579f7 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java @@ -25,6 +25,7 @@ package com.sun.tools.javac.comp; +import com.sun.source.tree.MemberReferenceTree; import com.sun.tools.javac.code.*; import com.sun.tools.javac.tree.*; import com.sun.tools.javac.util.*; @@ -39,7 +40,9 @@ import com.sun.tools.javac.tree.JCTree.*; import java.util.ArrayList; +import java.util.Collections; import java.util.EnumSet; +import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; @@ -98,7 +101,7 @@ public class DeferredAttr extends JCTree.Visitor { emptyDeferredAttrContext = new DeferredAttrContext(AttrMode.CHECK, null, MethodResolutionPhase.BOX, infer.emptyContext, null, null) { @Override - void addDeferredAttrNode(DeferredType dt, ResultInfo ri, List stuckVars) { + void addDeferredAttrNode(DeferredType dt, ResultInfo ri, DeferredStuckPolicy deferredStuckPolicy) { Assert.error("Empty deferred context!"); } @Override @@ -149,15 +152,15 @@ public class DeferredAttr extends JCTree.Visitor { class Entry { JCTree speculativeTree; - Resolve.MethodResolutionPhase phase; + ResultInfo resultInfo; - public Entry(JCTree speculativeTree, MethodResolutionPhase phase) { + public Entry(JCTree speculativeTree, ResultInfo resultInfo) { this.speculativeTree = speculativeTree; - this.phase = phase; + this.resultInfo = resultInfo; } - boolean matches(Resolve.MethodResolutionPhase phase) { - return this.phase == phase; + boolean matches(MethodResolutionPhase phase) { + return resultInfo.checkContext.deferredAttrContext().phase == phase; } } @@ -178,12 +181,13 @@ public class DeferredAttr extends JCTree.Visitor { * Stores a speculative cache entry corresponding to given symbol * and resolution phase */ - void put(Symbol msym, JCTree speculativeTree, MethodResolutionPhase phase) { + void put(JCTree speculativeTree, ResultInfo resultInfo) { + Symbol msym = resultInfo.checkContext.deferredAttrContext().msym; List entries = cache.get(msym); if (entries == null) { entries = List.nil(); } - cache.put(msym, entries.prepend(new Entry(speculativeTree, phase))); + cache.put(msym, entries.prepend(new Entry(speculativeTree, resultInfo))); } } @@ -203,15 +207,24 @@ public class DeferredAttr extends JCTree.Visitor { * attribution round must follow one or more speculative rounds. */ Type check(ResultInfo resultInfo) { - return check(resultInfo, stuckVars(tree, env, resultInfo), basicCompleter); + DeferredStuckPolicy deferredStuckPolicy; + if (resultInfo.pt.hasTag(NONE) || resultInfo.pt.isErroneous()) { + deferredStuckPolicy = dummyStuckPolicy; + } else if (resultInfo.checkContext.deferredAttrContext().mode == AttrMode.SPECULATIVE) { + deferredStuckPolicy = new OverloadStuckPolicy(resultInfo, this); + } else { + deferredStuckPolicy = new CheckStuckPolicy(resultInfo, this); + } + return check(resultInfo, deferredStuckPolicy, basicCompleter); } - Type check(ResultInfo resultInfo, List stuckVars, DeferredTypeCompleter deferredTypeCompleter) { + private Type check(ResultInfo resultInfo, DeferredStuckPolicy deferredStuckPolicy, + DeferredTypeCompleter deferredTypeCompleter) { DeferredAttrContext deferredAttrContext = resultInfo.checkContext.deferredAttrContext(); Assert.check(deferredAttrContext != emptyDeferredAttrContext); - if (stuckVars.nonEmpty()) { - deferredAttrContext.addDeferredAttrNode(this, resultInfo, stuckVars); + if (deferredStuckPolicy.isStuck()) { + deferredAttrContext.addDeferredAttrNode(this, resultInfo, deferredStuckPolicy); return Type.noType; } else { try { @@ -236,6 +249,7 @@ public class DeferredAttr extends JCTree.Visitor { Type complete(DeferredType dt, ResultInfo resultInfo, DeferredAttrContext deferredAttrContext); } + /** * A basic completer for deferred types. This completer type-checks a deferred type * using attribution; depending on the attribution mode, this could be either standard @@ -249,7 +263,7 @@ public class DeferredAttr extends JCTree.Visitor { //speculative rounds... Assert.check(dt.mode == null || dt.mode == AttrMode.SPECULATIVE); JCTree speculativeTree = attribSpeculative(dt.tree, dt.env, resultInfo); - dt.speculativeCache.put(deferredAttrContext.msym, speculativeTree, deferredAttrContext.phase); + dt.speculativeCache.put(speculativeTree, resultInfo); return speculativeTree.type; case CHECK: Assert.check(dt.mode != null); @@ -267,6 +281,45 @@ public class DeferredAttr extends JCTree.Visitor { } }; + /** + * Policy for detecting stuck expressions. Different criteria might cause + * an expression to be judged as stuck, depending on whether the check + * is performed during overload resolution or after most specific. + */ + interface DeferredStuckPolicy { + /** + * Has the policy detected that a given expression should be considered stuck? + */ + boolean isStuck(); + /** + * Get the set of inference variables a given expression depends upon. + */ + Set stuckVars(); + /** + * Get the set of inference variables which might get new constraints + * if a given expression is being type-checked. + */ + Set depVars(); + } + + /** + * Basic stuck policy; an expression is never considered to be stuck. + */ + DeferredStuckPolicy dummyStuckPolicy = new DeferredStuckPolicy() { + @Override + public boolean isStuck() { + return false; + } + @Override + public Set stuckVars() { + return Collections.emptySet(); + } + @Override + public Set depVars() { + return Collections.emptySet(); + } + }; + /** * The 'mode' in which the deferred type is to be type-checked */ @@ -388,8 +441,9 @@ public class DeferredAttr extends JCTree.Visitor { * Adds a node to the list of deferred attribution nodes - used by Resolve.rawCheckArgumentsApplicable * Nodes added this way act as 'roots' for the out-of-order method checking process. */ - void addDeferredAttrNode(final DeferredType dt, ResultInfo resultInfo, List stuckVars) { - deferredAttrNodes.add(new DeferredAttrNode(dt, resultInfo, stuckVars)); + void addDeferredAttrNode(final DeferredType dt, ResultInfo resultInfo, + DeferredStuckPolicy deferredStuckPolicy) { + deferredAttrNodes.add(new DeferredAttrNode(dt, resultInfo, deferredStuckPolicy)); } /** @@ -400,23 +454,52 @@ public class DeferredAttr extends JCTree.Visitor { */ void complete() { while (!deferredAttrNodes.isEmpty()) { - Set stuckVars = new LinkedHashSet(); + Map> depVarsMap = new LinkedHashMap>(); + List stuckVars = List.nil(); boolean progress = false; //scan a defensive copy of the node list - this is because a deferred //attribution round can add new nodes to the list for (DeferredAttrNode deferredAttrNode : List.from(deferredAttrNodes)) { if (!deferredAttrNode.process(this)) { - stuckVars.addAll(deferredAttrNode.stuckVars); + List restStuckVars = + List.from(deferredAttrNode.deferredStuckPolicy.stuckVars()) + .intersect(inferenceContext.restvars()); + stuckVars = stuckVars.prependList(restStuckVars); + //update dependency map + for (Type t : List.from(deferredAttrNode.deferredStuckPolicy.depVars()) + .intersect(inferenceContext.restvars())) { + Set prevDeps = depVarsMap.get(t); + if (prevDeps == null) { + prevDeps = new LinkedHashSet(); + depVarsMap.put(t, prevDeps); + } + prevDeps.addAll(restStuckVars); + } } else { deferredAttrNodes.remove(deferredAttrNode); progress = true; } } if (!progress) { + DeferredAttrContext dac = this; + while (dac != emptyDeferredAttrContext) { + if (dac.mode == AttrMode.SPECULATIVE) { + //unsticking does not take place during overload + break; + } + dac = dac.parent; + } //remove all variables that have already been instantiated //from the list of stuck variables - inferenceContext.solveAny(List.from(stuckVars), warn); - inferenceContext.notifyChange(); + try { + inferenceContext.solveAny(stuckVars, depVarsMap, warn); + inferenceContext.notifyChange(); + } catch (Infer.GraphStrategy.NodeNotFoundException ex) { + //this means that we are in speculative mode and the + //set of contraints are too tight for progess to be made. + //Just leave the remaining expressions as stuck. + break; + } } } } @@ -426,7 +509,7 @@ public class DeferredAttr extends JCTree.Visitor { * Class representing a deferred attribution node. It keeps track of * a deferred type, along with the expected target type information. */ - class DeferredAttrNode implements Infer.FreeTypeListener { + class DeferredAttrNode { /** underlying deferred type */ DeferredType dt; @@ -434,22 +517,13 @@ public class DeferredAttr extends JCTree.Visitor { /** underlying target type information */ ResultInfo resultInfo; - /** list of uninferred inference variables causing this node to be stuck */ - List stuckVars; + /** stuck policy associated with this node */ + DeferredStuckPolicy deferredStuckPolicy; - DeferredAttrNode(DeferredType dt, ResultInfo resultInfo, List stuckVars) { + DeferredAttrNode(DeferredType dt, ResultInfo resultInfo, DeferredStuckPolicy deferredStuckPolicy) { this.dt = dt; this.resultInfo = resultInfo; - this.stuckVars = stuckVars; - if (!stuckVars.isEmpty()) { - resultInfo.checkContext.inferenceContext().addFreeTypeListener(stuckVars, this); - } - } - - @Override - public void typesInferred(InferenceContext inferenceContext) { - stuckVars = List.nil(); - resultInfo = resultInfo.dup(inferenceContext.asInstType(resultInfo.pt)); + this.deferredStuckPolicy = deferredStuckPolicy; } /** @@ -457,24 +531,41 @@ public class DeferredAttr extends JCTree.Visitor { * Invariant: a stuck node cannot be processed. */ @SuppressWarnings("fallthrough") - boolean process(DeferredAttrContext deferredAttrContext) { + boolean process(final DeferredAttrContext deferredAttrContext) { switch (deferredAttrContext.mode) { case SPECULATIVE: - dt.check(resultInfo, List.nil(), new StructuralStuckChecker()); - return true; + if (deferredStuckPolicy.isStuck()) { + dt.check(resultInfo, dummyStuckPolicy, new StructuralStuckChecker()); + return true; + } else { + Assert.error("Cannot get here"); + } case CHECK: - if (stuckVars.nonEmpty()) { + if (deferredStuckPolicy.isStuck()) { //stuck expression - see if we can propagate if (deferredAttrContext.parent != emptyDeferredAttrContext && - Type.containsAny(deferredAttrContext.parent.inferenceContext.inferencevars, List.from(stuckVars))) { - deferredAttrContext.parent.deferredAttrNodes.add(this); - dt.check(resultInfo, List.nil(), dummyCompleter); + Type.containsAny(deferredAttrContext.parent.inferenceContext.inferencevars, + List.from(deferredStuckPolicy.stuckVars()))) { + deferredAttrContext.parent.addDeferredAttrNode(dt, + resultInfo.dup(new Check.NestedCheckContext(resultInfo.checkContext) { + @Override + public InferenceContext inferenceContext() { + return deferredAttrContext.parent.inferenceContext; + } + @Override + public DeferredAttrContext deferredAttrContext() { + return deferredAttrContext.parent; + } + }), deferredStuckPolicy); + dt.tree.type = Type.stuckType; return true; } else { return false; } } else { - dt.check(resultInfo, stuckVars, basicCompleter); + ResultInfo instResultInfo = + resultInfo.dup(deferredAttrContext.inferenceContext.asInstType(resultInfo.pt)); + dt.check(instResultInfo, dummyStuckPolicy, basicCompleter); return true; } default: @@ -489,12 +580,14 @@ public class DeferredAttr extends JCTree.Visitor { ResultInfo resultInfo; InferenceContext inferenceContext; + Env env; public Type complete(DeferredType dt, ResultInfo resultInfo, DeferredAttrContext deferredAttrContext) { this.resultInfo = resultInfo; this.inferenceContext = deferredAttrContext.inferenceContext; + this.env = dt.env; dt.tree.accept(this); - dt.speculativeCache.put(deferredAttrContext.msym, stuckTree, deferredAttrContext.phase); + dt.speculativeCache.put(stuckTree, resultInfo); return Type.noType; } @@ -541,15 +634,25 @@ public class DeferredAttr extends JCTree.Visitor { } catch (Types.FunctionDescriptorLookupError ex) { checkContext.report(null, ex.getDiagnostic()); } - switch (tree.sym.kind) { + Env localEnv = env.dup(tree); + JCExpression exprTree = (JCExpression)attribSpeculative(tree.getQualifierExpression(), localEnv, + attr.memberReferenceQualifierResult(tree)); + ListBuffer argtypes = ListBuffer.lb(); + for (Type t : types.findDescriptorType(pt).getParameterTypes()) { + argtypes.append(Type.noType); + } + JCMemberReference mref2 = new TreeCopier(make).copy(tree); + mref2.expr = exprTree; + Pair lookupRes = + rs.resolveMemberReference(tree, localEnv, mref2, exprTree.type, + tree.name, argtypes.toList(), null, true, rs.arityMethodCheck, inferenceContext); + switch (lookupRes.fst.kind) { //note: as argtypes are erroneous types, type-errors must //have been caused by arity mismatch case Kinds.ABSENT_MTH: case Kinds.WRONG_MTH: case Kinds.WRONG_MTHS: - case Kinds.STATICERR: - case Kinds.MISSING_ENCL: - checkContext.report(null, diags.fragment("incompatible.arg.types.in.mref")); + checkContext.report(tree, diags.fragment("incompatible.arg.types.in.mref")); } } } @@ -575,18 +678,12 @@ public class DeferredAttr extends JCTree.Visitor { infer.emptyContext, emptyDeferredAttrContext, types.noWarnings); } - protected boolean validState(DeferredType dt) { - return dt.mode != null && - deferredAttrContext.mode.ordinal() <= dt.mode.ordinal(); - } - @Override public Type apply(Type t) { if (!t.hasTag(DEFERRED)) { return t.map(this); } else { DeferredType dt = (DeferredType)t; - Assert.check(validState(dt)); return typeOf(dt); } } @@ -623,11 +720,6 @@ public class DeferredAttr extends JCTree.Visitor { recover(dt) : owntype; } - @Override - protected boolean validState(DeferredType dt) { - return true; - } - /** * Synthesize a type for a deferred type that hasn't been previously * reduced to an ordinary type. Functional deferred types and conditionals @@ -646,25 +738,6 @@ public class DeferredAttr extends JCTree.Visitor { } } - /** - * Retrieves the list of inference variables that need to be inferred before - * an AST node can be type-checked - */ - @SuppressWarnings("fallthrough") - List stuckVars(JCTree tree, Env env, ResultInfo resultInfo) { - if (resultInfo.pt.hasTag(NONE) || resultInfo.pt.isErroneous()) { - return List.nil(); - } else { - return stuckVarsInternal(tree, resultInfo.pt, env, resultInfo.checkContext.inferenceContext()); - } - } - //where - private List stuckVarsInternal(JCTree tree, Type pt, Env env, Infer.InferenceContext inferenceContext) { - StuckChecker sc = new StuckChecker(pt, env, inferenceContext); - sc.scan(tree); - return List.from(sc.stuckVars); - } - /** * A special tree scanner that would only visit portions of a given tree. * The set of nodes visited by the scanner can be customized at construction-time. @@ -737,17 +810,41 @@ public class DeferredAttr extends JCTree.Visitor { * inferring types that make some of the nested expressions incompatible * with their corresponding instantiated target */ - class StuckChecker extends PolyScanner { + class CheckStuckPolicy extends PolyScanner implements DeferredStuckPolicy, Infer.FreeTypeListener { Type pt; - Env env; Infer.InferenceContext inferenceContext; Set stuckVars = new LinkedHashSet(); + Set depVars = new LinkedHashSet(); - StuckChecker(Type pt, Env env, Infer.InferenceContext inferenceContext) { - this.pt = pt; - this.env = env; - this.inferenceContext = inferenceContext; + @Override + public boolean isStuck() { + return !stuckVars.isEmpty(); + } + + @Override + public Set stuckVars() { + return stuckVars; + } + + @Override + public Set depVars() { + return depVars; + } + + public CheckStuckPolicy(ResultInfo resultInfo, DeferredType dt) { + this.pt = resultInfo.pt; + this.inferenceContext = resultInfo.checkContext.inferenceContext(); + scan(dt.tree); + if (!stuckVars.isEmpty()) { + resultInfo.checkContext.inferenceContext() + .addFreeTypeListener(List.from(stuckVars), this); + } + } + + @Override + public void typesInferred(InferenceContext inferenceContext) { + stuckVars.clear(); } @Override @@ -763,6 +860,7 @@ public class DeferredAttr extends JCTree.Visitor { if (tree.paramKind == JCLambda.ParameterKind.IMPLICIT && freeArgVars.nonEmpty()) { stuckVars.addAll(freeArgVars); + depVars.addAll(inferenceContext.freeVarsIn(descType.getReturnType())); } scanLambdaBody(tree, descType.getReturnType()); } @@ -780,41 +878,34 @@ public class DeferredAttr extends JCTree.Visitor { Type descType = types.findDescriptorType(pt); List freeArgVars = inferenceContext.freeVarsIn(descType.getParameterTypes()); - Env localEnv = env.dup(tree, env.info.dup()); - if (freeArgVars.nonEmpty()) { - //perform arity-based check - JCExpression exprTree = (JCExpression)attribSpeculative(tree.getQualifierExpression(), localEnv, - attr.memberReferenceQualifierResult(tree)); - ListBuffer argtypes = ListBuffer.lb(); - for (Type t : descType.getParameterTypes()) { - argtypes.append(Type.noType); - } - JCMemberReference mref2 = new TreeCopier(make).copy(tree); - mref2.expr = exprTree; - Pair lookupRes = - rs.resolveMemberReference(tree, localEnv, mref2, exprTree.type, - tree.name, argtypes.toList(), null, true, rs.arityMethodCheck, - inferenceContext); - Symbol res = tree.sym = lookupRes.fst; - if (res.kind >= Kinds.ERRONEOUS || - res.type.hasTag(FORALL) || - (res.flags() & Flags.VARARGS) != 0 || - (TreeInfo.isStaticSelector(exprTree, tree.name.table.names) && - exprTree.type.isRaw())) { - stuckVars.addAll(freeArgVars); - } + if (freeArgVars.nonEmpty() && + tree.overloadKind == JCMemberReference.OverloadKind.OVERLOADED) { + stuckVars.addAll(freeArgVars); + depVars.addAll(inferenceContext.freeVarsIn(descType.getReturnType())); } } void scanLambdaBody(JCLambda lambda, final Type pt) { if (lambda.getBodyKind() == JCTree.JCLambda.BodyKind.EXPRESSION) { - stuckVars.addAll(stuckVarsInternal(lambda.body, pt, env, inferenceContext)); + Type prevPt = this.pt; + try { + this.pt = pt; + scan(lambda.body); + } finally { + this.pt = prevPt; + } } else { LambdaReturnScanner lambdaScanner = new LambdaReturnScanner() { @Override public void visitReturn(JCReturn tree) { if (tree.expr != null) { - stuckVars.addAll(stuckVarsInternal(tree.expr, pt, env, inferenceContext)); + Type prevPt = CheckStuckPolicy.this.pt; + try { + CheckStuckPolicy.this.pt = pt; + CheckStuckPolicy.this.scan(tree.expr); + } finally { + CheckStuckPolicy.this.pt = prevPt; + } } } }; @@ -823,6 +914,42 @@ public class DeferredAttr extends JCTree.Visitor { } } + /** + * This visitor is used to check that structural expressions conform + * to their target - this step is required as inference could end up + * inferring types that make some of the nested expressions incompatible + * with their corresponding instantiated target + */ + class OverloadStuckPolicy extends CheckStuckPolicy implements DeferredStuckPolicy { + + boolean stuck; + + @Override + public boolean isStuck() { + return super.isStuck() || stuck; + } + + public OverloadStuckPolicy(ResultInfo resultInfo, DeferredType dt) { + super(resultInfo, dt); + } + + @Override + public void visitLambda(JCLambda tree) { + super.visitLambda(tree); + if (tree.paramKind == JCLambda.ParameterKind.IMPLICIT) { + stuck = true; + } + } + + @Override + public void visitReference(JCMemberReference tree) { + super.visitReference(tree); + if (tree.overloadKind == JCMemberReference.OverloadKind.OVERLOADED) { + stuck = true; + } + } + } + /** * Does the argument expression {@code expr} need speculative type-checking? */ @@ -904,6 +1031,26 @@ public class DeferredAttr extends JCTree.Visitor { @Override public void visitReference(JCMemberReference tree) { + //perform arity-based check + Env localEnv = env.dup(tree); + JCExpression exprTree = (JCExpression)attribSpeculative(tree.getQualifierExpression(), localEnv, + attr.memberReferenceQualifierResult(tree)); + JCMemberReference mref2 = new TreeCopier(make).copy(tree); + mref2.expr = exprTree; + Pair lookupRes = + rs.resolveMemberReference(tree, localEnv, mref2, exprTree.type, + tree.name, List.nil(), null, true, rs.nilMethodCheck, + infer.emptyContext); + Symbol res = tree.sym = lookupRes.fst; + if (res.kind >= Kinds.ERRONEOUS || + res.type.hasTag(FORALL) || + (res.flags() & Flags.VARARGS) != 0 || + (TreeInfo.isStaticSelector(exprTree, tree.name.table.names) && + exprTree.type.isRaw())) { + tree.overloadKind = JCMemberReference.OverloadKind.OVERLOADED; + } else { + tree.overloadKind = JCMemberReference.OverloadKind.UNOVERLOADED; + } //a method reference is always a poly expression result = ArgumentExpressionKind.POLY; } diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/Infer.java b/langtools/src/share/classes/com/sun/tools/javac/comp/Infer.java index a87156a6b07..4c9568eb32c 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Infer.java +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Infer.java @@ -40,17 +40,17 @@ import com.sun.tools.javac.comp.Infer.GraphSolver.InferenceGraph; import com.sun.tools.javac.comp.Infer.GraphSolver.InferenceGraph.Node; import com.sun.tools.javac.comp.Resolve.InapplicableMethodException; import com.sun.tools.javac.comp.Resolve.VerboseResolutionMode; - -import java.util.Comparator; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.TreeSet; +import com.sun.tools.javac.util.GraphUtils.TarjanNode; import java.util.ArrayList; import java.util.Collections; +import java.util.EnumMap; import java.util.EnumSet; +import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.Map; +import java.util.Set; import static com.sun.tools.javac.code.TypeTag.*; @@ -113,6 +113,12 @@ public class Infer { super(diags); } + @Override + InapplicableMethodException setMessage() { + //no message to set + return this; + } + @Override InapplicableMethodException setMessage(JCDiagnostic diag) { messages = messages.append(diag); @@ -1006,10 +1012,24 @@ public class Infer { * and (ii) tell th engine when we are done fixing inference variables */ interface GraphStrategy { + + /** + * A NodeNotFoundException is thrown whenever an inference strategy fails + * to pick the next node to solve in the inference graph. + */ + public static class NodeNotFoundException extends RuntimeException { + private static final long serialVersionUID = 0; + + InferenceGraph graph; + + public NodeNotFoundException(InferenceGraph graph) { + this.graph = graph; + } + } /** * Pick the next node (leaf) to solve in the graph */ - Node pickNode(InferenceGraph g); + Node pickNode(InferenceGraph g) throws NodeNotFoundException; /** * Is this the last step? */ @@ -1022,7 +1042,10 @@ public class Infer { */ abstract class LeafSolver implements GraphStrategy { public Node pickNode(InferenceGraph g) { - Assert.check(!g.nodes.isEmpty(), "No nodes to solve!"); + if (g.nodes.isEmpty()) { + //should not happen + throw new NodeNotFoundException(g); + }; return g.nodes.get(0); } @@ -1069,6 +1092,7 @@ public class Infer { */ abstract class BestLeafSolver extends LeafSolver { + /** list of ivars of which at least one must be solved */ List varsToSolve; BestLeafSolver(List varsToSolve) { @@ -1076,54 +1100,66 @@ public class Infer { } /** - * Computes the minimum path that goes from a given node to any of the nodes - * containing a variable in {@code varsToSolve}. For any given path, the cost - * is computed as the total number of type-variables that should be eagerly - * instantiated across that path. + * Computes a path that goes from a given node to the leafs in the graph. + * Typically this will start from a node containing a variable in + * {@code varsToSolve}. For any given path, the cost is computed as the total + * number of type-variables that should be eagerly instantiated across that path. */ - int computeMinPath(InferenceGraph g, Node n) { - return computeMinPath(g, n, List.nil(), 0); + Pair, Integer> computeTreeToLeafs(Node n) { + Pair, Integer> cachedPath = treeCache.get(n); + if (cachedPath == null) { + //cache miss + if (n.isLeaf()) { + //if leaf, stop + cachedPath = new Pair, Integer>(List.of(n), n.data.length()); + } else { + //if non-leaf, proceed recursively + Pair, Integer> path = new Pair, Integer>(List.of(n), n.data.length()); + for (Node n2 : n.getAllDependencies()) { + if (n2 == n) continue; + Pair, Integer> subpath = computeTreeToLeafs(n2); + path = new Pair, Integer>( + path.fst.prependList(subpath.fst), + path.snd + subpath.snd); + } + cachedPath = path; + } + //save results in cache + treeCache.put(n, cachedPath); + } + return cachedPath; } - int computeMinPath(InferenceGraph g, Node n, List path, int cost) { - if (path.contains(n)) return Integer.MAX_VALUE; - List path2 = path.prepend(n); - int cost2 = cost + n.data.size(); - if (!Collections.disjoint(n.data, varsToSolve)) { - return cost2; - } else { - int bestPath = Integer.MAX_VALUE; - for (Node n2 : g.nodes) { - if (n2.deps.contains(n)) { - int res = computeMinPath(g, n2, path2, cost2); - if (res < bestPath) { - bestPath = res; - } - } - } - return bestPath; - } - } + /** cache used to avoid redundant computation of tree costs */ + final Map, Integer>> treeCache = + new HashMap, Integer>>(); + + /** constant value used to mark non-existent paths */ + final Pair, Integer> noPath = + new Pair, Integer>(null, Integer.MAX_VALUE); /** * Pick the leaf that minimize cost */ @Override public Node pickNode(final InferenceGraph g) { - final Map leavesMap = new HashMap(); + treeCache.clear(); //graph changes at every step - cache must be cleared + Pair, Integer> bestPath = noPath; for (Node n : g.nodes) { - if (n.isLeaf(n)) { - leavesMap.put(n, computeMinPath(g, n)); + if (!Collections.disjoint(n.data, varsToSolve)) { + Pair, Integer> path = computeTreeToLeafs(n); + //discard all paths containing at least a node in the + //closure computed above + if (path.snd < bestPath.snd) { + bestPath = path; + } } } - Assert.check(!leavesMap.isEmpty(), "No nodes to solve!"); - TreeSet orderedLeaves = new TreeSet(new Comparator() { - public int compare(Node n1, Node n2) { - return leavesMap.get(n1) - leavesMap.get(n2); - } - }); - orderedLeaves.addAll(leavesMap.keySet()); - return orderedLeaves.first(); + if (bestPath == noPath) { + //no path leads there + throw new NodeNotFoundException(g); + } + return bestPath.fst.head; } } @@ -1320,6 +1356,33 @@ public class Infer { } } + /** + * There are two kinds of dependencies between inference variables. The basic + * kind of dependency (or bound dependency) arises when a variable mention + * another variable in one of its bounds. There's also a more subtle kind + * of dependency that arises when a variable 'might' lead to better constraints + * on another variable (this is typically the case with variables holding up + * stuck expressions). + */ + enum DependencyKind implements GraphUtils.DependencyKind { + + /** bound dependency */ + BOUND("dotted"), + /** stuck dependency */ + STUCK("dashed"); + + final String dotSyle; + + private DependencyKind(String dotSyle) { + this.dotSyle = dotSyle; + } + + @Override + public String getDotStyle() { + return dotSyle; + } + } + /** * This is the graph inference solver - the solver organizes all inference variables in * a given inference context by bound dependencies - in the general case, such dependencies @@ -1331,10 +1394,12 @@ public class Infer { class GraphSolver { InferenceContext inferenceContext; + Map> stuckDeps; Warner warn; - GraphSolver(InferenceContext inferenceContext, Warner warn) { + GraphSolver(InferenceContext inferenceContext, Map> stuckDeps, Warner warn) { this.inferenceContext = inferenceContext; + this.stuckDeps = stuckDeps; this.warn = warn; } @@ -1345,7 +1410,7 @@ public class Infer { */ void solve(GraphStrategy sstrategy) { checkWithinBounds(inferenceContext, warn); //initial propagation of bounds - InferenceGraph inferenceGraph = new InferenceGraph(); + InferenceGraph inferenceGraph = new InferenceGraph(stuckDeps); while (!sstrategy.done()) { InferenceGraph.Node nodeToSolve = sstrategy.pickNode(inferenceGraph); List varsToSolve = List.from(nodeToSolve.data); @@ -1390,64 +1455,172 @@ public class Infer { */ class Node extends GraphUtils.TarjanNode> { - Set deps; + /** map listing all dependencies (grouped by kind) */ + EnumMap> deps; Node(Type ivar) { super(ListBuffer.of(ivar)); - this.deps = new HashSet(); + this.deps = new EnumMap>(DependencyKind.class); } @Override - public Iterable getDependencies() { - return deps; + public GraphUtils.DependencyKind[] getSupportedDependencyKinds() { + return DependencyKind.values(); } @Override - public String printDependency(GraphUtils.Node> to) { - StringBuilder buf = new StringBuilder(); - String sep = ""; - for (Type from : data) { - UndetVar uv = (UndetVar)inferenceContext.asFree(from); - for (Type bound : uv.getBounds(InferenceBound.values())) { - if (bound.containsAny(List.from(to.data))) { - buf.append(sep); - buf.append(bound); - sep = ","; + public String getDependencyName(GraphUtils.Node> to, GraphUtils.DependencyKind dk) { + if (dk == DependencyKind.STUCK) return ""; + else { + StringBuilder buf = new StringBuilder(); + String sep = ""; + for (Type from : data) { + UndetVar uv = (UndetVar)inferenceContext.asFree(from); + for (Type bound : uv.getBounds(InferenceBound.values())) { + if (bound.containsAny(List.from(to.data))) { + buf.append(sep); + buf.append(bound); + sep = ","; + } } } + return buf.toString(); } - return buf.toString(); } - boolean isLeaf(Node n) { + @Override + public Iterable getAllDependencies() { + return getDependencies(DependencyKind.values()); + } + + @Override + public Iterable>> getDependenciesByKind(GraphUtils.DependencyKind dk) { + return getDependencies((DependencyKind)dk); + } + + /** + * Retrieves all dependencies with given kind(s). + */ + protected Set getDependencies(DependencyKind... depKinds) { + Set buf = new LinkedHashSet(); + for (DependencyKind dk : depKinds) { + Set depsByKind = deps.get(dk); + if (depsByKind != null) { + buf.addAll(depsByKind); + } + } + return buf; + } + + /** + * Adds dependency with given kind. + */ + protected void addDependency(DependencyKind dk, Node depToAdd) { + Set depsByKind = deps.get(dk); + if (depsByKind == null) { + depsByKind = new LinkedHashSet(); + deps.put(dk, depsByKind); + } + depsByKind.add(depToAdd); + } + + /** + * Add multiple dependencies of same given kind. + */ + protected void addDependencies(DependencyKind dk, Set depsToAdd) { + for (Node n : depsToAdd) { + addDependency(dk, n); + } + } + + /** + * Remove a dependency, regardless of its kind. + */ + protected Set removeDependency(Node n) { + Set removedKinds = new HashSet<>(); + for (DependencyKind dk : DependencyKind.values()) { + Set depsByKind = deps.get(dk); + if (depsByKind == null) continue; + if (depsByKind.remove(n)) { + removedKinds.add(dk); + } + } + return removedKinds; + } + + /** + * Compute closure of a give node, by recursively walking + * through all its dependencies (of given kinds) + */ + protected Set closure(DependencyKind... depKinds) { + boolean progress = true; + Set closure = new HashSet(); + closure.add(this); + while (progress) { + progress = false; + for (Node n1 : new HashSet(closure)) { + progress = closure.addAll(n1.getDependencies(depKinds)); + } + } + return closure; + } + + /** + * Is this node a leaf? This means either the node has no dependencies, + * or it just has self-dependencies. + */ + protected boolean isLeaf() { //no deps, or only one self dep - return (n.deps.isEmpty() || - n.deps.size() == 1 && n.deps.contains(n)); + Set allDeps = getDependencies(DependencyKind.BOUND, DependencyKind.STUCK); + if (allDeps.isEmpty()) return true; + for (Node n : allDeps) { + if (n != this) { + return false; + } + } + return true; } - void mergeWith(List nodes) { + /** + * Merge this node with another node, acquiring its dependencies. + * This routine is used to merge all cyclic node together and + * form an acyclic graph. + */ + protected void mergeWith(List nodes) { for (Node n : nodes) { Assert.check(n.data.length() == 1, "Attempt to merge a compound node!"); data.appendList(n.data); - deps.addAll(n.deps); + for (DependencyKind dk : DependencyKind.values()) { + addDependencies(dk, n.getDependencies(dk)); + } } //update deps - Set deps2 = new HashSet(); - for (Node d : deps) { - if (data.contains(d.data.first())) { - deps2.add(this); - } else { - deps2.add(d); + EnumMap> deps2 = new EnumMap>(DependencyKind.class); + for (DependencyKind dk : DependencyKind.values()) { + for (Node d : getDependencies(dk)) { + Set depsByKind = deps2.get(dk); + if (depsByKind == null) { + depsByKind = new LinkedHashSet(); + deps2.put(dk, depsByKind); + } + if (data.contains(d.data.first())) { + depsByKind.add(this); + } else { + depsByKind.add(d); + } } } deps = deps2; } - void graphChanged(Node from, Node to) { - if (deps.contains(from)) { - deps.remove(from); + /** + * Notify all nodes that something has changed in the graph + * topology. + */ + private void graphChanged(Node from, Node to) { + for (DependencyKind dk : removeDependency(from)) { if (to != null) { - deps.add(to); + addDependency(dk, to); } } } @@ -1456,8 +1629,21 @@ public class Infer { /** the nodes in the inference graph */ ArrayList nodes; - InferenceGraph() { - initNodes(); + InferenceGraph(Map> optDeps) { + initNodes(optDeps); + } + + /** + * Basic lookup helper for retrieving a graph node given an inference + * variable type. + */ + public Node findNode(Type t) { + for (Node n : nodes) { + if (n.data.contains(t)) { + return n; + } + } + return null; } /** @@ -1484,24 +1670,32 @@ public class Infer { * Create the graph nodes. First a simple node is created for every inference * variables to be solved. Then Tarjan is used to found all connected components * in the graph. For each component containing more than one node, a super node is - * created, effectively replacing the original cyclic nodes. + * created, effectively replacing the original cyclic nodes. */ - void initNodes() { + void initNodes(Map> stuckDeps) { + //add nodes nodes = new ArrayList(); for (Type t : inferenceContext.restvars()) { nodes.add(new Node(t)); } + //add dependencies for (Node n_i : nodes) { Type i = n_i.data.first(); + Set optDepsByNode = stuckDeps.get(i); for (Node n_j : nodes) { Type j = n_j.data.first(); UndetVar uv_i = (UndetVar)inferenceContext.asFree(i); if (Type.containsAny(uv_i.getBounds(InferenceBound.values()), List.of(j))) { - //update i's deps - n_i.deps.add(n_j); + //update i's bound dependencies + n_i.addDependency(DependencyKind.BOUND, n_j); + } + if (optDepsByNode != null && optDepsByNode.contains(j)) { + //update i's stuck dependencies + n_i.addDependency(DependencyKind.STUCK, n_j); } } } + //merge cyclic nodes ArrayList acyclicNodes = new ArrayList(); for (List conSubGraph : GraphUtils.tarjan(nodes)) { if (conSubGraph.length() > 1) { @@ -1631,8 +1825,8 @@ public class Infer { return filterVars(new Filter() { public boolean accepts(UndetVar uv) { return uv.getBounds(InferenceBound.UPPER) - .diff(uv.getDeclaredBounds()) - .appendList(uv.getBounds(InferenceBound.EQ, InferenceBound.LOWER)).nonEmpty(); + .diff(uv.getDeclaredBounds()) + .appendList(uv.getBounds(InferenceBound.EQ, InferenceBound.LOWER)).nonEmpty(); } }); } @@ -1822,11 +2016,15 @@ public class Infer { } } + private void solve(GraphStrategy ss, Warner warn) { + solve(ss, new HashMap>(), warn); + } + /** * Solve with given graph strategy. */ - private void solve(GraphStrategy ss, Warner warn) { - GraphSolver s = new GraphSolver(this, warn); + private void solve(GraphStrategy ss, Map> stuckDeps, Warner warn) { + GraphSolver s = new GraphSolver(this, stuckDeps, warn); s.solve(ss); } @@ -1855,18 +2053,12 @@ public class Infer { /** * Solve at least one variable in given list. */ - public void solveAny(List varsToSolve, Warner warn) { - checkWithinBounds(this, warn); //propagate bounds - List boundedVars = boundedVars().intersect(restvars()).intersect(varsToSolve); - if (boundedVars.isEmpty()) { - throw inferenceException.setMessage("cyclic.inference", - freeVarsIn(varsToSolve)); - } - solve(new BestLeafSolver(boundedVars) { + public void solveAny(List varsToSolve, Map> optDeps, Warner warn) { + solve(new BestLeafSolver(varsToSolve.intersect(restvars())) { public boolean done() { return instvars().intersect(varsToSolve).nonEmpty(); } - }, warn); + }, optDeps, warn); } /** diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java b/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java index 0439e0d6132..03f50401171 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java @@ -568,8 +568,10 @@ public class Resolve { currentResolutionContext, warn); - currentResolutionContext.methodCheck.argumentsAcceptable(env, currentResolutionContext.deferredAttrContext(m, infer.emptyContext, resultInfo, warn), + DeferredAttr.DeferredAttrContext dc = currentResolutionContext.deferredAttrContext(m, infer.emptyContext, resultInfo, warn); + currentResolutionContext.methodCheck.argumentsAcceptable(env, dc, argtypes, mt.getParameterTypes(), warn); + dc.complete(); return mt; } @@ -1053,7 +1055,8 @@ public class Resolve { DeferredType dt = (DeferredType) actual; DeferredType.SpeculativeCache.Entry e = dt.speculativeCache.get(deferredAttrContext.msym, deferredAttrContext.phase); return (e == null || e.speculativeTree == deferredAttr.stuckTree) - ? false : mostSpecific(found, req, e.speculativeTree, warn); + ? super.compatible(found, req, warn) : + mostSpecific(found, req, e.speculativeTree, warn); default: return standaloneMostSpecific(found, req, actual, warn); } @@ -1125,13 +1128,15 @@ public class Resolve { @Override public void visitReference(JCMemberReference tree) { if (types.isFunctionalInterface(t.tsym) && - types.isFunctionalInterface(s.tsym) && - types.asSuper(t, s.tsym) == null && - types.asSuper(s, t.tsym) == null) { + types.isFunctionalInterface(s.tsym)) { Type desc_t = types.findDescriptorType(t); Type desc_s = types.findDescriptorType(s); - if (types.isSameTypes(desc_t.getParameterTypes(), desc_s.getParameterTypes())) { - if (!desc_s.getReturnType().hasTag(VOID)) { + if (types.isSameTypes(desc_t.getParameterTypes(), + inferenceContext().asFree(desc_s.getParameterTypes()))) { + if (types.asSuper(t, s.tsym) != null || + types.asSuper(s, t.tsym) != null) { + result &= MostSpecificCheckContext.super.compatible(t, s, warn); + } else if (!desc_s.getReturnType().hasTag(VOID)) { //perform structural comparison Type ret_t = desc_t.getReturnType(); Type ret_s = desc_s.getReturnType(); @@ -1141,25 +1146,24 @@ public class Resolve { } else { return; } - } else { - result &= false; } } else { - result &= MostSpecificCheckContext.super.compatible(t, s, warn); + result &= false; } } @Override public void visitLambda(JCLambda tree) { if (types.isFunctionalInterface(t.tsym) && - types.isFunctionalInterface(s.tsym) && - types.asSuper(t, s.tsym) == null && - types.asSuper(s, t.tsym) == null) { + types.isFunctionalInterface(s.tsym)) { Type desc_t = types.findDescriptorType(t); Type desc_s = types.findDescriptorType(s); - if (tree.paramKind == JCLambda.ParameterKind.EXPLICIT - || types.isSameTypes(desc_t.getParameterTypes(), desc_s.getParameterTypes())) { - if (!desc_s.getReturnType().hasTag(VOID)) { + if (types.isSameTypes(desc_t.getParameterTypes(), + inferenceContext().asFree(desc_s.getParameterTypes()))) { + if (types.asSuper(t, s.tsym) != null || + types.asSuper(s, t.tsym) != null) { + result &= MostSpecificCheckContext.super.compatible(t, s, warn); + } else if (!desc_s.getReturnType().hasTag(VOID)) { //perform structural comparison Type ret_t = desc_t.getReturnType(); Type ret_s = desc_s.getReturnType(); @@ -1167,11 +1171,9 @@ public class Resolve { } else { return; } - } else { - result &= false; } } else { - result &= MostSpecificCheckContext.super.compatible(t, s, warn); + result &= false; } } //where @@ -1521,7 +1523,8 @@ public class Resolve { currentResolutionContext = prevResolutionContext; } } - private List adjustArgs(List args, Symbol msym, int length, boolean allowVarargs) { + + List adjustArgs(List args, Symbol msym, int length, boolean allowVarargs) { if ((msym.flags() & VARARGS) != 0 && allowVarargs) { Type varargsElem = types.elemtype(args.last()); if (varargsElem == null) { @@ -2241,33 +2244,33 @@ public class Resolve { public List getArgumentTypes(ResolveError errSym, Symbol accessedSym, Name name, List argtypes) { return (syms.operatorNames.contains(name)) ? argtypes : - Type.map(argtypes, new ResolveDeferredRecoveryMap(accessedSym)); - } - - class ResolveDeferredRecoveryMap extends DeferredAttr.RecoveryDeferredTypeMap { - - public ResolveDeferredRecoveryMap(Symbol msym) { - deferredAttr.super(AttrMode.SPECULATIVE, msym, currentResolutionContext.step); - } - - @Override - protected Type typeOf(DeferredType dt) { - Type res = super.typeOf(dt); - if (!res.isErroneous()) { - switch (TreeInfo.skipParens(dt.tree).getTag()) { - case LAMBDA: - case REFERENCE: - return dt; - case CONDEXPR: - return res == Type.recoveryType ? - dt : res; - } - } - return res; - } + Type.map(argtypes, new ResolveDeferredRecoveryMap(AttrMode.SPECULATIVE, accessedSym, currentResolutionContext.step)); } }; + class ResolveDeferredRecoveryMap extends DeferredAttr.RecoveryDeferredTypeMap { + + public ResolveDeferredRecoveryMap(AttrMode mode, Symbol msym, MethodResolutionPhase step) { + deferredAttr.super(mode, msym, step); + } + + @Override + protected Type typeOf(DeferredType dt) { + Type res = super.typeOf(dt); + if (!res.isErroneous()) { + switch (TreeInfo.skipParens(dt.tree).getTag()) { + case LAMBDA: + case REFERENCE: + return dt; + case CONDEXPR: + return res == Type.recoveryType ? + dt : res; + } + } + return res; + } + } + /** Check that sym is not an abstract method. */ void checkNonAbstract(DiagnosticPosition pos, Symbol sym) { @@ -3969,16 +3972,6 @@ public class Resolve { static { String argMismatchRegex = MethodCheckDiag.ARG_MISMATCH.regex(); - rewriters.put(new Template(argMismatchRegex, new Template("(.*)(bad.arg.types.in.lambda)", skip, skip)), - new DiagnosticRewriter() { - @Override - public JCDiagnostic rewriteDiagnostic(JCDiagnostic.Factory diags, - DiagnosticPosition preferedPos, DiagnosticSource preferredSource, - DiagnosticType preferredKind, JCDiagnostic d) { - return (JCDiagnostic)((JCDiagnostic)d.getArgs()[0]).getArgs()[1]; - } - }); - rewriters.put(new Template(argMismatchRegex, skip), new DiagnosticRewriter() { @Override diff --git a/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties b/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties index 5d1a22b84a1..4ca8a90c0c0 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties +++ b/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties @@ -742,11 +742,6 @@ compiler.misc.incompatible.arg.types.in.lambda=\ compiler.misc.incompatible.arg.types.in.mref=\ incompatible parameter types in method reference -# 0: list of type, 1: message segment -compiler.misc.bad.arg.types.in.lambda=\ - cannot type-check lambda expression with inferred parameter types\n\ - inferred types: {0} - compiler.err.new.not.allowed.in.annotation=\ ''new'' not allowed in an annotation @@ -1397,6 +1392,10 @@ compiler.warn.long.SVUID=\ compiler.warn.missing.SVUID=\ serializable class {0} has no definition of serialVersionUID +# 0: symbol, 1: symbol, 2: symbol, 3: symbol +compiler.warn.potentially.ambiguous.overload=\ + {0} in {1} is potentially ambiguous with {2} in {3} + # 0: message segment compiler.warn.override.varargs.missing=\ {0}; overridden method has no ''...'' @@ -1916,10 +1915,6 @@ compiler.misc.inferred.do.not.conform.to.eq.bounds=\ inferred: {0}\n\ equality constraints(s): {1} -# 0: list of type -compiler.misc.cyclic.inference=\ - Cannot instantiate inference variables {0} because of an inference loop - # 0: symbol compiler.misc.diamond=\ {0}<> diff --git a/langtools/src/share/classes/com/sun/tools/javac/tree/JCTree.java b/langtools/src/share/classes/com/sun/tools/javac/tree/JCTree.java index d2e9b67324b..a0581cce87a 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/tree/JCTree.java +++ b/langtools/src/share/classes/com/sun/tools/javac/tree/JCTree.java @@ -1908,6 +1908,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition { * Selects a member expression. */ public static class JCMemberReference extends JCFunctionalExpression implements MemberReferenceTree { + public ReferenceMode mode; public ReferenceKind kind; public Name name; @@ -1917,6 +1918,12 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition { public Type varargsElement; public PolyKind refPolyKind; public boolean ownerAccessible; + public OverloadKind overloadKind; + + public enum OverloadKind { + OVERLOADED, + UNOVERLOADED; + } /** * Javac-dependent classification for member references, based diff --git a/langtools/src/share/classes/com/sun/tools/javac/util/GraphUtils.java b/langtools/src/share/classes/com/sun/tools/javac/util/GraphUtils.java index c15f1ec66b9..aa9899ed210 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/util/GraphUtils.java +++ b/langtools/src/share/classes/com/sun/tools/javac/util/GraphUtils.java @@ -32,6 +32,18 @@ package com.sun.tools.javac.util; */ public class GraphUtils { + /** + * Basic interface for defining various dependency kinds. All dependency kinds + * must at least support basic capabilities to tell the DOT engine how to render them. + */ + public interface DependencyKind { + /** + * Returns the DOT representation (to be used in a {@code style} attribute + * that's most suited for this dependency kind. + */ + String getDotStyle(); + } + /** * This class is a basic abstract class for representing a node. * A node is associated with a given data. @@ -43,9 +55,20 @@ public class GraphUtils { this.data = data; } - public abstract Iterable> getDependencies(); + /** + * Get an array of the dependency kinds supported by this node. + */ + public abstract DependencyKind[] getSupportedDependencyKinds(); - public abstract String printDependency(Node to); + /** + * Get all dependencies, regardless of their kind. + */ + public abstract Iterable> getAllDependencies(); + + /** + * Get a name for the dependency (of given kind) linking this node to a given node + */ + public abstract String getDependencyName(Node to, DependencyKind dk); @Override public String toString() { @@ -66,7 +89,9 @@ public class GraphUtils { super(data); } - public abstract Iterable> getDependencies(); + public abstract Iterable> getAllDependencies(); + + public abstract Iterable> getDependenciesByKind(DependencyKind dk); public int compareTo(TarjanNode o) { return (index < o.index) ? -1 : (index == o.index) ? 0 : 1; @@ -95,7 +120,7 @@ public class GraphUtils { index++; stack.prepend(v); v.active = true; - for (TarjanNode nd: v.getDependencies()) { + for (TarjanNode nd: v.getAllDependencies()) { @SuppressWarnings("unchecked") N n = (N)nd; if (n.index == -1) { @@ -134,9 +159,11 @@ public class GraphUtils { } //dump arcs for (TarjanNode from : nodes) { - for (TarjanNode to : from.getDependencies()) { - buf.append(String.format("%s -> %s [label = \" %s \"];\n", - from.hashCode(), to.hashCode(), from.printDependency(to))); + for (DependencyKind dk : from.getSupportedDependencyKinds()) { + for (TarjanNode to : from.getDependenciesByKind(dk)) { + buf.append(String.format("%s -> %s [label = \" %s \" style = %s ];\n", + from.hashCode(), to.hashCode(), from.getDependencyName(to, dk), dk.getDotStyle())); + } } } buf.append("}\n"); diff --git a/langtools/src/share/classes/com/sun/tools/javac/util/List.java b/langtools/src/share/classes/com/sun/tools/javac/util/List.java index 611798d9caa..dee69807e2c 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/util/List.java +++ b/langtools/src/share/classes/com/sun/tools/javac/util/List.java @@ -116,6 +116,19 @@ public class List extends AbstractCollection implements java.util.List return buf.toList(); } + /** + * Create a new list from the first {@code n} elements of this list + */ + public List take(int n) { + ListBuffer buf = ListBuffer.lb(); + int count = 0; + for (A el : this) { + if (count++ == n) break; + buf.append(el); + } + return buf.toList(); + } + /** Construct a list consisting of given element. */ public static List of(A x1) { diff --git a/langtools/test/tools/javac/Diagnostics/compressed/T8012003c.out b/langtools/test/tools/javac/Diagnostics/compressed/T8012003c.out index 7af49cc18e5..e2e2c8549c9 100644 --- a/langtools/test/tools/javac/Diagnostics/compressed/T8012003c.out +++ b/langtools/test/tools/javac/Diagnostics/compressed/T8012003c.out @@ -1,3 +1,2 @@ T8012003c.java:18:15: compiler.err.report.access: m(), private, P -- compiler.note.compressed.diags 1 error diff --git a/langtools/test/tools/javac/diags/examples/BadArgTypesInLambda.java b/langtools/test/tools/javac/diags/examples/BadArgTypesInLambda.java index 493c4c31efc..e4feea050d5 100644 --- a/langtools/test/tools/javac/diags/examples/BadArgTypesInLambda.java +++ b/langtools/test/tools/javac/diags/examples/BadArgTypesInLambda.java @@ -21,9 +21,6 @@ * questions. */ -// key: compiler.err.cant.apply.symbol -// key: compiler.misc.no.conforming.assignment.exists -// key: compiler.misc.bad.arg.types.in.lambda // key: compiler.err.prob.found.req // key: compiler.misc.inconvertible.types // options: -Xdiags:verbose diff --git a/langtools/test/tools/javac/diags/examples/IncompatibleArgTypesInMethodRef.java b/langtools/test/tools/javac/diags/examples/IncompatibleArgTypesInMethodRef.java index 999eb903296..a983af8663f 100644 --- a/langtools/test/tools/javac/diags/examples/IncompatibleArgTypesInMethodRef.java +++ b/langtools/test/tools/javac/diags/examples/IncompatibleArgTypesInMethodRef.java @@ -31,6 +31,7 @@ class IncompatibleArgTypesInMethodRef { } void g(String s, Integer i) { } + void g(Integer i, String s) { } void m(SAM s) { } diff --git a/langtools/test/tools/javac/diags/examples/CyclicInference.java b/langtools/test/tools/javac/diags/examples/PotentiallyAmbiguousOverload.java similarity index 75% rename from langtools/test/tools/javac/diags/examples/CyclicInference.java rename to langtools/test/tools/javac/diags/examples/PotentiallyAmbiguousOverload.java index 0a6bc7a2b82..50660cf49e1 100644 --- a/langtools/test/tools/javac/diags/examples/CyclicInference.java +++ b/langtools/test/tools/javac/diags/examples/PotentiallyAmbiguousOverload.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 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 @@ -21,17 +21,18 @@ * questions. */ -// key: compiler.err.prob.found.req -// key: compiler.misc.cyclic.inference +// key: compiler.warn.potentially.ambiguous.overload +// options: -Xlint:overloads -class CyclicInference { - interface SAM { - void m(X x); +class PotentiallyAmbiguousOverload { + interface F1 { + void m(String s); } - void g(SAM sz) { } - - void test() { - g(x-> {}); + interface F2 { + void m(Integer s); } + + void m(F1 f1) { } + void m(F2 f2) { } } diff --git a/langtools/test/tools/javac/lambda/8016177/T8016177a.java b/langtools/test/tools/javac/lambda/8016177/T8016177a.java new file mode 100644 index 00000000000..bc36c2eae00 --- /dev/null +++ b/langtools/test/tools/javac/lambda/8016177/T8016177a.java @@ -0,0 +1,45 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8016177 8016178 + * @summary structural most specific and stuckness + * @compile/fail/ref=T8016177a.out -XDrawDiagnostics T8016177a.java + */ +import java.util.List; + +class T8016177a { + + interface ToIntFunction { + int m(X x); + } + + interface Function { + Y m(X x); + } + + void m1(List s, Function f) { } + void m1(List s, ToIntFunction f) { } + + List m2(List s, Function f) { return null; } + List m2(List s, ToIntFunction f) { return null; } + + List m3(List s, Function f) { return null; } + List m3(List s, ToIntFunction f) { return null; } + + List m4(List s, Function f) { return null; } + List m4(List s, ToIntFunction f) { return null; } + + List m5(List s, Function f) { return null; } + List m5(List s, ToIntFunction f) { return null; } + + List m6(List s, Function f) { return null; } + List m6(List s, ToIntFunction f) { return null; } + + void test(List ss) { + m1(ss, s->s.length()); //ambiguous + m2(ss, s->s.length()); //ambiguous + m3(ss, s->s.length()); //ambiguous + m4(ss, s->s.length()); //ambiguous + m5(ss, s->s.length()); //ambiguous + m6(ss, s->s.length()); //ambiguous + } +} diff --git a/langtools/test/tools/javac/lambda/8016177/T8016177a.out b/langtools/test/tools/javac/lambda/8016177/T8016177a.out new file mode 100644 index 00000000000..7efd6ebfe45 --- /dev/null +++ b/langtools/test/tools/javac/lambda/8016177/T8016177a.out @@ -0,0 +1,8 @@ +T8016177a.java:38:10: compiler.err.ref.ambiguous: m1, kindname.method, m1(java.util.List,T8016177a.Function), T8016177a, kindname.method, m1(java.util.List,T8016177a.ToIntFunction), T8016177a +T8016177a.java:39:10: compiler.err.ref.ambiguous: m2, kindname.method, m2(java.util.List,T8016177a.Function), T8016177a, kindname.method, m2(java.util.List,T8016177a.ToIntFunction), T8016177a +T8016177a.java:40:10: compiler.err.ref.ambiguous: m3, kindname.method, m3(java.util.List,T8016177a.Function), T8016177a, kindname.method, m3(java.util.List,T8016177a.ToIntFunction), T8016177a +T8016177a.java:41:10: compiler.err.ref.ambiguous: m4, kindname.method, m4(java.util.List,T8016177a.Function), T8016177a, kindname.method, m4(java.util.List,T8016177a.ToIntFunction), T8016177a +T8016177a.java:42:10: compiler.err.ref.ambiguous: m5, kindname.method, m5(java.util.List,T8016177a.Function), T8016177a, kindname.method, m5(java.util.List,T8016177a.ToIntFunction), T8016177a +T8016177a.java:43:10: compiler.err.ref.ambiguous: m6, kindname.method, m6(java.util.List,T8016177a.Function), T8016177a, kindname.method, m6(java.util.List,T8016177a.ToIntFunction), T8016177a +T8016177a.java:43:12: compiler.err.prob.found.req: (compiler.misc.infer.no.conforming.assignment.exists: T,R, (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.inconvertible.types: int, java.lang.String))) +7 errors diff --git a/langtools/test/tools/javac/lambda/8016177/T8016177b.java b/langtools/test/tools/javac/lambda/8016177/T8016177b.java new file mode 100644 index 00000000000..fddd6cbb8de --- /dev/null +++ b/langtools/test/tools/javac/lambda/8016177/T8016177b.java @@ -0,0 +1,34 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8016177 8016178 + * @summary structural most specific and stuckness + * @compile/fail/ref=T8016177b.out -XDrawDiagnostics T8016177b.java + */ +class T8016177b { + interface ToIntFunction { + int m(X x); + } + + interface Function { + Y m(X x); + } + + Function id(Function arg) { return null; } + + Function id2(Function arg) { return null; } + ToIntFunction id2(ToIntFunction arg) { return null; } + + + X f(Y arg, Function f) { return null; } + + X f2(Y arg, Function f) { return null; } + X f2(Y arg, ToIntFunction f) { return null; } + + T g(T arg) { return null; } + + void test() { + g(f("hi", id(x->1))); //ok + g(f("hi", id2(x->1))); //ambiguous + g(f2("hi", id(x->1))); //ok + } +} diff --git a/langtools/test/tools/javac/lambda/8016177/T8016177b.out b/langtools/test/tools/javac/lambda/8016177/T8016177b.out new file mode 100644 index 00000000000..09bc289fc85 --- /dev/null +++ b/langtools/test/tools/javac/lambda/8016177/T8016177b.out @@ -0,0 +1,2 @@ +T8016177b.java:31:19: compiler.err.ref.ambiguous: id2, kindname.method, id2(T8016177b.Function), T8016177b, kindname.method, id2(T8016177b.ToIntFunction), T8016177b +1 error diff --git a/langtools/test/tools/javac/lambda/8016177/T8016177c.java b/langtools/test/tools/javac/lambda/8016177/T8016177c.java new file mode 100644 index 00000000000..d50b37beb9e --- /dev/null +++ b/langtools/test/tools/javac/lambda/8016177/T8016177c.java @@ -0,0 +1,47 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8016081 8016178 + * @summary structural most specific and stuckness + * @compile/fail/ref=T8016177c.out -XDrawDiagnostics T8016177c.java + */ + +class T8016177c { + + interface Function { + Y m(X x); + } + + interface ExtFunction extends Function { } + + U m1(Function f) { return null; } + U m1(ExtFunction f) { return null; } + + void m2(Function f) { } + void m2(ExtFunction f) { } + + void m3(Function f) { } + void m3(ExtFunction f) { } + + int g1(Object s) { return 1; } + + int g2(Number s) { return 1; } + int g2(Object s) { return 1; } + + void test() { + m1((Integer x)->x); //ok - explicit lambda - subtyping picks most specific + m2((Integer x)->x); //ok - explicit lambda - subtyping picks most specific + m3((Integer x)->x); //ok - explicit lambda (only one applicable) + + m1(x->1); //ok - stuck lambda but nominal most specific wins + m2(x->1); //ok - stuck lambda but nominal most specific wins + m3(x->1); //ambiguous - implicit lambda & different params + + m1(this::g1); //ok - unambiguous ref - subtyping picks most specific + m2(this::g1); //ok - unambiguous ref - subtyping picks most specific + m3(this::g1); //ambiguous - both applicable, neither most specific + + m1(this::g2); //ok - stuck mref but nominal most specific wins + m2(this::g2); //ok - stuck mref but nominal most specific wins + m3(this::g2); //ambiguous - different params + } +} diff --git a/langtools/test/tools/javac/lambda/8016177/T8016177c.out b/langtools/test/tools/javac/lambda/8016177/T8016177c.out new file mode 100644 index 00000000000..d5780901e96 --- /dev/null +++ b/langtools/test/tools/javac/lambda/8016177/T8016177c.out @@ -0,0 +1,4 @@ +T8016177c.java:37:9: compiler.err.ref.ambiguous: m3, kindname.method, m3(T8016177c.Function), T8016177c, kindname.method, m3(T8016177c.ExtFunction), T8016177c +T8016177c.java:41:9: compiler.err.ref.ambiguous: m3, kindname.method, m3(T8016177c.Function), T8016177c, kindname.method, m3(T8016177c.ExtFunction), T8016177c +T8016177c.java:45:9: compiler.err.ref.ambiguous: m3, kindname.method, m3(T8016177c.Function), T8016177c, kindname.method, m3(T8016177c.ExtFunction), T8016177c +3 errors diff --git a/langtools/test/tools/javac/lambda/8016177/T8016177d.java b/langtools/test/tools/javac/lambda/8016177/T8016177d.java new file mode 100644 index 00000000000..e9cc243fe2f --- /dev/null +++ b/langtools/test/tools/javac/lambda/8016177/T8016177d.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2013, 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 8016081 8016178 + * @summary structural most specific and stuckness + * @compile T8016177d.java + */ +import java.util.*; + +class T8016177d { + + interface UnaryOperator { + X m(X x); + } + + interface IntStream { + IntStream sorted(); + IntStream distinct(); + IntStream limit(int i); + } + + abstract class WrappingUnaryOperator implements UnaryOperator { } + + WrappingUnaryOperator wrap1(UnaryOperator uo) { return null; } + WrappingUnaryOperator wrap2(UnaryOperator uo) { return null; } + WrappingUnaryOperator wrap3(UnaryOperator uo) { return null; } + +

    List> perm(List

    l) { return null; } + + List>> intPermutationOfFunctions = + perm(Arrays.asList( + wrap1(s -> s.sorted()), + wrap2(s -> s.distinct()), + wrap3(s -> s.limit(5)) + )); +} diff --git a/langtools/test/tools/javac/lambda/8016177/T8016177e.java b/langtools/test/tools/javac/lambda/8016177/T8016177e.java new file mode 100644 index 00000000000..b26af04bc1a --- /dev/null +++ b/langtools/test/tools/javac/lambda/8016177/T8016177e.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2013, 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 8016081 8016178 + * @summary structural most specific and stuckness + * @compile T8016177e.java + */ +import java.util.*; + +class T8016177e { + + interface TerminalOp { } + + interface Consumer { + void m(X x); + } + + TerminalOp makeRef(Consumer action) { return null; } + + void test() { + Map map = null; + TerminalOp forEachOp = makeRef(t -> { map.put(t, null); }); + } +} diff --git a/langtools/test/tools/javac/lambda/8016177/T8016177f.java b/langtools/test/tools/javac/lambda/8016177/T8016177f.java new file mode 100644 index 00000000000..5f07fbbf04b --- /dev/null +++ b/langtools/test/tools/javac/lambda/8016177/T8016177f.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2013, 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 8016081 8016178 + * @summary structural most specific and stuckness + * @compile T8016177f.java + */ +import java.util.*; + +class T8016177f { + + interface Function { + T apply(S s); + } + + interface IntFunction { + T apply(int s); + } + + + interface BiConsumer { + void m(X x, Y y); + } + + interface Consumer { + void m(X x); + } + + interface Supplier { + X make(); + } + + interface TestData> { + interface OfRef extends TestData> { } + interface OfDouble extends TestData { } + } + + interface BaseStream> { } + + interface Stream extends BaseStream> { + Stream map(Function s); + R collect(Supplier resultFactory, BiConsumer accumulator, BiConsumer combiner); + Z[] toArray(IntFunction s); + } + + interface DoubleStream extends BaseStream { + DoubleStream filter(DoublePredicate dp); + double[] toArray(); + } + + interface DoublePredicate { + boolean p(double d); + } + + , S_OUT extends BaseStream> + R exerciseTerminalOps(TestData data, + Function streamF, + Function terminalF) { return null; } + + TestData.OfRef ofCollection(Collection collection) { return null; } + + void test1(TestData.OfDouble data, DoublePredicate dp) { + exerciseTerminalOps(data, s -> s.filter(dp), s -> s.toArray()); + } + + void test2(Function fdi, TestData.OfRef td, Stream si) { + exerciseTerminalOps( + ofCollection((List)null), + s -> s.map(fdi), + s -> s.toArray(Integer[]::new)); + } +} diff --git a/langtools/test/tools/javac/lambda/8016177/T8016177g.java b/langtools/test/tools/javac/lambda/8016177/T8016177g.java new file mode 100644 index 00000000000..f8660e892f0 --- /dev/null +++ b/langtools/test/tools/javac/lambda/8016177/T8016177g.java @@ -0,0 +1,37 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8016081 8016178 + * @summary structural most specific and stuckness + * @compile/fail/ref=T8016177g.out -XDrawDiagnostics T8016177g.java + */ + + +class Test { + + interface Function { + Y m(X x); + } + + interface Box { + T get(); + R map(Function f); + } + + static class Person { + Person(String name) { } + } + + void print(Object arg) { } + void print(String arg) { } + + int abs(int a) { return 0; } + long abs(long a) { return 0; } + float abs(float a) { return 0; } + double abs(double a) { return 0; } + + void test() { + Box b = null; + print(b.map(s -> new Person(s))); + int i = abs(b.map(s -> Double.valueOf(s))); + } +} diff --git a/langtools/test/tools/javac/lambda/8016177/T8016177g.out b/langtools/test/tools/javac/lambda/8016177/T8016177g.out new file mode 100644 index 00000000000..beb47b0f53c --- /dev/null +++ b/langtools/test/tools/javac/lambda/8016177/T8016177g.out @@ -0,0 +1,2 @@ +T8016177g.java:35:20: compiler.err.prob.found.req: (compiler.misc.possible.loss.of.precision: double, int) +1 error diff --git a/langtools/test/tools/javac/lambda/BadRecovery.out b/langtools/test/tools/javac/lambda/BadRecovery.out index 6035eecfd6f..427d97f0f81 100644 --- a/langtools/test/tools/javac/lambda/BadRecovery.out +++ b/langtools/test/tools/javac/lambda/BadRecovery.out @@ -1,2 +1,3 @@ +BadRecovery.java:17:9: compiler.err.cant.apply.symbol: kindname.method, m, BadRecovery.SAM1, @369, kindname.class, BadRecovery, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.arg.types.in.lambda)) BadRecovery.java:17:77: compiler.err.cant.resolve.location: kindname.variable, f, , , (compiler.misc.location: kindname.class, BadRecovery, null) -1 error +2 errors diff --git a/langtools/test/tools/javac/lambda/ErroneousLambdaExpr.java b/langtools/test/tools/javac/lambda/ErroneousLambdaExpr.java index be21473b241..173f084638b 100644 --- a/langtools/test/tools/javac/lambda/ErroneousLambdaExpr.java +++ b/langtools/test/tools/javac/lambda/ErroneousLambdaExpr.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2013 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,6 +26,7 @@ * @bug 8003280 * @summary Add lambda tests * stale state after speculative attribution round leads to missing classfiles + * @compile/fail/ref=ErroneousLambdaExpr.out -XDrawDiagnostics ErroneousLambdaExpr.java */ public class ErroneousLambdaExpr { diff --git a/langtools/test/tools/javac/lambda/ErroneousLambdaExpr.out b/langtools/test/tools/javac/lambda/ErroneousLambdaExpr.out new file mode 100644 index 00000000000..aeb312fb180 --- /dev/null +++ b/langtools/test/tools/javac/lambda/ErroneousLambdaExpr.out @@ -0,0 +1,2 @@ +ErroneousLambdaExpr.java:63:13: compiler.err.ref.ambiguous: call, kindname.method, call(ErroneousLambdaExpr.SAM1), ErroneousLambdaExpr, kindname.method, call(ErroneousLambdaExpr.SAM2), ErroneousLambdaExpr +1 error diff --git a/langtools/test/tools/javac/lambda/MethodReference22.out b/langtools/test/tools/javac/lambda/MethodReference22.out index d25b71e3a12..dfd2ebe554e 100644 --- a/langtools/test/tools/javac/lambda/MethodReference22.out +++ b/langtools/test/tools/javac/lambda/MethodReference22.out @@ -3,13 +3,17 @@ MethodReference22.java:41:15: compiler.err.invalid.mref: kindname.method, (compi MethodReference22.java:46:19: compiler.err.invalid.mref: kindname.method, (compiler.misc.non-static.cant.be.ref: kindname.method, m4(java.lang.String)) MethodReference22.java:47:15: compiler.err.invalid.mref: kindname.method, (compiler.misc.non-static.cant.be.ref: kindname.method, m4(java.lang.String)) MethodReference22.java:51:19: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.ref.ambiguous: m1, kindname.method, m1(MethodReference22,java.lang.String), MethodReference22, kindname.method, m1(java.lang.String), MethodReference22)) -MethodReference22.java:52:9: compiler.err.cant.apply.symbol: kindname.method, call2, MethodReference22.SAM2, @1401, kindname.class, MethodReference22, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.ref.ambiguous: m1, kindname.method, m1(MethodReference22,java.lang.String), MethodReference22, kindname.method, m1(java.lang.String), MethodReference22))) +MethodReference22.java:52:14: compiler.err.cant.apply.symbol: kindname.method, call2, MethodReference22.SAM2, @1401, kindname.class, MethodReference22, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.ref.ambiguous: m1, kindname.method, m1(MethodReference22,java.lang.String), MethodReference22, kindname.method, m1(java.lang.String), MethodReference22))) MethodReference22.java:53:19: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.ref.ambiguous: m2, kindname.method, m2(MethodReference22,java.lang.String), MethodReference22, kindname.method, m2(java.lang.String), MethodReference22)) -MethodReference22.java:54:9: compiler.err.cant.apply.symbol: kindname.method, call2, MethodReference22.SAM2, @1504, kindname.class, MethodReference22, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.ref.ambiguous: m2, kindname.method, m2(MethodReference22,java.lang.String), MethodReference22, kindname.method, m2(java.lang.String), MethodReference22))) +MethodReference22.java:54:14: compiler.err.cant.apply.symbol: kindname.method, call2, MethodReference22.SAM2, @1504, kindname.class, MethodReference22, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.ref.ambiguous: m2, kindname.method, m2(MethodReference22,java.lang.String), MethodReference22, kindname.method, m2(java.lang.String), MethodReference22))) MethodReference22.java:55:19: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.ref.ambiguous: m3, kindname.method, m3(MethodReference22,java.lang.String), MethodReference22, kindname.method, m3(java.lang.String), MethodReference22)) -MethodReference22.java:56:9: compiler.err.cant.apply.symbol: kindname.method, call2, MethodReference22.SAM2, @1607, kindname.class, MethodReference22, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.ref.ambiguous: m3, kindname.method, m3(MethodReference22,java.lang.String), MethodReference22, kindname.method, m3(java.lang.String), MethodReference22))) +MethodReference22.java:56:14: compiler.err.cant.apply.symbol: kindname.method, call2, MethodReference22.SAM2, @1607, kindname.class, MethodReference22, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.ref.ambiguous: m3, kindname.method, m3(MethodReference22,java.lang.String), MethodReference22, kindname.method, m3(java.lang.String), MethodReference22))) MethodReference22.java:57:19: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.ref.ambiguous: m4, kindname.method, m4(MethodReference22,java.lang.String), MethodReference22, kindname.method, m4(java.lang.String), MethodReference22)) -MethodReference22.java:58:9: compiler.err.cant.apply.symbol: kindname.method, call2, MethodReference22.SAM2, @1710, kindname.class, MethodReference22, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.ref.ambiguous: m4, kindname.method, m4(MethodReference22,java.lang.String), MethodReference22, kindname.method, m4(java.lang.String), MethodReference22))) +MethodReference22.java:58:14: compiler.err.cant.apply.symbol: kindname.method, call2, MethodReference22.SAM2, @1710, kindname.class, MethodReference22, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.ref.ambiguous: m4, kindname.method, m4(MethodReference22,java.lang.String), MethodReference22, kindname.method, m4(java.lang.String), MethodReference22))) +MethodReference22.java:62:9: compiler.err.ref.ambiguous: call3, kindname.method, call3(MethodReference22.SAM1), MethodReference22, kindname.method, call3(MethodReference22.SAM2), MethodReference22 MethodReference22.java:62:15: compiler.err.invalid.mref: kindname.method, (compiler.misc.non-static.cant.be.ref: kindname.method, m1(java.lang.String)) +MethodReference22.java:63:9: compiler.err.ref.ambiguous: call3, kindname.method, call3(MethodReference22.SAM1), MethodReference22, kindname.method, call3(MethodReference22.SAM2), MethodReference22 +MethodReference22.java:64:9: compiler.err.ref.ambiguous: call3, kindname.method, call3(MethodReference22.SAM1), MethodReference22, kindname.method, call3(MethodReference22.SAM2), MethodReference22 +MethodReference22.java:65:9: compiler.err.ref.ambiguous: call3, kindname.method, call3(MethodReference22.SAM1), MethodReference22, kindname.method, call3(MethodReference22.SAM2), MethodReference22 MethodReference22.java:65:15: compiler.err.invalid.mref: kindname.method, (compiler.misc.non-static.cant.be.ref: kindname.method, m4(java.lang.String)) -14 errors +18 errors diff --git a/langtools/test/tools/javac/lambda/MethodReference23.out b/langtools/test/tools/javac/lambda/MethodReference23.out index 3849d8631c6..462a75105ff 100644 --- a/langtools/test/tools/javac/lambda/MethodReference23.out +++ b/langtools/test/tools/javac/lambda/MethodReference23.out @@ -1,6 +1,6 @@ MethodReference23.java:52:19: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.constructor, (compiler.misc.cant.access.inner.cls.constr: Inner1, MethodReference23, MethodReference23)) -MethodReference23.java:53:9: compiler.err.cant.apply.symbol: kindname.method, call11, MethodReference23.SAM11, @1140, kindname.class, MethodReference23, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.invalid.mref: kindname.constructor, (compiler.misc.cant.access.inner.cls.constr: Inner1, MethodReference23, MethodReference23))) +MethodReference23.java:53:15: compiler.err.cant.apply.symbol: kindname.method, call11, MethodReference23.SAM11, @1140, kindname.class, MethodReference23, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.invalid.mref: kindname.constructor, (compiler.misc.cant.access.inner.cls.constr: Inner1, MethodReference23, MethodReference23))) MethodReference23.java:57:19: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.constructor, (compiler.misc.cant.access.inner.cls.constr: Inner1, , MethodReference23)) -MethodReference23.java:58:9: compiler.err.cant.apply.symbol: kindname.method, call12, MethodReference23.SAM12, @1282, kindname.class, MethodReference23, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.invalid.mref: kindname.constructor, (compiler.misc.cant.access.inner.cls.constr: Inner1, , MethodReference23))) +MethodReference23.java:58:15: compiler.err.cant.apply.symbol: kindname.method, call12, MethodReference23.SAM12, @1282, kindname.class, MethodReference23, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.invalid.mref: kindname.constructor, (compiler.misc.cant.access.inner.cls.constr: Inner1, , MethodReference23))) MethodReference23.java:72:9: compiler.err.ref.ambiguous: call3, kindname.method, call3(MethodReference23.SAM21), MethodReference23, kindname.method, call3(MethodReference23.SAM22), MethodReference23 5 errors diff --git a/langtools/test/tools/javac/lambda/MethodReference41.java b/langtools/test/tools/javac/lambda/MethodReference41.java index a2593320021..836dce0f1cb 100644 --- a/langtools/test/tools/javac/lambda/MethodReference41.java +++ b/langtools/test/tools/javac/lambda/MethodReference41.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2013, 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,18 +26,10 @@ * @bug 8003280 * @summary Add lambda tests * check that diamond inference is applied when using raw constructor reference qualifier - * @run main MethodReference41 + * @compile/fail/ref=MethodReference41.out -XDrawDiagnostics MethodReference41.java */ public class MethodReference41 { - static int assertionCount = 0; - - static void assertTrue(boolean cond) { - assertionCount++; - if (!cond) - throw new AssertionError(); - } - interface SAM1 { void m(String s); } @@ -54,13 +46,20 @@ public class MethodReference41 { Foo(X x) { } } + static void m1(SAM1 s) { } - static void m(SAM1 s) { assertTrue(false); } - static void m(SAM2 s) { assertTrue(true); } - static void m(SAM3 s) { assertTrue(false); } + static void m2(SAM2 s) { } + + static void m3(SAM3 s) { } + + static void m4(SAM1 s) { } + static void m4(SAM2 s) { } + static void m4(SAM3 s) { } public static void main(String[] args) { - m(Foo::new); - assertTrue(assertionCount == 1); + m1(Foo::new); + m2(Foo::new); + m3(Foo::new); + m4(Foo::new); } } diff --git a/langtools/test/tools/javac/lambda/MethodReference41.out b/langtools/test/tools/javac/lambda/MethodReference41.out new file mode 100644 index 00000000000..f4a60cb3ba6 --- /dev/null +++ b/langtools/test/tools/javac/lambda/MethodReference41.out @@ -0,0 +1,4 @@ +MethodReference41.java:60:11: compiler.err.cant.apply.symbol: kindname.method, m1, MethodReference41.SAM1, @1819, kindname.class, MethodReference41, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.invalid.mref: kindname.constructor, (compiler.misc.cant.apply.symbol: kindname.constructor, Foo, java.lang.Number, java.lang.String, kindname.class, MethodReference41.Foo, (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.String, java.lang.Number)))) +MethodReference41.java:62:11: compiler.err.cant.apply.symbol: kindname.method, m3, MethodReference41.SAM3, @1863, kindname.class, MethodReference41, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.invalid.mref: kindname.constructor, (compiler.misc.cant.apply.symbol: kindname.constructor, Foo, java.lang.Number, java.lang.Object, kindname.class, MethodReference41.Foo, (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Object, java.lang.Number)))) +MethodReference41.java:63:9: compiler.err.ref.ambiguous: m4, kindname.method, m4(MethodReference41.SAM2), MethodReference41, kindname.method, m4(MethodReference41.SAM3), MethodReference41 +3 errors diff --git a/langtools/test/tools/javac/lambda/MethodReference42.java b/langtools/test/tools/javac/lambda/MethodReference42.java index 1c8aaefab75..957dc024902 100644 --- a/langtools/test/tools/javac/lambda/MethodReference42.java +++ b/langtools/test/tools/javac/lambda/MethodReference42.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2013, 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,18 +26,10 @@ * @bug 8003280 * @summary Add lambda tests * check that diamond inference is applied when using raw constructor reference qualifier - * @run main MethodReference42 + * @compile/fail/ref=MethodReference42.out -XDrawDiagnostics MethodReference42.java */ public class MethodReference42 { - static int assertionCount = 0; - - static void assertTrue(boolean cond) { - assertionCount++; - if (!cond) - throw new AssertionError(); - } - static class SuperFoo { } static class Foo extends SuperFoo { } @@ -54,12 +46,20 @@ public class MethodReference42 { SuperFoo m(); } - static void m(SAM1 s) { assertTrue(false); } - static void m(SAM2 s) { assertTrue(true); } - static void m(SAM3 s) { assertTrue(false); } + static void m1(SAM1 s) { } + + static void m2(SAM2 s) { } + + static void m3(SAM3 s) { } + + static void m4(SAM1 s) { } + static void m4(SAM2 s) { } + static void m4(SAM3 s) { } public static void main(String[] args) { - m(Foo::new); - assertTrue(assertionCount == 1); + m1(Foo::new); + m2(Foo::new); + m3(Foo::new); + m4(Foo::new); } } diff --git a/langtools/test/tools/javac/lambda/MethodReference42.out b/langtools/test/tools/javac/lambda/MethodReference42.out new file mode 100644 index 00000000000..70ec85a352e --- /dev/null +++ b/langtools/test/tools/javac/lambda/MethodReference42.out @@ -0,0 +1,4 @@ +MethodReference42.java:60:11: compiler.err.cant.apply.symbol: kindname.method, m1, MethodReference42.SAM1, @1851, kindname.class, MethodReference42, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.eq.upper.bounds: X, java.lang.String, java.lang.Number)) +MethodReference42.java:62:11: compiler.err.cant.apply.symbol: kindname.method, m3, MethodReference42.SAM3, @1895, kindname.class, MethodReference42, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.eq.upper.bounds: X, java.lang.Object, java.lang.Number)) +MethodReference42.java:63:9: compiler.err.ref.ambiguous: m4, kindname.method, m4(MethodReference42.SAM2), MethodReference42, kindname.method, m4(MethodReference42.SAM3), MethodReference42 +3 errors diff --git a/langtools/test/tools/javac/lambda/MethodReference43.java b/langtools/test/tools/javac/lambda/MethodReference43.java index f7b8203d1b1..53cf98c702f 100644 --- a/langtools/test/tools/javac/lambda/MethodReference43.java +++ b/langtools/test/tools/javac/lambda/MethodReference43.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2013, 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,18 +26,10 @@ * @bug 8003280 * @summary Add lambda tests * check that diamond inference is applied when using raw constructor reference qualifier - * @run main MethodReference43 + * @compile/fail/ref=MethodReference43.out -XDrawDiagnostics MethodReference43.java */ public class MethodReference43 { - static int assertionCount = 0; - - static void assertTrue(boolean cond) { - assertionCount++; - if (!cond) - throw new AssertionError(); - } - interface SAM1 { Foo m(String s); } @@ -58,14 +50,24 @@ public class MethodReference43 { Foo(X x) { } } + static void m1(SAM1 s) { } - static void m(SAM1 s) { assertTrue(false); } - static void m(SAM2 s) { assertTrue(false); } - static void m(SAM3 s) { assertTrue(false); } - static void m(SAM4 s) { assertTrue(true); } + static void m2(SAM2 s) { } + + static void m3(SAM3 s) { } + + static void m4(SAM4 s) { } + + static void m5(SAM1 s) { } + static void m5(SAM2 s) { } + static void m5(SAM3 s) { } + static void m5(SAM4 s) { } public static void main(String[] args) { - m(Foo::new); - assertTrue(assertionCount == 1); + m1(Foo::new); + m2(Foo::new); + m3(Foo::new); + m4(Foo::new); + m5(Foo::new); } } diff --git a/langtools/test/tools/javac/lambda/MethodReference43.out b/langtools/test/tools/javac/lambda/MethodReference43.out new file mode 100644 index 00000000000..e1e0461d80f --- /dev/null +++ b/langtools/test/tools/javac/lambda/MethodReference43.out @@ -0,0 +1,5 @@ +MethodReference43.java:67:11: compiler.err.cant.apply.symbol: kindname.method, m1, MethodReference43.SAM1, @1937, kindname.class, MethodReference43, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.invalid.mref: kindname.constructor, (compiler.misc.cant.apply.symbol: kindname.constructor, Foo, java.lang.Number, java.lang.String, kindname.class, MethodReference43.Foo, (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.String, java.lang.Number)))) +MethodReference43.java:69:11: compiler.err.cant.apply.symbol: kindname.method, m3, MethodReference43.SAM3, @1981, kindname.class, MethodReference43, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.invalid.mref: kindname.constructor, (compiler.misc.cant.apply.symbol: kindname.constructor, Foo, java.lang.Number, java.lang.Object, kindname.class, MethodReference43.Foo, (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Object, java.lang.Number)))) +MethodReference43.java:71:9: compiler.err.ref.ambiguous: m5, kindname.method, m5(MethodReference43.SAM3), MethodReference43, kindname.method, m5(MethodReference43.SAM4), MethodReference43 +MethodReference43.java:71:11: compiler.err.cant.apply.symbol: kindname.method, m5, MethodReference43.SAM3, @2025, kindname.class, MethodReference43, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.invalid.mref: kindname.constructor, (compiler.misc.cant.apply.symbol: kindname.constructor, Foo, java.lang.Number, java.lang.Object, kindname.class, MethodReference43.Foo, (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Object, java.lang.Number)))) +4 errors diff --git a/langtools/test/tools/javac/lambda/MethodReference44.java b/langtools/test/tools/javac/lambda/MethodReference44.java index 8c92593b43a..be96ad2987b 100644 --- a/langtools/test/tools/javac/lambda/MethodReference44.java +++ b/langtools/test/tools/javac/lambda/MethodReference44.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2013, 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,18 +26,10 @@ * @bug 8003280 * @summary Add lambda tests * check that generic method reference is inferred when type parameters are omitted - * @run main MethodReference44 + * @compile/fail/ref=MethodReference44.out -XDrawDiagnostics MethodReference44.java */ public class MethodReference44 { - static int assertionCount = 0; - - static void assertTrue(boolean cond) { - assertionCount++; - if (!cond) - throw new AssertionError(); - } - static class SuperFoo { } static class Foo extends SuperFoo { } @@ -56,12 +48,20 @@ public class MethodReference44 { static Foo m() { return null; } - static void g(SAM1 s) { assertTrue(false); } - static void g(SAM2 s) { assertTrue(true); } - static void g(SAM3 s) { assertTrue(false); } + static void g1(SAM1 s) { } + + static void g2(SAM2 s) { } + + static void g3(SAM3 s) { } + + static void g4(SAM1 s) { } + static void g4(SAM2 s) { } + static void g4(SAM3 s) { } public static void main(String[] args) { - g(MethodReference44::m); - assertTrue(assertionCount == 1); + g1(MethodReference44::m); + g2(MethodReference44::m); + g3(MethodReference44::m); + g4(MethodReference44::m); } } diff --git a/langtools/test/tools/javac/lambda/MethodReference44.out b/langtools/test/tools/javac/lambda/MethodReference44.out new file mode 100644 index 00000000000..dbf1a394fde --- /dev/null +++ b/langtools/test/tools/javac/lambda/MethodReference44.out @@ -0,0 +1,4 @@ +MethodReference44.java:62:11: compiler.err.cant.apply.symbol: kindname.method, g1, MethodReference44.SAM1, @1904, kindname.class, MethodReference44, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.eq.upper.bounds: X, java.lang.String, java.lang.Number)) +MethodReference44.java:64:11: compiler.err.cant.apply.symbol: kindname.method, g3, MethodReference44.SAM3, @1972, kindname.class, MethodReference44, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.eq.upper.bounds: X, java.lang.Object, java.lang.Number)) +MethodReference44.java:65:9: compiler.err.ref.ambiguous: g4, kindname.method, g4(MethodReference44.SAM2), MethodReference44, kindname.method, g4(MethodReference44.SAM3), MethodReference44 +3 errors diff --git a/langtools/test/tools/javac/lambda/MethodReference46.java b/langtools/test/tools/javac/lambda/MethodReference46.java index 8f0c327faff..0a9d42b8414 100644 --- a/langtools/test/tools/javac/lambda/MethodReference46.java +++ b/langtools/test/tools/javac/lambda/MethodReference46.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2013, 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,18 +26,10 @@ * @bug 8003280 * @summary Add lambda tests * check that generic method reference is inferred when type parameters are omitted - * @run main MethodReference46 + * @compile/fail/ref=MethodReference46.out -XDrawDiagnostics MethodReference46.java */ public class MethodReference46 { - static int assertionCount = 0; - - static void assertTrue(boolean cond) { - assertionCount++; - if (!cond) - throw new AssertionError(); - } - interface SAM1 { void m(String s); } @@ -56,12 +48,20 @@ public class MethodReference46 { static void m(X fx) { } - static void g(SAM1 s) { assertTrue(false); } - static void g(SAM2 s) { assertTrue(true); } - static void g(SAM3 s) { assertTrue(false); } + static void g1(SAM1 s) { } + + static void g2(SAM2 s) { } + + static void g3(SAM3 s) { } + + static void g4(SAM1 s) { } + static void g4(SAM2 s) { } + static void g4(SAM3 s) { } public static void main(String[] args) { - g(MethodReference46::m); - assertTrue(assertionCount == 1); + g1(MethodReference46::m); + g2(MethodReference46::m); + g3(MethodReference46::m); + g4(MethodReference46::m); } } diff --git a/langtools/test/tools/javac/lambda/MethodReference46.out b/langtools/test/tools/javac/lambda/MethodReference46.out new file mode 100644 index 00000000000..544affbd675 --- /dev/null +++ b/langtools/test/tools/javac/lambda/MethodReference46.out @@ -0,0 +1,4 @@ +MethodReference46.java:62:11: compiler.err.cant.apply.symbol: kindname.method, g1, MethodReference46.SAM1, @1849, kindname.class, MethodReference46, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.cant.apply.symbol: kindname.method, m, X, java.lang.String, kindname.class, MethodReference46, (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.String, java.lang.Number)))) +MethodReference46.java:64:11: compiler.err.cant.apply.symbol: kindname.method, g3, MethodReference46.SAM3, @1917, kindname.class, MethodReference46, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.cant.apply.symbol: kindname.method, m, X, java.lang.Object, kindname.class, MethodReference46, (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Object, java.lang.Number)))) +MethodReference46.java:65:9: compiler.err.ref.ambiguous: g4, kindname.method, g4(MethodReference46.SAM2), MethodReference46, kindname.method, g4(MethodReference46.SAM3), MethodReference46 +3 errors diff --git a/langtools/test/tools/javac/lambda/MethodReference47.java b/langtools/test/tools/javac/lambda/MethodReference47.java index 5bc949dd03b..d5fff0dd4b4 100644 --- a/langtools/test/tools/javac/lambda/MethodReference47.java +++ b/langtools/test/tools/javac/lambda/MethodReference47.java @@ -7,14 +7,6 @@ */ public class MethodReference47 { - static int assertionCount = 0; - - static void assertTrue(boolean cond) { - assertionCount++; - if (!cond) - throw new AssertionError(); - } - interface SAM1 { void m(Integer s); } @@ -34,7 +26,7 @@ public class MethodReference47 { static void g2(SAM2 s) { } public static void main(String[] args) { - g1(MethodReference46::m); - g2(MethodReference46::m); + g1(MethodReference47::m); + g2(MethodReference47::m); } } diff --git a/langtools/test/tools/javac/lambda/MethodReference47.out b/langtools/test/tools/javac/lambda/MethodReference47.out index 39d3c31ba12..7a745728948 100644 --- a/langtools/test/tools/javac/lambda/MethodReference47.out +++ b/langtools/test/tools/javac/lambda/MethodReference47.out @@ -1,2 +1,2 @@ -MethodReference47.java:38:9: compiler.err.ref.ambiguous: g2, kindname.method, g2(MethodReference47.SAM1), MethodReference47, kindname.method, g2(MethodReference47.SAM2), MethodReference47 +MethodReference47.java:30:9: compiler.err.ref.ambiguous: g2, kindname.method, g2(MethodReference47.SAM1), MethodReference47, kindname.method, g2(MethodReference47.SAM2), MethodReference47 1 error diff --git a/langtools/test/tools/javac/lambda/MethodReference48.java b/langtools/test/tools/javac/lambda/MethodReference48.java index 8c3a704dd02..5247f4adb3b 100644 --- a/langtools/test/tools/javac/lambda/MethodReference48.java +++ b/langtools/test/tools/javac/lambda/MethodReference48.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2013, 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,18 +26,10 @@ * @bug 8003280 * @summary Add lambda tests * check that raw qualifier in unbound method reference is inferred from descriptor - * @run main MethodReference48 + * @compile/fail/ref=MethodReference48.out -XDrawDiagnostics MethodReference48.java */ public class MethodReference48 { - static int assertionCount = 0; - - static void assertTrue(boolean cond) { - assertionCount++; - if (!cond) - throw new AssertionError(); - } - static class Foo { X m() { return null; }; } @@ -54,12 +46,20 @@ public class MethodReference48 { Object m(Foo fi); } - static void g(SAM1 s) { assertTrue(false); } //return type not compatible - static void g(SAM2 s) { assertTrue(true); } //ok - static void g(SAM3 s) { assertTrue(false); } //ok but less specific + static void g1(SAM1 s) { } //return type not compatible + + static void g2(SAM2 s) { } //ok + + static void g3(SAM3 s) { } //ok + + static void g4(SAM1 s) { } //return type not compatible + static void g4(SAM2 s) { } //ok + static void g4(SAM3 s) { } //ok public static void main(String[] args) { - g(Foo::m); - assertTrue(assertionCount == 1); + g1(Foo::m); + g2(Foo::m); + g3(Foo::m); + g4(Foo::m); } } diff --git a/langtools/test/tools/javac/lambda/MethodReference48.out b/langtools/test/tools/javac/lambda/MethodReference48.out new file mode 100644 index 00000000000..732649e51f0 --- /dev/null +++ b/langtools/test/tools/javac/lambda/MethodReference48.out @@ -0,0 +1,3 @@ +MethodReference48.java:60:11: compiler.err.cant.apply.symbol: kindname.method, g1, MethodReference48.SAM1, @1909, kindname.class, MethodReference48, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.ret.type.in.mref: (compiler.misc.inconvertible.types: java.lang.String, MethodReference48.Foo))) +MethodReference48.java:63:9: compiler.err.ref.ambiguous: g4, kindname.method, g4(MethodReference48.SAM2), MethodReference48, kindname.method, g4(MethodReference48.SAM3), MethodReference48 +2 errors diff --git a/langtools/test/tools/javac/lambda/MethodReference70.out b/langtools/test/tools/javac/lambda/MethodReference70.out index 875b9d2d064..4cdccd5a50a 100644 --- a/langtools/test/tools/javac/lambda/MethodReference70.out +++ b/langtools/test/tools/javac/lambda/MethodReference70.out @@ -1,3 +1,3 @@ MethodReference70.java:26:10: compiler.err.ref.ambiguous: g, kindname.method, g(MethodReference70.F), MethodReference70, kindname.method, g(MethodReference70.G), MethodReference70 -MethodReference70.java:26:11: compiler.err.prob.found.req: (compiler.misc.cyclic.inference: Z) +MethodReference70.java:26:11: compiler.err.prob.found.req: (compiler.misc.infer.no.conforming.assignment.exists: Z, (compiler.misc.invalid.mref: kindname.method, (compiler.misc.cant.apply.symbols: kindname.method, m2, java.lang.Object,{(compiler.misc.inapplicable.method: kindname.method, MethodReference70, m2(java.lang.Integer), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: java.lang.Object, java.lang.Integer))),(compiler.misc.inapplicable.method: kindname.method, MethodReference70, m2(java.lang.String), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: java.lang.Object, java.lang.String)))}))) 2 errors diff --git a/langtools/test/tools/javac/lambda/MethodReference71.out b/langtools/test/tools/javac/lambda/MethodReference71.out index f1a8942e3d1..f95734da07e 100644 --- a/langtools/test/tools/javac/lambda/MethodReference71.out +++ b/langtools/test/tools/javac/lambda/MethodReference71.out @@ -1,3 +1,3 @@ MethodReference71.java:24:10: compiler.err.ref.ambiguous: g, kindname.method, g(MethodReference71.F), MethodReference71, kindname.method, g(MethodReference71.G), MethodReference71 -MethodReference71.java:24:11: compiler.err.prob.found.req: (compiler.misc.cyclic.inference: Z) +MethodReference71.java:24:11: compiler.err.prob.found.req: (compiler.misc.infer.no.conforming.assignment.exists: Z, (compiler.misc.invalid.mref: kindname.method, (compiler.misc.cant.apply.symbol: kindname.method, m2, java.lang.Integer[], java.lang.Object, kindname.class, MethodReference71, (compiler.misc.varargs.argument.mismatch: (compiler.misc.inconvertible.types: java.lang.Object, java.lang.Integer))))) 2 errors diff --git a/langtools/test/tools/javac/lambda/MostSpecific04.java b/langtools/test/tools/javac/lambda/MostSpecific04.java index c5fbc3d35a5..74ac24e4bc4 100644 --- a/langtools/test/tools/javac/lambda/MostSpecific04.java +++ b/langtools/test/tools/javac/lambda/MostSpecific04.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2013, 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,17 +26,10 @@ * @bug 8003280 * @summary Add lambda tests * Structural most specific doesn't handle cases with wildcards in functional interfaces + * @compile/fail/ref=MostSpecific04.out -XDrawDiagnostics MostSpecific04.java */ public class MostSpecific04 { - static int assertionCount = 0; - - static void assertTrue(boolean cond) { - assertionCount++; - if (!cond) - throw new AssertionError(); - } - interface DoubleMapper { double map(T t); } @@ -46,13 +39,13 @@ public class MostSpecific04 { } static class MyList { - void map(DoubleMapper m) { assertTrue(false); } - void map(LongMapper m) { assertTrue(true); } + void map(DoubleMapper m) { } + void map(LongMapper m) { } } public static void main(String[] args) { MyList ls = new MyList(); - ls.map(e->e.length()); - assertTrue(assertionCount == 1); + ls.map(e->e.length()); //ambiguous - implicit + ls.map((String e)->e.length()); //ok } } diff --git a/langtools/test/tools/javac/lambda/MostSpecific04.out b/langtools/test/tools/javac/lambda/MostSpecific04.out new file mode 100644 index 00000000000..3a672f0698e --- /dev/null +++ b/langtools/test/tools/javac/lambda/MostSpecific04.out @@ -0,0 +1,2 @@ +MostSpecific04.java:48:11: compiler.err.ref.ambiguous: map, kindname.method, map(MostSpecific04.DoubleMapper), MostSpecific04.MyList, kindname.method, map(MostSpecific04.LongMapper), MostSpecific04.MyList +1 error diff --git a/langtools/test/tools/javac/lambda/MostSpecific05.java b/langtools/test/tools/javac/lambda/MostSpecific05.java index 177a43e7637..f001ccc195b 100644 --- a/langtools/test/tools/javac/lambda/MostSpecific05.java +++ b/langtools/test/tools/javac/lambda/MostSpecific05.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2013, 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,17 +26,10 @@ * @bug 8003280 * @summary Add lambda tests * Structural most specific doesn't handle cases with wildcards in functional interfaces + * @compile/fail/ref=MostSpecific05.out -XDrawDiagnostics MostSpecific05.java */ public class MostSpecific05 { - static int assertionCount = 0; - - static void assertTrue(boolean cond) { - assertionCount++; - if (!cond) - throw new AssertionError(); - } - interface ObjectConverter { T map(Object o); } @@ -46,13 +39,13 @@ public class MostSpecific05 { } static class MyMapper { - void map(ObjectConverter m) { assertTrue(false); } - void map(NumberConverter m) { assertTrue(true); } + void map(ObjectConverter m) { } + void map(NumberConverter m) { } } public static void main(String[] args) { MyMapper mm = new MyMapper(); - mm.map(e->1.0); - assertTrue(assertionCount == 1); + mm.map(e->1.0); //ambiguous - implicit + mm.map((Object e)->1.0); //ok } } diff --git a/langtools/test/tools/javac/lambda/MostSpecific05.out b/langtools/test/tools/javac/lambda/MostSpecific05.out new file mode 100644 index 00000000000..d0d86c151b4 --- /dev/null +++ b/langtools/test/tools/javac/lambda/MostSpecific05.out @@ -0,0 +1,2 @@ +MostSpecific05.java:48:11: compiler.err.ref.ambiguous: map, kindname.method, map(MostSpecific05.ObjectConverter), MostSpecific05.MyMapper, kindname.method, map(MostSpecific05.NumberConverter), MostSpecific05.MyMapper +1 error diff --git a/langtools/test/tools/javac/lambda/MostSpecific08.java b/langtools/test/tools/javac/lambda/MostSpecific08.java index 453f04cd7f4..0673ef0ba06 100644 --- a/langtools/test/tools/javac/lambda/MostSpecific08.java +++ b/langtools/test/tools/javac/lambda/MostSpecific08.java @@ -25,7 +25,7 @@ * @test * @bug 8008813 * @summary Structural most specific fails when method reference is passed to overloaded method - * @compile MostSpecific08.java + * @compile/fail/ref=MostSpecific08.out -XDrawDiagnostics MostSpecific08.java */ class MostSpecific08 { @@ -51,12 +51,14 @@ class MostSpecific08 { } void testMref(Tester t) { - IntResult pr = t.apply(C::getInt); - ReferenceResult rr = t.apply(C::getInteger); + IntResult pr = t.apply(C::getInt); //ok - unoverloaded mref + ReferenceResult rr = t.apply(C::getInteger); //ok - unoverloaded mref } void testLambda(Tester t) { - IntResult pr = t.apply(c->c.getInt()); - ReferenceResult rr = t.apply(c->c.getInteger()); + IntResult pr1 = t.apply(c->c.getInt()); //ambiguous - implicit + IntResult pr2 = t.apply((C c)->c.getInt()); //ok + ReferenceResult rr1 = t.apply(c->c.getInteger()); //ambiguous - implicit + ReferenceResult rr2 = t.apply((C c)->c.getInteger()); //ok } } diff --git a/langtools/test/tools/javac/lambda/MostSpecific08.out b/langtools/test/tools/javac/lambda/MostSpecific08.out new file mode 100644 index 00000000000..f4e47d7d0ed --- /dev/null +++ b/langtools/test/tools/javac/lambda/MostSpecific08.out @@ -0,0 +1,4 @@ +MostSpecific08.java:59:26: compiler.err.ref.ambiguous: apply, kindname.method, apply(MostSpecific08.PrimitiveFunction), MostSpecific08.Tester, kindname.method, apply(MostSpecific08.ReferenceFunction), MostSpecific08.Tester +MostSpecific08.java:61:41: compiler.err.ref.ambiguous: apply, kindname.method, apply(MostSpecific08.PrimitiveFunction), MostSpecific08.Tester, kindname.method, apply(MostSpecific08.ReferenceFunction), MostSpecific08.Tester +MostSpecific08.java:61:47: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: MostSpecific08.IntResult, MostSpecific08.ReferenceResult) +3 errors diff --git a/langtools/test/tools/javac/lambda/TargetType01.java b/langtools/test/tools/javac/lambda/TargetType01.java index 0e8f16c045c..2ad86c64c88 100644 --- a/langtools/test/tools/javac/lambda/TargetType01.java +++ b/langtools/test/tools/javac/lambda/TargetType01.java @@ -26,7 +26,7 @@ * @bug 8003280 8009131 * @summary Add lambda tests * check nested case of overload resolution and lambda parameter inference - * @compile TargetType01.java + * @compile/fail/ref=TargetType01.out -XDrawDiagnostics TargetType01.java */ class TargetType01 { diff --git a/langtools/test/tools/javac/lambda/TargetType01.out b/langtools/test/tools/javac/lambda/TargetType01.out new file mode 100644 index 00000000000..b460bfc4230 --- /dev/null +++ b/langtools/test/tools/javac/lambda/TargetType01.out @@ -0,0 +1,3 @@ +TargetType01.java:45:9: compiler.err.ref.ambiguous: M, kindname.method, M(TargetType01.F_I_I), TargetType01, kindname.method, M(TargetType01.F_S_S), TargetType01 +TargetType01.java:45:26: compiler.err.ref.ambiguous: M, kindname.method, M(TargetType01.F_I_I), TargetType01, kindname.method, M(TargetType01.F_S_S), TargetType01 +2 errors diff --git a/langtools/test/tools/javac/lambda/TargetType02.java b/langtools/test/tools/javac/lambda/TargetType02.java index f5141ed18eb..05077c88f3d 100644 --- a/langtools/test/tools/javac/lambda/TargetType02.java +++ b/langtools/test/tools/javac/lambda/TargetType02.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2013, 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,19 +27,11 @@ * @summary Add lambda tests * check overload resolution and target type inference w.r.t. generic methods * @author Maurizio Cimadamore - * @run main TargetType02 + * @compile/fail/ref=TargetType02.out -XDrawDiagnostics TargetType02.java */ public class TargetType02 { - static int assertionCount = 0; - - static void assertTrue(boolean cond) { - assertionCount++; - if (!cond) - throw new AssertionError(); - } - interface S1 { X m(Integer x); } @@ -48,15 +40,16 @@ public class TargetType02 { abstract X m(Integer x); } - static void call(S1 s) { s.m(1); assertTrue(true); } - static void call(S2 s) { s.m(2); assertTrue(false); } + static void call1(S1 s) { } + + static void call2(S2 s) { } + + static void call3(S1 s) { } + static void call3(S2 s) { } void test() { - call(i -> { toString(); return i; }); - } - - public static void main(String[] args) { - new TargetType02().test(); - assertTrue(assertionCount == 1); + call1(i -> { toString(); return i; }); + call2(i -> { toString(); return i; }); + call3(i -> { toString(); return i; }); } } diff --git a/langtools/test/tools/javac/lambda/TargetType02.out b/langtools/test/tools/javac/lambda/TargetType02.out new file mode 100644 index 00000000000..2336ef70e6b --- /dev/null +++ b/langtools/test/tools/javac/lambda/TargetType02.out @@ -0,0 +1,3 @@ +TargetType02.java:52:14: compiler.err.prob.found.req: (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Integer, java.lang.String) +TargetType02.java:53:9: compiler.err.ref.ambiguous: call3, kindname.method, call3(TargetType02.S1), TargetType02, kindname.method, call3(TargetType02.S2), TargetType02 +2 errors diff --git a/langtools/test/tools/javac/lambda/TargetType10.java b/langtools/test/tools/javac/lambda/TargetType10.java index 39afaee727a..538b8e0221d 100644 --- a/langtools/test/tools/javac/lambda/TargetType10.java +++ b/langtools/test/tools/javac/lambda/TargetType10.java @@ -1,10 +1,10 @@ /* * @test /nodynamiccopyright/ - * @bug 8003280 + * @bug 8003280 8016177 * @summary Add lambda tests * check that wildcards in the target method of a lambda conversion is handled correctly * @author Maurizio Cimadamore - * @compile/fail/ref=TargetType10.out -XDrawDiagnostics TargetType10.java + * @compile TargetType10.java */ class TargetType10 { diff --git a/langtools/test/tools/javac/lambda/TargetType10.out b/langtools/test/tools/javac/lambda/TargetType10.out deleted file mode 100644 index eaf9bb3a07f..00000000000 --- a/langtools/test/tools/javac/lambda/TargetType10.out +++ /dev/null @@ -1,2 +0,0 @@ -TargetType10.java:17:18: compiler.err.prob.found.req: (compiler.misc.cyclic.inference: B,A) -1 error diff --git a/langtools/test/tools/javac/lambda/TargetType21.java b/langtools/test/tools/javac/lambda/TargetType21.java index ac70cacb6dc..d55e803cb4a 100644 --- a/langtools/test/tools/javac/lambda/TargetType21.java +++ b/langtools/test/tools/javac/lambda/TargetType21.java @@ -26,8 +26,10 @@ class TargetType21 { void test() { call(x -> { throw new Exception(); }); //ambiguous + call((Integer x) -> { System.out.println(""); }); //ok (only one is void) + call((Integer x) -> { return (Object) null; }); //ok (only one returns Object) call(x -> { System.out.println(""); }); //ambiguous - call(x -> { return (Object) null; }); //cyclic inference + call(x -> { return (Object) null; }); //ambiguous call(x -> { return null; }); //ambiguous } } diff --git a/langtools/test/tools/javac/lambda/TargetType21.out b/langtools/test/tools/javac/lambda/TargetType21.out index 904e30f1278..90131dc4bfc 100644 --- a/langtools/test/tools/javac/lambda/TargetType21.out +++ b/langtools/test/tools/javac/lambda/TargetType21.out @@ -1,5 +1,7 @@ TargetType21.java:28:9: compiler.err.ref.ambiguous: call, kindname.method, call(TargetType21.SAM2), TargetType21, kindname.method, call(TargetType21.SAM3), TargetType21 -TargetType21.java:29:9: compiler.err.ref.ambiguous: call, kindname.method, call(TargetType21.SAM2), TargetType21, kindname.method, call(TargetType21.SAM3), TargetType21 -TargetType21.java:30:13: compiler.err.prob.found.req: (compiler.misc.cyclic.inference: A) -TargetType21.java:31:9: compiler.err.ref.ambiguous: call, kindname.method, call(TargetType21.SAM1), TargetType21, kindname.method, call(TargetType21.SAM3), TargetType21 -4 errors +TargetType21.java:31:9: compiler.err.ref.ambiguous: call, kindname.method, call(TargetType21.SAM2), TargetType21, kindname.method, call(TargetType21.SAM3), TargetType21 +TargetType21.java:32:9: compiler.err.ref.ambiguous: call, kindname.method, call(TargetType21.SAM2), TargetType21, kindname.method, call(TargetType21.SAM3), TargetType21 +TargetType21.java:32:13: compiler.err.cant.apply.symbol: kindname.method, call, TargetType21.SAM2, @888, kindname.class, TargetType21, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.unexpected.ret.val))) +TargetType21.java:33:9: compiler.err.ref.ambiguous: call, kindname.method, call(TargetType21.SAM2), TargetType21, kindname.method, call(TargetType21.SAM3), TargetType21 +TargetType21.java:33:13: compiler.err.cant.apply.symbol: kindname.method, call, TargetType21.SAM2, @946, kindname.class, TargetType21, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.unexpected.ret.val))) +6 errors diff --git a/langtools/test/tools/javac/lambda/TargetType24.java b/langtools/test/tools/javac/lambda/TargetType24.java index b470a9169f9..5180cd5373f 100644 --- a/langtools/test/tools/javac/lambda/TargetType24.java +++ b/langtools/test/tools/javac/lambda/TargetType24.java @@ -29,11 +29,14 @@ class TargetType24 { } void test(Array as, final Array ac) { - final boolean b1 = as.forAll(s -> ac.forAll(c -> false)); //ok + final boolean b1 = as.forAll((String s) -> ac.forAll((Character c) -> false)); //ok + final boolean b2 = as.forAll(s -> ac.forAll(c -> false)); //ambiguous + final boolean b3 = as.forAll((String s) -> ac.forAll(c -> false)); //ambiguous + final boolean b4 = as.forAll(s -> ac.forAll((Character c) -> false)); //ambiguous final String s1 = as.forAll2(s -> ac.forAll2(c -> "")); //ok - final boolean b2 = as.forAll(s -> ac.forAll(c -> "" )); //fail + final boolean b5 = as.forAll(s -> ac.forAll(c -> "" )); //fail final String s2 = as.forAll2(s -> ac.forAll2(c -> false)); //fail - final boolean b3 = as.forAll((F)s -> ac.forAll((F)c -> "")); //fail + final boolean b6 = as.forAll((F)s -> ac.forAll((F)c -> "")); //fail final String s3 = as.forAll((FSub)s -> ac.forAll((FSub)c -> false)); //fail } } diff --git a/langtools/test/tools/javac/lambda/TargetType24.out b/langtools/test/tools/javac/lambda/TargetType24.out index 7554a6dd2c3..9542304a21b 100644 --- a/langtools/test/tools/javac/lambda/TargetType24.out +++ b/langtools/test/tools/javac/lambda/TargetType24.out @@ -1,5 +1,11 @@ -TargetType24.java:34:37: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.String, boolean) -TargetType24.java:35:45: compiler.err.cant.apply.symbol: kindname.method, forAll2, TargetType24.FSub, @945, kindname.class, TargetType24.Array, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.inconvertible.types: boolean, java.lang.String))) -TargetType24.java:36:101: compiler.err.prob.found.req: (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Boolean)) -TargetType24.java:37:104: compiler.err.prob.found.req: (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.inconvertible.types: boolean, java.lang.String)) -4 errors +TargetType24.java:33:30: compiler.err.ref.ambiguous: forAll, kindname.method, forAll(TargetType24.F), TargetType24.Array, kindname.method, forAll(TargetType24.FSub), TargetType24.Array +TargetType24.java:33:45: compiler.err.ref.ambiguous: forAll, kindname.method, forAll(TargetType24.F), TargetType24.Array, kindname.method, forAll(TargetType24.FSub), TargetType24.Array +TargetType24.java:34:54: compiler.err.ref.ambiguous: forAll, kindname.method, forAll(TargetType24.F), TargetType24.Array, kindname.method, forAll(TargetType24.FSub), TargetType24.Array +TargetType24.java:35:30: compiler.err.ref.ambiguous: forAll, kindname.method, forAll(TargetType24.F), TargetType24.Array, kindname.method, forAll(TargetType24.FSub), TargetType24.Array +TargetType24.java:37:30: compiler.err.ref.ambiguous: forAll, kindname.method, forAll(TargetType24.F), TargetType24.Array, kindname.method, forAll(TargetType24.FSub), TargetType24.Array +TargetType24.java:37:45: compiler.err.ref.ambiguous: forAll, kindname.method, forAll(TargetType24.F), TargetType24.Array, kindname.method, forAll(TargetType24.FSub), TargetType24.Array +TargetType24.java:37:52: compiler.err.cant.apply.symbol: kindname.method, forAll, TargetType24.F, @1149, kindname.class, TargetType24.Array, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Boolean))) +TargetType24.java:38:53: compiler.err.cant.apply.symbol: kindname.method, forAll2, TargetType24.FSub, @1221, kindname.class, TargetType24.Array, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.inconvertible.types: boolean, java.lang.String))) +TargetType24.java:39:101: compiler.err.prob.found.req: (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Boolean)) +TargetType24.java:40:104: compiler.err.prob.found.req: (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.inconvertible.types: boolean, java.lang.String)) +10 errors diff --git a/langtools/test/tools/javac/lambda/TargetType26.out b/langtools/test/tools/javac/lambda/TargetType26.out index 15cfc615f45..b90c658302d 100644 --- a/langtools/test/tools/javac/lambda/TargetType26.out +++ b/langtools/test/tools/javac/lambda/TargetType26.out @@ -1,2 +1,2 @@ -TargetType26.java:16:11: compiler.err.prob.found.req: (compiler.misc.cyclic.inference: Z) +TargetType26.java:16:11: compiler.err.prob.found.req: (compiler.misc.infer.no.conforming.assignment.exists: Z, (compiler.misc.not.a.functional.intf: java.lang.Object)) 1 error diff --git a/langtools/test/tools/javac/lambda/TargetType27.out b/langtools/test/tools/javac/lambda/TargetType27.out index bf388592025..61cb54ead88 100644 --- a/langtools/test/tools/javac/lambda/TargetType27.out +++ b/langtools/test/tools/javac/lambda/TargetType27.out @@ -1,2 +1,2 @@ -TargetType27.java:18:10: compiler.err.prob.found.req: (compiler.misc.cyclic.inference: R) +TargetType27.java:18:10: compiler.err.prob.found.req: (compiler.misc.infer.no.conforming.assignment.exists: A,R, (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.not.a.functional.intf: java.lang.Object))) 1 error diff --git a/langtools/test/tools/javac/lambda/TargetType39.out b/langtools/test/tools/javac/lambda/TargetType39.out index 36a61bce0e2..6229f690173 100644 --- a/langtools/test/tools/javac/lambda/TargetType39.out +++ b/langtools/test/tools/javac/lambda/TargetType39.out @@ -1,3 +1,3 @@ -TargetType39.java:19:13: compiler.err.prob.found.req: (compiler.misc.cyclic.inference: U) -TargetType39.java:20:13: compiler.err.prob.found.req: (compiler.misc.cyclic.inference: V) +TargetType39.java:19:13: compiler.err.prob.found.req: (compiler.misc.infer.no.conforming.assignment.exists: U,V, (compiler.misc.incompatible.type.in.conditional: (compiler.misc.inconvertible.types: TargetType39.SAM, TargetType39.SAM))) +TargetType39.java:20:13: compiler.err.prob.found.req: (compiler.misc.infer.no.conforming.assignment.exists: U,V, (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.incompatible.type.in.conditional: (compiler.misc.not.a.functional.intf: java.lang.Object)))) 2 errors diff --git a/langtools/test/tools/javac/lambda/TargetType43.out b/langtools/test/tools/javac/lambda/TargetType43.out index 666e67c8341..7d50949d9a0 100644 --- a/langtools/test/tools/javac/lambda/TargetType43.out +++ b/langtools/test/tools/javac/lambda/TargetType43.out @@ -1,4 +1,5 @@ TargetType43.java:13:20: compiler.err.prob.found.req: (compiler.misc.not.a.functional.intf: java.lang.Object) TargetType43.java:13:30: compiler.err.cant.resolve.location: kindname.class, NonExistentClass, , , (compiler.misc.location: kindname.class, TargetType43, null) +TargetType43.java:14:9: compiler.err.cant.apply.symbol: kindname.method, m, java.lang.Object, @359, kindname.class, TargetType43, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.not.a.functional.intf: java.lang.Object)) TargetType43.java:14:21: compiler.err.cant.resolve.location: kindname.class, NonExistentClass, , , (compiler.misc.location: kindname.class, TargetType43, null) -3 errors +4 errors diff --git a/langtools/test/tools/javac/lambda/TargetType66.java b/langtools/test/tools/javac/lambda/TargetType66.java index d9e85a0c87e..db704fd3a6f 100644 --- a/langtools/test/tools/javac/lambda/TargetType66.java +++ b/langtools/test/tools/javac/lambda/TargetType66.java @@ -17,8 +17,8 @@ class TargetType66 { void g(SAM2 s2) { } void test() { - g(x->{ String s = x; }); //g(SAM1) - g(x->{ Integer i = x; }); //g(SAM2) + g(x->{ String s = x; }); //ambiguous + g(x->{ Integer i = x; }); //ambiguous g(x->{ Object o = x; }); //ambiguous g(x->{ Character c = x; }); //error: inapplicable methods g(x->{ Character c = ""; }); //error: incompatible types diff --git a/langtools/test/tools/javac/lambda/TargetType66.out b/langtools/test/tools/javac/lambda/TargetType66.out index b5c828df27b..8dd2ad710bb 100644 --- a/langtools/test/tools/javac/lambda/TargetType66.out +++ b/langtools/test/tools/javac/lambda/TargetType66.out @@ -1,4 +1,9 @@ +TargetType66.java:20:9: compiler.err.ref.ambiguous: g, kindname.method, g(TargetType66.SAM1), TargetType66, kindname.method, g(TargetType66.SAM2), TargetType66 +TargetType66.java:21:9: compiler.err.ref.ambiguous: g, kindname.method, g(TargetType66.SAM1), TargetType66, kindname.method, g(TargetType66.SAM2), TargetType66 +TargetType66.java:21:28: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Integer) TargetType66.java:22:9: compiler.err.ref.ambiguous: g, kindname.method, g(TargetType66.SAM1), TargetType66, kindname.method, g(TargetType66.SAM2), TargetType66 -TargetType66.java:23:9: compiler.err.cant.apply.symbols: kindname.method, g, @578,{(compiler.misc.inapplicable.method: kindname.method, TargetType66, g(TargetType66.SAM1), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.bad.arg.types.in.lambda: java.lang.String, (compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Character))))),(compiler.misc.inapplicable.method: kindname.method, TargetType66, g(TargetType66.SAM2), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.bad.arg.types.in.lambda: java.lang.Integer, (compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.Integer, java.lang.Character)))))} +TargetType66.java:23:9: compiler.err.ref.ambiguous: g, kindname.method, g(TargetType66.SAM1), TargetType66, kindname.method, g(TargetType66.SAM2), TargetType66 +TargetType66.java:23:30: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Character) +TargetType66.java:24:9: compiler.err.ref.ambiguous: g, kindname.method, g(TargetType66.SAM1), TargetType66, kindname.method, g(TargetType66.SAM2), TargetType66 TargetType66.java:24:30: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Character) -3 errors +8 errors diff --git a/langtools/test/tools/javac/lambda/mostSpecific/StructuralMostSpecificTest.java b/langtools/test/tools/javac/lambda/mostSpecific/StructuralMostSpecificTest.java index dbd7d1366a0..0e1f144f418 100644 --- a/langtools/test/tools/javac/lambda/mostSpecific/StructuralMostSpecificTest.java +++ b/langtools/test/tools/javac/lambda/mostSpecific/StructuralMostSpecificTest.java @@ -197,7 +197,7 @@ public class StructuralMostSpecificTest "class Test {\n" + " void m(SAM1 s) { }\n" + " void m(SAM2 s) { }\n" + - " { m(x->{ #LR }); }\n" + + " { m((#A1 x)->{ #LR }); }\n" + "}\n"; String source; @@ -236,14 +236,17 @@ public class StructuralMostSpecificTest void check() { checkCount.incrementAndGet(); + if (ak1 != ak2) + return; + if (!lrk.compatibleWith(rt1) || !lrk.compatibleWith(rt2)) return; if (lrk.needsConversion(rt1) != lrk.needsConversion(rt2)) return; - boolean m1MoreSpecific = moreSpecific(rt1, rt2, ek1, ek2, ak1, ak2); - boolean m2MoreSpecific = moreSpecific(rt2, rt1, ek2, ek1, ak2, ak1); + boolean m1MoreSpecific = rt1.moreSpecificThan(rt2); + boolean m2MoreSpecific = rt2.moreSpecificThan(rt1); boolean ambiguous = (m1MoreSpecific == m2MoreSpecific); @@ -268,17 +271,6 @@ public class StructuralMostSpecificTest } } - boolean moreSpecific(RetTypeKind rk1, RetTypeKind rk2, ExceptionKind ek1, - ExceptionKind ek2, ArgTypeKind ak1, ArgTypeKind ak2) { - if (!rk1.moreSpecificThan(rk2)) - return false; - - if (ak1 != ak2) - return false; - - return true; - } - static class DiagnosticChecker implements javax.tools.DiagnosticListener { diff --git a/langtools/test/tools/javac/lambda/typeInference/InferenceTest5.java b/langtools/test/tools/javac/lambda/typeInference/InferenceTest5.java deleted file mode 100644 index 291068070a4..00000000000 --- a/langtools/test/tools/javac/lambda/typeInference/InferenceTest5.java +++ /dev/null @@ -1,122 +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. - * - * 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 8003280 - * @summary Add lambda tests - * This test is for overloaded methods, verify that the specific method is - selected when type inference occurs - * @compile InferenceTest5.java - * @run main InferenceTest5 - */ - -import java.util.List; -import java.io.File; - -public class InferenceTest5 { - - private static void assertTrue(boolean b) { - if(!b) - throw new AssertionError(); - } - - public static void main(String[] args) { - InferenceTest5 test = new InferenceTest5(); - int n = test.method1((a, b) -> {} ); - assertTrue(n == 1); - - n = test.method1(() -> null); - assertTrue(n == 2); - - n = test.method1(a -> null); - assertTrue(n == 3); - - n = test.method1(a -> {}); - assertTrue(n == 4); - - n = test.method1(() -> {}); - assertTrue(n == 5); - - n = test.method1((a, b) -> 0); - assertTrue(n == 6); - - n = test.method1((a, b) -> null); - assertTrue(n == 6); - - n = test.method1((a, b) -> null, (a, b) -> null); - assertTrue(n == 7); - } - - int method1(SAM1 s) { - return 1; - } - - int method1(SAM2 s) { - return 2; - } - - int method1(SAM3 s) { - return 3; - } - - int method1(SAM4 s) { - return 4; - } - - int method1(SAM5 s) { - return 5; - } - - int method1(SAM6 s) { - return 6; - } - - int method1(SAM6... s) { - return 7; - } - - static interface SAM1 { - void foo(List a, List b); - } - - static interface SAM2 { - List foo(); - } - - static interface SAM3 { - String foo(int a); - } - - static interface SAM4 { - void foo(List a); - } - - static interface SAM5 { - void foo(); - } - - static interface SAM6 { - V get(T t, T t2); - } -} diff --git a/langtools/test/tools/javac/lambda/typeInference/InferenceTest_neg5.java b/langtools/test/tools/javac/lambda/typeInference/InferenceTest6.java similarity index 76% rename from langtools/test/tools/javac/lambda/typeInference/InferenceTest_neg5.java rename to langtools/test/tools/javac/lambda/typeInference/InferenceTest6.java index d5f757e1379..b80a5903299 100644 --- a/langtools/test/tools/javac/lambda/typeInference/InferenceTest_neg5.java +++ b/langtools/test/tools/javac/lambda/typeInference/InferenceTest6.java @@ -1,16 +1,16 @@ /* * @test /nodynamiccopyright/ - * @bug 8003280 + * @bug 8003280 8016177 * @summary Add lambda tests * Missing cast to SAM type that causes type inference to not work. - * @compile/fail/ref=InferenceTest_neg5.out -XDrawDiagnostics InferenceTest_neg5.java + * @compile -XDrawDiagnostics InferenceTest6.java */ import java.util.*; -public class InferenceTest_neg5 { +public class InferenceTest6 { public static void main(String[] args) { - InferenceTest_neg5 test = new InferenceTest_neg5(); + InferenceTest6 test = new InferenceTest6(); test.method1(n -> {}); test.method1((SAM1)n -> {}); test.method1((SAM1)n -> {n++;}); diff --git a/langtools/test/tools/javac/lambda/typeInference/InferenceTest_neg1_2.out b/langtools/test/tools/javac/lambda/typeInference/InferenceTest_neg1_2.out index cf0d1d587bf..8dc00a893ad 100644 --- a/langtools/test/tools/javac/lambda/typeInference/InferenceTest_neg1_2.out +++ b/langtools/test/tools/javac/lambda/typeInference/InferenceTest_neg1_2.out @@ -1,4 +1,5 @@ InferenceTest_neg1_2.java:14:13: compiler.err.ref.ambiguous: method, kindname.method, method(InferenceTest_neg1_2.SAM4), InferenceTest_neg1_2, kindname.method, method(InferenceTest_neg1_2.SAM5), InferenceTest_neg1_2 -InferenceTest_neg1_2.java:15:13: compiler.err.ref.ambiguous: method, kindname.method, method(InferenceTest_neg1_2.SAM2), InferenceTest_neg1_2, kindname.method, method(InferenceTest_neg1_2.SAM4), InferenceTest_neg1_2 -InferenceTest_neg1_2.java:16:13: compiler.err.ref.ambiguous: method, kindname.method, method(InferenceTest_neg1_2.SAM3), InferenceTest_neg1_2, kindname.method, method(InferenceTest_neg1_2.SAM5), InferenceTest_neg1_2 -3 errors +InferenceTest_neg1_2.java:15:13: compiler.err.ref.ambiguous: method, kindname.method, method(InferenceTest_neg1_2.SAM4), InferenceTest_neg1_2, kindname.method, method(InferenceTest_neg1_2.SAM5), InferenceTest_neg1_2 +InferenceTest_neg1_2.java:16:13: compiler.err.ref.ambiguous: method, kindname.method, method(InferenceTest_neg1_2.SAM4), InferenceTest_neg1_2, kindname.method, method(InferenceTest_neg1_2.SAM5), InferenceTest_neg1_2 +InferenceTest_neg1_2.java:16:20: compiler.err.cant.apply.symbol: kindname.method, method, InferenceTest_neg1_2.SAM4, @597, kindname.class, InferenceTest_neg1_2, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.inconvertible.types: int, java.lang.String))) +4 errors diff --git a/langtools/test/tools/javac/lambda/typeInference/InferenceTest_neg5.out b/langtools/test/tools/javac/lambda/typeInference/InferenceTest_neg5.out deleted file mode 100644 index 7f647251ecf..00000000000 --- a/langtools/test/tools/javac/lambda/typeInference/InferenceTest_neg5.out +++ /dev/null @@ -1,2 +0,0 @@ -InferenceTest_neg5.java:14:21: compiler.err.prob.found.req: (compiler.misc.cyclic.inference: X) -1 error diff --git a/langtools/test/tools/javac/lambda/typeInference/combo/TypeInferenceComboTest.java b/langtools/test/tools/javac/lambda/typeInference/combo/TypeInferenceComboTest.java index 9399eb7b284..744a3ff5511 100644 --- a/langtools/test/tools/javac/lambda/typeInference/combo/TypeInferenceComboTest.java +++ b/langtools/test/tools/javac/lambda/typeInference/combo/TypeInferenceComboTest.java @@ -227,12 +227,7 @@ public class TypeInferenceComboTest } else if (lambdaBodyType != LambdaBody.RETURN_ARG) return false; - if ( genericDeclKind == GenericDeclKind.GENERIC_NOBOUND || - genericDeclKind == GenericDeclKind.GENERIC_BOUND ) { - if ( parameterType == TypeKind.GENERIC && - parameterKind == ParameterKind.IMPLICIT) //cyclic inference - return false; - } + return true; } From 46d7a993ada29543e07fd5952f257c7373f071f3 Mon Sep 17 00:00:00 2001 From: Vicente Romero Date: Mon, 2 Sep 2013 22:44:06 +0100 Subject: [PATCH 084/210] 8022162: Incorrect signature determination for certain inner class generics Reviewed-by: jjg --- .../com/sun/tools/javac/jvm/ClassReader.java | 21 +++-- ...atureDeterminationForInnerClassesTest.java | 89 +++++++++++++++++++ 2 files changed, 104 insertions(+), 6 deletions(-) create mode 100644 langtools/test/tools/javac/T8022162/IncorrectSignatureDeterminationForInnerClassesTest.java diff --git a/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java b/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java index 1717e50194f..3fc93921c8e 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java +++ b/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java @@ -727,12 +727,14 @@ public class ClassReader implements Completer { ClassSymbol t = enterClass(names.fromUtf(signatureBuffer, startSbp, sbp - startSbp)); - if (outer == Type.noType) - outer = t.erasure(types); - else - outer = new ClassType(outer, List.nil(), t); - sbp = startSbp; - return outer; + + try { + return (outer == Type.noType) ? + t.erasure(types) : + new ClassType(outer, List.nil(), t); + } finally { + sbp = startSbp; + } } case '<': // generic arguments @@ -797,6 +799,13 @@ public class ClassReader implements Completer { continue; case '.': + //we have seen an enclosing non-generic class + if (outer != Type.noType) { + t = enterClass(names.fromUtf(signatureBuffer, + startSbp, + sbp - startSbp)); + outer = new ClassType(outer, List.nil(), t); + } signatureBuffer[sbp++] = (byte)'$'; continue; case '/': diff --git a/langtools/test/tools/javac/T8022162/IncorrectSignatureDeterminationForInnerClassesTest.java b/langtools/test/tools/javac/T8022162/IncorrectSignatureDeterminationForInnerClassesTest.java new file mode 100644 index 00000000000..4e9eaf2fb8f --- /dev/null +++ b/langtools/test/tools/javac/T8022162/IncorrectSignatureDeterminationForInnerClassesTest.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2013, 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 8022162 + * @summary Incorrect signature determination for certain inner class generics + * @library /tools/javac/lib + * @build ToolBox + * @run main IncorrectSignatureDeterminationForInnerClassesTest + */ + +import java.nio.file.Files; +import java.nio.file.Paths; + +public class IncorrectSignatureDeterminationForInnerClassesTest { + + private static final String DSrc = + "package p1;\n" + + + "public class D {\n" + + "}\n" + + + "abstract class Q {\n" + + " protected void m(M.E e) {}\n" + + + " public class M extends D {\n" + + " public class E {}\n" + + " }\n" + + "}"; + + private static final String HSrc = + "package p1;\n" + + + "public class H {\n" + + " static class EQ extends Q {\n" + + " private void m2(M.E item) {\n" + + " m(item);\n" + + " }\n" + + " }\n" + + "}"; + + public static void main(String args[]) throws Exception { + new IncorrectSignatureDeterminationForInnerClassesTest().run(); + } + + void run() throws Exception { + compile(); + } + + void compile() throws Exception { + Files.createDirectory(Paths.get("classes")); + + ToolBox.JavaToolArgs javacParams = + new ToolBox.JavaToolArgs() + .appendArgs("-d", "classes") + .setSources(DSrc); + + ToolBox.javac(javacParams); + + // compile class H against the class files for classes D and Q + javacParams = + new ToolBox.JavaToolArgs() + .appendArgs("-d", "classes", "-cp", "classes") + .setSources(HSrc); + ToolBox.javac(javacParams); + } + +} From bfb3ea37f74b0832c2cfc282342e4b42822ef587 Mon Sep 17 00:00:00 2001 From: Sean Coffey Date: Tue, 3 Sep 2013 22:35:05 +0100 Subject: [PATCH 085/210] 8017195: Introduce option to setKeepAlive parameter on CORBA sockets Reviewed-by: chegar, msheppar --- .../transport/DefaultSocketFactoryImpl.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/corba/src/share/classes/com/sun/corba/se/impl/transport/DefaultSocketFactoryImpl.java b/corba/src/share/classes/com/sun/corba/se/impl/transport/DefaultSocketFactoryImpl.java index fc1ffc70197..63578b9c3d1 100644 --- a/corba/src/share/classes/com/sun/corba/se/impl/transport/DefaultSocketFactoryImpl.java +++ b/corba/src/share/classes/com/sun/corba/se/impl/transport/DefaultSocketFactoryImpl.java @@ -32,6 +32,7 @@ import java.net.SocketException; import java.net.ServerSocket; import java.nio.channels.SocketChannel; import java.nio.channels.ServerSocketChannel; +import java.security.PrivilegedAction; import com.sun.corba.se.pept.transport.Acceptor; @@ -44,6 +45,22 @@ public class DefaultSocketFactoryImpl implements ORBSocketFactory { private ORB orb; + private static final boolean keepAlive; + + static { + keepAlive = java.security.AccessController.doPrivileged( + new PrivilegedAction() { + @Override + public Boolean run () { + String value = + System.getProperty("com.sun.CORBA.transport.enableTcpKeepAlive"); + if (value != null) + return new Boolean(!"false".equalsIgnoreCase(value)); + + return Boolean.FALSE; + } + }); + } public void setORB(ORB orb) { @@ -85,6 +102,9 @@ public class DefaultSocketFactoryImpl // Disable Nagle's algorithm (i.e., always send immediately). socket.setTcpNoDelay(true); + if (keepAlive) + socket.setKeepAlive(true); + return socket; } @@ -95,6 +115,8 @@ public class DefaultSocketFactoryImpl { // Disable Nagle's algorithm (i.e., always send immediately). socket.setTcpNoDelay(true); + if (keepAlive) + socket.setKeepAlive(true); } } From 0e90cf9ba0ebff017b843a20aced1b5d193873b5 Mon Sep 17 00:00:00 2001 From: Mike Duigou Date: Tue, 3 Sep 2013 15:23:16 -0700 Subject: [PATCH 086/210] 8024200: handle hg wrapper with space after #! Reviewed-by: tbell --- common/bin/hgforest.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/bin/hgforest.sh b/common/bin/hgforest.sh index 12cf0234b17..1dc50390b42 100644 --- a/common/bin/hgforest.sh +++ b/common/bin/hgforest.sh @@ -47,7 +47,7 @@ python="" bpython="" if [ "#!" = "$has_hash_bang" ] ; then - python="`head -n 1 ${whichhg} | cut -b 3-`" + python="`head -n 1 ${whichhg} | cut -b 3- | sed -e 's/^[ \t]*//;s/[ \t]*$//'`" bpython="`basename "$python"`" fi From 06caeea3d6ec543161ee0f2e19f71e19aa62fdfb Mon Sep 17 00:00:00 2001 From: Maurizio Cimadamore Date: Tue, 3 Sep 2013 23:31:33 +0100 Subject: [PATCH 087/210] 8023389: Javac fails to infer type for lambda used with intersection type and wildcards Reviewed-by: jjg, vromero --- .../com/sun/tools/javac/comp/Attr.java | 29 +++++++----- .../tools/javac/lambda/8023389/T8023389.java | 46 +++++++++++++++++++ 2 files changed, 64 insertions(+), 11 deletions(-) create mode 100644 langtools/test/tools/javac/lambda/8023389/T8023389.java diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java b/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java index ad0d5003144..4c49601e2a4 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java @@ -2319,30 +2319,37 @@ public class Attr extends JCTree.Visitor { boolean needsRecovery = resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.CHECK; try { - Type target = pt(); + Type currentTarget = pt(); List explicitParamTypes = null; if (that.paramKind == JCLambda.ParameterKind.EXPLICIT) { //attribute lambda parameters attribStats(that.params, localEnv); explicitParamTypes = TreeInfo.types(that.params); - target = infer.instantiateFunctionalInterface(that, target, explicitParamTypes, resultInfo.checkContext); } Type lambdaType; if (pt() != Type.recoveryType) { - target = targetChecker.visit(target, that); - lambdaType = types.findDescriptorType(target); + /* We need to adjust the target. If the target is an + * intersection type, for example: SAM & I1 & I2 ... + * the target will be updated to SAM + */ + currentTarget = targetChecker.visit(currentTarget, that); + if (explicitParamTypes != null) { + currentTarget = infer.instantiateFunctionalInterface(that, + currentTarget, explicitParamTypes, resultInfo.checkContext); + } + lambdaType = types.findDescriptorType(currentTarget); } else { - target = Type.recoveryType; + currentTarget = Type.recoveryType; lambdaType = fallbackDescriptorType(that); } - setFunctionalInfo(localEnv, that, pt(), lambdaType, target, resultInfo.checkContext); + setFunctionalInfo(localEnv, that, pt(), lambdaType, currentTarget, resultInfo.checkContext); if (lambdaType.hasTag(FORALL)) { //lambda expression target desc cannot be a generic method resultInfo.checkContext.report(that, diags.fragment("invalid.generic.lambda.target", - lambdaType, kindName(target.tsym), target.tsym)); + lambdaType, kindName(currentTarget.tsym), currentTarget.tsym)); result = that.type = types.createErrorType(pt()); return; } @@ -2376,7 +2383,7 @@ public class Attr extends JCTree.Visitor { if (arityMismatch) { resultInfo.checkContext.report(that, diags.fragment("incompatible.arg.types.in.lambda")); - result = that.type = types.createErrorType(target); + result = that.type = types.createErrorType(currentTarget); return; } } @@ -2403,7 +2410,7 @@ public class Attr extends JCTree.Visitor { attribStats(body.stats, localEnv); } - result = check(that, target, VAL, resultInfo); + result = check(that, currentTarget, VAL, resultInfo); boolean isSpeculativeRound = resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.SPECULATIVE; @@ -2414,9 +2421,9 @@ public class Attr extends JCTree.Visitor { checkLambdaCompatible(that, lambdaType, resultInfo.checkContext, isSpeculativeRound); if (!isSpeculativeRound) { - checkAccessibleTypes(that, localEnv, resultInfo.checkContext.inferenceContext(), lambdaType, target); + checkAccessibleTypes(that, localEnv, resultInfo.checkContext.inferenceContext(), lambdaType, currentTarget); } - result = check(that, target, VAL, resultInfo); + result = check(that, currentTarget, VAL, resultInfo); } catch (Types.FunctionDescriptorLookupError ex) { JCDiagnostic cause = ex.getDiagnostic(); resultInfo.checkContext.report(that, cause); diff --git a/langtools/test/tools/javac/lambda/8023389/T8023389.java b/langtools/test/tools/javac/lambda/8023389/T8023389.java new file mode 100644 index 00000000000..25eb0c8a066 --- /dev/null +++ b/langtools/test/tools/javac/lambda/8023389/T8023389.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2013, 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 8023389 + * @summary Javac fails to infer type for lambda used with intersection type and wildcards + * @compile T8023389.java + */ +public class T8023389 { + + static class U1 {} + static class X1 extends U1 {} + + interface I { } + + interface SAM { + void m(T t); + } + + /* Strictly speaking only the second of the following declarations provokes the bug. + * But the first line is also a useful test case. + */ + SAM sam1 = (SAM) (X1 x) -> { }; + SAM sam2 = (SAM & I) (X1 x) -> { }; +} From cab6b226ffd147158a7528c36f92a34ed10e685c Mon Sep 17 00:00:00 2001 From: Vicente Romero Date: Tue, 3 Sep 2013 23:41:37 +0100 Subject: [PATCH 088/210] 8023545: Misleading error message when using diamond operator with private constructor Reviewed-by: jjg --- .../com/sun/tools/javac/comp/Resolve.java | 36 ++++++++++--------- ...ingErrorMsgDiamondPlusPrivateCtorTest.java | 16 +++++++++ ...dingErrorMsgDiamondPlusPrivateCtorTest.out | 2 ++ 3 files changed, 38 insertions(+), 16 deletions(-) create mode 100644 langtools/test/tools/javac/T8023545/MisleadingErrorMsgDiamondPlusPrivateCtorTest.java create mode 100644 langtools/test/tools/javac/T8023545/MisleadingErrorMsgDiamondPlusPrivateCtorTest.out diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java b/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java index 03f50401171..f89bfed0161 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java @@ -2546,22 +2546,26 @@ public class Resolve { @Override Symbol access(Env env, DiagnosticPosition pos, Symbol location, Symbol sym) { if (sym.kind >= AMBIGUOUS) { - final JCDiagnostic details = sym.kind == WRONG_MTH ? - ((InapplicableSymbolError)sym).errCandidate().snd : - null; - sym = new InapplicableSymbolError(sym.kind, "diamondError", currentResolutionContext) { - @Override - JCDiagnostic getDiagnostic(DiagnosticType dkind, DiagnosticPosition pos, - Symbol location, Type site, Name name, List argtypes, List typeargtypes) { - String key = details == null ? - "cant.apply.diamond" : - "cant.apply.diamond.1"; - return diags.create(dkind, log.currentSource(), pos, key, - diags.fragment("diamond", site.tsym), details); - } - }; - sym = accessMethod(sym, pos, site, names.init, true, argtypes, typeargtypes); - env.info.pendingResolutionPhase = currentResolutionContext.step; + if (sym.kind == HIDDEN) { + sym = super.access(env, pos, location, sym); + } else { + final JCDiagnostic details = sym.kind == WRONG_MTH ? + ((InapplicableSymbolError)sym).errCandidate().snd : + null; + sym = new InapplicableSymbolError(sym.kind, "diamondError", currentResolutionContext) { + @Override + JCDiagnostic getDiagnostic(DiagnosticType dkind, DiagnosticPosition pos, + Symbol location, Type site, Name name, List argtypes, List typeargtypes) { + String key = details == null ? + "cant.apply.diamond" : + "cant.apply.diamond.1"; + return diags.create(dkind, log.currentSource(), pos, key, + diags.fragment("diamond", site.tsym), details); + } + }; + sym = accessMethod(sym, pos, site, names.init, true, argtypes, typeargtypes); + env.info.pendingResolutionPhase = currentResolutionContext.step; + } } return sym; }}); diff --git a/langtools/test/tools/javac/T8023545/MisleadingErrorMsgDiamondPlusPrivateCtorTest.java b/langtools/test/tools/javac/T8023545/MisleadingErrorMsgDiamondPlusPrivateCtorTest.java new file mode 100644 index 00000000000..75959e29e22 --- /dev/null +++ b/langtools/test/tools/javac/T8023545/MisleadingErrorMsgDiamondPlusPrivateCtorTest.java @@ -0,0 +1,16 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8023545 + * @summary Misleading error message when using diamond operator with private constructor + * @compile/fail/ref=MisleadingErrorMsgDiamondPlusPrivateCtorTest.out -XDrawDiagnostics MisleadingErrorMsgDiamondPlusPrivateCtorTest.java + */ + +public class MisleadingErrorMsgDiamondPlusPrivateCtorTest { + public void foo() { + MyClass foo = new MyClass<>(); + } +} + +class MyClass { + private MyClass() {} +} diff --git a/langtools/test/tools/javac/T8023545/MisleadingErrorMsgDiamondPlusPrivateCtorTest.out b/langtools/test/tools/javac/T8023545/MisleadingErrorMsgDiamondPlusPrivateCtorTest.out new file mode 100644 index 00000000000..488e6a1041c --- /dev/null +++ b/langtools/test/tools/javac/T8023545/MisleadingErrorMsgDiamondPlusPrivateCtorTest.out @@ -0,0 +1,2 @@ +MisleadingErrorMsgDiamondPlusPrivateCtorTest.java:10:31: compiler.err.report.access: MyClass(), private, MyClass +1 error From 4cc7a55aab23a17d3bc0b6dc994593b07db64ae7 Mon Sep 17 00:00:00 2001 From: Maurizio Cimadamore Date: Wed, 4 Sep 2013 00:01:05 +0100 Subject: [PATCH 089/210] 8023549: Compiler emitting spurious errors when constructor reference type is inferred and explicit type arguments are supplied Reviewed-by: jjg, vromero --- .../com/sun/tools/javac/comp/Attr.java | 7 ++++ .../tools/javac/resources/compiler.properties | 4 +++ .../examples/MrefInferAndExplicitParams.java | 35 +++++++++++++++++++ .../tools/javac/lambda/8023549/T8023549.java | 27 ++++++++++++++ .../tools/javac/lambda/8023549/T8023549.out | 5 +++ 5 files changed, 78 insertions(+) create mode 100644 langtools/test/tools/javac/diags/examples/MrefInferAndExplicitParams.java create mode 100644 langtools/test/tools/javac/lambda/8023549/T8023549.java create mode 100644 langtools/test/tools/javac/lambda/8023549/T8023549.out diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java b/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java index 4c49601e2a4..434f0b3815b 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java @@ -2647,6 +2647,13 @@ public class Attr extends JCTree.Visitor { if (that.getMode() == JCMemberReference.ReferenceMode.NEW) { exprType = chk.checkConstructorRefType(that.expr, exprType); + if (!exprType.isErroneous() && + exprType.isRaw() && + that.typeargs != null) { + log.error(that.expr.pos(), "invalid.mref", Kinds.kindName(that.getMode()), + diags.fragment("mref.infer.and.explicit.params")); + exprType = types.createErrorType(exprType); + } } if (exprType.isErroneous()) { diff --git a/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties b/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties index 4ca8a90c0c0..a87abc35b70 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties +++ b/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties @@ -1927,6 +1927,10 @@ compiler.misc.diamond.non.generic=\ compiler.misc.diamond.and.explicit.params=\ cannot use ''<>'' with explicit type parameters for constructor +# 0: unused +compiler.misc.mref.infer.and.explicit.params=\ + cannot use raw constructor reference with explicit type parameters for constructor + # 0: type, 1: list of type compiler.misc.explicit.param.do.not.conform.to.bounds=\ explicit type argument {0} does not conform to declared bound(s) {1} diff --git a/langtools/test/tools/javac/diags/examples/MrefInferAndExplicitParams.java b/langtools/test/tools/javac/diags/examples/MrefInferAndExplicitParams.java new file mode 100644 index 00000000000..ce24f82e60e --- /dev/null +++ b/langtools/test/tools/javac/diags/examples/MrefInferAndExplicitParams.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2013, 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. + */ + +// key: compiler.err.invalid.mref +// key: compiler.misc.mref.infer.and.explicit.params + +public class MrefInferAndExplicitParams { + static class Foo {} + + interface Supplier { + X make(); + } + + Supplier> sfs = Foo::new; +} diff --git a/langtools/test/tools/javac/lambda/8023549/T8023549.java b/langtools/test/tools/javac/lambda/8023549/T8023549.java new file mode 100644 index 00000000000..efee943b8d6 --- /dev/null +++ b/langtools/test/tools/javac/lambda/8023549/T8023549.java @@ -0,0 +1,27 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8023549 + * @summary Compiler emitting spurious errors when constructor reference type is inferred and explicit type arguments are supplied + * @compile/fail/ref=T8023549.out -XDrawDiagnostics T8023549.java + */ + +public class T8023549 { + static class Foo { } + + interface Supplier { + X make(); + } + + interface ExtSupplier extends Supplier { } + + void m1(Supplier> sfs) { } + + void m2(Supplier> sfs) { } + void m2(ExtSupplier> sfs) { } + + void test() { + Supplier> sfs = Foo::new; + m1(Foo::new); + m2(Foo::new); + } +} diff --git a/langtools/test/tools/javac/lambda/8023549/T8023549.out b/langtools/test/tools/javac/lambda/8023549/T8023549.out new file mode 100644 index 00000000000..d25a412378e --- /dev/null +++ b/langtools/test/tools/javac/lambda/8023549/T8023549.out @@ -0,0 +1,5 @@ +T8023549.java:23:37: compiler.err.invalid.mref: kindname.constructor, (compiler.misc.mref.infer.and.explicit.params) +T8023549.java:24:12: compiler.err.invalid.mref: kindname.constructor, (compiler.misc.mref.infer.and.explicit.params) +T8023549.java:25:9: compiler.err.ref.ambiguous: m2, kindname.method, m2(T8023549.Supplier>), T8023549, kindname.method, m2(T8023549.ExtSupplier>), T8023549 +T8023549.java:25:12: compiler.err.invalid.mref: kindname.constructor, (compiler.misc.mref.infer.and.explicit.params) +4 errors From 256894796fce919d11b720fb5c730f1afd78eecc Mon Sep 17 00:00:00 2001 From: Andrew Brygin Date: Wed, 4 Sep 2013 12:10:07 +0400 Subject: [PATCH 090/210] 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly Reviewed-by: prr, vadim --- jdk/make/sun/cmm/lcms/mapfile-vers | 5 +- jdk/makefiles/mapfiles/liblcms/mapfile-vers | 5 +- .../classes/java/awt/color/ICC_Profile.java | 73 ++--- .../java/awt/color/ICC_ProfileGray.java | 6 +- .../java/awt/color/ICC_ProfileRGB.java | 6 +- .../classes/sun/java2d/cmm/CMSManager.java | 44 +-- .../share/classes/sun/java2d/cmm/PCMM.java | 14 +- .../share/classes/sun/java2d/cmm/Profile.java | 43 +++ .../classes/sun/java2d/cmm/lcms/LCMS.java | 208 ++++++------ .../sun/java2d/cmm/lcms/LCMSProfile.java | 109 +++++++ .../sun/java2d/cmm/lcms/LCMSTransform.java | 14 +- .../share/native/sun/java2d/cmm/lcms/LCMS.c | 299 +++++++++++------- .../cmm/ProfileOp/ReadWriteProfileTest.java | 34 +- 13 files changed, 551 insertions(+), 309 deletions(-) create mode 100644 jdk/src/share/classes/sun/java2d/cmm/Profile.java create mode 100644 jdk/src/share/classes/sun/java2d/cmm/lcms/LCMSProfile.java diff --git a/jdk/make/sun/cmm/lcms/mapfile-vers b/jdk/make/sun/cmm/lcms/mapfile-vers index 3d9074f746d..949ff9b5787 100644 --- a/jdk/make/sun/cmm/lcms/mapfile-vers +++ b/jdk/make/sun/cmm/lcms/mapfile-vers @@ -28,9 +28,8 @@ SUNWprivate_1.1 { global: Java_sun_java2d_cmm_lcms_LCMS_loadProfileNative; - Java_sun_java2d_cmm_lcms_LCMS_freeProfileNative; - Java_sun_java2d_cmm_lcms_LCMS_getProfileSize; - Java_sun_java2d_cmm_lcms_LCMS_getProfileData; + Java_sun_java2d_cmm_lcms_LCMS_getProfileSizeNative; + Java_sun_java2d_cmm_lcms_LCMS_getProfileDataNative; Java_sun_java2d_cmm_lcms_LCMS_getTagNative; Java_sun_java2d_cmm_lcms_LCMS_setTagDataNative; Java_sun_java2d_cmm_lcms_LCMS_colorConvert; diff --git a/jdk/makefiles/mapfiles/liblcms/mapfile-vers b/jdk/makefiles/mapfiles/liblcms/mapfile-vers index 024511423d3..2e63d68e5d4 100644 --- a/jdk/makefiles/mapfiles/liblcms/mapfile-vers +++ b/jdk/makefiles/mapfiles/liblcms/mapfile-vers @@ -28,9 +28,8 @@ SUNWprivate_1.1 { global: Java_sun_java2d_cmm_lcms_LCMS_loadProfileNative; - Java_sun_java2d_cmm_lcms_LCMS_freeProfileNative; - Java_sun_java2d_cmm_lcms_LCMS_getProfileSize; - Java_sun_java2d_cmm_lcms_LCMS_getProfileData; + Java_sun_java2d_cmm_lcms_LCMS_getProfileSizeNative; + Java_sun_java2d_cmm_lcms_LCMS_getProfileDataNative; Java_sun_java2d_cmm_lcms_LCMS_getTagNative; Java_sun_java2d_cmm_lcms_LCMS_setTagDataNative; Java_sun_java2d_cmm_lcms_LCMS_colorConvert; diff --git a/jdk/src/share/classes/java/awt/color/ICC_Profile.java b/jdk/src/share/classes/java/awt/color/ICC_Profile.java index c1534249f39..7e44947477d 100644 --- a/jdk/src/share/classes/java/awt/color/ICC_Profile.java +++ b/jdk/src/share/classes/java/awt/color/ICC_Profile.java @@ -37,6 +37,7 @@ package java.awt.color; import sun.java2d.cmm.PCMM; import sun.java2d.cmm.CMSManager; +import sun.java2d.cmm.Profile; import sun.java2d.cmm.ProfileDataVerifier; import sun.java2d.cmm.ProfileDeferralMgr; import sun.java2d.cmm.ProfileDeferralInfo; @@ -94,7 +95,7 @@ public class ICC_Profile implements Serializable { private static final long serialVersionUID = -3938515861990936766L; - transient long ID; + private transient Profile cmmProfile; private transient ProfileDeferralInfo deferralInfo; private transient ProfileActivator profileActivator; @@ -727,8 +728,8 @@ public class ICC_Profile implements Serializable { /** * Constructs an ICC_Profile object with a given ID. */ - ICC_Profile(long ID) { - this.ID = ID; + ICC_Profile(Profile p) { + this.cmmProfile = p; } @@ -751,8 +752,8 @@ public class ICC_Profile implements Serializable { * Frees the resources associated with an ICC_Profile object. */ protected void finalize () { - if (ID != 0) { - CMSManager.getModule().freeProfile(ID); + if (cmmProfile != null) { + CMSManager.getModule().freeProfile(cmmProfile); } else if (profileActivator != null) { ProfileDeferralMgr.unregisterDeferral(profileActivator); } @@ -770,7 +771,7 @@ public class ICC_Profile implements Serializable { public static ICC_Profile getInstance(byte[] data) { ICC_Profile thisProfile; - long theID; + Profile p = null; if (ProfileDeferralMgr.deferring) { ProfileDeferralMgr.activateProfiles(); @@ -779,32 +780,32 @@ public class ICC_Profile implements Serializable { ProfileDataVerifier.verify(data); try { - theID = CMSManager.getModule().loadProfile(data); + p = CMSManager.getModule().loadProfile(data); } catch (CMMException c) { throw new IllegalArgumentException("Invalid ICC Profile Data"); } try { - if ((getColorSpaceType (theID) == ColorSpace.TYPE_GRAY) && - (getData (theID, icSigMediaWhitePointTag) != null) && - (getData (theID, icSigGrayTRCTag) != null)) { - thisProfile = new ICC_ProfileGray (theID); + if ((getColorSpaceType (p) == ColorSpace.TYPE_GRAY) && + (getData (p, icSigMediaWhitePointTag) != null) && + (getData (p, icSigGrayTRCTag) != null)) { + thisProfile = new ICC_ProfileGray (p); } - else if ((getColorSpaceType (theID) == ColorSpace.TYPE_RGB) && - (getData (theID, icSigMediaWhitePointTag) != null) && - (getData (theID, icSigRedColorantTag) != null) && - (getData (theID, icSigGreenColorantTag) != null) && - (getData (theID, icSigBlueColorantTag) != null) && - (getData (theID, icSigRedTRCTag) != null) && - (getData (theID, icSigGreenTRCTag) != null) && - (getData (theID, icSigBlueTRCTag) != null)) { - thisProfile = new ICC_ProfileRGB (theID); + else if ((getColorSpaceType (p) == ColorSpace.TYPE_RGB) && + (getData (p, icSigMediaWhitePointTag) != null) && + (getData (p, icSigRedColorantTag) != null) && + (getData (p, icSigGreenColorantTag) != null) && + (getData (p, icSigBlueColorantTag) != null) && + (getData (p, icSigRedTRCTag) != null) && + (getData (p, icSigGreenTRCTag) != null) && + (getData (p, icSigBlueTRCTag) != null)) { + thisProfile = new ICC_ProfileRGB (p); } else { - thisProfile = new ICC_Profile (theID); + thisProfile = new ICC_Profile (p); } } catch (CMMException c) { - thisProfile = new ICC_Profile (theID); + thisProfile = new ICC_Profile (p); } return thisProfile; } @@ -1119,7 +1120,7 @@ public class ICC_Profile implements Serializable { fileName); } try { - ID = CMSManager.getModule().loadProfile(profileData); + cmmProfile = CMSManager.getModule().loadProfile(profileData); } catch (CMMException c) { ProfileDataException pde = new ProfileDataException("Invalid ICC Profile Data" + fileName); @@ -1229,14 +1230,14 @@ public class ICC_Profile implements Serializable { causing a deferred profile to be loaded */ } - return getColorSpaceType(ID); + return getColorSpaceType(cmmProfile); } - static int getColorSpaceType(long profileID) { + static int getColorSpaceType(Profile p) { byte[] theHeader; int theColorSpaceSig, theColorSpace; - theHeader = getData(profileID, icSigHead); + theHeader = getData(p, icSigHead); theColorSpaceSig = intFromBigEndian(theHeader, icHdrColorSpace); theColorSpace = iccCStoJCS (theColorSpaceSig); return theColorSpace; @@ -1258,15 +1259,15 @@ public class ICC_Profile implements Serializable { if (ProfileDeferralMgr.deferring) { ProfileDeferralMgr.activateProfiles(); } - return getPCSType(ID); + return getPCSType(cmmProfile); } - static int getPCSType(long profileID) { + static int getPCSType(Profile p) { byte[] theHeader; int thePCSSig, thePCS; - theHeader = getData(profileID, icSigHead); + theHeader = getData(p, icSigHead); thePCSSig = intFromBigEndian(theHeader, icHdrPcs); thePCS = iccCStoJCS(thePCSSig); return thePCS; @@ -1326,12 +1327,12 @@ public class ICC_Profile implements Serializable { PCMM mdl = CMSManager.getModule(); /* get the number of bytes needed for this profile */ - profileSize = mdl.getProfileSize(ID); + profileSize = mdl.getProfileSize(cmmProfile); profileData = new byte [profileSize]; /* get the data for the profile */ - mdl.getProfileData(ID, profileData); + mdl.getProfileData(cmmProfile, profileData); return profileData; } @@ -1358,11 +1359,11 @@ public class ICC_Profile implements Serializable { ProfileDeferralMgr.activateProfiles(); } - return getData(ID, tagSignature); + return getData(cmmProfile, tagSignature); } - static byte[] getData(long profileID, int tagSignature) { + static byte[] getData(Profile p, int tagSignature) { int tagSize; byte[] tagData; @@ -1370,12 +1371,12 @@ public class ICC_Profile implements Serializable { PCMM mdl = CMSManager.getModule(); /* get the number of bytes needed for this tag */ - tagSize = mdl.getTagSize(profileID, tagSignature); + tagSize = mdl.getTagSize(p, tagSignature); tagData = new byte[tagSize]; /* get an array for the tag */ /* get the tag's data */ - mdl.getTagData(profileID, tagSignature, tagData); + mdl.getTagData(p, tagSignature, tagData); } catch(CMMException c) { tagData = null; } @@ -1406,7 +1407,7 @@ public class ICC_Profile implements Serializable { ProfileDeferralMgr.activateProfiles(); } - CMSManager.getModule().setTagData(ID, tagSignature, tagData); + CMSManager.getModule().setTagData(cmmProfile, tagSignature, tagData); } /** diff --git a/jdk/src/share/classes/java/awt/color/ICC_ProfileGray.java b/jdk/src/share/classes/java/awt/color/ICC_ProfileGray.java index d9042266663..a868a6f50fc 100644 --- a/jdk/src/share/classes/java/awt/color/ICC_ProfileGray.java +++ b/jdk/src/share/classes/java/awt/color/ICC_ProfileGray.java @@ -35,7 +35,7 @@ package java.awt.color; -import java.awt.image.LookupTable; +import sun.java2d.cmm.Profile; import sun.java2d.cmm.ProfileDeferralInfo; /** @@ -76,8 +76,8 @@ extends ICC_Profile { /** * Constructs a new ICC_ProfileGray from a CMM ID. */ - ICC_ProfileGray(long ID) { - super(ID); + ICC_ProfileGray(Profile p) { + super(p); } /** diff --git a/jdk/src/share/classes/java/awt/color/ICC_ProfileRGB.java b/jdk/src/share/classes/java/awt/color/ICC_ProfileRGB.java index b0bad4d9a91..dcf65828650 100644 --- a/jdk/src/share/classes/java/awt/color/ICC_ProfileRGB.java +++ b/jdk/src/share/classes/java/awt/color/ICC_ProfileRGB.java @@ -35,7 +35,7 @@ package java.awt.color; -import java.awt.image.LookupTable; +import sun.java2d.cmm.Profile; import sun.java2d.cmm.ProfileDeferralInfo; /** @@ -114,8 +114,8 @@ extends ICC_Profile { * @param ID The CMM ID for the profile. * */ - ICC_ProfileRGB(long ID) { - super(ID); + ICC_ProfileRGB(Profile p) { + super(p); } /** diff --git a/jdk/src/share/classes/sun/java2d/cmm/CMSManager.java b/jdk/src/share/classes/sun/java2d/cmm/CMSManager.java index 1e24504b45a..fcaede43a94 100644 --- a/jdk/src/share/classes/sun/java2d/cmm/CMSManager.java +++ b/jdk/src/share/classes/sun/java2d/cmm/CMSManager.java @@ -104,53 +104,53 @@ public class CMSManager { cName = tcmm.getClass().getName(); } - public long loadProfile(byte[] data) { + public Profile loadProfile(byte[] data) { System.err.print(cName + ".loadProfile"); - long profileID = tcmm.loadProfile(data); - System.err.printf("(ID=%x)\n", profileID); - return profileID; + Profile p = tcmm.loadProfile(data); + System.err.printf("(ID=%s)\n", p.toString()); + return p; } - public void freeProfile(long profileID) { - System.err.printf(cName + ".freeProfile(ID=%x)\n", profileID); - tcmm.freeProfile(profileID); + public void freeProfile(Profile p) { + System.err.printf(cName + ".freeProfile(ID=%s)\n", p.toString()); + tcmm.freeProfile(p); } - public int getProfileSize(long profileID) { - System.err.print(cName + ".getProfileSize(ID=" + profileID + ")"); - int size = tcmm.getProfileSize(profileID); + public int getProfileSize(Profile p) { + System.err.print(cName + ".getProfileSize(ID=" + p + ")"); + int size = tcmm.getProfileSize(p); System.err.println("=" + size); return size; } - public void getProfileData(long profileID, byte[] data) { - System.err.print(cName + ".getProfileData(ID=" + profileID + ") "); + public void getProfileData(Profile p, byte[] data) { + System.err.print(cName + ".getProfileData(ID=" + p + ") "); System.err.println("requested " + data.length + " byte(s)"); - tcmm.getProfileData(profileID, data); + tcmm.getProfileData(p, data); } - public int getTagSize(long profileID, int tagSignature) { + public int getTagSize(Profile p, int tagSignature) { System.err.printf(cName + ".getTagSize(ID=%x, TagSig=%s)", - profileID, signatureToString(tagSignature)); - int size = tcmm.getTagSize(profileID, tagSignature); + p, signatureToString(tagSignature)); + int size = tcmm.getTagSize(p, tagSignature); System.err.println("=" + size); return size; } - public void getTagData(long profileID, int tagSignature, + public void getTagData(Profile p, int tagSignature, byte[] data) { System.err.printf(cName + ".getTagData(ID=%x, TagSig=%s)", - profileID, signatureToString(tagSignature)); + p, signatureToString(tagSignature)); System.err.println(" requested " + data.length + " byte(s)"); - tcmm.getTagData(profileID, tagSignature, data); + tcmm.getTagData(p, tagSignature, data); } - public void setTagData(long profileID, int tagSignature, + public void setTagData(Profile p, int tagSignature, byte[] data) { - System.err.print(cName + ".setTagData(ID=" + profileID + + System.err.print(cName + ".setTagData(ID=" + p + ", TagSig=" + tagSignature + ")"); System.err.println(" sending " + data.length + " byte(s)"); - tcmm.setTagData(profileID, tagSignature, data); + tcmm.setTagData(p, tagSignature, data); } /* methods for creating ColorTransforms */ diff --git a/jdk/src/share/classes/sun/java2d/cmm/PCMM.java b/jdk/src/share/classes/sun/java2d/cmm/PCMM.java index 6b6ce93546d..03f2fab6336 100644 --- a/jdk/src/share/classes/sun/java2d/cmm/PCMM.java +++ b/jdk/src/share/classes/sun/java2d/cmm/PCMM.java @@ -32,13 +32,13 @@ import java.awt.color.ICC_Profile; public interface PCMM { /* methods invoked from ICC_Profile */ - public long loadProfile(byte[] data); - public void freeProfile(long profileID); - public int getProfileSize(long profileID); - public void getProfileData(long profileID, byte[] data); - public void getTagData(long profileID, int tagSignature, byte[] data); - public int getTagSize(long profileID, int tagSignature); - public void setTagData(long profileID, int tagSignature, byte[] data); + public Profile loadProfile(byte[] data); + public void freeProfile(Profile p); + public int getProfileSize(Profile p); + public void getProfileData(Profile p, byte[] data); + public void getTagData(Profile p, int tagSignature, byte[] data); + public int getTagSize(Profile p, int tagSignature); + public void setTagData(Profile p, int tagSignature, byte[] data); /* methods for creating ColorTransforms */ public ColorTransform createTransform(ICC_Profile profile, int renderType, diff --git a/jdk/src/share/classes/sun/java2d/cmm/Profile.java b/jdk/src/share/classes/sun/java2d/cmm/Profile.java new file mode 100644 index 00000000000..5b766b5d079 --- /dev/null +++ b/jdk/src/share/classes/sun/java2d/cmm/Profile.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2013, 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.java2d.cmm; + +import java.awt.color.CMMException; + +public class Profile { + private final long nativePtr; + + protected Profile(long ptr) { + nativePtr = ptr; + } + + protected final long getNativePtr() { + if (nativePtr == 0L) { + throw new CMMException("Invalid profile: ptr is null"); + } + return nativePtr; + } +} diff --git a/jdk/src/share/classes/sun/java2d/cmm/lcms/LCMS.java b/jdk/src/share/classes/sun/java2d/cmm/lcms/LCMS.java index f7ecc0b67c9..d76d99638a9 100644 --- a/jdk/src/share/classes/sun/java2d/cmm/lcms/LCMS.java +++ b/jdk/src/share/classes/sun/java2d/cmm/lcms/LCMS.java @@ -25,96 +25,139 @@ package sun.java2d.cmm.lcms; +import java.awt.color.CMMException; import java.awt.color.ICC_Profile; -import java.util.Arrays; -import java.util.HashMap; import sun.java2d.cmm.ColorTransform; import sun.java2d.cmm.PCMM; +import sun.java2d.cmm.Profile; +import sun.java2d.cmm.lcms.LCMSProfile.TagData; public class LCMS implements PCMM { /* methods invoked from ICC_Profile */ @Override - public long loadProfile(byte[] data) { - long id = loadProfileNative(data); + public Profile loadProfile(byte[] data) { + final Object disposerRef = new Object(); - if (id != 0L) { - if (profiles == null) { - profiles = new HashMap<>(); - } - profiles.put(id, new TagCache(id)); + final long ptr = loadProfileNative(data, disposerRef); + + if (ptr != 0L) { + return new LCMSProfile(ptr, disposerRef); } - return id; + return null; } - private native long loadProfileNative(byte[] data); + private native long loadProfileNative(byte[] data, Object ref); - @Override - public void freeProfile(long profileID) { - TagCache c = profiles.remove(profileID); - if (c != null) { - c.clear(); + private LCMSProfile getLcmsProfile(Profile p) { + if (p instanceof LCMSProfile) { + return (LCMSProfile)p; } - if (profiles.isEmpty()) { - profiles = null; - } - freeProfileNative(profileID); + throw new CMMException("Invalid profile: " + p); } - private native void freeProfileNative(long profileID); - - public native synchronized int getProfileSize(long profileID); - - public native synchronized void getProfileData(long profileID, byte[] data); @Override - public synchronized int getTagSize(long profileID, int tagSignature) { - TagCache cache = profiles.get(profileID); - - if (cache == null) { - cache = new TagCache(profileID); - profiles.put(profileID, cache); - } - - TagData t = cache.getTag(tagSignature); - return t == null ? 0 : t.getSize(); + public void freeProfile(Profile p) { + // we use disposer, so this method does nothing } - private static native byte[] getTagNative(long profileID, int signature); + @Override + public int getProfileSize(final Profile p) { + synchronized (p) { + return getProfileSizeNative(getLcmsProfile(p).getLcmsPtr()); + } + } + + private native int getProfileSizeNative(long ptr); @Override - public synchronized void getTagData(long profileID, int tagSignature, - byte[] data) + public void getProfileData(final Profile p, byte[] data) { + synchronized (p) { + getProfileDataNative(getLcmsProfile(p).getLcmsPtr(), data); + } + } + + private native void getProfileDataNative(long ptr, byte[] data); + + @Override + public int getTagSize(Profile p, int tagSignature) { + final LCMSProfile profile = getLcmsProfile(p); + + synchronized (profile) { + TagData t = profile.getTag(tagSignature); + return t == null ? 0 : t.getSize(); + } + } + + static native byte[] getTagNative(long profileID, int signature); + + @Override + public void getTagData(Profile p, int tagSignature, byte[] data) { - TagCache cache = profiles.get(profileID); + final LCMSProfile profile = getLcmsProfile(p); - if (cache == null) { - cache = new TagCache(profileID); - profiles.put(profileID, cache); - } - - TagData t = cache.getTag(tagSignature); - if (t != null) { - t.copyDataTo(data); + synchronized (profile) { + TagData t = profile.getTag(tagSignature); + if (t != null) { + t.copyDataTo(data); + } } } @Override - public synchronized void setTagData(long profileID, int tagSignature, byte[] data) { - TagCache cache = profiles.get(profileID); + public synchronized void setTagData(Profile p, int tagSignature, byte[] data) { + final LCMSProfile profile = getLcmsProfile(p); - if (cache != null) { - cache.clear(); + synchronized (profile) { + profile.clearTagCache(); + + // Now we are going to update the profile with new tag data + // In some cases, we may change the pointer to the native + // profile. + // + // If we fail to write tag data for any reason, the old pointer + // should be used. + setTagDataNative(profile.getLcmsPtr(), + tagSignature, data); } - setTagDataNative(profileID, tagSignature, data); } - private native synchronized void setTagDataNative(long profileID, int tagSignature, + /** + * Writes supplied data as a tag into the profile. + * Destroys old profile, if new one was successfully + * created. + * + * Returns valid pointer to new profile. + * + * Throws CMMException if operation fails, preserve old profile from + * destruction. + */ + private native void setTagDataNative(long ptr, int tagSignature, byte[] data); - public static native long getProfileID(ICC_Profile profile); + public synchronized static native LCMSProfile getProfileID(ICC_Profile profile); - public static native long createNativeTransform( + /* Helper method used from LCMSColorTransfrom */ + static long createTransform( + LCMSProfile[] profiles, int renderType, + int inFormatter, boolean isInIntPacked, + int outFormatter, boolean isOutIntPacked, + Object disposerRef) + { + long[] ptrs = new long[profiles.length]; + + for (int i = 0; i < profiles.length; i++) { + if (profiles[i] == null) throw new CMMException("Unknown profile ID"); + + ptrs[i] = profiles[i].getLcmsPtr(); + } + + return createNativeTransform(ptrs, renderType, inFormatter, + isInIntPacked, outFormatter, isOutIntPacked, disposerRef); + } + + private static native long createNativeTransform( long[] profileIDs, int renderType, int inFormatter, boolean isInIntPacked, int outFormatter, boolean isOutIntPacked, @@ -175,59 +218,4 @@ public class LCMS implements PCMM { return theLcms; } - - private static class TagData { - private int signature; - private byte[] data; - - TagData(int sig, byte[] data) { - this.signature = sig; - this.data = data; - } - - int getSize() { - return data.length; - } - - byte[] getData() { - return Arrays.copyOf(data, data.length); - } - - void copyDataTo(byte[] dst) { - System.arraycopy(data, 0, dst, 0, data.length); - } - - int getSignature() { - return signature; - } - } - - private static class TagCache { - private long profileID; - private HashMap tags; - - TagCache(long id) { - profileID = id; - - tags = new HashMap<>(); - } - - TagData getTag(int sig) { - TagData t = tags.get(sig); - if (t == null) { - byte[] tagData = getTagNative(profileID, sig); - if (tagData != null) { - t = new TagData(sig, tagData); - tags.put(sig, t); - } - } - return t; - } - - void clear() { - tags.clear(); - } - } - - private static HashMap profiles; } diff --git a/jdk/src/share/classes/sun/java2d/cmm/lcms/LCMSProfile.java b/jdk/src/share/classes/sun/java2d/cmm/lcms/LCMSProfile.java new file mode 100644 index 00000000000..12810812416 --- /dev/null +++ b/jdk/src/share/classes/sun/java2d/cmm/lcms/LCMSProfile.java @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2013, 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.java2d.cmm.lcms; + +import java.awt.color.CMMException; +import java.util.Arrays; +import java.util.HashMap; +import sun.java2d.cmm.Profile; + +final class LCMSProfile extends Profile { + private final TagCache tagCache; + + private final Object disposerReferent; + + LCMSProfile(long ptr, Object ref) { + super(ptr); + + disposerReferent = ref; + + tagCache = new TagCache(this); + } + + final long getLcmsPtr() { + return this.getNativePtr(); + } + + TagData getTag(int sig) { + return tagCache.getTag(sig); + } + + void clearTagCache() { + tagCache.clear(); + } + + static class TagCache { + final LCMSProfile profile; + private HashMap tags; + + TagCache(LCMSProfile p) { + profile = p; + tags = new HashMap<>(); + } + + TagData getTag(int sig) { + TagData t = tags.get(sig); + if (t == null) { + byte[] tagData = LCMS.getTagNative(profile.getNativePtr(), sig); + if (tagData != null) { + t = new TagData(sig, tagData); + tags.put(sig, t); + } + } + return t; + } + + void clear() { + tags.clear(); + } + } + + static class TagData { + private int signature; + private byte[] data; + + TagData(int sig, byte[] data) { + this.signature = sig; + this.data = data; + } + + int getSize() { + return data.length; + } + + byte[] getData() { + return Arrays.copyOf(data, data.length); + } + + void copyDataTo(byte[] dst) { + System.arraycopy(data, 0, dst, 0, data.length); + } + + int getSignature() { + return signature; + } + } +} diff --git a/jdk/src/share/classes/sun/java2d/cmm/lcms/LCMSTransform.java b/jdk/src/share/classes/sun/java2d/cmm/lcms/LCMSTransform.java index d5ce5525989..9d6dfa9aac3 100644 --- a/jdk/src/share/classes/sun/java2d/cmm/lcms/LCMSTransform.java +++ b/jdk/src/share/classes/sun/java2d/cmm/lcms/LCMSTransform.java @@ -62,7 +62,7 @@ public class LCMSTransform implements ColorTransform { private boolean isOutIntPacked = false; ICC_Profile[] profiles; - long [] profileIDs; + LCMSProfile[] lcmsProfiles; int renderType; int transformType; @@ -84,8 +84,8 @@ public class LCMSTransform implements ColorTransform { /* Actually, it is not a complete transform but just part of it */ profiles = new ICC_Profile[1]; profiles[0] = profile; - profileIDs = new long[1]; - profileIDs[0] = LCMS.getProfileID(profile); + lcmsProfiles = new LCMSProfile[1]; + lcmsProfiles[0] = LCMS.getProfileID(profile); this.renderType = (renderType == ColorTransform.Any)? ICC_Profile.icPerceptual : renderType; this.transformType = transformType; @@ -105,14 +105,14 @@ public class LCMSTransform implements ColorTransform { size+=((LCMSTransform)transforms[i]).profiles.length; } profiles = new ICC_Profile[size]; - profileIDs = new long[size]; + lcmsProfiles = new LCMSProfile[size]; int j = 0; for (int i=0; i < transforms.length; i++) { LCMSTransform curTrans = (LCMSTransform)transforms[i]; System.arraycopy(curTrans.profiles, 0, profiles, j, curTrans.profiles.length); - System.arraycopy(curTrans.profileIDs, 0, profileIDs, j, - curTrans.profileIDs.length); + System.arraycopy(curTrans.lcmsProfiles, 0, lcmsProfiles, j, + curTrans.lcmsProfiles.length); j += curTrans.profiles.length; } renderType = ((LCMSTransform)transforms[0]).renderType; @@ -152,7 +152,7 @@ public class LCMSTransform implements ColorTransform { outFormatter = out.pixelType; isOutIntPacked = out.isIntPacked; - ID = LCMS.createNativeTransform(profileIDs, renderType, + ID = LCMS.createTransform(lcmsProfiles, renderType, inFormatter, isInIntPacked, outFormatter, isOutIntPacked, disposerReferent); diff --git a/jdk/src/share/native/sun/java2d/cmm/lcms/LCMS.c b/jdk/src/share/native/sun/java2d/cmm/lcms/LCMS.c index 1340c82a822..13030cc41d5 100644 --- a/jdk/src/share/native/sun/java2d/cmm/lcms/LCMS.c +++ b/jdk/src/share/native/sun/java2d/cmm/lcms/LCMS.c @@ -94,8 +94,12 @@ cmsInt32Number TransportValue32(cmsInt32Number Value) # endif #endif -typedef union storeID_s { /* store SProfile stuff in a Java Long */ +typedef struct lcmsProfile_s { cmsHPROFILE pf; +} lcmsProfile_t, *lcmsProfile_p; + +typedef union storeID_s { /* store SProfile stuff in a Java Long */ + lcmsProfile_p lcmsPf; cmsHTRANSFORM xf; jobject jobj; jlong j; @@ -106,7 +110,6 @@ typedef union { jint j; } TagSignature_t, *TagSignature_p; -static jfieldID Trans_profileIDs_fID; static jfieldID Trans_renderType_fID; static jfieldID Trans_ID_fID; static jfieldID IL_isIntPacked_fID; @@ -118,7 +121,6 @@ static jfieldID IL_nextRowOffset_fID; static jfieldID IL_width_fID; static jfieldID IL_height_fID; static jfieldID IL_imageAtOnce_fID; -static jfieldID PF_ID_fID; JavaVM *javaVM; @@ -145,6 +147,18 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) { return JNI_VERSION_1_6; } +void LCMS_freeProfile(JNIEnv *env, jlong ptr) { + storeID_t sProfile; + sProfile.j = ptr; + + if (sProfile.lcmsPf != NULL) { + if (sProfile.lcmsPf->pf != NULL) { + cmsCloseProfile(sProfile.lcmsPf->pf); + } + free(sProfile.lcmsPf); + } +} + void LCMS_freeTransform(JNIEnv *env, jlong ID) { storeID_t sTrans; @@ -170,7 +184,7 @@ JNIEXPORT jlong JNICALL Java_sun_java2d_cmm_lcms_LCMS_createNativeTransform jlong* ids; size = (*env)->GetArrayLength (env, profileIDs); - ids = (*env)->GetPrimitiveArrayCritical(env, profileIDs, 0); + ids = (*env)->GetLongArrayElements(env, profileIDs, 0); #ifdef _LITTLE_ENDIAN /* Reversing data packed into int for LE archs */ @@ -186,6 +200,8 @@ JNIEXPORT jlong JNICALL Java_sun_java2d_cmm_lcms_LCMS_createNativeTransform iccArray = (cmsHPROFILE*) malloc( size*2*sizeof(cmsHPROFILE)); if (iccArray == NULL) { + (*env)->ReleaseLongArrayElements(env, profileIDs, ids, 0); + J2dRlsTraceLn(J2D_TRACE_ERROR, "getXForm: iccArray == NULL"); return 0L; } @@ -197,7 +213,7 @@ JNIEXPORT jlong JNICALL Java_sun_java2d_cmm_lcms_LCMS_createNativeTransform cmsColorSpaceSignature cs; sTrans.j = ids[i]; - icc = sTrans.pf; + icc = sTrans.lcmsPf->pf; iccArray[j++] = icc; /* Middle non-abstract profiles should be doubled before passing to @@ -215,13 +231,15 @@ JNIEXPORT jlong JNICALL Java_sun_java2d_cmm_lcms_LCMS_createNativeTransform sTrans.xf = cmsCreateMultiprofileTransform(iccArray, j, inFormatter, outFormatter, renderType, 0); - (*env)->ReleasePrimitiveArrayCritical(env, profileIDs, ids, 0); + (*env)->ReleaseLongArrayElements(env, profileIDs, ids, 0); if (sTrans.xf == NULL) { J2dRlsTraceLn(J2D_TRACE_ERROR, "LCMS_createNativeTransform: " "sTrans.xf == NULL"); - JNU_ThrowByName(env, "java/awt/color/CMMException", - "Cannot get color transform"); + if ((*env)->ExceptionOccurred(env) == NULL) { + JNU_ThrowByName(env, "java/awt/color/CMMException", + "Cannot get color transform"); + } } else { Disposer_AddRecord(env, disposerRef, LCMS_freeTransform, sTrans.j); } @@ -236,20 +254,23 @@ JNIEXPORT jlong JNICALL Java_sun_java2d_cmm_lcms_LCMS_createNativeTransform /* * Class: sun_java2d_cmm_lcms_LCMS * Method: loadProfile - * Signature: ([B)J + * Signature: ([B,Lsun/java2d/cmm/lcms/LCMSProfile;)V */ JNIEXPORT jlong JNICALL Java_sun_java2d_cmm_lcms_LCMS_loadProfileNative - (JNIEnv *env, jobject obj, jbyteArray data) + (JNIEnv *env, jobject obj, jbyteArray data, jobject disposerRef) { jbyte* dataArray; jint dataSize; storeID_t sProf; + cmsHPROFILE pf; if (JNU_IsNull(env, data)) { JNU_ThrowIllegalArgumentException(env, "Invalid profile data"); return 0L; } + sProf.j = 0L; + dataArray = (*env)->GetByteArrayElements (env, data, 0); dataSize = (*env)->GetArrayLength (env, data); @@ -258,22 +279,37 @@ JNIEXPORT jlong JNICALL Java_sun_java2d_cmm_lcms_LCMS_loadProfileNative return 0L; } - sProf.pf = cmsOpenProfileFromMem((const void *)dataArray, + pf = cmsOpenProfileFromMem((const void *)dataArray, (cmsUInt32Number) dataSize); (*env)->ReleaseByteArrayElements (env, data, dataArray, 0); - if (sProf.pf == NULL) { + if (pf == NULL) { JNU_ThrowIllegalArgumentException(env, "Invalid profile data"); } else { /* Sanity check: try to save the profile in order * to force basic validation. */ cmsUInt32Number pfSize = 0; - if (!cmsSaveProfileToMem(sProf.pf, NULL, &pfSize) || + if (!cmsSaveProfileToMem(pf, NULL, &pfSize) || pfSize < sizeof(cmsICCHeader)) { JNU_ThrowIllegalArgumentException(env, "Invalid profile data"); + + cmsCloseProfile(pf); + pf = NULL; + } + } + + if (pf != NULL) { + // create profile holder + sProf.lcmsPf = (lcmsProfile_p)malloc(sizeof(lcmsProfile_t)); + if (sProf.lcmsPf != NULL) { + // register the disposer record + sProf.lcmsPf->pf = pf; + Disposer_AddRecord(env, disposerRef, LCMS_freeTransform, sProf.j); + } else { + cmsCloseProfile(pf); } } @@ -282,37 +318,17 @@ JNIEXPORT jlong JNICALL Java_sun_java2d_cmm_lcms_LCMS_loadProfileNative /* * Class: sun_java2d_cmm_lcms_LCMS - * Method: freeProfile - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_sun_java2d_cmm_lcms_LCMS_freeProfileNative - (JNIEnv *env, jobject obj, jlong id) -{ - storeID_t sProf; - - sProf.j = id; - if (cmsCloseProfile(sProf.pf) == 0) { - J2dRlsTraceLn1(J2D_TRACE_ERROR, "LCMS_freeProfile: cmsCloseProfile(%d)" - "== 0", id); - JNU_ThrowByName(env, "java/awt/color/CMMException", - "Cannot close profile"); - } - -} - -/* - * Class: sun_java2d_cmm_lcms_LCMS - * Method: getProfileSize + * Method: getProfileSizeNative * Signature: (J)I */ -JNIEXPORT jint JNICALL Java_sun_java2d_cmm_lcms_LCMS_getProfileSize +JNIEXPORT jint JNICALL Java_sun_java2d_cmm_lcms_LCMS_getProfileSizeNative (JNIEnv *env, jobject obj, jlong id) { storeID_t sProf; cmsUInt32Number pfSize = 0; sProf.j = id; - if (cmsSaveProfileToMem(sProf.pf, NULL, &pfSize) && ((jint)pfSize > 0)) { + if (cmsSaveProfileToMem(sProf.lcmsPf->pf, NULL, &pfSize) && ((jint)pfSize > 0)) { return (jint)pfSize; } else { JNU_ThrowByName(env, "java/awt/color/CMMException", @@ -323,10 +339,10 @@ JNIEXPORT jint JNICALL Java_sun_java2d_cmm_lcms_LCMS_getProfileSize /* * Class: sun_java2d_cmm_lcms_LCMS - * Method: getProfileData + * Method: getProfileDataNative * Signature: (J[B)V */ -JNIEXPORT void JNICALL Java_sun_java2d_cmm_lcms_LCMS_getProfileData +JNIEXPORT void JNICALL Java_sun_java2d_cmm_lcms_LCMS_getProfileDataNative (JNIEnv *env, jobject obj, jlong id, jbyteArray data) { storeID_t sProf; @@ -338,7 +354,7 @@ JNIEXPORT void JNICALL Java_sun_java2d_cmm_lcms_LCMS_getProfileData sProf.j = id; // determine actual profile size - if (!cmsSaveProfileToMem(sProf.pf, NULL, &pfSize)) { + if (!cmsSaveProfileToMem(sProf.lcmsPf->pf, NULL, &pfSize)) { JNU_ThrowByName(env, "java/awt/color/CMMException", "Can not access specified profile."); return; @@ -354,7 +370,7 @@ JNIEXPORT void JNICALL Java_sun_java2d_cmm_lcms_LCMS_getProfileData dataArray = (*env)->GetByteArrayElements (env, data, 0); - status = cmsSaveProfileToMem(sProf.pf, dataArray, &pfSize); + status = cmsSaveProfileToMem(sProf.lcmsPf->pf, dataArray, &pfSize); (*env)->ReleaseByteArrayElements (env, data, dataArray, 0); @@ -368,7 +384,7 @@ JNIEXPORT void JNICALL Java_sun_java2d_cmm_lcms_LCMS_getProfileData /* Get profile header info */ static cmsBool _getHeaderInfo(cmsHPROFILE pf, jbyte* pBuffer, jint bufferSize); static cmsBool _setHeaderInfo(cmsHPROFILE pf, jbyte* pBuffer, jint bufferSize); -static cmsBool _writeCookedTag(cmsHPROFILE pfTarget, cmsTagSignature sig, jbyte *pData, jint size); +static cmsHPROFILE _writeCookedTag(cmsHPROFILE pfTarget, cmsTagSignature sig, jbyte *pData, jint size); /* @@ -412,7 +428,7 @@ JNIEXPORT jbyteArray JNICALL Java_sun_java2d_cmm_lcms_LCMS_getTagNative return NULL; } - status = _getHeaderInfo(sProf.pf, dataArray, bufSize); + status = _getHeaderInfo(sProf.lcmsPf->pf, dataArray, bufSize); (*env)->ReleaseByteArrayElements (env, data, dataArray, 0); @@ -425,8 +441,8 @@ JNIEXPORT jbyteArray JNICALL Java_sun_java2d_cmm_lcms_LCMS_getTagNative return data; } - if (cmsIsTag(sProf.pf, sig.cms)) { - tagSize = cmsReadRawTag(sProf.pf, sig.cms, NULL, 0); + if (cmsIsTag(sProf.lcmsPf->pf, sig.cms)) { + tagSize = cmsReadRawTag(sProf.lcmsPf->pf, sig.cms, NULL, 0); } else { JNU_ThrowByName(env, "java/awt/color/CMMException", "ICC profile tag not found"); @@ -449,7 +465,7 @@ JNIEXPORT jbyteArray JNICALL Java_sun_java2d_cmm_lcms_LCMS_getTagNative return NULL; } - bufSize = cmsReadRawTag(sProf.pf, sig.cms, dataArray, tagSize); + bufSize = cmsReadRawTag(sProf.lcmsPf->pf, sig.cms, dataArray, tagSize); (*env)->ReleaseByteArrayElements (env, data, dataArray, 0); @@ -470,8 +486,10 @@ JNIEXPORT void JNICALL Java_sun_java2d_cmm_lcms_LCMS_setTagDataNative (JNIEnv *env, jobject obj, jlong id, jint tagSig, jbyteArray data) { storeID_t sProf; + cmsHPROFILE pfReplace = NULL; + TagSignature_t sig; - cmsBool status; + cmsBool status = FALSE; jbyte* dataArray; int tagSize; @@ -493,15 +511,24 @@ JNIEXPORT void JNICALL Java_sun_java2d_cmm_lcms_LCMS_setTagDataNative } if (tagSig == SigHead) { - status = _setHeaderInfo(sProf.pf, dataArray, tagSize); + status = _setHeaderInfo(sProf.lcmsPf->pf, dataArray, tagSize); } else { - status = _writeCookedTag(sProf.pf, sig.cms, dataArray, tagSize); + /* + * New strategy for generic tags: create a place holder, + * dump all existing tags there, dump externally supplied + * tag, and return the new profile to the java. + */ + pfReplace = _writeCookedTag(sProf.lcmsPf->pf, sig.cms, dataArray, tagSize); + status = (pfReplace != NULL); } (*env)->ReleaseByteArrayElements(env, data, dataArray, 0); if (!status) { JNU_ThrowIllegalArgumentException(env, "Can not write tag data."); + } else if (pfReplace != NULL) { + cmsCloseProfile(sProf.lcmsPf->pf); + sProf.lcmsPf->pf = pfReplace; } } @@ -624,12 +651,27 @@ JNIEXPORT void JNICALL Java_sun_java2d_cmm_lcms_LCMS_colorConvert /* * Class: sun_java2d_cmm_lcms_LCMS * Method: getProfileID - * Signature: (Ljava/awt/color/ICC_Profile;)J + * Signature: (Ljava/awt/color/ICC_Profile;)Lsun/java2d/cmm/lcms/LCMSProfile */ -JNIEXPORT jlong JNICALL Java_sun_java2d_cmm_lcms_LCMS_getProfileID +JNIEXPORT jobject JNICALL Java_sun_java2d_cmm_lcms_LCMS_getProfileID (JNIEnv *env, jclass cls, jobject pf) { - return (*env)->GetLongField (env, pf, PF_ID_fID); + jfieldID fid = (*env)->GetFieldID (env, + (*env)->GetObjectClass(env, pf), + "cmmProfile", "Lsun/java2d/cmm/Profile;"); + + jclass clsLcmsProfile = (*env)->FindClass(env, + "sun/java2d/cmm/lcms/LCMSProfile"); + + jobject cmmProfile = (*env)->GetObjectField (env, pf, fid); + + if (JNU_IsNull(env, cmmProfile)) { + return NULL; + } + if ((*env)->IsInstanceOf(env, cmmProfile, clsLcmsProfile)) { + return cmmProfile; + } + return NULL; } /* @@ -644,7 +686,6 @@ JNIEXPORT void JNICALL Java_sun_java2d_cmm_lcms_LCMS_initLCMS * corresponding classes to avoid problems with invalidating ids by class * unloading */ - Trans_profileIDs_fID = (*env)->GetFieldID (env, Trans, "profileIDs", "[J"); Trans_renderType_fID = (*env)->GetFieldID (env, Trans, "renderType", "I"); Trans_ID_fID = (*env)->GetFieldID (env, Trans, "ID", "J"); @@ -658,8 +699,6 @@ JNIEXPORT void JNICALL Java_sun_java2d_cmm_lcms_LCMS_initLCMS IL_offset_fID = (*env)->GetFieldID (env, IL, "offset", "I"); IL_imageAtOnce_fID = (*env)->GetFieldID (env, IL, "imageAtOnce", "Z"); IL_nextRowOffset_fID = (*env)->GetFieldID (env, IL, "nextRowOffset", "I"); - - PF_ID_fID = (*env)->GetFieldID (env, Pf, "ID", "J"); } static cmsBool _getHeaderInfo(cmsHPROFILE pf, jbyte* pBuffer, jint bufferSize) @@ -714,76 +753,114 @@ static cmsBool _setHeaderInfo(cmsHPROFILE pf, jbyte* pBuffer, jint bufferSize) return TRUE; } -static cmsBool _writeCookedTag(cmsHPROFILE pfTarget, - cmsTagSignature sig, +/* Returns new profile handler, if it was created successfully, + NULL otherwise. + */ +static cmsHPROFILE _writeCookedTag(const cmsHPROFILE pfTarget, + const cmsTagSignature sig, jbyte *pData, jint size) { - cmsBool status; cmsUInt32Number pfSize = 0; - cmsUInt8Number* pfBuffer = NULL; + const cmsInt32Number tagCount = cmsGetTagCount(pfTarget); + cmsInt32Number i; + cmsHPROFILE pfSanity = NULL; + + cmsICCHeader hdr = { 0 }; cmsHPROFILE p = cmsCreateProfilePlaceholder(NULL); - if (NULL != p) { - cmsICCHeader hdr = { 0 }; - /* Populate the placeholder's header according to target profile */ - hdr.flags = cmsGetHeaderFlags(pfTarget); - hdr.renderingIntent = cmsGetHeaderRenderingIntent(pfTarget); - hdr.manufacturer = cmsGetHeaderManufacturer(pfTarget); - hdr.model = cmsGetHeaderModel(pfTarget); - hdr.pcs = cmsGetPCS(pfTarget); - hdr.colorSpace = cmsGetColorSpace(pfTarget); - hdr.deviceClass = cmsGetDeviceClass(pfTarget); - hdr.version = cmsGetEncodedICCversion(pfTarget); - cmsGetHeaderAttributes(pfTarget, &hdr.attributes); - cmsGetHeaderProfileID(pfTarget, (cmsUInt8Number*)&hdr.profileID); + if (NULL == p) { + return NULL; + } - cmsSetHeaderFlags(p, hdr.flags); - cmsSetHeaderManufacturer(p, hdr.manufacturer); - cmsSetHeaderModel(p, hdr.model); - cmsSetHeaderAttributes(p, hdr.attributes); - cmsSetHeaderProfileID(p, (cmsUInt8Number*)&(hdr.profileID)); - cmsSetHeaderRenderingIntent(p, hdr.renderingIntent); - cmsSetPCS(p, hdr.pcs); - cmsSetColorSpace(p, hdr.colorSpace); - cmsSetDeviceClass(p, hdr.deviceClass); - cmsSetEncodedICCversion(p, hdr.version); + // Populate the placeholder's header according to target profile + hdr.flags = cmsGetHeaderFlags(pfTarget); + hdr.renderingIntent = cmsGetHeaderRenderingIntent(pfTarget); + hdr.manufacturer = cmsGetHeaderManufacturer(pfTarget); + hdr.model = cmsGetHeaderModel(pfTarget); + hdr.pcs = cmsGetPCS(pfTarget); + hdr.colorSpace = cmsGetColorSpace(pfTarget); + hdr.deviceClass = cmsGetDeviceClass(pfTarget); + hdr.version = cmsGetEncodedICCversion(pfTarget); + cmsGetHeaderAttributes(pfTarget, &hdr.attributes); + cmsGetHeaderProfileID(pfTarget, (cmsUInt8Number*)&hdr.profileID); + cmsSetHeaderFlags(p, hdr.flags); + cmsSetHeaderManufacturer(p, hdr.manufacturer); + cmsSetHeaderModel(p, hdr.model); + cmsSetHeaderAttributes(p, hdr.attributes); + cmsSetHeaderProfileID(p, (cmsUInt8Number*)&(hdr.profileID)); + cmsSetHeaderRenderingIntent(p, hdr.renderingIntent); + cmsSetPCS(p, hdr.pcs); + cmsSetColorSpace(p, hdr.colorSpace); + cmsSetDeviceClass(p, hdr.deviceClass); + cmsSetEncodedICCversion(p, hdr.version); - if (cmsWriteRawTag(p, sig, pData, size)) { - if (cmsSaveProfileToMem(p, NULL, &pfSize)) { - pfBuffer = malloc(pfSize); - if (pfBuffer != NULL) { - /* load raw profile data into the buffer */ - if (!cmsSaveProfileToMem(p, pfBuffer, &pfSize)) { - free(pfBuffer); - pfBuffer = NULL; - } + // now write the user supplied tag + if (size <= 0 || !cmsWriteRawTag(p, sig, pData, size)) { + cmsCloseProfile(p); + return NULL; + } + + // copy tags from the original profile + for (i = 0; i < tagCount; i++) { + cmsBool isTagReady = FALSE; + const cmsTagSignature s = cmsGetTagSignature(pfTarget, i); + const cmsInt32Number tagSize = cmsReadRawTag(pfTarget, s, NULL, 0); + + if (s == sig) { + // skip the user supplied tag + continue; + } + + // read raw tag from the original profile + if (tagSize > 0) { + cmsUInt8Number* buf = (cmsUInt8Number*)malloc(tagSize); + if (buf != NULL) { + if (tagSize == cmsReadRawTag(pfTarget, s, buf, tagSize)) { + // now we are ready to write the tag + isTagReady = cmsWriteRawTag(p, s, buf, tagSize); } + free(buf); } } - cmsCloseProfile(p); - } - if (pfBuffer == NULL) { - return FALSE; - } - - /* re-open the placeholder profile */ - p = cmsOpenProfileFromMem(pfBuffer, pfSize); - free(pfBuffer); - status = FALSE; - - if (p != NULL) { - /* Note that pCookedTag points to internal structures of the placeholder, - * so this data is valid only while the placeholder is open. - */ - void *pCookedTag = cmsReadTag(p, sig); - if (pCookedTag != NULL) { - status = cmsWriteTag(pfTarget, sig, pCookedTag); + if (!isTagReady) { + cmsCloseProfile(p); + return NULL; } - pCookedTag = NULL; - cmsCloseProfile(p); } - return status; + + // now we have all tags moved to the new profile. + // do some sanity checks: write it to a memory buffer and read again. + if (cmsSaveProfileToMem(p, NULL, &pfSize)) { + void* buf = malloc(pfSize); + if (buf != NULL) { + // load raw profile data into the buffer + if (cmsSaveProfileToMem(p, buf, &pfSize)) { + pfSanity = cmsOpenProfileFromMem(buf, pfSize); + } + free(buf); + } + } + + if (pfSanity == NULL) { + // for some reason, we failed to save and read the updated profile + // It likely indicates that the profile is not correct, so we report + // a failure here. + cmsCloseProfile(p); + p = NULL; + } else { + // do final check whether we can read and handle the the target tag. + const void* pTag = cmsReadTag(pfSanity, sig); + if (pTag == NULL) { + // the tag can not be cooked + cmsCloseProfile(p); + p = NULL; + } + cmsCloseProfile(pfSanity); + pfSanity = NULL; + } + + return p; } diff --git a/jdk/test/sun/java2d/cmm/ProfileOp/ReadWriteProfileTest.java b/jdk/test/sun/java2d/cmm/ProfileOp/ReadWriteProfileTest.java index bc14128fcee..f3fa0791d46 100644 --- a/jdk/test/sun/java2d/cmm/ProfileOp/ReadWriteProfileTest.java +++ b/jdk/test/sun/java2d/cmm/ProfileOp/ReadWriteProfileTest.java @@ -23,7 +23,7 @@ /** * @test - * @bug 6476665 6523403 6733501 7042594 + * @bug 6476665 6523403 6733501 7042594 7043064 * @summary Verifies reading and writing profiles and tags of the standard color * spaces * @run main ReadWriteProfileTest @@ -82,6 +82,7 @@ public class ReadWriteProfileTest implements Runnable { public void run() { for (int i = 0; i < cspaces.length; i++) { + System.out.println("Profile: " + csNames[i]); ICC_Profile pf = ICC_Profile.getInstance(cspaces[i]); byte [] data = pf.getData(); pf = ICC_Profile.getInstance(data); @@ -92,6 +93,10 @@ public class ReadWriteProfileTest implements Runnable { } for (int tagSig : tags[i].keySet()) { + String signature = SigToString(tagSig); + System.out.printf("Tag: %s\n", signature); + System.out.flush(); + byte [] tagData = pf.getData(tagSig); byte [] empty = new byte[tagData.length]; boolean emptyDataRejected = false; @@ -104,15 +109,23 @@ public class ReadWriteProfileTest implements Runnable { throw new RuntimeException("Test failed: empty tag data was not rejected."); } - pf.setData(tagSig, tagData); - + try { + pf.setData(tagSig, tagData); + } catch (IllegalArgumentException e) { + // let's ignore this exception for Kodak proprietary tags + if (isKodakExtention(signature)) { + System.out.println("Ignore Kodak tag: " + signature); + } else { + throw new RuntimeException("Test failed!", e); + } + } byte [] tagData1 = pf.getData(tagSig); if (!Arrays.equals(tagData1, tags[i].get(tagSig))) { System.err.println("Incorrect result of getData(int) with" + " tag " + - Integer.toHexString(tagSig) + + SigToString(tagSig) + " of " + csNames[i] + " profile"); throw new RuntimeException("Incorrect result of " + @@ -122,6 +135,19 @@ public class ReadWriteProfileTest implements Runnable { } } + private static boolean isKodakExtention(String signature) { + return signature.matches("K\\d\\d\\d"); + } + + private static String SigToString(int tagSig ) { + return String.format("%c%c%c%c", + (char)(0xff & (tagSig >> 24)), + (char)(0xff & (tagSig >> 16)), + (char)(0xff & (tagSig >> 8)), + (char)(0xff & (tagSig))); + + } + public static void main(String [] args) { ReadWriteProfileTest test = new ReadWriteProfileTest(); test.run(); From 5159f55769cb383f4297b3553acb5d6a6e5a25ff Mon Sep 17 00:00:00 2001 From: Clemens Eisserer Date: Wed, 4 Sep 2013 12:38:00 +0400 Subject: [PATCH 091/210] 7159455: Nimbus scrollbar rendering glitch with xrender enabled on i945GM Reviewed-by: prr, bae --- .../classes/sun/java2d/xr/XRPMBlitLoops.java | 92 +++++++++---------- 1 file changed, 43 insertions(+), 49 deletions(-) diff --git a/jdk/src/solaris/classes/sun/java2d/xr/XRPMBlitLoops.java b/jdk/src/solaris/classes/sun/java2d/xr/XRPMBlitLoops.java index aaa48af2e16..20f84fa8ba3 100644 --- a/jdk/src/solaris/classes/sun/java2d/xr/XRPMBlitLoops.java +++ b/jdk/src/solaris/classes/sun/java2d/xr/XRPMBlitLoops.java @@ -225,6 +225,9 @@ class XRPMScaledBlit extends ScaledBlit { * @author Clemens Eisserer */ class XRPMTransformedBlit extends TransformBlit { + final Rectangle compositeBounds = new Rectangle(); + final double[] srcCoords = new double[8]; + final double[] dstCoords = new double[8]; public XRPMTransformedBlit(SurfaceType srcType, SurfaceType dstType) { super(srcType, CompositeType.AnyAlpha, dstType); @@ -235,61 +238,68 @@ class XRPMTransformedBlit extends TransformBlit { * method is functionally equal to: Shape shp = * xform.createTransformedShape(rect); Rectangle bounds = shp.getBounds(); * but performs significantly better. + * Returns true if the destination shape is parallel to x/y axis */ - public Rectangle getCompositeBounds(AffineTransform tr, int dstx, int dsty, int width, int height) { - double[] compBounds = new double[8]; - compBounds[0] = dstx; - compBounds[1] = dsty; - compBounds[2] = dstx + width; - compBounds[3] = dsty; - compBounds[4] = dstx + width; - compBounds[5] = dsty + height; - compBounds[6] = dstx; - compBounds[7] = dsty + height; + protected boolean adjustCompositeBounds(AffineTransform tr, int dstx, int dsty, int width, int height) { + srcCoords[0] = dstx; + srcCoords[1] = dsty; + srcCoords[2] = dstx + width; + srcCoords[3] = dsty; + srcCoords[4] = dstx + width; + srcCoords[5] = dsty + height; + srcCoords[6] = dstx; + srcCoords[7] = dsty + height; - tr.transform(compBounds, 0, compBounds, 0, 4); + tr.transform(srcCoords, 0, dstCoords, 0, 4); - double minX = Math.min(compBounds[0], Math.min(compBounds[2], Math.min(compBounds[4], compBounds[6]))); - double minY = Math.min(compBounds[1], Math.min(compBounds[3], Math.min(compBounds[5], compBounds[7]))); - double maxX = Math.max(compBounds[0], Math.max(compBounds[2], Math.max(compBounds[4], compBounds[6]))); - double maxY = Math.max(compBounds[1], Math.max(compBounds[3], Math.max(compBounds[5], compBounds[7]))); + double minX = Math.min(dstCoords[0], Math.min(dstCoords[2], Math.min(dstCoords[4], dstCoords[6]))); + double minY = Math.min(dstCoords[1], Math.min(dstCoords[3], Math.min(dstCoords[5], dstCoords[7]))); + double maxX = Math.max(dstCoords[0], Math.max(dstCoords[2], Math.max(dstCoords[4], dstCoords[6]))); + double maxY = Math.max(dstCoords[1], Math.max(dstCoords[3], Math.max(dstCoords[5], dstCoords[7]))); - minX = Math.floor(minX); - minY = Math.floor(minY); - maxX = Math.ceil(maxX); - maxY = Math.ceil(maxY); + minX = Math.round(minX); + minY = Math.round(minY); + maxX = Math.round(maxX); + maxY = Math.round(maxY); - return new Rectangle((int) minX, (int) minY, (int) (maxX - minX), (int) (maxY - minY)); + compositeBounds.x = (int) minX; + compositeBounds.y = (int) minY; + compositeBounds.width = (int) (maxX - minX); + compositeBounds.height = (int) (maxY - minY); + + boolean is0or180 = (dstCoords[1] == dstCoords[3]) && (dstCoords[2] == dstCoords[4]); + boolean is90or270 = (dstCoords[0] == dstCoords[2]) && (dstCoords[3] == dstCoords[5]); + + return is0or180 || is90or270; } - public void Transform(SurfaceData src, SurfaceData dst, Composite comp, Region clip, AffineTransform xform, int hint, int srcx, int srcy, - int dstx, int dsty, int width, int height) { + public void Transform(SurfaceData src, SurfaceData dst, Composite comp, Region clip, AffineTransform xform, + int hint, int srcx, int srcy, int dstx, int dsty, int width, int height) { try { SunToolkit.awtLock(); - int filter = XRUtils.ATransOpToXRQuality(hint); - XRSurfaceData x11sdDst = (XRSurfaceData) dst; - x11sdDst.validateAsDestination(null, clip); XRSurfaceData x11sdSrc = (XRSurfaceData) src; + + int filter = XRUtils.ATransOpToXRQuality(hint); + boolean isAxisAligned = adjustCompositeBounds(xform, dstx, dsty, width, height); + + x11sdDst.validateAsDestination(null, clip); x11sdDst.maskBuffer.validateCompositeState(comp, null, null, null); - Rectangle bounds = getCompositeBounds(xform, dstx, dsty, width, height); - - AffineTransform trx = AffineTransform.getTranslateInstance((-bounds.x), (-bounds.y)); + AffineTransform trx = AffineTransform.getTranslateInstance(-compositeBounds.x, -compositeBounds.y); trx.concatenate(xform); AffineTransform maskTX = (AffineTransform) trx.clone(); - trx.translate(-srcx, -srcy); try { trx.invert(); } catch (NoninvertibleTransformException ex) { trx.setToIdentity(); - System.err.println("Reseted to identity!"); } - boolean omitMask = isMaskOmittable(trx, comp, filter); + boolean omitMask = (filter == XRUtils.FAST) + || (isAxisAligned && ((AlphaComposite) comp).getAlpha() == 1.0f); if (!omitMask) { XRMaskImage mask = x11sdSrc.maskBuffer.getMaskImage(); @@ -297,33 +307,17 @@ class XRPMTransformedBlit extends TransformBlit { x11sdSrc.validateAsSource(trx, XRUtils.RepeatPad, filter); int maskPicture = mask.prepareBlitMask(x11sdDst, maskTX, width, height); x11sdDst.maskBuffer.con.renderComposite(XRCompositeManager.getInstance(x11sdSrc).getCompRule(), x11sdSrc.picture, maskPicture, x11sdDst.picture, - 0, 0, 0, 0, bounds.x, bounds.y, bounds.width, bounds.height); + 0, 0, 0, 0, compositeBounds.x, compositeBounds.y, compositeBounds.width, compositeBounds.height); } else { int repeat = filter == XRUtils.FAST ? XRUtils.RepeatNone : XRUtils.RepeatPad; x11sdSrc.validateAsSource(trx, repeat, filter); - x11sdDst.maskBuffer.compositeBlit(x11sdSrc, x11sdDst, 0, 0, bounds.x, bounds.y, bounds.width, bounds.height); + x11sdDst.maskBuffer.compositeBlit(x11sdSrc, x11sdDst, 0, 0, compositeBounds.x, compositeBounds.y, compositeBounds.width, compositeBounds.height); } } finally { SunToolkit.awtUnlock(); } } - - /* TODO: Is mask ever omitable??? ... should be for 90 degree rotation and no shear, but we always need to use RepeatPad */ - protected static boolean isMaskOmittable(AffineTransform trx, Composite comp, int filter) { - return (filter == XRUtils.FAST || trx.getTranslateX() == (int) trx.getTranslateX() /* - * If - * translate - * is - * integer - * only - */ - && trx.getTranslateY() == (int) trx.getTranslateY() && (trx.getShearX() == 0 && trx.getShearY() == 0 // Only - // 90 degree - // rotation - || trx.getShearX() == -trx.getShearY())) && ((AlphaComposite) comp).getAlpha() == 1.0f; // No - // ExtraAlpha!=1 - } } class XrSwToPMBlit extends Blit { From d28e08b5296726876b32631240631d258f61d78d Mon Sep 17 00:00:00 2001 From: Vicente Romero Date: Wed, 4 Sep 2013 11:53:09 +0100 Subject: [PATCH 092/210] 8008275: javac.Main should be @Supported Reviewed-by: jjg --- langtools/src/share/classes/com/sun/tools/javac/Main.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/langtools/src/share/classes/com/sun/tools/javac/Main.java b/langtools/src/share/classes/com/sun/tools/javac/Main.java index 2587d198972..43300b6c3c5 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/Main.java +++ b/langtools/src/share/classes/com/sun/tools/javac/Main.java @@ -30,14 +30,6 @@ import java.io.PrintWriter; /** * The programmatic interface for the Java Programming Language * compiler, javac. - * - *

    Except for the two methods - * {@link #compile(java.lang.String[])} - * {@link #compile(java.lang.String[],java.io.PrintWriter)}, - * nothing described in this source file is part of any supported - * API. If you write code that depends on this, you do so at your own - * risk. This code and its internal interfaces are subject to change - * or deletion without notice. */ @jdk.Supported public class Main { From 34d47bd6722ffc6e16a4b74eb5b3bdb134209fe6 Mon Sep 17 00:00:00 2001 From: Zhengyu Gu Date: Wed, 4 Sep 2013 08:55:08 -0400 Subject: [PATCH 093/210] 8022798: "assert(seq > 0) failed: counter overflow" in Kitchensink Removed incorrect assertion, sequence number can overflow Reviewed-by: dholmes, kamg --- hotspot/src/share/vm/services/memPtr.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hotspot/src/share/vm/services/memPtr.cpp b/hotspot/src/share/vm/services/memPtr.cpp index 3e124e2bde2..bc460517c58 100644 --- a/hotspot/src/share/vm/services/memPtr.cpp +++ b/hotspot/src/share/vm/services/memPtr.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2013, 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,9 +34,9 @@ jint SequenceGenerator::next() { jint seq = Atomic::add(1, &_seq_number); if (seq < 0) { MemTracker::shutdown(MemTracker::NMT_sequence_overflow); + } else { + NOT_PRODUCT(_max_seq_number = (seq > _max_seq_number) ? seq : _max_seq_number;) } - assert(seq > 0, "counter overflow"); - NOT_PRODUCT(_max_seq_number = (seq > _max_seq_number) ? seq : _max_seq_number;) return seq; } From 7da0f59aec2d0011cae55272a5327b8d2f38941f Mon Sep 17 00:00:00 2001 From: Jonathan Gibbons Date: Wed, 4 Sep 2013 14:44:05 -0700 Subject: [PATCH 094/210] 8024288: javadoc generated-by comment should always be present Reviewed-by: bpatel --- .../formats/html/HtmlDocletWriter.java | 5 +-- .../formats/html/markup/HtmlDocWriter.java | 17 ++++----- .../testGeneratedBy/TestGeneratedBy.java | 35 +++++++++++++------ 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java index c55ff564f2f..da36fedcff0 100644 --- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java +++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java @@ -406,10 +406,7 @@ public class HtmlDocletWriter extends HtmlDocWriter { Content htmlDocType = DocType.TRANSITIONAL; Content htmlComment = new Comment(configuration.getText("doclet.New_Page")); Content head = new HtmlTree(HtmlTag.HEAD); - if (!configuration.notimestamp) { - Content headComment = new Comment(getGeneratedByString()); - head.addContent(headComment); - } + head.addContent(getGeneratedBy(!configuration.notimestamp)); if (configuration.charset.length() > 0) { Content meta = HtmlTree.META("Content-Type", CONTENT_TYPE, configuration.charset); diff --git a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlDocWriter.java b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlDocWriter.java index 0eb40080295..c780e962cac 100644 --- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlDocWriter.java +++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlDocWriter.java @@ -191,10 +191,7 @@ public abstract class HtmlDocWriter extends HtmlWriter { Content htmlDocType = DocType.FRAMESET; Content htmlComment = new Comment(configuration.getText("doclet.New_Page")); Content head = new HtmlTree(HtmlTag.HEAD); - if (! noTimeStamp) { - Content headComment = new Comment(getGeneratedByString()); - head.addContent(headComment); - } + head.addContent(getGeneratedBy(!noTimeStamp)); if (configuration.charset.length() > 0) { Content meta = HtmlTree.META("Content-Type", CONTENT_TYPE, configuration.charset); @@ -210,9 +207,13 @@ public abstract class HtmlDocWriter extends HtmlWriter { write(htmlDocument); } - protected String getGeneratedByString() { - Calendar calendar = new GregorianCalendar(TimeZone.getDefault()); - Date today = calendar.getTime(); - return "Generated by javadoc ("+ ConfigurationImpl.BUILD_DATE + ") on " + today; + protected Comment getGeneratedBy(boolean timestamp) { + String text = "Generated by javadoc"; // marker string, deliberately not localized + if (timestamp) { + Calendar calendar = new GregorianCalendar(TimeZone.getDefault()); + Date today = calendar.getTime(); + text += " ("+ ConfigurationImpl.BUILD_DATE + ") on " + today; + } + return new Comment(text); } } diff --git a/langtools/test/com/sun/javadoc/testGeneratedBy/TestGeneratedBy.java b/langtools/test/com/sun/javadoc/testGeneratedBy/TestGeneratedBy.java index 162105edf8b..ec85bec863b 100644 --- a/langtools/test/com/sun/javadoc/testGeneratedBy/TestGeneratedBy.java +++ b/langtools/test/com/sun/javadoc/testGeneratedBy/TestGeneratedBy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2013, 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 8000418 + * @bug 8000418 8024288 * @summary Verify that files use a common Generated By string * @library ../lib/ * @build JavadocTester TestGeneratedBy @@ -50,32 +50,44 @@ public class TestGeneratedBy extends JavadocTester { "index.html" }; - private static final String[] ARGS = + private static final String[] STD_ARGS = new String[] { "-d", OUTPUT_DIR, "-sourcepath", SRC_DIR, "pkg" }; - private static final String BUG_ID = "8000418"; - private static String[][] getTests() { + private static final String[] NO_TIMESTAMP_ARGS = + new String[] { + "-notimestamp", + "-d", OUTPUT_DIR, + "-sourcepath", SRC_DIR, + "pkg" + }; + + private static final String BUG_ID = "8000418-8024288"; + + private static String[][] getTests(boolean timestamp) { String version = System.getProperty("java.version"); String[][] tests = new String[FILES.length][]; for (int i = 0; i < FILES.length; i++) { + String genBy = "Generated by javadoc"; + if (timestamp) genBy += " (" + version + ") on "; tests[i] = new String[] { - OUTPUT_DIR + FS + FILES[i], - "Generated by javadoc (" + version + ") on " + OUTPUT_DIR + FS + FILES[i], genBy }; } return tests; } - private static String[][] getNegatedTests() { + private static String[][] getNegatedTests(boolean timestamp) { String[][] tests = new String[FILES.length][]; for (int i = 0; i < FILES.length; i++) { tests[i] = new String[] { OUTPUT_DIR + FS + FILES[i], - "Generated by javadoc (version", + (timestamp + ? "Generated by javadoc (version" + : "Generated by javadoc ("), "Generated by javadoc on" }; } @@ -88,9 +100,10 @@ public class TestGeneratedBy extends JavadocTester { */ public static void main(String[] args) { TestGeneratedBy tester = new TestGeneratedBy(); - int exitCode = run(tester, ARGS, getTests(), getNegatedTests()); + int ec1 = run(tester, STD_ARGS, getTests(true), getNegatedTests(true)); + int ec2 = run(tester, NO_TIMESTAMP_ARGS, getTests(false), getNegatedTests(false)); tester.printSummary(); - if (exitCode != 0) { + if (ec1 != 0 || ec2 != 0) { throw new Error("Error found while executing Javadoc"); } } From d8b770b0cd7a1a52d39fd0f4407bd14e9232358a Mon Sep 17 00:00:00 2001 From: Clemens Eisserer Date: Thu, 5 Sep 2013 11:50:42 +0400 Subject: [PATCH 095/210] 8024261: xrender: improve performance of small fillRect operations Reviewed-by: prr, bae --- .../solaris/classes/sun/java2d/xr/XRCompositeManager.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/jdk/src/solaris/classes/sun/java2d/xr/XRCompositeManager.java b/jdk/src/solaris/classes/sun/java2d/xr/XRCompositeManager.java index b1c2ef08065..39b8642bb9d 100644 --- a/jdk/src/solaris/classes/sun/java2d/xr/XRCompositeManager.java +++ b/jdk/src/solaris/classes/sun/java2d/xr/XRCompositeManager.java @@ -285,7 +285,12 @@ public class XRCompositeManager { if (xorEnabled) { con.GCRectangles(dst.getXid(), dst.getGC(), rects); } else { - con.renderRectangles(dst.getPicture(), compRule, solidColor, rects); + if (rects.getSize() == 1) { + con.renderRectangle(dst.getPicture(), compRule, solidColor, + rects.getX(0), rects.getY(0), rects.getWidth(0), rects.getHeight(0)); + } else { + con.renderRectangles(dst.getPicture(), compRule, solidColor, rects); + } } } From 4bf1e0d9890a1df932db4b277720de1f181cfb46 Mon Sep 17 00:00:00 2001 From: Andreas Lundblad Date: Thu, 5 Sep 2013 11:27:27 +0200 Subject: [PATCH 096/210] 8023974: Drop 'implements Completer' and 'implements SourceCompleter' from ClassReader resp. JavaCompiler Reviewed-by: jjg, jfranck --- .../com/sun/tools/javac/jvm/ClassReader.java | 23 ++++++++++++++----- .../sun/tools/javac/main/JavaCompiler.java | 15 ++++++++++-- .../com/sun/tools/javadoc/JavadocTool.java | 4 ++-- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java b/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java index 3fc93921c8e..d3d9d302f1e 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java +++ b/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java @@ -72,7 +72,7 @@ import static com.sun.tools.javac.main.Option.*; * This code and its internal interfaces are subject to change or * deletion without notice. */ -public class ClassReader implements Completer { +public class ClassReader { /** The context key for the class reader. */ protected static final Context.Key classReaderKey = new Context.Key(); @@ -234,6 +234,17 @@ public class ClassReader implements Completer { */ Set warnedAttrs = new HashSet(); + /** + * Completer that delegates to the complete-method of this class. + */ + private final Completer thisCompleter = new Completer() { + @Override + public void complete(Symbol sym) throws CompletionFailure { + ClassReader.this.complete(sym); + } + }; + + /** Get the ClassReader instance for this invocation. */ public static ClassReader instance(Context context) { ClassReader instance = context.get(classReaderKey); @@ -264,8 +275,8 @@ public class ClassReader implements Completer { } packages.put(names.empty, syms.rootPackage); - syms.rootPackage.completer = this; - syms.unnamedPackage.completer = this; + syms.rootPackage.completer = thisCompleter; + syms.unnamedPackage.completer = thisCompleter; } /** Construct a new class reader, optionally treated as the @@ -2319,7 +2330,7 @@ public class ClassReader implements Completer { ClassSymbol c = new ClassSymbol(0, name, owner); if (owner.kind == PCK) Assert.checkNull(classes.get(c.flatname), c); - c.completer = this; + c.completer = thisCompleter; return c; } @@ -2389,7 +2400,7 @@ public class ClassReader implements Completer { /** Completion for classes to be loaded. Before a class is loaded * we make sure its enclosing class (if any) is loaded. */ - public void complete(Symbol sym) throws CompletionFailure { + private void complete(Symbol sym) throws CompletionFailure { if (sym.kind == TYP) { ClassSymbol c = (ClassSymbol)sym; c.members_field = new Scope.ErrorScope(c); // make sure it's always defined @@ -2610,7 +2621,7 @@ public class ClassReader implements Completer { p = new PackageSymbol( Convert.shortName(fullname), enterPackage(Convert.packagePart(fullname))); - p.completer = this; + p.completer = thisCompleter; packages.put(fullname, p); } return p; diff --git a/langtools/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java b/langtools/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java index 73d3b020bc1..ba369172f43 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java +++ b/langtools/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java @@ -80,7 +80,7 @@ import static com.sun.tools.javac.util.ListBuffer.lb; * This code and its internal interfaces are subject to change or * deletion without notice. */ -public class JavaCompiler implements ClassReader.SourceCompleter { +public class JavaCompiler { /** The context key for the compiler. */ protected static final Context.Key compilerKey = new Context.Key(); @@ -310,6 +310,17 @@ public class JavaCompiler implements ClassReader.SourceCompleter { */ protected JavaCompiler delegateCompiler; + /** + * SourceCompleter that delegates to the complete-method of this class. + */ + protected final ClassReader.SourceCompleter thisCompleter = + new ClassReader.SourceCompleter() { + @Override + public void complete(ClassSymbol sym) throws CompletionFailure { + JavaCompiler.this.complete(sym); + } + }; + /** * Command line options. */ @@ -374,7 +385,7 @@ public class JavaCompiler implements ClassReader.SourceCompleter { types = Types.instance(context); taskListener = MultiTaskListener.instance(context); - reader.sourceCompleter = this; + reader.sourceCompleter = thisCompleter; options = Options.instance(context); diff --git a/langtools/src/share/classes/com/sun/tools/javadoc/JavadocTool.java b/langtools/src/share/classes/com/sun/tools/javadoc/JavadocTool.java index 1cc3de3c8c3..f30251ab737 100644 --- a/langtools/src/share/classes/com/sun/tools/javadoc/JavadocTool.java +++ b/langtools/src/share/classes/com/sun/tools/javadoc/JavadocTool.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2013, 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 @@ -134,7 +134,7 @@ public class JavadocTool extends com.sun.tools.javac.main.JavaCompiler { docenv.setEncoding(encoding); docenv.docClasses = docClasses; docenv.legacyDoclet = legacyDoclet; - javadocReader.sourceCompleter = docClasses ? null : this; + javadocReader.sourceCompleter = docClasses ? null : thisCompleter; ListBuffer names = new ListBuffer(); ListBuffer classTrees = new ListBuffer(); From c73d39394791f549f2fe191c844f131ae958143b Mon Sep 17 00:00:00 2001 From: Igor Ignatyev Date: Thu, 5 Sep 2013 16:38:04 +0400 Subject: [PATCH 097/210] 8012447: Java CTW implementation Reviewed-by: vlivanov, kvn, twisti --- hotspot/test/gc/TestVerifyDuringStartup.java | 2 +- .../java/testlibrary/JDKToolFinder.java | 53 ++-- hotspot/test/testlibrary/ctw/Makefile | 73 ++++++ hotspot/test/testlibrary/ctw/README | 93 +++++++ .../hotspot/tools/ctw/ClassPathDirEntry.java | 117 +++++++++ .../hotspot/tools/ctw/ClassPathJarEntry.java | 81 ++++++ .../tools/ctw/ClassPathJarInDirEntry.java | 62 +++++ .../hotspot/tools/ctw/ClassesListInFile.java | 61 +++++ .../hotspot/tools/ctw/CompileTheWorld.java | 175 +++++++++++++ .../src/sun/hotspot/tools/ctw/Compiler.java | 235 ++++++++++++++++++ .../sun/hotspot/tools/ctw/PathHandler.java | 149 +++++++++++ .../ctw/src/sun/hotspot/tools/ctw/Utils.java | 215 ++++++++++++++++ hotspot/test/testlibrary/ctw/test/Bar.java | 5 + .../testlibrary/ctw/test/ClassesDirTest.java | 61 +++++ .../testlibrary/ctw/test/ClassesListTest.java | 58 +++++ .../test/testlibrary/ctw/test/CtwTest.java | 118 +++++++++ hotspot/test/testlibrary/ctw/test/Foo.java | 5 + .../test/testlibrary/ctw/test/JarDirTest.java | 75 ++++++ .../test/testlibrary/ctw/test/JarsTest.java | 65 +++++ hotspot/test/testlibrary/ctw/test/classes.lst | 4 + hotspot/test/testlibrary/whitebox/Makefile | 63 +++++ 21 files changed, 1752 insertions(+), 18 deletions(-) create mode 100644 hotspot/test/testlibrary/ctw/Makefile create mode 100644 hotspot/test/testlibrary/ctw/README create mode 100644 hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/ClassPathDirEntry.java create mode 100644 hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/ClassPathJarEntry.java create mode 100644 hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/ClassPathJarInDirEntry.java create mode 100644 hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/ClassesListInFile.java create mode 100644 hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/CompileTheWorld.java create mode 100644 hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/Compiler.java create mode 100644 hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/PathHandler.java create mode 100644 hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/Utils.java create mode 100644 hotspot/test/testlibrary/ctw/test/Bar.java create mode 100644 hotspot/test/testlibrary/ctw/test/ClassesDirTest.java create mode 100644 hotspot/test/testlibrary/ctw/test/ClassesListTest.java create mode 100644 hotspot/test/testlibrary/ctw/test/CtwTest.java create mode 100644 hotspot/test/testlibrary/ctw/test/Foo.java create mode 100644 hotspot/test/testlibrary/ctw/test/JarDirTest.java create mode 100644 hotspot/test/testlibrary/ctw/test/JarsTest.java create mode 100644 hotspot/test/testlibrary/ctw/test/classes.lst create mode 100644 hotspot/test/testlibrary/whitebox/Makefile diff --git a/hotspot/test/gc/TestVerifyDuringStartup.java b/hotspot/test/gc/TestVerifyDuringStartup.java index f4ac347f80e..4ac32bf118e 100644 --- a/hotspot/test/gc/TestVerifyDuringStartup.java +++ b/hotspot/test/gc/TestVerifyDuringStartup.java @@ -48,7 +48,7 @@ public class TestVerifyDuringStartup { "-XX:+VerifyDuringStartup", "-version"}); - System.out.print("Testing:\n" + JDKToolFinder.getJDKTool("java")); + System.out.print("Testing:\n" + JDKToolFinder.getCurrentJDKTool("java")); for (int i = 0; i < vmOpts.size(); i += 1) { System.out.print(" " + vmOpts.get(i)); } diff --git a/hotspot/test/testlibrary/com/oracle/java/testlibrary/JDKToolFinder.java b/hotspot/test/testlibrary/com/oracle/java/testlibrary/JDKToolFinder.java index 91ad6a8c8a9..a39abbd3626 100644 --- a/hotspot/test/testlibrary/com/oracle/java/testlibrary/JDKToolFinder.java +++ b/hotspot/test/testlibrary/com/oracle/java/testlibrary/JDKToolFinder.java @@ -27,24 +27,43 @@ import java.io.File; public final class JDKToolFinder { - private JDKToolFinder() { - } - - /** - * Returns the full path to an executable in jdk/bin based on System property - * test.jdk (set by jtreg test suite) - * - * @return Full path to an executable in jdk/bin - */ - public static String getJDKTool(String tool) { - String binPath = System.getProperty("test.jdk"); - if (binPath == null) { - throw new RuntimeException("System property 'test.jdk' not set. This property is normally set by jtreg. " - + "When running test separately, set this property using '-Dtest.jdk=/path/to/jdk'."); + private JDKToolFinder() { } - binPath += File.separatorChar + "bin" + File.separatorChar + tool; + /** + * Returns the full path to an executable in jdk/bin based on System + * property {@code compile.jdk} (set by jtreg test suite) + * + * @return Full path to an executable in jdk/bin + */ + public static String getJDKTool(String tool) { + String binPath = System.getProperty("compile.jdk"); + if (binPath == null) { + throw new RuntimeException("System property 'compile.jdk' not set. " + + "This property is normally set by jtreg. " + + "When running test separately, set this property using " + + "'-Dcompile.jdk=/path/to/jdk'."); + } + binPath += File.separatorChar + "bin" + File.separatorChar + tool; - return binPath; - } + return binPath; + } + /** + * Returns the full path to an executable in <current jdk>/bin based + * on System property {@code test.jdk} (set by jtreg test suite) + * + * @return Full path to an executable in jdk/bin + */ + public static String getCurrentJDKTool(String tool) { + String binPath = System.getProperty("test.jdk"); + if (binPath == null) { + throw new RuntimeException("System property 'test.jdk' not set. " + + "This property is normally set by jtreg. " + + "When running test separately, set this property using " + + "'-Dtest.jdk=/path/to/jdk'."); + } + binPath += File.separatorChar + "bin" + File.separatorChar + tool; + + return binPath; + } } diff --git a/hotspot/test/testlibrary/ctw/Makefile b/hotspot/test/testlibrary/ctw/Makefile new file mode 100644 index 00000000000..5bca7754c69 --- /dev/null +++ b/hotspot/test/testlibrary/ctw/Makefile @@ -0,0 +1,73 @@ +# +# Copyright (c) 2013, 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. +# +# + +ifneq "x$(ALT_BOOTDIR)" "x" + BOOTDIR := $(ALT_BOOTDIR) +endif + +ifeq "x$(BOOTDIR)" "x" + JDK_HOME := $(shell dirname $(shell which java))/.. +else + JDK_HOME := $(BOOTDIR) +endif + +SRC_DIR = src +BUILD_DIR = build +OUTPUT_DIR = $(BUILD_DIR)/classes +WHITEBOX_DIR = ../whitebox + +JAVAC = $(JDK_HOME)/bin/javac +JAR = $(JDK_HOME)/bin/jar + +SRC_FILES = $(shell find $(SRC_DIR) -name '*.java') + +MAIN_CLASS = sun.hotspot.tools.ctw.CompileTheWorld + +.PHONY: clean cleantmp + +all: ctw.jar cleantmp + +clean: cleantmp + @rm -rf ctw.jar wb.jar + +cleantmp: + @rm -rf filelist manifest.mf + @rm -rf $(BUILD_DIR) + +ctw.jar: filelist wb.jar manifest.mf + @mkdir -p $(OUTPUT_DIR) + $(JAVAC) -sourcepath $(SRC_DIR) -d $(OUTPUT_DIR) -cp wb.jar @filelist + $(JAR) cfm ctw.jar manifest.mf -C $(OUTPUT_DIR) . + +wb.jar: + make -C ${WHITEBOX_DIR} wb.jar + cp ${WHITEBOX_DIR}/wb.jar ./ + make -C ${WHITEBOX_DIR} clean + +filelist: $(SRC_FILES) + @rm -f $@ + @echo $(SRC_FILES) > $@ + +manifest.mf: + @echo "Main-Class: ${MAIN_CLASS}" > manifest.mf diff --git a/hotspot/test/testlibrary/ctw/README b/hotspot/test/testlibrary/ctw/README new file mode 100644 index 00000000000..babb0816229 --- /dev/null +++ b/hotspot/test/testlibrary/ctw/README @@ -0,0 +1,93 @@ +# +# Copyright (c) 2013, 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. +# +# + +DESCRIPTION + +This is replacement for CompileTheWorld (CTW) written on java. Its purpose is +to make possible the use of CTW in product builds. + +DEPENDENCES + +The tool depends on Whitebox API. Assumed, that the sources of whitebox are +located in '../whitebox' directory. + +BUILDING + +Simple way to build, just type 'make'. + +Makefile uses environment variables 'ALT_BOOTDIR', 'BOOTDIR' as root-dir of jdk +that will be used for compilation and creating jar. + +On successful building 'ctw.jar' will be created. + +RUNNING + +Since the tool uses WhiteBox API, options 'UnlockDiagnosticVMOptions' and +'WhiteBoxAPI' should be specified, and 'wb.jar' should be added to +boot-classpath: + $ java -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:wb.jar -jar ctw.jar + +Arguments can be paths to '.jar, '.zip', '.lst' files or directories with +classes, that define which classes will be compiled: + - '.jar', '.zip' files and directories are interpreted like in classpath +(including '

    /*' syntax) + - '.lst' files -- files with class names (in java notation) to compile. +CTW will try to find these classes with default class loader, so they should +be located in classpath. + +Without arguments it would work as old version of CTW: all classes in +boot-classpath will be compiled, excluding classes in 'rt.jar' if 'rt.jar' isn't +first in boot-classpath. + +Due CTW's flags also are not available in product builds, the tool uses +properties with the same names: + - 'CompileTheWorldPreloadClasses' -- type:boolean, default:true, description: +Preload all classes used by a class before start loading + - 'CompileTheWorldStartAt' -- type:long, default:1, description: First class +to consider + - 'CompileTheWorldStopAt' -- type:long, default:Long.MAX_VALUE, description: +Last class to consider + +Also it uses additional properties: + - 'sun.hotspot.tools.ctw.verbose' -- type:boolean, default:false, +description: Verbose output, adds additional information about compilation + - 'sun.hotspot.tools.ctw.logfile' -- type:string, default:null, +description: Path to logfile, if it's null, cout will be used. + +EXAMPLES + +compile classes from 'rt.jar': + $ java -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:wb.jar -jar ctw.jar ${JAVA_HOME}/jre/lib/rt.jar + +compile classes from all '.jar' in './testjars' directory: + $ java -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:wb.jar -jar ctw.jar ./testjars/* + +compile classes from './build/classes' directory: + $ java -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:wb.jar -jar ctw.jar ./build/classes + +compile only java.lang.String, java.lang.Object classes: + $ echo java.lang.String > classes.lst + $ echo java.lang.Object >> classes.lst + $ java -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:wb.jar -jar ctw.jar classes.lst + diff --git a/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/ClassPathDirEntry.java b/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/ClassPathDirEntry.java new file mode 100644 index 00000000000..3ee3526568d --- /dev/null +++ b/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/ClassPathDirEntry.java @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2013, 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. + */ + +package sun.hotspot.tools.ctw; + +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Set; +import java.util.EnumSet; +import java.util.HashSet; +import java.util.concurrent.Executor; + +import java.io.*; +import java.nio.file.*; +import java.nio.file.attribute.*; + +/** + * * Handler for dirs containing classes to compile. + * @author igor.ignatyev@oracle.com + */ +public class ClassPathDirEntry extends PathHandler { + + private final int rootLength = root.toString().length(); + + public ClassPathDirEntry(Path root, Executor executor) { + super(root, executor); + try { + URL url = root.toUri().toURL(); + setLoader(new URLClassLoader(new URL[]{url})); + } catch (MalformedURLException e) { + e.printStackTrace(); + } + } + + @Override + public void process() { + System.out.println("# dir: " + root); + if (!Files.exists(root)) { + return; + } + try { + Files.walkFileTree(root, EnumSet.of(FileVisitOption.FOLLOW_LINKS), + Integer.MAX_VALUE, new CompileFileVisitor()); + } catch (IOException ioe) { + ioe.printStackTrace(); + } + } + + private void processFile(Path file) { + if (Utils.isClassFile(file.toString())) { + processClass(pathToClassName(file)); + } + } + + private String pathToClassName(Path file) { + String fileString; + if (root == file) { + fileString = file.normalize().toString(); + } else { + fileString = file.normalize().toString().substring(rootLength + 1); + } + return Utils.fileNameToClassName(fileString); + } + + private class CompileFileVisitor extends SimpleFileVisitor { + + private final Set ready = new HashSet<>(); + + @Override + public FileVisitResult preVisitDirectory(Path dir, + BasicFileAttributes attrs) throws IOException { + if (ready.contains(dir)) { + return FileVisitResult.SKIP_SUBTREE; + } + ready.add(dir); + return super.preVisitDirectory(dir, attrs); + } + + @Override + public FileVisitResult visitFile(Path file, + BasicFileAttributes attrs) throws IOException { + if (!ready.contains(file)) { + processFile(file); + } + return isFinished() ? FileVisitResult.TERMINATE + : FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFileFailed(Path file, + IOException exc) throws IOException { + return FileVisitResult.CONTINUE; + } + } +} + diff --git a/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/ClassPathJarEntry.java b/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/ClassPathJarEntry.java new file mode 100644 index 00000000000..3d39f1b2573 --- /dev/null +++ b/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/ClassPathJarEntry.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2013, 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. + */ + +package sun.hotspot.tools.ctw; + +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.*; +import java.util.jar.*; +import java.util.concurrent.Executor; + +import java.io.*; +import java.nio.file.*; + +/** + * Handler for jar-files containing classes to compile. + * @author igor.ignatyev@oracle.com + */ +public class ClassPathJarEntry extends PathHandler { + + public ClassPathJarEntry(Path root, Executor executor) { + super(root, executor); + try { + URL url = root.toUri().toURL(); + setLoader(new URLClassLoader(new URL[]{url})); + } catch (MalformedURLException e) { + e.printStackTrace(); + } + } + + @Override + public void process() { + System.out.println("# jar: " + root); + if (!Files.exists(root)) { + return; + } + try { + JarFile jarFile = new JarFile(root.toFile()); + JarEntry entry; + for (Enumeration e = jarFile.entries(); + e.hasMoreElements(); ) { + entry = e.nextElement(); + processJarEntry(entry); + if (isFinished()) { + return; + } + } + } catch (IOException ioe) { + ioe.printStackTrace(); + } + } + + private void processJarEntry(JarEntry entry) { + String filename = entry.getName(); + if (Utils.isClassFile(filename)) { + processClass(Utils.fileNameToClassName(filename)); + } + } +} + diff --git a/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/ClassPathJarInDirEntry.java b/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/ClassPathJarInDirEntry.java new file mode 100644 index 00000000000..328280a2d88 --- /dev/null +++ b/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/ClassPathJarInDirEntry.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2013, 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. + */ + +package sun.hotspot.tools.ctw; + +import java.io.IOException; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.concurrent.Executor; + +/** + * Handler for dirs containing jar-files with classes to compile. + * + * @author igor.ignatyev@oracle.com + */ +public class ClassPathJarInDirEntry extends PathHandler { + + public ClassPathJarInDirEntry(Path root, Executor executor) { + super(root, executor); + } + + @Override + public void process() { + System.out.println("# jar_in_dir: " + root); + if (!Files.exists(root)) { + return; + } + try (DirectoryStream ds + = Files.newDirectoryStream(root, "*.jar")) { + for (Path p : ds) { + new ClassPathJarEntry(p, executor).process(); + if (isFinished()) { + return; + } + } + } catch (IOException ioe) { + ioe.printStackTrace(); + } + } +} + diff --git a/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/ClassesListInFile.java b/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/ClassesListInFile.java new file mode 100644 index 00000000000..6f36d8b5c6d --- /dev/null +++ b/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/ClassesListInFile.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2013, 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. + */ + +package sun.hotspot.tools.ctw; + +import java.io.BufferedReader; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.concurrent.Executor; + +/** + * Handler for files containing a list of classes to compile. + * + * @author igor.ignatyev@oracle.com + */ +public class ClassesListInFile extends PathHandler { + public ClassesListInFile(Path root, Executor executor) { + super(root, executor); + } + + @Override + public void process() { + System.out.println("# list: " + root); + if (!Files.exists(root)) { + return; + } + try { + try (BufferedReader reader = Files.newBufferedReader(root, + StandardCharsets.UTF_8)) { + String line; + while (!isFinished() && ((line = reader.readLine()) != null)) { + processClass(line); + } + } + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/CompileTheWorld.java b/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/CompileTheWorld.java new file mode 100644 index 00000000000..f1d46526d31 --- /dev/null +++ b/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/CompileTheWorld.java @@ -0,0 +1,175 @@ +/* + * Copyright (c) 2013, 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. + */ + +package sun.hotspot.tools.ctw; + +import sun.management.ManagementFactoryHelper; + +import java.io.*; +import java.nio.file.Files; +import java.nio.file.Paths; + +import java.util.List; +import java.util.concurrent.*; + +/** + * @author igor.ignatyev@oracle.com + */ +public class CompileTheWorld { + /** + * Entry point. Compiles classes in {@code args}, or all classes in + * boot-classpath if args is empty + * + * @param args paths to jar/zip, dir contains classes, or to .lst file + * contains list of classes to compile + */ + public static void main(String[] args) { + String logfile = Utils.LOG_FILE; + PrintStream os = null; + if (logfile != null) { + try { + os = new PrintStream(Files.newOutputStream(Paths.get(logfile))); + } catch (IOException io) { + } + } + if (os != null) { + System.setOut(os); + } + + try { + try { + if (ManagementFactoryHelper.getCompilationMXBean() == null) { + throw new RuntimeException( + "CTW can not work in interpreted mode"); + } + } catch (java.lang.NoClassDefFoundError e) { + // compact1, compact2 support + } + String[] paths = args; + boolean skipRtJar = false; + if (args.length == 0) { + paths = getDefaultPaths(); + skipRtJar = true; + } + ExecutorService executor = createExecutor(); + long start = System.currentTimeMillis(); + try { + String path; + for (int i = 0, n = paths.length; i < n + && !PathHandler.isFinished(); ++i) { + path = paths[i]; + if (skipRtJar && i > 0 && isRtJar(path)) { + // rt.jar is not first, so skip it + continue; + } + PathHandler.create(path, executor).process(); + } + } finally { + await(executor); + } + System.out.printf("Done (%d classes, %d methods, %d ms)%n", + Compiler.getClassCount(), + Compiler.getMethodCount(), + System.currentTimeMillis() - start); + } finally { + if (os != null) { + os.close(); + } + } + } + + private static ExecutorService createExecutor() { + final int threadsCount = Math.min( + Runtime.getRuntime().availableProcessors(), + Utils.CI_COMPILER_COUNT); + ExecutorService result; + if (threadsCount > 1) { + result = new ThreadPoolExecutor(threadsCount, threadsCount, + /* keepAliveTime */ 0L, TimeUnit.MILLISECONDS, + new ArrayBlockingQueue<>(threadsCount), + new ThreadPoolExecutor.CallerRunsPolicy()); + } else { + result = new CurrentThreadExecutor(); + } + return result; + } + + private static String[] getDefaultPaths() { + String property = System.getProperty("sun.boot.class.path"); + System.out.println( + "# use 'sun.boot.class.path' as args: " + property); + return Utils.PATH_SEPARATOR.split(property); + } + + private static void await(ExecutorService executor) { + executor.shutdown(); + while (!executor.isTerminated()) { + try { + executor.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); + } catch (InterruptedException ie) { + Thread.currentThread().interrupt(); + break; + } + } + } + + private static boolean isRtJar(String path) { + return Utils.endsWithIgnoreCase(path, File.separator + "rt.jar"); + } + + private static class CurrentThreadExecutor extends AbstractExecutorService { + private boolean isShutdown; + + @Override + public void shutdown() { + this.isShutdown = true; + } + + @Override + public List shutdownNow() { + return null; + } + + @Override + public boolean isShutdown() { + return isShutdown; + } + + @Override + public boolean isTerminated() { + return isShutdown; + } + + @Override + public boolean awaitTermination(long timeout, TimeUnit unit) + throws InterruptedException { + return isShutdown; + } + + @Override + public void execute(Runnable command) { + command.run(); + } + } +} + diff --git a/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/Compiler.java b/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/Compiler.java new file mode 100644 index 00000000000..ccb2d3ae53a --- /dev/null +++ b/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/Compiler.java @@ -0,0 +1,235 @@ +/* + * Copyright (c) 2013, 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. + */ + +package sun.hotspot.tools.ctw; + +import sun.hotspot.WhiteBox; +import sun.misc.SharedSecrets; +import sun.reflect.ConstantPool; + +import java.lang.reflect.Executable; + +import java.util.Objects; +import java.util.concurrent.Executor; +import java.util.concurrent.atomic.AtomicLong; + +/** + * Provide method to compile whole class. + * Also contains compiled methods and classes counters. + * + * @author igor.ignatyev@oracle.com + */ +public class Compiler { + private Compiler() { } + private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox(); + private static final AtomicLong CLASS_COUNT = new AtomicLong(0L); + private static final AtomicLong METHOD_COUNT = new AtomicLong(0L); + private static volatile boolean CLASSES_LIMIT_REACHED = false; + + /** + * @return count of processed classes + */ + public static long getClassCount() { + return CLASS_COUNT.get(); + } + + /** + * @return count of processed methods + */ + public static long getMethodCount() { + return METHOD_COUNT.get(); + } + + /** + * @return {@code true} if classes limit is reached + */ + public static boolean isLimitReached() { + return CLASSES_LIMIT_REACHED; + } + + /** + * Compiles all methods and constructors. + * + * @param aClass class to compile + * @param executor executor used for compile task invocation + * @throws NullPointerException if {@code class} or {@code executor} + * is {@code null} + */ + public static void compileClass(Class aClass, Executor executor) { + Objects.requireNonNull(aClass); + Objects.requireNonNull(executor); + long id = CLASS_COUNT.incrementAndGet(); + if (id > Utils.COMPILE_THE_WORLD_STOP_AT) { + CLASS_COUNT.decrementAndGet(); + CLASSES_LIMIT_REACHED = true; + return; + } + + if (id >= Utils.COMPILE_THE_WORLD_START_AT) { + String name = aClass.getName(); + try { + System.out.printf("[%d]\t%s%n", id, name); + ConstantPool constantPool = SharedSecrets.getJavaLangAccess(). + getConstantPool(aClass); + if (Utils.COMPILE_THE_WORLD_PRELOAD_CLASSES) { + preloadClasses(name, id, constantPool); + } + long methodCount = 0; + for (Executable e : aClass.getDeclaredConstructors()) { + ++methodCount; + executor.execute(new CompileMethodCommand(id, name, e)); + } + for (Executable e : aClass.getDeclaredMethods()) { + ++methodCount; + executor.execute(new CompileMethodCommand(id, name, e)); + } + METHOD_COUNT.addAndGet(methodCount); + + if (Utils.DEOPTIMIZE_ALL_CLASSES_RATE > 0 + && (id % Utils.DEOPTIMIZE_ALL_CLASSES_RATE == 0)) { + WHITE_BOX.deoptimizeAll(); + } + } catch (Throwable t) { + System.out.printf("[%d]\t%s\tskipping %s%n", id, name, t); + t.printStackTrace(); + } + } + } + + private static void preloadClasses(String className, long id, + ConstantPool constantPool) { + try { + for (int i = 0, n = constantPool.getSize(); i < n; ++i) { + try { + constantPool.getClassAt(i); + } catch (IllegalArgumentException ignore) { + } + } + } catch (Throwable t) { + System.out.printf("[%d]\t%s\tpreloading failed : %s%n", id, + className, t); + } + } + + + + /** + * Compilation of method. + * Will compile method on all available comp levels. + */ + private static class CompileMethodCommand implements Runnable { + private final long classId; + private final String className; + private final Executable method; + + /** + * @param classId id of class + * @param className name of class + * @param method compiled for compilation + */ + public CompileMethodCommand(long classId, String className, + Executable method) { + this.classId = classId; + this.className = className; + this.method = method; + } + + @Override + public final void run() { + int compLevel = Utils.INITIAL_COMP_LEVEL; + if (Utils.TIERED_COMPILATION) { + for (int i = compLevel; i <= Utils.TIERED_STOP_AT_LEVEL; ++i) { + WHITE_BOX.deoptimizeMethod(method); + compileMethod(method, i); + } + } else { + compileMethod(method, compLevel); + } + } + + private void waitCompilation() { + if (!Utils.BACKGROUND_COMPILATION) { + return; + } + final Object obj = new Object(); + synchronized (obj) { + for (int i = 0; + i < 10 && WHITE_BOX.isMethodQueuedForCompilation(method); + ++i) { + try { + obj.wait(1000); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + } + } + } + + private void compileMethod(Executable method, int compLevel) { + if (WHITE_BOX.isMethodCompilable(method, compLevel)) { + try { + WHITE_BOX.enqueueMethodForCompilation(method, compLevel); + waitCompilation(); + int tmp = WHITE_BOX.getMethodCompilationLevel(method); + if (tmp != compLevel) { + logMethod(method, "compilation level = " + tmp + + ", but not " + compLevel); + } else if (Utils.IS_VERBOSE) { + logMethod(method, "compilation level = " + tmp + ". OK"); + } + } catch (Throwable t) { + logMethod(method, "error on compile at " + compLevel + + " level"); + t.printStackTrace(); + } + } else if (Utils.IS_VERBOSE) { + logMethod(method, "not compilable at " + compLevel); + } + } + + private void logMethod(Executable method, String message) { + StringBuilder builder = new StringBuilder("["); + builder.append(classId); + builder.append("]\t"); + builder.append(className); + builder.append("::"); + builder.append(method.getName()); + builder.append('('); + Class[] params = method.getParameterTypes(); + for (int i = 0, n = params.length - 1; i < n; ++i) { + builder.append(params[i].getName()); + builder.append(", "); + } + if (params.length != 0) { + builder.append(params[params.length - 1].getName()); + } + builder.append(')'); + if (message != null) { + builder.append('\t'); + builder.append(message); + } + System.err.println(builder); + } + } + +} diff --git a/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/PathHandler.java b/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/PathHandler.java new file mode 100644 index 00000000000..5c284f896a8 --- /dev/null +++ b/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/PathHandler.java @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2013, 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. + */ + +package sun.hotspot.tools.ctw; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.io.File; + +import java.util.Objects; +import java.util.regex.Pattern; +import java.util.regex.Matcher; +import java.util.concurrent.Executor; + +/** + * Abstract handler for path. + *

    + * Concrete subclasses should implement method {@link #process()}. + * + * @author igor.ignatyev@oracle.com + */ +public abstract class PathHandler { + private static final Pattern JAR_IN_DIR_PATTERN + = Pattern.compile("^(.*[/\\\\])?\\*$"); + protected final Path root; + protected final Executor executor; + private ClassLoader loader; + + /** + * @param root root path to process + * @param executor executor used for process task invocation + * @throws NullPointerException if {@code root} or {@code executor} is + * {@code null} + */ + protected PathHandler(Path root, Executor executor) { + Objects.requireNonNull(root); + Objects.requireNonNull(executor); + this.root = root.normalize(); + this.executor = executor; + this.loader = ClassLoader.getSystemClassLoader(); + } + + /** + * Factory method. Construct concrete handler in depends from {@code path}. + * + * @param path the path to process + * @param executor executor used for compile task invocation + * @throws NullPointerException if {@code path} or {@code executor} is + * {@code null} + */ + public static PathHandler create(String path, Executor executor) { + Objects.requireNonNull(path); + Objects.requireNonNull(executor); + Matcher matcher = JAR_IN_DIR_PATTERN.matcher(path); + if (matcher.matches()) { + path = matcher.group(1); + path = path.isEmpty() ? "." : path; + return new ClassPathJarInDirEntry(Paths.get(path), executor); + } else { + path = path.isEmpty() ? "." : path; + Path p = Paths.get(path); + if (isJarFile(p)) { + return new ClassPathJarEntry(p, executor); + } else if (isListFile(p)) { + return new ClassesListInFile(p, executor); + } else { + return new ClassPathDirEntry(p, executor); + } + } + } + + private static boolean isJarFile(Path path) { + if (Files.isRegularFile(path)) { + String name = path.toString(); + return Utils.endsWithIgnoreCase(name, ".zip") + || Utils.endsWithIgnoreCase(name, ".jar"); + } + return false; + } + + private static boolean isListFile(Path path) { + if (Files.isRegularFile(path)) { + String name = path.toString(); + return Utils.endsWithIgnoreCase(name, ".lst"); + } + return false; + } + + /** + * Processes all classes in specified path. + */ + public abstract void process(); + + /** + * Sets class loader, that will be used to define class at + * {@link #processClass(String)}. + * + * @param loader class loader + * @throws NullPointerException if {@code loader} is {@code null} + */ + protected final void setLoader(ClassLoader loader) { + Objects.requireNonNull(loader); + this.loader = loader; + } + + /** + * Processes specificed class. + * @param name fully qualified name of class to process + */ + protected final void processClass(String name) { + try { + Class aClass = Class.forName(name, true, loader); + Compiler.compileClass(aClass, executor); + } catch (ClassNotFoundException | LinkageError e) { + System.out.printf("Class %s loading failed : %s%n", name, + e.getMessage()); + } + } + + /** + * @return {@code true} if processing should be stopped + */ + public static boolean isFinished() { + return Compiler.isLimitReached(); + } + +} + diff --git a/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/Utils.java b/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/Utils.java new file mode 100644 index 00000000000..5ffd06cee8b --- /dev/null +++ b/hotspot/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/Utils.java @@ -0,0 +1,215 @@ +/* + * Copyright (c) 2013, 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. + */ + +package sun.hotspot.tools.ctw; + +import com.sun.management.HotSpotDiagnosticMXBean; +import sun.management.ManagementFactoryHelper; + +import java.io.File; +import java.util.regex.Pattern; + +/** + * Auxiliary methods. + * + * @author igor.ignatyev@oracle.com + */ +public class Utils { + /** + * Value of {@code -XX:CompileThreshold} + */ + public static final boolean TIERED_COMPILATION + = Boolean.parseBoolean(getVMOption("TieredCompilation", "false")); + /** + * Value of {@code -XX:BackgroundCompilation} + */ + public static final boolean BACKGROUND_COMPILATION + = Boolean.parseBoolean(getVMOption("BackgroundCompilation", + "false")); + /** + * Value of {@code -XX:TieredStopAtLevel} + */ + public static final int TIERED_STOP_AT_LEVEL; + /** + * Value of {@code -XX:CICompilerCount} + */ + public static final Integer CI_COMPILER_COUNT + = Integer.valueOf(getVMOption("CICompilerCount", "1")); + /** + * Initial compilation level. + */ + public static final int INITIAL_COMP_LEVEL; + /** + * Compiled path-separator regexp. + */ + public static final Pattern PATH_SEPARATOR = Pattern.compile( + File.pathSeparator, Pattern.LITERAL); + /** + * Value of {@code -DDeoptimizeAllClassesRate}. Frequency of + * {@code WB.deoptimizeAll()} invocation If it less that {@code 0}, + * {@code WB.deoptimizeAll()} will not be invoked. + */ + public static final int DEOPTIMIZE_ALL_CLASSES_RATE + = Integer.getInteger("DeoptimizeAllClassesRate", -1); + /** + * Value of {@code -DCompileTheWorldStopAt}. Last class to consider. + */ + public static final long COMPILE_THE_WORLD_STOP_AT + = Long.getLong("CompileTheWorldStopAt", Long.MAX_VALUE); + /** + * Value of {@code -DCompileTheWorldStartAt}. First class to consider. + */ + public static final long COMPILE_THE_WORLD_START_AT + = Long.getLong("CompileTheWorldStartAt", 1); + /** + * Value of {@code -DCompileTheWorldPreloadClasses}. Preload all classes + * used by a class before start loading. + */ + public static final boolean COMPILE_THE_WORLD_PRELOAD_CLASSES; + /** + * Value of {@code -Dsun.hotspot.tools.ctw.verbose}. Verbose output, + * adds additional information about compilation. + */ + public static final boolean IS_VERBOSE + = Boolean.getBoolean("sun.hotspot.tools.ctw.verbose"); + /** + * Value of {@code -Dsun.hotspot.tools.ctw.logfile}.Path to logfile, if + * it's null, cout will be used. + */ + public static final String LOG_FILE + = System.getProperty("sun.hotspot.tools.ctw.logfile"); + static { + if (Utils.TIERED_COMPILATION) { + INITIAL_COMP_LEVEL = 1; + } else { + String vmName = System.getProperty("java.vm.name"); + if (Utils.endsWithIgnoreCase(vmName, " Server VM")) { + INITIAL_COMP_LEVEL = 4; + } else if (Utils.endsWithIgnoreCase(vmName, " Client VM") + || Utils.endsWithIgnoreCase(vmName, " Minimal VM")) { + INITIAL_COMP_LEVEL = 1; + } else { + throw new RuntimeException("Unknown VM: " + vmName); + } + } + + TIERED_STOP_AT_LEVEL = Integer.parseInt(getVMOption("TieredStopAtLevel", + String.valueOf(INITIAL_COMP_LEVEL))); + } + + static { + String tmp = System.getProperty("CompileTheWorldPreloadClasses"); + if (tmp == null) { + COMPILE_THE_WORLD_PRELOAD_CLASSES = true; + } else { + COMPILE_THE_WORLD_PRELOAD_CLASSES = Boolean.parseBoolean(tmp); + } + } + + public static final String CLASSFILE_EXT = ".class"; + + private Utils() { + } + + /** + * Tests if the string ends with the suffix, ignoring case + * considerations + * + * @param string the tested string + * @param suffix the suffix + * @return {@code true} if {@code string} ends with the {@code suffix} + * @see String#endsWith(String) + */ + public static boolean endsWithIgnoreCase(String string, String suffix) { + if (string == null || suffix == null) { + return false; + } + int length = suffix.length(); + int toffset = string.length() - length; + if (toffset < 0) { + return false; + } + return string.regionMatches(true, toffset, suffix, 0, length); + } + + /** + * Returns value of VM option. + * + * @param name option's name + * @return value of option or {@code null}, if option doesn't exist + * @throws NullPointerException if name is null + */ + public static String getVMOption(String name) { + String result; + HotSpotDiagnosticMXBean diagnostic + = ManagementFactoryHelper.getDiagnosticMXBean(); + result = diagnostic.getVMOption(name).getValue(); + return result; + } + + /** + * Returns value of VM option or default value. + * + * @param name option's name + * @param defaultValue default value + * @return value of option or {@code defaultValue}, if option doesn't exist + * @throws NullPointerException if name is null + * @see #getVMOption(String) + */ + public static String getVMOption(String name, String defaultValue) { + String result; + try { + result = getVMOption(name); + } catch (NoClassDefFoundError e) { + // compact1, compact2 support + result = defaultValue; + } + return result == null ? defaultValue : result; + } + + /** + * Tests if the filename is valid filename for class file. + * + * @param filename tested filename + */ + public static boolean isClassFile(String filename) { + // If the filename has a period after removing '.class', it's not valid class file + return endsWithIgnoreCase(filename, CLASSFILE_EXT) + && (filename.indexOf('.') + == (filename.length() - CLASSFILE_EXT.length())); + } + + /** + * Converts the filename to classname. + * + * @param filename filename to convert + * @return corresponding classname. + * @throws AssertionError if filename isn't valid filename for class file - + * {@link #isClassFile(String)} + */ + public static String fileNameToClassName(String filename) { + assert isClassFile(filename); + return filename.substring(0, filename.length() - CLASSFILE_EXT.length()) + .replace(File.separatorChar, '.'); + } +} diff --git a/hotspot/test/testlibrary/ctw/test/Bar.java b/hotspot/test/testlibrary/ctw/test/Bar.java new file mode 100644 index 00000000000..9b0324555f8 --- /dev/null +++ b/hotspot/test/testlibrary/ctw/test/Bar.java @@ -0,0 +1,5 @@ +public class Bar { + private static void staticMethod() { } + public void method() { } + protected Bar() { } +} diff --git a/hotspot/test/testlibrary/ctw/test/ClassesDirTest.java b/hotspot/test/testlibrary/ctw/test/ClassesDirTest.java new file mode 100644 index 00000000000..ae5eaf0f2e4 --- /dev/null +++ b/hotspot/test/testlibrary/ctw/test/ClassesDirTest.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2013, 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 ClassesDirTest + * @bug 8012447 + * @library /testlibrary /testlibrary/whitebox /testlibrary/ctw/src + * @build sun.hotspot.tools.ctw.CompileTheWorld sun.hotspot.WhiteBox ClassesDirTest Foo Bar + * @run main ClassFileInstaller sun.hotspot.WhiteBox Foo Bar + * @run main ClassesDirTest prepare + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Dsun.hotspot.tools.ctw.logfile=ctw.log sun.hotspot.tools.ctw.CompileTheWorld classes + * @run main ClassesDirTest check ctw.log + * @summary testing of CompileTheWorld :: classes in directory + * @author igor.ignatyev@oracle.com + */ + +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; + +public class ClassesDirTest extends CtwTest { + private static final String[] SHOULD_CONTAIN + = {"# dir: classes", "Done (2 classes, 6 methods, "}; + + private ClassesDirTest() { + super(SHOULD_CONTAIN); + } + + public static void main(String[] args) throws Exception { + new ClassesDirTest().run(args); + } + + protected void prepare() throws Exception { + String path = "classes"; + Files.createDirectory(Paths.get(path)); + Files.move(Paths.get("Foo.class"), Paths.get(path, "Foo.class"), + StandardCopyOption.REPLACE_EXISTING); + Files.move(Paths.get("Bar.class"), Paths.get(path, "Bar.class"), + StandardCopyOption.REPLACE_EXISTING); + } +} diff --git a/hotspot/test/testlibrary/ctw/test/ClassesListTest.java b/hotspot/test/testlibrary/ctw/test/ClassesListTest.java new file mode 100644 index 00000000000..a98cd53a3f6 --- /dev/null +++ b/hotspot/test/testlibrary/ctw/test/ClassesListTest.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2013, 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 ClassesListTest + * @bug 8012447 + * @library /testlibrary /testlibrary/whitebox /testlibrary/ctw/src + * @build sun.hotspot.tools.ctw.CompileTheWorld sun.hotspot.WhiteBox ClassesListTest Foo Bar + * @run main ClassFileInstaller sun.hotspot.WhiteBox Foo Bar + * @run main ClassesListTest prepare + * @run main/othervm/timeout=600 -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Dsun.hotspot.tools.ctw.logfile=ctw.log sun.hotspot.tools.ctw.CompileTheWorld classes.lst + * @run main ClassesListTest check ctw.log + * @summary testing of CompileTheWorld :: list of classes in file + * @author igor.ignatyev@oracle.com + */ + +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; + +public class ClassesListTest extends CtwTest { + private static final String[] SHOULD_CONTAIN + = {"# list: classes.lst", "Done (4 classes, "}; + + private ClassesListTest() { + super(SHOULD_CONTAIN); + } + + public static void main(String[] args) throws Exception { + new ClassesListTest().run(args); + } + + protected void prepare() throws Exception { + String path = "classes.lst"; + Files.copy(Paths.get(System.getProperty("test.src"), path), + Paths.get(path), StandardCopyOption.REPLACE_EXISTING); + } +} diff --git a/hotspot/test/testlibrary/ctw/test/CtwTest.java b/hotspot/test/testlibrary/ctw/test/CtwTest.java new file mode 100644 index 00000000000..ecc9c59c13a --- /dev/null +++ b/hotspot/test/testlibrary/ctw/test/CtwTest.java @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2013, 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.List; +import java.util.Collections; +import java.util.ArrayList; + +import java.io.File; +import java.io.Writer; +import java.io.FileWriter; +import java.io.IOException; +import java.io.BufferedReader; + +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; +import java.nio.charset.Charset; + +import com.oracle.java.testlibrary.JDKToolFinder; +import com.oracle.java.testlibrary.OutputAnalyzer; + +public abstract class CtwTest { + protected final String[] shouldContain; + protected CtwTest(String[] shouldContain) { + this.shouldContain = shouldContain; + } + + public void run(String[] args) throws Exception { + if (args.length == 0) { + throw new Error("args is empty"); + } + switch (args[0]) { + case "prepare": + prepare(); + break; + case "check": + check(args); + break; + default: + throw new Error("unregonized action -- " + args[0]); + } + } + + protected void prepare() throws Exception { } + + protected void check(String[] args) throws Exception { + if (args.length < 2) { + throw new Error("logfile isn't specified"); + } + String logfile = args[1]; + try (BufferedReader r = Files.newBufferedReader(Paths.get(logfile), + Charset.defaultCharset())) { + OutputAnalyzer output = readOutput(r); + for (String test : shouldContain) { + output.shouldContain(test); + } + } + } + + private static OutputAnalyzer readOutput(BufferedReader reader) + throws IOException { + StringBuilder builder = new StringBuilder(); + String eol = String.format("%n"); + String line; + + while ((line = reader.readLine()) != null) { + builder.append(line); + builder.append(eol); + } + return new OutputAnalyzer(builder.toString(), ""); + } + + protected void dump(OutputAnalyzer output, String name) { + try (Writer w = new FileWriter(name + ".out")) { + String s = output.getStdout(); + w.write(s, s.length(), 0); + } catch (IOException io) { + io.printStackTrace(); + } + try (Writer w = new FileWriter(name + ".err")) { + String s = output.getStderr(); + w.write(s, s.length(), 0); + } catch (IOException io) { + io.printStackTrace(); + } + } + + protected ProcessBuilder createJarProcessBuilder(String... command) + throws Exception { + String javapath = JDKToolFinder.getJDKTool("jar"); + + ArrayList args = new ArrayList<>(); + args.add(javapath); + Collections.addAll(args, command); + + return new ProcessBuilder(args.toArray(new String[args.size()])); + } +} diff --git a/hotspot/test/testlibrary/ctw/test/Foo.java b/hotspot/test/testlibrary/ctw/test/Foo.java new file mode 100644 index 00000000000..07d8f4643ce --- /dev/null +++ b/hotspot/test/testlibrary/ctw/test/Foo.java @@ -0,0 +1,5 @@ +public class Foo { + private static void staticMethod() { } + public void method() { } + protected Foo() { } +} diff --git a/hotspot/test/testlibrary/ctw/test/JarDirTest.java b/hotspot/test/testlibrary/ctw/test/JarDirTest.java new file mode 100644 index 00000000000..76f682fd755 --- /dev/null +++ b/hotspot/test/testlibrary/ctw/test/JarDirTest.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2013, 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 JarDirTest + * @bug 8012447 + * @library /testlibrary /testlibrary/whitebox /testlibrary/ctw/src + * @build sun.hotspot.tools.ctw.CompileTheWorld sun.hotspot.WhiteBox JarDirTest Foo Bar + * @run main ClassFileInstaller sun.hotspot.WhiteBox Foo Bar + * @run main JarDirTest prepare + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Dsun.hotspot.tools.ctw.logfile=ctw.log sun.hotspot.tools.ctw.CompileTheWorld jars/* + * @run main JarDirTest check ctw.log + * @summary testing of CompileTheWorld :: jars in directory + * @author igor.ignatyev@oracle.com + */ + +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Paths; + +import com.oracle.java.testlibrary.OutputAnalyzer; + +public class JarDirTest extends CtwTest { + private static final String[] SHOULD_CONTAIN + = {"# jar_in_dir: jars", + "# jar: jars" + File.separator +"foo.jar", + "# jar: jars" + File.separator +"bar.jar", + "Done (4 classes, 12 methods, "}; + + private JarDirTest() { + super(SHOULD_CONTAIN); + } + + public static void main(String[] args) throws Exception { + new JarDirTest().run(args); + } + + protected void prepare() throws Exception { + String path = "jars"; + Files.createDirectory(Paths.get(path)); + + ProcessBuilder pb = createJarProcessBuilder("cf", "jars/foo.jar", + "Foo.class", "Bar.class"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + dump(output, "ctw-foo.jar"); + output.shouldHaveExitValue(0); + + pb = createJarProcessBuilder("cf", "jars/bar.jar", "Foo.class", + "Bar.class"); + output = new OutputAnalyzer(pb.start()); + dump(output, "ctw-bar.jar"); + output.shouldHaveExitValue(0); + } + +} diff --git a/hotspot/test/testlibrary/ctw/test/JarsTest.java b/hotspot/test/testlibrary/ctw/test/JarsTest.java new file mode 100644 index 00000000000..04792729f4e --- /dev/null +++ b/hotspot/test/testlibrary/ctw/test/JarsTest.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2013, 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 JarsTest + * @bug 8012447 + * @library /testlibrary /testlibrary/whitebox /testlibrary/ctw/src + * @build sun.hotspot.tools.ctw.CompileTheWorld sun.hotspot.WhiteBox JarsTest Foo Bar + * @run main ClassFileInstaller sun.hotspot.WhiteBox Foo Bar + * @run main JarsTest prepare + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Dsun.hotspot.tools.ctw.logfile=ctw.log sun.hotspot.tools.ctw.CompileTheWorld foo.jar bar.jar + * @run main JarsTest check ctw.log + * @summary testing of CompileTheWorld :: jars + * @author igor.ignatyev@oracle.com + */ + +import com.oracle.java.testlibrary.OutputAnalyzer; + +public class JarsTest extends CtwTest { + private static final String[] SHOULD_CONTAIN + = {"# jar: foo.jar", "# jar: bar.jar", + "Done (4 classes, 12 methods, "}; + + private JarsTest() { + super(SHOULD_CONTAIN); + } + + public static void main(String[] args) throws Exception { + new JarsTest().run(args); + } + + protected void prepare() throws Exception { + ProcessBuilder pb = createJarProcessBuilder("cf", "foo.jar", + "Foo.class", "Bar.class"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + dump(output, "ctw-foo.jar"); + output.shouldHaveExitValue(0); + + pb = createJarProcessBuilder("cf", "bar.jar", "Foo.class", "Bar.class"); + output = new OutputAnalyzer(pb.start()); + dump(output, "ctw-bar.jar"); + output.shouldHaveExitValue(0); + } + +} diff --git a/hotspot/test/testlibrary/ctw/test/classes.lst b/hotspot/test/testlibrary/ctw/test/classes.lst new file mode 100644 index 00000000000..044c029e783 --- /dev/null +++ b/hotspot/test/testlibrary/ctw/test/classes.lst @@ -0,0 +1,4 @@ +java.lang.String +java.lang.Object +Foo +Bar diff --git a/hotspot/test/testlibrary/whitebox/Makefile b/hotspot/test/testlibrary/whitebox/Makefile new file mode 100644 index 00000000000..8a84a0a4492 --- /dev/null +++ b/hotspot/test/testlibrary/whitebox/Makefile @@ -0,0 +1,63 @@ +# +# Copyright (c) 2013, 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. +# +# + +ifneq "x$(ALT_BOOTDIR)" "x" + BOOTDIR := $(ALT_BOOTDIR) +endif + +ifeq "x$(BOOTDIR)" "x" + JDK_HOME := $(shell dirname $(shell which java))/.. +else + JDK_HOME := $(BOOTDIR) +endif + +SRC_DIR = ./ +BUILD_DIR = build +OUTPUT_DIR = $(BUILD_DIR)/classes + +JAVAC = $(JDK_HOME)/bin/javac +JAR = $(JDK_HOME)/bin/jar + +SRC_FILES = $(shell find $(SRC_DIR) -name '*.java') + +.PHONY: filelist clean cleantmp + +all: wb.jar cleantmp + +wb.jar: filelist + @mkdir -p $(OUTPUT_DIR) + $(JAVAC) -sourcepath $(SRC_DIR) -d $(OUTPUT_DIR) -cp $(OUTPUT_DIR) @filelist + $(JAR) cf wb.jar -C $(OUTPUT_DIR) . + @rm -rf $(OUTPUT_DIR) + +filelist: $(SRC_FILES) + @rm -f $@ + @echo $(SRC_FILES) > $@ + +clean: cleantmp + @rm -rf wb.jar + +cleantmp: + @rm -rf filelist + @rm -rf $(BUILD_DIR) From 9c6d420370b76c367d9abf96cedaa54123d513e2 Mon Sep 17 00:00:00 2001 From: Bhavesh Patel Date: Thu, 5 Sep 2013 16:35:47 -0700 Subject: [PATCH 098/210] 8023608: method grouping tabs folding issue Reviewed-by: jjg --- .../internal/toolkit/resources/stylesheet.css | 12 ++---- .../testStylesheet/TestStylesheet.java | 43 ++++++++++++++++++- 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/resources/stylesheet.css b/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/resources/stylesheet.css index c264d66b303..bf1bc9441de 100644 --- a/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/resources/stylesheet.css +++ b/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/resources/stylesheet.css @@ -378,7 +378,6 @@ Table styles overflow:hidden; padding:0px; margin:0px; - white-space:pre; } caption a:link, caption a:hover, caption a:active, caption a:visited { color:#FFFFFF; @@ -387,35 +386,32 @@ caption a:link, caption a:hover, caption a:active, caption a:visited { white-space:nowrap; padding-top:8px; padding-left:8px; - display:block; + display:inline-block; float:left; background-image:url(resources/titlebar.gif); - height:18px; } .contentContainer ul.blockList li.blockList caption span.activeTableTab span { white-space:nowrap; padding-top:8px; padding-left:8px; - display:block; + display:inline-block; float:left; background-image:url(resources/activetitlebar.gif); - height:18px; } .contentContainer ul.blockList li.blockList caption span.tableTab span { white-space:nowrap; padding-top:8px; padding-left:8px; - display:block; + display:inline-block; float:left; background-image:url(resources/titlebar.gif); - height:18px; } .contentContainer ul.blockList li.blockList caption span.tableTab, .contentContainer ul.blockList li.blockList caption span.activeTableTab { padding-top:0px; padding-left:0px; background-image:none; float:none; - display:inline; + display:inline-block; } .overviewSummary .tabEnd, .packageSummary .tabEnd, .contentContainer ul.blockList li.blockList .tabEnd, .summary .tabEnd, .classUseContainer .tabEnd, .constantValuesContainer .tabEnd { width:10px; diff --git a/langtools/test/com/sun/javadoc/testStylesheet/TestStylesheet.java b/langtools/test/com/sun/javadoc/testStylesheet/TestStylesheet.java index c4044a53d91..b6192fb8959 100644 --- a/langtools/test/com/sun/javadoc/testStylesheet/TestStylesheet.java +++ b/langtools/test/com/sun/javadoc/testStylesheet/TestStylesheet.java @@ -23,7 +23,7 @@ /* * @test - * @bug 4494033 7028815 7052425 8007338 + * @bug 4494033 7028815 7052425 8007338 8023608 * @summary Run tests on doclet stylesheet. * @author jamieh * @library ../lib/ @@ -72,7 +72,46 @@ public class TestStylesheet extends JavadocTester { " overflow:hidden;" + NL + " padding:0px;" + NL + " margin:0px;" + NL + - " white-space:pre;" + NL + + "}"}, + {BUG_ID + FS + "stylesheet.css", + ".overviewSummary caption span, .packageSummary caption span, " + + ".contentContainer ul.blockList li.blockList caption span, " + + ".summary caption span, .classUseContainer caption span, " + + ".constantValuesContainer caption span {" + NL + + " white-space:nowrap;" + NL + + " padding-top:8px;" + NL + + " padding-left:8px;" + NL + + " display:inline-block;" + NL + + " float:left;" + NL + + " background-image:url(resources/titlebar.gif);" + NL + + "}"}, + {BUG_ID + FS + "stylesheet.css", + ".contentContainer ul.blockList li.blockList caption " + + "span.activeTableTab span {" + NL + + " white-space:nowrap;" + NL + + " padding-top:8px;" + NL + + " padding-left:8px;" + NL + + " display:inline-block;" + NL + + " float:left;" + NL + + " background-image:url(resources/activetitlebar.gif);" + NL + + "}"}, + {BUG_ID + FS + "stylesheet.css", + ".contentContainer ul.blockList li.blockList caption span.tableTab span {" + NL + + " white-space:nowrap;" + NL + + " padding-top:8px;" + NL + + " padding-left:8px;" + NL + + " display:inline-block;" + NL + + " float:left;" + NL + + " background-image:url(resources/titlebar.gif);" + NL + + "}"}, + {BUG_ID + FS + "stylesheet.css", + ".contentContainer ul.blockList li.blockList caption span.tableTab, " + + ".contentContainer ul.blockList li.blockList caption span.activeTableTab {" + NL + + " padding-top:0px;" + NL + + " padding-left:0px;" + NL + + " background-image:none;" + NL + + " float:none;" + NL + + " display:inline-block;" + NL + "}"}, // Test whether a link to the stylesheet file is inserted properly // in the class documentation. From 26758f0ffd85e47f8f36bc567bea08c0957efe7b Mon Sep 17 00:00:00 2001 From: Vicente Romero Date: Fri, 6 Sep 2013 09:53:24 +0100 Subject: [PATCH 099/210] 8024039: javac, previous solution for JDK-8022186 was incorrect Reviewed-by: jjg --- .../com/sun/tools/javac/comp/Lower.java | 20 ++- .../classes/com/sun/tools/javac/jvm/Gen.java | 124 ++++++++---------- .../NoDeadCodeGenerationOnTrySmtTest.java | 124 ++++++++++++++++++ 3 files changed, 197 insertions(+), 71 deletions(-) create mode 100644 langtools/test/tools/javac/T8024039/NoDeadCodeGenerationOnTrySmtTest.java diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/Lower.java b/langtools/src/share/classes/com/sun/tools/javac/comp/Lower.java index 75e1d388666..7094d64b19c 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Lower.java +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Lower.java @@ -49,7 +49,6 @@ import static com.sun.tools.javac.code.Kinds.*; import static com.sun.tools.javac.code.TypeTag.*; import static com.sun.tools.javac.jvm.ByteCodes.*; import static com.sun.tools.javac.tree.JCTree.Tag.*; -import javax.lang.model.type.TypeKind; /** This pass translates away some syntactic sugar: inner classes, * class literals, assertions, foreach loops, etc. @@ -3830,15 +3829,26 @@ public class Lower extends TreeTranslator { @Override public void visitTry(JCTry tree) { - /* special case of try without catchers and with finally emtpy. - * Don't give it a try, translate only the body. - */ if (tree.resources.isEmpty()) { + /* special case of try without catchers and with finally emtpy. + * Don't give it a try, translate only the body. + */ if (tree.catchers.isEmpty() && tree.finalizer.getStatements().isEmpty()) { result = translate(tree.body); } else { - super.visitTry(tree); + /* also if the body is empty we only need to generate the finalizer + * provided that it's not empty. + */ + if (tree.body.getStatements().isEmpty()) { + if (tree.finalizer.getStatements().isEmpty()) { + result = translate(tree.body); + } else { + result = translate(tree.finalizer); + } + } else { + super.visitTry(tree); + } } } else { result = makeTwrTry(tree); diff --git a/langtools/src/share/classes/com/sun/tools/javac/jvm/Gen.java b/langtools/src/share/classes/com/sun/tools/javac/jvm/Gen.java index cc438a73510..3f0fc861da3 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/jvm/Gen.java +++ b/langtools/src/share/classes/com/sun/tools/javac/jvm/Gen.java @@ -1478,82 +1478,74 @@ public class Gen extends JCTree.Visitor { code.statBegin(TreeInfo.endPos(body)); genFinalizer(env); code.statBegin(TreeInfo.endPos(env.tree)); - Chain exitChain; - if (startpc != endpc) { - exitChain = code.branch(goto_); - } else { - exitChain = code.branch(dontgoto); - } + Chain exitChain = code.branch(goto_); endFinalizerGap(env); - if (startpc != endpc) { - for (List l = catchers; l.nonEmpty(); l = l.tail) { - // start off with exception on stack - code.entryPoint(stateTry, l.head.param.sym.type); - genCatch(l.head, env, startpc, endpc, gaps); - genFinalizer(env); - if (hasFinalizer || l.tail.nonEmpty()) { - code.statBegin(TreeInfo.endPos(env.tree)); - exitChain = Code.mergeChains(exitChain, - code.branch(goto_)); - } - endFinalizerGap(env); + if (startpc != endpc) for (List l = catchers; l.nonEmpty(); l = l.tail) { + // start off with exception on stack + code.entryPoint(stateTry, l.head.param.sym.type); + genCatch(l.head, env, startpc, endpc, gaps); + genFinalizer(env); + if (hasFinalizer || l.tail.nonEmpty()) { + code.statBegin(TreeInfo.endPos(env.tree)); + exitChain = Code.mergeChains(exitChain, + code.branch(goto_)); } + endFinalizerGap(env); + } + if (hasFinalizer) { + // Create a new register segement to avoid allocating + // the same variables in finalizers and other statements. + code.newRegSegment(); - if (hasFinalizer) { - // Create a new register segement to avoid allocating - // the same variables in finalizers and other statements. - code.newRegSegment(); + // Add a catch-all clause. - // Add a catch-all clause. + // start off with exception on stack + int catchallpc = code.entryPoint(stateTry, syms.throwableType); - // start off with exception on stack - int catchallpc = code.entryPoint(stateTry, syms.throwableType); + // Register all exception ranges for catch all clause. + // The range of the catch all clause is from the beginning + // of the try or synchronized block until the present + // code pointer excluding all gaps in the current + // environment's GenContext. + int startseg = startpc; + while (env.info.gaps.nonEmpty()) { + int endseg = env.info.gaps.next().intValue(); + registerCatch(body.pos(), startseg, endseg, + catchallpc, 0); + startseg = env.info.gaps.next().intValue(); + } + code.statBegin(TreeInfo.finalizerPos(env.tree)); + code.markStatBegin(); - // Register all exception ranges for catch all clause. - // The range of the catch all clause is from the beginning - // of the try or synchronized block until the present - // code pointer excluding all gaps in the current - // environment's GenContext. - int startseg = startpc; - while (env.info.gaps.nonEmpty()) { - int endseg = env.info.gaps.next().intValue(); - registerCatch(body.pos(), startseg, endseg, - catchallpc, 0); - startseg = env.info.gaps.next().intValue(); - } + Item excVar = makeTemp(syms.throwableType); + excVar.store(); + genFinalizer(env); + excVar.load(); + registerCatch(body.pos(), startseg, + env.info.gaps.next().intValue(), + catchallpc, 0); + code.emitop0(athrow); + code.markDead(); + + // If there are jsr's to this finalizer, ... + if (env.info.cont != null) { + // Resolve all jsr's. + code.resolve(env.info.cont); + + // Mark statement line number code.statBegin(TreeInfo.finalizerPos(env.tree)); code.markStatBegin(); - Item excVar = makeTemp(syms.throwableType); - excVar.store(); - genFinalizer(env); - excVar.load(); - registerCatch(body.pos(), startseg, - env.info.gaps.next().intValue(), - catchallpc, 0); - code.emitop0(athrow); + // Save return address. + LocalItem retVar = makeTemp(syms.throwableType); + retVar.store(); + + // Generate finalizer code. + env.info.finalize.genLast(); + + // Return. + code.emitop1w(ret, retVar.reg); code.markDead(); - - // If there are jsr's to this finalizer, ... - if (env.info.cont != null) { - // Resolve all jsr's. - code.resolve(env.info.cont); - - // Mark statement line number - code.statBegin(TreeInfo.finalizerPos(env.tree)); - code.markStatBegin(); - - // Save return address. - LocalItem retVar = makeTemp(syms.throwableType); - retVar.store(); - - // Generate finalizer code. - env.info.finalize.genLast(); - - // Return. - code.emitop1w(ret, retVar.reg); - code.markDead(); - } } } // Resolve all breaks. diff --git a/langtools/test/tools/javac/T8024039/NoDeadCodeGenerationOnTrySmtTest.java b/langtools/test/tools/javac/T8024039/NoDeadCodeGenerationOnTrySmtTest.java new file mode 100644 index 00000000000..0dd25871f3a --- /dev/null +++ b/langtools/test/tools/javac/T8024039/NoDeadCodeGenerationOnTrySmtTest.java @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2013, 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. + */ + +/* + * @test + * @bug 8024039 + * @summary javac, previous solution for JDK-8022186 was incorrect + * @library /tools/javac/lib + * @build ToolBox + * @run main NoDeadCodeGenerationOnTrySmtTest + */ + +import java.io.File; +import java.nio.file.Paths; + +import com.sun.tools.classfile.ClassFile; +import com.sun.tools.classfile.Code_attribute; +import com.sun.tools.classfile.Code_attribute.Exception_data; +import com.sun.tools.classfile.Method; +import com.sun.tools.javac.util.Assert; + +public class NoDeadCodeGenerationOnTrySmtTest { + + static final String testSource = + "public class Test {\n" + + " void m1(int arg) {\n" + + " synchronized (new Integer(arg)) {\n" + + " {\n" + + " label0:\n" + + " do {\n" + + " break label0;\n" + + " } while (arg != 0);\n" + + " }\n" + + " }\n" + + " }\n" + + + " void m2(int arg) {\n" + + " synchronized (new Integer(arg)) {\n" + + " {\n" + + " label0:\n" + + " {\n" + + " break label0;\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}"; + + static final int[][] expectedExceptionTable = { + // {from, to, target, type}, + {11, 13, 16, 0}, + {16, 19, 16, 0} + }; + + static final String[] methodsToLookFor = {"m1", "m2"}; + + public static void main(String[] args) throws Exception { + new NoDeadCodeGenerationOnTrySmtTest().run(); + } + + void run() throws Exception { + compileTestClass(); + checkClassFile(new File(Paths.get(System.getProperty("user.dir"), + "Test.class").toUri()), methodsToLookFor); + } + + void compileTestClass() throws Exception { + ToolBox.JavaToolArgs javacSuccessArgs = + new ToolBox.JavaToolArgs().setSources(testSource); + ToolBox.javac(javacSuccessArgs); + } + + void checkClassFile(final File cfile, String[] methodsToFind) throws Exception { + ClassFile classFile = ClassFile.read(cfile); + int numberOfmethodsFound = 0; + for (String methodToFind : methodsToFind) { + for (Method method : classFile.methods) { + if (method.getName(classFile.constant_pool).equals(methodToFind)) { + numberOfmethodsFound++; + Code_attribute code = (Code_attribute) method.attributes.get("Code"); + Assert.check(code.exception_table_langth == expectedExceptionTable.length, + "The ExceptionTable found has a length different to the expected one"); + int i = 0; + for (Exception_data entry: code.exception_table) { + Assert.check(entry.start_pc == expectedExceptionTable[i][0] && + entry.end_pc == expectedExceptionTable[i][1] && + entry.handler_pc == expectedExceptionTable[i][2] && + entry.catch_type == expectedExceptionTable[i][3], + "Exception table entry at pos " + i + " differ from expected."); + i++; + } + } + } + } + Assert.check(numberOfmethodsFound == 2, "Some seek methods were not found"); + } + + void error(String msg) { + throw new AssertionError(msg); + } + +} From 1c2a7eea85ea261102687190d6b2e92c560770b8 Mon Sep 17 00:00:00 2001 From: Ioi Lam Date: Fri, 6 Sep 2013 08:42:42 -0700 Subject: [PATCH 100/210] 8022335: Native stack walk while generating hs_err does not work on Windows x64 Use WinDbg API StackWalk64() Reviewed-by: zgu, dholmes --- hotspot/src/os/windows/vm/decoder_windows.cpp | 91 +++++++++++++++++- hotspot/src/os/windows/vm/decoder_windows.hpp | 41 +++++++++ .../os_cpu/windows_x86/vm/os_windows_x86.cpp | 92 +++++++++++++++++++ .../os_cpu/windows_x86/vm/os_windows_x86.hpp | 6 ++ hotspot/src/share/vm/runtime/frame.cpp | 2 +- hotspot/src/share/vm/runtime/frame.hpp | 1 + hotspot/src/share/vm/runtime/os.hpp | 8 ++ hotspot/src/share/vm/utilities/decoder.cpp | 18 +++- hotspot/src/share/vm/utilities/decoder.hpp | 14 +++ hotspot/src/share/vm/utilities/vmError.cpp | 5 + hotspot/src/share/vm/utilities/vmError.hpp | 4 + 11 files changed, 275 insertions(+), 7 deletions(-) diff --git a/hotspot/src/os/windows/vm/decoder_windows.cpp b/hotspot/src/os/windows/vm/decoder_windows.cpp index 326d3288020..b99adaa9f4f 100644 --- a/hotspot/src/os/windows/vm/decoder_windows.cpp +++ b/hotspot/src/os/windows/vm/decoder_windows.cpp @@ -32,7 +32,11 @@ WindowsDecoder::WindowsDecoder() { _can_decode_in_vm = false; _pfnSymGetSymFromAddr64 = NULL; _pfnUndecorateSymbolName = NULL; - +#ifdef AMD64 + _pfnStackWalk64 = NULL; + _pfnSymFunctionTableAccess64 = NULL; + _pfnSymGetModuleBase64 = NULL; +#endif _decoder_status = no_error; initialize(); } @@ -53,14 +57,24 @@ void WindowsDecoder::initialize() { _pfnUndecorateSymbolName = (pfn_UndecorateSymbolName)::GetProcAddress(handle, "UnDecorateSymbolName"); if (_pfnSymSetOptions == NULL || _pfnSymInitialize == NULL || _pfnSymGetSymFromAddr64 == NULL) { - _pfnSymGetSymFromAddr64 = NULL; - _pfnUndecorateSymbolName = NULL; - ::FreeLibrary(handle); - _dbghelp_handle = NULL; + uninitialize(); _decoder_status = helper_func_error; return; } +#ifdef AMD64 + _pfnStackWalk64 = (pfn_StackWalk64)::GetProcAddress(handle, "StackWalk64"); + _pfnSymFunctionTableAccess64 = (pfn_SymFunctionTableAccess64)::GetProcAddress(handle, "SymFunctionTableAccess64"); + _pfnSymGetModuleBase64 = (pfn_SymGetModuleBase64)::GetProcAddress(handle, "SymGetModuleBase64"); + if (_pfnStackWalk64 == NULL || _pfnSymFunctionTableAccess64 == NULL || _pfnSymGetModuleBase64 == NULL) { + // We can't call StackWalk64 to walk the stack, but we are still + // able to decode the symbols. Let's limp on. + _pfnStackWalk64 = NULL; + _pfnSymFunctionTableAccess64 = NULL; + _pfnSymGetModuleBase64 = NULL; + } +#endif + HANDLE hProcess = ::GetCurrentProcess(); _pfnSymSetOptions(SYMOPT_UNDNAME | SYMOPT_DEFERRED_LOADS | SYMOPT_EXACT_SYMBOLS); if (!_pfnSymInitialize(hProcess, NULL, TRUE)) { @@ -156,6 +170,11 @@ void WindowsDecoder::initialize() { void WindowsDecoder::uninitialize() { _pfnSymGetSymFromAddr64 = NULL; _pfnUndecorateSymbolName = NULL; +#ifdef AMD64 + _pfnStackWalk64 = NULL; + _pfnSymFunctionTableAccess64 = NULL; + _pfnSymGetModuleBase64 = NULL; +#endif if (_dbghelp_handle != NULL) { ::FreeLibrary(_dbghelp_handle); } @@ -195,3 +214,65 @@ bool WindowsDecoder::demangle(const char* symbol, char *buf, int buflen) { _pfnUndecorateSymbolName(symbol, buf, buflen, UNDNAME_COMPLETE); } +#ifdef AMD64 +BOOL WindowsDbgHelp::StackWalk64(DWORD MachineType, + HANDLE hProcess, + HANDLE hThread, + LPSTACKFRAME64 StackFrame, + PVOID ContextRecord, + PREAD_PROCESS_MEMORY_ROUTINE64 ReadMemoryRoutine, + PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine, + PGET_MODULE_BASE_ROUTINE64 GetModuleBaseRoutine, + PTRANSLATE_ADDRESS_ROUTINE64 TranslateAddress) { + DecoderLocker locker; + WindowsDecoder* wd = (WindowsDecoder*)locker.decoder(); + + if (!wd->has_error() && wd->_pfnStackWalk64) { + return wd->_pfnStackWalk64(MachineType, + hProcess, + hThread, + StackFrame, + ContextRecord, + ReadMemoryRoutine, + FunctionTableAccessRoutine, + GetModuleBaseRoutine, + TranslateAddress); + } else { + return false; + } +} + +PVOID WindowsDbgHelp::SymFunctionTableAccess64(HANDLE hProcess, DWORD64 AddrBase) { + DecoderLocker locker; + WindowsDecoder* wd = (WindowsDecoder*)locker.decoder(); + + if (!wd->has_error() && wd->_pfnSymFunctionTableAccess64) { + return wd->_pfnSymFunctionTableAccess64(hProcess, AddrBase); + } else { + return NULL; + } +} + +pfn_SymFunctionTableAccess64 WindowsDbgHelp::pfnSymFunctionTableAccess64() { + DecoderLocker locker; + WindowsDecoder* wd = (WindowsDecoder*)locker.decoder(); + + if (!wd->has_error()) { + return wd->_pfnSymFunctionTableAccess64; + } else { + return NULL; + } +} + +pfn_SymGetModuleBase64 WindowsDbgHelp::pfnSymGetModuleBase64() { + DecoderLocker locker; + WindowsDecoder* wd = (WindowsDecoder*)locker.decoder(); + + if (!wd->has_error()) { + return wd->_pfnSymGetModuleBase64; + } else { + return NULL; + } +} + +#endif // AMD64 diff --git a/hotspot/src/os/windows/vm/decoder_windows.hpp b/hotspot/src/os/windows/vm/decoder_windows.hpp index 3008ee79136..2555e8c9b79 100644 --- a/hotspot/src/os/windows/vm/decoder_windows.hpp +++ b/hotspot/src/os/windows/vm/decoder_windows.hpp @@ -38,6 +38,20 @@ typedef DWORD (WINAPI *pfn_UndecorateSymbolName)(const char*, char*, DWORD, DWOR typedef BOOL (WINAPI *pfn_SymSetSearchPath)(HANDLE, PCTSTR); typedef BOOL (WINAPI *pfn_SymGetSearchPath)(HANDLE, PTSTR, int); +#ifdef AMD64 +typedef BOOL (WINAPI *pfn_StackWalk64)(DWORD MachineType, + HANDLE hProcess, + HANDLE hThread, + LPSTACKFRAME64 StackFrame, + PVOID ContextRecord, + PREAD_PROCESS_MEMORY_ROUTINE64 ReadMemoryRoutine, + PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine, + PGET_MODULE_BASE_ROUTINE64 GetModuleBaseRoutine, + PTRANSLATE_ADDRESS_ROUTINE64 TranslateAddress); +typedef PVOID (WINAPI *pfn_SymFunctionTableAccess64)(HANDLE hProcess, DWORD64 AddrBase); +typedef DWORD64 (WINAPI *pfn_SymGetModuleBase64)(HANDLE hProcess, DWORD64 dwAddr); +#endif + class WindowsDecoder : public AbstractDecoder { public: @@ -61,7 +75,34 @@ private: bool _can_decode_in_vm; pfn_SymGetSymFromAddr64 _pfnSymGetSymFromAddr64; pfn_UndecorateSymbolName _pfnUndecorateSymbolName; +#ifdef AMD64 + pfn_StackWalk64 _pfnStackWalk64; + pfn_SymFunctionTableAccess64 _pfnSymFunctionTableAccess64; + pfn_SymGetModuleBase64 _pfnSymGetModuleBase64; + + friend class WindowsDbgHelp; +#endif }; +#ifdef AMD64 +// TODO: refactor and move the handling of dbghelp.dll outside of Decoder +class WindowsDbgHelp : public Decoder { +public: + static BOOL StackWalk64(DWORD MachineType, + HANDLE hProcess, + HANDLE hThread, + LPSTACKFRAME64 StackFrame, + PVOID ContextRecord, + PREAD_PROCESS_MEMORY_ROUTINE64 ReadMemoryRoutine, + PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine, + PGET_MODULE_BASE_ROUTINE64 GetModuleBaseRoutine, + PTRANSLATE_ADDRESS_ROUTINE64 TranslateAddress); + static PVOID SymFunctionTableAccess64(HANDLE hProcess, DWORD64 AddrBase); + + static pfn_SymFunctionTableAccess64 pfnSymFunctionTableAccess64(); + static pfn_SymGetModuleBase64 pfnSymGetModuleBase64(); +}; +#endif + #endif // OS_WINDOWS_VM_DECODER_WINDOWS_HPP diff --git a/hotspot/src/os_cpu/windows_x86/vm/os_windows_x86.cpp b/hotspot/src/os_cpu/windows_x86/vm/os_windows_x86.cpp index a0f2a7680be..09735dae0c6 100644 --- a/hotspot/src/os_cpu/windows_x86/vm/os_windows_x86.cpp +++ b/hotspot/src/os_cpu/windows_x86/vm/os_windows_x86.cpp @@ -29,6 +29,7 @@ #include "classfile/vmSymbols.hpp" #include "code/icBuffer.hpp" #include "code/vtableStubs.hpp" +#include "decoder_windows.hpp" #include "interpreter/interpreter.hpp" #include "jvm_windows.h" #include "memory/allocation.inline.hpp" @@ -327,6 +328,94 @@ add_ptr_func_t* os::atomic_add_ptr_func = os::atomic_add_ptr_bootstrap cmpxchg_long_func_t* os::atomic_cmpxchg_long_func = os::atomic_cmpxchg_long_bootstrap; +#ifdef AMD64 +/* + * Windows/x64 does not use stack frames the way expected by Java: + * [1] in most cases, there is no frame pointer. All locals are addressed via RSP + * [2] in rare cases, when alloca() is used, a frame pointer is used, but this may + * not be RBP. + * See http://msdn.microsoft.com/en-us/library/ew5tede7.aspx + * + * So it's not possible to print the native stack using the + * while (...) {... fr = os::get_sender_for_C_frame(&fr); } + * loop in vmError.cpp. We need to roll our own loop. + */ +bool os::platform_print_native_stack(outputStream* st, void* context, + char *buf, int buf_size) +{ + CONTEXT ctx; + if (context != NULL) { + memcpy(&ctx, context, sizeof(ctx)); + } else { + RtlCaptureContext(&ctx); + } + + st->print_cr("Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)"); + + STACKFRAME stk; + memset(&stk, 0, sizeof(stk)); + stk.AddrStack.Offset = ctx.Rsp; + stk.AddrStack.Mode = AddrModeFlat; + stk.AddrFrame.Offset = ctx.Rbp; + stk.AddrFrame.Mode = AddrModeFlat; + stk.AddrPC.Offset = ctx.Rip; + stk.AddrPC.Mode = AddrModeFlat; + + int count = 0; + address lastpc = 0; + while (count++ < StackPrintLimit) { + intptr_t* sp = (intptr_t*)stk.AddrStack.Offset; + intptr_t* fp = (intptr_t*)stk.AddrFrame.Offset; // NOT necessarily the same as ctx.Rbp! + address pc = (address)stk.AddrPC.Offset; + + if (pc != NULL && sp != NULL && fp != NULL) { + if (count == 2 && lastpc == pc) { + // Skip it -- StackWalk64() may return the same PC + // (but different SP) on the first try. + } else { + // Don't try to create a frame(sp, fp, pc) -- on WinX64, stk.AddrFrame + // may not contain what Java expects, and may cause the frame() constructor + // to crash. Let's just print out the symbolic address. + frame::print_C_frame(st, buf, buf_size, pc); + st->cr(); + } + lastpc = pc; + } else { + break; + } + + PVOID p = WindowsDbgHelp::SymFunctionTableAccess64(GetCurrentProcess(), stk.AddrPC.Offset); + if (!p) { + // StackWalk64() can't handle this PC. Calling StackWalk64 again may cause crash. + break; + } + + BOOL result = WindowsDbgHelp::StackWalk64( + IMAGE_FILE_MACHINE_AMD64, // __in DWORD MachineType, + GetCurrentProcess(), // __in HANDLE hProcess, + GetCurrentThread(), // __in HANDLE hThread, + &stk, // __inout LP STACKFRAME64 StackFrame, + &ctx, // __inout PVOID ContextRecord, + NULL, // __in_opt PREAD_PROCESS_MEMORY_ROUTINE64 ReadMemoryRoutine, + WindowsDbgHelp::pfnSymFunctionTableAccess64(), + // __in_opt PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine, + WindowsDbgHelp::pfnSymGetModuleBase64(), + // __in_opt PGET_MODULE_BASE_ROUTINE64 GetModuleBaseRoutine, + NULL); // __in_opt PTRANSLATE_ADDRESS_ROUTINE64 TranslateAddress + + if (!result) { + break; + } + } + if (count > StackPrintLimit) { + st->print_cr("......"); + } + st->cr(); + + return true; +} +#endif // AMD64 + ExtendedPC os::fetch_frame_from_context(void* ucVoid, intptr_t** ret_sp, intptr_t** ret_fp) { @@ -401,6 +490,9 @@ frame os::current_frame() { StubRoutines::x86::get_previous_fp_entry()); if (func == NULL) return frame(); intptr_t* fp = (*func)(); + if (fp == NULL) { + return frame(); + } #else intptr_t* fp = _get_previous_fp(); #endif // AMD64 diff --git a/hotspot/src/os_cpu/windows_x86/vm/os_windows_x86.hpp b/hotspot/src/os_cpu/windows_x86/vm/os_windows_x86.hpp index 41814b6c61b..22ffeb5dc34 100644 --- a/hotspot/src/os_cpu/windows_x86/vm/os_windows_x86.hpp +++ b/hotspot/src/os_cpu/windows_x86/vm/os_windows_x86.hpp @@ -62,4 +62,10 @@ static bool register_code_area(char *low, char *high); +#ifdef AMD64 +#define PLATFORM_PRINT_NATIVE_STACK 1 +static bool platform_print_native_stack(outputStream* st, void* context, + char *buf, int buf_size); +#endif + #endif // OS_CPU_WINDOWS_X86_VM_OS_WINDOWS_X86_HPP diff --git a/hotspot/src/share/vm/runtime/frame.cpp b/hotspot/src/share/vm/runtime/frame.cpp index 6f5724323cd..4fae1c8fe11 100644 --- a/hotspot/src/share/vm/runtime/frame.cpp +++ b/hotspot/src/share/vm/runtime/frame.cpp @@ -652,7 +652,7 @@ void frame::interpreter_frame_print_on(outputStream* st) const { // Return whether the frame is in the VM or os indicating a Hotspot problem. // Otherwise, it's likely a bug in the native library that the Java code calls, // hopefully indicating where to submit bugs. -static void print_C_frame(outputStream* st, char* buf, int buflen, address pc) { +void frame::print_C_frame(outputStream* st, char* buf, int buflen, address pc) { // C/C++ frame bool in_vm = os::address_is_in_vm(pc); st->print(in_vm ? "V" : "C"); diff --git a/hotspot/src/share/vm/runtime/frame.hpp b/hotspot/src/share/vm/runtime/frame.hpp index 096b467b5f8..78292c662ec 100644 --- a/hotspot/src/share/vm/runtime/frame.hpp +++ b/hotspot/src/share/vm/runtime/frame.hpp @@ -406,6 +406,7 @@ class frame VALUE_OBJ_CLASS_SPEC { void print_on(outputStream* st) const; void interpreter_frame_print_on(outputStream* st) const; void print_on_error(outputStream* st, char* buf, int buflen, bool verbose = false) const; + static void print_C_frame(outputStream* st, char* buf, int buflen, address pc); // Add annotated descriptions of memory locations belonging to this frame to values void describe(FrameValues& values, int frame_no); diff --git a/hotspot/src/share/vm/runtime/os.hpp b/hotspot/src/share/vm/runtime/os.hpp index e43d68981cb..4ca0d32607b 100644 --- a/hotspot/src/share/vm/runtime/os.hpp +++ b/hotspot/src/share/vm/runtime/os.hpp @@ -795,6 +795,14 @@ class os: AllStatic { #endif public: +#ifndef PLATFORM_PRINT_NATIVE_STACK + // No platform-specific code for printing the native stack. + static bool platform_print_native_stack(outputStream* st, void* context, + char *buf, int buf_size) { + return false; + } +#endif + // debugging support (mostly used by debug.cpp but also fatal error handler) static bool find(address pc, outputStream* st = tty); // OS specific function to make sense out of an address diff --git a/hotspot/src/share/vm/utilities/decoder.cpp b/hotspot/src/share/vm/utilities/decoder.cpp index 5489fe6fefb..3fc934b4f32 100644 --- a/hotspot/src/share/vm/utilities/decoder.cpp +++ b/hotspot/src/share/vm/utilities/decoder.cpp @@ -24,7 +24,6 @@ #include "precompiled.hpp" #include "prims/jvm.h" -#include "runtime/mutexLocker.hpp" #include "runtime/os.hpp" #include "utilities/decoder.hpp" #include "utilities/vmError.hpp" @@ -80,6 +79,23 @@ AbstractDecoder* Decoder::create_decoder() { return decoder; } +inline bool DecoderLocker::is_first_error_thread() { + return (os::current_thread_id() == VMError::get_first_error_tid()); +} + +DecoderLocker::DecoderLocker() : + MutexLockerEx(DecoderLocker::is_first_error_thread() ? + NULL : Decoder::shared_decoder_lock(), true) { + _decoder = is_first_error_thread() ? + Decoder::get_error_handler_instance() : Decoder::get_shared_instance(); + assert(_decoder != NULL, "null decoder"); +} + +Mutex* Decoder::shared_decoder_lock() { + assert(_shared_decoder_lock != NULL, "Just check"); + return _shared_decoder_lock; +} + bool Decoder::decode(address addr, char* buf, int buflen, int* offset, const char* modulepath) { assert(_shared_decoder_lock != NULL, "Just check"); bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid; diff --git a/hotspot/src/share/vm/utilities/decoder.hpp b/hotspot/src/share/vm/utilities/decoder.hpp index 0d2af80986c..0cc880f1915 100644 --- a/hotspot/src/share/vm/utilities/decoder.hpp +++ b/hotspot/src/share/vm/utilities/decoder.hpp @@ -28,6 +28,7 @@ #include "memory/allocation.hpp" #include "runtime/mutex.hpp" +#include "runtime/mutexLocker.hpp" class AbstractDecoder : public CHeapObj { public: @@ -124,6 +125,19 @@ private: protected: static Mutex* _shared_decoder_lock; + static Mutex* shared_decoder_lock(); + + friend class DecoderLocker; +}; + +class DecoderLocker : public MutexLockerEx { + AbstractDecoder* _decoder; + inline bool is_first_error_thread(); +public: + DecoderLocker(); + AbstractDecoder* decoder() { + return _decoder; + } }; #endif // SHARE_VM_UTILITIES_DECODER_HPP diff --git a/hotspot/src/share/vm/utilities/vmError.cpp b/hotspot/src/share/vm/utilities/vmError.cpp index b07404dc9b7..79769aeb3bc 100644 --- a/hotspot/src/share/vm/utilities/vmError.cpp +++ b/hotspot/src/share/vm/utilities/vmError.cpp @@ -574,6 +574,10 @@ void VMError::report(outputStream* st) { STEP(120, "(printing native stack)" ) if (_verbose) { + if (os::platform_print_native_stack(st, _context, buf, sizeof(buf))) { + // We have printed the native stack in platform-specific code + // Windows/x64 needs special handling. + } else { frame fr = _context ? os::fetch_frame_from_context(_context) : os::current_frame(); @@ -604,6 +608,7 @@ void VMError::report(outputStream* st) { st->cr(); } } + } STEP(130, "(printing Java stack)" ) diff --git a/hotspot/src/share/vm/utilities/vmError.hpp b/hotspot/src/share/vm/utilities/vmError.hpp index 1b1608bdc90..299cfaa6f3d 100644 --- a/hotspot/src/share/vm/utilities/vmError.hpp +++ b/hotspot/src/share/vm/utilities/vmError.hpp @@ -136,6 +136,10 @@ public: // check to see if fatal error reporting is in progress static bool fatal_error_in_progress() { return first_error != NULL; } + + static jlong get_first_error_tid() { + return first_error_tid; + } }; #endif // SHARE_VM_UTILITIES_VMERROR_HPP From 7e04c1775ca6ed242a472f8aa0909d5e33cf023e Mon Sep 17 00:00:00 2001 From: Alejandro Murillo Date: Fri, 6 Sep 2013 11:11:19 -0700 Subject: [PATCH 101/210] 8024258: new hotspot build - hs25-b50 Reviewed-by: jcoomes --- hotspot/make/hotspot_version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hotspot/make/hotspot_version b/hotspot/make/hotspot_version index 15223e843df..e1572121149 100644 --- a/hotspot/make/hotspot_version +++ b/hotspot/make/hotspot_version @@ -35,7 +35,7 @@ HOTSPOT_VM_COPYRIGHT=Copyright 2013 HS_MAJOR_VER=25 HS_MINOR_VER=0 -HS_BUILD_NUMBER=49 +HS_BUILD_NUMBER=50 JDK_MAJOR_VER=1 JDK_MINOR_VER=8 From f607953eb87ebe214f7696affeeabf92906a318a Mon Sep 17 00:00:00 2001 From: Jonathan Gibbons Date: Fri, 6 Sep 2013 15:31:59 -0700 Subject: [PATCH 102/210] 8024434: problem running javadoc tests in samevm mode on Windows Reviewed-by: darcy --- .../internal/toolkit/util/PathDocFileFactory.java | 7 +++++-- .../test/tools/javadoc/api/basic/APITest.java | 15 +++++++++------ .../api/basic/GetTask_FileManagerTest.java | 4 ++-- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/PathDocFileFactory.java b/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/PathDocFileFactory.java index 7990a347c18..faeec757e7a 100644 --- a/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/PathDocFileFactory.java +++ b/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/PathDocFileFactory.java @@ -34,6 +34,7 @@ import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.UnsupportedEncodingException; import java.io.Writer; +import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; @@ -221,8 +222,10 @@ class PathDocFileFactory extends DocFileFactory { /** If the file is a directory, list its contents. */ public Iterable list() throws IOException { List files = new ArrayList(); - for (Path f: Files.newDirectoryStream(file)) { - files.add(new StandardDocFile(f)); + try (DirectoryStream ds = Files.newDirectoryStream(file)) { + for (Path f: ds) { + files.add(new StandardDocFile(f)); + } } return files; } diff --git a/langtools/test/tools/javadoc/api/basic/APITest.java b/langtools/test/tools/javadoc/api/basic/APITest.java index 358b6b3bc48..439d80c4a26 100644 --- a/langtools/test/tools/javadoc/api/basic/APITest.java +++ b/langtools/test/tools/javadoc/api/basic/APITest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2013, 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 @@ -29,6 +29,7 @@ import java.lang.annotation.RetentionPolicy; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.URI; +import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.Path; import java.util.Arrays; @@ -164,11 +165,13 @@ class APITest { } private void listFiles(Path dir, Set files) throws IOException { - for (Path f: Files.newDirectoryStream(dir)) { - if (Files.isDirectory(f)) - listFiles(f, files); - else if (Files.isRegularFile(f)) - files.add(f); + try (DirectoryStream ds = Files.newDirectoryStream(dir)) { + for (Path f: ds) { + if (Files.isDirectory(f)) + listFiles(f, files); + else if (Files.isRegularFile(f)) + files.add(f); + } } } diff --git a/langtools/test/tools/javadoc/api/basic/GetTask_FileManagerTest.java b/langtools/test/tools/javadoc/api/basic/GetTask_FileManagerTest.java index 4532e619f9b..d5ab604f6ac 100644 --- a/langtools/test/tools/javadoc/api/basic/GetTask_FileManagerTest.java +++ b/langtools/test/tools/javadoc/api/basic/GetTask_FileManagerTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2013, 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 6493690 + * @bug 6493690 8024434 * @summary javadoc should have a javax.tools.Tool service provider * @build APITest * @run main GetTask_FileManagerTest From a3b1359af5a40a1cd1901f491bc7ebf2c7f2b6e0 Mon Sep 17 00:00:00 2001 From: Vicente Romero Date: Sun, 8 Sep 2013 11:54:21 +0100 Subject: [PATCH 103/210] 8024398: javac, compiler crashes with try with empty body Reviewed-by: jjg --- .../com/sun/tools/javac/comp/Lower.java | 46 ++++++++--------- .../test/tools/javac/T8024398/NPETryTest.java | 49 +++++++++++++++++++ 2 files changed, 73 insertions(+), 22 deletions(-) create mode 100644 langtools/test/tools/javac/T8024398/NPETryTest.java diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/Lower.java b/langtools/src/share/classes/com/sun/tools/javac/comp/Lower.java index 7094d64b19c..5926a1b68c1 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Lower.java +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Lower.java @@ -3829,30 +3829,32 @@ public class Lower extends TreeTranslator { @Override public void visitTry(JCTry tree) { - if (tree.resources.isEmpty()) { - /* special case of try without catchers and with finally emtpy. - * Don't give it a try, translate only the body. - */ - if (tree.catchers.isEmpty() && - tree.finalizer.getStatements().isEmpty()) { - result = translate(tree.body); - } else { - /* also if the body is empty we only need to generate the finalizer - * provided that it's not empty. - */ - if (tree.body.getStatements().isEmpty()) { - if (tree.finalizer.getStatements().isEmpty()) { - result = translate(tree.body); - } else { - result = translate(tree.finalizer); - } - } else { - super.visitTry(tree); - } - } - } else { + if (tree.resources.nonEmpty()) { result = makeTwrTry(tree); + return; } + + boolean hasBody = tree.body.getStatements().nonEmpty(); + boolean hasCatchers = tree.catchers.nonEmpty(); + boolean hasFinally = tree.finalizer != null && + tree.finalizer.getStatements().nonEmpty(); + + if (!hasCatchers && !hasFinally) { + result = translate(tree.body); + return; + } + + if (!hasBody) { + if (hasFinally) { + result = translate(tree.finalizer); + } else { + result = translate(tree.body); + } + return; + } + + // no optimizations possible + super.visitTry(tree); } /************************************************************************** diff --git a/langtools/test/tools/javac/T8024398/NPETryTest.java b/langtools/test/tools/javac/T8024398/NPETryTest.java new file mode 100644 index 00000000000..7d5b11fb6e0 --- /dev/null +++ b/langtools/test/tools/javac/T8024398/NPETryTest.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2013, 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. + */ + +/* + * @test + * @bug 8024398 + * @summary javac, compiler crashes with try with empty body + * @compile NPETryTest.java + */ + +public class NPETryTest { + void m() + { + /* This is the statement provoking the error the rest are provided as + * additional tests + */ + try {} + catch (Exception e) {} + + try {} + catch (Exception e) {} + finally {} + + try {} + finally {} + } +} From 5df75e001d5282e64036a739ac03b18ae5637c7d Mon Sep 17 00:00:00 2001 From: Andreas Lundblad Date: Mon, 9 Sep 2013 09:58:20 +0200 Subject: [PATCH 104/210] 8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata Reviewed-by: jfranck, jjg --- .../com/sun/tools/javac/code/Symbol.java | 14 +++++----- .../{Annotations.java => SymbolMetadata.java} | 26 +++++++++---------- langtools/test/tools/javac/lib/DPrinter.java | 14 +++++----- 3 files changed, 27 insertions(+), 27 deletions(-) rename langtools/src/share/classes/com/sun/tools/javac/code/{Annotations.java => SymbolMetadata.java} (94%) diff --git a/langtools/src/share/classes/com/sun/tools/javac/code/Symbol.java b/langtools/src/share/classes/com/sun/tools/javac/code/Symbol.java index 64c117cb2bc..d7552ee2a9e 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/code/Symbol.java +++ b/langtools/src/share/classes/com/sun/tools/javac/code/Symbol.java @@ -98,9 +98,9 @@ public abstract class Symbol implements Element { // /** The attributes of this symbol are contained in this - * Annotations. The Annotations instance is NOT immutable. + * SymbolMetadata. The SymbolMetadata instance is NOT immutable. */ - protected Annotations annotations; + protected SymbolMetadata annotations; /** An accessor method for the attributes of this symbol. * Attributes of class symbols should be accessed through the accessor @@ -217,19 +217,19 @@ public abstract class Symbol implements Element { public void setTypeAttributes(List a) { if (annotations != null || a.nonEmpty()) { if (annotations == null) - annotations = new Annotations(this); + annotations = new SymbolMetadata(this); annotations.setTypeAttributes(a); } } - private Annotations initedAnnos() { + private SymbolMetadata initedAnnos() { if (annotations == null) - annotations = new Annotations(this); + annotations = new SymbolMetadata(this); return annotations; } /** This method is intended for debugging only. */ - public Annotations getAnnotations() { + public SymbolMetadata getAnnotations() { return annotations; } @@ -852,7 +852,7 @@ public abstract class Symbol implements Element { private void mergeAttributes() { if (annotations == null && package_info.annotations != null) { - annotations = new Annotations(this); + annotations = new SymbolMetadata(this); annotations.setAttributes(package_info.annotations); } } diff --git a/langtools/src/share/classes/com/sun/tools/javac/code/Annotations.java b/langtools/src/share/classes/com/sun/tools/javac/code/SymbolMetadata.java similarity index 94% rename from langtools/src/share/classes/com/sun/tools/javac/code/Annotations.java rename to langtools/src/share/classes/com/sun/tools/javac/code/SymbolMetadata.java index 5be0865c042..42564f67ed3 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/code/Annotations.java +++ b/langtools/src/share/classes/com/sun/tools/javac/code/SymbolMetadata.java @@ -57,7 +57,7 @@ import static com.sun.tools.javac.code.Kinds.PCK; * later. You can reset to IN_PROGRESS. While IN_PROGRESS you can set the list * of attributes (and this moves out of the IN_PROGRESS state). * - * "unnamed" this Annotations contains some attributes, possibly the final set. + * "unnamed" this SymbolMetadata contains some attributes, possibly the final set. * While in this state you can only prepend or append to the attributes not set * it directly. You can also move back to the IN_PROGRESS state using reset(). * @@ -65,7 +65,7 @@ import static com.sun.tools.javac.code.Kinds.PCK; * on this, you do so at your own risk. This code and its internal interfaces * are subject to change or deletion without notice. */ -public class Annotations { +public class SymbolMetadata { private static final List DECL_NOT_STARTED = List.of(null); private static final List DECL_IN_PROGRESS = List.of(null); @@ -94,11 +94,11 @@ public class Annotations { private List clinit_type_attributes = List.nil(); /* - * The Symbol this Annotations instance belongs to + * The Symbol this SymbolMetadata instance belongs to */ private final Symbol sym; - public Annotations(Symbol sym) { + public SymbolMetadata(Symbol sym) { this.sym = sym; } @@ -147,7 +147,7 @@ public class Annotations { clinit_type_attributes = a; } - public void setAttributes(Annotations other) { + public void setAttributes(SymbolMetadata other) { if (other == null) { throw new NullPointerException(); } @@ -221,7 +221,7 @@ public class Annotations { return buf.reverse(); } - public Annotations reset() { + public SymbolMetadata reset() { attributes = DECL_IN_PROGRESS; return this; } @@ -240,7 +240,7 @@ public class Annotations { return attributes == DECL_IN_PROGRESS; } - public Annotations append(List l) { + public SymbolMetadata append(List l) { attributes = filterDeclSentinels(attributes); if (l.isEmpty()) { @@ -253,7 +253,7 @@ public class Annotations { return this; } - public Annotations appendUniqueTypes(List l) { + public SymbolMetadata appendUniqueTypes(List l) { if (l.isEmpty()) { ; // no-op } else if (type_attributes.isEmpty()) { @@ -269,7 +269,7 @@ public class Annotations { return this; } - public Annotations appendInitTypeAttributes(List l) { + public SymbolMetadata appendInitTypeAttributes(List l) { if (l.isEmpty()) { ; // no-op } else if (init_type_attributes.isEmpty()) { @@ -280,7 +280,7 @@ public class Annotations { return this; } - public Annotations appendClassInitTypeAttributes(List l) { + public SymbolMetadata appendClassInitTypeAttributes(List l) { if (l.isEmpty()) { ; // no-op } else if (clinit_type_attributes.isEmpty()) { @@ -291,7 +291,7 @@ public class Annotations { return this; } - public Annotations prepend(List l) { + public SymbolMetadata prepend(List l) { attributes = filterDeclSentinels(attributes); if (l.isEmpty()) { @@ -367,7 +367,7 @@ public class Annotations { type_attributes = result.reverse(); - Assert.check(Annotations.this.getTypePlaceholders().isEmpty()); + Assert.check(SymbolMetadata.this.getTypePlaceholders().isEmpty()); } else { Assert.check(!pendingCompletion()); @@ -391,7 +391,7 @@ public class Annotations { attributes = result.reverse(); - Assert.check(Annotations.this.getPlaceholders().isEmpty()); + Assert.check(SymbolMetadata.this.getPlaceholders().isEmpty()); } } finally { log.useSource(oldSource); diff --git a/langtools/test/tools/javac/lib/DPrinter.java b/langtools/test/tools/javac/lib/DPrinter.java index 8df4881cba4..8e67826c641 100644 --- a/langtools/test/tools/javac/lib/DPrinter.java +++ b/langtools/test/tools/javac/lib/DPrinter.java @@ -49,7 +49,7 @@ import com.sun.source.util.TaskEvent; import com.sun.source.util.TaskListener; import com.sun.source.util.Trees; import com.sun.tools.javac.api.JavacTrees; -import com.sun.tools.javac.code.Annotations; +import com.sun.tools.javac.code.SymbolMetadata; import com.sun.tools.javac.code.Attribute; import com.sun.tools.javac.code.Flags; import com.sun.tools.javac.code.Kinds; @@ -186,21 +186,21 @@ public class DPrinter { FULL }; - public void printAnnotations(String label, Annotations annotations) { + public void printAnnotations(String label, SymbolMetadata annotations) { printAnnotations(label, annotations, Details.FULL); } - protected void printAnnotations(String label, Annotations annotations, Details details) { + protected void printAnnotations(String label, SymbolMetadata annotations, Details details) { if (annotations == null) { printNull(label); } else { // no SUMMARY format currently available to use // use reflection to get at private fields - Object DECL_NOT_STARTED = getField(null, Annotations.class, "DECL_NOT_STARTED"); - Object DECL_IN_PROGRESS = getField(null, Annotations.class, "DECL_IN_PROGRESS"); - Object attributes = getField(annotations, Annotations.class, "attributes"); - Object type_attributes = getField(annotations, Annotations.class, "type_attributes"); + Object DECL_NOT_STARTED = getField(null, SymbolMetadata.class, "DECL_NOT_STARTED"); + Object DECL_IN_PROGRESS = getField(null, SymbolMetadata.class, "DECL_IN_PROGRESS"); + Object attributes = getField(annotations, SymbolMetadata.class, "attributes"); + Object type_attributes = getField(annotations, SymbolMetadata.class, "type_attributes"); if (!showEmptyItems) { if (attributes instanceof List && ((List) attributes).isEmpty() From 972efc6f0a9dff15c6f1c9fb57e7fe796baa300f Mon Sep 17 00:00:00 2001 From: Kevin Walls Date: Mon, 9 Sep 2013 10:01:09 +0100 Subject: [PATCH 105/210] 8023478: Test fails with HS crash in GCNotifier Reviewed-by: sla --- hotspot/src/share/vm/services/gcNotifier.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hotspot/src/share/vm/services/gcNotifier.cpp b/hotspot/src/share/vm/services/gcNotifier.cpp index 7d1fe5d8944..1025072339a 100644 --- a/hotspot/src/share/vm/services/gcNotifier.cpp +++ b/hotspot/src/share/vm/services/gcNotifier.cpp @@ -209,7 +209,7 @@ void GCNotifier::sendNotificationInternal(TRAPS) { GCNotificationRequest *request = getRequest(); if (request != NULL) { NotificationMark nm(request); - Handle objGcInfo = createGcInfo(request->gcManager, request->gcStatInfo, THREAD); + Handle objGcInfo = createGcInfo(request->gcManager, request->gcStatInfo, CHECK); Handle objName = java_lang_String::create_from_str(request->gcManager->name(), CHECK); Handle objAction = java_lang_String::create_from_str(request->gcAction, CHECK); From 1704a9454c687cbcfb493646308261609bcd164e Mon Sep 17 00:00:00 2001 From: Vicente Romero Date: Mon, 9 Sep 2013 16:32:08 +0100 Subject: [PATCH 106/210] 8024154: Fix for 8016177: structural most specific and stuckness breaks 6 langtools tests Reviewed-by: jjg, jfranck --- .../tools/javac/lambda/MethodReference41.java | 26 ++----------------- .../tools/javac/lambda/MethodReference41.out | 6 ++--- .../tools/javac/lambda/MethodReference42.java | 26 ++----------------- .../tools/javac/lambda/MethodReference42.out | 6 ++--- .../tools/javac/lambda/MethodReference43.java | 26 ++----------------- .../tools/javac/lambda/MethodReference43.out | 8 +++--- .../tools/javac/lambda/MethodReference44.java | 26 ++----------------- .../tools/javac/lambda/MethodReference44.out | 6 ++--- .../tools/javac/lambda/MethodReference46.java | 26 ++----------------- .../tools/javac/lambda/MethodReference46.out | 6 ++--- .../tools/javac/lambda/MethodReference48.java | 26 ++----------------- .../tools/javac/lambda/MethodReference48.out | 4 +-- 12 files changed, 30 insertions(+), 162 deletions(-) diff --git a/langtools/test/tools/javac/lambda/MethodReference41.java b/langtools/test/tools/javac/lambda/MethodReference41.java index 836dce0f1cb..a3a8bddb605 100644 --- a/langtools/test/tools/javac/lambda/MethodReference41.java +++ b/langtools/test/tools/javac/lambda/MethodReference41.java @@ -1,33 +1,11 @@ /* - * Copyright (c) 2012, 2013, 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 + * @test /nodynamiccopyright/ * @bug 8003280 * @summary Add lambda tests * check that diamond inference is applied when using raw constructor reference qualifier * @compile/fail/ref=MethodReference41.out -XDrawDiagnostics MethodReference41.java */ + public class MethodReference41 { interface SAM1 { diff --git a/langtools/test/tools/javac/lambda/MethodReference41.out b/langtools/test/tools/javac/lambda/MethodReference41.out index f4a60cb3ba6..a501b109bd3 100644 --- a/langtools/test/tools/javac/lambda/MethodReference41.out +++ b/langtools/test/tools/javac/lambda/MethodReference41.out @@ -1,4 +1,4 @@ -MethodReference41.java:60:11: compiler.err.cant.apply.symbol: kindname.method, m1, MethodReference41.SAM1, @1819, kindname.class, MethodReference41, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.invalid.mref: kindname.constructor, (compiler.misc.cant.apply.symbol: kindname.constructor, Foo, java.lang.Number, java.lang.String, kindname.class, MethodReference41.Foo, (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.String, java.lang.Number)))) -MethodReference41.java:62:11: compiler.err.cant.apply.symbol: kindname.method, m3, MethodReference41.SAM3, @1863, kindname.class, MethodReference41, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.invalid.mref: kindname.constructor, (compiler.misc.cant.apply.symbol: kindname.constructor, Foo, java.lang.Number, java.lang.Object, kindname.class, MethodReference41.Foo, (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Object, java.lang.Number)))) -MethodReference41.java:63:9: compiler.err.ref.ambiguous: m4, kindname.method, m4(MethodReference41.SAM2), MethodReference41, kindname.method, m4(MethodReference41.SAM3), MethodReference41 +MethodReference41.java:38:11: compiler.err.cant.apply.symbol: kindname.method, m1, MethodReference41.SAM1, @767, kindname.class, MethodReference41, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.invalid.mref: kindname.constructor, (compiler.misc.cant.apply.symbol: kindname.constructor, Foo, java.lang.Number, java.lang.String, kindname.class, MethodReference41.Foo, (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.String, java.lang.Number)))) +MethodReference41.java:40:11: compiler.err.cant.apply.symbol: kindname.method, m3, MethodReference41.SAM3, @811, kindname.class, MethodReference41, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.invalid.mref: kindname.constructor, (compiler.misc.cant.apply.symbol: kindname.constructor, Foo, java.lang.Number, java.lang.Object, kindname.class, MethodReference41.Foo, (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Object, java.lang.Number)))) +MethodReference41.java:41:9: compiler.err.ref.ambiguous: m4, kindname.method, m4(MethodReference41.SAM2), MethodReference41, kindname.method, m4(MethodReference41.SAM3), MethodReference41 3 errors diff --git a/langtools/test/tools/javac/lambda/MethodReference42.java b/langtools/test/tools/javac/lambda/MethodReference42.java index 957dc024902..61bef68c770 100644 --- a/langtools/test/tools/javac/lambda/MethodReference42.java +++ b/langtools/test/tools/javac/lambda/MethodReference42.java @@ -1,33 +1,11 @@ /* - * Copyright (c) 2012, 2013, 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 + * @test /nodynamiccopyright/ * @bug 8003280 * @summary Add lambda tests * check that diamond inference is applied when using raw constructor reference qualifier * @compile/fail/ref=MethodReference42.out -XDrawDiagnostics MethodReference42.java */ + public class MethodReference42 { static class SuperFoo { } diff --git a/langtools/test/tools/javac/lambda/MethodReference42.out b/langtools/test/tools/javac/lambda/MethodReference42.out index 70ec85a352e..ab324c44665 100644 --- a/langtools/test/tools/javac/lambda/MethodReference42.out +++ b/langtools/test/tools/javac/lambda/MethodReference42.out @@ -1,4 +1,4 @@ -MethodReference42.java:60:11: compiler.err.cant.apply.symbol: kindname.method, m1, MethodReference42.SAM1, @1851, kindname.class, MethodReference42, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.eq.upper.bounds: X, java.lang.String, java.lang.Number)) -MethodReference42.java:62:11: compiler.err.cant.apply.symbol: kindname.method, m3, MethodReference42.SAM3, @1895, kindname.class, MethodReference42, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.eq.upper.bounds: X, java.lang.Object, java.lang.Number)) -MethodReference42.java:63:9: compiler.err.ref.ambiguous: m4, kindname.method, m4(MethodReference42.SAM2), MethodReference42, kindname.method, m4(MethodReference42.SAM3), MethodReference42 +MethodReference42.java:38:11: compiler.err.cant.apply.symbol: kindname.method, m1, MethodReference42.SAM1, @811, kindname.class, MethodReference42, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.eq.upper.bounds: X, java.lang.String, java.lang.Number)) +MethodReference42.java:40:11: compiler.err.cant.apply.symbol: kindname.method, m3, MethodReference42.SAM3, @855, kindname.class, MethodReference42, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.eq.upper.bounds: X, java.lang.Object, java.lang.Number)) +MethodReference42.java:41:9: compiler.err.ref.ambiguous: m4, kindname.method, m4(MethodReference42.SAM2), MethodReference42, kindname.method, m4(MethodReference42.SAM3), MethodReference42 3 errors diff --git a/langtools/test/tools/javac/lambda/MethodReference43.java b/langtools/test/tools/javac/lambda/MethodReference43.java index 53cf98c702f..99fbc3d5dd4 100644 --- a/langtools/test/tools/javac/lambda/MethodReference43.java +++ b/langtools/test/tools/javac/lambda/MethodReference43.java @@ -1,33 +1,11 @@ /* - * Copyright (c) 2012, 2013, 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 + * @test /nodynamiccopyright/ * @bug 8003280 * @summary Add lambda tests * check that diamond inference is applied when using raw constructor reference qualifier * @compile/fail/ref=MethodReference43.out -XDrawDiagnostics MethodReference43.java */ + public class MethodReference43 { interface SAM1 { diff --git a/langtools/test/tools/javac/lambda/MethodReference43.out b/langtools/test/tools/javac/lambda/MethodReference43.out index e1e0461d80f..dfe70b3c1f8 100644 --- a/langtools/test/tools/javac/lambda/MethodReference43.out +++ b/langtools/test/tools/javac/lambda/MethodReference43.out @@ -1,5 +1,5 @@ -MethodReference43.java:67:11: compiler.err.cant.apply.symbol: kindname.method, m1, MethodReference43.SAM1, @1937, kindname.class, MethodReference43, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.invalid.mref: kindname.constructor, (compiler.misc.cant.apply.symbol: kindname.constructor, Foo, java.lang.Number, java.lang.String, kindname.class, MethodReference43.Foo, (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.String, java.lang.Number)))) -MethodReference43.java:69:11: compiler.err.cant.apply.symbol: kindname.method, m3, MethodReference43.SAM3, @1981, kindname.class, MethodReference43, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.invalid.mref: kindname.constructor, (compiler.misc.cant.apply.symbol: kindname.constructor, Foo, java.lang.Number, java.lang.Object, kindname.class, MethodReference43.Foo, (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Object, java.lang.Number)))) -MethodReference43.java:71:9: compiler.err.ref.ambiguous: m5, kindname.method, m5(MethodReference43.SAM3), MethodReference43, kindname.method, m5(MethodReference43.SAM4), MethodReference43 -MethodReference43.java:71:11: compiler.err.cant.apply.symbol: kindname.method, m5, MethodReference43.SAM3, @2025, kindname.class, MethodReference43, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.invalid.mref: kindname.constructor, (compiler.misc.cant.apply.symbol: kindname.constructor, Foo, java.lang.Number, java.lang.Object, kindname.class, MethodReference43.Foo, (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Object, java.lang.Number)))) +MethodReference43.java:45:11: compiler.err.cant.apply.symbol: kindname.method, m1, MethodReference43.SAM1, @897, kindname.class, MethodReference43, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.invalid.mref: kindname.constructor, (compiler.misc.cant.apply.symbol: kindname.constructor, Foo, java.lang.Number, java.lang.String, kindname.class, MethodReference43.Foo, (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.String, java.lang.Number)))) +MethodReference43.java:47:11: compiler.err.cant.apply.symbol: kindname.method, m3, MethodReference43.SAM3, @941, kindname.class, MethodReference43, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.invalid.mref: kindname.constructor, (compiler.misc.cant.apply.symbol: kindname.constructor, Foo, java.lang.Number, java.lang.Object, kindname.class, MethodReference43.Foo, (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Object, java.lang.Number)))) +MethodReference43.java:49:9: compiler.err.ref.ambiguous: m5, kindname.method, m5(MethodReference43.SAM3), MethodReference43, kindname.method, m5(MethodReference43.SAM4), MethodReference43 +MethodReference43.java:49:11: compiler.err.cant.apply.symbol: kindname.method, m5, MethodReference43.SAM3, @985, kindname.class, MethodReference43, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.invalid.mref: kindname.constructor, (compiler.misc.cant.apply.symbol: kindname.constructor, Foo, java.lang.Number, java.lang.Object, kindname.class, MethodReference43.Foo, (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Object, java.lang.Number)))) 4 errors diff --git a/langtools/test/tools/javac/lambda/MethodReference44.java b/langtools/test/tools/javac/lambda/MethodReference44.java index be96ad2987b..3a62d84657a 100644 --- a/langtools/test/tools/javac/lambda/MethodReference44.java +++ b/langtools/test/tools/javac/lambda/MethodReference44.java @@ -1,33 +1,11 @@ /* - * Copyright (c) 2012, 2013, 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 + * @test /nodynamiccopyright/ * @bug 8003280 * @summary Add lambda tests * check that generic method reference is inferred when type parameters are omitted * @compile/fail/ref=MethodReference44.out -XDrawDiagnostics MethodReference44.java */ + public class MethodReference44 { static class SuperFoo { } diff --git a/langtools/test/tools/javac/lambda/MethodReference44.out b/langtools/test/tools/javac/lambda/MethodReference44.out index dbf1a394fde..56c991c21f9 100644 --- a/langtools/test/tools/javac/lambda/MethodReference44.out +++ b/langtools/test/tools/javac/lambda/MethodReference44.out @@ -1,4 +1,4 @@ -MethodReference44.java:62:11: compiler.err.cant.apply.symbol: kindname.method, g1, MethodReference44.SAM1, @1904, kindname.class, MethodReference44, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.eq.upper.bounds: X, java.lang.String, java.lang.Number)) -MethodReference44.java:64:11: compiler.err.cant.apply.symbol: kindname.method, g3, MethodReference44.SAM3, @1972, kindname.class, MethodReference44, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.eq.upper.bounds: X, java.lang.Object, java.lang.Number)) -MethodReference44.java:65:9: compiler.err.ref.ambiguous: g4, kindname.method, g4(MethodReference44.SAM2), MethodReference44, kindname.method, g4(MethodReference44.SAM3), MethodReference44 +MethodReference44.java:40:11: compiler.err.cant.apply.symbol: kindname.method, g1, MethodReference44.SAM1, @864, kindname.class, MethodReference44, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.eq.upper.bounds: X, java.lang.String, java.lang.Number)) +MethodReference44.java:42:11: compiler.err.cant.apply.symbol: kindname.method, g3, MethodReference44.SAM3, @932, kindname.class, MethodReference44, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.eq.upper.bounds: X, java.lang.Object, java.lang.Number)) +MethodReference44.java:43:9: compiler.err.ref.ambiguous: g4, kindname.method, g4(MethodReference44.SAM2), MethodReference44, kindname.method, g4(MethodReference44.SAM3), MethodReference44 3 errors diff --git a/langtools/test/tools/javac/lambda/MethodReference46.java b/langtools/test/tools/javac/lambda/MethodReference46.java index 0a9d42b8414..ee83739fcac 100644 --- a/langtools/test/tools/javac/lambda/MethodReference46.java +++ b/langtools/test/tools/javac/lambda/MethodReference46.java @@ -1,33 +1,11 @@ /* - * Copyright (c) 2012, 2013, 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 + * @test /nodynamiccopyright/ * @bug 8003280 * @summary Add lambda tests * check that generic method reference is inferred when type parameters are omitted * @compile/fail/ref=MethodReference46.out -XDrawDiagnostics MethodReference46.java */ + public class MethodReference46 { interface SAM1 { diff --git a/langtools/test/tools/javac/lambda/MethodReference46.out b/langtools/test/tools/javac/lambda/MethodReference46.out index 544affbd675..7d409282749 100644 --- a/langtools/test/tools/javac/lambda/MethodReference46.out +++ b/langtools/test/tools/javac/lambda/MethodReference46.out @@ -1,4 +1,4 @@ -MethodReference46.java:62:11: compiler.err.cant.apply.symbol: kindname.method, g1, MethodReference46.SAM1, @1849, kindname.class, MethodReference46, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.cant.apply.symbol: kindname.method, m, X, java.lang.String, kindname.class, MethodReference46, (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.String, java.lang.Number)))) -MethodReference46.java:64:11: compiler.err.cant.apply.symbol: kindname.method, g3, MethodReference46.SAM3, @1917, kindname.class, MethodReference46, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.cant.apply.symbol: kindname.method, m, X, java.lang.Object, kindname.class, MethodReference46, (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Object, java.lang.Number)))) -MethodReference46.java:65:9: compiler.err.ref.ambiguous: g4, kindname.method, g4(MethodReference46.SAM2), MethodReference46, kindname.method, g4(MethodReference46.SAM3), MethodReference46 +MethodReference46.java:40:11: compiler.err.cant.apply.symbol: kindname.method, g1, MethodReference46.SAM1, @809, kindname.class, MethodReference46, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.cant.apply.symbol: kindname.method, m, X, java.lang.String, kindname.class, MethodReference46, (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.String, java.lang.Number)))) +MethodReference46.java:42:11: compiler.err.cant.apply.symbol: kindname.method, g3, MethodReference46.SAM3, @877, kindname.class, MethodReference46, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.cant.apply.symbol: kindname.method, m, X, java.lang.Object, kindname.class, MethodReference46, (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Object, java.lang.Number)))) +MethodReference46.java:43:9: compiler.err.ref.ambiguous: g4, kindname.method, g4(MethodReference46.SAM2), MethodReference46, kindname.method, g4(MethodReference46.SAM3), MethodReference46 3 errors diff --git a/langtools/test/tools/javac/lambda/MethodReference48.java b/langtools/test/tools/javac/lambda/MethodReference48.java index 5247f4adb3b..153ec900700 100644 --- a/langtools/test/tools/javac/lambda/MethodReference48.java +++ b/langtools/test/tools/javac/lambda/MethodReference48.java @@ -1,33 +1,11 @@ /* - * Copyright (c) 2012, 2013, 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 + * @test /nodynamiccopyright/ * @bug 8003280 * @summary Add lambda tests * check that raw qualifier in unbound method reference is inferred from descriptor * @compile/fail/ref=MethodReference48.out -XDrawDiagnostics MethodReference48.java */ + public class MethodReference48 { static class Foo { diff --git a/langtools/test/tools/javac/lambda/MethodReference48.out b/langtools/test/tools/javac/lambda/MethodReference48.out index 732649e51f0..41b8a6be69f 100644 --- a/langtools/test/tools/javac/lambda/MethodReference48.out +++ b/langtools/test/tools/javac/lambda/MethodReference48.out @@ -1,3 +1,3 @@ -MethodReference48.java:60:11: compiler.err.cant.apply.symbol: kindname.method, g1, MethodReference48.SAM1, @1909, kindname.class, MethodReference48, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.ret.type.in.mref: (compiler.misc.inconvertible.types: java.lang.String, MethodReference48.Foo))) -MethodReference48.java:63:9: compiler.err.ref.ambiguous: g4, kindname.method, g4(MethodReference48.SAM2), MethodReference48, kindname.method, g4(MethodReference48.SAM3), MethodReference48 +MethodReference48.java:38:11: compiler.err.cant.apply.symbol: kindname.method, g1, MethodReference48.SAM1, @869, kindname.class, MethodReference48, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.ret.type.in.mref: (compiler.misc.inconvertible.types: java.lang.String, MethodReference48.Foo))) +MethodReference48.java:41:9: compiler.err.ref.ambiguous: g4, kindname.method, g4(MethodReference48.SAM2), MethodReference48, kindname.method, g4(MethodReference48.SAM3), MethodReference48 2 errors From 76033b1a3738d01a7778b2e595df222a1370b34a Mon Sep 17 00:00:00 2001 From: Harold Seigel Date: Mon, 9 Sep 2013 14:44:37 -0400 Subject: [PATCH 107/210] 8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures Add checks for duplicates and issue errors when detected. Reviewed-by: coleenp, zgu --- .../share/vm/classfile/classFileParser.cpp | 71 +++++++++++++++---- 1 file changed, 56 insertions(+), 15 deletions(-) diff --git a/hotspot/src/share/vm/classfile/classFileParser.cpp b/hotspot/src/share/vm/classfile/classFileParser.cpp index 0705c5f14d6..7b79a1ab274 100644 --- a/hotspot/src/share/vm/classfile/classFileParser.cpp +++ b/hotspot/src/share/vm/classfile/classFileParser.cpp @@ -888,6 +888,7 @@ void ClassFileParser::parse_field_attributes(u2 attributes_count, int runtime_visible_type_annotations_length = 0; u1* runtime_invisible_type_annotations = NULL; int runtime_invisible_type_annotations_length = 0; + bool runtime_invisible_type_annotations_exists = false; while (attributes_count--) { cfs->guarantee_more(6, CHECK); // attribute_name_index, attribute_length u2 attribute_name_index = cfs->get_u2_fast(); @@ -946,15 +947,27 @@ void ClassFileParser::parse_field_attributes(u2 attributes_count, assert(runtime_invisible_annotations != NULL, "null invisible annotations"); cfs->skip_u1(runtime_invisible_annotations_length, CHECK); } else if (attribute_name == vmSymbols::tag_runtime_visible_type_annotations()) { + if (runtime_visible_type_annotations != NULL) { + classfile_parse_error( + "Multiple RuntimeVisibleTypeAnnotations attributes for field in class file %s", CHECK); + } runtime_visible_type_annotations_length = attribute_length; runtime_visible_type_annotations = cfs->get_u1_buffer(); assert(runtime_visible_type_annotations != NULL, "null visible type annotations"); cfs->skip_u1(runtime_visible_type_annotations_length, CHECK); - } else if (PreserveAllAnnotations && attribute_name == vmSymbols::tag_runtime_invisible_type_annotations()) { - runtime_invisible_type_annotations_length = attribute_length; - runtime_invisible_type_annotations = cfs->get_u1_buffer(); - assert(runtime_invisible_type_annotations != NULL, "null invisible type annotations"); - cfs->skip_u1(runtime_invisible_type_annotations_length, CHECK); + } else if (attribute_name == vmSymbols::tag_runtime_invisible_type_annotations()) { + if (runtime_invisible_type_annotations_exists) { + classfile_parse_error( + "Multiple RuntimeInvisibleTypeAnnotations attributes for field in class file %s", CHECK); + } else { + runtime_invisible_type_annotations_exists = true; + } + if (PreserveAllAnnotations) { + runtime_invisible_type_annotations_length = attribute_length; + runtime_invisible_type_annotations = cfs->get_u1_buffer(); + assert(runtime_invisible_type_annotations != NULL, "null invisible type annotations"); + } + cfs->skip_u1(attribute_length, CHECK); } else { cfs->skip_u1(attribute_length, CHECK); // Skip unknown attributes } @@ -2060,6 +2073,7 @@ methodHandle ClassFileParser::parse_method(bool is_interface, int runtime_visible_type_annotations_length = 0; u1* runtime_invisible_type_annotations = NULL; int runtime_invisible_type_annotations_length = 0; + bool runtime_invisible_type_annotations_exists = false; u1* annotation_default = NULL; int annotation_default_length = 0; @@ -2316,16 +2330,30 @@ methodHandle ClassFileParser::parse_method(bool is_interface, assert(annotation_default != NULL, "null annotation default"); cfs->skip_u1(annotation_default_length, CHECK_(nullHandle)); } else if (method_attribute_name == vmSymbols::tag_runtime_visible_type_annotations()) { + if (runtime_visible_type_annotations != NULL) { + classfile_parse_error( + "Multiple RuntimeVisibleTypeAnnotations attributes for method in class file %s", + CHECK_(nullHandle)); + } runtime_visible_type_annotations_length = method_attribute_length; runtime_visible_type_annotations = cfs->get_u1_buffer(); assert(runtime_visible_type_annotations != NULL, "null visible type annotations"); // No need for the VM to parse Type annotations cfs->skip_u1(runtime_visible_type_annotations_length, CHECK_(nullHandle)); - } else if (PreserveAllAnnotations && method_attribute_name == vmSymbols::tag_runtime_invisible_type_annotations()) { - runtime_invisible_type_annotations_length = method_attribute_length; - runtime_invisible_type_annotations = cfs->get_u1_buffer(); - assert(runtime_invisible_type_annotations != NULL, "null invisible type annotations"); - cfs->skip_u1(runtime_invisible_type_annotations_length, CHECK_(nullHandle)); + } else if (method_attribute_name == vmSymbols::tag_runtime_invisible_type_annotations()) { + if (runtime_invisible_type_annotations_exists) { + classfile_parse_error( + "Multiple RuntimeInvisibleTypeAnnotations attributes for method in class file %s", + CHECK_(nullHandle)); + } else { + runtime_invisible_type_annotations_exists = true; + } + if (PreserveAllAnnotations) { + runtime_invisible_type_annotations_length = method_attribute_length; + runtime_invisible_type_annotations = cfs->get_u1_buffer(); + assert(runtime_invisible_type_annotations != NULL, "null invisible type annotations"); + } + cfs->skip_u1(method_attribute_length, CHECK_(nullHandle)); } else { // Skip unknown attributes cfs->skip_u1(method_attribute_length, CHECK_(nullHandle)); @@ -2818,6 +2846,7 @@ void ClassFileParser::parse_classfile_attributes(ClassFileParser::ClassAnnotatio int runtime_visible_type_annotations_length = 0; u1* runtime_invisible_type_annotations = NULL; int runtime_invisible_type_annotations_length = 0; + bool runtime_invisible_type_annotations_exists = false; u1* inner_classes_attribute_start = NULL; u4 inner_classes_attribute_length = 0; u2 enclosing_method_class_index = 0; @@ -2921,16 +2950,28 @@ void ClassFileParser::parse_classfile_attributes(ClassFileParser::ClassAnnotatio parsed_bootstrap_methods_attribute = true; parse_classfile_bootstrap_methods_attribute(attribute_length, CHECK); } else if (tag == vmSymbols::tag_runtime_visible_type_annotations()) { + if (runtime_visible_type_annotations != NULL) { + classfile_parse_error( + "Multiple RuntimeVisibleTypeAnnotations attributes in class file %s", CHECK); + } runtime_visible_type_annotations_length = attribute_length; runtime_visible_type_annotations = cfs->get_u1_buffer(); assert(runtime_visible_type_annotations != NULL, "null visible type annotations"); // No need for the VM to parse Type annotations cfs->skip_u1(runtime_visible_type_annotations_length, CHECK); - } else if (PreserveAllAnnotations && tag == vmSymbols::tag_runtime_invisible_type_annotations()) { - runtime_invisible_type_annotations_length = attribute_length; - runtime_invisible_type_annotations = cfs->get_u1_buffer(); - assert(runtime_invisible_type_annotations != NULL, "null invisible type annotations"); - cfs->skip_u1(runtime_invisible_type_annotations_length, CHECK); + } else if (tag == vmSymbols::tag_runtime_invisible_type_annotations()) { + if (runtime_invisible_type_annotations_exists) { + classfile_parse_error( + "Multiple RuntimeInvisibleTypeAnnotations attributes in class file %s", CHECK); + } else { + runtime_invisible_type_annotations_exists = true; + } + if (PreserveAllAnnotations) { + runtime_invisible_type_annotations_length = attribute_length; + runtime_invisible_type_annotations = cfs->get_u1_buffer(); + assert(runtime_invisible_type_annotations != NULL, "null invisible type annotations"); + } + cfs->skip_u1(attribute_length, CHECK); } else { // Unknown attribute cfs->skip_u1(attribute_length, CHECK); From 5b76a0d2165048cdfbebdc44a6c2d182bf5637c3 Mon Sep 17 00:00:00 2001 From: Eric McCorkle Date: Mon, 9 Sep 2013 16:26:55 -0400 Subject: [PATCH 108/210] 8022322: Reject default and static methods in annotation Causes javac to reject static and default method declarations inside an annotation Reviewed-by: jjg --- .../share/classes/com/sun/tools/javac/code/Flags.java | 3 ++- .../share/classes/com/sun/tools/javac/comp/Check.java | 9 ++++++--- .../test/tools/javac/annotations/neg/NoDefault.java | 9 +++++++++ .../test/tools/javac/annotations/neg/NoDefault.out | 3 +++ .../tools/javac/annotations/neg/NoDefaultAbstract.java | 9 +++++++++ .../tools/javac/annotations/neg/NoDefaultAbstract.out | 2 ++ .../test/tools/javac/annotations/neg/NoStatic.java | 10 ++++++++++ .../test/tools/javac/annotations/neg/NoStatic.out | 3 +++ .../tools/javac/annotations/neg/NoStaticAbstract.java | 10 ++++++++++ .../tools/javac/annotations/neg/NoStaticAbstract.out | 2 ++ 10 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 langtools/test/tools/javac/annotations/neg/NoDefault.java create mode 100644 langtools/test/tools/javac/annotations/neg/NoDefault.out create mode 100644 langtools/test/tools/javac/annotations/neg/NoDefaultAbstract.java create mode 100644 langtools/test/tools/javac/annotations/neg/NoDefaultAbstract.out create mode 100644 langtools/test/tools/javac/annotations/neg/NoStatic.java create mode 100644 langtools/test/tools/javac/annotations/neg/NoStatic.out create mode 100644 langtools/test/tools/javac/annotations/neg/NoStaticAbstract.java create mode 100644 langtools/test/tools/javac/annotations/neg/NoStaticAbstract.out diff --git a/langtools/src/share/classes/com/sun/tools/javac/code/Flags.java b/langtools/src/share/classes/com/sun/tools/javac/code/Flags.java index b2da2807363..3a4084ed2a8 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/code/Flags.java +++ b/langtools/src/share/classes/com/sun/tools/javac/code/Flags.java @@ -97,7 +97,6 @@ public class Flags { public static final int MANDATED = 1<<15; public static final int StandardFlags = 0x0fff; - public static final int ModifierFlags = StandardFlags & ~INTERFACE; // Because the following access flags are overloaded with other // bit positions, we translate them when reading and writing class @@ -287,7 +286,9 @@ public class Flags { SYNCHRONIZED | FINAL | STRICTFP; public static final long ExtendedStandardFlags = (long)StandardFlags | DEFAULT, + ModifierFlags = ((long)StandardFlags & ~INTERFACE) | DEFAULT, InterfaceMethodMask = ABSTRACT | STATIC | PUBLIC | STRICTFP | DEFAULT, + AnnotationTypeElementMask = FINAL | ABSTRACT | PUBLIC | STRICTFP, LocalVarFlags = FINAL | PARAMETER; diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java b/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java index 5529627ed90..59d6c7b4468 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java @@ -1050,6 +1050,7 @@ public class Check { long checkFlags(DiagnosticPosition pos, long flags, Symbol sym, JCTree tree) { long mask; long implicit = 0; + switch (sym.kind) { case VAR: if (sym.owner.kind != TYP) @@ -1070,7 +1071,10 @@ public class Check { } else mask = ConstructorFlags; } else if ((sym.owner.flags_field & INTERFACE) != 0) { - if ((flags & (DEFAULT | STATIC)) != 0) { + if ((sym.owner.flags_field & ANNOTATION) != 0) { + mask = AnnotationTypeElementMask; + implicit = PUBLIC | ABSTRACT; + } else if ((flags & (DEFAULT | STATIC)) != 0) { mask = InterfaceMethodMask; implicit = PUBLIC; if ((flags & DEFAULT) != 0) { @@ -1079,8 +1083,7 @@ public class Check { } else { mask = implicit = InterfaceMethodFlags; } - } - else { + } else { mask = MethodFlags; } // Imply STRICTFP if owner has STRICTFP set. diff --git a/langtools/test/tools/javac/annotations/neg/NoDefault.java b/langtools/test/tools/javac/annotations/neg/NoDefault.java new file mode 100644 index 00000000000..282bc98bf3a --- /dev/null +++ b/langtools/test/tools/javac/annotations/neg/NoDefault.java @@ -0,0 +1,9 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8022322 + * @summary Default methods are not allowed in an annotation. + * @compile/fail/ref=NoDefault.out -XDrawDiagnostics NoDefault.java + */ +@interface NoDefault { + default int m() {return 0;} +} diff --git a/langtools/test/tools/javac/annotations/neg/NoDefault.out b/langtools/test/tools/javac/annotations/neg/NoDefault.out new file mode 100644 index 00000000000..ffcbf823351 --- /dev/null +++ b/langtools/test/tools/javac/annotations/neg/NoDefault.out @@ -0,0 +1,3 @@ +NoDefault.java:8:17: compiler.err.mod.not.allowed.here: default +NoDefault.java:8:21: compiler.err.intf.meth.cant.have.body +2 errors \ No newline at end of file diff --git a/langtools/test/tools/javac/annotations/neg/NoDefaultAbstract.java b/langtools/test/tools/javac/annotations/neg/NoDefaultAbstract.java new file mode 100644 index 00000000000..6c288810fe1 --- /dev/null +++ b/langtools/test/tools/javac/annotations/neg/NoDefaultAbstract.java @@ -0,0 +1,9 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8022322 + * @summary Default methods are not allowed in an annotation. + * @compile/fail/ref=NoDefaultAbstract.out -XDrawDiagnostics NoDefaultAbstract.java + */ +@interface NoDefaultAbstract { + default int m(); +} diff --git a/langtools/test/tools/javac/annotations/neg/NoDefaultAbstract.out b/langtools/test/tools/javac/annotations/neg/NoDefaultAbstract.out new file mode 100644 index 00000000000..ea445c68e13 --- /dev/null +++ b/langtools/test/tools/javac/annotations/neg/NoDefaultAbstract.out @@ -0,0 +1,2 @@ +NoDefaultAbstract.java:8:17: compiler.err.mod.not.allowed.here: default +1 error diff --git a/langtools/test/tools/javac/annotations/neg/NoStatic.java b/langtools/test/tools/javac/annotations/neg/NoStatic.java new file mode 100644 index 00000000000..3a62dc7c748 --- /dev/null +++ b/langtools/test/tools/javac/annotations/neg/NoStatic.java @@ -0,0 +1,10 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8022322 + * @summary Static methods are not allowed in an annotation. + * @compile/fail/ref=NoStatic.out -XDrawDiagnostics NoStatic.java + */ + +@interface NoStatic { + static int m() {return 0;} +} diff --git a/langtools/test/tools/javac/annotations/neg/NoStatic.out b/langtools/test/tools/javac/annotations/neg/NoStatic.out new file mode 100644 index 00000000000..8d9d3131915 --- /dev/null +++ b/langtools/test/tools/javac/annotations/neg/NoStatic.out @@ -0,0 +1,3 @@ +NoStatic.java:9:16: compiler.err.mod.not.allowed.here: static +NoStatic.java:9:20: compiler.err.intf.meth.cant.have.body +2 errors diff --git a/langtools/test/tools/javac/annotations/neg/NoStaticAbstract.java b/langtools/test/tools/javac/annotations/neg/NoStaticAbstract.java new file mode 100644 index 00000000000..af27fa75b9a --- /dev/null +++ b/langtools/test/tools/javac/annotations/neg/NoStaticAbstract.java @@ -0,0 +1,10 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8022322 + * @summary Static methods are not allowed in an annotation. + * @compile/fail/ref=NoStaticAbstract.out -XDrawDiagnostics NoStaticAbstract.java + */ + +@interface NoStaticAbstract { + static int m(); +} diff --git a/langtools/test/tools/javac/annotations/neg/NoStaticAbstract.out b/langtools/test/tools/javac/annotations/neg/NoStaticAbstract.out new file mode 100644 index 00000000000..694cea1771f --- /dev/null +++ b/langtools/test/tools/javac/annotations/neg/NoStaticAbstract.out @@ -0,0 +1,2 @@ +NoStaticAbstract.java:9:16: compiler.err.mod.not.allowed.here: static +1 error From b03e5fc290b9d39ced09836a2c63948f2a81c372 Mon Sep 17 00:00:00 2001 From: Brian Goetz Date: Mon, 9 Sep 2013 17:11:55 -0400 Subject: [PATCH 109/210] 8015322: Javac template test framework Putback of the javac template test framework from the Lambda repository Reviewed-by: jjg --- langtools/README | 2 +- langtools/test/lib/combo/TEST.properties | 4 + .../combo/tools/javac/combo/Diagnostics.java | 82 ++ .../javac/combo/JavacTemplateTestBase.java | 362 ++++++ .../lib/combo/tools/javac/combo/Template.java | 112 ++ .../combo/tools/javac/combo/TemplateTest.java | 94 ++ .../template_tests/BridgeMethodTestCase.java | 421 +++++++ .../BridgeMethodsTemplateTest.java | 1082 +++++++++++++++++ .../bridge/template_tests/TEST.properties | 7 + 9 files changed, 2165 insertions(+), 1 deletion(-) create mode 100644 langtools/test/lib/combo/TEST.properties create mode 100644 langtools/test/lib/combo/tools/javac/combo/Diagnostics.java create mode 100644 langtools/test/lib/combo/tools/javac/combo/JavacTemplateTestBase.java create mode 100644 langtools/test/lib/combo/tools/javac/combo/Template.java create mode 100644 langtools/test/lib/combo/tools/javac/combo/TemplateTest.java create mode 100644 langtools/test/tools/javac/lambda/bridge/template_tests/BridgeMethodTestCase.java create mode 100644 langtools/test/tools/javac/lambda/bridge/template_tests/BridgeMethodsTemplateTest.java create mode 100644 langtools/test/tools/javac/lambda/bridge/template_tests/TEST.properties diff --git a/langtools/README b/langtools/README index bc8873178ef..94beb071e92 100644 --- a/langtools/README +++ b/langtools/README @@ -32,7 +32,7 @@ tests that the compiler performs according to the specifications in JLS and JVMS. In addition, there is a substantial collection of regression and unit -tests for all the tools in the maain langtools test/ directory. +tests for all the tools in the main langtools test/ directory. Finally, there is a small set of tests to do basic validation of a build of the langtools workspace for use by JDK. These tests check the contents diff --git a/langtools/test/lib/combo/TEST.properties b/langtools/test/lib/combo/TEST.properties new file mode 100644 index 00000000000..341ff2af467 --- /dev/null +++ b/langtools/test/lib/combo/TEST.properties @@ -0,0 +1,4 @@ +# This file identifies root(s) of the test-ng hierarchy. + + +TestNG.dirs = . diff --git a/langtools/test/lib/combo/tools/javac/combo/Diagnostics.java b/langtools/test/lib/combo/tools/javac/combo/Diagnostics.java new file mode 100644 index 00000000000..6f1774d6572 --- /dev/null +++ b/langtools/test/lib/combo/tools/javac/combo/Diagnostics.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2013, 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. + */ +package tools.javac.combo; + +import javax.tools.Diagnostic; +import javax.tools.JavaFileObject; +import java.util.ArrayList; +import java.util.List; + +import static java.util.stream.Collectors.toList; + +/** +* A container for compiler diagnostics, separated into errors and warnings, + * used by JavacTemplateTestBase. + * + * @author Brian Goetz +*/ +public class Diagnostics implements javax.tools.DiagnosticListener { + + protected List> diags = new ArrayList<>(); + protected boolean foundErrors = false; + + public void report(Diagnostic diagnostic) { + diags.add(diagnostic); + foundErrors = foundErrors || diagnostic.getKind() == Diagnostic.Kind.ERROR; + } + + /** Were there any errors found? */ + public boolean errorsFound() { + return foundErrors; + } + + /** Get all diagnostic keys */ + public List keys() { + return diags.stream() + .map(Diagnostic::getCode) + .collect(toList()); + } + + /** Do the diagnostics contain the specified error key? */ + public boolean containsErrorKey(String key) { + return diags.stream() + .filter(d -> d.getKind() == Diagnostic.Kind.ERROR) + .anyMatch(d -> d.getCode().equals(key)); + } + + /** Get the error keys */ + public List errorKeys() { + return diags.stream() + .filter(d -> d.getKind() == Diagnostic.Kind.ERROR) + .map(Diagnostic::getCode) + .collect(toList()); + } + + public String toString() { return keys().toString(); } + + /** Clear all diagnostic state */ + public void reset() { + diags.clear(); + foundErrors = false; + } +} diff --git a/langtools/test/lib/combo/tools/javac/combo/JavacTemplateTestBase.java b/langtools/test/lib/combo/tools/javac/combo/JavacTemplateTestBase.java new file mode 100644 index 00000000000..e2a8bd7cac3 --- /dev/null +++ b/langtools/test/lib/combo/tools/javac/combo/JavacTemplateTestBase.java @@ -0,0 +1,362 @@ +/* + * Copyright (c) 2013, 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. + */ +package tools.javac.combo; + +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.atomic.AtomicInteger; +import javax.tools.JavaCompiler; +import javax.tools.JavaFileObject; +import javax.tools.SimpleJavaFileObject; +import javax.tools.StandardJavaFileManager; +import javax.tools.StandardLocation; +import javax.tools.ToolProvider; + +import com.sun.source.util.JavacTask; +import com.sun.tools.javac.util.Pair; +import org.testng.ITestResult; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.AfterSuite; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import static org.testng.Assert.fail; + +/** + * Base class for template-driven TestNG javac tests that support on-the-fly + * source file generation, compilation, classloading, execution, and separate + * compilation. + * + *

    Manages a set of templates (which have embedded tags of the form + * {@code #\{NAME\}}), source files (which are also templates), and compile + * options. Test cases can register templates and source files, cause them to + * be compiled, validate whether the set of diagnostic messages output by the + * compiler is correct, and optionally load and run the compiled classes. + * + * @author Brian Goetz + */ +@Test +public abstract class JavacTemplateTestBase { + private static final Set suiteErrors = Collections.synchronizedSet(new HashSet<>()); + private static final AtomicInteger counter = new AtomicInteger(); + private static final File root = new File("gen"); + private static final File nullDir = new File("empty"); + + protected final Map templates = new HashMap<>(); + protected final Diagnostics diags = new Diagnostics(); + protected final List> sourceFiles = new ArrayList<>(); + protected final List compileOptions = new ArrayList<>(); + protected final List classpaths = new ArrayList<>(); + protected final Template.Resolver defaultResolver = new MapResolver(templates); + + private Template.Resolver currentResolver = defaultResolver; + + /** Add a template with a specified name */ + protected void addTemplate(String name, Template t) { + templates.put(name, t); + } + + /** Add a template with a specified name */ + protected void addTemplate(String name, String s) { + templates.put(name, new StringTemplate(s)); + } + + /** Add a source file */ + protected void addSourceFile(String name, Template t) { + sourceFiles.add(new Pair<>(name, t)); + } + + /** Add a File to the class path to be used when loading classes; File values + * will generally be the result of a previous call to {@link #compile()}. + * This enables testing of separate compilation scenarios if the class path + * is set up properly. + */ + protected void addClassPath(File path) { + classpaths.add(path); + } + + /** + * Add a set of compilation command-line options + */ + protected void addCompileOptions(String... opts) { + Collections.addAll(compileOptions, opts); + } + + /** Reset the compile options to the default (empty) value */ + protected void resetCompileOptions() { compileOptions.clear(); } + + /** Remove all templates */ + protected void resetTemplates() { templates.clear(); } + + /** Remove accumulated diagnostics */ + protected void resetDiagnostics() { diags.reset(); } + + /** Remove all source files */ + protected void resetSourceFiles() { sourceFiles.clear(); } + + /** Remove registered class paths */ + protected void resetClassPaths() { classpaths.clear(); } + + // Before each test method, reset everything + @BeforeMethod + public void reset() { + resetCompileOptions(); + resetDiagnostics(); + resetSourceFiles(); + resetTemplates(); + resetClassPaths(); + } + + // After each test method, if the test failed, capture source files and diagnostics and put them in the log + @AfterMethod + public void copyErrors(ITestResult result) { + if (!result.isSuccess()) { + suiteErrors.addAll(diags.errorKeys()); + + List list = new ArrayList<>(); + Collections.addAll(list, result.getParameters()); + list.add("Test case: " + getTestCaseDescription()); + for (Pair e : sourceFiles) + list.add("Source file " + e.fst + ": " + e.snd); + if (diags.errorsFound()) + list.add("Compile diagnostics: " + diags.toString()); + result.setParameters(list.toArray(new Object[list.size()])); + } + } + + @AfterSuite + // After the suite is done, dump any errors to output + public void dumpErrors() { + if (!suiteErrors.isEmpty()) + System.err.println("Errors found in test suite: " + suiteErrors); + } + + /** + * Get a description of this test case; since test cases may be combinatorially + * generated, this should include all information needed to describe the test case + */ + protected String getTestCaseDescription() { + return this.toString(); + } + + /** Assert that all previous calls to compile() succeeded */ + protected void assertCompileSucceeded() { + if (diags.errorsFound()) + fail("Expected successful compilation"); + } + + /** + * If the provided boolean is true, assert all previous compiles succeeded, + * otherwise assert that a compile failed. + * */ + protected void assertCompileSucceededIff(boolean b) { + if (b) + assertCompileSucceeded(); + else + assertCompileFailed(); + } + + /** Assert that a previous call to compile() failed */ + protected void assertCompileFailed() { + if (!diags.errorsFound()) + fail("Expected failed compilation"); + } + + /** Assert that a previous call to compile() failed with a specific error key */ + protected void assertCompileFailed(String message) { + if (!diags.errorsFound()) + fail("Expected failed compilation: " + message); + } + + /** Assert that a previous call to compile() failed with all of the specified error keys */ + protected void assertCompileErrors(String... keys) { + if (!diags.errorsFound()) + fail("Expected failed compilation"); + for (String k : keys) + if (!diags.containsErrorKey(k)) + fail("Expected compilation error " + k); + } + + /** Convert an object, which may be a Template or a String, into a Template */ + protected Template asTemplate(Object o) { + if (o instanceof Template) + return (Template) o; + else if (o instanceof String) + return new StringTemplate((String) o); + else + return new StringTemplate(o.toString()); + } + + /** Compile all registered source files */ + protected void compile() throws IOException { + compile(false); + } + + /** Compile all registered source files, optionally generating class files + * and returning a File describing the directory to which they were written */ + protected File compile(boolean generate) throws IOException { + List files = new ArrayList<>(); + for (Pair e : sourceFiles) + files.add(new FileAdapter(e.fst, asTemplate(e.snd))); + return compile(classpaths, files, generate); + } + + /** Compile all registered source files, using the provided list of class paths + * for finding required classfiles, optionally generating class files + * and returning a File describing the directory to which they were written */ + protected File compile(List classpaths, boolean generate) throws IOException { + List files = new ArrayList<>(); + for (Pair e : sourceFiles) + files.add(new FileAdapter(e.fst, asTemplate(e.snd))); + return compile(classpaths, files, generate); + } + + private File compile(List classpaths, List files, boolean generate) throws IOException { + JavaCompiler systemJavaCompiler = ToolProvider.getSystemJavaCompiler(); + StandardJavaFileManager fm = systemJavaCompiler.getStandardFileManager(null, null, null); + if (classpaths.size() > 0) + fm.setLocation(StandardLocation.CLASS_PATH, classpaths); + JavacTask ct = (JavacTask) systemJavaCompiler.getTask(null, fm, diags, compileOptions, null, files); + if (generate) { + File destDir = new File(root, Integer.toString(counter.incrementAndGet())); + // @@@ Assert that this directory didn't exist, or start counter at max+1 + destDir.mkdirs(); + fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(destDir)); + ct.generate(); + return destDir; + } + else { + ct.analyze(); + return nullDir; + } + } + + /** Load the given class using the provided list of class paths */ + protected Class loadClass(String className, File... destDirs) { + try { + List list = new ArrayList<>(); + for (File f : destDirs) + list.add(new URL("file:" + f.toString().replace("\\", "/") + "/")); + return Class.forName(className, true, new URLClassLoader(list.toArray(new URL[list.size()]))); + } catch (ClassNotFoundException | MalformedURLException e) { + throw new RuntimeException("Error loading class " + className, e); + } + } + + /** An implementation of Template which is backed by a String */ + protected class StringTemplate implements Template { + protected final String template; + + public StringTemplate(String template) { + this.template = template; + } + + public String expand(String selector) { + return Behavior.expandTemplate(template, currentResolver); + } + + public String toString() { + return expand(""); + } + + public StringTemplate with(final String key, final String value) { + return new StringTemplateWithResolver(template, new KeyResolver(key, value)); + } + + } + + /** An implementation of Template which is backed by a String and which + * encapsulates a Resolver for resolving embedded tags. */ + protected class StringTemplateWithResolver extends StringTemplate { + private final Resolver localResolver; + + public StringTemplateWithResolver(String template, Resolver localResolver) { + super(template); + this.localResolver = localResolver; + } + + @Override + public String expand(String selector) { + Resolver saved = currentResolver; + currentResolver = new ChainedResolver(currentResolver, localResolver); + try { + return super.expand(selector); + } + finally { + currentResolver = saved; + } + } + + @Override + public StringTemplate with(String key, String value) { + return new StringTemplateWithResolver(template, new ChainedResolver(localResolver, new KeyResolver(key, value))); + } + } + + /** A Resolver which uses a Map to resolve tags */ + private class KeyResolver implements Template.Resolver { + private final String key; + private final String value; + + public KeyResolver(String key, String value) { + this.key = key; + this.value = value; + } + + @Override + public Template lookup(String k) { + return key.equals(k) ? new StringTemplate(value) : null; + } + } + + private class FileAdapter extends SimpleJavaFileObject { + private final String filename; + private final Template template; + + public FileAdapter(String filename, Template template) { + super(URI.create("myfo:/" + filename), Kind.SOURCE); + this.template = template; + this.filename = filename; + } + + public CharSequence getCharContent(boolean ignoreEncodingErrors) { + return toString(); + } + + public String toString() { + return Template.Behavior.expandTemplate(template.expand(filename), defaultResolver); + } + } +} diff --git a/langtools/test/lib/combo/tools/javac/combo/Template.java b/langtools/test/lib/combo/tools/javac/combo/Template.java new file mode 100644 index 00000000000..8ad4d72edcb --- /dev/null +++ b/langtools/test/lib/combo/tools/javac/combo/Template.java @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2013, 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. + */ +package tools.javac.combo; + +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * A template into which tags of the form {@code #\{KEY\}} or + * {@code #\{KEY.SUBKEY\}} can be expanded. + */ +public interface Template { + String expand(String selector); + + interface Resolver { + public Template lookup(String key); + } + + public static class Behavior { + /* Looks for expandable keys. An expandable key can take the form: + * #{MAJOR} + * #{MAJOR.MINOR} + * where MAJOR can be IDENTIFIER or IDENTIFIER[NUMERIC_INDEX] + * and MINOR can be an identifier + */ + private static final Pattern pattern = Pattern.compile("#\\{([A-Z_][A-Z0-9_]*(?:\\[\\d+\\])?)(?:\\.([A-Z_][A-Z0-9_]*))?\\}"); + + public static String expandTemplate(String template, final Map vars) { + return expandTemplate(template, new MapResolver(vars)); + } + + public static String expandTemplate(String template, Resolver res) { + CharSequence in = template; + StringBuffer out = new StringBuffer(); + while (true) { + boolean more = false; + Matcher m = pattern.matcher(in); + while (m.find()) { + String major = m.group(1); + String minor = m.group(2); + Template key = res.lookup(major); + if (key == null) + throw new IllegalStateException("Unknown major key " + major); + + String replacement = key.expand(minor == null ? "" : minor); + more |= pattern.matcher(replacement).find(); + m.appendReplacement(out, replacement); + } + m.appendTail(out); + if (!more) + return out.toString(); + else { + in = out; + out = new StringBuffer(); + } + } + } + + } +} + +class MapResolver implements Template.Resolver { + private final Map vars; + + public MapResolver(Map vars) {this.vars = vars;} + + public Template lookup(String key) { + return vars.get(key); + } +} + +class ChainedResolver implements Template.Resolver { + private final Template.Resolver upstreamResolver, thisResolver; + + public ChainedResolver(Template.Resolver upstreamResolver, Template.Resolver thisResolver) { + this.upstreamResolver = upstreamResolver; + this.thisResolver = thisResolver; + } + + public Template.Resolver getUpstreamResolver() { + return upstreamResolver; + } + + @Override + public Template lookup(String key) { + Template result = thisResolver.lookup(key); + if (result == null) + result = upstreamResolver.lookup(key); + return result; + } +} diff --git a/langtools/test/lib/combo/tools/javac/combo/TemplateTest.java b/langtools/test/lib/combo/tools/javac/combo/TemplateTest.java new file mode 100644 index 00000000000..356456872dd --- /dev/null +++ b/langtools/test/lib/combo/tools/javac/combo/TemplateTest.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2013, 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. + * + */ +package tools.javac.combo; + +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + +import java.util.HashMap; +import java.util.Map; + +import static org.testng.Assert.assertEquals; + +/** + * TemplateTest + */ +@Test +public class TemplateTest { + Map vars = new HashMap<>(); + + @BeforeTest + void before() { vars.clear(); } + + private void assertTemplate(String expected, String template) { + String result = Template.Behavior.expandTemplate(template, vars); + assertEquals(result, expected, "for " + template); + } + + private String dotIf(String s) { + return s == null || s.isEmpty() ? "" : "." + s; + } + + public void testTemplateExpansion() { + vars.put("A", s -> "a" + dotIf(s)); + vars.put("B", s -> "b" + dotIf(s)); + vars.put("C", s -> "#{A}#{B}"); + vars.put("D", s -> "#{A" + dotIf(s) + "}#{B" + dotIf(s) + "}"); + vars.put("_D", s -> "d"); + + assertTemplate("", ""); + assertTemplate("foo", "foo"); + assertTemplate("a", "#{A}"); + assertTemplate("a", "#{A.}"); + assertTemplate("a.FOO", "#{A.FOO}"); + assertTemplate("aa", "#{A}#{A}"); + assertTemplate("ab", "#{C}"); + assertTemplate("ab", "#{C.FOO}"); + assertTemplate("ab", "#{C.}"); + assertTemplate("a.FOOb.FOO", "#{D.FOO}"); + assertTemplate("ab", "#{D}"); + assertTemplate("d", "#{_D}"); + assertTemplate("#{A", "#{A"); + } + + public void testIndexedTemplate() { + vars.put("A[0]", s -> "a" ); + vars.put("A[1]", s -> "b" ); + vars.put("A[2]", s -> "c" ); + vars.put("X", s -> "0"); + assertTemplate("a", "#{A[0]}"); + assertTemplate("b", "#{A[1]}"); + assertTemplate("c", "#{A[2]}"); + } + + public void testAngleBrackets() { + vars.put("X", s -> "xyz"); + assertTemplate("List ls = xyz;", "List ls = #{X};"); + } + + @Test(expectedExceptions = IllegalStateException.class ) + public void testUnknownKey() { + assertTemplate("#{Q}", "#{Q}"); + } +} diff --git a/langtools/test/tools/javac/lambda/bridge/template_tests/BridgeMethodTestCase.java b/langtools/test/tools/javac/lambda/bridge/template_tests/BridgeMethodTestCase.java new file mode 100644 index 00000000000..964a59658b1 --- /dev/null +++ b/langtools/test/tools/javac/lambda/bridge/template_tests/BridgeMethodTestCase.java @@ -0,0 +1,421 @@ +/* + * Copyright (c) 2013, 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.io.File; +import java.io.IOException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.StringJoiner; + +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import tools.javac.combo.*; + +import static org.testng.Assert.fail; + +/** + * BridgeMethodTestCase -- used for asserting linkage to bridges under separate compilation. + * + * Example test case: + * public void test1() throws IOException, ReflectiveOperationException { + * compileSpec("C(Bc1(A))"); + * assertLinkage("C", LINKAGE_ERROR, "B1"); + * recompileSpec("C(Bc1(Ac0))", "A"); + * assertLinkage("C", "A0", "B1"); + * } + * + * This compiles A, B, and C, asserts that C.m()Object does not exist, asserts + * that C.m()Number eventually invokes B.m()Number, recompiles B, and then asserts + * that the result of calling C.m()Object now arrives at A. + * + * @author Brian Goetz + */ + +@Test +public abstract class BridgeMethodTestCase extends JavacTemplateTestBase { + + private static final String TYPE_LETTERS = "ABCDIJK"; + + private static final String BASE_INDEX_CLASS = "class C0 {\n" + + " int val;\n" + + " C0(int val) { this.val = val; }\n" + + " public int getVal() { return val; }\n" + + "}\n"; + private static final String INDEX_CLASS_TEMPLATE = "class C#ID extends C#PREV {\n" + + " C#ID(int val) { super(val); }\n" + + "}\n"; + + + + protected static String LINKAGE_ERROR = "-1"; + + private List compileDirs = new ArrayList<>(); + + /** + * Compile all the classes in a class spec, and put them on the classpath. + * + * The spec is the specification for a nest of classes, using the following notation + * A, B represent abstract classes + * C represents a concrete class + * I, J, K represent interfaces + * Lowercase 'c' following a class means that the method m() is concrete + * Lowercase 'a' following a class or interface means that the method m() is abstract + * Lowercase 'd' following an interface means that the method m() is default + * A number 0, 1, or 2 following the lowercase letter indicates the return type of that method + * 0 = Object, 1 = Number, 2 = Integer (these form an inheritance chain so bridges are generated) + * A classes supertypes follow its method spec, in parentheses + * Examples: + * C(Ia0, Jd0) -- C extends I and J, I has abstract m()Object, J has default m()Object + * Cc1(Ia0) -- C has concrete m()Number, extends I with abstract m()Object + * If a type must appear multiple times, its full spec must be in the first occurrence + * Example: + * C(I(Kd0), J(K)) + */ + protected void compileSpec(String spec) throws IOException { + compileSpec(spec, false); + } + + /** + * Compile all the classes in a class spec, and assert that there were compilation errors. + */ + protected void compileSpec(String spec, String... errorKeys) throws IOException { + compileSpec(spec, false, errorKeys); + } + + protected void compileSpec(String spec, boolean debug, String... errorKeys) throws IOException { + ClassModel cm = new Parser(spec).parseClassModel(); + for (int i = 0; i <= cm.maxIndex() ; i++) { + if (debug) System.out.println(indexClass(i)); + addSourceFile(String.format("C%d.java", i), new StringTemplate(indexClass(i))); + } + for (Map.Entry e : classes(cm).entrySet()) { + if (debug) System.out.println(e.getValue().toSource()); + addSourceFile(e.getKey() + ".java", new StringTemplate(e.getValue().toSource())); + } + compileDirs.add(compile(true)); + resetSourceFiles(); + if (errorKeys.length == 0) + assertCompileSucceeded(); + else + assertCompileErrors(errorKeys); + } + + /** + * Recompile only a subset of classes in the class spec, as named by names, + * and put them on the classpath such that they shadow earlier versions of that class. + */ + protected void recompileSpec(String spec, String... names) throws IOException { + List nameList = Arrays.asList(names); + ClassModel cm = new Parser(spec).parseClassModel(); + for (int i = 0; i <= cm.maxIndex() ; i++) { + addSourceFile(String.format("C%d.java", i), new StringTemplate(indexClass(i))); + } + for (Map.Entry e : classes(cm).entrySet()) + if (nameList.contains(e.getKey())) + addSourceFile(e.getKey() + ".java", new StringTemplate(e.getValue().toSource())); + compileDirs.add(compile(Arrays.asList(classPaths()), true)); + resetSourceFiles(); + assertCompileSucceeded(); + } + + protected void assertLinkage(String name, String... expected) throws ReflectiveOperationException { + for (int i=0; i classes(ClassModel cm) { + HashMap m = new HashMap<>(); + classesHelper(cm, m); + return m; + } + + private String indexClass(int index) { + if (index == 0) { + return BASE_INDEX_CLASS; + } else { + return INDEX_CLASS_TEMPLATE + .replace("#ID", String.valueOf(index)) + .replace("#PREV", String.valueOf(index - 1)); + } + } + + private static String overrideName(int index) { + return "C" + index; + } + + private void classesHelper(ClassModel cm, Map m) { + if (!m.containsKey(cm.name)) + m.put(cm.name, cm); + for (ClassModel s : cm.supertypes) + classesHelper(s, m); + } + + private static String fromNum(int num) { + return String.format("%c%d", TYPE_LETTERS.charAt(num / 10), num % 10); + } + + private static int toNum(String name, int index) { + return 10*(TYPE_LETTERS.indexOf(name.charAt(0))) + index; + } + + private static int toNum(String string) { + return 10*(TYPE_LETTERS.indexOf(string.charAt(0))) + Integer.parseInt(string.substring(1, 2)); + } + + private int invoke(String name, int index) throws ReflectiveOperationException { + File[] files = classPaths(); + Class clazz = loadClass(name, files); + Method[] ms = clazz.getMethods(); + for (Method m : ms) { + if (m.getName().equals("m") && m.getReturnType().getName().equals(overrideName(index))) { + m.setAccessible(true); + Object instance = clazz.newInstance(); + Object c0 = m.invoke(instance); + Method getVal = c0.getClass().getMethod("getVal"); + getVal.setAccessible(true); + return (int)getVal.invoke(c0); + } + } + throw new NoSuchMethodError("cannot find method m()" + index + " in class " + name); + } + + private File[] classPaths() { + File[] files = new File[compileDirs.size()]; + for (int i=0; i supertypes; + private final MethodType methodType; + private final int methodIndex; + + private ClassModel(String name, + boolean anInterface, + List supertypes, + MethodType methodType, + int methodIndex) { + this.name = name; + isInterface = anInterface; + this.supertypes = supertypes; + this.methodType = methodType; + this.methodIndex = methodIndex; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(name); + if (methodType != null) { + sb.append(methodType.designator); + sb.append(methodIndex); + } + if (!supertypes.isEmpty()) { + sb.append("("); + for (int i=0; i 0) + sb.append(","); + sb.append(supertypes.get(i).toString()); + } + sb.append(")"); + } + return sb.toString(); + } + + int maxIndex() { + int maxSoFar = methodIndex; + for (ClassModel cm : supertypes) { + maxSoFar = Math.max(cm.maxIndex(), maxSoFar); + } + return maxSoFar; + } + + public String toSource() { + String extendsClause = ""; + String implementsClause = ""; + String methodBody = ""; + boolean isAbstract = "AB".contains(name); + + for (ClassModel s : supertypes) { + if (!s.isInterface) { + extendsClause = String.format("extends %s", s.name); + break; + } + } + + StringJoiner sj = new StringJoiner(", "); + for (ClassModel s : supertypes) + if (s.isInterface) + sj.add(s.name); + if (sj.length() > 0) { + if (isInterface) + implementsClause = "extends " + sj.toString(); + else + implementsClause = "implements " + sj.toString(); + } + if (methodType != null) { + switch (methodType) { + case ABSTRACT: + methodBody = String.format("public abstract %s m();", overrideName(methodIndex)); + break; + case CONCRETE: + methodBody = String.format("public %s m() { return new %s(%d); };", + overrideName(methodIndex), overrideName(methodIndex), toNum(name, methodIndex)); + break; + case DEFAULT: + methodBody = String.format("public default %s m() { return new %s(%d); };", + overrideName(methodIndex), overrideName(methodIndex), toNum(name, methodIndex)); + break; + + } + } + + return String.format("public %s %s %s %s %s { %s }", isAbstract ? "abstract" : "", + isInterface ? "interface" : "class", + name, extendsClause, implementsClause, methodBody); + } + } + + private static class Parser { + private final String input; + private final char[] chars; + private int index; + + private Parser(String s) { + input = s; + chars = s.toCharArray(); + } + + private char peek() { + return index < chars.length ? chars[index] : 0; + } + + private boolean peek(String validChars) { + return validChars.indexOf(peek()) >= 0; + } + + private char advanceIf(String validChars) { + if (peek(validChars)) + return chars[index++]; + else + return 0; + } + + private char advanceIfDigit() { + return advanceIf("0123456789"); + } + + private int index() { + StringBuilder buf = new StringBuilder(); + char c = advanceIfDigit(); + while (c != 0) { + buf.append(c); + c = advanceIfDigit(); + } + return Integer.valueOf(buf.toString()); + } + + private char advance() { + return chars[index++]; + } + + private char expect(String validChars) { + char c = advanceIf(validChars); + if (c == 0) + throw new IllegalArgumentException(String.format("Expecting %s at position %d of %s", validChars, index, input)); + return c; + } + + public ClassModel parseClassModel() { + List supers = new ArrayList<>(); + char name = expect(TYPE_LETTERS); + boolean isInterface = "IJK".indexOf(name) >= 0; + ClassModel.MethodType methodType = peek(isInterface ? "ad" : "ac") ? ClassModel.MethodType.find(advance()) : null; + int methodIndex = 0; + if (methodType != null) { + methodIndex = index(); + } + if (peek() == '(') { + advance(); + supers.add(parseClassModel()); + while (peek() == ',') { + advance(); + supers.add(parseClassModel()); + } + expect(")"); + } + return new ClassModel(new String(new char[]{ name }), isInterface, supers, methodType, methodIndex); + } + } +} diff --git a/langtools/test/tools/javac/lambda/bridge/template_tests/BridgeMethodsTemplateTest.java b/langtools/test/tools/javac/lambda/bridge/template_tests/BridgeMethodsTemplateTest.java new file mode 100644 index 00000000000..028602ea057 --- /dev/null +++ b/langtools/test/tools/javac/lambda/bridge/template_tests/BridgeMethodsTemplateTest.java @@ -0,0 +1,1082 @@ +/* + * Copyright (c) 2013, 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.io.IOException; + +import org.testng.annotations.Test; + +/** + * BridgeMethodsTemplateTest + * + * @author Brian Goetz + */ +@Test +public class BridgeMethodsTemplateTest extends BridgeMethodTestCase { + + /* + * Cc1(A) -> Cc1(Ac0) + * + * 0*: Inherited from A + * 1: Declared in C + */ + public void test1() throws IOException, ReflectiveOperationException { + compileSpec("Cc1(A)"); + assertLinkage("C", LINKAGE_ERROR, "C1"); + recompileSpec("Cc1(Ac0)", "A"); + assertLinkage("C", "A0", "C1"); + } + + /* + * Cc1(I) -> Cc1(Id0) + * + * 0*: Inherited default from I + * 1: Declared in C + */ + public void test2() throws IOException, ReflectiveOperationException { + compileSpec("Cc1(I)"); + assertLinkage("C", LINKAGE_ERROR, "C1"); + recompileSpec("Cc1(Id0)", "I"); + assertLinkage("C", "I0", "C1"); + } + + /* + * C(Bc1(A)) -> C(Bc1(Ac0)) + * + * 0*: Inherited from A + * 1: Inherited from B + */ + public void test3() throws IOException, ReflectiveOperationException { + compileSpec("C(Bc1(A))"); + assertLinkage("C", LINKAGE_ERROR, "B1"); + recompileSpec("C(Bc1(Ac0))", "A"); + assertLinkage("C", "A0", "B1"); + } + + /* + * C(B(Ac0)) -> C(Bc1(Ac0)) + * + * 0: Inherited from B (through bridge) + * 1: Inherited from B + */ + public void test4() throws IOException, ReflectiveOperationException { + compileSpec("C(B(Ac0))"); + assertLinkage("C", "A0", LINKAGE_ERROR); + recompileSpec("C(Bc1(Ac0))", "B"); + assertLinkage("C", "B1", "B1"); + } + + /* + * C(B(A)) -> C(Bc1(Ac0)) + * + * 0: Inherited from B (through bridge) + * 1: Inherited from B + */ + public void test5() throws IOException, ReflectiveOperationException { + compileSpec("C(B(A))"); + assertLinkage("C", LINKAGE_ERROR, LINKAGE_ERROR); + recompileSpec("C(Bc1(Ac0))", "A", "B"); + assertLinkage("C", "B1", "B1"); + } + + /* + * C(Ac1(I)) -> C(Ac1(Id0)) + * + * 0*: Inherited default from I + * 1: Inherited from A + */ + public void test6() throws IOException, ReflectiveOperationException { + compileSpec("C(Ac1(I))"); + assertLinkage("C", LINKAGE_ERROR, "A1"); + recompileSpec("C(Ac1(Id0))", "I"); + assertLinkage("C", "I0", "A1"); + } + + /* + * C(A(Id0)) -> C(Ac1(Id0)) + * + * 0: Inherited from A (through bridge) + * 1: Inherited from A + */ + public void test7() throws IOException, ReflectiveOperationException { + compileSpec("C(A(Id0))"); + assertLinkage("C", "I0", LINKAGE_ERROR); + recompileSpec("C(Ac1(Id0))", "A"); + assertLinkage("C", "A1", "A1"); + } + + /* + * C(A(I)) -> C(Ac1(Id0)) + * + * 0*: Inherited from A (through bridge) + * 1*: Inherited from A + */ + public void test8() throws IOException, ReflectiveOperationException { + compileSpec("C(A(I))"); + assertLinkage("C", LINKAGE_ERROR, LINKAGE_ERROR); + recompileSpec("C(Ac1(Id0))", "A", "I"); + assertLinkage("C", "A1", "A1"); + } + + /* + * C(Id1(J)) -> C(Id1(Jd0)) + * + * 0*: Inherited default from J + * 1: Inherited default from I + */ + public void test9() throws IOException, ReflectiveOperationException { + compileSpec("C(Id1(J))"); + assertLinkage("C", LINKAGE_ERROR, "I1"); + recompileSpec("C(Id1(Jd0))", "J"); + assertLinkage("C", "J0", "I1"); + } + + /* + * C(I(Jd0)) -> C(Id1(Jd0)) + * + * 0: Inherited default from I (through bridge) + * 1: Inherited default from I + */ + public void test10() throws IOException, ReflectiveOperationException { + compileSpec("C(I(Jd0))"); + assertLinkage("C", "J0", LINKAGE_ERROR); + recompileSpec("C(Id1(Jd0))", "I"); + assertLinkage("C", "I1", "I1"); + } + + /* + * C(I(J)) -> C(Id1(Jd0)) + * + * 0: Inherited default from I (through bridge) + * 1: Inherited default from I + */ + public void test11() throws IOException, ReflectiveOperationException { + compileSpec("C(I(J))"); + assertLinkage("C", LINKAGE_ERROR, LINKAGE_ERROR); + recompileSpec("C(Id1(Jd0))", "I", "J"); + assertLinkage("C", "I1", "I1"); + } + + /* + * Cc2(B(Ac0)) -> Cc2(Bc1(Ac0)) + * + * 0: Declared in C (through bridge) + * 1*: Inherited from B + * 2: Declared in C + */ + public void test12() throws IOException, ReflectiveOperationException { + compileSpec("Cc2(B(Ac0))"); + assertLinkage("C", "C2", LINKAGE_ERROR, "C2"); + recompileSpec("Cc2(Bc1(Ac0))", "B"); + assertLinkage("C", "C2", "B1", "C2"); + } + + /* + * Cc2(B(Aa0)) -> Cc2(Bc1(Aa0)) + * + * 0: Bridge in C (through bridge) + * 1*: Inherited from B + * 2: Declared in C + */ + public void test13() throws IOException, ReflectiveOperationException { + compileSpec("Cc2(B(Aa0))"); + assertLinkage("C", "C2", LINKAGE_ERROR, "C2"); + recompileSpec("Cc2(Bc1(Aa0))", "B"); + assertLinkage("C", "C2", "B1", "C2"); + } + + /* + * Cc2(Bc1(A)) -> Cc2(Bc1(Ac0)) + * + * 0*: Inherited from A + * 1: Declared in C (through bridge) + * 2: Declared in C + */ + public void test14() throws IOException, ReflectiveOperationException { + compileSpec("Cc2(Bc1(A))"); + assertLinkage("C", LINKAGE_ERROR, "C2", "C2"); + recompileSpec("Cc2(Bc1(Ac0))", "A"); + assertLinkage("C", "A0", "C2", "C2"); + } + + /* + * Cc2(Ba1(A)) -> Cc2(Ba1(Ac0)) + * + * 0*: Inherited from A + * 1: Declared in C (through bridge) + * 2: Declared in C + */ + public void test15() throws IOException, ReflectiveOperationException { + compileSpec("Cc2(Ba1(A))"); + assertLinkage("C", LINKAGE_ERROR, "C2", "C2"); + recompileSpec("Cc2(Ba1(Ac0))", "A"); + assertLinkage("C", "A0", "C2", "C2"); + } + + /* + * Cc2(B(A)) -> Cc2(Bc1(Ac0)) + * + * 0*: Inherited from B (through bridge) + * 1*: Inherited from B + * 2: Declared in C + */ + public void test16() throws IOException, ReflectiveOperationException { + compileSpec("Cc2(B(A))"); + assertLinkage("C", LINKAGE_ERROR, LINKAGE_ERROR, "C2"); + recompileSpec("Cc2(Bc1(Ac0))", "B", "A"); + assertLinkage("C", "B1", "B1", "C2"); + } + + /* + * Cc2(A(Id0)) -> Cc2(Ac1(Id0)) + * + * 0: Declared in C (through bridge) + * 1*: Inherited from A + * 2: Declared in C + */ + public void test17() throws IOException, ReflectiveOperationException { + compileSpec("Cc2(A(Id0))"); + assertLinkage("C", "C2", LINKAGE_ERROR, "C2"); + recompileSpec("Cc2(Ac1(Id0))", "A"); + assertLinkage("C", "C2", "A1", "C2"); + } + + /* + * Cc2(A(Ia0)) -> Cc2(Ac1(Ia0)) + * + * 0: Declared in C (through bridge) + * 1*: Inherited from A + * 2: Declared in C + */ + public void test18() throws IOException, ReflectiveOperationException { + compileSpec("Cc2(A(Ia0))"); + assertLinkage("C", "C2", LINKAGE_ERROR, "C2"); + recompileSpec("Cc2(Ac1(Ia0))", "A"); + assertLinkage("C", "C2", "A1", "C2"); + } + + /* + * Cc2(Ac1(I)) -> Cc2(Ac1(Id0)) + * + * 0*: Inherited from I + * 1: Declared in C (through bridge) + * 2: Declared in C + */ + public void test19() throws IOException, ReflectiveOperationException { + compileSpec("Cc2(Ac1(I))"); + assertLinkage("C", LINKAGE_ERROR, "C2", "C2"); + recompileSpec("Cc2(Ac1(Id0))", "I"); + assertLinkage("C", "I0", "C2", "C2"); + } + + /* + * Cc2(Aa1(I)) -> Cc2(Aa1(Id0)) + * + * 0*: Inherited from I + * 1: Declared in C (through bridge) + * 2: Declared in C + */ + public void test20() throws IOException, ReflectiveOperationException { + compileSpec("Cc2(Aa1(I))"); + assertLinkage("C", LINKAGE_ERROR, "C2", "C2"); + recompileSpec("Cc2(Aa1(Id0))", "I"); + assertLinkage("C", "I0", "C2", "C2"); + } + + /* + * Cc2(A(I)) -> Cc2(Ac1(Id0)) + * + * 0*: Inherited from A (through bridge) + * 1*: Inherited from A + * 2: Declared in C + */ + public void test21() throws IOException, ReflectiveOperationException { + compileSpec("Cc2(A(I))"); + assertLinkage("C", LINKAGE_ERROR, LINKAGE_ERROR, "C2"); + recompileSpec("Cc2(Ac1(Id0))", "A", "I"); + assertLinkage("C", "A1", "A1", "C2"); + } + + /* + * Cc2(J(Id0)) -> Cc2(Jd1(Id0)) + * + * 0: Declared in C (through bridge) + * 1*: Inherited default from J + * 2: Declared in C + */ + public void test22() throws IOException, ReflectiveOperationException { + compileSpec("Cc2(J(Id0))"); + assertLinkage("C", "C2", LINKAGE_ERROR, "C2"); + recompileSpec("Cc2(Jd1(Id0))", "J"); + assertLinkage("C", "C2", "J1", "C2"); + } + + /* + * Cc2(J(Ia0)) -> Cc2(Jd1(Ia0)) + * + * 0: Declared in C (through bridge) + * 1*: Inherited default from J + * 2: Declared in C + */ + public void test23() throws IOException, ReflectiveOperationException { + compileSpec("Cc2(J(Ia0))"); + assertLinkage("C", "C2", LINKAGE_ERROR, "C2"); + recompileSpec("Cc2(Jd1(Ia0))", "J"); + assertLinkage("C", "C2", "J1", "C2"); + } + + /* + * Cc2(Jd1(I)) -> Cc2(Jd1(Id0)) + * + * 0*: Inherited default from I + * 1: Declared in C (through bridge) + * 2: Declared in C + */ + public void test24() throws IOException, ReflectiveOperationException { + compileSpec("Cc2(Jd1(I))"); + assertLinkage("C", LINKAGE_ERROR, "C2", "C2"); + recompileSpec("Cc2(Jd1(Id0))", "I"); + assertLinkage("C", "I0", "C2", "C2"); + } + + /* + * Cc2(Ja1(I)) -> Cc2(Ja1(Id0)) + * + * 0*: Inherited default from I + * 1: Declared in C (through bridge) + * 2: Declared in C + */ + public void test25() throws IOException, ReflectiveOperationException { + compileSpec("Cc2(Ja1(I))"); + assertLinkage("C", LINKAGE_ERROR, "C2", "C2"); + recompileSpec("Cc2(Ja1(Id0))", "I"); + assertLinkage("C", "I0", "C2", "C2"); + } + + /* + * Cc2(J(I)) -> Cc2(Jd1(Id0)) + * + * 0*: Inherited default from J (through bridge) + * 1*: Inherited default from J + * 2: Declared in C + */ + public void test26() throws IOException, ReflectiveOperationException { + compileSpec("Cc2(J(I))"); + assertLinkage("C", LINKAGE_ERROR, LINKAGE_ERROR, "C2"); + recompileSpec("Cc2(Jd1(Id0))", "J", "I"); + assertLinkage("C", "J1", "J1", "C2"); + } + + /* + * C(Ac1, I) -> C(Ac1, Id0) + * + * 0*: Inherited default from I + * 1: Inherited from A + */ + public void test27() throws IOException, ReflectiveOperationException { + compileSpec("C(Ac1,I)"); + assertLinkage("C", LINKAGE_ERROR, "A1"); + recompileSpec("C(Ac1,Id0)", "I"); + assertLinkage("C", "I0", "A1"); + } + + /* + * C(A, Id0) -> C(Ac1, Id0) + * + * 0*: Inherited default from I + * 1: Inherited from A + */ + public void test28() throws IOException, ReflectiveOperationException { + compileSpec("C(A,Id0)"); + assertLinkage("C", "I0", LINKAGE_ERROR); + recompileSpec("C(Ac1,Id0)", "A"); + assertLinkage("C", "I0", "A1"); + } + + /* + * C(A, I) -> C(Ac1, Id0) + * + * 0*: Inherited default from I + * 1: Inherited from A + */ + public void test29() throws IOException, ReflectiveOperationException { + compileSpec("C(A,I)"); + assertLinkage("C", LINKAGE_ERROR, LINKAGE_ERROR); + recompileSpec("C(Ac1,Id0)", "A", "I"); + assertLinkage("C", "I0", "A1"); + } + + /* + * Cc2(Ac1, I) -> Cc2(Ac1, Id0) + * + * 0*: Inherited default from I + * 1: Declared in C (through bridge) + * 2: Declared in C + */ + public void test30() throws IOException, ReflectiveOperationException { + compileSpec("Cc2(Ac1,I)"); + assertLinkage("C", LINKAGE_ERROR, "C2", "C2"); + recompileSpec("Cc2(Ac1,Id0)", "I"); + assertLinkage("C", "I0", "C2", "C2"); + } + + /* + * Cc2(Aa1, I) -> Cc2(Aa1, Id0) + * + * 0*: Inherited default from I + * 1: Declared in C (through bridge) + * 2: Declared in C + */ + public void test31() throws IOException, ReflectiveOperationException { + compileSpec("Cc2(Aa1,I)"); + assertLinkage("C", LINKAGE_ERROR, "C2", "C2"); + recompileSpec("Cc2(Aa1,Id0)", "I"); + assertLinkage("C", "I0", "C2", "C2"); + } + + /* + * Cc2(A, Id0) -> Cc2(Ac1, Id0) + * + * 0: Declared in C (through bridge) + * 1*: Inherited from A + * 2: Declared in C + */ + public void test32() throws IOException, ReflectiveOperationException { + compileSpec("Cc2(A,Id0)"); + assertLinkage("C", "C2", LINKAGE_ERROR, "C2"); + recompileSpec("Cc2(Ac1,Id0)", "A"); + assertLinkage("C", "C2", "A1", "C2"); + } + + /* + * Cc2(A, Ia0) -> Cc2(Ac1, Ia0) + * + * 0: Declared in C (through bridge) + * 1*: Inherited from A + * 2: Declared in C + */ + public void test33() throws IOException, ReflectiveOperationException { + compileSpec("Cc2(A,Ia0)"); + assertLinkage("C", "C2", LINKAGE_ERROR, "C2"); + recompileSpec("Cc2(Ac1,Ia0)", "A"); + assertLinkage("C", "C2", "A1", "C2"); + } + + /* + * Cc2(A, I) -> Cc2(Ac1, Id0) + * + * 0*: Inherited from A + * 1*: Inherited default from I + * 2: Declared in C + */ + public void test34() throws IOException, ReflectiveOperationException { + compileSpec("Cc2(A,I)"); + assertLinkage("C", LINKAGE_ERROR, LINKAGE_ERROR, "C2"); + recompileSpec("Cc2(Ac1,Id0)", "A", "I"); + assertLinkage("C", "I0", "A1", "C2"); + } + + /* + * Cc2(Id0, J) -> Cc2(Id0, Jd1) + * + * 0: Declared in C (through bridge) + * 1*: Inherited default from J + * 2: Declared in C + */ + public void test35() throws IOException, ReflectiveOperationException { + compileSpec("Cc2(Id0,J)"); + assertLinkage("C", "C2", LINKAGE_ERROR, "C2"); + recompileSpec("Cc2(Id0,Jd1)", "J"); + assertLinkage("C", "C2", "J1", "C2"); + } + + /* + * Cc2(Ia0, J) -> Cc2(Ia0, Jd1) + * + * 0: Declared in C (through bridge) + * 1*: Inherited default from J + * 2: Declared in C + */ + public void test36() throws IOException, ReflectiveOperationException { + compileSpec("Cc2(Ia0,J)"); + assertLinkage("C", "C2", LINKAGE_ERROR, "C2"); + recompileSpec("Cc2(Ia0,Jd1)", "J"); + assertLinkage("C", "C2", "J1", "C2"); + } + + /* + * Cc2(I, J) -> Cc2(Id0, Jd1) + * + * 0*: Inherited default from I + * 1*: Inherited default from J + * 2: Declared in C + */ + public void test37() throws IOException, ReflectiveOperationException { + compileSpec("Cc2(I,J)"); + assertLinkage("C", LINKAGE_ERROR, LINKAGE_ERROR, "C2"); + recompileSpec("Cc2(Id0,Jd1)", "I", "J"); + assertLinkage("C", "I0", "J1", "C2"); + } + + /* + * C(A(Id0), J(Id0)) -> C(Ac1(Id0), J(Id0)) + * + * 0: Inherited default from I + * 0*: Inherited from A (through bridge) + * 1*: Inherited from A + */ + public void test38() throws IOException, ReflectiveOperationException { + compileSpec("C(A(Id0),J(Id0))"); + assertLinkage("C", "I0", LINKAGE_ERROR); + recompileSpec("C(Ac1(Id0),J(Id0))", "A"); + assertLinkage("C", "A1", "A1"); + } + + /* + * C(A(Id0), J(Id0)) -> C(A(Id0), Jd1(Id0)) + * + * 0: Inherited default from I + * 0: Inherited default from J (through bridge) + * 1*: Inherited default from J + */ + public void test39() throws IOException, ReflectiveOperationException { + compileSpec("C(A(Id0),J(Id0))"); + assertLinkage("C", "I0", LINKAGE_ERROR); + recompileSpec("C(A(Id0),Jd1(Id0))", "J"); + assertLinkage("C", "J1", "J1"); + } + + /* + * C(A(Id0), J(Id0)) -> C(Ac2(Id0), Jd1(Id0)) + * + * 0: Inherited default from I + * 0*: Inherited from A (new bridge in A beats new bridge in J) + * 1*: Inherited default from J + * 2: Inherited from A + */ + public void test40() throws IOException, ReflectiveOperationException { + compileSpec("C(A(Id0),J(Id0))"); + assertLinkage("C", "I0", LINKAGE_ERROR); + recompileSpec("C(Ac2(Id0),Jd1(Id0))", "A", "J"); + assertLinkage("C", "A2", "J1", "A2"); + } + + /* + * C(J(Id0), K(Id0)) -> C(Jd1(Id0), K(Id0)) + * + * 0: Inherited from I + * 0*: Inherited default from J (through bridge) + * 1: Inherited default from J + */ + public void test41() throws IOException, ReflectiveOperationException { + compileSpec("C(J(Id0),K(Id0))"); + assertLinkage("C", "I0", LINKAGE_ERROR); + recompileSpec("C(Jd1(Id0),K(Id0))", "J"); + assertLinkage("C", "J1", "J1"); + } + + /* + * C(Ac2(Id0), J(Id0)) -> C(Ac2(Id0), Jd1(Id0)) + * + * 0: Inherited from A (bridge in A beats new bridge in J) + * 1*: Inherited default from J + * 2: Inherited from A + */ + public void test42() throws IOException, ReflectiveOperationException { + compileSpec("C(Ac2(Id0),J(Id0))"); + assertLinkage("C", "A2", LINKAGE_ERROR, "A2"); + recompileSpec("C(Ac2(Id0),Jd1(Id0))", "J"); + assertLinkage("C", "A2", "J1", "A2"); + } + + /* + * C(Ac2(Ia0), J(Ia0)) -> C(Ac2(Ia0), Jd1(Ia0)) + * + * 0: Inherited from A (bridge in A beats new bridge in J) + * 1*: Inherited default from J + * 2: Inherited from A + */ + public void test43() throws IOException, ReflectiveOperationException { + compileSpec("C(Ac2(Ia0),J(Ia0))"); + assertLinkage("C", "A2", LINKAGE_ERROR, "A2"); + recompileSpec("C(Ac2(Ia0),Jd1(Ia0))", "J"); + assertLinkage("C", "A2", "J1", "A2"); + } + + /* + * C(A(Id0), Jd1(Id0)) -> C(Ac2(Id0), Jd1(Id0)) + * + * 0: Inherited from J + * 0*: Inherited from A (new bridge in A beats bridge in J) + * 1: Inherited default from J + * 2*: Inherited from A + */ + public void test44() throws IOException, ReflectiveOperationException { + compileSpec("C(A(Id0),Jd1(Id0))"); + assertLinkage("C", "J1", "J1", LINKAGE_ERROR); + recompileSpec("C(Ac2(Id0),Jd1(Id0))", "A"); + assertLinkage("C", "A2", "J1", "A2"); + } + + /* + * C(A(Ia0), Jd1(Ia0)) -> C(Ac2(Ia0), Jd1(Ia0)) + * + * 0: Inherited from J + * 0*: Inherited from A (new bridge in A beats bridge in J) + * 1: Inherited default from J + * 2*: Inherited from A + */ + public void test45() throws IOException, ReflectiveOperationException { + compileSpec("C(A(Ia0),Jd1(Ia0))"); + assertLinkage("C", "J1", "J1", LINKAGE_ERROR); + recompileSpec("C(Ac2(Ia0),Jd1(Ia0))", "A"); + assertLinkage("C", "A2", "J1", "A2"); + } + + /* + * Cc2(A(Id0), J(Id0)) -> Cc2(Ac1(Id0), J(Id0)) + * + * 0: Declared in C (through bridge) + * 1*: Inherited from A + * 2: Declared in C + */ + public void test46() throws IOException, ReflectiveOperationException { + compileSpec("Cc2(A(Id0),J(Id0))"); + assertLinkage("C", "C2", LINKAGE_ERROR, "C2"); + recompileSpec("Cc2(Ac1(Id0),J(Id0))", "A"); + assertLinkage("C", "C2", "A1", "C2"); + } + + /* + * Cc2(A(Ia0), J(Ia0)) -> Cc2(Ac1(Ia0), J(Ia0)) + * + * 0: Declared in C (through bridge) + * 1*: Inherited from A + * 2: Declared in C + */ + public void test47() throws IOException, ReflectiveOperationException { + compileSpec("Cc2(A(Ia0),J(Ia0))"); + assertLinkage("C", "C2", LINKAGE_ERROR, "C2"); + recompileSpec("Cc2(Ac1(Ia0),J(Ia0))", "A"); + assertLinkage("C", "C2", "A1", "C2"); + } + + /* + * Cc2(A(Id0), J(Id0)) -> Cc2(A(Id0), Jd1(Id0)) + * + * 0: Declared in C (through bridge) + * 1*: Inherited default from J + * 2: Declared in C + */ + public void test48() throws IOException, ReflectiveOperationException { + compileSpec("Cc2(A(Id0),J(Id0))"); + assertLinkage("C", "C2", LINKAGE_ERROR, "C2"); + recompileSpec("Cc2(A(Id0),Jd1(Id0))", "J"); + assertLinkage("C", "C2", "J1", "C2"); + } + + /* + * Cc2(A(Ia0), J(Ia0)) -> Cc2(A(Ia0), Jd1(Ia0)) + * + * 0: Declared in C (through bridge) + * 1*: Inherited default from J + * 2: Declared in C + */ + public void test49() throws IOException, ReflectiveOperationException { + compileSpec("Cc2(A(Ia0),J(Ia0))"); + assertLinkage("C", "C2", LINKAGE_ERROR, "C2"); + recompileSpec("Cc2(A(Ia0),Jd1(Ia0))", "J"); + assertLinkage("C", "C2", "J1", "C2"); + } + + + /* + * Cc3(A(Id0), J(Id0)) -> Cc3(Ac1(Id0), Jd2(Id0)) + * + * 0: Bridge in C + * 1*: Inherited from A + * 2*: Inherited default from J + * 3: Declared in C + */ + public void test50() throws IOException, ReflectiveOperationException { + compileSpec("Cc3(A(Id0),J(Id0))"); + assertLinkage("C", "C3", LINKAGE_ERROR, LINKAGE_ERROR, "C3"); + recompileSpec("Cc3(Ac1(Id0),Jd2(Id0))", "A", "J"); + assertLinkage("C", "C3", "A1", "J2", "C3"); + } + + /* + * Cc3(A(Ia0), J(Ia0)) -> Cc3(Ac1(Ia0), Jd2(Ia0)) + * + * 0: Bridge in C + * 1*: Inherited from A + * 2*: Inherited default from J + * 3: Declared in C + */ + public void test51() throws IOException, ReflectiveOperationException { + compileSpec("Cc3(A(Ia0),J(Ia0))"); + assertLinkage("C", "C3", LINKAGE_ERROR, LINKAGE_ERROR, "C3"); + recompileSpec("Cc3(Ac1(Ia0),Jd2(Ia0))", "A", "J"); + assertLinkage("C", "C3", "A1", "J2", "C3"); + } + + /* + * Cc2(J(Id0), K(Id0)) -> Cc2(Jd1(Id0), K(Id0)) + * + * 0: Declared in C (through bridge) + * 1*: Inherited default from J + * 2: Declared in C + */ + public void test52() throws IOException, ReflectiveOperationException { + compileSpec("Cc2(J(Id0),K(Id0))"); + assertLinkage("C", "C2", LINKAGE_ERROR, "C2"); + recompileSpec("Cc2(Jd1(Id0),K(Id0))", "J"); + assertLinkage("C", "C2", "J1", "C2"); + } + + /* + * Cc2(J(Ia0), K(Ia0)) -> Cc2(Jd1(Ia0), K(Ia0)) + * + * 0: Declared in C (through bridge) + * 1*: Inherited default from J + * 2: Declared in C + */ + public void test53() throws IOException, ReflectiveOperationException { + compileSpec("Cc2(J(Ia0),K(Ia0))"); + assertLinkage("C", "C2", LINKAGE_ERROR, "C2"); + recompileSpec("Cc2(Jd1(Ia0),K(Ia0))", "J"); + assertLinkage("C", "C2", "J1", "C2"); + } + + /* + * Cc3(J(Id0), K(Id0)) -> Cc3(Jd1(Id0), Kd2(Id0)) + * + * 0: Declared in C (through bridge) + * 1*: Inherited default from J + * 2*: Inherited default from K + * 3: Declared in C + */ + public void test54() throws IOException, ReflectiveOperationException { + compileSpec("Cc3(J(Id0),K(Id0))"); + assertLinkage("C", "C3", LINKAGE_ERROR, LINKAGE_ERROR, "C3"); + recompileSpec("Cc3(Jd1(Id0),Kd2(Id0))", "J", "K"); + assertLinkage("C", "C3", "J1", "K2", "C3"); + } + + /* + * Cc3(J(Ia0), K(Ia0)) -> Cc3(Jd1(Ia0), Kd2(Ia0)) + * + * 0: Declared in C (through bridge) + * 1*: Inherited default from J + * 2*: Inherited default from K + * 3: Declared in C + */ + public void test55() throws IOException, ReflectiveOperationException { + compileSpec("Cc3(J(Ia0),K(Ia0))"); + assertLinkage("C", "C3", LINKAGE_ERROR, LINKAGE_ERROR, "C3"); + recompileSpec("Cc3(Jd1(Ia0),Kd2(Ia0))", "J", "K"); + assertLinkage("C", "C3", "J1", "K2", "C3"); + } + + /* + * Cc3(Ac1(Id0), J(Id0)) -> Cc3(Ac1(Id0), Jd2(Id0)) + * + * 0: Declared in C (through bridge) + * 1: Declared in C (through bridge) + * 2*: Inherited default from J + * 3: Declared in C + */ + public void test56() throws IOException, ReflectiveOperationException { + compileSpec("Cc3(Ac1(Id0),J(Id0))"); + assertLinkage("C", "C3", "C3", LINKAGE_ERROR, "C3"); + recompileSpec("Cc3(Ac1(Id0),Jd2(Id0))", "J"); + assertLinkage("C", "C3", "C3", "J2", "C3"); + } + + /* + * Cc3(Ac1(Ia0), J(Ia0)) -> Cc3(Ac1(Ia0), Jd2(Ia0)) + * + * 0: Declared in C (through bridge) + * 1: Declared in C (through bridge) + * 2*: Inherited default from J + * 3: Declared in C + */ + public void test57() throws IOException, ReflectiveOperationException { + compileSpec("Cc3(Ac1(Ia0),J(Ia0))"); + assertLinkage("C", "C3", "C3", LINKAGE_ERROR, "C3"); + recompileSpec("Cc3(Ac1(Ia0),Jd2(Ia0))", "J"); + assertLinkage("C", "C3", "C3", "J2", "C3"); + } + + /* + * Cc3(Aa1(Id0), J(Id0)) -> Cc3(Aa1(Id0), Jd2(Id0)) + * + * 0: Declared in C (through bridge) + * 1: Declared in C (through bridge) + * 2*: Inherited default from J + * 3: Declared in C + */ + public void test58() throws IOException, ReflectiveOperationException { + compileSpec("Cc3(Aa1(Id0),J(Id0))"); + assertLinkage("C", "C3", "C3", LINKAGE_ERROR, "C3"); + recompileSpec("Cc3(Aa1(Id0),Jd2(Id0))", "J"); + assertLinkage("C", "C3", "C3", "J2", "C3"); + } + + /* + * Cc3(Aa1(Ia0), J(Ia0)) -> Cc3(Aa1(Ia0), Jd2(Ia0)) + * + * 0: Declared in C (through bridge) + * 1: Declared in C (through bridge) + * 2*: Inherited default from J + * 3: Declared in C + */ + public void test59() throws IOException, ReflectiveOperationException { + compileSpec("Cc3(Aa1(Ia0),J(Ia0))"); + assertLinkage("C", "C3", "C3", LINKAGE_ERROR, "C3"); + recompileSpec("Cc3(Aa1(Ia0),Jd2(Ia0))", "J"); + assertLinkage("C", "C3", "C3", "J2", "C3"); + } + + /* + * Cc3(A(Id0), Jd2(Id0)) -> Cc3(Ac1(Id0), Jd2(Id0)) + * + * 0: Declared in C (through bridge) + * 1*: Inherited from A + * 2: Declared in C (through bridge) + * 3: Declared in C + */ + public void test60() throws IOException, ReflectiveOperationException { + compileSpec("Cc3(A(Id0),Jd2(Id0))"); + assertLinkage("C", "C3", LINKAGE_ERROR, "C3", "C3"); + recompileSpec("Cc3(Ac1(Id0),Jd2(Id0))", "A"); + assertLinkage("C", "C3", "A1", "C3", "C3"); + } + + /* + * Cc3(A(Im0), Jd2(Ia0)) -> Cc3(Ac1(Im0), Jd2(Ia0)) + * + * 0: Declared in C (through bridge) + * 1*: Inherited from A + * 2: Declared in C (through bridge) + * 3: Declared in C + */ + public void test61() throws IOException, ReflectiveOperationException { + compileSpec("Cc3(A(Ia0),Jd2(Ia0))"); + assertLinkage("C", "C3", LINKAGE_ERROR, "C3", "C3"); + recompileSpec("Cc3(Ac1(Ia0),Jd2(Ia0))", "A"); + assertLinkage("C", "C3", "A1", "C3", "C3"); + } + + /* + * Cc3(A(Im0), Ja2(Id0)) -> Cc3(Ac1(Id0), Ja2(Id0)) + * + * 0: Declared in C (through bridge) + * 1*: Inherited from A + * 2: Declared in C (through bridge) + * 3: Declared in C + */ + public void test62() throws IOException, ReflectiveOperationException { + compileSpec("Cc3(A(Id0),Ja2(Id0))"); + assertLinkage("C", "C3", LINKAGE_ERROR, "C3", "C3"); + recompileSpec("Cc3(Ac1(Id0),Ja2(Id0))", "A"); + assertLinkage("C", "C3", "A1", "C3", "C3"); + } + + /* + * Cc3(A(Im0), Ja2(Ia0)) -> Cc3(Ac1(Ia0), Ja2(Ia0)) + * + * 0: Declared in C (through bridge) + * 1*: Inherited from A + * 2: Declared in C (through bridge) + * 3: Declared in C + */ + public void test63() throws IOException, ReflectiveOperationException { + compileSpec("Cc3(A(Ia0),Ja2(Ia0))"); + assertLinkage("C", "C3", LINKAGE_ERROR, "C3", "C3"); + recompileSpec("Cc3(Ac1(Ia0),Ja2(Ia0))", "A"); + assertLinkage("C", "C3", "A1", "C3", "C3"); + } + + /* + * Cc3(Jd1(Id0), K(Id0)) -> Cc3(Jd1(Id0), Kd2(Id0)) + * + * 0: Declared in C (through bridge) + * 1: Declared in C (through bridge) + * 2*: Inherited default from K + * 3: Declared in C + */ + public void test64() throws IOException, ReflectiveOperationException { + compileSpec("Cc3(Jd1(Id0),K(Id0))"); + assertLinkage("C", "C3", "C3", LINKAGE_ERROR, "C3"); + recompileSpec("Cc3(Jd1(Id0),Kd2(Id0))", "K"); + assertLinkage("C", "C3", "C3", "K2", "C3"); + } + + /* + * Cc3(Jd1(Ia0), K(Ia0)) -> Cc3(Jd1(Ia0), Kd2(Ia0)) + * + * 0: Declared in C (through bridge) + * 1: Declared in C (through bridge) + * 2*: Inherited default from K + * 3: Declared in C + */ + public void test65() throws IOException, ReflectiveOperationException { + compileSpec("Cc3(Jd1(Ia0),K(Ia0))"); + assertLinkage("C", "C3", "C3", LINKAGE_ERROR, "C3"); + recompileSpec("Cc3(Jd1(Ia0),Kd2(Ia0))", "K"); + assertLinkage("C", "C3", "C3", "K2", "C3"); + } + + /* + * Cc3(Ja1(Id0), K(Id0)) -> Cc3(Ja1(Id0), Kd2(Id0)) + * + * 0: Declared in C (through bridge) + * 1: Declared in C (through bridge) + * 2*: Inherited default from K + * 3: Declared in C + */ + public void test66() throws IOException, ReflectiveOperationException { + compileSpec("Cc3(Jd1(Id0),K(Id0))"); + assertLinkage("C", "C3", "C3", LINKAGE_ERROR, "C3"); + recompileSpec("Cc3(Jd1(Id0),Kd2(Id0))", "K"); + assertLinkage("C", "C3", "C3", "K2", "C3"); + } + + /* + * Cc3(Ja1(Ia0), K(Ia0)) -> Cc3(Ja1(Ia0), Kd2(Ia0)) + * + * 0: Declared in C (through bridge) + * 1: Declared in C (through bridge) + * 2*: Inherited default from K + * 3: Declared in C + */ + public void test67() throws IOException, ReflectiveOperationException { + compileSpec("Cc3(Jd1(Ia0),K(Ia0))"); + assertLinkage("C", "C3", "C3", LINKAGE_ERROR, "C3"); + recompileSpec("Cc3(Jd1(Ia0),Kd2(Ia0))", "K"); + assertLinkage("C", "C3", "C3", "K2", "C3"); + } + + // Dan's set A + public void testA1() throws IOException, ReflectiveOperationException { + compileSpec("C(Id0)"); + assertLinkage("C", "I0"); + } + + public void testA2() throws IOException, ReflectiveOperationException { + compileSpec("C(A(Id0))"); + assertLinkage("C", "I0"); + } + + public void testA3() throws IOException, ReflectiveOperationException { + compileSpec("C(A(Id0),J)"); + assertLinkage("C", "I0"); + } + + public void testA4() throws IOException, ReflectiveOperationException { + compileSpec("D(C(Id0),Jd0(Id0))"); + assertLinkage("D", "J0"); + assertLinkage("C", "I0"); + } + + public void testA5() throws IOException, ReflectiveOperationException { + compileSpec("C(A(Id0),Jd0)", + "compiler.err.types.incompatible.unrelated.defaults"); + } + + public void testA6() throws IOException, ReflectiveOperationException { + compileSpec("C(A(Ia0,Jd0))", + "compiler.err.does.not.override.abstract", + "compiler.err.types.incompatible.abstract.default"); + } + + public void testA7() throws IOException, ReflectiveOperationException { + compileSpec("C(A(Id0,Jd0))", + "compiler.err.types.incompatible.unrelated.defaults"); + } + + public void testA8() throws IOException, ReflectiveOperationException { + compileSpec("C(A(Ia0),J)", "compiler.err.does.not.override.abstract"); + } + + public void testA9() throws IOException, ReflectiveOperationException { + compileSpec("C(Ac0(Id0))"); + assertLinkage("C", "A0"); + } + + public void testA10() throws IOException, ReflectiveOperationException { + compileSpec("C(Aa0,I)", "compiler.err.does.not.override.abstract"); + } + + public void testA11() throws IOException, ReflectiveOperationException { + compileSpec("C(Ac0,Id0)"); + assertLinkage("C", "A0"); + } + + // Dan's set B + + /* B1 can't be done, needs a second concrete class D + public void testB1() throws IOException, ReflectiveOperationException { + compileSpec("Cc1(Dc0)"); + assertLinkage("C", "C1", "C1"); + assertLinkage("D", "A0", LINKAGE_ERROR); + } + */ + + public void testB2() throws IOException, ReflectiveOperationException { + compileSpec("Cc1(Ac0)"); + assertLinkage("C", "C1", "C1"); + } + + //??? B3 seems to suggest that we should create an abstract class + //public void testB3() throws IOException, ReflectiveOperationException { + // compileSpec("Ba1(Cc0)"); + // assertLinkage("B", "C0", "A1"); + //} + + // B4 needs too many classes + + public void testB5() throws IOException, ReflectiveOperationException { + compileSpec("Cc1(Aa1(Id0))"); + assertLinkage("C", "C1", "C1"); + } + + public void testB6() throws IOException, ReflectiveOperationException { + compileSpec("C(Ac1(Id0))"); + assertLinkage("C", "A1", "A1"); + } + + public void testB7() throws IOException, ReflectiveOperationException { + compileSpec("Cc1(Id0)"); + assertLinkage("C", "C1", "C1"); + } + + public void testB8() throws IOException, ReflectiveOperationException { + compileSpec("C(Jd1(Id0))"); + assertLinkage("C", "J1", "J1"); + } + + // B9 needs too many classes + + // The rest of Dan's tests need generics +} diff --git a/langtools/test/tools/javac/lambda/bridge/template_tests/TEST.properties b/langtools/test/tools/javac/lambda/bridge/template_tests/TEST.properties new file mode 100644 index 00000000000..9e96df01db6 --- /dev/null +++ b/langtools/test/tools/javac/lambda/bridge/template_tests/TEST.properties @@ -0,0 +1,7 @@ +# This file identifies root(s) of the test-ng hierarchy. + + + +TestNG.dirs = . + +lib.dirs = /lib/combo From 810c76f567e5d568686a71c19c192f7a344d73cc Mon Sep 17 00:00:00 2001 From: Jonathan Gibbons Date: Mon, 9 Sep 2013 17:36:23 -0700 Subject: [PATCH 110/210] 8006972: jtreg test fails: test/tools/javac/processing/model/element/TestMissingElement/TestMissingElement.java Reviewed-by: darcy --- .../TestMissingElement.java | 18 +++++++-- .../TestMissingElement/TestMissingElement.ref | 38 +++++++++---------- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/langtools/test/tools/javac/processing/model/element/TestMissingElement/TestMissingElement.java b/langtools/test/tools/javac/processing/model/element/TestMissingElement/TestMissingElement.java index 2ddcd10bd26..644ec9d5b17 100644 --- a/langtools/test/tools/javac/processing/model/element/TestMissingElement/TestMissingElement.java +++ b/langtools/test/tools/javac/processing/model/element/TestMissingElement/TestMissingElement.java @@ -31,6 +31,7 @@ * @compile/fail/ref=TestMissingElement.ref -proc:only -XprintRounds -XDrawDiagnostics -processor TestMissingElement InvalidSource.java */ +import java.io.PrintWriter; import java.util.*; import javax.annotation.processing.*; import javax.lang.model.element.*; @@ -38,7 +39,18 @@ import javax.lang.model.type.*; import javax.lang.model.util.*; import static javax.tools.Diagnostic.Kind.*; +import com.sun.tools.javac.processing.JavacProcessingEnvironment; +import com.sun.tools.javac.util.Log; + public class TestMissingElement extends JavacTestingAbstractProcessor { + private PrintWriter out; + + @Override + public void init(ProcessingEnvironment env) { + super.init(env); + out = ((JavacProcessingEnvironment) env).getContext().get(Log.outKey); + } + @Override public boolean process(Set annotations, RoundEnvironment roundEnv) { for (TypeElement te: ElementFilter.typesIn(roundEnv.getRootElements())) { @@ -70,13 +82,13 @@ public class TestMissingElement extends JavacTestingAbstractProcessor { } private void checkInterfaces(TypeElement te, String expect) { - System.err.println("check interfaces: " + te + " -- " + expect); + out.println("check interfaces: " + te + " -- " + expect); String found = asString(te.getInterfaces(), ", "); checkEqual("interfaces", te, found, expect); } private void checkSupertype(TypeElement te, String expect) { - System.err.println("check supertype: " + te + " -- " + expect); + out.println("check supertype: " + te + " -- " + expect); String found = asString(te.getSuperclass()); checkEqual("supertype", te, found, expect); } @@ -85,7 +97,7 @@ public class TestMissingElement extends JavacTestingAbstractProcessor { if (found.equals(expect)) { // messager.printMessage(NOTE, "expected " + label + " found: " + expect, te); } else { - System.err.println("unexpected " + label + ": " + te + "\n" + out.println("unexpected " + label + ": " + te + "\n" + " found: " + found + "\n" + "expect: " + expect); messager.printMessage(ERROR, "unexpected " + label + " found: " + found + "; expected: " + expect, te); diff --git a/langtools/test/tools/javac/processing/model/element/TestMissingElement/TestMissingElement.ref b/langtools/test/tools/javac/processing/model/element/TestMissingElement/TestMissingElement.ref index 4c31a101dbb..d71a2cce8ba 100644 --- a/langtools/test/tools/javac/processing/model/element/TestMissingElement/TestMissingElement.ref +++ b/langtools/test/tools/javac/processing/model/element/TestMissingElement/TestMissingElement.ref @@ -2,6 +2,24 @@ Round 1: input files: {ExpectInterfaces, ExpectSupertype, OK, InvalidSource} annotations: [ExpectSupertype, ExpectInterfaces] last round: false +check supertype: InvalidSource.TestClassMissingClassA -- !:empty clss A! +check supertype: InvalidSource.TestClassMissingClassAB -- !:empty clss (pkg A).B! +check supertype: InvalidSource.TestClassMissingClass_juA -- !:empty clss (pkg java.util).A! +check supertype: InvalidSource.TestClassTMissingClassAT -- !:empty clss A! +check interfaces: InvalidSource.TestClassMissingIntfA -- !:empty intf A! +check interfaces: InvalidSource.TestClassMissingIntfAB -- !:empty intf (pkg A).B! +check interfaces: InvalidSource.TestClassMissingIntfAOK -- !:empty intf A!, intf OK +check interfaces: InvalidSource.TestClassOKMissingIntfA -- intf OK, !:empty intf A! +check interfaces: InvalidSource.TestClassMissingIntfA_B -- !:empty intf A!, !:empty intf B! +check interfaces: InvalidSource.TestIntfMissingIntfA -- !:empty intf A! +check interfaces: InvalidSource.TestIntfMissingIntfAOK -- !:empty intf A!, intf OK +check interfaces: InvalidSource.TestIntfOKMissingIntfA -- intf OK, !:empty intf A! +check interfaces: InvalidSource.TestIntfMissingIntfAB -- !:empty intf A!, !:empty intf B! +check interfaces: InvalidSource.TestClassTMissingIntfAT -- !:empty intf A! +check interfaces: InvalidSource.TestClassTMissingIntfAT_B -- !:empty intf A!, !:empty intf B! +check interfaces: InvalidSource.TestIntfTMissingIntfAT -- !:empty intf A! +check interfaces: InvalidSource.TestIntfTMissingIntfAT_B -- !:empty intf A!, !:empty intf B! +check interfaces: InvalidSource.TestClassListMissingX -- intf (pkg java.util).List Round 2: input files: {} annotations: [] @@ -28,22 +46,4 @@ InvalidSource.java:100:49: compiler.err.cant.resolve.location: kindname.class, A InvalidSource.java:103:51: compiler.err.cant.resolve.location: kindname.class, A, , , (compiler.misc.location: kindname.class, InvalidSource, null) InvalidSource.java:103:57: compiler.err.cant.resolve.location: kindname.class, B, , , (compiler.misc.location: kindname.class, InvalidSource, null) InvalidSource.java:106:58: compiler.err.cant.resolve.location: kindname.class, X, , , (compiler.misc.location: kindname.class, InvalidSource, null) -22 errors -check supertype: InvalidSource.TestClassMissingClassA -- !:empty clss A! -check supertype: InvalidSource.TestClassMissingClassAB -- !:empty clss (pkg A).B! -check supertype: InvalidSource.TestClassMissingClass_juA -- !:empty clss (pkg java.util).A! -check supertype: InvalidSource.TestClassTMissingClassAT -- !:empty clss A! -check interfaces: InvalidSource.TestClassMissingIntfA -- !:empty intf A! -check interfaces: InvalidSource.TestClassMissingIntfAB -- !:empty intf (pkg A).B! -check interfaces: InvalidSource.TestClassMissingIntfAOK -- !:empty intf A!, intf OK -check interfaces: InvalidSource.TestClassOKMissingIntfA -- intf OK, !:empty intf A! -check interfaces: InvalidSource.TestClassMissingIntfA_B -- !:empty intf A!, !:empty intf B! -check interfaces: InvalidSource.TestIntfMissingIntfA -- !:empty intf A! -check interfaces: InvalidSource.TestIntfMissingIntfAOK -- !:empty intf A!, intf OK -check interfaces: InvalidSource.TestIntfOKMissingIntfA -- intf OK, !:empty intf A! -check interfaces: InvalidSource.TestIntfMissingIntfAB -- !:empty intf A!, !:empty intf B! -check interfaces: InvalidSource.TestClassTMissingIntfAT -- !:empty intf A! -check interfaces: InvalidSource.TestClassTMissingIntfAT_B -- !:empty intf A!, !:empty intf B! -check interfaces: InvalidSource.TestIntfTMissingIntfAT -- !:empty intf A! -check interfaces: InvalidSource.TestIntfTMissingIntfAT_B -- !:empty intf A!, !:empty intf B! -check interfaces: InvalidSource.TestClassListMissingX -- intf (pkg java.util).List \ No newline at end of file +22 errors \ No newline at end of file From a9e5e17bd2827d68e0121b1c615b9c3144ad64e2 Mon Sep 17 00:00:00 2001 From: Jan Lahoda Date: Mon, 9 Sep 2013 23:13:45 +0200 Subject: [PATCH 111/210] 8019521: Enhanced rethrow disabled in lambdas Fixing effectively final detection inside lambdas, small cleanup related to thrown types detection in lambdas Reviewed-by: mcimadamore, jjg --- .../com/sun/tools/javac/comp/Attr.java | 20 ++++++------ .../com/sun/tools/javac/comp/Flow.java | 32 ++++++++++++++++--- .../com/sun/tools/javac/tree/JCTree.java | 1 - .../javac/lambda/EffectivelyFinalThrows.java | 25 +++++++++++++++ 4 files changed, 64 insertions(+), 14 deletions(-) create mode 100644 langtools/test/tools/javac/lambda/EffectivelyFinalThrows.java diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java b/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java index 434f0b3815b..c09ab8907a2 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java @@ -2418,9 +2418,17 @@ public class Attr extends JCTree.Visitor { preFlow(that); flow.analyzeLambda(env, that, make, isSpeculativeRound); - checkLambdaCompatible(that, lambdaType, resultInfo.checkContext, isSpeculativeRound); + checkLambdaCompatible(that, lambdaType, resultInfo.checkContext); if (!isSpeculativeRound) { + //add thrown types as bounds to the thrown types free variables if needed: + if (resultInfo.checkContext.inferenceContext().free(lambdaType.getThrownTypes())) { + List inferredThrownTypes = flow.analyzeLambdaThrownTypes(env, that, make); + List thrownTypes = resultInfo.checkContext.inferenceContext().asFree(lambdaType.getThrownTypes()); + + chk.unhandled(inferredThrownTypes, thrownTypes); + } + checkAccessibleTypes(that, localEnv, resultInfo.checkContext.inferenceContext(), lambdaType, currentTarget); } result = check(that, currentTarget, VAL, resultInfo); @@ -2587,10 +2595,9 @@ public class Attr extends JCTree.Visitor { * Lambda compatibility. Check that given return types, thrown types, parameter types * are compatible with the expected functional interface descriptor. This means that: * (i) parameter types must be identical to those of the target descriptor; (ii) return - * types must be compatible with the return type of the expected descriptor; - * (iii) finish inference of thrown types if required. + * types must be compatible with the return type of the expected descriptor. */ - private void checkLambdaCompatible(JCLambda tree, Type descriptor, CheckContext checkContext, boolean speculativeAttr) { + private void checkLambdaCompatible(JCLambda tree, Type descriptor, CheckContext checkContext) { Type returnType = checkContext.inferenceContext().asFree(descriptor.getReturnType()); //return values have already been checked - but if lambda has no return @@ -2607,11 +2614,6 @@ public class Attr extends JCTree.Visitor { if (!types.isSameTypes(argTypes, TreeInfo.types(tree.params))) { checkContext.report(tree, diags.fragment("incompatible.arg.types.in.lambda")); } - - if (!speculativeAttr) { - List thrownTypes = checkContext.inferenceContext().asFree(descriptor.getThrownTypes()); - chk.unhandled(tree.inferredThrownTypes == null ? List.nil() : tree.inferredThrownTypes, thrownTypes); - } } private Env lambdaEnv(JCLambda that, Env env) { diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/Flow.java b/langtools/src/share/classes/com/sun/tools/javac/comp/Flow.java index e488d45b0c0..466436b6b9e 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Flow.java +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Flow.java @@ -224,7 +224,6 @@ public class Flow { } try { new AliveAnalyzer().analyzeTree(env, that, make); - new LambdaFlowAnalyzer().analyzeTree(env, that, make); } finally { if (!speculative) { log.popDiagnosticHandler(diagHandler); @@ -232,6 +231,23 @@ public class Flow { } } + public List analyzeLambdaThrownTypes(Env env, JCLambda that, TreeMaker make) { + //we need to disable diagnostics temporarily; the problem is that if + //a lambda expression contains e.g. an unreachable statement, an error + //message will be reported and will cause compilation to skip the flow analyis + //step - if we suppress diagnostics, we won't stop at Attr for flow-analysis + //related errors, which will allow for more errors to be detected + Log.DiagnosticHandler diagHandler = new Log.DiscardDiagnosticHandler(log); + try { + new AssignAnalyzer().analyzeTree(env, that, make); + LambdaFlowAnalyzer flowAnalyzer = new LambdaFlowAnalyzer(); + flowAnalyzer.analyzeTree(env, that, make); + return flowAnalyzer.inferredThrownTypes; + } finally { + log.popDiagnosticHandler(diagHandler); + } + } + /** * Definite assignment scan mode */ @@ -1318,27 +1334,35 @@ public class Flow { * Specialized pass that performs inference of thrown types for lambdas. */ class LambdaFlowAnalyzer extends FlowAnalyzer { + List inferredThrownTypes; + boolean inLambda; @Override public void visitLambda(JCLambda tree) { - if (tree.type != null && - tree.type.isErroneous()) { + if ((tree.type != null && + tree.type.isErroneous()) || inLambda) { return; } List prevCaught = caught; List prevThrown = thrown; ListBuffer prevPending = pendingExits; + inLambda = true; try { pendingExits = ListBuffer.lb(); caught = List.of(syms.throwableType); thrown = List.nil(); scan(tree.body); - tree.inferredThrownTypes = thrown; + inferredThrownTypes = thrown; } finally { pendingExits = prevPending; caught = prevCaught; thrown = prevThrown; + inLambda = false; } } + @Override + public void visitClassDef(JCClassDecl tree) { + //skip + } } /** diff --git a/langtools/src/share/classes/com/sun/tools/javac/tree/JCTree.java b/langtools/src/share/classes/com/sun/tools/javac/tree/JCTree.java index a0581cce87a..d1d71080027 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/tree/JCTree.java +++ b/langtools/src/share/classes/com/sun/tools/javac/tree/JCTree.java @@ -1596,7 +1596,6 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition { public List params; public JCTree body; public boolean canCompleteNormally = true; - public List inferredThrownTypes; public ParameterKind paramKind; public JCLambda(List params, diff --git a/langtools/test/tools/javac/lambda/EffectivelyFinalThrows.java b/langtools/test/tools/javac/lambda/EffectivelyFinalThrows.java new file mode 100644 index 00000000000..54183173f3a --- /dev/null +++ b/langtools/test/tools/javac/lambda/EffectivelyFinalThrows.java @@ -0,0 +1,25 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8019521 + * @summary Check that enhanced rethrow/effectivelly final works correctly inside lambdas + * @compile EffectivelyFinalThrows.java + */ + +class EffectivelyFinalThrows { + interface SAM { + public void t() throws E; + } + void test(SAM s) throws E { + s.t(); + } + void test2(SAM s) throws Checked { + test(() -> { + try { + s.t(); + } catch (Throwable t) { + throw t; + } + }); + } + static class Checked extends Exception {} +} From 4d99afea082e01c35984e24eb11fbd00327b9f4f Mon Sep 17 00:00:00 2001 From: Albert Noll Date: Tue, 10 Sep 2013 07:51:37 +0200 Subject: [PATCH 112/210] 8024473: Remove unused macro: IRT_ENTRY_FOR_NMETHOD Removed unused macro Reviewed-by: kvn, adlertz --- hotspot/src/share/vm/runtime/interfaceSupport.hpp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/hotspot/src/share/vm/runtime/interfaceSupport.hpp b/hotspot/src/share/vm/runtime/interfaceSupport.hpp index f995a4ee714..4d2ca5137ea 100644 --- a/hotspot/src/share/vm/runtime/interfaceSupport.hpp +++ b/hotspot/src/share/vm/runtime/interfaceSupport.hpp @@ -471,16 +471,6 @@ class RuntimeHistogramElement : public HistogramElement { VM_ENTRY_BASE(result_type, header, thread) \ debug_only(VMEntryWrapper __vew;) -// Another special case for nmethod_entry_point so the nmethod that the -// interpreter is about to branch to doesn't get flushed before as we -// branch to it's interpreter_entry_point. Skip stress testing here too. -// Also we don't allow async exceptions because it is just too painful. -#define IRT_ENTRY_FOR_NMETHOD(result_type, header) \ - result_type header { \ - nmethodLocker _nmlock(nm); \ - ThreadInVMfromJavaNoAsyncException __tiv(thread); \ - VM_ENTRY_BASE(result_type, header, thread) - #define IRT_END } From fae7d60062ef1378fc5b35a85f77022b56f3aa4c Mon Sep 17 00:00:00 2001 From: Andreas Lundblad Date: Tue, 10 Sep 2013 13:47:51 +0200 Subject: [PATCH 113/210] 8005222: Fixed bugs should have tests with bugid in @bug tag Reviewed-by: jfranck, jjg --- .../javac/defaultMethods/ClassReaderTest/ClassReaderTest.java | 3 ++- langtools/test/tools/javac/defaultMethods/Neg01.java | 4 ++-- langtools/test/tools/javac/defaultMethods/Neg02.java | 4 ++-- langtools/test/tools/javac/defaultMethods/Neg03.java | 4 ++-- langtools/test/tools/javac/defaultMethods/Neg04.java | 4 ++-- langtools/test/tools/javac/defaultMethods/Neg05.java | 4 ++-- langtools/test/tools/javac/defaultMethods/Neg06.java | 4 ++-- langtools/test/tools/javac/defaultMethods/Neg07.java | 4 ++-- langtools/test/tools/javac/defaultMethods/Neg08.java | 4 ++-- langtools/test/tools/javac/defaultMethods/Neg09.java | 4 ++-- langtools/test/tools/javac/defaultMethods/Neg10.java | 4 ++-- langtools/test/tools/javac/defaultMethods/Neg11.java | 4 ++-- langtools/test/tools/javac/defaultMethods/Neg12.java | 4 ++-- langtools/test/tools/javac/defaultMethods/Neg13.java | 4 ++-- langtools/test/tools/javac/defaultMethods/Neg14.java | 4 ++-- langtools/test/tools/javac/defaultMethods/Neg15.java | 4 ++-- langtools/test/tools/javac/defaultMethods/Neg16.java | 4 ++-- langtools/test/tools/javac/defaultMethods/Pos01.java | 3 ++- langtools/test/tools/javac/defaultMethods/Pos02.java | 3 ++- langtools/test/tools/javac/defaultMethods/Pos04.java | 3 ++- langtools/test/tools/javac/defaultMethods/Pos05.java | 3 ++- langtools/test/tools/javac/defaultMethods/Pos06.java | 3 ++- langtools/test/tools/javac/defaultMethods/Pos07.java | 3 ++- langtools/test/tools/javac/defaultMethods/Pos08.java | 3 ++- langtools/test/tools/javac/defaultMethods/Pos10.java | 3 ++- langtools/test/tools/javac/defaultMethods/Pos11.java | 3 ++- langtools/test/tools/javac/defaultMethods/Pos12.java | 3 ++- langtools/test/tools/javac/defaultMethods/Pos13.java | 3 ++- langtools/test/tools/javac/defaultMethods/Pos14.java | 3 ++- langtools/test/tools/javac/defaultMethods/Pos15.java | 3 ++- langtools/test/tools/javac/defaultMethods/Pos16.java | 3 ++- .../test/tools/javac/defaultMethods/TestDefaultBody.java | 3 ++- .../tools/javac/defaultMethods/TestNoBridgeOnDefaults.java | 3 ++- .../tools/javac/defaultMethods/crossCompile/CrossCompile.java | 3 ++- .../test/tools/javac/defaultMethods/separate/Separate.java | 3 ++- .../javac/defaultMethods/super/TestDefaultSuperCall.java | 2 +- langtools/test/tools/javac/lambda/EffectivelyFinalTest.java | 2 +- 37 files changed, 72 insertions(+), 53 deletions(-) diff --git a/langtools/test/tools/javac/defaultMethods/ClassReaderTest/ClassReaderTest.java b/langtools/test/tools/javac/defaultMethods/ClassReaderTest/ClassReaderTest.java index 0e533acbe6f..491486f106e 100644 --- a/langtools/test/tools/javac/defaultMethods/ClassReaderTest/ClassReaderTest.java +++ b/langtools/test/tools/javac/defaultMethods/ClassReaderTest/ClassReaderTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2013, 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,6 +23,7 @@ /* * @test + * @bug 7192246 * @summary check that default methods don't cause ClassReader to complete classes recursively * @author Maurizio Cimadamore * @compile pkg/Foo.java diff --git a/langtools/test/tools/javac/defaultMethods/Neg01.java b/langtools/test/tools/javac/defaultMethods/Neg01.java index bbf1aba7eaa..0457b5de9bc 100644 --- a/langtools/test/tools/javac/defaultMethods/Neg01.java +++ b/langtools/test/tools/javac/defaultMethods/Neg01.java @@ -1,5 +1,5 @@ -/* - * @test /nodynamiccopyright/ +/* @test /nodynamiccopyright/ + * @bug 7192246 * @summary negative test for ambiguous defaults * @compile/fail/ref=Neg01.out -XDrawDiagnostics Neg01.java */ diff --git a/langtools/test/tools/javac/defaultMethods/Neg02.java b/langtools/test/tools/javac/defaultMethods/Neg02.java index deb35a19d78..2ba1319ae96 100644 --- a/langtools/test/tools/javac/defaultMethods/Neg02.java +++ b/langtools/test/tools/javac/defaultMethods/Neg02.java @@ -1,5 +1,5 @@ -/* - * @test /nodynamiccopyright/ +/* @test /nodynamiccopyright/ + * @bug 7192246 * @summary check that ill-formed MI hierarchies do not compile * @compile/fail/ref=Neg02.out -XDrawDiagnostics Neg02.java */ diff --git a/langtools/test/tools/javac/defaultMethods/Neg03.java b/langtools/test/tools/javac/defaultMethods/Neg03.java index ba6262c853b..2a1fbe48df2 100644 --- a/langtools/test/tools/javac/defaultMethods/Neg03.java +++ b/langtools/test/tools/javac/defaultMethods/Neg03.java @@ -1,5 +1,5 @@ -/* - * @test /nodynamiccopyright/ +/* @test /nodynamiccopyright/ + * @bug 7192246 * @summary check that re-abstraction works properly * @compile/fail/ref=Neg03.out -XDrawDiagnostics Neg03.java */ diff --git a/langtools/test/tools/javac/defaultMethods/Neg04.java b/langtools/test/tools/javac/defaultMethods/Neg04.java index a057f35d620..c1abcfad8f3 100644 --- a/langtools/test/tools/javac/defaultMethods/Neg04.java +++ b/langtools/test/tools/javac/defaultMethods/Neg04.java @@ -1,5 +1,5 @@ -/* - * @test /nodynamiccopyright/ +/* @test /nodynamiccopyright/ + * @bug 7192246 * @summary check that default method must have most specific return type * @compile/fail/ref=Neg04.out -XDrawDiagnostics Neg04.java */ diff --git a/langtools/test/tools/javac/defaultMethods/Neg05.java b/langtools/test/tools/javac/defaultMethods/Neg05.java index 3550c497241..8be5cf59019 100644 --- a/langtools/test/tools/javac/defaultMethods/Neg05.java +++ b/langtools/test/tools/javac/defaultMethods/Neg05.java @@ -1,5 +1,5 @@ -/* - * @test /nodynamiccopyright/ +/* @test /nodynamiccopyright/ + * @bug 7192246 * @summary check that abstract methods are compatible with inherited defaults * @compile/fail/ref=Neg05.out -XDrawDiagnostics Neg05.java */ diff --git a/langtools/test/tools/javac/defaultMethods/Neg06.java b/langtools/test/tools/javac/defaultMethods/Neg06.java index 602ece8166f..23a757f5791 100644 --- a/langtools/test/tools/javac/defaultMethods/Neg06.java +++ b/langtools/test/tools/javac/defaultMethods/Neg06.java @@ -1,5 +1,5 @@ -/* - * @test /nodynamiccopyright/ +/* @test /nodynamiccopyright/ + * @bug 7192246 * @summary flow analysis is not run on inlined default bodies * @compile/fail/ref=Neg06.out -XDrawDiagnostics Neg06.java */ diff --git a/langtools/test/tools/javac/defaultMethods/Neg07.java b/langtools/test/tools/javac/defaultMethods/Neg07.java index c11f3157b22..763a253623a 100644 --- a/langtools/test/tools/javac/defaultMethods/Neg07.java +++ b/langtools/test/tools/javac/defaultMethods/Neg07.java @@ -1,5 +1,5 @@ -/* - * @test /nodynamiccopyright/ +/* @test /nodynamiccopyright/ + * @bug 7192246 * @summary check that default overrides are properly type-checked * @compile/fail/ref=Neg07.out -XDrawDiagnostics Neg07.java */ diff --git a/langtools/test/tools/javac/defaultMethods/Neg08.java b/langtools/test/tools/javac/defaultMethods/Neg08.java index 5e3ef07e719..b6eb221c1e2 100644 --- a/langtools/test/tools/javac/defaultMethods/Neg08.java +++ b/langtools/test/tools/javac/defaultMethods/Neg08.java @@ -1,5 +1,5 @@ -/* - * @test /nodynamiccopyright/ +/* @test /nodynamiccopyright/ + * @bug 7192246 * @summary check that default overrides are properly type-checked * @compile/fail/ref=Neg08.out -XDrawDiagnostics Neg08.java */ diff --git a/langtools/test/tools/javac/defaultMethods/Neg09.java b/langtools/test/tools/javac/defaultMethods/Neg09.java index cabda07c321..dc7801a0a2c 100644 --- a/langtools/test/tools/javac/defaultMethods/Neg09.java +++ b/langtools/test/tools/javac/defaultMethods/Neg09.java @@ -1,5 +1,5 @@ -/* - * @test /nodynamiccopyright/ +/* @test /nodynamiccopyright/ + * @bug 7192246 * @summary check that default overrides are properly type-checked * @compile/fail/ref=Neg09.out -Werror -Xlint:unchecked -XDrawDiagnostics Neg09.java */ diff --git a/langtools/test/tools/javac/defaultMethods/Neg10.java b/langtools/test/tools/javac/defaultMethods/Neg10.java index 3ecb1af86e1..188fd7f0747 100644 --- a/langtools/test/tools/javac/defaultMethods/Neg10.java +++ b/langtools/test/tools/javac/defaultMethods/Neg10.java @@ -1,5 +1,5 @@ -/* - * @test /nodynamiccopyright/ +/* @test /nodynamiccopyright/ + * @bug 7192246 * @summary check that default overrides are properly type-checked * @compile/fail/ref=Neg10.out -Werror -Xlint:unchecked -XDrawDiagnostics Neg10.java */ diff --git a/langtools/test/tools/javac/defaultMethods/Neg11.java b/langtools/test/tools/javac/defaultMethods/Neg11.java index acf88f65ef2..c3b35b68b38 100644 --- a/langtools/test/tools/javac/defaultMethods/Neg11.java +++ b/langtools/test/tools/javac/defaultMethods/Neg11.java @@ -1,5 +1,5 @@ -/* - * @test /nodynamiccopyright/ +/* @test /nodynamiccopyright/ + * @bug 7192246 * @summary check that default overrides are properly type-checked * @compile/fail/ref=Neg11.out -XDrawDiagnostics Neg11.java */ diff --git a/langtools/test/tools/javac/defaultMethods/Neg12.java b/langtools/test/tools/javac/defaultMethods/Neg12.java index e61245bf7e3..267dc86f70e 100644 --- a/langtools/test/tools/javac/defaultMethods/Neg12.java +++ b/langtools/test/tools/javac/defaultMethods/Neg12.java @@ -1,5 +1,5 @@ -/* - * @test /nodynamiccopyright/ +/* @test /nodynamiccopyright/ + * @bug 7192246 * @summary check that abstract methods are discarded in overload resolution diags * @compile/fail/ref=Neg12.out -XDrawDiagnostics Neg12.java */ diff --git a/langtools/test/tools/javac/defaultMethods/Neg13.java b/langtools/test/tools/javac/defaultMethods/Neg13.java index e512cc3a65b..a166adab3f1 100644 --- a/langtools/test/tools/javac/defaultMethods/Neg13.java +++ b/langtools/test/tools/javac/defaultMethods/Neg13.java @@ -1,5 +1,5 @@ -/* - * @test /nodynamiccopyright/ +/* @test /nodynamiccopyright/ + * @bug 7192246 * @summary check that default method overriding object members are flagged as error * @compile/fail/ref=Neg13.out -XDrawDiagnostics Neg13.java */ diff --git a/langtools/test/tools/javac/defaultMethods/Neg14.java b/langtools/test/tools/javac/defaultMethods/Neg14.java index 9c3c6a69e3c..842b51607a1 100644 --- a/langtools/test/tools/javac/defaultMethods/Neg14.java +++ b/langtools/test/tools/javac/defaultMethods/Neg14.java @@ -1,5 +1,5 @@ -/* - * @test /nodynamiccopyright/ +/* @test /nodynamiccopyright/ + * @bug 7192246 * @summary check that a class cannot have two sibling interfaces with a default and abstract method * @compile/fail/ref=Neg14.out -XDrawDiagnostics Neg14.java */ diff --git a/langtools/test/tools/javac/defaultMethods/Neg15.java b/langtools/test/tools/javac/defaultMethods/Neg15.java index 7c42167d75f..1845733fe91 100644 --- a/langtools/test/tools/javac/defaultMethods/Neg15.java +++ b/langtools/test/tools/javac/defaultMethods/Neg15.java @@ -1,5 +1,5 @@ -/* - * @test /nodynamiccopyright/ +/* @test /nodynamiccopyright/ + * @bug 7192246 * @summary check that level skipping in default super calls is correctly rejected * @compile/fail/ref=Neg15.out -XDrawDiagnostics Neg15.java */ diff --git a/langtools/test/tools/javac/defaultMethods/Neg16.java b/langtools/test/tools/javac/defaultMethods/Neg16.java index 1022fda22c8..cb5ce4930f5 100644 --- a/langtools/test/tools/javac/defaultMethods/Neg16.java +++ b/langtools/test/tools/javac/defaultMethods/Neg16.java @@ -1,5 +1,5 @@ -/* - * @test /nodynamiccopyright/ +/* @test /nodynamiccopyright/ + * @bug 7192246 * @summary check that level skipping in default super calls is correctly rejected * @compile/fail/ref=Neg16.out -XDrawDiagnostics Neg16.java */ diff --git a/langtools/test/tools/javac/defaultMethods/Pos01.java b/langtools/test/tools/javac/defaultMethods/Pos01.java index 13fa6b47e83..30a3e3179f0 100644 --- a/langtools/test/tools/javac/defaultMethods/Pos01.java +++ b/langtools/test/tools/javac/defaultMethods/Pos01.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2013, 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,6 +23,7 @@ /* * @test + * @bug 7192246 * @summary basic test for default methods * @author Maurizio Cimadamore */ diff --git a/langtools/test/tools/javac/defaultMethods/Pos02.java b/langtools/test/tools/javac/defaultMethods/Pos02.java index 597e7f50c79..5b71e36f8bd 100644 --- a/langtools/test/tools/javac/defaultMethods/Pos02.java +++ b/langtools/test/tools/javac/defaultMethods/Pos02.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2013, 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,6 +23,7 @@ /* * @test + * @bug 7192246 * @summary test for explicit resolution of ambiguous default methods * @author Maurizio Cimadamore * @compile Pos02.java diff --git a/langtools/test/tools/javac/defaultMethods/Pos04.java b/langtools/test/tools/javac/defaultMethods/Pos04.java index 3cc0cd4c4c5..e238e280dd5 100644 --- a/langtools/test/tools/javac/defaultMethods/Pos04.java +++ b/langtools/test/tools/javac/defaultMethods/Pos04.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2013, 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,6 +23,7 @@ /* * @test + * @bug 7192246 * @summary test for overriding with default method * @author Maurizio Cimadamore * @compile Pos04.java diff --git a/langtools/test/tools/javac/defaultMethods/Pos05.java b/langtools/test/tools/javac/defaultMethods/Pos05.java index 92a7eaccc9c..181ce39d4ab 100644 --- a/langtools/test/tools/javac/defaultMethods/Pos05.java +++ b/langtools/test/tools/javac/defaultMethods/Pos05.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2013, 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,6 +23,7 @@ /* * @test + * @bug 7192246 * @summary check that indirectly inherited default methods are discovered during resolution * @author Maurizio Cimadamore * @compile Pos05.java diff --git a/langtools/test/tools/javac/defaultMethods/Pos06.java b/langtools/test/tools/javac/defaultMethods/Pos06.java index 3263e9276e2..15bcec46e4c 100644 --- a/langtools/test/tools/javac/defaultMethods/Pos06.java +++ b/langtools/test/tools/javac/defaultMethods/Pos06.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2013, 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,6 +23,7 @@ /* * @test + * @bug 7192246 * @summary check that well-formed MI hierarchies behaves well w.r.t. method resolution (i.e. no ambiguities) * @author Maurizio Cimadamore * @compile Pos06.java diff --git a/langtools/test/tools/javac/defaultMethods/Pos07.java b/langtools/test/tools/javac/defaultMethods/Pos07.java index 6e1c2308bb5..a48e8ba3993 100644 --- a/langtools/test/tools/javac/defaultMethods/Pos07.java +++ b/langtools/test/tools/javac/defaultMethods/Pos07.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2013, 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,6 +23,7 @@ /* * @test + * @bug 7192246 * @summary check that compilation order does not matter * @author Maurizio Cimadamore * @compile Pos07.java diff --git a/langtools/test/tools/javac/defaultMethods/Pos08.java b/langtools/test/tools/javac/defaultMethods/Pos08.java index b12486a7f8b..78bc0792257 100644 --- a/langtools/test/tools/javac/defaultMethods/Pos08.java +++ b/langtools/test/tools/javac/defaultMethods/Pos08.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2013, 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,6 +23,7 @@ /* * @test + * @bug 7192246 * @summary check that common overrider solves default method conflicts * @author Maurizio Cimadamore * @compile Pos08.java diff --git a/langtools/test/tools/javac/defaultMethods/Pos10.java b/langtools/test/tools/javac/defaultMethods/Pos10.java index 7f0039a685b..b4c6546fa2f 100644 --- a/langtools/test/tools/javac/defaultMethods/Pos10.java +++ b/langtools/test/tools/javac/defaultMethods/Pos10.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2013, 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,6 +23,7 @@ /* * @test + * @bug 7192246 * @summary check that type-variables in generic extension decl can be accessed from default impl * @author Maurizio Cimadamore * @compile Pos10.java diff --git a/langtools/test/tools/javac/defaultMethods/Pos11.java b/langtools/test/tools/javac/defaultMethods/Pos11.java index 91b83ccbb1c..3d6305e3be1 100644 --- a/langtools/test/tools/javac/defaultMethods/Pos11.java +++ b/langtools/test/tools/javac/defaultMethods/Pos11.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2013, 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,6 +23,7 @@ /* * @test + * @bug 7192246 * @summary complex test with conflict resolution via overriding * @author Brian Goetz * @compile Pos11.java diff --git a/langtools/test/tools/javac/defaultMethods/Pos12.java b/langtools/test/tools/javac/defaultMethods/Pos12.java index 4db7f3ca182..56d2d0ea5a5 100644 --- a/langtools/test/tools/javac/defaultMethods/Pos12.java +++ b/langtools/test/tools/javac/defaultMethods/Pos12.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2013, 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,6 +23,7 @@ /* * @test + * @bug 7192246 * @summary check that 'this' can be used from within an extension method * @compile Pos12.java */ diff --git a/langtools/test/tools/javac/defaultMethods/Pos13.java b/langtools/test/tools/javac/defaultMethods/Pos13.java index b9acba34b44..e267f4a3ecd 100644 --- a/langtools/test/tools/javac/defaultMethods/Pos13.java +++ b/langtools/test/tools/javac/defaultMethods/Pos13.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2013, 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,6 +23,7 @@ /* * @test + * @bug 7192246 * @summary qualified 'this' inside default method causes StackOverflowException * @compile Pos13.java */ diff --git a/langtools/test/tools/javac/defaultMethods/Pos14.java b/langtools/test/tools/javac/defaultMethods/Pos14.java index d8ac04af981..07801d35529 100644 --- a/langtools/test/tools/javac/defaultMethods/Pos14.java +++ b/langtools/test/tools/javac/defaultMethods/Pos14.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2013, 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,6 +23,7 @@ /* * @test + * @bug 7192246 * @summary check that overload resolution selects most specific signature * @compile Pos14.java */ diff --git a/langtools/test/tools/javac/defaultMethods/Pos15.java b/langtools/test/tools/javac/defaultMethods/Pos15.java index a2dad21b237..b1a3281c583 100644 --- a/langtools/test/tools/javac/defaultMethods/Pos15.java +++ b/langtools/test/tools/javac/defaultMethods/Pos15.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2013, 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,6 +23,7 @@ /* * @test + * @bug 7192246 * @summary check that overload resolution selects most specific signature * @compile Pos15.java */ diff --git a/langtools/test/tools/javac/defaultMethods/Pos16.java b/langtools/test/tools/javac/defaultMethods/Pos16.java index eca63b94faf..0d9a2b1da55 100644 --- a/langtools/test/tools/javac/defaultMethods/Pos16.java +++ b/langtools/test/tools/javac/defaultMethods/Pos16.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2013, 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,6 +23,7 @@ /* * @test + * @bug 7192246 * @summary 'class wins' should not short-circuit overload resolution * @compile Pos16.java */ diff --git a/langtools/test/tools/javac/defaultMethods/TestDefaultBody.java b/langtools/test/tools/javac/defaultMethods/TestDefaultBody.java index be3f6bfbf94..7f1be065bd1 100644 --- a/langtools/test/tools/javac/defaultMethods/TestDefaultBody.java +++ b/langtools/test/tools/javac/defaultMethods/TestDefaultBody.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2013, 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,6 +23,7 @@ /* * @test + * @bug 7192246 * @summary check that code attributed for default methods is correctly generated */ diff --git a/langtools/test/tools/javac/defaultMethods/TestNoBridgeOnDefaults.java b/langtools/test/tools/javac/defaultMethods/TestNoBridgeOnDefaults.java index 328629c51e7..ab464b70314 100644 --- a/langtools/test/tools/javac/defaultMethods/TestNoBridgeOnDefaults.java +++ b/langtools/test/tools/javac/defaultMethods/TestNoBridgeOnDefaults.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2013, 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,6 +23,7 @@ /* * @test + * @bug 7192246 * @summary check that javac does not generate bridge methods for defaults */ diff --git a/langtools/test/tools/javac/defaultMethods/crossCompile/CrossCompile.java b/langtools/test/tools/javac/defaultMethods/crossCompile/CrossCompile.java index de51d4afacd..6a6f9a12e49 100644 --- a/langtools/test/tools/javac/defaultMethods/crossCompile/CrossCompile.java +++ b/langtools/test/tools/javac/defaultMethods/crossCompile/CrossCompile.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2013, 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,6 +23,7 @@ /* * @test + * @bug 7192246 * @summary check that clinit in interface doesn't cause spurious default method diagnostics * @compile -source 1.4 -target 1.4 Clinit.java * @compile CrossCompile.java diff --git a/langtools/test/tools/javac/defaultMethods/separate/Separate.java b/langtools/test/tools/javac/defaultMethods/separate/Separate.java index 7dcf4e3ac2b..513fc996a9a 100644 --- a/langtools/test/tools/javac/defaultMethods/separate/Separate.java +++ b/langtools/test/tools/javac/defaultMethods/separate/Separate.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2013, 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,6 +23,7 @@ /* * @test + * @bug 7192246 * @summary smoke test for separate compilation of default methods * @author Maurizio Cimadamore * @compile pkg1/A.java diff --git a/langtools/test/tools/javac/defaultMethods/super/TestDefaultSuperCall.java b/langtools/test/tools/javac/defaultMethods/super/TestDefaultSuperCall.java index 9c3a513c90f..1fbeed6d5c2 100644 --- a/langtools/test/tools/javac/defaultMethods/super/TestDefaultSuperCall.java +++ b/langtools/test/tools/javac/defaultMethods/super/TestDefaultSuperCall.java @@ -23,7 +23,7 @@ /* * @test - * @bug 8006694 + * @bug 7192246 8006694 * @summary Automatic test for checking correctness of default super/this resolution * temporarily workaround combo tests are causing time out in several platforms * @library ../../lib diff --git a/langtools/test/tools/javac/lambda/EffectivelyFinalTest.java b/langtools/test/tools/javac/lambda/EffectivelyFinalTest.java index 9d1dff9b6e4..c701b3ca6d0 100644 --- a/langtools/test/tools/javac/lambda/EffectivelyFinalTest.java +++ b/langtools/test/tools/javac/lambda/EffectivelyFinalTest.java @@ -1,6 +1,6 @@ /* * @test /nodynamiccopyright/ - * @bug 8003280 + * @bug 7175538 8003280 * @summary Add lambda tests * Integrate effectively final check with DA/DU analysis * @compile/fail/ref=EffectivelyFinalTest01.out -XDrawDiagnostics EffectivelyFinalTest.java From de5e0f4b27daf5e87ef58f3821bf1b35b28561a5 Mon Sep 17 00:00:00 2001 From: Maurizio Cimadamore Date: Tue, 10 Sep 2013 16:47:40 +0100 Subject: [PATCH 114/210] 8024414: javac, should facilitate the use of the bootstrap compiler for debugging Reviewed-by: jjg --- langtools/make/netbeans/langtools/build.xml | 29 +++++-- .../make/tools/anttasks/SelectToolTask.java | 86 +++++++++++++++---- 2 files changed, 90 insertions(+), 25 deletions(-) diff --git a/langtools/make/netbeans/langtools/build.xml b/langtools/make/netbeans/langtools/build.xml index dd2caf9e3bc..cbb007057cc 100644 --- a/langtools/make/netbeans/langtools/build.xml +++ b/langtools/make/netbeans/langtools/build.xml @@ -1,6 +1,6 @@ @@ -136,9 +145,9 @@ - + - + @@ -207,6 +216,7 @@ @@ -216,6 +226,7 @@ @@ -226,10 +237,12 @@ + + - + diff --git a/langtools/make/tools/anttasks/SelectToolTask.java b/langtools/make/tools/anttasks/SelectToolTask.java index fb2cf49e312..5897398d173 100644 --- a/langtools/make/tools/anttasks/SelectToolTask.java +++ b/langtools/make/tools/anttasks/SelectToolTask.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2013, 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 @@ -43,6 +43,7 @@ import java.io.Reader; import java.io.Writer; import java.util.ArrayList; import java.util.Arrays; +import java.util.EnumSet; import java.util.List; import java.util.Properties; import javax.swing.JButton; @@ -71,6 +72,31 @@ import org.apache.tools.ant.Task; * is invoked to allow the user to set or reset values for use in property mode. */ public class SelectToolTask extends Task { + + enum ToolChoices { + NONE(""), + JAVAC("javac"), + JAVADOC("javadoc"), + JAVAH("javah"), + JAVAP("javap"); + + String toolName; + boolean bootstrap; + + ToolChoices(String toolName) { + this(toolName, false); + } + + ToolChoices(String toolName, boolean boostrap) { + this.toolName = toolName; + } + + @Override + public String toString() { + return toolName; + } + } + /** * Set the location of the private properties file used to keep the retain * user preferences for this repository. @@ -96,6 +122,14 @@ public class SelectToolTask extends Task { this.argsProperty = argsProperty; } + /** + * Set the name of the property which will be set to the execution args of the + * selected tool, if any. The args default to an empty string. + */ + public void setBootstrapProperty(String bootstrapProperty) { + this.bootstrapProperty = bootstrapProperty; + } + /** * Specify whether or not to pop up a dialog if the user has not specified * a default value for a property. @@ -110,6 +144,7 @@ public class SelectToolTask extends Task { Properties props = readProperties(propertyFile); toolName = props.getProperty("tool.name"); + toolBootstrap = props.getProperty("tool.bootstrap") != null; if (toolName != null) { toolArgs = props.getProperty(toolName + ".args", ""); } @@ -123,6 +158,8 @@ public class SelectToolTask extends Task { // finally, return required values, if any if (toolProperty != null && !(toolName == null || toolName.equals(""))) { p.setProperty(toolProperty, toolName); + if (toolBootstrap) + p.setProperty(bootstrapProperty, "true"); if (argsProperty != null && toolArgs != null) p.setProperty(argsProperty, toolArgs); @@ -134,14 +171,20 @@ public class SelectToolTask extends Task { JOptionPane p = createPane(guiProps); p.createDialog("Select Tool").setVisible(true); - toolName = (String) toolChoice.getSelectedItem(); + toolName = ((ToolChoices)toolChoice.getSelectedItem()).toolName; toolArgs = argsField.getText(); - + toolBootstrap = bootstrapCheckbox.isSelected(); if (defaultCheck.isSelected()) { if (toolName.equals("")) { fileProps.remove("tool.name"); + fileProps.remove("tool.bootstrap"); } else { fileProps.put("tool.name", toolName); + if (toolBootstrap) { + fileProps.put("tool.bootstrap", "true"); + } else { + fileProps.remove("tool.bootstrap"); + } fileProps.put(toolName + ".args", toolArgs); } writeProperties(propertyFile, fileProps); @@ -154,32 +197,38 @@ public class SelectToolTask extends Task { lc.insets.right = 10; lc.insets.bottom = 3; GridBagConstraints fc = new GridBagConstraints(); - fc.anchor = GridBagConstraints.WEST; fc.gridx = 1; - fc.gridwidth = GridBagConstraints.REMAINDER; + fc.gridwidth = GridBagConstraints.NONE; fc.insets.bottom = 3; + JPanel toolPane = new JPanel(new GridBagLayout()); + JLabel toolLabel = new JLabel("Tool:"); body.add(toolLabel, lc); - String[] toolChoices = { "apt", "javac", "javadoc", "javah", "javap" }; - if (true || toolProperty == null) { - // include empty value in setup mode - List l = new ArrayList(Arrays.asList(toolChoices)); - l.add(0, ""); - toolChoices = l.toArray(new String[l.size()]); - } - toolChoice = new JComboBox(toolChoices); + EnumSet toolChoices = toolProperty == null ? + EnumSet.allOf(ToolChoices.class) : EnumSet.range(ToolChoices.JAVAC, ToolChoices.JAVAP); + toolChoice = new JComboBox(toolChoices.toArray()); if (toolName != null) - toolChoice.setSelectedItem(toolName); + toolChoice.setSelectedItem(ToolChoices.valueOf(toolName.toUpperCase())); toolChoice.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { - String tn = (String) e.getItem(); + String tn = ((ToolChoices)e.getItem()).toolName; argsField.setText(getDefaultArgsForTool(props, tn)); if (toolProperty != null) okButton.setEnabled(!tn.equals("")); } }); - body.add(toolChoice, fc); + GridBagConstraints checkConstraint = new GridBagConstraints(); + fc.anchor = GridBagConstraints.EAST; + + GridBagConstraints toolConstraint = new GridBagConstraints(); + fc.anchor = GridBagConstraints.WEST; + + toolPane.add(toolChoice, toolConstraint); + bootstrapCheckbox = new JCheckBox("bootstrap", toolBootstrap); + toolPane.add(bootstrapCheckbox, checkConstraint); + + body.add(toolPane, fc); argsField = new JTextField(getDefaultArgsForTool(props, toolName), 40); if (toolProperty == null || argsProperty != null) { @@ -190,7 +239,7 @@ public class SelectToolTask extends Task { public void focusGained(FocusEvent e) { } public void focusLost(FocusEvent e) { - String toolName = (String) toolChoice.getSelectedItem(); + String toolName = ((ToolChoices)toolChoice.getSelectedItem()).toolName; if (toolName.length() > 0) props.put(toolName + ".args", argsField.getText()); } @@ -271,16 +320,19 @@ public class SelectToolTask extends Task { // Ant task parameters private boolean askIfUnset; private String toolProperty; + private String bootstrapProperty; private String argsProperty; private File propertyFile; // GUI components private JComboBox toolChoice; + private JCheckBox bootstrapCheckbox; private JTextField argsField; private JCheckBox defaultCheck; private JButton okButton; // Result values for the client private String toolName; + private boolean toolBootstrap; private String toolArgs; } From 47f48cad92630ada6ccd34d7d7aa2b6191cb1bf9 Mon Sep 17 00:00:00 2001 From: Andrew Brygin Date: Tue, 10 Sep 2013 21:54:14 +0400 Subject: [PATCH 115/210] 8024511: Crash during color profile destruction Reviewed-by: vadim, prr --- .../share/native/sun/java2d/cmm/lcms/LCMS.c | 2 +- .../cmm/ProfileOp/DisposalCrashTest.java | 83 +++++++++++++++++++ 2 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 jdk/test/sun/java2d/cmm/ProfileOp/DisposalCrashTest.java diff --git a/jdk/src/share/native/sun/java2d/cmm/lcms/LCMS.c b/jdk/src/share/native/sun/java2d/cmm/lcms/LCMS.c index 13030cc41d5..b2c4fce4229 100644 --- a/jdk/src/share/native/sun/java2d/cmm/lcms/LCMS.c +++ b/jdk/src/share/native/sun/java2d/cmm/lcms/LCMS.c @@ -307,7 +307,7 @@ JNIEXPORT jlong JNICALL Java_sun_java2d_cmm_lcms_LCMS_loadProfileNative if (sProf.lcmsPf != NULL) { // register the disposer record sProf.lcmsPf->pf = pf; - Disposer_AddRecord(env, disposerRef, LCMS_freeTransform, sProf.j); + Disposer_AddRecord(env, disposerRef, LCMS_freeProfile, sProf.j); } else { cmsCloseProfile(pf); } diff --git a/jdk/test/sun/java2d/cmm/ProfileOp/DisposalCrashTest.java b/jdk/test/sun/java2d/cmm/ProfileOp/DisposalCrashTest.java new file mode 100644 index 00000000000..ab8527d76da --- /dev/null +++ b/jdk/test/sun/java2d/cmm/ProfileOp/DisposalCrashTest.java @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2013, 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 8024511 + * @summary Verifies that instances of color profiles are destroyed correctly. + * A crash during profile destruction indicates failure. + * + * @run main DisposalCrashTest + */ + +import static java.awt.color.ColorSpace.*; +import java.awt.color.ICC_Profile; +import java.lang.ref.Reference; +import java.lang.ref.ReferenceQueue; +import java.lang.ref.WeakReference; +import java.util.Vector; + +public class DisposalCrashTest { + + static final ReferenceQueue queue = new ReferenceQueue<>(); + static final Vector> v = new Vector<>(); + + public static void main(String[] args) { + int[] ids = new int[]{ + CS_sRGB, CS_CIEXYZ, CS_GRAY, CS_LINEAR_RGB, CS_PYCC + }; + + for (int id : ids) { + ICC_Profile p = getCopyOf(id); + } + + while (!v.isEmpty()) { + System.gc(); + System.out.println("."); + try { + Thread.sleep(500); + } catch (InterruptedException e) {}; + + final Reference ref = queue.poll(); + System.out.println("Got reference: " + ref); + + v.remove(ref); + } + + System.out.println("Test PASSED."); + } + + private static ICC_Profile getCopyOf(int id) { + ICC_Profile std = ICC_Profile.getInstance(id); + + byte[] data = std.getData(); + + ICC_Profile p = ICC_Profile.getInstance(data); + + WeakReference ref = new WeakReference<>(p, queue); + + v.add(ref); + + return p; + } +} From f0e77ac67f03c437020a14081b54bb2cce168ded Mon Sep 17 00:00:00 2001 From: Vladimir Ivanov Date: Tue, 10 Sep 2013 14:51:48 -0700 Subject: [PATCH 116/210] 8001107: @Stable annotation for constant folding of lazily evaluated variables Co-authored-by: John Rose Reviewed-by: rbackman, twisti, kvn --- hotspot/src/share/vm/ci/ciArray.cpp | 79 ++++++++++++++++ hotspot/src/share/vm/ci/ciArray.hpp | 19 +++- hotspot/src/share/vm/ci/ciConstant.hpp | 15 +++- hotspot/src/share/vm/ci/ciField.cpp | 20 +++-- hotspot/src/share/vm/ci/ciField.hpp | 6 +- hotspot/src/share/vm/ci/ciFlags.hpp | 1 + hotspot/src/share/vm/ci/ciInstance.cpp | 2 + hotspot/src/share/vm/ci/ciTypeArray.cpp | 7 +- .../share/vm/classfile/classFileParser.cpp | 6 ++ .../share/vm/classfile/classFileParser.hpp | 18 +++- hotspot/src/share/vm/classfile/vmSymbols.hpp | 1 + hotspot/src/share/vm/oops/fieldInfo.hpp | 8 ++ hotspot/src/share/vm/opto/c2_globals.hpp | 3 + hotspot/src/share/vm/opto/compile.cpp | 17 +++- hotspot/src/share/vm/opto/compile.hpp | 12 ++- hotspot/src/share/vm/opto/graphKit.cpp | 18 ++-- hotspot/src/share/vm/opto/graphKit.hpp | 3 + hotspot/src/share/vm/opto/library_call.cpp | 5 ++ hotspot/src/share/vm/opto/memnode.cpp | 90 +++++++++++++++---- hotspot/src/share/vm/opto/parse.hpp | 2 +- hotspot/src/share/vm/opto/parse3.cpp | 71 +++++++-------- hotspot/src/share/vm/opto/type.cpp | 79 ++++++++++++++-- hotspot/src/share/vm/opto/type.hpp | 15 +++- hotspot/src/share/vm/runtime/globals.hpp | 3 + .../src/share/vm/utilities/accessFlags.hpp | 3 + 25 files changed, 419 insertions(+), 84 deletions(-) diff --git a/hotspot/src/share/vm/ci/ciArray.cpp b/hotspot/src/share/vm/ci/ciArray.cpp index 584b1aeb50f..fdcc63a0dec 100644 --- a/hotspot/src/share/vm/ci/ciArray.cpp +++ b/hotspot/src/share/vm/ci/ciArray.cpp @@ -24,13 +24,92 @@ #include "precompiled.hpp" #include "ci/ciArray.hpp" +#include "ci/ciArrayKlass.hpp" +#include "ci/ciConstant.hpp" #include "ci/ciKlass.hpp" #include "ci/ciUtilities.hpp" +#include "oops/objArrayOop.hpp" +#include "oops/typeArrayOop.hpp" // ciArray // // This class represents an arrayOop in the HotSpot virtual // machine. +static BasicType fixup_element_type(BasicType bt) { + if (bt == T_ARRAY) return T_OBJECT; + if (bt == T_BOOLEAN) return T_BYTE; + return bt; +} + +ciConstant ciArray::element_value_impl(BasicType elembt, + arrayOop ary, + int index) { + if (ary == NULL) + return ciConstant(); + assert(ary->is_array(), ""); + if (index < 0 || index >= ary->length()) + return ciConstant(); + ArrayKlass* ak = (ArrayKlass*) ary->klass(); + BasicType abt = ak->element_type(); + if (fixup_element_type(elembt) != + fixup_element_type(abt)) + return ciConstant(); + switch (elembt) { + case T_ARRAY: + case T_OBJECT: + { + assert(ary->is_objArray(), ""); + objArrayOop objary = (objArrayOop) ary; + oop elem = objary->obj_at(index); + ciEnv* env = CURRENT_ENV; + ciObject* box = env->get_object(elem); + return ciConstant(T_OBJECT, box); + } + } + assert(ary->is_typeArray(), ""); + typeArrayOop tary = (typeArrayOop) ary; + jint value = 0; + switch (elembt) { + case T_LONG: return ciConstant(tary->long_at(index)); + case T_FLOAT: return ciConstant(tary->float_at(index)); + case T_DOUBLE: return ciConstant(tary->double_at(index)); + default: return ciConstant(); + case T_BYTE: value = tary->byte_at(index); break; + case T_BOOLEAN: value = tary->byte_at(index) & 1; break; + case T_SHORT: value = tary->short_at(index); break; + case T_CHAR: value = tary->char_at(index); break; + case T_INT: value = tary->int_at(index); break; + } + return ciConstant(elembt, value); +} + +// ------------------------------------------------------------------ +// ciArray::element_value +// +// Current value of an element. +// Returns T_ILLEGAL if there is no element at the given index. +ciConstant ciArray::element_value(int index) { + BasicType elembt = element_basic_type(); + GUARDED_VM_ENTRY( + return element_value_impl(elembt, get_arrayOop(), index); + ) +} + +// ------------------------------------------------------------------ +// ciArray::element_value_by_offset +// +// Current value of an element at the specified offset. +// Returns T_ILLEGAL if there is no element at the given offset. +ciConstant ciArray::element_value_by_offset(intptr_t element_offset) { + BasicType elembt = element_basic_type(); + intptr_t shift = exact_log2(type2aelembytes(elembt)); + intptr_t header = arrayOopDesc::base_offset_in_bytes(elembt); + intptr_t index = (element_offset - header) >> shift; + intptr_t offset = header + ((intptr_t)index << shift); + if (offset != element_offset || index != (jint)index) + return ciConstant(); + return element_value((jint) index); +} // ------------------------------------------------------------------ // ciArray::print_impl diff --git a/hotspot/src/share/vm/ci/ciArray.hpp b/hotspot/src/share/vm/ci/ciArray.hpp index 440e407a510..c5c86265d61 100644 --- a/hotspot/src/share/vm/ci/ciArray.hpp +++ b/hotspot/src/share/vm/ci/ciArray.hpp @@ -25,6 +25,8 @@ #ifndef SHARE_VM_CI_CIARRAY_HPP #define SHARE_VM_CI_CIARRAY_HPP +#include "ci/ciArrayKlass.hpp" +#include "ci/ciConstant.hpp" #include "ci/ciObject.hpp" #include "oops/arrayOop.hpp" #include "oops/objArrayOop.hpp" @@ -45,15 +47,30 @@ protected: ciArray(ciKlass* klass, int len) : ciObject(klass), _length(len) {} - arrayOop get_arrayOop() { return (arrayOop)get_oop(); } + arrayOop get_arrayOop() const { return (arrayOop)get_oop(); } const char* type_string() { return "ciArray"; } void print_impl(outputStream* st); + ciConstant element_value_impl(BasicType elembt, arrayOop ary, int index); + public: int length() { return _length; } + // Convenience routines. + ciArrayKlass* array_type() { return klass()->as_array_klass(); } + ciType* element_type() { return array_type()->element_type(); } + BasicType element_basic_type() { return element_type()->basic_type(); } + + // Current value of an element. + // Returns T_ILLEGAL if there is no element at the given index. + ciConstant element_value(int index); + + // Current value of an element at the specified offset. + // Returns T_ILLEGAL if there is no element at the given offset. + ciConstant element_value_by_offset(intptr_t element_offset); + // What kind of ciObject is this? bool is_array() { return true; } bool is_java_object() { return true; } diff --git a/hotspot/src/share/vm/ci/ciConstant.hpp b/hotspot/src/share/vm/ci/ciConstant.hpp index 8cdc893fd2b..7a72a7de1e5 100644 --- a/hotspot/src/share/vm/ci/ciConstant.hpp +++ b/hotspot/src/share/vm/ci/ciConstant.hpp @@ -41,7 +41,6 @@ private: union { jint _int; jlong _long; - jint _long_half[2]; jfloat _float; jdouble _double; ciObject* _object; @@ -111,6 +110,20 @@ public: return _value._object; } + bool is_null_or_zero() const { + if (!is_java_primitive(basic_type())) { + return as_object()->is_null_object(); + } else if (type2size[basic_type()] == 1) { + // treat float bits as int, to avoid comparison with -0 and NaN + return (_value._int == 0); + } else if (type2size[basic_type()] == 2) { + // treat double bits as long, to avoid comparison with -0 and NaN + return (_value._long == 0); + } else { + return false; + } + } + // Debugging output void print(); }; diff --git a/hotspot/src/share/vm/ci/ciField.cpp b/hotspot/src/share/vm/ci/ciField.cpp index fe967554c3a..1a711ae522a 100644 --- a/hotspot/src/share/vm/ci/ciField.cpp +++ b/hotspot/src/share/vm/ci/ciField.cpp @@ -189,12 +189,14 @@ void ciField::initialize_from(fieldDescriptor* fd) { _holder = CURRENT_ENV->get_instance_klass(fd->field_holder()); // Check to see if the field is constant. - if (_holder->is_initialized() && this->is_final()) { + bool is_final = this->is_final(); + bool is_stable = FoldStableValues && this->is_stable(); + if (_holder->is_initialized() && (is_final || is_stable)) { if (!this->is_static()) { // A field can be constant if it's a final static field or if // it's a final non-static field of a trusted class (classes in // java.lang.invoke and sun.invoke packages and subpackages). - if (trust_final_non_static_fields(_holder)) { + if (is_stable || trust_final_non_static_fields(_holder)) { _is_constant = true; return; } @@ -227,7 +229,6 @@ void ciField::initialize_from(fieldDescriptor* fd) { Handle mirror = k->java_mirror(); - _is_constant = true; switch(type()->basic_type()) { case T_BYTE: _constant_value = ciConstant(type()->basic_type(), mirror->byte_field(_offset)); @@ -273,6 +274,12 @@ void ciField::initialize_from(fieldDescriptor* fd) { } } } + if (is_stable && _constant_value.is_null_or_zero()) { + // It is not a constant after all; treat it as uninitialized. + _is_constant = false; + } else { + _is_constant = true; + } } else { _is_constant = false; } @@ -373,8 +380,11 @@ void ciField::print() { tty->print(" signature="); _signature->print_symbol(); tty->print(" offset=%d type=", _offset); - if (_type != NULL) _type->print_name(); - else tty->print("(reference)"); + if (_type != NULL) + _type->print_name(); + else + tty->print("(reference)"); + tty->print(" flags=%04x", flags().as_int()); tty->print(" is_constant=%s", bool_to_str(_is_constant)); if (_is_constant && is_static()) { tty->print(" constant_value="); diff --git a/hotspot/src/share/vm/ci/ciField.hpp b/hotspot/src/share/vm/ci/ciField.hpp index ff96c99313c..81af9ca79a9 100644 --- a/hotspot/src/share/vm/ci/ciField.hpp +++ b/hotspot/src/share/vm/ci/ciField.hpp @@ -139,7 +139,10 @@ public: // non-constant fields. These are java.lang.System.in // and java.lang.System.out. Abomination. // - // Note: the check for case 4 is not yet implemented. + // A field is also considered constant if it is marked @Stable + // and is non-null (or non-zero, if a primitive). + // For non-static fields, the null/zero check must be + // arranged by the user, as constant_value().is_null_or_zero(). bool is_constant() { return _is_constant; } // Get the constant value of this field. @@ -173,6 +176,7 @@ public: bool is_protected () { return flags().is_protected(); } bool is_static () { return flags().is_static(); } bool is_final () { return flags().is_final(); } + bool is_stable () { return flags().is_stable(); } bool is_volatile () { return flags().is_volatile(); } bool is_transient () { return flags().is_transient(); } diff --git a/hotspot/src/share/vm/ci/ciFlags.hpp b/hotspot/src/share/vm/ci/ciFlags.hpp index 6dc50d25a60..87e19466f27 100644 --- a/hotspot/src/share/vm/ci/ciFlags.hpp +++ b/hotspot/src/share/vm/ci/ciFlags.hpp @@ -59,6 +59,7 @@ public: bool is_interface () const { return (_flags & JVM_ACC_INTERFACE ) != 0; } bool is_abstract () const { return (_flags & JVM_ACC_ABSTRACT ) != 0; } bool is_strict () const { return (_flags & JVM_ACC_STRICT ) != 0; } + bool is_stable () const { return (_flags & JVM_ACC_FIELD_STABLE) != 0; } // Conversion jint as_int() { return _flags; } diff --git a/hotspot/src/share/vm/ci/ciInstance.cpp b/hotspot/src/share/vm/ci/ciInstance.cpp index a74eb04f4a7..8b48b1b3706 100644 --- a/hotspot/src/share/vm/ci/ciInstance.cpp +++ b/hotspot/src/share/vm/ci/ciInstance.cpp @@ -127,6 +127,8 @@ ciConstant ciInstance::field_value(ciField* field) { ciConstant ciInstance::field_value_by_offset(int field_offset) { ciInstanceKlass* ik = klass()->as_instance_klass(); ciField* field = ik->get_field_by_offset(field_offset, false); + if (field == NULL) + return ciConstant(); // T_ILLEGAL return field_value(field); } diff --git a/hotspot/src/share/vm/ci/ciTypeArray.cpp b/hotspot/src/share/vm/ci/ciTypeArray.cpp index d4a6eff6f41..2d013e21c0e 100644 --- a/hotspot/src/share/vm/ci/ciTypeArray.cpp +++ b/hotspot/src/share/vm/ci/ciTypeArray.cpp @@ -39,5 +39,10 @@ jchar ciTypeArray::char_at(int index) { VM_ENTRY_MARK; assert(index >= 0 && index < length(), "out of range"); - return get_typeArrayOop()->char_at(index); + jchar c = get_typeArrayOop()->char_at(index); +#ifdef ASSERT + jchar d = element_value(index).as_char(); + assert(c == d, ""); +#endif //ASSERT + return c; } diff --git a/hotspot/src/share/vm/classfile/classFileParser.cpp b/hotspot/src/share/vm/classfile/classFileParser.cpp index 0705c5f14d6..8972bceb434 100644 --- a/hotspot/src/share/vm/classfile/classFileParser.cpp +++ b/hotspot/src/share/vm/classfile/classFileParser.cpp @@ -1774,6 +1774,10 @@ ClassFileParser::AnnotationCollector::annotation_index(ClassLoaderData* loader_d if (_location != _in_method) break; // only allow for methods if (!privileged) break; // only allow in privileged code return _method_LambdaForm_Hidden; + case vmSymbols::VM_SYMBOL_ENUM_NAME(sun_invoke_Stable_signature): + if (_location != _in_field) break; // only allow for fields + if (!privileged) break; // only allow in privileged code + return _field_Stable; case vmSymbols::VM_SYMBOL_ENUM_NAME(sun_misc_Contended_signature): if (_location != _in_field && _location != _in_class) break; // only allow for fields and classes if (!EnableContended || (RestrictContended && !privileged)) break; // honor privileges @@ -1786,6 +1790,8 @@ ClassFileParser::AnnotationCollector::annotation_index(ClassLoaderData* loader_d void ClassFileParser::FieldAnnotationCollector::apply_to(FieldInfo* f) { if (is_contended()) f->set_contended_group(contended_group()); + if (is_stable()) + f->set_stable(true); } ClassFileParser::FieldAnnotationCollector::~FieldAnnotationCollector() { diff --git a/hotspot/src/share/vm/classfile/classFileParser.hpp b/hotspot/src/share/vm/classfile/classFileParser.hpp index 1b5ed30c5a6..02a4ce20dd3 100644 --- a/hotspot/src/share/vm/classfile/classFileParser.hpp +++ b/hotspot/src/share/vm/classfile/classFileParser.hpp @@ -125,6 +125,7 @@ class ClassFileParser VALUE_OBJ_CLASS_SPEC { _method_LambdaForm_Compiled, _method_LambdaForm_Hidden, _sun_misc_Contended, + _field_Stable, _annotation_LIMIT }; const Location _location; @@ -143,14 +144,23 @@ class ClassFileParser VALUE_OBJ_CLASS_SPEC { assert((int)id >= 0 && (int)id < (int)_annotation_LIMIT, "oob"); _annotations_present |= nth_bit((int)id); } + + void remove_annotation(ID id) { + assert((int)id >= 0 && (int)id < (int)_annotation_LIMIT, "oob"); + _annotations_present &= ~nth_bit((int)id); + } + // Report if the annotation is present. - bool has_any_annotations() { return _annotations_present != 0; } - bool has_annotation(ID id) { return (nth_bit((int)id) & _annotations_present) != 0; } + bool has_any_annotations() const { return _annotations_present != 0; } + bool has_annotation(ID id) const { return (nth_bit((int)id) & _annotations_present) != 0; } void set_contended_group(u2 group) { _contended_group = group; } - u2 contended_group() { return _contended_group; } + u2 contended_group() const { return _contended_group; } - bool is_contended() { return has_annotation(_sun_misc_Contended); } + bool is_contended() const { return has_annotation(_sun_misc_Contended); } + + void set_stable(bool stable) { set_annotation(_field_Stable); } + bool is_stable() const { return has_annotation(_field_Stable); } }; // This class also doubles as a holder for metadata cleanup. diff --git a/hotspot/src/share/vm/classfile/vmSymbols.hpp b/hotspot/src/share/vm/classfile/vmSymbols.hpp index 067cf503305..f1758f86654 100644 --- a/hotspot/src/share/vm/classfile/vmSymbols.hpp +++ b/hotspot/src/share/vm/classfile/vmSymbols.hpp @@ -270,6 +270,7 @@ template(java_lang_invoke_LambdaForm, "java/lang/invoke/LambdaForm") \ template(java_lang_invoke_ForceInline_signature, "Ljava/lang/invoke/ForceInline;") \ template(java_lang_invoke_DontInline_signature, "Ljava/lang/invoke/DontInline;") \ + template(sun_invoke_Stable_signature, "Lsun/invoke/Stable;") \ template(java_lang_invoke_LambdaForm_Compiled_signature, "Ljava/lang/invoke/LambdaForm$Compiled;") \ template(java_lang_invoke_LambdaForm_Hidden_signature, "Ljava/lang/invoke/LambdaForm$Hidden;") \ template(java_lang_invoke_MagicLambdaImpl, "java/lang/invoke/MagicLambdaImpl") \ diff --git a/hotspot/src/share/vm/oops/fieldInfo.hpp b/hotspot/src/share/vm/oops/fieldInfo.hpp index 5da8ed9628a..6763c42d127 100644 --- a/hotspot/src/share/vm/oops/fieldInfo.hpp +++ b/hotspot/src/share/vm/oops/fieldInfo.hpp @@ -240,6 +240,14 @@ class FieldInfo VALUE_OBJ_CLASS_SPEC { return (access_flags() & JVM_ACC_FIELD_INTERNAL) != 0; } + bool is_stable() const { + return (access_flags() & JVM_ACC_FIELD_STABLE) != 0; + } + void set_stable(bool z) { + if (z) _shorts[access_flags_offset] |= JVM_ACC_FIELD_STABLE; + else _shorts[access_flags_offset] &= ~JVM_ACC_FIELD_STABLE; + } + Symbol* lookup_symbol(int symbol_index) const { assert(is_internal(), "only internal fields"); return vmSymbols::symbol_at((vmSymbols::SID)symbol_index); diff --git a/hotspot/src/share/vm/opto/c2_globals.hpp b/hotspot/src/share/vm/opto/c2_globals.hpp index 15d8befbbac..1ff73e7c425 100644 --- a/hotspot/src/share/vm/opto/c2_globals.hpp +++ b/hotspot/src/share/vm/opto/c2_globals.hpp @@ -448,6 +448,9 @@ product(bool, EliminateAutoBox, true, \ "Control optimizations for autobox elimination") \ \ + experimental(bool, UseImplicitStableValues, false, \ + "Mark well-known stable fields as such (e.g. String.value)") \ + \ product(intx, AutoBoxCacheMax, 128, \ "Sets max value cached by the java.lang.Integer autobox cache") \ \ diff --git a/hotspot/src/share/vm/opto/compile.cpp b/hotspot/src/share/vm/opto/compile.cpp index b426bcce1a2..8d7e6c9e102 100644 --- a/hotspot/src/share/vm/opto/compile.cpp +++ b/hotspot/src/share/vm/opto/compile.cpp @@ -1297,6 +1297,10 @@ const TypePtr *Compile::flatten_alias_type( const TypePtr *tj ) const { // Array pointers need some flattening const TypeAryPtr *ta = tj->isa_aryptr(); + if (ta && ta->is_stable()) { + // Erase stability property for alias analysis. + tj = ta = ta->cast_to_stable(false); + } if( ta && is_known_inst ) { if ( offset != Type::OffsetBot && offset > arrayOopDesc::length_offset_in_bytes() ) { @@ -1497,6 +1501,7 @@ void Compile::AliasType::Init(int i, const TypePtr* at) { _index = i; _adr_type = at; _field = NULL; + _element = NULL; _is_rewritable = true; // default const TypeOopPtr *atoop = (at != NULL) ? at->isa_oopptr() : NULL; if (atoop != NULL && atoop->is_known_instance()) { @@ -1615,6 +1620,16 @@ Compile::AliasType* Compile::find_alias_type(const TypePtr* adr_type, bool no_cr && flat->is_instptr()->klass() == env()->Class_klass()) alias_type(idx)->set_rewritable(false); } + if (flat->isa_aryptr()) { +#ifdef ASSERT + const int header_size_min = arrayOopDesc::base_offset_in_bytes(T_BYTE); + // (T_BYTE has the weakest alignment and size restrictions...) + assert(flat->offset() < header_size_min, "array body reference must be OffsetBot"); +#endif + if (flat->offset() == TypePtr::OffsetBot) { + alias_type(idx)->set_element(flat->is_aryptr()->elem()); + } + } if (flat->isa_klassptr()) { if (flat->offset() == in_bytes(Klass::super_check_offset_offset())) alias_type(idx)->set_rewritable(false); @@ -1677,7 +1692,7 @@ Compile::AliasType* Compile::alias_type(ciField* field) { else t = TypeOopPtr::make_from_klass_raw(field->holder()); AliasType* atp = alias_type(t->add_offset(field->offset_in_bytes()), field); - assert(field->is_final() == !atp->is_rewritable(), "must get the rewritable bits correct"); + assert((field->is_final() || field->is_stable()) == !atp->is_rewritable(), "must get the rewritable bits correct"); return atp; } diff --git a/hotspot/src/share/vm/opto/compile.hpp b/hotspot/src/share/vm/opto/compile.hpp index 60787464bd0..8d862c24125 100644 --- a/hotspot/src/share/vm/opto/compile.hpp +++ b/hotspot/src/share/vm/opto/compile.hpp @@ -72,6 +72,7 @@ class Scope; class StartNode; class SafePointNode; class JVMState; +class Type; class TypeData; class TypePtr; class TypeOopPtr; @@ -119,6 +120,7 @@ class Compile : public Phase { int _index; // unique index, used with MergeMemNode const TypePtr* _adr_type; // normalized address type ciField* _field; // relevant instance field, or null if none + const Type* _element; // relevant array element type, or null if none bool _is_rewritable; // false if the memory is write-once only int _general_index; // if this is type is an instance, the general // type that this is an instance of @@ -129,6 +131,7 @@ class Compile : public Phase { int index() const { return _index; } const TypePtr* adr_type() const { return _adr_type; } ciField* field() const { return _field; } + const Type* element() const { return _element; } bool is_rewritable() const { return _is_rewritable; } bool is_volatile() const { return (_field ? _field->is_volatile() : false); } int general_index() const { return (_general_index != 0) ? _general_index : _index; } @@ -137,7 +140,14 @@ class Compile : public Phase { void set_field(ciField* f) { assert(!_field,""); _field = f; - if (f->is_final()) _is_rewritable = false; + if (f->is_final() || f->is_stable()) { + // In the case of @Stable, multiple writes are possible but may be assumed to be no-ops. + _is_rewritable = false; + } + } + void set_element(const Type* e) { + assert(_element == NULL, ""); + _element = e; } void print_on(outputStream* st) PRODUCT_RETURN; diff --git a/hotspot/src/share/vm/opto/graphKit.cpp b/hotspot/src/share/vm/opto/graphKit.cpp index 18772dfd0a8..dcdd104ee72 100644 --- a/hotspot/src/share/vm/opto/graphKit.cpp +++ b/hotspot/src/share/vm/opto/graphKit.cpp @@ -3825,8 +3825,13 @@ Node* GraphKit::load_String_value(Node* ctrl, Node* str) { TypeAry::make(TypeInt::CHAR,TypeInt::POS), ciTypeArrayKlass::make(T_CHAR), true, 0); int value_field_idx = C->get_alias_index(value_field_type); - return make_load(ctrl, basic_plus_adr(str, str, value_offset), - value_type, T_OBJECT, value_field_idx); + Node* load = make_load(ctrl, basic_plus_adr(str, str, value_offset), + value_type, T_OBJECT, value_field_idx); + // String.value field is known to be @Stable. + if (UseImplicitStableValues) { + load = cast_array_to_stable(load, value_type); + } + return load; } void GraphKit::store_String_offset(Node* ctrl, Node* str, Node* value) { @@ -3844,9 +3849,6 @@ void GraphKit::store_String_value(Node* ctrl, Node* str, Node* value) { const TypeInstPtr* string_type = TypeInstPtr::make(TypePtr::NotNull, C->env()->String_klass(), false, NULL, 0); const TypePtr* value_field_type = string_type->add_offset(value_offset); - const TypeAryPtr* value_type = TypeAryPtr::make(TypePtr::NotNull, - TypeAry::make(TypeInt::CHAR,TypeInt::POS), - ciTypeArrayKlass::make(T_CHAR), true, 0); int value_field_idx = C->get_alias_index(value_field_type); store_to_memory(ctrl, basic_plus_adr(str, value_offset), value, T_OBJECT, value_field_idx); @@ -3861,3 +3863,9 @@ void GraphKit::store_String_length(Node* ctrl, Node* str, Node* value) { store_to_memory(ctrl, basic_plus_adr(str, count_offset), value, T_INT, count_field_idx); } + +Node* GraphKit::cast_array_to_stable(Node* ary, const TypeAryPtr* ary_type) { + // Reify the property as a CastPP node in Ideal graph to comply with monotonicity + // assumption of CCP analysis. + return _gvn.transform(new(C) CastPPNode(ary, ary_type->cast_to_stable(true))); +} diff --git a/hotspot/src/share/vm/opto/graphKit.hpp b/hotspot/src/share/vm/opto/graphKit.hpp index e9d102cb6c5..1fd4e86d2e7 100644 --- a/hotspot/src/share/vm/opto/graphKit.hpp +++ b/hotspot/src/share/vm/opto/graphKit.hpp @@ -836,6 +836,9 @@ class GraphKit : public Phase { // Insert a loop predicate into the graph void add_predicate(int nargs = 0); void add_predicate_impl(Deoptimization::DeoptReason reason, int nargs); + + // Produce new array node of stable type + Node* cast_array_to_stable(Node* ary, const TypeAryPtr* ary_type); }; // Helper class to support building of control flow branches. Upon diff --git a/hotspot/src/share/vm/opto/library_call.cpp b/hotspot/src/share/vm/opto/library_call.cpp index 60525d73ef7..f7e09c3f89f 100644 --- a/hotspot/src/share/vm/opto/library_call.cpp +++ b/hotspot/src/share/vm/opto/library_call.cpp @@ -1280,6 +1280,11 @@ Node* LibraryCallKit::string_indexOf(Node* string_object, ciTypeArray* target_ar const TypeAry* target_array_type = TypeAry::make(TypeInt::CHAR, TypeInt::make(0, target_length, Type::WidenMin)); const TypeAryPtr* target_type = TypeAryPtr::make(TypePtr::BotPTR, target_array_type, target_array->klass(), true, Type::OffsetBot); + // String.value field is known to be @Stable. + if (UseImplicitStableValues) { + target = cast_array_to_stable(target, target_type); + } + IdealKit kit(this, false, true); #define __ kit. Node* zero = __ ConI(0); diff --git a/hotspot/src/share/vm/opto/memnode.cpp b/hotspot/src/share/vm/opto/memnode.cpp index aa03b5ff6c5..a91c63abc9b 100644 --- a/hotspot/src/share/vm/opto/memnode.cpp +++ b/hotspot/src/share/vm/opto/memnode.cpp @@ -962,6 +962,19 @@ uint LoadNode::hash() const { return (uintptr_t)in(Control) + (uintptr_t)in(Memory) + (uintptr_t)in(Address); } +static bool skip_through_membars(Compile::AliasType* atp, const TypeInstPtr* tp, bool eliminate_boxing) { + if ((atp != NULL) && (atp->index() >= Compile::AliasIdxRaw)) { + bool non_volatile = (atp->field() != NULL) && !atp->field()->is_volatile(); + bool is_stable_ary = FoldStableValues && + (tp != NULL) && (tp->isa_aryptr() != NULL) && + tp->isa_aryptr()->is_stable(); + + return (eliminate_boxing && non_volatile) || is_stable_ary; + } + + return false; +} + //---------------------------can_see_stored_value------------------------------ // This routine exists to make sure this set of tests is done the same // everywhere. We need to make a coordinated change: first LoadNode::Ideal @@ -976,11 +989,9 @@ Node* MemNode::can_see_stored_value(Node* st, PhaseTransform* phase) const { const TypeInstPtr* tp = phase->type(ld_adr)->isa_instptr(); Compile::AliasType* atp = (tp != NULL) ? phase->C->alias_type(tp) : NULL; // This is more general than load from boxing objects. - if (phase->C->eliminate_boxing() && (atp != NULL) && - (atp->index() >= Compile::AliasIdxRaw) && - (atp->field() != NULL) && !atp->field()->is_volatile()) { + if (skip_through_membars(atp, tp, phase->C->eliminate_boxing())) { uint alias_idx = atp->index(); - bool final = atp->field()->is_final(); + bool final = !atp->is_rewritable(); Node* result = NULL; Node* current = st; // Skip through chains of MemBarNodes checking the MergeMems for @@ -1015,7 +1026,6 @@ Node* MemNode::can_see_stored_value(Node* st, PhaseTransform* phase) const { } } - // Loop around twice in the case Load -> Initialize -> Store. // (See PhaseIterGVN::add_users_to_worklist, which knows about this case.) for (int trip = 0; trip <= 1; trip++) { @@ -1577,6 +1587,40 @@ LoadNode::load_array_final_field(const TypeKlassPtr *tkls, return NULL; } +// Try to constant-fold a stable array element. +static const Type* fold_stable_ary_elem(const TypeAryPtr* ary, int off, BasicType loadbt) { + assert(ary->is_stable(), "array should be stable"); + + if (ary->const_oop() != NULL) { + // Decode the results of GraphKit::array_element_address. + ciArray* aobj = ary->const_oop()->as_array(); + ciConstant con = aobj->element_value_by_offset(off); + + if (con.basic_type() != T_ILLEGAL && !con.is_null_or_zero()) { + const Type* con_type = Type::make_from_constant(con); + if (con_type != NULL) { + if (con_type->isa_aryptr()) { + // Join with the array element type, in case it is also stable. + int dim = ary->stable_dimension(); + con_type = con_type->is_aryptr()->cast_to_stable(true, dim-1); + } + if (loadbt == T_NARROWOOP && con_type->isa_oopptr()) { + con_type = con_type->make_narrowoop(); + } +#ifndef PRODUCT + if (TraceIterativeGVN) { + tty->print("FoldStableValues: array element [off=%d]: con_type=", off); + con_type->dump(); tty->cr(); + } +#endif //PRODUCT + return con_type; + } + } + } + + return NULL; +} + //------------------------------Value----------------------------------------- const Type *LoadNode::Value( PhaseTransform *phase ) const { // Either input is TOP ==> the result is TOP @@ -1591,8 +1635,31 @@ const Type *LoadNode::Value( PhaseTransform *phase ) const { Compile* C = phase->C; // Try to guess loaded type from pointer type - if (tp->base() == Type::AryPtr) { - const Type *t = tp->is_aryptr()->elem(); + if (tp->isa_aryptr()) { + const TypeAryPtr* ary = tp->is_aryptr(); + const Type *t = ary->elem(); + + // Determine whether the reference is beyond the header or not, by comparing + // the offset against the offset of the start of the array's data. + // Different array types begin at slightly different offsets (12 vs. 16). + // We choose T_BYTE as an example base type that is least restrictive + // as to alignment, which will therefore produce the smallest + // possible base offset. + const int min_base_off = arrayOopDesc::base_offset_in_bytes(T_BYTE); + const bool off_beyond_header = ((uint)off >= (uint)min_base_off); + + // Try to constant-fold a stable array element. + if (FoldStableValues && ary->is_stable()) { + // Make sure the reference is not into the header + if (off_beyond_header && off != Type::OffsetBot) { + assert(adr->is_AddP() && adr->in(AddPNode::Offset)->is_Con(), "offset is a constant"); + const Type* con_type = fold_stable_ary_elem(ary, off, memory_type()); + if (con_type != NULL) { + return con_type; + } + } + } + // Don't do this for integer types. There is only potential profit if // the element type t is lower than _type; that is, for int types, if _type is // more restrictive than t. This only happens here if one is short and the other @@ -1613,14 +1680,7 @@ const Type *LoadNode::Value( PhaseTransform *phase ) const { && Opcode() != Op_LoadKlass && Opcode() != Op_LoadNKlass) { // t might actually be lower than _type, if _type is a unique // concrete subclass of abstract class t. - // Make sure the reference is not into the header, by comparing - // the offset against the offset of the start of the array's data. - // Different array types begin at slightly different offsets (12 vs. 16). - // We choose T_BYTE as an example base type that is least restrictive - // as to alignment, which will therefore produce the smallest - // possible base offset. - const int min_base_off = arrayOopDesc::base_offset_in_bytes(T_BYTE); - if ((uint)off >= (uint)min_base_off) { // is the offset beyond the header? + if (off_beyond_header) { // is the offset beyond the header? const Type* jt = t->join(_type); // In any case, do not allow the join, per se, to empty out the type. if (jt->empty() && !t->empty()) { diff --git a/hotspot/src/share/vm/opto/parse.hpp b/hotspot/src/share/vm/opto/parse.hpp index 91025bf56fb..ea01b08475e 100644 --- a/hotspot/src/share/vm/opto/parse.hpp +++ b/hotspot/src/share/vm/opto/parse.hpp @@ -518,7 +518,7 @@ class Parse : public GraphKit { // loading from a constant field or the constant pool // returns false if push failed (non-perm field constants only, not ldcs) - bool push_constant(ciConstant con, bool require_constant = false, bool is_autobox_cache = false); + bool push_constant(ciConstant con, bool require_constant = false, bool is_autobox_cache = false, const Type* basic_type = NULL); // implementation of object creation bytecodes void emit_guard_for_new(ciInstanceKlass* klass); diff --git a/hotspot/src/share/vm/opto/parse3.cpp b/hotspot/src/share/vm/opto/parse3.cpp index 28eb0580bad..8c545f3ece5 100644 --- a/hotspot/src/share/vm/opto/parse3.cpp +++ b/hotspot/src/share/vm/opto/parse3.cpp @@ -147,7 +147,15 @@ void Parse::do_field_access(bool is_get, bool is_field) { void Parse::do_get_xxx(Node* obj, ciField* field, bool is_field) { // Does this field have a constant value? If so, just push the value. if (field->is_constant()) { - // final field + // final or stable field + const Type* stable_type = NULL; + if (FoldStableValues && field->is_stable()) { + stable_type = Type::get_const_type(field->type()); + if (field->type()->is_array_klass()) { + int stable_dimension = field->type()->as_array_klass()->dimension(); + stable_type = stable_type->is_aryptr()->cast_to_stable(true, stable_dimension); + } + } if (field->is_static()) { // final static field if (C->eliminate_boxing()) { @@ -167,11 +175,10 @@ void Parse::do_get_xxx(Node* obj, ciField* field, bool is_field) { } } } - if (push_constant(field->constant_value())) + if (push_constant(field->constant_value(), false, false, stable_type)) return; - } - else { - // final non-static field + } else { + // final or stable non-static field // Treat final non-static fields of trusted classes (classes in // java.lang.invoke and sun.invoke packages and subpackages) as // compile time constants. @@ -179,8 +186,12 @@ void Parse::do_get_xxx(Node* obj, ciField* field, bool is_field) { const TypeOopPtr* oop_ptr = obj->bottom_type()->isa_oopptr(); ciObject* constant_oop = oop_ptr->const_oop(); ciConstant constant = field->constant_value_of(constant_oop); - if (push_constant(constant, true)) - return; + if (FoldStableValues && field->is_stable() && constant.is_null_or_zero()) { + // fall through to field load; the field is not yet initialized + } else { + if (push_constant(constant, true, false, stable_type)) + return; + } } } } @@ -301,7 +312,8 @@ void Parse::do_put_xxx(Node* obj, ciField* field, bool is_field) { // Note the presence of writes to final non-static fields, so that we // can insert a memory barrier later on to keep the writes from floating // out of the constructor. - if (is_field && field->is_final()) { + // Any method can write a @Stable field; insert memory barriers after those also. + if (is_field && (field->is_final() || field->is_stable())) { set_wrote_final(true); // Preserve allocation ptr to create precedent edge to it in membar // generated on exit from constructor. @@ -314,35 +326,21 @@ void Parse::do_put_xxx(Node* obj, ciField* field, bool is_field) { } -bool Parse::push_constant(ciConstant constant, bool require_constant, bool is_autobox_cache) { + +bool Parse::push_constant(ciConstant constant, bool require_constant, bool is_autobox_cache, const Type* stable_type) { + const Type* con_type = Type::make_from_constant(constant, require_constant, is_autobox_cache); switch (constant.basic_type()) { - case T_BOOLEAN: push( intcon(constant.as_boolean()) ); break; - case T_INT: push( intcon(constant.as_int()) ); break; - case T_CHAR: push( intcon(constant.as_char()) ); break; - case T_BYTE: push( intcon(constant.as_byte()) ); break; - case T_SHORT: push( intcon(constant.as_short()) ); break; - case T_FLOAT: push( makecon(TypeF::make(constant.as_float())) ); break; - case T_DOUBLE: push_pair( makecon(TypeD::make(constant.as_double())) ); break; - case T_LONG: push_pair( longcon(constant.as_long()) ); break; case T_ARRAY: - case T_OBJECT: { + case T_OBJECT: // cases: // can_be_constant = (oop not scavengable || ScavengeRootsInCode != 0) // should_be_constant = (oop not scavengable || ScavengeRootsInCode >= 2) // An oop is not scavengable if it is in the perm gen. - ciObject* oop_constant = constant.as_object(); - if (oop_constant->is_null_object()) { - push( zerocon(T_OBJECT) ); - break; - } else if (require_constant || oop_constant->should_be_constant()) { - push( makecon(TypeOopPtr::make_from_constant(oop_constant, require_constant, is_autobox_cache)) ); - break; - } else { - // we cannot inline the oop, but we can use it later to narrow a type - return false; - } - } - case T_ILLEGAL: { + if (stable_type != NULL && con_type != NULL && con_type->isa_oopptr()) + con_type = con_type->join(stable_type); + break; + + case T_ILLEGAL: // Invalid ciConstant returned due to OutOfMemoryError in the CI assert(C->env()->failing(), "otherwise should not see this"); // These always occur because of object types; we are going to @@ -350,17 +348,16 @@ bool Parse::push_constant(ciConstant constant, bool require_constant, bool is_au push( zerocon(T_OBJECT) ); return false; } - default: - ShouldNotReachHere(); - return false; - } - // success + if (con_type == NULL) + // we cannot inline the oop, but we can use it later to narrow a type + return false; + + push_node(constant.basic_type(), makecon(con_type)); return true; } - //============================================================================= void Parse::do_anewarray() { bool will_link; diff --git a/hotspot/src/share/vm/opto/type.cpp b/hotspot/src/share/vm/opto/type.cpp index fabcf1cad16..23e84a05d77 100644 --- a/hotspot/src/share/vm/opto/type.cpp +++ b/hotspot/src/share/vm/opto/type.cpp @@ -189,6 +189,38 @@ const Type* Type::get_typeflow_type(ciType* type) { } +//-----------------------make_from_constant------------------------------------ +const Type* Type::make_from_constant(ciConstant constant, + bool require_constant, bool is_autobox_cache) { + switch (constant.basic_type()) { + case T_BOOLEAN: return TypeInt::make(constant.as_boolean()); + case T_CHAR: return TypeInt::make(constant.as_char()); + case T_BYTE: return TypeInt::make(constant.as_byte()); + case T_SHORT: return TypeInt::make(constant.as_short()); + case T_INT: return TypeInt::make(constant.as_int()); + case T_LONG: return TypeLong::make(constant.as_long()); + case T_FLOAT: return TypeF::make(constant.as_float()); + case T_DOUBLE: return TypeD::make(constant.as_double()); + case T_ARRAY: + case T_OBJECT: + { + // cases: + // can_be_constant = (oop not scavengable || ScavengeRootsInCode != 0) + // should_be_constant = (oop not scavengable || ScavengeRootsInCode >= 2) + // An oop is not scavengable if it is in the perm gen. + ciObject* oop_constant = constant.as_object(); + if (oop_constant->is_null_object()) { + return Type::get_zero_type(T_OBJECT); + } else if (require_constant || oop_constant->should_be_constant()) { + return TypeOopPtr::make_from_constant(oop_constant, require_constant, is_autobox_cache); + } + } + } + // Fall through to failure + return NULL; +} + + //------------------------------make------------------------------------------- // Create a simple Type, with default empty symbol sets. Then hashcons it // and look for an existing copy in the type dictionary. @@ -1824,12 +1856,12 @@ inline const TypeInt* normalize_array_size(const TypeInt* size) { } //------------------------------make------------------------------------------- -const TypeAry *TypeAry::make( const Type *elem, const TypeInt *size) { +const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable) { if (UseCompressedOops && elem->isa_oopptr()) { elem = elem->make_narrowoop(); } size = normalize_array_size(size); - return (TypeAry*)(new TypeAry(elem,size))->hashcons(); + return (TypeAry*)(new TypeAry(elem,size,stable))->hashcons(); } //------------------------------meet------------------------------------------- @@ -1850,7 +1882,8 @@ const Type *TypeAry::xmeet( const Type *t ) const { case Array: { // Meeting 2 arrays? const TypeAry *a = t->is_ary(); return TypeAry::make(_elem->meet(a->_elem), - _size->xmeet(a->_size)->is_int()); + _size->xmeet(a->_size)->is_int(), + _stable & a->_stable); } case Top: break; @@ -1863,7 +1896,7 @@ const Type *TypeAry::xmeet( const Type *t ) const { const Type *TypeAry::xdual() const { const TypeInt* size_dual = _size->dual()->is_int(); size_dual = normalize_array_size(size_dual); - return new TypeAry( _elem->dual(), size_dual); + return new TypeAry(_elem->dual(), size_dual, !_stable); } //------------------------------eq--------------------------------------------- @@ -1871,13 +1904,14 @@ const Type *TypeAry::xdual() const { bool TypeAry::eq( const Type *t ) const { const TypeAry *a = (const TypeAry*)t; return _elem == a->_elem && + _stable == a->_stable && _size == a->_size; } //------------------------------hash------------------------------------------- // Type-specific hashing function. int TypeAry::hash(void) const { - return (intptr_t)_elem + (intptr_t)_size; + return (intptr_t)_elem + (intptr_t)_size + (_stable ? 43 : 0); } //----------------------interface_vs_oop--------------------------------------- @@ -1894,6 +1928,7 @@ bool TypeAry::interface_vs_oop(const Type *t) const { //------------------------------dump2------------------------------------------ #ifndef PRODUCT void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const { + if (_stable) st->print("stable:"); _elem->dump2(d, depth, st); st->print("["); _size->dump2(d, depth, st); @@ -3457,11 +3492,39 @@ const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const { assert(new_size != NULL, ""); new_size = narrow_size_type(new_size); if (new_size == size()) return this; - const TypeAry* new_ary = TypeAry::make(elem(), new_size); + const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable()); return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id); } +//------------------------------cast_to_stable--------------------------------- +const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const { + if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable())) + return this; + + const Type* elem = this->elem(); + const TypePtr* elem_ptr = elem->make_ptr(); + + if (stable_dimension > 1 && elem_ptr != NULL && elem_ptr->isa_aryptr()) { + // If this is widened from a narrow oop, TypeAry::make will re-narrow it. + elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1); + } + + const TypeAry* new_ary = TypeAry::make(elem, size(), stable); + + return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id); +} + +//-----------------------------stable_dimension-------------------------------- +int TypeAryPtr::stable_dimension() const { + if (!is_stable()) return 0; + int dim = 1; + const TypePtr* elem_ptr = elem()->make_ptr(); + if (elem_ptr != NULL && elem_ptr->isa_aryptr()) + dim += elem_ptr->is_aryptr()->stable_dimension(); + return dim; +} + //------------------------------eq--------------------------------------------- // Structural equality check for Type representations bool TypeAryPtr::eq( const Type *t ) const { @@ -3570,7 +3633,7 @@ const Type *TypeAryPtr::xmeet( const Type *t ) const { // Something like byte[int+] meets char[int+]. // This must fall to bottom, not (int[-128..65535])[int+]. instance_id = InstanceBot; - tary = TypeAry::make(Type::BOTTOM, tary->_size); + tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable); } } else // Non integral arrays. // Must fall to bottom if exact klasses in upper lattice @@ -3584,7 +3647,7 @@ const Type *TypeAryPtr::xmeet( const Type *t ) const { (tap ->_klass_is_exact && !tap->klass()->is_subtype_of(klass())) || // 'this' is exact and super or unrelated: (this->_klass_is_exact && !klass()->is_subtype_of(tap->klass())))) { - tary = TypeAry::make(Type::BOTTOM, tary->_size); + tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable); return make( NotNull, NULL, tary, lazy_klass, false, off, InstanceBot ); } diff --git a/hotspot/src/share/vm/opto/type.hpp b/hotspot/src/share/vm/opto/type.hpp index 55d98bd5e51..d4832591843 100644 --- a/hotspot/src/share/vm/opto/type.hpp +++ b/hotspot/src/share/vm/opto/type.hpp @@ -372,6 +372,10 @@ public: // Mapping from CI type system to compiler type: static const Type* get_typeflow_type(ciType* type); + static const Type* make_from_constant(ciConstant constant, + bool require_constant = false, + bool is_autobox_cache = false); + private: // support arrays static const BasicType _basic_type[]; @@ -588,8 +592,8 @@ public: //------------------------------TypeAry---------------------------------------- // Class of Array Types class TypeAry : public Type { - TypeAry( const Type *elem, const TypeInt *size) : Type(Array), - _elem(elem), _size(size) {} + TypeAry(const Type* elem, const TypeInt* size, bool stable) : Type(Array), + _elem(elem), _size(size), _stable(stable) {} public: virtual bool eq( const Type *t ) const; virtual int hash() const; // Type specific hashing @@ -599,10 +603,11 @@ public: private: const Type *_elem; // Element type of array const TypeInt *_size; // Elements in array + const bool _stable; // Are elements @Stable? friend class TypeAryPtr; public: - static const TypeAry *make( const Type *elem, const TypeInt *size); + static const TypeAry* make(const Type* elem, const TypeInt* size, bool stable = false); virtual const Type *xmeet( const Type *t ) const; virtual const Type *xdual() const; // Compute dual right now. @@ -988,6 +993,7 @@ public: const TypeAry* ary() const { return _ary; } const Type* elem() const { return _ary->_elem; } const TypeInt* size() const { return _ary->_size; } + bool is_stable() const { return _ary->_stable; } bool is_autobox_cache() const { return _is_autobox_cache; } @@ -1011,6 +1017,9 @@ public: virtual const Type *xmeet( const Type *t ) const; virtual const Type *xdual() const; // Compute dual right now. + const TypeAryPtr* cast_to_stable(bool stable, int stable_dimension = 1) const; + int stable_dimension() const; + // Convenience common pre-built types. static const TypeAryPtr *RANGE; static const TypeAryPtr *OOPS; diff --git a/hotspot/src/share/vm/runtime/globals.hpp b/hotspot/src/share/vm/runtime/globals.hpp index c9bcbe1f4d3..7fdf668bac5 100644 --- a/hotspot/src/share/vm/runtime/globals.hpp +++ b/hotspot/src/share/vm/runtime/globals.hpp @@ -3649,6 +3649,9 @@ class CommandLineFlags { experimental(bool, TrustFinalNonStaticFields, false, \ "trust final non-static declarations for constant folding") \ \ + experimental(bool, FoldStableValues, false, \ + "Private flag to control optimizations for stable variables") \ + \ develop(bool, TraceInvokeDynamic, false, \ "trace internal invoke dynamic operations") \ \ diff --git a/hotspot/src/share/vm/utilities/accessFlags.hpp b/hotspot/src/share/vm/utilities/accessFlags.hpp index 99f9a3360f8..a3d3de99c91 100644 --- a/hotspot/src/share/vm/utilities/accessFlags.hpp +++ b/hotspot/src/share/vm/utilities/accessFlags.hpp @@ -78,11 +78,13 @@ enum { JVM_ACC_FIELD_ACCESS_WATCHED = 0x00002000, // field access is watched by JVMTI JVM_ACC_FIELD_MODIFICATION_WATCHED = 0x00008000, // field modification is watched by JVMTI JVM_ACC_FIELD_INTERNAL = 0x00000400, // internal field, same as JVM_ACC_ABSTRACT + JVM_ACC_FIELD_STABLE = 0x00000020, // @Stable field, same as JVM_ACC_SYNCHRONIZED JVM_ACC_FIELD_HAS_GENERIC_SIGNATURE = 0x00000800, // field has generic signature JVM_ACC_FIELD_INTERNAL_FLAGS = JVM_ACC_FIELD_ACCESS_WATCHED | JVM_ACC_FIELD_MODIFICATION_WATCHED | JVM_ACC_FIELD_INTERNAL | + JVM_ACC_FIELD_STABLE | JVM_ACC_FIELD_HAS_GENERIC_SIGNATURE, // flags accepted by set_field_flags() @@ -148,6 +150,7 @@ class AccessFlags VALUE_OBJ_CLASS_SPEC { { return (_flags & JVM_ACC_FIELD_MODIFICATION_WATCHED) != 0; } bool on_stack() const { return (_flags & JVM_ACC_ON_STACK) != 0; } bool is_internal() const { return (_flags & JVM_ACC_FIELD_INTERNAL) != 0; } + bool is_stable() const { return (_flags & JVM_ACC_FIELD_STABLE) != 0; } bool field_has_generic_signature() const { return (_flags & JVM_ACC_FIELD_HAS_GENERIC_SIGNATURE) != 0; } From ce469f1922e134ac709a9189c4328637655d5e38 Mon Sep 17 00:00:00 2001 From: David Holmes Date: Wed, 11 Sep 2013 00:38:18 -0400 Subject: [PATCH 117/210] 8024256: Minimal VM build is broken with PCH disabled Reviewed-by: coleenp, twisti --- hotspot/make/excludeSrc.make | 2 +- .../share/vm/gc_implementation/shared/allocationStats.hpp | 6 ++---- .../share/vm/gc_implementation/shared/hSpaceCounters.hpp | 4 +--- hotspot/src/share/vm/memory/binaryTreeDictionary.cpp | 4 ++-- hotspot/src/share/vm/utilities/yieldingWorkgroup.hpp | 5 +---- 5 files changed, 7 insertions(+), 14 deletions(-) diff --git a/hotspot/make/excludeSrc.make b/hotspot/make/excludeSrc.make index 7cc879a3d7b..c3a9b4dea0e 100644 --- a/hotspot/make/excludeSrc.make +++ b/hotspot/make/excludeSrc.make @@ -99,7 +99,7 @@ ifeq ($(INCLUDE_ALL_GCS), false) psTasks.cpp psVirtualspace.cpp psYoungGen.cpp vmPSOperations.cpp asParNewGeneration.cpp \ parCardTableModRefBS.cpp parGCAllocBuffer.cpp parNewGeneration.cpp mutableSpace.cpp \ gSpaceCounters.cpp allocationStats.cpp spaceCounters.cpp gcAdaptivePolicyCounters.cpp \ - mutableNUMASpace.cpp immutableSpace.cpp yieldingWorkGroup.cpp + mutableNUMASpace.cpp immutableSpace.cpp yieldingWorkGroup.cpp hSpaceCounters.cpp endif ifeq ($(INCLUDE_NMT), false) diff --git a/hotspot/src/share/vm/gc_implementation/shared/allocationStats.hpp b/hotspot/src/share/vm/gc_implementation/shared/allocationStats.hpp index cf7cd3ae0f2..0fb6d7fa23e 100644 --- a/hotspot/src/share/vm/gc_implementation/shared/allocationStats.hpp +++ b/hotspot/src/share/vm/gc_implementation/shared/allocationStats.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2013, 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,11 +26,9 @@ #define SHARE_VM_GC_IMPLEMENTATION_SHARED_ALLOCATIONSTATS_HPP #include "utilities/macros.hpp" -#if INCLUDE_ALL_GCS -#include "gc_implementation/shared/gcUtil.hpp" #include "memory/allocation.hpp" #include "utilities/globalDefinitions.hpp" -#endif // INCLUDE_ALL_GCS +#include "gc_implementation/shared/gcUtil.hpp" class AllocationStats VALUE_OBJ_CLASS_SPEC { // A duration threshold (in ms) used to filter diff --git a/hotspot/src/share/vm/gc_implementation/shared/hSpaceCounters.hpp b/hotspot/src/share/vm/gc_implementation/shared/hSpaceCounters.hpp index 034d319b078..0b855e7f674 100644 --- a/hotspot/src/share/vm/gc_implementation/shared/hSpaceCounters.hpp +++ b/hotspot/src/share/vm/gc_implementation/shared/hSpaceCounters.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2013, 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,11 +26,9 @@ #define SHARE_VM_GC_IMPLEMENTATION_SHARED_HSPACECOUNTERS_HPP #include "utilities/macros.hpp" -#if INCLUDE_ALL_GCS #include "gc_implementation/shared/generationCounters.hpp" #include "memory/generation.hpp" #include "runtime/perfData.hpp" -#endif // INCLUDE_ALL_GCS // A HSpaceCounter is a holder class for performance counters // that track a collections (logical spaces) in a heap; diff --git a/hotspot/src/share/vm/memory/binaryTreeDictionary.cpp b/hotspot/src/share/vm/memory/binaryTreeDictionary.cpp index 8ed2b61a921..bfe1d1b4ca8 100644 --- a/hotspot/src/share/vm/memory/binaryTreeDictionary.cpp +++ b/hotspot/src/share/vm/memory/binaryTreeDictionary.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2013, 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,10 +33,10 @@ #include "runtime/globals.hpp" #include "utilities/ostream.hpp" #include "utilities/macros.hpp" +#include "gc_implementation/shared/spaceDecorator.hpp" #if INCLUDE_ALL_GCS #include "gc_implementation/concurrentMarkSweep/adaptiveFreeList.hpp" #include "gc_implementation/concurrentMarkSweep/freeChunk.hpp" -#include "gc_implementation/shared/spaceDecorator.hpp" #include "gc_implementation/concurrentMarkSweep/freeChunk.hpp" #endif // INCLUDE_ALL_GCS diff --git a/hotspot/src/share/vm/utilities/yieldingWorkgroup.hpp b/hotspot/src/share/vm/utilities/yieldingWorkgroup.hpp index 5a626ce7fa3..98d8f438ea4 100644 --- a/hotspot/src/share/vm/utilities/yieldingWorkgroup.hpp +++ b/hotspot/src/share/vm/utilities/yieldingWorkgroup.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2013, 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,10 +26,7 @@ #define SHARE_VM_UTILITIES_YIELDINGWORKGROUP_HPP #include "utilities/macros.hpp" -#if INCLUDE_ALL_GCS #include "utilities/workgroup.hpp" -#endif // INCLUDE_ALL_GCS - // Forward declarations class YieldingFlexibleWorkGang; From 86624d96d773b48cf814ed669ff4bc8aac40623c Mon Sep 17 00:00:00 2001 From: Stefan Johansson Date: Wed, 11 Sep 2013 08:57:02 +0200 Subject: [PATCH 118/210] 8024176: [macosx] gc/metaspace/ClassMetaspaceSizeInJmapHeap.java failed since jdk8b105, hs25b47 The code for reading compressed klass pointers in the sa-agent on Mac used readCompOopAddress instead of readCompKlassAddress, this is wrong but has been hidden because compressed oops and compressed klasses has used the same base address in the past. Reviewed-by: sla, jmasa --- .../share/classes/sun/jvm/hotspot/debugger/bsd/BsdAddress.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdAddress.java b/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdAddress.java index d1b56881f13..f25d50ff23c 100644 --- a/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdAddress.java +++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdAddress.java @@ -81,7 +81,7 @@ class BsdAddress implements Address { public Address getCompKlassAddressAt(long offset) throws UnalignedAddressException, UnmappedAddressException { - return debugger.readCompOopAddress(addr + offset); + return debugger.readCompKlassAddress(addr + offset); } // From bcdf7e7a4d6cd53248206e182e3c1d664d21b47e Mon Sep 17 00:00:00 2001 From: Niclas Adlertz Date: Wed, 11 Sep 2013 09:34:00 +0200 Subject: [PATCH 119/210] 8010941: MinJumpTableSize is set to 18, investigate if that's still optimal Lowered the MinJumpTableSize for each platform Reviewed-by: kvn --- hotspot/src/cpu/sparc/vm/c2_globals_sparc.hpp | 1 + hotspot/src/cpu/x86/vm/c2_globals_x86.hpp | 2 +- hotspot/src/share/vm/opto/c2_globals.hpp | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/hotspot/src/cpu/sparc/vm/c2_globals_sparc.hpp b/hotspot/src/cpu/sparc/vm/c2_globals_sparc.hpp index 093be806072..e4fe6bb00a4 100644 --- a/hotspot/src/cpu/sparc/vm/c2_globals_sparc.hpp +++ b/hotspot/src/cpu/sparc/vm/c2_globals_sparc.hpp @@ -57,6 +57,7 @@ define_pd_global(intx, RegisterCostAreaRatio, 12000); define_pd_global(bool, UseTLAB, true); define_pd_global(bool, ResizeTLAB, true); define_pd_global(intx, LoopUnrollLimit, 60); // Design center runs on 1.3.1 +define_pd_global(intx, MinJumpTableSize, 5); // Peephole and CISC spilling both break the graph, and so makes the // scheduler sick. diff --git a/hotspot/src/cpu/x86/vm/c2_globals_x86.hpp b/hotspot/src/cpu/x86/vm/c2_globals_x86.hpp index d49bec21fe7..a45bd9624e5 100644 --- a/hotspot/src/cpu/x86/vm/c2_globals_x86.hpp +++ b/hotspot/src/cpu/x86/vm/c2_globals_x86.hpp @@ -30,7 +30,6 @@ // Sets the default values for platform dependent flags used by the server compiler. // (see c2_globals.hpp). Alpha-sorted. - define_pd_global(bool, BackgroundCompilation, true); define_pd_global(bool, UseTLAB, true); define_pd_global(bool, ResizeTLAB, true); @@ -52,6 +51,7 @@ define_pd_global(intx, OnStackReplacePercentage, 140); define_pd_global(intx, ConditionalMoveLimit, 3); define_pd_global(intx, FLOATPRESSURE, 6); define_pd_global(intx, FreqInlineSize, 325); +define_pd_global(intx, MinJumpTableSize, 10); #ifdef AMD64 define_pd_global(intx, INTPRESSURE, 13); define_pd_global(intx, InteriorEntryAlignment, 16); diff --git a/hotspot/src/share/vm/opto/c2_globals.hpp b/hotspot/src/share/vm/opto/c2_globals.hpp index 1ff73e7c425..cf9a82092fd 100644 --- a/hotspot/src/share/vm/opto/c2_globals.hpp +++ b/hotspot/src/share/vm/opto/c2_globals.hpp @@ -421,7 +421,7 @@ product(bool, UseDivMod, true, \ "Use combined DivMod instruction if available") \ \ - product(intx, MinJumpTableSize, 18, \ + product_pd(intx, MinJumpTableSize, \ "Minimum number of targets in a generated jump table") \ \ product(intx, MaxJumpTableSize, 65000, \ From 1d978716242b7d4ef33f8e82f8ce6d79f802e38b Mon Sep 17 00:00:00 2001 From: Mikael Gerdin Date: Wed, 11 Sep 2013 09:37:14 +0200 Subject: [PATCH 120/210] 8009561: NPG: Metaspace fragmentation when retiring a Metachunk Use best-fit block-splitting freelist allocation from the block freelist. Reviewed-by: jmasa, stefank --- hotspot/src/share/vm/memory/metaspace.cpp | 35 +++++++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/hotspot/src/share/vm/memory/metaspace.cpp b/hotspot/src/share/vm/memory/metaspace.cpp index 1c5cec84d5f..63e6be716da 100644 --- a/hotspot/src/share/vm/memory/metaspace.cpp +++ b/hotspot/src/share/vm/memory/metaspace.cpp @@ -51,7 +51,7 @@ const bool metaspace_slow_verify = false; // Parameters for stress mode testing const uint metadata_deallocate_a_lot_block = 10; const uint metadata_deallocate_a_lock_chunk = 3; -size_t const allocation_from_dictionary_limit = 64 * K; +size_t const allocation_from_dictionary_limit = 4 * K; MetaWord* last_allocated = 0; @@ -228,6 +228,10 @@ class BlockFreelist VALUE_OBJ_CLASS_SPEC { BlockTreeDictionary* _dictionary; static Metablock* initialize_free_chunk(MetaWord* p, size_t word_size); + // Only allocate and split from freelist if the size of the allocation + // is at least 1/4th the size of the available block. + const static int WasteMultiplier = 4; + // Accessors BlockTreeDictionary* dictionary() const { return _dictionary; } @@ -623,6 +627,7 @@ class SpaceManager : public CHeapObj { // Add chunk to the list of chunks in use void add_chunk(Metachunk* v, bool make_current); + void retire_current_chunk(); Mutex* lock() const { return _lock; } @@ -807,12 +812,25 @@ MetaWord* BlockFreelist::get_block(size_t word_size) { } Metablock* free_block = - dictionary()->get_chunk(word_size, FreeBlockDictionary::exactly); + dictionary()->get_chunk(word_size, FreeBlockDictionary::atLeast); if (free_block == NULL) { return NULL; } - return (MetaWord*) free_block; + const size_t block_size = free_block->size(); + if (block_size > WasteMultiplier * word_size) { + return_block((MetaWord*)free_block, block_size); + return NULL; + } + + MetaWord* new_block = (MetaWord*)free_block; + assert(block_size >= word_size, "Incorrect size of block from freelist"); + const size_t unused = block_size - word_size; + if (unused >= TreeChunk::min_size()) { + return_block(new_block + word_size, unused); + } + + return new_block; } void BlockFreelist::print_on(outputStream* st) const { @@ -2278,6 +2296,7 @@ void SpaceManager::add_chunk(Metachunk* new_chunk, bool make_current) { ChunkIndex index = ChunkManager::list_index(new_chunk->word_size()); if (index != HumongousIndex) { + retire_current_chunk(); set_current_chunk(new_chunk); new_chunk->set_next(chunks_in_use(index)); set_chunks_in_use(index, new_chunk); @@ -2313,6 +2332,16 @@ void SpaceManager::add_chunk(Metachunk* new_chunk, bool make_current) { } } +void SpaceManager::retire_current_chunk() { + if (current_chunk() != NULL) { + size_t remaining_words = current_chunk()->free_word_size(); + if (remaining_words >= TreeChunk::min_size()) { + block_freelists()->return_block(current_chunk()->allocate(remaining_words), remaining_words); + inc_used_metrics(remaining_words); + } + } +} + Metachunk* SpaceManager::get_new_chunk(size_t word_size, size_t grow_chunks_by_words) { From a136d0573963ee7cc319a0e4c577479479420172 Mon Sep 17 00:00:00 2001 From: Thomas Schatzl Date: Wed, 11 Sep 2013 10:14:32 +0200 Subject: [PATCH 121/210] 8016825: Large pages for the heap broken on Windows for compressed oops Correctly pass the requested base address for the heap to the OS function to reserve memory. Reviewed-by: brutisso, stefank --- hotspot/src/os/windows/vm/os_windows.cpp | 68 ++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 3 deletions(-) diff --git a/hotspot/src/os/windows/vm/os_windows.cpp b/hotspot/src/os/windows/vm/os_windows.cpp index 015f94d6662..985cbd6230f 100644 --- a/hotspot/src/os/windows/vm/os_windows.cpp +++ b/hotspot/src/os/windows/vm/os_windows.cpp @@ -3189,9 +3189,12 @@ char* os::reserve_memory_special(size_t bytes, size_t alignment, char* addr, boo return p_buf; } else { + if (TracePageSizes && Verbose) { + tty->print_cr("Reserving large pages in a single large chunk."); + } // normal policy just allocate it all at once DWORD flag = MEM_RESERVE | MEM_COMMIT | MEM_LARGE_PAGES; - char * res = (char *)VirtualAlloc(NULL, bytes, flag, prot); + char * res = (char *)VirtualAlloc(addr, bytes, flag, prot); if (res != NULL) { address pc = CALLER_PC; MemTracker::record_virtual_memory_reserve_and_commit((address)res, bytes, mtNone, pc); @@ -5714,7 +5717,66 @@ BOOL os::Advapi32Dll::AdvapiAvailable() { #endif #ifndef PRODUCT + +// test the code path in reserve_memory_special() that tries to allocate memory in a single +// contiguous memory block at a particular address. +// The test first tries to find a good approximate address to allocate at by using the same +// method to allocate some memory at any address. The test then tries to allocate memory in +// the vicinity (not directly after it to avoid possible by-chance use of that location) +// This is of course only some dodgy assumption, there is no guarantee that the vicinity of +// the previously allocated memory is available for allocation. The only actual failure +// that is reported is when the test tries to allocate at a particular location but gets a +// different valid one. A NULL return value at this point is not considered an error but may +// be legitimate. +// If -XX:+VerboseInternalVMTests is enabled, print some explanatory messages. void TestReserveMemorySpecial_test() { - // No tests available for this platform + if (!UseLargePages) { + if (VerboseInternalVMTests) { + gclog_or_tty->print("Skipping test because large pages are disabled"); + } + return; + } + // save current value of globals + bool old_use_large_pages_individual_allocation = UseLargePagesIndividualAllocation; + bool old_use_numa_interleaving = UseNUMAInterleaving; + + // set globals to make sure we hit the correct code path + UseLargePagesIndividualAllocation = UseNUMAInterleaving = false; + + // do an allocation at an address selected by the OS to get a good one. + const size_t large_allocation_size = os::large_page_size() * 4; + char* result = os::reserve_memory_special(large_allocation_size, os::large_page_size(), NULL, false); + if (result == NULL) { + if (VerboseInternalVMTests) { + gclog_or_tty->print("Failed to allocate control block with size "SIZE_FORMAT". Skipping remainder of test.", + large_allocation_size); + } + } else { + os::release_memory_special(result, large_allocation_size); + + // allocate another page within the recently allocated memory area which seems to be a good location. At least + // we managed to get it once. + const size_t expected_allocation_size = os::large_page_size(); + char* expected_location = result + os::large_page_size(); + char* actual_location = os::reserve_memory_special(expected_allocation_size, os::large_page_size(), expected_location, false); + if (actual_location == NULL) { + if (VerboseInternalVMTests) { + gclog_or_tty->print("Failed to allocate any memory at "PTR_FORMAT" size "SIZE_FORMAT". Skipping remainder of test.", + expected_location, large_allocation_size); + } + } else { + // release memory + os::release_memory_special(actual_location, expected_allocation_size); + // only now check, after releasing any memory to avoid any leaks. + assert(actual_location == expected_location, + err_msg("Failed to allocate memory at requested location "PTR_FORMAT" of size "SIZE_FORMAT", is "PTR_FORMAT" instead", + expected_location, expected_allocation_size, actual_location)); + } + } + + // restore globals + UseLargePagesIndividualAllocation = old_use_large_pages_individual_allocation; + UseNUMAInterleaving = old_use_numa_interleaving; } -#endif +#endif // PRODUCT + From 87a98b7267958dc8046ff36226083785fa442f36 Mon Sep 17 00:00:00 2001 From: Thomas Schatzl Date: Wed, 11 Sep 2013 10:19:16 +0200 Subject: [PATCH 122/210] 8021823: G1: Concurrent marking crashes with -XX:ObjectAlignmentInBytes>=32 in 64bit VMs Correctly calculate the initialization value for the shift between object start and bitmap bit in the G1 mark bitmaps. Reviewed-by: tonyp --- .../gc_implementation/g1/concurrentMark.cpp | 5 +- hotspot/test/gc/TestObjectAlignment.java | 65 +++++++++++++++++++ 2 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 hotspot/test/gc/TestObjectAlignment.java diff --git a/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.cpp b/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.cpp index 04f8ccd0fc7..77f08f0d3a3 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/concurrentMark.cpp @@ -481,9 +481,8 @@ uint ConcurrentMark::scale_parallel_threads(uint n_par_threads) { ConcurrentMark::ConcurrentMark(G1CollectedHeap* g1h, ReservedSpace heap_rs) : _g1h(g1h), - _markBitMap1(MinObjAlignment - 1), - _markBitMap2(MinObjAlignment - 1), - + _markBitMap1(log2_intptr(MinObjAlignment)), + _markBitMap2(log2_intptr(MinObjAlignment)), _parallel_marking_threads(0), _max_parallel_marking_threads(0), _sleep_factor(0.0), diff --git a/hotspot/test/gc/TestObjectAlignment.java b/hotspot/test/gc/TestObjectAlignment.java new file mode 100644 index 00000000000..8cfc9709f16 --- /dev/null +++ b/hotspot/test/gc/TestObjectAlignment.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2013, 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 TestObjectAlignment + * @key gc + * @bug 8021823 + * @summary G1: Concurrent marking crashes with -XX:ObjectAlignmentInBytes>=32 in 64bit VMs + * @library /testlibrary + * @run main/othervm TestObjectAlignment -Xmx20M -XX:+ExplicitGCInvokesConcurrent -XX:+IgnoreUnrecognizedVMOptions -XX:ObjectAlignmentInBytes=8 + * @run main/othervm TestObjectAlignment -Xmx20M -XX:+ExplicitGCInvokesConcurrent -XX:+IgnoreUnrecognizedVMOptions -XX:ObjectAlignmentInBytes=16 + * @run main/othervm TestObjectAlignment -Xmx20M -XX:+ExplicitGCInvokesConcurrent -XX:+IgnoreUnrecognizedVMOptions -XX:ObjectAlignmentInBytes=32 + * @run main/othervm TestObjectAlignment -Xmx20M -XX:+ExplicitGCInvokesConcurrent -XX:+IgnoreUnrecognizedVMOptions -XX:ObjectAlignmentInBytes=64 + * @run main/othervm TestObjectAlignment -Xmx20M -XX:+ExplicitGCInvokesConcurrent -XX:+IgnoreUnrecognizedVMOptions -XX:ObjectAlignmentInBytes=128 + * @run main/othervm TestObjectAlignment -Xmx20M -XX:+ExplicitGCInvokesConcurrent -XX:+IgnoreUnrecognizedVMOptions -XX:ObjectAlignmentInBytes=256 + * @run main/othervm TestObjectAlignment -Xmx20M -XX:-ExplicitGCInvokesConcurrent -XX:+IgnoreUnrecognizedVMOptions -XX:ObjectAlignmentInBytes=8 + * @run main/othervm TestObjectAlignment -Xmx20M -XX:-ExplicitGCInvokesConcurrent -XX:+IgnoreUnrecognizedVMOptions -XX:ObjectAlignmentInBytes=16 + * @run main/othervm TestObjectAlignment -Xmx20M -XX:-ExplicitGCInvokesConcurrent -XX:+IgnoreUnrecognizedVMOptions -XX:ObjectAlignmentInBytes=32 + * @run main/othervm TestObjectAlignment -Xmx20M -XX:-ExplicitGCInvokesConcurrent -XX:+IgnoreUnrecognizedVMOptions -XX:ObjectAlignmentInBytes=64 + * @run main/othervm TestObjectAlignment -Xmx20M -XX:-ExplicitGCInvokesConcurrent -XX:+IgnoreUnrecognizedVMOptions -XX:ObjectAlignmentInBytes=128 + * @run main/othervm TestObjectAlignment -Xmx20M -XX:-ExplicitGCInvokesConcurrent -XX:+IgnoreUnrecognizedVMOptions -XX:ObjectAlignmentInBytes=256 + */ + +import com.oracle.java.testlibrary.ProcessTools; +import com.oracle.java.testlibrary.OutputAnalyzer; + +public class TestObjectAlignment { + + public static byte[] garbage; + + private static boolean runsOn32bit() { + return System.getProperty("sun.arch.data.model").equals("32"); + } + + public static void main(String[] args) throws Exception { + if (runsOn32bit()) { + // 32 bit VMs do not allow setting ObjectAlignmentInBytes, so there is nothing to test. We still get called. + return; + } + for (int i = 0; i < 10; i++) { + garbage = new byte[1000]; + System.gc(); + } + } +} From eaa4cfd4a7c29b81b55422f0b013d28061236172 Mon Sep 17 00:00:00 2001 From: Dmitry Samersoff Date: Wed, 11 Sep 2013 14:30:17 +0400 Subject: [PATCH 123/210] 8024056: runtime/InitialThreadOverflow/testme.sh fails On some macines gcc not able to link cxx program Reviewed-by: dholmes --- hotspot/test/runtime/InitialThreadOverflow/testme.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hotspot/test/runtime/InitialThreadOverflow/testme.sh b/hotspot/test/runtime/InitialThreadOverflow/testme.sh index 015a6bd43b1..b7154dc2abd 100644 --- a/hotspot/test/runtime/InitialThreadOverflow/testme.sh +++ b/hotspot/test/runtime/InitialThreadOverflow/testme.sh @@ -43,9 +43,9 @@ then exit 0 fi -gcc_cmd=`which gcc` -if [ "x$gcc_cmd" == "x" ]; then - echo "WARNING: gcc not found. Cannot execute test." 2>&1 +gcc_cmd=`which g++` +if [ "x$gcc_cmd" = "x" ]; then + echo "WARNING: g++ not found. Cannot execute test." 2>&1 exit 0; fi From 1b72835883920aa57a33a7b0da3d6a9dd072bf58 Mon Sep 17 00:00:00 2001 From: Eric McCorkle Date: Wed, 11 Sep 2013 08:30:58 -0400 Subject: [PATCH 124/210] 8024510: lib/combo/tools/javac/combo/TemplateTest.java fails Edit regex in Template to allow "MAJOR." pattern. Reviewed-by: briangoetz --- .../lib/combo/tools/javac/combo/Template.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/langtools/test/lib/combo/tools/javac/combo/Template.java b/langtools/test/lib/combo/tools/javac/combo/Template.java index 8ad4d72edcb..ad8aeb9f956 100644 --- a/langtools/test/lib/combo/tools/javac/combo/Template.java +++ b/langtools/test/lib/combo/tools/javac/combo/Template.java @@ -40,11 +40,22 @@ public interface Template { public static class Behavior { /* Looks for expandable keys. An expandable key can take the form: * #{MAJOR} + * #{MAJOR.} * #{MAJOR.MINOR} - * where MAJOR can be IDENTIFIER or IDENTIFIER[NUMERIC_INDEX] - * and MINOR can be an identifier + * where MAJOR can be IDENTIFIER or IDENTIFIER[NUMERIC_INDEX] + * and MINOR can be an identifier. + * + * The ability to have an empty minor is provided on the + * assumption that some tests that can be written with this + * will find it useful to make a distinction akin to + * distinguishing F from F(), where F is a function pointer, + * and also cases of #{FOO.#{BAR}}, where BAR expands to an + * empty string. + * + * However, this being a general-purpose framework, the exact + * use is left up to the test writers. */ - private static final Pattern pattern = Pattern.compile("#\\{([A-Z_][A-Z0-9_]*(?:\\[\\d+\\])?)(?:\\.([A-Z_][A-Z0-9_]*))?\\}"); + private static final Pattern pattern = Pattern.compile("#\\{([A-Z_][A-Z0-9_]*(?:\\[\\d+\\])?)(?:\\.([A-Z0-9_]*))?\\}"); public static String expandTemplate(String template, final Map vars) { return expandTemplate(template, new MapResolver(vars)); From 962008f22b4767fa6c87a36119bc3f2fdbbe397c Mon Sep 17 00:00:00 2001 From: Thomas Schatzl Date: Wed, 11 Sep 2013 16:25:02 +0200 Subject: [PATCH 125/210] 8010722: assert: failed: heap size is too big for compressed oops Use conservative assumptions of required alignment for the various garbage collector components into account when determining the maximum heap size that supports compressed oops. Using this conservative value avoids several circular dependencies in the calculation. Reviewed-by: stefank, dholmes --- hotspot/src/os/bsd/vm/os_bsd.cpp | 2 - hotspot/src/os/linux/vm/os_linux.cpp | 2 - hotspot/src/os/solaris/vm/os_solaris.cpp | 4 +- hotspot/src/os/windows/vm/os_windows.cpp | 2 - .../gc_implementation/g1/g1CollectedHeap.cpp | 4 + .../gc_implementation/g1/g1CollectedHeap.hpp | 3 + .../vm/gc_implementation/g1/heapRegion.cpp | 6 +- .../vm/gc_implementation/g1/heapRegion.hpp | 4 +- .../parallelScavenge/parallelScavengeHeap.hpp | 7 +- .../src/share/vm/memory/collectorPolicy.cpp | 47 ++--- .../src/share/vm/memory/collectorPolicy.hpp | 6 +- .../src/share/vm/memory/genCollectedHeap.hpp | 7 +- hotspot/src/share/vm/memory/universe.cpp | 3 + hotspot/src/share/vm/prims/whitebox.cpp | 8 + hotspot/src/share/vm/runtime/arguments.cpp | 39 +++- hotspot/src/share/vm/runtime/arguments.hpp | 12 +- hotspot/src/share/vm/runtime/os.cpp | 5 + hotspot/src/share/vm/runtime/os.hpp | 8 + hotspot/src/share/vm/runtime/thread.cpp | 5 + .../arguments/TestUseCompressedOopsErgo.java | 50 +++++ .../TestUseCompressedOopsErgoTools.java | 179 ++++++++++++++++++ .../whitebox/sun/hotspot/WhiteBox.java | 2 + 22 files changed, 363 insertions(+), 42 deletions(-) create mode 100644 hotspot/test/gc/arguments/TestUseCompressedOopsErgo.java create mode 100644 hotspot/test/gc/arguments/TestUseCompressedOopsErgoTools.java diff --git a/hotspot/src/os/bsd/vm/os_bsd.cpp b/hotspot/src/os/bsd/vm/os_bsd.cpp index 6b636d379de..58c961b43eb 100644 --- a/hotspot/src/os/bsd/vm/os_bsd.cpp +++ b/hotspot/src/os/bsd/vm/os_bsd.cpp @@ -3589,8 +3589,6 @@ jint os::init_2(void) #endif } - os::large_page_init(); - // initialize suspend/resume support - must do this before signal_sets_init() if (SR_initialize() != 0) { perror("SR_initialize failed"); diff --git a/hotspot/src/os/linux/vm/os_linux.cpp b/hotspot/src/os/linux/vm/os_linux.cpp index 70837a850d8..5b3d6b31116 100644 --- a/hotspot/src/os/linux/vm/os_linux.cpp +++ b/hotspot/src/os/linux/vm/os_linux.cpp @@ -4755,8 +4755,6 @@ jint os::init_2(void) #endif } - os::large_page_init(); - // initialize suspend/resume support - must do this before signal_sets_init() if (SR_initialize() != 0) { perror("SR_initialize failed"); diff --git a/hotspot/src/os/solaris/vm/os_solaris.cpp b/hotspot/src/os/solaris/vm/os_solaris.cpp index c3e6e879077..8e5984ffa3d 100644 --- a/hotspot/src/os/solaris/vm/os_solaris.cpp +++ b/hotspot/src/os/solaris/vm/os_solaris.cpp @@ -5178,9 +5178,7 @@ jint os::init_2(void) { if(Verbose && PrintMiscellaneous) tty->print("[Memory Serialize Page address: " INTPTR_FORMAT "]\n", (intptr_t)mem_serialize_page); #endif -} - - os::large_page_init(); + } // Check minimum allowable stack size for thread creation and to initialize // the java system classes, including StackOverflowError - depends on page diff --git a/hotspot/src/os/windows/vm/os_windows.cpp b/hotspot/src/os/windows/vm/os_windows.cpp index 985cbd6230f..e55281af4c9 100644 --- a/hotspot/src/os/windows/vm/os_windows.cpp +++ b/hotspot/src/os/windows/vm/os_windows.cpp @@ -3920,8 +3920,6 @@ jint os::init_2(void) { #endif } - os::large_page_init(); - // Setup Windows Exceptions // for debugging float code generation bugs diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp index bd01ec3b602..1d8ff8a26dc 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp @@ -2191,6 +2191,10 @@ jint G1CollectedHeap::initialize() { return JNI_OK; } +size_t G1CollectedHeap::conservative_max_heap_alignment() { + return HeapRegion::max_region_size(); +} + void G1CollectedHeap::ref_processing_init() { // Reference processing in G1 currently works as follows: // diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp index aecaa5e97ac..747b2326236 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp @@ -1092,6 +1092,9 @@ public: // specified by the policy object. jint initialize(); + // Return the (conservative) maximum heap alignment for any G1 heap + static size_t conservative_max_heap_alignment(); + // Initialize weak reference processing. virtual void ref_processing_init(); diff --git a/hotspot/src/share/vm/gc_implementation/g1/heapRegion.cpp b/hotspot/src/share/vm/gc_implementation/g1/heapRegion.cpp index e66268885e3..726acbfcdc0 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/heapRegion.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/heapRegion.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2013, 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 @@ -149,6 +149,10 @@ void HeapRegionDCTOC::walk_mem_region_with_cl(MemRegion mr, // many regions in the heap (based on the min heap size). #define TARGET_REGION_NUMBER 2048 +size_t HeapRegion::max_region_size() { + return (size_t)MAX_REGION_SIZE; +} + void HeapRegion::setup_heap_region_size(size_t initial_heap_size, size_t max_heap_size) { uintx region_size = G1HeapRegionSize; if (FLAG_IS_DEFAULT(G1HeapRegionSize)) { diff --git a/hotspot/src/share/vm/gc_implementation/g1/heapRegion.hpp b/hotspot/src/share/vm/gc_implementation/g1/heapRegion.hpp index 097c0b54380..ad2b0649795 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/heapRegion.hpp +++ b/hotspot/src/share/vm/gc_implementation/g1/heapRegion.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2013, 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 @@ -355,6 +355,8 @@ class HeapRegion: public G1OffsetTableContigSpace { ~((1 << (size_t) LogOfHRGrainBytes) - 1); } + static size_t max_region_size(); + // It sets up the heap region size (GrainBytes / GrainWords), as // well as other related fields that are based on the heap region // size (LogOfHRGrainBytes / LogOfHRGrainWords / diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/parallelScavengeHeap.hpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/parallelScavengeHeap.hpp index 11ef5325120..4e458efa903 100644 --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/parallelScavengeHeap.hpp +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/parallelScavengeHeap.hpp @@ -86,6 +86,11 @@ class ParallelScavengeHeap : public CollectedHeap { set_alignment(_old_gen_alignment, intra_heap_alignment()); } + // Return the (conservative) maximum heap alignment + static size_t conservative_max_heap_alignment() { + return intra_heap_alignment(); + } + // For use by VM operations enum CollectionType { Scavenge, @@ -122,7 +127,7 @@ class ParallelScavengeHeap : public CollectedHeap { // The alignment used for eden and survivors within the young gen // and for boundary between young gen and old gen. - size_t intra_heap_alignment() const { return 64 * K * HeapWordSize; } + static size_t intra_heap_alignment() { return 64 * K * HeapWordSize; } size_t capacity() const; size_t used() const; diff --git a/hotspot/src/share/vm/memory/collectorPolicy.cpp b/hotspot/src/share/vm/memory/collectorPolicy.cpp index 6a1967daeda..a5b4aa61894 100644 --- a/hotspot/src/share/vm/memory/collectorPolicy.cpp +++ b/hotspot/src/share/vm/memory/collectorPolicy.cpp @@ -145,6 +145,30 @@ void CollectorPolicy::cleared_all_soft_refs() { _all_soft_refs_clear = true; } +size_t CollectorPolicy::compute_max_alignment() { + // The card marking array and the offset arrays for old generations are + // committed in os pages as well. Make sure they are entirely full (to + // avoid partial page problems), e.g. if 512 bytes heap corresponds to 1 + // byte entry and the os page size is 4096, the maximum heap size should + // be 512*4096 = 2MB aligned. + + // There is only the GenRemSet in Hotspot and only the GenRemSet::CardTable + // is supported. + // Requirements of any new remembered set implementations must be added here. + size_t alignment = GenRemSet::max_alignment_constraint(GenRemSet::CardTable); + + // Parallel GC does its own alignment of the generations to avoid requiring a + // large page (256M on some platforms) for the permanent generation. The + // other collectors should also be updated to do their own alignment and then + // this use of lcm() should be removed. + if (UseLargePages && !UseParallelGC) { + // in presence of large pages we have to make sure that our + // alignment is large page aware + alignment = lcm(os::large_page_size(), alignment); + } + + return alignment; +} // GenCollectorPolicy methods. @@ -175,29 +199,6 @@ void GenCollectorPolicy::initialize_size_policy(size_t init_eden_size, GCTimeRatio); } -size_t GenCollectorPolicy::compute_max_alignment() { - // The card marking array and the offset arrays for old generations are - // committed in os pages as well. Make sure they are entirely full (to - // avoid partial page problems), e.g. if 512 bytes heap corresponds to 1 - // byte entry and the os page size is 4096, the maximum heap size should - // be 512*4096 = 2MB aligned. - size_t alignment = GenRemSet::max_alignment_constraint(rem_set_name()); - - // Parallel GC does its own alignment of the generations to avoid requiring a - // large page (256M on some platforms) for the permanent generation. The - // other collectors should also be updated to do their own alignment and then - // this use of lcm() should be removed. - if (UseLargePages && !UseParallelGC) { - // in presence of large pages we have to make sure that our - // alignment is large page aware - alignment = lcm(os::large_page_size(), alignment); - } - - assert(alignment >= min_alignment(), "Must be"); - - return alignment; -} - void GenCollectorPolicy::initialize_flags() { // All sizes must be multiples of the generation granularity. set_min_alignment((uintx) Generation::GenGrain); diff --git a/hotspot/src/share/vm/memory/collectorPolicy.hpp b/hotspot/src/share/vm/memory/collectorPolicy.hpp index 4acf7ba780c..73fd177d7ba 100644 --- a/hotspot/src/share/vm/memory/collectorPolicy.hpp +++ b/hotspot/src/share/vm/memory/collectorPolicy.hpp @@ -98,6 +98,9 @@ class CollectorPolicy : public CHeapObj { {} public: + // Return maximum heap alignment that may be imposed by the policy + static size_t compute_max_alignment(); + void set_min_alignment(size_t align) { _min_alignment = align; } size_t min_alignment() { return _min_alignment; } void set_max_alignment(size_t align) { _max_alignment = align; } @@ -234,9 +237,6 @@ class GenCollectorPolicy : public CollectorPolicy { // Try to allocate space by expanding the heap. virtual HeapWord* expand_heap_and_allocate(size_t size, bool is_tlab); - // compute max heap alignment - size_t compute_max_alignment(); - // Scale the base_size by NewRation according to // result = base_size / (NewRatio + 1) // and align by min_alignment() diff --git a/hotspot/src/share/vm/memory/genCollectedHeap.hpp b/hotspot/src/share/vm/memory/genCollectedHeap.hpp index 9ab9d1991df..8f814132a78 100644 --- a/hotspot/src/share/vm/memory/genCollectedHeap.hpp +++ b/hotspot/src/share/vm/memory/genCollectedHeap.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2013, 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 @@ -148,6 +148,11 @@ public: return gen_policy()->size_policy(); } + // Return the (conservative) maximum heap alignment + static size_t conservative_max_heap_alignment() { + return Generation::GenGrain; + } + size_t capacity() const; size_t used() const; diff --git a/hotspot/src/share/vm/memory/universe.cpp b/hotspot/src/share/vm/memory/universe.cpp index d0f34b33ae1..54d6851d16d 100644 --- a/hotspot/src/share/vm/memory/universe.cpp +++ b/hotspot/src/share/vm/memory/universe.cpp @@ -872,6 +872,9 @@ jint Universe::initialize_heap() { // Reserve the Java heap, which is now the same for all GCs. ReservedSpace Universe::reserve_heap(size_t heap_size, size_t alignment) { + assert(alignment <= Arguments::conservative_max_heap_alignment(), + err_msg("actual alignment "SIZE_FORMAT" must be within maximum heap alignment "SIZE_FORMAT, + alignment, Arguments::conservative_max_heap_alignment())); size_t total_reserved = align_size_up(heap_size, alignment); assert(!UseCompressedOops || (total_reserved <= (OopEncodingHeapMax - os::vm_page_size())), "heap size is too big for compressed oops"); diff --git a/hotspot/src/share/vm/prims/whitebox.cpp b/hotspot/src/share/vm/prims/whitebox.cpp index 0f5607e22b2..6f6a2000a3f 100644 --- a/hotspot/src/share/vm/prims/whitebox.cpp +++ b/hotspot/src/share/vm/prims/whitebox.cpp @@ -33,6 +33,7 @@ #include "prims/whitebox.hpp" #include "prims/wbtestmethods/parserTests.hpp" +#include "runtime/arguments.hpp" #include "runtime/interfaceSupport.hpp" #include "runtime/os.hpp" #include "utilities/debug.hpp" @@ -94,6 +95,11 @@ WB_ENTRY(jboolean, WB_IsClassAlive(JNIEnv* env, jobject target, jstring name)) return closure.found(); WB_END +WB_ENTRY(jlong, WB_GetCompressedOopsMaxHeapSize(JNIEnv* env, jobject o)) { + return (jlong)Arguments::max_heap_for_compressed_oops(); +} +WB_END + WB_ENTRY(void, WB_PrintHeapSizes(JNIEnv* env, jobject o)) { CollectorPolicy * p = Universe::heap()->collector_policy(); gclog_or_tty->print_cr("Minimum heap "SIZE_FORMAT" Initial heap " @@ -436,6 +442,8 @@ static JNINativeMethod methods[] = { CC"(Ljava/lang/String;[Lsun/hotspot/parser/DiagnosticCommand;)[Ljava/lang/Object;", (void*) &WB_ParseCommandLine }, + {CC"getCompressedOopsMaxHeapSize", CC"()J", + (void*)&WB_GetCompressedOopsMaxHeapSize}, {CC"printHeapSizes", CC"()V", (void*)&WB_PrintHeapSizes }, #if INCLUDE_ALL_GCS {CC"g1InConcurrentMark", CC"()Z", (void*)&WB_G1InConcurrentMark}, diff --git a/hotspot/src/share/vm/runtime/arguments.cpp b/hotspot/src/share/vm/runtime/arguments.cpp index fbce8b6b695..9751c552233 100644 --- a/hotspot/src/share/vm/runtime/arguments.cpp +++ b/hotspot/src/share/vm/runtime/arguments.cpp @@ -28,6 +28,7 @@ #include "compiler/compilerOracle.hpp" #include "memory/allocation.inline.hpp" #include "memory/cardTableRS.hpp" +#include "memory/genCollectedHeap.hpp" #include "memory/referenceProcessor.hpp" #include "memory/universe.inline.hpp" #include "oops/oop.inline.hpp" @@ -54,6 +55,8 @@ #endif #if INCLUDE_ALL_GCS #include "gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp" +#include "gc_implementation/g1/g1CollectedHeap.inline.hpp" +#include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp" #endif // INCLUDE_ALL_GCS // Note: This is a special bug reporting site for the JVM @@ -90,6 +93,7 @@ char* Arguments::_java_command = NULL; SystemProperty* Arguments::_system_properties = NULL; const char* Arguments::_gc_log_filename = NULL; bool Arguments::_has_profile = false; +size_t Arguments::_conservative_max_heap_alignment = 0; uintx Arguments::_min_heap_size = 0; Arguments::Mode Arguments::_mode = _mixed; bool Arguments::_java_compiler = false; @@ -1391,10 +1395,17 @@ bool verify_object_alignment() { return true; } -inline uintx max_heap_for_compressed_oops() { +uintx Arguments::max_heap_for_compressed_oops() { // Avoid sign flip. assert(OopEncodingHeapMax > (uint64_t)os::vm_page_size(), "Unusual page size"); - LP64_ONLY(return OopEncodingHeapMax - os::vm_page_size()); + // We need to fit both the NULL page and the heap into the memory budget, while + // keeping alignment constraints of the heap. To guarantee the latter, as the + // NULL page is located before the heap, we pad the NULL page to the conservative + // maximum alignment that the GC may ever impose upon the heap. + size_t displacement_due_to_null_page = align_size_up_(os::vm_page_size(), + Arguments::conservative_max_heap_alignment()); + + LP64_ONLY(return OopEncodingHeapMax - displacement_due_to_null_page); NOT_LP64(ShouldNotReachHere(); return 0); } @@ -1475,6 +1486,23 @@ void Arguments::set_use_compressed_klass_ptrs() { #endif // !ZERO } +void Arguments::set_conservative_max_heap_alignment() { + // The conservative maximum required alignment for the heap is the maximum of + // the alignments imposed by several sources: any requirements from the heap + // itself, the collector policy and the maximum page size we may run the VM + // with. + size_t heap_alignment = GenCollectedHeap::conservative_max_heap_alignment(); +#if INCLUDE_ALL_GCS + if (UseParallelGC) { + heap_alignment = ParallelScavengeHeap::conservative_max_heap_alignment(); + } else if (UseG1GC) { + heap_alignment = G1CollectedHeap::conservative_max_heap_alignment(); + } +#endif // INCLUDE_ALL_GCS + _conservative_max_heap_alignment = MAX3(heap_alignment, os::max_page_size(), + CollectorPolicy::compute_max_alignment()); +} + void Arguments::set_ergonomics_flags() { if (os::is_server_class_machine()) { @@ -1503,6 +1531,8 @@ void Arguments::set_ergonomics_flags() { } } + set_conservative_max_heap_alignment(); + #ifndef ZERO #ifdef _LP64 set_use_compressed_oops(); @@ -3506,6 +3536,11 @@ jint Arguments::parse(const JavaVMInitArgs* args) { no_shared_spaces(); #endif // INCLUDE_CDS + return JNI_OK; +} + +jint Arguments::apply_ergo() { + // Set flags based on ergonomics. set_ergonomics_flags(); diff --git a/hotspot/src/share/vm/runtime/arguments.hpp b/hotspot/src/share/vm/runtime/arguments.hpp index 43256b75082..c2f4c9883f1 100644 --- a/hotspot/src/share/vm/runtime/arguments.hpp +++ b/hotspot/src/share/vm/runtime/arguments.hpp @@ -280,6 +280,9 @@ class Arguments : AllStatic { // Option flags static bool _has_profile; static const char* _gc_log_filename; + // Value of the conservative maximum heap alignment needed + static size_t _conservative_max_heap_alignment; + static uintx _min_heap_size; // -Xrun arguments @@ -327,6 +330,7 @@ class Arguments : AllStatic { // Garbage-First (UseG1GC) static void set_g1_gc_flags(); // GC ergonomics + static void set_conservative_max_heap_alignment(); static void set_use_compressed_oops(); static void set_use_compressed_klass_ptrs(); static void set_ergonomics_flags(); @@ -430,8 +434,10 @@ class Arguments : AllStatic { static char* SharedArchivePath; public: - // Parses the arguments + // Parses the arguments, first phase static jint parse(const JavaVMInitArgs* args); + // Apply ergonomics + static jint apply_ergo(); // Adjusts the arguments after the OS have adjusted the arguments static jint adjust_after_os(); // Check for consistency in the selection of the garbage collector. @@ -445,6 +451,10 @@ class Arguments : AllStatic { // Used by os_solaris static bool process_settings_file(const char* file_name, bool should_exist, jboolean ignore_unrecognized); + static size_t conservative_max_heap_alignment() { return _conservative_max_heap_alignment; } + // Return the maximum size a heap with compressed oops can take + static size_t max_heap_for_compressed_oops(); + // return a char* array containing all options static char** jvm_flags_array() { return _jvm_flags_array; } static char** jvm_args_array() { return _jvm_args_array; } diff --git a/hotspot/src/share/vm/runtime/os.cpp b/hotspot/src/share/vm/runtime/os.cpp index 0c83565195c..8f49f4a2edf 100644 --- a/hotspot/src/share/vm/runtime/os.cpp +++ b/hotspot/src/share/vm/runtime/os.cpp @@ -314,6 +314,11 @@ static void signal_thread_entry(JavaThread* thread, TRAPS) { } } +void os::init_before_ergo() { + // We need to initialize large page support here because ergonomics takes some + // decisions depending on large page support and the calculated large page size. + large_page_init(); +} void os::signal_init() { if (!ReduceSignalUsage) { diff --git a/hotspot/src/share/vm/runtime/os.hpp b/hotspot/src/share/vm/runtime/os.hpp index e43d68981cb..3438badb095 100644 --- a/hotspot/src/share/vm/runtime/os.hpp +++ b/hotspot/src/share/vm/runtime/os.hpp @@ -139,7 +139,10 @@ class os: AllStatic { public: static void init(void); // Called before command line parsing + static void init_before_ergo(void); // Called after command line parsing + // before VM ergonomics processing. static jint init_2(void); // Called after command line parsing + // and VM ergonomics processing static void init_globals(void) { // Called from init_globals() in init.cpp init_globals_ext(); } @@ -254,6 +257,11 @@ class os: AllStatic { static size_t page_size_for_region(size_t region_min_size, size_t region_max_size, uint min_pages); + // Return the largest page size that can be used + static size_t max_page_size() { + // The _page_sizes array is sorted in descending order. + return _page_sizes[0]; + } // Methods for tracing page sizes returned by the above method; enabled by // TracePageSizes. The region_{min,max}_size parameters should be the values diff --git a/hotspot/src/share/vm/runtime/thread.cpp b/hotspot/src/share/vm/runtime/thread.cpp index d5bc3a00006..02bd4b38f24 100644 --- a/hotspot/src/share/vm/runtime/thread.cpp +++ b/hotspot/src/share/vm/runtime/thread.cpp @@ -3329,6 +3329,11 @@ jint Threads::create_vm(JavaVMInitArgs* args, bool* canTryAgain) { jint parse_result = Arguments::parse(args); if (parse_result != JNI_OK) return parse_result; + os::init_before_ergo(); + + jint ergo_result = Arguments::apply_ergo(); + if (ergo_result != JNI_OK) return ergo_result; + if (PauseAtStartup) { os::pause(); } diff --git a/hotspot/test/gc/arguments/TestUseCompressedOopsErgo.java b/hotspot/test/gc/arguments/TestUseCompressedOopsErgo.java new file mode 100644 index 00000000000..852076e768e --- /dev/null +++ b/hotspot/test/gc/arguments/TestUseCompressedOopsErgo.java @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2013, 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 TestUseCompressedOopsErgo + * @key gc + * @bug 8010722 + * @summary Tests ergonomics for UseCompressedOops. + * @library /testlibrary /testlibrary/whitebox + * @build TestUseCompressedOopsErgo TestUseCompressedOopsErgoTools + * @run main ClassFileInstaller sun.hotspot.WhiteBox + * @run main/othervm TestUseCompressedOopsErgo -XX:+UseG1GC + * @run main/othervm TestUseCompressedOopsErgo -XX:+UseParallelGC + * @run main/othervm TestUseCompressedOopsErgo -XX:+UseParallelGC -XX:-UseParallelOldGC + * @run main/othervm TestUseCompressedOopsErgo -XX:+UseConcMarkSweepGC + * @run main/othervm TestUseCompressedOopsErgo -XX:+UseSerialGC + */ + +public class TestUseCompressedOopsErgo { + + public static void main(String args[]) throws Exception { + if (!TestUseCompressedOopsErgoTools.is64bitVM()) { + // this test is relevant for 64 bit VMs only + return; + } + final String[] gcFlags = args; + TestUseCompressedOopsErgoTools.checkCompressedOopsErgo(gcFlags); + } +} + diff --git a/hotspot/test/gc/arguments/TestUseCompressedOopsErgoTools.java b/hotspot/test/gc/arguments/TestUseCompressedOopsErgoTools.java new file mode 100644 index 00000000000..49d0a8a1d21 --- /dev/null +++ b/hotspot/test/gc/arguments/TestUseCompressedOopsErgoTools.java @@ -0,0 +1,179 @@ +/* +* Copyright (c) 2013, 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 sun.management.ManagementFactoryHelper; +import com.sun.management.HotSpotDiagnosticMXBean; +import com.sun.management.VMOption; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.ArrayList; +import java.util.Arrays; + +import com.oracle.java.testlibrary.*; +import sun.hotspot.WhiteBox; + +class DetermineMaxHeapForCompressedOops { + public static void main(String[] args) throws Exception { + WhiteBox wb = WhiteBox.getWhiteBox(); + System.out.print(wb.getCompressedOopsMaxHeapSize()); + } +} + +class TestUseCompressedOopsErgoTools { + + private static long getClassMetaspaceSize() { + HotSpotDiagnosticMXBean diagnostic = ManagementFactoryHelper.getDiagnosticMXBean(); + + VMOption option = diagnostic.getVMOption("ClassMetaspaceSize"); + return Long.parseLong(option.getValue()); + } + + + public static long getMaxHeapForCompressedOops(String[] vmargs) throws Exception { + OutputAnalyzer output = runWhiteBoxTest(vmargs, DetermineMaxHeapForCompressedOops.class.getName(), new String[] {}, false); + return Long.parseLong(output.getStdout()); + } + + public static boolean is64bitVM() { + String val = System.getProperty("sun.arch.data.model"); + if (val == null) { + throw new RuntimeException("Could not read sun.arch.data.model"); + } + if (val.equals("64")) { + return true; + } else if (val.equals("32")) { + return false; + } + throw new RuntimeException("Unexpected value " + val + " of sun.arch.data.model"); + } + + /** + * Executes a new VM process with the given class and parameters. + * @param vmargs Arguments to the VM to run + * @param classname Name of the class to run + * @param arguments Arguments to the class + * @param useTestDotJavaDotOpts Use test.java.opts as part of the VM argument string + * @return The OutputAnalyzer with the results for the invocation. + */ + public static OutputAnalyzer runWhiteBoxTest(String[] vmargs, String classname, String[] arguments, boolean useTestDotJavaDotOpts) throws Exception { + ArrayList finalargs = new ArrayList(); + + String[] whiteboxOpts = new String[] { + "-Xbootclasspath/a:.", + "-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI", + "-cp", System.getProperty("java.class.path"), + }; + + if (useTestDotJavaDotOpts) { + // System.getProperty("test.java.opts") is '' if no options is set, + // we need to skip such a result + String[] externalVMOpts = new String[0]; + if (System.getProperty("test.java.opts") != null && System.getProperty("test.java.opts").length() != 0) { + externalVMOpts = System.getProperty("test.java.opts").split(" "); + } + finalargs.addAll(Arrays.asList(externalVMOpts)); + } + + finalargs.addAll(Arrays.asList(vmargs)); + finalargs.addAll(Arrays.asList(whiteboxOpts)); + finalargs.add(classname); + finalargs.addAll(Arrays.asList(arguments)); + + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(finalargs.toArray(new String[0])); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldHaveExitValue(0); + return output; + } + + private static String[] join(String[] part1, String part2) { + ArrayList result = new ArrayList(); + result.addAll(Arrays.asList(part1)); + result.add(part2); + return result.toArray(new String[0]); + } + + public static void checkCompressedOopsErgo(String[] gcflags) throws Exception { + long maxHeapForCompressedOops = getMaxHeapForCompressedOops(gcflags); + + checkUseCompressedOops(gcflags, maxHeapForCompressedOops, true); + checkUseCompressedOops(gcflags, maxHeapForCompressedOops - 1, true); + checkUseCompressedOops(gcflags, maxHeapForCompressedOops + 1, false); + + // the use of HeapBaseMinAddress should not change the outcome + checkUseCompressedOops(join(gcflags, "-XX:HeapBaseMinAddress=32G"), maxHeapForCompressedOops, true); + checkUseCompressedOops(join(gcflags, "-XX:HeapBaseMinAddress=32G"), maxHeapForCompressedOops - 1, true); + checkUseCompressedOops(join(gcflags, "-XX:HeapBaseMinAddress=32G"), maxHeapForCompressedOops + 1, false); + + // use a different object alignment + maxHeapForCompressedOops = getMaxHeapForCompressedOops(join(gcflags, "-XX:ObjectAlignmentInBytes=16")); + + checkUseCompressedOops(join(gcflags, "-XX:ObjectAlignmentInBytes=16"), maxHeapForCompressedOops, true); + checkUseCompressedOops(join(gcflags, "-XX:ObjectAlignmentInBytes=16"), maxHeapForCompressedOops - 1, true); + checkUseCompressedOops(join(gcflags, "-XX:ObjectAlignmentInBytes=16"), maxHeapForCompressedOops + 1, false); + + // use a different ClassMetaspaceSize + String classMetaspaceSizeArg = "-XX:ClassMetaspaceSize=" + 2 * getClassMetaspaceSize(); + maxHeapForCompressedOops = getMaxHeapForCompressedOops(join(gcflags, classMetaspaceSizeArg)); + + checkUseCompressedOops(join(gcflags, classMetaspaceSizeArg), maxHeapForCompressedOops, true); + checkUseCompressedOops(join(gcflags, classMetaspaceSizeArg), maxHeapForCompressedOops - 1, true); + checkUseCompressedOops(join(gcflags, classMetaspaceSizeArg), maxHeapForCompressedOops + 1, false); + } + + private static void checkUseCompressedOops(String[] args, long heapsize, boolean expectUseCompressedOops) throws Exception { + ArrayList finalargs = new ArrayList(); + finalargs.addAll(Arrays.asList(args)); + finalargs.add("-Xmx" + heapsize); + finalargs.add("-XX:+PrintFlagsFinal"); + finalargs.add("-version"); + + String output = expectValid(finalargs.toArray(new String[0])); + + boolean actualUseCompressedOops = getFlagBoolValue(" UseCompressedOops", output); + + if (expectUseCompressedOops != actualUseCompressedOops) { + throw new RuntimeException("Expected use of compressed oops: " + expectUseCompressedOops + " but was: " + actualUseCompressedOops); + } + } + + private static boolean getFlagBoolValue(String flag, String where) { + Matcher m = Pattern.compile(flag + "\\s+:?= (true|false)").matcher(where); + if (!m.find()) { + throw new RuntimeException("Could not find value for flag " + flag + " in output string"); + } + String match = m.group(1).equals("true"); + } + + private static String expect(String[] flags, boolean hasWarning, boolean hasError, int errorcode) throws Exception { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(flags); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldHaveExitValue(errorcode); + return output.getStdout(); + } + + private static String expectValid(String[] flags) throws Exception { + return expect(flags, false, false, 0); + } +} + diff --git a/hotspot/test/testlibrary/whitebox/sun/hotspot/WhiteBox.java b/hotspot/test/testlibrary/whitebox/sun/hotspot/WhiteBox.java index c508b8f121a..091b5f7543b 100644 --- a/hotspot/test/testlibrary/whitebox/sun/hotspot/WhiteBox.java +++ b/hotspot/test/testlibrary/whitebox/sun/hotspot/WhiteBox.java @@ -61,6 +61,8 @@ public class WhiteBox { registerNatives(); } + // Get the maximum heap size supporting COOPs + public native long getCompressedOopsMaxHeapSize(); // Arguments public native void printHeapSizes(); From a357688f61daa0311edebc9cc4a96e11c749bed8 Mon Sep 17 00:00:00 2001 From: Bhavesh Patel Date: Wed, 11 Sep 2013 14:50:11 -0700 Subject: [PATCH 126/210] 8015496: Information that package is deprecated is missing in profiles view Reviewed-by: jjg --- .../html/AbstractPackageIndexWriter.java | 2 +- .../doclets/formats/html/HtmlDoclet.java | 13 ++++-- .../formats/html/PackageIndexWriter.java | 12 ++++-- .../formats/html/ProfileIndexFrameWriter.java | 12 ++++-- .../formats/html/ProfileWriterImpl.java | 25 +++++++++++ .../internal/toolkit/Configuration.java | 21 +++++++++- .../TestProfilesConfiguration.java | 35 +++++++++++++++- .../profile-rtjar-includes-nopkgs.txt | 41 +++++++++++++++++++ 8 files changed, 147 insertions(+), 14 deletions(-) create mode 100644 langtools/test/com/sun/javadoc/testProfiles/profile-rtjar-includes-nopkgs.txt diff --git a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/AbstractPackageIndexWriter.java b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/AbstractPackageIndexWriter.java index bd84d2caf2d..91877d1cdfa 100644 --- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/AbstractPackageIndexWriter.java +++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/AbstractPackageIndexWriter.java @@ -157,7 +157,7 @@ public abstract class AbstractPackageIndexWriter extends HtmlDocletWriter { addAllProfilesLink(div); } body.addContent(div); - if (configuration.showProfiles) { + if (configuration.showProfiles && configuration.profilePackages.size() > 0) { Content profileSummary = configuration.getResource("doclet.Profiles"); addProfilesList(profileSummary, body); } diff --git a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDoclet.java b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDoclet.java index 24c95876e6f..bf61cd1fae5 100644 --- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDoclet.java +++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDoclet.java @@ -205,13 +205,20 @@ public class HtmlDoclet extends AbstractDoclet { * {@inheritDoc} */ protected void generateProfileFiles() throws Exception { - if (configuration.showProfiles) { + if (configuration.showProfiles && configuration.profilePackages.size() > 0) { ProfileIndexFrameWriter.generate(configuration); Profile prevProfile = null, nextProfile; + String profileName; for (int i = 1; i < configuration.profiles.getProfileCount(); i++) { - ProfilePackageIndexFrameWriter.generate(configuration, Profile.lookup(i).name); + profileName = Profile.lookup(i).name; + // Generate profile package pages only if there are any packages + // in a profile to be documented. The profilePackages map will not + // contain an entry for the profile if there are no packages to be documented. + if (!configuration.shouldDocumentProfile(profileName)) + continue; + ProfilePackageIndexFrameWriter.generate(configuration, profileName); PackageDoc[] packages = configuration.profilePackages.get( - Profile.lookup(i).name); + profileName); PackageDoc prev = null, next; for (int j = 0; j < packages.length; j++) { // if -nodeprecated option is set and the package is marked as diff --git a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/PackageIndexWriter.java b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/PackageIndexWriter.java index 7a67b38d102..caf0e0976a6 100644 --- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/PackageIndexWriter.java +++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/PackageIndexWriter.java @@ -130,10 +130,14 @@ public class PackageIndexWriter extends AbstractPackageIndexWriter { String profileName; for (int i = 1; i < configuration.profiles.getProfileCount(); i++) { profileName = Profile.lookup(i).name; - Content profileLinkContent = getTargetProfileLink("classFrame", - new StringContent(profileName), profileName); - Content li = HtmlTree.LI(profileLinkContent); - ul.addContent(li); + // If the profile has valid packages to be documented, add it to the + // profiles list on overview-summary.html page. + if (configuration.shouldDocumentProfile(profileName)) { + Content profileLinkContent = getTargetProfileLink("classFrame", + new StringContent(profileName), profileName); + Content li = HtmlTree.LI(profileLinkContent); + ul.addContent(li); + } } profilesDiv.addContent(ul); Content div = HtmlTree.DIV(HtmlStyle.contentContainer, profilesDiv); diff --git a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/ProfileIndexFrameWriter.java b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/ProfileIndexFrameWriter.java index c7217cd5037..c5caa90a10c 100644 --- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/ProfileIndexFrameWriter.java +++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/ProfileIndexFrameWriter.java @@ -88,8 +88,13 @@ public class ProfileIndexFrameWriter extends AbstractProfileIndexWriter { Content div = HtmlTree.DIV(HtmlStyle.indexContainer, heading); HtmlTree ul = new HtmlTree(HtmlTag.UL); ul.setTitle(profilesLabel); + String profileName; for (int i = 1; i < profiles.getProfileCount(); i++) { - ul.addContent(getProfile(i)); + profileName = (Profile.lookup(i)).name; + // If the profile has valid packages to be documented, add it to the + // left-frame generated for profile index. + if (configuration.shouldDocumentProfile(profileName)) + ul.addContent(getProfile(profileName)); } div.addContent(ul); body.addContent(div); @@ -98,13 +103,12 @@ public class ProfileIndexFrameWriter extends AbstractProfileIndexWriter { /** * Gets each profile name as a separate link. * - * @param profile the profile being documented + * @param profileName the profile being documented * @return content for the profile link */ - protected Content getProfile(int profile) { + protected Content getProfile(String profileName) { Content profileLinkContent; Content profileLabel; - String profileName = (Profile.lookup(profile)).name; profileLabel = new StringContent(profileName); profileLinkContent = getHyperLink(DocPaths.profileFrame(profileName), profileLabel, "", "packageListFrame"); diff --git a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/ProfileWriterImpl.java b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/ProfileWriterImpl.java index 5dae2e944a4..ebe8b0d1e69 100644 --- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/ProfileWriterImpl.java +++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/ProfileWriterImpl.java @@ -138,6 +138,7 @@ public class ProfileWriterImpl extends HtmlDocletWriter "classFrame", new StringContent(pkg.name()), profile.name); Content heading = HtmlTree.HEADING(HtmlTag.H3, pkgName); HtmlTree li = HtmlTree.LI(HtmlStyle.blockList, heading); + addPackageDeprecationInfo(li, pkg); return li; } @@ -174,6 +175,30 @@ public class ProfileWriterImpl extends HtmlDocletWriter true, contentTree); } + /** + * Add the profile package deprecation information to the documentation tree. + * + * @param li the content tree to which the deprecation information will be added + * @param pkg the PackageDoc that is added + */ + public void addPackageDeprecationInfo(Content li, PackageDoc pkg) { + Tag[] deprs; + if (Util.isDeprecated(pkg)) { + deprs = pkg.tags("deprecated"); + HtmlTree deprDiv = new HtmlTree(HtmlTag.DIV); + deprDiv.addStyle(HtmlStyle.deprecatedContent); + Content deprPhrase = HtmlTree.SPAN(HtmlStyle.strong, deprecatedPhrase); + deprDiv.addContent(deprPhrase); + if (deprs.length > 0) { + Tag[] commentTags = deprs[0].inlineTags(); + if (commentTags.length > 0) { + addInlineDeprecatedComment(pkg, deprs[0], deprDiv); + } + } + li.addContent(deprDiv); + } + } + /** * Get "PREV PROFILE" link in the navigation bar. * diff --git a/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java b/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java index 0337840d248..940f1c91294 100644 --- a/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java +++ b/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java @@ -396,6 +396,9 @@ public abstract class Configuration { interimResults.put(p, new ArrayList()); for (PackageDoc pkg: packages) { + if (nodeprecated && Util.isDeprecated(pkg)) { + continue; + } // the getProfile method takes a type name, not a package name, // but isn't particularly fussy about the simple name -- so just use * int i = profiles.getProfile(pkg.name().replace(".", "/") + "/*"); @@ -409,12 +412,17 @@ public abstract class Configuration { // Build the profilePackages structure used by the doclet profilePackages = new HashMap(); List prev = Collections.emptyList(); + int size; for (Map.Entry> e: interimResults.entrySet()) { Profile p = e.getKey(); List pkgs = e.getValue(); pkgs.addAll(prev); // each profile contains all lower profiles Collections.sort(pkgs); - profilePackages.put(p.name, pkgs.toArray(new PackageDoc[pkgs.size()])); + size = pkgs.size(); + // For a profile, if there are no packages to be documented, do not add + // it to profilePackages map. + if (size > 0) + profilePackages.put(p.name, pkgs.toArray(new PackageDoc[pkgs.size()])); prev = pkgs; } @@ -718,6 +726,17 @@ public abstract class Configuration { return true; } + /** + * Check the validity of the given profile. Return false if there are no + * valid packages to be documented for the profile. + * + * @param profileName the profile that needs to be validated. + * @return true if the profile has valid packages to be documented. + */ + public boolean shouldDocumentProfile(String profileName) { + return profilePackages.containsKey(profileName); + } + /** * Check the validity of the given Source or Output File encoding on this * platform. diff --git a/langtools/test/com/sun/javadoc/testProfiles/TestProfilesConfiguration.java b/langtools/test/com/sun/javadoc/testProfiles/TestProfilesConfiguration.java index 140728e1ac5..287cca02952 100644 --- a/langtools/test/com/sun/javadoc/testProfiles/TestProfilesConfiguration.java +++ b/langtools/test/com/sun/javadoc/testProfiles/TestProfilesConfiguration.java @@ -23,7 +23,7 @@ /* * @test - * @bug 8006124 8009684 8015663 + * @bug 8006124 8009684 8015663 8015496 * @summary Test javadoc options support for profiles. * @author Evgeniya Stepanova * @library ../lib/ @@ -35,6 +35,7 @@ public class TestProfilesConfiguration extends JavadocTester { //Test information. private static final String BUG_ID = "8006124-8009684"; private static final String PROFILE_CONFIGURATION_BUG_ID = BUG_ID + "-3"; + private static final String NODEPR_NOPKGS_BUG_ID = BUG_ID + "-4"; //Javadoc arguments. private static final String[] ARGS3 = new String[]{ "-d", PROFILE_CONFIGURATION_BUG_ID, "-sourcepath", SRC_DIR, "-nocomment", @@ -42,6 +43,30 @@ public class TestProfilesConfiguration extends JavadocTester { "-doctitle", "Simple doctitle", "-use", "pkg3", "pkg1", "pkg2", "pkg4", "pkg5", "-packagesheader", "Simple packages header","pkgDeprecated" }; + private static final String[] ARGS4 = new String[]{ + "-d", NODEPR_NOPKGS_BUG_ID, "-sourcepath", SRC_DIR, "-nocomment", "-nodeprecated", + "-keywords", "-Xprofilespath", SRC_DIR + FS + "profile-rtjar-includes-nopkgs.txt", + "-doctitle", "Simple doctitle", "-use", "-packagesheader", "Simple packages header", + "pkg1", "pkg2", "pkg3", "pkg4", "pkg5", "pkgDeprecated" + }; + private static final String[][] NODEPR_NOPKGS_TEST = { + {NODEPR_NOPKGS_BUG_ID + FS + "overview-summary.html", + "" + }, + {NODEPR_NOPKGS_BUG_ID + FS + "profile-overview-frame.html", + "" + } + }; + private static final String[][] NODEPR_NOPKGS_NEGATED_TEST = { + {NODEPR_NOPKGS_BUG_ID + FS + "overview-summary.html", + "compact1" + } + }; + private static final String[][] PROFILES_CONFIGURATION_TEST = { //-use option test string fo profile view page {PROFILE_CONFIGURATION_BUG_ID + FS + "compact1-summary.html","
  • Use
  • " @@ -57,6 +82,12 @@ public class TestProfilesConfiguration extends JavadocTester { //-keywords option test string for profiles {PROFILE_CONFIGURATION_BUG_ID + FS + "compact1-summary.html", "" + }, + //Deprecated information on a package + {PROFILE_CONFIGURATION_BUG_ID + FS + "compact1-summary.html", + "

    pkgDeprecated

    " + NL + "
    " + + "Deprecated.
    " } }; private static final String[][] PROFILES_CONFIGURATION_NEGATED_TEST = { @@ -75,6 +106,8 @@ public class TestProfilesConfiguration extends JavadocTester { TestProfilesConfiguration tester = new TestProfilesConfiguration(); run(tester, ARGS3, PROFILES_CONFIGURATION_TEST, PROFILES_CONFIGURATION_NEGATED_TEST); + run(tester, ARGS4, NODEPR_NOPKGS_TEST, + NODEPR_NOPKGS_NEGATED_TEST); tester.printSummary(); } diff --git a/langtools/test/com/sun/javadoc/testProfiles/profile-rtjar-includes-nopkgs.txt b/langtools/test/com/sun/javadoc/testProfiles/profile-rtjar-includes-nopkgs.txt new file mode 100644 index 00000000000..c63a4e85214 --- /dev/null +++ b/langtools/test/com/sun/javadoc/testProfiles/profile-rtjar-includes-nopkgs.txt @@ -0,0 +1,41 @@ +PROFILE_1_RTJAR_INCLUDE_PACKAGES := + +PROFILE_1_RTJAR_INCLUDE_TYPES := + +PROFILE_1_RTJAR_EXCLUDE_TYPES := + +PROFILE_1_INCLUDE_METAINF_SERVICES := + + +PROFILE_2_RTJAR_INCLUDE_PACKAGES := \ + pkg4 \ + pkgDeprecated + +PROFILE_2_RTJAR_INCLUDE_TYPES := + +PROFILE_2_RTJAR_EXCLUDE_TYPES := \ + pkg4/Anno1Pkg4.class + +PROFILE_2_INCLUDE_METAINF_SERVICES := + + +PROFILE_3_RTJAR_INCLUDE_PACKAGES := \ + pkg5 + +PROFILE_3_RTJAR_INCLUDE_TYPES := + +PROFILE_3_RTJAR_EXCLUDE_TYPES := + +PROFILE_3_INCLUDE_METAINF_SERVICES := + + +PROFILE_4_RTJAR_INCLUDE_PACKAGES := \ + pkg1 + +PROFILE_4_RTJAR_INCLUDE_TYPES := + +PROFILE_4_RTJAR_EXCLUDE_TYPES := + +PROFILE_4_INCLUDE_METAINF_SERVICES := + + From 091edb47c5295609b2b64ef32e7075d2008b656d Mon Sep 17 00:00:00 2001 From: Bill Pittore Date: Wed, 11 Sep 2013 20:03:34 -0400 Subject: [PATCH 127/210] 8024007: Misc. cleanup of static agent code Minor cleanup of static agent code from 8014135 Reviewed-by: dcubed, sspitsyn --- hotspot/src/os/windows/vm/os_windows.cpp | 2 +- hotspot/src/share/vm/prims/jvmti.xml | 6 ++++-- hotspot/src/share/vm/runtime/arguments.hpp | 2 +- hotspot/src/share/vm/runtime/os.cpp | 5 +++-- hotspot/src/share/vm/runtime/thread.cpp | 2 +- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/hotspot/src/os/windows/vm/os_windows.cpp b/hotspot/src/os/windows/vm/os_windows.cpp index 015f94d6662..d6dbde4c929 100644 --- a/hotspot/src/os/windows/vm/os_windows.cpp +++ b/hotspot/src/os/windows/vm/os_windows.cpp @@ -5429,7 +5429,7 @@ char* os::build_agent_function_name(const char *sym_name, const char *lib_name, if ((start = strrchr(lib_name, *os::file_separator())) != NULL) { lib_name = ++start; } else { - // Need to check for C: + // Need to check for drive prefix if ((start = strchr(lib_name, ':')) != NULL) { lib_name = ++start; } diff --git a/hotspot/src/share/vm/prims/jvmti.xml b/hotspot/src/share/vm/prims/jvmti.xml index 87a28ae0cfc..98a0a0640aa 100644 --- a/hotspot/src/share/vm/prims/jvmti.xml +++ b/hotspot/src/share/vm/prims/jvmti.xml @@ -458,8 +458,10 @@ the same name from being loaded dynamically.

    The VM will invoke the Agent_OnUnload_L function of the agent, if such - a function is exported, at the same point during startup as it would - have called the dynamic entry point Agent_OnUnLoad. + a function is exported, at the same point during VM execution as it would + have called the dynamic entry point Agent_OnUnLoad. A statically loaded + agent cannot be unloaded. The Agent_OnUnload_L function will still be + called to do any other agent shutdown related tasks. If a statically linked agent L exports a function called Agent_OnUnLoad_L and a function called Agent_OnUnLoad, the Agent_OnUnLoad function will be ignored. diff --git a/hotspot/src/share/vm/runtime/arguments.hpp b/hotspot/src/share/vm/runtime/arguments.hpp index 43256b75082..6b8eb305aae 100644 --- a/hotspot/src/share/vm/runtime/arguments.hpp +++ b/hotspot/src/share/vm/runtime/arguments.hpp @@ -144,7 +144,7 @@ public: void set_os_lib(void* os_lib) { _os_lib = os_lib; } AgentLibrary* next() const { return _next; } bool is_static_lib() const { return _is_static_lib; } - void set_static_lib(bool static_lib) { _is_static_lib = static_lib; } + void set_static_lib(bool is_static_lib) { _is_static_lib = is_static_lib; } bool valid() { return (_state == agent_valid); } void set_valid() { _state = agent_valid; } void set_invalid() { _state = agent_invalid; } diff --git a/hotspot/src/share/vm/runtime/os.cpp b/hotspot/src/share/vm/runtime/os.cpp index 0c83565195c..f85f1237f14 100644 --- a/hotspot/src/share/vm/runtime/os.cpp +++ b/hotspot/src/share/vm/runtime/os.cpp @@ -454,6 +454,7 @@ void* os::native_java_library() { */ void* os::find_agent_function(AgentLibrary *agent_lib, bool check_lib, const char *syms[], size_t syms_len) { + assert(agent_lib != NULL, "sanity check"); const char *lib_name; void *handle = agent_lib->os_lib(); void *entryName = NULL; @@ -484,6 +485,7 @@ bool os::find_builtin_agent(AgentLibrary *agent_lib, const char *syms[], void *proc_handle; void *save_handle; + assert(agent_lib != NULL, "sanity check"); if (agent_lib->name() == NULL) { return false; } @@ -493,14 +495,13 @@ bool os::find_builtin_agent(AgentLibrary *agent_lib, const char *syms[], // We want to look in this process' symbol table. agent_lib->set_os_lib(proc_handle); ret = find_agent_function(agent_lib, true, syms, syms_len); - agent_lib->set_os_lib(save_handle); if (ret != NULL) { // Found an entry point like Agent_OnLoad_lib_name so we have a static agent - agent_lib->set_os_lib(proc_handle); agent_lib->set_valid(); agent_lib->set_static_lib(true); return true; } + agent_lib->set_os_lib(save_handle); return false; } diff --git a/hotspot/src/share/vm/runtime/thread.cpp b/hotspot/src/share/vm/runtime/thread.cpp index d5bc3a00006..2745703b598 100644 --- a/hotspot/src/share/vm/runtime/thread.cpp +++ b/hotspot/src/share/vm/runtime/thread.cpp @@ -3714,7 +3714,7 @@ static OnLoadEntry_t lookup_on_load(AgentLibrary* agent, const char *on_load_sym const char *name = agent->name(); const char *msg = "Could not find agent library "; - // First check to see if agent is statcally linked into executable + // First check to see if agent is statically linked into executable if (os::find_builtin_agent(agent, on_load_symbols, num_symbol_entries)) { library = agent->os_lib(); } else if (agent->is_absolute_path()) { From dfd2d9a574dc868c3a9bd0515e61b04873b358f3 Mon Sep 17 00:00:00 2001 From: Erik Helin Date: Thu, 12 Sep 2013 10:15:30 +0200 Subject: [PATCH 128/210] 8023476: Metaspace capacity > reserved Reviewed-by: stefank, hseigel, mgerdin --- .../share/vm/gc_interface/collectedHeap.cpp | 6 +- hotspot/src/share/vm/memory/metaspace.cpp | 85 +++++++++++-------- hotspot/src/share/vm/memory/metaspace.hpp | 58 ++++--------- .../src/share/vm/memory/metaspaceCounters.cpp | 16 ++-- 4 files changed, 80 insertions(+), 85 deletions(-) diff --git a/hotspot/src/share/vm/gc_interface/collectedHeap.cpp b/hotspot/src/share/vm/gc_interface/collectedHeap.cpp index 3af380049bb..3f5364b79c0 100644 --- a/hotspot/src/share/vm/gc_interface/collectedHeap.cpp +++ b/hotspot/src/share/vm/gc_interface/collectedHeap.cpp @@ -87,15 +87,15 @@ MetaspaceSummary CollectedHeap::create_metaspace_summary() { const MetaspaceSizes meta_space( MetaspaceAux::allocated_capacity_bytes(), MetaspaceAux::allocated_used_bytes(), - MetaspaceAux::reserved_in_bytes()); + MetaspaceAux::reserved_bytes()); const MetaspaceSizes data_space( MetaspaceAux::allocated_capacity_bytes(Metaspace::NonClassType), MetaspaceAux::allocated_used_bytes(Metaspace::NonClassType), - MetaspaceAux::reserved_in_bytes(Metaspace::NonClassType)); + MetaspaceAux::reserved_bytes(Metaspace::NonClassType)); const MetaspaceSizes class_space( MetaspaceAux::allocated_capacity_bytes(Metaspace::ClassType), MetaspaceAux::allocated_used_bytes(Metaspace::ClassType), - MetaspaceAux::reserved_in_bytes(Metaspace::ClassType)); + MetaspaceAux::reserved_bytes(Metaspace::ClassType)); return MetaspaceSummary(meta_space, data_space, class_space); } diff --git a/hotspot/src/share/vm/memory/metaspace.cpp b/hotspot/src/share/vm/memory/metaspace.cpp index 63e6be716da..e8117f7fae9 100644 --- a/hotspot/src/share/vm/memory/metaspace.cpp +++ b/hotspot/src/share/vm/memory/metaspace.cpp @@ -177,8 +177,8 @@ class ChunkManager VALUE_OBJ_CLASS_SPEC { void return_chunks(ChunkIndex index, Metachunk* chunks); // Total of the space in the free chunks list - size_t free_chunks_total(); - size_t free_chunks_total_in_bytes(); + size_t free_chunks_total_words(); + size_t free_chunks_total_bytes(); // Number of chunks in the free chunks list size_t free_chunks_count(); @@ -1080,12 +1080,12 @@ size_t VirtualSpaceList::used_words_sum() { // Sum used region [bottom, top) in each virtualspace allocated_by_vs += vsl->used_words_in_vs(); } - assert(allocated_by_vs >= chunk_manager()->free_chunks_total(), + assert(allocated_by_vs >= chunk_manager()->free_chunks_total_words(), err_msg("Total in free chunks " SIZE_FORMAT " greater than total from virtual_spaces " SIZE_FORMAT, - allocated_by_vs, chunk_manager()->free_chunks_total())); + allocated_by_vs, chunk_manager()->free_chunks_total_words())); size_t used = - allocated_by_vs - chunk_manager()->free_chunks_total(); + allocated_by_vs - chunk_manager()->free_chunks_total_words(); return used; } @@ -1526,7 +1526,7 @@ void Metadebug::deallocate_chunk_a_lot(SpaceManager* sm, sm->sum_count_in_chunks_in_use()); dummy_chunk->print_on(gclog_or_tty); gclog_or_tty->print_cr(" Free chunks total %d count %d", - vsl->chunk_manager()->free_chunks_total(), + vsl->chunk_manager()->free_chunks_total_words(), vsl->chunk_manager()->free_chunks_count()); } } @@ -1583,12 +1583,12 @@ bool Metadebug::test_metadata_failure() { // ChunkManager methods -size_t ChunkManager::free_chunks_total() { +size_t ChunkManager::free_chunks_total_words() { return _free_chunks_total; } -size_t ChunkManager::free_chunks_total_in_bytes() { - return free_chunks_total() * BytesPerWord; +size_t ChunkManager::free_chunks_total_bytes() { + return free_chunks_total_words() * BytesPerWord; } size_t ChunkManager::free_chunks_count() { @@ -2567,13 +2567,13 @@ size_t MetaspaceAux::used_bytes_slow(Metaspace::MetadataType mdtype) { return used * BytesPerWord; } -size_t MetaspaceAux::free_in_bytes(Metaspace::MetadataType mdtype) { +size_t MetaspaceAux::free_bytes_slow(Metaspace::MetadataType mdtype) { size_t free = 0; ClassLoaderDataGraphMetaspaceIterator iter; while (iter.repeat()) { Metaspace* msp = iter.get_next(); if (msp != NULL) { - free += msp->free_words(mdtype); + free += msp->free_words_slow(mdtype); } } return free * BytesPerWord; @@ -2596,34 +2596,51 @@ size_t MetaspaceAux::capacity_bytes_slow(Metaspace::MetadataType mdtype) { return capacity * BytesPerWord; } -size_t MetaspaceAux::reserved_in_bytes(Metaspace::MetadataType mdtype) { - VirtualSpaceList* list = Metaspace::get_space_list(mdtype); - return list == NULL ? 0 : list->virtual_space_total(); +size_t MetaspaceAux::capacity_bytes_slow() { +#ifdef PRODUCT + // Use allocated_capacity_bytes() in PRODUCT instead of this function. + guarantee(false, "Should not call capacity_bytes_slow() in the PRODUCT"); +#endif + size_t class_capacity = capacity_bytes_slow(Metaspace::ClassType); + size_t non_class_capacity = capacity_bytes_slow(Metaspace::NonClassType); + assert(allocated_capacity_bytes() == class_capacity + non_class_capacity, + err_msg("bad accounting: allocated_capacity_bytes() " SIZE_FORMAT + " class_capacity + non_class_capacity " SIZE_FORMAT + " class_capacity " SIZE_FORMAT " non_class_capacity " SIZE_FORMAT, + allocated_capacity_bytes(), class_capacity + non_class_capacity, + class_capacity, non_class_capacity)); + + return class_capacity + non_class_capacity; } -size_t MetaspaceAux::min_chunk_size() { return Metaspace::first_chunk_word_size(); } +size_t MetaspaceAux::reserved_bytes(Metaspace::MetadataType mdtype) { + VirtualSpaceList* list = Metaspace::get_space_list(mdtype); + return list == NULL ? 0 : list->virtual_space_total() * BytesPerWord; +} -size_t MetaspaceAux::free_chunks_total(Metaspace::MetadataType mdtype) { +size_t MetaspaceAux::min_chunk_size_words() { return Metaspace::first_chunk_word_size(); } + +size_t MetaspaceAux::free_chunks_total_words(Metaspace::MetadataType mdtype) { VirtualSpaceList* list = Metaspace::get_space_list(mdtype); if (list == NULL) { return 0; } ChunkManager* chunk = list->chunk_manager(); chunk->slow_verify(); - return chunk->free_chunks_total(); + return chunk->free_chunks_total_words(); } -size_t MetaspaceAux::free_chunks_total_in_bytes(Metaspace::MetadataType mdtype) { - return free_chunks_total(mdtype) * BytesPerWord; +size_t MetaspaceAux::free_chunks_total_bytes(Metaspace::MetadataType mdtype) { + return free_chunks_total_words(mdtype) * BytesPerWord; } -size_t MetaspaceAux::free_chunks_total() { - return free_chunks_total(Metaspace::ClassType) + - free_chunks_total(Metaspace::NonClassType); +size_t MetaspaceAux::free_chunks_total_words() { + return free_chunks_total_words(Metaspace::ClassType) + + free_chunks_total_words(Metaspace::NonClassType); } -size_t MetaspaceAux::free_chunks_total_in_bytes() { - return free_chunks_total() * BytesPerWord; +size_t MetaspaceAux::free_chunks_total_bytes() { + return free_chunks_total_words() * BytesPerWord; } void MetaspaceAux::print_metaspace_change(size_t prev_metadata_used) { @@ -2634,14 +2651,14 @@ void MetaspaceAux::print_metaspace_change(size_t prev_metadata_used) { "(" SIZE_FORMAT ")", prev_metadata_used, allocated_used_bytes(), - reserved_in_bytes()); + reserved_bytes()); } else { gclog_or_tty->print(" " SIZE_FORMAT "K" "->" SIZE_FORMAT "K" "(" SIZE_FORMAT "K)", - prev_metadata_used / K, - allocated_used_bytes() / K, - reserved_in_bytes()/ K); + prev_metadata_used/K, + allocated_used_bytes()/K, + reserved_bytes()/K); } gclog_or_tty->print("]"); @@ -2654,14 +2671,14 @@ void MetaspaceAux::print_on(outputStream* out) { out->print_cr(" Metaspace total " SIZE_FORMAT "K, used " SIZE_FORMAT "K," " reserved " SIZE_FORMAT "K", - allocated_capacity_bytes()/K, allocated_used_bytes()/K, reserved_in_bytes()/K); + allocated_capacity_bytes()/K, allocated_used_bytes()/K, reserved_bytes()/K); out->print_cr(" data space " SIZE_FORMAT "K, used " SIZE_FORMAT "K," " reserved " SIZE_FORMAT "K", allocated_capacity_bytes(nct)/K, allocated_used_bytes(nct)/K, - reserved_in_bytes(nct)/K); + reserved_bytes(nct)/K); if (Metaspace::using_class_space()) { Metaspace::MetadataType ct = Metaspace::ClassType; out->print_cr(" class space " @@ -2669,17 +2686,17 @@ void MetaspaceAux::print_on(outputStream* out) { " reserved " SIZE_FORMAT "K", allocated_capacity_bytes(ct)/K, allocated_used_bytes(ct)/K, - reserved_in_bytes(ct)/K); + reserved_bytes(ct)/K); } } // Print information for class space and data space separately. // This is almost the same as above. void MetaspaceAux::print_on(outputStream* out, Metaspace::MetadataType mdtype) { - size_t free_chunks_capacity_bytes = free_chunks_total_in_bytes(mdtype); + size_t free_chunks_capacity_bytes = free_chunks_total_bytes(mdtype); size_t capacity_bytes = capacity_bytes_slow(mdtype); size_t used_bytes = used_bytes_slow(mdtype); - size_t free_bytes = free_in_bytes(mdtype); + size_t free_bytes = free_bytes_slow(mdtype); size_t used_and_free = used_bytes + free_bytes + free_chunks_capacity_bytes; out->print_cr(" Chunk accounting: used in chunks " SIZE_FORMAT @@ -3132,7 +3149,7 @@ size_t Metaspace::used_words_slow(MetadataType mdtype) const { } } -size_t Metaspace::free_words(MetadataType mdtype) const { +size_t Metaspace::free_words_slow(MetadataType mdtype) const { if (mdtype == ClassType) { return using_class_space() ? class_vsm()->sum_free_in_chunks_in_use() : 0; } else { diff --git a/hotspot/src/share/vm/memory/metaspace.hpp b/hotspot/src/share/vm/memory/metaspace.hpp index 591acf30075..b51c80be0e6 100644 --- a/hotspot/src/share/vm/memory/metaspace.hpp +++ b/hotspot/src/share/vm/memory/metaspace.hpp @@ -182,9 +182,8 @@ class Metaspace : public CHeapObj { char* bottom() const; size_t used_words_slow(MetadataType mdtype) const; - size_t free_words(MetadataType mdtype) const; + size_t free_words_slow(MetadataType mdtype) const; size_t capacity_words_slow(MetadataType mdtype) const; - size_t waste_words(MetadataType mdtype) const; size_t used_bytes_slow(MetadataType mdtype) const; size_t capacity_bytes_slow(MetadataType mdtype) const; @@ -221,19 +220,14 @@ class Metaspace : public CHeapObj { }; class MetaspaceAux : AllStatic { - static size_t free_chunks_total(Metaspace::MetadataType mdtype); - - public: - // Statistics for class space and data space in metaspace. + static size_t free_chunks_total_words(Metaspace::MetadataType mdtype); // These methods iterate over the classloader data graph // for the given Metaspace type. These are slow. static size_t used_bytes_slow(Metaspace::MetadataType mdtype); - static size_t free_in_bytes(Metaspace::MetadataType mdtype); + static size_t free_bytes_slow(Metaspace::MetadataType mdtype); static size_t capacity_bytes_slow(Metaspace::MetadataType mdtype); - - // Iterates over the virtual space list. - static size_t reserved_in_bytes(Metaspace::MetadataType mdtype); + static size_t capacity_bytes_slow(); // Running sum of space in all Metachunks that has been // allocated to a Metaspace. This is used instead of @@ -263,17 +257,16 @@ class MetaspaceAux : AllStatic { } // Used by MetaspaceCounters - static size_t free_chunks_total(); - static size_t free_chunks_total_in_bytes(); - static size_t free_chunks_total_in_bytes(Metaspace::MetadataType mdtype); + static size_t free_chunks_total_words(); + static size_t free_chunks_total_bytes(); + static size_t free_chunks_total_bytes(Metaspace::MetadataType mdtype); static size_t allocated_capacity_words(Metaspace::MetadataType mdtype) { return _allocated_capacity_words[mdtype]; } static size_t allocated_capacity_words() { - return _allocated_capacity_words[Metaspace::NonClassType] + - (Metaspace::using_class_space() ? - _allocated_capacity_words[Metaspace::ClassType] : 0); + return allocated_capacity_words(Metaspace::NonClassType) + + allocated_capacity_words(Metaspace::ClassType); } static size_t allocated_capacity_bytes(Metaspace::MetadataType mdtype) { return allocated_capacity_words(mdtype) * BytesPerWord; @@ -286,9 +279,8 @@ class MetaspaceAux : AllStatic { return _allocated_used_words[mdtype]; } static size_t allocated_used_words() { - return _allocated_used_words[Metaspace::NonClassType] + - (Metaspace::using_class_space() ? - _allocated_used_words[Metaspace::ClassType] : 0); + return allocated_used_words(Metaspace::NonClassType) + + allocated_used_words(Metaspace::ClassType); } static size_t allocated_used_bytes(Metaspace::MetadataType mdtype) { return allocated_used_words(mdtype) * BytesPerWord; @@ -301,31 +293,17 @@ class MetaspaceAux : AllStatic { static size_t free_bytes(Metaspace::MetadataType mdtype); // Total capacity in all Metaspaces - static size_t capacity_bytes_slow() { -#ifdef PRODUCT - // Use allocated_capacity_bytes() in PRODUCT instead of this function. - guarantee(false, "Should not call capacity_bytes_slow() in the PRODUCT"); -#endif - size_t class_capacity = capacity_bytes_slow(Metaspace::ClassType); - size_t non_class_capacity = capacity_bytes_slow(Metaspace::NonClassType); - assert(allocated_capacity_bytes() == class_capacity + non_class_capacity, - err_msg("bad accounting: allocated_capacity_bytes() " SIZE_FORMAT - " class_capacity + non_class_capacity " SIZE_FORMAT - " class_capacity " SIZE_FORMAT " non_class_capacity " SIZE_FORMAT, - allocated_capacity_bytes(), class_capacity + non_class_capacity, - class_capacity, non_class_capacity)); - - return class_capacity + non_class_capacity; + static size_t reserved_bytes(Metaspace::MetadataType mdtype); + static size_t reserved_bytes() { + return reserved_bytes(Metaspace::ClassType) + + reserved_bytes(Metaspace::NonClassType); } - // Total space reserved in all Metaspaces - static size_t reserved_in_bytes() { - return reserved_in_bytes(Metaspace::ClassType) + - reserved_in_bytes(Metaspace::NonClassType); + static size_t min_chunk_size_words(); + static size_t min_chunk_size_bytes() { + return min_chunk_size_words() * BytesPerWord; } - static size_t min_chunk_size(); - // Print change in used metadata. static void print_metaspace_change(size_t prev_metadata_used); static void print_on(outputStream * out); diff --git a/hotspot/src/share/vm/memory/metaspaceCounters.cpp b/hotspot/src/share/vm/memory/metaspaceCounters.cpp index 32eda2b4ed8..6f443466ffb 100644 --- a/hotspot/src/share/vm/memory/metaspaceCounters.cpp +++ b/hotspot/src/share/vm/memory/metaspaceCounters.cpp @@ -71,7 +71,7 @@ size_t MetaspaceCounters::calculate_capacity() { // 2) unused space at the end of each Metachunk // 3) space in the freelist size_t total_capacity = MetaspaceAux::allocated_capacity_bytes() - + MetaspaceAux::free_bytes() + MetaspaceAux::free_chunks_total_in_bytes(); + + MetaspaceAux::free_bytes() + MetaspaceAux::free_chunks_total_bytes(); return total_capacity; } @@ -79,9 +79,9 @@ void MetaspaceCounters::initialize_performance_counters() { if (UsePerfData) { assert(_perf_counters == NULL, "Should only be initialized once"); - size_t min_capacity = MetaspaceAux::min_chunk_size(); + size_t min_capacity = MetaspaceAux::min_chunk_size_bytes(); size_t capacity = calculate_capacity(); - size_t max_capacity = MetaspaceAux::reserved_in_bytes(); + size_t max_capacity = MetaspaceAux::reserved_bytes(); size_t used = MetaspaceAux::allocated_used_bytes(); _perf_counters = new MetaspacePerfCounters("metaspace", min_capacity, capacity, max_capacity, used); @@ -93,7 +93,7 @@ void MetaspaceCounters::update_performance_counters() { assert(_perf_counters != NULL, "Should be initialized"); size_t capacity = calculate_capacity(); - size_t max_capacity = MetaspaceAux::reserved_in_bytes(); + size_t max_capacity = MetaspaceAux::reserved_bytes(); size_t used = MetaspaceAux::allocated_used_bytes(); _perf_counters->update(capacity, max_capacity, used); @@ -105,7 +105,7 @@ MetaspacePerfCounters* CompressedClassSpaceCounters::_perf_counters = NULL; size_t CompressedClassSpaceCounters::calculate_capacity() { return MetaspaceAux::allocated_capacity_bytes(_class_type) + MetaspaceAux::free_bytes(_class_type) + - MetaspaceAux::free_chunks_total_in_bytes(_class_type); + MetaspaceAux::free_chunks_total_bytes(_class_type); } void CompressedClassSpaceCounters::update_performance_counters() { @@ -113,7 +113,7 @@ void CompressedClassSpaceCounters::update_performance_counters() { assert(_perf_counters != NULL, "Should be initialized"); size_t capacity = calculate_capacity(); - size_t max_capacity = MetaspaceAux::reserved_in_bytes(_class_type); + size_t max_capacity = MetaspaceAux::reserved_bytes(_class_type); size_t used = MetaspaceAux::allocated_used_bytes(_class_type); _perf_counters->update(capacity, max_capacity, used); @@ -126,9 +126,9 @@ void CompressedClassSpaceCounters::initialize_performance_counters() { const char* ns = "compressedclassspace"; if (UseCompressedClassPointers) { - size_t min_capacity = MetaspaceAux::min_chunk_size(); + size_t min_capacity = MetaspaceAux::min_chunk_size_bytes(); size_t capacity = calculate_capacity(); - size_t max_capacity = MetaspaceAux::reserved_in_bytes(_class_type); + size_t max_capacity = MetaspaceAux::reserved_bytes(_class_type); size_t used = MetaspaceAux::allocated_used_bytes(_class_type); _perf_counters = new MetaspacePerfCounters(ns, min_capacity, capacity, max_capacity, used); From 8a515de48c15b44fbbe2abef6bc50b4391d93788 Mon Sep 17 00:00:00 2001 From: Stefan Karlsson Date: Thu, 12 Sep 2013 10:15:54 +0200 Subject: [PATCH 129/210] 8024638: Count and expose the amount of committed memory in the metaspaces Reviewed-by: brutisso, ehelin --- hotspot/src/share/vm/memory/metaspace.cpp | 182 +++++++++++++----- hotspot/src/share/vm/memory/metaspace.hpp | 7 +- hotspot/src/share/vm/prims/jni.cpp | 4 + hotspot/src/share/vm/runtime/virtualspace.cpp | 139 +++++++++++++ hotspot/src/share/vm/runtime/virtualspace.hpp | 13 +- 5 files changed, 289 insertions(+), 56 deletions(-) diff --git a/hotspot/src/share/vm/memory/metaspace.cpp b/hotspot/src/share/vm/memory/metaspace.cpp index e8117f7fae9..1dd97842eb4 100644 --- a/hotspot/src/share/vm/memory/metaspace.cpp +++ b/hotspot/src/share/vm/memory/metaspace.cpp @@ -291,6 +291,10 @@ class VirtualSpaceNode : public CHeapObj { MetaWord* bottom() const { return (MetaWord*) _virtual_space.low(); } MetaWord* end() const { return (MetaWord*) _virtual_space.high(); } + size_t reserved_words() const { return _virtual_space.reserved_size() / BytesPerWord; } + size_t expanded_words() const { return _virtual_space.committed_size() / BytesPerWord; } + size_t committed_words() const { return _virtual_space.actual_committed_size() / BytesPerWord; } + // address of next available space in _virtual_space; // Accessors VirtualSpaceNode* next() { return _next; } @@ -327,12 +331,10 @@ class VirtualSpaceNode : public CHeapObj { // Allocate a chunk from the virtual space and return it. Metachunk* get_chunk_vs(size_t chunk_word_size); - Metachunk* get_chunk_vs_with_expand(size_t chunk_word_size); // Expands/shrinks the committed space in a virtual space. Delegates // to Virtualspace bool expand_by(size_t words, bool pre_touch = false); - bool shrink_by(size_t words); // In preparation for deleting this node, remove all the chunks // in the node from any freelist. @@ -340,8 +342,6 @@ class VirtualSpaceNode : public CHeapObj { #ifdef ASSERT // Debug support - static void verify_virtual_space_total(); - static void verify_virtual_space_count(); void mangle(); #endif @@ -429,8 +429,11 @@ class VirtualSpaceList : public CHeapObj { bool _is_class; bool can_grow() const { return !is_class() || !UseCompressedClassPointers; } - // Sum of space in all virtual spaces and number of virtual spaces - size_t _virtual_space_total; + // Sum of reserved and committed memory in the virtual spaces + size_t _reserved_words; + size_t _committed_words; + + // Number of virtual spaces size_t _virtual_space_count; ~VirtualSpaceList(); @@ -444,7 +447,7 @@ class VirtualSpaceList : public CHeapObj { _current_virtual_space = v; } - void link_vs(VirtualSpaceNode* new_entry, size_t vs_word_size); + void link_vs(VirtualSpaceNode* new_entry); // Get another virtual space and add it to the list. This // is typically prompted by a failed attempt to allocate a chunk @@ -461,6 +464,8 @@ class VirtualSpaceList : public CHeapObj { size_t grow_chunks_by_words, size_t medium_chunk_bunch); + bool expand_by(VirtualSpaceNode* node, size_t word_size, bool pre_touch = false); + // Get the first chunk for a Metaspace. Used for // special cases such as the boot class loader, reflection // class loader and anonymous class loader. @@ -476,10 +481,15 @@ class VirtualSpaceList : public CHeapObj { // Allocate the first virtualspace. void initialize(size_t word_size); - size_t virtual_space_total() { return _virtual_space_total; } + size_t reserved_words() { return _reserved_words; } + size_t reserved_bytes() { return reserved_words() * BytesPerWord; } + size_t committed_words() { return _committed_words; } + size_t committed_bytes() { return committed_words() * BytesPerWord; } - void inc_virtual_space_total(size_t v); - void dec_virtual_space_total(size_t v); + void inc_reserved_words(size_t v); + void dec_reserved_words(size_t v); + void inc_committed_words(size_t v); + void dec_committed_words(size_t v); void inc_virtual_space_count(); void dec_virtual_space_count(); @@ -901,15 +911,6 @@ bool VirtualSpaceNode::expand_by(size_t words, bool pre_touch) { return result; } -// Shrink the virtual space (commit more of the reserved space) -bool VirtualSpaceNode::shrink_by(size_t words) { - size_t bytes = words * BytesPerWord; - virtual_space()->shrink_by(bytes); - return true; -} - -// Add another chunk to the chunk list. - Metachunk* VirtualSpaceNode::get_chunk_vs(size_t chunk_word_size) { assert_lock_strong(SpaceManager::expand_lock()); Metachunk* result = take_from_committed(chunk_word_size); @@ -919,23 +920,6 @@ Metachunk* VirtualSpaceNode::get_chunk_vs(size_t chunk_word_size) { return result; } -Metachunk* VirtualSpaceNode::get_chunk_vs_with_expand(size_t chunk_word_size) { - assert_lock_strong(SpaceManager::expand_lock()); - - Metachunk* new_chunk = get_chunk_vs(chunk_word_size); - - if (new_chunk == NULL) { - // Only a small part of the virtualspace is committed when first - // allocated so committing more here can be expected. - size_t page_size_words = os::vm_page_size() / BytesPerWord; - size_t aligned_expand_vs_by_words = align_size_up(chunk_word_size, - page_size_words); - expand_by(aligned_expand_vs_by_words, false); - new_chunk = get_chunk_vs(chunk_word_size); - } - return new_chunk; -} - bool VirtualSpaceNode::initialize() { if (!_rs.is_reserved()) { @@ -995,13 +979,22 @@ VirtualSpaceList::~VirtualSpaceList() { } } -void VirtualSpaceList::inc_virtual_space_total(size_t v) { +void VirtualSpaceList::inc_reserved_words(size_t v) { assert_lock_strong(SpaceManager::expand_lock()); - _virtual_space_total = _virtual_space_total + v; + _reserved_words = _reserved_words + v; } -void VirtualSpaceList::dec_virtual_space_total(size_t v) { +void VirtualSpaceList::dec_reserved_words(size_t v) { assert_lock_strong(SpaceManager::expand_lock()); - _virtual_space_total = _virtual_space_total - v; + _reserved_words = _reserved_words - v; +} + +void VirtualSpaceList::inc_committed_words(size_t v) { + assert_lock_strong(SpaceManager::expand_lock()); + _committed_words = _committed_words + v; +} +void VirtualSpaceList::dec_committed_words(size_t v) { + assert_lock_strong(SpaceManager::expand_lock()); + _committed_words = _committed_words - v; } void VirtualSpaceList::inc_virtual_space_count() { @@ -1052,7 +1045,8 @@ void VirtualSpaceList::purge() { } vsl->purge(chunk_manager()); - dec_virtual_space_total(vsl->reserved()->word_size()); + dec_reserved_words(vsl->reserved_words()); + dec_committed_words(vsl->committed_words()); dec_virtual_space_count(); purged_vsl = vsl; delete vsl; @@ -1106,7 +1100,8 @@ VirtualSpaceList::VirtualSpaceList(size_t word_size ) : _is_class(false), _virtual_space_list(NULL), _current_virtual_space(NULL), - _virtual_space_total(0), + _reserved_words(0), + _committed_words(0), _virtual_space_count(0) { MutexLockerEx cl(SpaceManager::expand_lock(), Mutex::_no_safepoint_check_flag); @@ -1123,7 +1118,8 @@ VirtualSpaceList::VirtualSpaceList(ReservedSpace rs) : _is_class(true), _virtual_space_list(NULL), _current_virtual_space(NULL), - _virtual_space_total(0), + _reserved_words(0), + _committed_words(0), _virtual_space_count(0) { MutexLockerEx cl(SpaceManager::expand_lock(), Mutex::_no_safepoint_check_flag); @@ -1133,7 +1129,7 @@ VirtualSpaceList::VirtualSpaceList(ReservedSpace rs) : _chunk_manager.free_chunks(SmallIndex)->set_size(ClassSmallChunk); _chunk_manager.free_chunks(MediumIndex)->set_size(ClassMediumChunk); assert(succeeded, " VirtualSpaceList initialization should not fail"); - link_vs(class_entry, rs.size()/BytesPerWord); + link_vs(class_entry); } size_t VirtualSpaceList::free_bytes() { @@ -1156,21 +1152,23 @@ bool VirtualSpaceList::grow_vs(size_t vs_word_size) { delete new_entry; return false; } else { + assert(new_entry->reserved_words() == vs_word_size, "Must be"); // ensure lock-free iteration sees fully initialized node OrderAccess::storestore(); - link_vs(new_entry, vs_word_size); + link_vs(new_entry); return true; } } -void VirtualSpaceList::link_vs(VirtualSpaceNode* new_entry, size_t vs_word_size) { +void VirtualSpaceList::link_vs(VirtualSpaceNode* new_entry) { if (virtual_space_list() == NULL) { set_virtual_space_list(new_entry); } else { current_virtual_space()->set_next(new_entry); } set_current_virtual_space(new_entry); - inc_virtual_space_total(vs_word_size); + inc_reserved_words(new_entry->reserved_words()); + inc_committed_words(new_entry->committed_words()); inc_virtual_space_count(); #ifdef ASSERT new_entry->mangle(); @@ -1181,6 +1179,20 @@ void VirtualSpaceList::link_vs(VirtualSpaceNode* new_entry, size_t vs_word_size) } } +bool VirtualSpaceList::expand_by(VirtualSpaceNode* node, size_t word_size, bool pre_touch) { + size_t before = node->committed_words(); + + bool result = node->expand_by(word_size, pre_touch); + + size_t after = node->committed_words(); + + // after and before can be the same if the memory was pre-committed. + assert(after >= before, "Must be"); + inc_committed_words(after - before); + + return result; +} + Metachunk* VirtualSpaceList::get_new_chunk(size_t word_size, size_t grow_chunks_by_words, size_t medium_chunk_bunch) { @@ -1204,7 +1216,7 @@ Metachunk* VirtualSpaceList::get_new_chunk(size_t word_size, size_t aligned_expand_vs_by_words = align_size_up(expand_vs_by_words, page_size_words); bool vs_expanded = - current_virtual_space()->expand_by(aligned_expand_vs_by_words, false); + expand_by(current_virtual_space(), aligned_expand_vs_by_words); if (!vs_expanded) { // Should the capacity of the metaspaces be expanded for // this allocation? If it's the virtual space for classes and is @@ -1215,7 +1227,14 @@ Metachunk* VirtualSpaceList::get_new_chunk(size_t word_size, MAX2((size_t)VirtualSpaceSize, aligned_expand_vs_by_words); if (grow_vs(grow_vs_words)) { // Got it. It's on the list now. Get a chunk from it. - next = current_virtual_space()->get_chunk_vs_with_expand(grow_chunks_by_words); + assert(current_virtual_space()->expanded_words() == 0, + "New virtuals space nodes should not have expanded"); + + size_t grow_chunks_by_words_aligned = align_size_up(grow_chunks_by_words, + page_size_words); + // We probably want to expand by aligned_expand_vs_by_words here. + expand_by(current_virtual_space(), grow_chunks_by_words_aligned); + next = current_virtual_space()->get_chunk_vs(grow_chunks_by_words); } } else { // Allocation will fail and induce a GC @@ -1325,7 +1344,7 @@ bool MetaspaceGC::should_expand(VirtualSpaceList* vsl, size_t word_size) { // reserved space, because this is a larger space prereserved for compressed // class pointers. if (!FLAG_IS_DEFAULT(MaxMetaspaceSize)) { - size_t real_allocated = Metaspace::space_list()->virtual_space_total() + + size_t real_allocated = Metaspace::space_list()->reserved_words() + MetaspaceAux::allocated_capacity_bytes(Metaspace::ClassType); if (real_allocated >= MaxMetaspaceSize) { return false; @@ -2615,7 +2634,12 @@ size_t MetaspaceAux::capacity_bytes_slow() { size_t MetaspaceAux::reserved_bytes(Metaspace::MetadataType mdtype) { VirtualSpaceList* list = Metaspace::get_space_list(mdtype); - return list == NULL ? 0 : list->virtual_space_total() * BytesPerWord; + return list == NULL ? 0 : list->reserved_bytes(); +} + +size_t MetaspaceAux::committed_bytes(Metaspace::MetadataType mdtype) { + VirtualSpaceList* list = Metaspace::get_space_list(mdtype); + return list == NULL ? 0 : list->committed_bytes(); } size_t MetaspaceAux::min_chunk_size_words() { return Metaspace::first_chunk_word_size(); } @@ -3357,3 +3381,59 @@ void Metaspace::dump(outputStream* const out) const { class_vsm()->dump(out); } } + +/////////////// Unit tests /////////////// + +#ifndef PRODUCT + +class MetaspaceAuxTest : AllStatic { + public: + static void test_reserved() { + size_t reserved = MetaspaceAux::reserved_bytes(); + + assert(reserved > 0, "assert"); + + size_t committed = MetaspaceAux::committed_bytes(); + assert(committed <= reserved, "assert"); + + size_t reserved_metadata = MetaspaceAux::reserved_bytes(Metaspace::NonClassType); + assert(reserved_metadata > 0, "assert"); + assert(reserved_metadata <= reserved, "assert"); + + if (UseCompressedClassPointers) { + size_t reserved_class = MetaspaceAux::reserved_bytes(Metaspace::ClassType); + assert(reserved_class > 0, "assert"); + assert(reserved_class < reserved, "assert"); + } + } + + static void test_committed() { + size_t committed = MetaspaceAux::committed_bytes(); + + assert(committed > 0, "assert"); + + size_t reserved = MetaspaceAux::reserved_bytes(); + assert(committed <= reserved, "assert"); + + size_t committed_metadata = MetaspaceAux::committed_bytes(Metaspace::NonClassType); + assert(committed_metadata > 0, "assert"); + assert(committed_metadata <= committed, "assert"); + + if (UseCompressedClassPointers) { + size_t committed_class = MetaspaceAux::committed_bytes(Metaspace::ClassType); + assert(committed_class > 0, "assert"); + assert(committed_class < committed, "assert"); + } + } + + static void test() { + test_reserved(); + test_committed(); + } +}; + +void MetaspaceAux_test() { + MetaspaceAuxTest::test(); +} + +#endif diff --git a/hotspot/src/share/vm/memory/metaspace.hpp b/hotspot/src/share/vm/memory/metaspace.hpp index b51c80be0e6..242fa61b1cc 100644 --- a/hotspot/src/share/vm/memory/metaspace.hpp +++ b/hotspot/src/share/vm/memory/metaspace.hpp @@ -292,13 +292,18 @@ class MetaspaceAux : AllStatic { static size_t free_bytes(); static size_t free_bytes(Metaspace::MetadataType mdtype); - // Total capacity in all Metaspaces static size_t reserved_bytes(Metaspace::MetadataType mdtype); static size_t reserved_bytes() { return reserved_bytes(Metaspace::ClassType) + reserved_bytes(Metaspace::NonClassType); } + static size_t committed_bytes(Metaspace::MetadataType mdtype); + static size_t committed_bytes() { + return committed_bytes(Metaspace::ClassType) + + committed_bytes(Metaspace::NonClassType); + } + static size_t min_chunk_size_words(); static size_t min_chunk_size_bytes() { return min_chunk_size_words() * BytesPerWord; diff --git a/hotspot/src/share/vm/prims/jni.cpp b/hotspot/src/share/vm/prims/jni.cpp index ea44e2c6679..16457a8cd6e 100644 --- a/hotspot/src/share/vm/prims/jni.cpp +++ b/hotspot/src/share/vm/prims/jni.cpp @@ -5048,12 +5048,16 @@ _JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_GetDefaultJavaVMInitArgs(void *args_) { // Forward declaration void TestReservedSpace_test(); void TestReserveMemorySpecial_test(); +void TestVirtualSpace_test(); +void MetaspaceAux_test(); void execute_internal_vm_tests() { if (ExecuteInternalVMTests) { tty->print_cr("Running internal VM tests"); run_unit_test(TestReservedSpace_test()); run_unit_test(TestReserveMemorySpecial_test()); + run_unit_test(TestVirtualSpace_test()); + run_unit_test(MetaspaceAux_test()); run_unit_test(GlobalDefinitions::test_globals()); run_unit_test(GCTimerAllTest::all()); run_unit_test(arrayOopDesc::test_max_array_length()); diff --git a/hotspot/src/share/vm/runtime/virtualspace.cpp b/hotspot/src/share/vm/runtime/virtualspace.cpp index 9e01fe0292f..b7724a6a082 100644 --- a/hotspot/src/share/vm/runtime/virtualspace.cpp +++ b/hotspot/src/share/vm/runtime/virtualspace.cpp @@ -453,6 +453,42 @@ size_t VirtualSpace::uncommitted_size() const { return reserved_size() - committed_size(); } +size_t VirtualSpace::actual_committed_size() const { + // Special VirtualSpaces commit all reserved space up front. + if (special()) { + return reserved_size(); + } + + size_t committed_low = pointer_delta(_lower_high, _low_boundary, sizeof(char)); + size_t committed_middle = pointer_delta(_middle_high, _lower_high_boundary, sizeof(char)); + size_t committed_high = pointer_delta(_upper_high, _middle_high_boundary, sizeof(char)); + +#ifdef ASSERT + size_t lower = pointer_delta(_lower_high_boundary, _low_boundary, sizeof(char)); + size_t middle = pointer_delta(_middle_high_boundary, _lower_high_boundary, sizeof(char)); + size_t upper = pointer_delta(_upper_high_boundary, _middle_high_boundary, sizeof(char)); + + if (committed_high > 0) { + assert(committed_low == lower, "Must be"); + assert(committed_middle == middle, "Must be"); + } + + if (committed_middle > 0) { + assert(committed_low == lower, "Must be"); + } + if (committed_middle < middle) { + assert(committed_high == 0, "Must be"); + } + + if (committed_low < lower) { + assert(committed_high == 0, "Must be"); + assert(committed_middle == 0, "Must be"); + } +#endif + + return committed_low + committed_middle + committed_high; +} + bool VirtualSpace::contains(const void* p) const { return low() <= (const char*) p && (const char*) p < high(); @@ -910,6 +946,109 @@ void TestReservedSpace_test() { TestReservedSpace::test_reserved_space(); } +#define assert_equals(actual, expected) \ + assert(actual == expected, \ + err_msg("Got " SIZE_FORMAT " expected " \ + SIZE_FORMAT, actual, expected)); + +#define assert_ge(value1, value2) \ + assert(value1 >= value2, \ + err_msg("'" #value1 "': " SIZE_FORMAT " '" \ + #value2 "': " SIZE_FORMAT, value1, value2)); + +#define assert_lt(value1, value2) \ + assert(value1 < value2, \ + err_msg("'" #value1 "': " SIZE_FORMAT " '" \ + #value2 "': " SIZE_FORMAT, value1, value2)); + + +class TestVirtualSpace : AllStatic { + public: + static void test_virtual_space_actual_committed_space(size_t reserve_size, size_t commit_size) { + size_t granularity = os::vm_allocation_granularity(); + size_t reserve_size_aligned = align_size_up(reserve_size, granularity); + + ReservedSpace reserved(reserve_size_aligned); + + assert(reserved.is_reserved(), "Must be"); + + VirtualSpace vs; + bool initialized = vs.initialize(reserved, 0); + assert(initialized, "Failed to initialize VirtualSpace"); + + vs.expand_by(commit_size, false); + + if (vs.special()) { + assert_equals(vs.actual_committed_size(), reserve_size_aligned); + } else { + assert_ge(vs.actual_committed_size(), commit_size); + // Approximate the commit granularity. + size_t commit_granularity = UseLargePages ? os::large_page_size() : os::vm_page_size(); + assert_lt(vs.actual_committed_size(), commit_size + commit_granularity); + } + + reserved.release(); + } + + static void test_virtual_space_actual_committed_space_one_large_page() { + if (!UseLargePages) { + return; + } + + size_t large_page_size = os::large_page_size(); + + ReservedSpace reserved(large_page_size, large_page_size, true, false); + + assert(reserved.is_reserved(), "Must be"); + + VirtualSpace vs; + bool initialized = vs.initialize(reserved, 0); + assert(initialized, "Failed to initialize VirtualSpace"); + + vs.expand_by(large_page_size, false); + + assert_equals(vs.actual_committed_size(), large_page_size); + + reserved.release(); + } + + static void test_virtual_space_actual_committed_space() { + test_virtual_space_actual_committed_space(4 * K, 0); + test_virtual_space_actual_committed_space(4 * K, 4 * K); + test_virtual_space_actual_committed_space(8 * K, 0); + test_virtual_space_actual_committed_space(8 * K, 4 * K); + test_virtual_space_actual_committed_space(8 * K, 8 * K); + test_virtual_space_actual_committed_space(12 * K, 0); + test_virtual_space_actual_committed_space(12 * K, 4 * K); + test_virtual_space_actual_committed_space(12 * K, 8 * K); + test_virtual_space_actual_committed_space(12 * K, 12 * K); + test_virtual_space_actual_committed_space(64 * K, 0); + test_virtual_space_actual_committed_space(64 * K, 32 * K); + test_virtual_space_actual_committed_space(64 * K, 64 * K); + test_virtual_space_actual_committed_space(2 * M, 0); + test_virtual_space_actual_committed_space(2 * M, 4 * K); + test_virtual_space_actual_committed_space(2 * M, 64 * K); + test_virtual_space_actual_committed_space(2 * M, 1 * M); + test_virtual_space_actual_committed_space(2 * M, 2 * M); + test_virtual_space_actual_committed_space(10 * M, 0); + test_virtual_space_actual_committed_space(10 * M, 4 * K); + test_virtual_space_actual_committed_space(10 * M, 8 * K); + test_virtual_space_actual_committed_space(10 * M, 1 * M); + test_virtual_space_actual_committed_space(10 * M, 2 * M); + test_virtual_space_actual_committed_space(10 * M, 5 * M); + test_virtual_space_actual_committed_space(10 * M, 10 * M); + } + + static void test_virtual_space() { + test_virtual_space_actual_committed_space(); + test_virtual_space_actual_committed_space_one_large_page(); + } +}; + +void TestVirtualSpace_test() { + TestVirtualSpace::test_virtual_space(); +} + #endif // PRODUCT #endif diff --git a/hotspot/src/share/vm/runtime/virtualspace.hpp b/hotspot/src/share/vm/runtime/virtualspace.hpp index bca9b6c14fc..938a71a4a43 100644 --- a/hotspot/src/share/vm/runtime/virtualspace.hpp +++ b/hotspot/src/share/vm/runtime/virtualspace.hpp @@ -183,11 +183,16 @@ class VirtualSpace VALUE_OBJ_CLASS_SPEC { // Destruction ~VirtualSpace(); - // Testers (all sizes are byte sizes) - size_t committed_size() const; - size_t reserved_size() const; + // Reserved memory + size_t reserved_size() const; + // Actually committed OS memory + size_t actual_committed_size() const; + // Memory used/expanded in this virtual space + size_t committed_size() const; + // Memory left to use/expand in this virtual space size_t uncommitted_size() const; - bool contains(const void* p) const; + + bool contains(const void* p) const; // Operations // returns true on success, false otherwise From e6f97e8fc5b628f13af8a19f75734613a56932b7 Mon Sep 17 00:00:00 2001 From: Magnus Ihse Bursie Date: Thu, 12 Sep 2013 10:38:17 +0200 Subject: [PATCH 130/210] 8024467: Update autoconf-config.guess to autoconf 2.69 Reviewed-by: erikj --- .../autoconf/build-aux/autoconf-config.guess | 551 +++++++++--------- 1 file changed, 275 insertions(+), 276 deletions(-) diff --git a/common/autoconf/build-aux/autoconf-config.guess b/common/autoconf/build-aux/autoconf-config.guess index 3aa7f690629..15ee4389269 100644 --- a/common/autoconf/build-aux/autoconf-config.guess +++ b/common/autoconf/build-aux/autoconf-config.guess @@ -26,10 +26,10 @@ # Attempt to guess a canonical system name. # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, -# 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 -# Free Software Foundation, Inc. +# 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, +# 2011, 2012 Free Software Foundation, Inc. -timestamp='2008-01-23' +timestamp='2012-02-10' # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by @@ -42,9 +42,7 @@ timestamp='2008-01-23' # General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA -# 02110-1301, USA. +# along with this program; if not, see . # # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a @@ -52,16 +50,16 @@ timestamp='2008-01-23' # the same distribution terms that you use for the rest of that program. -# Originally written by Per Bothner . -# Please send patches to . Submit a context -# diff and a properly formatted ChangeLog entry. +# Originally written by Per Bothner. Please send patches (context +# diff format) to and include a ChangeLog +# entry. # # This script attempts to guess a canonical system name similar to # config.sub. If it succeeds, it prints the system name on stdout, and # exits with 0. Otherwise, it exits with 1. # -# The plan is that this can be called by configure scripts if you -# don't specify an explicit build system type. +# You can get the latest version of this script from: +# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD me=`echo "$0" | sed -e 's,.*/,,'` @@ -81,8 +79,9 @@ version="\ GNU config.guess ($timestamp) Originally written by Per Bothner. -Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, -2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. +Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, +2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 +Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." @@ -169,7 +168,7 @@ UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in *:NetBSD:*:*) # NetBSD (nbsd) targets should (where applicable) match one or - # more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*, + # more of the tuples: *-*-netbsdelf*, *-*-netbsdaout*, # *-*-netbsdecoff* and *-*-netbsd*. For targets that recently # switched to ELF, *-*-netbsd* would select the old # object file format. This provides both forward @@ -195,7 +194,7 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in arm*|i386|m68k|ns32k|sh3*|sparc|vax) eval $set_cc_for_build if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \ - | grep __ELF__ >/dev/null + | grep -q __ELF__ then # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout). # Return netbsd for either. FIX? @@ -205,7 +204,7 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in fi ;; *) - os=netbsd + os=netbsd ;; esac # The OS release @@ -248,7 +247,7 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` ;; *5.*) - UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'` + UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'` ;; esac # According to Compaq, /usr/sbin/psrinfo has been available on @@ -294,7 +293,10 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in # A Xn.n version is an unreleased experimental baselevel. # 1.2 uses "1.2" for uname -r. echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` - exit ;; + # Reset EXIT trap before exiting to avoid spurious non-zero exit code. + exitcode=$? + trap '' 0 + exit $exitcode ;; Alpha\ *:Windows_NT*:*) # How do we know it's Interix rather than the generic POSIX subsystem? # Should we change UNAME_MACHINE based on the output of uname instead @@ -320,7 +322,7 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in echo s390-ibm-zvmoe exit ;; *:OS400:*:*) - echo powerpc-ibm-os400 + echo powerpc-ibm-os400 exit ;; arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) echo arm-acorn-riscix${UNAME_RELEASE} @@ -349,14 +351,33 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in case `/usr/bin/uname -p` in sparc) echo sparc-icl-nx7; exit ;; esac ;; + s390x:SunOS:*:*) + echo ${UNAME_MACHINE}-ibm-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; sun4H:SunOS:5.*:*) echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` exit ;; sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` exit ;; + i86pc:AuroraUX:5.*:* | i86xen:AuroraUX:5.*:*) + echo i386-pc-auroraux${UNAME_RELEASE} + exit ;; i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*) - echo i386-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + eval $set_cc_for_build + SUN_ARCH="i386" + # If there is a compiler, see if it is configured for 64-bit objects. + # Note that the Sun cc does not turn __LP64__ into 1 like gcc does. + # This test works for both compilers. + if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then + if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \ + (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \ + grep IS_64BIT_ARCH >/dev/null + then + SUN_ARCH="x86_64" + fi + fi + echo ${SUN_ARCH}-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` exit ;; sun4*:SunOS:6*:*) # According to config.sub, this is the proper way to canonicalize @@ -400,23 +421,23 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in # MiNT. But MiNT is downward compatible to TOS, so this should # be no problem. atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*) - echo m68k-atari-mint${UNAME_RELEASE} + echo m68k-atari-mint${UNAME_RELEASE} exit ;; atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) echo m68k-atari-mint${UNAME_RELEASE} - exit ;; + exit ;; *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) - echo m68k-atari-mint${UNAME_RELEASE} + echo m68k-atari-mint${UNAME_RELEASE} exit ;; milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) - echo m68k-milan-mint${UNAME_RELEASE} - exit ;; + echo m68k-milan-mint${UNAME_RELEASE} + exit ;; hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) - echo m68k-hades-mint${UNAME_RELEASE} - exit ;; + echo m68k-hades-mint${UNAME_RELEASE} + exit ;; *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) - echo m68k-unknown-mint${UNAME_RELEASE} - exit ;; + echo m68k-unknown-mint${UNAME_RELEASE} + exit ;; m68k:machten:*:*) echo m68k-apple-machten${UNAME_RELEASE} exit ;; @@ -486,8 +507,8 @@ EOF echo m88k-motorola-sysv3 exit ;; AViiON:dgux:*:*) - # DG/UX returns AViiON for all architectures - UNAME_PROCESSOR=`/usr/bin/uname -p` + # DG/UX returns AViiON for all architectures + UNAME_PROCESSOR=`/usr/bin/uname -p` if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ] then if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \ @@ -500,7 +521,7 @@ EOF else echo i586-dg-dgux${UNAME_RELEASE} fi - exit ;; + exit ;; M88*:DolphinOS:*:*) # DolphinOS (SVR3) echo m88k-dolphin-sysv3 exit ;; @@ -557,7 +578,7 @@ EOF echo rs6000-ibm-aix3.2 fi exit ;; - *:AIX:*:[456]) + *:AIX:*:[4567]) IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then IBM_ARCH=rs6000 @@ -600,52 +621,52 @@ EOF 9000/[678][0-9][0-9]) if [ -x /usr/bin/getconf ]; then sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null` - sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` - case "${sc_cpu_version}" in - 523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0 - 528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1 - 532) # CPU_PA_RISC2_0 - case "${sc_kernel_bits}" in - 32) HP_ARCH="hppa2.0n" ;; - 64) HP_ARCH="hppa2.0w" ;; + sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` + case "${sc_cpu_version}" in + 523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0 + 528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1 + 532) # CPU_PA_RISC2_0 + case "${sc_kernel_bits}" in + 32) HP_ARCH="hppa2.0n" ;; + 64) HP_ARCH="hppa2.0w" ;; '') HP_ARCH="hppa2.0" ;; # HP-UX 10.20 - esac ;; - esac + esac ;; + esac fi if [ "${HP_ARCH}" = "" ]; then eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c + sed 's/^ //' << EOF >$dummy.c - #define _HPUX_SOURCE - #include - #include + #define _HPUX_SOURCE + #include + #include - int main () - { - #if defined(_SC_KERNEL_BITS) - long bits = sysconf(_SC_KERNEL_BITS); - #endif - long cpu = sysconf (_SC_CPU_VERSION); + int main () + { + #if defined(_SC_KERNEL_BITS) + long bits = sysconf(_SC_KERNEL_BITS); + #endif + long cpu = sysconf (_SC_CPU_VERSION); - switch (cpu) - { - case CPU_PA_RISC1_0: puts ("hppa1.0"); break; - case CPU_PA_RISC1_1: puts ("hppa1.1"); break; - case CPU_PA_RISC2_0: - #if defined(_SC_KERNEL_BITS) - switch (bits) - { - case 64: puts ("hppa2.0w"); break; - case 32: puts ("hppa2.0n"); break; - default: puts ("hppa2.0"); break; - } break; - #else /* !defined(_SC_KERNEL_BITS) */ - puts ("hppa2.0"); break; - #endif - default: puts ("hppa1.0"); break; - } - exit (0); - } + switch (cpu) + { + case CPU_PA_RISC1_0: puts ("hppa1.0"); break; + case CPU_PA_RISC1_1: puts ("hppa1.1"); break; + case CPU_PA_RISC2_0: + #if defined(_SC_KERNEL_BITS) + switch (bits) + { + case 64: puts ("hppa2.0w"); break; + case 32: puts ("hppa2.0n"); break; + default: puts ("hppa2.0"); break; + } break; + #else /* !defined(_SC_KERNEL_BITS) */ + puts ("hppa2.0"); break; + #endif + default: puts ("hppa1.0"); break; + } + exit (0); + } EOF (CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy` test -z "$HP_ARCH" && HP_ARCH=hppa @@ -665,7 +686,7 @@ EOF # => hppa64-hp-hpux11.23 if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | - grep __LP64__ >/dev/null + grep -q __LP64__ then HP_ARCH="hppa2.0w" else @@ -736,22 +757,22 @@ EOF exit ;; C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*) echo c1-convex-bsd - exit ;; + exit ;; C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*) if getsysinfo -f scalar_acc then echo c32-convex-bsd else echo c2-convex-bsd fi - exit ;; + exit ;; C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*) echo c34-convex-bsd - exit ;; + exit ;; C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*) echo c38-convex-bsd - exit ;; + exit ;; C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) echo c4-convex-bsd - exit ;; + exit ;; CRAY*Y-MP:*:*:*) echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' exit ;; @@ -775,14 +796,14 @@ EOF exit ;; F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` - FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` - FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'` - echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" - exit ;; + FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` + FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'` + echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" + exit ;; 5000:UNIX_System_V:4.*:*) - FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` - FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'` - echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" + FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` + FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'` + echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" exit ;; i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE} @@ -794,13 +815,12 @@ EOF echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE} exit ;; *:FreeBSD:*:*) - case ${UNAME_MACHINE} in - pc98) - echo i386-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; + UNAME_PROCESSOR=`/usr/bin/uname -p` + case ${UNAME_PROCESSOR} in amd64) echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; *) - echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; + echo ${UNAME_PROCESSOR}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; esac exit ;; i*:CYGWIN*:*) @@ -809,19 +829,22 @@ EOF *:MINGW*:*) echo ${UNAME_MACHINE}-pc-mingw32 exit ;; + i*:MSYS*:*) + echo ${UNAME_MACHINE}-pc-msys + exit ;; i*:windows32*:*) - # uname -m includes "-pc" on this system. - echo ${UNAME_MACHINE}-mingw32 + # uname -m includes "-pc" on this system. + echo ${UNAME_MACHINE}-mingw32 exit ;; i*:PW*:*) echo ${UNAME_MACHINE}-pc-pw32 exit ;; - *:Interix*:[3456]*) - case ${UNAME_MACHINE} in + *:Interix*:*) + case ${UNAME_MACHINE} in x86) echo i586-pc-interix${UNAME_RELEASE} exit ;; - EM64T | authenticamd) + authenticamd | genuineintel | EM64T) echo x86_64-unknown-interix${UNAME_RELEASE} exit ;; IA64) @@ -831,6 +854,9 @@ EOF [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*) echo i${UNAME_MACHINE}-pc-mks exit ;; + 8664:Windows_NT:*) + echo x86_64-pc-mks + exit ;; i*:Windows_NT*:* | Pentium*:Windows_NT*:*) # How do we know it's Interix rather than the generic POSIX subsystem? # It also conflicts with pre-2.0 versions of AT&T UWIN. Should we @@ -860,92 +886,13 @@ EOF i*86:Minix:*:*) echo ${UNAME_MACHINE}-pc-minix exit ;; - arm*:Linux:*:*) - eval $set_cc_for_build - if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \ - | grep -q __ARM_EABI__ - then - echo ${UNAME_MACHINE}-unknown-linux-gnu - else - echo ${UNAME_MACHINE}-unknown-linux-gnueabi - fi - exit ;; - avr32*:Linux:*:*) + aarch64:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu exit ;; - cris:Linux:*:*) - echo cris-axis-linux-gnu - exit ;; - crisv32:Linux:*:*) - echo crisv32-axis-linux-gnu - exit ;; - frv:Linux:*:*) - echo frv-unknown-linux-gnu - exit ;; - ia64:Linux:*:*) + aarch64_be:Linux:*:*) + UNAME_MACHINE=aarch64_be echo ${UNAME_MACHINE}-unknown-linux-gnu exit ;; - m32r*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - m68*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - mips:Linux:*:*) - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - #undef CPU - #undef mips - #undef mipsel - #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) - CPU=mipsel - #else - #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) - CPU=mips - #else - CPU= - #endif - #endif -EOF - eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' - /^CPU/{ - s: ::g - p - }'`" - test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } - ;; - mips64:Linux:*:*) - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - #undef CPU - #undef mips64 - #undef mips64el - #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) - CPU=mips64el - #else - #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) - CPU=mips64 - #else - CPU= - #endif - #endif -EOF - eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' - /^CPU/{ - s: ::g - p - }'`" - test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } - ;; - or32:Linux:*:*) - echo or32-unknown-linux-gnu - exit ;; - ppc:Linux:*:*) - echo powerpc-unknown-linux-gnu - exit ;; - ppc64:Linux:*:*) - echo powerpc64-unknown-linux-gnu - exit ;; alpha:Linux:*:*) case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in EV5) UNAME_MACHINE=alphaev5 ;; @@ -955,11 +902,90 @@ EOF EV6) UNAME_MACHINE=alphaev6 ;; EV67) UNAME_MACHINE=alphaev67 ;; EV68*) UNAME_MACHINE=alphaev68 ;; - esac - objdump --private-headers /bin/sh | grep ld.so.1 >/dev/null + esac + objdump --private-headers /bin/sh | grep -q ld.so.1 if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC} exit ;; + arm*:Linux:*:*) + eval $set_cc_for_build + if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \ + | grep -q __ARM_EABI__ + then + echo ${UNAME_MACHINE}-unknown-linux-gnu + else + if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \ + | grep -q __ARM_PCS_VFP + then + echo ${UNAME_MACHINE}-unknown-linux-gnueabi + else + echo ${UNAME_MACHINE}-unknown-linux-gnueabihf + fi + fi + exit ;; + avr32*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + cris:Linux:*:*) + echo ${UNAME_MACHINE}-axis-linux-gnu + exit ;; + crisv32:Linux:*:*) + echo ${UNAME_MACHINE}-axis-linux-gnu + exit ;; + frv:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + hexagon:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + i*86:Linux:*:*) + LIBC=gnu + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #ifdef __dietlibc__ + LIBC=dietlibc + #endif +EOF + eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^LIBC'` + echo "${UNAME_MACHINE}-pc-linux-${LIBC}" + exit ;; + ia64:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + m32r*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + m68*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + mips:Linux:*:* | mips64:Linux:*:*) + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #undef CPU + #undef ${UNAME_MACHINE} + #undef ${UNAME_MACHINE}el + #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) + CPU=${UNAME_MACHINE}el + #else + #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) + CPU=${UNAME_MACHINE} + #else + CPU= + #endif + #endif +EOF + eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^CPU'` + test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } + ;; + or32:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + padre:Linux:*:*) + echo sparc-unknown-linux-gnu + exit ;; + parisc64:Linux:*:* | hppa64:Linux:*:*) + echo hppa64-unknown-linux-gnu + exit ;; parisc:Linux:*:* | hppa:Linux:*:*) # Look for CPU level case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in @@ -968,14 +994,17 @@ EOF *) echo hppa-unknown-linux-gnu ;; esac exit ;; - parisc64:Linux:*:* | hppa64:Linux:*:*) - echo hppa64-unknown-linux-gnu + ppc64:Linux:*:*) + echo powerpc64-unknown-linux-gnu + exit ;; + ppc:Linux:*:*) + echo powerpc-unknown-linux-gnu exit ;; s390:Linux:*:* | s390x:Linux:*:*) echo ${UNAME_MACHINE}-ibm-linux exit ;; sh64*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu + echo ${UNAME_MACHINE}-unknown-linux-gnu exit ;; sh*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu @@ -983,78 +1012,18 @@ EOF sparc:Linux:*:* | sparc64:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu exit ;; + tile*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; vax:Linux:*:*) echo ${UNAME_MACHINE}-dec-linux-gnu exit ;; x86_64:Linux:*:*) - echo x86_64-unknown-linux-gnu + echo ${UNAME_MACHINE}-unknown-linux-gnu exit ;; xtensa*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu + echo ${UNAME_MACHINE}-unknown-linux-gnu exit ;; - i*86:Linux:*:*) - # The BFD linker knows what the default object file format is, so - # first see if it will tell us. cd to the root directory to prevent - # problems with other programs or directories called `ld' in the path. - # Set LC_ALL=C to ensure ld outputs messages in English. - ld_supported_targets=`cd /; LC_ALL=C ld --help 2>&1 \ - | sed -ne '/supported targets:/!d - s/[ ][ ]*/ /g - s/.*supported targets: *// - s/ .*// - p'` - case "$ld_supported_targets" in - elf32-i386) - TENTATIVE="${UNAME_MACHINE}-pc-linux-gnu" - ;; - a.out-i386-linux) - echo "${UNAME_MACHINE}-pc-linux-gnuaout" - exit ;; - coff-i386) - echo "${UNAME_MACHINE}-pc-linux-gnucoff" - exit ;; - "") - # Either a pre-BFD a.out linker (linux-gnuoldld) or - # one that does not give us useful --help. - echo "${UNAME_MACHINE}-pc-linux-gnuoldld" - exit ;; - esac - # Determine whether the default compiler is a.out or elf - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - #include - #ifdef __ELF__ - # ifdef __GLIBC__ - # if __GLIBC__ >= 2 - LIBC=gnu - # else - LIBC=gnulibc1 - # endif - # else - LIBC=gnulibc1 - # endif - #else - #if defined(__INTEL_COMPILER) || defined(__PGI) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) - LIBC=gnu - #else - LIBC=gnuaout - #endif - #endif - #ifdef __dietlibc__ - LIBC=dietlibc - #endif -EOF - eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' - /^LIBC/{ - s: ::g - p - }'`" - test x"${LIBC}" != x && { - echo "${UNAME_MACHINE}-pc-linux-${LIBC}" - exit - } - test x"${TENTATIVE}" != x && { echo "${TENTATIVE}"; exit; } - ;; i*86:DYNIX/ptx:4*:*) # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. # earlier versions are messed up and put the nodename in both @@ -1062,11 +1031,11 @@ EOF echo i386-sequent-sysv4 exit ;; i*86:UNIX_SV:4.2MP:2.*) - # Unixware is an offshoot of SVR4, but it has its own version - # number series starting with 2... - # I am not positive that other SVR4 systems won't match this, + # Unixware is an offshoot of SVR4, but it has its own version + # number series starting with 2... + # I am not positive that other SVR4 systems won't match this, # I just have to hope. -- rms. - # Use sysv4.2uw... so that sysv4* matches it. + # Use sysv4.2uw... so that sysv4* matches it. echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION} exit ;; i*86:OS/2:*:*) @@ -1083,7 +1052,7 @@ EOF i*86:syllable:*:*) echo ${UNAME_MACHINE}-pc-syllable exit ;; - i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*) + i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.[02]*:*) echo i386-unknown-lynxos${UNAME_RELEASE} exit ;; i*86:*DOS:*:*) @@ -1098,7 +1067,7 @@ EOF fi exit ;; i*86:*:5:[678]*) - # UnixWare 7.x, OpenUNIX and OpenServer 6. + # UnixWare 7.x, OpenUNIX and OpenServer 6. case `/bin/uname -X | grep "^Machine"` in *486*) UNAME_MACHINE=i486 ;; *Pentium) UNAME_MACHINE=i586 ;; @@ -1126,10 +1095,13 @@ EOF exit ;; pc:*:*:*) # Left here for compatibility: - # uname -m prints for DJGPP always 'pc', but it prints nothing about - # the processor, so we play safe by assuming i386. - echo i386-pc-msdosdjgpp - exit ;; + # uname -m prints for DJGPP always 'pc', but it prints nothing about + # the processor, so we play safe by assuming i586. + # Note: whatever this is, it MUST be the same as what config.sub + # prints for the "djgpp" host, or else GDB configury will decide that + # this is a cross-build. + echo i586-pc-msdosdjgpp + exit ;; Intel:Mach:3*:*) echo i386-pc-mach3 exit ;; @@ -1164,8 +1136,18 @@ EOF /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;; 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) - /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ - && { echo i486-ncr-sysv4; exit; } ;; + /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ + && { echo i486-ncr-sysv4; exit; } ;; + NCR*:*:4.2:* | MPRAS*:*:4.2:*) + OS_REL='.3' + test -r /etc/.relid \ + && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` + /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ + && { echo i486-ncr-sysv4.3${OS_REL}; exit; } + /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ + && { echo i586-ncr-sysv4.3${OS_REL}; exit; } + /bin/uname -p 2>/dev/null | /bin/grep pteron >/dev/null \ + && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;; m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) echo m68k-unknown-lynxos${UNAME_RELEASE} exit ;; @@ -1178,7 +1160,7 @@ EOF rs6000:LynxOS:2.*:*) echo rs6000-unknown-lynxos${UNAME_RELEASE} exit ;; - PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.0*:*) + PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.[02]*:*) echo powerpc-unknown-lynxos${UNAME_RELEASE} exit ;; SM[BE]S:UNIX_SV:*:*) @@ -1198,10 +1180,10 @@ EOF echo ns32k-sni-sysv fi exit ;; - PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort - # says - echo i586-unisys-sysv4 - exit ;; + PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort + # says + echo i586-unisys-sysv4 + exit ;; *:UNIX_System_V:4*:FTX*) # From Gerald Hewes . # How about differentiating between stratus architectures? -djm @@ -1227,11 +1209,11 @@ EOF exit ;; R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) if [ -d /usr/nec ]; then - echo mips-nec-sysv${UNAME_RELEASE} + echo mips-nec-sysv${UNAME_RELEASE} else - echo mips-unknown-sysv${UNAME_RELEASE} + echo mips-unknown-sysv${UNAME_RELEASE} fi - exit ;; + exit ;; BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. echo powerpc-be-beos exit ;; @@ -1241,6 +1223,9 @@ EOF BePC:BeOS:*:*) # BeOS running on Intel PC compatible. echo i586-pc-beos exit ;; + BePC:Haiku:*:*) # Haiku running on Intel PC compatible. + echo i586-pc-haiku + exit ;; SX-4:SUPER-UX:*:*) echo sx4-nec-superux${UNAME_RELEASE} exit ;; @@ -1267,12 +1252,17 @@ EOF exit ;; *:Darwin:*:*) UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown - eval $set_cc_for_build - echo "int main(){}" > $dummy.c - if test "`$CC_FOR_BUILD -o $dummy $dummy.c; file $dummy | grep -c x86_64`" = 1 ; then - UNAME_PROCESSOR=x86_64 - fi case $UNAME_PROCESSOR in + i386) + eval $set_cc_for_build + if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then + if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \ + (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \ + grep IS_64BIT_ARCH >/dev/null + then + UNAME_PROCESSOR="x86_64" + fi + fi ;; unknown) UNAME_PROCESSOR=powerpc ;; esac echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE} @@ -1288,6 +1278,9 @@ EOF *:QNX:*:4*) echo i386-pc-qnx exit ;; + NEO-?:NONSTOP_KERNEL:*:*) + echo neo-tandem-nsk${UNAME_RELEASE} + exit ;; NSE-?:NONSTOP_KERNEL:*:*) echo nse-tandem-nsk${UNAME_RELEASE} exit ;; @@ -1333,13 +1326,13 @@ EOF echo pdp10-unknown-its exit ;; SEI:*:*:SEIUX) - echo mips-sei-seiux${UNAME_RELEASE} + echo mips-sei-seiux${UNAME_RELEASE} exit ;; *:DragonFly:*:*) echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` exit ;; *:*VMS:*:*) - UNAME_MACHINE=`(uname -p) 2>/dev/null` + UNAME_MACHINE=`(uname -p) 2>/dev/null` case "${UNAME_MACHINE}" in A*) echo alpha-dec-vms ; exit ;; I*) echo ia64-dec-vms ; exit ;; @@ -1354,6 +1347,12 @@ EOF i*86:rdos:*:*) echo ${UNAME_MACHINE}-pc-rdos exit ;; + i*86:AROS:*:*) + echo ${UNAME_MACHINE}-pc-aros + exit ;; + x86_64:VMkernel:*:*) + echo ${UNAME_MACHINE}-unknown-esx + exit ;; esac #echo '(No uname command or uname output not recognized.)' 1>&2 @@ -1376,11 +1375,11 @@ main () #include printf ("m68k-sony-newsos%s\n", #ifdef NEWSOS4 - "4" + "4" #else - "" + "" #endif - ); exit (0); + ); exit (0); #endif #endif From df8c6df8a8c87f5b81774c1c7531d32aea0c5fa2 Mon Sep 17 00:00:00 2001 From: Magnus Ihse Bursie Date: Thu, 12 Sep 2013 10:42:19 +0200 Subject: [PATCH 131/210] 8010185: Build should support --with-override-nashorn Reviewed-by: erikj --- common/autoconf/generated-configure.sh | 21 +++++++++++++++++++-- common/autoconf/source-dirs.m4 | 13 ++++++++++++- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/common/autoconf/generated-configure.sh b/common/autoconf/generated-configure.sh index 7679cc5c4df..373f03fa2b1 100644 --- a/common/autoconf/generated-configure.sh +++ b/common/autoconf/generated-configure.sh @@ -1031,6 +1031,7 @@ with_override_corba with_override_jaxp with_override_jaxws with_override_hotspot +with_override_nashorn with_override_jdk with_import_hotspot with_msvcr_dll @@ -1784,6 +1785,7 @@ Optional Packages: --with-override-jaxp use this jaxp dir for the build --with-override-jaxws use this jaxws dir for the build --with-override-hotspot use this hotspot dir for the build + --with-override-nashorn use this nashorn dir for the build --with-override-jdk use this jdk dir for the build --with-import-hotspot import hotspot binaries from this jdk image or hotspot build dist dir instead of building from @@ -3818,7 +3820,7 @@ fi #CUSTOM_AUTOCONF_INCLUDE # Do not change or remove the following line, it is needed for consistency checks: -DATE_WHEN_GENERATED=1378914658 +DATE_WHEN_GENERATED=1378975246 ############################################################################### # @@ -16102,6 +16104,10 @@ if test "x$with_add_source_root" != x; then test -f $with_add_source_root/hotspot/make/Makefile; then as_fn_error $? "Your add source root seems to contain a full hotspot repo! An add source root should only contain additional sources." "$LINENO" 5 fi + if test -f $with_add_source_root/nashorn/makefiles/Makefile || \ + test -f $with_add_source_root/nashorn/make/Makefile; then + as_fn_error $? "Your add source root seems to contain a full nashorn repo! An add source root should only contain additional sources." "$LINENO" 5 + fi if test -f $with_add_source_root/jdk/makefiles/Makefile || \ test -f $with_add_source_root/jdk/make/Makefile; then as_fn_error $? "Your add source root seems to contain a full JDK repo! An add source root should only contain additional sources." "$LINENO" 5 @@ -16137,6 +16143,10 @@ if test "x$with_override_source_root" != x; then test -f $with_override_source_root/hotspot/make/Makefile; then as_fn_error $? "Your override source root seems to contain a full hotspot repo! An override source root should only contain sources that override." "$LINENO" 5 fi + if test -f $with_override_source_root/nashorn/makefiles/Makefile || \ + test -f $with_override_source_root/nashorn/make/Makefile; then + as_fn_error $? "Your override source root seems to contain a full nashorn repo! An override source root should only contain sources that override." "$LINENO" 5 + fi if test -f $with_override_source_root/jdk/makefiles/Makefile || \ test -f $with_override_source_root/jdk/make/Makefile; then as_fn_error $? "Your override source root seems to contain a full JDK repo! An override source root should only contain sources that override." "$LINENO" 5 @@ -16199,6 +16209,13 @@ fi +# Check whether --with-override-nashorn was given. +if test "${with_override_nashorn+set}" = set; then : + withval=$with_override_nashorn; +fi + + + # Check whether --with-override-jdk was given. if test "${with_override_jdk+set}" = set; then : withval=$with_override_jdk; @@ -16276,7 +16293,7 @@ if test "x$with_override_nashorn" != x; then cd "$with_override_nashorn" NASHORN_TOPDIR="`pwd`" cd "$CURDIR" - if ! test -f $NASHORN_TOPDIR/makefiles/BuildNashorn.gmk; then + if ! test -f $NASHORN_TOPDIR/makefiles/Makefile; then as_fn_error $? "You have to override nashorn with a full nashorn repo!" "$LINENO" 5 fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking if nashorn should be overridden" >&5 diff --git a/common/autoconf/source-dirs.m4 b/common/autoconf/source-dirs.m4 index bb0aba1b826..e040cc82f69 100644 --- a/common/autoconf/source-dirs.m4 +++ b/common/autoconf/source-dirs.m4 @@ -101,6 +101,10 @@ if test "x$with_add_source_root" != x; then test -f $with_add_source_root/hotspot/make/Makefile; then AC_MSG_ERROR([Your add source root seems to contain a full hotspot repo! An add source root should only contain additional sources.]) fi + if test -f $with_add_source_root/nashorn/makefiles/Makefile || \ + test -f $with_add_source_root/nashorn/make/Makefile; then + AC_MSG_ERROR([Your add source root seems to contain a full nashorn repo! An add source root should only contain additional sources.]) + fi if test -f $with_add_source_root/jdk/makefiles/Makefile || \ test -f $with_add_source_root/jdk/make/Makefile; then AC_MSG_ERROR([Your add source root seems to contain a full JDK repo! An add source root should only contain additional sources.]) @@ -136,6 +140,10 @@ if test "x$with_override_source_root" != x; then test -f $with_override_source_root/hotspot/make/Makefile; then AC_MSG_ERROR([Your override source root seems to contain a full hotspot repo! An override source root should only contain sources that override.]) fi + if test -f $with_override_source_root/nashorn/makefiles/Makefile || \ + test -f $with_override_source_root/nashorn/make/Makefile; then + AC_MSG_ERROR([Your override source root seems to contain a full nashorn repo! An override source root should only contain sources that override.]) + fi if test -f $with_override_source_root/jdk/makefiles/Makefile || \ test -f $with_override_source_root/jdk/make/Makefile; then AC_MSG_ERROR([Your override source root seems to contain a full JDK repo! An override source root should only contain sources that override.]) @@ -177,6 +185,9 @@ AC_ARG_WITH(override-jaxws, [AS_HELP_STRING([--with-override-jaxws], AC_ARG_WITH(override-hotspot, [AS_HELP_STRING([--with-override-hotspot], [use this hotspot dir for the build])]) +AC_ARG_WITH(override-nashorn, [AS_HELP_STRING([--with-override-nashorn], + [use this nashorn dir for the build])]) + AC_ARG_WITH(override-jdk, [AS_HELP_STRING([--with-override-jdk], [use this jdk dir for the build])]) @@ -241,7 +252,7 @@ if test "x$with_override_nashorn" != x; then cd "$with_override_nashorn" NASHORN_TOPDIR="`pwd`" cd "$CURDIR" - if ! test -f $NASHORN_TOPDIR/makefiles/BuildNashorn.gmk; then + if ! test -f $NASHORN_TOPDIR/makefiles/Makefile; then AC_MSG_ERROR([You have to override nashorn with a full nashorn repo!]) fi AC_MSG_CHECKING([if nashorn should be overridden]) From 57ed4a7edfffd59a2e0ba1961ffff876d0f7430a Mon Sep 17 00:00:00 2001 From: Vadim Pakhnushev Date: Thu, 12 Sep 2013 12:12:13 +0200 Subject: [PATCH 132/210] 8008022: Upgrade Direct X SDK used to build JDK Reviewed-by: erikj, prr, ihse --- Makefile | 12 - README-builds.html | 23 -- common/autoconf/generated-configure.sh | 451 +------------------------ common/autoconf/spec.gmk.in | 4 - common/autoconf/toolchain.m4 | 1 - common/autoconf/toolchain_windows.m4 | 58 ---- 6 files changed, 1 insertion(+), 548 deletions(-) diff --git a/Makefile b/Makefile index f7b9d1b35e3..2ef4bb99853 100644 --- a/Makefile +++ b/Makefile @@ -404,7 +404,6 @@ COMPILER_PATH.desc = Compiler install directory 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 # Make variables to print out (description and value) VARIABLE_PRINTVAL_LIST += \ @@ -429,17 +428,6 @@ VARIABLE_CHECKDIR_LIST += \ VARIABLE_CHECKFIL_LIST += \ CACERTS_FILE -# Some are windows specific -ifeq ($(PLATFORM), windows) - -VARIABLE_PRINTVAL_LIST += \ - DXSDK_PATH - -VARIABLE_CHECKDIR_LIST += \ - DXSDK_PATH - -endif - # For pattern rules below, so all are treated the same DO_PRINTVAL_LIST=$(VARIABLE_PRINTVAL_LIST:%=%.printval) DO_CHECKDIR_LIST=$(VARIABLE_CHECKDIR_LIST:%=%.checkdir) diff --git a/README-builds.html b/README-builds.html index 71c05c0fbf4..14796a27e87 100644 --- a/README-builds.html +++ b/README-builds.html @@ -444,10 +444,6 @@ Install Visual Studio 2010 -

  • - Install the - Microsoft DirectX SDK -
  • - - - -
    Error Summary " + + "
    ErrorDescription
    " + + "ClassError @@ -971,25 +967,6 @@ developer install location
    --with-dxsdk=path - select location of the Windows Direct X SDK install -
    - The Microsoft DirectX 9.0 SDK - header files and libraries - from the Summer 2004 edition - are required for building OpenJDK. - This SDK can be downloaded from - - Microsoft DirectX 9.0 SDK (Summer 2004). - If the link above becomes obsolete, the SDK can be found from - the Microsoft Download Site - (search with "DirectX 9.0 SDK Update Summer 2004"). - Installation usually will set the environment variable - DXSDK_DIR to it's install location. -
    --with-freetype=path diff --git a/common/autoconf/generated-configure.sh b/common/autoconf/generated-configure.sh index 373f03fa2b1..84c38a67dba 100644 --- a/common/autoconf/generated-configure.sh +++ b/common/autoconf/generated-configure.sh @@ -766,8 +766,6 @@ BUILD_LD BUILD_CXX BUILD_CC MSVCR_DLL -DXSDK_INCLUDE_PATH -DXSDK_LIB_PATH VS_PATH VS_LIB VS_INCLUDE @@ -1035,9 +1033,6 @@ with_override_nashorn with_override_jdk with_import_hotspot with_msvcr_dll -with_dxsdk -with_dxsdk_lib -with_dxsdk_include with_jtreg with_extra_cflags with_extra_cxxflags @@ -1792,11 +1787,6 @@ Optional Packages: source --with-msvcr-dll copy this msvcr100.dll into the built JDK (Windows only) [probed] - --with-dxsdk the DirectX SDK (Windows only) [probed] - --with-dxsdk-lib the DirectX SDK lib directory (Windows only) - [probed] - --with-dxsdk-include the DirectX SDK include directory (Windows only) - [probed] --with-jtreg Regression Test Harness [probed] --with-extra-cflags extra flags to be used when compiling jdk c-files --with-extra-cxxflags extra flags to be used when compiling jdk c++-files @@ -3807,10 +3797,6 @@ fi -# Setup the DXSDK paths - - - @@ -3820,7 +3806,7 @@ fi #CUSTOM_AUTOCONF_INCLUDE # Do not change or remove the following line, it is needed for consistency checks: -DATE_WHEN_GENERATED=1378975246 +DATE_WHEN_GENERATED=1378980507 ############################################################################### # @@ -17599,441 +17585,6 @@ $as_echo "$as_me: The path of MSVCR_DLL, which resolves as \"$path\", is invalid fi - - -# Check whether --with-dxsdk was given. -if test "${with_dxsdk+set}" = set; then : - withval=$with_dxsdk; -fi - - -# Check whether --with-dxsdk-lib was given. -if test "${with_dxsdk_lib+set}" = set; then : - withval=$with_dxsdk_lib; -fi - - -# Check whether --with-dxsdk-include was given. -if test "${with_dxsdk_include+set}" = set; then : - withval=$with_dxsdk_include; -fi - - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for DirectX SDK" >&5 -$as_echo_n "checking for DirectX SDK... " >&6; } - - if test "x$with_dxsdk" != x; then - dxsdk_path="$with_dxsdk" - elif test "x$DXSDK_DIR" != x; then - dxsdk_path="$DXSDK_DIR" - elif test -d "C:/DXSDK"; then - dxsdk_path="C:/DXSDK" - else - as_fn_error $? "Could not find the DirectX SDK" "$LINENO" 5 - fi - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $dxsdk_path" >&5 -$as_echo "$dxsdk_path" >&6; } - - if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.cygwin"; then - - # Input might be given as Windows format, start by converting to - # unix format. - path="$dxsdk_path" - new_path=`$CYGPATH -u "$path"` - - # Cygwin tries to hide some aspects of the Windows file system, such that binaries are - # named .exe but called without that suffix. Therefore, "foo" and "foo.exe" are considered - # the same file, most of the time (as in "test -f"). But not when running cygpath -s, then - # "foo.exe" is OK but "foo" is an error. - # - # This test is therefore slightly more accurate than "test -f" to check for file precense. - # It is also a way to make sure we got the proper file name for the real test later on. - test_shortpath=`$CYGPATH -s -m "$new_path" 2> /dev/null` - if test "x$test_shortpath" = x; then - { $as_echo "$as_me:${as_lineno-$LINENO}: The path of dxsdk_path, which resolves as \"$path\", is invalid." >&5 -$as_echo "$as_me: The path of dxsdk_path, which resolves as \"$path\", is invalid." >&6;} - as_fn_error $? "Cannot locate the the path of dxsdk_path" "$LINENO" 5 - fi - - # Call helper function which possibly converts this using DOS-style short mode. - # If so, the updated path is stored in $new_path. - - input_path="$new_path" - # Check if we need to convert this using DOS-style short mode. If the path - # contains just simple characters, use it. Otherwise (spaces, weird characters), - # take no chances and rewrite it. - # Note: m4 eats our [], so we need to use [ and ] instead. - has_forbidden_chars=`$ECHO "$input_path" | $GREP [^-._/a-zA-Z0-9]` - if test "x$has_forbidden_chars" != x; then - # Now convert it to mixed DOS-style, short mode (no spaces, and / instead of \) - shortmode_path=`$CYGPATH -s -m -a "$input_path"` - path_after_shortmode=`$CYGPATH -u "$shortmode_path"` - if test "x$path_after_shortmode" != "x$input_to_shortpath"; then - # Going to short mode and back again did indeed matter. Since short mode is - # case insensitive, let's make it lowercase to improve readability. - shortmode_path=`$ECHO "$shortmode_path" | $TR 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` - # Now convert it back to Unix-stile (cygpath) - input_path=`$CYGPATH -u "$shortmode_path"` - new_path="$input_path" - fi - fi - - test_cygdrive_prefix=`$ECHO $input_path | $GREP ^/cygdrive/` - if test "x$test_cygdrive_prefix" = x; then - # As a simple fix, exclude /usr/bin since it's not a real path. - if test "x`$ECHO $new_path | $GREP ^/usr/bin/`" = x; then - # The path is in a Cygwin special directory (e.g. /home). We need this converted to - # a path prefixed by /cygdrive for fixpath to work. - new_path="$CYGWIN_ROOT_PATH$input_path" - fi - fi - - - if test "x$path" != "x$new_path"; then - dxsdk_path="$new_path" - { $as_echo "$as_me:${as_lineno-$LINENO}: Rewriting dxsdk_path to \"$new_path\"" >&5 -$as_echo "$as_me: Rewriting dxsdk_path to \"$new_path\"" >&6;} - fi - - elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then - - path="$dxsdk_path" - has_colon=`$ECHO $path | $GREP ^.:` - new_path="$path" - if test "x$has_colon" = x; then - # Not in mixed or Windows style, start by that. - new_path=`cmd //c echo $path` - fi - - - input_path="$new_path" - # Check if we need to convert this using DOS-style short mode. If the path - # contains just simple characters, use it. Otherwise (spaces, weird characters), - # take no chances and rewrite it. - # Note: m4 eats our [], so we need to use [ and ] instead. - has_forbidden_chars=`$ECHO "$input_path" | $GREP [^-_/:a-zA-Z0-9]` - if test "x$has_forbidden_chars" != x; then - # Now convert it to mixed DOS-style, short mode (no spaces, and / instead of \) - new_path=`cmd /c "for %A in (\"$input_path\") do @echo %~sA"|$TR \\\\\\\\ / | $TR 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` - fi - - - windows_path="$new_path" - if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.cygwin"; then - unix_path=`$CYGPATH -u "$windows_path"` - new_path="$unix_path" - elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then - unix_path=`$ECHO "$windows_path" | $SED -e 's,^\\(.\\):,/\\1,g' -e 's,\\\\,/,g'` - new_path="$unix_path" - fi - - if test "x$path" != "x$new_path"; then - dxsdk_path="$new_path" - { $as_echo "$as_me:${as_lineno-$LINENO}: Rewriting dxsdk_path to \"$new_path\"" >&5 -$as_echo "$as_me: Rewriting dxsdk_path to \"$new_path\"" >&6;} - fi - - # Save the first 10 bytes of this path to the storage, so fixpath can work. - all_fixpath_prefixes=("${all_fixpath_prefixes[@]}" "${new_path:0:10}") - - else - # We're on a posix platform. Hooray! :) - path="$dxsdk_path" - has_space=`$ECHO "$path" | $GREP " "` - if test "x$has_space" != x; then - { $as_echo "$as_me:${as_lineno-$LINENO}: The path of dxsdk_path, which resolves as \"$path\", is invalid." >&5 -$as_echo "$as_me: The path of dxsdk_path, which resolves as \"$path\", is invalid." >&6;} - as_fn_error $? "Spaces are not allowed in this path." "$LINENO" 5 - fi - - # Use eval to expand a potential ~ - eval path="$path" - if test ! -f "$path" && test ! -d "$path"; then - as_fn_error $? "The path of dxsdk_path, which resolves as \"$path\", is not found." "$LINENO" 5 - fi - - dxsdk_path="`cd "$path"; $THEPWDCMD -L`" - fi - - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for DirectX SDK lib dir" >&5 -$as_echo_n "checking for DirectX SDK lib dir... " >&6; } - if test "x$with_dxsdk_lib" != x; then - DXSDK_LIB_PATH="$with_dxsdk_lib" - elif test "x$OPENJDK_TARGET_CPU" = "xx86_64"; then - DXSDK_LIB_PATH="$dxsdk_path/Lib/x64" - else - DXSDK_LIB_PATH="$dxsdk_path/Lib" - fi - # dsound.lib is linked to in jsoundds - if test ! -f "$DXSDK_LIB_PATH/dsound.lib"; then - as_fn_error $? "Invalid DirectX SDK lib dir" "$LINENO" 5 - fi - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DXSDK_LIB_PATH" >&5 -$as_echo "$DXSDK_LIB_PATH" >&6; } - - if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.cygwin"; then - - # Input might be given as Windows format, start by converting to - # unix format. - path="$DXSDK_LIB_PATH" - new_path=`$CYGPATH -u "$path"` - - # Cygwin tries to hide some aspects of the Windows file system, such that binaries are - # named .exe but called without that suffix. Therefore, "foo" and "foo.exe" are considered - # the same file, most of the time (as in "test -f"). But not when running cygpath -s, then - # "foo.exe" is OK but "foo" is an error. - # - # This test is therefore slightly more accurate than "test -f" to check for file precense. - # It is also a way to make sure we got the proper file name for the real test later on. - test_shortpath=`$CYGPATH -s -m "$new_path" 2> /dev/null` - if test "x$test_shortpath" = x; then - { $as_echo "$as_me:${as_lineno-$LINENO}: The path of DXSDK_LIB_PATH, which resolves as \"$path\", is invalid." >&5 -$as_echo "$as_me: The path of DXSDK_LIB_PATH, which resolves as \"$path\", is invalid." >&6;} - as_fn_error $? "Cannot locate the the path of DXSDK_LIB_PATH" "$LINENO" 5 - fi - - # Call helper function which possibly converts this using DOS-style short mode. - # If so, the updated path is stored in $new_path. - - input_path="$new_path" - # Check if we need to convert this using DOS-style short mode. If the path - # contains just simple characters, use it. Otherwise (spaces, weird characters), - # take no chances and rewrite it. - # Note: m4 eats our [], so we need to use [ and ] instead. - has_forbidden_chars=`$ECHO "$input_path" | $GREP [^-._/a-zA-Z0-9]` - if test "x$has_forbidden_chars" != x; then - # Now convert it to mixed DOS-style, short mode (no spaces, and / instead of \) - shortmode_path=`$CYGPATH -s -m -a "$input_path"` - path_after_shortmode=`$CYGPATH -u "$shortmode_path"` - if test "x$path_after_shortmode" != "x$input_to_shortpath"; then - # Going to short mode and back again did indeed matter. Since short mode is - # case insensitive, let's make it lowercase to improve readability. - shortmode_path=`$ECHO "$shortmode_path" | $TR 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` - # Now convert it back to Unix-stile (cygpath) - input_path=`$CYGPATH -u "$shortmode_path"` - new_path="$input_path" - fi - fi - - test_cygdrive_prefix=`$ECHO $input_path | $GREP ^/cygdrive/` - if test "x$test_cygdrive_prefix" = x; then - # As a simple fix, exclude /usr/bin since it's not a real path. - if test "x`$ECHO $new_path | $GREP ^/usr/bin/`" = x; then - # The path is in a Cygwin special directory (e.g. /home). We need this converted to - # a path prefixed by /cygdrive for fixpath to work. - new_path="$CYGWIN_ROOT_PATH$input_path" - fi - fi - - - if test "x$path" != "x$new_path"; then - DXSDK_LIB_PATH="$new_path" - { $as_echo "$as_me:${as_lineno-$LINENO}: Rewriting DXSDK_LIB_PATH to \"$new_path\"" >&5 -$as_echo "$as_me: Rewriting DXSDK_LIB_PATH to \"$new_path\"" >&6;} - fi - - elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then - - path="$DXSDK_LIB_PATH" - has_colon=`$ECHO $path | $GREP ^.:` - new_path="$path" - if test "x$has_colon" = x; then - # Not in mixed or Windows style, start by that. - new_path=`cmd //c echo $path` - fi - - - input_path="$new_path" - # Check if we need to convert this using DOS-style short mode. If the path - # contains just simple characters, use it. Otherwise (spaces, weird characters), - # take no chances and rewrite it. - # Note: m4 eats our [], so we need to use [ and ] instead. - has_forbidden_chars=`$ECHO "$input_path" | $GREP [^-_/:a-zA-Z0-9]` - if test "x$has_forbidden_chars" != x; then - # Now convert it to mixed DOS-style, short mode (no spaces, and / instead of \) - new_path=`cmd /c "for %A in (\"$input_path\") do @echo %~sA"|$TR \\\\\\\\ / | $TR 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` - fi - - - windows_path="$new_path" - if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.cygwin"; then - unix_path=`$CYGPATH -u "$windows_path"` - new_path="$unix_path" - elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then - unix_path=`$ECHO "$windows_path" | $SED -e 's,^\\(.\\):,/\\1,g' -e 's,\\\\,/,g'` - new_path="$unix_path" - fi - - if test "x$path" != "x$new_path"; then - DXSDK_LIB_PATH="$new_path" - { $as_echo "$as_me:${as_lineno-$LINENO}: Rewriting DXSDK_LIB_PATH to \"$new_path\"" >&5 -$as_echo "$as_me: Rewriting DXSDK_LIB_PATH to \"$new_path\"" >&6;} - fi - - # Save the first 10 bytes of this path to the storage, so fixpath can work. - all_fixpath_prefixes=("${all_fixpath_prefixes[@]}" "${new_path:0:10}") - - else - # We're on a posix platform. Hooray! :) - path="$DXSDK_LIB_PATH" - has_space=`$ECHO "$path" | $GREP " "` - if test "x$has_space" != x; then - { $as_echo "$as_me:${as_lineno-$LINENO}: The path of DXSDK_LIB_PATH, which resolves as \"$path\", is invalid." >&5 -$as_echo "$as_me: The path of DXSDK_LIB_PATH, which resolves as \"$path\", is invalid." >&6;} - as_fn_error $? "Spaces are not allowed in this path." "$LINENO" 5 - fi - - # Use eval to expand a potential ~ - eval path="$path" - if test ! -f "$path" && test ! -d "$path"; then - as_fn_error $? "The path of DXSDK_LIB_PATH, which resolves as \"$path\", is not found." "$LINENO" 5 - fi - - DXSDK_LIB_PATH="`cd "$path"; $THEPWDCMD -L`" - fi - - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for DirectX SDK include dir" >&5 -$as_echo_n "checking for DirectX SDK include dir... " >&6; } - if test "x$with_dxsdk_include" != x; then - DXSDK_INCLUDE_PATH="$with_dxsdk_include" - else - DXSDK_INCLUDE_PATH="$dxsdk_path/Include" - fi - # dsound.h is included in jsoundds - if test ! -f "$DXSDK_INCLUDE_PATH/dsound.h"; then - as_fn_error $? "Invalid DirectX SDK lib dir" "$LINENO" 5 - fi - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DXSDK_INCLUDE_PATH" >&5 -$as_echo "$DXSDK_INCLUDE_PATH" >&6; } - - if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.cygwin"; then - - # Input might be given as Windows format, start by converting to - # unix format. - path="$DXSDK_INCLUDE_PATH" - new_path=`$CYGPATH -u "$path"` - - # Cygwin tries to hide some aspects of the Windows file system, such that binaries are - # named .exe but called without that suffix. Therefore, "foo" and "foo.exe" are considered - # the same file, most of the time (as in "test -f"). But not when running cygpath -s, then - # "foo.exe" is OK but "foo" is an error. - # - # This test is therefore slightly more accurate than "test -f" to check for file precense. - # It is also a way to make sure we got the proper file name for the real test later on. - test_shortpath=`$CYGPATH -s -m "$new_path" 2> /dev/null` - if test "x$test_shortpath" = x; then - { $as_echo "$as_me:${as_lineno-$LINENO}: The path of DXSDK_INCLUDE_PATH, which resolves as \"$path\", is invalid." >&5 -$as_echo "$as_me: The path of DXSDK_INCLUDE_PATH, which resolves as \"$path\", is invalid." >&6;} - as_fn_error $? "Cannot locate the the path of DXSDK_INCLUDE_PATH" "$LINENO" 5 - fi - - # Call helper function which possibly converts this using DOS-style short mode. - # If so, the updated path is stored in $new_path. - - input_path="$new_path" - # Check if we need to convert this using DOS-style short mode. If the path - # contains just simple characters, use it. Otherwise (spaces, weird characters), - # take no chances and rewrite it. - # Note: m4 eats our [], so we need to use [ and ] instead. - has_forbidden_chars=`$ECHO "$input_path" | $GREP [^-._/a-zA-Z0-9]` - if test "x$has_forbidden_chars" != x; then - # Now convert it to mixed DOS-style, short mode (no spaces, and / instead of \) - shortmode_path=`$CYGPATH -s -m -a "$input_path"` - path_after_shortmode=`$CYGPATH -u "$shortmode_path"` - if test "x$path_after_shortmode" != "x$input_to_shortpath"; then - # Going to short mode and back again did indeed matter. Since short mode is - # case insensitive, let's make it lowercase to improve readability. - shortmode_path=`$ECHO "$shortmode_path" | $TR 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` - # Now convert it back to Unix-stile (cygpath) - input_path=`$CYGPATH -u "$shortmode_path"` - new_path="$input_path" - fi - fi - - test_cygdrive_prefix=`$ECHO $input_path | $GREP ^/cygdrive/` - if test "x$test_cygdrive_prefix" = x; then - # As a simple fix, exclude /usr/bin since it's not a real path. - if test "x`$ECHO $new_path | $GREP ^/usr/bin/`" = x; then - # The path is in a Cygwin special directory (e.g. /home). We need this converted to - # a path prefixed by /cygdrive for fixpath to work. - new_path="$CYGWIN_ROOT_PATH$input_path" - fi - fi - - - if test "x$path" != "x$new_path"; then - DXSDK_INCLUDE_PATH="$new_path" - { $as_echo "$as_me:${as_lineno-$LINENO}: Rewriting DXSDK_INCLUDE_PATH to \"$new_path\"" >&5 -$as_echo "$as_me: Rewriting DXSDK_INCLUDE_PATH to \"$new_path\"" >&6;} - fi - - elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then - - path="$DXSDK_INCLUDE_PATH" - has_colon=`$ECHO $path | $GREP ^.:` - new_path="$path" - if test "x$has_colon" = x; then - # Not in mixed or Windows style, start by that. - new_path=`cmd //c echo $path` - fi - - - input_path="$new_path" - # Check if we need to convert this using DOS-style short mode. If the path - # contains just simple characters, use it. Otherwise (spaces, weird characters), - # take no chances and rewrite it. - # Note: m4 eats our [], so we need to use [ and ] instead. - has_forbidden_chars=`$ECHO "$input_path" | $GREP [^-_/:a-zA-Z0-9]` - if test "x$has_forbidden_chars" != x; then - # Now convert it to mixed DOS-style, short mode (no spaces, and / instead of \) - new_path=`cmd /c "for %A in (\"$input_path\") do @echo %~sA"|$TR \\\\\\\\ / | $TR 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` - fi - - - windows_path="$new_path" - if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.cygwin"; then - unix_path=`$CYGPATH -u "$windows_path"` - new_path="$unix_path" - elif test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then - unix_path=`$ECHO "$windows_path" | $SED -e 's,^\\(.\\):,/\\1,g' -e 's,\\\\,/,g'` - new_path="$unix_path" - fi - - if test "x$path" != "x$new_path"; then - DXSDK_INCLUDE_PATH="$new_path" - { $as_echo "$as_me:${as_lineno-$LINENO}: Rewriting DXSDK_INCLUDE_PATH to \"$new_path\"" >&5 -$as_echo "$as_me: Rewriting DXSDK_INCLUDE_PATH to \"$new_path\"" >&6;} - fi - - # Save the first 10 bytes of this path to the storage, so fixpath can work. - all_fixpath_prefixes=("${all_fixpath_prefixes[@]}" "${new_path:0:10}") - - else - # We're on a posix platform. Hooray! :) - path="$DXSDK_INCLUDE_PATH" - has_space=`$ECHO "$path" | $GREP " "` - if test "x$has_space" != x; then - { $as_echo "$as_me:${as_lineno-$LINENO}: The path of DXSDK_INCLUDE_PATH, which resolves as \"$path\", is invalid." >&5 -$as_echo "$as_me: The path of DXSDK_INCLUDE_PATH, which resolves as \"$path\", is invalid." >&6;} - as_fn_error $? "Spaces are not allowed in this path." "$LINENO" 5 - fi - - # Use eval to expand a potential ~ - eval path="$path" - if test ! -f "$path" && test ! -d "$path"; then - as_fn_error $? "The path of DXSDK_INCLUDE_PATH, which resolves as \"$path\", is not found." "$LINENO" 5 - fi - - DXSDK_INCLUDE_PATH="`cd "$path"; $THEPWDCMD -L`" - fi - - - - - LDFLAGS_JDK="$LDFLAGS_JDK -libpath:$DXSDK_LIB_PATH" - fi diff --git a/common/autoconf/spec.gmk.in b/common/autoconf/spec.gmk.in index d2ffb614bcc..d44b3c8c973 100644 --- a/common/autoconf/spec.gmk.in +++ b/common/autoconf/spec.gmk.in @@ -291,10 +291,6 @@ X_CFLAGS:=@X_CFLAGS@ X_LIBS:=@X_LIBS@ OPENWIN_HOME:=@OPENWIN_HOME@ -# DirectX SDK -DXSDK_LIB_PATH=@DXSDK_LIB_PATH@ -DXSDK_INCLUDE_PATH=@DXSDK_INCLUDE_PATH@ - # The lowest required version of macosx to enforce compatiblity for MACOSX_VERSION_MIN=@MACOSX_VERSION_MIN@ diff --git a/common/autoconf/toolchain.m4 b/common/autoconf/toolchain.m4 index efaecc18960..b60f3e3c583 100644 --- a/common/autoconf/toolchain.m4 +++ b/common/autoconf/toolchain.m4 @@ -176,7 +176,6 @@ AC_DEFUN([TOOLCHAIN_SETUP_PATHS], [ if test "x$OPENJDK_TARGET_OS" = "xwindows"; then TOOLCHAIN_SETUP_VISUAL_STUDIO_ENV - TOOLCHAIN_SETUP_DXSDK fi AC_SUBST(MSVCR_DLL) diff --git a/common/autoconf/toolchain_windows.m4 b/common/autoconf/toolchain_windows.m4 index e5d4fff38f9..f97713f952f 100644 --- a/common/autoconf/toolchain_windows.m4 +++ b/common/autoconf/toolchain_windows.m4 @@ -277,61 +277,3 @@ AC_DEFUN([TOOLCHAIN_SETUP_VISUAL_STUDIO_ENV], AC_MSG_RESULT([$MSVCR_DLL]) BASIC_FIXUP_PATH(MSVCR_DLL) ]) - - -# Setup the DXSDK paths -AC_DEFUN([TOOLCHAIN_SETUP_DXSDK], -[ - AC_ARG_WITH(dxsdk, [AS_HELP_STRING([--with-dxsdk], - [the DirectX SDK (Windows only) @<:@probed@:>@])]) - AC_ARG_WITH(dxsdk-lib, [AS_HELP_STRING([--with-dxsdk-lib], - [the DirectX SDK lib directory (Windows only) @<:@probed@:>@])]) - AC_ARG_WITH(dxsdk-include, [AS_HELP_STRING([--with-dxsdk-include], - [the DirectX SDK include directory (Windows only) @<:@probed@:>@])]) - - AC_MSG_CHECKING([for DirectX SDK]) - - if test "x$with_dxsdk" != x; then - dxsdk_path="$with_dxsdk" - elif test "x$DXSDK_DIR" != x; then - dxsdk_path="$DXSDK_DIR" - elif test -d "C:/DXSDK"; then - dxsdk_path="C:/DXSDK" - else - AC_MSG_ERROR([Could not find the DirectX SDK]) - fi - AC_MSG_RESULT([$dxsdk_path]) - BASIC_FIXUP_PATH(dxsdk_path) - - AC_MSG_CHECKING([for DirectX SDK lib dir]) - if test "x$with_dxsdk_lib" != x; then - DXSDK_LIB_PATH="$with_dxsdk_lib" - elif test "x$OPENJDK_TARGET_CPU" = "xx86_64"; then - DXSDK_LIB_PATH="$dxsdk_path/Lib/x64" - else - DXSDK_LIB_PATH="$dxsdk_path/Lib" - fi - # dsound.lib is linked to in jsoundds - if test ! -f "$DXSDK_LIB_PATH/dsound.lib"; then - AC_MSG_ERROR([Invalid DirectX SDK lib dir]) - fi - AC_MSG_RESULT([$DXSDK_LIB_PATH]) - BASIC_FIXUP_PATH(DXSDK_LIB_PATH) - - AC_MSG_CHECKING([for DirectX SDK include dir]) - if test "x$with_dxsdk_include" != x; then - DXSDK_INCLUDE_PATH="$with_dxsdk_include" - else - DXSDK_INCLUDE_PATH="$dxsdk_path/Include" - fi - # dsound.h is included in jsoundds - if test ! -f "$DXSDK_INCLUDE_PATH/dsound.h"; then - AC_MSG_ERROR([Invalid DirectX SDK lib dir]) - fi - AC_MSG_RESULT([$DXSDK_INCLUDE_PATH]) - BASIC_FIXUP_PATH(DXSDK_INCLUDE_PATH) - - AC_SUBST(DXSDK_LIB_PATH) - AC_SUBST(DXSDK_INCLUDE_PATH) - LDFLAGS_JDK="$LDFLAGS_JDK -libpath:$DXSDK_LIB_PATH" -]) From 10fa6ae01ea94054b1f87df1d3a73746f15c3aff Mon Sep 17 00:00:00 2001 From: Vadim Pakhnushev Date: Thu, 12 Sep 2013 12:12:32 +0200 Subject: [PATCH 133/210] 8008022: Upgrade Direct X SDK used to build JDK Reviewed-by: erikj, prr, ihse --- jdk/make/Makefile | 12 ------ jdk/make/common/Defs-windows.gmk | 2 - jdk/make/common/Sanity.gmk | 1 - jdk/make/common/shared/Defs-versions.gmk | 4 -- jdk/make/common/shared/Defs-windows.gmk | 47 +--------------------- jdk/make/common/shared/Sanity-Settings.gmk | 4 -- jdk/make/common/shared/Sanity.gmk | 47 ---------------------- jdk/make/javax/sound/jsoundds/Makefile | 3 +- jdk/make/jdk_generic_profile.sh | 1 - jdk/make/netbeans/awt2d/README | 5 +-- jdk/make/sun/awt/Makefile | 1 - jdk/make/sun/jawt/Makefile | 1 - jdk/makefiles/CompileNativeLibraries.gmk | 7 +--- 13 files changed, 5 insertions(+), 130 deletions(-) diff --git a/jdk/make/Makefile b/jdk/make/Makefile index c2db5a816a2..e82edd7271f 100644 --- a/jdk/make/Makefile +++ b/jdk/make/Makefile @@ -99,7 +99,6 @@ COMPILER_PATH.desc = Compiler install directory CACERTS_FILE.desc = Location of certificates file DEVTOOLS_PATH.desc = Directory containing zip and unzip CUPS_HEADERS_PATH.desc = Include directory location for CUPS header files -DXSDK_PATH.desc = Root directory of DirectX SDK # Make variables to print out (description and value) VARIABLE_PRINTVAL_LIST += \ @@ -128,17 +127,6 @@ VARIABLE_CHECKDIR_LIST += \ VARIABLE_CHECKFIL_LIST += \ CACERTS_FILE -# Some are windows specific -ifeq ($(PLATFORM), windows) - -VARIABLE_PRINTVAL_LIST += \ - DXSDK_PATH - -VARIABLE_CHECKDIR_LIST += \ - DXSDK_PATH - -endif - # For pattern rules below, so all are treated the same DO_PRINTVAL_LIST=$(VARIABLE_PRINTVAL_LIST:%=%.printval) DO_CHECKDIR_LIST=$(VARIABLE_CHECKDIR_LIST:%=%.checkdir) diff --git a/jdk/make/common/Defs-windows.gmk b/jdk/make/common/Defs-windows.gmk index c5c15b3d387..ef2c4aeab6f 100644 --- a/jdk/make/common/Defs-windows.gmk +++ b/jdk/make/common/Defs-windows.gmk @@ -78,8 +78,6 @@ ifeq ($(COMPILER_VERSION), VS2010) MS_RUNTIME_LIBRARIES = $(MSVCRNN_DLL) endif -EXTRA_LFLAGS += -LIBPATH:$(DXSDK_LIB_PATH) - # Full Debug Symbols has been enabled on Windows since JDK1.4.1. # The Full Debug Symbols (FDS) default for VARIANT == OPT builds is # enabled with debug info files ZIP'ed to save space. For VARIANT != diff --git a/jdk/make/common/Sanity.gmk b/jdk/make/common/Sanity.gmk index 25f5fa7bfe8..233abeacabb 100644 --- a/jdk/make/common/Sanity.gmk +++ b/jdk/make/common/Sanity.gmk @@ -65,7 +65,6 @@ sanity-base: pre-sanity \ sane-libCrun \ sane-unixccs_path \ sane-msdevtools_path \ - sane-dxsdk \ sane-compiler \ sane-cacerts \ sane-ant_version \ diff --git a/jdk/make/common/shared/Defs-versions.gmk b/jdk/make/common/shared/Defs-versions.gmk index 8a60563c122..a3a53c5c048 100644 --- a/jdk/make/common/shared/Defs-versions.gmk +++ b/jdk/make/common/shared/Defs-versions.gmk @@ -74,9 +74,6 @@ endif # REQUIRED_CYGWIN_VER # Windows only: If CYGWIN is used, the minimum CYGWIN version. # -# REQUIRED_DXSDK_VER -# Windows only: The version of DirectX SDK expected. -# # REQUIRED_FREETYPE_VERSION # If we are using freetype, the freetype version expected. # @@ -193,7 +190,6 @@ ifeq ($(PLATFORM), windows) REQUIRED_OS_VARIANT_VERSION = $(REQUIRED_OS_VERSION) REQUIRED_CYGWIN_VER = 4.0 REQUIRED_MKS_VER = 6.1 - REQUIRED_DXSDK_VER = 0x0900 ifeq ($(CC_VERSION),msvc) REQUIRED_COMPILER_NAME = Visual Studio 10 REQUIRED_COMPILER_VERSION = VS2010 diff --git a/jdk/make/common/shared/Defs-windows.gmk b/jdk/make/common/shared/Defs-windows.gmk index 40415547d71..d46d884cc05 100644 --- a/jdk/make/common/shared/Defs-windows.gmk +++ b/jdk/make/common/shared/Defs-windows.gmk @@ -79,7 +79,7 @@ override INCREMENTAL_BUILD = false # The ALT values should never really have spaces or use \. # Suspect these environment variables to have spaces and/or \ characters: # SYSTEMROOT, SystemRoot, WINDIR, windir, PROGRAMFILES, ProgramFiles, -# DXSDK_DIR, MSTOOLS, Mstools, MSSDK, MSSdk, VCnnCOMNTOOLS, +# MSTOOLS, Mstools, MSSDK, MSSdk, VCnnCOMNTOOLS, # MSVCDIR, MSVCDir. # So use $(subst \,/,) on them first adding quotes and placing them in # their own variable assigned with :=, then use FullPath. @@ -255,18 +255,6 @@ ifneq ($(word 1,$(_program_files)),$(_program_files)) _program_files:= endif -# DirectX SDK -ifdef ALT_DXSDK_DRIVE - _dx_sdk_dir =$(ALT_DXSDK_DRIVE):/DXSDK -else - ifdef DXSDK_DIR - xDXSDK_DIR :="$(subst \,/,$(DXSDK_DIR))" - else - xDXSDK_DIR :="$(_system_drive)/DXSDK" - endif - _dx_sdk_dir :=$(call FullPath,$(xDXSDK_DIR)) -endif - # Use of the Visual Studio compilers requires certain env variables be set: # PATH should include the path to cl.exe # INCLUDE should be defined @@ -489,39 +477,6 @@ ifeq ($(_NEEDS_MSVCRNN), true) MSVCRNN_DLL_PATH:=$(call AltCheckValue,MSVCRNN_DLL_PATH) endif -# DXSDK_PATH: path to Microsoft DirectX SDK Include and Lib -ifdef ALT_DXSDK_PATH - xALT_DXSDK_PATH :="$(subst \,/,$(ALT_DXSDK_PATH))" - DXSDK_PATH :=$(call FullPath,$(xALT_DXSDK_PATH)) -else - _DXSDK_PATH1 :=$(_dx_sdk_dir) - _DXSDK_PATH2 :=$(JDK_DEVTOOLS_DIR)/windows/dxsdk - DXSDK_PATH :=$(call DirExists,$(_DXSDK_PATH1),$(_DXSDK_PATH2),$(_dx_sdk_dir)) -endif -DXSDK_PATH :=$(call AltCheckSpaces,DXSDK_PATH) -DXSDK_PATH:=$(call AltCheckValue,DXSDK_PATH) - -# DXSDK_INCLUDE_PATH: path to Microsoft DirectX SDK Include -ifdef ALT_DXSDK_INCLUDE_PATH - xALT_DXSDK_INCLUDE_PATH :="$(subst \,/,$(ALT_DXSDK_INCLUDE_PATH))" - DXSDK_INCLUDE_PATH :=$(call FullPath,$(xALT_DXSDK_INCLUDE_PATH)) -else - DXSDK_INCLUDE_PATH =$(subst //,/,$(DXSDK_PATH)/Include) -endif - -# DXSDK_LIB_PATH: path to Microsoft DirectX SDK Lib -ifdef ALT_DXSDK_LIB_PATH - xALT_DXSDK_LIB_PATH :="$(subst \,/,$(ALT_DXSDK_LIB_PATH))" - DXSDK_LIB_PATH :=$(call FullPath,$(xALT_DXSDK_LIB_PATH)) -else - ifeq ($(ARCH_DATA_MODEL), 64) - # 64bit libs are located in "Lib/x64" subdir - DXSDK_LIB_PATH =$(subst //,/,$(DXSDK_PATH)/Lib/x64) - else - DXSDK_LIB_PATH =$(subst //,/,$(DXSDK_PATH)/Lib) - endif -endif - # DEPLOY_MSSDK: Microsoft SDK for this platform (for deploy) ifdef ALT_DEPLOY_MSSDK xALT_DEPLOY_MSSDK :="$(subst \,/,$(ALT_DEPLOY_MSSDK))" diff --git a/jdk/make/common/shared/Sanity-Settings.gmk b/jdk/make/common/shared/Sanity-Settings.gmk index ea32eeadcaa..2ceef21e13e 100644 --- a/jdk/make/common/shared/Sanity-Settings.gmk +++ b/jdk/make/common/shared/Sanity-Settings.gmk @@ -234,10 +234,6 @@ endif ALL_SETTINGS+=$(call addAltSetting,HOTSPOT_SERVER_PATH) ifeq ($(PLATFORM),windows) ALL_SETTINGS+=$(call addAltSetting,HOTSPOT_LIB_PATH) - ALL_SETTINGS+=$(call addRequiredSetting,DXSDK_VER) - ALL_SETTINGS+=$(call addAltSetting,DXSDK_PATH) - ALL_SETTINGS+=$(call addAltSetting,DXSDK_INCLUDE_PATH) - ALL_SETTINGS+=$(call addAltSetting,DXSDK_LIB_PATH) ALL_SETTINGS+=$(call addAltSetting,WINDOWSSDKDIR) ALL_SETTINGS+=$(call addRequiredSetting,RC) ALL_SETTINGS+=$(call addRequiredSetting,REBASE) diff --git a/jdk/make/common/shared/Sanity.gmk b/jdk/make/common/shared/Sanity.gmk index c4a96d73c5f..a9f4692064a 100644 --- a/jdk/make/common/shared/Sanity.gmk +++ b/jdk/make/common/shared/Sanity.gmk @@ -143,8 +143,6 @@ ifeq ($(PLATFORM), windows) _CYGWIN_VER := $(SYSTEM_UNAME) CYGWIN_VER :=$(call GetVersion,$(_CYGWIN_VER)) endif - DXSDK_VER := $(shell $(EGREP) DIRECT3D_VERSION $(DXSDK_INCLUDE_PATH)/d3d9.h 2>&1 | \ - $(EGREP) "\#define" | $(NAWK) '{print $$3}') endif # Get the version numbers of what we are using @@ -1300,51 +1298,6 @@ sane-unzip_version: "" >> $(WARNING_FILE) ; \ fi -###################################################### -# Check for windows DirectX sdk directory -###################################################### -sane-dxsdk: -ifeq ($(PLATFORM), windows) - @if [ ! -r $(DXSDK_INCLUDE_PATH)/d3d9.h ]; then \ - $(ECHO) "ERROR: You do not have access to a valid DirectX SDK Include dir.\n" \ - " The value of DXSDK_INCLUDE_PATH must point a valid DX SDK dir.\n" \ - " Please check your access to \n" \ - " $(DXSDK_INCLUDE_PATH) \n" \ - " and/or check your value of ALT_DXSDK_PATH or ALT_DXSDK_INCLUDE_PATH.\n" \ - " Microsoft DirectX 9 SDK (Summer 2004 Update or newer) can be downloaded from the following location:\n" \ - " http://msdn.microsoft.com/library/default.asp?url=/downloads/list/directx.asp\n" \ - " Or http://www.microsoft.com/directx\n" \ - "" >> $(ERROR_FILE) ; \ - else \ - if [ ! "$(DXSDK_VER)" = "$(REQUIRED_DXSDK_VER)" ]; then \ - $(ECHO) "ERROR: The DirectX SDK must be version $(REQUIRED_DXSDK_VER).\n" \ - " $(YOU_ARE_USING) DirectX SDK version: $(DXSDK_VER)\n" \ - " The DirectX SDK was obtained from the following location: \n" \ - " $(DXSDK_PATH) \n" \ - " Please change your DirectX SDK. \n" \ - " Microsoft DirectX 9 SDK (Summer 2004 Update or newer) can be downloaded from the following location:\n" \ - " http://msdn.microsoft.com/library/default.asp?url=/downloads/list/directx.asp\n" \ - " Or http://www.microsoft.com/directx\n" \ - "" >> $(ERROR_FILE) ; \ - else \ - if [ -r $(DXSDK_INCLUDE_PATH)/basetsd.h ]; then \ - if [ `$(EGREP) -c __int3264 $(DXSDK_INCLUDE_PATH)/basetsd.h` -ne 0 ]; then \ - $(ECHO) "WARNING: The DirectX SDK Include directory contains a newer basetsd.h,\n" \ - " which may indicate that you're using an incorrect version of DirectX SDK.\n" \ - " This may result in a build failure.\n" \ - " The DirectX SDK Include dir was obtained from the following location:\n" \ - " $(DXSDK_INCLUDE_PATH) \n" \ - " Please change your DirectX SDK to version 9 (Summer 2004 Update or newer).\n" \ - " Microsoft DirectX 9 SDK can be downloaded from the following location:\n" \ - " http://msdn.microsoft.com/library/default.asp?url=/downloads/list/directx.asp\n" \ - " Or http://www.microsoft.com/directx\n" \ - "" >> $(WARNING_FILE) ; \ - fi \ - fi \ - fi \ - fi -endif - ###################################################### # Check the linker version(s) ###################################################### diff --git a/jdk/make/javax/sound/jsoundds/Makefile b/jdk/make/javax/sound/jsoundds/Makefile index f476b39811a..a747d699a0a 100644 --- a/jdk/make/javax/sound/jsoundds/Makefile +++ b/jdk/make/javax/sound/jsoundds/Makefile @@ -55,8 +55,7 @@ FILES_export = \ LDLIBS += dsound.lib winmm.lib user32.lib ole32.lib CPPFLAGS += \ -DUSE_DAUDIO=TRUE \ - -I$(SHARE_SRC)/native/com/sun/media/sound \ - -I$(DXSDK_INCLUDE_PATH) + -I$(SHARE_SRC)/native/com/sun/media/sound # # Add to the ambient VPATH. diff --git a/jdk/make/jdk_generic_profile.sh b/jdk/make/jdk_generic_profile.sh index 28705393a33..1103a56aa52 100644 --- a/jdk/make/jdk_generic_profile.sh +++ b/jdk/make/jdk_generic_profile.sh @@ -80,7 +80,6 @@ # ALT_BOOTDIR # Windows Only: # ALT_UNIXCOMMAND_PATH -# ALT_DXSDK_PATH # ALT_MSVCRNN_DLL_PATH # ############################################################################# diff --git a/jdk/make/netbeans/awt2d/README b/jdk/make/netbeans/awt2d/README index 040c9e76919..4df566dd157 100644 --- a/jdk/make/netbeans/awt2d/README +++ b/jdk/make/netbeans/awt2d/README @@ -39,7 +39,6 @@ Here are the steps: (on Windows): #>env | grep ALT ALT_JDK_IMPORT_PATH=c:/devtools/java/jdk1.7.0 - ALT_DXSDK_PATH=c:/devtools/DirectX/DXSDK_Dec06 ALT_BOOTDIR=c:/DevTools/java/jdk1.6.0 If your build is a FASTDEBUG build, don't forget @@ -50,7 +49,6 @@ Here are the steps: accordingly: make.options=\ ALT_JDK_IMPORT_PATH=c:/devtools/java/jdk1.7.0 \ - ALT_DXSDK_PATH=c:/devtools/DirectX/DXSDK_Dec06 \ ALT_BOOTDIR=c:/DevTools/java/jdk1.6.0 \ FASTDEBUG=true make=c:/devtools/cygwin/bin/make @@ -175,7 +173,6 @@ Notes on using CND (C/C++ pack) with this project and NetBeans. ../../build/windows-i586/tmp/sun/sun.awt/splashscreen/CClassHeaders; ../../build/windows-i586/tmp/sun/sun.font/fontmanager/CClassHeaders; ../../build/windows-i586/tmp/sun/sun.font/t2k/CClassHeaders; - C:/DevTools/DirectX/DXSDK_Dec06/Include; C:/devtools/VS2003/SDK/v1.1/include; C:/devtools/VS2003/VC7/ATLMFC/INCLUDE; C:/devtools/VS2003/VC7/INCLUDE; @@ -188,7 +185,7 @@ Notes on using CND (C/C++ pack) with this project and NetBeans. Note that most paths are relative to the native project directory - this helps if you decide to relocate the workspace later. The ones that aren't relative are paths to external include directories, like those - of the Platform SDK, DirectX SDK. + of the Platform SDK. On Unix platforms these may be directories like /usr/include. The parser must know some defines to correctly parse the source files, diff --git a/jdk/make/sun/awt/Makefile b/jdk/make/sun/awt/Makefile index dc4c250cf74..8b7612e416a 100644 --- a/jdk/make/sun/awt/Makefile +++ b/jdk/make/sun/awt/Makefile @@ -564,7 +564,6 @@ OTHER_INCLUDES += -I$(CLASSHDRDIR)/../../java/jvm \ -I$(OBJDIR) \ -I$(SHARE_SRC)/native/common \ -I$(WINAWT_native) \ - -I$(DXSDK_INCLUDE_PATH) \ -I$(SHARE_SRC)/native/sun/awt/image/cvutils \ -I$(SHARE_SRC)/native/sun/awt/image \ -I$(SHARE_SRC)/native/sun/java2d/loops \ diff --git a/jdk/make/sun/jawt/Makefile b/jdk/make/sun/jawt/Makefile index 718fb33c499..0520fc17bf1 100644 --- a/jdk/make/sun/jawt/Makefile +++ b/jdk/make/sun/jawt/Makefile @@ -69,7 +69,6 @@ OTHER_CXXFLAGS += $(GX_OPTION) -DUNICODE -D_UNICODE # Other extra flags needed for compiling. # CPPFLAGS += -I$(SHARE_SRC)/native/common \ - -I$(DXSDK_INCLUDE_PATH) \ -I$(PLATFORM_SRC)/native/sun/windows \ -I$(CLASSHDRDIR)/../../awt/CClassHeaders \ -I$(SHARE_SRC)/native/sun/awt/debug \ diff --git a/jdk/makefiles/CompileNativeLibraries.gmk b/jdk/makefiles/CompileNativeLibraries.gmk index 656ee3c4841..79204e0a3e0 100644 --- a/jdk/makefiles/CompileNativeLibraries.gmk +++ b/jdk/makefiles/CompileNativeLibraries.gmk @@ -472,7 +472,6 @@ ifeq ($(OPENJDK_TARGET_OS),windows) $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/windows \ $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/java2d/windows \ $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/java2d/d3d - LIBAWT_CFLAGS+=-I$(DXSDK_INCLUDE_PATH) else LIBAWT_DIRS+=\ $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/java2d/x11 @@ -1482,8 +1481,7 @@ ifeq ($(OPENJDK_TARGET_OS), windows) -I$(JDK_TOPDIR)/src/share/native/sun/awt/debug \ -I$(JDK_TOPDIR)/src/share/native/sun/java2d \ -I$(JDK_TOPDIR)/src/share/native/sun/awt/image/cvutils \ - -I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/java2d/windows \ - -I$(DXSDK_INCLUDE_PATH), \ + -I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/java2d/windows, \ LDFLAGS:=$(LDFLAGS_JDKLIB) $(KERNEL32_LIB) $(LDFLAGS_CXX_JDK) \ advapi32.lib $(WIN_AWT_LIB),\ LDFLAGS_SUFFIX:=$(LDFLAGS_JDKLIB_SUFFIX),\ @@ -2961,8 +2959,7 @@ $(eval $(call SetupNativeCompilation,BUILD_LIBJSOUNDDS,\ OPTIMIZATION:=LOW, \ CFLAGS:=$(CFLAGS_JDKLIB) \ $(LIBJSOUND_CFLAGS) \ - -DUSE_DAUDIO=TRUE \ - -I$(DXSDK_INCLUDE_PATH), \ + -DUSE_DAUDIO=TRUE, \ LDFLAGS:=$(LDFLAGS_JDKLIB) $(LDFLAGS_CXX_JDK) \ $(call SET_SHARED_LIBRARY_ORIGIN),\ LDFLAGS_SUFFIX:=$(LDFLAGS_JDKLIB_SUFFIX) dsound.lib winmm.lib user32.lib ole32.lib,\ From dc7c7c5e1361ab08d3c251f7fcaadf1aca4eff6c Mon Sep 17 00:00:00 2001 From: Dmitry Samersoff Date: Thu, 12 Sep 2013 15:53:49 +0400 Subject: [PATCH 134/210] 8022617: Openjdk hotspot build is broken on BSD platforms using gcc Enforce of preprocessing of all assembly sources by assembler-with-cpp Reviewed-by: dholmes, erikj --- hotspot/make/bsd/makefiles/gcc.make | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/hotspot/make/bsd/makefiles/gcc.make b/hotspot/make/bsd/makefiles/gcc.make index b98485f901d..0277bb66aa3 100644 --- a/hotspot/make/bsd/makefiles/gcc.make +++ b/hotspot/make/bsd/makefiles/gcc.make @@ -80,7 +80,7 @@ ifeq ($(SPEC),) HOSTCC = $(CC) endif - AS = $(CC) -c -x assembler-with-cpp + AS = $(CC) -c endif @@ -347,6 +347,13 @@ ifeq ($(OS_VENDOR), Darwin) LDFLAGS += -mmacosx-version-min=$(MACOSX_VERSION_MIN) endif + +#------------------------------------------------------------------------ +# Assembler flags + +# Enforce prerpocessing of .s files +ASFLAGS += -x assembler-with-cpp + #------------------------------------------------------------------------ # Linker flags From f0058a6c7e72240f10bc9dd2efe9ec678721966f Mon Sep 17 00:00:00 2001 From: Christine Lu Date: Thu, 12 Sep 2013 11:08:54 -0700 Subject: [PATCH 135/210] Added tag jdk8-b107 for changeset 2c525ed65d4c --- .hgtags-top-repo | 1 + 1 file changed, 1 insertion(+) diff --git a/.hgtags-top-repo b/.hgtags-top-repo index ca1497b3968..d83fa5ca611 100644 --- a/.hgtags-top-repo +++ b/.hgtags-top-repo @@ -228,3 +228,4 @@ b7e64be81c8a7690703df5711f4fc2375da8a9cb jdk8-b103 96c1b9b7524b52c3fcefc90ffad4c767396727c8 jdk8-b104 5166118c59178b5d31001bc4058e92486ee07d9b jdk8-b105 8e7b4d9fb00fdf1334376aeac050c9bca6d1b383 jdk8-b106 +0874bb4707b723d5bb108d379c557cf41529d1a7 jdk8-b107 From a6085bc97e1eb5bad42140a1c7f9ab14ea1d8657 Mon Sep 17 00:00:00 2001 From: Christine Lu Date: Thu, 12 Sep 2013 11:08:55 -0700 Subject: [PATCH 136/210] Added tag jdk8-b107 for changeset 03623ef0f781 --- corba/.hgtags | 1 + 1 file changed, 1 insertion(+) diff --git a/corba/.hgtags b/corba/.hgtags index f96b90eb232..e24845b3555 100644 --- a/corba/.hgtags +++ b/corba/.hgtags @@ -228,3 +228,4 @@ a013024b07475782f1fa8e196e950b34b4077663 jdk8-b101 d411c60a8c2fe8fdc572af907775e90f7eefd513 jdk8-b104 4e38de7c767e34104fa147b5b346d9fe6b731279 jdk8-b105 2e3a056c84a71eba78945c18b05397858ffd7ad0 jdk8-b106 +23fc34133152692b725db4bd617b4c8dfd6ccb05 jdk8-b107 From 32856d517b4dba9f78a9b4b6a2901e336bb7c34f Mon Sep 17 00:00:00 2001 From: Christine Lu Date: Thu, 12 Sep 2013 11:08:59 -0700 Subject: [PATCH 137/210] Added tag jdk8-b107 for changeset c86a71fcceaf --- hotspot/.hgtags | 1 + 1 file changed, 1 insertion(+) diff --git a/hotspot/.hgtags b/hotspot/.hgtags index bc3aba45318..8d3f958c431 100644 --- a/hotspot/.hgtags +++ b/hotspot/.hgtags @@ -375,3 +375,4 @@ acac3bde66b2c22791c257a8d99611d6d08c6713 jdk8-b105 18b4798adbc42c6fa16f5ecb7d5cd3ca130754bf hs25-b48 aed585cafc0d9655726af6d1e1081d1c94cb3b5c jdk8-b106 50794d8ac11c9579b41dec4de23b808fef9f34a1 hs25-b49 +5b7f90aab3ad25a25b75b7b2bb18d5ae23d8231c jdk8-b107 From f6cfa523c73a3670e521d0eeafebce9e8cff7539 Mon Sep 17 00:00:00 2001 From: Christine Lu Date: Thu, 12 Sep 2013 11:09:06 -0700 Subject: [PATCH 138/210] Added tag jdk8-b107 for changeset 82c75a285e35 --- jaxp/.hgtags | 1 + 1 file changed, 1 insertion(+) diff --git a/jaxp/.hgtags b/jaxp/.hgtags index e21e3e57573..e136f4f7d31 100644 --- a/jaxp/.hgtags +++ b/jaxp/.hgtags @@ -228,3 +228,4 @@ b1ceab582fc6d795b20aaa8a3fde2eba34af9399 jdk8-b103 a22fe9bd01e6c7e7ddc7995dfc9471711692b8d1 jdk8-b104 09a46ec11f880154886c70be03aff5ab2ddf0ab7 jdk8-b105 d3be8e3b429df917e72c1c23e7920c651219b587 jdk8-b106 +d6a32e3831aab20a9a3bc78cdc0a60aaad725c6c jdk8-b107 From b406ae898bafd8f0e43dcdbb375e334ea9e296a0 Mon Sep 17 00:00:00 2001 From: Christine Lu Date: Thu, 12 Sep 2013 11:09:08 -0700 Subject: [PATCH 139/210] Added tag jdk8-b107 for changeset 8a84d7cf2ea6 --- jaxws/.hgtags | 1 + 1 file changed, 1 insertion(+) diff --git a/jaxws/.hgtags b/jaxws/.hgtags index d213728514a..164a718d39c 100644 --- a/jaxws/.hgtags +++ b/jaxws/.hgtags @@ -228,3 +228,4 @@ b1fb4612a2caea52b5661b87509e560fa044b194 jdk8-b98 42211ab0ab1cca51a050d184634cf1db7ef81fbf jdk8-b104 88390df7ed2cf128298a02c5e6d978f0a603cd58 jdk8-b105 6908370afe834ff01739e8ec992d4246c74b7e6e jdk8-b106 +e3c9328f75638289a342ce15fbe532f05078946e jdk8-b107 From ccef21daceb606ea375e16e970047a8991e8818a Mon Sep 17 00:00:00 2001 From: Christine Lu Date: Thu, 12 Sep 2013 11:09:11 -0700 Subject: [PATCH 140/210] Added tag jdk8-b107 for changeset 55dd1a0fe510 --- jdk/.hgtags | 1 + 1 file changed, 1 insertion(+) diff --git a/jdk/.hgtags b/jdk/.hgtags index c20c5cde8f0..3e3a625970b 100644 --- a/jdk/.hgtags +++ b/jdk/.hgtags @@ -228,3 +228,4 @@ e0f6039c0290b7381042a6fec3100a69a5a67e37 jdk8-b103 f1d8d15bfcb5ada858a942f8a31f6598f23214d1 jdk8-b104 1fe211ae3d2b8cc2dfc4f58d9a6eb96418679672 jdk8-b105 c817276bd870dfe1dcc3a3dbbc092436b6907f75 jdk8-b106 +eea685b9ccaa1980e0a7e07d6a3a84bcc7e9ab82 jdk8-b107 From 2de4350911f9ac388424d5e40d7fe0105708848e Mon Sep 17 00:00:00 2001 From: Christine Lu Date: Thu, 12 Sep 2013 11:09:20 -0700 Subject: [PATCH 141/210] Added tag jdk8-b107 for changeset bd69808a67e1 --- langtools/.hgtags | 1 + 1 file changed, 1 insertion(+) diff --git a/langtools/.hgtags b/langtools/.hgtags index d15910c1e57..f3ac2a1e9ab 100644 --- a/langtools/.hgtags +++ b/langtools/.hgtags @@ -228,3 +228,4 @@ ce5a90df517bdceb2739d7dd3e6764b070def802 jdk8-b98 dd4a00c220c6e14d9b2ce93a2bd436a1d04f0d03 jdk8-b104 375834b5cf086dd7ce9e49f602d81bb51d3e0fa9 jdk8-b105 fcd768844b9926c5f994292ec6350c20cc7c0f76 jdk8-b106 +3f274927ec1863544b8214262ab02b7de2970da6 jdk8-b107 From 9ce24938888f1c969b45282ac396b2ab58f5ab75 Mon Sep 17 00:00:00 2001 From: Christine Lu Date: Thu, 12 Sep 2013 11:09:22 -0700 Subject: [PATCH 142/210] Added tag jdk8-b107 for changeset e94578d4e6a5 --- nashorn/.hgtags | 1 + 1 file changed, 1 insertion(+) diff --git a/nashorn/.hgtags b/nashorn/.hgtags index 0cc3a707a66..05fbb43822b 100644 --- a/nashorn/.hgtags +++ b/nashorn/.hgtags @@ -216,3 +216,4 @@ e966ff0a3ffef8a687eaf5a14167bb595b623d02 jdk8-b102 afc100513451d22f0b8135999d6eb52f36df3d36 jdk8-b104 f484bfb624dd06683cb33b524700a5dd4927a82b jdk8-b105 bf70cbd2c8369fd97ffdfcbe1a80dbc2797408ee jdk8-b106 +f35e1255024b66f7cf82517798f45f6e194e5567 jdk8-b107 From 914b1751c4fe4c7ad42e777c066439c3e133e1ad Mon Sep 17 00:00:00 2001 From: Eric McCorkle Date: Thu, 12 Sep 2013 14:52:28 -0400 Subject: [PATCH 143/210] 8013846: javac fails to reject semantically equivalent generic method declarations Cause javac to consider intersection types with the same elements to be equal regardless of order. Reviewed-by: jjg, vromero --- .../com/sun/tools/javac/comp/Check.java | 4 +++- .../generics/neg/OrderedIntersections.java | 21 +++++++++++++++++++ .../generics/neg/OrderedIntersections.out | 2 ++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 langtools/test/tools/javac/generics/neg/OrderedIntersections.java create mode 100644 langtools/test/tools/javac/generics/neg/OrderedIntersections.out diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java b/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java index 59d6c7b4468..2612741ac03 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java @@ -3340,7 +3340,9 @@ public class Check { (e.sym.flags() & CLASH) == 0 && sym.kind == e.sym.kind && sym.name != names.error && - (sym.kind != MTH || types.hasSameArgs(types.erasure(sym.type), types.erasure(e.sym.type)))) { + (sym.kind != MTH || + types.hasSameArgs(sym.type, e.sym.type) || + types.hasSameArgs(types.erasure(sym.type), types.erasure(e.sym.type)))) { if ((sym.flags() & VARARGS) != (e.sym.flags() & VARARGS)) { varargsDuplicateError(pos, sym, e.sym); return true; diff --git a/langtools/test/tools/javac/generics/neg/OrderedIntersections.java b/langtools/test/tools/javac/generics/neg/OrderedIntersections.java new file mode 100644 index 00000000000..2213ac5a78a --- /dev/null +++ b/langtools/test/tools/javac/generics/neg/OrderedIntersections.java @@ -0,0 +1,21 @@ +/* + * @test /nodynamiccopyright/ + * @bug 6962494 + * @summary The order of elements of intersection types shouldn't matter + * @compile/fail/ref=OrderedIntersections.out -XDrawDiagnostics OrderedIntersections.java + */ + +interface i1 {} +interface i2 {} + +public class OrderedIntersections { + static Object smf(t1 x) { + System.out.println( " smf1 " ); + return null; + } + + static Object smf(t2 x) { + System.out.println( " smf2 " ); + return null; + } +} diff --git a/langtools/test/tools/javac/generics/neg/OrderedIntersections.out b/langtools/test/tools/javac/generics/neg/OrderedIntersections.out new file mode 100644 index 00000000000..69deb46b26d --- /dev/null +++ b/langtools/test/tools/javac/generics/neg/OrderedIntersections.out @@ -0,0 +1,2 @@ +OrderedIntersections.java:17:40: compiler.err.already.defined: kindname.method, smf(t1), kindname.class, OrderedIntersections +1 error From 350906807bf274a05000522a64e683da309dff94 Mon Sep 17 00:00:00 2001 From: Niclas Adlertz Date: Thu, 12 Sep 2013 23:13:45 +0200 Subject: [PATCH 144/210] 8024646: Remove LRG_List container, replace it with GrowableArray We already have GrowableArray, use it instead of LRG_List Reviewed-by: kvn --- hotspot/src/share/vm/opto/chaitin.cpp | 42 ++++++++------------------ hotspot/src/share/vm/opto/chaitin.hpp | 34 ++++++++++----------- hotspot/src/share/vm/opto/coalesce.hpp | 1 - hotspot/src/share/vm/opto/live.cpp | 10 +++--- hotspot/src/share/vm/opto/live.hpp | 22 +------------- 5 files changed, 36 insertions(+), 73 deletions(-) diff --git a/hotspot/src/share/vm/opto/chaitin.cpp b/hotspot/src/share/vm/opto/chaitin.cpp index a1a0e1c1fb7..492bf384f2f 100644 --- a/hotspot/src/share/vm/opto/chaitin.cpp +++ b/hotspot/src/share/vm/opto/chaitin.cpp @@ -122,40 +122,23 @@ double LRG::score() const { return score; } -LRG_List::LRG_List( uint max ) : _cnt(max), _max(max), _lidxs(NEW_RESOURCE_ARRAY(uint,max)) { - memset( _lidxs, 0, sizeof(uint)*max ); -} - -void LRG_List::extend( uint nidx, uint lidx ) { - _nesting.check(); - if( nidx >= _max ) { - uint size = 16; - while( size <= nidx ) size <<=1; - _lidxs = REALLOC_RESOURCE_ARRAY( uint, _lidxs, _max, size ); - _max = size; - } - while( _cnt <= nidx ) - _lidxs[_cnt++] = 0; - _lidxs[nidx] = lidx; -} - #define NUMBUCKS 3 // Straight out of Tarjan's union-find algorithm uint LiveRangeMap::find_compress(uint lrg) { uint cur = lrg; - uint next = _uf_map[cur]; + uint next = _uf_map.at(cur); while (next != cur) { // Scan chain of equivalences assert( next < cur, "always union smaller"); cur = next; // until find a fixed-point - next = _uf_map[cur]; + next = _uf_map.at(cur); } // Core of union-find algorithm: update chain of // equivalences to be equal to the root. while (lrg != next) { - uint tmp = _uf_map[lrg]; - _uf_map.map(lrg, next); + uint tmp = _uf_map.at(lrg); + _uf_map.at_put(lrg, next); lrg = tmp; } return lrg; @@ -165,10 +148,10 @@ uint LiveRangeMap::find_compress(uint lrg) { void LiveRangeMap::reset_uf_map(uint max_lrg_id) { _max_lrg_id= max_lrg_id; // Force the Union-Find mapping to be at least this large - _uf_map.extend(_max_lrg_id, 0); + _uf_map.at_put_grow(_max_lrg_id, 0); // Initialize it to be the ID mapping. for (uint i = 0; i < _max_lrg_id; ++i) { - _uf_map.map(i, i); + _uf_map.at_put(i, i); } } @@ -176,12 +159,12 @@ void LiveRangeMap::reset_uf_map(uint max_lrg_id) { // the Union-Find mapping after this call. void LiveRangeMap::compress_uf_map_for_nodes() { // For all Nodes, compress mapping - uint unique = _names.Size(); + uint unique = _names.length(); for (uint i = 0; i < unique; ++i) { - uint lrg = _names[i]; + uint lrg = _names.at(i); uint compressed_lrg = find(lrg); if (lrg != compressed_lrg) { - _names.map(i, compressed_lrg); + _names.at_put(i, compressed_lrg); } } } @@ -198,11 +181,11 @@ uint LiveRangeMap::find_const(uint lrg) const { return lrg; } - uint next = _uf_map[lrg]; + uint next = _uf_map.at(lrg); while (next != lrg) { // Scan chain of equivalences assert(next < lrg, "always union smaller"); lrg = next; // until find a fixed-point - next = _uf_map[lrg]; + next = _uf_map.at(lrg); } return next; } @@ -215,7 +198,7 @@ PhaseChaitin::PhaseChaitin(uint unique, PhaseCFG &cfg, Matcher &matcher) NULL #endif ) - , _lrg_map(unique) + , _lrg_map(Thread::current()->resource_area(), unique) , _live(0) , _spilled_once(Thread::current()->resource_area()) , _spilled_twice(Thread::current()->resource_area()) @@ -692,6 +675,7 @@ void PhaseChaitin::de_ssa() { _lrg_map.map(n->_idx, rm.is_NotEmpty() ? lr_counter++ : 0); } } + // Reset the Union-Find mapping to be identity _lrg_map.reset_uf_map(lr_counter); } diff --git a/hotspot/src/share/vm/opto/chaitin.hpp b/hotspot/src/share/vm/opto/chaitin.hpp index c951024ee75..41276efa5ca 100644 --- a/hotspot/src/share/vm/opto/chaitin.hpp +++ b/hotspot/src/share/vm/opto/chaitin.hpp @@ -283,8 +283,8 @@ private: // Straight out of Tarjan's union-find algorithm uint find_compress(const Node *node) { - uint lrg_id = find_compress(_names[node->_idx]); - _names.map(node->_idx, lrg_id); + uint lrg_id = find_compress(_names.at(node->_idx)); + _names.at_put(node->_idx, lrg_id); return lrg_id; } @@ -305,40 +305,40 @@ public: } uint size() const { - return _names.Size(); + return _names.length(); } uint live_range_id(uint idx) const { - return _names[idx]; + return _names.at(idx); } uint live_range_id(const Node *node) const { - return _names[node->_idx]; + return _names.at(node->_idx); } uint uf_live_range_id(uint lrg_id) const { - return _uf_map[lrg_id]; + return _uf_map.at(lrg_id); } void map(uint idx, uint lrg_id) { - _names.map(idx, lrg_id); + _names.at_put(idx, lrg_id); } void uf_map(uint dst_lrg_id, uint src_lrg_id) { - _uf_map.map(dst_lrg_id, src_lrg_id); + _uf_map.at_put(dst_lrg_id, src_lrg_id); } void extend(uint idx, uint lrg_id) { - _names.extend(idx, lrg_id); + _names.at_put_grow(idx, lrg_id); } void uf_extend(uint dst_lrg_id, uint src_lrg_id) { - _uf_map.extend(dst_lrg_id, src_lrg_id); + _uf_map.at_put_grow(dst_lrg_id, src_lrg_id); } - LiveRangeMap(uint unique) - : _names(unique) - , _uf_map(unique) + LiveRangeMap(Arena* arena, uint unique) + : _names(arena, unique, unique, 0) + , _uf_map(arena, unique, unique, 0) , _max_lrg_id(0) {} uint find_id( const Node *n ) { @@ -355,14 +355,14 @@ public: void compress_uf_map_for_nodes(); uint find(uint lidx) { - uint uf_lidx = _uf_map[lidx]; + uint uf_lidx = _uf_map.at(lidx); return (uf_lidx == lidx) ? uf_lidx : find_compress(lidx); } // Convert a Node into a Live Range Index - a lidx uint find(const Node *node) { uint lidx = live_range_id(node); - uint uf_lidx = _uf_map[lidx]; + uint uf_lidx = _uf_map.at(lidx); return (uf_lidx == lidx) ? uf_lidx : find_compress(node); } @@ -371,10 +371,10 @@ public: // Like Find above, but no path compress, so bad asymptotic behavior uint find_const(const Node *node) const { - if(node->_idx >= _names.Size()) { + if(node->_idx >= (uint)_names.length()) { return 0; // not mapped, usual for debug dump } - return find_const(_names[node->_idx]); + return find_const(_names.at(node->_idx)); } }; diff --git a/hotspot/src/share/vm/opto/coalesce.hpp b/hotspot/src/share/vm/opto/coalesce.hpp index a6359af101c..3a361b25f11 100644 --- a/hotspot/src/share/vm/opto/coalesce.hpp +++ b/hotspot/src/share/vm/opto/coalesce.hpp @@ -29,7 +29,6 @@ class LoopTree; class LRG; -class LRG_List; class Matcher; class PhaseIFG; class PhaseCFG; diff --git a/hotspot/src/share/vm/opto/live.cpp b/hotspot/src/share/vm/opto/live.cpp index 280d22204c2..adbbc24f8fd 100644 --- a/hotspot/src/share/vm/opto/live.cpp +++ b/hotspot/src/share/vm/opto/live.cpp @@ -91,7 +91,7 @@ void PhaseLive::compute(uint maxlrg) { break; } - uint r = _names[n->_idx]; + uint r = _names.at(n->_idx); assert(!def_outside->member(r), "Use of external LRG overlaps the same LRG defined in this block"); def->insert( r ); use->remove( r ); @@ -100,7 +100,7 @@ void PhaseLive::compute(uint maxlrg) { Node *nk = n->in(k); uint nkidx = nk->_idx; if (_cfg.get_block_for_node(nk) != block) { - uint u = _names[nkidx]; + uint u = _names.at(nkidx); use->insert(u); DEBUG_ONLY(def_outside->insert(u);) } @@ -112,7 +112,7 @@ void PhaseLive::compute(uint maxlrg) { #endif // Remove anything defined by Phis and the block start instruction for (uint k = i; k > 0; k--) { - uint r = _names[block->get_node(k - 1)->_idx]; + uint r = _names.at(block->get_node(k - 1)->_idx); def->insert(r); use->remove(r); } @@ -124,7 +124,7 @@ void PhaseLive::compute(uint maxlrg) { // PhiNode uses go in the live-out set of prior blocks. for (uint k = i; k > 0; k--) { - add_liveout(p, _names[block->get_node(k-1)->in(l)->_idx], first_pass); + add_liveout(p, _names.at(block->get_node(k-1)->in(l)->_idx), first_pass); } } freeset(block); @@ -256,7 +256,7 @@ void PhaseLive::dump( const Block *b ) const { tty->print("LiveOut: "); _live[b->_pre_order-1].dump(); uint cnt = b->number_of_nodes(); for( uint i=0; iprint("L%d/", _names[b->get_node(i)->_idx] ); + tty->print("L%d/", _names.at(b->get_node(i)->_idx)); b->get_node(i)->dump(); } tty->print("\n"); diff --git a/hotspot/src/share/vm/opto/live.hpp b/hotspot/src/share/vm/opto/live.hpp index c2ebe758cf8..e449bb3f3a6 100644 --- a/hotspot/src/share/vm/opto/live.hpp +++ b/hotspot/src/share/vm/opto/live.hpp @@ -40,27 +40,7 @@ class IndexSet; //------------------------------LRG_List--------------------------------------- // Map Node indices to Live RanGe indices. // Array lookup in the optimized case. -class LRG_List : public ResourceObj { - friend class VMStructs; - uint _cnt, _max; - uint* _lidxs; - ReallocMark _nesting; // assertion check for reallocations -public: - LRG_List( uint max ); - - uint lookup( uint nidx ) const { - return _lidxs[nidx]; - } - uint operator[] (uint nidx) const { return lookup(nidx); } - - void map( uint nidx, uint lidx ) { - assert( nidx < _cnt, "oob" ); - _lidxs[nidx] = lidx; - } - void extend( uint nidx, uint lidx ); - - uint Size() const { return _cnt; } -}; +typedef GrowableArray LRG_List; //------------------------------PhaseLive-------------------------------------- // Compute live-in/live-out From 204f4422ba5afba76c7604ba956421a290d695e2 Mon Sep 17 00:00:00 2001 From: Vicente Romero Date: Thu, 12 Sep 2013 22:40:29 +0100 Subject: [PATCH 145/210] 8023558: Javac creates invalid bootstrap methods for complex lambda/methodref case Co-authored-by: Maurizio Cimadamore Reviewed-by: jjg --- .../com/sun/tools/javac/comp/TransTypes.java | 2 +- .../tools/javac/lambda/8023558/T8023558a.java | 38 ++++++++++++ .../tools/javac/lambda/8023558/T8023558b.java | 58 +++++++++++++++++++ .../tools/javac/lambda/8023558/T8023558c.java | 39 +++++++++++++ 4 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 langtools/test/tools/javac/lambda/8023558/T8023558a.java create mode 100644 langtools/test/tools/javac/lambda/8023558/T8023558b.java create mode 100644 langtools/test/tools/javac/lambda/8023558/T8023558c.java diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/TransTypes.java b/langtools/src/share/classes/com/sun/tools/javac/comp/TransTypes.java index 47cc589e967..ff7f0da574d 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/comp/TransTypes.java +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/TransTypes.java @@ -833,7 +833,7 @@ public class TransTypes extends TreeTranslator { } public void visitReference(JCMemberReference tree) { - tree.expr = translate(tree.expr, null); + tree.expr = translate(tree.expr, erasure(tree.expr.type)); tree.type = erasure(tree.type); result = tree; } diff --git a/langtools/test/tools/javac/lambda/8023558/T8023558a.java b/langtools/test/tools/javac/lambda/8023558/T8023558a.java new file mode 100644 index 00000000000..205ff9eefdc --- /dev/null +++ b/langtools/test/tools/javac/lambda/8023558/T8023558a.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2013, 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 8023558 + * @summary Javac creates invalid bootstrap methods for complex lambda/methodref case + */ +public class T8023558a { + interface SAM { + T get(); + } + + public static void main(String[] args) { + SAM sam = new SAM() { public SAM get() { return null; } }; + SAM temp = sam.get()::get; + } +} diff --git a/langtools/test/tools/javac/lambda/8023558/T8023558b.java b/langtools/test/tools/javac/lambda/8023558/T8023558b.java new file mode 100644 index 00000000000..c4fe72894e3 --- /dev/null +++ b/langtools/test/tools/javac/lambda/8023558/T8023558b.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2013, 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 8023558 + * @summary Javac creates invalid bootstrap methods for complex lambda/methodref case + */ +public class T8023558b { + + interface Supplier { + X get(); + } + + static class A { + public A(Supplier supplier) { } + } + + static class B { } + + static class C { + public B getB() { + return new B(); + } + } + + public static void main(String[] args) { + new T8023558b().test(T8023558b::getC); + } + + private static C getC() { + return new C(); + } + + public void test(Supplier supplier) { + new A(supplier.get()::getB); + } +} diff --git a/langtools/test/tools/javac/lambda/8023558/T8023558c.java b/langtools/test/tools/javac/lambda/8023558/T8023558c.java new file mode 100644 index 00000000000..32234178e3b --- /dev/null +++ b/langtools/test/tools/javac/lambda/8023558/T8023558c.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2013, 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 8023558 + * @summary Javac creates invalid bootstrap methods for complex lambda/methodref case + */ + +interface SAM { + T get(); +} + +public class T8023558c { + public static void main(String[] args) { + SAM sam = () -> Object::new; + SAM temp = sam.get()::get; + } +} From bfe7c0bfc24b61d31ec87d3ebecb1aeec17c45f2 Mon Sep 17 00:00:00 2001 From: Christian Thalinger Date: Thu, 12 Sep 2013 14:53:44 -0700 Subject: [PATCH 146/210] 8024275: During CTW: assert(sig_bt[member_arg_pos] == T_OBJECT) failed: dispatch argument must be an object Reviewed-by: kvn, vlivanov --- .../src/share/vm/classfile/classLoader.cpp | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/hotspot/src/share/vm/classfile/classLoader.cpp b/hotspot/src/share/vm/classfile/classLoader.cpp index 35055b4cb41..0ab350d90f8 100644 --- a/hotspot/src/share/vm/classfile/classLoader.cpp +++ b/hotspot/src/share/vm/classfile/classLoader.cpp @@ -1319,6 +1319,25 @@ static void clear_pending_exception_if_not_oom(TRAPS) { // The CHECK at the caller will propagate the exception out } +/** + * Returns if the given method should be compiled when doing compile-the-world. + * + * TODO: This should be a private method in a CompileTheWorld class. + */ +static bool can_be_compiled(methodHandle m, int comp_level) { + assert(CompileTheWorld, "must be"); + + // It's not valid to compile a native wrapper for MethodHandle methods + // that take a MemberName appendix since the bytecode signature is not + // correct. + vmIntrinsics::ID iid = m->intrinsic_id(); + if (MethodHandles::is_signature_polymorphic(iid) && MethodHandles::has_member_arg(iid)) { + return false; + } + + return CompilationPolicy::can_be_compiled(m, comp_level); +} + void ClassLoader::compile_the_world_in(char* name, Handle loader, TRAPS) { int len = (int)strlen(name); if (len > 6 && strcmp(".class", name + len - 6) == 0) { @@ -1362,8 +1381,7 @@ void ClassLoader::compile_the_world_in(char* name, Handle loader, TRAPS) { int comp_level = CompilationPolicy::policy()->initial_compile_level(); for (int n = 0; n < k->methods()->length(); n++) { methodHandle m (THREAD, k->methods()->at(n)); - if (CompilationPolicy::can_be_compiled(m, comp_level)) { - + if (can_be_compiled(m, comp_level)) { if (++_codecache_sweep_counter == CompileTheWorldSafepointInterval) { // Give sweeper a chance to keep up with CTW VM_ForceSafepoint op; @@ -1375,7 +1393,7 @@ void ClassLoader::compile_the_world_in(char* name, Handle loader, TRAPS) { methodHandle(), 0, "CTW", THREAD); if (HAS_PENDING_EXCEPTION) { clear_pending_exception_if_not_oom(CHECK); - tty->print_cr("CompileTheWorld (%d) : Skipping method: %s", _compile_the_world_class_counter, m->name()->as_C_string()); + tty->print_cr("CompileTheWorld (%d) : Skipping method: %s", _compile_the_world_class_counter, m->name_and_sig_as_C_string()); } else { _compile_the_world_method_counter++; } @@ -1391,11 +1409,13 @@ void ClassLoader::compile_the_world_in(char* name, Handle loader, TRAPS) { methodHandle(), 0, "CTW", THREAD); if (HAS_PENDING_EXCEPTION) { clear_pending_exception_if_not_oom(CHECK); - tty->print_cr("CompileTheWorld (%d) : Skipping method: %s", _compile_the_world_class_counter, m->name()->as_C_string()); + tty->print_cr("CompileTheWorld (%d) : Skipping method: %s", _compile_the_world_class_counter, m->name_and_sig_as_C_string()); } else { _compile_the_world_method_counter++; } } + } else { + tty->print_cr("CompileTheWorld (%d) : Skipping method: %s", _compile_the_world_class_counter, m->name_and_sig_as_C_string()); } nmethod* nm = m->code(); From d2d4036f85983c026b380005526361567c5f4455 Mon Sep 17 00:00:00 2001 From: Stefan Karlsson Date: Fri, 13 Sep 2013 22:21:06 +0200 Subject: [PATCH 147/210] 8024651: Remove the incorrect usage of Metablock::overhead() Reviewed-by: brutisso, mgerdin, coleenp, jmasa --- hotspot/src/share/vm/memory/metablock.cpp | 7 ------- hotspot/src/share/vm/memory/metablock.hpp | 2 -- hotspot/src/share/vm/memory/metaspace.cpp | 4 +--- 3 files changed, 1 insertion(+), 12 deletions(-) diff --git a/hotspot/src/share/vm/memory/metablock.cpp b/hotspot/src/share/vm/memory/metablock.cpp index 450d2c3193d..b6c6947e1ac 100644 --- a/hotspot/src/share/vm/memory/metablock.cpp +++ b/hotspot/src/share/vm/memory/metablock.cpp @@ -50,13 +50,6 @@ // Chunks, change Chunks so that they can be allocated out of a VirtualSpace. size_t Metablock::_min_block_byte_size = sizeof(Metablock); -#ifdef ASSERT -size_t Metablock::_overhead = - Chunk::aligned_overhead_size(sizeof(Metablock)) / BytesPerWord; -#else -size_t Metablock::_overhead = 0; -#endif - // New blocks returned by the Metaspace are zero initialized. // We should fix the constructors to not assume this instead. Metablock* Metablock::initialize(MetaWord* p, size_t word_size) { diff --git a/hotspot/src/share/vm/memory/metablock.hpp b/hotspot/src/share/vm/memory/metablock.hpp index 220d3614818..fa4c6c0b445 100644 --- a/hotspot/src/share/vm/memory/metablock.hpp +++ b/hotspot/src/share/vm/memory/metablock.hpp @@ -48,7 +48,6 @@ class Metablock VALUE_OBJ_CLASS_SPEC { } _header; } _block; static size_t _min_block_byte_size; - static size_t _overhead; typedef union block_t Block; typedef struct header_t Header; @@ -73,7 +72,6 @@ class Metablock VALUE_OBJ_CLASS_SPEC { void set_prev(Metablock* v) { _block._header._prev = v; } static size_t min_block_byte_size() { return _min_block_byte_size; } - static size_t overhead() { return _overhead; } bool is_free() { return header()->_word_size != 0; } void clear_next() { set_next(NULL); } diff --git a/hotspot/src/share/vm/memory/metaspace.cpp b/hotspot/src/share/vm/memory/metaspace.cpp index 1dd97842eb4..9d7834a56fb 100644 --- a/hotspot/src/share/vm/memory/metaspace.cpp +++ b/hotspot/src/share/vm/memory/metaspace.cpp @@ -737,9 +737,7 @@ class SpaceManager : public CHeapObj { // MinChunkSize is a placeholder for the real minimum size JJJ size_t byte_size = word_size * BytesPerWord; - size_t byte_size_with_overhead = byte_size + Metablock::overhead(); - - size_t raw_bytes_size = MAX2(byte_size_with_overhead, + size_t raw_bytes_size = MAX2(byte_size, Metablock::min_block_byte_size()); raw_bytes_size = ARENA_ALIGN(raw_bytes_size); size_t raw_word_size = raw_bytes_size / BytesPerWord; From 860b5dcec78c71f5ad307b0732b2e23c38be82c7 Mon Sep 17 00:00:00 2001 From: Stefan Karlsson Date: Fri, 13 Sep 2013 22:22:14 +0200 Subject: [PATCH 148/210] 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize Reviewed-by: jwilhelm, brutisso, tschatzl --- .../parallelScavenge/generationSizer.hpp | 5 +- .../src/share/vm/memory/collectorPolicy.cpp | 31 +++-- .../gc/metaspace/TestMetaspaceSizeFlags.java | 108 ++++++++++++++++++ .../test/testlibrary/OutputAnalyzerTest.java | 17 +++ .../java/testlibrary/OutputAnalyzer.java | 35 +++++- 5 files changed, 180 insertions(+), 16 deletions(-) create mode 100644 hotspot/test/gc/metaspace/TestMetaspaceSizeFlags.java diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/generationSizer.hpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/generationSizer.hpp index b4b8c1ae9bb..e5637687e84 100644 --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/generationSizer.hpp +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/generationSizer.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2013, 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 @@ -68,9 +68,6 @@ class GenerationSizer : public TwoGenerationCollectorPolicy { size_t min_old_gen_size() { return _min_gen1_size; } size_t old_gen_size() { return _initial_gen1_size; } size_t max_old_gen_size() { return _max_gen1_size; } - - size_t metaspace_size() { return MetaspaceSize; } - size_t max_metaspace_size() { return MaxMetaspaceSize; } }; #endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_GENERATIONSIZER_HPP diff --git a/hotspot/src/share/vm/memory/collectorPolicy.cpp b/hotspot/src/share/vm/memory/collectorPolicy.cpp index a5b4aa61894..0728997b769 100644 --- a/hotspot/src/share/vm/memory/collectorPolicy.cpp +++ b/hotspot/src/share/vm/memory/collectorPolicy.cpp @@ -47,6 +47,11 @@ // CollectorPolicy methods. +// Align down. If the aligning result in 0, return 'alignment'. +static size_t restricted_align_down(size_t size, size_t alignment) { + return MAX2(alignment, align_size_down_(size, alignment)); +} + void CollectorPolicy::initialize_flags() { assert(max_alignment() >= min_alignment(), err_msg("max_alignment: " SIZE_FORMAT " less than min_alignment: " SIZE_FORMAT, @@ -59,18 +64,24 @@ void CollectorPolicy::initialize_flags() { vm_exit_during_initialization("Incompatible initial and maximum heap sizes specified"); } - if (MetaspaceSize > MaxMetaspaceSize) { - MaxMetaspaceSize = MetaspaceSize; - } - MetaspaceSize = MAX2(min_alignment(), align_size_down_(MetaspaceSize, min_alignment())); - // Don't increase Metaspace size limit above specified. - MaxMetaspaceSize = align_size_down(MaxMetaspaceSize, max_alignment()); - if (MetaspaceSize > MaxMetaspaceSize) { - MetaspaceSize = MaxMetaspaceSize; + if (!is_size_aligned(MaxMetaspaceSize, max_alignment())) { + FLAG_SET_ERGO(uintx, MaxMetaspaceSize, + restricted_align_down(MaxMetaspaceSize, max_alignment())); } - MinMetaspaceExpansion = MAX2(min_alignment(), align_size_down_(MinMetaspaceExpansion, min_alignment())); - MaxMetaspaceExpansion = MAX2(min_alignment(), align_size_down_(MaxMetaspaceExpansion, min_alignment())); + if (MetaspaceSize > MaxMetaspaceSize) { + FLAG_SET_ERGO(uintx, MetaspaceSize, MaxMetaspaceSize); + } + + if (!is_size_aligned(MetaspaceSize, min_alignment())) { + FLAG_SET_ERGO(uintx, MetaspaceSize, + restricted_align_down(MetaspaceSize, min_alignment())); + } + + assert(MetaspaceSize <= MaxMetaspaceSize, "Must be"); + + MinMetaspaceExpansion = restricted_align_down(MinMetaspaceExpansion, min_alignment()); + MaxMetaspaceExpansion = restricted_align_down(MaxMetaspaceExpansion, min_alignment()); MinHeapDeltaBytes = align_size_up(MinHeapDeltaBytes, min_alignment()); diff --git a/hotspot/test/gc/metaspace/TestMetaspaceSizeFlags.java b/hotspot/test/gc/metaspace/TestMetaspaceSizeFlags.java new file mode 100644 index 00000000000..c67b8dc5ce9 --- /dev/null +++ b/hotspot/test/gc/metaspace/TestMetaspaceSizeFlags.java @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2013, 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 com.oracle.java.testlibrary.Asserts; +import com.oracle.java.testlibrary.OutputAnalyzer; +import com.oracle.java.testlibrary.ProcessTools; + +/* + * @test TestMetaspaceSizeFlags + * @key gc + * @bug 8024650 + * @summary Test that metaspace size flags can be set correctly + * @library /testlibrary + */ +public class TestMetaspaceSizeFlags { + public static final long K = 1024L; + public static final long M = 1024L * K; + + // HotSpot uses a number of different values to align memory size flags. + // This is currently the largest alignment (unless huge large pages are used). + public static final long MAX_ALIGNMENT = 32 * M; + + public static void main(String [] args) throws Exception { + testMaxMetaspaceSizeEQMetaspaceSize(MAX_ALIGNMENT, MAX_ALIGNMENT); + // 8024650: MaxMetaspaceSize was adjusted instead of MetaspaceSize. + testMaxMetaspaceSizeLTMetaspaceSize(MAX_ALIGNMENT, MAX_ALIGNMENT * 2); + testMaxMetaspaceSizeGTMetaspaceSize(MAX_ALIGNMENT * 2, MAX_ALIGNMENT); + testTooSmallInitialMetaspace(0, 0); + testTooSmallInitialMetaspace(0, MAX_ALIGNMENT); + testTooSmallInitialMetaspace(MAX_ALIGNMENT, 0); + } + + private static void testMaxMetaspaceSizeEQMetaspaceSize(long maxMetaspaceSize, long metaspaceSize) throws Exception { + MetaspaceFlags mf = runAndGetValue(maxMetaspaceSize, metaspaceSize); + Asserts.assertEQ(maxMetaspaceSize, metaspaceSize); + Asserts.assertEQ(mf.maxMetaspaceSize, maxMetaspaceSize); + Asserts.assertEQ(mf.metaspaceSize, metaspaceSize); + } + + private static void testMaxMetaspaceSizeLTMetaspaceSize(long maxMetaspaceSize, long metaspaceSize) throws Exception { + MetaspaceFlags mf = runAndGetValue(maxMetaspaceSize, metaspaceSize); + Asserts.assertEQ(mf.maxMetaspaceSize, maxMetaspaceSize); + Asserts.assertEQ(mf.metaspaceSize, maxMetaspaceSize); + } + + private static void testMaxMetaspaceSizeGTMetaspaceSize(long maxMetaspaceSize, long metaspaceSize) throws Exception { + MetaspaceFlags mf = runAndGetValue(maxMetaspaceSize, metaspaceSize); + Asserts.assertGT(maxMetaspaceSize, metaspaceSize); + Asserts.assertGT(mf.maxMetaspaceSize, mf.metaspaceSize); + Asserts.assertEQ(mf.maxMetaspaceSize, maxMetaspaceSize); + Asserts.assertEQ(mf.metaspaceSize, metaspaceSize); + } + + private static void testTooSmallInitialMetaspace(long maxMetaspaceSize, long metaspaceSize) throws Exception { + OutputAnalyzer output = run(maxMetaspaceSize, metaspaceSize); + output.shouldContain("Too small initial Metaspace size"); + } + + private static MetaspaceFlags runAndGetValue(long maxMetaspaceSize, long metaspaceSize) throws Exception { + OutputAnalyzer output = run(maxMetaspaceSize, metaspaceSize); + output.shouldNotMatch("Error occurred during initialization of VM\n.*"); + + String stringMaxMetaspaceSize = output.firstMatch(".* MaxMetaspaceSize .* := (\\d+).*", 1); + String stringMetaspaceSize = output.firstMatch(".* MetaspaceSize .* := (\\d+).*", 1); + + return new MetaspaceFlags(Long.parseLong(stringMaxMetaspaceSize), + Long.parseLong(stringMetaspaceSize)); + } + + private static OutputAnalyzer run(long maxMetaspaceSize, long metaspaceSize) throws Exception { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( + "-XX:MaxMetaspaceSize=" + maxMetaspaceSize, + "-XX:MetaspaceSize=" + metaspaceSize, + "-XX:-UseLargePages", // Prevent us from using 2GB large pages on solaris + sparc. + "-XX:+PrintFlagsFinal", + "-version"); + return new OutputAnalyzer(pb.start()); + } + + private static class MetaspaceFlags { + public long maxMetaspaceSize; + public long metaspaceSize; + public MetaspaceFlags(long maxMetaspaceSize, long metaspaceSize) { + this.maxMetaspaceSize = maxMetaspaceSize; + this.metaspaceSize = metaspaceSize; + } + } +} diff --git a/hotspot/test/testlibrary/OutputAnalyzerTest.java b/hotspot/test/testlibrary/OutputAnalyzerTest.java index 6117e9000bd..2fd677783a8 100644 --- a/hotspot/test/testlibrary/OutputAnalyzerTest.java +++ b/hotspot/test/testlibrary/OutputAnalyzerTest.java @@ -172,5 +172,22 @@ public class OutputAnalyzerTest { } catch (RuntimeException e) { // expected } + + { + String aaaa = "aaaa"; + String result = output.firstMatch(aaaa); + if (!aaaa.equals(result)) { + throw new Exception("firstMatch(String) faild to match. Expected: " + aaaa + " got: " + result); + } + } + + { + String aa = "aa"; + String aa_grouped_aa = aa + "(" + aa + ")"; + String result = output.firstMatch(aa_grouped_aa, 1); + if (!aa.equals(result)) { + throw new Exception("firstMatch(String, int) failed to match. Expected: " + aa + " got: " + result); + } + } } } diff --git a/hotspot/test/testlibrary/com/oracle/java/testlibrary/OutputAnalyzer.java b/hotspot/test/testlibrary/com/oracle/java/testlibrary/OutputAnalyzer.java index b9e37128d23..73b65165e91 100644 --- a/hotspot/test/testlibrary/com/oracle/java/testlibrary/OutputAnalyzer.java +++ b/hotspot/test/testlibrary/com/oracle/java/testlibrary/OutputAnalyzer.java @@ -211,13 +211,13 @@ public final class OutputAnalyzer { if (matcher.find()) { reportDiagnosticSummary(); throw new RuntimeException("'" + pattern - + "' found in stdout \n"); + + "' found in stdout: '" + matcher.group() + "' \n"); } matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stderr); if (matcher.find()) { reportDiagnosticSummary(); throw new RuntimeException("'" + pattern - + "' found in stderr \n"); + + "' found in stderr: '" + matcher.group() + "' \n"); } } @@ -253,6 +253,37 @@ public final class OutputAnalyzer { } } + /** + * Get the captured group of the first string matching the pattern. + * stderr is searched before stdout. + * + * @param pattern The multi-line pattern to match + * @param group The group to capture + * @return The matched string or null if no match was found + */ + public String firstMatch(String pattern, int group) { + Matcher stderrMatcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stderr); + Matcher stdoutMatcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stdout); + if (stderrMatcher.find()) { + return stderrMatcher.group(group); + } + if (stdoutMatcher.find()) { + return stdoutMatcher.group(group); + } + return null; + } + + /** + * Get the first string matching the pattern. + * stderr is searched before stdout. + * + * @param pattern The multi-line pattern to match + * @return The matched string or null if no match was found + */ + public String firstMatch(String pattern) { + return firstMatch(pattern, 0); + } + /** * Verify the exit value of the process * From 9784317e8a91e5642c9128c05d78dcd4e1e80f5d Mon Sep 17 00:00:00 2001 From: Stefan Karlsson Date: Fri, 13 Sep 2013 22:23:48 +0200 Subject: [PATCH 149/210] 8024751: Fix bugs in TraceMetadata Reviewed-by: jmasa, brutisso --- hotspot/src/share/vm/memory/metaspace.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/hotspot/src/share/vm/memory/metaspace.cpp b/hotspot/src/share/vm/memory/metaspace.cpp index 9d7834a56fb..9b73b6303aa 100644 --- a/hotspot/src/share/vm/memory/metaspace.cpp +++ b/hotspot/src/share/vm/memory/metaspace.cpp @@ -2366,10 +2366,10 @@ Metachunk* SpaceManager::get_new_chunk(size_t word_size, grow_chunks_by_words, medium_chunk_bunch()); - if (TraceMetadataHumongousAllocation && + if (TraceMetadataHumongousAllocation && next != NULL && SpaceManager::is_humongous(next->word_size())) { - gclog_or_tty->print_cr(" new humongous chunk word size " PTR_FORMAT, - next->word_size()); + gclog_or_tty->print_cr(" new humongous chunk word size " + PTR_FORMAT, next->word_size()); } return next; @@ -2487,9 +2487,6 @@ void SpaceManager::dump(outputStream* const out) const { curr = curr->next()) { out->print("%d) ", i++); curr->print_on(out); - if (TraceMetadataChunkAllocation && Verbose) { - block_freelists()->print_on(out); - } curr_total += curr->word_size(); used += curr->used_word_size(); capacity += curr->capacity_word_size(); @@ -2497,6 +2494,10 @@ void SpaceManager::dump(outputStream* const out) const { } } + if (TraceMetadataChunkAllocation && Verbose) { + block_freelists()->print_on(out); + } + size_t free = current_chunk() == NULL ? 0 : current_chunk()->free_word_size(); // Free space isn't wasted. waste -= free; From 4d3c6221b785cb307770a5113160babe21e6e999 Mon Sep 17 00:00:00 2001 From: Stefan Karlsson Date: Fri, 13 Sep 2013 22:25:27 +0200 Subject: [PATCH 150/210] 8024752: Log TraceMetadata* output to gclog_or_tty instead of tty Reviewed-by: brutisso, mgerdin, coleenp --- hotspot/src/share/vm/memory/metaspace.cpp | 38 +++++++++---------- hotspot/src/share/vm/runtime/virtualspace.cpp | 19 ++++++---- hotspot/src/share/vm/runtime/virtualspace.hpp | 3 +- 3 files changed, 32 insertions(+), 28 deletions(-) diff --git a/hotspot/src/share/vm/memory/metaspace.cpp b/hotspot/src/share/vm/memory/metaspace.cpp index 9b73b6303aa..c12c0b8637b 100644 --- a/hotspot/src/share/vm/memory/metaspace.cpp +++ b/hotspot/src/share/vm/memory/metaspace.cpp @@ -881,9 +881,9 @@ Metachunk* VirtualSpaceNode::take_from_committed(size_t chunk_word_size) { if (!is_available(chunk_word_size)) { if (TraceMetadataChunkAllocation) { - tty->print("VirtualSpaceNode::take_from_committed() not available %d words ", chunk_word_size); + gclog_or_tty->print("VirtualSpaceNode::take_from_committed() not available %d words ", chunk_word_size); // Dump some information about the virtual space that is nearly full - print_on(tty); + print_on(gclog_or_tty); } return NULL; } @@ -904,7 +904,7 @@ bool VirtualSpaceNode::expand_by(size_t words, bool pre_touch) { if (TraceMetavirtualspaceAllocation && !result) { gclog_or_tty->print_cr("VirtualSpaceNode::expand_by() failed " "for byte size " SIZE_FORMAT, bytes); - virtual_space()->print(); + virtual_space()->print_on(gclog_or_tty); } return result; } @@ -1173,7 +1173,7 @@ void VirtualSpaceList::link_vs(VirtualSpaceNode* new_entry) { #endif if (TraceMetavirtualspaceAllocation && Verbose) { VirtualSpaceNode* vsl = current_virtual_space(); - vsl->print_on(tty); + vsl->print_on(gclog_or_tty); } } @@ -1733,9 +1733,9 @@ void ChunkManager::chunk_freelist_deallocate(Metachunk* chunk) { assert_lock_strong(SpaceManager::expand_lock()); slow_locked_verify(); if (TraceMetadataChunkAllocation) { - tty->print_cr("ChunkManager::chunk_freelist_deallocate: chunk " - PTR_FORMAT " size " SIZE_FORMAT, - chunk, chunk->word_size()); + gclog_or_tty->print_cr("ChunkManager::chunk_freelist_deallocate: chunk " + PTR_FORMAT " size " SIZE_FORMAT, + chunk, chunk->word_size()); } free_chunks_put(chunk); } @@ -1764,9 +1764,9 @@ Metachunk* ChunkManager::free_chunks_get(size_t word_size) { dec_free_chunks_total(chunk->capacity_word_size()); if (TraceMetadataChunkAllocation && Verbose) { - tty->print_cr("ChunkManager::free_chunks_get: free_list " - PTR_FORMAT " head " PTR_FORMAT " size " SIZE_FORMAT, - free_list, chunk, chunk->word_size()); + gclog_or_tty->print_cr("ChunkManager::free_chunks_get: free_list " + PTR_FORMAT " head " PTR_FORMAT " size " SIZE_FORMAT, + free_list, chunk, chunk->word_size()); } } else { chunk = humongous_dictionary()->get_chunk( @@ -1776,10 +1776,10 @@ Metachunk* ChunkManager::free_chunks_get(size_t word_size) { if (chunk != NULL) { if (TraceMetadataHumongousAllocation) { size_t waste = chunk->word_size() - word_size; - tty->print_cr("Free list allocate humongous chunk size " SIZE_FORMAT - " for requested size " SIZE_FORMAT - " waste " SIZE_FORMAT, - chunk->word_size(), word_size, waste); + gclog_or_tty->print_cr("Free list allocate humongous chunk size " + SIZE_FORMAT " for requested size " SIZE_FORMAT + " waste " SIZE_FORMAT, + chunk->word_size(), word_size, waste); } // Chunk is being removed from the chunks free list. dec_free_chunks_total(chunk->capacity_word_size()); @@ -1821,10 +1821,10 @@ Metachunk* ChunkManager::chunk_freelist_allocate(size_t word_size) { } else { list_count = humongous_dictionary()->total_count(); } - tty->print("ChunkManager::chunk_freelist_allocate: " PTR_FORMAT " chunk " - PTR_FORMAT " size " SIZE_FORMAT " count " SIZE_FORMAT " ", - this, chunk, chunk->word_size(), list_count); - locked_print_free_chunks(tty); + gclog_or_tty->print("ChunkManager::chunk_freelist_allocate: " PTR_FORMAT " chunk " + PTR_FORMAT " size " SIZE_FORMAT " count " SIZE_FORMAT " ", + this, chunk, chunk->word_size(), list_count); + locked_print_free_chunks(gclog_or_tty); } return chunk; @@ -2344,7 +2344,7 @@ void SpaceManager::add_chunk(Metachunk* new_chunk, bool make_current) { sum_count_in_chunks_in_use()); new_chunk->print_on(gclog_or_tty); if (vs_list() != NULL) { - vs_list()->chunk_manager()->locked_print_free_chunks(tty); + vs_list()->chunk_manager()->locked_print_free_chunks(gclog_or_tty); } } } diff --git a/hotspot/src/share/vm/runtime/virtualspace.cpp b/hotspot/src/share/vm/runtime/virtualspace.cpp index b7724a6a082..98ee7635002 100644 --- a/hotspot/src/share/vm/runtime/virtualspace.cpp +++ b/hotspot/src/share/vm/runtime/virtualspace.cpp @@ -754,16 +754,19 @@ void VirtualSpace::check_for_contiguity() { assert(high() <= upper_high(), "upper high"); } -void VirtualSpace::print() { - tty->print ("Virtual space:"); - if (special()) tty->print(" (pinned in memory)"); - tty->cr(); - tty->print_cr(" - committed: " SIZE_FORMAT, committed_size()); - tty->print_cr(" - reserved: " SIZE_FORMAT, reserved_size()); - tty->print_cr(" - [low, high]: [" INTPTR_FORMAT ", " INTPTR_FORMAT "]", low(), high()); - tty->print_cr(" - [low_b, high_b]: [" INTPTR_FORMAT ", " INTPTR_FORMAT "]", low_boundary(), high_boundary()); +void VirtualSpace::print_on(outputStream* out) { + out->print ("Virtual space:"); + if (special()) out->print(" (pinned in memory)"); + out->cr(); + out->print_cr(" - committed: " SIZE_FORMAT, committed_size()); + out->print_cr(" - reserved: " SIZE_FORMAT, reserved_size()); + out->print_cr(" - [low, high]: [" INTPTR_FORMAT ", " INTPTR_FORMAT "]", low(), high()); + out->print_cr(" - [low_b, high_b]: [" INTPTR_FORMAT ", " INTPTR_FORMAT "]", low_boundary(), high_boundary()); } +void VirtualSpace::print() { + print_on(tty); +} /////////////// Unit tests /////////////// diff --git a/hotspot/src/share/vm/runtime/virtualspace.hpp b/hotspot/src/share/vm/runtime/virtualspace.hpp index 938a71a4a43..02b14734a00 100644 --- a/hotspot/src/share/vm/runtime/virtualspace.hpp +++ b/hotspot/src/share/vm/runtime/virtualspace.hpp @@ -203,7 +203,8 @@ class VirtualSpace VALUE_OBJ_CLASS_SPEC { void check_for_contiguity() PRODUCT_RETURN; // Debugging - void print() PRODUCT_RETURN; + void print_on(outputStream* out) PRODUCT_RETURN; + void print(); }; #endif // SHARE_VM_RUNTIME_VIRTUALSPACE_HPP From 403a37663ac616a849f35d855519d84c134ff46a Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Fri, 13 Sep 2013 07:57:13 +0200 Subject: [PATCH 151/210] 8024671: G1 generates assert error messages in product builds Reviewed-by: brutisso, tschatzl --- .../share/vm/gc_implementation/g1/g1CardCounts.cpp | 4 ++-- .../share/vm/gc_implementation/g1/g1CardCounts.hpp | 14 +++++--------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1CardCounts.cpp b/hotspot/src/share/vm/gc_implementation/g1/g1CardCounts.cpp index f75e518facc..31972bf3c4e 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1CardCounts.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1CardCounts.cpp @@ -33,8 +33,8 @@ void G1CardCounts::clear_range(size_t from_card_num, size_t to_card_num) { if (has_count_table()) { - check_card_num(from_card_num, - err_msg("from card num out of range: "SIZE_FORMAT, from_card_num)); + assert(from_card_num >= 0 && from_card_num < _committed_max_card_num, + err_msg("from card num out of range: "SIZE_FORMAT, from_card_num)); assert(from_card_num < to_card_num, err_msg("Wrong order? from: " SIZE_FORMAT ", to: "SIZE_FORMAT, from_card_num, to_card_num)); diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1CardCounts.hpp b/hotspot/src/share/vm/gc_implementation/g1/g1CardCounts.hpp index fd516c0b90e..129b3b0d232 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1CardCounts.hpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1CardCounts.hpp @@ -72,25 +72,21 @@ class G1CardCounts: public CHeapObj { return has_reserved_count_table() && _committed_max_card_num > 0; } - void check_card_num(size_t card_num, const char* msg) { - assert(card_num >= 0 && card_num < _committed_max_card_num, msg); - } - size_t ptr_2_card_num(const jbyte* card_ptr) { assert(card_ptr >= _ct_bot, - err_msg("Inavalied card pointer: " + err_msg("Invalid card pointer: " "card_ptr: " PTR_FORMAT ", " "_ct_bot: " PTR_FORMAT, card_ptr, _ct_bot)); size_t card_num = pointer_delta(card_ptr, _ct_bot, sizeof(jbyte)); - check_card_num(card_num, - err_msg("card pointer out of range: " PTR_FORMAT, card_ptr)); + assert(card_num >= 0 && card_num < _committed_max_card_num, + err_msg("card pointer out of range: " PTR_FORMAT, card_ptr)); return card_num; } jbyte* card_num_2_ptr(size_t card_num) { - check_card_num(card_num, - err_msg("card num out of range: "SIZE_FORMAT, card_num)); + assert(card_num >= 0 && card_num < _committed_max_card_num, + err_msg("card num out of range: "SIZE_FORMAT, card_num)); return (jbyte*) (_ct_bot + card_num); } From f8f4e382cf66fbf5b75a9870a1d54fd49231d0b8 Mon Sep 17 00:00:00 2001 From: Alejandro Murillo Date: Fri, 13 Sep 2013 00:25:19 -0700 Subject: [PATCH 152/210] Added tag hs25-b50 for changeset 8292c62817e4 --- hotspot/.hgtags | 1 + 1 file changed, 1 insertion(+) diff --git a/hotspot/.hgtags b/hotspot/.hgtags index 8d3f958c431..370ade6688d 100644 --- a/hotspot/.hgtags +++ b/hotspot/.hgtags @@ -376,3 +376,4 @@ acac3bde66b2c22791c257a8d99611d6d08c6713 jdk8-b105 aed585cafc0d9655726af6d1e1081d1c94cb3b5c jdk8-b106 50794d8ac11c9579b41dec4de23b808fef9f34a1 hs25-b49 5b7f90aab3ad25a25b75b7b2bb18d5ae23d8231c jdk8-b107 +a09fe9d1e016c285307507a5793bc4fa6215e9c9 hs25-b50 From 4bc9598f85d15b28077287f8d33fda0e84830cb1 Mon Sep 17 00:00:00 2001 From: Alejandro Murillo Date: Fri, 13 Sep 2013 00:43:01 -0700 Subject: [PATCH 153/210] 8024764: new hotspot build - hs25-b51 Reviewed-by: jcoomes --- hotspot/make/hotspot_version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hotspot/make/hotspot_version b/hotspot/make/hotspot_version index e1572121149..fa4d6554e16 100644 --- a/hotspot/make/hotspot_version +++ b/hotspot/make/hotspot_version @@ -35,7 +35,7 @@ HOTSPOT_VM_COPYRIGHT=Copyright 2013 HS_MAJOR_VER=25 HS_MINOR_VER=0 -HS_BUILD_NUMBER=50 +HS_BUILD_NUMBER=51 JDK_MAJOR_VER=1 JDK_MINOR_VER=8 From d477f2800d171cbf34b92d0a8c82630017122a10 Mon Sep 17 00:00:00 2001 From: Magnus Ihse Bursie Date: Fri, 13 Sep 2013 13:07:02 +0200 Subject: [PATCH 154/210] 8024620: config.log does not end up in corresponding configuration Reviewed-by: erikj --- common/autoconf/configure | 5 ----- common/autoconf/configure.ac | 6 ++++++ common/autoconf/generated-configure.sh | 8 +++++++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/common/autoconf/configure b/common/autoconf/configure index 8e4560df114..7378efe379d 100644 --- a/common/autoconf/configure +++ b/common/autoconf/configure @@ -219,9 +219,4 @@ else echo configure exiting with result code $conf_result_code fi -# Move the log file to the output root, if this was successfully created -if test -d "$OUTPUT_ROOT"; then - mv -f config.log "$OUTPUT_ROOT" 2> /dev/null -fi - exit $conf_result_code diff --git a/common/autoconf/configure.ac b/common/autoconf/configure.ac index 274f278fb3d..ad8bd97cea3 100644 --- a/common/autoconf/configure.ac +++ b/common/autoconf/configure.ac @@ -232,9 +232,15 @@ CUSTOM_LATE_HOOK # We're messing a bit with internal autoconf variables to put the config.status # in the output directory instead of the current directory. CONFIG_STATUS="$OUTPUT_ROOT/config.status" + # Create the actual output files. Now the main work of configure is done. AC_OUTPUT +# Try to move the config.log file to the output directory. +if test -e ./config.log; then + $MV -f ./config.log "$OUTPUT_ROOT/config.log" 2> /dev/null +fi + # Make the compare script executable $CHMOD +x $OUTPUT_ROOT/compare.sh diff --git a/common/autoconf/generated-configure.sh b/common/autoconf/generated-configure.sh index 84c38a67dba..f273159ba26 100644 --- a/common/autoconf/generated-configure.sh +++ b/common/autoconf/generated-configure.sh @@ -3806,7 +3806,7 @@ fi #CUSTOM_AUTOCONF_INCLUDE # Do not change or remove the following line, it is needed for consistency checks: -DATE_WHEN_GENERATED=1378980507 +DATE_WHEN_GENERATED=1379070243 ############################################################################### # @@ -33186,6 +33186,7 @@ fi # We're messing a bit with internal autoconf variables to put the config.status # in the output directory instead of the current directory. CONFIG_STATUS="$OUTPUT_ROOT/config.status" + # Create the actual output files. Now the main work of configure is done. cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure @@ -34467,6 +34468,11 @@ $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;} fi +# Try to move the config.log file to the output directory. +if test -e ./config.log; then + $MV -f ./config.log "$OUTPUT_ROOT/config.log" 2> /dev/null +fi + # Make the compare script executable $CHMOD +x $OUTPUT_ROOT/compare.sh From 13d322d70fa5dba35976acaa7236fd23371352e0 Mon Sep 17 00:00:00 2001 From: Vladimir Ivanov Date: Fri, 13 Sep 2013 04:16:54 -0700 Subject: [PATCH 155/210] 8023134: Rename VM LogFile to hotspot_pid{pid}.log (was hotspot.log) Reviewed-by: twisti, kvn, sla --- hotspot/src/share/tools/LogCompilation/README | 6 ++-- hotspot/src/share/vm/runtime/arguments.cpp | 35 ++++++++++++++++++- .../src/share/vm/runtime/deoptimization.cpp | 4 +-- hotspot/src/share/vm/runtime/globals.hpp | 11 +++--- hotspot/src/share/vm/utilities/ostream.cpp | 7 ++-- 5 files changed, 49 insertions(+), 14 deletions(-) diff --git a/hotspot/src/share/tools/LogCompilation/README b/hotspot/src/share/tools/LogCompilation/README index 90dc3b893bb..aa18fe891f6 100644 --- a/hotspot/src/share/tools/LogCompilation/README +++ b/hotspot/src/share/tools/LogCompilation/README @@ -4,14 +4,14 @@ It's main purpose is to recreate output similar to requires a 1.5 JDK to build and simply typing make should build it. It produces a jar file, logc.jar, that can be run on the -hotspot.log from LogCompilation output like this: +HotSpot log (by default, hotspot_pid{pid}.log) from LogCompilation output like this: - java -jar logc.jar hotspot.log + java -jar logc.jar hotspot_pid1234.log This will produce something like the normal PrintCompilation output. Adding the -i option with also report inlining like PrintInlining. -More information about the LogCompilation output can be found at +More information about the LogCompilation output can be found at https://wikis.oracle.com/display/HotSpotInternals/LogCompilation+overview https://wikis.oracle.com/display/HotSpotInternals/PrintCompilation diff --git a/hotspot/src/share/vm/runtime/arguments.cpp b/hotspot/src/share/vm/runtime/arguments.cpp index 1287e811496..b2627fea1d1 100644 --- a/hotspot/src/share/vm/runtime/arguments.cpp +++ b/hotspot/src/share/vm/runtime/arguments.cpp @@ -3337,6 +3337,33 @@ static char* get_shared_archive_path() { return shared_archive_path; } +#ifndef PRODUCT +// Determine whether LogVMOutput should be implicitly turned on. +static bool use_vm_log() { + if (LogCompilation || !FLAG_IS_DEFAULT(LogFile) || + PrintCompilation || PrintInlining || PrintDependencies || PrintNativeNMethods || + PrintDebugInfo || PrintRelocations || PrintNMethods || PrintExceptionHandlers || + PrintAssembly || TraceDeoptimization || TraceDependencies || + (VerifyDependencies && FLAG_IS_CMDLINE(VerifyDependencies))) { + return true; + } + +#ifdef COMPILER1 + if (PrintC1Statistics) { + return true; + } +#endif // COMPILER1 + +#ifdef COMPILER2 + if (PrintOptoAssembly || PrintOptoStatistics) { + return true; + } +#endif // COMPILER2 + + return false; +} +#endif // PRODUCT + // Parse entry point called from JNI_CreateJavaVM jint Arguments::parse(const JavaVMInitArgs* args) { @@ -3630,7 +3657,13 @@ jint Arguments::parse(const JavaVMInitArgs* args) { NmethodSweepFraction = 1; } } -#endif + + if (!LogVMOutput && FLAG_IS_DEFAULT(LogVMOutput)) { + if (use_vm_log()) { + LogVMOutput = true; + } + } +#endif // PRODUCT if (PrintCommandLineFlags) { CommandLineFlags::printSetFlags(tty); diff --git a/hotspot/src/share/vm/runtime/deoptimization.cpp b/hotspot/src/share/vm/runtime/deoptimization.cpp index 7f71c2d8b76..007bfe7aa13 100644 --- a/hotspot/src/share/vm/runtime/deoptimization.cpp +++ b/hotspot/src/share/vm/runtime/deoptimization.cpp @@ -1751,7 +1751,7 @@ int Deoptimization::trap_state_set_recompiled(int trap_state, bool z) { else return trap_state & ~DS_RECOMPILE_BIT; } //---------------------------format_trap_state--------------------------------- -// This is used for debugging and diagnostics, including hotspot.log output. +// This is used for debugging and diagnostics, including LogFile output. const char* Deoptimization::format_trap_state(char* buf, size_t buflen, int trap_state) { DeoptReason reason = trap_state_reason(trap_state); @@ -1828,7 +1828,7 @@ const char* Deoptimization::trap_action_name(int action) { return buf; } -// This is used for debugging and diagnostics, including hotspot.log output. +// This is used for debugging and diagnostics, including LogFile output. const char* Deoptimization::format_trap_request(char* buf, size_t buflen, int trap_request) { jint unloaded_class_index = trap_request_index(trap_request); diff --git a/hotspot/src/share/vm/runtime/globals.hpp b/hotspot/src/share/vm/runtime/globals.hpp index 7fdf668bac5..ed3e1e8ff5d 100644 --- a/hotspot/src/share/vm/runtime/globals.hpp +++ b/hotspot/src/share/vm/runtime/globals.hpp @@ -880,7 +880,7 @@ class CommandLineFlags { "stay alive at the expense of JVM performance") \ \ diagnostic(bool, LogCompilation, false, \ - "Log compilation activity in detail to hotspot.log or LogFile") \ + "Log compilation activity in detail to LogFile") \ \ product(bool, PrintCompilation, false, \ "Print compilations") \ @@ -2498,16 +2498,17 @@ class CommandLineFlags { "Print all VM flags with default values and descriptions and exit")\ \ diagnostic(bool, SerializeVMOutput, true, \ - "Use a mutex to serialize output to tty and hotspot.log") \ + "Use a mutex to serialize output to tty and LogFile") \ \ diagnostic(bool, DisplayVMOutput, true, \ "Display all VM output on the tty, independently of LogVMOutput") \ \ - diagnostic(bool, LogVMOutput, trueInDebug, \ - "Save VM output to hotspot.log, or to LogFile") \ + diagnostic(bool, LogVMOutput, false, \ + "Save VM output to LogFile") \ \ diagnostic(ccstr, LogFile, NULL, \ - "If LogVMOutput is on, save VM output to this file [hotspot.log]") \ + "If LogVMOutput or LogCompilation is on, save VM output to " \ + "this file [default: ./hotspot_pid%p.log] (%p replaced with pid)") \ \ product(ccstr, ErrorFile, NULL, \ "If an error occurs, save the error data to this file " \ diff --git a/hotspot/src/share/vm/utilities/ostream.cpp b/hotspot/src/share/vm/utilities/ostream.cpp index 2f04fa0e437..90532078652 100644 --- a/hotspot/src/share/vm/utilities/ostream.cpp +++ b/hotspot/src/share/vm/utilities/ostream.cpp @@ -592,7 +592,7 @@ static const char* make_log_name(const char* log_name, const char* force_directo void defaultStream::init_log() { // %%% Need a MutexLocker? - const char* log_name = LogFile != NULL ? LogFile : "hotspot.log"; + const char* log_name = LogFile != NULL ? LogFile : "hotspot_pid%p.log"; const char* try_name = make_log_name(log_name, NULL); fileStream* file = new(ResourceObj::C_HEAP, mtInternal) fileStream(try_name); if (!file->is_open()) { @@ -603,14 +603,15 @@ void defaultStream::init_log() { // Note: This feature is for maintainer use only. No need for L10N. jio_print(warnbuf); FREE_C_HEAP_ARRAY(char, try_name, mtInternal); - try_name = make_log_name("hs_pid%p.log", os::get_temp_directory()); + try_name = make_log_name(log_name, os::get_temp_directory()); jio_snprintf(warnbuf, sizeof(warnbuf), "Warning: Forcing option -XX:LogFile=%s\n", try_name); jio_print(warnbuf); delete file; file = new(ResourceObj::C_HEAP, mtInternal) fileStream(try_name); - FREE_C_HEAP_ARRAY(char, try_name, mtInternal); } + FREE_C_HEAP_ARRAY(char, try_name, mtInternal); + if (file->is_open()) { _log_file = file; xmlStream* xs = new(ResourceObj::C_HEAP, mtInternal) xmlStream(file); From 3c2808598812d24e00b4a4eb7dc1ca13a9e43702 Mon Sep 17 00:00:00 2001 From: Magnus Ihse Bursie Date: Fri, 13 Sep 2013 14:59:23 +0200 Subject: [PATCH 156/210] 8024665: Move open changes for JDK-8020411 to closed source Reviewed-by: erikj --- common/autoconf/generated-configure.sh | 49 ++++++++++++++------------ common/autoconf/platform.m4 | 23 ++++++------ common/autoconf/spec.gmk.in | 1 - 3 files changed, 40 insertions(+), 33 deletions(-) diff --git a/common/autoconf/generated-configure.sh b/common/autoconf/generated-configure.sh index f273159ba26..bc9d07da3f3 100644 --- a/common/autoconf/generated-configure.sh +++ b/common/autoconf/generated-configure.sh @@ -709,7 +709,6 @@ STATIC_LIBRARY SHARED_LIBRARY OBJ_SUFFIX COMPILER_NAME -TARGET_BITS_FLAG JT_HOME JTREGEXE LIPO @@ -3806,7 +3805,7 @@ fi #CUSTOM_AUTOCONF_INCLUDE # Do not change or remove the following line, it is needed for consistency checks: -DATE_WHEN_GENERATED=1379070243 +DATE_WHEN_GENERATED=1379077060 ############################################################################### # @@ -28398,35 +28397,41 @@ done if test "x$OPENJDK_TARGET_OS" = xsolaris; then # Always specify -m flags on Solaris - # keep track of c/cxx flags that we added outselves... - # to prevent emitting warning... - TARGET_BITS_FLAG="-m${OPENJDK_TARGET_CPU_BITS}" + # When we add flags to the "official" CFLAGS etc, we need to + # keep track of these additions in ADDED_CFLAGS etc. These + # will later be checked to make sure only controlled additions + # have been made to CFLAGS etc. + ADDED_CFLAGS=" -m${OPENJDK_TARGET_CPU_BITS}" + ADDED_CXXFLAGS=" -m${OPENJDK_TARGET_CPU_BITS}" + ADDED_LDFLAGS=" -m${OPENJDK_TARGET_CPU_BITS}" + CFLAGS="${CFLAGS}${ADDED_CFLAGS}" + CXXFLAGS="${CXXFLAGS}${ADDED_CXXFLAGS}" + LDFLAGS="${LDFLAGS}${ADDED_LDFLAGS}" - CFLAGS="${CFLAGS} ${TARGET_BITS_FLAG}" - CXXFLAGS="${CXXFLAGS} ${TARGET_BITS_FLAG}" - LDFLAGS="${LDFLAGS} ${TARGET_BITS_FLAG}" - - CFLAGS_JDK="${CFLAGS_JDK} ${TARGET_BITS_FLAG}" - CXXFLAGS_JDK="${CXXFLAGS_JDK} ${TARGET_BITS_FLAG}" - LDFLAGS_JDK="${LDFLAGS_JDK} ${TARGET_BITS_FLAG}" + CFLAGS_JDK="${CFLAGS_JDK}${ADDED_CFLAGS}" + CXXFLAGS_JDK="${CXXFLAGS_JDK}${ADDED_CXXFLAGS}" + LDFLAGS_JDK="${LDFLAGS_JDK}${ADDED_LDFLAGS}" elif test "x$COMPILE_TYPE" = xreduced; then if test "x$OPENJDK_TARGET_OS" != xwindows; then # Specify -m if running reduced on other Posix platforms - # keep track of c/cxx flags that we added outselves... - # to prevent emitting warning... - TARGET_BITS_FLAG="-m${OPENJDK_TARGET_CPU_BITS}" + # When we add flags to the "official" CFLAGS etc, we need to + # keep track of these additions in ADDED_CFLAGS etc. These + # will later be checked to make sure only controlled additions + # have been made to CFLAGS etc. + ADDED_CFLAGS=" -m${OPENJDK_TARGET_CPU_BITS}" + ADDED_CXXFLAGS=" -m${OPENJDK_TARGET_CPU_BITS}" + ADDED_LDFLAGS=" -m${OPENJDK_TARGET_CPU_BITS}" + CFLAGS="${CFLAGS}${ADDED_CFLAGS}" + CXXFLAGS="${CXXFLAGS}${ADDED_CXXFLAGS}" + LDFLAGS="${LDFLAGS}${ADDED_LDFLAGS}" - CFLAGS="${CFLAGS} ${TARGET_BITS_FLAG}" - CXXFLAGS="${CXXFLAGS} ${TARGET_BITS_FLAG}" - LDFLAGS="${LDFLAGS} ${TARGET_BITS_FLAG}" - - CFLAGS_JDK="${CFLAGS_JDK} ${TARGET_BITS_FLAG}" - CXXFLAGS_JDK="${CXXFLAGS_JDK} ${TARGET_BITS_FLAG}" - LDFLAGS_JDK="${LDFLAGS_JDK} ${TARGET_BITS_FLAG}" + CFLAGS_JDK="${CFLAGS_JDK}${ADDED_CFLAGS}" + CXXFLAGS_JDK="${CXXFLAGS_JDK}${ADDED_CXXFLAGS}" + LDFLAGS_JDK="${LDFLAGS_JDK}${ADDED_LDFLAGS}" fi fi diff --git a/common/autoconf/platform.m4 b/common/autoconf/platform.m4 index 71ae2ceab7b..96c710d8a18 100644 --- a/common/autoconf/platform.m4 +++ b/common/autoconf/platform.m4 @@ -422,18 +422,21 @@ AC_SUBST(OS_VERSION_MICRO) # Add -mX to various FLAGS variables. AC_DEFUN([PLATFORM_SET_COMPILER_TARGET_BITS_FLAGS], [ - # keep track of c/cxx flags that we added outselves... - # to prevent emitting warning... - TARGET_BITS_FLAG="-m${OPENJDK_TARGET_CPU_BITS}" - AC_SUBST(TARGET_BITS_FLAG) + # When we add flags to the "official" CFLAGS etc, we need to + # keep track of these additions in ADDED_CFLAGS etc. These + # will later be checked to make sure only controlled additions + # have been made to CFLAGS etc. + ADDED_CFLAGS=" -m${OPENJDK_TARGET_CPU_BITS}" + ADDED_CXXFLAGS=" -m${OPENJDK_TARGET_CPU_BITS}" + ADDED_LDFLAGS=" -m${OPENJDK_TARGET_CPU_BITS}" - CFLAGS="${CFLAGS} ${TARGET_BITS_FLAG}" - CXXFLAGS="${CXXFLAGS} ${TARGET_BITS_FLAG}" - LDFLAGS="${LDFLAGS} ${TARGET_BITS_FLAG}" + CFLAGS="${CFLAGS}${ADDED_CFLAGS}" + CXXFLAGS="${CXXFLAGS}${ADDED_CXXFLAGS}" + LDFLAGS="${LDFLAGS}${ADDED_LDFLAGS}" - CFLAGS_JDK="${CFLAGS_JDK} ${TARGET_BITS_FLAG}" - CXXFLAGS_JDK="${CXXFLAGS_JDK} ${TARGET_BITS_FLAG}" - LDFLAGS_JDK="${LDFLAGS_JDK} ${TARGET_BITS_FLAG}" + CFLAGS_JDK="${CFLAGS_JDK}${ADDED_CFLAGS}" + CXXFLAGS_JDK="${CXXFLAGS_JDK}${ADDED_CXXFLAGS}" + LDFLAGS_JDK="${LDFLAGS_JDK}${ADDED_LDFLAGS}" ]) AC_DEFUN_ONCE([PLATFORM_SETUP_OPENJDK_TARGET_BITS], diff --git a/common/autoconf/spec.gmk.in b/common/autoconf/spec.gmk.in index d44b3c8c973..7e186693700 100644 --- a/common/autoconf/spec.gmk.in +++ b/common/autoconf/spec.gmk.in @@ -300,7 +300,6 @@ MACOSX_VERSION_MIN=@MACOSX_VERSION_MIN@ COMPILER_TYPE:=@COMPILER_TYPE@ COMPILER_NAME:=@COMPILER_NAME@ -TARGET_BITS_FLAG=@TARGET_BITS_FLAG@ COMPILER_SUPPORTS_TARGET_BITS_FLAG=@COMPILER_SUPPORTS_TARGET_BITS_FLAG@ CC_OUT_OPTION:=@CC_OUT_OPTION@ From dc42cb136dae4a66dc582ed312480c84c81c65d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Gr=C3=B6nlund?= Date: Fri, 13 Sep 2013 17:47:00 +0200 Subject: [PATCH 157/210] 8021353: Event based tracing is missing thread exit Reviewed-by: allwin, acorn, dcubed, dholmes, egahlin --- hotspot/src/share/vm/runtime/thread.cpp | 2 ++ hotspot/src/share/vm/trace/traceMacros.hpp | 1 + 2 files changed, 3 insertions(+) diff --git a/hotspot/src/share/vm/runtime/thread.cpp b/hotspot/src/share/vm/runtime/thread.cpp index 18b46c988e3..eab949297b3 100644 --- a/hotspot/src/share/vm/runtime/thread.cpp +++ b/hotspot/src/share/vm/runtime/thread.cpp @@ -333,6 +333,8 @@ Thread::~Thread() { // Reclaim the objectmonitors from the omFreeList of the moribund thread. ObjectSynchronizer::omFlush (this) ; + EVENT_THREAD_DESTRUCT(this); + // stack_base can be NULL if the thread is never started or exited before // record_stack_base_and_size called. Although, we would like to ensure // that all started threads do call record_stack_base_and_size(), there is diff --git a/hotspot/src/share/vm/trace/traceMacros.hpp b/hotspot/src/share/vm/trace/traceMacros.hpp index 1a6dd644935..4776e13507e 100644 --- a/hotspot/src/share/vm/trace/traceMacros.hpp +++ b/hotspot/src/share/vm/trace/traceMacros.hpp @@ -26,6 +26,7 @@ #define SHARE_VM_TRACE_TRACE_MACRO_HPP #define EVENT_THREAD_EXIT(thread) +#define EVENT_THREAD_DESTRUCT(thread) #define TRACE_INIT_ID(k) #define TRACE_DATA TraceThreadData From e3016af23b88aa40523ced16d5af94a0c5c8627b Mon Sep 17 00:00:00 2001 From: Andrew Brygin Date: Fri, 13 Sep 2013 20:28:17 +0400 Subject: [PATCH 158/210] 8024697: Fix for 8020983 causes Xcheck:jni warnings Reviewed-by: prr, jchen --- .../native/sun/awt/image/jpeg/imageioJPEG.c | 18 +++++++++++------- .../plugins/jpeg/JpegWriterLeakTest.java | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c b/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c index e0716b1835b..fce061d0fb8 100644 --- a/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c +++ b/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c @@ -930,9 +930,10 @@ imageio_fill_input_buffer(j_decompress_ptr cinfo) * Now fill a complete buffer, or as much of one as the stream * will give us if we are near the end. */ + RELEASE_ARRAYS(env, data, src->next_input_byte); + GET_IO_REF(input); - RELEASE_ARRAYS(env, data, src->next_input_byte); ret = (*env)->CallIntMethod(env, input, JPEGImageReader_readInputDataID, @@ -1017,9 +1018,11 @@ imageio_fill_suspended_buffer(j_decompress_ptr cinfo) memcpy(sb->buf, src->next_input_byte, offset); } - GET_IO_REF(input); RELEASE_ARRAYS(env, data, src->next_input_byte); + + GET_IO_REF(input); + buflen = sb->bufferLength - offset; if (buflen <= 0) { if (!GET_ARRAYS(env, data, &(src->next_input_byte))) { @@ -1121,9 +1124,10 @@ imageio_skip_input_data(j_decompress_ptr cinfo, long num_bytes) return; } + RELEASE_ARRAYS(env, data, src->next_input_byte); + GET_IO_REF(input); - RELEASE_ARRAYS(env, data, src->next_input_byte); ret = (*env)->CallLongMethod(env, input, JPEGImageReader_skipInputBytesID, @@ -2306,10 +2310,10 @@ imageio_empty_output_buffer (j_compress_ptr cinfo) JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); jobject output = NULL; - GET_IO_REF(output); - RELEASE_ARRAYS(env, data, (const JOCTET *)(dest->next_output_byte)); + GET_IO_REF(output); + (*env)->CallVoidMethod(env, output, JPEGImageWriter_writeOutputDataID, @@ -2348,10 +2352,10 @@ imageio_term_destination (j_compress_ptr cinfo) if (datacount != 0) { jobject output = NULL; - GET_IO_REF(output); - RELEASE_ARRAYS(env, data, (const JOCTET *)(dest->next_output_byte)); + GET_IO_REF(output); + (*env)->CallVoidMethod(env, output, JPEGImageWriter_writeOutputDataID, diff --git a/jdk/test/javax/imageio/plugins/jpeg/JpegWriterLeakTest.java b/jdk/test/javax/imageio/plugins/jpeg/JpegWriterLeakTest.java index ffb2b63b0b0..bb5fc06e99b 100644 --- a/jdk/test/javax/imageio/plugins/jpeg/JpegWriterLeakTest.java +++ b/jdk/test/javax/imageio/plugins/jpeg/JpegWriterLeakTest.java @@ -23,7 +23,7 @@ /** * @test - * @bug 8020983 + * @bug 8020983 8024697 * @summary Test verifies that jpeg writer instances are collected * even if destroy() or reset() methods is not invoked. * From 4831191842e6f1b54b5fa9ff73c2c6e8459f6aad Mon Sep 17 00:00:00 2001 From: Mike Duigou Date: Fri, 13 Sep 2013 12:06:53 -0700 Subject: [PATCH 159/210] 8024201: Update bugdatabase url Reviewed-by: wetmore --- make/scripts/webrev.ksh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/make/scripts/webrev.ksh b/make/scripts/webrev.ksh index 9fef47fa69e..3839b7490f5 100644 --- a/make/scripts/webrev.ksh +++ b/make/scripts/webrev.ksh @@ -27,7 +27,7 @@ # Documentation is available via 'webrev -h'. # -WEBREV_UPDATED=24.0-hg+jbs +WEBREV_UPDATED=24.1-hg+openjdk.java.net HTML=' +# ' # JDK-1234567 my bugid' > .html # # framed_sdiff() is then called which creates $2.frames.html @@ -1476,7 +1476,7 @@ function treestatus # The first and last are simple addition while the middle one # is a move/rename or a copy. We can't distinguish from a rename vs a copy # without also getting the status of removed files. The middle case above - # is a rename if File4 is also shown a being removed. If File4 is not a + # is a rename if File4 is also shown a being removed. If File4 is not a # removed file, then the middle case is a copy from File4 to subdir/File4 # FIXME - we're not distinguishing copy from rename $HGCMD -aC | $FILTER | while read LINE; do @@ -1644,7 +1644,7 @@ function flist_from_mercurial # The first and last are simple addition while the middle one # is a move/rename or a copy. We can't distinguish from a rename vs a copy # without also getting the status of removed files. The middle case above - # is a rename if File4 is also shown a being removed. If File4 is not a + # is a rename if File4 is also shown a being removed. If File4 is not a # removed file, then the middle case is a copy from File4 to subdir/File4 # FIXME - we're not distinguishing copy from rename @@ -2529,7 +2529,7 @@ print " Output to: $WDIR" # Bug IDs will be replaced by a URL. Order of precedence # is: default location, $WEBREV_BUGURL, the -O flag. # -BUGURL='https://jbs.oracle.com/bugs/browse/' +BUGURL='https://bugs.openjdk.java.net/browse/' [[ -n $WEBREV_BUGURL ]] && BUGURL="$WEBREV_BUGURL" if [[ -n "$Oflag" ]]; then CRID=`echo $CRID | sed -e 's/JDK-//'` @@ -3056,7 +3056,7 @@ if [[ -n $CRID ]]; then for id in $CRID do if [[ -z "$Oflag" ]]; then - #add "JDK-" to raw bug id for jbs links. + #add "JDK-" to raw bug id for openjdk.java.net links. id=`echo ${id} | sed 's/^\([0-9]\{5,\}\)$/JDK-\1/'` fi print "
    Bug id:" From 5c11ecebfba784fda6007fda8447fc60d02224a8 Mon Sep 17 00:00:00 2001 From: Serguei Spitsyn Date: Fri, 13 Sep 2013 12:46:40 -0700 Subject: [PATCH 160/210] 8017230: Internal Error (jvmtiRedefineClasses.cpp:1662): guarantee(false) failed: insert_space_at() failed Handle pending exceptions instead of firing a guarantee() Reviewed-by: coleenp, dholmes --- .../share/vm/prims/jvmtiRedefineClasses.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/hotspot/src/share/vm/prims/jvmtiRedefineClasses.cpp b/hotspot/src/share/vm/prims/jvmtiRedefineClasses.cpp index 803cf9a7545..5330ab791b2 100644 --- a/hotspot/src/share/vm/prims/jvmtiRedefineClasses.cpp +++ b/hotspot/src/share/vm/prims/jvmtiRedefineClasses.cpp @@ -1590,11 +1590,23 @@ bool VM_RedefineClasses::rewrite_cp_refs_in_methods( for (int i = methods->length() - 1; i >= 0; i--) { methodHandle method(THREAD, methods->at(i)); methodHandle new_method; - rewrite_cp_refs_in_method(method, &new_method, CHECK_false); + rewrite_cp_refs_in_method(method, &new_method, THREAD); if (!new_method.is_null()) { // the method has been replaced so save the new method version + // even in the case of an exception. original method is on the + // deallocation list. methods->at_put(i, new_method()); } + if (HAS_PENDING_EXCEPTION) { + Symbol* ex_name = PENDING_EXCEPTION->klass()->name(); + // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark + RC_TRACE_WITH_THREAD(0x00000002, THREAD, + ("rewrite_cp_refs_in_method exception: '%s'", ex_name->as_C_string())); + // Need to clear pending exception here as the super caller sets + // the JVMTI_ERROR_INTERNAL if the returned value is false. + CLEAR_PENDING_EXCEPTION; + return false; + } } return true; @@ -1674,10 +1686,7 @@ void VM_RedefineClasses::rewrite_cp_refs_in_method(methodHandle method, Pause_No_Safepoint_Verifier pnsv(&nsv); // ldc is 2 bytes and ldc_w is 3 bytes - m = rc.insert_space_at(bci, 3, inst_buffer, THREAD); - if (m.is_null() || HAS_PENDING_EXCEPTION) { - guarantee(false, "insert_space_at() failed"); - } + m = rc.insert_space_at(bci, 3, inst_buffer, CHECK); } // return the new method so that the caller can update From 47e8234251c09ec74d0de11f602b6c9a2c51d432 Mon Sep 17 00:00:00 2001 From: Serguei Spitsyn Date: Fri, 13 Sep 2013 12:47:44 -0700 Subject: [PATCH 161/210] 8024345: 'assert(_value != NULL) failed: resolving NULL _value' from VM_RedefineClasses::set_new_constant_pool The OOME's in the JVMTI merge_cp_and_rewrite and set_new_constant_pool must be handled correctly Reviewed-by: coleenp, dholmes --- .../share/vm/prims/jvmtiRedefineClasses.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/hotspot/src/share/vm/prims/jvmtiRedefineClasses.cpp b/hotspot/src/share/vm/prims/jvmtiRedefineClasses.cpp index 5330ab791b2..69e1c9f949c 100644 --- a/hotspot/src/share/vm/prims/jvmtiRedefineClasses.cpp +++ b/hotspot/src/share/vm/prims/jvmtiRedefineClasses.cpp @@ -1395,8 +1395,8 @@ jvmtiError VM_RedefineClasses::merge_cp_and_rewrite( ClassLoaderData* loader_data = the_class->class_loader_data(); ConstantPool* merge_cp_oop = ConstantPool::allocate(loader_data, - merge_cp_length, - THREAD); + merge_cp_length, + CHECK_(JVMTI_ERROR_OUT_OF_MEMORY)); MergeCPCleaner cp_cleaner(loader_data, merge_cp_oop); HandleMark hm(THREAD); // make sure handles are cleared before @@ -1472,7 +1472,8 @@ jvmtiError VM_RedefineClasses::merge_cp_and_rewrite( // Replace the new constant pool with a shrunken copy of the // merged constant pool - set_new_constant_pool(loader_data, scratch_class, merge_cp, merge_cp_length, THREAD); + set_new_constant_pool(loader_data, scratch_class, merge_cp, merge_cp_length, + CHECK_(JVMTI_ERROR_OUT_OF_MEMORY)); // The new constant pool replaces scratch_cp so have cleaner clean it up. // It can't be cleaned up while there are handles to it. cp_cleaner.add_scratch_cp(scratch_cp()); @@ -1502,7 +1503,8 @@ jvmtiError VM_RedefineClasses::merge_cp_and_rewrite( // merged constant pool so now the rewritten bytecodes have // valid references; the previous new constant pool will get // GCed. - set_new_constant_pool(loader_data, scratch_class, merge_cp, merge_cp_length, THREAD); + set_new_constant_pool(loader_data, scratch_class, merge_cp, merge_cp_length, + CHECK_(JVMTI_ERROR_OUT_OF_MEMORY)); // The new constant pool replaces scratch_cp so have cleaner clean it up. // It can't be cleaned up while there are handles to it. cp_cleaner.add_scratch_cp(scratch_cp()); @@ -2496,8 +2498,8 @@ void VM_RedefineClasses::set_new_constant_pool( // scratch_cp is a merged constant pool and has enough space for a // worst case merge situation. We want to associate the minimum // sized constant pool with the klass to save space. - constantPoolHandle smaller_cp(THREAD, - ConstantPool::allocate(loader_data, scratch_cp_length, THREAD)); + ConstantPool* cp = ConstantPool::allocate(loader_data, scratch_cp_length, CHECK); + constantPoolHandle smaller_cp(THREAD, cp); // preserve version() value in the smaller copy int version = scratch_cp->version(); @@ -2509,6 +2511,11 @@ void VM_RedefineClasses::set_new_constant_pool( smaller_cp->set_pool_holder(scratch_class()); scratch_cp->copy_cp_to(1, scratch_cp_length - 1, smaller_cp, 1, THREAD); + if (HAS_PENDING_EXCEPTION) { + // Exception is handled in the caller + loader_data->add_to_deallocate_list(smaller_cp()); + return; + } scratch_cp = smaller_cp; // attach new constant pool to klass From 2823ae69434df3acb2a94227539fd6f7038db557 Mon Sep 17 00:00:00 2001 From: Serguei Spitsyn Date: Fri, 13 Sep 2013 12:48:50 -0700 Subject: [PATCH 162/210] 8024346: ~CautiouslyPreserveExceptionMark - assert(!_thread->has_pending_exception()) failed: unexpected exception generated Pending exceptions must be handled properly after a call to the JVMTI merge_cp_and_rewrite Reviewed-by: coleenp, dholmes --- .../src/share/vm/prims/jvmtiRedefineClasses.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/hotspot/src/share/vm/prims/jvmtiRedefineClasses.cpp b/hotspot/src/share/vm/prims/jvmtiRedefineClasses.cpp index 69e1c9f949c..6894ec3f1f4 100644 --- a/hotspot/src/share/vm/prims/jvmtiRedefineClasses.cpp +++ b/hotspot/src/share/vm/prims/jvmtiRedefineClasses.cpp @@ -1072,8 +1072,17 @@ jvmtiError VM_RedefineClasses::load_new_class_versions(TRAPS) { } res = merge_cp_and_rewrite(the_class, scratch_class, THREAD); - if (res != JVMTI_ERROR_NONE) { - return res; + if (HAS_PENDING_EXCEPTION) { + Symbol* ex_name = PENDING_EXCEPTION->klass()->name(); + // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark + RC_TRACE_WITH_THREAD(0x00000002, THREAD, + ("merge_cp_and_rewrite exception: '%s'", ex_name->as_C_string())); + CLEAR_PENDING_EXCEPTION; + if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) { + return JVMTI_ERROR_OUT_OF_MEMORY; + } else { + return JVMTI_ERROR_INTERNAL; + } } if (VerifyMergedCPBytecodes) { @@ -1105,6 +1114,9 @@ jvmtiError VM_RedefineClasses::load_new_class_versions(TRAPS) { } if (HAS_PENDING_EXCEPTION) { Symbol* ex_name = PENDING_EXCEPTION->klass()->name(); + // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark + RC_TRACE_WITH_THREAD(0x00000002, THREAD, + ("Rewriter::rewrite or link_methods exception: '%s'", ex_name->as_C_string())); CLEAR_PENDING_EXCEPTION; if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) { return JVMTI_ERROR_OUT_OF_MEMORY; From 4fa99b3fc5fa1a52b1e7edd24076ab6d83e70e7d Mon Sep 17 00:00:00 2001 From: Christian Thalinger Date: Fri, 13 Sep 2013 16:55:44 -0700 Subject: [PATCH 163/210] 8024760: add more types, fields and constants to VMStructs Reviewed-by: kvn, coleenp --- .../sun/jvm/hotspot/CommandProcessor.java | 2 + .../vm/gc_implementation/g1/ptrQueue.hpp | 1 + .../vm/gc_implementation/g1/vmStructs_g1.hpp | 3 +- hotspot/src/share/vm/memory/universe.cpp | 8 +- hotspot/src/share/vm/memory/universe.hpp | 2 + hotspot/src/share/vm/oops/klassVtable.hpp | 2 + hotspot/src/share/vm/oops/methodData.hpp | 2 + hotspot/src/share/vm/runtime/os.hpp | 2 + hotspot/src/share/vm/runtime/vmStructs.cpp | 119 ++++++++++++++++-- 9 files changed, 123 insertions(+), 18 deletions(-) diff --git a/hotspot/agent/src/share/classes/sun/jvm/hotspot/CommandProcessor.java b/hotspot/agent/src/share/classes/sun/jvm/hotspot/CommandProcessor.java index 1840caf9313..354f0b906b3 100644 --- a/hotspot/agent/src/share/classes/sun/jvm/hotspot/CommandProcessor.java +++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/CommandProcessor.java @@ -1213,6 +1213,7 @@ public class CommandProcessor { } HotSpotTypeDataBase db = (HotSpotTypeDataBase)agent.getTypeDataBase(); if (t.countTokens() == 1) { + String name = t.nextToken(); out.println("intConstant " + name + " " + db.lookupIntConstant(name)); } else if (t.countTokens() == 0) { Iterator i = db.getIntConstants(); @@ -1235,6 +1236,7 @@ public class CommandProcessor { } HotSpotTypeDataBase db = (HotSpotTypeDataBase)agent.getTypeDataBase(); if (t.countTokens() == 1) { + String name = t.nextToken(); out.println("longConstant " + name + " " + db.lookupLongConstant(name)); } else if (t.countTokens() == 0) { Iterator i = db.getLongConstants(); diff --git a/hotspot/src/share/vm/gc_implementation/g1/ptrQueue.hpp b/hotspot/src/share/vm/gc_implementation/g1/ptrQueue.hpp index 1f6d9b21388..958317166ea 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/ptrQueue.hpp +++ b/hotspot/src/share/vm/gc_implementation/g1/ptrQueue.hpp @@ -38,6 +38,7 @@ class PtrQueueSet; class PtrQueue VALUE_OBJ_CLASS_SPEC { + friend class VMStructs; protected: // The ptr queue set to which this queue belongs. diff --git a/hotspot/src/share/vm/gc_implementation/g1/vmStructs_g1.hpp b/hotspot/src/share/vm/gc_implementation/g1/vmStructs_g1.hpp index 5507dee5f80..736c2d75096 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/vmStructs_g1.hpp +++ b/hotspot/src/share/vm/gc_implementation/g1/vmStructs_g1.hpp @@ -31,7 +31,8 @@ #define VM_STRUCTS_G1(nonstatic_field, static_field) \ \ - static_field(HeapRegion, GrainBytes, size_t) \ + static_field(HeapRegion, GrainBytes, size_t) \ + static_field(HeapRegion, LogOfHRGrainBytes, int) \ \ nonstatic_field(HeapRegionSeq, _regions, HeapRegion**) \ nonstatic_field(HeapRegionSeq, _length, uint) \ diff --git a/hotspot/src/share/vm/memory/universe.cpp b/hotspot/src/share/vm/memory/universe.cpp index 143c0c00c45..f00a10f74a4 100644 --- a/hotspot/src/share/vm/memory/universe.cpp +++ b/hotspot/src/share/vm/memory/universe.cpp @@ -602,7 +602,7 @@ oop Universe::gen_out_of_memory_error(oop default_err) { } } -static intptr_t non_oop_bits = 0; +intptr_t Universe::_non_oop_bits = 0; void* Universe::non_oop_word() { // Neither the high bits nor the low bits of this value is allowed @@ -616,11 +616,11 @@ void* Universe::non_oop_word() { // Using the OS-supplied non-memory-address word (usually 0 or -1) // will take care of the high bits, however many there are. - if (non_oop_bits == 0) { - non_oop_bits = (intptr_t)os::non_memory_address_word() | 1; + if (_non_oop_bits == 0) { + _non_oop_bits = (intptr_t)os::non_memory_address_word() | 1; } - return (void*)non_oop_bits; + return (void*)_non_oop_bits; } jint universe_init() { diff --git a/hotspot/src/share/vm/memory/universe.hpp b/hotspot/src/share/vm/memory/universe.hpp index a8b541d03a1..09b52c099f2 100644 --- a/hotspot/src/share/vm/memory/universe.hpp +++ b/hotspot/src/share/vm/memory/universe.hpp @@ -179,6 +179,8 @@ class Universe: AllStatic { // The particular choice of collected heap. static CollectedHeap* _collectedHeap; + static intptr_t _non_oop_bits; + // For UseCompressedOops. static struct NarrowPtrStruct _narrow_oop; // For UseCompressedKlassPointers. diff --git a/hotspot/src/share/vm/oops/klassVtable.hpp b/hotspot/src/share/vm/oops/klassVtable.hpp index 01495e35d90..8d8d6cf27c5 100644 --- a/hotspot/src/share/vm/oops/klassVtable.hpp +++ b/hotspot/src/share/vm/oops/klassVtable.hpp @@ -150,6 +150,8 @@ class klassVtable : public ResourceObj { // from_compiled_code_entry_point -> nmethod entry point // from_interpreter_entry_point -> i2cadapter class vtableEntry VALUE_OBJ_CLASS_SPEC { + friend class VMStructs; + public: // size in words static int size() { diff --git a/hotspot/src/share/vm/oops/methodData.hpp b/hotspot/src/share/vm/oops/methodData.hpp index 765b91c142c..7ff9b2bbb6d 100644 --- a/hotspot/src/share/vm/oops/methodData.hpp +++ b/hotspot/src/share/vm/oops/methodData.hpp @@ -72,6 +72,8 @@ class ProfileData; // // Overlay for generic profiling data. class DataLayout VALUE_OBJ_CLASS_SPEC { + friend class VMStructs; + private: // Every data layout begins with a header. This header // contains a tag, which is used to indicate the size/layout diff --git a/hotspot/src/share/vm/runtime/os.hpp b/hotspot/src/share/vm/runtime/os.hpp index e43d68981cb..b224a3d7427 100644 --- a/hotspot/src/share/vm/runtime/os.hpp +++ b/hotspot/src/share/vm/runtime/os.hpp @@ -91,6 +91,8 @@ const bool ExecMem = true; typedef void (*java_call_t)(JavaValue* value, methodHandle* method, JavaCallArguments* args, Thread* thread); class os: AllStatic { + friend class VMStructs; + public: enum { page_sizes_max = 9 }; // Size of _page_sizes array (8 plus a sentinel) diff --git a/hotspot/src/share/vm/runtime/vmStructs.cpp b/hotspot/src/share/vm/runtime/vmStructs.cpp index 7e0df23a3e1..448a8919f0e 100644 --- a/hotspot/src/share/vm/runtime/vmStructs.cpp +++ b/hotspot/src/share/vm/runtime/vmStructs.cpp @@ -330,11 +330,13 @@ typedef BinaryTreeDictionary MetablockTreeDictionary; nonstatic_field(Klass, _java_mirror, oop) \ nonstatic_field(Klass, _modifier_flags, jint) \ nonstatic_field(Klass, _super, Klass*) \ + nonstatic_field(Klass, _subklass, Klass*) \ nonstatic_field(Klass, _layout_helper, jint) \ nonstatic_field(Klass, _name, Symbol*) \ nonstatic_field(Klass, _access_flags, AccessFlags) \ - nonstatic_field(Klass, _subklass, Klass*) \ + nonstatic_field(Klass, _prototype_header, markOop) \ nonstatic_field(Klass, _next_sibling, Klass*) \ + nonstatic_field(vtableEntry, _method, Method*) \ nonstatic_field(MethodData, _size, int) \ nonstatic_field(MethodData, _method, Method*) \ nonstatic_field(MethodData, _data_size, int) \ @@ -342,10 +344,15 @@ typedef BinaryTreeDictionary MetablockTreeDictionary; nonstatic_field(MethodData, _nof_decompiles, uint) \ nonstatic_field(MethodData, _nof_overflow_recompiles, uint) \ nonstatic_field(MethodData, _nof_overflow_traps, uint) \ + nonstatic_field(MethodData, _trap_hist._array[0], u1) \ nonstatic_field(MethodData, _eflags, intx) \ nonstatic_field(MethodData, _arg_local, intx) \ nonstatic_field(MethodData, _arg_stack, intx) \ nonstatic_field(MethodData, _arg_returned, intx) \ + nonstatic_field(DataLayout, _header._struct._tag, u1) \ + nonstatic_field(DataLayout, _header._struct._flags, u1) \ + nonstatic_field(DataLayout, _header._struct._bci, u2) \ + nonstatic_field(DataLayout, _cells[0], intptr_t) \ nonstatic_field(MethodCounters, _interpreter_invocation_count, int) \ nonstatic_field(MethodCounters, _interpreter_throwout_count, u2) \ nonstatic_field(MethodCounters, _number_of_breakpoints, u2) \ @@ -357,6 +364,7 @@ typedef BinaryTreeDictionary MetablockTreeDictionary; nonstatic_field(Method, _access_flags, AccessFlags) \ nonstatic_field(Method, _vtable_index, int) \ nonstatic_field(Method, _method_size, u2) \ + nonstatic_field(Method, _intrinsic_id, u1) \ nonproduct_nonstatic_field(Method, _compiled_invocation_count, int) \ volatile_nonstatic_field(Method, _code, nmethod*) \ nonstatic_field(Method, _i2i_entry, address) \ @@ -443,12 +451,19 @@ typedef BinaryTreeDictionary MetablockTreeDictionary; static_field(Universe, _bootstrapping, bool) \ static_field(Universe, _fully_initialized, bool) \ static_field(Universe, _verify_count, int) \ + static_field(Universe, _non_oop_bits, intptr_t) \ static_field(Universe, _narrow_oop._base, address) \ static_field(Universe, _narrow_oop._shift, int) \ static_field(Universe, _narrow_oop._use_implicit_null_checks, bool) \ static_field(Universe, _narrow_klass._base, address) \ static_field(Universe, _narrow_klass._shift, int) \ \ + /******/ \ + /* os */ \ + /******/ \ + \ + static_field(os, _polling_page, address) \ + \ /**********************************************************************************/ \ /* Generation and Space hierarchies */ \ /**********************************************************************************/ \ @@ -456,6 +471,7 @@ typedef BinaryTreeDictionary MetablockTreeDictionary; unchecked_nonstatic_field(ageTable, sizes, sizeof(ageTable::sizes)) \ \ nonstatic_field(BarrierSet, _max_covered_regions, int) \ + nonstatic_field(BarrierSet, _kind, BarrierSet::Name) \ nonstatic_field(BlockOffsetTable, _bottom, HeapWord*) \ nonstatic_field(BlockOffsetTable, _end, HeapWord*) \ \ @@ -495,6 +511,7 @@ typedef BinaryTreeDictionary MetablockTreeDictionary; nonstatic_field(CollectedHeap, _barrier_set, BarrierSet*) \ nonstatic_field(CollectedHeap, _defer_initial_card_mark, bool) \ nonstatic_field(CollectedHeap, _is_gc_active, bool) \ + nonstatic_field(CollectedHeap, _total_collections, unsigned int) \ nonstatic_field(CompactibleSpace, _compaction_top, HeapWord*) \ nonstatic_field(CompactibleSpace, _first_dead, HeapWord*) \ nonstatic_field(CompactibleSpace, _end_of_live, HeapWord*) \ @@ -505,7 +522,7 @@ typedef BinaryTreeDictionary MetablockTreeDictionary; nonstatic_field(ContiguousSpace, _saved_mark_word, HeapWord*) \ \ nonstatic_field(DefNewGeneration, _next_gen, Generation*) \ - nonstatic_field(DefNewGeneration, _tenuring_threshold, uint) \ + nonstatic_field(DefNewGeneration, _tenuring_threshold, uint) \ nonstatic_field(DefNewGeneration, _age_table, ageTable) \ nonstatic_field(DefNewGeneration, _eden_space, EdenSpace*) \ nonstatic_field(DefNewGeneration, _from_space, ContiguousSpace*) \ @@ -552,6 +569,11 @@ typedef BinaryTreeDictionary MetablockTreeDictionary; nonstatic_field(ThreadLocalAllocBuffer, _desired_size, size_t) \ nonstatic_field(ThreadLocalAllocBuffer, _refill_waste_limit, size_t) \ static_field(ThreadLocalAllocBuffer, _target_refills, unsigned) \ + nonstatic_field(ThreadLocalAllocBuffer, _number_of_refills, unsigned) \ + nonstatic_field(ThreadLocalAllocBuffer, _fast_refill_waste, unsigned) \ + nonstatic_field(ThreadLocalAllocBuffer, _slow_refill_waste, unsigned) \ + nonstatic_field(ThreadLocalAllocBuffer, _gc_waste, unsigned) \ + nonstatic_field(ThreadLocalAllocBuffer, _slow_allocations, unsigned) \ nonstatic_field(VirtualSpace, _low_boundary, char*) \ nonstatic_field(VirtualSpace, _high_boundary, char*) \ nonstatic_field(VirtualSpace, _low, char*) \ @@ -713,6 +735,13 @@ typedef BinaryTreeDictionary MetablockTreeDictionary; \ static_field(ClassLoaderDataGraph, _head, ClassLoaderData*) \ \ + /**********/ \ + /* Arrays */ \ + /**********/ \ + \ + nonstatic_field(Array, _length, int) \ + nonstatic_field(Array, _data[0], Klass*) \ + \ /*******************/ \ /* GrowableArrays */ \ /*******************/ \ @@ -720,7 +749,7 @@ typedef BinaryTreeDictionary MetablockTreeDictionary; nonstatic_field(GenericGrowableArray, _len, int) \ nonstatic_field(GenericGrowableArray, _max, int) \ nonstatic_field(GenericGrowableArray, _arena, Arena*) \ - nonstatic_field(GrowableArray, _data, int*) \ + nonstatic_field(GrowableArray, _data, int*) \ \ /********************************/ \ /* CodeCache (NOTE: incomplete) */ \ @@ -763,7 +792,20 @@ typedef BinaryTreeDictionary MetablockTreeDictionary; /* StubRoutines (NOTE: incomplete) */ \ /***********************************/ \ \ + static_field(StubRoutines, _verify_oop_count, jint) \ static_field(StubRoutines, _call_stub_return_address, address) \ + static_field(StubRoutines, _aescrypt_encryptBlock, address) \ + static_field(StubRoutines, _aescrypt_decryptBlock, address) \ + static_field(StubRoutines, _cipherBlockChaining_encryptAESCrypt, address) \ + static_field(StubRoutines, _cipherBlockChaining_decryptAESCrypt, address) \ + static_field(StubRoutines, _updateBytesCRC32, address) \ + static_field(StubRoutines, _crc_table_adr, address) \ + \ + /*****************/ \ + /* SharedRuntime */ \ + /*****************/ \ + \ + static_field(SharedRuntime, _ic_miss_blob, RuntimeStub*) \ \ /***************************************/ \ /* PcDesc and other compiled code info */ \ @@ -853,6 +895,7 @@ typedef BinaryTreeDictionary MetablockTreeDictionary; volatile_nonstatic_field(Thread, _suspend_flags, uint32_t) \ nonstatic_field(Thread, _active_handles, JNIHandleBlock*) \ nonstatic_field(Thread, _tlab, ThreadLocalAllocBuffer) \ + nonstatic_field(Thread, _allocated_bytes, jlong) \ nonstatic_field(Thread, _current_pending_monitor, ObjectMonitor*) \ nonstatic_field(Thread, _current_pending_monitor_is_from_java, bool) \ nonstatic_field(Thread, _current_waiting_monitor, ObjectMonitor*) \ @@ -866,6 +909,7 @@ typedef BinaryTreeDictionary MetablockTreeDictionary; nonstatic_field(JavaThread, _pending_async_exception, oop) \ volatile_nonstatic_field(JavaThread, _exception_oop, oop) \ volatile_nonstatic_field(JavaThread, _exception_pc, address) \ + volatile_nonstatic_field(JavaThread, _is_method_handle_return, int) \ nonstatic_field(JavaThread, _is_compiling, bool) \ nonstatic_field(JavaThread, _special_runtime_exit_condition, JavaThread::AsyncRequests) \ nonstatic_field(JavaThread, _saved_exception_pc, address) \ @@ -875,6 +919,8 @@ typedef BinaryTreeDictionary MetablockTreeDictionary; nonstatic_field(JavaThread, _stack_size, size_t) \ nonstatic_field(JavaThread, _vframe_array_head, vframeArray*) \ nonstatic_field(JavaThread, _vframe_array_last, vframeArray*) \ + nonstatic_field(JavaThread, _satb_mark_queue, ObjPtrQueue) \ + nonstatic_field(JavaThread, _dirty_card_queue, DirtyCardQueue) \ nonstatic_field(Thread, _resource_area, ResourceArea*) \ nonstatic_field(CompilerThread, _env, ciEnv*) \ \ @@ -1187,7 +1233,7 @@ typedef BinaryTreeDictionary MetablockTreeDictionary; unchecked_nonstatic_field(Array, _data, sizeof(int)) \ unchecked_nonstatic_field(Array, _data, sizeof(u1)) \ unchecked_nonstatic_field(Array, _data, sizeof(u2)) \ - unchecked_nonstatic_field(Array, _data, sizeof(Method*)) \ + unchecked_nonstatic_field(Array, _data, sizeof(Method*)) \ unchecked_nonstatic_field(Array, _data, sizeof(Klass*)) \ \ /*********************************/ \ @@ -1203,7 +1249,7 @@ typedef BinaryTreeDictionary MetablockTreeDictionary; /* Miscellaneous fields */ \ /************************/ \ \ - nonstatic_field(CompileTask, _method, Method*) \ + nonstatic_field(CompileTask, _method, Method*) \ nonstatic_field(CompileTask, _osr_bci, int) \ nonstatic_field(CompileTask, _comp_level, int) \ nonstatic_field(CompileTask, _compile_id, uint) \ @@ -1217,7 +1263,11 @@ typedef BinaryTreeDictionary MetablockTreeDictionary; \ nonstatic_field(vframeArrayElement, _frame, frame) \ nonstatic_field(vframeArrayElement, _bci, int) \ - nonstatic_field(vframeArrayElement, _method, Method*) \ + nonstatic_field(vframeArrayElement, _method, Method*) \ + \ + nonstatic_field(PtrQueue, _active, bool) \ + nonstatic_field(PtrQueue, _buf, void**) \ + nonstatic_field(PtrQueue, _index, size_t) \ \ nonstatic_field(AccessFlags, _flags, jint) \ nonstatic_field(elapsedTimer, _counter, jlong) \ @@ -1363,7 +1413,7 @@ typedef BinaryTreeDictionary MetablockTreeDictionary; /* MetadataOopDesc hierarchy (NOTE: some missing) */ \ /**************************************************/ \ \ - declare_toplevel_type(CompiledICHolder) \ + declare_toplevel_type(CompiledICHolder) \ declare_toplevel_type(MetaspaceObj) \ declare_type(Metadata, MetaspaceObj) \ declare_type(Klass, Metadata) \ @@ -1374,17 +1424,20 @@ typedef BinaryTreeDictionary MetablockTreeDictionary; declare_type(InstanceClassLoaderKlass, InstanceKlass) \ declare_type(InstanceMirrorKlass, InstanceKlass) \ declare_type(InstanceRefKlass, InstanceKlass) \ - declare_type(ConstantPool, Metadata) \ - declare_type(ConstantPoolCache, MetaspaceObj) \ - declare_type(MethodData, Metadata) \ - declare_type(Method, Metadata) \ - declare_type(MethodCounters, MetaspaceObj) \ - declare_type(ConstMethod, MetaspaceObj) \ + declare_type(ConstantPool, Metadata) \ + declare_type(ConstantPoolCache, MetaspaceObj) \ + declare_type(MethodData, Metadata) \ + declare_type(Method, Metadata) \ + declare_type(MethodCounters, MetaspaceObj) \ + declare_type(ConstMethod, MetaspaceObj) \ + \ + declare_toplevel_type(vtableEntry) \ \ declare_toplevel_type(Symbol) \ declare_toplevel_type(Symbol*) \ declare_toplevel_type(volatile Metadata*) \ \ + declare_toplevel_type(DataLayout) \ declare_toplevel_type(nmethodBucket) \ \ /********/ \ @@ -1432,6 +1485,7 @@ typedef BinaryTreeDictionary MetablockTreeDictionary; declare_type(ModRefBarrierSet, BarrierSet) \ declare_type(CardTableModRefBS, ModRefBarrierSet) \ declare_type(CardTableModRefBSForCTRS, CardTableModRefBS) \ + declare_toplevel_type(BarrierSet::Name) \ declare_toplevel_type(GenRemSet) \ declare_type(CardTableRS, GenRemSet) \ declare_toplevel_type(BlockOffsetSharedArray) \ @@ -1450,6 +1504,8 @@ typedef BinaryTreeDictionary MetablockTreeDictionary; declare_toplevel_type(ThreadLocalAllocBuffer) \ declare_toplevel_type(VirtualSpace) \ declare_toplevel_type(WaterMark) \ + declare_toplevel_type(ObjPtrQueue) \ + declare_toplevel_type(DirtyCardQueue) \ \ /* Pointers to Garbage Collection types */ \ \ @@ -2068,6 +2124,7 @@ typedef BinaryTreeDictionary MetablockTreeDictionary; declare_toplevel_type(StubQueue*) \ declare_toplevel_type(Thread*) \ declare_toplevel_type(Universe) \ + declare_toplevel_type(os) \ declare_toplevel_type(vframeArray) \ declare_toplevel_type(vframeArrayElement) \ declare_toplevel_type(Annotations*) \ @@ -2076,6 +2133,8 @@ typedef BinaryTreeDictionary MetablockTreeDictionary; /* Miscellaneous types */ \ /***************/ \ \ + declare_toplevel_type(PtrQueue) \ + \ /* freelist */ \ declare_toplevel_type(FreeChunk*) \ declare_toplevel_type(Metablock*) \ @@ -2106,6 +2165,7 @@ typedef BinaryTreeDictionary MetablockTreeDictionary; /* Useful globals */ \ /******************/ \ \ + declare_preprocessor_constant("ASSERT", DEBUG_ONLY(1) NOT_DEBUG(0)) \ \ /**************/ \ /* Stack bias */ \ @@ -2122,6 +2182,8 @@ typedef BinaryTreeDictionary MetablockTreeDictionary; declare_constant(BytesPerWord) \ declare_constant(BytesPerLong) \ \ + declare_constant(LogKlassAlignmentInBytes) \ + \ /********************************************/ \ /* Generation and Space Hierarchy Constants */ \ /********************************************/ \ @@ -2130,6 +2192,9 @@ typedef BinaryTreeDictionary MetablockTreeDictionary; \ declare_constant(BarrierSet::ModRef) \ declare_constant(BarrierSet::CardTableModRef) \ + declare_constant(BarrierSet::CardTableExtension) \ + declare_constant(BarrierSet::G1SATBCT) \ + declare_constant(BarrierSet::G1SATBCTLogging) \ declare_constant(BarrierSet::Other) \ \ declare_constant(BlockOffsetSharedArray::LogN) \ @@ -2248,8 +2313,11 @@ typedef BinaryTreeDictionary MetablockTreeDictionary; declare_constant(Klass::_primary_super_limit) \ declare_constant(Klass::_lh_instance_slow_path_bit) \ declare_constant(Klass::_lh_log2_element_size_shift) \ + declare_constant(Klass::_lh_log2_element_size_mask) \ declare_constant(Klass::_lh_element_type_shift) \ + declare_constant(Klass::_lh_element_type_mask) \ declare_constant(Klass::_lh_header_size_shift) \ + declare_constant(Klass::_lh_header_size_mask) \ declare_constant(Klass::_lh_array_tag_shift) \ declare_constant(Klass::_lh_array_tag_type_value) \ declare_constant(Klass::_lh_array_tag_obj_value) \ @@ -2268,6 +2336,12 @@ typedef BinaryTreeDictionary MetablockTreeDictionary; declare_constant(ConstMethod::_has_default_annotations) \ declare_constant(ConstMethod::_has_type_annotations) \ \ + /**************/ \ + /* DataLayout */ \ + /**************/ \ + \ + declare_constant(DataLayout::cell_size) \ + \ /*************************************/ \ /* InstanceKlass enum */ \ /*************************************/ \ @@ -2402,6 +2476,13 @@ typedef BinaryTreeDictionary MetablockTreeDictionary; declare_constant(Deoptimization::Reason_LIMIT) \ declare_constant(Deoptimization::Reason_RECORDED_LIMIT) \ \ + declare_constant(Deoptimization::Action_none) \ + declare_constant(Deoptimization::Action_maybe_recompile) \ + declare_constant(Deoptimization::Action_reinterpret) \ + declare_constant(Deoptimization::Action_make_not_entrant) \ + declare_constant(Deoptimization::Action_make_not_compilable) \ + declare_constant(Deoptimization::Action_LIMIT) \ + \ /*********************/ \ /* Matcher (C2 only) */ \ /*********************/ \ @@ -2468,6 +2549,16 @@ typedef BinaryTreeDictionary MetablockTreeDictionary; declare_constant(vmSymbols::FIRST_SID) \ declare_constant(vmSymbols::SID_LIMIT) \ \ + /****************/ \ + /* vmIntrinsics */ \ + /****************/ \ + \ + declare_constant(vmIntrinsics::_invokeBasic) \ + declare_constant(vmIntrinsics::_linkToVirtual) \ + declare_constant(vmIntrinsics::_linkToStatic) \ + declare_constant(vmIntrinsics::_linkToSpecial) \ + declare_constant(vmIntrinsics::_linkToInterface) \ + \ /********************************/ \ /* Calling convention constants */ \ /********************************/ \ @@ -2515,6 +2606,8 @@ typedef BinaryTreeDictionary MetablockTreeDictionary; declare_constant(markOopDesc::biased_lock_bit_in_place) \ declare_constant(markOopDesc::age_mask) \ declare_constant(markOopDesc::age_mask_in_place) \ + declare_constant(markOopDesc::epoch_mask) \ + declare_constant(markOopDesc::epoch_mask_in_place) \ declare_constant(markOopDesc::hash_mask) \ declare_constant(markOopDesc::hash_mask_in_place) \ declare_constant(markOopDesc::biased_lock_alignment) \ From 7b2ffab30e57a21afe0ee70a801d4faa68d03b07 Mon Sep 17 00:00:00 2001 From: David Holmes Date: Fri, 13 Sep 2013 21:36:27 -0400 Subject: [PATCH 164/210] 8024505: [TESTBUG] update test groups for additional tests that can't run on the minimal VM Reviewed-by: coleenp, hseigel --- hotspot/test/TEST.groups | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/hotspot/test/TEST.groups b/hotspot/test/TEST.groups index bf5e3f088fb..d2ad0c7ea18 100644 --- a/hotspot/test/TEST.groups +++ b/hotspot/test/TEST.groups @@ -84,6 +84,7 @@ needs_jdk = \ runtime/NMT/ThreadedVirtualAllocTestType.java \ runtime/NMT/VirtualAllocTestType.java \ runtime/RedefineObject/TestRedefineObject.java \ + runtime/XCheckJniJsig/XCheckJSig.java \ serviceability/attach/AttachWithStalePidFile.java # JRE adds further tests to compact3 @@ -159,7 +160,18 @@ needs_full_vm_compact1 = \ gc/g1/TestRegionAlignment.java \ gc/g1/TestShrinkToOneRegion.java \ gc/metaspace/G1AddMetaspaceDependency.java \ - runtime/6929067/Test6929067.sh + gc/startup_warnings/TestCMS.java \ + gc/startup_warnings/TestCMSIncrementalMode.java \ + gc/startup_warnings/TestCMSNoIncrementalMode.java \ + gc/startup_warnings/TestDefaultMaxRAMFraction.java \ + gc/startup_warnings/TestDefNewCMS.java \ + gc/startup_warnings/TestIncGC.java \ + gc/startup_warnings/TestParallelGC.java \ + gc/startup_warnings/TestParallelScavengeSerialOld.java \ + gc/startup_warnings/TestParNewCMS.java \ + gc/startup_warnings/TestParNewSerialOld.java \ + runtime/6929067/Test6929067.sh \ + runtime/SharedArchiveFile/SharedArchiveFile.java # Minimal VM on Compact 2 adds in some compact2 tests # From 222c7354581b068ba6ff99d041084b481b08960f Mon Sep 17 00:00:00 2001 From: David Chase Date: Fri, 13 Sep 2013 22:38:02 -0400 Subject: [PATCH 165/210] 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation Enhance method resolution and resulting data structures, plus some refactoring. Reviewed-by: twisti, acorn, jrose --- hotspot/src/share/vm/c1/c1_Runtime1.cpp | 12 +- hotspot/src/share/vm/ci/ciField.cpp | 18 +- hotspot/src/share/vm/ci/ciField.hpp | 5 +- hotspot/src/share/vm/ci/ciInstanceKlass.cpp | 5 +- hotspot/src/share/vm/ci/ciMethod.cpp | 9 +- hotspot/src/share/vm/ci/ciSymbol.hpp | 3 +- .../share/vm/classfile/classFileParser.cpp | 5 +- hotspot/src/share/vm/code/compiledIC.cpp | 27 +- hotspot/src/share/vm/code/vtableStubs.cpp | 2 +- hotspot/src/share/vm/code/vtableStubs.hpp | 4 +- .../vm/interpreter/interpreterRuntime.cpp | 52 +++- .../src/share/vm/interpreter/linkResolver.cpp | 213 ++++++++++------ .../src/share/vm/interpreter/linkResolver.hpp | 111 ++++---- hotspot/src/share/vm/oops/constantPool.cpp | 26 -- hotspot/src/share/vm/oops/constantPool.hpp | 2 - hotspot/src/share/vm/oops/cpCache.cpp | 28 +- hotspot/src/share/vm/oops/cpCache.hpp | 22 +- hotspot/src/share/vm/oops/fieldStreams.hpp | 13 +- hotspot/src/share/vm/oops/instanceKlass.cpp | 119 ++------- hotspot/src/share/vm/oops/instanceKlass.hpp | 10 - hotspot/src/share/vm/oops/klass.cpp | 16 +- hotspot/src/share/vm/oops/klass.hpp | 3 +- hotspot/src/share/vm/oops/klassVtable.cpp | 239 +++++++++++------- hotspot/src/share/vm/oops/klassVtable.hpp | 6 +- hotspot/src/share/vm/oops/method.cpp | 34 ++- hotspot/src/share/vm/oops/method.hpp | 19 +- hotspot/src/share/vm/oops/symbol.hpp | 2 +- hotspot/src/share/vm/opto/library_call.cpp | 4 + hotspot/src/share/vm/prims/jni.cpp | 8 +- hotspot/src/share/vm/prims/jvm.cpp | 2 +- .../share/vm/prims/jvmtiRedefineClasses.cpp | 2 +- hotspot/src/share/vm/prims/methodHandles.cpp | 235 +++++++---------- hotspot/src/share/vm/prims/methodHandles.hpp | 13 +- .../src/share/vm/runtime/fieldDescriptor.cpp | 18 +- .../src/share/vm/runtime/fieldDescriptor.hpp | 12 +- hotspot/src/share/vm/runtime/mutexLocker.cpp | 2 - hotspot/src/share/vm/runtime/mutexLocker.hpp | 3 +- hotspot/src/share/vm/runtime/reflection.cpp | 3 +- .../src/share/vm/runtime/reflectionUtils.hpp | 8 + hotspot/src/share/vm/runtime/vmStructs.cpp | 1 - 40 files changed, 715 insertions(+), 601 deletions(-) diff --git a/hotspot/src/share/vm/c1/c1_Runtime1.cpp b/hotspot/src/share/vm/c1/c1_Runtime1.cpp index 037bc31f658..080eaf67088 100644 --- a/hotspot/src/share/vm/c1/c1_Runtime1.cpp +++ b/hotspot/src/share/vm/c1/c1_Runtime1.cpp @@ -709,10 +709,10 @@ static Klass* resolve_field_return_klass(methodHandle caller, int bci, TRAPS) { Bytecodes::Code code = field_access.code(); // We must load class, initialize class and resolvethe field - FieldAccessInfo result; // initialize class if needed + fieldDescriptor result; // initialize class if needed constantPoolHandle constants(THREAD, caller->constants()); - LinkResolver::resolve_field(result, constants, field_access.index(), Bytecodes::java_code(code), false, CHECK_NULL); - return result.klass()(); + LinkResolver::resolve_field_access(result, constants, field_access.index(), Bytecodes::java_code(code), CHECK_NULL); + return result.field_holder(); } @@ -826,11 +826,11 @@ JRT_ENTRY(void, Runtime1::patch_code(JavaThread* thread, Runtime1::StubID stub_i if (stub_id == Runtime1::access_field_patching_id) { Bytecode_field field_access(caller_method, bci); - FieldAccessInfo result; // initialize class if needed + fieldDescriptor result; // initialize class if needed Bytecodes::Code code = field_access.code(); constantPoolHandle constants(THREAD, caller_method->constants()); - LinkResolver::resolve_field(result, constants, field_access.index(), Bytecodes::java_code(code), false, CHECK); - patch_field_offset = result.field_offset(); + LinkResolver::resolve_field_access(result, constants, field_access.index(), Bytecodes::java_code(code), CHECK); + patch_field_offset = result.offset(); // If we're patching a field which is volatile then at compile it // must not have been know to be volatile, so the generated code diff --git a/hotspot/src/share/vm/ci/ciField.cpp b/hotspot/src/share/vm/ci/ciField.cpp index 1a711ae522a..b08ec3616fa 100644 --- a/hotspot/src/share/vm/ci/ciField.cpp +++ b/hotspot/src/share/vm/ci/ciField.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2013, 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 @@ -75,7 +75,6 @@ ciField::ciField(ciInstanceKlass* klass, int index): _known_to_link_with_put(NUL assert(klass->get_instanceKlass()->is_linked(), "must be linked before using its constan-pool"); - _cp_index = index; constantPoolHandle cpool(thread, klass->get_instanceKlass()->constants()); // Get the field's name, signature, and type. @@ -116,7 +115,7 @@ ciField::ciField(ciInstanceKlass* klass, int index): _known_to_link_with_put(NUL // The declared holder of this field may not have been loaded. // Bail out with partial field information. if (!holder_is_accessible) { - // _cp_index and _type have already been set. + // _type has already been set. // The default values for _flags and _constant_value will suffice. // We need values for _holder, _offset, and _is_constant, _holder = declared_holder; @@ -146,8 +145,6 @@ ciField::ciField(ciInstanceKlass* klass, int index): _known_to_link_with_put(NUL ciField::ciField(fieldDescriptor *fd): _known_to_link_with_put(NULL), _known_to_link_with_get(NULL) { ASSERT_IN_VM; - _cp_index = -1; - // Get the field's name, signature, and type. ciEnv* env = CURRENT_ENV; _name = env->get_symbol(fd->name()); @@ -351,12 +348,11 @@ bool ciField::will_link(ciInstanceKlass* accessing_klass, } } - FieldAccessInfo result; - constantPoolHandle c_pool(THREAD, - accessing_klass->get_instanceKlass()->constants()); - LinkResolver::resolve_field(result, c_pool, _cp_index, - Bytecodes::java_code(bc), - true, false, KILL_COMPILE_ON_FATAL_(false)); + fieldDescriptor result; + LinkResolver::resolve_field(result, _holder->get_instanceKlass(), + _name->get_symbol(), _signature->get_symbol(), + accessing_klass->get_Klass(), bc, true, false, + KILL_COMPILE_ON_FATAL_(false)); // update the hit-cache, unless there is a problem with memory scoping: if (accessing_klass->is_shared() || !is_shared()) { diff --git a/hotspot/src/share/vm/ci/ciField.hpp b/hotspot/src/share/vm/ci/ciField.hpp index 81af9ca79a9..75263e3f217 100644 --- a/hotspot/src/share/vm/ci/ciField.hpp +++ b/hotspot/src/share/vm/ci/ciField.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2013, 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 @@ -53,9 +53,6 @@ private: ciInstanceKlass* _known_to_link_with_get; ciConstant _constant_value; - // Used for will_link - int _cp_index; - ciType* compute_type(); ciType* compute_type_impl(); diff --git a/hotspot/src/share/vm/ci/ciInstanceKlass.cpp b/hotspot/src/share/vm/ci/ciInstanceKlass.cpp index d74e484c66e..c689efa46d6 100644 --- a/hotspot/src/share/vm/ci/ciInstanceKlass.cpp +++ b/hotspot/src/share/vm/ci/ciInstanceKlass.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2013, 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 @@ -522,8 +522,7 @@ ciInstanceKlass::compute_nonstatic_fields_impl(GrowableArray* for (JavaFieldStream fs(k); !fs.done(); fs.next()) { if (fs.access_flags().is_static()) continue; - fieldDescriptor fd; - fd.initialize(k, fs.index()); + fieldDescriptor& fd = fs.field_descriptor(); ciField* field = new (arena) ciField(&fd); fields->append(field); } diff --git a/hotspot/src/share/vm/ci/ciMethod.cpp b/hotspot/src/share/vm/ci/ciMethod.cpp index d0363250ee6..486d8c499b6 100644 --- a/hotspot/src/share/vm/ci/ciMethod.cpp +++ b/hotspot/src/share/vm/ci/ciMethod.cpp @@ -286,7 +286,10 @@ int ciMethod::itable_index() { check_is_loaded(); assert(holder()->is_linked(), "must be linked"); VM_ENTRY_MARK; - return klassItable::compute_itable_index(get_Method()); + Method* m = get_Method(); + if (!m->has_itable_index()) + return Method::nonvirtual_vtable_index; + return m->itable_index(); } #endif // SHARK @@ -1137,6 +1140,10 @@ bool ciMethod::is_klass_loaded(int refinfo_index, bool must_be_resolved) const { // ------------------------------------------------------------------ // ciMethod::check_call bool ciMethod::check_call(int refinfo_index, bool is_static) const { + // This method is used only in C2 from InlineTree::ok_to_inline, + // and is only used under -Xcomp or -XX:CompileTheWorld. + // It appears to fail when applied to an invokeinterface call site. + // FIXME: Remove this method and resolve_method_statically; refactor to use the other LinkResolver entry points. VM_ENTRY_MARK; { EXCEPTION_MARK; diff --git a/hotspot/src/share/vm/ci/ciSymbol.hpp b/hotspot/src/share/vm/ci/ciSymbol.hpp index d54b54009be..3c974cf272e 100644 --- a/hotspot/src/share/vm/ci/ciSymbol.hpp +++ b/hotspot/src/share/vm/ci/ciSymbol.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2013, 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 @@ -44,6 +44,7 @@ class ciSymbol : public ciBaseObject { friend class ciInstanceKlass; friend class ciSignature; friend class ciMethod; + friend class ciField; friend class ciObjArrayKlass; private: diff --git a/hotspot/src/share/vm/classfile/classFileParser.cpp b/hotspot/src/share/vm/classfile/classFileParser.cpp index 8972bceb434..dc00790869c 100644 --- a/hotspot/src/share/vm/classfile/classFileParser.cpp +++ b/hotspot/src/share/vm/classfile/classFileParser.cpp @@ -3954,9 +3954,8 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name, this_klass->set_has_final_method(); } this_klass->copy_method_ordering(method_ordering, CHECK_NULL); - // The InstanceKlass::_methods_jmethod_ids cache and the - // InstanceKlass::_methods_cached_itable_indices cache are - // both managed on the assumption that the initial cache + // The InstanceKlass::_methods_jmethod_ids cache + // is managed on the assumption that the initial cache // size is equal to the number of methods in the class. If // that changes, then InstanceKlass::idnum_can_increment() // has to be changed accordingly. diff --git a/hotspot/src/share/vm/code/compiledIC.cpp b/hotspot/src/share/vm/code/compiledIC.cpp index e9a63b86623..b9db323e5b2 100644 --- a/hotspot/src/share/vm/code/compiledIC.cpp +++ b/hotspot/src/share/vm/code/compiledIC.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2013, 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 @@ -161,31 +161,36 @@ address CompiledIC::stub_address() const { void CompiledIC::set_to_megamorphic(CallInfo* call_info, Bytecodes::Code bytecode, TRAPS) { - methodHandle method = call_info->selected_method(); - bool is_invoke_interface = (bytecode == Bytecodes::_invokeinterface && !call_info->has_vtable_index()); assert(CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); assert(!is_optimized(), "cannot set an optimized virtual call to megamorphic"); assert(is_call_to_compiled() || is_call_to_interpreted(), "going directly to megamorphic?"); address entry; - if (is_invoke_interface) { - int index = klassItable::compute_itable_index(call_info->resolved_method()()); - entry = VtableStubs::create_stub(false, index, method()); + if (call_info->call_kind() == CallInfo::itable_call) { + assert(bytecode == Bytecodes::_invokeinterface, ""); + int itable_index = call_info->itable_index(); + entry = VtableStubs::find_itable_stub(itable_index); +#ifdef ASSERT assert(entry != NULL, "entry not computed"); + int index = call_info->resolved_method()->itable_index(); + assert(index == itable_index, "CallInfo pre-computes this"); +#endif //ASSERT InstanceKlass* k = call_info->resolved_method()->method_holder(); - assert(k->is_interface(), "sanity check"); + assert(k->verify_itable_index(itable_index), "sanity check"); InlineCacheBuffer::create_transition_stub(this, k, entry); } else { - // Can be different than method->vtable_index(), due to package-private etc. + assert(call_info->call_kind() == CallInfo::vtable_call, "either itable or vtable"); + // Can be different than selected_method->vtable_index(), due to package-private etc. int vtable_index = call_info->vtable_index(); - entry = VtableStubs::create_stub(true, vtable_index, method()); - InlineCacheBuffer::create_transition_stub(this, method(), entry); + assert(call_info->resolved_klass()->verify_vtable_index(vtable_index), "sanity check"); + entry = VtableStubs::find_vtable_stub(vtable_index); + InlineCacheBuffer::create_transition_stub(this, NULL, entry); } if (TraceICs) { ResourceMark rm; tty->print_cr ("IC@" INTPTR_FORMAT ": to megamorphic %s entry: " INTPTR_FORMAT, - instruction_address(), method->print_value_string(), entry); + instruction_address(), call_info->selected_method()->print_value_string(), entry); } // We can't check this anymore. With lazy deopt we could have already diff --git a/hotspot/src/share/vm/code/vtableStubs.cpp b/hotspot/src/share/vm/code/vtableStubs.cpp index 0d7b39a0241..7d9d7efaf67 100644 --- a/hotspot/src/share/vm/code/vtableStubs.cpp +++ b/hotspot/src/share/vm/code/vtableStubs.cpp @@ -111,7 +111,7 @@ void VtableStubs::initialize() { } -address VtableStubs::create_stub(bool is_vtable_stub, int vtable_index, Method* method) { +address VtableStubs::find_stub(bool is_vtable_stub, int vtable_index) { assert(vtable_index >= 0, "must be positive"); VtableStub* s = ShareVtableStubs ? lookup(is_vtable_stub, vtable_index) : NULL; diff --git a/hotspot/src/share/vm/code/vtableStubs.hpp b/hotspot/src/share/vm/code/vtableStubs.hpp index aa95fee763c..06f2a67a857 100644 --- a/hotspot/src/share/vm/code/vtableStubs.hpp +++ b/hotspot/src/share/vm/code/vtableStubs.hpp @@ -121,9 +121,11 @@ class VtableStubs : AllStatic { static VtableStub* lookup (bool is_vtable_stub, int vtable_index); static void enter (bool is_vtable_stub, int vtable_index, VtableStub* s); static inline uint hash (bool is_vtable_stub, int vtable_index); + static address find_stub (bool is_vtable_stub, int vtable_index); public: - static address create_stub(bool is_vtable_stub, int vtable_index, Method* method); // return the entry point of a stub for this call + static address find_vtable_stub(int vtable_index) { return find_stub(true, vtable_index); } + static address find_itable_stub(int itable_index) { return find_stub(false, itable_index); } static bool is_entry_point(address pc); // is pc a vtable stub entry point? static bool contains(address pc); // is pc within any stub? static VtableStub* stub_containing(address pc); // stub containing pc or NULL diff --git a/hotspot/src/share/vm/interpreter/interpreterRuntime.cpp b/hotspot/src/share/vm/interpreter/interpreterRuntime.cpp index 4a3019f867f..4c082597b22 100644 --- a/hotspot/src/share/vm/interpreter/interpreterRuntime.cpp +++ b/hotspot/src/share/vm/interpreter/interpreterRuntime.cpp @@ -496,15 +496,15 @@ IRT_END IRT_ENTRY(void, InterpreterRuntime::resolve_get_put(JavaThread* thread, Bytecodes::Code bytecode)) // resolve field - FieldAccessInfo info; + fieldDescriptor info; constantPoolHandle pool(thread, method(thread)->constants()); bool is_put = (bytecode == Bytecodes::_putfield || bytecode == Bytecodes::_putstatic); bool is_static = (bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic); { JvmtiHideSingleStepping jhss(thread); - LinkResolver::resolve_field(info, pool, get_index_u2_cpcache(thread, bytecode), - bytecode, false, CHECK); + LinkResolver::resolve_field_access(info, pool, get_index_u2_cpcache(thread, bytecode), + bytecode, CHECK); } // end JvmtiHideSingleStepping // check if link resolution caused cpCache to be updated @@ -524,7 +524,7 @@ IRT_ENTRY(void, InterpreterRuntime::resolve_get_put(JavaThread* thread, Bytecode // class is intitialized. This is required so that access to the static // field will call the initialization function every time until the class // is completely initialized ala. in 2.17.5 in JVM Specification. - InstanceKlass *klass = InstanceKlass::cast(info.klass()()); + InstanceKlass* klass = InstanceKlass::cast(info.field_holder()); bool uninitialized_static = ((bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic) && !klass->is_initialized()); Bytecodes::Code get_code = (Bytecodes::Code)0; @@ -539,9 +539,9 @@ IRT_ENTRY(void, InterpreterRuntime::resolve_get_put(JavaThread* thread, Bytecode cache_entry(thread)->set_field( get_code, put_code, - info.klass(), - info.field_index(), - info.field_offset(), + info.field_holder(), + info.index(), + info.offset(), state, info.access_flags().is_final(), info.access_flags().is_volatile(), @@ -686,29 +686,55 @@ IRT_ENTRY(void, InterpreterRuntime::resolve_invoke(JavaThread* thread, Bytecodes if (already_resolved(thread)) return; if (bytecode == Bytecodes::_invokeinterface) { - if (TraceItables && Verbose) { ResourceMark rm(thread); tty->print_cr("Resolving: klass: %s to method: %s", info.resolved_klass()->name()->as_C_string(), info.resolved_method()->name()->as_C_string()); } + } +#ifdef ASSERT + if (bytecode == Bytecodes::_invokeinterface) { if (info.resolved_method()->method_holder() == SystemDictionary::Object_klass()) { // NOTE: THIS IS A FIX FOR A CORNER CASE in the JVM spec - // (see also cpCacheOop.cpp for details) + // (see also CallInfo::set_interface for details) + assert(info.call_kind() == CallInfo::vtable_call || + info.call_kind() == CallInfo::direct_call, ""); methodHandle rm = info.resolved_method(); assert(rm->is_final() || info.has_vtable_index(), "should have been set already"); - cache_entry(thread)->set_method(bytecode, rm, info.vtable_index()); + } else if (!info.resolved_method()->has_itable_index()) { + // Resolved something like CharSequence.toString. Use vtable not itable. + assert(info.call_kind() != CallInfo::itable_call, ""); } else { // Setup itable entry - int index = klassItable::compute_itable_index(info.resolved_method()()); - cache_entry(thread)->set_interface_call(info.resolved_method(), index); + assert(info.call_kind() == CallInfo::itable_call, ""); + int index = info.resolved_method()->itable_index(); + assert(info.itable_index() == index, ""); } } else { - cache_entry(thread)->set_method( + assert(info.call_kind() == CallInfo::direct_call || + info.call_kind() == CallInfo::vtable_call, ""); + } +#endif + switch (info.call_kind()) { + case CallInfo::direct_call: + cache_entry(thread)->set_direct_call( + bytecode, + info.resolved_method()); + break; + case CallInfo::vtable_call: + cache_entry(thread)->set_vtable_call( bytecode, info.resolved_method(), info.vtable_index()); + break; + case CallInfo::itable_call: + cache_entry(thread)->set_itable_call( + bytecode, + info.resolved_method(), + info.itable_index()); + break; + default: ShouldNotReachHere(); } } IRT_END diff --git a/hotspot/src/share/vm/interpreter/linkResolver.cpp b/hotspot/src/share/vm/interpreter/linkResolver.cpp index b0bd678b597..44ac9e0862d 100644 --- a/hotspot/src/share/vm/interpreter/linkResolver.cpp +++ b/hotspot/src/share/vm/interpreter/linkResolver.cpp @@ -46,19 +46,6 @@ #include "runtime/thread.inline.hpp" #include "runtime/vmThread.hpp" -//------------------------------------------------------------------------------------------------------------------------ -// Implementation of FieldAccessInfo - -void FieldAccessInfo::set(KlassHandle klass, Symbol* name, int field_index, int field_offset, -BasicType field_type, AccessFlags access_flags) { - _klass = klass; - _name = name; - _field_index = field_index; - _field_offset = field_offset; - _field_type = field_type; - _access_flags = access_flags; -} - //------------------------------------------------------------------------------------------------------------------------ // Implementation of CallInfo @@ -66,26 +53,25 @@ BasicType field_type, AccessFlags access_flags) { void CallInfo::set_static(KlassHandle resolved_klass, methodHandle resolved_method, TRAPS) { int vtable_index = Method::nonvirtual_vtable_index; - set_common(resolved_klass, resolved_klass, resolved_method, resolved_method, vtable_index, CHECK); + set_common(resolved_klass, resolved_klass, resolved_method, resolved_method, CallInfo::direct_call, vtable_index, CHECK); } -void CallInfo::set_interface(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, TRAPS) { +void CallInfo::set_interface(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, int itable_index, TRAPS) { // This is only called for interface methods. If the resolved_method // comes from java/lang/Object, it can be the subject of a virtual call, so // we should pick the vtable index from the resolved method. - // Other than that case, there is no valid vtable index to specify. - int vtable_index = Method::invalid_vtable_index; - if (resolved_method->method_holder() == SystemDictionary::Object_klass()) { - assert(resolved_method->vtable_index() == selected_method->vtable_index(), "sanity check"); - vtable_index = resolved_method->vtable_index(); - } - set_common(resolved_klass, selected_klass, resolved_method, selected_method, vtable_index, CHECK); + // In that case, the caller must call set_virtual instead of set_interface. + assert(resolved_method->method_holder()->is_interface(), ""); + assert(itable_index == resolved_method()->itable_index(), ""); + set_common(resolved_klass, selected_klass, resolved_method, selected_method, CallInfo::itable_call, itable_index, CHECK); } void CallInfo::set_virtual(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, int vtable_index, TRAPS) { assert(vtable_index >= 0 || vtable_index == Method::nonvirtual_vtable_index, "valid index"); - set_common(resolved_klass, selected_klass, resolved_method, selected_method, vtable_index, CHECK); + assert(vtable_index < 0 || !resolved_method->has_vtable_index() || vtable_index == resolved_method->vtable_index(), ""); + CallKind kind = (vtable_index >= 0 && !resolved_method->can_be_statically_bound() ? CallInfo::vtable_call : CallInfo::direct_call); + set_common(resolved_klass, selected_klass, resolved_method, selected_method, kind, vtable_index, CHECK); assert(!resolved_method->is_compiled_lambda_form(), "these must be handled via an invokehandle call"); } @@ -98,20 +84,29 @@ void CallInfo::set_handle(methodHandle resolved_method, Handle resolved_appendix resolved_method->is_compiled_lambda_form(), "linkMethod must return one of these"); int vtable_index = Method::nonvirtual_vtable_index; - assert(resolved_method->vtable_index() == vtable_index, ""); - set_common(resolved_klass, resolved_klass, resolved_method, resolved_method, vtable_index, CHECK); + assert(!resolved_method->has_vtable_index(), ""); + set_common(resolved_klass, resolved_klass, resolved_method, resolved_method, CallInfo::direct_call, vtable_index, CHECK); _resolved_appendix = resolved_appendix; _resolved_method_type = resolved_method_type; } -void CallInfo::set_common(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, int vtable_index, TRAPS) { +void CallInfo::set_common(KlassHandle resolved_klass, + KlassHandle selected_klass, + methodHandle resolved_method, + methodHandle selected_method, + CallKind kind, + int index, + TRAPS) { assert(resolved_method->signature() == selected_method->signature(), "signatures must correspond"); _resolved_klass = resolved_klass; _selected_klass = selected_klass; _resolved_method = resolved_method; _selected_method = selected_method; - _vtable_index = vtable_index; + _call_kind = kind; + _call_index = index; _resolved_appendix = Handle(); + DEBUG_ONLY(verify()); // verify before making side effects + if (CompilationPolicy::must_be_compiled(selected_method)) { // This path is unusual, mostly used by the '-Xcomp' stress test mode. @@ -138,6 +133,65 @@ void CallInfo::set_common(KlassHandle resolved_klass, KlassHandle selected_klass } } +// utility query for unreflecting a method +CallInfo::CallInfo(Method* resolved_method, Klass* resolved_klass) { + Klass* resolved_method_holder = resolved_method->method_holder(); + if (resolved_klass == NULL) { // 2nd argument defaults to holder of 1st + resolved_klass = resolved_method_holder; + } + _resolved_klass = resolved_klass; + _selected_klass = resolved_klass; + _resolved_method = resolved_method; + _selected_method = resolved_method; + // classify: + CallKind kind = CallInfo::unknown_kind; + int index = resolved_method->vtable_index(); + if (resolved_method->can_be_statically_bound()) { + kind = CallInfo::direct_call; + } else if (!resolved_method_holder->is_interface()) { + // Could be an Object method inherited into an interface, but still a vtable call. + kind = CallInfo::vtable_call; + } else if (!resolved_klass->is_interface()) { + // A miranda method. Compute the vtable index. + ResourceMark rm; + klassVtable* vt = InstanceKlass::cast(resolved_klass)->vtable(); + index = vt->index_of_miranda(resolved_method->name(), + resolved_method->signature()); + kind = CallInfo::vtable_call; + } else { + // A regular interface call. + kind = CallInfo::itable_call; + index = resolved_method->itable_index(); + } + assert(index == Method::nonvirtual_vtable_index || index >= 0, err_msg("bad index %d", index)); + _call_kind = kind; + _call_index = index; + _resolved_appendix = Handle(); + DEBUG_ONLY(verify()); +} + +#ifdef ASSERT +void CallInfo::verify() { + switch (call_kind()) { // the meaning and allowed value of index depends on kind + case CallInfo::direct_call: + if (_call_index == Method::nonvirtual_vtable_index) break; + // else fall through to check vtable index: + case CallInfo::vtable_call: + assert(resolved_klass()->verify_vtable_index(_call_index), ""); + break; + case CallInfo::itable_call: + assert(resolved_method()->method_holder()->verify_itable_index(_call_index), ""); + break; + case CallInfo::unknown_kind: + assert(call_kind() != CallInfo::unknown_kind, "CallInfo must be set"); + break; + default: + fatal(err_msg_res("Unexpected call kind %d", call_kind())); + } +} +#endif //ASSERT + + //------------------------------------------------------------------------------------------------------------------------ // Klass resolution @@ -163,13 +217,6 @@ void LinkResolver::resolve_klass(KlassHandle& result, constantPoolHandle pool, i result = KlassHandle(THREAD, result_oop); } -void LinkResolver::resolve_klass_no_update(KlassHandle& result, constantPoolHandle pool, int index, TRAPS) { - Klass* result_oop = - ConstantPool::klass_ref_at_if_loaded_check(pool, index, CHECK); - result = KlassHandle(THREAD, result_oop); -} - - //------------------------------------------------------------------------------------------------------------------------ // Method resolution // @@ -360,7 +407,12 @@ void LinkResolver::check_method_accessability(KlassHandle ref_klass, void LinkResolver::resolve_method_statically(methodHandle& resolved_method, KlassHandle& resolved_klass, Bytecodes::Code code, constantPoolHandle pool, int index, TRAPS) { - + // This method is used only + // (1) in C2 from InlineTree::ok_to_inline (via ciMethod::check_call), + // and + // (2) in Bytecode_invoke::static_target + // It appears to fail when applied to an invokeinterface call site. + // FIXME: Remove this method and ciMethod::check_call; refactor to use the other LinkResolver entry points. // resolve klass if (code == Bytecodes::_invokedynamic) { resolved_klass = SystemDictionary::MethodHandle_klass(); @@ -580,45 +632,49 @@ void LinkResolver::check_field_accessability(KlassHandle ref_klass, } } -void LinkResolver::resolve_field(FieldAccessInfo& result, constantPoolHandle pool, int index, Bytecodes::Code byte, bool check_only, TRAPS) { - resolve_field(result, pool, index, byte, check_only, true, CHECK); +void LinkResolver::resolve_field_access(fieldDescriptor& result, constantPoolHandle pool, int index, Bytecodes::Code byte, TRAPS) { + // Load these early in case the resolve of the containing klass fails + Symbol* field = pool->name_ref_at(index); + Symbol* sig = pool->signature_ref_at(index); + + // resolve specified klass + KlassHandle resolved_klass; + resolve_klass(resolved_klass, pool, index, CHECK); + + KlassHandle current_klass(THREAD, pool->pool_holder()); + resolve_field(result, resolved_klass, field, sig, current_klass, byte, true, true, CHECK); } -void LinkResolver::resolve_field(FieldAccessInfo& result, constantPoolHandle pool, int index, Bytecodes::Code byte, bool check_only, bool update_pool, TRAPS) { +void LinkResolver::resolve_field(fieldDescriptor& fd, KlassHandle resolved_klass, Symbol* field, Symbol* sig, + KlassHandle current_klass, Bytecodes::Code byte, bool check_access, bool initialize_class, + TRAPS) { assert(byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic || - byte == Bytecodes::_getfield || byte == Bytecodes::_putfield, "bad bytecode"); + byte == Bytecodes::_getfield || byte == Bytecodes::_putfield || + (byte == Bytecodes::_nop && !check_access), "bad field access bytecode"); bool is_static = (byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic); bool is_put = (byte == Bytecodes::_putfield || byte == Bytecodes::_putstatic); - // resolve specified klass - KlassHandle resolved_klass; - if (update_pool) { - resolve_klass(resolved_klass, pool, index, CHECK); - } else { - resolve_klass_no_update(resolved_klass, pool, index, CHECK); - } - // Load these early in case the resolve of the containing klass fails - Symbol* field = pool->name_ref_at(index); - Symbol* sig = pool->signature_ref_at(index); // Check if there's a resolved klass containing the field - if( resolved_klass.is_null() ) { + if (resolved_klass.is_null()) { ResourceMark rm(THREAD); THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string()); } // Resolve instance field - fieldDescriptor fd; // find_field initializes fd if found KlassHandle sel_klass(THREAD, InstanceKlass::cast(resolved_klass())->find_field(field, sig, &fd)); // check if field exists; i.e., if a klass containing the field def has been selected - if (sel_klass.is_null()){ + if (sel_klass.is_null()) { ResourceMark rm(THREAD); THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string()); } + if (!check_access) + // Access checking may be turned off when calling from within the VM. + return; + // check access - KlassHandle ref_klass(THREAD, pool->pool_holder()); - check_field_accessability(ref_klass, resolved_klass, sel_klass, fd, CHECK); + check_field_accessability(current_klass, resolved_klass, sel_klass, fd, CHECK); // check for errors if (is_static != fd.is_static()) { @@ -629,7 +685,7 @@ void LinkResolver::resolve_field(FieldAccessInfo& result, constantPoolHandle poo } // Final fields can only be accessed from its own class. - if (is_put && fd.access_flags().is_final() && sel_klass() != pool->pool_holder()) { + if (is_put && fd.access_flags().is_final() && sel_klass() != current_klass()) { THROW(vmSymbols::java_lang_IllegalAccessError()); } @@ -639,19 +695,18 @@ void LinkResolver::resolve_field(FieldAccessInfo& result, constantPoolHandle poo // // note 2: we don't want to force initialization if we are just checking // if the field access is legal; e.g., during compilation - if (is_static && !check_only) { + if (is_static && initialize_class) { sel_klass->initialize(CHECK); } - { + if (sel_klass() != current_klass()) { HandleMark hm(THREAD); - Handle ref_loader (THREAD, InstanceKlass::cast(ref_klass())->class_loader()); + Handle ref_loader (THREAD, InstanceKlass::cast(current_klass())->class_loader()); Handle sel_loader (THREAD, InstanceKlass::cast(sel_klass())->class_loader()); - Symbol* signature_ref = pool->signature_ref_at(index); { ResourceMark rm(THREAD); Symbol* failed_type_symbol = - SystemDictionary::check_signature_loaders(signature_ref, + SystemDictionary::check_signature_loaders(sig, ref_loader, sel_loader, false, CHECK); @@ -677,9 +732,6 @@ void LinkResolver::resolve_field(FieldAccessInfo& result, constantPoolHandle poo // return information. note that the klass is set to the actual klass containing the // field, otherwise access of static fields in superclasses will not work. - KlassHandle holder (THREAD, fd.field_holder()); - Symbol* name = fd.name(); - result.set(holder, name, fd.index(), fd.offset(), fd.field_type(), fd.access_flags()); } @@ -906,10 +958,6 @@ void LinkResolver::runtime_resolve_virtual_method(CallInfo& result, THROW(vmSymbols::java_lang_NullPointerException()); } - // Virtual methods cannot be resolved before its klass has been linked, for otherwise the Method*'s - // has not been rewritten, and the vtable initialized. - assert(resolved_method->method_holder()->is_linked(), "must be linked"); - // Virtual methods cannot be resolved before its klass has been linked, for otherwise the Method*'s // has not been rewritten, and the vtable initialized. Make sure to do this after the nullcheck, since // a missing receiver might result in a bogus lookup. @@ -920,6 +968,7 @@ void LinkResolver::runtime_resolve_virtual_method(CallInfo& result, vtable_index = vtable_index_of_miranda_method(resolved_klass, resolved_method->name(), resolved_method->signature(), CHECK); + assert(vtable_index >= 0 , "we should have valid vtable index at this point"); InstanceKlass* inst = InstanceKlass::cast(recv_klass()); @@ -927,6 +976,7 @@ void LinkResolver::runtime_resolve_virtual_method(CallInfo& result, } else { // at this point we are sure that resolved_method is virtual and not // a miranda method; therefore, it must have a valid vtable index. + assert(!resolved_method->has_itable_index(), ""); vtable_index = resolved_method->vtable_index(); // We could get a negative vtable_index for final methods, // because as an optimization they are they are never put in the vtable, @@ -1006,6 +1056,12 @@ void LinkResolver::runtime_resolve_interface_method(CallInfo& result, methodHand lookup_instance_method_in_klasses(sel_method, recv_klass, resolved_method->name(), resolved_method->signature(), CHECK); + if (sel_method.is_null() && !check_null_and_abstract) { + // In theory this is a harmless placeholder value, but + // in practice leaving in null affects the nsk default method tests. + // This needs further study. + sel_method = resolved_method; + } // check if method exists if (sel_method.is_null()) { ResourceMark rm(THREAD); @@ -1046,7 +1102,14 @@ void LinkResolver::runtime_resolve_interface_method(CallInfo& result, methodHand sel_method->signature())); } // setup result - result.set_interface(resolved_klass, recv_klass, resolved_method, sel_method, CHECK); + if (!resolved_method->has_itable_index()) { + int vtable_index = resolved_method->vtable_index(); + assert(vtable_index == sel_method->vtable_index(), "sanity check"); + result.set_virtual(resolved_klass, recv_klass, resolved_method, sel_method, vtable_index, CHECK); + return; + } + int itable_index = resolved_method()->itable_index(); + result.set_interface(resolved_klass, recv_klass, resolved_method, sel_method, itable_index, CHECK); } @@ -1293,7 +1356,8 @@ void LinkResolver::resolve_invokedynamic(CallInfo& result, constantPoolHandle po } if (TraceMethodHandles) { - tty->print_cr("resolve_invokedynamic #%d %s %s", + ResourceMark rm(THREAD); + tty->print_cr("resolve_invokedynamic #%d %s %s", ConstantPool::decode_invokedynamic_index(index), method_name->as_C_string(), method_signature->as_C_string()); tty->print(" BSM info: "); bootstrap_specifier->print(); @@ -1342,9 +1406,16 @@ void LinkResolver::resolve_dynamic_call(CallInfo& result, //------------------------------------------------------------------------------------------------------------------------ #ifndef PRODUCT -void FieldAccessInfo::print() { +void CallInfo::print() { ResourceMark rm; - tty->print_cr("Field %s@%d", name()->as_C_string(), field_offset()); + const char* kindstr = "unknown"; + switch (_call_kind) { + case direct_call: kindstr = "direct"; break; + case vtable_call: kindstr = "vtable"; break; + case itable_call: kindstr = "itable"; break; + } + tty->print_cr("Call %s@%d %s", kindstr, _call_index, + _resolved_method.is_null() ? "(none)" : _resolved_method->name_and_sig_as_C_string()); } #endif diff --git a/hotspot/src/share/vm/interpreter/linkResolver.hpp b/hotspot/src/share/vm/interpreter/linkResolver.hpp index 4054eeb35ef..0fb551a23a8 100644 --- a/hotspot/src/share/vm/interpreter/linkResolver.hpp +++ b/hotspot/src/share/vm/interpreter/linkResolver.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2013, 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 @@ -30,63 +30,54 @@ // All the necessary definitions for run-time link resolution. -// LinkInfo & its subclasses provide all the information gathered -// for a particular link after resolving it. A link is any reference +// CallInfo provides all the information gathered for a particular +// linked call site after resolving it. A link is any reference // made from within the bytecodes of a method to an object outside of // that method. If the info is invalid, the link has not been resolved // successfully. -class LinkInfo VALUE_OBJ_CLASS_SPEC { -}; - - -// Link information for getfield/putfield & getstatic/putstatic bytecodes. - -class FieldAccessInfo: public LinkInfo { - protected: - KlassHandle _klass; - Symbol* _name; - AccessFlags _access_flags; - int _field_index; // original index in the klass - int _field_offset; - BasicType _field_type; - +class CallInfo VALUE_OBJ_CLASS_SPEC { public: - void set(KlassHandle klass, Symbol* name, int field_index, int field_offset, - BasicType field_type, AccessFlags access_flags); - KlassHandle klass() const { return _klass; } - Symbol* name() const { return _name; } - int field_index() const { return _field_index; } - int field_offset() const { return _field_offset; } - BasicType field_type() const { return _field_type; } - AccessFlags access_flags() const { return _access_flags; } - - // debugging - void print() PRODUCT_RETURN; -}; - - -// Link information for all calls. - -class CallInfo: public LinkInfo { + // Ways that a method call might be selected (or not) based on receiver type. + // Note that an invokevirtual instruction might be linked with no_dispatch, + // and an invokeinterface instruction might be linked with any of the three options + enum CallKind { + direct_call, // jump into resolved_method (must be concrete) + vtable_call, // select recv.klass.method_at_vtable(index) + itable_call, // select recv.klass.method_at_itable(resolved_method.holder, index) + unknown_kind = -1 + }; private: - KlassHandle _resolved_klass; // static receiver klass + KlassHandle _resolved_klass; // static receiver klass, resolved from a symbolic reference KlassHandle _selected_klass; // dynamic receiver class (same as static, or subklass) methodHandle _resolved_method; // static target method methodHandle _selected_method; // dynamic (actual) target method - int _vtable_index; // vtable index of selected method + CallKind _call_kind; // kind of call (static(=bytecode static/special + + // others inferred), vtable, itable) + int _call_index; // vtable or itable index of selected class method (if any) Handle _resolved_appendix; // extra argument in constant pool (if CPCE::has_appendix) Handle _resolved_method_type; // MethodType (for invokedynamic and invokehandle call sites) void set_static( KlassHandle resolved_klass, methodHandle resolved_method , TRAPS); - void set_interface(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method , TRAPS); + void set_interface(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, int itable_index , TRAPS); void set_virtual( KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, int vtable_index , TRAPS); void set_handle( methodHandle resolved_method, Handle resolved_appendix, Handle resolved_method_type, TRAPS); - void set_common( KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, int vtable_index , TRAPS); + void set_common( KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, CallKind kind, int index, TRAPS); friend class LinkResolver; public: + CallInfo() { +#ifndef PRODUCT + _call_kind = CallInfo::unknown_kind; + _call_index = Method::garbage_vtable_index; +#endif //PRODUCT + } + + // utility to extract an effective CallInfo from a method and an optional receiver limit + // does not queue the method for compilation + CallInfo(Method* resolved_method, Klass* resolved_klass = NULL); + KlassHandle resolved_klass() const { return _resolved_klass; } KlassHandle selected_klass() const { return _selected_klass; } methodHandle resolved_method() const { return _resolved_method; } @@ -95,21 +86,43 @@ class CallInfo: public LinkInfo { Handle resolved_method_type() const { return _resolved_method_type; } BasicType result_type() const { return selected_method()->result_type(); } - bool has_vtable_index() const { return _vtable_index >= 0; } - bool is_statically_bound() const { return _vtable_index == Method::nonvirtual_vtable_index; } + CallKind call_kind() const { return _call_kind; } + int call_index() const { return _call_index; } int vtable_index() const { // Even for interface calls the vtable index could be non-negative. // See CallInfo::set_interface. assert(has_vtable_index() || is_statically_bound(), ""); - return _vtable_index; + assert(call_kind() == vtable_call || call_kind() == direct_call, ""); + // The returned value is < 0 if the call is statically bound. + // But, the returned value may be >= 0 even if the kind is direct_call. + // It is up to the caller to decide which way to go. + return _call_index; } + int itable_index() const { + assert(call_kind() == itable_call, ""); + // The returned value is always >= 0, a valid itable index. + return _call_index; + } + + // debugging +#ifdef ASSERT + bool has_vtable_index() const { return _call_index >= 0 && _call_kind != CallInfo::itable_call; } + bool is_statically_bound() const { return _call_index == Method::nonvirtual_vtable_index; } +#endif //ASSERT + void verify() PRODUCT_RETURN; + void print() PRODUCT_RETURN; }; +// Link information for getfield/putfield & getstatic/putstatic bytecodes +// is represented using a fieldDescriptor. // The LinkResolver is used to resolve constant-pool references at run-time. // It does all necessary link-time checks & throws exceptions if necessary. class LinkResolver: AllStatic { + friend class klassVtable; + friend class klassItable; + private: static void lookup_method_in_klasses (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS); static void lookup_instance_method_in_klasses (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS); @@ -120,7 +133,6 @@ class LinkResolver: AllStatic { static int vtable_index_of_miranda_method(KlassHandle klass, Symbol* name, Symbol* signature, TRAPS); static void resolve_klass (KlassHandle& result, constantPoolHandle pool, int index, TRAPS); - static void resolve_klass_no_update (KlassHandle& result, constantPoolHandle pool, int index, TRAPS); // no update of constantPool entry static void resolve_pool (KlassHandle& resolved_klass, Symbol*& method_name, Symbol*& method_signature, KlassHandle& current_klass, constantPoolHandle pool, int index, TRAPS); @@ -148,9 +160,16 @@ class LinkResolver: AllStatic { Bytecodes::Code code, constantPoolHandle pool, int index, TRAPS); // runtime/static resolving for fields - static void resolve_field(FieldAccessInfo& result, constantPoolHandle pool, int index, Bytecodes::Code byte, bool check_only, TRAPS); - // takes an extra bool argument "update_pool" to decide whether to update the constantPool during klass resolution. - static void resolve_field(FieldAccessInfo& result, constantPoolHandle pool, int index, Bytecodes::Code byte, bool check_only, bool update_pool, TRAPS); + static void resolve_field_access(fieldDescriptor& result, constantPoolHandle pool, int index, Bytecodes::Code byte, TRAPS); + static void resolve_field(fieldDescriptor& result, KlassHandle resolved_klass, Symbol* field_name, Symbol* field_signature, + KlassHandle current_klass, Bytecodes::Code access_kind, bool check_access, bool initialize_class, TRAPS); + + // source of access_kind codes: + static Bytecodes::Code field_access_kind(bool is_static, bool is_put) { + return (is_static + ? (is_put ? Bytecodes::_putstatic : Bytecodes::_getstatic) + : (is_put ? Bytecodes::_putfield : Bytecodes::_getfield )); + } // runtime resolving: // resolved_klass = specified class (i.e., static receiver class) diff --git a/hotspot/src/share/vm/oops/constantPool.cpp b/hotspot/src/share/vm/oops/constantPool.cpp index 8033d7e3850..673da4dd622 100644 --- a/hotspot/src/share/vm/oops/constantPool.cpp +++ b/hotspot/src/share/vm/oops/constantPool.cpp @@ -396,32 +396,6 @@ Klass* ConstantPool::klass_ref_at_if_loaded(constantPoolHandle this_oop, int whi } -// This is an interface for the compiler that allows accessing non-resolved entries -// in the constant pool - but still performs the validations tests. Must be used -// in a pre-parse of the compiler - to determine what it can do and not do. -// Note: We cannot update the ConstantPool from the vm_thread. -Klass* ConstantPool::klass_ref_at_if_loaded_check(constantPoolHandle this_oop, int index, TRAPS) { - int which = this_oop->klass_ref_index_at(index); - CPSlot entry = this_oop->slot_at(which); - if (entry.is_resolved()) { - assert(entry.get_klass()->is_klass(), "must be"); - return entry.get_klass(); - } else { - assert(entry.is_unresolved(), "must be either symbol or klass"); - Symbol* name = entry.get_symbol(); - oop loader = this_oop->pool_holder()->class_loader(); - oop protection_domain = this_oop->pool_holder()->protection_domain(); - Handle h_loader(THREAD, loader); - Handle h_prot (THREAD, protection_domain); - KlassHandle k(THREAD, SystemDictionary::find(name, h_loader, h_prot, THREAD)); - - // Do access check for klasses - if( k.not_null() ) verify_constant_pool_resolve(this_oop, k, CHECK_NULL); - return k(); - } -} - - Method* ConstantPool::method_at_if_loaded(constantPoolHandle cpool, int which) { if (cpool->cache() == NULL) return NULL; // nothing to load yet diff --git a/hotspot/src/share/vm/oops/constantPool.hpp b/hotspot/src/share/vm/oops/constantPool.hpp index eca2dcd9c56..b7d607d763a 100644 --- a/hotspot/src/share/vm/oops/constantPool.hpp +++ b/hotspot/src/share/vm/oops/constantPool.hpp @@ -730,8 +730,6 @@ class ConstantPool : public Metadata { static oop method_type_at_if_loaded (constantPoolHandle this_oop, int which); static Klass* klass_at_if_loaded (constantPoolHandle this_oop, int which); static Klass* klass_ref_at_if_loaded (constantPoolHandle this_oop, int which); - // Same as above - but does LinkResolving. - static Klass* klass_ref_at_if_loaded_check(constantPoolHandle this_oop, int which, TRAPS); // Routines currently used for annotations (only called by jvm.cpp) but which might be used in the // future by other Java code. These take constant pool indices rather than diff --git a/hotspot/src/share/vm/oops/cpCache.cpp b/hotspot/src/share/vm/oops/cpCache.cpp index 9e2b83c2caf..9d358955025 100644 --- a/hotspot/src/share/vm/oops/cpCache.cpp +++ b/hotspot/src/share/vm/oops/cpCache.cpp @@ -140,9 +140,10 @@ void ConstantPoolCacheEntry::set_parameter_size(int value) { err_msg("size must not change: parameter_size=%d, value=%d", parameter_size(), value)); } -void ConstantPoolCacheEntry::set_method(Bytecodes::Code invoke_code, - methodHandle method, - int vtable_index) { +void ConstantPoolCacheEntry::set_direct_or_vtable_call(Bytecodes::Code invoke_code, + methodHandle method, + int vtable_index) { + bool is_vtable_call = (vtable_index >= 0); // FIXME: split this method on this boolean assert(method->interpreter_entry() != NULL, "should have been set at this point"); assert(!method->is_obsolete(), "attempt to write obsolete method to cpCache"); @@ -160,7 +161,8 @@ void ConstantPoolCacheEntry::set_method(Bytecodes::Code invoke_code, // ...and fall through as if we were handling invokevirtual: case Bytecodes::_invokevirtual: { - if (method->can_be_statically_bound()) { + if (!is_vtable_call) { + assert(method->can_be_statically_bound(), ""); // set_f2_as_vfinal_method checks if is_vfinal flag is true. set_method_flags(as_TosState(method->result_type()), ( 1 << is_vfinal_shift) | @@ -169,6 +171,7 @@ void ConstantPoolCacheEntry::set_method(Bytecodes::Code invoke_code, method()->size_of_parameters()); set_f2_as_vfinal_method(method()); } else { + assert(!method->can_be_statically_bound(), ""); assert(vtable_index >= 0, "valid index"); assert(!method->is_final_method(), "sanity"); set_method_flags(as_TosState(method->result_type()), @@ -182,6 +185,7 @@ void ConstantPoolCacheEntry::set_method(Bytecodes::Code invoke_code, case Bytecodes::_invokespecial: case Bytecodes::_invokestatic: + assert(!is_vtable_call, ""); // Note: Read and preserve the value of the is_vfinal flag on any // invokevirtual bytecode shared with this constant pool cache entry. // It is cheap and safe to consult is_vfinal() at all times. @@ -232,8 +236,22 @@ void ConstantPoolCacheEntry::set_method(Bytecodes::Code invoke_code, NOT_PRODUCT(verify(tty)); } +void ConstantPoolCacheEntry::set_direct_call(Bytecodes::Code invoke_code, methodHandle method) { + int index = Method::nonvirtual_vtable_index; + // index < 0; FIXME: inline and customize set_direct_or_vtable_call + set_direct_or_vtable_call(invoke_code, method, index); +} -void ConstantPoolCacheEntry::set_interface_call(methodHandle method, int index) { +void ConstantPoolCacheEntry::set_vtable_call(Bytecodes::Code invoke_code, methodHandle method, int index) { + // either the method is a miranda or its holder should accept the given index + assert(method->method_holder()->is_interface() || method->method_holder()->verify_vtable_index(index), ""); + // index >= 0; FIXME: inline and customize set_direct_or_vtable_call + set_direct_or_vtable_call(invoke_code, method, index); +} + +void ConstantPoolCacheEntry::set_itable_call(Bytecodes::Code invoke_code, methodHandle method, int index) { + assert(method->method_holder()->verify_itable_index(index), ""); + assert(invoke_code == Bytecodes::_invokeinterface, ""); InstanceKlass* interf = method->method_holder(); assert(interf->is_interface(), "must be an interface"); assert(!method->is_final_method(), "interfaces do not have final methods; cannot link to one here"); diff --git a/hotspot/src/share/vm/oops/cpCache.hpp b/hotspot/src/share/vm/oops/cpCache.hpp index c15b4a54bd6..77c0deb9d8f 100644 --- a/hotspot/src/share/vm/oops/cpCache.hpp +++ b/hotspot/src/share/vm/oops/cpCache.hpp @@ -219,15 +219,29 @@ class ConstantPoolCacheEntry VALUE_OBJ_CLASS_SPEC { Klass* root_klass // needed by the GC to dirty the klass ); - void set_method( // sets entry to resolved method entry + private: + void set_direct_or_vtable_call( Bytecodes::Code invoke_code, // the bytecode used for invoking the method methodHandle method, // the method/prototype if any (NULL, otherwise) int vtable_index // the vtable index if any, else negative ); - void set_interface_call( - methodHandle method, // Resolved method - int index // Method index into interface + public: + void set_direct_call( // sets entry to exact concrete method entry + Bytecodes::Code invoke_code, // the bytecode used for invoking the method + methodHandle method // the method to call + ); + + void set_vtable_call( // sets entry to vtable index + Bytecodes::Code invoke_code, // the bytecode used for invoking the method + methodHandle method, // resolved method which declares the vtable index + int vtable_index // the vtable index + ); + + void set_itable_call( + Bytecodes::Code invoke_code, // the bytecode used; must be invokeinterface + methodHandle method, // the resolved interface method + int itable_index // index into itable for the method ); void set_method_handle( diff --git a/hotspot/src/share/vm/oops/fieldStreams.hpp b/hotspot/src/share/vm/oops/fieldStreams.hpp index acc590c970c..17f1b0a8585 100644 --- a/hotspot/src/share/vm/oops/fieldStreams.hpp +++ b/hotspot/src/share/vm/oops/fieldStreams.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2013, 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,6 +27,7 @@ #include "oops/instanceKlass.hpp" #include "oops/fieldInfo.hpp" +#include "runtime/fieldDescriptor.hpp" // The is the base class for iteration over the fields array // describing the declared fields in the class. Several subclasses @@ -43,8 +44,10 @@ class FieldStreamBase : public StackObj { int _index; int _limit; int _generic_signature_slot; + fieldDescriptor _fd_buf; FieldInfo* field() const { return FieldInfo::from_field_array(_fields, _index); } + InstanceKlass* field_holder() const { return _constants->pool_holder(); } int init_generic_signature_start_slot() { int length = _fields->length(); @@ -102,6 +105,7 @@ class FieldStreamBase : public StackObj { _index = 0; _limit = klass->java_fields_count(); init_generic_signature_start_slot(); + assert(klass == field_holder(), ""); } FieldStreamBase(instanceKlassHandle klass) { _fields = klass->fields(); @@ -109,6 +113,7 @@ class FieldStreamBase : public StackObj { _index = 0; _limit = klass->java_fields_count(); init_generic_signature_start_slot(); + assert(klass == field_holder(), ""); } // accessors @@ -180,6 +185,12 @@ class FieldStreamBase : public StackObj { return field()->contended_group(); } + // bridge to a heavier API: + fieldDescriptor& field_descriptor() const { + fieldDescriptor& field = const_cast(_fd_buf); + field.reinitialize(field_holder(), _index); + return field; + } }; // Iterate over only the internal fields diff --git a/hotspot/src/share/vm/oops/instanceKlass.cpp b/hotspot/src/share/vm/oops/instanceKlass.cpp index 29c77a07ccb..cf77300dcf0 100644 --- a/hotspot/src/share/vm/oops/instanceKlass.cpp +++ b/hotspot/src/share/vm/oops/instanceKlass.cpp @@ -286,7 +286,6 @@ InstanceKlass::InstanceKlass(int vtable_len, init_previous_versions(); set_generic_signature_index(0); release_set_methods_jmethod_ids(NULL); - release_set_methods_cached_itable_indices(NULL); set_annotations(NULL); set_jvmti_cached_class_field_map(NULL); set_initial_method_idnum(0); @@ -1149,7 +1148,7 @@ bool InstanceKlass::find_local_field(Symbol* name, Symbol* sig, fieldDescriptor* Symbol* f_name = fs.name(); Symbol* f_sig = fs.signature(); if (f_name == name && f_sig == sig) { - fd->initialize(const_cast(this), fs.index()); + fd->reinitialize(const_cast(this), fs.index()); return true; } } @@ -1218,7 +1217,7 @@ Klass* InstanceKlass::find_field(Symbol* name, Symbol* sig, bool is_static, fiel bool InstanceKlass::find_local_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const { for (JavaFieldStream fs(this); !fs.done(); fs.next()) { if (fs.offset() == offset) { - fd->initialize(const_cast(this), fs.index()); + fd->reinitialize(const_cast(this), fs.index()); if (fd->is_static() == is_static) return true; } } @@ -1251,8 +1250,7 @@ void InstanceKlass::methods_do(void f(Method* method)) { void InstanceKlass::do_local_static_fields(FieldClosure* cl) { for (JavaFieldStream fs(this); !fs.done(); fs.next()) { if (fs.access_flags().is_static()) { - fieldDescriptor fd; - fd.initialize(this, fs.index()); + fieldDescriptor& fd = fs.field_descriptor(); cl->do_field(&fd); } } @@ -1268,8 +1266,7 @@ void InstanceKlass::do_local_static_fields(void f(fieldDescriptor*, TRAPS), TRAP void InstanceKlass::do_local_static_fields_impl(instanceKlassHandle this_oop, void f(fieldDescriptor* fd, TRAPS), TRAPS) { for (JavaFieldStream fs(this_oop()); !fs.done(); fs.next()) { if (fs.access_flags().is_static()) { - fieldDescriptor fd; - fd.initialize(this_oop(), fs.index()); + fieldDescriptor& fd = fs.field_descriptor(); f(&fd, CHECK); } } @@ -1291,7 +1288,7 @@ void InstanceKlass::do_nonstatic_fields(FieldClosure* cl) { int* fields_sorted = NEW_C_HEAP_ARRAY(int, 2*(length+1), mtClass); int j = 0; for (int i = 0; i < length; i += 1) { - fd.initialize(this, i); + fd.reinitialize(this, i); if (!fd.is_static()) { fields_sorted[j + 0] = fd.offset(); fields_sorted[j + 1] = i; @@ -1303,7 +1300,7 @@ void InstanceKlass::do_nonstatic_fields(FieldClosure* cl) { // _sort_Fn is defined in growableArray.hpp. qsort(fields_sorted, length/2, 2*sizeof(int), (_sort_Fn)compare_fields_by_offset); for (int i = 0; i < length; i += 2) { - fd.initialize(this, fields_sorted[i + 1]); + fd.reinitialize(this, fields_sorted[i + 1]); assert(!fd.is_static() && fd.offset() == fields_sorted[i], "only nonstatic fields"); cl->do_field(&fd); } @@ -1686,87 +1683,6 @@ jmethodID InstanceKlass::jmethod_id_or_null(Method* method) { } -// Cache an itable index -void InstanceKlass::set_cached_itable_index(size_t idnum, int index) { - int* indices = methods_cached_itable_indices_acquire(); - int* to_dealloc_indices = NULL; - - // We use a double-check locking idiom here because this cache is - // performance sensitive. In the normal system, this cache only - // transitions from NULL to non-NULL which is safe because we use - // release_set_methods_cached_itable_indices() to advertise the - // new cache. A partially constructed cache should never be seen - // by a racing thread. Cache reads and writes proceed without a - // lock, but creation of the cache itself requires no leaks so a - // lock is generally acquired in that case. - // - // If the RedefineClasses() API has been used, then this cache can - // grow and we'll have transitions from non-NULL to bigger non-NULL. - // Cache creation requires no leaks and we require safety between all - // cache accesses and freeing of the old cache so a lock is generally - // acquired when the RedefineClasses() API has been used. - - if (indices == NULL || idnum_can_increment()) { - // we need a cache or the cache can grow - MutexLocker ml(JNICachedItableIndex_lock); - // reacquire the cache to see if another thread already did the work - indices = methods_cached_itable_indices_acquire(); - size_t length = 0; - // cache size is stored in element[0], other elements offset by one - if (indices == NULL || (length = (size_t)indices[0]) <= idnum) { - size_t size = MAX2(idnum+1, (size_t)idnum_allocated_count()); - int* new_indices = NEW_C_HEAP_ARRAY(int, size+1, mtClass); - new_indices[0] = (int)size; - // copy any existing entries - size_t i; - for (i = 0; i < length; i++) { - new_indices[i+1] = indices[i+1]; - } - // Set all the rest to -1 - for (i = length; i < size; i++) { - new_indices[i+1] = -1; - } - if (indices != NULL) { - // We have an old cache to delete so save it for after we - // drop the lock. - to_dealloc_indices = indices; - } - release_set_methods_cached_itable_indices(indices = new_indices); - } - - if (idnum_can_increment()) { - // this cache can grow so we have to write to it safely - indices[idnum+1] = index; - } - } else { - CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops()); - } - - if (!idnum_can_increment()) { - // The cache cannot grow and this JNI itable index value does not - // have to be unique like a jmethodID. If there is a race to set it, - // it doesn't matter. - indices[idnum+1] = index; - } - - if (to_dealloc_indices != NULL) { - // we allocated a new cache so free the old one - FreeHeap(to_dealloc_indices); - } -} - - -// Retrieve a cached itable index -int InstanceKlass::cached_itable_index(size_t idnum) { - int* indices = methods_cached_itable_indices_acquire(); - if (indices != NULL && ((size_t)indices[0]) > idnum) { - // indices exist and are long enough, retrieve possible cached - return indices[idnum+1]; - } - return -1; -} - - // // Walk the list of dependent nmethods searching for nmethods which // are dependent on the changes that were passed in and mark them for @@ -2326,12 +2242,6 @@ void InstanceKlass::release_C_heap_structures() { } } - int* indices = methods_cached_itable_indices_acquire(); - if (indices != (int*)NULL) { - release_set_methods_cached_itable_indices(NULL); - FreeHeap(indices); - } - // release dependencies nmethodBucket* b = _dependencies; _dependencies = NULL; @@ -2782,6 +2692,18 @@ static const char* state_names[] = { "allocated", "loaded", "linked", "being_initialized", "fully_initialized", "initialization_error" }; +static void print_vtable(intptr_t* start, int len, outputStream* st) { + for (int i = 0; i < len; i++) { + intptr_t e = start[i]; + st->print("%d : " INTPTR_FORMAT, i, e); + if (e != 0 && ((Metadata*)e)->is_metaspace_object()) { + st->print(" "); + ((Metadata*)e)->print_value_on(st); + } + st->cr(); + } +} + void InstanceKlass::print_on(outputStream* st) const { assert(is_klass(), "must be klass"); Klass::print_on(st); @@ -2816,7 +2738,7 @@ void InstanceKlass::print_on(outputStream* st) const { st->print(BULLET"arrays: "); array_klasses()->print_value_on_maybe_null(st); st->cr(); st->print(BULLET"methods: "); methods()->print_value_on(st); st->cr(); - if (Verbose) { + if (Verbose || WizardMode) { Array* method_array = methods(); for(int i = 0; i < method_array->length(); i++) { st->print("%d : ", i); method_array->at(i)->print_value(); st->cr(); @@ -2874,7 +2796,9 @@ void InstanceKlass::print_on(outputStream* st) const { st->print(BULLET"inner classes: "); inner_classes()->print_value_on(st); st->cr(); st->print(BULLET"java mirror: "); java_mirror()->print_value_on(st); st->cr(); st->print(BULLET"vtable length %d (start addr: " INTPTR_FORMAT ")", vtable_length(), start_of_vtable()); st->cr(); + if (vtable_length() > 0 && (Verbose || WizardMode)) print_vtable(start_of_vtable(), vtable_length(), st); st->print(BULLET"itable length %d (start addr: " INTPTR_FORMAT ")", itable_length(), start_of_itable()); st->cr(); + if (itable_length() > 0 && (Verbose || WizardMode)) print_vtable(start_of_itable(), itable_length(), st); st->print_cr(BULLET"---- static fields (%d words):", static_field_size()); FieldPrinter print_static_field(st); ((InstanceKlass*)this)->do_local_static_fields(&print_static_field); @@ -2896,6 +2820,7 @@ void InstanceKlass::print_on(outputStream* st) const { void InstanceKlass::print_value_on(outputStream* st) const { assert(is_klass(), "must be klass"); + if (Verbose || WizardMode) access_flags().print_on(st); name()->print_value_on(st); } diff --git a/hotspot/src/share/vm/oops/instanceKlass.hpp b/hotspot/src/share/vm/oops/instanceKlass.hpp index 123f6b17911..3bd4e9de40c 100644 --- a/hotspot/src/share/vm/oops/instanceKlass.hpp +++ b/hotspot/src/share/vm/oops/instanceKlass.hpp @@ -245,7 +245,6 @@ class InstanceKlass: public Klass { MemberNameTable* _member_names; // Member names JNIid* _jni_ids; // First JNI identifier for static fields in this class jmethodID* _methods_jmethod_ids; // jmethodIDs corresponding to method_idnum, or NULL if none - int* _methods_cached_itable_indices; // itable_index cache for JNI invoke corresponding to methods idnum, or NULL nmethodBucket* _dependencies; // list of dependent nmethods nmethod* _osr_nmethods_head; // Head of list of on-stack replacement nmethods for this class BreakpointInfo* _breakpoints; // bpt lists, managed by Method* @@ -690,10 +689,6 @@ class InstanceKlass: public Klass { size_t *length_p, jmethodID* id_p); jmethodID jmethod_id_or_null(Method* method); - // cached itable index support - void set_cached_itable_index(size_t idnum, int index); - int cached_itable_index(size_t idnum); - // annotations support Annotations* annotations() const { return _annotations; } void set_annotations(Annotations* anno) { _annotations = anno; } @@ -994,11 +989,6 @@ private: void release_set_methods_jmethod_ids(jmethodID* jmeths) { OrderAccess::release_store_ptr(&_methods_jmethod_ids, jmeths); } - int* methods_cached_itable_indices_acquire() const - { return (int*)OrderAccess::load_ptr_acquire(&_methods_cached_itable_indices); } - void release_set_methods_cached_itable_indices(int* indices) - { OrderAccess::release_store_ptr(&_methods_cached_itable_indices, indices); } - // Lock during initialization public: // Lock for (1) initialization; (2) access to the ConstantPool of this class. diff --git a/hotspot/src/share/vm/oops/klass.cpp b/hotspot/src/share/vm/oops/klass.cpp index cf24783fbf8..22b570bbff3 100644 --- a/hotspot/src/share/vm/oops/klass.cpp +++ b/hotspot/src/share/vm/oops/klass.cpp @@ -674,13 +674,23 @@ void Klass::oop_verify_on(oop obj, outputStream* st) { #ifndef PRODUCT -void Klass::verify_vtable_index(int i) { +bool Klass::verify_vtable_index(int i) { if (oop_is_instance()) { - assert(i>=0 && i<((InstanceKlass*)this)->vtable_length()/vtableEntry::size(), "index out of bounds"); + int limit = ((InstanceKlass*)this)->vtable_length()/vtableEntry::size(); + assert(i >= 0 && i < limit, err_msg("index %d out of bounds %d", i, limit)); } else { assert(oop_is_array(), "Must be"); - assert(i>=0 && i<((ArrayKlass*)this)->vtable_length()/vtableEntry::size(), "index out of bounds"); + int limit = ((ArrayKlass*)this)->vtable_length()/vtableEntry::size(); + assert(i >= 0 && i < limit, err_msg("index %d out of bounds %d", i, limit)); } + return true; +} + +bool Klass::verify_itable_index(int i) { + assert(oop_is_instance(), ""); + int method_count = klassItable::method_count_for_interface(this); + assert(i >= 0 && i < method_count, "index out of bounds"); + return true; } #endif diff --git a/hotspot/src/share/vm/oops/klass.hpp b/hotspot/src/share/vm/oops/klass.hpp index 83bf44561b2..9855fdd3233 100644 --- a/hotspot/src/share/vm/oops/klass.hpp +++ b/hotspot/src/share/vm/oops/klass.hpp @@ -699,7 +699,8 @@ class Klass : public Metadata { void verify(bool check_dictionary = true) { verify_on(tty, check_dictionary); } #ifndef PRODUCT - void verify_vtable_index(int index); + bool verify_vtable_index(int index); + bool verify_itable_index(int index); #endif virtual void oop_verify_on(oop obj, outputStream* st); diff --git a/hotspot/src/share/vm/oops/klassVtable.cpp b/hotspot/src/share/vm/oops/klassVtable.cpp index ebc6e0aea88..7105368840f 100644 --- a/hotspot/src/share/vm/oops/klassVtable.cpp +++ b/hotspot/src/share/vm/oops/klassVtable.cpp @@ -47,11 +47,12 @@ inline InstanceKlass* klassVtable::ik() const { // this function computes the vtable size (including the size needed for miranda -// methods) and the number of miranda methods in this class +// methods) and the number of miranda methods in this class. // Note on Miranda methods: Let's say there is a class C that implements -// interface I. Let's say there is a method m in I that neither C nor any -// of its super classes implement (i.e there is no method of any access, with -// the same name and signature as m), then m is a Miranda method which is +// interface I, and none of C's superclasses implements I. +// Let's say there is an abstract method m in I that neither C +// nor any of its super classes implement (i.e there is no method of any access, +// with the same name and signature as m), then m is a Miranda method which is // entered as a public abstract method in C's vtable. From then on it should // treated as any other public method in C for method over-ride purposes. void klassVtable::compute_vtable_size_and_num_mirandas( @@ -111,10 +112,13 @@ void klassVtable::compute_vtable_size_and_num_mirandas( } int klassVtable::index_of(Method* m, int len) const { - assert(m->vtable_index() >= 0, "do not ask this of non-vtable methods"); + assert(m->has_vtable_index(), "do not ask this of non-vtable methods"); return m->vtable_index(); } +// Copy super class's vtable to the first part (prefix) of this class's vtable, +// and return the number of entries copied. Expects that 'super' is the Java +// super class (arrays can have "array" super classes that must be skipped). int klassVtable::initialize_from_super(KlassHandle super) { if (super.is_null()) { return 0; @@ -139,14 +143,14 @@ int klassVtable::initialize_from_super(KlassHandle super) { } } -// Revised lookup semantics introduced 1.3 (Kestral beta) +// +// Revised lookup semantics introduced 1.3 (Kestrel beta) void klassVtable::initialize_vtable(bool checkconstraints, TRAPS) { // Note: Arrays can have intermediate array supers. Use java_super to skip them. KlassHandle super (THREAD, klass()->java_super()); int nofNewEntries = 0; - if (PrintVtables && !klass()->oop_is_array()) { ResourceMark rm(THREAD); tty->print_cr("Initializing: %s", _klass->name()->as_C_string()); @@ -174,8 +178,10 @@ void klassVtable::initialize_vtable(bool checkconstraints, TRAPS) { int len = methods->length(); int initialized = super_vtable_len; - // update_inherited_vtable can stop for gc - ensure using handles + // Check each of this class's methods against super; + // if override, replace in copy of super vtable, otherwise append to end for (int i = 0; i < len; i++) { + // update_inherited_vtable can stop for gc - ensure using handles HandleMark hm(THREAD); assert(methods->at(i)->is_method(), "must be a Method*"); methodHandle mh(THREAD, methods->at(i)); @@ -189,11 +195,11 @@ void klassVtable::initialize_vtable(bool checkconstraints, TRAPS) { } } - // add miranda methods; it will also update the value of initialized - fill_in_mirandas(&initialized); + // add miranda methods to end of vtable. + initialized = fill_in_mirandas(initialized); // In class hierarchies where the accessibility is not increasing (i.e., going from private -> - // package_private -> publicprotected), the vtable might actually be smaller than our initial + // package_private -> public/protected), the vtable might actually be smaller than our initial // calculation. assert(initialized <= _length, "vtable initialization failed"); for(;initialized < _length; initialized++) { @@ -248,14 +254,8 @@ InstanceKlass* klassVtable::find_transitive_override(InstanceKlass* initialsuper return superk; } -// Methods that are "effectively" final don't need vtable entries. -bool method_is_effectively_final( - AccessFlags klass_flags, methodHandle target) { - return target->is_final() || klass_flags.is_final() && !target->is_overpass(); -} - // Update child's copy of super vtable for overrides -// OR return true if a new vtable entry is required +// OR return true if a new vtable entry is required. // Only called for InstanceKlass's, i.e. not for arrays // If that changed, could not use _klass as handle for klass bool klassVtable::update_inherited_vtable(InstanceKlass* klass, methodHandle target_method, int super_vtable_len, @@ -263,6 +263,7 @@ bool klassVtable::update_inherited_vtable(InstanceKlass* klass, methodHandle tar ResourceMark rm; bool allocate_new = true; assert(klass->oop_is_instance(), "must be InstanceKlass"); + assert(klass == target_method()->method_holder(), "caller resp."); // Initialize the method's vtable index to "nonvirtual". // If we allocate a vtable entry, we will update it to a non-negative number. @@ -273,11 +274,17 @@ bool klassVtable::update_inherited_vtable(InstanceKlass* klass, methodHandle tar return false; } - if (method_is_effectively_final(klass->access_flags(), target_method)) { + if (target_method->is_final_method(klass->access_flags())) { // a final method never needs a new entry; final methods can be statically // resolved and they have to be present in the vtable only if they override // a super's method, in which case they re-use its entry allocate_new = false; + } else if (klass->is_interface()) { + allocate_new = false; // see note below in needs_new_vtable_entry + // An interface never allocates new vtable slots, only inherits old ones. + // This method will either be assigned its own itable index later, + // or be assigned an inherited vtable index in the loop below. + target_method()->set_vtable_index(Method::pending_itable_index); } // we need a new entry if there is no superclass @@ -411,8 +418,14 @@ bool klassVtable::needs_new_vtable_entry(methodHandle target_method, Symbol* classname, AccessFlags class_flags, TRAPS) { + if (class_flags.is_interface()) { + // Interfaces do not use vtables, so there is no point to assigning + // a vtable index to any of their methods. If we refrain from doing this, + // we can use Method::_vtable_index to hold the itable index + return false; + } - if (method_is_effectively_final(class_flags, target_method) || + if (target_method->is_final_method(class_flags) || // a final method never needs a new entry; final methods can be statically // resolved and they have to be present in the vtable only if they override // a super's method, in which case they re-use its entry @@ -500,7 +513,8 @@ int klassVtable::index_of_miranda(Symbol* name, Symbol* signature) { return Method::invalid_vtable_index; } -// check if an entry is miranda +// check if an entry at an index is miranda +// requires that method m at entry be declared ("held") by an interface. bool klassVtable::is_miranda_entry_at(int i) { Method* m = method_at(i); Klass* method_holder = m->method_holder(); @@ -516,7 +530,9 @@ bool klassVtable::is_miranda_entry_at(int i) { return false; } -// check if a method is a miranda method, given a class's methods table and it's super +// check if a method is a miranda method, given a class's methods table and its super +// "miranda" means not static, not defined by this class, and not defined +// in super unless it is private and therefore inaccessible to this class. // the caller must make sure that the method belongs to an interface implemented by the class bool klassVtable::is_miranda(Method* m, Array* class_methods, Klass* super) { if (m->is_static()) { @@ -541,6 +557,14 @@ bool klassVtable::is_miranda(Method* m, Array* class_methods, Klass* su return false; } +// Scans current_interface_methods for miranda methods that do not +// already appear in new_mirandas and are also not defined-and-non-private +// in super (superclass). These mirandas are added to all_mirandas if it is +// not null; in addition, those that are not duplicates of miranda methods +// inherited by super from its interfaces are added to new_mirandas. +// Thus, new_mirandas will be the set of mirandas that this class introduces, +// all_mirandas will be the set of all mirandas applicable to this class +// including all defined in superclasses. void klassVtable::add_new_mirandas_to_lists( GrowableArray* new_mirandas, GrowableArray* all_mirandas, Array* current_interface_methods, Array* class_methods, @@ -599,17 +623,22 @@ void klassVtable::get_mirandas(GrowableArray* new_mirandas, } } -// fill in mirandas -void klassVtable::fill_in_mirandas(int* initialized) { +// Discover miranda methods ("miranda" = "interface abstract, no binding"), +// and append them into the vtable starting at index initialized, +// return the new value of initialized. +int klassVtable::fill_in_mirandas(int initialized) { GrowableArray mirandas(20); get_mirandas(&mirandas, NULL, ik()->super(), ik()->methods(), ik()->local_interfaces()); for (int i = 0; i < mirandas.length(); i++) { - put_method_at(mirandas.at(i), *initialized); - ++(*initialized); + put_method_at(mirandas.at(i), initialized); + ++initialized; } + return initialized; } +// Copy this class's vtable to the vtable beginning at start. +// Used to copy superclass vtable to prefix of subclass's vtable. void klassVtable::copy_vtable_to(vtableEntry* start) { Copy::disjoint_words((HeapWord*)table(), (HeapWord*)start, _length * vtableEntry::size()); } @@ -723,6 +752,12 @@ static int initialize_count = 0; // Initialization void klassItable::initialize_itable(bool checkconstraints, TRAPS) { + if (_klass->is_interface()) { + // This needs to go after vtable indexes are assigned but + // before implementors need to know the number of itable indexes. + assign_itable_indexes_for_interface(_klass()); + } + // Cannot be setup doing bootstrapping, interfaces don't have // itables, and klass with only ones entry have empty itables if (Universe::is_bootstrapping() || @@ -754,45 +789,89 @@ void klassItable::initialize_itable(bool checkconstraints, TRAPS) { } +inline bool interface_method_needs_itable_index(Method* m) { + if (m->is_static()) return false; // e.g., Stream.empty + if (m->is_initializer()) return false; // or + // If an interface redeclares a method from java.lang.Object, + // it should already have a vtable index, don't touch it. + // e.g., CharSequence.toString (from initialize_vtable) + // if (m->has_vtable_index()) return false; // NO! + return true; +} + +int klassItable::assign_itable_indexes_for_interface(Klass* klass) { + // an interface does not have an itable, but its methods need to be numbered + if (TraceItables) tty->print_cr("%3d: Initializing itable for interface %s", ++initialize_count, + klass->name()->as_C_string()); + Array* methods = InstanceKlass::cast(klass)->methods(); + int nof_methods = methods->length(); + int ime_num = 0; + for (int i = 0; i < nof_methods; i++) { + Method* m = methods->at(i); + if (interface_method_needs_itable_index(m)) { + assert(!m->is_final_method(), "no final interface methods"); + // If m is already assigned a vtable index, do not disturb it. + if (!m->has_vtable_index()) { + assert(m->vtable_index() == Method::pending_itable_index, "set by initialize_vtable"); + m->set_itable_index(ime_num); + // Progress to next itable entry + ime_num++; + } + } + } + assert(ime_num == method_count_for_interface(klass), "proper sizing"); + return ime_num; +} + +int klassItable::method_count_for_interface(Klass* interf) { + assert(interf->oop_is_instance(), "must be"); + assert(interf->is_interface(), "must be"); + Array* methods = InstanceKlass::cast(interf)->methods(); + int nof_methods = methods->length(); + while (nof_methods > 0) { + Method* m = methods->at(nof_methods-1); + if (m->has_itable_index()) { + int length = m->itable_index() + 1; +#ifdef ASSERT + while (nof_methods = 0) { + m = methods->at(--nof_methods); + assert(!m->has_itable_index() || m->itable_index() < length, ""); + } +#endif //ASSERT + return length; // return the rightmost itable index, plus one + } + nof_methods -= 1; + } + // no methods have itable indexes + return 0; +} + + void klassItable::initialize_itable_for_interface(int method_table_offset, KlassHandle interf_h, bool checkconstraints, TRAPS) { Array* methods = InstanceKlass::cast(interf_h())->methods(); int nof_methods = methods->length(); HandleMark hm; - KlassHandle klass = _klass; assert(nof_methods > 0, "at least one method must exist for interface to be in vtable"); Handle interface_loader (THREAD, InstanceKlass::cast(interf_h())->class_loader()); - int ime_num = 0; - // Skip first Method* if it is a class initializer - int i = methods->at(0)->is_static_initializer() ? 1 : 0; - - // m, method_name, method_signature, klass reset each loop so they - // don't need preserving across check_signature_loaders call - // methods needs a handle in case of gc from check_signature_loaders - for(; i < nof_methods; i++) { + int ime_count = method_count_for_interface(interf_h()); + for (int i = 0; i < nof_methods; i++) { Method* m = methods->at(i); - Symbol* method_name = m->name(); - Symbol* method_signature = m->signature(); - - // This is same code as in Linkresolver::lookup_instance_method_in_klasses - Method* target = klass->uncached_lookup_method(method_name, method_signature); - while (target != NULL && target->is_static()) { - // continue with recursive lookup through the superclass - Klass* super = target->method_holder()->super(); - target = (super == NULL) ? (Method*)NULL : super->uncached_lookup_method(method_name, method_signature); + methodHandle target; + if (m->has_itable_index()) { + LinkResolver::lookup_instance_method_in_klasses(target, _klass, m->name(), m->signature(), CHECK); } if (target == NULL || !target->is_public() || target->is_abstract()) { // Entry do not resolve. Leave it empty } else { // Entry did resolve, check loader constraints before initializing // if checkconstraints requested - methodHandle target_h (THREAD, target); // preserve across gc if (checkconstraints) { Handle method_holder_loader (THREAD, target->method_holder()->class_loader()); if (method_holder_loader() != interface_loader()) { ResourceMark rm(THREAD); Symbol* failed_type_symbol = - SystemDictionary::check_signature_loaders(method_signature, + SystemDictionary::check_signature_loaders(m->signature(), method_holder_loader, interface_loader, true, CHECK); @@ -803,9 +882,9 @@ void klassItable::initialize_itable_for_interface(int method_table_offset, Klass "and the class loader (instance of %s) for interface " "%s have different Class objects for the type %s " "used in the signature"; - char* sig = target_h()->name_and_sig_as_C_string(); + char* sig = target()->name_and_sig_as_C_string(); const char* loader1 = SystemDictionary::loader_name(method_holder_loader()); - char* current = klass->name()->as_C_string(); + char* current = _klass->name()->as_C_string(); const char* loader2 = SystemDictionary::loader_name(interface_loader()); char* iface = InstanceKlass::cast(interf_h())->name()->as_C_string(); char* failed_type_name = failed_type_symbol->as_C_string(); @@ -821,10 +900,10 @@ void klassItable::initialize_itable_for_interface(int method_table_offset, Klass } // ime may have moved during GC so recalculate address - itableOffsetEntry::method_entry(_klass(), method_table_offset)[ime_num].initialize(target_h()); + int ime_num = m->itable_index(); + assert(ime_num < ime_count, "oob"); + itableOffsetEntry::method_entry(_klass(), method_table_offset)[ime_num].initialize(target()); } - // Progress to next entry - ime_num++; } } @@ -913,20 +992,22 @@ class InterfaceVisiterClosure : public StackObj { virtual void doit(Klass* intf, int method_count) = 0; }; -// Visit all interfaces with at-least one method (excluding ) +// Visit all interfaces with at least one itable method void visit_all_interfaces(Array* transitive_intf, InterfaceVisiterClosure *blk) { // Handle array argument for(int i = 0; i < transitive_intf->length(); i++) { Klass* intf = transitive_intf->at(i); assert(intf->is_interface(), "sanity check"); - // Find no. of methods excluding a - int method_count = InstanceKlass::cast(intf)->methods()->length(); - if (method_count > 0) { - Method* m = InstanceKlass::cast(intf)->methods()->at(0); - assert(m != NULL && m->is_method(), "sanity check"); - if (m->name() == vmSymbols::object_initializer_name()) { - method_count--; + // Find no. of itable methods + int method_count = 0; + // method_count = klassItable::method_count_for_interface(intf); + Array* methods = InstanceKlass::cast(intf)->methods(); + if (methods->length() > 0) { + for (int i = methods->length(); --i >= 0; ) { + if (interface_method_needs_itable_index(methods->at(i))) { + method_count++; + } } } @@ -1024,40 +1105,26 @@ void klassItable::setup_itable_offset_table(instanceKlassHandle klass) { } -// m must be a method in an interface -int klassItable::compute_itable_index(Method* m) { - InstanceKlass* intf = m->method_holder(); - assert(intf->is_interface(), "sanity check"); - Array* methods = intf->methods(); - int index = 0; - while(methods->at(index) != m) { - index++; - assert(index < methods->length(), "should find index for resolve_invoke"); - } - // Adjust for , which is left out of table if first method - if (methods->length() > 0 && methods->at(0)->is_static_initializer()) { - index--; - } - return index; -} - - -// inverse to compute_itable_index +// inverse to itable_index Method* klassItable::method_for_itable_index(Klass* intf, int itable_index) { assert(InstanceKlass::cast(intf)->is_interface(), "sanity check"); + assert(intf->verify_itable_index(itable_index), ""); Array* methods = InstanceKlass::cast(intf)->methods(); - int index = itable_index; - // Adjust for , which is left out of table if first method - if (methods->length() > 0 && methods->at(0)->is_static_initializer()) { - index++; - } - - if (itable_index < 0 || index >= methods->length()) + if (itable_index < 0 || itable_index >= method_count_for_interface(intf)) return NULL; // help caller defend against bad indexes + int index = itable_index; Method* m = methods->at(index); - assert(compute_itable_index(m) == itable_index, "correct inverse"); + int index2 = -1; + while (!m->has_itable_index() || + (index2 = m->itable_index()) != itable_index) { + assert(index2 < itable_index, "monotonic"); + if (++index == methods->length()) + return NULL; + m = methods->at(index); + } + assert(m->itable_index() == itable_index, "correct inverse"); return m; } diff --git a/hotspot/src/share/vm/oops/klassVtable.hpp b/hotspot/src/share/vm/oops/klassVtable.hpp index 8d8d6cf27c5..06d55af2566 100644 --- a/hotspot/src/share/vm/oops/klassVtable.hpp +++ b/hotspot/src/share/vm/oops/klassVtable.hpp @@ -124,7 +124,7 @@ class klassVtable : public ResourceObj { // support for miranda methods bool is_miranda_entry_at(int i); - void fill_in_mirandas(int* initialized); + int fill_in_mirandas(int initialized); static bool is_miranda(Method* m, Array* class_methods, Klass* super); static void add_new_mirandas_to_lists( GrowableArray* new_mirandas, @@ -290,12 +290,12 @@ class klassItable : public ResourceObj { #endif // INCLUDE_JVMTI // Setup of itable + static int assign_itable_indexes_for_interface(Klass* klass); + static int method_count_for_interface(Klass* klass); static int compute_itable_size(Array* transitive_interfaces); static void setup_itable_offset_table(instanceKlassHandle klass); // Resolving of method to index - static int compute_itable_index(Method* m); - // ...and back again: static Method* method_for_itable_index(Klass* klass, int itable_index); // Debugging/Statistics diff --git a/hotspot/src/share/vm/oops/method.cpp b/hotspot/src/share/vm/oops/method.cpp index b8e60a774f3..30631fa3b61 100644 --- a/hotspot/src/share/vm/oops/method.cpp +++ b/hotspot/src/share/vm/oops/method.cpp @@ -509,24 +509,31 @@ bool Method::compute_has_loops_flag() { return _access_flags.has_loops(); } +bool Method::is_final_method(AccessFlags class_access_flags) const { + // or "does_not_require_vtable_entry" + // overpass can occur, is not final (reuses vtable entry) + // private methods get vtable entries for backward class compatibility. + if (is_overpass()) return false; + return is_final() || class_access_flags.is_final(); +} bool Method::is_final_method() const { - // %%% Should return true for private methods also, - // since there is no way to override them. - return is_final() || method_holder()->is_final(); + return is_final_method(method_holder()->access_flags()); } - -bool Method::is_strict_method() const { - return is_strict(); -} - - -bool Method::can_be_statically_bound() const { - if (is_final_method()) return true; +bool Method::can_be_statically_bound(AccessFlags class_access_flags) const { + if (is_final_method(class_access_flags)) return true; +#ifdef ASSERT + bool is_nonv = (vtable_index() == nonvirtual_vtable_index); + if (class_access_flags.is_interface()) assert(is_nonv == is_static(), err_msg("is_nonv=%s", is_nonv)); +#endif + assert(valid_vtable_index() || valid_itable_index(), "method must be linked before we ask this question"); return vtable_index() == nonvirtual_vtable_index; } +bool Method::can_be_statically_bound() const { + return can_be_statically_bound(method_holder()->access_flags()); +} bool Method::is_accessor() const { if (code_size() != 5) return false; @@ -967,7 +974,7 @@ bool Method::is_overridden_in(Klass* k) const { assert(ik->is_subclass_of(method_holder()), "should be subklass"); assert(ik->vtable() != NULL, "vtable should exist"); - if (vtable_index() == nonvirtual_vtable_index) { + if (!has_vtable_index()) { return false; } else { Method* vt_m = ik->method_at_vtable(vtable_index()); @@ -1959,7 +1966,7 @@ void Method::print_on(outputStream* st) const { void Method::print_value_on(outputStream* st) const { assert(is_method(), "must be method"); - st->print_cr(internal_name()); + st->print(internal_name()); print_address_on(st); st->print(" "); name()->print_value_on(st); @@ -1967,6 +1974,7 @@ void Method::print_value_on(outputStream* st) const { signature()->print_value_on(st); st->print(" in "); method_holder()->print_value_on(st); + if (WizardMode) st->print("#%d", _vtable_index); if (WizardMode) st->print("[%d,%d]", size_of_parameters(), max_locals()); if (WizardMode && code() != NULL) st->print(" ((nmethod*)%p)", code()); } diff --git a/hotspot/src/share/vm/oops/method.hpp b/hotspot/src/share/vm/oops/method.hpp index faaf5105994..02d2253b80a 100644 --- a/hotspot/src/share/vm/oops/method.hpp +++ b/hotspot/src/share/vm/oops/method.hpp @@ -448,16 +448,22 @@ class Method : public Metadata { enum VtableIndexFlag { // Valid vtable indexes are non-negative (>= 0). // These few negative values are used as sentinels. - highest_unused_vtable_index_value = -5, + itable_index_max = -10, // first itable index, growing downward + pending_itable_index = -9, // itable index will be assigned invalid_vtable_index = -4, // distinct from any valid vtable index garbage_vtable_index = -3, // not yet linked; no vtable layout yet nonvirtual_vtable_index = -2 // there is no need for vtable dispatch // 6330203 Note: Do not use -1, which was overloaded with many meanings. }; DEBUG_ONLY(bool valid_vtable_index() const { return _vtable_index >= nonvirtual_vtable_index; }) - int vtable_index() const { assert(valid_vtable_index(), ""); - return _vtable_index; } + bool has_vtable_index() const { return _vtable_index >= 0; } + int vtable_index() const { return _vtable_index; } void set_vtable_index(int index) { _vtable_index = index; } + DEBUG_ONLY(bool valid_itable_index() const { return _vtable_index <= pending_itable_index; }) + bool has_itable_index() const { return _vtable_index <= itable_index_max; } + int itable_index() const { assert(valid_itable_index(), ""); + return itable_index_max - _vtable_index; } + void set_itable_index(int index) { _vtable_index = itable_index_max - index; assert(valid_itable_index(), ""); } // interpreter entry address interpreter_entry() const { return _i2i_entry; } @@ -560,10 +566,11 @@ class Method : public Metadata { // checks method and its method holder bool is_final_method() const; - bool is_strict_method() const; + bool is_final_method(AccessFlags class_access_flags) const; // true if method needs no dynamic dispatch (final and/or no vtable entry) bool can_be_statically_bound() const; + bool can_be_statically_bound(AccessFlags class_access_flags) const; // returns true if the method has any backward branches. bool has_loops() { @@ -740,10 +747,6 @@ class Method : public Metadata { // so handles are not used to avoid deadlock. jmethodID find_jmethod_id_or_null() { return method_holder()->jmethod_id_or_null(this); } - // JNI static invoke cached itable index accessors - int cached_itable_index() { return method_holder()->cached_itable_index(method_idnum()); } - void set_cached_itable_index(int index) { method_holder()->set_cached_itable_index(method_idnum(), index); } - // Support for inlining of intrinsic methods vmIntrinsics::ID intrinsic_id() const { return (vmIntrinsics::ID) _intrinsic_id; } void set_intrinsic_id(vmIntrinsics::ID id) { _intrinsic_id = (u1) id; } diff --git a/hotspot/src/share/vm/oops/symbol.hpp b/hotspot/src/share/vm/oops/symbol.hpp index f9db8d39974..e747c464607 100644 --- a/hotspot/src/share/vm/oops/symbol.hpp +++ b/hotspot/src/share/vm/oops/symbol.hpp @@ -45,7 +45,7 @@ // in the SymbolTable bucket (the _literal field in HashtableEntry) // that points to the Symbol. All other stores of a Symbol* // to a field of a persistent variable (e.g., the _name filed in -// FieldAccessInfo or _ptr in a CPSlot) is reference counted. +// fieldDescriptor or _ptr in a CPSlot) is reference counted. // // 1) The lookup of a "name" in the SymbolTable either creates a Symbol F for // "name" and returns a pointer to F or finds a pre-existing Symbol F for diff --git a/hotspot/src/share/vm/opto/library_call.cpp b/hotspot/src/share/vm/opto/library_call.cpp index f7e09c3f89f..e0d68d9fc58 100644 --- a/hotspot/src/share/vm/opto/library_call.cpp +++ b/hotspot/src/share/vm/opto/library_call.cpp @@ -3734,6 +3734,8 @@ Node* LibraryCallKit::generate_virtual_guard(Node* obj_klass, RegionNode* slow_region) { ciMethod* method = callee(); int vtable_index = method->vtable_index(); + assert(vtable_index >= 0 || vtable_index == Method::nonvirtual_vtable_index, + err_msg_res("bad index %d", vtable_index)); // Get the Method* out of the appropriate vtable entry. int entry_offset = (InstanceKlass::vtable_start_offset() + vtable_index*vtableEntry::size()) * wordSize + @@ -3784,6 +3786,8 @@ LibraryCallKit::generate_method_call(vmIntrinsics::ID method_id, bool is_virtual // so the vtable index is fixed. // No need to use the linkResolver to get it. vtable_index = method->vtable_index(); + assert(vtable_index >= 0 || vtable_index == Method::nonvirtual_vtable_index, + err_msg_res("bad index %d", vtable_index)); } slow_call = new(C) CallDynamicJavaNode(tf, SharedRuntime::get_resolve_virtual_call_stub(), diff --git a/hotspot/src/share/vm/prims/jni.cpp b/hotspot/src/share/vm/prims/jni.cpp index ea44e2c6679..8367f5133b6 100644 --- a/hotspot/src/share/vm/prims/jni.cpp +++ b/hotspot/src/share/vm/prims/jni.cpp @@ -1336,6 +1336,7 @@ static void jni_invoke_nonstatic(JNIEnv *env, JavaValue* result, jobject receive if (call_type == JNI_VIRTUAL) { // jni_GetMethodID makes sure class is linked and initialized // so m should have a valid vtable index. + assert(!m->has_itable_index(), ""); int vtbl_index = m->vtable_index(); if (vtbl_index != Method::nonvirtual_vtable_index) { Klass* k = h_recv->klass(); @@ -1355,12 +1356,7 @@ static void jni_invoke_nonstatic(JNIEnv *env, JavaValue* result, jobject receive // interface call KlassHandle h_holder(THREAD, holder); - int itbl_index = m->cached_itable_index(); - if (itbl_index == -1) { - itbl_index = klassItable::compute_itable_index(m); - m->set_cached_itable_index(itbl_index); - // the above may have grabbed a lock, 'm' and anything non-handlized can't be used again - } + int itbl_index = m->itable_index(); Klass* k = h_recv->klass(); selected_method = InstanceKlass::cast(k)->method_at_itable(h_holder(), itbl_index, CHECK); } diff --git a/hotspot/src/share/vm/prims/jvm.cpp b/hotspot/src/share/vm/prims/jvm.cpp index caed2d13612..d7a961edfbb 100644 --- a/hotspot/src/share/vm/prims/jvm.cpp +++ b/hotspot/src/share/vm/prims/jvm.cpp @@ -1824,7 +1824,7 @@ JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredFields(JNIEnv *env, jclass ofClass, } if (!publicOnly || fs.access_flags().is_public()) { - fd.initialize(k(), fs.index()); + fd.reinitialize(k(), fs.index()); oop field = Reflection::new_field(&fd, UseNewReflection, CHECK_NULL); result->obj_at_put(out_idx, field); ++out_idx; diff --git a/hotspot/src/share/vm/prims/jvmtiRedefineClasses.cpp b/hotspot/src/share/vm/prims/jvmtiRedefineClasses.cpp index 803cf9a7545..db009a43361 100644 --- a/hotspot/src/share/vm/prims/jvmtiRedefineClasses.cpp +++ b/hotspot/src/share/vm/prims/jvmtiRedefineClasses.cpp @@ -2930,7 +2930,7 @@ void VM_RedefineClasses::check_methods_and_mark_as_obsolete( for (int i = 0; i < _deleted_methods_length; ++i) { Method* old_method = _deleted_methods[i]; - assert(old_method->vtable_index() < 0, + assert(!old_method->has_vtable_index(), "cannot delete methods with vtable entries");; // Mark all deleted methods as old and obsolete diff --git a/hotspot/src/share/vm/prims/methodHandles.cpp b/hotspot/src/share/vm/prims/methodHandles.cpp index ac1c796eb31..88b82b358e6 100644 --- a/hotspot/src/share/vm/prims/methodHandles.cpp +++ b/hotspot/src/share/vm/prims/methodHandles.cpp @@ -127,25 +127,37 @@ Handle MethodHandles::new_MemberName(TRAPS) { } oop MethodHandles::init_MemberName(Handle mname, Handle target) { + // This method is used from java.lang.invoke.MemberName constructors. + // It fills in the new MemberName from a java.lang.reflect.Member. Thread* thread = Thread::current(); oop target_oop = target(); Klass* target_klass = target_oop->klass(); if (target_klass == SystemDictionary::reflect_Field_klass()) { oop clazz = java_lang_reflect_Field::clazz(target_oop); // fd.field_holder() int slot = java_lang_reflect_Field::slot(target_oop); // fd.index() - int mods = java_lang_reflect_Field::modifiers(target_oop); - oop type = java_lang_reflect_Field::type(target_oop); - oop name = java_lang_reflect_Field::name(target_oop); KlassHandle k(thread, java_lang_Class::as_Klass(clazz)); - intptr_t offset = InstanceKlass::cast(k())->field_offset(slot); - return init_field_MemberName(mname, k, accessFlags_from(mods), type, name, offset); + if (!k.is_null() && k->oop_is_instance()) { + fieldDescriptor fd(InstanceKlass::cast(k()), slot); + oop mname2 = init_field_MemberName(mname, fd); + if (mname2 != NULL) { + // Since we have the reified name and type handy, add them to the result. + if (java_lang_invoke_MemberName::name(mname2) == NULL) + java_lang_invoke_MemberName::set_name(mname2, java_lang_reflect_Field::name(target_oop)); + if (java_lang_invoke_MemberName::type(mname2) == NULL) + java_lang_invoke_MemberName::set_type(mname2, java_lang_reflect_Field::type(target_oop)); + } + return mname2; + } } else if (target_klass == SystemDictionary::reflect_Method_klass()) { oop clazz = java_lang_reflect_Method::clazz(target_oop); int slot = java_lang_reflect_Method::slot(target_oop); KlassHandle k(thread, java_lang_Class::as_Klass(clazz)); if (!k.is_null() && k->oop_is_instance()) { Method* m = InstanceKlass::cast(k())->method_with_idnum(slot); - return init_method_MemberName(mname, m, true, k); + if (m == NULL || is_signature_polymorphic(m->intrinsic_id())) + return NULL; // do not resolve unless there is a concrete signature + CallInfo info(m, k()); + return init_method_MemberName(mname, info); } } else if (target_klass == SystemDictionary::reflect_Constructor_klass()) { oop clazz = java_lang_reflect_Constructor::clazz(target_oop); @@ -153,65 +165,50 @@ oop MethodHandles::init_MemberName(Handle mname, Handle target) { KlassHandle k(thread, java_lang_Class::as_Klass(clazz)); if (!k.is_null() && k->oop_is_instance()) { Method* m = InstanceKlass::cast(k())->method_with_idnum(slot); - return init_method_MemberName(mname, m, false, k); - } - } else if (target_klass == SystemDictionary::MemberName_klass()) { - // Note: This only works if the MemberName has already been resolved. - oop clazz = java_lang_invoke_MemberName::clazz(target_oop); - int flags = java_lang_invoke_MemberName::flags(target_oop); - Metadata* vmtarget=java_lang_invoke_MemberName::vmtarget(target_oop); - intptr_t vmindex = java_lang_invoke_MemberName::vmindex(target_oop); - KlassHandle k(thread, java_lang_Class::as_Klass(clazz)); - int ref_kind = (flags >> REFERENCE_KIND_SHIFT) & REFERENCE_KIND_MASK; - if (vmtarget == NULL) return NULL; // not resolved - if ((flags & IS_FIELD) != 0) { - assert(vmtarget->is_klass(), "field vmtarget is Klass*"); - int basic_mods = (ref_kind_is_static(ref_kind) ? JVM_ACC_STATIC : 0); - // FIXME: how does k (receiver_limit) contribute? - KlassHandle k_vmtarget(thread, (Klass*)vmtarget); - return init_field_MemberName(mname, k_vmtarget, accessFlags_from(basic_mods), NULL, NULL, vmindex); - } else if ((flags & (IS_METHOD | IS_CONSTRUCTOR)) != 0) { - assert(vmtarget->is_method(), "method or constructor vmtarget is Method*"); - return init_method_MemberName(mname, (Method*)vmtarget, ref_kind_does_dispatch(ref_kind), k); - } else { - return NULL; + if (m == NULL) return NULL; + CallInfo info(m, k()); + return init_method_MemberName(mname, info); } } return NULL; } -oop MethodHandles::init_method_MemberName(Handle mname, Method* m, bool do_dispatch, - KlassHandle receiver_limit_h) { - Klass* receiver_limit = receiver_limit_h(); - AccessFlags mods = m->access_flags(); - int flags = (jushort)( mods.as_short() & JVM_RECOGNIZED_METHOD_MODIFIERS ); - int vmindex = Method::nonvirtual_vtable_index; // implies never any dispatch - Klass* mklass = m->method_holder(); - if (receiver_limit == NULL) - receiver_limit = mklass; - if (m->is_initializer()) { - flags |= IS_CONSTRUCTOR | (JVM_REF_invokeSpecial << REFERENCE_KIND_SHIFT); - } else if (mods.is_static()) { - flags |= IS_METHOD | (JVM_REF_invokeStatic << REFERENCE_KIND_SHIFT); - } else if (receiver_limit != mklass && - !receiver_limit->is_subtype_of(mklass)) { - return NULL; // bad receiver limit - } else if (do_dispatch && receiver_limit->is_interface() && - mklass->is_interface()) { +oop MethodHandles::init_method_MemberName(Handle mname, CallInfo& info) { + assert(info.resolved_appendix().is_null(), "only normal methods here"); + KlassHandle receiver_limit = info.resolved_klass(); + methodHandle m = info.resolved_method(); + int flags = (jushort)( m->access_flags().as_short() & JVM_RECOGNIZED_METHOD_MODIFIERS ); + int vmindex = Method::invalid_vtable_index; + + switch (info.call_kind()) { + case CallInfo::itable_call: + vmindex = info.itable_index(); + // More importantly, the itable index only works with the method holder. + receiver_limit = m->method_holder(); + assert(receiver_limit->verify_itable_index(vmindex), ""); flags |= IS_METHOD | (JVM_REF_invokeInterface << REFERENCE_KIND_SHIFT); - receiver_limit = mklass; // ignore passed-in limit; interfaces are interconvertible - vmindex = klassItable::compute_itable_index(m); - } else if (do_dispatch && mklass != receiver_limit && mklass->is_interface()) { + break; + + case CallInfo::vtable_call: + vmindex = info.vtable_index(); flags |= IS_METHOD | (JVM_REF_invokeVirtual << REFERENCE_KIND_SHIFT); - // it is a miranda method, so m->vtable_index is not what we want - ResourceMark rm; - klassVtable* vt = InstanceKlass::cast(receiver_limit)->vtable(); - vmindex = vt->index_of_miranda(m->name(), m->signature()); - } else if (!do_dispatch || m->can_be_statically_bound()) { - flags |= IS_METHOD | (JVM_REF_invokeSpecial << REFERENCE_KIND_SHIFT); - } else { - flags |= IS_METHOD | (JVM_REF_invokeVirtual << REFERENCE_KIND_SHIFT); - vmindex = m->vtable_index(); + assert(receiver_limit->is_subtype_of(m->method_holder()), "virtual call must be type-safe"); + break; + + case CallInfo::direct_call: + vmindex = Method::nonvirtual_vtable_index; + if (m->is_static()) { + flags |= IS_METHOD | (JVM_REF_invokeStatic << REFERENCE_KIND_SHIFT); + } else if (m->is_initializer()) { + flags |= IS_CONSTRUCTOR | (JVM_REF_invokeSpecial << REFERENCE_KIND_SHIFT); + assert(receiver_limit == m->method_holder(), "constructor call must be exactly typed"); + } else { + flags |= IS_METHOD | (JVM_REF_invokeSpecial << REFERENCE_KIND_SHIFT); + assert(receiver_limit->is_subtype_of(m->method_holder()), "special call must be type-safe"); + } + break; + + default: assert(false, "bad CallInfo"); return NULL; } // @CallerSensitive annotation detected @@ -221,7 +218,7 @@ oop MethodHandles::init_method_MemberName(Handle mname, Method* m, bool do_dispa oop mname_oop = mname(); java_lang_invoke_MemberName::set_flags( mname_oop, flags); - java_lang_invoke_MemberName::set_vmtarget(mname_oop, m); + java_lang_invoke_MemberName::set_vmtarget(mname_oop, m()); java_lang_invoke_MemberName::set_vmindex( mname_oop, vmindex); // vtable/itable index java_lang_invoke_MemberName::set_clazz( mname_oop, receiver_limit->java_mirror()); // Note: name and type can be lazily computed by resolve_MemberName, @@ -237,59 +234,19 @@ oop MethodHandles::init_method_MemberName(Handle mname, Method* m, bool do_dispa return mname(); } -Handle MethodHandles::init_method_MemberName(Handle mname, CallInfo& info, TRAPS) { - Handle empty; - if (info.resolved_appendix().not_null()) { - // The resolved MemberName must not be accompanied by an appendix argument, - // since there is no way to bind this value into the MemberName. - // Caller is responsible to prevent this from happening. - THROW_MSG_(vmSymbols::java_lang_InternalError(), "appendix", empty); - } - methodHandle m = info.resolved_method(); - KlassHandle defc = info.resolved_klass(); - int vmindex = Method::invalid_vtable_index; - if (defc->is_interface() && m->method_holder()->is_interface()) { - // static interface methods do not reference vtable or itable - if (m->is_static()) { - vmindex = Method::nonvirtual_vtable_index; - } - // interface methods invoked via invokespecial also - // do not reference vtable or itable. - int ref_kind = ((java_lang_invoke_MemberName::flags(mname()) >> - REFERENCE_KIND_SHIFT) & REFERENCE_KIND_MASK); - if (ref_kind == JVM_REF_invokeSpecial) { - vmindex = Method::nonvirtual_vtable_index; - } - // If neither m is static nor ref_kind is invokespecial, - // set it to itable index. - if (vmindex == Method::invalid_vtable_index) { - // LinkResolver does not report itable indexes! (fix this?) - vmindex = klassItable::compute_itable_index(m()); - } - } else if (m->can_be_statically_bound()) { - // LinkResolver reports vtable index even for final methods! - vmindex = Method::nonvirtual_vtable_index; - } else { - vmindex = info.vtable_index(); - } - oop res = init_method_MemberName(mname, m(), (vmindex >= 0), defc()); - assert(res == NULL || (java_lang_invoke_MemberName::vmindex(res) == vmindex), ""); - return Handle(THREAD, res); -} - -oop MethodHandles::init_field_MemberName(Handle mname, KlassHandle field_holder, - AccessFlags mods, oop type, oop name, - intptr_t offset, bool is_setter) { - int flags = (jushort)( mods.as_short() & JVM_RECOGNIZED_FIELD_MODIFIERS ); - flags |= IS_FIELD | ((mods.is_static() ? JVM_REF_getStatic : JVM_REF_getField) << REFERENCE_KIND_SHIFT); +oop MethodHandles::init_field_MemberName(Handle mname, fieldDescriptor& fd, bool is_setter) { + int flags = (jushort)( fd.access_flags().as_short() & JVM_RECOGNIZED_FIELD_MODIFIERS ); + flags |= IS_FIELD | ((fd.is_static() ? JVM_REF_getStatic : JVM_REF_getField) << REFERENCE_KIND_SHIFT); if (is_setter) flags += ((JVM_REF_putField - JVM_REF_getField) << REFERENCE_KIND_SHIFT); - Metadata* vmtarget = field_holder(); - int vmindex = offset; // determines the field uniquely when combined with static bit + Metadata* vmtarget = fd.field_holder(); + int vmindex = fd.offset(); // determines the field uniquely when combined with static bit oop mname_oop = mname(); java_lang_invoke_MemberName::set_flags(mname_oop, flags); java_lang_invoke_MemberName::set_vmtarget(mname_oop, vmtarget); java_lang_invoke_MemberName::set_vmindex(mname_oop, vmindex); - java_lang_invoke_MemberName::set_clazz(mname_oop, field_holder->java_mirror()); + java_lang_invoke_MemberName::set_clazz(mname_oop, fd.field_holder()->java_mirror()); + oop type = field_signature_type_or_null(fd.signature()); + oop name = field_name_or_null(fd.name()); if (name != NULL) java_lang_invoke_MemberName::set_name(mname_oop, name); if (type != NULL) @@ -305,19 +262,6 @@ oop MethodHandles::init_field_MemberName(Handle mname, KlassHandle field_holder, return mname(); } -Handle MethodHandles::init_field_MemberName(Handle mname, FieldAccessInfo& info, TRAPS) { - return Handle(); -#if 0 // FIXME - KlassHandle field_holder = info.klass(); - intptr_t field_offset = info.field_offset(); - return init_field_MemberName(mname_oop, field_holder(), - info.access_flags(), - type, name, - field_offset, false /*is_setter*/); -#endif -} - - // JVM 2.9 Special Methods: // A method is signature polymorphic if and only if all of the following conditions hold : // * It is declared in the java.lang.invoke.MethodHandle class. @@ -573,12 +517,12 @@ static oop object_java_mirror() { return SystemDictionary::Object_klass()->java_mirror(); } -static oop field_name_or_null(Symbol* s) { +oop MethodHandles::field_name_or_null(Symbol* s) { if (s == NULL) return NULL; return StringTable::lookup(s); } -static oop field_signature_type_or_null(Symbol* s) { +oop MethodHandles::field_signature_type_or_null(Symbol* s) { if (s == NULL) return NULL; BasicType bt = FieldType::basic_type(s); if (is_java_primitive(bt)) { @@ -701,7 +645,14 @@ Handle MethodHandles::resolve_MemberName(Handle mname, TRAPS) { return empty; } } - return init_method_MemberName(mname, result, THREAD); + if (result.resolved_appendix().not_null()) { + // The resolved MemberName must not be accompanied by an appendix argument, + // since there is no way to bind this value into the MemberName. + // Caller is responsible to prevent this from happening. + THROW_MSG_(vmSymbols::java_lang_InternalError(), "appendix", empty); + } + oop mname2 = init_method_MemberName(mname, result); + return Handle(THREAD, mname2); } case IS_CONSTRUCTOR: { @@ -719,22 +670,21 @@ Handle MethodHandles::resolve_MemberName(Handle mname, TRAPS) { } } assert(result.is_statically_bound(), ""); - return init_method_MemberName(mname, result, THREAD); + oop mname2 = init_method_MemberName(mname, result); + return Handle(THREAD, mname2); } case IS_FIELD: { - // This is taken from LinkResolver::resolve_field, sans access checks. - fieldDescriptor fd; // find_field initializes fd if found - KlassHandle sel_klass(THREAD, InstanceKlass::cast(defc())->find_field(name, type, &fd)); - // check if field exists; i.e., if a klass containing the field def has been selected - if (sel_klass.is_null()) return empty; // should not happen - oop type = field_signature_type_or_null(fd.signature()); - oop name = field_name_or_null(fd.name()); - bool is_setter = (ref_kind_is_valid(ref_kind) && ref_kind_is_setter(ref_kind)); - mname = Handle(THREAD, - init_field_MemberName(mname, sel_klass, - fd.access_flags(), type, name, fd.offset(), is_setter)); - return mname; + fieldDescriptor result; // find_field initializes fd if found + { + assert(!HAS_PENDING_EXCEPTION, ""); + LinkResolver::resolve_field(result, defc, name, type, KlassHandle(), Bytecodes::_nop, false, false, THREAD); + if (HAS_PENDING_EXCEPTION) { + return empty; + } + } + oop mname2 = init_field_MemberName(mname, result, ref_kind_is_setter(ref_kind)); + return Handle(THREAD, mname2); } default: THROW_MSG_(vmSymbols::java_lang_InternalError(), "unrecognized MemberName format", empty); @@ -793,7 +743,6 @@ void MethodHandles::expand_MemberName(Handle mname, int suppress, TRAPS) { } case IS_FIELD: { - // This is taken from LinkResolver::resolve_field, sans access checks. assert(vmtarget->is_klass(), "field vmtarget is Klass*"); if (!((Klass*) vmtarget)->oop_is_instance()) break; instanceKlassHandle defc(THREAD, (Klass*) vmtarget); @@ -872,11 +821,7 @@ int MethodHandles::find_MemberNames(KlassHandle k, Handle result(thread, results->obj_at(rfill++)); if (!java_lang_invoke_MemberName::is_instance(result())) return -99; // caller bug! - oop type = field_signature_type_or_null(st.signature()); - oop name = field_name_or_null(st.name()); - oop saved = MethodHandles::init_field_MemberName(result, st.klass(), - st.access_flags(), type, name, - st.offset()); + oop saved = MethodHandles::init_field_MemberName(result, st.field_descriptor()); if (saved != result()) results->obj_at_put(rfill-1, saved); // show saved instance to user } else if (++overflow >= overflow_limit) { @@ -926,7 +871,8 @@ int MethodHandles::find_MemberNames(KlassHandle k, Handle result(thread, results->obj_at(rfill++)); if (!java_lang_invoke_MemberName::is_instance(result())) return -99; // caller bug! - oop saved = MethodHandles::init_method_MemberName(result, m, true, NULL); + CallInfo info(m); + oop saved = MethodHandles::init_method_MemberName(result, info); if (saved != result()) results->obj_at_put(rfill-1, saved); // show saved instance to user } else if (++overflow >= overflow_limit) { @@ -1227,7 +1173,8 @@ JVM_ENTRY(jobject, MHN_getMemberVMInfo(JNIEnv *env, jobject igcls, jobject mname x = ((Klass*) vmtarget)->java_mirror(); } else if (vmtarget->is_method()) { Handle mname2 = MethodHandles::new_MemberName(CHECK_NULL); - x = MethodHandles::init_method_MemberName(mname2, (Method*)vmtarget, false, NULL); + CallInfo info((Method*)vmtarget); + x = MethodHandles::init_method_MemberName(mname2, info); } result->obj_at_put(1, x); return JNIHandles::make_local(env, result()); diff --git a/hotspot/src/share/vm/prims/methodHandles.hpp b/hotspot/src/share/vm/prims/methodHandles.hpp index 50ce7af86ea..7ae7bd36fb5 100644 --- a/hotspot/src/share/vm/prims/methodHandles.hpp +++ b/hotspot/src/share/vm/prims/methodHandles.hpp @@ -49,19 +49,18 @@ class MethodHandles: AllStatic { // Adapters. static MethodHandlesAdapterBlob* _adapter_code; + // utility functions for reifying names and types + static oop field_name_or_null(Symbol* s); + static oop field_signature_type_or_null(Symbol* s); + public: // working with member names static Handle resolve_MemberName(Handle mname, TRAPS); // compute vmtarget/vmindex from name/type static void expand_MemberName(Handle mname, int suppress, TRAPS); // expand defc/name/type if missing static Handle new_MemberName(TRAPS); // must be followed by init_MemberName static oop init_MemberName(Handle mname_h, Handle target_h); // compute vmtarget/vmindex from target - static oop init_method_MemberName(Handle mname_h, Method* m, bool do_dispatch, - KlassHandle receiver_limit_h); - static oop init_field_MemberName(Handle mname_h, KlassHandle field_holder_h, - AccessFlags mods, oop type, oop name, - intptr_t offset, bool is_setter = false); - static Handle init_method_MemberName(Handle mname_h, CallInfo& info, TRAPS); - static Handle init_field_MemberName(Handle mname_h, FieldAccessInfo& info, TRAPS); + static oop init_field_MemberName(Handle mname_h, fieldDescriptor& fd, bool is_setter = false); + static oop init_method_MemberName(Handle mname_h, CallInfo& info); static int method_ref_kind(Method* m, bool do_dispatch_if_possible = true); static int find_MemberNames(KlassHandle k, Symbol* name, Symbol* sig, int mflags, KlassHandle caller, diff --git a/hotspot/src/share/vm/runtime/fieldDescriptor.cpp b/hotspot/src/share/vm/runtime/fieldDescriptor.cpp index 23d679494ac..79e3ddcd85d 100644 --- a/hotspot/src/share/vm/runtime/fieldDescriptor.cpp +++ b/hotspot/src/share/vm/runtime/fieldDescriptor.cpp @@ -97,18 +97,32 @@ oop fieldDescriptor::string_initial_value(TRAPS) const { return constants()->uncached_string_at(initial_value_index(), CHECK_0); } -void fieldDescriptor::initialize(InstanceKlass* ik, int index) { - _cp = ik->constants(); +void fieldDescriptor::reinitialize(InstanceKlass* ik, int index) { + if (_cp.is_null() || field_holder() != ik) { + _cp = constantPoolHandle(Thread::current(), ik->constants()); + // _cp should now reference ik's constant pool; i.e., ik is now field_holder. + assert(field_holder() == ik, "must be already initialized to this class"); + } FieldInfo* f = ik->field(index); assert(!f->is_internal(), "regular Java fields only"); _access_flags = accessFlags_from(f->access_flags()); guarantee(f->name_index() != 0 && f->signature_index() != 0, "bad constant pool index for fieldDescriptor"); _index = index; + verify(); } #ifndef PRODUCT +void fieldDescriptor::verify() const { + if (_cp.is_null()) { + assert(_index == badInt, "constructor must be called"); // see constructor + } else { + assert(_index >= 0, "good index"); + assert(_index < field_holder()->java_fields_count(), "oob"); + } +} + void fieldDescriptor::print_on(outputStream* st) const { access_flags().print_on(st); name()->print_value_on(st); diff --git a/hotspot/src/share/vm/runtime/fieldDescriptor.hpp b/hotspot/src/share/vm/runtime/fieldDescriptor.hpp index 12b75cab144..9c3101b38ba 100644 --- a/hotspot/src/share/vm/runtime/fieldDescriptor.hpp +++ b/hotspot/src/share/vm/runtime/fieldDescriptor.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2013, 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 @@ -53,6 +53,13 @@ class fieldDescriptor VALUE_OBJ_CLASS_SPEC { } public: + fieldDescriptor() { + DEBUG_ONLY(_index = badInt); + } + fieldDescriptor(InstanceKlass* ik, int index) { + DEBUG_ONLY(_index = badInt); + reinitialize(ik, index); + } Symbol* name() const { return field()->name(_cp); } @@ -112,12 +119,13 @@ class fieldDescriptor VALUE_OBJ_CLASS_SPEC { } // Initialization - void initialize(InstanceKlass* ik, int index); + void reinitialize(InstanceKlass* ik, int index); // Print void print() { print_on(tty); } void print_on(outputStream* st) const PRODUCT_RETURN; void print_on_for(outputStream* st, oop obj) PRODUCT_RETURN; + void verify() const PRODUCT_RETURN; }; #endif // SHARE_VM_RUNTIME_FIELDDESCRIPTOR_HPP diff --git a/hotspot/src/share/vm/runtime/mutexLocker.cpp b/hotspot/src/share/vm/runtime/mutexLocker.cpp index f513b7b376c..19f98cc2e4f 100644 --- a/hotspot/src/share/vm/runtime/mutexLocker.cpp +++ b/hotspot/src/share/vm/runtime/mutexLocker.cpp @@ -45,7 +45,6 @@ Mutex* InlineCacheBuffer_lock = NULL; Mutex* VMStatistic_lock = NULL; Mutex* JNIGlobalHandle_lock = NULL; Mutex* JNIHandleBlockFreeList_lock = NULL; -Mutex* JNICachedItableIndex_lock = NULL; Mutex* MemberNameTable_lock = NULL; Mutex* JmethodIdCreation_lock = NULL; Mutex* JfieldIdCreation_lock = NULL; @@ -253,7 +252,6 @@ void mutex_init() { } def(Heap_lock , Monitor, nonleaf+1, false); def(JfieldIdCreation_lock , Mutex , nonleaf+1, true ); // jfieldID, Used in VM_Operation - def(JNICachedItableIndex_lock , Mutex , nonleaf+1, false); // Used to cache an itable index during JNI invoke def(MemberNameTable_lock , Mutex , nonleaf+1, false); // Used to protect MemberNameTable def(CompiledIC_lock , Mutex , nonleaf+2, false); // locks VtableStubs_lock, InlineCacheBuffer_lock diff --git a/hotspot/src/share/vm/runtime/mutexLocker.hpp b/hotspot/src/share/vm/runtime/mutexLocker.hpp index d98b8d890fd..361febdcdb8 100644 --- a/hotspot/src/share/vm/runtime/mutexLocker.hpp +++ b/hotspot/src/share/vm/runtime/mutexLocker.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2013, 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 @@ -50,7 +50,6 @@ extern Mutex* InlineCacheBuffer_lock; // a lock used to guard the Inl extern Mutex* VMStatistic_lock; // a lock used to guard statistics count increment extern Mutex* JNIGlobalHandle_lock; // a lock on creating JNI global handles extern Mutex* JNIHandleBlockFreeList_lock; // a lock on the JNI handle block free list -extern Mutex* JNICachedItableIndex_lock; // a lock on caching an itable index during JNI invoke extern Mutex* MemberNameTable_lock; // a lock on the MemberNameTable updates extern Mutex* JmethodIdCreation_lock; // a lock on creating JNI method identifiers extern Mutex* JfieldIdCreation_lock; // a lock on creating JNI static field identifiers diff --git a/hotspot/src/share/vm/runtime/reflection.cpp b/hotspot/src/share/vm/runtime/reflection.cpp index f06a7f922aa..be29fdecfcf 100644 --- a/hotspot/src/share/vm/runtime/reflection.cpp +++ b/hotspot/src/share/vm/runtime/reflection.cpp @@ -952,7 +952,8 @@ oop Reflection::invoke(instanceKlassHandle klass, methodHandle reflected_method, } } else { // if the method can be overridden, we resolve using the vtable index. - int index = reflected_method->vtable_index(); + assert(!reflected_method->has_itable_index(), ""); + int index = reflected_method->vtable_index(); method = reflected_method; if (index != Method::nonvirtual_vtable_index) { // target_klass might be an arrayKlassOop but all vtables start at diff --git a/hotspot/src/share/vm/runtime/reflectionUtils.hpp b/hotspot/src/share/vm/runtime/reflectionUtils.hpp index d51b2ab7874..71a500976a7 100644 --- a/hotspot/src/share/vm/runtime/reflectionUtils.hpp +++ b/hotspot/src/share/vm/runtime/reflectionUtils.hpp @@ -109,6 +109,8 @@ class FieldStream : public KlassStream { private: int length() const { return _klass->java_fields_count(); } + fieldDescriptor _fd_buf; + public: FieldStream(instanceKlassHandle klass, bool local_only, bool classes_only) : KlassStream(klass, local_only, classes_only) { @@ -134,6 +136,12 @@ class FieldStream : public KlassStream { int offset() const { return _klass->field_offset( index() ); } + // bridge to a heavier API: + fieldDescriptor& field_descriptor() const { + fieldDescriptor& field = const_cast(_fd_buf); + field.reinitialize(_klass(), _index); + return field; + } }; class FilteredField : public CHeapObj { diff --git a/hotspot/src/share/vm/runtime/vmStructs.cpp b/hotspot/src/share/vm/runtime/vmStructs.cpp index 448a8919f0e..55405b27fd4 100644 --- a/hotspot/src/share/vm/runtime/vmStructs.cpp +++ b/hotspot/src/share/vm/runtime/vmStructs.cpp @@ -315,7 +315,6 @@ typedef BinaryTreeDictionary MetablockTreeDictionary; nonstatic_field(InstanceKlass, _breakpoints, BreakpointInfo*) \ nonstatic_field(InstanceKlass, _generic_signature_index, u2) \ nonstatic_field(InstanceKlass, _methods_jmethod_ids, jmethodID*) \ - nonstatic_field(InstanceKlass, _methods_cached_itable_indices, int*) \ volatile_nonstatic_field(InstanceKlass, _idnum_allocated_count, u2) \ nonstatic_field(InstanceKlass, _annotations, Annotations*) \ nonstatic_field(InstanceKlass, _dependencies, nmethodBucket*) \ From 0a312ba2ce98432392b3fe7b9054c74f93e66631 Mon Sep 17 00:00:00 2001 From: Vicente Romero Date: Sat, 14 Sep 2013 15:23:21 +0100 Subject: [PATCH 166/210] 8024207: javac crash in Flow.AssignAnalyzer.visitIdent Reviewed-by: jjg --- .../com/sun/tools/javac/comp/Resolve.java | 2 +- .../tools/javac/T8024207/FlowCrashTest.java | 23 +++++++++++++++++++ .../tools/javac/T8024207/FlowCrashTest.out | 2 ++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 langtools/test/tools/javac/T8024207/FlowCrashTest.java create mode 100644 langtools/test/tools/javac/T8024207/FlowCrashTest.out diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java b/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java index f89bfed0161..e3c427413ec 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java @@ -2546,7 +2546,7 @@ public class Resolve { @Override Symbol access(Env env, DiagnosticPosition pos, Symbol location, Symbol sym) { if (sym.kind >= AMBIGUOUS) { - if (sym.kind == HIDDEN) { + if (sym.kind != WRONG_MTH && sym.kind != WRONG_MTHS) { sym = super.access(env, pos, location, sym); } else { final JCDiagnostic details = sym.kind == WRONG_MTH ? diff --git a/langtools/test/tools/javac/T8024207/FlowCrashTest.java b/langtools/test/tools/javac/T8024207/FlowCrashTest.java new file mode 100644 index 00000000000..5040c0ad448 --- /dev/null +++ b/langtools/test/tools/javac/T8024207/FlowCrashTest.java @@ -0,0 +1,23 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8024207 + * @summary javac crash in Flow$AssignAnalyzer.visitIdent + * @compile/fail/ref=FlowCrashTest.out -XDrawDiagnostics FlowCrashTest.java + */ + +import java.util.*; +import java.util.stream.*; + +public class FlowCrashTest { + static class ViewId { } + + public void crash() { + + Map viewToProfile = null; + new TreeMap<>(viewToProfile.entrySet().stream() + .collect(Collectors.toMap((vid, prn) -> prn, + (vid, prn) -> Arrays.asList(vid), + (a, b) -> { a.addAll(b); return a; }))); + + } +} diff --git a/langtools/test/tools/javac/T8024207/FlowCrashTest.out b/langtools/test/tools/javac/T8024207/FlowCrashTest.out new file mode 100644 index 00000000000..7eab7ccbb39 --- /dev/null +++ b/langtools/test/tools/javac/T8024207/FlowCrashTest.out @@ -0,0 +1,2 @@ +FlowCrashTest.java:18:42: compiler.err.cant.apply.symbols: kindname.method, toMap, @475,@542,@624,{(compiler.misc.inapplicable.method: kindname.method, java.util.stream.Collectors, toMap(java.util.function.Function,java.util.function.Function), (compiler.misc.infer.arg.length.mismatch: T,K,U)),(compiler.misc.inapplicable.method: kindname.method, java.util.stream.Collectors, toMap(java.util.function.Function,java.util.function.Function,java.util.function.BinaryOperator), (compiler.misc.infer.no.conforming.assignment.exists: T,K,U, (compiler.misc.incompatible.arg.types.in.lambda))),(compiler.misc.inapplicable.method: kindname.method, java.util.stream.Collectors, toMap(java.util.function.Function,java.util.function.Function,java.util.function.BinaryOperator,java.util.function.Supplier), (compiler.misc.infer.arg.length.mismatch: T,K,U,M))} +1 error From 86baa378e40350b45d474582e38bd5d87ab2b351 Mon Sep 17 00:00:00 2001 From: Vicente Romero Date: Sat, 14 Sep 2013 19:04:47 +0100 Subject: [PATCH 167/210] 7047734: javac, the LVT is not generated correctly in several scenarios Reviewed-by: jjg, mcimadamore --- .../com/sun/tools/javac/code/Lint.java | 5 - .../com/sun/tools/javac/comp/Flow.java | 563 ++++++++++++------ .../sun/tools/javac/comp/LambdaToMethod.java | 5 + .../com/sun/tools/javac/comp/Lower.java | 37 +- .../com/sun/tools/javac/comp/MemberEnter.java | 4 +- .../com/sun/tools/javac/comp/TransTypes.java | 2 +- .../com/sun/tools/javac/jvm/ClassWriter.java | 51 +- .../classes/com/sun/tools/javac/jvm/Code.java | 215 ++++++- .../classes/com/sun/tools/javac/jvm/Gen.java | 457 +++++++++++++- .../com/sun/tools/javac/jvm/Items.java | 8 +- .../com/sun/tools/javac/jvm/LVTRanges.java | 129 ++++ .../com/sun/tools/javac/tree/TreeMaker.java | 2 +- .../com/sun/tools/javac/util/Bits.java | 128 ++-- .../test/tools/javac/flow/AliveRanges.java | 34 ++ .../test/tools/javac/flow/LVTHarness.java | 280 +++++++++ .../javac/flow/tests/TestCaseConditional.java | 16 + .../javac/flow/tests/TestCaseDoLoop.java | 15 + .../tools/javac/flow/tests/TestCaseFor.java | 27 + .../javac/flow/tests/TestCaseForEach.java | 15 + .../tools/javac/flow/tests/TestCaseIf.java | 61 ++ .../javac/flow/tests/TestCaseIfElse.java | 48 ++ .../javac/flow/tests/TestCaseSwitch.java | 73 +++ .../tools/javac/flow/tests/TestCaseTry.java | 76 +++ .../tools/javac/flow/tests/TestCaseWhile.java | 15 + 24 files changed, 1888 insertions(+), 378 deletions(-) create mode 100644 langtools/src/share/classes/com/sun/tools/javac/jvm/LVTRanges.java create mode 100644 langtools/test/tools/javac/flow/AliveRanges.java create mode 100644 langtools/test/tools/javac/flow/LVTHarness.java create mode 100644 langtools/test/tools/javac/flow/tests/TestCaseConditional.java create mode 100644 langtools/test/tools/javac/flow/tests/TestCaseDoLoop.java create mode 100644 langtools/test/tools/javac/flow/tests/TestCaseFor.java create mode 100644 langtools/test/tools/javac/flow/tests/TestCaseForEach.java create mode 100644 langtools/test/tools/javac/flow/tests/TestCaseIf.java create mode 100644 langtools/test/tools/javac/flow/tests/TestCaseIfElse.java create mode 100644 langtools/test/tools/javac/flow/tests/TestCaseSwitch.java create mode 100644 langtools/test/tools/javac/flow/tests/TestCaseTry.java create mode 100644 langtools/test/tools/javac/flow/tests/TestCaseWhile.java diff --git a/langtools/src/share/classes/com/sun/tools/javac/code/Lint.java b/langtools/src/share/classes/com/sun/tools/javac/code/Lint.java index fb0ea30429f..9e1c4424fa8 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/code/Lint.java +++ b/langtools/src/share/classes/com/sun/tools/javac/code/Lint.java @@ -33,9 +33,6 @@ import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.Options; import com.sun.tools.javac.util.Pair; -import static com.sun.tools.javac.code.Flags.*; - - /** * A class for handling -Xlint suboptions and @SuppresssWarnings. * @@ -81,7 +78,6 @@ public class Lint return l; } - private final AugmentVisitor augmentor; private final EnumSet values; @@ -90,7 +86,6 @@ public class Lint private static final Map map = new java.util.concurrent.ConcurrentHashMap(20); - protected Lint(Context context) { // initialize values according to the lint options Options options = Options.instance(context); diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/Flow.java b/langtools/src/share/classes/com/sun/tools/javac/comp/Flow.java index 466436b6b9e..252124370e5 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Flow.java +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Flow.java @@ -207,7 +207,7 @@ public class Flow { public void analyzeTree(Env env, TreeMaker make) { new AliveAnalyzer().analyzeTree(env, make); - new AssignAnalyzer().analyzeTree(env, make); + new AssignAnalyzer(log, syms, lint, names).analyzeTree(env); new FlowAnalyzer().analyzeTree(env, make); new CaptureAnalyzer().analyzeTree(env, make); } @@ -239,7 +239,7 @@ public class Flow { //related errors, which will allow for more errors to be detected Log.DiagnosticHandler diagHandler = new Log.DiscardDiagnosticHandler(log); try { - new AssignAnalyzer().analyzeTree(env, that, make); + new AssignAnalyzer(log, syms, lint, names).analyzeTree(env); LambdaFlowAnalyzer flowAnalyzer = new LambdaFlowAnalyzer(); flowAnalyzer.analyzeTree(env, that, make); return flowAnalyzer.inferredThrownTypes; @@ -291,15 +291,6 @@ public class Flow { allowEffectivelyFinalInInnerClasses = source.allowEffectivelyFinalInInnerClasses(); } - /** - * Utility method to reset several Bits instances. - */ - private void resetBits(Bits... bits) { - for (Bits b : bits) { - b.reset(); - } - } - /** * Base visitor class for all visitors implementing dataflow analysis logic. * This class define the shared logic for handling jumps (break/continue statements). @@ -347,17 +338,17 @@ public class Flow { this.tree = tree; } - void resolveJump() { + void resolveJump(JCTree tree) { //do nothing } } - abstract void markDead(); + abstract void markDead(JCTree tree); /** Record an outward transfer of control. */ void recordExit(JCTree tree, P pe) { pendingExits.append(pe); - markDead(); + markDead(tree); } /** Resolve all jumps of this statement. */ @@ -371,7 +362,7 @@ public class Flow { P exit = exits.head; if (exit.tree.hasTag(jk.treeTag) && jk.getTarget(exit.tree) == tree) { - exit.resolveJump(); + exit.resolveJump(tree); resolved = true; } else { pendingExits.append(exit); @@ -380,12 +371,12 @@ public class Flow { return resolved; } - /** Resolve all breaks of this statement. */ + /** Resolve all continues of this statement. */ boolean resolveContinues(JCTree tree) { return resolveJump(tree, new ListBuffer

    (), JumpKind.CONTINUE); } - /** Resolve all continues of this statement. */ + /** Resolve all breaks of this statement. */ boolean resolveBreaks(JCTree tree, ListBuffer

    oldPendingExits) { return resolveJump(tree, oldPendingExits, JumpKind.BREAK); } @@ -414,7 +405,7 @@ public class Flow { private boolean alive; @Override - void markDead() { + void markDead(JCTree tree) { alive = false; } @@ -696,7 +687,7 @@ public class Flow { public void visitThrow(JCThrow tree) { scan(tree.expr); - markDead(); + markDead(tree); } public void visitApply(JCMethodInvocation tree) { @@ -797,7 +788,7 @@ public class Flow { } @Override - void markDead() { + void markDead(JCTree tree) { //do nothing } @@ -1222,7 +1213,7 @@ public class Flow { else { markThrown(tree, tree.expr.type); } - markDead(); + markDead(tree); } public void visitApply(JCMethodInvocation tree) { @@ -1372,11 +1363,13 @@ public class Flow { * depends on the results of the liveliness analyzer. This pass is also used to mark * effectively-final local variables/parameters. */ - class AssignAnalyzer extends BaseAnalyzer { + + public abstract static class AbstractAssignAnalyzer

    + extends BaseAnalyzer

    { /** The set of definitely assigned variables. */ - final Bits inits; + protected final Bits inits; /** The set of definitely unassigned variables. */ @@ -1402,7 +1395,7 @@ public class Flow { /** A mapping from addresses to variable symbols. */ - JCVariableDecl[] vardecls; + protected JCVariableDecl[] vardecls; /** The current class being defined. */ @@ -1414,11 +1407,11 @@ public class Flow { /** The next available variable sequence number. */ - int nextadr; + protected int nextadr; /** The first variable sequence number in a block that can return. */ - int returnadr; + protected int returnadr; /** The list of unreferenced automatic resources. */ @@ -1430,35 +1423,46 @@ public class Flow { /** The starting position of the analysed tree */ int startPos; - AssignAnalyzer() { - inits = new Bits(); + final Symtab syms; + + protected Names names; + + public static class AbstractAssignPendingExit extends BaseAnalyzer.PendingExit { + + final Bits inits; + final Bits uninits; + final Bits exit_inits = new Bits(true); + final Bits exit_uninits = new Bits(true); + + public AbstractAssignPendingExit(JCTree tree, final Bits inits, final Bits uninits) { + super(tree); + this.inits = inits; + this.uninits = uninits; + this.exit_inits.assign(inits); + this.exit_uninits.assign(uninits); + } + + @Override + public void resolveJump(JCTree tree) { + inits.andSet(exit_inits); + uninits.andSet(exit_uninits); + } + } + + public AbstractAssignAnalyzer(Bits inits, Symtab syms, Names names) { + this.inits = inits; uninits = new Bits(); uninitsTry = new Bits(); initsWhenTrue = new Bits(true); initsWhenFalse = new Bits(true); uninitsWhenTrue = new Bits(true); uninitsWhenFalse = new Bits(true); - } - - class AssignPendingExit extends BaseAnalyzer.PendingExit { - - final Bits exit_inits = new Bits(true); - final Bits exit_uninits = new Bits(true); - - AssignPendingExit(JCTree tree, final Bits inits, final Bits uninits) { - super(tree); - this.exit_inits.assign(inits); - this.exit_uninits.assign(uninits); - } - - void resolveJump() { - inits.andSet(exit_inits); - uninits.andSet(exit_uninits); - } + this.syms = syms; + this.names = names; } @Override - void markDead() { + protected void markDead(JCTree tree) { inits.inclRange(returnadr, nextadr); uninits.inclRange(returnadr, nextadr); } @@ -1468,7 +1472,7 @@ public class Flow { /** Do we need to track init/uninit state of this symbol? * I.e. is symbol either a local or a blank final variable? */ - boolean trackable(VarSymbol sym) { + protected boolean trackable(VarSymbol sym) { return sym.pos >= startPos && ((sym.owner.kind == MTH || @@ -1488,44 +1492,35 @@ public class Flow { } sym.adr = nextadr; vardecls[nextadr] = varDecl; - inits.excl(nextadr); + exclVarFromInits(varDecl, nextadr); uninits.incl(nextadr); nextadr++; } + protected void exclVarFromInits(JCTree tree, int adr) { + inits.excl(adr); + } + + protected void assignToInits(JCTree tree, Bits bits) { + inits.assign(bits); + } + + protected void andSetInits(JCTree tree, Bits bits) { + inits.andSet(bits); + } + + protected void orSetInits(JCTree tree, Bits bits) { + inits.orSet(bits); + } + /** Record an initialization of a trackable variable. */ void letInit(DiagnosticPosition pos, VarSymbol sym) { if (sym.adr >= firstadr && trackable(sym)) { - if ((sym.flags() & EFFECTIVELY_FINAL) != 0) { - if (!uninits.isMember(sym.adr)) { - //assignment targeting an effectively final variable - //makes the variable lose its status of effectively final - //if the variable is _not_ definitively unassigned - sym.flags_field &= ~EFFECTIVELY_FINAL; - } else { - uninit(sym); - } - } - else if ((sym.flags() & FINAL) != 0) { - if ((sym.flags() & PARAMETER) != 0) { - if ((sym.flags() & UNION) != 0) { //multi-catch parameter - log.error(pos, "multicatch.parameter.may.not.be.assigned", - sym); - } - else { - log.error(pos, "final.parameter.may.not.be.assigned", - sym); - } - } else if (!uninits.isMember(sym.adr)) { - log.error(pos, flowKind.errKey, sym); - } else { - uninit(sym); - } + if (uninits.isMember(sym.adr)) { + uninit(sym); } inits.incl(sym.adr); - } else if ((sym.flags() & FINAL) != 0) { - log.error(pos, "var.might.already.be.assigned", sym); } } //where @@ -1559,12 +1554,14 @@ public class Flow { void checkInit(DiagnosticPosition pos, VarSymbol sym) { checkInit(pos, sym, "var.might.not.have.been.initialized"); } - void checkInit(DiagnosticPosition pos, VarSymbol sym, String errkey) { - if ((sym.adr >= firstadr || sym.owner.kind != TYP) && - trackable(sym) && - !inits.isMember(sym.adr)) { - log.error(pos, errkey, sym); - inits.incl(sym.adr); + + void checkInit(DiagnosticPosition pos, VarSymbol sym, String errkey) {} + + /** Utility method to reset several Bits instances. + */ + private void resetBits(Bits... bits) { + for (Bits b : bits) { + b.reset(); } } @@ -1582,7 +1579,7 @@ public class Flow { /** Merge (intersect) inits/uninits from WhenTrue/WhenFalse sets. */ - void merge() { + protected void merge(JCTree tree) { inits.assign(initsWhenFalse.andSet(initsWhenTrue)); uninits.assign(uninitsWhenFalse.andSet(uninitsWhenTrue)); } @@ -1597,7 +1594,9 @@ public class Flow { void scanExpr(JCTree tree) { if (tree != null) { scan(tree); - if (inits.isReset()) merge(); + if (inits.isReset()) { + merge(tree); + } } } @@ -1614,7 +1613,7 @@ public class Flow { */ void scanCond(JCTree tree) { if (tree.type.isFalse()) { - if (inits.isReset()) merge(); + if (inits.isReset()) merge(tree); initsWhenTrue.assign(inits); initsWhenTrue.inclRange(firstadr, nextadr); uninitsWhenTrue.assign(uninits); @@ -1622,7 +1621,7 @@ public class Flow { initsWhenFalse.assign(inits); uninitsWhenFalse.assign(uninits); } else if (tree.type.isTrue()) { - if (inits.isReset()) merge(); + if (inits.isReset()) merge(tree); initsWhenFalse.assign(inits); initsWhenFalse.inclRange(firstadr, nextadr); uninitsWhenFalse.assign(uninits); @@ -1641,22 +1640,22 @@ public class Flow { /* ------------ Visitor methods for various sorts of trees -------------*/ + @Override public void visitClassDef(JCClassDecl tree) { - if (tree.sym == null) return; + if (tree.sym == null) { + return; + } JCClassDecl classDefPrev = classDef; int firstadrPrev = firstadr; int nextadrPrev = nextadr; - ListBuffer pendingExitsPrev = pendingExits; - Lint lintPrev = lint; + ListBuffer

    pendingExitsPrev = pendingExits; - pendingExits = new ListBuffer(); + pendingExits = new ListBuffer

    (); if (tree.name != names.empty) { firstadr = nextadr; } classDef = tree; - lint = lint.augment(tree.sym); - try { // define all the static fields for (List l = tree.defs; l.nonEmpty(); l = l.tail) { @@ -1664,8 +1663,9 @@ public class Flow { JCVariableDecl def = (JCVariableDecl)l.head; if ((def.mods.flags & STATIC) != 0) { VarSymbol sym = def.sym; - if (trackable(sym)) + if (trackable(sym)) { newVar(def); + } } } } @@ -1684,8 +1684,9 @@ public class Flow { JCVariableDecl def = (JCVariableDecl)l.head; if ((def.mods.flags & STATIC) == 0) { VarSymbol sym = def.sym; - if (trackable(sym)) + if (trackable(sym)) { newVar(def); + } } } } @@ -1709,21 +1710,25 @@ public class Flow { nextadr = nextadrPrev; firstadr = firstadrPrev; classDef = classDefPrev; - lint = lintPrev; } } + @Override public void visitMethodDef(JCMethodDecl tree) { - if (tree.body == null) return; + if (tree.body == null) { + return; + } + /* MemberEnter can generate synthetic methods, ignore them + */ + if ((tree.sym.flags() & SYNTHETIC) != 0) { + return; + } final Bits initsPrev = new Bits(inits); final Bits uninitsPrev = new Bits(uninits); int nextadrPrev = nextadr; int firstadrPrev = firstadr; int returnadrPrev = returnadr; - Lint lintPrev = lint; - - lint = lint.augment(tree.sym); Assert.check(pendingExits.isEmpty()); @@ -1731,13 +1736,17 @@ public class Flow { boolean isInitialConstructor = TreeInfo.isInitialConstructor(tree); - if (!isInitialConstructor) + if (!isInitialConstructor) { firstadr = nextadr; + } for (List l = tree.params; l.nonEmpty(); l = l.tail) { JCVariableDecl def = l.head; scan(def); - inits.incl(def.sym.adr); - uninits.excl(def.sym.adr); + Assert.check((def.sym.flags() & PARAMETER) != 0, "Method parameter without PARAMETER flag"); + /* If we are executing the code from Gen, then there can be + * synthetic or mandated variables, ignore them. + */ + initParam(def); } // else we are in an instance initializer block; // leave caught unchanged. @@ -1761,39 +1770,42 @@ public class Flow { } } } - List exits = pendingExits.toList(); - pendingExits = new ListBuffer(); + List

    exits = pendingExits.toList(); + pendingExits = new ListBuffer<>(); while (exits.nonEmpty()) { - AssignPendingExit exit = exits.head; + P exit = exits.head; exits = exits.tail; Assert.check(exit.tree.hasTag(RETURN), exit.tree); if (isInitialConstructor) { - inits.assign(exit.exit_inits); - for (int i = firstadr; i < nextadr; i++) + assignToInits(exit.tree, exit.exit_inits); + for (int i = firstadr; i < nextadr; i++) { checkInit(exit.tree.pos(), vardecls[i].sym); + } } } } finally { - inits.assign(initsPrev); + assignToInits(tree, initsPrev); uninits.assign(uninitsPrev); nextadr = nextadrPrev; firstadr = firstadrPrev; returnadr = returnadrPrev; - lint = lintPrev; } } + protected void initParam(JCVariableDecl def) { + inits.incl(def.sym.adr); + uninits.excl(def.sym.adr); + } + public void visitVarDef(JCVariableDecl tree) { boolean track = trackable(tree.sym); - if (track && tree.sym.owner.kind == MTH) newVar(tree); + if (track && tree.sym.owner.kind == MTH) { + newVar(tree); + } if (tree.init != null) { - Lint lintPrev = lint; - lint = lint.augment(tree.sym); - try{ - scanExpr(tree.init); - if (track) letInit(tree.pos(), tree.sym); - } finally { - lint = lintPrev; + scanExpr(tree.init); + if (track) { + letInit(tree.pos(), tree.sym); } } } @@ -1804,14 +1816,18 @@ public class Flow { nextadr = nextadrPrev; } + int getLogNumberOfErrors() { + return 0; + } + public void visitDoLoop(JCDoWhileLoop tree) { - ListBuffer prevPendingExits = pendingExits; + ListBuffer

    prevPendingExits = pendingExits; FlowKind prevFlowKind = flowKind; flowKind = FlowKind.NORMAL; final Bits initsSkip = new Bits(true); final Bits uninitsSkip = new Bits(true); - pendingExits = new ListBuffer(); - int prevErrors = log.nerrors; + pendingExits = new ListBuffer

    (); + int prevErrors = getLogNumberOfErrors(); do { final Bits uninitsEntry = new Bits(uninits); uninitsEntry.excludeFrom(nextadr); @@ -1822,28 +1838,28 @@ public class Flow { initsSkip.assign(initsWhenFalse); uninitsSkip.assign(uninitsWhenFalse); } - if (log.nerrors != prevErrors || + if (getLogNumberOfErrors() != prevErrors || flowKind.isFinal() || new Bits(uninitsEntry).diffSet(uninitsWhenTrue).nextBit(firstadr)==-1) break; - inits.assign(initsWhenTrue); + assignToInits(tree.cond, initsWhenTrue); uninits.assign(uninitsEntry.andSet(uninitsWhenTrue)); flowKind = FlowKind.SPECULATIVE_LOOP; } while (true); flowKind = prevFlowKind; - inits.assign(initsSkip); + assignToInits(tree, initsSkip); uninits.assign(uninitsSkip); resolveBreaks(tree, prevPendingExits); } public void visitWhileLoop(JCWhileLoop tree) { - ListBuffer prevPendingExits = pendingExits; + ListBuffer

    prevPendingExits = pendingExits; FlowKind prevFlowKind = flowKind; flowKind = FlowKind.NORMAL; final Bits initsSkip = new Bits(true); final Bits uninitsSkip = new Bits(true); - pendingExits = new ListBuffer(); - int prevErrors = log.nerrors; + pendingExits = new ListBuffer<>(); + int prevErrors = getLogNumberOfErrors(); final Bits uninitsEntry = new Bits(uninits); uninitsEntry.excludeFrom(nextadr); do { @@ -1852,35 +1868,36 @@ public class Flow { initsSkip.assign(initsWhenFalse) ; uninitsSkip.assign(uninitsWhenFalse); } - inits.assign(initsWhenTrue); + assignToInits(tree, initsWhenTrue); uninits.assign(uninitsWhenTrue); scan(tree.body); resolveContinues(tree); - if (log.nerrors != prevErrors || + if (getLogNumberOfErrors() != prevErrors || flowKind.isFinal() || - new Bits(uninitsEntry).diffSet(uninits).nextBit(firstadr) == -1) + new Bits(uninitsEntry).diffSet(uninits).nextBit(firstadr) == -1) { break; + } uninits.assign(uninitsEntry.andSet(uninits)); flowKind = FlowKind.SPECULATIVE_LOOP; } while (true); flowKind = prevFlowKind; //a variable is DA/DU after the while statement, if it's DA/DU assuming the //branch is not taken AND if it's DA/DU before any break statement - inits.assign(initsSkip); + assignToInits(tree.body, initsSkip); uninits.assign(uninitsSkip); resolveBreaks(tree, prevPendingExits); } public void visitForLoop(JCForLoop tree) { - ListBuffer prevPendingExits = pendingExits; + ListBuffer

    prevPendingExits = pendingExits; FlowKind prevFlowKind = flowKind; flowKind = FlowKind.NORMAL; int nextadrPrev = nextadr; scan(tree.init); final Bits initsSkip = new Bits(true); final Bits uninitsSkip = new Bits(true); - pendingExits = new ListBuffer(); - int prevErrors = log.nerrors; + pendingExits = new ListBuffer

    (); + int prevErrors = getLogNumberOfErrors(); do { final Bits uninitsEntry = new Bits(uninits); uninitsEntry.excludeFrom(nextadr); @@ -1890,7 +1907,7 @@ public class Flow { initsSkip.assign(initsWhenFalse); uninitsSkip.assign(uninitsWhenFalse); } - inits.assign(initsWhenTrue); + assignToInits(tree.body, initsWhenTrue); uninits.assign(uninitsWhenTrue); } else if (!flowKind.isFinal()) { initsSkip.assign(inits); @@ -1901,7 +1918,7 @@ public class Flow { scan(tree.body); resolveContinues(tree); scan(tree.step); - if (log.nerrors != prevErrors || + if (getLogNumberOfErrors() != prevErrors || flowKind.isFinal() || new Bits(uninitsEntry).diffSet(uninits).nextBit(firstadr) == -1) break; @@ -1911,7 +1928,7 @@ public class Flow { flowKind = prevFlowKind; //a variable is DA/DU after a for loop, if it's DA/DU assuming the //branch is not taken AND if it's DA/DU before any break statement - inits.assign(initsSkip); + assignToInits(tree.body, initsSkip); uninits.assign(uninitsSkip); resolveBreaks(tree, prevPendingExits); nextadr = nextadrPrev; @@ -1920,7 +1937,7 @@ public class Flow { public void visitForeachLoop(JCEnhancedForLoop tree) { visitVarDef(tree.var); - ListBuffer prevPendingExits = pendingExits; + ListBuffer

    prevPendingExits = pendingExits; FlowKind prevFlowKind = flowKind; flowKind = FlowKind.NORMAL; int nextadrPrev = nextadr; @@ -1929,14 +1946,14 @@ public class Flow { final Bits uninitsStart = new Bits(uninits); letInit(tree.pos(), tree.var.sym); - pendingExits = new ListBuffer(); - int prevErrors = log.nerrors; + pendingExits = new ListBuffer

    (); + int prevErrors = getLogNumberOfErrors(); do { final Bits uninitsEntry = new Bits(uninits); uninitsEntry.excludeFrom(nextadr); scan(tree.body); resolveContinues(tree); - if (log.nerrors != prevErrors || + if (getLogNumberOfErrors() != prevErrors || flowKind.isFinal() || new Bits(uninitsEntry).diffSet(uninits).nextBit(firstadr) == -1) break; @@ -1944,41 +1961,50 @@ public class Flow { flowKind = FlowKind.SPECULATIVE_LOOP; } while (true); flowKind = prevFlowKind; - inits.assign(initsStart); + assignToInits(tree.body, initsStart); uninits.assign(uninitsStart.andSet(uninits)); resolveBreaks(tree, prevPendingExits); nextadr = nextadrPrev; } public void visitLabelled(JCLabeledStatement tree) { - ListBuffer prevPendingExits = pendingExits; - pendingExits = new ListBuffer(); + ListBuffer

    prevPendingExits = pendingExits; + pendingExits = new ListBuffer

    (); scan(tree.body); resolveBreaks(tree, prevPendingExits); } public void visitSwitch(JCSwitch tree) { - ListBuffer prevPendingExits = pendingExits; - pendingExits = new ListBuffer(); + ListBuffer

    prevPendingExits = pendingExits; + pendingExits = new ListBuffer<>(); int nextadrPrev = nextadr; scanExpr(tree.selector); final Bits initsSwitch = new Bits(inits); final Bits uninitsSwitch = new Bits(uninits); boolean hasDefault = false; for (List l = tree.cases; l.nonEmpty(); l = l.tail) { - inits.assign(initsSwitch); + assignToInits(l.head, initsSwitch); uninits.assign(uninits.andSet(uninitsSwitch)); JCCase c = l.head; - if (c.pat == null) + if (c.pat == null) { hasDefault = true; - else + } else { scanExpr(c.pat); + } + if (hasDefault) { + assignToInits(null, initsSwitch); + uninits.assign(uninits.andSet(uninitsSwitch)); + } scan(c.stats); addVars(c.stats, initsSwitch, uninitsSwitch); + if (!hasDefault) { + assignToInits(l.head.stats.last(), initsSwitch); + uninits.assign(uninits.andSet(uninitsSwitch)); + } // Warn about fall-through if lint switch fallthrough enabled. } if (!hasDefault) { - inits.andSet(initsSwitch); + andSetInits(null, initsSwitch); } resolveBreaks(tree, prevPendingExits); nextadr = nextadrPrev; @@ -1997,11 +2023,17 @@ public class Flow { } } + boolean isEnabled(Lint.LintCategory lc) { + return false; + } + + void reportWarning(Lint.LintCategory lc, DiagnosticPosition pos, String key, Object ... args) {} + public void visitTry(JCTry tree) { ListBuffer resourceVarDecls = ListBuffer.lb(); final Bits uninitsTryPrev = new Bits(uninitsTry); - ListBuffer prevPendingExits = pendingExits; - pendingExits = new ListBuffer(); + ListBuffer

    prevPendingExits = pendingExits; + pendingExits = new ListBuffer<>(); final Bits initsTry = new Bits(inits); uninitsTry.assign(uninits); for (JCTree resource : tree.resources) { @@ -2023,10 +2055,10 @@ public class Flow { int nextadrCatch = nextadr; if (!resourceVarDecls.isEmpty() && - lint.isEnabled(Lint.LintCategory.TRY)) { + isEnabled(Lint.LintCategory.TRY)) { for (JCVariableDecl resVar : resourceVarDecls) { if (unrefdResources.includes(resVar.sym)) { - log.warning(Lint.LintCategory.TRY, resVar.pos(), + reportWarning(Lint.LintCategory.TRY, resVar.pos(), "try.resource.not.referenced", resVar.sym); unrefdResources.remove(resVar.sym); } @@ -2042,20 +2074,22 @@ public class Flow { for (List l = tree.catchers; l.nonEmpty(); l = l.tail) { JCVariableDecl param = l.head.param; - inits.assign(initsCatchPrev); + assignToInits(tree.body, initsCatchPrev); uninits.assign(uninitsCatchPrev); scan(param); - inits.incl(param.sym.adr); - uninits.excl(param.sym.adr); + /* If this is a TWR and we are executing the code from Gen, + * then there can be synthetic variables, ignore them. + */ + initParam(param); scan(l.head.body); initsEnd.andSet(inits); uninitsEnd.andSet(uninits); nextadr = nextadrCatch; } if (tree.finalizer != null) { - inits.assign(initsTry); + assignToInits(tree.finalizer, initsTry); uninits.assign(uninitsTry); - ListBuffer exits = pendingExits; + ListBuffer

    exits = pendingExits; pendingExits = prevPendingExits; scan(tree.finalizer); if (!tree.finallyCanCompleteNormally) { @@ -2065,19 +2099,19 @@ public class Flow { // FIX: this doesn't preserve source order of exits in catch // versus finally! while (exits.nonEmpty()) { - AssignPendingExit exit = exits.next(); + P exit = exits.next(); if (exit.exit_inits != null) { exit.exit_inits.orSet(inits); exit.exit_uninits.andSet(uninits); } pendingExits.append(exit); } - inits.orSet(initsEnd); + orSetInits(tree, initsEnd); } } else { - inits.assign(initsEnd); + assignToInits(tree, initsEnd); uninits.assign(uninitsEnd); - ListBuffer exits = pendingExits; + ListBuffer

    exits = pendingExits; pendingExits = prevPendingExits; while (exits.nonEmpty()) pendingExits.append(exits.next()); } @@ -2088,7 +2122,7 @@ public class Flow { scanCond(tree.cond); final Bits initsBeforeElse = new Bits(initsWhenFalse); final Bits uninitsBeforeElse = new Bits(uninitsWhenFalse); - inits.assign(initsWhenTrue); + assignToInits(tree.cond, initsWhenTrue); uninits.assign(uninitsWhenTrue); if (tree.truepart.type.hasTag(BOOLEAN) && tree.falsepart.type.hasTag(BOOLEAN)) { @@ -2101,7 +2135,7 @@ public class Flow { final Bits initsAfterThenWhenFalse = new Bits(initsWhenFalse); final Bits uninitsAfterThenWhenTrue = new Bits(uninitsWhenTrue); final Bits uninitsAfterThenWhenFalse = new Bits(uninitsWhenFalse); - inits.assign(initsBeforeElse); + assignToInits(tree.truepart, initsBeforeElse); uninits.assign(uninitsBeforeElse); scanCond(tree.falsepart); initsWhenTrue.andSet(initsAfterThenWhenTrue); @@ -2112,10 +2146,10 @@ public class Flow { scanExpr(tree.truepart); final Bits initsAfterThen = new Bits(inits); final Bits uninitsAfterThen = new Bits(uninits); - inits.assign(initsBeforeElse); + assignToInits(tree.truepart, initsBeforeElse); uninits.assign(uninitsBeforeElse); scanExpr(tree.falsepart); - inits.andSet(initsAfterThen); + andSetInits(tree.falsepart, initsAfterThen); uninits.andSet(uninitsAfterThen); } } @@ -2124,39 +2158,46 @@ public class Flow { scanCond(tree.cond); final Bits initsBeforeElse = new Bits(initsWhenFalse); final Bits uninitsBeforeElse = new Bits(uninitsWhenFalse); - inits.assign(initsWhenTrue); + assignToInits(tree.cond, initsWhenTrue); uninits.assign(uninitsWhenTrue); scan(tree.thenpart); if (tree.elsepart != null) { final Bits initsAfterThen = new Bits(inits); final Bits uninitsAfterThen = new Bits(uninits); - inits.assign(initsBeforeElse); + assignToInits(tree.thenpart, initsBeforeElse); uninits.assign(uninitsBeforeElse); scan(tree.elsepart); - inits.andSet(initsAfterThen); + andSetInits(tree.elsepart, initsAfterThen); uninits.andSet(uninitsAfterThen); } else { - inits.andSet(initsBeforeElse); + andSetInits(tree.thenpart, initsBeforeElse); uninits.andSet(uninitsBeforeElse); } } + protected P createNewPendingExit(JCTree tree, Bits inits, Bits uninits) { + return null; + } + + @Override public void visitBreak(JCBreak tree) { - recordExit(tree, new AssignPendingExit(tree, inits, uninits)); + recordExit(tree, createNewPendingExit(tree, inits, uninits)); } + @Override public void visitContinue(JCContinue tree) { - recordExit(tree, new AssignPendingExit(tree, inits, uninits)); + recordExit(tree, createNewPendingExit(tree, inits, uninits)); } + @Override public void visitReturn(JCReturn tree) { scanExpr(tree.expr); - recordExit(tree, new AssignPendingExit(tree, inits, uninits)); + recordExit(tree, createNewPendingExit(tree, inits, uninits)); } public void visitThrow(JCThrow tree) { scanExpr(tree.expr); - markDead(); + markDead(tree.expr); } public void visitApply(JCMethodInvocation tree) { @@ -2175,10 +2216,10 @@ public class Flow { final Bits prevUninits = new Bits(uninits); final Bits prevInits = new Bits(inits); int returnadrPrev = returnadr; - ListBuffer prevPending = pendingExits; + ListBuffer

    prevPending = pendingExits; try { returnadr = nextadr; - pendingExits = new ListBuffer(); + pendingExits = new ListBuffer

    (); for (List l = tree.params; l.nonEmpty(); l = l.tail) { JCVariableDecl def = l.head; scan(def); @@ -2194,7 +2235,7 @@ public class Flow { finally { returnadr = returnadrPrev; uninits.assign(prevUninits); - inits.assign(prevInits); + assignToInits(tree, prevInits); pendingExits = prevPending; } } @@ -2210,11 +2251,11 @@ public class Flow { scanCond(tree.cond); uninitsExit.andSet(uninitsWhenTrue); if (tree.detail != null) { - inits.assign(initsWhenFalse); + assignToInits(tree, initsWhenFalse); uninits.assign(uninitsWhenFalse); scanExpr(tree.detail); } - inits.assign(initsExit); + assignToInits(tree, initsExit); uninits.assign(uninitsExit); } @@ -2260,7 +2301,7 @@ public class Flow { scanCond(tree.lhs); final Bits initsWhenFalseLeft = new Bits(initsWhenFalse); final Bits uninitsWhenFalseLeft = new Bits(uninitsWhenFalse); - inits.assign(initsWhenTrue); + assignToInits(tree.lhs, initsWhenTrue); uninits.assign(uninitsWhenTrue); scanCond(tree.rhs); initsWhenFalse.andSet(initsWhenFalseLeft); @@ -2270,7 +2311,7 @@ public class Flow { scanCond(tree.lhs); final Bits initsWhenTrueLeft = new Bits(initsWhenTrue); final Bits uninitsWhenTrueLeft = new Bits(uninitsWhenTrue); - inits.assign(initsWhenFalse); + assignToInits(tree.lhs, initsWhenFalse); uninits.assign(uninitsWhenFalse); scanCond(tree.rhs); initsWhenTrue.andSet(initsWhenTrueLeft); @@ -2308,14 +2349,12 @@ public class Flow { /** Perform definite assignment/unassignment analysis on a tree. */ - public void analyzeTree(Env env, TreeMaker make) { - analyzeTree(env, env.tree, make); - } + public void analyzeTree(Env env) { + analyzeTree(env, env.tree); + } - public void analyzeTree(Env env, JCTree tree, TreeMaker make) { + public void analyzeTree(Env env, JCTree tree) { try { - attrEnv = env; - Flow.this.make = make; startPos = tree.pos().getStartPosition(); if (vardecls == null) @@ -2325,7 +2364,7 @@ public class Flow { vardecls[i] = null; firstadr = 0; nextadr = 0; - pendingExits = new ListBuffer(); + pendingExits = new ListBuffer<>(); this.classDef = null; unrefdResources = new Scope(env.enclClass.sym); scan(tree); @@ -2334,18 +2373,160 @@ public class Flow { startPos = -1; resetBits(inits, uninits, uninitsTry, initsWhenTrue, initsWhenFalse, uninitsWhenTrue, uninitsWhenFalse); - if (vardecls != null) for (int i=0; i { + + Log log; + Lint lint; + + public static class AssignPendingExit + extends AbstractAssignAnalyzer.AbstractAssignPendingExit { + + public AssignPendingExit(JCTree tree, final Bits inits, final Bits uninits) { + super(tree, inits, uninits); + } + } + + public AssignAnalyzer(Log log, Symtab syms, Lint lint, Names names) { + super(new Bits(), syms, names); + this.log = log; + this.lint = lint; + } + + @Override + protected AssignPendingExit createNewPendingExit(JCTree tree, + Bits inits, Bits uninits) { + return new AssignPendingExit(tree, inits, uninits); + } + + /** Record an initialization of a trackable variable. + */ + @Override + void letInit(DiagnosticPosition pos, VarSymbol sym) { + if (sym.adr >= firstadr && trackable(sym)) { + if ((sym.flags() & EFFECTIVELY_FINAL) != 0) { + if (!uninits.isMember(sym.adr)) { + //assignment targeting an effectively final variable + //makes the variable lose its status of effectively final + //if the variable is _not_ definitively unassigned + sym.flags_field &= ~EFFECTIVELY_FINAL; + } else { + uninit(sym); + } + } + else if ((sym.flags() & FINAL) != 0) { + if ((sym.flags() & PARAMETER) != 0) { + if ((sym.flags() & UNION) != 0) { //multi-catch parameter + log.error(pos, "multicatch.parameter.may.not.be.assigned", sym); + } + else { + log.error(pos, "final.parameter.may.not.be.assigned", + sym); + } + } else if (!uninits.isMember(sym.adr)) { + log.error(pos, flowKind.errKey, sym); + } else { + uninit(sym); + } + } + inits.incl(sym.adr); + } else if ((sym.flags() & FINAL) != 0) { + log.error(pos, "var.might.already.be.assigned", sym); + } + } + + @Override + void checkInit(DiagnosticPosition pos, VarSymbol sym, String errkey) { + if ((sym.adr >= firstadr || sym.owner.kind != TYP) && + trackable(sym) && + !inits.isMember(sym.adr)) { + log.error(pos, errkey, sym); + inits.incl(sym.adr); + } + } + + @Override + void reportWarning(Lint.LintCategory lc, DiagnosticPosition pos, + String key, Object ... args) { + log.warning(lc, pos, key, args); + } + + @Override + int getLogNumberOfErrors() { + return log.nerrors; + } + + @Override + boolean isEnabled(Lint.LintCategory lc) { + return lint.isEnabled(lc); + } + + @Override + public void visitClassDef(JCClassDecl tree) { + if (tree.sym == null) { + return; + } + + Lint lintPrev = lint; + lint = lint.augment(tree.sym); + try { + super.visitClassDef(tree); + } finally { + lint = lintPrev; + } + } + + @Override + public void visitMethodDef(JCMethodDecl tree) { + if (tree.body == null) { + return; + } + + /* MemberEnter can generate synthetic methods ignore them + */ + if ((tree.sym.flags() & SYNTHETIC) != 0) { + return; + } + + Lint lintPrev = lint; + lint = lint.augment(tree.sym); + try { + super.visitMethodDef(tree); + } finally { + lint = lintPrev; + } + } + + @Override + public void visitVarDef(JCVariableDecl tree) { + if (tree.init == null) { + super.visitVarDef(tree); + } else { + Lint lintPrev = lint; + lint = lint.augment(tree.sym); + try{ + super.visitVarDef(tree); + } finally { + lint = lintPrev; + } + } + } + + } + /** * This pass implements the last step of the dataflow analysis, namely * the effectively-final analysis check. This checks that every local variable @@ -2358,7 +2539,7 @@ public class Flow { JCTree currentTree; //local class or lambda @Override - void markDead() { + void markDead(JCTree tree) { //do nothing } diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java b/langtools/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java index 7633f96d1df..b2a501d27d6 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java @@ -1745,6 +1745,11 @@ public class LambdaToMethod extends TreeTranslator { // Just erase the type var ret = new VarSymbol(sym.flags(), name, types.erasure(sym.type), sym.owner); + + /* this information should also be kept for LVT generation at Gen + * a Symbol with pos < startPos won't be tracked. + */ + ((VarSymbol)ret).pos = ((VarSymbol)sym).pos; break; case CAPTURED_VAR: ret = new VarSymbol(SYNTHETIC | FINAL, name, types.erasure(sym.type), translatedSym) { diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/Lower.java b/langtools/src/share/classes/com/sun/tools/javac/comp/Lower.java index 5926a1b68c1..cb054fe80f2 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Lower.java +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Lower.java @@ -1479,7 +1479,12 @@ public class Lower extends TreeTranslator { * @param owner The class in which the definitions go. */ List freevarDefs(int pos, List freevars, Symbol owner) { - long flags = FINAL | SYNTHETIC; + return freevarDefs(pos, freevars, owner, 0); + } + + List freevarDefs(int pos, List freevars, Symbol owner, + long additionalFlags) { + long flags = FINAL | SYNTHETIC | additionalFlags; if (owner.kind == TYP && target.usePrivateSyntheticFields()) flags |= PRIVATE; @@ -1542,7 +1547,7 @@ public class Lower extends TreeTranslator { (owner.isConstructor() && c.isInner() && !c.isPrivate() && !c.isStatic()); long flags = - FINAL | (isMandated ? MANDATED : SYNTHETIC); + FINAL | (isMandated ? MANDATED : SYNTHETIC) | PARAMETER; VarSymbol outerThis = makeOuterThisVarSymbol(owner, flags); owner.extraParams = owner.extraParams.prepend(outerThis); return makeOuterThisVarDecl(pos, outerThis); @@ -1626,7 +1631,8 @@ public class Lower extends TreeTranslator { JCTree makeTwrTry(JCTry tree) { make_at(tree.pos()); twrVars = twrVars.dup(); - JCBlock twrBlock = makeTwrBlock(tree.resources, tree.body, 0); + JCBlock twrBlock = makeTwrBlock(tree.resources, tree.body, + tree.finallyCanCompleteNormally, 0); if (tree.catchers.isEmpty() && tree.finalizer == null) result = translate(twrBlock); else @@ -1635,7 +1641,8 @@ public class Lower extends TreeTranslator { return result; } - private JCBlock makeTwrBlock(List resources, JCBlock block, int depth) { + private JCBlock makeTwrBlock(List resources, JCBlock block, + boolean finallyCanCompleteNormally, int depth) { if (resources.isEmpty()) return block; @@ -1691,17 +1698,20 @@ public class Lower extends TreeTranslator { make.at(TreeInfo.endPos(block)); JCBlock finallyClause = makeTwrFinallyClause(primaryException, expr); make.at(oldPos); - JCTry outerTry = make.Try(makeTwrBlock(resources.tail, block, depth + 1), + JCTry outerTry = make.Try(makeTwrBlock(resources.tail, block, + finallyCanCompleteNormally, depth + 1), List.of(catchClause), finallyClause); + outerTry.finallyCanCompleteNormally = finallyCanCompleteNormally; stats.add(outerTry); - return make.Block(0L, stats.toList()); + JCBlock newBlock = make.Block(0L, stats.toList()); + return newBlock; } private JCBlock makeTwrFinallyClause(Symbol primaryException, JCExpression resource) { // primaryException.addSuppressed(catchException); VarSymbol catchException = - new VarSymbol(0, make.paramName(2), + new VarSymbol(SYNTHETIC, make.paramName(2), syms.throwableType, currentMethodSym); JCStatement addSuppressionStatement = @@ -1716,6 +1726,7 @@ public class Lower extends TreeTranslator { JCBlock catchBlock = make.Block(0L, List.of(addSuppressionStatement)); List catchClauses = List.of(make.Catch(catchExceptionDecl, catchBlock)); JCTry tryTree = make.Try(tryBlock, catchClauses, null); + tryTree.finallyCanCompleteNormally = true; // if (primaryException != null) {try...} else resourceClose; JCIf closeIfStatement = make.If(makeNonNullCheck(make.Ident(primaryException)), @@ -2016,7 +2027,7 @@ public class Lower extends TreeTranslator { // catchParam := ClassNotFoundException e1 VarSymbol catchParam = - new VarSymbol(0, make.paramName(1), + new VarSymbol(SYNTHETIC, make.paramName(1), syms.classNotFoundExceptionType, classDollarSym); @@ -2704,7 +2715,7 @@ public class Lower extends TreeTranslator { JCVariableDecl otdef = null; if (currentClass.hasOuterInstance()) otdef = outerThisDef(tree.pos, m); - List fvdefs = freevarDefs(tree.pos, fvs, m); + List fvdefs = freevarDefs(tree.pos, fvs, m, PARAMETER); // Recursively translate result type, parameters and thrown list. tree.restype = translate(tree.restype); @@ -3363,18 +3374,18 @@ public class Lower extends TreeTranslator { */ private void visitArrayForeachLoop(JCEnhancedForLoop tree) { make_at(tree.expr.pos()); - VarSymbol arraycache = new VarSymbol(0, + VarSymbol arraycache = new VarSymbol(SYNTHETIC, names.fromString("arr" + target.syntheticNameChar()), tree.expr.type, currentMethodSym); JCStatement arraycachedef = make.VarDef(arraycache, tree.expr); - VarSymbol lencache = new VarSymbol(0, + VarSymbol lencache = new VarSymbol(SYNTHETIC, names.fromString("len" + target.syntheticNameChar()), syms.intType, currentMethodSym); JCStatement lencachedef = make. VarDef(lencache, make.Select(make.Ident(arraycache), syms.lengthVar)); - VarSymbol index = new VarSymbol(0, + VarSymbol index = new VarSymbol(SYNTHETIC, names.fromString("i" + target.syntheticNameChar()), syms.intType, currentMethodSym); @@ -3456,7 +3467,7 @@ public class Lower extends TreeTranslator { names.iterator, eType, List.nil()); - VarSymbol itvar = new VarSymbol(0, names.fromString("i" + target.syntheticNameChar()), + VarSymbol itvar = new VarSymbol(SYNTHETIC, names.fromString("i" + target.syntheticNameChar()), types.erasure(types.asSuper(iterator.type.getReturnType(), syms.iteratorType.tsym)), currentMethodSym); diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java b/langtools/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java index 9f9dd4fb874..a2d021fbc36 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java @@ -1532,7 +1532,7 @@ public class MemberEnter extends JCTree.Visitor implements Completer { * parameters from baseInit. */ initParams = List.nil(); - VarSymbol param = new VarSymbol(0, make.paramName(0), argtypes.head, init); + VarSymbol param = new VarSymbol(PARAMETER, make.paramName(0), argtypes.head, init); initParams = initParams.append(param); argTypesList = argTypesList.tail; } @@ -1541,7 +1541,7 @@ public class MemberEnter extends JCTree.Visitor implements Completer { initParams = (initParams == null) ? List.nil() : initParams; List baseInitParams = baseInit.params; while (baseInitParams.nonEmpty() && argTypesList.nonEmpty()) { - VarSymbol param = new VarSymbol(baseInitParams.head.flags(), + VarSymbol param = new VarSymbol(baseInitParams.head.flags() | PARAMETER, baseInitParams.head.name, argTypesList.head, init); initParams = initParams.append(param); baseInitParams = baseInitParams.tail; diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/TransTypes.java b/langtools/src/share/classes/com/sun/tools/javac/comp/TransTypes.java index ff7f0da574d..d747a2b5156 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/comp/TransTypes.java +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/TransTypes.java @@ -310,7 +310,7 @@ public class TransTypes extends TreeTranslator { Type.MethodType mType = (Type.MethodType)bridgeType; List argTypes = mType.argtypes; while (implParams.nonEmpty() && argTypes.nonEmpty()) { - VarSymbol param = new VarSymbol(implParams.head.flags() | SYNTHETIC, + VarSymbol param = new VarSymbol(implParams.head.flags() | SYNTHETIC | PARAMETER, implParams.head.name, argTypes.head, bridge); param.setAttributes(implParams.head); bridgeParams = bridgeParams.append(param); diff --git a/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java b/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java index 73eb2d34acf..6698c7fde27 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java +++ b/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java @@ -37,7 +37,6 @@ import javax.tools.JavaFileObject; import com.sun.tools.javac.code.*; import com.sun.tools.javac.code.Attribute.RetentionPolicy; -import com.sun.tools.javac.code.Attribute.TypeCompound; import com.sun.tools.javac.code.Symbol.*; import com.sun.tools.javac.code.Type.*; import com.sun.tools.javac.code.Types.UniqueType; @@ -55,7 +54,6 @@ import static com.sun.tools.javac.jvm.UninitializedType.*; import static com.sun.tools.javac.main.Option.*; import static javax.tools.StandardLocation.CLASS_OUTPUT; - /** This class provides operations to map an internal symbol table graph * rooted in a ClassSymbol into a classfile. * @@ -1180,25 +1178,26 @@ public class ClassWriter extends ClassFile { if (code.varBufferSize > 0) { int alenIdx = writeAttr(names.LocalVariableTable); - databuf.appendChar(code.varBufferSize); - + databuf.appendChar(code.getLVTSize()); for (int i=0; i= 0 - && var.start_pc <= code.cp); - databuf.appendChar(var.start_pc); - Assert.check(var.length >= 0 - && (var.start_pc + var.length) <= code.cp); - databuf.appendChar(var.length); - VarSymbol sym = var.sym; - databuf.appendChar(pool.put(sym.name)); - Type vartype = sym.erasure(types); - if (needsLocalVariableTypeEntry(sym.type)) - nGenericVars++; - databuf.appendChar(pool.put(typeSig(vartype))); - databuf.appendChar(var.reg); + for (Code.LocalVar.Range r: var.aliveRanges) { + // write variable info + Assert.check(r.start_pc >= 0 + && r.start_pc <= code.cp); + databuf.appendChar(r.start_pc); + Assert.check(r.length >= 0 + && (r.start_pc + r.length) <= code.cp); + databuf.appendChar(r.length); + VarSymbol sym = var.sym; + databuf.appendChar(pool.put(sym.name)); + Type vartype = sym.erasure(types); + databuf.appendChar(pool.put(typeSig(vartype))); + databuf.appendChar(var.reg); + if (needsLocalVariableTypeEntry(var.sym.type)) + nGenericVars++; + } } endAttr(alenIdx); acount++; @@ -1214,13 +1213,15 @@ public class ClassWriter extends ClassFile { VarSymbol sym = var.sym; if (!needsLocalVariableTypeEntry(sym.type)) continue; - count++; - // write variable info - databuf.appendChar(var.start_pc); - databuf.appendChar(var.length); - databuf.appendChar(pool.put(sym.name)); - databuf.appendChar(pool.put(typeSig(sym.type))); - databuf.appendChar(var.reg); + for (Code.LocalVar.Range r : var.aliveRanges) { + // write variable info + databuf.appendChar(r.start_pc); + databuf.appendChar(r.length); + databuf.appendChar(pool.put(sym.name)); + databuf.appendChar(pool.put(typeSig(sym.type))); + databuf.appendChar(var.reg); + count++; + } } Assert.check(count == nGenericVars); endAttr(alenIdx); diff --git a/langtools/src/share/classes/com/sun/tools/javac/jvm/Code.java b/langtools/src/share/classes/com/sun/tools/javac/jvm/Code.java index d151dd46172..d0ed7ec559c 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/jvm/Code.java +++ b/langtools/src/share/classes/com/sun/tools/javac/jvm/Code.java @@ -28,6 +28,7 @@ package com.sun.tools.javac.jvm; import com.sun.tools.javac.code.*; import com.sun.tools.javac.code.Symbol.*; import com.sun.tools.javac.code.Types.UniqueType; +import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.util.*; import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; @@ -181,6 +182,8 @@ public class Code { final MethodSymbol meth; + final LVTRanges lvtRanges; + /** Construct a code object, given the settings of the fatcode, * debugging info switches and the CharacterRangeTable. */ @@ -193,7 +196,8 @@ public class Code { CRTable crt, Symtab syms, Types types, - Pool pool) { + Pool pool, + LVTRanges lvtRanges) { this.meth = meth; this.fatcode = fatcode; this.lineMap = lineMap; @@ -215,6 +219,7 @@ public class Code { state = new State(); lvar = new LocalVar[20]; this.pool = pool; + this.lvtRanges = lvtRanges; } @@ -305,9 +310,19 @@ public class Code { /** The current output code pointer. */ - public int curPc() { - if (pendingJumps != null) resolvePending(); - if (pendingStatPos != Position.NOPOS) markStatBegin(); + public int curCP() { + /* + * This method has side-effects because calling it can indirectly provoke + * extra code generation, like goto instructions, depending on the context + * where it's called. + * Use with care or even better avoid using it. + */ + if (pendingJumps != null) { + resolvePending(); + } + if (pendingStatPos != Position.NOPOS) { + markStatBegin(); + } fixedPc = true; return cp; } @@ -1175,7 +1190,7 @@ public class Code { /** Declare an entry point; return current code pointer */ public int entryPoint() { - int pc = curPc(); + int pc = curCP(); alive = true; pendingStackMap = needStackMap; return pc; @@ -1185,7 +1200,7 @@ public class Code { * return current code pointer */ public int entryPoint(State state) { - int pc = curPc(); + int pc = curCP(); alive = true; this.state = state.dup(); Assert.check(state.stacksize <= max_stack); @@ -1198,7 +1213,7 @@ public class Code { * return current code pointer */ public int entryPoint(State state, Type pushed) { - int pc = curPc(); + int pc = curCP(); alive = true; this.state = state.dup(); Assert.check(state.stacksize <= max_stack); @@ -1238,7 +1253,7 @@ public class Code { /** Emit a stack map entry. */ public void emitStackMap() { - int pc = curPc(); + int pc = curCP(); if (!needStackMap) return; @@ -1482,6 +1497,9 @@ public class Code { chain.pc + 3 == target && target == cp && !fixedPc) { // If goto the next instruction, the jump is not needed: // compact the code. + if (varDebugInfo) { + adjustAliveRanges(cp, -3); + } cp = cp - 3; target = target - 3; if (chain.next == null) { @@ -1781,8 +1799,7 @@ public class Code { sym = sym.clone(sym.owner); sym.type = newtype; LocalVar newlv = lvar[i] = new LocalVar(sym); - // should the following be initialized to cp? - newlv.start_pc = lv.start_pc; + newlv.aliveRanges = lv.aliveRanges; } } } @@ -1870,8 +1887,36 @@ public class Code { static class LocalVar { final VarSymbol sym; final char reg; - char start_pc = Character.MAX_VALUE; - char length = Character.MAX_VALUE; + + class Range { + char start_pc = Character.MAX_VALUE; + char length = Character.MAX_VALUE; + + Range() {} + + Range(char start) { + this.start_pc = start; + } + + Range(char start, char length) { + this.start_pc = start; + this.length = length; + } + + boolean closed() { + return start_pc != Character.MAX_VALUE && length != Character.MAX_VALUE; + } + + @Override + public String toString() { + int currentStartPC = start_pc; + int currentLength = length; + return "startpc = " + currentStartPC + " length " + currentLength; + } + } + + java.util.List aliveRanges = new java.util.ArrayList<>(); + LocalVar(VarSymbol v) { this.sym = v; this.reg = (char)v.adr; @@ -1879,9 +1924,78 @@ public class Code { public LocalVar dup() { return new LocalVar(sym); } - public String toString() { - return "" + sym + " in register " + ((int)reg) + " starts at pc=" + ((int)start_pc) + " length=" + ((int)length); + + Range firstRange() { + return aliveRanges.isEmpty() ? null : aliveRanges.get(0); } + + Range lastRange() { + return aliveRanges.isEmpty() ? null : aliveRanges.get(aliveRanges.size() - 1); + } + + @Override + public String toString() { + if (aliveRanges == null) { + return "empty local var"; + } + StringBuilder sb = new StringBuilder().append(sym) + .append(" in register ").append((int)reg).append(" \n"); + for (Range r : aliveRanges) { + sb.append(" starts at pc=").append(Integer.toString(((int)r.start_pc))) + .append(" length=").append(Integer.toString(((int)r.length))) + .append("\n"); + } + return sb.toString(); + } + + public void openRange(char start) { + if (!hasOpenRange()) { + aliveRanges.add(new Range(start)); + } + } + + public void closeRange(char end) { + if (isLastRangeInitialized()) { + Range range = lastRange(); + if (range != null) { + if (range.length == Character.MAX_VALUE) { + range.length = end; + } + } + } else { + if (!aliveRanges.isEmpty()) { + aliveRanges.remove(aliveRanges.size() - 1); + } + } + } + + public boolean hasOpenRange() { + if (aliveRanges.isEmpty()) { + return false; + } + Range range = lastRange(); + return range.length == Character.MAX_VALUE; + } + + public boolean isLastRangeInitialized() { + if (aliveRanges.isEmpty()) { + return false; + } + Range range = lastRange(); + return range.start_pc != Character.MAX_VALUE; + } + + public Range getWidestRange() { + if (aliveRanges.isEmpty()) { + return new Range(); + } else { + Range firstRange = firstRange(); + Range lastRange = lastRange(); + char length = (char)(lastRange.length + (lastRange.start_pc - firstRange.start_pc)); + return new Range(firstRange.start_pc, length); + } + } + }; /** Local variables, indexed by register. */ @@ -1892,11 +2006,60 @@ public class Code { int adr = v.adr; lvar = ArrayUtils.ensureCapacity(lvar, adr+1); Assert.checkNull(lvar[adr]); - if (pendingJumps != null) resolvePending(); + if (pendingJumps != null) { + resolvePending(); + } lvar[adr] = new LocalVar(v); state.defined.excl(adr); } + + public void closeAliveRanges(JCTree tree) { + closeAliveRanges(tree, cp); + } + + public void closeAliveRanges(JCTree tree, int closingCP) { + List locals = lvtRanges.getVars(meth, tree); + for (LocalVar localVar: lvar) { + for (VarSymbol aliveLocal : locals) { + if (localVar == null) { + return; + } + if (localVar.sym == aliveLocal && localVar.lastRange() != null) { + char length = (char)(closingCP - localVar.lastRange().start_pc); + if (length > 0 && length < Character.MAX_VALUE) { + localVar.closeRange(length); + } + } + } + } + } + + void adjustAliveRanges(int oldCP, int delta) { + for (LocalVar localVar: lvar) { + if (localVar == null) { + return; + } + for (LocalVar.Range range: localVar.aliveRanges) { + if (range.closed() && range.start_pc + range.length >= oldCP) { + range.length += delta; + } + } + } + } + + /** + * Calculates the size of the LocalVariableTable. + */ + public int getLVTSize() { + int result = varBufferSize; + for (int i = 0; i < varBufferSize; i++) { + LocalVar var = varBuffer[i]; + result += var.aliveRanges.size() - 1; + } + return result; + } + /** Set the current variable defined state. */ public void setDefined(Bits newDefined) { if (alive && newDefined != state.defined) { @@ -1922,8 +2085,7 @@ public class Code { } else { state.defined.incl(adr); if (cp < Character.MAX_VALUE) { - if (v.start_pc == Character.MAX_VALUE) - v.start_pc = (char)cp; + v.openRange((char)cp); } } } @@ -1933,15 +2095,15 @@ public class Code { state.defined.excl(adr); if (adr < lvar.length && lvar[adr] != null && - lvar[adr].start_pc != Character.MAX_VALUE) { + lvar[adr].isLastRangeInitialized()) { LocalVar v = lvar[adr]; - char length = (char)(curPc() - v.start_pc); + char length = (char)(curCP() - v.lastRange().start_pc); if (length > 0 && length < Character.MAX_VALUE) { lvar[adr] = v.dup(); - v.length = length; + v.closeRange(length); putVar(v); } else { - v.start_pc = Character.MAX_VALUE; + v.lastRange().start_pc = Character.MAX_VALUE; } } } @@ -1951,10 +2113,10 @@ public class Code { LocalVar v = lvar[adr]; if (v != null) { lvar[adr] = null; - if (v.start_pc != Character.MAX_VALUE) { - char length = (char)(curPc() - v.start_pc); + if (v.isLastRangeInitialized()) { + char length = (char)(curCP() - v.lastRange().start_pc); if (length < Character.MAX_VALUE) { - v.length = length; + v.closeRange(length); putVar(v); fillLocalVarPosition(v); } @@ -1968,8 +2130,9 @@ public class Code { return; for (Attribute.TypeCompound ta : lv.sym.getRawTypeAttributes()) { TypeAnnotationPosition p = ta.position; - p.lvarOffset = new int[] { (int)lv.start_pc }; - p.lvarLength = new int[] { (int)lv.length }; + LocalVar.Range widestRange = lv.getWidestRange(); + p.lvarOffset = new int[] { (int)widestRange.start_pc }; + p.lvarLength = new int[] { (int)widestRange.length }; p.lvarIndex = new int[] { (int)lv.reg }; p.isValidOffset = true; } diff --git a/langtools/src/share/classes/com/sun/tools/javac/jvm/Gen.java b/langtools/src/share/classes/com/sun/tools/javac/jvm/Gen.java index 3f0fc861da3..7e727f23955 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/jvm/Gen.java +++ b/langtools/src/share/classes/com/sun/tools/javac/jvm/Gen.java @@ -24,6 +24,7 @@ */ package com.sun.tools.javac.jvm; + import java.util.*; import com.sun.tools.javac.util.*; @@ -95,10 +96,14 @@ public class Gen extends JCTree.Visitor { return instance; } - /* Constant pool, reset by genClass. + /** Constant pool, reset by genClass. */ private Pool pool; + /** LVTRanges info. + */ + private LVTRanges lvtRanges; + protected Gen(Context context) { context.put(genKey, this); @@ -128,6 +133,9 @@ public class Gen extends JCTree.Visitor { options.isUnset(G_CUSTOM) ? options.isSet(G) : options.isSet(G_CUSTOM, "vars"); + if (varDebugInfo) { + lvtRanges = LVTRanges.instance(context); + } genCrt = options.isSet(XJCOV); debugCode = options.isSet("debugcode"); allowInvokedynamic = target.hasInvokedynamic() || options.isSet("invokedynamic"); @@ -423,7 +431,7 @@ public class Gen extends JCTree.Visitor { */ void endFinalizerGap(Env env) { if (env.info.gaps != null && env.info.gaps.length() % 2 == 1) - env.info.gaps.append(code.curPc()); + env.info.gaps.append(code.curCP()); } /** Mark end of all gaps in catch-all ranges for finalizers of environments @@ -743,10 +751,10 @@ public class Gen extends JCTree.Visitor { genStat(tree, env); return; } - int startpc = code.curPc(); + int startpc = code.curCP(); genStat(tree, env); if (tree.hasTag(Tag.BLOCK)) crtFlags |= CRT_BLOCK; - code.crt.put(tree, crtFlags, startpc, code.curPc()); + code.crt.put(tree, crtFlags, startpc, code.curCP()); } /** Derived visitor method: generate code for a statement. @@ -781,9 +789,9 @@ public class Gen extends JCTree.Visitor { if (trees.length() == 1) { // mark one statement with the flags genStat(trees.head, env, crtFlags | CRT_STATEMENT); } else { - int startpc = code.curPc(); + int startpc = code.curCP(); genStats(trees, env); - code.crt.put(trees, crtFlags, startpc, code.curPc()); + code.crt.put(trees, crtFlags, startpc, code.curCP()); } } @@ -806,9 +814,9 @@ public class Gen extends JCTree.Visitor { */ public CondItem genCond(JCTree tree, int crtFlags) { if (!genCrt) return genCond(tree, false); - int startpc = code.curPc(); + int startpc = code.curCP(); CondItem item = genCond(tree, (crtFlags & CRT_FLOW_CONTROLLER) != 0); - code.crt.put(tree, crtFlags, startpc, code.curPc()); + code.crt.put(tree, crtFlags, startpc, code.curCP()); return item; } @@ -971,7 +979,6 @@ public class Gen extends JCTree.Visitor { // definition. Env localEnv = env.dup(tree); localEnv.enclMethod = tree; - // The expected type of every return statement in this method // is the method's return type. this.pt = tree.sym.erasure(types).getReturnType(); @@ -1045,7 +1052,7 @@ public class Gen extends JCTree.Visitor { code.crt.put(tree.body, CRT_BLOCK, startpcCrt, - code.curPc()); + code.curCP()); code.endScopes(0); @@ -1087,10 +1094,12 @@ public class Gen extends JCTree.Visitor { : null, syms, types, - pool); + pool, + varDebugInfo ? lvtRanges : null); items = new Items(pool, code, syms, types); - if (code.debugCode) + if (code.debugCode) { System.err.println(meth + " for body " + tree); + } // If method is not static, create a new local variable address // for `this'. @@ -1111,7 +1120,7 @@ public class Gen extends JCTree.Visitor { } // Get ready to generate code for method body. - int startpcCrt = genCrt ? code.curPc() : 0; + int startpcCrt = genCrt ? code.curCP() : 0; code.entryPoint(); // Suppress initial stackmap @@ -1189,14 +1198,30 @@ public class Gen extends JCTree.Visitor { Chain loopDone = c.jumpFalse(); code.resolve(c.trueJumps); genStat(body, loopEnv, CRT_STATEMENT | CRT_FLOW_TARGET); + if (varDebugInfo) { + checkLoopLocalVarRangeEnding(loop, body, + LoopLocalVarRangeEndingPoint.BEFORE_STEPS); + } code.resolve(loopEnv.info.cont); genStats(step, loopEnv); + if (varDebugInfo) { + checkLoopLocalVarRangeEnding(loop, body, + LoopLocalVarRangeEndingPoint.AFTER_STEPS); + } code.resolve(code.branch(goto_), startpc); code.resolve(loopDone); } else { genStat(body, loopEnv, CRT_STATEMENT | CRT_FLOW_TARGET); + if (varDebugInfo) { + checkLoopLocalVarRangeEnding(loop, body, + LoopLocalVarRangeEndingPoint.BEFORE_STEPS); + } code.resolve(loopEnv.info.cont); genStats(step, loopEnv); + if (varDebugInfo) { + checkLoopLocalVarRangeEnding(loop, body, + LoopLocalVarRangeEndingPoint.AFTER_STEPS); + } CondItem c; if (cond != null) { code.statBegin(cond.pos); @@ -1210,6 +1235,44 @@ public class Gen extends JCTree.Visitor { code.resolve(loopEnv.info.exit); } + private enum LoopLocalVarRangeEndingPoint { + BEFORE_STEPS, + AFTER_STEPS, + } + + /** + * Checks whether we have reached an alive range ending point for local + * variables after a loop. + * + * Local variables alive range ending point for loops varies depending + * on the loop type. The range can be closed before or after the code + * for the steps sentences has been generated. + * + * - While loops has no steps so in that case the range is closed just + * after the body of the loop. + * + * - For-like loops may have steps so as long as the steps sentences + * can possibly contain non-synthetic local variables, the alive range + * for local variables must be closed after the steps in this case. + */ + private void checkLoopLocalVarRangeEnding(JCTree loop, JCTree body, + LoopLocalVarRangeEndingPoint endingPoint) { + if (varDebugInfo && lvtRanges.containsKey(code.meth, body)) { + switch (endingPoint) { + case BEFORE_STEPS: + if (!loop.hasTag(FORLOOP)) { + code.closeAliveRanges(body); + } + break; + case AFTER_STEPS: + if (loop.hasTag(FORLOOP)) { + code.closeAliveRanges(body); + } + break; + } + } + } + public void visitForeachLoop(JCEnhancedForLoop tree) { throw new AssertionError(); // should have been removed by Lower. } @@ -1223,7 +1286,7 @@ public class Gen extends JCTree.Visitor { public void visitSwitch(JCSwitch tree) { int limit = code.nextreg; Assert.check(!tree.selector.type.hasTag(CLASS)); - int startpcCrt = genCrt ? code.curPc() : 0; + int startpcCrt = genCrt ? code.curCP() : 0; Item sel = genExpr(tree.selector, syms.intType); List cases = tree.cases; if (cases.isEmpty()) { @@ -1231,13 +1294,13 @@ public class Gen extends JCTree.Visitor { sel.load().drop(); if (genCrt) code.crt.put(TreeInfo.skipParens(tree.selector), - CRT_FLOW_CONTROLLER, startpcCrt, code.curPc()); + CRT_FLOW_CONTROLLER, startpcCrt, code.curCP()); } else { // We are seeing a nonempty switch. sel.load(); if (genCrt) code.crt.put(TreeInfo.skipParens(tree.selector), - CRT_FLOW_CONTROLLER, startpcCrt, code.curPc()); + CRT_FLOW_CONTROLLER, startpcCrt, code.curCP()); Env switchEnv = env.dup(tree, new GenContext()); switchEnv.info.isSwitch = true; @@ -1278,10 +1341,10 @@ public class Gen extends JCTree.Visitor { ? tableswitch : lookupswitch; - int startpc = code.curPc(); // the position of the selector operation + int startpc = code.curCP(); // the position of the selector operation code.emitop0(opcode); code.align(4); - int tableBase = code.curPc(); // the start of the jump table + int tableBase = code.curCP(); // the start of the jump table int[] offsets = null; // a table of offsets for a lookupswitch code.emit4(-1); // leave space for default offset if (opcode == tableswitch) { @@ -1323,6 +1386,9 @@ public class Gen extends JCTree.Visitor { // Generate code for the statements in this case. genStats(c.stats, switchEnv, CRT_FLOW_TARGET); + if (varDebugInfo && lvtRanges.containsKey(code.meth, c.stats.last())) { + code.closeAliveRanges(c.stats.last()); + } } // Resolve all breaks. @@ -1402,7 +1468,7 @@ public class Gen extends JCTree.Visitor { void gen() { genLast(); Assert.check(syncEnv.info.gaps.length() % 2 == 0); - syncEnv.info.gaps.append(code.curPc()); + syncEnv.info.gaps.append(code.curCP()); } void genLast() { if (code.isAlive()) { @@ -1441,10 +1507,10 @@ public class Gen extends JCTree.Visitor { jsrState); } Assert.check(tryEnv.info.gaps.length() % 2 == 0); - tryEnv.info.gaps.append(code.curPc()); + tryEnv.info.gaps.append(code.curCP()); } else { Assert.check(tryEnv.info.gaps.length() % 2 == 0); - tryEnv.info.gaps.append(code.curPc()); + tryEnv.info.gaps.append(code.curCP()); genLast(); } } @@ -1467,10 +1533,10 @@ public class Gen extends JCTree.Visitor { */ void genTry(JCTree body, List catchers, Env env) { int limit = code.nextreg; - int startpc = code.curPc(); + int startpc = code.curCP(); Code.State stateTry = code.state.dup(); genStat(body, env, CRT_BLOCK); - int endpc = code.curPc(); + int endpc = code.curCP(); boolean hasFinalizer = env.info.finalize != null && env.info.finalize.hasFinalizer(); @@ -1479,6 +1545,9 @@ public class Gen extends JCTree.Visitor { genFinalizer(env); code.statBegin(TreeInfo.endPos(env.tree)); Chain exitChain = code.branch(goto_); + if (varDebugInfo && lvtRanges.containsKey(code.meth, body)) { + code.closeAliveRanges(body); + } endFinalizerGap(env); if (startpc != endpc) for (List l = catchers; l.nonEmpty(); l = l.tail) { // start off with exception on stack @@ -1573,7 +1642,7 @@ public class Gen extends JCTree.Visitor { int catchType = makeRef(tree.pos(), subCatch.type); int end = gaps.head.intValue(); registerCatch(tree.pos(), - startpc, end, code.curPc(), + startpc, end, code.curCP(), catchType); if (subCatch.type.isAnnotated()) { // All compounds share the same position, simply update the @@ -1589,7 +1658,7 @@ public class Gen extends JCTree.Visitor { for (JCExpression subCatch : subClauses) { int catchType = makeRef(tree.pos(), subCatch.type); registerCatch(tree.pos(), - startpc, endpc, code.curPc(), + startpc, endpc, code.curCP(), catchType); if (subCatch.type.isAnnotated()) { // All compounds share the same position, simply update the @@ -1732,11 +1801,19 @@ public class Gen extends JCTree.Visitor { code.resolve(c.trueJumps); genStat(tree.thenpart, env, CRT_STATEMENT | CRT_FLOW_TARGET); thenExit = code.branch(goto_); + if (varDebugInfo && lvtRanges.containsKey(code.meth, tree.thenpart)) { + code.closeAliveRanges(tree.thenpart, + thenExit != null && tree.elsepart == null ? thenExit.pc : code.cp); + } } if (elseChain != null) { code.resolve(elseChain); - if (tree.elsepart != null) + if (tree.elsepart != null) { genStat(tree.elsepart, env,CRT_STATEMENT | CRT_FLOW_TARGET); + if (varDebugInfo && lvtRanges.containsKey(code.meth, tree.elsepart)) { + code.closeAliveRanges(tree.elsepart); + } + } } code.resolve(thenExit); code.endScopes(limit); @@ -1830,20 +1907,20 @@ public class Gen extends JCTree.Visitor { Chain elseChain = c.jumpFalse(); if (!c.isFalse()) { code.resolve(c.trueJumps); - int startpc = genCrt ? code.curPc() : 0; + int startpc = genCrt ? code.curCP() : 0; genExpr(tree.truepart, pt).load(); code.state.forceStackTop(tree.type); if (genCrt) code.crt.put(tree.truepart, CRT_FLOW_TARGET, - startpc, code.curPc()); + startpc, code.curCP()); thenExit = code.branch(goto_); } if (elseChain != null) { code.resolve(elseChain); - int startpc = genCrt ? code.curPc() : 0; + int startpc = genCrt ? code.curCP() : 0; genExpr(tree.falsepart, pt).load(); code.state.forceStackTop(tree.type); if (genCrt) code.crt.put(tree.falsepart, CRT_FLOW_TARGET, - startpc, code.curPc()); + startpc, code.curCP()); } code.resolve(thenExit); result = items.makeStackItem(pt); @@ -2423,6 +2500,19 @@ public class Gen extends JCTree.Visitor { new Env(cdef, new GenContext()); localEnv.toplevel = env.toplevel; localEnv.enclClass = cdef; + + /* We must not analyze synthetic methods + */ + if (varDebugInfo && (cdef.sym.flags() & SYNTHETIC) == 0) { + try { + LVTAssignAnalyzer lvtAssignAnalyzer = LVTAssignAnalyzer.make( + lvtRanges, syms, names); + lvtAssignAnalyzer.analyzeTree(localEnv); + } catch (Throwable e) { + throw e; + } + } + for (List l = cdef.defs; l.nonEmpty(); l = l.tail) { genDef(l.head, localEnv); } @@ -2507,4 +2597,311 @@ public class Gen extends JCTree.Visitor { cont = Code.mergeChains(c, cont); } } + + static class LVTAssignAnalyzer + extends Flow.AbstractAssignAnalyzer { + + final LVTBits lvtInits; + final LVTRanges lvtRanges; + + /* This class is anchored to a context dependent tree. The tree can + * vary inside the same instruction for example in the switch instruction + * the same FlowBits instance can be anchored to the whole tree, or + * to a given case. The aim is to always anchor the bits to the tree + * capable of closing a DA range. + */ + static class LVTBits extends Bits { + + enum BitsOpKind { + INIT, + CLEAR, + INCL_BIT, + EXCL_BIT, + ASSIGN, + AND_SET, + OR_SET, + DIFF_SET, + XOR_SET, + INCL_RANGE, + EXCL_RANGE, + } + + JCTree currentTree; + LVTAssignAnalyzer analyzer; + private int[] oldBits = null; + BitsState stateBeforeOp; + + LVTBits() { + super(false); + } + + LVTBits(int[] bits, BitsState initState) { + super(bits, initState); + } + + @Override + public void clear() { + generalOp(null, -1, BitsOpKind.CLEAR); + } + + @Override + protected void internalReset() { + super.internalReset(); + oldBits = null; + } + + @Override + public Bits assign(Bits someBits) { + // bits can be null + oldBits = bits; + stateBeforeOp = currentState; + super.assign(someBits); + changed(); + return this; + } + + @Override + public void excludeFrom(int start) { + generalOp(null, start, BitsOpKind.EXCL_RANGE); + } + + @Override + public void excl(int x) { + Assert.check(x >= 0); + generalOp(null, x, BitsOpKind.EXCL_BIT); + } + + @Override + public Bits andSet(Bits xs) { + return generalOp(xs, -1, BitsOpKind.AND_SET); + } + + @Override + public Bits orSet(Bits xs) { + return generalOp(xs, -1, BitsOpKind.OR_SET); + } + + @Override + public Bits diffSet(Bits xs) { + return generalOp(xs, -1, BitsOpKind.DIFF_SET); + } + + @Override + public Bits xorSet(Bits xs) { + return generalOp(xs, -1, BitsOpKind.XOR_SET); + } + + private Bits generalOp(Bits xs, int i, BitsOpKind opKind) { + Assert.check(currentState != BitsState.UNKNOWN); + oldBits = dupBits(); + stateBeforeOp = currentState; + switch (opKind) { + case AND_SET: + super.andSet(xs); + break; + case OR_SET: + super.orSet(xs); + break; + case XOR_SET: + super.xorSet(xs); + break; + case DIFF_SET: + super.diffSet(xs); + break; + case CLEAR: + super.clear(); + break; + case EXCL_BIT: + super.excl(i); + break; + case EXCL_RANGE: + super.excludeFrom(i); + break; + } + changed(); + return this; + } + + /* The tree we need to anchor the bits instance to. + */ + LVTBits at(JCTree tree) { + this.currentTree = tree; + return this; + } + + /* If the instance should be changed but the tree is not a closing + * tree then a reset is needed or the former tree can mistakingly be + * used. + */ + LVTBits resetTree() { + this.currentTree = null; + return this; + } + + /** This method will be called after any operation that causes a change to + * the bits. Subclasses can thus override it in order to extract information + * from the changes produced to the bits by the given operation. + */ + public void changed() { + if (currentTree != null && + stateBeforeOp != BitsState.UNKNOWN && + trackTree(currentTree)) { + List locals = + analyzer.lvtRanges + .getVars(analyzer.currentMethod, currentTree); + locals = locals != null ? + locals : List.nil(); + for (JCVariableDecl vardecl : analyzer.vardecls) { + //once the first is null, the rest will be so. + if (vardecl == null) { + break; + } + if (trackVar(vardecl.sym) && bitChanged(vardecl.sym.adr)) { + locals = locals.prepend(vardecl.sym); + } + } + if (!locals.isEmpty()) { + analyzer.lvtRanges.setEntry(analyzer.currentMethod, + currentTree, locals); + } + } + } + + boolean bitChanged(int x) { + boolean isMemberOfBits = isMember(x); + int[] tmp = bits; + bits = oldBits; + boolean isMemberOfOldBits = isMember(x); + bits = tmp; + return (!isMemberOfBits && isMemberOfOldBits); + } + + boolean trackVar(VarSymbol var) { + return (var.owner.kind == MTH && + (var.flags() & (PARAMETER | HASINIT)) == 0 && + analyzer.trackable(var)); + } + + boolean trackTree(JCTree tree) { + switch (tree.getTag()) { + // of course a method closes the alive range of a local variable. + case METHODDEF: + // for while loops we want only the body + case WHILELOOP: + return false; + } + return true; + } + + } + + public class LVTAssignPendingExit extends Flow.AssignAnalyzer.AssignPendingExit { + + LVTAssignPendingExit(JCTree tree, final Bits inits, final Bits uninits) { + super(tree, inits, uninits); + } + + @Override + public void resolveJump(JCTree tree) { + lvtInits.at(tree); + super.resolveJump(tree); + } + } + + private LVTAssignAnalyzer(LVTRanges lvtRanges, Symtab syms, Names names) { + super(new LVTBits(), syms, names); + lvtInits = (LVTBits)inits; + this.lvtRanges = lvtRanges; + } + + public static LVTAssignAnalyzer make(LVTRanges lvtRanges, Symtab syms, Names names) { + LVTAssignAnalyzer result = new LVTAssignAnalyzer(lvtRanges, syms, names); + result.lvtInits.analyzer = result; + return result; + } + + @Override + protected void markDead(JCTree tree) { + lvtInits.at(tree).inclRange(returnadr, nextadr); + super.markDead(tree); + } + + @Override + protected void merge(JCTree tree) { + lvtInits.at(tree); + super.merge(tree); + } + + boolean isSyntheticOrMandated(Symbol sym) { + return (sym.flags() & (SYNTHETIC | MANDATED)) != 0; + } + + @Override + protected boolean trackable(VarSymbol sym) { + if (isSyntheticOrMandated(sym)) { + //fast check to avoid tracking synthetic or mandated variables + return false; + } + return super.trackable(sym); + } + + @Override + protected void initParam(JCVariableDecl def) { + if (!isSyntheticOrMandated(def.sym)) { + super.initParam(def); + } + } + + @Override + protected void assignToInits(JCTree tree, Bits bits) { + lvtInits.at(tree); + lvtInits.assign(bits); + } + + @Override + protected void andSetInits(JCTree tree, Bits bits) { + lvtInits.at(tree); + lvtInits.andSet(bits); + } + + @Override + protected void orSetInits(JCTree tree, Bits bits) { + lvtInits.at(tree); + lvtInits.orSet(bits); + } + + @Override + protected void exclVarFromInits(JCTree tree, int adr) { + lvtInits.at(tree); + lvtInits.excl(adr); + } + + @Override + protected LVTAssignPendingExit createNewPendingExit(JCTree tree, Bits inits, Bits uninits) { + return new LVTAssignPendingExit(tree, inits, uninits); + } + + MethodSymbol currentMethod; + + @Override + public void visitMethodDef(JCMethodDecl tree) { + if ((tree.sym.flags() & (SYNTHETIC | GENERATEDCONSTR)) != 0) { + return; + } + if (tree.name.equals(names.clinit)) { + return; + } + boolean enumClass = (tree.sym.owner.flags() & ENUM) != 0; + if (enumClass && + (tree.name.equals(names.valueOf) || + tree.name.equals(names.values) || + tree.name.equals(names.init))) { + return; + } + currentMethod = tree.sym; + super.visitMethodDef(tree); + } + + } + } diff --git a/langtools/src/share/classes/com/sun/tools/javac/jvm/Items.java b/langtools/src/share/classes/com/sun/tools/javac/jvm/Items.java index 054facddaa6..3e1d7c68eb6 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/jvm/Items.java +++ b/langtools/src/share/classes/com/sun/tools/javac/jvm/Items.java @@ -789,18 +789,18 @@ public class Items { Chain jumpTrue() { if (tree == null) return Code.mergeChains(trueJumps, code.branch(opcode)); // we should proceed further in -Xjcov mode only - int startpc = code.curPc(); + int startpc = code.curCP(); Chain c = Code.mergeChains(trueJumps, code.branch(opcode)); - code.crt.put(tree, CRTable.CRT_BRANCH_TRUE, startpc, code.curPc()); + code.crt.put(tree, CRTable.CRT_BRANCH_TRUE, startpc, code.curCP()); return c; } Chain jumpFalse() { if (tree == null) return Code.mergeChains(falseJumps, code.branch(Code.negate(opcode))); // we should proceed further in -Xjcov mode only - int startpc = code.curPc(); + int startpc = code.curCP(); Chain c = Code.mergeChains(falseJumps, code.branch(Code.negate(opcode))); - code.crt.put(tree, CRTable.CRT_BRANCH_FALSE, startpc, code.curPc()); + code.crt.put(tree, CRTable.CRT_BRANCH_FALSE, startpc, code.curCP()); return c; } diff --git a/langtools/src/share/classes/com/sun/tools/javac/jvm/LVTRanges.java b/langtools/src/share/classes/com/sun/tools/javac/jvm/LVTRanges.java new file mode 100644 index 00000000000..71139ee78b6 --- /dev/null +++ b/langtools/src/share/classes/com/sun/tools/javac/jvm/LVTRanges.java @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2013, 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.tools.javac.jvm; + +import java.util.Map; +import java.util.Map.Entry; +import java.util.WeakHashMap; + +import com.sun.tools.javac.code.Symbol.MethodSymbol; +import com.sun.tools.javac.code.Symbol.VarSymbol; +import com.sun.tools.javac.tree.JCTree; +import com.sun.tools.javac.util.Context; +import com.sun.tools.javac.util.List; + +/** This class contains a one to many relation between a tree and a set of variables. + * The relation implies that the given tree closes the DA (definite assignment) + * range for the set of variables. + * + *

    This is NOT part of any supported API. + * If you write code that depends on this, you do so at your own risk. + * This code and its internal interfaces are subject to change or + * deletion without notice. + */ +public class LVTRanges { + /** The context key for the LVT ranges. */ + protected static final Context.Key lvtRangesKey = new Context.Key<>(); + + /** Get the LVTRanges instance for this context. */ + public static LVTRanges instance(Context context) { + LVTRanges instance = context.get(lvtRangesKey); + if (instance == null) { + instance = new LVTRanges(context); + } + return instance; + } + + private static final long serialVersionUID = 1812267524140424433L; + + protected Context context; + + protected Map>> + aliveRangeClosingTrees = new WeakHashMap<>(); + + public LVTRanges(Context context) { + this.context = context; + context.put(lvtRangesKey, this); + } + + public List getVars(MethodSymbol method, JCTree tree) { + Map> varMap = aliveRangeClosingTrees.get(method); + return (varMap != null) ? varMap.get(tree) : null; + } + + public boolean containsKey(MethodSymbol method, JCTree tree) { + Map> varMap = aliveRangeClosingTrees.get(method); + if (varMap == null) { + return false; + } + return varMap.containsKey(tree); + } + + public void setEntry(MethodSymbol method, JCTree tree, List vars) { + Map> varMap = aliveRangeClosingTrees.get(method); + if (varMap != null) { + varMap.put(tree, vars); + } else { + varMap = new WeakHashMap<>(); + varMap.put(tree, vars); + aliveRangeClosingTrees.put(method, varMap); + } + } + + public List removeEntry(MethodSymbol method, JCTree tree) { + Map> varMap = aliveRangeClosingTrees.get(method); + if (varMap != null) { + List result = varMap.remove(tree); + if (varMap.isEmpty()) { + aliveRangeClosingTrees.remove(method); + } + return result; + } + return null; + } + + /* This method should be used for debugging LVT related issues. + */ + @Override + public String toString() { + String result = ""; + for (Entry>> mainEntry: aliveRangeClosingTrees.entrySet()) { + result += "Method: \n" + mainEntry.getKey().flatName() + "\n"; + int i = 1; + for (Entry> treeEntry: mainEntry.getValue().entrySet()) { + result += " Tree " + i + ": \n" + treeEntry.getKey().toString() + "\n"; + result += " Variables closed:\n"; + for (VarSymbol var: treeEntry.getValue()) { + result += " " + var.toString(); + } + result += "\n"; + i++; + } + } + return result; + } + +} diff --git a/langtools/src/share/classes/com/sun/tools/javac/tree/TreeMaker.java b/langtools/src/share/classes/com/sun/tools/javac/tree/TreeMaker.java index b94dd5f8a4f..4e6ef7ba6ff 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/tree/TreeMaker.java +++ b/langtools/src/share/classes/com/sun/tools/javac/tree/TreeMaker.java @@ -890,7 +890,7 @@ public class TreeMaker implements JCTree.Factory { /** Create a value parameter tree from its name, type, and owner. */ public JCVariableDecl Param(Name name, Type argtype, Symbol owner) { - return VarDef(new VarSymbol(0, name, argtype, owner), null); + return VarDef(new VarSymbol(PARAMETER, name, argtype, owner), null); } /** Create a a list of value parameter trees x0, ..., xn from a list of diff --git a/langtools/src/share/classes/com/sun/tools/javac/util/Bits.java b/langtools/src/share/classes/com/sun/tools/javac/util/Bits.java index 272bf0fd49c..f8db31a4665 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/util/Bits.java +++ b/langtools/src/share/classes/com/sun/tools/javac/util/Bits.java @@ -27,8 +27,6 @@ package com.sun.tools.javac.util; import java.util.Arrays; -import static com.sun.tools.javac.util.Bits.BitsOpKind.*; - /** A class for extensible, mutable bit sets. * *

    This is NOT part of any supported API. @@ -38,20 +36,6 @@ import static com.sun.tools.javac.util.Bits.BitsOpKind.*; */ public class Bits { - public enum BitsOpKind { - INIT, - CLEAR, - INCL_BIT, - EXCL_BIT, - ASSIGN, - AND_SET, - OR_SET, - DIFF_SET, - XOR_SET, - INCL_RANGE, - EXCL_RANGE, - } - // ____________ reset _________ // / UNKNOWN \ <-------- / UNINIT \ // \____________/ | \_________/ @@ -64,11 +48,14 @@ public class Bits { // | | // ----------- // any - private enum BitsState { + protected enum BitsState { /* A Bits instance is in UNKNOWN state if it has been explicitly reset. * It is possible to get to this state from any other by calling the * reset method. An instance in the UNKNOWN state can pass to the * NORMAL state after being assigned another Bits instance. + * + * Bits instances are final fields in Flow so the UNKNOWN state models + * the null assignment. */ UNKNOWN, /* A Bits instance is in UNINIT when it is created with the default @@ -103,13 +90,9 @@ public class Bits { public int[] bits = null; // This field will store last version of bits after every change. - public int[] oldBits = null; - - public BitsOpKind lastOperation = null; - private static final int[] unassignedBits = new int[0]; - private BitsState currentState; + protected BitsState currentState; /** Construct an initially empty set. */ @@ -127,27 +110,20 @@ public class Bits { /** Construct a set consisting initially of given bit vector. */ - private Bits(int[] bits, BitsState initState) { + protected Bits(int[] bits, BitsState initState) { this.bits = bits; this.currentState = initState; switch (initState) { case UNKNOWN: - reset(); //this will also set current state; + this.bits = null; break; case NORMAL: Assert.check(bits != unassignedBits); - lastOperation = INIT; break; } } - /** This method will be called after any operation that causes a change to - * the bits. Subclasses can thus override it in order to extract information - * from the changes produced to the bits by the given operation. - */ - public void changed() {} - - private void sizeTo(int len) { + protected void sizeTo(int len) { if (bits.length < len) { bits = Arrays.copyOf(bits, len); } @@ -157,16 +133,18 @@ public class Bits { */ public void clear() { Assert.check(currentState != BitsState.UNKNOWN); - oldBits = bits; - lastOperation = CLEAR; - for (int i = 0; i < bits.length; i++) bits[i] = 0; - changed(); + for (int i = 0; i < bits.length; i++) { + bits[i] = 0; + } currentState = BitsState.NORMAL; } public void reset() { + internalReset(); + } + + protected void internalReset() { bits = null; - oldBits = null; currentState = BitsState.UNKNOWN; } @@ -175,40 +153,40 @@ public class Bits { } public Bits assign(Bits someBits) { - lastOperation = ASSIGN; - oldBits = bits; bits = someBits.dup().bits; - changed(); currentState = BitsState.NORMAL; return this; } /** Return a copy of this set. */ - private Bits dup() { + public Bits dup() { Assert.check(currentState != BitsState.UNKNOWN); Bits tmp = new Bits(); - if (currentState != BitsState.NORMAL) { - tmp.bits = bits; - } else { - tmp.bits = new int[bits.length]; - System.arraycopy(bits, 0, tmp.bits, 0, bits.length); - } + tmp.bits = dupBits(); currentState = BitsState.NORMAL; return tmp; } + protected int[] dupBits() { + int [] result; + if (currentState != BitsState.NORMAL) { + result = bits; + } else { + result = new int[bits.length]; + System.arraycopy(bits, 0, result, 0, bits.length); + } + return result; + } + /** Include x in this set. */ public void incl(int x) { Assert.check(currentState != BitsState.UNKNOWN); - Assert.check(x >= 0); - oldBits = bits; - lastOperation = INCL_BIT; + Assert.check(x >= 0, "Value of x " + x); sizeTo((x >>> wordshift) + 1); bits[x >>> wordshift] = bits[x >>> wordshift] | (1 << (x & wordmask)); - changed(); currentState = BitsState.NORMAL; } @@ -217,14 +195,11 @@ public class Bits { */ public void inclRange(int start, int limit) { Assert.check(currentState != BitsState.UNKNOWN); - oldBits = bits; - lastOperation = INCL_RANGE; sizeTo((limit >>> wordshift) + 1); for (int x = start; x < limit; x++) { bits[x >>> wordshift] = bits[x >>> wordshift] | (1 << (x & wordmask)); } - changed(); currentState = BitsState.NORMAL; } @@ -232,13 +207,10 @@ public class Bits { */ public void excludeFrom(int start) { Assert.check(currentState != BitsState.UNKNOWN); - oldBits = bits; - lastOperation = EXCL_RANGE; Bits temp = new Bits(); temp.sizeTo(bits.length); temp.inclRange(0, start); internalAndSet(temp); - changed(); currentState = BitsState.NORMAL; } @@ -247,12 +219,9 @@ public class Bits { public void excl(int x) { Assert.check(currentState != BitsState.UNKNOWN); Assert.check(x >= 0); - oldBits = bits; - lastOperation = EXCL_BIT; sizeTo((x >>> wordshift) + 1); bits[x >>> wordshift] = bits[x >>> wordshift] & ~(1 << (x & wordmask)); - changed(); currentState = BitsState.NORMAL; } @@ -269,15 +238,12 @@ public class Bits { */ public Bits andSet(Bits xs) { Assert.check(currentState != BitsState.UNKNOWN); - oldBits = bits; - lastOperation = AND_SET; internalAndSet(xs); - changed(); currentState = BitsState.NORMAL; return this; } - private void internalAndSet(Bits xs) { + protected void internalAndSet(Bits xs) { Assert.check(currentState != BitsState.UNKNOWN); sizeTo(xs.bits.length); for (int i = 0; i < xs.bits.length; i++) { @@ -289,13 +255,10 @@ public class Bits { */ public Bits orSet(Bits xs) { Assert.check(currentState != BitsState.UNKNOWN); - oldBits = bits; - lastOperation = OR_SET; sizeTo(xs.bits.length); for (int i = 0; i < xs.bits.length; i++) { bits[i] = bits[i] | xs.bits[i]; } - changed(); currentState = BitsState.NORMAL; return this; } @@ -304,14 +267,11 @@ public class Bits { */ public Bits diffSet(Bits xs) { Assert.check(currentState != BitsState.UNKNOWN); - oldBits = bits; - lastOperation = DIFF_SET; for (int i = 0; i < bits.length; i++) { if (i < xs.bits.length) { bits[i] = bits[i] & ~xs.bits[i]; } } - changed(); currentState = BitsState.NORMAL; return this; } @@ -320,13 +280,10 @@ public class Bits { */ public Bits xorSet(Bits xs) { Assert.check(currentState != BitsState.UNKNOWN); - oldBits = bits; - lastOperation = XOR_SET; sizeTo(xs.bits.length); for (int i = 0; i < xs.bits.length; i++) { bits[i] = bits[i] ^ xs.bits[i]; } - changed(); currentState = BitsState.NORMAL; return this; } @@ -336,7 +293,9 @@ public class Bits { */ private static int trailingZeroBits(int x) { Assert.check(wordlen == 32); - if (x == 0) return 32; + if (x == 0) { + return 32; + } int n = 1; if ((x & 0xffff) == 0) { n += 16; x >>>= 16; } if ((x & 0x00ff) == 0) { n += 8; x >>>= 8; } @@ -355,24 +314,31 @@ public class Bits { public int nextBit(int x) { Assert.check(currentState != BitsState.UNKNOWN); int windex = x >>> wordshift; - if (windex >= bits.length) return -1; + if (windex >= bits.length) { + return -1; + } int word = bits[windex] & ~((1 << (x & wordmask))-1); while (true) { - if (word != 0) + if (word != 0) { return (windex << wordshift) + trailingZeroBits(word); + } windex++; - if (windex >= bits.length) return -1; + if (windex >= bits.length) { + return -1; + } word = bits[windex]; } } /** a string representation of this set. */ + @Override public String toString() { - if (bits.length > 0) { + if (bits != null && bits.length > 0) { char[] digits = new char[bits.length * wordlen]; - for (int i = 0; i < bits.length * wordlen; i++) + for (int i = 0; i < bits.length * wordlen; i++) { digits[i] = isMember(i) ? '1' : '0'; + } return new String(digits); } else { return "[]"; @@ -396,6 +362,8 @@ public class Bits { System.out.println("found " + i); count ++; } - if (count != 125) throw new Error(); + if (count != 125) { + throw new Error(); + } } } diff --git a/langtools/test/tools/javac/flow/AliveRanges.java b/langtools/test/tools/javac/flow/AliveRanges.java new file mode 100644 index 00000000000..2494f77aca8 --- /dev/null +++ b/langtools/test/tools/javac/flow/AliveRanges.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013, 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.lang.annotation.*; + +@Repeatable(AliveRanges.class) +@Target({ElementType.METHOD}) +@interface AliveRange { + String varName(); + int bytecodeStart(); + int bytecodeLength(); +} + +@Target({ElementType.METHOD}) +@interface AliveRanges {AliveRange[] value();} diff --git a/langtools/test/tools/javac/flow/LVTHarness.java b/langtools/test/tools/javac/flow/LVTHarness.java new file mode 100644 index 00000000000..7794ded19dd --- /dev/null +++ b/langtools/test/tools/javac/flow/LVTHarness.java @@ -0,0 +1,280 @@ +/* + * Copyright (c) 2013, 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 7047734 + * @summary The LVT is not generated correctly during some try/catch scenarios + * @library /tools/javac/lib + * @build JavacTestingAbstractProcessor LVTHarness + * @run main LVTHarness + */ + +import java.io.File; +import java.io.IOException; +import java.lang.annotation.Annotation; +import java.util.Set; +import java.util.Arrays; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; + +import javax.annotation.processing.RoundEnvironment; +import javax.lang.model.element.Element; +import javax.lang.model.element.TypeElement; +import javax.tools.JavaCompiler; +import javax.tools.JavaFileObject; +import javax.tools.StandardJavaFileManager; +import javax.tools.ToolProvider; + +import com.sun.source.util.JavacTask; +import com.sun.tools.classfile.Attribute; +import com.sun.tools.classfile.ClassFile; +import com.sun.tools.classfile.ConstantPool; +import com.sun.tools.classfile.ConstantPoolException; +import com.sun.tools.classfile.Code_attribute; +import com.sun.tools.classfile.ConstantPool.InvalidIndex; +import com.sun.tools.classfile.ConstantPool.UnexpectedEntry; +import com.sun.tools.classfile.Descriptor.InvalidDescriptor; +import com.sun.tools.classfile.LocalVariableTable_attribute; +import com.sun.tools.classfile.Method; + +import static javax.tools.StandardLocation.*; +import static com.sun.tools.classfile.LocalVariableTable_attribute.Entry; + +public class LVTHarness { + + static int nerrors = 0; + + static final JavaCompiler comp = ToolProvider.getSystemJavaCompiler(); + static final StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null); + + public static void main(String[] args) throws Exception { + fm.setLocation(SOURCE_PATH, + Arrays.asList(new File(System.getProperty("test.src"), "tests"))); + for (JavaFileObject jfo : fm.list(SOURCE_PATH, "", + Collections.singleton(JavaFileObject.Kind.SOURCE), true)) { + new LVTHarness(jfo).check(); + } + if (nerrors > 0) { + throw new AssertionError("Errors were found"); + } + } + + + JavaFileObject jfo; + Map aliveRangeMap = + new HashMap(); + Set declaredKeys = new HashSet<>(); + List seenAliveRanges = new ArrayList<>(); + + protected LVTHarness(JavaFileObject jfo) { + this.jfo = jfo; + } + + protected void check() throws Exception { + JavacTask ct = (JavacTask)comp.getTask(null, fm, null, Arrays.asList("-g"), + null, Arrays.asList(jfo)); + System.err.println("compiling code " + jfo.toString()); + ct.setProcessors(Collections.singleton(new AliveRangeFinder())); + if (!ct.call()) { + throw new AssertionError("Error during compilation"); + } + + checkClassFile(new File(jfo.getName().replace(".java", ".class"))); + + //check all candidates have been used up + for (Map.Entry entry : aliveRangeMap.entrySet()) { + if (!seenAliveRanges.contains(entry.getKey())) { + error("Redundant @AliveRanges annotation on method " + + entry.getKey().elem); + } + } + } + + void checkClassFile(File file) + throws IOException, ConstantPoolException, InvalidDescriptor { + ClassFile classFile = ClassFile.read(file); + ConstantPool constantPool = classFile.constant_pool; + + //lets get all the methods in the class file. + for (Method method : classFile.methods) { + for (ElementKey elementKey: aliveRangeMap.keySet()) { + String methodDesc = method.getName(constantPool) + + method.descriptor.getParameterTypes(constantPool); + if (methodDesc.equals(elementKey.elem.toString())) { + checkMethod(constantPool, method, aliveRangeMap.get(elementKey)); + seenAliveRanges.add(elementKey); + } + } + } + } + + void checkMethod(ConstantPool constantPool, Method method, AliveRanges ranges) + throws InvalidIndex, UnexpectedEntry { + Code_attribute code = (Code_attribute) method.attributes.get(Attribute.Code); + LocalVariableTable_attribute lvt = + (LocalVariableTable_attribute) (code.attributes.get(Attribute.LocalVariableTable)); + List infoFromRanges = convertToStringList(ranges); + List infoFromLVT = convertToStringList(constantPool, lvt); + + // infoFromRanges most be contained in infoFromLVT + int i = 0; + int j = 0; + while (i < infoFromRanges.size() && j < infoFromLVT.size()) { + int comparison = infoFromRanges.get(i).compareTo(infoFromLVT.get(j)); + if (comparison == 0) { + i++; j++; + } else if (comparison > 0) { + j++; + } else { + break; + } + } + + if (i < infoFromRanges.size()) { + error(infoFromLVT, infoFromRanges); + } + } + + List convertToStringList(AliveRanges ranges) { + List result = new ArrayList<>(); + for (Annotation anno : ranges.value()) { + AliveRange range = (AliveRange)anno; + String str = formatLocalVariableData(range.varName(), + range.bytecodeStart(), range.bytecodeLength()); + result.add(str); + } + Collections.sort(result); + return result; + } + + List convertToStringList(ConstantPool constantPool, + LocalVariableTable_attribute lvt) throws InvalidIndex, UnexpectedEntry { + List result = new ArrayList<>(); + for (Entry entry : lvt.local_variable_table) { + String str = formatLocalVariableData(constantPool.getUTF8Value(entry.name_index), + entry.start_pc, entry.length); + result.add(str); + } + Collections.sort(result); + return result; + } + + String formatLocalVariableData(String varName, int start, int length) { + StringBuilder sb = new StringBuilder() + .append("var name: ").append(varName) + .append(" start: ").append(start) + .append(" length: ").append(length); + return sb.toString(); + } + + protected void error(List infoFromLVT, List infoFromRanges) { + nerrors++; + System.err.printf("Error occurred while checking file: %s\n", jfo.getName()); + System.err.println("The range info from the annotations is"); + printStringListToErrOutput(infoFromRanges); + System.err.println(); + System.err.println("And the range info from the class file is"); + printStringListToErrOutput(infoFromLVT); + System.err.println(); + } + + void printStringListToErrOutput(List list) { + for (String s : list) { + System.err.println("\t" + s); + } + } + + protected void error(String msg) { + nerrors++; + System.err.printf("Error occurred while checking file: %s\nreason: %s\n", + jfo.getName(), msg); + } + + class AliveRangeFinder extends JavacTestingAbstractProcessor { + + @Override + public boolean process(Set annotations, + RoundEnvironment roundEnv) { + if (roundEnv.processingOver()) + return true; + + TypeElement aliveRangeAnno = elements.getTypeElement("AliveRanges"); + + if (!annotations.contains(aliveRangeAnno)) { + error("no @AliveRanges annotation found in test class"); + } + + for (Element elem: roundEnv.getElementsAnnotatedWith(aliveRangeAnno)) { + Annotation annotation = elem.getAnnotation(AliveRanges.class); + aliveRangeMap.put(new ElementKey(elem), (AliveRanges)annotation); + } + return true; + } + } + + class ElementKey { + + String key; + Element elem; + + public ElementKey(Element elem) { + this.elem = elem; + this.key = computeKey(elem); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof ElementKey) { + ElementKey other = (ElementKey)obj; + return other.key.equals(key); + } + return false; + } + + @Override + public int hashCode() { + return key.hashCode(); + } + + String computeKey(Element e) { + StringBuilder buf = new StringBuilder(); + while (e != null) { + buf.append(e.toString()); + e = e.getEnclosingElement(); + } + buf.append(jfo.getName()); + return buf.toString(); + } + + @Override + public String toString() { + return "Key{" + key + "}"; + } + } + +} diff --git a/langtools/test/tools/javac/flow/tests/TestCaseConditional.java b/langtools/test/tools/javac/flow/tests/TestCaseConditional.java new file mode 100644 index 00000000000..0e5915985d0 --- /dev/null +++ b/langtools/test/tools/javac/flow/tests/TestCaseConditional.java @@ -0,0 +1,16 @@ +/* /nodynamiccopyright/ */ + +public class TestCaseConditional { + + @AliveRange(varName="o", bytecodeStart=5, bytecodeLength=33) + @AliveRange(varName="oo", bytecodeStart=23, bytecodeLength=15) + void m(String[] args) { + Boolean o; + Boolean oo = ((o = Boolean.TRUE).booleanValue()) ? + o = Boolean.TRUE : + Boolean.FALSE; + oo.hashCode(); + o = Boolean.FALSE; + o.hashCode(); + } +} diff --git a/langtools/test/tools/javac/flow/tests/TestCaseDoLoop.java b/langtools/test/tools/javac/flow/tests/TestCaseDoLoop.java new file mode 100644 index 00000000000..68e3d20e6a4 --- /dev/null +++ b/langtools/test/tools/javac/flow/tests/TestCaseDoLoop.java @@ -0,0 +1,15 @@ +/* /nodynamiccopyright/ */ + +public class TestCaseDoLoop { + + @AliveRange(varName="o", bytecodeStart=3, bytecodeLength=15) + @AliveRange(varName="args", bytecodeStart=0, bytecodeLength=18) + void m(String[] args) { + Object o; + do { + o = ""; + o.hashCode(); + } while (args[0] != null); + o = ""; + } +} diff --git a/langtools/test/tools/javac/flow/tests/TestCaseFor.java b/langtools/test/tools/javac/flow/tests/TestCaseFor.java new file mode 100644 index 00000000000..10056b88086 --- /dev/null +++ b/langtools/test/tools/javac/flow/tests/TestCaseFor.java @@ -0,0 +1,27 @@ +/* /nodynamiccopyright/ */ + +public class TestCaseFor { + + @AliveRange(varName="o", bytecodeStart=10, bytecodeLength=8) + @AliveRange(varName="o", bytecodeStart=24, bytecodeLength=1) + void m1(String[] args) { + Object o; + for (int i = 0; i < 5; i++) { + o = ""; + o.hashCode(); + } + o = ""; + } + + @AliveRange(varName="o", bytecodeStart=10, bytecodeLength=8) + @AliveRange(varName="o", bytecodeStart=24, bytecodeLength=1) + void m2(String[] args) { + Object o; + for (int i = 0; i < 5; i++) { + o = ""; + o.hashCode(); + continue; + } + o = ""; + } +} diff --git a/langtools/test/tools/javac/flow/tests/TestCaseForEach.java b/langtools/test/tools/javac/flow/tests/TestCaseForEach.java new file mode 100644 index 00000000000..219f1180772 --- /dev/null +++ b/langtools/test/tools/javac/flow/tests/TestCaseForEach.java @@ -0,0 +1,15 @@ +/* /nodynamiccopyright/ */ + +public class TestCaseForEach { + + @AliveRange(varName="o", bytecodeStart=25, bytecodeLength=8) + @AliveRange(varName="o", bytecodeStart=39, bytecodeLength=1) + void m(String[] args) { + Object o; + for (String s : args) { + o = ""; + o.hashCode(); + } + o = ""; + } +} diff --git a/langtools/test/tools/javac/flow/tests/TestCaseIf.java b/langtools/test/tools/javac/flow/tests/TestCaseIf.java new file mode 100644 index 00000000000..9869443f773 --- /dev/null +++ b/langtools/test/tools/javac/flow/tests/TestCaseIf.java @@ -0,0 +1,61 @@ +/* /nodynamiccopyright/ */ + +public class TestCaseIf { + + @AliveRange(varName="o", bytecodeStart=9, bytecodeLength=5) + @AliveRange(varName="o", bytecodeStart=17, bytecodeLength=1) + void m0(String[] args) { + Object o; + if (args[0] != null) { + o = ""; + o.hashCode(); + } + o = ""; + } + + @AliveRange(varName="o", bytecodeStart=10, bytecodeLength=5) + @AliveRange(varName="o", bytecodeStart=18, bytecodeLength=1) + void m1() { + Object o; + int i = 5; + if (i == 5) { + o = ""; + o.hashCode(); + } + o = ""; + } + + @AliveRange(varName="o", bytecodeStart=10, bytecodeLength=5) + @AliveRange(varName="o", bytecodeStart=18, bytecodeLength=1) + void m2() { + Object o; + int i = 5; + if (!(i == 5)) { + o = ""; + o.hashCode(); + } + o = ""; + } + + @AliveRange(varName="o", bytecodeStart=15, bytecodeLength=5) + @AliveRange(varName="o", bytecodeStart=23, bytecodeLength=1) + void m3(String[] args) { + Object o; + if (args[0] != null && args[1] != null) { + o = ""; + o.hashCode(); + } + o = ""; + } + + @AliveRange(varName="o", bytecodeStart=15, bytecodeLength=5) + @AliveRange(varName="o", bytecodeStart=23, bytecodeLength=1) + void m4(String[] args) { + Object o; + if (args[0] != null || args[1] != null) { + o = ""; + o.hashCode(); + } + o = ""; + } +} diff --git a/langtools/test/tools/javac/flow/tests/TestCaseIfElse.java b/langtools/test/tools/javac/flow/tests/TestCaseIfElse.java new file mode 100644 index 00000000000..3e6cc893794 --- /dev/null +++ b/langtools/test/tools/javac/flow/tests/TestCaseIfElse.java @@ -0,0 +1,48 @@ +/* /nodynamiccopyright/ */ + +public class TestCaseIfElse { + + @AliveRange(varName="o", bytecodeStart=9, bytecodeLength=8) + @AliveRange(varName="o", bytecodeStart=20, bytecodeLength=9) + void m0(String[] args) { + Object o; + if (args[0] != null) { + o = "then"; + o.hashCode(); + } else { + o = "else"; + o.hashCode(); + } + o = "finish"; + } + + @AliveRange(varName="o", bytecodeStart=10, bytecodeLength=8) + @AliveRange(varName="o", bytecodeStart=21, bytecodeLength=9) + void m1() { + Object o; + int i = 5; + if (i == 5) { + o = "then"; + o.hashCode(); + } else { + o = "else"; + o.hashCode(); + } + o = "finish"; + } + + @AliveRange(varName="o", bytecodeStart=10, bytecodeLength=8) + @AliveRange(varName="o", bytecodeStart=21, bytecodeLength=9) + void m2(String[] args) { + Object o; + int i = 5; + if (i != 5) { + o = "then"; + o.hashCode(); + } else { + o = "else"; + o.hashCode(); + } + o = "finish"; + } +} diff --git a/langtools/test/tools/javac/flow/tests/TestCaseSwitch.java b/langtools/test/tools/javac/flow/tests/TestCaseSwitch.java new file mode 100644 index 00000000000..d96850ffd21 --- /dev/null +++ b/langtools/test/tools/javac/flow/tests/TestCaseSwitch.java @@ -0,0 +1,73 @@ +/* /nodynamiccopyright/ */ + +public class TestCaseSwitch { + + @AliveRange(varName="o", bytecodeStart=31, bytecodeLength=16) + @AliveRange(varName="o", bytecodeStart=50, bytecodeLength=15) + @AliveRange(varName="o", bytecodeStart=68, bytecodeLength=1) + @AliveRange(varName="oo", bytecodeStart=39, bytecodeLength=26) + @AliveRange(varName="uu", bytecodeStart=59, bytecodeLength=6) + void m1(String[] args) { + Object o; + switch (args.length) { + case 0: + o = "0"; + o.hashCode(); + Object oo = "oo"; + oo.hashCode(); + break; + case 1: + o = "1"; + o.hashCode(); + Object uu = "uu"; + uu.hashCode(); + break; + } + o = "return"; + } + + @AliveRange(varName="o", bytecodeStart=95, bytecodeLength=18) + @AliveRange(varName="o", bytecodeStart=116, bytecodeLength=15) + @AliveRange(varName="o", bytecodeStart=134, bytecodeLength=1) + @AliveRange(varName="oo", bytecodeStart=104, bytecodeLength=27) + @AliveRange(varName="uu", bytecodeStart=125, bytecodeLength=6) + void m2(String[] args) { + Object o; + switch (args[0]) { + case "string0": + o = "0"; + o.hashCode(); + Object oo = "oo"; + oo.hashCode(); + break; + case "string1": + o = "1"; + o.hashCode(); + Object uu = "uu"; + uu.hashCode(); + break; + } + o = "return"; + } + + @AliveRange(varName="o", bytecodeStart=31, bytecodeLength=8) + @AliveRange(varName="o", bytecodeStart=42, bytecodeLength=8) + @AliveRange(varName="o", bytecodeStart=53, bytecodeLength=9) + void m3(String[] args) { + Object o; + switch (args.length) { + case 0: + o = "0"; + o.hashCode(); + break; + case 1: + o = "1"; + o.hashCode(); + break; + default: + o = "default"; + o.hashCode(); + } + o = "finish"; + } +} diff --git a/langtools/test/tools/javac/flow/tests/TestCaseTry.java b/langtools/test/tools/javac/flow/tests/TestCaseTry.java new file mode 100644 index 00000000000..e987534ddfc --- /dev/null +++ b/langtools/test/tools/javac/flow/tests/TestCaseTry.java @@ -0,0 +1,76 @@ +/* /nodynamiccopyright/ */ + +import java.io.BufferedReader; +import java.io.FileReader; + +public class TestCaseTry { + + @AliveRange(varName="o", bytecodeStart=3, bytecodeLength=8) + @AliveRange(varName="o", bytecodeStart=15, bytecodeLength=1) + void m0(String[] args) { + Object o; + try { + o = ""; + o.hashCode(); + } catch (RuntimeException e) {} + o = ""; + } + + @AliveRange(varName="o", bytecodeStart=3, bytecodeLength=16) + @AliveRange(varName="o", bytecodeStart=23, bytecodeLength=23) + void m1() { + Object o; + try { + o = ""; + o.hashCode(); + } catch (RuntimeException e) { + } + finally { + o = "finally"; + o.hashCode(); + } + o = ""; + } + + @AliveRange(varName="o", bytecodeStart=3, bytecodeLength=16) + @AliveRange(varName="o", bytecodeStart=23, bytecodeLength=31) + void m2() { + Object o; + try { + o = ""; + o.hashCode(); + } catch (RuntimeException e) { + o = "catch"; + o.hashCode(); + } + finally { + o = "finally"; + o.hashCode(); + } + o = ""; + } + + @AliveRange(varName="o", bytecodeStart=22, bytecodeLength=38) + @AliveRange(varName="o", bytecodeStart=103, bytecodeLength=8) + void m3() { + Object o; + try (BufferedReader br = + new BufferedReader(new FileReader("aFile"))) { + o = "inside try"; + o.hashCode(); + } catch (Exception e) {} + o = ""; + } + + @AliveRange(varName="o", bytecodeStart=12, bytecodeLength=96) + @AliveRange(varName="o", bytecodeStart=112, bytecodeLength=1) + void m4() { + String o; + try (BufferedReader br = + new BufferedReader(new FileReader(o = "aFile"))) { + o = "inside try"; + o.hashCode(); + } catch (Exception e) {} + o = ""; + } +} diff --git a/langtools/test/tools/javac/flow/tests/TestCaseWhile.java b/langtools/test/tools/javac/flow/tests/TestCaseWhile.java new file mode 100644 index 00000000000..bbe1f844422 --- /dev/null +++ b/langtools/test/tools/javac/flow/tests/TestCaseWhile.java @@ -0,0 +1,15 @@ +/* /nodynamiccopyright/ */ + +public class TestCaseWhile { + + @AliveRange(varName="o", bytecodeStart=9, bytecodeLength=5) + @AliveRange(varName="o", bytecodeStart=20, bytecodeLength=1) + void m(String[] args) { + Object o; + while (args[0] != null) { + o = ""; + o.hashCode(); + } + o = ""; + } +} From 4df3876c56f6b810120159af2959e59f90bab69b Mon Sep 17 00:00:00 2001 From: Paul Sandoz Date: Sun, 15 Sep 2013 16:13:41 +0200 Subject: [PATCH 168/210] 8024837: Rename java/util/concurrent/ConcurrentHashMap/toArray.java to ToArray.java Reviewed-by: alanb --- .../concurrent/ConcurrentHashMap/{toArray.java => ToArray.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename jdk/test/java/util/concurrent/ConcurrentHashMap/{toArray.java => ToArray.java} (98%) diff --git a/jdk/test/java/util/concurrent/ConcurrentHashMap/toArray.java b/jdk/test/java/util/concurrent/ConcurrentHashMap/ToArray.java similarity index 98% rename from jdk/test/java/util/concurrent/ConcurrentHashMap/toArray.java rename to jdk/test/java/util/concurrent/ConcurrentHashMap/ToArray.java index 81108ac9c55..dca07084162 100644 --- a/jdk/test/java/util/concurrent/ConcurrentHashMap/toArray.java +++ b/jdk/test/java/util/concurrent/ConcurrentHashMap/ToArray.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2013, 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 From 344c38fc804de7d28b95d044c4f45ad007933ba6 Mon Sep 17 00:00:00 2001 From: Xueming Shen Date: Sun, 15 Sep 2013 11:16:58 -0700 Subject: [PATCH 169/210] 7186311: (props) "Unicode" is misspelled as "Uniocde" in JavaDoc and error message To correct the typo Reviewed-by: alanb, chegar --- .../tools/src/build/tools/generatecharacter/CharacterName.java | 2 +- jdk/src/share/classes/java/util/Properties.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/jdk/make/tools/src/build/tools/generatecharacter/CharacterName.java b/jdk/make/tools/src/build/tools/generatecharacter/CharacterName.java index 0872100b7db..833a835c0ce 100644 --- a/jdk/make/tools/src/build/tools/generatecharacter/CharacterName.java +++ b/jdk/make/tools/src/build/tools/generatecharacter/CharacterName.java @@ -11,7 +11,7 @@ public class CharacterName { FileReader reader = null; try { if (args.length != 2) { - System.err.println("Usage: java CharacterName UniocdeData.txt uniName.dat"); + System.err.println("Usage: java CharacterName UnicodeData.txt uniName.dat"); System.exit(1); } diff --git a/jdk/src/share/classes/java/util/Properties.java b/jdk/src/share/classes/java/util/Properties.java index ed0bf857d66..073c7771630 100644 --- a/jdk/src/share/classes/java/util/Properties.java +++ b/jdk/src/share/classes/java/util/Properties.java @@ -304,7 +304,7 @@ class Properties extends Hashtable { * preceded by a backslash still yield single and double quote * characters, respectively. * - *

  • Only a single 'u' character is allowed in a Uniocde escape + *
  • Only a single 'u' character is allowed in a Unicode escape * sequence. * * From 763eb8d2e341667f9f8470df39a6bb0ff84b20ce Mon Sep 17 00:00:00 2001 From: Xueming Shen Date: Sun, 15 Sep 2013 13:58:47 -0700 Subject: [PATCH 170/210] 8020687: Deflater.setLevel does not work as expected To clarify the api to match the existing implementation behavior Reviewed-by: alanb --- jdk/src/share/classes/java/util/zip/Deflater.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/jdk/src/share/classes/java/util/zip/Deflater.java b/jdk/src/share/classes/java/util/zip/Deflater.java index 085287996be..c4521bec667 100644 --- a/jdk/src/share/classes/java/util/zip/Deflater.java +++ b/jdk/src/share/classes/java/util/zip/Deflater.java @@ -261,6 +261,12 @@ class Deflater { /** * Sets the compression strategy to the specified value. + * + *

    If the compression strategy is changed, the next invocation + * of {@code deflate} will compress the input available so far with + * the old strategy (and may be flushed); the new strategy will take + * effect only after that invocation. + * * @param strategy the new compression strategy * @exception IllegalArgumentException if the compression strategy is * invalid @@ -283,7 +289,13 @@ class Deflater { } /** - * Sets the current compression level to the specified value. + * Sets the compression level to the specified value. + * + *

    If the compression level is changed, the next invocation + * of {@code deflate} will compress the input available so far + * with the old level (and may be flushed); the new level will + * take effect only after that invocation. + * * @param level the new compression level (0-9) * @exception IllegalArgumentException if the compression level is invalid */ From 3184042cd14fb6a080bb75cb31f683200855393c Mon Sep 17 00:00:00 2001 From: Thomas Schatzl Date: Mon, 16 Sep 2013 10:20:45 +0200 Subject: [PATCH 171/210] 8024396: VM crashing with assert(!UseLargePages || UseParallelOldGC || use_large_pages) failed: Wrong alignment to use large pages Loosen wrong assert for UseParallelOldGC to UseParallelGC Reviewed-by: stefank, brutisso --- hotspot/src/share/vm/memory/universe.cpp | 2 +- .../TestAlignmentToUseLargePages.java | 47 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 hotspot/test/gc/arguments/TestAlignmentToUseLargePages.java diff --git a/hotspot/src/share/vm/memory/universe.cpp b/hotspot/src/share/vm/memory/universe.cpp index 54d6851d16d..a9be3486396 100644 --- a/hotspot/src/share/vm/memory/universe.cpp +++ b/hotspot/src/share/vm/memory/universe.cpp @@ -881,7 +881,7 @@ ReservedSpace Universe::reserve_heap(size_t heap_size, size_t alignment) { bool use_large_pages = UseLargePages && is_size_aligned(alignment, os::large_page_size()); assert(!UseLargePages - || UseParallelOldGC + || UseParallelGC || use_large_pages, "Wrong alignment to use large pages"); char* addr = Universe::preferred_heap_base(total_reserved, alignment, Universe::UnscaledNarrowOop); diff --git a/hotspot/test/gc/arguments/TestAlignmentToUseLargePages.java b/hotspot/test/gc/arguments/TestAlignmentToUseLargePages.java new file mode 100644 index 00000000000..125c1aabd51 --- /dev/null +++ b/hotspot/test/gc/arguments/TestAlignmentToUseLargePages.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2013, 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 TestAlignmentToUseLargePages + * @summary All parallel GC variants may use large pages without the requirement that the + * heap alignment is large page aligned. Other collectors also need to start up with odd sized heaps. + * @bug 8024396 + * @key gc + * @key regression + * @run main/othervm -Xms7M -Xmx9M -XX:+UseParallelGC -XX:-UseParallelOldGC -XX:+UseLargePages TestAlignmentToUseLargePages + * @run main/othervm -Xms7M -Xmx9M -XX:+UseParallelGC -XX:-UseParallelOldGC -XX:-UseLargePages TestAlignmentToUseLargePages + * @run main/othervm -Xms7M -Xmx9M -XX:+UseParallelGC -XX:+UseParallelOldGC -XX:+UseLargePages TestAlignmentToUseLargePages + * @run main/othervm -Xms7M -Xmx9M -XX:+UseParallelGC -XX:+UseParallelOldGC -XX:-UseLargePages TestAlignmentToUseLargePages + * @run main/othervm -Xms7M -Xmx9M -XX:+UseSerialGC -XX:+UseLargePages TestAlignmentToUseLargePages + * @run main/othervm -Xms7M -Xmx9M -XX:+UseSerialGC -XX:-UseLargePages TestAlignmentToUseLargePages + * @run main/othervm -Xms7M -Xmx9M -XX:+UseConcMarkSweepGC -XX:+UseLargePages TestAlignmentToUseLargePages + * @run main/othervm -Xms7M -Xmx9M -XX:+UseConcMarkSweepGC -XX:-UseLargePages TestAlignmentToUseLargePages + * @run main/othervm -Xms7M -Xmx9M -XX:+UseG1GC -XX:+UseLargePages TestAlignmentToUseLargePages + * @run main/othervm -Xms7M -Xmx9M -XX:+UseG1GC -XX:-UseLargePages TestAlignmentToUseLargePages + */ + +public class TestAlignmentToUseLargePages { + public static void main(String args[]) throws Exception { + // nothing to do + } +} From 139c3e6621b2105f1d69c5032e5a10b48967dc8a Mon Sep 17 00:00:00 2001 From: David Holmes Date: Mon, 16 Sep 2013 07:38:13 -0400 Subject: [PATCH 172/210] 6900441: PlatformEvent.park(millis) on Linux could still be affected by changes to the time-of-day clock Associate CLOCK_MONOTONIC with the pthread_cond_t objects used for relative timed waits Reviewed-by: dcubed, shade --- hotspot/src/os/linux/vm/os_linux.cpp | 148 +++++++++++++++++++-------- hotspot/src/os/linux/vm/os_linux.hpp | 25 ++++- 2 files changed, 128 insertions(+), 45 deletions(-) diff --git a/hotspot/src/os/linux/vm/os_linux.cpp b/hotspot/src/os/linux/vm/os_linux.cpp index 70837a850d8..de5a7686989 100644 --- a/hotspot/src/os/linux/vm/os_linux.cpp +++ b/hotspot/src/os/linux/vm/os_linux.cpp @@ -131,6 +131,7 @@ bool os::Linux::_is_NPTL = false; bool os::Linux::_supports_fast_thread_cpu_time = false; const char * os::Linux::_glibc_version = NULL; const char * os::Linux::_libpthread_version = NULL; +pthread_condattr_t os::Linux::_condattr[1]; static jlong initial_time_count=0; @@ -1399,12 +1400,15 @@ void os::Linux::clock_init() { clock_gettime_func(CLOCK_MONOTONIC, &tp) == 0) { // yes, monotonic clock is supported _clock_gettime = clock_gettime_func; + return; } else { // close librt if there is no monotonic clock dlclose(handle); } } } + warning("No monotonic clock was available - timed services may " \ + "be adversely affected if the time-of-day clock changes"); } #ifndef SYS_clock_getres @@ -4709,6 +4713,26 @@ void os::init(void) { Linux::clock_init(); initial_time_count = os::elapsed_counter(); + + // pthread_condattr initialization for monotonic clock + int status; + pthread_condattr_t* _condattr = os::Linux::condAttr(); + if ((status = pthread_condattr_init(_condattr)) != 0) { + fatal(err_msg("pthread_condattr_init: %s", strerror(status))); + } + // Only set the clock if CLOCK_MONOTONIC is available + if (Linux::supports_monotonic_clock()) { + if ((status = pthread_condattr_setclock(_condattr, CLOCK_MONOTONIC)) != 0) { + if (status == EINVAL) { + warning("Unable to use monotonic clock with relative timed-waits" \ + " - changes to the time-of-day clock may have adverse affects"); + } else { + fatal(err_msg("pthread_condattr_setclock: %s", strerror(status))); + } + } + } + // else it defaults to CLOCK_REALTIME + pthread_mutex_init(&dl_mutex, NULL); // If the pagesize of the VM is greater than 8K determine the appropriate @@ -5519,21 +5543,36 @@ void os::pause() { static struct timespec* compute_abstime(timespec* abstime, jlong millis) { if (millis < 0) millis = 0; - struct timeval now; - int status = gettimeofday(&now, NULL); - assert(status == 0, "gettimeofday"); + jlong seconds = millis / 1000; millis %= 1000; if (seconds > 50000000) { // see man cond_timedwait(3T) seconds = 50000000; } - abstime->tv_sec = now.tv_sec + seconds; - long usec = now.tv_usec + millis * 1000; - if (usec >= 1000000) { - abstime->tv_sec += 1; - usec -= 1000000; + + if (os::Linux::supports_monotonic_clock()) { + struct timespec now; + int status = os::Linux::clock_gettime(CLOCK_MONOTONIC, &now); + assert_status(status == 0, status, "clock_gettime"); + abstime->tv_sec = now.tv_sec + seconds; + long nanos = now.tv_nsec + millis * NANOSECS_PER_MILLISEC; + if (nanos >= NANOSECS_PER_SEC) { + abstime->tv_sec += 1; + nanos -= NANOSECS_PER_SEC; + } + abstime->tv_nsec = nanos; + } else { + struct timeval now; + int status = gettimeofday(&now, NULL); + assert(status == 0, "gettimeofday"); + abstime->tv_sec = now.tv_sec + seconds; + long usec = now.tv_usec + millis * 1000; + if (usec >= 1000000) { + abstime->tv_sec += 1; + usec -= 1000000; + } + abstime->tv_nsec = usec * 1000; } - abstime->tv_nsec = usec * 1000; return abstime; } @@ -5625,7 +5664,7 @@ int os::PlatformEvent::park(jlong millis) { status = os::Linux::safe_cond_timedwait(_cond, _mutex, &abst); if (status != 0 && WorkAroundNPTLTimedWaitHang) { pthread_cond_destroy (_cond); - pthread_cond_init (_cond, NULL) ; + pthread_cond_init (_cond, os::Linux::condAttr()) ; } assert_status(status == 0 || status == EINTR || status == ETIME || status == ETIMEDOUT, @@ -5726,32 +5765,50 @@ void os::PlatformEvent::unpark() { static void unpackTime(timespec* absTime, bool isAbsolute, jlong time) { assert (time > 0, "convertTime"); + time_t max_secs = 0; - struct timeval now; - int status = gettimeofday(&now, NULL); - assert(status == 0, "gettimeofday"); + if (!os::Linux::supports_monotonic_clock() || isAbsolute) { + struct timeval now; + int status = gettimeofday(&now, NULL); + assert(status == 0, "gettimeofday"); - time_t max_secs = now.tv_sec + MAX_SECS; + max_secs = now.tv_sec + MAX_SECS; - if (isAbsolute) { - jlong secs = time / 1000; - if (secs > max_secs) { - absTime->tv_sec = max_secs; + if (isAbsolute) { + jlong secs = time / 1000; + if (secs > max_secs) { + absTime->tv_sec = max_secs; + } else { + absTime->tv_sec = secs; + } + absTime->tv_nsec = (time % 1000) * NANOSECS_PER_MILLISEC; + } else { + jlong secs = time / NANOSECS_PER_SEC; + if (secs >= MAX_SECS) { + absTime->tv_sec = max_secs; + absTime->tv_nsec = 0; + } else { + absTime->tv_sec = now.tv_sec + secs; + absTime->tv_nsec = (time % NANOSECS_PER_SEC) + now.tv_usec*1000; + if (absTime->tv_nsec >= NANOSECS_PER_SEC) { + absTime->tv_nsec -= NANOSECS_PER_SEC; + ++absTime->tv_sec; // note: this must be <= max_secs + } + } } - else { - absTime->tv_sec = secs; - } - absTime->tv_nsec = (time % 1000) * NANOSECS_PER_MILLISEC; - } - else { + } else { + // must be relative using monotonic clock + struct timespec now; + int status = os::Linux::clock_gettime(CLOCK_MONOTONIC, &now); + assert_status(status == 0, status, "clock_gettime"); + max_secs = now.tv_sec + MAX_SECS; jlong secs = time / NANOSECS_PER_SEC; if (secs >= MAX_SECS) { absTime->tv_sec = max_secs; absTime->tv_nsec = 0; - } - else { + } else { absTime->tv_sec = now.tv_sec + secs; - absTime->tv_nsec = (time % NANOSECS_PER_SEC) + now.tv_usec*1000; + absTime->tv_nsec = (time % NANOSECS_PER_SEC) + now.tv_nsec; if (absTime->tv_nsec >= NANOSECS_PER_SEC) { absTime->tv_nsec -= NANOSECS_PER_SEC; ++absTime->tv_sec; // note: this must be <= max_secs @@ -5831,15 +5888,19 @@ void Parker::park(bool isAbsolute, jlong time) { jt->set_suspend_equivalent(); // cleared by handle_special_suspend_equivalent_condition() or java_suspend_self() + assert(_cur_index == -1, "invariant"); if (time == 0) { - status = pthread_cond_wait (_cond, _mutex) ; + _cur_index = REL_INDEX; // arbitrary choice when not timed + status = pthread_cond_wait (&_cond[_cur_index], _mutex) ; } else { - status = os::Linux::safe_cond_timedwait (_cond, _mutex, &absTime) ; + _cur_index = isAbsolute ? ABS_INDEX : REL_INDEX; + status = os::Linux::safe_cond_timedwait (&_cond[_cur_index], _mutex, &absTime) ; if (status != 0 && WorkAroundNPTLTimedWaitHang) { - pthread_cond_destroy (_cond) ; - pthread_cond_init (_cond, NULL); + pthread_cond_destroy (&_cond[_cur_index]) ; + pthread_cond_init (&_cond[_cur_index], isAbsolute ? NULL : os::Linux::condAttr()); } } + _cur_index = -1; assert_status(status == 0 || status == EINTR || status == ETIME || status == ETIMEDOUT, status, "cond_timedwait"); @@ -5868,17 +5929,24 @@ void Parker::unpark() { s = _counter; _counter = 1; if (s < 1) { - if (WorkAroundNPTLTimedWaitHang) { - status = pthread_cond_signal (_cond) ; - assert (status == 0, "invariant") ; + // thread might be parked + if (_cur_index != -1) { + // thread is definitely parked + if (WorkAroundNPTLTimedWaitHang) { + status = pthread_cond_signal (&_cond[_cur_index]); + assert (status == 0, "invariant"); status = pthread_mutex_unlock(_mutex); - assert (status == 0, "invariant") ; - } else { + assert (status == 0, "invariant"); + } else { status = pthread_mutex_unlock(_mutex); - assert (status == 0, "invariant") ; - status = pthread_cond_signal (_cond) ; - assert (status == 0, "invariant") ; - } + assert (status == 0, "invariant"); + status = pthread_cond_signal (&_cond[_cur_index]); + assert (status == 0, "invariant"); + } + } else { + pthread_mutex_unlock(_mutex); + assert (status == 0, "invariant") ; + } } else { pthread_mutex_unlock(_mutex); assert (status == 0, "invariant") ; diff --git a/hotspot/src/os/linux/vm/os_linux.hpp b/hotspot/src/os/linux/vm/os_linux.hpp index c824e8ad3fe..5eed54f8c1e 100644 --- a/hotspot/src/os/linux/vm/os_linux.hpp +++ b/hotspot/src/os/linux/vm/os_linux.hpp @@ -221,6 +221,13 @@ class Linux { static jlong fast_thread_cpu_time(clockid_t clockid); + // pthread_cond clock suppport + private: + static pthread_condattr_t _condattr[1]; + + public: + static pthread_condattr_t* condAttr() { return _condattr; } + // Stack repair handling // none present @@ -295,7 +302,7 @@ class PlatformEvent : public CHeapObj { public: PlatformEvent() { int status; - status = pthread_cond_init (_cond, NULL); + status = pthread_cond_init (_cond, os::Linux::condAttr()); assert_status(status == 0, status, "cond_init"); status = pthread_mutex_init (_mutex, NULL); assert_status(status == 0, status, "mutex_init"); @@ -310,14 +317,19 @@ class PlatformEvent : public CHeapObj { void park () ; void unpark () ; int TryPark () ; - int park (jlong millis) ; + int park (jlong millis) ; // relative timed-wait only void SetAssociation (Thread * a) { _Assoc = a ; } } ; class PlatformParker : public CHeapObj { protected: + enum { + REL_INDEX = 0, + ABS_INDEX = 1 + }; + int _cur_index; // which cond is in use: -1, 0, 1 pthread_mutex_t _mutex [1] ; - pthread_cond_t _cond [1] ; + pthread_cond_t _cond [2] ; // one for relative times and one for abs. public: // TODO-FIXME: make dtor private ~PlatformParker() { guarantee (0, "invariant") ; } @@ -325,10 +337,13 @@ class PlatformParker : public CHeapObj { public: PlatformParker() { int status; - status = pthread_cond_init (_cond, NULL); - assert_status(status == 0, status, "cond_init"); + status = pthread_cond_init (&_cond[REL_INDEX], os::Linux::condAttr()); + assert_status(status == 0, status, "cond_init rel"); + status = pthread_cond_init (&_cond[ABS_INDEX], NULL); + assert_status(status == 0, status, "cond_init abs"); status = pthread_mutex_init (_mutex, NULL); assert_status(status == 0, status, "mutex_init"); + _cur_index = -1; // mark as unused } }; From 315696de0025ff317cd5cb0e28d4f26cc13b16e7 Mon Sep 17 00:00:00 2001 From: Jan Lahoda Date: Mon, 16 Sep 2013 14:13:44 +0200 Subject: [PATCH 173/210] 8021112: Spurious unchecked warning reported by javac 6480588: No way to suppress deprecation warnings when implementing deprecated interface Fixing DeferredLintHandler configuration, so lint warnings are reported with correct @SuppressWarnings settings Reviewed-by: jjg, vromero --- .../tools/javac/code/DeferredLintHandler.java | 73 +++++- .../com/sun/tools/javac/code/Symbol.java | 5 +- .../com/sun/tools/javac/comp/Attr.java | 40 ++-- .../com/sun/tools/javac/comp/Check.java | 31 +-- .../com/sun/tools/javac/comp/MemberEnter.java | 98 +++++--- .../depDocComment/SuppressDeprecation.out | 2 +- .../javac/warnings/6594914/T6594914a.out | 2 +- .../javac/warnings/6594914/T6594914b.out | 2 +- .../javac/warnings/suppress/ImplicitTest.java | 31 +++ .../javac/warnings/suppress/ImplicitTest.out | 2 + .../javac/warnings/suppress/PackageInfo.java | 30 +++ .../javac/warnings/suppress/PackageInfo.out | 3 + .../javac/warnings/suppress/T6480588.java | 36 +++ .../javac/warnings/suppress/T6480588.out | 18 ++ .../javac/warnings/suppress/T8021112a.java | 45 ++++ .../javac/warnings/suppress/T8021112b.java | 22 ++ .../javac/warnings/suppress/T8021112b.out | 3 + .../warnings/suppress/TypeAnnotations.java | 51 +++++ .../warnings/suppress/TypeAnnotations.out | 41 ++++ .../suppress/VerifySuppressWarnings.java | 212 ++++++++++++++++++ .../suppress/pack/DeprecatedClass.java | 5 + .../warnings/suppress/pack/ImplicitMain.java | 14 ++ .../warnings/suppress/pack/ImplicitUse.java | 7 + .../warnings/suppress/pack/package-info.java | 5 + 24 files changed, 687 insertions(+), 91 deletions(-) create mode 100644 langtools/test/tools/javac/warnings/suppress/ImplicitTest.java create mode 100644 langtools/test/tools/javac/warnings/suppress/ImplicitTest.out create mode 100644 langtools/test/tools/javac/warnings/suppress/PackageInfo.java create mode 100644 langtools/test/tools/javac/warnings/suppress/PackageInfo.out create mode 100644 langtools/test/tools/javac/warnings/suppress/T6480588.java create mode 100644 langtools/test/tools/javac/warnings/suppress/T6480588.out create mode 100644 langtools/test/tools/javac/warnings/suppress/T8021112a.java create mode 100644 langtools/test/tools/javac/warnings/suppress/T8021112b.java create mode 100644 langtools/test/tools/javac/warnings/suppress/T8021112b.out create mode 100644 langtools/test/tools/javac/warnings/suppress/TypeAnnotations.java create mode 100644 langtools/test/tools/javac/warnings/suppress/TypeAnnotations.out create mode 100644 langtools/test/tools/javac/warnings/suppress/VerifySuppressWarnings.java create mode 100644 langtools/test/tools/javac/warnings/suppress/pack/DeprecatedClass.java create mode 100644 langtools/test/tools/javac/warnings/suppress/pack/ImplicitMain.java create mode 100644 langtools/test/tools/javac/warnings/suppress/pack/ImplicitUse.java create mode 100644 langtools/test/tools/javac/warnings/suppress/pack/package-info.java diff --git a/langtools/src/share/classes/com/sun/tools/javac/code/DeferredLintHandler.java b/langtools/src/share/classes/com/sun/tools/javac/code/DeferredLintHandler.java index 022681bd8f6..9392046bb2d 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/code/DeferredLintHandler.java +++ b/langtools/src/share/classes/com/sun/tools/javac/code/DeferredLintHandler.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2013, 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 @@ -28,6 +28,8 @@ package com.sun.tools.javac.code; import java.util.HashMap; import java.util.Map; +import com.sun.tools.javac.tree.EndPosTable; +import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.util.Assert; import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; @@ -53,10 +55,13 @@ public class DeferredLintHandler { protected DeferredLintHandler(Context context) { context.put(deferredLintHandlerKey, this); + this.currentPos = IMMEDIATE_POSITION; } - private DeferredLintHandler() {} - + /**An interface for deferred lint reporting - loggers passed to + * {@link #report(LintLogger) } will be called when + * {@link #flush(DiagnosticPosition) } is invoked. + */ public interface LintLogger { void report(); } @@ -64,12 +69,26 @@ public class DeferredLintHandler { private DiagnosticPosition currentPos; private Map> loggersQueue = new HashMap>(); + /**Associate the given logger with the current position as set by {@link #setPos(DiagnosticPosition) }. + * Will be invoked when {@link #flush(DiagnosticPosition) } will be invoked with the same position. + *
    + * Will invoke the logger synchronously if {@link #immediate() } was called + * instead of {@link #setPos(DiagnosticPosition) }. + */ public void report(LintLogger logger) { - ListBuffer loggers = loggersQueue.get(currentPos); - Assert.checkNonNull(loggers); - loggers.append(logger); + if (currentPos == IMMEDIATE_POSITION) { + logger.report(); + } else { + ListBuffer loggers = loggersQueue.get(currentPos); + if (loggers == null) { + loggersQueue.put(currentPos, loggers = ListBuffer.lb()); + } + loggers.append(logger); + } } + /**Invoke all {@link LintLogger}s that were associated with the provided {@code pos}. + */ public void flush(DiagnosticPosition pos) { ListBuffer loggers = loggersQueue.get(pos); if (loggers != null) { @@ -80,16 +99,46 @@ public class DeferredLintHandler { } } - public DeferredLintHandler setPos(DiagnosticPosition currentPos) { + /**Sets the current position to the provided {@code currentPos}. {@link LintLogger}s + * passed to subsequent invocations of {@link #report(LintLogger) } will be associated + * with the given position. + */ + public DiagnosticPosition setPos(DiagnosticPosition currentPos) { + DiagnosticPosition prevPosition = this.currentPos; this.currentPos = currentPos; - loggersQueue.put(currentPos, ListBuffer.lb()); - return this; + return prevPosition; } - public static final DeferredLintHandler immediateHandler = new DeferredLintHandler() { + /**{@link LintLogger}s passed to subsequent invocations of + * {@link #report(LintLogger) } will be invoked immediately. + */ + public DiagnosticPosition immediate() { + return setPos(IMMEDIATE_POSITION); + } + + private static final DiagnosticPosition IMMEDIATE_POSITION = new DiagnosticPosition() { @Override - public void report(LintLogger logger) { - logger.report(); + public JCTree getTree() { + Assert.error(); + return null; + } + + @Override + public int getStartPosition() { + Assert.error(); + return -1; + } + + @Override + public int getPreferredPosition() { + Assert.error(); + return -1; + } + + @Override + public int getEndPosition(EndPosTable endPosTable) { + Assert.error(); + return -1; } }; } diff --git a/langtools/src/share/classes/com/sun/tools/javac/code/Symbol.java b/langtools/src/share/classes/com/sun/tools/javac/code/Symbol.java index d7552ee2a9e..65459ec3daf 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/code/Symbol.java +++ b/langtools/src/share/classes/com/sun/tools/javac/code/Symbol.java @@ -46,6 +46,7 @@ import static com.sun.tools.javac.code.Kinds.*; import static com.sun.tools.javac.code.TypeTag.CLASS; import static com.sun.tools.javac.code.TypeTag.FORALL; import static com.sun.tools.javac.code.TypeTag.TYPEVAR; +import com.sun.tools.javac.tree.JCTree.JCVariableDecl; /** Root class for Java symbols. It contains subclasses * for specific sorts of symbols, such as variables, methods and operators, @@ -1167,11 +1168,11 @@ public abstract class Symbol implements Element { public void setLazyConstValue(final Env env, final Attr attr, - final JCTree.JCExpression initializer) + final JCVariableDecl variable) { setData(new Callable() { public Object call() { - return attr.attribLazyConstantValue(env, initializer, type); + return attr.attribLazyConstantValue(env, variable, type); } }); } diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java b/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java index c09ab8907a2..cb2337f936c 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java @@ -748,19 +748,11 @@ public class Attr extends JCTree.Visitor { * @see VarSymbol#setLazyConstValue */ public Object attribLazyConstantValue(Env env, - JCTree.JCExpression initializer, + JCVariableDecl variable, Type type) { - /* When this env was created, it didn't have the correct lint nor had - * annotations has been processed. - * But now at this phase we have already processed annotations and the - * correct lint must have been set in chk, so we should use that one to - * attribute the initializer. - */ - Lint prevLint = env.info.lint; - env.info.lint = chk.getLint(); - - JavaFileObject prevSource = log.useSource(env.toplevel.sourcefile); + DiagnosticPosition prevLintPos + = deferredLintHandler.setPos(variable.pos()); try { // Use null as symbol to not attach the type annotation to any symbol. @@ -768,17 +760,16 @@ public class Attr extends JCTree.Visitor { // to the symbol. // This prevents having multiple type annotations, just because of // lazy constant value evaluation. - memberEnter.typeAnnotate(initializer, env, null); + memberEnter.typeAnnotate(variable.init, env, null, variable.pos()); annotate.flush(); - Type itype = attribExpr(initializer, env, type); + Type itype = attribExpr(variable.init, env, type); if (itype.constValue() != null) { return coerce(itype, type).constValue(); } else { return null; } } finally { - env.info.lint = prevLint; - log.useSource(prevSource); + deferredLintHandler.setPos(prevLintPos); } } @@ -1012,7 +1003,7 @@ public class Attr extends JCTree.Visitor { } // Attribute all type annotations in the body - memberEnter.typeAnnotate(tree.body, localEnv, m); + memberEnter.typeAnnotate(tree.body, localEnv, m, null); annotate.flush(); // Attribute method body. @@ -1042,7 +1033,7 @@ public class Attr extends JCTree.Visitor { } else { if (tree.init != null) { // Field initializer expression need to be entered. - memberEnter.typeAnnotate(tree.init, env, tree.sym); + memberEnter.typeAnnotate(tree.init, env, tree.sym, tree.pos()); annotate.flush(); } } @@ -1056,18 +1047,16 @@ public class Attr extends JCTree.Visitor { ((JCLambda)env.tree).paramKind == JCLambda.ParameterKind.IMPLICIT && (tree.sym.flags() & PARAMETER) != 0; chk.validate(tree.vartype, env, !isImplicitLambdaParameter); - deferredLintHandler.flush(tree.pos()); try { + v.getConstValue(); // ensure compile-time constant initializer is evaluated + deferredLintHandler.flush(tree.pos()); chk.checkDeprecatedAnnotation(tree.pos(), v); if (tree.init != null) { - if ((v.flags_field & FINAL) != 0 && - memberEnter.needsLazyConstValue(tree.init)) { - // In this case, `v' is final. Ensure that it's initializer is - // evaluated. - v.getConstValue(); // ensure initializer is evaluated - } else { + if ((v.flags_field & FINAL) == 0 || + !memberEnter.needsLazyConstValue(tree.init)) { + // Not a compile-time constant // Attribute initializer in a new environment // with the declared variable as owner. // Check that initializer conforms to variable's declared type. @@ -1106,7 +1095,7 @@ public class Attr extends JCTree.Visitor { if ((tree.flags & STATIC) != 0) localEnv.info.staticLevel++; // Attribute all type annotations in the block - memberEnter.typeAnnotate(tree, localEnv, localEnv.info.scope.owner); + memberEnter.typeAnnotate(tree, localEnv, localEnv.info.scope.owner, null); annotate.flush(); { @@ -4209,6 +4198,7 @@ public class Attr extends JCTree.Visitor { ResultInfo prevReturnRes = env.info.returnResult; try { + deferredLintHandler.flush(env.tree); env.info.returnResult = null; // java.lang.Enum may not be subclassed by a non-enum if (st.tsym == syms.enumSym && diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java b/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java index 2612741ac03..5f6d1886bd8 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java @@ -148,7 +148,7 @@ public class Check { sunApiHandler = new MandatoryWarningHandler(log, verboseSunApi, enforceMandatoryWarnings, "sunapi", null); - deferredLintHandler = DeferredLintHandler.immediateHandler; + deferredLintHandler = DeferredLintHandler.instance(context); } /** Switch: generics enabled? @@ -218,20 +218,6 @@ public class Check { return prev; } - /* This idiom should be used only in cases when it is needed to set the lint - * of an environment that has been created in a phase previous to annotations - * processing. - */ - Lint getLint() { - return lint; - } - - DeferredLintHandler setDeferredLintHandler(DeferredLintHandler newDeferredLintHandler) { - DeferredLintHandler prev = deferredLintHandler; - deferredLintHandler = newDeferredLintHandler; - return prev; - } - MethodSymbol setMethod(MethodSymbol newMethod) { MethodSymbol prev = method; method = newMethod; @@ -582,14 +568,19 @@ public class Check { /** Check for redundant casts (i.e. where source type is a subtype of target type) * The problem should only be reported for non-292 cast */ - public void checkRedundantCast(Env env, JCTypeCast tree) { - if (!tree.type.isErroneous() && - (env.info.lint == null || env.info.lint.isEnabled(Lint.LintCategory.CAST)) + public void checkRedundantCast(Env env, final JCTypeCast tree) { + if (!tree.type.isErroneous() && types.isSameType(tree.expr.type, tree.clazz.type) && !(ignoreAnnotatedCasts && TreeInfo.containsTypeAnnotation(tree.clazz)) && !is292targetTypeCast(tree)) { - log.warning(Lint.LintCategory.CAST, - tree.pos(), "redundant.cast", tree.expr.type); + deferredLintHandler.report(new DeferredLintHandler.LintLogger() { + @Override + public void report() { + if (lint.isEnabled(Lint.LintCategory.CAST)) + log.warning(Lint.LintCategory.CAST, + tree.pos(), "redundant.cast", tree.expr.type); + } + }); } } //where diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java b/langtools/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java index a2d021fbc36..634e875d5aa 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java @@ -84,6 +84,7 @@ public class MemberEnter extends JCTree.Visitor implements Completer { private final Source source; private final Target target; private final DeferredLintHandler deferredLintHandler; + private final Lint lint; public static MemberEnter instance(Context context) { MemberEnter instance = context.get(memberEnterKey); @@ -109,6 +110,7 @@ public class MemberEnter extends JCTree.Visitor implements Completer { source = Source.instance(context); target = Target.instance(context); deferredLintHandler = DeferredLintHandler.instance(context); + lint = Lint.instance(context); allowTypeAnnos = source.allowTypeAnnotations(); } @@ -506,9 +508,10 @@ public class MemberEnter extends JCTree.Visitor implements Completer { } // process package annotations - annotateLater(tree.packageAnnotations, env, tree.packge); + annotateLater(tree.packageAnnotations, env, tree.packge, null); - DeferredLintHandler prevLintHandler = chk.setDeferredLintHandler(DeferredLintHandler.immediateHandler); + DiagnosticPosition prevLintPos = deferredLintHandler.immediate(); + Lint prevLint = chk.setLint(lint); try { // Import-on-demand java.lang. @@ -517,7 +520,8 @@ public class MemberEnter extends JCTree.Visitor implements Completer { // Process all import clauses. memberEnter(tree.defs, env); } finally { - chk.setDeferredLintHandler(prevLintHandler); + chk.setLint(prevLint); + deferredLintHandler.setPos(prevLintPos); } } @@ -564,8 +568,7 @@ public class MemberEnter extends JCTree.Visitor implements Completer { Env localEnv = methodEnv(tree, env); - DeferredLintHandler prevLintHandler = - chk.setDeferredLintHandler(deferredLintHandler.setPos(tree.pos())); + DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos()); try { // Compute the method type m.type = signature(m, tree.typarams, tree.params, @@ -573,7 +576,7 @@ public class MemberEnter extends JCTree.Visitor implements Completer { tree.thrown, localEnv); } finally { - chk.setDeferredLintHandler(prevLintHandler); + deferredLintHandler.setPos(prevLintPos); } if (types.isSignaturePolymorphic(m)) { @@ -597,10 +600,10 @@ public class MemberEnter extends JCTree.Visitor implements Completer { if (chk.checkUnique(tree.pos(), m, enclScope)) { enclScope.enter(m); } - annotateLater(tree.mods.annotations, localEnv, m); + annotateLater(tree.mods.annotations, localEnv, m, tree.pos()); // Visit the signature of the method. Note that // TypeAnnotate doesn't descend into the body. - typeAnnotate(tree, localEnv, m); + typeAnnotate(tree, localEnv, m, tree.pos()); if (tree.defaultValue != null) annotateDefaultValueLater(tree.defaultValue, localEnv, m); @@ -630,15 +633,14 @@ public class MemberEnter extends JCTree.Visitor implements Completer { localEnv = env.dup(tree, env.info.dup()); localEnv.info.staticLevel++; } - DeferredLintHandler prevLintHandler = - chk.setDeferredLintHandler(deferredLintHandler.setPos(tree.pos())); + DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos()); try { if (TreeInfo.isEnumInit(tree)) { attr.attribIdentAsEnumType(localEnv, (JCIdent)tree.vartype); } else { // Make sure type annotations are processed. // But we don't have a symbol to attach them to yet - use null. - typeAnnotate(tree.vartype, env, null); + typeAnnotate(tree.vartype, env, null, tree.pos()); attr.attribType(tree.vartype, localEnv); if (tree.nameexpr != null) { attr.attribExpr(tree.nameexpr, localEnv); @@ -658,7 +660,7 @@ public class MemberEnter extends JCTree.Visitor implements Completer { } } } finally { - chk.setDeferredLintHandler(prevLintHandler); + deferredLintHandler.setPos(prevLintPos); } if ((tree.mods.flags & VARARGS) != 0) { @@ -680,15 +682,15 @@ public class MemberEnter extends JCTree.Visitor implements Completer { needsLazyConstValue(tree.init)) { Env initEnv = getInitEnv(tree, env); initEnv.info.enclVar = v; - v.setLazyConstValue(initEnv(tree, initEnv), attr, tree.init); + v.setLazyConstValue(initEnv(tree, initEnv), attr, tree); } } if (chk.checkUnique(tree.pos(), v, enclScope)) { chk.checkTransparentVar(tree.pos(), v, enclScope); enclScope.enter(v); } - annotateLater(tree.mods.annotations, localEnv, v); - typeAnnotate(tree.vartype, env, v); + annotateLater(tree.mods.annotations, localEnv, v, tree.pos()); + typeAnnotate(tree.vartype, env, v, tree.pos()); annotate.flush(); v.pos = tree.pos; } @@ -719,6 +721,11 @@ public class MemberEnter extends JCTree.Visitor implements Completer { result = false; } + @Override + public void visitNewArray(JCNewArray that) { + result = false; + } + @Override public void visitLambda(JCLambda that) { result = false; @@ -729,6 +736,11 @@ public class MemberEnter extends JCTree.Visitor implements Completer { result = false; } + @Override + public void visitApply(JCMethodInvocation that) { + result = false; + } + @Override public void visitSelect(JCFieldAccess tree) { tree.selected.accept(this); @@ -820,7 +832,8 @@ public class MemberEnter extends JCTree.Visitor implements Completer { /** Queue annotations for later processing. */ void annotateLater(final List annotations, final Env localEnv, - final Symbol s) { + final Symbol s, + final DiagnosticPosition deferPos) { if (annotations.isEmpty()) { return; } @@ -837,6 +850,11 @@ public class MemberEnter extends JCTree.Visitor implements Completer { public void enterAnnotation() { Assert.check(s.kind == PCK || s.annotationsPendingCompletion()); JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile); + DiagnosticPosition prevLintPos = + deferPos != null + ? deferredLintHandler.setPos(deferPos) + : deferredLintHandler.immediate(); + Lint prevLint = deferPos != null ? null : chk.setLint(lint); try { if (s.hasAnnotations() && annotations.nonEmpty()) @@ -845,6 +863,9 @@ public class MemberEnter extends JCTree.Visitor implements Completer { kindName(s), s); actualEnterAnnotations(annotations, localEnv, s); } finally { + if (prevLint != null) + chk.setLint(prevLint); + deferredLintHandler.setPos(prevLintPos); log.useSource(prev); } } @@ -964,6 +985,7 @@ public class MemberEnter extends JCTree.Visitor implements Completer { isFirst = false; JavaFileObject prev = log.useSource(env.toplevel.sourcefile); + DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos()); try { // Save class environment for later member enter (2) processing. halfcompleted.append(env); @@ -985,9 +1007,9 @@ public class MemberEnter extends JCTree.Visitor implements Completer { Env baseEnv = baseEnv(tree, env); if (tree.extending != null) - typeAnnotate(tree.extending, baseEnv, sym); + typeAnnotate(tree.extending, baseEnv, sym, tree.pos()); for (JCExpression impl : tree.implementing) - typeAnnotate(impl, baseEnv, sym); + typeAnnotate(impl, baseEnv, sym, tree.pos()); annotate.flush(); // Determine supertype. @@ -1048,7 +1070,7 @@ public class MemberEnter extends JCTree.Visitor implements Completer { attr.attribAnnotationTypes(tree.mods.annotations, baseEnv); if (hasDeprecatedAnnotation(tree.mods.annotations)) c.flags_field |= DEPRECATED; - annotateLater(tree.mods.annotations, baseEnv, c); + annotateLater(tree.mods.annotations, baseEnv, c, tree.pos()); // class type parameters use baseEnv but everything uses env chk.checkNonCyclicDecl(tree); @@ -1056,7 +1078,7 @@ public class MemberEnter extends JCTree.Visitor implements Completer { attr.attribTypeVariables(tree.typarams, baseEnv); // Do this here, where we have the symbol. for (JCTypeParameter tp : tree.typarams) - typeAnnotate(tp, baseEnv, sym); + typeAnnotate(tp, baseEnv, sym, tree.pos()); annotate.flush(); // Add default constructor if needed. @@ -1126,6 +1148,7 @@ public class MemberEnter extends JCTree.Visitor implements Completer { } catch (CompletionFailure ex) { chk.completionError(tree.pos(), ex); } finally { + deferredLintHandler.setPos(prevLintPos); log.useSource(prev); } @@ -1186,9 +1209,9 @@ public class MemberEnter extends JCTree.Visitor implements Completer { } } - public void typeAnnotate(final JCTree tree, final Env env, final Symbol sym) { + public void typeAnnotate(final JCTree tree, final Env env, final Symbol sym, DiagnosticPosition deferPos) { if (allowTypeAnnos) { - tree.accept(new TypeAnnotate(env, sym)); + tree.accept(new TypeAnnotate(env, sym, deferPos)); } } @@ -1199,10 +1222,12 @@ public class MemberEnter extends JCTree.Visitor implements Completer { private class TypeAnnotate extends TreeScanner { private Env env; private Symbol sym; + private DiagnosticPosition deferPos; - public TypeAnnotate(final Env env, final Symbol sym) { + public TypeAnnotate(final Env env, final Symbol sym, DiagnosticPosition deferPos) { this.env = env; this.sym = sym; + this.deferPos = deferPos; } void annotateTypeLater(final List annotations) { @@ -1210,6 +1235,8 @@ public class MemberEnter extends JCTree.Visitor implements Completer { return; } + final DiagnosticPosition deferPos = this.deferPos; + annotate.normal(new Annotate.Annotator() { @Override public String toString() { @@ -1218,9 +1245,16 @@ public class MemberEnter extends JCTree.Visitor implements Completer { @Override public void enterAnnotation() { JavaFileObject prev = log.useSource(env.toplevel.sourcefile); + DiagnosticPosition prevLintPos = null; + + if (deferPos != null) { + prevLintPos = deferredLintHandler.setPos(deferPos); + } try { actualEnterTypeAnnotations(annotations, env, sym); } finally { + if (prevLintPos != null) + deferredLintHandler.setPos(prevLintPos); log.useSource(prev); } } @@ -1262,13 +1296,19 @@ public class MemberEnter extends JCTree.Visitor implements Completer { @Override public void visitVarDef(final JCVariableDecl tree) { - if (sym != null && sym.kind == Kinds.VAR) { - // Don't visit a parameter once when the sym is the method - // and once when the sym is the parameter. - scan(tree.mods); - scan(tree.vartype); + DiagnosticPosition prevPos = deferPos; + deferPos = tree.pos(); + try { + if (sym != null && sym.kind == Kinds.VAR) { + // Don't visit a parameter once when the sym is the method + // and once when the sym is the parameter. + scan(tree.mods); + scan(tree.vartype); + } + scan(tree.init); + } finally { + deferPos = prevPos; } - scan(tree.init); } @Override diff --git a/langtools/test/tools/javac/depDocComment/SuppressDeprecation.out b/langtools/test/tools/javac/depDocComment/SuppressDeprecation.out index eb0c0ff686b..4a8b15f33fd 100644 --- a/langtools/test/tools/javac/depDocComment/SuppressDeprecation.out +++ b/langtools/test/tools/javac/depDocComment/SuppressDeprecation.out @@ -1,8 +1,8 @@ -SuppressDeprecation.java:130:17: compiler.warn.has.been.deprecated: X, compiler.misc.unnamed.package SuppressDeprecation.java:82:10: compiler.warn.has.been.deprecated: g(), T SuppressDeprecation.java:83:14: compiler.warn.has.been.deprecated: g(), T SuppressDeprecation.java:84:9: compiler.warn.has.been.deprecated: var, T SuppressDeprecation.java:87:9: compiler.warn.has.been.deprecated: T(), T SuppressDeprecation.java:90:9: compiler.warn.has.been.deprecated: T(int), T SuppressDeprecation.java:98:1: compiler.warn.has.been.deprecated: T(), T +SuppressDeprecation.java:130:17: compiler.warn.has.been.deprecated: X, compiler.misc.unnamed.package 7 warnings diff --git a/langtools/test/tools/javac/warnings/6594914/T6594914a.out b/langtools/test/tools/javac/warnings/6594914/T6594914a.out index d3d759ca044..62f99072a7a 100644 --- a/langtools/test/tools/javac/warnings/6594914/T6594914a.out +++ b/langtools/test/tools/javac/warnings/6594914/T6594914a.out @@ -1,7 +1,7 @@ T6594914a.java:11:5: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package T6594914a.java:16:16: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package -T6594914a.java:16:52: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package T6594914a.java:16:33: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package T6594914a.java:17:20: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package +T6594914a.java:16:52: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package T6594914a.java:24:9: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package 6 warnings diff --git a/langtools/test/tools/javac/warnings/6594914/T6594914b.out b/langtools/test/tools/javac/warnings/6594914/T6594914b.out index 652ad120d78..56e0794f1d8 100644 --- a/langtools/test/tools/javac/warnings/6594914/T6594914b.out +++ b/langtools/test/tools/javac/warnings/6594914/T6594914b.out @@ -1,7 +1,7 @@ T6594914b.java:11:13: compiler.warn.sun.proprietary: sun.misc.Lock T6594914b.java:16:24: compiler.warn.sun.proprietary: sun.misc.Lock -T6594914b.java:16:56: compiler.warn.sun.proprietary: sun.misc.Lock T6594914b.java:16:39: compiler.warn.sun.proprietary: sun.misc.Lock T6594914b.java:17:28: compiler.warn.sun.proprietary: sun.misc.CEFormatException +T6594914b.java:16:56: compiler.warn.sun.proprietary: sun.misc.Lock T6594914b.java:24:17: compiler.warn.sun.proprietary: sun.misc.Lock 6 warnings diff --git a/langtools/test/tools/javac/warnings/suppress/ImplicitTest.java b/langtools/test/tools/javac/warnings/suppress/ImplicitTest.java new file mode 100644 index 00000000000..1c4208ca902 --- /dev/null +++ b/langtools/test/tools/javac/warnings/suppress/ImplicitTest.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013, 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 8021112 + * @summary Verify that deprecated warning is printed correctly for import + * statement when processing a file on demand while attributing another file. + * @clean pack.ImplicitUse pack.ImplicitMain pack.Dep + * @compile/ref=ImplicitTest.out -XDrawDiagnostics -Xlint:deprecation pack/ImplicitMain.java + */ diff --git a/langtools/test/tools/javac/warnings/suppress/ImplicitTest.out b/langtools/test/tools/javac/warnings/suppress/ImplicitTest.out new file mode 100644 index 00000000000..be39624289b --- /dev/null +++ b/langtools/test/tools/javac/warnings/suppress/ImplicitTest.out @@ -0,0 +1,2 @@ +ImplicitUse.java:4:12: compiler.warn.has.been.deprecated: pack.Dep, pack +1 warning \ No newline at end of file diff --git a/langtools/test/tools/javac/warnings/suppress/PackageInfo.java b/langtools/test/tools/javac/warnings/suppress/PackageInfo.java new file mode 100644 index 00000000000..98a93102a7c --- /dev/null +++ b/langtools/test/tools/javac/warnings/suppress/PackageInfo.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2013, 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 8021112 + * @summary Verify that deprecated warnings are printed correctly for package-info.java + * @clean pack.package-info pack.DeprecatedClass + * @compile/ref=PackageInfo.out -XDrawDiagnostics -Xlint:deprecation pack/package-info.java pack/DeprecatedClass.java + */ diff --git a/langtools/test/tools/javac/warnings/suppress/PackageInfo.out b/langtools/test/tools/javac/warnings/suppress/PackageInfo.out new file mode 100644 index 00000000000..d1379ce82ab --- /dev/null +++ b/langtools/test/tools/javac/warnings/suppress/PackageInfo.out @@ -0,0 +1,3 @@ +package-info.java:5:12: compiler.warn.has.been.deprecated: pack.DeprecatedClass, pack +package-info.java:2:2: compiler.warn.has.been.deprecated: pack.DeprecatedClass, pack +2 warnings diff --git a/langtools/test/tools/javac/warnings/suppress/T6480588.java b/langtools/test/tools/javac/warnings/suppress/T6480588.java new file mode 100644 index 00000000000..88af4cca73d --- /dev/null +++ b/langtools/test/tools/javac/warnings/suppress/T6480588.java @@ -0,0 +1,36 @@ +/** + * @test /nodynamiccopyright/ + * @bug 6470588 + * @summary Verify that \\@SuppressWarnings("deprecation") works OK for all parts + * of class/method/field "header", including (declaration) annotations + * @build VerifySuppressWarnings + * @compile/ref=T6480588.out -XDrawDiagnostics -Xlint:unchecked,deprecation,cast T6480588.java + * @run main VerifySuppressWarnings T6480588.java + */ + +@DeprecatedAnnotation +class T6480588 extends DeprecatedClass implements DeprecatedInterface { + @DeprecatedAnnotation + public DeprecatedClass method(DeprecatedClass param) throws DeprecatedClass { + DeprecatedClass lv = new DeprecatedClass(); + @Deprecated + DeprecatedClass lvd = new DeprecatedClass(); + return null; + } + + @Deprecated + public void methodD() { + } + + @DeprecatedAnnotation + DeprecatedClass field = new DeprecatedClass(); + + @DeprecatedAnnotation + class Inner extends DeprecatedClass implements DeprecatedInterface { + } + +} + +@Deprecated class DeprecatedClass extends Throwable { } +@Deprecated interface DeprecatedInterface { } +@Deprecated @interface DeprecatedAnnotation { } diff --git a/langtools/test/tools/javac/warnings/suppress/T6480588.out b/langtools/test/tools/javac/warnings/suppress/T6480588.out new file mode 100644 index 00000000000..6e6f36739f3 --- /dev/null +++ b/langtools/test/tools/javac/warnings/suppress/T6480588.out @@ -0,0 +1,18 @@ +T6480588.java:12:24: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package +T6480588.java:12:51: compiler.warn.has.been.deprecated: DeprecatedInterface, compiler.misc.unnamed.package +T6480588.java:11:2: compiler.warn.has.been.deprecated: DeprecatedAnnotation, compiler.misc.unnamed.package +T6480588.java:14:12: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package +T6480588.java:14:65: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package +T6480588.java:13:6: compiler.warn.has.been.deprecated: DeprecatedAnnotation, compiler.misc.unnamed.package +T6480588.java:14:35: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package +T6480588.java:15:9: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package +T6480588.java:15:34: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package +T6480588.java:17:9: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package +T6480588.java:17:35: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package +T6480588.java:26:5: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package +T6480588.java:25:6: compiler.warn.has.been.deprecated: DeprecatedAnnotation, compiler.misc.unnamed.package +T6480588.java:26:33: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package +T6480588.java:29:25: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package +T6480588.java:29:52: compiler.warn.has.been.deprecated: DeprecatedInterface, compiler.misc.unnamed.package +T6480588.java:28:6: compiler.warn.has.been.deprecated: DeprecatedAnnotation, compiler.misc.unnamed.package +17 warnings \ No newline at end of file diff --git a/langtools/test/tools/javac/warnings/suppress/T8021112a.java b/langtools/test/tools/javac/warnings/suppress/T8021112a.java new file mode 100644 index 00000000000..4e8b69895fa --- /dev/null +++ b/langtools/test/tools/javac/warnings/suppress/T8021112a.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2013, 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. + */ +package test; + +/** + * @test + * @bug 8021112 + * @summary Verify that \\@SuppressWarnings work even if the value is defined + * inside the suppressed class itself, and verify that "unnecessary cast" + * lint can be properly suppressed. + * @compile -Xlint:cast -Werror T8021112a.java + */ + +import static test.T8021112a.D; + +@SuppressWarnings(D) +public class T8021112a { + public static final String D = (String) "cast"; +} + +class Other { + public static final String D = "cast"; + @SuppressWarnings(D) + public static final String D2 = (String) "cast"; +} diff --git a/langtools/test/tools/javac/warnings/suppress/T8021112b.java b/langtools/test/tools/javac/warnings/suppress/T8021112b.java new file mode 100644 index 00000000000..eb391bb1753 --- /dev/null +++ b/langtools/test/tools/javac/warnings/suppress/T8021112b.java @@ -0,0 +1,22 @@ +/** + * @test /nodynamiccopyright/ + * @bug 8021112 + * @summary Verify that \\@SuppressWarnings("unchecked") works correctly for lazy attrib values + * @build VerifySuppressWarnings + * @compile/ref=T8021112b.out -XDrawDiagnostics -Xlint:unchecked,deprecation,cast T8021112b.java + * @run main VerifySuppressWarnings T8021112b.java + */ + +public class T8021112b { + public static final String D1 = Dep.D; + public static final String D2 = ""; + public static final Object[] o = { + new Object() { + Dep d; + } + }; +} + +@Deprecated class Dep { + public static final String D = T8021112b.D2; +} diff --git a/langtools/test/tools/javac/warnings/suppress/T8021112b.out b/langtools/test/tools/javac/warnings/suppress/T8021112b.out new file mode 100644 index 00000000000..bc45f324cde --- /dev/null +++ b/langtools/test/tools/javac/warnings/suppress/T8021112b.out @@ -0,0 +1,3 @@ +T8021112b.java:11:37: compiler.warn.has.been.deprecated: Dep, compiler.misc.unnamed.package +T8021112b.java:15:13: compiler.warn.has.been.deprecated: Dep, compiler.misc.unnamed.package +2 warnings \ No newline at end of file diff --git a/langtools/test/tools/javac/warnings/suppress/TypeAnnotations.java b/langtools/test/tools/javac/warnings/suppress/TypeAnnotations.java new file mode 100644 index 00000000000..58d63bc9bd0 --- /dev/null +++ b/langtools/test/tools/javac/warnings/suppress/TypeAnnotations.java @@ -0,0 +1,51 @@ +/** + * @test /nodynamiccopyright/ + * @bug 8021112 + * @summary Verify that \\@SuppressWarnings("unchecked") works for type annotations + * @build VerifySuppressWarnings + * @compile/ref=TypeAnnotations.out -XDrawDiagnostics -Xlint:unchecked,deprecation,cast TypeAnnotations.java + * @run main VerifySuppressWarnings TypeAnnotations.java + */ + +import java.lang.annotation.*; + +public class TypeAnnotations extends @TA Object implements @TA Runnable { + + public @TA String @TA [] m(@TA String @TA [] p) throws @TA Throwable { + Runnable r = () -> { + @TA Object tested = null; + @TA boolean isAnnotated = tested instanceof @TA String; + }; + + @TA Object tested = null; + @TA boolean isAnnotated = tested instanceof @TA String; + + return (@TA String @TA []) null; + } + + { + Runnable r = () -> { + @TA Object tested = null; + @TA boolean isAnnotated = tested instanceof @TA String; + }; + + @TA Object tested = null; + @TA boolean isAnnotated = tested instanceof @TA String; + + @TA String @TA [] ret = (@TA String @TA []) null; + } + + @TA String @TA [] f = new @TA String @TA[0]; + + @Override public void run() { } + + public static class Inner extends @TA Object implements @TA Runnable { + @Override public void run() { } + } +} + +@Target({ElementType.TYPE_USE, ElementType.TYPE}) +@Deprecated +@interface TA { + +} diff --git a/langtools/test/tools/javac/warnings/suppress/TypeAnnotations.out b/langtools/test/tools/javac/warnings/suppress/TypeAnnotations.out new file mode 100644 index 00000000000..52a5484ea5e --- /dev/null +++ b/langtools/test/tools/javac/warnings/suppress/TypeAnnotations.out @@ -0,0 +1,41 @@ +TypeAnnotations.java:12:39: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package +TypeAnnotations.java:12:61: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package +TypeAnnotations.java:14:24: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package +TypeAnnotations.java:14:61: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package +TypeAnnotations.java:14:13: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package +TypeAnnotations.java:14:44: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package +TypeAnnotations.java:14:33: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package +TypeAnnotations.java:23:29: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package +TypeAnnotations.java:23:18: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package +TypeAnnotations.java:16:14: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package +TypeAnnotations.java:17:58: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package +TypeAnnotations.java:17:14: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package +TypeAnnotations.java:17:58: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package +TypeAnnotations.java:20:10: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package +TypeAnnotations.java:21:54: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package +TypeAnnotations.java:21:10: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package +TypeAnnotations.java:21:54: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package +TypeAnnotations.java:23:18: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package +TypeAnnotations.java:23:29: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package +TypeAnnotations.java:28:14: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package +TypeAnnotations.java:29:58: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package +TypeAnnotations.java:29:14: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package +TypeAnnotations.java:29:58: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package +TypeAnnotations.java:32:10: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package +TypeAnnotations.java:33:54: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package +TypeAnnotations.java:33:10: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package +TypeAnnotations.java:33:54: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package +TypeAnnotations.java:35:46: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package +TypeAnnotations.java:35:35: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package +TypeAnnotations.java:35:21: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package +TypeAnnotations.java:35:10: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package +TypeAnnotations.java:35:35: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package +TypeAnnotations.java:35:46: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package +TypeAnnotations.java:38:17: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package +TypeAnnotations.java:38:6: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package +TypeAnnotations.java:38:43: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package +TypeAnnotations.java:38:32: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package +TypeAnnotations.java:38:32: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package +TypeAnnotations.java:42:40: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package +TypeAnnotations.java:42:62: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package +40 warnings \ No newline at end of file diff --git a/langtools/test/tools/javac/warnings/suppress/VerifySuppressWarnings.java b/langtools/test/tools/javac/warnings/suppress/VerifySuppressWarnings.java new file mode 100644 index 00000000000..037f2a1764a --- /dev/null +++ b/langtools/test/tools/javac/warnings/suppress/VerifySuppressWarnings.java @@ -0,0 +1,212 @@ +/* + * Copyright (c) 2013, 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 com.sun.source.tree.ClassTree; +import com.sun.source.tree.CompilationUnitTree; +import com.sun.source.tree.MethodTree; +import com.sun.source.tree.NewClassTree; +import com.sun.source.tree.Tree; +import com.sun.source.tree.VariableTree; +import com.sun.source.util.JavacTask; +import com.sun.source.util.TreeScanner; +import com.sun.source.util.Trees; +import com.sun.tools.javac.api.JavacTool; +import com.sun.tools.javac.code.Flags; +import com.sun.tools.javac.file.JavacFileManager; +import com.sun.tools.javac.tree.JCTree.JCMethodDecl; +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import javax.tools.Diagnostic; +import javax.tools.DiagnosticListener; +import javax.tools.FileObject; +import javax.tools.ForwardingJavaFileManager; +import javax.tools.JavaFileManager; +import javax.tools.JavaFileObject; +import javax.tools.SimpleJavaFileObject; + +/**Takes a source file, parses it once to get the warnings inside the file and + * then for each and every declaration in the file, it tries to place + * the @SuppressWarnings annotation on the declaration and verifies than no + * warnings are produced inside the declaration, but all are produced outside it. + * + * Currently only works with unchecked,deprecation,cast warnings. + */ +public class VerifySuppressWarnings { + + private static final List STANDARD_PARAMS = Arrays.asList("-Xlint:unchecked,deprecation,cast", "-Xjcov"); + + public static void main(String... args) throws IOException, URISyntaxException { + if (args.length != 1) throw new IllegalStateException("Must provide class name!"); + String testContent = null; + List sourcePath = new ArrayList<>(); + for (String sourcePaths : System.getProperty("test.src.path").split(":")) { + sourcePath.add(new File(sourcePaths)); + } + JavacFileManager fm = JavacTool.create().getStandardFileManager(null, null, null); + for (File sp : sourcePath) { + File inp = new File(sp, args[0]); + + if (inp.canRead()) { + testContent = fm.getRegularFile(inp).getCharContent(true).toString(); + } + } + if (testContent == null) throw new IllegalStateException(); + final List> diagnostics = new ArrayList<>(); + DiagnosticListener collectDiagnostics = new DiagnosticListener() { + @Override public void report(Diagnostic diagnostic) { + diagnostics.add(diagnostic); + } + }; + JavaFileObject testFile = new TestFO(new URI("mem://" + args[0]), testContent); + JavacTask task = JavacTool.create().getTask(null, + new TestFM(fm), + collectDiagnostics, + STANDARD_PARAMS, + null, + Arrays.asList(testFile)); + final Trees trees = Trees.instance(task); + final CompilationUnitTree cut = task.parse().iterator().next(); + task.analyze(); + + final List declarationSpans = new ArrayList<>(); + + new TreeScanner() { + @Override public Void visitClass(ClassTree node, Void p) { + handleDeclaration(node); + return super.visitClass(node, p); + } + @Override public Void visitMethod(MethodTree node, Void p) { + handleDeclaration(node); + return super.visitMethod(node, p); + } + @Override public Void visitVariable(VariableTree node, Void p) { + handleDeclaration(node); + return super.visitVariable(node, p); + } + + @Override + public Void visitNewClass(NewClassTree node, Void p) { + if (node.getClassBody() != null) { + scan(node.getClassBody().getMembers(), null); + } + return null; + } + + private void handleDeclaration(Tree node) { + int endPos = (int) trees.getSourcePositions().getEndPosition(cut, node); + + if (endPos == (-1)) { + if (node.getKind() == Tree.Kind.METHOD && (((JCMethodDecl) node).getModifiers().flags & Flags.GENERATEDCONSTR) != 0) { + return ; + } + throw new IllegalStateException(); + } + + declarationSpans.add(new int[] {(int) trees.getSourcePositions().getStartPosition(cut, node), endPos}); + } + }.scan(cut, null); + + for (final int[] declarationSpan : declarationSpans) { + final String suppressWarnings = "@SuppressWarnings({\"deprecation\", \"unchecked\", \"serial\"})"; + final String updatedContent = testContent.substring(0, declarationSpan[0]) + suppressWarnings + testContent.substring(declarationSpan[0]); + final List> foundErrors = new ArrayList<>(diagnostics); + DiagnosticListener verifyDiagnostics = new DiagnosticListener() { + @Override public void report(Diagnostic diagnostic) { + long adjustedPos = diagnostic.getPosition(); + + if (adjustedPos >= declarationSpan[0]) adjustedPos -= suppressWarnings.length(); + + if (declarationSpan[0] <= adjustedPos && adjustedPos <= declarationSpan[1]) { + throw new IllegalStateException("unsuppressed: " + diagnostic.getMessage(null)); + } + + boolean found = false; + + for (Iterator> it = foundErrors.iterator(); it.hasNext();) { + Diagnostic d = it.next(); + if (d.getPosition() == adjustedPos && d.getCode().equals(diagnostic.getCode())) { + it.remove(); + found = true; + break; + } + } + + if (!found) { + throw new IllegalStateException("diagnostic not originally reported: " + diagnostic.getMessage(null)); + } + } + }; + + JavaFileObject updatedFile = new TestFO(new URI("mem://" + args[0]), updatedContent); + JavacTask testTask = JavacTool.create().getTask(null, + new TestFM(fm), + verifyDiagnostics, + STANDARD_PARAMS, + null, + Arrays.asList(updatedFile)); + + testTask.analyze(); + + for (Diagnostic d : foundErrors) { + if (d.getPosition() < declarationSpan[0] || declarationSpan[1] < d.getPosition()) { + throw new IllegalStateException("missing: " + d.getMessage(null)); + } + } + } + } + + private static final class TestFO extends SimpleJavaFileObject { + private final String content; + public TestFO(URI uri, String content) { + super(uri, Kind.SOURCE); + this.content = content; + } + + @Override public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { + return content; + } + + @Override public boolean isNameCompatible(String simpleName, Kind kind) { + return true; + } + } + + private static final class TestFM extends ForwardingJavaFileManager { + + public TestFM(JavaFileManager fileManager) { + super(fileManager); + } + + @Override + public boolean isSameFile(FileObject a, FileObject b) { + return a.equals(b); + } + + } +} diff --git a/langtools/test/tools/javac/warnings/suppress/pack/DeprecatedClass.java b/langtools/test/tools/javac/warnings/suppress/pack/DeprecatedClass.java new file mode 100644 index 00000000000..8b7a482298e --- /dev/null +++ b/langtools/test/tools/javac/warnings/suppress/pack/DeprecatedClass.java @@ -0,0 +1,5 @@ +/* /nodynamiccopyright/ */ +package pack; +@Deprecated +@interface DeprecatedClass { +} diff --git a/langtools/test/tools/javac/warnings/suppress/pack/ImplicitMain.java b/langtools/test/tools/javac/warnings/suppress/pack/ImplicitMain.java new file mode 100644 index 00000000000..22ed4e7def8 --- /dev/null +++ b/langtools/test/tools/javac/warnings/suppress/pack/ImplicitMain.java @@ -0,0 +1,14 @@ +/* /nodynamiccopyright/ */ +package pack; + +@SuppressWarnings("deprecation") +public class ImplicitMain { + private Object test() { + return new ImplicitUse(); + } +} + +@Deprecated +class Dep { + +} diff --git a/langtools/test/tools/javac/warnings/suppress/pack/ImplicitUse.java b/langtools/test/tools/javac/warnings/suppress/pack/ImplicitUse.java new file mode 100644 index 00000000000..9e9e6cd5916 --- /dev/null +++ b/langtools/test/tools/javac/warnings/suppress/pack/ImplicitUse.java @@ -0,0 +1,7 @@ +/* /nodynamiccopyright/ */ +package pack; + +import pack.Dep; + +public class ImplicitUse { +} diff --git a/langtools/test/tools/javac/warnings/suppress/pack/package-info.java b/langtools/test/tools/javac/warnings/suppress/pack/package-info.java new file mode 100644 index 00000000000..679de2b4f60 --- /dev/null +++ b/langtools/test/tools/javac/warnings/suppress/pack/package-info.java @@ -0,0 +1,5 @@ +/* /nodynamiccopyright/ */ +@DeprecatedClass +package pack; + +import pack.DeprecatedClass; From 4d540aa581e7f9ecb8b74cf519238d182b42e28d Mon Sep 17 00:00:00 2001 From: Mark Sheppard Date: Mon, 16 Sep 2013 14:51:48 +0100 Subject: [PATCH 174/210] 6458027: Disabling IPv6 on a specific network interface causes problems Added a check to test if an interface is configured for IPv6 to native code TwoStacklainDatagramSocketImpl: getMulticastInterface, setMulticastInterface Reviewed-by: chegar, michaelm --- .../native/java/net/NetworkInterface.c | 2 +- .../net/TwoStacksPlainDatagramSocketImpl.c | 160 ++++++++++++------ .../SetGetNetworkInterfaceTest.java | 125 ++++++++++++++ 3 files changed, 230 insertions(+), 57 deletions(-) create mode 100644 jdk/test/java/net/MulticastSocket/SetGetNetworkInterfaceTest.java diff --git a/jdk/src/windows/native/java/net/NetworkInterface.c b/jdk/src/windows/native/java/net/NetworkInterface.c index c548930a913..98606fab667 100644 --- a/jdk/src/windows/native/java/net/NetworkInterface.c +++ b/jdk/src/windows/native/java/net/NetworkInterface.c @@ -900,7 +900,7 @@ JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isUp0 MIB_IFROW *ifRowP; ifRowP = getIF(index); if (ifRowP != NULL) { - ret = ifRowP->dwAdminStatus == 1 && + ret = ifRowP->dwAdminStatus == MIB_IF_ADMIN_STATUS_UP && (ifRowP->dwOperStatus == MIB_IF_OPER_STATUS_OPERATIONAL || ifRowP->dwOperStatus == MIB_IF_OPER_STATUS_CONNECTED); free(ifRowP); diff --git a/jdk/src/windows/native/java/net/TwoStacksPlainDatagramSocketImpl.c b/jdk/src/windows/native/java/net/TwoStacksPlainDatagramSocketImpl.c index 5adadd28e0f..77496d195cf 100644 --- a/jdk/src/windows/native/java/net/TwoStacksPlainDatagramSocketImpl.c +++ b/jdk/src/windows/native/java/net/TwoStacksPlainDatagramSocketImpl.c @@ -43,6 +43,7 @@ #include "java_net_SocketOptions.h" #include "java_net_NetworkInterface.h" +#include "NetworkInterface.h" #include "jvm.h" #include "jni_util.h" #include "net_util.h" @@ -1644,6 +1645,33 @@ static int getIndexFromIf (JNIEnv *env, jobject nif) { return (*env)->GetIntField(env, nif, ni_indexID); } +static int isAdapterIpv6Enabled(JNIEnv *env, int index) { + netif *ifList, *curr; + int ipv6Enabled = 0; + if (getAllInterfacesAndAddresses (env, &ifList) < 0) { + return ipv6Enabled; + } + + /* search by index */ + curr = ifList; + while (curr != NULL) { + if (index == curr->index) { + break; + } + curr = curr->next; + } + + /* if found ipv6Index != 0 then interface is configured with IPV6 */ + if ((curr != NULL) && (curr->ipv6Index !=0)) { + ipv6Enabled = 1; + } + + /* release the interface list */ + free_netif(ifList); + + return ipv6Enabled; +} + /* * Sets the multicast interface. * @@ -1703,7 +1731,6 @@ static void setMulticastInterface(JNIEnv *env, jobject this, int fd, int fd1, struct in_addr in; in.s_addr = htonl(getInetAddress_addr(env, value)); - if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF, (const char*)&in, sizeof(in)) < 0) { NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", @@ -1734,19 +1761,20 @@ static void setMulticastInterface(JNIEnv *env, jobject this, int fd, int fd1, } index = (*env)->GetIntField(env, value, ni_indexID); - if (setsockopt(fd1, IPPROTO_IPV6, IPV6_MULTICAST_IF, + if ( isAdapterIpv6Enabled(env, index) != 0 ) { + if (setsockopt(fd1, IPPROTO_IPV6, IPV6_MULTICAST_IF, (const char*)&index, sizeof(index)) < 0) { - if (errno == EINVAL && index > 0) { - JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", - "IPV6_MULTICAST_IF failed (interface has IPv4 " - "address only?)"); - } else { - NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", + if (errno == EINVAL && index > 0) { + JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", + "IPV6_MULTICAST_IF failed (interface has IPv4 " + "address only?)"); + } else { + NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "Error setting socket option"); + } + return; } - return; } - /* If there are any IPv4 addresses on this interface then * repeat the operation on the IPv4 fd */ @@ -1797,7 +1825,6 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_socketNativeSetOption(JNIEnv *env char c; } optval; int ipv6_supported = ipv6_available(); - fd = getFD(env, this); if (ipv6_supported) { @@ -1898,42 +1925,21 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_socketNativeSetOption(JNIEnv *env } /* - * Return the multicast interface: * - * SocketOptions.IP_MULTICAST_IF - * IPv4: Query IPPROTO_IP/IP_MULTICAST_IF - * Create InetAddress - * IP_MULTICAST_IF returns struct ip_mreqn on 2.2 - * kernel but struct in_addr on 2.4 kernel - * IPv6: Query IPPROTO_IPV6 / IPV6_MULTICAST_IF or - * obtain from impl is Linux 2.2 kernel - * If index == 0 return InetAddress representing - * anyLocalAddress. - * If index > 0 query NetworkInterface by index - * and returns addrs[0] + * called by getMulticastInterface to retrieve a NetworkInterface + * configured for IPv4. + * The ipv4Mode parameter, is a closet boolean, which allows for a NULL return, + * or forces the creation of a NetworkInterface object with null data. + * It relates to its calling context in getMulticastInterface. + * ipv4Mode == 1, the context is IPV4 processing only. + * ipv4Mode == 0, the context is IPV6 processing * - * SocketOptions.IP_MULTICAST_IF2 - * IPv4: Query IPPROTO_IP/IP_MULTICAST_IF - * Query NetworkInterface by IP address and - * return the NetworkInterface that the address - * is bound too. - * IPv6: Query IPPROTO_IPV6 / IPV6_MULTICAST_IF - * (except Linux .2 kernel) - * Query NetworkInterface by index and - * return NetworkInterface. */ -jobject getMulticastInterface(JNIEnv *env, jobject this, int fd, int fd1, jint opt) { - jboolean isIPV4 = !ipv6_available() || fd1 == -1; - - /* - * IPv4 implementation - */ - if (isIPV4) { +static jobject getIPv4NetworkInterface (JNIEnv *env, jobject this, int fd, jint opt, int ipv4Mode) { static jclass inet4_class; static jmethodID inet4_ctrID; - static jclass ni_class; - static jmethodID ni_ctrID; + static jclass ni_class; static jmethodID ni_ctrID; static jfieldID ni_indexID; static jfieldID ni_addrsID; @@ -1944,7 +1950,6 @@ jobject getMulticastInterface(JNIEnv *env, jobject this, int fd, int fd1, jint o struct in_addr in; struct in_addr *inP = ∈ int len = sizeof(struct in_addr); - if (getsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF, (char *)inP, &len) < 0) { NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", @@ -1996,23 +2001,57 @@ jobject getMulticastInterface(JNIEnv *env, jobject this, int fd, int fd1, jint o if (ni) { return ni; } + if (ipv4Mode) { + ni = (*env)->NewObject(env, ni_class, ni_ctrID, 0); + CHECK_NULL_RETURN(ni, NULL); - /* - * The address doesn't appear to be bound at any known - * NetworkInterface. Therefore we construct a NetworkInterface - * with this address. - */ - ni = (*env)->NewObject(env, ni_class, ni_ctrID, 0); - CHECK_NULL_RETURN(ni, NULL); - - (*env)->SetIntField(env, ni, ni_indexID, -1); - addrArray = (*env)->NewObjectArray(env, 1, inet4_class, NULL); - CHECK_NULL_RETURN(addrArray, NULL); - (*env)->SetObjectArrayElement(env, addrArray, 0, addr); - (*env)->SetObjectField(env, ni, ni_addrsID, addrArray); + (*env)->SetIntField(env, ni, ni_indexID, -1); + addrArray = (*env)->NewObjectArray(env, 1, inet4_class, NULL); + CHECK_NULL_RETURN(addrArray, NULL); + (*env)->SetObjectArrayElement(env, addrArray, 0, addr); + (*env)->SetObjectField(env, ni, ni_addrsID, addrArray); + } else { + ni = NULL; + } return ni; - } +} +/* + * Return the multicast interface: + * + * SocketOptions.IP_MULTICAST_IF + * IPv4: Query IPPROTO_IP/IP_MULTICAST_IF + * Create InetAddress + * IP_MULTICAST_IF returns struct ip_mreqn on 2.2 + * kernel but struct in_addr on 2.4 kernel + * IPv6: Query IPPROTO_IPV6 / IPV6_MULTICAST_IF or + * obtain from impl is Linux 2.2 kernel + * If index == 0 return InetAddress representing + * anyLocalAddress. + * If index > 0 query NetworkInterface by index + * and returns addrs[0] + * + * SocketOptions.IP_MULTICAST_IF2 + * IPv4: Query IPPROTO_IP/IP_MULTICAST_IF + * Query NetworkInterface by IP address and + * return the NetworkInterface that the address + * is bound too. + * IPv6: Query IPPROTO_IPV6 / IPV6_MULTICAST_IF + * (except Linux .2 kernel) + * Query NetworkInterface by index and + * return NetworkInterface. + */ +jobject getMulticastInterface(JNIEnv *env, jobject this, int fd, int fd1, jint opt) { + jboolean isIPV4 = !ipv6_available() || fd1 == -1; + + /* + * IPv4 implementation + */ + if (isIPV4) { + jobject netObject = NULL; // return is either an addr or a netif + netObject = getIPv4NetworkInterface(env, this, fd, opt, 1); + return netObject; + } /* * IPv6 implementation @@ -2103,6 +2142,13 @@ jobject getMulticastInterface(JNIEnv *env, jobject this, int fd, int fd1, jint o addr = (*env)->GetObjectArrayElement(env, addrArray, 0); return addr; + } else if (index == 0) { // index == 0 typically means IPv6 not configured on the interfaces + // falling back to treat interface as configured for IPv4 + jobject netObject = NULL; + netObject = getIPv4NetworkInterface(env, this, fd, opt, 0); + if (netObject != NULL) { + return netObject; + } } /* @@ -2127,6 +2173,8 @@ jobject getMulticastInterface(JNIEnv *env, jobject this, int fd, int fd1, jint o } return NULL; } + + /* * Returns relevant info as a jint. * diff --git a/jdk/test/java/net/MulticastSocket/SetGetNetworkInterfaceTest.java b/jdk/test/java/net/MulticastSocket/SetGetNetworkInterfaceTest.java new file mode 100644 index 00000000000..b46bdbedbce --- /dev/null +++ b/jdk/test/java/net/MulticastSocket/SetGetNetworkInterfaceTest.java @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2013, 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 6458027 + * @summary Disabling IPv6 on a specific network interface causes problems. + * + */ + +import java.io.IOException; +import java.net.InetAddress; +import java.net.MulticastSocket; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.util.Arrays; +import java.util.Enumeration; + + +public class SetGetNetworkInterfaceTest { + + public static void main(String[] args) throws Exception { + + boolean passed = true; + try { + MulticastSocket ms = new MulticastSocket(); + Enumeration networkInterfaces = NetworkInterface + .getNetworkInterfaces(); + while (networkInterfaces.hasMoreElements()) { + NetworkInterface netIf = networkInterfaces.nextElement(); + if (isNetworkInterfaceTestable(netIf)) { + printNetIfDetails(netIf); + ms.setNetworkInterface(netIf); + NetworkInterface msNetIf = ms.getNetworkInterface(); + if (netIf.equals(msNetIf)) { + System.out.println(" OK"); + } else { + System.out.println("FAILED!!!"); + printNetIfDetails(msNetIf); + passed = false; + } + System.out.println("------------------"); + } + } + } catch (IOException e) { + e.printStackTrace(); + passed = false; + } + if (!passed) { + throw new RuntimeException("Test Fail"); + } + System.out.println("Test passed "); + } + + private static boolean isNetworkInterfaceTestable(NetworkInterface netIf) throws Exception { + System.out.println("checking netif == " + netIf.getName()); + return (netIf.isUp() && netIf.supportsMulticast() && isIpAddrAvailable(netIf)); + } + + private static boolean isIpAddrAvailable (NetworkInterface netIf) { + boolean ipAddrAvailable = false; + byte[] nullIpAddr = {'0', '0', '0', '0'}; + byte[] testIpAddr = null; + + Enumeration ipAddresses = netIf.getInetAddresses(); + while (ipAddresses.hasMoreElements()) { + InetAddress testAddr = ipAddresses.nextElement(); + testIpAddr = testAddr.getAddress(); + if ((testIpAddr != null) && (!Arrays.equals(testIpAddr, nullIpAddr))) { + ipAddrAvailable = true; + break; + } else { + System.out.println("ignore netif " + netIf.getName()); + } + } + return ipAddrAvailable; + } + + private static void printNetIfDetails(NetworkInterface ni) + throws SocketException { + System.out.println("Name " + ni.getName() + " index " + ni.getIndex()); + Enumeration en = ni.getInetAddresses(); + while (en.hasMoreElements()) { + System.out.println(" InetAdress: " + en.nextElement()); + } + System.out.println("HardwareAddress: " + createMacAddrString(ni)); + System.out.println("loopback: " + ni.isLoopback() + "; pointToPoint: " + + ni.isPointToPoint() + "; virtual: " + ni.isVirtual() + + "; MTU: " + ni.getMTU()); + } + + private static String createMacAddrString(NetworkInterface netIf) + throws SocketException { + byte[] macAddr = netIf.getHardwareAddress(); + StringBuilder sb = new StringBuilder(); + if (macAddr != null) { + for (int i = 0; i < macAddr.length; i++) { + sb.append(String.format("%02X%s", macAddr[i], + (i < macAddr.length - 1) ? "-" : "")); + } + } + return sb.toString(); + } +} From 43e0cb63278d4ab1a1b4443e1bee83daefbf751c Mon Sep 17 00:00:00 2001 From: Henry Jen Date: Mon, 16 Sep 2013 10:28:20 -0700 Subject: [PATCH 175/210] 8024874: Copy-paste typo in the spec for j.u.Comparator.thenComparing(Function, Comparator) Reviewed-by: mduigou --- jdk/src/share/classes/java/util/Comparator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jdk/src/share/classes/java/util/Comparator.java b/jdk/src/share/classes/java/util/Comparator.java index b19481df198..6f9d1663e69 100644 --- a/jdk/src/share/classes/java/util/Comparator.java +++ b/jdk/src/share/classes/java/util/Comparator.java @@ -230,7 +230,7 @@ public interface Comparator { * @param keyComparator the {@code Comparator} used to compare the sort key * @return a lexicographic-order comparator composed of this comparator * and then comparing on the key extracted by the keyExtractor function - * @throws NullPointerException if the argument is null. + * @throws NullPointerException if either argument is null. * @see #comparing(Function, Comparator) * @see #thenComparing(Comparator) * @since 1.8 From dffefd9ecfd231283a25f48e3a45c92fdeac11ba Mon Sep 17 00:00:00 2001 From: Gerald Thornbrugh Date: Mon, 16 Sep 2013 12:43:34 -0700 Subject: [PATCH 176/210] 6986195: correctly identify Ubuntu as the operating system in crash report instead of "Debian" Cleanup and document how various Linux release info files are used by print_distro_info(). Reviewed-by: dcubed, dsamersoff, coleenp, iklam, omajid --- hotspot/src/os/linux/vm/os_linux.cpp | 58 ++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/hotspot/src/os/linux/vm/os_linux.cpp b/hotspot/src/os/linux/vm/os_linux.cpp index de5a7686989..ec6adc5d3ea 100644 --- a/hotspot/src/os/linux/vm/os_linux.cpp +++ b/hotspot/src/os/linux/vm/os_linux.cpp @@ -2169,23 +2169,49 @@ void os::print_os_info(outputStream* st) { } // Try to identify popular distros. -// Most Linux distributions have /etc/XXX-release file, which contains -// the OS version string. Some have more than one /etc/XXX-release file -// (e.g. Mandrake has both /etc/mandrake-release and /etc/redhat-release.), -// so the order is important. +// Most Linux distributions have a /etc/XXX-release file, which contains +// the OS version string. Newer Linux distributions have a /etc/lsb-release +// file that also contains the OS version string. Some have more than one +// /etc/XXX-release file (e.g. Mandrake has both /etc/mandrake-release and +// /etc/redhat-release.), so the order is important. +// Any Linux that is based on Redhat (i.e. Oracle, Mandrake, Sun JDS...) have +// their own specific XXX-release file as well as a redhat-release file. +// Because of this the XXX-release file needs to be searched for before the +// redhat-release file. +// Since Red Hat has a lsb-release file that is not very descriptive the +// search for redhat-release needs to be before lsb-release. +// Since the lsb-release file is the new standard it needs to be searched +// before the older style release files. +// Searching system-release (Red Hat) and os-release (other Linuxes) are a +// next to last resort. The os-release file is a new standard that contains +// distribution information and the system-release file seems to be an old +// standard that has been replaced by the lsb-release and os-release files. +// Searching for the debian_version file is the last resort. It contains +// an informative string like "6.0.6" or "wheezy/sid". Because of this +// "Debian " is printed before the contents of the debian_version file. void os::Linux::print_distro_info(outputStream* st) { - if (!_print_ascii_file("/etc/mandrake-release", st) && - !_print_ascii_file("/etc/sun-release", st) && - !_print_ascii_file("/etc/redhat-release", st) && - !_print_ascii_file("/etc/SuSE-release", st) && - !_print_ascii_file("/etc/turbolinux-release", st) && - !_print_ascii_file("/etc/gentoo-release", st) && - !_print_ascii_file("/etc/debian_version", st) && - !_print_ascii_file("/etc/ltib-release", st) && - !_print_ascii_file("/etc/angstrom-version", st)) { - st->print("Linux"); - } - st->cr(); + if (!_print_ascii_file("/etc/oracle-release", st) && + !_print_ascii_file("/etc/mandriva-release", st) && + !_print_ascii_file("/etc/mandrake-release", st) && + !_print_ascii_file("/etc/sun-release", st) && + !_print_ascii_file("/etc/redhat-release", st) && + !_print_ascii_file("/etc/lsb-release", st) && + !_print_ascii_file("/etc/SuSE-release", st) && + !_print_ascii_file("/etc/turbolinux-release", st) && + !_print_ascii_file("/etc/gentoo-release", st) && + !_print_ascii_file("/etc/ltib-release", st) && + !_print_ascii_file("/etc/angstrom-version", st) && + !_print_ascii_file("/etc/system-release", st) && + !_print_ascii_file("/etc/os-release", st)) { + + if (file_exists("/etc/debian_version")) { + st->print("Debian "); + _print_ascii_file("/etc/debian_version", st); + } else { + st->print("Linux"); + } + } + st->cr(); } void os::Linux::print_libversion_info(outputStream* st) { From 9505ddf1e2ac35d74071f4425bdeba180c11a46a Mon Sep 17 00:00:00 2001 From: Karen Kinnear Date: Mon, 16 Sep 2013 17:57:56 -0400 Subject: [PATCH 177/210] 8024647: Default method resolution with private superclass method Reviewed-by: kamg, minqi --- .../src/share/vm/classfile/defaultMethods.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/hotspot/src/share/vm/classfile/defaultMethods.cpp b/hotspot/src/share/vm/classfile/defaultMethods.cpp index b59fe66e062..99a45b55b6d 100644 --- a/hotspot/src/share/vm/classfile/defaultMethods.cpp +++ b/hotspot/src/share/vm/classfile/defaultMethods.cpp @@ -450,6 +450,10 @@ class MethodFamily : public ResourceObj { streamIndentor si(str, indent * 2); str->indent().print("Selected method: "); print_method(str, _selected_target); + Klass* method_holder = _selected_target->method_holder(); + if (!method_holder->is_interface()) { + tty->print(" : in superclass"); + } str->print_cr(""); } @@ -1141,19 +1145,23 @@ static void create_overpasses( #endif // ndef PRODUCT if (method->has_target()) { Method* selected = method->get_selected_target(); - max_stack = assemble_redirect( + if (selected->method_holder()->is_interface()) { + max_stack = assemble_redirect( &bpool, &buffer, slot->signature(), selected, CHECK); + } } else if (method->throws_exception()) { max_stack = assemble_abstract_method_error( &bpool, &buffer, method->get_exception_message(), CHECK); } - AccessFlags flags = accessFlags_from( + if (max_stack != 0) { + AccessFlags flags = accessFlags_from( JVM_ACC_PUBLIC | JVM_ACC_SYNTHETIC | JVM_ACC_BRIDGE); - Method* m = new_method(&bpool, &buffer, slot->name(), slot->signature(), + Method* m = new_method(&bpool, &buffer, slot->name(), slot->signature(), flags, max_stack, slot->size_of_parameters(), ConstMethod::OVERPASS, CHECK); - if (m != NULL) { - overpasses.push(m); + if (m != NULL) { + overpasses.push(m); + } } } } From 0cd7bc2cde5d0042634e25b269501235707fea7c Mon Sep 17 00:00:00 2001 From: Yumin Qi Date: Mon, 16 Sep 2013 15:35:04 -0700 Subject: [PATCH 178/210] 7164841: Improvements to the GC log file rotation Made changes to easily identify current log file in rotation. Parameterize the input with %t for time replacement in file name. Reviewed-by: ccheung, tschatzl, tamao, zgu --- hotspot/src/share/vm/prims/jni.cpp | 2 + hotspot/src/share/vm/runtime/arguments.cpp | 54 ++- hotspot/src/share/vm/utilities/ostream.cpp | 385 ++++++++++++++++----- hotspot/src/share/vm/utilities/ostream.hpp | 18 +- 4 files changed, 357 insertions(+), 102 deletions(-) diff --git a/hotspot/src/share/vm/prims/jni.cpp b/hotspot/src/share/vm/prims/jni.cpp index ea44e2c6679..4fba6577d82 100644 --- a/hotspot/src/share/vm/prims/jni.cpp +++ b/hotspot/src/share/vm/prims/jni.cpp @@ -5037,6 +5037,7 @@ _JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_GetDefaultJavaVMInitArgs(void *args_) { #include "gc_implementation/g1/heapRegionRemSet.hpp" #endif #include "utilities/quickSort.hpp" +#include "utilities/ostream.hpp" #if INCLUDE_VM_STRUCTS #include "runtime/vmStructs.hpp" #endif @@ -5060,6 +5061,7 @@ void execute_internal_vm_tests() { run_unit_test(CollectedHeap::test_is_in()); run_unit_test(QuickSort::test_quick_sort()); run_unit_test(AltHashing::test_alt_hash()); + run_unit_test(test_loggc_filename()); #if INCLUDE_VM_STRUCTS run_unit_test(VMStructs::test()); #endif diff --git a/hotspot/src/share/vm/runtime/arguments.cpp b/hotspot/src/share/vm/runtime/arguments.cpp index d8a6f90eeef..ef4da6da740 100644 --- a/hotspot/src/share/vm/runtime/arguments.cpp +++ b/hotspot/src/share/vm/runtime/arguments.cpp @@ -1839,7 +1839,7 @@ void check_gclog_consistency() { (NumberOfGCLogFiles == 0) || (GCLogFileSize == 0)) { jio_fprintf(defaultStream::output_stream(), - "To enable GC log rotation, use -Xloggc: -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles= -XX:GCLogFileSize=\n" + "To enable GC log rotation, use -Xloggc: -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles= -XX:GCLogFileSize=[k|K|m|M|g|G]\n" "where num_of_file > 0 and num_of_size > 0\n" "GC log rotation is turned off\n"); UseGCLogFileRotation = false; @@ -1853,6 +1853,51 @@ void check_gclog_consistency() { } } +// This function is called for -Xloggc:, it can be used +// to check if a given file name(or string) conforms to the following +// specification: +// A valid string only contains "[A-Z][a-z][0-9].-_%[p|t]" +// %p and %t only allowed once. We only limit usage of filename not path +bool is_filename_valid(const char *file_name) { + const char* p = file_name; + char file_sep = os::file_separator()[0]; + const char* cp; + // skip prefix path + for (cp = file_name; *cp != '\0'; cp++) { + if (*cp == '/' || *cp == file_sep) { + p = cp + 1; + } + } + + int count_p = 0; + int count_t = 0; + while (*p != '\0') { + if ((*p >= '0' && *p <= '9') || + (*p >= 'A' && *p <= 'Z') || + (*p >= 'a' && *p <= 'z') || + *p == '-' || + *p == '_' || + *p == '.') { + p++; + continue; + } + if (*p == '%') { + if(*(p + 1) == 'p') { + p += 2; + count_p ++; + continue; + } + if (*(p + 1) == 't') { + p += 2; + count_t ++; + continue; + } + } + return false; + } + return count_p < 2 && count_t < 2; +} + // Check consistency of GC selection bool Arguments::check_gc_consistency() { check_gclog_consistency(); @@ -2806,6 +2851,13 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, // ostream_init_log(), when called will use this filename // to initialize a fileStream. _gc_log_filename = strdup(tail); + if (!is_filename_valid(_gc_log_filename)) { + jio_fprintf(defaultStream::output_stream(), + "Invalid file name for use with -Xloggc: Filename can only contain the " + "characters [A-Z][a-z][0-9]-_.%%[p|t] but it has been %s\n" + "Note %%p or %%t can only be used once\n", _gc_log_filename); + return JNI_EINVAL; + } FLAG_SET_CMDLINE(bool, PrintGC, true); FLAG_SET_CMDLINE(bool, PrintGCTimeStamps, true); diff --git a/hotspot/src/share/vm/utilities/ostream.cpp b/hotspot/src/share/vm/utilities/ostream.cpp index 2f04fa0e437..0ad9b9eb0dd 100644 --- a/hotspot/src/share/vm/utilities/ostream.cpp +++ b/hotspot/src/share/vm/utilities/ostream.cpp @@ -342,7 +342,7 @@ void stringStream::write(const char* s, size_t len) { } char* stringStream::as_string() { - char* copy = NEW_RESOURCE_ARRAY(char, buffer_pos+1); + char* copy = NEW_RESOURCE_ARRAY(char, buffer_pos + 1); strncpy(copy, buffer, buffer_pos); copy[buffer_pos] = 0; // terminating null return copy; @@ -355,14 +355,190 @@ outputStream* tty; outputStream* gclog_or_tty; extern Mutex* tty_lock; +#define EXTRACHARLEN 32 +#define CURRENTAPPX ".current" +#define FILENAMEBUFLEN 1024 +// convert YYYY-MM-DD HH:MM:SS to YYYY-MM-DD_HH-MM-SS +char* get_datetime_string(char *buf, size_t len) { + os::local_time_string(buf, len); + int i = (int)strlen(buf); + while (i-- >= 0) { + if (buf[i] == ' ') buf[i] = '_'; + else if (buf[i] == ':') buf[i] = '-'; + } + return buf; +} + +static const char* make_log_name_internal(const char* log_name, const char* force_directory, + int pid, const char* tms) { + const char* basename = log_name; + char file_sep = os::file_separator()[0]; + const char* cp; + char pid_text[32]; + + for (cp = log_name; *cp != '\0'; cp++) { + if (*cp == '/' || *cp == file_sep) { + basename = cp + 1; + } + } + const char* nametail = log_name; + // Compute buffer length + size_t buffer_length; + if (force_directory != NULL) { + buffer_length = strlen(force_directory) + strlen(os::file_separator()) + + strlen(basename) + 1; + } else { + buffer_length = strlen(log_name) + 1; + } + + // const char* star = strchr(basename, '*'); + const char* pts = strstr(basename, "%p"); + int pid_pos = (pts == NULL) ? -1 : (pts - nametail); + + if (pid_pos >= 0) { + jio_snprintf(pid_text, sizeof(pid_text), "pid%u", pid); + buffer_length += strlen(pid_text); + } + + pts = strstr(basename, "%t"); + int tms_pos = (pts == NULL) ? -1 : (pts - nametail); + if (tms_pos >= 0) { + buffer_length += strlen(tms); + } + + // Create big enough buffer. + char *buf = NEW_C_HEAP_ARRAY(char, buffer_length, mtInternal); + + strcpy(buf, ""); + if (force_directory != NULL) { + strcat(buf, force_directory); + strcat(buf, os::file_separator()); + nametail = basename; // completely skip directory prefix + } + + // who is first, %p or %t? + int first = -1, second = -1; + const char *p1st = NULL; + const char *p2nd = NULL; + + if (pid_pos >= 0 && tms_pos >= 0) { + // contains both %p and %t + if (pid_pos < tms_pos) { + // case foo%pbar%tmonkey.log + first = pid_pos; + p1st = pid_text; + second = tms_pos; + p2nd = tms; + } else { + // case foo%tbar%pmonkey.log + first = tms_pos; + p1st = tms; + second = pid_pos; + p2nd = pid_text; + } + } else if (pid_pos >= 0) { + // contains %p only + first = pid_pos; + p1st = pid_text; + } else if (tms_pos >= 0) { + // contains %t only + first = tms_pos; + p1st = tms; + } + + int buf_pos = (int)strlen(buf); + const char* tail = nametail; + + if (first >= 0) { + tail = nametail + first + 2; + strncpy(&buf[buf_pos], nametail, first); + strcpy(&buf[buf_pos + first], p1st); + buf_pos = (int)strlen(buf); + if (second >= 0) { + strncpy(&buf[buf_pos], tail, second - first - 2); + strcpy(&buf[buf_pos + second - first - 2], p2nd); + tail = nametail + second + 2; + } + } + strcat(buf, tail); // append rest of name, or all of name + return buf; +} + +// log_name comes from -XX:LogFile=log_name or -Xloggc:log_name +// in log_name, %p => pipd1234 and +// %t => YYYY-MM-DD_HH-MM-SS +static const char* make_log_name(const char* log_name, const char* force_directory) { + char timestr[32]; + get_datetime_string(timestr, sizeof(timestr)); + return make_log_name_internal(log_name, force_directory, os::current_process_id(), + timestr); +} + +#ifndef PRODUCT +void test_loggc_filename() { + int pid; + char tms[32]; + char i_result[FILENAMEBUFLEN]; + const char* o_result; + get_datetime_string(tms, sizeof(tms)); + pid = os::current_process_id(); + + // test.log + jio_snprintf(i_result, sizeof(char)*FILENAMEBUFLEN, "test.log", tms); + o_result = make_log_name_internal("test.log", NULL, pid, tms); + assert(strcmp(i_result, o_result) == 0, "failed on testing make_log_name(\"test.log\", NULL)"); + FREE_C_HEAP_ARRAY(char, o_result, mtInternal); + + // test-%t-%p.log + jio_snprintf(i_result, sizeof(char)*FILENAMEBUFLEN, "test-%s-pid%u.log", tms, pid); + o_result = make_log_name_internal("test-%t-%p.log", NULL, pid, tms); + assert(strcmp(i_result, o_result) == 0, "failed on testing make_log_name(\"test-%%t-%%p.log\", NULL)"); + FREE_C_HEAP_ARRAY(char, o_result, mtInternal); + + // test-%t%p.log + jio_snprintf(i_result, sizeof(char)*FILENAMEBUFLEN, "test-%spid%u.log", tms, pid); + o_result = make_log_name_internal("test-%t%p.log", NULL, pid, tms); + assert(strcmp(i_result, o_result) == 0, "failed on testing make_log_name(\"test-%%t%%p.log\", NULL)"); + FREE_C_HEAP_ARRAY(char, o_result, mtInternal); + + // %p%t.log + jio_snprintf(i_result, sizeof(char)*FILENAMEBUFLEN, "pid%u%s.log", pid, tms); + o_result = make_log_name_internal("%p%t.log", NULL, pid, tms); + assert(strcmp(i_result, o_result) == 0, "failed on testing make_log_name(\"%%p%%t.log\", NULL)"); + FREE_C_HEAP_ARRAY(char, o_result, mtInternal); + + // %p-test.log + jio_snprintf(i_result, sizeof(char)*FILENAMEBUFLEN, "pid%u-test.log", pid); + o_result = make_log_name_internal("%p-test.log", NULL, pid, tms); + assert(strcmp(i_result, o_result) == 0, "failed on testing make_log_name(\"%%p-test.log\", NULL)"); + FREE_C_HEAP_ARRAY(char, o_result, mtInternal); + + // %t.log + jio_snprintf(i_result, sizeof(char)*FILENAMEBUFLEN, "%s.log", tms); + o_result = make_log_name_internal("%t.log", NULL, pid, tms); + assert(strcmp(i_result, o_result) == 0, "failed on testing make_log_name(\"%%t.log\", NULL)"); + FREE_C_HEAP_ARRAY(char, o_result, mtInternal); +} +#endif // PRODUCT + fileStream::fileStream(const char* file_name) { _file = fopen(file_name, "w"); - _need_close = true; + if (_file != NULL) { + _need_close = true; + } else { + warning("Cannot open file %s due to %s\n", file_name, strerror(errno)); + _need_close = false; + } } fileStream::fileStream(const char* file_name, const char* opentype) { _file = fopen(file_name, opentype); - _need_close = true; + if (_file != NULL) { + _need_close = true; + } else { + warning("Cannot open file %s due to %s\n", file_name, strerror(errno)); + _need_close = false; + } } void fileStream::write(const char* s, size_t len) { @@ -423,34 +599,51 @@ void fdStream::write(const char* s, size_t len) { update_position(s, len); } -rotatingFileStream::~rotatingFileStream() { +// dump vm version, os version, platform info, build id, +// memory usage and command line flags into header +void gcLogFileStream::dump_loggc_header() { + if (is_open()) { + print_cr(Abstract_VM_Version::internal_vm_info_string()); + os::print_memory_info(this); + print("CommandLine flags: "); + CommandLineFlags::printSetFlags(this); + } +} + +gcLogFileStream::~gcLogFileStream() { if (_file != NULL) { if (_need_close) fclose(_file); - _file = NULL; + _file = NULL; + } + if (_file_name != NULL) { FREE_C_HEAP_ARRAY(char, _file_name, mtInternal); _file_name = NULL; } } -rotatingFileStream::rotatingFileStream(const char* file_name) { +gcLogFileStream::gcLogFileStream(const char* file_name) { _cur_file_num = 0; _bytes_written = 0L; - _file_name = NEW_C_HEAP_ARRAY(char, strlen(file_name)+10, mtInternal); - jio_snprintf(_file_name, strlen(file_name)+10, "%s.%d", file_name, _cur_file_num); - _file = fopen(_file_name, "w"); - _need_close = true; + _file_name = make_log_name(file_name, NULL); + + // gc log file rotation + if (UseGCLogFileRotation && NumberOfGCLogFiles > 1) { + char tempbuf[FILENAMEBUFLEN]; + jio_snprintf(tempbuf, sizeof(tempbuf), "%s.%d" CURRENTAPPX, _file_name, _cur_file_num); + _file = fopen(tempbuf, "w"); + } else { + _file = fopen(_file_name, "w"); + } + if (_file != NULL) { + _need_close = true; + dump_loggc_header(); + } else { + warning("Cannot open file %s due to %s\n", _file_name, strerror(errno)); + _need_close = false; + } } -rotatingFileStream::rotatingFileStream(const char* file_name, const char* opentype) { - _cur_file_num = 0; - _bytes_written = 0L; - _file_name = NEW_C_HEAP_ARRAY(char, strlen(file_name)+10, mtInternal); - jio_snprintf(_file_name, strlen(file_name)+10, "%s.%d", file_name, _cur_file_num); - _file = fopen(_file_name, opentype); - _need_close = true; -} - -void rotatingFileStream::write(const char* s, size_t len) { +void gcLogFileStream::write(const char* s, size_t len) { if (_file != NULL) { size_t count = fwrite(s, 1, len, _file); _bytes_written += count; @@ -466,7 +659,12 @@ void rotatingFileStream::write(const char* s, size_t len) { // write to gc log file at safepoint. If in future, changes made for mutator threads or // concurrent GC threads to run parallel with VMThread at safepoint, write and rotate_log // must be synchronized. -void rotatingFileStream::rotate_log() { +void gcLogFileStream::rotate_log() { + char time_msg[FILENAMEBUFLEN]; + char time_str[EXTRACHARLEN]; + char current_file_name[FILENAMEBUFLEN]; + char renamed_file_name[FILENAMEBUFLEN]; + if (_bytes_written < (jlong)GCLogFileSize) { return; } @@ -481,27 +679,89 @@ void rotatingFileStream::rotate_log() { // rotate in same file rewind(); _bytes_written = 0L; + jio_snprintf(time_msg, sizeof(time_msg), "File %s rotated at %s\n", + _file_name, os::local_time_string((char *)time_str, sizeof(time_str))); + write(time_msg, strlen(time_msg)); + dump_loggc_header(); return; } - // rotate file in names file.0, file.1, file.2, ..., file. - // close current file, rotate to next file +#if defined(_WINDOWS) +#ifndef F_OK +#define F_OK 0 +#endif +#endif // _WINDOWS + + // rotate file in names extended_filename.0, extended_filename.1, ..., + // extended_filename.. Current rotation file name will + // have a form of extended_filename..current where i is the current rotation + // file number. After it reaches max file size, the file will be saved and renamed + // with .current removed from its tail. + size_t filename_len = strlen(_file_name); if (_file != NULL) { - _cur_file_num ++; - if (_cur_file_num >= NumberOfGCLogFiles) _cur_file_num = 0; - jio_snprintf(_file_name, strlen(Arguments::gc_log_filename()) + 10, "%s.%d", - Arguments::gc_log_filename(), _cur_file_num); + jio_snprintf(renamed_file_name, filename_len + EXTRACHARLEN, "%s.%d", + _file_name, _cur_file_num); + jio_snprintf(current_file_name, filename_len + EXTRACHARLEN, "%s.%d" CURRENTAPPX, + _file_name, _cur_file_num); + jio_snprintf(time_msg, sizeof(time_msg), "%s GC log file has reached the" + " maximum size. Saved as %s\n", + os::local_time_string((char *)time_str, sizeof(time_str)), + renamed_file_name); + write(time_msg, strlen(time_msg)); + fclose(_file); _file = NULL; + + bool can_rename = true; + if (access(current_file_name, F_OK) != 0) { + // current file does not exist? + warning("No source file exists, cannot rename\n"); + can_rename = false; + } + if (can_rename) { + if (access(renamed_file_name, F_OK) == 0) { + if (remove(renamed_file_name) != 0) { + warning("Could not delete existing file %s\n", renamed_file_name); + can_rename = false; + } + } else { + // file does not exist, ok to rename + } + } + if (can_rename && rename(current_file_name, renamed_file_name) != 0) { + warning("Could not rename %s to %s\n", _file_name, renamed_file_name); + } } - _file = fopen(_file_name, "w"); + + _cur_file_num++; + if (_cur_file_num > NumberOfGCLogFiles - 1) _cur_file_num = 0; + jio_snprintf(current_file_name, filename_len + EXTRACHARLEN, "%s.%d" CURRENTAPPX, + _file_name, _cur_file_num); + _file = fopen(current_file_name, "w"); + if (_file != NULL) { _bytes_written = 0L; _need_close = true; + // reuse current_file_name for time_msg + jio_snprintf(current_file_name, filename_len + EXTRACHARLEN, + "%s.%d", _file_name, _cur_file_num); + jio_snprintf(time_msg, sizeof(time_msg), "%s GC log file created %s\n", + os::local_time_string((char *)time_str, sizeof(time_str)), + current_file_name); + write(time_msg, strlen(time_msg)); + dump_loggc_header(); + // remove the existing file + if (access(current_file_name, F_OK) == 0) { + if (remove(current_file_name) != 0) { + warning("Could not delete existing file %s\n", current_file_name); + } + } } else { - tty->print_cr("failed to open rotation log file %s due to %s\n", + warning("failed to open rotation log file %s due to %s\n" + "Turned off GC log file rotation\n", _file_name, strerror(errno)); _need_close = false; + FLAG_SET_DEFAULT(UseGCLogFileRotation, false); } } @@ -530,66 +790,6 @@ bool defaultStream::has_log_file() { return _log_file != NULL; } -static const char* make_log_name(const char* log_name, const char* force_directory) { - const char* basename = log_name; - char file_sep = os::file_separator()[0]; - const char* cp; - for (cp = log_name; *cp != '\0'; cp++) { - if (*cp == '/' || *cp == file_sep) { - basename = cp+1; - } - } - const char* nametail = log_name; - - // Compute buffer length - size_t buffer_length; - if (force_directory != NULL) { - buffer_length = strlen(force_directory) + strlen(os::file_separator()) + - strlen(basename) + 1; - } else { - buffer_length = strlen(log_name) + 1; - } - - const char* star = strchr(basename, '*'); - int star_pos = (star == NULL) ? -1 : (star - nametail); - int skip = 1; - if (star == NULL) { - // Try %p - star = strstr(basename, "%p"); - if (star != NULL) { - skip = 2; - } - } - star_pos = (star == NULL) ? -1 : (star - nametail); - - char pid[32]; - if (star_pos >= 0) { - jio_snprintf(pid, sizeof(pid), "%u", os::current_process_id()); - buffer_length += strlen(pid); - } - - // Create big enough buffer. - char *buf = NEW_C_HEAP_ARRAY(char, buffer_length, mtInternal); - - strcpy(buf, ""); - if (force_directory != NULL) { - strcat(buf, force_directory); - strcat(buf, os::file_separator()); - nametail = basename; // completely skip directory prefix - } - - if (star_pos >= 0) { - // convert foo*bar.log or foo%pbar.log to foo123bar.log - int buf_pos = (int) strlen(buf); - strncpy(&buf[buf_pos], nametail, star_pos); - strcpy(&buf[buf_pos + star_pos], pid); - nametail += star_pos + skip; // skip prefix and pid format - } - - strcat(buf, nametail); // append rest of name, or all of name - return buf; -} - void defaultStream::init_log() { // %%% Need a MutexLocker? const char* log_name = LogFile != NULL ? LogFile : "hotspot.log"; @@ -877,11 +1077,8 @@ void ostream_init_log() { gclog_or_tty = tty; // default to tty if (Arguments::gc_log_filename() != NULL) { - fileStream * gclog = UseGCLogFileRotation ? - new(ResourceObj::C_HEAP, mtInternal) - rotatingFileStream(Arguments::gc_log_filename()) : - new(ResourceObj::C_HEAP, mtInternal) - fileStream(Arguments::gc_log_filename()); + fileStream * gclog = new(ResourceObj::C_HEAP, mtInternal) + gcLogFileStream(Arguments::gc_log_filename()); if (gclog->is_open()) { // now we update the time stamp of the GC log to be synced up // with tty. diff --git a/hotspot/src/share/vm/utilities/ostream.hpp b/hotspot/src/share/vm/utilities/ostream.hpp index 4d13847663e..9b1b1217b49 100644 --- a/hotspot/src/share/vm/utilities/ostream.hpp +++ b/hotspot/src/share/vm/utilities/ostream.hpp @@ -231,20 +231,24 @@ class fdStream : public outputStream { void flush() {}; }; -class rotatingFileStream : public fileStream { +class gcLogFileStream : public fileStream { protected: - char* _file_name; + const char* _file_name; jlong _bytes_written; - uintx _cur_file_num; // current logfile rotation number, from 0 to MaxGCLogFileNumbers-1 + uintx _cur_file_num; // current logfile rotation number, from 0 to NumberOfGCLogFiles-1 public: - rotatingFileStream(const char* file_name); - rotatingFileStream(const char* file_name, const char* opentype); - rotatingFileStream(FILE* file) : fileStream(file) {} - ~rotatingFileStream(); + gcLogFileStream(const char* file_name); + ~gcLogFileStream(); virtual void write(const char* c, size_t len); virtual void rotate_log(); + void dump_loggc_header(); }; +#ifndef PRODUCT +// unit test for checking -Xloggc: parsing result +void test_loggc_filename(); +#endif + void ostream_init(); void ostream_init_log(); void ostream_exit(); From d11f6f252b8abc75927b658f44a32fab9a21f8fb Mon Sep 17 00:00:00 2001 From: Albert Noll Date: Tue, 17 Sep 2013 08:39:20 +0200 Subject: [PATCH 179/210] 8024128: guarantee(codelet_size > 0 && (size_t)codelet_size > 2*K) failed: not enough space for interpreter generation Increase interpreter size for x86 template interpreter Reviewed-by: kvn, iveresov --- hotspot/src/cpu/x86/vm/templateInterpreter_x86.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hotspot/src/cpu/x86/vm/templateInterpreter_x86.hpp b/hotspot/src/cpu/x86/vm/templateInterpreter_x86.hpp index c828c90fba1..a632fbab313 100644 --- a/hotspot/src/cpu/x86/vm/templateInterpreter_x86.hpp +++ b/hotspot/src/cpu/x86/vm/templateInterpreter_x86.hpp @@ -34,9 +34,9 @@ // Run with +PrintInterpreter to get the VM to print out the size. // Max size with JVMTI #ifdef AMD64 - const static int InterpreterCodeSize = 200 * 1024; + const static int InterpreterCodeSize = 208 * 1024; #else - const static int InterpreterCodeSize = 168 * 1024; + const static int InterpreterCodeSize = 176 * 1024; #endif // AMD64 #endif // CPU_X86_VM_TEMPLATEINTERPRETER_X86_HPP From 7e77954221a2ef8c24f9686c047be45af1b511d8 Mon Sep 17 00:00:00 2001 From: Dan Horak Date: Tue, 17 Sep 2013 12:04:11 +0200 Subject: [PATCH 180/210] 8024914: Swapped usage of idx_t and bm_word_t types in bitMap.inline.hpp Incorrect usage of idx_t where bm_word_t is appropriate. Reviewed-by: tschatzl, brutisso --- .../src/share/vm/utilities/bitMap.inline.hpp | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/hotspot/src/share/vm/utilities/bitMap.inline.hpp b/hotspot/src/share/vm/utilities/bitMap.inline.hpp index 7bb244795fc..2171e849f8f 100644 --- a/hotspot/src/share/vm/utilities/bitMap.inline.hpp +++ b/hotspot/src/share/vm/utilities/bitMap.inline.hpp @@ -52,16 +52,16 @@ inline void BitMap::clear_bit(idx_t bit) { inline bool BitMap::par_set_bit(idx_t bit) { verify_index(bit); - volatile idx_t* const addr = word_addr(bit); - const idx_t mask = bit_mask(bit); - idx_t old_val = *addr; + volatile bm_word_t* const addr = word_addr(bit); + const bm_word_t mask = bit_mask(bit); + bm_word_t old_val = *addr; do { - const idx_t new_val = old_val | mask; + const bm_word_t new_val = old_val | mask; if (new_val == old_val) { return false; // Someone else beat us to it. } - const idx_t cur_val = (idx_t) Atomic::cmpxchg_ptr((void*) new_val, + const bm_word_t cur_val = (bm_word_t) Atomic::cmpxchg_ptr((void*) new_val, (volatile void*) addr, (void*) old_val); if (cur_val == old_val) { @@ -73,16 +73,16 @@ inline bool BitMap::par_set_bit(idx_t bit) { inline bool BitMap::par_clear_bit(idx_t bit) { verify_index(bit); - volatile idx_t* const addr = word_addr(bit); - const idx_t mask = ~bit_mask(bit); - idx_t old_val = *addr; + volatile bm_word_t* const addr = word_addr(bit); + const bm_word_t mask = ~bit_mask(bit); + bm_word_t old_val = *addr; do { - const idx_t new_val = old_val & mask; + const bm_word_t new_val = old_val & mask; if (new_val == old_val) { return false; // Someone else beat us to it. } - const idx_t cur_val = (idx_t) Atomic::cmpxchg_ptr((void*) new_val, + const bm_word_t cur_val = (bm_word_t) Atomic::cmpxchg_ptr((void*) new_val, (volatile void*) addr, (void*) old_val); if (cur_val == old_val) { From 508e958dfe7856e132e0b9c42573220ce5002ceb Mon Sep 17 00:00:00 2001 From: Lance Andersen Date: Tue, 17 Sep 2013 07:56:56 -0400 Subject: [PATCH 181/210] 7097386: Correct error in Predicate javadoc example Reviewed-by: alanb, shade --- .../classes/javax/sql/rowset/Predicate.java | 41 +++++++++---------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/jdk/src/share/classes/javax/sql/rowset/Predicate.java b/jdk/src/share/classes/javax/sql/rowset/Predicate.java index 63d76fdca6b..5b9676d67f4 100644 --- a/jdk/src/share/classes/javax/sql/rowset/Predicate.java +++ b/jdk/src/share/classes/javax/sql/rowset/Predicate.java @@ -56,44 +56,43 @@ import java.sql.*; *
    {@code
      *    public class Range implements Predicate {
      *
    - *       private Object lo[];
    - *       private Object hi[];
    - *       private int idx[];
    + *       private int[] lo;
    + *       private int[] hi;
    + *       private int[] idx;
      *
    - *       public Range(Object[] lo, Object[] hi, int[] idx) {
    + *       public Range(int[] lo, int[] hi, int[] idx) {
      *          this.lo = lo;
      *          this.hi = hi;
      *          this.idx = idx;
      *       }
      *
      *      public boolean evaluate(RowSet rs) {
    - *          CachedRowSet crs = (CachedRowSet)rs;
    - *          boolean bool1,bool2;
      *
      *          // Check the present row determine if it lies
      *          // within the filtering criteria.
      *
      *          for (int i = 0; i < idx.length; i++) {
    + *             int value;
    + *             try {
    + *                 value = (Integer) rs.getObject(idx[i]);
    + *             } catch (SQLException ex) {
    + *                 Logger.getLogger(Range.class.getName()).log(Level.SEVERE, null, ex);
    + *                 return false;
    + *             }
      *
    - *              if ((rs.getObject(idx[i]) >= lo[i]) &&
    - *                  (rs.getObject(idx[i]) >= hi[i]) {
    - *                  bool1 = true; // within filter constraints
    - *              } else {
    - *                  bool2 = true; // outside of filter constraints
    - *              }
    - *          }
    - *
    - *          if (bool2) {
    - *             return false;
    - *          } else {
    - *             return true;
    - *          }
    + *             if (value < lo[i] && value > hi[i]) {
    + *                 // outside of filter constraints
    + *                 return false;
    + *             }
    + *         }
    + *         // Within filter constraints
    + *        return true;
      *      }
    - *  }
    + *   }
      * }
    *

    * The example above implements a simple range predicate. Note, that - * implementations should but are not required to provider String + * implementations should but are not required to provide String * and integer index based constructors to provide for JDBC RowSet Implementation * applications that use both column identification conventions. * From e6c8a775ed5dc5105af44858bc22317665a8dc3b Mon Sep 17 00:00:00 2001 From: Jesper Wilhelmsson Date: Tue, 17 Sep 2013 14:02:53 +0200 Subject: [PATCH 182/210] 8024884: Test name changed, test list not updated Updated the test list with the new test name. Reviewed-by: brutisso, ehelin --- hotspot/test/TEST.groups | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hotspot/test/TEST.groups b/hotspot/test/TEST.groups index bf5e3f088fb..a75ac20ce62 100644 --- a/hotspot/test/TEST.groups +++ b/hotspot/test/TEST.groups @@ -62,7 +62,7 @@ jdk = \ # needs_jdk = \ gc/TestG1ZeroPGCTJcmdThreadPrint.java \ - gc/metaspace/ClassMetaspaceSizeInJmapHeap.java \ + gc/metaspace/CompressedClassSpaceSizeInJmapHeap.java \ gc/metaspace/TestMetaspacePerfCounters.java \ runtime/6819213/TestBootNativeLibraryPath.java \ runtime/6878713/Test6878713.sh \ From 0051ace82a86bb3cfa9cf825d4c7d025f5ac901e Mon Sep 17 00:00:00 2001 From: Christian Tornqvist Date: Tue, 17 Sep 2013 16:55:53 +0200 Subject: [PATCH 183/210] 8014905: [TESTBUG] Some hotspot tests should be updated to divide test jdk and compile jdk Change JDKToolFinder to look in compile.jdk if the executable cannot be found in test.jdk Reviewed-by: dholmes, hseigel --- hotspot/test/TEST.groups | 11 --- hotspot/test/gc/TestVerifyDuringStartup.java | 2 +- .../java/testlibrary/JDKToolFinder.java | 81 ++++++++++++++----- 3 files changed, 60 insertions(+), 34 deletions(-) diff --git a/hotspot/test/TEST.groups b/hotspot/test/TEST.groups index bf5e3f088fb..e6d88dc4b06 100644 --- a/hotspot/test/TEST.groups +++ b/hotspot/test/TEST.groups @@ -72,18 +72,7 @@ needs_jdk = \ runtime/7194254/Test7194254.java \ runtime/jsig/Test8017498.sh \ runtime/Metaspace/FragmentMetaspace.java \ - runtime/NMT/BaselineWithParameter.java \ - runtime/NMT/JcmdScale.java \ - runtime/NMT/JcmdWithNMTDisabled.java \ - runtime/NMT/MallocTestType.java \ runtime/NMT/ReleaseCommittedMemory.java \ - runtime/NMT/ShutdownTwice.java \ - runtime/NMT/SummaryAfterShutdown.java \ - runtime/NMT/SummarySanityCheck.java \ - runtime/NMT/ThreadedMallocTestType.java \ - runtime/NMT/ThreadedVirtualAllocTestType.java \ - runtime/NMT/VirtualAllocTestType.java \ - runtime/RedefineObject/TestRedefineObject.java \ serviceability/attach/AttachWithStalePidFile.java # JRE adds further tests to compact3 diff --git a/hotspot/test/gc/TestVerifyDuringStartup.java b/hotspot/test/gc/TestVerifyDuringStartup.java index 4ac32bf118e..f4ac347f80e 100644 --- a/hotspot/test/gc/TestVerifyDuringStartup.java +++ b/hotspot/test/gc/TestVerifyDuringStartup.java @@ -48,7 +48,7 @@ public class TestVerifyDuringStartup { "-XX:+VerifyDuringStartup", "-version"}); - System.out.print("Testing:\n" + JDKToolFinder.getCurrentJDKTool("java")); + System.out.print("Testing:\n" + JDKToolFinder.getJDKTool("java")); for (int i = 0; i < vmOpts.size(); i += 1) { System.out.print(" " + vmOpts.get(i)); } diff --git a/hotspot/test/testlibrary/com/oracle/java/testlibrary/JDKToolFinder.java b/hotspot/test/testlibrary/com/oracle/java/testlibrary/JDKToolFinder.java index a39abbd3626..6434135c108 100644 --- a/hotspot/test/testlibrary/com/oracle/java/testlibrary/JDKToolFinder.java +++ b/hotspot/test/testlibrary/com/oracle/java/testlibrary/JDKToolFinder.java @@ -23,7 +23,9 @@ package com.oracle.java.testlibrary; -import java.io.File; +import java.io.FileNotFoundException; +import java.nio.file.Path; +import java.nio.file.Paths; public final class JDKToolFinder { @@ -32,38 +34,73 @@ public final class JDKToolFinder { /** * Returns the full path to an executable in jdk/bin based on System - * property {@code compile.jdk} (set by jtreg test suite) + * property {@code test.jdk} or {@code compile.jdk} (both are set by the jtreg test suite) * * @return Full path to an executable in jdk/bin */ public static String getJDKTool(String tool) { - String binPath = System.getProperty("compile.jdk"); - if (binPath == null) { - throw new RuntimeException("System property 'compile.jdk' not set. " - + "This property is normally set by jtreg. " - + "When running test separately, set this property using " - + "'-Dcompile.jdk=/path/to/jdk'."); - } - binPath += File.separatorChar + "bin" + File.separatorChar + tool; - return binPath; + // First try to find the executable in test.jdk + try { + return getTool(tool, "test.jdk"); + } catch (FileNotFoundException e) { + + } + + // Now see if it's available in compile.jdk + try { + return getTool(tool, "compile.jdk"); + } catch (FileNotFoundException e) { + throw new RuntimeException("Failed to find " + tool + + ", looked in test.jdk (" + System.getProperty("test.jdk") + + ") and compile.jdk (" + System.getProperty("compile.jdk") + ")"); + } } + /** - * Returns the full path to an executable in <current jdk>/bin based - * on System property {@code test.jdk} (set by jtreg test suite) + * Returns the full path to an executable in jdk/bin based on System + * property {@code compile.jdk} * * @return Full path to an executable in jdk/bin */ - public static String getCurrentJDKTool(String tool) { - String binPath = System.getProperty("test.jdk"); - if (binPath == null) { - throw new RuntimeException("System property 'test.jdk' not set. " - + "This property is normally set by jtreg. " - + "When running test separately, set this property using " - + "'-Dtest.jdk=/path/to/jdk'."); + public static String getCompileJDKTool(String tool) { + try { + return getTool(tool, "compile.jdk"); + } catch (FileNotFoundException e) { + throw new RuntimeException(e); } - binPath += File.separatorChar + "bin" + File.separatorChar + tool; + } - return binPath; + /** + * Returns the full path to an executable in jdk/bin based on System + * property {@code test.jdk} + * + * @return Full path to an executable in jdk/bin + */ + public static String getTestJDKTool(String tool) { + try { + return getTool(tool, "test.jdk"); + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } + } + + private static String getTool(String tool, String property) throws FileNotFoundException { + String jdkPath = System.getProperty(property); + + if (jdkPath == null) { + throw new RuntimeException( + "System property '" + property + "' not set. This property is normally set by jtreg. " + + "When running test separately, set this property using '-D" + property + "=/path/to/jdk'."); + } + + Path toolName = Paths.get("bin", tool + (Platform.isWindows() ? ".exe" : "")); + + Path jdkTool = Paths.get(jdkPath, toolName.toString()); + if (!jdkTool.toFile().exists()) { + throw new FileNotFoundException("Could not find file " + jdkTool.toAbsolutePath()); + } + + return jdkTool.toAbsolutePath().toString(); } } From a19b450d568a4b09b78fbaf5b23ffe9b2eaed03a Mon Sep 17 00:00:00 2001 From: Mikhailo Seledtsov Date: Tue, 17 Sep 2013 20:09:32 +0200 Subject: [PATCH 184/210] 8016029: test runtime/6878713/Test6878713.sh failed Rewrote test in Java; updated the test condition to reflect latest changes in the source Reviewed-by: dholmes, ctornqvi --- hotspot/test/runtime/6878713/Test6878713.sh | 137 ------------------ .../ClassFile/OomWhileParsingRepeatedJsr.java | 74 ++++++++++ .../{6878713 => ClassFile}/testcase.jar | Bin 3 files changed, 74 insertions(+), 137 deletions(-) delete mode 100644 hotspot/test/runtime/6878713/Test6878713.sh create mode 100644 hotspot/test/runtime/ClassFile/OomWhileParsingRepeatedJsr.java rename hotspot/test/runtime/{6878713 => ClassFile}/testcase.jar (100%) diff --git a/hotspot/test/runtime/6878713/Test6878713.sh b/hotspot/test/runtime/6878713/Test6878713.sh deleted file mode 100644 index a2b5b2d2eb7..00000000000 --- a/hotspot/test/runtime/6878713/Test6878713.sh +++ /dev/null @@ -1,137 +0,0 @@ -#!/bin/sh - -# -# Copyright (c) 2011, 2013, 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 6878713 -## @bug 7030610 -## @bug 7037122 -## @bug 7123945 -## @summary Verifier heap corruption, relating to backward jsrs -## @run shell Test6878713.sh -## -## some tests require path to find test source dir -if [ "${TESTSRC}" = "" ] -then - TESTSRC=${PWD} - echo "TESTSRC not set. Using "${TESTSRC}" as default" -fi -echo "TESTSRC=${TESTSRC}" -## Adding common setup Variables for running shell tests. -. ${TESTSRC}/../../test_env.sh - -TARGET_CLASS=OOMCrashClass1960_2 - -echo "INFO: extracting the target class." -${COMPILEJAVA}${FS}bin${FS}jar xvf \ - ${TESTSRC}${FS}testcase.jar ${TARGET_CLASS}.class - -# remove any hs_err_pid that might exist here -rm -f hs_err_pid*.log - -echo "INFO: checking for 32-bit versus 64-bit VM." -${TESTJAVA}${FS}bin${FS}java ${TESTVMOPTS} -version 2>&1 \ - | grep "64-Bit [^ ][^ ]* VM" > /dev/null 2>&1 -status="$?" -if [ "$status" = 0 ]; then - echo "INFO: testing a 64-bit VM." - is_64_bit=true -else - echo "INFO: testing a 32-bit VM." -fi - -if [ "$is_64_bit" = true ]; then - # limit is 768MB in 8-byte words (1024 * 1024 * 768 / 8) == 100663296 - MALLOC_MAX=100663296 -else - # limit is 768MB in 4-byte words (1024 * 1024 * 768 / 4) == 201326592 - MALLOC_MAX=201326592 -fi -echo "INFO: MALLOC_MAX=$MALLOC_MAX" - -echo "INFO: executing the target class." -# -XX:+PrintCommandLineFlags for debugging purposes -# -XX:+IgnoreUnrecognizedVMOptions so test will run on a VM without -# the new -XX:MallocMaxTestWords option -# -XX:+UnlockDiagnosticVMOptions so we can use -XX:MallocMaxTestWords -# -XX:MallocMaxTestWords limits malloc to $MALLOC_MAX -${TESTJAVA}${FS}bin${FS}java \ - -XX:+PrintCommandLineFlags \ - -XX:+IgnoreUnrecognizedVMOptions \ - -XX:+UnlockDiagnosticVMOptions \ - -XX:MallocMaxTestWords=$MALLOC_MAX \ - ${TESTVMOPTS} ${TARGET_CLASS} > test.out 2>&1 - -echo "INFO: begin contents of test.out:" -cat test.out -echo "INFO: end contents of test.out." - -echo "INFO: checking for memory allocation error message." -# We are looking for this specific memory allocation failure mesg so -# we know we exercised the right allocation path with the test class: -MESG1="Native memory allocation (malloc) failed to allocate 25696531[0-9][0-9] bytes" -grep "$MESG1" test.out -status="$?" -if [ "$status" = 0 ]; then - echo "INFO: found expected memory allocation error message." -else - echo "INFO: did not find expected memory allocation error message." - - # If we didn't find MESG1 above, then there are several scenarios: - # 1) -XX:MallocMaxTestWords is not supported by the current VM and we - # didn't fail TARGET_CLASS's memory allocation attempt; instead - # we failed to find TARGET_CLASS's main() method. The TARGET_CLASS - # is designed to provoke a memory allocation failure during class - # loading; we actually don't care about running the class which is - # why it doesn't have a main() method. - # 2) we failed a memory allocation, but not the one we were looking - # so it might be that TARGET_CLASS no longer tickles the same - # memory allocation code path - # 3) TARGET_CLASS reproduces the failure mode (SIGSEGV) fixed by - # 6878713 because the test is running on a pre-fix VM. - echo "INFO: checking for no main() method message." - MESG2="Error: Main method not found in class" - grep "$MESG2" test.out - status="$?" - if [ "$status" = 0 ]; then - echo "INFO: found no main() method message." - else - echo "FAIL: did not find no main() method message." - # status is non-zero for exit below - - if [ -s hs_err_pid*.log ]; then - echo "INFO: begin contents of hs_err_pid file:" - cat hs_err_pid*.log - echo "INFO: end contents of hs_err_pid file." - fi - fi -fi - -if [ "$status" = 0 ]; then - echo "PASS: test found one of the expected messages." -fi -exit "$status" diff --git a/hotspot/test/runtime/ClassFile/OomWhileParsingRepeatedJsr.java b/hotspot/test/runtime/ClassFile/OomWhileParsingRepeatedJsr.java new file mode 100644 index 00000000000..ad08b183e59 --- /dev/null +++ b/hotspot/test/runtime/ClassFile/OomWhileParsingRepeatedJsr.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2011, 2013, 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 OomWhileParsingRepeatedJsr + * @summary Testing class file parser; specifically parsing + * a file with repeated JSR (jump local subroutine) + * bytecode command. + * @bug 6878713 + * @bug 7030610 + * @bug 7037122 + * @bug 7123945 + * @bug 8016029 + * @library /testlibrary + * @run main OomWhileParsingRepeatedJsr + */ + +import com.oracle.java.testlibrary.*; + + +public class OomWhileParsingRepeatedJsr { + + public static void main(String[] args) throws Exception { + + // ======= Configure the test + String jarFile = System.getProperty("test.src") + "/testcase.jar"; + String className = "OOMCrashClass1960_2"; + + // limit is 768MB in native words + int mallocMaxTestWords = (1024 * 1024 * 768 / 4); + if (Platform.is64bit()) + mallocMaxTestWords = (mallocMaxTestWords / 2); + + // ======= extract the test class + ProcessBuilder pb = new ProcessBuilder(new String[] { + JDKToolFinder.getJDKTool("jar"), + "xvf", jarFile } ); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldHaveExitValue(0); + + // ======= execute the test + pb = ProcessTools.createJavaProcessBuilder( + "-cp", ".", + "-XX:+UnlockDiagnosticVMOptions", + "-XX:MallocMaxTestWords=" + mallocMaxTestWords, + className ); + + output = new OutputAnalyzer(pb.start()); + output.shouldContain("Cannot reserve enough memory"); + } +} + diff --git a/hotspot/test/runtime/6878713/testcase.jar b/hotspot/test/runtime/ClassFile/testcase.jar similarity index 100% rename from hotspot/test/runtime/6878713/testcase.jar rename to hotspot/test/runtime/ClassFile/testcase.jar From 876967ae1f16b587efc44c93334b2155b8931a9d Mon Sep 17 00:00:00 2001 From: Mikhailo Seledtsov Date: Tue, 17 Sep 2013 20:20:03 +0200 Subject: [PATCH 185/210] 7149464: [TESTBUG] Test runtime/7020373/Test7020373.sh failed to clean up files after test Re-wrote in Java, this also eliminated temporary result file; set upper limit on malloc'd memory Reviewed-by: dcubed, dholmes, ccheung --- hotspot/test/runtime/7020373/Test7020373.sh | 43 -------- .../test/runtime/ClassFile/JsrRewriting.java | 102 ++++++++++++++++++ .../JsrRewritingTestCase.jar} | Bin 3 files changed, 102 insertions(+), 43 deletions(-) delete mode 100644 hotspot/test/runtime/7020373/Test7020373.sh create mode 100644 hotspot/test/runtime/ClassFile/JsrRewriting.java rename hotspot/test/runtime/{7020373/testcase.jar => ClassFile/JsrRewritingTestCase.jar} (100%) diff --git a/hotspot/test/runtime/7020373/Test7020373.sh b/hotspot/test/runtime/7020373/Test7020373.sh deleted file mode 100644 index 83b7028c82f..00000000000 --- a/hotspot/test/runtime/7020373/Test7020373.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/sh - -## -## @test -## @bug 7020373 7055247 7053586 7185550 -## @key cte_test -## @summary JSR rewriting can overflow memory address size variables -## @ignore Ignore it as 7053586 test uses lots of memory. See bug report for detail. -## @run shell Test7020373.sh -## - -if [ "${TESTSRC}" = "" ] -then - TESTSRC=${PWD} - echo "TESTSRC not set. Using "${TESTSRC}" as default" -fi -echo "TESTSRC=${TESTSRC}" -## Adding common setup Variables for running shell tests. -. ${TESTSRC}/../../test_env.sh - -${COMPILEJAVA}${FS}bin${FS}jar xvf ${TESTSRC}${FS}testcase.jar - -${TESTJAVA}${FS}bin${FS}java ${TESTVMOPTS} OOMCrashClass4000_1 > test.out 2>&1 - -cat test.out - -egrep "SIGSEGV|An unexpected error has been detected" test.out - -if [ $? = 0 ] -then - echo "Test Failed" - exit 1 -else - egrep "java.lang.LinkageError|java.lang.NoSuchMethodError|Main method not found in class OOMCrashClass4000_1|insufficient memory" test.out - if [ $? = 0 ] - then - echo "Test Passed" - exit 0 - else - echo "Test Failed" - exit 1 - fi -fi diff --git a/hotspot/test/runtime/ClassFile/JsrRewriting.java b/hotspot/test/runtime/ClassFile/JsrRewriting.java new file mode 100644 index 00000000000..856658f9bf3 --- /dev/null +++ b/hotspot/test/runtime/ClassFile/JsrRewriting.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2011, 2013, 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 JsrRewriting + * @summary JSR (jump local subroutine) + * rewriting can overflow memory address size variables + * @bug 7020373 + * @bug 7055247 + * @bug 7053586 + * @bug 7185550 + * @bug 7149464 + * @key cte_test + * @library /testlibrary + * @run main JsrRewriting + */ + +import com.oracle.java.testlibrary.*; +import java.io.File; + +public class JsrRewriting { + + public static void main(String[] args) throws Exception { + + // ======= Configure the test + String jarFile = System.getProperty("test.src") + + File.separator + "JsrRewritingTestCase.jar"; + String className = "OOMCrashClass4000_1"; + + // limit is 768MB in native words + int mallocMaxTestWords = (1024 * 1024 * 768 / 4); + if (Platform.is64bit()) + mallocMaxTestWords = (mallocMaxTestWords / 2); + + // ======= extract the test class + ProcessBuilder pb = new ProcessBuilder(new String[] { + JDKToolFinder.getJDKTool("jar"), + "xvf", jarFile } ); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldHaveExitValue(0); + + // ======= execute the test + pb = ProcessTools.createJavaProcessBuilder( + "-cp", ".", + "-XX:+UnlockDiagnosticVMOptions", + "-XX:MallocMaxTestWords=" + mallocMaxTestWords, + className); + + output = new OutputAnalyzer(pb.start()); + String[] expectedMsgs = { + "java.lang.LinkageError", + "java.lang.NoSuchMethodError", + "Main method not found in class " + className, + "insufficient memory" + }; + + MultipleOrMatch(output, expectedMsgs); + } + + private static void + MultipleOrMatch(OutputAnalyzer analyzer, String[] whatToMatch) { + String output = analyzer.getOutput(); + + for (String expected : whatToMatch) + if (output.contains(expected)) + return; + + String err = + " stdout: [" + analyzer.getOutput() + "];\n" + + " exitValue = " + analyzer.getExitValue() + "\n"; + System.err.println(err); + + StringBuilder msg = new StringBuilder("Output did not contain " + + "any of the following expected messages: \n"); + for (String expected : whatToMatch) + msg.append(expected).append(System.lineSeparator()); + throw new RuntimeException(msg.toString()); + } +} + diff --git a/hotspot/test/runtime/7020373/testcase.jar b/hotspot/test/runtime/ClassFile/JsrRewritingTestCase.jar similarity index 100% rename from hotspot/test/runtime/7020373/testcase.jar rename to hotspot/test/runtime/ClassFile/JsrRewritingTestCase.jar From 2cab7ea037453442645008267f6e63b94fbbcd81 Mon Sep 17 00:00:00 2001 From: Erik Helin Date: Tue, 17 Sep 2013 20:59:07 +0200 Subject: [PATCH 186/210] 8024718: Metaspace performance counters and memory pools should report the same data Reviewed-by: stefank, dholmes, coleenp --- .../src/share/vm/memory/metaspaceCounters.cpp | 62 ++++++------- .../src/share/vm/memory/metaspaceCounters.hpp | 11 ++- hotspot/src/share/vm/services/memoryPool.cpp | 19 ++-- hotspot/src/share/vm/services/memoryPool.hpp | 2 - hotspot/src/share/vm/services/memoryUsage.hpp | 4 +- .../gc/metaspace/TestMetaspaceMemoryPool.java | 71 ++++----------- .../metaspace/TestMetaspacePerfCounters.java | 35 ++++++-- .../TestPerfCountersAndMemoryPools.java | 86 +++++++++++++++++++ .../java/testlibrary/InputArguments.java | 25 ++++++ 9 files changed, 201 insertions(+), 114 deletions(-) create mode 100644 hotspot/test/gc/metaspace/TestPerfCountersAndMemoryPools.java diff --git a/hotspot/src/share/vm/memory/metaspaceCounters.cpp b/hotspot/src/share/vm/memory/metaspaceCounters.cpp index 6f443466ffb..60e26b8c714 100644 --- a/hotspot/src/share/vm/memory/metaspaceCounters.cpp +++ b/hotspot/src/share/vm/memory/metaspaceCounters.cpp @@ -65,26 +65,25 @@ class MetaspacePerfCounters: public CHeapObj { MetaspacePerfCounters* MetaspaceCounters::_perf_counters = NULL; -size_t MetaspaceCounters::calculate_capacity() { - // The total capacity is the sum of - // 1) capacity of Metachunks in use by all Metaspaces - // 2) unused space at the end of each Metachunk - // 3) space in the freelist - size_t total_capacity = MetaspaceAux::allocated_capacity_bytes() - + MetaspaceAux::free_bytes() + MetaspaceAux::free_chunks_total_bytes(); - return total_capacity; +size_t MetaspaceCounters::used() { + return MetaspaceAux::allocated_used_bytes(); +} + +size_t MetaspaceCounters::capacity() { + return MetaspaceAux::committed_bytes(); +} + +size_t MetaspaceCounters::max_capacity() { + return MetaspaceAux::reserved_bytes(); } void MetaspaceCounters::initialize_performance_counters() { if (UsePerfData) { assert(_perf_counters == NULL, "Should only be initialized once"); - size_t min_capacity = MetaspaceAux::min_chunk_size_bytes(); - size_t capacity = calculate_capacity(); - size_t max_capacity = MetaspaceAux::reserved_bytes(); - size_t used = MetaspaceAux::allocated_used_bytes(); - - _perf_counters = new MetaspacePerfCounters("metaspace", min_capacity, capacity, max_capacity, used); + size_t min_capacity = 0; + _perf_counters = new MetaspacePerfCounters("metaspace", min_capacity, + capacity(), max_capacity(), used()); } } @@ -92,31 +91,29 @@ void MetaspaceCounters::update_performance_counters() { if (UsePerfData) { assert(_perf_counters != NULL, "Should be initialized"); - size_t capacity = calculate_capacity(); - size_t max_capacity = MetaspaceAux::reserved_bytes(); - size_t used = MetaspaceAux::allocated_used_bytes(); - - _perf_counters->update(capacity, max_capacity, used); + _perf_counters->update(capacity(), max_capacity(), used()); } } MetaspacePerfCounters* CompressedClassSpaceCounters::_perf_counters = NULL; -size_t CompressedClassSpaceCounters::calculate_capacity() { - return MetaspaceAux::allocated_capacity_bytes(_class_type) + - MetaspaceAux::free_bytes(_class_type) + - MetaspaceAux::free_chunks_total_bytes(_class_type); +size_t CompressedClassSpaceCounters::used() { + return MetaspaceAux::allocated_used_bytes(Metaspace::ClassType); +} + +size_t CompressedClassSpaceCounters::capacity() { + return MetaspaceAux::committed_bytes(Metaspace::ClassType); +} + +size_t CompressedClassSpaceCounters::max_capacity() { + return MetaspaceAux::reserved_bytes(Metaspace::ClassType); } void CompressedClassSpaceCounters::update_performance_counters() { if (UsePerfData && UseCompressedClassPointers) { assert(_perf_counters != NULL, "Should be initialized"); - size_t capacity = calculate_capacity(); - size_t max_capacity = MetaspaceAux::reserved_bytes(_class_type); - size_t used = MetaspaceAux::allocated_used_bytes(_class_type); - - _perf_counters->update(capacity, max_capacity, used); + _perf_counters->update(capacity(), max_capacity(), used()); } } @@ -126,12 +123,9 @@ void CompressedClassSpaceCounters::initialize_performance_counters() { const char* ns = "compressedclassspace"; if (UseCompressedClassPointers) { - size_t min_capacity = MetaspaceAux::min_chunk_size_bytes(); - size_t capacity = calculate_capacity(); - size_t max_capacity = MetaspaceAux::reserved_bytes(_class_type); - size_t used = MetaspaceAux::allocated_used_bytes(_class_type); - - _perf_counters = new MetaspacePerfCounters(ns, min_capacity, capacity, max_capacity, used); + size_t min_capacity = 0; + _perf_counters = new MetaspacePerfCounters(ns, min_capacity, capacity(), + max_capacity(), used()); } else { _perf_counters = new MetaspacePerfCounters(ns, 0, 0, 0, 0); } diff --git a/hotspot/src/share/vm/memory/metaspaceCounters.hpp b/hotspot/src/share/vm/memory/metaspaceCounters.hpp index 5b481d59b4d..0fa991291a1 100644 --- a/hotspot/src/share/vm/memory/metaspaceCounters.hpp +++ b/hotspot/src/share/vm/memory/metaspaceCounters.hpp @@ -25,13 +25,15 @@ #ifndef SHARE_VM_MEMORY_METASPACECOUNTERS_HPP #define SHARE_VM_MEMORY_METASPACECOUNTERS_HPP -#include "memory/metaspace.hpp" +#include "memory/allocation.hpp" class MetaspacePerfCounters; class MetaspaceCounters: public AllStatic { static MetaspacePerfCounters* _perf_counters; - static size_t calculate_capacity(); + static size_t used(); + static size_t capacity(); + static size_t max_capacity(); public: static void initialize_performance_counters(); @@ -40,8 +42,9 @@ class MetaspaceCounters: public AllStatic { class CompressedClassSpaceCounters: public AllStatic { static MetaspacePerfCounters* _perf_counters; - static size_t calculate_capacity(); - static const Metaspace::MetadataType _class_type = Metaspace::ClassType; + static size_t used(); + static size_t capacity(); + static size_t max_capacity(); public: static void initialize_performance_counters(); diff --git a/hotspot/src/share/vm/services/memoryPool.cpp b/hotspot/src/share/vm/services/memoryPool.cpp index 7a17f0bd138..cfae726cf7b 100644 --- a/hotspot/src/share/vm/services/memoryPool.cpp +++ b/hotspot/src/share/vm/services/memoryPool.cpp @@ -260,10 +260,10 @@ MemoryUsage CodeHeapPool::get_memory_usage() { } MetaspacePool::MetaspacePool() : - MemoryPool("Metaspace", NonHeap, capacity_in_bytes(), calculate_max_size(), true, false) { } + MemoryPool("Metaspace", NonHeap, 0, calculate_max_size(), true, false) { } MemoryUsage MetaspacePool::get_memory_usage() { - size_t committed = align_size_down_(capacity_in_bytes(), os::vm_page_size()); + size_t committed = MetaspaceAux::committed_bytes(); return MemoryUsage(initial_size(), used_in_bytes(), committed, max_size()); } @@ -271,26 +271,19 @@ size_t MetaspacePool::used_in_bytes() { return MetaspaceAux::allocated_used_bytes(); } -size_t MetaspacePool::capacity_in_bytes() const { - return MetaspaceAux::allocated_capacity_bytes(); -} - size_t MetaspacePool::calculate_max_size() const { - return FLAG_IS_CMDLINE(MaxMetaspaceSize) ? MaxMetaspaceSize : max_uintx; + return FLAG_IS_CMDLINE(MaxMetaspaceSize) ? MaxMetaspaceSize : + MemoryUsage::undefined_size(); } CompressedKlassSpacePool::CompressedKlassSpacePool() : - MemoryPool("Compressed Class Space", NonHeap, capacity_in_bytes(), CompressedClassSpaceSize, true, false) { } + MemoryPool("Compressed Class Space", NonHeap, 0, CompressedClassSpaceSize, true, false) { } size_t CompressedKlassSpacePool::used_in_bytes() { return MetaspaceAux::allocated_used_bytes(Metaspace::ClassType); } -size_t CompressedKlassSpacePool::capacity_in_bytes() const { - return MetaspaceAux::allocated_capacity_bytes(Metaspace::ClassType); -} - MemoryUsage CompressedKlassSpacePool::get_memory_usage() { - size_t committed = align_size_down_(capacity_in_bytes(), os::vm_page_size()); + size_t committed = MetaspaceAux::committed_bytes(Metaspace::ClassType); return MemoryUsage(initial_size(), used_in_bytes(), committed, max_size()); } diff --git a/hotspot/src/share/vm/services/memoryPool.hpp b/hotspot/src/share/vm/services/memoryPool.hpp index 08efe08e838..4ec810a985f 100644 --- a/hotspot/src/share/vm/services/memoryPool.hpp +++ b/hotspot/src/share/vm/services/memoryPool.hpp @@ -224,7 +224,6 @@ public: class MetaspacePool : public MemoryPool { size_t calculate_max_size() const; - size_t capacity_in_bytes() const; public: MetaspacePool(); MemoryUsage get_memory_usage(); @@ -232,7 +231,6 @@ class MetaspacePool : public MemoryPool { }; class CompressedKlassSpacePool : public MemoryPool { - size_t capacity_in_bytes() const; public: CompressedKlassSpacePool(); MemoryUsage get_memory_usage(); diff --git a/hotspot/src/share/vm/services/memoryUsage.hpp b/hotspot/src/share/vm/services/memoryUsage.hpp index efc6f2966d1..9027f8e76b7 100644 --- a/hotspot/src/share/vm/services/memoryUsage.hpp +++ b/hotspot/src/share/vm/services/memoryUsage.hpp @@ -63,10 +63,12 @@ public: size_t committed() const { return _committed; } size_t max_size() const { return _maxSize; } + static size_t undefined_size() { return (size_t) -1; } + inline static jlong convert_to_jlong(size_t val) { // In the 64-bit vm, a size_t can overflow a jlong (which is signed). jlong ret; - if (val == (size_t)-1) { + if (val == undefined_size()) { ret = -1L; } else { NOT_LP64(ret = val;) diff --git a/hotspot/test/gc/metaspace/TestMetaspaceMemoryPool.java b/hotspot/test/gc/metaspace/TestMetaspaceMemoryPool.java index 105ba240ddf..bf9e74c8ab0 100644 --- a/hotspot/test/gc/metaspace/TestMetaspaceMemoryPool.java +++ b/hotspot/test/gc/metaspace/TestMetaspaceMemoryPool.java @@ -22,18 +22,15 @@ */ import java.util.List; -import java.lang.management.ManagementFactory; -import java.lang.management.MemoryManagerMXBean; -import java.lang.management.MemoryPoolMXBean; -import java.lang.management.MemoryUsage; - -import java.lang.management.RuntimeMXBean; -import java.lang.management.ManagementFactory; +import java.lang.management.*; +import com.oracle.java.testlibrary.*; +import static com.oracle.java.testlibrary.Asserts.*; /* @test TestMetaspaceMemoryPool * @bug 8000754 * @summary Tests that a MemoryPoolMXBeans is created for metaspace and that a * MemoryManagerMXBean is created. + * @library /testlibrary * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops TestMetaspaceMemoryPool * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:MaxMetaspaceSize=60m TestMetaspaceMemoryPool * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedClassPointers TestMetaspaceMemoryPool @@ -42,35 +39,18 @@ import java.lang.management.ManagementFactory; public class TestMetaspaceMemoryPool { public static void main(String[] args) { verifyThatMetaspaceMemoryManagerExists(); - verifyMemoryPool(getMemoryPool("Metaspace"), isFlagDefined("MaxMetaspaceSize")); - if (runsOn64bit()) { - if (usesCompressedOops()) { + boolean isMetaspaceMaxDefined = InputArguments.containsPrefix("-XX:MaxMetaspaceSize"); + verifyMemoryPool(getMemoryPool("Metaspace"), isMetaspaceMaxDefined); + + if (Platform.is64bit()) { + if (InputArguments.contains("-XX:+UseCompressedOops")) { MemoryPoolMXBean cksPool = getMemoryPool("Compressed Class Space"); verifyMemoryPool(cksPool, true); } } } - private static boolean runsOn64bit() { - return !System.getProperty("sun.arch.data.model").equals("32"); - } - - private static boolean usesCompressedOops() { - return isFlagDefined("+UseCompressedOops"); - } - - private static boolean isFlagDefined(String name) { - RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean(); - List args = runtimeMxBean.getInputArguments(); - for (String arg : args) { - if (arg.startsWith("-XX:" + name)) { - return true; - } - } - return false; - } - private static void verifyThatMetaspaceMemoryManagerExists() { List managers = ManagementFactory.getMemoryManagerMXBeans(); for (MemoryManagerMXBean manager : managers) { @@ -95,32 +75,19 @@ public class TestMetaspaceMemoryPool { private static void verifyMemoryPool(MemoryPoolMXBean pool, boolean isMaxDefined) { MemoryUsage mu = pool.getUsage(); - assertDefined(mu.getInit(), "init"); - assertDefined(mu.getUsed(), "used"); - assertDefined(mu.getCommitted(), "committed"); + long init = mu.getInit(); + long used = mu.getUsed(); + long committed = mu.getCommitted(); + long max = mu.getMax(); + + assertGTE(init, 0L); + assertGTE(used, init); + assertGTE(committed, used); if (isMaxDefined) { - assertDefined(mu.getMax(), "max"); + assertGTE(max, committed); } else { - assertUndefined(mu.getMax(), "max"); - } - } - - private static void assertDefined(long value, String name) { - assertTrue(value != -1, "Expected " + name + " to be defined"); - } - - private static void assertUndefined(long value, String name) { - assertEquals(value, -1, "Expected " + name + " to be undefined"); - } - - private static void assertEquals(long actual, long expected, String msg) { - assertTrue(actual == expected, msg); - } - - private static void assertTrue(boolean condition, String msg) { - if (!condition) { - throw new RuntimeException(msg); + assertEQ(max, -1L); } } } diff --git a/hotspot/test/gc/metaspace/TestMetaspacePerfCounters.java b/hotspot/test/gc/metaspace/TestMetaspacePerfCounters.java index 9672d90a5d0..974066cba56 100644 --- a/hotspot/test/gc/metaspace/TestMetaspacePerfCounters.java +++ b/hotspot/test/gc/metaspace/TestMetaspacePerfCounters.java @@ -61,10 +61,15 @@ public class TestMetaspacePerfCounters { } private static void checkPerfCounters(String ns) throws Exception { - for (PerfCounter counter : countersInNamespace(ns)) { - String msg = "Expected " + counter.getName() + " to be larger than 0"; - assertGT(counter.longValue(), 0L, msg); - } + long minCapacity = getMinCapacity(ns); + long maxCapacity = getMaxCapacity(ns); + long capacity = getCapacity(ns); + long used = getUsed(ns); + + assertGTE(minCapacity, 0L); + assertGTE(used, minCapacity); + assertGTE(capacity, used); + assertGTE(maxCapacity, capacity); } private static void checkEmptyPerfCounters(String ns) throws Exception { @@ -75,12 +80,10 @@ public class TestMetaspacePerfCounters { } private static void checkUsedIncreasesWhenLoadingClass(String ns) throws Exception { - PerfCounter used = PerfCounters.findByName(ns + ".used"); - - long before = used.longValue(); + long before = getUsed(ns); fooClass = compileAndLoad("Foo", "public class Foo { }"); System.gc(); - long after = used.longValue(); + long after = getUsed(ns); assertGT(after, before); } @@ -101,4 +104,20 @@ public class TestMetaspacePerfCounters { private static boolean isUsingCompressedClassPointers() { return Platform.is64bit() && InputArguments.contains("-XX:+UseCompressedClassPointers"); } + + private static long getMinCapacity(String ns) throws Exception { + return PerfCounters.findByName(ns + ".minCapacity").longValue(); + } + + private static long getCapacity(String ns) throws Exception { + return PerfCounters.findByName(ns + ".capacity").longValue(); + } + + private static long getMaxCapacity(String ns) throws Exception { + return PerfCounters.findByName(ns + ".maxCapacity").longValue(); + } + + private static long getUsed(String ns) throws Exception { + return PerfCounters.findByName(ns + ".used").longValue(); + } } diff --git a/hotspot/test/gc/metaspace/TestPerfCountersAndMemoryPools.java b/hotspot/test/gc/metaspace/TestPerfCountersAndMemoryPools.java new file mode 100644 index 00000000000..e26aa6eee57 --- /dev/null +++ b/hotspot/test/gc/metaspace/TestPerfCountersAndMemoryPools.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2013, 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.List; +import java.lang.management.*; + +import com.oracle.java.testlibrary.*; +import static com.oracle.java.testlibrary.Asserts.*; + +/* @test TestPerfCountersAndMemoryPools + * @bug 8023476 + * @summary Tests that a MemoryPoolMXBeans and PerfCounters for metaspace + * report the same data. + * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-UseCompressedKlassPointers -XX:+UseSerialGC -XX:+UsePerfData TestPerfCountersAndMemoryPools + * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedKlassPointers -XX:+UseSerialGC -XX:+UsePerfData TestPerfCountersAndMemoryPools + */ +public class TestPerfCountersAndMemoryPools { + public static void main(String[] args) throws Exception { + checkMemoryUsage("Metaspace", "sun.gc.metaspace"); + + if (InputArguments.contains("-XX:+UseCompressedKlassPointers") && Platform.is64bit()) { + checkMemoryUsage("Compressed Class Space", "sun.gc.compressedclassspace"); + } + } + + private static MemoryUsage getMemoryUsage(String memoryPoolName) { + List pools = ManagementFactory.getMemoryPoolMXBeans(); + for (MemoryPoolMXBean pool : pools) { + if (pool.getName().equals(memoryPoolName)) { + return pool.getUsage(); + } + } + + throw new RuntimeException("Excpted to find a memory pool with name " + + memoryPoolName); + } + + private static void checkMemoryUsage(String memoryPoolName, String perfNS) + throws Exception { + // Need to do a gc before each comparison to update the perf counters + + System.gc(); + MemoryUsage mu = getMemoryUsage(memoryPoolName); + assertEQ(getMinCapacity(perfNS), mu.getInit()); + + System.gc(); + mu = getMemoryUsage(memoryPoolName); + assertEQ(getUsed(perfNS), mu.getUsed()); + + System.gc(); + mu = getMemoryUsage(memoryPoolName); + assertEQ(getCapacity(perfNS), mu.getCommitted()); + } + + private static long getMinCapacity(String ns) throws Exception { + return PerfCounters.findByName(ns + ".minCapacity").longValue(); + } + + private static long getCapacity(String ns) throws Exception { + return PerfCounters.findByName(ns + ".capacity").longValue(); + } + + private static long getUsed(String ns) throws Exception { + return PerfCounters.findByName(ns + ".used").longValue(); + } +} diff --git a/hotspot/test/testlibrary/com/oracle/java/testlibrary/InputArguments.java b/hotspot/test/testlibrary/com/oracle/java/testlibrary/InputArguments.java index 650d6c23390..6f40b4050be 100644 --- a/hotspot/test/testlibrary/com/oracle/java/testlibrary/InputArguments.java +++ b/hotspot/test/testlibrary/com/oracle/java/testlibrary/InputArguments.java @@ -41,6 +41,9 @@ public class InputArguments { /** * Returns true if {@code arg} is an input argument to the VM. * + * This is useful for checking boolean flags such as -XX:+UseSerialGC or + * -XX:-UsePerfData. + * * @param arg The name of the argument. * @return {@code true} if the given argument is an input argument, * otherwise {@code false}. @@ -48,4 +51,26 @@ public class InputArguments { public static boolean contains(String arg) { return args.contains(arg); } + + /** + * Returns true if {@code prefix} is the start of an input argument to the + * VM. + * + * This is useful for checking if flags describing a quantity, such as + * -XX:+MaxMetaspaceSize=100m, is set without having to know the quantity. + * To check if the flag -XX:MaxMetaspaceSize is set, use + * {@code InputArguments.containsPrefix("-XX:MaxMetaspaceSize")}. + * + * @param prefix The start of the argument. + * @return {@code true} if the given argument is the start of an input + * argument, otherwise {@code false}. + */ + public static boolean containsPrefix(String prefix) { + for (String arg : args) { + if (arg.startsWith(prefix)) { + return true; + } + } + return false; + } } From 73fa61708235e102fde7475399427e295ed3873c Mon Sep 17 00:00:00 2001 From: Albert Noll Date: Wed, 18 Sep 2013 07:22:20 +0200 Subject: [PATCH 187/210] 8022883: Assertion failed: sweptCount >= flushedCount + markedCount + zombifiedCount Provide correct number of visited nmethods to Tracing Reviewed-by: kvn, iveresov --- hotspot/src/share/vm/runtime/sweeper.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hotspot/src/share/vm/runtime/sweeper.cpp b/hotspot/src/share/vm/runtime/sweeper.cpp index ebecda50be0..37315aec328 100644 --- a/hotspot/src/share/vm/runtime/sweeper.cpp +++ b/hotspot/src/share/vm/runtime/sweeper.cpp @@ -269,6 +269,7 @@ void NMethodSweeper::sweep_code_cache() { // the number of nmethods changes during the sweep so the final // stage must iterate until it there are no more nmethods. int todo = (CodeCache::nof_nmethods() - _seen) / _invocations; + int swept_count = 0; assert(!SafepointSynchronize::is_at_safepoint(), "should not be in safepoint when we get here"); assert(!CodeCache_lock->owned_by_self(), "just checking"); @@ -278,6 +279,7 @@ void NMethodSweeper::sweep_code_cache() { // The last invocation iterates until there are no more nmethods for (int i = 0; (i < todo || _invocations == 1) && _current != NULL; i++) { + swept_count++; if (SafepointSynchronize::is_synchronizing()) { // Safepoint request if (PrintMethodFlushing && Verbose) { tty->print_cr("### Sweep at %d out of %d, invocation: %d, yielding to safepoint", _seen, CodeCache::nof_nmethods(), _invocations); @@ -331,7 +333,7 @@ void NMethodSweeper::sweep_code_cache() { event.set_endtime(sweep_end_counter); event.set_sweepIndex(_traversals); event.set_sweepFractionIndex(NmethodSweepFraction - _invocations + 1); - event.set_sweptCount(todo); + event.set_sweptCount(swept_count); event.set_flushedCount(_flushed_count); event.set_markedCount(_marked_count); event.set_zombifiedCount(_zombified_count); From 3e4a59f7973775bea3d1bebce1e095178854df42 Mon Sep 17 00:00:00 2001 From: Thomas Schatzl Date: Wed, 18 Sep 2013 10:02:19 +0200 Subject: [PATCH 188/210] 8024662: gc/arguments/TestUseCompressedOopsErgo.java does not compile Fix compilation error and use of an outdated VM option in the test Reviewed-by: stefank, jwilhelm --- .../TestUseCompressedOopsErgoTools.java | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/hotspot/test/gc/arguments/TestUseCompressedOopsErgoTools.java b/hotspot/test/gc/arguments/TestUseCompressedOopsErgoTools.java index 49d0a8a1d21..54c70672d04 100644 --- a/hotspot/test/gc/arguments/TestUseCompressedOopsErgoTools.java +++ b/hotspot/test/gc/arguments/TestUseCompressedOopsErgoTools.java @@ -42,10 +42,10 @@ class DetermineMaxHeapForCompressedOops { class TestUseCompressedOopsErgoTools { - private static long getClassMetaspaceSize() { + private static long getCompressedClassSpaceSize() { HotSpotDiagnosticMXBean diagnostic = ManagementFactoryHelper.getDiagnosticMXBean(); - VMOption option = diagnostic.getVMOption("ClassMetaspaceSize"); + VMOption option = diagnostic.getVMOption("CompressedClassSpaceSize"); return Long.parseLong(option.getValue()); } @@ -132,13 +132,13 @@ class TestUseCompressedOopsErgoTools { checkUseCompressedOops(join(gcflags, "-XX:ObjectAlignmentInBytes=16"), maxHeapForCompressedOops - 1, true); checkUseCompressedOops(join(gcflags, "-XX:ObjectAlignmentInBytes=16"), maxHeapForCompressedOops + 1, false); - // use a different ClassMetaspaceSize - String classMetaspaceSizeArg = "-XX:ClassMetaspaceSize=" + 2 * getClassMetaspaceSize(); - maxHeapForCompressedOops = getMaxHeapForCompressedOops(join(gcflags, classMetaspaceSizeArg)); + // use a different CompressedClassSpaceSize + String compressedClassSpaceSizeArg = "-XX:CompressedClassSpaceSize=" + 2 * getCompressedClassSpaceSize(); + maxHeapForCompressedOops = getMaxHeapForCompressedOops(join(gcflags, compressedClassSpaceSizeArg)); - checkUseCompressedOops(join(gcflags, classMetaspaceSizeArg), maxHeapForCompressedOops, true); - checkUseCompressedOops(join(gcflags, classMetaspaceSizeArg), maxHeapForCompressedOops - 1, true); - checkUseCompressedOops(join(gcflags, classMetaspaceSizeArg), maxHeapForCompressedOops + 1, false); + checkUseCompressedOops(join(gcflags, compressedClassSpaceSizeArg), maxHeapForCompressedOops, true); + checkUseCompressedOops(join(gcflags, compressedClassSpaceSizeArg), maxHeapForCompressedOops - 1, true); + checkUseCompressedOops(join(gcflags, compressedClassSpaceSizeArg), maxHeapForCompressedOops + 1, false); } private static void checkUseCompressedOops(String[] args, long heapsize, boolean expectUseCompressedOops) throws Exception { @@ -152,9 +152,7 @@ class TestUseCompressedOopsErgoTools { boolean actualUseCompressedOops = getFlagBoolValue(" UseCompressedOops", output); - if (expectUseCompressedOops != actualUseCompressedOops) { - throw new RuntimeException("Expected use of compressed oops: " + expectUseCompressedOops + " but was: " + actualUseCompressedOops); - } + Asserts.assertEQ(expectUseCompressedOops, actualUseCompressedOops); } private static boolean getFlagBoolValue(String flag, String where) { @@ -162,7 +160,7 @@ class TestUseCompressedOopsErgoTools { if (!m.find()) { throw new RuntimeException("Could not find value for flag " + flag + " in output string"); } - String match = m.group(1).equals("true"); + return m.group(1).equals("true"); } private static String expect(String[] flags, boolean hasWarning, boolean hasError, int errorcode) throws Exception { From 862bc33d7aa704d7513b9a1fea0d80e5fcb4366f Mon Sep 17 00:00:00 2001 From: Magnus Ihse Bursie Date: Wed, 18 Sep 2013 12:37:54 +0200 Subject: [PATCH 189/210] 8024815: Make --with-dxsdk and friends deprecated Reviewed-by: erikj --- common/autoconf/basics.m4 | 9 ++++++ common/autoconf/generated-configure.sh | 42 +++++++++++++++++++++++++- common/autoconf/toolchain.m4 | 3 ++ 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/common/autoconf/basics.m4 b/common/autoconf/basics.m4 index 126993b5cd7..f3911ff9bd9 100644 --- a/common/autoconf/basics.m4 +++ b/common/autoconf/basics.m4 @@ -203,6 +203,15 @@ AC_DEFUN([BASIC_REMOVE_SYMBOLIC_LINKS], fi ]) +# Register a --with argument but mark it as deprecated +# $1: The name of the with argument to deprecate, not including --with- +AC_DEFUN([BASIC_DEPRECATED_ARG_WITH], +[ + AC_ARG_WITH($1, [AS_HELP_STRING([--with-$1], + [Deprecated. Option is kept for backwards compatibility and is ignored])], + [AC_MSG_WARN([Option --with-$1 is deprecated and will be ignored.])]) +]) + AC_DEFUN_ONCE([BASIC_INIT], [ # Save the original command line. This is passed to us by the wrapper configure script. diff --git a/common/autoconf/generated-configure.sh b/common/autoconf/generated-configure.sh index bc9d07da3f3..cf14b82ccfd 100644 --- a/common/autoconf/generated-configure.sh +++ b/common/autoconf/generated-configure.sh @@ -1032,6 +1032,9 @@ with_override_nashorn with_override_jdk with_import_hotspot with_msvcr_dll +with_dxsdk +with_dxsdk_lib +with_dxsdk_include with_jtreg with_extra_cflags with_extra_cxxflags @@ -1786,6 +1789,12 @@ Optional Packages: source --with-msvcr-dll copy this msvcr100.dll into the built JDK (Windows only) [probed] + --with-dxsdk Deprecated. Option is kept for backwards + compatibility and is ignored + --with-dxsdk-lib Deprecated. Option is kept for backwards + compatibility and is ignored + --with-dxsdk-include Deprecated. Option is kept for backwards + compatibility and is ignored --with-jtreg Regression Test Harness [probed] --with-extra-cflags extra flags to be used when compiling jdk c-files --with-extra-cxxflags extra flags to be used when compiling jdk c++-files @@ -3135,6 +3144,10 @@ ac_configure="$SHELL $ac_aux_dir/configure" # Please don't use this var. +# Register a --with argument but mark it as deprecated +# $1: The name of the with argument to deprecate, not including --with- + + # Test that variable $1 denoting a program is not empty. If empty, exit with an error. @@ -3805,7 +3818,7 @@ fi #CUSTOM_AUTOCONF_INCLUDE # Do not change or remove the following line, it is needed for consistency checks: -DATE_WHEN_GENERATED=1379077060 +DATE_WHEN_GENERATED=1379500606 ############################################################################### # @@ -17584,6 +17597,33 @@ $as_echo "$as_me: The path of MSVCR_DLL, which resolves as \"$path\", is invalid fi + + +# Check whether --with-dxsdk was given. +if test "${with_dxsdk+set}" = set; then : + withval=$with_dxsdk; { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Option --with-dxsdk is deprecated and will be ignored." >&5 +$as_echo "$as_me: WARNING: Option --with-dxsdk is deprecated and will be ignored." >&2;} +fi + + + + +# Check whether --with-dxsdk-lib was given. +if test "${with_dxsdk_lib+set}" = set; then : + withval=$with_dxsdk_lib; { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Option --with-dxsdk-lib is deprecated and will be ignored." >&5 +$as_echo "$as_me: WARNING: Option --with-dxsdk-lib is deprecated and will be ignored." >&2;} +fi + + + + +# Check whether --with-dxsdk-include was given. +if test "${with_dxsdk_include+set}" = set; then : + withval=$with_dxsdk_include; { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Option --with-dxsdk-include is deprecated and will be ignored." >&5 +$as_echo "$as_me: WARNING: Option --with-dxsdk-include is deprecated and will be ignored." >&2;} +fi + + fi diff --git a/common/autoconf/toolchain.m4 b/common/autoconf/toolchain.m4 index b60f3e3c583..21733003023 100644 --- a/common/autoconf/toolchain.m4 +++ b/common/autoconf/toolchain.m4 @@ -176,6 +176,9 @@ AC_DEFUN([TOOLCHAIN_SETUP_PATHS], [ if test "x$OPENJDK_TARGET_OS" = "xwindows"; then TOOLCHAIN_SETUP_VISUAL_STUDIO_ENV + BASIC_DEPRECATED_ARG_WITH([dxsdk]) + BASIC_DEPRECATED_ARG_WITH([dxsdk-lib]) + BASIC_DEPRECATED_ARG_WITH([dxsdk-include]) fi AC_SUBST(MSVCR_DLL) From f6e98b818159cabd05ad21cadc906c8ef1b5cba6 Mon Sep 17 00:00:00 2001 From: Thomas Schatzl Date: Wed, 18 Sep 2013 13:18:52 +0200 Subject: [PATCH 190/210] 8024669: Native OOME when allocating after changes to maximum heap supporting Coops sizing on sparcv9 After changes in 8010722 the ergonomics for calculating the size of the heap that supports zero based compressed oops changed. This lead to the VM actually using zero based compressed oops. Due to low default HeapBaseMinAddress, the OS mapping in the application image at the same address, and limitations of the malloc implementation on Solaris this resulted in very little C heap available for the VM. So the VM immediately gives a native OOME when the machine has lots of physical memory (>=32G). The solution is to increase the HeapBaseMinAddress so that the VM has enough C heap. Reviewed-by: kvn, brutisso --- hotspot/src/os_cpu/solaris_sparc/vm/globals_solaris_sparc.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hotspot/src/os_cpu/solaris_sparc/vm/globals_solaris_sparc.hpp b/hotspot/src/os_cpu/solaris_sparc/vm/globals_solaris_sparc.hpp index 595cd781447..e0ed6961e3a 100644 --- a/hotspot/src/os_cpu/solaris_sparc/vm/globals_solaris_sparc.hpp +++ b/hotspot/src/os_cpu/solaris_sparc/vm/globals_solaris_sparc.hpp @@ -35,7 +35,9 @@ define_pd_global(intx, CompilerThreadStackSize, 0); // Used on 64 bit platforms for UseCompressedOops base address #ifdef _LP64 -define_pd_global(uintx, HeapBaseMinAddress, CONST64(4)*G); +// use 6G as default base address because by default the OS maps the application +// to 4G on Solaris-Sparc. This leaves at least 2G for the native heap. +define_pd_global(uintx, HeapBaseMinAddress, CONST64(6)*G); #else define_pd_global(uintx, HeapBaseMinAddress, 2*G); #endif From c36b6491454999553a5fc55146fa1c7ff73b35ed Mon Sep 17 00:00:00 2001 From: Magnus Ihse Bursie Date: Wed, 18 Sep 2013 13:49:49 +0200 Subject: [PATCH 191/210] 8024849: Don't remove upper case letters from username when setting USER_RELEASE_SUFFIX Reviewed-by: erikj --- common/autoconf/basics_windows.m4 | 2 +- common/autoconf/generated-configure.sh | 68 +++++++++++++------------- common/autoconf/jdk-options.m4 | 2 +- 3 files changed, 36 insertions(+), 36 deletions(-) diff --git a/common/autoconf/basics_windows.m4 b/common/autoconf/basics_windows.m4 index 9ddb9e8c5c0..0a26d830239 100644 --- a/common/autoconf/basics_windows.m4 +++ b/common/autoconf/basics_windows.m4 @@ -211,7 +211,7 @@ AC_DEFUN([BASIC_FIXUP_EXECUTABLE_CYGWIN], # the same file, most of the time (as in "test -f"). But not when running cygpath -s, then # "foo.exe" is OK but "foo" is an error. # - # This test is therefore slightly more accurate than "test -f" to check for file precense. + # This test is therefore slightly more accurate than "test -f" to check for file presence. # It is also a way to make sure we got the proper file name for the real test later on. test_shortpath=`$CYGPATH -s -m "$new_path" 2> /dev/null` if test "x$test_shortpath" = x; then diff --git a/common/autoconf/generated-configure.sh b/common/autoconf/generated-configure.sh index cf14b82ccfd..7a65a92ecc4 100644 --- a/common/autoconf/generated-configure.sh +++ b/common/autoconf/generated-configure.sh @@ -3818,7 +3818,7 @@ fi #CUSTOM_AUTOCONF_INCLUDE # Do not change or remove the following line, it is needed for consistency checks: -DATE_WHEN_GENERATED=1379500606 +DATE_WHEN_GENERATED=1379504921 ############################################################################### # @@ -8352,7 +8352,7 @@ $as_echo "$as_me: You might be mixing spaces in the path and extra arguments, wh # the same file, most of the time (as in "test -f"). But not when running cygpath -s, then # "foo.exe" is OK but "foo" is an error. # - # This test is therefore slightly more accurate than "test -f" to check for file precense. + # This test is therefore slightly more accurate than "test -f" to check for file presence. # It is also a way to make sure we got the proper file name for the real test later on. test_shortpath=`$CYGPATH -s -m "$new_path" 2> /dev/null` if test "x$test_shortpath" = x; then @@ -8709,7 +8709,7 @@ $as_echo "$as_me: You might be mixing spaces in the path and extra arguments, wh # the same file, most of the time (as in "test -f"). But not when running cygpath -s, then # "foo.exe" is OK but "foo" is an error. # - # This test is therefore slightly more accurate than "test -f" to check for file precense. + # This test is therefore slightly more accurate than "test -f" to check for file presence. # It is also a way to make sure we got the proper file name for the real test later on. test_shortpath=`$CYGPATH -s -m "$new_path" 2> /dev/null` if test "x$test_shortpath" = x; then @@ -9063,7 +9063,7 @@ $as_echo "$as_me: You might be mixing spaces in the path and extra arguments, wh # the same file, most of the time (as in "test -f"). But not when running cygpath -s, then # "foo.exe" is OK but "foo" is an error. # - # This test is therefore slightly more accurate than "test -f" to check for file precense. + # This test is therefore slightly more accurate than "test -f" to check for file presence. # It is also a way to make sure we got the proper file name for the real test later on. test_shortpath=`$CYGPATH -s -m "$new_path" 2> /dev/null` if test "x$test_shortpath" = x; then @@ -9422,7 +9422,7 @@ $as_echo "$as_me: You might be mixing spaces in the path and extra arguments, wh # the same file, most of the time (as in "test -f"). But not when running cygpath -s, then # "foo.exe" is OK but "foo" is an error. # - # This test is therefore slightly more accurate than "test -f" to check for file precense. + # This test is therefore slightly more accurate than "test -f" to check for file presence. # It is also a way to make sure we got the proper file name for the real test later on. test_shortpath=`$CYGPATH -s -m "$new_path" 2> /dev/null` if test "x$test_shortpath" = x; then @@ -9775,7 +9775,7 @@ $as_echo "$as_me: You might be mixing spaces in the path and extra arguments, wh # the same file, most of the time (as in "test -f"). But not when running cygpath -s, then # "foo.exe" is OK but "foo" is an error. # - # This test is therefore slightly more accurate than "test -f" to check for file precense. + # This test is therefore slightly more accurate than "test -f" to check for file presence. # It is also a way to make sure we got the proper file name for the real test later on. test_shortpath=`$CYGPATH -s -m "$new_path" 2> /dev/null` if test "x$test_shortpath" = x; then @@ -11075,7 +11075,7 @@ elif test "x$with_user_release_suffix" != x; then else BUILD_DATE=`date '+%Y_%m_%d_%H_%M'` # Avoid [:alnum:] since it depends on the locale. - CLEAN_USERNAME=`echo "$USER" | $TR -d -c 'abcdefghijklmnopqrstuvqxyz0123456789'` + CLEAN_USERNAME=`echo "$USER" | $TR -d -c 'abcdefghijklmnopqrstuvqxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'` USER_RELEASE_SUFFIX=`echo "${CLEAN_USERNAME}_${BUILD_DATE}" | $TR 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` fi @@ -17101,7 +17101,7 @@ $as_echo "$as_me: You might be mixing spaces in the path and extra arguments, wh # the same file, most of the time (as in "test -f"). But not when running cygpath -s, then # "foo.exe" is OK but "foo" is an error. # - # This test is therefore slightly more accurate than "test -f" to check for file precense. + # This test is therefore slightly more accurate than "test -f" to check for file presence. # It is also a way to make sure we got the proper file name for the real test later on. test_shortpath=`$CYGPATH -s -m "$new_path" 2> /dev/null` if test "x$test_shortpath" = x; then @@ -17747,7 +17747,7 @@ $as_echo "$as_me: You might be mixing spaces in the path and extra arguments, wh # the same file, most of the time (as in "test -f"). But not when running cygpath -s, then # "foo.exe" is OK but "foo" is an error. # - # This test is therefore slightly more accurate than "test -f" to check for file precense. + # This test is therefore slightly more accurate than "test -f" to check for file presence. # It is also a way to make sure we got the proper file name for the real test later on. test_shortpath=`$CYGPATH -s -m "$new_path" 2> /dev/null` if test "x$test_shortpath" = x; then @@ -18058,7 +18058,7 @@ $as_echo "$as_me: You might be mixing spaces in the path and extra arguments, wh # the same file, most of the time (as in "test -f"). But not when running cygpath -s, then # "foo.exe" is OK but "foo" is an error. # - # This test is therefore slightly more accurate than "test -f" to check for file precense. + # This test is therefore slightly more accurate than "test -f" to check for file presence. # It is also a way to make sure we got the proper file name for the real test later on. test_shortpath=`$CYGPATH -s -m "$new_path" 2> /dev/null` if test "x$test_shortpath" = x; then @@ -18364,7 +18364,7 @@ $as_echo "$as_me: You might be mixing spaces in the path and extra arguments, wh # the same file, most of the time (as in "test -f"). But not when running cygpath -s, then # "foo.exe" is OK but "foo" is an error. # - # This test is therefore slightly more accurate than "test -f" to check for file precense. + # This test is therefore slightly more accurate than "test -f" to check for file presence. # It is also a way to make sure we got the proper file name for the real test later on. test_shortpath=`$CYGPATH -s -m "$new_path" 2> /dev/null` if test "x$test_shortpath" = x; then @@ -18957,7 +18957,7 @@ $as_echo "$as_me: You might be mixing spaces in the path and extra arguments, wh # the same file, most of the time (as in "test -f"). But not when running cygpath -s, then # "foo.exe" is OK but "foo" is an error. # - # This test is therefore slightly more accurate than "test -f" to check for file precense. + # This test is therefore slightly more accurate than "test -f" to check for file presence. # It is also a way to make sure we got the proper file name for the real test later on. test_shortpath=`$CYGPATH -s -m "$new_path" 2> /dev/null` if test "x$test_shortpath" = x; then @@ -19393,7 +19393,7 @@ $as_echo "$as_me: You might be mixing spaces in the path and extra arguments, wh # the same file, most of the time (as in "test -f"). But not when running cygpath -s, then # "foo.exe" is OK but "foo" is an error. # - # This test is therefore slightly more accurate than "test -f" to check for file precense. + # This test is therefore slightly more accurate than "test -f" to check for file presence. # It is also a way to make sure we got the proper file name for the real test later on. test_shortpath=`$CYGPATH -s -m "$new_path" 2> /dev/null` if test "x$test_shortpath" = x; then @@ -20529,7 +20529,7 @@ $as_echo "$as_me: You might be mixing spaces in the path and extra arguments, wh # the same file, most of the time (as in "test -f"). But not when running cygpath -s, then # "foo.exe" is OK but "foo" is an error. # - # This test is therefore slightly more accurate than "test -f" to check for file precense. + # This test is therefore slightly more accurate than "test -f" to check for file presence. # It is also a way to make sure we got the proper file name for the real test later on. test_shortpath=`$CYGPATH -s -m "$new_path" 2> /dev/null` if test "x$test_shortpath" = x; then @@ -20965,7 +20965,7 @@ $as_echo "$as_me: You might be mixing spaces in the path and extra arguments, wh # the same file, most of the time (as in "test -f"). But not when running cygpath -s, then # "foo.exe" is OK but "foo" is an error. # - # This test is therefore slightly more accurate than "test -f" to check for file precense. + # This test is therefore slightly more accurate than "test -f" to check for file presence. # It is also a way to make sure we got the proper file name for the real test later on. test_shortpath=`$CYGPATH -s -m "$new_path" 2> /dev/null` if test "x$test_shortpath" = x; then @@ -21866,7 +21866,7 @@ $as_echo "$as_me: You might be mixing spaces in the path and extra arguments, wh # the same file, most of the time (as in "test -f"). But not when running cygpath -s, then # "foo.exe" is OK but "foo" is an error. # - # This test is therefore slightly more accurate than "test -f" to check for file precense. + # This test is therefore slightly more accurate than "test -f" to check for file presence. # It is also a way to make sure we got the proper file name for the real test later on. test_shortpath=`$CYGPATH -s -m "$new_path" 2> /dev/null` if test "x$test_shortpath" = x; then @@ -22247,7 +22247,7 @@ $as_echo "$as_me: You might be mixing spaces in the path and extra arguments, wh # the same file, most of the time (as in "test -f"). But not when running cygpath -s, then # "foo.exe" is OK but "foo" is an error. # - # This test is therefore slightly more accurate than "test -f" to check for file precense. + # This test is therefore slightly more accurate than "test -f" to check for file presence. # It is also a way to make sure we got the proper file name for the real test later on. test_shortpath=`$CYGPATH -s -m "$new_path" 2> /dev/null` if test "x$test_shortpath" = x; then @@ -22594,7 +22594,7 @@ $as_echo "$as_me: You might be mixing spaces in the path and extra arguments, wh # the same file, most of the time (as in "test -f"). But not when running cygpath -s, then # "foo.exe" is OK but "foo" is an error. # - # This test is therefore slightly more accurate than "test -f" to check for file precense. + # This test is therefore slightly more accurate than "test -f" to check for file presence. # It is also a way to make sure we got the proper file name for the real test later on. test_shortpath=`$CYGPATH -s -m "$new_path" 2> /dev/null` if test "x$test_shortpath" = x; then @@ -22931,7 +22931,7 @@ $as_echo "$as_me: You might be mixing spaces in the path and extra arguments, wh # the same file, most of the time (as in "test -f"). But not when running cygpath -s, then # "foo.exe" is OK but "foo" is an error. # - # This test is therefore slightly more accurate than "test -f" to check for file precense. + # This test is therefore slightly more accurate than "test -f" to check for file presence. # It is also a way to make sure we got the proper file name for the real test later on. test_shortpath=`$CYGPATH -s -m "$new_path" 2> /dev/null` if test "x$test_shortpath" = x; then @@ -23252,7 +23252,7 @@ $as_echo "$as_me: You might be mixing spaces in the path and extra arguments, wh # the same file, most of the time (as in "test -f"). But not when running cygpath -s, then # "foo.exe" is OK but "foo" is an error. # - # This test is therefore slightly more accurate than "test -f" to check for file precense. + # This test is therefore slightly more accurate than "test -f" to check for file presence. # It is also a way to make sure we got the proper file name for the real test later on. test_shortpath=`$CYGPATH -s -m "$new_path" 2> /dev/null` if test "x$test_shortpath" = x; then @@ -23627,7 +23627,7 @@ $as_echo "$as_me: You might be mixing spaces in the path and extra arguments, wh # the same file, most of the time (as in "test -f"). But not when running cygpath -s, then # "foo.exe" is OK but "foo" is an error. # - # This test is therefore slightly more accurate than "test -f" to check for file precense. + # This test is therefore slightly more accurate than "test -f" to check for file presence. # It is also a way to make sure we got the proper file name for the real test later on. test_shortpath=`$CYGPATH -s -m "$new_path" 2> /dev/null` if test "x$test_shortpath" = x; then @@ -23933,7 +23933,7 @@ $as_echo "$as_me: You might be mixing spaces in the path and extra arguments, wh # the same file, most of the time (as in "test -f"). But not when running cygpath -s, then # "foo.exe" is OK but "foo" is an error. # - # This test is therefore slightly more accurate than "test -f" to check for file precense. + # This test is therefore slightly more accurate than "test -f" to check for file presence. # It is also a way to make sure we got the proper file name for the real test later on. test_shortpath=`$CYGPATH -s -m "$new_path" 2> /dev/null` if test "x$test_shortpath" = x; then @@ -24344,7 +24344,7 @@ $as_echo "$as_me: You might be mixing spaces in the path and extra arguments, wh # the same file, most of the time (as in "test -f"). But not when running cygpath -s, then # "foo.exe" is OK but "foo" is an error. # - # This test is therefore slightly more accurate than "test -f" to check for file precense. + # This test is therefore slightly more accurate than "test -f" to check for file presence. # It is also a way to make sure we got the proper file name for the real test later on. test_shortpath=`$CYGPATH -s -m "$new_path" 2> /dev/null` if test "x$test_shortpath" = x; then @@ -24744,7 +24744,7 @@ $as_echo "$as_me: You might be mixing spaces in the path and extra arguments, wh # the same file, most of the time (as in "test -f"). But not when running cygpath -s, then # "foo.exe" is OK but "foo" is an error. # - # This test is therefore slightly more accurate than "test -f" to check for file precense. + # This test is therefore slightly more accurate than "test -f" to check for file presence. # It is also a way to make sure we got the proper file name for the real test later on. test_shortpath=`$CYGPATH -s -m "$new_path" 2> /dev/null` if test "x$test_shortpath" = x; then @@ -25073,7 +25073,7 @@ $as_echo "$as_me: You might be mixing spaces in the path and extra arguments, wh # the same file, most of the time (as in "test -f"). But not when running cygpath -s, then # "foo.exe" is OK but "foo" is an error. # - # This test is therefore slightly more accurate than "test -f" to check for file precense. + # This test is therefore slightly more accurate than "test -f" to check for file presence. # It is also a way to make sure we got the proper file name for the real test later on. test_shortpath=`$CYGPATH -s -m "$new_path" 2> /dev/null` if test "x$test_shortpath" = x; then @@ -25385,7 +25385,7 @@ $as_echo "$as_me: You might be mixing spaces in the path and extra arguments, wh # the same file, most of the time (as in "test -f"). But not when running cygpath -s, then # "foo.exe" is OK but "foo" is an error. # - # This test is therefore slightly more accurate than "test -f" to check for file precense. + # This test is therefore slightly more accurate than "test -f" to check for file presence. # It is also a way to make sure we got the proper file name for the real test later on. test_shortpath=`$CYGPATH -s -m "$new_path" 2> /dev/null` if test "x$test_shortpath" = x; then @@ -25691,7 +25691,7 @@ $as_echo "$as_me: You might be mixing spaces in the path and extra arguments, wh # the same file, most of the time (as in "test -f"). But not when running cygpath -s, then # "foo.exe" is OK but "foo" is an error. # - # This test is therefore slightly more accurate than "test -f" to check for file precense. + # This test is therefore slightly more accurate than "test -f" to check for file presence. # It is also a way to make sure we got the proper file name for the real test later on. test_shortpath=`$CYGPATH -s -m "$new_path" 2> /dev/null` if test "x$test_shortpath" = x; then @@ -25997,7 +25997,7 @@ $as_echo "$as_me: You might be mixing spaces in the path and extra arguments, wh # the same file, most of the time (as in "test -f"). But not when running cygpath -s, then # "foo.exe" is OK but "foo" is an error. # - # This test is therefore slightly more accurate than "test -f" to check for file precense. + # This test is therefore slightly more accurate than "test -f" to check for file presence. # It is also a way to make sure we got the proper file name for the real test later on. test_shortpath=`$CYGPATH -s -m "$new_path" 2> /dev/null` if test "x$test_shortpath" = x; then @@ -26303,7 +26303,7 @@ $as_echo "$as_me: You might be mixing spaces in the path and extra arguments, wh # the same file, most of the time (as in "test -f"). But not when running cygpath -s, then # "foo.exe" is OK but "foo" is an error. # - # This test is therefore slightly more accurate than "test -f" to check for file precense. + # This test is therefore slightly more accurate than "test -f" to check for file presence. # It is also a way to make sure we got the proper file name for the real test later on. test_shortpath=`$CYGPATH -s -m "$new_path" 2> /dev/null` if test "x$test_shortpath" = x; then @@ -26662,7 +26662,7 @@ $as_echo "$as_me: You might be mixing spaces in the path and extra arguments, wh # the same file, most of the time (as in "test -f"). But not when running cygpath -s, then # "foo.exe" is OK but "foo" is an error. # - # This test is therefore slightly more accurate than "test -f" to check for file precense. + # This test is therefore slightly more accurate than "test -f" to check for file presence. # It is also a way to make sure we got the proper file name for the real test later on. test_shortpath=`$CYGPATH -s -m "$new_path" 2> /dev/null` if test "x$test_shortpath" = x; then @@ -27022,7 +27022,7 @@ $as_echo "$as_me: You might be mixing spaces in the path and extra arguments, wh # the same file, most of the time (as in "test -f"). But not when running cygpath -s, then # "foo.exe" is OK but "foo" is an error. # - # This test is therefore slightly more accurate than "test -f" to check for file precense. + # This test is therefore slightly more accurate than "test -f" to check for file presence. # It is also a way to make sure we got the proper file name for the real test later on. test_shortpath=`$CYGPATH -s -m "$new_path" 2> /dev/null` if test "x$test_shortpath" = x; then @@ -27395,7 +27395,7 @@ $as_echo "$as_me: You might be mixing spaces in the path and extra arguments, wh # the same file, most of the time (as in "test -f"). But not when running cygpath -s, then # "foo.exe" is OK but "foo" is an error. # - # This test is therefore slightly more accurate than "test -f" to check for file precense. + # This test is therefore slightly more accurate than "test -f" to check for file presence. # It is also a way to make sure we got the proper file name for the real test later on. test_shortpath=`$CYGPATH -s -m "$new_path" 2> /dev/null` if test "x$test_shortpath" = x; then @@ -27766,7 +27766,7 @@ $as_echo "$as_me: You might be mixing spaces in the path and extra arguments, wh # the same file, most of the time (as in "test -f"). But not when running cygpath -s, then # "foo.exe" is OK but "foo" is an error. # - # This test is therefore slightly more accurate than "test -f" to check for file precense. + # This test is therefore slightly more accurate than "test -f" to check for file presence. # It is also a way to make sure we got the proper file name for the real test later on. test_shortpath=`$CYGPATH -s -m "$new_path" 2> /dev/null` if test "x$test_shortpath" = x; then @@ -28075,7 +28075,7 @@ $as_echo "$as_me: You might be mixing spaces in the path and extra arguments, wh # the same file, most of the time (as in "test -f"). But not when running cygpath -s, then # "foo.exe" is OK but "foo" is an error. # - # This test is therefore slightly more accurate than "test -f" to check for file precense. + # This test is therefore slightly more accurate than "test -f" to check for file presence. # It is also a way to make sure we got the proper file name for the real test later on. test_shortpath=`$CYGPATH -s -m "$new_path" 2> /dev/null` if test "x$test_shortpath" = x; then diff --git a/common/autoconf/jdk-options.m4 b/common/autoconf/jdk-options.m4 index ba14373e593..b1c99bbe7dc 100644 --- a/common/autoconf/jdk-options.m4 +++ b/common/autoconf/jdk-options.m4 @@ -446,7 +446,7 @@ elif test "x$with_user_release_suffix" != x; then else BUILD_DATE=`date '+%Y_%m_%d_%H_%M'` # Avoid [:alnum:] since it depends on the locale. - CLEAN_USERNAME=`echo "$USER" | $TR -d -c 'abcdefghijklmnopqrstuvqxyz0123456789'` + CLEAN_USERNAME=`echo "$USER" | $TR -d -c 'abcdefghijklmnopqrstuvqxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'` USER_RELEASE_SUFFIX=`echo "${CLEAN_USERNAME}_${BUILD_DATE}" | $TR 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` fi AC_SUBST(USER_RELEASE_SUFFIX) From f99391ee6f088383a785637b63dbce56fe3f6f5c Mon Sep 17 00:00:00 2001 From: Igor Veresov Date: Wed, 18 Sep 2013 14:10:21 -0700 Subject: [PATCH 192/210] 8023542: Test java/io/File/CheckPermission.java fails due to unfinished recursion (java.lang.StackOverflowError) when JIT'ed code (-client,-server) is running Move null check before klass reference materialization in checkcast Reviewed-by: kvn, roland --- hotspot/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/hotspot/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp b/hotspot/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp index 334d0cc92db..952e1adbc52 100644 --- a/hotspot/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp +++ b/hotspot/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp @@ -1724,14 +1724,6 @@ void LIR_Assembler::emit_typecheck_helper(LIR_OpTypeCheck *op, Label* success, L } assert_different_registers(obj, k_RInfo, klass_RInfo); - if (!k->is_loaded()) { - klass2reg_with_patching(k_RInfo, op->info_for_patch()); - } else { -#ifdef _LP64 - __ mov_metadata(k_RInfo, k->constant_encoding()); -#endif // _LP64 - } - assert(obj != k_RInfo, "must be different"); __ cmpptr(obj, (int32_t)NULL_WORD); if (op->should_profile()) { @@ -1748,6 +1740,14 @@ void LIR_Assembler::emit_typecheck_helper(LIR_OpTypeCheck *op, Label* success, L } else { __ jcc(Assembler::equal, *obj_is_null); } + + if (!k->is_loaded()) { + klass2reg_with_patching(k_RInfo, op->info_for_patch()); + } else { +#ifdef _LP64 + __ mov_metadata(k_RInfo, k->constant_encoding()); +#endif // _LP64 + } __ verify_oop(obj); if (op->fast_check()) { From ff9c0f87c4dd3f17fb075bc0cba65b3dd4762c5c Mon Sep 17 00:00:00 2001 From: Christine Lu Date: Thu, 19 Sep 2013 09:36:42 -0700 Subject: [PATCH 193/210] Added tag jdk8-b108 for changeset 345aa6f8d18a --- .hgtags-top-repo | 1 + 1 file changed, 1 insertion(+) diff --git a/.hgtags-top-repo b/.hgtags-top-repo index d83fa5ca611..fbcdb0977c0 100644 --- a/.hgtags-top-repo +++ b/.hgtags-top-repo @@ -229,3 +229,4 @@ b7e64be81c8a7690703df5711f4fc2375da8a9cb jdk8-b103 5166118c59178b5d31001bc4058e92486ee07d9b jdk8-b105 8e7b4d9fb00fdf1334376aeac050c9bca6d1b383 jdk8-b106 0874bb4707b723d5bb108d379c557cf41529d1a7 jdk8-b107 +9286a6e61291246d88af713f1ef79adeea30fe2e jdk8-b108 From 62ae29e3cad403385213865a0a1c920643d91482 Mon Sep 17 00:00:00 2001 From: Christine Lu Date: Thu, 19 Sep 2013 09:36:44 -0700 Subject: [PATCH 194/210] Added tag jdk8-b108 for changeset 78407de2df2f --- corba/.hgtags | 1 + 1 file changed, 1 insertion(+) diff --git a/corba/.hgtags b/corba/.hgtags index e24845b3555..7271ad7b3fa 100644 --- a/corba/.hgtags +++ b/corba/.hgtags @@ -229,3 +229,4 @@ d411c60a8c2fe8fdc572af907775e90f7eefd513 jdk8-b104 4e38de7c767e34104fa147b5b346d9fe6b731279 jdk8-b105 2e3a056c84a71eba78945c18b05397858ffd7ad0 jdk8-b106 23fc34133152692b725db4bd617b4c8dfd6ccb05 jdk8-b107 +a4bb3b4500164748a9c33b2283cfda76d89f25ab jdk8-b108 From 6e53556facbfe6dbcaa9107947b8d65d137c0f0b Mon Sep 17 00:00:00 2001 From: Christine Lu Date: Thu, 19 Sep 2013 09:36:51 -0700 Subject: [PATCH 195/210] Added tag jdk8-b108 for changeset be8d551c4d00 --- hotspot/.hgtags | 1 + 1 file changed, 1 insertion(+) diff --git a/hotspot/.hgtags b/hotspot/.hgtags index 370ade6688d..024f5b4d0ee 100644 --- a/hotspot/.hgtags +++ b/hotspot/.hgtags @@ -377,3 +377,4 @@ aed585cafc0d9655726af6d1e1081d1c94cb3b5c jdk8-b106 50794d8ac11c9579b41dec4de23b808fef9f34a1 hs25-b49 5b7f90aab3ad25a25b75b7b2bb18d5ae23d8231c jdk8-b107 a09fe9d1e016c285307507a5793bc4fa6215e9c9 hs25-b50 +85072013aad46050a362d10ab78e963121c8014c jdk8-b108 From bfcf677949ddfc9881716d2e57a4512304bb989a Mon Sep 17 00:00:00 2001 From: Christine Lu Date: Thu, 19 Sep 2013 09:37:02 -0700 Subject: [PATCH 196/210] Added tag jdk8-b108 for changeset 261ae91f2b65 --- jaxp/.hgtags | 1 + 1 file changed, 1 insertion(+) diff --git a/jaxp/.hgtags b/jaxp/.hgtags index e136f4f7d31..f3166e9d9df 100644 --- a/jaxp/.hgtags +++ b/jaxp/.hgtags @@ -229,3 +229,4 @@ a22fe9bd01e6c7e7ddc7995dfc9471711692b8d1 jdk8-b104 09a46ec11f880154886c70be03aff5ab2ddf0ab7 jdk8-b105 d3be8e3b429df917e72c1c23e7920c651219b587 jdk8-b106 d6a32e3831aab20a9a3bc78cdc0a60aaad725c6c jdk8-b107 +8ade3eed63da87067a7137c111f684a821e9e531 jdk8-b108 From e8367de47cb63d71d4b42083feb2cc65a29e8cd5 Mon Sep 17 00:00:00 2001 From: Christine Lu Date: Thu, 19 Sep 2013 09:37:05 -0700 Subject: [PATCH 197/210] Added tag jdk8-b108 for changeset 815fb8808c4b --- jaxws/.hgtags | 1 + 1 file changed, 1 insertion(+) diff --git a/jaxws/.hgtags b/jaxws/.hgtags index 164a718d39c..6a23622251b 100644 --- a/jaxws/.hgtags +++ b/jaxws/.hgtags @@ -229,3 +229,4 @@ b1fb4612a2caea52b5661b87509e560fa044b194 jdk8-b98 88390df7ed2cf128298a02c5e6d978f0a603cd58 jdk8-b105 6908370afe834ff01739e8ec992d4246c74b7e6e jdk8-b106 e3c9328f75638289a342ce15fbe532f05078946e jdk8-b107 +d1ea68556fd7925a3c7078dd9f77c6ca73d5aa9e jdk8-b108 From f0b751a85487dc289e5bd6635fa68041611c9fdd Mon Sep 17 00:00:00 2001 From: Christine Lu Date: Thu, 19 Sep 2013 09:37:13 -0700 Subject: [PATCH 198/210] Added tag jdk8-b108 for changeset f45d281bd0de --- jdk/.hgtags | 1 + 1 file changed, 1 insertion(+) diff --git a/jdk/.hgtags b/jdk/.hgtags index 3e3a625970b..6eef7251ea8 100644 --- a/jdk/.hgtags +++ b/jdk/.hgtags @@ -229,3 +229,4 @@ f1d8d15bfcb5ada858a942f8a31f6598f23214d1 jdk8-b104 1fe211ae3d2b8cc2dfc4f58d9a6eb96418679672 jdk8-b105 c817276bd870dfe1dcc3a3dbbc092436b6907f75 jdk8-b106 eea685b9ccaa1980e0a7e07d6a3a84bcc7e9ab82 jdk8-b107 +006aaa5f069e7dd98fccdc696866c9f8582c087c jdk8-b108 From cb06edc1bf96e8683ce735eb0da0da771bf996b0 Mon Sep 17 00:00:00 2001 From: Christine Lu Date: Thu, 19 Sep 2013 09:37:26 -0700 Subject: [PATCH 199/210] Added tag jdk8-b108 for changeset 669e1adcbf50 --- langtools/.hgtags | 1 + 1 file changed, 1 insertion(+) diff --git a/langtools/.hgtags b/langtools/.hgtags index f3ac2a1e9ab..2210809d462 100644 --- a/langtools/.hgtags +++ b/langtools/.hgtags @@ -229,3 +229,4 @@ dd4a00c220c6e14d9b2ce93a2bd436a1d04f0d03 jdk8-b104 375834b5cf086dd7ce9e49f602d81bb51d3e0fa9 jdk8-b105 fcd768844b9926c5f994292ec6350c20cc7c0f76 jdk8-b106 3f274927ec1863544b8214262ab02b7de2970da6 jdk8-b107 +252f872b8a2f81a416f9127e77924ca56a4578b0 jdk8-b108 From 1c1306bb1d06768a13f1b9daad7727829c6507a3 Mon Sep 17 00:00:00 2001 From: Christine Lu Date: Thu, 19 Sep 2013 09:37:28 -0700 Subject: [PATCH 200/210] Added tag jdk8-b108 for changeset 3afa46cd7e01 --- nashorn/.hgtags | 1 + 1 file changed, 1 insertion(+) diff --git a/nashorn/.hgtags b/nashorn/.hgtags index 05fbb43822b..10aa318ed1d 100644 --- a/nashorn/.hgtags +++ b/nashorn/.hgtags @@ -217,3 +217,4 @@ afc100513451d22f0b8135999d6eb52f36df3d36 jdk8-b104 f484bfb624dd06683cb33b524700a5dd4927a82b jdk8-b105 bf70cbd2c8369fd97ffdfcbe1a80dbc2797408ee jdk8-b106 f35e1255024b66f7cf82517798f45f6e194e5567 jdk8-b107 +445ad3f6d3b4ba62ebc483323e1919110a304053 jdk8-b108 From 0f9d70232f18cf1b9f233c8cd22c67140f4894bb Mon Sep 17 00:00:00 2001 From: Alejandro Murillo Date: Fri, 20 Sep 2013 11:09:26 -0700 Subject: [PATCH 201/210] Added tag hs25-b51 for changeset e446e24611f9 --- hotspot/.hgtags | 1 + 1 file changed, 1 insertion(+) diff --git a/hotspot/.hgtags b/hotspot/.hgtags index 024f5b4d0ee..d218a0c962d 100644 --- a/hotspot/.hgtags +++ b/hotspot/.hgtags @@ -378,3 +378,4 @@ aed585cafc0d9655726af6d1e1081d1c94cb3b5c jdk8-b106 5b7f90aab3ad25a25b75b7b2bb18d5ae23d8231c jdk8-b107 a09fe9d1e016c285307507a5793bc4fa6215e9c9 hs25-b50 85072013aad46050a362d10ab78e963121c8014c jdk8-b108 +566db1b0e6efca31f181456e54c8911d0192410d hs25-b51 From 06564ac469c180f4cbc7fa6755fbafa1925b9149 Mon Sep 17 00:00:00 2001 From: Tim Bell Date: Wed, 25 Sep 2013 12:21:35 -0700 Subject: [PATCH 202/210] 8025411: JPRT to switch to the new Win platforms for JDK8 builds this week Reviewed-by: ksrini, katleman --- make/jprt.properties | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/make/jprt.properties b/make/jprt.properties index b7bad856278..3860e9228ba 100644 --- a/make/jprt.properties +++ b/make/jprt.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2006, 2013, 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 @@ -43,8 +43,8 @@ jprt.build.targets= \ linux_i586_2.6-{product|fastdebug}, \ linux_x64_2.6-{product|fastdebug}, \ macosx_x64_10.7-{product|fastdebug}, \ - windows_i586_5.1-{product|fastdebug}, \ - windows_x64_5.2-{product|fastdebug} + windows_i586_6.1-{product|fastdebug}, \ + windows_x64_6.1-{product|fastdebug} # User can select the test set with jprt submit "-testset name" option jprt.my.test.set=${jprt.test.set} @@ -58,8 +58,8 @@ jprt.my.test.target.set= \ linux_i586_2.6-product-{c1|c2}-TESTNAME, \ linux_x64_2.6-product-c2-TESTNAME, \ macosx_x64_10.7-product-c2-TESTNAME, \ - windows_i586_5.1-product-c1-TESTNAME, \ - windows_x64_5.2-product-c2-TESTNAME + windows_i586_6.1-product-c1-TESTNAME, \ + windows_x64_6.1-product-c2-TESTNAME # Default vm test targets (testset=default) jprt.vm.default.test.targets= \ From c5556a0948eaa352580b7d7c3c7f0b4b78b2006e Mon Sep 17 00:00:00 2001 From: Tim Bell Date: Wed, 25 Sep 2013 12:22:44 -0700 Subject: [PATCH 203/210] 8025411: JPRT to switch to the new Win platforms for JDK8 builds this week Reviewed-by: ksrini, katleman --- corba/make/jprt.properties | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/corba/make/jprt.properties b/corba/make/jprt.properties index 360b6b22dba..b03c53ca656 100644 --- a/corba/make/jprt.properties +++ b/corba/make/jprt.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2006, 2013, 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 @@ -39,8 +39,8 @@ jprt.build.targets= \ solaris_x64_5.10-{product|fastdebug}, \ linux_i586_2.6-{product|fastdebug}, \ linux_x64_2.6-{product|fastdebug}, \ - windows_i586_5.1-{product|fastdebug}, \ - windows_x64_5.2-{product|fastdebug} + windows_i586_6.1-{product|fastdebug}, \ + windows_x64_6.1-{product|fastdebug} # Directories to be excluded from the source bundles jprt.bundle.exclude.src.dirs=build dist webrev From f07a2ff3cbdd6cc645de66b0064a00df9e21b0ec Mon Sep 17 00:00:00 2001 From: Tim Bell Date: Wed, 25 Sep 2013 12:23:10 -0700 Subject: [PATCH 204/210] 8025411: JPRT to switch to the new Win platforms for JDK8 builds this week Reviewed-by: ksrini, katleman --- hotspot/make/jprt.properties | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hotspot/make/jprt.properties b/hotspot/make/jprt.properties index 5971546c6d9..f322e7024ae 100644 --- a/hotspot/make/jprt.properties +++ b/hotspot/make/jprt.properties @@ -120,13 +120,13 @@ jprt.my.macosx.x64.jdk7=macosx_x64_10.7 jprt.my.macosx.x64.jdk7u8=${jprt.my.macosx.x64.jdk7} jprt.my.macosx.x64=${jprt.my.macosx.x64.${jprt.tools.default.release}} -jprt.my.windows.i586.jdk8=windows_i586_5.1 -jprt.my.windows.i586.jdk7=windows_i586_5.1 +jprt.my.windows.i586.jdk8=windows_i586_6.1 +jprt.my.windows.i586.jdk7=windows_i586_6.1 jprt.my.windows.i586.jdk7u8=${jprt.my.windows.i586.jdk7} jprt.my.windows.i586=${jprt.my.windows.i586.${jprt.tools.default.release}} -jprt.my.windows.x64.jdk8=windows_x64_5.2 -jprt.my.windows.x64.jdk7=windows_x64_5.2 +jprt.my.windows.x64.jdk8=windows_x64_6.1 +jprt.my.windows.x64.jdk7=windows_x64_6.1 jprt.my.windows.x64.jdk7u8=${jprt.my.windows.x64.jdk7} jprt.my.windows.x64=${jprt.my.windows.x64.${jprt.tools.default.release}} From 502d1331efe784977f49edcad906dc8c2d31b00d Mon Sep 17 00:00:00 2001 From: Tim Bell Date: Wed, 25 Sep 2013 12:23:30 -0700 Subject: [PATCH 205/210] 8025411: JPRT to switch to the new Win platforms for JDK8 builds this week Reviewed-by: ksrini, katleman --- jaxp/make/jprt.properties | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jaxp/make/jprt.properties b/jaxp/make/jprt.properties index 360b6b22dba..b03c53ca656 100644 --- a/jaxp/make/jprt.properties +++ b/jaxp/make/jprt.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2006, 2013, 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 @@ -39,8 +39,8 @@ jprt.build.targets= \ solaris_x64_5.10-{product|fastdebug}, \ linux_i586_2.6-{product|fastdebug}, \ linux_x64_2.6-{product|fastdebug}, \ - windows_i586_5.1-{product|fastdebug}, \ - windows_x64_5.2-{product|fastdebug} + windows_i586_6.1-{product|fastdebug}, \ + windows_x64_6.1-{product|fastdebug} # Directories to be excluded from the source bundles jprt.bundle.exclude.src.dirs=build dist webrev From 18726314c255e908dd4924a088b2a5f2e94bb082 Mon Sep 17 00:00:00 2001 From: Tim Bell Date: Wed, 25 Sep 2013 12:23:40 -0700 Subject: [PATCH 206/210] 8025411: JPRT to switch to the new Win platforms for JDK8 builds this week Reviewed-by: ksrini, katleman --- jaxws/make/jprt.properties | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jaxws/make/jprt.properties b/jaxws/make/jprt.properties index 91064331043..12ce773022a 100644 --- a/jaxws/make/jprt.properties +++ b/jaxws/make/jprt.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2006, 2013, 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 @@ -40,8 +40,8 @@ jprt.build.targets= \ linux_i586_2.6-{product|fastdebug}, \ linux_x64_2.6-{product|fastdebug}, \ macosx_x64_10.7-{product|fastdebug}, \ - windows_i586_5.1-{product|fastdebug}, \ - windows_x64_5.2-{product|fastdebug} + windows_i586_6.1-{product|fastdebug}, \ + windows_x64_6.1-{product|fastdebug} # Directories to be excluded from the source bundles jprt.bundle.exclude.src.dirs=build dist webrev From a13f76ec8c306bf8a526a12e493e5b3b7bc2a6e2 Mon Sep 17 00:00:00 2001 From: Tim Bell Date: Wed, 25 Sep 2013 12:24:05 -0700 Subject: [PATCH 207/210] 8025411: JPRT to switch to the new Win platforms for JDK8 builds this week Reviewed-by: ksrini, katleman --- jdk/make/jprt.properties | 10 ++-- jdk/makefiles/jprt.properties | 106 +++++++++++++++++----------------- 2 files changed, 58 insertions(+), 58 deletions(-) diff --git a/jdk/make/jprt.properties b/jdk/make/jprt.properties index 8f7038e1f3b..eb6ff3ff2f0 100644 --- a/jdk/make/jprt.properties +++ b/jdk/make/jprt.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2006, 2013, 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 @@ -40,8 +40,8 @@ jprt.build.targets= \ linux_i586_2.6-{product|fastdebug}, \ linux_x64_2.6-{product|fastdebug}, \ macosx_x64_10.7-{product|fastdebug}, \ - windows_i586_5.1-{product|fastdebug}, \ - windows_x64_5.2-{product|fastdebug} + windows_i586_6.1-{product|fastdebug}, \ + windows_x64_6.1-{product|fastdebug} # User can select the test set with jprt submit "-testset name" option jprt.my.test.set=${jprt.test.set} @@ -55,8 +55,8 @@ jprt.my.test.target.set= \ linux_i586_2.6-product-{c1|c2}-TESTNAME, \ linux_x64_2.6-product-c2-TESTNAME, \ macosx_x64_10.7-product-c2-TESTNAME, \ - windows_i586_5.1-product-c1-TESTNAME, \ - windows_x64_5.2-product-c2-TESTNAME + windows_i586_6.1-product-c1-TESTNAME, \ + windows_x64_6.1-product-c2-TESTNAME # Default vm test targets (testset=default) jprt.vm.default.test.targets= \ diff --git a/jdk/makefiles/jprt.properties b/jdk/makefiles/jprt.properties index a4a077226e8..1051bb34bb7 100644 --- a/jdk/makefiles/jprt.properties +++ b/jdk/makefiles/jprt.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2006, 2013, 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 @@ -39,8 +39,8 @@ jprt.build.targets= \ solaris_x64_5.10-{product|fastdebug}, \ linux_i586_2.6-{product|fastdebug}, \ linux_x64_2.6-{product|fastdebug}, \ - windows_i586_5.1-{product|fastdebug}, \ - windows_x64_5.2-{product|fastdebug} + windows_i586_6.1-{product|fastdebug}, \ + windows_x64_6.1-{product|fastdebug} # User can select the test set with jprt submit "-testset name" option jprt.my.test.set=${jprt.test.set} @@ -53,8 +53,8 @@ jprt.vm.default.test.targets= \ solaris_x64_5.10-product-c2-jvm98, \ linux_i586_2.6-product-{c1|c2}-jvm98, \ linux_x64_2.6-product-c2-jvm98, \ - windows_i586_5.1-product-c1-jvm98, \ - windows_x64_5.2-product-c2-jvm98 + windows_i586_6.1-product-c1-jvm98, \ + windows_x64_6.1-product-c2-jvm98 # Select vm testlist to use (allow for testset to be empty too) jprt.vm.all.test.targets=${jprt.vm.default.test.targets} @@ -70,8 +70,8 @@ jprt.make.rule.default.test.targets= \ solaris_x64_5.10-product-c2-jdk_beans1, \ linux_i586_2.6-product-{c1|c2}-jdk_beans1, \ linux_x64_2.6-product-c2-jdk_beans1, \ - windows_i586_5.1-product-c1-jdk_beans1, \ - windows_x64_5.2-product-c2-jdk_beans1, \ + windows_i586_6.1-product-c1-jdk_beans1, \ + windows_x64_6.1-product-c2-jdk_beans1, \ \ solaris_sparc_5.10-product-c1-jdk_io, \ solaris_sparcv9_5.10-product-c2-jdk_io, \ @@ -79,8 +79,8 @@ jprt.make.rule.default.test.targets= \ solaris_x64_5.10-product-c2-jdk_io, \ linux_i586_2.6-product-{c1|c2}-jdk_io, \ linux_x64_2.6-product-c2-jdk_io, \ - windows_i586_5.1-product-c1-jdk_io, \ - windows_x64_5.2-product-c2-jdk_io, \ + windows_i586_6.1-product-c1-jdk_io, \ + windows_x64_6.1-product-c2-jdk_io, \ \ solaris_sparc_5.10-product-c1-jdk_lang, \ solaris_sparcv9_5.10-product-c2-jdk_lang, \ @@ -88,8 +88,8 @@ jprt.make.rule.default.test.targets= \ solaris_x64_5.10-product-c2-jdk_lang, \ linux_i586_2.6-product-{c1|c2}-jdk_lang, \ linux_x64_2.6-product-c2-jdk_lang, \ - windows_i586_5.1-product-c1-jdk_lang, \ - windows_x64_5.2-product-c2-jdk_lang, \ + windows_i586_6.1-product-c1-jdk_lang, \ + windows_x64_6.1-product-c2-jdk_lang, \ \ solaris_sparc_5.10-product-c1-jdk_math, \ solaris_sparcv9_5.10-product-c2-jdk_math, \ @@ -97,8 +97,8 @@ jprt.make.rule.default.test.targets= \ solaris_x64_5.10-product-c2-jdk_math, \ linux_i586_2.6-product-{c1|c2}-jdk_math, \ linux_x64_2.6-product-c2-jdk_math, \ - windows_i586_5.1-product-c1-jdk_math, \ - windows_x64_5.2-product-c2-jdk_math, \ + windows_i586_6.1-product-c1-jdk_math, \ + windows_x64_6.1-product-c2-jdk_math, \ \ solaris_sparc_5.10-product-c1-jdk_misc, \ solaris_sparcv9_5.10-product-c2-jdk_misc, \ @@ -106,8 +106,8 @@ jprt.make.rule.default.test.targets= \ solaris_x64_5.10-product-c2-jdk_misc, \ linux_i586_2.6-product-{c1|c2}-jdk_misc, \ linux_x64_2.6-product-c2-jdk_misc, \ - windows_i586_5.1-product-c1-jdk_misc, \ - windows_x64_5.2-product-c2-jdk_misc, \ + windows_i586_6.1-product-c1-jdk_misc, \ + windows_x64_6.1-product-c2-jdk_misc, \ \ solaris_sparc_5.10-product-c1-jdk_net, \ solaris_sparcv9_5.10-product-c2-jdk_net, \ @@ -115,8 +115,8 @@ jprt.make.rule.default.test.targets= \ solaris_x64_5.10-product-c2-jdk_net, \ linux_i586_2.6-product-{c1|c2}-jdk_net, \ linux_x64_2.6-product-c2-jdk_net, \ - windows_i586_5.1-product-c1-jdk_net, \ - windows_x64_5.2-product-c2-jdk_net, \ + windows_i586_6.1-product-c1-jdk_net, \ + windows_x64_6.1-product-c2-jdk_net, \ \ solaris_sparc_5.10-product-c1-jdk_nio1, \ solaris_sparcv9_5.10-product-c2-jdk_nio1, \ @@ -124,8 +124,8 @@ jprt.make.rule.default.test.targets= \ solaris_x64_5.10-product-c2-jdk_nio1, \ linux_i586_2.6-product-{c1|c2}-jdk_nio1, \ linux_x64_2.6-product-c2-jdk_nio1, \ - windows_i586_5.1-product-c1-jdk_nio1, \ - windows_x64_5.2-product-c2-jdk_nio1, \ + windows_i586_6.1-product-c1-jdk_nio1, \ + windows_x64_6.1-product-c2-jdk_nio1, \ \ solaris_sparc_5.10-product-c1-jdk_nio2, \ solaris_sparcv9_5.10-product-c2-jdk_nio2, \ @@ -133,8 +133,8 @@ jprt.make.rule.default.test.targets= \ solaris_x64_5.10-product-c2-jdk_nio2, \ linux_i586_2.6-product-{c1|c2}-jdk_nio2, \ linux_x64_2.6-product-c2-jdk_nio2, \ - windows_i586_5.1-product-c1-jdk_nio2, \ - windows_x64_5.2-product-c2-jdk_nio2, \ + windows_i586_6.1-product-c1-jdk_nio2, \ + windows_x64_6.1-product-c2-jdk_nio2, \ \ solaris_sparc_5.10-product-c1-jdk_nio3, \ solaris_sparcv9_5.10-product-c2-jdk_nio3, \ @@ -142,8 +142,8 @@ jprt.make.rule.default.test.targets= \ solaris_x64_5.10-product-c2-jdk_nio3, \ linux_i586_2.6-product-{c1|c2}-jdk_nio3, \ linux_x64_2.6-product-c2-jdk_nio3, \ - windows_i586_5.1-product-c1-jdk_nio3, \ - windows_x64_5.2-product-c2-jdk_nio3, \ + windows_i586_6.1-product-c1-jdk_nio3, \ + windows_x64_6.1-product-c2-jdk_nio3, \ \ solaris_sparc_5.10-product-c1-jdk_security1, \ solaris_sparcv9_5.10-product-c2-jdk_security1, \ @@ -151,8 +151,8 @@ jprt.make.rule.default.test.targets= \ solaris_x64_5.10-product-c2-jdk_security1, \ linux_i586_2.6-product-{c1|c2}-jdk_security1, \ linux_x64_2.6-product-c2-jdk_security1, \ - windows_i586_5.1-product-c1-jdk_security1, \ - windows_x64_5.2-product-c2-jdk_security1, \ + windows_i586_6.1-product-c1-jdk_security1, \ + windows_x64_6.1-product-c2-jdk_security1, \ \ solaris_sparc_5.10-product-c1-jdk_text, \ solaris_sparcv9_5.10-product-c2-jdk_text, \ @@ -160,8 +160,8 @@ jprt.make.rule.default.test.targets= \ solaris_x64_5.10-product-c2-jdk_text, \ linux_i586_2.6-product-{c1|c2}-jdk_text, \ linux_x64_2.6-product-c2-jdk_text, \ - windows_i586_5.1-product-c1-jdk_text, \ - windows_x64_5.2-product-c2-jdk_text, \ + windows_i586_6.1-product-c1-jdk_text, \ + windows_x64_6.1-product-c2-jdk_text, \ \ solaris_sparc_5.10-product-c1-jdk_tools1, \ solaris_sparcv9_5.10-product-c2-jdk_tools1, \ @@ -169,8 +169,8 @@ jprt.make.rule.default.test.targets= \ solaris_x64_5.10-product-c2-jdk_tools1, \ linux_i586_2.6-product-{c1|c2}-jdk_tools1, \ linux_x64_2.6-product-c2-jdk_tools1, \ - windows_i586_5.1-product-c1-jdk_tools1, \ - windows_x64_5.2-product-c2-jdk_tools1, \ + windows_i586_6.1-product-c1-jdk_tools1, \ + windows_x64_6.1-product-c2-jdk_tools1, \ \ solaris_sparc_5.10-product-c1-jdk_util, \ solaris_sparcv9_5.10-product-c2-jdk_util, \ @@ -178,8 +178,8 @@ jprt.make.rule.default.test.targets= \ solaris_x64_5.10-product-c2-jdk_util, \ linux_i586_2.6-product-{c1|c2}-jdk_util, \ linux_x64_2.6-product-c2-jdk_util, \ - windows_i586_5.1-product-c1-jdk_util, \ - windows_x64_5.2-product-c2-jdk_util + windows_i586_6.1-product-c1-jdk_util, \ + windows_x64_6.1-product-c2-jdk_util # All jdk test targets in test/Makefile (still no fastdebug & limited c2) jprt.make.rule.all.test.targets= \ @@ -192,8 +192,8 @@ jprt.make.rule.all.test.targets= \ solaris_x64_5.10-product-c2-jdk_awt, \ linux_i586_2.6-product-{c1|c2}-jdk_awt, \ linux_x64_2.6-product-c2-jdk_awt, \ - windows_i586_5.1-product-c1-jdk_awt, \ - windows_x64_5.2-product-c2-jdk_awt, \ + windows_i586_6.1-product-c1-jdk_awt, \ + windows_x64_6.1-product-c2-jdk_awt, \ \ solaris_sparc_5.10-product-c1-jdk_beans2, \ solaris_sparcv9_5.10-product-c2-jdk_beans2, \ @@ -201,8 +201,8 @@ jprt.make.rule.all.test.targets= \ solaris_x64_5.10-product-c2-jdk_beans2, \ linux_i586_2.6-product-{c1|c2}-jdk_beans2, \ linux_x64_2.6-product-c2-jdk_beans2, \ - windows_i586_5.1-product-c1-jdk_beans2, \ - windows_x64_5.2-product-c2-jdk_beans2, \ + windows_i586_6.1-product-c1-jdk_beans2, \ + windows_x64_6.1-product-c2-jdk_beans2, \ \ solaris_sparc_5.10-product-c1-jdk_beans3, \ solaris_sparcv9_5.10-product-c2-jdk_beans3, \ @@ -210,8 +210,8 @@ jprt.make.rule.all.test.targets= \ solaris_x64_5.10-product-c2-jdk_beans3, \ linux_i586_2.6-product-{c1|c2}-jdk_beans3, \ linux_x64_2.6-product-c2-jdk_beans3, \ - windows_i586_5.1-product-c1-jdk_beans3, \ - windows_x64_5.2-product-c2-jdk_beans3, \ + windows_i586_6.1-product-c1-jdk_beans3, \ + windows_x64_6.1-product-c2-jdk_beans3, \ \ solaris_sparc_5.10-product-c1-jdk_management1, \ solaris_sparcv9_5.10-product-c2-jdk_management1, \ @@ -219,8 +219,8 @@ jprt.make.rule.all.test.targets= \ solaris_x64_5.10-product-c2-jdk_management1, \ linux_i586_2.6-product-{c1|c2}-jdk_management1, \ linux_x64_2.6-product-c2-jdk_management1, \ - windows_i586_5.1-product-c1-jdk_management1, \ - windows_x64_5.2-product-c2-jdk_management1, \ + windows_i586_6.1-product-c1-jdk_management1, \ + windows_x64_6.1-product-c2-jdk_management1, \ \ solaris_sparc_5.10-product-c1-jdk_management2, \ solaris_sparcv9_5.10-product-c2-jdk_management2, \ @@ -228,8 +228,8 @@ jprt.make.rule.all.test.targets= \ solaris_x64_5.10-product-c2-jdk_management2, \ linux_i586_2.6-product-{c1|c2}-jdk_management2, \ linux_x64_2.6-product-c2-jdk_management2, \ - windows_i586_5.1-product-c1-jdk_management2, \ - windows_x64_5.2-product-c2-jdk_management2, \ + windows_i586_6.1-product-c1-jdk_management2, \ + windows_x64_6.1-product-c2-jdk_management2, \ \ solaris_sparc_5.10-product-c1-jdk_rmi, \ solaris_sparcv9_5.10-product-c2-jdk_rmi, \ @@ -237,8 +237,8 @@ jprt.make.rule.all.test.targets= \ solaris_x64_5.10-product-c2-jdk_rmi, \ linux_i586_2.6-product-{c1|c2}-jdk_rmi, \ linux_x64_2.6-product-c2-jdk_rmi, \ - windows_i586_5.1-product-c1-jdk_rmi, \ - windows_x64_5.2-product-c2-jdk_rmi, \ + windows_i586_6.1-product-c1-jdk_rmi, \ + windows_x64_6.1-product-c2-jdk_rmi, \ \ solaris_sparc_5.10-product-c1-jdk_security2, \ solaris_sparcv9_5.10-product-c2-jdk_security2, \ @@ -246,8 +246,8 @@ jprt.make.rule.all.test.targets= \ solaris_x64_5.10-product-c2-jdk_security2, \ linux_i586_2.6-product-{c1|c2}-jdk_security2, \ linux_x64_2.6-product-c2-jdk_security2, \ - windows_i586_5.1-product-c1-jdk_security2, \ - windows_x64_5.2-product-c2-jdk_security2, \ + windows_i586_6.1-product-c1-jdk_security2, \ + windows_x64_6.1-product-c2-jdk_security2, \ \ solaris_sparc_5.10-product-c1-jdk_security3, \ solaris_sparcv9_5.10-product-c2-jdk_security3, \ @@ -255,8 +255,8 @@ jprt.make.rule.all.test.targets= \ solaris_x64_5.10-product-c2-jdk_security3, \ linux_i586_2.6-product-{c1|c2}-jdk_security3, \ linux_x64_2.6-product-c2-jdk_security3, \ - windows_i586_5.1-product-c1-jdk_security3, \ - windows_x64_5.2-product-c2-jdk_security3, \ + windows_i586_6.1-product-c1-jdk_security3, \ + windows_x64_6.1-product-c2-jdk_security3, \ \ solaris_sparc_5.10-product-c1-jdk_sound, \ solaris_sparcv9_5.10-product-c2-jdk_sound, \ @@ -264,8 +264,8 @@ jprt.make.rule.all.test.targets= \ solaris_x64_5.10-product-c2-jdk_sound, \ linux_i586_2.6-product-{c1|c2}-jdk_sound, \ linux_x64_2.6-product-c2-jdk_sound, \ - windows_i586_5.1-product-c1-jdk_sound, \ - windows_x64_5.2-product-c2-jdk_sound, \ + windows_i586_6.1-product-c1-jdk_sound, \ + windows_x64_6.1-product-c2-jdk_sound, \ \ solaris_sparc_5.10-product-c1-jdk_swing, \ solaris_sparcv9_5.10-product-c2-jdk_swing, \ @@ -273,8 +273,8 @@ jprt.make.rule.all.test.targets= \ solaris_x64_5.10-product-c2-jdk_swing, \ linux_i586_2.6-product-{c1|c2}-jdk_swing, \ linux_x64_2.6-product-c2-jdk_swing, \ - windows_i586_5.1-product-c1-jdk_swing, \ - windows_x64_5.2-product-c2-jdk_swing, \ + windows_i586_6.1-product-c1-jdk_swing, \ + windows_x64_6.1-product-c2-jdk_swing, \ \ solaris_sparc_5.10-product-c1-jdk_tools2, \ solaris_sparcv9_5.10-product-c2-jdk_tools2, \ @@ -282,8 +282,8 @@ jprt.make.rule.all.test.targets= \ solaris_x64_5.10-product-c2-jdk_tools2, \ linux_i586_2.6-product-{c1|c2}-jdk_tools2, \ linux_x64_2.6-product-c2-jdk_tools2, \ - windows_i586_5.1-product-c1-jdk_tools2, \ - windows_x64_5.2-product-c2-jdk_tools2 + windows_i586_6.1-product-c1-jdk_tools2, \ + windows_x64_6.1-product-c2-jdk_tools2 # JCK test targets in test/Makefile (no fastdebug & limited c2, windows broken) jprt.my.jck.test.target.set= \ From 2578c3a839ed5a2e408ceeb54e697ab955e80c4c Mon Sep 17 00:00:00 2001 From: Tim Bell Date: Wed, 25 Sep 2013 12:24:13 -0700 Subject: [PATCH 208/210] 8025411: JPRT to switch to the new Win platforms for JDK8 builds this week Reviewed-by: ksrini, katleman --- langtools/make/jprt.properties | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/langtools/make/jprt.properties b/langtools/make/jprt.properties index c0399ed7083..734fa8cd89d 100644 --- a/langtools/make/jprt.properties +++ b/langtools/make/jprt.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2006, 2013, 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 @@ -40,8 +40,8 @@ jprt.build.targets= \ linux_i586_2.6-{product|fastdebug}, \ linux_x64_2.6-{product|fastdebug}, \ macosx_x64_10.7-{product|fastdebug}, \ - windows_i586_5.1-{product|fastdebug}, \ - windows_x64_5.2-{product|fastdebug} + windows_i586_6.1-{product|fastdebug}, \ + windows_x64_6.1-{product|fastdebug} # Test target list (no fastdebug & limited c2 testing) jprt.my.test.target.set= \ @@ -52,8 +52,8 @@ jprt.my.test.target.set= \ linux_i586_2.6-product-{c1|c2}-TESTNAME, \ linux_x64_2.6-product-c2-TESTNAME, \ macosx_x64_10.7-product-c2-TESTNAME, \ - windows_i586_5.1-product-c1-TESTNAME, \ - windows_x64_5.2-product-c2-TESTNAME + windows_i586_6.1-product-c1-TESTNAME, \ + windows_x64_6.1-product-c2-TESTNAME # Default test targets jprt.make.rule.test.targets= \ @@ -71,8 +71,8 @@ jprt.my.test.target.set= \ linux_i586_2.6-product-{c1|c2}-TESTNAME, \ linux_x64_2.6-product-c2-TESTNAME, \ macosx_x64_10.7-product-c2-TESTNAME, \ - windows_i586_5.1-product-c1-TESTNAME, \ - windows_x64_5.2-product-c2-TESTNAME + windows_i586_6.1-product-c1-TESTNAME, \ + windows_x64_6.1-product-c2-TESTNAME # Default test targets jprt.make.rule.test.targets= \ From 76083df2e17538305001238edde73f67ecce0129 Mon Sep 17 00:00:00 2001 From: "J. Duke" Date: Wed, 5 Jul 2017 19:11:15 +0200 Subject: [PATCH 209/210] Added tag jdk8-b107 for changeset 892889f44575 --- .hgtags | 1 + 1 file changed, 1 insertion(+) diff --git a/.hgtags b/.hgtags index f59b4028db2..2fc464b6481 100644 --- a/.hgtags +++ b/.hgtags @@ -228,3 +228,4 @@ bbe43d712fe08e650808d774861b256ccb34e500 jdk8-b102 b5ed503c26ad38869c247c5e32debec217fd056b jdk8-b104 589f4fdc584e373a47cde0162e9eceec9165c381 jdk8-b105 514b0b69fb9683ef52062fd962a3e0644431f64d jdk8-b106 +892889f445755790ae90e61775bfb59ddc6182b5 jdk8-b107 From 37283c9847217f6606b916faee02d733e3ea9f2b Mon Sep 17 00:00:00 2001 From: "J. Duke" Date: Wed, 5 Jul 2017 19:12:21 +0200 Subject: [PATCH 210/210] Added tag jdk8-b108 for changeset 74049f7a28b4 --- .hgtags | 1 + 1 file changed, 1 insertion(+) diff --git a/.hgtags b/.hgtags index 2fc464b6481..a3f78b33edc 100644 --- a/.hgtags +++ b/.hgtags @@ -229,3 +229,4 @@ b5ed503c26ad38869c247c5e32debec217fd056b jdk8-b104 589f4fdc584e373a47cde0162e9eceec9165c381 jdk8-b105 514b0b69fb9683ef52062fd962a3e0644431f64d jdk8-b106 892889f445755790ae90e61775bfb59ddc6182b5 jdk8-b107 +74049f7a28b48c14910106a75d9f2504169c352e jdk8-b108