test/compiler/6942326/Test.java

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 /**
aoqi@0 26 * @test
aoqi@0 27 * @bug 6942326
aoqi@0 28 * @summary x86 code in string_indexof() could read beyond reserved heap space
aoqi@0 29 *
aoqi@0 30 * @run main/othervm/timeout=300 -Xmx32m -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:CompileCommand=exclude,Test,main -XX:CompileCommand=exclude,Test,test_varsub_indexof -XX:CompileCommand=exclude,Test,test_varstr_indexof -XX:CompileCommand=exclude,Test,test_missub_indexof -XX:CompileCommand=exclude,Test,test_consub_indexof -XX:CompileCommand=exclude,Test,test_conmis_indexof -XX:CompileCommand=exclude,Test,test_subcon Test
aoqi@0 31 *
aoqi@0 32 */
aoqi@0 33
aoqi@0 34 public class Test {
aoqi@0 35
aoqi@0 36 static String[] strings = new String[1024];
aoqi@0 37 private static final int ITERATIONS = 100000;
aoqi@0 38
aoqi@0 39 public static void main(String[] args) {
aoqi@0 40
aoqi@0 41 long start_total = System.currentTimeMillis();
aoqi@0 42
aoqi@0 43 // search variable size substring in string (33 chars).
aoqi@0 44 String a = " 1111111111111xx1111111111111xx11y"; // +1 to execute a.substring(1) first
aoqi@0 45 String b = "1111111111111xx1111111111111xx11y";
aoqi@0 46 test_varsub_indexof(a, b);
aoqi@0 47
aoqi@0 48 // search variable size substring in string (32 chars).
aoqi@0 49 a = " 1111111111111xx1111111111111xx1y";
aoqi@0 50 b = "1111111111111xx1111111111111xx1y";
aoqi@0 51 test_varsub_indexof(a, b);
aoqi@0 52
aoqi@0 53 // search variable size substring in string (17 chars).
aoqi@0 54 a = " 1111111111111xx1y";
aoqi@0 55 b = "1111111111111xx1y";
aoqi@0 56 test_varsub_indexof(a, b);
aoqi@0 57
aoqi@0 58 // search variable size substring in string (16 chars).
aoqi@0 59 a = " 111111111111xx1y";
aoqi@0 60 b = "111111111111xx1y";
aoqi@0 61 test_varsub_indexof(a, b);
aoqi@0 62
aoqi@0 63 // search variable size substring in string (8 chars).
aoqi@0 64 a = " 1111xx1y";
aoqi@0 65 b = "1111xx1y";
aoqi@0 66 test_varsub_indexof(a, b);
aoqi@0 67
aoqi@0 68 // search variable size substring in string (7 chars).
aoqi@0 69 a = " 111xx1y";
aoqi@0 70 b = "111xx1y";
aoqi@0 71 test_varsub_indexof(a, b);
aoqi@0 72
aoqi@0 73
aoqi@0 74
aoqi@0 75 // search substring (17 chars) in variable size string.
aoqi@0 76 a = "1111111111111xx1x";
aoqi@0 77 b = " 1111111111111xx1111111111111xx1x"; // +1 to execute b.substring(1) first
aoqi@0 78 test_varstr_indexof(a, b);
aoqi@0 79
aoqi@0 80 // search substring (16 chars) in variable size string.
aoqi@0 81 a = "111111111111xx1x";
aoqi@0 82 b = " 1111111111111xx1111111111111xx1x";
aoqi@0 83 test_varstr_indexof(a, b);
aoqi@0 84
aoqi@0 85 // search substring (9 chars) in variable size string.
aoqi@0 86 a = "11111xx1x";
aoqi@0 87 b = " 1111111111111xx1111111111111xx1x";
aoqi@0 88 test_varstr_indexof(a, b);
aoqi@0 89
aoqi@0 90 // search substring (8 chars) in variable size string.
aoqi@0 91 a = "1111xx1x";
aoqi@0 92 b = " 1111111111111xx1111111111111xx1x";
aoqi@0 93 test_varstr_indexof(a, b);
aoqi@0 94
aoqi@0 95 // search substring (4 chars) in variable size string.
aoqi@0 96 a = "xx1x";
aoqi@0 97 b = " 1111111111111xx1111111111111xx1x";
aoqi@0 98 test_varstr_indexof(a, b);
aoqi@0 99
aoqi@0 100 // search substring (3 chars) in variable size string.
aoqi@0 101 a = "x1x";
aoqi@0 102 b = " 1111111111111xx1111111111111xx1x";
aoqi@0 103 test_varstr_indexof(a, b);
aoqi@0 104
aoqi@0 105 // search substring (2 chars) in variable size string.
aoqi@0 106 a = "1y";
aoqi@0 107 b = " 1111111111111xx1111111111111xx1y";
aoqi@0 108 test_varstr_indexof(a, b);
aoqi@0 109
aoqi@0 110
aoqi@0 111
aoqi@0 112 // search non matching variable size substring in string (33 chars).
aoqi@0 113 a = " 1111111111111xx1111111111111xx11z"; // +1 to execute a.substring(1) first
aoqi@0 114 b = "1111111111111xx1111111111111xx11y";
aoqi@0 115 test_missub_indexof(a, b);
aoqi@0 116
aoqi@0 117 // search non matching variable size substring in string (32 chars).
aoqi@0 118 a = " 1111111111111xx1111111111111xx1z";
aoqi@0 119 b = "1111111111111xx1111111111111xx1y";
aoqi@0 120 test_missub_indexof(a, b);
aoqi@0 121
aoqi@0 122 // search non matching variable size substring in string (17 chars).
aoqi@0 123 a = " 1111111111111xx1z";
aoqi@0 124 b = "1111111111111xx1y";
aoqi@0 125 test_missub_indexof(a, b);
aoqi@0 126
aoqi@0 127 // search non matching variable size substring in string (16 chars).
aoqi@0 128 a = " 111111111111xx1z";
aoqi@0 129 b = "111111111111xx1y";
aoqi@0 130 test_missub_indexof(a, b);
aoqi@0 131
aoqi@0 132 // search non matching variable size substring in string (8 chars).
aoqi@0 133 a = " 1111xx1z";
aoqi@0 134 b = "1111xx1y";
aoqi@0 135 test_missub_indexof(a, b);
aoqi@0 136
aoqi@0 137 // search non matching variable size substring in string (7 chars).
aoqi@0 138 a = " 111xx1z";
aoqi@0 139 b = "111xx1y";
aoqi@0 140 test_missub_indexof(a, b);
aoqi@0 141
aoqi@0 142
aoqi@0 143
aoqi@0 144 // Testing constant substring search in variable size string.
aoqi@0 145
aoqi@0 146 // search constant substring (17 chars).
aoqi@0 147 b = " 1111111111111xx1111111111111xx1x"; // +1 to execute b.substring(1) first
aoqi@0 148 TestCon tc = new TestCon17();
aoqi@0 149 test_consub_indexof(tc, b);
aoqi@0 150
aoqi@0 151 // search constant substring (16 chars).
aoqi@0 152 b = " 1111111111111xx1111111111111xx1x";
aoqi@0 153 tc = new TestCon16();
aoqi@0 154 test_consub_indexof(tc, b);
aoqi@0 155
aoqi@0 156 // search constant substring (9 chars).
aoqi@0 157 b = " 1111111111111xx1111111111111xx1x";
aoqi@0 158 tc = new TestCon9();
aoqi@0 159 test_consub_indexof(tc, b);
aoqi@0 160
aoqi@0 161 // search constant substring (8 chars).
aoqi@0 162 b = " 1111111111111xx1111111111111xx1x";
aoqi@0 163 tc = new TestCon8();
aoqi@0 164 test_consub_indexof(tc, b);
aoqi@0 165
aoqi@0 166 // search constant substring (4 chars).
aoqi@0 167 b = " 1111111111111xx1111111111111xx1x";
aoqi@0 168 tc = new TestCon4();
aoqi@0 169 test_consub_indexof(tc, b);
aoqi@0 170
aoqi@0 171 // search constant substring (3 chars).
aoqi@0 172 b = " 1111111111111xx1111111111111xx1x";
aoqi@0 173 tc = new TestCon3();
aoqi@0 174 test_consub_indexof(tc, b);
aoqi@0 175
aoqi@0 176 // search constant substring (2 chars).
aoqi@0 177 b = " 1111111111111xx1111111111111xx1y";
aoqi@0 178 tc = new TestCon2();
aoqi@0 179 test_consub_indexof(tc, b);
aoqi@0 180
aoqi@0 181 // search constant substring (1 chars).
aoqi@0 182 b = " 1111111111111xx1111111111111xx1y";
aoqi@0 183 tc = new TestCon1();
aoqi@0 184 test_consub_indexof(tc, b);
aoqi@0 185
aoqi@0 186
aoqi@0 187 // search non matching constant substring (17 chars).
aoqi@0 188 b = " 1111111111111xx1111111111111xx1z"; // +1 to execute b.substring(1) first
aoqi@0 189 tc = new TestCon17();
aoqi@0 190 test_conmis_indexof(tc, b);
aoqi@0 191
aoqi@0 192 // search non matching constant substring (16 chars).
aoqi@0 193 b = " 1111111111111xx1111111111111xx1z";
aoqi@0 194 tc = new TestCon16();
aoqi@0 195 test_conmis_indexof(tc, b);
aoqi@0 196
aoqi@0 197 // search non matching constant substring (9 chars).
aoqi@0 198 b = " 1111111111111xx1111111111111xx1z";
aoqi@0 199 tc = new TestCon9();
aoqi@0 200 test_conmis_indexof(tc, b);
aoqi@0 201
aoqi@0 202 // search non matching constant substring (8 chars).
aoqi@0 203 b = " 1111111111111xx1111111111111xx1z";
aoqi@0 204 tc = new TestCon8();
aoqi@0 205 test_conmis_indexof(tc, b);
aoqi@0 206
aoqi@0 207 // search non matching constant substring (4 chars).
aoqi@0 208 b = " 1111111111111xx1111111111111xx1z";
aoqi@0 209 tc = new TestCon4();
aoqi@0 210 test_conmis_indexof(tc, b);
aoqi@0 211
aoqi@0 212 // search non matching constant substring (3 chars).
aoqi@0 213 b = " 1111111111111xx1111111111111xx1z";
aoqi@0 214 tc = new TestCon3();
aoqi@0 215 test_conmis_indexof(tc, b);
aoqi@0 216
aoqi@0 217 // search non matching constant substring (2 chars).
aoqi@0 218 b = " 1111111111111xx1111111111111xx1z";
aoqi@0 219 tc = new TestCon2();
aoqi@0 220 test_conmis_indexof(tc, b);
aoqi@0 221
aoqi@0 222 // search non matching constant substring (1 chars).
aoqi@0 223 b = " 1111111111111xx1111111111111xx1z";
aoqi@0 224 tc = new TestCon1();
aoqi@0 225 test_conmis_indexof(tc, b);
aoqi@0 226
aoqi@0 227 long end_total = System.currentTimeMillis();
aoqi@0 228 System.out.println("End run time: " + (end_total - start_total));
aoqi@0 229
aoqi@0 230 }
aoqi@0 231
aoqi@0 232 public static long test_init(String a, String b) {
aoqi@0 233 for (int i = 0; i < 512; i++) {
aoqi@0 234 strings[i * 2] = new String(b.toCharArray());
aoqi@0 235 strings[i * 2 + 1] = new String(a.toCharArray());
aoqi@0 236 }
aoqi@0 237 System.out.print(a.length() + " " + b.length() + " ");
aoqi@0 238 return System.currentTimeMillis();
aoqi@0 239 }
aoqi@0 240
aoqi@0 241 public static void test_end(String a, String b, int v, int expected, long start) {
aoqi@0 242 long end = System.currentTimeMillis();
aoqi@0 243 int res = (v/ITERATIONS);
aoqi@0 244 System.out.print(" " + res);
aoqi@0 245 System.out.println(" time:" + (end - start));
aoqi@0 246 if (res != expected) {
aoqi@0 247 System.out.println("wrong indexOf result: " + res + ", expected " + expected);
aoqi@0 248 System.out.println("\"" + b + "\".indexOf(\"" + a + "\")");
aoqi@0 249 System.exit(97);
aoqi@0 250 }
aoqi@0 251 }
aoqi@0 252
aoqi@0 253 public static int test_subvar() {
aoqi@0 254 int s = 0;
aoqi@0 255 int v = 0;
aoqi@0 256 for (int i = 0; i < ITERATIONS; i++) {
aoqi@0 257 v += strings[s].indexOf(strings[s + 1]);
aoqi@0 258 s += 2;
aoqi@0 259 if (s >= strings.length) s = 0;
aoqi@0 260 }
aoqi@0 261 return v;
aoqi@0 262 }
aoqi@0 263
aoqi@0 264 public static void test_varsub_indexof(String a, String b) {
aoqi@0 265 System.out.println("Start search variable size substring in string (" + b.length() + " chars)");
aoqi@0 266 long start_it = System.currentTimeMillis();
aoqi@0 267 int limit = 1; // last a.length() == 1
aoqi@0 268 while (a.length() > limit) {
aoqi@0 269 a = a.substring(1);
aoqi@0 270 long start = test_init(a, b);
aoqi@0 271 int v = test_subvar();
aoqi@0 272 test_end(a, b, v, (b.length() - a.length()), start);
aoqi@0 273 }
aoqi@0 274 long end_it = System.currentTimeMillis();
aoqi@0 275 System.out.println("End search variable size substring in string (" + b.length() + " chars), time: " + (end_it - start_it));
aoqi@0 276 }
aoqi@0 277
aoqi@0 278 public static void test_varstr_indexof(String a, String b) {
aoqi@0 279 System.out.println("Start search substring (" + a.length() + " chars) in variable size string");
aoqi@0 280 long start_it = System.currentTimeMillis();
aoqi@0 281 int limit = a.length();
aoqi@0 282 while (b.length() > limit) {
aoqi@0 283 b = b.substring(1);
aoqi@0 284 long start = test_init(a, b);
aoqi@0 285 int v = test_subvar();
aoqi@0 286 test_end(a, b, v, (b.length() - a.length()), start);
aoqi@0 287 }
aoqi@0 288 long end_it = System.currentTimeMillis();
aoqi@0 289 System.out.println("End search substring (" + a.length() + " chars) in variable size string, time: " + (end_it - start_it));
aoqi@0 290 }
aoqi@0 291
aoqi@0 292 public static void test_missub_indexof(String a, String b) {
aoqi@0 293 System.out.println("Start search non matching variable size substring in string (" + b.length() + " chars)");
aoqi@0 294 long start_it = System.currentTimeMillis();
aoqi@0 295 int limit = 1; // last a.length() == 1
aoqi@0 296 while (a.length() > limit) {
aoqi@0 297 a = a.substring(1);
aoqi@0 298 long start = test_init(a, b);
aoqi@0 299 int v = test_subvar();
aoqi@0 300 test_end(a, b, v, (-1), start);
aoqi@0 301 }
aoqi@0 302 long end_it = System.currentTimeMillis();
aoqi@0 303 System.out.println("End search non matching variable size substring in string (" + b.length() + " chars), time: " + (end_it - start_it));
aoqi@0 304 }
aoqi@0 305
aoqi@0 306
aoqi@0 307
aoqi@0 308 public static void test_consub_indexof(TestCon tc, String b) {
aoqi@0 309 System.out.println("Start search constant substring (" + tc.constr().length() + " chars)");
aoqi@0 310 long start_it = System.currentTimeMillis();
aoqi@0 311 int limit = tc.constr().length();
aoqi@0 312 while (b.length() > limit) {
aoqi@0 313 b = b.substring(1);
aoqi@0 314 long start = test_init(tc.constr(), b);
aoqi@0 315 int v = test_subcon(tc);
aoqi@0 316 test_end(tc.constr(), b, v, (b.length() - tc.constr().length()), start);
aoqi@0 317 }
aoqi@0 318 long end_it = System.currentTimeMillis();
aoqi@0 319 System.out.println("End search constant substring (" + tc.constr().length() + " chars), time: " + (end_it - start_it));
aoqi@0 320 }
aoqi@0 321
aoqi@0 322 public static void test_conmis_indexof(TestCon tc, String b) {
aoqi@0 323 System.out.println("Start search non matching constant substring (" + tc.constr().length() + " chars)");
aoqi@0 324 long start_it = System.currentTimeMillis();
aoqi@0 325 int limit = tc.constr().length();
aoqi@0 326 while (b.length() > limit) {
aoqi@0 327 b = b.substring(1);
aoqi@0 328 long start = test_init(tc.constr(), b);
aoqi@0 329 int v = test_subcon(tc);
aoqi@0 330 test_end(tc.constr(), b, v, (-1), start);
aoqi@0 331 }
aoqi@0 332 long end_it = System.currentTimeMillis();
aoqi@0 333 System.out.println("End search non matching constant substring (" + tc.constr().length() + " chars), time: " + (end_it - start_it));
aoqi@0 334 }
aoqi@0 335
aoqi@0 336 public static int test_subcon(TestCon tc) {
aoqi@0 337 int s = 0;
aoqi@0 338 int v = 0;
aoqi@0 339 for (int i = 0; i < ITERATIONS; i++) {
aoqi@0 340 v += tc.indexOf(strings[s]);
aoqi@0 341 s += 2;
aoqi@0 342 if (s >= strings.length) s = 0;
aoqi@0 343 }
aoqi@0 344 return v;
aoqi@0 345 }
aoqi@0 346
aoqi@0 347 private interface TestCon {
aoqi@0 348 public String constr();
aoqi@0 349 public int indexOf(String str);
aoqi@0 350 }
aoqi@0 351
aoqi@0 352 // search constant substring (17 chars).
aoqi@0 353 private final static class TestCon17 implements TestCon {
aoqi@0 354 private static final String constr = "1111111111111xx1x";
aoqi@0 355 public String constr() { return constr; }
aoqi@0 356 public int indexOf(String str) { return str.indexOf(constr); }
aoqi@0 357 }
aoqi@0 358
aoqi@0 359 // search constant substring (16 chars).
aoqi@0 360 private final static class TestCon16 implements TestCon {
aoqi@0 361 private static final String constr = "111111111111xx1x";
aoqi@0 362 public String constr() { return constr; }
aoqi@0 363 public int indexOf(String str) { return str.indexOf(constr); }
aoqi@0 364 }
aoqi@0 365
aoqi@0 366 // search constant substring (9 chars).
aoqi@0 367 private final static class TestCon9 implements TestCon {
aoqi@0 368 private static final String constr = "11111xx1x";
aoqi@0 369 public String constr() { return constr; }
aoqi@0 370 public int indexOf(String str) { return str.indexOf(constr); }
aoqi@0 371 }
aoqi@0 372
aoqi@0 373 // search constant substring (8 chars).
aoqi@0 374 private final static class TestCon8 implements TestCon {
aoqi@0 375 private static final String constr = "1111xx1x";
aoqi@0 376 public String constr() { return constr; }
aoqi@0 377 public int indexOf(String str) { return str.indexOf(constr); }
aoqi@0 378 }
aoqi@0 379
aoqi@0 380 // search constant substring (4 chars).
aoqi@0 381 private final static class TestCon4 implements TestCon {
aoqi@0 382 private static final String constr = "xx1x";
aoqi@0 383 public String constr() { return constr; }
aoqi@0 384 public int indexOf(String str) { return str.indexOf(constr); }
aoqi@0 385 }
aoqi@0 386
aoqi@0 387 // search constant substring (3 chars).
aoqi@0 388 private final static class TestCon3 implements TestCon {
aoqi@0 389 private static final String constr = "x1x";
aoqi@0 390 public String constr() { return constr; }
aoqi@0 391 public int indexOf(String str) { return str.indexOf(constr); }
aoqi@0 392 }
aoqi@0 393
aoqi@0 394 // search constant substring (2 chars).
aoqi@0 395 private final static class TestCon2 implements TestCon {
aoqi@0 396 private static final String constr = "1y";
aoqi@0 397 public String constr() { return constr; }
aoqi@0 398 public int indexOf(String str) { return str.indexOf(constr); }
aoqi@0 399 }
aoqi@0 400
aoqi@0 401
aoqi@0 402 // search constant substring (1 chars).
aoqi@0 403 private final static class TestCon1 implements TestCon {
aoqi@0 404 private static final String constr = "y";
aoqi@0 405 public String constr() { return constr; }
aoqi@0 406 public int indexOf(String str) { return str.indexOf(constr); }
aoqi@0 407 }
aoqi@0 408 }
aoqi@0 409

mercurial