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

Side by Side Diff: test/cctest/test-api.cc

Issue 101413006: Implement in-heap backing store for typed arrays. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Self-review Created 7 years 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 unified diff | Download patch | Annotate | Revision Log
« src/objects-printer.cc ('K') | « src/stub-cache.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 15865 matching lines...) Expand 10 before | Expand all | Expand 10 after
15876 int64_t low, int64_t high) { 15876 int64_t low, int64_t high) {
15877 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj); 15877 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj);
15878 i::Isolate* isolate = jsobj->GetIsolate(); 15878 i::Isolate* isolate = jsobj->GetIsolate();
15879 obj->Set(v8_str("field"), v8::Int32::New(1503)); 15879 obj->Set(v8_str("field"), v8::Int32::New(1503));
15880 context->Global()->Set(v8_str("ext_array"), obj); 15880 context->Global()->Set(v8_str("ext_array"), obj);
15881 v8::Handle<v8::Value> result = CompileRun("ext_array.field"); 15881 v8::Handle<v8::Value> result = CompileRun("ext_array.field");
15882 CHECK_EQ(1503, result->Int32Value()); 15882 CHECK_EQ(1503, result->Int32Value());
15883 result = CompileRun("ext_array[1]"); 15883 result = CompileRun("ext_array[1]");
15884 CHECK_EQ(1, result->Int32Value()); 15884 CHECK_EQ(1, result->Int32Value());
15885 15885
15886 // Check pass through of assigned smis
15887 result = CompileRun("var sum = 0;"
15888 "for (var i = 0; i < 8; i++) {"
15889 " sum += ext_array[i] = ext_array[i] = -i;"
15890 "}"
15891 "sum;");
15892 CHECK_EQ(-28, result->Int32Value());
15893
15894 // Check assigned smis 15886 // Check assigned smis
15895 result = CompileRun("for (var i = 0; i < 8; i++) {" 15887 result = CompileRun("for (var i = 0; i < 8; i++) {"
15896 " ext_array[i] = i;" 15888 " ext_array[i] = i;"
15897 "}" 15889 "}"
15898 "var sum = 0;" 15890 "var sum = 0;"
15899 "for (var i = 0; i < 8; i++) {" 15891 "for (var i = 0; i < 8; i++) {"
15900 " sum += ext_array[i];" 15892 " sum += ext_array[i];"
15901 "}" 15893 "}"
15902 "sum;"); 15894 "sum;");
15895
15903 CHECK_EQ(28, result->Int32Value()); 15896 CHECK_EQ(28, result->Int32Value());
15897 // Check pass through of assigned smis
15898 result = CompileRun("var sum = 0;"
15899 "for (var i = 0; i < 8; i++) {"
15900 " sum += ext_array[i] = ext_array[i] = -i;"
15901 "}"
15902 "sum;");
15903 CHECK_EQ(-28, result->Int32Value());
15904
15904 15905
15905 // Check assigned smis in reverse order 15906 // Check assigned smis in reverse order
15906 result = CompileRun("for (var i = 8; --i >= 0; ) {" 15907 result = CompileRun("for (var i = 8; --i >= 0; ) {"
15907 " ext_array[i] = i;" 15908 " ext_array[i] = i;"
15908 "}" 15909 "}"
15909 "var sum = 0;" 15910 "var sum = 0;"
15910 "for (var i = 0; i < 8; i++) {" 15911 "for (var i = 0; i < 8; i++) {"
15911 " sum += ext_array[i];" 15912 " sum += ext_array[i];"
15912 "}" 15913 "}"
15913 "sum;"); 15914 "sum;");
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
16161 "js_array.__proto__ = ext_array;" 16162 "js_array.__proto__ = ext_array;"
16162 "js_array.concat(ext_array);"); 16163 "js_array.concat(ext_array);");
16163 CHECK_EQ(77, v8::Object::Cast(*result)->Get(v8_str("0"))->Int32Value()); 16164 CHECK_EQ(77, v8::Object::Cast(*result)->Get(v8_str("0"))->Int32Value());
16164 CHECK_EQ(23, v8::Object::Cast(*result)->Get(v8_str("1"))->Int32Value()); 16165 CHECK_EQ(23, v8::Object::Cast(*result)->Get(v8_str("1"))->Int32Value());
16165 16166
16166 result = CompileRun("ext_array[1] = 23;"); 16167 result = CompileRun("ext_array[1] = 23;");
16167 CHECK_EQ(23, result->Int32Value()); 16168 CHECK_EQ(23, result->Int32Value());
16168 } 16169 }
16169 16170
16170 16171
16172 template <class FixedTypedArrayClass,
16173 i::ElementsKind elements_kind,
16174 class ElementType>
16175 static void FixedTypedArrayTestHelper(
16176 v8::ExternalArrayType array_type,
16177 ElementType low,
16178 ElementType high) {
16179 LocalContext context;
16180 i::Isolate* isolate = CcTest::i_isolate();
16181 i::Factory* factory = isolate->factory();
16182 v8::HandleScope scope(context->GetIsolate());
16183 const int kElementCount = 260;
16184 i::Handle<FixedTypedArrayClass> fixed_array =
16185 i::Handle<FixedTypedArrayClass>::cast(
16186 factory->NewFixedTypedArray(kElementCount,
Toon Verwaest 2013/12/23 10:40:32 Join lines
Dmitry Lomov (no reviews) 2014/01/07 15:48:43 Done.
16187 array_type));
16188 CHECK_EQ(FixedTypedArrayClass::kInstanceType,
16189 fixed_array->map()->instance_type());
16190 CHECK_EQ(kElementCount, fixed_array->length());
16191 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
16192 for (int i = 0; i < kElementCount; i++) {
16193 fixed_array->set(i, static_cast<ElementType>(i));
16194 }
Toon Verwaest 2013/12/23 10:40:32 From what I can tell, out-of-bounds accesses are t
Dmitry Lomov (no reviews) 2014/01/07 15:48:43 Yes. 'set' just asserts on OOB On 2013/12/23 10:40
16195 // Force GC to trigger verification.
16196 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
16197 for (int i = 0; i < kElementCount; i++) {
16198 CHECK_EQ(static_cast<int64_t>(static_cast<ElementType>(i)),
16199 static_cast<int64_t>(fixed_array->get_scalar(i)));
16200 }
16201 v8::Handle<v8::Object> obj = v8::Object::New();
16202 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj);
16203 i::Handle<i::Map> fixed_array_map =
16204 isolate->factory()->GetElementsTransitionMap(
16205 jsobj,
Toon Verwaest 2013/12/23 10:40:32 join lines
Dmitry Lomov (no reviews) 2014/01/07 15:48:43 Done.
16206 elements_kind);
16207 jsobj->set_map(*fixed_array_map);
16208 jsobj->set_elements(*fixed_array);
16209
16210 ObjectWithExternalArrayTestHelper<FixedTypedArrayClass, ElementType>(
16211 context.local(),
Toon Verwaest 2013/12/23 10:40:32 Don't all these arguments fit on a single line?
Dmitry Lomov (no reviews) 2014/01/07 15:48:43 Done.
16212 obj,
16213 kElementCount,
16214 array_type,
16215 low, high);
16216 }
16217
16218
16219 THREADED_TEST(FixedUint8Array) {
16220 FixedTypedArrayTestHelper<i::FixedUint8Array, i::UINT8_ELEMENTS, uint8_t>(
16221 v8::kExternalUnsignedByteArray,
16222 0x0, 0xFF);
16223 }
16224
16225
16226 THREADED_TEST(FixedUint8ClampedArray) {
16227 FixedTypedArrayTestHelper<i::FixedUint8ClampedArray,
16228 i::UINT8_CLAMPED_ELEMENTS, uint8_t>(
16229 v8::kExternalPixelArray,
16230 0x0, 0xFF);
16231 }
16232
16233
16234 THREADED_TEST(FixedInt8Array) {
16235 FixedTypedArrayTestHelper<i::FixedInt8Array, i::INT8_ELEMENTS, int8_t>(
16236 v8::kExternalByteArray,
16237 -0x80, 0x7F);
16238 }
16239
16240
16241 THREADED_TEST(FixedUint16Array) {
16242 FixedTypedArrayTestHelper<i::FixedUint16Array, i::UINT16_ELEMENTS, uint16_t>(
16243 v8::kExternalUnsignedShortArray,
16244 0x0, 0xFFFF);
16245 }
16246
16247
16248 THREADED_TEST(FixedInt16Array) {
16249 FixedTypedArrayTestHelper<i::FixedInt16Array, i::INT16_ELEMENTS, int16_t>(
16250 v8::kExternalShortArray,
16251 -0x8000, 0x7FFF);
16252 }
16253
16254
16255 THREADED_TEST(FixedUint32Array) {
16256 FixedTypedArrayTestHelper<i::FixedUint32Array, i::UINT32_ELEMENTS, uint32_t>(
16257 v8::kExternalUnsignedIntArray,
16258 0x0, 0xFFFFFFFF);
16259 }
16260
16261
16262 THREADED_TEST(FixedInt32Array) {
16263 FixedTypedArrayTestHelper<i::FixedInt32Array, i::INT32_ELEMENTS, int32_t>(
16264 v8::kExternalIntArray,
16265 -0x80000000, 0x7FFFFFFF);
16266 }
16267
16268
16269 THREADED_TEST(FixedFloat32Array) {
16270 FixedTypedArrayTestHelper<i::FixedFloat32Array, i::FLOAT32_ELEMENTS, float>(
16271 v8::kExternalFloatArray,
16272 -500, 500);
16273 }
16274
16275
16276 THREADED_TEST(FixedFloat64Array) {
16277 FixedTypedArrayTestHelper<i::FixedFloat64Array, i::FLOAT64_ELEMENTS, float>(
16278 v8::kExternalDoubleArray,
16279 -500, 500);
16280 }
16281
16282
16171 template <class ExternalArrayClass, class ElementType> 16283 template <class ExternalArrayClass, class ElementType>
16172 static void ExternalArrayTestHelper(v8::ExternalArrayType array_type, 16284 static void ExternalArrayTestHelper(v8::ExternalArrayType array_type,
16173 int64_t low, 16285 int64_t low,
16174 int64_t high) { 16286 int64_t high) {
16175 LocalContext context; 16287 LocalContext context;
16176 i::Isolate* isolate = CcTest::i_isolate(); 16288 i::Isolate* isolate = CcTest::i_isolate();
16177 i::Factory* factory = isolate->factory(); 16289 i::Factory* factory = isolate->factory();
16178 v8::HandleScope scope(context->GetIsolate()); 16290 v8::HandleScope scope(context->GetIsolate());
16179 const int kElementCount = 40; 16291 const int kElementCount = 40;
16180 int element_size = ExternalArrayElementSize(array_type); 16292 int element_size = ExternalArrayElementSize(array_type);
(...skipping 4894 matching lines...) Expand 10 before | Expand all | Expand 10 after
21075 } 21187 }
21076 for (int i = 0; i < runs; i++) { 21188 for (int i = 0; i < runs; i++) {
21077 Local<String> expected; 21189 Local<String> expected;
21078 if (i != 0) { 21190 if (i != 0) {
21079 CHECK_EQ(v8_str("escape value"), values[i]); 21191 CHECK_EQ(v8_str("escape value"), values[i]);
21080 } else { 21192 } else {
21081 CHECK(values[i].IsEmpty()); 21193 CHECK(values[i].IsEmpty());
21082 } 21194 }
21083 } 21195 }
21084 } 21196 }
OLDNEW
« src/objects-printer.cc ('K') | « src/stub-cache.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698