From 00cf15a96c8fd2ad5bda7e4965eb8f46151d11ec Mon Sep 17 00:00:00 2001 From: Masayoshi Okutsu Date: Thu, 3 Dec 2015 15:34:08 +0900 Subject: [PATCH 1/8] 8141243: Unexpected timezone returned after parsing a date Reviewed-by: naoto, peytoia --- .../ResourceBundleGenerator.java | 3 +- .../sun/util/resources/TimeZoneNames.java | 2 +- .../util/resources/de/TimeZoneNames_de.java | 2 +- .../util/resources/es/TimeZoneNames_es.java | 2 +- .../util/resources/fr/TimeZoneNames_fr.java | 2 +- .../util/resources/it/TimeZoneNames_it.java | 2 +- .../util/resources/ja/TimeZoneNames_ja.java | 2 +- .../util/resources/ko/TimeZoneNames_ko.java | 2 +- .../resources/pt/BR/TimeZoneNames_pt_BR.java | 2 +- .../util/resources/sv/TimeZoneNames_sv.java | 2 +- .../resources/zh/CN/TimeZoneNames_zh_CN.java | 2 +- .../resources/zh/TW/TimeZoneNames_zh_TW.java | 2 +- .../text/Format/DateFormat/Bug8141243.java | 84 +++++++++++++++++++ 13 files changed, 97 insertions(+), 12 deletions(-) create mode 100644 jdk/test/java/text/Format/DateFormat/Bug8141243.java diff --git a/jdk/make/src/classes/build/tools/cldrconverter/ResourceBundleGenerator.java b/jdk/make/src/classes/build/tools/cldrconverter/ResourceBundleGenerator.java index 697e7172081..26857aa2157 100644 --- a/jdk/make/src/classes/build/tools/cldrconverter/ResourceBundleGenerator.java +++ b/jdk/make/src/classes/build/tools/cldrconverter/ResourceBundleGenerator.java @@ -62,6 +62,7 @@ class ResourceBundleGenerator implements BundleGenerator { "Asia/Tokyo", "Europe/Bucharest", "Asia/Shanghai", + "UTC", }; // For duplicated values @@ -136,7 +137,7 @@ class ResourceBundleGenerator implements BundleGenerator { for (String preferred : preferredTZIDs) { if (map.containsKey(preferred)) { newMap.put(preferred, map.remove(preferred)); - } else if ("GMT".equals(preferred) && + } else if (("GMT".equals(preferred) || "UTC".equals(preferred)) && metaKeys.contains(CLDRConverter.METAZONE_ID_PREFIX+preferred)) { newMap.put(preferred, preferred); } diff --git a/jdk/src/java.base/share/classes/sun/util/resources/TimeZoneNames.java b/jdk/src/java.base/share/classes/sun/util/resources/TimeZoneNames.java index fba48a35787..d0b8197fb9e 100644 --- a/jdk/src/java.base/share/classes/sun/util/resources/TimeZoneNames.java +++ b/jdk/src/java.base/share/classes/sun/util/resources/TimeZoneNames.java @@ -307,6 +307,7 @@ public final class TimeZoneNames extends TimeZoneNamesBundle { {"Europe/Bucharest", EET}, {"Asia/Shanghai", CTT}, {"CTT", CTT}, + {"UTC", UTC}, /* Don't change the order of the above zones * to keep compatibility with the previous version. */ @@ -1034,7 +1035,6 @@ public final class TimeZoneNames extends TimeZoneNamesBundle { {"US/Pacific", PST}, {"US/Pacific-New", PST}, {"US/Samoa", SAMOA}, - {"UTC", UTC}, {"VST", ICT}, {"W-SU", MSK}, {"WET", WET}, diff --git a/jdk/src/jdk.localedata/share/classes/sun/util/resources/de/TimeZoneNames_de.java b/jdk/src/jdk.localedata/share/classes/sun/util/resources/de/TimeZoneNames_de.java index 14dce89f91c..6a594cf0199 100644 --- a/jdk/src/jdk.localedata/share/classes/sun/util/resources/de/TimeZoneNames_de.java +++ b/jdk/src/jdk.localedata/share/classes/sun/util/resources/de/TimeZoneNames_de.java @@ -308,6 +308,7 @@ public final class TimeZoneNames_de extends TimeZoneNamesBundle { {"Europe/Bucharest", EET}, {"Asia/Shanghai", CTT}, {"CTT", CTT}, + {"UTC", UTC}, /* Don't change the order of the above zones * to keep compatibility with the previous version. */ @@ -1034,7 +1035,6 @@ public final class TimeZoneNames_de extends TimeZoneNamesBundle { {"US/Pacific", PST}, {"US/Pacific-New", PST}, {"US/Samoa", SAMOA}, - {"UTC", UTC}, {"VST", ICT}, {"W-SU", MSK}, {"WET", WET}, diff --git a/jdk/src/jdk.localedata/share/classes/sun/util/resources/es/TimeZoneNames_es.java b/jdk/src/jdk.localedata/share/classes/sun/util/resources/es/TimeZoneNames_es.java index 081d1a0d56f..ef20bd1a320 100644 --- a/jdk/src/jdk.localedata/share/classes/sun/util/resources/es/TimeZoneNames_es.java +++ b/jdk/src/jdk.localedata/share/classes/sun/util/resources/es/TimeZoneNames_es.java @@ -308,6 +308,7 @@ public final class TimeZoneNames_es extends TimeZoneNamesBundle { {"Europe/Bucharest", EET}, {"Asia/Shanghai", CTT}, {"CTT", CTT}, + {"UTC", UTC}, /* Don't change the order of the above zones * to keep compatibility with the previous version. */ @@ -1034,7 +1035,6 @@ public final class TimeZoneNames_es extends TimeZoneNamesBundle { {"US/Pacific", PST}, {"US/Pacific-New", PST}, {"US/Samoa", SAMOA}, - {"UTC", UTC}, {"VST", ICT}, {"W-SU", MSK}, {"WET", WET}, diff --git a/jdk/src/jdk.localedata/share/classes/sun/util/resources/fr/TimeZoneNames_fr.java b/jdk/src/jdk.localedata/share/classes/sun/util/resources/fr/TimeZoneNames_fr.java index 426e2be867b..f22b27afcbc 100644 --- a/jdk/src/jdk.localedata/share/classes/sun/util/resources/fr/TimeZoneNames_fr.java +++ b/jdk/src/jdk.localedata/share/classes/sun/util/resources/fr/TimeZoneNames_fr.java @@ -308,6 +308,7 @@ public final class TimeZoneNames_fr extends TimeZoneNamesBundle { {"Europe/Bucharest", EET}, {"Asia/Shanghai", CTT}, {"CTT", CTT}, + {"UTC", UTC}, /* Don't change the order of the above zones * to keep compatibility with the previous version. */ @@ -1034,7 +1035,6 @@ public final class TimeZoneNames_fr extends TimeZoneNamesBundle { {"US/Pacific", PST}, {"US/Pacific-New", PST}, {"US/Samoa", SAMOA}, - {"UTC", UTC}, {"VST", ICT}, {"W-SU", MSK}, {"WET", WET}, diff --git a/jdk/src/jdk.localedata/share/classes/sun/util/resources/it/TimeZoneNames_it.java b/jdk/src/jdk.localedata/share/classes/sun/util/resources/it/TimeZoneNames_it.java index 6fb3657965d..311ceea07cf 100644 --- a/jdk/src/jdk.localedata/share/classes/sun/util/resources/it/TimeZoneNames_it.java +++ b/jdk/src/jdk.localedata/share/classes/sun/util/resources/it/TimeZoneNames_it.java @@ -308,6 +308,7 @@ public final class TimeZoneNames_it extends TimeZoneNamesBundle { {"Europe/Bucharest", EET}, {"Asia/Shanghai", CTT}, {"CTT", CTT}, + {"UTC", UTC}, /* Don't change the order of the above zones * to keep compatibility with the previous version. */ @@ -1034,7 +1035,6 @@ public final class TimeZoneNames_it extends TimeZoneNamesBundle { {"US/Pacific", PST}, {"US/Pacific-New", PST}, {"US/Samoa", SAMOA}, - {"UTC", UTC}, {"VST", ICT}, {"W-SU", MSK}, {"WET", WET}, diff --git a/jdk/src/jdk.localedata/share/classes/sun/util/resources/ja/TimeZoneNames_ja.java b/jdk/src/jdk.localedata/share/classes/sun/util/resources/ja/TimeZoneNames_ja.java index 3cf72c4d1ae..9f6dd7e8aa8 100644 --- a/jdk/src/jdk.localedata/share/classes/sun/util/resources/ja/TimeZoneNames_ja.java +++ b/jdk/src/jdk.localedata/share/classes/sun/util/resources/ja/TimeZoneNames_ja.java @@ -308,6 +308,7 @@ public final class TimeZoneNames_ja extends TimeZoneNamesBundle { {"Europe/Bucharest", EET}, {"Asia/Shanghai", CTT}, {"CTT", CTT}, + {"UTC", UTC}, /* Don't change the order of the above zones * to keep compatibility with the previous version. */ @@ -1034,7 +1035,6 @@ public final class TimeZoneNames_ja extends TimeZoneNamesBundle { {"US/Pacific", PST}, {"US/Pacific-New", PST}, {"US/Samoa", SAMOA}, - {"UTC", UTC}, {"VST", ICT}, {"W-SU", MSK}, {"WET", WET}, diff --git a/jdk/src/jdk.localedata/share/classes/sun/util/resources/ko/TimeZoneNames_ko.java b/jdk/src/jdk.localedata/share/classes/sun/util/resources/ko/TimeZoneNames_ko.java index 61485c86c32..7432190e7a9 100644 --- a/jdk/src/jdk.localedata/share/classes/sun/util/resources/ko/TimeZoneNames_ko.java +++ b/jdk/src/jdk.localedata/share/classes/sun/util/resources/ko/TimeZoneNames_ko.java @@ -308,6 +308,7 @@ public final class TimeZoneNames_ko extends TimeZoneNamesBundle { {"Europe/Bucharest", EET}, {"Asia/Shanghai", CTT}, {"CTT", CTT}, + {"UTC", UTC}, /* Don't change the order of the above zones * to keep compatibility with the previous version. */ @@ -1034,7 +1035,6 @@ public final class TimeZoneNames_ko extends TimeZoneNamesBundle { {"US/Pacific", PST}, {"US/Pacific-New", PST}, {"US/Samoa", SAMOA}, - {"UTC", UTC}, {"VST", ICT}, {"W-SU", MSK}, {"WET", WET}, diff --git a/jdk/src/jdk.localedata/share/classes/sun/util/resources/pt/BR/TimeZoneNames_pt_BR.java b/jdk/src/jdk.localedata/share/classes/sun/util/resources/pt/BR/TimeZoneNames_pt_BR.java index aade1bb9537..44bed26f776 100644 --- a/jdk/src/jdk.localedata/share/classes/sun/util/resources/pt/BR/TimeZoneNames_pt_BR.java +++ b/jdk/src/jdk.localedata/share/classes/sun/util/resources/pt/BR/TimeZoneNames_pt_BR.java @@ -308,6 +308,7 @@ public final class TimeZoneNames_pt_BR extends TimeZoneNamesBundle { {"Europe/Bucharest", EET}, {"Asia/Shanghai", CTT}, {"CTT", CTT}, + {"UTC", UTC}, /* Don't change the order of the above zones * to keep compatibility with the previous version. */ @@ -1034,7 +1035,6 @@ public final class TimeZoneNames_pt_BR extends TimeZoneNamesBundle { {"US/Pacific", PST}, {"US/Pacific-New", PST}, {"US/Samoa", SAMOA}, - {"UTC", UTC}, {"VST", ICT}, {"W-SU", MSK}, {"WET", WET}, diff --git a/jdk/src/jdk.localedata/share/classes/sun/util/resources/sv/TimeZoneNames_sv.java b/jdk/src/jdk.localedata/share/classes/sun/util/resources/sv/TimeZoneNames_sv.java index f857b0aeba3..86285b8c9fa 100644 --- a/jdk/src/jdk.localedata/share/classes/sun/util/resources/sv/TimeZoneNames_sv.java +++ b/jdk/src/jdk.localedata/share/classes/sun/util/resources/sv/TimeZoneNames_sv.java @@ -308,6 +308,7 @@ public final class TimeZoneNames_sv extends TimeZoneNamesBundle { {"Europe/Bucharest", EET}, {"Asia/Shanghai", CTT}, {"CTT", CTT}, + {"UTC", UTC}, /* Don't change the order of the above zones * to keep compatibility with the previous version. */ @@ -1034,7 +1035,6 @@ public final class TimeZoneNames_sv extends TimeZoneNamesBundle { {"US/Pacific", PST}, {"US/Pacific-New", PST}, {"US/Samoa", SAMOA}, - {"UTC", UTC}, {"VST", ICT}, {"W-SU", MSK}, {"WET", WET}, diff --git a/jdk/src/jdk.localedata/share/classes/sun/util/resources/zh/CN/TimeZoneNames_zh_CN.java b/jdk/src/jdk.localedata/share/classes/sun/util/resources/zh/CN/TimeZoneNames_zh_CN.java index dbbae8373f2..f3e82346cd8 100644 --- a/jdk/src/jdk.localedata/share/classes/sun/util/resources/zh/CN/TimeZoneNames_zh_CN.java +++ b/jdk/src/jdk.localedata/share/classes/sun/util/resources/zh/CN/TimeZoneNames_zh_CN.java @@ -308,6 +308,7 @@ public final class TimeZoneNames_zh_CN extends TimeZoneNamesBundle { {"Europe/Bucharest", EET}, {"Asia/Shanghai", CTT}, {"CTT", CTT}, + {"UTC", UTC}, /* Don't change the order of the above zones * to keep compatibility with the previous version. */ @@ -1034,7 +1035,6 @@ public final class TimeZoneNames_zh_CN extends TimeZoneNamesBundle { {"US/Pacific", PST}, {"US/Pacific-New", PST}, {"US/Samoa", SAMOA}, - {"UTC", UTC}, {"VST", ICT}, {"W-SU", MSK}, {"WET", WET}, diff --git a/jdk/src/jdk.localedata/share/classes/sun/util/resources/zh/TW/TimeZoneNames_zh_TW.java b/jdk/src/jdk.localedata/share/classes/sun/util/resources/zh/TW/TimeZoneNames_zh_TW.java index 4d3caee1cc3..b5bce8bbb37 100644 --- a/jdk/src/jdk.localedata/share/classes/sun/util/resources/zh/TW/TimeZoneNames_zh_TW.java +++ b/jdk/src/jdk.localedata/share/classes/sun/util/resources/zh/TW/TimeZoneNames_zh_TW.java @@ -308,6 +308,7 @@ public final class TimeZoneNames_zh_TW extends TimeZoneNamesBundle { {"Europe/Bucharest", EET}, {"Asia/Shanghai", CTT}, {"CTT", CTT}, + {"UTC", UTC}, /* Don't change the order of the above zones * to keep compatibility with the previous version. */ @@ -1036,7 +1037,6 @@ public final class TimeZoneNames_zh_TW extends TimeZoneNamesBundle { {"US/Pacific", PST}, {"US/Pacific-New", PST}, {"US/Samoa", SAMOA}, - {"UTC", UTC}, {"VST", ICT}, {"W-SU", MSK}, {"WET", WET}, diff --git a/jdk/test/java/text/Format/DateFormat/Bug8141243.java b/jdk/test/java/text/Format/DateFormat/Bug8141243.java new file mode 100644 index 00000000000..ddc78acea06 --- /dev/null +++ b/jdk/test/java/text/Format/DateFormat/Bug8141243.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2015, 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 8141243 + * @summary Make sure that SimpleDateFormat parses "UTC" as the UTC time zone. + * @run main Bug8141243 + * @run main/othervm -Djava.locale.providers=COMPAT Bug8141243 + */ + +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Locale; +import java.util.TimeZone; +import static java.util.TimeZone.*; + +public class Bug8141243 { + public static void main(String[] args) { + TimeZone UTC = TimeZone.getTimeZone("UTC"); + TimeZone initTz = TimeZone.getDefault(); + + List errors = new ArrayList<>(); + try { + TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles")); + for (Locale locale : DateFormat.getAvailableLocales()) { + // exclude any locales which localize "UTC". + String utc = UTC.getDisplayName(false, SHORT, locale); + if (!"UTC".equals(utc)) { + System.out.println("Skipping " + locale + " due to localized UTC name: " + utc); + continue; + } + SimpleDateFormat fmt = new SimpleDateFormat("z", locale); + try { + Date date = fmt.parse("UTC"); + // Parsed one may not exactly be UTC. Universal, UCT, etc. are equivalents. + if (!fmt.getTimeZone().getID().matches("(Etc/)?(UTC|Universal|UCT|Zulu)")) { + errors.add("timezone: " + fmt.getTimeZone().getID() + + ", locale: " + locale); + } + } catch (ParseException e) { + errors.add("parse exception: " + e + ", locale: " + locale); + } + } + } finally { + // Restore the default time zone + TimeZone.setDefault(initTz); + } + + if (!errors.isEmpty()) { + System.out.println("Got unexpected results:"); + for (String s : errors) { + System.out.println(" " + s); + } + throw new RuntimeException("Test failed."); + } else { + System.out.println("Test passed."); + } + } +} From ebceee66741dbbd6cca63ea276859d0c58949bfa Mon Sep 17 00:00:00 2001 From: Chris Hegarty Date: Thu, 3 Dec 2015 11:57:14 +0000 Subject: [PATCH 2/8] 8144480: Remove test dependencies on sun.misc.BASE64Encoder and BASE64Decoder Reviewed-by: alanb, amlu, psandoz, weijun --- .../provider/Cipher/KeyWrap/XMLEncKAT.java | 34 ++- jdk/test/com/sun/jndi/ldap/Base64Test.java | 31 +-- .../javax/net/ssl/TLSv12/ShortRSAKeyGCM.java | 4 +- jdk/test/sun/security/util/Oid/S11N.java | 207 +++++++++++------- .../x509/X509CertImpl/V3Certificate.java | 5 +- 5 files changed, 147 insertions(+), 134 deletions(-) diff --git a/jdk/test/com/sun/crypto/provider/Cipher/KeyWrap/XMLEncKAT.java b/jdk/test/com/sun/crypto/provider/Cipher/KeyWrap/XMLEncKAT.java index 93f9991ee1e..90cfacf36fd 100644 --- a/jdk/test/com/sun/crypto/provider/Cipher/KeyWrap/XMLEncKAT.java +++ b/jdk/test/com/sun/crypto/provider/Cipher/KeyWrap/XMLEncKAT.java @@ -26,16 +26,14 @@ * @bug 5008159 5008156 * @summary Verify that the two key wrap ciphers, i.e. "DESedeWrap" * and "AESWrap", work as expected. - * @modules java.base/sun.misc * @run main XMLEncKAT * @author Valerie Peng */ +import java.util.Base64; import java.security.Key; import java.security.AlgorithmParameters; import javax.crypto.*; import javax.crypto.spec.*; -import sun.misc.BASE64Decoder; -import sun.misc.BASE64Encoder; import java.io.UnsupportedEncodingException; import java.io.IOException; @@ -50,8 +48,8 @@ public class XMLEncKAT { private static byte[] aes192Key_2; private static byte[] aes256Key_2; - private static BASE64Decoder base64D = new BASE64Decoder(); - private static BASE64Encoder base64E = new BASE64Encoder(); + private static Base64.Decoder base64D = Base64.getDecoder(); + private static Base64.Encoder base64E = Base64.getEncoder(); static { try { @@ -62,18 +60,16 @@ public class XMLEncKAT { } catch (UnsupportedEncodingException uee) { // should never happen } - try { - desEdeKey_2 = base64D.decodeBuffer - ("yI+J1f3puYAERjIcT6vfg6RitmKX8nD0"); - aes128Key_2 = base64D.decodeBuffer - ("01+yuQ2huPS1+Qv0LH+zaQ=="); - aes192Key_2 = base64D.decodeBuffer - ("IlfuS40LvStVU0Mj8ePrrGHVhAb48y++"); - aes256Key_2 = base64D.decodeBuffer - ("ZhZ4v3RlwTlCEOpIrHfLKVyJOBDtEJOOQDat/4xR1bA="); - } catch (IOException ioe) { - // should never happen - } + + desEdeKey_2 = base64D.decode + ("yI+J1f3puYAERjIcT6vfg6RitmKX8nD0"); + aes128Key_2 = base64D.decode + ("01+yuQ2huPS1+Qv0LH+zaQ=="); + aes192Key_2 = base64D.decode + ("IlfuS40LvStVU0Mj8ePrrGHVhAb48y++"); + aes256Key_2 = base64D.decode + ("ZhZ4v3RlwTlCEOpIrHfLKVyJOBDtEJOOQDat/4xR1bA="); + } private static String[] desEdeWrappedKey_1 = { "ZyJbVsjRM4MEsswwwHz57aUz1eMqZHuEIoEPGS47CcmLvhuCtlzWZ9S/WcVJZIpz", @@ -123,7 +119,7 @@ public class XMLEncKAT { new IvParameterSpec[base64Wrapped.length]; // first test UNWRAP with known values for (int i = 0; i < base64Wrapped.length; i++) { - byte[] wrappedKey = base64D.decodeBuffer(base64Wrapped[i]); + byte[] wrappedKey = base64D.decode(base64Wrapped[i]); key[i] = c.unwrap(wrappedKey, "AES", Cipher.SECRET_KEY); if (c.getIV() != null) { params[i] = new IvParameterSpec(c.getIV()); @@ -133,7 +129,7 @@ public class XMLEncKAT { for (int i = 0; i < key.length; i++) { c.init(Cipher.WRAP_MODE, cKey, params[i]); byte[] wrapped2 = c.wrap(key[i]); - String out = base64E.encode(wrapped2); + String out = base64E.encodeToString(wrapped2); if (!out.equalsIgnoreCase(base64Wrapped[i])) { throw new Exception("Wrap failed; got " + out + ", expect " + base64Wrapped[i]); diff --git a/jdk/test/com/sun/jndi/ldap/Base64Test.java b/jdk/test/com/sun/jndi/ldap/Base64Test.java index 24f46afeb8d..884fae87c0c 100644 --- a/jdk/test/com/sun/jndi/ldap/Base64Test.java +++ b/jdk/test/com/sun/jndi/ldap/Base64Test.java @@ -25,7 +25,6 @@ * @test * @bug 8035807 * @summary Confirm that old and new Base64 encodings are compatible. - * @modules java.base/sun.misc */ import java.io.*; @@ -33,8 +32,6 @@ import java.util.*; import javax.naming.*; import javax.naming.directory.*; -import sun.misc.BASE64Decoder; - /* * RFC 2713 specifies an encoding for Java objects stored in an LDAP directory. * Section 3.6 specifies how a binary-valued JNDI RefAddr object is encoded @@ -48,12 +45,10 @@ import sun.misc.BASE64Decoder; * as the line separator. It is a compatible change. * * This test demonstrates that there is no compatability problem when - * encoding and decoding using either Base64 coder: + * decoding using the new Base64 coder: * - * encode with s.m.BASE64Encoder, decode with s.m.BASE64Decoder => OK - * encode with s.m.BASE64Encoder, decode with j.u.Base64.Decoder => OK - * encode with j.u.Base64.Encoder, decode with s.m.BASE64Decoder => OK - * encode with j.u.Base64.Encoder, decode with j.u.Base64.Decoder => OK + * encoded bytes captured from s.m.BASE64Encoder, decode with j.u.Base64.Decoder => OK + * encoded bytes captured from j.u.Base64.Encoder, decode with j.u.Base64.Decoder => OK * * * NOTE: The two Base64 encodings used in this test were captured from @@ -148,25 +143,9 @@ public class Base64Test { System.out.println("\nOriginal RefAddr object:\n" + BINARY_REF_ADDR); System.out.println("Old Base64 encoded serialized RefAddr object:\n" + - OLD_ENCODING); - System.out.println("Decode using old Base64 decoder..."); - deserialize(new BASE64Decoder().decodeBuffer(OLD_ENCODING)); - - System.out.println("----"); - - System.out.println("\nOriginal RefAddr object:\n" + BINARY_REF_ADDR); - System.out.println("Old Base64 encoded serialized RefAddr object:\n" + - OLD_ENCODING); + OLD_ENCODING + "\n"); System.out.println("Decode using new Base64 decoder..."); - deserialize(new BASE64Decoder().decodeBuffer(OLD_ENCODING)); - - System.out.println("----"); - - System.out.println("\nOriginal RefAddr object:\n" + BINARY_REF_ADDR); - System.out.println("New Base64 encoded serialized RefAddr object:\n" + - NEW_ENCODING + "\n"); - System.out.println("Decode using old Base64 decoder..."); - deserialize(new BASE64Decoder().decodeBuffer(OLD_ENCODING)); + deserialize(Base64.getMimeDecoder().decode(OLD_ENCODING)); System.out.println("----"); diff --git a/jdk/test/javax/net/ssl/TLSv12/ShortRSAKeyGCM.java b/jdk/test/javax/net/ssl/TLSv12/ShortRSAKeyGCM.java index 6c02652f7d9..fe4f91460d6 100644 --- a/jdk/test/javax/net/ssl/TLSv12/ShortRSAKeyGCM.java +++ b/jdk/test/javax/net/ssl/TLSv12/ShortRSAKeyGCM.java @@ -32,7 +32,6 @@ * @test * @bug 7030966 * @summary Support AEAD CipherSuites - * @modules java.base/sun.misc * @run main/othervm ShortRSAKeyGCM PKIX TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 * @run main/othervm ShortRSAKeyGCM PKIX TLS_RSA_WITH_AES_128_GCM_SHA256 * @run main/othervm ShortRSAKeyGCM PKIX TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 @@ -69,7 +68,6 @@ import java.security.cert.Certificate; import java.security.cert.CertificateFactory; import java.security.spec.*; import java.security.interfaces.*; -import sun.misc.BASE64Decoder; public class ShortRSAKeyGCM { @@ -252,7 +250,7 @@ public class ShortRSAKeyGCM { if (keyCertStr != null) { // generate the private key. PKCS8EncodedKeySpec priKeySpec = new PKCS8EncodedKeySpec( - new BASE64Decoder().decodeBuffer(keySpecStr)); + Base64.getMimeDecoder().decode(keySpecStr)); KeyFactory kf = KeyFactory.getInstance("RSA"); RSAPrivateKey priKey = (RSAPrivateKey)kf.generatePrivate(priKeySpec); diff --git a/jdk/test/sun/security/util/Oid/S11N.java b/jdk/test/sun/security/util/Oid/S11N.java index 4b7afe58a3b..b522885d89e 100644 --- a/jdk/test/sun/security/util/Oid/S11N.java +++ b/jdk/test/sun/security/util/Oid/S11N.java @@ -24,8 +24,7 @@ /* * @test * @bug 4811968 6908628 8006564 8130696 - * @modules java.base/sun.misc - * java.base/sun.security.util + * @modules java.base/sun.security.util * @run main S11N check * @summary Serialization compatibility with old versions (and fixes) */ @@ -36,7 +35,6 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.HashMap; import java.util.Map; -import sun.misc.BASE64Encoder; import sun.security.util.ObjectIdentifier; public class S11N { @@ -56,14 +54,6 @@ public class S11N { "1.2.8888888888888888.33333333333333333.44444444444444", }; - // Do not use j.u.Base64, the test needs to run in jdk6 - static BASE64Encoder encoder = new BASE64Encoder() { - @Override - protected int bytesPerLine() { - return 48; - } - }; - public static void main(String[] args) throws Exception { if (args[0].equals("check")) { String jv = System.getProperty("java.version"); @@ -117,12 +107,12 @@ public class S11N { // Gets the serialized form for jdk6 private static byte[] out6(String oid) throws Exception { - return new sun.misc.BASE64Decoder().decodeBuffer(dump6.get(oid)); + return decode(dump6.get(oid)); } // Gets the serialized form for jdk7 private static byte[] out7(String oid) throws Exception { - return new sun.misc.BASE64Decoder().decodeBuffer(dump7.get(oid)); + return decode(dump7.get(oid)); } // Gets the serialized form for this java @@ -144,11 +134,15 @@ public class S11N { // dump serialized form to java code style text private static void dump(String title, String[] oids) throws Exception { for (String oid: oids) { - String[] base64 = encoder.encodeBuffer(out(oid)).split("\n"); + String hex = encode(out(oid)); System.out.println(" " + title + ".put(\"" + oid + "\","); - for (int i = 0; i hex.length()) { + end = hex.length(); + } + System.out.print(" \"" + hex.substring(i, end) + "\""); + if (end == hex.length()) { System.out.println(");"); } else { System.out.println(" +"); @@ -157,6 +151,22 @@ public class S11N { } } + private static String encode(byte[] bytes) { + StringBuilder sb = new StringBuilder(bytes.length * 2); + for (byte b: bytes) { + sb.append(String.format("%02x", b & 0xff)); + } + return sb.toString(); + } + + private static byte[] decode(String var) { + byte[] data = new byte[var.length()/2]; + for (int i=0; i dump7 = new HashMap(); private static Map dump6 = new HashMap(); @@ -164,88 +174,119 @@ public class S11N { static { ////////////// PASTE BEGIN ////////////// dump7.put("0.0", - "rO0ABXNyACJzdW4uc2VjdXJpdHkudXRpbC5PYmplY3RJZGVudGlmaWVyeLIO7GQX" + - "fy4DAANJAAxjb21wb25lbnRMZW5MAApjb21wb25lbnRzdAASTGphdmEvbGFuZy9P" + - "YmplY3Q7WwAIZW5jb2Rpbmd0AAJbQnhwAAAAAnVyAAJbSU26YCZ26rKlAgAAeHAA" + - "AAACAAAAAAAAAAB1cgACW0Ks8xf4BghU4AIAAHhwAAAAAQB4"); + "aced00057372002273756e2e73656375726974792e7574696c2e4f626a656374" + + "4964656e74696669657278b20eec64177f2e03000349000c636f6d706f6e656e" + + "744c656e4c000a636f6d706f6e656e74737400124c6a6176612f6c616e672f4f" + + "626a6563743b5b0008656e636f64696e677400025b4278700000000275720002" + + "5b494dba602676eab2a50200007870000000020000000000000000757200025b" + + "42acf317f8060854e00200007870000000010078"); dump7.put("1.1", - "rO0ABXNyACJzdW4uc2VjdXJpdHkudXRpbC5PYmplY3RJZGVudGlmaWVyeLIO7GQX" + - "fy4DAANJAAxjb21wb25lbnRMZW5MAApjb21wb25lbnRzdAASTGphdmEvbGFuZy9P" + - "YmplY3Q7WwAIZW5jb2Rpbmd0AAJbQnhwAAAAAnVyAAJbSU26YCZ26rKlAgAAeHAA" + - "AAACAAAAAQAAAAF1cgACW0Ks8xf4BghU4AIAAHhwAAAAASl4"); + "aced00057372002273756e2e73656375726974792e7574696c2e4f626a656374" + + "4964656e74696669657278b20eec64177f2e03000349000c636f6d706f6e656e" + + "744c656e4c000a636f6d706f6e656e74737400124c6a6176612f6c616e672f4f" + + "626a6563743b5b0008656e636f64696e677400025b4278700000000275720002" + + "5b494dba602676eab2a50200007870000000020000000100000001757200025b" + + "42acf317f8060854e00200007870000000012978"); dump7.put("2.2", - "rO0ABXNyACJzdW4uc2VjdXJpdHkudXRpbC5PYmplY3RJZGVudGlmaWVyeLIO7GQX" + - "fy4DAANJAAxjb21wb25lbnRMZW5MAApjb21wb25lbnRzdAASTGphdmEvbGFuZy9P" + - "YmplY3Q7WwAIZW5jb2Rpbmd0AAJbQnhwAAAAAnVyAAJbSU26YCZ26rKlAgAAeHAA" + - "AAACAAAAAgAAAAJ1cgACW0Ks8xf4BghU4AIAAHhwAAAAAVJ4"); + "aced00057372002273756e2e73656375726974792e7574696c2e4f626a656374" + + "4964656e74696669657278b20eec64177f2e03000349000c636f6d706f6e656e" + + "744c656e4c000a636f6d706f6e656e74737400124c6a6176612f6c616e672f4f" + + "626a6563743b5b0008656e636f64696e677400025b4278700000000275720002" + + "5b494dba602676eab2a50200007870000000020000000200000002757200025b" + + "42acf317f8060854e00200007870000000015278"); dump7.put("1.2.3456", - "rO0ABXNyACJzdW4uc2VjdXJpdHkudXRpbC5PYmplY3RJZGVudGlmaWVyeLIO7GQX" + - "fy4DAANJAAxjb21wb25lbnRMZW5MAApjb21wb25lbnRzdAASTGphdmEvbGFuZy9P" + - "YmplY3Q7WwAIZW5jb2Rpbmd0AAJbQnhwAAAAA3VyAAJbSU26YCZ26rKlAgAAeHAA" + - "AAADAAAAAQAAAAIAAA2AdXIAAltCrPMX+AYIVOACAAB4cAAAAAMqmwB4"); + "aced00057372002273756e2e73656375726974792e7574696c2e4f626a656374" + + "4964656e74696669657278b20eec64177f2e03000349000c636f6d706f6e656e" + + "744c656e4c000a636f6d706f6e656e74737400124c6a6176612f6c616e672f4f" + + "626a6563743b5b0008656e636f64696e677400025b4278700000000375720002" + + "5b494dba602676eab2a5020000787000000003000000010000000200000d8075" + + "7200025b42acf317f8060854e00200007870000000032a9b0078"); dump7.put("1.2.2147483647.4", - "rO0ABXNyACJzdW4uc2VjdXJpdHkudXRpbC5PYmplY3RJZGVudGlmaWVyeLIO7GQX" + - "fy4DAANJAAxjb21wb25lbnRMZW5MAApjb21wb25lbnRzdAASTGphdmEvbGFuZy9P" + - "YmplY3Q7WwAIZW5jb2Rpbmd0AAJbQnhwAAAABHVyAAJbSU26YCZ26rKlAgAAeHAA" + - "AAAEAAAAAQAAAAJ/////AAAABHVyAAJbQqzzF/gGCFTgAgAAeHAAAAAHKof///9/" + - "BHg="); + "aced00057372002273756e2e73656375726974792e7574696c2e4f626a656374" + + "4964656e74696669657278b20eec64177f2e03000349000c636f6d706f6e656e" + + "744c656e4c000a636f6d706f6e656e74737400124c6a6176612f6c616e672f4f" + + "626a6563743b5b0008656e636f64696e677400025b4278700000000475720002" + + "5b494dba602676eab2a502000078700000000400000001000000027fffffff00" + + "000004757200025b42acf317f8060854e00200007870000000072a87ffffff7f" + + "0478"); dump7.put("1.2.268435456.4", - "rO0ABXNyACJzdW4uc2VjdXJpdHkudXRpbC5PYmplY3RJZGVudGlmaWVyeLIO7GQX" + - "fy4DAANJAAxjb21wb25lbnRMZW5MAApjb21wb25lbnRzdAASTGphdmEvbGFuZy9P" + - "YmplY3Q7WwAIZW5jb2Rpbmd0AAJbQnhwAAAABHVyAAJbSU26YCZ26rKlAgAAeHAA" + - "AAAEAAAAAQAAAAIQAAAAAAAABHVyAAJbQqzzF/gGCFTgAgAAeHAAAAAHKoGAgIAA" + - "BHg="); + "aced00057372002273756e2e73656375726974792e7574696c2e4f626a656374" + + "4964656e74696669657278b20eec64177f2e03000349000c636f6d706f6e656e" + + "744c656e4c000a636f6d706f6e656e74737400124c6a6176612f6c616e672f4f" + + "626a6563743b5b0008656e636f64696e677400025b4278700000000475720002" + + "5b494dba602676eab2a502000078700000000400000001000000021000000000" + + "000004757200025b42acf317f8060854e00200007870000000072a8180808000" + + "0478"); dump7.put("2.16.764.1.3101555394.1.0.100.2.1", - "rO0ABXNyACJzdW4uc2VjdXJpdHkudXRpbC5PYmplY3RJZGVudGlmaWVyeLIO7GQX" + - "fy4DAANJAAxjb21wb25lbnRMZW5MAApjb21wb25lbnRzdAASTGphdmEvbGFuZy9P" + - "YmplY3Q7WwAIZW5jb2Rpbmd0AAJbQnhw/////3NyAD5zdW4uc2VjdXJpdHkudXRp" + - "bC5PYmplY3RJZGVudGlmaWVyJEh1Z2VPaWROb3RTdXBwb3J0ZWRCeU9sZEpESwAA" + - "AAAAAAABAgAAeHB1cgACW0Ks8xf4BghU4AIAAHhwAAAADmCFfAGLxvf1QgEAZAIB" + - "eA=="); + "aced00057372002273756e2e73656375726974792e7574696c2e4f626a656374" + + "4964656e74696669657278b20eec64177f2e03000349000c636f6d706f6e656e" + + "744c656e4c000a636f6d706f6e656e74737400124c6a6176612f6c616e672f4f" + + "626a6563743b5b0008656e636f64696e677400025b427870ffffffff7372003e" + + "73756e2e73656375726974792e7574696c2e4f626a6563744964656e74696669" + + "657224487567654f69644e6f74537570706f7274656442794f6c644a444b0000" + + "0000000000010200007870757200025b42acf317f8060854e002000078700000" + + "000e60857c018bc6f7f542010064020178"); dump7.put("1.2.2147483648.4", - "rO0ABXNyACJzdW4uc2VjdXJpdHkudXRpbC5PYmplY3RJZGVudGlmaWVyeLIO7GQX" + - "fy4DAANJAAxjb21wb25lbnRMZW5MAApjb21wb25lbnRzdAASTGphdmEvbGFuZy9P" + - "YmplY3Q7WwAIZW5jb2Rpbmd0AAJbQnhw/////3NyAD5zdW4uc2VjdXJpdHkudXRp" + - "bC5PYmplY3RJZGVudGlmaWVyJEh1Z2VPaWROb3RTdXBwb3J0ZWRCeU9sZEpESwAA" + - "AAAAAAABAgAAeHB1cgACW0Ks8xf4BghU4AIAAHhwAAAAByqIgICAAAR4"); + "aced00057372002273756e2e73656375726974792e7574696c2e4f626a656374" + + "4964656e74696669657278b20eec64177f2e03000349000c636f6d706f6e656e" + + "744c656e4c000a636f6d706f6e656e74737400124c6a6176612f6c616e672f4f" + + "626a6563743b5b0008656e636f64696e677400025b427870ffffffff7372003e" + + "73756e2e73656375726974792e7574696c2e4f626a6563744964656e74696669" + + "657224487567654f69644e6f74537570706f7274656442794f6c644a444b0000" + + "0000000000010200007870757200025b42acf317f8060854e002000078700000" + + "00072a88808080000478"); dump7.put("2.3.4444444444444444444444", - "rO0ABXNyACJzdW4uc2VjdXJpdHkudXRpbC5PYmplY3RJZGVudGlmaWVyeLIO7GQX" + - "fy4DAANJAAxjb21wb25lbnRMZW5MAApjb21wb25lbnRzdAASTGphdmEvbGFuZy9P" + - "YmplY3Q7WwAIZW5jb2Rpbmd0AAJbQnhw/////3NyAD5zdW4uc2VjdXJpdHkudXRp" + - "bC5PYmplY3RJZGVudGlmaWVyJEh1Z2VPaWROb3RTdXBwb3J0ZWRCeU9sZEpESwAA" + - "AAAAAAABAgAAeHB1cgACW0Ks8xf4BghU4AIAAHhwAAAADFOD4e+HpNG968eOHHg="); + "aced00057372002273756e2e73656375726974792e7574696c2e4f626a656374" + + "4964656e74696669657278b20eec64177f2e03000349000c636f6d706f6e656e" + + "744c656e4c000a636f6d706f6e656e74737400124c6a6176612f6c616e672f4f" + + "626a6563743b5b0008656e636f64696e677400025b427870ffffffff7372003e" + + "73756e2e73656375726974792e7574696c2e4f626a6563744964656e74696669" + + "657224487567654f69644e6f74537570706f7274656442794f6c644a444b0000" + + "0000000000010200007870757200025b42acf317f8060854e002000078700000" + + "000c5383e1ef87a4d1bdebc78e1c78"); dump7.put("1.2.8888888888888888.33333333333333333.44444444444444", - "rO0ABXNyACJzdW4uc2VjdXJpdHkudXRpbC5PYmplY3RJZGVudGlmaWVyeLIO7GQX" + - "fy4DAANJAAxjb21wb25lbnRMZW5MAApjb21wb25lbnRzdAASTGphdmEvbGFuZy9P" + - "YmplY3Q7WwAIZW5jb2Rpbmd0AAJbQnhw/////3NyAD5zdW4uc2VjdXJpdHkudXRp" + - "bC5PYmplY3RJZGVudGlmaWVyJEh1Z2VPaWROb3RTdXBwb3J0ZWRCeU9sZEpESwAA" + - "AAAAAAABAgAAeHB1cgACW0Ks8xf4BghU4AIAAHhwAAAAGCqP5Yzbxa6cOLubj9ek" + - "japVio3AusuOHHg="); + "aced00057372002273756e2e73656375726974792e7574696c2e4f626a656374" + + "4964656e74696669657278b20eec64177f2e03000349000c636f6d706f6e656e" + + "744c656e4c000a636f6d706f6e656e74737400124c6a6176612f6c616e672f4f" + + "626a6563743b5b0008656e636f64696e677400025b427870ffffffff7372003e" + + "73756e2e73656375726974792e7574696c2e4f626a6563744964656e74696669" + + "657224487567654f69644e6f74537570706f7274656442794f6c644a444b0000" + + "0000000000010200007870757200025b42acf317f8060854e002000078700000" + + "00182a8fe58cdbc5ae9c38bb9b8fd7a48daa558a8dc0bacb8e1c78"); dump6.put("0.0", - "rO0ABXNyACJzdW4uc2VjdXJpdHkudXRpbC5PYmplY3RJZGVudGlmaWVyeLIO7GQX" + - "fy4CAAJJAAxjb21wb25lbnRMZW5bAApjb21wb25lbnRzdAACW0l4cAAAAAJ1cgAC" + - "W0lNumAmduqypQIAAHhwAAAAAgAAAAAAAAAA"); + "aced00057372002273756e2e73656375726974792e7574696c2e4f626a656374" + + "4964656e74696669657278b20eec64177f2e02000249000c636f6d706f6e656e" + + "744c656e5b000a636f6d706f6e656e74737400025b4978700000000275720002" + + "5b494dba602676eab2a50200007870000000020000000000000000"); dump6.put("1.1", - "rO0ABXNyACJzdW4uc2VjdXJpdHkudXRpbC5PYmplY3RJZGVudGlmaWVyeLIO7GQX" + - "fy4CAAJJAAxjb21wb25lbnRMZW5bAApjb21wb25lbnRzdAACW0l4cAAAAAJ1cgAC" + - "W0lNumAmduqypQIAAHhwAAAAAgAAAAEAAAAB"); + "aced00057372002273756e2e73656375726974792e7574696c2e4f626a656374" + + "4964656e74696669657278b20eec64177f2e02000249000c636f6d706f6e656e" + + "744c656e5b000a636f6d706f6e656e74737400025b4978700000000275720002" + + "5b494dba602676eab2a50200007870000000020000000100000001"); dump6.put("2.2", - "rO0ABXNyACJzdW4uc2VjdXJpdHkudXRpbC5PYmplY3RJZGVudGlmaWVyeLIO7GQX" + - "fy4CAAJJAAxjb21wb25lbnRMZW5bAApjb21wb25lbnRzdAACW0l4cAAAAAJ1cgAC" + - "W0lNumAmduqypQIAAHhwAAAAAgAAAAIAAAAC"); + "aced00057372002273756e2e73656375726974792e7574696c2e4f626a656374" + + "4964656e74696669657278b20eec64177f2e02000249000c636f6d706f6e656e" + + "744c656e5b000a636f6d706f6e656e74737400025b4978700000000275720002" + + "5b494dba602676eab2a50200007870000000020000000200000002"); dump6.put("1.2.3456", - "rO0ABXNyACJzdW4uc2VjdXJpdHkudXRpbC5PYmplY3RJZGVudGlmaWVyeLIO7GQX" + - "fy4CAAJJAAxjb21wb25lbnRMZW5bAApjb21wb25lbnRzdAACW0l4cAAAAAN1cgAC" + - "W0lNumAmduqypQIAAHhwAAAAAwAAAAEAAAACAAANgA=="); + "aced00057372002273756e2e73656375726974792e7574696c2e4f626a656374" + + "4964656e74696669657278b20eec64177f2e02000249000c636f6d706f6e656e" + + "744c656e5b000a636f6d706f6e656e74737400025b4978700000000375720002" + + "5b494dba602676eab2a5020000787000000003000000010000000200000d80"); dump6.put("1.2.2147483647.4", - "rO0ABXNyACJzdW4uc2VjdXJpdHkudXRpbC5PYmplY3RJZGVudGlmaWVyeLIO7GQX" + - "fy4CAAJJAAxjb21wb25lbnRMZW5bAApjb21wb25lbnRzdAACW0l4cAAAAAR1cgAC" + - "W0lNumAmduqypQIAAHhwAAAABAAAAAEAAAACf////wAAAAQ="); + "aced00057372002273756e2e73656375726974792e7574696c2e4f626a656374" + + "4964656e74696669657278b20eec64177f2e02000249000c636f6d706f6e656e" + + "744c656e5b000a636f6d706f6e656e74737400025b4978700000000475720002" + + "5b494dba602676eab2a502000078700000000400000001000000027fffffff00" + + "000004"); dump6.put("1.2.268435456.4", - "rO0ABXNyACJzdW4uc2VjdXJpdHkudXRpbC5PYmplY3RJZGVudGlmaWVyeLIO7GQX" + - "fy4CAAJJAAxjb21wb25lbnRMZW5bAApjb21wb25lbnRzdAACW0l4cAAAAAR1cgAC" + - "W0lNumAmduqypQIAAHhwAAAABAAAAAEAAAACEAAAAAAAAAQ="); + "aced00057372002273756e2e73656375726974792e7574696c2e4f626a656374" + + "4964656e74696669657278b20eec64177f2e02000249000c636f6d706f6e656e" + + "744c656e5b000a636f6d706f6e656e74737400025b4978700000000475720002" + + "5b494dba602676eab2a502000078700000000400000001000000021000000000" + + "000004"); + ////////////// PASTE END ////////////// } } diff --git a/jdk/test/sun/security/x509/X509CertImpl/V3Certificate.java b/jdk/test/sun/security/x509/X509CertImpl/V3Certificate.java index 6d169ed1ee5..479cbc10621 100644 --- a/jdk/test/sun/security/x509/X509CertImpl/V3Certificate.java +++ b/jdk/test/sun/security/x509/X509CertImpl/V3Certificate.java @@ -42,10 +42,10 @@ import java.security.SignatureException; import java.security.cert.CertificateException; import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; +import java.util.Base64; import java.util.Calendar; import java.util.Date; import java.util.TimeZone; -import sun.misc.BASE64Encoder; import sun.security.util.BitArray; import sun.security.util.ObjectIdentifier; import sun.security.x509.*; @@ -55,7 +55,6 @@ import sun.security.x509.*; * @bug 8049237 * @modules java.base/sun.security.x509 * java.base/sun.security.util - * java.base/sun.misc * @summary This test generates V3 certificate with all the supported * extensions. Writes back the generated certificate in to a file and checks for * equality with the original certificate. @@ -224,7 +223,7 @@ public class V3Certificate { // Certificate boundaries/ pw.println("-----BEGIN CERTIFICATE-----"); pw.flush(); - new BASE64Encoder().encodeBuffer(crt.getEncoded(), fos_b64); + fos_b64.write(Base64.getMimeEncoder().encode(crt.getEncoded())); fos_b64.flush(); pw.println("-----END CERTIFICATE-----"); } From d3f047f9cf830238ababa1e47a0cbb006f223a7f Mon Sep 17 00:00:00 2001 From: Hamlin Li Date: Wed, 2 Dec 2015 19:27:16 -0800 Subject: [PATCH 3/8] 8144214: Some log messages will be discarded when VM is bootstrapping Use logp instead of log. Reviewed-by: dfuchs --- .../share/classes/jdk/internal/logger/BootstrapLogger.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jdk/src/java.base/share/classes/jdk/internal/logger/BootstrapLogger.java b/jdk/src/java.base/share/classes/jdk/internal/logger/BootstrapLogger.java index 6338f871644..813c4787e86 100644 --- a/jdk/src/java.base/share/classes/jdk/internal/logger/BootstrapLogger.java +++ b/jdk/src/java.base/share/classes/jdk/internal/logger/BootstrapLogger.java @@ -389,9 +389,9 @@ public final class BootstrapLogger implements Logger, PlatformLogger.Bridge, } else { if (msgSupplier != null) { if (thrown != null) { - logger.log(platformLevel, sourceClass, sourceMethod, thrown, msgSupplier); + logger.logp(platformLevel, sourceClass, sourceMethod, thrown, msgSupplier); } else { - logger.log(platformLevel,sourceClass, sourceMethod, msgSupplier); + logger.logp(platformLevel, sourceClass, sourceMethod, msgSupplier); } } else { // BootstrapLoggers are never localized so we can safely From b3fa048050e860af4d0486bf2a206da9d4b05149 Mon Sep 17 00:00:00 2001 From: Hamlin Li Date: Wed, 2 Dec 2015 19:46:46 -0800 Subject: [PATCH 4/8] 8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214 Cover the logXX and LogEvent.valueOf APIs of BootstrapLogger and logXX APIs of SimpleConsoleLogger Reviewed-by: dfuchs --- .../BootstrapLoggerAPIsTest.java | 286 ++++++++++++++++++ .../BootstrapLogger/BootstrapLoggerTest.java | 63 +--- .../BootstrapLogger/BootstrapLoggerUtils.java | 61 ++++ .../internal/BootstrapLogger/LogStream.java | 58 ++++ 4 files changed, 412 insertions(+), 56 deletions(-) create mode 100644 jdk/test/java/lang/System/LoggerFinder/internal/BootstrapLogger/BootstrapLoggerAPIsTest.java create mode 100644 jdk/test/java/lang/System/LoggerFinder/internal/BootstrapLogger/BootstrapLoggerUtils.java create mode 100644 jdk/test/java/lang/System/LoggerFinder/internal/BootstrapLogger/LogStream.java diff --git a/jdk/test/java/lang/System/LoggerFinder/internal/BootstrapLogger/BootstrapLoggerAPIsTest.java b/jdk/test/java/lang/System/LoggerFinder/internal/BootstrapLogger/BootstrapLoggerAPIsTest.java new file mode 100644 index 00000000000..4cacb966906 --- /dev/null +++ b/jdk/test/java/lang/System/LoggerFinder/internal/BootstrapLogger/BootstrapLoggerAPIsTest.java @@ -0,0 +1,286 @@ +/* + * Copyright (c) 2015, 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.PrintStream; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; +import java.util.ArrayList; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.Enumeration; +import java.util.List; +import java.util.ResourceBundle; +import java.util.Set; + +import jdk.internal.logger.BootstrapLogger; +import jdk.internal.logger.LazyLoggers; + +/* + * @test + * @bug 8144460 8144214 + * @summary Cover the logXX and LogEvent.valueOf APIs of BootstrapLogger + * and logXX APIs of SimpleConsoleLogger. + * @modules java.base/jdk.internal.logger + * @build BootstrapLoggerUtils LogStream + * @run main/othervm BootstrapLoggerAPIsTest + */ + +public class BootstrapLoggerAPIsTest { + + private static final LogStream ERR = new LogStream(); + + public static void main(String[] args) throws Exception { + + final ContentManager MGR = new ContentManager(); + + // private reflection hook that allows us to simulate a non booted VM + final AtomicBoolean VM_BOOTED = new AtomicBoolean(false); + + BootstrapLoggerUtils.setBootedHook(() -> VM_BOOTED.get()); + + // We replace System.err to check the messages that have been logged + // by the JUL ConsoleHandler and default SimpleConsoleLogger + // implementaion + System.setErr(new PrintStream(ERR)); + + VM_BOOTED.getAndSet(false); + if (BootstrapLogger.isBooted()) { + throw new RuntimeException("VM should not be booted!"); + } + + final Logger LOGGER = + LazyLoggers.getLogger("foo.bar", Thread.class); + final sun.util.logging.PlatformLogger.Level PLATFORM_LEVEL = + sun.util.logging.PlatformLogger.Level.SEVERE; + final MyResources BUNDLE = new MyResources(); + + /* + * Test logXX APIs for interface java.lang.System.Logger. Log content + * before VM is booted should be retained. Log content after VM was + * booted should be flushed instantly. VM is not booted in first round + * of loop, VM is booted in second round of loop. + */ + for (int i = 0; i < 2; i++) { + boolean booted = BootstrapLogger.isBooted(); + + // make sure there is no [remaining] content in the LogStream. + MGR.failLog("xyz", "throwable #", "MyClass_#", "MyMethod_#"); + + /* + * test logXX APIs for interface java.lang.System.Logger. + */ + // void log(java.lang.System$Logger$Level,java.util.ResourceBundle, + // java.lang.String,java.lang.Throwable) + LOGGER.log(Level.ERROR, BUNDLE, "abc #0", new RuntimeException("throwable #0")); + MGR.checkLog(booted, "xyz #0", "throwable #0"); + + // void log(java.lang.System$Logger$Level,java.util.ResourceBundle, + // java.lang.String,java.lang.Object[]) + LOGGER.log(Level.ERROR, BUNDLE, "abc #1"); + MGR.checkLog(booted, "xyz #1"); + + // void log(java.lang.System$Logger$Level,java.lang.String,java.lang.Object[]) + LOGGER.log(Level.ERROR, BUNDLE, "abc {0}", "#2"); + MGR.checkLog(booted, "xyz #2"); + + // void log(java.lang.System$Logger$Level,java.lang.String,java.lang.Throwable) + LOGGER.log(Level.ERROR, "xyz #3", new RuntimeException("throwable #3")); + MGR.checkLog(booted, "xyz #3", "throwable #3"); + + // void log(java.lang.System$Logger$Level,java.util.function.Supplier) + LOGGER.log(Level.ERROR, () -> "xyz #4"); + MGR.checkLog(booted, "xyz #4"); + + // void log(java.lang.System$Logger$Level,java.lang.Object) + LOGGER.log(Level.ERROR, new MyObject("xyz #5")); + MGR.checkLog(booted, "xyz #5"); + + // void log(java.lang.System$Logger$Level,java.util.function.Supplier, + // java.lang.Throwable) + LOGGER.log(Level.ERROR, () -> "xyz #6", new RuntimeException("throwable #6")); + MGR.checkLog(booted, "xyz #6", "throwable #6"); + + + /* + * test logXX APIs for interface + * sun.util.logging.PlatformLogger.Bridge. + */ + sun.util.logging.PlatformLogger.Bridge bridge = + (sun.util.logging.PlatformLogger.Bridge) LOGGER; + + // void log(sun.util.logging.PlatformLogger$Level,java.lang.String) + bridge.log(PLATFORM_LEVEL, "xyz #7"); + MGR.checkLog(booted, "xyz #7"); + + // void log(sun.util.logging.PlatformLogger$Level,java.lang.String,java.lang.Throwable) + bridge.log(PLATFORM_LEVEL, "xyz #8", new RuntimeException("throwable #8")); + MGR.checkLog(booted, "xyz #8", "throwable #8"); + + // void log(sun.util.logging.PlatformLogger$Level,java.lang.String,java.lang.Object[]) + bridge.log(PLATFORM_LEVEL, "xyz {0}", "#9"); + MGR.checkLog(booted, "xyz #9"); + + // void log(sun.util.logging.PlatformLogger$Level,java.util.function.Supplier) + bridge.log(PLATFORM_LEVEL, () -> "xyz #10"); + MGR.checkLog(booted, "xyz #10"); + + // void log(sun.util.logging.PlatformLogger$Level, + // java.lang.Throwable,java.util.function.Supplier) + bridge.log(PLATFORM_LEVEL, new RuntimeException("throwable #11"), () -> "xyz #11"); + MGR.checkLog(booted, "xyz #11", "throwable #11"); + + // void logp(sun.util.logging.PlatformLogger$Level,java.lang.String, + // java.lang.String,java.lang.String) + bridge.logp(PLATFORM_LEVEL, "MyClass_#12", "MyMethod_#12", "xyz #12"); + MGR.checkLog(booted, "xyz #12", "MyClass_#12", "MyMethod_#12"); + + // void logp(sun.util.logging.PlatformLogger$Level,java.lang.String, + // java.lang.String,java.util.function.Supplier) + bridge.logp(PLATFORM_LEVEL, "MyClass_#13", "MyMethod_#13", () -> "xyz #13"); + MGR.checkLog(booted, "xyz #13", "MyClass_#13", "MyMethod_#13"); + + // void logp(sun.util.logging.PlatformLogger$Level,java.lang.String, + // java.lang.String,java.lang.String,java.lang.Object[]) + bridge.logp(PLATFORM_LEVEL, "MyClass_#14", "MyMethod_#14", "xyz {0}", "#14"); + MGR.checkLog(booted, "xyz #14", "MyClass_#14", "MyMethod_#14"); + + // void logp(sun.util.logging.PlatformLogger$Level,java.lang.String, + // java.lang.String,java.lang.String,java.lang.Throwable) + bridge.logp(PLATFORM_LEVEL, "MyClass_#15", "MyMethod_#15", + "xyz #15", new RuntimeException("throwable #15")); + MGR.checkLog(booted, "xyz #15", "throwable #15", "MyClass_#15", "MyMethod_#15"); + + // void logp(sun.util.logging.PlatformLogger$Level,java.lang.String, + // java.lang.String,java.lang.Throwable,java.util.function.Supplier) + bridge.logp(PLATFORM_LEVEL, "MyClass_#16", "MyMethod_#16", + new RuntimeException("throwable #16"), () -> "xyz #16"); + MGR.checkLog(booted, "xyz #16", "throwable #16", "MyClass_#16", "MyMethod_#16"); + + // void logrb(sun.util.logging.PlatformLogger$Level,java.lang.String,java.lang.String, + // java.util.ResourceBundle,java.lang.String,java.lang.Object[]) + bridge.logrb(PLATFORM_LEVEL, "MyClass_#17", "MyMethod_#17", + BUNDLE, "abc {0}", "#17"); + MGR.checkLog(booted, "xyz #17", "MyClass_#17", "MyMethod_#17"); + + // void logrb(sun.util.logging.PlatformLogger$Level,java.lang.String,java.lang.String, + // java.util.ResourceBundle,java.lang.String,java.lang.Throwable) + bridge.logrb(PLATFORM_LEVEL, "MyClass_#18", "MyMethod_#18", + BUNDLE, "abc #18", new RuntimeException("throwable #18")); + MGR.checkLog(booted, "xyz #18", "throwable #18", "MyClass_#18", "MyMethod_#18"); + + // void logrb(sun.util.logging.PlatformLogger$Level,java.util.ResourceBundle, + // java.lang.String,java.lang.Object[]) + bridge.logrb(PLATFORM_LEVEL, BUNDLE, "abc {0}", "#19"); + MGR.checkLog(booted, "xyz #19"); + + // void logrb(sun.util.logging.PlatformLogger$Level,java.util.ResourceBundle, + // java.lang.String,java.lang.Throwable) + bridge.logrb(PLATFORM_LEVEL, BUNDLE, "abc #20", + new RuntimeException("throwable #20")); + MGR.checkLog(booted, "xyz #20", "throwable #20"); + + /* + * retained log content should be flushed after VM is booted. + */ + if (!booted) { + VM_BOOTED.getAndSet(true); + // trigger the flush, make sure to call LOGGER.log(...) + // after VM_BOOTED.getAndSet(true) and before MGR.assertCachedLog() + LOGGER.log(Level.ERROR, "VM was just booted! This log should flush the cached logs."); + MGR.assertCachedLog(); + } + } + } + + private static class ContentManager { + final List cached = new ArrayList(); + String[] last; + + public void cache() { + cached.add(last); + } + + public ContentManager failLog(String... nonexistent) { + last = nonexistent; + for (String c : nonexistent) { + if (ERR.drain().contains(c)) { + throw new RuntimeException("Content \"" + nonexistent + + "\" should not exist in the log!"); + } + } + return this; + } + + public void assertLog(String... logs) { + String log = ERR.drain(); + for (String str : logs) { + if (!log.contains(str)) { + throw new RuntimeException("Content \"" + str + "\" does not exist in the log!"); + } + } + } + + public void checkLog(boolean booted, String... logs) { + if (!booted) { + failLog(logs).cache(); + } else { + assertLog(logs); + } + } + + public void assertCachedLog() { + String log = ERR.drain(); + for (String[] arr : cached) { + for (String c : arr) { + if (!log.contains(c)) { + throw new RuntimeException("Content \"" + c + "\" does not exist in the log!"); + } + } + } + } + } + + private static class MyObject { + String str; + + public MyObject(String str) { + this.str = str; + } + + public String toString() { + return str; + } + } + + private static class MyResources extends ResourceBundle { + public Object handleGetObject(String key) { + if (key.contains("abc #") || key.contains("abc {")) { + return key.replaceAll("abc ", "xyz "); + } + return null; + } + + public Enumeration getKeys() { + return null; + } + } +} diff --git a/jdk/test/java/lang/System/LoggerFinder/internal/BootstrapLogger/BootstrapLoggerTest.java b/jdk/test/java/lang/System/LoggerFinder/internal/BootstrapLogger/BootstrapLoggerTest.java index 4bbfe1e1f10..eca65eec03d 100644 --- a/jdk/test/java/lang/System/LoggerFinder/internal/BootstrapLogger/BootstrapLoggerTest.java +++ b/jdk/test/java/lang/System/LoggerFinder/internal/BootstrapLogger/BootstrapLoggerTest.java @@ -21,19 +21,14 @@ * questions. */ -import java.io.ByteArrayOutputStream; -import java.io.OutputStream; import java.io.PrintStream; -import java.lang.reflect.Array; -import java.lang.reflect.Field; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.function.BooleanSupplier; -import java.lang.System.Logger; -import java.lang.System.Logger.Level; import java.lang.ref.ReferenceQueue; import java.lang.ref.WeakReference; -import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Array; +import java.lang.reflect.Field; import java.lang.reflect.Method; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.security.AllPermission; import java.security.CodeSource; import java.security.Permission; @@ -41,6 +36,7 @@ import java.security.PermissionCollection; import java.security.Permissions; import java.security.Policy; import java.security.ProtectionDomain; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; @@ -56,25 +52,17 @@ import jdk.internal.logger.LazyLoggers; Tests the behavior of bootstrap loggers (and SimpleConsoleLoggers * too). * @modules java.base/jdk.internal.logger + * @build BootstrapLoggerUtils LogStream * @run main/othervm BootstrapLoggerTest NO_SECURITY * @run main/othervm BootstrapLoggerTest SECURE * @run main/othervm/timeout=120 BootstrapLoggerTest SECURE_AND_WAIT */ public class BootstrapLoggerTest { - static final Method awaitPending; static final Method isAlive; - static final Field isBooted; static final Field logManagerInitialized; static { try { - isBooted = BootstrapLogger.class.getDeclaredField("isBooted"); - isBooted.setAccessible(true); - // private reflection hook that allows us to test wait until all - // the tasks pending in the BootstrapExecutor are finished. - awaitPending = BootstrapLogger.class - .getDeclaredMethod("awaitPendingTasks"); - awaitPending.setAccessible(true); // private reflection hook that allows us to test whether // the BootstrapExecutor is alive. isAlive = BootstrapLogger.class @@ -90,43 +78,6 @@ public class BootstrapLoggerTest { } } - static void awaitPending() { - try { - awaitPending.invoke(null); - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { - ex.printStackTrace(LogStream.err); - } - } - - /** - * We use an instance of this class to check what the logging system has - * printed on System.err. - */ - public static class LogStream extends OutputStream { - - final static PrintStream err = System.err; - final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - - public LogStream() { - super(); - } - - @Override - public synchronized void write(int b) { - baos.write(b); - err.write(b); - } - - public String drain() { - awaitPending(); - synchronized(this) { - String txt = baos.toString(); - baos.reset(); - return txt; - } - } - } - static enum TestCase { NO_SECURITY, SECURE, SECURE_AND_WAIT } @@ -142,7 +93,7 @@ public class BootstrapLoggerTest { // private reflection hook that allows us to simulate a non booted VM final AtomicBoolean vmBooted = new AtomicBoolean(false); - isBooted.set(null,(BooleanSupplier) () -> vmBooted.get()); + BootstrapLoggerUtils.setBootedHook(() -> vmBooted.get()); // We replace System.err to check the messages that have been logged // by the JUL ConsoleHandler and default SimpleConsoleLogger diff --git a/jdk/test/java/lang/System/LoggerFinder/internal/BootstrapLogger/BootstrapLoggerUtils.java b/jdk/test/java/lang/System/LoggerFinder/internal/BootstrapLogger/BootstrapLoggerUtils.java new file mode 100644 index 00000000000..0e78b588e99 --- /dev/null +++ b/jdk/test/java/lang/System/LoggerFinder/internal/BootstrapLogger/BootstrapLoggerUtils.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2015, 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.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.function.BooleanSupplier; + +import jdk.internal.logger.BootstrapLogger; + +class BootstrapLoggerUtils { + + private static final Field IS_BOOTED; + private static final Method AWAIT_PENDING; + + static { + try { + IS_BOOTED = BootstrapLogger.class.getDeclaredField("isBooted"); + IS_BOOTED.setAccessible(true); + // private reflection hook that allows us to test wait until all + // the tasks pending in the BootstrapExecutor are finished. + AWAIT_PENDING = BootstrapLogger.class.getDeclaredMethod("awaitPendingTasks"); + AWAIT_PENDING.setAccessible(true); + } catch (Exception ex) { + throw new ExceptionInInitializerError(ex); + } + } + + static void setBootedHook(BooleanSupplier supplier) throws IllegalAccessException { + IS_BOOTED.set(null, supplier); + } + + static void awaitPending() { + try { + AWAIT_PENDING.invoke(null); + } catch (IllegalAccessException | IllegalArgumentException + | InvocationTargetException ex) { + ex.printStackTrace(); + } + } +} diff --git a/jdk/test/java/lang/System/LoggerFinder/internal/BootstrapLogger/LogStream.java b/jdk/test/java/lang/System/LoggerFinder/internal/BootstrapLogger/LogStream.java new file mode 100644 index 00000000000..d6e218a2a43 --- /dev/null +++ b/jdk/test/java/lang/System/LoggerFinder/internal/BootstrapLogger/LogStream.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2015, 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.ByteArrayOutputStream; +import java.io.OutputStream; +import java.io.PrintStream; + +import jdk.internal.logger.BootstrapLogger; + +/** + * We use an instance of this class to check what the logging system has printed + * on System.err. + */ +class LogStream extends OutputStream { + + static final PrintStream err = System.err; + + private final ByteArrayOutputStream BAOS = new ByteArrayOutputStream(); + + LogStream() { + super(); + } + + @Override + public synchronized void write(int b) { + BAOS.write(b); + err.write(b); + } + + String drain() { + BootstrapLoggerUtils.awaitPending(); + synchronized (this) { + String txt = BAOS.toString(); + BAOS.reset(); + return txt; + } + } +} From d66865cb0f9c21cf40ee2c3577e27d8a998d8939 Mon Sep 17 00:00:00 2001 From: Michael Haupt Date: Thu, 3 Dec 2015 15:34:39 +0100 Subject: [PATCH 5/8] 8072844: Use more efficient LambdaForm type representation Reviewed-by: sundar, redestad --- .../lang/invoke/InvokerBytecodeGenerator.java | 8 +-- .../classes/java/lang/invoke/LambdaForm.java | 67 +++++++++---------- 2 files changed, 34 insertions(+), 41 deletions(-) diff --git a/jdk/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java b/jdk/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java index 35100f1e5a2..83d66d52299 100644 --- a/jdk/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java +++ b/jdk/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java @@ -1276,10 +1276,10 @@ class InvokerBytecodeGenerator { /** * Generate bytecode for a LambdaForm.vmentry which calls interpretWithArguments. */ - static MemberName generateLambdaFormInterpreterEntryPoint(String sig) { - assert(isValidSignature(sig)); - String name = "interpret_"+signatureReturn(sig).basicTypeChar(); - MethodType type = signatureType(sig); // sig includes leading argument + static MemberName generateLambdaFormInterpreterEntryPoint(MethodType mt) { + assert(isValidSignature(basicTypeSignature(mt))); + String name = "interpret_"+basicTypeChar(mt.returnType()); + MethodType type = mt; // includes leading argument type = type.changeParameterType(0, MethodHandle.class); InvokerBytecodeGenerator g = new InvokerBytecodeGenerator("LFI", name, type); return g.loadMethod(g.generateLambdaFormInterpreterEntryPointBytes()); diff --git a/jdk/src/java.base/share/classes/java/lang/invoke/LambdaForm.java b/jdk/src/java.base/share/classes/java/lang/invoke/LambdaForm.java index a95f7b11856..438b4256c09 100644 --- a/jdk/src/java.base/share/classes/java/lang/invoke/LambdaForm.java +++ b/jdk/src/java.base/share/classes/java/lang/invoke/LambdaForm.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2015, 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 @@ -288,32 +288,28 @@ class LambdaForm { return names; } - private LambdaForm(String sig) { + private LambdaForm(MethodType mt) { // Make a blank lambda form, which returns a constant zero or null. // It is used as a template for managing the invocation of similar forms that are non-empty. // Called only from getPreparedForm. - assert(isValidSignature(sig)); - this.arity = signatureArity(sig); - this.result = (signatureReturn(sig) == V_TYPE ? -1 : arity); - this.names = buildEmptyNames(arity, sig); + this.arity = mt.parameterCount(); + this.result = (mt.returnType() == void.class || mt.returnType() == Void.class) ? -1 : arity; + this.names = buildEmptyNames(arity, mt, result == -1); this.debugName = "LF.zero"; this.forceInline = true; this.customized = null; assert(nameRefsAreLegal()); assert(isEmpty()); + String sig = null; + assert(isValidSignature(sig = basicTypeSignature())); assert(sig.equals(basicTypeSignature())) : sig + " != " + basicTypeSignature(); } - private static Name[] buildEmptyNames(int arity, String basicTypeSignature) { - assert(isValidSignature(basicTypeSignature)); - int resultPos = arity + 1; // skip '_' - if (arity < 0 || basicTypeSignature.length() != resultPos+1) - throw new IllegalArgumentException("bad arity for "+basicTypeSignature); - int numRes = (basicType(basicTypeSignature.charAt(resultPos)) == V_TYPE ? 0 : 1); - Name[] names = arguments(numRes, basicTypeSignature.substring(0, arity)); - for (int i = 0; i < numRes; i++) { - Name zero = new Name(constantZero(basicType(basicTypeSignature.charAt(resultPos + i)))); - names[arity + i] = zero.newIndex(arity + i); + private static Name[] buildEmptyNames(int arity, MethodType mt, boolean isVoid) { + Name[] names = arguments(isVoid ? 0 : 1, mt); + if (!isVoid) { + Name zero = new Name(constantZero(basicType(mt.returnType()))); + names[arity] = zero.newIndex(arity); } return names; } @@ -520,8 +516,13 @@ class LambdaForm { /** Return the method type corresponding to my basic type signature. */ MethodType methodType() { - return signatureType(basicTypeSignature()); + Class[] ptypes = new Class[arity]; + for (int i = 0; i < arity; ++i) { + ptypes[i] = parameterType(i).btClass; + } + return MethodType.methodType(returnType().btClass, ptypes); } + /** Return ABC_Z, where the ABC are parameter type characters, and Z is the return type character. */ final String basicTypeSignature() { StringBuilder buf = new StringBuilder(arity() + 3); @@ -633,7 +634,14 @@ class LambdaForm { // already prepared (e.g., a primitive DMH invoker form) return; } - LambdaForm prep = getPreparedForm(basicTypeSignature()); + MethodType mtype = methodType(); + LambdaForm prep = mtype.form().cachedLambdaForm(MethodTypeForm.LF_INTERPRET); + if (prep == null) { + assert (isValidSignature(basicTypeSignature())); + prep = new LambdaForm(mtype); + prep.vmentry = InvokerBytecodeGenerator.generateLambdaFormInterpreterEntryPoint(mtype); + prep = mtype.form().setCachedLambdaForm(MethodTypeForm.LF_INTERPRET, prep); + } this.vmentry = prep.vmentry; // TO DO: Maybe add invokeGeneric, invokeWithArguments } @@ -664,9 +672,10 @@ class LambdaForm { if (mt.parameterCount() > 0 && mt.parameterType(0) == MethodHandle.class && m.getName().startsWith("interpret_")) { - String sig = basicTypeSignature(mt); - assert(m.getName().equals("interpret" + sig.substring(sig.indexOf('_')))); - LambdaForm form = new LambdaForm(sig); + String sig = null; + assert((sig = basicTypeSignature(mt)) != null && + m.getName().equals("interpret" + sig.substring(sig.indexOf('_')))); + LambdaForm form = new LambdaForm(mt); form.vmentry = m; form = mt.form().setCachedLambdaForm(MethodTypeForm.LF_INTERPRET, form); } @@ -702,15 +711,6 @@ class LambdaForm { assert(returnTypesMatch(sig, av, res)); return res; } - private static LambdaForm getPreparedForm(String sig) { - MethodType mtype = signatureType(sig); - LambdaForm prep = mtype.form().cachedLambdaForm(MethodTypeForm.LF_INTERPRET); - if (prep != null) return prep; - assert(isValidSignature(sig)); - prep = new LambdaForm(sig); - prep.vmentry = InvokerBytecodeGenerator.generateLambdaFormInterpreterEntryPoint(sig); - return mtype.form().setCachedLambdaForm(MethodTypeForm.LF_INTERPRET, prep); - } // The next few routines are called only from assert expressions // They verify that the built-in invokers process the correct raw data types. @@ -1558,13 +1558,6 @@ class LambdaForm { if (n.constraint != null) return n; return argument(n.index, n.type); } - static Name[] arguments(int extra, String types) { - int length = types.length(); - Name[] names = new Name[length + extra]; - for (int i = 0; i < length; i++) - names[i] = argument(i, basicType(types.charAt(i))); - return names; - } static Name[] arguments(int extra, MethodType types) { int length = types.parameterCount(); Name[] names = new Name[length + extra]; From 03e64cef7be3a22cda43aeca829ba730c948c54e Mon Sep 17 00:00:00 2001 From: Michael Haupt Date: Thu, 3 Dec 2015 15:36:20 +0100 Subject: [PATCH 6/8] 8143343: add JEP 274 Javadoc tests to JavaDocExamplesTest Reviewed-by: sundar --- .../java/lang/invoke/MethodHandles.java | 9 +- .../java/lang/invoke/JavaDocExamplesTest.java | 168 +++++++++++++++++- 2 files changed, 172 insertions(+), 5 deletions(-) diff --git a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandles.java b/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandles.java index 8378ab9e1c3..535a7781cf7 100644 --- a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandles.java +++ b/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandles.java @@ -3463,7 +3463,7 @@ assertEquals("boojum", (String) catTrace.invokeExact("boo", "jum")); * return zip; * } * // assume MH_initZip, MH_zipPred, and MH_zipStep are handles to the above methods - * MethodHandle loop = MethodHandles.doWhileLoop(MH_initZip, MH_zipPred, MH_zipStep); + * MethodHandle loop = MethodHandles.doWhileLoop(MH_initZip, MH_zipStep, MH_zipPred); * List a = Arrays.asList("a", "b", "c", "d"); * List b = Arrays.asList("e", "f", "g", "h"); * List zipped = Arrays.asList("a", "e", "b", "f", "c", "g", "d", "h"); @@ -3602,7 +3602,8 @@ assertEquals("boojum", (String) catTrace.invokeExact("boo", "jum")); * String start(String arg) { return arg; } * String step(int counter, String v, String arg) { return "na " + v; } * // assume MH_start and MH_step are handles to the two methods above - * MethodHandle loop = MethodHandles.countedLoop(13, MH_start, MH_step); + * MethodHandle fit13 = MethodHandles.constant(int.class, 13); + * MethodHandle loop = MethodHandles.countedLoop(fit13, MH_start, MH_step); * assertEquals("na na na na na na na na na na na na na Lambdaman!", loop.invoke("Lambdaman!")); * } * @@ -3742,11 +3743,11 @@ assertEquals("boojum", (String) catTrace.invokeExact("boo", "jum")); * @apiNote Example: *
{@code
      * // reverse a list
-     * List reverseStep(String e, List r) {
+     * List reverseStep(String e, List r, List l) {
      *   r.add(0, e);
      *   return r;
      * }
-     * List newArrayList() { return new ArrayList<>(); }
+     * List newArrayList(List l) { return new ArrayList<>(); }
      * // assume MH_reverseStep, MH_newArrayList are handles to the above methods
      * MethodHandle loop = MethodHandles.iteratedLoop(null, MH_newArrayList, MH_reverseStep);
      * List list = Arrays.asList("a", "b", "c", "d", "e");
diff --git a/jdk/test/java/lang/invoke/JavaDocExamplesTest.java b/jdk/test/java/lang/invoke/JavaDocExamplesTest.java
index b94f2f04ea8..9a4b3f3624b 100644
--- a/jdk/test/java/lang/invoke/JavaDocExamplesTest.java
+++ b/jdk/test/java/lang/invoke/JavaDocExamplesTest.java
@@ -29,6 +29,7 @@
 
 package test.java.lang.invoke;
 
+import java.io.StringWriter;
 import java.lang.invoke.*;
 import static java.lang.invoke.MethodHandles.*;
 import static java.lang.invoke.MethodType.*;
@@ -36,7 +37,6 @@ import static java.lang.invoke.MethodType.*;
 import java.util.*;
 
 import org.testng.*;
-import static org.testng.AssertJUnit.*;
 import org.testng.annotations.*;
 
 /**
@@ -322,6 +322,13 @@ assertEquals("boojum", (String) catTrace.invokeExact("boo", "jum"));
         Assert.assertEquals(exp, act);
     }
 
+    static void assertTrue(boolean b) {
+        if (verbosity > 0) {
+            System.out.println("result: " + b);
+        }
+        Assert.assertTrue(b);
+    }
+
     @Test public void testMethodHandlesSummary() throws Throwable {
         {{
 {} /// JAVADOC
@@ -639,6 +646,165 @@ assert(!(boolean) invokeDispatched.invokeExact(y, "hasNext", "[123]+[789]"));
             }}
     }
 
+    static int one(int k) { return 1; }
+    static int inc(int i, int acc, int k) { return i + 1; }
+    static int mult(int i, int acc, int k) { return i * acc; }
+    static boolean pred(int i, int acc, int k) { return i < k; }
+    static int fin(int i, int acc, int k) { return acc; }
+
+    @Test public void testLoop() throws Throwable {
+        MethodHandle MH_inc, MH_one, MH_mult, MH_pred, MH_fin;
+        Class I = int.class;
+        MH_inc = LOOKUP.findStatic(THIS_CLASS, "inc", methodType(I, I, I, I));
+        MH_one = LOOKUP.findStatic(THIS_CLASS, "one", methodType(I, I));
+        MH_mult = LOOKUP.findStatic(THIS_CLASS, "mult", methodType(I, I, I, I));
+        MH_pred = LOOKUP.findStatic(THIS_CLASS, "pred", methodType(boolean.class, I, I, I));
+        MH_fin = LOOKUP.findStatic(THIS_CLASS, "fin", methodType(I, I, I, I));
+        {{
+{} /// JAVADOC
+// iterative implementation of the factorial function as a loop handle
+// null initializer for counter, should initialize to 0
+MethodHandle[] counterClause = new MethodHandle[]{null, MH_inc};
+MethodHandle[] accumulatorClause = new MethodHandle[]{MH_one, MH_mult, MH_pred, MH_fin};
+MethodHandle loop = MethodHandles.loop(counterClause, accumulatorClause);
+assertEquals(120, loop.invoke(5));
+{}
+        }}
+    }
+
+    static List initZip(Iterator a, Iterator b) { return new ArrayList<>(); }
+    static boolean zipPred(List zip, Iterator a, Iterator b) { return a.hasNext() && b.hasNext(); }
+    static List zipStep(List zip, Iterator a, Iterator b) {
+        zip.add(a.next());
+        zip.add(b.next());
+        return zip;
+    }
+
+    @Test public void testWhileLoop() throws Throwable {
+        MethodHandle MH_initZip, MH_zipPred, MH_zipStep;
+        Class IT = Iterator.class;
+        Class L = List.class;
+        MH_initZip = LOOKUP.findStatic(THIS_CLASS, "initZip", methodType(L, IT, IT));
+        MH_zipPred = LOOKUP.findStatic(THIS_CLASS, "zipPred", methodType(boolean.class, L, IT, IT));
+        MH_zipStep = LOOKUP.findStatic(THIS_CLASS, "zipStep", methodType(L, L, IT, IT));
+        {{
+{} /// JAVADOC
+// implement the zip function for lists as a loop handle
+MethodHandle loop = MethodHandles.doWhileLoop(MH_initZip, MH_zipStep, MH_zipPred);
+List a = Arrays.asList("a", "b", "c", "d");
+List b = Arrays.asList("e", "f", "g", "h");
+List zipped = Arrays.asList("a", "e", "b", "f", "c", "g", "d", "h");
+assertEquals(zipped, (List) loop.invoke(a.iterator(), b.iterator()));
+{}
+        }}
+    }
+
+    static int zero(int limit) { return 0; }
+    static int step(int i, int limit) { return i + 1; }
+    static boolean pred(int i, int limit) { return i < limit; }
+
+    @Test public void testDoWhileLoop() throws Throwable {
+        MethodHandle MH_zero, MH_step, MH_pred;
+        Class I = int.class;
+        MH_zero = LOOKUP.findStatic(THIS_CLASS, "zero", methodType(I, I));
+        MH_step = LOOKUP.findStatic(THIS_CLASS, "step", methodType(I, I, I));
+        MH_pred = LOOKUP.findStatic(THIS_CLASS, "pred", methodType(boolean.class, I, I));
+        {{
+{} /// JAVADOC
+// int i = 0; while (i < limit) { ++i; } return i; => limit
+MethodHandle loop = MethodHandles.doWhileLoop(MH_zero, MH_step, MH_pred);
+assertEquals(23, loop.invoke(23));
+{}
+        }}
+    }
+
+    static String start(String arg) { return arg; }
+    static String step(int counter, String v, String arg) { return "na " + v; }
+
+    @Test public void testCountedLoop() throws Throwable {
+        MethodHandle MH_start, MH_step;
+        Class S = String.class;
+        MH_start = LOOKUP.findStatic(THIS_CLASS, "start", methodType(S, S));
+        MH_step = LOOKUP.findStatic(THIS_CLASS, "step", methodType(S, int.class, S, S));
+        {{
+{} /// JAVADOC
+// String s = "Lambdaman!"; for (int i = 0; i < 13; ++i) { s = "na " + s; } return s;
+// => a variation on a well known theme
+MethodHandle fit13 = MethodHandles.constant(int.class, 13);
+MethodHandle loop = MethodHandles.countedLoop(fit13, MH_start, MH_step);
+assertEquals("na na na na na na na na na na na na na Lambdaman!", loop.invoke("Lambdaman!"));
+{}
+        }}
+    }
+
+    static List reverseStep(String e, List r, List l) {
+        r.add(0, e);
+        return r;
+    }
+    static List newArrayList(List l) { return new ArrayList<>(); }
+
+    @Test public void testIteratedLoop() throws Throwable {
+        MethodHandle MH_newArrayList, MH_reverseStep;
+        Class L = List.class;
+        MH_newArrayList = LOOKUP.findStatic(THIS_CLASS, "newArrayList", methodType(L, L));
+        MH_reverseStep = LOOKUP.findStatic(THIS_CLASS, "reverseStep", methodType(L, String.class, L, L));
+        {{
+{} /// JAVADOC
+// reverse a list
+MethodHandle loop = MethodHandles.iteratedLoop(null, MH_newArrayList, MH_reverseStep);
+List list = Arrays.asList("a", "b", "c", "d", "e");
+List reversedList = Arrays.asList("e", "d", "c", "b", "a");
+assertEquals(reversedList, (List) loop.invoke(list));
+{}
+        }}
+    }
+
+    @Test public void testFoldArguments3() throws Throwable {
+        {{
+{} /// JAVADOC
+MethodHandle trace = publicLookup().findVirtual(java.io.PrintStream.class,
+        "println", methodType(void.class, String.class))
+        .bindTo(System.out);
+MethodHandle cat = lookup().findVirtual(String.class,
+        "concat", methodType(String.class, String.class));
+assertEquals("boojum", (String) cat.invokeExact("boo", "jum"));
+MethodHandle catTrace = foldArguments(cat, 1, trace);
+// also prints "jum":
+assertEquals("boojum", (String) catTrace.invokeExact("boo", "jum"));
+{}
+        }}
+    }
+
+    @Test public void testAsCollector2() throws Throwable {
+        {{
+{} /// JAVADOC
+StringWriter swr = new StringWriter();
+MethodHandle swWrite = LOOKUP.findVirtual(StringWriter.class, "write", methodType(void.class, char[].class, int.class, int.class)).bindTo(swr);
+MethodHandle swWrite4 = swWrite.asCollector(0, char[].class, 4);
+swWrite4.invoke('A', 'B', 'C', 'D', 1, 2);
+assertEquals("BC", swr.toString());
+swWrite4.invoke('P', 'Q', 'R', 'S', 0, 4);
+assertEquals("BCPQRS", swr.toString());
+swWrite4.invoke('W', 'X', 'Y', 'Z', 3, 1);
+assertEquals("BCPQRSZ", swr.toString());
+{}
+        }}
+    }
+
+    @Test public void testAsSpreader2() throws Throwable {
+        {{
+{} /// JAVADOC
+MethodHandle compare = LOOKUP.findStatic(Objects.class, "compare", methodType(int.class, Object.class, Object.class, Comparator.class));
+MethodHandle compare2FromArray = compare.asSpreader(0, Object[].class, 2);
+Object[] ints = new Object[]{3, 9, 7, 7};
+Comparator cmp = (a, b) -> a - b;
+assertTrue((int) compare2FromArray.invoke(Arrays.copyOfRange(ints, 0, 2), cmp) < 0);
+assertTrue((int) compare2FromArray.invoke(Arrays.copyOfRange(ints, 1, 3), cmp) > 0);
+assertTrue((int) compare2FromArray.invoke(Arrays.copyOfRange(ints, 2, 4), cmp) == 0);
+{}
+        }}
+    }
+
     /* ---- TEMPLATE ----
     @Test public void testFoo() throws Throwable {
         {{

From 034df88671f4e1c9f2bed69a51cf93337d978f5d Mon Sep 17 00:00:00 2001
From: Rachna Goel 
Date: Thu, 3 Dec 2015 14:01:33 +0530
Subject: [PATCH 7/8] 8130246: java/util/Currency/PropertiesTest.sh fails
 Exception java.lang.NullPointerException

Updated PropertiesTest.sh to be sequential

Reviewed-by: naoto
---
 jdk/test/java/util/Currency/PropertiesTest.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/jdk/test/java/util/Currency/PropertiesTest.sh b/jdk/test/java/util/Currency/PropertiesTest.sh
index cc56c38d2d2..10dd24e519f 100644
--- a/jdk/test/java/util/Currency/PropertiesTest.sh
+++ b/jdk/test/java/util/Currency/PropertiesTest.sh
@@ -23,7 +23,7 @@
 #
 
 # @test
-# @bug 6332666 6863624 7180362 8003846 8074350 8074351
+# @bug 6332666 6863624 7180362 8003846 8074350 8074351 8130246
 # @summary tests the capability of replacing the currency data with user
 #     specified currency properties file
 # @build PropertiesTest
@@ -75,7 +75,7 @@ failures=0
 
 run() {
     echo ''
-    sh -xc "${TESTJAVA}${FS}bin${FS}java ${TESTVMOPTS} -cp ${TESTCLASSES} $*" 2>&1
+    ${TESTJAVA}${FS}bin${FS}java ${TESTVMOPTS} -cp ${TESTCLASSES} $* 2>&1
     if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
 }
 
@@ -108,7 +108,7 @@ echo "Properties location: ${PROPLOCATION}"
 
 # run
 echo ''
-sh -xc "${WRITABLEJDK}${FS}bin${FS}java ${TESTVMOPTS} -cp ${TESTCLASSES} PropertiesTest -d dump3"
+${WRITABLEJDK}${FS}bin${FS}java ${TESTVMOPTS} -cp ${TESTCLASSES} PropertiesTest -d dump3
 if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
 
 # Cleanup

From 9e7c59271736028dd19780d5634587244a30f616 Mon Sep 17 00:00:00 2001
From: Phil Race 
Date: Thu, 3 Dec 2015 11:53:00 -0800
Subject: [PATCH 8/8] 8144616: Problem building OpenJDK/harfbuzz on jprt

Reviewed-by: serb, vadim
---
 jdk/make/lib/Awt2dLibraries.gmk | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/jdk/make/lib/Awt2dLibraries.gmk b/jdk/make/lib/Awt2dLibraries.gmk
index bc4a95064a3..af85b7e0566 100644
--- a/jdk/make/lib/Awt2dLibraries.gmk
+++ b/jdk/make/lib/Awt2dLibraries.gmk
@@ -622,9 +622,8 @@ endif
 ifneq ($(OPENJDK_TARGET_OS), macosx)
   LIBFONTMANAGER_EXCLUDE_FILES += harfbuzz/hb-coretext.cc
 endif
-ifndef OPENJDK
-  LIBFONTMANAGER_EXCLUDE_FILES += harfbuzz/hb-ft.cc
-endif
+# hb-ft.cc is not presently needed, and requires freetype 2.4.2 or later.
+LIBFONTMANAGER_EXCLUDE_FILES += harfbuzz/hb-ft.cc
 
 LIBFONTMANAGER_CFLAGS += $(HARFBUZZ_CFLAGS)