Watchpoint.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * Copyright (C) 2012 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. #include "config.h"
  26. #include "Watchpoint.h"
  27. #include "JumpReplacementWatchpoint.h"
  28. #include "LinkBuffer.h"
  29. #include "StructureStubClearingWatchpoint.h"
  30. #include <wtf/PassRefPtr.h>
  31. namespace JSC {
  32. Watchpoint::~Watchpoint()
  33. {
  34. if (isOnList())
  35. remove();
  36. }
  37. #if ENABLE(JIT) && ENABLE(DETACHED_JIT)
  38. void Watchpoint::fire()
  39. {
  40. switch(m_type) {
  41. case e_StrutureStubClearingType:
  42. reinterpret_cast<StructureStubClearingWatchpoint *>(this)->fireInternal();
  43. break;
  44. #if !BUILDING_DETACHED_JIT
  45. case e_JumpReplacementType:
  46. reinterpret_cast<JumpReplacementWatchpoint *>(this)->fireInternal();
  47. break;
  48. #endif
  49. default:
  50. __builtin_trap();
  51. break;
  52. }
  53. return;
  54. }
  55. #endif
  56. WatchpointSet::WatchpointSet(InitialWatchpointSetMode mode)
  57. : m_isWatched(mode == InitializedWatching)
  58. , m_isInvalidated(false)
  59. {
  60. }
  61. WatchpointSet::~WatchpointSet()
  62. {
  63. // Fire all watchpoints. This is necessary because it is possible, say with
  64. // structure watchpoints, for the watchpoint set owner to die while the
  65. // watchpoint owners are still live.
  66. fireAllWatchpoints();
  67. }
  68. void WatchpointSet::add(Watchpoint* watchpoint)
  69. {
  70. if (!watchpoint)
  71. return;
  72. m_set.push(watchpoint);
  73. m_isWatched = true;
  74. }
  75. void WatchpointSet::notifyWriteSlow()
  76. {
  77. ASSERT(m_isWatched);
  78. fireAllWatchpoints();
  79. m_isWatched = false;
  80. m_isInvalidated = true;
  81. }
  82. void WatchpointSet::fireAllWatchpoints()
  83. {
  84. while (!m_set.isEmpty())
  85. m_set.begin()->fire();
  86. }
  87. void InlineWatchpointSet::add(Watchpoint* watchpoint)
  88. {
  89. inflate()->add(watchpoint);
  90. }
  91. WatchpointSet* InlineWatchpointSet::inflateSlow()
  92. {
  93. ASSERT(isThin());
  94. WatchpointSet* fat = adoptRef(new WatchpointSet(InitializedBlind)).leakRef();
  95. if (m_data & IsInvalidatedFlag)
  96. fat->m_isInvalidated = true;
  97. if (m_data & IsWatchedFlag)
  98. fat->m_isWatched = true;
  99. m_data = bitwise_cast<uintptr_t>(fat);
  100. return fat;
  101. }
  102. void InlineWatchpointSet::freeFat()
  103. {
  104. ASSERT(isFat());
  105. fat()->deref();
  106. }
  107. } // namespace JSC