Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/ci/ciMethod.cpp
32285 views
/*1* Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "ci/ciCallProfile.hpp"26#include "ci/ciExceptionHandler.hpp"27#include "ci/ciInstanceKlass.hpp"28#include "ci/ciMethod.hpp"29#include "ci/ciMethodBlocks.hpp"30#include "ci/ciMethodData.hpp"31#include "ci/ciStreams.hpp"32#include "ci/ciSymbol.hpp"33#include "ci/ciReplay.hpp"34#include "ci/ciUtilities.hpp"35#include "classfile/systemDictionary.hpp"36#include "compiler/abstractCompiler.hpp"37#include "compiler/compilerOracle.hpp"38#include "compiler/methodLiveness.hpp"39#include "interpreter/interpreter.hpp"40#include "interpreter/linkResolver.hpp"41#include "interpreter/oopMapCache.hpp"42#include "memory/allocation.inline.hpp"43#include "memory/resourceArea.hpp"44#include "oops/generateOopMap.hpp"45#include "oops/oop.inline.hpp"46#include "prims/nativeLookup.hpp"47#include "runtime/deoptimization.hpp"48#include "utilities/bitMap.inline.hpp"49#include "utilities/xmlstream.hpp"50#ifdef COMPILER251#include "ci/bcEscapeAnalyzer.hpp"52#include "ci/ciTypeFlow.hpp"53#include "oops/method.hpp"54#endif55#ifdef SHARK56#include "ci/ciTypeFlow.hpp"57#include "oops/method.hpp"58#endif5960// ciMethod61//62// This class represents a Method* in the HotSpot virtual63// machine.646566// ------------------------------------------------------------------67// ciMethod::ciMethod68//69// Loaded method.70ciMethod::ciMethod(methodHandle h_m, ciInstanceKlass* holder) :71ciMetadata(h_m()),72_holder(holder)73{74assert(h_m() != NULL, "no null method");7576// These fields are always filled in in loaded methods.77_flags = ciFlags(h_m()->access_flags());7879// Easy to compute, so fill them in now.80_max_stack = h_m()->max_stack();81_max_locals = h_m()->max_locals();82_code_size = h_m()->code_size();83_intrinsic_id = h_m()->intrinsic_id();84_handler_count = h_m()->exception_table_length();85_size_of_parameters = h_m()->size_of_parameters();86_uses_monitors = h_m()->access_flags().has_monitor_bytecodes();87_balanced_monitors = !_uses_monitors || h_m()->access_flags().is_monitor_matching();88_is_c1_compilable = !h_m()->is_not_c1_compilable();89_is_c2_compilable = !h_m()->is_not_c2_compilable();90// Lazy fields, filled in on demand. Require allocation.91_code = NULL;92_exception_handlers = NULL;93_liveness = NULL;94_method_blocks = NULL;95#if defined(COMPILER2) || defined(SHARK)96_flow = NULL;97_bcea = NULL;98#endif // COMPILER2 || SHARK99100ciEnv *env = CURRENT_ENV;101if (env->jvmti_can_hotswap_or_post_breakpoint() && can_be_compiled()) {102// 6328518 check hotswap conditions under the right lock.103MutexLocker locker(Compile_lock);104if (Dependencies::check_evol_method(h_m()) != NULL) {105_is_c1_compilable = false;106_is_c2_compilable = false;107}108} else {109CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());110}111112if (h_m()->method_holder()->is_linked()) {113_can_be_statically_bound = h_m()->can_be_statically_bound();114} else {115// Have to use a conservative value in this case.116_can_be_statically_bound = false;117}118119// Adjust the definition of this condition to be more useful:120// %%% take these conditions into account in vtable generation121if (!_can_be_statically_bound && h_m()->is_private())122_can_be_statically_bound = true;123if (_can_be_statically_bound && h_m()->is_abstract())124_can_be_statically_bound = false;125126// generating _signature may allow GC and therefore move m.127// These fields are always filled in.128_name = env->get_symbol(h_m()->name());129ciSymbol* sig_symbol = env->get_symbol(h_m()->signature());130constantPoolHandle cpool = h_m()->constants();131_signature = new (env->arena()) ciSignature(_holder, cpool, sig_symbol);132_method_data = NULL;133// Take a snapshot of these values, so they will be commensurate with the MDO.134if (ProfileInterpreter || TieredCompilation) {135int invcnt = h_m()->interpreter_invocation_count();136// if the value overflowed report it as max int137_interpreter_invocation_count = invcnt < 0 ? max_jint : invcnt ;138_interpreter_throwout_count = h_m()->interpreter_throwout_count();139} else {140_interpreter_invocation_count = 0;141_interpreter_throwout_count = 0;142}143if (_interpreter_invocation_count == 0)144_interpreter_invocation_count = 1;145_instructions_size = -1;146#ifdef ASSERT147if (ReplayCompiles) {148ciReplay::initialize(this);149}150#endif151}152153154// ------------------------------------------------------------------155// ciMethod::ciMethod156//157// Unloaded method.158ciMethod::ciMethod(ciInstanceKlass* holder,159ciSymbol* name,160ciSymbol* signature,161ciInstanceKlass* accessor) :162ciMetadata((Metadata*)NULL),163_name( name),164_holder( holder),165_intrinsic_id( vmIntrinsics::_none),166_liveness( NULL),167_can_be_statically_bound(false),168_method_blocks( NULL),169_method_data( NULL)170#if defined(COMPILER2) || defined(SHARK)171,172_flow( NULL),173_bcea( NULL),174_instructions_size(-1)175#endif // COMPILER2 || SHARK176{177// Usually holder and accessor are the same type but in some cases178// the holder has the wrong class loader (e.g. invokedynamic call179// sites) so we pass the accessor.180_signature = new (CURRENT_ENV->arena()) ciSignature(accessor, constantPoolHandle(), signature);181}182183184// ------------------------------------------------------------------185// ciMethod::load_code186//187// Load the bytecodes and exception handler table for this method.188void ciMethod::load_code() {189VM_ENTRY_MARK;190assert(is_loaded(), "only loaded methods have code");191192Method* me = get_Method();193Arena* arena = CURRENT_THREAD_ENV->arena();194195// Load the bytecodes.196_code = (address)arena->Amalloc(code_size());197memcpy(_code, me->code_base(), code_size());198199// Revert any breakpoint bytecodes in ci's copy200if (me->number_of_breakpoints() > 0) {201BreakpointInfo* bp = me->method_holder()->breakpoints();202for (; bp != NULL; bp = bp->next()) {203if (bp->match(me)) {204code_at_put(bp->bci(), bp->orig_bytecode());205}206}207}208209// And load the exception table.210ExceptionTable exc_table(me);211212// Allocate one extra spot in our list of exceptions. This213// last entry will be used to represent the possibility that214// an exception escapes the method. See ciExceptionHandlerStream215// for details.216_exception_handlers =217(ciExceptionHandler**)arena->Amalloc(sizeof(ciExceptionHandler*)218* (_handler_count + 1));219if (_handler_count > 0) {220for (int i=0; i<_handler_count; i++) {221_exception_handlers[i] = new (arena) ciExceptionHandler(222holder(),223/* start */ exc_table.start_pc(i),224/* limit */ exc_table.end_pc(i),225/* goto pc */ exc_table.handler_pc(i),226/* cp index */ exc_table.catch_type_index(i));227}228}229230// Put an entry at the end of our list to represent the possibility231// of exceptional exit.232_exception_handlers[_handler_count] =233new (arena) ciExceptionHandler(holder(), 0, code_size(), -1, 0);234235if (CIPrintMethodCodes) {236print_codes();237}238}239240241// ------------------------------------------------------------------242// ciMethod::has_linenumber_table243//244// length unknown until decompression245bool ciMethod::has_linenumber_table() const {246check_is_loaded();247VM_ENTRY_MARK;248return get_Method()->has_linenumber_table();249}250251252// ------------------------------------------------------------------253// ciMethod::compressed_linenumber_table254u_char* ciMethod::compressed_linenumber_table() const {255check_is_loaded();256VM_ENTRY_MARK;257return get_Method()->compressed_linenumber_table();258}259260261// ------------------------------------------------------------------262// ciMethod::line_number_from_bci263int ciMethod::line_number_from_bci(int bci) const {264check_is_loaded();265VM_ENTRY_MARK;266return get_Method()->line_number_from_bci(bci);267}268269270// ------------------------------------------------------------------271// ciMethod::vtable_index272//273// Get the position of this method's entry in the vtable, if any.274int ciMethod::vtable_index() {275check_is_loaded();276assert(holder()->is_linked(), "must be linked");277VM_ENTRY_MARK;278return get_Method()->vtable_index();279}280281282#ifdef SHARK283// ------------------------------------------------------------------284// ciMethod::itable_index285//286// Get the position of this method's entry in the itable, if any.287int ciMethod::itable_index() {288check_is_loaded();289assert(holder()->is_linked(), "must be linked");290VM_ENTRY_MARK;291Method* m = get_Method();292if (!m->has_itable_index())293return Method::nonvirtual_vtable_index;294return m->itable_index();295}296#endif // SHARK297298299// ------------------------------------------------------------------300// ciMethod::native_entry301//302// Get the address of this method's native code, if any.303address ciMethod::native_entry() {304check_is_loaded();305assert(flags().is_native(), "must be native method");306VM_ENTRY_MARK;307Method* method = get_Method();308address entry = method->native_function();309assert(entry != NULL, "must be valid entry point");310return entry;311}312313314// ------------------------------------------------------------------315// ciMethod::interpreter_entry316//317// Get the entry point for running this method in the interpreter.318address ciMethod::interpreter_entry() {319check_is_loaded();320VM_ENTRY_MARK;321methodHandle mh(THREAD, get_Method());322return Interpreter::entry_for_method(mh);323}324325326// ------------------------------------------------------------------327// ciMethod::uses_balanced_monitors328//329// Does this method use monitors in a strict stack-disciplined manner?330bool ciMethod::has_balanced_monitors() {331check_is_loaded();332if (_balanced_monitors) return true;333334// Analyze the method to see if monitors are used properly.335VM_ENTRY_MARK;336methodHandle method(THREAD, get_Method());337assert(method->has_monitor_bytecodes(), "should have checked this");338339// Check to see if a previous compilation computed the340// monitor-matching analysis.341if (method->guaranteed_monitor_matching()) {342_balanced_monitors = true;343return true;344}345346{347EXCEPTION_MARK;348ResourceMark rm(THREAD);349GeneratePairingInfo gpi(method);350gpi.compute_map(CATCH);351if (!gpi.monitor_safe()) {352return false;353}354method->set_guaranteed_monitor_matching();355_balanced_monitors = true;356}357return true;358}359360361// ------------------------------------------------------------------362// ciMethod::get_flow_analysis363ciTypeFlow* ciMethod::get_flow_analysis() {364#if defined(COMPILER2) || defined(SHARK)365if (_flow == NULL) {366ciEnv* env = CURRENT_ENV;367_flow = new (env->arena()) ciTypeFlow(env, this);368_flow->do_flow();369}370return _flow;371#else // COMPILER2 || SHARK372ShouldNotReachHere();373return NULL;374#endif // COMPILER2 || SHARK375}376377378// ------------------------------------------------------------------379// ciMethod::get_osr_flow_analysis380ciTypeFlow* ciMethod::get_osr_flow_analysis(int osr_bci) {381#if defined(COMPILER2) || defined(SHARK)382// OSR entry points are always place after a call bytecode of some sort383assert(osr_bci >= 0, "must supply valid OSR entry point");384ciEnv* env = CURRENT_ENV;385ciTypeFlow* flow = new (env->arena()) ciTypeFlow(env, this, osr_bci);386flow->do_flow();387return flow;388#else // COMPILER2 || SHARK389ShouldNotReachHere();390return NULL;391#endif // COMPILER2 || SHARK392}393394// ------------------------------------------------------------------395// ciMethod::raw_liveness_at_bci396//397// Which local variables are live at a specific bci?398MethodLivenessResult ciMethod::raw_liveness_at_bci(int bci) {399check_is_loaded();400if (_liveness == NULL) {401// Create the liveness analyzer.402Arena* arena = CURRENT_ENV->arena();403_liveness = new (arena) MethodLiveness(arena, this);404_liveness->compute_liveness();405}406return _liveness->get_liveness_at(bci);407}408409// ------------------------------------------------------------------410// ciMethod::liveness_at_bci411//412// Which local variables are live at a specific bci? When debugging413// will return true for all locals in some cases to improve debug414// information.415MethodLivenessResult ciMethod::liveness_at_bci(int bci) {416MethodLivenessResult result = raw_liveness_at_bci(bci);417if (CURRENT_ENV->should_retain_local_variables() || DeoptimizeALot || CompileTheWorld) {418// Keep all locals live for the user's edification and amusement.419result.at_put_range(0, result.size(), true);420}421return result;422}423424// ciMethod::live_local_oops_at_bci425//426// find all the live oops in the locals array for a particular bci427// Compute what the interpreter believes by using the interpreter428// oopmap generator. This is used as a double check during osr to429// guard against conservative result from MethodLiveness making us430// think a dead oop is live. MethodLiveness is conservative in the431// sense that it may consider locals to be live which cannot be live,432// like in the case where a local could contain an oop or a primitive433// along different paths. In that case the local must be dead when434// those paths merge. Since the interpreter's viewpoint is used when435// gc'ing an interpreter frame we need to use its viewpoint during436// OSR when loading the locals.437438BitMap ciMethod::live_local_oops_at_bci(int bci) {439VM_ENTRY_MARK;440InterpreterOopMap mask;441OopMapCache::compute_one_oop_map(get_Method(), bci, &mask);442int mask_size = max_locals();443BitMap result(mask_size);444result.clear();445int i;446for (i = 0; i < mask_size ; i++ ) {447if (mask.is_oop(i)) result.set_bit(i);448}449return result;450}451452453#ifdef COMPILER1454// ------------------------------------------------------------------455// ciMethod::bci_block_start456//457// Marks all bcis where a new basic block starts458const BitMap ciMethod::bci_block_start() {459check_is_loaded();460if (_liveness == NULL) {461// Create the liveness analyzer.462Arena* arena = CURRENT_ENV->arena();463_liveness = new (arena) MethodLiveness(arena, this);464_liveness->compute_liveness();465}466467return _liveness->get_bci_block_start();468}469#endif // COMPILER1470471472// ------------------------------------------------------------------473// ciMethod::call_profile_at_bci474//475// Get the ciCallProfile for the invocation of this method.476// Also reports receiver types for non-call type checks (if TypeProfileCasts).477ciCallProfile ciMethod::call_profile_at_bci(int bci) {478ResourceMark rm;479ciCallProfile result;480if (method_data() != NULL && method_data()->is_mature()) {481ciProfileData* data = method_data()->bci_to_data(bci);482if (data != NULL && data->is_CounterData()) {483// Every profiled call site has a counter.484int count = data->as_CounterData()->count();485486if (!data->is_ReceiverTypeData()) {487result._receiver_count[0] = 0; // that's a definite zero488} else { // ReceiverTypeData is a subclass of CounterData489ciReceiverTypeData* call = (ciReceiverTypeData*)data->as_ReceiverTypeData();490// In addition, virtual call sites have receiver type information491int receivers_count_total = 0;492int morphism = 0;493// Precompute morphism for the possible fixup494for (uint i = 0; i < call->row_limit(); i++) {495ciKlass* receiver = call->receiver(i);496if (receiver == NULL) continue;497morphism++;498}499int epsilon = 0;500if (TieredCompilation && ProfileInterpreter) {501// Interpreter and C1 treat final and special invokes differently.502// C1 will record a type, whereas the interpreter will just503// increment the count. Detect this case.504if (morphism == 1 && count > 0) {505epsilon = count;506count = 0;507}508}509for (uint i = 0; i < call->row_limit(); i++) {510ciKlass* receiver = call->receiver(i);511if (receiver == NULL) continue;512int rcount = call->receiver_count(i) + epsilon;513if (rcount == 0) rcount = 1; // Should be valid value514receivers_count_total += rcount;515// Add the receiver to result data.516result.add_receiver(receiver, rcount);517// If we extend profiling to record methods,518// we will set result._method also.519}520// Determine call site's morphism.521// The call site count is 0 with known morphism (onlt 1 or 2 receivers)522// or < 0 in the case of a type check failured for checkcast, aastore, instanceof.523// The call site count is > 0 in the case of a polymorphic virtual call.524if (morphism > 0 && morphism == result._limit) {525// The morphism <= MorphismLimit.526if ((morphism < ciCallProfile::MorphismLimit) ||527(morphism == ciCallProfile::MorphismLimit && count == 0)) {528#ifdef ASSERT529if (count > 0) {530this->print_short_name(tty);531tty->print_cr(" @ bci:%d", bci);532this->print_codes();533assert(false, "this call site should not be polymorphic");534}535#endif536result._morphism = morphism;537}538}539// Make the count consistent if this is a call profile. If count is540// zero or less, presume that this is a typecheck profile and541// do nothing. Otherwise, increase count to be the sum of all542// receiver's counts.543if (count >= 0) {544count += receivers_count_total;545}546}547result._count = count;548}549}550return result;551}552553// ------------------------------------------------------------------554// Add new receiver and sort data by receiver's profile count.555void ciCallProfile::add_receiver(ciKlass* receiver, int receiver_count) {556// Add new receiver and sort data by receiver's counts when we have space557// for it otherwise replace the less called receiver (less called receiver558// is placed to the last array element which is not used).559// First array's element contains most called receiver.560int i = _limit;561for (; i > 0 && receiver_count > _receiver_count[i-1]; i--) {562_receiver[i] = _receiver[i-1];563_receiver_count[i] = _receiver_count[i-1];564}565_receiver[i] = receiver;566_receiver_count[i] = receiver_count;567if (_limit < MorphismLimit) _limit++;568}569570571void ciMethod::assert_virtual_call_type_ok(int bci) {572assert(java_code_at_bci(bci) == Bytecodes::_invokevirtual ||573java_code_at_bci(bci) == Bytecodes::_invokeinterface, err_msg("unexpected bytecode %s", Bytecodes::name(java_code_at_bci(bci))));574}575576void ciMethod::assert_call_type_ok(int bci) {577assert(java_code_at_bci(bci) == Bytecodes::_invokestatic ||578java_code_at_bci(bci) == Bytecodes::_invokespecial ||579java_code_at_bci(bci) == Bytecodes::_invokedynamic, err_msg("unexpected bytecode %s", Bytecodes::name(java_code_at_bci(bci))));580}581582/**583* Check whether profiling provides a type for the argument i to the584* call at bci bci585*586* @param bci bci of the call587* @param i argument number588* @return profiled type589*590* If the profile reports that the argument may be null, return false591* at least for now.592*/593ciKlass* ciMethod::argument_profiled_type(int bci, int i) {594if (MethodData::profile_parameters() && method_data() != NULL && method_data()->is_mature()) {595ciProfileData* data = method_data()->bci_to_data(bci);596if (data != NULL) {597if (data->is_VirtualCallTypeData()) {598assert_virtual_call_type_ok(bci);599ciVirtualCallTypeData* call = (ciVirtualCallTypeData*)data->as_VirtualCallTypeData();600if (i >= call->number_of_arguments()) {601return NULL;602}603ciKlass* type = call->valid_argument_type(i);604if (type != NULL && !call->argument_maybe_null(i)) {605return type;606}607} else if (data->is_CallTypeData()) {608assert_call_type_ok(bci);609ciCallTypeData* call = (ciCallTypeData*)data->as_CallTypeData();610if (i >= call->number_of_arguments()) {611return NULL;612}613ciKlass* type = call->valid_argument_type(i);614if (type != NULL && !call->argument_maybe_null(i)) {615return type;616}617}618}619}620return NULL;621}622623/**624* Check whether profiling provides a type for the return value from625* the call at bci bci626*627* @param bci bci of the call628* @return profiled type629*630* If the profile reports that the argument may be null, return false631* at least for now.632*/633ciKlass* ciMethod::return_profiled_type(int bci) {634if (MethodData::profile_return() && method_data() != NULL && method_data()->is_mature()) {635ciProfileData* data = method_data()->bci_to_data(bci);636if (data != NULL) {637if (data->is_VirtualCallTypeData()) {638assert_virtual_call_type_ok(bci);639ciVirtualCallTypeData* call = (ciVirtualCallTypeData*)data->as_VirtualCallTypeData();640ciKlass* type = call->valid_return_type();641if (type != NULL && !call->return_maybe_null()) {642return type;643}644} else if (data->is_CallTypeData()) {645assert_call_type_ok(bci);646ciCallTypeData* call = (ciCallTypeData*)data->as_CallTypeData();647ciKlass* type = call->valid_return_type();648if (type != NULL && !call->return_maybe_null()) {649return type;650}651}652}653}654return NULL;655}656657/**658* Check whether profiling provides a type for the parameter i659*660* @param i parameter number661* @return profiled type662*663* If the profile reports that the argument may be null, return false664* at least for now.665*/666ciKlass* ciMethod::parameter_profiled_type(int i) {667if (MethodData::profile_parameters() && method_data() != NULL && method_data()->is_mature()) {668ciParametersTypeData* parameters = method_data()->parameters_type_data();669if (parameters != NULL && i < parameters->number_of_parameters()) {670ciKlass* type = parameters->valid_parameter_type(i);671if (type != NULL && !parameters->parameter_maybe_null(i)) {672return type;673}674}675}676return NULL;677}678679680// ------------------------------------------------------------------681// ciMethod::find_monomorphic_target682//683// Given a certain calling environment, find the monomorphic target684// for the call. Return NULL if the call is not monomorphic in685// its calling environment, or if there are only abstract methods.686// The returned method is never abstract.687// Note: If caller uses a non-null result, it must inform dependencies688// via assert_unique_concrete_method or assert_leaf_type.689ciMethod* ciMethod::find_monomorphic_target(ciInstanceKlass* caller,690ciInstanceKlass* callee_holder,691ciInstanceKlass* actual_recv,692bool check_access) {693check_is_loaded();694695if (actual_recv->is_interface()) {696// %%% We cannot trust interface types, yet. See bug 6312651.697return NULL;698}699700ciMethod* root_m = resolve_invoke(caller, actual_recv, check_access);701if (root_m == NULL) {702// Something went wrong looking up the actual receiver method.703return NULL;704}705assert(!root_m->is_abstract(), "resolve_invoke promise");706707// Make certain quick checks even if UseCHA is false.708709// Is it private or final?710if (root_m->can_be_statically_bound()) {711return root_m;712}713714if (actual_recv->is_leaf_type() && actual_recv == root_m->holder()) {715// Easy case. There is no other place to put a method, so don't bother716// to go through the VM_ENTRY_MARK and all the rest.717return root_m;718}719720// Array methods (clone, hashCode, etc.) are always statically bound.721// If we were to see an array type here, we'd return root_m.722// However, this method processes only ciInstanceKlasses. (See 4962591.)723// The inline_native_clone intrinsic narrows Object to T[] properly,724// so there is no need to do the same job here.725726if (!UseCHA) return NULL;727728VM_ENTRY_MARK;729730// Disable CHA for default methods for now731if (root_m->get_Method()->is_default_method()) {732return NULL;733}734735methodHandle target;736{737MutexLocker locker(Compile_lock);738Klass* context = actual_recv->get_Klass();739target = Dependencies::find_unique_concrete_method(context,740root_m->get_Method());741// %%% Should upgrade this ciMethod API to look for 1 or 2 concrete methods.742}743744#ifndef PRODUCT745if (TraceDependencies && target() != NULL && target() != root_m->get_Method()) {746tty->print("found a non-root unique target method");747tty->print_cr(" context = %s", InstanceKlass::cast(actual_recv->get_Klass())->external_name());748tty->print(" method = ");749target->print_short_name(tty);750tty->cr();751}752#endif //PRODUCT753754if (target() == NULL) {755return NULL;756}757if (target() == root_m->get_Method()) {758return root_m;759}760if (!root_m->is_public() &&761!root_m->is_protected()) {762// If we are going to reason about inheritance, it's easiest763// if the method in question is public, protected, or private.764// If the answer is not root_m, it is conservatively correct765// to return NULL, even if the CHA encountered irrelevant766// methods in other packages.767// %%% TO DO: Work out logic for package-private methods768// with the same name but different vtable indexes.769return NULL;770}771return CURRENT_THREAD_ENV->get_method(target());772}773774// ------------------------------------------------------------------775// ciMethod::resolve_invoke776//777// Given a known receiver klass, find the target for the call.778// Return NULL if the call has no target or the target is abstract.779ciMethod* ciMethod::resolve_invoke(ciKlass* caller, ciKlass* exact_receiver, bool check_access) {780check_is_loaded();781VM_ENTRY_MARK;782783KlassHandle caller_klass (THREAD, caller->get_Klass());784KlassHandle h_recv (THREAD, exact_receiver->get_Klass());785KlassHandle h_resolved (THREAD, holder()->get_Klass());786Symbol* h_name = name()->get_symbol();787Symbol* h_signature = signature()->get_symbol();788789methodHandle m;790// Only do exact lookup if receiver klass has been linked. Otherwise,791// the vtable has not been setup, and the LinkResolver will fail.792if (h_recv->oop_is_array()793||794InstanceKlass::cast(h_recv())->is_linked() && !exact_receiver->is_interface()) {795if (holder()->is_interface()) {796m = LinkResolver::resolve_interface_call_or_null(h_recv, h_resolved, h_name, h_signature, caller_klass, check_access);797} else {798m = LinkResolver::resolve_virtual_call_or_null(h_recv, h_resolved, h_name, h_signature, caller_klass, check_access);799}800}801802if (m.is_null()) {803// Return NULL only if there was a problem with lookup (uninitialized class, etc.)804return NULL;805}806807ciMethod* result = this;808if (m() != get_Method()) {809result = CURRENT_THREAD_ENV->get_method(m());810}811812// Don't return abstract methods because they aren't813// optimizable or interesting.814if (result->is_abstract()) {815return NULL;816} else {817return result;818}819}820821// ------------------------------------------------------------------822// ciMethod::resolve_vtable_index823//824// Given a known receiver klass, find the vtable index for the call.825// Return Method::invalid_vtable_index if the vtable_index is unknown.826int ciMethod::resolve_vtable_index(ciKlass* caller, ciKlass* receiver) {827check_is_loaded();828829int vtable_index = Method::invalid_vtable_index;830// Only do lookup if receiver klass has been linked. Otherwise,831// the vtable has not been setup, and the LinkResolver will fail.832if (!receiver->is_interface()833&& (!receiver->is_instance_klass() ||834receiver->as_instance_klass()->is_linked())) {835VM_ENTRY_MARK;836837KlassHandle caller_klass (THREAD, caller->get_Klass());838KlassHandle h_recv (THREAD, receiver->get_Klass());839Symbol* h_name = name()->get_symbol();840Symbol* h_signature = signature()->get_symbol();841842vtable_index = LinkResolver::resolve_virtual_vtable_index(h_recv, h_recv, h_name, h_signature, caller_klass);843if (vtable_index == Method::nonvirtual_vtable_index) {844// A statically bound method. Return "no such index".845vtable_index = Method::invalid_vtable_index;846}847}848849return vtable_index;850}851852// ------------------------------------------------------------------853// ciMethod::interpreter_call_site_count854int ciMethod::interpreter_call_site_count(int bci) {855if (method_data() != NULL) {856ResourceMark rm;857ciProfileData* data = method_data()->bci_to_data(bci);858if (data != NULL && data->is_CounterData()) {859return scale_count(data->as_CounterData()->count());860}861}862return -1; // unknown863}864865// ------------------------------------------------------------------866// ciMethod::get_field_at_bci867ciField* ciMethod::get_field_at_bci(int bci, bool &will_link) {868ciBytecodeStream iter(this);869iter.reset_to_bci(bci);870iter.next();871return iter.get_field(will_link);872}873874// ------------------------------------------------------------------875// ciMethod::get_method_at_bci876ciMethod* ciMethod::get_method_at_bci(int bci, bool &will_link, ciSignature* *declared_signature) {877ciBytecodeStream iter(this);878iter.reset_to_bci(bci);879iter.next();880return iter.get_method(will_link, declared_signature);881}882883// ------------------------------------------------------------------884// Adjust a CounterData count to be commensurate with885// interpreter_invocation_count. If the MDO exists for886// only 25% of the time the method exists, then the887// counts in the MDO should be scaled by 4X, so that888// they can be usefully and stably compared against the889// invocation counts in methods.890int ciMethod::scale_count(int count, float prof_factor) {891if (count > 0 && method_data() != NULL) {892int counter_life;893int method_life = interpreter_invocation_count();894if (TieredCompilation) {895// In tiered the MDO's life is measured directly, so just use the snapshotted counters896counter_life = MAX2(method_data()->invocation_count(), method_data()->backedge_count());897} else {898int current_mileage = method_data()->current_mileage();899int creation_mileage = method_data()->creation_mileage();900counter_life = current_mileage - creation_mileage;901}902903// counter_life due to backedge_counter could be > method_life904if (counter_life > method_life)905counter_life = method_life;906if (0 < counter_life && counter_life <= method_life) {907count = (int)((double)count * prof_factor * method_life / counter_life + 0.5);908count = (count > 0) ? count : 1;909}910}911return count;912}913914915// ------------------------------------------------------------------916// ciMethod::is_special_get_caller_class_method917//918bool ciMethod::is_ignored_by_security_stack_walk() const {919check_is_loaded();920VM_ENTRY_MARK;921return get_Method()->is_ignored_by_security_stack_walk();922}923924925// ------------------------------------------------------------------926// invokedynamic support927928// ------------------------------------------------------------------929// ciMethod::is_method_handle_intrinsic930//931// Return true if the method is an instance of the JVM-generated932// signature-polymorphic MethodHandle methods, _invokeBasic, _linkToVirtual, etc.933bool ciMethod::is_method_handle_intrinsic() const {934vmIntrinsics::ID iid = _intrinsic_id; // do not check if loaded935return (MethodHandles::is_signature_polymorphic(iid) &&936MethodHandles::is_signature_polymorphic_intrinsic(iid));937}938939// ------------------------------------------------------------------940// ciMethod::is_compiled_lambda_form941//942// Return true if the method is a generated MethodHandle adapter.943// These are built by Java code.944bool ciMethod::is_compiled_lambda_form() const {945vmIntrinsics::ID iid = _intrinsic_id; // do not check if loaded946return iid == vmIntrinsics::_compiledLambdaForm;947}948949// ------------------------------------------------------------------950// ciMethod::is_object_initializer951//952bool ciMethod::is_object_initializer() const {953return name() == ciSymbol::object_initializer_name();954}955956// ------------------------------------------------------------------957// ciMethod::has_member_arg958//959// Return true if the method is a linker intrinsic like _linkToVirtual.960// These are built by the JVM.961bool ciMethod::has_member_arg() const {962vmIntrinsics::ID iid = _intrinsic_id; // do not check if loaded963return (MethodHandles::is_signature_polymorphic(iid) &&964MethodHandles::has_member_arg(iid));965}966967// ------------------------------------------------------------------968// ciMethod::ensure_method_data969//970// Generate new MethodData* objects at compile time.971// Return true if allocation was successful or no MDO is required.972bool ciMethod::ensure_method_data(methodHandle h_m) {973EXCEPTION_CONTEXT;974if (is_native() || is_abstract() || h_m()->is_accessor()) {975return true;976}977if (h_m()->method_data() == NULL) {978Method::build_interpreter_method_data(h_m, THREAD);979if (HAS_PENDING_EXCEPTION) {980CLEAR_PENDING_EXCEPTION;981}982}983if (h_m()->method_data() != NULL) {984_method_data = CURRENT_ENV->get_method_data(h_m()->method_data());985_method_data->load_data();986return true;987} else {988_method_data = CURRENT_ENV->get_empty_methodData();989return false;990}991}992993// public, retroactive version994bool ciMethod::ensure_method_data() {995bool result = true;996if (_method_data == NULL || _method_data->is_empty()) {997GUARDED_VM_ENTRY({998result = ensure_method_data(get_Method());999});1000}1001return result;1002}100310041005// ------------------------------------------------------------------1006// ciMethod::method_data1007//1008ciMethodData* ciMethod::method_data() {1009if (_method_data != NULL) {1010return _method_data;1011}1012VM_ENTRY_MARK;1013ciEnv* env = CURRENT_ENV;1014Thread* my_thread = JavaThread::current();1015methodHandle h_m(my_thread, get_Method());10161017if (h_m()->method_data() != NULL) {1018_method_data = CURRENT_ENV->get_method_data(h_m()->method_data());1019_method_data->load_data();1020} else {1021_method_data = CURRENT_ENV->get_empty_methodData();1022}1023return _method_data;10241025}10261027// ------------------------------------------------------------------1028// ciMethod::method_data_or_null1029// Returns a pointer to ciMethodData if MDO exists on the VM side,1030// NULL otherwise.1031ciMethodData* ciMethod::method_data_or_null() {1032ciMethodData *md = method_data();1033if (md->is_empty()) {1034return NULL;1035}1036return md;1037}10381039// ------------------------------------------------------------------1040// ciMethod::ensure_method_counters1041//1042MethodCounters* ciMethod::ensure_method_counters() {1043check_is_loaded();1044VM_ENTRY_MARK;1045methodHandle mh(THREAD, get_Method());1046MethodCounters* method_counters = mh->get_method_counters(CHECK_NULL);1047return method_counters;1048}10491050// ------------------------------------------------------------------1051// ciMethod::should_exclude1052//1053// Should this method be excluded from compilation?1054bool ciMethod::should_exclude() {1055check_is_loaded();1056VM_ENTRY_MARK;1057methodHandle mh(THREAD, get_Method());1058bool ignore;1059return CompilerOracle::should_exclude(mh, ignore);1060}10611062// ------------------------------------------------------------------1063// ciMethod::should_inline1064//1065// Should this method be inlined during compilation?1066bool ciMethod::should_inline() {1067check_is_loaded();1068VM_ENTRY_MARK;1069methodHandle mh(THREAD, get_Method());1070return CompilerOracle::should_inline(mh);1071}10721073// ------------------------------------------------------------------1074// ciMethod::should_not_inline1075//1076// Should this method be disallowed from inlining during compilation?1077bool ciMethod::should_not_inline() {1078check_is_loaded();1079VM_ENTRY_MARK;1080methodHandle mh(THREAD, get_Method());1081return CompilerOracle::should_not_inline(mh);1082}10831084// ------------------------------------------------------------------1085// ciMethod::should_print_assembly1086//1087// Should the compiler print the generated code for this method?1088bool ciMethod::should_print_assembly() {1089check_is_loaded();1090VM_ENTRY_MARK;1091methodHandle mh(THREAD, get_Method());1092return CompilerOracle::should_print(mh);1093}10941095// ------------------------------------------------------------------1096// ciMethod::break_at_execute1097//1098// Should the compiler insert a breakpoint into the generated code1099// method?1100bool ciMethod::break_at_execute() {1101check_is_loaded();1102VM_ENTRY_MARK;1103methodHandle mh(THREAD, get_Method());1104return CompilerOracle::should_break_at(mh);1105}11061107// ------------------------------------------------------------------1108// ciMethod::has_option1109//1110bool ciMethod::has_option(const char* option) {1111check_is_loaded();1112VM_ENTRY_MARK;1113methodHandle mh(THREAD, get_Method());1114return CompilerOracle::has_option_string(mh, option);1115}11161117// ------------------------------------------------------------------1118// ciMethod::has_option_value1119//1120template<typename T>1121bool ciMethod::has_option_value(const char* option, T& value) {1122check_is_loaded();1123VM_ENTRY_MARK;1124methodHandle mh(THREAD, get_Method());1125return CompilerOracle::has_option_value(mh, option, value);1126}1127// Explicit instantiation for all OptionTypes supported.1128template bool ciMethod::has_option_value<intx>(const char* option, intx& value);1129template bool ciMethod::has_option_value<uintx>(const char* option, uintx& value);1130template bool ciMethod::has_option_value<bool>(const char* option, bool& value);1131template bool ciMethod::has_option_value<ccstr>(const char* option, ccstr& value);11321133// ------------------------------------------------------------------1134// ciMethod::can_be_compiled1135//1136// Have previous compilations of this method succeeded?1137bool ciMethod::can_be_compiled() {1138check_is_loaded();1139ciEnv* env = CURRENT_ENV;1140if (is_c1_compile(env->comp_level())) {1141return _is_c1_compilable;1142}1143return _is_c2_compilable;1144}11451146// ------------------------------------------------------------------1147// ciMethod::set_not_compilable1148//1149// Tell the VM that this method cannot be compiled at all.1150void ciMethod::set_not_compilable(const char* reason) {1151check_is_loaded();1152VM_ENTRY_MARK;1153ciEnv* env = CURRENT_ENV;1154if (is_c1_compile(env->comp_level())) {1155_is_c1_compilable = false;1156} else {1157_is_c2_compilable = false;1158}1159get_Method()->set_not_compilable(env->comp_level(), true, reason);1160}11611162// ------------------------------------------------------------------1163// ciMethod::can_be_osr_compiled1164//1165// Have previous compilations of this method succeeded?1166//1167// Implementation note: the VM does not currently keep track1168// of failed OSR compilations per bci. The entry_bci parameter1169// is currently unused.1170bool ciMethod::can_be_osr_compiled(int entry_bci) {1171check_is_loaded();1172VM_ENTRY_MARK;1173ciEnv* env = CURRENT_ENV;1174return !get_Method()->is_not_osr_compilable(env->comp_level());1175}11761177// ------------------------------------------------------------------1178// ciMethod::has_compiled_code1179bool ciMethod::has_compiled_code() {1180return instructions_size() > 0;1181}11821183int ciMethod::comp_level() {1184check_is_loaded();1185VM_ENTRY_MARK;1186nmethod* nm = get_Method()->code();1187if (nm != NULL) return nm->comp_level();1188return 0;1189}11901191int ciMethod::highest_osr_comp_level() {1192check_is_loaded();1193VM_ENTRY_MARK;1194return get_Method()->highest_osr_comp_level();1195}11961197// ------------------------------------------------------------------1198// ciMethod::code_size_for_inlining1199//1200// Code size for inlining decisions. This method returns a code1201// size of 1 for methods which has the ForceInline annotation.1202int ciMethod::code_size_for_inlining() {1203check_is_loaded();1204if (get_Method()->force_inline()) {1205return 1;1206}1207return code_size();1208}12091210// ------------------------------------------------------------------1211// ciMethod::instructions_size1212//1213// This is a rough metric for "fat" methods, compared before inlining1214// with InlineSmallCode. The CodeBlob::code_size accessor includes1215// junk like exception handler, stubs, and constant table, which are1216// not highly relevant to an inlined method. So we use the more1217// specific accessor nmethod::insts_size.1218int ciMethod::instructions_size() {1219if (_instructions_size == -1) {1220GUARDED_VM_ENTRY(1221nmethod* code = get_Method()->code();1222if (code != NULL && (code->comp_level() == CompLevel_full_optimization)) {1223_instructions_size = code->insts_end() - code->verified_entry_point();1224} else {1225_instructions_size = 0;1226}1227);1228}1229return _instructions_size;1230}12311232// ------------------------------------------------------------------1233// ciMethod::log_nmethod_identity1234void ciMethod::log_nmethod_identity(xmlStream* log) {1235GUARDED_VM_ENTRY(1236nmethod* code = get_Method()->code();1237if (code != NULL) {1238code->log_identity(log);1239}1240)1241}12421243// ------------------------------------------------------------------1244// ciMethod::is_not_reached1245bool ciMethod::is_not_reached(int bci) {1246check_is_loaded();1247VM_ENTRY_MARK;1248return Interpreter::is_not_reached(1249methodHandle(THREAD, get_Method()), bci);1250}12511252// ------------------------------------------------------------------1253// ciMethod::was_never_executed1254bool ciMethod::was_executed_more_than(int times) {1255VM_ENTRY_MARK;1256return get_Method()->was_executed_more_than(times);1257}12581259// ------------------------------------------------------------------1260// ciMethod::has_unloaded_classes_in_signature1261bool ciMethod::has_unloaded_classes_in_signature() {1262VM_ENTRY_MARK;1263{1264EXCEPTION_MARK;1265methodHandle m(THREAD, get_Method());1266bool has_unloaded = Method::has_unloaded_classes_in_signature(m, (JavaThread *)THREAD);1267if( HAS_PENDING_EXCEPTION ) {1268CLEAR_PENDING_EXCEPTION;1269return true; // Declare that we may have unloaded classes1270}1271return has_unloaded;1272}1273}12741275// ------------------------------------------------------------------1276// ciMethod::is_klass_loaded1277bool ciMethod::is_klass_loaded(int refinfo_index, bool must_be_resolved) const {1278VM_ENTRY_MARK;1279return get_Method()->is_klass_loaded(refinfo_index, must_be_resolved);1280}12811282// ------------------------------------------------------------------1283// ciMethod::check_call1284bool ciMethod::check_call(int refinfo_index, bool is_static) const {1285// This method is used only in C2 from InlineTree::ok_to_inline,1286// and is only used under -Xcomp or -XX:CompileTheWorld.1287// It appears to fail when applied to an invokeinterface call site.1288// FIXME: Remove this method and resolve_method_statically; refactor to use the other LinkResolver entry points.1289VM_ENTRY_MARK;1290{1291EXCEPTION_MARK;1292HandleMark hm(THREAD);1293constantPoolHandle pool (THREAD, get_Method()->constants());1294methodHandle spec_method;1295KlassHandle spec_klass;1296Bytecodes::Code code = (is_static ? Bytecodes::_invokestatic : Bytecodes::_invokevirtual);1297LinkResolver::resolve_method_statically(spec_method, spec_klass, code, pool, refinfo_index, THREAD);1298if (HAS_PENDING_EXCEPTION) {1299CLEAR_PENDING_EXCEPTION;1300return false;1301} else {1302return (spec_method->is_static() == is_static);1303}1304}1305return false;1306}13071308// ------------------------------------------------------------------1309// ciMethod::print_codes1310//1311// Print the bytecodes for this method.1312void ciMethod::print_codes_on(outputStream* st) {1313check_is_loaded();1314GUARDED_VM_ENTRY(get_Method()->print_codes_on(st);)1315}131613171318#define FETCH_FLAG_FROM_VM(flag_accessor) { \1319check_is_loaded(); \1320VM_ENTRY_MARK; \1321return get_Method()->flag_accessor(); \1322}13231324bool ciMethod::is_empty_method() const { FETCH_FLAG_FROM_VM(is_empty_method); }1325bool ciMethod::is_vanilla_constructor() const { FETCH_FLAG_FROM_VM(is_vanilla_constructor); }1326bool ciMethod::has_loops () const { FETCH_FLAG_FROM_VM(has_loops); }1327bool ciMethod::has_jsrs () const { FETCH_FLAG_FROM_VM(has_jsrs); }1328bool ciMethod::is_accessor () const { FETCH_FLAG_FROM_VM(is_accessor); }1329bool ciMethod::is_initializer () const { FETCH_FLAG_FROM_VM(is_initializer); }13301331bool ciMethod::is_boxing_method() const {1332if (holder()->is_box_klass()) {1333switch (intrinsic_id()) {1334case vmIntrinsics::_Boolean_valueOf:1335case vmIntrinsics::_Byte_valueOf:1336case vmIntrinsics::_Character_valueOf:1337case vmIntrinsics::_Short_valueOf:1338case vmIntrinsics::_Integer_valueOf:1339case vmIntrinsics::_Long_valueOf:1340case vmIntrinsics::_Float_valueOf:1341case vmIntrinsics::_Double_valueOf:1342return true;1343default:1344return false;1345}1346}1347return false;1348}13491350bool ciMethod::is_unboxing_method() const {1351if (holder()->is_box_klass()) {1352switch (intrinsic_id()) {1353case vmIntrinsics::_booleanValue:1354case vmIntrinsics::_byteValue:1355case vmIntrinsics::_charValue:1356case vmIntrinsics::_shortValue:1357case vmIntrinsics::_intValue:1358case vmIntrinsics::_longValue:1359case vmIntrinsics::_floatValue:1360case vmIntrinsics::_doubleValue:1361return true;1362default:1363return false;1364}1365}1366return false;1367}13681369BCEscapeAnalyzer *ciMethod::get_bcea() {1370#ifdef COMPILER21371if (_bcea == NULL) {1372_bcea = new (CURRENT_ENV->arena()) BCEscapeAnalyzer(this, NULL);1373}1374return _bcea;1375#else // COMPILER21376ShouldNotReachHere();1377return NULL;1378#endif // COMPILER21379}13801381ciMethodBlocks *ciMethod::get_method_blocks() {1382Arena *arena = CURRENT_ENV->arena();1383if (_method_blocks == NULL) {1384_method_blocks = new (arena) ciMethodBlocks(arena, this);1385}1386return _method_blocks;1387}13881389#undef FETCH_FLAG_FROM_VM13901391void ciMethod::dump_name_as_ascii(outputStream* st) {1392Method* method = get_Method();1393st->print("%s %s %s",1394method->klass_name()->as_quoted_ascii(),1395method->name()->as_quoted_ascii(),1396method->signature()->as_quoted_ascii());1397}13981399void ciMethod::dump_replay_data(outputStream* st) {1400ResourceMark rm;1401Method* method = get_Method();1402MethodCounters* mcs = method->method_counters();1403st->print("ciMethod ");1404dump_name_as_ascii(st);1405st->print_cr(" %d %d %d %d %d",1406mcs == NULL ? 0 : mcs->invocation_counter()->raw_counter(),1407mcs == NULL ? 0 : mcs->backedge_counter()->raw_counter(),1408interpreter_invocation_count(),1409interpreter_throwout_count(),1410_instructions_size);1411}14121413// ------------------------------------------------------------------1414// ciMethod::print_codes1415//1416// Print a range of the bytecodes for this method.1417void ciMethod::print_codes_on(int from, int to, outputStream* st) {1418check_is_loaded();1419GUARDED_VM_ENTRY(get_Method()->print_codes_on(from, to, st);)1420}14211422// ------------------------------------------------------------------1423// ciMethod::print_name1424//1425// Print the name of this method, including signature and some flags.1426void ciMethod::print_name(outputStream* st) {1427check_is_loaded();1428GUARDED_VM_ENTRY(get_Method()->print_name(st);)1429}14301431// ------------------------------------------------------------------1432// ciMethod::print_short_name1433//1434// Print the name of this method, without signature.1435void ciMethod::print_short_name(outputStream* st) {1436if (is_loaded()) {1437GUARDED_VM_ENTRY(get_Method()->print_short_name(st););1438} else {1439// Fall back if method is not loaded.1440holder()->print_name_on(st);1441st->print("::");1442name()->print_symbol_on(st);1443if (WizardMode)1444signature()->as_symbol()->print_symbol_on(st);1445}1446}14471448// ------------------------------------------------------------------1449// ciMethod::print_impl1450//1451// Implementation of the print method.1452void ciMethod::print_impl(outputStream* st) {1453ciMetadata::print_impl(st);1454st->print(" name=");1455name()->print_symbol_on(st);1456st->print(" holder=");1457holder()->print_name_on(st);1458st->print(" signature=");1459signature()->as_symbol()->print_symbol_on(st);1460if (is_loaded()) {1461st->print(" loaded=true");1462st->print(" arg_size=%d", arg_size());1463st->print(" flags=");1464flags().print_member_flags(st);1465} else {1466st->print(" loaded=false");1467}1468}146914701471