duke@435: /* twisti@1573: * Copyright 1999-2009 Sun Microsystems, Inc. All Rights Reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * duke@435: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@435: * CA 95054 USA or visit www.sun.com if you need additional information or duke@435: * have any questions. duke@435: * duke@435: */ duke@435: duke@435: #include "incls/_precompiled.incl" duke@435: #include "incls/_ciSymbol.cpp.incl" duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciSymbol::ciSymbol duke@435: // duke@435: // Preallocated handle variant. Used with handles from vmSymboHandles. duke@435: ciSymbol::ciSymbol(symbolHandle h_s) : ciObject(h_s) { duke@435: } duke@435: duke@435: // ciSymbol duke@435: // duke@435: // This class represents a symbolOop in the HotSpot virtual duke@435: // machine. duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciSymbol::as_utf8 duke@435: // duke@435: // The text of the symbol as a null-terminated C string. duke@435: const char* ciSymbol::as_utf8() { duke@435: VM_QUICK_ENTRY_MARK; duke@435: symbolOop s = get_symbolOop(); duke@435: return s->as_utf8(); duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciSymbol::base duke@435: jbyte* ciSymbol::base() { duke@435: GUARDED_VM_ENTRY(return get_symbolOop()->base();) duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciSymbol::byte_at duke@435: int ciSymbol::byte_at(int i) { duke@435: GUARDED_VM_ENTRY(return get_symbolOop()->byte_at(i);) duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ twisti@1573: // ciSymbol::starts_with twisti@1573: // twisti@1573: // Tests if the symbol starts with the given prefix. twisti@1573: bool ciSymbol::starts_with(const char* prefix, int len) const { twisti@1573: GUARDED_VM_ENTRY(return get_symbolOop()->starts_with(prefix, len);) twisti@1573: } twisti@1573: twisti@1573: // ------------------------------------------------------------------ twisti@1573: // ciSymbol::index_of twisti@1573: // twisti@1573: // Determines where the symbol contains the given substring. twisti@1573: int ciSymbol::index_of_at(int i, const char* str, int len) const { twisti@1573: GUARDED_VM_ENTRY(return get_symbolOop()->index_of_at(i, str, len);) twisti@1573: } twisti@1573: twisti@1573: // ------------------------------------------------------------------ duke@435: // ciSymbol::utf8_length duke@435: int ciSymbol::utf8_length() { duke@435: GUARDED_VM_ENTRY(return get_symbolOop()->utf8_length();) duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciSymbol::print_impl duke@435: // duke@435: // Implementation of the print method duke@435: void ciSymbol::print_impl(outputStream* st) { duke@435: st->print(" value="); duke@435: print_symbol_on(st); duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciSymbol::print_symbol_on duke@435: // duke@435: // Print the value of this symbol on an outputStream duke@435: void ciSymbol::print_symbol_on(outputStream *st) { duke@435: GUARDED_VM_ENTRY(get_symbolOop()->print_symbol_on(st);) duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciSymbol::make_impl duke@435: // duke@435: // Make a ciSymbol from a C string (implementation). duke@435: ciSymbol* ciSymbol::make_impl(const char* s) { duke@435: EXCEPTION_CONTEXT; duke@435: // For some reason, oopFactory::new_symbol doesn't declare its duke@435: // char* argument as const. duke@435: symbolOop sym = oopFactory::new_symbol((char*)s, (int)strlen(s), THREAD); duke@435: if (HAS_PENDING_EXCEPTION) { duke@435: CLEAR_PENDING_EXCEPTION; duke@435: CURRENT_THREAD_ENV->record_out_of_memory_failure(); duke@435: return ciEnv::_unloaded_cisymbol; duke@435: } duke@435: return CURRENT_THREAD_ENV->get_object(sym)->as_symbol(); duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciSymbol::make duke@435: // duke@435: // Make a ciSymbol from a C string. duke@435: ciSymbol* ciSymbol::make(const char* s) { duke@435: GUARDED_VM_ENTRY(return make_impl(s);) duke@435: }