Mercurial > hg > graal-compiler
annotate src/share/vm/oops/symbol.hpp @ 7199:cd3d6a6b95d9
8003240: x86: move MacroAssembler into separate file
Reviewed-by: kvn
author | twisti |
---|---|
date | Fri, 30 Nov 2012 15:23:16 -0800 |
parents | bd7a7ce2e264 |
children | 63e54c37ac64 |
rev | line source |
---|---|
0 | 1 /* |
5979
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1138
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1138
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1138
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
25 #ifndef SHARE_VM_OOPS_SYMBOL_HPP |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
26 #define SHARE_VM_OOPS_SYMBOL_HPP |
1972 | 27 |
28 #include "utilities/utf8.hpp" | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
29 #include "memory/allocation.hpp" |
5979
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
30 #include "runtime/atomic.hpp" |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
31 |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
32 // A Symbol is a canonicalized string. |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
33 // All Symbols reside in global SymbolTable and are reference counted. |
1972 | 34 |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
35 // Reference counting |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
36 // |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
37 // All Symbols are allocated and added to the SymbolTable. |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
38 // When a class is unloaded, the reference counts of the Symbol pointers in |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
5979
diff
changeset
|
39 // the ConstantPool and in InstanceKlass (see release_C_heap_structures) are |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
40 // decremented. When the reference count for a Symbol goes to 0, the garbage |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
41 // collector can free the Symbol and remove it from the SymbolTable. |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
42 // |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
43 // 0) Symbols need to be reference counted when a pointer to the Symbol is |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
44 // saved in persistent storage. This does not include the pointer |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
45 // in the SymbolTable bucket (the _literal field in HashtableEntry) |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
46 // that points to the Symbol. All other stores of a Symbol* |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
47 // to a field of a persistent variable (e.g., the _name filed in |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
48 // FieldAccessInfo or _ptr in a CPSlot) is reference counted. |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
49 // |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
50 // 1) The lookup of a "name" in the SymbolTable either creates a Symbol F for |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
51 // "name" and returns a pointer to F or finds a pre-existing Symbol F for |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
52 // "name" and returns a pointer to it. In both cases the reference count for F |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
53 // is incremented under the assumption that a pointer to F will be created from |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
54 // the return value. Thus the increment of the reference count is on the lookup |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
55 // and not on the assignment to the new Symbol*. That is |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
56 // Symbol* G = lookup() |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
57 // ^ increment on lookup() |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
58 // and not |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
59 // Symbol* G = lookup() |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
60 // ^ increment on assignmnet |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
61 // The reference count must be decremented manually when the copy of the |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
62 // pointer G is destroyed. |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
63 // |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
64 // 2) For a local Symbol* A that is a copy of an existing Symbol* B, the |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
65 // reference counting is elided when the scope of B is greater than the scope |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
66 // of A. For example, in the code fragment |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
67 // below "klass" is passed as a parameter to the method. Symbol* "kn" |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
68 // is a copy of the name in "klass". |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
69 // |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
70 // Symbol* kn = klass->name(); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
71 // unsigned int d_hash = dictionary()->compute_hash(kn, class_loader); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
72 // |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
73 // The scope of "klass" is greater than the scope of "kn" so the reference |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
74 // counting for "kn" is elided. |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
75 // |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
76 // Symbol* copied from ConstantPool entries are good candidates for reference |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
77 // counting elision. The ConstantPool entries for a class C exist until C is |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
78 // unloaded. If a Symbol* is copied out of the ConstantPool into Symbol* X, |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
79 // the Symbol* in the ConstantPool will in general out live X so the reference |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
80 // counting on X can be elided. |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
81 // |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
82 // For cases where the scope of A is not greater than the scope of B, |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
83 // the reference counting is explicitly done. See ciSymbol, |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
84 // ResolutionErrorEntry and ClassVerifier for examples. |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
85 // |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
86 // 3) When a Symbol K is created for temporary use, generally for substrings of |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
87 // an existing symbol or to create a new symbol, assign it to a |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
88 // TempNewSymbol. The SymbolTable methods new_symbol(), lookup() |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
89 // and probe() all potentially return a pointer to a new Symbol. |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
90 // The allocation (or lookup) of K increments the reference count for K |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
91 // and the destructor decrements the reference count. |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
92 // |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
93 // Another example of TempNewSymbol usage is parsed_name used in |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
94 // ClassFileParser::parseClassFile() where parsed_name is used in the cleanup |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
95 // after a failed attempt to load a class. Here parsed_name is a |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
96 // TempNewSymbol (passed in as a parameter) so the reference count on its symbol |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
97 // will be decremented when it goes out of scope. |
0 | 98 |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
5979
diff
changeset
|
99 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
5979
diff
changeset
|
100 // This cannot be inherited from ResourceObj because it cannot have a vtable. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
5979
diff
changeset
|
101 // Since sometimes this is allocated from Metadata, pick a base allocation |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
5979
diff
changeset
|
102 // type without virtual functions. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
5979
diff
changeset
|
103 class ClassLoaderData; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
5979
diff
changeset
|
104 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
5979
diff
changeset
|
105 class Symbol : public MetaspaceObj { |
0 | 106 friend class VMStructs; |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
107 friend class SymbolTable; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
108 friend class MoveSymbols; |
0 | 109 private: |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
110 volatile int _refcount; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
111 int _identity_hash; |
0 | 112 unsigned short _length; // number of UTF8 characters in the symbol |
113 jbyte _body[1]; | |
114 | |
115 enum { | |
116 // max_symbol_length is constrained by type of _length | |
117 max_symbol_length = (1 << 16) -1 | |
118 }; | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
119 |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
5979
diff
changeset
|
120 static int size(int length) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
5979
diff
changeset
|
121 size_t sz = heap_word_size(sizeof(Symbol) + (length > 0 ? length - 1 : 0)); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
5979
diff
changeset
|
122 return align_object_size(sz); |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
123 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
124 |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
125 void byte_at_put(int index, int value) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
126 assert(index >=0 && index < _length, "symbol index overflow"); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
127 _body[index] = value; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
128 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
129 |
5979
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
130 Symbol(const u1* name, int length, int refcount); |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
131 void* operator new(size_t size, int len, TRAPS); |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
132 void* operator new(size_t size, int len, Arena* arena, TRAPS); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
5979
diff
changeset
|
133 void* operator new(size_t size, int len, ClassLoaderData* loader_data, TRAPS); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
5979
diff
changeset
|
134 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
5979
diff
changeset
|
135 void operator delete(void* p); |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
136 |
0 | 137 public: |
138 // Low-level access (used with care, since not GC-safe) | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
139 const jbyte* base() const { return &_body[0]; } |
0 | 140 |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
5979
diff
changeset
|
141 int size() { return size(utf8_length()); } |
0 | 142 |
143 // Returns the largest size symbol we can safely hold. | |
5979
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
144 static int max_length() { return max_symbol_length; } |
0 | 145 |
5979
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
146 int identity_hash() { return _identity_hash; } |
0 | 147 |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
5979
diff
changeset
|
148 // For symbol table alternate hashing |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
5979
diff
changeset
|
149 unsigned int new_hash(jint seed); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
5979
diff
changeset
|
150 |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
151 // Reference counting. See comments above this class for when to use. |
5979
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
152 int refcount() const { return _refcount; } |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
153 inline void increment_refcount(); |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
154 inline void decrement_refcount(); |
0 | 155 |
156 int byte_at(int index) const { | |
157 assert(index >=0 && index < _length, "symbol index overflow"); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
158 return base()[index]; |
0 | 159 } |
160 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
161 const jbyte* bytes() const { return base(); } |
0 | 162 |
163 int utf8_length() const { return _length; } | |
164 | |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
0
diff
changeset
|
165 // Compares the symbol with a string. |
0 | 166 bool equals(const char* str, int len) const; |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
0
diff
changeset
|
167 bool equals(const char* str) const { return equals(str, (int) strlen(str)); } |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
0
diff
changeset
|
168 |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
0
diff
changeset
|
169 // Tests if the symbol starts with the given prefix. |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
0
diff
changeset
|
170 bool starts_with(const char* prefix, int len) const; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
0
diff
changeset
|
171 bool starts_with(const char* prefix) const { |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
0
diff
changeset
|
172 return starts_with(prefix, (int) strlen(prefix)); |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
0
diff
changeset
|
173 } |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
0
diff
changeset
|
174 |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
0
diff
changeset
|
175 // Tests if the symbol starts with the given prefix. |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
0
diff
changeset
|
176 int index_of_at(int i, const char* str, int len) const; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
0
diff
changeset
|
177 int index_of_at(int i, const char* str) const { |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
0
diff
changeset
|
178 return index_of_at(i, str, (int) strlen(str)); |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
0
diff
changeset
|
179 } |
0 | 180 |
181 // Three-way compare for sorting; returns -1/0/1 if receiver is </==/> than arg | |
182 // note that the ordering is not alfabetical | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
183 inline int fast_compare(Symbol* other) const; |
0 | 184 |
185 // Returns receiver converted to null-terminated UTF-8 string; string is | |
186 // allocated in resource area, or in the char buffer provided by caller. | |
187 char* as_C_string() const; | |
188 char* as_C_string(char* buf, int size) const; | |
189 // Use buf if needed buffer length is <= size. | |
190 char* as_C_string_flexible_buffer(Thread* t, char* buf, int size) const; | |
191 | |
6972
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6725
diff
changeset
|
192 // Returns an escaped form of a Java string. |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6725
diff
changeset
|
193 char* as_quoted_ascii() const; |
0 | 194 |
195 // Returns a null terminated utf8 string in a resource array | |
196 char* as_utf8() const { return as_C_string(); } | |
197 char* as_utf8_flexible_buffer(Thread* t, char* buf, int size) const { | |
198 return as_C_string_flexible_buffer(t, buf, size); | |
199 } | |
200 | |
201 jchar* as_unicode(int& length) const; | |
202 | |
203 // Treating this symbol as a class name, returns the Java name for the class. | |
204 // String is allocated in resource area if buffer is not provided. | |
205 // See Klass::external_name() | |
206 const char* as_klass_external_name() const; | |
207 const char* as_klass_external_name(char* buf, int size) const; | |
208 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
209 // Printing |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
210 void print_symbol_on(outputStream* st = NULL) const; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
211 void print_on(outputStream* st) const; // First level print |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
212 void print_value_on(outputStream* st) const; // Second level print. |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
213 |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
214 // printing on default output stream |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
215 void print() { print_on(tty); } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
216 void print_value() { print_value_on(tty); } |
0 | 217 |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
218 #ifndef PRODUCT |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
219 // Empty constructor to create a dummy symbol object on stack |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
220 // only for getting its vtable pointer. |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
221 Symbol() { } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
222 |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
223 static int _total_count; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
224 #endif |
0 | 225 }; |
226 | |
227 // Note: this comparison is used for vtable sorting only; it doesn't matter | |
228 // what order it defines, as long as it is a total, time-invariant order | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
229 // Since Symbol*s are in C_HEAP, their relative order in memory never changes, |
0 | 230 // so use address comparison for speed |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
231 int Symbol::fast_compare(Symbol* other) const { |
0 | 232 return (((uintptr_t)this < (uintptr_t)other) ? -1 |
233 : ((uintptr_t)this == (uintptr_t) other) ? 0 : 1); | |
234 } | |
5979
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
235 |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
236 inline void Symbol::increment_refcount() { |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
237 // Only increment the refcount if positive. If negative either |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
238 // overflow has occurred or it is a permanent symbol in a read only |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
239 // shared archive. |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
240 if (_refcount >= 0) { |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
241 Atomic::inc(&_refcount); |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
242 NOT_PRODUCT(Atomic::inc(&_total_count);) |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
243 } |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
244 } |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
245 |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
246 inline void Symbol::decrement_refcount() { |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
247 if (_refcount >= 0) { |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
248 Atomic::dec(&_refcount); |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
249 #ifdef ASSERT |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
250 if (_refcount < 0) { |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
251 print(); |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
252 assert(false, "reference count underflow for symbol"); |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
253 } |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
254 #endif |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
255 } |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
256 } |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
257 #endif // SHARE_VM_OOPS_SYMBOL_HPP |