Use of pointer casts in the interpreter
Per Bothner
per@bothner.com
Sun Aug 8 23:14:00 GMT 1999
I've gotten to the point that Kawa now crashes in the Interpreter,
which led me to look at interpret.cc. There are a bunch of
pointer casts in there. Such casts are unsafe, as the gcc
optimizer makes aliasing assumptions based on the types of
pointers. In general, I think it is cleaner to use a union
anyway. I suggest:
typedef union {
jint i;
jfloat f;
jint ia[1]; // Half of _Jv_word2.
void* p;
_Jv_Field *fld;
...
} _Jv_word;
typedef union {
jint ia[2];
jlong l;
jdouble d;
} _Jv_word2;
class _Jv_InterpMethodInvocation {
_Jv_InterpMethod *running;
_Jv_word *sp;
...
};
#define PUSHA(V) ((sp++)->p = (V))
#define PUSHI(V) ((sp++)->i = (V))
#define PUSHF(V) ((sp++)->f = (V))
#define PUSHL(V) ({ _Jv_word2 word2_tmp; \
word2_tmp.l = (V); (sp++)->ia[0] = word2_tmp.ia[0]; (sp++)->ia[0] = word2_tmp.ia[1]; })
I also noticed a comment in _Jv_InterpMethod::continue1 about huge stack frames. That
suggests avoiding local variables in macros. Instead make word2_tmp a local
variable in _Jv_InterpMethod::continue1. (Admittedly, this is less clean.)
--
--Per Bothner
bothner@pacbell.net per@bothner.com http://home.pacbell.net/bothner/
More information about the Java
mailing list