test/script/basic/JDK-8061391.js

changeset 1071
78eb2b415108
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/script/basic/JDK-8061391.js	Thu Oct 23 15:19:00 2014 +0400
     1.3 @@ -0,0 +1,151 @@
     1.4 +/*
     1.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + */
    1.26 +
    1.27 +/**
    1.28 + * JDK-8061391 - Checks that the optimistic builtin for concat is semantically
    1.29 + * correct.
    1.30 + *
    1.31 + * @test
    1.32 + * @run
    1.33 + */
    1.34 +
    1.35 +var maxJavaInt = 0x7fffffff;
    1.36 +
    1.37 +var ia = [1, 2, 3, 4];
    1.38 +var la = [maxJavaInt + 1000, maxJavaInt + 2000, maxJavaInt + 3000, maxJavaInt + 4000];
    1.39 +var da = [1.1, 2.2, 3.3, 4.4];
    1.40 +var oa = ["one", "two", "three", "four"];  
    1.41 +
    1.42 +var aa = [ia, la, da, oa];
    1.43 +
    1.44 +function concats() {
    1.45 +    print("shared callsite");
    1.46 +
    1.47 +    print(ia);
    1.48 +    print(la);
    1.49 +    print(da);
    1.50 +    print(oa);
    1.51 +    print(aa);
    1.52 +    
    1.53 +    for (var i = 0; i < aa.length; i++) {
    1.54 +	print(aa[i].concat(aa[i][0]));
    1.55 +	for (var j = 0; j < aa.length ; j++) {
    1.56 +	    print(aa[i].concat(aa[j]));
    1.57 +	}
    1.58 +    }
    1.59 +}
    1.60 +
    1.61 +function concats_inline() {
    1.62 +    print("separate callsites");
    1.63 +
    1.64 +    print(ia);
    1.65 +    print(la);
    1.66 +    print(da);
    1.67 +    print(oa);
    1.68 +    print(aa);
    1.69 +    
    1.70 +    print(aa[0].concat(aa[0]));
    1.71 +    print(aa[0].concat(aa[1]));
    1.72 +    print(aa[0].concat(aa[2]));
    1.73 +    print(aa[0].concat(aa[3]));
    1.74 +    print(aa[0].concat(aa[0][0]));    
    1.75 +
    1.76 +    print(aa[1].concat(aa[0]));
    1.77 +    print(aa[1].concat(aa[1]));
    1.78 +    print(aa[1].concat(aa[2]));
    1.79 +    print(aa[1].concat(aa[3]));
    1.80 +    print(aa[1].concat(aa[1][0]));    
    1.81 +
    1.82 +    print(aa[2].concat(aa[0]));
    1.83 +    print(aa[2].concat(aa[1]));
    1.84 +    print(aa[2].concat(aa[2]));
    1.85 +    print(aa[2].concat(aa[3]));
    1.86 +    print(aa[2].concat(aa[2][0]));    
    1.87 +
    1.88 +    print(aa[3].concat(aa[0]));
    1.89 +    print(aa[3].concat(aa[1]));
    1.90 +    print(aa[3].concat(aa[2]));
    1.91 +    print(aa[3].concat(aa[3]));
    1.92 +    print(aa[3].concat(aa[3][0]));    
    1.93 +}
    1.94 +
    1.95 +concats();
    1.96 +concats_inline();
    1.97 +
    1.98 +print();
    1.99 +var oldia = ia.slice(0); //clone ia
   1.100 +print("oldia = " + oldia);
   1.101 +ia[10] = "sparse";
   1.102 +print("oldia = " + oldia);
   1.103 +
   1.104 +print();
   1.105 +print("Redoing with sparse arrays");
   1.106 +
   1.107 +concats();
   1.108 +concats_inline();
   1.109 +
   1.110 +ia = oldia;
   1.111 +print("Restored ia = " + ia);
   1.112 +
   1.113 +function concat_expand() {
   1.114 +    print("concat type expansion");
   1.115 +    print(ia.concat(la));
   1.116 +    print(ia.concat(da));
   1.117 +    print(ia.concat(oa));
   1.118 +    print(la.concat(ia));
   1.119 +    print(la.concat(da));
   1.120 +    print(la.concat(oa));
   1.121 +    print(da.concat(ia));
   1.122 +    print(da.concat(la));
   1.123 +    print(da.concat(oa));
   1.124 +}
   1.125 +
   1.126 +print();
   1.127 +concat_expand();
   1.128 +
   1.129 +print();
   1.130 +
   1.131 +function concat_varargs() {
   1.132 +    print("concat varargs");
   1.133 +    print(ia.concat(la)); //fast
   1.134 +    print(ia.concat(la, da, oa)); //slow
   1.135 +    var slow = ia.concat(1, maxJavaInt * 2, 4711.17, function() { print("hello, world") }); //slow
   1.136 +    print(slow);
   1.137 +    return slow;
   1.138 +}
   1.139 +
   1.140 +var slow = concat_varargs();
   1.141 +
   1.142 +print();
   1.143 +print("sanity checks");
   1.144 +slow.map(
   1.145 +	 function(elem) {
   1.146 +	     if (elem instanceof Function) {
   1.147 +		 elem();
   1.148 +	     } else {
   1.149 +		 print((typeof elem) + " = " + elem);
   1.150 +	     }
   1.151 +	 });
   1.152 +
   1.153 +print(ia.concat({key: "value"}));
   1.154 +print(ia.concat({key: "value"}, {key2: "value2"}));

mercurial