author | coleenp |
Wed, 24 Jul 2019 10:22:11 -0400 | |
changeset 57511 | 00ae3b739184 |
parent 54927 | 1512d88b24c6 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
53156 | 2 |
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4567
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4567
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4567
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
53156
diff
changeset
|
25 |
#ifndef SHARE_OOPS_SYMBOL_HPP |
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
53156
diff
changeset
|
26 |
#define SHARE_OOPS_SYMBOL_HPP |
7397 | 27 |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
28 |
#include "memory/allocation.hpp" |
37466 | 29 |
#include "utilities/exceptions.hpp" |
40655
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
40016
diff
changeset
|
30 |
#include "utilities/macros.hpp" |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
31 |
|
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
32 |
// A Symbol is a canonicalized string. |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
33 |
// All Symbols reside in global SymbolTable and are reference counted. |
7397 | 34 |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
35 |
// Reference counting |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
36 |
// |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
37 |
// All Symbols are allocated and added to the SymbolTable. |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
38 |
// When a class is unloaded, the reference counts of the Symbol pointers in |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
12263
diff
changeset
|
39 |
// the ConstantPool and in InstanceKlass (see release_C_heap_structures) are |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
40 |
// decremented. When the reference count for a Symbol goes to 0, the garbage |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
41 |
// collector can free the Symbol and remove it from the SymbolTable. |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
42 |
// |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
43 |
// 0) Symbols need to be reference counted when a pointer to the Symbol is |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
44 |
// saved in persistent storage. This does not include the pointer |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
45 |
// in the SymbolTable bucket (the _literal field in HashtableEntry) |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
46 |
// that points to the Symbol. All other stores of a Symbol* |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
47 |
// to a field of a persistent variable (e.g., the _name filed in |
20017
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
19696
diff
changeset
|
48 |
// fieldDescriptor or _ptr in a CPSlot) is reference counted. |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
49 |
// |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
50 |
// 1) The lookup of a "name" in the SymbolTable either creates a Symbol F for |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
51 |
// "name" and returns a pointer to F or finds a pre-existing Symbol F for |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
52 |
// "name" and returns a pointer to it. In both cases the reference count for F |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
53 |
// is incremented under the assumption that a pointer to F will be created from |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
54 |
// the return value. Thus the increment of the reference count is on the lookup |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
55 |
// and not on the assignment to the new Symbol*. That is |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
56 |
// Symbol* G = lookup() |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
57 |
// ^ increment on lookup() |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
58 |
// and not |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
59 |
// Symbol* G = lookup() |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
60 |
// ^ increment on assignmnet |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
61 |
// The reference count must be decremented manually when the copy of the |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
62 |
// pointer G is destroyed. |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
63 |
// |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
64 |
// 2) For a local Symbol* A that is a copy of an existing Symbol* B, the |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
65 |
// reference counting is elided when the scope of B is greater than the scope |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
66 |
// of A. For example, in the code fragment |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
67 |
// below "klass" is passed as a parameter to the method. Symbol* "kn" |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
68 |
// is a copy of the name in "klass". |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
69 |
// |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
70 |
// Symbol* kn = klass->name(); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
71 |
// unsigned int d_hash = dictionary()->compute_hash(kn, class_loader); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
72 |
// |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
73 |
// The scope of "klass" is greater than the scope of "kn" so the reference |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
74 |
// counting for "kn" is elided. |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
75 |
// |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
76 |
// Symbol* copied from ConstantPool entries are good candidates for reference |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
77 |
// counting elision. The ConstantPool entries for a class C exist until C is |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
78 |
// unloaded. If a Symbol* is copied out of the ConstantPool into Symbol* X, |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
79 |
// the Symbol* in the ConstantPool will in general out live X so the reference |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
80 |
// counting on X can be elided. |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
81 |
// |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
82 |
// For cases where the scope of A is not greater than the scope of B, |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
83 |
// the reference counting is explicitly done. See ciSymbol, |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
84 |
// ResolutionErrorEntry and ClassVerifier for examples. |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
85 |
// |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
86 |
// 3) When a Symbol K is created for temporary use, generally for substrings of |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
87 |
// an existing symbol or to create a new symbol, assign it to a |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
88 |
// TempNewSymbol. The SymbolTable methods new_symbol(), lookup() |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
89 |
// and probe() all potentially return a pointer to a new Symbol. |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
90 |
// The allocation (or lookup) of K increments the reference count for K |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
91 |
// and the destructor decrements the reference count. |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
92 |
// |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
12263
diff
changeset
|
93 |
// This cannot be inherited from ResourceObj because it cannot have a vtable. |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
12263
diff
changeset
|
94 |
// Since sometimes this is allocated from Metadata, pick a base allocation |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
12263
diff
changeset
|
95 |
// type without virtual functions. |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
12263
diff
changeset
|
96 |
class ClassLoaderData; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
12263
diff
changeset
|
97 |
|
51179
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
49613
diff
changeset
|
98 |
// Set _refcount to PERM_REFCOUNT to prevent the Symbol from being freed. |
31790 | 99 |
#ifndef PERM_REFCOUNT |
51179
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
49613
diff
changeset
|
100 |
#define PERM_REFCOUNT ((1 << 16) - 1) |
31790 | 101 |
#endif |
102 |
||
32357
43087bc6dd04
8130115: REDO - Reduce Symbol::_identity_hash to 2 bytes
minqi
parents:
31790
diff
changeset
|
103 |
class Symbol : public MetaspaceObj { |
43087bc6dd04
8130115: REDO - Reduce Symbol::_identity_hash to 2 bytes
minqi
parents:
31790
diff
changeset
|
104 |
friend class VMStructs; |
43087bc6dd04
8130115: REDO - Reduce Symbol::_identity_hash to 2 bytes
minqi
parents:
31790
diff
changeset
|
105 |
friend class SymbolTable; |
43087bc6dd04
8130115: REDO - Reduce Symbol::_identity_hash to 2 bytes
minqi
parents:
31790
diff
changeset
|
106 |
|
43087bc6dd04
8130115: REDO - Reduce Symbol::_identity_hash to 2 bytes
minqi
parents:
31790
diff
changeset
|
107 |
private: |
51179
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
49613
diff
changeset
|
108 |
|
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
49613
diff
changeset
|
109 |
// This is an int because it needs atomic operation on the refcount. Mask length |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
49613
diff
changeset
|
110 |
// in high half word. length is the number of UTF8 characters in the symbol |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
49613
diff
changeset
|
111 |
volatile uint32_t _length_and_refcount; |
32357
43087bc6dd04
8130115: REDO - Reduce Symbol::_identity_hash to 2 bytes
minqi
parents:
31790
diff
changeset
|
112 |
short _identity_hash; |
51997
9ce37fa2e179
8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents:
51405
diff
changeset
|
113 |
u1 _body[2]; |
1 | 114 |
|
115 |
enum { |
|
51179
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
49613
diff
changeset
|
116 |
// max_symbol_length must fit into the top 16 bits of _length_and_refcount |
1 | 117 |
max_symbol_length = (1 << 16) -1 |
118 |
}; |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
119 |
|
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46492
diff
changeset
|
120 |
static int byte_size(int length) { |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46492
diff
changeset
|
121 |
// minimum number of natural words needed to hold these bits (no non-heap version) |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46492
diff
changeset
|
122 |
return (int)(sizeof(Symbol) + (length > 2 ? length - 2 : 0)); |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46492
diff
changeset
|
123 |
} |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
12263
diff
changeset
|
124 |
static int size(int length) { |
35898
ddc274f0052f
8145628: hotspot metadata classes shouldn't use HeapWordSize or heap related macros like align_object_size
coleenp
parents:
34666
diff
changeset
|
125 |
// minimum number of natural words needed to hold these bits (no non-heap version) |
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46492
diff
changeset
|
126 |
return (int)heap_word_size(byte_size(length)); |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
127 |
} |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
128 |
|
51997
9ce37fa2e179
8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents:
51405
diff
changeset
|
129 |
void byte_at_put(int index, u1 value) { |
51179
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
49613
diff
changeset
|
130 |
assert(index >=0 && index < length(), "symbol index overflow"); |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
131 |
_body[index] = value; |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
132 |
} |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
133 |
|
12263
d20640f4f8fe
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
8921
diff
changeset
|
134 |
Symbol(const u1* name, int length, int refcount); |
54847
59ea39bb2809
8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents:
54807
diff
changeset
|
135 |
void* operator new(size_t size, int len) throw(); |
59ea39bb2809
8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents:
54807
diff
changeset
|
136 |
void* operator new(size_t size, int len, Arena* arena) throw(); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
12263
diff
changeset
|
137 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
12263
diff
changeset
|
138 |
void operator delete(void* p); |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
139 |
|
51179
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
49613
diff
changeset
|
140 |
static int extract_length(uint32_t value) { return value >> 16; } |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
49613
diff
changeset
|
141 |
static int extract_refcount(uint32_t value) { return value & 0xffff; } |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
49613
diff
changeset
|
142 |
static uint32_t pack_length_and_refcount(int length, int refcount); |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
49613
diff
changeset
|
143 |
|
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
49613
diff
changeset
|
144 |
int length() const { return extract_length(_length_and_refcount); } |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
49613
diff
changeset
|
145 |
|
1 | 146 |
public: |
147 |
// Low-level access (used with care, since not GC-safe) |
|
51997
9ce37fa2e179
8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents:
51405
diff
changeset
|
148 |
const u1* base() const { return &_body[0]; } |
1 | 149 |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
12263
diff
changeset
|
150 |
int size() { return size(utf8_length()); } |
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46492
diff
changeset
|
151 |
int byte_size() { return byte_size(utf8_length()); } |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46492
diff
changeset
|
152 |
|
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46492
diff
changeset
|
153 |
// Symbols should be stored in the read-only region of CDS archive. |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46492
diff
changeset
|
154 |
static bool is_read_only_by_default() { return true; } |
1 | 155 |
|
156 |
// Returns the largest size symbol we can safely hold. |
|
34666 | 157 |
static int max_length() { return max_symbol_length; } |
158 |
unsigned identity_hash() const { |
|
32357
43087bc6dd04
8130115: REDO - Reduce Symbol::_identity_hash to 2 bytes
minqi
parents:
31790
diff
changeset
|
159 |
unsigned addr_bits = (unsigned)((uintptr_t)this >> (LogMinObjAlignmentInBytes + 3)); |
43087bc6dd04
8130115: REDO - Reduce Symbol::_identity_hash to 2 bytes
minqi
parents:
31790
diff
changeset
|
160 |
return ((unsigned)_identity_hash & 0xffff) | |
51179
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
49613
diff
changeset
|
161 |
((addr_bits ^ (length() << 8) ^ (( _body[0] << 8) | _body[1])) << 16); |
32357
43087bc6dd04
8130115: REDO - Reduce Symbol::_identity_hash to 2 bytes
minqi
parents:
31790
diff
changeset
|
162 |
} |
1 | 163 |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
164 |
// Reference counting. See comments above this class for when to use. |
51179
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
49613
diff
changeset
|
165 |
int refcount() const { return extract_refcount(_length_and_refcount); } |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
49613
diff
changeset
|
166 |
bool try_increment_refcount(); |
15855
2ac9ebea17f3
8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents:
14477
diff
changeset
|
167 |
void increment_refcount(); |
2ac9ebea17f3
8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents:
14477
diff
changeset
|
168 |
void decrement_refcount(); |
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46492
diff
changeset
|
169 |
bool is_permanent() { |
51179
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
49613
diff
changeset
|
170 |
return (refcount() == PERM_REFCOUNT); |
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46492
diff
changeset
|
171 |
} |
54927 | 172 |
void set_permanent(); |
54133
829bf950287e
8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents:
53731
diff
changeset
|
173 |
void make_permanent(); |
1 | 174 |
|
51997
9ce37fa2e179
8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents:
51405
diff
changeset
|
175 |
// Function char_at() returns the Symbol's selected u1 byte as a char type. |
9ce37fa2e179
8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents:
51405
diff
changeset
|
176 |
// |
9ce37fa2e179
8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents:
51405
diff
changeset
|
177 |
// Note that all multi-byte chars have the sign bit set on all their bytes. |
9ce37fa2e179
8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents:
51405
diff
changeset
|
178 |
// No single byte chars have their sign bit set. |
9ce37fa2e179
8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents:
51405
diff
changeset
|
179 |
char char_at(int index) const { |
51179
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
49613
diff
changeset
|
180 |
assert(index >=0 && index < length(), "symbol index overflow"); |
51997
9ce37fa2e179
8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents:
51405
diff
changeset
|
181 |
return (char)base()[index]; |
1 | 182 |
} |
183 |
||
51997
9ce37fa2e179
8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents:
51405
diff
changeset
|
184 |
const u1* bytes() const { return base(); } |
1 | 185 |
|
51179
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
49613
diff
changeset
|
186 |
int utf8_length() const { return length(); } |
1 | 187 |
|
4567
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1
diff
changeset
|
188 |
// Compares the symbol with a string. |
46492
5848b57c9dc5
8180763: Improve inlining of Symbol::equals(char*,int) into CompactHashtable
redestad
parents:
40655
diff
changeset
|
189 |
bool equals(const char* str, int len) const { |
5848b57c9dc5
8180763: Improve inlining of Symbol::equals(char*,int) into CompactHashtable
redestad
parents:
40655
diff
changeset
|
190 |
int l = utf8_length(); |
5848b57c9dc5
8180763: Improve inlining of Symbol::equals(char*,int) into CompactHashtable
redestad
parents:
40655
diff
changeset
|
191 |
if (l != len) return false; |
5848b57c9dc5
8180763: Improve inlining of Symbol::equals(char*,int) into CompactHashtable
redestad
parents:
40655
diff
changeset
|
192 |
while (l-- > 0) { |
51997
9ce37fa2e179
8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents:
51405
diff
changeset
|
193 |
if (str[l] != char_at(l)) |
46492
5848b57c9dc5
8180763: Improve inlining of Symbol::equals(char*,int) into CompactHashtable
redestad
parents:
40655
diff
changeset
|
194 |
return false; |
5848b57c9dc5
8180763: Improve inlining of Symbol::equals(char*,int) into CompactHashtable
redestad
parents:
40655
diff
changeset
|
195 |
} |
5848b57c9dc5
8180763: Improve inlining of Symbol::equals(char*,int) into CompactHashtable
redestad
parents:
40655
diff
changeset
|
196 |
assert(l == -1, "we should be at the beginning"); |
5848b57c9dc5
8180763: Improve inlining of Symbol::equals(char*,int) into CompactHashtable
redestad
parents:
40655
diff
changeset
|
197 |
return true; |
5848b57c9dc5
8180763: Improve inlining of Symbol::equals(char*,int) into CompactHashtable
redestad
parents:
40655
diff
changeset
|
198 |
} |
4567
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1
diff
changeset
|
199 |
bool equals(const char* str) const { return equals(str, (int) strlen(str)); } |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1
diff
changeset
|
200 |
|
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1
diff
changeset
|
201 |
// Tests if the symbol starts with the given prefix. |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1
diff
changeset
|
202 |
bool starts_with(const char* prefix, int len) const; |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1
diff
changeset
|
203 |
bool starts_with(const char* prefix) const { |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1
diff
changeset
|
204 |
return starts_with(prefix, (int) strlen(prefix)); |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1
diff
changeset
|
205 |
} |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1
diff
changeset
|
206 |
|
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1
diff
changeset
|
207 |
// Tests if the symbol starts with the given prefix. |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1
diff
changeset
|
208 |
int index_of_at(int i, const char* str, int len) const; |
1 | 209 |
|
210 |
// Three-way compare for sorting; returns -1/0/1 if receiver is </==/> than arg |
|
211 |
// note that the ordering is not alfabetical |
|
34666 | 212 |
inline int fast_compare(const Symbol* other) const; |
1 | 213 |
|
214 |
// Returns receiver converted to null-terminated UTF-8 string; string is |
|
215 |
// allocated in resource area, or in the char buffer provided by caller. |
|
216 |
char* as_C_string() const; |
|
217 |
char* as_C_string(char* buf, int size) const; |
|
218 |
||
14477
95e66ea71f71
6830717: replay of compilations would help with debugging
minqi
parents:
13728
diff
changeset
|
219 |
// Returns an escaped form of a Java string. |
95e66ea71f71
6830717: replay of compilations would help with debugging
minqi
parents:
13728
diff
changeset
|
220 |
char* as_quoted_ascii() const; |
1 | 221 |
|
222 |
// Returns a null terminated utf8 string in a resource array |
|
223 |
char* as_utf8() const { return as_C_string(); } |
|
224 |
||
225 |
jchar* as_unicode(int& length) const; |
|
226 |
||
227 |
// Treating this symbol as a class name, returns the Java name for the class. |
|
228 |
// String is allocated in resource area if buffer is not provided. |
|
229 |
// See Klass::external_name() |
|
230 |
const char* as_klass_external_name() const; |
|
231 |
const char* as_klass_external_name(char* buf, int size) const; |
|
232 |
||
54432
532e88de77eb
8221470: Print methods in exception messages in java-like Syntax.
goetz
parents:
54347
diff
changeset
|
233 |
// Treating the symbol as a signature, print the return |
532e88de77eb
8221470: Print methods in exception messages in java-like Syntax.
goetz
parents:
54347
diff
changeset
|
234 |
// type to the outputStream. Prints external names as 'double' or |
532e88de77eb
8221470: Print methods in exception messages in java-like Syntax.
goetz
parents:
54347
diff
changeset
|
235 |
// 'java.lang.Object[][]'. |
532e88de77eb
8221470: Print methods in exception messages in java-like Syntax.
goetz
parents:
54347
diff
changeset
|
236 |
void print_as_signature_external_return_type(outputStream *os); |
532e88de77eb
8221470: Print methods in exception messages in java-like Syntax.
goetz
parents:
54347
diff
changeset
|
237 |
// Treating the symbol as a signature, print the parameter types |
532e88de77eb
8221470: Print methods in exception messages in java-like Syntax.
goetz
parents:
54347
diff
changeset
|
238 |
// seperated by ', ' to the outputStream. Prints external names as |
532e88de77eb
8221470: Print methods in exception messages in java-like Syntax.
goetz
parents:
54347
diff
changeset
|
239 |
// 'double' or 'java.lang.Object[][]'. |
532e88de77eb
8221470: Print methods in exception messages in java-like Syntax.
goetz
parents:
54347
diff
changeset
|
240 |
void print_as_signature_external_parameters(outputStream *os); |
532e88de77eb
8221470: Print methods in exception messages in java-like Syntax.
goetz
parents:
54347
diff
changeset
|
241 |
|
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46492
diff
changeset
|
242 |
void metaspace_pointers_do(MetaspaceClosure* it); |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46492
diff
changeset
|
243 |
MetaspaceObj::Type type() const { return SymbolType; } |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46492
diff
changeset
|
244 |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
245 |
// Printing |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
246 |
void print_symbol_on(outputStream* st = NULL) const; |
33468
b82c87453d2d
8139996: CompileCommand prints quoted ascii strings
neliasso
parents:
32357
diff
changeset
|
247 |
void print_utf8_on(outputStream* st) const; |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
248 |
void print_on(outputStream* st) const; // First level print |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
249 |
void print_value_on(outputStream* st) const; // Second level print. |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
250 |
|
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
251 |
// printing on default output stream |
54807 | 252 |
void print() const; |
253 |
void print_value() const; |
|
1 | 254 |
|
52014
1aa9beac610e
8210754: print_location is not reliable enough (printing register info)
mdoerr
parents:
51997
diff
changeset
|
255 |
static bool is_valid(Symbol* s); |
1aa9beac610e
8210754: print_location is not reliable enough (printing register info)
mdoerr
parents:
51997
diff
changeset
|
256 |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
257 |
#ifndef PRODUCT |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
258 |
// Empty constructor to create a dummy symbol object on stack |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
259 |
// only for getting its vtable pointer. |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
260 |
Symbol() { } |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
261 |
|
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
262 |
static size_t _total_count; |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
263 |
#endif |
1 | 264 |
}; |
265 |
||
266 |
// Note: this comparison is used for vtable sorting only; it doesn't matter |
|
267 |
// what order it defines, as long as it is a total, time-invariant order |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
268 |
// Since Symbol*s are in C_HEAP, their relative order in memory never changes, |
1 | 269 |
// so use address comparison for speed |
34666 | 270 |
int Symbol::fast_compare(const Symbol* other) const { |
1 | 271 |
return (((uintptr_t)this < (uintptr_t)other) ? -1 |
272 |
: ((uintptr_t)this == (uintptr_t) other) ? 0 : 1); |
|
273 |
} |
|
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
53156
diff
changeset
|
274 |
#endif // SHARE_OOPS_SYMBOL_HPP |