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