2012-01-25 16:31:25 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
2010-02-15 14:24:38 +00:00
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
2010-03-25 12:44:15 +00:00
|
|
|
#ifndef V8_TYPE_INFO_H_
|
|
|
|
#define V8_TYPE_INFO_H_
|
2010-02-15 14:24:38 +00:00
|
|
|
|
2011-05-06 06:50:20 +00:00
|
|
|
#include "allocation.h"
|
2012-03-13 12:11:46 +00:00
|
|
|
#include "ast.h"
|
2010-03-24 15:55:15 +00:00
|
|
|
#include "globals.h"
|
2010-12-07 11:31:57 +00:00
|
|
|
#include "zone-inl.h"
|
2010-03-24 15:55:15 +00:00
|
|
|
|
2010-02-15 14:24:38 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
2011-06-20 10:19:00 +00:00
|
|
|
const int kMaxKeyedPolymorphism = 4;
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
// Unknown
|
2011-04-27 15:02:59 +00:00
|
|
|
// | \____________
|
|
|
|
// | |
|
|
|
|
// Primitive Non-primitive
|
|
|
|
// | \_______ |
|
|
|
|
// | | |
|
|
|
|
// Number String |
|
|
|
|
// / \ | |
|
|
|
|
// Double Integer32 | /
|
|
|
|
// | | / /
|
|
|
|
// | Smi / /
|
|
|
|
// | | / __/
|
|
|
|
// Uninitialized.
|
2010-03-05 23:54:13 +00:00
|
|
|
|
2010-03-25 12:44:15 +00:00
|
|
|
class TypeInfo {
|
2010-02-15 14:24:38 +00:00
|
|
|
public:
|
2010-12-07 11:31:57 +00:00
|
|
|
TypeInfo() : type_(kUninitialized) { }
|
2010-03-05 23:54:13 +00:00
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
static TypeInfo Unknown() { return TypeInfo(kUnknown); }
|
2010-03-24 12:34:27 +00:00
|
|
|
// We know it's a primitive type.
|
2010-12-07 11:31:57 +00:00
|
|
|
static TypeInfo Primitive() { return TypeInfo(kPrimitive); }
|
2010-03-05 23:54:13 +00:00
|
|
|
// We know it's a number of some sort.
|
2010-12-07 11:31:57 +00:00
|
|
|
static TypeInfo Number() { return TypeInfo(kNumber); }
|
|
|
|
// We know it's a signed 32 bit integer.
|
|
|
|
static TypeInfo Integer32() { return TypeInfo(kInteger32); }
|
2010-03-05 23:54:13 +00:00
|
|
|
// We know it's a Smi.
|
2010-12-07 11:31:57 +00:00
|
|
|
static TypeInfo Smi() { return TypeInfo(kSmi); }
|
2011-11-17 13:57:55 +00:00
|
|
|
// We know it's a Symbol.
|
|
|
|
static TypeInfo Symbol() { return TypeInfo(kSymbol); }
|
2010-03-05 23:54:13 +00:00
|
|
|
// We know it's a heap number.
|
2010-12-07 11:31:57 +00:00
|
|
|
static TypeInfo Double() { return TypeInfo(kDouble); }
|
2010-03-24 12:34:27 +00:00
|
|
|
// We know it's a string.
|
2010-12-07 11:31:57 +00:00
|
|
|
static TypeInfo String() { return TypeInfo(kString); }
|
|
|
|
// We know it's a non-primitive (object) type.
|
|
|
|
static TypeInfo NonPrimitive() { return TypeInfo(kNonPrimitive); }
|
2010-03-05 23:54:13 +00:00
|
|
|
// We haven't started collecting info yet.
|
2010-12-07 11:31:57 +00:00
|
|
|
static TypeInfo Uninitialized() { return TypeInfo(kUninitialized); }
|
2010-03-05 23:54:13 +00:00
|
|
|
|
|
|
|
int ToInt() {
|
|
|
|
return type_;
|
|
|
|
}
|
|
|
|
|
2010-03-25 12:44:15 +00:00
|
|
|
static TypeInfo FromInt(int bit_representation) {
|
2010-03-05 23:54:13 +00:00
|
|
|
Type t = static_cast<Type>(bit_representation);
|
2010-12-07 11:31:57 +00:00
|
|
|
ASSERT(t == kUnknown ||
|
|
|
|
t == kPrimitive ||
|
|
|
|
t == kNumber ||
|
|
|
|
t == kInteger32 ||
|
|
|
|
t == kSmi ||
|
|
|
|
t == kDouble ||
|
|
|
|
t == kString ||
|
|
|
|
t == kNonPrimitive);
|
2010-03-25 12:44:15 +00:00
|
|
|
return TypeInfo(t);
|
2010-03-05 23:54:13 +00:00
|
|
|
}
|
2010-02-15 14:24:38 +00:00
|
|
|
|
|
|
|
// Return the weakest (least precise) common type.
|
2010-03-25 12:44:15 +00:00
|
|
|
static TypeInfo Combine(TypeInfo a, TypeInfo b) {
|
|
|
|
return TypeInfo(static_cast<Type>(a.type_ & b.type_));
|
2010-03-05 23:54:13 +00:00
|
|
|
}
|
|
|
|
|
2010-03-24 15:29:41 +00:00
|
|
|
|
2011-02-03 15:36:44 +00:00
|
|
|
// Integer32 is an integer that can be represented as a signed
|
|
|
|
// 32-bit integer. It has to be
|
|
|
|
// in the range [-2^31, 2^31 - 1]. We also have to check for negative 0
|
2010-12-07 11:31:57 +00:00
|
|
|
// as it is not an Integer32.
|
2010-03-24 15:29:41 +00:00
|
|
|
static inline bool IsInt32Double(double value) {
|
2010-03-24 16:37:27 +00:00
|
|
|
const DoubleRepresentation minus_zero(-0.0);
|
|
|
|
DoubleRepresentation rep(value);
|
|
|
|
if (rep.bits == minus_zero.bits) return false;
|
2010-12-07 11:31:57 +00:00
|
|
|
if (value >= kMinInt && value <= kMaxInt &&
|
|
|
|
value == static_cast<int32_t>(value)) {
|
|
|
|
return true;
|
2010-03-24 15:29:41 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-03-26 11:34:00 +00:00
|
|
|
static TypeInfo TypeFromValue(Handle<Object> value);
|
2010-03-24 15:29:41 +00:00
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
bool Equals(const TypeInfo& other) {
|
|
|
|
return type_ == other.type_;
|
|
|
|
}
|
|
|
|
|
2010-03-05 23:54:13 +00:00
|
|
|
inline bool IsUnknown() {
|
2010-12-07 11:31:57 +00:00
|
|
|
ASSERT(type_ != kUninitialized);
|
|
|
|
return type_ == kUnknown;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool IsPrimitive() {
|
|
|
|
ASSERT(type_ != kUninitialized);
|
|
|
|
return ((type_ & kPrimitive) == kPrimitive);
|
2010-03-05 23:54:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool IsNumber() {
|
2010-12-07 11:31:57 +00:00
|
|
|
ASSERT(type_ != kUninitialized);
|
|
|
|
return ((type_ & kNumber) == kNumber);
|
2010-03-05 23:54:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool IsSmi() {
|
2010-12-07 11:31:57 +00:00
|
|
|
ASSERT(type_ != kUninitialized);
|
|
|
|
return ((type_ & kSmi) == kSmi);
|
2010-03-05 23:54:13 +00:00
|
|
|
}
|
|
|
|
|
2011-11-17 13:57:55 +00:00
|
|
|
inline bool IsSymbol() {
|
|
|
|
ASSERT(type_ != kUninitialized);
|
|
|
|
return ((type_ & kSymbol) == kSymbol);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool IsNonSymbol() {
|
|
|
|
ASSERT(type_ != kUninitialized);
|
|
|
|
return ((type_ & kSymbol) == kString);
|
|
|
|
}
|
|
|
|
|
2010-03-05 23:54:13 +00:00
|
|
|
inline bool IsInteger32() {
|
2010-12-07 11:31:57 +00:00
|
|
|
ASSERT(type_ != kUninitialized);
|
|
|
|
return ((type_ & kInteger32) == kInteger32);
|
2010-03-05 23:54:13 +00:00
|
|
|
}
|
|
|
|
|
2010-03-24 15:29:41 +00:00
|
|
|
inline bool IsDouble() {
|
2010-12-07 11:31:57 +00:00
|
|
|
ASSERT(type_ != kUninitialized);
|
|
|
|
return ((type_ & kDouble) == kDouble);
|
2010-02-15 14:24:38 +00:00
|
|
|
}
|
2010-02-16 13:03:16 +00:00
|
|
|
|
2010-03-29 11:48:57 +00:00
|
|
|
inline bool IsString() {
|
2010-12-07 11:31:57 +00:00
|
|
|
ASSERT(type_ != kUninitialized);
|
|
|
|
return ((type_ & kString) == kString);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool IsNonPrimitive() {
|
|
|
|
ASSERT(type_ != kUninitialized);
|
|
|
|
return ((type_ & kNonPrimitive) == kNonPrimitive);
|
2010-03-29 11:48:57 +00:00
|
|
|
}
|
|
|
|
|
2010-03-05 23:54:13 +00:00
|
|
|
inline bool IsUninitialized() {
|
2010-12-07 11:31:57 +00:00
|
|
|
return type_ == kUninitialized;
|
2010-02-16 13:03:16 +00:00
|
|
|
}
|
|
|
|
|
2010-03-05 23:54:13 +00:00
|
|
|
const char* ToString() {
|
|
|
|
switch (type_) {
|
2010-12-07 11:31:57 +00:00
|
|
|
case kUnknown: return "Unknown";
|
|
|
|
case kPrimitive: return "Primitive";
|
|
|
|
case kNumber: return "Number";
|
|
|
|
case kInteger32: return "Integer32";
|
|
|
|
case kSmi: return "Smi";
|
2011-11-17 13:57:55 +00:00
|
|
|
case kSymbol: return "Symbol";
|
2010-12-07 11:31:57 +00:00
|
|
|
case kDouble: return "Double";
|
|
|
|
case kString: return "String";
|
|
|
|
case kNonPrimitive: return "Object";
|
|
|
|
case kUninitialized: return "Uninitialized";
|
2010-02-16 13:03:16 +00:00
|
|
|
}
|
|
|
|
UNREACHABLE();
|
|
|
|
return "Unreachable code";
|
|
|
|
}
|
2010-03-05 23:54:13 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
enum Type {
|
2010-12-07 11:31:57 +00:00
|
|
|
kUnknown = 0, // 0000000
|
|
|
|
kPrimitive = 0x10, // 0010000
|
|
|
|
kNumber = 0x11, // 0010001
|
|
|
|
kInteger32 = 0x13, // 0010011
|
|
|
|
kSmi = 0x17, // 0010111
|
|
|
|
kDouble = 0x19, // 0011001
|
|
|
|
kString = 0x30, // 0110000
|
2011-11-17 13:57:55 +00:00
|
|
|
kSymbol = 0x32, // 0110010
|
2010-12-07 11:31:57 +00:00
|
|
|
kNonPrimitive = 0x40, // 1000000
|
|
|
|
kUninitialized = 0x7f // 1111111
|
2010-03-05 23:54:13 +00:00
|
|
|
};
|
2012-11-14 15:59:45 +00:00
|
|
|
|
2010-03-25 12:44:15 +00:00
|
|
|
explicit inline TypeInfo(Type t) : type_(t) { }
|
2010-03-05 23:54:13 +00:00
|
|
|
|
|
|
|
Type type_;
|
2010-02-15 14:24:38 +00:00
|
|
|
};
|
|
|
|
|
2010-03-05 23:54:13 +00:00
|
|
|
|
2011-01-18 16:54:48 +00:00
|
|
|
enum StringStubFeedback {
|
|
|
|
DEFAULT_STRING_STUB = 0,
|
|
|
|
STRING_INDEX_OUT_OF_BOUNDS = 1
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
// Forward declarations.
|
|
|
|
class Assignment;
|
|
|
|
class BinaryOperation;
|
|
|
|
class Call;
|
2012-01-27 13:03:19 +00:00
|
|
|
class CallNew;
|
2011-08-22 14:23:37 +00:00
|
|
|
class CaseClause;
|
2010-12-07 11:31:57 +00:00
|
|
|
class CompareOperation;
|
|
|
|
class CompilationInfo;
|
2011-08-22 14:23:37 +00:00
|
|
|
class CountOperation;
|
2012-01-25 16:31:25 +00:00
|
|
|
class Expression;
|
2010-12-07 11:31:57 +00:00
|
|
|
class Property;
|
2011-08-22 14:23:37 +00:00
|
|
|
class SmallMapList;
|
|
|
|
class UnaryOperation;
|
2012-03-02 11:33:33 +00:00
|
|
|
class ForInStatement;
|
2011-08-22 14:23:37 +00:00
|
|
|
|
2010-03-05 23:54:13 +00:00
|
|
|
|
2012-07-17 16:24:40 +00:00
|
|
|
class TypeFeedbackOracle: public ZoneObject {
|
2010-12-07 11:31:57 +00:00
|
|
|
public:
|
2011-10-10 09:21:48 +00:00
|
|
|
TypeFeedbackOracle(Handle<Code> code,
|
2012-08-17 09:03:08 +00:00
|
|
|
Handle<Context> native_context,
|
2012-06-11 12:42:31 +00:00
|
|
|
Isolate* isolate,
|
|
|
|
Zone* zone);
|
2010-03-24 12:34:27 +00:00
|
|
|
|
2011-06-16 06:37:49 +00:00
|
|
|
bool LoadIsMonomorphicNormal(Property* expr);
|
2012-03-19 15:54:37 +00:00
|
|
|
bool LoadIsUninitialized(Property* expr);
|
2011-06-20 10:19:00 +00:00
|
|
|
bool LoadIsMegamorphicWithTypeInfo(Property* expr);
|
2012-08-06 14:13:09 +00:00
|
|
|
bool StoreIsMonomorphicNormal(TypeFeedbackId ast_id);
|
|
|
|
bool StoreIsMegamorphicWithTypeInfo(TypeFeedbackId ast_id);
|
2010-12-07 11:31:57 +00:00
|
|
|
bool CallIsMonomorphic(Call* expr);
|
2012-01-27 13:03:19 +00:00
|
|
|
bool CallNewIsMonomorphic(CallNew* expr);
|
2012-03-13 12:11:46 +00:00
|
|
|
bool ObjectLiteralStoreIsMonomorphic(ObjectLiteral::Property* prop);
|
2010-03-24 12:34:27 +00:00
|
|
|
|
2012-03-02 11:33:33 +00:00
|
|
|
bool IsForInFastCase(ForInStatement* expr);
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
Handle<Map> LoadMonomorphicReceiverType(Property* expr);
|
2012-08-06 14:13:09 +00:00
|
|
|
Handle<Map> StoreMonomorphicReceiverType(TypeFeedbackId ast_id);
|
2010-03-05 23:54:13 +00:00
|
|
|
|
2011-08-22 14:23:37 +00:00
|
|
|
void LoadReceiverTypes(Property* expr,
|
|
|
|
Handle<String> name,
|
|
|
|
SmallMapList* types);
|
|
|
|
void StoreReceiverTypes(Assignment* expr,
|
|
|
|
Handle<String> name,
|
|
|
|
SmallMapList* types);
|
|
|
|
void CallReceiverTypes(Call* expr,
|
|
|
|
Handle<String> name,
|
|
|
|
CallKind call_kind,
|
|
|
|
SmallMapList* types);
|
2012-08-06 14:13:09 +00:00
|
|
|
void CollectKeyedReceiverTypes(TypeFeedbackId ast_id,
|
2011-08-22 14:23:37 +00:00
|
|
|
SmallMapList* types);
|
2010-03-05 23:54:13 +00:00
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
static bool CanRetainOtherContext(Map* map, Context* native_context);
|
2011-12-14 14:01:54 +00:00
|
|
|
static bool CanRetainOtherContext(JSFunction* function,
|
2012-08-17 09:03:08 +00:00
|
|
|
Context* native_context);
|
2011-12-14 14:01:54 +00:00
|
|
|
|
2011-01-13 14:16:08 +00:00
|
|
|
CheckType GetCallCheckType(Call* expr);
|
|
|
|
Handle<JSObject> GetPrototypeForPrimitiveCheck(CheckType check);
|
|
|
|
|
2011-09-27 11:42:02 +00:00
|
|
|
Handle<JSFunction> GetCallTarget(Call* expr);
|
2012-02-28 09:05:55 +00:00
|
|
|
Handle<JSFunction> GetCallNewTarget(CallNew* expr);
|
2011-09-27 11:42:02 +00:00
|
|
|
|
2012-03-13 12:11:46 +00:00
|
|
|
Handle<Map> GetObjectLiteralStoreMap(ObjectLiteral::Property* prop);
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
bool LoadIsBuiltin(Property* expr, Builtins::Name id);
|
2010-03-05 23:54:13 +00:00
|
|
|
|
2011-07-25 14:08:36 +00:00
|
|
|
// TODO(1571) We can't use ToBooleanStub::Types as the return value because
|
|
|
|
// of various cylces in our headers. Death to tons of implementations in
|
|
|
|
// headers!! :-P
|
2012-08-06 14:13:09 +00:00
|
|
|
byte ToBooleanTypes(TypeFeedbackId ast_id);
|
2011-07-25 14:08:36 +00:00
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
// Get type information for arithmetic operations and compares.
|
2011-04-28 17:49:55 +00:00
|
|
|
TypeInfo UnaryType(UnaryOperation* expr);
|
2012-11-14 15:59:45 +00:00
|
|
|
void BinaryType(BinaryOperation* expr,
|
|
|
|
TypeInfo* left,
|
|
|
|
TypeInfo* right,
|
|
|
|
TypeInfo* result);
|
|
|
|
void CompareType(CompareOperation* expr,
|
|
|
|
TypeInfo* left_type,
|
|
|
|
TypeInfo* right_type,
|
|
|
|
TypeInfo* overall_type);
|
2011-12-09 09:26:14 +00:00
|
|
|
Handle<Map> GetCompareMap(CompareOperation* expr);
|
2010-12-07 11:31:57 +00:00
|
|
|
TypeInfo SwitchType(CaseClause* clause);
|
2011-04-29 09:21:18 +00:00
|
|
|
TypeInfo IncrementType(CountOperation* expr);
|
2010-03-05 23:54:13 +00:00
|
|
|
|
2012-06-11 12:42:31 +00:00
|
|
|
Zone* zone() const { return zone_; }
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
private:
|
2012-08-06 14:13:09 +00:00
|
|
|
void CollectReceiverTypes(TypeFeedbackId ast_id,
|
2011-08-22 14:23:37 +00:00
|
|
|
Handle<String> name,
|
|
|
|
Code::Flags flags,
|
|
|
|
SmallMapList* types);
|
2010-03-05 23:54:13 +00:00
|
|
|
|
2012-08-06 14:13:09 +00:00
|
|
|
void SetInfo(TypeFeedbackId ast_id, Object* target);
|
2011-03-30 15:31:16 +00:00
|
|
|
|
2011-06-20 12:33:08 +00:00
|
|
|
void BuildDictionary(Handle<Code> code);
|
|
|
|
void GetRelocInfos(Handle<Code> code, ZoneList<RelocInfo>* infos);
|
|
|
|
void CreateDictionary(Handle<Code> code, ZoneList<RelocInfo>* infos);
|
|
|
|
void RelocateRelocInfos(ZoneList<RelocInfo>* infos,
|
|
|
|
byte* old_start,
|
|
|
|
byte* new_start);
|
|
|
|
void ProcessRelocInfos(ZoneList<RelocInfo>* infos);
|
2012-01-27 13:03:19 +00:00
|
|
|
void ProcessTypeFeedbackCells(Handle<Code> code);
|
2010-03-24 12:34:27 +00:00
|
|
|
|
2011-03-07 16:09:56 +00:00
|
|
|
// Returns an element from the backing store. Returns undefined if
|
|
|
|
// there is no information.
|
2012-08-06 14:13:09 +00:00
|
|
|
Handle<Object> GetInfo(TypeFeedbackId ast_id);
|
2011-03-07 16:09:56 +00:00
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
Handle<Context> native_context_;
|
2011-10-10 09:21:48 +00:00
|
|
|
Isolate* isolate_;
|
2012-01-16 09:44:35 +00:00
|
|
|
Handle<UnseededNumberDictionary> dictionary_;
|
2012-06-11 12:42:31 +00:00
|
|
|
Zone* zone_;
|
2010-03-24 12:34:27 +00:00
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(TypeFeedbackOracle);
|
|
|
|
};
|
2010-03-05 23:54:13 +00:00
|
|
|
|
2010-02-15 14:24:38 +00:00
|
|
|
} } // namespace v8::internal
|
|
|
|
|
2010-03-25 12:44:15 +00:00
|
|
|
#endif // V8_TYPE_INFO_H_
|