RFR: 8301065: Handle control characters in java_lang_String::print

Ioi Lam iklam at openjdk.org
Fri Jan 27 16:39:17 UTC 2023


On Wed, 25 Jan 2023 11:51:37 GMT, Kevin Walls <kevinw at openjdk.org> wrote:

> Change to avoid printing raw control characters in  java_lang_String::print.
> Usually called in debug printing and error reporting.  One usage from debug logging for modules.
> 
> Format as \x followed by two hex digits, e.g. \x0A 
> 
> Small change, in a routine with few callers.  Could make two calls to value->byte_at(), which I left in as it reads more clearly, and this is not called at time critical situations.
> 
> The error reporting and debug.cpp usages I can test manually, with some trial and error, trying to catch the register info containing relevant info.  This same String printing routine is used for showing register contents or stack slot mappings, and for a String, or a class containing a String.  
> 
> Before the change: (newlines and null embedded in String)
> 
> R11=0x000000011f74e568 is an oop: java.lang.String
> {0x000000011f74e568} - klass: 'java/lang/String'
>  - string: "this is my string
> ^@and also: this is more of my string
> "
>  - ---- fields (total size 3 words):
>  - private 'hash' 'I' @12  0 (0x00000000)
> 
> 
> 
> With the change:
> 
> {0x000000011faf5bf0} - klass: 'Test'
>  - ---- fields (total size 3 words):
>  - private 'lastChar' 'C' @12    10 (0x000a)
>  - private 'myString' 'Ljava/lang/String;' @16  "this is my string\x0A\x00and also: this is more of my string\x0A"{0x000000011faf5ca8} (0x23f5eb95)
> R15=0x00007f928002a260 is a thread

Changes requested by iklam (Reviewer).

src/hotspot/share/classfile/javaClasses.cpp line 768:

> 766:   for (int index = 0; index < length; index++) {
> 767:     jchar c = value->byte_at(index);
> 768:     if (c < ' ') {

`byte_at()` will give the wrong result if `is_latin1` is false.

Maybe we should use `java_lang_String::as_quoted_ascii()` instead?

-------------

PR: https://git.openjdk.org/jdk/pull/12190


More information about the hotspot-runtime-dev mailing list