8733cdc4f3
Most of the SpillStacks we do are just to keep the in-memory VM stack clean in case a helper call throws an exception. Many of these exceptions are vanishingly rare, so let's stop making the fast path slower for them. This diff adds support for catch traces, which are just like normal exit traces with one major exception: they're never jumped to from translated code. If we're unwinding a TC frame and discover that the current rip has a catch trace registered, the unwinder will execute it before resuming unwinding. The unwinder parts were fairly straightfoward, then I ran into a bunch of issues with SetM. The SetElem instruction sometimes consumes a reference to one of its inputs, which is bad news for our optimizations. To make everything work again, I changed SetElem to throw an exception in cases where it would've previously decreffed the value input. This is a special exception that the new unwinding code recognizes. When one of these is caught, the catch trace executed for that TC frame will finish up the vector instruction and push the value provided by the exception on the stack. This allows us to optimize most traces under the assumption that SetM's output is the same as its input, letting the catch trace clean things up if the helper decides that's not the case and throws. There is one common case where SetM's output isn't the same as its input: setting an offset in a string base returns a new String. Luckily, we can detect most of these at compile time so SetElem returns a new StringData* when the base is known to be a string. If the base might be a string, SetElem will return nullptr if the base wasn't a string, and a StringData* if it was. We test the output in these cases and side exit if the return value of SetElem is non-null (I have yet to see this side exit happen outside of artificially created test cases). Once I got things working in the vector translator, I went through every other call to spillStack and exceptionBarrier, replacing them with catch traces as appropriate.
63 linhas
2.0 KiB
C++
63 linhas
2.0 KiB
C++
/*
|
|
+----------------------------------------------------------------------+
|
|
| HipHop for PHP |
|
|
+----------------------------------------------------------------------+
|
|
| Copyright (c) 2010- Facebook, Inc. (http://www.facebook.com) |
|
|
+----------------------------------------------------------------------+
|
|
| This source file is subject to version 3.01 of the PHP license, |
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
| available through the world-wide-web at the following url: |
|
|
| http://www.php.net/license/3_01.txt |
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
| license@php.net so we can mail you a copy immediately. |
|
|
+----------------------------------------------------------------------+
|
|
*/
|
|
|
|
#include "hphp/runtime/vm/translator/physreg.h"
|
|
|
|
namespace HPHP { namespace Transl {
|
|
|
|
PhysRegSaverParity::PhysRegSaverParity(int parity, X64Assembler& as,
|
|
RegSet regs)
|
|
: m_as(as)
|
|
, m_regs(regs)
|
|
, m_adjust((parity & 0x1) == (regs.size() & 0x1) ? 8 : 0)
|
|
{
|
|
m_regs.forEach([&] (PhysReg pr) {
|
|
m_as. push (pr);
|
|
});
|
|
if (m_adjust) {
|
|
// Maintain stack evenness for SIMD compatibility.
|
|
m_as. subq (m_adjust, reg::rsp);
|
|
}
|
|
}
|
|
|
|
PhysRegSaverParity::~PhysRegSaverParity() {
|
|
if (m_adjust) {
|
|
// See above; stack parity.
|
|
m_as. addq (m_adjust, reg::rsp);
|
|
}
|
|
emitPops(m_as, m_regs);
|
|
}
|
|
|
|
void PhysRegSaverParity::emitPops(X64Assembler& as, RegSet regs) {
|
|
regs.forEachR([&] (PhysReg pr) {
|
|
as. pop (pr);
|
|
});
|
|
}
|
|
|
|
int PhysRegSaverParity::rspAdjustment() const {
|
|
return m_adjust;
|
|
}
|
|
|
|
int PhysRegSaverParity::rspTotalAdjustmentRegs() const {
|
|
return m_regs.size() + m_adjust / sizeof(int64_t);
|
|
}
|
|
|
|
void PhysRegSaverParity::bytesPushed(int64_t bytes) {
|
|
m_adjust += bytes;
|
|
}
|
|
|
|
} }
|