v8  3.14.5(node0.10.28)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
type-info.h
Go to the documentation of this file.
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 #ifndef V8_TYPE_INFO_H_
29 #define V8_TYPE_INFO_H_
30 
31 #include "allocation.h"
32 #include "ast.h"
33 #include "globals.h"
34 #include "zone-inl.h"
35 
36 namespace v8 {
37 namespace internal {
38 
39 const int kMaxKeyedPolymorphism = 4;
40 
41 // Unknown
42 // | \____________
43 // | |
44 // Primitive Non-primitive
45 // | \_______ |
46 // | | |
47 // Number String |
48 // / \ | |
49 // Double Integer32 | /
50 // | | / /
51 // | Smi / /
52 // | | / __/
53 // Uninitialized.
54 
55 class TypeInfo {
56  public:
57  TypeInfo() : type_(kUninitialized) { }
58 
59  static TypeInfo Unknown() { return TypeInfo(kUnknown); }
60  // We know it's a primitive type.
61  static TypeInfo Primitive() { return TypeInfo(kPrimitive); }
62  // We know it's a number of some sort.
63  static TypeInfo Number() { return TypeInfo(kNumber); }
64  // We know it's a signed 32 bit integer.
65  static TypeInfo Integer32() { return TypeInfo(kInteger32); }
66  // We know it's a Smi.
67  static TypeInfo Smi() { return TypeInfo(kSmi); }
68  // We know it's a Symbol.
69  static TypeInfo Symbol() { return TypeInfo(kSymbol); }
70  // We know it's a heap number.
71  static TypeInfo Double() { return TypeInfo(kDouble); }
72  // We know it's a string.
73  static TypeInfo String() { return TypeInfo(kString); }
74  // We know it's a non-primitive (object) type.
75  static TypeInfo NonPrimitive() { return TypeInfo(kNonPrimitive); }
76  // We haven't started collecting info yet.
77  static TypeInfo Uninitialized() { return TypeInfo(kUninitialized); }
78 
79  int ToInt() {
80  return type_;
81  }
82 
83  static TypeInfo FromInt(int bit_representation) {
84  Type t = static_cast<Type>(bit_representation);
85  ASSERT(t == kUnknown ||
86  t == kPrimitive ||
87  t == kNumber ||
88  t == kInteger32 ||
89  t == kSmi ||
90  t == kDouble ||
91  t == kString ||
92  t == kNonPrimitive);
93  return TypeInfo(t);
94  }
95 
96  // Return the weakest (least precise) common type.
98  return TypeInfo(static_cast<Type>(a.type_ & b.type_));
99  }
100 
101 
102  // Integer32 is an integer that can be represented as a signed
103  // 32-bit integer. It has to be
104  // in the range [-2^31, 2^31 - 1]. We also have to check for negative 0
105  // as it is not an Integer32.
106  static inline bool IsInt32Double(double value) {
107  const DoubleRepresentation minus_zero(-0.0);
108  DoubleRepresentation rep(value);
109  if (rep.bits == minus_zero.bits) return false;
110  if (value >= kMinInt && value <= kMaxInt &&
111  value == static_cast<int32_t>(value)) {
112  return true;
113  }
114  return false;
115  }
116 
117  static TypeInfo TypeFromValue(Handle<Object> value);
118 
119  bool Equals(const TypeInfo& other) {
120  return type_ == other.type_;
121  }
122 
123  inline bool IsUnknown() {
124  ASSERT(type_ != kUninitialized);
125  return type_ == kUnknown;
126  }
127 
128  inline bool IsPrimitive() {
129  ASSERT(type_ != kUninitialized);
130  return ((type_ & kPrimitive) == kPrimitive);
131  }
132 
133  inline bool IsNumber() {
134  ASSERT(type_ != kUninitialized);
135  return ((type_ & kNumber) == kNumber);
136  }
137 
138  inline bool IsSmi() {
139  ASSERT(type_ != kUninitialized);
140  return ((type_ & kSmi) == kSmi);
141  }
142 
143  inline bool IsSymbol() {
144  ASSERT(type_ != kUninitialized);
145  return ((type_ & kSymbol) == kSymbol);
146  }
147 
148  inline bool IsNonSymbol() {
149  ASSERT(type_ != kUninitialized);
150  return ((type_ & kSymbol) == kString);
151  }
152 
153  inline bool IsInteger32() {
154  ASSERT(type_ != kUninitialized);
155  return ((type_ & kInteger32) == kInteger32);
156  }
157 
158  inline bool IsDouble() {
159  ASSERT(type_ != kUninitialized);
160  return ((type_ & kDouble) == kDouble);
161  }
162 
163  inline bool IsString() {
164  ASSERT(type_ != kUninitialized);
165  return ((type_ & kString) == kString);
166  }
167 
168  inline bool IsNonPrimitive() {
169  ASSERT(type_ != kUninitialized);
170  return ((type_ & kNonPrimitive) == kNonPrimitive);
171  }
172 
173  inline bool IsUninitialized() {
174  return type_ == kUninitialized;
175  }
176 
177  const char* ToString() {
178  switch (type_) {
179  case kUnknown: return "Unknown";
180  case kPrimitive: return "Primitive";
181  case kNumber: return "Number";
182  case kInteger32: return "Integer32";
183  case kSmi: return "Smi";
184  case kSymbol: return "Symbol";
185  case kDouble: return "Double";
186  case kString: return "String";
187  case kNonPrimitive: return "Object";
188  case kUninitialized: return "Uninitialized";
189  }
190  UNREACHABLE();
191  return "Unreachable code";
192  }
193 
194  private:
195  enum Type {
196  kUnknown = 0, // 0000000
197  kPrimitive = 0x10, // 0010000
198  kNumber = 0x11, // 0010001
199  kInteger32 = 0x13, // 0010011
200  kSmi = 0x17, // 0010111
201  kDouble = 0x19, // 0011001
202  kString = 0x30, // 0110000
203  kSymbol = 0x32, // 0110010
204  kNonPrimitive = 0x40, // 1000000
205  kUninitialized = 0x7f // 1111111
206  };
207  explicit inline TypeInfo(Type t) : type_(t) { }
208 
209  Type type_;
210 };
211 
212 
216 };
217 
218 
219 // Forward declarations.
220 class Assignment;
221 class BinaryOperation;
222 class Call;
223 class CallNew;
224 class CaseClause;
225 class CompareOperation;
226 class CompilationInfo;
227 class CountOperation;
228 class Expression;
229 class Property;
230 class SmallMapList;
231 class UnaryOperation;
232 class ForInStatement;
233 
234 
236  public:
238  Handle<Context> native_context,
239  Isolate* isolate,
240  Zone* zone);
241 
242  bool LoadIsMonomorphicNormal(Property* expr);
243  bool LoadIsUninitialized(Property* expr);
247  bool CallIsMonomorphic(Call* expr);
248  bool CallNewIsMonomorphic(CallNew* expr);
250 
251  bool IsForInFastCase(ForInStatement* expr);
252 
255 
256  void LoadReceiverTypes(Property* expr,
257  Handle<String> name,
258  SmallMapList* types);
259  void StoreReceiverTypes(Assignment* expr,
260  Handle<String> name,
261  SmallMapList* types);
262  void CallReceiverTypes(Call* expr,
263  Handle<String> name,
264  CallKind call_kind,
265  SmallMapList* types);
267  SmallMapList* types);
268 
269  static bool CanRetainOtherContext(Map* map, Context* native_context);
270  static bool CanRetainOtherContext(JSFunction* function,
271  Context* native_context);
272 
275 
278 
280 
281  bool LoadIsBuiltin(Property* expr, Builtins::Name id);
282 
283  // TODO(1571) We can't use ToBooleanStub::Types as the return value because
284  // of various cylces in our headers. Death to tons of implementations in
285  // headers!! :-P
287 
288  // Get type information for arithmetic operations and compares.
292  bool IsSymbolCompare(CompareOperation* expr);
294  TypeInfo SwitchType(CaseClause* clause);
296 
297  Zone* zone() const { return zone_; }
298 
299  private:
300  void CollectReceiverTypes(TypeFeedbackId ast_id,
301  Handle<String> name,
303  SmallMapList* types);
304 
305  void SetInfo(TypeFeedbackId ast_id, Object* target);
306 
307  void BuildDictionary(Handle<Code> code);
308  void GetRelocInfos(Handle<Code> code, ZoneList<RelocInfo>* infos);
309  void CreateDictionary(Handle<Code> code, ZoneList<RelocInfo>* infos);
310  void RelocateRelocInfos(ZoneList<RelocInfo>* infos,
311  byte* old_start,
312  byte* new_start);
313  void ProcessRelocInfos(ZoneList<RelocInfo>* infos);
314  void ProcessTypeFeedbackCells(Handle<Code> code);
315 
316  // Returns an element from the backing store. Returns undefined if
317  // there is no information.
318  Handle<Object> GetInfo(TypeFeedbackId ast_id);
319 
320  Handle<Context> native_context_;
321  Isolate* isolate_;
323  Zone* zone_;
324 
325  DISALLOW_COPY_AND_ASSIGN(TypeFeedbackOracle);
326 };
327 
328 } } // namespace v8::internal
329 
330 #endif // V8_TYPE_INFO_H_
static TypeInfo Combine(TypeInfo a, TypeInfo b)
Definition: type-info.h:97
const int kMinInt
Definition: globals.h:211
Handle< JSFunction > GetCallNewTarget(CallNew *expr)
Definition: type-info.cc:297
Handle< Map > GetCompareMap(CompareOperation *expr)
Definition: type-info.cc:355
const char * ToString()
Definition: type-info.h:177
static bool IsInt32Double(double value)
Definition: type-info.h:106
void CollectKeyedReceiverTypes(TypeFeedbackId ast_id, SmallMapList *types)
Definition: type-info.cc:574
static TypeInfo NonPrimitive()
Definition: type-info.h:75
bool IsForInFastCase(ForInStatement *expr)
Definition: type-info.cc:185
static bool CanRetainOtherContext(Map *map, Context *native_context)
Definition: type-info.cc:534
static TypeInfo Number()
Definition: type-info.h:63
static TypeInfo Unknown()
Definition: type-info.h:59
static TypeInfo Primitive()
Definition: type-info.h:61
static TypeInfo Double()
Definition: type-info.h:71
const int kMaxInt
Definition: globals.h:210
Handle< Map > LoadMonomorphicReceiverType(Property *expr)
Definition: type-info.cc:192
#define ASSERT(condition)
Definition: checks.h:270
bool StoreIsMonomorphicNormal(TypeFeedbackId ast_id)
Definition: type-info.cc:127
TypeInfo IncrementType(CountOperation *expr)
Definition: type-info.cc:475
static TypeInfo TypeFromValue(Handle< Object > value)
Definition: type-info.cc:45
static TypeInfo Smi()
Definition: type-info.h:67
void CallReceiverTypes(Call *expr, Handle< String > name, CallKind call_kind, SmallMapList *types)
Definition: type-info.cc:241
void LoadReceiverTypes(Property *expr, Handle< String > name, SmallMapList *types)
Definition: type-info.cc:223
uint8_t byte
Definition: globals.h:156
TypeInfo SwitchType(CaseClause *clause)
Definition: type-info.cc:443
#define UNREACHABLE()
Definition: checks.h:50
static TypeInfo String()
Definition: type-info.h:73
static TypeInfo Integer32()
Definition: type-info.h:65
CheckType GetCallCheckType(Call *expr)
Definition: type-info.cc:261
static TypeInfo Symbol()
Definition: type-info.h:69
bool StoreIsMegamorphicWithTypeInfo(TypeFeedbackId ast_id)
Definition: type-info.cc:148
Handle< JSObject > GetPrototypeForPrimitiveCheck(CheckType check)
Definition: type-info.cc:270
Handle< Map > StoreMonomorphicReceiverType(TypeFeedbackId ast_id)
Definition: type-info.cc:207
bool LoadIsUninitialized(Property *expr)
Definition: type-info.cc:87
bool Equals(const TypeInfo &other)
Definition: type-info.h:119
TypeInfo CompareType(CompareOperation *expr)
Definition: type-info.cc:315
static TypeInfo FromInt(int bit_representation)
Definition: type-info.h:83
TypeInfo BinaryType(BinaryOperation *expr)
Definition: type-info.cc:391
byte ToBooleanTypes(TypeFeedbackId ast_id)
Definition: type-info.cc:597
Handle< Map > GetObjectLiteralStoreMap(ObjectLiteral::Property *prop)
Definition: type-info.cc:302
bool LoadIsBuiltin(Property *expr, Builtins::Name id)
Definition: type-info.cc:309
TypeFeedbackOracle(Handle< Code > code, Handle< Context > native_context, Isolate *isolate, Zone *zone)
Definition: type-info.cc:62
static TypeInfo Uninitialized()
Definition: type-info.h:77
void StoreReceiverTypes(Assignment *expr, Handle< String > name, SmallMapList *types)
Definition: type-info.cc:232
bool CallIsMonomorphic(Call *expr)
Definition: type-info.cc:166
bool IsSymbolCompare(CompareOperation *expr)
Definition: type-info.cc:345
Handle< JSFunction > GetCallTarget(Call *expr)
Definition: type-info.cc:292
bool ObjectLiteralStoreIsMonomorphic(ObjectLiteral::Property *prop)
Definition: type-info.cc:178
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra code(assertions) for debugging") DEFINE_bool(code_comments
const int kMaxKeyedPolymorphism
Definition: type-info.h:39
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of SAHF instruction if enable use of VFP3 instructions if available this implies enabling ARMv7 and VFP2 enable use of VFP2 instructions if available enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of MIPS FPU instructions if expose natives in global object expose gc extension number of stack frames to capture disable builtin natives files print a stack trace if an assertion failure occurs use random jit cookie to mask large constants trace lazy optimization use adaptive optimizations prepare for turning on always opt minimum length for automatic enable preparsing maximum number of optimization attempts before giving up cache prototype transitions automatically set the debug break flag when debugger commands are in the queue always cause a debug break before aborting maximum length of function source code printed in a stack trace max size of the new max size of the old max size of executable always perform global GCs print one trace line following each garbage collection do not print trace line after scavenger collection print more details following each garbage collection print amount of external allocated memory after each time it is adjusted flush code that we expect not to use again before full gc do incremental marking steps track object counts and memory usage use caching Perform compaction on every full GC Never perform compaction on full GC testing only Compact code space on full incremental collections Default seed for initializing random allows verbose printing trace parsing and preparsing Check icache flushes in ARM and MIPS simulator Stack alingment in bytes in print stack trace when throwing exceptions randomize hashes to avoid predictable hash Fixed seed to use to hash property activate a timer that switches between V8 threads testing_bool_flag float flag Seed used for threading test randomness A filename with extra code to be included in the Print usage including flags
Definition: flags.cc:495
bool LoadIsMonomorphicNormal(Property *expr)
Definition: type-info.cc:98
bool LoadIsMegamorphicWithTypeInfo(Property *expr)
Definition: type-info.cc:114
void check(i::Vector< const char > string)
TypeInfo UnaryType(UnaryOperation *expr)
Definition: type-info.cc:372
bool CallNewIsMonomorphic(CallNew *expr)
Definition: type-info.cc:172