ciSymbol.hpp revision 1879:f95d63e2154a
11541Srgrimes/*
21541Srgrimes * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
31541Srgrimes * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
41541Srgrimes *
529349Speter * This code is free software; you can redistribute it and/or modify it
61541Srgrimes * under the terms of the GNU General Public License version 2 only, as
71541Srgrimes * published by the Free Software Foundation.
81541Srgrimes *
91541Srgrimes * This code is distributed in the hope that it will be useful, but WITHOUT
101541Srgrimes * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
111541Srgrimes * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
121541Srgrimes * version 2 for more details (a copy is included in the LICENSE file that
131541Srgrimes * accompanied this code).
141541Srgrimes *
151541Srgrimes * You should have received a copy of the GNU General Public License version
161541Srgrimes * 2 along with this work; if not, write to the Free Software Foundation,
171541Srgrimes * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
181541Srgrimes *
191541Srgrimes * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
201541Srgrimes * or visit www.oracle.com if you need additional information or have any
211541Srgrimes * questions.
221541Srgrimes *
231541Srgrimes */
241541Srgrimes
251541Srgrimes#ifndef SHARE_VM_CI_CISYMBOL_HPP
261541Srgrimes#define SHARE_VM_CI_CISYMBOL_HPP
271541Srgrimes
281541Srgrimes#include "ci/ciObject.hpp"
291541Srgrimes#include "ci/ciObjectFactory.hpp"
301541Srgrimes#include "classfile/vmSymbols.hpp"
311541Srgrimes#include "oops/symbolOop.hpp"
321541Srgrimes
331541Srgrimes// ciSymbol
341541Srgrimes//
351541Srgrimes// This class represents a symbolOop in the HotSpot virtual
361541Srgrimes// machine.
371541Srgrimesclass ciSymbol : public ciObject {
381541Srgrimes  CI_PACKAGE_ACCESS
391541Srgrimes  // These friends all make direct use of get_symbolOop:
401541Srgrimes  friend class ciEnv;
411541Srgrimes  friend class ciInstanceKlass;
421541Srgrimes  friend class ciSignature;
431541Srgrimes  friend class ciMethod;
441541Srgrimes  friend class ciObjArrayKlass;
451541Srgrimes
461541Srgrimesprivate:
471541Srgrimes  const vmSymbols::SID _sid;
481541Srgrimes  DEBUG_ONLY( bool sid_ok() { return vmSymbols::find_sid(get_symbolOop()) == _sid; } )
491541Srgrimes
501541Srgrimes  ciSymbol(symbolOop s);  // normal case, for symbols not mentioned in vmSymbols
511541Srgrimes  ciSymbol(symbolHandle s, vmSymbols::SID sid);   // for use with vmSymbolHandles
521541Srgrimes
531541Srgrimes  symbolOop get_symbolOop() const { return (symbolOop)get_oop(); }
541541Srgrimes
551541Srgrimes  const char* type_string() { return "ciSymbol"; }
561541Srgrimes
571541Srgrimes  void print_impl(outputStream* st);
581541Srgrimes
591541Srgrimes  // This is public in symbolOop but private here, because the base can move:
601541Srgrimes  jbyte*      base();
611541Srgrimes
621541Srgrimes  // Make a ciSymbol from a C string (implementation).
631541Srgrimes  static ciSymbol* make_impl(const char* s);
641541Srgrimes
651541Srgrimespublic:
661541Srgrimes  // The enumeration ID from vmSymbols, or vmSymbols::NO_SID if none.
671541Srgrimes  vmSymbols::SID sid() const { return _sid; }
681541Srgrimes
691541Srgrimes  // The text of the symbol as a null-terminated utf8 string.
701541Srgrimes  const char* as_utf8();
711541Srgrimes  int         utf8_length();
721541Srgrimes
731541Srgrimes  // Return the i-th utf8 byte, where i < utf8_length
741541Srgrimes  int         byte_at(int i);
751541Srgrimes
761541Srgrimes  // Tests if the symbol starts with the given prefix.
771541Srgrimes  bool starts_with(const char* prefix, int len) const;
781541Srgrimes
791541Srgrimes  // Determines where the symbol contains the given substring.
801541Srgrimes  int index_of_at(int i, const char* str, int len) const;
811541Srgrimes
821541Srgrimes  // What kind of ciObject is this?
831541Srgrimes  bool is_symbol() { return true; }
841541Srgrimes
851541Srgrimes  void print_symbol_on(outputStream* st);
861541Srgrimes  void print_symbol() {
871541Srgrimes    print_symbol_on(tty);
881541Srgrimes  }
891541Srgrimes
901541Srgrimes  // Make a ciSymbol from a C string.
911541Srgrimes  // Consider adding to vmSymbols.hpp instead of using this constructor.
921541Srgrimes  // (Your code will be less subject to typographical bugs.)
931541Srgrimes  static ciSymbol* make(const char* s);
941541Srgrimes
951541Srgrimes#define CI_SYMBOL_DECLARE(name, ignore_def) \
961541Srgrimes  static ciSymbol* name() { return ciObjectFactory::vm_symbol_at(vmSymbols::VM_SYMBOL_ENUM_NAME(name)); }
971541Srgrimes  VM_SYMBOLS_DO(CI_SYMBOL_DECLARE, CI_SYMBOL_DECLARE)
981541Srgrimes#undef CI_SYMBOL_DECLARE
991541Srgrimes};
1001541Srgrimes
1011541Srgrimes#endif // SHARE_VM_CI_CISYMBOL_HPP
1021541Srgrimes