Switch-related cleanup
[hiphop-php.git] / hphp / runtime / vm / jit / unique-stubs.h
blob7a170b860a62389061339f7097cdb80c032a72c7
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2014 Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
16 #ifndef incl_HPHP_JIT_UNIQUE_STUBS_H_
17 #define incl_HPHP_JIT_UNIQUE_STUBS_H_
19 #include "hphp/runtime/base/datatype.h"
20 #include "hphp/runtime/vm/hhbc.h"
21 #include "hphp/runtime/vm/jit/types.h"
23 namespace HPHP { namespace jit {
25 //////////////////////////////////////////////////////////////////////
28 constexpr int kNumFreeLocalsHelpers = 9;
31 * Addresses of various unique, long-lived JIT helper routines are
32 * emitted when we first start up our code cache.
34 struct UniqueStubs {
36 * Stub that returns from this level VM-nesting to the previous one,
37 * with whatever value is on the top of the stack.
39 TCA callToExit;
42 * Returning from a function when the ActRec was pushed by the interpreter.
43 * The return IP on the ActRec will be set to one of these stubs, so if
44 * someone tries to execute a return instruction, we get a chance to set up
45 * state for a POST_INTERP_RET service request.
47 * Generators need a different stub because the ActRec for a generator is in
48 * the heap.
50 TCA retHelper;
51 TCA genRetHelper; // version for generators
54 * Returning from a function when the ActRec was called from jitted code but
55 * had its m_savedRip smashed by the debugger. These stubs call a helper that
56 * looks up the original catch trace from the call, executes it, then executes
57 * a REQ_POST_DEBUGGER_RET.
59 TCA debuggerRetHelper;
60 TCA debuggerGenRetHelper;
63 * Returning from a function where the ActRec was pushed by an
64 * inlined call. This is the same as retHelper but separated just
65 * for debugability.
67 TCA retInlHelper;
70 * Helpers used for restarting execution based on the value of PC, after
71 * things like InterpOne of an instruction that changes PC. Assumes all VM
72 * regs are synced.
74 TCA resumeHelperRet;
75 TCA resumeHelper;
78 * Like resumeHelper, but interpret a basic block first to ensure we make
79 * forward progress. interpHelper expects the correct value of vmpc to be in
80 * the first argument register, and interpHelperSyncedPC expects vmpc to
81 * already be synced. Both stubs will sync the sp and fp registers to vmRegs
82 * before interpreting.
84 TCA interpHelper;
85 TCA interpHelperSyncedPC;
88 * For every bytecode with the CF flag, a stub will exist here to interpOne
89 * that bytecode, followed by a call to resumeHelper. The stubs expect rVmFp
90 * and rVmSp to be live, and rAsm must contain the offset to the bytecode to
91 * interpret.
93 std::unordered_map<Op, TCA> interpOneCFHelpers;
96 * Throw a VMSwitchMode exception. Used in
97 * bytecode.cpp:switchModeForDebugger().
99 TCA throwSwitchMode;
102 * Catch blocks jump to endCatchHelper when they've finished executing. If
103 * the unwinder has set state indicating a return address to jump to, this
104 * stub will load vmfp and vmsp and jump there. Otherwise, it calls
105 * unwindResumeHelper.
107 TCA endCatchHelper;
108 TCA endCatchHelperPast;
111 * Helper stubs for doing generic decrefs on a function return. The
112 * stub is a partially-unrolled loop with kNumFreeLocalsHelpers
113 * points to call to. The freeManyLocalsHelper entry point should
114 * be used when there's more locals than that.
116 TCA freeManyLocalsHelper;
117 TCA freeLocalsHelpers[kNumFreeLocalsHelpers];
120 * When we enter a func prologue based on a prediction of which
121 * Func* we'll be calling, if the prediction was wrong we bail to
122 * this stub to redispatch.
124 TCA funcPrologueRedispatch;
127 * Utility routine that helps implement a fast path to avoid full VM
128 * re-entry during translations of Op::FCallArray.
130 TCA fcallArrayHelper;
133 * The stub we jump to when a stack overflow check fails.
135 TCA stackOverflowHelper;
138 * A Func's prologue table is initialized to this stub for every entry. The
139 * stub calls fcallHelper, which looks up or generates the appropriate
140 * prologue and returns it. The stub then dispatches to the prologue.
142 TCA fcallHelperThunk;
145 * A Func's "function body entry point" is initialized to this stub. The stub
146 * calls funcBodyHelper, which creates a real translation. The stub then
147 * dispatches to the translation.
149 TCA funcBodyHelperThunk;
152 * Calls EventHook::onFunctionEnter, and handles the case where it requests
153 * that we skip the function. functionEnterHelperReturn is used by unwinder
154 * code that needs to detect calls made from this stub.
156 TCA functionEnterHelper;
157 TCA functionEnterHelperReturn;
160 * BindCall stubs for immutable/non-immutable calls
162 TCA bindCallStub;
163 TCA immutableBindCallStub;
166 * Utility for logging stubs addresses during startup and registering the gdb
167 * symbols. It's often useful to know where they were when debugging.
169 TCA add(const char* name, TCA start);
172 * If the given address is within one of the registered stubs, return a
173 * string indicating which stub and how far in it is:
174 * "fcallArrayHelper+0xfa". Otherwise, return a string representation of the
175 * raw address: "0xabcdef".
177 std::string describe(TCA addr);
179 private:
180 struct StubRange {
181 std::string name;
182 TCA start, end;
184 bool operator<(const StubRange& other) const {
185 return start < other.start;
188 bool contains(TCA address) const {
189 return start <= address && address < end;
193 std::vector<StubRange> m_ranges;
196 //////////////////////////////////////////////////////////////////////
200 #endif