Region.h 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #pragma once
  6. enum RegionType : BYTE
  7. {
  8. RegionTypeInvalid,
  9. RegionTypeRoot,
  10. RegionTypeTry,
  11. RegionTypeCatch,
  12. RegionTypeFinally
  13. };
  14. class Region
  15. {
  16. public:
  17. Region() : type(RegionTypeInvalid),
  18. parent(NULL), matchingTryRegion(nullptr), matchingCatchRegion(nullptr), matchingFinallyRegion(nullptr), selfOrFirstTryAncestor(nullptr),
  19. start(NULL), end(NULL),
  20. writeThroughSymbolsSet(nullptr),
  21. ehBailoutData(nullptr), bailoutReturnThunkLabel(nullptr), returnThunkEmitted(false),
  22. exceptionObjectSym(nullptr) {}
  23. static Region * New(RegionType, Region *, Func *);
  24. public:
  25. inline RegionType GetType() const { return this->type; }
  26. inline void SetType(RegionType type) { this->type = type; }
  27. inline Region * GetParent() const { return this->parent; }
  28. inline void SetParent(Region* parent) { this->parent = parent; }
  29. inline Region * GetMatchingTryRegion() const { return this->matchingTryRegion; }
  30. inline void SetMatchingTryRegion(Region* tryRegion) { this->matchingTryRegion = tryRegion; }
  31. inline Region * GetMatchingCatchRegion() const { return this->matchingCatchRegion; }
  32. inline void SetMatchingCatchRegion(Region* catchRegion) { this->matchingCatchRegion = catchRegion; }
  33. inline Region * GetMatchingFinallyRegion() const { return this->matchingFinallyRegion; }
  34. inline void SetMatchingFinallyRegion(Region* finallyRegion) { this->matchingFinallyRegion = finallyRegion; }
  35. inline IR::Instr * GetStart() const { return this->start; }
  36. inline void SetStart(IR::Instr * instr) { this->start = instr; }
  37. inline IR::Instr * GetEnd() const { return this->end; }
  38. inline void SetEnd(IR::Instr * instr) { this->end = instr; }
  39. inline IR::LabelInstr * GetBailoutReturnThunkLabel() const { return this->bailoutReturnThunkLabel; }
  40. inline StackSym * GetExceptionObjectSym() const { return this->exceptionObjectSym; }
  41. inline void SetExceptionObjectSym(StackSym * sym) { this->exceptionObjectSym = sym; }
  42. void AllocateEHBailoutData(Func * func, IR::Instr * tryInstr);
  43. Region * GetSelfOrFirstTryAncestor();
  44. private:
  45. RegionType type;
  46. Region * parent;
  47. Region * matchingTryRegion;
  48. Region * matchingCatchRegion;
  49. Region * matchingFinallyRegion;
  50. Region * selfOrFirstTryAncestor; // = self, if try region, otherwise
  51. // = first try ancestor
  52. IR::Instr * start;
  53. IR::Instr * end;
  54. StackSym * exceptionObjectSym;
  55. IR::LabelInstr * bailoutReturnThunkLabel;
  56. // bailoutReturnThunkLabel is the Label denoting start of return thunk for this region.
  57. // The JIT'ed code of a function having EH may have multiple frames on the stack, pertaining to the JIT'ed code and the TryCatch helper.
  58. // After a bailout in an EH region, we want to jump to the epilog of the function, but we have to do this via a series of returns (to clear out the frames on the stack).
  59. // To achieve this, post bailout, we jump to the return thunk of that region, which loads the appropriate return address into eax and executes a RET.
  60. // This has the effect of returning that address to the TryCatch helper, which, in turn, returns it to its caller JIT'ed code.
  61. // Non-top-level EH regions return the address of their parent's return thunk, and top level EH regions return the address
  62. // where the return value from a bailout is loaded into eax (restoreReturnValueFromBailoutLabel in EHBailoutPatchUp::Emit).
  63. // (Control should go to a return thunk only in case of a bailout from an EH region.)
  64. public:
  65. BVSparse<JitArenaAllocator> * writeThroughSymbolsSet;
  66. Js::EHBailoutData * ehBailoutData;
  67. bool returnThunkEmitted;
  68. };