The data contained in this repository can be downloaded to your computer using one of several clients.
Please see the documentation of your version control software client for more information.

Please select the desired protocol below to get the URL.

This URL has Read-Only access.

Statistics
| Branch: | Revision:

main_repo / deps / v8 / test / mjsunit / osr-elements-kind.js @ f230a1cf

History | View | Annotate | Download (6.16 KB)

1
// Copyright 2012 the V8 project authors. All rights reserved.
2
// Redistribution and use in source and binary forms, with or without
3
// modification, are permitted provided that the following conditions are
4
// met:
5
//
6
//     * Redistributions of source code must retain the above copyright
7
//       notice, this list of conditions and the following disclaimer.
8
//     * Redistributions in binary form must reproduce the above
9
//       copyright notice, this list of conditions and the following
10
//       disclaimer in the documentation and/or other materials provided
11
//       with the distribution.
12
//     * Neither the name of Google Inc. nor the names of its
13
//       contributors may be used to endorse or promote products derived
14
//       from this software without specific prior written permission.
15
//
16
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27

    
28
// Flags: --allow-natives-syntax --smi-only-arrays --expose-gc
29
// Flags: --notrack_allocation_sites
30

    
31
// Limit the number of stress runs to reduce polymorphism it defeats some of the
32
// assumptions made about how elements transitions work because transition stubs
33
// end up going generic.
34
// Flags: --stress-runs=2
35

    
36
// Test element kind of objects.
37
// Since --smi-only-arrays affects builtins, its default setting at compile
38
// time sticks if built with snapshot.  If --smi-only-arrays is deactivated
39
// by default, only a no-snapshot build actually has smi-only arrays enabled
40
// in this test case.  Depending on whether smi-only arrays are actually
41
// enabled, this test takes the appropriate code path to check smi-only arrays.
42

    
43
// Reset the GC stress mode to be off. Needed because AllocationMementos only
44
// live for one gc, so a gc that happens in certain fragile areas of the test
45
// can break assumptions.
46
%SetFlags("--gc-interval=-1")
47

    
48
support_smi_only_arrays = %HasFastSmiElements(new Array(1,2,3,4,5,6,7,8));
49

    
50
if (support_smi_only_arrays) {
51
  print("Tests include smi-only arrays.");
52
} else {
53
  print("Tests do NOT include smi-only arrays.");
54
}
55

    
56
var elements_kind = {
57
  fast_smi_only            :  'fast smi only elements',
58
  fast                     :  'fast elements',
59
  fast_double              :  'fast double elements',
60
  dictionary               :  'dictionary elements',
61
  external_byte            :  'external byte elements',
62
  external_unsigned_byte   :  'external unsigned byte elements',
63
  external_short           :  'external short elements',
64
  external_unsigned_short  :  'external unsigned short elements',
65
  external_int             :  'external int elements',
66
  external_unsigned_int    :  'external unsigned int elements',
67
  external_float           :  'external float elements',
68
  external_double          :  'external double elements',
69
  external_pixel           :  'external pixel elements'
70
}
71

    
72
function getKind(obj) {
73
  if (%HasFastSmiElements(obj)) return elements_kind.fast_smi_only;
74
  if (%HasFastObjectElements(obj)) return elements_kind.fast;
75
  if (%HasFastDoubleElements(obj)) return elements_kind.fast_double;
76
  if (%HasDictionaryElements(obj)) return elements_kind.dictionary;
77
  // Every external kind is also an external array.
78
  assertTrue(%HasExternalArrayElements(obj));
79
  if (%HasExternalByteElements(obj)) {
80
    return elements_kind.external_byte;
81
  }
82
  if (%HasExternalUnsignedByteElements(obj)) {
83
    return elements_kind.external_unsigned_byte;
84
  }
85
  if (%HasExternalShortElements(obj)) {
86
    return elements_kind.external_short;
87
  }
88
  if (%HasExternalUnsignedShortElements(obj)) {
89
    return elements_kind.external_unsigned_short;
90
  }
91
  if (%HasExternalIntElements(obj)) {
92
    return elements_kind.external_int;
93
  }
94
  if (%HasExternalUnsignedIntElements(obj)) {
95
    return elements_kind.external_unsigned_int;
96
  }
97
  if (%HasExternalFloatElements(obj)) {
98
    return elements_kind.external_float;
99
  }
100
  if (%HasExternalDoubleElements(obj)) {
101
    return elements_kind.external_double;
102
  }
103
  if (%HasExternalPixelElements(obj)) {
104
    return elements_kind.external_pixel;
105
  }
106
}
107

    
108
function assertKind(expected, obj, name_opt) {
109
  if (!support_smi_only_arrays &&
110
      expected == elements_kind.fast_smi_only) {
111
    expected = elements_kind.fast;
112
  }
113
  assertEquals(expected, getKind(obj), name_opt);
114
}
115

    
116
// long-running loop forces OSR.
117
%NeverOptimizeFunction(construct_smis);
118
%NeverOptimizeFunction(construct_doubles);
119
%NeverOptimizeFunction(convert_mixed);
120
for (var i = 0; i < 1000000; i++) { }
121

    
122
if (support_smi_only_arrays) {
123
  function construct_smis() {
124
    var a = [0, 0, 0];
125
    a[0] = 0;  // Send the COW array map to the steak house.
126
    assertKind(elements_kind.fast_smi_only, a);
127
    return a;
128
  }
129
  function construct_doubles() {
130
    var a = construct_smis();
131
    a[0] = 1.5;
132
    assertKind(elements_kind.fast_double, a);
133
    return a;
134
  }
135

    
136
  // Test transition chain SMI->DOUBLE->FAST (crankshafted function will
137
  // transition to FAST directly).
138
  function convert_mixed(array, value, kind) {
139
    array[1] = value;
140
    assertKind(kind, array);
141
    assertEquals(value, array[1]);
142
  }
143
  smis = construct_smis();
144
  convert_mixed(smis, 1.5, elements_kind.fast_double);
145

    
146
  doubles = construct_doubles();
147
  convert_mixed(doubles, "three", elements_kind.fast);
148

    
149
  convert_mixed(construct_smis(), "three", elements_kind.fast);
150
  convert_mixed(construct_doubles(), "three", elements_kind.fast);
151

    
152
  smis = construct_smis();
153
  doubles = construct_doubles();
154
  convert_mixed(smis, 1, elements_kind.fast);
155
  convert_mixed(doubles, 1, elements_kind.fast);
156
  assertTrue(%HaveSameMap(smis, doubles));
157
}
158

    
159
// Throw away type information in the ICs for next stress run.
160
gc();