annotate src/share/vm/oops/symbol.cpp @ 3011:f00918f35c7f

inlining and runtime interface related changes: added codeSize() and compilerStorage() to RiMethod HotSpotMethodResolved uses reflective methods instead of vmIds and survives compilations HotSpotResolvedType.isInitialized not represented as field (can change) inlining stores graphs into method objects and reuses them
author Lukas Stadler <lukas.stadler@jku.at>
date Thu, 16 Jun 2011 20:36:17 +0200
parents 1d1603768966
children fc9d8850ab8b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
2426
1d1603768966 7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass
trims
parents: 2177
diff changeset
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
25
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27 #include "oops/oop.inline.hpp"
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
28 #include "oops/symbol.hpp"
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
29 #include "runtime/os.hpp"
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
30 #include "memory/allocation.inline.hpp"
0
a61af66fc99e Initial load
duke
parents:
diff changeset
31
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
32 Symbol::Symbol(const u1* name, int length) : _refcount(0), _length(length) {
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
33 _identity_hash = os::random();
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
34 for (int i = 0; i < _length; i++) {
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
35 byte_at_put(i, name[i]);
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 }
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
38
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
39 void* Symbol::operator new(size_t size, int len) {
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
40 return (void *) AllocateHeap(object_size(len) * HeapWordSize, "symbol");
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
41 }
1138
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 222
diff changeset
42
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 222
diff changeset
43 // ------------------------------------------------------------------
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
44 // Symbol::equals
1138
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 222
diff changeset
45 //
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 222
diff changeset
46 // Compares the symbol with a string of the given length.
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
47 bool Symbol::equals(const char* str, int len) const {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
48 int l = utf8_length();
a61af66fc99e Initial load
duke
parents:
diff changeset
49 if (l != len) return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
50 while (l-- > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
51 if (str[l] != (char) byte_at(l))
a61af66fc99e Initial load
duke
parents:
diff changeset
52 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
53 }
a61af66fc99e Initial load
duke
parents:
diff changeset
54 assert(l == -1, "we should be at the beginning");
a61af66fc99e Initial load
duke
parents:
diff changeset
55 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
56 }
a61af66fc99e Initial load
duke
parents:
diff changeset
57
1138
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 222
diff changeset
58
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 222
diff changeset
59 // ------------------------------------------------------------------
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
60 // Symbol::starts_with
1138
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 222
diff changeset
61 //
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 222
diff changeset
62 // Tests if the symbol starts with the specified prefix of the given
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 222
diff changeset
63 // length.
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
64 bool Symbol::starts_with(const char* prefix, int len) const {
1138
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 222
diff changeset
65 if (len > utf8_length()) return false;
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 222
diff changeset
66 while (len-- > 0) {
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 222
diff changeset
67 if (prefix[len] != (char) byte_at(len))
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 222
diff changeset
68 return false;
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 222
diff changeset
69 }
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 222
diff changeset
70 assert(len == -1, "we should be at the beginning");
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 222
diff changeset
71 return true;
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 222
diff changeset
72 }
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 222
diff changeset
73
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 222
diff changeset
74
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 222
diff changeset
75 // ------------------------------------------------------------------
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
76 // Symbol::index_of
1138
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 222
diff changeset
77 //
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 222
diff changeset
78 // Finds if the given string is a substring of this symbol's utf8 bytes.
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 222
diff changeset
79 // Return -1 on failure. Otherwise return the first index where str occurs.
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
80 int Symbol::index_of_at(int i, const char* str, int len) const {
1138
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 222
diff changeset
81 assert(i >= 0 && i <= utf8_length(), "oob");
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 222
diff changeset
82 if (len <= 0) return 0;
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 222
diff changeset
83 char first_char = str[0];
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
84 address bytes = (address) ((Symbol*)this)->base();
1138
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 222
diff changeset
85 address limit = bytes + utf8_length() - len; // inclusive limit
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 222
diff changeset
86 address scan = bytes + i;
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 222
diff changeset
87 if (scan > limit)
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 222
diff changeset
88 return -1;
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 222
diff changeset
89 for (;;) {
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 222
diff changeset
90 scan = (address) memchr(scan, first_char, (limit + 1 - scan));
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 222
diff changeset
91 if (scan == NULL)
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 222
diff changeset
92 return -1; // not found
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 222
diff changeset
93 assert(scan >= bytes+i && scan <= limit, "scan oob");
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 222
diff changeset
94 if (memcmp(scan, str, len) == 0)
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 222
diff changeset
95 return (int)(scan - bytes);
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 222
diff changeset
96 }
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 222
diff changeset
97 }
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 222
diff changeset
98
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 222
diff changeset
99
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
100 char* Symbol::as_C_string(char* buf, int size) const {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
101 if (size > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 int len = MIN2(size - 1, utf8_length());
a61af66fc99e Initial load
duke
parents:
diff changeset
103 for (int i = 0; i < len; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
104 buf[i] = byte_at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
105 }
a61af66fc99e Initial load
duke
parents:
diff changeset
106 buf[len] = '\0';
a61af66fc99e Initial load
duke
parents:
diff changeset
107 }
a61af66fc99e Initial load
duke
parents:
diff changeset
108 return buf;
a61af66fc99e Initial load
duke
parents:
diff changeset
109 }
a61af66fc99e Initial load
duke
parents:
diff changeset
110
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
111 char* Symbol::as_C_string() const {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
112 int len = utf8_length();
a61af66fc99e Initial load
duke
parents:
diff changeset
113 char* str = NEW_RESOURCE_ARRAY(char, len + 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
114 return as_C_string(str, len + 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
115 }
a61af66fc99e Initial load
duke
parents:
diff changeset
116
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
117 char* Symbol::as_C_string_flexible_buffer(Thread* t,
0
a61af66fc99e Initial load
duke
parents:
diff changeset
118 char* buf, int size) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
119 char* str;
a61af66fc99e Initial load
duke
parents:
diff changeset
120 int len = utf8_length();
a61af66fc99e Initial load
duke
parents:
diff changeset
121 int buf_len = len + 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
122 if (size < buf_len) {
a61af66fc99e Initial load
duke
parents:
diff changeset
123 str = NEW_RESOURCE_ARRAY(char, buf_len);
a61af66fc99e Initial load
duke
parents:
diff changeset
124 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
125 str = buf;
a61af66fc99e Initial load
duke
parents:
diff changeset
126 }
a61af66fc99e Initial load
duke
parents:
diff changeset
127 return as_C_string(str, buf_len);
a61af66fc99e Initial load
duke
parents:
diff changeset
128 }
a61af66fc99e Initial load
duke
parents:
diff changeset
129
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
130 void Symbol::print_symbol_on(outputStream* st) const {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
131 st = st ? st : tty;
222
2a1a77d3458f 6718676: putback for 6604014 is incomplete
never
parents: 0
diff changeset
132 int length = UTF8::unicode_length((const char*)bytes(), utf8_length());
2a1a77d3458f 6718676: putback for 6604014 is incomplete
never
parents: 0
diff changeset
133 const char *ptr = (const char *)bytes();
2a1a77d3458f 6718676: putback for 6604014 is incomplete
never
parents: 0
diff changeset
134 jchar value;
2a1a77d3458f 6718676: putback for 6604014 is incomplete
never
parents: 0
diff changeset
135 for (int index = 0; index < length; index++) {
2a1a77d3458f 6718676: putback for 6604014 is incomplete
never
parents: 0
diff changeset
136 ptr = UTF8::next(ptr, &value);
2a1a77d3458f 6718676: putback for 6604014 is incomplete
never
parents: 0
diff changeset
137 if (value >= 32 && value < 127 || value == '\'' || value == '\\') {
2a1a77d3458f 6718676: putback for 6604014 is incomplete
never
parents: 0
diff changeset
138 st->put(value);
2a1a77d3458f 6718676: putback for 6604014 is incomplete
never
parents: 0
diff changeset
139 } else {
2a1a77d3458f 6718676: putback for 6604014 is incomplete
never
parents: 0
diff changeset
140 st->print("\\u%04x", value);
2a1a77d3458f 6718676: putback for 6604014 is incomplete
never
parents: 0
diff changeset
141 }
2a1a77d3458f 6718676: putback for 6604014 is incomplete
never
parents: 0
diff changeset
142 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
143 }
a61af66fc99e Initial load
duke
parents:
diff changeset
144
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
145 jchar* Symbol::as_unicode(int& length) const {
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
146 Symbol* this_ptr = (Symbol*)this;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
147 length = UTF8::unicode_length((char*)this_ptr->bytes(), utf8_length());
a61af66fc99e Initial load
duke
parents:
diff changeset
148 jchar* result = NEW_RESOURCE_ARRAY(jchar, length);
a61af66fc99e Initial load
duke
parents:
diff changeset
149 if (length > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
150 UTF8::convert_to_unicode((char*)this_ptr->bytes(), result, length);
a61af66fc99e Initial load
duke
parents:
diff changeset
151 }
a61af66fc99e Initial load
duke
parents:
diff changeset
152 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
153 }
a61af66fc99e Initial load
duke
parents:
diff changeset
154
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
155 const char* Symbol::as_klass_external_name(char* buf, int size) const {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
156 if (size > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
157 char* str = as_C_string(buf, size);
a61af66fc99e Initial load
duke
parents:
diff changeset
158 int length = (int)strlen(str);
a61af66fc99e Initial load
duke
parents:
diff changeset
159 // Turn all '/'s into '.'s (also for array klasses)
a61af66fc99e Initial load
duke
parents:
diff changeset
160 for (int index = 0; index < length; index++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
161 if (str[index] == '/') {
a61af66fc99e Initial load
duke
parents:
diff changeset
162 str[index] = '.';
a61af66fc99e Initial load
duke
parents:
diff changeset
163 }
a61af66fc99e Initial load
duke
parents:
diff changeset
164 }
a61af66fc99e Initial load
duke
parents:
diff changeset
165 return str;
a61af66fc99e Initial load
duke
parents:
diff changeset
166 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
167 return buf;
a61af66fc99e Initial load
duke
parents:
diff changeset
168 }
a61af66fc99e Initial load
duke
parents:
diff changeset
169 }
a61af66fc99e Initial load
duke
parents:
diff changeset
170
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
171 const char* Symbol::as_klass_external_name() const {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
172 char* str = as_C_string();
a61af66fc99e Initial load
duke
parents:
diff changeset
173 int length = (int)strlen(str);
a61af66fc99e Initial load
duke
parents:
diff changeset
174 // Turn all '/'s into '.'s (also for array klasses)
a61af66fc99e Initial load
duke
parents:
diff changeset
175 for (int index = 0; index < length; index++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
176 if (str[index] == '/') {
a61af66fc99e Initial load
duke
parents:
diff changeset
177 str[index] = '.';
a61af66fc99e Initial load
duke
parents:
diff changeset
178 }
a61af66fc99e Initial load
duke
parents:
diff changeset
179 }
a61af66fc99e Initial load
duke
parents:
diff changeset
180 return str;
a61af66fc99e Initial load
duke
parents:
diff changeset
181 }
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
182
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
183
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
184 void Symbol::print_on(outputStream* st) const {
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
185 if (this == NULL) {
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
186 st->print_cr("NULL");
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
187 } else {
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
188 st->print("Symbol: '");
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
189 print_symbol_on(st);
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
190 st->print("'");
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
191 st->print(" count %d", refcount());
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
192 }
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
193 }
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
194
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
195 // The print_value functions are present in all builds, to support the
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
196 // disassembler and error reporting.
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
197 void Symbol::print_value_on(outputStream* st) const {
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
198 if (this == NULL) {
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
199 st->print("NULL");
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
200 } else {
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
201 st->print("'");
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
202 for (int i = 0; i < utf8_length(); i++) {
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
203 st->print("%c", byte_at(i));
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
204 }
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
205 st->print("'");
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
206 }
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
207 }
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
208
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
209 void Symbol::increment_refcount() {
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
210 // Only increment the refcount if positive. If negative either
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
211 // overflow has occurred or it is a permanent symbol in a read only
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
212 // shared archive.
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
213 if (_refcount >= 0) {
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
214 Atomic::inc(&_refcount);
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
215 NOT_PRODUCT(Atomic::inc(&_total_count);)
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
216 }
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
217 }
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
218
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
219 void Symbol::decrement_refcount() {
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
220 if (_refcount >= 0) {
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
221 Atomic::dec(&_refcount);
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
222 #ifdef ASSERT
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
223 if (_refcount < 0) {
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
224 print();
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
225 assert(false, "reference count underflow for symbol");
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
226 }
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
227 #endif
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
228 }
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
229 }
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
230
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
231 NOT_PRODUCT(int Symbol::_total_count = 0;)