src/share/vm/oops/method.cpp

Tue, 08 Jan 2013 14:01:36 -0500

author
coleenp
date
Tue, 08 Jan 2013 14:01:36 -0500
changeset 4398
ade95d680b42
parent 4393
35431a769282
child 4406
18c3c3fa291b
permissions
-rw-r--r--

8004728: Add hotspot support for parameter reflection
Summary: Add hotspot support for parameter reflection
Reviewed-by: acorn, jrose, coleenp
Contributed-by: eric.mccorkle@oracle.com

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

mercurial