Chromium Code Reviews| 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 2348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2359 is_internalized_string_(is_internalize_string), | 2359 is_internalized_string_(is_internalize_string), |
| 2360 is_not_in_new_space_(is_not_in_new_space), | 2360 is_not_in_new_space_(is_not_in_new_space), |
| 2361 is_cell_(is_cell), | 2361 is_cell_(is_cell), |
| 2362 boolean_value_(boolean_value) { | 2362 boolean_value_(boolean_value) { |
| 2363 ASSERT(!handle.is_null()); | 2363 ASSERT(!handle.is_null()); |
| 2364 ASSERT(!type.IsTaggedNumber()); | 2364 ASSERT(!type.IsTaggedNumber()); |
| 2365 Initialize(r); | 2365 Initialize(r); |
| 2366 } | 2366 } |
| 2367 | 2367 |
| 2368 | 2368 |
| 2369 HConstant::HConstant(Handle<Map> handle, | |
| 2370 UniqueValueId unique_id) | |
| 2371 : HTemplateInstruction<0>(HType::Tagged()), | |
| 2372 handle_(handle), | |
| 2373 unique_id_(unique_id), | |
| 2374 has_smi_value_(false), | |
| 2375 has_int32_value_(false), | |
| 2376 has_double_value_(false), | |
| 2377 has_external_reference_value_(false), | |
| 2378 is_internalized_string_(false), | |
| 2379 is_not_in_new_space_(true), | |
| 2380 is_cell_(false), | |
| 2381 boolean_value_(false) { | |
| 2382 ASSERT(!handle.is_null()); | |
| 2383 Initialize(Representation::Tagged()); | |
| 2384 } | |
| 2385 | |
| 2386 | |
| 2369 HConstant::HConstant(int32_t integer_value, | 2387 HConstant::HConstant(int32_t integer_value, |
| 2370 Representation r, | 2388 Representation r, |
| 2371 bool is_not_in_new_space, | 2389 bool is_not_in_new_space, |
| 2372 Handle<Object> optional_handle) | 2390 Handle<Object> optional_handle) |
| 2373 : handle_(optional_handle), | 2391 : handle_(optional_handle), |
| 2374 unique_id_(), | 2392 unique_id_(), |
| 2375 has_smi_value_(Smi::IsValid(integer_value)), | 2393 has_smi_value_(Smi::IsValid(integer_value)), |
| 2376 has_int32_value_(true), | 2394 has_int32_value_(true), |
| 2377 has_double_value_(true), | 2395 has_double_value_(true), |
| 2378 has_external_reference_value_(false), | 2396 has_external_reference_value_(false), |
| (...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3177 } else if (flexible_int()) { | 3195 } else if (flexible_int()) { |
| 3178 rep = Representation::Integer32(); | 3196 rep = Representation::Integer32(); |
| 3179 } | 3197 } |
| 3180 return rep; | 3198 return rep; |
| 3181 } | 3199 } |
| 3182 | 3200 |
| 3183 | 3201 |
| 3184 void HAllocate::HandleSideEffectDominator(GVNFlag side_effect, | 3202 void HAllocate::HandleSideEffectDominator(GVNFlag side_effect, |
| 3185 HValue* dominator) { | 3203 HValue* dominator) { |
| 3186 ASSERT(side_effect == kChangesNewSpacePromotion); | 3204 ASSERT(side_effect == kChangesNewSpacePromotion); |
| 3205 Zone* zone = block()->zone(); | |
| 3187 if (!FLAG_use_allocation_folding) return; | 3206 if (!FLAG_use_allocation_folding) return; |
| 3188 | 3207 |
| 3189 // Try to fold allocations together with their dominating allocations. | 3208 // Try to fold allocations together with their dominating allocations. |
| 3190 if (!dominator->IsAllocate()) { | 3209 if (!dominator->IsAllocate()) { |
| 3191 if (FLAG_trace_allocation_folding) { | 3210 if (FLAG_trace_allocation_folding) { |
| 3192 PrintF("#%d (%s) cannot fold into #%d (%s)\n", | 3211 PrintF("#%d (%s) cannot fold into #%d (%s)\n", |
| 3193 id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); | 3212 id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); |
| 3194 } | 3213 } |
| 3195 return; | 3214 return; |
| 3196 } | 3215 } |
| 3197 | 3216 |
| 3198 HAllocate* dominator_allocate_instr = HAllocate::cast(dominator); | 3217 HAllocate* dominator_allocate = HAllocate::cast(dominator); |
| 3199 HValue* dominator_size = dominator_allocate_instr->size(); | 3218 HValue* dominator_size = dominator_allocate->size(); |
| 3200 HValue* current_size = size(); | 3219 HValue* current_size = size(); |
| 3201 // We can just fold allocations that are guaranteed in new space. | 3220 |
| 3202 // TODO(hpayer): Add support for non-constant allocation in dominator. | 3221 // TODO(hpayer): Add support for non-constant allocation in dominator. |
| 3203 if (!IsNewSpaceAllocation() || !current_size->IsInteger32Constant() || | 3222 if (!current_size->IsInteger32Constant() || |
| 3204 !dominator_allocate_instr->IsNewSpaceAllocation() || | |
| 3205 !dominator_size->IsInteger32Constant()) { | 3223 !dominator_size->IsInteger32Constant()) { |
| 3206 if (FLAG_trace_allocation_folding) { | 3224 if (FLAG_trace_allocation_folding) { |
| 3207 PrintF("#%d (%s) cannot fold into #%d (%s)\n", | 3225 PrintF("#%d (%s) cannot fold into #%d (%s), dynamic allocation size\n", |
| 3208 id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); | 3226 id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); |
| 3209 } | 3227 } |
| 3210 return; | 3228 return; |
| 3211 } | 3229 } |
| 3212 | 3230 |
| 3231 dominator_allocate = GetFoldableDominator(dominator_allocate); | |
| 3232 if (dominator_allocate == NULL) { | |
| 3233 return; | |
| 3234 } | |
| 3235 | |
| 3236 ASSERT((IsNewSpaceAllocation() && | |
| 3237 dominator_allocate->IsNewSpaceAllocation()) || | |
| 3238 (IsOldDataSpaceAllocation() && | |
| 3239 dominator_allocate->IsOldDataSpaceAllocation()) || | |
| 3240 (IsOldPointerSpaceAllocation() && | |
| 3241 dominator_allocate->IsOldPointerSpaceAllocation())); | |
| 3242 | |
| 3213 // First update the size of the dominator allocate instruction. | 3243 // First update the size of the dominator allocate instruction. |
| 3244 dominator_size = dominator_allocate->size(); | |
| 3214 int32_t dominator_size_constant = | 3245 int32_t dominator_size_constant = |
| 3215 HConstant::cast(dominator_size)->GetInteger32Constant(); | 3246 HConstant::cast(dominator_size)->GetInteger32Constant(); |
| 3216 int32_t current_size_constant = | 3247 int32_t current_size_constant = |
| 3217 HConstant::cast(current_size)->GetInteger32Constant(); | 3248 HConstant::cast(current_size)->GetInteger32Constant(); |
| 3218 int32_t new_dominator_size = dominator_size_constant + current_size_constant; | 3249 int32_t new_dominator_size = dominator_size_constant + current_size_constant; |
| 3219 | 3250 |
| 3220 if (MustAllocateDoubleAligned()) { | 3251 if (MustAllocateDoubleAligned()) { |
| 3221 if (!dominator_allocate_instr->MustAllocateDoubleAligned()) { | 3252 if (!dominator_allocate->MustAllocateDoubleAligned()) { |
| 3222 dominator_allocate_instr->MakeDoubleAligned(); | 3253 dominator_allocate->MakeDoubleAligned(); |
| 3223 } | 3254 } |
| 3224 if ((dominator_size_constant & kDoubleAlignmentMask) != 0) { | 3255 if ((dominator_size_constant & kDoubleAlignmentMask) != 0) { |
| 3225 dominator_size_constant += kDoubleSize / 2; | 3256 dominator_size_constant += kDoubleSize / 2; |
| 3226 new_dominator_size += kDoubleSize / 2; | 3257 new_dominator_size += kDoubleSize / 2; |
| 3227 } | 3258 } |
| 3228 } | 3259 } |
| 3229 | 3260 |
| 3230 if (new_dominator_size > Page::kMaxNonCodeHeapObjectSize) { | 3261 if (new_dominator_size > Page::kMaxNonCodeHeapObjectSize) { |
| 3231 if (FLAG_trace_allocation_folding) { | 3262 if (FLAG_trace_allocation_folding) { |
| 3232 PrintF("#%d (%s) cannot fold into #%d (%s) due to size: %d\n", | 3263 PrintF("#%d (%s) cannot fold into #%d (%s) due to size: %d\n", |
| 3233 id(), Mnemonic(), dominator->id(), dominator->Mnemonic(), | 3264 id(), Mnemonic(), dominator_allocate->id(), |
| 3234 new_dominator_size); | 3265 dominator_allocate->Mnemonic(), new_dominator_size); |
| 3235 } | 3266 } |
| 3236 return; | 3267 return; |
| 3237 } | 3268 } |
| 3238 HBasicBlock* block = dominator->block(); | 3269 |
| 3239 Zone* zone = block->zone(); | 3270 HInstruction* new_dominator_size_constant = HConstant::CreateAndInsertBefore( |
| 3240 HInstruction* new_dominator_size_constant = | 3271 zone, context(), new_dominator_size, dominator_allocate); |
| 3241 HConstant::New(zone, context(), new_dominator_size); | 3272 dominator_allocate->UpdateSize(new_dominator_size_constant); |
| 3242 new_dominator_size_constant->InsertBefore(dominator_allocate_instr); | |
| 3243 dominator_allocate_instr->UpdateSize(new_dominator_size_constant); | |
| 3244 | 3273 |
| 3245 #ifdef VERIFY_HEAP | 3274 #ifdef VERIFY_HEAP |
| 3246 if (FLAG_verify_heap) { | 3275 if (FLAG_verify_heap && dominator_allocate->IsNewSpaceAllocation()) { |
| 3247 dominator_allocate_instr->MakePrefillWithFiller(); | 3276 dominator_allocate->MakePrefillWithFiller(); |
| 3248 } | 3277 } |
| 3249 #endif | 3278 #endif |
| 3250 | 3279 |
| 3251 // After that replace the dominated allocate instruction. | 3280 // After that replace the dominated allocate instruction. |
| 3252 HInstruction* dominated_allocate_instr = | 3281 HInstruction* dominated_allocate_instr = |
| 3253 HInnerAllocatedObject::New(zone, | 3282 HInnerAllocatedObject::New(zone, |
| 3254 context(), | 3283 context(), |
| 3255 dominator_allocate_instr, | 3284 dominator_allocate, |
| 3256 dominator_size_constant, | 3285 dominator_size_constant, |
| 3257 type()); | 3286 type()); |
| 3258 dominated_allocate_instr->InsertBefore(this); | 3287 dominated_allocate_instr->InsertBefore(this); |
| 3259 DeleteAndReplaceWith(dominated_allocate_instr); | 3288 DeleteAndReplaceWith(dominated_allocate_instr); |
| 3260 if (FLAG_trace_allocation_folding) { | 3289 if (FLAG_trace_allocation_folding) { |
| 3261 PrintF("#%d (%s) folded into #%d (%s)\n", | 3290 PrintF("#%d (%s) folded into #%d (%s)\n", |
| 3262 id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); | 3291 id(), Mnemonic(), dominator_allocate->id(), |
| 3292 dominator_allocate->Mnemonic()); | |
| 3263 } | 3293 } |
| 3264 } | 3294 } |
| 3265 | 3295 |
| 3266 | 3296 |
| 3297 HAllocate* HAllocate::GetFoldableDominator(HAllocate* dominator) { | |
| 3298 if (!IsFoldable(dominator)) { | |
| 3299 // We cannot hoist old space allocations over new space allocations. | |
| 3300 if (IsNewSpaceAllocation() || dominator->IsNewSpaceAllocation()) { | |
| 3301 if (FLAG_trace_allocation_folding) { | |
| 3302 PrintF("#%d (%s) cannot fold into #%d (%s), new space hoisting\n", | |
| 3303 id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); | |
| 3304 } | |
| 3305 return NULL; | |
| 3306 } | |
| 3307 | |
| 3308 HAllocate* dominator_dominator = dominator->dominating_allocate_; | |
| 3309 | |
| 3310 // We can hoist old data space allocations over an old pointer space | |
| 3311 // allocation and vice versa. For that we have to check the dominator | |
| 3312 // of the dominator allocate instruction. | |
| 3313 if (dominator_dominator == NULL) { | |
| 3314 dominating_allocate_ = dominator; | |
| 3315 if (FLAG_trace_allocation_folding) { | |
| 3316 PrintF("#%d (%s) cannot fold into #%d (%s), different spaces\n", | |
| 3317 id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); | |
| 3318 } | |
| 3319 return NULL; | |
| 3320 } | |
| 3321 | |
| 3322 // We can just fold old space allocations that are in the same basic block, | |
| 3323 // since it is not guaranteed that we fill up the whole allocated old | |
| 3324 // space memory. | |
| 3325 // TODO(hpayer): Remove this limitation and add filler maps for each each | |
| 3326 // allocation as soon as we have store elimination. | |
| 3327 if (block()->block_id() != dominator_dominator->block()->block_id()) { | |
| 3328 if (FLAG_trace_allocation_folding) { | |
| 3329 PrintF("#%d (%s) cannot fold into #%d (%s), different basic blocks\n", | |
| 3330 id(), Mnemonic(), dominator_dominator->id(), | |
| 3331 dominator_dominator->Mnemonic()); | |
| 3332 } | |
| 3333 return NULL; | |
| 3334 } | |
| 3335 | |
| 3336 ASSERT((IsOldDataSpaceAllocation() && | |
| 3337 dominator_dominator->IsOldDataSpaceAllocation()) || | |
| 3338 (IsOldPointerSpaceAllocation() && | |
| 3339 dominator_dominator->IsOldPointerSpaceAllocation())); | |
| 3340 | |
| 3341 int32_t current_size = HConstant::cast(size())->GetInteger32Constant(); | |
| 3342 HConstant* dominator_free_space_size = dominator->filler_free_space_size_; | |
| 3343 if (dominator_free_space_size != NULL) { | |
| 3344 // We already hoisted one old space allocation, i.e., we already installed | |
| 3345 // a filler map. Hence, we just have to update the free space size. | |
| 3346 dominator->UpdateFreeSpaceFiller(current_size); | |
| 3347 } else { | |
| 3348 // This is the first old space allocation that gets hoisted. We have to | |
| 3349 // install a filler map since the follwing allocation may cause a GC. | |
| 3350 dominator->CreateFreeSpaceFiller(current_size); | |
| 3351 } | |
| 3352 | |
| 3353 // We can hoist the old space allocation over the actual dominator. | |
| 3354 return dominator_dominator; | |
| 3355 } | |
| 3356 return dominator; | |
| 3357 } | |
| 3358 | |
| 3359 | |
| 3360 void HAllocate::UpdateFreeSpaceFiller(int32_t free_space_size) { | |
| 3361 ASSERT(filler_free_space_size_ != NULL); | |
| 3362 Zone* zone = block()->zone(); | |
| 3363 HConstant* new_free_space_size = HConstant::CreateAndInsertBefore( | |
| 3364 zone, context(), filler_free_space_size_->GetInteger32Constant() + | |
| 3365 free_space_size, filler_free_space_size_); | |
| 3366 filler_free_space_size_->DeleteAndReplaceWith(new_free_space_size); | |
|
titzer
2013/08/26 09:50:24
Whoa. I don't think you want to DeleteAndReplaceWi
Hannes Payer (out of office)
2013/08/26 13:34:08
Yeah, let's play safe. Done.
| |
| 3367 } | |
| 3368 | |
| 3369 | |
| 3370 void HAllocate::CreateFreeSpaceFiller(int32_t free_space_size) { | |
| 3371 ASSERT(filler_free_space_size_ == NULL); | |
| 3372 Zone* zone = block()->zone(); | |
| 3373 int32_t dominator_size = | |
| 3374 HConstant::cast(dominating_allocate_->size())->GetInteger32Constant(); | |
| 3375 HInstruction* free_space_instr = | |
| 3376 HInnerAllocatedObject::New(zone, context(), dominating_allocate_, | |
| 3377 dominator_size, type()); | |
| 3378 free_space_instr->InsertBefore(this); | |
| 3379 HConstant* filler_map = HConstant::New( | |
| 3380 zone, | |
| 3381 context(), | |
| 3382 isolate()->factory()->free_space_map(), | |
| 3383 UniqueValueId(isolate()->heap()->free_space_map())); | |
| 3384 filler_map->InsertAfter(free_space_instr); | |
| 3385 HInstruction* store_map = HStoreNamedField::New(zone, context(), | |
| 3386 free_space_instr, HObjectAccess::ForMap(), filler_map); | |
| 3387 store_map->SetFlag(HValue::kHasNoObservableSideEffects); | |
| 3388 store_map->InsertAfter(filler_map); | |
| 3389 | |
| 3390 HConstant* filler_size = HConstant::CreateAndInsertAfter( | |
| 3391 zone, context(), free_space_size, store_map); | |
| 3392 filler_free_space_size_ = filler_size; | |
| 3393 HObjectAccess access = | |
| 3394 HObjectAccess::ForJSObjectOffset(FreeSpace::kSizeOffset); | |
| 3395 HInstruction* store_size = HStoreNamedField::New(zone, context(), | |
| 3396 free_space_instr, access, filler_size); | |
| 3397 store_size->SetFlag(HValue::kHasNoObservableSideEffects); | |
| 3398 store_size->InsertAfter(filler_size); | |
| 3399 } | |
| 3400 | |
| 3401 | |
| 3267 void HAllocate::PrintDataTo(StringStream* stream) { | 3402 void HAllocate::PrintDataTo(StringStream* stream) { |
| 3268 size()->PrintNameTo(stream); | 3403 size()->PrintNameTo(stream); |
| 3269 stream->Add(" ("); | 3404 stream->Add(" ("); |
| 3270 if (IsNewSpaceAllocation()) stream->Add("N"); | 3405 if (IsNewSpaceAllocation()) stream->Add("N"); |
| 3271 if (IsOldPointerSpaceAllocation()) stream->Add("P"); | 3406 if (IsOldPointerSpaceAllocation()) stream->Add("P"); |
| 3272 if (IsOldDataSpaceAllocation()) stream->Add("D"); | 3407 if (IsOldDataSpaceAllocation()) stream->Add("D"); |
| 3273 if (MustAllocateDoubleAligned()) stream->Add("A"); | 3408 if (MustAllocateDoubleAligned()) stream->Add("A"); |
| 3274 if (MustPrefillWithFiller()) stream->Add("F"); | 3409 if (MustPrefillWithFiller()) stream->Add("F"); |
| 3275 stream->Add(")"); | 3410 stream->Add(")"); |
| 3276 } | 3411 } |
| (...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3998 break; | 4133 break; |
| 3999 case kExternalMemory: | 4134 case kExternalMemory: |
| 4000 stream->Add("[external-memory]"); | 4135 stream->Add("[external-memory]"); |
| 4001 break; | 4136 break; |
| 4002 } | 4137 } |
| 4003 | 4138 |
| 4004 stream->Add("@%d", offset()); | 4139 stream->Add("@%d", offset()); |
| 4005 } | 4140 } |
| 4006 | 4141 |
| 4007 } } // namespace v8::internal | 4142 } } // namespace v8::internal |
| OLD | NEW |