8204531: Remove unused chars following '\0'
authorysuenaga
Thu, 14 Jun 2018 16:56:58 +0900
changeset 50560 dafb2cc6ba32
parent 50559 27929b7eae4b
child 50561 5756e8eecb17
8204531: Remove unused chars following '\0' Reviewed-by: dholmes, stuefe
src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/PerfDataEntry.java
src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/CStringUtilities.java
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/PerfDataEntry.java	Thu Jun 14 00:07:10 2018 -0700
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/PerfDataEntry.java	Thu Jun 14 16:56:58 2018 +0900
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,6 +24,7 @@
 
 package sun.jvm.hotspot.runtime;
 
+import java.nio.charset.StandardCharsets;
 import java.util.*;
 import sun.jvm.hotspot.debugger.*;
 import sun.jvm.hotspot.oops.*;
@@ -362,11 +363,8 @@
                 str = new String(charArrayValue());
             } else if (dataType == BasicType.getTByte()) {
                 // byte[] is returned as a String
-                try {
-                    str = new String(byteArrayValue(), "US-ASCII");
-                } catch (java.io.UnsupportedEncodingException e) {
-                    str = "can't decode string : " + e.getMessage();
-                }
+                str = CStringUtilities.getString(addr.addOffsetTo(dataOffset()),
+                                                 StandardCharsets.US_ASCII);
             } else if (dataType == BasicType.getTShort()) {
                 short[] res = shortArrayValue();
                 StringBuffer buf = new StringBuffer();
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/CStringUtilities.java	Thu Jun 14 00:07:10 2018 -0700
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/CStringUtilities.java	Thu Jun 14 16:56:58 2018 +0900
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,7 @@
 package sun.jvm.hotspot.utilities;
 
 import java.io.*;
+import java.nio.charset.Charset;
 import java.util.*;
 
 import sun.jvm.hotspot.debugger.*;
@@ -45,11 +46,15 @@
 
   private static String encoding = System.getProperty("file.encoding", "US-ASCII");
 
+  public static String getString(Address addr) {
+    return getString(addr, Charset.forName(encoding));
+  }
+
   /** Fetch a null-terminated ASCII string from the remote process.
       Returns null if the argument is null, otherwise returns a
       non-null string (for example, returns an empty string if the
       first character fetched is the null terminator). */
-  public static String getString(Address addr) {
+  public static String getString(Address addr, Charset charset) {
     if (addr == null) {
       return null;
     }
@@ -73,10 +78,6 @@
     // FIXME: When we switch to use JDK 6 to build SA,
     // we can change the following to just return:
     // return new String(bytes, Charset.defaultCharset());
-    try {
-      return new String(bytes, encoding);
-    } catch (UnsupportedEncodingException e) {
-      throw new RuntimeException("Error converting bytes to String using " + encoding + " encoding", e);
-    }
+    return new String(bytes, charset);
   }
 }