Gráfico de Commits

281 Commits

Autor SHA1 Mensagem Data
Drew Paroski d33687616d Don't allow mock classes to extend collection classes
The native collection classes aren't made to support derived classes, and it
would take some work to add such support. This diff adds a check to prevent
classes marked with <<__MockClass>> from deriving from a collection class.

Reviewed By: drussi

Differential Revision: D980050
2013-09-30 12:24:07 -07:00
mwilliams 8224f94dcb Make hhvm more numa aware
Makes a number of changes:
 - Binds each server thread to a numa node, and
   sets its default allocation mode to that node
 - Allocates a jemalloc arena for each node,
   and selects the right one at thread startup (
   to ensure that we don't get memory that was
   previously allocated on a different node)
 - Changes thread scheduling to alternate between
   nodes
 - Sets the default allocation strategy for the
   main thread (and non-server threads) to
   interleaved.

Reviewed By: @jdelong

Differential Revision: D974085
2013-09-30 12:23:59 -07:00
bsimmers 059e1c7702 Properly support surprise flags in hhir
hhir used to do a slow exit whenever a surprise flag check
succeeded. This is fine for most things, but can be all sorts of bad news for
PHProf. This diff adds support for calling the surprise flag hooks without
leaving the trace, and should restore some sanity to profiling results.

Reviewed By: @markw65

Differential Revision: D985446
2013-09-27 10:15:18 -07:00
Jordan DeLong 46c3df8c1d Move class constants tables to TargetCache, use Array instead of HphpArray
This was going to make Class 408 bytes, and it seemed
plausible that that could be causing some red cpu time numbers in a
early perflab, so as part of this diff change declInterfaces not to be
a std::vector to pay for it.

Reviewed By: @edwinsmith

Differential Revision: D979850
2013-09-27 10:15:17 -07:00
Jordan DeLong 40fbe4af8f Remove duplicate call to destructObjects
In hphp_context_exit, we've already called this (before
requestEventHandler shutdowns).

Reviewed By: @paroski

Differential Revision: D979838
2013-09-27 10:15:16 -07:00
Jordan DeLong df07602d08 Implement closure static locals using object props instead of HphpArray
Reviewed By: @edwinsmith

Differential Revision: D976430
2013-09-27 10:15:15 -07:00
Jordan DeLong 2d63f2360b Don't use HphpArray to store static locals; translate StaticLoc* better
Reviewed By: bertrand

Differential Revision: D974604
2013-09-27 10:15:15 -07:00
Jordan DeLong f665e5656d Use MakePacked in bytecode.cpp instead of doing it by hand
Smith noticed this could reuse the existing creation
functions.

Reviewed By: @edwinsmith

Differential Revision: D975127
2013-09-20 13:34:38 -07:00
Andrei Alexandrescu 2c11e1c92d Make sure no decRefs are evaluated during sweeping
We're trying to make sure that destruction/sweeping of extensions is implemented properly. During sweeping there should be no reference decrementing and no smart memory freeing.

Reviewed By: @jdelong

Differential Revision: D932364
2013-09-20 13:34:37 -07:00
Jordan DeLong 6692e056f7 Fix direct use of HphpArray in pack_args_into_array
Use PackedArrayInit.  Also, this function is only called when
there is no invName, but it was doing the magic call case in this case
(we null it first), so rename it and don't branch on that and move it
to the single caller.  Also, it was using appendWithRef instead of
append, presumably because it used to be possible for it to be used
for non-magic calls or something.  From what I can tell, __call can
never get the argument array with reference members (if it can, the
translator is the one doing it wrong).

Reviewed By: @markw65

Differential Revision: D972302
2013-09-19 11:27:37 -07:00
Jordan DeLong ab801de2ba Change a few direct ArrayData/HphpArray uses to Array
Also, add comments on the other ones I've found for ->set().
The biggest thing here is sorting out static property initializers
(probably the answer there is to make them not even use arrays).

Reviewed By: @edwinsmith

Differential Revision: D972067
2013-09-19 11:27:37 -07:00
Drew Paroski 4e5773ad81 Rework the Zend compat layer to be more robust
This diff reworks the PHP extension compat layer to be more robust by
taking steps to reconcile the difference between mainstream PHP's way and
HHVM's way of representing program values and operating on program values.
This includes the shape of the object graph in the heap (what points to
what), how refcounting is done and how "reffiness" is handled, how copy-
on-write semantics are honored, and how values are stored into arrays.

One of the core ideas here is that HHVM supports "boxing" a program value
via the RefData type and that there's a reasonably clean mapping between
PHP's object graph and HHVM's object graph (when HHVM program values are
"boxed") that maps PHP "zval" objects onto HHVM RefData objects. For the
purposes of a compat layer for PHP extensions, it makes sense to use
RefData to represent "zvals". Of course, it is unreasonable to box every
program variable in HHVM since this would hurt performance. However, we
can make things work by boxing program values lazily as needed in the
right places to ensure that Zend PHP extensions only deal with boxed
values. Along the way I also fixed a bug where we were leaking all of
the arguments that were passed to Zend PHP extension functions.

The next issue involves "reffiness". At present, HHVM RefDatas are treated
as "reffy" when their refcount is 2 or greater, while Zend PHP zvals have a
separate flag (independent of the refcount) that indicates whether they
should be treated as "reffy". Zend PHP extensions are capable of setting
two or more program variable to point to the same zval where the zval's
"reffy" flag is set to false. In such cases, the program variables share
the zval using copy-on-write semantics, where the zval must be copied
before making a modification. To make this work, we need to change RefData
somehow so that we can keep track of whether copy-on-write is needed when
the refcount is 2 or greater. Adding "reffy" flag directly poses some
challenges in terms of performance, because it means that when a value's
refcount decreases from 2 to 1 we'll need to make sure the "reffy" flag
gets cleared. I was able to avoid this by adding two flags (m_cow and m_z)
and creating a scheme that maps the 3-tuple (m_count, m_cow, m_z) to the
2-tuple (realRefcount, reffy). Under this scheme decRef continues to work
as it does today, decrementing the m_count field and calling a helper
m_count reaches zero. Another neat thing about this scheme is that m_cow is
set to 1 iff copy-on-write would be required before modifying m_tv. (NOTE:
This diff does not implement copy-on-write yet for these cases, it will be
addressed in a later diff.)

Another issue is the relationship between strings/arrays and the
zvals/RefDatas that point to them. Under Zend PHP, it is assumed that a
zval exclusively owns the string or array and that nothing else points to
the string/array. A consequence of this is that Zend PHP extensions do not
perform any copy-on-write checks with the string or array's refcount before
modifying the string/array. HHVM on the other hand supports sharing strings
and arrays between multiple RefDatas and/or program variables. Thus, we
need some way to protect against Zend PHP extensions modifying a string or
array when its refcount is 2 or greater. This is achieved by putting checks
in the right places to lazily make a copy of the string or array (when
refcount >= 2) so that Zend PHP extensions only deal with strings and
arrays with a refcount of 1.

Finally, the Zend PHP APIs for adding values to an array are a little
different. Zend PHP extensions pass a zval to the API, and the appropriate
array slot is set to point at the zval. The API does not increment the
zval's refcount; it is the caller's responsibility to do this is needed.
New APIs were added to HphpArray to address this need.

With this in place, the next things to go after would be (1) Fixing up how
the Zend compat layer deals emulating Zend PHP string macros and
operations, this may require adding a new KindOfZStr type if StringData
can't be adapted without hurting HHVM performance; (2) Adding checks in the
right places to make a copy of a RefData if m_cow is 1, I've found most the
places where this is needed and it doesn't look like these checks will
noticably hurt performance; (3) improving support for resource types and
object types defined by Zend PHP extensions and interoperability with HHVM
extension classes, HHVM resources, and user-defined pure-PHP classes.

Reviewed By: @ptarjan

Differential Revision: D966781
2013-09-18 11:07:19 -07:00
Jordan DeLong cf888c19d7 Convert CREATE_{VECTOR,MAP} from macros to variadic templates
Reviewed By: @andralex

Differential Revision: D970885
2013-09-17 11:08:24 -07:00
Jordan DeLong 9cbcb364f7 Fix a bug when FPushFunc throws an exception
We need to create the catch trace before we pop the object,
since we're throwing with the marker set to before this instruction
has started.  Also it needs Refs, because it can invoke the autoload
map code.

Reviewed By: @ottoni

Differential Revision: D970481
2013-09-17 11:08:23 -07:00
Jordan DeLong 73a31162ea Debug-fill popped eval stack slots when running in interpreter
Was hoping to catch a bug from D891329.  Only caught a benign
use-after-pop of an ActRec in the unwinder.  Maybe worth it anyway?

Reviewed By: @edwinsmith

Differential Revision: D907772
2013-09-17 11:08:12 -07:00
Edwin Smith ce9cf05c02 Rename NewTuple to NewPackedArray and MakeTuple to MakePacked
This un-overloads "tuple", which also refers to one of the new
container classes.

Reviewed By: @jdelong

Differential Revision: D970494
2013-09-16 11:43:42 -07:00
Jordan DeLong 38fd595342 Allocate HphpArrays in a flat mode instead of using m_inline_data
Gets HphpArrays into a flat mode using MM().objMalloc()
instead of SmartAllocator.  Various optimizations were needed to the
Make functions to get this to work out ok.  Growth still creates a
non-flat HphpArray (leaving a PromotedPayload behind so we know how
big the original allocation was).

Reviewed By: @edwinsmith

Differential Revision: D969431
2013-09-16 11:43:40 -07:00
Jordan DeLong 7cfa297dab Move static string map to its own module
Reviewed By: @edwinsmith

Differential Revision: D970170
2013-09-16 11:43:39 -07:00
Jordan DeLong ef35f55f3c Rename the HA ArgType in hhbc.h to LA
Removes an old TODO here from when we removed homes from
HHBC.

Reviewed By: @edwinsmith

Differential Revision: D960900
2013-09-10 13:21:58 -07:00
Sean Cannella 19da83f2aa fix inlining warnings
Noticed these warnings when building on OSX.

Reviewed By: @jdelong

Differential Revision: D958997
2013-09-09 10:28:10 -07:00
Jordan DeLong fb520052ff Some fixes for building stuff with clang
Not that much.

Reviewed By: @oyamauchi

Differential Revision: D954663
2013-09-08 17:47:14 -07:00
Mirek Klimos 705d2ac5cd Eager execution of async function.
Currently, a call to an async function returns a (Continuation)WaitHandle
object but the excution of the function body doesn't start before await
(or join()) on the WaitHandle is called. This changes it to start the
execution immediately and the control is returned to the caller only
after it's blocked.

Differential Revision: D946914
2013-09-06 17:52:38 -07:00
Jordan DeLong f6899af571 Move InstanceBits to separate module; make Class not friend of things
Aside from instance bits this is pretty straight forward.
Most of the other friends were just directly accessing members instead
of using accessors.

Differential Revision: D953599
2013-09-05 19:39:57 -07:00
Drew Paroski c5e9e0a652 Fix bugs with invokeFunc() and invokeFuncFew(), and other cleanup
This diff fixes some bugs with invokeFunc() and invokeFuncFew(), it removes
some dead code, and it converts more places to use cellDup() instead of
tvDup().

invokeFunc() had a bug where the VM stack did not get cleaned up properly
when a warning is raised and the user error handler threw an exception.
This diff adds a catch clause that will perform the appropriate cleanup and
then rethrow the exception.

invokeFuncFew() had a bug where in some cases it would pass a parameter by
reference when the callee required that the parameter be passed by value.
This was happening because TypedValues that were KindOfRef would get copied
onto the VM stack using operator=, and nothing was checking whether the
callee required the parameter to be passed by value. This diff fixes the
issue by reworking invokeFuncFew() and callers of invokeFuncFew().

Differential Revision: D949251
2013-09-03 08:02:33 -07:00
Alok Menghrajani 5fa62cce63 Add XHPChild interface, an interface compatible with arrays, strings, ints and doubles.
We currently don't have a way to type XHP's {} operator (i.e. to type $foo in
function ($foo) {
  return <div>{$foo}</div>;
}

An XHPChild interface should solve this issue by having a type which is compatible with arrays, strings,
ints and doubles. We can then modify www to have :x:base implement XHPChild.

To me, this seems like the right step to get rid of the Xhp special casing.

Differential Revision: D886565
2013-08-30 16:04:02 -07:00
Sara Golemon 9effdc0172 Add "native" functions for use in Systemlib
<?hh
  class Foo {
    <<__Native>>
    public function bar(int $baz) : string;

    <<__Native>>
    public static function bling(mixed $blong) : double;
  }

  <<__Native>>
  function blong(string $a, stdClass $b) : void;

  <<__Native("ActRec")>>
  function zorb(int $foo, string $bar): float;

Hooks internal functions:

  String HHVM_METHOD(Foo, bar, int64_t bar) { ... }
  double HHVM_STATIC_METHOD(Foo, bling, CVarRef blong) { ... }
  void HHVM_FUNCTION(blong, CStrRef a, CObjRef b) { ... }
  TypedValue* HHVM_FN(zorb)(ActRec* ar) { ... }

When registered during Extension::moduleLoad() with:

  HHVM_ME(Foo, bar)
  HHVM_STATIC_ME(Foo, bling)
  HHVM_FE(blong)
  HHVM_FE(zorb)

Differential Revision: D922477
2013-08-30 16:04:01 -07:00
Sean Cannella 980a6762cc Refactor GetNamedEntity (produce read-only version)
- GetNamedEntity always creates an entry into the table, we should not do this for dynamic input

Differential Revision: D938245
2013-08-29 11:58:47 -07:00
Sean Cannella f98d71d6f0 instanceof needs to denormalize name
- iopInstanceOf needs to denormalize input

Closes #963

Differential Revision: D945675
2013-08-29 11:58:46 -07:00
Jordan DeLong 5edf20b293 Split unique long lived shared stubs generation out of tx64
Translator modularization.  Mostly mechanical code motion,
with addition of some documentation and better logging (disasm
support, etc).  It's possible that the set of stubs for ARM vs x64
might not be exactly the same eventually, but it might, so for now
this is layed out with the assumption that a future
unique-stubs-arm.cpp will populate the same list of stubs.  (I also
tried drawing the line on a per 'stub group' basis, but too many stubs
have tricks about layout and it seemed hard to predict whether that
would commonize anything other than the function call loop, so we can
do it later as needed.)  Also rename the JIT::CodeGenHelpersX64
namespace to JIT::X64.

Differential Revision: D942874
2013-08-29 11:58:45 -07:00
Herman Venter cc4c70398a Remove dead catch blocks.
evalPHPDebugger catches and suppresses all exceptions except debugger exceptions. Hence the catch clauses that follow its only call site are dead code, except for the catch all, which seems just wrong to me since it suppresses Debugger exceptions that are explicitly propagated by evalPHPDebugger.

Differential Revision: D945652
2013-08-29 11:58:43 -07:00
Herman Venter 5e215dbca2 $_ not cleared but still printed after exception
The code to print out the result of the expression following the = command has moved from inside the resulting eval block, to outside it in the debugger code itself. Hence, if the eval block fails, the value of $_ now prints out and this is confusion because it is the value that a previous = command put in there. With this change the eval block first unsets $_, so that the subsequent print value code will do nothing in the case of a failure.

Differential Revision: D944120
2013-08-29 11:58:42 -07:00
Jordan DeLong 42f7e857f6 Move fCallArrayHelper to an asm helper stub
fCallArrayhelper smashes its return address, leading to
return branch mispredictions until we return enough times to get back
on track.  Rewrite it as an asm stub so it can make a tail jump and
pop the proper return ip into the ActRec.

Differential Revision: D941930
2013-08-29 11:58:38 -07:00
Paul Bissonnette b913a5d9a5 Generalized Inlining
Generalizing inlining to work with more complex functions.

Differential Revision: D898434
2013-08-27 11:58:30 -07:00
Owen Yamauchi 88cd96db87 Devirtualize ObjectData, part 1
The C++ vtable pointers and the m_cls pointers in ObjectData are
redundant for C++ extension classes; they both indicate the ObjectData's
dynamic type.

This diff gives ObjectData the same treatment that the ArrayData
hierarchy got, replacing virtual functions with manual dispatch based on
attributes and m_cls. We can't do direct comparison against m_cls,
because of inheritance, except when we know inheritance is not in the
picture.

The vtable isn't gone yet, because I need to do something about C++
destructors, which still require virtual dispatch. That's going to
require a lot of grunt work, so I wanted to put this diff up to keep
that stuff separate.

I did, however, make ~ObjectData non-virtual and try to compile, to
flush out all the dynamic_casts of ObjectData.

- The type-casting functions and clone() are pretty straightforward. The
  only trick is that specialized clone() functions now have to call
  cloneImpl() instead of the base class' clone(), otherwise infinite
  recursion. I added an ObjectData attribute to indicate whether clone()
  is special.

- t___{sleep,wakeup} didn't even need to be virtual, it turns out.
  ObjectData's implementation goes through the normal PHP-method lookup
  path, which effectively does virtual dispatch and routes us to any
  specialized implementations anyway.

Differential Revision: D940852
2013-08-27 11:58:28 -07:00
Sara Golemon 00908f8be3 Reduce bad error spam on too few arguments
function foo($bar, $baz) { }
  foo();

Currently raises two errors:

  foo() expects exactly 2 parameters, 0 given
  foo() expects exactly 2 parameters, 1 given

Only the first of these is either meaningful or correct.
Stop reporting once we've raised it.

Differential Revision: D939810
2013-08-23 09:59:27 -07:00
mwilliams 9e35396b7f Fix some stack overflow bugs
If re-entry triggers stack overflow, there is no FCall or FCallArray,
so the code to find the pc in REQ_STACK_OVERFLOW would fail. If it
managed to get through there, it would then try to DecRef the contents
of an ActRec, sometimes causing it to DecRef a Func.

In addition, if a "leaf" function resulted in re-entry we didn't
necessarily check the stack.

Differential Revision: D936843
2013-08-21 09:33:12 -07:00
Mirek Klimos 3682f42d8a Removing unnecessary mapping of var ids on CreateCont.
Since D898769, all locals in generator bodies have the same ids
as in the corresponding 'create generator' methods, so the mapping
between these ids is no longer needed.

Differential Revision: D932354
2013-08-20 09:04:51 -07:00
Paul Bissonnette cfa4c3427c Adding OpAbs to codegen
fast absolute value computation and related optimizations

implemented Abs in interpreter

implemented Abs in codegen

added const folding for abs

updating docs

adding new test for abs()

Differential Revision: D896037
2013-08-13 14:24:32 -07:00
Drew Paroski da140be7e2 Miscellaneous cleanup
This diff gets rid of some mostly dead code and cuts down on the number
of uses of tvAsCVarRef().

Differential Revision: D923035
2013-08-13 14:24:28 -07:00
Edwin Smith b62a3acde7 Rename files in runtime/server and facebook/runtime/server
Replace _ with -

Differential Revision: D922863
2013-08-12 11:56:05 -07:00
Sean Cannella 0084a8cc20 remove defunct segfault handler
- segfault handler never panned out and has been off for 1.5
years; cheaper to resurrect later from git than refactor to take it out
of tx64

Differential Revision: D922900
2013-08-12 11:33:03 -07:00
Sean Cannella fc59c6a00a Don't always call values() for array fcalls
We should only call values() when we absolutely have to (magic calls where the array is not a vector)

Differential Revision: D920504

Blame Revision: D917994
2013-08-09 10:30:43 -07:00
Sean Cannella 439d8d34fe folly::errnoStr is safer than Util::safe_strerror
- Eliminate Util::safe_strerror and use folly::errnoStr instead since the former is less safe as it doesn't preserve errno

Differential Revision: D920282
2013-08-09 10:30:42 -07:00
Daniel Sloof 1ecc70eeff Fix arguments with __call and call_user_func_array
- Fix call_user_func_array to be Zend compliant, see new test
case

Closes #939

Differential Revision: D917994
2013-08-08 09:11:24 -07:00
Edwin Smith 860d410367 Streamline NewTuple and NewArray helpers
Rearrange the code so when we allocate an array from JIT code,
we call one helper where most of the code is inline.

Differential Revision: D917956
2013-08-08 09:11:24 -07:00
Edwin Smith de4259e8ae Rename rest of files in runtime/base
Differential Revision: D913884
2013-08-06 09:23:21 -07:00
Jordan DeLong ae30d7480c Fix a few SEGVs relating to cyclic data with SETOP_BODY
Test cases inspired by zend test bug35239.phpt.  I think
there are other cases where SETOP_BODY should be SETOP_BODY_CELL, but
I looked at them mainly to see if they would crash, not if they were
optimal.  (Except I changed SetOpL which seemed to be doing tvToCell
twice for no reason.)

Differential Revision: D910025
2013-08-06 09:23:15 -07:00
Edwin Smith 251ebf9685 Rename files in runtime/base, part 7
Differential Revision: D913883
2013-08-05 14:42:18 -07:00
Edwin Smith 55494c2443 Rename files in runtime/base, part 6
Differential Revision: D913699
2013-08-05 14:42:17 -07:00
Edwin Smith 355a49c38f Rename files in runtim/base, part 5
Differential Revision: D913077
2013-08-05 14:42:17 -07:00