8146484: Examine sun.misc.MessageUtils
authorchegar
Wed, 06 Jan 2016 17:40:48 +0000
changeset 34885 63d4a8c733f8
parent 34884 862b9a8988a0
child 34886 f3ee5206aa01
8146484: Examine sun.misc.MessageUtils Reviewed-by: alanb, mchung, sherman
jdk/make/mapfiles/libjava/mapfile-vers
jdk/make/src/classes/build/tools/dtdbuilder/DTDParser.java
jdk/src/java.base/share/classes/java/lang/StringCoding.java
jdk/src/java.base/share/classes/sun/misc/MessageUtils.java
jdk/src/java.base/share/native/libjava/MessageUtils.c
jdk/src/java.base/share/native/libjava/StringCoding.c
jdk/src/java.desktop/share/classes/javax/swing/text/html/parser/Parser.java
jdk/src/java.desktop/share/classes/sun/applet/AppletPanel.java
--- a/jdk/make/mapfiles/libjava/mapfile-vers	Wed Jan 06 17:59:20 2016 +0100
+++ b/jdk/make/mapfiles/libjava/mapfile-vers	Wed Jan 06 17:40:48 2016 +0000
@@ -216,6 +216,7 @@
 		Java_java_lang_SecurityManager_getClassContext;
 		Java_java_lang_Shutdown_halt0;
 		Java_java_lang_String_intern;
+		Java_java_lang_StringCoding_err;
 		Java_java_lang_StringUTF16_isBigEndian;
 		Java_java_lang_System_identityHashCode;
 		Java_java_lang_System_initProperties;
@@ -243,8 +244,6 @@
 		Java_java_util_TimeZone_getSystemTimeZoneID;
 		Java_java_util_TimeZone_getSystemGMTOffsetID;
 		Java_java_util_concurrent_atomic_AtomicLong_VMSupportsCS8;
-		Java_sun_misc_MessageUtils_toStderr;
-		Java_sun_misc_MessageUtils_toStdout;
 		Java_sun_misc_NativeSignalHandler_handle0;
 		Java_sun_misc_Signal_findSignal;
 		Java_sun_misc_Signal_handle0;
--- a/jdk/make/src/classes/build/tools/dtdbuilder/DTDParser.java	Wed Jan 06 17:59:20 2016 +0100
+++ b/jdk/make/src/classes/build/tools/dtdbuilder/DTDParser.java	Wed Jan 06 17:40:48 2016 +0000
@@ -35,8 +35,6 @@
 import java.util.BitSet;
 import java.text.MessageFormat;
 
-import sun.misc.MessageUtils;
-
 /**
  * A parser for DTDs. This parser roughly corresponds to the
  * rules specified in "The SGML Handbook" by Charles F. Goldfarb.
--- a/jdk/src/java.base/share/classes/java/lang/StringCoding.java	Wed Jan 06 17:59:20 2016 +0100
+++ b/jdk/src/java.base/share/classes/java/lang/StringCoding.java	Wed Jan 06 17:40:48 2016 +0000
@@ -39,7 +39,6 @@
 import java.nio.charset.UnsupportedCharsetException;
 import java.util.Arrays;
 import jdk.internal.HotSpotIntrinsicCandidate;
-import sun.misc.MessageUtils;
 import sun.nio.cs.HistoricallyNamedCharset;
 import sun.nio.cs.ArrayDecoder;
 import sun.nio.cs.ArrayEncoder;
@@ -106,11 +105,11 @@
 
     private static void warnUnsupportedCharset(String csn) {
         if (warnUnsupportedCharset) {
-            // Use sun.misc.MessageUtils rather than the Logging API or
-            // System.err since this method may be called during VM
-            // initialization before either is available.
-            MessageUtils.err("WARNING: Default charset " + csn +
-                             " not supported, using ISO-8859-1 instead");
+            // Use err(String) rather than the Logging API or System.err
+            // since this method may be called during VM initialization
+            // before either is available.
+            err("WARNING: Default charset " + csn +
+                " not supported, using ISO-8859-1 instead\n");
             warnUnsupportedCharset = false;
         }
     }
@@ -341,10 +340,9 @@
         try {
             return decode("ISO-8859-1", ba, off, len);
         } catch (UnsupportedEncodingException x) {
-            // If this code is hit during VM initialization, MessageUtils is
+            // If this code is hit during VM initialization, err(String) is
             // the only way we will be able to get any kind of error message.
-            MessageUtils.err("ISO-8859-1 charset not available: "
-                             + x.toString());
+            err("ISO-8859-1 charset not available: " + x.toString() + "\n");
             // If we can not find ISO-8859-1 (a required encoding) then things
             // are seriously wrong with the installation.
             System.exit(1);
@@ -653,14 +651,20 @@
         try {
             return encode("ISO-8859-1", coder, val);
         } catch (UnsupportedEncodingException x) {
-            // If this code is hit during VM initialization, MessageUtils is
+            // If this code is hit during VM initialization, err(String) is
             // the only way we will be able to get any kind of error message.
-            MessageUtils.err("ISO-8859-1 charset not available: "
-                             + x.toString());
+            err("ISO-8859-1 charset not available: " + x.toString() + "\n");
             // If we can not find ISO-8859-1 (a required encoding) then things
             // are seriously wrong with the installation.
             System.exit(1);
             return null;
         }
     }
+
+    /**
+     *  Print a message directly to stderr, bypassing all character conversion
+     *  methods.
+     *  @param msg  message to print
+     */
+    private static native void err(String msg);
 }
--- a/jdk/src/java.base/share/classes/sun/misc/MessageUtils.java	Wed Jan 06 17:59:20 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,127 +0,0 @@
-/*
- * Copyright (c) 1995, 2000, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package sun.misc;
-
-/**
- * MessageUtils: miscellaneous utilities for handling error and status
- * properties and messages.
- *
- * @author Herb Jellinek
- */
-
-public class MessageUtils {
-    // can instantiate it for to allow less verbose use - via instance
-    // instead of classname
-
-    public MessageUtils() { }
-
-    public static String subst(String patt, String arg) {
-        String args[] = { arg };
-        return subst(patt, args);
-    }
-
-    public static String subst(String patt, String arg1, String arg2) {
-        String args[] = { arg1, arg2 };
-        return subst(patt, args);
-    }
-
-    public static String subst(String patt, String arg1, String arg2,
-                               String arg3) {
-        String args[] = { arg1, arg2, arg3 };
-        return subst(patt, args);
-    }
-
-    public static String subst(String patt, String args[]) {
-        StringBuilder result = new StringBuilder();
-        int len = patt.length();
-        for (int i = 0; i >= 0 && i < len; i++) {
-            char ch = patt.charAt(i);
-            if (ch == '%') {
-                if (i != len) {
-                    int index = Character.digit(patt.charAt(i + 1), 10);
-                    if (index == -1) {
-                        result.append(patt.charAt(i + 1));
-                        i++;
-                    } else if (index < args.length) {
-                        result.append(args[index]);
-                        i++;
-                    }
-                }
-            } else {
-                result.append(ch);
-            }
-        }
-        return result.toString();
-    }
-
-    public static String substProp(String propName, String arg) {
-        return subst(System.getProperty(propName), arg);
-    }
-
-    public static String substProp(String propName, String arg1, String arg2) {
-        return subst(System.getProperty(propName), arg1, arg2);
-    }
-
-    public static String substProp(String propName, String arg1, String arg2,
-                                   String arg3) {
-        return subst(System.getProperty(propName), arg1, arg2, arg3);
-    }
-
-    /**
-     *  Print a message directly to stderr, bypassing all the
-     *  character conversion methods.
-     *  @param msg   message to print
-     */
-    public static native void toStderr(String msg);
-
-    /**
-     *  Print a message directly to stdout, bypassing all the
-     *  character conversion methods.
-     *  @param msg   message to print
-     */
-    public static native void toStdout(String msg);
-
-
-    // Short forms of the above
-
-    public static void err(String s) {
-        toStderr(s + "\n");
-    }
-
-    public static void out(String s) {
-        toStdout(s + "\n");
-    }
-
-    // Print a stack trace to stderr
-    //
-    public static void where() {
-        Throwable t = new Throwable();
-        StackTraceElement[] es = t.getStackTrace();
-        for (int i = 1; i < es.length; i++)
-            toStderr("\t" + es[i].toString() + "\n");
-    }
-
-}
--- a/jdk/src/java.base/share/native/libjava/MessageUtils.c	Wed Jan 06 17:59:20 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,82 +0,0 @@
-/*
- * Copyright (c) 1998, 2014, 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.
- */
-
-#include <stdlib.h>
-#include <jni.h>
-#include <jni_util.h>
-#include <jlong.h>
-#include <stdio.h>
-#include <jvm.h>
-
-#include "sun_misc_MessageUtils.h"
-
-static void
-printToFile(JNIEnv *env, jstring s, FILE *file)
-{
-    char *sConverted;
-    int length = 0;
-    int i;
-    const jchar *sAsArray;
-
-    if (s == NULL) {
-      s = (*env)->NewStringUTF(env, "null");
-      if (s == NULL) return;
-    }
-
-    sAsArray = (*env)->GetStringChars(env, s, NULL);
-    if (!sAsArray)
-        return;
-    length = (*env)->GetStringLength(env, s);
-    if (length == 0) {
-        (*env)->ReleaseStringChars(env, s, sAsArray);
-        return;
-    }
-    sConverted = (char *) malloc(length + 1);
-    if (!sConverted) {
-        (*env)->ReleaseStringChars(env, s, sAsArray);
-        JNU_ThrowOutOfMemoryError(env, NULL);
-        return;
-    }
-
-    for(i = 0; i < length; i++) {
-        sConverted[i] = (0x7f & sAsArray[i]);
-    }
-    sConverted[length] = '\0';
-    jio_fprintf(file, "%s", sConverted);
-    (*env)->ReleaseStringChars(env, s, sAsArray);
-    free(sConverted);
-}
-
-JNIEXPORT void JNICALL
-Java_sun_misc_MessageUtils_toStderr(JNIEnv *env, jclass cls, jstring s)
-{
-    printToFile(env, s, stderr);
-}
-
-JNIEXPORT void JNICALL
-Java_sun_misc_MessageUtils_toStdout(JNIEnv *env, jclass cls, jstring s)
-{
-    printToFile(env, s, stdout);
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/native/libjava/StringCoding.c	Wed Jan 06 17:40:48 2016 +0000
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 1998, 2014, 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.
+ */
+
+#include <stdlib.h>
+#include <jni.h>
+#include <jni_util.h>
+#include <stdio.h>
+#include <jvm.h>
+
+#include "java_lang_StringCoding.h"
+
+static void
+printToFile(JNIEnv *env, jstring s, FILE *file)
+{
+    char *sConverted;
+    int length = 0;
+    int i;
+    const jchar *sAsArray;
+
+    if (s == NULL) {
+        JNU_ThrowNullPointerException(env, NULL);
+        return;
+    }
+
+    sAsArray = (*env)->GetStringChars(env, s, NULL);
+    if (!sAsArray)
+        return;
+    length = (*env)->GetStringLength(env, s);
+    if (length == 0) {
+        (*env)->ReleaseStringChars(env, s, sAsArray);
+        return;
+    }
+    sConverted = (char *) malloc(length + 1);
+    if (!sConverted) {
+        (*env)->ReleaseStringChars(env, s, sAsArray);
+        JNU_ThrowOutOfMemoryError(env, NULL);
+        return;
+    }
+
+    for(i = 0; i < length; i++) {
+        sConverted[i] = (0x7f & sAsArray[i]);
+    }
+    sConverted[length] = '\0';
+    jio_fprintf(file, "%s", sConverted);
+    (*env)->ReleaseStringChars(env, s, sAsArray);
+    free(sConverted);
+}
+
+JNIEXPORT void JNICALL
+Java_java_lang_StringCoding_err(JNIEnv *env, jclass cls, jstring s)
+{
+    printToFile(env, s, stderr);
+}
--- a/jdk/src/java.desktop/share/classes/javax/swing/text/html/parser/Parser.java	Wed Jan 06 17:59:20 2016 +0100
+++ b/jdk/src/java.desktop/share/classes/javax/swing/text/html/parser/Parser.java	Wed Jan 06 17:40:48 2016 +0000
@@ -35,8 +35,6 @@
 import java.util.Enumeration;
 import java.net.URL;
 
-import sun.misc.MessageUtils;
-
 /**
  * A simple DTD-driven HTML parser. The parser reads an
  * HTML file from an InputStream and calls various methods
--- a/jdk/src/java.desktop/share/classes/sun/applet/AppletPanel.java	Wed Jan 06 17:59:20 2016 +0100
+++ b/jdk/src/java.desktop/share/classes/sun/applet/AppletPanel.java	Wed Jan 06 17:40:48 2016 +0000
@@ -44,7 +44,6 @@
 import sun.awt.EmbeddedFrame;
 import sun.awt.SunToolkit;
 import sun.misc.ManagedLocalsThread;
-import sun.misc.MessageUtils;
 import sun.misc.PerformanceLogger;
 import sun.security.util.SecurityConstants;
 
@@ -118,8 +117,6 @@
      */
     Dimension currentAppletSize = new Dimension(10, 10);
 
-    MessageUtils mu = new MessageUtils();
-
     /**
      * The thread to use during applet loading
      */