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