Gráfico de Commits

79 Commits

Autor SHA1 Mensagem Data
Mike Magruder ed8fb402c0 Improve the Next command to not interpret and single-step ever line under calls from the original source line
This improves both Next and Out to avoid interpreting and stepping everything between when they start and finish. Out now lets the program run free until a pseudo-breakpoint at the return site it hit. Next continues to single-step the source line being stepped over, but now lets the program run free under calls made from that line.

The logic in Next regarding "calls made from that line" is extremely generic. We don't look at, say, call opcodes and decide to do something special. Rather, when we find we're off the original source line and a frame deeper we setup a "step out" operation much like the Out command then let the program run free. When we reach our return point, we continue stepping like normal. This accounts for not just calls, but iterators, and anything else that causes more PHP to run under the original source line.

This change moves the flow control logic down in to the respective cmds: Next, Step, Out, Continue. These cmds get a crack at executing at various points in the interrupt/command processing path. These cmds now own setting up the last location filter, whether they need VM interrupts, and whether they're done or not.
2013-05-07 10:55:31 -07:00
Andrei Alexandrescu 11151fe1ea Eliminate unnecessary and unawesome instances of dynamic_cast<HphpArray*>
There are two dynamic_cast<HphpArray*> instances in bytecode.cpp that cause code to fail when using other types of arrays. However, the necessity of those casts seems to have disappeared in the meantime because simply removing them compiles and runs. I have ran full 'fbmake runtests' after removing the first cast (all passed). Then I removed the second cast (in lexical order) and ran the tests again. This time test/zend/good/ext-hash/hash_file_basic.php failed, but when I ran it again in separation it passed.
2013-05-02 10:14:16 -07:00
Drew Paroski a3620e7758 Remove hphp_get_iterator and related dead code
This code is no longer used, let's get rid of it.
2013-05-02 10:13:38 -07:00
Jordan DeLong effe6d71f3 Omit stack overflow checks on leaf functions
I did an experiment turning off all stack checks, and it
looks like it does cost something.  This seemed like an easy way to
turn it off some of the time, but maybe we should resurrect the SEGV
handler.
2013-05-01 21:00:48 -07:00
Drew Paroski 9a804f6463 Implement Set 2013-05-01 21:00:47 -07:00
jdelong b26e59a920 Inline the outer functions for continuations with no arguments
We store a bunch of data into an ActRec on the stack, then
call a php-level function that calls a C++ function to copy it into an
ActRec on the heap.  This should hopefully be a little better.
2013-05-01 20:59:45 -07:00
Mark Williams 6f4b1c76a8 Fix issue with call_user_func_array and by-ref params
We can't box a non-ref value for a ref param because
we could be modifying an array with refCount != 1.

zend warns, skips the call and returns null. For now, this
makes us warn, but do the call (without modifying the array).

A file scope flag controls whether to skip the call or not,
and should be changed (and eliminated) once all our tests pass.

With the flag turned on, we still dont match zend's behavior,
because its happy to go ahead and call the function with no
warning in the case of a literal array parameter
(cuf('foo', array(1))), even though it warns and skips it when
the array is in a variable ($a=array(1); cuf('foo', $a)).
2013-04-30 09:58:57 -07:00
jdelong 9749e6bd54 Initial support for inlining small functions
Sets up the translator analyze pass to create a Tracelet for
the callee at every statically-known FCall.  If the callee has an
appropriate shape (in this diff, it must be a function consisting of
"return $this->foo" for a declared property), we can inline it in
HHIR.  Restructures the IR relating to frames some so we can eliminate
the stores relating to ActRec in this simple case (see the comments in
dce.cpp and hhbctranslator.cpp for details).  Includes partial support
for inlining callees with locals, but it's disabled for now because
they will keep the frame live.
2013-04-26 12:59:48 -07:00
smith a73e674aea Litstr must die, episode IV.
Removed Array::remove(litstr).  Grouped the other litstr overloads
together and reimplemented each one in terms of the CStrRef overload.
2013-04-26 09:29:53 -07:00
Keith Adams 98483c74d6 Lift a lot of stuff out of HPHP::VM.
This is a partial step towards merging the HPHP::VM namespace
up into its parent. To keep it reviewable/mergeable I'm not doing
everything at once here, but most of the code I've touched seems
improved. I've drawn an invisible line around the jit, Unit and
its cohort (Class, Func, PreClass, etc.); we'll get back to them
soon.
2013-04-25 00:50:01 -07:00
Sean Cannella 54efa29d5f Fix off-by-one in multi-line function call traces
Fixes off-by-one in line number reporting in multi-line function calls
2013-04-24 22:32:36 -07:00
Mike Magruder 76db66ec82 Add comments to some of the debugger code to aid in understanding it more clearly, plus minor code cleanup.
Add a lot of comments to the debugger based on my current understanding of it. These may change in the future as we learn more, but they're helpful right now.

Also moved a few small things around in the code to clarify their purpose or scope. I.e., making a few things private, renaming a few functions, etc. No real logic changes, though. Also minor dead code removal. Also a few lint errors.
2013-04-23 09:52:57 -07:00
Jordan DeLong f650635e0b Define __STDC_FORMAT_MACROS in build configuration
Avoids some header order dependencies.
2013-04-22 14:43:51 -07:00
Mark Williams b28254c8f2 Fix a crash if an exception is thrown in a constructor's surprise check
The unwinder assumed that if the actrec's constructor flag
was set, then there must be a $this. But the $this is cleared during
the return sequence.
2013-04-22 14:43:48 -07:00
bsimmers 5d1c69b048 Revert Generator changes 2013-04-18 14:24:56 -07:00
mwilliams 6df0912bc0 Get rid of baseStrOff
It was unnecessary book keeping, and caused us to differ
from zend's behavior
2013-04-18 12:19:35 -07:00
mwilliams 5f9df0e7c6 Rework constants to use the target cache exclusively
Make the targetcache the one true home for constants,
so we dont need to (also) insert them all into
VMExecutionContext::m_constants (which is now gone).

By also making "non-volatile" constants persistent, we save
initializing most of them at all in RepoAuthoritative mode.
2013-04-18 12:19:05 -07:00
mikemag 5240dae6a9 Add a new option to control args in backtraces
Add Eval.EnableArgsInBacktraces, which defaults to !Repo.Authoritative. This allows us to test what happens when backtraces keep references to function arguments even when testing in authoritative mode. Modified the test harness to set this to true when using Repo.Authoritative.
2013-04-17 10:12:46 -07:00
jdelong cff9360510 Fix a bug in CreateCl, combine helper calls and use precoloring
The CreateCl translation dereferenced its targetcache handle
at compile time instead of in the TC, so we could get "class
undefined" errors if the targetcache slot in the thread that jitted it
didn't happen to have that closure defined.  Fix that, combine the two
helper calls, and use nativecalls so we get register precoloring.
2013-04-17 10:12:45 -07:00
mikemag 602b1bd64f Ensure C++ exceptions eventually propagate out of destructors.
This diff addresses what we called "step 1" in the task: simply ensure that any C++ exceptions that escape a destructor get rethrown and can continue to propagate naturally. The exception is remembered on the thread, and rethrown when we check for surprises later. If multiple destructors let C++ exceptions escape the last one to escape will be the one rethrown at the next surprise check.

This also ensures that C++ exceptions prevent more PHP code from running, by omitting calls to __destruct methods as we unwind the stack.

Finally, this also enables surprise checks for OnFunctionExit unless we're unwinding, in which case surprises remain unchecked so they can propagate later.

This is different than Zend's behavior, where destructors do run as fatals unwind.
2013-04-17 08:54:58 -07:00
ptarjan dd36937f94 new opcode CreateCl
This is the bottleneck for closure perf. Instead of all the code in the prologue, it turned out the expensive thing about closures was constructing them. This bypasses all the roundabout copying involved with __construct and makes a new opcode to do the same thing.
2013-04-15 13:01:49 -07:00
kma 197305cc45 HHIR mod. 2013-04-12 12:03:57 -07:00
seanc 0840deb71a Use name to be consistent with Zend in backtraces
Generators should specify function names as the name instead of the
full name for consistency with Zend 5.5 (and more importantly because
this breaks PHPUnit), this was exposed by the backtrace removal of
file and line info
2013-04-11 12:13:43 -07:00
jdelong 6faa7cbea1 @override-unit-failures Initial support for <?hh typedefs and shapes
Adds runtime support for non-class typehints.  Typedefs are
introduced using type statements, and autoloaded via a new autoload
map entry.  Shapes are parsed but the structure is currently thrown
away and treated as arrays at runtime.  This extends the NamedEntity
structure to sometimes cache 'NameDefs', which are either Typedef*'s
or Class*'s.  VerifyParamType now has to check for typedefs if an
object fails a class check, or when checking non-Object types against
a non-primitive type name that isn't a class.
2013-04-09 13:01:46 -07:00
andrewparoski d0321ec5aa Rename Tuple to Pair, restrict them to having exactly 2 elements 2013-04-08 21:41:07 -07:00
mwilliams b9e7308acb Fix some bugs when we fail to get a translation
If we failed to get the translation for a cloned closure, we didnt
clean the registers.

VMRegAnchor::VMRegAncor(ActRec*,bool) didnt know how to set things
up for continuations, and had an unused bool parameter.

RetFromInterpretedFrame isnt suitable for returning from a
generator - so just preserve m_savedRip across the doFCall.
2013-04-08 21:17:46 -07:00
Owen Yamauchi 9c453b1ad0 Get rid of ext_hhvm_noinline.cpp, part 2
unserialize() and call_user_func_array() were straightforward. They were
called from all over the runtime, but I renamed those implementations
and codemodded the runtime.

The is_* functions were only ever being called by the CVarRef signature,
so I deleted all the other ones (same for f_gettype). Only some of the
is_* functions were being called from the runtime, so I made inline
versions of those without the f_ prefix.
2013-04-08 21:16:48 -07:00
seanc b1e00e219b Add original filepath for continuations in backtrace 2013-04-04 15:39:04 -07:00
mwilliams 46e547b907 Use Func::m_funcBody to avoid SrcDB lookups 2013-04-04 15:39:04 -07:00
ptarjan f7b2fac580 become consistent with zend for too few param error
I've been fighting with these in the importer. What do you think about being consistent? It gives an extra param of info too.
2013-04-04 15:38:49 -07:00
mwilliams 17f2ae8df7 Fix the context class for continuations in closures
The late static bound class was being used for the context. This
was wrong, but before this change there was no context at all, so
it would have taken newly written code to expose the bug.

However, a given continuation can be instantiated from a large number
of different lsb classes (but only one context class) which meant that
we got an explosion of unnecessary translations.
2013-04-01 13:48:50 -07:00
seanc 4a6ae52f5d Generators should show original name in backtrace
Use the original name instead of the outer name for generator
functions in backtraces
2013-04-01 13:46:30 -07:00
smith 22058efe41 Allow different RefData and TypedValue layouts
Fixing various bugs all over the VM that make assumptions about RefData
and TypedValue layout.  Here are the assumptions fixed by this diff:

offsetof(RefData, m_tv) == 0.  Both JIT's assumed this in many subtle
ways, by punning RefData* as TypedValue* without adding an offset.
This assumption also causes RefData._count to overlap TypedValue.m_aux,
which constraints TypedValue layout.

offsetof(TypedValue, m_data) == 0.  gen_ext_hhvm.php assumes you
can cast TypedValue* to Value*; the JITs often weren't using
offsetof(TypedValue, m_data) in their addressing calculations.  HHIR
assumed return-by-value TV's have m_data/m_type in rax/rdx, which
can change when TV layout changes.

offsetof(TypedValue, m_type) > 8 is an assumption baked into the
pass-by-value register assignment logic in HHIR's codegen.cpp; if
the type is in the low word, register assignment is swapped.

sizeof(TypedValue::m_type) == 4.  We used dword-sized operations
in both JIT's when accessing m_type.  Now, we use helper functions
that are sensitive to sizeof(DataType)

Configuration:
DEBUG=: (opt)  same layouts as trunk for RefData & TypedValue
DEBUG=1: (dbg) new RefData layout (m_tv doesn't overlap RefData::_count)
PACKED_TV=1, DEBUG=*:  new RefData and TypedValue layout.
2013-04-01 11:51:31 -07:00
smith 55c20f79c1 Tighten tvIsPlausible() checks
I've found several bugs recently due to the TypedValue plausible
check being too loose.  Our DataType enum values are now sparse,
and we miss garbage that happens to fall inside the [-10, 127]
range, which is >50% of possible garbage values.
2013-04-01 11:51:31 -07:00
jan 20b8aeea2f Consolidate ContDone into ContRetC
Merge ContDone+ContExit into ContRetC with added support of passing results. This variable passing mechanism is not exposed to the PHP as the ReturnStatements in generators do not contain result expression. However, this is exposed by restored hphp_continuation_done() built-in to allow experimentation.

The idea is that once we introduce ContYield opcode (merge of all opcodes used by YieldExpression), we could change ContRetC and ContYield to leave result and done-status on the stack and leave it up to the caller (ContNext/ContSend/ContRaise) to fill in Continuation fields. This will make these opcodes more generic and useful for other things, while allowing us to move some properties to the VM and kill opcodes like ContCurrent.
2013-03-28 11:05:47 -07:00
jan 6822bc55cc Early release of m_received value
Continuation::send() uses m_received field to transfer the value inside
the continuation. This field remains set until the continuation is
iterated the next time.

Unset this field early by ContReceive so that the memory can be
reclaimed.
2013-03-28 11:05:42 -07:00
ptarjan 3710ac0713 Remove duplicately named variables from a closure class
Remove it from the usevar list. Also, add assert to catch stack pointer bugs.
2013-03-28 11:05:42 -07:00
kma 5e603184f5 De-virtualize ArrayData::release.
Of the four horsemen of the SmartAllocator, ArrayData was the only virtual
call. This meant an extra layer of indirection when coming from the TC
to allow the c++ compiler to emit its virtual call, and slightly larger
callsites when using non-generic paths.

While we're moving in this direction, consolidate ArrayData introspection
on its type enum. isSharedMap() was previously implemented with a vtable
slot, and we had no way of asking if an ArrayData was a NameValueTable.
2013-03-27 17:39:41 -07:00
Alex Suhan fb121815dc Merge {get, set}HelperPre 2013-03-27 16:10:46 -07:00
mwilliams 4c6cb0a577 Fix getContextClassName and getParentContextClassName
They both returned the late static bound class, not the context
class. This meant that eg "constant('self::FOO')" was actually
returning what "constant('static::FOO')" should have done.

In addition, we often want the Class*, not its name, so
change them to return Class*. The remaining places that then
read the name from the Class* should be fixed to use the Class*
directly (in a later diff).

Finally, noticed that while "defined()" was recently fixed to
support "static::", "constant()" was not. Pulled out a common
function to find the correct Class*.
2013-03-25 13:31:17 -07:00
smith 768a8bd238 Fix type-puns in FCallBuiltin
Avoid punning TypedValue* to String&/Array&/Object& in FCallBuiltin
(all three implementations).  Our native function calling conventions
require passing pointers into a TypedValue for these types, and
pointers-to-scratch for return values.

In the HHIR case, I removed the optional "return pointer" argument
from the IR CallBuiltin instruction.  The C++ value-passing ABI details
are now handled in cgCallBuiltin and are no longer exposed in the IR.
The argument types are still PtrTo*, but we handle the address fixups
in CodeGenerator.
2013-03-25 13:31:16 -07:00
ptarjan 6b61441bd9 more isStatic fixed for closures
The interpreter fix was different than the jit/ir fix because ##translateFPushObjMethodD()##'s ##i.inputs[0]->rtt.valueClass()## is null (with a TODO in the code to make it not null). It then goes into the slowpath.

Another one like this and I think I should have a different attribute for static closures :(
2013-03-25 12:44:12 -07:00
jan 06713e6226 Eliminate transform_yield_break()
The only places where ReturnStatement is constructed are:

- onReturn(check_yield=true) -> not allowed in generator
- onReturn(check_yield=false) -> coming from transform_yield_break, right after creating hphp_continuation_done()
- MethodStatement, end of function call -> hphp_continuation_done() is created at end of generator in prepare_generator()

Emitter is emitting ContExit in ReturnStatements used in generators. As
can be seen from the analysis above, it's always preceded by emitting
ContDone from hphp_continuation_done(). Let's emit ContDone inside the
ReturnStatement directly and kill usage of hphp_continuation_done().

transform_yield_break() becomes a simple onReturn(check_yield=false), so
let's inline it into onYield and create ReturnStatement directly. After
this change, check_yield flag is always true and can be killed.

ContExit was also used after emitting a generator method in case the end
of method is still reachable. ContDone is added so that the generator is
properly closed. I believe this is never actually used, as MethodStatement
creates ReturnStatement at the end of method anyway.
2013-03-25 11:31:17 -07:00
jan 7b7343b56a Introduce YieldExpression
Unhack the parser and introduce YieldExpression that emits the
equivalent set of opcodes that were emitted by bunch of
expressions/statements generated by parser before.

YieldExpression expects evaluation stack to contain just the value
being yielded, so {,List}AssignmentExpression need to evaluate RHS
first. The previous code had the same behavior.

This will let us consolidate continuation-related opcodes and make
them less tied with continuation objects.
2013-03-22 13:01:05 -07:00
bsimmers 7219dec255 Implement more final operations in VectorTranslator
Most of this is pretty boring and mechanical. I added
VectorProp and VectorElem flags to help deal with the increasing
number of vector-related opcodes.
2013-03-22 11:48:50 -07:00
mwilliams 737a8c87b1 Cleanup more unused code in Continuation
m_method was unused, and __construct had a couple of
unused parameters. Also bring the idl back into sync.
2013-03-21 17:52:28 -07:00
ptarjan a6d70040fa fix static closures
I added the check for this in the interpreter but ##f_array_map## re-enteres the VM via a different path than FCall. Here is the equivilent check for the VM.
2013-03-21 16:51:06 -07:00
ptarjan a1802db1d2 allow static keyword before closure
PHP added this in 5.4 so that you can say your closure shouldn't capture ##$this##. https://wiki.php.net/rfc/closures

Should we add it? Many of their unit tests use it.

Instead of putting a boolean somewhere I used the same attr framework and set the static bit there. Thoughts? It only needs one change in the ##FPushFunc##.
2013-03-21 16:50:55 -07:00
ptarjan 4d7004e955 :Allow $this on closures
In Zend 5.3 they decided that closures should inherit the ##$this## from the containing scope. This brings us close to paraity with them. The remaining thing is to make

    function() use ($this) {}

fatal after we purge it from WWW.
2013-03-21 16:50:12 -07:00
bsimmers 3f829f3ede Print relative offsets in Eval.JitCompareHHIR
This diff adds a relativeOffsets option to Disasm, which will print
code addresses as relative offsets from the beginning of the tracelet instead
of absolute addresses. This format makes it much easier to compare the relative
sizes of the instructions selected by the two jits. I also changed the runtime
option to be a double instead of a bool, which is used as the cutoff ratio for
which tracelets to print. Setting it to 1 will print tracelets where the ir
made larger code than tx64, setting it to 2 will print tracelets where the ir's
code is at least twice as big as tx64's, etc...
2013-03-19 14:11:16 -07:00