| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_CODE_STUBS_H_ | 5 #ifndef V8_CODE_STUBS_H_ |
| 6 #define V8_CODE_STUBS_H_ | 6 #define V8_CODE_STUBS_H_ |
| 7 | 7 |
| 8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
| 9 #include "src/assembler.h" | 9 #include "src/assembler.h" |
| 10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 | 147 |
| 148 static Major MajorKeyFromKey(uint32_t key) { | 148 static Major MajorKeyFromKey(uint32_t key) { |
| 149 return static_cast<Major>(MajorKeyBits::decode(key)); | 149 return static_cast<Major>(MajorKeyBits::decode(key)); |
| 150 } | 150 } |
| 151 static int MinorKeyFromKey(uint32_t key) { | 151 static int MinorKeyFromKey(uint32_t key) { |
| 152 return MinorKeyBits::decode(key); | 152 return MinorKeyBits::decode(key); |
| 153 } | 153 } |
| 154 | 154 |
| 155 // Gets the major key from a code object that is a code stub or binary op IC. | 155 // Gets the major key from a code object that is a code stub or binary op IC. |
| 156 static Major GetMajorKey(Code* code_stub) { | 156 static Major GetMajorKey(Code* code_stub) { |
| 157 return static_cast<Major>(code_stub->major_key()); | 157 return MajorKeyFromKey(code_stub->stub_key()); |
| 158 } | 158 } |
| 159 | 159 |
| 160 static uint32_t NoCacheKey() { return MajorKeyBits::encode(NoCache); } |
| 161 |
| 160 static const char* MajorName(Major major_key, bool allow_unknown_keys); | 162 static const char* MajorName(Major major_key, bool allow_unknown_keys); |
| 161 | 163 |
| 162 explicit CodeStub(Isolate* isolate) : isolate_(isolate) { } | 164 explicit CodeStub(Isolate* isolate) : isolate_(isolate) { } |
| 163 virtual ~CodeStub() {} | 165 virtual ~CodeStub() {} |
| 164 | 166 |
| 165 static void GenerateStubsAheadOfTime(Isolate* isolate); | 167 static void GenerateStubsAheadOfTime(Isolate* isolate); |
| 166 static void GenerateFPStubs(Isolate* isolate); | 168 static void GenerateFPStubs(Isolate* isolate); |
| 167 | 169 |
| 168 // Some stubs put untagged junk on the stack that cannot be scanned by the | 170 // Some stubs put untagged junk on the stack that cannot be scanned by the |
| 169 // GC. This means that we must be statically sure that no GC can occur while | 171 // GC. This means that we must be statically sure that no GC can occur while |
| (...skipping 30 matching lines...) Expand all Loading... |
| 200 virtual Handle<Code> GenerateCode() = 0; | 202 virtual Handle<Code> GenerateCode() = 0; |
| 201 | 203 |
| 202 // Returns whether the code generated for this stub needs to be allocated as | 204 // Returns whether the code generated for this stub needs to be allocated as |
| 203 // a fixed (non-moveable) code object. | 205 // a fixed (non-moveable) code object. |
| 204 virtual bool NeedsImmovableCode() { return false; } | 206 virtual bool NeedsImmovableCode() { return false; } |
| 205 | 207 |
| 206 virtual void PrintName(OStream& os) const; // NOLINT | 208 virtual void PrintName(OStream& os) const; // NOLINT |
| 207 virtual void PrintBaseName(OStream& os) const; // NOLINT | 209 virtual void PrintBaseName(OStream& os) const; // NOLINT |
| 208 virtual void PrintState(OStream& os) const { ; } // NOLINT | 210 virtual void PrintState(OStream& os) const { ; } // NOLINT |
| 209 | 211 |
| 212 // Computes the key based on major and minor. |
| 213 uint32_t GetKey() { |
| 214 ASSERT(static_cast<int>(MajorKey()) < NUMBER_OF_IDS); |
| 215 return MinorKeyBits::encode(MinorKey()) | MajorKeyBits::encode(MajorKey()); |
| 216 } |
| 217 |
| 210 private: | 218 private: |
| 211 // Perform bookkeeping required after code generation when stub code is | 219 // Perform bookkeeping required after code generation when stub code is |
| 212 // initially generated. | 220 // initially generated. |
| 213 void RecordCodeGeneration(Handle<Code> code); | 221 void RecordCodeGeneration(Handle<Code> code); |
| 214 | 222 |
| 215 // Finish the code object after it has been generated. | 223 // Finish the code object after it has been generated. |
| 216 virtual void FinishCode(Handle<Code> code) { } | 224 virtual void FinishCode(Handle<Code> code) { } |
| 217 | 225 |
| 218 // Activate newly generated stub. Is called after | 226 // Activate newly generated stub. Is called after |
| 219 // registering stub in the stub cache. | 227 // registering stub in the stub cache. |
| 220 virtual void Activate(Code* code) { } | 228 virtual void Activate(Code* code) { } |
| 221 | 229 |
| 222 // BinaryOpStub needs to override this. | 230 // BinaryOpStub needs to override this. |
| 223 virtual Code::Kind GetCodeKind() const; | 231 virtual Code::Kind GetCodeKind() const; |
| 224 | 232 |
| 225 // Add the code to a specialized cache, specific to an individual | 233 // Add the code to a specialized cache, specific to an individual |
| 226 // stub type. Please note, this method must add the code object to a | 234 // stub type. Please note, this method must add the code object to a |
| 227 // roots object, otherwise we will remove the code during GC. | 235 // roots object, otherwise we will remove the code during GC. |
| 228 virtual void AddToSpecialCache(Handle<Code> new_object) { } | 236 virtual void AddToSpecialCache(Handle<Code> new_object) { } |
| 229 | 237 |
| 230 // Find code in a specialized cache, work is delegated to the specific stub. | 238 // Find code in a specialized cache, work is delegated to the specific stub. |
| 231 virtual bool FindCodeInSpecialCache(Code** code_out) { | 239 virtual bool FindCodeInSpecialCache(Code** code_out) { |
| 232 return false; | 240 return false; |
| 233 } | 241 } |
| 234 | 242 |
| 235 // If a stub uses a special cache override this. | 243 // If a stub uses a special cache override this. |
| 236 virtual bool UseSpecialCache() { return false; } | 244 virtual bool UseSpecialCache() { return false; } |
| 237 | 245 |
| 238 // Computes the key based on major and minor. | |
| 239 uint32_t GetKey() { | |
| 240 ASSERT(static_cast<int>(MajorKey()) < NUMBER_OF_IDS); | |
| 241 return MinorKeyBits::encode(MinorKey()) | | |
| 242 MajorKeyBits::encode(MajorKey()); | |
| 243 } | |
| 244 | |
| 245 STATIC_ASSERT(NUMBER_OF_IDS < (1 << kStubMajorKeyBits)); | 246 STATIC_ASSERT(NUMBER_OF_IDS < (1 << kStubMajorKeyBits)); |
| 246 class MajorKeyBits: public BitField<uint32_t, 0, kStubMajorKeyBits> {}; | 247 class MajorKeyBits: public BitField<uint32_t, 0, kStubMajorKeyBits> {}; |
| 247 class MinorKeyBits: public BitField<uint32_t, | 248 class MinorKeyBits: public BitField<uint32_t, |
| 248 kStubMajorKeyBits, kStubMinorKeyBits> {}; // NOLINT | 249 kStubMajorKeyBits, kStubMinorKeyBits> {}; // NOLINT |
| 249 | 250 |
| 250 friend class BreakPointIterator; | 251 friend class BreakPointIterator; |
| 251 | 252 |
| 252 Isolate* isolate_; | 253 Isolate* isolate_; |
| 253 }; | 254 }; |
| 254 | 255 |
| (...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 823 }; | 824 }; |
| 824 | 825 |
| 825 | 826 |
| 826 class ICStub: public PlatformCodeStub { | 827 class ICStub: public PlatformCodeStub { |
| 827 public: | 828 public: |
| 828 ICStub(Isolate* isolate, Code::Kind kind) | 829 ICStub(Isolate* isolate, Code::Kind kind) |
| 829 : PlatformCodeStub(isolate), kind_(kind) { } | 830 : PlatformCodeStub(isolate), kind_(kind) { } |
| 830 virtual Code::Kind GetCodeKind() const { return kind_; } | 831 virtual Code::Kind GetCodeKind() const { return kind_; } |
| 831 virtual InlineCacheState GetICState() { return MONOMORPHIC; } | 832 virtual InlineCacheState GetICState() { return MONOMORPHIC; } |
| 832 | 833 |
| 833 bool Describes(Code* code) { | 834 bool Describes(Code* code) { return code->stub_key() == GetKey(); } |
| 834 return GetMajorKey(code) == MajorKey() && code->stub_info() == MinorKey(); | |
| 835 } | |
| 836 | 835 |
| 837 protected: | 836 protected: |
| 838 class KindBits: public BitField<Code::Kind, 0, 4> {}; | 837 class KindBits: public BitField<Code::Kind, 0, 4> {}; |
| 839 virtual void FinishCode(Handle<Code> code) { | |
| 840 code->set_stub_info(MinorKey()); | |
| 841 } | |
| 842 Code::Kind kind() const { return kind_; } | 838 Code::Kind kind() const { return kind_; } |
| 843 | 839 |
| 844 virtual int MinorKey() const { return KindBits::encode(kind_); } | 840 virtual int MinorKey() const { return KindBits::encode(kind_); } |
| 845 | 841 |
| 846 private: | 842 private: |
| 847 Code::Kind kind_; | 843 Code::Kind kind_; |
| 848 }; | 844 }; |
| 849 | 845 |
| 850 | 846 |
| 851 class CallICStub: public PlatformCodeStub { | 847 class CallICStub: public PlatformCodeStub { |
| (...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1359 left_(left), | 1355 left_(left), |
| 1360 right_(right), | 1356 right_(right), |
| 1361 state_(handler) { | 1357 state_(handler) { |
| 1362 ASSERT(Token::IsCompareOp(op)); | 1358 ASSERT(Token::IsCompareOp(op)); |
| 1363 } | 1359 } |
| 1364 | 1360 |
| 1365 virtual void Generate(MacroAssembler* masm); | 1361 virtual void Generate(MacroAssembler* masm); |
| 1366 | 1362 |
| 1367 void set_known_map(Handle<Map> map) { known_map_ = map; } | 1363 void set_known_map(Handle<Map> map) { known_map_ = map; } |
| 1368 | 1364 |
| 1369 static void DecodeMinorKey(int minor_key, | 1365 static void DecodeKey(uint32_t stub_key, CompareIC::State* left_state, |
| 1370 CompareIC::State* left_state, | 1366 CompareIC::State* right_state, |
| 1371 CompareIC::State* right_state, | 1367 CompareIC::State* handler_state, Token::Value* op); |
| 1372 CompareIC::State* handler_state, | |
| 1373 Token::Value* op); | |
| 1374 | 1368 |
| 1375 virtual InlineCacheState GetICState(); | 1369 virtual InlineCacheState GetICState(); |
| 1376 | 1370 |
| 1377 private: | 1371 private: |
| 1378 class OpField: public BitField<int, 0, 3> { }; | 1372 class OpField: public BitField<int, 0, 3> { }; |
| 1379 class LeftStateField: public BitField<int, 3, 4> { }; | 1373 class LeftStateField: public BitField<int, 3, 4> { }; |
| 1380 class RightStateField: public BitField<int, 7, 4> { }; | 1374 class RightStateField: public BitField<int, 7, 4> { }; |
| 1381 class HandlerStateField: public BitField<int, 11, 4> { }; | 1375 class HandlerStateField: public BitField<int, 11, 4> { }; |
| 1382 | 1376 |
| 1383 virtual void FinishCode(Handle<Code> code) { | |
| 1384 code->set_stub_info(MinorKey()); | |
| 1385 } | |
| 1386 | |
| 1387 virtual CodeStub::Major MajorKey() const { return CompareIC; } | 1377 virtual CodeStub::Major MajorKey() const { return CompareIC; } |
| 1388 virtual int MinorKey() const; | 1378 virtual int MinorKey() const; |
| 1389 | 1379 |
| 1390 virtual Code::Kind GetCodeKind() const { return Code::COMPARE_IC; } | 1380 virtual Code::Kind GetCodeKind() const { return Code::COMPARE_IC; } |
| 1391 | 1381 |
| 1392 void GenerateSmis(MacroAssembler* masm); | 1382 void GenerateSmis(MacroAssembler* masm); |
| 1393 void GenerateNumbers(MacroAssembler* masm); | 1383 void GenerateNumbers(MacroAssembler* masm); |
| 1394 void GenerateInternalizedStrings(MacroAssembler* masm); | 1384 void GenerateInternalizedStrings(MacroAssembler* masm); |
| 1395 void GenerateStrings(MacroAssembler* masm); | 1385 void GenerateStrings(MacroAssembler* masm); |
| 1396 void GenerateUniqueNames(MacroAssembler* masm); | 1386 void GenerateUniqueNames(MacroAssembler* masm); |
| (...skipping 1169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2566 | 2556 |
| 2567 | 2557 |
| 2568 class CallDescriptors { | 2558 class CallDescriptors { |
| 2569 public: | 2559 public: |
| 2570 static void InitializeForIsolate(Isolate* isolate); | 2560 static void InitializeForIsolate(Isolate* isolate); |
| 2571 }; | 2561 }; |
| 2572 | 2562 |
| 2573 } } // namespace v8::internal | 2563 } } // namespace v8::internal |
| 2574 | 2564 |
| 2575 #endif // V8_CODE_STUBS_H_ | 2565 #endif // V8_CODE_STUBS_H_ |
| OLD | NEW |