Wed, 01 May 2013 08:07:59 -0700
8013418: assert(i == total_args_passed) in AdapterHandlerLibrary::get_adapter since 8-b87
Summary: Do not treat static methods as miranda methods.
Reviewed-by: dholmes, acorn
duke@435 | 1 | /* |
coleenp@4490 | 2 | * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #include "precompiled.hpp" |
coleenp@4490 | 26 | #include "classfile/metadataOnStackMark.hpp" |
stefank@2314 | 27 | #include "classfile/systemDictionary.hpp" |
stefank@2314 | 28 | #include "code/debugInfoRec.hpp" |
stefank@2314 | 29 | #include "gc_interface/collectedHeap.inline.hpp" |
stefank@2314 | 30 | #include "interpreter/bytecodeStream.hpp" |
stefank@2314 | 31 | #include "interpreter/bytecodeTracer.hpp" |
stefank@2314 | 32 | #include "interpreter/bytecodes.hpp" |
stefank@2314 | 33 | #include "interpreter/interpreter.hpp" |
stefank@2314 | 34 | #include "interpreter/oopMapCache.hpp" |
stefank@2314 | 35 | #include "memory/gcLocker.hpp" |
stefank@2314 | 36 | #include "memory/generation.hpp" |
acorn@4497 | 37 | #include "memory/heapInspection.hpp" |
coleenp@4037 | 38 | #include "memory/metadataFactory.hpp" |
stefank@2314 | 39 | #include "memory/oopFactory.hpp" |
kamg@4245 | 40 | #include "oops/constMethod.hpp" |
coleenp@4037 | 41 | #include "oops/methodData.hpp" |
coleenp@4037 | 42 | #include "oops/method.hpp" |
stefank@2314 | 43 | #include "oops/oop.inline.hpp" |
coleenp@2497 | 44 | #include "oops/symbol.hpp" |
stefank@2314 | 45 | #include "prims/jvmtiExport.hpp" |
twisti@3969 | 46 | #include "prims/methodHandles.hpp" |
stefank@2314 | 47 | #include "prims/nativeLookup.hpp" |
stefank@2314 | 48 | #include "runtime/arguments.hpp" |
stefank@2314 | 49 | #include "runtime/compilationPolicy.hpp" |
stefank@2314 | 50 | #include "runtime/frame.inline.hpp" |
stefank@2314 | 51 | #include "runtime/handles.inline.hpp" |
stefank@2314 | 52 | #include "runtime/relocator.hpp" |
stefank@2314 | 53 | #include "runtime/sharedRuntime.hpp" |
stefank@2314 | 54 | #include "runtime/signature.hpp" |
brutisso@2976 | 55 | #include "utilities/quickSort.hpp" |
stefank@2314 | 56 | #include "utilities/xmlstream.hpp" |
duke@435 | 57 | |
duke@435 | 58 | |
coleenp@4037 | 59 | // Implementation of Method |
duke@435 | 60 | |
coleenp@4037 | 61 | Method* Method::allocate(ClassLoaderData* loader_data, |
kamg@4245 | 62 | int byte_code_size, |
kamg@4245 | 63 | AccessFlags access_flags, |
coleenp@4572 | 64 | InlineTableSizes* sizes, |
kamg@4245 | 65 | ConstMethod::MethodType method_type, |
kamg@4245 | 66 | TRAPS) { |
coleenp@4037 | 67 | assert(!access_flags.is_native() || byte_code_size == 0, |
coleenp@4037 | 68 | "native methods should not contain byte codes"); |
coleenp@4037 | 69 | ConstMethod* cm = ConstMethod::allocate(loader_data, |
kamg@4245 | 70 | byte_code_size, |
coleenp@4572 | 71 | sizes, |
kamg@4245 | 72 | method_type, |
kamg@4245 | 73 | CHECK_NULL); |
coleenp@4037 | 74 | |
coleenp@4037 | 75 | int size = Method::size(access_flags.is_native()); |
coleenp@4037 | 76 | |
coleenp@4037 | 77 | return new (loader_data, size, false, THREAD) Method(cm, access_flags, size); |
coleenp@4037 | 78 | } |
coleenp@4037 | 79 | |
coleenp@4712 | 80 | Method::Method(ConstMethod* xconst, AccessFlags access_flags, int size) { |
coleenp@4037 | 81 | No_Safepoint_Verifier no_safepoint; |
coleenp@4037 | 82 | set_constMethod(xconst); |
coleenp@4037 | 83 | set_access_flags(access_flags); |
coleenp@4037 | 84 | set_method_size(size); |
coleenp@4037 | 85 | #ifdef CC_INTERP |
coleenp@4037 | 86 | set_result_index(T_VOID); |
coleenp@4037 | 87 | #endif |
coleenp@4037 | 88 | set_intrinsic_id(vmIntrinsics::_none); |
coleenp@4037 | 89 | set_jfr_towrite(false); |
coleenp@4715 | 90 | set_force_inline(false); |
coleenp@4715 | 91 | set_hidden(false); |
coleenp@4715 | 92 | set_dont_inline(false); |
coleenp@4037 | 93 | set_method_data(NULL); |
jiangli@4936 | 94 | set_method_counters(NULL); |
coleenp@4037 | 95 | set_vtable_index(Method::garbage_vtable_index); |
coleenp@4037 | 96 | |
coleenp@4037 | 97 | // Fix and bury in Method* |
coleenp@4037 | 98 | set_interpreter_entry(NULL); // sets i2i entry and from_int |
coleenp@4037 | 99 | set_adapter_entry(NULL); |
coleenp@4037 | 100 | clear_code(); // from_c/from_i get set to c2i/i2i |
coleenp@4037 | 101 | |
coleenp@4037 | 102 | if (access_flags.is_native()) { |
coleenp@4037 | 103 | clear_native_function(); |
coleenp@4037 | 104 | set_signature_handler(NULL); |
coleenp@4037 | 105 | } |
coleenp@4037 | 106 | |
coleenp@4037 | 107 | NOT_PRODUCT(set_compiled_invocation_count(0);) |
coleenp@4037 | 108 | } |
coleenp@4037 | 109 | |
coleenp@4037 | 110 | // Release Method*. The nmethod will be gone when we get here because |
coleenp@4037 | 111 | // we've walked the code cache. |
coleenp@4037 | 112 | void Method::deallocate_contents(ClassLoaderData* loader_data) { |
coleenp@4037 | 113 | MetadataFactory::free_metadata(loader_data, constMethod()); |
coleenp@4037 | 114 | set_constMethod(NULL); |
coleenp@4037 | 115 | MetadataFactory::free_metadata(loader_data, method_data()); |
coleenp@4037 | 116 | set_method_data(NULL); |
jiangli@4936 | 117 | MetadataFactory::free_metadata(loader_data, method_counters()); |
jiangli@4936 | 118 | set_method_counters(NULL); |
coleenp@4037 | 119 | // The nmethod will be gone when we get here. |
coleenp@4037 | 120 | if (code() != NULL) _code = NULL; |
coleenp@4037 | 121 | } |
coleenp@4037 | 122 | |
coleenp@4037 | 123 | address Method::get_i2c_entry() { |
duke@435 | 124 | assert(_adapter != NULL, "must have"); |
duke@435 | 125 | return _adapter->get_i2c_entry(); |
duke@435 | 126 | } |
duke@435 | 127 | |
coleenp@4037 | 128 | address Method::get_c2i_entry() { |
duke@435 | 129 | assert(_adapter != NULL, "must have"); |
duke@435 | 130 | return _adapter->get_c2i_entry(); |
duke@435 | 131 | } |
duke@435 | 132 | |
coleenp@4037 | 133 | address Method::get_c2i_unverified_entry() { |
duke@435 | 134 | assert(_adapter != NULL, "must have"); |
duke@435 | 135 | return _adapter->get_c2i_unverified_entry(); |
duke@435 | 136 | } |
duke@435 | 137 | |
coleenp@4037 | 138 | char* Method::name_and_sig_as_C_string() const { |
hseigel@4278 | 139 | return name_and_sig_as_C_string(constants()->pool_holder(), name(), signature()); |
duke@435 | 140 | } |
duke@435 | 141 | |
coleenp@4037 | 142 | char* Method::name_and_sig_as_C_string(char* buf, int size) const { |
hseigel@4278 | 143 | return name_and_sig_as_C_string(constants()->pool_holder(), name(), signature(), buf, size); |
duke@435 | 144 | } |
duke@435 | 145 | |
coleenp@4037 | 146 | char* Method::name_and_sig_as_C_string(Klass* klass, Symbol* method_name, Symbol* signature) { |
duke@435 | 147 | const char* klass_name = klass->external_name(); |
duke@435 | 148 | int klass_name_len = (int)strlen(klass_name); |
duke@435 | 149 | int method_name_len = method_name->utf8_length(); |
duke@435 | 150 | int len = klass_name_len + 1 + method_name_len + signature->utf8_length(); |
duke@435 | 151 | char* dest = NEW_RESOURCE_ARRAY(char, len + 1); |
duke@435 | 152 | strcpy(dest, klass_name); |
duke@435 | 153 | dest[klass_name_len] = '.'; |
duke@435 | 154 | strcpy(&dest[klass_name_len + 1], method_name->as_C_string()); |
duke@435 | 155 | strcpy(&dest[klass_name_len + 1 + method_name_len], signature->as_C_string()); |
duke@435 | 156 | dest[len] = 0; |
duke@435 | 157 | return dest; |
duke@435 | 158 | } |
duke@435 | 159 | |
coleenp@4037 | 160 | char* Method::name_and_sig_as_C_string(Klass* klass, Symbol* method_name, Symbol* signature, char* buf, int size) { |
coleenp@2497 | 161 | Symbol* klass_name = klass->name(); |
duke@435 | 162 | klass_name->as_klass_external_name(buf, size); |
duke@435 | 163 | int len = (int)strlen(buf); |
duke@435 | 164 | |
duke@435 | 165 | if (len < size - 1) { |
duke@435 | 166 | buf[len++] = '.'; |
duke@435 | 167 | |
duke@435 | 168 | method_name->as_C_string(&(buf[len]), size - len); |
duke@435 | 169 | len = (int)strlen(buf); |
duke@435 | 170 | |
duke@435 | 171 | signature->as_C_string(&(buf[len]), size - len); |
duke@435 | 172 | } |
duke@435 | 173 | |
duke@435 | 174 | return buf; |
duke@435 | 175 | } |
duke@435 | 176 | |
jiangli@4405 | 177 | int Method::fast_exception_handler_bci_for(methodHandle mh, KlassHandle ex_klass, int throw_bci, TRAPS) { |
duke@435 | 178 | // exception table holds quadruple entries of the form (beg_bci, end_bci, handler_bci, klass_index) |
duke@435 | 179 | // access exception table |
jiangli@4405 | 180 | ExceptionTable table(mh()); |
jiangli@3917 | 181 | int length = table.length(); |
duke@435 | 182 | // iterate through all entries sequentially |
jiangli@4405 | 183 | constantPoolHandle pool(THREAD, mh->constants()); |
jiangli@3917 | 184 | for (int i = 0; i < length; i ++) { |
jiangli@3917 | 185 | //reacquire the table in case a GC happened |
jiangli@4405 | 186 | ExceptionTable table(mh()); |
jiangli@3917 | 187 | int beg_bci = table.start_pc(i); |
jiangli@3917 | 188 | int end_bci = table.end_pc(i); |
duke@435 | 189 | assert(beg_bci <= end_bci, "inconsistent exception table"); |
duke@435 | 190 | if (beg_bci <= throw_bci && throw_bci < end_bci) { |
duke@435 | 191 | // exception handler bci range covers throw_bci => investigate further |
jiangli@3917 | 192 | int handler_bci = table.handler_pc(i); |
jiangli@3917 | 193 | int klass_index = table.catch_type_index(i); |
duke@435 | 194 | if (klass_index == 0) { |
duke@435 | 195 | return handler_bci; |
duke@435 | 196 | } else if (ex_klass.is_null()) { |
duke@435 | 197 | return handler_bci; |
duke@435 | 198 | } else { |
duke@435 | 199 | // we know the exception class => get the constraint class |
duke@435 | 200 | // this may require loading of the constraint class; if verification |
duke@435 | 201 | // fails or some other exception occurs, return handler_bci |
coleenp@4037 | 202 | Klass* k = pool->klass_at(klass_index, CHECK_(handler_bci)); |
duke@435 | 203 | KlassHandle klass = KlassHandle(THREAD, k); |
duke@435 | 204 | assert(klass.not_null(), "klass not loaded"); |
duke@435 | 205 | if (ex_klass->is_subtype_of(klass())) { |
duke@435 | 206 | return handler_bci; |
duke@435 | 207 | } |
duke@435 | 208 | } |
duke@435 | 209 | } |
duke@435 | 210 | } |
duke@435 | 211 | |
duke@435 | 212 | return -1; |
duke@435 | 213 | } |
duke@435 | 214 | |
coleenp@4037 | 215 | void Method::mask_for(int bci, InterpreterOopMap* mask) { |
duke@435 | 216 | |
duke@435 | 217 | Thread* myThread = Thread::current(); |
duke@435 | 218 | methodHandle h_this(myThread, this); |
duke@435 | 219 | #ifdef ASSERT |
duke@435 | 220 | bool has_capability = myThread->is_VM_thread() || |
duke@435 | 221 | myThread->is_ConcurrentGC_thread() || |
duke@435 | 222 | myThread->is_GC_task_thread(); |
duke@435 | 223 | |
duke@435 | 224 | if (!has_capability) { |
duke@435 | 225 | if (!VerifyStack && !VerifyLastFrame) { |
duke@435 | 226 | // verify stack calls this outside VM thread |
duke@435 | 227 | warning("oopmap should only be accessed by the " |
duke@435 | 228 | "VM, GC task or CMS threads (or during debugging)"); |
duke@435 | 229 | InterpreterOopMap local_mask; |
coleenp@4251 | 230 | method_holder()->mask_for(h_this, bci, &local_mask); |
duke@435 | 231 | local_mask.print(); |
duke@435 | 232 | } |
duke@435 | 233 | } |
duke@435 | 234 | #endif |
coleenp@4251 | 235 | method_holder()->mask_for(h_this, bci, mask); |
duke@435 | 236 | return; |
duke@435 | 237 | } |
duke@435 | 238 | |
duke@435 | 239 | |
coleenp@4037 | 240 | int Method::bci_from(address bcp) const { |
kvn@4102 | 241 | #ifdef ASSERT |
kvn@4102 | 242 | { ResourceMark rm; |
twisti@3848 | 243 | assert(is_native() && bcp == code_base() || contains(bcp) || is_error_reported(), |
twisti@3848 | 244 | err_msg("bcp doesn't belong to this method: bcp: " INTPTR_FORMAT ", method: %s", bcp, name_and_sig_as_C_string())); |
kvn@4102 | 245 | } |
kvn@4102 | 246 | #endif |
duke@435 | 247 | return bcp - code_base(); |
duke@435 | 248 | } |
duke@435 | 249 | |
duke@435 | 250 | |
duke@435 | 251 | // Return (int)bcx if it appears to be a valid BCI. |
duke@435 | 252 | // Return bci_from((address)bcx) if it appears to be a valid BCP. |
duke@435 | 253 | // Return -1 otherwise. |
duke@435 | 254 | // Used by profiling code, when invalid data is a possibility. |
coleenp@4037 | 255 | // The caller is responsible for validating the Method* itself. |
coleenp@4037 | 256 | int Method::validate_bci_from_bcx(intptr_t bcx) const { |
duke@435 | 257 | // keep bci as -1 if not a valid bci |
duke@435 | 258 | int bci = -1; |
duke@435 | 259 | if (bcx == 0 || (address)bcx == code_base()) { |
duke@435 | 260 | // code_size() may return 0 and we allow 0 here |
duke@435 | 261 | // the method may be native |
duke@435 | 262 | bci = 0; |
duke@435 | 263 | } else if (frame::is_bci(bcx)) { |
duke@435 | 264 | if (bcx < code_size()) { |
duke@435 | 265 | bci = (int)bcx; |
duke@435 | 266 | } |
duke@435 | 267 | } else if (contains((address)bcx)) { |
duke@435 | 268 | bci = (address)bcx - code_base(); |
duke@435 | 269 | } |
duke@435 | 270 | // Assert that if we have dodged any asserts, bci is negative. |
duke@435 | 271 | assert(bci == -1 || bci == bci_from(bcp_from(bci)), "sane bci if >=0"); |
duke@435 | 272 | return bci; |
duke@435 | 273 | } |
duke@435 | 274 | |
coleenp@4037 | 275 | address Method::bcp_from(int bci) const { |
duke@435 | 276 | assert((is_native() && bci == 0) || (!is_native() && 0 <= bci && bci < code_size()), "illegal bci"); |
duke@435 | 277 | address bcp = code_base() + bci; |
duke@435 | 278 | assert(is_native() && bcp == code_base() || contains(bcp), "bcp doesn't belong to this method"); |
duke@435 | 279 | return bcp; |
duke@435 | 280 | } |
duke@435 | 281 | |
duke@435 | 282 | |
coleenp@4037 | 283 | int Method::size(bool is_native) { |
duke@435 | 284 | // If native, then include pointers for native_function and signature_handler |
duke@435 | 285 | int extra_bytes = (is_native) ? 2*sizeof(address*) : 0; |
duke@435 | 286 | int extra_words = align_size_up(extra_bytes, BytesPerWord) / BytesPerWord; |
duke@435 | 287 | return align_object_size(header_size() + extra_words); |
duke@435 | 288 | } |
duke@435 | 289 | |
duke@435 | 290 | |
coleenp@4037 | 291 | Symbol* Method::klass_name() const { |
coleenp@4037 | 292 | Klass* k = method_holder(); |
duke@435 | 293 | assert(k->is_klass(), "must be klass"); |
coleenp@4037 | 294 | InstanceKlass* ik = (InstanceKlass*) k; |
duke@435 | 295 | return ik->name(); |
duke@435 | 296 | } |
duke@435 | 297 | |
duke@435 | 298 | |
duke@435 | 299 | // Attempt to return method oop to original state. Clear any pointers |
duke@435 | 300 | // (to objects outside the shared spaces). We won't be able to predict |
duke@435 | 301 | // where they should point in a new JVM. Further initialize some |
duke@435 | 302 | // entries now in order allow them to be write protected later. |
duke@435 | 303 | |
coleenp@4037 | 304 | void Method::remove_unshareable_info() { |
duke@435 | 305 | unlink_method(); |
duke@435 | 306 | } |
duke@435 | 307 | |
duke@435 | 308 | |
coleenp@4037 | 309 | bool Method::was_executed_more_than(int n) { |
coleenp@4037 | 310 | // Invocation counter is reset when the Method* is compiled. |
duke@435 | 311 | // If the method has compiled code we therefore assume it has |
duke@435 | 312 | // be excuted more than n times. |
duke@435 | 313 | if (is_accessor() || is_empty_method() || (code() != NULL)) { |
duke@435 | 314 | // interpreter doesn't bump invocation counter of trivial methods |
duke@435 | 315 | // compiler does not bump invocation counter of compiled methods |
duke@435 | 316 | return true; |
iveresov@2138 | 317 | } |
jiangli@4936 | 318 | else if ((method_counters() != NULL && |
jiangli@4936 | 319 | method_counters()->invocation_counter()->carry()) || |
jiangli@4936 | 320 | (method_data() != NULL && |
jiangli@4936 | 321 | method_data()->invocation_counter()->carry())) { |
duke@435 | 322 | // The carry bit is set when the counter overflows and causes |
duke@435 | 323 | // a compilation to occur. We don't know how many times |
duke@435 | 324 | // the counter has been reset, so we simply assume it has |
duke@435 | 325 | // been executed more than n times. |
duke@435 | 326 | return true; |
duke@435 | 327 | } else { |
duke@435 | 328 | return invocation_count() > n; |
duke@435 | 329 | } |
duke@435 | 330 | } |
duke@435 | 331 | |
duke@435 | 332 | #ifndef PRODUCT |
coleenp@4037 | 333 | void Method::print_invocation_count() { |
duke@435 | 334 | if (is_static()) tty->print("static "); |
duke@435 | 335 | if (is_final()) tty->print("final "); |
duke@435 | 336 | if (is_synchronized()) tty->print("synchronized "); |
duke@435 | 337 | if (is_native()) tty->print("native "); |
coleenp@4037 | 338 | method_holder()->name()->print_symbol_on(tty); |
duke@435 | 339 | tty->print("."); |
duke@435 | 340 | name()->print_symbol_on(tty); |
duke@435 | 341 | signature()->print_symbol_on(tty); |
duke@435 | 342 | |
duke@435 | 343 | if (WizardMode) { |
duke@435 | 344 | // dump the size of the byte codes |
duke@435 | 345 | tty->print(" {%d}", code_size()); |
duke@435 | 346 | } |
duke@435 | 347 | tty->cr(); |
duke@435 | 348 | |
duke@435 | 349 | tty->print_cr (" interpreter_invocation_count: %8d ", interpreter_invocation_count()); |
duke@435 | 350 | tty->print_cr (" invocation_counter: %8d ", invocation_count()); |
duke@435 | 351 | tty->print_cr (" backedge_counter: %8d ", backedge_count()); |
duke@435 | 352 | if (CountCompiledCalls) { |
duke@435 | 353 | tty->print_cr (" compiled_invocation_count: %8d ", compiled_invocation_count()); |
duke@435 | 354 | } |
duke@435 | 355 | |
duke@435 | 356 | } |
duke@435 | 357 | #endif |
duke@435 | 358 | |
coleenp@4037 | 359 | // Build a MethodData* object to hold information about this method |
duke@435 | 360 | // collected in the interpreter. |
coleenp@4037 | 361 | void Method::build_interpreter_method_data(methodHandle method, TRAPS) { |
coleenp@2363 | 362 | // Do not profile method if current thread holds the pending list lock, |
coleenp@2363 | 363 | // which avoids deadlock for acquiring the MethodData_lock. |
coleenp@4047 | 364 | if (InstanceRefKlass::owns_pending_list_lock((JavaThread*)THREAD)) { |
coleenp@2363 | 365 | return; |
coleenp@2363 | 366 | } |
coleenp@2363 | 367 | |
duke@435 | 368 | // Grab a lock here to prevent multiple |
coleenp@4037 | 369 | // MethodData*s from being created. |
duke@435 | 370 | MutexLocker ml(MethodData_lock, THREAD); |
duke@435 | 371 | if (method->method_data() == NULL) { |
coleenp@4037 | 372 | ClassLoaderData* loader_data = method->method_holder()->class_loader_data(); |
coleenp@4037 | 373 | MethodData* method_data = MethodData::allocate(loader_data, method, CHECK); |
duke@435 | 374 | method->set_method_data(method_data); |
duke@435 | 375 | if (PrintMethodData && (Verbose || WizardMode)) { |
duke@435 | 376 | ResourceMark rm(THREAD); |
duke@435 | 377 | tty->print("build_interpreter_method_data for "); |
duke@435 | 378 | method->print_name(tty); |
duke@435 | 379 | tty->cr(); |
duke@435 | 380 | // At the end of the run, the MDO, full of data, will be dumped. |
duke@435 | 381 | } |
duke@435 | 382 | } |
duke@435 | 383 | } |
duke@435 | 384 | |
jiangli@4936 | 385 | MethodCounters* Method::build_method_counters(Method* m, TRAPS) { |
jiangli@4936 | 386 | methodHandle mh(m); |
jiangli@4936 | 387 | ClassLoaderData* loader_data = mh->method_holder()->class_loader_data(); |
jiangli@4936 | 388 | MethodCounters* counters = MethodCounters::allocate(loader_data, CHECK_NULL); |
jiangli@4936 | 389 | if (mh->method_counters() == NULL) { |
jiangli@4936 | 390 | mh->set_method_counters(counters); |
jiangli@4936 | 391 | } else { |
jiangli@4936 | 392 | MetadataFactory::free_metadata(loader_data, counters); |
jiangli@4936 | 393 | } |
jiangli@4936 | 394 | return mh->method_counters(); |
jiangli@4936 | 395 | } |
jiangli@4936 | 396 | |
coleenp@4037 | 397 | void Method::cleanup_inline_caches() { |
duke@435 | 398 | // The current system doesn't use inline caches in the interpreter |
duke@435 | 399 | // => nothing to do (keep this method around for future use) |
duke@435 | 400 | } |
duke@435 | 401 | |
duke@435 | 402 | |
coleenp@4037 | 403 | int Method::extra_stack_words() { |
jrose@1145 | 404 | // not an inline function, to avoid a header dependency on Interpreter |
twisti@1861 | 405 | return extra_stack_entries() * Interpreter::stackElementSize; |
jrose@1145 | 406 | } |
jrose@1145 | 407 | |
jrose@1145 | 408 | |
coleenp@4037 | 409 | void Method::compute_size_of_parameters(Thread *thread) { |
coleenp@2497 | 410 | ArgumentSizeComputer asc(signature()); |
duke@435 | 411 | set_size_of_parameters(asc.size() + (is_static() ? 0 : 1)); |
duke@435 | 412 | } |
duke@435 | 413 | |
duke@435 | 414 | #ifdef CC_INTERP |
coleenp@4037 | 415 | void Method::set_result_index(BasicType type) { |
duke@435 | 416 | _result_index = Interpreter::BasicType_as_index(type); |
duke@435 | 417 | } |
duke@435 | 418 | #endif |
duke@435 | 419 | |
coleenp@4037 | 420 | BasicType Method::result_type() const { |
duke@435 | 421 | ResultTypeFinder rtf(signature()); |
duke@435 | 422 | return rtf.type(); |
duke@435 | 423 | } |
duke@435 | 424 | |
duke@435 | 425 | |
coleenp@4037 | 426 | bool Method::is_empty_method() const { |
duke@435 | 427 | return code_size() == 1 |
duke@435 | 428 | && *code_base() == Bytecodes::_return; |
duke@435 | 429 | } |
duke@435 | 430 | |
duke@435 | 431 | |
coleenp@4037 | 432 | bool Method::is_vanilla_constructor() const { |
duke@435 | 433 | // Returns true if this method is a vanilla constructor, i.e. an "<init>" "()V" method |
duke@435 | 434 | // which only calls the superclass vanilla constructor and possibly does stores of |
duke@435 | 435 | // zero constants to local fields: |
duke@435 | 436 | // |
duke@435 | 437 | // aload_0 |
duke@435 | 438 | // invokespecial |
duke@435 | 439 | // indexbyte1 |
duke@435 | 440 | // indexbyte2 |
duke@435 | 441 | // |
duke@435 | 442 | // followed by an (optional) sequence of: |
duke@435 | 443 | // |
duke@435 | 444 | // aload_0 |
duke@435 | 445 | // aconst_null / iconst_0 / fconst_0 / dconst_0 |
duke@435 | 446 | // putfield |
duke@435 | 447 | // indexbyte1 |
duke@435 | 448 | // indexbyte2 |
duke@435 | 449 | // |
duke@435 | 450 | // followed by: |
duke@435 | 451 | // |
duke@435 | 452 | // return |
duke@435 | 453 | |
duke@435 | 454 | assert(name() == vmSymbols::object_initializer_name(), "Should only be called for default constructors"); |
duke@435 | 455 | assert(signature() == vmSymbols::void_method_signature(), "Should only be called for default constructors"); |
duke@435 | 456 | int size = code_size(); |
duke@435 | 457 | // Check if size match |
duke@435 | 458 | if (size == 0 || size % 5 != 0) return false; |
duke@435 | 459 | address cb = code_base(); |
duke@435 | 460 | int last = size - 1; |
duke@435 | 461 | if (cb[0] != Bytecodes::_aload_0 || cb[1] != Bytecodes::_invokespecial || cb[last] != Bytecodes::_return) { |
duke@435 | 462 | // Does not call superclass default constructor |
duke@435 | 463 | return false; |
duke@435 | 464 | } |
duke@435 | 465 | // Check optional sequence |
duke@435 | 466 | for (int i = 4; i < last; i += 5) { |
duke@435 | 467 | if (cb[i] != Bytecodes::_aload_0) return false; |
duke@435 | 468 | if (!Bytecodes::is_zero_const(Bytecodes::cast(cb[i+1]))) return false; |
duke@435 | 469 | if (cb[i+2] != Bytecodes::_putfield) return false; |
duke@435 | 470 | } |
duke@435 | 471 | return true; |
duke@435 | 472 | } |
duke@435 | 473 | |
duke@435 | 474 | |
coleenp@4037 | 475 | bool Method::compute_has_loops_flag() { |
coleenp@4037 | 476 | BytecodeStream bcs(this); |
duke@435 | 477 | Bytecodes::Code bc; |
duke@435 | 478 | |
duke@435 | 479 | while ((bc = bcs.next()) >= 0) { |
duke@435 | 480 | switch( bc ) { |
duke@435 | 481 | case Bytecodes::_ifeq: |
duke@435 | 482 | case Bytecodes::_ifnull: |
duke@435 | 483 | case Bytecodes::_iflt: |
duke@435 | 484 | case Bytecodes::_ifle: |
duke@435 | 485 | case Bytecodes::_ifne: |
duke@435 | 486 | case Bytecodes::_ifnonnull: |
duke@435 | 487 | case Bytecodes::_ifgt: |
duke@435 | 488 | case Bytecodes::_ifge: |
duke@435 | 489 | case Bytecodes::_if_icmpeq: |
duke@435 | 490 | case Bytecodes::_if_icmpne: |
duke@435 | 491 | case Bytecodes::_if_icmplt: |
duke@435 | 492 | case Bytecodes::_if_icmpgt: |
duke@435 | 493 | case Bytecodes::_if_icmple: |
duke@435 | 494 | case Bytecodes::_if_icmpge: |
duke@435 | 495 | case Bytecodes::_if_acmpeq: |
duke@435 | 496 | case Bytecodes::_if_acmpne: |
duke@435 | 497 | case Bytecodes::_goto: |
duke@435 | 498 | case Bytecodes::_jsr: |
duke@435 | 499 | if( bcs.dest() < bcs.next_bci() ) _access_flags.set_has_loops(); |
duke@435 | 500 | break; |
duke@435 | 501 | |
duke@435 | 502 | case Bytecodes::_goto_w: |
duke@435 | 503 | case Bytecodes::_jsr_w: |
duke@435 | 504 | if( bcs.dest_w() < bcs.next_bci() ) _access_flags.set_has_loops(); |
duke@435 | 505 | break; |
duke@435 | 506 | } |
duke@435 | 507 | } |
duke@435 | 508 | _access_flags.set_loops_flag_init(); |
duke@435 | 509 | return _access_flags.has_loops(); |
duke@435 | 510 | } |
duke@435 | 511 | |
duke@435 | 512 | |
coleenp@4037 | 513 | bool Method::is_final_method() const { |
duke@435 | 514 | // %%% Should return true for private methods also, |
duke@435 | 515 | // since there is no way to override them. |
coleenp@4251 | 516 | return is_final() || method_holder()->is_final(); |
duke@435 | 517 | } |
duke@435 | 518 | |
duke@435 | 519 | |
coleenp@4037 | 520 | bool Method::is_strict_method() const { |
duke@435 | 521 | return is_strict(); |
duke@435 | 522 | } |
duke@435 | 523 | |
duke@435 | 524 | |
coleenp@4037 | 525 | bool Method::can_be_statically_bound() const { |
duke@435 | 526 | if (is_final_method()) return true; |
duke@435 | 527 | return vtable_index() == nonvirtual_vtable_index; |
duke@435 | 528 | } |
duke@435 | 529 | |
duke@435 | 530 | |
coleenp@4037 | 531 | bool Method::is_accessor() const { |
duke@435 | 532 | if (code_size() != 5) return false; |
duke@435 | 533 | if (size_of_parameters() != 1) return false; |
never@2462 | 534 | if (java_code_at(0) != Bytecodes::_aload_0 ) return false; |
never@2462 | 535 | if (java_code_at(1) != Bytecodes::_getfield) return false; |
never@2462 | 536 | if (java_code_at(4) != Bytecodes::_areturn && |
never@2462 | 537 | java_code_at(4) != Bytecodes::_ireturn ) return false; |
duke@435 | 538 | return true; |
duke@435 | 539 | } |
duke@435 | 540 | |
duke@435 | 541 | |
coleenp@4037 | 542 | bool Method::is_initializer() const { |
kamg@2616 | 543 | return name() == vmSymbols::object_initializer_name() || is_static_initializer(); |
kamg@2616 | 544 | } |
kamg@2616 | 545 | |
coleenp@4037 | 546 | bool Method::has_valid_initializer_flags() const { |
kamg@2616 | 547 | return (is_static() || |
coleenp@4251 | 548 | method_holder()->major_version() < 51); |
kamg@2616 | 549 | } |
kamg@2616 | 550 | |
coleenp@4037 | 551 | bool Method::is_static_initializer() const { |
kamg@2616 | 552 | // For classfiles version 51 or greater, ensure that the clinit method is |
kamg@2616 | 553 | // static. Non-static methods with the name "<clinit>" are not static |
kamg@2616 | 554 | // initializers. (older classfiles exempted for backward compatibility) |
kamg@2616 | 555 | return name() == vmSymbols::class_initializer_name() && |
kamg@2616 | 556 | has_valid_initializer_flags(); |
duke@435 | 557 | } |
duke@435 | 558 | |
duke@435 | 559 | |
coleenp@4037 | 560 | objArrayHandle Method::resolved_checked_exceptions_impl(Method* this_oop, TRAPS) { |
duke@435 | 561 | int length = this_oop->checked_exceptions_length(); |
duke@435 | 562 | if (length == 0) { // common case |
duke@435 | 563 | return objArrayHandle(THREAD, Universe::the_empty_class_klass_array()); |
duke@435 | 564 | } else { |
duke@435 | 565 | methodHandle h_this(THREAD, this_oop); |
never@1577 | 566 | objArrayOop m_oop = oopFactory::new_objArray(SystemDictionary::Class_klass(), length, CHECK_(objArrayHandle())); |
duke@435 | 567 | objArrayHandle mirrors (THREAD, m_oop); |
duke@435 | 568 | for (int i = 0; i < length; i++) { |
duke@435 | 569 | CheckedExceptionElement* table = h_this->checked_exceptions_start(); // recompute on each iteration, not gc safe |
coleenp@4037 | 570 | Klass* k = h_this->constants()->klass_at(table[i].class_cp_index, CHECK_(objArrayHandle())); |
hseigel@4278 | 571 | assert(k->is_subclass_of(SystemDictionary::Throwable_klass()), "invalid exception class"); |
hseigel@4278 | 572 | mirrors->obj_at_put(i, k->java_mirror()); |
duke@435 | 573 | } |
duke@435 | 574 | return mirrors; |
duke@435 | 575 | } |
duke@435 | 576 | }; |
duke@435 | 577 | |
duke@435 | 578 | |
coleenp@4037 | 579 | int Method::line_number_from_bci(int bci) const { |
duke@435 | 580 | if (bci == SynchronizationEntryBCI) bci = 0; |
duke@435 | 581 | assert(bci == 0 || 0 <= bci && bci < code_size(), "illegal bci"); |
duke@435 | 582 | int best_bci = 0; |
duke@435 | 583 | int best_line = -1; |
duke@435 | 584 | |
duke@435 | 585 | if (has_linenumber_table()) { |
duke@435 | 586 | // The line numbers are a short array of 2-tuples [start_pc, line_number]. |
duke@435 | 587 | // Not necessarily sorted and not necessarily one-to-one. |
duke@435 | 588 | CompressedLineNumberReadStream stream(compressed_linenumber_table()); |
duke@435 | 589 | while (stream.read_pair()) { |
duke@435 | 590 | if (stream.bci() == bci) { |
duke@435 | 591 | // perfect match |
duke@435 | 592 | return stream.line(); |
duke@435 | 593 | } else { |
duke@435 | 594 | // update best_bci/line |
duke@435 | 595 | if (stream.bci() < bci && stream.bci() >= best_bci) { |
duke@435 | 596 | best_bci = stream.bci(); |
duke@435 | 597 | best_line = stream.line(); |
duke@435 | 598 | } |
duke@435 | 599 | } |
duke@435 | 600 | } |
duke@435 | 601 | } |
duke@435 | 602 | return best_line; |
duke@435 | 603 | } |
duke@435 | 604 | |
duke@435 | 605 | |
coleenp@4037 | 606 | bool Method::is_klass_loaded_by_klass_index(int klass_index) const { |
jiangli@3826 | 607 | if( constants()->tag_at(klass_index).is_unresolved_klass() ) { |
duke@435 | 608 | Thread *thread = Thread::current(); |
jiangli@3826 | 609 | Symbol* klass_name = constants()->klass_name_at(klass_index); |
coleenp@4251 | 610 | Handle loader(thread, method_holder()->class_loader()); |
hseigel@4278 | 611 | Handle prot (thread, method_holder()->protection_domain()); |
duke@435 | 612 | return SystemDictionary::find(klass_name, loader, prot, thread) != NULL; |
duke@435 | 613 | } else { |
duke@435 | 614 | return true; |
duke@435 | 615 | } |
duke@435 | 616 | } |
duke@435 | 617 | |
duke@435 | 618 | |
coleenp@4037 | 619 | bool Method::is_klass_loaded(int refinfo_index, bool must_be_resolved) const { |
jiangli@3826 | 620 | int klass_index = constants()->klass_ref_index_at(refinfo_index); |
duke@435 | 621 | if (must_be_resolved) { |
duke@435 | 622 | // Make sure klass is resolved in constantpool. |
duke@435 | 623 | if (constants()->tag_at(klass_index).is_unresolved_klass()) return false; |
duke@435 | 624 | } |
duke@435 | 625 | return is_klass_loaded_by_klass_index(klass_index); |
duke@435 | 626 | } |
duke@435 | 627 | |
duke@435 | 628 | |
coleenp@4037 | 629 | void Method::set_native_function(address function, bool post_event_flag) { |
duke@435 | 630 | assert(function != NULL, "use clear_native_function to unregister natives"); |
twisti@3969 | 631 | assert(!is_method_handle_intrinsic() || function == SharedRuntime::native_method_throw_unsatisfied_link_error_entry(), ""); |
duke@435 | 632 | address* native_function = native_function_addr(); |
duke@435 | 633 | |
duke@435 | 634 | // We can see racers trying to place the same native function into place. Once |
duke@435 | 635 | // is plenty. |
duke@435 | 636 | address current = *native_function; |
duke@435 | 637 | if (current == function) return; |
duke@435 | 638 | if (post_event_flag && JvmtiExport::should_post_native_method_bind() && |
duke@435 | 639 | function != NULL) { |
duke@435 | 640 | // native_method_throw_unsatisfied_link_error_entry() should only |
duke@435 | 641 | // be passed when post_event_flag is false. |
duke@435 | 642 | assert(function != |
duke@435 | 643 | SharedRuntime::native_method_throw_unsatisfied_link_error_entry(), |
duke@435 | 644 | "post_event_flag mis-match"); |
duke@435 | 645 | |
duke@435 | 646 | // post the bind event, and possible change the bind function |
duke@435 | 647 | JvmtiExport::post_native_method_bind(this, &function); |
duke@435 | 648 | } |
duke@435 | 649 | *native_function = function; |
duke@435 | 650 | // This function can be called more than once. We must make sure that we always |
duke@435 | 651 | // use the latest registered method -> check if a stub already has been generated. |
duke@435 | 652 | // If so, we have to make it not_entrant. |
duke@435 | 653 | nmethod* nm = code(); // Put it into local variable to guard against concurrent updates |
duke@435 | 654 | if (nm != NULL) { |
duke@435 | 655 | nm->make_not_entrant(); |
duke@435 | 656 | } |
duke@435 | 657 | } |
duke@435 | 658 | |
duke@435 | 659 | |
coleenp@4037 | 660 | bool Method::has_native_function() const { |
twisti@3970 | 661 | if (is_method_handle_intrinsic()) |
twisti@3970 | 662 | return false; // special-cased in SharedRuntime::generate_native_wrapper |
duke@435 | 663 | address func = native_function(); |
duke@435 | 664 | return (func != NULL && func != SharedRuntime::native_method_throw_unsatisfied_link_error_entry()); |
duke@435 | 665 | } |
duke@435 | 666 | |
duke@435 | 667 | |
coleenp@4037 | 668 | void Method::clear_native_function() { |
twisti@3969 | 669 | // Note: is_method_handle_intrinsic() is allowed here. |
duke@435 | 670 | set_native_function( |
duke@435 | 671 | SharedRuntime::native_method_throw_unsatisfied_link_error_entry(), |
duke@435 | 672 | !native_bind_event_is_interesting); |
duke@435 | 673 | clear_code(); |
duke@435 | 674 | } |
duke@435 | 675 | |
coleenp@4037 | 676 | address Method::critical_native_function() { |
never@3500 | 677 | methodHandle mh(this); |
never@3500 | 678 | return NativeLookup::lookup_critical_entry(mh); |
never@3500 | 679 | } |
never@3500 | 680 | |
duke@435 | 681 | |
coleenp@4037 | 682 | void Method::set_signature_handler(address handler) { |
duke@435 | 683 | address* signature_handler = signature_handler_addr(); |
duke@435 | 684 | *signature_handler = handler; |
duke@435 | 685 | } |
duke@435 | 686 | |
duke@435 | 687 | |
vlivanov@4539 | 688 | void Method::print_made_not_compilable(int comp_level, bool is_osr, bool report, const char* reason) { |
kvn@1643 | 689 | if (PrintCompilation && report) { |
kvn@1641 | 690 | ttyLocker ttyl; |
twisti@4111 | 691 | tty->print("made not %scompilable on ", is_osr ? "OSR " : ""); |
twisti@4111 | 692 | if (comp_level == CompLevel_all) { |
twisti@4111 | 693 | tty->print("all levels "); |
twisti@4111 | 694 | } else { |
twisti@4111 | 695 | tty->print("levels "); |
twisti@4111 | 696 | for (int i = (int)CompLevel_none; i <= comp_level; i++) { |
twisti@4111 | 697 | tty->print("%d ", i); |
twisti@4111 | 698 | } |
twisti@4111 | 699 | } |
kvn@1641 | 700 | this->print_short_name(tty); |
kvn@1641 | 701 | int size = this->code_size(); |
vlivanov@4539 | 702 | if (size > 0) { |
kvn@1641 | 703 | tty->print(" (%d bytes)", size); |
vlivanov@4539 | 704 | } |
vlivanov@4539 | 705 | if (reason != NULL) { |
vlivanov@4539 | 706 | tty->print(" %s", reason); |
vlivanov@4539 | 707 | } |
kvn@1641 | 708 | tty->cr(); |
kvn@1641 | 709 | } |
duke@435 | 710 | if ((TraceDeoptimization || LogCompilation) && (xtty != NULL)) { |
duke@435 | 711 | ttyLocker ttyl; |
vlivanov@4154 | 712 | xtty->begin_elem("make_not_%scompilable thread='" UINTX_FORMAT "'", |
vlivanov@4154 | 713 | is_osr ? "osr_" : "", os::current_thread_id()); |
vlivanov@4539 | 714 | if (reason != NULL) { |
vlivanov@4539 | 715 | xtty->print(" reason=\'%s\'", reason); |
vlivanov@4539 | 716 | } |
coleenp@4037 | 717 | xtty->method(this); |
duke@435 | 718 | xtty->stamp(); |
duke@435 | 719 | xtty->end_elem(); |
duke@435 | 720 | } |
twisti@4111 | 721 | } |
twisti@4111 | 722 | |
twisti@4111 | 723 | bool Method::is_not_compilable(int comp_level) const { |
twisti@4111 | 724 | if (number_of_breakpoints() > 0) |
twisti@4111 | 725 | return true; |
twisti@4111 | 726 | if (is_method_handle_intrinsic()) |
twisti@4111 | 727 | return !is_synthetic(); // the generated adapters must be compiled |
twisti@4111 | 728 | if (comp_level == CompLevel_any) |
twisti@4111 | 729 | return is_not_c1_compilable() || is_not_c2_compilable(); |
twisti@4111 | 730 | if (is_c1_compile(comp_level)) |
twisti@4111 | 731 | return is_not_c1_compilable(); |
twisti@4111 | 732 | if (is_c2_compile(comp_level)) |
twisti@4111 | 733 | return is_not_c2_compilable(); |
twisti@4111 | 734 | return false; |
twisti@4111 | 735 | } |
twisti@4111 | 736 | |
twisti@4111 | 737 | // call this when compiler finds that this method is not compilable |
vlivanov@4539 | 738 | void Method::set_not_compilable(int comp_level, bool report, const char* reason) { |
vlivanov@4539 | 739 | print_made_not_compilable(comp_level, /*is_osr*/ false, report, reason); |
iveresov@2138 | 740 | if (comp_level == CompLevel_all) { |
iveresov@2138 | 741 | set_not_c1_compilable(); |
iveresov@2138 | 742 | set_not_c2_compilable(); |
iveresov@2138 | 743 | } else { |
twisti@4111 | 744 | if (is_c1_compile(comp_level)) |
iveresov@2138 | 745 | set_not_c1_compilable(); |
twisti@4111 | 746 | if (is_c2_compile(comp_level)) |
twisti@4111 | 747 | set_not_c2_compilable(); |
twisti@4111 | 748 | } |
twisti@4111 | 749 | CompilationPolicy::policy()->disable_compilation(this); |
twisti@4111 | 750 | } |
twisti@4111 | 751 | |
twisti@4111 | 752 | bool Method::is_not_osr_compilable(int comp_level) const { |
twisti@4111 | 753 | if (is_not_compilable(comp_level)) |
twisti@4111 | 754 | return true; |
twisti@4111 | 755 | if (comp_level == CompLevel_any) |
twisti@4111 | 756 | return is_not_c1_osr_compilable() || is_not_c2_osr_compilable(); |
twisti@4111 | 757 | if (is_c1_compile(comp_level)) |
twisti@4111 | 758 | return is_not_c1_osr_compilable(); |
twisti@4111 | 759 | if (is_c2_compile(comp_level)) |
twisti@4111 | 760 | return is_not_c2_osr_compilable(); |
twisti@4111 | 761 | return false; |
twisti@4111 | 762 | } |
twisti@4111 | 763 | |
vlivanov@4539 | 764 | void Method::set_not_osr_compilable(int comp_level, bool report, const char* reason) { |
vlivanov@4539 | 765 | print_made_not_compilable(comp_level, /*is_osr*/ true, report, reason); |
twisti@4111 | 766 | if (comp_level == CompLevel_all) { |
twisti@4111 | 767 | set_not_c1_osr_compilable(); |
twisti@4111 | 768 | set_not_c2_osr_compilable(); |
twisti@4111 | 769 | } else { |
twisti@4111 | 770 | if (is_c1_compile(comp_level)) |
twisti@4111 | 771 | set_not_c1_osr_compilable(); |
twisti@4111 | 772 | if (is_c2_compile(comp_level)) |
twisti@4111 | 773 | set_not_c2_osr_compilable(); |
duke@435 | 774 | } |
iveresov@2138 | 775 | CompilationPolicy::policy()->disable_compilation(this); |
duke@435 | 776 | } |
duke@435 | 777 | |
duke@435 | 778 | // Revert to using the interpreter and clear out the nmethod |
coleenp@4037 | 779 | void Method::clear_code() { |
duke@435 | 780 | |
duke@435 | 781 | // this may be NULL if c2i adapters have not been made yet |
duke@435 | 782 | // Only should happen at allocate time. |
duke@435 | 783 | if (_adapter == NULL) { |
duke@435 | 784 | _from_compiled_entry = NULL; |
duke@435 | 785 | } else { |
duke@435 | 786 | _from_compiled_entry = _adapter->get_c2i_entry(); |
duke@435 | 787 | } |
duke@435 | 788 | OrderAccess::storestore(); |
duke@435 | 789 | _from_interpreted_entry = _i2i_entry; |
duke@435 | 790 | OrderAccess::storestore(); |
duke@435 | 791 | _code = NULL; |
duke@435 | 792 | } |
duke@435 | 793 | |
duke@435 | 794 | // Called by class data sharing to remove any entry points (which are not shared) |
coleenp@4037 | 795 | void Method::unlink_method() { |
duke@435 | 796 | _code = NULL; |
duke@435 | 797 | _i2i_entry = NULL; |
duke@435 | 798 | _from_interpreted_entry = NULL; |
duke@435 | 799 | if (is_native()) { |
duke@435 | 800 | *native_function_addr() = NULL; |
duke@435 | 801 | set_signature_handler(NULL); |
duke@435 | 802 | } |
duke@435 | 803 | NOT_PRODUCT(set_compiled_invocation_count(0);) |
duke@435 | 804 | _adapter = NULL; |
duke@435 | 805 | _from_compiled_entry = NULL; |
coleenp@4751 | 806 | |
coleenp@4751 | 807 | // In case of DumpSharedSpaces, _method_data should always be NULL. |
coleenp@4751 | 808 | // |
coleenp@4751 | 809 | // During runtime (!DumpSharedSpaces), when we are cleaning a |
coleenp@4751 | 810 | // shared class that failed to load, this->link_method() may |
coleenp@4751 | 811 | // have already been called (before an exception happened), so |
coleenp@4751 | 812 | // this->_method_data may not be NULL. |
coleenp@4751 | 813 | assert(!DumpSharedSpaces || _method_data == NULL, "unexpected method data?"); |
coleenp@4751 | 814 | |
duke@435 | 815 | set_method_data(NULL); |
jiangli@4936 | 816 | set_method_counters(NULL); |
duke@435 | 817 | } |
duke@435 | 818 | |
duke@435 | 819 | // Called when the method_holder is getting linked. Setup entrypoints so the method |
duke@435 | 820 | // is ready to be called from interpreter, compiler, and vtables. |
coleenp@4037 | 821 | void Method::link_method(methodHandle h_method, TRAPS) { |
coleenp@2945 | 822 | // If the code cache is full, we may reenter this function for the |
coleenp@2945 | 823 | // leftover methods that weren't linked. |
coleenp@2945 | 824 | if (_i2i_entry != NULL) return; |
coleenp@2945 | 825 | |
duke@435 | 826 | assert(_adapter == NULL, "init'd to NULL" ); |
duke@435 | 827 | assert( _code == NULL, "nothing compiled yet" ); |
duke@435 | 828 | |
duke@435 | 829 | // Setup interpreter entrypoint |
duke@435 | 830 | assert(this == h_method(), "wrong h_method()" ); |
duke@435 | 831 | address entry = Interpreter::entry_for_method(h_method); |
duke@435 | 832 | assert(entry != NULL, "interpreter entry must be non-null"); |
duke@435 | 833 | // Sets both _i2i_entry and _from_interpreted_entry |
duke@435 | 834 | set_interpreter_entry(entry); |
twisti@3969 | 835 | if (is_native() && !is_method_handle_intrinsic()) { |
duke@435 | 836 | set_native_function( |
duke@435 | 837 | SharedRuntime::native_method_throw_unsatisfied_link_error_entry(), |
duke@435 | 838 | !native_bind_event_is_interesting); |
duke@435 | 839 | } |
duke@435 | 840 | |
duke@435 | 841 | // Setup compiler entrypoint. This is made eagerly, so we do not need |
duke@435 | 842 | // special handling of vtables. An alternative is to make adapters more |
duke@435 | 843 | // lazily by calling make_adapter() from from_compiled_entry() for the |
duke@435 | 844 | // normal calls. For vtable calls life gets more complicated. When a |
duke@435 | 845 | // call-site goes mega-morphic we need adapters in all methods which can be |
duke@435 | 846 | // called from the vtable. We need adapters on such methods that get loaded |
duke@435 | 847 | // later. Ditto for mega-morphic itable calls. If this proves to be a |
duke@435 | 848 | // problem we'll make these lazily later. |
coleenp@2946 | 849 | (void) make_adapters(h_method, CHECK); |
duke@435 | 850 | |
duke@435 | 851 | // ONLY USE the h_method now as make_adapter may have blocked |
duke@435 | 852 | |
duke@435 | 853 | } |
duke@435 | 854 | |
coleenp@4037 | 855 | address Method::make_adapters(methodHandle mh, TRAPS) { |
duke@435 | 856 | // Adapters for compiled code are made eagerly here. They are fairly |
duke@435 | 857 | // small (generally < 100 bytes) and quick to make (and cached and shared) |
duke@435 | 858 | // so making them eagerly shouldn't be too expensive. |
duke@435 | 859 | AdapterHandlerEntry* adapter = AdapterHandlerLibrary::get_adapter(mh); |
duke@435 | 860 | if (adapter == NULL ) { |
never@1622 | 861 | THROW_MSG_NULL(vmSymbols::java_lang_VirtualMachineError(), "out of space in CodeCache for adapters"); |
duke@435 | 862 | } |
duke@435 | 863 | |
duke@435 | 864 | mh->set_adapter_entry(adapter); |
duke@435 | 865 | mh->_from_compiled_entry = adapter->get_c2i_entry(); |
duke@435 | 866 | return adapter->get_c2i_entry(); |
duke@435 | 867 | } |
duke@435 | 868 | |
duke@435 | 869 | // The verified_code_entry() must be called when a invoke is resolved |
duke@435 | 870 | // on this method. |
duke@435 | 871 | |
duke@435 | 872 | // It returns the compiled code entry point, after asserting not null. |
duke@435 | 873 | // This function is called after potential safepoints so that nmethod |
duke@435 | 874 | // or adapter that it points to is still live and valid. |
duke@435 | 875 | // This function must not hit a safepoint! |
coleenp@4037 | 876 | address Method::verified_code_entry() { |
duke@435 | 877 | debug_only(No_Safepoint_Verifier nsv;) |
kvn@1637 | 878 | nmethod *code = (nmethod *)OrderAccess::load_ptr_acquire(&_code); |
kvn@1637 | 879 | if (code == NULL && UseCodeCacheFlushing) { |
kvn@1637 | 880 | nmethod *saved_code = CodeCache::find_and_remove_saved_code(this); |
kvn@1637 | 881 | if (saved_code != NULL) { |
kvn@1637 | 882 | methodHandle method(this); |
kvn@1637 | 883 | assert( ! saved_code->is_osr_method(), "should not get here for osr" ); |
kvn@1637 | 884 | set_code( method, saved_code ); |
kvn@1637 | 885 | } |
kvn@1637 | 886 | } |
kvn@1637 | 887 | |
duke@435 | 888 | assert(_from_compiled_entry != NULL, "must be set"); |
duke@435 | 889 | return _from_compiled_entry; |
duke@435 | 890 | } |
duke@435 | 891 | |
duke@435 | 892 | // Check that if an nmethod ref exists, it has a backlink to this or no backlink at all |
duke@435 | 893 | // (could be racing a deopt). |
duke@435 | 894 | // Not inline to avoid circular ref. |
coleenp@4037 | 895 | bool Method::check_code() const { |
duke@435 | 896 | // cached in a register or local. There's a race on the value of the field. |
duke@435 | 897 | nmethod *code = (nmethod *)OrderAccess::load_ptr_acquire(&_code); |
coleenp@4037 | 898 | return code == NULL || (code->method() == NULL) || (code->method() == (Method*)this && !code->is_osr_method()); |
duke@435 | 899 | } |
duke@435 | 900 | |
duke@435 | 901 | // Install compiled code. Instantly it can execute. |
coleenp@4037 | 902 | void Method::set_code(methodHandle mh, nmethod *code) { |
duke@435 | 903 | assert( code, "use clear_code to remove code" ); |
duke@435 | 904 | assert( mh->check_code(), "" ); |
duke@435 | 905 | |
duke@435 | 906 | guarantee(mh->adapter() != NULL, "Adapter blob must already exist!"); |
duke@435 | 907 | |
duke@435 | 908 | // These writes must happen in this order, because the interpreter will |
duke@435 | 909 | // directly jump to from_interpreted_entry which jumps to an i2c adapter |
duke@435 | 910 | // which jumps to _from_compiled_entry. |
duke@435 | 911 | mh->_code = code; // Assign before allowing compiled code to exec |
duke@435 | 912 | |
duke@435 | 913 | int comp_level = code->comp_level(); |
duke@435 | 914 | // In theory there could be a race here. In practice it is unlikely |
duke@435 | 915 | // and not worth worrying about. |
iveresov@2138 | 916 | if (comp_level > mh->highest_comp_level()) { |
iveresov@2138 | 917 | mh->set_highest_comp_level(comp_level); |
duke@435 | 918 | } |
duke@435 | 919 | |
duke@435 | 920 | OrderAccess::storestore(); |
twisti@2047 | 921 | #ifdef SHARK |
twisti@2200 | 922 | mh->_from_interpreted_entry = code->insts_begin(); |
twisti@3969 | 923 | #else //!SHARK |
duke@435 | 924 | mh->_from_compiled_entry = code->verified_entry_point(); |
duke@435 | 925 | OrderAccess::storestore(); |
duke@435 | 926 | // Instantly compiled code can execute. |
twisti@3969 | 927 | if (!mh->is_method_handle_intrinsic()) |
twisti@3969 | 928 | mh->_from_interpreted_entry = mh->get_i2c_entry(); |
twisti@3969 | 929 | #endif //!SHARK |
duke@435 | 930 | } |
duke@435 | 931 | |
duke@435 | 932 | |
coleenp@4037 | 933 | bool Method::is_overridden_in(Klass* k) const { |
coleenp@4037 | 934 | InstanceKlass* ik = InstanceKlass::cast(k); |
duke@435 | 935 | |
duke@435 | 936 | if (ik->is_interface()) return false; |
duke@435 | 937 | |
duke@435 | 938 | // If method is an interface, we skip it - except if it |
duke@435 | 939 | // is a miranda method |
coleenp@4251 | 940 | if (method_holder()->is_interface()) { |
duke@435 | 941 | // Check that method is not a miranda method |
duke@435 | 942 | if (ik->lookup_method(name(), signature()) == NULL) { |
duke@435 | 943 | // No implementation exist - so miranda method |
duke@435 | 944 | return false; |
duke@435 | 945 | } |
duke@435 | 946 | return true; |
duke@435 | 947 | } |
duke@435 | 948 | |
duke@435 | 949 | assert(ik->is_subclass_of(method_holder()), "should be subklass"); |
duke@435 | 950 | assert(ik->vtable() != NULL, "vtable should exist"); |
duke@435 | 951 | if (vtable_index() == nonvirtual_vtable_index) { |
duke@435 | 952 | return false; |
duke@435 | 953 | } else { |
coleenp@4037 | 954 | Method* vt_m = ik->method_at_vtable(vtable_index()); |
coleenp@4037 | 955 | return vt_m != this; |
duke@435 | 956 | } |
duke@435 | 957 | } |
duke@435 | 958 | |
duke@435 | 959 | |
coleenp@4037 | 960 | // give advice about whether this Method* should be cached or not |
coleenp@4037 | 961 | bool Method::should_not_be_cached() const { |
dcubed@483 | 962 | if (is_old()) { |
dcubed@483 | 963 | // This method has been redefined. It is either EMCP or obsolete |
dcubed@483 | 964 | // and we don't want to cache it because that would pin the method |
dcubed@483 | 965 | // down and prevent it from being collectible if and when it |
dcubed@483 | 966 | // finishes executing. |
dcubed@483 | 967 | return true; |
dcubed@483 | 968 | } |
dcubed@483 | 969 | |
dcubed@483 | 970 | // caching this method should be just fine |
dcubed@483 | 971 | return false; |
dcubed@483 | 972 | } |
dcubed@483 | 973 | |
twisti@4866 | 974 | |
twisti@4866 | 975 | /** |
twisti@4866 | 976 | * Returns true if this is one of the specially treated methods for |
twisti@4866 | 977 | * security related stack walks (like Reflection.getCallerClass). |
twisti@4866 | 978 | */ |
twisti@4866 | 979 | bool Method::is_ignored_by_security_stack_walk() const { |
twisti@4866 | 980 | const bool use_new_reflection = JDK_Version::is_gte_jdk14x_version() && UseNewReflection; |
twisti@4866 | 981 | |
twisti@4866 | 982 | assert(intrinsic_id() != vmIntrinsics::_invoke || Universe::reflect_invoke_cache()->is_same_method((Method*)this), "sanity"); |
twisti@4866 | 983 | if (intrinsic_id() == vmIntrinsics::_invoke) { |
twisti@4866 | 984 | // This is Method.invoke() -- ignore it |
twisti@4866 | 985 | return true; |
twisti@4866 | 986 | } |
twisti@4866 | 987 | if (use_new_reflection && |
twisti@4866 | 988 | method_holder()->is_subclass_of(SystemDictionary::reflect_MethodAccessorImpl_klass())) { |
twisti@4866 | 989 | // This is an auxilary frame -- ignore it |
twisti@4866 | 990 | return true; |
twisti@4866 | 991 | } |
twisti@4866 | 992 | if (is_method_handle_intrinsic() || is_compiled_lambda_form()) { |
twisti@4866 | 993 | // This is an internal adapter frame for method handles -- ignore it |
twisti@4866 | 994 | return true; |
twisti@4866 | 995 | } |
twisti@4866 | 996 | return false; |
twisti@4866 | 997 | } |
twisti@4866 | 998 | |
twisti@4866 | 999 | |
jrose@1145 | 1000 | // Constant pool structure for invoke methods: |
jrose@1145 | 1001 | enum { |
twisti@3969 | 1002 | _imcp_invoke_name = 1, // utf8: 'invokeExact', etc. |
coleenp@2497 | 1003 | _imcp_invoke_signature, // utf8: (variable Symbol*) |
jrose@1145 | 1004 | _imcp_limit |
jrose@1145 | 1005 | }; |
jrose@1145 | 1006 | |
twisti@3969 | 1007 | // Test if this method is an MH adapter frame generated by Java code. |
twisti@3969 | 1008 | // Cf. java/lang/invoke/InvokerBytecodeGenerator |
coleenp@4037 | 1009 | bool Method::is_compiled_lambda_form() const { |
twisti@3969 | 1010 | return intrinsic_id() == vmIntrinsics::_compiledLambdaForm; |
jrose@1145 | 1011 | } |
jrose@1145 | 1012 | |
twisti@3969 | 1013 | // Test if this method is an internal MH primitive method. |
coleenp@4037 | 1014 | bool Method::is_method_handle_intrinsic() const { |
twisti@3969 | 1015 | vmIntrinsics::ID iid = intrinsic_id(); |
twisti@3969 | 1016 | return (MethodHandles::is_signature_polymorphic(iid) && |
twisti@3969 | 1017 | MethodHandles::is_signature_polymorphic_intrinsic(iid)); |
jrose@1145 | 1018 | } |
jrose@1145 | 1019 | |
coleenp@4037 | 1020 | bool Method::has_member_arg() const { |
twisti@3969 | 1021 | vmIntrinsics::ID iid = intrinsic_id(); |
twisti@3969 | 1022 | return (MethodHandles::is_signature_polymorphic(iid) && |
twisti@3969 | 1023 | MethodHandles::has_member_arg(iid)); |
twisti@1587 | 1024 | } |
twisti@1587 | 1025 | |
twisti@3969 | 1026 | // Make an instance of a signature-polymorphic internal MH primitive. |
coleenp@4037 | 1027 | methodHandle Method::make_method_handle_intrinsic(vmIntrinsics::ID iid, |
twisti@3969 | 1028 | Symbol* signature, |
twisti@3969 | 1029 | TRAPS) { |
never@3091 | 1030 | ResourceMark rm; |
jrose@1145 | 1031 | methodHandle empty; |
jrose@1145 | 1032 | |
twisti@3969 | 1033 | KlassHandle holder = SystemDictionary::MethodHandle_klass(); |
twisti@3969 | 1034 | Symbol* name = MethodHandles::signature_polymorphic_intrinsic_name(iid); |
twisti@3969 | 1035 | assert(iid == MethodHandles::signature_polymorphic_name_id(name), ""); |
jrose@1145 | 1036 | if (TraceMethodHandles) { |
twisti@3969 | 1037 | tty->print_cr("make_method_handle_intrinsic MH.%s%s", name->as_C_string(), signature->as_C_string()); |
jrose@1145 | 1038 | } |
jrose@1145 | 1039 | |
jrose@2760 | 1040 | // invariant: cp->symbol_at_put is preceded by a refcount increment (more usually a lookup) |
jrose@2760 | 1041 | name->increment_refcount(); |
jrose@2760 | 1042 | signature->increment_refcount(); |
jrose@2760 | 1043 | |
twisti@3969 | 1044 | int cp_length = _imcp_limit; |
coleenp@4037 | 1045 | ClassLoaderData* loader_data = holder->class_loader_data(); |
jrose@1145 | 1046 | constantPoolHandle cp; |
jrose@1145 | 1047 | { |
coleenp@4037 | 1048 | ConstantPool* cp_oop = ConstantPool::allocate(loader_data, cp_length, CHECK_(empty)); |
jrose@1145 | 1049 | cp = constantPoolHandle(THREAD, cp_oop); |
jrose@1145 | 1050 | } |
coleenp@4251 | 1051 | cp->set_pool_holder(InstanceKlass::cast(holder())); |
coleenp@2497 | 1052 | cp->symbol_at_put(_imcp_invoke_name, name); |
coleenp@2497 | 1053 | cp->symbol_at_put(_imcp_invoke_signature, signature); |
coleenp@4490 | 1054 | cp->set_has_preresolution(); |
jrose@1145 | 1055 | |
twisti@3969 | 1056 | // decide on access bits: public or not? |
twisti@3969 | 1057 | int flags_bits = (JVM_ACC_NATIVE | JVM_ACC_SYNTHETIC | JVM_ACC_FINAL); |
twisti@3969 | 1058 | bool must_be_static = MethodHandles::is_signature_polymorphic_static(iid); |
twisti@3969 | 1059 | if (must_be_static) flags_bits |= JVM_ACC_STATIC; |
twisti@3969 | 1060 | assert((flags_bits & JVM_ACC_PUBLIC) == 0, "do not expose these methods"); |
twisti@3969 | 1061 | |
jrose@1145 | 1062 | methodHandle m; |
jrose@1145 | 1063 | { |
coleenp@4572 | 1064 | InlineTableSizes sizes; |
coleenp@4398 | 1065 | Method* m_oop = Method::allocate(loader_data, 0, |
coleenp@4572 | 1066 | accessFlags_from(flags_bits), &sizes, |
coleenp@4398 | 1067 | ConstMethod::NORMAL, CHECK_(empty)); |
jrose@1145 | 1068 | m = methodHandle(THREAD, m_oop); |
jrose@1145 | 1069 | } |
jrose@1145 | 1070 | m->set_constants(cp()); |
jrose@1145 | 1071 | m->set_name_index(_imcp_invoke_name); |
jrose@1145 | 1072 | m->set_signature_index(_imcp_invoke_signature); |
twisti@3969 | 1073 | assert(MethodHandles::is_signature_polymorphic_name(m->name()), ""); |
coleenp@2497 | 1074 | assert(m->signature() == signature, ""); |
jrose@1145 | 1075 | #ifdef CC_INTERP |
twisti@2563 | 1076 | ResultTypeFinder rtf(signature); |
jrose@1145 | 1077 | m->set_result_index(rtf.type()); |
jrose@1145 | 1078 | #endif |
jrose@1145 | 1079 | m->compute_size_of_parameters(THREAD); |
jrose@2148 | 1080 | m->init_intrinsic_id(); |
twisti@3969 | 1081 | assert(m->is_method_handle_intrinsic(), ""); |
twisti@3969 | 1082 | #ifdef ASSERT |
twisti@3969 | 1083 | if (!MethodHandles::is_signature_polymorphic(m->intrinsic_id())) m->print(); |
twisti@3969 | 1084 | assert(MethodHandles::is_signature_polymorphic(m->intrinsic_id()), "must be an invoker"); |
twisti@3969 | 1085 | assert(m->intrinsic_id() == iid, "correctly predicted iid"); |
twisti@3969 | 1086 | #endif //ASSERT |
jrose@1145 | 1087 | |
jrose@1145 | 1088 | // Finally, set up its entry points. |
jrose@1145 | 1089 | assert(m->can_be_statically_bound(), ""); |
coleenp@4037 | 1090 | m->set_vtable_index(Method::nonvirtual_vtable_index); |
jrose@1145 | 1091 | m->link_method(m, CHECK_(empty)); |
jrose@1145 | 1092 | |
jrose@1474 | 1093 | if (TraceMethodHandles && (Verbose || WizardMode)) |
jrose@1145 | 1094 | m->print_on(tty); |
jrose@1145 | 1095 | |
jrose@1145 | 1096 | return m; |
jrose@1145 | 1097 | } |
jrose@1145 | 1098 | |
coleenp@4037 | 1099 | Klass* Method::check_non_bcp_klass(Klass* klass) { |
hseigel@4278 | 1100 | if (klass != NULL && klass->class_loader() != NULL) { |
hseigel@4278 | 1101 | if (klass->oop_is_objArray()) |
coleenp@4142 | 1102 | klass = ObjArrayKlass::cast(klass)->bottom_klass(); |
jrose@2982 | 1103 | return klass; |
jrose@2982 | 1104 | } |
jrose@2982 | 1105 | return NULL; |
jrose@2982 | 1106 | } |
jrose@1145 | 1107 | |
dcubed@483 | 1108 | |
coleenp@4037 | 1109 | methodHandle Method::clone_with_new_data(methodHandle m, u_char* new_code, int new_code_length, |
duke@435 | 1110 | u_char* new_compressed_linenumber_table, int new_compressed_linenumber_size, TRAPS) { |
duke@435 | 1111 | // Code below does not work for native methods - they should never get rewritten anyway |
duke@435 | 1112 | assert(!m->is_native(), "cannot rewrite native methods"); |
coleenp@4037 | 1113 | // Allocate new Method* |
duke@435 | 1114 | AccessFlags flags = m->access_flags(); |
coleenp@4572 | 1115 | |
coleenp@4572 | 1116 | ConstMethod* cm = m->constMethod(); |
coleenp@4572 | 1117 | int checked_exceptions_len = cm->checked_exceptions_length(); |
coleenp@4572 | 1118 | int localvariable_len = cm->localvariable_table_length(); |
coleenp@4572 | 1119 | int exception_table_len = cm->exception_table_length(); |
coleenp@4572 | 1120 | int method_parameters_len = cm->method_parameters_length(); |
coleenp@4572 | 1121 | int method_annotations_len = cm->method_annotations_length(); |
coleenp@4572 | 1122 | int parameter_annotations_len = cm->parameter_annotations_length(); |
coleenp@4572 | 1123 | int type_annotations_len = cm->type_annotations_length(); |
coleenp@4572 | 1124 | int default_annotations_len = cm->default_annotations_length(); |
coleenp@4572 | 1125 | |
coleenp@4572 | 1126 | InlineTableSizes sizes( |
coleenp@4572 | 1127 | localvariable_len, |
coleenp@4572 | 1128 | new_compressed_linenumber_size, |
coleenp@4572 | 1129 | exception_table_len, |
coleenp@4572 | 1130 | checked_exceptions_len, |
coleenp@4572 | 1131 | method_parameters_len, |
coleenp@4572 | 1132 | cm->generic_signature_index(), |
coleenp@4572 | 1133 | method_annotations_len, |
coleenp@4572 | 1134 | parameter_annotations_len, |
coleenp@4572 | 1135 | type_annotations_len, |
coleenp@4572 | 1136 | default_annotations_len, |
coleenp@4572 | 1137 | 0); |
coleenp@4037 | 1138 | |
kamg@4245 | 1139 | ClassLoaderData* loader_data = m->method_holder()->class_loader_data(); |
coleenp@4037 | 1140 | Method* newm_oop = Method::allocate(loader_data, |
kamg@4245 | 1141 | new_code_length, |
kamg@4245 | 1142 | flags, |
coleenp@4572 | 1143 | &sizes, |
kamg@4245 | 1144 | m->method_type(), |
kamg@4245 | 1145 | CHECK_(methodHandle())); |
duke@435 | 1146 | methodHandle newm (THREAD, newm_oop); |
duke@435 | 1147 | int new_method_size = newm->method_size(); |
jmasa@953 | 1148 | |
coleenp@4037 | 1149 | // Create a shallow copy of Method part, but be careful to preserve the new ConstMethod* |
coleenp@4037 | 1150 | ConstMethod* newcm = newm->constMethod(); |
coleenp@4037 | 1151 | int new_const_method_size = newm->constMethod()->size(); |
ysr@2533 | 1152 | |
coleenp@4037 | 1153 | memcpy(newm(), m(), sizeof(Method)); |
coleenp@4037 | 1154 | |
coleenp@4037 | 1155 | // Create shallow copy of ConstMethod. |
coleenp@4037 | 1156 | memcpy(newcm, m->constMethod(), sizeof(ConstMethod)); |
ysr@2533 | 1157 | |
duke@435 | 1158 | // Reset correct method/const method, method size, and parameter info |
duke@435 | 1159 | newm->set_constMethod(newcm); |
duke@435 | 1160 | newm->constMethod()->set_code_size(new_code_length); |
duke@435 | 1161 | newm->constMethod()->set_constMethod_size(new_const_method_size); |
duke@435 | 1162 | newm->set_method_size(new_method_size); |
duke@435 | 1163 | assert(newm->code_size() == new_code_length, "check"); |
duke@435 | 1164 | assert(newm->checked_exceptions_length() == checked_exceptions_len, "check"); |
jiangli@3920 | 1165 | assert(newm->exception_table_length() == exception_table_len, "check"); |
duke@435 | 1166 | assert(newm->localvariable_table_length() == localvariable_len, "check"); |
duke@435 | 1167 | // Copy new byte codes |
duke@435 | 1168 | memcpy(newm->code_base(), new_code, new_code_length); |
duke@435 | 1169 | // Copy line number table |
duke@435 | 1170 | if (new_compressed_linenumber_size > 0) { |
duke@435 | 1171 | memcpy(newm->compressed_linenumber_table(), |
duke@435 | 1172 | new_compressed_linenumber_table, |
duke@435 | 1173 | new_compressed_linenumber_size); |
duke@435 | 1174 | } |
duke@435 | 1175 | // Copy checked_exceptions |
duke@435 | 1176 | if (checked_exceptions_len > 0) { |
duke@435 | 1177 | memcpy(newm->checked_exceptions_start(), |
duke@435 | 1178 | m->checked_exceptions_start(), |
duke@435 | 1179 | checked_exceptions_len * sizeof(CheckedExceptionElement)); |
duke@435 | 1180 | } |
jiangli@3920 | 1181 | // Copy exception table |
jiangli@3920 | 1182 | if (exception_table_len > 0) { |
jiangli@3920 | 1183 | memcpy(newm->exception_table_start(), |
jiangli@3920 | 1184 | m->exception_table_start(), |
jiangli@3920 | 1185 | exception_table_len * sizeof(ExceptionTableElement)); |
jiangli@3920 | 1186 | } |
duke@435 | 1187 | // Copy local variable number table |
duke@435 | 1188 | if (localvariable_len > 0) { |
duke@435 | 1189 | memcpy(newm->localvariable_table_start(), |
duke@435 | 1190 | m->localvariable_table_start(), |
duke@435 | 1191 | localvariable_len * sizeof(LocalVariableTableElement)); |
duke@435 | 1192 | } |
coleenp@4037 | 1193 | // Copy stackmap table |
coleenp@4037 | 1194 | if (m->has_stackmap_table()) { |
coleenp@4037 | 1195 | int code_attribute_length = m->stackmap_data()->length(); |
coleenp@4037 | 1196 | Array<u1>* stackmap_data = |
coleenp@4037 | 1197 | MetadataFactory::new_array<u1>(loader_data, code_attribute_length, 0, CHECK_NULL); |
coleenp@4037 | 1198 | memcpy((void*)stackmap_data->adr_at(0), |
coleenp@4037 | 1199 | (void*)m->stackmap_data()->adr_at(0), code_attribute_length); |
coleenp@4037 | 1200 | newm->set_stackmap_data(stackmap_data); |
coleenp@4037 | 1201 | } |
jmasa@953 | 1202 | |
coleenp@4837 | 1203 | // copy annotations over to new method |
coleenp@4837 | 1204 | newcm->copy_annotations_from(cm); |
duke@435 | 1205 | return newm; |
duke@435 | 1206 | } |
duke@435 | 1207 | |
coleenp@4037 | 1208 | vmSymbols::SID Method::klass_id_for_intrinsics(Klass* holder) { |
duke@435 | 1209 | // if loader is not the default loader (i.e., != NULL), we can't know the intrinsics |
duke@435 | 1210 | // because we are not loading from core libraries |
kvn@4205 | 1211 | // exception: the AES intrinsics come from lib/ext/sunjce_provider.jar |
kvn@4205 | 1212 | // which does not use the class default class loader so we check for its loader here |
twisti@4866 | 1213 | InstanceKlass* ik = InstanceKlass::cast(holder); |
twisti@4866 | 1214 | if ((ik->class_loader() != NULL) && !SystemDictionary::is_ext_class_loader(ik->class_loader())) { |
jrose@1291 | 1215 | return vmSymbols::NO_SID; // regardless of name, no intrinsics here |
kvn@4205 | 1216 | } |
duke@435 | 1217 | |
duke@435 | 1218 | // see if the klass name is well-known: |
twisti@4866 | 1219 | Symbol* klass_name = ik->name(); |
jrose@1291 | 1220 | return vmSymbols::find_sid(klass_name); |
jrose@1291 | 1221 | } |
jrose@1291 | 1222 | |
coleenp@4037 | 1223 | void Method::init_intrinsic_id() { |
jrose@1291 | 1224 | assert(_intrinsic_id == vmIntrinsics::_none, "do this just once"); |
jrose@1291 | 1225 | const uintptr_t max_id_uint = right_n_bits((int)(sizeof(_intrinsic_id) * BitsPerByte)); |
jrose@1291 | 1226 | assert((uintptr_t)vmIntrinsics::ID_LIMIT <= max_id_uint, "else fix size"); |
jrose@2148 | 1227 | assert(intrinsic_id_size_in_bytes() == sizeof(_intrinsic_id), ""); |
jrose@1291 | 1228 | |
jrose@1291 | 1229 | // the klass name is well-known: |
jrose@1291 | 1230 | vmSymbols::SID klass_id = klass_id_for_intrinsics(method_holder()); |
jrose@1291 | 1231 | assert(klass_id != vmSymbols::NO_SID, "caller responsibility"); |
duke@435 | 1232 | |
duke@435 | 1233 | // ditto for method and signature: |
duke@435 | 1234 | vmSymbols::SID name_id = vmSymbols::find_sid(name()); |
twisti@3969 | 1235 | if (klass_id != vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_MethodHandle) |
twisti@3969 | 1236 | && name_id == vmSymbols::NO_SID) |
twisti@3969 | 1237 | return; |
duke@435 | 1238 | vmSymbols::SID sig_id = vmSymbols::find_sid(signature()); |
jrose@2639 | 1239 | if (klass_id != vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_MethodHandle) |
jrose@2148 | 1240 | && sig_id == vmSymbols::NO_SID) return; |
duke@435 | 1241 | jshort flags = access_flags().as_short(); |
duke@435 | 1242 | |
jrose@1291 | 1243 | vmIntrinsics::ID id = vmIntrinsics::find_id(klass_id, name_id, sig_id, flags); |
jrose@1291 | 1244 | if (id != vmIntrinsics::_none) { |
jrose@1291 | 1245 | set_intrinsic_id(id); |
jrose@1291 | 1246 | return; |
jrose@1291 | 1247 | } |
jrose@1291 | 1248 | |
duke@435 | 1249 | // A few slightly irregular cases: |
duke@435 | 1250 | switch (klass_id) { |
duke@435 | 1251 | case vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_StrictMath): |
duke@435 | 1252 | // Second chance: check in regular Math. |
duke@435 | 1253 | switch (name_id) { |
duke@435 | 1254 | case vmSymbols::VM_SYMBOL_ENUM_NAME(min_name): |
duke@435 | 1255 | case vmSymbols::VM_SYMBOL_ENUM_NAME(max_name): |
duke@435 | 1256 | case vmSymbols::VM_SYMBOL_ENUM_NAME(sqrt_name): |
duke@435 | 1257 | // pretend it is the corresponding method in the non-strict class: |
duke@435 | 1258 | klass_id = vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_Math); |
jrose@1291 | 1259 | id = vmIntrinsics::find_id(klass_id, name_id, sig_id, flags); |
duke@435 | 1260 | break; |
duke@435 | 1261 | } |
jrose@1862 | 1262 | break; |
jrose@1862 | 1263 | |
jrose@1862 | 1264 | // Signature-polymorphic methods: MethodHandle.invoke*, InvokeDynamic.*. |
jrose@2639 | 1265 | case vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_MethodHandle): |
twisti@3969 | 1266 | if (!is_native()) break; |
twisti@3969 | 1267 | id = MethodHandles::signature_polymorphic_name_id(method_holder(), name()); |
twisti@3969 | 1268 | if (is_static() != MethodHandles::is_signature_polymorphic_static(id)) |
twisti@3969 | 1269 | id = vmIntrinsics::_none; |
jrose@1862 | 1270 | break; |
duke@435 | 1271 | } |
duke@435 | 1272 | |
jrose@1291 | 1273 | if (id != vmIntrinsics::_none) { |
jrose@1291 | 1274 | // Set up its iid. It is an alias method. |
jrose@1291 | 1275 | set_intrinsic_id(id); |
jrose@1291 | 1276 | return; |
jrose@1291 | 1277 | } |
duke@435 | 1278 | } |
duke@435 | 1279 | |
coleenp@4037 | 1280 | // These two methods are static since a GC may move the Method |
coleenp@4037 | 1281 | bool Method::load_signature_classes(methodHandle m, TRAPS) { |
twisti@3969 | 1282 | if (THREAD->is_Compiler_thread()) { |
twisti@3969 | 1283 | // There is nothing useful this routine can do from within the Compile thread. |
twisti@3969 | 1284 | // Hopefully, the signature contains only well-known classes. |
twisti@3969 | 1285 | // We could scan for this and return true/false, but the caller won't care. |
twisti@3969 | 1286 | return false; |
twisti@3969 | 1287 | } |
duke@435 | 1288 | bool sig_is_loaded = true; |
coleenp@4251 | 1289 | Handle class_loader(THREAD, m->method_holder()->class_loader()); |
coleenp@4251 | 1290 | Handle protection_domain(THREAD, m->method_holder()->protection_domain()); |
coleenp@2497 | 1291 | ResourceMark rm(THREAD); |
coleenp@2497 | 1292 | Symbol* signature = m->signature(); |
duke@435 | 1293 | for(SignatureStream ss(signature); !ss.is_done(); ss.next()) { |
duke@435 | 1294 | if (ss.is_object()) { |
coleenp@2497 | 1295 | Symbol* sym = ss.as_symbol(CHECK_(false)); |
coleenp@2497 | 1296 | Symbol* name = sym; |
coleenp@4037 | 1297 | Klass* klass = SystemDictionary::resolve_or_null(name, class_loader, |
duke@435 | 1298 | protection_domain, THREAD); |
rasbold@539 | 1299 | // We are loading classes eagerly. If a ClassNotFoundException or |
rasbold@539 | 1300 | // a LinkageError was generated, be sure to ignore it. |
duke@435 | 1301 | if (HAS_PENDING_EXCEPTION) { |
never@1577 | 1302 | if (PENDING_EXCEPTION->is_a(SystemDictionary::ClassNotFoundException_klass()) || |
never@1577 | 1303 | PENDING_EXCEPTION->is_a(SystemDictionary::LinkageError_klass())) { |
duke@435 | 1304 | CLEAR_PENDING_EXCEPTION; |
duke@435 | 1305 | } else { |
duke@435 | 1306 | return false; |
duke@435 | 1307 | } |
duke@435 | 1308 | } |
duke@435 | 1309 | if( klass == NULL) { sig_is_loaded = false; } |
duke@435 | 1310 | } |
duke@435 | 1311 | } |
duke@435 | 1312 | return sig_is_loaded; |
duke@435 | 1313 | } |
duke@435 | 1314 | |
coleenp@4037 | 1315 | bool Method::has_unloaded_classes_in_signature(methodHandle m, TRAPS) { |
coleenp@4251 | 1316 | Handle class_loader(THREAD, m->method_holder()->class_loader()); |
coleenp@4251 | 1317 | Handle protection_domain(THREAD, m->method_holder()->protection_domain()); |
coleenp@2497 | 1318 | ResourceMark rm(THREAD); |
coleenp@2497 | 1319 | Symbol* signature = m->signature(); |
duke@435 | 1320 | for(SignatureStream ss(signature); !ss.is_done(); ss.next()) { |
duke@435 | 1321 | if (ss.type() == T_OBJECT) { |
coleenp@2497 | 1322 | Symbol* name = ss.as_symbol_or_null(); |
coleenp@2497 | 1323 | if (name == NULL) return true; |
coleenp@4037 | 1324 | Klass* klass = SystemDictionary::find(name, class_loader, protection_domain, THREAD); |
duke@435 | 1325 | if (klass == NULL) return true; |
duke@435 | 1326 | } |
duke@435 | 1327 | } |
duke@435 | 1328 | return false; |
duke@435 | 1329 | } |
duke@435 | 1330 | |
duke@435 | 1331 | // Exposed so field engineers can debug VM |
coleenp@4037 | 1332 | void Method::print_short_name(outputStream* st) { |
duke@435 | 1333 | ResourceMark rm; |
duke@435 | 1334 | #ifdef PRODUCT |
coleenp@4037 | 1335 | st->print(" %s::", method_holder()->external_name()); |
duke@435 | 1336 | #else |
coleenp@4037 | 1337 | st->print(" %s::", method_holder()->internal_name()); |
duke@435 | 1338 | #endif |
duke@435 | 1339 | name()->print_symbol_on(st); |
duke@435 | 1340 | if (WizardMode) signature()->print_symbol_on(st); |
twisti@3969 | 1341 | else if (MethodHandles::is_signature_polymorphic(intrinsic_id())) |
twisti@3969 | 1342 | MethodHandles::print_as_basic_type_signature_on(st, signature(), true); |
duke@435 | 1343 | } |
duke@435 | 1344 | |
brutisso@2976 | 1345 | // Comparer for sorting an object array containing |
coleenp@4037 | 1346 | // Method*s. |
coleenp@4037 | 1347 | static int method_comparator(Method* a, Method* b) { |
coleenp@4037 | 1348 | return a->name()->fast_compare(b->name()); |
kvn@3128 | 1349 | } |
duke@435 | 1350 | |
duke@435 | 1351 | // This is only done during class loading, so it is OK to assume method_idnum matches the methods() array |
coleenp@4572 | 1352 | void Method::sort_methods(Array<Method*>* methods, bool idempotent) { |
duke@435 | 1353 | int length = methods->length(); |
duke@435 | 1354 | if (length > 1) { |
brutisso@2976 | 1355 | { |
brutisso@2976 | 1356 | No_Safepoint_Verifier nsv; |
coleenp@4037 | 1357 | QuickSort::sort<Method*>(methods->data(), length, method_comparator, idempotent); |
duke@435 | 1358 | } |
duke@435 | 1359 | // Reset method ordering |
duke@435 | 1360 | for (int i = 0; i < length; i++) { |
coleenp@4037 | 1361 | Method* m = methods->at(i); |
duke@435 | 1362 | m->set_method_idnum(i); |
duke@435 | 1363 | } |
duke@435 | 1364 | } |
duke@435 | 1365 | } |
duke@435 | 1366 | |
duke@435 | 1367 | |
duke@435 | 1368 | //----------------------------------------------------------------------------------- |
dcubed@4562 | 1369 | // Non-product code unless JVM/TI needs it |
duke@435 | 1370 | |
dcubed@4562 | 1371 | #if !defined(PRODUCT) || INCLUDE_JVMTI |
duke@435 | 1372 | class SignatureTypePrinter : public SignatureTypeNames { |
duke@435 | 1373 | private: |
duke@435 | 1374 | outputStream* _st; |
duke@435 | 1375 | bool _use_separator; |
duke@435 | 1376 | |
duke@435 | 1377 | void type_name(const char* name) { |
duke@435 | 1378 | if (_use_separator) _st->print(", "); |
duke@435 | 1379 | _st->print(name); |
duke@435 | 1380 | _use_separator = true; |
duke@435 | 1381 | } |
duke@435 | 1382 | |
duke@435 | 1383 | public: |
coleenp@2497 | 1384 | SignatureTypePrinter(Symbol* signature, outputStream* st) : SignatureTypeNames(signature) { |
duke@435 | 1385 | _st = st; |
duke@435 | 1386 | _use_separator = false; |
duke@435 | 1387 | } |
duke@435 | 1388 | |
duke@435 | 1389 | void print_parameters() { _use_separator = false; iterate_parameters(); } |
duke@435 | 1390 | void print_returntype() { _use_separator = false; iterate_returntype(); } |
duke@435 | 1391 | }; |
duke@435 | 1392 | |
duke@435 | 1393 | |
coleenp@4037 | 1394 | void Method::print_name(outputStream* st) { |
duke@435 | 1395 | Thread *thread = Thread::current(); |
duke@435 | 1396 | ResourceMark rm(thread); |
duke@435 | 1397 | SignatureTypePrinter sig(signature(), st); |
duke@435 | 1398 | st->print("%s ", is_static() ? "static" : "virtual"); |
duke@435 | 1399 | sig.print_returntype(); |
coleenp@4037 | 1400 | st->print(" %s.", method_holder()->internal_name()); |
duke@435 | 1401 | name()->print_symbol_on(st); |
duke@435 | 1402 | st->print("("); |
duke@435 | 1403 | sig.print_parameters(); |
duke@435 | 1404 | st->print(")"); |
duke@435 | 1405 | } |
dcubed@4562 | 1406 | #endif // !PRODUCT || INCLUDE_JVMTI |
duke@435 | 1407 | |
duke@435 | 1408 | |
dcubed@4562 | 1409 | //----------------------------------------------------------------------------------- |
dcubed@4562 | 1410 | // Non-product code |
dcubed@4562 | 1411 | |
dcubed@4562 | 1412 | #ifndef PRODUCT |
coleenp@4037 | 1413 | void Method::print_codes_on(outputStream* st) const { |
duke@435 | 1414 | print_codes_on(0, code_size(), st); |
duke@435 | 1415 | } |
duke@435 | 1416 | |
coleenp@4037 | 1417 | void Method::print_codes_on(int from, int to, outputStream* st) const { |
duke@435 | 1418 | Thread *thread = Thread::current(); |
duke@435 | 1419 | ResourceMark rm(thread); |
coleenp@4037 | 1420 | methodHandle mh (thread, (Method*)this); |
duke@435 | 1421 | BytecodeStream s(mh); |
duke@435 | 1422 | s.set_interval(from, to); |
duke@435 | 1423 | BytecodeTracer::set_closure(BytecodeTracer::std_closure()); |
duke@435 | 1424 | while (s.next() >= 0) BytecodeTracer::trace(mh, s.bcp(), st); |
duke@435 | 1425 | } |
duke@435 | 1426 | #endif // not PRODUCT |
duke@435 | 1427 | |
duke@435 | 1428 | |
duke@435 | 1429 | // Simple compression of line number tables. We use a regular compressed stream, except that we compress deltas |
duke@435 | 1430 | // between (bci,line) pairs since they are smaller. If (bci delta, line delta) fits in (5-bit unsigned, 3-bit unsigned) |
duke@435 | 1431 | // we save it as one byte, otherwise we write a 0xFF escape character and use regular compression. 0x0 is used |
duke@435 | 1432 | // as end-of-stream terminator. |
duke@435 | 1433 | |
duke@435 | 1434 | void CompressedLineNumberWriteStream::write_pair_regular(int bci_delta, int line_delta) { |
duke@435 | 1435 | // bci and line number does not compress into single byte. |
duke@435 | 1436 | // Write out escape character and use regular compression for bci and line number. |
duke@435 | 1437 | write_byte((jubyte)0xFF); |
duke@435 | 1438 | write_signed_int(bci_delta); |
duke@435 | 1439 | write_signed_int(line_delta); |
duke@435 | 1440 | } |
duke@435 | 1441 | |
coleenp@4037 | 1442 | // See comment in method.hpp which explains why this exists. |
sla@2540 | 1443 | #if defined(_M_AMD64) && _MSC_VER >= 1400 |
duke@435 | 1444 | #pragma optimize("", off) |
duke@435 | 1445 | void CompressedLineNumberWriteStream::write_pair(int bci, int line) { |
duke@435 | 1446 | write_pair_inline(bci, line); |
duke@435 | 1447 | } |
duke@435 | 1448 | #pragma optimize("", on) |
duke@435 | 1449 | #endif |
duke@435 | 1450 | |
duke@435 | 1451 | CompressedLineNumberReadStream::CompressedLineNumberReadStream(u_char* buffer) : CompressedReadStream(buffer) { |
duke@435 | 1452 | _bci = 0; |
duke@435 | 1453 | _line = 0; |
duke@435 | 1454 | }; |
duke@435 | 1455 | |
duke@435 | 1456 | |
duke@435 | 1457 | bool CompressedLineNumberReadStream::read_pair() { |
duke@435 | 1458 | jubyte next = read_byte(); |
duke@435 | 1459 | // Check for terminator |
duke@435 | 1460 | if (next == 0) return false; |
duke@435 | 1461 | if (next == 0xFF) { |
duke@435 | 1462 | // Escape character, regular compression used |
duke@435 | 1463 | _bci += read_signed_int(); |
duke@435 | 1464 | _line += read_signed_int(); |
duke@435 | 1465 | } else { |
duke@435 | 1466 | // Single byte compression used |
duke@435 | 1467 | _bci += next >> 3; |
duke@435 | 1468 | _line += next & 0x7; |
duke@435 | 1469 | } |
duke@435 | 1470 | return true; |
duke@435 | 1471 | } |
duke@435 | 1472 | |
duke@435 | 1473 | |
coleenp@4037 | 1474 | Bytecodes::Code Method::orig_bytecode_at(int bci) const { |
coleenp@4251 | 1475 | BreakpointInfo* bp = method_holder()->breakpoints(); |
duke@435 | 1476 | for (; bp != NULL; bp = bp->next()) { |
duke@435 | 1477 | if (bp->match(this, bci)) { |
duke@435 | 1478 | return bp->orig_bytecode(); |
duke@435 | 1479 | } |
duke@435 | 1480 | } |
duke@435 | 1481 | ShouldNotReachHere(); |
duke@435 | 1482 | return Bytecodes::_shouldnotreachhere; |
duke@435 | 1483 | } |
duke@435 | 1484 | |
coleenp@4037 | 1485 | void Method::set_orig_bytecode_at(int bci, Bytecodes::Code code) { |
duke@435 | 1486 | assert(code != Bytecodes::_breakpoint, "cannot patch breakpoints this way"); |
coleenp@4251 | 1487 | BreakpointInfo* bp = method_holder()->breakpoints(); |
duke@435 | 1488 | for (; bp != NULL; bp = bp->next()) { |
duke@435 | 1489 | if (bp->match(this, bci)) { |
duke@435 | 1490 | bp->set_orig_bytecode(code); |
duke@435 | 1491 | // and continue, in case there is more than one |
duke@435 | 1492 | } |
duke@435 | 1493 | } |
duke@435 | 1494 | } |
duke@435 | 1495 | |
coleenp@4037 | 1496 | void Method::set_breakpoint(int bci) { |
coleenp@4251 | 1497 | InstanceKlass* ik = method_holder(); |
duke@435 | 1498 | BreakpointInfo *bp = new BreakpointInfo(this, bci); |
duke@435 | 1499 | bp->set_next(ik->breakpoints()); |
duke@435 | 1500 | ik->set_breakpoints(bp); |
duke@435 | 1501 | // do this last: |
duke@435 | 1502 | bp->set(this); |
duke@435 | 1503 | } |
duke@435 | 1504 | |
coleenp@4037 | 1505 | static void clear_matches(Method* m, int bci) { |
coleenp@4251 | 1506 | InstanceKlass* ik = m->method_holder(); |
duke@435 | 1507 | BreakpointInfo* prev_bp = NULL; |
duke@435 | 1508 | BreakpointInfo* next_bp; |
duke@435 | 1509 | for (BreakpointInfo* bp = ik->breakpoints(); bp != NULL; bp = next_bp) { |
duke@435 | 1510 | next_bp = bp->next(); |
duke@435 | 1511 | // bci value of -1 is used to delete all breakpoints in method m (ex: clear_all_breakpoint). |
duke@435 | 1512 | if (bci >= 0 ? bp->match(m, bci) : bp->match(m)) { |
duke@435 | 1513 | // do this first: |
duke@435 | 1514 | bp->clear(m); |
duke@435 | 1515 | // unhook it |
duke@435 | 1516 | if (prev_bp != NULL) |
duke@435 | 1517 | prev_bp->set_next(next_bp); |
duke@435 | 1518 | else |
duke@435 | 1519 | ik->set_breakpoints(next_bp); |
duke@435 | 1520 | delete bp; |
duke@435 | 1521 | // When class is redefined JVMTI sets breakpoint in all versions of EMCP methods |
duke@435 | 1522 | // at same location. So we have multiple matching (method_index and bci) |
duke@435 | 1523 | // BreakpointInfo nodes in BreakpointInfo list. We should just delete one |
duke@435 | 1524 | // breakpoint for clear_breakpoint request and keep all other method versions |
duke@435 | 1525 | // BreakpointInfo for future clear_breakpoint request. |
duke@435 | 1526 | // bcivalue of -1 is used to clear all breakpoints (see clear_all_breakpoints) |
duke@435 | 1527 | // which is being called when class is unloaded. We delete all the Breakpoint |
duke@435 | 1528 | // information for all versions of method. We may not correctly restore the original |
duke@435 | 1529 | // bytecode in all method versions, but that is ok. Because the class is being unloaded |
duke@435 | 1530 | // so these methods won't be used anymore. |
duke@435 | 1531 | if (bci >= 0) { |
duke@435 | 1532 | break; |
duke@435 | 1533 | } |
duke@435 | 1534 | } else { |
duke@435 | 1535 | // This one is a keeper. |
duke@435 | 1536 | prev_bp = bp; |
duke@435 | 1537 | } |
duke@435 | 1538 | } |
duke@435 | 1539 | } |
duke@435 | 1540 | |
coleenp@4037 | 1541 | void Method::clear_breakpoint(int bci) { |
duke@435 | 1542 | assert(bci >= 0, ""); |
duke@435 | 1543 | clear_matches(this, bci); |
duke@435 | 1544 | } |
duke@435 | 1545 | |
coleenp@4037 | 1546 | void Method::clear_all_breakpoints() { |
duke@435 | 1547 | clear_matches(this, -1); |
duke@435 | 1548 | } |
duke@435 | 1549 | |
duke@435 | 1550 | |
coleenp@4037 | 1551 | int Method::invocation_count() { |
jiangli@4936 | 1552 | MethodCounters *mcs = method_counters(); |
iveresov@2138 | 1553 | if (TieredCompilation) { |
coleenp@4037 | 1554 | MethodData* const mdo = method_data(); |
jiangli@4936 | 1555 | if (((mcs != NULL) ? mcs->invocation_counter()->carry() : false) || |
jiangli@4936 | 1556 | ((mdo != NULL) ? mdo->invocation_counter()->carry() : false)) { |
iveresov@2138 | 1557 | return InvocationCounter::count_limit; |
iveresov@2138 | 1558 | } else { |
jiangli@4936 | 1559 | return ((mcs != NULL) ? mcs->invocation_counter()->count() : 0) + |
jiangli@4936 | 1560 | ((mdo != NULL) ? mdo->invocation_counter()->count() : 0); |
iveresov@2138 | 1561 | } |
iveresov@2138 | 1562 | } else { |
jiangli@4936 | 1563 | return (mcs == NULL) ? 0 : mcs->invocation_counter()->count(); |
iveresov@2138 | 1564 | } |
iveresov@2138 | 1565 | } |
iveresov@2138 | 1566 | |
coleenp@4037 | 1567 | int Method::backedge_count() { |
jiangli@4936 | 1568 | MethodCounters *mcs = method_counters(); |
iveresov@2138 | 1569 | if (TieredCompilation) { |
coleenp@4037 | 1570 | MethodData* const mdo = method_data(); |
jiangli@4936 | 1571 | if (((mcs != NULL) ? mcs->backedge_counter()->carry() : false) || |
jiangli@4936 | 1572 | ((mdo != NULL) ? mdo->backedge_counter()->carry() : false)) { |
iveresov@2138 | 1573 | return InvocationCounter::count_limit; |
iveresov@2138 | 1574 | } else { |
jiangli@4936 | 1575 | return ((mcs != NULL) ? mcs->backedge_counter()->count() : 0) + |
jiangli@4936 | 1576 | ((mdo != NULL) ? mdo->backedge_counter()->count() : 0); |
iveresov@2138 | 1577 | } |
iveresov@2138 | 1578 | } else { |
jiangli@4936 | 1579 | return (mcs == NULL) ? 0 : mcs->backedge_counter()->count(); |
iveresov@2138 | 1580 | } |
iveresov@2138 | 1581 | } |
iveresov@2138 | 1582 | |
coleenp@4037 | 1583 | int Method::highest_comp_level() const { |
coleenp@4037 | 1584 | MethodData* mdo = method_data(); |
iveresov@2138 | 1585 | if (mdo != NULL) { |
iveresov@2138 | 1586 | return mdo->highest_comp_level(); |
iveresov@2138 | 1587 | } else { |
iveresov@2138 | 1588 | return CompLevel_none; |
iveresov@2138 | 1589 | } |
iveresov@2138 | 1590 | } |
iveresov@2138 | 1591 | |
coleenp@4037 | 1592 | int Method::highest_osr_comp_level() const { |
coleenp@4037 | 1593 | MethodData* mdo = method_data(); |
iveresov@2138 | 1594 | if (mdo != NULL) { |
iveresov@2138 | 1595 | return mdo->highest_osr_comp_level(); |
iveresov@2138 | 1596 | } else { |
iveresov@2138 | 1597 | return CompLevel_none; |
iveresov@2138 | 1598 | } |
iveresov@2138 | 1599 | } |
iveresov@2138 | 1600 | |
coleenp@4037 | 1601 | void Method::set_highest_comp_level(int level) { |
coleenp@4037 | 1602 | MethodData* mdo = method_data(); |
iveresov@2138 | 1603 | if (mdo != NULL) { |
iveresov@2138 | 1604 | mdo->set_highest_comp_level(level); |
iveresov@2138 | 1605 | } |
iveresov@2138 | 1606 | } |
iveresov@2138 | 1607 | |
coleenp@4037 | 1608 | void Method::set_highest_osr_comp_level(int level) { |
coleenp@4037 | 1609 | MethodData* mdo = method_data(); |
iveresov@2138 | 1610 | if (mdo != NULL) { |
iveresov@2138 | 1611 | mdo->set_highest_osr_comp_level(level); |
iveresov@2138 | 1612 | } |
iveresov@2138 | 1613 | } |
iveresov@2138 | 1614 | |
coleenp@4037 | 1615 | BreakpointInfo::BreakpointInfo(Method* m, int bci) { |
duke@435 | 1616 | _bci = bci; |
duke@435 | 1617 | _name_index = m->name_index(); |
duke@435 | 1618 | _signature_index = m->signature_index(); |
duke@435 | 1619 | _orig_bytecode = (Bytecodes::Code) *m->bcp_from(_bci); |
duke@435 | 1620 | if (_orig_bytecode == Bytecodes::_breakpoint) |
duke@435 | 1621 | _orig_bytecode = m->orig_bytecode_at(_bci); |
duke@435 | 1622 | _next = NULL; |
duke@435 | 1623 | } |
duke@435 | 1624 | |
coleenp@4037 | 1625 | void BreakpointInfo::set(Method* method) { |
duke@435 | 1626 | #ifdef ASSERT |
duke@435 | 1627 | { |
duke@435 | 1628 | Bytecodes::Code code = (Bytecodes::Code) *method->bcp_from(_bci); |
duke@435 | 1629 | if (code == Bytecodes::_breakpoint) |
duke@435 | 1630 | code = method->orig_bytecode_at(_bci); |
duke@435 | 1631 | assert(orig_bytecode() == code, "original bytecode must be the same"); |
duke@435 | 1632 | } |
duke@435 | 1633 | #endif |
jiangli@4936 | 1634 | Thread *thread = Thread::current(); |
duke@435 | 1635 | *method->bcp_from(_bci) = Bytecodes::_breakpoint; |
jiangli@4936 | 1636 | method->incr_number_of_breakpoints(thread); |
duke@435 | 1637 | SystemDictionary::notice_modification(); |
duke@435 | 1638 | { |
duke@435 | 1639 | // Deoptimize all dependents on this method |
duke@435 | 1640 | HandleMark hm(thread); |
duke@435 | 1641 | methodHandle mh(thread, method); |
duke@435 | 1642 | Universe::flush_dependents_on_method(mh); |
duke@435 | 1643 | } |
duke@435 | 1644 | } |
duke@435 | 1645 | |
coleenp@4037 | 1646 | void BreakpointInfo::clear(Method* method) { |
duke@435 | 1647 | *method->bcp_from(_bci) = orig_bytecode(); |
duke@435 | 1648 | assert(method->number_of_breakpoints() > 0, "must not go negative"); |
jiangli@4936 | 1649 | method->decr_number_of_breakpoints(Thread::current()); |
duke@435 | 1650 | } |
coleenp@4037 | 1651 | |
coleenp@4037 | 1652 | // jmethodID handling |
coleenp@4037 | 1653 | |
coleenp@4037 | 1654 | // This is a block allocating object, sort of like JNIHandleBlock, only a |
coleenp@4037 | 1655 | // lot simpler. There aren't many of these, they aren't long, they are rarely |
coleenp@4037 | 1656 | // deleted and so we can do some suboptimal things. |
coleenp@4037 | 1657 | // It's allocated on the CHeap because once we allocate a jmethodID, we can |
coleenp@4037 | 1658 | // never get rid of it. |
coleenp@4037 | 1659 | // It would be nice to be able to parameterize the number of methods for |
coleenp@4037 | 1660 | // the null_class_loader but then we'd have to turn this and ClassLoaderData |
coleenp@4037 | 1661 | // into templates. |
coleenp@4037 | 1662 | |
coleenp@4037 | 1663 | // I feel like this brain dead class should exist somewhere in the STL |
coleenp@4037 | 1664 | |
coleenp@4037 | 1665 | class JNIMethodBlock : public CHeapObj<mtClass> { |
coleenp@4037 | 1666 | enum { number_of_methods = 8 }; |
coleenp@4037 | 1667 | |
coleenp@4037 | 1668 | Method* _methods[number_of_methods]; |
coleenp@4037 | 1669 | int _top; |
coleenp@4037 | 1670 | JNIMethodBlock* _next; |
coleenp@4037 | 1671 | public: |
coleenp@4037 | 1672 | static Method* const _free_method; |
coleenp@4037 | 1673 | |
coleenp@4037 | 1674 | JNIMethodBlock() : _next(NULL), _top(0) { |
coleenp@4037 | 1675 | for (int i = 0; i< number_of_methods; i++) _methods[i] = _free_method; |
coleenp@4037 | 1676 | } |
coleenp@4037 | 1677 | |
coleenp@4037 | 1678 | Method** add_method(Method* m) { |
coleenp@4037 | 1679 | if (_top < number_of_methods) { |
coleenp@4037 | 1680 | // top points to the next free entry. |
coleenp@4037 | 1681 | int i = _top; |
coleenp@4037 | 1682 | _methods[i] = m; |
coleenp@4037 | 1683 | _top++; |
coleenp@4037 | 1684 | return &_methods[i]; |
coleenp@4037 | 1685 | } else if (_top == number_of_methods) { |
coleenp@4037 | 1686 | // if the next free entry ran off the block see if there's a free entry |
coleenp@4037 | 1687 | for (int i = 0; i< number_of_methods; i++) { |
coleenp@4037 | 1688 | if (_methods[i] == _free_method) { |
coleenp@4037 | 1689 | _methods[i] = m; |
coleenp@4037 | 1690 | return &_methods[i]; |
coleenp@4037 | 1691 | } |
coleenp@4037 | 1692 | } |
coleenp@4037 | 1693 | // Only check each block once for frees. They're very unlikely. |
coleenp@4037 | 1694 | // Increment top past the end of the block. |
coleenp@4037 | 1695 | _top++; |
coleenp@4037 | 1696 | } |
coleenp@4037 | 1697 | // need to allocate a next block. |
coleenp@4037 | 1698 | if (_next == NULL) { |
coleenp@4037 | 1699 | _next = new JNIMethodBlock(); |
coleenp@4037 | 1700 | } |
coleenp@4037 | 1701 | return _next->add_method(m); |
coleenp@4037 | 1702 | } |
coleenp@4037 | 1703 | |
coleenp@4037 | 1704 | bool contains(Method** m) { |
coleenp@4037 | 1705 | for (JNIMethodBlock* b = this; b != NULL; b = b->_next) { |
coleenp@4037 | 1706 | for (int i = 0; i< number_of_methods; i++) { |
coleenp@4037 | 1707 | if (&(b->_methods[i]) == m) { |
coleenp@4037 | 1708 | return true; |
coleenp@4037 | 1709 | } |
coleenp@4037 | 1710 | } |
coleenp@4037 | 1711 | } |
coleenp@4037 | 1712 | return false; // not found |
coleenp@4037 | 1713 | } |
coleenp@4037 | 1714 | |
coleenp@4037 | 1715 | // Doesn't really destroy it, just marks it as free so it can be reused. |
coleenp@4037 | 1716 | void destroy_method(Method** m) { |
coleenp@4037 | 1717 | #ifdef ASSERT |
coleenp@4037 | 1718 | assert(contains(m), "should be a methodID"); |
coleenp@4037 | 1719 | #endif // ASSERT |
coleenp@4037 | 1720 | *m = _free_method; |
coleenp@4037 | 1721 | } |
coleenp@4037 | 1722 | |
coleenp@4037 | 1723 | // During class unloading the methods are cleared, which is different |
coleenp@4037 | 1724 | // than freed. |
coleenp@4037 | 1725 | void clear_all_methods() { |
coleenp@4037 | 1726 | for (JNIMethodBlock* b = this; b != NULL; b = b->_next) { |
coleenp@4037 | 1727 | for (int i = 0; i< number_of_methods; i++) { |
coleenp@4037 | 1728 | _methods[i] = NULL; |
coleenp@4037 | 1729 | } |
coleenp@4037 | 1730 | } |
coleenp@4037 | 1731 | } |
coleenp@4037 | 1732 | #ifndef PRODUCT |
coleenp@4037 | 1733 | int count_methods() { |
coleenp@4037 | 1734 | // count all allocated methods |
coleenp@4037 | 1735 | int count = 0; |
coleenp@4037 | 1736 | for (JNIMethodBlock* b = this; b != NULL; b = b->_next) { |
coleenp@4037 | 1737 | for (int i = 0; i< number_of_methods; i++) { |
coleenp@4037 | 1738 | if (_methods[i] != _free_method) count++; |
coleenp@4037 | 1739 | } |
coleenp@4037 | 1740 | } |
coleenp@4037 | 1741 | return count; |
coleenp@4037 | 1742 | } |
coleenp@4037 | 1743 | #endif // PRODUCT |
coleenp@4037 | 1744 | }; |
coleenp@4037 | 1745 | |
coleenp@4037 | 1746 | // Something that can't be mistaken for an address or a markOop |
coleenp@4037 | 1747 | Method* const JNIMethodBlock::_free_method = (Method*)55; |
coleenp@4037 | 1748 | |
coleenp@4037 | 1749 | // Add a method id to the jmethod_ids |
coleenp@4037 | 1750 | jmethodID Method::make_jmethod_id(ClassLoaderData* loader_data, Method* m) { |
coleenp@4037 | 1751 | ClassLoaderData* cld = loader_data; |
coleenp@4037 | 1752 | |
coleenp@4037 | 1753 | if (!SafepointSynchronize::is_at_safepoint()) { |
coleenp@4037 | 1754 | // Have to add jmethod_ids() to class loader data thread-safely. |
coleenp@4037 | 1755 | // Also have to add the method to the list safely, which the cld lock |
coleenp@4037 | 1756 | // protects as well. |
coleenp@4037 | 1757 | MutexLockerEx ml(cld->metaspace_lock(), Mutex::_no_safepoint_check_flag); |
coleenp@4037 | 1758 | if (cld->jmethod_ids() == NULL) { |
coleenp@4037 | 1759 | cld->set_jmethod_ids(new JNIMethodBlock()); |
coleenp@4037 | 1760 | } |
coleenp@4037 | 1761 | // jmethodID is a pointer to Method* |
coleenp@4037 | 1762 | return (jmethodID)cld->jmethod_ids()->add_method(m); |
coleenp@4037 | 1763 | } else { |
coleenp@4037 | 1764 | // At safepoint, we are single threaded and can set this. |
coleenp@4037 | 1765 | if (cld->jmethod_ids() == NULL) { |
coleenp@4037 | 1766 | cld->set_jmethod_ids(new JNIMethodBlock()); |
coleenp@4037 | 1767 | } |
coleenp@4037 | 1768 | // jmethodID is a pointer to Method* |
coleenp@4037 | 1769 | return (jmethodID)cld->jmethod_ids()->add_method(m); |
coleenp@4037 | 1770 | } |
coleenp@4037 | 1771 | } |
coleenp@4037 | 1772 | |
coleenp@4037 | 1773 | // Mark a jmethodID as free. This is called when there is a data race in |
coleenp@4037 | 1774 | // InstanceKlass while creating the jmethodID cache. |
coleenp@4037 | 1775 | void Method::destroy_jmethod_id(ClassLoaderData* loader_data, jmethodID m) { |
coleenp@4037 | 1776 | ClassLoaderData* cld = loader_data; |
coleenp@4037 | 1777 | Method** ptr = (Method**)m; |
coleenp@4037 | 1778 | assert(cld->jmethod_ids() != NULL, "should have method handles"); |
coleenp@4037 | 1779 | cld->jmethod_ids()->destroy_method(ptr); |
coleenp@4037 | 1780 | } |
coleenp@4037 | 1781 | |
coleenp@4037 | 1782 | void Method::change_method_associated_with_jmethod_id(jmethodID jmid, Method* new_method) { |
coleenp@4037 | 1783 | // Can't assert the method_holder is the same because the new method has the |
coleenp@4037 | 1784 | // scratch method holder. |
coleenp@4037 | 1785 | assert(resolve_jmethod_id(jmid)->method_holder()->class_loader() |
coleenp@4037 | 1786 | == new_method->method_holder()->class_loader(), |
coleenp@4037 | 1787 | "changing to a different class loader"); |
coleenp@4037 | 1788 | // Just change the method in place, jmethodID pointer doesn't change. |
coleenp@4037 | 1789 | *((Method**)jmid) = new_method; |
coleenp@4037 | 1790 | } |
coleenp@4037 | 1791 | |
coleenp@4037 | 1792 | bool Method::is_method_id(jmethodID mid) { |
coleenp@4037 | 1793 | Method* m = resolve_jmethod_id(mid); |
coleenp@4037 | 1794 | assert(m != NULL, "should be called with non-null method"); |
coleenp@4251 | 1795 | InstanceKlass* ik = m->method_holder(); |
coleenp@4037 | 1796 | ClassLoaderData* cld = ik->class_loader_data(); |
coleenp@4037 | 1797 | if (cld->jmethod_ids() == NULL) return false; |
coleenp@4037 | 1798 | return (cld->jmethod_ids()->contains((Method**)mid)); |
coleenp@4037 | 1799 | } |
coleenp@4037 | 1800 | |
coleenp@4037 | 1801 | Method* Method::checked_resolve_jmethod_id(jmethodID mid) { |
coleenp@4037 | 1802 | if (mid == NULL) return NULL; |
coleenp@4037 | 1803 | Method* o = resolve_jmethod_id(mid); |
coleenp@4037 | 1804 | if (o == NULL || o == JNIMethodBlock::_free_method || !((Metadata*)o)->is_method()) { |
coleenp@4037 | 1805 | return NULL; |
coleenp@4037 | 1806 | } |
coleenp@4037 | 1807 | return o; |
coleenp@4037 | 1808 | }; |
coleenp@4037 | 1809 | |
coleenp@4037 | 1810 | void Method::set_on_stack(const bool value) { |
coleenp@4037 | 1811 | // Set both the method itself and its constant pool. The constant pool |
coleenp@4037 | 1812 | // on stack means some method referring to it is also on the stack. |
coleenp@4037 | 1813 | _access_flags.set_on_stack(value); |
coleenp@4037 | 1814 | constants()->set_on_stack(value); |
coleenp@4037 | 1815 | if (value) MetadataOnStackMark::record(this); |
coleenp@4037 | 1816 | } |
coleenp@4037 | 1817 | |
coleenp@4037 | 1818 | // Called when the class loader is unloaded to make all methods weak. |
coleenp@4037 | 1819 | void Method::clear_jmethod_ids(ClassLoaderData* loader_data) { |
coleenp@4037 | 1820 | loader_data->jmethod_ids()->clear_all_methods(); |
coleenp@4037 | 1821 | } |
coleenp@4037 | 1822 | |
coleenp@4295 | 1823 | |
coleenp@4295 | 1824 | // Check that this pointer is valid by checking that the vtbl pointer matches |
coleenp@4295 | 1825 | bool Method::is_valid_method() const { |
coleenp@4295 | 1826 | if (this == NULL) { |
coleenp@4295 | 1827 | return false; |
coleenp@4295 | 1828 | } else if (!is_metaspace_object()) { |
coleenp@4295 | 1829 | return false; |
coleenp@4295 | 1830 | } else { |
coleenp@4295 | 1831 | Method m; |
coleenp@4295 | 1832 | // This assumes that the vtbl pointer is the first word of a C++ object. |
coleenp@4295 | 1833 | // This assumption is also in universe.cpp patch_klass_vtble |
coleenp@4295 | 1834 | void* vtbl2 = dereference_vptr((void*)&m); |
coleenp@4295 | 1835 | void* this_vtbl = dereference_vptr((void*)this); |
coleenp@4295 | 1836 | return vtbl2 == this_vtbl; |
coleenp@4295 | 1837 | } |
coleenp@4295 | 1838 | } |
coleenp@4295 | 1839 | |
coleenp@4037 | 1840 | #ifndef PRODUCT |
coleenp@4037 | 1841 | void Method::print_jmethod_ids(ClassLoaderData* loader_data, outputStream* out) { |
coleenp@4037 | 1842 | out->print_cr("jni_method_id count = %d", loader_data->jmethod_ids()->count_methods()); |
coleenp@4037 | 1843 | } |
coleenp@4037 | 1844 | #endif // PRODUCT |
coleenp@4037 | 1845 | |
coleenp@4037 | 1846 | |
coleenp@4037 | 1847 | // Printing |
coleenp@4037 | 1848 | |
coleenp@4037 | 1849 | #ifndef PRODUCT |
coleenp@4037 | 1850 | |
coleenp@4037 | 1851 | void Method::print_on(outputStream* st) const { |
coleenp@4037 | 1852 | ResourceMark rm; |
coleenp@4037 | 1853 | assert(is_method(), "must be method"); |
coleenp@4037 | 1854 | st->print_cr(internal_name()); |
coleenp@4037 | 1855 | // get the effect of PrintOopAddress, always, for methods: |
coleenp@4037 | 1856 | st->print_cr(" - this oop: "INTPTR_FORMAT, (intptr_t)this); |
coleenp@4037 | 1857 | st->print (" - method holder: "); method_holder()->print_value_on(st); st->cr(); |
coleenp@4037 | 1858 | st->print (" - constants: "INTPTR_FORMAT" ", (address)constants()); |
coleenp@4037 | 1859 | constants()->print_value_on(st); st->cr(); |
coleenp@4037 | 1860 | st->print (" - access: 0x%x ", access_flags().as_int()); access_flags().print_on(st); st->cr(); |
coleenp@4037 | 1861 | st->print (" - name: "); name()->print_value_on(st); st->cr(); |
coleenp@4037 | 1862 | st->print (" - signature: "); signature()->print_value_on(st); st->cr(); |
coleenp@4037 | 1863 | st->print_cr(" - max stack: %d", max_stack()); |
coleenp@4037 | 1864 | st->print_cr(" - max locals: %d", max_locals()); |
coleenp@4037 | 1865 | st->print_cr(" - size of params: %d", size_of_parameters()); |
coleenp@4037 | 1866 | st->print_cr(" - method size: %d", method_size()); |
coleenp@4037 | 1867 | if (intrinsic_id() != vmIntrinsics::_none) |
coleenp@4037 | 1868 | st->print_cr(" - intrinsic id: %d %s", intrinsic_id(), vmIntrinsics::name_at(intrinsic_id())); |
coleenp@4037 | 1869 | if (highest_comp_level() != CompLevel_none) |
coleenp@4037 | 1870 | st->print_cr(" - highest level: %d", highest_comp_level()); |
coleenp@4037 | 1871 | st->print_cr(" - vtable index: %d", _vtable_index); |
coleenp@4037 | 1872 | st->print_cr(" - i2i entry: " INTPTR_FORMAT, interpreter_entry()); |
coleenp@4037 | 1873 | st->print( " - adapters: "); |
coleenp@4037 | 1874 | AdapterHandlerEntry* a = ((Method*)this)->adapter(); |
coleenp@4037 | 1875 | if (a == NULL) |
coleenp@4037 | 1876 | st->print_cr(INTPTR_FORMAT, a); |
coleenp@4037 | 1877 | else |
coleenp@4037 | 1878 | a->print_adapter_on(st); |
coleenp@4037 | 1879 | st->print_cr(" - compiled entry " INTPTR_FORMAT, from_compiled_entry()); |
coleenp@4037 | 1880 | st->print_cr(" - code size: %d", code_size()); |
coleenp@4037 | 1881 | if (code_size() != 0) { |
coleenp@4037 | 1882 | st->print_cr(" - code start: " INTPTR_FORMAT, code_base()); |
coleenp@4037 | 1883 | st->print_cr(" - code end (excl): " INTPTR_FORMAT, code_base() + code_size()); |
coleenp@4037 | 1884 | } |
coleenp@4037 | 1885 | if (method_data() != NULL) { |
coleenp@4037 | 1886 | st->print_cr(" - method data: " INTPTR_FORMAT, (address)method_data()); |
coleenp@4037 | 1887 | } |
coleenp@4037 | 1888 | st->print_cr(" - checked ex length: %d", checked_exceptions_length()); |
coleenp@4037 | 1889 | if (checked_exceptions_length() > 0) { |
coleenp@4037 | 1890 | CheckedExceptionElement* table = checked_exceptions_start(); |
coleenp@4037 | 1891 | st->print_cr(" - checked ex start: " INTPTR_FORMAT, table); |
coleenp@4037 | 1892 | if (Verbose) { |
coleenp@4037 | 1893 | for (int i = 0; i < checked_exceptions_length(); i++) { |
coleenp@4037 | 1894 | st->print_cr(" - throws %s", constants()->printable_name_at(table[i].class_cp_index)); |
coleenp@4037 | 1895 | } |
coleenp@4037 | 1896 | } |
coleenp@4037 | 1897 | } |
coleenp@4037 | 1898 | if (has_linenumber_table()) { |
coleenp@4037 | 1899 | u_char* table = compressed_linenumber_table(); |
coleenp@4037 | 1900 | st->print_cr(" - linenumber start: " INTPTR_FORMAT, table); |
coleenp@4037 | 1901 | if (Verbose) { |
coleenp@4037 | 1902 | CompressedLineNumberReadStream stream(table); |
coleenp@4037 | 1903 | while (stream.read_pair()) { |
coleenp@4037 | 1904 | st->print_cr(" - line %d: %d", stream.line(), stream.bci()); |
coleenp@4037 | 1905 | } |
coleenp@4037 | 1906 | } |
coleenp@4037 | 1907 | } |
coleenp@4037 | 1908 | st->print_cr(" - localvar length: %d", localvariable_table_length()); |
coleenp@4037 | 1909 | if (localvariable_table_length() > 0) { |
coleenp@4037 | 1910 | LocalVariableTableElement* table = localvariable_table_start(); |
coleenp@4037 | 1911 | st->print_cr(" - localvar start: " INTPTR_FORMAT, table); |
coleenp@4037 | 1912 | if (Verbose) { |
coleenp@4037 | 1913 | for (int i = 0; i < localvariable_table_length(); i++) { |
coleenp@4037 | 1914 | int bci = table[i].start_bci; |
coleenp@4037 | 1915 | int len = table[i].length; |
coleenp@4037 | 1916 | const char* name = constants()->printable_name_at(table[i].name_cp_index); |
coleenp@4037 | 1917 | const char* desc = constants()->printable_name_at(table[i].descriptor_cp_index); |
coleenp@4037 | 1918 | int slot = table[i].slot; |
coleenp@4037 | 1919 | st->print_cr(" - %s %s bci=%d len=%d slot=%d", desc, name, bci, len, slot); |
coleenp@4037 | 1920 | } |
coleenp@4037 | 1921 | } |
coleenp@4037 | 1922 | } |
coleenp@4037 | 1923 | if (code() != NULL) { |
coleenp@4037 | 1924 | st->print (" - compiled code: "); |
coleenp@4037 | 1925 | code()->print_value_on(st); |
coleenp@4037 | 1926 | } |
coleenp@4037 | 1927 | if (is_native()) { |
coleenp@4037 | 1928 | st->print_cr(" - native function: " INTPTR_FORMAT, native_function()); |
coleenp@4037 | 1929 | st->print_cr(" - signature handler: " INTPTR_FORMAT, signature_handler()); |
coleenp@4037 | 1930 | } |
coleenp@4037 | 1931 | } |
coleenp@4037 | 1932 | |
coleenp@4037 | 1933 | #endif //PRODUCT |
coleenp@4037 | 1934 | |
coleenp@4037 | 1935 | void Method::print_value_on(outputStream* st) const { |
coleenp@4037 | 1936 | assert(is_method(), "must be method"); |
coleenp@4037 | 1937 | st->print_cr(internal_name()); |
coleenp@4037 | 1938 | print_address_on(st); |
coleenp@4037 | 1939 | st->print(" "); |
coleenp@4037 | 1940 | name()->print_value_on(st); |
coleenp@4037 | 1941 | st->print(" "); |
coleenp@4037 | 1942 | signature()->print_value_on(st); |
coleenp@4037 | 1943 | st->print(" in "); |
coleenp@4037 | 1944 | method_holder()->print_value_on(st); |
coleenp@4037 | 1945 | if (WizardMode) st->print("[%d,%d]", size_of_parameters(), max_locals()); |
coleenp@4037 | 1946 | if (WizardMode && code() != NULL) st->print(" ((nmethod*)%p)", code()); |
coleenp@4037 | 1947 | } |
coleenp@4037 | 1948 | |
acorn@4497 | 1949 | #if INCLUDE_SERVICES |
acorn@4497 | 1950 | // Size Statistics |
acorn@4497 | 1951 | void Method::collect_statistics(KlassSizeStats *sz) const { |
acorn@4497 | 1952 | int mysize = sz->count(this); |
acorn@4497 | 1953 | sz->_method_bytes += mysize; |
acorn@4497 | 1954 | sz->_method_all_bytes += mysize; |
acorn@4497 | 1955 | sz->_rw_bytes += mysize; |
acorn@4497 | 1956 | |
acorn@4497 | 1957 | if (constMethod()) { |
acorn@4497 | 1958 | constMethod()->collect_statistics(sz); |
acorn@4497 | 1959 | } |
acorn@4497 | 1960 | if (method_data()) { |
acorn@4497 | 1961 | method_data()->collect_statistics(sz); |
acorn@4497 | 1962 | } |
acorn@4497 | 1963 | } |
acorn@4497 | 1964 | #endif // INCLUDE_SERVICES |
coleenp@4037 | 1965 | |
coleenp@4037 | 1966 | // Verification |
coleenp@4037 | 1967 | |
coleenp@4037 | 1968 | void Method::verify_on(outputStream* st) { |
coleenp@4037 | 1969 | guarantee(is_method(), "object must be method"); |
coleenp@4037 | 1970 | guarantee(is_metadata(), "should be metadata"); |
coleenp@4037 | 1971 | guarantee(constants()->is_constantPool(), "should be constant pool"); |
coleenp@4037 | 1972 | guarantee(constants()->is_metadata(), "should be metadata"); |
coleenp@4037 | 1973 | guarantee(constMethod()->is_constMethod(), "should be ConstMethod*"); |
coleenp@4037 | 1974 | guarantee(constMethod()->is_metadata(), "should be metadata"); |
coleenp@4037 | 1975 | MethodData* md = method_data(); |
coleenp@4037 | 1976 | guarantee(md == NULL || |
coleenp@4295 | 1977 | md->is_metadata(), "should be metadata"); |
coleenp@4037 | 1978 | guarantee(md == NULL || |
coleenp@4037 | 1979 | md->is_methodData(), "should be method data"); |
coleenp@4037 | 1980 | } |