This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: class initialization check overhead
- From: Jeff Sturm <jsturm at one-point dot com>
- To: Adam Megacz <adam at megacz dot com>
- Cc: java at gcc dot gnu dot org
- Date: Wed, 23 Oct 2002 22:41:28 -0400 (EDT)
- Subject: Re: class initialization check overhead
On 23 Oct 2002, Adam Megacz wrote:
> Jeff Sturm <jsturm@one-point.com> writes:
> > Or are you suggesting something like PROT_NONE, as in a guard page?
>
> Whoops, yes, that's what I meant. Would this work?
I don't know.
> Could _Jv_InitClass be re-jiggered to perform all the register saves
> itself (rather than asking the caller to do it)? In other words, put
> a PUSHALL at the beginning and a POPALL at the end?
Not without doing away with the calling convention, CALL_EXPR, etc.
Some trapping instruction might be better, like below. This example only
clobbers eax and memory, and overwrites the single-byte INT3 with one NOP.
#include <stdio.h>
#include <sys/mman.h>
#include <sys/signal.h>
#include <asm/param.h>
static void handler(int signum, struct sigcontext sc) {
unsigned char *ip = (unsigned char *)sc.eip - 1;
*((int *)sc.eax) += 1;
if (*ip == 0xcc) {
if (mprotect ((void *)(((unsigned long)ip) & ~(EXEC_PAGESIZE-1)),
EXEC_PAGESIZE, PROT_READ | PROT_WRITE | PROT_EXEC) < 0)
abort();
*ip = 0x90;
}
}
static inline void trap(volatile int *p) {
asm volatile("int $3" : : "a" (p) : "memory");
}
int main(void) {
struct sigaction sa;
int n;
static volatile int x = 0;
sa.sa_flags = SA_RESTART;
sa.sa_handler = handler;
sigaction(SIGTRAP, &sa, NULL);
printf("%d\n", x);
for (n = 0; n < 10; n++) trap(&x);
printf("%d\n", x);
}