test/jdk/java/lang/StringBuffer/CompactStringBufferSerialization.java
author phh
Sat, 30 Nov 2019 14:33:05 -0800
changeset 59330 5b96c12f909d
parent 47216 71c04702a3d5
permissions -rw-r--r--
8234541: C1 emits an empty message when it inlines successfully Summary: Use "inline" as the message when successfull Reviewed-by: thartmann, mdoerr Contributed-by: navy.xliu@gmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33663
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
     1
/*
45179
5c2ed400440a 8180391: move SerializationUtils to top level testlibrary
iignatyev
parents: 33663
diff changeset
     2
 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
33663
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
     4
 *
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
     7
 * published by the Free Software Foundation.
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
     8
 *
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    13
 * accompanied this code).
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    14
 *
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    18
 *
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    21
 * questions.
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    22
 */
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    23
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    24
import java.io.*;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    25
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    26
import org.testng.annotations.DataProvider;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    27
import org.testng.annotations.Test;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    28
45179
5c2ed400440a 8180391: move SerializationUtils to top level testlibrary
iignatyev
parents: 33663
diff changeset
    29
import static jdk.test.lib.util.SerializationUtils.*;
33663
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    30
import static org.testng.Assert.*;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    31
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    32
/*
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    33
 * @test
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    34
 * @bug 8077559
45179
5c2ed400440a 8180391: move SerializationUtils to top level testlibrary
iignatyev
parents: 33663
diff changeset
    35
 * @library /test/lib
45466
faf1c55d2046 8181759: add explicit @build actions for jdk.test.lib classes in all :tier1 tests
iignatyev
parents: 45179
diff changeset
    36
 * @build jdk.test.lib.util.SerializationUtils
33663
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    37
 * @summary Tests Compact String. This one is testing StringBuffer serialization
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    38
 *          among -XX:+CompactStrings/-XX:-CompactStrings/LegacyStringBuffer
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    39
 * @run testng/othervm -XX:+CompactStrings CompactStringBufferSerialization
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    40
 * @run testng/othervm -XX:-CompactStrings CompactStringBufferSerialization
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    41
 */
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    42
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    43
public class CompactStringBufferSerialization {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    44
    @DataProvider
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    45
    public Object[][] provider() {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    46
        return new Object[][] {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    47
                // every byte array is serialized from corresponding StringBuilder object
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    48
                // by previous JDK(build 1.8.0_45-b14).
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    49
                new Object[] {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    50
                        new StringBuffer(""),
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    51
                        new byte[] { -84, -19, 0, 5, 115, 114, 0, 22, 106, 97, 118, 97, 46, 108, 97, 110, 103, 46, 83, 116, 114, 105, 110, 103, 66, 117, 102,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    52
                                102, 101, 114, 47, 7, 7, -39, -22, -56, -22, -45, 3, 0, 3, 73, 0, 5, 99, 111, 117, 110, 116, 90, 0, 6, 115, 104, 97, 114, 101,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    53
                                100, 91, 0, 5, 118, 97, 108, 117, 101, 116, 0, 2, 91, 67, 120, 112, 0, 0, 0, 0, 0, 117, 114, 0, 2, 91, 67, -80, 38, 102, -80,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    54
                                -30, 93, -124, -84, 2, 0, 0, 120, 112, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    55
                                0, 0, 0, 0, 0, 0, 0, 120 } },
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    56
                new Object[] {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    57
                        new StringBuffer("A"),
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    58
                        new byte[] { -84, -19, 0, 5, 115, 114, 0, 22, 106, 97, 118, 97, 46, 108, 97, 110, 103, 46, 83, 116, 114, 105, 110, 103, 66, 117, 102,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    59
                                102, 101, 114, 47, 7, 7, -39, -22, -56, -22, -45, 3, 0, 3, 73, 0, 5, 99, 111, 117, 110, 116, 90, 0, 6, 115, 104, 97, 114, 101,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    60
                                100, 91, 0, 5, 118, 97, 108, 117, 101, 116, 0, 2, 91, 67, 120, 112, 0, 0, 0, 1, 0, 117, 114, 0, 2, 91, 67, -80, 38, 102, -80,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    61
                                -30, 93, -124, -84, 2, 0, 0, 120, 112, 0, 0, 0, 17, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    62
                                0, 0, 0, 0, 0, 0, 0, 0, 0, 120 } },
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    63
                new Object[] {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    64
                        new StringBuffer("AB"),
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    65
                        new byte[] { -84, -19, 0, 5, 115, 114, 0, 22, 106, 97, 118, 97, 46, 108, 97, 110, 103, 46, 83, 116, 114, 105, 110, 103, 66, 117, 102,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    66
                                102, 101, 114, 47, 7, 7, -39, -22, -56, -22, -45, 3, 0, 3, 73, 0, 5, 99, 111, 117, 110, 116, 90, 0, 6, 115, 104, 97, 114, 101,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    67
                                100, 91, 0, 5, 118, 97, 108, 117, 101, 116, 0, 2, 91, 67, 120, 112, 0, 0, 0, 2, 0, 117, 114, 0, 2, 91, 67, -80, 38, 102, -80,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    68
                                -30, 93, -124, -84, 2, 0, 0, 120, 112, 0, 0, 0, 18, 0, 65, 0, 66, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    69
                                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 120 } },
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    70
                new Object[] {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    71
                        new StringBuffer("abcdefghijk"),
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    72
                        new byte[] { -84, -19, 0, 5, 115, 114, 0, 22, 106, 97, 118, 97, 46, 108, 97, 110, 103, 46, 83, 116, 114, 105, 110, 103, 66, 117, 102,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    73
                                102, 101, 114, 47, 7, 7, -39, -22, -56, -22, -45, 3, 0, 3, 73, 0, 5, 99, 111, 117, 110, 116, 90, 0, 6, 115, 104, 97, 114, 101,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    74
                                100, 91, 0, 5, 118, 97, 108, 117, 101, 116, 0, 2, 91, 67, 120, 112, 0, 0, 0, 11, 0, 117, 114, 0, 2, 91, 67, -80, 38, 102, -80,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    75
                                -30, 93, -124, -84, 2, 0, 0, 120, 112, 0, 0, 0, 27, 0, 97, 0, 98, 0, 99, 0, 100, 0, 101, 0, 102, 0, 103, 0, 104, 0, 105, 0,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    76
                                106, 0, 107, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 120 } },
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    77
                new Object[] {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    78
                        new StringBuffer("\uff21"),
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    79
                        new byte[] { -84, -19, 0, 5, 115, 114, 0, 22, 106, 97, 118, 97, 46, 108, 97, 110, 103, 46, 83, 116, 114, 105, 110, 103, 66, 117, 102,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    80
                                102, 101, 114, 47, 7, 7, -39, -22, -56, -22, -45, 3, 0, 3, 73, 0, 5, 99, 111, 117, 110, 116, 90, 0, 6, 115, 104, 97, 114, 101,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    81
                                100, 91, 0, 5, 118, 97, 108, 117, 101, 116, 0, 2, 91, 67, 120, 112, 0, 0, 0, 1, 0, 117, 114, 0, 2, 91, 67, -80, 38, 102, -80,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    82
                                -30, 93, -124, -84, 2, 0, 0, 120, 112, 0, 0, 0, 17, -1, 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    83
                                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 120 } },
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    84
                new Object[] {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    85
                        new StringBuffer("\uff21\uff22"),
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    86
                        new byte[] { -84, -19, 0, 5, 115, 114, 0, 22, 106, 97, 118, 97, 46, 108, 97, 110, 103, 46, 83, 116, 114, 105, 110, 103, 66, 117, 102,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    87
                                102, 101, 114, 47, 7, 7, -39, -22, -56, -22, -45, 3, 0, 3, 73, 0, 5, 99, 111, 117, 110, 116, 90, 0, 6, 115, 104, 97, 114, 101,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    88
                                100, 91, 0, 5, 118, 97, 108, 117, 101, 116, 0, 2, 91, 67, 120, 112, 0, 0, 0, 2, 0, 117, 114, 0, 2, 91, 67, -80, 38, 102, -80,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    89
                                -30, 93, -124, -84, 2, 0, 0, 120, 112, 0, 0, 0, 18, -1, 33, -1, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    90
                                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 120 } },
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    91
                new Object[] {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    92
                        new StringBuffer("\uff21A\uff21A\uff21A\uff21A\uff21A"),
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    93
                        new byte[] { -84, -19, 0, 5, 115, 114, 0, 22, 106, 97, 118, 97, 46, 108, 97, 110, 103, 46, 83, 116, 114, 105, 110, 103, 66, 117, 102,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    94
                                102, 101, 114, 47, 7, 7, -39, -22, -56, -22, -45, 3, 0, 3, 73, 0, 5, 99, 111, 117, 110, 116, 90, 0, 6, 115, 104, 97, 114, 101,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    95
                                100, 91, 0, 5, 118, 97, 108, 117, 101, 116, 0, 2, 91, 67, 120, 112, 0, 0, 0, 10, 0, 117, 114, 0, 2, 91, 67, -80, 38, 102, -80,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    96
                                -30, 93, -124, -84, 2, 0, 0, 120, 112, 0, 0, 0, 26, -1, 33, 0, 65, -1, 33, 0, 65, -1, 33, 0, 65, -1, 33, 0, 65, -1, 33, 0, 65,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    97
                                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 120 } },
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    98
                new Object[] {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    99
                        new StringBuffer("A\uff21B\uff22C\uff23D\uff24E\uff25F\uff26G\uff27H\uff28"),
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   100
                        new byte[] { -84, -19, 0, 5, 115, 114, 0, 22, 106, 97, 118, 97, 46, 108, 97, 110, 103, 46, 83, 116, 114, 105, 110, 103, 66, 117, 102,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   101
                                102, 101, 114, 47, 7, 7, -39, -22, -56, -22, -45, 3, 0, 3, 73, 0, 5, 99, 111, 117, 110, 116, 90, 0, 6, 115, 104, 97, 114, 101,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   102
                                100, 91, 0, 5, 118, 97, 108, 117, 101, 116, 0, 2, 91, 67, 120, 112, 0, 0, 0, 16, 0, 117, 114, 0, 2, 91, 67, -80, 38, 102, -80,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   103
                                -30, 93, -124, -84, 2, 0, 0, 120, 112, 0, 0, 0, 32, 0, 65, -1, 33, 0, 66, -1, 34, 0, 67, -1, 35, 0, 68, -1, 36, 0, 69, -1, 37,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   104
                                0, 70, -1, 38, 0, 71, -1, 39, 0, 72, -1, 40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   105
                                0, 0, 0, 0, 0, 120 } },
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   106
                new Object[] {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   107
                        new StringBuffer("\uff21A\uff22B\uff23C\uff24D\uff25E\uff26F\uff27G\uff28H"),
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   108
                        new byte[] { -84, -19, 0, 5, 115, 114, 0, 22, 106, 97, 118, 97, 46, 108, 97, 110, 103, 46, 83, 116, 114, 105, 110, 103, 66, 117, 102,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   109
                                102, 101, 114, 47, 7, 7, -39, -22, -56, -22, -45, 3, 0, 3, 73, 0, 5, 99, 111, 117, 110, 116, 90, 0, 6, 115, 104, 97, 114, 101,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   110
                                100, 91, 0, 5, 118, 97, 108, 117, 101, 116, 0, 2, 91, 67, 120, 112, 0, 0, 0, 16, 0, 117, 114, 0, 2, 91, 67, -80, 38, 102, -80,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   111
                                -30, 93, -124, -84, 2, 0, 0, 120, 112, 0, 0, 0, 32, -1, 33, 0, 65, -1, 34, 0, 66, -1, 35, 0, 67, -1, 36, 0, 68, -1, 37, 0, 69,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   112
                                -1, 38, 0, 70, -1, 39, 0, 71, -1, 40, 0, 72, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   113
                                0, 0, 0, 0, 0, 120 } },
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   114
                new Object[] {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   115
                        new StringBuffer("\ud801\udc00\ud801\udc01\uff21A"),
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   116
                        new byte[] { -84, -19, 0, 5, 115, 114, 0, 22, 106, 97, 118, 97, 46, 108, 97, 110, 103, 46, 83, 116, 114, 105, 110, 103, 66, 117, 102,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   117
                                102, 101, 114, 47, 7, 7, -39, -22, -56, -22, -45, 3, 0, 3, 73, 0, 5, 99, 111, 117, 110, 116, 90, 0, 6, 115, 104, 97, 114, 101,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   118
                                100, 91, 0, 5, 118, 97, 108, 117, 101, 116, 0, 2, 91, 67, 120, 112, 0, 0, 0, 6, 0, 117, 114, 0, 2, 91, 67, -80, 38, 102, -80,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   119
                                -30, 93, -124, -84, 2, 0, 0, 120, 112, 0, 0, 0, 22, -40, 1, -36, 0, -40, 1, -36, 1, -1, 33, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   120
                                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 120 } },
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   121
                new Object[] {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   122
                        new StringBuffer("\uff21\uff22\uff21\uff22\uff21\uff22\uff21\uff22\uff21\uff22"),
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   123
                        new byte[] { -84, -19, 0, 5, 115, 114, 0, 22, 106, 97, 118, 97, 46, 108, 97, 110, 103, 46, 83, 116, 114, 105, 110, 103, 66, 117, 102,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   124
                                102, 101, 114, 47, 7, 7, -39, -22, -56, -22, -45, 3, 0, 3, 73, 0, 5, 99, 111, 117, 110, 116, 90, 0, 6, 115, 104, 97, 114, 101,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   125
                                100, 91, 0, 5, 118, 97, 108, 117, 101, 116, 0, 2, 91, 67, 120, 112, 0, 0, 0, 10, 0, 117, 114, 0, 2, 91, 67, -80, 38, 102, -80,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   126
                                -30, 93, -124, -84, 2, 0, 0, 120, 112, 0, 0, 0, 26, -1, 33, -1, 34, -1, 33, -1, 34, -1, 33, -1, 34, -1, 33, -1, 34, -1, 33, -1,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   127
                                34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 120 } } };
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   128
    }
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   129
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   130
    /*
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   131
     * Verify serialization works between Compact StringBuffer/Legacy StringBuffer
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   132
     */
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   133
    @Test(dataProvider = "provider")
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   134
    public void test(StringBuffer sbContent, byte[] baInJDK8) throws Exception {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   135
        // Serialize a StringBuffer object into byte array.
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   136
        byte[] ba = serialize(sbContent);
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   137
        assertEquals(ba, baInJDK8);
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   138
        // Deserialize a StringBuffer object from byte array which is generated by previous JDK(build 1.8.0_45-b14).
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   139
        Object obj = deserialize(ba);
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   140
        assertEquals(obj.getClass(), StringBuffer.class);
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   141
        assertTrue(equals((StringBuffer)obj, sbContent));
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   142
    }
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   143
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   144
    boolean equals(StringBuffer sb, StringBuffer expected) {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   145
        if(sb.length() == expected.length()
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   146
                && sb.capacity() == expected.capacity()
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   147
                && sb.toString().equals(expected.toString())) {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   148
            return true;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   149
        }
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   150
        return false;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   151
    }
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   152
}