1 /*
2 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
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 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25
26 #include "precompiled.hpp"
27 #include "classfile/altHashing.hpp"
28 #include "classfile/classLoaderData.hpp"
29 #include "logging/log.hpp"
30 #include "memory/allocation.inline.hpp"
31 #include "memory/resourceArea.hpp"
32 #include "oops/symbol.hpp"
33 #include "runtime/atomic.hpp"
34 #include "runtime/os.hpp"
35
36 Symbol::Symbol(const u1* name, int length, int refcount) {
37 _refcount = refcount;
38 _length = length;
39 _identity_hash = (short)os::random();
40 for (int i = 0; i < _length; i++) {
41 byte_at_put(i, name[i]);
42 }
43 }
44
45 void* Symbol::operator new(size_t sz, int len, TRAPS) throw() {
46 int alloc_size = size(len)*wordSize;
47 address res = (address) AllocateHeap(alloc_size, mtSymbol);
48 return res;
49 }
214 Atomic::inc(&_refcount);
215 NOT_PRODUCT(Atomic::inc(&_total_count);)
216 }
217 }
218
219 void Symbol::decrement_refcount() {
220 if (_refcount >= 0) { // not a permanent symbol
221 jshort new_value = Atomic::add(-1, &_refcount);
222 #ifdef ASSERT
223 if (new_value == -1) { // we have transitioned from 0 -> -1
224 print();
225 assert(false, "reference count underflow for symbol");
226 }
227 #endif
228 (void)new_value;
229 }
230 }
231
232 void Symbol::metaspace_pointers_do(MetaspaceClosure* it) {
233 if (log_is_enabled(Trace, cds)) {
234 outputStream* log = Log(cds)::trace_stream();
235 log->print("Iter(Symbol): %p ", this);
236 print_value_on(log);
237 log->cr();
238 }
239 }
240
241 void Symbol::print_on(outputStream* st) const {
242 if (this == NULL) {
243 st->print_cr("NULL");
244 } else {
245 st->print("Symbol: '");
246 print_symbol_on(st);
247 st->print("'");
248 st->print(" count %d", refcount());
249 }
250 }
251
252 // The print_value functions are present in all builds, to support the
253 // disassembler and error reporting.
254 void Symbol::print_value_on(outputStream* st) const {
255 if (this == NULL) {
256 st->print("NULL");
257 } else {
|
1 /*
2 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
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 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25
26 #include "precompiled.hpp"
27 #include "classfile/altHashing.hpp"
28 #include "classfile/classLoaderData.hpp"
29 #include "logging/log.hpp"
30 #include "logging/logStream.hpp"
31 #include "memory/allocation.inline.hpp"
32 #include "memory/resourceArea.hpp"
33 #include "oops/symbol.hpp"
34 #include "runtime/atomic.hpp"
35 #include "runtime/os.hpp"
36
37 Symbol::Symbol(const u1* name, int length, int refcount) {
38 _refcount = refcount;
39 _length = length;
40 _identity_hash = (short)os::random();
41 for (int i = 0; i < _length; i++) {
42 byte_at_put(i, name[i]);
43 }
44 }
45
46 void* Symbol::operator new(size_t sz, int len, TRAPS) throw() {
47 int alloc_size = size(len)*wordSize;
48 address res = (address) AllocateHeap(alloc_size, mtSymbol);
49 return res;
50 }
215 Atomic::inc(&_refcount);
216 NOT_PRODUCT(Atomic::inc(&_total_count);)
217 }
218 }
219
220 void Symbol::decrement_refcount() {
221 if (_refcount >= 0) { // not a permanent symbol
222 jshort new_value = Atomic::add(-1, &_refcount);
223 #ifdef ASSERT
224 if (new_value == -1) { // we have transitioned from 0 -> -1
225 print();
226 assert(false, "reference count underflow for symbol");
227 }
228 #endif
229 (void)new_value;
230 }
231 }
232
233 void Symbol::metaspace_pointers_do(MetaspaceClosure* it) {
234 if (log_is_enabled(Trace, cds)) {
235 LogStream trace_stream(Log(cds)::trace());
236 trace_stream.print("Iter(Symbol): %p ", this);
237 print_value_on(&trace_stream);
238 trace_stream.cr();
239 }
240 }
241
242 void Symbol::print_on(outputStream* st) const {
243 if (this == NULL) {
244 st->print_cr("NULL");
245 } else {
246 st->print("Symbol: '");
247 print_symbol_on(st);
248 st->print("'");
249 st->print(" count %d", refcount());
250 }
251 }
252
253 // The print_value functions are present in all builds, to support the
254 // disassembler and error reporting.
255 void Symbol::print_value_on(outputStream* st) const {
256 if (this == NULL) {
257 st->print("NULL");
258 } else {
|