8328592: hprof tests fail with -XX:-CompactStrings
Reviewed-by: phh, lmesnik, amenkov
This commit is contained in:
parent
ac2f8e5af8
commit
bb3e84bd1f
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -188,9 +188,14 @@ public class JavaObject extends JavaLazyReadObject {
|
|||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if (getClazz().isString()) {
|
if (getClazz().isString()) {
|
||||||
|
JavaThing coder = getField("coder");
|
||||||
|
boolean compact = false;
|
||||||
|
if (coder instanceof JavaByte) {
|
||||||
|
compact = ((JavaByte)coder).value == 0;
|
||||||
|
}
|
||||||
JavaThing value = getField("value");
|
JavaThing value = getField("value");
|
||||||
if (value instanceof JavaValueArray) {
|
if (value instanceof JavaValueArray) {
|
||||||
return ((JavaValueArray)value).valueAsString();
|
return ((JavaValueArray)value).valueAsString(compact);
|
||||||
} else {
|
} else {
|
||||||
return "null";
|
return "null";
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -31,6 +31,7 @@
|
|||||||
package jdk.test.lib.hprof.model;
|
package jdk.test.lib.hprof.model;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -348,15 +349,37 @@ public class JavaValueArray extends JavaLazyReadObject
|
|||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final int STRING_HI_BYTE_SHIFT;
|
||||||
|
private static final int STRING_LO_BYTE_SHIFT;
|
||||||
|
static {
|
||||||
|
if (ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN) {
|
||||||
|
STRING_HI_BYTE_SHIFT = 8;
|
||||||
|
STRING_LO_BYTE_SHIFT = 0;
|
||||||
|
} else {
|
||||||
|
STRING_HI_BYTE_SHIFT = 0;
|
||||||
|
STRING_LO_BYTE_SHIFT = 8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Tries to represent the value as string (used by JavaObject.toString).
|
// Tries to represent the value as string (used by JavaObject.toString).
|
||||||
public String valueAsString() {
|
public String valueAsString(boolean compact) {
|
||||||
if (getElementType() == 'B') {
|
if (getElementType() == 'B') {
|
||||||
JavaThing[] things = getValue();
|
JavaThing[] things = getValue();
|
||||||
byte[] bytes = new byte[things.length];
|
if (compact) {
|
||||||
for (int i = 0; i < things.length; i++) {
|
byte[] bytes = new byte[things.length];
|
||||||
bytes[i] = ((JavaByte)things[i]).value;
|
for (int i = 0; i < things.length; i++) {
|
||||||
|
bytes[i] = ((JavaByte)things[i]).value;
|
||||||
|
}
|
||||||
|
return new String(bytes);
|
||||||
|
} else {
|
||||||
|
char[] chars = new char[things.length / 2];
|
||||||
|
for (int i = 0; i < things.length; i += 2) {
|
||||||
|
int b1 = ((JavaByte)things[i]).value << STRING_HI_BYTE_SHIFT;
|
||||||
|
int b2 = ((JavaByte)things[i + 1]).value << STRING_LO_BYTE_SHIFT;
|
||||||
|
chars[i / 2] = (char)(b1 | b2);
|
||||||
|
}
|
||||||
|
return new String(chars);
|
||||||
}
|
}
|
||||||
return new String(bytes);
|
|
||||||
}
|
}
|
||||||
// fallback
|
// fallback
|
||||||
return valueString();
|
return valueString();
|
||||||
|
Loading…
Reference in New Issue
Block a user