OLD | NEW |
(Empty) | |
| 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: --track-allocation-sites |
| 30 |
| 31 // Test element kind of objects. |
| 32 // Since --smi-only-arrays affects builtins, its default setting at compile |
| 33 // time sticks if built with snapshot. If --smi-only-arrays is deactivated |
| 34 // by default, only a no-snapshot build actually has smi-only arrays enabled |
| 35 // in this test case. Depending on whether smi-only arrays are actually |
| 36 // enabled, this test takes the appropriate code path to check smi-only arrays. |
| 37 |
| 38 support_smi_only_arrays = %HasFastSmiElements(new Array(1,2,3,4,5,6,7,8)); |
| 39 |
| 40 if (support_smi_only_arrays) { |
| 41 print("Tests include smi-only arrays."); |
| 42 } else { |
| 43 print("Tests do NOT include smi-only arrays."); |
| 44 } |
| 45 |
| 46 var elements_kind = { |
| 47 fast_smi_only : 'fast smi only elements', |
| 48 fast : 'fast elements', |
| 49 fast_double : 'fast double elements', |
| 50 dictionary : 'dictionary elements', |
| 51 external_byte : 'external byte elements', |
| 52 external_unsigned_byte : 'external unsigned byte elements', |
| 53 external_short : 'external short elements', |
| 54 external_unsigned_short : 'external unsigned short elements', |
| 55 external_int : 'external int elements', |
| 56 external_unsigned_int : 'external unsigned int elements', |
| 57 external_float : 'external float elements', |
| 58 external_double : 'external double elements', |
| 59 external_pixel : 'external pixel elements' |
| 60 } |
| 61 |
| 62 function getKind(obj) { |
| 63 if (%HasFastSmiElements(obj)) return elements_kind.fast_smi_only; |
| 64 if (%HasFastObjectElements(obj)) return elements_kind.fast; |
| 65 if (%HasFastDoubleElements(obj)) return elements_kind.fast_double; |
| 66 if (%HasDictionaryElements(obj)) return elements_kind.dictionary; |
| 67 } |
| 68 |
| 69 function assertKind(expected, obj, name_opt) { |
| 70 if (!support_smi_only_arrays && |
| 71 expected == elements_kind.fast_smi_only) { |
| 72 expected = elements_kind.fast; |
| 73 } |
| 74 assertEquals(expected, getKind(obj), name_opt); |
| 75 } |
| 76 |
| 77 if (support_smi_only_arrays) { |
| 78 function fastliteralcase(value) { |
| 79 var literal = [1, 2, 3]; |
| 80 literal[0] = value; |
| 81 return literal; |
| 82 } |
| 83 |
| 84 // Case: [1,2,3] as allocation site |
| 85 obj = fastliteralcase(1); |
| 86 assertKind(elements_kind.fast_smi_only, obj); |
| 87 obj = fastliteralcase(1.5); |
| 88 assertKind(elements_kind.fast_double, obj); |
| 89 obj = fastliteralcase(2); |
| 90 assertKind(elements_kind.fast_double, obj); |
| 91 |
| 92 // Verify that we will not pretransition the double->fast path. |
| 93 obj = fastliteralcase("elliot"); |
| 94 assertKind(elements_kind.fast, obj); |
| 95 |
| 96 // This fails until we turn off optimistic transitions to the |
| 97 // most general elements kind seen on keyed stores. It's a goal |
| 98 // to turn it off, but for now we need it. |
| 99 // obj = fastliteralcase(3); |
| 100 // assertKind(elements_kind.fast_double, obj); |
| 101 |
| 102 function fastliteralcase_smifast(value) { |
| 103 var literal = [1, 2, 3, 4]; |
| 104 literal[0] = value; |
| 105 return literal; |
| 106 } |
| 107 |
| 108 obj = fastliteralcase_smifast(1); |
| 109 assertKind(elements_kind.fast_smi_only, obj); |
| 110 obj = fastliteralcase_smifast("carter"); |
| 111 assertKind(elements_kind.fast, obj); |
| 112 obj = fastliteralcase_smifast(2); |
| 113 assertKind(elements_kind.fast, obj); |
| 114 } |
OLD | NEW |