Gráfico de Commits

296 Commits

Autor SHA1 Mensagem Data
Dario Russi dc12168af0 IR support for collection initializer
Expose to IR the opcodes for initialization of collection

Reviewed By: @paroski

Differential Revision: D1010966
2013-10-16 09:31:20 -07:00
Alok Menghrajani 627c315940 Log when a nullable (e.g. ?int) is incorrect.
Reviewed By: @dariorussi

Differential Revision: D928297
2013-10-16 09:31:16 -07:00
Jordan DeLong dd4bd0c175 Check for stack overflow when doing include ops
Bsimmers found it.

Reviewed By: @markw65

Differential Revision: D1011987
2013-10-16 09:30:46 -07:00
Jordan DeLong de4ae3ad50 Rename various typedef' things to type alias'
Reviewed By: @swtaarrs

Differential Revision: D1008398
2013-10-14 12:22:34 -07:00
Sara Golemon 73085a3043 Support loading mini-systemlibs from extensions.
Create a registry for per-extension systemlibs to be
loaded from the binary and parsed at InitModules() time.

Auto-embed runtime/ext/ext_foo.php as systemlib.ext.foo

loadSystemlib() looks for systemlib.ext.foo and calls
CompileSystemlib() which parses the section and merges
immediately as well as storing for later re-merging (if needed).

Enables the following <<__Native>> pattern:
  virtual void moduleInit() {
    HHVM_FE(myfunc);
    loadSystemlib();
  }

Where the extension systemlib has a declaration for myfunc().

Reviewed By: @jdelong

Differential Revision: D986853
2013-10-11 16:47:55 -07:00
Abel Nieto b9c50323f6 Make FrozenVector a collection
Add FrozenVector as a collection.

Enable the following:
  * frozen vector literals
  * casting fvs to array and bool
  * array_key_exists and isset with fv

Reviewed By: @paroski

Differential Revision: D988612
2013-10-10 18:02:39 -07:00
Eugene Letuchy bc1642581a make ()-invoke and call_user_func a bit more uniform ...
A `$var` containing a string, a closure, and (by
 happenstance?) functor instance, worked when invoked directly by a
 pair of parens afterwards. This diff extends that behavior to also
 support the ##array($instance, 'method')## and ##array('Class',
 'method')## callable syntaxes.

 It would be nice if we had a facility for
 explicitly creating function pointers in the runtime.

Reviewed By: @jdelong

Differential Revision: D984939
2013-10-09 16:30:09 -07:00
Jordan DeLong 68d297d007 Clean up RDS, part 2
Part two tries to sort out the different types of allocations
from RDS, and abstract the allocation pattern found in a few runtime
structures into an RDS::Link type, and simplify namedAlloc stuff (most
namespaces were dead, and it also did unnamed allocs).  This also
allowed moving the unwind-specific parts of the header into a
dynamically-bound RDS::Link.  (Which also reduced header dependencies
for this module.)

The comments in the header hopefully make the idea clear.  A part 3 is
still coming, in which I plan to move the remaining actual "target
caches" back to JIT::, as just a use case of RDS.  The rds.h itself is
still going to be a central place where different "symbol" types have
to be registered, but I think that is probably ok and still a bit more
modular than it was.  (Ideally the symbols would have types associated
with them, but this would make rds.h depend on the JIT cyclically,
which is unfortunate, so I figure having helper functions for
different symbols that force the type is a reasonable enough thing.)

Reviewed By: @swtaarrs

Differential Revision: D990590
2013-10-08 09:18:07 -07:00
Jordan DeLong 5d4da49c9a Remove various dead code relating to fb_rename_function
Apparently there used to be an API to limit the renamable
functions to a particular set, but this no longer exists.  Delete code
related to it.

Reviewed By: @bertmaher

Differential Revision: D989168
2013-10-07 08:40:44 -07:00
Jordan DeLong 01f45dc835 Cleaning up RDS, part 1
This is a quick start of cleaning up and documenting the RDS
(formerly target cache) module.  This diff contains:

  - a few renames to make things reasonable wrt the containing namespace

  - make Class::wouldCall a non-member function

  - various additional renames of "target cache" to "RDP"

  - the start of some documentation about what it is

Reviewed By: @markw65

Differential Revision: D989135
2013-10-07 08:40:43 -07:00
Jordan DeLong 26669ccca8 Move runtime/vm/jit/target-cache.h to runtime/base/rds.h
Separate diff for rebase-ability and reviewability.

Reviewed By: @edwinsmith

Differential Revision: D989134
2013-10-07 08:40:43 -07:00
Jordan DeLong 6bfe5f011d Rename TargetCache:: to RDS::
In its own diff for reviewability.

Reviewed By: @edwinsmith

Differential Revision: D989132
2013-10-07 08:40:42 -07:00
Jordan DeLong c33c69ee24 Move TargetCache out of Transl:: and rm using directives of TargetCache
If we want to keep the namespace, we should make the naming
such that using directives aren't needed.  (Follow up diffs will make
the naming reasonable.)

Reviewed By: @edwinsmith

Differential Revision: D989131
2013-10-07 08:40:42 -07:00
bsimmers ba02df1b2d Don't let a pointer to a local escape its scope
This code was written before tvScratch existed, and this is exactly
what tvScratch is intended for.

Reviewed By: @markw65

Differential Revision: D995591
2013-10-04 18:26:07 -07:00
Andrei Alexandrescu cfee94b1fc CStrRef sucks
This is the first step of a larger campaign of eliminating goofy types from our codebase. Typedef-ing a reference is unrecommended because references are not first class types and therefore things like construction and copying may do unexpected things. In fact search this diff for 'reinterpret_cast' to see some very odd stuff.

Destroy!

Reviewed By: @jdelong

Differential Revision: D983915
2013-10-02 11:01:08 -07:00
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