src/share/vm/oops/methodOop.cpp

Fri, 08 Jan 2010 11:09:46 +0100

author
twisti
date
Fri, 08 Jan 2010 11:09:46 +0100
changeset 1587
cd37471eaecc
parent 1577
4ce7240d622c
child 1622
cf0685d550f1
permissions
-rw-r--r--

6914206: change way of permission checking for generated MethodHandle adapters
Summary: Put generated MH adapter in InvokeDynamic/MethodHandle classes to be able to indentify them easily in the compiler.
Reviewed-by: kvn, never, jrose

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

mercurial