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