annotate src/share/vm/oops/symbolKlass.cpp @ 45:48a3fa21394b

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