1 //===-- sanitizer_chained_origin_depot.cpp --------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // A storage for chained origins.
10 //===----------------------------------------------------------------------===//
12 #include "sanitizer_chained_origin_depot.h"
14 namespace __sanitizer
{
16 bool ChainedOriginDepot::ChainedOriginDepotNode::eq(
17 u32 hash
, const args_type
&args
) const {
18 return here_id
== args
.here_id
&& prev_id
== args
.prev_id
;
21 uptr
ChainedOriginDepot::ChainedOriginDepotNode::storage_size(
22 const args_type
&args
) {
23 return sizeof(ChainedOriginDepotNode
);
26 /* This is murmur2 hash for the 64->32 bit case.
27 It does not behave all that well because the keys have a very biased
28 distribution (I've seen 7-element buckets with the table only 14% full).
31 * (1 bits) Reserved, zero.
32 * (8 bits) Part id = bits 13..20 of the hash value of here_id's key.
33 * (23 bits) Sequential number (each part has each own sequence).
35 prev_id has either the same distribution as here_id (but with 3:8:21)
36 split, or one of two reserved values (-1) or (-2). Either case can
37 dominate depending on the workload.
39 u32
ChainedOriginDepot::ChainedOriginDepotNode::hash(const args_type
&args
) {
40 const u32 m
= 0x5bd1e995;
41 const u32 seed
= 0x9747b28c;
64 bool ChainedOriginDepot::ChainedOriginDepotNode::is_valid(
65 const args_type
&args
) {
69 void ChainedOriginDepot::ChainedOriginDepotNode::store(const args_type
&args
,
71 here_id
= args
.here_id
;
72 prev_id
= args
.prev_id
;
75 ChainedOriginDepot::ChainedOriginDepotNode::args_type
76 ChainedOriginDepot::ChainedOriginDepotNode::load() const {
77 args_type ret
= {here_id
, prev_id
};
81 ChainedOriginDepot::ChainedOriginDepotNode::Handle
82 ChainedOriginDepot::ChainedOriginDepotNode::get_handle() {
86 ChainedOriginDepot::ChainedOriginDepot() {}
88 StackDepotStats
*ChainedOriginDepot::GetStats() { return depot
.GetStats(); }
90 bool ChainedOriginDepot::Put(u32 here_id
, u32 prev_id
, u32
*new_id
) {
91 ChainedOriginDepotDesc desc
= {here_id
, prev_id
};
93 ChainedOriginDepotNode::Handle h
= depot
.Put(desc
, &inserted
);
94 *new_id
= h
.valid() ? h
.id() : 0;
98 u32
ChainedOriginDepot::Get(u32 id
, u32
*other
) {
99 ChainedOriginDepotDesc desc
= depot
.Get(id
);
100 *other
= desc
.prev_id
;
104 void ChainedOriginDepot::LockAll() { depot
.LockAll(); }
106 void ChainedOriginDepot::UnlockAll() { depot
.UnlockAll(); }
108 } // namespace __sanitizer