Refactor back ends into implementations of BackEnd.
[hiphop-php.git] / hphp / runtime / vm / instance-bits.h
blobb060e7855d456137f2dba6efaf16aed7582c6e9f
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_RUNTIME_VM_INSTANCE_BITS_H_
17 #define incl_HPHP_RUNTIME_VM_INSTANCE_BITS_H_
19 #include <bitset>
20 #include <atomic>
21 #include <cinttypes>
23 #include "hphp/util/mutex.h"
25 namespace HPHP { struct StringData; }
27 //////////////////////////////////////////////////////////////////////
30 * During warmup, we profile the most common classes or interfaces
31 * involved in instanceof checks in order to set up a bitmask for each
32 * class to allow these checks to be performed quickly by the JIT.
34 namespace HPHP { namespace InstanceBits {
36 //////////////////////////////////////////////////////////////////////
38 typedef std::bitset<128> BitSet;
41 * The initFlag tracks whether init() has finished yet.
43 * The lock is used to protect access to the instance bits on
44 * individual classes to ensure that after the initFlag -> true
45 * transition, all loaded classes will properly have instance bits
46 * populated.
48 * See Unit::defClass for some details.
50 extern ReadWriteMutex lock;
51 extern std::atomic<bool> initFlag;
54 * Called to record an instanceof check for `name', during the warmup
55 * phase.
57 void profile(const StringData* name);
60 * InstanceBits::init() must be called by the first translation which
61 * uses instance bits, while holding the write lease.
63 void init();
66 * Returns: the instance bit for the class or interface `name', or
67 * zero if there is no allocated bit.
69 * This function may be called by the thread doing init(), or
70 * otherwise only after init() is finished (i.e. initFlag == true).
72 unsigned lookup(const StringData* name);
75 * Populate a mask and offset for checking instance bits from JIT
76 * compiled code. The offset is the offset of the byte that should be
77 * tested with mask, relative to a Class*.
79 * Returns false if `name' has no instance bit.
81 * Pre: initFlag == true.
83 bool getMask(const StringData* name, int& offset, uint8_t& mask);
85 //////////////////////////////////////////////////////////////////////
89 #endif