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: // ciSymbol duke@435: // duke@435: // This class represents a symbolOop in the HotSpot virtual duke@435: // machine. duke@435: class ciSymbol : public ciObject { duke@435: CI_PACKAGE_ACCESS twisti@1573: // These friends all make direct use of get_symbolOop: duke@435: friend class ciEnv; duke@435: friend class ciInstanceKlass; duke@435: friend class ciSignature; duke@435: friend class ciMethod; duke@435: friend class ciObjArrayKlass; duke@435: duke@435: private: duke@435: ciSymbol(symbolOop s) : ciObject(s) {} duke@435: ciSymbol(symbolHandle s); // for use with vmSymbolHandles duke@435: twisti@1573: symbolOop get_symbolOop() const { return (symbolOop)get_oop(); } duke@435: duke@435: const char* type_string() { return "ciSymbol"; } duke@435: duke@435: void print_impl(outputStream* st); duke@435: twisti@1573: // This is public in symbolOop but private here, because the base can move: duke@435: jbyte* base(); duke@435: duke@435: // Make a ciSymbol from a C string (implementation). duke@435: static ciSymbol* make_impl(const char* s); duke@435: duke@435: public: duke@435: // The text of the symbol as a null-terminated utf8 string. duke@435: const char* as_utf8(); duke@435: int utf8_length(); duke@435: twisti@1573: // Return the i-th utf8 byte, where i < utf8_length twisti@1573: int byte_at(int i); twisti@1573: twisti@1573: // Tests if the symbol starts with the given prefix. twisti@1573: bool starts_with(const char* prefix, int len) const; twisti@1573: twisti@1573: // Determines where the symbol contains the given substring. twisti@1573: int index_of_at(int i, const char* str, int len) const; twisti@1573: duke@435: // What kind of ciObject is this? duke@435: bool is_symbol() { return true; } duke@435: duke@435: void print_symbol_on(outputStream* st); duke@435: void print_symbol() { duke@435: print_symbol_on(tty); duke@435: } duke@435: duke@435: // Make a ciSymbol from a C string. duke@435: // Consider adding to vmSymbols.hpp instead of using this constructor. duke@435: // (Your code will be less subject to typographical bugs.) duke@435: static ciSymbol* make(const char* s); duke@435: duke@435: #define CI_SYMBOL_DECLARE(name, ignore_def) \ duke@435: static ciSymbol* name() { return ciObjectFactory::vm_symbol_at(vmSymbols::VM_SYMBOL_ENUM_NAME(name)); } duke@435: VM_SYMBOLS_DO(CI_SYMBOL_DECLARE, CI_SYMBOL_DECLARE) duke@435: #undef CI_SYMBOL_DECLARE duke@435: };