Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(254)

Side by Side Diff: src/objects.h

Issue 2197183002: [debugger] use handler table on unoptimized code for exception prediction. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: address comments and rebase Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/isolate.cc ('k') | src/objects.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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_OBJECTS_H_ 5 #ifndef V8_OBJECTS_H_
6 #define V8_OBJECTS_H_ 6 #define V8_OBJECTS_H_
7 7
8 #include <iosfwd> 8 #include <iosfwd>
9 #include <memory> 9 #include <memory>
10 10
(...skipping 4430 matching lines...) Expand 10 before | Expand all | Expand 10 after
4441 private: 4441 private:
4442 static const int kEntries = 64; 4442 static const int kEntries = 64;
4443 4443
4444 static inline int GetIndex(Handle<Map> map); 4444 static inline int GetIndex(Handle<Map> map);
4445 4445
4446 // The following declarations hide base class methods. 4446 // The following declarations hide base class methods.
4447 Object* get(int index); 4447 Object* get(int index);
4448 void set(int index, Object* value); 4448 void set(int index, Object* value);
4449 }; 4449 };
4450 4450
4451 // HandlerTable is a fixed array containing entries for exception handlers in
4452 // the code object it is associated with. The tables comes in two flavors:
4453 // 1) Based on ranges: Used for unoptimized code. Contains one entry per
4454 // exception handler and a range representing the try-block covered by that
4455 // handler. Layout looks as follows:
4456 // [ range-start , range-end , handler-offset , handler-data ]
4457 // 2) Based on return addresses: Used for turbofanned code. Contains one entry
4458 // per call-site that could throw an exception. Layout looks as follows:
4459 // [ return-address-offset , handler-offset ]
4460 class HandlerTable : public FixedArray {
4461 public:
4462 // Conservative prediction whether a given handler will locally catch an
4463 // exception or cause a re-throw to outside the code boundary. Since this is
4464 // undecidable it is merely an approximation (e.g. useful for debugger).
4465 enum CatchPrediction {
4466 UNCAUGHT, // the handler will (likely) rethrow the exception.
4467 CAUGHT, // the exception will be caught by the handler.
4468 PROMISE // the exception will be caught and cause a promise rejection.
4469 };
4470
4471 // Getters for handler table based on ranges.
4472 inline int GetRangeStart(int index) const;
4473 inline int GetRangeEnd(int index) const;
4474 inline int GetRangeHandler(int index) const;
4475 inline int GetRangeData(int index) const;
4476
4477 // Setters for handler table based on ranges.
4478 inline void SetRangeStart(int index, int value);
4479 inline void SetRangeEnd(int index, int value);
4480 inline void SetRangeHandler(int index, int offset, CatchPrediction pred);
4481 inline void SetRangeData(int index, int value);
4482
4483 // Setters for handler table based on return addresses.
4484 inline void SetReturnOffset(int index, int value);
4485 inline void SetReturnHandler(int index, int offset, CatchPrediction pred);
4486
4487 // Lookup handler in a table based on ranges.
4488 int LookupRange(int pc_offset, int* data, CatchPrediction* prediction);
4489
4490 // Lookup handler in a table based on return addresses.
4491 int LookupReturn(int pc_offset);
4492
4493 // Returns the conservative catch predication.
4494 inline CatchPrediction GetRangePrediction(int index) const;
4495
4496 // Returns the number of entries in the table.
4497 inline int NumberOfRangeEntries() const;
4498
4499 // Returns the required length of the underlying fixed array.
4500 static int LengthForRange(int entries) { return entries * kRangeEntrySize; }
4501 static int LengthForReturn(int entries) { return entries * kReturnEntrySize; }
4502
4503 DECLARE_CAST(HandlerTable)
4504
4505 #ifdef ENABLE_DISASSEMBLER
4506 void HandlerTableRangePrint(std::ostream& os); // NOLINT
4507 void HandlerTableReturnPrint(std::ostream& os); // NOLINT
4508 #endif
4509
4510 private:
4511 // Layout description for handler table based on ranges.
4512 static const int kRangeStartIndex = 0;
4513 static const int kRangeEndIndex = 1;
4514 static const int kRangeHandlerIndex = 2;
4515 static const int kRangeDataIndex = 3;
4516 static const int kRangeEntrySize = 4;
4517
4518 // Layout description for handler table based on return addresses.
4519 static const int kReturnOffsetIndex = 0;
4520 static const int kReturnHandlerIndex = 1;
4521 static const int kReturnEntrySize = 2;
4522
4523 // Encoding of the {handler} field.
4524 class HandlerPredictionField : public BitField<CatchPrediction, 0, 2> {};
4525 class HandlerOffsetField : public BitField<int, 2, 30> {};
4526 };
4451 4527
4452 // ByteArray represents fixed sized byte arrays. Used for the relocation info 4528 // ByteArray represents fixed sized byte arrays. Used for the relocation info
4453 // that is attached to code objects. 4529 // that is attached to code objects.
4454 class ByteArray: public FixedArrayBase { 4530 class ByteArray: public FixedArrayBase {
4455 public: 4531 public:
4456 inline int Size(); 4532 inline int Size();
4457 4533
4458 // Setter and getter. 4534 // Setter and getter.
4459 inline byte get(int index); 4535 inline byte get(int index);
4460 inline void set(int index, byte value); 4536 inline void set(int index, byte value);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
4564 int SourcePosition(int offset); 4640 int SourcePosition(int offset);
4565 int SourceStatementPosition(int offset); 4641 int SourceStatementPosition(int offset);
4566 4642
4567 DECLARE_PRINTER(BytecodeArray) 4643 DECLARE_PRINTER(BytecodeArray)
4568 DECLARE_VERIFIER(BytecodeArray) 4644 DECLARE_VERIFIER(BytecodeArray)
4569 4645
4570 void Disassemble(std::ostream& os); 4646 void Disassemble(std::ostream& os);
4571 4647
4572 void CopyBytecodesTo(BytecodeArray* to); 4648 void CopyBytecodesTo(BytecodeArray* to);
4573 4649
4650 int LookupRangeInHandlerTable(int code_offset, int* data,
4651 HandlerTable::CatchPrediction* prediction);
4652
4574 // Layout description. 4653 // Layout description.
4575 static const int kConstantPoolOffset = FixedArrayBase::kHeaderSize; 4654 static const int kConstantPoolOffset = FixedArrayBase::kHeaderSize;
4576 static const int kHandlerTableOffset = kConstantPoolOffset + kPointerSize; 4655 static const int kHandlerTableOffset = kConstantPoolOffset + kPointerSize;
4577 static const int kSourcePositionTableOffset = 4656 static const int kSourcePositionTableOffset =
4578 kHandlerTableOffset + kPointerSize; 4657 kHandlerTableOffset + kPointerSize;
4579 static const int kFrameSizeOffset = kSourcePositionTableOffset + kPointerSize; 4658 static const int kFrameSizeOffset = kSourcePositionTableOffset + kPointerSize;
4580 static const int kParameterSizeOffset = kFrameSizeOffset + kIntSize; 4659 static const int kParameterSizeOffset = kFrameSizeOffset + kIntSize;
4581 static const int kInterruptBudgetOffset = kParameterSizeOffset + kIntSize; 4660 static const int kInterruptBudgetOffset = kParameterSizeOffset + kIntSize;
4582 static const int kOSRNestingLevelOffset = kInterruptBudgetOffset + kIntSize; 4661 static const int kOSRNestingLevelOffset = kInterruptBudgetOffset + kIntSize;
4583 static const int kHeaderSize = kOSRNestingLevelOffset + kCharSize; 4662 static const int kHeaderSize = kOSRNestingLevelOffset + kCharSize;
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
4871 DECLARE_CAST(LiteralsArray) 4950 DECLARE_CAST(LiteralsArray)
4872 4951
4873 private: 4952 private:
4874 inline Object* get(int index) const; 4953 inline Object* get(int index) const;
4875 inline void set(int index, Object* value); 4954 inline void set(int index, Object* value);
4876 inline void set(int index, Smi* value); 4955 inline void set(int index, Smi* value);
4877 inline void set(int index, Object* value, WriteBarrierMode mode); 4956 inline void set(int index, Object* value, WriteBarrierMode mode);
4878 }; 4957 };
4879 4958
4880 4959
4881 // HandlerTable is a fixed array containing entries for exception handlers in
4882 // the code object it is associated with. The tables comes in two flavors:
4883 // 1) Based on ranges: Used for unoptimized code. Contains one entry per
4884 // exception handler and a range representing the try-block covered by that
4885 // handler. Layout looks as follows:
4886 // [ range-start , range-end , handler-offset , handler-data ]
4887 // 2) Based on return addresses: Used for turbofanned code. Contains one entry
4888 // per call-site that could throw an exception. Layout looks as follows:
4889 // [ return-address-offset , handler-offset ]
4890 class HandlerTable : public FixedArray {
4891 public:
4892 // Conservative prediction whether a given handler will locally catch an
4893 // exception or cause a re-throw to outside the code boundary. Since this is
4894 // undecidable it is merely an approximation (e.g. useful for debugger).
4895 enum CatchPrediction {
4896 UNCAUGHT, // the handler will (likely) rethrow the exception.
4897 CAUGHT, // the exception will be caught by the handler.
4898 PROMISE // the exception will be caught and cause a promise rejection.
4899 };
4900
4901 // Getters for handler table based on ranges.
4902 inline int GetRangeStart(int index) const;
4903 inline int GetRangeEnd(int index) const;
4904 inline int GetRangeHandler(int index) const;
4905 inline int GetRangeData(int index) const;
4906
4907 // Setters for handler table based on ranges.
4908 inline void SetRangeStart(int index, int value);
4909 inline void SetRangeEnd(int index, int value);
4910 inline void SetRangeHandler(int index, int offset, CatchPrediction pred);
4911 inline void SetRangeData(int index, int value);
4912
4913 // Setters for handler table based on return addresses.
4914 inline void SetReturnOffset(int index, int value);
4915 inline void SetReturnHandler(int index, int offset, CatchPrediction pred);
4916
4917 // Lookup handler in a table based on ranges.
4918 int LookupRange(int pc_offset, int* data, CatchPrediction* prediction);
4919
4920 // Lookup handler in a table based on return addresses.
4921 int LookupReturn(int pc_offset, CatchPrediction* prediction);
4922
4923 // Returns the conservative catch predication.
4924 inline CatchPrediction GetRangePrediction(int index) const;
4925
4926 // Returns the number of entries in the table.
4927 inline int NumberOfRangeEntries() const;
4928
4929 // Returns the required length of the underlying fixed array.
4930 static int LengthForRange(int entries) { return entries * kRangeEntrySize; }
4931 static int LengthForReturn(int entries) { return entries * kReturnEntrySize; }
4932
4933 DECLARE_CAST(HandlerTable)
4934
4935 #ifdef ENABLE_DISASSEMBLER
4936 void HandlerTableRangePrint(std::ostream& os); // NOLINT
4937 void HandlerTableReturnPrint(std::ostream& os); // NOLINT
4938 #endif
4939
4940 private:
4941 // Layout description for handler table based on ranges.
4942 static const int kRangeStartIndex = 0;
4943 static const int kRangeEndIndex = 1;
4944 static const int kRangeHandlerIndex = 2;
4945 static const int kRangeDataIndex = 3;
4946 static const int kRangeEntrySize = 4;
4947
4948 // Layout description for handler table based on return addresses.
4949 static const int kReturnOffsetIndex = 0;
4950 static const int kReturnHandlerIndex = 1;
4951 static const int kReturnEntrySize = 2;
4952
4953 // Encoding of the {handler} field.
4954 class HandlerPredictionField : public BitField<CatchPrediction, 0, 2> {};
4955 class HandlerOffsetField : public BitField<int, 2, 30> {};
4956 };
4957
4958 class TemplateList : public FixedArray { 4960 class TemplateList : public FixedArray {
4959 public: 4961 public:
4960 static Handle<TemplateList> New(Isolate* isolate, int size); 4962 static Handle<TemplateList> New(Isolate* isolate, int size);
4961 inline int length() const; 4963 inline int length() const;
4962 inline Object* get(int index) const; 4964 inline Object* get(int index) const;
4963 inline void set(int index, Object* value); 4965 inline void set(int index, Object* value);
4964 static Handle<TemplateList> Add(Isolate* isolate, Handle<TemplateList> list, 4966 static Handle<TemplateList> Add(Isolate* isolate, Handle<TemplateList> list,
4965 Handle<Object> value); 4967 Handle<Object> value);
4966 DECLARE_CAST(TemplateList) 4968 DECLARE_CAST(TemplateList)
4967 private: 4969 private:
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
5334 inline int CodeSize(); 5336 inline int CodeSize();
5335 5337
5336 DECLARE_PRINTER(Code) 5338 DECLARE_PRINTER(Code)
5337 DECLARE_VERIFIER(Code) 5339 DECLARE_VERIFIER(Code)
5338 5340
5339 void ClearInlineCaches(); 5341 void ClearInlineCaches();
5340 5342
5341 BailoutId TranslatePcOffsetToAstId(uint32_t pc_offset); 5343 BailoutId TranslatePcOffsetToAstId(uint32_t pc_offset);
5342 uint32_t TranslateAstIdToPcOffset(BailoutId ast_id); 5344 uint32_t TranslateAstIdToPcOffset(BailoutId ast_id);
5343 5345
5346 int LookupRangeInHandlerTable(int code_offset, int* data,
5347 HandlerTable::CatchPrediction* prediction);
5348
5344 #define DECLARE_CODE_AGE_ENUM(X) k##X##CodeAge, 5349 #define DECLARE_CODE_AGE_ENUM(X) k##X##CodeAge,
5345 enum Age { 5350 enum Age {
5346 kToBeExecutedOnceCodeAge = -3, 5351 kToBeExecutedOnceCodeAge = -3,
5347 kNotExecutedCodeAge = -2, 5352 kNotExecutedCodeAge = -2,
5348 kExecutedOnceCodeAge = -1, 5353 kExecutedOnceCodeAge = -1,
5349 kNoAgeCodeAge = 0, 5354 kNoAgeCodeAge = 0,
5350 CODE_AGE_LIST(DECLARE_CODE_AGE_ENUM) 5355 CODE_AGE_LIST(DECLARE_CODE_AGE_ENUM)
5351 kAfterLastCodeAge, 5356 kAfterLastCodeAge,
5352 kFirstCodeAge = kToBeExecutedOnceCodeAge, 5357 kFirstCodeAge = kToBeExecutedOnceCodeAge,
5353 kLastCodeAge = kAfterLastCodeAge - 1, 5358 kLastCodeAge = kAfterLastCodeAge - 1,
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
5547 5552
5548 // Returns the address right after the last instruction. 5553 // Returns the address right after the last instruction.
5549 inline Address instruction_end(); 5554 inline Address instruction_end();
5550 5555
5551 // Returns the size of the code instructions. 5556 // Returns the size of the code instructions.
5552 inline int instruction_size(); 5557 inline int instruction_size();
5553 5558
5554 // Return the source position table. 5559 // Return the source position table.
5555 inline ByteArray* source_position_table(); 5560 inline ByteArray* source_position_table();
5556 5561
5562 // Return the exception handler table.
5563 inline int LookupRangeInHandlerTable(
5564 int code_offset, int* data, HandlerTable::CatchPrediction* prediction);
5565
5557 // Returns the size of instructions and the metadata. 5566 // Returns the size of instructions and the metadata.
5558 inline int SizeIncludingMetadata(); 5567 inline int SizeIncludingMetadata();
5559 5568
5560 // Returns true if pc is inside this object's instructions. 5569 // Returns true if pc is inside this object's instructions.
5561 inline bool contains(byte* pc); 5570 inline bool contains(byte* pc);
5562 5571
5563 // Returns the AbstractCode::Kind of the code. 5572 // Returns the AbstractCode::Kind of the code.
5564 inline Kind kind(); 5573 inline Kind kind();
5565 5574
5566 // Calculate the size of the code object to report for log events. This takes 5575 // Calculate the size of the code object to report for log events. This takes
(...skipping 5484 matching lines...) Expand 10 before | Expand all | Expand 10 after
11051 } 11060 }
11052 return value; 11061 return value;
11053 } 11062 }
11054 }; 11063 };
11055 11064
11056 11065
11057 } // NOLINT, false-positive due to second-order macros. 11066 } // NOLINT, false-positive due to second-order macros.
11058 } // NOLINT, false-positive due to second-order macros. 11067 } // NOLINT, false-positive due to second-order macros.
11059 11068
11060 #endif // V8_OBJECTS_H_ 11069 #endif // V8_OBJECTS_H_
OLDNEW
« no previous file with comments | « src/isolate.cc ('k') | src/objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698