Skip to content

Commit

Permalink
Make use of DECLARE_GLOBAL and DECLARE_EXTERN macros
Browse files Browse the repository at this point in the history
By making use of those macros, which are generated by jilgen,
we no longer have to worry about handling the OS differences when
writing assembly code to work across operating systems. This removes
the need to prepend underscores to global and extern symbol names.

Signed-off-by: Nazim Uddin Bhuiyan <[email protected]>
  • Loading branch information
nbhuiyan committed Oct 22, 2018
1 parent c6542ec commit 1aeb25d
Show file tree
Hide file tree
Showing 8 changed files with 559 additions and 556 deletions.
20 changes: 10 additions & 10 deletions runtime/compiler/x/amd64/runtime/AMD64CompressString_nasm.inc
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@

segment .text

global _compressString
global _compressStringJ
global _compressStringNoCheck
global _compressStringNoCheckJ
global _andORString
DECLARE_GLOBAL compressString
DECLARE_GLOBAL compressStringJ
DECLARE_GLOBAL compressStringNoCheck
DECLARE_GLOBAL compressStringNoCheckJ
DECLARE_GLOBAL andORString

align 16


_compressString:
compressString:
shr rcx, 4
add rsi, rax
add rsi, rax
Expand Down Expand Up @@ -89,7 +89,7 @@ ret
; ecx has length of copy in bytes
; esi has source address
; edi has destination address
_compressStringJ:
compressStringJ:
shr rcx, 4
add rsi, rax
add rsi, rax
Expand Down Expand Up @@ -120,7 +120,7 @@ eightcharsJ:
shr rax, 32
ret

_andORString:
andORString:
shr rcx, 4
add rsi, rax
add rsi, rax
Expand Down Expand Up @@ -159,7 +159,7 @@ eightchars2:
ret


_compressStringNoCheckJ:
compressStringNoCheckJ:
shr rcx, 4
add rsi, rax
add rsi, rax
Expand All @@ -181,7 +181,7 @@ eightcharsNoCheckJ:
loop eightcharsNoCheckJ
ret

_compressStringNoCheck:
compressStringNoCheck:
shr rcx, 4
add rsi, rax
add rsi, rax
Expand Down
81 changes: 40 additions & 41 deletions runtime/compiler/x/amd64/runtime/AMD64Recompilation.nasm
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,20 @@

%include "jilconsts.inc"


extern _jitRetranslateMethod
extern _jitCallCFunction
extern _induceRecompilation_unwrapper
extern _mcc_AMD64callPointPatching_unwrapper
extern _initialInvokeExactThunk_unwrapper
extern _methodHandleJ2I_unwrapper

global _countingRecompileMethod
global _samplingRecompileMethod
global _countingPatchCallSite
global _samplingPatchCallSite
global _induceRecompilation
global _initialInvokeExactThunkGlue
global _methodHandleJ2IGlue
DECLARE_EXTERN jitRetranslateMethod
DECLARE_EXTERN jitCallCFunction
DECLARE_EXTERN induceRecompilation_unwrapper
DECLARE_EXTERN mcc_AMD64callPointPatching_unwrapper
DECLARE_EXTERN initialInvokeExactThunk_unwrapper
DECLARE_EXTERN methodHandleJ2I_unwrapper

DECLARE_GLOBAL countingRecompileMethod
DECLARE_GLOBAL samplingRecompileMethod
DECLARE_GLOBAL countingPatchCallSite
DECLARE_GLOBAL samplingPatchCallSite
DECLARE_GLOBAL induceRecompilation
DECLARE_GLOBAL initialInvokeExactThunkGlue
DECLARE_GLOBAL methodHandleJ2IGlue

segment .text

Expand Down Expand Up @@ -106,7 +105,7 @@ ret ;exitRecompileMethod endp
;
align 16
;
_countingRecompileMethod:
countingRecompileMethod:
;
pop rdi ; Return address in snippet
saveRegs
Expand All @@ -123,7 +122,7 @@ _countingRecompileMethod:
mov rax, qword [rax+eq_BodyInfo_MethodInfo]
mov rax, qword [rax+eq_MethodInfo_J9Method]

CallHelperUseReg _jitRetranslateMethod,rax
CallHelperUseReg jitRetranslateMethod,rax
test rax, rax
jnz countingGotStartAddress

Expand Down Expand Up @@ -153,7 +152,7 @@ ret
;
align 16
;
_samplingRecompileMethod:
samplingRecompileMethod:
;
pop rdi ; Return address in preprologue
saveRegs
Expand All @@ -169,7 +168,7 @@ _samplingRecompileMethod:
mov rax, qword [rax+eq_BodyInfo_MethodInfo]
mov rax, qword [rax+eq_MethodInfo_J9Method]

CallHelperUseReg _jitRetranslateMethod,rax
CallHelperUseReg jitRetranslateMethod,rax

; If the compilation has not been done yet, restart this method.
; It should now execute normally
Expand All @@ -193,7 +192,7 @@ ret

align 16
;
_induceRecompilation:
induceRecompilation:
;
xchg rdi, [rsp] ; Return address in snippet
push rsi ; Preserve
Expand All @@ -203,15 +202,15 @@ _induceRecompilation:
movsxd rsi, dword [rdi+eq_induceSnippet_startPCOffset]
add rsi, rdi

; set up args to _induceRecompilation_unwrapper
; set up args to induceRecompilation_unwrapper
push rbp ; parm: vmThread
push rsi ; parm: startPC

; set up args to _jitCallCFunction
MoveHelper rax, _induceRecompilation_unwrapper ; parm: C function to call
; set up args to jitCallCFunction
MoveHelper rax, induceRecompilation_unwrapper ; parm: C function to call
mov rsi, rsp ; parm: args array
; parm: result pointer; don't care
CallHelper _jitCallCFunction
CallHelper jitCallCFunction
add rsp, 16

; restore regs and return to snippet
Expand All @@ -227,7 +226,7 @@ ret

align 16
;
_countingPatchCallSite:
countingPatchCallSite:
;
xchg qword [rsp], rdi
push rdx
Expand Down Expand Up @@ -278,7 +277,7 @@ patchCallSite:
push rsi ; preserve rsi
xor rsi, rsi
push rsi ; extraArg
push rax ; pass old startPC to _mcc_AMD64callPointPatching_unwrapper
push rax ; pass old startPC to mcc_AMD64callPointPatching_unwrapper
mov rsi, qword [rax+eq_startPC_BodyInfo]
mov rsi, qword [rsi+eq_BodyInfo_MethodInfo]
mov rax, qword [rsi+eq_MethodInfo_J9Method] ; rax = j9method
Expand All @@ -288,10 +287,10 @@ patchCallSite:
push rsi ; new startPC
push rdx ; call instruction
push rax ; j9method
MoveHelper rax, _mcc_AMD64callPointPatching_unwrapper
MoveHelper rax, mcc_AMD64callPointPatching_unwrapper
lea rsi, [rsp]
lea rdx, [rsp]
call _jitCallCFunction
call jitCallCFunction
add rsp, 48
pop rsi
Expand Down Expand Up @@ -334,7 +333,7 @@ ret

align 16
;
_samplingPatchCallSite:
samplingPatchCallSite:
;
xchg qword [rsp], rdi
push rdx
Expand Down Expand Up @@ -368,35 +367,35 @@ samplingPatchToRecompile:
; HCR: we've got our hands on a new j9method that hasn't been compiled yet,
; so there's no way to patch the call site without first compiling the new method
;
; Make the world look the way it should for a call to _samplingRecompileMethod
; Make the world look the way it should for a call to samplingRecompileMethod
pop rdi
pop rax
pop rdx
xchg qword [rsp], rdi
jmp _samplingRecompileMethod
jmp samplingRecompileMethod
;
;
ret
;

align 16
;
_initialInvokeExactThunkGlue:
initialInvokeExactThunkGlue:
;
; preserve all non-scratch regs
push rax
push rsi
push rdx

; set up args to _initialInvokeExactThunk_unwrapper
; set up args to initialInvokeExactThunk_unwrapper
push rbp ; parm: vmThread
push rax ; parm: receiver MethodHandle; also, result goes here

; set up args to _jitCallCFunction
MoveHelper rax, _initialInvokeExactThunk_unwrapper ; parm: C function to call
; set up args to jitCallCFunction
MoveHelper rax, initialInvokeExactThunk_unwrapper ; parm: C function to call
mov rsi, rsp ; parm: args array
mov rdx, rsp ; parm: result pointer
CallHelper _jitCallCFunction
CallHelper jitCallCFunction
pop rax ; result jitted entry point
pop rbp

Expand All @@ -416,7 +415,7 @@ ret

align 16
;
_methodHandleJ2IGlue:
methodHandleJ2IGlue:
;
; Note: this glue is not called, it is jumped to. There is no
; return address on the stack.
Expand All @@ -426,17 +425,17 @@ _methodHandleJ2IGlue:
push rsi
push rdx

; set up args to _initialInvokeExactThunk_unwrapper
; set up args to initialInvokeExactThunk_unwrapper
push rbp ; parm: vmThread
lea rsi, [rsp+40]
push rsi ; parm: stack pointer before the call to the j2i thunk
push rax ; parm: receiver MethodHandle; also, result goes here

; set up args to _jitCallCFunction
MoveHelper rax, _methodHandleJ2I_unwrapper ; parm: C function to call
; set up args to jitCallCFunction
MoveHelper rax, methodHandleJ2I_unwrapper ; parm: C function to call
mov rsi, rsp ; parm: args array
mov rdx, rsp ; parm: result pointer
CallHelper _jitCallCFunction
CallHelper jitCallCFunction
pop rax ; result (currently unused)
pop rsi
pop rbp
Expand Down
13 changes: 7 additions & 6 deletions runtime/compiler/x/runtime/X86ArrayTranslate.nasm
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@

segment .text

global _arrayTranslateTRTO
global _arrayTranslateTROTNoBreak
global _arrayTranslateTROT
DECLARE_GLOBAL arrayTranslateTRTO
DECLARE_GLOBAL arrayTranslateTROTNoBreak
DECLARE_GLOBAL arrayTranslateTROT

align 16

; pseudocode:
Expand All @@ -33,7 +34,7 @@ segment .text
; if (chararray[i] && DX != 0) break; //DX is the register
; else bytearray[i] = (byte) chararray[i])
; return i
_arrayTranslateTRTO: ;TO stands for Two bytes to One byte
arrayTranslateTRTO: ;TO stands for Two bytes to One byte
%ifdef TR_HOST_64BIT
mov ecx, ecx
%endif
Expand Down Expand Up @@ -85,7 +86,7 @@ segment .text
; int i;
; for (i = 0; i < N; i++)
; chararray[i] = (char) bytearray[i];
_arrayTranslateTROTNoBreak: ;OT stands for One byte to Two bytes
arrayTranslateTROTNoBreak: ;OT stands for One byte to Two bytes
%ifdef TR_HOST_64BIT
mov ecx, ecx
%endif
Expand Down Expand Up @@ -156,7 +157,7 @@ segment .text
; if (bytearray[i] < 0) break;
; else chararray[i] = (char) bytearray[i];
; return i;
_arrayTranslateTROT: ;OT stands for One byte to Two bytes
arrayTranslateTROT: ;OT stands for One byte to Two bytes
%ifdef TR_HOST_64BIT
mov ecx, ecx
%endif
Expand Down
Loading

0 comments on commit 1aeb25d

Please sign in to comment.