Executable.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright (c) 2021-2023, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/DeprecatedFlyString.h>
  8. #include <AK/HashMap.h>
  9. #include <AK/NonnullOwnPtr.h>
  10. #include <AK/OwnPtr.h>
  11. #include <AK/WeakPtr.h>
  12. #include <LibJS/Bytecode/IdentifierTable.h>
  13. #include <LibJS/Bytecode/Label.h>
  14. #include <LibJS/Bytecode/StringTable.h>
  15. #include <LibJS/Forward.h>
  16. #include <LibJS/Heap/Cell.h>
  17. #include <LibJS/Heap/CellAllocator.h>
  18. #include <LibJS/Runtime/EnvironmentCoordinate.h>
  19. namespace JS::JIT {
  20. class NativeExecutable;
  21. }
  22. namespace JS::Bytecode {
  23. struct PropertyLookupCache {
  24. static FlatPtr shape_offset() { return OFFSET_OF(PropertyLookupCache, shape); }
  25. static FlatPtr property_offset_offset() { return OFFSET_OF(PropertyLookupCache, property_offset); }
  26. static FlatPtr unique_shape_serial_number_offset() { return OFFSET_OF(PropertyLookupCache, unique_shape_serial_number); }
  27. WeakPtr<Shape> shape;
  28. Optional<u32> property_offset;
  29. u64 unique_shape_serial_number { 0 };
  30. };
  31. struct GlobalVariableCache : public PropertyLookupCache {
  32. static FlatPtr environment_serial_number_offset() { return OFFSET_OF(GlobalVariableCache, environment_serial_number); }
  33. u64 environment_serial_number { 0 };
  34. };
  35. using EnvironmentVariableCache = Optional<EnvironmentCoordinate>;
  36. struct SourceRecord {
  37. u32 source_start_offset {};
  38. u32 source_end_offset {};
  39. };
  40. class Executable final : public Cell {
  41. JS_CELL(Executable, Cell);
  42. JS_DECLARE_ALLOCATOR(Executable);
  43. public:
  44. Executable(
  45. NonnullOwnPtr<IdentifierTable>,
  46. NonnullOwnPtr<StringTable>,
  47. NonnullOwnPtr<RegexTable>,
  48. NonnullRefPtr<SourceCode const>,
  49. size_t number_of_property_lookup_caches,
  50. size_t number_of_global_variable_caches,
  51. size_t number_of_environment_variable_caches,
  52. size_t number_of_registers,
  53. Vector<NonnullOwnPtr<BasicBlock>>,
  54. bool is_strict_mode);
  55. virtual ~Executable() override;
  56. DeprecatedFlyString name;
  57. Vector<PropertyLookupCache> property_lookup_caches;
  58. Vector<GlobalVariableCache> global_variable_caches;
  59. Vector<EnvironmentVariableCache> environment_variable_caches;
  60. Vector<NonnullOwnPtr<BasicBlock>> basic_blocks;
  61. NonnullOwnPtr<StringTable> string_table;
  62. NonnullOwnPtr<IdentifierTable> identifier_table;
  63. NonnullOwnPtr<RegexTable> regex_table;
  64. NonnullRefPtr<SourceCode const> source_code;
  65. size_t number_of_registers { 0 };
  66. bool is_strict_mode { false };
  67. DeprecatedString const& get_string(StringTableIndex index) const { return string_table->get(index); }
  68. DeprecatedFlyString const& get_identifier(IdentifierTableIndex index) const { return identifier_table->get(index); }
  69. void dump() const;
  70. JIT::NativeExecutable const* get_or_create_native_executable();
  71. JIT::NativeExecutable const* native_executable() const { return m_native_executable; }
  72. private:
  73. OwnPtr<JIT::NativeExecutable> m_native_executable;
  74. bool m_did_try_jitting { false };
  75. };
  76. }