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

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

Issue 198253004: Introduce per-isolate assert scopes and API to guard JS execution. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: add missing file Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1003 matching lines...) Expand 10 before | Expand all | Expand 10 after
1014 CHECK_EQ(0, FixedArray::cast(jsobject->elements())->length()); 1014 CHECK_EQ(0, FixedArray::cast(jsobject->elements())->length());
1015 CHECK_EQ(0, jsobject->properties()->length()); 1015 CHECK_EQ(0, jsobject->properties()->length());
1016 // Create a reference to object in new space in jsobject. 1016 // Create a reference to object in new space in jsobject.
1017 jsobject->FastPropertyAtPut(-1, array); 1017 jsobject->FastPropertyAtPut(-1, array);
1018 1018
1019 CHECK_EQ(0, static_cast<int>(*limit_addr - *top_addr)); 1019 CHECK_EQ(0, static_cast<int>(*limit_addr - *top_addr));
1020 1020
1021 // Step 4: clone jsobject, but force always allocate first to create a clone 1021 // Step 4: clone jsobject, but force always allocate first to create a clone
1022 // in old pointer space. 1022 // in old pointer space.
1023 Address old_pointer_space_top = heap->old_pointer_space()->top(); 1023 Address old_pointer_space_top = heap->old_pointer_space()->top();
1024 AlwaysAllocateScope aa_scope; 1024 AlwaysAllocateScope aa_scope(isolate);
1025 Object* clone_obj = heap->CopyJSObject(jsobject)->ToObjectChecked(); 1025 Object* clone_obj = heap->CopyJSObject(jsobject)->ToObjectChecked();
1026 JSObject* clone = JSObject::cast(clone_obj); 1026 JSObject* clone = JSObject::cast(clone_obj);
1027 if (clone->address() != old_pointer_space_top) { 1027 if (clone->address() != old_pointer_space_top) {
1028 // Alas, got allocated from free list, we cannot do checks. 1028 // Alas, got allocated from free list, we cannot do checks.
1029 return; 1029 return;
1030 } 1030 }
1031 CHECK(heap->old_pointer_space()->Contains(clone->address())); 1031 CHECK(heap->old_pointer_space()->Contains(clone->address()));
1032 } 1032 }
1033 1033
1034 1034
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
1588 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); 1588 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
1589 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); 1589 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
1590 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); 1590 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
1591 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); 1591 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
1592 CHECK(CcTest::heap()->old_pointer_space()->IsLazySweepingComplete()); 1592 CHECK(CcTest::heap()->old_pointer_space()->IsLazySweepingComplete());
1593 int initial_size = static_cast<int>(CcTest::heap()->SizeOfObjects()); 1593 int initial_size = static_cast<int>(CcTest::heap()->SizeOfObjects());
1594 1594
1595 { 1595 {
1596 // Allocate objects on several different old-space pages so that 1596 // Allocate objects on several different old-space pages so that
1597 // lazy sweeping kicks in for subsequent GC runs. 1597 // lazy sweeping kicks in for subsequent GC runs.
1598 AlwaysAllocateScope always_allocate; 1598 AlwaysAllocateScope always_allocate(CcTest::i_isolate());
1599 int filler_size = static_cast<int>(FixedArray::SizeFor(8192)); 1599 int filler_size = static_cast<int>(FixedArray::SizeFor(8192));
1600 for (int i = 1; i <= 100; i++) { 1600 for (int i = 1; i <= 100; i++) {
1601 CcTest::heap()->AllocateFixedArray(8192, TENURED)->ToObjectChecked(); 1601 CcTest::heap()->AllocateFixedArray(8192, TENURED)->ToObjectChecked();
1602 CHECK_EQ(initial_size + i * filler_size, 1602 CHECK_EQ(initial_size + i * filler_size,
1603 static_cast<int>(CcTest::heap()->SizeOfObjects())); 1603 static_cast<int>(CcTest::heap()->SizeOfObjects()));
1604 } 1604 }
1605 } 1605 }
1606 1606
1607 // The heap size should go back to initial size after a full GC, even 1607 // The heap size should go back to initial size after a full GC, even
1608 // though sweeping didn't finish yet. 1608 // though sweeping didn't finish yet.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1655 } 1655 }
1656 1656
1657 1657
1658 static void FillUpNewSpace(NewSpace* new_space) { 1658 static void FillUpNewSpace(NewSpace* new_space) {
1659 // Fill up new space to the point that it is completely full. Make sure 1659 // Fill up new space to the point that it is completely full. Make sure
1660 // that the scavenger does not undo the filling. 1660 // that the scavenger does not undo the filling.
1661 Heap* heap = new_space->heap(); 1661 Heap* heap = new_space->heap();
1662 Isolate* isolate = heap->isolate(); 1662 Isolate* isolate = heap->isolate();
1663 Factory* factory = isolate->factory(); 1663 Factory* factory = isolate->factory();
1664 HandleScope scope(isolate); 1664 HandleScope scope(isolate);
1665 AlwaysAllocateScope always_allocate; 1665 AlwaysAllocateScope always_allocate(isolate);
1666 intptr_t available = new_space->EffectiveCapacity() - new_space->Size(); 1666 intptr_t available = new_space->EffectiveCapacity() - new_space->Size();
1667 intptr_t number_of_fillers = (available / FixedArray::SizeFor(32)) - 1; 1667 intptr_t number_of_fillers = (available / FixedArray::SizeFor(32)) - 1;
1668 for (intptr_t i = 0; i < number_of_fillers; i++) { 1668 for (intptr_t i = 0; i < number_of_fillers; i++) {
1669 CHECK(heap->InNewSpace(*factory->NewFixedArray(32, NOT_TENURED))); 1669 CHECK(heap->InNewSpace(*factory->NewFixedArray(32, NOT_TENURED)));
1670 } 1670 }
1671 } 1671 }
1672 1672
1673 1673
1674 TEST(GrowAndShrinkNewSpace) { 1674 TEST(GrowAndShrinkNewSpace) {
1675 CcTest::InitializeVM(); 1675 CcTest::InitializeVM();
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
2034 i * Map::kProtoTransitionElementsPerEntry; 2034 i * Map::kProtoTransitionElementsPerEntry;
2035 CHECK(trans->get(j + Map::kProtoTransitionMapOffset)->IsMap()); 2035 CHECK(trans->get(j + Map::kProtoTransitionMapOffset)->IsMap());
2036 Object* proto = trans->get(j + Map::kProtoTransitionPrototypeOffset); 2036 Object* proto = trans->get(j + Map::kProtoTransitionPrototypeOffset);
2037 CHECK(proto->IsJSObject()); 2037 CHECK(proto->IsJSObject());
2038 } 2038 }
2039 2039
2040 // Make sure next prototype is placed on an old-space evacuation candidate. 2040 // Make sure next prototype is placed on an old-space evacuation candidate.
2041 Handle<JSObject> prototype; 2041 Handle<JSObject> prototype;
2042 PagedSpace* space = CcTest::heap()->old_pointer_space(); 2042 PagedSpace* space = CcTest::heap()->old_pointer_space();
2043 { 2043 {
2044 AlwaysAllocateScope always_allocate; 2044 AlwaysAllocateScope always_allocate(isolate);
2045 SimulateFullSpace(space); 2045 SimulateFullSpace(space);
2046 prototype = factory->NewJSArray(32 * KB, FAST_HOLEY_ELEMENTS, TENURED); 2046 prototype = factory->NewJSArray(32 * KB, FAST_HOLEY_ELEMENTS, TENURED);
2047 } 2047 }
2048 2048
2049 // Add a prototype on an evacuation candidate and verify that transition 2049 // Add a prototype on an evacuation candidate and verify that transition
2050 // clearing correctly records slots in prototype transition array. 2050 // clearing correctly records slots in prototype transition array.
2051 i::FLAG_always_compact = true; 2051 i::FLAG_always_compact = true;
2052 Handle<Map> map(baseObject->map()); 2052 Handle<Map> map(baseObject->map());
2053 CHECK(!space->LastPage()->Contains( 2053 CHECK(!space->LastPage()->Contains(
2054 map->GetPrototypeTransitions()->address())); 2054 map->GetPrototypeTransitions()->address()));
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
2162 2162
2163 // Test that HAllocateObject will always return an object in new-space. 2163 // Test that HAllocateObject will always return an object in new-space.
2164 TEST(OptimizedAllocationAlwaysInNewSpace) { 2164 TEST(OptimizedAllocationAlwaysInNewSpace) {
2165 i::FLAG_allow_natives_syntax = true; 2165 i::FLAG_allow_natives_syntax = true;
2166 CcTest::InitializeVM(); 2166 CcTest::InitializeVM();
2167 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; 2167 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return;
2168 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; 2168 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return;
2169 v8::HandleScope scope(CcTest::isolate()); 2169 v8::HandleScope scope(CcTest::isolate());
2170 2170
2171 SimulateFullSpace(CcTest::heap()->new_space()); 2171 SimulateFullSpace(CcTest::heap()->new_space());
2172 AlwaysAllocateScope always_allocate; 2172 AlwaysAllocateScope always_allocate(CcTest::i_isolate());
2173 v8::Local<v8::Value> res = CompileRun( 2173 v8::Local<v8::Value> res = CompileRun(
2174 "function c(x) {" 2174 "function c(x) {"
2175 " this.x = x;" 2175 " this.x = x;"
2176 " for (var i = 0; i < 32; i++) {" 2176 " for (var i = 0; i < 32; i++) {"
2177 " this['x' + i] = x;" 2177 " this['x' + i] = x;"
2178 " }" 2178 " }"
2179 "}" 2179 "}"
2180 "function f(x) { return new c(x); };" 2180 "function f(x) { return new c(x); };"
2181 "f(1); f(2); f(3);" 2181 "f(1); f(2); f(3);"
2182 "%OptimizeFunctionOnNextCall(f);" 2182 "%OptimizeFunctionOnNextCall(f);"
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
2544 TEST(OptimizedPretenuringCallNew) { 2544 TEST(OptimizedPretenuringCallNew) {
2545 i::FLAG_allow_natives_syntax = true; 2545 i::FLAG_allow_natives_syntax = true;
2546 i::FLAG_allocation_site_pretenuring = false; 2546 i::FLAG_allocation_site_pretenuring = false;
2547 i::FLAG_pretenuring_call_new = true; 2547 i::FLAG_pretenuring_call_new = true;
2548 CcTest::InitializeVM(); 2548 CcTest::InitializeVM();
2549 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; 2549 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return;
2550 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; 2550 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return;
2551 v8::HandleScope scope(CcTest::isolate()); 2551 v8::HandleScope scope(CcTest::isolate());
2552 CcTest::heap()->SetNewSpaceHighPromotionModeActive(true); 2552 CcTest::heap()->SetNewSpaceHighPromotionModeActive(true);
2553 2553
2554 AlwaysAllocateScope always_allocate; 2554 AlwaysAllocateScope always_allocate(CcTest::i_isolate());
2555 v8::Local<v8::Value> res = CompileRun( 2555 v8::Local<v8::Value> res = CompileRun(
2556 "function g() { this.a = 0; }" 2556 "function g() { this.a = 0; }"
2557 "function f() {" 2557 "function f() {"
2558 " return new g();" 2558 " return new g();"
2559 "};" 2559 "};"
2560 "f(); f(); f();" 2560 "f(); f(); f();"
2561 "%OptimizeFunctionOnNextCall(f);" 2561 "%OptimizeFunctionOnNextCall(f);"
2562 "f();"); 2562 "f();");
2563 2563
2564 Handle<JSObject> o = 2564 Handle<JSObject> o =
(...skipping 11 matching lines...) Expand all
2576 // incremental marking as well. 2576 // incremental marking as well.
2577 TEST(Regress1465) { 2577 TEST(Regress1465) {
2578 i::FLAG_stress_compaction = false; 2578 i::FLAG_stress_compaction = false;
2579 i::FLAG_allow_natives_syntax = true; 2579 i::FLAG_allow_natives_syntax = true;
2580 i::FLAG_trace_incremental_marking = true; 2580 i::FLAG_trace_incremental_marking = true;
2581 CcTest::InitializeVM(); 2581 CcTest::InitializeVM();
2582 v8::HandleScope scope(CcTest::isolate()); 2582 v8::HandleScope scope(CcTest::isolate());
2583 static const int transitions_count = 256; 2583 static const int transitions_count = 256;
2584 2584
2585 { 2585 {
2586 AlwaysAllocateScope always_allocate; 2586 AlwaysAllocateScope always_allocate(CcTest::i_isolate());
2587 for (int i = 0; i < transitions_count; i++) { 2587 for (int i = 0; i < transitions_count; i++) {
2588 EmbeddedVector<char, 64> buffer; 2588 EmbeddedVector<char, 64> buffer;
2589 OS::SNPrintF(buffer, "var o = new Object; o.prop%d = %d;", i, i); 2589 OS::SNPrintF(buffer, "var o = new Object; o.prop%d = %d;", i, i);
2590 CompileRun(buffer.start()); 2590 CompileRun(buffer.start());
2591 } 2591 }
2592 CompileRun("var root = new Object;"); 2592 CompileRun("var root = new Object;");
2593 } 2593 }
2594 2594
2595 Handle<JSObject> root = 2595 Handle<JSObject> root =
2596 v8::Utils::OpenHandle( 2596 v8::Utils::OpenHandle(
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
2706 Isolate* isolate = CcTest::i_isolate(); 2706 Isolate* isolate = CcTest::i_isolate();
2707 Factory* factory = isolate->factory(); 2707 Factory* factory = isolate->factory();
2708 Heap* heap = isolate->heap(); 2708 Heap* heap = isolate->heap();
2709 v8::HandleScope scope(CcTest::isolate()); 2709 v8::HandleScope scope(CcTest::isolate());
2710 static const int number_of_test_pages = 20; 2710 static const int number_of_test_pages = 20;
2711 2711
2712 // Prepare many pages with low live-bytes count. 2712 // Prepare many pages with low live-bytes count.
2713 PagedSpace* old_pointer_space = heap->old_pointer_space(); 2713 PagedSpace* old_pointer_space = heap->old_pointer_space();
2714 CHECK_EQ(1, old_pointer_space->CountTotalPages()); 2714 CHECK_EQ(1, old_pointer_space->CountTotalPages());
2715 for (int i = 0; i < number_of_test_pages; i++) { 2715 for (int i = 0; i < number_of_test_pages; i++) {
2716 AlwaysAllocateScope always_allocate; 2716 AlwaysAllocateScope always_allocate(isolate);
2717 SimulateFullSpace(old_pointer_space); 2717 SimulateFullSpace(old_pointer_space);
2718 factory->NewFixedArray(1, TENURED); 2718 factory->NewFixedArray(1, TENURED);
2719 } 2719 }
2720 CHECK_EQ(number_of_test_pages + 1, old_pointer_space->CountTotalPages()); 2720 CHECK_EQ(number_of_test_pages + 1, old_pointer_space->CountTotalPages());
2721 2721
2722 // Triggering one GC will cause a lot of garbage to be discovered but 2722 // Triggering one GC will cause a lot of garbage to be discovered but
2723 // even spread across all allocated pages. 2723 // even spread across all allocated pages.
2724 heap->CollectAllGarbage(Heap::kNoGCFlags, "triggered for preparation"); 2724 heap->CollectAllGarbage(Heap::kNoGCFlags, "triggered for preparation");
2725 CHECK_GE(number_of_test_pages + 1, old_pointer_space->CountTotalPages()); 2725 CHECK_GE(number_of_test_pages + 1, old_pointer_space->CountTotalPages());
2726 2726
(...skipping 28 matching lines...) Expand all
2755 // Generate a parent that lives in new-space. 2755 // Generate a parent that lives in new-space.
2756 v8::HandleScope inner_scope(CcTest::isolate()); 2756 v8::HandleScope inner_scope(CcTest::isolate());
2757 const char* c = "This text is long enough to trigger sliced strings."; 2757 const char* c = "This text is long enough to trigger sliced strings.";
2758 Handle<String> s = factory->NewStringFromAscii(CStrVector(c)); 2758 Handle<String> s = factory->NewStringFromAscii(CStrVector(c));
2759 CHECK(s->IsSeqOneByteString()); 2759 CHECK(s->IsSeqOneByteString());
2760 CHECK(CcTest::heap()->InNewSpace(*s)); 2760 CHECK(CcTest::heap()->InNewSpace(*s));
2761 2761
2762 // Generate a sliced string that is based on the above parent and 2762 // Generate a sliced string that is based on the above parent and
2763 // lives in old-space. 2763 // lives in old-space.
2764 SimulateFullSpace(CcTest::heap()->new_space()); 2764 SimulateFullSpace(CcTest::heap()->new_space());
2765 AlwaysAllocateScope always_allocate; 2765 AlwaysAllocateScope always_allocate(isolate);
2766 Handle<String> t = factory->NewProperSubString(s, 5, 35); 2766 Handle<String> t = factory->NewProperSubString(s, 5, 35);
2767 CHECK(t->IsSlicedString()); 2767 CHECK(t->IsSlicedString());
2768 CHECK(!CcTest::heap()->InNewSpace(*t)); 2768 CHECK(!CcTest::heap()->InNewSpace(*t));
2769 *slice.location() = *t.location(); 2769 *slice.location() = *t.location();
2770 } 2770 }
2771 2771
2772 CHECK(SlicedString::cast(*slice)->parent()->IsSeqOneByteString()); 2772 CHECK(SlicedString::cast(*slice)->parent()->IsSeqOneByteString());
2773 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); 2773 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
2774 CHECK(SlicedString::cast(*slice)->parent()->IsSeqOneByteString()); 2774 CHECK(SlicedString::cast(*slice)->parent()->IsSeqOneByteString());
2775 } 2775 }
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
3347 reinterpret_cast<byte*>(obj - kHeapObjectTag)); 3347 reinterpret_cast<byte*>(obj - kHeapObjectTag));
3348 CcTest::heap()->CreateFillerObjectAt(addr_obj, 3348 CcTest::heap()->CreateFillerObjectAt(addr_obj,
3349 AllocationMemento::kSize + kPointerSize); 3349 AllocationMemento::kSize + kPointerSize);
3350 3350
3351 // Give the array a name, making sure not to allocate strings. 3351 // Give the array a name, making sure not to allocate strings.
3352 v8::Handle<v8::Object> array_obj = v8::Utils::ToLocal(array); 3352 v8::Handle<v8::Object> array_obj = v8::Utils::ToLocal(array);
3353 CcTest::global()->Set(array_name, array_obj); 3353 CcTest::global()->Set(array_name, array_obj);
3354 3354
3355 // This should crash with a protection violation if we are running a build 3355 // This should crash with a protection violation if we are running a build
3356 // with the bug. 3356 // with the bug.
3357 AlwaysAllocateScope aa_scope; 3357 AlwaysAllocateScope aa_scope(isolate);
3358 v8::Script::Compile(mote_code_string)->Run(); 3358 v8::Script::Compile(mote_code_string)->Run();
3359 } 3359 }
3360 3360
3361 3361
3362 TEST(Regress168801) { 3362 TEST(Regress168801) {
3363 i::FLAG_always_compact = true; 3363 i::FLAG_always_compact = true;
3364 i::FLAG_cache_optimized_code = false; 3364 i::FLAG_cache_optimized_code = false;
3365 i::FLAG_allow_natives_syntax = true; 3365 i::FLAG_allow_natives_syntax = true;
3366 i::FLAG_flush_code_incrementally = true; 3366 i::FLAG_flush_code_incrementally = true;
3367 CcTest::InitializeVM(); 3367 CcTest::InitializeVM();
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
3733 v8::Handle<v8::Object> global = CcTest::global(); 3733 v8::Handle<v8::Object> global = CcTest::global();
3734 v8::Handle<v8::Function> g = 3734 v8::Handle<v8::Function> g =
3735 v8::Handle<v8::Function>::Cast(global->Get(v8_str("crash"))); 3735 v8::Handle<v8::Function>::Cast(global->Get(v8_str("crash")));
3736 v8::Handle<v8::Value> args1[] = { v8_num(1) }; 3736 v8::Handle<v8::Value> args1[] = { v8_num(1) };
3737 heap->DisableInlineAllocation(); 3737 heap->DisableInlineAllocation();
3738 heap->set_allocation_timeout(1); 3738 heap->set_allocation_timeout(1);
3739 g->Call(global, 1, args1); 3739 g->Call(global, 1, args1);
3740 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 3740 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
3741 } 3741 }
3742 #endif 3742 #endif
OLDNEW
« include/v8.h ('K') | « test/cctest/test-api.cc ('k') | test/cctest/test-strings.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698