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