jdk/test/java/text/Bidi/Bug6665028.java
author peytoia
Mon, 08 Sep 2008 10:44:57 +0900
changeset 1310 edc39463f896
child 5506 202f599c92aa
permissions -rw-r--r--
6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct Reviewed-by: okutsu
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1310
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
     1
/*
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
     2
 * Copyright (c) 2007 Sun Microsystems, Inc.  All Rights Reserved.
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
     4
 *
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
     7
 * published by the Free Software Foundation.
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
     8
 *
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    13
 * accompanied this code).
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    14
 *
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    18
 *
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    21
 * have any questions.
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    22
 */
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    23
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    24
/*
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    25
 * @test
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    26
 * @bug 6665028
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    27
 * @summary verify that the memory corruption doesn't happen. Note
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    28
 * that this test case fails without the fix in some different ways,
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    29
 * including timeout, due to the memory corruption.
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    30
 * @build Bug6665028
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    31
 * @run main/othervm/timeout=60 -Xmx16m Bug6665028
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    32
 */
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    33
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    34
import java.awt.font.TextAttribute;
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    35
import java.text.AttributedString;
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    36
import java.text.Bidi;
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    37
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    38
// test1() and test2() were derived from BidiEmbeddingTest.
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    39
public class Bug6665028 {
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    40
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    41
    private static boolean runrun = true;
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    42
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    43
    private static class Test extends Thread {
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    44
        public void run() {
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    45
            while (runrun) {
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    46
                test1();
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    47
                test2();
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    48
            }
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    49
        }
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    50
    }
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    51
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    52
    public static void main(String[] args) {
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    53
        Test[] tests = new Test[4];
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    54
        for (int i = 0; i < tests.length; i++) {
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    55
            Test t = new Test();
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    56
            tests[i] = t;
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    57
            t.start();
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    58
        }
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    59
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    60
        try {
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    61
            Thread.sleep(45000);
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    62
        } catch (InterruptedException e) {
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    63
        }
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    64
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    65
        runrun = false;
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    66
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    67
        for (int i = 0; i < tests.length; i++) {
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    68
            try {
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    69
                tests[i].join();
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    70
            } catch (InterruptedException e) {
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    71
            }
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    72
        }
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    73
    }
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    74
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    75
    static String target;
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    76
    static {
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    77
        String s = "A Bidi object provides information on the bidirectional reordering of the text used to create it. This is required, for example, to properly display Arabic or Hebrew text. ";
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    78
        StringBuilder sb = new StringBuilder();
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    79
        for (int i = 0; i < 1000; i++) {
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    80
            sb.append(s);
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    81
        }
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    82
        target = sb.toString();
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    83
    }
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    84
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    85
    static void test1() {
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    86
        String str = "If this text is >" + target + "< the test passed.";
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    87
        int start = str.indexOf(target);
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    88
        int limit = start + target.length();
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    89
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    90
        AttributedString astr = new AttributedString(str);
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    91
        astr.addAttribute(TextAttribute.BIDI_EMBEDDING,
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    92
                         new Integer(-1),
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    93
                         start,
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    94
                         limit);
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    95
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    96
        Bidi bidi = new Bidi(astr.getIterator());
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    97
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    98
        byte[] embs = new byte[str.length() + 3];
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
    99
        for (int i = start + 1; i < limit + 1; ++i) {
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
   100
            embs[i] = -1;
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
   101
        }
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
   102
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
   103
        Bidi bidi2 = new Bidi(str.toCharArray(), 0, embs, 1, str.length(), Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
   104
        if (bidi.getRunCount() != 3 || bidi2.getRunCount() != 3) {
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
   105
            throw new Error("Bidi run count incorrect");
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
   106
        }
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
   107
    }
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
   108
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
   109
    static void test2() {
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
   110
        String str = "If this text is >" + target + "< the test passed.";
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
   111
        int length = str.length();
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
   112
        int start = str.indexOf(target);
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
   113
        int limit = start + target.length();
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
   114
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
   115
        AttributedString astr = new AttributedString(str);
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
   116
        astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL);
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
   117
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
   118
        astr.addAttribute(TextAttribute.BIDI_EMBEDDING,
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
   119
                         new Integer(-3),
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
   120
                         start,
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
   121
                         limit);
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
   122
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
   123
        Bidi bidi = new Bidi(astr.getIterator());
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
   124
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
   125
        if (bidi.getRunCount() != 6) { // runs of spaces and angles at embedding bound,s and final period, each get level 1
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
   126
            throw new Error("Bidi embedding processing failed");
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
   127
        }
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
   128
    }
edc39463f896 6665028: native code of method j*.text.Bidi.nativeBidiChars is using the contents of a primitive array direct
peytoia
parents:
diff changeset
   129
}