OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 1029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1040 Token::Value op_; | 1040 Token::Value op_; |
1041 CompareIC::State left_; | 1041 CompareIC::State left_; |
1042 CompareIC::State right_; | 1042 CompareIC::State right_; |
1043 CompareIC::State state_; | 1043 CompareIC::State state_; |
1044 Handle<Map> known_map_; | 1044 Handle<Map> known_map_; |
1045 }; | 1045 }; |
1046 | 1046 |
1047 | 1047 |
1048 class CompareNilICStub : public HydrogenCodeStub { | 1048 class CompareNilICStub : public HydrogenCodeStub { |
1049 public: | 1049 public: |
1050 enum Types { | 1050 enum Type { |
1051 kCompareAgainstNull = 1 << 0, | 1051 UNDEFINED, |
1052 kCompareAgainstUndefined = 1 << 1, | 1052 NULL_TYPE, |
1053 kCompareAgainstMonomorphicMap = 1 << 2, | 1053 MONOMORPHIC_MAP, |
1054 kCompareAgainstUndetectable = 1 << 3, | 1054 UNDETECTABLE, |
1055 kFullCompare = kCompareAgainstNull | kCompareAgainstUndefined | | 1055 NUMBER_OF_TYPES |
1056 kCompareAgainstUndetectable | |
1057 }; | 1056 }; |
1058 | 1057 |
1058 class Types : public EnumSet<Type, byte> { | |
1059 public: | |
1060 Types() : EnumSet<Type, byte>(0) { } | |
1061 explicit Types(byte bits) : EnumSet<Type, byte>(bits) { } | |
1062 | |
1063 static const Types FullCompare() { | |
Sven Panne
2013/05/14 09:18:42
No need for "const" here, we have an implicit copy
| |
1064 Types set; | |
1065 set.Add(UNDEFINED); | |
1066 set.Add(NULL_TYPE); | |
1067 set.Add(UNDETECTABLE); | |
1068 return set; | |
1069 } | |
1070 | |
1071 bool IsFullCompare() const { | |
Sven Panne
2013/05/14 09:18:42
No need for this function, we have FullCompare() a
| |
1072 return this->ToByte() == FullCompare().ToByte(); | |
1073 } | |
1074 | |
1075 void SetTo(Type type); | |
Sven Panne
2013/05/14 09:18:42
We don't need this, pretending that Types is immut
| |
1076 byte ToByte() const { return ToIntegral(); } | |
Sven Panne
2013/05/14 09:18:42
Remove this, just use ToIntegral().
| |
1077 | |
1078 void Print(StringStream* stream) const; | |
1079 }; | |
1080 | |
1081 // At most 6 different types can be distinguished, because the Code object | |
1082 // only has room for a single byte to hold a set and there are two more | |
1083 // boolean flags we need to store. :-P | |
1084 STATIC_ASSERT(NUMBER_OF_TYPES <= 6); | |
1085 | |
1059 CompareNilICStub(EqualityKind kind, NilValue nil, Types types) | 1086 CompareNilICStub(EqualityKind kind, NilValue nil, Types types) |
1060 : HydrogenCodeStub(CODE_STUB_IS_NOT_MISS), bit_field_(0) { | 1087 : HydrogenCodeStub(CODE_STUB_IS_NOT_MISS), types_(types) { |
1061 bit_field_ = EqualityKindField::encode(kind) | | 1088 equality_kind_ = kind; |
1062 NilValueField::encode(nil) | | 1089 nil_value_ = nil; |
1063 TypesField::encode(types); | |
1064 } | 1090 } |
1065 | 1091 |
1066 virtual InlineCacheState GetICState() { | 1092 explicit CompareNilICStub(Code::ExtraICState ic_state) |
1067 Types types = GetTypes(); | 1093 : HydrogenCodeStub(CODE_STUB_IS_NOT_MISS) { |
1068 if (types == kFullCompare) { | 1094 equality_kind_ = EqualityKindField::decode(ic_state); |
1069 return MEGAMORPHIC; | 1095 nil_value_ = NilValueField::decode(ic_state); |
1070 } else if ((types & kCompareAgainstMonomorphicMap) != 0) { | 1096 types_ = Types(ExtractTypesFromExtraICState(ic_state)); |
1071 return MONOMORPHIC; | |
1072 } else { | |
1073 return PREMONOMORPHIC; | |
1074 } | |
1075 } | 1097 } |
1076 | 1098 |
1077 virtual Code::Kind GetCodeKind() const { return Code::COMPARE_NIL_IC; } | |
1078 | |
1079 Handle<Code> GenerateCode(); | |
1080 | |
1081 static Handle<Code> GetUninitialized(Isolate* isolate, | 1099 static Handle<Code> GetUninitialized(Isolate* isolate, |
1082 EqualityKind kind, | 1100 EqualityKind kind, |
1083 NilValue nil) { | 1101 NilValue nil) { |
1084 return CompareNilICStub(kind, nil).GetCode(isolate); | 1102 return CompareNilICStub(kind, nil, CODE_STUB_IS_MISS).GetCode(isolate); |
1085 } | 1103 } |
1086 | 1104 |
1087 virtual void InitializeInterfaceDescriptor( | 1105 virtual void InitializeInterfaceDescriptor( |
1088 Isolate* isolate, | 1106 Isolate* isolate, |
1089 CodeStubInterfaceDescriptor* descriptor); | 1107 CodeStubInterfaceDescriptor* descriptor); |
1090 | 1108 |
1091 static void InitializeForIsolate(Isolate* isolate) { | 1109 static void InitializeForIsolate(Isolate* isolate) { |
1092 CompareNilICStub compare_stub(kStrictEquality, kNullValue); | 1110 CompareNilICStub compare_stub(kStrictEquality, kNullValue, |
1111 CODE_STUB_IS_MISS); | |
1093 compare_stub.InitializeInterfaceDescriptor( | 1112 compare_stub.InitializeInterfaceDescriptor( |
1094 isolate, | 1113 isolate, |
1095 isolate->code_stub_interface_descriptor(CodeStub::CompareNilIC)); | 1114 isolate->code_stub_interface_descriptor(CodeStub::CompareNilIC)); |
1096 } | 1115 } |
1097 | 1116 |
1098 virtual Code::ExtraICState GetExtraICState() { | 1117 virtual InlineCacheState GetICState() { |
1099 return bit_field_; | 1118 if (types_.IsFullCompare()) { |
1119 return MEGAMORPHIC; | |
1120 } else if (types_.Contains(MONOMORPHIC_MAP)) { | |
1121 return MONOMORPHIC; | |
1122 } else { | |
1123 return PREMONOMORPHIC; | |
1124 } | |
1100 } | 1125 } |
1101 | 1126 |
1102 EqualityKind GetKind() { return EqualityKindField::decode(bit_field_); } | 1127 virtual Code::Kind GetCodeKind() const { return Code::COMPARE_NIL_IC; } |
1103 NilValue GetNilValue() { return NilValueField::decode(bit_field_); } | |
1104 Types GetTypes() { return TypesField::decode(bit_field_); } | |
1105 | 1128 |
1106 static Types TypesFromExtraICState( | 1129 Handle<Code> GenerateCode(); |
1130 | |
1131 // extra ic state = nil_value | equality_kind | type_n-1 | ... | type_0 | |
1132 virtual Code::ExtraICState GetExtraICState() { | |
1133 return NilValueField::encode(nil_value_) | | |
1134 EqualityKindField::encode(equality_kind_) | | |
1135 types_.ToByte(); | |
1136 } | |
1137 static byte ExtractTypesFromExtraICState( | |
1107 Code::ExtraICState state) { | 1138 Code::ExtraICState state) { |
1108 return TypesField::decode(state); | 1139 return state & ((1<<NUMBER_OF_TYPES)-1); |
1109 } | |
1110 static EqualityKind EqualityKindFromExtraICState( | |
1111 Code::ExtraICState state) { | |
1112 return EqualityKindField::decode(state); | |
1113 } | |
1114 static NilValue NilValueFromExtraICState(Code::ExtraICState state) { | |
1115 return NilValueField::decode(state); | |
1116 } | 1140 } |
1117 | 1141 |
1118 static Types GetPatchedICFlags(Code::ExtraICState extra_ic_state, | 1142 void Record(Handle<Object> object); |
1119 Handle<Object> object, | 1143 |
1120 bool* already_monomorphic); | 1144 bool IsMonomorphic() const { return types_.Contains(MONOMORPHIC_MAP); } |
1145 EqualityKind GetKind() const { return equality_kind_; } | |
1146 NilValue GetNilValue() const { return nil_value_; } | |
1147 const Types GetTypes() const { return types_; } | |
Sven Panne
2013/05/14 09:18:42
The first 'const' doesn't really make sense: It do
| |
1148 void ClearTypes() { types_.RemoveAll(); } | |
1149 void SetKind(EqualityKind kind) { equality_kind_ = kind; } | |
1150 | |
1151 virtual void PrintName(StringStream* stream); | |
1121 | 1152 |
1122 private: | 1153 private: |
1123 friend class CompareNilIC; | 1154 friend class CompareNilIC; |
1124 | 1155 |
1125 class EqualityKindField : public BitField<EqualityKind, 0, 1> {}; | 1156 CompareNilICStub(EqualityKind kind, NilValue nil, |
1126 class NilValueField : public BitField<NilValue, 1, 1> {}; | 1157 InitializationState init_state) |
1127 class TypesField : public BitField<Types, 3, 4> {}; | 1158 : HydrogenCodeStub(init_state), types_(0) { |
1128 | 1159 equality_kind_ = kind; |
1129 CompareNilICStub(EqualityKind kind, NilValue nil) | 1160 nil_value_ = nil; |
1130 : HydrogenCodeStub(CODE_STUB_IS_MISS), bit_field_(0) { | |
1131 bit_field_ = EqualityKindField::encode(kind) | | |
1132 NilValueField::encode(nil); | |
1133 } | 1161 } |
1134 | 1162 |
1163 CompareNilICStub(Code::ExtraICState ic_state, InitializationState init_state) | |
1164 : HydrogenCodeStub(init_state) { | |
1165 equality_kind_ = EqualityKindField::decode(ic_state); | |
1166 nil_value_ = NilValueField::decode(ic_state); | |
1167 types_ = Types(ExtractTypesFromExtraICState(ic_state)); | |
1168 } | |
1169 | |
1170 class EqualityKindField : public BitField<EqualityKind, NUMBER_OF_TYPES, 1> { | |
1171 }; | |
1172 class NilValueField : public BitField<NilValue, NUMBER_OF_TYPES+1, 1> {}; | |
1173 | |
1135 virtual CodeStub::Major MajorKey() { return CompareNilIC; } | 1174 virtual CodeStub::Major MajorKey() { return CompareNilIC; } |
1136 virtual int NotMissMinorKey() { return bit_field_; } | 1175 virtual int NotMissMinorKey() { return GetExtraICState(); } |
1137 | 1176 |
1138 int bit_field_; | 1177 EqualityKind equality_kind_; |
1178 NilValue nil_value_; | |
1179 Types types_; | |
1139 | 1180 |
1140 DISALLOW_COPY_AND_ASSIGN(CompareNilICStub); | 1181 DISALLOW_COPY_AND_ASSIGN(CompareNilICStub); |
1141 }; | 1182 }; |
1142 | 1183 |
1143 | 1184 |
1144 class CEntryStub : public PlatformCodeStub { | 1185 class CEntryStub : public PlatformCodeStub { |
1145 public: | 1186 public: |
1146 explicit CEntryStub(int result_size, | 1187 explicit CEntryStub(int result_size, |
1147 SaveFPRegsMode save_doubles = kDontSaveFPRegs) | 1188 SaveFPRegsMode save_doubles = kDontSaveFPRegs) |
1148 : result_size_(result_size), save_doubles_(save_doubles) { } | 1189 : result_size_(result_size), save_doubles_(save_doubles) { } |
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1788 STRING, | 1829 STRING, |
1789 SYMBOL, | 1830 SYMBOL, |
1790 HEAP_NUMBER, | 1831 HEAP_NUMBER, |
1791 NUMBER_OF_TYPES | 1832 NUMBER_OF_TYPES |
1792 }; | 1833 }; |
1793 | 1834 |
1794 // At most 8 different types can be distinguished, because the Code object | 1835 // At most 8 different types can be distinguished, because the Code object |
1795 // only has room for a single byte to hold a set of these types. :-P | 1836 // only has room for a single byte to hold a set of these types. :-P |
1796 STATIC_ASSERT(NUMBER_OF_TYPES <= 8); | 1837 STATIC_ASSERT(NUMBER_OF_TYPES <= 8); |
1797 | 1838 |
1798 class Types { | 1839 class Types : public EnumSet<Type, byte> { |
1799 public: | 1840 public: |
1800 Types() {} | 1841 Types() {} |
1801 explicit Types(byte bits) : set_(bits) {} | 1842 explicit Types(byte bits) : EnumSet<Type, byte>(bits) {} |
1802 | 1843 |
1803 bool IsEmpty() const { return set_.IsEmpty(); } | 1844 byte ToByte() const { return ToIntegral(); } |
Sven Panne
2013/05/14 09:18:42
Just using ToIntegral() is easier here, too. (I kn
oliv
2013/05/14 13:28:11
This is still called from platform dependant code,
| |
1804 bool Contains(Type type) const { return set_.Contains(type); } | |
1805 bool ContainsAnyOf(Types types) const { | |
1806 return set_.ContainsAnyOf(types.set_); | |
1807 } | |
1808 void Add(Type type) { set_.Add(type); } | |
1809 byte ToByte() const { return set_.ToIntegral(); } | |
1810 void Print(StringStream* stream) const; | 1845 void Print(StringStream* stream) const; |
1811 void TraceTransition(Types to) const; | 1846 void TraceTransition(Types to) const; |
1812 bool Record(Handle<Object> object); | 1847 bool Record(Handle<Object> object); |
1813 bool NeedsMap() const; | 1848 bool NeedsMap() const; |
1814 bool CanBeUndetectable() const; | 1849 bool CanBeUndetectable() const; |
1815 | |
1816 private: | |
1817 EnumSet<Type, byte> set_; | |
1818 }; | 1850 }; |
1819 | 1851 |
1820 static Types no_types() { return Types(); } | 1852 static Types no_types() { return Types(); } |
1821 static Types all_types() { return Types((1 << NUMBER_OF_TYPES) - 1); } | 1853 static Types all_types() { return Types((1 << NUMBER_OF_TYPES) - 1); } |
1822 | 1854 |
1823 explicit ToBooleanStub(Register tos, Types types = Types()) | 1855 explicit ToBooleanStub(Register tos, Types types = Types()) |
1824 : tos_(tos), types_(types) { } | 1856 : tos_(tos), types_(types) { } |
1825 | 1857 |
1826 void Generate(MacroAssembler* masm); | 1858 void Generate(MacroAssembler* masm); |
1827 virtual Code::Kind GetCodeKind() const { return Code::TO_BOOLEAN_IC; } | 1859 virtual Code::Kind GetCodeKind() const { return Code::TO_BOOLEAN_IC; } |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1964 | 1996 |
1965 // The current function entry hook. | 1997 // The current function entry hook. |
1966 static FunctionEntryHook entry_hook_; | 1998 static FunctionEntryHook entry_hook_; |
1967 | 1999 |
1968 DISALLOW_COPY_AND_ASSIGN(ProfileEntryHookStub); | 2000 DISALLOW_COPY_AND_ASSIGN(ProfileEntryHookStub); |
1969 }; | 2001 }; |
1970 | 2002 |
1971 } } // namespace v8::internal | 2003 } } // namespace v8::internal |
1972 | 2004 |
1973 #endif // V8_CODE_STUBS_H_ | 2005 #endif // V8_CODE_STUBS_H_ |
OLD | NEW |