OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/crankshaft/lithium.h" | 5 #include "src/crankshaft/lithium.h" |
6 | 6 |
7 #include "src/ast/scopes.h" | 7 #include "src/ast/scopes.h" |
8 | 8 |
9 #if V8_TARGET_ARCH_IA32 | 9 #if V8_TARGET_ARCH_IA32 |
10 #include "src/crankshaft/ia32/lithium-ia32.h" // NOLINT | 10 #include "src/crankshaft/ia32/lithium-ia32.h" // NOLINT |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 return HConstant::cast(graph_->LookupValue(operand->index())); | 399 return HConstant::cast(graph_->LookupValue(operand->index())); |
400 } | 400 } |
401 | 401 |
402 | 402 |
403 Representation LChunk::LookupLiteralRepresentation( | 403 Representation LChunk::LookupLiteralRepresentation( |
404 LConstantOperand* operand) const { | 404 LConstantOperand* operand) const { |
405 return graph_->LookupValue(operand->index())->representation(); | 405 return graph_->LookupValue(operand->index())->representation(); |
406 } | 406 } |
407 | 407 |
408 | 408 |
409 static void AddWeakObjectToCodeDependency(Isolate* isolate, | |
410 Handle<HeapObject> object, | |
411 Handle<Code> code) { | |
412 Handle<WeakCell> cell = Code::WeakCellFor(code); | |
413 Heap* heap = isolate->heap(); | |
414 Handle<DependentCode> dep(heap->LookupWeakObjectToCodeDependency(object)); | |
415 dep = DependentCode::InsertWeakCode(dep, DependentCode::kWeakCodeGroup, cell); | |
416 heap->AddWeakObjectToCodeDependency(object, dep); | |
417 } | |
418 | |
419 | |
420 void LChunk::RegisterWeakObjectsInOptimizedCode(Handle<Code> code) const { | |
421 DCHECK(code->is_optimized_code()); | |
422 ZoneList<Handle<Map> > maps(1, zone()); | |
423 ZoneList<Handle<HeapObject> > objects(1, zone()); | |
424 int mode_mask = RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT) | | |
425 RelocInfo::ModeMask(RelocInfo::CELL); | |
426 for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) { | |
427 RelocInfo::Mode mode = it.rinfo()->rmode(); | |
428 if (mode == RelocInfo::CELL && | |
429 code->IsWeakObjectInOptimizedCode(it.rinfo()->target_cell())) { | |
430 objects.Add(Handle<HeapObject>(it.rinfo()->target_cell()), zone()); | |
431 } else if (mode == RelocInfo::EMBEDDED_OBJECT && | |
432 code->IsWeakObjectInOptimizedCode(it.rinfo()->target_object())) { | |
433 if (it.rinfo()->target_object()->IsMap()) { | |
434 Handle<Map> map(Map::cast(it.rinfo()->target_object())); | |
435 maps.Add(map, zone()); | |
436 } else { | |
437 Handle<HeapObject> object( | |
438 HeapObject::cast(it.rinfo()->target_object())); | |
439 objects.Add(object, zone()); | |
440 } | |
441 } | |
442 } | |
443 for (int i = 0; i < maps.length(); i++) { | |
444 if (maps.at(i)->dependent_code()->IsEmpty(DependentCode::kWeakCodeGroup)) { | |
445 isolate()->heap()->AddRetainedMap(maps.at(i)); | |
446 } | |
447 Map::AddDependentCode(maps.at(i), DependentCode::kWeakCodeGroup, code); | |
448 } | |
449 for (int i = 0; i < objects.length(); i++) { | |
450 AddWeakObjectToCodeDependency(isolate(), objects.at(i), code); | |
451 } | |
452 code->set_can_have_weak_objects(true); | |
453 } | |
454 | |
455 | |
456 void LChunk::CommitDependencies(Handle<Code> code) const { | 409 void LChunk::CommitDependencies(Handle<Code> code) const { |
457 if (!code->is_optimized_code()) return; | 410 if (!code->is_optimized_code()) return; |
458 HandleScope scope(isolate()); | 411 HandleScope scope(isolate()); |
459 | 412 |
460 for (Handle<Map> map : deprecation_dependencies_) { | 413 for (Handle<Map> map : deprecation_dependencies_) { |
461 DCHECK(!map->is_deprecated()); | 414 DCHECK(!map->is_deprecated()); |
462 DCHECK(map->CanBeDeprecated()); | 415 DCHECK(map->CanBeDeprecated()); |
463 Map::AddDependentCode(map, DependentCode::kTransitionGroup, code); | 416 Map::AddDependentCode(map, DependentCode::kTransitionGroup, code); |
464 } | 417 } |
465 | 418 |
466 for (Handle<Map> map : stability_dependencies_) { | 419 for (Handle<Map> map : stability_dependencies_) { |
467 DCHECK(map->is_stable()); | 420 DCHECK(map->is_stable()); |
468 DCHECK(map->CanTransition()); | 421 DCHECK(map->CanTransition()); |
469 Map::AddDependentCode(map, DependentCode::kPrototypeCheckGroup, code); | 422 Map::AddDependentCode(map, DependentCode::kPrototypeCheckGroup, code); |
470 } | 423 } |
471 | 424 |
472 info_->dependencies()->Commit(code); | 425 info_->dependencies()->Commit(code); |
473 RegisterWeakObjectsInOptimizedCode(code); | |
474 } | 426 } |
475 | 427 |
476 | 428 |
477 LChunk* LChunk::NewChunk(HGraph* graph) { | 429 LChunk* LChunk::NewChunk(HGraph* graph) { |
478 DisallowHandleAllocation no_handles; | 430 DisallowHandleAllocation no_handles; |
479 DisallowHeapAllocation no_gc; | 431 DisallowHeapAllocation no_gc; |
480 graph->DisallowAddingNewValues(); | 432 graph->DisallowAddingNewValues(); |
481 int values = graph->GetMaximumValueID(); | 433 int values = graph->GetMaximumValueID(); |
482 CompilationInfo* info = graph->info(); | 434 CompilationInfo* info = graph->info(); |
483 if (values > LUnallocated::kMaxVirtualRegisters) { | 435 if (values > LUnallocated::kMaxVirtualRegisters) { |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 | 657 |
706 LPhase::~LPhase() { | 658 LPhase::~LPhase() { |
707 if (ShouldProduceTraceOutput()) { | 659 if (ShouldProduceTraceOutput()) { |
708 isolate()->GetHTracer()->TraceLithium(name(), chunk_); | 660 isolate()->GetHTracer()->TraceLithium(name(), chunk_); |
709 } | 661 } |
710 } | 662 } |
711 | 663 |
712 | 664 |
713 } // namespace internal | 665 } // namespace internal |
714 } // namespace v8 | 666 } // namespace v8 |
OLD | NEW |