/*
* 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.
*
*/
#ifndef SHARE_VM_OPTO_CALLGENERATOR_HPP
#define SHARE_VM_OPTO_CALLGENERATOR_HPP
#include "compiler/compileBroker.hpp"
#include "opto/callnode.hpp"
#include "opto/compile.hpp"
#include "runtime/deoptimization.hpp"
//---------------------------CallGenerator-------------------------------------
// The subclasses of this class handle generation of ideal nodes for
// call sites and method entry points.
public:
enum {
};
private:
protected:
public:
// Accessors
// is_inline: At least some code implementing the method is copied here.
virtual bool is_inline() const { return false; }
// is_intrinsic: There's a method-specific way of generating the inline code.
virtual bool is_intrinsic() const { return false; }
// is_parse: Bytecodes implementing the specific method are copied here.
virtual bool is_parse() const { return false; }
// is_virtual: The call uses the receiver type to select or check the method.
virtual bool is_virtual() const { return false; }
// is_deferred: The decision whether to inline or not is deferred.
virtual bool is_deferred() const { return false; }
// is_predicted: Uses an explicit check against a predicted type.
virtual bool is_predicted() const { return false; }
// is_trap: Does not return to the caller. (E.g., uncommon trap.)
virtual bool is_trap() const { return false; }
// is_late_inline: supports conversion of call into an inline
virtual bool is_late_inline() const { return false; }
// same but for method handle calls
virtual bool is_mh_late_inline() const { return false; }
// for method handle calls: have we tried inlinining the call already?
// Replace the call with an inline version of the code
// Note: It is possible for a CG to be both inline and virtual.
// (The hashCode intrinsic does a vtable check and an inlined fast path.)
// Utilities:
// The given jvms has state and arguments for a call to my method.
// Edges after jvms->argoff() carry all (pre-popped) argument values.
//
// Update the map with state and return values (if any) and return it.
// The return values (0, 1, or 2) must be pushed on the map's stack,
// and the sp of the jvms incremented accordingly.
//
// The jvms is returned on success. Alternatively, a copy of the
// given jvms, suitably updated, may be returned, in which case the
// caller should discard the original jvms.
//
// The non-Parm edges of the returned map will contain updated global state,
// and one or two edges before jvms->sp() will carry any return values.
// Other map edges may contain locals or monitors, and should not
// be changed in meaning.
//
// If the call traps, the returned map must have a control edge of top.
// If the call can throw, the returned map must report has_exceptions().
//
// If the result is NULL, it means that this CallGenerator was unable
// to handle the given call, and another CallGenerator should be consulted.
// How to generate a call site that is inlined:
// How to generate code for an on-stack replacement handler.
// How to generate vanilla out-of-line call sites:
static CallGenerator* for_direct_call(ciMethod* m, bool separate_io_projs = false); // static, special
static CallGenerator* for_method_handle_call( JVMState* jvms, ciMethod* caller, ciMethod* callee, bool delayed_forbidden);
static CallGenerator* for_method_handle_inline(JVMState* jvms, ciMethod* caller, ciMethod* callee, bool& input_not_const);
// How to generate a replace a direct call with an inline version
// How to make a call but defer the decision whether to inline or not.
// How to make a call that optimistically assumes a receiver type:
float hit_prob);
// How to make a call that optimistically assumes a MethodHandle target:
float hit_prob);
// How to make a call that gives up and goes back to the interpreter:
// Registry for intrinsics:
CallGenerator* cg);
static void print_inlining(Compile* C, ciMethod* callee, int inline_level, int bci, const char* msg) {
if (PrintInlining)
}
};
//------------------------InlineCallGenerator----------------------------------
protected:
public:
virtual bool is_inline() const { return true; }
};
//---------------------------WarmCallInfo--------------------------------------
// A struct to collect information about a given call site.
// Helps sort call sites into "hot", "medium", and "cold".
// Participates in the queueing of "medium" call sites for possible inlining.
private:
// These are the metrics we use to evaluate call sites:
// Count is the number of times this call site is expected to be executed.
// Large count is favorable for inlining, because the extra compilation
// work will be amortized more completely.
// Profit is a rough measure of the amount of time we expect to save
// per execution of this site if we inline it. (1.0 == call overhead)
// Large profit favors inlining. Negative profit disables inlining.
// Work is a rough measure of the amount of time a typical out-of-line
// call from this site is expected to take. (1.0 == call, no-op, return)
// Small work is somewhat favorable for inlining, since methods with
// short "hot" traces are more likely to inline smoothly.
// Size is the number of graph nodes we expect this method to produce,
// not counting the inlining of any further warm calls it may include.
// Small size favors inlining, since small methods are more likely to
// inline smoothly. The size is estimated by examining the native code
// if available. The method bytecodes are also examined, assuming
// empirically observed node counts for each kind of bytecode.
// Heat is the combined "goodness" of a site's inlining. If we were
// omniscient, it would be the difference of two sums of future execution
// times of code emitted for this site (amortized across multiple sites if
// sharing applies). The two sums are for versions of this call site with
// and without inlining.
// We approximate this mythical quantity by playing with averages,
// rough estimates, and assumptions that history repeats itself.
// The basic formula count * profit is heuristically adjusted
// by looking at the expected compilation and execution times of
// of the inlined call.
// Note: Some of these metrics may not be present in the final product,
// but exist in development builds to experiment with inline policy tuning.
// This heuristic framework does not model well the very significant
// effects of multiple-level inlining. It is possible to see no immediate
// profit from inlining X->Y, but to get great profit from a subsequent
// inlining X->Y->Z.
// This framework does not take well into account the problem of N**2 code
// size in a clique of mutually inlinable methods.
// Constructor intitialization of always_hot and always_cold
WarmCallInfo(float c, float p, float w, float s) {
_count = c;
_profit = p;
_work = w;
_size = s;
_heat = 0;
}
public:
// Because WarmInfo objects live over the entire lifetime of the
// Compile object, they are allocated into the comp_arena, which
// does not get resource marked or reset during the compile process
void operator delete( void * ) { } // fast deallocation
static WarmCallInfo* always_hot();
static WarmCallInfo* always_cold();
WarmCallInfo() {
}
// Load initial heuristics from profiles, etc.
// The heuristics can be tweaked further by the caller.
float compute_heat() const;
// Do not queue very hot or very cold calls.
// Make very cold ones out of line immediately.
// Inline very hot ones immediately.
// These queries apply various tunable limits
// to the above metrics in a systematic way.
// Test for coldness before testing for hotness.
bool is_cold() const;
bool is_hot() const;
// Force a warm call to be hot. This worklists the call node for inlining.
void make_hot();
// Force a warm call to be cold. This worklists the call node for out-of-lining.
void make_cold();
// A reproducible total ordering, in which heat is the major key.
// List management. These methods are called with the list head,
// and return the new list head, inserting or removing the receiver.
#ifndef PRODUCT
void print() const;
void print_all() const;
int count_all() const;
#endif
};
#endif // SHARE_VM_OPTO_CALLGENERATOR_HPP