Reland D23318594 and D23318592 add recordbasenativesp instr
[hiphop-php.git] / hphp / runtime / vm / property-profile.cpp
blobce8b524d7e6450a41b2acf8bf3e28d732ef08e14
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present 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 +----------------------------------------------------------------------+
17 #include "hphp/runtime/vm/property-profile.h"
19 #include <atomic>
20 #include <cinttypes>
21 #include <tbb/concurrent_hash_map.h>
23 #include "hphp/runtime/base/string-functors.h"
24 #include "hphp/util/trace.h"
25 #include "hphp/runtime/vm/class.h"
26 #include "hphp/runtime/vm/jit/prof-data-serialize.h"
28 namespace HPHP { namespace PropertyProfile {
30 //////////////////////////////////////////////////////////////////////
32 namespace {
34 TRACE_SET_MOD(prof_prop);
36 using ClassMethodPair = std::pair<const StringData*, const StringData*>;
38 using PropertyCounts = tbb::concurrent_hash_map<
39 ClassMethodPair,
40 uint32_t,
41 StringDataPairHashICompare
44 PropertyCounts s_counts;
48 //////////////////////////////////////////////////////////////////////
50 void incCount(const StringData* cls, const StringData* prop) {
51 auto fullName = ClassMethodPair(cls, prop);
53 PropertyCounts::accessor acc;
54 if (!s_counts.insert(acc, PropertyCounts::value_type(fullName, 1))) {
55 acc->second++;
59 uint32_t getCount(const StringData* cls, const StringData* prop) {
60 auto fullName = ClassMethodPair(cls, prop);
62 PropertyCounts::accessor acc;
63 if (s_counts.find(acc, fullName)) return acc->second;
64 return 0;
67 void serialize(jit::ProfDataSerializer& ser) {
68 write_raw(ser, s_counts.size());
69 FTRACE(1, "PropertyProfile::serialize ({} entries):\n", s_counts.size());
70 for (auto const& elm : s_counts) {
71 FTRACE(1, " {}::{} = {}\n",
72 elm.first.first->data(), elm.first.second->data(), elm.second);
73 write_string(ser, elm.first.first);
74 write_string(ser, elm.first.second);
75 write_raw(ser, elm.second);
79 void deserialize(jit::ProfDataDeserializer& ser) {
80 size_t elems;
81 read_raw(ser, elems);
82 FTRACE(1, "PropertyProfile::deserialize ({} entries):\n", elems);
83 while (elems--) {
84 auto const clsName = read_string(ser);
85 auto const propName = read_string(ser);
86 auto const fullName = ClassMethodPair(clsName, propName);
87 uint32_t count;
88 read_raw(ser, count);
89 FTRACE(1, " {}::{} = {}\n", clsName->data(), propName->data(), count);
90 PropertyCounts::accessor acc;
91 if (!s_counts.insert(acc, PropertyCounts::value_type(fullName, count))) {
92 always_assert_flog(
93 0, "found duplicate entry while deserializing PropertyProfile"
99 //////////////////////////////////////////////////////////////////////