DFGCodeBlocks.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright (C) 2011 Apple Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
  14. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
  17. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  20. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  21. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  23. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #ifndef DFGCodeBlocks_h
  26. #define DFGCodeBlocks_h
  27. #include <wtf/FastAllocBase.h>
  28. #include <wtf/HashSet.h>
  29. #include <wtf/PassOwnPtr.h>
  30. namespace JSC {
  31. class CodeBlock;
  32. class SlotVisitor;
  33. // DFGCodeBlocks notifies the garbage collector about optimized code blocks that
  34. // have different marking behavior depending on whether or not they are on the
  35. // stack, and that may be jettisoned. Jettisoning is the process of discarding
  36. // a code block after all calls to it have been unlinked. This class takes special
  37. // care to ensure that if there are still call frames that are using the code
  38. // block, then it should not be immediately deleted, but rather, it should be
  39. // deleted once we know that there are no longer any references to it from any
  40. // call frames. This class takes its name from the DFG compiler; only code blocks
  41. // compiled by the DFG need special marking behavior if they are on the stack, and
  42. // only those code blocks may be jettisoned.
  43. #if ENABLE(DFG_JIT)
  44. class DFGCodeBlocks {
  45. WTF_MAKE_FAST_ALLOCATED;
  46. public:
  47. DFGCodeBlocks();
  48. ~DFGCodeBlocks();
  49. // Inform the collector that a code block has been jettisoned form its
  50. // executable and should only be kept alive if there are call frames that use
  51. // it. This is typically called either from a recompilation trigger, or from
  52. // an unconditional finalizer associated with a CodeBlock that had weak
  53. // references, where some subset of those references were dead.
  54. void jettison(PassOwnPtr<CodeBlock>);
  55. // Clear all mark bits associated with DFG code blocks.
  56. void clearMarks();
  57. // Mark a pointer that may be a CodeBlock that belongs to the set of DFG code
  58. // blocks. This is defined inline in CodeBlock.h
  59. void mark(void* candidateCodeBlock);
  60. // Delete all jettisoned code blocks that have not been marked (i.e. are not referenced
  61. // from call frames).
  62. void deleteUnmarkedJettisonedCodeBlocks();
  63. // Trace all marked code blocks (i.e. are referenced from call frames). The CodeBlock
  64. // is free to make use of m_dfgData->isMarked and m_dfgData->isJettisoned.
  65. void traceMarkedCodeBlocks(SlotVisitor&);
  66. private:
  67. friend class CodeBlock;
  68. HashSet<CodeBlock*> m_set;
  69. };
  70. #else
  71. class DFGCodeBlocks {
  72. WTF_MAKE_FAST_ALLOCATED;
  73. public:
  74. void jettison(PassOwnPtr<CodeBlock>);
  75. void clearMarks() { }
  76. void mark(void*) { }
  77. void deleteUnmarkedJettisonedCodeBlocks() { }
  78. void traceMarkedCodeBlocks(SlotVisitor&) { }
  79. };
  80. #endif
  81. } // namespace JSC
  82. #endif