26
26
#include " rommeth.h"
27
27
#include " vmhook.h"
28
28
29
- #if defined(LINUX) && defined(J9VM_ARCH_X86) && defined(J9VM_ENV_DATA64)
29
+ #if defined(LINUX) && ( defined(J9VM_ARCH_X86) || defined(J9VM_ARCH_POWER) ) && defined(J9VM_ENV_DATA64)
30
30
#include < ucontext.h>
31
31
#define ASGCT_SUPPORTED
32
32
#endif /* defined(LINUX) && defined(J9VM_ARCH_X86) && defined(J9VM_ENV_DATA64) */
@@ -47,7 +47,7 @@ ticks_unknown_state = -7, // ¯\_(ツ)_/¯
47
47
ticks_thread_exit = -8 , // dying thread
48
48
ticks_deopt = -9 , // mid-deopting code
49
49
ticks_safepoint = -10 // ¯\_(ツ)_/¯
50
- };
50
+ };
51
51
52
52
typedef struct {
53
53
jint lineno;
@@ -62,6 +62,17 @@ typedef struct {
62
62
63
63
#if defined(ASGCT_SUPPORTED)
64
64
65
+ #if defined(J9VM_ARCH_X86)
66
+ #define J9VM_GET_PC (ucontext ) ((ucontext_t *)(ucontext))->uc_mcontext.gregs[REG_RIP]
67
+ #define J9VM_GET_SP (ucontext ) ((ucontext_t *)(ucontext))->uc_mcontext.gregs[REG_RSP]
68
+ #define REGISTER greg_t
69
+ #elif defined(J9VM_ARCH_POWER) /* defined(J9VM_ARCH_X86) */
70
+ #define J9VM_GET_PC (ucontext ) ((ucontext_t *)(ucontext))->uc_mcontext.gp_regs[PT_NIP]
71
+ #define J9VM_GET_SP (ucontext ) ((ucontext_t *)(ucontext))->uc_mcontext.gp_regs[PT_R1]
72
+ #define REGISTER elf_greg_t
73
+ #endif /* defined(J9VM_ARCH_X86) */
74
+
75
+
65
76
extern J9JavaVM *BFUjavaVM;
66
77
67
78
#define TRIGGER_SEGV () *(UDATA*)UDATA_MAX = UDATA_MAX
@@ -76,7 +87,7 @@ asyncFrameIterator(J9VMThread * currentThread, J9StackWalkState * walkState)
76
87
UDATA methodIndex = getMethodIndexUnchecked (method);
77
88
/* If any of the following are true, trigger a SEGV which will
78
89
* be caught in the caller.
79
- *
90
+ *
80
91
* - method index is invalid (i.e. method was invalid)
81
92
* - method IDs for the class not pre-initialized
82
93
* - method ID for the method not pre-initialized
@@ -160,20 +171,19 @@ protectedASGCT(J9PortLibrary *portLib, void *arg)
160
171
if (NULL != jitConfig) {
161
172
void *ucontext = parms->ucontext ;
162
173
if (NULL != ucontext) {
163
- greg_t *regs = ((ucontext_t *)ucontext)->uc_mcontext .gregs ;
164
- greg_t rip = regs[REG_RIP];
165
- J9JITExceptionTable *metaData = jitConfig->jitGetExceptionTableFromPC (currentThread, rip);
174
+ REGISTER pc = J9VM_GET_PC (ucontext);
175
+ J9JITExceptionTable *metaData = jitConfig->jitGetExceptionTableFromPC (currentThread, pc);
166
176
if (NULL != metaData) {
167
- greg_t rsp = regs[REG_RSP] ;
177
+ REGISTER sp = J9VM_GET_SP (ucontext) ;
168
178
/* Build a JIT resolve frame on the C stack to avoid writing to the java
169
179
* stack in the signal handler. Update the J9VMThread roots to point to
170
180
* the resolve frame (will be restored in the caller).
171
181
*/
172
182
resolveFrame.savedJITException = NULL ;
173
183
resolveFrame.specialFrameFlags = J9_SSF_JIT_RESOLVE;
174
184
resolveFrame.parmCount = 0 ;
175
- resolveFrame.returnAddress = (U_8*)rip ;
176
- resolveFrame.taggedRegularReturnSP = (UDATA*)(((U_8 *)rsp ) + J9SF_A0_INVISIBLE_TAG);
185
+ resolveFrame.returnAddress = (U_8*)pc ;
186
+ resolveFrame.taggedRegularReturnSP = (UDATA*)(((U_8 *)sp ) + J9SF_A0_INVISIBLE_TAG);
177
187
currentThread->pc = (U_8*)J9SF_FRAME_TYPE_JIT_RESOLVE;
178
188
currentThread->arg0EA = (UDATA*)&(resolveFrame.taggedRegularReturnSP );
179
189
currentThread->literals = NULL ;
@@ -215,9 +225,9 @@ void AsyncGetCallTrace(ASGCT_CallTrace *trace, jint depth, void *ucontext)
215
225
ASGCT_parms parms = { trace, depth, ucontext, currentThread, num_frames, NULL , NULL , NULL , NULL , NULL , 0 };
216
226
UDATA result = 0 ;
217
227
j9sig_protect (
218
- protectedASGCT, (void *)&parms,
228
+ protectedASGCT, (void *)&parms,
219
229
emptySignalHandler, NULL ,
220
- J9PORT_SIG_FLAG_SIGALLSYNC | J9PORT_SIG_FLAG_MAY_RETURN,
230
+ J9PORT_SIG_FLAG_SIGALLSYNC | J9PORT_SIG_FLAG_MAY_RETURN,
221
231
&result);
222
232
num_frames = parms.num_frames ;
223
233
currentThread = parms.currentThread ;
0 commit comments