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 2176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2187 | 2187 |
2188 Handle<JSObject> o = | 2188 Handle<JSObject> o = |
2189 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); | 2189 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); |
2190 | 2190 |
2191 CHECK(CcTest::heap()->InNewSpace(*o)); | 2191 CHECK(CcTest::heap()->InNewSpace(*o)); |
2192 } | 2192 } |
2193 | 2193 |
2194 | 2194 |
2195 TEST(OptimizedPretenuringAllocationFolding) { | 2195 TEST(OptimizedPretenuringAllocationFolding) { |
2196 i::FLAG_allow_natives_syntax = true; | 2196 i::FLAG_allow_natives_syntax = true; |
2197 i::FLAG_max_semi_space_size = 1; | 2197 i::FLAG_expose_gc = true; |
2198 i::FLAG_allocation_site_pretenuring = false; | |
2199 CcTest::InitializeVM(); | 2198 CcTest::InitializeVM(); |
2200 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; | 2199 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; |
2201 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; | 2200 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; |
2202 v8::HandleScope scope(CcTest::isolate()); | 2201 v8::HandleScope scope(CcTest::isolate()); |
2203 | 2202 |
2204 v8::Local<v8::Value> res = CompileRun( | 2203 i::ScopedVector<char> source(1024); |
2205 "function DataObject() {" | 2204 i::OS::SNPrintF( |
2206 " this.a = 1.1;" | 2205 source, |
2207 " this.b = [{}];" | 2206 "var number_elements = %d;" |
2208 " this.c = 1.2;" | |
2209 " this.d = [{}];" | |
2210 " this.e = 1.3;" | |
2211 " this.f = [{}];" | |
2212 "}" | |
2213 "var number_elements = 20000;" | |
2214 "var elements = new Array();" | 2207 "var elements = new Array();" |
2215 "function f() {" | 2208 "function f() {" |
2216 " for (var i = 0; i < number_elements; i++) {" | 2209 " for (var i = 0; i < number_elements; i++) {" |
2217 " elements[i] = new DataObject();" | 2210 " elements[i] = [[{}], [1.1]];" |
2218 " }" | 2211 " }" |
2219 " return elements[number_elements-1]" | 2212 " return elements[number_elements-1]" |
2220 "};" | 2213 "};" |
2221 "f(); f(); f();" | 2214 "f(); gc();" |
| 2215 "f(); f();" |
2222 "%OptimizeFunctionOnNextCall(f);" | 2216 "%OptimizeFunctionOnNextCall(f);" |
2223 "f();"); | 2217 "f();", |
| 2218 AllocationSite::kPretenureMinimumCreated); |
| 2219 |
| 2220 v8::Local<v8::Value> res = CompileRun(source.start()); |
| 2221 |
| 2222 v8::Local<v8::Value> int_array = v8::Object::Cast(*res)->Get(v8_str("0")); |
| 2223 Handle<JSObject> int_array_handle = |
| 2224 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(int_array)); |
| 2225 v8::Local<v8::Value> double_array = v8::Object::Cast(*res)->Get(v8_str("1")); |
| 2226 Handle<JSObject> double_array_handle = |
| 2227 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(double_array)); |
2224 | 2228 |
2225 Handle<JSObject> o = | 2229 Handle<JSObject> o = |
2226 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); | 2230 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); |
2227 | 2231 CHECK(CcTest::heap()->InOldPointerSpace(*o)); |
2228 CHECK(CcTest::heap()->InOldDataSpace(o->RawFastPropertyAt(0))); | 2232 CHECK(CcTest::heap()->InOldPointerSpace(*int_array_handle)); |
2229 CHECK(CcTest::heap()->InOldPointerSpace(o->RawFastPropertyAt(1))); | 2233 CHECK(CcTest::heap()->InOldPointerSpace(int_array_handle->elements())); |
2230 CHECK(CcTest::heap()->InOldDataSpace(o->RawFastPropertyAt(2))); | 2234 CHECK(CcTest::heap()->InOldPointerSpace(*double_array_handle)); |
2231 CHECK(CcTest::heap()->InOldPointerSpace(o->RawFastPropertyAt(3))); | 2235 CHECK(CcTest::heap()->InOldDataSpace(double_array_handle->elements())); |
2232 CHECK(CcTest::heap()->InOldDataSpace(o->RawFastPropertyAt(4))); | |
2233 CHECK(CcTest::heap()->InOldPointerSpace(o->RawFastPropertyAt(5))); | |
2234 } | 2236 } |
2235 | 2237 |
2236 | 2238 |
2237 TEST(OptimizedPretenuringAllocationFoldingBlocks) { | 2239 TEST(OptimizedPretenuringObjectArrayLiterals) { |
2238 i::FLAG_allow_natives_syntax = true; | 2240 i::FLAG_allow_natives_syntax = true; |
2239 i::FLAG_max_semi_space_size = 1; | 2241 i::FLAG_expose_gc = true; |
2240 i::FLAG_allocation_site_pretenuring = false; | |
2241 CcTest::InitializeVM(); | 2242 CcTest::InitializeVM(); |
2242 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; | 2243 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; |
2243 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; | 2244 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; |
2244 v8::HandleScope scope(CcTest::isolate()); | 2245 v8::HandleScope scope(CcTest::isolate()); |
2245 | 2246 |
2246 v8::Local<v8::Value> res = CompileRun( | 2247 i::ScopedVector<char> source(1024); |
2247 "var number_elements = 30000;" | 2248 i::OS::SNPrintF( |
2248 "var elements = new Array(number_elements);" | 2249 source, |
2249 "function DataObject() {" | 2250 "var number_elements = %d;" |
2250 " this.a = [{}];" | |
2251 " this.b = [{}];" | |
2252 " this.c = 1.1;" | |
2253 " this.d = 1.2;" | |
2254 " this.e = [{}];" | |
2255 " this.f = 1.3;" | |
2256 "}" | |
2257 "function f() {" | |
2258 " for (var i = 0; i < number_elements; i++) {" | |
2259 " elements[i] = new DataObject();" | |
2260 " }" | |
2261 " return elements[number_elements - 1];" | |
2262 "};" | |
2263 "f(); f(); f();" | |
2264 "%OptimizeFunctionOnNextCall(f);" | |
2265 "f();"); | |
2266 | |
2267 Handle<JSObject> o = | |
2268 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); | |
2269 | |
2270 CHECK(CcTest::heap()->InOldPointerSpace(o->RawFastPropertyAt(0))); | |
2271 CHECK(CcTest::heap()->InOldPointerSpace(o->RawFastPropertyAt(1))); | |
2272 CHECK(CcTest::heap()->InOldDataSpace(o->RawFastPropertyAt(2))); | |
2273 CHECK(CcTest::heap()->InOldDataSpace(o->RawFastPropertyAt(3))); | |
2274 CHECK(CcTest::heap()->InOldPointerSpace(o->RawFastPropertyAt(4))); | |
2275 CHECK(CcTest::heap()->InOldDataSpace(o->RawFastPropertyAt(5))); | |
2276 } | |
2277 | |
2278 | |
2279 TEST(OptimizedPretenuringObjectArrayLiterals) { | |
2280 i::FLAG_allow_natives_syntax = true; | |
2281 i::FLAG_max_semi_space_size = 1; | |
2282 CcTest::InitializeVM(); | |
2283 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; | |
2284 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; | |
2285 v8::HandleScope scope(CcTest::isolate()); | |
2286 | |
2287 v8::Local<v8::Value> res = CompileRun( | |
2288 "var number_elements = 20000;" | |
2289 "var elements = new Array(number_elements);" | 2251 "var elements = new Array(number_elements);" |
2290 "function f() {" | 2252 "function f() {" |
2291 " for (var i = 0; i < number_elements; i++) {" | 2253 " for (var i = 0; i < number_elements; i++) {" |
2292 " elements[i] = [{}, {}, {}];" | 2254 " elements[i] = [{}, {}, {}];" |
2293 " }" | 2255 " }" |
2294 " return elements[number_elements - 1];" | 2256 " return elements[number_elements - 1];" |
2295 "};" | 2257 "};" |
2296 "f(); f(); f();" | 2258 "f(); gc();" |
| 2259 "f(); f();" |
2297 "%OptimizeFunctionOnNextCall(f);" | 2260 "%OptimizeFunctionOnNextCall(f);" |
2298 "f();"); | 2261 "f();", |
| 2262 AllocationSite::kPretenureMinimumCreated); |
| 2263 |
| 2264 v8::Local<v8::Value> res = CompileRun(source.start()); |
2299 | 2265 |
2300 Handle<JSObject> o = | 2266 Handle<JSObject> o = |
2301 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); | 2267 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); |
2302 | 2268 |
2303 CHECK(CcTest::heap()->InOldPointerSpace(o->elements())); | 2269 CHECK(CcTest::heap()->InOldPointerSpace(o->elements())); |
2304 CHECK(CcTest::heap()->InOldPointerSpace(*o)); | 2270 CHECK(CcTest::heap()->InOldPointerSpace(*o)); |
2305 } | 2271 } |
2306 | 2272 |
2307 | 2273 |
2308 TEST(OptimizedPretenuringMixedInObjectProperties) { | 2274 TEST(OptimizedPretenuringMixedInObjectProperties) { |
2309 i::FLAG_allow_natives_syntax = true; | 2275 i::FLAG_allow_natives_syntax = true; |
2310 i::FLAG_max_semi_space_size = 1; | 2276 i::FLAG_expose_gc = true; |
2311 CcTest::InitializeVM(); | 2277 CcTest::InitializeVM(); |
2312 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; | 2278 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; |
2313 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; | 2279 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; |
2314 v8::HandleScope scope(CcTest::isolate()); | 2280 v8::HandleScope scope(CcTest::isolate()); |
2315 | 2281 |
2316 v8::Local<v8::Value> res = CompileRun( | 2282 i::ScopedVector<char> source(1024); |
2317 "var number_elements = 20000;" | 2283 i::OS::SNPrintF( |
| 2284 source, |
| 2285 "var number_elements = %d;" |
2318 "var elements = new Array(number_elements);" | 2286 "var elements = new Array(number_elements);" |
2319 "function f() {" | 2287 "function f() {" |
2320 " for (var i = 0; i < number_elements; i++) {" | 2288 " for (var i = 0; i < number_elements; i++) {" |
2321 " elements[i] = {a: {c: 2.2, d: {}}, b: 1.1};" | 2289 " elements[i] = {a: {c: 2.2, d: {}}, b: 1.1};" |
2322 " }" | 2290 " }" |
2323 " return elements[number_elements - 1];" | 2291 " return elements[number_elements - 1];" |
2324 "};" | 2292 "};" |
2325 "f(); f(); f();" | 2293 "f(); gc();" |
| 2294 "f(); f();" |
2326 "%OptimizeFunctionOnNextCall(f);" | 2295 "%OptimizeFunctionOnNextCall(f);" |
2327 "f();"); | 2296 "f();", |
| 2297 AllocationSite::kPretenureMinimumCreated); |
| 2298 |
| 2299 v8::Local<v8::Value> res = CompileRun(source.start()); |
2328 | 2300 |
2329 Handle<JSObject> o = | 2301 Handle<JSObject> o = |
2330 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); | 2302 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); |
2331 | 2303 |
2332 CHECK(CcTest::heap()->InOldPointerSpace(*o)); | 2304 CHECK(CcTest::heap()->InOldPointerSpace(*o)); |
2333 CHECK(CcTest::heap()->InOldPointerSpace(o->RawFastPropertyAt(0))); | 2305 CHECK(CcTest::heap()->InOldPointerSpace(o->RawFastPropertyAt(0))); |
2334 CHECK(CcTest::heap()->InOldDataSpace(o->RawFastPropertyAt(1))); | 2306 CHECK(CcTest::heap()->InOldDataSpace(o->RawFastPropertyAt(1))); |
2335 | 2307 |
2336 JSObject* inner_object = reinterpret_cast<JSObject*>(o->RawFastPropertyAt(0)); | 2308 JSObject* inner_object = reinterpret_cast<JSObject*>(o->RawFastPropertyAt(0)); |
2337 CHECK(CcTest::heap()->InOldPointerSpace(inner_object)); | 2309 CHECK(CcTest::heap()->InOldPointerSpace(inner_object)); |
2338 CHECK(CcTest::heap()->InOldDataSpace(inner_object->RawFastPropertyAt(0))); | 2310 CHECK(CcTest::heap()->InOldDataSpace(inner_object->RawFastPropertyAt(0))); |
2339 CHECK(CcTest::heap()->InOldPointerSpace(inner_object->RawFastPropertyAt(1))); | 2311 CHECK(CcTest::heap()->InOldPointerSpace(inner_object->RawFastPropertyAt(1))); |
2340 } | 2312 } |
2341 | 2313 |
2342 | 2314 |
2343 TEST(OptimizedPretenuringDoubleArrayProperties) { | 2315 TEST(OptimizedPretenuringDoubleArrayProperties) { |
2344 i::FLAG_allow_natives_syntax = true; | 2316 i::FLAG_allow_natives_syntax = true; |
2345 i::FLAG_max_semi_space_size = 1; | 2317 i::FLAG_expose_gc = true; |
2346 CcTest::InitializeVM(); | 2318 CcTest::InitializeVM(); |
2347 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; | 2319 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; |
2348 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; | 2320 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; |
2349 v8::HandleScope scope(CcTest::isolate()); | 2321 v8::HandleScope scope(CcTest::isolate()); |
2350 | 2322 |
2351 v8::Local<v8::Value> res = CompileRun( | 2323 i::ScopedVector<char> source(1024); |
2352 "var number_elements = 30000;" | 2324 i::OS::SNPrintF( |
| 2325 source, |
| 2326 "var number_elements = %d;" |
2353 "var elements = new Array(number_elements);" | 2327 "var elements = new Array(number_elements);" |
2354 "function f() {" | 2328 "function f() {" |
2355 " for (var i = 0; i < number_elements; i++) {" | 2329 " for (var i = 0; i < number_elements; i++) {" |
2356 " elements[i] = {a: 1.1, b: 2.2};" | 2330 " elements[i] = {a: 1.1, b: 2.2};" |
2357 " }" | 2331 " }" |
2358 " return elements[i - 1];" | 2332 " return elements[i - 1];" |
2359 "};" | 2333 "};" |
2360 "f(); f(); f();" | 2334 "f(); gc();" |
| 2335 "f(); f();" |
2361 "%OptimizeFunctionOnNextCall(f);" | 2336 "%OptimizeFunctionOnNextCall(f);" |
2362 "f();"); | 2337 "f();", |
| 2338 AllocationSite::kPretenureMinimumCreated); |
| 2339 |
| 2340 v8::Local<v8::Value> res = CompileRun(source.start()); |
2363 | 2341 |
2364 Handle<JSObject> o = | 2342 Handle<JSObject> o = |
2365 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); | 2343 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); |
2366 | 2344 |
2367 CHECK(CcTest::heap()->InOldPointerSpace(*o)); | 2345 CHECK(CcTest::heap()->InOldPointerSpace(*o)); |
2368 CHECK(CcTest::heap()->InOldDataSpace(o->properties())); | 2346 CHECK(CcTest::heap()->InOldDataSpace(o->properties())); |
2369 } | 2347 } |
2370 | 2348 |
2371 | 2349 |
2372 TEST(OptimizedPretenuringdoubleArrayLiterals) { | 2350 TEST(OptimizedPretenuringdoubleArrayLiterals) { |
2373 i::FLAG_allow_natives_syntax = true; | 2351 i::FLAG_allow_natives_syntax = true; |
2374 i::FLAG_max_semi_space_size = 1; | 2352 i::FLAG_expose_gc = true; |
2375 CcTest::InitializeVM(); | 2353 CcTest::InitializeVM(); |
2376 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; | 2354 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; |
2377 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; | 2355 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; |
2378 v8::HandleScope scope(CcTest::isolate()); | 2356 v8::HandleScope scope(CcTest::isolate()); |
2379 | 2357 |
2380 v8::Local<v8::Value> res = CompileRun( | 2358 i::ScopedVector<char> source(1024); |
2381 "var number_elements = 30000;" | 2359 i::OS::SNPrintF( |
| 2360 source, |
| 2361 "var number_elements = %d;" |
2382 "var elements = new Array(number_elements);" | 2362 "var elements = new Array(number_elements);" |
2383 "function f() {" | 2363 "function f() {" |
2384 " for (var i = 0; i < number_elements; i++) {" | 2364 " for (var i = 0; i < number_elements; i++) {" |
2385 " elements[i] = [1.1, 2.2, 3.3];" | 2365 " elements[i] = [1.1, 2.2, 3.3];" |
2386 " }" | 2366 " }" |
2387 " return elements[number_elements - 1];" | 2367 " return elements[number_elements - 1];" |
2388 "};" | 2368 "};" |
2389 "f(); f(); f();" | 2369 "f(); gc();" |
| 2370 "f(); f();" |
2390 "%OptimizeFunctionOnNextCall(f);" | 2371 "%OptimizeFunctionOnNextCall(f);" |
2391 "f();"); | 2372 "f();", |
| 2373 AllocationSite::kPretenureMinimumCreated); |
| 2374 |
| 2375 v8::Local<v8::Value> res = CompileRun(source.start()); |
2392 | 2376 |
2393 Handle<JSObject> o = | 2377 Handle<JSObject> o = |
2394 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); | 2378 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); |
2395 | 2379 |
2396 CHECK(CcTest::heap()->InOldDataSpace(o->elements())); | 2380 CHECK(CcTest::heap()->InOldDataSpace(o->elements())); |
2397 CHECK(CcTest::heap()->InOldPointerSpace(*o)); | 2381 CHECK(CcTest::heap()->InOldPointerSpace(*o)); |
2398 } | 2382 } |
2399 | 2383 |
2400 | 2384 |
2401 TEST(OptimizedPretenuringNestedMixedArrayLiterals) { | 2385 TEST(OptimizedPretenuringNestedMixedArrayLiterals) { |
2402 i::FLAG_allow_natives_syntax = true; | 2386 i::FLAG_allow_natives_syntax = true; |
2403 i::FLAG_max_semi_space_size = 1; | 2387 i::FLAG_expose_gc = true; |
2404 CcTest::InitializeVM(); | 2388 CcTest::InitializeVM(); |
2405 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; | 2389 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; |
2406 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; | 2390 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; |
2407 v8::HandleScope scope(CcTest::isolate()); | 2391 v8::HandleScope scope(CcTest::isolate()); |
2408 | 2392 |
2409 v8::Local<v8::Value> res = CompileRun( | 2393 i::ScopedVector<char> source(1024); |
2410 "var number_elements = 20000;" | 2394 i::OS::SNPrintF( |
| 2395 source, |
| 2396 "var number_elements = 100;" |
2411 "var elements = new Array(number_elements);" | 2397 "var elements = new Array(number_elements);" |
2412 "function f() {" | 2398 "function f() {" |
2413 " for (var i = 0; i < number_elements; i++) {" | 2399 " for (var i = 0; i < number_elements; i++) {" |
2414 " elements[i] = [[{}, {}, {}], [1.1, 2.2, 3.3]];" | 2400 " elements[i] = [[{}, {}, {}], [1.1, 2.2, 3.3]];" |
2415 " }" | 2401 " }" |
2416 " return elements[number_elements - 1];" | 2402 " return elements[number_elements - 1];" |
2417 "};" | 2403 "};" |
2418 "f(); f(); f();" | 2404 "f(); gc();" |
| 2405 "f(); f();" |
2419 "%OptimizeFunctionOnNextCall(f);" | 2406 "%OptimizeFunctionOnNextCall(f);" |
2420 "f();"); | 2407 "f();", |
| 2408 AllocationSite::kPretenureMinimumCreated); |
| 2409 |
| 2410 v8::Local<v8::Value> res = CompileRun(source.start()); |
2421 | 2411 |
2422 v8::Local<v8::Value> int_array = v8::Object::Cast(*res)->Get(v8_str("0")); | 2412 v8::Local<v8::Value> int_array = v8::Object::Cast(*res)->Get(v8_str("0")); |
2423 Handle<JSObject> int_array_handle = | 2413 Handle<JSObject> int_array_handle = |
2424 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(int_array)); | 2414 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(int_array)); |
2425 v8::Local<v8::Value> double_array = v8::Object::Cast(*res)->Get(v8_str("1")); | 2415 v8::Local<v8::Value> double_array = v8::Object::Cast(*res)->Get(v8_str("1")); |
2426 Handle<JSObject> double_array_handle = | 2416 Handle<JSObject> double_array_handle = |
2427 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(double_array)); | 2417 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(double_array)); |
2428 | 2418 |
2429 Handle<JSObject> o = | 2419 Handle<JSObject> o = |
2430 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); | 2420 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); |
2431 CHECK(CcTest::heap()->InOldPointerSpace(*o)); | 2421 CHECK(CcTest::heap()->InOldPointerSpace(*o)); |
2432 CHECK(CcTest::heap()->InOldPointerSpace(*int_array_handle)); | 2422 CHECK(CcTest::heap()->InOldPointerSpace(*int_array_handle)); |
2433 CHECK(CcTest::heap()->InOldPointerSpace(int_array_handle->elements())); | 2423 CHECK(CcTest::heap()->InOldPointerSpace(int_array_handle->elements())); |
2434 CHECK(CcTest::heap()->InOldPointerSpace(*double_array_handle)); | 2424 CHECK(CcTest::heap()->InOldPointerSpace(*double_array_handle)); |
2435 CHECK(CcTest::heap()->InOldDataSpace(double_array_handle->elements())); | 2425 CHECK(CcTest::heap()->InOldDataSpace(double_array_handle->elements())); |
2436 } | 2426 } |
2437 | 2427 |
2438 | 2428 |
2439 TEST(OptimizedPretenuringNestedObjectLiterals) { | 2429 TEST(OptimizedPretenuringNestedObjectLiterals) { |
2440 i::FLAG_allow_natives_syntax = true; | 2430 i::FLAG_allow_natives_syntax = true; |
2441 i::FLAG_max_semi_space_size = 1; | 2431 i::FLAG_expose_gc = true; |
2442 CcTest::InitializeVM(); | 2432 CcTest::InitializeVM(); |
2443 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; | 2433 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; |
2444 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; | 2434 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; |
2445 v8::HandleScope scope(CcTest::isolate()); | 2435 v8::HandleScope scope(CcTest::isolate()); |
2446 | 2436 |
2447 v8::Local<v8::Value> res = CompileRun( | 2437 i::ScopedVector<char> source(1024); |
2448 "var number_elements = 20000;" | 2438 i::OS::SNPrintF( |
| 2439 source, |
| 2440 "var number_elements = %d;" |
2449 "var elements = new Array(number_elements);" | 2441 "var elements = new Array(number_elements);" |
2450 "function f() {" | 2442 "function f() {" |
2451 " for (var i = 0; i < number_elements; i++) {" | 2443 " for (var i = 0; i < number_elements; i++) {" |
2452 " elements[i] = [[{}, {}, {}],[{}, {}, {}]];" | 2444 " elements[i] = [[{}, {}, {}],[{}, {}, {}]];" |
2453 " }" | 2445 " }" |
2454 " return elements[number_elements - 1];" | 2446 " return elements[number_elements - 1];" |
2455 "};" | 2447 "};" |
2456 "f(); f(); f();" | 2448 "f(); gc();" |
| 2449 "f(); f();" |
2457 "%OptimizeFunctionOnNextCall(f);" | 2450 "%OptimizeFunctionOnNextCall(f);" |
2458 "f();"); | 2451 "f();", |
| 2452 AllocationSite::kPretenureMinimumCreated); |
| 2453 |
| 2454 v8::Local<v8::Value> res = CompileRun(source.start()); |
2459 | 2455 |
2460 v8::Local<v8::Value> int_array_1 = v8::Object::Cast(*res)->Get(v8_str("0")); | 2456 v8::Local<v8::Value> int_array_1 = v8::Object::Cast(*res)->Get(v8_str("0")); |
2461 Handle<JSObject> int_array_handle_1 = | 2457 Handle<JSObject> int_array_handle_1 = |
2462 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(int_array_1)); | 2458 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(int_array_1)); |
2463 v8::Local<v8::Value> int_array_2 = v8::Object::Cast(*res)->Get(v8_str("1")); | 2459 v8::Local<v8::Value> int_array_2 = v8::Object::Cast(*res)->Get(v8_str("1")); |
2464 Handle<JSObject> int_array_handle_2 = | 2460 Handle<JSObject> int_array_handle_2 = |
2465 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(int_array_2)); | 2461 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(int_array_2)); |
2466 | 2462 |
2467 Handle<JSObject> o = | 2463 Handle<JSObject> o = |
2468 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); | 2464 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); |
2469 CHECK(CcTest::heap()->InOldPointerSpace(*o)); | 2465 CHECK(CcTest::heap()->InOldPointerSpace(*o)); |
2470 CHECK(CcTest::heap()->InOldPointerSpace(*int_array_handle_1)); | 2466 CHECK(CcTest::heap()->InOldPointerSpace(*int_array_handle_1)); |
2471 CHECK(CcTest::heap()->InOldPointerSpace(int_array_handle_1->elements())); | 2467 CHECK(CcTest::heap()->InOldPointerSpace(int_array_handle_1->elements())); |
2472 CHECK(CcTest::heap()->InOldPointerSpace(*int_array_handle_2)); | 2468 CHECK(CcTest::heap()->InOldPointerSpace(*int_array_handle_2)); |
2473 CHECK(CcTest::heap()->InOldPointerSpace(int_array_handle_2->elements())); | 2469 CHECK(CcTest::heap()->InOldPointerSpace(int_array_handle_2->elements())); |
2474 } | 2470 } |
2475 | 2471 |
2476 | 2472 |
2477 TEST(OptimizedPretenuringNestedDoubleLiterals) { | 2473 TEST(OptimizedPretenuringNestedDoubleLiterals) { |
2478 i::FLAG_allow_natives_syntax = true; | 2474 i::FLAG_allow_natives_syntax = true; |
2479 i::FLAG_max_semi_space_size = 1; | 2475 i::FLAG_expose_gc = true; |
2480 CcTest::InitializeVM(); | 2476 CcTest::InitializeVM(); |
2481 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; | 2477 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; |
2482 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; | 2478 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; |
2483 v8::HandleScope scope(CcTest::isolate()); | 2479 v8::HandleScope scope(CcTest::isolate()); |
2484 | 2480 |
2485 v8::Local<v8::Value> res = CompileRun( | 2481 i::ScopedVector<char> source(1024); |
2486 "var number_elements = 20000;" | 2482 i::OS::SNPrintF( |
| 2483 source, |
| 2484 "var number_elements = %d;" |
2487 "var elements = new Array(number_elements);" | 2485 "var elements = new Array(number_elements);" |
2488 "function f() {" | 2486 "function f() {" |
2489 " for (var i = 0; i < number_elements; i++) {" | 2487 " for (var i = 0; i < number_elements; i++) {" |
2490 " elements[i] = [[1.1, 1.2, 1.3],[2.1, 2.2, 2.3]];" | 2488 " elements[i] = [[1.1, 1.2, 1.3],[2.1, 2.2, 2.3]];" |
2491 " }" | 2489 " }" |
2492 " return elements[number_elements - 1];" | 2490 " return elements[number_elements - 1];" |
2493 "};" | 2491 "};" |
2494 "f(); f(); f();" | 2492 "f(); gc();" |
| 2493 "f(); f();" |
2495 "%OptimizeFunctionOnNextCall(f);" | 2494 "%OptimizeFunctionOnNextCall(f);" |
2496 "f();"); | 2495 "f();", |
| 2496 AllocationSite::kPretenureMinimumCreated); |
| 2497 |
| 2498 v8::Local<v8::Value> res = CompileRun(source.start()); |
2497 | 2499 |
2498 v8::Local<v8::Value> double_array_1 = | 2500 v8::Local<v8::Value> double_array_1 = |
2499 v8::Object::Cast(*res)->Get(v8_str("0")); | 2501 v8::Object::Cast(*res)->Get(v8_str("0")); |
2500 Handle<JSObject> double_array_handle_1 = | 2502 Handle<JSObject> double_array_handle_1 = |
2501 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(double_array_1)); | 2503 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(double_array_1)); |
2502 v8::Local<v8::Value> double_array_2 = | 2504 v8::Local<v8::Value> double_array_2 = |
2503 v8::Object::Cast(*res)->Get(v8_str("1")); | 2505 v8::Object::Cast(*res)->Get(v8_str("1")); |
2504 Handle<JSObject> double_array_handle_2 = | 2506 Handle<JSObject> double_array_handle_2 = |
2505 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(double_array_2)); | 2507 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(double_array_2)); |
2506 | 2508 |
2507 Handle<JSObject> o = | 2509 Handle<JSObject> o = |
2508 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); | 2510 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); |
2509 CHECK(CcTest::heap()->InOldPointerSpace(*o)); | 2511 CHECK(CcTest::heap()->InOldPointerSpace(*o)); |
2510 CHECK(CcTest::heap()->InOldPointerSpace(*double_array_handle_1)); | 2512 CHECK(CcTest::heap()->InOldPointerSpace(*double_array_handle_1)); |
2511 CHECK(CcTest::heap()->InOldDataSpace(double_array_handle_1->elements())); | 2513 CHECK(CcTest::heap()->InOldDataSpace(double_array_handle_1->elements())); |
2512 CHECK(CcTest::heap()->InOldPointerSpace(*double_array_handle_2)); | 2514 CHECK(CcTest::heap()->InOldPointerSpace(*double_array_handle_2)); |
2513 CHECK(CcTest::heap()->InOldDataSpace(double_array_handle_2->elements())); | 2515 CHECK(CcTest::heap()->InOldDataSpace(double_array_handle_2->elements())); |
2514 } | 2516 } |
2515 | 2517 |
2516 | 2518 |
2517 // Make sure pretenuring feedback is gathered for constructed objects as well | 2519 // Make sure pretenuring feedback is gathered for constructed objects as well |
2518 // as for literals. | 2520 // as for literals. |
2519 TEST(OptimizedPretenuringConstructorCalls) { | 2521 TEST(OptimizedPretenuringConstructorCalls) { |
2520 if (!FLAG_allocation_site_pretenuring || !i::FLAG_pretenuring_call_new) { | 2522 if (!i::FLAG_pretenuring_call_new) { |
2521 // FLAG_pretenuring_call_new needs to be synced with the snapshot. | 2523 // FLAG_pretenuring_call_new needs to be synced with the snapshot. |
2522 return; | 2524 return; |
2523 } | 2525 } |
2524 i::FLAG_allow_natives_syntax = true; | 2526 i::FLAG_allow_natives_syntax = true; |
2525 i::FLAG_max_semi_space_size = 1; | 2527 i::FLAG_expose_gc = true; |
2526 CcTest::InitializeVM(); | 2528 CcTest::InitializeVM(); |
2527 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; | 2529 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; |
2528 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; | 2530 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; |
2529 v8::HandleScope scope(CcTest::isolate()); | 2531 v8::HandleScope scope(CcTest::isolate()); |
2530 | 2532 |
2531 v8::Local<v8::Value> res = CompileRun( | 2533 i::ScopedVector<char> source(1024); |
2532 "var number_elements = 20000;" | 2534 i::OS::SNPrintF( |
| 2535 source, |
| 2536 "var number_elements = %d;" |
2533 "var elements = new Array(number_elements);" | 2537 "var elements = new Array(number_elements);" |
2534 "function foo() {" | 2538 "function foo() {" |
2535 " this.a = 3;" | 2539 " this.a = 3;" |
2536 " this.b = {};" | 2540 " this.b = {};" |
2537 "}" | 2541 "}" |
2538 "function f() {" | 2542 "function f() {" |
2539 " for (var i = 0; i < number_elements; i++) {" | 2543 " for (var i = 0; i < number_elements; i++) {" |
2540 " elements[i] = new foo();" | 2544 " elements[i] = new foo();" |
2541 " }" | 2545 " }" |
2542 " return elements[number_elements - 1];" | 2546 " return elements[number_elements - 1];" |
2543 "};" | 2547 "};" |
2544 "f(); f(); f();" | 2548 "f(); gc();" |
| 2549 "f(); f();" |
2545 "%OptimizeFunctionOnNextCall(f);" | 2550 "%OptimizeFunctionOnNextCall(f);" |
2546 "f();"); | 2551 "f();", |
| 2552 AllocationSite::kPretenureMinimumCreated); |
| 2553 |
| 2554 v8::Local<v8::Value> res = CompileRun(source.start()); |
2547 | 2555 |
2548 Handle<JSObject> o = | 2556 Handle<JSObject> o = |
2549 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); | 2557 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); |
2550 | 2558 |
2551 CHECK(CcTest::heap()->InOldPointerSpace(*o)); | 2559 CHECK(CcTest::heap()->InOldPointerSpace(*o)); |
2552 } | 2560 } |
2553 | 2561 |
2554 | 2562 |
| 2563 TEST(OptimizedPretenuringCallNew) { |
| 2564 if (!i::FLAG_pretenuring_call_new) { |
| 2565 // FLAG_pretenuring_call_new needs to be synced with the snapshot. |
| 2566 return; |
| 2567 } |
| 2568 i::FLAG_allow_natives_syntax = true; |
| 2569 i::FLAG_expose_gc = true; |
| 2570 CcTest::InitializeVM(); |
| 2571 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; |
| 2572 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; |
| 2573 v8::HandleScope scope(CcTest::isolate()); |
| 2574 |
| 2575 i::ScopedVector<char> source(1024); |
| 2576 i::OS::SNPrintF( |
| 2577 source, |
| 2578 "var number_elements = 100;" |
| 2579 "var elements = new Array(number_elements);" |
| 2580 "function g() { this.a = 0; }" |
| 2581 "function f() {" |
| 2582 " for (var i = 0; i < number_elements; i++) {" |
| 2583 " elements[i] = new g();" |
| 2584 " }" |
| 2585 " return elements[number_elements - 1];" |
| 2586 "};" |
| 2587 "f(); gc();" |
| 2588 "f(); f();" |
| 2589 "%OptimizeFunctionOnNextCall(f);" |
| 2590 "f();", |
| 2591 AllocationSite::kPretenureMinimumCreated); |
| 2592 |
| 2593 v8::Local<v8::Value> res = CompileRun(source.start()); |
| 2594 |
| 2595 Handle<JSObject> o = |
| 2596 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); |
| 2597 CHECK(CcTest::heap()->InOldPointerSpace(*o)); |
| 2598 } |
| 2599 |
| 2600 |
2555 // Test regular array literals allocation. | 2601 // Test regular array literals allocation. |
2556 TEST(OptimizedAllocationArrayLiterals) { | 2602 TEST(OptimizedAllocationArrayLiterals) { |
2557 i::FLAG_allow_natives_syntax = true; | 2603 i::FLAG_allow_natives_syntax = true; |
2558 CcTest::InitializeVM(); | 2604 CcTest::InitializeVM(); |
2559 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; | 2605 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; |
2560 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; | 2606 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; |
2561 v8::HandleScope scope(CcTest::isolate()); | 2607 v8::HandleScope scope(CcTest::isolate()); |
2562 | 2608 |
2563 v8::Local<v8::Value> res = CompileRun( | 2609 v8::Local<v8::Value> res = CompileRun( |
2564 "function f() {" | 2610 "function f() {" |
2565 " var numbers = new Array(1, 2, 3);" | 2611 " var numbers = new Array(1, 2, 3);" |
2566 " numbers[0] = 3.14;" | 2612 " numbers[0] = 3.14;" |
2567 " return numbers;" | 2613 " return numbers;" |
2568 "};" | 2614 "};" |
2569 "f(); f(); f();" | 2615 "f(); f(); f();" |
2570 "%OptimizeFunctionOnNextCall(f);" | 2616 "%OptimizeFunctionOnNextCall(f);" |
2571 "f();"); | 2617 "f();"); |
2572 CHECK_EQ(static_cast<int>(3.14), | 2618 CHECK_EQ(static_cast<int>(3.14), |
2573 v8::Object::Cast(*res)->Get(v8_str("0"))->Int32Value()); | 2619 v8::Object::Cast(*res)->Get(v8_str("0"))->Int32Value()); |
2574 | 2620 |
2575 Handle<JSObject> o = | 2621 Handle<JSObject> o = |
2576 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); | 2622 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); |
2577 | 2623 |
2578 CHECK(CcTest::heap()->InNewSpace(o->elements())); | 2624 CHECK(CcTest::heap()->InNewSpace(o->elements())); |
2579 } | 2625 } |
2580 | 2626 |
2581 | 2627 |
2582 // Test global pretenuring call new. | |
2583 TEST(OptimizedPretenuringCallNew) { | |
2584 i::FLAG_allow_natives_syntax = true; | |
2585 i::FLAG_allocation_site_pretenuring = false; | |
2586 i::FLAG_pretenuring_call_new = true; | |
2587 CcTest::InitializeVM(); | |
2588 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; | |
2589 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; | |
2590 v8::HandleScope scope(CcTest::isolate()); | |
2591 | |
2592 AlwaysAllocateScope always_allocate(CcTest::i_isolate()); | |
2593 v8::Local<v8::Value> res = CompileRun( | |
2594 "function g() { this.a = 0; }" | |
2595 "function f() {" | |
2596 " return new g();" | |
2597 "};" | |
2598 "f(); f(); f();" | |
2599 "%OptimizeFunctionOnNextCall(f);" | |
2600 "f();"); | |
2601 | |
2602 Handle<JSObject> o = | |
2603 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); | |
2604 CHECK(CcTest::heap()->InOldPointerSpace(*o)); | |
2605 } | |
2606 | |
2607 | |
2608 static int CountMapTransitions(Map* map) { | 2628 static int CountMapTransitions(Map* map) { |
2609 return map->transitions()->number_of_transitions(); | 2629 return map->transitions()->number_of_transitions(); |
2610 } | 2630 } |
2611 | 2631 |
2612 | 2632 |
2613 // Test that map transitions are cleared and maps are collected with | 2633 // Test that map transitions are cleared and maps are collected with |
2614 // incremental marking as well. | 2634 // incremental marking as well. |
2615 TEST(Regress1465) { | 2635 TEST(Regress1465) { |
2616 i::FLAG_stress_compaction = false; | 2636 i::FLAG_stress_compaction = false; |
2617 i::FLAG_allow_natives_syntax = true; | 2637 i::FLAG_allow_natives_syntax = true; |
(...skipping 1617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4235 "array;"); | 4255 "array;"); |
4236 | 4256 |
4237 Handle<JSObject> o = | 4257 Handle<JSObject> o = |
4238 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(result)); | 4258 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(result)); |
4239 CHECK(heap->InOldPointerSpace(o->elements())); | 4259 CHECK(heap->InOldPointerSpace(o->elements())); |
4240 CHECK(heap->InOldPointerSpace(*o)); | 4260 CHECK(heap->InOldPointerSpace(*o)); |
4241 Page* page = Page::FromAddress(o->elements()->address()); | 4261 Page* page = Page::FromAddress(o->elements()->address()); |
4242 CHECK(page->WasSwept() || | 4262 CHECK(page->WasSwept() || |
4243 Marking::IsBlack(Marking::MarkBitFrom(o->elements()))); | 4263 Marking::IsBlack(Marking::MarkBitFrom(o->elements()))); |
4244 } | 4264 } |
OLD | NEW |