55 #include <java-superend.i>
59 #include <java-names.i>
63 #define INST_ADDR(_inst) N_##_inst
64 #include <java-labels.i>
100 #define HASHTABLE_PATCHERSUPERS_BITS 14
102 #if defined(ENABLE_THREADS)
114 #define HASHTABLE_SUPERREUSE_BITS 14
116 #if defined(ENABLE_THREADS)
120 # define debugp(x...) if (opt_verbose) fprintf(x)
121 #define debugp1(x...)
148 char *a = *(
char **)pa;
149 char *b = *(
char **)pb;
205 Label *symbols2, *symbols3, *js1, *ks1, *ks1sorted;
206 Label after_goto, before_goto2;
210 fprintf(stderr,
"Compiled with gcc-" __VERSION__
"\n");
212 for (i=0; symbols1[
i]!=0; i++)
221 symbols3=(
Inst *)engine3(0,0,0);
228 after_goto = ks1[i+2];
229 before_goto2 = (ks1+(symbols2-symbols1))[i+1];
233 ks1sorted = (
Label *)alloca((i+1)*
sizeof(
Label));
239 debugp(stderr,
"goto * %p %p len=%d\n",
241 if (memcmp(before_goto, before_goto2,
goto_len)!=0) {
242 opt_no_dynamic =
true;
243 debugp(stderr,
" not relocatable, disabling dynamic code generation\n");
247 priminfos = calloc(i,
sizeof(
PrimInfo));
248 for (i=0; symbols1[
i]!=0; i++) {
254 int prim_len = js1[
i]-symbols1[
i];
257 char *
s1 = (
char *)symbols1[i];
258 char *
s2 = (
char *)symbols2[i];
259 char *
s3 = (
char *)symbols3[i];
268 debugp(stderr,
"%-15s %3d %p %p %p len=%3ld restlen=%2ld s-end=%1d",
270 if (endlabel == NULL) {
273 debugp(stderr,
"\n non_reloc: no K label > start found\n");
276 if (js1[i] > endlabel && !pi->
superend) {
278 pi->
length = endlabel-symbols1[
i];
279 debugp(stderr,
"\n non_reloc: there is a K label before the J label (restlength<0)\n");
284 pi->
length = endlabel-symbols1[
i];
285 debugp(stderr,
"\n non_reloc: J label before I label (length<0)\n");
292 if (s1[j] != s2[j]) {
294 debugp(stderr,
"\n non_reloc: engine1!=engine2 offset %3d",j);
312 return !opt_no_dynamic && priminfos[p].
start != NULL;
321 cd->ncodebase + cd->ncodesize) {
322 cd->ncodeptr = codegen_ncode_increase(cd, cd->ncodeptr);
325 cd->ncodeptr += pi->
length;
331 cd->lastpatcheroffset = -1;
333 cd->dynsupern = cd->ncodeptr - cd->ncodebase;
352 for (i=0; i<(length&(~3)); i+=
sizeof(
u4)) {
353 r += *(
s4 *)(code+i);
383 for (; sr != NULL; sr = sr->
next)
384 if (length == sr->
length && memcmp(code, sr->
code, length)==0)
406 for (; ss=*listp, ss!=NULL; listp = &(ss->next)) {
407 if (p == ((
Inst *)(ss->mcodebase + ss->patcherm))) {
409 if (ss->oldsuper != NULL)
410 target = (
Inst)ss->oldsuper;
412 target = (
Inst)(ss->ncodebase + ss->dynsupern);
413 *(
Inst *)(ss->mcodebase + ss->dynsuperm) =
target;
414 debugp1(stderr,
"patcher rewrote %p into %p\n",
415 ss->mcodebase + ss->dynsuperm, target);
431 void **listp = &hashtable_patchersupers.
ptr[
slot];
449 for (; ss != NULL; ss = ssnext) {
451 if (opt_no_replication && ss->
oldsuper == NULL)
457 debugp1(stderr,
"rewrote %p into %p\n",
478 u1 *
code = cd->ncodebase + cd->dynsupern;
481 if (opt_no_replication) {
483 if (oldsuper != NULL) {
487 if (cd->lastpatcheroffset == -1) {
489 debugp1(stderr,
"rewrote %p into %p (reused)\n",
495 if (cd->lastpatcheroffset == -1) {
502 ss->
patcherm = cd->lastpatcheroffset;
507 ss->
next = cd->superstarts;
508 cd->superstarts = ss;
515 if (cd->lastinstwithoutdispatch != ~0) {
516 PrimInfo *pi = &priminfos[cd->lastinstwithoutdispatch];
522 cd->lastinstwithoutdispatch = ~0;
536 if (cd->lastinstwithoutdispatch != ~0)
541 if (cd->dynsuperm == -1)
544 cd->lastinstwithoutdispatch = p;
553 if (opt_no_quicksuper) {
569 case N_PATCHER_ARRAYCHECKCAST:
replace_patcher(cd, N_ARRAYCHECKCAST);
break;
570 case N_PATCHER_GETSTATIC_INT:
replace_patcher(cd, N_GETSTATIC_INT);
break;
571 case N_PATCHER_GETSTATIC_LONG:
replace_patcher(cd, N_GETSTATIC_LONG);
break;
572 case N_PATCHER_GETSTATIC_CELL:
replace_patcher(cd, N_GETSTATIC_CELL);
break;
573 case N_PATCHER_PUTSTATIC_INT:
replace_patcher(cd, N_PUTSTATIC_INT);
break;
574 case N_PATCHER_PUTSTATIC_LONG:
replace_patcher(cd, N_PUTSTATIC_LONG);
break;
575 case N_PATCHER_PUTSTATIC_CELL:
replace_patcher(cd, N_PUTSTATIC_CELL);
break;
576 case N_PATCHER_GETFIELD_INT:
replace_patcher(cd, N_GETFIELD_INT);
break;
577 case N_PATCHER_GETFIELD_LONG:
replace_patcher(cd, N_GETFIELD_LONG);
break;
578 case N_PATCHER_GETFIELD_CELL:
replace_patcher(cd, N_GETFIELD_CELL);
break;
579 case N_PATCHER_PUTFIELD_INT:
replace_patcher(cd, N_PUTFIELD_INT);
break;
580 case N_PATCHER_PUTFIELD_LONG:
replace_patcher(cd, N_PUTFIELD_LONG);
break;
581 case N_PATCHER_PUTFIELD_CELL:
replace_patcher(cd, N_PUTFIELD_CELL);
break;
582 case N_PATCHER_MULTIANEWARRAY:
replace_patcher(cd, N_MULTIANEWARRAY);
break;
583 case N_PATCHER_INVOKESTATIC:
replace_patcher(cd, N_INVOKESTATIC);
break;
584 case N_PATCHER_INVOKESPECIAL:
replace_patcher(cd, N_INVOKESPECIAL);
break;
585 case N_PATCHER_INVOKEVIRTUAL:
replace_patcher(cd, N_INVOKEVIRTUAL);
break;
586 case N_PATCHER_INVOKEINTERFACE:
replace_patcher(cd, N_INVOKEINTERFACE);
break;
589 case N_PATCHER_NATIVECALL:
595 case N_TRANSLATE:
break;
631 if (lastmcodeptr != NULL) {
634 assert((
u1 *) lastmcodeptr < cd->mcodeptr &&
640 *lastmcodeptr = combo;
674 #if defined(ENABLE_DISASSEMBLER)
675 void disassemble_prim(
int n)
680 #if defined(ENABLE_JIT)
691 #if defined(ENABLE_DISASSEMBLER)
693 disassemble_prim(N_IADD);
694 disassemble_prim(N_ILOAD);
695 disassemble_prim(N_GETFIELD_INT);
700 if (opt_no_replication)
703 #if defined(ENABLE_THREADS)
jlong jlong jlong jlong jint jmethodID jint slot
static void new_dynamic_super(codegendata *cd)
void gen_inst1(codegendata *cd, ptrint instr)
static void init_dynamic_super(codegendata *cd)
void dynamic_super_rewrite(codegendata *cd)
void finish_ss(codegendata *cd)
#define LOCK_MONITOR_EXIT(o)
static Label bsearch_next(Label key, Label *a, u4 n)
static int compare_labels(const void *pa, const void *pb)
void patchersuper_rewrite(Inst *p)
static void hashtable_patchersupers_insert(superstart *ss)
static bool is_relocatable(ptrint p)
static java_objectheader * lock_hashtable_patchersupers
static java_objectheader * lock_hashtable_superreuse
void gen_inst(codegendata *cd, ptrint instr)
static hashtable hashtable_superreuse
struct superreuse superreuse
static hashtable hashtable_patchersupers
static void append_prim(codegendata *cd, ptrint p)
static void superreuse_insert(u1 *code, u4 length)
static void check_prims(Label symbols1[])
ptrint peephole_opt(ptrint inst1, ptrint inst2, Cell peeptable)
const char *const prim_names[]
java_objectheader * engine2(Inst *ip0, Cell *sp, Cell *fp)
static u1 * superreuse_lookup(u1 *code, u4 length)
static u4 hash_superreuse(u1 *code, u4 length)
struct superstart superstart
static void replace_patcher(codegendata *cd, ptrint p)
#define HASHTABLE_PATCHERSUPERS_BITS
void append_dispatch(codegendata *cd)
#define LOCK_MONITOR_ENTER(o)
static void compile_prim_dyn(codegendata *cd, ptrint p)
void disassemble(u1 *start, u1 *end)
#define HASHTABLE_SUPERREUSE_BITS
#define MCOPY(dest, src, type, num)
void hashtable_create(hashtable *hash, u4 size)
void dynamic_super_init(void)
Represent an instance of a VM.
const char const void jint length
static char MAYBE_UNUSED superend[]
void print_dynamic_super_statistics(void)