Commit 5c82f3bd authored by Igor Sheludko's avatar Igor Sheludko Committed by Commit Bot

[runtime] Cleanup SharedFunctionInfo fields definitions (3).

Use convenient macros for accessing bit fields.

Bug: v8:6470
Change-Id: Iada9779ce56c7ca2e8b6a9617c236e294db7325e
Reviewed-on: https://chromium-review.googlesource.com/527432
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45804}
parent c0bf6ee3
......@@ -102,6 +102,14 @@
set_##field(BooleanBit::set(field(), offset, value)); \
}
#define BIT_FIELD_ACCESSORS(holder, field, name, BitField) \
typename BitField::FieldType holder::name() const { \
return BitField::decode(field()); \
} \
void holder::set_##name(typename BitField::FieldType value) { \
set_##field(BitField::update(field(), value)); \
}
#define TYPE_CHECKER(type, instancetype) \
bool HeapObject::Is##type() const { \
return map()->instance_type() == instancetype; \
......
......@@ -34,10 +34,11 @@ ACCESSORS(SharedFunctionInfo, debug_info, Object, kDebugInfoOffset)
ACCESSORS(SharedFunctionInfo, function_identifier, Object,
kFunctionIdentifierOffset)
BOOL_ACCESSORS(SharedFunctionInfo, start_position_and_type, is_named_expression,
kIsNamedExpressionBit)
BOOL_ACCESSORS(SharedFunctionInfo, start_position_and_type, is_toplevel,
kIsTopLevelBit)
BIT_FIELD_ACCESSORS(SharedFunctionInfo, start_position_and_type,
is_named_expression,
SharedFunctionInfo::IsNamedExpressionBits)
BIT_FIELD_ACCESSORS(SharedFunctionInfo, start_position_and_type, is_toplevel,
SharedFunctionInfo::IsTopLevelBits)
INT_ACCESSORS(SharedFunctionInfo, length, kLengthOffset)
INT_ACCESSORS(SharedFunctionInfo, internal_formal_parameter_count,
......@@ -147,15 +148,8 @@ void SharedFunctionInfo::DontAdaptArguments() {
set_internal_formal_parameter_count(kDontAdaptArgumentsSentinel);
}
int SharedFunctionInfo::start_position() const {
return start_position_and_type() >> kStartPositionShift;
}
void SharedFunctionInfo::set_start_position(int start_position) {
set_start_position_and_type(
(start_position << kStartPositionShift) |
(start_position_and_type() & ~kStartPositionMask));
}
BIT_FIELD_ACCESSORS(SharedFunctionInfo, start_position_and_type, start_position,
SharedFunctionInfo::StartPositionBits)
Code* SharedFunctionInfo::code() const {
return Code::cast(READ_FIELD(this, kCodeOffset));
......@@ -318,19 +312,11 @@ void SharedFunctionInfo::set_inferred_name(String* inferred_name) {
set_function_identifier(inferred_name);
}
int SharedFunctionInfo::ic_age() { return ICAgeBits::decode(counters()); }
BIT_FIELD_ACCESSORS(SharedFunctionInfo, counters, ic_age,
SharedFunctionInfo::ICAgeBits)
void SharedFunctionInfo::set_ic_age(int ic_age) {
set_counters(ICAgeBits::update(counters(), ic_age));
}
int SharedFunctionInfo::deopt_count() {
return DeoptCountBits::decode(counters());
}
void SharedFunctionInfo::set_deopt_count(int deopt_count) {
set_counters(DeoptCountBits::update(counters(), deopt_count));
}
BIT_FIELD_ACCESSORS(SharedFunctionInfo, counters, deopt_count,
SharedFunctionInfo::DeoptCountBits)
void SharedFunctionInfo::increment_deopt_count() {
int value = counters();
......@@ -341,29 +327,17 @@ void SharedFunctionInfo::increment_deopt_count() {
}
}
int SharedFunctionInfo::opt_reenable_tries() {
return OptReenableTriesBits::decode(counters());
}
BIT_FIELD_ACCESSORS(SharedFunctionInfo, counters, opt_reenable_tries,
SharedFunctionInfo::OptReenableTriesBits)
void SharedFunctionInfo::set_opt_reenable_tries(int tries) {
set_counters(OptReenableTriesBits::update(counters(), tries));
}
int SharedFunctionInfo::opt_count() {
return OptCountBits::decode(opt_count_and_bailout_reason());
}
void SharedFunctionInfo::set_opt_count(int opt_count) {
set_opt_count_and_bailout_reason(
OptCountBits::update(opt_count_and_bailout_reason(), opt_count));
}
BIT_FIELD_ACCESSORS(SharedFunctionInfo, opt_count_and_bailout_reason, opt_count,
SharedFunctionInfo::OptCountBits)
BailoutReason SharedFunctionInfo::disable_optimization_reason() {
return static_cast<BailoutReason>(
DisabledOptimizationReasonBits::decode(opt_count_and_bailout_reason()));
}
BIT_FIELD_ACCESSORS(SharedFunctionInfo, opt_count_and_bailout_reason,
disable_optimization_reason,
SharedFunctionInfo::DisabledOptimizationReasonBits)
bool SharedFunctionInfo::has_deoptimization_support() {
bool SharedFunctionInfo::has_deoptimization_support() const {
Code* code = this->code();
return code->kind() == Code::FUNCTION && code->has_deoptimization_support();
}
......@@ -379,11 +353,6 @@ void SharedFunctionInfo::TryReenableOptimization() {
}
}
void SharedFunctionInfo::set_disable_optimization_reason(BailoutReason reason) {
set_opt_count_and_bailout_reason(DisabledOptimizationReasonBits::update(
opt_count_and_bailout_reason(), reason));
}
bool SharedFunctionInfo::IsUserJavaScript() {
Object* script_obj = script();
if (script_obj->IsUndefined(GetIsolate())) return false;
......
......@@ -270,7 +270,7 @@ class SharedFunctionInfo : public HeapObject {
// Inline cache age is used to infer whether the function survived a context
// disposal or not. In the former case we reset the opt_count.
inline int ic_age();
inline int ic_age() const;
inline void set_ic_age(int age);
// Indicates if this function can be lazy compiled.
......@@ -331,7 +331,7 @@ class SharedFunctionInfo : public HeapObject {
// Indicates whether or not the code in the shared function support
// deoptimization.
inline bool has_deoptimization_support();
inline bool has_deoptimization_support() const;
// Enable deoptimization support through recompiled code.
void EnableDeoptimizationSupport(Code* recompiled);
......@@ -340,8 +340,6 @@ class SharedFunctionInfo : public HeapObject {
// shared function info.
void DisableOptimization(BailoutReason reason);
inline BailoutReason disable_optimization_reason();
// Lookup the bailout ID and DCHECK that it exists in the non-optimized
// code, returns whether it asserted (i.e., always true if assertions are
// disabled).
......@@ -353,18 +351,18 @@ class SharedFunctionInfo : public HeapObject {
Handle<Object> GetSourceCodeHarmony();
// Number of times the function was optimized.
inline int opt_count();
inline int opt_count() const;
inline void set_opt_count(int opt_count);
// Number of times the function was deoptimized.
inline void set_deopt_count(int value);
inline int deopt_count();
inline int deopt_count() const;
inline void increment_deopt_count();
// Number of time we tried to re-enable optimization after it
// was disabled due to high number of deoptimizations.
inline void set_opt_reenable_tries(int value);
inline int opt_reenable_tries();
inline int opt_reenable_tries() const;
inline void TryReenableOptimization();
......@@ -376,6 +374,7 @@ class SharedFunctionInfo : public HeapObject {
inline void set_opt_count_and_bailout_reason(int value);
inline int opt_count_and_bailout_reason() const;
inline BailoutReason disable_optimization_reason() const;
inline void set_disable_optimization_reason(BailoutReason reason);
// Tells whether this function should be subject to debugging.
......@@ -501,13 +500,10 @@ class SharedFunctionInfo : public HeapObject {
kLastPointerFieldOffset + kPointerSize, kSize>
BodyDescriptorWeakCode;
// Bit positions in start_position_and_type.
// The source code start position is in the 30 most significant bits of
// the start_position_and_type field.
static const int kIsNamedExpressionBit = 0;
static const int kIsTopLevelBit = 1;
static const int kStartPositionShift = 2;
static const int kStartPositionMask = ~((1 << kStartPositionShift) - 1);
// Bit fields in |start_position_and_type|.
typedef BitField<bool, 0, 1> IsNamedExpressionBits;
typedef BitField<bool, IsNamedExpressionBits::kNext, 1> IsTopLevelBits;
typedef BitField<int, IsTopLevelBits::kNext, 30> StartPositionBits;
// TODO(ishell): turn this into a set of BitFields.
// Bit positions in compiler_hints.
......@@ -539,7 +535,7 @@ class SharedFunctionInfo : public HeapObject {
kCompilerHintsCount = kFunctionKind + 10, // Pseudo entry
};
// Bit positions in debugger_hints.
// Bit positions in |debugger_hints|.
enum DebuggerHints {
kIsAnonymousExpression,
kNameShouldPrintAsAnonymous,
......@@ -556,12 +552,15 @@ class SharedFunctionInfo : public HeapObject {
class FunctionKindBits : public BitField<FunctionKind, kFunctionKind, 10> {};
class DeoptCountBits : public BitField<int, 0, 4> {};
class OptReenableTriesBits : public BitField<int, 4, 18> {};
class ICAgeBits : public BitField<int, 22, 8> {};
// Bit fields in |counters|.
typedef BitField<int, 0, 4> DeoptCountBits;
typedef BitField<int, DeoptCountBits::kNext, 18> OptReenableTriesBits;
typedef BitField<int, OptReenableTriesBits::kNext, 8> ICAgeBits;
class OptCountBits : public BitField<int, 0, 22> {};
class DisabledOptimizationReasonBits : public BitField<int, 22, 8> {};
// Bit fields in |opt_count_and_bailout_reason|.
typedef BitField<int, 0, 22> OptCountBits;
typedef BitField<BailoutReason, OptCountBits::kNext, 8>
DisabledOptimizationReasonBits;
private:
FRIEND_TEST(PreParserTest, LazyFunctionLength);
......
......@@ -274,6 +274,8 @@ inline int32_t WhichPowerOf2Abs(int32_t x) {
template<class T, int shift, int size, class U>
class BitFieldBase {
public:
typedef T FieldType;
// A type U mask of bit field. To use all bits of a type U of x bits
// in a bitfield without compiler warnings we have to compute 2^x
// without using a shift count of x in the computation.
......
......@@ -192,9 +192,9 @@ consts_misc = [
'value': 'ScopeInfo::kVariablePartIndex' },
{ 'name': 'sharedfunctioninfo_start_position_mask',
'value': 'SharedFunctionInfo::kStartPositionMask' },
'value': 'SharedFunctionInfo::StartPositionBits::kMask' },
{ 'name': 'sharedfunctioninfo_start_position_shift',
'value': 'SharedFunctionInfo::kStartPositionShift' },
'value': 'SharedFunctionInfo::StartPositionBits::kShift' },
{ 'name': 'jsarray_buffer_was_neutered_mask',
'value': 'JSArrayBuffer::WasNeutered::kMask' },
......
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