1 /*
2 * Copyright (c) 1999, 2025, 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 #include "ci/ciSymbol.hpp"
26 #include "ci/ciSymbols.hpp"
27 #include "ci/ciUtilities.inline.hpp"
28 #include "classfile/symbolTable.hpp"
29 #include "classfile/vmSymbols.hpp"
30 #include "memory/oopFactory.hpp"
31 #include "prims/methodHandles.hpp"
32
33 // ------------------------------------------------------------------
34 // ciSymbol::ciSymbol
35 ciSymbol::ciSymbol(Symbol* s, vmSymbolID sid)
36 : _symbol(s), _sid(sid)
37 {
38 assert(_symbol != nullptr, "adding null symbol");
39 _symbol->increment_refcount(); // increment ref count
40 assert(sid_ok(), "sid must be consistent with vmSymbols");
41 }
42
43 DEBUG_ONLY(bool ciSymbol::sid_ok() { return vmSymbols::find_sid(get_symbol()) == _sid; })
44
45 // ciSymbol
46 //
47 // This class represents a Symbol* in the HotSpot virtual
48 // machine.
49
50 // ------------------------------------------------------------------
51 // ciSymbol::as_utf8
52 //
53 // The text of the symbol as a null-terminated C string.
54 const char* ciSymbol::as_utf8() {
55 GUARDED_VM_QUICK_ENTRY(return get_symbol()->as_utf8();)
56 }
57
58 // The text of the symbol as a null-terminated C string.
59 const char* ciSymbol::as_quoted_ascii() {
60 GUARDED_VM_QUICK_ENTRY(return get_symbol()->as_quoted_ascii();)
61 }
62
63 // ------------------------------------------------------------------
64 // ciSymbol::base
65 const u1* ciSymbol::base() {
66 GUARDED_VM_ENTRY(return get_symbol()->base();)
67 }
68
69 // ------------------------------------------------------------------
70 // ciSymbol::char_at
71 char ciSymbol::char_at(int i) {
72 GUARDED_VM_ENTRY(return get_symbol()->char_at(i);)
73 }
74
75 // ------------------------------------------------------------------
76 // ciSymbol::starts_with
77 //
78 // Tests if the symbol starts with the given prefix.
79 bool ciSymbol::starts_with(const char* prefix, int len) const {
80 GUARDED_VM_ENTRY(return get_symbol()->starts_with(prefix, len);)
81 }
82
83 bool ciSymbol::is_signature_polymorphic_name() const {
84 GUARDED_VM_ENTRY(return MethodHandles::is_signature_polymorphic_name(get_symbol());)
85 }
86
87 // ------------------------------------------------------------------
88 // ciSymbol::index_of
89 //
90 // Determines where the symbol contains the given substring.
91 int ciSymbol::index_of_at(int i, const char* str, int len) const {
92 GUARDED_VM_ENTRY(return get_symbol()->index_of_at(i, str, len);)
93 }
94
95 // ------------------------------------------------------------------
96 // ciSymbol::utf8_length
97 int ciSymbol::utf8_length() {
98 GUARDED_VM_ENTRY(return get_symbol()->utf8_length();)
99 }
100
101 // ------------------------------------------------------------------
102 // ciSymbol::print_impl
103 //
104 // Implementation of the print method
105 void ciSymbol::print_impl(outputStream* st) {
106 st->print(" value=");
107 print_symbol_on(st);
108 }
109
110 // ------------------------------------------------------------------
111 // ciSymbol::print_symbol_on
112 //
113 // Print the value of this symbol on an outputStream
114 void ciSymbol::print_symbol_on(outputStream *st) {
115 GUARDED_VM_ENTRY(get_symbol()->print_symbol_on(st);)
116 }
117
118 const char* ciSymbol::as_klass_external_name() const {
119 GUARDED_VM_ENTRY(return get_symbol()->as_klass_external_name(););
120 }
121
122 // ------------------------------------------------------------------
123 // ciSymbol::make_impl
124 //
125 // Make a ciSymbol from a C string (implementation).
126 ciSymbol* ciSymbol::make_impl(const char* s) {
127 EXCEPTION_CONTEXT;
128 TempNewSymbol sym = SymbolTable::new_symbol(s);
129 return CURRENT_THREAD_ENV->get_symbol(sym);
130 }
131
132 // ------------------------------------------------------------------
133 // ciSymbol::make
134 //
135 // Make a ciSymbol from a C string.
136 ciSymbol* ciSymbol::make(const char* s) {
137 GUARDED_VM_ENTRY(return make_impl(s);)
138 }