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

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

Issue 559913002: Rename ascii to one-byte where applicable. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 3 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 unified diff | Download patch | Annotate | Revision Log
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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 value = factory->NewNumberFromUint(static_cast<uint32_t>(1) << 31); 178 value = factory->NewNumberFromUint(static_cast<uint32_t>(1) << 31);
179 CHECK(value->IsHeapNumber()); 179 CHECK(value->IsHeapNumber());
180 CHECK(value->IsNumber()); 180 CHECK(value->IsNumber());
181 CHECK_EQ(static_cast<double>(static_cast<uint32_t>(1) << 31), 181 CHECK_EQ(static_cast<double>(static_cast<uint32_t>(1) << 31),
182 value->Number()); 182 value->Number());
183 183
184 // nan oddball checks 184 // nan oddball checks
185 CHECK(factory->nan_value()->IsNumber()); 185 CHECK(factory->nan_value()->IsNumber());
186 CHECK(std::isnan(factory->nan_value()->Number())); 186 CHECK(std::isnan(factory->nan_value()->Number()));
187 187
188 Handle<String> s = factory->NewStringFromStaticAscii("fisk hest "); 188 Handle<String> s = factory->NewStringFromStaticChars("fisk hest ");
189 CHECK(s->IsString()); 189 CHECK(s->IsString());
190 CHECK_EQ(10, s->length()); 190 CHECK_EQ(10, s->length());
191 191
192 Handle<String> object_string = Handle<String>::cast(factory->Object_string()); 192 Handle<String> object_string = Handle<String>::cast(factory->Object_string());
193 Handle<GlobalObject> global(CcTest::i_isolate()->context()->global_object()); 193 Handle<GlobalObject> global(CcTest::i_isolate()->context()->global_object());
194 v8::Maybe<bool> maybe = JSReceiver::HasOwnProperty(global, object_string); 194 v8::Maybe<bool> maybe = JSReceiver::HasOwnProperty(global, object_string);
195 CHECK(maybe.has_value); 195 CHECK(maybe.has_value);
196 CHECK(maybe.value); 196 CHECK(maybe.value);
197 197
198 // Check ToString for oddballs 198 // Check ToString for oddballs
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 GlobalHandles* global_handles = isolate->global_handles(); 334 GlobalHandles* global_handles = isolate->global_handles();
335 335
336 Handle<Object> h1; 336 Handle<Object> h1;
337 Handle<Object> h2; 337 Handle<Object> h2;
338 Handle<Object> h3; 338 Handle<Object> h3;
339 Handle<Object> h4; 339 Handle<Object> h4;
340 340
341 { 341 {
342 HandleScope scope(isolate); 342 HandleScope scope(isolate);
343 343
344 Handle<Object> i = factory->NewStringFromStaticAscii("fisk"); 344 Handle<Object> i = factory->NewStringFromStaticChars("fisk");
345 Handle<Object> u = factory->NewNumber(1.12344); 345 Handle<Object> u = factory->NewNumber(1.12344);
346 346
347 h1 = global_handles->Create(*i); 347 h1 = global_handles->Create(*i);
348 h2 = global_handles->Create(*u); 348 h2 = global_handles->Create(*u);
349 h3 = global_handles->Create(*i); 349 h3 = global_handles->Create(*i);
350 h4 = global_handles->Create(*u); 350 h4 = global_handles->Create(*u);
351 } 351 }
352 352
353 // after gc, it should survive 353 // after gc, it should survive
354 heap->CollectGarbage(NEW_SPACE); 354 heap->CollectGarbage(NEW_SPACE);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 GlobalHandles* global_handles = isolate->global_handles(); 389 GlobalHandles* global_handles = isolate->global_handles();
390 390
391 WeakPointerCleared = false; 391 WeakPointerCleared = false;
392 392
393 Handle<Object> h1; 393 Handle<Object> h1;
394 Handle<Object> h2; 394 Handle<Object> h2;
395 395
396 { 396 {
397 HandleScope scope(isolate); 397 HandleScope scope(isolate);
398 398
399 Handle<Object> i = factory->NewStringFromStaticAscii("fisk"); 399 Handle<Object> i = factory->NewStringFromStaticChars("fisk");
400 Handle<Object> u = factory->NewNumber(1.12344); 400 Handle<Object> u = factory->NewNumber(1.12344);
401 401
402 h1 = global_handles->Create(*i); 402 h1 = global_handles->Create(*i);
403 h2 = global_handles->Create(*u); 403 h2 = global_handles->Create(*u);
404 } 404 }
405 405
406 std::pair<Handle<Object>*, int> handle_and_id(&h2, 1234); 406 std::pair<Handle<Object>*, int> handle_and_id(&h2, 1234);
407 GlobalHandles::MakeWeak(h2.location(), 407 GlobalHandles::MakeWeak(h2.location(),
408 reinterpret_cast<void*>(&handle_and_id), 408 reinterpret_cast<void*>(&handle_and_id),
409 &TestWeakGlobalHandleCallback); 409 &TestWeakGlobalHandleCallback);
(...skipping 21 matching lines...) Expand all
431 GlobalHandles* global_handles = isolate->global_handles(); 431 GlobalHandles* global_handles = isolate->global_handles();
432 432
433 WeakPointerCleared = false; 433 WeakPointerCleared = false;
434 434
435 Handle<Object> h1; 435 Handle<Object> h1;
436 Handle<Object> h2; 436 Handle<Object> h2;
437 437
438 { 438 {
439 HandleScope scope(isolate); 439 HandleScope scope(isolate);
440 440
441 Handle<Object> i = factory->NewStringFromStaticAscii("fisk"); 441 Handle<Object> i = factory->NewStringFromStaticChars("fisk");
442 Handle<Object> u = factory->NewNumber(1.12344); 442 Handle<Object> u = factory->NewNumber(1.12344);
443 443
444 h1 = global_handles->Create(*i); 444 h1 = global_handles->Create(*i);
445 h2 = global_handles->Create(*u); 445 h2 = global_handles->Create(*u);
446 } 446 }
447 447
448 // Make sure the objects are promoted. 448 // Make sure the objects are promoted.
449 heap->CollectGarbage(OLD_POINTER_SPACE); 449 heap->CollectGarbage(OLD_POINTER_SPACE);
450 heap->CollectGarbage(NEW_SPACE); 450 heap->CollectGarbage(NEW_SPACE);
451 CHECK(!heap->InNewSpace(*h1) && !heap->InNewSpace(*h2)); 451 CHECK(!heap->InNewSpace(*h1) && !heap->InNewSpace(*h2));
(...skipping 25 matching lines...) Expand all
477 Factory* factory = isolate->factory(); 477 Factory* factory = isolate->factory();
478 GlobalHandles* global_handles = isolate->global_handles(); 478 GlobalHandles* global_handles = isolate->global_handles();
479 479
480 WeakPointerCleared = false; 480 WeakPointerCleared = false;
481 481
482 Handle<Object> h; 482 Handle<Object> h;
483 483
484 { 484 {
485 HandleScope scope(isolate); 485 HandleScope scope(isolate);
486 486
487 Handle<Object> i = factory->NewStringFromStaticAscii("fisk"); 487 Handle<Object> i = factory->NewStringFromStaticChars("fisk");
488 h = global_handles->Create(*i); 488 h = global_handles->Create(*i);
489 } 489 }
490 490
491 std::pair<Handle<Object>*, int> handle_and_id(&h, 1234); 491 std::pair<Handle<Object>*, int> handle_and_id(&h, 1234);
492 GlobalHandles::MakeWeak(h.location(), 492 GlobalHandles::MakeWeak(h.location(),
493 reinterpret_cast<void*>(&handle_and_id), 493 reinterpret_cast<void*>(&handle_and_id),
494 &TestWeakGlobalHandleCallback); 494 &TestWeakGlobalHandleCallback);
495 495
496 // Scanvenge does not recognize weak reference. 496 // Scanvenge does not recognize weak reference.
497 heap->CollectGarbage(NEW_SPACE); 497 heap->CollectGarbage(NEW_SPACE);
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
863 863
864 864
865 TEST(StringAllocation) { 865 TEST(StringAllocation) {
866 CcTest::InitializeVM(); 866 CcTest::InitializeVM();
867 Isolate* isolate = CcTest::i_isolate(); 867 Isolate* isolate = CcTest::i_isolate();
868 Factory* factory = isolate->factory(); 868 Factory* factory = isolate->factory();
869 869
870 const unsigned char chars[] = { 0xe5, 0xa4, 0xa7 }; 870 const unsigned char chars[] = { 0xe5, 0xa4, 0xa7 };
871 for (int length = 0; length < 100; length++) { 871 for (int length = 0; length < 100; length++) {
872 v8::HandleScope scope(CcTest::isolate()); 872 v8::HandleScope scope(CcTest::isolate());
873 char* non_ascii = NewArray<char>(3 * length + 1); 873 char* non_one_byte = NewArray<char>(3 * length + 1);
874 char* ascii = NewArray<char>(length + 1); 874 char* one_byte = NewArray<char>(length + 1);
875 non_ascii[3 * length] = 0; 875 non_one_byte[3 * length] = 0;
876 ascii[length] = 0; 876 one_byte[length] = 0;
877 for (int i = 0; i < length; i++) { 877 for (int i = 0; i < length; i++) {
878 ascii[i] = 'a'; 878 one_byte[i] = 'a';
879 non_ascii[3 * i] = chars[0]; 879 non_one_byte[3 * i] = chars[0];
880 non_ascii[3 * i + 1] = chars[1]; 880 non_one_byte[3 * i + 1] = chars[1];
881 non_ascii[3 * i + 2] = chars[2]; 881 non_one_byte[3 * i + 2] = chars[2];
882 } 882 }
883 Handle<String> non_ascii_sym = 883 Handle<String> non_one_byte_sym = factory->InternalizeUtf8String(
884 factory->InternalizeUtf8String( 884 Vector<const char>(non_one_byte, 3 * length));
885 Vector<const char>(non_ascii, 3 * length)); 885 CHECK_EQ(length, non_one_byte_sym->length());
886 CHECK_EQ(length, non_ascii_sym->length()); 886 Handle<String> one_byte_sym =
887 Handle<String> ascii_sym = 887 factory->InternalizeOneByteString(OneByteVector(one_byte, length));
888 factory->InternalizeOneByteString(OneByteVector(ascii, length)); 888 CHECK_EQ(length, one_byte_sym->length());
889 CHECK_EQ(length, ascii_sym->length()); 889 Handle<String> non_one_byte_str =
890 Handle<String> non_ascii_str = factory->NewStringFromUtf8( 890 factory->NewStringFromUtf8(Vector<const char>(non_one_byte, 3 * length))
891 Vector<const char>(non_ascii, 3 * length)).ToHandleChecked(); 891 .ToHandleChecked();
892 non_ascii_str->Hash(); 892 non_one_byte_str->Hash();
893 CHECK_EQ(length, non_ascii_str->length()); 893 CHECK_EQ(length, non_one_byte_str->length());
894 Handle<String> ascii_str = factory->NewStringFromUtf8( 894 Handle<String> one_byte_str =
895 Vector<const char>(ascii, length)).ToHandleChecked(); 895 factory->NewStringFromUtf8(Vector<const char>(one_byte, length))
896 ascii_str->Hash(); 896 .ToHandleChecked();
897 CHECK_EQ(length, ascii_str->length()); 897 one_byte_str->Hash();
898 DeleteArray(non_ascii); 898 CHECK_EQ(length, one_byte_str->length());
899 DeleteArray(ascii); 899 DeleteArray(non_one_byte);
900 DeleteArray(one_byte);
900 } 901 }
901 } 902 }
902 903
903 904
904 static int ObjectsFoundInHeap(Heap* heap, Handle<Object> objs[], int size) { 905 static int ObjectsFoundInHeap(Heap* heap, Handle<Object> objs[], int size) {
905 // Count the number of objects found in the heap. 906 // Count the number of objects found in the heap.
906 int found_count = 0; 907 int found_count = 0;
907 HeapIterator iterator(heap); 908 HeapIterator iterator(heap);
908 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { 909 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) {
909 for (int i = 0; i < size; i++) { 910 for (int i = 0; i < size; i++) {
(...skipping 17 matching lines...) Expand all
927 Handle<Object> objs[objs_count]; 928 Handle<Object> objs[objs_count];
928 int next_objs_index = 0; 929 int next_objs_index = 0;
929 930
930 // Allocate a JS array to OLD_POINTER_SPACE and NEW_SPACE 931 // Allocate a JS array to OLD_POINTER_SPACE and NEW_SPACE
931 objs[next_objs_index++] = factory->NewJSArray(10); 932 objs[next_objs_index++] = factory->NewJSArray(10);
932 objs[next_objs_index++] = factory->NewJSArray(10, 933 objs[next_objs_index++] = factory->NewJSArray(10,
933 FAST_HOLEY_ELEMENTS, 934 FAST_HOLEY_ELEMENTS,
934 TENURED); 935 TENURED);
935 936
936 // Allocate a small string to OLD_DATA_SPACE and NEW_SPACE 937 // Allocate a small string to OLD_DATA_SPACE and NEW_SPACE
938 objs[next_objs_index++] = factory->NewStringFromStaticChars("abcdefghij");
937 objs[next_objs_index++] = 939 objs[next_objs_index++] =
938 factory->NewStringFromStaticAscii("abcdefghij"); 940 factory->NewStringFromStaticChars("abcdefghij", TENURED);
939 objs[next_objs_index++] =
940 factory->NewStringFromStaticAscii("abcdefghij", TENURED);
941 941
942 // Allocate a large string (for large object space). 942 // Allocate a large string (for large object space).
943 int large_size = Page::kMaxRegularHeapObjectSize + 1; 943 int large_size = Page::kMaxRegularHeapObjectSize + 1;
944 char* str = new char[large_size]; 944 char* str = new char[large_size];
945 for (int i = 0; i < large_size - 1; ++i) str[i] = 'a'; 945 for (int i = 0; i < large_size - 1; ++i) str[i] = 'a';
946 str[large_size - 1] = '\0'; 946 str[large_size - 1] = '\0';
947 objs[next_objs_index++] = factory->NewStringFromAsciiChecked(str, TENURED); 947 objs[next_objs_index++] = factory->NewStringFromAsciiChecked(str, TENURED);
948 delete[] str; 948 delete[] str;
949 949
950 // Add a Map object to look for. 950 // Add a Map object to look for.
(...skipping 2317 matching lines...) Expand 10 before | Expand all | Expand 10 after
3268 // Fire context dispose notification. 3268 // Fire context dispose notification.
3269 CcTest::isolate()->ContextDisposedNotification(); 3269 CcTest::isolate()->ContextDisposedNotification();
3270 SimulateIncrementalMarking(CcTest::heap()); 3270 SimulateIncrementalMarking(CcTest::heap());
3271 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); 3271 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
3272 3272
3273 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); 3273 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC);
3274 CHECK(IC::IsCleared(ic_after)); 3274 CHECK(IC::IsCleared(ic_after));
3275 } 3275 }
3276 3276
3277 3277
3278 class SourceResource: public v8::String::ExternalAsciiStringResource { 3278 class SourceResource : public v8::String::ExternalOneByteStringResource {
3279 public: 3279 public:
3280 explicit SourceResource(const char* data) 3280 explicit SourceResource(const char* data)
3281 : data_(data), length_(strlen(data)) { } 3281 : data_(data), length_(strlen(data)) { }
3282 3282
3283 virtual void Dispose() { 3283 virtual void Dispose() {
3284 i::DeleteArray(data_); 3284 i::DeleteArray(data_);
3285 data_ = NULL; 3285 data_ = NULL;
3286 } 3286 }
3287 3287
3288 const char* data() const { return data_; } 3288 const char* data() const { return data_; }
(...skipping 1138 matching lines...) Expand 10 before | Expand all | Expand 10 after
4427 TEST(Regress388880) { 4427 TEST(Regress388880) {
4428 i::FLAG_expose_gc = true; 4428 i::FLAG_expose_gc = true;
4429 CcTest::InitializeVM(); 4429 CcTest::InitializeVM();
4430 v8::HandleScope scope(CcTest::isolate()); 4430 v8::HandleScope scope(CcTest::isolate());
4431 Isolate* isolate = CcTest::i_isolate(); 4431 Isolate* isolate = CcTest::i_isolate();
4432 Factory* factory = isolate->factory(); 4432 Factory* factory = isolate->factory();
4433 Heap* heap = isolate->heap(); 4433 Heap* heap = isolate->heap();
4434 4434
4435 Handle<Map> map1 = Map::Create(isolate->object_function(), 1); 4435 Handle<Map> map1 = Map::Create(isolate->object_function(), 1);
4436 Handle<Map> map2 = 4436 Handle<Map> map2 =
4437 Map::CopyWithField(map1, factory->NewStringFromStaticAscii("foo"), 4437 Map::CopyWithField(map1, factory->NewStringFromStaticChars("foo"),
4438 HeapType::Any(isolate), NONE, Representation::Tagged(), 4438 HeapType::Any(isolate), NONE, Representation::Tagged(),
4439 OMIT_TRANSITION).ToHandleChecked(); 4439 OMIT_TRANSITION).ToHandleChecked();
4440 4440
4441 int desired_offset = Page::kPageSize - map1->instance_size(); 4441 int desired_offset = Page::kPageSize - map1->instance_size();
4442 4442
4443 // Allocate fixed array in old pointer space so, that object allocated 4443 // Allocate fixed array in old pointer space so, that object allocated
4444 // afterwards would end at the end of the page. 4444 // afterwards would end at the end of the page.
4445 { 4445 {
4446 SimulateFullSpace(heap->old_pointer_space()); 4446 SimulateFullSpace(heap->old_pointer_space());
4447 int padding_size = desired_offset - Page::kObjectStartOffset; 4447 int padding_size = desired_offset - Page::kObjectStartOffset;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
4479 #ifdef DEBUG 4479 #ifdef DEBUG
4480 TEST(PathTracer) { 4480 TEST(PathTracer) {
4481 CcTest::InitializeVM(); 4481 CcTest::InitializeVM();
4482 v8::HandleScope scope(CcTest::isolate()); 4482 v8::HandleScope scope(CcTest::isolate());
4483 4483
4484 v8::Local<v8::Value> result = CompileRun("'abc'"); 4484 v8::Local<v8::Value> result = CompileRun("'abc'");
4485 Handle<Object> o = v8::Utils::OpenHandle(*result); 4485 Handle<Object> o = v8::Utils::OpenHandle(*result);
4486 CcTest::i_isolate()->heap()->TracePathToObject(*o); 4486 CcTest::i_isolate()->heap()->TracePathToObject(*o);
4487 } 4487 }
4488 #endif // DEBUG 4488 #endif // DEBUG
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698