Skip to content

Commit 7c207f1

Browse files
authored
Merge pull request #18901 from tajila/asgct
Port ASGCT to PPC64
2 parents 70b540e + 2996756 commit 7c207f1

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

runtime/j9vm/asgct.cpp

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include "rommeth.h"
2727
#include "vmhook.h"
2828

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)
3030
#include <ucontext.h>
3131
#define ASGCT_SUPPORTED
3232
#endif /* defined(LINUX) && defined(J9VM_ARCH_X86) && defined(J9VM_ENV_DATA64) */
@@ -47,7 +47,7 @@ ticks_unknown_state = -7, // ¯\_(ツ)_/¯
4747
ticks_thread_exit = -8, // dying thread
4848
ticks_deopt = -9, // mid-deopting code
4949
ticks_safepoint = -10 // ¯\_(ツ)_/¯
50-
};
50+
};
5151

5252
typedef struct {
5353
jint lineno;
@@ -62,6 +62,17 @@ typedef struct {
6262

6363
#if defined(ASGCT_SUPPORTED)
6464

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+
6576
extern J9JavaVM *BFUjavaVM;
6677

6778
#define TRIGGER_SEGV() *(UDATA*)UDATA_MAX = UDATA_MAX
@@ -76,7 +87,7 @@ asyncFrameIterator(J9VMThread * currentThread, J9StackWalkState * walkState)
7687
UDATA methodIndex = getMethodIndexUnchecked(method);
7788
/* If any of the following are true, trigger a SEGV which will
7889
* be caught in the caller.
79-
*
90+
*
8091
* - method index is invalid (i.e. method was invalid)
8192
* - method IDs for the class not pre-initialized
8293
* - method ID for the method not pre-initialized
@@ -160,20 +171,19 @@ protectedASGCT(J9PortLibrary *portLib, void *arg)
160171
if (NULL != jitConfig) {
161172
void *ucontext = parms->ucontext;
162173
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);
166176
if (NULL != metaData) {
167-
greg_t rsp = regs[REG_RSP];
177+
REGISTER sp = J9VM_GET_SP(ucontext);
168178
/* Build a JIT resolve frame on the C stack to avoid writing to the java
169179
* stack in the signal handler. Update the J9VMThread roots to point to
170180
* the resolve frame (will be restored in the caller).
171181
*/
172182
resolveFrame.savedJITException = NULL;
173183
resolveFrame.specialFrameFlags = J9_SSF_JIT_RESOLVE;
174184
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);
177187
currentThread->pc = (U_8*)J9SF_FRAME_TYPE_JIT_RESOLVE;
178188
currentThread->arg0EA = (UDATA*)&(resolveFrame.taggedRegularReturnSP);
179189
currentThread->literals = NULL;
@@ -215,9 +225,9 @@ void AsyncGetCallTrace(ASGCT_CallTrace *trace, jint depth, void *ucontext)
215225
ASGCT_parms parms = { trace, depth, ucontext, currentThread, num_frames, NULL, NULL, NULL, NULL, NULL, 0 };
216226
UDATA result = 0;
217227
j9sig_protect(
218-
protectedASGCT, (void*)&parms,
228+
protectedASGCT, (void*)&parms,
219229
emptySignalHandler, NULL,
220-
J9PORT_SIG_FLAG_SIGALLSYNC | J9PORT_SIG_FLAG_MAY_RETURN,
230+
J9PORT_SIG_FLAG_SIGALLSYNC | J9PORT_SIG_FLAG_MAY_RETURN,
221231
&result);
222232
num_frames = parms.num_frames;
223233
currentThread = parms.currentThread;

0 commit comments

Comments
 (0)