aoqi@0: /* aoqi@0: * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #include "precompiled.hpp" aoqi@0: #include "ci/ciSymbol.hpp" aoqi@0: #include "ci/ciUtilities.hpp" aoqi@0: #include "memory/oopFactory.hpp" aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciSymbol::ciSymbol aoqi@0: // aoqi@0: // Preallocated symbol variant. Used with symbols from vmSymbols. aoqi@0: ciSymbol::ciSymbol(Symbol* s, vmSymbols::SID sid) aoqi@0: : _symbol(s), _sid(sid) aoqi@0: { aoqi@0: assert(_symbol != NULL, "adding null symbol"); aoqi@0: _symbol->increment_refcount(); // increment ref count aoqi@0: assert(sid_ok(), "must be in vmSymbols"); aoqi@0: } aoqi@0: aoqi@0: // Normal case for non-famous symbols. aoqi@0: ciSymbol::ciSymbol(Symbol* s) aoqi@0: : _symbol(s), _sid(vmSymbols::NO_SID) aoqi@0: { aoqi@0: assert(_symbol != NULL, "adding null symbol"); aoqi@0: _symbol->increment_refcount(); // increment ref count aoqi@0: assert(sid_ok(), "must not be in vmSymbols"); aoqi@0: } aoqi@0: aoqi@0: // ciSymbol aoqi@0: // aoqi@0: // This class represents a Symbol* in the HotSpot virtual aoqi@0: // machine. aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciSymbol::as_utf8 aoqi@0: // aoqi@0: // The text of the symbol as a null-terminated C string. aoqi@0: const char* ciSymbol::as_utf8() { aoqi@0: VM_QUICK_ENTRY_MARK; aoqi@0: Symbol* s = get_symbol(); aoqi@0: return s->as_utf8(); aoqi@0: } aoqi@0: aoqi@0: // The text of the symbol as a null-terminated C string. aoqi@0: const char* ciSymbol::as_quoted_ascii() { aoqi@0: GUARDED_VM_QUICK_ENTRY(return get_symbol()->as_quoted_ascii();) aoqi@0: } aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciSymbol::base aoqi@0: const jbyte* ciSymbol::base() { aoqi@0: GUARDED_VM_ENTRY(return get_symbol()->base();) aoqi@0: } aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciSymbol::byte_at aoqi@0: int ciSymbol::byte_at(int i) { aoqi@0: GUARDED_VM_ENTRY(return get_symbol()->byte_at(i);) aoqi@0: } aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciSymbol::starts_with aoqi@0: // aoqi@0: // Tests if the symbol starts with the given prefix. aoqi@0: bool ciSymbol::starts_with(const char* prefix, int len) const { aoqi@0: GUARDED_VM_ENTRY(return get_symbol()->starts_with(prefix, len);) aoqi@0: } aoqi@0: aoqi@0: bool ciSymbol::is_signature_polymorphic_name() const { aoqi@0: GUARDED_VM_ENTRY(return MethodHandles::is_signature_polymorphic_name(get_symbol());) aoqi@0: } aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciSymbol::index_of aoqi@0: // aoqi@0: // Determines where the symbol contains the given substring. aoqi@0: int ciSymbol::index_of_at(int i, const char* str, int len) const { aoqi@0: GUARDED_VM_ENTRY(return get_symbol()->index_of_at(i, str, len);) aoqi@0: } aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciSymbol::utf8_length aoqi@0: int ciSymbol::utf8_length() { aoqi@0: GUARDED_VM_ENTRY(return get_symbol()->utf8_length();) aoqi@0: } aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciSymbol::print_impl aoqi@0: // aoqi@0: // Implementation of the print method aoqi@0: void ciSymbol::print_impl(outputStream* st) { aoqi@0: st->print(" value="); aoqi@0: print_symbol_on(st); aoqi@0: } aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciSymbol::print_symbol_on aoqi@0: // aoqi@0: // Print the value of this symbol on an outputStream aoqi@0: void ciSymbol::print_symbol_on(outputStream *st) { aoqi@0: GUARDED_VM_ENTRY(get_symbol()->print_symbol_on(st);) aoqi@0: } aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciSymbol::make_impl aoqi@0: // aoqi@0: // Make a ciSymbol from a C string (implementation). aoqi@0: ciSymbol* ciSymbol::make_impl(const char* s) { aoqi@0: EXCEPTION_CONTEXT; aoqi@0: TempNewSymbol sym = SymbolTable::new_symbol(s, THREAD); aoqi@0: if (HAS_PENDING_EXCEPTION) { aoqi@0: CLEAR_PENDING_EXCEPTION; aoqi@0: CURRENT_THREAD_ENV->record_out_of_memory_failure(); aoqi@0: return ciEnv::_unloaded_cisymbol; aoqi@0: } aoqi@0: return CURRENT_THREAD_ENV->get_symbol(sym); aoqi@0: } aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciSymbol::make aoqi@0: // aoqi@0: // Make a ciSymbol from a C string. aoqi@0: ciSymbol* ciSymbol::make(const char* s) { aoqi@0: GUARDED_VM_ENTRY(return make_impl(s);) aoqi@0: }