duke@435: /* duke@435: * Copyright 1997-2006 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/_symbolKlass.cpp.incl" duke@435: duke@435: symbolOop symbolKlass::allocate_symbol(u1* name, int len, TRAPS) { duke@435: // Don't allow symbol oops to be created which cannot fit in a symbolOop. duke@435: if (len > symbolOopDesc::max_length()) { duke@435: THROW_MSG_0(vmSymbols::java_lang_InternalError(), duke@435: "name is too long to represent"); duke@435: } duke@435: int size = symbolOopDesc::object_size(len); duke@435: symbolKlassHandle h_k(THREAD, as_klassOop()); duke@435: symbolOop sym = (symbolOop) duke@435: CollectedHeap::permanent_obj_allocate(h_k, size, CHECK_NULL); duke@435: assert(!sym->is_parsable(), "not expecting parsability yet."); duke@435: No_Safepoint_Verifier no_safepoint; duke@435: sym->set_utf8_length(len); duke@435: for (int i = 0; i < len; i++) { duke@435: sym->byte_at_put(i, name[i]); duke@435: } duke@435: // Let the first emptySymbol be created and duke@435: // ensure only one is ever created. duke@435: assert(sym->is_parsable() || Universe::emptySymbol() == NULL, duke@435: "should be parsable here."); duke@435: return sym; duke@435: } duke@435: duke@435: bool symbolKlass::allocate_symbols(int names_count, const char** names, duke@435: int* lengths, symbolOop* sym_oops, TRAPS) { duke@435: if (UseConcMarkSweepGC || UseParallelGC) { duke@435: // Concurrent GC needs to mark all the allocated symbol oops after duke@435: // the remark phase which isn't done below (except the first symbol oop). duke@435: // So return false which will let the symbols be allocated one by one. duke@435: // The parallel collector uses an object start array to find the duke@435: // start of objects on a dirty card. The object start array is not duke@435: // updated for the start of each symbol so is not precise. During duke@435: // object array verification this causes a verification failure. duke@435: // In a product build this causes extra searching for the start of duke@435: // a symbol. As with the concurrent collector a return of false will duke@435: // cause each symbol to be allocated separately and in the case duke@435: // of the parallel collector will cause the object duke@435: // start array to be updated. duke@435: return false; duke@435: } duke@435: duke@435: assert(names_count > 0, "can't allocate 0 symbols"); duke@435: duke@435: int total_size = 0; duke@435: int i, sizes[SymbolTable::symbol_alloc_batch_size]; duke@435: for (i=0; i symbolOopDesc::max_length()) { duke@435: return false; duke@435: } duke@435: int sz = symbolOopDesc::object_size(len); duke@435: sizes[i] = sz * HeapWordSize; duke@435: total_size += sz; duke@435: } duke@435: symbolKlassHandle h_k(THREAD, as_klassOop()); duke@435: HeapWord* base = Universe::heap()->permanent_mem_allocate(total_size); duke@435: if (base == NULL) { duke@435: return false; duke@435: } duke@435: duke@435: // CAN'T take any safepoint during the initialization of the symbol oops ! duke@435: No_Safepoint_Verifier nosafepoint; duke@435: duke@435: klassOop sk = h_k(); duke@435: int pos = 0; duke@435: for (i=0; iset_mark(markOopDesc::prototype()); duke@435: s->set_klass(sk); duke@435: s->set_utf8_length(lengths[i]); duke@435: const char* name = names[i]; duke@435: for (int j=0; jbyte_at_put(j, name[j]); duke@435: } duke@435: duke@435: assert(s->is_parsable(), "should be parsable here."); duke@435: duke@435: sym_oops[i] = s; duke@435: pos += sizes[i]; duke@435: } duke@435: return true; duke@435: } duke@435: duke@435: klassOop symbolKlass::create_klass(TRAPS) { duke@435: symbolKlass o; duke@435: KlassHandle h_this_klass(THREAD, Universe::klassKlassObj()); duke@435: KlassHandle k = base_create_klass(h_this_klass, header_size(), o.vtbl_value(), CHECK_NULL); duke@435: // Make sure size calculation is right duke@435: assert(k()->size() == align_object_size(header_size()), "wrong size for object"); duke@435: // java_lang_Class::create_mirror(k, CHECK_NULL); // Allocate mirror duke@435: return k(); duke@435: } duke@435: duke@435: int symbolKlass::oop_size(oop obj) const { duke@435: assert(obj->is_symbol(),"must be a symbol"); duke@435: symbolOop s = symbolOop(obj); duke@435: int size = s->object_size(); duke@435: return size; duke@435: } duke@435: duke@435: bool symbolKlass::oop_is_parsable(oop obj) const { duke@435: assert(obj->is_symbol(),"must be a symbol"); duke@435: symbolOop s = symbolOop(obj); duke@435: return s->object_is_parsable(); duke@435: } duke@435: duke@435: void symbolKlass::oop_follow_contents(oop obj) { duke@435: assert (obj->is_symbol(), "object must be symbol"); duke@435: // Performance tweak: We skip iterating over the klass pointer since we duke@435: // know that Universe::symbolKlassObj never moves. duke@435: // Note: do not follow next link here (see SymbolTable::follow_contents) duke@435: } duke@435: duke@435: #ifndef SERIALGC duke@435: void symbolKlass::oop_follow_contents(ParCompactionManager* cm, oop obj) { duke@435: assert (obj->is_symbol(), "object must be symbol"); duke@435: // Performance tweak: We skip iterating over the klass pointer since we duke@435: // know that Universe::symbolKlassObj never moves. duke@435: // Note: do not follow next link here (see SymbolTable::follow_contents) duke@435: } duke@435: #endif // SERIALGC duke@435: duke@435: int symbolKlass::oop_oop_iterate(oop obj, OopClosure* blk) { duke@435: assert(obj->is_symbol(), "object must be symbol"); duke@435: symbolOop s = symbolOop(obj); duke@435: // Get size before changing pointers. duke@435: // Don't call size() or oop_size() since that is a virtual call. duke@435: int size = s->object_size(); duke@435: // Performance tweak: We skip iterating over the klass pointer since we duke@435: // know that Universe::symbolKlassObj never moves. duke@435: return size; duke@435: } duke@435: duke@435: duke@435: int symbolKlass::oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr) { duke@435: assert(obj->is_symbol(), "object must be symbol"); duke@435: symbolOop s = symbolOop(obj); duke@435: // Get size before changing pointers. duke@435: // Don't call size() or oop_size() since that is a virtual call. duke@435: int size = s->object_size(); duke@435: // Performance tweak: We skip iterating over the klass pointer since we duke@435: // know that Universe::symbolKlassObj never moves. duke@435: return size; duke@435: } duke@435: duke@435: duke@435: int symbolKlass::oop_adjust_pointers(oop obj) { duke@435: assert(obj->is_symbol(), "should be symbol"); duke@435: symbolOop s = symbolOop(obj); duke@435: // Get size before changing pointers. duke@435: // Don't call size() or oop_size() since that is a virtual call. duke@435: int size = s->object_size(); duke@435: // Performance tweak: We skip iterating over the klass pointer since we duke@435: // know that Universe::symbolKlassObj never moves. duke@435: return size; duke@435: } duke@435: duke@435: duke@435: #ifndef SERIALGC duke@435: void symbolKlass::oop_copy_contents(PSPromotionManager* pm, oop obj) { duke@435: assert(obj->is_symbol(), "should be symbol"); duke@435: } duke@435: duke@435: void symbolKlass::oop_push_contents(PSPromotionManager* pm, oop obj) { duke@435: assert(obj->is_symbol(), "should be symbol"); duke@435: } duke@435: duke@435: int symbolKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) { duke@435: assert(obj->is_symbol(), "should be symbol"); duke@435: return symbolOop(obj)->object_size(); duke@435: } duke@435: duke@435: int symbolKlass::oop_update_pointers(ParCompactionManager* cm, oop obj, duke@435: HeapWord* beg_addr, HeapWord* end_addr) { duke@435: assert(obj->is_symbol(), "should be symbol"); duke@435: return symbolOop(obj)->object_size(); duke@435: } duke@435: #endif // SERIALGC duke@435: duke@435: #ifndef PRODUCT duke@435: // Printing duke@435: duke@435: void symbolKlass::oop_print_on(oop obj, outputStream* st) { duke@435: st->print("Symbol: '"); never@657: symbolOop(obj)->print_symbol_on(st); duke@435: st->print("'"); duke@435: } duke@435: jrose@1590: #endif //PRODUCT jrose@1590: duke@435: void symbolKlass::oop_print_value_on(oop obj, outputStream* st) { duke@435: symbolOop sym = symbolOop(obj); duke@435: st->print("'"); duke@435: for (int i = 0; i < sym->utf8_length(); i++) { duke@435: st->print("%c", sym->byte_at(i)); duke@435: } duke@435: st->print("'"); duke@435: } duke@435: duke@435: const char* symbolKlass::internal_name() const { duke@435: return "{symbol}"; duke@435: }