1 /*
2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @bug 4221795 8032446
27 * @summary Confirm that java.text.Normalizer and sun.text.Normalize are
28 * thread-safe.
29 * @modules java.base/sun.text java.base/sun.text.normalizer
30 * @compile -XDignore.symbol.file ThreadSafeTest.java
31 * @run main/othervm -esa ThreadSafeTest 5 10
32 */
33
34 // Usage: java ThreadSafeTest [threadsFactor [duration]]
35 public class ThreadSafeTest {
36
37 static volatile boolean runrun = true;
38 static volatile boolean error = false;
39
40 public static void main(String[] args) throws Exception {
41 int threadsFactor = 5;
42 if (args.length > 0) {
43 threadsFactor = Math.max(Integer.parseInt(args[0]), 5);
44 }
45 int duration = 180;
46 if (args.length > 1) {
47 duration = Math.max(5, Integer.parseInt(args[1]));
48 }
49 int nProcessors = Runtime.getRuntime().availableProcessors();
98 }
99 }
100
101 static void testIsNormalized(int num, java.text.Normalizer.Form form) {
102 boolean normalized = java.text.Normalizer.isNormalized(data[num][1], form);
103 if (!normalized) {
104 System.err.println("java.text.Normalizer.isNormalized(" +
105 form.toString() + ") failed.");
106 error = true;
107 }
108 }
109
110 static class Worker implements Runnable {
111 public void run() {
112 while (runrun) {
113 testJavaNormalize(0, java.text.Normalizer.Form.NFKC);
114 testSunNormalize(1, java.text.Normalizer.Form.NFC,
115 sun.text.Normalizer.UNICODE_3_2);
116 testJavaNormalize(2, java.text.Normalizer.Form.NFKD);
117 testSunNormalize(3, java.text.Normalizer.Form.NFC,
118 sun.text.normalizer.NormalizerBase.UNICODE_LATEST);
119 testJavaNormalize(4, java.text.Normalizer.Form.NFD);
120
121 testIsNormalized(0, java.text.Normalizer.Form.NFKC);
122 testIsNormalized(2, java.text.Normalizer.Form.NFKD);
123 testIsNormalized(4, java.text.Normalizer.Form.NFD);
124
125 if (error) {
126 runrun = false;
127 return;
128 }
129 }
130 }
131 }
132
133 static final String[][] data = {
134 /* From: To: */
135 {"A\u0300\u0316", "\u00C0\u0316"},
136 {"\u0071\u0307\u0323\u0072", "\u0071\u0323\u0307\u0072"},
137 {"\u0f77", "\u0fb2\u0f71\u0f80"},
138 {"D\u0307\u0328\u0323", "\u1e0c\u0328\u0307"},
|
1 /*
2 * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @bug 4221795 8032446 8174270
27 * @summary Confirm that java.text.Normalizer and sun.text.Normalizer are
28 * thread-safe.
29 * @modules java.base/sun.text java.base/jdk.internal.icu.text
30 * @compile -XDignore.symbol.file ThreadSafeTest.java
31 * @run main/othervm -esa ThreadSafeTest 5 10
32 */
33
34 // Usage: java ThreadSafeTest [threadsFactor [duration]]
35 public class ThreadSafeTest {
36
37 static volatile boolean runrun = true;
38 static volatile boolean error = false;
39
40 public static void main(String[] args) throws Exception {
41 int threadsFactor = 5;
42 if (args.length > 0) {
43 threadsFactor = Math.max(Integer.parseInt(args[0]), 5);
44 }
45 int duration = 180;
46 if (args.length > 1) {
47 duration = Math.max(5, Integer.parseInt(args[1]));
48 }
49 int nProcessors = Runtime.getRuntime().availableProcessors();
98 }
99 }
100
101 static void testIsNormalized(int num, java.text.Normalizer.Form form) {
102 boolean normalized = java.text.Normalizer.isNormalized(data[num][1], form);
103 if (!normalized) {
104 System.err.println("java.text.Normalizer.isNormalized(" +
105 form.toString() + ") failed.");
106 error = true;
107 }
108 }
109
110 static class Worker implements Runnable {
111 public void run() {
112 while (runrun) {
113 testJavaNormalize(0, java.text.Normalizer.Form.NFKC);
114 testSunNormalize(1, java.text.Normalizer.Form.NFC,
115 sun.text.Normalizer.UNICODE_3_2);
116 testJavaNormalize(2, java.text.Normalizer.Form.NFKD);
117 testSunNormalize(3, java.text.Normalizer.Form.NFC,
118 jdk.internal.icu.text.NormalizerBase.UNICODE_LATEST);
119 testJavaNormalize(4, java.text.Normalizer.Form.NFD);
120
121 testIsNormalized(0, java.text.Normalizer.Form.NFKC);
122 testIsNormalized(2, java.text.Normalizer.Form.NFKD);
123 testIsNormalized(4, java.text.Normalizer.Form.NFD);
124
125 if (error) {
126 runrun = false;
127 return;
128 }
129 }
130 }
131 }
132
133 static final String[][] data = {
134 /* From: To: */
135 {"A\u0300\u0316", "\u00C0\u0316"},
136 {"\u0071\u0307\u0323\u0072", "\u0071\u0323\u0307\u0072"},
137 {"\u0f77", "\u0fb2\u0f71\u0f80"},
138 {"D\u0307\u0328\u0323", "\u1e0c\u0328\u0307"},
|