JSCBridgeVM.cpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. // Copyright (C) 2012 Sony Computer Entertainment Inc.
  2. // All Rights Reserved.
  3. #include "config.h"
  4. #if ENABLE(JIT)
  5. #if ENABLE(DETACHED_JIT) && !BUILDING_DETACHED_JIT
  6. #include "JSCBridge.h"
  7. #include "dfg/DFGOperations.h"
  8. #include "dfg/DFGOSRExitCompiler.h"
  9. #include "dfg/DFGSpeculativeJIT.h"
  10. #include "AbstractMacroAssembler.h"
  11. #include "Arguments.h"
  12. #include "ArrayConstructor.h"
  13. #include "ArrayPrototype.h"
  14. #include "AssemblerBuffer.h"
  15. #include "BooleanConstructor.h"
  16. #include "DateConstructor.h"
  17. #include "DateInstance.h"
  18. #include "DatePrototype.h"
  19. #include "Error.h"
  20. #include "ErrorConstructor.h"
  21. #include "FunctionConstructor.h"
  22. #include "FunctionPrototype.h"
  23. #include "InternalFunction.h"
  24. #include "InitializeThreading.h"
  25. #include "JIT.h"
  26. #include "JITStubEntries.h"
  27. #include "JSActivation.h"
  28. #include "JSArray.h"
  29. #include "JSBoundFunction.h"
  30. #include "JSCBridgeToll.h"
  31. #include "JSFunction.h"
  32. #include "JSGlobalObject.h"
  33. #include "LinkBuffer.h"
  34. #include "Logging.h"
  35. #include "MacroAssembler.h"
  36. #include "MathObject.h"
  37. #include "NativeErrorConstructor.h"
  38. #include "NumberConstructor.h"
  39. #include "ObjectConstructor.h"
  40. #include "ObjectPrototype.h"
  41. #include "RegExpConstructor.h"
  42. #include "RegExpPrototype.h"
  43. #include "RepatchBuffer.h"
  44. #include "StringConstructor.h"
  45. #include "ThunkGenerators.h"
  46. #include "YarrJIT.h"
  47. #include <JITBridge.h>
  48. #if !defined(NDEBUG)
  49. #define DEBUG_LOG(x, ...) fprintf(stderr, "[JSC bridge VM] " x, __VA_ARGS__)
  50. #define DEBUG_ERR(x, ...) fprintf(stderr, "[JSC bridge VM] " x, __VA_ARGS__)
  51. #else
  52. #define DEBUG_LOG(x, ...)
  53. #define DEBUG_ERR(x, ...)
  54. #endif
  55. namespace JSC {
  56. JSCBridgeToll * JSCBridge::createToll(Payload * payload)
  57. {
  58. return new JSCBridgeToll(payload);
  59. }
  60. void JSCBridge::initializeFromCompiler(char const * vmTestApp, char ** vmTestAppArgs, JITBridge::RestartData const *)
  61. {
  62. // you MUST NOT call this from the VM process
  63. __builtin_trap();
  64. }
  65. void JSCBridge::initializeFromVM(char const * compilerApp, char ** compilerArgs, JITBridge::RestartData const * restartData)
  66. {
  67. if (m_processType != ProcessUnknown) {
  68. return;
  69. }
  70. m_processType = ProcessVM;
  71. m_sharedBridge = JITBridge::initializeFromVM(compilerApp, compilerArgs, restartData);
  72. initializeSharedData();
  73. // VM<->Compiler handshake
  74. {
  75. using namespace DFG;
  76. JSC::JSCBridge::StaticVMData * vmData(this->staticVMData());
  77. memset(vmData, 0, sizeof(JSC::JSCBridge::StaticVMData));
  78. vmData->m_ctiVMThrowTrampoline = reinterpret_cast<uintptr_t>(ctiVMThrowTrampoline);
  79. vmData->m_oneConstant = reinterpret_cast<uintptr_t>(&JSC::oneConstant);
  80. vmData->m_zeroConstant = reinterpret_cast<uintptr_t>(&JSC::zeroConstant);
  81. vmData->m_halfConstant = reinterpret_cast<uintptr_t>(&JSC::halfConstant);
  82. vmData->m_negativeHalfConstant = reinterpret_cast<uintptr_t>(&JSC::negativeHalfConstant);
  83. vmData->m_negativeZeroConstant = reinterpret_cast<uintptr_t>(&JSC::negativeZeroConstant);
  84. vmData->m_NaN = reinterpret_cast<uintptr_t>(&JSC::NaN);
  85. vmData->m_twoToThe32 = reinterpret_cast<uintptr_t>(&JSC::twoToThe32);
  86. vmData->m_byteMax = reinterpret_cast<uintptr_t>(&JSC::byteMax);
  87. vmData->m_regExpSpacesData = reinterpret_cast<uintptr_t>(JSC::Yarr::regExp_spacesData);
  88. vmData->m_regExpWordCharData = reinterpret_cast<uintptr_t>(JSC::Yarr::regExp_wordcharData);
  89. size_t runtimeClassInfoCount(0);
  90. RuntimeClassInfo * runtimeClassInfo(registerRuntimeClassinfo(NULL, &runtimeClassInfoCount));
  91. if (runtimeClassInfo && runtimeClassInfoCount) {
  92. DEBUG_LOG("transferring %zd instances of class information to the shared heap\n", runtimeClassInfoCount);
  93. ASSERT(sizeof(vmData->m_runtimeClassInfo) >= runtimeClassInfoCount * sizeof(RuntimeClassInfo));
  94. memcpy(vmData->m_runtimeClassInfo, runtimeClassInfo, runtimeClassInfoCount * sizeof(RuntimeClassInfo));
  95. vmData->m_runtimeClassInfoCount = runtimeClassInfoCount ;
  96. }
  97. #define CTI_STUB_ENTRY(ignoredReturnType, stub) vmData->m_##stub = reinterpret_cast<uintptr_t>(stub)
  98. CTI_STUB_ENTRIES;
  99. #if ENABLE(LLINT)
  100. CTI_STUB_ENTRIES_LLINT;
  101. #endif
  102. #if ENABLE(DFG_JIT)
  103. CTI_STUB_ENTRIES_DFG;
  104. CTI_STUB_ENTRIES_DFG_OPERATIONS;
  105. #endif
  106. #undef CTI_STUB_ENTRY
  107. #define CLASSINFO_STUB_ENTRY(classname) { \
  108. vmData->m_##classname##_classinfo = reinterpret_cast<uintptr_t>(& JSC::classname::s_info); \
  109. }
  110. CLASSINFO_STUB_ENTRIES;
  111. #undef CLASSINFO_STUB_ENTRY
  112. // wait for compiler to prepare shared data arenas
  113. waitDoorbell();
  114. // executable allocators can only be initialized when shared data arenas are ready
  115. vmData->m_executableAllocator = reinterpret_cast<uintptr_t>(ExecutableAllocator::metaAllocator());
  116. // notify compiler all VM data that the compiler needs are ready
  117. ringDoorbell();
  118. // wait for compiler to prepare all data the VM needs
  119. waitDoorbell();
  120. }
  121. }
  122. void JSCBridge::performCompilerTask()
  123. {
  124. // you MUST NOT call this from the VM process
  125. __builtin_trap();
  126. }
  127. JSCBridge::RuntimeClassInfo * JSCBridge::registerRuntimeClassinfo(ClassInfo const * classInfo, size_t * total)
  128. {
  129. static RuntimeClassInfo s_runtimeClassInfo[s_jscbridgeRuntimeClassInfoMax]; // stores runtime registered ClassInfo instances defined outside of JSC (i.e. when WebCore uses JSC ClassInfo to define object class)
  130. static size_t s_runtimeClassInfoCount = 0;
  131. if (classInfo) {
  132. // allocate slot for class info
  133. size_t slot(s_runtimeClassInfoCount++);
  134. if (s_runtimeClassInfoCount >= s_jscbridgeRuntimeClassInfoMax) {
  135. DEBUG_ERR("dynamic class info registration full! current size = %zd\n", s_jscbridgeRuntimeClassInfoMax);
  136. __builtin_trap();
  137. return 0;
  138. }
  139. //DEBUG_LOG("registering runtime ClassInfo %lx : %s\n", (uintptr_t)classInfo, classInfo->className);
  140. s_runtimeClassInfo[slot].m_classInfoPtr = reinterpret_cast<uintptr_t>(classInfo);
  141. COMPILE_ASSERT(sizeof(s_runtimeClassInfo[slot].m_data) == sizeof(*classInfo), RuntimeClassInfo_mData_LargeEnough);
  142. memcpy(&(s_runtimeClassInfo[slot].m_data[0]), classInfo, sizeof(*classInfo));
  143. }
  144. if (total) *total = s_runtimeClassInfoCount;
  145. return s_runtimeClassInfo;
  146. }
  147. uintptr_t JSCBridge::requestCompilerTask(CompilerFunction compilerFunction)
  148. {
  149. FUNCTION_MARKER;
  150. Payload * const payload(&(m_sharedData->m_payload));
  151. payload->m_compilerFunction = compilerFunction;
  152. ringDoorbell();
  153. waitDoorbell();
  154. return m_sharedData->m_payload.m_retval;
  155. }
  156. } // namespace JSC
  157. #endif // #if ENABLE(DETACHED_JIT) && !BUILDING_DETACHED_JIT
  158. #endif // #if ENABLE(JIT)