MethodOfGettingAValueProfile.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. #ifndef MethodOfGettingAValueProfile_h
  26. #define MethodOfGettingAValueProfile_h
  27. #include <wtf/Platform.h>
  28. // This is guarded by ENABLE_DFG_JIT only because it uses some value profiles
  29. // that are currently only used if the DFG is enabled (i.e. they are not
  30. // available in the profile-only configuration). Hopefully someday all of
  31. // these #if's will disappear...
  32. #if ENABLE(DFG_JIT)
  33. #include "JSCJSValue.h"
  34. namespace JSC {
  35. class CodeBlock;
  36. class LazyOperandValueProfileKey;
  37. struct ValueProfile;
  38. class MethodOfGettingAValueProfile {
  39. public:
  40. MethodOfGettingAValueProfile()
  41. : m_kind(None)
  42. {
  43. }
  44. explicit MethodOfGettingAValueProfile(ValueProfile* profile)
  45. {
  46. if (profile) {
  47. m_kind = Ready;
  48. u.profile = profile;
  49. } else
  50. m_kind = None;
  51. }
  52. static MethodOfGettingAValueProfile fromLazyOperand(
  53. CodeBlock*, const LazyOperandValueProfileKey&);
  54. bool operator!() const { return m_kind == None; }
  55. // This logically has a pointer to a "There exists X such that
  56. // ValueProfileBase<X>". But since C++ does not have existential
  57. // templates, I cannot return it. So instead, for any methods that
  58. // users of this class would like to call, we'll just have to provide
  59. // a method here that does it through an indirection. Or we could
  60. // possibly just make ValueProfile less template-based. But last I
  61. // tried that, it felt more yucky than this class.
  62. EncodedJSValue* getSpecFailBucket(unsigned index) const;
  63. private:
  64. enum Kind {
  65. None,
  66. Ready,
  67. LazyOperand
  68. };
  69. Kind m_kind;
  70. union {
  71. ValueProfile* profile;
  72. struct {
  73. CodeBlock* codeBlock;
  74. unsigned bytecodeOffset;
  75. int operand;
  76. } lazyOperand;
  77. } u;
  78. };
  79. } // namespace JSC
  80. #endif // ENABLE(DFG_JIT)
  81. #endif // MethodOfGettingAValueProfile_h