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