src/share/vm/oops/methodKlass.cpp

Fri, 03 Sep 2010 17:51:07 -0700

author
iveresov
date
Fri, 03 Sep 2010 17:51:07 -0700
changeset 2138
d5d065957597
parent 2061
9d7a8ab3736b
child 2314
f95d63e2154a
permissions
-rw-r--r--

6953144: Tiered compilation
Summary: Infrastructure for tiered compilation support (interpreter + c1 + c2) for 32 and 64 bit. Simple tiered policy implementation.
Reviewed-by: kvn, never, phh, twisti

duke@435 1 /*
iveresov@2138 2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. 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 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * 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);
jrose@1291 71 m->set_intrinsic_id(vmIntrinsics::_none);
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_adapter_entry(NULL);
duke@435 79 m->clear_code(); // from_c/from_i get set to c2i/i2i
duke@435 80
duke@435 81 if (access_flags.is_native()) {
duke@435 82 m->clear_native_function();
duke@435 83 m->set_signature_handler(NULL);
duke@435 84 }
duke@435 85
duke@435 86 NOT_PRODUCT(m->set_compiled_invocation_count(0);)
duke@435 87 m->set_interpreter_invocation_count(0);
duke@435 88 m->invocation_counter()->init();
duke@435 89 m->backedge_counter()->init();
duke@435 90 m->clear_number_of_breakpoints();
iveresov@2138 91
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_push_contents(PSPromotionManager* pm, oop obj) {
duke@435 188 assert(obj->is_method(), "should be method");
duke@435 189 }
duke@435 190
duke@435 191 int methodKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) {
duke@435 192 assert(obj->is_method(), "should be method");
duke@435 193 methodOop m = methodOop(obj);
duke@435 194 PSParallelCompact::adjust_pointer(m->adr_constMethod());
duke@435 195 PSParallelCompact::adjust_pointer(m->adr_constants());
duke@435 196 #ifdef COMPILER2
duke@435 197 if (m->method_data() != NULL) {
duke@435 198 PSParallelCompact::adjust_pointer(m->adr_method_data());
duke@435 199 }
duke@435 200 #endif // COMPILER2
duke@435 201 return m->object_size();
duke@435 202 }
duke@435 203
duke@435 204 int methodKlass::oop_update_pointers(ParCompactionManager* cm, oop obj,
duke@435 205 HeapWord* beg_addr, HeapWord* end_addr) {
duke@435 206 assert(obj->is_method(), "should be method");
duke@435 207
duke@435 208 oop* p;
duke@435 209 methodOop m = methodOop(obj);
duke@435 210
duke@435 211 p = m->adr_constMethod();
duke@435 212 PSParallelCompact::adjust_pointer(p, beg_addr, end_addr);
duke@435 213 p = m->adr_constants();
duke@435 214 PSParallelCompact::adjust_pointer(p, beg_addr, end_addr);
duke@435 215
duke@435 216 #ifdef COMPILER2
duke@435 217 if (m->method_data() != NULL) {
duke@435 218 p = m->adr_method_data();
duke@435 219 PSParallelCompact::adjust_pointer(p, beg_addr, end_addr);
duke@435 220 }
duke@435 221 #endif // COMPILER2
duke@435 222 return m->object_size();
duke@435 223 }
duke@435 224 #endif // SERIALGC
duke@435 225
duke@435 226 #ifndef PRODUCT
duke@435 227
duke@435 228 // Printing
duke@435 229
duke@435 230 void methodKlass::oop_print_on(oop obj, outputStream* st) {
duke@435 231 ResourceMark rm;
duke@435 232 assert(obj->is_method(), "must be method");
duke@435 233 Klass::oop_print_on(obj, st);
duke@435 234 methodOop m = methodOop(obj);
jrose@1862 235 // get the effect of PrintOopAddress, always, for methods:
jrose@1928 236 st->print_cr(" - this oop: "INTPTR_FORMAT, (intptr_t)m);
duke@435 237 st->print (" - method holder: "); m->method_holder()->print_value_on(st); st->cr();
jrose@1862 238 st->print (" - constants: "INTPTR_FORMAT" ", (address)m->constants());
duke@435 239 m->constants()->print_value_on(st); st->cr();
duke@435 240 st->print (" - access: 0x%x ", m->access_flags().as_int()); m->access_flags().print_on(st); st->cr();
duke@435 241 st->print (" - name: "); m->name()->print_value_on(st); st->cr();
duke@435 242 st->print (" - signature: "); m->signature()->print_value_on(st); st->cr();
duke@435 243 st->print_cr(" - max stack: %d", m->max_stack());
duke@435 244 st->print_cr(" - max locals: %d", m->max_locals());
duke@435 245 st->print_cr(" - size of params: %d", m->size_of_parameters());
duke@435 246 st->print_cr(" - method size: %d", m->method_size());
jrose@1862 247 if (m->intrinsic_id() != vmIntrinsics::_none)
jrose@1862 248 st->print_cr(" - intrinsic id: %d %s", m->intrinsic_id(), vmIntrinsics::name_at(m->intrinsic_id()));
iveresov@2138 249 if (m->highest_comp_level() != CompLevel_none)
iveresov@2138 250 st->print_cr(" - highest level: %d", m->highest_comp_level());
duke@435 251 st->print_cr(" - vtable index: %d", m->_vtable_index);
jrose@1100 252 st->print_cr(" - i2i entry: " INTPTR_FORMAT, m->interpreter_entry());
jrose@1100 253 st->print_cr(" - adapter: " INTPTR_FORMAT, m->adapter());
jrose@1100 254 st->print_cr(" - compiled entry " INTPTR_FORMAT, m->from_compiled_entry());
duke@435 255 st->print_cr(" - code size: %d", m->code_size());
jrose@1100 256 if (m->code_size() != 0) {
jrose@1100 257 st->print_cr(" - code start: " INTPTR_FORMAT, m->code_base());
jrose@1100 258 st->print_cr(" - code end (excl): " INTPTR_FORMAT, m->code_base() + m->code_size());
jrose@1100 259 }
duke@435 260 if (m->method_data() != NULL) {
duke@435 261 st->print_cr(" - method data: " INTPTR_FORMAT, (address)m->method_data());
duke@435 262 }
duke@435 263 st->print_cr(" - checked ex length: %d", m->checked_exceptions_length());
duke@435 264 if (m->checked_exceptions_length() > 0) {
duke@435 265 CheckedExceptionElement* table = m->checked_exceptions_start();
duke@435 266 st->print_cr(" - checked ex start: " INTPTR_FORMAT, table);
duke@435 267 if (Verbose) {
duke@435 268 for (int i = 0; i < m->checked_exceptions_length(); i++) {
duke@435 269 st->print_cr(" - throws %s", m->constants()->printable_name_at(table[i].class_cp_index));
duke@435 270 }
duke@435 271 }
duke@435 272 }
duke@435 273 if (m->has_linenumber_table()) {
duke@435 274 u_char* table = m->compressed_linenumber_table();
duke@435 275 st->print_cr(" - linenumber start: " INTPTR_FORMAT, table);
duke@435 276 if (Verbose) {
duke@435 277 CompressedLineNumberReadStream stream(table);
duke@435 278 while (stream.read_pair()) {
duke@435 279 st->print_cr(" - line %d: %d", stream.line(), stream.bci());
duke@435 280 }
duke@435 281 }
duke@435 282 }
duke@435 283 st->print_cr(" - localvar length: %d", m->localvariable_table_length());
duke@435 284 if (m->localvariable_table_length() > 0) {
duke@435 285 LocalVariableTableElement* table = m->localvariable_table_start();
duke@435 286 st->print_cr(" - localvar start: " INTPTR_FORMAT, table);
duke@435 287 if (Verbose) {
duke@435 288 for (int i = 0; i < m->localvariable_table_length(); i++) {
duke@435 289 int bci = table[i].start_bci;
duke@435 290 int len = table[i].length;
duke@435 291 const char* name = m->constants()->printable_name_at(table[i].name_cp_index);
duke@435 292 const char* desc = m->constants()->printable_name_at(table[i].descriptor_cp_index);
duke@435 293 int slot = table[i].slot;
duke@435 294 st->print_cr(" - %s %s bci=%d len=%d slot=%d", desc, name, bci, len, slot);
duke@435 295 }
duke@435 296 }
duke@435 297 }
duke@435 298 if (m->code() != NULL) {
duke@435 299 st->print (" - compiled code: ");
duke@435 300 m->code()->print_value_on(st);
duke@435 301 st->cr();
duke@435 302 }
jrose@1145 303 if (m->is_method_handle_invoke()) {
jrose@1145 304 st->print_cr(" - invoke method type: " INTPTR_FORMAT, (address) m->method_handle_type());
jrose@1145 305 // m is classified as native, but it does not have an interesting
jrose@1145 306 // native_function or signature handler
jrose@1145 307 } else if (m->is_native()) {
jrose@1100 308 st->print_cr(" - native function: " INTPTR_FORMAT, m->native_function());
jrose@1100 309 st->print_cr(" - signature handler: " INTPTR_FORMAT, m->signature_handler());
jrose@1100 310 }
duke@435 311 }
duke@435 312
jrose@1590 313 #endif //PRODUCT
duke@435 314
duke@435 315 void methodKlass::oop_print_value_on(oop obj, outputStream* st) {
duke@435 316 assert(obj->is_method(), "must be method");
duke@435 317 Klass::oop_print_value_on(obj, st);
duke@435 318 methodOop m = methodOop(obj);
duke@435 319 st->print(" ");
duke@435 320 m->name()->print_value_on(st);
duke@435 321 st->print(" ");
duke@435 322 m->signature()->print_value_on(st);
duke@435 323 st->print(" in ");
duke@435 324 m->method_holder()->print_value_on(st);
duke@435 325 if (WizardMode) st->print("[%d,%d]", m->size_of_parameters(), m->max_locals());
duke@435 326 if (WizardMode && m->code() != NULL) st->print(" ((nmethod*)%p)", m->code());
duke@435 327 }
duke@435 328
duke@435 329 const char* methodKlass::internal_name() const {
duke@435 330 return "{method}";
duke@435 331 }
duke@435 332
duke@435 333
duke@435 334 // Verification
duke@435 335
duke@435 336 void methodKlass::oop_verify_on(oop obj, outputStream* st) {
duke@435 337 Klass::oop_verify_on(obj, st);
duke@435 338 guarantee(obj->is_method(), "object must be method");
duke@435 339 if (!obj->partially_loaded()) {
duke@435 340 methodOop m = methodOop(obj);
duke@435 341 guarantee(m->is_perm(), "should be in permspace");
duke@435 342 guarantee(m->name()->is_perm(), "should be in permspace");
duke@435 343 guarantee(m->name()->is_symbol(), "should be symbol");
duke@435 344 guarantee(m->signature()->is_perm(), "should be in permspace");
duke@435 345 guarantee(m->signature()->is_symbol(), "should be symbol");
duke@435 346 guarantee(m->constants()->is_perm(), "should be in permspace");
duke@435 347 guarantee(m->constants()->is_constantPool(), "should be constant pool");
duke@435 348 guarantee(m->constMethod()->is_constMethod(), "should be constMethodOop");
duke@435 349 guarantee(m->constMethod()->is_perm(), "should be in permspace");
duke@435 350 methodDataOop method_data = m->method_data();
duke@435 351 guarantee(method_data == NULL ||
duke@435 352 method_data->is_perm(), "should be in permspace");
duke@435 353 guarantee(method_data == NULL ||
duke@435 354 method_data->is_methodData(), "should be method data");
duke@435 355 }
duke@435 356 }
duke@435 357
duke@435 358 bool methodKlass::oop_partially_loaded(oop obj) const {
duke@435 359 assert(obj->is_method(), "object must be method");
duke@435 360 methodOop m = methodOop(obj);
duke@435 361 constMethodOop xconst = m->constMethod();
duke@435 362 assert(xconst != NULL, "const method must be set");
duke@435 363 constMethodKlass* ck = constMethodKlass::cast(xconst->klass());
duke@435 364 return ck->oop_partially_loaded(xconst);
duke@435 365 }
duke@435 366
duke@435 367
duke@435 368 void methodKlass::oop_set_partially_loaded(oop obj) {
duke@435 369 assert(obj->is_method(), "object must be method");
duke@435 370 methodOop m = methodOop(obj);
duke@435 371 constMethodOop xconst = m->constMethod();
duke@435 372 assert(xconst != NULL, "const method must be set");
duke@435 373 constMethodKlass* ck = constMethodKlass::cast(xconst->klass());
duke@435 374 ck->oop_set_partially_loaded(xconst);
duke@435 375 }

mercurial