diff --git a/runtime/vm/flag_list.h b/runtime/vm/flag_list.h index 40a8d2896bc61..1e74d39ae06f5 100644 --- a/runtime/vm/flag_list.h +++ b/runtime/vm/flag_list.h @@ -12,6 +12,13 @@ #define USING_DBC false #endif +// Don't use USING_KBC outside of this file. +#if defined(DART_USE_INTERPRETER) +#define USING_KBC true +#else +#define USING_KBC false +#endif + // Don't use USING_MULTICORE outside of this file. #if defined(ARCH_IS_MULTI_CORE) #define USING_MULTICORE true @@ -186,7 +193,7 @@ constexpr bool kDartPrecompiledRuntime = false; P(use_compactor, bool, false, "Compact the heap during old-space GC.") \ P(use_cha_deopt, bool, true, \ "Use class hierarchy analysis even if it can cause deoptimization.") \ - P(use_field_guards, bool, !USING_DBC, \ + P(use_field_guards, bool, !USING_DBC && !USING_KBC, \ "Use field guards and track field types") \ C(use_osr, false, true, bool, true, "Use OSR") \ P(use_strong_mode_types, bool, true, "Optimize based on strong mode types.") \ diff --git a/runtime/vm/interpreter.cc b/runtime/vm/interpreter.cc index 0f2cea16f26a2..34c4b8c5ead07 100644 --- a/runtime/vm/interpreter.cc +++ b/runtime/vm/interpreter.cc @@ -1013,28 +1013,30 @@ DART_NOINLINE bool Interpreter::ProcessInvocation(bool* invoked, return false; } } - // Check value cid according to field.guarded_cid(). - // The interpreter should never see a cloned field. - ASSERT(field->ptr()->owner_->GetClassId() != kFieldCid); - const classid_t field_guarded_cid = field->ptr()->guarded_cid_; - const classid_t field_nullability_cid = field->ptr()->is_nullable_; - const classid_t value_cid = InterpreterHelpers::GetClassId(value); - if (value_cid != field_guarded_cid && - value_cid != field_nullability_cid) { - if (Smi::Value(field->ptr()->guarded_list_length_) < - Field::kUnknownFixedLength && - field_guarded_cid == kIllegalCid) { - field->ptr()->guarded_cid_ = value_cid; - field->ptr()->is_nullable_ = value_cid; - } else if (field_guarded_cid != kDynamicCid) { - call_top[1] = 0; // Unused result of runtime call. - call_top[2] = field; - call_top[3] = value; - Exit(thread, *FP, call_top + 4, *pc); - NativeArguments native_args(thread, 2, call_top + 2, call_top + 1); - if (!InvokeRuntime(thread, this, DRT_UpdateFieldCid, native_args)) { - *invoked = true; - return false; + if (thread->isolate()->use_field_guards()) { + // Check value cid according to field.guarded_cid(). + // The interpreter should never see a cloned field. + ASSERT(field->ptr()->owner_->GetClassId() != kFieldCid); + const classid_t field_guarded_cid = field->ptr()->guarded_cid_; + const classid_t field_nullability_cid = field->ptr()->is_nullable_; + const classid_t value_cid = InterpreterHelpers::GetClassId(value); + if (value_cid != field_guarded_cid && + value_cid != field_nullability_cid) { + if (Smi::Value(field->ptr()->guarded_list_length_) < + Field::kUnknownFixedLength && + field_guarded_cid == kIllegalCid) { + field->ptr()->guarded_cid_ = value_cid; + field->ptr()->is_nullable_ = value_cid; + } else if (field_guarded_cid != kDynamicCid) { + call_top[1] = 0; // Unused result of runtime call. + call_top[2] = field; + call_top[3] = value; + Exit(thread, *FP, call_top + 4, *pc); + NativeArguments native_args(thread, 2, call_top + 2, call_top + 1); + if (!InvokeRuntime(thread, this, DRT_UpdateFieldCid, native_args)) { + *invoked = true; + return false; + } } } } @@ -3480,6 +3482,9 @@ RawObject* Interpreter::Call(RawFunction* function, RawInstance* instance = reinterpret_cast(FP[rA]); RawObject* value = FP[value_reg]; + // TODO(regis): Implement cid guard. + ASSERT(!thread->isolate()->use_field_guards()); + instance->StorePointer( reinterpret_cast(instance->ptr()) + offset_in_words, value); @@ -3493,6 +3498,8 @@ RawObject* Interpreter::Call(RawFunction* function, RawInstance* instance = reinterpret_cast(FP[rA]); RawObject* value = FP[rD]; + UNREACHABLE(); // TODO(regis): unused, remove. + instance->StorePointer( reinterpret_cast(instance->ptr()) + offset_in_words, value); @@ -3506,6 +3513,10 @@ RawObject* Interpreter::Call(RawFunction* function, RawInstance* instance = reinterpret_cast(SP[-1]); RawObject* value = reinterpret_cast(SP[0]); SP -= 2; // Drop instance and value. + + // TODO(regis): Implement cid guard. + ASSERT(!thread->isolate()->use_field_guards()); + instance->StorePointer( reinterpret_cast(instance->ptr()) + offset_in_words, value);