/*
* 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 "classfile/systemDictionary.hpp"
#include "code/debugInfoRec.hpp"
#include "code/nmethod.hpp"
#include "code/pcDesc.hpp"
#include "code/scopeDesc.hpp"
#include "interpreter/bytecode.hpp"
#include "interpreter/interpreter.hpp"
#include "interpreter/oopMapCache.hpp"
#include "memory/allocation.inline.hpp"
#include "memory/oopFactory.hpp"
#include "memory/resourceArea.hpp"
#include "oops/methodOop.hpp"
#include "oops/oop.inline.hpp"
#include "prims/jvmtiThreadState.hpp"
#include "runtime/biasedLocking.hpp"
#include "runtime/compilationPolicy.hpp"
#include "runtime/deoptimization.hpp"
#include "runtime/interfaceSupport.hpp"
#include "runtime/sharedRuntime.hpp"
#include "runtime/signature.hpp"
#include "runtime/stubRoutines.hpp"
#include "runtime/thread.hpp"
#include "runtime/vframe.hpp"
#include "runtime/vframeArray.hpp"
#include "runtime/vframe_hp.hpp"
#include "utilities/events.hpp"
#include "utilities/xmlstream.hpp"
#ifdef TARGET_ARCH_x86
# include "vmreg_x86.inline.hpp"
#endif
#ifdef TARGET_ARCH_sparc
# include "vmreg_sparc.inline.hpp"
#endif
#ifdef TARGET_ARCH_zero
# include "vmreg_zero.inline.hpp"
#endif
#ifdef TARGET_ARCH_arm
# include "vmreg_arm.inline.hpp"
#endif
#ifdef TARGET_ARCH_ppc
# include "vmreg_ppc.inline.hpp"
#endif
#ifdef COMPILER2
#ifdef TARGET_ARCH_MODEL_x86_32
# include "adfiles/ad_x86_32.hpp"
#endif
#ifdef TARGET_ARCH_MODEL_x86_64
# include "adfiles/ad_x86_64.hpp"
#endif
#ifdef TARGET_ARCH_MODEL_sparc
# include "adfiles/ad_sparc.hpp"
#endif
#ifdef TARGET_ARCH_MODEL_zero
# include "adfiles/ad_zero.hpp"
#endif
#ifdef TARGET_ARCH_MODEL_arm
# include "adfiles/ad_arm.hpp"
#endif
#ifdef TARGET_ARCH_MODEL_ppc
# include "adfiles/ad_ppc.hpp"
#endif
#endif
int caller_adjustment,
int number_of_frames,
_initial_info = 0;
// PD (x86 only)
_counter_temp = 0;
_unpack_kind = 0;
_sender_sp_temp = 0;
}
}
}
// Acount first for the adjustment of the initial frame
int result = _caller_adjustment;
}
return result;
}
}
}
// In order to make fetch_unroll_info work properly with escape
// analysis, The method was changed from JRT_LEAF to JRT_BLOCK_ENTRY and
// ResetNoHandleMark and HandleMark were removed from it. The actual reallocation
// of previously eliminated objects occurs in realloc_objects, which is
// called from the method fetch_unroll_info_helper below.
JRT_BLOCK_ENTRY(Deoptimization::UnrollBlock*, Deoptimization::fetch_unroll_info(JavaThread* thread))
// It is actually ok to allocate handles in a leaf method. It causes no safepoints,
// but makes the entry a little slower. There is however a little dance we have to
// do in debug mode to get around the NoHandleMark code in the JRT_LEAF macro
// fetch_unroll_info() is called at the beginning of the deoptimization
// handler. Note this fact before we start generating temporary frames
// that can confuse an asynchronous stack walker. This counter is
// decremented at the end of unpack_frames().
return fetch_unroll_info_helper(thread);
// This is factored, since it is both called from a JRT_LEAF (deoptimization) and a JRT_ENTRY (uncommon_trap)
// Note: there is a safepoint safety issue here. No matter whether we enter
// via vanilla deopt or uncommon trap we MUST NOT stop at a safepoint once
// the vframeArray is created.
//
// Allocate our special deoptimization ResourceMark
// Now get the deoptee with a valid map
// Set the deoptee nmethod
if (VerifyStack) {
}
// Create a growable array of VFrames where each VFrame represents an inlined
// Java frame. This storage is allocated with the usual system arena.
}
#ifdef COMPILER2
// Reallocate the non-escaping objects and restore their fields. Then
// relock objects if synchronization on them was eliminated.
if (DoEscapeAnalysis || EliminateNestedLocks) {
if (EliminateAllocations) {
// The flag return_oop() indicates call sites which return oop
// in compiled code. Such sites include java method calls,
// on slow code path) and any other calls generated in compiled code.
// It is not guaranteed that we can get such information here only
// by analyzing bytecode in deoptimized frames. This is why this flag
// is set during method compilation (see Compile::Process_OopMap_Node()).
if (save_oop_result) {
// Reallocation may trigger GC. If deoptimization happened on return from
// call which returns oop we need to save it since it is not in oopmap.
if (TraceDeoptimization) {
}
}
bool reallocated = false;
}
if (reallocated) {
#ifndef PRODUCT
if (TraceDeoptimization) {
}
#endif
}
if (save_oop_result) {
// Restore result.
}
}
if (EliminateLocks) {
#ifndef PRODUCT
bool first = true;
#endif
if (monitors->is_nonempty()) {
#ifndef PRODUCT
if (TraceDeoptimization) {
if (mi->eliminated()) {
if (first) {
first = false;
}
}
}
}
#endif
}
}
}
}
#endif // COMPILER2
// Ensure that no safepoint is taken after pointers have been stored
// in fields of rematerialized objects. If a safepoint occurs from here on
// out the java state residing in the vframeArray will be missed.
// Now that the vframeArray has been created if we have any deferred local writes
// added by jvmti then we can free up that structure as the data is now in the
// vframeArray
int i = 0;
do {
// Because of inlining we could have multiple vframes for a single frame
// and several of the vframes could have deferred writes. Find them all.
// individual jvmtiDeferredLocalVariableSet are CHeapObj's
delete dlv;
} else {
i++;
}
// free the list and elements back to C heap.
delete list;
}
}
#ifndef SHARK
// Compute the caller frame based on the sender sp of stub_frame and stored frame sizes info.
// Verify we have the right vframeArray
// If the deopt call site is a MethodHandle invoke call site we have
// to adjust the unpack_sp.
#ifdef ASSERT
#endif
#else
#endif // !SHARK
// This is a guarantee instead of an assert because if vframe doesn't match
// we will unpack the wrong deoptimized frame and wind up in strange places
// where it will be very difficult to figure out what went wrong. Better
// to die an early death here than some very obscure death later when the
// trail is cold.
// Note: on ia64 this guarantee can be fooled by frames with no memory stack
// in that it will fail to detect a problem when there is one. This needs
// more work in tiger timeframe.
guarantee(array->unextended_sp() == unpack_sp, "vframe_array_head must contain the vframeArray to unpack");
// Compute the vframes' sizes. Note that frame_sizes[] entries are ordered from outermost to innermost
// virtual activation, which is the reverse of the elements in the vframes array.
// +1 because we always have an interpreter return address for the final slot.
int popframe_extra_args = 0;
// Create an interpreter return address for the stub to use as its return
// address so the skeletal frames are perfectly walkable
// PopFrame requires that the preserved incoming arguments from the recently-popped topmost
// activation be put back on the expression stack of the caller for reexecution
}
// Find the current pc for sender of the deoptee. Since the sender may have been deoptimized
// itself since the deoptee vframeArray was created we must get a fresh value of the pc rather
// than simply use array->sender.pc(). This requires us to walk the current set of frames
//
// It's possible that the number of paramters at the call site is
// different than number of arguments in the callee when method
// handles are used. If the caller is interpreted get the real
// value so that the proper amount of space can be added to it's
// frame.
bool caller_was_method_handle = false;
if (deopt_sender.is_interpreted_frame()) {
// Method handle invokes may involve fairly arbitrary chains of
// calls so it's impossible to know how much actual space the
// caller has for locals.
caller_was_method_handle = true;
}
}
//
// frame_sizes/frame_pcs[0] oldest frame (int or c2i)
// frame_sizes/frame_pcs[1] next oldest frame (int)
// frame_sizes/frame_pcs[n] youngest frame (int)
//
// Now a pc in frame_pcs is actually the return address to the frame's caller (a frame
// owns the space for the return address to it's caller). Confusing ain't it.
//
// The vframe array can address vframes with indices running from
// 0.._frames-1. Index 0 is the youngest frame and _frame - 1 is the oldest (root) frame.
// When we create the skeletal frames we need the oldest frame to be in the zero slot
// in the frame_sizes/frame_pcs so the assembly code can do a trivial walk.
// so things look a little strange in this loop.
//
int callee_parameters = 0;
int callee_locals = 0;
// frame[number_of_frames - 1 ] = on_stack_size(youngest)
// frame[number_of_frames - 2 ] = on_stack_size(sender(youngest))
// frame[number_of_frames - 3 ] = on_stack_size(sender(sender(youngest)))
caller_parms = 0;
}
frame_sizes[number_of_frames - 1 - index] = BytesPerWord * array->element(index)->on_stack_size(caller_parms,
index == 0,
// This pc doesn't have to be perfect just good enough to identify the frame
// as interpreted so the skeleton frame will be walkable
// The correct pc will be set when the skeleton frame is completely filled out
// The final pc we store in the loop is wrong and will be overwritten below
frame_pcs[number_of_frames - 1 - index ] = Interpreter::deopt_entry(vtos, 0) - frame::pc_return_offset;
popframe_extra_args = 0;
}
// Compute whether the root vframe returns a float or double value.
{
}
// Compute information for handling adapters and adjusting the frame size of the caller.
int caller_adjustment = 0;
// Compute the amount the oldest interpreter frame will have to adjust
// its caller's stack by. If the caller is a compiled frame then
// we pretend that the callee has no parameters so that the
// extension counts for the full amount of locals and not just
// locals-parms. This is because without a c2i adapter the parm
// area as created by the compiled frame will not be usable by
// the interpreter. (Depending on the calling convention there
// may not even be enough space).
// QQQ I'd rather see this pushed down into last_frame_adjust
// and have it take the sender (aka caller).
} else if (callee_locals > callee_parameters) {
// The caller frame may need extending to accommodate
// non-parameter locals of the first unpacked interpreted frame.
// Compute that adjustment.
}
// If the sender is deoptimized the we must retrieve the address of the handler
// since the frame will "magically" show the original pc before the deopt
// and we'd undo the deopt.
#ifndef SHARK
#endif // SHARK
// On some platforms, we need a way to pass some platform dependent
// information to the unpacking code so the skeletal frames come out
// correct (initial fp value, unextended sp, ...)
if (VerifyStack && TraceDeoptimization) {
}
}
return info;
}
// Called to cleanup deoptimization data structures in normal case
// after unpacking to stack and when stack overflow error occurs
vframeArray *array) {
// Get array if coming from exception
}
// Free the previous UnrollBlock
delete old_info;
delete old_array;
}
// Deallocate any resource creating in this routine and any ResourceObjs allocated
// inside the vframeArray (StackValueCollections)
delete thread->deopt_mark();
if (JvmtiExport::can_pop_frame()) {
#ifndef CC_INTERP
// Regardless of whether we entered this routine with the pending
// popframe condition bit set, we should always clear it now
#else
// C++ interpeter will clear has_pending_popframe when it enters
// with method_resume. For deopt_resume2 we clear it now.
#endif /* CC_INTERP */
}
// unpack_frames() is called at the end of the deoptimization handler
// and (in C2) at the end of the uncommon trap handler. Note this fact
// so that an asynchronous stack walker can work again. This counter is
// incremented at the beginning of fetch_unroll_info() and (in C2) at
// the beginning of uncommon_trap().
}
// Return BasicType of value being returned
// We are already active int he special DeoptResourceMark any ResourceObj's we
// allocate will be freed at the end of the routine.
// It is actually ok to allocate handles in a leaf method. It causes no safepoints,
// but makes the entry a little slower. There is however a little dance we have to
// do in debug mode to get around the NoHandleMark code in the JRT_LEAF macro
// Since the frame to unpack is the top frame of this thread, the vframe_array_head
// must point to the vframeArray for the unpack frame.
#ifndef PRODUCT
if (TraceDeoptimization) {
tty->print_cr("DEOPT UNPACKING thread " INTPTR_FORMAT " vframeArray " INTPTR_FORMAT " mode %d", thread, array, exec_mode);
}
#endif
// Unpack the interpreter frames and any adapter frame (c2 only) we might create.
// If we have an exception pending, claim that the return type is an oop
// so the deopt_blob does not overwrite the exception_oop.
if (exec_mode == Unpack_exception)
// Cleanup thread deopt data
#ifndef PRODUCT
if (VerifyStack) {
// Verify that the just-unpacked frames match the interpreter's
// notions of expression stack and locals
rm.set_include_argument_oops(false);
bool is_top_frame = true;
int callee_size_of_parameters = 0;
int callee_max_locals = 0;
// Get the oop map for this bci
int cur_invoke_parameter_size = 0;
bool try_next_mask = false;
// Get to the next bytecode if possible
// Check to see if we can grab the number of outgoing arguments
// at an uncommon trap for an invoke (where the compiler
// generates debug info before the invoke has executed)
// Add in receiver
}
}
if (bc >= 0) {
// The interpreter oop map generator reports results before
// the current bytecode has executed except in the case of
// calls. It seems to be hard to tell whether the compiler
// has emitted debug information matching the "state before"
// a given bytecode or the state after, so we try both
switch (cur_code) {
case Bytecodes::_invokevirtual:
case Bytecodes::_invokespecial:
case Bytecodes::_invokestatic:
case Bytecodes::_invokeinterface:
break;
default: {
// Need to subtract off the size of the result type of
// the bytecode because this is not described in the
// debug info but returned to the interpreter in the TOS
// caching register
if (bytecode_result_type != T_ILLEGAL) {
}
try_next_mask = true;
break;
}
}
}
}
// Verify stack depth and oops in frame
// This assertion may be dependent on the platform we're running on and may need modification (tested on x86 and sparc)
if (!(
/* SPARC */
(iframe->interpreter_frame_expression_stack_size() == mask.expression_stack_size() + callee_size_of_parameters) ||
/* x86 */
(iframe->interpreter_frame_expression_stack_size() == mask.expression_stack_size() + callee_max_locals) ||
(try_next_mask &&
(is_top_frame && (exec_mode == Unpack_exception) && iframe->interpreter_frame_expression_stack_size() == 0) ||
(iframe->interpreter_frame_expression_stack_size() == mask.expression_stack_size() + cur_invoke_parameter_size))
)) {
// Print out some information that will help us debug the problem
tty->print_cr(" Error occurred while verifying frame %d (0..%d, 0 is topmost)", i, cur_array->frames() - 1);
tty->print_cr(" Interpreter oop map had %d expression stack elements", mask.expression_stack_size());
tty->print_cr(" top_frame_expression_stack_adjustment = %d", top_frame_expression_stack_adjustment);
tty->print_cr(" Thread = " INTPTR_FORMAT ", thread ID = " UINTX_FORMAT, thread, thread->osthread()->thread_id());
}
guarantee(false, "wrong number of expression stack elements during deopt");
}
is_top_frame = false;
}
}
#endif /* !PRODUCT */
return bt;
return 0;
}
#ifdef COMPILER2
bool Deoptimization::realloc_objects(JavaThread* thread, frame* fr, GrowableArray<ScopeValue*>* objects, TRAPS) {
if (k->oop_is_instance()) {
} else if (k->oop_is_typeArray()) {
} else if (k->oop_is_objArray()) {
}
}
if (pending_exception.not_null()) {
}
return true;
}
// This assumes that the fields are stored in ObjectValue in the same order
// they are yielded by do_nonstatic_fields.
int _i;
public:
int i() const { return _i; }
switch (fd->field_type()) {
break;
#ifdef _LP64
#else
#ifdef SPARC
// For SPARC we have to swap high and low words.
#else
#endif //SPARC
#endif
break;
}
// Have to cast to INT (32 bits) pointer to avoid little/big-endian problem.
break;
break;
break;
default:
}
_i++;
}
};
// restore elements of an eliminated type array
void Deoptimization::reassign_type_array_elements(frame* fr, RegisterMap* reg_map, ObjectValue* sv, typeArrayOop obj, BasicType type) {
int index = 0;
for (int i = 0; i < sv->field_size(); i++) {
switch(type) {
#ifdef _LP64
#else
#ifdef SPARC
// For SPARC we have to swap high and low words.
#else
#endif //SPARC
#endif
break;
}
// Have to cast to INT (32 bits) pointer to avoid little/big-endian problem.
break;
break;
break;
default:
}
index++;
}
}
// restore fields of an eliminated object array
void Deoptimization::reassign_object_array_elements(frame* fr, RegisterMap* reg_map, ObjectValue* sv, objArrayOop obj) {
for (int i = 0; i < sv->field_size(); i++) {
}
}
// restore fields of all eliminated objects and arrays
void Deoptimization::reassign_fields(frame* fr, RegisterMap* reg_map, GrowableArray<ScopeValue*>* objects) {
if (k->oop_is_instance()) {
} else if (k->oop_is_typeArray()) {
} else if (k->oop_is_objArray()) {
}
}
}
// relock objects for which synchronization was eliminated
if (mon_info->eliminated()) {
// New allocated objects may have the mark set to anonymously biased.
// Also the deoptimized method may called methods with synchronization
// where the thread-local object is bias locked to the current thread.
// Reset mark word to unbiased prototype.
}
}
}
}
#ifndef PRODUCT
// print information about reallocated objects
k->as_klassOop()->print_value();
if (Verbose) {
}
}
}
#endif
#endif // COMPILER2
vframeArray* Deoptimization::create_vframeArray(JavaThread* thread, frame fr, RegisterMap *reg_map, GrowableArray<compiledVFrame*>* chunk) {
#ifndef PRODUCT
if (TraceDeoptimization) {
vf->print_value();
const char* code_name;
if (bci == SynchronizationEntryBCI) {
code_name = "sync entry";
} else {
}
if (Verbose) {
}
}
}
#endif
// Register map for next frame (used for stack crawl). We capture
// the state of the deopt'ing frame's caller. Thus if we need to
// stuff a C2I adapter we can properly fill in the callee-save
// register locations.
// Since the Java thread being deoptimized will eventually adjust it's own stack,
// the vframeArray containing the unpacking information is allocated in the C heap.
// For Compiler1, the caller of the deoptimized frame is saved for use by unpack_frames().
// Compare the vframeArray to the collected vframes
#ifndef PRODUCT
if (TraceDeoptimization) {
}
#endif // PRODUCT
return array;
}
}
}
}
if (!UseBiasedLocking) {
return;
}
// Unfortunately we don't have a RegisterMap available in most of
// the places we want to call this routine so we need to walk the
// stack again to update the register map.
bool found = false;
}
}
// Revoke monitors' biases in all scopes
}
if (SafepointSynchronize::is_at_safepoint()) {
} else {
}
}
if (!UseBiasedLocking) {
return;
}
if (jt->has_last_Java_frame()) {
// Revoke monitors' biases in all scopes
}
}
}
}
}
}
// Patch the nmethod so that when execution returns to it we will
// deopt the execution state and return to the interpreter.
}
// Deoptimize only if the frame comes from compile code.
// Do not deoptimize the frame which is already patched
// during the execution of the loops below.
return;
}
if (UseBiasedLocking) {
}
}
"can only deoptimize other thread at a safepoint");
// Compute frame and register map based on thread and sp.
}
}
} else {
}
}
// JVMTI PopFrame support
JRT_LEAF(void, Deoptimization::popframe_preserve_args(JavaThread* thread, int bytes_to_save, void* start_address))
{
}
// in case of an unresolved klass entry, load the class.
return;
}
// class name?
return;
}
// then it must be a signature!
}
}
}
if (HAS_PENDING_EXCEPTION) {
// Exception happened during classloading. We ignore the exception here, since it
// is going to be rethrown since the current activation is going to be deoptimzied and
// the interpreter will re-execute the bytecode.
}
}
// uncommon_trap() is called at the beginning of the uncommon trap
// handler. Note this fact before we start generating temporary frames
// that can confuse an asynchronous stack walker. This counter is
// decremented at the end of unpack_frames().
// We need to update the map if we have biased locking.
// Make sure the calling nmethod is not getting deoptimized and removed
// before we are done with it.
// Log a message
{
// Revoke biases of any monitors in the frame to ensure we can migrate them
// Record this event in the histogram.
// Ensure that we can record deopt. history:
// Log a message
Events::log_deopt_message(thread, "Uncommon trap: reason=%s action=%s pc=" INTPTR_FORMAT " method=%s @ %d",
// Print a bunch of diagnostics, if requested.
if (TraceDeoptimization || LogCompilation) {
os::current_thread_id(),
}
bool unresolved = false;
if (unloaded_class_index >= 0) {
unresolved = true;
}
}
// Dump the relevant MDO state.
// This is the deopt count for the current reason, any previous
// reasons or recompiles seen at this point.
if (dcnt != 0)
if (dos != 0) {
if (trap_state_is_recompiled(dos)) {
if (recnt2 != 0)
}
}
}
}
if (TraceDeoptimization) { // make noise on the tty
tty->print(" (@" INTPTR_FORMAT ") thread=" UINTX_FORMAT " reason=%s action=%s unloaded_class_index=%d",
os::current_thread_id(),
if (class_name != NULL) {
}
}
// Log the precise location of the trap.
}
}
}
// (End diagnostic printout.)
// Load class if necessary
if (unloaded_class_index >= 0) {
}
// Flush the nmethod if necessary and desirable.
//
// We need to avoid situations where we are re-flushing the nmethod
// because of a hot deoptimization site. Repeated flushes at the same
// point need to be detected by the compiler and avoided. If the compiler
// cannot avoid them (or has a bug and "refuses" to avoid them), this
// module must take measures to avoid an infinite cycle of recompilation
// and deoptimization. There are several such measures:
//
// 1. If a recompilation is ordered a second time at some site X
// and for the same reason R, the action is adjusted to 'reinterpret',
// to give the interpreter time to exercise the method more thoroughly.
// If this happens, the method's overflow_recompile_count is incremented.
//
// 2. If the compiler fails to reduce the deoptimization rate, then
// the method's overflow_recompile_count will begin to exceed the set
// limit PerBytecodeRecompilationCutoff. If this happens, the action
// is adjusted to 'make_not_compilable', and the method is abandoned
// to the interpreter. This is a performance hit for hot methods,
// but is better than a disastrous infinite cycle of recompilations.
// (Actually, only the method containing the site X is abandoned.)
//
// 3. In parallel with the previous measures, if the total number of
// recompilations of a method exceeds the much larger set limit
// PerMethodRecompilationCutoff, the method is abandoned.
// This should only happen if the method is very large and has
// many "lukewarm" deoptimizations. The code which enforces this
// limit is elsewhere (class nmethod, class methodOopDesc).
//
// Note that the per-BCI 'is_recompiled' bit gives the compiler one chance
// to recompile at each bytecode independently of the per-BCI cutoff.
//
// The decision to update code is up to the compiler, and is encoded
// in the Action_xxx code. If the compiler requests Action_none
// no trap state is changed, no compiled code is changed, and the
// computation suffers along in the interpreter.
//
// The other action codes specify various tactics for decompilation
// and recompilation. Action_maybe_recompile is the loosest, and
// allows the compiled code to stay around until enough traps are seen,
// and until the compiler gets around to recompiling the trapping method.
//
// The other actions cause immediate removal of the present code.
bool update_trap_state = true;
bool make_not_entrant = false;
bool make_not_compilable = false;
bool reprofile = false;
switch (action) {
case Action_none:
// Keep the old code.
update_trap_state = false;
break;
case Action_maybe_recompile:
// Do not need to invalidate the present code, but we can
// initiate another
// Start compiler without (necessarily) invalidating the nmethod.
// The system will tolerate the old code, but new code should be
// generated when possible.
break;
case Action_reinterpret:
// Go back into the interpreter for a while, and then consider
// recompiling form scratch.
make_not_entrant = true;
// Reset invocation counter for outer most method.
// This will allow the interpreter to exercise the bytecodes
// for a while before recompiling.
// By contrast, Action_make_not_entrant is immediate.
//
// Note that the compiler will track null_check, null_assert,
// range_check, and class_check events and log them as if they
// had been traps taken from compiled code. This will update
// the MDO trap history so that the next compilation will
// properly detect hot trap sites.
reprofile = true;
break;
case Action_make_not_entrant:
// Request immediate recompilation, and get rid of the old code.
// Make them not entrant, so next time they are called they get
// recompiled. Unloaded classes are loaded now so recompile before next
// time they are called. Same for uninitialized. The interpreter will
// link the missing class, if any.
make_not_entrant = true;
break;
// Give up on compiling this method at all.
make_not_entrant = true;
make_not_compilable = true;
break;
default:
}
// Setting +ProfileTraps fixes the following, on all platforms:
// 4852688: ProfileInterpreter is off by default for ia64. The result is
// infinite heroic-opt-uncommon-trap/deopt/recompile cycles, since the
// recompile relies on a methodDataOop to record heroic opt failures.
// Whether the interpreter is producing MDO data or not, we also need
// to use the MDO to detect hot deoptimization points and control
// aggressive optimization.
bool inc_recompile_count = false;
bool maybe_prior_trap = false;
bool maybe_prior_recompile = false;
//outputs:
// Because the interpreter also counts null, div0, range, and class
// checks, these traps from compiled code are double-counted.
// This is harmless; it just means that the PerXTrapLimit values
// are in effect a little smaller than they look.
if (per_bc_reason != Reason_none) {
// Now take action based on the partially known per-BCI history.
if (maybe_prior_trap
// If there are too many traps at this BCI, force a recompile.
// This will allow the compiler to see the limit overflow, and
// take corrective action, if possible. The compiler generally
// does not use the exact PerBytecodeTrapLimit value, but instead
// changes its tactics if it sees any traps at all. This provides
// a little hysteresis, delaying a recompile until a trap happens
// several times.
//
// Actually, since there is only one bit of counter per BCI,
// the possible per-BCI counts are {0,1,(per-method count)}.
// This produces accurate results if in fact there is only
// one hot trap site, but begins to get fuzzy if there are
// many sites. For example, if there are ten sites each
// trapping two or more times, they each get the blame for
// all of their traps.
make_not_entrant = true;
}
// Detect repeated recompilation at the same BCI, and enforce a limit.
if (make_not_entrant && maybe_prior_recompile) {
// More than one recompile at this point.
}
} else {
// For reasons which are not recorded per-bytecode, we simply
// force recompiles unconditionally.
// (Note that PerMethodRecompilationCutoff is enforced elsewhere.)
make_not_entrant = true;
}
// Go back to the compiler if there are too many traps in this method.
// If there are too many traps in this method, force a recompile.
// This will allow the compiler to see the limit overflow, and
// take corrective action, if possible.
// (This condition is an unlikely backstop only, because the
// PerBytecodeTrapLimit is more likely to take effect first,
// if it is applicable.)
make_not_entrant = true;
}
// Here's more hysteresis: If there has been a recompile at
// this trap point already, run the method in the interpreter
// for a while to exercise it more thoroughly.
reprofile = true;
}
}
// Take requested actions on the method:
// Recompile
if (make_not_entrant) {
if (!nm->make_not_entrant()) {
return; // the call did not change nmethod's state
}
// Record the recompilation event, if any.
}
}
if (inc_recompile_count) {
// Give up on the method containing the bad BCI.
make_not_compilable = true;
} else {
trap_method->set_not_compilable(CompLevel_full_optimization, true, "overflow_recompile_count > PerBytecodeRecompilationCutoff");
// But give grace to the enclosing nm->method().
}
}
}
// Reprofile
if (reprofile) {
}
// Give up compiling
}
} // Free marked resources
}
bool create_if_missing) {
// Build an MDO. Ignore errors like OutOfMemory;
// that simply means we won't have an MDO to update.
if (HAS_PENDING_EXCEPTION) {
assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOM error here");
}
mdo = m()->method_data();
}
return mdo;
}
int trap_bci,
//outputs:
bool& ret_maybe_prior_trap,
bool& ret_maybe_prior_recompile) {
// If the runtime cannot find a place to store trap history,
// it is estimated based on the general condition of the method.
// If the method has ever been recompiled, or has ever incurred
// a trap with the present reason , then this BCI is assumed
// (pessimistically) to be the culprit.
// For reasons which are recorded per bytecode, we check per-BCI data.
if (per_bc_reason != Reason_none) {
// Find the profile data for this BCI. If there isn't one,
// try to allocate one from the MDO's set of spares.
// This will let us detect a repeated trap at this point.
// Query the trap state of this profile datum.
maybe_prior_trap = false;
if (!trap_state_is_recompiled(tstate0))
maybe_prior_recompile = false;
// Update the trap state of this profile datum.
// Record the reason.
// Store the updated state on the MDO, for next time.
} else {
// Missing MDP? Leave a small complaint in the log.
}
}
}
// Return results:
return pdata;
}
void
Deoptimization::update_method_data_from_interpreter(methodDataHandle trap_mdo, int trap_bci, int reason) {
// Ignored outputs:
bool ignore_maybe_prior_trap;
}
// Still in Java no safepoints
{
// This enters VM and may safepoint
}
return fetch_unroll_info_helper(thread);
}
// Local derived constants.
// Further breakdown of DataLayout::trap_state, as promised by DataLayout.
//---------------------------trap_state_reason---------------------------------
// This assert provides the link between the width of DataLayout::trap_bits
// and the encoding of "recorded" reasons. It ensures there are enough
// bits to store all needed reasons in the per-BCI MDO profile.
if (trap_state == DS_REASON_MASK) {
return Reason_many;
} else {
return (DeoptReason)trap_state;
}
}
//-------------------------trap_state_has_reason-------------------------------
if (trap_state == DS_REASON_MASK) {
return -1; // true, unspecifically (bottom of state lattice)
} else if (trap_state == reason) {
return 1; // true, definitely
} else if (trap_state == 0) {
return 0; // false, definitely (top of state lattice)
} else {
return 0; // false, definitely
}
}
//-------------------------trap_state_add_reason-------------------------------
assert(reason_is_recorded_per_bytecode((DeoptReason)reason) || reason == Reason_many, "valid reason");
if (trap_state == DS_REASON_MASK) {
} else if (trap_state == reason) {
} else if (trap_state == 0) {
} else {
}
}
//-----------------------trap_state_is_recompiled------------------------------
return (trap_state & DS_RECOMPILE_BIT) != 0;
}
//-----------------------trap_state_set_recompiled-----------------------------
if (z) return trap_state | DS_RECOMPILE_BIT;
else return trap_state & ~DS_RECOMPILE_BIT;
}
//---------------------------format_trap_state---------------------------------
// This is used for debugging and diagnostics, including hotspot.log output.
int trap_state) {
// Re-encode the state from its decoded components.
int decoded_state = 0;
if (recomp_flag)
// If the state re-encodes properly, format it symbolically.
// Because this routine is used for debugging and diagnostics,
// be robust even if the state is a strange value.
if (decoded_state != trap_state) {
// Random buggy state that doesn't decode??
} else {
}
return buf;
}
//--------------------------------statics--------------------------------------
// Note: Keep this in sync. with enum DeoptReason.
"none",
"null_check",
"null_assert",
"range_check",
"class_check",
"array_check",
"intrinsic",
"bimorphic",
"unloaded",
"uninitialized",
"unreached",
"unhandled",
"constraint",
"div0_check",
"age",
"predicate",
"loop_limit_check"
};
// Note: Keep this in sync. with enum DeoptAction.
"none",
"maybe_recompile",
"reinterpret",
"make_not_entrant",
"make_not_compilable"
};
return _trap_reason_name[reason];
return buf;
}
return _trap_action_name[action];
return buf;
}
// This is used for debugging and diagnostics, including hotspot.log output.
int trap_request) {
if (unloaded_class_index < 0) {
} else {
}
return buf;
}
= {0};
enum {
};
// Look for an unused counter, or an exact match to this BC.
// this counter is either free or is already devoted to this BC
}
}
}
if (bc_counter_addr == NULL) {
// Overflow, or no given bytecode.
}
}
return _deoptimization_hist[Reason_none][0][0];
}
return _deoptimization_hist[reason][0][0];
}
if (total != 0) {
// For each non-zero entry in the histogram, print the reason,
// the action, and (if specifically known) the type of bytecode.
if (counter != 0) {
account -= r;
}
}
}
}
if (account != 0) {
}
}
}
#else // COMPILER2 || SHARK
// Stubs for C1 only system.
return false;
}
return "unknown";
}
void Deoptimization::print_statistics() {
// no output
}
void
Deoptimization::update_method_data_from_interpreter(methodDataHandle trap_mdo, int trap_bci, int reason) {
// no udpate
}
return 0;
}
// no update
}
int trap_state) {
return buf;
}
#endif // COMPILER2 || SHARK