class initialization check overhead

Jeff Sturm jsturm@one-point.com
Wed Oct 23 19:41:00 GMT 2002


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);
}



More information about the Java mailing list