|
1 /* |
|
2 * Copyright (c) 2010, 2013, 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 * JDK-8061391 - Checks that the optimistic builtin for concat is semantically |
|
26 * correct. |
|
27 * |
|
28 * @test |
|
29 * @run |
|
30 */ |
|
31 |
|
32 var maxJavaInt = 0x7fffffff; |
|
33 |
|
34 var ia = [1, 2, 3, 4]; |
|
35 var la = [maxJavaInt + 1000, maxJavaInt + 2000, maxJavaInt + 3000, maxJavaInt + 4000]; |
|
36 var da = [1.1, 2.2, 3.3, 4.4]; |
|
37 var oa = ["one", "two", "three", "four"]; |
|
38 |
|
39 var aa = [ia, la, da, oa]; |
|
40 |
|
41 function concats() { |
|
42 print("shared callsite"); |
|
43 |
|
44 print(ia); |
|
45 print(la); |
|
46 print(da); |
|
47 print(oa); |
|
48 print(aa); |
|
49 |
|
50 for (var i = 0; i < aa.length; i++) { |
|
51 print(aa[i].concat(aa[i][0])); |
|
52 for (var j = 0; j < aa.length ; j++) { |
|
53 print(aa[i].concat(aa[j])); |
|
54 } |
|
55 } |
|
56 } |
|
57 |
|
58 function concats_inline() { |
|
59 print("separate callsites"); |
|
60 |
|
61 print(ia); |
|
62 print(la); |
|
63 print(da); |
|
64 print(oa); |
|
65 print(aa); |
|
66 |
|
67 print(aa[0].concat(aa[0])); |
|
68 print(aa[0].concat(aa[1])); |
|
69 print(aa[0].concat(aa[2])); |
|
70 print(aa[0].concat(aa[3])); |
|
71 print(aa[0].concat(aa[0][0])); |
|
72 |
|
73 print(aa[1].concat(aa[0])); |
|
74 print(aa[1].concat(aa[1])); |
|
75 print(aa[1].concat(aa[2])); |
|
76 print(aa[1].concat(aa[3])); |
|
77 print(aa[1].concat(aa[1][0])); |
|
78 |
|
79 print(aa[2].concat(aa[0])); |
|
80 print(aa[2].concat(aa[1])); |
|
81 print(aa[2].concat(aa[2])); |
|
82 print(aa[2].concat(aa[3])); |
|
83 print(aa[2].concat(aa[2][0])); |
|
84 |
|
85 print(aa[3].concat(aa[0])); |
|
86 print(aa[3].concat(aa[1])); |
|
87 print(aa[3].concat(aa[2])); |
|
88 print(aa[3].concat(aa[3])); |
|
89 print(aa[3].concat(aa[3][0])); |
|
90 } |
|
91 |
|
92 concats(); |
|
93 concats_inline(); |
|
94 |
|
95 print(); |
|
96 var oldia = ia.slice(0); //clone ia |
|
97 print("oldia = " + oldia); |
|
98 ia[10] = "sparse"; |
|
99 print("oldia = " + oldia); |
|
100 |
|
101 print(); |
|
102 print("Redoing with sparse arrays"); |
|
103 |
|
104 concats(); |
|
105 concats_inline(); |
|
106 |
|
107 ia = oldia; |
|
108 print("Restored ia = " + ia); |
|
109 |
|
110 function concat_expand() { |
|
111 print("concat type expansion"); |
|
112 print(ia.concat(la)); |
|
113 print(ia.concat(da)); |
|
114 print(ia.concat(oa)); |
|
115 print(la.concat(ia)); |
|
116 print(la.concat(da)); |
|
117 print(la.concat(oa)); |
|
118 print(da.concat(ia)); |
|
119 print(da.concat(la)); |
|
120 print(da.concat(oa)); |
|
121 } |
|
122 |
|
123 print(); |
|
124 concat_expand(); |
|
125 |
|
126 print(); |
|
127 |
|
128 function concat_varargs() { |
|
129 print("concat varargs"); |
|
130 print(ia.concat(la)); //fast |
|
131 print(ia.concat(la, da, oa)); //slow |
|
132 var slow = ia.concat(1, maxJavaInt * 2, 4711.17, function() { print("hello, world") }); //slow |
|
133 print(slow); |
|
134 return slow; |
|
135 } |
|
136 |
|
137 var slow = concat_varargs(); |
|
138 |
|
139 print(); |
|
140 print("sanity checks"); |
|
141 slow.map( |
|
142 function(elem) { |
|
143 if (elem instanceof Function) { |
|
144 elem(); |
|
145 } else { |
|
146 print((typeof elem) + " = " + elem); |
|
147 } |
|
148 }); |
|
149 |
|
150 print(ia.concat({key: "value"})); |
|
151 print(ia.concat({key: "value"}, {key2: "value2"})); |