OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 | 2 |
3 #include <stdlib.h> | 3 #include <stdlib.h> |
4 | 4 |
5 #include "v8.h" | 5 #include "v8.h" |
6 | 6 |
7 #include "execution.h" | 7 #include "execution.h" |
8 #include "factory.h" | 8 #include "factory.h" |
9 #include "macro-assembler.h" | 9 #include "macro-assembler.h" |
10 #include "global-handles.h" | 10 #include "global-handles.h" |
(...skipping 1246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1257 } | 1257 } |
1258 } | 1258 } |
1259 | 1259 |
1260 | 1260 |
1261 static void FillUpNewSpace(NewSpace* new_space) { | 1261 static void FillUpNewSpace(NewSpace* new_space) { |
1262 // Fill up new space to the point that it is completely full. Make sure | 1262 // Fill up new space to the point that it is completely full. Make sure |
1263 // that the scavenger does not undo the filling. | 1263 // that the scavenger does not undo the filling. |
1264 v8::HandleScope scope; | 1264 v8::HandleScope scope; |
1265 AlwaysAllocateScope always_allocate; | 1265 AlwaysAllocateScope always_allocate; |
1266 intptr_t available = new_space->EffectiveCapacity() - new_space->Size(); | 1266 intptr_t available = new_space->EffectiveCapacity() - new_space->Size(); |
1267 intptr_t number_of_fillers = (available / FixedArray::SizeFor(1000)) - 10; | 1267 intptr_t number_of_fillers = (available / FixedArray::SizeFor(32)) - 1; |
1268 for (intptr_t i = 0; i < number_of_fillers; i++) { | 1268 for (intptr_t i = 0; i < number_of_fillers; i++) { |
1269 CHECK(HEAP->InNewSpace(*FACTORY->NewFixedArray(1000, NOT_TENURED))); | 1269 CHECK(HEAP->InNewSpace(*FACTORY->NewFixedArray(32, NOT_TENURED))); |
1270 } | 1270 } |
1271 } | 1271 } |
1272 | 1272 |
1273 | 1273 |
1274 TEST(GrowAndShrinkNewSpace) { | 1274 TEST(GrowAndShrinkNewSpace) { |
1275 InitializeVM(); | 1275 InitializeVM(); |
1276 NewSpace* new_space = HEAP->new_space(); | 1276 NewSpace* new_space = HEAP->new_space(); |
1277 | 1277 |
1278 // Explicitly growing should double the space capacity. | 1278 // Explicitly growing should double the space capacity. |
1279 intptr_t old_capacity, new_capacity; | 1279 intptr_t old_capacity, new_capacity; |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1673 // The following two calls will increment HEAP->global_ic_age(). | 1673 // The following two calls will increment HEAP->global_ic_age(). |
1674 // Since incremental marking is off, IdleNotification will do full GC. | 1674 // Since incremental marking is off, IdleNotification will do full GC. |
1675 const int kLongIdlePauseInMs = 1000; | 1675 const int kLongIdlePauseInMs = 1000; |
1676 v8::V8::ContextDisposedNotification(); | 1676 v8::V8::ContextDisposedNotification(); |
1677 v8::V8::IdleNotification(kLongIdlePauseInMs); | 1677 v8::V8::IdleNotification(kLongIdlePauseInMs); |
1678 | 1678 |
1679 CHECK_EQ(HEAP->global_ic_age(), f->shared()->ic_age()); | 1679 CHECK_EQ(HEAP->global_ic_age(), f->shared()->ic_age()); |
1680 CHECK_EQ(0, f->shared()->opt_count()); | 1680 CHECK_EQ(0, f->shared()->opt_count()); |
1681 CHECK_EQ(0, f->shared()->code()->profiler_ticks()); | 1681 CHECK_EQ(0, f->shared()->code()->profiler_ticks()); |
1682 } | 1682 } |
| 1683 |
| 1684 |
| 1685 // Test that HAllocateObject will always return an object in new-space. |
| 1686 TEST(OptimizedAllocationAlwaysInNewSpace) { |
| 1687 i::FLAG_allow_natives_syntax = true; |
| 1688 InitializeVM(); |
| 1689 if (!i::V8::UseCrankshaft() || i::FLAG_always_opt) return; |
| 1690 v8::HandleScope scope; |
| 1691 |
| 1692 FillUpNewSpace(HEAP->new_space()); |
| 1693 AlwaysAllocateScope always_allocate; |
| 1694 v8::Local<v8::Value> res = CompileRun( |
| 1695 "function c(x) {" |
| 1696 " this.x = x;" |
| 1697 " for (var i = 0; i < 32; i++) {" |
| 1698 " this['x' + i] = x;" |
| 1699 " }" |
| 1700 "}" |
| 1701 "function f(x) { return new c(x); };" |
| 1702 "f(1); f(2); f(3);" |
| 1703 "%OptimizeFunctionOnNextCall(f);" |
| 1704 "f(4);"); |
| 1705 CHECK(res->IsObject()); |
| 1706 CHECK(res->ToObject()->GetRealNamedProperty(v8_str("x"))->Int32Value() == 4); |
| 1707 |
| 1708 Handle<JSObject> o = |
| 1709 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); |
| 1710 |
| 1711 CHECK(HEAP->InNewSpace(*o)); |
| 1712 } |
OLD | NEW |