Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(987)

Unified Diff: test/mjsunit/elements-kind.js

Issue 8241003: Elements kind conversion in generated code (ia32). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Applied suggested changes. Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/mjsunit/element-kind.js ('k') | test/mjsunit/elements-transition.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/elements-kind.js
diff --git a/test/mjsunit/element-kind.js b/test/mjsunit/elements-kind.js
similarity index 50%
rename from test/mjsunit/element-kind.js
rename to test/mjsunit/elements-kind.js
index 46fd8f567d48f536661a2df63a5bdae3393dca74..0ae2e692f430dfad1697b05a1665a9c52f41a559 100644
--- a/test/mjsunit/element-kind.js
+++ b/test/mjsunit/elements-kind.js
@@ -25,7 +25,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Flags: --allow-natives-syntax --smi-only-arrays
+// Flags: --allow-natives-syntax --smi-only-arrays --expose-gc
+
// Test element kind of objects.
// Since --smi-only-arrays affects builtins, its default setting at compile
// time sticks if built with snapshot. If --smi-only-arrays is deactivated
@@ -33,7 +34,6 @@
// in this test case. Depending on whether smi-only arrays are actually
// enabled, this test takes the appropriate code path to check smi-only arrays.
-
support_smi_only_arrays = %HasFastSmiOnlyElements([]);
if (support_smi_only_arrays) {
@@ -42,108 +42,113 @@ if (support_smi_only_arrays) {
print("Tests do NOT include smi-only arrays.");
}
-var element_kind = {
- fast_smi_only_elements : 0,
- fast_elements : 1,
- fast_double_elements : 2,
- dictionary_elements : 3,
- external_byte_elements : 4,
- external_unsigned_byte_elements : 5,
- external_short_elements : 6,
- external_unsigned_short_elements : 7,
- external_int_elements : 8,
- external_unsigned_int_elements : 9,
- external_float_elements : 10,
- external_double_elements : 11,
- external_pixel_elements : 12
+var elements_kind = {
+ fast_smi_only : 'fast smi only elements',
+ fast : 'fast elements',
+ fast_double : 'fast double elements',
+ dictionary : 'dictionary elements',
+ external_byte : 'external byte elements',
+ external_unsigned_byte : 'external unsigned byte elements',
+ external_short : 'external short elements',
+ external_unsigned_short : 'external unsigned short elements',
+ external_int : 'external int elements',
+ external_unsigned_int : 'external unsigned int elements',
+ external_float : 'external float elements',
+ external_double : 'external double elements',
+ external_pixel : 'external pixel elements'
}
-// We expect an object to only be of one element kind.
-function assertKind(expected, obj) {
- if (support_smi_only_arrays) {
- assertEquals(expected == element_kind.fast_smi_only_elements,
- %HasFastSmiOnlyElements(obj));
- assertEquals(expected == element_kind.fast_elements,
- %HasFastElements(obj));
- } else {
- assertEquals(expected == element_kind.fast_elements ||
- expected == element_kind.fast_smi_only_elements,
- %HasFastElements(obj));
+function getKind(obj) {
+ if (%HasFastSmiOnlyElements(obj)) return elements_kind.fast_smi_only;
+ if (%HasFastElements(obj)) return elements_kind.fast;
+ if (%HasFastDoubleElements(obj)) return elements_kind.fast_double;
+ if (%HasDictionaryElements(obj)) return elements_kind.dictionary;
+ // Every external kind is also an external array.
+ assertTrue(%HasExternalArrayElements(obj));
+ if (%HasExternalByteElements(obj)) {
+ return elements_kind.external_byte;
+ }
+ if (%HasExternalUnsignedByteElements(obj)) {
+ return elements_kind.external_unsigned_byte;
+ }
+ if (%HasExternalShortElements(obj)) {
+ return elements_kind.external_short;
+ }
+ if (%HasExternalUnsignedShortElements(obj)) {
+ return elements_kind.external_unsigned_short;
+ }
+ if (%HasExternalIntElements(obj)) {
+ return elements_kind.external_int;
+ }
+ if (%HasExternalUnsignedIntElements(obj)) {
+ return elements_kind.external_unsigned_int;
+ }
+ if (%HasExternalFloatElements(obj)) {
+ return elements_kind.external_float;
+ }
+ if (%HasExternalDoubleElements(obj)) {
+ return elements_kind.external_double;
+ }
+ if (%HasExternalPixelElements(obj)) {
+ return elements_kind.external_pixel;
}
- assertEquals(expected == element_kind.fast_double_elements,
- %HasFastDoubleElements(obj));
- assertEquals(expected == element_kind.dictionary_elements,
- %HasDictionaryElements(obj));
- assertEquals(expected == element_kind.external_byte_elements,
- %HasExternalByteElements(obj));
- assertEquals(expected == element_kind.external_unsigned_byte_elements,
- %HasExternalUnsignedByteElements(obj));
- assertEquals(expected == element_kind.external_short_elements,
- %HasExternalShortElements(obj));
- assertEquals(expected == element_kind.external_unsigned_short_elements,
- %HasExternalUnsignedShortElements(obj));
- assertEquals(expected == element_kind.external_int_elements,
- %HasExternalIntElements(obj));
- assertEquals(expected == element_kind.external_unsigned_int_elements,
- %HasExternalUnsignedIntElements(obj));
- assertEquals(expected == element_kind.external_float_elements,
- %HasExternalFloatElements(obj));
- assertEquals(expected == element_kind.external_double_elements,
- %HasExternalDoubleElements(obj));
- assertEquals(expected == element_kind.external_pixel_elements,
- %HasExternalPixelElements(obj));
- // every external kind is also an external array
- assertEquals(expected >= element_kind.external_byte_elements,
- %HasExternalArrayElements(obj));
+}
+
+function assertKind(expected, obj, name_opt) {
+ if (!support_smi_only_arrays &&
+ expected == elements_kind.fast_smi_only) {
+ expected = elements_kind.fast;
+ }
+ assertEquals(expected, getKind(obj), name_opt);
}
var me = {};
-assertKind(element_kind.fast_elements, me);
+assertKind(elements_kind.fast, me);
me.dance = 0xD15C0;
me.drink = 0xC0C0A;
-assertKind(element_kind.fast_elements, me);
+assertKind(elements_kind.fast, me);
var too = [1,2,3];
-assertKind(element_kind.fast_smi_only_elements, too);
+assertKind(elements_kind.fast_smi_only, too);
too.dance = 0xD15C0;
too.drink = 0xC0C0A;
-assertKind(element_kind.fast_smi_only_elements, too);
+assertKind(elements_kind.fast_smi_only, too);
// Make sure the element kind transitions from smionly when a non-smi is stored.
var you = new Array();
-assertKind(element_kind.fast_smi_only_elements, you);
+assertKind(elements_kind.fast_smi_only, you);
for (var i = 0; i < 1337; i++) {
var val = i;
if (i == 1336) {
- assertKind(element_kind.fast_smi_only_elements, you);
+ assertKind(elements_kind.fast_smi_only, you);
val = new Object();
}
you[i] = val;
}
-assertKind(element_kind.fast_elements, you);
+assertKind(elements_kind.fast, you);
-assertKind(element_kind.dictionary_elements, new Array(0xDECAF));
+assertKind(elements_kind.dictionary, new Array(0xDECAF));
var fast_double_array = new Array(0xDECAF);
for (var i = 0; i < 0xDECAF; i++) fast_double_array[i] = i / 2;
-assertKind(element_kind.fast_double_elements, fast_double_array);
+assertKind(elements_kind.fast_double, fast_double_array);
-assertKind(element_kind.external_byte_elements, new Int8Array(9001));
-assertKind(element_kind.external_unsigned_byte_elements, new Uint8Array(007));
-assertKind(element_kind.external_short_elements, new Int16Array(666));
-assertKind(element_kind.external_unsigned_short_elements, new Uint16Array(42));
-assertKind(element_kind.external_int_elements, new Int32Array(0xF));
-assertKind(element_kind.external_unsigned_int_elements, new Uint32Array(23));
-assertKind(element_kind.external_float_elements, new Float32Array(7));
-assertKind(element_kind.external_double_elements, new Float64Array(0));
-assertKind(element_kind.external_pixel_elements, new PixelArray(512));
+assertKind(elements_kind.external_byte, new Int8Array(9001));
+assertKind(elements_kind.external_unsigned_byte, new Uint8Array(007));
+assertKind(elements_kind.external_short, new Int16Array(666));
+assertKind(elements_kind.external_unsigned_short, new Uint16Array(42));
+assertKind(elements_kind.external_int, new Int32Array(0xF));
+assertKind(elements_kind.external_unsigned_int, new Uint32Array(23));
+assertKind(elements_kind.external_float, new Float32Array(7));
+assertKind(elements_kind.external_double, new Float64Array(0));
+assertKind(elements_kind.external_pixel, new PixelArray(512));
// Crankshaft support for smi-only array elements.
function monomorphic(array) {
for (var i = 0; i < 3; i++) {
array[i] = i + 10;
}
- assertKind(element_kind.fast_smi_only_elements, array);
+ assertKind(elements_kind.fast_smi_only, array);
for (var i = 0; i < 3; i++) {
var a = array[i];
assertEquals(i + 10, a);
@@ -160,42 +165,46 @@ function polymorphic(array, expected_kind) {
assertEquals(42, a);
}
var smis = [1, 2, 3];
-var strings = ["one", "two", "three"];
-var doubles = [0, 0, 0]; doubles[0] = 1.5; doubles[1] = 2.5; doubles[2] = 3.5;
+var strings = [0, 0, 0]; strings[0] = "one";
+var doubles = [0, 0, 0]; doubles[0] = 1.5;
assertKind(support_smi_only_arrays
- ? element_kind.fast_double_elements
- : element_kind.fast_elements,
+ ? elements_kind.fast_double
+ : elements_kind.fast,
doubles);
for (var i = 0; i < 3; i++) {
- polymorphic(smis, element_kind.fast_smi_only_elements);
- polymorphic(strings, element_kind.fast_elements);
- polymorphic(doubles, support_smi_only_arrays
- ? element_kind.fast_double_elements
- : element_kind.fast_elements);
+ polymorphic(smis, elements_kind.fast_smi_only);
+}
+for (var i = 0; i < 3; i++) {
+ polymorphic(strings, elements_kind.fast);
+}
+for (var i = 0; i < 3; i++) {
+ polymorphic(doubles, i == 0 && support_smi_only_arrays
+ ? elements_kind.fast_double
+ : elements_kind.fast);
}
+
+/* Element transitions have not been implemented in crankshaft yet.
%OptimizeFunctionOnNextCall(polymorphic);
-polymorphic(smis, element_kind.fast_smi_only_elements);
-polymorphic(strings, element_kind.fast_elements);
-polymorphic(doubles, support_smi_only_arrays
- ? element_kind.fast_double_elements
- : element_kind.fast_elements);
+polymorphic(smis, elements_kind.fast_smi_only);
+polymorphic(strings, elements_kind.fast);
+polymorphic(doubles, elements_kind.fast);
// Crankshaft support for smi-only elements in dynamic array literals.
function get(foo) { return foo; } // Used to generate dynamic values.
function crankshaft_test() {
var a = [get(1), get(2), get(3)];
- assertKind(element_kind.fast_smi_only_elements, a);
+ assertKind(elements_kind.fast_smi_only, a);
var b = [get(1), get(2), get("three")];
- assertKind(element_kind.fast_elements, b);
+ assertKind(elements_kind.fast, b);
var c = [get(1), get(2), get(3.5)];
- // The full code generator doesn't support conversion to fast_double_elements
+ // The full code generator doesn't support conversion to fast_double
// yet. Crankshaft does, but only with --smi-only-arrays support.
if ((%GetOptimizationStatus(crankshaft_test) & 1) &&
support_smi_only_arrays) {
- assertKind(element_kind.fast_double_elements, c);
+ assertKind(elements_kind.fast_double, c);
} else {
- assertKind(element_kind.fast_elements, c);
+ assertKind(elements_kind.fast, c);
}
}
for (var i = 0; i < 3; i++) {
@@ -203,6 +212,7 @@ for (var i = 0; i < 3; i++) {
}
%OptimizeFunctionOnNextCall(crankshaft_test);
crankshaft_test();
+*/
// Elements_kind transitions for arrays.
@@ -216,14 +226,14 @@ if (support_smi_only_arrays) {
var a = [1, 2, 3];
var b = [1, 2, 3];
assertTrue(%HaveSameMap(a, b));
- assertKind(element_kind.fast_smi_only_elements, a);
+ assertKind(elements_kind.fast_smi_only, a);
var c = [1, 2, 3];
c["case2"] = true;
var d = [1, 2, 3];
d["case2"] = true;
assertTrue(%HaveSameMap(c, d));
assertFalse(%HaveSameMap(a, c));
- assertKind(element_kind.fast_smi_only_elements, c);
+ assertKind(elements_kind.fast_smi_only, c);
var e = [1, 2, 3];
e["case3"] = true;
var f = [1, 2, 3];
@@ -231,31 +241,34 @@ if (support_smi_only_arrays) {
assertTrue(%HaveSameMap(e, f));
assertFalse(%HaveSameMap(a, e));
assertFalse(%HaveSameMap(c, e));
- assertKind(element_kind.fast_smi_only_elements, e);
+ assertKind(elements_kind.fast_smi_only, e);
// Case 1: SMI->DOUBLE, DOUBLE->OBJECT, SMI->OBJECT.
a[0] = 1.5;
- assertKind(element_kind.fast_double_elements, a);
+ assertKind(elements_kind.fast_double, a);
a[0] = "foo";
- assertKind(element_kind.fast_elements, a);
+ assertKind(elements_kind.fast, a);
b[0] = "bar";
assertTrue(%HaveSameMap(a, b));
// Case 2: SMI->DOUBLE, SMI->OBJECT, DOUBLE->OBJECT.
c[0] = 1.5;
- assertKind(element_kind.fast_double_elements, c);
+ assertKind(elements_kind.fast_double, c);
assertFalse(%HaveSameMap(c, d));
d[0] = "foo";
- assertKind(element_kind.fast_elements, d);
+ assertKind(elements_kind.fast, d);
assertFalse(%HaveSameMap(c, d));
c[0] = "bar";
assertTrue(%HaveSameMap(c, d));
// Case 3: SMI->OBJECT, SMI->DOUBLE, DOUBLE->OBJECT.
e[0] = "foo";
- assertKind(element_kind.fast_elements, e);
+ assertKind(elements_kind.fast, e);
assertFalse(%HaveSameMap(e, f));
f[0] = 1.5;
- assertKind(element_kind.fast_double_elements, f);
+ assertKind(elements_kind.fast_double, f);
assertFalse(%HaveSameMap(e, f));
f[0] = "bar";
- assertKind(element_kind.fast_elements, f);
+ assertKind(elements_kind.fast, f);
assertTrue(%HaveSameMap(e, f));
}
+
+// Throw away type information in the ICs for next stress run.
+gc();
« no previous file with comments | « test/mjsunit/element-kind.js ('k') | test/mjsunit/elements-transition.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698