/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "precompiled.hpp"
#include "ci/ciCallProfile.hpp"
#include "ci/ciExceptionHandler.hpp"
#include "ci/ciInstanceKlass.hpp"
#include "ci/ciMethod.hpp"
#include "ci/ciMethodBlocks.hpp"
#include "ci/ciMethodData.hpp"
#include "ci/ciMethodKlass.hpp"
#include "ci/ciStreams.hpp"
#include "ci/ciSymbol.hpp"
#include "ci/ciUtilities.hpp"
#include "classfile/systemDictionary.hpp"
#include "compiler/abstractCompiler.hpp"
#include "compiler/compilerOracle.hpp"
#include "compiler/methodLiveness.hpp"
#include "interpreter/interpreter.hpp"
#include "interpreter/linkResolver.hpp"
#include "interpreter/oopMapCache.hpp"
#include "memory/allocation.inline.hpp"
#include "memory/resourceArea.hpp"
#include "oops/generateOopMap.hpp"
#include "oops/oop.inline.hpp"
#include "prims/nativeLookup.hpp"
#include "runtime/deoptimization.hpp"
#include "utilities/bitMap.inline.hpp"
#include "utilities/xmlstream.hpp"
#ifdef COMPILER2
#include "ci/bcEscapeAnalyzer.hpp"
#include "ci/ciTypeFlow.hpp"
#include "oops/methodOop.hpp"
#endif
#ifdef SHARK
#include "ci/ciTypeFlow.hpp"
#include "oops/methodOop.hpp"
#endif
// ciMethod
//
// This class represents a methodOop in the HotSpot virtual
// machine.
// ------------------------------------------------------------------
// ciMethod::ciMethod
//
// Loaded method.
// These fields are always filled in in loaded methods.
// Easy to compute, so fill them in now.
// Lazy fields, filled in on demand. Require allocation.
#endif // COMPILER2 || SHARK
// 6328518 check hotswap conditions under the right lock.
_is_c1_compilable = false;
_is_c2_compilable = false;
}
} else {
}
} else {
// Have to use a conservative value in this case.
_can_be_statically_bound = false;
}
// Adjust the definition of this condition to be more useful:
// %%% take these conditions into account in vtable generation
_can_be_statically_bound = true;
_can_be_statically_bound = false;
// generating _signature may allow GC and therefore move m.
// These fields are always filled in.
_method_data = NULL;
// Take a snapshot of these values, so they will be commensurate with the MDO.
if (ProfileInterpreter || TieredCompilation) {
// if the value overflowed report it as max int
} else {
}
if (_interpreter_invocation_count == 0)
}
// ------------------------------------------------------------------
// ciMethod::ciMethod
//
// Unloaded method.
_can_be_statically_bound(false),
,
#endif // COMPILER2 || SHARK
{
// Usually holder and accessor are the same type but in some cases
// the holder has the wrong class loader (e.g. invokedynamic call
// sites) so we pass the accessor.
}
// ------------------------------------------------------------------
// ciMethod::load_code
//
// Load the bytecodes and exception handler table for this method.
// Load the bytecodes.
// Revert any breakpoint bytecodes in ci's copy
if (me->number_of_breakpoints() > 0) {
}
}
}
// And load the exception table.
// Allocate one extra spot in our list of exceptions. This
// last entry will be used to represent the possibility that
// an exception escapes the method. See ciExceptionHandlerStream
// for details.
* (_handler_count + 1));
if (_handler_count > 0) {
for (int i=0; i<_handler_count; i++) {
holder(),
}
}
// Put an entry at the end of our list to represent the possibility
// of exceptional exit.
if (CIPrintMethodCodes) {
print_codes();
}
}
// ------------------------------------------------------------------
// ciMethod::has_linenumber_table
//
// length unknown until decompression
return get_methodOop()->has_linenumber_table();
}
// ------------------------------------------------------------------
// ciMethod::compressed_linenumber_table
return get_methodOop()->compressed_linenumber_table();
}
// ------------------------------------------------------------------
// ciMethod::line_number_from_bci
}
// ------------------------------------------------------------------
// ciMethod::vtable_index
//
// Get the position of this method's entry in the vtable, if any.
return get_methodOop()->vtable_index();
}
#ifdef SHARK
// ------------------------------------------------------------------
// ciMethod::itable_index
//
// Get the position of this method's entry in the itable, if any.
}
#endif // SHARK
// ------------------------------------------------------------------
// ciMethod::native_entry
//
// Get the address of this method's native code, if any.
return entry;
}
// ------------------------------------------------------------------
// ciMethod::interpreter_entry
//
// Get the entry point for running this method in the interpreter.
}
// ------------------------------------------------------------------
// ciMethod::uses_balanced_monitors
//
// Does this method use monitors in a strict stack-disciplined manner?
if (_balanced_monitors) return true;
// Analyze the method to see if monitors are used properly.
// Check to see if a previous compilation computed the
// monitor-matching analysis.
if (method->guaranteed_monitor_matching()) {
_balanced_monitors = true;
return true;
}
{
if (!gpi.monitor_safe()) {
return false;
}
_balanced_monitors = true;
}
return true;
}
// ------------------------------------------------------------------
// ciMethod::get_flow_analysis
}
return _flow;
#else // COMPILER2 || SHARK
return NULL;
#endif // COMPILER2 || SHARK
}
// ------------------------------------------------------------------
// ciMethod::get_osr_flow_analysis
// OSR entry points are always place after a call bytecode of some sort
return flow;
#else // COMPILER2 || SHARK
return NULL;
#endif // COMPILER2 || SHARK
}
// ------------------------------------------------------------------
// ciMethod::raw_liveness_at_bci
//
// Which local variables are live at a specific bci?
// Create the liveness analyzer.
}
}
// ------------------------------------------------------------------
// ciMethod::liveness_at_bci
//
// Which local variables are live at a specific bci? When debugging
// will return true for all locals in some cases to improve debug
// information.
// Keep all locals live for the user's edification and amusement.
}
return result;
}
// ciMethod::live_local_oops_at_bci
//
// find all the live oops in the locals array for a particular bci
// Compute what the interpreter believes by using the interpreter
// oopmap generator. This is used as a double check during osr to
// guard against conservative result from MethodLiveness making us
// think a dead oop is live. MethodLiveness is conservative in the
// sense that it may consider locals to be live which cannot be live,
// like in the case where a local could contain an oop or a primitive
// along different paths. In that case the local must be dead when
// those paths merge. Since the interpreter's viewpoint is used when
// gc'ing an interpreter frame we need to use its viewpoint during
// OSR when loading the locals.
int i;
for (i = 0; i < mask_size ; i++ ) {
}
return result;
}
#ifdef COMPILER1
// ------------------------------------------------------------------
// ciMethod::bci_block_start
//
// Marks all bcis where a new basic block starts
// Create the liveness analyzer.
}
return _liveness->get_bci_block_start();
}
#endif // COMPILER1
// ------------------------------------------------------------------
// ciMethod::call_profile_at_bci
//
// Get the ciCallProfile for the invocation of this method.
// Also reports receiver types for non-call type checks (if TypeProfileCasts).
// Every profiled call site has a counter.
if (!data->is_ReceiverTypeData()) {
} else { // ReceiverTypeData is a subclass of CounterData
// In addition, virtual call sites have receiver type information
int receivers_count_total = 0;
int morphism = 0;
// Precompute morphism for the possible fixup
morphism++;
}
int epsilon = 0;
if (TieredCompilation && ProfileInterpreter) {
// Interpreter and C1 treat final and special invokes differently.
// C1 will record a type, whereas the interpreter will just
// increment the count. Detect this case.
count = 0;
}
}
// Add the receiver to result data.
// If we extend profiling to record methods,
// we will set result._method also.
}
// Determine call site's morphism.
// The call site count is 0 with known morphism (onlt 1 or 2 receivers)
// or < 0 in the case of a type check failured for checkcast, aastore, instanceof.
// The call site count is > 0 in the case of a polymorphic virtual call.
// The morphism <= MorphismLimit.
#ifdef ASSERT
if (count > 0) {
this->print_short_name(tty);
this->print_codes();
assert(false, "this call site should not be polymorphic");
}
#endif
}
}
// Make the count consistent if this is a call profile. If count is
// zero or less, presume that this is a typecheck profile and
// do nothing. Otherwise, increase count to be the sum of all
// receiver's counts.
if (count >= 0) {
}
}
}
}
return result;
}
// ------------------------------------------------------------------
// Add new receiver and sort data by receiver's profile count.
// Add new receiver and sort data by receiver's counts when we have space
// for it otherwise replace the less called receiver (less called receiver
// is placed to the last array element which is not used).
// First array's element contains most called receiver.
int i = _limit;
}
}
// ------------------------------------------------------------------
// ciMethod::find_monomorphic_target
//
// Given a certain calling environment, find the monomorphic target
// for the call. Return NULL if the call is not monomorphic in
// its calling environment, or if there are only abstract methods.
// The returned method is never abstract.
// Note: If caller uses a non-null result, it must inform dependencies
// via assert_unique_concrete_method or assert_leaf_type.
if (actual_recv->is_interface()) {
// %%% We cannot trust interface types, yet. See bug 6312651.
return NULL;
}
// Something went wrong looking up the actual receiver method.
return NULL;
}
// Make certain quick checks even if UseCHA is false.
// Is it private or final?
if (root_m->can_be_statically_bound()) {
return root_m;
}
// Easy case. There is no other place to put a method, so don't bother
// to go through the VM_ENTRY_MARK and all the rest.
return root_m;
}
// Array methods (clone, hashCode, etc.) are always statically bound.
// If we were to see an array type here, we'd return root_m.
// However, this method processes only ciInstanceKlasses. (See 4962591.)
// The inline_native_clone intrinsic narrows Object to T[] properly,
// so there is no need to do the same job here.
{
root_m->get_methodOop());
// %%% Should upgrade this ciMethod API to look for 1 or 2 concrete methods.
}
#ifndef PRODUCT
}
#endif //PRODUCT
return NULL;
}
return root_m;
}
!root_m->is_protected()) {
// If we are going to reason about inheritance, it's easiest
// if the method in question is public, protected, or private.
// If the answer is not root_m, it is conservatively correct
// to return NULL, even if the CHA encountered irrelevant
// methods in other packages.
// %%% TO DO: Work out logic for package-private methods
// with the same name but different vtable indexes.
return NULL;
}
}
// ------------------------------------------------------------------
// ciMethod::resolve_invoke
//
// Given a known receiver klass, find the target for the call.
// Return NULL if the call has no target or the target is abstract.
methodHandle m;
// Only do exact lookup if receiver klass has been linked. Otherwise,
// the vtable has not been setup, and the LinkResolver will fail.
if (h_recv->oop_is_javaArray()
||
if (holder()->is_interface()) {
m = LinkResolver::resolve_interface_call_or_null(h_recv, h_resolved, h_name, h_signature, caller_klass);
} else {
m = LinkResolver::resolve_virtual_call_or_null(h_recv, h_resolved, h_name, h_signature, caller_klass);
}
}
if (m.is_null()) {
// Return NULL only if there was a problem with lookup (uninitialized class, etc.)
return NULL;
}
if (m() != get_methodOop()) {
}
// Don't return abstract methods because they aren't
// optimizable or interesting.
if (result->is_abstract()) {
return NULL;
} else {
return result;
}
}
// ------------------------------------------------------------------
// ciMethod::resolve_vtable_index
//
// Given a known receiver klass, find the vtable index for the call.
// Return methodOopDesc::invalid_vtable_index if the vtable_index is unknown.
// Only do lookup if receiver klass has been linked. Otherwise,
// the vtable has not been setup, and the LinkResolver will fail.
if (!receiver->is_interface()
&& (!receiver->is_instance_klass() ||
vtable_index = LinkResolver::resolve_virtual_vtable_index(h_recv, h_recv, h_name, h_signature, caller_klass);
// A statically bound method. Return "no such index".
}
}
return vtable_index;
}
// ------------------------------------------------------------------
// ciMethod::interpreter_call_site_count
if (method_data() != NULL) {
}
}
return -1; // unknown
}
// ------------------------------------------------------------------
// ciMethod::get_field_at_bci
ciBytecodeStream iter(this);
}
// ------------------------------------------------------------------
// ciMethod::get_method_at_bci
ciBytecodeStream iter(this);
}
// ------------------------------------------------------------------
// Adjust a CounterData count to be commensurate with
// interpreter_invocation_count. If the MDO exists for
// only 25% of the time the method exists, then the
// counts in the MDO should be scaled by 4X, so that
// they can be usefully and stably compared against the
// invocation counts in methods.
int counter_life;
if (TieredCompilation) {
// In tiered the MDO's life is measured directly, so just use the snapshotted counters
} else {
}
// counter_life due to backedge_counter could be > method_life
if (counter_life > method_life)
}
}
return count;
}
// ------------------------------------------------------------------
// invokedynamic support
// ------------------------------------------------------------------
// ciMethod::is_method_handle_intrinsic
//
// Return true if the method is an instance of the JVM-generated
// signature-polymorphic MethodHandle methods, _invokeBasic, _linkToVirtual, etc.
}
// ------------------------------------------------------------------
// ciMethod::is_compiled_lambda_form
//
// Return true if the method is a generated MethodHandle adapter.
// These are built by Java code.
}
// ------------------------------------------------------------------
// ciMethod::has_member_arg
//
// Return true if the method is a linker intrinsic like _linkToVirtual.
// These are built by the JVM.
}
// ------------------------------------------------------------------
// ciMethod::ensure_method_data
//
// Generate new methodDataOop objects at compile time.
// Return true if allocation was successful or no MDO is required.
if (HAS_PENDING_EXCEPTION) {
}
}
return true;
} else {
return false;
}
}
// public, retroactive version
bool result = true;
});
}
return result;
}
// ------------------------------------------------------------------
// ciMethod::method_data
//
if (_method_data != NULL) {
return _method_data;
}
} else {
}
return _method_data;
}
// ------------------------------------------------------------------
// ciMethod::method_data_or_null
// Returns a pointer to ciMethodData if MDO exists on the VM side,
// NULL otherwise.
return md;
}
// ------------------------------------------------------------------
// ciMethod::should_exclude
//
// Should this method be excluded from compilation?
bool ignore;
}
// ------------------------------------------------------------------
// ciMethod::should_inline
//
// Should this method be inlined during compilation?
}
// ------------------------------------------------------------------
// ciMethod::should_not_inline
//
// Should this method be disallowed from inlining during compilation?
}
// ------------------------------------------------------------------
// ciMethod::should_print_assembly
//
// Should the compiler print the generated code for this method?
}
// ------------------------------------------------------------------
// ciMethod::break_at_execute
//
// Should the compiler insert a breakpoint into the generated code
// method?
}
// ------------------------------------------------------------------
// ciMethod::has_option
//
}
// ------------------------------------------------------------------
// ciMethod::can_be_compiled
//
// Have previous compilations of this method succeeded?
return _is_c1_compilable;
}
return _is_c2_compilable;
}
// ------------------------------------------------------------------
// ciMethod::set_not_compilable
//
// Tell the VM that this method cannot be compiled at all.
_is_c1_compilable = false;
} else {
_is_c2_compilable = false;
}
}
// ------------------------------------------------------------------
// ciMethod::can_be_osr_compiled
//
// Have previous compilations of this method succeeded?
//
// Implementation note: the VM does not currently keep track
// of failed OSR compilations per bci. The entry_bci parameter
// is currently unused.
}
// ------------------------------------------------------------------
// ciMethod::has_compiled_code
}
return 0;
}
return get_methodOop()->highest_osr_comp_level();
}
// ------------------------------------------------------------------
// ciMethod::code_size_for_inlining
//
// Code size for inlining decisions. This method returns a code
// size of 1 for methods which has the ForceInline annotation.
if (get_methodOop()->force_inline()) {
return 1;
}
return code_size();
}
// ------------------------------------------------------------------
// ciMethod::instructions_size
//
// This is a rough metric for "fat" methods, compared before inlining
// with InlineSmallCode. The CodeBlob::code_size accessor includes
// junk like exception handler, stubs, and constant table, which are
// not highly relevant to an inlined method. So we use the more
// specific accessor nmethod::insts_size.
}
return 0;
)
}
// ------------------------------------------------------------------
// ciMethod::log_nmethod_identity
}
)
}
// ------------------------------------------------------------------
// ciMethod::is_not_reached
return Interpreter::is_not_reached(
}
// ------------------------------------------------------------------
// ciMethod::was_never_executed
}
// ------------------------------------------------------------------
// ciMethod::has_unloaded_classes_in_signature
{
if( HAS_PENDING_EXCEPTION ) {
return true; // Declare that we may have unloaded classes
}
return has_unloaded;
}
}
// ------------------------------------------------------------------
// ciMethod::is_klass_loaded
}
// ------------------------------------------------------------------
// ciMethod::check_call
{
LinkResolver::resolve_method_statically(spec_method, spec_klass, code, pool, refinfo_index, THREAD);
if (HAS_PENDING_EXCEPTION) {
return false;
} else {
}
}
return false;
}
// ------------------------------------------------------------------
// ciMethod::print_codes
//
// Print the bytecodes for this method.
}
check_is_loaded(); \
return get_methodOop()->flag_accessor(); \
}
#ifdef COMPILER2
}
return _bcea;
#else // COMPILER2
return NULL;
#endif // COMPILER2
}
if (_method_blocks == NULL) {
}
return _method_blocks;
}
// ------------------------------------------------------------------
// ciMethod::print_codes
//
// Print a range of the bytecodes for this method.
}
// ------------------------------------------------------------------
// ciMethod::print_name
//
// Print the name of this method, including signature and some flags.
}
// ------------------------------------------------------------------
// ciMethod::print_short_name
//
// Print the name of this method, without signature.
if (is_loaded()) {
} else {
// Fall back if method is not loaded.
if (WizardMode)
}
}
// ------------------------------------------------------------------
// ciMethod::print_impl
//
// Implementation of the print method.
if (is_loaded()) {
} else {
}
}