OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_WASM_SIGNATURE_MAP_H_ | 5 #ifndef V8_WASM_SIGNATURE_MAP_H_ |
6 #define V8_WASM_SIGNATURE_MAP_H_ | 6 #define V8_WASM_SIGNATURE_MAP_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "src/signature.h" | 10 #include "src/signature.h" |
11 #include "src/wasm/wasm-opcodes.h" | 11 #include "src/wasm/wasm-opcodes.h" |
12 | 12 |
13 namespace v8 { | 13 namespace v8 { |
14 namespace internal { | 14 namespace internal { |
15 namespace wasm { | 15 namespace wasm { |
16 | 16 |
17 // A signature map canonicalizes signatures into a range of indices so that | 17 // A signature map canonicalizes signatures into a range of indices so that |
18 // two different {FunctionSig} instances with the same contents map to the | 18 // two different {FunctionSig} instances with the same contents map to the |
19 // same index. | 19 // same index. |
20 class V8_EXPORT_PRIVATE SignatureMap { | 20 class V8_EXPORT_PRIVATE SignatureMap { |
21 public: | 21 public: |
22 // Allow default construction and move construction (because we have vectors | 22 // Allow default construction and move construction (because we have vectors |
23 // of objects containing SignatureMaps), but disallow copy or assign. It's | 23 // of objects containing SignatureMaps), but disallow copy or assign. It's |
24 // too easy to get security bugs by accidentally updating a copy of the map. | 24 // too easy to get security bugs by accidentally updating a copy of the map. |
25 SignatureMap() = default; | 25 SignatureMap(); |
26 SignatureMap(SignatureMap&&) = default; | 26 SignatureMap(SignatureMap&&) = default; |
27 | 27 |
28 // Gets the index for a signature, assigning a new index if necessary. | 28 // Gets the index for a signature, assigning a new index if necessary. |
29 uint32_t FindOrInsert(FunctionSig* sig); | 29 uint32_t FindOrInsert(FunctionSig* sig); |
30 | 30 |
31 // Gets the index for a signature, returning {-1} if not found. | 31 // Gets the index for a signature, returning {-1} if not found. |
32 int32_t Find(FunctionSig* sig) const; | 32 int32_t Find(FunctionSig* sig) const; |
33 | 33 |
34 private: | 34 private: |
35 // TODO(wasm): use a hashmap instead of an ordered map? | 35 // TODO(wasm): use a hashmap instead of an ordered map? |
36 struct CompareFunctionSigs { | 36 struct CompareFunctionSigs { |
37 bool operator()(FunctionSig* a, FunctionSig* b) const; | 37 bool operator()(FunctionSig* a, FunctionSig* b) const; |
38 }; | 38 }; |
39 uint32_t next_ = 0; | 39 uint32_t next_ = 0; |
| 40 std::unique_ptr<base::Mutex> mutex_; |
40 std::map<FunctionSig*, uint32_t, CompareFunctionSigs> map_; | 41 std::map<FunctionSig*, uint32_t, CompareFunctionSigs> map_; |
41 | 42 |
42 DISALLOW_COPY_AND_ASSIGN(SignatureMap); | 43 DISALLOW_COPY_AND_ASSIGN(SignatureMap); |
43 }; | 44 }; |
44 | 45 |
45 } // namespace wasm | 46 } // namespace wasm |
46 } // namespace internal | 47 } // namespace internal |
47 } // namespace v8 | 48 } // namespace v8 |
48 | 49 |
49 #endif // V8_WASM_SIGNATURE_MAP_H_ | 50 #endif // V8_WASM_SIGNATURE_MAP_H_ |
OLD | NEW |