src/share/vm/oops/methodKlass.cpp

Fri, 20 Mar 2009 23:19:36 -0700

author
jrose
date
Fri, 20 Mar 2009 23:19:36 -0700
changeset 1100
c89f86385056
parent 435
a61af66fc99e
child 1145
e5b0439ef4ae
permissions
-rw-r--r--

6814659: separable cleanups and subroutines for 6655638
Summary: preparatory but separable changes for method handles
Reviewed-by: kvn, never

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

mercurial