/* * Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2016, 2022 SAP SE. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * 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. *
*/
// consider stack guards when trying to determine "safe" stack pointers // sp must be within the usable part of the stack (not in guards) if (!thread->is_in_usable_stack(sp)) { returnfalse;
}
// Unextended sp must be within the stack if (!thread->is_in_full_stack_checked(unextended_sp)) { returnfalse;
}
// An fp must be within the stack and above (but not equal) sp. bool fp_safe = thread->is_in_stack_range_excl(fp, sp); // An interpreter fp must be fp_safe. // Moreover, it must be at a distance at least the size of the z_ijava_state structure. bool fp_interp_safe = fp_safe && ((fp - sp) >= z_ijava_state_size);
// We know sp/unextended_sp are safe, only fp is questionable here
// If the current frame is known to the code cache then we can attempt to // construct the sender and do some validation of it. This goes a long way // toward eliminating issues when we get in frame construction code
if (_cb != NULL ) {
// First check if the frame is complete and the test is reliable. // Unfortunately we can only check frame completeness for runtime stubs. // Other generic buffer blobs are more problematic so we just assume they are OK. // Adapter blobs never have a complete frame and are never OK. // nmethods should be OK on s390. if (!_cb->is_frame_complete_at(_pc)) { if (_cb->is_adapter_blob() || _cb->is_runtime_stub()) { returnfalse;
}
}
// Could just be some random pointer within the codeBlob. if (!_cb->code_contains(_pc)) { returnfalse;
}
// Entry frame checks if (is_entry_frame()) { // An entry frame must have a valid fp. return fp_safe && is_entry_frame_valid(thread);
}
if (is_interpreted_frame() && !fp_interp_safe) { returnfalse;
}
// At this point, there still is a chance that fp_safe is false. // In particular, (fp == NULL) might be true. So let's check and // bail out before we actually dereference from fp. if (!fp_safe) { returnfalse;
}
// We must always be able to find a recognizable pc.
CodeBlob* sender_blob = CodeCache::find_blob(sender_pc); if (sender_blob == NULL) { returnfalse;
}
// It should be safe to construct the sender though it might not be valid.
frame sender(sender_sp, sender_pc);
// Do we have a valid fp?
address sender_fp = (address) sender.fp();
// sender_fp must be within the stack and above (but not // equal) current frame's fp. if (!thread->is_in_stack_range_excl(sender_fp, fp)) { returnfalse;
}
// If the potential sender is the interpreter then we can do some more checking. if (Interpreter::contains(sender_pc)) { return sender.is_interpreted_frame_valid(thread);
}
// Could just be some random pointer within the codeBlob. if (!sender.cb()->code_contains(sender_pc)) { returnfalse;
}
// We should never be able to see an adapter if the current frame is something from code cache. if (sender_blob->is_adapter_blob()) { returnfalse;
}
if (sender.is_entry_frame()) { return sender.is_entry_frame_valid(thread);
}
// Frame size is always greater than zero. If the sender frame size is zero or less, // something is really weird and we better give up. if (sender_blob->frame_size() <= 0) { returnfalse;
}
returntrue;
}
// Must be native-compiled frame. Since sender will try and use fp to find // linkages it must be safe
frame frame::sender_for_entry_frame(RegisterMap *map) const {
assert(map != NULL, "map must be set"); // Java frame called from C. Skip all C frames and return top C // frame of that chunk as the sender.
JavaFrameAnchor* jfa = entry_frame_call_wrapper()->anchor();
assert(!entry_frame_is_first(), "next Java sp must be non zero");
assert(jfa->last_Java_sp() > _sp, "must be above this frame on stack");
map->clear();
assert(map->include_argument_oops(), "should be set by clear");
if (jfa->last_Java_pc() != NULL) {
frame fr(jfa->last_Java_sp(), jfa->last_Java_pc()); return fr;
} // Last_java_pc is not set if we come here from compiled code.
frame fr(jfa->last_Java_sp()); return fr;
}
bool frame::is_interpreted_frame_valid(JavaThread* thread) const {
assert(is_interpreted_frame(), "Not an interpreted frame"); // These are reasonable sanity checks if (fp() == 0 || (intptr_t(fp()) & (wordSize-1)) != 0) { returnfalse;
} if (sp() == 0 || (intptr_t(sp()) & (wordSize-1)) != 0) { returnfalse;
} int min_frame_slots = (z_abi_16_size + z_ijava_state_size) / sizeof(intptr_t); if (fp() - min_frame_slots < sp()) { returnfalse;
} // These are hacks to keep us out of trouble. // The problem with these is that they mask other problems if (fp() <= sp()) { // this attempts to deal with unsigned comparison above returnfalse;
}
// do some validation of frame elements
// first the method // Need to use "unchecked" versions to avoid "z_istate_magic_number" assertion.
Method* m = (Method*)(ijava_state_unchecked()->method);
// validate the method we'd find in this potential sender if (!Method::is_valid_method(m)) returnfalse;
// stack frames shouldn't be much larger than max_stack elements // this test requires the use of unextended_sp which is the sp as seen by // the current frame, and not sp which is the "raw" pc which could point // further because of local variables of the callee method inserted after // method arguments if (fp() - unextended_sp() > 1024 + m->max_stack()*Interpreter::stackElementSize) { returnfalse;
}
switch (type) { case T_OBJECT: case T_ARRAY: {
*oop_result = cast_to_oop((void*) ijava_state()->oop_tmp); break;
} // We use std/stfd to store the values. case T_BOOLEAN : value_result->z = (jboolean) *(unsignedlong*)lresult; break; case T_INT : value_result->i = (jint) *(long*)lresult; break; case T_CHAR : value_result->c = (jchar) *(unsignedlong*)lresult; break; case T_SHORT : value_result->s = (jshort) *(long*)lresult; break; case T_BYTE : value_result->z = (jbyte) *(long*)lresult; break; case T_LONG : value_result->j = (jlong) *(long*)lresult; break; case T_FLOAT : value_result->f = (jfloat) *(float*)fresult; break; case T_DOUBLE : value_result->d = (jdouble) *(double*)fresult; break; case T_VOID : break; // Nothing to do. default : ShouldNotReachHere();
}
} else {
intptr_t* tos_addr = interpreter_frame_tos_address(); switch (type) { case T_OBJECT: case T_ARRAY: {
oop obj = *(oop*)tos_addr;
assert(Universe::is_in_heap_or_null(obj), "sanity check");
*oop_result = obj; break;
} case T_BOOLEAN : value_result->z = (jboolean) *(jint*)tos_addr; break; case T_BYTE : value_result->b = (jbyte) *(jint*)tos_addr; break; case T_CHAR : value_result->c = (jchar) *(jint*)tos_addr; break; case T_SHORT : value_result->s = (jshort) *(jint*)tos_addr; break; case T_INT : value_result->i = *(jint*)tos_addr; break; case T_LONG : value_result->j = *(jlong*)tos_addr; break; case T_FLOAT : value_result->f = *(jfloat*)tos_addr; break; case T_DOUBLE : value_result->d = *(jdouble*)tos_addr; break; case T_VOID : break; // Nothing to do. default : ShouldNotReachHere();
}
}
return type;
}
// Dump all frames starting a given C stack-pointer. // Use max_frames to limit the number of traced frames. void frame::back_trace(outputStream* st, intptr_t* start_sp, intptr_t* top_pc, unsignedlong flags, int max_frames) {
staticchar buf[ 150 ];
bool print_outgoing_arguments = flags & 0x1; bool print_istate_pointers = flags & 0x2; int num = 0;
intptr_t* current_sp = (intptr_t*) start_sp; int last_num_jargs = 0; int frame_type = 0; int last_frame_type = 0;
case 4: // named frames
{
st->print("%s ", type_name);
// name if (function_name)
st->print("%s", function_name);
} break;
default: break;
}
st->cr();
st->flush();
current_sp = current_fp;
last_frame_type = frame_type;
num++; // Check for maximum # of frames, and stop when reached. if (max_frames > 0 && --max_frames == 0) break;
}
}
// Convenience function for calls from the debugger.
// Function for tracing a limited number of frames. // Use this one if you only need to see the "top of stack" frames. extern"C"void bt_max(intptr_t *start_sp, intptr_t *top_pc, int max_frames) {
frame::back_trace(tty, start_sp, top_pc, 0, max_frames);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.