LLIntData.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. #include "config.h"
  26. #include "LLIntData.h"
  27. #if ENABLE(LLINT)
  28. #include "BytecodeConventions.h"
  29. #include "CodeType.h"
  30. #include "Instruction.h"
  31. #include "LLIntCLoop.h"
  32. #include "Opcode.h"
  33. namespace JSC { namespace LLInt {
  34. Instruction* Data::s_exceptionInstructions = 0;
  35. Opcode* Data::s_opcodeMap = 0;
  36. void initialize()
  37. {
  38. Data::s_exceptionInstructions = new Instruction[maxOpcodeLength + 1];
  39. #if ENABLE(DETACHED_JIT)
  40. if (JSCBridge::sharedInstance()->jitBridge()) {
  41. void * sharedBuffer = JITSharedDataMemory::shared_malloc(sizeof(Opcode) * numOpcodeIDs);
  42. Data::s_opcodeMap = new(sharedBuffer) Opcode[numOpcodeIDs];
  43. } else {
  44. Data::s_opcodeMap = new Opcode[numOpcodeIDs];
  45. }
  46. #else
  47. Data::s_opcodeMap = new Opcode[numOpcodeIDs];
  48. #endif
  49. #if ENABLE(LLINT_C_LOOP)
  50. CLoop::initialize();
  51. #else // !ENABLE(LLINT_C_LOOP)
  52. for (int i = 0; i < maxOpcodeLength + 1; ++i)
  53. Data::s_exceptionInstructions[i].u.pointer =
  54. LLInt::getCodePtr(llint_throw_from_slow_path_trampoline);
  55. #define OPCODE_ENTRY(opcode, length) \
  56. Data::s_opcodeMap[opcode] = LLInt::getCodePtr(llint_##opcode);
  57. FOR_EACH_OPCODE_ID(OPCODE_ENTRY);
  58. #undef OPCODE_ENTRY
  59. #endif // !ENABLE(LLINT_C_LOOP)
  60. }
  61. #if COMPILER(CLANG)
  62. #pragma clang diagnostic push
  63. #pragma clang diagnostic ignored "-Wmissing-noreturn"
  64. #endif
  65. void Data::performAssertions(VM& vm)
  66. {
  67. UNUSED_PARAM(vm);
  68. // Assertions to match LowLevelInterpreter.asm. If you change any of this code, be
  69. // prepared to change LowLevelInterpreter.asm as well!!
  70. ASSERT(JSStack::CallFrameHeaderSize * 8 == 48);
  71. ASSERT(JSStack::ArgumentCount * 8 == -48);
  72. ASSERT(JSStack::CallerFrame * 8 == -40);
  73. ASSERT(JSStack::Callee * 8 == -32);
  74. ASSERT(JSStack::ScopeChain * 8 == -24);
  75. ASSERT(JSStack::ReturnPC * 8 == -16);
  76. ASSERT(JSStack::CodeBlock * 8 == -8);
  77. ASSERT(CallFrame::argumentOffsetIncludingThis(0) == -JSStack::CallFrameHeaderSize - 1);
  78. #if CPU(BIG_ENDIAN)
  79. ASSERT(OBJECT_OFFSETOF(EncodedValueDescriptor, asBits.tag) == 0);
  80. ASSERT(OBJECT_OFFSETOF(EncodedValueDescriptor, asBits.payload) == 4);
  81. #else
  82. ASSERT(OBJECT_OFFSETOF(EncodedValueDescriptor, asBits.tag) == 4);
  83. ASSERT(OBJECT_OFFSETOF(EncodedValueDescriptor, asBits.payload) == 0);
  84. #endif
  85. #if USE(JSVALUE32_64)
  86. ASSERT(JSValue::Int32Tag == static_cast<unsigned>(-1));
  87. ASSERT(JSValue::BooleanTag == static_cast<unsigned>(-2));
  88. ASSERT(JSValue::NullTag == static_cast<unsigned>(-3));
  89. ASSERT(JSValue::UndefinedTag == static_cast<unsigned>(-4));
  90. ASSERT(JSValue::CellTag == static_cast<unsigned>(-5));
  91. ASSERT(JSValue::EmptyValueTag == static_cast<unsigned>(-6));
  92. ASSERT(JSValue::DeletedValueTag == static_cast<unsigned>(-7));
  93. ASSERT(JSValue::LowestTag == static_cast<unsigned>(-7));
  94. #else
  95. ASSERT(TagBitTypeOther == 0x2);
  96. ASSERT(TagBitBool == 0x4);
  97. ASSERT(TagBitUndefined == 0x8);
  98. ASSERT(ValueEmpty == 0x0);
  99. ASSERT(ValueFalse == (TagBitTypeOther | TagBitBool));
  100. ASSERT(ValueTrue == (TagBitTypeOther | TagBitBool | 1));
  101. ASSERT(ValueUndefined == (TagBitTypeOther | TagBitUndefined));
  102. ASSERT(ValueNull == TagBitTypeOther);
  103. #endif
  104. ASSERT(StringType == 5);
  105. ASSERT(ObjectType == 17);
  106. ASSERT(MasqueradesAsUndefined == 1);
  107. ASSERT(ImplementsHasInstance == 2);
  108. ASSERT(ImplementsDefaultHasInstance == 8);
  109. ASSERT(FirstConstantRegisterIndex == 0x40000000);
  110. ASSERT(GlobalCode == 0);
  111. ASSERT(EvalCode == 1);
  112. ASSERT(FunctionCode == 2);
  113. // FIXME: make these assertions less horrible.
  114. #if !ASSERT_DISABLED
  115. Vector<int> testVector;
  116. testVector.resize(42);
  117. ASSERT(bitwise_cast<uint32_t*>(&testVector)[sizeof(void*)/sizeof(uint32_t) + 1] == 42);
  118. ASSERT(bitwise_cast<int**>(&testVector)[0] == testVector.begin());
  119. #endif
  120. ASSERT(StringImpl::s_hashFlag8BitBuffer == 64);
  121. }
  122. #if COMPILER(CLANG)
  123. #pragma clang diagnostic pop
  124. #endif
  125. } } // namespace JSC::LLInt
  126. #endif // ENABLE(LLINT)