StructureStubInfo.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. /*
  2. * Copyright (C) 2008, 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 StructureStubInfo_h
  26. #define StructureStubInfo_h
  27. #include <wtf/Platform.h>
  28. #if ENABLE(JIT)
  29. #include "CodeOrigin.h"
  30. #include "DFGRegisterSet.h"
  31. #include "Instruction.h"
  32. #include "JITStubRoutine.h"
  33. #include "MacroAssembler.h"
  34. #include "Opcode.h"
  35. #include "PolymorphicAccessStructureList.h"
  36. #include "Structure.h"
  37. #include "StructureStubClearingWatchpoint.h"
  38. #include <wtf/OwnPtr.h>
  39. namespace JSC {
  40. class PolymorphicPutByIdList;
  41. enum AccessType {
  42. access_get_by_id_self,
  43. access_get_by_id_proto,
  44. access_get_by_id_chain,
  45. access_get_by_id_self_list,
  46. access_get_by_id_proto_list,
  47. access_put_by_id_transition_normal,
  48. access_put_by_id_transition_direct,
  49. access_put_by_id_replace,
  50. access_put_by_id_list,
  51. access_unset,
  52. access_get_by_id_generic,
  53. access_put_by_id_generic,
  54. access_get_array_length,
  55. access_get_string_length,
  56. };
  57. inline bool isGetByIdAccess(AccessType accessType)
  58. {
  59. switch (accessType) {
  60. case access_get_by_id_self:
  61. case access_get_by_id_proto:
  62. case access_get_by_id_chain:
  63. case access_get_by_id_self_list:
  64. case access_get_by_id_proto_list:
  65. case access_get_by_id_generic:
  66. case access_get_array_length:
  67. case access_get_string_length:
  68. return true;
  69. default:
  70. return false;
  71. }
  72. }
  73. inline bool isPutByIdAccess(AccessType accessType)
  74. {
  75. switch (accessType) {
  76. case access_put_by_id_transition_normal:
  77. case access_put_by_id_transition_direct:
  78. case access_put_by_id_replace:
  79. case access_put_by_id_list:
  80. case access_put_by_id_generic:
  81. return true;
  82. default:
  83. return false;
  84. }
  85. }
  86. struct StructureStubInfo {
  87. StructureStubInfo()
  88. : accessType(access_unset)
  89. , seen(false)
  90. , resetByGC(false)
  91. {
  92. }
  93. void initGetByIdSelf(VM& vm, JSCell* owner, Structure* baseObjectStructure)
  94. {
  95. accessType = access_get_by_id_self;
  96. u.getByIdSelf.baseObjectStructure.set(vm, owner, baseObjectStructure);
  97. }
  98. void initGetByIdProto(VM& vm, JSCell* owner, Structure* baseObjectStructure, Structure* prototypeStructure, bool isDirect)
  99. {
  100. accessType = access_get_by_id_proto;
  101. u.getByIdProto.baseObjectStructure.set(vm, owner, baseObjectStructure);
  102. u.getByIdProto.prototypeStructure.set(vm, owner, prototypeStructure);
  103. u.getByIdProto.isDirect = isDirect;
  104. }
  105. void initGetByIdChain(VM& vm, JSCell* owner, Structure* baseObjectStructure, StructureChain* chain, unsigned count, bool isDirect)
  106. {
  107. accessType = access_get_by_id_chain;
  108. u.getByIdChain.baseObjectStructure.set(vm, owner, baseObjectStructure);
  109. u.getByIdChain.chain.set(vm, owner, chain);
  110. u.getByIdChain.count = count;
  111. u.getByIdChain.isDirect = isDirect;
  112. }
  113. void initGetByIdSelfList(PolymorphicAccessStructureList* structureList, int listSize)
  114. {
  115. accessType = access_get_by_id_self_list;
  116. u.getByIdSelfList.structureList = structureList;
  117. u.getByIdSelfList.listSize = listSize;
  118. }
  119. void initGetByIdProtoList(PolymorphicAccessStructureList* structureList, int listSize)
  120. {
  121. accessType = access_get_by_id_proto_list;
  122. u.getByIdProtoList.structureList = structureList;
  123. u.getByIdProtoList.listSize = listSize;
  124. }
  125. // PutById*
  126. void initPutByIdTransition(VM& vm, JSCell* owner, Structure* previousStructure, Structure* structure, StructureChain* chain, bool isDirect)
  127. {
  128. if (isDirect)
  129. accessType = access_put_by_id_transition_direct;
  130. else
  131. accessType = access_put_by_id_transition_normal;
  132. u.putByIdTransition.previousStructure.set(vm, owner, previousStructure);
  133. u.putByIdTransition.structure.set(vm, owner, structure);
  134. u.putByIdTransition.chain.set(vm, owner, chain);
  135. }
  136. void initPutByIdReplace(VM& vm, JSCell* owner, Structure* baseObjectStructure)
  137. {
  138. accessType = access_put_by_id_replace;
  139. u.putByIdReplace.baseObjectStructure.set(vm, owner, baseObjectStructure);
  140. }
  141. void initPutByIdList(PolymorphicPutByIdList* list)
  142. {
  143. accessType = access_put_by_id_list;
  144. u.putByIdList.list = list;
  145. }
  146. void reset()
  147. {
  148. deref();
  149. accessType = access_unset;
  150. stubRoutine.clear();
  151. watchpoints.clear();
  152. }
  153. void deref();
  154. bool visitWeakReferences();
  155. bool seenOnce()
  156. {
  157. return seen;
  158. }
  159. void setSeen()
  160. {
  161. seen = true;
  162. }
  163. StructureStubClearingWatchpoint* addWatchpoint(CodeBlock* codeBlock)
  164. {
  165. return WatchpointsOnStructureStubInfo::ensureReferenceAndAddWatchpoint(
  166. watchpoints, codeBlock, this);
  167. }
  168. unsigned bytecodeIndex;
  169. int8_t accessType;
  170. bool seen : 1;
  171. bool resetByGC : 1;
  172. #if ENABLE(DFG_JIT)
  173. CodeOrigin codeOrigin;
  174. #endif // ENABLE(DFG_JIT)
  175. union {
  176. struct {
  177. int8_t registersFlushed;
  178. int8_t baseGPR;
  179. #if USE(JSVALUE32_64)
  180. int8_t valueTagGPR;
  181. #endif
  182. int8_t valueGPR;
  183. DFG::RegisterSetPOD usedRegisters;
  184. int32_t deltaCallToDone;
  185. int32_t deltaCallToStorageLoad;
  186. int32_t deltaCallToStructCheck;
  187. int32_t deltaCallToSlowCase;
  188. int32_t deltaCheckImmToCall;
  189. #if USE(JSVALUE64)
  190. int32_t deltaCallToLoadOrStore;
  191. #else
  192. int32_t deltaCallToTagLoadOrStore;
  193. int32_t deltaCallToPayloadLoadOrStore;
  194. #endif
  195. } dfg;
  196. struct {
  197. union {
  198. struct {
  199. int16_t structureToCompare;
  200. int16_t structureCheck;
  201. int16_t propertyStorageLoad;
  202. #if USE(JSVALUE64)
  203. int16_t displacementLabel;
  204. #else
  205. int16_t displacementLabel1;
  206. int16_t displacementLabel2;
  207. #endif
  208. int16_t putResult;
  209. int16_t coldPathBegin;
  210. } get;
  211. struct {
  212. int16_t structureToCompare;
  213. int16_t propertyStorageLoad;
  214. #if USE(JSVALUE64)
  215. int16_t displacementLabel;
  216. #else
  217. int16_t displacementLabel1;
  218. int16_t displacementLabel2;
  219. #endif
  220. } put;
  221. } u;
  222. int16_t methodCheckProtoObj;
  223. int16_t methodCheckProtoStructureToCompare;
  224. int16_t methodCheckPutFunction;
  225. } baseline;
  226. } patch;
  227. union {
  228. struct {
  229. // It would be unwise to put anything here, as it will surely be overwritten.
  230. } unset;
  231. struct {
  232. WriteBarrierBase<Structure> baseObjectStructure;
  233. } getByIdSelf;
  234. struct {
  235. WriteBarrierBase<Structure> baseObjectStructure;
  236. WriteBarrierBase<Structure> prototypeStructure;
  237. bool isDirect;
  238. } getByIdProto;
  239. struct {
  240. WriteBarrierBase<Structure> baseObjectStructure;
  241. WriteBarrierBase<StructureChain> chain;
  242. unsigned count : 31;
  243. bool isDirect : 1;
  244. } getByIdChain;
  245. struct {
  246. PolymorphicAccessStructureList* structureList;
  247. int listSize;
  248. } getByIdSelfList;
  249. struct {
  250. PolymorphicAccessStructureList* structureList;
  251. int listSize;
  252. } getByIdProtoList;
  253. struct {
  254. WriteBarrierBase<Structure> previousStructure;
  255. WriteBarrierBase<Structure> structure;
  256. WriteBarrierBase<StructureChain> chain;
  257. } putByIdTransition;
  258. struct {
  259. WriteBarrierBase<Structure> baseObjectStructure;
  260. } putByIdReplace;
  261. struct {
  262. PolymorphicPutByIdList* list;
  263. } putByIdList;
  264. } u;
  265. RefPtr<JITStubRoutine> stubRoutine;
  266. CodeLocationCall callReturnLocation;
  267. CodeLocationLabel hotPathBegin;
  268. RefPtr<WatchpointsOnStructureStubInfo> watchpoints;
  269. };
  270. inline void* getStructureStubInfoReturnLocation(StructureStubInfo* structureStubInfo)
  271. {
  272. return structureStubInfo->callReturnLocation.executableAddress();
  273. }
  274. inline unsigned getStructureStubInfoBytecodeIndex(StructureStubInfo* structureStubInfo)
  275. {
  276. return structureStubInfo->bytecodeIndex;
  277. }
  278. } // namespace JSC
  279. #endif // ENABLE(JIT)
  280. #endif // StructureStubInfo_h