annotate src/share/vm/oops/methodKlass.cpp @ 0:a61af66fc99e

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children c89f86385056
rev   line source
duke@0 1 /*
duke@0 2 * Copyright 1997-2007 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/_methodKlass.cpp.incl"
duke@0 27
duke@0 28 klassOop methodKlass::create_klass(TRAPS) {
duke@0 29 methodKlass o;
duke@0 30 KlassHandle h_this_klass(THREAD, Universe::klassKlassObj());
duke@0 31 KlassHandle k = base_create_klass(h_this_klass, header_size(), o.vtbl_value(), CHECK_NULL);
duke@0 32 // Make sure size calculation is right
duke@0 33 assert(k()->size() == align_object_size(header_size()), "wrong size for object");
duke@0 34 java_lang_Class::create_mirror(k, CHECK_NULL); // Allocate mirror
duke@0 35 return k();
duke@0 36 }
duke@0 37
duke@0 38
duke@0 39 int methodKlass::oop_size(oop obj) const {
duke@0 40 assert(obj->is_method(), "must be method oop");
duke@0 41 return methodOop(obj)->object_size();
duke@0 42 }
duke@0 43
duke@0 44
duke@0 45 bool methodKlass::oop_is_parsable(oop obj) const {
duke@0 46 assert(obj->is_method(), "must be method oop");
duke@0 47 return methodOop(obj)->object_is_parsable();
duke@0 48 }
duke@0 49
duke@0 50
duke@0 51 methodOop methodKlass::allocate(constMethodHandle xconst,
duke@0 52 AccessFlags access_flags, TRAPS) {
duke@0 53 int size = methodOopDesc::object_size(access_flags.is_native());
duke@0 54 KlassHandle h_k(THREAD, as_klassOop());
duke@0 55 assert(xconst()->is_parsable(), "possible publication protocol violation");
duke@0 56 methodOop m = (methodOop)CollectedHeap::permanent_obj_allocate(h_k, size, CHECK_NULL);
duke@0 57 assert(!m->is_parsable(), "not expecting parsability yet.");
duke@0 58
duke@0 59 No_Safepoint_Verifier no_safepoint; // until m becomes parsable below
duke@0 60 m->set_constMethod(xconst());
duke@0 61 m->set_access_flags(access_flags);
duke@0 62 m->set_method_size(size);
duke@0 63 m->set_name_index(0);
duke@0 64 m->set_signature_index(0);
duke@0 65 #ifdef CC_INTERP
duke@0 66 m->set_result_index(T_VOID);
duke@0 67 #endif
duke@0 68 m->set_constants(NULL);
duke@0 69 m->set_max_stack(0);
duke@0 70 m->set_max_locals(0);
duke@0 71 m->clear_intrinsic_id_cache();
duke@0 72 m->set_method_data(NULL);
duke@0 73 m->set_interpreter_throwout_count(0);
duke@0 74 m->set_vtable_index(methodOopDesc::garbage_vtable_index);
duke@0 75
duke@0 76 // Fix and bury in methodOop
duke@0 77 m->set_interpreter_entry(NULL); // sets i2i entry and from_int
duke@0 78 m->set_highest_tier_compile(CompLevel_none);
duke@0 79 m->set_adapter_entry(NULL);
duke@0 80 m->clear_code(); // from_c/from_i get set to c2i/i2i
duke@0 81
duke@0 82 if (access_flags.is_native()) {
duke@0 83 m->clear_native_function();
duke@0 84 m->set_signature_handler(NULL);
duke@0 85 }
duke@0 86
duke@0 87 NOT_PRODUCT(m->set_compiled_invocation_count(0);)
duke@0 88 m->set_interpreter_invocation_count(0);
duke@0 89 m->invocation_counter()->init();
duke@0 90 m->backedge_counter()->init();
duke@0 91 m->clear_number_of_breakpoints();
duke@0 92 assert(m->is_parsable(), "must be parsable here.");
duke@0 93 assert(m->size() == size, "wrong size for object");
duke@0 94 // We should not publish an uprasable object's reference
duke@0 95 // into one that is parsable, since that presents problems
duke@0 96 // for the concurrent parallel marking and precleaning phases
duke@0 97 // of concurrent gc (CMS).
duke@0 98 xconst->set_method(m);
duke@0 99 return m;
duke@0 100 }
duke@0 101
duke@0 102
duke@0 103 void methodKlass::oop_follow_contents(oop obj) {
duke@0 104 assert (obj->is_method(), "object must be method");
duke@0 105 methodOop m = methodOop(obj);
duke@0 106 // Performance tweak: We skip iterating over the klass pointer since we
duke@0 107 // know that Universe::methodKlassObj never moves.
duke@0 108 MarkSweep::mark_and_push(m->adr_constMethod());
duke@0 109 MarkSweep::mark_and_push(m->adr_constants());
duke@0 110 if (m->method_data() != NULL) {
duke@0 111 MarkSweep::mark_and_push(m->adr_method_data());
duke@0 112 }
duke@0 113 }
duke@0 114
duke@0 115 #ifndef SERIALGC
duke@0 116 void methodKlass::oop_follow_contents(ParCompactionManager* cm,
duke@0 117 oop obj) {
duke@0 118 assert (obj->is_method(), "object must be method");
duke@0 119 methodOop m = methodOop(obj);
duke@0 120 // Performance tweak: We skip iterating over the klass pointer since we
duke@0 121 // know that Universe::methodKlassObj never moves.
duke@0 122 PSParallelCompact::mark_and_push(cm, m->adr_constMethod());
duke@0 123 PSParallelCompact::mark_and_push(cm, m->adr_constants());
duke@0 124 #ifdef COMPILER2
duke@0 125 if (m->method_data() != NULL) {
duke@0 126 PSParallelCompact::mark_and_push(cm, m->adr_method_data());
duke@0 127 }
duke@0 128 #endif // COMPILER2
duke@0 129 }
duke@0 130 #endif // SERIALGC
duke@0 131
duke@0 132 int methodKlass::oop_oop_iterate(oop obj, OopClosure* blk) {
duke@0 133 assert (obj->is_method(), "object must be method");
duke@0 134 methodOop m = methodOop(obj);
duke@0 135 // Get size before changing pointers.
duke@0 136 // Don't call size() or oop_size() since that is a virtual call.
duke@0 137 int size = m->object_size();
duke@0 138 // Performance tweak: We skip iterating over the klass pointer since we
duke@0 139 // know that Universe::methodKlassObj never moves
duke@0 140 blk->do_oop(m->adr_constMethod());
duke@0 141 blk->do_oop(m->adr_constants());
duke@0 142 if (m->method_data() != NULL) {
duke@0 143 blk->do_oop(m->adr_method_data());
duke@0 144 }
duke@0 145 return size;
duke@0 146 }
duke@0 147
duke@0 148
duke@0 149 int methodKlass::oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr) {
duke@0 150 assert (obj->is_method(), "object must be method");
duke@0 151 methodOop m = methodOop(obj);
duke@0 152 // Get size before changing pointers.
duke@0 153 // Don't call size() or oop_size() since that is a virtual call.
duke@0 154 int size = m->object_size();
duke@0 155 // Performance tweak: We skip iterating over the klass pointer since we
duke@0 156 // know that Universe::methodKlassObj never moves.
duke@0 157 oop* adr;
duke@0 158 adr = m->adr_constMethod();
duke@0 159 if (mr.contains(adr)) blk->do_oop(adr);
duke@0 160 adr = m->adr_constants();
duke@0 161 if (mr.contains(adr)) blk->do_oop(adr);
duke@0 162 if (m->method_data() != NULL) {
duke@0 163 adr = m->adr_method_data();
duke@0 164 if (mr.contains(adr)) blk->do_oop(adr);
duke@0 165 }
duke@0 166 return size;
duke@0 167 }
duke@0 168
duke@0 169
duke@0 170 int methodKlass::oop_adjust_pointers(oop obj) {
duke@0 171 assert(obj->is_method(), "should be method");
duke@0 172 methodOop m = methodOop(obj);
duke@0 173 // Get size before changing pointers.
duke@0 174 // Don't call size() or oop_size() since that is a virtual call.
duke@0 175 int size = m->object_size();
duke@0 176 // Performance tweak: We skip iterating over the klass pointer since we
duke@0 177 // know that Universe::methodKlassObj never moves.
duke@0 178 MarkSweep::adjust_pointer(m->adr_constMethod());
duke@0 179 MarkSweep::adjust_pointer(m->adr_constants());
duke@0 180 if (m->method_data() != NULL) {
duke@0 181 MarkSweep::adjust_pointer(m->adr_method_data());
duke@0 182 }
duke@0 183 return size;
duke@0 184 }
duke@0 185
duke@0 186 #ifndef SERIALGC
duke@0 187 void methodKlass::oop_copy_contents(PSPromotionManager* pm, oop obj) {
duke@0 188 assert(obj->is_method(), "should be method");
duke@0 189 }
duke@0 190
duke@0 191 void methodKlass::oop_push_contents(PSPromotionManager* pm, oop obj) {
duke@0 192 assert(obj->is_method(), "should be method");
duke@0 193 }
duke@0 194
duke@0 195 int methodKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) {
duke@0 196 assert(obj->is_method(), "should be method");
duke@0 197 methodOop m = methodOop(obj);
duke@0 198 PSParallelCompact::adjust_pointer(m->adr_constMethod());
duke@0 199 PSParallelCompact::adjust_pointer(m->adr_constants());
duke@0 200 #ifdef COMPILER2
duke@0 201 if (m->method_data() != NULL) {
duke@0 202 PSParallelCompact::adjust_pointer(m->adr_method_data());
duke@0 203 }
duke@0 204 #endif // COMPILER2
duke@0 205 return m->object_size();
duke@0 206 }
duke@0 207
duke@0 208 int methodKlass::oop_update_pointers(ParCompactionManager* cm, oop obj,
duke@0 209 HeapWord* beg_addr, HeapWord* end_addr) {
duke@0 210 assert(obj->is_method(), "should be method");
duke@0 211
duke@0 212 oop* p;
duke@0 213 methodOop m = methodOop(obj);
duke@0 214
duke@0 215 p = m->adr_constMethod();
duke@0 216 PSParallelCompact::adjust_pointer(p, beg_addr, end_addr);
duke@0 217 p = m->adr_constants();
duke@0 218 PSParallelCompact::adjust_pointer(p, beg_addr, end_addr);
duke@0 219
duke@0 220 #ifdef COMPILER2
duke@0 221 if (m->method_data() != NULL) {
duke@0 222 p = m->adr_method_data();
duke@0 223 PSParallelCompact::adjust_pointer(p, beg_addr, end_addr);
duke@0 224 }
duke@0 225 #endif // COMPILER2
duke@0 226 return m->object_size();
duke@0 227 }
duke@0 228 #endif // SERIALGC
duke@0 229
duke@0 230 #ifndef PRODUCT
duke@0 231
duke@0 232 // Printing
duke@0 233
duke@0 234 void methodKlass::oop_print_on(oop obj, outputStream* st) {
duke@0 235 ResourceMark rm;
duke@0 236 assert(obj->is_method(), "must be method");
duke@0 237 Klass::oop_print_on(obj, st);
duke@0 238 methodOop m = methodOop(obj);
duke@0 239 st->print (" - method holder: "); m->method_holder()->print_value_on(st); st->cr();
duke@0 240 st->print (" - constants: " INTPTR_FORMAT, " ", (address)m->constants());
duke@0 241 m->constants()->print_value_on(st); st->cr();
duke@0 242 st->print (" - access: 0x%x ", m->access_flags().as_int()); m->access_flags().print_on(st); st->cr();
duke@0 243 st->print (" - name: "); m->name()->print_value_on(st); st->cr();
duke@0 244 st->print (" - signature: "); m->signature()->print_value_on(st); st->cr();
duke@0 245 st->print_cr(" - max stack: %d", m->max_stack());
duke@0 246 st->print_cr(" - max locals: %d", m->max_locals());
duke@0 247 st->print_cr(" - size of params: %d", m->size_of_parameters());
duke@0 248 st->print_cr(" - method size: %d", m->method_size());
duke@0 249 st->print_cr(" - vtable index: %d", m->_vtable_index);
duke@0 250 st->print_cr(" - code size: %d", m->code_size());
duke@0 251 st->print_cr(" - code start: " INTPTR_FORMAT, m->code_base());
duke@0 252 st->print_cr(" - code end (excl): " INTPTR_FORMAT, m->code_base() + m->code_size());
duke@0 253 if (m->method_data() != NULL) {
duke@0 254 st->print_cr(" - method data: " INTPTR_FORMAT, (address)m->method_data());
duke@0 255 }
duke@0 256 st->print_cr(" - checked ex length: %d", m->checked_exceptions_length());
duke@0 257 if (m->checked_exceptions_length() > 0) {
duke@0 258 CheckedExceptionElement* table = m->checked_exceptions_start();
duke@0 259 st->print_cr(" - checked ex start: " INTPTR_FORMAT, table);
duke@0 260 if (Verbose) {
duke@0 261 for (int i = 0; i < m->checked_exceptions_length(); i++) {
duke@0 262 st->print_cr(" - throws %s", m->constants()->printable_name_at(table[i].class_cp_index));
duke@0 263 }
duke@0 264 }
duke@0 265 }
duke@0 266 if (m->has_linenumber_table()) {
duke@0 267 u_char* table = m->compressed_linenumber_table();
duke@0 268 st->print_cr(" - linenumber start: " INTPTR_FORMAT, table);
duke@0 269 if (Verbose) {
duke@0 270 CompressedLineNumberReadStream stream(table);
duke@0 271 while (stream.read_pair()) {
duke@0 272 st->print_cr(" - line %d: %d", stream.line(), stream.bci());
duke@0 273 }
duke@0 274 }
duke@0 275 }
duke@0 276 st->print_cr(" - localvar length: %d", m->localvariable_table_length());
duke@0 277 if (m->localvariable_table_length() > 0) {
duke@0 278 LocalVariableTableElement* table = m->localvariable_table_start();
duke@0 279 st->print_cr(" - localvar start: " INTPTR_FORMAT, table);
duke@0 280 if (Verbose) {
duke@0 281 for (int i = 0; i < m->localvariable_table_length(); i++) {
duke@0 282 int bci = table[i].start_bci;
duke@0 283 int len = table[i].length;
duke@0 284 const char* name = m->constants()->printable_name_at(table[i].name_cp_index);
duke@0 285 const char* desc = m->constants()->printable_name_at(table[i].descriptor_cp_index);
duke@0 286 int slot = table[i].slot;
duke@0 287 st->print_cr(" - %s %s bci=%d len=%d slot=%d", desc, name, bci, len, slot);
duke@0 288 }
duke@0 289 }
duke@0 290 }
duke@0 291 if (m->code() != NULL) {
duke@0 292 st->print (" - compiled code: ");
duke@0 293 m->code()->print_value_on(st);
duke@0 294 st->cr();
duke@0 295 }
duke@0 296 }
duke@0 297
duke@0 298
duke@0 299 void methodKlass::oop_print_value_on(oop obj, outputStream* st) {
duke@0 300 assert(obj->is_method(), "must be method");
duke@0 301 Klass::oop_print_value_on(obj, st);
duke@0 302 methodOop m = methodOop(obj);
duke@0 303 st->print(" ");
duke@0 304 m->name()->print_value_on(st);
duke@0 305 st->print(" ");
duke@0 306 m->signature()->print_value_on(st);
duke@0 307 st->print(" in ");
duke@0 308 m->method_holder()->print_value_on(st);
duke@0 309 if (WizardMode) st->print("[%d,%d]", m->size_of_parameters(), m->max_locals());
duke@0 310 if (WizardMode && m->code() != NULL) st->print(" ((nmethod*)%p)", m->code());
duke@0 311 }
duke@0 312
duke@0 313 #endif // PRODUCT
duke@0 314
duke@0 315 const char* methodKlass::internal_name() const {
duke@0 316 return "{method}";
duke@0 317 }
duke@0 318
duke@0 319
duke@0 320 // Verification
duke@0 321
duke@0 322 void methodKlass::oop_verify_on(oop obj, outputStream* st) {
duke@0 323 Klass::oop_verify_on(obj, st);
duke@0 324 guarantee(obj->is_method(), "object must be method");
duke@0 325 if (!obj->partially_loaded()) {
duke@0 326 methodOop m = methodOop(obj);
duke@0 327 guarantee(m->is_perm(), "should be in permspace");
duke@0 328 guarantee(m->name()->is_perm(), "should be in permspace");
duke@0 329 guarantee(m->name()->is_symbol(), "should be symbol");
duke@0 330 guarantee(m->signature()->is_perm(), "should be in permspace");
duke@0 331 guarantee(m->signature()->is_symbol(), "should be symbol");
duke@0 332 guarantee(m->constants()->is_perm(), "should be in permspace");
duke@0 333 guarantee(m->constants()->is_constantPool(), "should be constant pool");
duke@0 334 guarantee(m->constMethod()->is_constMethod(), "should be constMethodOop");
duke@0 335 guarantee(m->constMethod()->is_perm(), "should be in permspace");
duke@0 336 methodDataOop method_data = m->method_data();
duke@0 337 guarantee(method_data == NULL ||
duke@0 338 method_data->is_perm(), "should be in permspace");
duke@0 339 guarantee(method_data == NULL ||
duke@0 340 method_data->is_methodData(), "should be method data");
duke@0 341 }
duke@0 342 }
duke@0 343
duke@0 344 bool methodKlass::oop_partially_loaded(oop obj) const {
duke@0 345 assert(obj->is_method(), "object must be method");
duke@0 346 methodOop m = methodOop(obj);
duke@0 347 constMethodOop xconst = m->constMethod();
duke@0 348 assert(xconst != NULL, "const method must be set");
duke@0 349 constMethodKlass* ck = constMethodKlass::cast(xconst->klass());
duke@0 350 return ck->oop_partially_loaded(xconst);
duke@0 351 }
duke@0 352
duke@0 353
duke@0 354 void methodKlass::oop_set_partially_loaded(oop obj) {
duke@0 355 assert(obj->is_method(), "object must be method");
duke@0 356 methodOop m = methodOop(obj);
duke@0 357 constMethodOop xconst = m->constMethod();
duke@0 358 assert(xconst != NULL, "const method must be set");
duke@0 359 constMethodKlass* ck = constMethodKlass::cast(xconst->klass());
duke@0 360 ck->oop_set_partially_loaded(xconst);
duke@0 361 }