ciSymbol.cpp revision 0:a61af66fc99e
1116742Ssam/* 2116904Ssam * Copyright 1999-2007 Sun Microsystems, Inc. All Rights Reserved. 3186904Ssam * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4116742Ssam * 5116742Ssam * This code is free software; you can redistribute it and/or modify it 6116742Ssam * under the terms of the GNU General Public License version 2 only, as 7116742Ssam * published by the Free Software Foundation. 8116742Ssam * 9116742Ssam * This code is distributed in the hope that it will be useful, but WITHOUT 10116904Ssam * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11116904Ssam * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12116904Ssam * version 2 for more details (a copy is included in the LICENSE file that 13116904Ssam * accompanied this code). 14116742Ssam * 15116904Ssam * You should have received a copy of the GNU General Public License version 16116904Ssam * 2 along with this work; if not, write to the Free Software Foundation, 17116904Ssam * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18116904Ssam * 19116904Ssam * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 20116904Ssam * CA 95054 USA or visit www.sun.com if you need additional information or 21116904Ssam * have any questions. 22116904Ssam * 23116904Ssam */ 24116904Ssam 25116742Ssam#include "incls/_precompiled.incl" 26116742Ssam#include "incls/_ciSymbol.cpp.incl" 27116742Ssam 28116742Ssam// ------------------------------------------------------------------ 29116742Ssam// ciSymbol::ciSymbol 30116742Ssam// 31116742Ssam// Preallocated handle variant. Used with handles from vmSymboHandles. 32116742SsamciSymbol::ciSymbol(symbolHandle h_s) : ciObject(h_s) { 33116742Ssam} 34127646Ssam 35127646Ssam// ciSymbol 36178354Ssam// 37127646Ssam// This class represents a symbolOop in the HotSpot virtual 38116742Ssam// machine. 39116742Ssam 40116742Ssam// ------------------------------------------------------------------ 41164033Srwatson// ciSymbol::as_utf8 42116742Ssam// 43116742Ssam// The text of the symbol as a null-terminated C string. 44116742Ssamconst char* ciSymbol::as_utf8() { 45116742Ssam VM_QUICK_ENTRY_MARK; 46116742Ssam symbolOop s = get_symbolOop(); 47152315Sru return s->as_utf8(); 48116742Ssam} 49116742Ssam 50116742Ssam// ------------------------------------------------------------------ 51127646Ssam// ciSymbol::base 52127646Ssamjbyte* ciSymbol::base() { 53127646Ssam GUARDED_VM_ENTRY(return get_symbolOop()->base();) 54127646Ssam} 55127646Ssam 56127646Ssam// ------------------------------------------------------------------ 57127646Ssam// ciSymbol::byte_at 58127646Ssamint ciSymbol::byte_at(int i) { 59127646Ssam GUARDED_VM_ENTRY(return get_symbolOop()->byte_at(i);) 60127646Ssam} 61116742Ssam 62116742Ssam// ------------------------------------------------------------------ 63178354Ssam// ciSymbol::utf8_length 64178354Ssamint ciSymbol::utf8_length() { 65116742Ssam GUARDED_VM_ENTRY(return get_symbolOop()->utf8_length();) 66178354Ssam} 67193347Ssam 68178354Ssam// ------------------------------------------------------------------ 69138568Ssam// ciSymbol::print_impl 70178354Ssam// 71170530Ssam// Implementation of the print method 72170530Ssamvoid ciSymbol::print_impl(outputStream* st) { 73206457Sbschmidt st->print(" value="); 74206457Sbschmidt print_symbol_on(st); 75116742Ssam} 76178354Ssam 77178354Ssam// ------------------------------------------------------------------ 78138568Ssam// ciSymbol::print_symbol_on 79178354Ssam// 80138568Ssam// Print the value of this symbol on an outputStream 81138568Ssamvoid ciSymbol::print_symbol_on(outputStream *st) { 82138568Ssam GUARDED_VM_ENTRY(get_symbolOop()->print_symbol_on(st);) 83138568Ssam} 84138568Ssam 85138568Ssam// ------------------------------------------------------------------ 86138568Ssam// ciSymbol::make_impl 87138568Ssam// 88138568Ssam// Make a ciSymbol from a C string (implementation). 89138568SsamciSymbol* ciSymbol::make_impl(const char* s) { 90138568Ssam EXCEPTION_CONTEXT; 91138568Ssam // For some reason, oopFactory::new_symbol doesn't declare its 92138568Ssam // char* argument as const. 93138568Ssam symbolOop sym = oopFactory::new_symbol((char*)s, (int)strlen(s), THREAD); 94178354Ssam if (HAS_PENDING_EXCEPTION) { 95138568Ssam CLEAR_PENDING_EXCEPTION; 96178354Ssam CURRENT_THREAD_ENV->record_out_of_memory_failure(); 97138568Ssam return ciEnv::_unloaded_cisymbol; 98138568Ssam } 99138568Ssam return CURRENT_THREAD_ENV->get_object(sym)->as_symbol(); 100138568Ssam} 101178354Ssam 102178354Ssam// ------------------------------------------------------------------ 103138568Ssam// ciSymbol::make 104138568Ssam// 105138568Ssam// Make a ciSymbol from a C string. 106138568SsamciSymbol* ciSymbol::make(const char* s) { 107138568Ssam GUARDED_VM_ENTRY(return make_impl(s);) 108138568Ssam} 109178354Ssam