Commit e5dd7a40 authored by Toon Verwaest's avatar Toon Verwaest Committed by V8 LUCI CQ

[code-cache] Add a flag to control bytecode aging limits

Change-Id: Ia09e8c4528e59116be39be12d688f5b99a34c8e7
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3732938Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Auto-Submit: Toon Verwaest <verwaest@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81437}
parent a1b1b759
......@@ -1067,7 +1067,6 @@ namespace {
void ResetBytecodeAge(MacroAssembler* masm, Register bytecode_array,
Register scratch) {
static_assert(BytecodeArray::kNoAgeBytecodeAge == 0);
DCHECK(!AreAliased(bytecode_array, scratch));
__ mov(scratch, Operand(0));
__ strh(scratch,
......
......@@ -1233,7 +1233,6 @@ static void MaybeOptimizeCodeOrTailCallOptimizedCodeSlot(
namespace {
void ResetBytecodeAge(MacroAssembler* masm, Register bytecode_array) {
static_assert(BytecodeArray::kNoAgeBytecodeAge == 0);
__ Strh(wzr,
FieldMemOperand(bytecode_array, BytecodeArray::kBytecodeAgeOffset));
}
......
......@@ -1034,7 +1034,6 @@ static void MaybeOptimizeCodeOrTailCallOptimizedCodeSlot(
namespace {
void ResetBytecodeAge(MacroAssembler* masm, Register bytecode_array) {
static_assert(BytecodeArray::kNoAgeBytecodeAge == 0);
__ mov_w(FieldOperand(bytecode_array, BytecodeArray::kBytecodeAgeOffset),
Immediate(0));
}
......
......@@ -1038,9 +1038,7 @@ static void MaybeOptimizeCodeOrTailCallOptimizedCodeSlot(
}
namespace {
void ResetBytecodeAge(MacroAssembler* masm,
Register bytecode_array) {
static_assert(BytecodeArray::kNoAgeBytecodeAge == 0);
void ResetBytecodeAge(MacroAssembler* masm, Register bytecode_array) {
__ sh(zero_reg,
FieldMemOperand(bytecode_array, BytecodeArray::kBytecodeAgeOffset));
}
......
......@@ -1047,7 +1047,6 @@ static void MaybeOptimizeCodeOrTailCallOptimizedCodeSlot(
namespace {
void ResetBytecodeAge(MacroAssembler* masm, Register bytecode_array) {
static_assert(BytecodeArray::kNoAgeBytecodeAge == 0);
__ Sh(zero_reg,
FieldMemOperand(bytecode_array, BytecodeArray::kBytecodeAgeOffset));
}
......
......@@ -81,7 +81,6 @@ void Generate_OSREntry(MacroAssembler* masm, Register entry_address,
void ResetBytecodeAge(MacroAssembler* masm, Register bytecode_array,
Register scratch) {
static_assert(BytecodeArray::kNoAgeBytecodeAge == 0);
DCHECK(!AreAliased(bytecode_array, scratch));
__ mov(scratch, Operand(0));
__ StoreU16(
......
......@@ -85,7 +85,6 @@ void Generate_OSREntry(MacroAssembler* masm, Register entry_address,
void ResetBytecodeAge(MacroAssembler* masm, Register bytecode_array,
Register scratch) {
static_assert(BytecodeArray::kNoAgeBytecodeAge == 0);
DCHECK(!AreAliased(bytecode_array, scratch));
__ mov(r0, Operand(0));
__ StoreU16(
......
......@@ -1134,7 +1134,6 @@ static void MaybeOptimizeCodeOrTailCallOptimizedCodeSlot(
namespace {
void ResetBytecodeAge(MacroAssembler* masm, Register bytecode_array) {
static_assert(BytecodeArray::kNoAgeBytecodeAge == 0);
__ movw(FieldOperand(bytecode_array, BytecodeArray::kBytecodeAgeOffset),
Immediate(0));
}
......
......@@ -1402,6 +1402,7 @@ DEFINE_BOOL(flush_baseline_code, false,
"flush of baseline code when it has not been executed recently")
DEFINE_BOOL(flush_bytecode, true,
"flush of bytecode when it has not been executed recently")
DEFINE_INT(bytecode_old_age, 5, "number of gcs before we flush code")
DEFINE_BOOL(stress_flush_code, false, "stress code flushing")
DEFINE_BOOL(trace_flush_bytecode, false, "trace bytecode flushing")
DEFINE_BOOL(use_marking_progress_bar, true,
......
......@@ -247,7 +247,7 @@ Handle<BytecodeArray> FactoryBase<Impl>::NewBytecodeArray(
instance.set_parameter_count(parameter_count);
instance.set_incoming_new_target_or_generator_register(
interpreter::Register::invalid_value());
instance.set_bytecode_age(BytecodeArray::kNoAgeBytecodeAge);
instance.set_bytecode_age(0);
instance.set_constant_pool(*constant_pool);
instance.set_handler_table(read_only_roots().empty_byte_array(),
SKIP_WRITE_BARRIER);
......
......@@ -1272,20 +1272,14 @@ void BytecodeArray::set_incoming_new_target_or_generator_register(
}
}
BytecodeArray::Age BytecodeArray::bytecode_age() const {
uint16_t BytecodeArray::bytecode_age() const {
// Bytecode is aged by the concurrent marker.
static_assert(kBytecodeAgeSize == kUInt16Size);
return static_cast<Age>(RELAXED_READ_INT16_FIELD(*this, kBytecodeAgeOffset));
return RELAXED_READ_UINT16_FIELD(*this, kBytecodeAgeOffset);
}
void BytecodeArray::set_bytecode_age(BytecodeArray::Age age) {
DCHECK_GE(age, kFirstBytecodeAge);
DCHECK_LE(age, kLastBytecodeAge);
static_assert(kLastBytecodeAge <= kMaxInt16);
static_assert(kBytecodeAgeSize == kUInt16Size);
void BytecodeArray::set_bytecode_age(uint16_t age) {
// Bytecode is aged by the concurrent marker.
RELAXED_WRITE_INT16_FIELD(*this, kBytecodeAgeOffset,
static_cast<int16_t>(age));
RELAXED_WRITE_UINT16_FIELD(*this, kBytecodeAgeOffset, age);
}
int32_t BytecodeArray::parameter_count() const {
......
......@@ -713,19 +713,19 @@ void BytecodeArray::MakeOlder() {
// The word must be completely within the byte code array.
Address age_addr = address() + kBytecodeAgeOffset;
DCHECK_LE(RoundDown(age_addr, kTaggedSize) + kTaggedSize, address() + Size());
Age age = bytecode_age();
if (age < kLastBytecodeAge) {
uint16_t age = bytecode_age();
if (age < FLAG_bytecode_old_age) {
static_assert(kBytecodeAgeSize == kUInt16Size);
base::AsAtomic16::Relaxed_CompareAndSwap(
reinterpret_cast<base::Atomic16*>(age_addr), age, age + 1);
}
DCHECK_GE(bytecode_age(), kFirstBytecodeAge);
DCHECK_LE(bytecode_age(), kLastBytecodeAge);
DCHECK_GE(bytecode_age(), 1);
DCHECK_LE(bytecode_age(), FLAG_bytecode_old_age);
}
bool BytecodeArray::IsOld() const {
return bytecode_age() >= kIsOldBytecodeAge;
return bytecode_age() >= FLAG_bytecode_old_age;
}
DependentCode DependentCode::GetDependentCode(HeapObject object) {
......
......@@ -1088,20 +1088,6 @@ DEFINE_OPERATORS_FOR_FLAGS(DependentCode::DependencyGroups)
class BytecodeArray
: public TorqueGeneratedBytecodeArray<BytecodeArray, FixedArrayBase> {
public:
enum Age {
kNoAgeBytecodeAge = 0,
kQuadragenarianBytecodeAge,
kQuinquagenarianBytecodeAge,
kSexagenarianBytecodeAge,
kSeptuagenarianBytecodeAge,
kOctogenarianBytecodeAge,
kAfterLastBytecodeAge,
kFirstBytecodeAge = kNoAgeBytecodeAge,
kLastBytecodeAge = kAfterLastBytecodeAge - 1,
kBytecodeAgeCount = kAfterLastBytecodeAge - kFirstBytecodeAge - 1,
kIsOldBytecodeAge = kOctogenarianBytecodeAge
};
static constexpr int SizeFor(int length) {
return OBJECT_POINTER_ALIGN(kHeaderSize + length);
}
......@@ -1130,8 +1116,8 @@ class BytecodeArray
static_assert(kBytecodeAgeOffset + kBytecodeAgeSize - 1 ==
kBytecodeAgeOffsetEnd);
inline Age bytecode_age() const;
inline void set_bytecode_age(Age age);
inline uint16_t bytecode_age() const;
inline void set_bytecode_age(uint16_t age);
inline bool HasSourcePositionTable() const;
inline bool DidSourcePositionGenerationFail() const;
......
......@@ -635,8 +635,7 @@ Handle<HeapObject> Deserializer<IsolateT>::ReadObject(SnapshotSpace space) {
// Make sure BytecodeArrays have a valid age, so that the marker doesn't
// break when making them older.
if (raw_obj.IsBytecodeArray(isolate())) {
BytecodeArray::cast(raw_obj).set_bytecode_age(
BytecodeArray::kFirstBytecodeAge);
BytecodeArray::cast(raw_obj).set_bytecode_age(0);
}
#ifdef DEBUG
......
......@@ -1192,7 +1192,7 @@ void Serializer::ObjectSerializer::OutputRawData(Address up_to) {
if (object_->IsBytecodeArray(cage_base)) {
// The bytecode age field can be changed by GC concurrently.
static_assert(BytecodeArray::kBytecodeAgeSize == kUInt16Size);
uint16_t field_value = BytecodeArray::kNoAgeBytecodeAge;
uint16_t field_value = 0;
OutputRawWithCustomField(sink_, object_start, base, bytes_to_output,
BytecodeArray::kBytecodeAgeOffset,
sizeof(field_value),
......
......@@ -706,12 +706,12 @@ TEST(BytecodeArrayAging) {
factory->NewBytecodeArray(kRawBytesSize, kRawBytes, kFrameSize,
kParameterCount, factory->empty_fixed_array());
CHECK_EQ(BytecodeArray::kFirstBytecodeAge, array->bytecode_age());
CHECK_EQ(0, array->bytecode_age());
array->MakeOlder();
CHECK_EQ(BytecodeArray::kQuadragenarianBytecodeAge, array->bytecode_age());
array->set_bytecode_age(BytecodeArray::kLastBytecodeAge);
CHECK_EQ(1, array->bytecode_age());
array->set_bytecode_age(FLAG_bytecode_old_age);
array->MakeOlder();
CHECK_EQ(BytecodeArray::kLastBytecodeAge, array->bytecode_age());
CHECK_EQ(FLAG_bytecode_old_age, array->bytecode_age());
}
static const char* not_so_random_string_table[] = {
......
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