/* vm/jit/codegen.inc - architecture independent code generator
- Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
- Institut f. Computersprachen, TU Wien
- R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser, M. Probst,
- S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich,
- J. Wenninger
+ Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
+ R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
+ C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
+ Institut f. Computersprachen - TU Wien
This file is part of CACAO.
Authors: Reinhard Grafl
Andreas Krall
- Changes: Michael Gschwind
- Christian Thalinger
+ Changes: Christian Thalinger
+ Joseph Wenninger
All functions assume the following code area / data area layout:
memory. All functions writing values into the data area return the offset
relative the begin of the code area (start of procedure).
- $Id: codegen.inc 1621 2004-11-30 13:06:55Z twisti $
+ $Id: codegen.inc 1735 2004-12-07 14:33:27Z twisti $
*/
+#ifndef _CODEGEN_INC_H_
+#define _CODEGEN_INC_H_
#include <string.h>
static void codegen_createlinenumbertable(codegendata *cd)
{
-#ifdef __I386__
+#if defined(__I386__) || defined(__ALPHA__)
linenumberref *lr;
for (lr = cd->linenumberreferences; lr != NULL; lr = lr->next) {
}
#endif
+#if defined(__ALPHA__)
+/*perhaps in the end I'll have to go for the tree version on alpha too, since this is insecure for eg segfault signals in native code,
+since it will still return an adress of a datasegment, but which will not be a valid one of a java method. This version is faster though (jowenn)*/
+void *codegen_findmethod(void *returnAdress)
+ {
+ void *result;
+ s8 d;
+ void *dataseg;
+ d=*((s4*)returnAdress);
+ d=d<<48;
+ d=d>>48;
+ dataseg=returnAdress+d;
+ d=*(((s4*)returnAdress)+1);
+ d=d>>16;
+ d=d-0x177b;
+ if (d==0) {
+ d=*(((s4*)returnAdress)+1);
+ d=d<<16;
+ dataseg=dataseg+d;
+ }
+ return dataseg;
+#if 0
+ ldl t0,0(ra) /* load instruction LDA PV,xxx(RA) */
+ sll t0,48,t0
+ sra t0,48,t0 /* isolate offset */
+ addq t0,ra,pv /* compute update address */
+ ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
+ srl t0,16,t0 /* isolate instruction code */
+ lda t0,-0x177b(t0) /* test for LDAH */
+ bne t0,ex_stack_loop
+ ldl t0,4(ra) /* load instruction LDAH PV,xxx(RA) */
+ sll t0,16,t0 /* compute high offset */
+ addl t0,0,t0 /* sign extend high offset */
+ addq t0,pv,pv /* compute update address */
+ br ex_stack_loop
+#endif
+}
+
+#endif
+
static void codegen_finish(methodinfo *m, codegendata *cd, s4 mcodelen)
{
jr = jr->next;
}
-#ifdef __I386__
+#if defined(__I386__) || defined(__ALPHA__)
/* line number table resolving */
{
linenumberref *lr;
void *sym;
builtin_monitorenter((java_objectheader*) m);
+#if defined(__X86_64__)
+ if ((*((s4*)jmpPatchTarget))==((s4)jmpTarget)) {
+#else
if ((*jmpPatchTarget)==jmpTarget) {
+#endif
builtin_monitorexit((java_objectheader*) m);
return;
}
- log_text("trying to resolve a native method");
+ /*log_text("trying to resolve a native method");
utf_display(m->class->name);
- utf_display(m->name);
+ utf_display(m->name);*/
- lib=dlopen(0,RTLD_NOW | RTLD_GLOBAL);
- if (lib) {
+ lib=dlopen(0,RTLD_NOW | RTLD_GLOBAL); /* open the application execution image */
+ if (lib) { /* it did work -> good, otherwise fail with error*/
int ok=0;
/*generate the name of the native function in the form Java_package1_package2...._classname_methodname*/
nativeLen=/*Java_*/5+strlen(m->class->name->text)+/*_*/1+strlen(m->name->text)+/*\0*/1;
/* printf("nativename: %s\n",nativeName); */
+ /*try to find the symbal fo the function */
sym=dlsym(lib,nativeName);
if (sym) {
- ok=1;
- log_text("resolved");
+ ok=1; /* it worked, everything fine */
+ /*log_text("resolved");*/
MFREE(nativeName,char,nativeLen);
- } else {
+ } else { /* we didn't find the symbol yet, try to resolve an overlaoded function (having the types in it's name*/
size_t overloadedNativeLen=nativeLen+codegen_overloadPartLen(m->descriptor);
char *overloadedNative=MNEW(char,overloadedNativeLen);
sprintf(overloadedNative,"%s",nativeName);
MFREE(nativeName,char,nativeLen);
codegen_fillInOverloadPart(overloadedNative,m->descriptor);
- log_text("symbol not found,trying harder (overloaded member ?)");
+ /*log_text("symbol not found,trying harder (overloaded member ?)");*/
sym=dlsym(lib,overloadedNative);
if (sym) {
MFREE(overloadedNative,char,overloadedNativeLen);
- ok=1;
- log_text("resolved");
+ ok=1; /* we eventually found the native function -> everything ok*/
+ /*log_text("resolved");*/
} else {
+ /* we failed to find the native function within the execution image (app + loaded libraries) -> will cause an exit*/
MFREE(overloadedNative,char,overloadedNativeLen);
log_text("It was not possible to find the native function implementation. Not even in overloading case");
}
}
+ /* patch the address of the native function into the stub and make the stub jump over this function call in the future */
if (ok) {
(*insertionPoint)=sym;
+#if defined(__X86_64__)
+ (*((s4*)jmpPatchTarget))=(s4)jmpTarget;
+#else
(*jmpPatchTarget)=jmpTarget;
+#endif
builtin_monitorexit((java_objectheader *) m );
return;
}
} else log_text("library not found");
-
+ /* There was an error, either the app image could not be opened or the native does not exist in the application and the
+ loaded libraries. Show an additional error and exit the vm*/
{
char *info;
size_t slen;
#endif
+#endif
+
/*
* These are local overrides for various environment variables in Emacs.
* Please do not remove this and leave it at the end of the file, where