Commit d8434356 authored by verwaest's avatar verwaest Committed by Commit bot

Better pack fields in Variable

This reduces sizeof(Variable) from 64 to 40 on x64

BUG=v8:5209

Review-Url: https://codereview.chromium.org/2253513002
Cr-Commit-Position: refs/heads/master@{#38659}
parent b73376b9
...@@ -34,12 +34,12 @@ Variable::Variable(Scope* scope, const AstRawString* name, VariableMode mode, ...@@ -34,12 +34,12 @@ Variable::Variable(Scope* scope, const AstRawString* name, VariableMode mode,
MaybeAssignedFlag maybe_assigned_flag) MaybeAssignedFlag maybe_assigned_flag)
: scope_(scope), : scope_(scope),
name_(name), name_(name),
local_if_not_shadowed_(nullptr),
index_(-1),
initializer_position_(kNoSourcePosition),
mode_(mode), mode_(mode),
kind_(kind), kind_(kind),
location_(VariableLocation::UNALLOCATED), location_(VariableLocation::UNALLOCATED),
index_(-1),
initializer_position_(kNoSourcePosition),
local_if_not_shadowed_(NULL),
force_context_allocation_(false), force_context_allocation_(false),
is_used_(false), is_used_(false),
initialization_flag_(initialization_flag), initialization_flag_(initialization_flag),
......
...@@ -17,7 +17,13 @@ namespace internal { ...@@ -17,7 +17,13 @@ namespace internal {
// after binding and variable allocation. // after binding and variable allocation.
class Variable final : public ZoneObject { class Variable final : public ZoneObject {
public: public:
enum Kind { NORMAL, FUNCTION, THIS, ARGUMENTS }; enum Kind : uint8_t {
NORMAL,
FUNCTION,
THIS,
ARGUMENTS,
kLastKind = ARGUMENTS
};
Variable(Scope* scope, const AstRawString* name, VariableMode mode, Kind kind, Variable(Scope* scope, const AstRawString* name, VariableMode mode, Kind kind,
InitializationFlag initialization_flag, InitializationFlag initialization_flag,
...@@ -105,23 +111,27 @@ class Variable final : public ZoneObject { ...@@ -105,23 +111,27 @@ class Variable final : public ZoneObject {
private: private:
Scope* scope_; Scope* scope_;
const AstRawString* name_; const AstRawString* name_;
VariableMode mode_;
Kind kind_;
VariableLocation location_;
int index_;
int initializer_position_;
// If this field is set, this variable references the stored locally bound // If this field is set, this variable references the stored locally bound
// variable, but it might be shadowed by variable bindings introduced by // variable, but it might be shadowed by variable bindings introduced by
// sloppy 'eval' calls between the reference scope (inclusive) and the // sloppy 'eval' calls between the reference scope (inclusive) and the
// binding scope (exclusive). // binding scope (exclusive).
Variable* local_if_not_shadowed_; Variable* local_if_not_shadowed_;
int index_;
int initializer_position_;
STATIC_ASSERT(kLastVariableMode < (1 << 3));
VariableMode mode_ : 3;
STATIC_ASSERT(kLastKind < (1 << 2));
Kind kind_ : 2;
STATIC_ASSERT(static_cast<uint8_t>(VariableLocation::kLastVariableLocation) <
(1 << 3));
VariableLocation location_ : 3;
// Usage info. // Usage info.
bool force_context_allocation_; // set by variable resolver bool force_context_allocation_ : 1; // set by variable resolver
bool is_used_; bool is_used_ : 1;
InitializationFlag initialization_flag_; InitializationFlag initialization_flag_ : 2;
MaybeAssignedFlag maybe_assigned_; MaybeAssignedFlag maybe_assigned_ : 2;
}; };
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
......
...@@ -878,7 +878,7 @@ const double kMaxSafeInteger = 9007199254740991.0; // 2^53-1 ...@@ -878,7 +878,7 @@ const double kMaxSafeInteger = 9007199254740991.0; // 2^53-1
// The order of this enum has to be kept in sync with the predicates below. // The order of this enum has to be kept in sync with the predicates below.
enum VariableMode { enum VariableMode : uint8_t {
// User declared variables: // User declared variables:
VAR, // declared via 'var', and 'function' declarations VAR, // declared via 'var', and 'function' declarations
...@@ -899,10 +899,12 @@ enum VariableMode { ...@@ -899,10 +899,12 @@ enum VariableMode {
// variable is global unless it has been shadowed // variable is global unless it has been shadowed
// by an eval-introduced variable // by an eval-introduced variable
DYNAMIC_LOCAL // requires dynamic lookup, but we know that the DYNAMIC_LOCAL, // requires dynamic lookup, but we know that the
// variable is local and where it is unless it // variable is local and where it is unless it
// has been shadowed by an eval-introduced // has been shadowed by an eval-introduced
// variable // variable
kLastVariableMode = DYNAMIC_LOCAL
}; };
inline bool IsDynamicVariableMode(VariableMode mode) { inline bool IsDynamicVariableMode(VariableMode mode) {
...@@ -924,7 +926,7 @@ inline bool IsImmutableVariableMode(VariableMode mode) { ...@@ -924,7 +926,7 @@ inline bool IsImmutableVariableMode(VariableMode mode) {
return mode == CONST || mode == CONST_LEGACY; return mode == CONST || mode == CONST_LEGACY;
} }
enum class VariableLocation { enum class VariableLocation : uint8_t {
// Before and during variable allocation, a variable whose location is // Before and during variable allocation, a variable whose location is
// not yet determined. After allocation, a variable looked up as a // not yet determined. After allocation, a variable looked up as a
// property on the global object (and possibly absent). name() is the // property on the global object (and possibly absent). name() is the
...@@ -957,7 +959,9 @@ enum class VariableLocation { ...@@ -957,7 +959,9 @@ enum class VariableLocation {
LOOKUP, LOOKUP,
// A named slot in a module's export table. // A named slot in a module's export table.
MODULE MODULE,
kLastVariableLocation = MODULE
}; };
// ES6 Draft Rev3 10.2 specifies declarative environment records with mutable // ES6 Draft Rev3 10.2 specifies declarative environment records with mutable
...@@ -991,14 +995,9 @@ enum class VariableLocation { ...@@ -991,14 +995,9 @@ enum class VariableLocation {
// The following enum specifies a flag that indicates if the binding needs a // The following enum specifies a flag that indicates if the binding needs a
// distinct initialization step (kNeedsInitialization) or if the binding is // distinct initialization step (kNeedsInitialization) or if the binding is
// immediately initialized upon creation (kCreatedInitialized). // immediately initialized upon creation (kCreatedInitialized).
enum InitializationFlag { enum InitializationFlag : uint8_t { kNeedsInitialization, kCreatedInitialized };
kNeedsInitialization,
kCreatedInitialized
};
enum MaybeAssignedFlag { kNotAssigned, kMaybeAssigned };
enum MaybeAssignedFlag : uint8_t { kNotAssigned, kMaybeAssigned };
// Serialized in PreparseData, so numeric values should not be changed. // Serialized in PreparseData, so numeric values should not be changed.
enum ParseErrorType { kSyntaxError = 0, kReferenceError = 1 }; enum ParseErrorType { kSyntaxError = 0, kReferenceError = 1 };
......
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