OLD | NEW |
1 // Copyright 2007-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 8065 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8076 result = CompileRun("ext_array[1] = 23;" | 8076 result = CompileRun("ext_array[1] = 23;" |
8077 "ext_array.__proto__ = [];" | 8077 "ext_array.__proto__ = [];" |
8078 "js_array.__proto__ = ext_array;" | 8078 "js_array.__proto__ = ext_array;" |
8079 "js_array.concat(ext_array);"); | 8079 "js_array.concat(ext_array);"); |
8080 CHECK_EQ(77, v8::Object::Cast(*result)->Get(v8_str("0"))->Int32Value()); | 8080 CHECK_EQ(77, v8::Object::Cast(*result)->Get(v8_str("0"))->Int32Value()); |
8081 CHECK_EQ(23, v8::Object::Cast(*result)->Get(v8_str("1"))->Int32Value()); | 8081 CHECK_EQ(23, v8::Object::Cast(*result)->Get(v8_str("1"))->Int32Value()); |
8082 | 8082 |
8083 result = CompileRun("ext_array[1] = 23;"); | 8083 result = CompileRun("ext_array[1] = 23;"); |
8084 CHECK_EQ(23, result->Int32Value()); | 8084 CHECK_EQ(23, result->Int32Value()); |
8085 | 8085 |
| 8086 // Test more complex manipulations which cause eax to contain values |
| 8087 // that won't be completely overwritten by loads from the arrays. |
| 8088 // This catches bugs in the instructions used for the KeyedLoadIC |
| 8089 // for byte and word types. |
| 8090 { |
| 8091 const int kXSize = 300; |
| 8092 const int kYSize = 300; |
| 8093 const int kLargeElementCount = kXSize * kYSize * 4; |
| 8094 ElementType* large_array_data = |
| 8095 static_cast<ElementType*>(malloc(kLargeElementCount * element_size)); |
| 8096 i::Handle<ExternalArrayClass> large_array = |
| 8097 i::Handle<ExternalArrayClass>::cast( |
| 8098 i::Factory::NewExternalArray(kLargeElementCount, |
| 8099 array_type, |
| 8100 array_data)); |
| 8101 v8::Handle<v8::Object> large_obj = v8::Object::New(); |
| 8102 // Set the elements to be the external array. |
| 8103 large_obj->SetIndexedPropertiesToExternalArrayData(large_array_data, |
| 8104 array_type, |
| 8105 kLargeElementCount); |
| 8106 context->Global()->Set(v8_str("large_array"), large_obj); |
| 8107 // Initialize contents of a few rows. |
| 8108 for (int x = 0; x < 300; x++) { |
| 8109 int row = 0; |
| 8110 int offset = row * 300 * 4; |
| 8111 large_array_data[offset + 4 * x + 0] = (ElementType) 127; |
| 8112 large_array_data[offset + 4 * x + 1] = (ElementType) 0; |
| 8113 large_array_data[offset + 4 * x + 2] = (ElementType) 0; |
| 8114 large_array_data[offset + 4 * x + 3] = (ElementType) 127; |
| 8115 row = 150; |
| 8116 offset = row * 300 * 4; |
| 8117 large_array_data[offset + 4 * x + 0] = (ElementType) 127; |
| 8118 large_array_data[offset + 4 * x + 1] = (ElementType) 0; |
| 8119 large_array_data[offset + 4 * x + 2] = (ElementType) 0; |
| 8120 large_array_data[offset + 4 * x + 3] = (ElementType) 127; |
| 8121 row = 298; |
| 8122 offset = row * 300 * 4; |
| 8123 large_array_data[offset + 4 * x + 0] = (ElementType) 127; |
| 8124 large_array_data[offset + 4 * x + 1] = (ElementType) 0; |
| 8125 large_array_data[offset + 4 * x + 2] = (ElementType) 0; |
| 8126 large_array_data[offset + 4 * x + 3] = (ElementType) 127; |
| 8127 } |
| 8128 // The goal of the code below is to make "offset" large enough |
| 8129 // that the computation of the index (which goes into eax) has |
| 8130 // high bits set which will not be overwritten by a byte or short |
| 8131 // load. |
| 8132 result = CompileRun("var failed = false;" |
| 8133 "var offset = 0;" |
| 8134 "for (var i = 0; i < 300; i++) {" |
| 8135 " if (large_array[4 * i] != 127 ||" |
| 8136 " large_array[4 * i + 1] != 0 ||" |
| 8137 " large_array[4 * i + 2] != 0 ||" |
| 8138 " large_array[4 * i + 3] != 127) {" |
| 8139 " failed = true;" |
| 8140 " }" |
| 8141 "}" |
| 8142 "offset = 150 * 300 * 4;" |
| 8143 "for (var i = 0; i < 300; i++) {" |
| 8144 " if (large_array[offset + 4 * i] != 127 ||" |
| 8145 " large_array[offset + 4 * i + 1] != 0 ||" |
| 8146 " large_array[offset + 4 * i + 2] != 0 ||" |
| 8147 " large_array[offset + 4 * i + 3] != 127) {" |
| 8148 " failed = true;" |
| 8149 " }" |
| 8150 "}" |
| 8151 "offset = 298 * 300 * 4;" |
| 8152 "for (var i = 0; i < 300; i++) {" |
| 8153 " if (large_array[offset + 4 * i] != 127 ||" |
| 8154 " large_array[offset + 4 * i + 1] != 0 ||" |
| 8155 " large_array[offset + 4 * i + 2] != 0 ||" |
| 8156 " large_array[offset + 4 * i + 3] != 127) {" |
| 8157 " failed = true;" |
| 8158 " }" |
| 8159 "}" |
| 8160 "!failed;"); |
| 8161 CHECK_EQ(true, result->BooleanValue()); |
| 8162 free(large_array_data); |
| 8163 } |
| 8164 |
8086 free(array_data); | 8165 free(array_data); |
8087 } | 8166 } |
8088 | 8167 |
8089 | 8168 |
8090 THREADED_TEST(ExternalByteArray) { | 8169 THREADED_TEST(ExternalByteArray) { |
8091 ExternalArrayTestHelper<v8::internal::ExternalByteArray, int8_t>( | 8170 ExternalArrayTestHelper<v8::internal::ExternalByteArray, int8_t>( |
8092 v8::kExternalByteArray, | 8171 v8::kExternalByteArray, |
8093 -128, | 8172 -128, |
8094 127); | 8173 127); |
8095 } | 8174 } |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8512 context->Exit(); | 8591 context->Exit(); |
8513 } | 8592 } |
8514 context.Dispose(); | 8593 context.Dispose(); |
8515 for (gc_count = 1; gc_count < 10; gc_count++) { | 8594 for (gc_count = 1; gc_count < 10; gc_count++) { |
8516 v8::internal::Heap::CollectAllGarbage(false); | 8595 v8::internal::Heap::CollectAllGarbage(false); |
8517 if (GetGlobalObjectsCount() == 0) break; | 8596 if (GetGlobalObjectsCount() == 0) break; |
8518 } | 8597 } |
8519 CHECK_EQ(0, GetGlobalObjectsCount()); | 8598 CHECK_EQ(0, GetGlobalObjectsCount()); |
8520 CHECK_EQ(2, gc_count); | 8599 CHECK_EQ(2, gc_count); |
8521 } | 8600 } |
OLD | NEW |