8269280: (bf) Replace StringBuffer in *Buffer.toString()

Reviewed-by: alanb, chegar, bpb
This commit is contained in:
Aleksey Shipilev 2021-06-25 08:08:10 +00:00
parent c37988d079
commit 3a8f3d6cac
9 changed files with 649 additions and 16 deletions

View file

@ -1666,16 +1666,11 @@ public abstract class $Type$Buffer
* @return A summary string * @return A summary string
*/ */
public String toString() { public String toString() {
StringBuffer sb = new StringBuffer(); return getClass().getName()
sb.append(getClass().getName()); + "[pos=" + position()
sb.append("[pos="); + " lim=" + limit()
sb.append(position()); + " cap=" + capacity()
sb.append(" lim="); + "]";
sb.append(limit());
sb.append(" cap=");
sb.append(capacity());
sb.append("]");
return sb.toString();
} }
#end[!char] #end[!char]

View file

@ -1134,6 +1134,26 @@ public class Basic$Type$
#end[byte] #end[byte]
} }
public static void testToString() {
final int cap = 10;
#if[byte]
$Type$Buffer direct1 = $Type$Buffer.allocateDirect(cap);
if (!direct1.toString().equals(Basic.toString(direct1))) {
fail("Direct buffer toString is incorrect: "
+ direct1.toString() + " vs " + Basic.toString(direct1));
}
#end[byte]
#if[!char]
$Type$Buffer nondirect1 = $Type$Buffer.allocate(cap);
if (!nondirect1.toString().equals(Basic.toString(nondirect1))) {
fail("Heap buffer toString is incorrect: "
+ nondirect1.toString() + " vs " + Basic.toString(nondirect1));
}
#end[!char]
}
public static void test() { public static void test() {
testAllocate(); testAllocate();
test(0, $Type$Buffer.allocate(7 * 1024), false); test(0, $Type$Buffer.allocate(7 * 1024), false);
@ -1155,6 +1175,8 @@ public class Basic$Type$
#else[byte] #else[byte]
putBuffer(); putBuffer();
#end[byte] #end[byte]
testToString();
} }
} }

View file

@ -1134,6 +1134,26 @@ public class BasicByte
} }
public static void testToString() {
final int cap = 10;
ByteBuffer direct1 = ByteBuffer.allocateDirect(cap);
if (!direct1.toString().equals(Basic.toString(direct1))) {
fail("Direct buffer toString is incorrect: "
+ direct1.toString() + " vs " + Basic.toString(direct1));
}
ByteBuffer nondirect1 = ByteBuffer.allocate(cap);
if (!nondirect1.toString().equals(Basic.toString(nondirect1))) {
fail("Heap buffer toString is incorrect: "
+ nondirect1.toString() + " vs " + Basic.toString(nondirect1));
}
}
public static void test() { public static void test() {
testAllocate(); testAllocate();
test(0, ByteBuffer.allocate(7 * 1024), false); test(0, ByteBuffer.allocate(7 * 1024), false);
@ -1155,6 +1175,8 @@ public class BasicByte
testToString();
} }
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2020, 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
@ -30,9 +30,19 @@
// -- This file was mechanically generated: Do not edit! -- // // -- This file was mechanically generated: Do not edit! -- //
import java.nio.*; import java.nio.*;
public class BasicChar public class BasicChar
extends Basic extends Basic
{ {
@ -451,6 +461,73 @@ public class BasicChar
@ -1055,6 +1132,26 @@ public class BasicChar
}
public static void testToString() {
final int cap = 10;
} }
public static void test() { public static void test() {
@ -1078,6 +1175,8 @@ public class BasicChar
putBuffer(); putBuffer();
testToString();
} }
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2020, 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
@ -30,9 +30,19 @@
// -- This file was mechanically generated: Do not edit! -- // // -- This file was mechanically generated: Do not edit! -- //
import java.nio.*; import java.nio.*;
public class BasicDouble public class BasicDouble
extends Basic extends Basic
{ {
@ -451,6 +461,73 @@ public class BasicDouble
@ -1055,6 +1132,26 @@ public class BasicDouble
}
public static void testToString() {
final int cap = 10;
DoubleBuffer nondirect1 = DoubleBuffer.allocate(cap);
if (!nondirect1.toString().equals(Basic.toString(nondirect1))) {
fail("Heap buffer toString is incorrect: "
+ nondirect1.toString() + " vs " + Basic.toString(nondirect1));
}
} }
public static void test() { public static void test() {
@ -1078,6 +1175,8 @@ public class BasicDouble
putBuffer(); putBuffer();
testToString();
} }
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2020, 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
@ -30,9 +30,19 @@
// -- This file was mechanically generated: Do not edit! -- // // -- This file was mechanically generated: Do not edit! -- //
import java.nio.*; import java.nio.*;
public class BasicFloat public class BasicFloat
extends Basic extends Basic
{ {
@ -451,6 +461,73 @@ public class BasicFloat
@ -1055,6 +1132,26 @@ public class BasicFloat
}
public static void testToString() {
final int cap = 10;
FloatBuffer nondirect1 = FloatBuffer.allocate(cap);
if (!nondirect1.toString().equals(Basic.toString(nondirect1))) {
fail("Heap buffer toString is incorrect: "
+ nondirect1.toString() + " vs " + Basic.toString(nondirect1));
}
} }
public static void test() { public static void test() {
@ -1078,6 +1175,8 @@ public class BasicFloat
putBuffer(); putBuffer();
testToString();
} }
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2020, 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
@ -30,9 +30,19 @@
// -- This file was mechanically generated: Do not edit! -- // // -- This file was mechanically generated: Do not edit! -- //
import java.nio.*; import java.nio.*;
public class BasicInt public class BasicInt
extends Basic extends Basic
{ {
@ -451,6 +461,73 @@ public class BasicInt
@ -1055,6 +1132,26 @@ public class BasicInt
}
public static void testToString() {
final int cap = 10;
IntBuffer nondirect1 = IntBuffer.allocate(cap);
if (!nondirect1.toString().equals(Basic.toString(nondirect1))) {
fail("Heap buffer toString is incorrect: "
+ nondirect1.toString() + " vs " + Basic.toString(nondirect1));
}
} }
public static void test() { public static void test() {
@ -1078,6 +1175,8 @@ public class BasicInt
putBuffer(); putBuffer();
testToString();
} }
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2020, 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
@ -30,9 +30,19 @@
// -- This file was mechanically generated: Do not edit! -- // // -- This file was mechanically generated: Do not edit! -- //
import java.nio.*; import java.nio.*;
public class BasicLong public class BasicLong
extends Basic extends Basic
{ {
@ -451,6 +461,73 @@ public class BasicLong
@ -1055,6 +1132,26 @@ public class BasicLong
}
public static void testToString() {
final int cap = 10;
LongBuffer nondirect1 = LongBuffer.allocate(cap);
if (!nondirect1.toString().equals(Basic.toString(nondirect1))) {
fail("Heap buffer toString is incorrect: "
+ nondirect1.toString() + " vs " + Basic.toString(nondirect1));
}
} }
public static void test() { public static void test() {
@ -1078,6 +1175,8 @@ public class BasicLong
putBuffer(); putBuffer();
testToString();
} }
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2020, 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
@ -30,9 +30,19 @@
// -- This file was mechanically generated: Do not edit! -- // // -- This file was mechanically generated: Do not edit! -- //
import java.nio.*; import java.nio.*;
public class BasicShort public class BasicShort
extends Basic extends Basic
{ {
@ -451,6 +461,73 @@ public class BasicShort
@ -1055,6 +1132,26 @@ public class BasicShort
}
public static void testToString() {
final int cap = 10;
ShortBuffer nondirect1 = ShortBuffer.allocate(cap);
if (!nondirect1.toString().equals(Basic.toString(nondirect1))) {
fail("Heap buffer toString is incorrect: "
+ nondirect1.toString() + " vs " + Basic.toString(nondirect1));
}
} }
public static void test() { public static void test() {
@ -1078,6 +1175,8 @@ public class BasicShort
putBuffer(); putBuffer();
testToString();
} }
} }