duke@435: /* jiangli@4936: * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #include "precompiled.hpp" stefank@2314: #include "ci/ciCallProfile.hpp" stefank@2314: #include "ci/ciExceptionHandler.hpp" stefank@2314: #include "ci/ciInstanceKlass.hpp" stefank@2314: #include "ci/ciMethod.hpp" stefank@2314: #include "ci/ciMethodBlocks.hpp" stefank@2314: #include "ci/ciMethodData.hpp" stefank@2314: #include "ci/ciStreams.hpp" stefank@2314: #include "ci/ciSymbol.hpp" minqi@4267: #include "ci/ciReplay.hpp" stefank@2314: #include "ci/ciUtilities.hpp" stefank@2314: #include "classfile/systemDictionary.hpp" stefank@2314: #include "compiler/abstractCompiler.hpp" stefank@2314: #include "compiler/compilerOracle.hpp" stefank@2314: #include "compiler/methodLiveness.hpp" stefank@2314: #include "interpreter/interpreter.hpp" stefank@2314: #include "interpreter/linkResolver.hpp" stefank@2314: #include "interpreter/oopMapCache.hpp" stefank@2314: #include "memory/allocation.inline.hpp" stefank@2314: #include "memory/resourceArea.hpp" stefank@2314: #include "oops/generateOopMap.hpp" stefank@2314: #include "oops/oop.inline.hpp" stefank@2314: #include "prims/nativeLookup.hpp" stefank@2314: #include "runtime/deoptimization.hpp" stefank@2314: #include "utilities/bitMap.inline.hpp" stefank@2314: #include "utilities/xmlstream.hpp" stefank@2314: #ifdef COMPILER2 stefank@2314: #include "ci/bcEscapeAnalyzer.hpp" stefank@2314: #include "ci/ciTypeFlow.hpp" coleenp@4037: #include "oops/method.hpp" stefank@2314: #endif stefank@2314: #ifdef SHARK stefank@2314: #include "ci/ciTypeFlow.hpp" coleenp@4037: #include "oops/method.hpp" stefank@2314: #endif duke@435: duke@435: // ciMethod duke@435: // coleenp@4037: // This class represents a Method* in the HotSpot virtual duke@435: // machine. duke@435: duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciMethod::ciMethod duke@435: // duke@435: // Loaded method. coleenp@4037: ciMethod::ciMethod(methodHandle h_m) : ciMetadata(h_m()) { duke@435: assert(h_m() != NULL, "no null method"); duke@435: duke@435: // These fields are always filled in in loaded methods. duke@435: _flags = ciFlags(h_m()->access_flags()); duke@435: duke@435: // Easy to compute, so fill them in now. duke@435: _max_stack = h_m()->max_stack(); duke@435: _max_locals = h_m()->max_locals(); duke@435: _code_size = h_m()->code_size(); duke@435: _intrinsic_id = h_m()->intrinsic_id(); jiangli@3917: _handler_count = h_m()->exception_table_length(); duke@435: _uses_monitors = h_m()->access_flags().has_monitor_bytecodes(); duke@435: _balanced_monitors = !_uses_monitors || h_m()->access_flags().is_monitor_matching(); iveresov@2138: _is_c1_compilable = !h_m()->is_not_c1_compilable(); iveresov@2138: _is_c2_compilable = !h_m()->is_not_c2_compilable(); duke@435: // Lazy fields, filled in on demand. Require allocation. duke@435: _code = NULL; duke@435: _exception_handlers = NULL; duke@435: _liveness = NULL; duke@435: _method_blocks = NULL; twisti@2047: #if defined(COMPILER2) || defined(SHARK) duke@435: _flow = NULL; kvn@2003: _bcea = NULL; twisti@2047: #endif // COMPILER2 || SHARK duke@435: kvn@1215: ciEnv *env = CURRENT_ENV; iveresov@2138: if (env->jvmti_can_hotswap_or_post_breakpoint() && can_be_compiled()) { duke@435: // 6328518 check hotswap conditions under the right lock. duke@435: MutexLocker locker(Compile_lock); duke@435: if (Dependencies::check_evol_method(h_m()) != NULL) { iveresov@2138: _is_c1_compilable = false; iveresov@2138: _is_c2_compilable = false; duke@435: } duke@435: } else { duke@435: CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops()); duke@435: } duke@435: coleenp@4251: if (h_m()->method_holder()->is_linked()) { duke@435: _can_be_statically_bound = h_m()->can_be_statically_bound(); duke@435: } else { duke@435: // Have to use a conservative value in this case. duke@435: _can_be_statically_bound = false; duke@435: } duke@435: duke@435: // Adjust the definition of this condition to be more useful: duke@435: // %%% take these conditions into account in vtable generation duke@435: if (!_can_be_statically_bound && h_m()->is_private()) duke@435: _can_be_statically_bound = true; duke@435: if (_can_be_statically_bound && h_m()->is_abstract()) duke@435: _can_be_statically_bound = false; duke@435: duke@435: // generating _signature may allow GC and therefore move m. duke@435: // These fields are always filled in. coleenp@2497: _name = env->get_symbol(h_m()->name()); coleenp@4037: _holder = env->get_instance_klass(h_m()->method_holder()); coleenp@2497: ciSymbol* sig_symbol = env->get_symbol(h_m()->signature()); jrose@2982: constantPoolHandle cpool = h_m()->constants(); jrose@2982: _signature = new (env->arena()) ciSignature(_holder, cpool, sig_symbol); duke@435: _method_data = NULL; duke@435: // Take a snapshot of these values, so they will be commensurate with the MDO. iveresov@2138: if (ProfileInterpreter || TieredCompilation) { duke@435: int invcnt = h_m()->interpreter_invocation_count(); duke@435: // if the value overflowed report it as max int duke@435: _interpreter_invocation_count = invcnt < 0 ? max_jint : invcnt ; duke@435: _interpreter_throwout_count = h_m()->interpreter_throwout_count(); duke@435: } else { duke@435: _interpreter_invocation_count = 0; duke@435: _interpreter_throwout_count = 0; duke@435: } duke@435: if (_interpreter_invocation_count == 0) duke@435: _interpreter_invocation_count = 1; minqi@4267: _instructions_size = -1; minqi@4267: #ifdef ASSERT minqi@4267: if (ReplayCompiles) { minqi@4267: ciReplay::initialize(this); minqi@4267: } minqi@4267: #endif duke@435: } duke@435: duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciMethod::ciMethod duke@435: // duke@435: // Unloaded method. duke@435: ciMethod::ciMethod(ciInstanceKlass* holder, twisti@3197: ciSymbol* name, twisti@3197: ciSymbol* signature, twisti@3197: ciInstanceKlass* accessor) : coleenp@4037: ciMetadata((Metadata*)NULL), twisti@3197: _name( name), twisti@3197: _holder( holder), twisti@3197: _intrinsic_id( vmIntrinsics::_none), twisti@3197: _liveness( NULL), twisti@3197: _can_be_statically_bound(false), twisti@3197: _method_blocks( NULL), twisti@3197: _method_data( NULL) twisti@2047: #if defined(COMPILER2) || defined(SHARK) twisti@3197: , twisti@3197: _flow( NULL), minqi@4267: _bcea( NULL), minqi@4267: _instructions_size(-1) twisti@2047: #endif // COMPILER2 || SHARK twisti@3197: { twisti@3197: // Usually holder and accessor are the same type but in some cases twisti@3197: // the holder has the wrong class loader (e.g. invokedynamic call twisti@3197: // sites) so we pass the accessor. twisti@3197: _signature = new (CURRENT_ENV->arena()) ciSignature(accessor, constantPoolHandle(), signature); duke@435: } duke@435: duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciMethod::load_code duke@435: // duke@435: // Load the bytecodes and exception handler table for this method. duke@435: void ciMethod::load_code() { duke@435: VM_ENTRY_MARK; duke@435: assert(is_loaded(), "only loaded methods have code"); duke@435: coleenp@4037: Method* me = get_Method(); duke@435: Arena* arena = CURRENT_THREAD_ENV->arena(); duke@435: duke@435: // Load the bytecodes. duke@435: _code = (address)arena->Amalloc(code_size()); duke@435: memcpy(_code, me->code_base(), code_size()); duke@435: duke@435: // Revert any breakpoint bytecodes in ci's copy kvn@462: if (me->number_of_breakpoints() > 0) { coleenp@4251: BreakpointInfo* bp = me->method_holder()->breakpoints(); duke@435: for (; bp != NULL; bp = bp->next()) { duke@435: if (bp->match(me)) { duke@435: code_at_put(bp->bci(), bp->orig_bytecode()); duke@435: } duke@435: } duke@435: } duke@435: duke@435: // And load the exception table. jiangli@3917: ExceptionTable exc_table(me); duke@435: duke@435: // Allocate one extra spot in our list of exceptions. This duke@435: // last entry will be used to represent the possibility that duke@435: // an exception escapes the method. See ciExceptionHandlerStream duke@435: // for details. duke@435: _exception_handlers = duke@435: (ciExceptionHandler**)arena->Amalloc(sizeof(ciExceptionHandler*) duke@435: * (_handler_count + 1)); duke@435: if (_handler_count > 0) { duke@435: for (int i=0; i<_handler_count; i++) { duke@435: _exception_handlers[i] = new (arena) ciExceptionHandler( duke@435: holder(), jiangli@3917: /* start */ exc_table.start_pc(i), jiangli@3917: /* limit */ exc_table.end_pc(i), jiangli@3917: /* goto pc */ exc_table.handler_pc(i), jiangli@3917: /* cp index */ exc_table.catch_type_index(i)); duke@435: } duke@435: } duke@435: duke@435: // Put an entry at the end of our list to represent the possibility duke@435: // of exceptional exit. duke@435: _exception_handlers[_handler_count] = duke@435: new (arena) ciExceptionHandler(holder(), 0, code_size(), -1, 0); duke@435: duke@435: if (CIPrintMethodCodes) { duke@435: print_codes(); duke@435: } duke@435: } duke@435: duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciMethod::has_linenumber_table duke@435: // duke@435: // length unknown until decompression duke@435: bool ciMethod::has_linenumber_table() const { duke@435: check_is_loaded(); duke@435: VM_ENTRY_MARK; coleenp@4037: return get_Method()->has_linenumber_table(); duke@435: } duke@435: duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciMethod::compressed_linenumber_table duke@435: u_char* ciMethod::compressed_linenumber_table() const { duke@435: check_is_loaded(); duke@435: VM_ENTRY_MARK; coleenp@4037: return get_Method()->compressed_linenumber_table(); duke@435: } duke@435: duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciMethod::line_number_from_bci duke@435: int ciMethod::line_number_from_bci(int bci) const { duke@435: check_is_loaded(); duke@435: VM_ENTRY_MARK; coleenp@4037: return get_Method()->line_number_from_bci(bci); duke@435: } duke@435: duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciMethod::vtable_index duke@435: // duke@435: // Get the position of this method's entry in the vtable, if any. duke@435: int ciMethod::vtable_index() { duke@435: check_is_loaded(); duke@435: assert(holder()->is_linked(), "must be linked"); duke@435: VM_ENTRY_MARK; coleenp@4037: return get_Method()->vtable_index(); duke@435: } duke@435: duke@435: twisti@2047: #ifdef SHARK twisti@2047: // ------------------------------------------------------------------ twisti@2047: // ciMethod::itable_index twisti@2047: // twisti@2047: // Get the position of this method's entry in the itable, if any. twisti@2047: int ciMethod::itable_index() { twisti@2047: check_is_loaded(); twisti@2047: assert(holder()->is_linked(), "must be linked"); twisti@2047: VM_ENTRY_MARK; drchase@5732: Method* m = get_Method(); drchase@5732: if (!m->has_itable_index()) drchase@5732: return Method::nonvirtual_vtable_index; drchase@5732: return m->itable_index(); twisti@2047: } twisti@2047: #endif // SHARK twisti@2047: twisti@2047: duke@435: // ------------------------------------------------------------------ duke@435: // ciMethod::native_entry duke@435: // duke@435: // Get the address of this method's native code, if any. duke@435: address ciMethod::native_entry() { duke@435: check_is_loaded(); duke@435: assert(flags().is_native(), "must be native method"); duke@435: VM_ENTRY_MARK; coleenp@4037: Method* method = get_Method(); duke@435: address entry = method->native_function(); duke@435: assert(entry != NULL, "must be valid entry point"); duke@435: return entry; duke@435: } duke@435: duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciMethod::interpreter_entry duke@435: // duke@435: // Get the entry point for running this method in the interpreter. duke@435: address ciMethod::interpreter_entry() { duke@435: check_is_loaded(); duke@435: VM_ENTRY_MARK; coleenp@4037: methodHandle mh(THREAD, get_Method()); duke@435: return Interpreter::entry_for_method(mh); duke@435: } duke@435: duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciMethod::uses_balanced_monitors duke@435: // duke@435: // Does this method use monitors in a strict stack-disciplined manner? duke@435: bool ciMethod::has_balanced_monitors() { duke@435: check_is_loaded(); duke@435: if (_balanced_monitors) return true; duke@435: duke@435: // Analyze the method to see if monitors are used properly. duke@435: VM_ENTRY_MARK; coleenp@4037: methodHandle method(THREAD, get_Method()); duke@435: assert(method->has_monitor_bytecodes(), "should have checked this"); duke@435: duke@435: // Check to see if a previous compilation computed the duke@435: // monitor-matching analysis. duke@435: if (method->guaranteed_monitor_matching()) { duke@435: _balanced_monitors = true; duke@435: return true; duke@435: } duke@435: duke@435: { duke@435: EXCEPTION_MARK; duke@435: ResourceMark rm(THREAD); duke@435: GeneratePairingInfo gpi(method); duke@435: gpi.compute_map(CATCH); duke@435: if (!gpi.monitor_safe()) { duke@435: return false; duke@435: } duke@435: method->set_guaranteed_monitor_matching(); duke@435: _balanced_monitors = true; duke@435: } duke@435: return true; duke@435: } duke@435: duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciMethod::get_flow_analysis duke@435: ciTypeFlow* ciMethod::get_flow_analysis() { twisti@2047: #if defined(COMPILER2) || defined(SHARK) duke@435: if (_flow == NULL) { duke@435: ciEnv* env = CURRENT_ENV; duke@435: _flow = new (env->arena()) ciTypeFlow(env, this); duke@435: _flow->do_flow(); duke@435: } duke@435: return _flow; twisti@2047: #else // COMPILER2 || SHARK duke@435: ShouldNotReachHere(); duke@435: return NULL; twisti@2047: #endif // COMPILER2 || SHARK duke@435: } duke@435: duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciMethod::get_osr_flow_analysis duke@435: ciTypeFlow* ciMethod::get_osr_flow_analysis(int osr_bci) { twisti@2047: #if defined(COMPILER2) || defined(SHARK) duke@435: // OSR entry points are always place after a call bytecode of some sort duke@435: assert(osr_bci >= 0, "must supply valid OSR entry point"); duke@435: ciEnv* env = CURRENT_ENV; duke@435: ciTypeFlow* flow = new (env->arena()) ciTypeFlow(env, this, osr_bci); duke@435: flow->do_flow(); duke@435: return flow; twisti@2047: #else // COMPILER2 || SHARK duke@435: ShouldNotReachHere(); duke@435: return NULL; twisti@2047: #endif // COMPILER2 || SHARK duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ never@1426: // ciMethod::raw_liveness_at_bci duke@435: // duke@435: // Which local variables are live at a specific bci? never@1426: MethodLivenessResult ciMethod::raw_liveness_at_bci(int bci) { duke@435: check_is_loaded(); duke@435: if (_liveness == NULL) { duke@435: // Create the liveness analyzer. duke@435: Arena* arena = CURRENT_ENV->arena(); duke@435: _liveness = new (arena) MethodLiveness(arena, this); duke@435: _liveness->compute_liveness(); duke@435: } never@1426: return _liveness->get_liveness_at(bci); never@1426: } never@1426: never@1426: // ------------------------------------------------------------------ never@1426: // ciMethod::liveness_at_bci never@1426: // never@1426: // Which local variables are live at a specific bci? When debugging never@1426: // will return true for all locals in some cases to improve debug never@1426: // information. never@1426: MethodLivenessResult ciMethod::liveness_at_bci(int bci) { never@1426: MethodLivenessResult result = raw_liveness_at_bci(bci); kvn@1215: if (CURRENT_ENV->jvmti_can_access_local_variables() || DeoptimizeALot || CompileTheWorld) { duke@435: // Keep all locals live for the user's edification and amusement. duke@435: result.at_put_range(0, result.size(), true); duke@435: } duke@435: return result; duke@435: } duke@435: duke@435: // ciMethod::live_local_oops_at_bci duke@435: // duke@435: // find all the live oops in the locals array for a particular bci duke@435: // Compute what the interpreter believes by using the interpreter duke@435: // oopmap generator. This is used as a double check during osr to duke@435: // guard against conservative result from MethodLiveness making us duke@435: // think a dead oop is live. MethodLiveness is conservative in the duke@435: // sense that it may consider locals to be live which cannot be live, duke@435: // like in the case where a local could contain an oop or a primitive duke@435: // along different paths. In that case the local must be dead when duke@435: // those paths merge. Since the interpreter's viewpoint is used when duke@435: // gc'ing an interpreter frame we need to use its viewpoint during duke@435: // OSR when loading the locals. duke@435: duke@435: BitMap ciMethod::live_local_oops_at_bci(int bci) { duke@435: VM_ENTRY_MARK; duke@435: InterpreterOopMap mask; coleenp@4037: OopMapCache::compute_one_oop_map(get_Method(), bci, &mask); duke@435: int mask_size = max_locals(); duke@435: BitMap result(mask_size); duke@435: result.clear(); duke@435: int i; duke@435: for (i = 0; i < mask_size ; i++ ) { duke@435: if (mask.is_oop(i)) result.set_bit(i); duke@435: } duke@435: return result; duke@435: } duke@435: duke@435: duke@435: #ifdef COMPILER1 duke@435: // ------------------------------------------------------------------ duke@435: // ciMethod::bci_block_start duke@435: // duke@435: // Marks all bcis where a new basic block starts duke@435: const BitMap ciMethod::bci_block_start() { duke@435: check_is_loaded(); duke@435: if (_liveness == NULL) { duke@435: // Create the liveness analyzer. duke@435: Arena* arena = CURRENT_ENV->arena(); duke@435: _liveness = new (arena) MethodLiveness(arena, this); duke@435: _liveness->compute_liveness(); duke@435: } duke@435: duke@435: return _liveness->get_bci_block_start(); duke@435: } duke@435: #endif // COMPILER1 duke@435: duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciMethod::call_profile_at_bci duke@435: // duke@435: // Get the ciCallProfile for the invocation of this method. duke@435: // Also reports receiver types for non-call type checks (if TypeProfileCasts). duke@435: ciCallProfile ciMethod::call_profile_at_bci(int bci) { duke@435: ResourceMark rm; duke@435: ciCallProfile result; duke@435: if (method_data() != NULL && method_data()->is_mature()) { duke@435: ciProfileData* data = method_data()->bci_to_data(bci); duke@435: if (data != NULL && data->is_CounterData()) { duke@435: // Every profiled call site has a counter. duke@435: int count = data->as_CounterData()->count(); duke@435: duke@435: if (!data->is_ReceiverTypeData()) { duke@435: result._receiver_count[0] = 0; // that's a definite zero duke@435: } else { // ReceiverTypeData is a subclass of CounterData duke@435: ciReceiverTypeData* call = (ciReceiverTypeData*)data->as_ReceiverTypeData(); duke@435: // In addition, virtual call sites have receiver type information duke@435: int receivers_count_total = 0; duke@435: int morphism = 0; iveresov@2138: // Precompute morphism for the possible fixup duke@435: for (uint i = 0; i < call->row_limit(); i++) { duke@435: ciKlass* receiver = call->receiver(i); duke@435: if (receiver == NULL) continue; iveresov@2138: morphism++; iveresov@2138: } iveresov@2138: int epsilon = 0; iveresov@2138: if (TieredCompilation && ProfileInterpreter) { iveresov@2138: // Interpreter and C1 treat final and special invokes differently. iveresov@2138: // C1 will record a type, whereas the interpreter will just iveresov@2138: // increment the count. Detect this case. iveresov@2138: if (morphism == 1 && count > 0) { iveresov@2138: epsilon = count; iveresov@2138: count = 0; iveresov@2138: } iveresov@2138: } iveresov@2138: for (uint i = 0; i < call->row_limit(); i++) { iveresov@2138: ciKlass* receiver = call->receiver(i); iveresov@2138: if (receiver == NULL) continue; iveresov@2138: int rcount = call->receiver_count(i) + epsilon; duke@435: if (rcount == 0) rcount = 1; // Should be valid value duke@435: receivers_count_total += rcount; duke@435: // Add the receiver to result data. duke@435: result.add_receiver(receiver, rcount); duke@435: // If we extend profiling to record methods, duke@435: // we will set result._method also. duke@435: } duke@435: // Determine call site's morphism. kvn@1641: // The call site count is 0 with known morphism (onlt 1 or 2 receivers) kvn@1641: // or < 0 in the case of a type check failured for checkcast, aastore, instanceof. kvn@1641: // The call site count is > 0 in the case of a polymorphic virtual call. kvn@1641: if (morphism > 0 && morphism == result._limit) { kvn@1641: // The morphism <= MorphismLimit. kvn@1641: if ((morphism < ciCallProfile::MorphismLimit) || kvn@1641: (morphism == ciCallProfile::MorphismLimit && count == 0)) { kvn@1641: #ifdef ASSERT kvn@1641: if (count > 0) { kvn@1686: this->print_short_name(tty); kvn@1686: tty->print_cr(" @ bci:%d", bci); kvn@1641: this->print_codes(); kvn@1641: assert(false, "this call site should not be polymorphic"); kvn@1641: } kvn@1641: #endif duke@435: result._morphism = morphism; duke@435: } duke@435: } duke@435: // Make the count consistent if this is a call profile. If count is duke@435: // zero or less, presume that this is a typecheck profile and duke@435: // do nothing. Otherwise, increase count to be the sum of all duke@435: // receiver's counts. kvn@1641: if (count >= 0) { kvn@1641: count += receivers_count_total; duke@435: } duke@435: } duke@435: result._count = count; duke@435: } duke@435: } duke@435: return result; duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // Add new receiver and sort data by receiver's profile count. duke@435: void ciCallProfile::add_receiver(ciKlass* receiver, int receiver_count) { duke@435: // Add new receiver and sort data by receiver's counts when we have space duke@435: // for it otherwise replace the less called receiver (less called receiver duke@435: // is placed to the last array element which is not used). duke@435: // First array's element contains most called receiver. duke@435: int i = _limit; duke@435: for (; i > 0 && receiver_count > _receiver_count[i-1]; i--) { duke@435: _receiver[i] = _receiver[i-1]; duke@435: _receiver_count[i] = _receiver_count[i-1]; duke@435: } duke@435: _receiver[i] = receiver; duke@435: _receiver_count[i] = receiver_count; duke@435: if (_limit < MorphismLimit) _limit++; duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciMethod::find_monomorphic_target duke@435: // duke@435: // Given a certain calling environment, find the monomorphic target duke@435: // for the call. Return NULL if the call is not monomorphic in duke@435: // its calling environment, or if there are only abstract methods. duke@435: // The returned method is never abstract. duke@435: // Note: If caller uses a non-null result, it must inform dependencies duke@435: // via assert_unique_concrete_method or assert_leaf_type. duke@435: ciMethod* ciMethod::find_monomorphic_target(ciInstanceKlass* caller, duke@435: ciInstanceKlass* callee_holder, duke@435: ciInstanceKlass* actual_recv) { duke@435: check_is_loaded(); duke@435: duke@435: if (actual_recv->is_interface()) { duke@435: // %%% We cannot trust interface types, yet. See bug 6312651. duke@435: return NULL; duke@435: } duke@435: duke@435: ciMethod* root_m = resolve_invoke(caller, actual_recv); duke@435: if (root_m == NULL) { duke@435: // Something went wrong looking up the actual receiver method. duke@435: return NULL; duke@435: } duke@435: assert(!root_m->is_abstract(), "resolve_invoke promise"); duke@435: duke@435: // Make certain quick checks even if UseCHA is false. duke@435: duke@435: // Is it private or final? duke@435: if (root_m->can_be_statically_bound()) { duke@435: return root_m; duke@435: } duke@435: duke@435: if (actual_recv->is_leaf_type() && actual_recv == root_m->holder()) { duke@435: // Easy case. There is no other place to put a method, so don't bother duke@435: // to go through the VM_ENTRY_MARK and all the rest. duke@435: return root_m; duke@435: } duke@435: duke@435: // Array methods (clone, hashCode, etc.) are always statically bound. duke@435: // If we were to see an array type here, we'd return root_m. duke@435: // However, this method processes only ciInstanceKlasses. (See 4962591.) duke@435: // The inline_native_clone intrinsic narrows Object to T[] properly, duke@435: // so there is no need to do the same job here. duke@435: duke@435: if (!UseCHA) return NULL; duke@435: duke@435: VM_ENTRY_MARK; duke@435: duke@435: methodHandle target; duke@435: { duke@435: MutexLocker locker(Compile_lock); coleenp@4037: Klass* context = actual_recv->get_Klass(); duke@435: target = Dependencies::find_unique_concrete_method(context, coleenp@4037: root_m->get_Method()); duke@435: // %%% Should upgrade this ciMethod API to look for 1 or 2 concrete methods. duke@435: } duke@435: duke@435: #ifndef PRODUCT coleenp@4037: if (TraceDependencies && target() != NULL && target() != root_m->get_Method()) { duke@435: tty->print("found a non-root unique target method"); coleenp@4037: tty->print_cr(" context = %s", InstanceKlass::cast(actual_recv->get_Klass())->external_name()); duke@435: tty->print(" method = "); duke@435: target->print_short_name(tty); duke@435: tty->cr(); duke@435: } duke@435: #endif //PRODUCT duke@435: duke@435: if (target() == NULL) { duke@435: return NULL; duke@435: } coleenp@4037: if (target() == root_m->get_Method()) { duke@435: return root_m; duke@435: } duke@435: if (!root_m->is_public() && duke@435: !root_m->is_protected()) { duke@435: // If we are going to reason about inheritance, it's easiest duke@435: // if the method in question is public, protected, or private. duke@435: // If the answer is not root_m, it is conservatively correct duke@435: // to return NULL, even if the CHA encountered irrelevant duke@435: // methods in other packages. duke@435: // %%% TO DO: Work out logic for package-private methods duke@435: // with the same name but different vtable indexes. duke@435: return NULL; duke@435: } coleenp@4037: return CURRENT_THREAD_ENV->get_method(target()); duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciMethod::resolve_invoke duke@435: // duke@435: // Given a known receiver klass, find the target for the call. duke@435: // Return NULL if the call has no target or the target is abstract. duke@435: ciMethod* ciMethod::resolve_invoke(ciKlass* caller, ciKlass* exact_receiver) { duke@435: check_is_loaded(); duke@435: VM_ENTRY_MARK; duke@435: coleenp@4037: KlassHandle caller_klass (THREAD, caller->get_Klass()); coleenp@4037: KlassHandle h_recv (THREAD, exact_receiver->get_Klass()); coleenp@4037: KlassHandle h_resolved (THREAD, holder()->get_Klass()); coleenp@2497: Symbol* h_name = name()->get_symbol(); coleenp@2497: Symbol* h_signature = signature()->get_symbol(); duke@435: duke@435: methodHandle m; duke@435: // Only do exact lookup if receiver klass has been linked. Otherwise, duke@435: // the vtable has not been setup, and the LinkResolver will fail. coleenp@4037: if (h_recv->oop_is_array() duke@435: || coleenp@4037: InstanceKlass::cast(h_recv())->is_linked() && !exact_receiver->is_interface()) { duke@435: if (holder()->is_interface()) { duke@435: m = LinkResolver::resolve_interface_call_or_null(h_recv, h_resolved, h_name, h_signature, caller_klass); duke@435: } else { duke@435: m = LinkResolver::resolve_virtual_call_or_null(h_recv, h_resolved, h_name, h_signature, caller_klass); duke@435: } duke@435: } duke@435: duke@435: if (m.is_null()) { duke@435: // Return NULL only if there was a problem with lookup (uninitialized class, etc.) duke@435: return NULL; duke@435: } duke@435: duke@435: ciMethod* result = this; coleenp@4037: if (m() != get_Method()) { coleenp@4037: result = CURRENT_THREAD_ENV->get_method(m()); duke@435: } duke@435: duke@435: // Don't return abstract methods because they aren't duke@435: // optimizable or interesting. duke@435: if (result->is_abstract()) { duke@435: return NULL; duke@435: } else { duke@435: return result; duke@435: } duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciMethod::resolve_vtable_index duke@435: // duke@435: // Given a known receiver klass, find the vtable index for the call. coleenp@4037: // Return Method::invalid_vtable_index if the vtable_index is unknown. duke@435: int ciMethod::resolve_vtable_index(ciKlass* caller, ciKlass* receiver) { duke@435: check_is_loaded(); duke@435: coleenp@4037: int vtable_index = Method::invalid_vtable_index; duke@435: // Only do lookup if receiver klass has been linked. Otherwise, duke@435: // the vtable has not been setup, and the LinkResolver will fail. duke@435: if (!receiver->is_interface() duke@435: && (!receiver->is_instance_klass() || duke@435: receiver->as_instance_klass()->is_linked())) { duke@435: VM_ENTRY_MARK; duke@435: coleenp@4037: KlassHandle caller_klass (THREAD, caller->get_Klass()); coleenp@4037: KlassHandle h_recv (THREAD, receiver->get_Klass()); coleenp@2497: Symbol* h_name = name()->get_symbol(); coleenp@2497: Symbol* h_signature = signature()->get_symbol(); duke@435: duke@435: vtable_index = LinkResolver::resolve_virtual_vtable_index(h_recv, h_recv, h_name, h_signature, caller_klass); coleenp@4037: if (vtable_index == Method::nonvirtual_vtable_index) { duke@435: // A statically bound method. Return "no such index". coleenp@4037: vtable_index = Method::invalid_vtable_index; duke@435: } duke@435: } duke@435: duke@435: return vtable_index; duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciMethod::interpreter_call_site_count duke@435: int ciMethod::interpreter_call_site_count(int bci) { duke@435: if (method_data() != NULL) { duke@435: ResourceMark rm; duke@435: ciProfileData* data = method_data()->bci_to_data(bci); duke@435: if (data != NULL && data->is_CounterData()) { duke@435: return scale_count(data->as_CounterData()->count()); duke@435: } duke@435: } duke@435: return -1; // unknown duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ twisti@4313: // ciMethod::get_field_at_bci twisti@4313: ciField* ciMethod::get_field_at_bci(int bci, bool &will_link) { twisti@4313: ciBytecodeStream iter(this); twisti@4313: iter.reset_to_bci(bci); twisti@4313: iter.next(); twisti@4313: return iter.get_field(will_link); twisti@4313: } twisti@4313: twisti@4313: // ------------------------------------------------------------------ twisti@4313: // ciMethod::get_method_at_bci twisti@4313: ciMethod* ciMethod::get_method_at_bci(int bci, bool &will_link, ciSignature* *declared_signature) { twisti@4313: ciBytecodeStream iter(this); twisti@4313: iter.reset_to_bci(bci); twisti@4313: iter.next(); twisti@4313: return iter.get_method(will_link, declared_signature); twisti@4313: } twisti@4313: twisti@4313: // ------------------------------------------------------------------ duke@435: // Adjust a CounterData count to be commensurate with duke@435: // interpreter_invocation_count. If the MDO exists for duke@435: // only 25% of the time the method exists, then the duke@435: // counts in the MDO should be scaled by 4X, so that duke@435: // they can be usefully and stably compared against the duke@435: // invocation counts in methods. duke@435: int ciMethod::scale_count(int count, float prof_factor) { duke@435: if (count > 0 && method_data() != NULL) { iveresov@2138: int counter_life; duke@435: int method_life = interpreter_invocation_count(); iveresov@2138: if (TieredCompilation) { iveresov@2138: // In tiered the MDO's life is measured directly, so just use the snapshotted counters iveresov@2138: counter_life = MAX2(method_data()->invocation_count(), method_data()->backedge_count()); iveresov@2138: } else { iveresov@2138: int current_mileage = method_data()->current_mileage(); iveresov@2138: int creation_mileage = method_data()->creation_mileage(); iveresov@2138: counter_life = current_mileage - creation_mileage; iveresov@2138: } iveresov@2138: duke@435: // counter_life due to backedge_counter could be > method_life duke@435: if (counter_life > method_life) duke@435: counter_life = method_life; duke@435: if (0 < counter_life && counter_life <= method_life) { duke@435: count = (int)((double)count * prof_factor * method_life / counter_life + 0.5); duke@435: count = (count > 0) ? count : 1; duke@435: } duke@435: } duke@435: return count; duke@435: } duke@435: twisti@4866: twisti@4866: // ------------------------------------------------------------------ twisti@4866: // ciMethod::is_special_get_caller_class_method twisti@4866: // twisti@4866: bool ciMethod::is_ignored_by_security_stack_walk() const { twisti@4866: check_is_loaded(); twisti@4866: VM_ENTRY_MARK; twisti@4866: return get_Method()->is_ignored_by_security_stack_walk(); twisti@4866: } twisti@4866: twisti@4866: duke@435: // ------------------------------------------------------------------ jrose@1145: // invokedynamic support twisti@1919: twisti@1919: // ------------------------------------------------------------------ twisti@3969: // ciMethod::is_method_handle_intrinsic jrose@1145: // twisti@3969: // Return true if the method is an instance of the JVM-generated twisti@3969: // signature-polymorphic MethodHandle methods, _invokeBasic, _linkToVirtual, etc. twisti@3969: bool ciMethod::is_method_handle_intrinsic() const { twisti@3969: vmIntrinsics::ID iid = _intrinsic_id; // do not check if loaded twisti@3969: return (MethodHandles::is_signature_polymorphic(iid) && twisti@3969: MethodHandles::is_signature_polymorphic_intrinsic(iid)); jrose@1145: } jrose@1145: twisti@1919: // ------------------------------------------------------------------ twisti@3969: // ciMethod::is_compiled_lambda_form twisti@1919: // twisti@1919: // Return true if the method is a generated MethodHandle adapter. twisti@3969: // These are built by Java code. twisti@3969: bool ciMethod::is_compiled_lambda_form() const { twisti@3969: vmIntrinsics::ID iid = _intrinsic_id; // do not check if loaded twisti@3969: return iid == vmIntrinsics::_compiledLambdaForm; twisti@1587: } twisti@1587: twisti@3969: // ------------------------------------------------------------------ twisti@3969: // ciMethod::has_member_arg twisti@3969: // twisti@3969: // Return true if the method is a linker intrinsic like _linkToVirtual. twisti@3969: // These are built by the JVM. twisti@3969: bool ciMethod::has_member_arg() const { twisti@3969: vmIntrinsics::ID iid = _intrinsic_id; // do not check if loaded twisti@3969: return (MethodHandles::is_signature_polymorphic(iid) && twisti@3969: MethodHandles::has_member_arg(iid)); jrose@1145: } jrose@1145: jrose@1145: // ------------------------------------------------------------------ iveresov@2349: // ciMethod::ensure_method_data duke@435: // coleenp@4037: // Generate new MethodData* objects at compile time. iveresov@2349: // Return true if allocation was successful or no MDO is required. iveresov@2349: bool ciMethod::ensure_method_data(methodHandle h_m) { duke@435: EXCEPTION_CONTEXT; iveresov@2349: if (is_native() || is_abstract() || h_m()->is_accessor()) return true; duke@435: if (h_m()->method_data() == NULL) { coleenp@4037: Method::build_interpreter_method_data(h_m, THREAD); duke@435: if (HAS_PENDING_EXCEPTION) { duke@435: CLEAR_PENDING_EXCEPTION; duke@435: } duke@435: } duke@435: if (h_m()->method_data() != NULL) { coleenp@4037: _method_data = CURRENT_ENV->get_method_data(h_m()->method_data()); duke@435: _method_data->load_data(); iveresov@2349: return true; duke@435: } else { duke@435: _method_data = CURRENT_ENV->get_empty_methodData(); iveresov@2349: return false; duke@435: } duke@435: } duke@435: duke@435: // public, retroactive version iveresov@2349: bool ciMethod::ensure_method_data() { iveresov@2349: bool result = true; duke@435: if (_method_data == NULL || _method_data->is_empty()) { duke@435: GUARDED_VM_ENTRY({ coleenp@4037: result = ensure_method_data(get_Method()); duke@435: }); duke@435: } iveresov@2349: return result; duke@435: } duke@435: duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciMethod::method_data duke@435: // duke@435: ciMethodData* ciMethod::method_data() { duke@435: if (_method_data != NULL) { duke@435: return _method_data; duke@435: } duke@435: VM_ENTRY_MARK; duke@435: ciEnv* env = CURRENT_ENV; duke@435: Thread* my_thread = JavaThread::current(); coleenp@4037: methodHandle h_m(my_thread, get_Method()); duke@435: duke@435: if (h_m()->method_data() != NULL) { coleenp@4037: _method_data = CURRENT_ENV->get_method_data(h_m()->method_data()); duke@435: _method_data->load_data(); duke@435: } else { duke@435: _method_data = CURRENT_ENV->get_empty_methodData(); duke@435: } duke@435: return _method_data; duke@435: duke@435: } duke@435: iveresov@2349: // ------------------------------------------------------------------ iveresov@2349: // ciMethod::method_data_or_null iveresov@2349: // Returns a pointer to ciMethodData if MDO exists on the VM side, iveresov@2349: // NULL otherwise. iveresov@2349: ciMethodData* ciMethod::method_data_or_null() { iveresov@2349: ciMethodData *md = method_data(); iveresov@2349: if (md->is_empty()) return NULL; iveresov@2349: return md; iveresov@2349: } duke@435: duke@435: // ------------------------------------------------------------------ jiangli@4936: // ciMethod::ensure_method_counters jiangli@4936: // jiangli@4936: address ciMethod::ensure_method_counters() { jiangli@4936: check_is_loaded(); jiangli@4936: VM_ENTRY_MARK; jiangli@4936: methodHandle mh(THREAD, get_Method()); jiangli@4936: MethodCounters *counter = mh->method_counters(); jiangli@4936: if (counter == NULL) { jiangli@4936: counter = Method::build_method_counters(mh(), CHECK_AND_CLEAR_NULL); jiangli@4936: } jiangli@4936: return (address)counter; jiangli@4936: } jiangli@4936: jiangli@4936: // ------------------------------------------------------------------ duke@435: // ciMethod::should_exclude duke@435: // duke@435: // Should this method be excluded from compilation? duke@435: bool ciMethod::should_exclude() { duke@435: check_is_loaded(); duke@435: VM_ENTRY_MARK; coleenp@4037: methodHandle mh(THREAD, get_Method()); duke@435: bool ignore; duke@435: return CompilerOracle::should_exclude(mh, ignore); duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciMethod::should_inline duke@435: // duke@435: // Should this method be inlined during compilation? duke@435: bool ciMethod::should_inline() { duke@435: check_is_loaded(); duke@435: VM_ENTRY_MARK; coleenp@4037: methodHandle mh(THREAD, get_Method()); duke@435: return CompilerOracle::should_inline(mh); duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciMethod::should_not_inline duke@435: // duke@435: // Should this method be disallowed from inlining during compilation? duke@435: bool ciMethod::should_not_inline() { duke@435: check_is_loaded(); duke@435: VM_ENTRY_MARK; coleenp@4037: methodHandle mh(THREAD, get_Method()); duke@435: return CompilerOracle::should_not_inline(mh); duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciMethod::should_print_assembly duke@435: // duke@435: // Should the compiler print the generated code for this method? duke@435: bool ciMethod::should_print_assembly() { duke@435: check_is_loaded(); duke@435: VM_ENTRY_MARK; coleenp@4037: methodHandle mh(THREAD, get_Method()); duke@435: return CompilerOracle::should_print(mh); duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciMethod::break_at_execute duke@435: // duke@435: // Should the compiler insert a breakpoint into the generated code duke@435: // method? duke@435: bool ciMethod::break_at_execute() { duke@435: check_is_loaded(); duke@435: VM_ENTRY_MARK; coleenp@4037: methodHandle mh(THREAD, get_Method()); duke@435: return CompilerOracle::should_break_at(mh); duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciMethod::has_option duke@435: // duke@435: bool ciMethod::has_option(const char* option) { duke@435: check_is_loaded(); duke@435: VM_ENTRY_MARK; coleenp@4037: methodHandle mh(THREAD, get_Method()); duke@435: return CompilerOracle::has_option_string(mh, option); duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciMethod::can_be_compiled duke@435: // duke@435: // Have previous compilations of this method succeeded? duke@435: bool ciMethod::can_be_compiled() { duke@435: check_is_loaded(); iveresov@2138: ciEnv* env = CURRENT_ENV; iveresov@2138: if (is_c1_compile(env->comp_level())) { iveresov@2138: return _is_c1_compilable; iveresov@2138: } iveresov@2138: return _is_c2_compilable; duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciMethod::set_not_compilable duke@435: // duke@435: // Tell the VM that this method cannot be compiled at all. vlivanov@4539: void ciMethod::set_not_compilable(const char* reason) { duke@435: check_is_loaded(); duke@435: VM_ENTRY_MARK; iveresov@2138: ciEnv* env = CURRENT_ENV; iveresov@2138: if (is_c1_compile(env->comp_level())) { iveresov@2138: _is_c1_compilable = false; iveresov@2138: } else { iveresov@2138: _is_c2_compilable = false; iveresov@2138: } vlivanov@4539: get_Method()->set_not_compilable(env->comp_level(), true, reason); duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciMethod::can_be_osr_compiled duke@435: // duke@435: // Have previous compilations of this method succeeded? duke@435: // duke@435: // Implementation note: the VM does not currently keep track duke@435: // of failed OSR compilations per bci. The entry_bci parameter duke@435: // is currently unused. duke@435: bool ciMethod::can_be_osr_compiled(int entry_bci) { duke@435: check_is_loaded(); duke@435: VM_ENTRY_MARK; iveresov@2138: ciEnv* env = CURRENT_ENV; coleenp@4037: return !get_Method()->is_not_osr_compilable(env->comp_level()); duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciMethod::has_compiled_code duke@435: bool ciMethod::has_compiled_code() { minqi@4267: return instructions_size() > 0; duke@435: } duke@435: iveresov@2138: int ciMethod::comp_level() { iveresov@2138: check_is_loaded(); iveresov@2138: VM_ENTRY_MARK; coleenp@4037: nmethod* nm = get_Method()->code(); iveresov@2138: if (nm != NULL) return nm->comp_level(); iveresov@2138: return 0; iveresov@2138: } iveresov@2138: iveresov@2988: int ciMethod::highest_osr_comp_level() { iveresov@2988: check_is_loaded(); iveresov@2988: VM_ENTRY_MARK; coleenp@4037: return get_Method()->highest_osr_comp_level(); iveresov@2988: } iveresov@2988: duke@435: // ------------------------------------------------------------------ twisti@3097: // ciMethod::code_size_for_inlining twisti@3097: // twisti@3969: // Code size for inlining decisions. This method returns a code twisti@3969: // size of 1 for methods which has the ForceInline annotation. twisti@3097: int ciMethod::code_size_for_inlining() { twisti@3097: check_is_loaded(); coleenp@4037: if (get_Method()->force_inline()) { twisti@3969: return 1; twisti@3097: } twisti@3097: return code_size(); twisti@3097: } twisti@3097: twisti@3097: // ------------------------------------------------------------------ duke@435: // ciMethod::instructions_size twisti@2103: // twisti@2103: // This is a rough metric for "fat" methods, compared before inlining twisti@2103: // with InlineSmallCode. The CodeBlob::code_size accessor includes twisti@2103: // junk like exception handler, stubs, and constant table, which are twisti@2103: // not highly relevant to an inlined method. So we use the more twisti@2103: // specific accessor nmethod::insts_size. minqi@4267: int ciMethod::instructions_size() { minqi@4267: if (_instructions_size == -1) { minqi@4267: GUARDED_VM_ENTRY( minqi@4267: nmethod* code = get_Method()->code(); minqi@4267: if (code != NULL && (code->comp_level() == CompLevel_full_optimization)) { minqi@4267: _instructions_size = code->insts_end() - code->verified_entry_point(); minqi@4267: } else { minqi@4267: _instructions_size = 0; minqi@4267: } minqi@4267: ); minqi@4267: } minqi@4267: return _instructions_size; duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciMethod::log_nmethod_identity duke@435: void ciMethod::log_nmethod_identity(xmlStream* log) { duke@435: GUARDED_VM_ENTRY( coleenp@4037: nmethod* code = get_Method()->code(); duke@435: if (code != NULL) { duke@435: code->log_identity(log); duke@435: } duke@435: ) duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciMethod::is_not_reached duke@435: bool ciMethod::is_not_reached(int bci) { duke@435: check_is_loaded(); duke@435: VM_ENTRY_MARK; duke@435: return Interpreter::is_not_reached( coleenp@4037: methodHandle(THREAD, get_Method()), bci); duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciMethod::was_never_executed duke@435: bool ciMethod::was_executed_more_than(int times) { duke@435: VM_ENTRY_MARK; coleenp@4037: return get_Method()->was_executed_more_than(times); duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciMethod::has_unloaded_classes_in_signature duke@435: bool ciMethod::has_unloaded_classes_in_signature() { duke@435: VM_ENTRY_MARK; duke@435: { duke@435: EXCEPTION_MARK; coleenp@4037: methodHandle m(THREAD, get_Method()); coleenp@4037: bool has_unloaded = Method::has_unloaded_classes_in_signature(m, (JavaThread *)THREAD); duke@435: if( HAS_PENDING_EXCEPTION ) { duke@435: CLEAR_PENDING_EXCEPTION; duke@435: return true; // Declare that we may have unloaded classes duke@435: } duke@435: return has_unloaded; duke@435: } duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciMethod::is_klass_loaded duke@435: bool ciMethod::is_klass_loaded(int refinfo_index, bool must_be_resolved) const { duke@435: VM_ENTRY_MARK; coleenp@4037: return get_Method()->is_klass_loaded(refinfo_index, must_be_resolved); duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciMethod::check_call duke@435: bool ciMethod::check_call(int refinfo_index, bool is_static) const { drchase@5732: // This method is used only in C2 from InlineTree::ok_to_inline, drchase@5732: // and is only used under -Xcomp or -XX:CompileTheWorld. drchase@5732: // It appears to fail when applied to an invokeinterface call site. drchase@5732: // FIXME: Remove this method and resolve_method_statically; refactor to use the other LinkResolver entry points. duke@435: VM_ENTRY_MARK; duke@435: { duke@435: EXCEPTION_MARK; duke@435: HandleMark hm(THREAD); coleenp@4037: constantPoolHandle pool (THREAD, get_Method()->constants()); duke@435: methodHandle spec_method; duke@435: KlassHandle spec_klass; twisti@3969: Bytecodes::Code code = (is_static ? Bytecodes::_invokestatic : Bytecodes::_invokevirtual); twisti@3969: LinkResolver::resolve_method_statically(spec_method, spec_klass, code, pool, refinfo_index, THREAD); duke@435: if (HAS_PENDING_EXCEPTION) { duke@435: CLEAR_PENDING_EXCEPTION; duke@435: return false; duke@435: } else { duke@435: return (spec_method->is_static() == is_static); duke@435: } duke@435: } duke@435: return false; duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciMethod::print_codes duke@435: // duke@435: // Print the bytecodes for this method. duke@435: void ciMethod::print_codes_on(outputStream* st) { duke@435: check_is_loaded(); coleenp@4037: GUARDED_VM_ENTRY(get_Method()->print_codes_on(st);) duke@435: } duke@435: duke@435: duke@435: #define FETCH_FLAG_FROM_VM(flag_accessor) { \ duke@435: check_is_loaded(); \ duke@435: VM_ENTRY_MARK; \ coleenp@4037: return get_Method()->flag_accessor(); \ duke@435: } duke@435: duke@435: bool ciMethod::is_empty_method() const { FETCH_FLAG_FROM_VM(is_empty_method); } duke@435: bool ciMethod::is_vanilla_constructor() const { FETCH_FLAG_FROM_VM(is_vanilla_constructor); } duke@435: bool ciMethod::has_loops () const { FETCH_FLAG_FROM_VM(has_loops); } duke@435: bool ciMethod::has_jsrs () const { FETCH_FLAG_FROM_VM(has_jsrs); } duke@435: bool ciMethod::is_accessor () const { FETCH_FLAG_FROM_VM(is_accessor); } duke@435: bool ciMethod::is_initializer () const { FETCH_FLAG_FROM_VM(is_initializer); } duke@435: kvn@5110: bool ciMethod::is_boxing_method() const { kvn@5110: if (holder()->is_box_klass()) { kvn@5110: switch (intrinsic_id()) { kvn@5110: case vmIntrinsics::_Boolean_valueOf: kvn@5110: case vmIntrinsics::_Byte_valueOf: kvn@5110: case vmIntrinsics::_Character_valueOf: kvn@5110: case vmIntrinsics::_Short_valueOf: kvn@5110: case vmIntrinsics::_Integer_valueOf: kvn@5110: case vmIntrinsics::_Long_valueOf: kvn@5110: case vmIntrinsics::_Float_valueOf: kvn@5110: case vmIntrinsics::_Double_valueOf: kvn@5110: return true; kvn@5110: default: kvn@5110: return false; kvn@5110: } kvn@5110: } kvn@5110: return false; kvn@5110: } kvn@5110: kvn@5110: bool ciMethod::is_unboxing_method() const { kvn@5110: if (holder()->is_box_klass()) { kvn@5110: switch (intrinsic_id()) { kvn@5110: case vmIntrinsics::_booleanValue: kvn@5110: case vmIntrinsics::_byteValue: kvn@5110: case vmIntrinsics::_charValue: kvn@5110: case vmIntrinsics::_shortValue: kvn@5110: case vmIntrinsics::_intValue: kvn@5110: case vmIntrinsics::_longValue: kvn@5110: case vmIntrinsics::_floatValue: kvn@5110: case vmIntrinsics::_doubleValue: kvn@5110: return true; kvn@5110: default: kvn@5110: return false; kvn@5110: } kvn@5110: } kvn@5110: return false; kvn@5110: } kvn@5110: duke@435: BCEscapeAnalyzer *ciMethod::get_bcea() { kvn@2003: #ifdef COMPILER2 duke@435: if (_bcea == NULL) { duke@435: _bcea = new (CURRENT_ENV->arena()) BCEscapeAnalyzer(this, NULL); duke@435: } duke@435: return _bcea; kvn@2003: #else // COMPILER2 kvn@2003: ShouldNotReachHere(); kvn@2003: return NULL; kvn@2003: #endif // COMPILER2 duke@435: } duke@435: duke@435: ciMethodBlocks *ciMethod::get_method_blocks() { duke@435: Arena *arena = CURRENT_ENV->arena(); duke@435: if (_method_blocks == NULL) { duke@435: _method_blocks = new (arena) ciMethodBlocks(arena, this); duke@435: } duke@435: return _method_blocks; duke@435: } duke@435: duke@435: #undef FETCH_FLAG_FROM_VM duke@435: minqi@4267: void ciMethod::dump_replay_data(outputStream* st) { minqi@4267: ASSERT_IN_VM; vlivanov@4531: ResourceMark rm; minqi@4267: Method* method = get_Method(); jiangli@4936: MethodCounters* mcs = method->method_counters(); minqi@4267: Klass* holder = method->method_holder(); minqi@4267: st->print_cr("ciMethod %s %s %s %d %d %d %d %d", minqi@4267: holder->name()->as_quoted_ascii(), minqi@4267: method->name()->as_quoted_ascii(), minqi@4267: method->signature()->as_quoted_ascii(), jiangli@4936: mcs == NULL ? 0 : mcs->invocation_counter()->raw_counter(), jiangli@4936: mcs == NULL ? 0 : mcs->backedge_counter()->raw_counter(), minqi@4267: interpreter_invocation_count(), minqi@4267: interpreter_throwout_count(), minqi@4267: _instructions_size); minqi@4267: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciMethod::print_codes duke@435: // duke@435: // Print a range of the bytecodes for this method. duke@435: void ciMethod::print_codes_on(int from, int to, outputStream* st) { duke@435: check_is_loaded(); coleenp@4037: GUARDED_VM_ENTRY(get_Method()->print_codes_on(from, to, st);) duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciMethod::print_name duke@435: // duke@435: // Print the name of this method, including signature and some flags. duke@435: void ciMethod::print_name(outputStream* st) { duke@435: check_is_loaded(); coleenp@4037: GUARDED_VM_ENTRY(get_Method()->print_name(st);) duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciMethod::print_short_name duke@435: // duke@435: // Print the name of this method, without signature. duke@435: void ciMethod::print_short_name(outputStream* st) { twisti@3969: if (is_loaded()) { coleenp@4037: GUARDED_VM_ENTRY(get_Method()->print_short_name(st);); twisti@3969: } else { twisti@3969: // Fall back if method is not loaded. twisti@3969: holder()->print_name_on(st); twisti@3969: st->print("::"); twisti@3969: name()->print_symbol_on(st); twisti@3969: if (WizardMode) twisti@3969: signature()->as_symbol()->print_symbol_on(st); twisti@3969: } duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciMethod::print_impl duke@435: // duke@435: // Implementation of the print method. duke@435: void ciMethod::print_impl(outputStream* st) { coleenp@4037: ciMetadata::print_impl(st); duke@435: st->print(" name="); duke@435: name()->print_symbol_on(st); duke@435: st->print(" holder="); duke@435: holder()->print_name_on(st); duke@435: st->print(" signature="); duke@435: signature()->as_symbol()->print_symbol_on(st); duke@435: if (is_loaded()) { twisti@4021: st->print(" loaded=true"); twisti@4021: st->print(" arg_size=%d", arg_size()); twisti@4021: st->print(" flags="); duke@435: flags().print_member_flags(st); duke@435: } else { duke@435: st->print(" loaded=false"); duke@435: } duke@435: }