/*
* 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 "memory/allocation.hpp"
#include "runtime/frame.inline.hpp"
class ProfileData;
class vframeArray;
class MonitorValue;
class ObjectValue;
friend class VMStructs;
public:
// What condition caused the deoptimization?
enum DeoptReason {
// Next 7 reasons are recorded per bytecode in DataLayout::trap_bits
// Note: Keep this enum in sync. with _trap_reason_name.
// Note: Reason_RECORDED_LIMIT should be < 8 to fit into 3 bits of
// DataLayout::trap_bits. This dependency is enforced indirectly
// via asserts, to avoid excessive direct header-to-header dependencies.
// See Deoptimization::trap_state_reason and class DataLayout.
};
// What action must be taken by the runtime?
enum DeoptAction {
// Note: Keep this enum in sync. with _trap_action_name.
};
enum {
_action_shift = 0,
};
enum UnpackType {
};
// Checks all compiled methods. Invalid methods are deleted and
// corresponding activations are deoptimized.
static int deoptimize_dependents();
// Deoptimizes a frame lazily. nmethod gets patched deopt happens on return to the frame
private:
// Does the actual work for deoptimizing a single frame
// Helper function to revoke biases of all monitors in frame if UseBiasedLocking
// is enabled
// Helper function to revoke biases of all monitors in frames
// executing in a particular CodeBlob if UseBiasedLocking is enabled
#ifdef COMPILER2
// Support for restoring non-escaping objects
static bool realloc_objects(JavaThread* thread, frame* fr, GrowableArray<ScopeValue*>* objects, TRAPS);
static void reassign_type_array_elements(frame* fr, RegisterMap* reg_map, ObjectValue* sv, typeArrayOop obj, BasicType type);
static void reassign_object_array_elements(frame* fr, RegisterMap* reg_map, ObjectValue* sv, objArrayOop obj);
#endif // COMPILER2
public:
static vframeArray* create_vframeArray(JavaThread* thread, frame fr, RegisterMap *reg_map, GrowableArray<compiledVFrame*>* chunk);
// Interface used for unpacking deoptimized frames
// UnrollBlock is returned by fetch_unroll_info() to the deoptimization handler (blob).
// This is only a CheapObj to ease debugging after a deopt failure
private:
// interpreted caller of the deoptimized frame
// The following fields are used as temps during the unpacking phase
// (which is tight on registers, especially on x86). They really ought
// to be PD variables but that involves moving this class into its own
// file to use the pd include mechanism. Maybe in a later cleanup ...
public:
// Constructor
int caller_adjustment,
int number_of_frames,
~UnrollBlock();
// Returns where a register is located.
// Accessors
// Returns the total size of frames
int size_of_frames() const;
// Accessors used by the code generator for the unpack stub.
static int size_of_deoptimized_frame_offset_in_bytes() { return offset_of(UnrollBlock, _size_of_deoptimized_frame); }
static int caller_adjustment_offset_in_bytes() { return offset_of(UnrollBlock, _caller_adjustment); }
static int total_frame_sizes_offset_in_bytes() { return offset_of(UnrollBlock, _total_frame_sizes); }
void print();
};
//** Returns an UnrollBlock continuing information
// how to make room for the resulting interpreter frames.
// Called by assembly stub after execution has returned to
// deoptimized frame.
// @argument thread. Thread where stub_frame resides.
// @see OptoRuntime::deoptimization_fetch_unroll_info_C
//** Unpacks vframeArray onto execution stack
// Called by assembly stub after execution has returned to
// deoptimized frame and after the stack unrolling.
// @argument thread. Thread where stub_frame resides.
// @argument exec_mode. Determines how execution should be continuted in top frame.
// 0 means continue after current byte code
// 1 means exception has happened, handle exception
// 2 means reexecute current bytecode (for uncommon traps).
// @see OptoRuntime::deoptimization_unpack_frames_C
// Return BasicType of call return type, if any
// Cleans up deoptimization bits on thread after unpacking or in the
// case of an exception.
vframeArray * array);
// Restores callee saved values from deoptimized frame into oldest interpreter frame
// so caller of the deoptimized frame will get back the values it expects.
//** Performs an uncommon trap for compiled code.
// The top most compiler frame is converted into interpreter frames
// Helper routine that enters the VM and may block
//** Deoptimizes the frame identified by id.
// Only called from VMDeoptimizeFrame
// @argument thread. Thread where stub_frame resides.
// @argument id. id of frame that should be deoptimized.
// If thread is not the current thread then execute
// VM_DeoptimizeFrame otherwise deoptimize directly.
// Statistics
static void print_statistics();
// How much room to adjust the last frame's SP by, to make space for
// the callee's interpreter frame (which expects locals to be next to
// incoming arguments)
// trap_request codes
if (trap_request < 0)
return (DeoptReason)
else
// standard reason for unloaded CP entry
return Reason_unloaded;
}
if (trap_request < 0)
return (DeoptAction)
else
// standard action for unloaded CP entry
return _unloaded_action;
}
if (trap_request < 0)
return -1;
else
return trap_request;
}
int index = -1) {
int trap_request;
if (index != -1)
else
+ ((action) << _action_shift)));
return trap_request;
}
// The trap_state stored in a MDO is decoded here.
// It records two items of information.
// reason: If a deoptimization happened here, what its reason was,
// or if there were multiple deopts with differing reasons.
// recompiled: If a deoptimization here triggered a recompilation.
// Note that not all reasons are recorded per-bci.
static bool trap_state_is_recompiled(int trap_state);
static int trap_state_set_recompiled(int trap_state, bool z);
int trap_state);
}
return reason;
return Reason_null_check; // recorded per BCI as a null check
else
return Reason_none;
}
static const char* trap_reason_name(int reason);
static const char* trap_action_name(int action);
// Format like reason='foo' action='bar' index='123'.
// This is suitable both for XML and for tty output.
int trap_request);
static jint total_deoptimization_count();
// JVMTI PopFrame support
// Preserves incoming arguments to the popped frame when it is
// returning to a deoptimized caller
private:
// Update the mdo's count and per-BCI reason bits, returning previous state:
int trap_bci,
//outputs:
bool& ret_maybe_prior_trap,
bool& ret_maybe_prior_recompile);
// class loading support for uncommon trap
// Note: Histogram array size is 1-2 Kb.
public:
static void update_method_data_from_interpreter(methodDataHandle trap_mdo, int trap_bci, int reason);
};
static bool _is_active;
public:
~DeoptimizationMarker() { _is_active = false; }
};
#endif // SHARE_VM_RUNTIME_DEOPTIMIZATION_HPP