annotate src/share/vm/oops/methodOop.cpp @ 3413:e2fe93124108

7174928: JSR 292: unresolved invokedynamic call sites deopt and osr infinitely Reviewed-by: kvn
author twisti
date Wed, 13 Jun 2012 11:36:03 -0700
parents 0382d2b469b2
children eba1d5bce9e8
rev   line source
duke@0 1 /*
never@3065 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. 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 *
trims@1472 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1472 20 * or visit www.oracle.com if you need additional information or have any
trims@1472 21 * questions.
duke@0 22 *
duke@0 23 */
duke@0 24
stefank@1879 25 #include "precompiled.hpp"
stefank@1879 26 #include "classfile/systemDictionary.hpp"
stefank@1879 27 #include "code/debugInfoRec.hpp"
stefank@1879 28 #include "gc_interface/collectedHeap.inline.hpp"
stefank@1879 29 #include "interpreter/bytecodeStream.hpp"
stefank@1879 30 #include "interpreter/bytecodeTracer.hpp"
stefank@1879 31 #include "interpreter/bytecodes.hpp"
stefank@1879 32 #include "interpreter/interpreter.hpp"
stefank@1879 33 #include "interpreter/oopMapCache.hpp"
stefank@1879 34 #include "memory/gcLocker.hpp"
stefank@1879 35 #include "memory/generation.hpp"
stefank@1879 36 #include "memory/oopFactory.hpp"
stefank@1879 37 #include "oops/klassOop.hpp"
stefank@1879 38 #include "oops/methodDataOop.hpp"
stefank@1879 39 #include "oops/methodOop.hpp"
stefank@1879 40 #include "oops/oop.inline.hpp"
coleenp@2062 41 #include "oops/symbol.hpp"
stefank@1879 42 #include "prims/jvmtiExport.hpp"
stefank@1879 43 #include "prims/methodHandleWalk.hpp"
stefank@1879 44 #include "prims/nativeLookup.hpp"
stefank@1879 45 #include "runtime/arguments.hpp"
stefank@1879 46 #include "runtime/compilationPolicy.hpp"
stefank@1879 47 #include "runtime/frame.inline.hpp"
stefank@1879 48 #include "runtime/handles.inline.hpp"
stefank@1879 49 #include "runtime/relocator.hpp"
stefank@1879 50 #include "runtime/sharedRuntime.hpp"
stefank@1879 51 #include "runtime/signature.hpp"
brutisso@2541 52 #include "utilities/quickSort.hpp"
stefank@1879 53 #include "utilities/xmlstream.hpp"
duke@0 54
duke@0 55
duke@0 56 // Implementation of methodOopDesc
duke@0 57
duke@0 58 address methodOopDesc::get_i2c_entry() {
duke@0 59 assert(_adapter != NULL, "must have");
duke@0 60 return _adapter->get_i2c_entry();
duke@0 61 }
duke@0 62
duke@0 63 address methodOopDesc::get_c2i_entry() {
duke@0 64 assert(_adapter != NULL, "must have");
duke@0 65 return _adapter->get_c2i_entry();
duke@0 66 }
duke@0 67
duke@0 68 address methodOopDesc::get_c2i_unverified_entry() {
duke@0 69 assert(_adapter != NULL, "must have");
duke@0 70 return _adapter->get_c2i_unverified_entry();
duke@0 71 }
duke@0 72
twisti@3413 73 char* methodOopDesc::name_and_sig_as_C_string() const {
duke@0 74 return name_and_sig_as_C_string(Klass::cast(constants()->pool_holder()), name(), signature());
duke@0 75 }
duke@0 76
twisti@3413 77 char* methodOopDesc::name_and_sig_as_C_string(char* buf, int size) const {
duke@0 78 return name_and_sig_as_C_string(Klass::cast(constants()->pool_holder()), name(), signature(), buf, size);
duke@0 79 }
duke@0 80
coleenp@2062 81 char* methodOopDesc::name_and_sig_as_C_string(Klass* klass, Symbol* method_name, Symbol* signature) {
duke@0 82 const char* klass_name = klass->external_name();
duke@0 83 int klass_name_len = (int)strlen(klass_name);
duke@0 84 int method_name_len = method_name->utf8_length();
duke@0 85 int len = klass_name_len + 1 + method_name_len + signature->utf8_length();
duke@0 86 char* dest = NEW_RESOURCE_ARRAY(char, len + 1);
duke@0 87 strcpy(dest, klass_name);
duke@0 88 dest[klass_name_len] = '.';
duke@0 89 strcpy(&dest[klass_name_len + 1], method_name->as_C_string());
duke@0 90 strcpy(&dest[klass_name_len + 1 + method_name_len], signature->as_C_string());
duke@0 91 dest[len] = 0;
duke@0 92 return dest;
duke@0 93 }
duke@0 94
coleenp@2062 95 char* methodOopDesc::name_and_sig_as_C_string(Klass* klass, Symbol* method_name, Symbol* signature, char* buf, int size) {
coleenp@2062 96 Symbol* klass_name = klass->name();
duke@0 97 klass_name->as_klass_external_name(buf, size);
duke@0 98 int len = (int)strlen(buf);
duke@0 99
duke@0 100 if (len < size - 1) {
duke@0 101 buf[len++] = '.';
duke@0 102
duke@0 103 method_name->as_C_string(&(buf[len]), size - len);
duke@0 104 len = (int)strlen(buf);
duke@0 105
duke@0 106 signature->as_C_string(&(buf[len]), size - len);
duke@0 107 }
duke@0 108
duke@0 109 return buf;
duke@0 110 }
duke@0 111
duke@0 112 int methodOopDesc::fast_exception_handler_bci_for(KlassHandle ex_klass, int throw_bci, TRAPS) {
duke@0 113 // exception table holds quadruple entries of the form (beg_bci, end_bci, handler_bci, klass_index)
duke@0 114 const int beg_bci_offset = 0;
duke@0 115 const int end_bci_offset = 1;
duke@0 116 const int handler_bci_offset = 2;
duke@0 117 const int klass_index_offset = 3;
duke@0 118 const int entry_size = 4;
duke@0 119 // access exception table
duke@0 120 typeArrayHandle table (THREAD, constMethod()->exception_table());
duke@0 121 int length = table->length();
duke@0 122 assert(length % entry_size == 0, "exception table format has changed");
duke@0 123 // iterate through all entries sequentially
duke@0 124 constantPoolHandle pool(THREAD, constants());
duke@0 125 for (int i = 0; i < length; i += entry_size) {
duke@0 126 int beg_bci = table->int_at(i + beg_bci_offset);
duke@0 127 int end_bci = table->int_at(i + end_bci_offset);
duke@0 128 assert(beg_bci <= end_bci, "inconsistent exception table");
duke@0 129 if (beg_bci <= throw_bci && throw_bci < end_bci) {
duke@0 130 // exception handler bci range covers throw_bci => investigate further
duke@0 131 int handler_bci = table->int_at(i + handler_bci_offset);
duke@0 132 int klass_index = table->int_at(i + klass_index_offset);
duke@0 133 if (klass_index == 0) {
duke@0 134 return handler_bci;
duke@0 135 } else if (ex_klass.is_null()) {
duke@0 136 return handler_bci;
duke@0 137 } else {
duke@0 138 // we know the exception class => get the constraint class
duke@0 139 // this may require loading of the constraint class; if verification
duke@0 140 // fails or some other exception occurs, return handler_bci
duke@0 141 klassOop k = pool->klass_at(klass_index, CHECK_(handler_bci));
duke@0 142 KlassHandle klass = KlassHandle(THREAD, k);
duke@0 143 assert(klass.not_null(), "klass not loaded");
duke@0 144 if (ex_klass->is_subtype_of(klass())) {
duke@0 145 return handler_bci;
duke@0 146 }
duke@0 147 }
duke@0 148 }
duke@0 149 }
duke@0 150
duke@0 151 return -1;
duke@0 152 }
duke@0 153
duke@0 154 void methodOopDesc::mask_for(int bci, InterpreterOopMap* mask) {
duke@0 155
duke@0 156 Thread* myThread = Thread::current();
duke@0 157 methodHandle h_this(myThread, this);
duke@0 158 #ifdef ASSERT
duke@0 159 bool has_capability = myThread->is_VM_thread() ||
duke@0 160 myThread->is_ConcurrentGC_thread() ||
duke@0 161 myThread->is_GC_task_thread();
duke@0 162
duke@0 163 if (!has_capability) {
duke@0 164 if (!VerifyStack && !VerifyLastFrame) {
duke@0 165 // verify stack calls this outside VM thread
duke@0 166 warning("oopmap should only be accessed by the "
duke@0 167 "VM, GC task or CMS threads (or during debugging)");
duke@0 168 InterpreterOopMap local_mask;
duke@0 169 instanceKlass::cast(method_holder())->mask_for(h_this, bci, &local_mask);
duke@0 170 local_mask.print();
duke@0 171 }
duke@0 172 }
duke@0 173 #endif
duke@0 174 instanceKlass::cast(method_holder())->mask_for(h_this, bci, mask);
duke@0 175 return;
duke@0 176 }
duke@0 177
duke@0 178
duke@0 179 int methodOopDesc::bci_from(address bcp) const {
twisti@3413 180 assert(is_native() && bcp == code_base() || contains(bcp) || is_error_reported(),
twisti@3413 181 err_msg("bcp doesn't belong to this method: bcp: " INTPTR_FORMAT ", method: %s", bcp, name_and_sig_as_C_string()));
duke@0 182 return bcp - code_base();
duke@0 183 }
duke@0 184
duke@0 185
duke@0 186 // Return (int)bcx if it appears to be a valid BCI.
duke@0 187 // Return bci_from((address)bcx) if it appears to be a valid BCP.
duke@0 188 // Return -1 otherwise.
duke@0 189 // Used by profiling code, when invalid data is a possibility.
duke@0 190 // The caller is responsible for validating the methodOop itself.
duke@0 191 int methodOopDesc::validate_bci_from_bcx(intptr_t bcx) const {
duke@0 192 // keep bci as -1 if not a valid bci
duke@0 193 int bci = -1;
duke@0 194 if (bcx == 0 || (address)bcx == code_base()) {
duke@0 195 // code_size() may return 0 and we allow 0 here
duke@0 196 // the method may be native
duke@0 197 bci = 0;
duke@0 198 } else if (frame::is_bci(bcx)) {
duke@0 199 if (bcx < code_size()) {
duke@0 200 bci = (int)bcx;
duke@0 201 }
duke@0 202 } else if (contains((address)bcx)) {
duke@0 203 bci = (address)bcx - code_base();
duke@0 204 }
duke@0 205 // Assert that if we have dodged any asserts, bci is negative.
duke@0 206 assert(bci == -1 || bci == bci_from(bcp_from(bci)), "sane bci if >=0");
duke@0 207 return bci;
duke@0 208 }
duke@0 209
duke@0 210 address methodOopDesc::bcp_from(int bci) const {
duke@0 211 assert((is_native() && bci == 0) || (!is_native() && 0 <= bci && bci < code_size()), "illegal bci");
duke@0 212 address bcp = code_base() + bci;
duke@0 213 assert(is_native() && bcp == code_base() || contains(bcp), "bcp doesn't belong to this method");
duke@0 214 return bcp;
duke@0 215 }
duke@0 216
duke@0 217
duke@0 218 int methodOopDesc::object_size(bool is_native) {
duke@0 219 // If native, then include pointers for native_function and signature_handler
duke@0 220 int extra_bytes = (is_native) ? 2*sizeof(address*) : 0;
duke@0 221 int extra_words = align_size_up(extra_bytes, BytesPerWord) / BytesPerWord;
duke@0 222 return align_object_size(header_size() + extra_words);
duke@0 223 }
duke@0 224
duke@0 225
coleenp@2062 226 Symbol* methodOopDesc::klass_name() const {
duke@0 227 klassOop k = method_holder();
duke@0 228 assert(k->is_klass(), "must be klass");
duke@0 229 instanceKlass* ik = (instanceKlass*) k->klass_part();
duke@0 230 return ik->name();
duke@0 231 }
duke@0 232
duke@0 233
duke@0 234 void methodOopDesc::set_interpreter_kind() {
duke@0 235 int kind = Interpreter::method_kind(methodOop(this));
duke@0 236 assert(kind != Interpreter::invalid,
duke@0 237 "interpreter entry must be valid");
duke@0 238 set_interpreter_kind(kind);
duke@0 239 }
duke@0 240
duke@0 241
duke@0 242 // Attempt to return method oop to original state. Clear any pointers
duke@0 243 // (to objects outside the shared spaces). We won't be able to predict
duke@0 244 // where they should point in a new JVM. Further initialize some
duke@0 245 // entries now in order allow them to be write protected later.
duke@0 246
duke@0 247 void methodOopDesc::remove_unshareable_info() {
duke@0 248 unlink_method();
duke@0 249 set_interpreter_kind();
duke@0 250 }
duke@0 251
duke@0 252
iveresov@1703 253 bool methodOopDesc::was_executed_more_than(int n) {
duke@0 254 // Invocation counter is reset when the methodOop is compiled.
duke@0 255 // If the method has compiled code we therefore assume it has
duke@0 256 // be excuted more than n times.
duke@0 257 if (is_accessor() || is_empty_method() || (code() != NULL)) {
duke@0 258 // interpreter doesn't bump invocation counter of trivial methods
duke@0 259 // compiler does not bump invocation counter of compiled methods
duke@0 260 return true;
iveresov@1703 261 }
iveresov@1703 262 else if (_invocation_counter.carry() || (method_data() != NULL && method_data()->invocation_counter()->carry())) {
duke@0 263 // The carry bit is set when the counter overflows and causes
duke@0 264 // a compilation to occur. We don't know how many times
duke@0 265 // the counter has been reset, so we simply assume it has
duke@0 266 // been executed more than n times.
duke@0 267 return true;
duke@0 268 } else {
duke@0 269 return invocation_count() > n;
duke@0 270 }
duke@0 271 }
duke@0 272
duke@0 273 #ifndef PRODUCT
iveresov@1703 274 void methodOopDesc::print_invocation_count() {
duke@0 275 if (is_static()) tty->print("static ");
duke@0 276 if (is_final()) tty->print("final ");
duke@0 277 if (is_synchronized()) tty->print("synchronized ");
duke@0 278 if (is_native()) tty->print("native ");
duke@0 279 method_holder()->klass_part()->name()->print_symbol_on(tty);
duke@0 280 tty->print(".");
duke@0 281 name()->print_symbol_on(tty);
duke@0 282 signature()->print_symbol_on(tty);
duke@0 283
duke@0 284 if (WizardMode) {
duke@0 285 // dump the size of the byte codes
duke@0 286 tty->print(" {%d}", code_size());
duke@0 287 }
duke@0 288 tty->cr();
duke@0 289
duke@0 290 tty->print_cr (" interpreter_invocation_count: %8d ", interpreter_invocation_count());
duke@0 291 tty->print_cr (" invocation_counter: %8d ", invocation_count());
duke@0 292 tty->print_cr (" backedge_counter: %8d ", backedge_count());
duke@0 293 if (CountCompiledCalls) {
duke@0 294 tty->print_cr (" compiled_invocation_count: %8d ", compiled_invocation_count());
duke@0 295 }
duke@0 296
duke@0 297 }
duke@0 298 #endif
duke@0 299
duke@0 300 // Build a methodDataOop object to hold information about this method
duke@0 301 // collected in the interpreter.
duke@0 302 void methodOopDesc::build_interpreter_method_data(methodHandle method, TRAPS) {
coleenp@1928 303 // Do not profile method if current thread holds the pending list lock,
coleenp@1928 304 // which avoids deadlock for acquiring the MethodData_lock.
coleenp@1928 305 if (instanceRefKlass::owns_pending_list_lock((JavaThread*)THREAD)) {
coleenp@1928 306 return;
coleenp@1928 307 }
coleenp@1928 308
duke@0 309 // Grab a lock here to prevent multiple
duke@0 310 // methodDataOops from being created.
duke@0 311 MutexLocker ml(MethodData_lock, THREAD);
duke@0 312 if (method->method_data() == NULL) {
duke@0 313 methodDataOop method_data = oopFactory::new_methodData(method, CHECK);
duke@0 314 method->set_method_data(method_data);
duke@0 315 if (PrintMethodData && (Verbose || WizardMode)) {
duke@0 316 ResourceMark rm(THREAD);
duke@0 317 tty->print("build_interpreter_method_data for ");
duke@0 318 method->print_name(tty);
duke@0 319 tty->cr();
duke@0 320 // At the end of the run, the MDO, full of data, will be dumped.
duke@0 321 }
duke@0 322 }
duke@0 323 }
duke@0 324
duke@0 325 void methodOopDesc::cleanup_inline_caches() {
duke@0 326 // The current system doesn't use inline caches in the interpreter
duke@0 327 // => nothing to do (keep this method around for future use)
duke@0 328 }
duke@0 329
duke@0 330
jrose@710 331 int methodOopDesc::extra_stack_words() {
jrose@710 332 // not an inline function, to avoid a header dependency on Interpreter
twisti@1426 333 return extra_stack_entries() * Interpreter::stackElementSize;
jrose@710 334 }
jrose@710 335
jrose@710 336
duke@0 337 void methodOopDesc::compute_size_of_parameters(Thread *thread) {
coleenp@2062 338 ArgumentSizeComputer asc(signature());
duke@0 339 set_size_of_parameters(asc.size() + (is_static() ? 0 : 1));
duke@0 340 }
duke@0 341
duke@0 342 #ifdef CC_INTERP
duke@0 343 void methodOopDesc::set_result_index(BasicType type) {
duke@0 344 _result_index = Interpreter::BasicType_as_index(type);
duke@0 345 }
duke@0 346 #endif
duke@0 347
duke@0 348 BasicType methodOopDesc::result_type() const {
duke@0 349 ResultTypeFinder rtf(signature());
duke@0 350 return rtf.type();
duke@0 351 }
duke@0 352
duke@0 353
duke@0 354 bool methodOopDesc::is_empty_method() const {
duke@0 355 return code_size() == 1
duke@0 356 && *code_base() == Bytecodes::_return;
duke@0 357 }
duke@0 358
duke@0 359
duke@0 360 bool methodOopDesc::is_vanilla_constructor() const {
duke@0 361 // Returns true if this method is a vanilla constructor, i.e. an "<init>" "()V" method
duke@0 362 // which only calls the superclass vanilla constructor and possibly does stores of
duke@0 363 // zero constants to local fields:
duke@0 364 //
duke@0 365 // aload_0
duke@0 366 // invokespecial
duke@0 367 // indexbyte1
duke@0 368 // indexbyte2
duke@0 369 //
duke@0 370 // followed by an (optional) sequence of:
duke@0 371 //
duke@0 372 // aload_0
duke@0 373 // aconst_null / iconst_0 / fconst_0 / dconst_0
duke@0 374 // putfield
duke@0 375 // indexbyte1
duke@0 376 // indexbyte2
duke@0 377 //
duke@0 378 // followed by:
duke@0 379 //
duke@0 380 // return
duke@0 381
duke@0 382 assert(name() == vmSymbols::object_initializer_name(), "Should only be called for default constructors");
duke@0 383 assert(signature() == vmSymbols::void_method_signature(), "Should only be called for default constructors");
duke@0 384 int size = code_size();
duke@0 385 // Check if size match
duke@0 386 if (size == 0 || size % 5 != 0) return false;
duke@0 387 address cb = code_base();
duke@0 388 int last = size - 1;
duke@0 389 if (cb[0] != Bytecodes::_aload_0 || cb[1] != Bytecodes::_invokespecial || cb[last] != Bytecodes::_return) {
duke@0 390 // Does not call superclass default constructor
duke@0 391 return false;
duke@0 392 }
duke@0 393 // Check optional sequence
duke@0 394 for (int i = 4; i < last; i += 5) {
duke@0 395 if (cb[i] != Bytecodes::_aload_0) return false;
duke@0 396 if (!Bytecodes::is_zero_const(Bytecodes::cast(cb[i+1]))) return false;
duke@0 397 if (cb[i+2] != Bytecodes::_putfield) return false;
duke@0 398 }
duke@0 399 return true;
duke@0 400 }
duke@0 401
duke@0 402
duke@0 403 bool methodOopDesc::compute_has_loops_flag() {
duke@0 404 BytecodeStream bcs(methodOop(this));
duke@0 405 Bytecodes::Code bc;
duke@0 406
duke@0 407 while ((bc = bcs.next()) >= 0) {
duke@0 408 switch( bc ) {
duke@0 409 case Bytecodes::_ifeq:
duke@0 410 case Bytecodes::_ifnull:
duke@0 411 case Bytecodes::_iflt:
duke@0 412 case Bytecodes::_ifle:
duke@0 413 case Bytecodes::_ifne:
duke@0 414 case Bytecodes::_ifnonnull:
duke@0 415 case Bytecodes::_ifgt:
duke@0 416 case Bytecodes::_ifge:
duke@0 417 case Bytecodes::_if_icmpeq:
duke@0 418 case Bytecodes::_if_icmpne:
duke@0 419 case Bytecodes::_if_icmplt:
duke@0 420 case Bytecodes::_if_icmpgt:
duke@0 421 case Bytecodes::_if_icmple:
duke@0 422 case Bytecodes::_if_icmpge:
duke@0 423 case Bytecodes::_if_acmpeq:
duke@0 424 case Bytecodes::_if_acmpne:
duke@0 425 case Bytecodes::_goto:
duke@0 426 case Bytecodes::_jsr:
duke@0 427 if( bcs.dest() < bcs.next_bci() ) _access_flags.set_has_loops();
duke@0 428 break;
duke@0 429
duke@0 430 case Bytecodes::_goto_w:
duke@0 431 case Bytecodes::_jsr_w:
duke@0 432 if( bcs.dest_w() < bcs.next_bci() ) _access_flags.set_has_loops();
duke@0 433 break;
duke@0 434 }
duke@0 435 }
duke@0 436 _access_flags.set_loops_flag_init();
duke@0 437 return _access_flags.has_loops();
duke@0 438 }
duke@0 439
duke@0 440
duke@0 441 bool methodOopDesc::is_final_method() const {
duke@0 442 // %%% Should return true for private methods also,
duke@0 443 // since there is no way to override them.
duke@0 444 return is_final() || Klass::cast(method_holder())->is_final();
duke@0 445 }
duke@0 446
duke@0 447
duke@0 448 bool methodOopDesc::is_strict_method() const {
duke@0 449 return is_strict();
duke@0 450 }
duke@0 451
duke@0 452
duke@0 453 bool methodOopDesc::can_be_statically_bound() const {
duke@0 454 if (is_final_method()) return true;
duke@0 455 return vtable_index() == nonvirtual_vtable_index;
duke@0 456 }
duke@0 457
duke@0 458
duke@0 459 bool methodOopDesc::is_accessor() const {
duke@0 460 if (code_size() != 5) return false;
duke@0 461 if (size_of_parameters() != 1) return false;
never@2027 462 if (java_code_at(0) != Bytecodes::_aload_0 ) return false;
never@2027 463 if (java_code_at(1) != Bytecodes::_getfield) return false;
never@2027 464 if (java_code_at(4) != Bytecodes::_areturn &&
never@2027 465 java_code_at(4) != Bytecodes::_ireturn ) return false;
duke@0 466 return true;
duke@0 467 }
duke@0 468
duke@0 469
duke@0 470 bool methodOopDesc::is_initializer() const {
kamg@2181 471 return name() == vmSymbols::object_initializer_name() || is_static_initializer();
kamg@2181 472 }
kamg@2181 473
kamg@2181 474 bool methodOopDesc::has_valid_initializer_flags() const {
kamg@2181 475 return (is_static() ||
kamg@2181 476 instanceKlass::cast(method_holder())->major_version() < 51);
kamg@2181 477 }
kamg@2181 478
kamg@2181 479 bool methodOopDesc::is_static_initializer() const {
kamg@2181 480 // For classfiles version 51 or greater, ensure that the clinit method is
kamg@2181 481 // static. Non-static methods with the name "<clinit>" are not static
kamg@2181 482 // initializers. (older classfiles exempted for backward compatibility)
kamg@2181 483 return name() == vmSymbols::class_initializer_name() &&
kamg@2181 484 has_valid_initializer_flags();
duke@0 485 }
duke@0 486
duke@0 487
duke@0 488 objArrayHandle methodOopDesc::resolved_checked_exceptions_impl(methodOop this_oop, TRAPS) {
duke@0 489 int length = this_oop->checked_exceptions_length();
duke@0 490 if (length == 0) { // common case
duke@0 491 return objArrayHandle(THREAD, Universe::the_empty_class_klass_array());
duke@0 492 } else {
duke@0 493 methodHandle h_this(THREAD, this_oop);
never@1142 494 objArrayOop m_oop = oopFactory::new_objArray(SystemDictionary::Class_klass(), length, CHECK_(objArrayHandle()));
duke@0 495 objArrayHandle mirrors (THREAD, m_oop);
duke@0 496 for (int i = 0; i < length; i++) {
duke@0 497 CheckedExceptionElement* table = h_this->checked_exceptions_start(); // recompute on each iteration, not gc safe
duke@0 498 klassOop k = h_this->constants()->klass_at(table[i].class_cp_index, CHECK_(objArrayHandle()));
never@1142 499 assert(Klass::cast(k)->is_subclass_of(SystemDictionary::Throwable_klass()), "invalid exception class");
duke@0 500 mirrors->obj_at_put(i, Klass::cast(k)->java_mirror());
duke@0 501 }
duke@0 502 return mirrors;
duke@0 503 }
duke@0 504 };
duke@0 505
duke@0 506
duke@0 507 int methodOopDesc::line_number_from_bci(int bci) const {
duke@0 508 if (bci == SynchronizationEntryBCI) bci = 0;
duke@0 509 assert(bci == 0 || 0 <= bci && bci < code_size(), "illegal bci");
duke@0 510 int best_bci = 0;
duke@0 511 int best_line = -1;
duke@0 512
duke@0 513 if (has_linenumber_table()) {
duke@0 514 // The line numbers are a short array of 2-tuples [start_pc, line_number].
duke@0 515 // Not necessarily sorted and not necessarily one-to-one.
duke@0 516 CompressedLineNumberReadStream stream(compressed_linenumber_table());
duke@0 517 while (stream.read_pair()) {
duke@0 518 if (stream.bci() == bci) {
duke@0 519 // perfect match
duke@0 520 return stream.line();
duke@0 521 } else {
duke@0 522 // update best_bci/line
duke@0 523 if (stream.bci() < bci && stream.bci() >= best_bci) {
duke@0 524 best_bci = stream.bci();
duke@0 525 best_line = stream.line();
duke@0 526 }
duke@0 527 }
duke@0 528 }
duke@0 529 }
duke@0 530 return best_line;
duke@0 531 }
duke@0 532
duke@0 533
duke@0 534 bool methodOopDesc::is_klass_loaded_by_klass_index(int klass_index) const {
duke@0 535 if( _constants->tag_at(klass_index).is_unresolved_klass() ) {
duke@0 536 Thread *thread = Thread::current();
coleenp@2062 537 Symbol* klass_name = _constants->klass_name_at(klass_index);
duke@0 538 Handle loader(thread, instanceKlass::cast(method_holder())->class_loader());
duke@0 539 Handle prot (thread, Klass::cast(method_holder())->protection_domain());
duke@0 540 return SystemDictionary::find(klass_name, loader, prot, thread) != NULL;
duke@0 541 } else {
duke@0 542 return true;
duke@0 543 }
duke@0 544 }
duke@0 545
duke@0 546
duke@0 547 bool methodOopDesc::is_klass_loaded(int refinfo_index, bool must_be_resolved) const {
duke@0 548 int klass_index = _constants->klass_ref_index_at(refinfo_index);
duke@0 549 if (must_be_resolved) {
duke@0 550 // Make sure klass is resolved in constantpool.
duke@0 551 if (constants()->tag_at(klass_index).is_unresolved_klass()) return false;
duke@0 552 }
duke@0 553 return is_klass_loaded_by_klass_index(klass_index);
duke@0 554 }
duke@0 555
duke@0 556
duke@0 557 void methodOopDesc::set_native_function(address function, bool post_event_flag) {
duke@0 558 assert(function != NULL, "use clear_native_function to unregister natives");
duke@0 559 address* native_function = native_function_addr();
duke@0 560
duke@0 561 // We can see racers trying to place the same native function into place. Once
duke@0 562 // is plenty.
duke@0 563 address current = *native_function;
duke@0 564 if (current == function) return;
duke@0 565 if (post_event_flag && JvmtiExport::should_post_native_method_bind() &&
duke@0 566 function != NULL) {
duke@0 567 // native_method_throw_unsatisfied_link_error_entry() should only
duke@0 568 // be passed when post_event_flag is false.
duke@0 569 assert(function !=
duke@0 570 SharedRuntime::native_method_throw_unsatisfied_link_error_entry(),
duke@0 571 "post_event_flag mis-match");
duke@0 572
duke@0 573 // post the bind event, and possible change the bind function
duke@0 574 JvmtiExport::post_native_method_bind(this, &function);
duke@0 575 }
duke@0 576 *native_function = function;
duke@0 577 // This function can be called more than once. We must make sure that we always
duke@0 578 // use the latest registered method -> check if a stub already has been generated.
duke@0 579 // If so, we have to make it not_entrant.
duke@0 580 nmethod* nm = code(); // Put it into local variable to guard against concurrent updates
duke@0 581 if (nm != NULL) {
duke@0 582 nm->make_not_entrant();
duke@0 583 }
duke@0 584 }
duke@0 585
duke@0 586
duke@0 587 bool methodOopDesc::has_native_function() const {
duke@0 588 address func = native_function();
duke@0 589 return (func != NULL && func != SharedRuntime::native_method_throw_unsatisfied_link_error_entry());
duke@0 590 }
duke@0 591
duke@0 592
duke@0 593 void methodOopDesc::clear_native_function() {
duke@0 594 set_native_function(
duke@0 595 SharedRuntime::native_method_throw_unsatisfied_link_error_entry(),
duke@0 596 !native_bind_event_is_interesting);
duke@0 597 clear_code();
duke@0 598 }
duke@0 599
never@3065 600 address methodOopDesc::critical_native_function() {
never@3065 601 methodHandle mh(this);
never@3065 602 return NativeLookup::lookup_critical_entry(mh);
never@3065 603 }
never@3065 604
duke@0 605
duke@0 606 void methodOopDesc::set_signature_handler(address handler) {
duke@0 607 address* signature_handler = signature_handler_addr();
duke@0 608 *signature_handler = handler;
duke@0 609 }
duke@0 610
duke@0 611
duke@0 612 bool methodOopDesc::is_not_compilable(int comp_level) const {
jrose@710 613 if (is_method_handle_invoke()) {
jrose@710 614 // compilers must recognize this method specially, or not at all
jrose@710 615 return true;
jrose@710 616 }
iveresov@1703 617 if (number_of_breakpoints() > 0) {
iveresov@1703 618 return true;
duke@0 619 }
iveresov@1703 620 if (comp_level == CompLevel_any) {
iveresov@1703 621 return is_not_c1_compilable() || is_not_c2_compilable();
iveresov@1703 622 }
iveresov@1703 623 if (is_c1_compile(comp_level)) {
iveresov@1703 624 return is_not_c1_compilable();
iveresov@1703 625 }
iveresov@1703 626 if (is_c2_compile(comp_level)) {
iveresov@1703 627 return is_not_c2_compilable();
iveresov@1703 628 }
iveresov@1703 629 return false;
duke@0 630 }
duke@0 631
duke@0 632 // call this when compiler finds that this method is not compilable
kvn@1208 633 void methodOopDesc::set_not_compilable(int comp_level, bool report) {
kvn@1208 634 if (PrintCompilation && report) {
kvn@1206 635 ttyLocker ttyl;
kvn@1206 636 tty->print("made not compilable ");
kvn@1206 637 this->print_short_name(tty);
kvn@1206 638 int size = this->code_size();
kvn@1206 639 if (size > 0)
kvn@1206 640 tty->print(" (%d bytes)", size);
kvn@1206 641 tty->cr();
kvn@1206 642 }
duke@0 643 if ((TraceDeoptimization || LogCompilation) && (xtty != NULL)) {
duke@0 644 ttyLocker ttyl;
duke@0 645 xtty->begin_elem("make_not_compilable thread='%d'", (int) os::current_thread_id());
duke@0 646 xtty->method(methodOop(this));
duke@0 647 xtty->stamp();
duke@0 648 xtty->end_elem();
duke@0 649 }
iveresov@1703 650 if (comp_level == CompLevel_all) {
iveresov@1703 651 set_not_c1_compilable();
iveresov@1703 652 set_not_c2_compilable();
iveresov@1703 653 } else {
iveresov@1703 654 if (is_c1_compile(comp_level)) {
iveresov@1703 655 set_not_c1_compilable();
iveresov@1703 656 } else
iveresov@1703 657 if (is_c2_compile(comp_level)) {
iveresov@1703 658 set_not_c2_compilable();
iveresov@1703 659 }
duke@0 660 }
iveresov@1703 661 CompilationPolicy::policy()->disable_compilation(this);
duke@0 662 }
duke@0 663
duke@0 664 // Revert to using the interpreter and clear out the nmethod
duke@0 665 void methodOopDesc::clear_code() {
duke@0 666
duke@0 667 // this may be NULL if c2i adapters have not been made yet
duke@0 668 // Only should happen at allocate time.
duke@0 669 if (_adapter == NULL) {
duke@0 670 _from_compiled_entry = NULL;
duke@0 671 } else {
duke@0 672 _from_compiled_entry = _adapter->get_c2i_entry();
duke@0 673 }
duke@0 674 OrderAccess::storestore();
duke@0 675 _from_interpreted_entry = _i2i_entry;
duke@0 676 OrderAccess::storestore();
duke@0 677 _code = NULL;
duke@0 678 }
duke@0 679
duke@0 680 // Called by class data sharing to remove any entry points (which are not shared)
duke@0 681 void methodOopDesc::unlink_method() {
duke@0 682 _code = NULL;
duke@0 683 _i2i_entry = NULL;
duke@0 684 _from_interpreted_entry = NULL;
duke@0 685 if (is_native()) {
duke@0 686 *native_function_addr() = NULL;
duke@0 687 set_signature_handler(NULL);
duke@0 688 }
duke@0 689 NOT_PRODUCT(set_compiled_invocation_count(0);)
duke@0 690 invocation_counter()->reset();
duke@0 691 backedge_counter()->reset();
duke@0 692 _adapter = NULL;
duke@0 693 _from_compiled_entry = NULL;
duke@0 694 assert(_method_data == NULL, "unexpected method data?");
duke@0 695 set_method_data(NULL);
duke@0 696 set_interpreter_throwout_count(0);
duke@0 697 set_interpreter_invocation_count(0);
duke@0 698 }
duke@0 699
duke@0 700 // Called when the method_holder is getting linked. Setup entrypoints so the method
duke@0 701 // is ready to be called from interpreter, compiler, and vtables.
duke@0 702 void methodOopDesc::link_method(methodHandle h_method, TRAPS) {
coleenp@2510 703 // If the code cache is full, we may reenter this function for the
coleenp@2510 704 // leftover methods that weren't linked.
coleenp@2510 705 if (_i2i_entry != NULL) return;
coleenp@2510 706
duke@0 707 assert(_adapter == NULL, "init'd to NULL" );
duke@0 708 assert( _code == NULL, "nothing compiled yet" );
duke@0 709
duke@0 710 // Setup interpreter entrypoint
duke@0 711 assert(this == h_method(), "wrong h_method()" );
duke@0 712 address entry = Interpreter::entry_for_method(h_method);
duke@0 713 assert(entry != NULL, "interpreter entry must be non-null");
duke@0 714 // Sets both _i2i_entry and _from_interpreted_entry
duke@0 715 set_interpreter_entry(entry);
jrose@710 716 if (is_native() && !is_method_handle_invoke()) {
duke@0 717 set_native_function(
duke@0 718 SharedRuntime::native_method_throw_unsatisfied_link_error_entry(),
duke@0 719 !native_bind_event_is_interesting);
duke@0 720 }
duke@0 721
duke@0 722 // Setup compiler entrypoint. This is made eagerly, so we do not need
duke@0 723 // special handling of vtables. An alternative is to make adapters more
duke@0 724 // lazily by calling make_adapter() from from_compiled_entry() for the
duke@0 725 // normal calls. For vtable calls life gets more complicated. When a
duke@0 726 // call-site goes mega-morphic we need adapters in all methods which can be
duke@0 727 // called from the vtable. We need adapters on such methods that get loaded
duke@0 728 // later. Ditto for mega-morphic itable calls. If this proves to be a
duke@0 729 // problem we'll make these lazily later.
coleenp@2511 730 (void) make_adapters(h_method, CHECK);
duke@0 731
duke@0 732 // ONLY USE the h_method now as make_adapter may have blocked
duke@0 733
duke@0 734 }
duke@0 735
duke@0 736 address methodOopDesc::make_adapters(methodHandle mh, TRAPS) {
duke@0 737 // Adapters for compiled code are made eagerly here. They are fairly
duke@0 738 // small (generally < 100 bytes) and quick to make (and cached and shared)
duke@0 739 // so making them eagerly shouldn't be too expensive.
duke@0 740 AdapterHandlerEntry* adapter = AdapterHandlerLibrary::get_adapter(mh);
duke@0 741 if (adapter == NULL ) {
never@1187 742 THROW_MSG_NULL(vmSymbols::java_lang_VirtualMachineError(), "out of space in CodeCache for adapters");
duke@0 743 }
duke@0 744
duke@0 745 mh->set_adapter_entry(adapter);
duke@0 746 mh->_from_compiled_entry = adapter->get_c2i_entry();
duke@0 747 return adapter->get_c2i_entry();
duke@0 748 }
duke@0 749
duke@0 750 // The verified_code_entry() must be called when a invoke is resolved
duke@0 751 // on this method.
duke@0 752
duke@0 753 // It returns the compiled code entry point, after asserting not null.
duke@0 754 // This function is called after potential safepoints so that nmethod
duke@0 755 // or adapter that it points to is still live and valid.
duke@0 756 // This function must not hit a safepoint!
duke@0 757 address methodOopDesc::verified_code_entry() {
duke@0 758 debug_only(No_Safepoint_Verifier nsv;)
kvn@1202 759 nmethod *code = (nmethod *)OrderAccess::load_ptr_acquire(&_code);
kvn@1202 760 if (code == NULL && UseCodeCacheFlushing) {
kvn@1202 761 nmethod *saved_code = CodeCache::find_and_remove_saved_code(this);
kvn@1202 762 if (saved_code != NULL) {
kvn@1202 763 methodHandle method(this);
kvn@1202 764 assert( ! saved_code->is_osr_method(), "should not get here for osr" );
kvn@1202 765 set_code( method, saved_code );
kvn@1202 766 }
kvn@1202 767 }
kvn@1202 768
duke@0 769 assert(_from_compiled_entry != NULL, "must be set");
duke@0 770 return _from_compiled_entry;
duke@0 771 }
duke@0 772
duke@0 773 // Check that if an nmethod ref exists, it has a backlink to this or no backlink at all
duke@0 774 // (could be racing a deopt).
duke@0 775 // Not inline to avoid circular ref.
duke@0 776 bool methodOopDesc::check_code() const {
duke@0 777 // cached in a register or local. There's a race on the value of the field.
duke@0 778 nmethod *code = (nmethod *)OrderAccess::load_ptr_acquire(&_code);
duke@0 779 return code == NULL || (code->method() == NULL) || (code->method() == (methodOop)this && !code->is_osr_method());
duke@0 780 }
duke@0 781
duke@0 782 // Install compiled code. Instantly it can execute.
duke@0 783 void methodOopDesc::set_code(methodHandle mh, nmethod *code) {
duke@0 784 assert( code, "use clear_code to remove code" );
duke@0 785 assert( mh->check_code(), "" );
duke@0 786
duke@0 787 guarantee(mh->adapter() != NULL, "Adapter blob must already exist!");
duke@0 788
duke@0 789 // These writes must happen in this order, because the interpreter will
duke@0 790 // directly jump to from_interpreted_entry which jumps to an i2c adapter
duke@0 791 // which jumps to _from_compiled_entry.
duke@0 792 mh->_code = code; // Assign before allowing compiled code to exec
duke@0 793
duke@0 794 int comp_level = code->comp_level();
duke@0 795 // In theory there could be a race here. In practice it is unlikely
duke@0 796 // and not worth worrying about.
iveresov@1703 797 if (comp_level > mh->highest_comp_level()) {
iveresov@1703 798 mh->set_highest_comp_level(comp_level);
duke@0 799 }
duke@0 800
duke@0 801 OrderAccess::storestore();
twisti@1612 802 #ifdef SHARK
twisti@1765 803 mh->_from_interpreted_entry = code->insts_begin();
twisti@1612 804 #else
duke@0 805 mh->_from_compiled_entry = code->verified_entry_point();
duke@0 806 OrderAccess::storestore();
duke@0 807 // Instantly compiled code can execute.
duke@0 808 mh->_from_interpreted_entry = mh->get_i2c_entry();
twisti@1612 809 #endif // SHARK
duke@0 810
duke@0 811 }
duke@0 812
duke@0 813
duke@0 814 bool methodOopDesc::is_overridden_in(klassOop k) const {
duke@0 815 instanceKlass* ik = instanceKlass::cast(k);
duke@0 816
duke@0 817 if (ik->is_interface()) return false;
duke@0 818
duke@0 819 // If method is an interface, we skip it - except if it
duke@0 820 // is a miranda method
duke@0 821 if (instanceKlass::cast(method_holder())->is_interface()) {
duke@0 822 // Check that method is not a miranda method
duke@0 823 if (ik->lookup_method(name(), signature()) == NULL) {
duke@0 824 // No implementation exist - so miranda method
duke@0 825 return false;
duke@0 826 }
duke@0 827 return true;
duke@0 828 }
duke@0 829
duke@0 830 assert(ik->is_subclass_of(method_holder()), "should be subklass");
duke@0 831 assert(ik->vtable() != NULL, "vtable should exist");
duke@0 832 if (vtable_index() == nonvirtual_vtable_index) {
duke@0 833 return false;
duke@0 834 } else {
duke@0 835 methodOop vt_m = ik->method_at_vtable(vtable_index());
duke@0 836 return vt_m != methodOop(this);
duke@0 837 }
duke@0 838 }
duke@0 839
duke@0 840
dcubed@48 841 // give advice about whether this methodOop should be cached or not
dcubed@48 842 bool methodOopDesc::should_not_be_cached() const {
dcubed@48 843 if (is_old()) {
dcubed@48 844 // This method has been redefined. It is either EMCP or obsolete
dcubed@48 845 // and we don't want to cache it because that would pin the method
dcubed@48 846 // down and prevent it from being collectible if and when it
dcubed@48 847 // finishes executing.
dcubed@48 848 return true;
dcubed@48 849 }
dcubed@48 850
dcubed@48 851 if (mark()->should_not_be_cached()) {
dcubed@48 852 // It is either not safe or not a good idea to cache this
dcubed@48 853 // method at this time because of the state of the embedded
dcubed@48 854 // markOop. See markOop.cpp for the gory details.
dcubed@48 855 return true;
dcubed@48 856 }
dcubed@48 857
dcubed@48 858 // caching this method should be just fine
dcubed@48 859 return false;
dcubed@48 860 }
dcubed@48 861
jrose@1427 862 bool methodOopDesc::is_method_handle_invoke_name(vmSymbols::SID name_sid) {
jrose@1427 863 switch (name_sid) {
jrose@1427 864 case vmSymbols::VM_SYMBOL_ENUM_NAME(invokeExact_name):
jrose@2307 865 case vmSymbols::VM_SYMBOL_ENUM_NAME(invoke_name):
jrose@1427 866 return true;
jrose@1427 867 }
jrose@2307 868 if (AllowInvokeGeneric
jrose@2307 869 && name_sid == vmSymbols::VM_SYMBOL_ENUM_NAME(invokeGeneric_name))
jrose@1713 870 return true;
jrose@1427 871 return false;
jrose@1427 872 }
jrose@1427 873
jrose@710 874 // Constant pool structure for invoke methods:
jrose@710 875 enum {
jrose@1427 876 _imcp_invoke_name = 1, // utf8: 'invokeExact' or 'invokeGeneric'
coleenp@2062 877 _imcp_invoke_signature, // utf8: (variable Symbol*)
jrose@2204 878 _imcp_method_type_value, // string: (variable java/lang/invoke/MethodType, sic)
jrose@710 879 _imcp_limit
jrose@710 880 };
jrose@710 881
jrose@710 882 oop methodOopDesc::method_handle_type() const {
jrose@710 883 if (!is_method_handle_invoke()) { assert(false, "caller resp."); return NULL; }
jrose@710 884 oop mt = constants()->resolved_string_at(_imcp_method_type_value);
jrose@710 885 assert(mt->klass() == SystemDictionary::MethodType_klass(), "");
jrose@710 886 return mt;
jrose@710 887 }
jrose@710 888
jrose@710 889 jint* methodOopDesc::method_type_offsets_chain() {
jrose@710 890 static jint pchase[] = { -1, -1, -1 };
jrose@710 891 if (pchase[0] == -1) {
jrose@710 892 jint step0 = in_bytes(constants_offset());
jrose@710 893 jint step1 = (constantPoolOopDesc::header_size() + _imcp_method_type_value) * HeapWordSize;
jrose@710 894 // do this in reverse to avoid races:
jrose@710 895 OrderAccess::release_store(&pchase[1], step1);
jrose@710 896 OrderAccess::release_store(&pchase[0], step0);
jrose@710 897 }
jrose@710 898 return pchase;
jrose@710 899 }
jrose@710 900
twisti@1152 901 //------------------------------------------------------------------------------
twisti@1152 902 // methodOopDesc::is_method_handle_adapter
twisti@1152 903 //
twisti@1152 904 // Tests if this method is an internal adapter frame from the
twisti@1152 905 // MethodHandleCompiler.
jrose@1427 906 // Must be consistent with MethodHandleCompiler::get_method_oop().
twisti@1152 907 bool methodOopDesc::is_method_handle_adapter() const {
jrose@1582 908 if (is_synthetic() &&
jrose@1582 909 !is_native() && // has code from MethodHandleCompiler
jrose@1582 910 is_method_handle_invoke_name(name()) &&
jrose@1582 911 MethodHandleCompiler::klass_is_method_handle_adapter_holder(method_holder())) {
jrose@1582 912 assert(!is_method_handle_invoke(), "disjoint");
jrose@1582 913 return true;
jrose@1582 914 } else {
jrose@1582 915 return false;
jrose@1582 916 }
twisti@1152 917 }
twisti@1152 918
jrose@710 919 methodHandle methodOopDesc::make_invoke_method(KlassHandle holder,
coleenp@2062 920 Symbol* name,
coleenp@2062 921 Symbol* signature,
jrose@710 922 Handle method_type, TRAPS) {
never@2656 923 ResourceMark rm;
jrose@710 924 methodHandle empty;
jrose@710 925
jrose@710 926 assert(holder() == SystemDictionary::MethodHandle_klass(),
jrose@710 927 "must be a JSR 292 magic type");
jrose@710 928
jrose@710 929 if (TraceMethodHandles) {
jrose@710 930 tty->print("Creating invoke method for ");
jrose@710 931 signature->print_value();
jrose@710 932 tty->cr();
jrose@710 933 }
jrose@710 934
jrose@2325 935 // invariant: cp->symbol_at_put is preceded by a refcount increment (more usually a lookup)
jrose@2325 936 name->increment_refcount();
jrose@2325 937 signature->increment_refcount();
jrose@2325 938
jrose@2547 939 // record non-BCP method types in the constant pool
jrose@2547 940 GrowableArray<KlassHandle>* extra_klasses = NULL;
jrose@2547 941 for (int i = -1, len = java_lang_invoke_MethodType::ptype_count(method_type()); i < len; i++) {
jrose@2547 942 oop ptype = (i == -1
jrose@2547 943 ? java_lang_invoke_MethodType::rtype(method_type())
jrose@2547 944 : java_lang_invoke_MethodType::ptype(method_type(), i));
jrose@2547 945 klassOop klass = check_non_bcp_klass(java_lang_Class::as_klassOop(ptype));
jrose@2547 946 if (klass != NULL) {
jrose@2547 947 if (extra_klasses == NULL)
jrose@2547 948 extra_klasses = new GrowableArray<KlassHandle>(len+1);
jrose@2547 949 bool dup = false;
jrose@2547 950 for (int j = 0; j < extra_klasses->length(); j++) {
jrose@2547 951 if (extra_klasses->at(j) == klass) { dup = true; break; }
jrose@2547 952 }
jrose@2547 953 if (!dup)
jrose@2547 954 extra_klasses->append(KlassHandle(THREAD, klass));
jrose@2547 955 }
jrose@2547 956 }
jrose@2547 957
jrose@2547 958 int extra_klass_count = (extra_klasses == NULL ? 0 : extra_klasses->length());
jrose@2547 959 int cp_length = _imcp_limit + extra_klass_count;
jrose@710 960 constantPoolHandle cp;
jrose@710 961 {
jrose@2547 962 constantPoolOop cp_oop = oopFactory::new_constantPool(cp_length, IsSafeConc, CHECK_(empty));
jrose@710 963 cp = constantPoolHandle(THREAD, cp_oop);
jrose@710 964 }
coleenp@2062 965 cp->symbol_at_put(_imcp_invoke_name, name);
coleenp@2062 966 cp->symbol_at_put(_imcp_invoke_signature, signature);
coleenp@2062 967 cp->string_at_put(_imcp_method_type_value, Universe::the_null_string());
jrose@2547 968 for (int j = 0; j < extra_klass_count; j++) {
jrose@2547 969 KlassHandle klass = extra_klasses->at(j);
jrose@2547 970 cp->klass_at_put(_imcp_limit + j, klass());
jrose@2547 971 }
jrose@2547 972 cp->set_preresolution();
jrose@710 973 cp->set_pool_holder(holder());
jrose@710 974
jrose@710 975 // set up the fancy stuff:
jrose@710 976 cp->pseudo_string_at_put(_imcp_method_type_value, method_type());
jrose@710 977 methodHandle m;
jrose@710 978 {
jrose@710 979 int flags_bits = (JVM_MH_INVOKE_BITS | JVM_ACC_PUBLIC | JVM_ACC_FINAL);
jrose@710 980 methodOop m_oop = oopFactory::new_method(0, accessFlags_from(flags_bits),
jrose@710 981 0, 0, 0, IsSafeConc, CHECK_(empty));
jrose@710 982 m = methodHandle(THREAD, m_oop);
jrose@710 983 }
jrose@710 984 m->set_constants(cp());
jrose@710 985 m->set_name_index(_imcp_invoke_name);
jrose@710 986 m->set_signature_index(_imcp_invoke_signature);
jrose@1427 987 assert(is_method_handle_invoke_name(m->name()), "");
coleenp@2062 988 assert(m->signature() == signature, "");
jrose@1713 989 assert(m->is_method_handle_invoke(), "");
jrose@710 990 #ifdef CC_INTERP
twisti@2128 991 ResultTypeFinder rtf(signature);
jrose@710 992 m->set_result_index(rtf.type());
jrose@710 993 #endif
jrose@710 994 m->compute_size_of_parameters(THREAD);
jrose@710 995 m->set_exception_table(Universe::the_empty_int_array());
jrose@1713 996 m->init_intrinsic_id();
jrose@1713 997 assert(m->intrinsic_id() == vmIntrinsics::_invokeExact ||
jrose@1713 998 m->intrinsic_id() == vmIntrinsics::_invokeGeneric, "must be an invoker");
jrose@710 999
jrose@710 1000 // Finally, set up its entry points.
jrose@710 1001 assert(m->method_handle_type() == method_type(), "");
jrose@710 1002 assert(m->can_be_statically_bound(), "");
jrose@710 1003 m->set_vtable_index(methodOopDesc::nonvirtual_vtable_index);
jrose@710 1004 m->link_method(m, CHECK_(empty));
jrose@710 1005
jrose@710 1006 #ifdef ASSERT
jrose@710 1007 // Make sure the pointer chase works.
jrose@710 1008 address p = (address) m();
jrose@710 1009 for (jint* pchase = method_type_offsets_chain(); (*pchase) != -1; pchase++) {
jrose@710 1010 p = *(address*)(p + (*pchase));
jrose@710 1011 }
jrose@710 1012 assert((oop)p == method_type(), "pointer chase is correct");
jrose@710 1013 #endif
jrose@710 1014
jrose@1039 1015 if (TraceMethodHandles && (Verbose || WizardMode))
jrose@710 1016 m->print_on(tty);
jrose@710 1017
jrose@710 1018 return m;
jrose@710 1019 }
jrose@710 1020
jrose@2547 1021 klassOop methodOopDesc::check_non_bcp_klass(klassOop klass) {
jrose@2547 1022 if (klass != NULL && Klass::cast(klass)->class_loader() != NULL) {
jrose@2547 1023 if (Klass::cast(klass)->oop_is_objArray())
jrose@2547 1024 klass = objArrayKlass::cast(klass)->bottom_klass();
jrose@2547 1025 return klass;
jrose@2547 1026 }
jrose@2547 1027 return NULL;
jrose@2547 1028 }
jrose@710 1029
dcubed@48 1030
duke@0 1031 methodHandle methodOopDesc:: clone_with_new_data(methodHandle m, u_char* new_code, int new_code_length,
duke@0 1032 u_char* new_compressed_linenumber_table, int new_compressed_linenumber_size, TRAPS) {
duke@0 1033 // Code below does not work for native methods - they should never get rewritten anyway
duke@0 1034 assert(!m->is_native(), "cannot rewrite native methods");
duke@0 1035 // Allocate new methodOop
duke@0 1036 AccessFlags flags = m->access_flags();
duke@0 1037 int checked_exceptions_len = m->checked_exceptions_length();
duke@0 1038 int localvariable_len = m->localvariable_table_length();
jmasa@518 1039 // Allocate newm_oop with the is_conc_safe parameter set
jmasa@518 1040 // to IsUnsafeConc to indicate that newm_oop is not yet
jmasa@518 1041 // safe for concurrent processing by a GC.
jmasa@518 1042 methodOop newm_oop = oopFactory::new_method(new_code_length,
jmasa@518 1043 flags,
jmasa@518 1044 new_compressed_linenumber_size,
jmasa@518 1045 localvariable_len,
jmasa@518 1046 checked_exceptions_len,
jmasa@518 1047 IsUnsafeConc,
jmasa@518 1048 CHECK_(methodHandle()));
duke@0 1049 methodHandle newm (THREAD, newm_oop);
ysr@2098 1050 NOT_PRODUCT(int nmsz = newm->is_parsable() ? newm->size() : -1;)
duke@0 1051 int new_method_size = newm->method_size();
duke@0 1052 // Create a shallow copy of methodOopDesc part, but be careful to preserve the new constMethodOop
duke@0 1053 constMethodOop newcm = newm->constMethod();
ysr@2098 1054 NOT_PRODUCT(int ncmsz = newcm->is_parsable() ? newcm->size() : -1;)
duke@0 1055 int new_const_method_size = newm->constMethod()->object_size();
jmasa@518 1056
duke@0 1057 memcpy(newm(), m(), sizeof(methodOopDesc));
duke@0 1058 // Create shallow copy of constMethodOopDesc, but be careful to preserve the methodOop
jmasa@518 1059 // is_conc_safe is set to false because that is the value of
jmasa@518 1060 // is_conc_safe initialzied into newcm and the copy should
jmasa@518 1061 // not overwrite that value. During the window during which it is
jmasa@518 1062 // tagged as unsafe, some extra work could be needed during precleaning
jmasa@518 1063 // or concurrent marking but those phases will be correct. Setting and
jmasa@518 1064 // resetting is done in preference to a careful copying into newcm to
jmasa@518 1065 // avoid having to know the precise layout of a constMethodOop.
ysr@2098 1066 m->constMethod()->set_is_conc_safe(oopDesc::IsUnsafeConc);
ysr@2098 1067 assert(m->constMethod()->is_parsable(), "Should remain parsable");
ysr@2098 1068
ysr@2098 1069 // NOTE: this is a reachable object that transiently signals "conc_unsafe"
ysr@2098 1070 // However, no allocations are done during this window
ysr@2098 1071 // during which it is tagged conc_unsafe, so we are assured that any concurrent
ysr@2098 1072 // thread will not wait forever for the object to revert to "conc_safe".
ysr@2098 1073 // Further, any such conc_unsafe object will indicate a stable size
ysr@2098 1074 // through the transition.
duke@0 1075 memcpy(newcm, m->constMethod(), sizeof(constMethodOopDesc));
ysr@2098 1076 m->constMethod()->set_is_conc_safe(oopDesc::IsSafeConc);
ysr@2098 1077 assert(m->constMethod()->is_parsable(), "Should remain parsable");
ysr@2098 1078
duke@0 1079 // Reset correct method/const method, method size, and parameter info
duke@0 1080 newcm->set_method(newm());
duke@0 1081 newm->set_constMethod(newcm);
duke@0 1082 assert(newcm->method() == newm(), "check");
duke@0 1083 newm->constMethod()->set_code_size(new_code_length);
duke@0 1084 newm->constMethod()->set_constMethod_size(new_const_method_size);
duke@0 1085 newm->set_method_size(new_method_size);
duke@0 1086 assert(newm->code_size() == new_code_length, "check");
duke@0 1087 assert(newm->checked_exceptions_length() == checked_exceptions_len, "check");
duke@0 1088 assert(newm->localvariable_table_length() == localvariable_len, "check");
duke@0 1089 // Copy new byte codes
duke@0 1090 memcpy(newm->code_base(), new_code, new_code_length);
duke@0 1091 // Copy line number table
duke@0 1092 if (new_compressed_linenumber_size > 0) {
duke@0 1093 memcpy(newm->compressed_linenumber_table(),
duke@0 1094 new_compressed_linenumber_table,
duke@0 1095 new_compressed_linenumber_size);
duke@0 1096 }
duke@0 1097 // Copy checked_exceptions
duke@0 1098 if (checked_exceptions_len > 0) {
duke@0 1099 memcpy(newm->checked_exceptions_start(),
duke@0 1100 m->checked_exceptions_start(),
duke@0 1101 checked_exceptions_len * sizeof(CheckedExceptionElement));
duke@0 1102 }
duke@0 1103 // Copy local variable number table
duke@0 1104 if (localvariable_len > 0) {
duke@0 1105 memcpy(newm->localvariable_table_start(),
duke@0 1106 m->localvariable_table_start(),
duke@0 1107 localvariable_len * sizeof(LocalVariableTableElement));
duke@0 1108 }
jmasa@518 1109
jmasa@518 1110 // Only set is_conc_safe to true when changes to newcm are
jmasa@518 1111 // complete.
ysr@2098 1112 assert(!newm->is_parsable() || nmsz < 0 || newm->size() == nmsz, "newm->size() inconsistency");
ysr@2098 1113 assert(!newcm->is_parsable() || ncmsz < 0 || newcm->size() == ncmsz, "newcm->size() inconsistency");
jmasa@518 1114 newcm->set_is_conc_safe(true);
duke@0 1115 return newm;
duke@0 1116 }
duke@0 1117
jrose@856 1118 vmSymbols::SID methodOopDesc::klass_id_for_intrinsics(klassOop holder) {
duke@0 1119 // if loader is not the default loader (i.e., != NULL), we can't know the intrinsics
duke@0 1120 // because we are not loading from core libraries
jrose@856 1121 if (instanceKlass::cast(holder)->class_loader() != NULL)
jrose@856 1122 return vmSymbols::NO_SID; // regardless of name, no intrinsics here
duke@0 1123
duke@0 1124 // see if the klass name is well-known:
coleenp@2062 1125 Symbol* klass_name = instanceKlass::cast(holder)->name();
jrose@856 1126 return vmSymbols::find_sid(klass_name);
jrose@856 1127 }
jrose@856 1128
jrose@856 1129 void methodOopDesc::init_intrinsic_id() {
jrose@856 1130 assert(_intrinsic_id == vmIntrinsics::_none, "do this just once");
jrose@856 1131 const uintptr_t max_id_uint = right_n_bits((int)(sizeof(_intrinsic_id) * BitsPerByte));
jrose@856 1132 assert((uintptr_t)vmIntrinsics::ID_LIMIT <= max_id_uint, "else fix size");
jrose@1713 1133 assert(intrinsic_id_size_in_bytes() == sizeof(_intrinsic_id), "");
jrose@856 1134
jrose@856 1135 // the klass name is well-known:
jrose@856 1136 vmSymbols::SID klass_id = klass_id_for_intrinsics(method_holder());
jrose@856 1137 assert(klass_id != vmSymbols::NO_SID, "caller responsibility");
duke@0 1138
duke@0 1139 // ditto for method and signature:
duke@0 1140 vmSymbols::SID name_id = vmSymbols::find_sid(name());
jrose@1713 1141 if (name_id == vmSymbols::NO_SID) return;
duke@0 1142 vmSymbols::SID sig_id = vmSymbols::find_sid(signature());
jrose@2204 1143 if (klass_id != vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_MethodHandle)
jrose@1713 1144 && sig_id == vmSymbols::NO_SID) return;
duke@0 1145 jshort flags = access_flags().as_short();
duke@0 1146
jrose@856 1147 vmIntrinsics::ID id = vmIntrinsics::find_id(klass_id, name_id, sig_id, flags);
jrose@856 1148 if (id != vmIntrinsics::_none) {
jrose@856 1149 set_intrinsic_id(id);
jrose@856 1150 return;
jrose@856 1151 }
jrose@856 1152
duke@0 1153 // A few slightly irregular cases:
duke@0 1154 switch (klass_id) {
duke@0 1155 case vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_StrictMath):
duke@0 1156 // Second chance: check in regular Math.
duke@0 1157 switch (name_id) {
duke@0 1158 case vmSymbols::VM_SYMBOL_ENUM_NAME(min_name):
duke@0 1159 case vmSymbols::VM_SYMBOL_ENUM_NAME(max_name):
duke@0 1160 case vmSymbols::VM_SYMBOL_ENUM_NAME(sqrt_name):
duke@0 1161 // pretend it is the corresponding method in the non-strict class:
duke@0 1162 klass_id = vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_Math);
jrose@856 1163 id = vmIntrinsics::find_id(klass_id, name_id, sig_id, flags);
duke@0 1164 break;
duke@0 1165 }
jrose@1427 1166 break;
jrose@1427 1167
jrose@1427 1168 // Signature-polymorphic methods: MethodHandle.invoke*, InvokeDynamic.*.
jrose@2204 1169 case vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_MethodHandle):
jrose@1427 1170 if (is_static() || !is_native()) break;
jrose@1427 1171 switch (name_id) {
jrose@1427 1172 case vmSymbols::VM_SYMBOL_ENUM_NAME(invokeGeneric_name):
jrose@2307 1173 if (!AllowInvokeGeneric) break;
jrose@2307 1174 case vmSymbols::VM_SYMBOL_ENUM_NAME(invoke_name):
jrose@1713 1175 id = vmIntrinsics::_invokeGeneric;
jrose@1713 1176 break;
jrose@1713 1177 case vmSymbols::VM_SYMBOL_ENUM_NAME(invokeExact_name):
jrose@1713 1178 id = vmIntrinsics::_invokeExact;
jrose@1713 1179 break;
jrose@1427 1180 }
jrose@1427 1181 break;
jrose@2204 1182 case vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_InvokeDynamic):
jrose@1427 1183 if (!is_static() || !is_native()) break;
jrose@1427 1184 id = vmIntrinsics::_invokeDynamic;
jrose@1427 1185 break;
duke@0 1186 }
duke@0 1187
jrose@856 1188 if (id != vmIntrinsics::_none) {
jrose@856 1189 // Set up its iid. It is an alias method.
jrose@856 1190 set_intrinsic_id(id);
jrose@856 1191 return;
jrose@856 1192 }
duke@0 1193 }
duke@0 1194
duke@0 1195 // These two methods are static since a GC may move the methodOopDesc
duke@0 1196 bool methodOopDesc::load_signature_classes(methodHandle m, TRAPS) {
duke@0 1197 bool sig_is_loaded = true;
duke@0 1198 Handle class_loader(THREAD, instanceKlass::cast(m->method_holder())->class_loader());
duke@0 1199 Handle protection_domain(THREAD, Klass::cast(m->method_holder())->protection_domain());
coleenp@2062 1200 ResourceMark rm(THREAD);
coleenp@2062 1201 Symbol* signature = m->signature();
duke@0 1202 for(SignatureStream ss(signature); !ss.is_done(); ss.next()) {
duke@0 1203 if (ss.is_object()) {
coleenp@2062 1204 Symbol* sym = ss.as_symbol(CHECK_(false));
coleenp@2062 1205 Symbol* name = sym;
duke@0 1206 klassOop klass = SystemDictionary::resolve_or_null(name, class_loader,
duke@0 1207 protection_domain, THREAD);
rasbold@104 1208 // We are loading classes eagerly. If a ClassNotFoundException or
rasbold@104 1209 // a LinkageError was generated, be sure to ignore it.
duke@0 1210 if (HAS_PENDING_EXCEPTION) {
never@1142 1211 if (PENDING_EXCEPTION->is_a(SystemDictionary::ClassNotFoundException_klass()) ||
never@1142 1212 PENDING_EXCEPTION->is_a(SystemDictionary::LinkageError_klass())) {
duke@0 1213 CLEAR_PENDING_EXCEPTION;
duke@0 1214 } else {
duke@0 1215 return false;
duke@0 1216 }
duke@0 1217 }
duke@0 1218 if( klass == NULL) { sig_is_loaded = false; }
duke@0 1219 }
duke@0 1220 }
duke@0 1221 return sig_is_loaded;
duke@0 1222 }
duke@0 1223
duke@0 1224 bool methodOopDesc::has_unloaded_classes_in_signature(methodHandle m, TRAPS) {
duke@0 1225 Handle class_loader(THREAD, instanceKlass::cast(m->method_holder())->class_loader());
duke@0 1226 Handle protection_domain(THREAD, Klass::cast(m->method_holder())->protection_domain());
coleenp@2062 1227 ResourceMark rm(THREAD);
coleenp@2062 1228 Symbol* signature = m->signature();
duke@0 1229 for(SignatureStream ss(signature); !ss.is_done(); ss.next()) {
duke@0 1230 if (ss.type() == T_OBJECT) {
coleenp@2062 1231 Symbol* name = ss.as_symbol_or_null();
coleenp@2062 1232 if (name == NULL) return true;
duke@0 1233 klassOop klass = SystemDictionary::find(name, class_loader, protection_domain, THREAD);
duke@0 1234 if (klass == NULL) return true;
duke@0 1235 }
duke@0 1236 }
duke@0 1237 return false;
duke@0 1238 }
duke@0 1239
duke@0 1240 // Exposed so field engineers can debug VM
duke@0 1241 void methodOopDesc::print_short_name(outputStream* st) {
duke@0 1242 ResourceMark rm;
duke@0 1243 #ifdef PRODUCT
duke@0 1244 st->print(" %s::", method_holder()->klass_part()->external_name());
duke@0 1245 #else
duke@0 1246 st->print(" %s::", method_holder()->klass_part()->internal_name());
duke@0 1247 #endif
duke@0 1248 name()->print_symbol_on(st);
duke@0 1249 if (WizardMode) signature()->print_symbol_on(st);
duke@0 1250 }
duke@0 1251
duke@0 1252 // This is only done during class loading, so it is OK to assume method_idnum matches the methods() array
duke@0 1253 static void reorder_based_on_method_index(objArrayOop methods,
duke@0 1254 objArrayOop annotations,
coleenp@113 1255 GrowableArray<oop>* temp_array) {
duke@0 1256 if (annotations == NULL) {
duke@0 1257 return;
duke@0 1258 }
duke@0 1259
duke@0 1260 int length = methods->length();
duke@0 1261 int i;
duke@0 1262 // Copy to temp array
coleenp@113 1263 temp_array->clear();
coleenp@113 1264 for (i = 0; i < length; i++) {
coleenp@113 1265 temp_array->append(annotations->obj_at(i));
coleenp@113 1266 }
duke@0 1267
duke@0 1268 // Copy back using old method indices
duke@0 1269 for (i = 0; i < length; i++) {
duke@0 1270 methodOop m = (methodOop) methods->obj_at(i);
coleenp@113 1271 annotations->obj_at_put(i, temp_array->at(m->method_idnum()));
duke@0 1272 }
duke@0 1273 }
duke@0 1274
brutisso@2541 1275 // Comparer for sorting an object array containing
brutisso@2541 1276 // methodOops.
kvn@2693 1277 // Used non-template method_comparator methods since
kvn@2693 1278 // Visual Studio 2003 compiler generates incorrect
kvn@2693 1279 // optimized code for it.
kvn@2693 1280 static int method_comparator_narrowOop(narrowOop a, narrowOop b) {
brutisso@2541 1281 methodOop m = (methodOop)oopDesc::decode_heap_oop_not_null(a);
brutisso@2541 1282 methodOop n = (methodOop)oopDesc::decode_heap_oop_not_null(b);
brutisso@2541 1283 return m->name()->fast_compare(n->name());
brutisso@2541 1284 }
kvn@2693 1285 static int method_comparator_oop(oop a, oop b) {
kvn@2693 1286 methodOop m = (methodOop)a;
kvn@2693 1287 methodOop n = (methodOop)b;
kvn@2693 1288 return m->name()->fast_compare(n->name());
kvn@2693 1289 }
duke@0 1290
duke@0 1291 // This is only done during class loading, so it is OK to assume method_idnum matches the methods() array
duke@0 1292 void methodOopDesc::sort_methods(objArrayOop methods,
duke@0 1293 objArrayOop methods_annotations,
duke@0 1294 objArrayOop methods_parameter_annotations,
duke@0 1295 objArrayOop methods_default_annotations,
duke@0 1296 bool idempotent) {
duke@0 1297 int length = methods->length();
duke@0 1298 if (length > 1) {
duke@0 1299 bool do_annotations = false;
duke@0 1300 if (methods_annotations != NULL ||
duke@0 1301 methods_parameter_annotations != NULL ||
duke@0 1302 methods_default_annotations != NULL) {
duke@0 1303 do_annotations = true;
duke@0 1304 }
duke@0 1305 if (do_annotations) {
duke@0 1306 // Remember current method ordering so we can reorder annotations
duke@0 1307 for (int i = 0; i < length; i++) {
duke@0 1308 methodOop m = (methodOop) methods->obj_at(i);
duke@0 1309 m->set_method_idnum(i);
duke@0 1310 }
duke@0 1311 }
brutisso@2541 1312 {
brutisso@2541 1313 No_Safepoint_Verifier nsv;
brutisso@2541 1314 if (UseCompressedOops) {
kvn@2693 1315 QuickSort::sort<narrowOop>((narrowOop*)(methods->base()), length, method_comparator_narrowOop, idempotent);
brutisso@2541 1316 } else {
kvn@2693 1317 QuickSort::sort<oop>((oop*)(methods->base()), length, method_comparator_oop, idempotent);
duke@0 1318 }
brutisso@2541 1319 if (UseConcMarkSweepGC) {
brutisso@2541 1320 // For CMS we need to dirty the cards for the array
brutisso@2541 1321 BarrierSet* bs = Universe::heap()->barrier_set();
brutisso@2541 1322 assert(bs->has_write_ref_array_opt(), "Barrier set must have ref array opt");
brutisso@2541 1323 bs->write_ref_array(methods->base(), length);
brutisso@2541 1324 }
duke@0 1325 }
duke@0 1326
duke@0 1327 // Sort annotations if necessary
duke@0 1328 assert(methods_annotations == NULL || methods_annotations->length() == methods->length(), "");
duke@0 1329 assert(methods_parameter_annotations == NULL || methods_parameter_annotations->length() == methods->length(), "");
duke@0 1330 assert(methods_default_annotations == NULL || methods_default_annotations->length() == methods->length(), "");
duke@0 1331 if (do_annotations) {
coleenp@113 1332 ResourceMark rm;
duke@0 1333 // Allocate temporary storage
coleenp@113 1334 GrowableArray<oop>* temp_array = new GrowableArray<oop>(length);
duke@0 1335 reorder_based_on_method_index(methods, methods_annotations, temp_array);
duke@0 1336 reorder_based_on_method_index(methods, methods_parameter_annotations, temp_array);
duke@0 1337 reorder_based_on_method_index(methods, methods_default_annotations, temp_array);
duke@0 1338 }
duke@0 1339
duke@0 1340 // Reset method ordering
duke@0 1341 for (int i = 0; i < length; i++) {
duke@0 1342 methodOop m = (methodOop) methods->obj_at(i);
duke@0 1343 m->set_method_idnum(i);
duke@0 1344 }
duke@0 1345 }
duke@0 1346 }
duke@0 1347
duke@0 1348
duke@0 1349 //-----------------------------------------------------------------------------------
duke@0 1350 // Non-product code
duke@0 1351
duke@0 1352 #ifndef PRODUCT
duke@0 1353 class SignatureTypePrinter : public SignatureTypeNames {
duke@0 1354 private:
duke@0 1355 outputStream* _st;
duke@0 1356 bool _use_separator;
duke@0 1357
duke@0 1358 void type_name(const char* name) {
duke@0 1359 if (_use_separator) _st->print(", ");
duke@0 1360 _st->print(name);
duke@0 1361 _use_separator = true;
duke@0 1362 }
duke@0 1363
duke@0 1364 public:
coleenp@2062 1365 SignatureTypePrinter(Symbol* signature, outputStream* st) : SignatureTypeNames(signature) {
duke@0 1366 _st = st;
duke@0 1367 _use_separator = false;
duke@0 1368 }
duke@0 1369
duke@0 1370 void print_parameters() { _use_separator = false; iterate_parameters(); }
duke@0 1371 void print_returntype() { _use_separator = false; iterate_returntype(); }
duke@0 1372 };
duke@0 1373
duke@0 1374
duke@0 1375 void methodOopDesc::print_name(outputStream* st) {
duke@0 1376 Thread *thread = Thread::current();
duke@0 1377 ResourceMark rm(thread);
duke@0 1378 SignatureTypePrinter sig(signature(), st);
duke@0 1379 st->print("%s ", is_static() ? "static" : "virtual");
duke@0 1380 sig.print_returntype();
duke@0 1381 st->print(" %s.", method_holder()->klass_part()->internal_name());
duke@0 1382 name()->print_symbol_on(st);
duke@0 1383 st->print("(");
duke@0 1384 sig.print_parameters();
duke@0 1385 st->print(")");
duke@0 1386 }
duke@0 1387
duke@0 1388
duke@0 1389 void methodOopDesc::print_codes_on(outputStream* st) const {
duke@0 1390 print_codes_on(0, code_size(), st);
duke@0 1391 }
duke@0 1392
duke@0 1393 void methodOopDesc::print_codes_on(int from, int to, outputStream* st) const {
duke@0 1394 Thread *thread = Thread::current();
duke@0 1395 ResourceMark rm(thread);
duke@0 1396 methodHandle mh (thread, (methodOop)this);
duke@0 1397 BytecodeStream s(mh);
duke@0 1398 s.set_interval(from, to);
duke@0 1399 BytecodeTracer::set_closure(BytecodeTracer::std_closure());
duke@0 1400 while (s.next() >= 0) BytecodeTracer::trace(mh, s.bcp(), st);
duke@0 1401 }
duke@0 1402 #endif // not PRODUCT
duke@0 1403
duke@0 1404
duke@0 1405 // Simple compression of line number tables. We use a regular compressed stream, except that we compress deltas
duke@0 1406 // between (bci,line) pairs since they are smaller. If (bci delta, line delta) fits in (5-bit unsigned, 3-bit unsigned)
duke@0 1407 // we save it as one byte, otherwise we write a 0xFF escape character and use regular compression. 0x0 is used
duke@0 1408 // as end-of-stream terminator.
duke@0 1409
duke@0 1410 void CompressedLineNumberWriteStream::write_pair_regular(int bci_delta, int line_delta) {
duke@0 1411 // bci and line number does not compress into single byte.
duke@0 1412 // Write out escape character and use regular compression for bci and line number.
duke@0 1413 write_byte((jubyte)0xFF);
duke@0 1414 write_signed_int(bci_delta);
duke@0 1415 write_signed_int(line_delta);
duke@0 1416 }
duke@0 1417
duke@0 1418 // See comment in methodOop.hpp which explains why this exists.
sla@2105 1419 #if defined(_M_AMD64) && _MSC_VER >= 1400
duke@0 1420 #pragma optimize("", off)
duke@0 1421 void CompressedLineNumberWriteStream::write_pair(int bci, int line) {
duke@0 1422 write_pair_inline(bci, line);
duke@0 1423 }
duke@0 1424 #pragma optimize("", on)
duke@0 1425 #endif
duke@0 1426
duke@0 1427 CompressedLineNumberReadStream::CompressedLineNumberReadStream(u_char* buffer) : CompressedReadStream(buffer) {
duke@0 1428 _bci = 0;
duke@0 1429 _line = 0;
duke@0 1430 };
duke@0 1431
duke@0 1432
duke@0 1433 bool CompressedLineNumberReadStream::read_pair() {
duke@0 1434 jubyte next = read_byte();
duke@0 1435 // Check for terminator
duke@0 1436 if (next == 0) return false;
duke@0 1437 if (next == 0xFF) {
duke@0 1438 // Escape character, regular compression used
duke@0 1439 _bci += read_signed_int();
duke@0 1440 _line += read_signed_int();
duke@0 1441 } else {
duke@0 1442 // Single byte compression used
duke@0 1443 _bci += next >> 3;
duke@0 1444 _line += next & 0x7;
duke@0 1445 }
duke@0 1446 return true;
duke@0 1447 }
duke@0 1448
duke@0 1449
never@2027 1450 Bytecodes::Code methodOopDesc::orig_bytecode_at(int bci) const {
duke@0 1451 BreakpointInfo* bp = instanceKlass::cast(method_holder())->breakpoints();
duke@0 1452 for (; bp != NULL; bp = bp->next()) {
duke@0 1453 if (bp->match(this, bci)) {
duke@0 1454 return bp->orig_bytecode();
duke@0 1455 }
duke@0 1456 }
duke@0 1457 ShouldNotReachHere();
duke@0 1458 return Bytecodes::_shouldnotreachhere;
duke@0 1459 }
duke@0 1460
duke@0 1461 void methodOopDesc::set_orig_bytecode_at(int bci, Bytecodes::Code code) {
duke@0 1462 assert(code != Bytecodes::_breakpoint, "cannot patch breakpoints this way");
duke@0 1463 BreakpointInfo* bp = instanceKlass::cast(method_holder())->breakpoints();
duke@0 1464 for (; bp != NULL; bp = bp->next()) {
duke@0 1465 if (bp->match(this, bci)) {
duke@0 1466 bp->set_orig_bytecode(code);
duke@0 1467 // and continue, in case there is more than one
duke@0 1468 }
duke@0 1469 }
duke@0 1470 }
duke@0 1471
duke@0 1472 void methodOopDesc::set_breakpoint(int bci) {
duke@0 1473 instanceKlass* ik = instanceKlass::cast(method_holder());
duke@0 1474 BreakpointInfo *bp = new BreakpointInfo(this, bci);
duke@0 1475 bp->set_next(ik->breakpoints());
duke@0 1476 ik->set_breakpoints(bp);
duke@0 1477 // do this last:
duke@0 1478 bp->set(this);
duke@0 1479 }
duke@0 1480
duke@0 1481 static void clear_matches(methodOop m, int bci) {
duke@0 1482 instanceKlass* ik = instanceKlass::cast(m->method_holder());
duke@0 1483 BreakpointInfo* prev_bp = NULL;
duke@0 1484 BreakpointInfo* next_bp;
duke@0 1485 for (BreakpointInfo* bp = ik->breakpoints(); bp != NULL; bp = next_bp) {
duke@0 1486 next_bp = bp->next();
duke@0 1487 // bci value of -1 is used to delete all breakpoints in method m (ex: clear_all_breakpoint).
duke@0 1488 if (bci >= 0 ? bp->match(m, bci) : bp->match(m)) {
duke@0 1489 // do this first:
duke@0 1490 bp->clear(m);
duke@0 1491 // unhook it
duke@0 1492 if (prev_bp != NULL)
duke@0 1493 prev_bp->set_next(next_bp);
duke@0 1494 else
duke@0 1495 ik->set_breakpoints(next_bp);
duke@0 1496 delete bp;
duke@0 1497 // When class is redefined JVMTI sets breakpoint in all versions of EMCP methods
duke@0 1498 // at same location. So we have multiple matching (method_index and bci)
duke@0 1499 // BreakpointInfo nodes in BreakpointInfo list. We should just delete one
duke@0 1500 // breakpoint for clear_breakpoint request and keep all other method versions
duke@0 1501 // BreakpointInfo for future clear_breakpoint request.
duke@0 1502 // bcivalue of -1 is used to clear all breakpoints (see clear_all_breakpoints)
duke@0 1503 // which is being called when class is unloaded. We delete all the Breakpoint
duke@0 1504 // information for all versions of method. We may not correctly restore the original
duke@0 1505 // bytecode in all method versions, but that is ok. Because the class is being unloaded
duke@0 1506 // so these methods won't be used anymore.
duke@0 1507 if (bci >= 0) {
duke@0 1508 break;
duke@0 1509 }
duke@0 1510 } else {
duke@0 1511 // This one is a keeper.
duke@0 1512 prev_bp = bp;
duke@0 1513 }
duke@0 1514 }
duke@0 1515 }
duke@0 1516
duke@0 1517 void methodOopDesc::clear_breakpoint(int bci) {
duke@0 1518 assert(bci >= 0, "");
duke@0 1519 clear_matches(this, bci);
duke@0 1520 }
duke@0 1521
duke@0 1522 void methodOopDesc::clear_all_breakpoints() {
duke@0 1523 clear_matches(this, -1);
duke@0 1524 }
duke@0 1525
duke@0 1526
iveresov@1703 1527 int methodOopDesc::invocation_count() {
iveresov@1703 1528 if (TieredCompilation) {
iveresov@1703 1529 const methodDataOop mdo = method_data();
iveresov@1703 1530 if (invocation_counter()->carry() || ((mdo != NULL) ? mdo->invocation_counter()->carry() : false)) {
iveresov@1703 1531 return InvocationCounter::count_limit;
iveresov@1703 1532 } else {
iveresov@1703 1533 return invocation_counter()->count() + ((mdo != NULL) ? mdo->invocation_counter()->count() : 0);
iveresov@1703 1534 }
iveresov@1703 1535 } else {
iveresov@1703 1536 return invocation_counter()->count();
iveresov@1703 1537 }
iveresov@1703 1538 }
iveresov@1703 1539
iveresov@1703 1540 int methodOopDesc::backedge_count() {
iveresov@1703 1541 if (TieredCompilation) {
iveresov@1703 1542 const methodDataOop mdo = method_data();
iveresov@1703 1543 if (backedge_counter()->carry() || ((mdo != NULL) ? mdo->backedge_counter()->carry() : false)) {
iveresov@1703 1544 return InvocationCounter::count_limit;
iveresov@1703 1545 } else {
iveresov@1703 1546 return backedge_counter()->count() + ((mdo != NULL) ? mdo->backedge_counter()->count() : 0);
iveresov@1703 1547 }
iveresov@1703 1548 } else {
iveresov@1703 1549 return backedge_counter()->count();
iveresov@1703 1550 }
iveresov@1703 1551 }
iveresov@1703 1552
iveresov@1703 1553 int methodOopDesc::highest_comp_level() const {
iveresov@1703 1554 methodDataOop mdo = method_data();
iveresov@1703 1555 if (mdo != NULL) {
iveresov@1703 1556 return mdo->highest_comp_level();
iveresov@1703 1557 } else {
iveresov@1703 1558 return CompLevel_none;
iveresov@1703 1559 }
iveresov@1703 1560 }
iveresov@1703 1561
iveresov@1703 1562 int methodOopDesc::highest_osr_comp_level() const {
iveresov@1703 1563 methodDataOop mdo = method_data();
iveresov@1703 1564 if (mdo != NULL) {
iveresov@1703 1565 return mdo->highest_osr_comp_level();
iveresov@1703 1566 } else {
iveresov@1703 1567 return CompLevel_none;
iveresov@1703 1568 }
iveresov@1703 1569 }
iveresov@1703 1570
iveresov@1703 1571 void methodOopDesc::set_highest_comp_level(int level) {
iveresov@1703 1572 methodDataOop mdo = method_data();
iveresov@1703 1573 if (mdo != NULL) {
iveresov@1703 1574 mdo->set_highest_comp_level(level);
iveresov@1703 1575 }
iveresov@1703 1576 }
iveresov@1703 1577
iveresov@1703 1578 void methodOopDesc::set_highest_osr_comp_level(int level) {
iveresov@1703 1579 methodDataOop mdo = method_data();
iveresov@1703 1580 if (mdo != NULL) {
iveresov@1703 1581 mdo->set_highest_osr_comp_level(level);
iveresov@1703 1582 }
iveresov@1703 1583 }
iveresov@1703 1584
duke@0 1585 BreakpointInfo::BreakpointInfo(methodOop m, int bci) {
duke@0 1586 _bci = bci;
duke@0 1587 _name_index = m->name_index();
duke@0 1588 _signature_index = m->signature_index();
duke@0 1589 _orig_bytecode = (Bytecodes::Code) *m->bcp_from(_bci);
duke@0 1590 if (_orig_bytecode == Bytecodes::_breakpoint)
duke@0 1591 _orig_bytecode = m->orig_bytecode_at(_bci);
duke@0 1592 _next = NULL;
duke@0 1593 }
duke@0 1594
duke@0 1595 void BreakpointInfo::set(methodOop method) {
duke@0 1596 #ifdef ASSERT
duke@0 1597 {
duke@0 1598 Bytecodes::Code code = (Bytecodes::Code) *method->bcp_from(_bci);
duke@0 1599 if (code == Bytecodes::_breakpoint)
duke@0 1600 code = method->orig_bytecode_at(_bci);
duke@0 1601 assert(orig_bytecode() == code, "original bytecode must be the same");
duke@0 1602 }
duke@0 1603 #endif
duke@0 1604 *method->bcp_from(_bci) = Bytecodes::_breakpoint;
duke@0 1605 method->incr_number_of_breakpoints();
duke@0 1606 SystemDictionary::notice_modification();
duke@0 1607 {
duke@0 1608 // Deoptimize all dependents on this method
duke@0 1609 Thread *thread = Thread::current();
duke@0 1610 HandleMark hm(thread);
duke@0 1611 methodHandle mh(thread, method);
duke@0 1612 Universe::flush_dependents_on_method(mh);
duke@0 1613 }
duke@0 1614 }
duke@0 1615
duke@0 1616 void BreakpointInfo::clear(methodOop method) {
duke@0 1617 *method->bcp_from(_bci) = orig_bytecode();
duke@0 1618 assert(method->number_of_breakpoints() > 0, "must not go negative");
duke@0 1619 method->decr_number_of_breakpoints();
duke@0 1620 }