Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/runtime/frame.cpp
32285 views
/*1* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "compiler/abstractCompiler.hpp"26#include "compiler/disassembler.hpp"27#include "gc_interface/collectedHeap.inline.hpp"28#include "interpreter/interpreter.hpp"29#include "interpreter/oopMapCache.hpp"30#include "memory/resourceArea.hpp"31#include "memory/universe.inline.hpp"32#include "oops/markOop.hpp"33#include "oops/methodData.hpp"34#include "oops/method.hpp"35#include "oops/oop.inline.hpp"36#include "oops/oop.inline2.hpp"37#include "prims/methodHandles.hpp"38#include "runtime/frame.inline.hpp"39#include "runtime/handles.inline.hpp"40#include "runtime/javaCalls.hpp"41#include "runtime/monitorChunk.hpp"42#include "runtime/sharedRuntime.hpp"43#include "runtime/signature.hpp"44#include "runtime/stubCodeGenerator.hpp"45#include "runtime/stubRoutines.hpp"46#include "utilities/decoder.hpp"4748#ifdef TARGET_ARCH_x8649# include "nativeInst_x86.hpp"50#endif51#ifdef TARGET_ARCH_aarch3252# include "nativeInst_aarch32.hpp"53#endif54#ifdef TARGET_ARCH_aarch6455# include "nativeInst_aarch64.hpp"56#endif57#ifdef TARGET_ARCH_sparc58# include "nativeInst_sparc.hpp"59#endif60#ifdef TARGET_ARCH_zero61# include "nativeInst_zero.hpp"62#endif63#ifdef TARGET_ARCH_arm64# include "nativeInst_arm.hpp"65#endif66#ifdef TARGET_ARCH_ppc67# include "nativeInst_ppc.hpp"68#endif6970PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC7172RegisterMap::RegisterMap(JavaThread *thread, bool update_map) {73_thread = thread;74_update_map = update_map;75clear();76debug_only(_update_for_id = NULL;)77#ifndef PRODUCT78for (int i = 0; i < reg_count ; i++ ) _location[i] = NULL;79#endif /* PRODUCT */80}8182RegisterMap::RegisterMap(const RegisterMap* map) {83assert(map != this, "bad initialization parameter");84assert(map != NULL, "RegisterMap must be present");85_thread = map->thread();86_update_map = map->update_map();87_include_argument_oops = map->include_argument_oops();88debug_only(_update_for_id = map->_update_for_id;)89pd_initialize_from(map);90if (update_map()) {91for(int i = 0; i < location_valid_size; i++) {92LocationValidType bits = !update_map() ? 0 : map->_location_valid[i];93_location_valid[i] = bits;94// for whichever bits are set, pull in the corresponding map->_location95int j = i*location_valid_type_size;96while (bits != 0) {97if ((bits & 1) != 0) {98assert(0 <= j && j < reg_count, "range check");99_location[j] = map->_location[j];100}101bits >>= 1;102j += 1;103}104}105}106}107108void RegisterMap::clear() {109set_include_argument_oops(true);110if (_update_map) {111for(int i = 0; i < location_valid_size; i++) {112_location_valid[i] = 0;113}114pd_clear();115} else {116pd_initialize();117}118}119120#ifndef PRODUCT121122void RegisterMap::print_on(outputStream* st) const {123st->print_cr("Register map");124for(int i = 0; i < reg_count; i++) {125126VMReg r = VMRegImpl::as_VMReg(i);127intptr_t* src = (intptr_t*) location(r);128if (src != NULL) {129130r->print_on(st);131st->print(" [" INTPTR_FORMAT "] = ", src);132if (((uintptr_t)src & (sizeof(*src)-1)) != 0) {133st->print_cr("<misaligned>");134} else {135st->print_cr(INTPTR_FORMAT, *src);136}137}138}139}140141void RegisterMap::print() const {142print_on(tty);143}144145#endif146// This returns the pc that if you were in the debugger you'd see. Not147// the idealized value in the frame object. This undoes the magic conversion148// that happens for deoptimized frames. In addition it makes the value the149// hardware would want to see in the native frame. The only user (at this point)150// is deoptimization. It likely no one else should ever use it.151152address frame::raw_pc() const {153if (is_deoptimized_frame()) {154nmethod* nm = cb()->as_nmethod_or_null();155if (nm->is_method_handle_return(pc()))156return nm->deopt_mh_handler_begin() - pc_return_offset;157else158return nm->deopt_handler_begin() - pc_return_offset;159} else {160return (pc() - pc_return_offset);161}162}163164// Change the pc in a frame object. This does not change the actual pc in165// actual frame. To do that use patch_pc.166//167void frame::set_pc(address newpc ) {168#ifdef ASSERT169if (_cb != NULL && _cb->is_nmethod()) {170assert(!((nmethod*)_cb)->is_deopt_pc(_pc), "invariant violation");171}172#endif // ASSERT173174// Unsafe to use the is_deoptimzed tester after changing pc175_deopt_state = unknown;176_pc = newpc;177_cb = CodeCache::find_blob_unsafe(_pc);178179}180181// type testers182bool frame::is_ignored_frame() const {183return false; // FIXME: some LambdaForm frames should be ignored184}185bool frame::is_deoptimized_frame() const {186assert(_deopt_state != unknown, "not answerable");187return _deopt_state == is_deoptimized;188}189190bool frame::is_native_frame() const {191return (_cb != NULL &&192_cb->is_nmethod() &&193((nmethod*)_cb)->is_native_method());194}195196bool frame::is_java_frame() const {197if (is_interpreted_frame()) return true;198if (is_compiled_frame()) return true;199return false;200}201202203bool frame::is_compiled_frame() const {204if (_cb != NULL &&205_cb->is_nmethod() &&206((nmethod*)_cb)->is_java_method()) {207return true;208}209return false;210}211212213bool frame::is_runtime_frame() const {214return (_cb != NULL && _cb->is_runtime_stub());215}216217bool frame::is_safepoint_blob_frame() const {218return (_cb != NULL && _cb->is_safepoint_stub());219}220221// testers222223bool frame::is_first_java_frame() const {224RegisterMap map(JavaThread::current(), false); // No update225frame s;226for (s = sender(&map); !(s.is_java_frame() || s.is_first_frame()); s = s.sender(&map));227return s.is_first_frame();228}229230231bool frame::entry_frame_is_first() const {232return entry_frame_call_wrapper()->is_first_frame();233}234235JavaCallWrapper* frame::entry_frame_call_wrapper_if_safe(JavaThread* thread) const {236JavaCallWrapper** jcw = entry_frame_call_wrapper_addr();237address addr = (address) jcw;238239// addr must be within the usable part of the stack240if (thread->is_in_usable_stack(addr)) {241return *jcw;242}243244return NULL;245}246247bool frame::is_entry_frame_valid(JavaThread* thread) const {248// Validate the JavaCallWrapper an entry frame must have249address jcw = (address)entry_frame_call_wrapper();250bool jcw_safe = (jcw < thread->stack_base()) && (jcw > (address)fp()); // less than stack base251if (!jcw_safe) {252return false;253}254255// Validate sp saved in the java frame anchor256JavaFrameAnchor* jfa = entry_frame_call_wrapper()->anchor();257return (jfa->last_Java_sp() > sp());258}259260bool frame::should_be_deoptimized() const {261if (_deopt_state == is_deoptimized ||262!is_compiled_frame() ) return false;263assert(_cb != NULL && _cb->is_nmethod(), "must be an nmethod");264nmethod* nm = (nmethod *)_cb;265if (TraceDependencies) {266tty->print("checking (%s) ", nm->is_marked_for_deoptimization() ? "true" : "false");267nm->print_value_on(tty);268tty->cr();269}270271if( !nm->is_marked_for_deoptimization() )272return false;273274// If at the return point, then the frame has already been popped, and275// only the return needs to be executed. Don't deoptimize here.276return !nm->is_at_poll_return(pc());277}278279bool frame::can_be_deoptimized() const {280if (!is_compiled_frame()) return false;281nmethod* nm = (nmethod*)_cb;282283if( !nm->can_be_deoptimized() )284return false;285286return !nm->is_at_poll_return(pc());287}288289void frame::deoptimize(JavaThread* thread) {290// Schedule deoptimization of an nmethod activation with this frame.291assert(_cb != NULL && _cb->is_nmethod(), "must be");292nmethod* nm = (nmethod*)_cb;293294// This is a fix for register window patching race295if (NeedsDeoptSuspend && Thread::current() != thread) {296assert(SafepointSynchronize::is_at_safepoint(),297"patching other threads for deopt may only occur at a safepoint");298299// It is possible especially with DeoptimizeALot/DeoptimizeRandom that300// we could see the frame again and ask for it to be deoptimized since301// it might move for a long time. That is harmless and we just ignore it.302if (id() == thread->must_deopt_id()) {303assert(thread->is_deopt_suspend(), "lost suspension");304return;305}306307// We are at a safepoint so the target thread can only be308// in 4 states:309// blocked - no problem310// blocked_trans - no problem (i.e. could have woken up from blocked311// during a safepoint).312// native - register window pc patching race313// native_trans - momentary state314//315// We could just wait out a thread in native_trans to block.316// Then we'd have all the issues that the safepoint code has as to317// whether to spin or block. It isn't worth it. Just treat it like318// native and be done with it.319//320// Examine the state of the thread at the start of safepoint since321// threads that were in native at the start of the safepoint could322// come to a halt during the safepoint, changing the current value323// of the safepoint_state.324JavaThreadState state = thread->safepoint_state()->orig_thread_state();325if (state == _thread_in_native || state == _thread_in_native_trans) {326// Since we are at a safepoint the target thread will stop itself327// before it can return to java as long as we remain at the safepoint.328// Therefore we can put an additional request for the thread to stop329// no matter what no (like a suspend). This will cause the thread330// to notice it needs to do the deopt on its own once it leaves native.331//332// The only reason we must do this is because on machine with register333// windows we have a race with patching the return address and the334// window coming live as the thread returns to the Java code (but still335// in native mode) and then blocks. It is only this top most frame336// that is at risk. So in truth we could add an additional check to337// see if this frame is one that is at risk.338RegisterMap map(thread, false);339frame at_risk = thread->last_frame().sender(&map);340if (id() == at_risk.id()) {341thread->set_must_deopt_id(id());342thread->set_deopt_suspend();343return;344}345}346} // NeedsDeoptSuspend347348349// If the call site is a MethodHandle call site use the MH deopt350// handler.351address deopt = nm->is_method_handle_return(pc()) ?352nm->deopt_mh_handler_begin() :353nm->deopt_handler_begin();354355// Save the original pc before we patch in the new one356nm->set_original_pc(this, pc());357patch_pc(thread, deopt);358359#ifdef ASSERT360{361RegisterMap map(thread, false);362frame check = thread->last_frame();363while (id() != check.id()) {364check = check.sender(&map);365}366assert(check.is_deoptimized_frame(), "missed deopt");367}368#endif // ASSERT369}370371frame frame::java_sender() const {372RegisterMap map(JavaThread::current(), false);373frame s;374for (s = sender(&map); !(s.is_java_frame() || s.is_first_frame()); s = s.sender(&map)) ;375guarantee(s.is_java_frame(), "tried to get caller of first java frame");376return s;377}378379frame frame::real_sender(RegisterMap* map) const {380frame result = sender(map);381while (result.is_runtime_frame() ||382result.is_ignored_frame()) {383result = result.sender(map);384}385return result;386}387388// Note: called by profiler - NOT for current thread389frame frame::profile_find_Java_sender_frame(JavaThread *thread) {390// If we don't recognize this frame, walk back up the stack until we do391RegisterMap map(thread, false);392frame first_java_frame = frame();393394// Find the first Java frame on the stack starting with input frame395if (is_java_frame()) {396// top frame is compiled frame or deoptimized frame397first_java_frame = *this;398} else if (safe_for_sender(thread)) {399for (frame sender_frame = sender(&map);400sender_frame.safe_for_sender(thread) && !sender_frame.is_first_frame();401sender_frame = sender_frame.sender(&map)) {402if (sender_frame.is_java_frame()) {403first_java_frame = sender_frame;404break;405}406}407}408return first_java_frame;409}410411// Interpreter frames412413414void frame::interpreter_frame_set_locals(intptr_t* locs) {415assert(is_interpreted_frame(), "Not an interpreted frame");416*interpreter_frame_locals_addr() = locs;417}418419Method* frame::interpreter_frame_method() const {420assert(is_interpreted_frame(), "interpreted frame expected");421Method* m = *interpreter_frame_method_addr();422assert(m->is_method(), "not a Method*");423return m;424}425426void frame::interpreter_frame_set_method(Method* method) {427assert(is_interpreted_frame(), "interpreted frame expected");428*interpreter_frame_method_addr() = method;429}430431void frame::interpreter_frame_set_bcx(intptr_t bcx) {432assert(is_interpreted_frame(), "Not an interpreted frame");433if (ProfileInterpreter) {434bool formerly_bci = is_bci(interpreter_frame_bcx());435bool is_now_bci = is_bci(bcx);436*interpreter_frame_bcx_addr() = bcx;437438intptr_t mdx = interpreter_frame_mdx();439440if (mdx != 0) {441if (formerly_bci) {442if (!is_now_bci) {443// The bcx was just converted from bci to bcp.444// Convert the mdx in parallel.445MethodData* mdo = interpreter_frame_method()->method_data();446assert(mdo != NULL, "");447int mdi = mdx - 1; // We distinguish valid mdi from zero by adding one.448address mdp = mdo->di_to_dp(mdi);449interpreter_frame_set_mdx((intptr_t)mdp);450}451} else {452if (is_now_bci) {453// The bcx was just converted from bcp to bci.454// Convert the mdx in parallel.455MethodData* mdo = interpreter_frame_method()->method_data();456assert(mdo != NULL, "");457int mdi = mdo->dp_to_di((address)mdx);458interpreter_frame_set_mdx((intptr_t)mdi + 1); // distinguish valid from 0.459}460}461}462} else {463*interpreter_frame_bcx_addr() = bcx;464}465}466467jint frame::interpreter_frame_bci() const {468assert(is_interpreted_frame(), "interpreted frame expected");469intptr_t bcx = interpreter_frame_bcx();470return is_bci(bcx) ? bcx : interpreter_frame_method()->bci_from((address)bcx);471}472473void frame::interpreter_frame_set_bci(jint bci) {474assert(is_interpreted_frame(), "interpreted frame expected");475assert(!is_bci(interpreter_frame_bcx()), "should not set bci during GC");476interpreter_frame_set_bcx((intptr_t)interpreter_frame_method()->bcp_from(bci));477}478479address frame::interpreter_frame_bcp() const {480assert(is_interpreted_frame(), "interpreted frame expected");481intptr_t bcx = interpreter_frame_bcx();482return is_bci(bcx) ? interpreter_frame_method()->bcp_from(bcx) : (address)bcx;483}484485void frame::interpreter_frame_set_bcp(address bcp) {486assert(is_interpreted_frame(), "interpreted frame expected");487assert(!is_bci(interpreter_frame_bcx()), "should not set bcp during GC");488interpreter_frame_set_bcx((intptr_t)bcp);489}490491void frame::interpreter_frame_set_mdx(intptr_t mdx) {492assert(is_interpreted_frame(), "Not an interpreted frame");493assert(ProfileInterpreter, "must be profiling interpreter");494*interpreter_frame_mdx_addr() = mdx;495}496497address frame::interpreter_frame_mdp() const {498assert(ProfileInterpreter, "must be profiling interpreter");499assert(is_interpreted_frame(), "interpreted frame expected");500intptr_t bcx = interpreter_frame_bcx();501intptr_t mdx = interpreter_frame_mdx();502503assert(!is_bci(bcx), "should not access mdp during GC");504return (address)mdx;505}506507void frame::interpreter_frame_set_mdp(address mdp) {508assert(is_interpreted_frame(), "interpreted frame expected");509if (mdp == NULL) {510// Always allow the mdp to be cleared.511interpreter_frame_set_mdx((intptr_t)mdp);512}513intptr_t bcx = interpreter_frame_bcx();514assert(!is_bci(bcx), "should not set mdp during GC");515interpreter_frame_set_mdx((intptr_t)mdp);516}517518BasicObjectLock* frame::next_monitor_in_interpreter_frame(BasicObjectLock* current) const {519assert(is_interpreted_frame(), "Not an interpreted frame");520#ifdef ASSERT521interpreter_frame_verify_monitor(current);522#endif523BasicObjectLock* next = (BasicObjectLock*) (((intptr_t*) current) + interpreter_frame_monitor_size());524return next;525}526527BasicObjectLock* frame::previous_monitor_in_interpreter_frame(BasicObjectLock* current) const {528assert(is_interpreted_frame(), "Not an interpreted frame");529#ifdef ASSERT530// // This verification needs to be checked before being enabled531// interpreter_frame_verify_monitor(current);532#endif533BasicObjectLock* previous = (BasicObjectLock*) (((intptr_t*) current) - interpreter_frame_monitor_size());534return previous;535}536537// Interpreter locals and expression stack locations.538539intptr_t* frame::interpreter_frame_local_at(int index) const {540const int n = Interpreter::local_offset_in_bytes(index)/wordSize;541return &((*interpreter_frame_locals_addr())[n]);542}543544intptr_t* frame::interpreter_frame_expression_stack_at(jint offset) const {545const int i = offset * interpreter_frame_expression_stack_direction();546const int n = i * Interpreter::stackElementWords;547return &(interpreter_frame_expression_stack()[n]);548}549550jint frame::interpreter_frame_expression_stack_size() const {551// Number of elements on the interpreter expression stack552// Callers should span by stackElementWords553int element_size = Interpreter::stackElementWords;554size_t stack_size = 0;555if (frame::interpreter_frame_expression_stack_direction() < 0) {556stack_size = (interpreter_frame_expression_stack() -557interpreter_frame_tos_address() + 1)/element_size;558} else {559stack_size = (interpreter_frame_tos_address() -560interpreter_frame_expression_stack() + 1)/element_size;561}562assert( stack_size <= (size_t)max_jint, "stack size too big");563return ((jint)stack_size);564}565566567// (frame::interpreter_frame_sender_sp accessor is in frame_<arch>.cpp)568569const char* frame::print_name() const {570if (is_native_frame()) return "Native";571if (is_interpreted_frame()) return "Interpreted";572if (is_compiled_frame()) {573if (is_deoptimized_frame()) return "Deoptimized";574return "Compiled";575}576if (sp() == NULL) return "Empty";577return "C";578}579580void frame::print_value_on(outputStream* st, JavaThread *thread) const {581NOT_PRODUCT(address begin = pc()-40;)582NOT_PRODUCT(address end = NULL;)583584st->print("%s frame (sp=" INTPTR_FORMAT " unextended sp=" INTPTR_FORMAT, print_name(), sp(), unextended_sp());585if (sp() != NULL)586st->print(", fp=" INTPTR_FORMAT ", real_fp=" INTPTR_FORMAT ", pc=" INTPTR_FORMAT, fp(), real_fp(), pc());587588if (StubRoutines::contains(pc())) {589st->print_cr(")");590st->print("(");591StubCodeDesc* desc = StubCodeDesc::desc_for(pc());592st->print("~Stub::%s", desc->name());593NOT_PRODUCT(begin = desc->begin(); end = desc->end();)594} else if (Interpreter::contains(pc())) {595st->print_cr(")");596st->print("(");597InterpreterCodelet* desc = Interpreter::codelet_containing(pc());598if (desc != NULL) {599st->print("~");600desc->print_on(st);601NOT_PRODUCT(begin = desc->code_begin(); end = desc->code_end();)602} else {603st->print("~interpreter");604}605}606st->print_cr(")");607608if (_cb != NULL) {609st->print(" ");610_cb->print_value_on(st);611st->cr();612#ifndef PRODUCT613if (end == NULL) {614begin = _cb->code_begin();615end = _cb->code_end();616}617#endif618}619NOT_PRODUCT(if (WizardMode && Verbose) Disassembler::decode(begin, end);)620}621622623void frame::print_on(outputStream* st) const {624print_value_on(st,NULL);625if (is_interpreted_frame()) {626interpreter_frame_print_on(st);627}628}629630631void frame::interpreter_frame_print_on(outputStream* st) const {632#ifndef PRODUCT633assert(is_interpreted_frame(), "Not an interpreted frame");634jint i;635for (i = 0; i < interpreter_frame_method()->max_locals(); i++ ) {636intptr_t x = *interpreter_frame_local_at(i);637st->print(" - local [" INTPTR_FORMAT "]", x);638st->fill_to(23);639st->print_cr("; #%d", i);640}641for (i = interpreter_frame_expression_stack_size() - 1; i >= 0; --i ) {642intptr_t x = *interpreter_frame_expression_stack_at(i);643st->print(" - stack [" INTPTR_FORMAT "]", x);644st->fill_to(23);645st->print_cr("; #%d", i);646}647// locks for synchronization648for (BasicObjectLock* current = interpreter_frame_monitor_end();649current < interpreter_frame_monitor_begin();650current = next_monitor_in_interpreter_frame(current)) {651st->print(" - obj [");652current->obj()->print_value_on(st);653st->print_cr("]");654st->print(" - lock [");655current->lock()->print_on(st);656st->print_cr("]");657}658// monitor659st->print_cr(" - monitor[" INTPTR_FORMAT "]", interpreter_frame_monitor_begin());660// bcp661st->print(" - bcp [" INTPTR_FORMAT "]", interpreter_frame_bcp());662st->fill_to(23);663st->print_cr("; @%d", interpreter_frame_bci());664// locals665st->print_cr(" - locals [" INTPTR_FORMAT "]", interpreter_frame_local_at(0));666// method667st->print(" - method [" INTPTR_FORMAT "]", (address)interpreter_frame_method());668st->fill_to(23);669st->print("; ");670interpreter_frame_method()->print_name(st);671st->cr();672#endif673}674675// Return whether the frame is in the VM or os indicating a Hotspot problem.676// Otherwise, it's likely a bug in the native library that the Java code calls,677// hopefully indicating where to submit bugs.678void frame::print_C_frame(outputStream* st, char* buf, int buflen, address pc) {679// C/C++ frame680bool in_vm = os::address_is_in_vm(pc);681st->print(in_vm ? "V" : "C");682683int offset;684bool found;685686// libname687found = os::dll_address_to_library_name(pc, buf, buflen, &offset);688if (found) {689// skip directory names690const char *p1, *p2;691p1 = buf;692int len = (int)strlen(os::file_separator());693while ((p2 = strstr(p1, os::file_separator())) != NULL) p1 = p2 + len;694st->print(" [%s+0x%x]", p1, offset);695} else {696st->print(" " PTR_FORMAT, pc);697}698699// function name - os::dll_address_to_function_name() may return confusing700// names if pc is within jvm.dll or libjvm.so, because JVM only has701// JVM_xxxx and a few other symbols in the dynamic symbol table. Do this702// only for native libraries.703if (!in_vm || Decoder::can_decode_C_frame_in_vm()) {704found = os::dll_address_to_function_name(pc, buf, buflen, &offset);705706if (found) {707st->print(" %s+0x%x", buf, offset);708}709}710}711712// frame::print_on_error() is called by fatal error handler. Notice that we may713// crash inside this function if stack frame is corrupted. The fatal error714// handler can catch and handle the crash. Here we assume the frame is valid.715//716// First letter indicates type of the frame:717// J: Java frame (compiled)718// j: Java frame (interpreted)719// V: VM frame (C/C++)720// v: Other frames running VM generated code (e.g. stubs, adapters, etc.)721// C: C/C++ frame722//723// We don't need detailed frame type as that in frame::print_name(). "C"724// suggests the problem is in user lib; everything else is likely a VM bug.725726void frame::print_on_error(outputStream* st, char* buf, int buflen, bool verbose) const {727if (_cb != NULL) {728if (Interpreter::contains(pc())) {729Method* m = this->interpreter_frame_method();730if (m != NULL) {731m->name_and_sig_as_C_string(buf, buflen);732st->print("j %s", buf);733st->print("+%d", this->interpreter_frame_bci());734} else {735st->print("j " PTR_FORMAT, pc());736}737} else if (StubRoutines::contains(pc())) {738StubCodeDesc* desc = StubCodeDesc::desc_for(pc());739if (desc != NULL) {740st->print("v ~StubRoutines::%s", desc->name());741} else {742st->print("v ~StubRoutines::" PTR_FORMAT, pc());743}744} else if (_cb->is_buffer_blob()) {745st->print("v ~BufferBlob::%s", ((BufferBlob *)_cb)->name());746} else if (_cb->is_nmethod()) {747nmethod* nm = (nmethod*)_cb;748Method* m = nm->method();749if (m != NULL) {750m->name_and_sig_as_C_string(buf, buflen);751st->print("J %d%s %s %s (%d bytes) @ " PTR_FORMAT " [" PTR_FORMAT "+0x%x]",752nm->compile_id(), (nm->is_osr_method() ? "%" : ""),753((nm->compiler() != NULL) ? nm->compiler()->name() : ""),754buf, m->code_size(), _pc, _cb->code_begin(), _pc - _cb->code_begin());755} else {756st->print("J " PTR_FORMAT, pc());757}758} else if (_cb->is_runtime_stub()) {759st->print("v ~RuntimeStub::%s", ((RuntimeStub *)_cb)->name());760} else if (_cb->is_deoptimization_stub()) {761st->print("v ~DeoptimizationBlob");762} else if (_cb->is_exception_stub()) {763st->print("v ~ExceptionBlob");764} else if (_cb->is_safepoint_stub()) {765st->print("v ~SafepointBlob");766} else {767st->print("v blob " PTR_FORMAT, pc());768}769} else {770print_C_frame(st, buf, buflen, pc());771}772}773774775/*776The interpreter_frame_expression_stack_at method in the case of SPARC needs the777max_stack value of the method in order to compute the expression stack address.778It uses the Method* in order to get the max_stack value but during GC this779Method* value saved on the frame is changed by reverse_and_push and hence cannot780be used. So we save the max_stack value in the FrameClosure object and pass it781down to the interpreter_frame_expression_stack_at method782*/783class InterpreterFrameClosure : public OffsetClosure {784private:785frame* _fr;786OopClosure* _f;787int _max_locals;788int _max_stack;789790public:791InterpreterFrameClosure(frame* fr, int max_locals, int max_stack,792OopClosure* f) {793_fr = fr;794_max_locals = max_locals;795_max_stack = max_stack;796_f = f;797}798799void offset_do(int offset) {800oop* addr;801if (offset < _max_locals) {802addr = (oop*) _fr->interpreter_frame_local_at(offset);803assert((intptr_t*)addr >= _fr->sp(), "must be inside the frame");804_f->do_oop(addr);805} else {806addr = (oop*) _fr->interpreter_frame_expression_stack_at((offset - _max_locals));807// In case of exceptions, the expression stack is invalid and the esp will be reset to express808// this condition. Therefore, we call f only if addr is 'inside' the stack (i.e., addr >= esp for Intel).809bool in_stack;810if (frame::interpreter_frame_expression_stack_direction() > 0) {811in_stack = (intptr_t*)addr <= _fr->interpreter_frame_tos_address();812} else {813in_stack = (intptr_t*)addr >= _fr->interpreter_frame_tos_address();814}815if (in_stack) {816_f->do_oop(addr);817}818}819}820821int max_locals() { return _max_locals; }822frame* fr() { return _fr; }823};824825826class InterpretedArgumentOopFinder: public SignatureInfo {827private:828OopClosure* _f; // Closure to invoke829int _offset; // TOS-relative offset, decremented with each argument830bool _has_receiver; // true if the callee has a receiver831frame* _fr;832833void set(int size, BasicType type) {834_offset -= size;835if (type == T_OBJECT || type == T_ARRAY) oop_offset_do();836}837838void oop_offset_do() {839oop* addr;840addr = (oop*)_fr->interpreter_frame_tos_at(_offset);841_f->do_oop(addr);842}843844public:845InterpretedArgumentOopFinder(Symbol* signature, bool has_receiver, frame* fr, OopClosure* f) : SignatureInfo(signature), _has_receiver(has_receiver) {846// compute size of arguments847int args_size = ArgumentSizeComputer(signature).size() + (has_receiver ? 1 : 0);848assert(!fr->is_interpreted_frame() ||849args_size <= fr->interpreter_frame_expression_stack_size(),850"args cannot be on stack anymore");851// initialize InterpretedArgumentOopFinder852_f = f;853_fr = fr;854_offset = args_size;855}856857void oops_do() {858if (_has_receiver) {859--_offset;860oop_offset_do();861}862iterate_parameters();863}864};865866867// Entry frame has following form (n arguments)868// +-----------+869// sp -> | last arg |870// +-----------+871// : ::: :872// +-----------+873// (sp+n)->| first arg|874// +-----------+875876877878// visits and GC's all the arguments in entry frame879class EntryFrameOopFinder: public SignatureInfo {880private:881bool _is_static;882int _offset;883frame* _fr;884OopClosure* _f;885886void set(int size, BasicType type) {887assert (_offset >= 0, "illegal offset");888if (type == T_OBJECT || type == T_ARRAY) oop_at_offset_do(_offset);889_offset -= size;890}891892void oop_at_offset_do(int offset) {893assert (offset >= 0, "illegal offset");894oop* addr = (oop*) _fr->entry_frame_argument_at(offset);895_f->do_oop(addr);896}897898public:899EntryFrameOopFinder(frame* frame, Symbol* signature, bool is_static) : SignatureInfo(signature) {900_f = NULL; // will be set later901_fr = frame;902_is_static = is_static;903_offset = ArgumentSizeComputer(signature).size() - 1; // last parameter is at index 0904}905906void arguments_do(OopClosure* f) {907_f = f;908if (!_is_static) oop_at_offset_do(_offset+1); // do the receiver909iterate_parameters();910}911912};913914oop* frame::interpreter_callee_receiver_addr(Symbol* signature) {915ArgumentSizeComputer asc(signature);916int size = asc.size();917return (oop *)interpreter_frame_tos_at(size);918}919920921void frame::oops_interpreted_do(OopClosure* f, CLDClosure* cld_f,922const RegisterMap* map, bool query_oop_map_cache) {923assert(is_interpreted_frame(), "Not an interpreted frame");924assert(map != NULL, "map must be set");925Thread *thread = Thread::current();926methodHandle m (thread, interpreter_frame_method());927jint bci = interpreter_frame_bci();928929assert(!Universe::heap()->is_in(m()),930"must be valid oop");931assert(m->is_method(), "checking frame value");932assert((m->is_native() && bci == 0) ||933(!m->is_native() && bci >= 0 && bci < m->code_size()),934"invalid bci value");935936// Handle the monitor elements in the activation937for (938BasicObjectLock* current = interpreter_frame_monitor_end();939current < interpreter_frame_monitor_begin();940current = next_monitor_in_interpreter_frame(current)941) {942#ifdef ASSERT943interpreter_frame_verify_monitor(current);944#endif945current->oops_do(f);946}947948// process fixed part949if (cld_f != NULL) {950// The method pointer in the frame might be the only path to the method's951// klass, and the klass needs to be kept alive while executing. The GCs952// don't trace through method pointers, so typically in similar situations953// the mirror or the class loader of the klass are installed as a GC root.954// To minimze the overhead of doing that here, we ask the GC to pass down a955// closure that knows how to keep klasses alive given a ClassLoaderData.956cld_f->do_cld(m->method_holder()->class_loader_data());957}958959if (m->is_native() PPC32_ONLY(&& m->is_static())) {960f->do_oop(interpreter_frame_temp_oop_addr());961}962963int max_locals = m->is_native() ? m->size_of_parameters() : m->max_locals();964965Symbol* signature = NULL;966bool has_receiver = false;967968// Process a callee's arguments if we are at a call site969// (i.e., if we are at an invoke bytecode)970// This is used sometimes for calling into the VM, not for another971// interpreted or compiled frame.972if (!m->is_native()) {973Bytecode_invoke call = Bytecode_invoke_check(m, bci);974if (call.is_valid()) {975signature = call.signature();976has_receiver = call.has_receiver();977if (map->include_argument_oops() &&978interpreter_frame_expression_stack_size() > 0) {979ResourceMark rm(thread); // is this right ???980// we are at a call site & the expression stack is not empty981// => process callee's arguments982//983// Note: The expression stack can be empty if an exception984// occurred during method resolution/execution. In all985// cases we empty the expression stack completely be-986// fore handling the exception (the exception handling987// code in the interpreter calls a blocking runtime988// routine which can cause this code to be executed).989// (was bug gri 7/27/98)990oops_interpreted_arguments_do(signature, has_receiver, f);991}992}993}994995InterpreterFrameClosure blk(this, max_locals, m->max_stack(), f);996997// process locals & expression stack998InterpreterOopMap mask;999if (query_oop_map_cache) {1000m->mask_for(bci, &mask);1001} else {1002OopMapCache::compute_one_oop_map(m, bci, &mask);1003}1004mask.iterate_oop(&blk);1005}100610071008void frame::oops_interpreted_arguments_do(Symbol* signature, bool has_receiver, OopClosure* f) {1009InterpretedArgumentOopFinder finder(signature, has_receiver, this, f);1010finder.oops_do();1011}10121013void frame::oops_code_blob_do(OopClosure* f, CodeBlobClosure* cf, const RegisterMap* reg_map) {1014assert(_cb != NULL, "sanity check");1015if (_cb->oop_maps() != NULL) {1016OopMapSet::oops_do(this, reg_map, f);10171018// Preserve potential arguments for a callee. We handle this by dispatching1019// on the codeblob. For c2i, we do1020if (reg_map->include_argument_oops()) {1021_cb->preserve_callee_argument_oops(*this, reg_map, f);1022}1023}1024// In cases where perm gen is collected, GC will want to mark1025// oops referenced from nmethods active on thread stacks so as to1026// prevent them from being collected. However, this visit should be1027// restricted to certain phases of the collection only. The1028// closure decides how it wants nmethods to be traced.1029if (cf != NULL)1030cf->do_code_blob(_cb);1031}10321033class CompiledArgumentOopFinder: public SignatureInfo {1034protected:1035OopClosure* _f;1036int _offset; // the current offset, incremented with each argument1037bool _has_receiver; // true if the callee has a receiver1038bool _has_appendix; // true if the call has an appendix1039frame _fr;1040RegisterMap* _reg_map;1041int _arg_size;1042VMRegPair* _regs; // VMReg list of arguments10431044void set(int size, BasicType type) {1045if (type == T_OBJECT || type == T_ARRAY) handle_oop_offset();1046_offset += size;1047}10481049virtual void handle_oop_offset() {1050// Extract low order register number from register array.1051// In LP64-land, the high-order bits are valid but unhelpful.1052VMReg reg = _regs[_offset].first();1053oop *loc = _fr.oopmapreg_to_location(reg, _reg_map);1054_f->do_oop(loc);1055}10561057public:1058CompiledArgumentOopFinder(Symbol* signature, bool has_receiver, bool has_appendix, OopClosure* f, frame fr, const RegisterMap* reg_map)1059: SignatureInfo(signature) {10601061// initialize CompiledArgumentOopFinder1062_f = f;1063_offset = 0;1064_has_receiver = has_receiver;1065_has_appendix = has_appendix;1066_fr = fr;1067_reg_map = (RegisterMap*)reg_map;1068_arg_size = ArgumentSizeComputer(signature).size() + (has_receiver ? 1 : 0) + (has_appendix ? 1 : 0);10691070int arg_size;1071_regs = SharedRuntime::find_callee_arguments(signature, has_receiver, has_appendix, &arg_size);1072assert(arg_size == _arg_size, "wrong arg size");1073}10741075void oops_do() {1076if (_has_receiver) {1077handle_oop_offset();1078_offset++;1079}1080iterate_parameters();1081if (_has_appendix) {1082handle_oop_offset();1083_offset++;1084}1085}1086};10871088void frame::oops_compiled_arguments_do(Symbol* signature, bool has_receiver, bool has_appendix, const RegisterMap* reg_map, OopClosure* f) {1089ResourceMark rm;1090CompiledArgumentOopFinder finder(signature, has_receiver, has_appendix, f, *this, reg_map);1091finder.oops_do();1092}109310941095// Get receiver out of callers frame, i.e. find parameter 0 in callers1096// frame. Consult ADLC for where parameter 0 is to be found. Then1097// check local reg_map for it being a callee-save register or argument1098// register, both of which are saved in the local frame. If not found1099// there, it must be an in-stack argument of the caller.1100// Note: caller.sp() points to callee-arguments1101oop frame::retrieve_receiver(RegisterMap* reg_map) {1102frame caller = *this;11031104// First consult the ADLC on where it puts parameter 0 for this signature.1105VMReg reg = SharedRuntime::name_for_receiver();1106oop* oop_adr = caller.oopmapreg_to_location(reg, reg_map);1107if (oop_adr == NULL) {1108guarantee(oop_adr != NULL, "bad register save location");1109return NULL;1110}1111oop r = *oop_adr;1112assert(Universe::heap()->is_in_or_null(r), err_msg("bad receiver: " INTPTR_FORMAT " (" INTX_FORMAT ")", (void *) r, (void *) r));1113return r;1114}111511161117oop* frame::oopmapreg_to_location(VMReg reg, const RegisterMap* reg_map) const {1118if(reg->is_reg()) {1119// If it is passed in a register, it got spilled in the stub frame.1120return (oop *)reg_map->location(reg);1121} else {1122int sp_offset_in_bytes = reg->reg2stack() * VMRegImpl::stack_slot_size;1123return (oop*)(((address)unextended_sp()) + sp_offset_in_bytes);1124}1125}11261127BasicLock* frame::get_native_monitor() {1128nmethod* nm = (nmethod*)_cb;1129assert(_cb != NULL && _cb->is_nmethod() && nm->method()->is_native(),1130"Should not call this unless it's a native nmethod");1131int byte_offset = in_bytes(nm->native_basic_lock_sp_offset());1132assert(byte_offset >= 0, "should not see invalid offset");1133return (BasicLock*) &sp()[byte_offset / wordSize];1134}11351136oop frame::get_native_receiver() {1137nmethod* nm = (nmethod*)_cb;1138assert(_cb != NULL && _cb->is_nmethod() && nm->method()->is_native(),1139"Should not call this unless it's a native nmethod");1140int byte_offset = in_bytes(nm->native_receiver_sp_offset());1141assert(byte_offset >= 0, "should not see invalid offset");1142oop owner = ((oop*) sp())[byte_offset / wordSize];1143assert( Universe::heap()->is_in(owner), "bad receiver" );1144return owner;1145}11461147void frame::oops_entry_do(OopClosure* f, const RegisterMap* map) {1148assert(map != NULL, "map must be set");1149if (map->include_argument_oops()) {1150// must collect argument oops, as nobody else is doing it1151Thread *thread = Thread::current();1152methodHandle m (thread, entry_frame_call_wrapper()->callee_method());1153EntryFrameOopFinder finder(this, m->signature(), m->is_static());1154finder.arguments_do(f);1155}1156// Traverse the Handle Block saved in the entry frame1157entry_frame_call_wrapper()->oops_do(f);1158}115911601161void frame::oops_do_internal(OopClosure* f, CLDClosure* cld_f, CodeBlobClosure* cf, RegisterMap* map, bool use_interpreter_oop_map_cache) {1162#ifndef PRODUCT1163// simulate GC crash here to dump java thread in error report1164if (CrashGCForDumpingJavaThread) {1165char *t = NULL;1166*t = 'c';1167}1168#endif1169if (is_interpreted_frame()) {1170oops_interpreted_do(f, cld_f, map, use_interpreter_oop_map_cache);1171} else if (is_entry_frame()) {1172oops_entry_do(f, map);1173} else if (CodeCache::contains(pc())) {1174oops_code_blob_do(f, cf, map);1175#ifdef SHARK1176} else if (is_fake_stub_frame()) {1177// nothing to do1178#endif // SHARK1179} else {1180ShouldNotReachHere();1181}1182}11831184void frame::nmethods_do(CodeBlobClosure* cf) {1185if (_cb != NULL && _cb->is_nmethod()) {1186cf->do_code_blob(_cb);1187}1188}118911901191// call f() on the interpreted Method*s in the stack.1192// Have to walk the entire code cache for the compiled frames Yuck.1193void frame::metadata_do(void f(Metadata*)) {1194if (_cb != NULL && Interpreter::contains(pc())) {1195Method* m = this->interpreter_frame_method();1196assert(m != NULL, "huh?");1197f(m);1198}1199}12001201void frame::gc_prologue() {1202if (is_interpreted_frame()) {1203// set bcx to bci to become Method* position independent during GC1204interpreter_frame_set_bcx(interpreter_frame_bci());1205}1206}120712081209void frame::gc_epilogue() {1210if (is_interpreted_frame()) {1211// set bcx back to bcp for interpreter1212interpreter_frame_set_bcx((intptr_t)interpreter_frame_bcp());1213}1214// call processor specific epilog function1215pd_gc_epilog();1216}121712181219# ifdef ENABLE_ZAP_DEAD_LOCALS12201221void frame::CheckValueClosure::do_oop(oop* p) {1222if (CheckOopishValues && Universe::heap()->is_in_reserved(*p)) {1223warning("value @ " INTPTR_FORMAT " looks oopish (" INTPTR_FORMAT ") (thread = " INTPTR_FORMAT ")", p, (address)*p, Thread::current());1224}1225}1226frame::CheckValueClosure frame::_check_value;122712281229void frame::CheckOopClosure::do_oop(oop* p) {1230if (*p != NULL && !(*p)->is_oop()) {1231warning("value @ " INTPTR_FORMAT " should be an oop (" INTPTR_FORMAT ") (thread = " INTPTR_FORMAT ")", p, (address)*p, Thread::current());1232}1233}1234frame::CheckOopClosure frame::_check_oop;12351236void frame::check_derived_oop(oop* base, oop* derived) {1237_check_oop.do_oop(base);1238}123912401241void frame::ZapDeadClosure::do_oop(oop* p) {1242if (TraceZapDeadLocals) tty->print_cr("zapping @ " INTPTR_FORMAT " containing " INTPTR_FORMAT, p, (address)*p);1243*p = cast_to_oop<intptr_t>(0xbabebabe);1244}1245frame::ZapDeadClosure frame::_zap_dead;12461247void frame::zap_dead_locals(JavaThread* thread, const RegisterMap* map) {1248assert(thread == Thread::current(), "need to synchronize to do this to another thread");1249// Tracing - part 11250if (TraceZapDeadLocals) {1251ResourceMark rm(thread);1252tty->print_cr("--------------------------------------------------------------------------------");1253tty->print("Zapping dead locals in ");1254print_on(tty);1255tty->cr();1256}1257// Zapping1258if (is_entry_frame ()) zap_dead_entry_locals (thread, map);1259else if (is_interpreted_frame()) zap_dead_interpreted_locals(thread, map);1260else if (is_compiled_frame()) zap_dead_compiled_locals (thread, map);12611262else1263// could be is_runtime_frame1264// so remove error: ShouldNotReachHere();1265;1266// Tracing - part 21267if (TraceZapDeadLocals) {1268tty->cr();1269}1270}127112721273void frame::zap_dead_interpreted_locals(JavaThread *thread, const RegisterMap* map) {1274// get current interpreter 'pc'1275assert(is_interpreted_frame(), "Not an interpreted frame");1276Method* m = interpreter_frame_method();1277int bci = interpreter_frame_bci();12781279int max_locals = m->is_native() ? m->size_of_parameters() : m->max_locals();12801281// process dynamic part1282InterpreterFrameClosure value_blk(this, max_locals, m->max_stack(),1283&_check_value);1284InterpreterFrameClosure oop_blk(this, max_locals, m->max_stack(),1285&_check_oop );1286InterpreterFrameClosure dead_blk(this, max_locals, m->max_stack(),1287&_zap_dead );12881289// get frame map1290InterpreterOopMap mask;1291m->mask_for(bci, &mask);1292mask.iterate_all( &oop_blk, &value_blk, &dead_blk);1293}129412951296void frame::zap_dead_compiled_locals(JavaThread* thread, const RegisterMap* reg_map) {12971298ResourceMark rm(thread);1299assert(_cb != NULL, "sanity check");1300if (_cb->oop_maps() != NULL) {1301OopMapSet::all_do(this, reg_map, &_check_oop, check_derived_oop, &_check_value);1302}1303}130413051306void frame::zap_dead_entry_locals(JavaThread*, const RegisterMap*) {1307if (TraceZapDeadLocals) warning("frame::zap_dead_entry_locals unimplemented");1308}130913101311void frame::zap_dead_deoptimized_locals(JavaThread*, const RegisterMap*) {1312if (TraceZapDeadLocals) warning("frame::zap_dead_deoptimized_locals unimplemented");1313}13141315# endif // ENABLE_ZAP_DEAD_LOCALS13161317void frame::verify(const RegisterMap* map) {1318// for now make sure receiver type is correct1319if (is_interpreted_frame()) {1320Method* method = interpreter_frame_method();1321guarantee(method->is_method(), "method is wrong in frame::verify");1322if (!method->is_static()) {1323// fetch the receiver1324oop* p = (oop*) interpreter_frame_local_at(0);1325// make sure we have the right receiver type1326}1327}1328COMPILER2_PRESENT(assert(DerivedPointerTable::is_empty(), "must be empty before verify");)1329oops_do_internal(&VerifyOopClosure::verify_oop, NULL, NULL, (RegisterMap*)map, false);1330}133113321333#ifdef ASSERT1334bool frame::verify_return_pc(address x) {1335if (StubRoutines::returns_to_call_stub(x)) {1336return true;1337}1338if (CodeCache::contains(x)) {1339return true;1340}1341if (Interpreter::contains(x)) {1342return true;1343}1344return false;1345}1346#endif13471348#ifdef ASSERT1349void frame::interpreter_frame_verify_monitor(BasicObjectLock* value) const {1350assert(is_interpreted_frame(), "Not an interpreted frame");1351// verify that the value is in the right part of the frame1352address low_mark = (address) interpreter_frame_monitor_end();1353address high_mark = (address) interpreter_frame_monitor_begin();1354address current = (address) value;13551356const int monitor_size = frame::interpreter_frame_monitor_size();1357guarantee((high_mark - current) % monitor_size == 0 , "Misaligned top of BasicObjectLock*");1358guarantee( high_mark > current , "Current BasicObjectLock* higher than high_mark");13591360guarantee((current - low_mark) % monitor_size == 0 , "Misaligned bottom of BasicObjectLock*");1361guarantee( current >= low_mark , "Current BasicObjectLock* below than low_mark");1362}1363#endif13641365#ifndef PRODUCT1366void frame::describe(FrameValues& values, int frame_no) {1367// boundaries: sp and the 'real' frame pointer1368values.describe(-1, sp(), err_msg("sp for #%d", frame_no), 1);1369intptr_t* frame_pointer = real_fp(); // Note: may differ from fp()13701371// print frame info at the highest boundary1372intptr_t* info_address = MAX2(sp(), frame_pointer);13731374if (info_address != frame_pointer) {1375// print frame_pointer explicitly if not marked by the frame info1376values.describe(-1, frame_pointer, err_msg("frame pointer for #%d", frame_no), 1);1377}13781379if (is_entry_frame() || is_compiled_frame() || is_interpreted_frame() || is_native_frame()) {1380// Label values common to most frames1381values.describe(-1, unextended_sp(), err_msg("unextended_sp for #%d", frame_no));1382}13831384if (is_interpreted_frame()) {1385Method* m = interpreter_frame_method();1386int bci = interpreter_frame_bci();13871388// Label the method and current bci1389values.describe(-1, info_address,1390FormatBuffer<1024>("#%d method %s @ %d", frame_no, m->name_and_sig_as_C_string(), bci), 2);1391values.describe(-1, info_address,1392err_msg("- %d locals %d max stack", m->max_locals(), m->max_stack()), 1);1393if (m->max_locals() > 0) {1394intptr_t* l0 = interpreter_frame_local_at(0);1395intptr_t* ln = interpreter_frame_local_at(m->max_locals() - 1);1396values.describe(-1, MAX2(l0, ln), err_msg("locals for #%d", frame_no), 1);1397// Report each local and mark as owned by this frame1398for (int l = 0; l < m->max_locals(); l++) {1399intptr_t* l0 = interpreter_frame_local_at(l);1400values.describe(frame_no, l0, err_msg("local %d", l));1401}1402}14031404// Compute the actual expression stack size1405InterpreterOopMap mask;1406OopMapCache::compute_one_oop_map(m, bci, &mask);1407intptr_t* tos = NULL;1408// Report each stack element and mark as owned by this frame1409for (int e = 0; e < mask.expression_stack_size(); e++) {1410tos = MAX2(tos, interpreter_frame_expression_stack_at(e));1411values.describe(frame_no, interpreter_frame_expression_stack_at(e),1412err_msg("stack %d", e));1413}1414if (tos != NULL) {1415values.describe(-1, tos, err_msg("expression stack for #%d", frame_no), 1);1416}1417if (interpreter_frame_monitor_begin() != interpreter_frame_monitor_end()) {1418values.describe(frame_no, (intptr_t*)interpreter_frame_monitor_begin(), "monitors begin");1419values.describe(frame_no, (intptr_t*)interpreter_frame_monitor_end(), "monitors end");1420}1421} else if (is_entry_frame()) {1422// For now just label the frame1423values.describe(-1, info_address, err_msg("#%d entry frame", frame_no), 2);1424} else if (is_compiled_frame()) {1425// For now just label the frame1426nmethod* nm = cb()->as_nmethod_or_null();1427values.describe(-1, info_address,1428FormatBuffer<1024>("#%d nmethod " INTPTR_FORMAT " for method %s%s", frame_no,1429nm, nm->method()->name_and_sig_as_C_string(),1430(_deopt_state == is_deoptimized) ?1431" (deoptimized)" :1432((_deopt_state == unknown) ? " (state unknown)" : "")),14332);1434} else if (is_native_frame()) {1435// For now just label the frame1436nmethod* nm = cb()->as_nmethod_or_null();1437values.describe(-1, info_address,1438FormatBuffer<1024>("#%d nmethod " INTPTR_FORMAT " for native method %s", frame_no,1439nm, nm->method()->name_and_sig_as_C_string()), 2);1440} else {1441// provide default info if not handled before1442char *info = (char *) "special frame";1443if ((_cb != NULL) &&1444(_cb->name() != NULL)) {1445info = (char *)_cb->name();1446}1447values.describe(-1, info_address, err_msg("#%d <%s>", frame_no, info), 2);1448}14491450// platform dependent additional data1451describe_pd(values, frame_no);1452}14531454#endif145514561457//-----------------------------------------------------------------------------------1458// StackFrameStream implementation14591460StackFrameStream::StackFrameStream(JavaThread *thread, bool update) : _reg_map(thread, update) {1461assert(thread->has_last_Java_frame(), "sanity check");1462_fr = thread->last_frame();1463_is_done = false;1464}146514661467#ifndef PRODUCT14681469void FrameValues::describe(int owner, intptr_t* location, const char* description, int priority) {1470FrameValue fv;1471fv.location = location;1472fv.owner = owner;1473fv.priority = priority;1474fv.description = NEW_RESOURCE_ARRAY(char, strlen(description) + 1);1475strcpy(fv.description, description);1476_values.append(fv);1477}147814791480#ifdef ASSERT1481void FrameValues::validate() {1482_values.sort(compare);1483bool error = false;1484FrameValue prev;1485prev.owner = -1;1486for (int i = _values.length() - 1; i >= 0; i--) {1487FrameValue fv = _values.at(i);1488if (fv.owner == -1) continue;1489if (prev.owner == -1) {1490prev = fv;1491continue;1492}1493if (prev.location == fv.location) {1494if (fv.owner != prev.owner) {1495tty->print_cr("overlapping storage");1496tty->print_cr(" " INTPTR_FORMAT ": " INTPTR_FORMAT " %s", prev.location, *prev.location, prev.description);1497tty->print_cr(" " INTPTR_FORMAT ": " INTPTR_FORMAT " %s", fv.location, *fv.location, fv.description);1498error = true;1499}1500} else {1501prev = fv;1502}1503}1504assert(!error, "invalid layout");1505}1506#endif // ASSERT15071508void FrameValues::print(JavaThread* thread) {1509_values.sort(compare);15101511// Sometimes values like the fp can be invalid values if the1512// register map wasn't updated during the walk. Trim out values1513// that aren't actually in the stack of the thread.1514int min_index = 0;1515int max_index = _values.length() - 1;1516intptr_t* v0 = _values.at(min_index).location;1517intptr_t* v1 = _values.at(max_index).location;15181519if (thread == Thread::current()) {1520while (!thread->is_in_stack((address)v0)) {1521v0 = _values.at(++min_index).location;1522}1523while (!thread->is_in_stack((address)v1)) {1524v1 = _values.at(--max_index).location;1525}1526} else {1527while (!thread->on_local_stack((address)v0)) {1528v0 = _values.at(++min_index).location;1529}1530while (!thread->on_local_stack((address)v1)) {1531v1 = _values.at(--max_index).location;1532}1533}1534intptr_t* min = MIN2(v0, v1);1535intptr_t* max = MAX2(v0, v1);1536intptr_t* cur = max;1537intptr_t* last = NULL;1538for (int i = max_index; i >= min_index; i--) {1539FrameValue fv = _values.at(i);1540while (cur > fv.location) {1541tty->print_cr(" " INTPTR_FORMAT ": " INTPTR_FORMAT, cur, *cur);1542cur--;1543}1544if (last == fv.location) {1545const char* spacer = " " LP64_ONLY(" ");1546tty->print_cr(" %s %s %s", spacer, spacer, fv.description);1547} else {1548tty->print_cr(" " INTPTR_FORMAT ": " INTPTR_FORMAT " %s", fv.location, *fv.location, fv.description);1549last = fv.location;1550cur--;1551}1552}1553}15541555#endif // ndef PRODUCT155615571558