OLD | NEW |
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 21 matching lines...) Expand all Loading... |
32 #include "compilation-cache.h" | 32 #include "compilation-cache.h" |
33 #include "execution.h" | 33 #include "execution.h" |
34 #include "factory.h" | 34 #include "factory.h" |
35 #include "macro-assembler.h" | 35 #include "macro-assembler.h" |
36 #include "global-handles.h" | 36 #include "global-handles.h" |
37 #include "stub-cache.h" | 37 #include "stub-cache.h" |
38 #include "cctest.h" | 38 #include "cctest.h" |
39 | 39 |
40 using namespace v8::internal; | 40 using namespace v8::internal; |
41 | 41 |
42 static v8::Persistent<v8::Context> env; | |
43 | |
44 static void InitializeVM() { | |
45 if (env.IsEmpty()) env = v8::Context::New(); | |
46 env->Enter(); | |
47 } | |
48 | |
49 | 42 |
50 // Go through all incremental marking steps in one swoop. | 43 // Go through all incremental marking steps in one swoop. |
51 static void SimulateIncrementalMarking() { | 44 static void SimulateIncrementalMarking() { |
52 MarkCompactCollector* collector = HEAP->mark_compact_collector(); | 45 MarkCompactCollector* collector = HEAP->mark_compact_collector(); |
53 IncrementalMarking* marking = HEAP->incremental_marking(); | 46 IncrementalMarking* marking = HEAP->incremental_marking(); |
54 if (collector->IsConcurrentSweepingInProgress()) { | 47 if (collector->IsConcurrentSweepingInProgress()) { |
55 collector->WaitUntilSweepingCompleted(); | 48 collector->WaitUntilSweepingCompleted(); |
56 } | 49 } |
57 CHECK(marking->IsMarking() || marking->IsStopped()); | 50 CHECK(marking->IsMarking() || marking->IsStopped()); |
58 if (marking->IsStopped()) { | 51 if (marking->IsStopped()) { |
(...skipping 12 matching lines...) Expand all Loading... |
71 #ifdef DEBUG | 64 #ifdef DEBUG |
72 CHECK(HEAP->Contains(map)); | 65 CHECK(HEAP->Contains(map)); |
73 #endif | 66 #endif |
74 CHECK_EQ(HEAP->meta_map(), map->map()); | 67 CHECK_EQ(HEAP->meta_map(), map->map()); |
75 CHECK_EQ(type, map->instance_type()); | 68 CHECK_EQ(type, map->instance_type()); |
76 CHECK_EQ(instance_size, map->instance_size()); | 69 CHECK_EQ(instance_size, map->instance_size()); |
77 } | 70 } |
78 | 71 |
79 | 72 |
80 TEST(HeapMaps) { | 73 TEST(HeapMaps) { |
81 InitializeVM(); | 74 CcTest::InitializeVM(); |
82 CheckMap(HEAP->meta_map(), MAP_TYPE, Map::kSize); | 75 CheckMap(HEAP->meta_map(), MAP_TYPE, Map::kSize); |
83 CheckMap(HEAP->heap_number_map(), HEAP_NUMBER_TYPE, HeapNumber::kSize); | 76 CheckMap(HEAP->heap_number_map(), HEAP_NUMBER_TYPE, HeapNumber::kSize); |
84 CheckMap(HEAP->fixed_array_map(), FIXED_ARRAY_TYPE, kVariableSizeSentinel); | 77 CheckMap(HEAP->fixed_array_map(), FIXED_ARRAY_TYPE, kVariableSizeSentinel); |
85 CheckMap(HEAP->string_map(), STRING_TYPE, kVariableSizeSentinel); | 78 CheckMap(HEAP->string_map(), STRING_TYPE, kVariableSizeSentinel); |
86 } | 79 } |
87 | 80 |
88 | 81 |
89 static void CheckOddball(Isolate* isolate, Object* obj, const char* string) { | 82 static void CheckOddball(Isolate* isolate, Object* obj, const char* string) { |
90 CHECK(obj->IsOddball()); | 83 CHECK(obj->IsOddball()); |
91 bool exc; | 84 bool exc; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 Handle<Code>())->ToObjectChecked(); | 137 Handle<Code>())->ToObjectChecked(); |
145 CHECK(copy->IsCode()); | 138 CHECK(copy->IsCode()); |
146 HeapObject* obj_copy = HeapObject::cast(copy); | 139 HeapObject* obj_copy = HeapObject::cast(copy); |
147 Object* not_right = heap->FindCodeObject(obj_copy->address() + | 140 Object* not_right = heap->FindCodeObject(obj_copy->address() + |
148 obj_copy->Size() / 2); | 141 obj_copy->Size() / 2); |
149 CHECK(not_right != code); | 142 CHECK(not_right != code); |
150 } | 143 } |
151 | 144 |
152 | 145 |
153 TEST(HeapObjects) { | 146 TEST(HeapObjects) { |
154 InitializeVM(); | 147 CcTest::InitializeVM(); |
155 Isolate* isolate = Isolate::Current(); | 148 Isolate* isolate = Isolate::Current(); |
156 Heap* heap = isolate->heap(); | 149 Heap* heap = isolate->heap(); |
157 | 150 |
158 HandleScope sc(isolate); | 151 HandleScope sc(isolate); |
159 Object* value = heap->NumberFromDouble(1.000123)->ToObjectChecked(); | 152 Object* value = heap->NumberFromDouble(1.000123)->ToObjectChecked(); |
160 CHECK(value->IsHeapNumber()); | 153 CHECK(value->IsHeapNumber()); |
161 CHECK(value->IsNumber()); | 154 CHECK(value->IsNumber()); |
162 CHECK_EQ(1.000123, value->Number()); | 155 CHECK_EQ(1.000123, value->Number()); |
163 | 156 |
164 value = heap->NumberFromDouble(1.0)->ToObjectChecked(); | 157 value = heap->NumberFromDouble(1.0)->ToObjectChecked(); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 CheckSmi(isolate, -42, "-42"); | 222 CheckSmi(isolate, -42, "-42"); |
230 | 223 |
231 // Check ToString for Numbers | 224 // Check ToString for Numbers |
232 CheckNumber(isolate, 1.1, "1.1"); | 225 CheckNumber(isolate, 1.1, "1.1"); |
233 | 226 |
234 CheckFindCodeObject(isolate); | 227 CheckFindCodeObject(isolate); |
235 } | 228 } |
236 | 229 |
237 | 230 |
238 TEST(Tagging) { | 231 TEST(Tagging) { |
239 InitializeVM(); | 232 CcTest::InitializeVM(); |
240 int request = 24; | 233 int request = 24; |
241 CHECK_EQ(request, static_cast<int>(OBJECT_POINTER_ALIGN(request))); | 234 CHECK_EQ(request, static_cast<int>(OBJECT_POINTER_ALIGN(request))); |
242 CHECK(Smi::FromInt(42)->IsSmi()); | 235 CHECK(Smi::FromInt(42)->IsSmi()); |
243 CHECK(Failure::RetryAfterGC(NEW_SPACE)->IsFailure()); | 236 CHECK(Failure::RetryAfterGC(NEW_SPACE)->IsFailure()); |
244 CHECK_EQ(NEW_SPACE, | 237 CHECK_EQ(NEW_SPACE, |
245 Failure::RetryAfterGC(NEW_SPACE)->allocation_space()); | 238 Failure::RetryAfterGC(NEW_SPACE)->allocation_space()); |
246 CHECK_EQ(OLD_POINTER_SPACE, | 239 CHECK_EQ(OLD_POINTER_SPACE, |
247 Failure::RetryAfterGC(OLD_POINTER_SPACE)->allocation_space()); | 240 Failure::RetryAfterGC(OLD_POINTER_SPACE)->allocation_space()); |
248 CHECK(Failure::Exception()->IsFailure()); | 241 CHECK(Failure::Exception()->IsFailure()); |
249 CHECK(Smi::FromInt(Smi::kMinValue)->IsSmi()); | 242 CHECK(Smi::FromInt(Smi::kMinValue)->IsSmi()); |
250 CHECK(Smi::FromInt(Smi::kMaxValue)->IsSmi()); | 243 CHECK(Smi::FromInt(Smi::kMaxValue)->IsSmi()); |
251 } | 244 } |
252 | 245 |
253 | 246 |
254 TEST(GarbageCollection) { | 247 TEST(GarbageCollection) { |
255 InitializeVM(); | 248 CcTest::InitializeVM(); |
256 Isolate* isolate = Isolate::Current(); | 249 Isolate* isolate = Isolate::Current(); |
257 Heap* heap = isolate->heap(); | 250 Heap* heap = isolate->heap(); |
258 Factory* factory = isolate->factory(); | 251 Factory* factory = isolate->factory(); |
259 | 252 |
260 HandleScope sc(isolate); | 253 HandleScope sc(isolate); |
261 // Check GC. | 254 // Check GC. |
262 heap->CollectGarbage(NEW_SPACE); | 255 heap->CollectGarbage(NEW_SPACE); |
263 | 256 |
264 Handle<String> name = factory->InternalizeUtf8String("theFunction"); | 257 Handle<String> name = factory->InternalizeUtf8String("theFunction"); |
265 Handle<String> prop_name = factory->InternalizeUtf8String("theSlot"); | 258 Handle<String> prop_name = factory->InternalizeUtf8String("theSlot"); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 HandleScope scope(isolate); | 319 HandleScope scope(isolate); |
327 Handle<String> s = isolate->factory()->NewStringFromUtf8(CStrVector(string)); | 320 Handle<String> s = isolate->factory()->NewStringFromUtf8(CStrVector(string)); |
328 CHECK_EQ(StrLength(string), s->length()); | 321 CHECK_EQ(StrLength(string), s->length()); |
329 for (int index = 0; index < s->length(); index++) { | 322 for (int index = 0; index < s->length(); index++) { |
330 CHECK_EQ(static_cast<uint16_t>(string[index]), s->Get(index)); | 323 CHECK_EQ(static_cast<uint16_t>(string[index]), s->Get(index)); |
331 } | 324 } |
332 } | 325 } |
333 | 326 |
334 | 327 |
335 TEST(String) { | 328 TEST(String) { |
336 InitializeVM(); | 329 CcTest::InitializeVM(); |
337 Isolate* isolate = reinterpret_cast<Isolate*>(env->GetIsolate()); | 330 Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate()); |
338 | 331 |
339 VerifyStringAllocation(isolate, "a"); | 332 VerifyStringAllocation(isolate, "a"); |
340 VerifyStringAllocation(isolate, "ab"); | 333 VerifyStringAllocation(isolate, "ab"); |
341 VerifyStringAllocation(isolate, "abc"); | 334 VerifyStringAllocation(isolate, "abc"); |
342 VerifyStringAllocation(isolate, "abcd"); | 335 VerifyStringAllocation(isolate, "abcd"); |
343 VerifyStringAllocation(isolate, "fiskerdrengen er paa havet"); | 336 VerifyStringAllocation(isolate, "fiskerdrengen er paa havet"); |
344 } | 337 } |
345 | 338 |
346 | 339 |
347 TEST(LocalHandles) { | 340 TEST(LocalHandles) { |
348 InitializeVM(); | 341 CcTest::InitializeVM(); |
349 | 342 |
350 v8::HandleScope scope(env->GetIsolate()); | 343 v8::HandleScope scope(CcTest::isolate()); |
351 const char* name = "Kasper the spunky"; | 344 const char* name = "Kasper the spunky"; |
352 Handle<String> string = FACTORY->NewStringFromAscii(CStrVector(name)); | 345 Handle<String> string = FACTORY->NewStringFromAscii(CStrVector(name)); |
353 CHECK_EQ(StrLength(name), string->length()); | 346 CHECK_EQ(StrLength(name), string->length()); |
354 } | 347 } |
355 | 348 |
356 | 349 |
357 TEST(GlobalHandles) { | 350 TEST(GlobalHandles) { |
358 InitializeVM(); | 351 CcTest::InitializeVM(); |
359 Isolate* isolate = Isolate::Current(); | 352 Isolate* isolate = Isolate::Current(); |
360 Heap* heap = isolate->heap(); | 353 Heap* heap = isolate->heap(); |
361 Factory* factory = isolate->factory(); | 354 Factory* factory = isolate->factory(); |
362 GlobalHandles* global_handles = isolate->global_handles(); | 355 GlobalHandles* global_handles = isolate->global_handles(); |
363 | 356 |
364 Handle<Object> h1; | 357 Handle<Object> h1; |
365 Handle<Object> h2; | 358 Handle<Object> h2; |
366 Handle<Object> h3; | 359 Handle<Object> h3; |
367 Handle<Object> h4; | 360 Handle<Object> h4; |
368 | 361 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 | 393 |
401 static void TestWeakGlobalHandleCallback(v8::Isolate* isolate, | 394 static void TestWeakGlobalHandleCallback(v8::Isolate* isolate, |
402 v8::Persistent<v8::Value> handle, | 395 v8::Persistent<v8::Value> handle, |
403 void* id) { | 396 void* id) { |
404 if (1234 == reinterpret_cast<intptr_t>(id)) WeakPointerCleared = true; | 397 if (1234 == reinterpret_cast<intptr_t>(id)) WeakPointerCleared = true; |
405 handle.Dispose(isolate); | 398 handle.Dispose(isolate); |
406 } | 399 } |
407 | 400 |
408 | 401 |
409 TEST(WeakGlobalHandlesScavenge) { | 402 TEST(WeakGlobalHandlesScavenge) { |
410 InitializeVM(); | 403 CcTest::InitializeVM(); |
411 Isolate* isolate = Isolate::Current(); | 404 Isolate* isolate = Isolate::Current(); |
412 Heap* heap = isolate->heap(); | 405 Heap* heap = isolate->heap(); |
413 Factory* factory = isolate->factory(); | 406 Factory* factory = isolate->factory(); |
414 GlobalHandles* global_handles = isolate->global_handles(); | 407 GlobalHandles* global_handles = isolate->global_handles(); |
415 | 408 |
416 WeakPointerCleared = false; | 409 WeakPointerCleared = false; |
417 | 410 |
418 Handle<Object> h1; | 411 Handle<Object> h1; |
419 Handle<Object> h2; | 412 Handle<Object> h2; |
420 | 413 |
(...skipping 21 matching lines...) Expand all Loading... |
442 CHECK(!WeakPointerCleared); | 435 CHECK(!WeakPointerCleared); |
443 CHECK(!global_handles->IsNearDeath(h2.location())); | 436 CHECK(!global_handles->IsNearDeath(h2.location())); |
444 CHECK(!global_handles->IsNearDeath(h1.location())); | 437 CHECK(!global_handles->IsNearDeath(h1.location())); |
445 | 438 |
446 global_handles->Destroy(h1.location()); | 439 global_handles->Destroy(h1.location()); |
447 global_handles->Destroy(h2.location()); | 440 global_handles->Destroy(h2.location()); |
448 } | 441 } |
449 | 442 |
450 | 443 |
451 TEST(WeakGlobalHandlesMark) { | 444 TEST(WeakGlobalHandlesMark) { |
452 InitializeVM(); | 445 CcTest::InitializeVM(); |
453 Isolate* isolate = Isolate::Current(); | 446 Isolate* isolate = Isolate::Current(); |
454 Heap* heap = isolate->heap(); | 447 Heap* heap = isolate->heap(); |
455 Factory* factory = isolate->factory(); | 448 Factory* factory = isolate->factory(); |
456 GlobalHandles* global_handles = isolate->global_handles(); | 449 GlobalHandles* global_handles = isolate->global_handles(); |
457 | 450 |
458 WeakPointerCleared = false; | 451 WeakPointerCleared = false; |
459 | 452 |
460 Handle<Object> h1; | 453 Handle<Object> h1; |
461 Handle<Object> h2; | 454 Handle<Object> h2; |
462 | 455 |
(...skipping 25 matching lines...) Expand all Loading... |
488 CHECK((*h1)->IsString()); | 481 CHECK((*h1)->IsString()); |
489 | 482 |
490 CHECK(WeakPointerCleared); | 483 CHECK(WeakPointerCleared); |
491 CHECK(!GlobalHandles::IsNearDeath(h1.location())); | 484 CHECK(!GlobalHandles::IsNearDeath(h1.location())); |
492 | 485 |
493 global_handles->Destroy(h1.location()); | 486 global_handles->Destroy(h1.location()); |
494 } | 487 } |
495 | 488 |
496 | 489 |
497 TEST(DeleteWeakGlobalHandle) { | 490 TEST(DeleteWeakGlobalHandle) { |
498 InitializeVM(); | 491 CcTest::InitializeVM(); |
499 Isolate* isolate = Isolate::Current(); | 492 Isolate* isolate = Isolate::Current(); |
500 Heap* heap = isolate->heap(); | 493 Heap* heap = isolate->heap(); |
501 Factory* factory = isolate->factory(); | 494 Factory* factory = isolate->factory(); |
502 GlobalHandles* global_handles = isolate->global_handles(); | 495 GlobalHandles* global_handles = isolate->global_handles(); |
503 | 496 |
504 WeakPointerCleared = false; | 497 WeakPointerCleared = false; |
505 | 498 |
506 Handle<Object> h; | 499 Handle<Object> h; |
507 | 500 |
508 { | 501 { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 Object* b; | 596 Object* b; |
604 MaybeObject* maybe_b = HEAP->InternalizeUtf8String(string); | 597 MaybeObject* maybe_b = HEAP->InternalizeUtf8String(string); |
605 if (!maybe_b->ToObject(&b)) continue; | 598 if (!maybe_b->ToObject(&b)) continue; |
606 CHECK_EQ(b, a); | 599 CHECK_EQ(b, a); |
607 CHECK(String::cast(b)->IsUtf8EqualTo(CStrVector(string))); | 600 CHECK(String::cast(b)->IsUtf8EqualTo(CStrVector(string))); |
608 } | 601 } |
609 } | 602 } |
610 | 603 |
611 | 604 |
612 TEST(StringTable) { | 605 TEST(StringTable) { |
613 InitializeVM(); | 606 CcTest::InitializeVM(); |
614 | 607 |
615 CheckInternalizedStrings(not_so_random_string_table); | 608 CheckInternalizedStrings(not_so_random_string_table); |
616 CheckInternalizedStrings(not_so_random_string_table); | 609 CheckInternalizedStrings(not_so_random_string_table); |
617 } | 610 } |
618 | 611 |
619 | 612 |
620 TEST(FunctionAllocation) { | 613 TEST(FunctionAllocation) { |
621 InitializeVM(); | 614 CcTest::InitializeVM(); |
622 | 615 |
623 v8::HandleScope sc(env->GetIsolate()); | 616 v8::HandleScope sc(CcTest::isolate()); |
624 Handle<String> name = FACTORY->InternalizeUtf8String("theFunction"); | 617 Handle<String> name = FACTORY->InternalizeUtf8String("theFunction"); |
625 Handle<JSFunction> function = | 618 Handle<JSFunction> function = |
626 FACTORY->NewFunction(name, FACTORY->undefined_value()); | 619 FACTORY->NewFunction(name, FACTORY->undefined_value()); |
627 Handle<Map> initial_map = | 620 Handle<Map> initial_map = |
628 FACTORY->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); | 621 FACTORY->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
629 function->set_initial_map(*initial_map); | 622 function->set_initial_map(*initial_map); |
630 | 623 |
631 Handle<String> prop_name = FACTORY->InternalizeUtf8String("theSlot"); | 624 Handle<String> prop_name = FACTORY->InternalizeUtf8String("theSlot"); |
632 Handle<JSObject> obj = FACTORY->NewJSObject(function); | 625 Handle<JSObject> obj = FACTORY->NewJSObject(function); |
633 obj->SetProperty( | 626 obj->SetProperty( |
634 *prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObjectChecked(); | 627 *prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObjectChecked(); |
635 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); | 628 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); |
636 // Check that we can add properties to function objects. | 629 // Check that we can add properties to function objects. |
637 function->SetProperty( | 630 function->SetProperty( |
638 *prop_name, Smi::FromInt(24), NONE, kNonStrictMode)->ToObjectChecked(); | 631 *prop_name, Smi::FromInt(24), NONE, kNonStrictMode)->ToObjectChecked(); |
639 CHECK_EQ(Smi::FromInt(24), function->GetProperty(*prop_name)); | 632 CHECK_EQ(Smi::FromInt(24), function->GetProperty(*prop_name)); |
640 } | 633 } |
641 | 634 |
642 | 635 |
643 TEST(ObjectProperties) { | 636 TEST(ObjectProperties) { |
644 InitializeVM(); | 637 CcTest::InitializeVM(); |
645 | 638 |
646 v8::HandleScope sc(env->GetIsolate()); | 639 v8::HandleScope sc(CcTest::isolate()); |
647 String* object_string = String::cast(HEAP->Object_string()); | 640 String* object_string = String::cast(HEAP->Object_string()); |
648 Object* raw_object = Isolate::Current()->context()->global_object()-> | 641 Object* raw_object = Isolate::Current()->context()->global_object()-> |
649 GetProperty(object_string)->ToObjectChecked(); | 642 GetProperty(object_string)->ToObjectChecked(); |
650 JSFunction* object_function = JSFunction::cast(raw_object); | 643 JSFunction* object_function = JSFunction::cast(raw_object); |
651 Handle<JSFunction> constructor(object_function); | 644 Handle<JSFunction> constructor(object_function); |
652 Handle<JSObject> obj = FACTORY->NewJSObject(constructor); | 645 Handle<JSObject> obj = FACTORY->NewJSObject(constructor); |
653 Handle<String> first = FACTORY->InternalizeUtf8String("first"); | 646 Handle<String> first = FACTORY->InternalizeUtf8String("first"); |
654 Handle<String> second = FACTORY->InternalizeUtf8String("second"); | 647 Handle<String> second = FACTORY->InternalizeUtf8String("second"); |
655 | 648 |
656 // check for empty | 649 // check for empty |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 const char* string2 = "fugl"; | 700 const char* string2 = "fugl"; |
708 Handle<String> s2_string = FACTORY->InternalizeUtf8String(string2); | 701 Handle<String> s2_string = FACTORY->InternalizeUtf8String(string2); |
709 obj->SetProperty( | 702 obj->SetProperty( |
710 *s2_string, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); | 703 *s2_string, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); |
711 Handle<String> s2 = FACTORY->NewStringFromAscii(CStrVector(string2)); | 704 Handle<String> s2 = FACTORY->NewStringFromAscii(CStrVector(string2)); |
712 CHECK(obj->HasLocalProperty(*s2)); | 705 CHECK(obj->HasLocalProperty(*s2)); |
713 } | 706 } |
714 | 707 |
715 | 708 |
716 TEST(JSObjectMaps) { | 709 TEST(JSObjectMaps) { |
717 InitializeVM(); | 710 CcTest::InitializeVM(); |
718 | 711 |
719 v8::HandleScope sc(env->GetIsolate()); | 712 v8::HandleScope sc(CcTest::isolate()); |
720 Handle<String> name = FACTORY->InternalizeUtf8String("theFunction"); | 713 Handle<String> name = FACTORY->InternalizeUtf8String("theFunction"); |
721 Handle<JSFunction> function = | 714 Handle<JSFunction> function = |
722 FACTORY->NewFunction(name, FACTORY->undefined_value()); | 715 FACTORY->NewFunction(name, FACTORY->undefined_value()); |
723 Handle<Map> initial_map = | 716 Handle<Map> initial_map = |
724 FACTORY->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); | 717 FACTORY->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
725 function->set_initial_map(*initial_map); | 718 function->set_initial_map(*initial_map); |
726 | 719 |
727 Handle<String> prop_name = FACTORY->InternalizeUtf8String("theSlot"); | 720 Handle<String> prop_name = FACTORY->InternalizeUtf8String("theSlot"); |
728 Handle<JSObject> obj = FACTORY->NewJSObject(function); | 721 Handle<JSObject> obj = FACTORY->NewJSObject(function); |
729 | 722 |
730 // Set a propery | 723 // Set a propery |
731 obj->SetProperty( | 724 obj->SetProperty( |
732 *prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObjectChecked(); | 725 *prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObjectChecked(); |
733 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); | 726 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); |
734 | 727 |
735 // Check the map has changed | 728 // Check the map has changed |
736 CHECK(*initial_map != obj->map()); | 729 CHECK(*initial_map != obj->map()); |
737 } | 730 } |
738 | 731 |
739 | 732 |
740 TEST(JSArray) { | 733 TEST(JSArray) { |
741 InitializeVM(); | 734 CcTest::InitializeVM(); |
742 | 735 |
743 v8::HandleScope sc(env->GetIsolate()); | 736 v8::HandleScope sc(CcTest::isolate()); |
744 Handle<String> name = FACTORY->InternalizeUtf8String("Array"); | 737 Handle<String> name = FACTORY->InternalizeUtf8String("Array"); |
745 Object* raw_object = Isolate::Current()->context()->global_object()-> | 738 Object* raw_object = Isolate::Current()->context()->global_object()-> |
746 GetProperty(*name)->ToObjectChecked(); | 739 GetProperty(*name)->ToObjectChecked(); |
747 Handle<JSFunction> function = Handle<JSFunction>( | 740 Handle<JSFunction> function = Handle<JSFunction>( |
748 JSFunction::cast(raw_object)); | 741 JSFunction::cast(raw_object)); |
749 | 742 |
750 // Allocate the object. | 743 // Allocate the object. |
751 Handle<JSObject> object = FACTORY->NewJSObject(function); | 744 Handle<JSObject> object = FACTORY->NewJSObject(function); |
752 Handle<JSArray> array = Handle<JSArray>::cast(object); | 745 Handle<JSArray> array = Handle<JSArray>::cast(object); |
753 // We just initialized the VM, no heap allocation failure yet. | 746 // We just initialized the VM, no heap allocation failure yet. |
(...skipping 24 matching lines...) Expand all Loading... |
778 array->SetElement(int_length, *name, NONE, kNonStrictMode)->ToObjectChecked(); | 771 array->SetElement(int_length, *name, NONE, kNonStrictMode)->ToObjectChecked(); |
779 uint32_t new_int_length = 0; | 772 uint32_t new_int_length = 0; |
780 CHECK(array->length()->ToArrayIndex(&new_int_length)); | 773 CHECK(array->length()->ToArrayIndex(&new_int_length)); |
781 CHECK_EQ(static_cast<double>(int_length), new_int_length - 1); | 774 CHECK_EQ(static_cast<double>(int_length), new_int_length - 1); |
782 CHECK_EQ(array->GetElement(int_length), *name); | 775 CHECK_EQ(array->GetElement(int_length), *name); |
783 CHECK_EQ(array->GetElement(0), *name); | 776 CHECK_EQ(array->GetElement(0), *name); |
784 } | 777 } |
785 | 778 |
786 | 779 |
787 TEST(JSObjectCopy) { | 780 TEST(JSObjectCopy) { |
788 InitializeVM(); | 781 CcTest::InitializeVM(); |
789 | 782 |
790 v8::HandleScope sc(env->GetIsolate()); | 783 v8::HandleScope sc(CcTest::isolate()); |
791 String* object_string = String::cast(HEAP->Object_string()); | 784 String* object_string = String::cast(HEAP->Object_string()); |
792 Object* raw_object = Isolate::Current()->context()->global_object()-> | 785 Object* raw_object = Isolate::Current()->context()->global_object()-> |
793 GetProperty(object_string)->ToObjectChecked(); | 786 GetProperty(object_string)->ToObjectChecked(); |
794 JSFunction* object_function = JSFunction::cast(raw_object); | 787 JSFunction* object_function = JSFunction::cast(raw_object); |
795 Handle<JSFunction> constructor(object_function); | 788 Handle<JSFunction> constructor(object_function); |
796 Handle<JSObject> obj = FACTORY->NewJSObject(constructor); | 789 Handle<JSObject> obj = FACTORY->NewJSObject(constructor); |
797 Handle<String> first = FACTORY->InternalizeUtf8String("first"); | 790 Handle<String> first = FACTORY->InternalizeUtf8String("first"); |
798 Handle<String> second = FACTORY->InternalizeUtf8String("second"); | 791 Handle<String> second = FACTORY->InternalizeUtf8String("second"); |
799 | 792 |
800 obj->SetProperty( | 793 obj->SetProperty( |
(...skipping 25 matching lines...) Expand all Loading... |
826 | 819 |
827 CHECK_EQ(obj->GetElement(1), clone->GetElement(0)); | 820 CHECK_EQ(obj->GetElement(1), clone->GetElement(0)); |
828 CHECK_EQ(obj->GetElement(0), clone->GetElement(1)); | 821 CHECK_EQ(obj->GetElement(0), clone->GetElement(1)); |
829 | 822 |
830 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*first)); | 823 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*first)); |
831 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*second)); | 824 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*second)); |
832 } | 825 } |
833 | 826 |
834 | 827 |
835 TEST(StringAllocation) { | 828 TEST(StringAllocation) { |
836 InitializeVM(); | 829 CcTest::InitializeVM(); |
837 | 830 |
838 const unsigned char chars[] = { 0xe5, 0xa4, 0xa7 }; | 831 const unsigned char chars[] = { 0xe5, 0xa4, 0xa7 }; |
839 for (int length = 0; length < 100; length++) { | 832 for (int length = 0; length < 100; length++) { |
840 v8::HandleScope scope(env->GetIsolate()); | 833 v8::HandleScope scope(CcTest::isolate()); |
841 char* non_ascii = NewArray<char>(3 * length + 1); | 834 char* non_ascii = NewArray<char>(3 * length + 1); |
842 char* ascii = NewArray<char>(length + 1); | 835 char* ascii = NewArray<char>(length + 1); |
843 non_ascii[3 * length] = 0; | 836 non_ascii[3 * length] = 0; |
844 ascii[length] = 0; | 837 ascii[length] = 0; |
845 for (int i = 0; i < length; i++) { | 838 for (int i = 0; i < length; i++) { |
846 ascii[i] = 'a'; | 839 ascii[i] = 'a'; |
847 non_ascii[3 * i] = chars[0]; | 840 non_ascii[3 * i] = chars[0]; |
848 non_ascii[3 * i + 1] = chars[1]; | 841 non_ascii[3 * i + 1] = chars[1]; |
849 non_ascii[3 * i + 2] = chars[2]; | 842 non_ascii[3 * i + 2] = chars[2]; |
850 } | 843 } |
(...skipping 27 matching lines...) Expand all Loading... |
878 if (*objs[i] == obj) { | 871 if (*objs[i] == obj) { |
879 found_count++; | 872 found_count++; |
880 } | 873 } |
881 } | 874 } |
882 } | 875 } |
883 return found_count; | 876 return found_count; |
884 } | 877 } |
885 | 878 |
886 | 879 |
887 TEST(Iteration) { | 880 TEST(Iteration) { |
888 InitializeVM(); | 881 CcTest::InitializeVM(); |
889 v8::HandleScope scope(env->GetIsolate()); | 882 v8::HandleScope scope(CcTest::isolate()); |
890 | 883 |
891 // Array of objects to scan haep for. | 884 // Array of objects to scan haep for. |
892 const int objs_count = 6; | 885 const int objs_count = 6; |
893 Handle<Object> objs[objs_count]; | 886 Handle<Object> objs[objs_count]; |
894 int next_objs_index = 0; | 887 int next_objs_index = 0; |
895 | 888 |
896 // Allocate a JS array to OLD_POINTER_SPACE and NEW_SPACE | 889 // Allocate a JS array to OLD_POINTER_SPACE and NEW_SPACE |
897 objs[next_objs_index++] = FACTORY->NewJSArray(10); | 890 objs[next_objs_index++] = FACTORY->NewJSArray(10); |
898 objs[next_objs_index++] = FACTORY->NewJSArray(10, | 891 objs[next_objs_index++] = FACTORY->NewJSArray(10, |
899 FAST_HOLEY_ELEMENTS, | 892 FAST_HOLEY_ELEMENTS, |
(...skipping 16 matching lines...) Expand all Loading... |
916 | 909 |
917 // Add a Map object to look for. | 910 // Add a Map object to look for. |
918 objs[next_objs_index++] = Handle<Map>(HeapObject::cast(*objs[0])->map()); | 911 objs[next_objs_index++] = Handle<Map>(HeapObject::cast(*objs[0])->map()); |
919 | 912 |
920 CHECK_EQ(objs_count, next_objs_index); | 913 CHECK_EQ(objs_count, next_objs_index); |
921 CHECK_EQ(objs_count, ObjectsFoundInHeap(HEAP, objs, objs_count)); | 914 CHECK_EQ(objs_count, ObjectsFoundInHeap(HEAP, objs, objs_count)); |
922 } | 915 } |
923 | 916 |
924 | 917 |
925 TEST(EmptyHandleEscapeFrom) { | 918 TEST(EmptyHandleEscapeFrom) { |
926 InitializeVM(); | 919 CcTest::InitializeVM(); |
927 | 920 |
928 v8::HandleScope scope(env->GetIsolate()); | 921 v8::HandleScope scope(CcTest::isolate()); |
929 Handle<JSObject> runaway; | 922 Handle<JSObject> runaway; |
930 | 923 |
931 { | 924 { |
932 v8::HandleScope nested(env->GetIsolate()); | 925 v8::HandleScope nested(CcTest::isolate()); |
933 Handle<JSObject> empty; | 926 Handle<JSObject> empty; |
934 runaway = empty.EscapeFrom(&nested); | 927 runaway = empty.EscapeFrom(&nested); |
935 } | 928 } |
936 | 929 |
937 CHECK(runaway.is_null()); | 930 CHECK(runaway.is_null()); |
938 } | 931 } |
939 | 932 |
940 | 933 |
941 static int LenFromSize(int size) { | 934 static int LenFromSize(int size) { |
942 return (size - FixedArray::kHeaderSize) / kPointerSize; | 935 return (size - FixedArray::kHeaderSize) / kPointerSize; |
943 } | 936 } |
944 | 937 |
945 | 938 |
946 TEST(Regression39128) { | 939 TEST(Regression39128) { |
947 // Test case for crbug.com/39128. | 940 // Test case for crbug.com/39128. |
948 InitializeVM(); | 941 CcTest::InitializeVM(); |
949 | 942 |
950 // Increase the chance of 'bump-the-pointer' allocation in old space. | 943 // Increase the chance of 'bump-the-pointer' allocation in old space. |
951 HEAP->CollectAllGarbage(Heap::kNoGCFlags); | 944 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
952 | 945 |
953 v8::HandleScope scope(env->GetIsolate()); | 946 v8::HandleScope scope(CcTest::isolate()); |
954 | 947 |
955 // The plan: create JSObject which references objects in new space. | 948 // The plan: create JSObject which references objects in new space. |
956 // Then clone this object (forcing it to go into old space) and check | 949 // Then clone this object (forcing it to go into old space) and check |
957 // that region dirty marks are updated correctly. | 950 // that region dirty marks are updated correctly. |
958 | 951 |
959 // Step 1: prepare a map for the object. We add 1 inobject property to it. | 952 // Step 1: prepare a map for the object. We add 1 inobject property to it. |
960 Handle<JSFunction> object_ctor( | 953 Handle<JSFunction> object_ctor( |
961 Isolate::Current()->native_context()->object_function()); | 954 Isolate::Current()->native_context()->object_function()); |
962 CHECK(object_ctor->has_initial_map()); | 955 CHECK(object_ctor->has_initial_map()); |
963 Handle<Map> object_map(object_ctor->initial_map()); | 956 Handle<Map> object_map(object_ctor->initial_map()); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1015 return; | 1008 return; |
1016 } | 1009 } |
1017 CHECK(HEAP->old_pointer_space()->Contains(clone->address())); | 1010 CHECK(HEAP->old_pointer_space()->Contains(clone->address())); |
1018 } | 1011 } |
1019 | 1012 |
1020 | 1013 |
1021 TEST(TestCodeFlushing) { | 1014 TEST(TestCodeFlushing) { |
1022 // If we do not flush code this test is invalid. | 1015 // If we do not flush code this test is invalid. |
1023 if (!FLAG_flush_code) return; | 1016 if (!FLAG_flush_code) return; |
1024 i::FLAG_allow_natives_syntax = true; | 1017 i::FLAG_allow_natives_syntax = true; |
1025 InitializeVM(); | 1018 CcTest::InitializeVM(); |
1026 v8::HandleScope scope(env->GetIsolate()); | 1019 v8::HandleScope scope(CcTest::isolate()); |
1027 const char* source = "function foo() {" | 1020 const char* source = "function foo() {" |
1028 " var x = 42;" | 1021 " var x = 42;" |
1029 " var y = 42;" | 1022 " var y = 42;" |
1030 " var z = x + y;" | 1023 " var z = x + y;" |
1031 "};" | 1024 "};" |
1032 "foo()"; | 1025 "foo()"; |
1033 Handle<String> foo_name = FACTORY->InternalizeUtf8String("foo"); | 1026 Handle<String> foo_name = FACTORY->InternalizeUtf8String("foo"); |
1034 | 1027 |
1035 // This compile will add the code to the compilation cache. | 1028 // This compile will add the code to the compilation cache. |
1036 { v8::HandleScope scope(env->GetIsolate()); | 1029 { v8::HandleScope scope(CcTest::isolate()); |
1037 CompileRun(source); | 1030 CompileRun(source); |
1038 } | 1031 } |
1039 | 1032 |
1040 // Check function is compiled. | 1033 // Check function is compiled. |
1041 Object* func_value = Isolate::Current()->context()->global_object()-> | 1034 Object* func_value = Isolate::Current()->context()->global_object()-> |
1042 GetProperty(*foo_name)->ToObjectChecked(); | 1035 GetProperty(*foo_name)->ToObjectChecked(); |
1043 CHECK(func_value->IsJSFunction()); | 1036 CHECK(func_value->IsJSFunction()); |
1044 Handle<JSFunction> function(JSFunction::cast(func_value)); | 1037 Handle<JSFunction> function(JSFunction::cast(func_value)); |
1045 CHECK(function->shared()->is_compiled()); | 1038 CHECK(function->shared()->is_compiled()); |
1046 | 1039 |
(...skipping 15 matching lines...) Expand all Loading... |
1062 CompileRun("foo()"); | 1055 CompileRun("foo()"); |
1063 CHECK(function->shared()->is_compiled()); | 1056 CHECK(function->shared()->is_compiled()); |
1064 CHECK(function->is_compiled()); | 1057 CHECK(function->is_compiled()); |
1065 } | 1058 } |
1066 | 1059 |
1067 | 1060 |
1068 TEST(TestCodeFlushingIncremental) { | 1061 TEST(TestCodeFlushingIncremental) { |
1069 // If we do not flush code this test is invalid. | 1062 // If we do not flush code this test is invalid. |
1070 if (!FLAG_flush_code || !FLAG_flush_code_incrementally) return; | 1063 if (!FLAG_flush_code || !FLAG_flush_code_incrementally) return; |
1071 i::FLAG_allow_natives_syntax = true; | 1064 i::FLAG_allow_natives_syntax = true; |
1072 InitializeVM(); | 1065 CcTest::InitializeVM(); |
1073 v8::HandleScope scope(env->GetIsolate()); | 1066 v8::HandleScope scope(CcTest::isolate()); |
1074 const char* source = "function foo() {" | 1067 const char* source = "function foo() {" |
1075 " var x = 42;" | 1068 " var x = 42;" |
1076 " var y = 42;" | 1069 " var y = 42;" |
1077 " var z = x + y;" | 1070 " var z = x + y;" |
1078 "};" | 1071 "};" |
1079 "foo()"; | 1072 "foo()"; |
1080 Handle<String> foo_name = FACTORY->InternalizeUtf8String("foo"); | 1073 Handle<String> foo_name = FACTORY->InternalizeUtf8String("foo"); |
1081 | 1074 |
1082 // This compile will add the code to the compilation cache. | 1075 // This compile will add the code to the compilation cache. |
1083 { v8::HandleScope scope(env->GetIsolate()); | 1076 { v8::HandleScope scope(CcTest::isolate()); |
1084 CompileRun(source); | 1077 CompileRun(source); |
1085 } | 1078 } |
1086 | 1079 |
1087 // Check function is compiled. | 1080 // Check function is compiled. |
1088 Object* func_value = Isolate::Current()->context()->global_object()-> | 1081 Object* func_value = Isolate::Current()->context()->global_object()-> |
1089 GetProperty(*foo_name)->ToObjectChecked(); | 1082 GetProperty(*foo_name)->ToObjectChecked(); |
1090 CHECK(func_value->IsJSFunction()); | 1083 CHECK(func_value->IsJSFunction()); |
1091 Handle<JSFunction> function(JSFunction::cast(func_value)); | 1084 Handle<JSFunction> function(JSFunction::cast(func_value)); |
1092 CHECK(function->shared()->is_compiled()); | 1085 CHECK(function->shared()->is_compiled()); |
1093 | 1086 |
1094 // The code will survive at least two GCs. | 1087 // The code will survive at least two GCs. |
1095 HEAP->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 1088 HEAP->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
1096 HEAP->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 1089 HEAP->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
1097 CHECK(function->shared()->is_compiled()); | 1090 CHECK(function->shared()->is_compiled()); |
1098 | 1091 |
1099 // Simulate several GCs that use incremental marking. | 1092 // Simulate several GCs that use incremental marking. |
1100 const int kAgingThreshold = 6; | 1093 const int kAgingThreshold = 6; |
1101 for (int i = 0; i < kAgingThreshold; i++) { | 1094 for (int i = 0; i < kAgingThreshold; i++) { |
1102 SimulateIncrementalMarking(); | 1095 SimulateIncrementalMarking(); |
1103 HEAP->CollectAllGarbage(Heap::kNoGCFlags); | 1096 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
1104 } | 1097 } |
1105 CHECK(!function->shared()->is_compiled() || function->IsOptimized()); | 1098 CHECK(!function->shared()->is_compiled() || function->IsOptimized()); |
1106 CHECK(!function->is_compiled() || function->IsOptimized()); | 1099 CHECK(!function->is_compiled() || function->IsOptimized()); |
1107 | 1100 |
1108 // This compile will compile the function again. | 1101 // This compile will compile the function again. |
1109 { v8::HandleScope scope(env->GetIsolate()); | 1102 { v8::HandleScope scope(CcTest::isolate()); |
1110 CompileRun("foo();"); | 1103 CompileRun("foo();"); |
1111 } | 1104 } |
1112 | 1105 |
1113 // Simulate several GCs that use incremental marking but make sure | 1106 // Simulate several GCs that use incremental marking but make sure |
1114 // the loop breaks once the function is enqueued as a candidate. | 1107 // the loop breaks once the function is enqueued as a candidate. |
1115 for (int i = 0; i < kAgingThreshold; i++) { | 1108 for (int i = 0; i < kAgingThreshold; i++) { |
1116 SimulateIncrementalMarking(); | 1109 SimulateIncrementalMarking(); |
1117 if (!function->next_function_link()->IsUndefined()) break; | 1110 if (!function->next_function_link()->IsUndefined()) break; |
1118 HEAP->CollectAllGarbage(Heap::kNoGCFlags); | 1111 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
1119 } | 1112 } |
1120 | 1113 |
1121 // Force optimization while incremental marking is active and while | 1114 // Force optimization while incremental marking is active and while |
1122 // the function is enqueued as a candidate. | 1115 // the function is enqueued as a candidate. |
1123 { v8::HandleScope scope(env->GetIsolate()); | 1116 { v8::HandleScope scope(CcTest::isolate()); |
1124 CompileRun("%OptimizeFunctionOnNextCall(foo); foo();"); | 1117 CompileRun("%OptimizeFunctionOnNextCall(foo); foo();"); |
1125 } | 1118 } |
1126 | 1119 |
1127 // Simulate one final GC to make sure the candidate queue is sane. | 1120 // Simulate one final GC to make sure the candidate queue is sane. |
1128 HEAP->CollectAllGarbage(Heap::kNoGCFlags); | 1121 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
1129 CHECK(function->shared()->is_compiled() || !function->IsOptimized()); | 1122 CHECK(function->shared()->is_compiled() || !function->IsOptimized()); |
1130 CHECK(function->is_compiled() || !function->IsOptimized()); | 1123 CHECK(function->is_compiled() || !function->IsOptimized()); |
1131 } | 1124 } |
1132 | 1125 |
1133 | 1126 |
1134 TEST(TestCodeFlushingIncrementalScavenge) { | 1127 TEST(TestCodeFlushingIncrementalScavenge) { |
1135 // If we do not flush code this test is invalid. | 1128 // If we do not flush code this test is invalid. |
1136 if (!FLAG_flush_code || !FLAG_flush_code_incrementally) return; | 1129 if (!FLAG_flush_code || !FLAG_flush_code_incrementally) return; |
1137 i::FLAG_allow_natives_syntax = true; | 1130 i::FLAG_allow_natives_syntax = true; |
1138 InitializeVM(); | 1131 CcTest::InitializeVM(); |
1139 v8::HandleScope scope(env->GetIsolate()); | 1132 v8::HandleScope scope(CcTest::isolate()); |
1140 const char* source = "var foo = function() {" | 1133 const char* source = "var foo = function() {" |
1141 " var x = 42;" | 1134 " var x = 42;" |
1142 " var y = 42;" | 1135 " var y = 42;" |
1143 " var z = x + y;" | 1136 " var z = x + y;" |
1144 "};" | 1137 "};" |
1145 "foo();" | 1138 "foo();" |
1146 "var bar = function() {" | 1139 "var bar = function() {" |
1147 " var x = 23;" | 1140 " var x = 23;" |
1148 "};" | 1141 "};" |
1149 "bar();"; | 1142 "bar();"; |
1150 Handle<String> foo_name = FACTORY->InternalizeUtf8String("foo"); | 1143 Handle<String> foo_name = FACTORY->InternalizeUtf8String("foo"); |
1151 Handle<String> bar_name = FACTORY->InternalizeUtf8String("bar"); | 1144 Handle<String> bar_name = FACTORY->InternalizeUtf8String("bar"); |
1152 | 1145 |
1153 // Perfrom one initial GC to enable code flushing. | 1146 // Perfrom one initial GC to enable code flushing. |
1154 HEAP->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 1147 HEAP->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
1155 | 1148 |
1156 // This compile will add the code to the compilation cache. | 1149 // This compile will add the code to the compilation cache. |
1157 { v8::HandleScope scope(env->GetIsolate()); | 1150 { v8::HandleScope scope(CcTest::isolate()); |
1158 CompileRun(source); | 1151 CompileRun(source); |
1159 } | 1152 } |
1160 | 1153 |
1161 // Check functions are compiled. | 1154 // Check functions are compiled. |
1162 Object* func_value = Isolate::Current()->context()->global_object()-> | 1155 Object* func_value = Isolate::Current()->context()->global_object()-> |
1163 GetProperty(*foo_name)->ToObjectChecked(); | 1156 GetProperty(*foo_name)->ToObjectChecked(); |
1164 CHECK(func_value->IsJSFunction()); | 1157 CHECK(func_value->IsJSFunction()); |
1165 Handle<JSFunction> function(JSFunction::cast(func_value)); | 1158 Handle<JSFunction> function(JSFunction::cast(func_value)); |
1166 CHECK(function->shared()->is_compiled()); | 1159 CHECK(function->shared()->is_compiled()); |
1167 Object* func_value2 = Isolate::Current()->context()->global_object()-> | 1160 Object* func_value2 = Isolate::Current()->context()->global_object()-> |
1168 GetProperty(*bar_name)->ToObjectChecked(); | 1161 GetProperty(*bar_name)->ToObjectChecked(); |
1169 CHECK(func_value2->IsJSFunction()); | 1162 CHECK(func_value2->IsJSFunction()); |
1170 Handle<JSFunction> function2(JSFunction::cast(func_value2)); | 1163 Handle<JSFunction> function2(JSFunction::cast(func_value2)); |
1171 CHECK(function2->shared()->is_compiled()); | 1164 CHECK(function2->shared()->is_compiled()); |
1172 | 1165 |
1173 // Clear references to functions so that one of them can die. | 1166 // Clear references to functions so that one of them can die. |
1174 { v8::HandleScope scope(env->GetIsolate()); | 1167 { v8::HandleScope scope(CcTest::isolate()); |
1175 CompileRun("foo = 0; bar = 0;"); | 1168 CompileRun("foo = 0; bar = 0;"); |
1176 } | 1169 } |
1177 | 1170 |
1178 // Bump the code age so that flushing is triggered while the function | 1171 // Bump the code age so that flushing is triggered while the function |
1179 // object is still located in new-space. | 1172 // object is still located in new-space. |
1180 const int kAgingThreshold = 6; | 1173 const int kAgingThreshold = 6; |
1181 for (int i = 0; i < kAgingThreshold; i++) { | 1174 for (int i = 0; i < kAgingThreshold; i++) { |
1182 function->shared()->code()->MakeOlder(static_cast<MarkingParity>(i % 2)); | 1175 function->shared()->code()->MakeOlder(static_cast<MarkingParity>(i % 2)); |
1183 function2->shared()->code()->MakeOlder(static_cast<MarkingParity>(i % 2)); | 1176 function2->shared()->code()->MakeOlder(static_cast<MarkingParity>(i % 2)); |
1184 } | 1177 } |
1185 | 1178 |
1186 // Simulate incremental marking so that the functions are enqueued as | 1179 // Simulate incremental marking so that the functions are enqueued as |
1187 // code flushing candidates. Then kill one of the functions. Finally | 1180 // code flushing candidates. Then kill one of the functions. Finally |
1188 // perform a scavenge while incremental marking is still running. | 1181 // perform a scavenge while incremental marking is still running. |
1189 SimulateIncrementalMarking(); | 1182 SimulateIncrementalMarking(); |
1190 *function2.location() = NULL; | 1183 *function2.location() = NULL; |
1191 HEAP->CollectGarbage(NEW_SPACE, "test scavenge while marking"); | 1184 HEAP->CollectGarbage(NEW_SPACE, "test scavenge while marking"); |
1192 | 1185 |
1193 // Simulate one final GC to make sure the candidate queue is sane. | 1186 // Simulate one final GC to make sure the candidate queue is sane. |
1194 HEAP->CollectAllGarbage(Heap::kNoGCFlags); | 1187 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
1195 CHECK(!function->shared()->is_compiled() || function->IsOptimized()); | 1188 CHECK(!function->shared()->is_compiled() || function->IsOptimized()); |
1196 CHECK(!function->is_compiled() || function->IsOptimized()); | 1189 CHECK(!function->is_compiled() || function->IsOptimized()); |
1197 } | 1190 } |
1198 | 1191 |
1199 | 1192 |
1200 TEST(TestCodeFlushingIncrementalAbort) { | 1193 TEST(TestCodeFlushingIncrementalAbort) { |
1201 // If we do not flush code this test is invalid. | 1194 // If we do not flush code this test is invalid. |
1202 if (!FLAG_flush_code || !FLAG_flush_code_incrementally) return; | 1195 if (!FLAG_flush_code || !FLAG_flush_code_incrementally) return; |
1203 i::FLAG_allow_natives_syntax = true; | 1196 i::FLAG_allow_natives_syntax = true; |
1204 InitializeVM(); | 1197 CcTest::InitializeVM(); |
1205 Isolate* isolate = Isolate::Current(); | 1198 Isolate* isolate = Isolate::Current(); |
1206 Heap* heap = isolate->heap(); | 1199 Heap* heap = isolate->heap(); |
1207 v8::HandleScope scope(env->GetIsolate()); | 1200 v8::HandleScope scope(CcTest::isolate()); |
1208 const char* source = "function foo() {" | 1201 const char* source = "function foo() {" |
1209 " var x = 42;" | 1202 " var x = 42;" |
1210 " var y = 42;" | 1203 " var y = 42;" |
1211 " var z = x + y;" | 1204 " var z = x + y;" |
1212 "};" | 1205 "};" |
1213 "foo()"; | 1206 "foo()"; |
1214 Handle<String> foo_name = FACTORY->InternalizeUtf8String("foo"); | 1207 Handle<String> foo_name = FACTORY->InternalizeUtf8String("foo"); |
1215 | 1208 |
1216 // This compile will add the code to the compilation cache. | 1209 // This compile will add the code to the compilation cache. |
1217 { v8::HandleScope scope(env->GetIsolate()); | 1210 { v8::HandleScope scope(CcTest::isolate()); |
1218 CompileRun(source); | 1211 CompileRun(source); |
1219 } | 1212 } |
1220 | 1213 |
1221 // Check function is compiled. | 1214 // Check function is compiled. |
1222 Object* func_value = Isolate::Current()->context()->global_object()-> | 1215 Object* func_value = Isolate::Current()->context()->global_object()-> |
1223 GetProperty(*foo_name)->ToObjectChecked(); | 1216 GetProperty(*foo_name)->ToObjectChecked(); |
1224 CHECK(func_value->IsJSFunction()); | 1217 CHECK(func_value->IsJSFunction()); |
1225 Handle<JSFunction> function(JSFunction::cast(func_value)); | 1218 Handle<JSFunction> function(JSFunction::cast(func_value)); |
1226 CHECK(function->shared()->is_compiled()); | 1219 CHECK(function->shared()->is_compiled()); |
1227 | 1220 |
(...skipping 16 matching lines...) Expand all Loading... |
1244 // Enable the debugger and add a breakpoint while incremental marking | 1237 // Enable the debugger and add a breakpoint while incremental marking |
1245 // is running so that incremental marking aborts and code flushing is | 1238 // is running so that incremental marking aborts and code flushing is |
1246 // disabled. | 1239 // disabled. |
1247 int position = 0; | 1240 int position = 0; |
1248 Handle<Object> breakpoint_object(Smi::FromInt(0), isolate); | 1241 Handle<Object> breakpoint_object(Smi::FromInt(0), isolate); |
1249 isolate->debug()->SetBreakPoint(function, breakpoint_object, &position); | 1242 isolate->debug()->SetBreakPoint(function, breakpoint_object, &position); |
1250 isolate->debug()->ClearAllBreakPoints(); | 1243 isolate->debug()->ClearAllBreakPoints(); |
1251 #endif // ENABLE_DEBUGGER_SUPPORT | 1244 #endif // ENABLE_DEBUGGER_SUPPORT |
1252 | 1245 |
1253 // Force optimization now that code flushing is disabled. | 1246 // Force optimization now that code flushing is disabled. |
1254 { v8::HandleScope scope(env->GetIsolate()); | 1247 { v8::HandleScope scope(CcTest::isolate()); |
1255 CompileRun("%OptimizeFunctionOnNextCall(foo); foo();"); | 1248 CompileRun("%OptimizeFunctionOnNextCall(foo); foo();"); |
1256 } | 1249 } |
1257 | 1250 |
1258 // Simulate one final GC to make sure the candidate queue is sane. | 1251 // Simulate one final GC to make sure the candidate queue is sane. |
1259 heap->CollectAllGarbage(Heap::kNoGCFlags); | 1252 heap->CollectAllGarbage(Heap::kNoGCFlags); |
1260 CHECK(function->shared()->is_compiled() || !function->IsOptimized()); | 1253 CHECK(function->shared()->is_compiled() || !function->IsOptimized()); |
1261 CHECK(function->is_compiled() || !function->IsOptimized()); | 1254 CHECK(function->is_compiled() || !function->IsOptimized()); |
1262 } | 1255 } |
1263 | 1256 |
1264 | 1257 |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1516 | 1509 |
1517 // Advancing the sweeper step-wise should not change the heap size. | 1510 // Advancing the sweeper step-wise should not change the heap size. |
1518 while (!HEAP->old_pointer_space()->IsLazySweepingComplete()) { | 1511 while (!HEAP->old_pointer_space()->IsLazySweepingComplete()) { |
1519 HEAP->old_pointer_space()->AdvanceSweeper(KB); | 1512 HEAP->old_pointer_space()->AdvanceSweeper(KB); |
1520 CHECK_EQ(initial_size, static_cast<int>(HEAP->SizeOfObjects())); | 1513 CHECK_EQ(initial_size, static_cast<int>(HEAP->SizeOfObjects())); |
1521 } | 1514 } |
1522 } | 1515 } |
1523 | 1516 |
1524 | 1517 |
1525 TEST(TestSizeOfObjectsVsHeapIteratorPrecision) { | 1518 TEST(TestSizeOfObjectsVsHeapIteratorPrecision) { |
1526 InitializeVM(); | 1519 CcTest::InitializeVM(); |
1527 HEAP->EnsureHeapIsIterable(); | 1520 HEAP->EnsureHeapIsIterable(); |
1528 intptr_t size_of_objects_1 = HEAP->SizeOfObjects(); | 1521 intptr_t size_of_objects_1 = HEAP->SizeOfObjects(); |
1529 HeapIterator iterator(HEAP); | 1522 HeapIterator iterator(HEAP); |
1530 intptr_t size_of_objects_2 = 0; | 1523 intptr_t size_of_objects_2 = 0; |
1531 for (HeapObject* obj = iterator.next(); | 1524 for (HeapObject* obj = iterator.next(); |
1532 obj != NULL; | 1525 obj != NULL; |
1533 obj = iterator.next()) { | 1526 obj = iterator.next()) { |
1534 if (!obj->IsFreeSpace()) { | 1527 if (!obj->IsFreeSpace()) { |
1535 size_of_objects_2 += obj->Size(); | 1528 size_of_objects_2 += obj->Size(); |
1536 } | 1529 } |
(...skipping 30 matching lines...) Expand all Loading... |
1567 AlwaysAllocateScope always_allocate; | 1560 AlwaysAllocateScope always_allocate; |
1568 intptr_t available = new_space->EffectiveCapacity() - new_space->Size(); | 1561 intptr_t available = new_space->EffectiveCapacity() - new_space->Size(); |
1569 intptr_t number_of_fillers = (available / FixedArray::SizeFor(32)) - 1; | 1562 intptr_t number_of_fillers = (available / FixedArray::SizeFor(32)) - 1; |
1570 for (intptr_t i = 0; i < number_of_fillers; i++) { | 1563 for (intptr_t i = 0; i < number_of_fillers; i++) { |
1571 CHECK(heap->InNewSpace(*factory->NewFixedArray(32, NOT_TENURED))); | 1564 CHECK(heap->InNewSpace(*factory->NewFixedArray(32, NOT_TENURED))); |
1572 } | 1565 } |
1573 } | 1566 } |
1574 | 1567 |
1575 | 1568 |
1576 TEST(GrowAndShrinkNewSpace) { | 1569 TEST(GrowAndShrinkNewSpace) { |
1577 InitializeVM(); | 1570 CcTest::InitializeVM(); |
1578 NewSpace* new_space = HEAP->new_space(); | 1571 NewSpace* new_space = HEAP->new_space(); |
1579 | 1572 |
1580 if (HEAP->ReservedSemiSpaceSize() == HEAP->InitialSemiSpaceSize() || | 1573 if (HEAP->ReservedSemiSpaceSize() == HEAP->InitialSemiSpaceSize() || |
1581 HEAP->MaxSemiSpaceSize() == HEAP->InitialSemiSpaceSize()) { | 1574 HEAP->MaxSemiSpaceSize() == HEAP->InitialSemiSpaceSize()) { |
1582 // The max size cannot exceed the reserved size, since semispaces must be | 1575 // The max size cannot exceed the reserved size, since semispaces must be |
1583 // always within the reserved space. We can't test new space growing and | 1576 // always within the reserved space. We can't test new space growing and |
1584 // shrinking if the reserved size is the same as the minimum (initial) size. | 1577 // shrinking if the reserved size is the same as the minimum (initial) size. |
1585 return; | 1578 return; |
1586 } | 1579 } |
1587 | 1580 |
(...skipping 29 matching lines...) Expand all Loading... |
1617 old_capacity = new_space->Capacity(); | 1610 old_capacity = new_space->Capacity(); |
1618 new_space->Shrink(); | 1611 new_space->Shrink(); |
1619 new_space->Shrink(); | 1612 new_space->Shrink(); |
1620 new_space->Shrink(); | 1613 new_space->Shrink(); |
1621 new_capacity = new_space->Capacity(); | 1614 new_capacity = new_space->Capacity(); |
1622 CHECK(old_capacity == new_capacity); | 1615 CHECK(old_capacity == new_capacity); |
1623 } | 1616 } |
1624 | 1617 |
1625 | 1618 |
1626 TEST(CollectingAllAvailableGarbageShrinksNewSpace) { | 1619 TEST(CollectingAllAvailableGarbageShrinksNewSpace) { |
1627 InitializeVM(); | 1620 CcTest::InitializeVM(); |
1628 | 1621 |
1629 if (HEAP->ReservedSemiSpaceSize() == HEAP->InitialSemiSpaceSize() || | 1622 if (HEAP->ReservedSemiSpaceSize() == HEAP->InitialSemiSpaceSize() || |
1630 HEAP->MaxSemiSpaceSize() == HEAP->InitialSemiSpaceSize()) { | 1623 HEAP->MaxSemiSpaceSize() == HEAP->InitialSemiSpaceSize()) { |
1631 // The max size cannot exceed the reserved size, since semispaces must be | 1624 // The max size cannot exceed the reserved size, since semispaces must be |
1632 // always within the reserved space. We can't test new space growing and | 1625 // always within the reserved space. We can't test new space growing and |
1633 // shrinking if the reserved size is the same as the minimum (initial) size. | 1626 // shrinking if the reserved size is the same as the minimum (initial) size. |
1634 return; | 1627 return; |
1635 } | 1628 } |
1636 | 1629 |
1637 v8::HandleScope scope(env->GetIsolate()); | 1630 v8::HandleScope scope(CcTest::isolate()); |
1638 NewSpace* new_space = HEAP->new_space(); | 1631 NewSpace* new_space = HEAP->new_space(); |
1639 intptr_t old_capacity, new_capacity; | 1632 intptr_t old_capacity, new_capacity; |
1640 old_capacity = new_space->Capacity(); | 1633 old_capacity = new_space->Capacity(); |
1641 new_space->Grow(); | 1634 new_space->Grow(); |
1642 new_capacity = new_space->Capacity(); | 1635 new_capacity = new_space->Capacity(); |
1643 CHECK(2 * old_capacity == new_capacity); | 1636 CHECK(2 * old_capacity == new_capacity); |
1644 FillUpNewSpace(new_space); | 1637 FillUpNewSpace(new_space); |
1645 HEAP->CollectAllAvailableGarbage(); | 1638 HEAP->CollectAllAvailableGarbage(); |
1646 new_capacity = new_space->Capacity(); | 1639 new_capacity = new_space->Capacity(); |
1647 CHECK(old_capacity == new_capacity); | 1640 CHECK(old_capacity == new_capacity); |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1809 CHECK_EQ(0, NumberOfGlobalObjects()); | 1802 CHECK_EQ(0, NumberOfGlobalObjects()); |
1810 } | 1803 } |
1811 | 1804 |
1812 | 1805 |
1813 TEST(InstanceOfStubWriteBarrier) { | 1806 TEST(InstanceOfStubWriteBarrier) { |
1814 i::FLAG_allow_natives_syntax = true; | 1807 i::FLAG_allow_natives_syntax = true; |
1815 #ifdef VERIFY_HEAP | 1808 #ifdef VERIFY_HEAP |
1816 i::FLAG_verify_heap = true; | 1809 i::FLAG_verify_heap = true; |
1817 #endif | 1810 #endif |
1818 | 1811 |
1819 InitializeVM(); | 1812 CcTest::InitializeVM(); |
1820 if (!i::V8::UseCrankshaft()) return; | 1813 if (!i::V8::UseCrankshaft()) return; |
1821 if (i::FLAG_force_marking_deque_overflows) return; | 1814 if (i::FLAG_force_marking_deque_overflows) return; |
1822 v8::HandleScope outer_scope(v8::Isolate::GetCurrent()); | 1815 v8::HandleScope outer_scope(v8::Isolate::GetCurrent()); |
1823 | 1816 |
1824 { | 1817 { |
1825 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 1818 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
1826 CompileRun( | 1819 CompileRun( |
1827 "function foo () { }" | 1820 "function foo () { }" |
1828 "function mkbar () { return new (new Function(\"\")) (); }" | 1821 "function mkbar () { return new (new Function(\"\")) (); }" |
1829 "function f (x) { return (x instanceof foo); }" | 1822 "function f (x) { return (x instanceof foo); }" |
(...skipping 30 matching lines...) Expand all Loading... |
1860 v8::Handle<v8::Function>::Cast(global->Get(v8_str("g"))); | 1853 v8::Handle<v8::Function>::Cast(global->Get(v8_str("g"))); |
1861 g->Call(global, 0, NULL); | 1854 g->Call(global, 0, NULL); |
1862 } | 1855 } |
1863 | 1856 |
1864 HEAP->incremental_marking()->set_should_hurry(true); | 1857 HEAP->incremental_marking()->set_should_hurry(true); |
1865 HEAP->CollectGarbage(OLD_POINTER_SPACE); | 1858 HEAP->CollectGarbage(OLD_POINTER_SPACE); |
1866 } | 1859 } |
1867 | 1860 |
1868 | 1861 |
1869 TEST(PrototypeTransitionClearing) { | 1862 TEST(PrototypeTransitionClearing) { |
1870 InitializeVM(); | 1863 CcTest::InitializeVM(); |
1871 v8::HandleScope scope(env->GetIsolate()); | 1864 v8::HandleScope scope(CcTest::isolate()); |
1872 | 1865 |
1873 CompileRun( | 1866 CompileRun( |
1874 "var base = {};" | 1867 "var base = {};" |
1875 "var live = [];" | 1868 "var live = [];" |
1876 "for (var i = 0; i < 10; i++) {" | 1869 "for (var i = 0; i < 10; i++) {" |
1877 " var object = {};" | 1870 " var object = {};" |
1878 " var prototype = {};" | 1871 " var prototype = {};" |
1879 " object.__proto__ = prototype;" | 1872 " object.__proto__ = prototype;" |
1880 " if (i >= 3) live.push(object, prototype);" | 1873 " if (i >= 3) live.push(object, prototype);" |
1881 "}"); | 1874 "}"); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1923 CHECK(map->GetPrototypeTransition(*prototype)->IsMap()); | 1916 CHECK(map->GetPrototypeTransition(*prototype)->IsMap()); |
1924 } | 1917 } |
1925 | 1918 |
1926 | 1919 |
1927 TEST(ResetSharedFunctionInfoCountersDuringIncrementalMarking) { | 1920 TEST(ResetSharedFunctionInfoCountersDuringIncrementalMarking) { |
1928 i::FLAG_allow_natives_syntax = true; | 1921 i::FLAG_allow_natives_syntax = true; |
1929 #ifdef VERIFY_HEAP | 1922 #ifdef VERIFY_HEAP |
1930 i::FLAG_verify_heap = true; | 1923 i::FLAG_verify_heap = true; |
1931 #endif | 1924 #endif |
1932 | 1925 |
1933 InitializeVM(); | 1926 CcTest::InitializeVM(); |
1934 if (!i::V8::UseCrankshaft()) return; | 1927 if (!i::V8::UseCrankshaft()) return; |
1935 v8::HandleScope outer_scope(v8::Isolate::GetCurrent()); | 1928 v8::HandleScope outer_scope(v8::Isolate::GetCurrent()); |
1936 | 1929 |
1937 { | 1930 { |
1938 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 1931 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
1939 CompileRun( | 1932 CompileRun( |
1940 "function f () {" | 1933 "function f () {" |
1941 " var s = 0;" | 1934 " var s = 0;" |
1942 " for (var i = 0; i < 100; i++) s += i;" | 1935 " for (var i = 0; i < 100; i++) s += i;" |
1943 " return s;" | 1936 " return s;" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1979 CHECK_EQ(0, f->shared()->code()->profiler_ticks()); | 1972 CHECK_EQ(0, f->shared()->code()->profiler_ticks()); |
1980 } | 1973 } |
1981 | 1974 |
1982 | 1975 |
1983 TEST(ResetSharedFunctionInfoCountersDuringMarkSweep) { | 1976 TEST(ResetSharedFunctionInfoCountersDuringMarkSweep) { |
1984 i::FLAG_allow_natives_syntax = true; | 1977 i::FLAG_allow_natives_syntax = true; |
1985 #ifdef VERIFY_HEAP | 1978 #ifdef VERIFY_HEAP |
1986 i::FLAG_verify_heap = true; | 1979 i::FLAG_verify_heap = true; |
1987 #endif | 1980 #endif |
1988 | 1981 |
1989 InitializeVM(); | 1982 CcTest::InitializeVM(); |
1990 if (!i::V8::UseCrankshaft()) return; | 1983 if (!i::V8::UseCrankshaft()) return; |
1991 v8::HandleScope outer_scope(env->GetIsolate()); | 1984 v8::HandleScope outer_scope(CcTest::isolate()); |
1992 | 1985 |
1993 { | 1986 { |
1994 v8::HandleScope scope(env->GetIsolate()); | 1987 v8::HandleScope scope(CcTest::isolate()); |
1995 CompileRun( | 1988 CompileRun( |
1996 "function f () {" | 1989 "function f () {" |
1997 " var s = 0;" | 1990 " var s = 0;" |
1998 " for (var i = 0; i < 100; i++) s += i;" | 1991 " for (var i = 0; i < 100; i++) s += i;" |
1999 " return s;" | 1992 " return s;" |
2000 "}" | 1993 "}" |
2001 "f(); f();" | 1994 "f(); f();" |
2002 "%OptimizeFunctionOnNextCall(f);" | 1995 "%OptimizeFunctionOnNextCall(f);" |
2003 "f();"); | 1996 "f();"); |
2004 } | 1997 } |
(...skipping 13 matching lines...) Expand all Loading... |
2018 | 2011 |
2019 CHECK_EQ(HEAP->global_ic_age(), f->shared()->ic_age()); | 2012 CHECK_EQ(HEAP->global_ic_age(), f->shared()->ic_age()); |
2020 CHECK_EQ(0, f->shared()->opt_count()); | 2013 CHECK_EQ(0, f->shared()->opt_count()); |
2021 CHECK_EQ(0, f->shared()->code()->profiler_ticks()); | 2014 CHECK_EQ(0, f->shared()->code()->profiler_ticks()); |
2022 } | 2015 } |
2023 | 2016 |
2024 | 2017 |
2025 // Test that HAllocateObject will always return an object in new-space. | 2018 // Test that HAllocateObject will always return an object in new-space. |
2026 TEST(OptimizedAllocationAlwaysInNewSpace) { | 2019 TEST(OptimizedAllocationAlwaysInNewSpace) { |
2027 i::FLAG_allow_natives_syntax = true; | 2020 i::FLAG_allow_natives_syntax = true; |
2028 InitializeVM(); | 2021 CcTest::InitializeVM(); |
2029 if (!i::V8::UseCrankshaft() || i::FLAG_always_opt) return; | 2022 if (!i::V8::UseCrankshaft() || i::FLAG_always_opt) return; |
2030 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; | 2023 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; |
2031 v8::HandleScope scope(env->GetIsolate()); | 2024 v8::HandleScope scope(CcTest::isolate()); |
2032 | 2025 |
2033 SimulateFullSpace(HEAP->new_space()); | 2026 SimulateFullSpace(HEAP->new_space()); |
2034 AlwaysAllocateScope always_allocate; | 2027 AlwaysAllocateScope always_allocate; |
2035 v8::Local<v8::Value> res = CompileRun( | 2028 v8::Local<v8::Value> res = CompileRun( |
2036 "function c(x) {" | 2029 "function c(x) {" |
2037 " this.x = x;" | 2030 " this.x = x;" |
2038 " for (var i = 0; i < 32; i++) {" | 2031 " for (var i = 0; i < 32; i++) {" |
2039 " this['x' + i] = x;" | 2032 " this['x' + i] = x;" |
2040 " }" | 2033 " }" |
2041 "}" | 2034 "}" |
2042 "function f(x) { return new c(x); };" | 2035 "function f(x) { return new c(x); };" |
2043 "f(1); f(2); f(3);" | 2036 "f(1); f(2); f(3);" |
2044 "%OptimizeFunctionOnNextCall(f);" | 2037 "%OptimizeFunctionOnNextCall(f);" |
2045 "f(4);"); | 2038 "f(4);"); |
2046 CHECK_EQ(4, res->ToObject()->GetRealNamedProperty(v8_str("x"))->Int32Value()); | 2039 CHECK_EQ(4, res->ToObject()->GetRealNamedProperty(v8_str("x"))->Int32Value()); |
2047 | 2040 |
2048 Handle<JSObject> o = | 2041 Handle<JSObject> o = |
2049 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); | 2042 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); |
2050 | 2043 |
2051 CHECK(HEAP->InNewSpace(*o)); | 2044 CHECK(HEAP->InNewSpace(*o)); |
2052 } | 2045 } |
2053 | 2046 |
2054 | 2047 |
2055 // Test pretenuring of array literals allocated with HAllocate. | 2048 // Test pretenuring of array literals allocated with HAllocate. |
2056 TEST(OptimizedPretenuringArrayLiterals) { | 2049 TEST(OptimizedPretenuringArrayLiterals) { |
2057 i::FLAG_allow_natives_syntax = true; | 2050 i::FLAG_allow_natives_syntax = true; |
2058 i::FLAG_pretenure_literals = true; | 2051 i::FLAG_pretenure_literals = true; |
2059 InitializeVM(); | 2052 CcTest::InitializeVM(); |
2060 if (!i::V8::UseCrankshaft() || i::FLAG_always_opt) return; | 2053 if (!i::V8::UseCrankshaft() || i::FLAG_always_opt) return; |
2061 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; | 2054 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; |
2062 v8::HandleScope scope(env->GetIsolate()); | 2055 v8::HandleScope scope(CcTest::isolate()); |
2063 | 2056 |
2064 AlwaysAllocateScope always_allocate; | 2057 AlwaysAllocateScope always_allocate; |
2065 v8::Local<v8::Value> res = CompileRun( | 2058 v8::Local<v8::Value> res = CompileRun( |
2066 "function f() {" | 2059 "function f() {" |
2067 " var numbers = [1, 2, 3];" | 2060 " var numbers = [1, 2, 3];" |
2068 " numbers[0] = {};" | 2061 " numbers[0] = {};" |
2069 " return numbers;" | 2062 " return numbers;" |
2070 "};" | 2063 "};" |
2071 "f(); f(); f();" | 2064 "f(); f(); f();" |
2072 "%OptimizeFunctionOnNextCall(f);" | 2065 "%OptimizeFunctionOnNextCall(f);" |
2073 "f();"); | 2066 "f();"); |
2074 | 2067 |
2075 Handle<JSObject> o = | 2068 Handle<JSObject> o = |
2076 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); | 2069 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); |
2077 | 2070 |
2078 CHECK(HEAP->InOldPointerSpace(o->elements())); | 2071 CHECK(HEAP->InOldPointerSpace(o->elements())); |
2079 } | 2072 } |
2080 | 2073 |
2081 | 2074 |
2082 // Test regular array literals allocation. | 2075 // Test regular array literals allocation. |
2083 TEST(OptimizedAllocationArrayLiterals) { | 2076 TEST(OptimizedAllocationArrayLiterals) { |
2084 i::FLAG_allow_natives_syntax = true; | 2077 i::FLAG_allow_natives_syntax = true; |
2085 InitializeVM(); | 2078 CcTest::InitializeVM(); |
2086 if (!i::V8::UseCrankshaft() || i::FLAG_always_opt) return; | 2079 if (!i::V8::UseCrankshaft() || i::FLAG_always_opt) return; |
2087 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; | 2080 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; |
2088 v8::HandleScope scope(env->GetIsolate()); | 2081 v8::HandleScope scope(CcTest::isolate()); |
2089 | 2082 |
2090 AlwaysAllocateScope always_allocate; | 2083 AlwaysAllocateScope always_allocate; |
2091 v8::Local<v8::Value> res = CompileRun( | 2084 v8::Local<v8::Value> res = CompileRun( |
2092 "function f() {" | 2085 "function f() {" |
2093 " var numbers = new Array(1, 2, 3);" | 2086 " var numbers = new Array(1, 2, 3);" |
2094 " numbers[0] = 3.14;" | 2087 " numbers[0] = 3.14;" |
2095 " return numbers;" | 2088 " return numbers;" |
2096 "};" | 2089 "};" |
2097 "f(); f(); f();" | 2090 "f(); f(); f();" |
2098 "%OptimizeFunctionOnNextCall(f);" | 2091 "%OptimizeFunctionOnNextCall(f);" |
(...skipping 11 matching lines...) Expand all Loading... |
2110 static int CountMapTransitions(Map* map) { | 2103 static int CountMapTransitions(Map* map) { |
2111 return map->transitions()->number_of_transitions(); | 2104 return map->transitions()->number_of_transitions(); |
2112 } | 2105 } |
2113 | 2106 |
2114 | 2107 |
2115 // Test that map transitions are cleared and maps are collected with | 2108 // Test that map transitions are cleared and maps are collected with |
2116 // incremental marking as well. | 2109 // incremental marking as well. |
2117 TEST(Regress1465) { | 2110 TEST(Regress1465) { |
2118 i::FLAG_allow_natives_syntax = true; | 2111 i::FLAG_allow_natives_syntax = true; |
2119 i::FLAG_trace_incremental_marking = true; | 2112 i::FLAG_trace_incremental_marking = true; |
2120 InitializeVM(); | 2113 CcTest::InitializeVM(); |
2121 v8::HandleScope scope(env->GetIsolate()); | 2114 v8::HandleScope scope(CcTest::isolate()); |
2122 static const int transitions_count = 256; | 2115 static const int transitions_count = 256; |
2123 | 2116 |
2124 { | 2117 { |
2125 AlwaysAllocateScope always_allocate; | 2118 AlwaysAllocateScope always_allocate; |
2126 for (int i = 0; i < transitions_count; i++) { | 2119 for (int i = 0; i < transitions_count; i++) { |
2127 EmbeddedVector<char, 64> buffer; | 2120 EmbeddedVector<char, 64> buffer; |
2128 OS::SNPrintF(buffer, "var o = new Object; o.prop%d = %d;", i, i); | 2121 OS::SNPrintF(buffer, "var o = new Object; o.prop%d = %d;", i, i); |
2129 CompileRun(buffer.start()); | 2122 CompileRun(buffer.start()); |
2130 } | 2123 } |
2131 CompileRun("var root = new Object;"); | 2124 CompileRun("var root = new Object;"); |
(...skipping 16 matching lines...) Expand all Loading... |
2148 // is left, because 'o' still holds an instance of one transition target. | 2141 // is left, because 'o' still holds an instance of one transition target. |
2149 int transitions_after = CountMapTransitions(root->map()); | 2142 int transitions_after = CountMapTransitions(root->map()); |
2150 CompileRun("%DebugPrint(root);"); | 2143 CompileRun("%DebugPrint(root);"); |
2151 CHECK_EQ(1, transitions_after); | 2144 CHECK_EQ(1, transitions_after); |
2152 } | 2145 } |
2153 | 2146 |
2154 | 2147 |
2155 TEST(Regress2143a) { | 2148 TEST(Regress2143a) { |
2156 i::FLAG_collect_maps = true; | 2149 i::FLAG_collect_maps = true; |
2157 i::FLAG_incremental_marking = true; | 2150 i::FLAG_incremental_marking = true; |
2158 InitializeVM(); | 2151 CcTest::InitializeVM(); |
2159 v8::HandleScope scope(env->GetIsolate()); | 2152 v8::HandleScope scope(CcTest::isolate()); |
2160 | 2153 |
2161 // Prepare a map transition from the root object together with a yet | 2154 // Prepare a map transition from the root object together with a yet |
2162 // untransitioned root object. | 2155 // untransitioned root object. |
2163 CompileRun("var root = new Object;" | 2156 CompileRun("var root = new Object;" |
2164 "root.foo = 0;" | 2157 "root.foo = 0;" |
2165 "root = new Object;"); | 2158 "root = new Object;"); |
2166 | 2159 |
2167 SimulateIncrementalMarking(); | 2160 SimulateIncrementalMarking(); |
2168 | 2161 |
2169 // Compile a StoreIC that performs the prepared map transition. This | 2162 // Compile a StoreIC that performs the prepared map transition. This |
(...skipping 19 matching lines...) Expand all Loading... |
2189 // The root object should be in a sane state. | 2182 // The root object should be in a sane state. |
2190 CHECK(root->IsJSObject()); | 2183 CHECK(root->IsJSObject()); |
2191 CHECK(root->map()->IsMap()); | 2184 CHECK(root->map()->IsMap()); |
2192 } | 2185 } |
2193 | 2186 |
2194 | 2187 |
2195 TEST(Regress2143b) { | 2188 TEST(Regress2143b) { |
2196 i::FLAG_collect_maps = true; | 2189 i::FLAG_collect_maps = true; |
2197 i::FLAG_incremental_marking = true; | 2190 i::FLAG_incremental_marking = true; |
2198 i::FLAG_allow_natives_syntax = true; | 2191 i::FLAG_allow_natives_syntax = true; |
2199 InitializeVM(); | 2192 CcTest::InitializeVM(); |
2200 v8::HandleScope scope(env->GetIsolate()); | 2193 v8::HandleScope scope(CcTest::isolate()); |
2201 | 2194 |
2202 // Prepare a map transition from the root object together with a yet | 2195 // Prepare a map transition from the root object together with a yet |
2203 // untransitioned root object. | 2196 // untransitioned root object. |
2204 CompileRun("var root = new Object;" | 2197 CompileRun("var root = new Object;" |
2205 "root.foo = 0;" | 2198 "root.foo = 0;" |
2206 "root = new Object;"); | 2199 "root = new Object;"); |
2207 | 2200 |
2208 SimulateIncrementalMarking(); | 2201 SimulateIncrementalMarking(); |
2209 | 2202 |
2210 // Compile an optimized LStoreNamedField that performs the prepared | 2203 // Compile an optimized LStoreNamedField that performs the prepared |
(...skipping 23 matching lines...) Expand all Loading... |
2234 CHECK(root->IsJSObject()); | 2227 CHECK(root->IsJSObject()); |
2235 CHECK(root->map()->IsMap()); | 2228 CHECK(root->map()->IsMap()); |
2236 } | 2229 } |
2237 | 2230 |
2238 | 2231 |
2239 TEST(ReleaseOverReservedPages) { | 2232 TEST(ReleaseOverReservedPages) { |
2240 i::FLAG_trace_gc = true; | 2233 i::FLAG_trace_gc = true; |
2241 // The optimizer can allocate stuff, messing up the test. | 2234 // The optimizer can allocate stuff, messing up the test. |
2242 i::FLAG_crankshaft = false; | 2235 i::FLAG_crankshaft = false; |
2243 i::FLAG_always_opt = false; | 2236 i::FLAG_always_opt = false; |
2244 InitializeVM(); | 2237 CcTest::InitializeVM(); |
2245 v8::HandleScope scope(env->GetIsolate()); | 2238 v8::HandleScope scope(CcTest::isolate()); |
2246 static const int number_of_test_pages = 20; | 2239 static const int number_of_test_pages = 20; |
2247 | 2240 |
2248 // Prepare many pages with low live-bytes count. | 2241 // Prepare many pages with low live-bytes count. |
2249 PagedSpace* old_pointer_space = HEAP->old_pointer_space(); | 2242 PagedSpace* old_pointer_space = HEAP->old_pointer_space(); |
2250 CHECK_EQ(1, old_pointer_space->CountTotalPages()); | 2243 CHECK_EQ(1, old_pointer_space->CountTotalPages()); |
2251 for (int i = 0; i < number_of_test_pages; i++) { | 2244 for (int i = 0; i < number_of_test_pages; i++) { |
2252 AlwaysAllocateScope always_allocate; | 2245 AlwaysAllocateScope always_allocate; |
2253 SimulateFullSpace(old_pointer_space); | 2246 SimulateFullSpace(old_pointer_space); |
2254 FACTORY->NewFixedArray(1, TENURED); | 2247 FACTORY->NewFixedArray(1, TENURED); |
2255 } | 2248 } |
(...skipping 17 matching lines...) Expand all Loading... |
2273 // size of the first page a little in SizeOfFirstPage in spaces.cc. The | 2266 // size of the first page a little in SizeOfFirstPage in spaces.cc. The |
2274 // first page should be small in order to reduce memory used when the VM | 2267 // first page should be small in order to reduce memory used when the VM |
2275 // boots, but if the 20 small arrays don't fit on the first page then that's | 2268 // boots, but if the 20 small arrays don't fit on the first page then that's |
2276 // an indication that it is too small. | 2269 // an indication that it is too small. |
2277 HEAP->CollectAllAvailableGarbage("triggered really hard"); | 2270 HEAP->CollectAllAvailableGarbage("triggered really hard"); |
2278 CHECK_EQ(1, old_pointer_space->CountTotalPages()); | 2271 CHECK_EQ(1, old_pointer_space->CountTotalPages()); |
2279 } | 2272 } |
2280 | 2273 |
2281 | 2274 |
2282 TEST(Regress2237) { | 2275 TEST(Regress2237) { |
2283 InitializeVM(); | 2276 CcTest::InitializeVM(); |
2284 v8::HandleScope scope(env->GetIsolate()); | 2277 v8::HandleScope scope(CcTest::isolate()); |
2285 Handle<String> slice(HEAP->empty_string()); | 2278 Handle<String> slice(HEAP->empty_string()); |
2286 | 2279 |
2287 { | 2280 { |
2288 // Generate a parent that lives in new-space. | 2281 // Generate a parent that lives in new-space. |
2289 v8::HandleScope inner_scope(env->GetIsolate()); | 2282 v8::HandleScope inner_scope(CcTest::isolate()); |
2290 const char* c = "This text is long enough to trigger sliced strings."; | 2283 const char* c = "This text is long enough to trigger sliced strings."; |
2291 Handle<String> s = FACTORY->NewStringFromAscii(CStrVector(c)); | 2284 Handle<String> s = FACTORY->NewStringFromAscii(CStrVector(c)); |
2292 CHECK(s->IsSeqOneByteString()); | 2285 CHECK(s->IsSeqOneByteString()); |
2293 CHECK(HEAP->InNewSpace(*s)); | 2286 CHECK(HEAP->InNewSpace(*s)); |
2294 | 2287 |
2295 // Generate a sliced string that is based on the above parent and | 2288 // Generate a sliced string that is based on the above parent and |
2296 // lives in old-space. | 2289 // lives in old-space. |
2297 SimulateFullSpace(HEAP->new_space()); | 2290 SimulateFullSpace(HEAP->new_space()); |
2298 AlwaysAllocateScope always_allocate; | 2291 AlwaysAllocateScope always_allocate; |
2299 Handle<String> t = FACTORY->NewProperSubString(s, 5, 35); | 2292 Handle<String> t = FACTORY->NewProperSubString(s, 5, 35); |
2300 CHECK(t->IsSlicedString()); | 2293 CHECK(t->IsSlicedString()); |
2301 CHECK(!HEAP->InNewSpace(*t)); | 2294 CHECK(!HEAP->InNewSpace(*t)); |
2302 *slice.location() = *t.location(); | 2295 *slice.location() = *t.location(); |
2303 } | 2296 } |
2304 | 2297 |
2305 CHECK(SlicedString::cast(*slice)->parent()->IsSeqOneByteString()); | 2298 CHECK(SlicedString::cast(*slice)->parent()->IsSeqOneByteString()); |
2306 HEAP->CollectAllGarbage(Heap::kNoGCFlags); | 2299 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
2307 CHECK(SlicedString::cast(*slice)->parent()->IsSeqOneByteString()); | 2300 CHECK(SlicedString::cast(*slice)->parent()->IsSeqOneByteString()); |
2308 } | 2301 } |
2309 | 2302 |
2310 | 2303 |
2311 #ifdef OBJECT_PRINT | 2304 #ifdef OBJECT_PRINT |
2312 TEST(PrintSharedFunctionInfo) { | 2305 TEST(PrintSharedFunctionInfo) { |
2313 InitializeVM(); | 2306 CcTest::InitializeVM(); |
2314 v8::HandleScope scope(env->GetIsolate()); | 2307 v8::HandleScope scope(CcTest::isolate()); |
2315 const char* source = "f = function() { return 987654321; }\n" | 2308 const char* source = "f = function() { return 987654321; }\n" |
2316 "g = function() { return 123456789; }\n"; | 2309 "g = function() { return 123456789; }\n"; |
2317 CompileRun(source); | 2310 CompileRun(source); |
2318 Handle<JSFunction> g = | 2311 Handle<JSFunction> g = |
2319 v8::Utils::OpenHandle( | 2312 v8::Utils::OpenHandle( |
2320 *v8::Handle<v8::Function>::Cast( | 2313 *v8::Handle<v8::Function>::Cast( |
2321 v8::Context::GetCurrent()->Global()->Get(v8_str("g")))); | 2314 v8::Context::GetCurrent()->Global()->Get(v8_str("g")))); |
2322 | 2315 |
2323 AssertNoAllocation no_alloc; | 2316 AssertNoAllocation no_alloc; |
2324 g->shared()->PrintLn(); | 2317 g->shared()->PrintLn(); |
2325 } | 2318 } |
2326 #endif // OBJECT_PRINT | 2319 #endif // OBJECT_PRINT |
2327 | 2320 |
2328 | 2321 |
2329 TEST(Regress2211) { | 2322 TEST(Regress2211) { |
2330 InitializeVM(); | 2323 CcTest::InitializeVM(); |
2331 v8::HandleScope scope(env->GetIsolate()); | 2324 v8::HandleScope scope(CcTest::isolate()); |
2332 | 2325 |
2333 v8::Handle<v8::String> value = v8_str("val string"); | 2326 v8::Handle<v8::String> value = v8_str("val string"); |
2334 Smi* hash = Smi::FromInt(321); | 2327 Smi* hash = Smi::FromInt(321); |
2335 Heap* heap = Isolate::Current()->heap(); | 2328 Heap* heap = Isolate::Current()->heap(); |
2336 | 2329 |
2337 for (int i = 0; i < 2; i++) { | 2330 for (int i = 0; i < 2; i++) { |
2338 // Store identity hash first and common hidden property second. | 2331 // Store identity hash first and common hidden property second. |
2339 v8::Handle<v8::Object> obj = v8::Object::New(); | 2332 v8::Handle<v8::Object> obj = v8::Object::New(); |
2340 Handle<JSObject> internal_obj = v8::Utils::OpenHandle(*obj); | 2333 Handle<JSObject> internal_obj = v8::Utils::OpenHandle(*obj); |
2341 CHECK(internal_obj->HasFastProperties()); | 2334 CHECK(internal_obj->HasFastProperties()); |
(...skipping 16 matching lines...) Expand all Loading... |
2358 ObjectHashTable* hashtable = ObjectHashTable::cast( | 2351 ObjectHashTable* hashtable = ObjectHashTable::cast( |
2359 internal_obj->FastPropertyAt(descriptors->GetFieldIndex(0))); | 2352 internal_obj->FastPropertyAt(descriptors->GetFieldIndex(0))); |
2360 // HashTable header (5) and 4 initial entries (8). | 2353 // HashTable header (5) and 4 initial entries (8). |
2361 CHECK_LE(hashtable->SizeFor(hashtable->length()), 13 * kPointerSize); | 2354 CHECK_LE(hashtable->SizeFor(hashtable->length()), 13 * kPointerSize); |
2362 } | 2355 } |
2363 } | 2356 } |
2364 | 2357 |
2365 | 2358 |
2366 TEST(IncrementalMarkingClearsTypeFeedbackCells) { | 2359 TEST(IncrementalMarkingClearsTypeFeedbackCells) { |
2367 if (i::FLAG_always_opt) return; | 2360 if (i::FLAG_always_opt) return; |
2368 InitializeVM(); | 2361 CcTest::InitializeVM(); |
2369 v8::HandleScope scope(env->GetIsolate()); | 2362 v8::HandleScope scope(CcTest::isolate()); |
2370 v8::Local<v8::Value> fun1, fun2; | 2363 v8::Local<v8::Value> fun1, fun2; |
2371 | 2364 |
2372 { | 2365 { |
2373 LocalContext env; | 2366 LocalContext env; |
2374 CompileRun("function fun() {};"); | 2367 CompileRun("function fun() {};"); |
2375 fun1 = env->Global()->Get(v8_str("fun")); | 2368 fun1 = env->Global()->Get(v8_str("fun")); |
2376 } | 2369 } |
2377 | 2370 |
2378 { | 2371 { |
2379 LocalContext env; | 2372 LocalContext env; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2417 if (target->is_inline_cache_stub() && target->kind() == kind) { | 2410 if (target->is_inline_cache_stub() && target->kind() == kind) { |
2418 return target; | 2411 return target; |
2419 } | 2412 } |
2420 } | 2413 } |
2421 return NULL; | 2414 return NULL; |
2422 } | 2415 } |
2423 | 2416 |
2424 | 2417 |
2425 TEST(IncrementalMarkingPreservesMonomorhpicIC) { | 2418 TEST(IncrementalMarkingPreservesMonomorhpicIC) { |
2426 if (i::FLAG_always_opt) return; | 2419 if (i::FLAG_always_opt) return; |
2427 InitializeVM(); | 2420 CcTest::InitializeVM(); |
2428 v8::HandleScope scope(env->GetIsolate()); | 2421 v8::HandleScope scope(CcTest::isolate()); |
2429 | 2422 |
2430 // Prepare function f that contains a monomorphic IC for object | 2423 // Prepare function f that contains a monomorphic IC for object |
2431 // originating from the same native context. | 2424 // originating from the same native context. |
2432 CompileRun("function fun() { this.x = 1; }; var obj = new fun();" | 2425 CompileRun("function fun() { this.x = 1; }; var obj = new fun();" |
2433 "function f(o) { return o.x; } f(obj); f(obj);"); | 2426 "function f(o) { return o.x; } f(obj); f(obj);"); |
2434 Handle<JSFunction> f = | 2427 Handle<JSFunction> f = |
2435 v8::Utils::OpenHandle( | 2428 v8::Utils::OpenHandle( |
2436 *v8::Handle<v8::Function>::Cast( | 2429 *v8::Handle<v8::Function>::Cast( |
2437 v8::Context::GetCurrent()->Global()->Get(v8_str("f")))); | 2430 v8::Context::GetCurrent()->Global()->Get(v8_str("f")))); |
2438 | 2431 |
2439 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 2432 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); |
2440 CHECK(ic_before->ic_state() == MONOMORPHIC); | 2433 CHECK(ic_before->ic_state() == MONOMORPHIC); |
2441 | 2434 |
2442 SimulateIncrementalMarking(); | 2435 SimulateIncrementalMarking(); |
2443 HEAP->CollectAllGarbage(Heap::kNoGCFlags); | 2436 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
2444 | 2437 |
2445 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 2438 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); |
2446 CHECK(ic_after->ic_state() == MONOMORPHIC); | 2439 CHECK(ic_after->ic_state() == MONOMORPHIC); |
2447 } | 2440 } |
2448 | 2441 |
2449 | 2442 |
2450 TEST(IncrementalMarkingClearsMonomorhpicIC) { | 2443 TEST(IncrementalMarkingClearsMonomorhpicIC) { |
2451 if (i::FLAG_always_opt) return; | 2444 if (i::FLAG_always_opt) return; |
2452 InitializeVM(); | 2445 CcTest::InitializeVM(); |
2453 v8::HandleScope scope(env->GetIsolate()); | 2446 v8::HandleScope scope(CcTest::isolate()); |
2454 v8::Local<v8::Value> obj1; | 2447 v8::Local<v8::Value> obj1; |
2455 | 2448 |
2456 { | 2449 { |
2457 LocalContext env; | 2450 LocalContext env; |
2458 CompileRun("function fun() { this.x = 1; }; var obj = new fun();"); | 2451 CompileRun("function fun() { this.x = 1; }; var obj = new fun();"); |
2459 obj1 = env->Global()->Get(v8_str("obj")); | 2452 obj1 = env->Global()->Get(v8_str("obj")); |
2460 } | 2453 } |
2461 | 2454 |
2462 // Prepare function f that contains a monomorphic IC for object | 2455 // Prepare function f that contains a monomorphic IC for object |
2463 // originating from a different native context. | 2456 // originating from a different native context. |
(...skipping 12 matching lines...) Expand all Loading... |
2476 SimulateIncrementalMarking(); | 2469 SimulateIncrementalMarking(); |
2477 HEAP->CollectAllGarbage(Heap::kNoGCFlags); | 2470 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
2478 | 2471 |
2479 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 2472 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); |
2480 CHECK(ic_after->ic_state() == UNINITIALIZED); | 2473 CHECK(ic_after->ic_state() == UNINITIALIZED); |
2481 } | 2474 } |
2482 | 2475 |
2483 | 2476 |
2484 TEST(IncrementalMarkingClearsPolymorhpicIC) { | 2477 TEST(IncrementalMarkingClearsPolymorhpicIC) { |
2485 if (i::FLAG_always_opt) return; | 2478 if (i::FLAG_always_opt) return; |
2486 InitializeVM(); | 2479 CcTest::InitializeVM(); |
2487 v8::HandleScope scope(env->GetIsolate()); | 2480 v8::HandleScope scope(CcTest::isolate()); |
2488 v8::Local<v8::Value> obj1, obj2; | 2481 v8::Local<v8::Value> obj1, obj2; |
2489 | 2482 |
2490 { | 2483 { |
2491 LocalContext env; | 2484 LocalContext env; |
2492 CompileRun("function fun() { this.x = 1; }; var obj = new fun();"); | 2485 CompileRun("function fun() { this.x = 1; }; var obj = new fun();"); |
2493 obj1 = env->Global()->Get(v8_str("obj")); | 2486 obj1 = env->Global()->Get(v8_str("obj")); |
2494 } | 2487 } |
2495 | 2488 |
2496 { | 2489 { |
2497 LocalContext env; | 2490 LocalContext env; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2542 const char* data_; | 2535 const char* data_; |
2543 size_t length_; | 2536 size_t length_; |
2544 }; | 2537 }; |
2545 | 2538 |
2546 | 2539 |
2547 void ReleaseStackTraceDataTest(const char* source) { | 2540 void ReleaseStackTraceDataTest(const char* source) { |
2548 // Test that the data retained by the Error.stack accessor is released | 2541 // Test that the data retained by the Error.stack accessor is released |
2549 // after the first time the accessor is fired. We use external string | 2542 // after the first time the accessor is fired. We use external string |
2550 // to check whether the data is being released since the external string | 2543 // to check whether the data is being released since the external string |
2551 // resource's callback is fired when the external string is GC'ed. | 2544 // resource's callback is fired when the external string is GC'ed. |
2552 InitializeVM(); | 2545 CcTest::InitializeVM(); |
2553 v8::HandleScope scope(env->GetIsolate()); | 2546 v8::HandleScope scope(CcTest::isolate()); |
2554 SourceResource* resource = new SourceResource(i::StrDup(source)); | 2547 SourceResource* resource = new SourceResource(i::StrDup(source)); |
2555 { | 2548 { |
2556 v8::HandleScope scope(env->GetIsolate()); | 2549 v8::HandleScope scope(CcTest::isolate()); |
2557 v8::Handle<v8::String> source_string = v8::String::NewExternal(resource); | 2550 v8::Handle<v8::String> source_string = v8::String::NewExternal(resource); |
2558 v8::Script::Compile(source_string)->Run(); | 2551 v8::Script::Compile(source_string)->Run(); |
2559 CHECK(!resource->IsDisposed()); | 2552 CHECK(!resource->IsDisposed()); |
2560 } | 2553 } |
2561 HEAP->CollectAllAvailableGarbage(); | 2554 HEAP->CollectAllAvailableGarbage(); |
2562 | 2555 |
2563 // External source has been released. | 2556 // External source has been released. |
2564 CHECK(resource->IsDisposed()); | 2557 CHECK(resource->IsDisposed()); |
2565 delete resource; | 2558 delete resource; |
2566 } | 2559 } |
(...skipping 11 matching lines...) Expand all Loading... |
2578 " (function f() { f(); })(); " | 2571 " (function f() { f(); })(); " |
2579 "} catch (e) { " | 2572 "} catch (e) { " |
2580 " error = e; " | 2573 " error = e; " |
2581 "} "; | 2574 "} "; |
2582 ReleaseStackTraceDataTest(source1); | 2575 ReleaseStackTraceDataTest(source1); |
2583 ReleaseStackTraceDataTest(source2); | 2576 ReleaseStackTraceDataTest(source2); |
2584 } | 2577 } |
2585 | 2578 |
2586 | 2579 |
2587 TEST(Regression144230) { | 2580 TEST(Regression144230) { |
2588 InitializeVM(); | 2581 CcTest::InitializeVM(); |
2589 Isolate* isolate = Isolate::Current(); | 2582 Isolate* isolate = Isolate::Current(); |
2590 Heap* heap = isolate->heap(); | 2583 Heap* heap = isolate->heap(); |
2591 HandleScope scope(isolate); | 2584 HandleScope scope(isolate); |
2592 | 2585 |
2593 // First make sure that the uninitialized CallIC stub is on a single page | 2586 // First make sure that the uninitialized CallIC stub is on a single page |
2594 // that will later be selected as an evacuation candidate. | 2587 // that will later be selected as an evacuation candidate. |
2595 { | 2588 { |
2596 HandleScope inner_scope(isolate); | 2589 HandleScope inner_scope(isolate); |
2597 AlwaysAllocateScope always_allocate; | 2590 AlwaysAllocateScope always_allocate; |
2598 SimulateFullSpace(heap->code_space()); | 2591 SimulateFullSpace(heap->code_space()); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2641 // Either heap verification caught the problem already or we go kaboom once | 2634 // Either heap verification caught the problem already or we go kaboom once |
2642 // the CallIC is executed the next time. | 2635 // the CallIC is executed the next time. |
2643 USE(global->SetProperty(*name, *call_function, NONE, kNonStrictMode)); | 2636 USE(global->SetProperty(*name, *call_function, NONE, kNonStrictMode)); |
2644 CompileRun("call();"); | 2637 CompileRun("call();"); |
2645 } | 2638 } |
2646 | 2639 |
2647 | 2640 |
2648 TEST(Regress159140) { | 2641 TEST(Regress159140) { |
2649 i::FLAG_allow_natives_syntax = true; | 2642 i::FLAG_allow_natives_syntax = true; |
2650 i::FLAG_flush_code_incrementally = true; | 2643 i::FLAG_flush_code_incrementally = true; |
2651 InitializeVM(); | 2644 CcTest::InitializeVM(); |
2652 Isolate* isolate = Isolate::Current(); | 2645 Isolate* isolate = Isolate::Current(); |
2653 Heap* heap = isolate->heap(); | 2646 Heap* heap = isolate->heap(); |
2654 HandleScope scope(isolate); | 2647 HandleScope scope(isolate); |
2655 | 2648 |
2656 // Perform one initial GC to enable code flushing. | 2649 // Perform one initial GC to enable code flushing. |
2657 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 2650 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
2658 | 2651 |
2659 // Prepare several closures that are all eligible for code flushing | 2652 // Prepare several closures that are all eligible for code flushing |
2660 // because all reachable ones are not optimized. Make sure that the | 2653 // because all reachable ones are not optimized. Make sure that the |
2661 // optimized code object is directly reachable through a handle so | 2654 // optimized code object is directly reachable through a handle so |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2703 heap->CollectAllGarbage(Heap::kNoGCFlags); | 2696 heap->CollectAllGarbage(Heap::kNoGCFlags); |
2704 | 2697 |
2705 // Unoptimized code is missing and the deoptimizer will go ballistic. | 2698 // Unoptimized code is missing and the deoptimizer will go ballistic. |
2706 CompileRun("g('bozo');"); | 2699 CompileRun("g('bozo');"); |
2707 } | 2700 } |
2708 | 2701 |
2709 | 2702 |
2710 TEST(Regress165495) { | 2703 TEST(Regress165495) { |
2711 i::FLAG_allow_natives_syntax = true; | 2704 i::FLAG_allow_natives_syntax = true; |
2712 i::FLAG_flush_code_incrementally = true; | 2705 i::FLAG_flush_code_incrementally = true; |
2713 InitializeVM(); | 2706 CcTest::InitializeVM(); |
2714 Isolate* isolate = Isolate::Current(); | 2707 Isolate* isolate = Isolate::Current(); |
2715 Heap* heap = isolate->heap(); | 2708 Heap* heap = isolate->heap(); |
2716 HandleScope scope(isolate); | 2709 HandleScope scope(isolate); |
2717 | 2710 |
2718 // Perform one initial GC to enable code flushing. | 2711 // Perform one initial GC to enable code flushing. |
2719 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 2712 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
2720 | 2713 |
2721 // Prepare an optimized closure that the optimized code map will get | 2714 // Prepare an optimized closure that the optimized code map will get |
2722 // populated. Then age the unoptimized code to trigger code flushing | 2715 // populated. Then age the unoptimized code to trigger code flushing |
2723 // but make sure the optimized code is unreachable. | 2716 // but make sure the optimized code is unreachable. |
(...skipping 27 matching lines...) Expand all Loading... |
2751 // Make a new closure that will get code installed from the code map. | 2744 // Make a new closure that will get code installed from the code map. |
2752 // Unoptimized code is missing and the deoptimizer will go ballistic. | 2745 // Unoptimized code is missing and the deoptimizer will go ballistic. |
2753 CompileRun("var g = mkClosure(); g('bozo');"); | 2746 CompileRun("var g = mkClosure(); g('bozo');"); |
2754 } | 2747 } |
2755 | 2748 |
2756 | 2749 |
2757 TEST(Regress169209) { | 2750 TEST(Regress169209) { |
2758 i::FLAG_stress_compaction = false; | 2751 i::FLAG_stress_compaction = false; |
2759 i::FLAG_allow_natives_syntax = true; | 2752 i::FLAG_allow_natives_syntax = true; |
2760 i::FLAG_flush_code_incrementally = true; | 2753 i::FLAG_flush_code_incrementally = true; |
2761 InitializeVM(); | 2754 CcTest::InitializeVM(); |
2762 Isolate* isolate = Isolate::Current(); | 2755 Isolate* isolate = Isolate::Current(); |
2763 Heap* heap = isolate->heap(); | 2756 Heap* heap = isolate->heap(); |
2764 HandleScope scope(isolate); | 2757 HandleScope scope(isolate); |
2765 | 2758 |
2766 // Perform one initial GC to enable code flushing. | 2759 // Perform one initial GC to enable code flushing. |
2767 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 2760 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
2768 | 2761 |
2769 // Prepare a shared function info eligible for code flushing for which | 2762 // Prepare a shared function info eligible for code flushing for which |
2770 // the unoptimized code will be replaced during optimization. | 2763 // the unoptimized code will be replaced during optimization. |
2771 Handle<SharedFunctionInfo> shared1; | 2764 Handle<SharedFunctionInfo> shared1; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2837 int new_linear_size = space_remaining - extra_bytes; | 2830 int new_linear_size = space_remaining - extra_bytes; |
2838 v8::internal::MaybeObject* maybe = space->AllocateRaw(new_linear_size); | 2831 v8::internal::MaybeObject* maybe = space->AllocateRaw(new_linear_size); |
2839 v8::internal::FreeListNode* node = v8::internal::FreeListNode::cast(maybe); | 2832 v8::internal::FreeListNode* node = v8::internal::FreeListNode::cast(maybe); |
2840 node->set_size(space->heap(), new_linear_size); | 2833 node->set_size(space->heap(), new_linear_size); |
2841 } | 2834 } |
2842 | 2835 |
2843 | 2836 |
2844 TEST(Regress169928) { | 2837 TEST(Regress169928) { |
2845 i::FLAG_allow_natives_syntax = true; | 2838 i::FLAG_allow_natives_syntax = true; |
2846 i::FLAG_crankshaft = false; | 2839 i::FLAG_crankshaft = false; |
2847 InitializeVM(); | 2840 CcTest::InitializeVM(); |
2848 v8::HandleScope scope(env->GetIsolate()); | 2841 v8::HandleScope scope(CcTest::isolate()); |
2849 | 2842 |
2850 // Some flags turn Scavenge collections into Mark-sweep collections | 2843 // Some flags turn Scavenge collections into Mark-sweep collections |
2851 // and hence are incompatible with this test case. | 2844 // and hence are incompatible with this test case. |
2852 if (FLAG_gc_global || FLAG_stress_compaction) return; | 2845 if (FLAG_gc_global || FLAG_stress_compaction) return; |
2853 | 2846 |
2854 // Prepare the environment | 2847 // Prepare the environment |
2855 CompileRun("function fastliteralcase(literal, value) {" | 2848 CompileRun("function fastliteralcase(literal, value) {" |
2856 " literal[0] = value;" | 2849 " literal[0] = value;" |
2857 " return literal;" | 2850 " return literal;" |
2858 "}" | 2851 "}" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2910 AlwaysAllocateScope aa_scope; | 2903 AlwaysAllocateScope aa_scope; |
2911 v8::Script::Compile(mote_code_string)->Run(); | 2904 v8::Script::Compile(mote_code_string)->Run(); |
2912 } | 2905 } |
2913 | 2906 |
2914 | 2907 |
2915 TEST(Regress168801) { | 2908 TEST(Regress168801) { |
2916 i::FLAG_always_compact = true; | 2909 i::FLAG_always_compact = true; |
2917 i::FLAG_cache_optimized_code = false; | 2910 i::FLAG_cache_optimized_code = false; |
2918 i::FLAG_allow_natives_syntax = true; | 2911 i::FLAG_allow_natives_syntax = true; |
2919 i::FLAG_flush_code_incrementally = true; | 2912 i::FLAG_flush_code_incrementally = true; |
2920 InitializeVM(); | 2913 CcTest::InitializeVM(); |
2921 Isolate* isolate = Isolate::Current(); | 2914 Isolate* isolate = Isolate::Current(); |
2922 Heap* heap = isolate->heap(); | 2915 Heap* heap = isolate->heap(); |
2923 HandleScope scope(isolate); | 2916 HandleScope scope(isolate); |
2924 | 2917 |
2925 // Perform one initial GC to enable code flushing. | 2918 // Perform one initial GC to enable code flushing. |
2926 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 2919 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
2927 | 2920 |
2928 // Ensure the code ends up on an evacuation candidate. | 2921 // Ensure the code ends up on an evacuation candidate. |
2929 SimulateFullSpace(heap->code_space()); | 2922 SimulateFullSpace(heap->code_space()); |
2930 | 2923 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2966 heap->CollectAllGarbage(Heap::kNoGCFlags); | 2959 heap->CollectAllGarbage(Heap::kNoGCFlags); |
2967 heap->CollectAllGarbage(Heap::kNoGCFlags); | 2960 heap->CollectAllGarbage(Heap::kNoGCFlags); |
2968 } | 2961 } |
2969 | 2962 |
2970 | 2963 |
2971 TEST(Regress173458) { | 2964 TEST(Regress173458) { |
2972 i::FLAG_always_compact = true; | 2965 i::FLAG_always_compact = true; |
2973 i::FLAG_cache_optimized_code = false; | 2966 i::FLAG_cache_optimized_code = false; |
2974 i::FLAG_allow_natives_syntax = true; | 2967 i::FLAG_allow_natives_syntax = true; |
2975 i::FLAG_flush_code_incrementally = true; | 2968 i::FLAG_flush_code_incrementally = true; |
2976 InitializeVM(); | 2969 CcTest::InitializeVM(); |
2977 Isolate* isolate = Isolate::Current(); | 2970 Isolate* isolate = Isolate::Current(); |
2978 Heap* heap = isolate->heap(); | 2971 Heap* heap = isolate->heap(); |
2979 HandleScope scope(isolate); | 2972 HandleScope scope(isolate); |
2980 | 2973 |
2981 // Perform one initial GC to enable code flushing. | 2974 // Perform one initial GC to enable code flushing. |
2982 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 2975 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
2983 | 2976 |
2984 // Ensure the code ends up on an evacuation candidate. | 2977 // Ensure the code ends up on an evacuation candidate. |
2985 SimulateFullSpace(heap->code_space()); | 2978 SimulateFullSpace(heap->code_space()); |
2986 | 2979 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3023 } | 3016 } |
3024 | 3017 |
3025 | 3018 |
3026 class DummyVisitor : public ObjectVisitor { | 3019 class DummyVisitor : public ObjectVisitor { |
3027 public: | 3020 public: |
3028 void VisitPointers(Object** start, Object** end) { } | 3021 void VisitPointers(Object** start, Object** end) { } |
3029 }; | 3022 }; |
3030 | 3023 |
3031 | 3024 |
3032 TEST(DeferredHandles) { | 3025 TEST(DeferredHandles) { |
3033 InitializeVM(); | 3026 CcTest::InitializeVM(); |
3034 Isolate* isolate = Isolate::Current(); | 3027 Isolate* isolate = Isolate::Current(); |
3035 Heap* heap = isolate->heap(); | 3028 Heap* heap = isolate->heap(); |
3036 v8::HandleScope scope; | 3029 v8::HandleScope scope; |
3037 v8::ImplementationUtilities::HandleScopeData* data = | 3030 v8::ImplementationUtilities::HandleScopeData* data = |
3038 isolate->handle_scope_data(); | 3031 isolate->handle_scope_data(); |
3039 Handle<Object> init(heap->empty_string(), isolate); | 3032 Handle<Object> init(heap->empty_string(), isolate); |
3040 while (data->next < data->limit) { | 3033 while (data->next < data->limit) { |
3041 Handle<Object> obj(heap->empty_string(), isolate); | 3034 Handle<Object> obj(heap->empty_string(), isolate); |
3042 } | 3035 } |
3043 // An entire block of handles has been filled. | 3036 // An entire block of handles has been filled. |
3044 // Next handle would require a new block. | 3037 // Next handle would require a new block. |
3045 ASSERT(data->next == data->limit); | 3038 ASSERT(data->next == data->limit); |
3046 | 3039 |
3047 DeferredHandleScope deferred(isolate); | 3040 DeferredHandleScope deferred(isolate); |
3048 DummyVisitor visitor; | 3041 DummyVisitor visitor; |
3049 isolate->handle_scope_implementer()->Iterate(&visitor); | 3042 isolate->handle_scope_implementer()->Iterate(&visitor); |
3050 deferred.Detach(); | 3043 deferred.Detach(); |
3051 } | 3044 } |
OLD | NEW |