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(OptimizedPretenuringObjectArrayLiterals) { |
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; | |
2122 v8::Local<v8::Value> res = CompileRun( | 2120 v8::Local<v8::Value> res = CompileRun( |
2123 "function f() {" | 2121 "function f() {" |
2124 " var numbers = [1, 2, 3];" | 2122 " var numbers = [{}, {}, {}];" |
2125 " numbers[0] = {};" | |
2126 " return numbers;" | 2123 " return numbers;" |
2127 "};" | 2124 "};" |
2128 "f(); f(); f();" | 2125 "f(); f(); f();" |
2129 "%OptimizeFunctionOnNextCall(f);" | 2126 "%OptimizeFunctionOnNextCall(f);" |
2130 "f();"); | 2127 "f();"); |
2131 | 2128 |
2132 Handle<JSObject> o = | 2129 Handle<JSObject> o = |
2133 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); | 2130 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); |
2134 | 2131 |
2135 CHECK(HEAP->InOldPointerSpace(o->elements())); | 2132 CHECK(HEAP->InOldPointerSpace(o->elements())); |
| 2133 CHECK(HEAP->InOldPointerSpace(*o)); |
2136 } | 2134 } |
2137 | 2135 |
2138 | 2136 |
2139 TEST(OptimizedPretenuringSimpleArrayLiterals) { | 2137 TEST(OptimizedPretenuringMixedInObjectProperties) { |
2140 i::FLAG_allow_natives_syntax = true; | 2138 i::FLAG_allow_natives_syntax = true; |
2141 i::FLAG_pretenuring = false; | |
2142 CcTest::InitializeVM(); | 2139 CcTest::InitializeVM(); |
2143 if (!i::V8::UseCrankshaft() || i::FLAG_always_opt) return; | 2140 if (!i::V8::UseCrankshaft() || i::FLAG_always_opt) return; |
2144 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; | 2141 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; |
2145 v8::HandleScope scope(CcTest::isolate()); | 2142 v8::HandleScope scope(CcTest::isolate()); |
| 2143 HEAP->SetNewSpaceHighPromotionModeActive(true); |
2146 | 2144 |
2147 AlwaysAllocateScope always_allocate; | |
2148 v8::Local<v8::Value> res = CompileRun( | 2145 v8::Local<v8::Value> res = CompileRun( |
2149 "function f() {" | 2146 "function f() {" |
2150 " return [1, 2, 3];" | 2147 " var numbers = {a: {c: 2.2, d: {}}, b: 1.1};" |
| 2148 " return numbers;" |
2151 "};" | 2149 "};" |
2152 "f(); f(); f();" | 2150 "f(); f(); f();" |
2153 "%OptimizeFunctionOnNextCall(f);" | 2151 "%OptimizeFunctionOnNextCall(f);" |
2154 "f();"); | 2152 "f();"); |
2155 | 2153 |
2156 Handle<JSObject> o = | 2154 Handle<JSObject> o = |
2157 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); | 2155 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); |
2158 | 2156 |
2159 CHECK(HEAP->InNewSpace(*o)); | 2157 CHECK(HEAP->InOldPointerSpace(*o)); |
| 2158 CHECK(HEAP->InOldPointerSpace(o->RawFastPropertyAt(0))); |
| 2159 CHECK(HEAP->InOldDataSpace(o->RawFastPropertyAt(1))); |
| 2160 |
| 2161 JSObject* inner_object = reinterpret_cast<JSObject*>(o->RawFastPropertyAt(0)); |
| 2162 CHECK(HEAP->InOldPointerSpace(inner_object)); |
| 2163 CHECK(HEAP->InOldDataSpace(inner_object->RawFastPropertyAt(0))); |
| 2164 CHECK(HEAP->InOldPointerSpace(inner_object->RawFastPropertyAt(1))); |
2160 } | 2165 } |
2161 | 2166 |
2162 | 2167 |
| 2168 TEST(OptimizedPretenuringDoubleArrayProperties) { |
| 2169 i::FLAG_allow_natives_syntax = true; |
| 2170 CcTest::InitializeVM(); |
| 2171 if (!i::V8::UseCrankshaft() || i::FLAG_always_opt) return; |
| 2172 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; |
| 2173 v8::HandleScope scope(CcTest::isolate()); |
| 2174 HEAP->SetNewSpaceHighPromotionModeActive(true); |
| 2175 |
| 2176 v8::Local<v8::Value> res = CompileRun( |
| 2177 "function f() {" |
| 2178 " var numbers = {a: 1.1, b: 2.2};" |
| 2179 " return numbers;" |
| 2180 "};" |
| 2181 "f(); f(); f();" |
| 2182 "%OptimizeFunctionOnNextCall(f);" |
| 2183 "f();"); |
| 2184 |
| 2185 Handle<JSObject> o = |
| 2186 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); |
| 2187 |
| 2188 CHECK(HEAP->InOldPointerSpace(*o)); |
| 2189 CHECK(HEAP->InOldDataSpace(o->properties())); |
| 2190 } |
| 2191 |
| 2192 |
| 2193 TEST(OptimizedPretenuringdoubleArrayLiterals) { |
| 2194 i::FLAG_allow_natives_syntax = true; |
| 2195 CcTest::InitializeVM(); |
| 2196 if (!i::V8::UseCrankshaft() || i::FLAG_always_opt) return; |
| 2197 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; |
| 2198 v8::HandleScope scope(CcTest::isolate()); |
| 2199 HEAP->SetNewSpaceHighPromotionModeActive(true); |
| 2200 |
| 2201 v8::Local<v8::Value> res = CompileRun( |
| 2202 "function f() {" |
| 2203 " var numbers = [1.1, 2.2, 3.3];" |
| 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->InOldDataSpace(o->elements())); |
| 2214 CHECK(HEAP->InOldPointerSpace(*o)); |
| 2215 } |
| 2216 |
| 2217 |
| 2218 TEST(OptimizedPretenuringNestedMixedArrayLiterals) { |
| 2219 i::FLAG_allow_natives_syntax = true; |
| 2220 CcTest::InitializeVM(); |
| 2221 if (!i::V8::UseCrankshaft() || i::FLAG_always_opt) return; |
| 2222 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; |
| 2223 v8::HandleScope scope(CcTest::isolate()); |
| 2224 HEAP->SetNewSpaceHighPromotionModeActive(true); |
| 2225 |
| 2226 v8::Local<v8::Value> res = CompileRun( |
| 2227 "function f() {" |
| 2228 " var numbers = [[{}, {}, {}],[1.1, 2.2, 3.3]];" |
| 2229 " return numbers;" |
| 2230 "};" |
| 2231 "f(); f(); f();" |
| 2232 "%OptimizeFunctionOnNextCall(f);" |
| 2233 "f();"); |
| 2234 |
| 2235 v8::Local<v8::Value> int_array = v8::Object::Cast(*res)->Get(v8_str("0")); |
| 2236 Handle<JSObject> int_array_handle = |
| 2237 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(int_array)); |
| 2238 v8::Local<v8::Value> double_array = v8::Object::Cast(*res)->Get(v8_str("1")); |
| 2239 Handle<JSObject> double_array_handle = |
| 2240 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(double_array)); |
| 2241 |
| 2242 Handle<JSObject> o = |
| 2243 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); |
| 2244 CHECK(HEAP->InOldPointerSpace(*o)); |
| 2245 CHECK(HEAP->InOldPointerSpace(*int_array_handle)); |
| 2246 CHECK(HEAP->InOldPointerSpace(int_array_handle->elements())); |
| 2247 CHECK(HEAP->InOldPointerSpace(*double_array_handle)); |
| 2248 CHECK(HEAP->InOldDataSpace(double_array_handle->elements())); |
| 2249 } |
| 2250 |
| 2251 |
| 2252 TEST(OptimizedPretenuringNestedObjectLiterals) { |
| 2253 i::FLAG_allow_natives_syntax = true; |
| 2254 CcTest::InitializeVM(); |
| 2255 if (!i::V8::UseCrankshaft() || i::FLAG_always_opt) return; |
| 2256 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; |
| 2257 v8::HandleScope scope(CcTest::isolate()); |
| 2258 HEAP->SetNewSpaceHighPromotionModeActive(true); |
| 2259 |
| 2260 v8::Local<v8::Value> res = CompileRun( |
| 2261 "function f() {" |
| 2262 " var numbers = [[{}, {}, {}],[{}, {}, {}]];" |
| 2263 " return numbers;" |
| 2264 "};" |
| 2265 "f(); f(); f();" |
| 2266 "%OptimizeFunctionOnNextCall(f);" |
| 2267 "f();"); |
| 2268 |
| 2269 v8::Local<v8::Value> int_array_1 = v8::Object::Cast(*res)->Get(v8_str("0")); |
| 2270 Handle<JSObject> int_array_handle_1 = |
| 2271 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(int_array_1)); |
| 2272 v8::Local<v8::Value> int_array_2 = v8::Object::Cast(*res)->Get(v8_str("1")); |
| 2273 Handle<JSObject> int_array_handle_2 = |
| 2274 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(int_array_2)); |
| 2275 |
| 2276 Handle<JSObject> o = |
| 2277 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); |
| 2278 CHECK(HEAP->InOldPointerSpace(*o)); |
| 2279 CHECK(HEAP->InOldPointerSpace(*int_array_handle_1)); |
| 2280 CHECK(HEAP->InOldPointerSpace(int_array_handle_1->elements())); |
| 2281 CHECK(HEAP->InOldPointerSpace(*int_array_handle_2)); |
| 2282 CHECK(HEAP->InOldPointerSpace(int_array_handle_2->elements())); |
| 2283 } |
| 2284 |
| 2285 |
| 2286 TEST(OptimizedPretenuringNestedDoubleLiterals) { |
| 2287 i::FLAG_allow_natives_syntax = true; |
| 2288 CcTest::InitializeVM(); |
| 2289 if (!i::V8::UseCrankshaft() || i::FLAG_always_opt) return; |
| 2290 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; |
| 2291 v8::HandleScope scope(CcTest::isolate()); |
| 2292 HEAP->SetNewSpaceHighPromotionModeActive(true); |
| 2293 |
| 2294 v8::Local<v8::Value> res = CompileRun( |
| 2295 "function f() {" |
| 2296 " var numbers = [[1.1, 1.2, 1.3],[2.1, 2.2, 2.3]];" |
| 2297 " return numbers;" |
| 2298 "};" |
| 2299 "f(); f(); f();" |
| 2300 "%OptimizeFunctionOnNextCall(f);" |
| 2301 "f();"); |
| 2302 |
| 2303 v8::Local<v8::Value> double_array_1 = |
| 2304 v8::Object::Cast(*res)->Get(v8_str("0")); |
| 2305 Handle<JSObject> double_array_handle_1 = |
| 2306 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(double_array_1)); |
| 2307 v8::Local<v8::Value> double_array_2 = |
| 2308 v8::Object::Cast(*res)->Get(v8_str("1")); |
| 2309 Handle<JSObject> double_array_handle_2 = |
| 2310 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(double_array_2)); |
| 2311 |
| 2312 Handle<JSObject> o = |
| 2313 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); |
| 2314 CHECK(HEAP->InOldPointerSpace(*o)); |
| 2315 CHECK(HEAP->InOldPointerSpace(*double_array_handle_1)); |
| 2316 CHECK(HEAP->InOldDataSpace(double_array_handle_1->elements())); |
| 2317 CHECK(HEAP->InOldPointerSpace(*double_array_handle_2)); |
| 2318 CHECK(HEAP->InOldDataSpace(double_array_handle_2->elements())); |
| 2319 } |
| 2320 |
| 2321 |
2163 // Test regular array literals allocation. | 2322 // Test regular array literals allocation. |
2164 TEST(OptimizedAllocationArrayLiterals) { | 2323 TEST(OptimizedAllocationArrayLiterals) { |
2165 i::FLAG_allow_natives_syntax = true; | 2324 i::FLAG_allow_natives_syntax = true; |
2166 CcTest::InitializeVM(); | 2325 CcTest::InitializeVM(); |
2167 if (!i::V8::UseCrankshaft() || i::FLAG_always_opt) return; | 2326 if (!i::V8::UseCrankshaft() || i::FLAG_always_opt) return; |
2168 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; | 2327 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; |
2169 v8::HandleScope scope(CcTest::isolate()); | 2328 v8::HandleScope scope(CcTest::isolate()); |
2170 | 2329 |
2171 AlwaysAllocateScope always_allocate; | |
2172 v8::Local<v8::Value> res = CompileRun( | 2330 v8::Local<v8::Value> res = CompileRun( |
2173 "function f() {" | 2331 "function f() {" |
2174 " var numbers = new Array(1, 2, 3);" | 2332 " var numbers = new Array(1, 2, 3);" |
2175 " numbers[0] = 3.14;" | 2333 " numbers[0] = 3.14;" |
2176 " return numbers;" | 2334 " return numbers;" |
2177 "};" | 2335 "};" |
2178 "f(); f(); f();" | 2336 "f(); f(); f();" |
2179 "%OptimizeFunctionOnNextCall(f);" | 2337 "%OptimizeFunctionOnNextCall(f);" |
2180 "f();"); | 2338 "f();"); |
2181 CHECK_EQ(static_cast<int>(3.14), | 2339 CHECK_EQ(static_cast<int>(3.14), |
(...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3155 " var a = new Array(n);" | 3313 " var a = new Array(n);" |
3156 " for (var i = 0; i < n; i += 100) a[i] = i;" | 3314 " for (var i = 0; i < n; i += 100) a[i] = i;" |
3157 "};" | 3315 "};" |
3158 "f(10 * 1024 * 1024);"); | 3316 "f(10 * 1024 * 1024);"); |
3159 IncrementalMarking* marking = HEAP->incremental_marking(); | 3317 IncrementalMarking* marking = HEAP->incremental_marking(); |
3160 if (marking->IsStopped()) marking->Start(); | 3318 if (marking->IsStopped()) marking->Start(); |
3161 // This big step should be sufficient to mark the whole array. | 3319 // This big step should be sufficient to mark the whole array. |
3162 marking->Step(100 * MB, IncrementalMarking::NO_GC_VIA_STACK_GUARD); | 3320 marking->Step(100 * MB, IncrementalMarking::NO_GC_VIA_STACK_GUARD); |
3163 ASSERT(marking->IsComplete()); | 3321 ASSERT(marking->IsComplete()); |
3164 } | 3322 } |
OLD | NEW |