Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 91 lines (72 sloc) 2.491 kb
5f2adf4 @brixen Replaced SymbolTable with native C++ class using STL.
brixen authored
1 #ifndef RBX_SYMBOLTABLE_HPP
2 #define RBX_SYMBOLTABLE_HPP
3
4 #include "oop.hpp"
5 #include "prelude.hpp"
7469cc5 Add background compiler thread to speed up performing JIT
Evan Phoenix authored
6 #include "util/thread.hpp"
5f2adf4 @brixen Replaced SymbolTable with native C++ class using STL.
brixen authored
7
8 #include <string>
9 #include <vector>
a645f80 @brixen Changed SymbolTable to use unordered_map. Added docs.
brixen authored
10 #include <tr1/unordered_map>
11
12 /* SymbolTable provides a one-to-one map between a symbol ID
13 * and a string. The hashing algorithm used to generate a
14 * hashval from a string is not perfect. For instance, the
15 * strings "__uint_fast64_t" and "TkIF_MOD" generate the same
16 * hashval. SymbolTable handles this by first looking up a
17 * symbol ID for a string by the string's hashval and then
18 * comparing the candidate string with the stored string that
19 * corresponds to the possible symbol ID.
20 *
21 * When a symbol ID is generated, the string corresponding to
22 * that symbol ID is stored in a vector. The symbol ID is the
23 * index of that string in the vector. The symbol ID becomes
1fdd151 @rue Changed all OBJECT, SYMBOL, FIXNUM, INTEGER to normal syntax.
rue authored
24 * a Symbol* by adding the tag value for symbols. (See builtin
a645f80 @brixen Changed SymbolTable to use unordered_map. Added docs.
brixen authored
25 * class Symbol::from_index and oop.hpp.)
26 */
5f2adf4 @brixen Replaced SymbolTable with native C++ class using STL.
brixen authored
27 namespace rubinius {
1fdd151 @rue Changed all OBJECT, SYMBOL, FIXNUM, INTEGER to normal syntax.
rue authored
28
58105ff @brixen Added Symbol::all_symbols primitive and fixed up Ruby Symbol code.
brixen authored
29 class Array;
5f2adf4 @brixen Replaced SymbolTable with native C++ class using STL.
brixen authored
30 class String;
1fdd151 @rue Changed all OBJECT, SYMBOL, FIXNUM, INTEGER to normal syntax.
rue authored
31 class Symbol;
1d69526 @dbussink Use MurmurHash 3 for String hashing
dbussink authored
32 class SharedState;
5f2adf4 @brixen Replaced SymbolTable with native C++ class using STL.
brixen authored
33
0053c4b @brixen Use explicit reference to vector in SymbolTable.
brixen authored
34 typedef std::vector<std::string> SymbolStrings;
35 typedef std::vector<std::size_t> SymbolIds;
36 typedef std::tr1::unordered_map<hashval, SymbolIds> SymbolMap;
5f2adf4 @brixen Replaced SymbolTable with native C++ class using STL.
brixen authored
37
38 class SymbolTable {
f60d156 Add a intern-type kind calculation of a symbol
Evan Phoenix authored
39 public: // Types
40
41 // We encode in the symbol some information about it, mostly
42 // what kind of prefix it has. This lets us ask questions
43 // easily about it without having to get the string representation
44 // and perform comparisons against the char data.
45 enum Kind {
46 Normal,
47 Constant,
48 IVar,
49 CVar,
50 System
51 };
52
53 typedef std::vector<Kind> SymbolKinds;
54
d087929 Revamp agent API, add a number of variables
Evan Phoenix authored
55 private:
56 SymbolMap symbols;
57 SymbolStrings strings;
58 SymbolKinds kinds;
59 thread::SpinLock lock_;
60 size_t bytes_used_;
61
1d69526 @dbussink Use MurmurHash 3 for String hashing
dbussink authored
62 Symbol* lookup(const char* str, size_t length, uint32_t seed);
63
5f2adf4 @brixen Replaced SymbolTable with native C++ class using STL.
brixen authored
64 public:
d087929 Revamp agent API, add a number of variables
Evan Phoenix authored
65 size_t& bytes_used() {
66 return bytes_used_;
67 }
68
1d69526 @dbussink Use MurmurHash 3 for String hashing
dbussink authored
69 Symbol* lookup(SharedState* shared, std::string str);
61c7b4e @dbussink Allow for using \0 characters in Symbols on 1.9
dbussink authored
70 Symbol* lookup(STATE, std::string str);
71 Symbol* lookup(STATE, const char* str, size_t length);
1fdd151 @rue Changed all OBJECT, SYMBOL, FIXNUM, INTEGER to normal syntax.
rue authored
72 Symbol* lookup(STATE, String* str);
1f0ca40 @rue Rudimentary const correctness fixes. This needs attention.
rue authored
73 String* lookup_string(STATE, const Symbol* sym);
de93336 Speed up Syck
Evan Phoenix authored
74
75 std::string& lookup_cppstring(const Symbol* sym);
392f4bb @dbussink Audited usage of char* for Symbols
dbussink authored
76 std::string lookup_debug_string(const Symbol* sym);
de93336 Speed up Syck
Evan Phoenix authored
77
5f2adf4 @brixen Replaced SymbolTable with native C++ class using STL.
brixen authored
78 size_t size();
58105ff @brixen Added Symbol::all_symbols primitive and fixed up Ruby Symbol code.
brixen authored
79 Array* all_as_array(STATE);
5f2adf4 @brixen Replaced SymbolTable with native C++ class using STL.
brixen authored
80
f60d156 Add a intern-type kind calculation of a symbol
Evan Phoenix authored
81 Kind kind(STATE, const Symbol* sym);
82
945145d Big memory usage cleanup
Evan Phoenix authored
83 int byte_size();
84
5f2adf4 @brixen Replaced SymbolTable with native C++ class using STL.
brixen authored
85 size_t add(std::string str);
f60d156 Add a intern-type kind calculation of a symbol
Evan Phoenix authored
86 Kind detect_kind(const char* str, int size);
5f2adf4 @brixen Replaced SymbolTable with native C++ class using STL.
brixen authored
87 };
88 };
89
90 #endif
Something went wrong with that request. Please try again.