diff --git a/src/compiler/code-generator.cc b/src/compiler/code-generator.cc index 0b55911402..a336c7a214 100644 --- a/src/compiler/code-generator.cc +++ b/src/compiler/code-generator.cc @@ -100,8 +100,7 @@ Handle CodeGenerator::GenerateCode() { for (CompilationInfo::InlinedFunctionHolder& inlined : info->inlined_functions()) { if (!inlined.shared_info.equals(info->shared_info())) { - int index = DefineDeoptimizationLiteral( - DeoptimizationLiteral(inlined.shared_info)); + int index = DefineDeoptimizationLiteral(inlined.shared_info); inlined.RegisterInlinedFunctionId(index); } } @@ -112,8 +111,7 @@ Handle CodeGenerator::GenerateCode() { for (const CompilationInfo::InlinedFunctionHolder& inlined : info->inlined_functions()) { if (!inlined.shared_info.equals(info->shared_info())) { - DefineDeoptimizationLiteral( - DeoptimizationLiteral(inlined.inlined_code_object_root)); + DefineDeoptimizationLiteral(inlined.inlined_code_object_root); } } @@ -577,11 +575,13 @@ void CodeGenerator::PopulateDeoptimizationData(Handle code_object) { Handle literals = isolate()->factory()->NewFixedArray( static_cast(deoptimization_literals_.size()), TENURED); - for (unsigned i = 0; i < deoptimization_literals_.size(); i++) { - Handle object = deoptimization_literals_[i].Reify(isolate()); - literals->set(i, *object); + { + AllowDeferredHandleDereference copy_handles; + for (unsigned i = 0; i < deoptimization_literals_.size(); i++) { + literals->set(i, *deoptimization_literals_[i]); + } + data->SetLiteralArray(*literals); } - data->SetLiteralArray(*literals); Handle> inl_pos = CreateInliningPositions(info); data->SetInliningPositions(*inl_pos); @@ -656,10 +656,11 @@ void CodeGenerator::RecordCallPosition(Instruction* instr) { } } -int CodeGenerator::DefineDeoptimizationLiteral(DeoptimizationLiteral literal) { + +int CodeGenerator::DefineDeoptimizationLiteral(Handle literal) { int result = static_cast(deoptimization_literals_.size()); for (unsigned i = 0; i < deoptimization_literals_.size(); ++i) { - if (deoptimization_literals_[i] == literal) return i; + if (deoptimization_literals_[i].equals(literal)) return i; } deoptimization_literals_.push_back(literal); return result; @@ -721,8 +722,8 @@ void CodeGenerator::TranslateStateValueDescriptor( DCHECK(desc->IsOptimizedOut()); if (translation != nullptr) { if (optimized_out_literal_id_ == -1) { - optimized_out_literal_id_ = DefineDeoptimizationLiteral( - DeoptimizationLiteral(isolate()->factory()->optimized_out())); + optimized_out_literal_id_ = + DefineDeoptimizationLiteral(isolate()->factory()->optimized_out()); } translation->StoreLiteral(optimized_out_literal_id_); } @@ -789,8 +790,7 @@ void CodeGenerator::BuildTranslationForFrameStateDescriptor( } shared_info = info()->shared_info(); } - int shared_info_id = - DefineDeoptimizationLiteral(DeoptimizationLiteral(shared_info)); + int shared_info_id = DefineDeoptimizationLiteral(shared_info); switch (descriptor->type()) { case FrameStateType::kJavaScriptFunction: @@ -906,23 +906,22 @@ void CodeGenerator::AddTranslationForOperand(Translation* translation, CHECK(op->IsImmediate()); InstructionOperandConverter converter(this, instr); Constant constant = converter.ToConstant(op); - DeoptimizationLiteral literal; + Handle constant_object; switch (constant.type()) { case Constant::kInt32: if (type.representation() == MachineRepresentation::kTagged) { // When pointers are 4 bytes, we can use int32 constants to represent // Smis. DCHECK_EQ(4, kPointerSize); - Smi* smi = reinterpret_cast(constant.ToInt32()); - DCHECK(smi->IsSmi()); - literal = DeoptimizationLiteral(smi->value()); + constant_object = + handle(reinterpret_cast(constant.ToInt32()), isolate()); + DCHECK(constant_object->IsSmi()); } else if (type.representation() == MachineRepresentation::kBit) { if (constant.ToInt32() == 0) { - literal = - DeoptimizationLiteral(isolate()->factory()->false_value()); + constant_object = isolate()->factory()->false_value(); } else { DCHECK_EQ(1, constant.ToInt32()); - literal = DeoptimizationLiteral(isolate()->factory()->true_value()); + constant_object = isolate()->factory()->true_value(); } } else { // TODO(jarin,bmeurer): We currently pass in raw pointers to the @@ -934,10 +933,11 @@ void CodeGenerator::AddTranslationForOperand(Translation* translation, DCHECK(type.representation() != MachineRepresentation::kNone || constant.ToInt32() == FrameStateDescriptor::kImpossibleValue); if (type == MachineType::Uint32()) { - literal = DeoptimizationLiteral( - static_cast(constant.ToInt32())); + constant_object = + isolate()->factory()->NewNumberFromUint(constant.ToInt32()); } else { - literal = DeoptimizationLiteral(constant.ToInt32()); + constant_object = + isolate()->factory()->NewNumberFromInt(constant.ToInt32()); } } break; @@ -949,33 +949,31 @@ void CodeGenerator::AddTranslationForOperand(Translation* translation, DCHECK(type.representation() == MachineRepresentation::kWord64 || type.representation() == MachineRepresentation::kTagged); DCHECK_EQ(8, kPointerSize); - { - Smi* smi = reinterpret_cast(constant.ToInt64()); - DCHECK(smi->IsSmi()); - literal = DeoptimizationLiteral(smi->value()); - } + constant_object = + handle(reinterpret_cast(constant.ToInt64()), isolate()); + DCHECK(constant_object->IsSmi()); break; case Constant::kFloat32: DCHECK(type.representation() == MachineRepresentation::kFloat32 || type.representation() == MachineRepresentation::kTagged); - literal = DeoptimizationLiteral(constant.ToFloat32()); + constant_object = isolate()->factory()->NewNumber(constant.ToFloat32()); break; case Constant::kFloat64: DCHECK(type.representation() == MachineRepresentation::kFloat64 || type.representation() == MachineRepresentation::kTagged); - literal = DeoptimizationLiteral(constant.ToFloat64()); + constant_object = isolate()->factory()->NewNumber(constant.ToFloat64()); break; case Constant::kHeapObject: DCHECK_EQ(MachineRepresentation::kTagged, type.representation()); - literal = DeoptimizationLiteral(constant.ToHeapObject()); + constant_object = constant.ToHeapObject(); break; default: UNREACHABLE(); } - if (literal.object().equals(info()->closure())) { + if (constant_object.equals(info()->closure())) { translation->StoreJSFrameFunction(); } else { - int literal_id = DefineDeoptimizationLiteral(literal); + int literal_id = DefineDeoptimizationLiteral(constant_object); translation->StoreLiteral(literal_id); } } diff --git a/src/compiler/code-generator.h b/src/compiler/code-generator.h index 3fa2a67bde..b4873ff2d8 100644 --- a/src/compiler/code-generator.h +++ b/src/compiler/code-generator.h @@ -48,30 +48,6 @@ class InstructionOperandIterator { size_t pos_; }; -// Either a non-null Handle or a double. -class DeoptimizationLiteral { - public: - DeoptimizationLiteral() : object_(), number_(0) {} - explicit DeoptimizationLiteral(Handle object) - : object_(object), number_(0) { - DCHECK(!object_.is_null()); - } - explicit DeoptimizationLiteral(double number) : object_(), number_(number) {} - - Handle object() const { return object_; } - - bool operator==(const DeoptimizationLiteral& other) const { - return object_.equals(other.object_) && number_ == other.number_; - } - - Handle Reify(Isolate* isolate) const { - return object_.is_null() ? isolate->factory()->NewNumber(number_) : object_; - } - - private: - Handle object_; - double number_; -}; // Generates native code for a sequence of instructions. class CodeGenerator final : public GapResolver::Assembler { @@ -232,7 +208,7 @@ class CodeGenerator final : public GapResolver::Assembler { void RecordCallPosition(Instruction* instr); void PopulateDeoptimizationData(Handle code); - int DefineDeoptimizationLiteral(DeoptimizationLiteral literal); + int DefineDeoptimizationLiteral(Handle literal); DeoptimizationEntry const& GetDeoptimizationEntry(Instruction* instr, size_t frame_state_offset); DeoptimizeKind GetDeoptimizationKind(int deoptimization_id) const; @@ -307,7 +283,7 @@ class CodeGenerator final : public GapResolver::Assembler { ZoneVector handlers_; ZoneDeque deoptimization_exits_; ZoneDeque deoptimization_states_; - ZoneDeque deoptimization_literals_; + ZoneDeque> deoptimization_literals_; size_t inlined_function_count_; TranslationBuffer translations_; int last_lazy_deopt_pc_;