2009-03-15 18:02:36 +00:00
|
|
|
/* Copyright (c) 2008-2009, Avian Contributors
|
2008-02-19 18:06:52 +00:00
|
|
|
|
|
|
|
Permission to use, copy, modify, and/or distribute this software
|
|
|
|
for any purpose with or without fee is hereby granted, provided
|
|
|
|
that the above copyright notice and this permission notice appear
|
|
|
|
in all copies.
|
|
|
|
|
|
|
|
There is NO WARRANTY for this software. See license.txt for
|
|
|
|
details. */
|
|
|
|
|
2007-06-29 02:58:48 +00:00
|
|
|
#include "types.h"
|
|
|
|
|
2008-06-15 18:49:37 +00:00
|
|
|
#define LOCAL(x) .L##x
|
2009-07-26 02:48:36 +00:00
|
|
|
|
2010-12-20 19:11:29 +00:00
|
|
|
#if defined __APPLE__ \
|
|
|
|
|| ((defined __MINGW32__ || defined __CYGWIN32__) && ! defined __x86_64__)
|
2009-07-26 02:48:36 +00:00
|
|
|
# define GLOBAL(x) _##x
|
|
|
|
#else
|
|
|
|
# define GLOBAL(x) x
|
|
|
|
#endif
|
2008-06-15 18:49:37 +00:00
|
|
|
|
2007-06-29 02:58:48 +00:00
|
|
|
.text
|
2009-06-11 15:42:07 +00:00
|
|
|
|
2007-10-04 00:41:54 +00:00
|
|
|
#ifdef __x86_64__
|
2009-06-11 15:42:07 +00:00
|
|
|
|
2010-12-27 22:55:23 +00:00
|
|
|
#define CHECKPOINT_THREAD 8
|
|
|
|
#define CHECKPOINT_STACK 48
|
|
|
|
|
2009-07-26 02:48:36 +00:00
|
|
|
#ifdef __MINGW32__
|
2009-08-10 19:20:23 +00:00
|
|
|
.globl GLOBAL(detectFeature)
|
|
|
|
GLOBAL(detectFeature):
|
2009-08-06 14:49:26 +00:00
|
|
|
pushq %rbp
|
|
|
|
movq %rsp, %rbp
|
|
|
|
pushq %rdx
|
|
|
|
pushq %rcx
|
|
|
|
pushq %rbx
|
|
|
|
pushq %rsi
|
|
|
|
pushq %rdi
|
|
|
|
movl %ecx, %edi
|
|
|
|
movl %edx, %esi
|
|
|
|
movl $1, %eax
|
|
|
|
cpuid
|
|
|
|
andl %esi, %edx
|
|
|
|
andl %edi, %ecx
|
|
|
|
orl %edx, %ecx
|
|
|
|
test %ecx, %ecx
|
|
|
|
je LOCAL(NOSSE)
|
|
|
|
movl $1, %eax
|
|
|
|
jmp LOCAL(SSEEND)
|
|
|
|
LOCAL(NOSSE):
|
|
|
|
movl $0, %eax
|
|
|
|
LOCAL(SSEEND):
|
|
|
|
popq %rdi
|
|
|
|
popq %rsi
|
|
|
|
popq %rbx
|
|
|
|
popq %rcx
|
|
|
|
popq %rdx
|
|
|
|
movq %rbp,%rsp
|
|
|
|
popq %rbp
|
|
|
|
ret
|
2009-06-11 15:42:07 +00:00
|
|
|
|
2009-07-26 02:48:36 +00:00
|
|
|
.globl GLOBAL(vmNativeCall)
|
|
|
|
GLOBAL(vmNativeCall):
|
2009-06-11 15:42:07 +00:00
|
|
|
pushq %rbp
|
|
|
|
//save nonvolatile registers
|
|
|
|
pushq %r12
|
|
|
|
pushq %r13
|
|
|
|
pushq %r14
|
|
|
|
pushq %r15
|
|
|
|
movq %rsp, %rbp
|
|
|
|
|
|
|
|
|
|
|
|
// %rcx: function
|
|
|
|
// %rdx: arguments
|
|
|
|
// %r8: arguments count
|
|
|
|
// %r9: return type
|
|
|
|
|
|
|
|
movq %rcx, %r10
|
|
|
|
movq %rdx, %r11
|
|
|
|
movq %r8, %r12
|
|
|
|
movq %r9, %r13
|
|
|
|
|
|
|
|
// %r10: function
|
|
|
|
// %r11: arguments
|
|
|
|
// %r12: arguments count
|
|
|
|
// %r13: return type
|
|
|
|
|
|
|
|
//allocate initial stack space
|
|
|
|
subq $32, %rsp
|
|
|
|
|
|
|
|
//first arg
|
|
|
|
cmp $0, %r12
|
|
|
|
je LOCAL(call)
|
|
|
|
movq 0(%r11),%rcx
|
|
|
|
movq 0(%r11),%xmm0
|
|
|
|
subq $1, %r12
|
|
|
|
|
|
|
|
//second arg
|
|
|
|
cmp $0, %r12
|
|
|
|
je LOCAL(call)
|
|
|
|
movq 8(%r11),%rdx
|
|
|
|
movq 8(%r11),%xmm1
|
|
|
|
subq $1, %r12
|
|
|
|
|
|
|
|
//third arg
|
|
|
|
cmp $0, %r12
|
|
|
|
je LOCAL(call)
|
|
|
|
movq 16(%r11),%r8
|
|
|
|
movq 16(%r11),%xmm2
|
|
|
|
subq $1, %r12
|
|
|
|
|
|
|
|
//fourth arg
|
|
|
|
cmp $0, %r12
|
|
|
|
je LOCAL(call)
|
|
|
|
movq 24(%r11),%r9
|
|
|
|
movq 24(%r11),%xmm3
|
|
|
|
subq $1, %r12
|
|
|
|
|
|
|
|
|
|
|
|
//calculate stack space for arguments, aligned
|
|
|
|
movq $8, %r15
|
|
|
|
leaq (%r15, %r12, 8), %r15
|
|
|
|
andq $0xFFFFFFFFFFFFFFF0, %r15
|
|
|
|
|
|
|
|
//reserve stack space for arguments
|
|
|
|
subq %r15, %rsp
|
|
|
|
|
|
|
|
//reset the counter
|
|
|
|
addq $3, %r12
|
|
|
|
jmp LOCAL(loopend)
|
|
|
|
|
|
|
|
LOCAL(loop):
|
|
|
|
movq (%r11, %r12, 8), %r14
|
|
|
|
movq %r14, (%rsp, %r12, 8);
|
|
|
|
subq $1, %r12
|
|
|
|
|
|
|
|
LOCAL(loopend):
|
|
|
|
//we don't need to move arg 3 and lower
|
|
|
|
cmpq $3, %r12
|
|
|
|
jne LOCAL(loop)
|
|
|
|
|
|
|
|
LOCAL(call):
|
|
|
|
call *%r10
|
|
|
|
|
|
|
|
LOCAL(void):
|
|
|
|
cmpq $VOID_TYPE,%r13
|
|
|
|
jne LOCAL(float)
|
|
|
|
jmp LOCAL(exit)
|
|
|
|
|
|
|
|
LOCAL(float):
|
|
|
|
cmpq $FLOAT_TYPE,%r13
|
|
|
|
je LOCAL(copy)
|
|
|
|
cmpq $DOUBLE_TYPE,%r13
|
|
|
|
jne LOCAL(exit)
|
|
|
|
|
|
|
|
LOCAL(copy):
|
|
|
|
movq %xmm0,%rax
|
|
|
|
|
|
|
|
LOCAL(exit):
|
|
|
|
|
|
|
|
movq %rbp, %rsp
|
|
|
|
//return nonvolatile registers to their former state
|
|
|
|
popq %r15
|
|
|
|
popq %r14
|
|
|
|
popq %r13
|
|
|
|
popq %r12
|
2007-10-04 00:41:54 +00:00
|
|
|
|
2009-06-11 15:42:07 +00:00
|
|
|
popq %rbp
|
|
|
|
ret
|
|
|
|
|
2009-07-26 02:48:36 +00:00
|
|
|
.globl GLOBAL(vmJump)
|
|
|
|
GLOBAL(vmJump):
|
support stack unwinding without using a frame pointer
Previously, we unwound the stack by following the chain of frame
pointers for normal returns, stack trace creation, and exception
unwinding. On x86, this required reserving EBP/RBP for frame pointer
duties, making it unavailable for general computation and requiring
that it be explicitly saved and restored on entry and exit,
respectively.
On PowerPC, we use an ABI that makes the stack pointer double as a
frame pointer, so it doesn't cost us anything. We've been using the
same convention on ARM, but it doesn't match the native calling
convention, which makes it unusable when we want to call native code
from Java and pass arguments on the stack.
So far, the ARM calling convention mismatch hasn't been an issue
because we've never passed more arguments from Java to native code
than would fit in registers. However, we must now pass an extra
argument (the thread pointer) to e.g. divideLong so it can throw an
exception on divide by zero, which means the last argument must be
passed on the stack. This will clobber the linkage area we've been
using to hold the frame pointer, so we need to stop using it.
One solution would be to use the same convention on ARM as we do on
x86, but this would introduce the same overhead of making a register
unavailable for general use and extra code at method entry and exit.
Instead, this commit removes the need for a frame pointer. Unwinding
involves consulting a map of instruction offsets to frame sizes which
is generated at compile time. This is necessary because stack trace
creation can happen at any time due to Thread.getStackTrace being
called by another thread, and the frame size varies during the
execution of a method.
So far, only x86(_64) is working, and continuations and tail call
optimization are probably broken. More to come.
2011-01-17 02:05:05 +00:00
|
|
|
movq %r9,%rax
|
|
|
|
movq 40(%rsp),%rdx
|
|
|
|
movq %rdx,%rsp
|
|
|
|
movq %r8,%rbx
|
2009-06-11 15:42:07 +00:00
|
|
|
jmp *%rcx
|
2010-12-27 22:55:23 +00:00
|
|
|
|
|
|
|
#define VMRUN_FRAME_SIZE 80
|
|
|
|
|
|
|
|
.globl GLOBAL(vmRun)
|
|
|
|
GLOBAL(vmRun):
|
|
|
|
// %rcx: function
|
|
|
|
// %rdx: arguments
|
|
|
|
// %r8 : checkpoint
|
|
|
|
pushq %rbp
|
|
|
|
movq %rsp,%rbp
|
|
|
|
subq $VMRUN_FRAME_SIZE,%rsp
|
|
|
|
|
|
|
|
movq %rbx,16(%rsp)
|
|
|
|
movq %r12,24(%rsp)
|
|
|
|
movq %r13,32(%rsp)
|
|
|
|
movq %r14,40(%rsp)
|
|
|
|
movq %r15,48(%rsp)
|
|
|
|
movq %rsi,56(%rsp)
|
|
|
|
movq %rdi,64(%rsp)
|
|
|
|
|
|
|
|
movq %rsp,CHECKPOINT_STACK(%rcx)
|
|
|
|
|
|
|
|
movq %rcx,%r11
|
|
|
|
movq CHECKPOINT_THREAD(%rdx),%rcx
|
|
|
|
|
|
|
|
call *%r11
|
|
|
|
|
|
|
|
.globl GLOBAL(vmRun_returnAddress)
|
|
|
|
GLOBAL(vmRun_returnAddress):
|
|
|
|
|
|
|
|
movq 16(%rsp),%rbx
|
|
|
|
movq 24(%rsp),%r12
|
|
|
|
movq 32(%rsp),%r13
|
|
|
|
movq 40(%rsp),%r14
|
|
|
|
movq 48(%rsp),%r15
|
|
|
|
movq 56(%rsp),%rsi
|
|
|
|
movq 64(%rsp),%rdi
|
|
|
|
|
|
|
|
addq $VMRUN_FRAME_SIZE,%rsp
|
|
|
|
popq %rbp
|
|
|
|
ret
|
2009-06-11 15:42:07 +00:00
|
|
|
|
2009-07-26 02:48:36 +00:00
|
|
|
#else // not __MINGW32__
|
2009-08-10 19:20:23 +00:00
|
|
|
.globl GLOBAL(detectFeature)
|
|
|
|
GLOBAL(detectFeature):
|
2009-08-06 14:49:26 +00:00
|
|
|
pushq %rbp
|
|
|
|
movq %rsp, %rbp
|
|
|
|
pushq %rdx
|
|
|
|
pushq %rcx
|
|
|
|
pushq %rbx
|
|
|
|
movl $1, %eax
|
|
|
|
cpuid
|
|
|
|
andl %esi, %edx
|
|
|
|
andl %edi, %ecx
|
|
|
|
orl %edx, %ecx
|
|
|
|
test %ecx, %ecx
|
|
|
|
je LOCAL(NOSSE)
|
|
|
|
movl $1, %eax
|
|
|
|
jmp LOCAL(SSEEND)
|
|
|
|
LOCAL(NOSSE):
|
|
|
|
movl $0, %eax
|
|
|
|
LOCAL(SSEEND):
|
|
|
|
popq %rbx
|
|
|
|
popq %rcx
|
|
|
|
popq %rdx
|
|
|
|
movq %rbp,%rsp
|
|
|
|
popq %rbp
|
|
|
|
ret
|
2009-06-11 15:42:07 +00:00
|
|
|
|
2009-07-26 02:48:36 +00:00
|
|
|
.globl GLOBAL(vmNativeCall)
|
|
|
|
GLOBAL(vmNativeCall):
|
2007-06-29 02:58:48 +00:00
|
|
|
pushq %rbp
|
2008-04-23 21:07:14 +00:00
|
|
|
movq %rsp,%rbp
|
2007-06-29 02:58:48 +00:00
|
|
|
|
2008-04-23 21:07:14 +00:00
|
|
|
// %rdi aka -48(%rbp): function
|
|
|
|
// %rsi aka -40(%rbp): stack
|
|
|
|
// %rdx aka -32(%rbp): stackSize
|
|
|
|
// %rcx aka -24(%rbp): gprTable
|
|
|
|
// %r8 aka -16(%rbp): sseTable
|
|
|
|
// %r9 aka -8(%rbp): returnType
|
2007-06-29 02:58:48 +00:00
|
|
|
|
|
|
|
// save our argument registers so we can clobber them
|
|
|
|
pushq %r9
|
|
|
|
pushq %r8
|
|
|
|
pushq %rcx
|
|
|
|
pushq %rdx
|
|
|
|
pushq %rsi
|
|
|
|
pushq %rdi
|
|
|
|
|
|
|
|
// reserve space for arguments passed via memory
|
|
|
|
subq %rdx,%rsp
|
2007-12-18 02:08:17 +00:00
|
|
|
|
|
|
|
// align to a 16 byte boundary
|
|
|
|
andq $0xFFFFFFFFFFFFFFF0,%rsp
|
2007-06-29 02:58:48 +00:00
|
|
|
|
|
|
|
// copy memory arguments into place
|
|
|
|
movq $0,%rcx
|
2008-06-15 18:49:37 +00:00
|
|
|
jmp LOCAL(test)
|
2007-06-29 02:58:48 +00:00
|
|
|
|
2008-06-15 18:49:37 +00:00
|
|
|
LOCAL(loop):
|
2007-06-29 02:58:48 +00:00
|
|
|
movq %rcx,%rax
|
|
|
|
movq %rcx,%rdx
|
|
|
|
addq %rsp,%rdx
|
2008-04-23 21:07:14 +00:00
|
|
|
addq -40(%rbp),%rax
|
|
|
|
movq (%rax),%rax
|
2007-06-29 02:58:48 +00:00
|
|
|
movq %rax,(%rdx)
|
|
|
|
addq $8,%rcx
|
|
|
|
|
2008-06-15 18:49:37 +00:00
|
|
|
LOCAL(test):
|
2008-04-23 21:07:14 +00:00
|
|
|
cmpq -32(%rbp),%rcx
|
2008-06-15 18:49:37 +00:00
|
|
|
jb LOCAL(loop)
|
2007-06-29 02:58:48 +00:00
|
|
|
|
|
|
|
// do we need to load the general-purpose registers?
|
2008-04-23 21:07:14 +00:00
|
|
|
cmpq $0,-24(%rbp)
|
2008-06-15 18:49:37 +00:00
|
|
|
je LOCAL(sse)
|
2007-06-29 02:58:48 +00:00
|
|
|
|
|
|
|
// yes, we do
|
2008-04-23 21:07:14 +00:00
|
|
|
movq -24(%rbp),%rax
|
2007-06-29 02:58:48 +00:00
|
|
|
movq 0(%rax),%rdi
|
|
|
|
movq 8(%rax),%rsi
|
2007-06-29 16:42:39 +00:00
|
|
|
movq 16(%rax),%rdx
|
|
|
|
movq 24(%rax),%rcx
|
2007-06-29 02:58:48 +00:00
|
|
|
movq 32(%rax),%r8
|
|
|
|
movq 40(%rax),%r9
|
|
|
|
|
2008-06-15 18:49:37 +00:00
|
|
|
LOCAL(sse):
|
2007-06-29 02:58:48 +00:00
|
|
|
// do we need to load the SSE registers?
|
2008-04-23 21:07:14 +00:00
|
|
|
cmpq $0,-16(%rbp)
|
2008-06-15 18:49:37 +00:00
|
|
|
je LOCAL(call)
|
2007-06-29 02:58:48 +00:00
|
|
|
|
|
|
|
// yes, we do
|
2008-04-23 21:07:14 +00:00
|
|
|
movq -16(%rbp),%rax
|
2007-06-29 02:58:48 +00:00
|
|
|
movq 0(%rax),%xmm0
|
|
|
|
movq 8(%rax),%xmm1
|
|
|
|
movq 16(%rax),%xmm2
|
|
|
|
movq 24(%rax),%xmm3
|
|
|
|
movq 32(%rax),%xmm4
|
|
|
|
movq 40(%rax),%xmm5
|
|
|
|
movq 48(%rax),%xmm6
|
|
|
|
movq 64(%rax),%xmm7
|
|
|
|
|
2008-06-15 18:49:37 +00:00
|
|
|
LOCAL(call):
|
2008-04-23 21:07:14 +00:00
|
|
|
call *-48(%rbp)
|
2007-06-29 02:58:48 +00:00
|
|
|
|
|
|
|
// handle return value based on expected type
|
2008-04-23 21:07:14 +00:00
|
|
|
movq -8(%rbp),%rcx
|
2007-06-29 02:58:48 +00:00
|
|
|
|
2008-06-15 18:49:37 +00:00
|
|
|
LOCAL(void):
|
2007-06-29 02:58:48 +00:00
|
|
|
cmpq $VOID_TYPE,%rcx
|
2008-06-15 18:49:37 +00:00
|
|
|
jne LOCAL(float)
|
|
|
|
jmp LOCAL(exit)
|
2007-06-29 02:58:48 +00:00
|
|
|
|
2008-06-15 18:49:37 +00:00
|
|
|
LOCAL(float):
|
2007-06-29 02:58:48 +00:00
|
|
|
cmpq $FLOAT_TYPE,%rcx
|
2008-06-15 18:49:37 +00:00
|
|
|
je LOCAL(copy)
|
2007-06-29 02:58:48 +00:00
|
|
|
cmpq $DOUBLE_TYPE,%rcx
|
2008-06-15 18:49:37 +00:00
|
|
|
jne LOCAL(exit)
|
2007-06-29 02:58:48 +00:00
|
|
|
|
2008-06-15 18:49:37 +00:00
|
|
|
LOCAL(copy):
|
2009-10-14 16:01:37 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
// as of OS X 10.6, Apple is still using an assembler that doesn't
|
|
|
|
// understand movq SSE,GPR, but movd does the same thing, despite
|
|
|
|
// the name
|
|
|
|
movd %xmm0,%rax
|
|
|
|
#else
|
2007-06-29 02:58:48 +00:00
|
|
|
movq %xmm0,%rax
|
2009-10-14 16:01:37 +00:00
|
|
|
#endif
|
2007-06-29 02:58:48 +00:00
|
|
|
|
2008-06-15 18:49:37 +00:00
|
|
|
LOCAL(exit):
|
2007-06-29 02:58:48 +00:00
|
|
|
movq %rbp,%rsp
|
|
|
|
popq %rbp
|
|
|
|
ret
|
2007-10-04 00:41:54 +00:00
|
|
|
|
2009-07-26 02:48:36 +00:00
|
|
|
.globl GLOBAL(vmJump)
|
|
|
|
GLOBAL(vmJump):
|
support stack unwinding without using a frame pointer
Previously, we unwound the stack by following the chain of frame
pointers for normal returns, stack trace creation, and exception
unwinding. On x86, this required reserving EBP/RBP for frame pointer
duties, making it unavailable for general computation and requiring
that it be explicitly saved and restored on entry and exit,
respectively.
On PowerPC, we use an ABI that makes the stack pointer double as a
frame pointer, so it doesn't cost us anything. We've been using the
same convention on ARM, but it doesn't match the native calling
convention, which makes it unusable when we want to call native code
from Java and pass arguments on the stack.
So far, the ARM calling convention mismatch hasn't been an issue
because we've never passed more arguments from Java to native code
than would fit in registers. However, we must now pass an extra
argument (the thread pointer) to e.g. divideLong so it can throw an
exception on divide by zero, which means the last argument must be
passed on the stack. This will clobber the linkage area we've been
using to hold the frame pointer, so we need to stop using it.
One solution would be to use the same convention on ARM as we do on
x86, but this would introduce the same overhead of making a register
unavailable for general use and extra code at method entry and exit.
Instead, this commit removes the need for a frame pointer. Unwinding
involves consulting a map of instruction offsets to frame sizes which
is generated at compile time. This is necessary because stack trace
creation can happen at any time due to Thread.getStackTrace being
called by another thread, and the frame size varies during the
execution of a method.
So far, only x86(_64) is working, and continuations and tail call
optimization are probably broken. More to come.
2011-01-17 02:05:05 +00:00
|
|
|
movq %rsi,%rsp
|
|
|
|
movq %rdx,%rbx
|
|
|
|
movq %rcx,%rax
|
|
|
|
movq %r8,%rdx
|
2008-01-01 17:08:47 +00:00
|
|
|
jmp *%rdi
|
2009-08-10 19:20:23 +00:00
|
|
|
|
2010-12-27 22:55:23 +00:00
|
|
|
#define VMRUN_FRAME_SIZE 64
|
|
|
|
|
|
|
|
.globl GLOBAL(vmRun)
|
|
|
|
GLOBAL(vmRun):
|
|
|
|
// %rdi: function
|
|
|
|
// %rsi: arguments
|
|
|
|
// %rdx: checkpoint
|
|
|
|
pushq %rbp
|
|
|
|
movq %rsp,%rbp
|
|
|
|
subq $VMRUN_FRAME_SIZE,%rsp
|
|
|
|
|
|
|
|
movq %rbx,16(%rsp)
|
|
|
|
movq %r12,24(%rsp)
|
|
|
|
movq %r13,32(%rsp)
|
|
|
|
movq %r14,40(%rsp)
|
|
|
|
movq %r15,48(%rsp)
|
|
|
|
|
|
|
|
movq %rsp,CHECKPOINT_STACK(%rdx)
|
|
|
|
|
|
|
|
movq %rdi,%r11
|
|
|
|
movq CHECKPOINT_THREAD(%rdx),%rdi
|
|
|
|
|
|
|
|
call *%r11
|
|
|
|
|
|
|
|
.globl GLOBAL(vmRun_returnAddress)
|
|
|
|
GLOBAL(vmRun_returnAddress):
|
|
|
|
|
|
|
|
movq 16(%rsp),%rbx
|
|
|
|
movq 24(%rsp),%r12
|
|
|
|
movq 32(%rsp),%r13
|
|
|
|
movq 40(%rsp),%r14
|
|
|
|
movq 48(%rsp),%r15
|
|
|
|
|
|
|
|
addq $VMRUN_FRAME_SIZE,%rsp
|
|
|
|
popq %rbp
|
|
|
|
ret
|
|
|
|
|
2009-07-26 02:48:36 +00:00
|
|
|
#endif // not __MINGW32__
|
2008-01-01 17:08:47 +00:00
|
|
|
|
2007-10-04 00:41:54 +00:00
|
|
|
#elif defined __i386__
|
2007-10-24 17:24:19 +00:00
|
|
|
|
2010-12-27 22:55:23 +00:00
|
|
|
#define CHECKPOINT_THREAD 4
|
|
|
|
#define CHECKPOINT_STACK 24
|
|
|
|
#define CHECKPOINT_BASE 28
|
|
|
|
|
2009-08-10 19:20:23 +00:00
|
|
|
.globl GLOBAL(detectFeature)
|
|
|
|
GLOBAL(detectFeature):
|
2009-08-06 14:49:26 +00:00
|
|
|
pushl %ebp
|
|
|
|
movl %esp, %ebp
|
|
|
|
pushl %edx
|
|
|
|
pushl %ecx
|
|
|
|
pushl %ebx
|
|
|
|
pushl %esi
|
|
|
|
pushl %edi
|
|
|
|
movl 12(%ebp), %esi
|
|
|
|
movl 8(%ebp), %edi
|
|
|
|
movl $1, %eax
|
|
|
|
cpuid
|
|
|
|
andl %esi, %edx
|
|
|
|
andl %edi, %ecx
|
|
|
|
orl %edx, %ecx
|
|
|
|
test %ecx, %ecx
|
|
|
|
je LOCAL(NOSSE)
|
|
|
|
movl $1, %eax
|
|
|
|
jmp LOCAL(SSEEND)
|
|
|
|
LOCAL(NOSSE):
|
|
|
|
movl $0, %eax
|
|
|
|
LOCAL(SSEEND):
|
|
|
|
popl %edi
|
|
|
|
popl %esi
|
|
|
|
popl %ebx
|
|
|
|
popl %ecx
|
|
|
|
popl %edx
|
|
|
|
movl %ebp,%esp
|
|
|
|
popl %ebp
|
|
|
|
ret
|
2009-08-10 19:20:23 +00:00
|
|
|
|
2009-07-26 02:48:36 +00:00
|
|
|
.globl GLOBAL(vmNativeCall)
|
|
|
|
GLOBAL(vmNativeCall):
|
2007-10-04 00:41:54 +00:00
|
|
|
pushl %ebp
|
|
|
|
movl %esp,%ebp
|
|
|
|
|
|
|
|
// 8(%ebp): function
|
|
|
|
// 12(%ebp): stack
|
|
|
|
// 16(%ebp): stackSize
|
|
|
|
// 20(%ebp): returnType
|
|
|
|
|
|
|
|
// reserve space for arguments
|
|
|
|
movl 16(%ebp),%ecx
|
2007-10-04 03:19:39 +00:00
|
|
|
|
|
|
|
subl %ecx,%esp
|
2007-10-04 00:41:54 +00:00
|
|
|
|
2007-10-24 17:24:19 +00:00
|
|
|
# ifdef __APPLE__
|
2007-10-04 00:41:54 +00:00
|
|
|
// align to a 16 byte boundary on Darwin
|
2007-10-04 03:19:39 +00:00
|
|
|
andl $0xFFFFFFF0,%esp
|
2007-10-24 17:24:19 +00:00
|
|
|
# endif
|
2007-10-04 00:41:54 +00:00
|
|
|
|
|
|
|
// copy arguments into place
|
|
|
|
movl $0,%ecx
|
2008-06-15 18:49:37 +00:00
|
|
|
jmp LOCAL(test)
|
2007-10-04 00:41:54 +00:00
|
|
|
|
2008-06-15 18:49:37 +00:00
|
|
|
LOCAL(loop):
|
2007-10-04 00:41:54 +00:00
|
|
|
movl %ecx,%eax
|
|
|
|
movl %ecx,%edx
|
|
|
|
addl %esp,%edx
|
|
|
|
addl 12(%ebp),%eax
|
|
|
|
movl (%eax),%eax
|
|
|
|
movl %eax,(%edx)
|
|
|
|
addl $4,%ecx
|
|
|
|
|
2008-06-15 18:49:37 +00:00
|
|
|
LOCAL(test):
|
2007-10-04 00:41:54 +00:00
|
|
|
cmpl 16(%ebp),%ecx
|
2008-06-15 18:49:37 +00:00
|
|
|
jb LOCAL(loop)
|
2007-10-04 00:41:54 +00:00
|
|
|
|
|
|
|
// call function
|
|
|
|
call *8(%ebp)
|
|
|
|
|
|
|
|
// handle return value based on expected type
|
|
|
|
movl 20(%ebp),%ecx
|
|
|
|
|
2008-06-15 18:49:37 +00:00
|
|
|
LOCAL(void):
|
2007-10-04 00:41:54 +00:00
|
|
|
cmpl $VOID_TYPE,%ecx
|
2008-06-15 18:49:37 +00:00
|
|
|
jne LOCAL(int64)
|
|
|
|
jmp LOCAL(exit)
|
2007-10-04 00:41:54 +00:00
|
|
|
|
2008-06-15 18:49:37 +00:00
|
|
|
LOCAL(int64):
|
2007-10-04 00:41:54 +00:00
|
|
|
cmpl $INT64_TYPE,%ecx
|
2008-06-15 18:49:37 +00:00
|
|
|
jne LOCAL(float)
|
|
|
|
jmp LOCAL(exit)
|
2007-10-04 00:41:54 +00:00
|
|
|
|
2008-06-15 18:49:37 +00:00
|
|
|
LOCAL(float):
|
2007-10-04 00:41:54 +00:00
|
|
|
cmpl $FLOAT_TYPE,%ecx
|
2008-06-15 18:49:37 +00:00
|
|
|
jne LOCAL(double)
|
2007-10-04 00:41:54 +00:00
|
|
|
fstps 8(%ebp)
|
|
|
|
movl 8(%ebp),%eax
|
2008-06-15 18:49:37 +00:00
|
|
|
jmp LOCAL(exit)
|
2007-10-04 00:41:54 +00:00
|
|
|
|
2008-06-15 18:49:37 +00:00
|
|
|
LOCAL(double):
|
2007-10-04 00:41:54 +00:00
|
|
|
cmpl $DOUBLE_TYPE,%ecx
|
2008-06-15 18:49:37 +00:00
|
|
|
jne LOCAL(exit)
|
2007-10-04 00:41:54 +00:00
|
|
|
fstpl 8(%ebp)
|
|
|
|
movl 8(%ebp),%eax
|
|
|
|
movl 12(%ebp),%edx
|
|
|
|
|
2008-06-15 18:49:37 +00:00
|
|
|
LOCAL(exit):
|
2007-10-04 00:41:54 +00:00
|
|
|
movl %ebp,%esp
|
|
|
|
popl %ebp
|
|
|
|
ret
|
2008-01-01 17:08:47 +00:00
|
|
|
|
2009-07-26 02:48:36 +00:00
|
|
|
.globl GLOBAL(vmJump)
|
|
|
|
GLOBAL(vmJump):
|
2009-05-25 00:57:59 +00:00
|
|
|
movl 4(%esp),%esi
|
support stack unwinding without using a frame pointer
Previously, we unwound the stack by following the chain of frame
pointers for normal returns, stack trace creation, and exception
unwinding. On x86, this required reserving EBP/RBP for frame pointer
duties, making it unavailable for general computation and requiring
that it be explicitly saved and restored on entry and exit,
respectively.
On PowerPC, we use an ABI that makes the stack pointer double as a
frame pointer, so it doesn't cost us anything. We've been using the
same convention on ARM, but it doesn't match the native calling
convention, which makes it unusable when we want to call native code
from Java and pass arguments on the stack.
So far, the ARM calling convention mismatch hasn't been an issue
because we've never passed more arguments from Java to native code
than would fit in registers. However, we must now pass an extra
argument (the thread pointer) to e.g. divideLong so it can throw an
exception on divide by zero, which means the last argument must be
passed on the stack. This will clobber the linkage area we've been
using to hold the frame pointer, so we need to stop using it.
One solution would be to use the same convention on ARM as we do on
x86, but this would introduce the same overhead of making a register
unavailable for general use and extra code at method entry and exit.
Instead, this commit removes the need for a frame pointer. Unwinding
involves consulting a map of instruction offsets to frame sizes which
is generated at compile time. This is necessary because stack trace
creation can happen at any time due to Thread.getStackTrace being
called by another thread, and the frame size varies during the
execution of a method.
So far, only x86(_64) is working, and continuations and tail call
optimization are probably broken. More to come.
2011-01-17 02:05:05 +00:00
|
|
|
movl 12(%esp),%ebx
|
|
|
|
movl 16(%esp),%eax
|
|
|
|
movl 20(%esp),%edx
|
|
|
|
movl 8(%esp),%esp
|
2009-05-25 00:57:59 +00:00
|
|
|
jmp *%esi
|
2007-10-04 00:41:54 +00:00
|
|
|
|
2010-12-27 22:55:23 +00:00
|
|
|
#define VMRUN_FRAME_SIZE 32
|
|
|
|
|
|
|
|
.globl GLOBAL(vmRun)
|
|
|
|
GLOBAL(vmRun):
|
|
|
|
// 8(%ebp): function
|
|
|
|
// 12(%ebp): arguments
|
|
|
|
// 16(%ebp): checkpoint
|
|
|
|
pushl %ebp
|
|
|
|
movl %esp,%ebp
|
|
|
|
subl $VMRUN_FRAME_SIZE,%esp
|
|
|
|
|
|
|
|
movl %ebx,8(%esp)
|
|
|
|
movl %esi,12(%esp)
|
|
|
|
movl %edi,16(%esp)
|
|
|
|
|
|
|
|
movl 12(%ebp),%eax
|
|
|
|
movl %eax,4(%esp)
|
|
|
|
|
|
|
|
movl 16(%ebp),%ecx
|
|
|
|
movl CHECKPOINT_THREAD(%ecx),%eax
|
|
|
|
movl %eax,0(%esp)
|
|
|
|
|
|
|
|
movl %esp,CHECKPOINT_STACK(%ecx)
|
|
|
|
|
|
|
|
call *8(%ebp)
|
|
|
|
|
|
|
|
.globl GLOBAL(vmRun_returnAddress)
|
|
|
|
GLOBAL(vmRun_returnAddress):
|
|
|
|
|
|
|
|
movl 8(%esp),%ebx
|
|
|
|
movl 12(%esp),%esi
|
|
|
|
movl 16(%esp),%edi
|
|
|
|
|
|
|
|
addl $VMRUN_FRAME_SIZE,%esp
|
|
|
|
popl %ebp
|
|
|
|
ret
|
|
|
|
|
|
|
|
#endif // __i386__
|