src/share/vm/oops/symbolKlass.cpp

Thu, 13 Mar 2008 14:17:48 -0700

author
dcubed
date
Thu, 13 Mar 2008 14:17:48 -0700
changeset 487
75b0f3cb1943
parent 435
a61af66fc99e
child 657
2a1a77d3458f
permissions
-rw-r--r--

Merge

duke@435 1 /*
duke@435 2 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 # include "incls/_precompiled.incl"
duke@435 26 # include "incls/_symbolKlass.cpp.incl"
duke@435 27
duke@435 28 symbolOop symbolKlass::allocate_symbol(u1* name, int len, TRAPS) {
duke@435 29 // Don't allow symbol oops to be created which cannot fit in a symbolOop.
duke@435 30 if (len > symbolOopDesc::max_length()) {
duke@435 31 THROW_MSG_0(vmSymbols::java_lang_InternalError(),
duke@435 32 "name is too long to represent");
duke@435 33 }
duke@435 34 int size = symbolOopDesc::object_size(len);
duke@435 35 symbolKlassHandle h_k(THREAD, as_klassOop());
duke@435 36 symbolOop sym = (symbolOop)
duke@435 37 CollectedHeap::permanent_obj_allocate(h_k, size, CHECK_NULL);
duke@435 38 assert(!sym->is_parsable(), "not expecting parsability yet.");
duke@435 39 No_Safepoint_Verifier no_safepoint;
duke@435 40 sym->set_utf8_length(len);
duke@435 41 for (int i = 0; i < len; i++) {
duke@435 42 sym->byte_at_put(i, name[i]);
duke@435 43 }
duke@435 44 // Let the first emptySymbol be created and
duke@435 45 // ensure only one is ever created.
duke@435 46 assert(sym->is_parsable() || Universe::emptySymbol() == NULL,
duke@435 47 "should be parsable here.");
duke@435 48 return sym;
duke@435 49 }
duke@435 50
duke@435 51 bool symbolKlass::allocate_symbols(int names_count, const char** names,
duke@435 52 int* lengths, symbolOop* sym_oops, TRAPS) {
duke@435 53 if (UseConcMarkSweepGC || UseParallelGC) {
duke@435 54 // Concurrent GC needs to mark all the allocated symbol oops after
duke@435 55 // the remark phase which isn't done below (except the first symbol oop).
duke@435 56 // So return false which will let the symbols be allocated one by one.
duke@435 57 // The parallel collector uses an object start array to find the
duke@435 58 // start of objects on a dirty card. The object start array is not
duke@435 59 // updated for the start of each symbol so is not precise. During
duke@435 60 // object array verification this causes a verification failure.
duke@435 61 // In a product build this causes extra searching for the start of
duke@435 62 // a symbol. As with the concurrent collector a return of false will
duke@435 63 // cause each symbol to be allocated separately and in the case
duke@435 64 // of the parallel collector will cause the object
duke@435 65 // start array to be updated.
duke@435 66 return false;
duke@435 67 }
duke@435 68
duke@435 69 assert(names_count > 0, "can't allocate 0 symbols");
duke@435 70
duke@435 71 int total_size = 0;
duke@435 72 int i, sizes[SymbolTable::symbol_alloc_batch_size];
duke@435 73 for (i=0; i<names_count; i++) {
duke@435 74 int len = lengths[i];
duke@435 75 if (len > symbolOopDesc::max_length()) {
duke@435 76 return false;
duke@435 77 }
duke@435 78 int sz = symbolOopDesc::object_size(len);
duke@435 79 sizes[i] = sz * HeapWordSize;
duke@435 80 total_size += sz;
duke@435 81 }
duke@435 82 symbolKlassHandle h_k(THREAD, as_klassOop());
duke@435 83 HeapWord* base = Universe::heap()->permanent_mem_allocate(total_size);
duke@435 84 if (base == NULL) {
duke@435 85 return false;
duke@435 86 }
duke@435 87
duke@435 88 // CAN'T take any safepoint during the initialization of the symbol oops !
duke@435 89 No_Safepoint_Verifier nosafepoint;
duke@435 90
duke@435 91 klassOop sk = h_k();
duke@435 92 int pos = 0;
duke@435 93 for (i=0; i<names_count; i++) {
duke@435 94 symbolOop s = (symbolOop) (((char*)base) + pos);
duke@435 95 s->set_mark(markOopDesc::prototype());
duke@435 96 s->set_klass(sk);
duke@435 97 s->set_utf8_length(lengths[i]);
duke@435 98 const char* name = names[i];
duke@435 99 for (int j=0; j<lengths[i]; j++) {
duke@435 100 s->byte_at_put(j, name[j]);
duke@435 101 }
duke@435 102
duke@435 103 assert(s->is_parsable(), "should be parsable here.");
duke@435 104
duke@435 105 sym_oops[i] = s;
duke@435 106 pos += sizes[i];
duke@435 107 }
duke@435 108 return true;
duke@435 109 }
duke@435 110
duke@435 111 klassOop symbolKlass::create_klass(TRAPS) {
duke@435 112 symbolKlass o;
duke@435 113 KlassHandle h_this_klass(THREAD, Universe::klassKlassObj());
duke@435 114 KlassHandle k = base_create_klass(h_this_klass, header_size(), o.vtbl_value(), CHECK_NULL);
duke@435 115 // Make sure size calculation is right
duke@435 116 assert(k()->size() == align_object_size(header_size()), "wrong size for object");
duke@435 117 // java_lang_Class::create_mirror(k, CHECK_NULL); // Allocate mirror
duke@435 118 return k();
duke@435 119 }
duke@435 120
duke@435 121 int symbolKlass::oop_size(oop obj) const {
duke@435 122 assert(obj->is_symbol(),"must be a symbol");
duke@435 123 symbolOop s = symbolOop(obj);
duke@435 124 int size = s->object_size();
duke@435 125 return size;
duke@435 126 }
duke@435 127
duke@435 128 bool symbolKlass::oop_is_parsable(oop obj) const {
duke@435 129 assert(obj->is_symbol(),"must be a symbol");
duke@435 130 symbolOop s = symbolOop(obj);
duke@435 131 return s->object_is_parsable();
duke@435 132 }
duke@435 133
duke@435 134 void symbolKlass::oop_follow_contents(oop obj) {
duke@435 135 assert (obj->is_symbol(), "object must be symbol");
duke@435 136 // Performance tweak: We skip iterating over the klass pointer since we
duke@435 137 // know that Universe::symbolKlassObj never moves.
duke@435 138 // Note: do not follow next link here (see SymbolTable::follow_contents)
duke@435 139 }
duke@435 140
duke@435 141 #ifndef SERIALGC
duke@435 142 void symbolKlass::oop_follow_contents(ParCompactionManager* cm, oop obj) {
duke@435 143 assert (obj->is_symbol(), "object must be symbol");
duke@435 144 // Performance tweak: We skip iterating over the klass pointer since we
duke@435 145 // know that Universe::symbolKlassObj never moves.
duke@435 146 // Note: do not follow next link here (see SymbolTable::follow_contents)
duke@435 147 }
duke@435 148 #endif // SERIALGC
duke@435 149
duke@435 150 int symbolKlass::oop_oop_iterate(oop obj, OopClosure* blk) {
duke@435 151 assert(obj->is_symbol(), "object must be symbol");
duke@435 152 symbolOop s = symbolOop(obj);
duke@435 153 // Get size before changing pointers.
duke@435 154 // Don't call size() or oop_size() since that is a virtual call.
duke@435 155 int size = s->object_size();
duke@435 156 // Performance tweak: We skip iterating over the klass pointer since we
duke@435 157 // know that Universe::symbolKlassObj never moves.
duke@435 158 return size;
duke@435 159 }
duke@435 160
duke@435 161
duke@435 162 int symbolKlass::oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr) {
duke@435 163 assert(obj->is_symbol(), "object must be symbol");
duke@435 164 symbolOop s = symbolOop(obj);
duke@435 165 // Get size before changing pointers.
duke@435 166 // Don't call size() or oop_size() since that is a virtual call.
duke@435 167 int size = s->object_size();
duke@435 168 // Performance tweak: We skip iterating over the klass pointer since we
duke@435 169 // know that Universe::symbolKlassObj never moves.
duke@435 170 return size;
duke@435 171 }
duke@435 172
duke@435 173
duke@435 174 int symbolKlass::oop_adjust_pointers(oop obj) {
duke@435 175 assert(obj->is_symbol(), "should be symbol");
duke@435 176 symbolOop s = symbolOop(obj);
duke@435 177 // Get size before changing pointers.
duke@435 178 // Don't call size() or oop_size() since that is a virtual call.
duke@435 179 int size = s->object_size();
duke@435 180 // Performance tweak: We skip iterating over the klass pointer since we
duke@435 181 // know that Universe::symbolKlassObj never moves.
duke@435 182 return size;
duke@435 183 }
duke@435 184
duke@435 185
duke@435 186 #ifndef SERIALGC
duke@435 187 void symbolKlass::oop_copy_contents(PSPromotionManager* pm, oop obj) {
duke@435 188 assert(obj->is_symbol(), "should be symbol");
duke@435 189 }
duke@435 190
duke@435 191 void symbolKlass::oop_push_contents(PSPromotionManager* pm, oop obj) {
duke@435 192 assert(obj->is_symbol(), "should be symbol");
duke@435 193 }
duke@435 194
duke@435 195 int symbolKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) {
duke@435 196 assert(obj->is_symbol(), "should be symbol");
duke@435 197 return symbolOop(obj)->object_size();
duke@435 198 }
duke@435 199
duke@435 200 int symbolKlass::oop_update_pointers(ParCompactionManager* cm, oop obj,
duke@435 201 HeapWord* beg_addr, HeapWord* end_addr) {
duke@435 202 assert(obj->is_symbol(), "should be symbol");
duke@435 203 return symbolOop(obj)->object_size();
duke@435 204 }
duke@435 205 #endif // SERIALGC
duke@435 206
duke@435 207 #ifndef PRODUCT
duke@435 208 // Printing
duke@435 209
duke@435 210 void symbolKlass::oop_print_on(oop obj, outputStream* st) {
duke@435 211 st->print("Symbol: '");
duke@435 212 symbolOop sym = symbolOop(obj);
duke@435 213 for (int i = 0; i < sym->utf8_length(); i++) {
duke@435 214 st->print("%c", sym->byte_at(i));
duke@435 215 }
duke@435 216 st->print("'");
duke@435 217 }
duke@435 218
duke@435 219 void symbolKlass::oop_print_value_on(oop obj, outputStream* st) {
duke@435 220 symbolOop sym = symbolOop(obj);
duke@435 221 st->print("'");
duke@435 222 for (int i = 0; i < sym->utf8_length(); i++) {
duke@435 223 st->print("%c", sym->byte_at(i));
duke@435 224 }
duke@435 225 st->print("'");
duke@435 226 }
duke@435 227
duke@435 228 #endif //PRODUCT
duke@435 229
duke@435 230 const char* symbolKlass::internal_name() const {
duke@435 231 return "{symbol}";
duke@435 232 }

mercurial