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 2091 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2102 "f(4);"); | 2102 "f(4);"); |
2103 CHECK_EQ(4, res->ToObject()->GetRealNamedProperty(v8_str("x"))->Int32Value()); | 2103 CHECK_EQ(4, res->ToObject()->GetRealNamedProperty(v8_str("x"))->Int32Value()); |
2104 | 2104 |
2105 Handle<JSObject> o = | 2105 Handle<JSObject> o = |
2106 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); | 2106 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); |
2107 | 2107 |
2108 CHECK(HEAP->InNewSpace(*o)); | 2108 CHECK(HEAP->InNewSpace(*o)); |
2109 } | 2109 } |
2110 | 2110 |
2111 | 2111 |
2112 // Test pretenuring of array literals allocated with HAllocate. | 2112 TEST(OptimizedPretenuringIntegerArrayLiterals) { |
2113 TEST(OptimizedPretenuringArrayLiterals) { | |
2114 i::FLAG_allow_natives_syntax = true; | 2113 i::FLAG_allow_natives_syntax = true; |
2115 CcTest::InitializeVM(); | 2114 CcTest::InitializeVM(); |
2116 if (!i::V8::UseCrankshaft() || i::FLAG_always_opt) return; | 2115 if (!i::V8::UseCrankshaft() || i::FLAG_always_opt) return; |
2117 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; | 2116 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; |
2118 v8::HandleScope scope(CcTest::isolate()); | 2117 v8::HandleScope scope(CcTest::isolate()); |
2119 HEAP->SetNewSpaceHighPromotionModeActive(true); | 2118 HEAP->SetNewSpaceHighPromotionModeActive(true); |
2120 | 2119 |
2121 AlwaysAllocateScope always_allocate; | 2120 AlwaysAllocateScope always_allocate; |
2122 v8::Local<v8::Value> res = CompileRun( | 2121 v8::Local<v8::Value> res = CompileRun( |
2123 "function f() {" | 2122 "function f() {" |
2124 " var numbers = [1, 2, 3];" | 2123 " var numbers = [1, 2, 3];" |
2125 " numbers[0] = {};" | |
2126 " return numbers;" | 2124 " return numbers;" |
2127 "};" | 2125 "};" |
2128 "f(); f(); f();" | 2126 "f(); f(); f();" |
2129 "%OptimizeFunctionOnNextCall(f);" | 2127 "%OptimizeFunctionOnNextCall(f);" |
2130 "f();"); | 2128 "f();"); |
2131 | 2129 |
2132 Handle<JSObject> o = | 2130 Handle<JSObject> o = |
2133 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); | 2131 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); |
2134 | 2132 |
2135 CHECK(HEAP->InOldPointerSpace(o->elements())); | 2133 CHECK(HEAP->InOldPointerSpace(o->elements())); |
2134 CHECK(HEAP->InOldPointerSpace(*o)); | |
2136 } | 2135 } |
2137 | 2136 |
2138 | 2137 |
2139 TEST(OptimizedPretenuringSimpleArrayLiterals) { | 2138 static void OptimizedPretenuringMixedInObjectProperties(bool full) { |
2140 i::FLAG_allow_natives_syntax = true; | 2139 i::FLAG_allow_natives_syntax = true; |
2141 i::FLAG_pretenuring = false; | |
2142 CcTest::InitializeVM(); | 2140 CcTest::InitializeVM(); |
2143 if (!i::V8::UseCrankshaft() || i::FLAG_always_opt) return; | 2141 if (!i::V8::UseCrankshaft() || i::FLAG_always_opt) return; |
2144 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; | 2142 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; |
2145 v8::HandleScope scope(CcTest::isolate()); | 2143 v8::HandleScope scope(CcTest::isolate()); |
2144 HEAP->SetNewSpaceHighPromotionModeActive(true); | |
2146 | 2145 |
2147 AlwaysAllocateScope always_allocate; | 2146 AlwaysAllocateScope always_allocate; |
2147 | |
2148 if (full) { | |
2149 PagedSpace* old_pointer_space = HEAP->old_pointer_space(); | |
2150 SimulateFullSpace(old_pointer_space); | |
2151 } | |
2152 | |
2148 v8::Local<v8::Value> res = CompileRun( | 2153 v8::Local<v8::Value> res = CompileRun( |
2149 "function f() {" | 2154 "function f() {" |
2150 " return [1, 2, 3];" | 2155 " var numbers = {a: {c: 2.2, d: {}}, b: 1.1};" |
2156 " return numbers;" | |
2151 "};" | 2157 "};" |
2152 "f(); f(); f();" | 2158 "f(); f(); f();" |
2153 "%OptimizeFunctionOnNextCall(f);" | 2159 "%OptimizeFunctionOnNextCall(f);" |
2154 "f();"); | 2160 "f();"); |
2155 | 2161 |
2156 Handle<JSObject> o = | 2162 Handle<JSObject> o = |
2157 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); | 2163 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); |
2158 | 2164 |
2159 CHECK(HEAP->InNewSpace(*o)); | 2165 CHECK(HEAP->InOldPointerSpace(*o)); |
2160 } | 2166 CHECK(HEAP->InOldPointerSpace(o->RawFastPropertyAt(0))); |
2161 | 2167 CHECK(HEAP->InOldDataSpace(o->RawFastPropertyAt(1))); |
2162 | 2168 |
2169 JSObject* inner_object = reinterpret_cast<JSObject*>(o->RawFastPropertyAt(0)); | |
2170 CHECK(HEAP->InOldPointerSpace(inner_object)); | |
2171 CHECK(HEAP->InOldDataSpace(inner_object->RawFastPropertyAt(0))); | |
2172 CHECK(HEAP->InOldPointerSpace(inner_object->RawFastPropertyAt(1))); | |
2173 } | |
2174 | |
2175 | |
2176 TEST(OptimizedPretenuringMixedInObjectProperties) { | |
2177 OptimizedPretenuringMixedInObjectProperties(false); | |
2178 } | |
2179 | |
2180 | |
2181 TEST(OptimizedPretenuringMixedInObjectPropertiesFullHeap) { | |
2182 OptimizedPretenuringMixedInObjectProperties(true); | |
2183 } | |
2184 | |
2185 | |
2186 static void OptimizedPretenuringDoubleArrayProperties(bool full) { | |
2187 i::FLAG_allow_natives_syntax = true; | |
2188 CcTest::InitializeVM(); | |
2189 if (!i::V8::UseCrankshaft() || i::FLAG_always_opt) return; | |
2190 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; | |
2191 v8::HandleScope scope(CcTest::isolate()); | |
2192 HEAP->SetNewSpaceHighPromotionModeActive(true); | |
2193 | |
2194 AlwaysAllocateScope always_allocate; | |
Michael Starzinger
2013/06/24 15:04:47
Is the AlwaysAllocateScope really necessary here?
Hannes Payer (out of office)
2013/06/24 16:44:22
Done.
| |
2195 | |
2196 if (full) { | |
Michael Starzinger
2013/06/24 15:04:47
As discussed offline: This will not really trigger
Hannes Payer (out of office)
2013/06/24 16:44:22
Done.
| |
2197 PagedSpace* old_pointer_space = HEAP->old_pointer_space(); | |
2198 SimulateFullSpace(old_pointer_space); | |
2199 } | |
2200 | |
2201 v8::Local<v8::Value> res = CompileRun( | |
2202 "function f() {" | |
2203 " var numbers = {a: 1.1, b: 2.2};" | |
2204 " return numbers;" | |
2205 "};" | |
2206 "f(); f(); f();" | |
2207 "%OptimizeFunctionOnNextCall(f);" | |
2208 "f();"); | |
2209 | |
2210 Handle<JSObject> o = | |
2211 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); | |
2212 | |
2213 CHECK(HEAP->InOldPointerSpace(*o)); | |
2214 CHECK(HEAP->InOldDataSpace(o->properties())); | |
2215 } | |
2216 | |
2217 | |
2218 TEST(OptimizedPretenuringDoubleArrayProperties) { | |
2219 OptimizedPretenuringDoubleArrayProperties(false); | |
2220 } | |
2221 | |
2222 | |
2223 TEST(OptimizedPretenuringDoubleArrayPropertiesFullHeap) { | |
2224 OptimizedPretenuringDoubleArrayProperties(true); | |
2225 } | |
2226 | |
2227 | |
2228 static void OptimizedPretenuringdoubleArrayLiterals(bool full) { | |
2229 i::FLAG_allow_natives_syntax = true; | |
2230 CcTest::InitializeVM(); | |
2231 if (!i::V8::UseCrankshaft() || i::FLAG_always_opt) return; | |
2232 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; | |
2233 v8::HandleScope scope(CcTest::isolate()); | |
2234 HEAP->SetNewSpaceHighPromotionModeActive(true); | |
2235 | |
2236 AlwaysAllocateScope always_allocate; | |
2237 | |
2238 if (full) { | |
2239 PagedSpace* old_pointer_space = HEAP->old_pointer_space(); | |
2240 SimulateFullSpace(old_pointer_space); | |
2241 } | |
2242 | |
2243 v8::Local<v8::Value> res = CompileRun( | |
2244 "function f() {" | |
2245 " var numbers = [1.1, 2.2, 3.3];" | |
2246 " return numbers;" | |
2247 "};" | |
2248 "f(); f(); f();" | |
2249 "%OptimizeFunctionOnNextCall(f);" | |
2250 "f();"); | |
2251 | |
2252 Handle<JSObject> o = | |
2253 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); | |
2254 | |
2255 CHECK(HEAP->InOldDataSpace(o->elements())); | |
2256 CHECK(HEAP->InOldPointerSpace(*o)); | |
2257 } | |
2258 | |
2259 | |
2260 TEST(OptimizedPretenuringdoubleArrayLiterals) { | |
2261 OptimizedPretenuringdoubleArrayLiterals(false); | |
2262 } | |
2263 | |
2264 | |
2265 TEST(OptimizedPretenuringdoubleArrayLiteralsFullHeap) { | |
2266 OptimizedPretenuringdoubleArrayLiterals(true); | |
2267 } | |
2268 | |
2269 | |
2270 static void OptimizedPretenuringNestedMixedArrayLiterals(bool full) { | |
2271 i::FLAG_allow_natives_syntax = true; | |
2272 CcTest::InitializeVM(); | |
2273 if (!i::V8::UseCrankshaft() || i::FLAG_always_opt) return; | |
2274 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; | |
2275 v8::HandleScope scope(CcTest::isolate()); | |
2276 HEAP->SetNewSpaceHighPromotionModeActive(true); | |
2277 | |
2278 AlwaysAllocateScope always_allocate; | |
2279 | |
2280 if (full) { | |
2281 PagedSpace* old_pointer_space = HEAP->old_pointer_space(); | |
2282 SimulateFullSpace(old_pointer_space); | |
2283 } | |
2284 | |
2285 v8::Local<v8::Value> res = CompileRun( | |
2286 "function f() {" | |
2287 " var numbers = [[1, 2, 3],[1.1, 2.2, 3.3]];" | |
2288 " return numbers;" | |
2289 "};" | |
2290 "f(); f(); f();" | |
2291 "%OptimizeFunctionOnNextCall(f);" | |
2292 "f();"); | |
2293 | |
2294 v8::Local<v8::Value> int_array = v8::Object::Cast(*res)->Get(v8_str("0")); | |
2295 Handle<JSObject> int_array_handle = | |
2296 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(int_array)); | |
2297 v8::Local<v8::Value> double_array = v8::Object::Cast(*res)->Get(v8_str("1")); | |
2298 Handle<JSObject> double_array_handle = | |
2299 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(double_array)); | |
2300 | |
2301 Handle<JSObject> o = | |
2302 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); | |
2303 CHECK(HEAP->InOldPointerSpace(*o)); | |
2304 CHECK(HEAP->InOldPointerSpace(*int_array_handle)); | |
2305 CHECK(HEAP->InOldPointerSpace(int_array_handle->elements())); | |
2306 CHECK(HEAP->InOldPointerSpace(*double_array_handle)); | |
2307 CHECK(HEAP->InOldDataSpace(double_array_handle->elements())); | |
2308 } | |
2309 | |
2310 | |
2311 TEST(OptimizedPretenuringNestedMixedArrayLiterals) { | |
2312 OptimizedPretenuringNestedMixedArrayLiterals(false); | |
2313 } | |
2314 | |
2315 | |
2316 TEST(OptimizedPretenuringNestedMixedArrayLiteralsFullHeap) { | |
2317 OptimizedPretenuringNestedMixedArrayLiterals(true); | |
2318 } | |
2319 | |
2320 | |
2321 TEST(OptimizedPretenuringNestedIntegerLiterals) { | |
2322 i::FLAG_allow_natives_syntax = true; | |
2323 CcTest::InitializeVM(); | |
2324 if (!i::V8::UseCrankshaft() || i::FLAG_always_opt) return; | |
2325 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; | |
2326 v8::HandleScope scope(CcTest::isolate()); | |
2327 HEAP->SetNewSpaceHighPromotionModeActive(true); | |
2328 | |
2329 AlwaysAllocateScope always_allocate; | |
2330 v8::Local<v8::Value> res = CompileRun( | |
2331 "function f() {" | |
2332 " var numbers = [[1, 1, 1],[2, 2, 2]];" | |
2333 " return numbers;" | |
2334 "};" | |
2335 "f(); f(); f();" | |
2336 "%OptimizeFunctionOnNextCall(f);" | |
2337 "f();"); | |
2338 | |
2339 v8::Local<v8::Value> int_array_1 = v8::Object::Cast(*res)->Get(v8_str("0")); | |
2340 Handle<JSObject> int_array_handle_1 = | |
2341 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(int_array_1)); | |
2342 v8::Local<v8::Value> int_array_2 = v8::Object::Cast(*res)->Get(v8_str("1")); | |
2343 Handle<JSObject> int_array_handle_2 = | |
2344 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(int_array_2)); | |
2345 | |
2346 Handle<JSObject> o = | |
2347 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); | |
2348 CHECK(HEAP->InOldPointerSpace(*o)); | |
2349 CHECK(HEAP->InOldPointerSpace(*int_array_handle_1)); | |
2350 CHECK(HEAP->InOldPointerSpace(int_array_handle_1->elements())); | |
2351 CHECK(HEAP->InOldPointerSpace(*int_array_handle_2)); | |
2352 CHECK(HEAP->InOldPointerSpace(int_array_handle_2->elements())); | |
2353 } | |
2354 | |
2355 | |
2356 static void TestOptimizedPretenuringNestedDoubleLiterals(bool full) { | |
2357 i::FLAG_allow_natives_syntax = true; | |
2358 CcTest::InitializeVM(); | |
2359 if (!i::V8::UseCrankshaft() || i::FLAG_always_opt) return; | |
2360 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; | |
2361 v8::HandleScope scope(CcTest::isolate()); | |
2362 HEAP->SetNewSpaceHighPromotionModeActive(true); | |
2363 | |
2364 AlwaysAllocateScope always_allocate; | |
2365 | |
2366 if (full) { | |
2367 PagedSpace* old_pointer_space = HEAP->old_pointer_space(); | |
2368 SimulateFullSpace(old_pointer_space); | |
2369 } | |
2370 | |
2371 v8::Local<v8::Value> res = CompileRun( | |
2372 "function f() {" | |
2373 " var numbers = [[1.1, 1.2, 1.3],[2.1, 2.2, 2.3]];" | |
2374 " return numbers;" | |
2375 "};" | |
2376 "f(); f(); f();" | |
2377 "%OptimizeFunctionOnNextCall(f);" | |
2378 "f();"); | |
2379 | |
2380 v8::Local<v8::Value> double_array_1 = | |
2381 v8::Object::Cast(*res)->Get(v8_str("0")); | |
2382 Handle<JSObject> double_array_handle_1 = | |
2383 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(double_array_1)); | |
2384 v8::Local<v8::Value> double_array_2 = | |
2385 v8::Object::Cast(*res)->Get(v8_str("1")); | |
2386 Handle<JSObject> double_array_handle_2 = | |
2387 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(double_array_2)); | |
2388 | |
2389 Handle<JSObject> o = | |
2390 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); | |
2391 CHECK(HEAP->InOldPointerSpace(*o)); | |
2392 CHECK(HEAP->InOldPointerSpace(*double_array_handle_1)); | |
2393 CHECK(HEAP->InOldDataSpace(double_array_handle_1->elements())); | |
2394 CHECK(HEAP->InOldPointerSpace(*double_array_handle_2)); | |
2395 CHECK(HEAP->InOldDataSpace(double_array_handle_2->elements())); | |
2396 } | |
2397 | |
2398 | |
2399 TEST(OptimizedPretenuringNestedDoubleLiterals) { | |
2400 TestOptimizedPretenuringNestedDoubleLiterals(false); | |
2401 } | |
2402 | |
2403 | |
2404 TEST(OptimizedPretenuringNestedDoubleLiteralsFullHeap) { | |
2405 TestOptimizedPretenuringNestedDoubleLiterals(true); | |
2406 } | |
2407 | |
2408 | |
2163 // Test regular array literals allocation. | 2409 // Test regular array literals allocation. |
2164 TEST(OptimizedAllocationArrayLiterals) { | 2410 TEST(OptimizedAllocationArrayLiterals) { |
2165 i::FLAG_allow_natives_syntax = true; | 2411 i::FLAG_allow_natives_syntax = true; |
2166 CcTest::InitializeVM(); | 2412 CcTest::InitializeVM(); |
2167 if (!i::V8::UseCrankshaft() || i::FLAG_always_opt) return; | 2413 if (!i::V8::UseCrankshaft() || i::FLAG_always_opt) return; |
2168 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; | 2414 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; |
2169 v8::HandleScope scope(CcTest::isolate()); | 2415 v8::HandleScope scope(CcTest::isolate()); |
2170 | 2416 |
2171 AlwaysAllocateScope always_allocate; | 2417 AlwaysAllocateScope always_allocate; |
2172 v8::Local<v8::Value> res = CompileRun( | 2418 v8::Local<v8::Value> res = CompileRun( |
(...skipping 982 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3155 " var a = new Array(n);" | 3401 " var a = new Array(n);" |
3156 " for (var i = 0; i < n; i += 100) a[i] = i;" | 3402 " for (var i = 0; i < n; i += 100) a[i] = i;" |
3157 "};" | 3403 "};" |
3158 "f(10 * 1024 * 1024);"); | 3404 "f(10 * 1024 * 1024);"); |
3159 IncrementalMarking* marking = HEAP->incremental_marking(); | 3405 IncrementalMarking* marking = HEAP->incremental_marking(); |
3160 if (marking->IsStopped()) marking->Start(); | 3406 if (marking->IsStopped()) marking->Start(); |
3161 // This big step should be sufficient to mark the whole array. | 3407 // This big step should be sufficient to mark the whole array. |
3162 marking->Step(100 * MB, IncrementalMarking::NO_GC_VIA_STACK_GUARD); | 3408 marking->Step(100 * MB, IncrementalMarking::NO_GC_VIA_STACK_GUARD); |
3163 ASSERT(marking->IsComplete()); | 3409 ASSERT(marking->IsComplete()); |
3164 } | 3410 } |
OLD | NEW |