| 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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 value = heap->NumberFromInt32(Smi::kMinValue)->ToObjectChecked(); | 173 value = heap->NumberFromInt32(Smi::kMinValue)->ToObjectChecked(); |
| 174 CHECK(value->IsSmi()); | 174 CHECK(value->IsSmi()); |
| 175 CHECK(value->IsNumber()); | 175 CHECK(value->IsNumber()); |
| 176 CHECK_EQ(Smi::kMinValue, Smi::cast(value)->value()); | 176 CHECK_EQ(Smi::kMinValue, Smi::cast(value)->value()); |
| 177 | 177 |
| 178 value = heap->NumberFromInt32(Smi::kMaxValue)->ToObjectChecked(); | 178 value = heap->NumberFromInt32(Smi::kMaxValue)->ToObjectChecked(); |
| 179 CHECK(value->IsSmi()); | 179 CHECK(value->IsSmi()); |
| 180 CHECK(value->IsNumber()); | 180 CHECK(value->IsNumber()); |
| 181 CHECK_EQ(Smi::kMaxValue, Smi::cast(value)->value()); | 181 CHECK_EQ(Smi::kMaxValue, Smi::cast(value)->value()); |
| 182 | 182 |
| 183 #if !defined(V8_TARGET_ARCH_X64) && !defined(V8_TARGET_ARCH_A64) | 183 #ifndef V8_TARGET_ARCH_X64 |
| 184 // TODO(lrn): We need a NumberFromIntptr function in order to test this. | 184 // TODO(lrn): We need a NumberFromIntptr function in order to test this. |
| 185 value = heap->NumberFromInt32(Smi::kMinValue - 1)->ToObjectChecked(); | 185 value = heap->NumberFromInt32(Smi::kMinValue - 1)->ToObjectChecked(); |
| 186 CHECK(value->IsHeapNumber()); | 186 CHECK(value->IsHeapNumber()); |
| 187 CHECK(value->IsNumber()); | 187 CHECK(value->IsNumber()); |
| 188 CHECK_EQ(static_cast<double>(Smi::kMinValue - 1), value->Number()); | 188 CHECK_EQ(static_cast<double>(Smi::kMinValue - 1), value->Number()); |
| 189 #endif | 189 #endif |
| 190 | 190 |
| 191 MaybeObject* maybe_value = | 191 MaybeObject* maybe_value = |
| 192 heap->NumberFromUint32(static_cast<uint32_t>(Smi::kMaxValue) + 1); | 192 heap->NumberFromUint32(static_cast<uint32_t>(Smi::kMaxValue) + 1); |
| 193 value = maybe_value->ToObjectChecked(); | 193 value = maybe_value->ToObjectChecked(); |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 h1 = global_handles->Create(*i); | 426 h1 = global_handles->Create(*i); |
| 427 h2 = global_handles->Create(*u); | 427 h2 = global_handles->Create(*u); |
| 428 } | 428 } |
| 429 | 429 |
| 430 std::pair<Handle<Object>*, int> handle_and_id(&h2, 1234); | 430 std::pair<Handle<Object>*, int> handle_and_id(&h2, 1234); |
| 431 GlobalHandles::MakeWeak(h2.location(), | 431 GlobalHandles::MakeWeak(h2.location(), |
| 432 reinterpret_cast<void*>(&handle_and_id), | 432 reinterpret_cast<void*>(&handle_and_id), |
| 433 &TestWeakGlobalHandleCallback); | 433 &TestWeakGlobalHandleCallback); |
| 434 | 434 |
| 435 // Scavenge treats weak pointers as normal roots. | 435 // Scavenge treats weak pointers as normal roots. |
| 436 heap->CollectGarbage(NEW_SPACE); | 436 heap->PerformScavenge(); |
| 437 | 437 |
| 438 CHECK((*h1)->IsString()); | 438 CHECK((*h1)->IsString()); |
| 439 CHECK((*h2)->IsHeapNumber()); | 439 CHECK((*h2)->IsHeapNumber()); |
| 440 | 440 |
| 441 CHECK(!WeakPointerCleared); | 441 CHECK(!WeakPointerCleared); |
| 442 CHECK(!global_handles->IsNearDeath(h2.location())); | 442 CHECK(!global_handles->IsNearDeath(h2.location())); |
| 443 CHECK(!global_handles->IsNearDeath(h1.location())); | 443 CHECK(!global_handles->IsNearDeath(h1.location())); |
| 444 | 444 |
| 445 GlobalHandles::Destroy(h1.location()); | 445 GlobalHandles::Destroy(h1.location()); |
| 446 GlobalHandles::Destroy(h2.location()); | 446 GlobalHandles::Destroy(h2.location()); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 Handle<Object> i = factory->NewStringFromAscii(CStrVector("fisk")); | 511 Handle<Object> i = factory->NewStringFromAscii(CStrVector("fisk")); |
| 512 h = global_handles->Create(*i); | 512 h = global_handles->Create(*i); |
| 513 } | 513 } |
| 514 | 514 |
| 515 std::pair<Handle<Object>*, int> handle_and_id(&h, 1234); | 515 std::pair<Handle<Object>*, int> handle_and_id(&h, 1234); |
| 516 GlobalHandles::MakeWeak(h.location(), | 516 GlobalHandles::MakeWeak(h.location(), |
| 517 reinterpret_cast<void*>(&handle_and_id), | 517 reinterpret_cast<void*>(&handle_and_id), |
| 518 &TestWeakGlobalHandleCallback); | 518 &TestWeakGlobalHandleCallback); |
| 519 | 519 |
| 520 // Scanvenge does not recognize weak reference. | 520 // Scanvenge does not recognize weak reference. |
| 521 heap->CollectGarbage(NEW_SPACE); | 521 heap->PerformScavenge(); |
| 522 | 522 |
| 523 CHECK(!WeakPointerCleared); | 523 CHECK(!WeakPointerCleared); |
| 524 | 524 |
| 525 // Mark-compact treats weak reference properly. | 525 // Mark-compact treats weak reference properly. |
| 526 heap->CollectGarbage(OLD_POINTER_SPACE); | 526 heap->CollectGarbage(OLD_POINTER_SPACE); |
| 527 | 527 |
| 528 CHECK(WeakPointerCleared); | 528 CHECK(WeakPointerCleared); |
| 529 } | 529 } |
| 530 | 530 |
| 531 | 531 |
| (...skipping 897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1429 CompileRun("f4()"); | 1429 CompileRun("f4()"); |
| 1430 CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctions(ctx[i])); | 1430 CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctions(ctx[i])); |
| 1431 CompileRun("f5()"); | 1431 CompileRun("f5()"); |
| 1432 CHECK_EQ(opt ? 5 : 0, CountOptimizedUserFunctions(ctx[i])); | 1432 CHECK_EQ(opt ? 5 : 0, CountOptimizedUserFunctions(ctx[i])); |
| 1433 | 1433 |
| 1434 // Remove function f1, and | 1434 // Remove function f1, and |
| 1435 CompileRun("f1=null"); | 1435 CompileRun("f1=null"); |
| 1436 | 1436 |
| 1437 // Scavenge treats these references as strong. | 1437 // Scavenge treats these references as strong. |
| 1438 for (int j = 0; j < 10; j++) { | 1438 for (int j = 0; j < 10; j++) { |
| 1439 CcTest::heap()->CollectGarbage(NEW_SPACE); | 1439 CcTest::heap()->PerformScavenge(); |
| 1440 CHECK_EQ(opt ? 5 : 0, CountOptimizedUserFunctions(ctx[i])); | 1440 CHECK_EQ(opt ? 5 : 0, CountOptimizedUserFunctions(ctx[i])); |
| 1441 } | 1441 } |
| 1442 | 1442 |
| 1443 // Mark compact handles the weak references. | 1443 // Mark compact handles the weak references. |
| 1444 isolate->compilation_cache()->Clear(); | 1444 isolate->compilation_cache()->Clear(); |
| 1445 heap->CollectAllGarbage(Heap::kNoGCFlags); | 1445 heap->CollectAllGarbage(Heap::kNoGCFlags); |
| 1446 CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctions(ctx[i])); | 1446 CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctions(ctx[i])); |
| 1447 | 1447 |
| 1448 // Get rid of f3 and f5 in the same way. | 1448 // Get rid of f3 and f5 in the same way. |
| 1449 CompileRun("f3=null"); | 1449 CompileRun("f3=null"); |
| 1450 for (int j = 0; j < 10; j++) { | 1450 for (int j = 0; j < 10; j++) { |
| 1451 CcTest::heap()->CollectGarbage(NEW_SPACE); | 1451 CcTest::heap()->PerformScavenge(); |
| 1452 CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctions(ctx[i])); | 1452 CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctions(ctx[i])); |
| 1453 } | 1453 } |
| 1454 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); | 1454 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
| 1455 CHECK_EQ(opt ? 3 : 0, CountOptimizedUserFunctions(ctx[i])); | 1455 CHECK_EQ(opt ? 3 : 0, CountOptimizedUserFunctions(ctx[i])); |
| 1456 CompileRun("f5=null"); | 1456 CompileRun("f5=null"); |
| 1457 for (int j = 0; j < 10; j++) { | 1457 for (int j = 0; j < 10; j++) { |
| 1458 CcTest::heap()->CollectGarbage(NEW_SPACE); | 1458 CcTest::heap()->PerformScavenge(); |
| 1459 CHECK_EQ(opt ? 3 : 0, CountOptimizedUserFunctions(ctx[i])); | 1459 CHECK_EQ(opt ? 3 : 0, CountOptimizedUserFunctions(ctx[i])); |
| 1460 } | 1460 } |
| 1461 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); | 1461 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
| 1462 CHECK_EQ(opt ? 2 : 0, CountOptimizedUserFunctions(ctx[i])); | 1462 CHECK_EQ(opt ? 2 : 0, CountOptimizedUserFunctions(ctx[i])); |
| 1463 | 1463 |
| 1464 ctx[i]->Exit(); | 1464 ctx[i]->Exit(); |
| 1465 } | 1465 } |
| 1466 | 1466 |
| 1467 // Force compilation cache cleanup. | 1467 // Force compilation cache cleanup. |
| 1468 CcTest::heap()->NotifyContextDisposed(); | 1468 CcTest::heap()->NotifyContextDisposed(); |
| 1469 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); | 1469 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
| 1470 | 1470 |
| 1471 // Dispose the native contexts one by one. | 1471 // Dispose the native contexts one by one. |
| 1472 for (int i = 0; i < kNumTestContexts; i++) { | 1472 for (int i = 0; i < kNumTestContexts; i++) { |
| 1473 // TODO(dcarney): is there a better way to do this? | 1473 // TODO(dcarney): is there a better way to do this? |
| 1474 i::Object** unsafe = reinterpret_cast<i::Object**>(*ctx[i]); | 1474 i::Object** unsafe = reinterpret_cast<i::Object**>(*ctx[i]); |
| 1475 *unsafe = CcTest::heap()->undefined_value(); | 1475 *unsafe = CcTest::heap()->undefined_value(); |
| 1476 ctx[i].Clear(); | 1476 ctx[i].Clear(); |
| 1477 | 1477 |
| 1478 // Scavenge treats these references as strong. | 1478 // Scavenge treats these references as strong. |
| 1479 for (int j = 0; j < 10; j++) { | 1479 for (int j = 0; j < 10; j++) { |
| 1480 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 1480 CcTest::heap()->PerformScavenge(); |
| 1481 CHECK_EQ(kNumTestContexts - i, CountNativeContexts()); | 1481 CHECK_EQ(kNumTestContexts - i, CountNativeContexts()); |
| 1482 } | 1482 } |
| 1483 | 1483 |
| 1484 // Mark compact handles the weak references. | 1484 // Mark compact handles the weak references. |
| 1485 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); | 1485 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
| 1486 CHECK_EQ(kNumTestContexts - i - 1, CountNativeContexts()); | 1486 CHECK_EQ(kNumTestContexts - i - 1, CountNativeContexts()); |
| 1487 } | 1487 } |
| 1488 | 1488 |
| 1489 CHECK_EQ(0, CountNativeContexts()); | 1489 CHECK_EQ(0, CountNativeContexts()); |
| 1490 } | 1490 } |
| (...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2203 " this.a = 1.1;" | 2203 " this.a = 1.1;" |
| 2204 " this.b = [{}];" | 2204 " this.b = [{}];" |
| 2205 " this.c = 1.2;" | 2205 " this.c = 1.2;" |
| 2206 " this.d = [{}];" | 2206 " this.d = [{}];" |
| 2207 " this.e = 1.3;" | 2207 " this.e = 1.3;" |
| 2208 " this.f = [{}];" | 2208 " this.f = [{}];" |
| 2209 "}" | 2209 "}" |
| 2210 "var number_elements = 20000;" | 2210 "var number_elements = 20000;" |
| 2211 "var elements = new Array();" | 2211 "var elements = new Array();" |
| 2212 "function f() {" | 2212 "function f() {" |
| 2213 " for (var i = 0; i < number_elements; i++) {" | 2213 " for (var i = 0; i < 20000-1; i++) {" |
| 2214 " elements[i] = new DataObject();" | 2214 " elements[i] = new DataObject();" |
| 2215 " }" | 2215 " }" |
| 2216 " return elements[number_elements-1]" | 2216 " return new DataObject()" |
| 2217 "};" | 2217 "};" |
| 2218 "f(); f(); f();" | 2218 "f(); f(); f();" |
| 2219 "%OptimizeFunctionOnNextCall(f);" | 2219 "%OptimizeFunctionOnNextCall(f);" |
| 2220 "f();"); | 2220 "f();"); |
| 2221 | 2221 |
| 2222 Handle<JSObject> o = | 2222 Handle<JSObject> o = |
| 2223 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); | 2223 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); |
| 2224 | 2224 |
| 2225 CHECK(CcTest::heap()->InOldDataSpace(o->RawFastPropertyAt(0))); | 2225 CHECK(CcTest::heap()->InOldDataSpace(o->RawFastPropertyAt(0))); |
| 2226 CHECK(CcTest::heap()->InOldPointerSpace(o->RawFastPropertyAt(1))); | 2226 CHECK(CcTest::heap()->InOldPointerSpace(o->RawFastPropertyAt(1))); |
| (...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2819 // Check size. | 2819 // Check size. |
| 2820 DescriptorArray* descriptors = internal_obj->map()->instance_descriptors(); | 2820 DescriptorArray* descriptors = internal_obj->map()->instance_descriptors(); |
| 2821 ObjectHashTable* hashtable = ObjectHashTable::cast( | 2821 ObjectHashTable* hashtable = ObjectHashTable::cast( |
| 2822 internal_obj->RawFastPropertyAt(descriptors->GetFieldIndex(0))); | 2822 internal_obj->RawFastPropertyAt(descriptors->GetFieldIndex(0))); |
| 2823 // HashTable header (5) and 4 initial entries (8). | 2823 // HashTable header (5) and 4 initial entries (8). |
| 2824 CHECK_LE(hashtable->SizeFor(hashtable->length()), 13 * kPointerSize); | 2824 CHECK_LE(hashtable->SizeFor(hashtable->length()), 13 * kPointerSize); |
| 2825 } | 2825 } |
| 2826 } | 2826 } |
| 2827 | 2827 |
| 2828 | 2828 |
| 2829 TEST(IncrementalMarkingClearsTypeFeedbackInfo) { | 2829 TEST(IncrementalMarkingClearsTypeFeedbackCells) { |
| 2830 if (i::FLAG_always_opt) return; | 2830 if (i::FLAG_always_opt) return; |
| 2831 CcTest::InitializeVM(); | 2831 CcTest::InitializeVM(); |
| 2832 v8::HandleScope scope(CcTest::isolate()); | 2832 v8::HandleScope scope(CcTest::isolate()); |
| 2833 v8::Local<v8::Value> fun1, fun2; | 2833 v8::Local<v8::Value> fun1, fun2; |
| 2834 | 2834 |
| 2835 { | 2835 { |
| 2836 LocalContext env; | 2836 LocalContext env; |
| 2837 CompileRun("function fun() {};"); | 2837 CompileRun("function fun() {};"); |
| 2838 fun1 = env->Global()->Get(v8_str("fun")); | 2838 fun1 = env->Global()->Get(v8_str("fun")); |
| 2839 } | 2839 } |
| 2840 | 2840 |
| 2841 { | 2841 { |
| 2842 LocalContext env; | 2842 LocalContext env; |
| 2843 CompileRun("function fun() {};"); | 2843 CompileRun("function fun() {};"); |
| 2844 fun2 = env->Global()->Get(v8_str("fun")); | 2844 fun2 = env->Global()->Get(v8_str("fun")); |
| 2845 } | 2845 } |
| 2846 | 2846 |
| 2847 // Prepare function f that contains type feedback for closures | 2847 // Prepare function f that contains type feedback for closures |
| 2848 // originating from two different native contexts. | 2848 // originating from two different native contexts. |
| 2849 CcTest::global()->Set(v8_str("fun1"), fun1); | 2849 CcTest::global()->Set(v8_str("fun1"), fun1); |
| 2850 CcTest::global()->Set(v8_str("fun2"), fun2); | 2850 CcTest::global()->Set(v8_str("fun2"), fun2); |
| 2851 CompileRun("function f(a, b) { a(); b(); } f(fun1, fun2);"); | 2851 CompileRun("function f(a, b) { a(); b(); } f(fun1, fun2);"); |
| 2852 | |
| 2853 Handle<JSFunction> f = | 2852 Handle<JSFunction> f = |
| 2854 v8::Utils::OpenHandle( | 2853 v8::Utils::OpenHandle( |
| 2855 *v8::Handle<v8::Function>::Cast( | 2854 *v8::Handle<v8::Function>::Cast( |
| 2856 CcTest::global()->Get(v8_str("f")))); | 2855 CcTest::global()->Get(v8_str("f")))); |
| 2856 Handle<TypeFeedbackCells> cells(TypeFeedbackInfo::cast( |
| 2857 f->shared()->code()->type_feedback_info())->type_feedback_cells()); |
| 2857 | 2858 |
| 2858 Handle<FixedArray> feedback_vector(TypeFeedbackInfo::cast( | 2859 CHECK_EQ(2, cells->CellCount()); |
| 2859 f->shared()->code()->type_feedback_info())->feedback_vector()); | 2860 CHECK(cells->GetCell(0)->value()->IsJSFunction()); |
| 2860 | 2861 CHECK(cells->GetCell(1)->value()->IsJSFunction()); |
| 2861 CHECK_EQ(2, feedback_vector->length()); | |
| 2862 CHECK(feedback_vector->get(0)->IsJSFunction()); | |
| 2863 CHECK(feedback_vector->get(1)->IsJSFunction()); | |
| 2864 | 2862 |
| 2865 SimulateIncrementalMarking(); | 2863 SimulateIncrementalMarking(); |
| 2866 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); | 2864 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
| 2867 | 2865 |
| 2868 CHECK_EQ(2, feedback_vector->length()); | 2866 CHECK_EQ(2, cells->CellCount()); |
| 2869 CHECK(feedback_vector->get(0)->IsTheHole()); | 2867 CHECK(cells->GetCell(0)->value()->IsTheHole()); |
| 2870 CHECK(feedback_vector->get(1)->IsTheHole()); | 2868 CHECK(cells->GetCell(1)->value()->IsTheHole()); |
| 2871 } | 2869 } |
| 2872 | 2870 |
| 2873 | 2871 |
| 2874 static Code* FindFirstIC(Code* code, Code::Kind kind) { | 2872 static Code* FindFirstIC(Code* code, Code::Kind kind) { |
| 2875 int mask = RelocInfo::ModeMask(RelocInfo::CODE_TARGET) | | 2873 int mask = RelocInfo::ModeMask(RelocInfo::CODE_TARGET) | |
| 2876 RelocInfo::ModeMask(RelocInfo::CONSTRUCT_CALL) | | 2874 RelocInfo::ModeMask(RelocInfo::CONSTRUCT_CALL) | |
| 2877 RelocInfo::ModeMask(RelocInfo::CODE_TARGET_WITH_ID); | 2875 RelocInfo::ModeMask(RelocInfo::CODE_TARGET_WITH_ID); |
| 2878 for (RelocIterator it(code, mask); !it.done(); it.next()) { | 2876 for (RelocIterator it(code, mask); !it.done(); it.next()) { |
| 2879 RelocInfo* info = it.rinfo(); | 2877 RelocInfo* info = it.rinfo(); |
| 2880 Code* target = Code::GetCodeFromTargetAddress(info->target_address()); | 2878 Code* target = Code::GetCodeFromTargetAddress(info->target_address()); |
| (...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3681 code = scope.CloseAndEscape(Handle<Code>(bar->code())); | 3679 code = scope.CloseAndEscape(Handle<Code>(bar->code())); |
| 3682 } | 3680 } |
| 3683 | 3681 |
| 3684 // Now make sure that a gc should get rid of the function | 3682 // Now make sure that a gc should get rid of the function |
| 3685 for (int i = 0; i < 4; i++) { | 3683 for (int i = 0; i < 4; i++) { |
| 3686 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 3684 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
| 3687 } | 3685 } |
| 3688 | 3686 |
| 3689 ASSERT(code->marked_for_deoptimization()); | 3687 ASSERT(code->marked_for_deoptimization()); |
| 3690 } | 3688 } |
| OLD | NEW |