< prev index next >

src/hotspot/os_cpu/linux_ppc/os_linux_ppc.cpp

Print this page
rev 48556 : 8196401: PPC64+s390: get_frame_at_stack_banging_point uses wrong PC
Reviewed-by: stuefe
   1 /*
   2  * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2012, 2016 SAP SE. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  *


 103   // registers - NIP, among others.
 104   // This substructure may or may not be there depending where uc came from:
 105   // - if uc was handed over as the argument to a sigaction handler, a pointer to the
 106   //   substructure was provided by the kernel when calling the signal handler, and
 107   //   regs->nip can be accessed.
 108   // - if uc was filled by getcontext(), it is undefined - getcontext() does not fill
 109   //   it because the volatile registers are not needed to make setcontext() work.
 110   //   Hopefully it was zero'd out beforehand.
 111   guarantee(uc->uc_mcontext.regs != NULL, "only use ucontext_get_pc in sigaction context");
 112   return (address)uc->uc_mcontext.regs->nip;
 113 }
 114 
 115 // modify PC in ucontext.
 116 // Note: Only use this for an ucontext handed down to a signal handler. See comment
 117 // in ucontext_get_pc.
 118 void os::Linux::ucontext_set_pc(ucontext_t * uc, address pc) {
 119   guarantee(uc->uc_mcontext.regs != NULL, "only use ucontext_set_pc in sigaction context");
 120   uc->uc_mcontext.regs->nip = (unsigned long)pc;
 121 }
 122 




 123 intptr_t* os::Linux::ucontext_get_sp(const ucontext_t * uc) {
 124   return (intptr_t*)uc->uc_mcontext.regs->gpr[1/*REG_SP*/];
 125 }
 126 
 127 intptr_t* os::Linux::ucontext_get_fp(const ucontext_t * uc) {
 128   return NULL;
 129 }
 130 
 131 ExtendedPC os::fetch_frame_from_context(const void* ucVoid,
 132                     intptr_t** ret_sp, intptr_t** ret_fp) {
 133 
 134   ExtendedPC  epc;
 135   const ucontext_t* uc = (const ucontext_t*)ucVoid;
 136 
 137   if (uc != NULL) {
 138     epc = ExtendedPC(os::Linux::ucontext_get_pc(uc));
 139     if (ret_sp) *ret_sp = os::Linux::ucontext_get_sp(uc);
 140     if (ret_fp) *ret_fp = os::Linux::ucontext_get_fp(uc);
 141   } else {
 142     // construct empty ExtendedPC for return value checking


 160   if (Interpreter::contains(pc)) {
 161     // Interpreter performs stack banging after the fixed frame header has
 162     // been generated while the compilers perform it before. To maintain
 163     // semantic consistency between interpreted and compiled frames, the
 164     // method returns the Java sender of the current frame.
 165     *fr = os::fetch_frame_from_context(uc);
 166     if (!fr->is_first_java_frame()) {
 167       assert(fr->safe_for_sender(thread), "Safety check");
 168       *fr = fr->java_sender();
 169     }
 170   } else {
 171     // More complex code with compiled code.
 172     assert(!Interpreter::contains(pc), "Interpreted methods should have been handled above");
 173     CodeBlob* cb = CodeCache::find_blob(pc);
 174     if (cb == NULL || !cb->is_nmethod() || cb->is_frame_complete_at(pc)) {
 175       // Not sure where the pc points to, fallback to default
 176       // stack overflow handling. In compiled code, we bang before
 177       // the frame is complete.
 178       return false;
 179     } else {
 180       intptr_t* fp = os::Linux::ucontext_get_fp(uc);
 181       intptr_t* sp = os::Linux::ucontext_get_sp(uc);
 182       *fr = frame(sp, (address)*sp);

 183       if (!fr->is_java_frame()) {
 184         assert(fr->safe_for_sender(thread), "Safety check");
 185         assert(!fr->is_first_frame(), "Safety check");
 186         *fr = fr->java_sender();
 187       }
 188     }
 189   }
 190   assert(fr->is_java_frame(), "Safety check");
 191   return true;
 192 }
 193 
 194 frame os::get_sender_for_C_frame(frame* fr) {
 195   if (*fr->sp() == 0) {
 196     // fr is the last C frame
 197     return frame(NULL, NULL);
 198   }
 199   return frame(fr->sender_sp(), fr->sender_pc());
 200 }
 201 
 202 


   1 /*
   2  * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2012, 2018 SAP SE. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  *


 103   // registers - NIP, among others.
 104   // This substructure may or may not be there depending where uc came from:
 105   // - if uc was handed over as the argument to a sigaction handler, a pointer to the
 106   //   substructure was provided by the kernel when calling the signal handler, and
 107   //   regs->nip can be accessed.
 108   // - if uc was filled by getcontext(), it is undefined - getcontext() does not fill
 109   //   it because the volatile registers are not needed to make setcontext() work.
 110   //   Hopefully it was zero'd out beforehand.
 111   guarantee(uc->uc_mcontext.regs != NULL, "only use ucontext_get_pc in sigaction context");
 112   return (address)uc->uc_mcontext.regs->nip;
 113 }
 114 
 115 // modify PC in ucontext.
 116 // Note: Only use this for an ucontext handed down to a signal handler. See comment
 117 // in ucontext_get_pc.
 118 void os::Linux::ucontext_set_pc(ucontext_t * uc, address pc) {
 119   guarantee(uc->uc_mcontext.regs != NULL, "only use ucontext_set_pc in sigaction context");
 120   uc->uc_mcontext.regs->nip = (unsigned long)pc;
 121 }
 122 
 123 static address ucontext_get_lr(const ucontext_t * uc) {
 124   return (address)uc->uc_mcontext.regs->link;
 125 }
 126 
 127 intptr_t* os::Linux::ucontext_get_sp(const ucontext_t * uc) {
 128   return (intptr_t*)uc->uc_mcontext.regs->gpr[1/*REG_SP*/];
 129 }
 130 
 131 intptr_t* os::Linux::ucontext_get_fp(const ucontext_t * uc) {
 132   return NULL;
 133 }
 134 
 135 ExtendedPC os::fetch_frame_from_context(const void* ucVoid,
 136                     intptr_t** ret_sp, intptr_t** ret_fp) {
 137 
 138   ExtendedPC  epc;
 139   const ucontext_t* uc = (const ucontext_t*)ucVoid;
 140 
 141   if (uc != NULL) {
 142     epc = ExtendedPC(os::Linux::ucontext_get_pc(uc));
 143     if (ret_sp) *ret_sp = os::Linux::ucontext_get_sp(uc);
 144     if (ret_fp) *ret_fp = os::Linux::ucontext_get_fp(uc);
 145   } else {
 146     // construct empty ExtendedPC for return value checking


 164   if (Interpreter::contains(pc)) {
 165     // Interpreter performs stack banging after the fixed frame header has
 166     // been generated while the compilers perform it before. To maintain
 167     // semantic consistency between interpreted and compiled frames, the
 168     // method returns the Java sender of the current frame.
 169     *fr = os::fetch_frame_from_context(uc);
 170     if (!fr->is_first_java_frame()) {
 171       assert(fr->safe_for_sender(thread), "Safety check");
 172       *fr = fr->java_sender();
 173     }
 174   } else {
 175     // More complex code with compiled code.
 176     assert(!Interpreter::contains(pc), "Interpreted methods should have been handled above");
 177     CodeBlob* cb = CodeCache::find_blob(pc);
 178     if (cb == NULL || !cb->is_nmethod() || cb->is_frame_complete_at(pc)) {
 179       // Not sure where the pc points to, fallback to default
 180       // stack overflow handling. In compiled code, we bang before
 181       // the frame is complete.
 182       return false;
 183     } else {

 184       intptr_t* sp = os::Linux::ucontext_get_sp(uc);
 185       address lr = ucontext_get_lr(uc);
 186       *fr = frame(sp, lr);
 187       if (!fr->is_java_frame()) {
 188         assert(fr->safe_for_sender(thread), "Safety check");
 189         assert(!fr->is_first_frame(), "Safety check");
 190         *fr = fr->java_sender();
 191       }
 192     }
 193   }
 194   assert(fr->is_java_frame(), "Safety check");
 195   return true;
 196 }
 197 
 198 frame os::get_sender_for_C_frame(frame* fr) {
 199   if (*fr->sp() == 0) {
 200     // fr is the last C frame
 201     return frame(NULL, NULL);
 202   }
 203   return frame(fr->sender_sp(), fr->sender_pc());
 204 }
 205 
 206 


< prev index next >