/*
* 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/stackMapTableFormat.hpp"
#include "interpreter/bytecodes.hpp"
#include "memory/oopFactory.hpp"
#include "memory/universe.inline.hpp"
#include "oops/oop.inline.hpp"
#include "runtime/handles.inline.hpp"
#include "runtime/relocator.hpp"
// Encapsulates a code change request. There are 3 types.
//
int _bci;
public:
virtual bool handle_code_change(Relocator *r) = 0;
// type info
virtual bool is_widen() { return false; }
virtual bool is_jump_widen() { return false; }
virtual bool is_switch_pad() { return false; }
// accessors
// debug
virtual void print() = 0;
};
public:
}
// Callback to do instruction
bool is_widen() { return true; }
};
public:
// Callback to do instruction
bool is_jump_widen() { return true; }
// If the bci matches, adjust the delta in the change jump request.
if (_delta > 0)
else
return true;
}
return false;
}
};
int _padding;
bool _is_lookup_switch;
public:
}
// Callback to do instruction
bool handle_code_change(Relocator *r) { return r->handle_switch_pad(bci(), _padding, _is_lookup_switch); };
bool is_switch_pad() { return true; }
void print() { tty->print_cr("ChangeSwitchPad. bci: %d Padding: %d IsLookupSwitch: %d", bci(), _padding, _is_lookup_switch); }
};
//-----------------------------------------------------------------------------------------------------------
// Relocator code
set_method(m);
// Allocate code array and copy bytecodes
if (!expand_code_array(0)) {
// Should have at least MAX_METHOD_LENGTH available or the verifier
// would have failed.
}
}
// size is the new size of the instruction at bci. Hence, if size is less than the current
// instruction sice, we will shrink the code.
if (TraceRelocator) {
_method->print_codes();
}
if (!handle_code_changes()) return methodHandle();
// Construct the new method
code_array(), code_length(),
CHECK_(methodHandle()));
if (TraceRelocator) {
_method->print_codes();
}
return new_method;
}
// Inv: everything is aligned.
if (TraceRelocator) {
}
// Execute operation
if (!ci->handle_code_change(this)) return false;
// Shuffel items up
}
}
return true;
}
switch (bc) {
case Bytecodes::_tableswitch: return false;
default: ShouldNotReachHere();
}
return true; // dummy
}
// We need a special instruction size method, since lookupswitches and tableswitches might not be
// properly alligned during relocation
switch (bc) {
// In the case of switch instructions, see if we have the original
// padding recorded.
case Bytecodes::_tableswitch:
case Bytecodes::_lookupswitch:
case Bytecodes::_fast_linearswitch:
case Bytecodes::_fast_binaryswitch:
{
if (pad == -1) {
return instruction_length_at(bci);
}
// Otherwise, depends on the switch type.
switch (bc) {
case Bytecodes::_tableswitch: {
}
case Bytecodes::_lookupswitch:
case Bytecodes::_fast_linearswitch:
case Bytecodes::_fast_binaryswitch: {
}
default:
}
}
}
return instruction_length_at(bci);
}
// If a change item is recorded for "pc", with type "ct", returns the
// associated padding, else -1.
if (ci->is_switch_pad()) {
}
}
}
return -1;
}
// Push a ChangeJumpWiden if it doesn't already exist on the work queue,
// otherwise adjust the item already there by delta. The calculation for
// new_delta is wrong for this because it uses the offset stored in the
// code stream itself which wasn't fixed when item was pushed on the work queue.
}
}
// The current instruction of "c" is a jump; one of its offset starts
// at "offset" and is a short if "isShort" is "TRUE",
// and an integer otherwise. If the jump crosses "breakPC", change
// the span of the jump by "delta".
int new_delta;
if (bci_delta > 0)
else
} else if (is_short) {
} else {
}
}
}
// Changes all jumps crossing "break_bci" by "delta". May enqueue things
// on "rc->changes"
int bci = 0;
// Now, adjust any affected instructions.
while (bci < code_length()) {
case Bytecodes::_if_icmpeq:
case Bytecodes::_if_icmpne:
case Bytecodes::_if_icmplt:
case Bytecodes::_if_icmpge:
case Bytecodes::_if_icmpgt:
case Bytecodes::_if_icmple:
case Bytecodes::_if_acmpeq:
case Bytecodes::_if_acmpne:
case Bytecodes::_ifnonnull:
break;
break;
case Bytecodes::_tableswitch:
case Bytecodes::_lookupswitch:
case Bytecodes::_fast_linearswitch:
case Bytecodes::_fast_binaryswitch: {
// Do we need to check the padding?
if (recPad == -1) {
}
}
}
// Then the rest, which depend on the kind of switch.
switch (bc) {
case Bytecodes::_tableswitch: {
// We cannot use the Bytecode_tableswitch abstraction, since the padding might not be correct.
for (int k = 0; k < n; k++) {
}
// Special next-bci calculation here...
continue;
}
case Bytecodes::_lookupswitch:
case Bytecodes::_fast_linearswitch:
case Bytecodes::_fast_binaryswitch: {
// We cannot use the Bytecode_lookupswitch abstraction, since the padding might not be correct.
for (int k = 0; k < npairs; k++) {
}
/* Special next-bci calculation here... */
continue;
}
default:
}
}
default:
break;
}
}
}
// The width of instruction at "pc" is changing by "delta". Adjust the
// exception table, if any, of "rc->mb".
}
}
}
// The width of instruction at "bci" is changing by "delta". Adjust the line number table.
if (method()->has_linenumber_table()) {
}
}
}
// The width of instruction at "bci" is changing by "delta". Adjust the local variable table.
if (localvariable_table_length > 0) {
for (int i = 0; i < localvariable_table_length; i++) {
if (current_bci > bci) {
} else {
}
}
}
}
}
// Create a new array, copying the src array but adding a hole at
// the specified location
return dst;
}
// The width of instruction at "bci" is changing by "delta". Adjust the stack
// map frames.
if (method()->has_stackmap_table()) {
// The data in the array is a classfile representation of the stackmap table
for (int i = 0; i < count; ++i) {
bci_iter += offset_delta;
} else {
"Frame must be one of the compressed forms");
// The new delta exceeds the capacity of the 'same_frame' or
// 'same_frame_1_stack_item_frame' frame types. We need to
// convert these frames to the extended versions, but the extended
// version is bigger and requires more room. So we allocate a
// new array and copy the data, being sure to leave u2-sized hole
// right after the 'frame_type' for the new offset field.
//
// We can safely ignore the reverse situation as a small delta
// can still be used in an extended version of the frame.
return; // out-of-memory?
}
// Now convert the frames in place
if (frame->is_same_frame()) {
} else {
// the verification_info_type should already be at the right spot
}
}
offset_adjusted = true; // needs to be done only once, since subsequent
// values are offsets from the current
}
// The stack map frame may contain verification types, if so we need to
// check and update any Uninitialized type's bci (no matter where it is).
for (int i = 0; i < number_of_types; ++i) {
}
}
// Full frame has stack values too
for (int i = 0; i < number_of_types; ++i) {
}
}
}
}
}
}
if (length > MAX_METHOD_LENGTH) {
} else {
return false;
}
}
if (!new_code_array) return false;
// Expanding current array
if (code_array() != NULL) {
} else {
// Initial copy. Copy directly from methodOop
}
return true;
}
// The instruction at "bci", whose size is "ilen", is changing size by
// "delta". Reallocate, move code, recalculate jumps, and enqueue
// change items as necessary.
// Expand allocated code space, if necessary.
if (!expand_code_array(delta)) {
return false;
}
}
// We require 4-byte alignment of code arrays.
// Change jumps before doing the copying; this routine requires aligned switches.
// In case we have shrunken a tableswitch/lookupswitch statement, we store the last
// bytes that get overwritten. We have to copy the bytes after the change_jumps method
// has been called, since it is likly to update last offset in a tableswitch/lookupswitch
if (delta < 0) {
}
// Also adjust exception tables...
// Line number tables...
// And local variable table...
// Adjust stack maps
// Relocate the pending change stack...
}
// Notify any listeners about code relocation
return true;
}
// relocate a general instruction. Called by ChangeWiden class
return false;
// Insert new bytecode(s)
for(int k = 0; k < new_ilen; k++) {
}
return true;
}
// handle jump_widen instruction. Called be ChangeJumpWiden class
switch (bc) {
case Bytecodes::_if_icmpeq:
case Bytecodes::_if_icmpne:
case Bytecodes::_if_icmplt:
case Bytecodes::_if_icmpge:
case Bytecodes::_if_icmpgt:
case Bytecodes::_if_icmple:
case Bytecodes::_if_acmpeq:
case Bytecodes::_if_acmpne:
case Bytecodes::_ifnonnull: {
// If 'if' points to the next bytecode after goto, it's already handled.
// it shouldn't be.
// Convert to 0 if <cond> goto 6
// 3 _goto 11
// 6 _goto_w <wide delta offset>
// 11 <else code>
// if bytecode points to goto_w instruction
// goto around
// goto_w <wide delta>
if (delta > 0) {
} else {
}
break;
}
else
// If it's a forward jump, add 2 for the widening.
break;
default: ShouldNotReachHere();
}
return true;
}
if (pad_delta != 0) {
int len;
if (!is_lookup_switch) {
} else {
}
// Because "relocateCode" does a "changeJumps" loop,
// which parses instructions to determine their length,
// we need to call that before messing with the current
// instruction. Since it may also overwrite the current
// instruction when moving down, remember the possibly
// overwritten part.
// Move the code following the instruction...
if (pad_delta < 0) {
// Move the shrunken instruction down.
_overwrite, -pad_delta);
} else {
// Move the expanded instruction up.
len * 4);
}
}
return true;
}