JitHelperUtils.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft Corporation and contributors. 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. namespace HelperMethodAttributes
  7. {
  8. // [Flags]
  9. enum HelperMethodAttribute : BYTE
  10. {
  11. AttrNone = 0x00,
  12. AttrCanThrow = 0x01, // Can throw non-OOM / non-SO exceptions. Under debugger / Fast F12, these helpers are wrapped with try-catch wrapper.
  13. AttrInVariant = 0x02, // The method is "const" method that can be hoisted.
  14. AttrCanNotBeReentrant = 0x4,
  15. AttrTempObjectProducing = 0x8
  16. };
  17. #if defined(DBG) && ENABLE_NATIVE_CODEGEN
  18. #define JIT_HELPER_REENTRANT_HEADER(Name) \
  19. void Name##Declared_in_Header(); \
  20. CompileAssert((HelperMethodAttributes::JitHelperUtils::helper##Name##_attributes & HelperMethodAttributes::AttrCanNotBeReentrant) == 0);
  21. #define JIT_HELPER_NOT_REENTRANT_NOLOCK_HEADER(Name) \
  22. void Name##Declared_in_Header(); \
  23. CompileAssert((HelperMethodAttributes::JitHelperUtils::helper##Name##_attributes & HelperMethodAttributes::AttrCanNotBeReentrant) != 0);
  24. #define JIT_HELPER_NOT_REENTRANT_HEADER(Name, reentrancyLock, threadContext) \
  25. JIT_HELPER_NOT_REENTRANT_NOLOCK_HEADER(Name)\
  26. JS_REENTRANCY_LOCK(reentrancyLock, threadContext);
  27. #define JIT_HELPER_SAME_ATTRIBUTES(T1, T2) \
  28. CompileAssert(HelperMethodAttributes::JitHelperUtils::helper##T1##_attributes == HelperMethodAttributes::JitHelperUtils::helper##T2##_attributes);
  29. // Private macro, do not use directly
  30. #define __JIT_HELPER_INSTANTIATE(Name) const bool HelperMethodAttributes::JitHelperUtils::helper##Name##_implemented = true;
  31. // JIT_HELPER_END will cause a compile error if no JIT_HELPER_*_HEADER is used
  32. // This macro cannot be used inside any namespaces as it needs to instantiate a static var
  33. #define JIT_HELPER_END(Name) \
  34. struct Name##_ForceUsage { \
  35. Name##_ForceUsage() { Name##Declared_in_Header(); }\
  36. };\
  37. }\
  38. __JIT_HELPER_INSTANTIATE(Name)\
  39. void dummy_##Name() {
  40. #define JIT_HELPER_TEMPLATE(T1, T2) \
  41. __JIT_HELPER_INSTANTIATE(T2);\
  42. JIT_HELPER_SAME_ATTRIBUTES(T1, T2);
  43. struct JitHelperUtils
  44. {
  45. #define HELPERCALL(Name, Address, Attributes)
  46. // This will cause Linker error if JIT_HELPER_END is not used
  47. #define HELPERCALLCHK(Name, Address, Attributes) \
  48. static const bool helper##Name##_implemented;\
  49. static constexpr HelperMethodAttribute helper##Name##_attributes = (HelperMethodAttribute)(Attributes);
  50. #include "../Backend/JnHelperMethodList.h"
  51. };
  52. #else
  53. #define JIT_HELPER_REENTRANT_HEADER(Name)
  54. #define JIT_HELPER_NOT_REENTRANT_NOLOCK_HEADER(Name)
  55. #define JIT_HELPER_NOT_REENTRANT_HEADER(Name, reentrancyLock, threadContext) \
  56. JS_REENTRANCY_LOCK(reentrancyLock, threadContext);
  57. #define JIT_HELPER_SAME_ATTRIBUTES(T1, T2)
  58. #define JIT_HELPER_END(Name)
  59. #define JIT_HELPER_TEMPLATE(T1, T2)
  60. #endif
  61. }