aoqi@0: /* aoqi@0: * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #include "precompiled.hpp" aoqi@0: #include "classfile/metadataOnStackMark.hpp" aoqi@0: #include "classfile/systemDictionary.hpp" aoqi@0: #include "code/debugInfoRec.hpp" aoqi@0: #include "gc_interface/collectedHeap.inline.hpp" aoqi@0: #include "interpreter/bytecodeStream.hpp" aoqi@0: #include "interpreter/bytecodeTracer.hpp" aoqi@0: #include "interpreter/bytecodes.hpp" aoqi@0: #include "interpreter/interpreter.hpp" aoqi@0: #include "interpreter/oopMapCache.hpp" aoqi@0: #include "memory/gcLocker.hpp" aoqi@0: #include "memory/generation.hpp" aoqi@0: #include "memory/heapInspection.hpp" aoqi@0: #include "memory/metadataFactory.hpp" aoqi@0: #include "memory/oopFactory.hpp" aoqi@0: #include "oops/constMethod.hpp" aoqi@0: #include "oops/methodData.hpp" aoqi@0: #include "oops/method.hpp" aoqi@0: #include "oops/oop.inline.hpp" aoqi@0: #include "oops/symbol.hpp" aoqi@0: #include "prims/jvmtiExport.hpp" aoqi@0: #include "prims/methodHandles.hpp" aoqi@0: #include "prims/nativeLookup.hpp" aoqi@0: #include "runtime/arguments.hpp" aoqi@0: #include "runtime/compilationPolicy.hpp" aoqi@0: #include "runtime/frame.inline.hpp" aoqi@0: #include "runtime/handles.inline.hpp" aoqi@0: #include "runtime/relocator.hpp" aoqi@0: #include "runtime/sharedRuntime.hpp" aoqi@0: #include "runtime/signature.hpp" aoqi@0: #include "utilities/quickSort.hpp" aoqi@0: #include "utilities/xmlstream.hpp" aoqi@0: aoqi@0: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC aoqi@0: aoqi@0: // Implementation of Method aoqi@0: aoqi@0: Method* Method::allocate(ClassLoaderData* loader_data, aoqi@0: int byte_code_size, aoqi@0: AccessFlags access_flags, aoqi@0: InlineTableSizes* sizes, aoqi@0: ConstMethod::MethodType method_type, aoqi@0: TRAPS) { aoqi@0: assert(!access_flags.is_native() || byte_code_size == 0, aoqi@0: "native methods should not contain byte codes"); aoqi@0: ConstMethod* cm = ConstMethod::allocate(loader_data, aoqi@0: byte_code_size, aoqi@0: sizes, aoqi@0: method_type, aoqi@0: CHECK_NULL); aoqi@0: aoqi@0: int size = Method::size(access_flags.is_native()); aoqi@0: aoqi@0: return new (loader_data, size, false, MetaspaceObj::MethodType, THREAD) Method(cm, access_flags, size); aoqi@0: } aoqi@0: aoqi@0: Method::Method(ConstMethod* xconst, AccessFlags access_flags, int size) { aoqi@0: No_Safepoint_Verifier no_safepoint; aoqi@0: set_constMethod(xconst); aoqi@0: set_access_flags(access_flags); aoqi@0: set_method_size(size); aoqi@0: #ifdef CC_INTERP aoqi@0: set_result_index(T_VOID); aoqi@0: #endif aoqi@0: set_intrinsic_id(vmIntrinsics::_none); aoqi@0: set_jfr_towrite(false); aoqi@0: set_force_inline(false); aoqi@0: set_hidden(false); aoqi@0: set_dont_inline(false); aoqi@0: set_method_data(NULL); aoqi@0: set_method_counters(NULL); aoqi@0: set_vtable_index(Method::garbage_vtable_index); aoqi@0: aoqi@0: // Fix and bury in Method* aoqi@0: set_interpreter_entry(NULL); // sets i2i entry and from_int aoqi@0: set_adapter_entry(NULL); aoqi@0: clear_code(); // from_c/from_i get set to c2i/i2i aoqi@0: aoqi@0: if (access_flags.is_native()) { aoqi@0: clear_native_function(); aoqi@0: set_signature_handler(NULL); aoqi@0: } aoqi@26: aoqi@0: NOT_PRODUCT(set_compiled_invocation_count(0);) aoqi@0: } aoqi@0: aoqi@0: // Release Method*. The nmethod will be gone when we get here because aoqi@0: // we've walked the code cache. aoqi@0: void Method::deallocate_contents(ClassLoaderData* loader_data) { aoqi@0: MetadataFactory::free_metadata(loader_data, constMethod()); aoqi@0: set_constMethod(NULL); aoqi@0: MetadataFactory::free_metadata(loader_data, method_data()); aoqi@0: set_method_data(NULL); aoqi@0: MetadataFactory::free_metadata(loader_data, method_counters()); aoqi@0: set_method_counters(NULL); aoqi@0: // The nmethod will be gone when we get here. aoqi@0: if (code() != NULL) _code = NULL; aoqi@0: } aoqi@0: aoqi@0: address Method::get_i2c_entry() { aoqi@0: assert(_adapter != NULL, "must have"); aoqi@0: return _adapter->get_i2c_entry(); aoqi@0: } aoqi@0: aoqi@0: address Method::get_c2i_entry() { aoqi@0: assert(_adapter != NULL, "must have"); aoqi@0: return _adapter->get_c2i_entry(); aoqi@0: } aoqi@0: aoqi@0: address Method::get_c2i_unverified_entry() { aoqi@0: assert(_adapter != NULL, "must have"); aoqi@0: return _adapter->get_c2i_unverified_entry(); aoqi@0: } aoqi@0: aoqi@0: char* Method::name_and_sig_as_C_string() const { aoqi@0: return name_and_sig_as_C_string(constants()->pool_holder(), name(), signature()); aoqi@0: } aoqi@0: aoqi@0: char* Method::name_and_sig_as_C_string(char* buf, int size) const { aoqi@0: return name_and_sig_as_C_string(constants()->pool_holder(), name(), signature(), buf, size); aoqi@0: } aoqi@0: aoqi@0: char* Method::name_and_sig_as_C_string(Klass* klass, Symbol* method_name, Symbol* signature) { aoqi@0: const char* klass_name = klass->external_name(); aoqi@0: int klass_name_len = (int)strlen(klass_name); aoqi@0: int method_name_len = method_name->utf8_length(); aoqi@0: int len = klass_name_len + 1 + method_name_len + signature->utf8_length(); aoqi@0: char* dest = NEW_RESOURCE_ARRAY(char, len + 1); aoqi@0: strcpy(dest, klass_name); aoqi@0: dest[klass_name_len] = '.'; aoqi@0: strcpy(&dest[klass_name_len + 1], method_name->as_C_string()); aoqi@0: strcpy(&dest[klass_name_len + 1 + method_name_len], signature->as_C_string()); aoqi@0: dest[len] = 0; aoqi@0: return dest; aoqi@0: } aoqi@0: aoqi@0: char* Method::name_and_sig_as_C_string(Klass* klass, Symbol* method_name, Symbol* signature, char* buf, int size) { aoqi@0: Symbol* klass_name = klass->name(); aoqi@0: klass_name->as_klass_external_name(buf, size); aoqi@0: int len = (int)strlen(buf); aoqi@0: aoqi@0: if (len < size - 1) { aoqi@0: buf[len++] = '.'; aoqi@0: aoqi@0: method_name->as_C_string(&(buf[len]), size - len); aoqi@0: len = (int)strlen(buf); aoqi@0: aoqi@0: signature->as_C_string(&(buf[len]), size - len); aoqi@0: } aoqi@0: aoqi@0: return buf; aoqi@0: } aoqi@0: aoqi@0: int Method::fast_exception_handler_bci_for(methodHandle mh, KlassHandle ex_klass, int throw_bci, TRAPS) { aoqi@0: // exception table holds quadruple entries of the form (beg_bci, end_bci, handler_bci, klass_index) aoqi@0: // access exception table aoqi@0: ExceptionTable table(mh()); aoqi@0: int length = table.length(); aoqi@0: // iterate through all entries sequentially aoqi@0: constantPoolHandle pool(THREAD, mh->constants()); aoqi@0: for (int i = 0; i < length; i ++) { aoqi@0: //reacquire the table in case a GC happened aoqi@0: ExceptionTable table(mh()); aoqi@0: int beg_bci = table.start_pc(i); aoqi@0: int end_bci = table.end_pc(i); aoqi@0: assert(beg_bci <= end_bci, "inconsistent exception table"); aoqi@0: if (beg_bci <= throw_bci && throw_bci < end_bci) { aoqi@0: // exception handler bci range covers throw_bci => investigate further aoqi@0: int handler_bci = table.handler_pc(i); aoqi@0: int klass_index = table.catch_type_index(i); aoqi@0: if (klass_index == 0) { aoqi@0: return handler_bci; aoqi@0: } else if (ex_klass.is_null()) { aoqi@0: return handler_bci; aoqi@0: } else { aoqi@0: // we know the exception class => get the constraint class aoqi@0: // this may require loading of the constraint class; if verification aoqi@0: // fails or some other exception occurs, return handler_bci aoqi@0: Klass* k = pool->klass_at(klass_index, CHECK_(handler_bci)); aoqi@0: KlassHandle klass = KlassHandle(THREAD, k); aoqi@0: assert(klass.not_null(), "klass not loaded"); aoqi@0: if (ex_klass->is_subtype_of(klass())) { aoqi@0: return handler_bci; aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: return -1; aoqi@0: } aoqi@0: aoqi@0: void Method::mask_for(int bci, InterpreterOopMap* mask) { aoqi@0: aoqi@0: Thread* myThread = Thread::current(); aoqi@0: methodHandle h_this(myThread, this); aoqi@0: #ifdef ASSERT aoqi@0: bool has_capability = myThread->is_VM_thread() || aoqi@0: myThread->is_ConcurrentGC_thread() || aoqi@0: myThread->is_GC_task_thread(); aoqi@0: aoqi@0: if (!has_capability) { aoqi@0: if (!VerifyStack && !VerifyLastFrame) { aoqi@0: // verify stack calls this outside VM thread aoqi@0: warning("oopmap should only be accessed by the " aoqi@0: "VM, GC task or CMS threads (or during debugging)"); aoqi@0: InterpreterOopMap local_mask; aoqi@0: method_holder()->mask_for(h_this, bci, &local_mask); aoqi@0: local_mask.print(); aoqi@0: } aoqi@0: } aoqi@0: #endif aoqi@0: method_holder()->mask_for(h_this, bci, mask); aoqi@0: return; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: int Method::bci_from(address bcp) const { aoqi@0: #ifdef ASSERT aoqi@0: { ResourceMark rm; aoqi@0: assert(is_native() && bcp == code_base() || contains(bcp) || is_error_reported(), aoqi@0: err_msg("bcp doesn't belong to this method: bcp: " INTPTR_FORMAT ", method: %s", bcp, name_and_sig_as_C_string())); aoqi@0: } aoqi@0: #endif aoqi@0: return bcp - code_base(); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // Return (int)bcx if it appears to be a valid BCI. aoqi@0: // Return bci_from((address)bcx) if it appears to be a valid BCP. aoqi@0: // Return -1 otherwise. aoqi@0: // Used by profiling code, when invalid data is a possibility. aoqi@0: // The caller is responsible for validating the Method* itself. aoqi@0: int Method::validate_bci_from_bcx(intptr_t bcx) const { aoqi@0: // keep bci as -1 if not a valid bci aoqi@0: int bci = -1; aoqi@0: if (bcx == 0 || (address)bcx == code_base()) { aoqi@0: // code_size() may return 0 and we allow 0 here aoqi@0: // the method may be native aoqi@0: bci = 0; aoqi@0: } else if (frame::is_bci(bcx)) { aoqi@0: if (bcx < code_size()) { aoqi@0: bci = (int)bcx; aoqi@0: } aoqi@0: } else if (contains((address)bcx)) { aoqi@0: bci = (address)bcx - code_base(); aoqi@0: } aoqi@0: // Assert that if we have dodged any asserts, bci is negative. aoqi@0: assert(bci == -1 || bci == bci_from(bcp_from(bci)), "sane bci if >=0"); aoqi@0: return bci; aoqi@0: } aoqi@0: aoqi@0: address Method::bcp_from(int bci) const { aoqi@0: assert((is_native() && bci == 0) || (!is_native() && 0 <= bci && bci < code_size()), err_msg("illegal bci: %d", bci)); aoqi@0: address bcp = code_base() + bci; aoqi@0: assert(is_native() && bcp == code_base() || contains(bcp), "bcp doesn't belong to this method"); aoqi@0: return bcp; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: int Method::size(bool is_native) { aoqi@0: // If native, then include pointers for native_function and signature_handler aoqi@0: int extra_bytes = (is_native) ? 2*sizeof(address*) : 0; aoqi@0: int extra_words = align_size_up(extra_bytes, BytesPerWord) / BytesPerWord; aoqi@0: return align_object_size(header_size() + extra_words); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: Symbol* Method::klass_name() const { aoqi@0: Klass* k = method_holder(); aoqi@0: assert(k->is_klass(), "must be klass"); aoqi@0: InstanceKlass* ik = (InstanceKlass*) k; aoqi@0: return ik->name(); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // Attempt to return method oop to original state. Clear any pointers aoqi@0: // (to objects outside the shared spaces). We won't be able to predict aoqi@0: // where they should point in a new JVM. Further initialize some aoqi@0: // entries now in order allow them to be write protected later. aoqi@0: aoqi@0: void Method::remove_unshareable_info() { aoqi@0: unlink_method(); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: bool Method::was_executed_more_than(int n) { aoqi@0: // Invocation counter is reset when the Method* is compiled. aoqi@0: // If the method has compiled code we therefore assume it has aoqi@0: // be excuted more than n times. aoqi@0: if (is_accessor() || is_empty_method() || (code() != NULL)) { aoqi@0: // interpreter doesn't bump invocation counter of trivial methods aoqi@0: // compiler does not bump invocation counter of compiled methods aoqi@0: return true; aoqi@0: } aoqi@0: else if ((method_counters() != NULL && aoqi@0: method_counters()->invocation_counter()->carry()) || aoqi@0: (method_data() != NULL && aoqi@0: method_data()->invocation_counter()->carry())) { aoqi@0: // The carry bit is set when the counter overflows and causes aoqi@0: // a compilation to occur. We don't know how many times aoqi@0: // the counter has been reset, so we simply assume it has aoqi@0: // been executed more than n times. aoqi@0: return true; aoqi@0: } else { aoqi@0: return invocation_count() > n; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: void Method::print_invocation_count() { aoqi@0: if (is_static()) tty->print("static "); aoqi@0: if (is_final()) tty->print("final "); aoqi@0: if (is_synchronized()) tty->print("synchronized "); aoqi@0: if (is_native()) tty->print("native "); aoqi@0: method_holder()->name()->print_symbol_on(tty); aoqi@0: tty->print("."); aoqi@0: name()->print_symbol_on(tty); aoqi@0: signature()->print_symbol_on(tty); aoqi@0: aoqi@0: if (WizardMode) { aoqi@0: // dump the size of the byte codes aoqi@0: tty->print(" {%d}", code_size()); aoqi@0: } aoqi@0: tty->cr(); aoqi@0: aoqi@0: tty->print_cr (" interpreter_invocation_count: %8d ", interpreter_invocation_count()); aoqi@0: tty->print_cr (" invocation_counter: %8d ", invocation_count()); aoqi@0: tty->print_cr (" backedge_counter: %8d ", backedge_count()); aoqi@0: if (CountCompiledCalls) { aoqi@0: tty->print_cr (" compiled_invocation_count: %8d ", compiled_invocation_count()); aoqi@0: } aoqi@0: aoqi@0: } aoqi@0: #endif aoqi@0: aoqi@0: // Build a MethodData* object to hold information about this method aoqi@0: // collected in the interpreter. aoqi@0: void Method::build_interpreter_method_data(methodHandle method, TRAPS) { aoqi@0: // Do not profile method if current thread holds the pending list lock, aoqi@0: // which avoids deadlock for acquiring the MethodData_lock. aoqi@0: if (InstanceRefKlass::owns_pending_list_lock((JavaThread*)THREAD)) { aoqi@0: return; aoqi@0: } aoqi@0: aoqi@0: // Grab a lock here to prevent multiple aoqi@0: // MethodData*s from being created. aoqi@0: MutexLocker ml(MethodData_lock, THREAD); aoqi@0: if (method->method_data() == NULL) { aoqi@0: ClassLoaderData* loader_data = method->method_holder()->class_loader_data(); aoqi@0: MethodData* method_data = MethodData::allocate(loader_data, method, CHECK); aoqi@0: method->set_method_data(method_data); aoqi@0: if (PrintMethodData && (Verbose || WizardMode)) { aoqi@0: ResourceMark rm(THREAD); aoqi@0: tty->print("build_interpreter_method_data for "); aoqi@0: method->print_name(tty); aoqi@0: tty->cr(); aoqi@0: // At the end of the run, the MDO, full of data, will be dumped. aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: MethodCounters* Method::build_method_counters(Method* m, TRAPS) { aoqi@0: methodHandle mh(m); aoqi@0: ClassLoaderData* loader_data = mh->method_holder()->class_loader_data(); aoqi@0: MethodCounters* counters = MethodCounters::allocate(loader_data, CHECK_NULL); aoqi@0: if (mh->method_counters() == NULL) { aoqi@0: mh->set_method_counters(counters); aoqi@0: } else { aoqi@0: MetadataFactory::free_metadata(loader_data, counters); aoqi@0: } aoqi@0: return mh->method_counters(); aoqi@0: } aoqi@0: aoqi@0: void Method::cleanup_inline_caches() { aoqi@0: // The current system doesn't use inline caches in the interpreter aoqi@0: // => nothing to do (keep this method around for future use) aoqi@0: } aoqi@0: aoqi@0: aoqi@0: int Method::extra_stack_words() { aoqi@0: // not an inline function, to avoid a header dependency on Interpreter aoqi@0: return extra_stack_entries() * Interpreter::stackElementSize; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void Method::compute_size_of_parameters(Thread *thread) { aoqi@0: ArgumentSizeComputer asc(signature()); aoqi@0: set_size_of_parameters(asc.size() + (is_static() ? 0 : 1)); aoqi@0: } aoqi@0: aoqi@0: #ifdef CC_INTERP aoqi@0: void Method::set_result_index(BasicType type) { aoqi@0: _result_index = Interpreter::BasicType_as_index(type); aoqi@0: } aoqi@0: #endif aoqi@0: aoqi@0: BasicType Method::result_type() const { aoqi@0: ResultTypeFinder rtf(signature()); aoqi@0: return rtf.type(); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: bool Method::is_empty_method() const { aoqi@0: return code_size() == 1 aoqi@0: && *code_base() == Bytecodes::_return; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: bool Method::is_vanilla_constructor() const { aoqi@0: // Returns true if this method is a vanilla constructor, i.e. an "" "()V" method aoqi@0: // which only calls the superclass vanilla constructor and possibly does stores of aoqi@0: // zero constants to local fields: aoqi@0: // aoqi@0: // aload_0 aoqi@0: // invokespecial aoqi@0: // indexbyte1 aoqi@0: // indexbyte2 aoqi@0: // aoqi@0: // followed by an (optional) sequence of: aoqi@0: // aoqi@0: // aload_0 aoqi@0: // aconst_null / iconst_0 / fconst_0 / dconst_0 aoqi@0: // putfield aoqi@0: // indexbyte1 aoqi@0: // indexbyte2 aoqi@0: // aoqi@0: // followed by: aoqi@0: // aoqi@0: // return aoqi@0: aoqi@0: assert(name() == vmSymbols::object_initializer_name(), "Should only be called for default constructors"); aoqi@0: assert(signature() == vmSymbols::void_method_signature(), "Should only be called for default constructors"); aoqi@0: int size = code_size(); aoqi@0: // Check if size match aoqi@0: if (size == 0 || size % 5 != 0) return false; aoqi@0: address cb = code_base(); aoqi@0: int last = size - 1; aoqi@0: if (cb[0] != Bytecodes::_aload_0 || cb[1] != Bytecodes::_invokespecial || cb[last] != Bytecodes::_return) { aoqi@0: // Does not call superclass default constructor aoqi@0: return false; aoqi@0: } aoqi@0: // Check optional sequence aoqi@0: for (int i = 4; i < last; i += 5) { aoqi@0: if (cb[i] != Bytecodes::_aload_0) return false; aoqi@0: if (!Bytecodes::is_zero_const(Bytecodes::cast(cb[i+1]))) return false; aoqi@0: if (cb[i+2] != Bytecodes::_putfield) return false; aoqi@0: } aoqi@0: return true; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: bool Method::compute_has_loops_flag() { aoqi@0: BytecodeStream bcs(this); aoqi@0: Bytecodes::Code bc; aoqi@0: aoqi@0: while ((bc = bcs.next()) >= 0) { aoqi@0: switch( bc ) { aoqi@0: case Bytecodes::_ifeq: aoqi@0: case Bytecodes::_ifnull: aoqi@0: case Bytecodes::_iflt: aoqi@0: case Bytecodes::_ifle: aoqi@0: case Bytecodes::_ifne: aoqi@0: case Bytecodes::_ifnonnull: aoqi@0: case Bytecodes::_ifgt: aoqi@0: case Bytecodes::_ifge: aoqi@0: case Bytecodes::_if_icmpeq: aoqi@0: case Bytecodes::_if_icmpne: aoqi@0: case Bytecodes::_if_icmplt: aoqi@0: case Bytecodes::_if_icmpgt: aoqi@0: case Bytecodes::_if_icmple: aoqi@0: case Bytecodes::_if_icmpge: aoqi@0: case Bytecodes::_if_acmpeq: aoqi@0: case Bytecodes::_if_acmpne: aoqi@0: case Bytecodes::_goto: aoqi@0: case Bytecodes::_jsr: aoqi@0: if( bcs.dest() < bcs.next_bci() ) _access_flags.set_has_loops(); aoqi@0: break; aoqi@0: aoqi@0: case Bytecodes::_goto_w: aoqi@0: case Bytecodes::_jsr_w: aoqi@0: if( bcs.dest_w() < bcs.next_bci() ) _access_flags.set_has_loops(); aoqi@0: break; aoqi@0: } aoqi@0: } aoqi@0: _access_flags.set_loops_flag_init(); aoqi@0: return _access_flags.has_loops(); aoqi@0: } aoqi@0: aoqi@0: bool Method::is_final_method(AccessFlags class_access_flags) const { aoqi@0: // or "does_not_require_vtable_entry" aoqi@0: // default method or overpass can occur, is not final (reuses vtable entry) aoqi@0: // private methods get vtable entries for backward class compatibility. aoqi@0: if (is_overpass() || is_default_method()) return false; aoqi@0: return is_final() || class_access_flags.is_final(); aoqi@0: } aoqi@0: aoqi@0: bool Method::is_final_method() const { aoqi@0: return is_final_method(method_holder()->access_flags()); aoqi@0: } aoqi@0: aoqi@0: bool Method::is_default_method() const { aoqi@0: if (method_holder() != NULL && aoqi@0: method_holder()->is_interface() && aoqi@0: !is_abstract()) { aoqi@0: return true; aoqi@0: } else { aoqi@0: return false; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: bool Method::can_be_statically_bound(AccessFlags class_access_flags) const { aoqi@0: if (is_final_method(class_access_flags)) return true; aoqi@0: #ifdef ASSERT aoqi@0: ResourceMark rm; aoqi@0: bool is_nonv = (vtable_index() == nonvirtual_vtable_index); aoqi@0: if (class_access_flags.is_interface()) { aoqi@0: assert(is_nonv == is_static(), err_msg("is_nonv=%s", name_and_sig_as_C_string())); aoqi@0: } aoqi@0: #endif aoqi@0: assert(valid_vtable_index() || valid_itable_index(), "method must be linked before we ask this question"); aoqi@0: return vtable_index() == nonvirtual_vtable_index; aoqi@0: } aoqi@0: aoqi@0: bool Method::can_be_statically_bound() const { aoqi@0: return can_be_statically_bound(method_holder()->access_flags()); aoqi@0: } aoqi@0: aoqi@0: bool Method::is_accessor() const { aoqi@0: if (code_size() != 5) return false; aoqi@0: if (size_of_parameters() != 1) return false; aoqi@0: if (java_code_at(0) != Bytecodes::_aload_0 ) return false; aoqi@0: if (java_code_at(1) != Bytecodes::_getfield) return false; aoqi@0: if (java_code_at(4) != Bytecodes::_areturn && aoqi@0: java_code_at(4) != Bytecodes::_ireturn ) return false; aoqi@0: return true; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: bool Method::is_initializer() const { aoqi@0: return name() == vmSymbols::object_initializer_name() || is_static_initializer(); aoqi@0: } aoqi@0: aoqi@0: bool Method::has_valid_initializer_flags() const { aoqi@0: return (is_static() || aoqi@0: method_holder()->major_version() < 51); aoqi@0: } aoqi@0: aoqi@0: bool Method::is_static_initializer() const { aoqi@0: // For classfiles version 51 or greater, ensure that the clinit method is aoqi@0: // static. Non-static methods with the name "" are not static aoqi@0: // initializers. (older classfiles exempted for backward compatibility) aoqi@0: return name() == vmSymbols::class_initializer_name() && aoqi@0: has_valid_initializer_flags(); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: objArrayHandle Method::resolved_checked_exceptions_impl(Method* this_oop, TRAPS) { aoqi@0: int length = this_oop->checked_exceptions_length(); aoqi@0: if (length == 0) { // common case aoqi@0: return objArrayHandle(THREAD, Universe::the_empty_class_klass_array()); aoqi@0: } else { aoqi@0: methodHandle h_this(THREAD, this_oop); aoqi@0: objArrayOop m_oop = oopFactory::new_objArray(SystemDictionary::Class_klass(), length, CHECK_(objArrayHandle())); aoqi@0: objArrayHandle mirrors (THREAD, m_oop); aoqi@0: for (int i = 0; i < length; i++) { aoqi@0: CheckedExceptionElement* table = h_this->checked_exceptions_start(); // recompute on each iteration, not gc safe aoqi@0: Klass* k = h_this->constants()->klass_at(table[i].class_cp_index, CHECK_(objArrayHandle())); aoqi@0: assert(k->is_subclass_of(SystemDictionary::Throwable_klass()), "invalid exception class"); aoqi@0: mirrors->obj_at_put(i, k->java_mirror()); aoqi@0: } aoqi@0: return mirrors; aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: int Method::line_number_from_bci(int bci) const { aoqi@0: if (bci == SynchronizationEntryBCI) bci = 0; aoqi@0: assert(bci == 0 || 0 <= bci && bci < code_size(), "illegal bci"); aoqi@0: int best_bci = 0; aoqi@0: int best_line = -1; aoqi@0: aoqi@0: if (has_linenumber_table()) { aoqi@0: // The line numbers are a short array of 2-tuples [start_pc, line_number]. aoqi@0: // Not necessarily sorted and not necessarily one-to-one. aoqi@0: CompressedLineNumberReadStream stream(compressed_linenumber_table()); aoqi@0: while (stream.read_pair()) { aoqi@0: if (stream.bci() == bci) { aoqi@0: // perfect match aoqi@0: return stream.line(); aoqi@0: } else { aoqi@0: // update best_bci/line aoqi@0: if (stream.bci() < bci && stream.bci() >= best_bci) { aoqi@0: best_bci = stream.bci(); aoqi@0: best_line = stream.line(); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: return best_line; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: bool Method::is_klass_loaded_by_klass_index(int klass_index) const { aoqi@0: if( constants()->tag_at(klass_index).is_unresolved_klass() ) { aoqi@0: Thread *thread = Thread::current(); aoqi@0: Symbol* klass_name = constants()->klass_name_at(klass_index); aoqi@0: Handle loader(thread, method_holder()->class_loader()); aoqi@0: Handle prot (thread, method_holder()->protection_domain()); aoqi@0: return SystemDictionary::find(klass_name, loader, prot, thread) != NULL; aoqi@0: } else { aoqi@0: return true; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: aoqi@0: bool Method::is_klass_loaded(int refinfo_index, bool must_be_resolved) const { aoqi@0: int klass_index = constants()->klass_ref_index_at(refinfo_index); aoqi@0: if (must_be_resolved) { aoqi@0: // Make sure klass is resolved in constantpool. aoqi@0: if (constants()->tag_at(klass_index).is_unresolved_klass()) return false; aoqi@0: } aoqi@0: return is_klass_loaded_by_klass_index(klass_index); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void Method::set_native_function(address function, bool post_event_flag) { aoqi@0: assert(function != NULL, "use clear_native_function to unregister natives"); aoqi@0: assert(!is_method_handle_intrinsic() || function == SharedRuntime::native_method_throw_unsatisfied_link_error_entry(), ""); aoqi@0: address* native_function = native_function_addr(); aoqi@0: aoqi@0: // We can see racers trying to place the same native function into place. Once aoqi@0: // is plenty. aoqi@0: address current = *native_function; aoqi@0: if (current == function) return; aoqi@0: if (post_event_flag && JvmtiExport::should_post_native_method_bind() && aoqi@0: function != NULL) { aoqi@0: // native_method_throw_unsatisfied_link_error_entry() should only aoqi@0: // be passed when post_event_flag is false. aoqi@0: assert(function != aoqi@0: SharedRuntime::native_method_throw_unsatisfied_link_error_entry(), aoqi@0: "post_event_flag mis-match"); aoqi@0: aoqi@0: // post the bind event, and possible change the bind function aoqi@0: JvmtiExport::post_native_method_bind(this, &function); aoqi@0: } aoqi@0: *native_function = function; aoqi@0: // This function can be called more than once. We must make sure that we always aoqi@0: // use the latest registered method -> check if a stub already has been generated. aoqi@0: // If so, we have to make it not_entrant. aoqi@0: nmethod* nm = code(); // Put it into local variable to guard against concurrent updates aoqi@0: if (nm != NULL) { aoqi@0: nm->make_not_entrant(); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: aoqi@0: bool Method::has_native_function() const { aoqi@0: if (is_method_handle_intrinsic()) aoqi@0: return false; // special-cased in SharedRuntime::generate_native_wrapper aoqi@0: address func = native_function(); aoqi@0: return (func != NULL && func != SharedRuntime::native_method_throw_unsatisfied_link_error_entry()); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void Method::clear_native_function() { aoqi@0: // Note: is_method_handle_intrinsic() is allowed here. aoqi@0: set_native_function( aoqi@0: SharedRuntime::native_method_throw_unsatisfied_link_error_entry(), aoqi@0: !native_bind_event_is_interesting); aoqi@0: clear_code(); aoqi@0: } aoqi@0: aoqi@0: address Method::critical_native_function() { aoqi@0: methodHandle mh(this); aoqi@0: return NativeLookup::lookup_critical_entry(mh); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void Method::set_signature_handler(address handler) { aoqi@0: address* signature_handler = signature_handler_addr(); aoqi@0: *signature_handler = handler; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void Method::print_made_not_compilable(int comp_level, bool is_osr, bool report, const char* reason) { aoqi@0: if (PrintCompilation && report) { aoqi@0: ttyLocker ttyl; aoqi@0: tty->print("made not %scompilable on ", is_osr ? "OSR " : ""); aoqi@0: if (comp_level == CompLevel_all) { aoqi@0: tty->print("all levels "); aoqi@0: } else { aoqi@0: tty->print("levels "); aoqi@0: for (int i = (int)CompLevel_none; i <= comp_level; i++) { aoqi@0: tty->print("%d ", i); aoqi@0: } aoqi@0: } aoqi@0: this->print_short_name(tty); aoqi@0: int size = this->code_size(); aoqi@0: if (size > 0) { aoqi@0: tty->print(" (%d bytes)", size); aoqi@0: } aoqi@0: if (reason != NULL) { aoqi@0: tty->print(" %s", reason); aoqi@0: } aoqi@0: tty->cr(); aoqi@0: } aoqi@0: if ((TraceDeoptimization || LogCompilation) && (xtty != NULL)) { aoqi@0: ttyLocker ttyl; aoqi@0: xtty->begin_elem("make_not_%scompilable thread='" UINTX_FORMAT "'", aoqi@0: is_osr ? "osr_" : "", os::current_thread_id()); aoqi@0: if (reason != NULL) { aoqi@0: xtty->print(" reason=\'%s\'", reason); aoqi@0: } aoqi@0: xtty->method(this); aoqi@0: xtty->stamp(); aoqi@0: xtty->end_elem(); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: bool Method::is_always_compilable() const { aoqi@0: // Generated adapters must be compiled aoqi@0: if (is_method_handle_intrinsic() && is_synthetic()) { aoqi@0: assert(!is_not_c1_compilable(), "sanity check"); aoqi@0: assert(!is_not_c2_compilable(), "sanity check"); aoqi@0: return true; aoqi@0: } aoqi@0: aoqi@0: return false; aoqi@0: } aoqi@0: aoqi@0: bool Method::is_not_compilable(int comp_level) const { aoqi@0: if (number_of_breakpoints() > 0) aoqi@0: return true; aoqi@0: if (is_always_compilable()) aoqi@0: return false; aoqi@0: if (comp_level == CompLevel_any) aoqi@0: return is_not_c1_compilable() || is_not_c2_compilable(); aoqi@0: if (is_c1_compile(comp_level)) aoqi@0: return is_not_c1_compilable(); aoqi@0: if (is_c2_compile(comp_level)) aoqi@0: return is_not_c2_compilable(); aoqi@0: return false; aoqi@0: } aoqi@0: aoqi@0: // call this when compiler finds that this method is not compilable aoqi@0: void Method::set_not_compilable(int comp_level, bool report, const char* reason) { aoqi@0: if (is_always_compilable()) { aoqi@0: // Don't mark a method which should be always compilable aoqi@0: return; aoqi@0: } aoqi@0: print_made_not_compilable(comp_level, /*is_osr*/ false, report, reason); aoqi@0: if (comp_level == CompLevel_all) { aoqi@0: set_not_c1_compilable(); aoqi@0: set_not_c2_compilable(); aoqi@0: } else { aoqi@0: if (is_c1_compile(comp_level)) aoqi@0: set_not_c1_compilable(); aoqi@0: if (is_c2_compile(comp_level)) aoqi@0: set_not_c2_compilable(); aoqi@0: } aoqi@0: CompilationPolicy::policy()->disable_compilation(this); aoqi@0: assert(!CompilationPolicy::can_be_compiled(this, comp_level), "sanity check"); aoqi@0: } aoqi@0: aoqi@0: bool Method::is_not_osr_compilable(int comp_level) const { aoqi@0: if (is_not_compilable(comp_level)) aoqi@0: return true; aoqi@0: if (comp_level == CompLevel_any) aoqi@0: return is_not_c1_osr_compilable() || is_not_c2_osr_compilable(); aoqi@0: if (is_c1_compile(comp_level)) aoqi@0: return is_not_c1_osr_compilable(); aoqi@0: if (is_c2_compile(comp_level)) aoqi@0: return is_not_c2_osr_compilable(); aoqi@0: return false; aoqi@0: } aoqi@0: aoqi@0: void Method::set_not_osr_compilable(int comp_level, bool report, const char* reason) { aoqi@0: print_made_not_compilable(comp_level, /*is_osr*/ true, report, reason); aoqi@0: if (comp_level == CompLevel_all) { aoqi@0: set_not_c1_osr_compilable(); aoqi@0: set_not_c2_osr_compilable(); aoqi@0: } else { aoqi@0: if (is_c1_compile(comp_level)) aoqi@0: set_not_c1_osr_compilable(); aoqi@0: if (is_c2_compile(comp_level)) aoqi@0: set_not_c2_osr_compilable(); aoqi@0: } aoqi@0: CompilationPolicy::policy()->disable_compilation(this); aoqi@0: assert(!CompilationPolicy::can_be_osr_compiled(this, comp_level), "sanity check"); aoqi@0: } aoqi@0: aoqi@0: // Revert to using the interpreter and clear out the nmethod aoqi@0: void Method::clear_code() { aoqi@0: aoqi@0: // this may be NULL if c2i adapters have not been made yet aoqi@0: // Only should happen at allocate time. aoqi@0: if (_adapter == NULL) { aoqi@0: _from_compiled_entry = NULL; aoqi@0: } else { aoqi@0: _from_compiled_entry = _adapter->get_c2i_entry(); aoqi@0: } aoqi@0: OrderAccess::storestore(); aoqi@0: _from_interpreted_entry = _i2i_entry; aoqi@0: OrderAccess::storestore(); aoqi@0: _code = NULL; aoqi@0: } aoqi@0: aoqi@0: // Called by class data sharing to remove any entry points (which are not shared) aoqi@0: void Method::unlink_method() { aoqi@0: _code = NULL; aoqi@0: _i2i_entry = NULL; aoqi@0: _from_interpreted_entry = NULL; aoqi@0: if (is_native()) { aoqi@0: *native_function_addr() = NULL; aoqi@0: set_signature_handler(NULL); aoqi@0: } aoqi@0: NOT_PRODUCT(set_compiled_invocation_count(0);) aoqi@0: _adapter = NULL; aoqi@0: _from_compiled_entry = NULL; aoqi@0: aoqi@0: // In case of DumpSharedSpaces, _method_data should always be NULL. aoqi@0: // aoqi@0: // During runtime (!DumpSharedSpaces), when we are cleaning a aoqi@0: // shared class that failed to load, this->link_method() may aoqi@0: // have already been called (before an exception happened), so aoqi@0: // this->_method_data may not be NULL. aoqi@0: assert(!DumpSharedSpaces || _method_data == NULL, "unexpected method data?"); aoqi@0: aoqi@0: set_method_data(NULL); aoqi@0: set_method_counters(NULL); aoqi@0: } aoqi@0: aoqi@0: // Called when the method_holder is getting linked. Setup entrypoints so the method aoqi@0: // is ready to be called from interpreter, compiler, and vtables. aoqi@0: void Method::link_method(methodHandle h_method, TRAPS) { aoqi@0: // If the code cache is full, we may reenter this function for the aoqi@0: // leftover methods that weren't linked. aoqi@0: if (_i2i_entry != NULL) return; aoqi@0: aoqi@0: assert(_adapter == NULL, "init'd to NULL" ); aoqi@0: assert( _code == NULL, "nothing compiled yet" ); aoqi@0: aoqi@0: // Setup interpreter entrypoint aoqi@0: assert(this == h_method(), "wrong h_method()" ); aoqi@0: address entry = Interpreter::entry_for_method(h_method); aoqi@0: assert(entry != NULL, "interpreter entry must be non-null"); aoqi@0: // Sets both _i2i_entry and _from_interpreted_entry aoqi@0: set_interpreter_entry(entry); aoqi@0: aoqi@0: // Don't overwrite already registered native entries. aoqi@0: if (is_native() && !has_native_function()) { aoqi@0: set_native_function( aoqi@0: SharedRuntime::native_method_throw_unsatisfied_link_error_entry(), aoqi@0: !native_bind_event_is_interesting); aoqi@0: } aoqi@0: aoqi@0: // Setup compiler entrypoint. This is made eagerly, so we do not need aoqi@0: // special handling of vtables. An alternative is to make adapters more aoqi@0: // lazily by calling make_adapter() from from_compiled_entry() for the aoqi@0: // normal calls. For vtable calls life gets more complicated. When a aoqi@0: // call-site goes mega-morphic we need adapters in all methods which can be aoqi@0: // called from the vtable. We need adapters on such methods that get loaded aoqi@0: // later. Ditto for mega-morphic itable calls. If this proves to be a aoqi@0: // problem we'll make these lazily later. aoqi@0: (void) make_adapters(h_method, CHECK); aoqi@0: aoqi@0: // ONLY USE the h_method now as make_adapter may have blocked aoqi@0: aoqi@0: } aoqi@0: aoqi@0: address Method::make_adapters(methodHandle mh, TRAPS) { aoqi@0: // Adapters for compiled code are made eagerly here. They are fairly aoqi@0: // small (generally < 100 bytes) and quick to make (and cached and shared) aoqi@0: // so making them eagerly shouldn't be too expensive. aoqi@0: AdapterHandlerEntry* adapter = AdapterHandlerLibrary::get_adapter(mh); aoqi@0: if (adapter == NULL ) { aoqi@0: THROW_MSG_NULL(vmSymbols::java_lang_VirtualMachineError(), "out of space in CodeCache for adapters"); aoqi@0: } aoqi@0: aoqi@0: mh->set_adapter_entry(adapter); aoqi@0: mh->_from_compiled_entry = adapter->get_c2i_entry(); aoqi@0: return adapter->get_c2i_entry(); aoqi@0: } aoqi@0: aoqi@0: void Method::restore_unshareable_info(TRAPS) { aoqi@0: // Since restore_unshareable_info can be called more than once for a method, don't aoqi@0: // redo any work. If this field is restored, there is nothing to do. aoqi@0: if (_from_compiled_entry == NULL) { aoqi@0: // restore method's vtable by calling a virtual function aoqi@0: restore_vtable(); aoqi@0: aoqi@0: methodHandle mh(THREAD, this); aoqi@0: link_method(mh, CHECK); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // The verified_code_entry() must be called when a invoke is resolved aoqi@0: // on this method. aoqi@0: aoqi@0: // It returns the compiled code entry point, after asserting not null. aoqi@0: // This function is called after potential safepoints so that nmethod aoqi@0: // or adapter that it points to is still live and valid. aoqi@0: // This function must not hit a safepoint! aoqi@0: address Method::verified_code_entry() { aoqi@0: debug_only(No_Safepoint_Verifier nsv;) aoqi@0: assert(_from_compiled_entry != NULL, "must be set"); aoqi@0: return _from_compiled_entry; aoqi@0: } aoqi@0: aoqi@0: // Check that if an nmethod ref exists, it has a backlink to this or no backlink at all aoqi@0: // (could be racing a deopt). aoqi@0: // Not inline to avoid circular ref. aoqi@0: bool Method::check_code() const { aoqi@0: // cached in a register or local. There's a race on the value of the field. aoqi@0: nmethod *code = (nmethod *)OrderAccess::load_ptr_acquire(&_code); aoqi@0: return code == NULL || (code->method() == NULL) || (code->method() == (Method*)this && !code->is_osr_method()); aoqi@0: } aoqi@0: aoqi@0: // Install compiled code. Instantly it can execute. aoqi@0: void Method::set_code(methodHandle mh, nmethod *code) { aoqi@0: assert( code, "use clear_code to remove code" ); aoqi@0: assert( mh->check_code(), "" ); aoqi@0: aoqi@0: guarantee(mh->adapter() != NULL, "Adapter blob must already exist!"); aoqi@0: aoqi@0: // These writes must happen in this order, because the interpreter will aoqi@0: // directly jump to from_interpreted_entry which jumps to an i2c adapter aoqi@0: // which jumps to _from_compiled_entry. aoqi@0: mh->_code = code; // Assign before allowing compiled code to exec aoqi@0: aoqi@0: int comp_level = code->comp_level(); aoqi@0: // In theory there could be a race here. In practice it is unlikely aoqi@0: // and not worth worrying about. aoqi@0: if (comp_level > mh->highest_comp_level()) { aoqi@0: mh->set_highest_comp_level(comp_level); aoqi@0: } aoqi@0: aoqi@0: OrderAccess::storestore(); aoqi@0: #ifdef SHARK aoqi@0: mh->_from_interpreted_entry = code->insts_begin(); aoqi@0: #else //!SHARK aoqi@0: mh->_from_compiled_entry = code->verified_entry_point(); aoqi@0: OrderAccess::storestore(); aoqi@0: // Instantly compiled code can execute. aoqi@0: if (!mh->is_method_handle_intrinsic()) aoqi@0: mh->_from_interpreted_entry = mh->get_i2c_entry(); aoqi@0: #endif //!SHARK aoqi@0: } aoqi@0: aoqi@0: aoqi@0: bool Method::is_overridden_in(Klass* k) const { aoqi@0: InstanceKlass* ik = InstanceKlass::cast(k); aoqi@0: aoqi@0: if (ik->is_interface()) return false; aoqi@0: aoqi@0: // If method is an interface, we skip it - except if it aoqi@0: // is a miranda method aoqi@0: if (method_holder()->is_interface()) { aoqi@0: // Check that method is not a miranda method aoqi@0: if (ik->lookup_method(name(), signature()) == NULL) { aoqi@0: // No implementation exist - so miranda method aoqi@0: return false; aoqi@0: } aoqi@0: return true; aoqi@0: } aoqi@0: aoqi@0: assert(ik->is_subclass_of(method_holder()), "should be subklass"); aoqi@0: assert(ik->vtable() != NULL, "vtable should exist"); aoqi@0: if (!has_vtable_index()) { aoqi@0: return false; aoqi@0: } else { aoqi@0: Method* vt_m = ik->method_at_vtable(vtable_index()); aoqi@0: return vt_m != this; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // give advice about whether this Method* should be cached or not aoqi@0: bool Method::should_not_be_cached() const { aoqi@0: if (is_old()) { aoqi@0: // This method has been redefined. It is either EMCP or obsolete aoqi@0: // and we don't want to cache it because that would pin the method aoqi@0: // down and prevent it from being collectible if and when it aoqi@0: // finishes executing. aoqi@0: return true; aoqi@0: } aoqi@0: aoqi@0: // caching this method should be just fine aoqi@0: return false; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: /** aoqi@0: * Returns true if this is one of the specially treated methods for aoqi@0: * security related stack walks (like Reflection.getCallerClass). aoqi@0: */ aoqi@0: bool Method::is_ignored_by_security_stack_walk() const { aoqi@0: const bool use_new_reflection = JDK_Version::is_gte_jdk14x_version() && UseNewReflection; aoqi@0: aoqi@0: if (intrinsic_id() == vmIntrinsics::_invoke) { aoqi@0: // This is Method.invoke() -- ignore it aoqi@0: return true; aoqi@0: } aoqi@0: if (use_new_reflection && aoqi@0: method_holder()->is_subclass_of(SystemDictionary::reflect_MethodAccessorImpl_klass())) { aoqi@0: // This is an auxilary frame -- ignore it aoqi@0: return true; aoqi@0: } aoqi@0: if (is_method_handle_intrinsic() || is_compiled_lambda_form()) { aoqi@0: // This is an internal adapter frame for method handles -- ignore it aoqi@0: return true; aoqi@0: } aoqi@0: return false; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // Constant pool structure for invoke methods: aoqi@0: enum { aoqi@0: _imcp_invoke_name = 1, // utf8: 'invokeExact', etc. aoqi@0: _imcp_invoke_signature, // utf8: (variable Symbol*) aoqi@0: _imcp_limit aoqi@0: }; aoqi@0: aoqi@0: // Test if this method is an MH adapter frame generated by Java code. aoqi@0: // Cf. java/lang/invoke/InvokerBytecodeGenerator aoqi@0: bool Method::is_compiled_lambda_form() const { aoqi@0: return intrinsic_id() == vmIntrinsics::_compiledLambdaForm; aoqi@0: } aoqi@0: aoqi@0: // Test if this method is an internal MH primitive method. aoqi@0: bool Method::is_method_handle_intrinsic() const { aoqi@0: vmIntrinsics::ID iid = intrinsic_id(); aoqi@0: return (MethodHandles::is_signature_polymorphic(iid) && aoqi@0: MethodHandles::is_signature_polymorphic_intrinsic(iid)); aoqi@0: } aoqi@0: aoqi@0: bool Method::has_member_arg() const { aoqi@0: vmIntrinsics::ID iid = intrinsic_id(); aoqi@0: return (MethodHandles::is_signature_polymorphic(iid) && aoqi@0: MethodHandles::has_member_arg(iid)); aoqi@0: } aoqi@0: aoqi@0: // Make an instance of a signature-polymorphic internal MH primitive. aoqi@0: methodHandle Method::make_method_handle_intrinsic(vmIntrinsics::ID iid, aoqi@0: Symbol* signature, aoqi@0: TRAPS) { aoqi@0: ResourceMark rm; aoqi@0: methodHandle empty; aoqi@0: aoqi@0: KlassHandle holder = SystemDictionary::MethodHandle_klass(); aoqi@0: Symbol* name = MethodHandles::signature_polymorphic_intrinsic_name(iid); aoqi@0: assert(iid == MethodHandles::signature_polymorphic_name_id(name), ""); aoqi@0: if (TraceMethodHandles) { aoqi@0: tty->print_cr("make_method_handle_intrinsic MH.%s%s", name->as_C_string(), signature->as_C_string()); aoqi@0: } aoqi@0: aoqi@0: // invariant: cp->symbol_at_put is preceded by a refcount increment (more usually a lookup) aoqi@0: name->increment_refcount(); aoqi@0: signature->increment_refcount(); aoqi@0: aoqi@0: int cp_length = _imcp_limit; aoqi@0: ClassLoaderData* loader_data = holder->class_loader_data(); aoqi@0: constantPoolHandle cp; aoqi@0: { aoqi@0: ConstantPool* cp_oop = ConstantPool::allocate(loader_data, cp_length, CHECK_(empty)); aoqi@0: cp = constantPoolHandle(THREAD, cp_oop); aoqi@0: } aoqi@0: cp->set_pool_holder(InstanceKlass::cast(holder())); aoqi@0: cp->symbol_at_put(_imcp_invoke_name, name); aoqi@0: cp->symbol_at_put(_imcp_invoke_signature, signature); aoqi@0: cp->set_has_preresolution(); aoqi@0: aoqi@0: // decide on access bits: public or not? aoqi@0: int flags_bits = (JVM_ACC_NATIVE | JVM_ACC_SYNTHETIC | JVM_ACC_FINAL); aoqi@0: bool must_be_static = MethodHandles::is_signature_polymorphic_static(iid); aoqi@0: if (must_be_static) flags_bits |= JVM_ACC_STATIC; aoqi@0: assert((flags_bits & JVM_ACC_PUBLIC) == 0, "do not expose these methods"); aoqi@0: aoqi@0: methodHandle m; aoqi@0: { aoqi@0: InlineTableSizes sizes; aoqi@0: Method* m_oop = Method::allocate(loader_data, 0, aoqi@0: accessFlags_from(flags_bits), &sizes, aoqi@0: ConstMethod::NORMAL, CHECK_(empty)); aoqi@0: m = methodHandle(THREAD, m_oop); aoqi@0: } aoqi@0: m->set_constants(cp()); aoqi@0: m->set_name_index(_imcp_invoke_name); aoqi@0: m->set_signature_index(_imcp_invoke_signature); aoqi@0: assert(MethodHandles::is_signature_polymorphic_name(m->name()), ""); aoqi@0: assert(m->signature() == signature, ""); aoqi@0: #ifdef CC_INTERP aoqi@0: ResultTypeFinder rtf(signature); aoqi@0: m->set_result_index(rtf.type()); aoqi@0: #endif aoqi@0: m->compute_size_of_parameters(THREAD); aoqi@0: m->init_intrinsic_id(); aoqi@0: assert(m->is_method_handle_intrinsic(), ""); aoqi@0: #ifdef ASSERT aoqi@0: if (!MethodHandles::is_signature_polymorphic(m->intrinsic_id())) m->print(); aoqi@0: assert(MethodHandles::is_signature_polymorphic(m->intrinsic_id()), "must be an invoker"); aoqi@0: assert(m->intrinsic_id() == iid, "correctly predicted iid"); aoqi@0: #endif //ASSERT aoqi@0: aoqi@0: // Finally, set up its entry points. aoqi@0: assert(m->can_be_statically_bound(), ""); aoqi@0: m->set_vtable_index(Method::nonvirtual_vtable_index); aoqi@0: m->link_method(m, CHECK_(empty)); aoqi@0: aoqi@0: if (TraceMethodHandles && (Verbose || WizardMode)) aoqi@0: m->print_on(tty); aoqi@0: aoqi@0: return m; aoqi@0: } aoqi@0: aoqi@0: Klass* Method::check_non_bcp_klass(Klass* klass) { aoqi@0: if (klass != NULL && klass->class_loader() != NULL) { aoqi@0: if (klass->oop_is_objArray()) aoqi@0: klass = ObjArrayKlass::cast(klass)->bottom_klass(); aoqi@0: return klass; aoqi@0: } aoqi@0: return NULL; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: methodHandle Method::clone_with_new_data(methodHandle m, u_char* new_code, int new_code_length, aoqi@0: u_char* new_compressed_linenumber_table, int new_compressed_linenumber_size, TRAPS) { aoqi@0: // Code below does not work for native methods - they should never get rewritten anyway aoqi@0: assert(!m->is_native(), "cannot rewrite native methods"); aoqi@0: // Allocate new Method* aoqi@0: AccessFlags flags = m->access_flags(); aoqi@0: aoqi@0: ConstMethod* cm = m->constMethod(); aoqi@0: int checked_exceptions_len = cm->checked_exceptions_length(); aoqi@0: int localvariable_len = cm->localvariable_table_length(); aoqi@0: int exception_table_len = cm->exception_table_length(); aoqi@0: int method_parameters_len = cm->method_parameters_length(); aoqi@0: int method_annotations_len = cm->method_annotations_length(); aoqi@0: int parameter_annotations_len = cm->parameter_annotations_length(); aoqi@0: int type_annotations_len = cm->type_annotations_length(); aoqi@0: int default_annotations_len = cm->default_annotations_length(); aoqi@0: aoqi@0: InlineTableSizes sizes( aoqi@0: localvariable_len, aoqi@0: new_compressed_linenumber_size, aoqi@0: exception_table_len, aoqi@0: checked_exceptions_len, aoqi@0: method_parameters_len, aoqi@0: cm->generic_signature_index(), aoqi@0: method_annotations_len, aoqi@0: parameter_annotations_len, aoqi@0: type_annotations_len, aoqi@0: default_annotations_len, aoqi@0: 0); aoqi@0: aoqi@0: ClassLoaderData* loader_data = m->method_holder()->class_loader_data(); aoqi@0: Method* newm_oop = Method::allocate(loader_data, aoqi@0: new_code_length, aoqi@0: flags, aoqi@0: &sizes, aoqi@0: m->method_type(), aoqi@0: CHECK_(methodHandle())); aoqi@0: methodHandle newm (THREAD, newm_oop); aoqi@0: int new_method_size = newm->method_size(); aoqi@0: aoqi@0: // Create a shallow copy of Method part, but be careful to preserve the new ConstMethod* aoqi@0: ConstMethod* newcm = newm->constMethod(); aoqi@0: int new_const_method_size = newm->constMethod()->size(); aoqi@0: aoqi@0: memcpy(newm(), m(), sizeof(Method)); aoqi@0: aoqi@0: // Create shallow copy of ConstMethod. aoqi@0: memcpy(newcm, m->constMethod(), sizeof(ConstMethod)); aoqi@0: aoqi@0: // Reset correct method/const method, method size, and parameter info aoqi@0: newm->set_constMethod(newcm); aoqi@0: newm->constMethod()->set_code_size(new_code_length); aoqi@0: newm->constMethod()->set_constMethod_size(new_const_method_size); aoqi@0: newm->set_method_size(new_method_size); aoqi@0: assert(newm->code_size() == new_code_length, "check"); aoqi@0: assert(newm->method_parameters_length() == method_parameters_len, "check"); aoqi@0: assert(newm->checked_exceptions_length() == checked_exceptions_len, "check"); aoqi@0: assert(newm->exception_table_length() == exception_table_len, "check"); aoqi@0: assert(newm->localvariable_table_length() == localvariable_len, "check"); aoqi@0: // Copy new byte codes aoqi@0: memcpy(newm->code_base(), new_code, new_code_length); aoqi@0: // Copy line number table aoqi@0: if (new_compressed_linenumber_size > 0) { aoqi@0: memcpy(newm->compressed_linenumber_table(), aoqi@0: new_compressed_linenumber_table, aoqi@0: new_compressed_linenumber_size); aoqi@0: } aoqi@0: // Copy method_parameters aoqi@0: if (method_parameters_len > 0) { aoqi@0: memcpy(newm->method_parameters_start(), aoqi@0: m->method_parameters_start(), aoqi@0: method_parameters_len * sizeof(MethodParametersElement)); aoqi@0: } aoqi@0: // Copy checked_exceptions aoqi@0: if (checked_exceptions_len > 0) { aoqi@0: memcpy(newm->checked_exceptions_start(), aoqi@0: m->checked_exceptions_start(), aoqi@0: checked_exceptions_len * sizeof(CheckedExceptionElement)); aoqi@0: } aoqi@0: // Copy exception table aoqi@0: if (exception_table_len > 0) { aoqi@0: memcpy(newm->exception_table_start(), aoqi@0: m->exception_table_start(), aoqi@0: exception_table_len * sizeof(ExceptionTableElement)); aoqi@0: } aoqi@0: // Copy local variable number table aoqi@0: if (localvariable_len > 0) { aoqi@0: memcpy(newm->localvariable_table_start(), aoqi@0: m->localvariable_table_start(), aoqi@0: localvariable_len * sizeof(LocalVariableTableElement)); aoqi@0: } aoqi@0: // Copy stackmap table aoqi@0: if (m->has_stackmap_table()) { aoqi@0: int code_attribute_length = m->stackmap_data()->length(); aoqi@0: Array* stackmap_data = aoqi@0: MetadataFactory::new_array(loader_data, code_attribute_length, 0, CHECK_NULL); aoqi@0: memcpy((void*)stackmap_data->adr_at(0), aoqi@0: (void*)m->stackmap_data()->adr_at(0), code_attribute_length); aoqi@0: newm->set_stackmap_data(stackmap_data); aoqi@0: } aoqi@0: aoqi@0: // copy annotations over to new method aoqi@0: newcm->copy_annotations_from(cm); aoqi@0: return newm; aoqi@0: } aoqi@0: aoqi@0: vmSymbols::SID Method::klass_id_for_intrinsics(Klass* holder) { aoqi@0: // if loader is not the default loader (i.e., != NULL), we can't know the intrinsics aoqi@0: // because we are not loading from core libraries aoqi@0: // exception: the AES intrinsics come from lib/ext/sunjce_provider.jar aoqi@0: // which does not use the class default class loader so we check for its loader here aoqi@0: InstanceKlass* ik = InstanceKlass::cast(holder); aoqi@0: if ((ik->class_loader() != NULL) && !SystemDictionary::is_ext_class_loader(ik->class_loader())) { aoqi@0: return vmSymbols::NO_SID; // regardless of name, no intrinsics here aoqi@0: } aoqi@0: aoqi@0: // see if the klass name is well-known: aoqi@0: Symbol* klass_name = ik->name(); aoqi@0: return vmSymbols::find_sid(klass_name); aoqi@0: } aoqi@0: aoqi@0: void Method::init_intrinsic_id() { aoqi@0: assert(_intrinsic_id == vmIntrinsics::_none, "do this just once"); aoqi@0: const uintptr_t max_id_uint = right_n_bits((int)(sizeof(_intrinsic_id) * BitsPerByte)); aoqi@0: assert((uintptr_t)vmIntrinsics::ID_LIMIT <= max_id_uint, "else fix size"); aoqi@0: assert(intrinsic_id_size_in_bytes() == sizeof(_intrinsic_id), ""); aoqi@0: aoqi@0: // the klass name is well-known: aoqi@0: vmSymbols::SID klass_id = klass_id_for_intrinsics(method_holder()); aoqi@0: assert(klass_id != vmSymbols::NO_SID, "caller responsibility"); aoqi@0: aoqi@0: // ditto for method and signature: aoqi@0: vmSymbols::SID name_id = vmSymbols::find_sid(name()); aoqi@0: if (klass_id != vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_MethodHandle) aoqi@0: && name_id == vmSymbols::NO_SID) aoqi@0: return; aoqi@0: vmSymbols::SID sig_id = vmSymbols::find_sid(signature()); aoqi@0: if (klass_id != vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_MethodHandle) aoqi@0: && sig_id == vmSymbols::NO_SID) return; aoqi@0: jshort flags = access_flags().as_short(); aoqi@0: aoqi@0: vmIntrinsics::ID id = vmIntrinsics::find_id(klass_id, name_id, sig_id, flags); aoqi@0: if (id != vmIntrinsics::_none) { aoqi@0: set_intrinsic_id(id); aoqi@0: return; aoqi@0: } aoqi@0: aoqi@0: // A few slightly irregular cases: aoqi@0: switch (klass_id) { aoqi@0: case vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_StrictMath): aoqi@0: // Second chance: check in regular Math. aoqi@0: switch (name_id) { aoqi@0: case vmSymbols::VM_SYMBOL_ENUM_NAME(min_name): aoqi@0: case vmSymbols::VM_SYMBOL_ENUM_NAME(max_name): aoqi@0: case vmSymbols::VM_SYMBOL_ENUM_NAME(sqrt_name): aoqi@0: // pretend it is the corresponding method in the non-strict class: aoqi@0: klass_id = vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_Math); aoqi@0: id = vmIntrinsics::find_id(klass_id, name_id, sig_id, flags); aoqi@0: break; aoqi@0: } aoqi@0: break; aoqi@0: aoqi@0: // Signature-polymorphic methods: MethodHandle.invoke*, InvokeDynamic.*. aoqi@0: case vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_MethodHandle): aoqi@0: if (!is_native()) break; aoqi@0: id = MethodHandles::signature_polymorphic_name_id(method_holder(), name()); aoqi@0: if (is_static() != MethodHandles::is_signature_polymorphic_static(id)) aoqi@0: id = vmIntrinsics::_none; aoqi@0: break; aoqi@0: } aoqi@0: aoqi@0: if (id != vmIntrinsics::_none) { aoqi@0: // Set up its iid. It is an alias method. aoqi@0: set_intrinsic_id(id); aoqi@0: return; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // These two methods are static since a GC may move the Method aoqi@0: bool Method::load_signature_classes(methodHandle m, TRAPS) { aoqi@0: if (THREAD->is_Compiler_thread()) { aoqi@0: // There is nothing useful this routine can do from within the Compile thread. aoqi@0: // Hopefully, the signature contains only well-known classes. aoqi@0: // We could scan for this and return true/false, but the caller won't care. aoqi@0: return false; aoqi@0: } aoqi@0: bool sig_is_loaded = true; aoqi@0: Handle class_loader(THREAD, m->method_holder()->class_loader()); aoqi@0: Handle protection_domain(THREAD, m->method_holder()->protection_domain()); aoqi@0: ResourceMark rm(THREAD); aoqi@0: Symbol* signature = m->signature(); aoqi@0: for(SignatureStream ss(signature); !ss.is_done(); ss.next()) { aoqi@0: if (ss.is_object()) { aoqi@0: Symbol* sym = ss.as_symbol(CHECK_(false)); aoqi@0: Symbol* name = sym; aoqi@0: Klass* klass = SystemDictionary::resolve_or_null(name, class_loader, aoqi@0: protection_domain, THREAD); aoqi@0: // We are loading classes eagerly. If a ClassNotFoundException or aoqi@0: // a LinkageError was generated, be sure to ignore it. aoqi@0: if (HAS_PENDING_EXCEPTION) { aoqi@0: if (PENDING_EXCEPTION->is_a(SystemDictionary::ClassNotFoundException_klass()) || aoqi@0: PENDING_EXCEPTION->is_a(SystemDictionary::LinkageError_klass())) { aoqi@0: CLEAR_PENDING_EXCEPTION; aoqi@0: } else { aoqi@0: return false; aoqi@0: } aoqi@0: } aoqi@0: if( klass == NULL) { sig_is_loaded = false; } aoqi@0: } aoqi@0: } aoqi@0: return sig_is_loaded; aoqi@0: } aoqi@0: aoqi@0: bool Method::has_unloaded_classes_in_signature(methodHandle m, TRAPS) { aoqi@0: Handle class_loader(THREAD, m->method_holder()->class_loader()); aoqi@0: Handle protection_domain(THREAD, m->method_holder()->protection_domain()); aoqi@0: ResourceMark rm(THREAD); aoqi@0: Symbol* signature = m->signature(); aoqi@0: for(SignatureStream ss(signature); !ss.is_done(); ss.next()) { aoqi@0: if (ss.type() == T_OBJECT) { aoqi@0: Symbol* name = ss.as_symbol_or_null(); aoqi@0: if (name == NULL) return true; aoqi@0: Klass* klass = SystemDictionary::find(name, class_loader, protection_domain, THREAD); aoqi@0: if (klass == NULL) return true; aoqi@0: } aoqi@0: } aoqi@0: return false; aoqi@0: } aoqi@0: aoqi@0: // Exposed so field engineers can debug VM aoqi@0: void Method::print_short_name(outputStream* st) { aoqi@0: ResourceMark rm; aoqi@0: #ifdef PRODUCT aoqi@0: st->print(" %s::", method_holder()->external_name()); aoqi@0: #else aoqi@0: st->print(" %s::", method_holder()->internal_name()); aoqi@0: #endif aoqi@0: name()->print_symbol_on(st); aoqi@0: if (WizardMode) signature()->print_symbol_on(st); aoqi@0: else if (MethodHandles::is_signature_polymorphic(intrinsic_id())) aoqi@0: MethodHandles::print_as_basic_type_signature_on(st, signature(), true); aoqi@0: } aoqi@0: aoqi@0: // Comparer for sorting an object array containing aoqi@0: // Method*s. aoqi@0: static int method_comparator(Method* a, Method* b) { aoqi@0: return a->name()->fast_compare(b->name()); aoqi@0: } aoqi@0: aoqi@0: // This is only done during class loading, so it is OK to assume method_idnum matches the methods() array aoqi@0: // default_methods also uses this without the ordering for fast find_method aoqi@0: void Method::sort_methods(Array* methods, bool idempotent, bool set_idnums) { aoqi@0: int length = methods->length(); aoqi@0: if (length > 1) { aoqi@0: { aoqi@0: No_Safepoint_Verifier nsv; aoqi@0: QuickSort::sort(methods->data(), length, method_comparator, idempotent); aoqi@0: } aoqi@0: // Reset method ordering aoqi@0: if (set_idnums) { aoqi@0: for (int i = 0; i < length; i++) { aoqi@0: Method* m = methods->at(i); aoqi@0: m->set_method_idnum(i); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: //----------------------------------------------------------------------------------- aoqi@0: // Non-product code unless JVM/TI needs it aoqi@0: aoqi@0: #if !defined(PRODUCT) || INCLUDE_JVMTI aoqi@0: class SignatureTypePrinter : public SignatureTypeNames { aoqi@0: private: aoqi@0: outputStream* _st; aoqi@0: bool _use_separator; aoqi@0: aoqi@0: void type_name(const char* name) { aoqi@0: if (_use_separator) _st->print(", "); aoqi@0: _st->print("%s", name); aoqi@0: _use_separator = true; aoqi@0: } aoqi@0: aoqi@0: public: aoqi@0: SignatureTypePrinter(Symbol* signature, outputStream* st) : SignatureTypeNames(signature) { aoqi@0: _st = st; aoqi@0: _use_separator = false; aoqi@0: } aoqi@0: aoqi@0: void print_parameters() { _use_separator = false; iterate_parameters(); } aoqi@0: void print_returntype() { _use_separator = false; iterate_returntype(); } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: void Method::print_name(outputStream* st) { aoqi@0: Thread *thread = Thread::current(); aoqi@0: ResourceMark rm(thread); aoqi@0: SignatureTypePrinter sig(signature(), st); aoqi@0: st->print("%s ", is_static() ? "static" : "virtual"); aoqi@0: sig.print_returntype(); aoqi@0: st->print(" %s.", method_holder()->internal_name()); aoqi@0: name()->print_symbol_on(st); aoqi@0: st->print("("); aoqi@0: sig.print_parameters(); aoqi@0: st->print(")"); aoqi@0: } aoqi@0: #endif // !PRODUCT || INCLUDE_JVMTI aoqi@0: aoqi@0: aoqi@0: //----------------------------------------------------------------------------------- aoqi@0: // Non-product code aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: void Method::print_codes_on(outputStream* st) const { aoqi@0: print_codes_on(0, code_size(), st); aoqi@0: } aoqi@0: aoqi@0: void Method::print_codes_on(int from, int to, outputStream* st) const { aoqi@0: Thread *thread = Thread::current(); aoqi@0: ResourceMark rm(thread); aoqi@0: methodHandle mh (thread, (Method*)this); aoqi@0: BytecodeStream s(mh); aoqi@0: s.set_interval(from, to); aoqi@0: BytecodeTracer::set_closure(BytecodeTracer::std_closure()); aoqi@0: while (s.next() >= 0) BytecodeTracer::trace(mh, s.bcp(), st); aoqi@0: } aoqi@0: #endif // not PRODUCT aoqi@0: aoqi@0: aoqi@0: // Simple compression of line number tables. We use a regular compressed stream, except that we compress deltas aoqi@0: // between (bci,line) pairs since they are smaller. If (bci delta, line delta) fits in (5-bit unsigned, 3-bit unsigned) aoqi@0: // we save it as one byte, otherwise we write a 0xFF escape character and use regular compression. 0x0 is used aoqi@0: // as end-of-stream terminator. aoqi@0: aoqi@0: void CompressedLineNumberWriteStream::write_pair_regular(int bci_delta, int line_delta) { aoqi@0: // bci and line number does not compress into single byte. aoqi@0: // Write out escape character and use regular compression for bci and line number. aoqi@0: write_byte((jubyte)0xFF); aoqi@0: write_signed_int(bci_delta); aoqi@0: write_signed_int(line_delta); aoqi@0: } aoqi@0: aoqi@0: // See comment in method.hpp which explains why this exists. aoqi@0: #if defined(_M_AMD64) && _MSC_VER >= 1400 aoqi@0: #pragma optimize("", off) aoqi@0: void CompressedLineNumberWriteStream::write_pair(int bci, int line) { aoqi@0: write_pair_inline(bci, line); aoqi@0: } aoqi@0: #pragma optimize("", on) aoqi@0: #endif aoqi@0: aoqi@0: CompressedLineNumberReadStream::CompressedLineNumberReadStream(u_char* buffer) : CompressedReadStream(buffer) { aoqi@0: _bci = 0; aoqi@0: _line = 0; aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: bool CompressedLineNumberReadStream::read_pair() { aoqi@0: jubyte next = read_byte(); aoqi@0: // Check for terminator aoqi@0: if (next == 0) return false; aoqi@0: if (next == 0xFF) { aoqi@0: // Escape character, regular compression used aoqi@0: _bci += read_signed_int(); aoqi@0: _line += read_signed_int(); aoqi@0: } else { aoqi@0: // Single byte compression used aoqi@0: _bci += next >> 3; aoqi@0: _line += next & 0x7; aoqi@0: } aoqi@0: return true; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: Bytecodes::Code Method::orig_bytecode_at(int bci) const { aoqi@0: BreakpointInfo* bp = method_holder()->breakpoints(); aoqi@0: for (; bp != NULL; bp = bp->next()) { aoqi@0: if (bp->match(this, bci)) { aoqi@0: return bp->orig_bytecode(); aoqi@0: } aoqi@0: } aoqi@0: { aoqi@0: ResourceMark rm; aoqi@0: fatal(err_msg("no original bytecode found in %s at bci %d", name_and_sig_as_C_string(), bci)); aoqi@0: } aoqi@0: return Bytecodes::_shouldnotreachhere; aoqi@0: } aoqi@0: aoqi@0: void Method::set_orig_bytecode_at(int bci, Bytecodes::Code code) { aoqi@0: assert(code != Bytecodes::_breakpoint, "cannot patch breakpoints this way"); aoqi@0: BreakpointInfo* bp = method_holder()->breakpoints(); aoqi@0: for (; bp != NULL; bp = bp->next()) { aoqi@0: if (bp->match(this, bci)) { aoqi@0: bp->set_orig_bytecode(code); aoqi@0: // and continue, in case there is more than one aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void Method::set_breakpoint(int bci) { aoqi@0: InstanceKlass* ik = method_holder(); aoqi@0: BreakpointInfo *bp = new BreakpointInfo(this, bci); aoqi@0: bp->set_next(ik->breakpoints()); aoqi@0: ik->set_breakpoints(bp); aoqi@0: // do this last: aoqi@0: bp->set(this); aoqi@0: } aoqi@0: aoqi@0: static void clear_matches(Method* m, int bci) { aoqi@0: InstanceKlass* ik = m->method_holder(); aoqi@0: BreakpointInfo* prev_bp = NULL; aoqi@0: BreakpointInfo* next_bp; aoqi@0: for (BreakpointInfo* bp = ik->breakpoints(); bp != NULL; bp = next_bp) { aoqi@0: next_bp = bp->next(); aoqi@0: // bci value of -1 is used to delete all breakpoints in method m (ex: clear_all_breakpoint). aoqi@0: if (bci >= 0 ? bp->match(m, bci) : bp->match(m)) { aoqi@0: // do this first: aoqi@0: bp->clear(m); aoqi@0: // unhook it aoqi@0: if (prev_bp != NULL) aoqi@0: prev_bp->set_next(next_bp); aoqi@0: else aoqi@0: ik->set_breakpoints(next_bp); aoqi@0: delete bp; aoqi@0: // When class is redefined JVMTI sets breakpoint in all versions of EMCP methods aoqi@0: // at same location. So we have multiple matching (method_index and bci) aoqi@0: // BreakpointInfo nodes in BreakpointInfo list. We should just delete one aoqi@0: // breakpoint for clear_breakpoint request and keep all other method versions aoqi@0: // BreakpointInfo for future clear_breakpoint request. aoqi@0: // bcivalue of -1 is used to clear all breakpoints (see clear_all_breakpoints) aoqi@0: // which is being called when class is unloaded. We delete all the Breakpoint aoqi@0: // information for all versions of method. We may not correctly restore the original aoqi@0: // bytecode in all method versions, but that is ok. Because the class is being unloaded aoqi@0: // so these methods won't be used anymore. aoqi@0: if (bci >= 0) { aoqi@0: break; aoqi@0: } aoqi@0: } else { aoqi@0: // This one is a keeper. aoqi@0: prev_bp = bp; aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void Method::clear_breakpoint(int bci) { aoqi@0: assert(bci >= 0, ""); aoqi@0: clear_matches(this, bci); aoqi@0: } aoqi@0: aoqi@0: void Method::clear_all_breakpoints() { aoqi@0: clear_matches(this, -1); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: int Method::invocation_count() { aoqi@0: MethodCounters *mcs = method_counters(); aoqi@0: if (TieredCompilation) { aoqi@0: MethodData* const mdo = method_data(); aoqi@0: if (((mcs != NULL) ? mcs->invocation_counter()->carry() : false) || aoqi@0: ((mdo != NULL) ? mdo->invocation_counter()->carry() : false)) { aoqi@0: return InvocationCounter::count_limit; aoqi@0: } else { aoqi@0: return ((mcs != NULL) ? mcs->invocation_counter()->count() : 0) + aoqi@0: ((mdo != NULL) ? mdo->invocation_counter()->count() : 0); aoqi@0: } aoqi@0: } else { aoqi@0: return (mcs == NULL) ? 0 : mcs->invocation_counter()->count(); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: int Method::backedge_count() { aoqi@0: MethodCounters *mcs = method_counters(); aoqi@0: if (TieredCompilation) { aoqi@0: MethodData* const mdo = method_data(); aoqi@0: if (((mcs != NULL) ? mcs->backedge_counter()->carry() : false) || aoqi@0: ((mdo != NULL) ? mdo->backedge_counter()->carry() : false)) { aoqi@0: return InvocationCounter::count_limit; aoqi@0: } else { aoqi@0: return ((mcs != NULL) ? mcs->backedge_counter()->count() : 0) + aoqi@0: ((mdo != NULL) ? mdo->backedge_counter()->count() : 0); aoqi@0: } aoqi@0: } else { aoqi@0: return (mcs == NULL) ? 0 : mcs->backedge_counter()->count(); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: int Method::highest_comp_level() const { aoqi@0: const MethodData* mdo = method_data(); aoqi@0: if (mdo != NULL) { aoqi@0: return mdo->highest_comp_level(); aoqi@0: } else { aoqi@0: return CompLevel_none; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: int Method::highest_osr_comp_level() const { aoqi@0: const MethodData* mdo = method_data(); aoqi@0: if (mdo != NULL) { aoqi@0: return mdo->highest_osr_comp_level(); aoqi@0: } else { aoqi@0: return CompLevel_none; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void Method::set_highest_comp_level(int level) { aoqi@0: MethodData* mdo = method_data(); aoqi@0: if (mdo != NULL) { aoqi@0: mdo->set_highest_comp_level(level); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void Method::set_highest_osr_comp_level(int level) { aoqi@0: MethodData* mdo = method_data(); aoqi@0: if (mdo != NULL) { aoqi@0: mdo->set_highest_osr_comp_level(level); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: BreakpointInfo::BreakpointInfo(Method* m, int bci) { aoqi@0: _bci = bci; aoqi@0: _name_index = m->name_index(); aoqi@0: _signature_index = m->signature_index(); aoqi@0: _orig_bytecode = (Bytecodes::Code) *m->bcp_from(_bci); aoqi@0: if (_orig_bytecode == Bytecodes::_breakpoint) aoqi@0: _orig_bytecode = m->orig_bytecode_at(_bci); aoqi@0: _next = NULL; aoqi@0: } aoqi@0: aoqi@0: void BreakpointInfo::set(Method* method) { aoqi@0: #ifdef ASSERT aoqi@0: { aoqi@0: Bytecodes::Code code = (Bytecodes::Code) *method->bcp_from(_bci); aoqi@0: if (code == Bytecodes::_breakpoint) aoqi@0: code = method->orig_bytecode_at(_bci); aoqi@0: assert(orig_bytecode() == code, "original bytecode must be the same"); aoqi@0: } aoqi@0: #endif aoqi@0: Thread *thread = Thread::current(); aoqi@0: *method->bcp_from(_bci) = Bytecodes::_breakpoint; aoqi@0: method->incr_number_of_breakpoints(thread); aoqi@0: SystemDictionary::notice_modification(); aoqi@0: { aoqi@0: // Deoptimize all dependents on this method aoqi@0: HandleMark hm(thread); aoqi@0: methodHandle mh(thread, method); aoqi@0: Universe::flush_dependents_on_method(mh); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void BreakpointInfo::clear(Method* method) { aoqi@0: *method->bcp_from(_bci) = orig_bytecode(); aoqi@0: assert(method->number_of_breakpoints() > 0, "must not go negative"); aoqi@0: method->decr_number_of_breakpoints(Thread::current()); aoqi@0: } aoqi@0: aoqi@0: // jmethodID handling aoqi@0: aoqi@0: // This is a block allocating object, sort of like JNIHandleBlock, only a aoqi@0: // lot simpler. There aren't many of these, they aren't long, they are rarely aoqi@0: // deleted and so we can do some suboptimal things. aoqi@0: // It's allocated on the CHeap because once we allocate a jmethodID, we can aoqi@0: // never get rid of it. aoqi@0: // It would be nice to be able to parameterize the number of methods for aoqi@0: // the null_class_loader but then we'd have to turn this and ClassLoaderData aoqi@0: // into templates. aoqi@0: aoqi@0: // I feel like this brain dead class should exist somewhere in the STL aoqi@0: aoqi@0: class JNIMethodBlock : public CHeapObj { aoqi@0: enum { number_of_methods = 8 }; aoqi@0: aoqi@0: Method* _methods[number_of_methods]; aoqi@0: int _top; aoqi@0: JNIMethodBlock* _next; aoqi@0: public: aoqi@0: static Method* const _free_method; aoqi@0: aoqi@0: JNIMethodBlock() : _next(NULL), _top(0) { aoqi@0: for (int i = 0; i< number_of_methods; i++) _methods[i] = _free_method; aoqi@0: } aoqi@0: aoqi@0: Method** add_method(Method* m) { aoqi@0: if (_top < number_of_methods) { aoqi@0: // top points to the next free entry. aoqi@0: int i = _top; aoqi@0: _methods[i] = m; aoqi@0: _top++; aoqi@0: return &_methods[i]; aoqi@0: } else if (_top == number_of_methods) { aoqi@0: // if the next free entry ran off the block see if there's a free entry aoqi@0: for (int i = 0; i< number_of_methods; i++) { aoqi@0: if (_methods[i] == _free_method) { aoqi@0: _methods[i] = m; aoqi@0: return &_methods[i]; aoqi@0: } aoqi@0: } aoqi@0: // Only check each block once for frees. They're very unlikely. aoqi@0: // Increment top past the end of the block. aoqi@0: _top++; aoqi@0: } aoqi@0: // need to allocate a next block. aoqi@0: if (_next == NULL) { aoqi@0: _next = new JNIMethodBlock(); aoqi@0: } aoqi@0: return _next->add_method(m); aoqi@0: } aoqi@0: aoqi@0: bool contains(Method** m) { aoqi@0: for (JNIMethodBlock* b = this; b != NULL; b = b->_next) { aoqi@0: for (int i = 0; i< number_of_methods; i++) { aoqi@0: if (&(b->_methods[i]) == m) { aoqi@0: return true; aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: return false; // not found aoqi@0: } aoqi@0: aoqi@0: // Doesn't really destroy it, just marks it as free so it can be reused. aoqi@0: void destroy_method(Method** m) { aoqi@0: #ifdef ASSERT aoqi@0: assert(contains(m), "should be a methodID"); aoqi@0: #endif // ASSERT aoqi@0: *m = _free_method; aoqi@0: } aoqi@0: aoqi@0: // During class unloading the methods are cleared, which is different aoqi@0: // than freed. aoqi@0: void clear_all_methods() { aoqi@0: for (JNIMethodBlock* b = this; b != NULL; b = b->_next) { aoqi@0: for (int i = 0; i< number_of_methods; i++) { aoqi@0: _methods[i] = NULL; aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: #ifndef PRODUCT aoqi@0: int count_methods() { aoqi@0: // count all allocated methods aoqi@0: int count = 0; aoqi@0: for (JNIMethodBlock* b = this; b != NULL; b = b->_next) { aoqi@0: for (int i = 0; i< number_of_methods; i++) { aoqi@0: if (_methods[i] != _free_method) count++; aoqi@0: } aoqi@0: } aoqi@0: return count; aoqi@0: } aoqi@0: #endif // PRODUCT aoqi@0: }; aoqi@0: aoqi@0: // Something that can't be mistaken for an address or a markOop aoqi@0: Method* const JNIMethodBlock::_free_method = (Method*)55; aoqi@0: aoqi@0: // Add a method id to the jmethod_ids aoqi@0: jmethodID Method::make_jmethod_id(ClassLoaderData* loader_data, Method* m) { aoqi@0: ClassLoaderData* cld = loader_data; aoqi@0: aoqi@0: if (!SafepointSynchronize::is_at_safepoint()) { aoqi@0: // Have to add jmethod_ids() to class loader data thread-safely. aoqi@0: // Also have to add the method to the list safely, which the cld lock aoqi@0: // protects as well. aoqi@0: MutexLockerEx ml(cld->metaspace_lock(), Mutex::_no_safepoint_check_flag); aoqi@0: if (cld->jmethod_ids() == NULL) { aoqi@0: cld->set_jmethod_ids(new JNIMethodBlock()); aoqi@0: } aoqi@0: // jmethodID is a pointer to Method* aoqi@0: return (jmethodID)cld->jmethod_ids()->add_method(m); aoqi@0: } else { aoqi@0: // At safepoint, we are single threaded and can set this. aoqi@0: if (cld->jmethod_ids() == NULL) { aoqi@0: cld->set_jmethod_ids(new JNIMethodBlock()); aoqi@0: } aoqi@0: // jmethodID is a pointer to Method* aoqi@0: return (jmethodID)cld->jmethod_ids()->add_method(m); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Mark a jmethodID as free. This is called when there is a data race in aoqi@0: // InstanceKlass while creating the jmethodID cache. aoqi@0: void Method::destroy_jmethod_id(ClassLoaderData* loader_data, jmethodID m) { aoqi@0: ClassLoaderData* cld = loader_data; aoqi@0: Method** ptr = (Method**)m; aoqi@0: assert(cld->jmethod_ids() != NULL, "should have method handles"); aoqi@0: cld->jmethod_ids()->destroy_method(ptr); aoqi@0: } aoqi@0: aoqi@0: void Method::change_method_associated_with_jmethod_id(jmethodID jmid, Method* new_method) { aoqi@0: // Can't assert the method_holder is the same because the new method has the aoqi@0: // scratch method holder. aoqi@0: assert(resolve_jmethod_id(jmid)->method_holder()->class_loader() aoqi@0: == new_method->method_holder()->class_loader(), aoqi@0: "changing to a different class loader"); aoqi@0: // Just change the method in place, jmethodID pointer doesn't change. aoqi@0: *((Method**)jmid) = new_method; aoqi@0: } aoqi@0: aoqi@0: bool Method::is_method_id(jmethodID mid) { aoqi@0: Method* m = resolve_jmethod_id(mid); aoqi@0: assert(m != NULL, "should be called with non-null method"); aoqi@0: InstanceKlass* ik = m->method_holder(); aoqi@0: ClassLoaderData* cld = ik->class_loader_data(); aoqi@0: if (cld->jmethod_ids() == NULL) return false; aoqi@0: return (cld->jmethod_ids()->contains((Method**)mid)); aoqi@0: } aoqi@0: aoqi@0: Method* Method::checked_resolve_jmethod_id(jmethodID mid) { aoqi@0: if (mid == NULL) return NULL; aoqi@0: Method* o = resolve_jmethod_id(mid); aoqi@0: if (o == NULL || o == JNIMethodBlock::_free_method || !((Metadata*)o)->is_method()) { aoqi@0: return NULL; aoqi@0: } aoqi@0: return o; aoqi@0: }; aoqi@0: aoqi@0: void Method::set_on_stack(const bool value) { aoqi@0: // Set both the method itself and its constant pool. The constant pool aoqi@0: // on stack means some method referring to it is also on the stack. aoqi@0: _access_flags.set_on_stack(value); aoqi@0: constants()->set_on_stack(value); aoqi@0: if (value) MetadataOnStackMark::record(this); aoqi@0: } aoqi@0: aoqi@0: // Called when the class loader is unloaded to make all methods weak. aoqi@0: void Method::clear_jmethod_ids(ClassLoaderData* loader_data) { aoqi@0: loader_data->jmethod_ids()->clear_all_methods(); aoqi@0: } aoqi@0: aoqi@0: bool Method::has_method_vptr(const void* ptr) { aoqi@0: Method m; aoqi@0: // This assumes that the vtbl pointer is the first word of a C++ object. aoqi@0: // This assumption is also in universe.cpp patch_klass_vtble aoqi@0: void* vtbl2 = dereference_vptr((const void*)&m); aoqi@0: void* this_vtbl = dereference_vptr(ptr); aoqi@0: return vtbl2 == this_vtbl; aoqi@0: } aoqi@0: aoqi@0: // Check that this pointer is valid by checking that the vtbl pointer matches aoqi@0: bool Method::is_valid_method() const { aoqi@0: if (this == NULL) { aoqi@0: return false; aoqi@0: } else if (!is_metaspace_object()) { aoqi@0: return false; aoqi@0: } else { aoqi@0: return has_method_vptr((const void*)this); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: void Method::print_jmethod_ids(ClassLoaderData* loader_data, outputStream* out) { aoqi@0: out->print_cr("jni_method_id count = %d", loader_data->jmethod_ids()->count_methods()); aoqi@0: } aoqi@0: #endif // PRODUCT aoqi@0: aoqi@0: aoqi@0: // Printing aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: aoqi@0: void Method::print_on(outputStream* st) const { aoqi@0: ResourceMark rm; aoqi@0: assert(is_method(), "must be method"); aoqi@0: st->print_cr("%s", internal_name()); aoqi@0: // get the effect of PrintOopAddress, always, for methods: aoqi@0: st->print_cr(" - this oop: "INTPTR_FORMAT, (intptr_t)this); aoqi@0: st->print (" - method holder: "); method_holder()->print_value_on(st); st->cr(); aoqi@0: st->print (" - constants: "INTPTR_FORMAT" ", (address)constants()); aoqi@0: constants()->print_value_on(st); st->cr(); aoqi@0: st->print (" - access: 0x%x ", access_flags().as_int()); access_flags().print_on(st); st->cr(); aoqi@0: st->print (" - name: "); name()->print_value_on(st); st->cr(); aoqi@0: st->print (" - signature: "); signature()->print_value_on(st); st->cr(); aoqi@0: st->print_cr(" - max stack: %d", max_stack()); aoqi@0: st->print_cr(" - max locals: %d", max_locals()); aoqi@0: st->print_cr(" - size of params: %d", size_of_parameters()); aoqi@0: st->print_cr(" - method size: %d", method_size()); aoqi@0: if (intrinsic_id() != vmIntrinsics::_none) aoqi@0: st->print_cr(" - intrinsic id: %d %s", intrinsic_id(), vmIntrinsics::name_at(intrinsic_id())); aoqi@0: if (highest_comp_level() != CompLevel_none) aoqi@0: st->print_cr(" - highest level: %d", highest_comp_level()); aoqi@0: st->print_cr(" - vtable index: %d", _vtable_index); aoqi@0: st->print_cr(" - i2i entry: " INTPTR_FORMAT, interpreter_entry()); aoqi@0: st->print( " - adapters: "); aoqi@0: AdapterHandlerEntry* a = ((Method*)this)->adapter(); aoqi@0: if (a == NULL) aoqi@0: st->print_cr(INTPTR_FORMAT, a); aoqi@0: else aoqi@0: a->print_adapter_on(st); aoqi@0: st->print_cr(" - compiled entry " INTPTR_FORMAT, from_compiled_entry()); aoqi@0: st->print_cr(" - code size: %d", code_size()); aoqi@0: if (code_size() != 0) { aoqi@0: st->print_cr(" - code start: " INTPTR_FORMAT, code_base()); aoqi@0: st->print_cr(" - code end (excl): " INTPTR_FORMAT, code_base() + code_size()); aoqi@0: } aoqi@0: if (method_data() != NULL) { aoqi@0: st->print_cr(" - method data: " INTPTR_FORMAT, (address)method_data()); aoqi@0: } aoqi@0: st->print_cr(" - checked ex length: %d", checked_exceptions_length()); aoqi@0: if (checked_exceptions_length() > 0) { aoqi@0: CheckedExceptionElement* table = checked_exceptions_start(); aoqi@0: st->print_cr(" - checked ex start: " INTPTR_FORMAT, table); aoqi@0: if (Verbose) { aoqi@0: for (int i = 0; i < checked_exceptions_length(); i++) { aoqi@0: st->print_cr(" - throws %s", constants()->printable_name_at(table[i].class_cp_index)); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: if (has_linenumber_table()) { aoqi@0: u_char* table = compressed_linenumber_table(); aoqi@0: st->print_cr(" - linenumber start: " INTPTR_FORMAT, table); aoqi@0: if (Verbose) { aoqi@0: CompressedLineNumberReadStream stream(table); aoqi@0: while (stream.read_pair()) { aoqi@0: st->print_cr(" - line %d: %d", stream.line(), stream.bci()); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: st->print_cr(" - localvar length: %d", localvariable_table_length()); aoqi@0: if (localvariable_table_length() > 0) { aoqi@0: LocalVariableTableElement* table = localvariable_table_start(); aoqi@0: st->print_cr(" - localvar start: " INTPTR_FORMAT, table); aoqi@0: if (Verbose) { aoqi@0: for (int i = 0; i < localvariable_table_length(); i++) { aoqi@0: int bci = table[i].start_bci; aoqi@0: int len = table[i].length; aoqi@0: const char* name = constants()->printable_name_at(table[i].name_cp_index); aoqi@0: const char* desc = constants()->printable_name_at(table[i].descriptor_cp_index); aoqi@0: int slot = table[i].slot; aoqi@0: st->print_cr(" - %s %s bci=%d len=%d slot=%d", desc, name, bci, len, slot); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: if (code() != NULL) { aoqi@0: st->print (" - compiled code: "); aoqi@0: code()->print_value_on(st); aoqi@0: } aoqi@0: if (is_native()) { aoqi@0: st->print_cr(" - native function: " INTPTR_FORMAT, native_function()); aoqi@0: st->print_cr(" - signature handler: " INTPTR_FORMAT, signature_handler()); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: #endif //PRODUCT aoqi@0: aoqi@0: void Method::print_value_on(outputStream* st) const { aoqi@0: assert(is_method(), "must be method"); aoqi@0: st->print("%s", internal_name()); aoqi@0: print_address_on(st); aoqi@0: st->print(" "); aoqi@0: name()->print_value_on(st); aoqi@0: st->print(" "); aoqi@0: signature()->print_value_on(st); aoqi@0: st->print(" in "); aoqi@0: method_holder()->print_value_on(st); aoqi@0: if (WizardMode) st->print("#%d", _vtable_index); aoqi@0: if (WizardMode) st->print("[%d,%d]", size_of_parameters(), max_locals()); aoqi@0: if (WizardMode && code() != NULL) st->print(" ((nmethod*)%p)", code()); aoqi@0: } aoqi@0: aoqi@0: #if INCLUDE_SERVICES aoqi@0: // Size Statistics aoqi@0: void Method::collect_statistics(KlassSizeStats *sz) const { aoqi@0: int mysize = sz->count(this); aoqi@0: sz->_method_bytes += mysize; aoqi@0: sz->_method_all_bytes += mysize; aoqi@0: sz->_rw_bytes += mysize; aoqi@0: aoqi@0: if (constMethod()) { aoqi@0: constMethod()->collect_statistics(sz); aoqi@0: } aoqi@0: if (method_data()) { aoqi@0: method_data()->collect_statistics(sz); aoqi@0: } aoqi@0: } aoqi@0: #endif // INCLUDE_SERVICES aoqi@0: aoqi@0: // Verification aoqi@0: aoqi@0: void Method::verify_on(outputStream* st) { aoqi@0: guarantee(is_method(), "object must be method"); aoqi@0: guarantee(constants()->is_constantPool(), "should be constant pool"); aoqi@0: guarantee(constMethod()->is_constMethod(), "should be ConstMethod*"); aoqi@0: MethodData* md = method_data(); aoqi@0: guarantee(md == NULL || aoqi@0: md->is_methodData(), "should be method data"); aoqi@0: }