8204531: Remove unused chars following '\0'

Reviewed-by: dholmes, stuefe
This commit is contained in:
Yasumasa Suenaga 2018-06-14 16:56:58 +09:00
parent 467da554a2
commit 390487c14d
2 changed files with 12 additions and 13 deletions

View File

@ -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 @@ public class PerfDataEntry extends VMObject {
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();

View File

@ -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 @@ public class CStringUtilities {
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 @@ public class CStringUtilities {
// 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);
}
}