jdk

Форк
0
/
javaThread_linux_s390.cpp 
139 строк · 5.9 Кб
1
/*
2
 * Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved.
3
 * Copyright (c) 2016, 2022 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
 *
24
 */
25

26
#include "precompiled.hpp"
27
#include "memory/metaspace.hpp"
28
#include "runtime/frame.inline.hpp"
29
#include "runtime/javaThread.hpp"
30

31
frame JavaThread::pd_last_frame() {
32
  assert(has_last_Java_frame(), "must have last_Java_sp() when suspended");
33

34
  intptr_t* sp = last_Java_sp();
35
  address pc = _anchor.last_Java_pc();
36

37
  // Last_Java_pc is not set if we come here from compiled code.
38
  // Assume spill slot for Z_R14 (return register) contains a suitable pc.
39
  // Should have been filled by method entry code.
40
  if (pc == nullptr) {
41
    pc = (address) *(sp + 14);
42
  }
43

44
  return frame(sp, pc);
45
}
46

47
bool JavaThread::pd_get_top_frame_for_profiling(frame* fr_addr, void* ucontext, bool isInJava) {
48

49
  // If we have a last_Java_frame, then we should use it even if
50
  // isInJava == true.  It should be more reliable than ucontext info.
51
  if (has_last_Java_frame() && frame_anchor()->walkable()) {
52
    *fr_addr = pd_last_frame();
53
    return true;
54
  }
55

56
  // At this point, we don't have a last_Java_frame, so
57
  // we try to glean some information out of the ucontext
58
  // if we were running Java code when SIGPROF came in.
59
  if (isInJava) {
60
    ucontext_t* uc = (ucontext_t*) ucontext;
61
    address pc = (address)uc->uc_mcontext.psw.addr;
62

63
    if (pc == nullptr) {
64
      // ucontext wasn't useful
65
      return false;
66
    }
67

68
    frame ret_frame((intptr_t*)uc->uc_mcontext.gregs[15/*Z_SP*/], pc);
69

70
    if (ret_frame.fp() == nullptr) {
71
      // The found frame does not have a valid frame pointer.
72
      // Bail out because this will create big trouble later on, either
73
      //  - when using istate, calculated as (nullptr - z_ijava_state_size (= 0x70 (dbg) or 0x68 (rel)) or
74
      //  - when using fp() directly in safe_for_sender()
75
      //
76
      // There is no conclusive description (yet) how this could happen, but it does:
77
      //
78
      // We observed a SIGSEGV with the following stack trace (openjdk.jdk11u-dev, 2021-07-07, linuxs390x fastdebug)
79
      // V  [libjvm.so+0x12c8f12]  JavaThread::pd_get_top_frame_for_profiling(frame*, void*, bool)+0x142
80
      // V  [libjvm.so+0xb1020c]  JfrGetCallTrace::get_topframe(void*, frame&)+0x3c
81
      // V  [libjvm.so+0xba0b08]  OSThreadSampler::protected_task(SuspendedThreadTaskContext const&)+0x98
82
      // V  [libjvm.so+0xff33c4]  SuspendedThreadTask::internal_do_task()+0x14c
83
      // V  [libjvm.so+0xfe3c9c]  SuspendedThreadTask::run()+0x24
84
      // V  [libjvm.so+0xba0c66]  JfrThreadSampleClosure::sample_thread_in_java(JavaThread*, JfrStackFrame*, unsigned int)+0x66
85
      // V  [libjvm.so+0xba1718]  JfrThreadSampleClosure::do_sample_thread(JavaThread*, JfrStackFrame*, unsigned int, JfrSampleType)+0x278
86
      // V  [libjvm.so+0xba4f54]  JfrThreadSampler::task_stacktrace(JfrSampleType, JavaThread**) [clone .constprop.62]+0x284
87
      // V  [libjvm.so+0xba5e54]  JfrThreadSampler::run()+0x2ec
88
      // V  [libjvm.so+0x12adc9c]  Thread::call_run()+0x9c
89
      // V  [libjvm.so+0xff5ab0]  thread_native_entry(Thread*)+0x128
90
      // siginfo: si_signo: 11 (SIGSEGV), si_code: 1 (SEGV_MAPERR), si_addr: 0xfffffffffffff000
91
      // failing instruction: e320 6008 0004   LG   r2,8(r0,r6)
92
      // contents of r6:  0xffffffffffffff90
93
      //
94
      // Here is the sequence of what happens:
95
      //  - ret_frame is constructed with _fp == nullptr (for whatever reason)
96
      //  - ijava_state_unchecked() calculates it's result as
97
      //      istate = fp() - z_ijava_state_size() = nullptr - 0x68 DEBUG_ONLY(-8)
98
      //  - istate->method dereferences memory at offset 8 from istate
99
      return false;
100
    }
101

102
    if (ret_frame.is_interpreted_frame()) {
103
      frame::z_ijava_state* istate = ret_frame.ijava_state_unchecked();
104
      if (!is_in_full_stack((address)istate)) {
105
        return false;
106
      }
107
      const Method *m = (const Method*)(istate->method);
108
      if (!Method::is_valid_method(m)) return false;
109
      if (!Metaspace::contains(m->constMethod())) return false;
110

111
      uint64_t reg_bcp = uc->uc_mcontext.gregs[13/*Z_BCP*/];
112
      uint64_t istate_bcp = istate->bcp;
113
      uint64_t code_start = (uint64_t)(m->code_base());
114
      uint64_t code_end = (uint64_t)(m->code_base() + m->code_size());
115
      if (istate_bcp >= code_start && istate_bcp < code_end) {
116
        // we have a valid bcp, don't touch it, do nothing
117
      } else if (reg_bcp >= code_start && reg_bcp < code_end) {
118
        istate->bcp = reg_bcp;
119
      } else {
120
        return false;
121
      }
122
    }
123
    if (!ret_frame.safe_for_sender(this)) {
124
      // nothing else to try if the frame isn't good
125
      return false;
126
    }
127
    *fr_addr = ret_frame;
128
    return true;
129
  }
130
  // nothing else to try
131
  return false;
132
}
133

134
// Forte Analyzer AsyncGetCallTrace profiling support.
135
bool JavaThread::pd_get_top_frame_for_signal_handler(frame* fr_addr, void* ucontext, bool isInJava) {
136
  return pd_get_top_frame_for_profiling(fr_addr, ucontext, isInJava);
137
}
138

139
void JavaThread::cache_global_variables() { }
140

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.