Commit a730a31a authored by ulan's avatar ulan Committed by Commit bot

Cache WeakCell for optimized code.

BUG=

Review URL: https://codereview.chromium.org/873233002

Cr-Commit-Position: refs/heads/master@{#26274}
parent 0e11bb7b
...@@ -944,6 +944,7 @@ void LCodeGen::PopulateDeoptimizationData(Handle<Code> code) { ...@@ -944,6 +944,7 @@ void LCodeGen::PopulateDeoptimizationData(Handle<Code> code) {
} else { } else {
data->SetSharedFunctionInfo(Smi::FromInt(0)); data->SetSharedFunctionInfo(Smi::FromInt(0));
} }
data->SetWeakCellCache(Smi::FromInt(0));
Handle<FixedArray> literals = Handle<FixedArray> literals =
factory()->NewFixedArray(deoptimization_literals_.length(), TENURED); factory()->NewFixedArray(deoptimization_literals_.length(), TENURED);
......
...@@ -941,6 +941,7 @@ void LCodeGen::PopulateDeoptimizationData(Handle<Code> code) { ...@@ -941,6 +941,7 @@ void LCodeGen::PopulateDeoptimizationData(Handle<Code> code) {
} else { } else {
data->SetSharedFunctionInfo(Smi::FromInt(0)); data->SetSharedFunctionInfo(Smi::FromInt(0));
} }
data->SetWeakCellCache(Smi::FromInt(0));
Handle<FixedArray> literals = Handle<FixedArray> literals =
factory()->NewFixedArray(deoptimization_literals_.length(), TENURED); factory()->NewFixedArray(deoptimization_literals_.length(), TENURED);
......
...@@ -913,6 +913,7 @@ void LCodeGen::PopulateDeoptimizationData(Handle<Code> code) { ...@@ -913,6 +913,7 @@ void LCodeGen::PopulateDeoptimizationData(Handle<Code> code) {
} else { } else {
data->SetSharedFunctionInfo(Smi::FromInt(0)); data->SetSharedFunctionInfo(Smi::FromInt(0));
} }
data->SetWeakCellCache(Smi::FromInt(0));
Handle<FixedArray> literals = Handle<FixedArray> literals =
factory()->NewFixedArray(deoptimization_literals_.length(), TENURED); factory()->NewFixedArray(deoptimization_literals_.length(), TENURED);
......
...@@ -908,6 +908,7 @@ void LCodeGen::PopulateDeoptimizationData(Handle<Code> code) { ...@@ -908,6 +908,7 @@ void LCodeGen::PopulateDeoptimizationData(Handle<Code> code) {
} else { } else {
data->SetSharedFunctionInfo(Smi::FromInt(0)); data->SetSharedFunctionInfo(Smi::FromInt(0));
} }
data->SetWeakCellCache(Smi::FromInt(0));
Handle<FixedArray> literals = Handle<FixedArray> literals =
factory()->NewFixedArray(deoptimization_literals_.length(), TENURED); factory()->NewFixedArray(deoptimization_literals_.length(), TENURED);
......
...@@ -858,6 +858,7 @@ void LCodeGen::PopulateDeoptimizationData(Handle<Code> code) { ...@@ -858,6 +858,7 @@ void LCodeGen::PopulateDeoptimizationData(Handle<Code> code) {
} else { } else {
data->SetSharedFunctionInfo(Smi::FromInt(0)); data->SetSharedFunctionInfo(Smi::FromInt(0));
} }
data->SetWeakCellCache(Smi::FromInt(0));
Handle<FixedArray> literals = Handle<FixedArray> literals =
factory()->NewFixedArray(deoptimization_literals_.length(), TENURED); factory()->NewFixedArray(deoptimization_literals_.length(), TENURED);
......
...@@ -11033,6 +11033,29 @@ const char* Code::Kind2String(Kind kind) { ...@@ -11033,6 +11033,29 @@ const char* Code::Kind2String(Kind kind) {
} }
Handle<WeakCell> Code::WeakCellFor(Handle<Code> code) {
DCHECK(code->kind() == OPTIMIZED_FUNCTION);
WeakCell* raw_cell = code->CachedWeakCell();
if (raw_cell != NULL) return Handle<WeakCell>(raw_cell);
Handle<WeakCell> cell = code->GetIsolate()->factory()->NewWeakCell(code);
DeoptimizationInputData::cast(code->deoptimization_data())
->SetWeakCellCache(*cell);
return cell;
}
WeakCell* Code::CachedWeakCell() {
DCHECK(kind() == OPTIMIZED_FUNCTION);
Object* weak_cell_cache =
DeoptimizationInputData::cast(deoptimization_data())->WeakCellCache();
if (weak_cell_cache->IsWeakCell()) {
DCHECK(this == WeakCell::cast(weak_cell_cache)->value());
return WeakCell::cast(weak_cell_cache);
}
return NULL;
}
#ifdef ENABLE_DISASSEMBLER #ifdef ENABLE_DISASSEMBLER
void DeoptimizationInputData::DeoptimizationInputDataPrint( void DeoptimizationInputData::DeoptimizationInputDataPrint(
......
...@@ -4852,7 +4852,8 @@ class DeoptimizationInputData: public FixedArray { ...@@ -4852,7 +4852,8 @@ class DeoptimizationInputData: public FixedArray {
static const int kOsrPcOffsetIndex = 4; static const int kOsrPcOffsetIndex = 4;
static const int kOptimizationIdIndex = 5; static const int kOptimizationIdIndex = 5;
static const int kSharedFunctionInfoIndex = 6; static const int kSharedFunctionInfoIndex = 6;
static const int kFirstDeoptEntryIndex = 7; static const int kWeakCellCacheIndex = 7;
static const int kFirstDeoptEntryIndex = 8;
// Offsets of deopt entry elements relative to the start of the entry. // Offsets of deopt entry elements relative to the start of the entry.
static const int kAstIdRawOffset = 0; static const int kAstIdRawOffset = 0;
...@@ -4877,6 +4878,7 @@ class DeoptimizationInputData: public FixedArray { ...@@ -4877,6 +4878,7 @@ class DeoptimizationInputData: public FixedArray {
DEFINE_ELEMENT_ACCESSORS(OsrPcOffset, Smi) DEFINE_ELEMENT_ACCESSORS(OsrPcOffset, Smi)
DEFINE_ELEMENT_ACCESSORS(OptimizationId, Smi) DEFINE_ELEMENT_ACCESSORS(OptimizationId, Smi)
DEFINE_ELEMENT_ACCESSORS(SharedFunctionInfo, Object) DEFINE_ELEMENT_ACCESSORS(SharedFunctionInfo, Object)
DEFINE_ELEMENT_ACCESSORS(WeakCellCache, Object)
#undef DEFINE_ELEMENT_ACCESSORS #undef DEFINE_ELEMENT_ACCESSORS
...@@ -5407,6 +5409,9 @@ class Code: public HeapObject { ...@@ -5407,6 +5409,9 @@ class Code: public HeapObject {
static inline bool IsWeakObjectInOptimizedCode(Object* object); static inline bool IsWeakObjectInOptimizedCode(Object* object);
static Handle<WeakCell> WeakCellFor(Handle<Code> code);
WeakCell* CachedWeakCell();
// Max loop nesting marker used to postpose OSR. We don't take loop // Max loop nesting marker used to postpose OSR. We don't take loop
// nesting that is deeper than 5 levels into account. // nesting that is deeper than 5 levels into account.
static const int kMaxLoopNestingMarker = 6; static const int kMaxLoopNestingMarker = 6;
......
...@@ -823,6 +823,7 @@ void LCodeGen::PopulateDeoptimizationData(Handle<Code> code) { ...@@ -823,6 +823,7 @@ void LCodeGen::PopulateDeoptimizationData(Handle<Code> code) {
} else { } else {
data->SetSharedFunctionInfo(Smi::FromInt(0)); data->SetSharedFunctionInfo(Smi::FromInt(0));
} }
data->SetWeakCellCache(Smi::FromInt(0));
Handle<FixedArray> literals = Handle<FixedArray> literals =
factory()->NewFixedArray(deoptimization_literals_.length(), TENURED); factory()->NewFixedArray(deoptimization_literals_.length(), TENURED);
......
...@@ -1195,6 +1195,7 @@ void LCodeGen::PopulateDeoptimizationData(Handle<Code> code) { ...@@ -1195,6 +1195,7 @@ void LCodeGen::PopulateDeoptimizationData(Handle<Code> code) {
} else { } else {
data->SetSharedFunctionInfo(Smi::FromInt(0)); data->SetSharedFunctionInfo(Smi::FromInt(0));
} }
data->SetWeakCellCache(Smi::FromInt(0));
Handle<FixedArray> literals = Handle<FixedArray> literals =
factory()->NewFixedArray(deoptimization_literals_.length(), TENURED); factory()->NewFixedArray(deoptimization_literals_.length(), TENURED);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment