Changes:
- $Id: patcher.c 2396 2005-04-27 12:44:31Z twisti $
+ $Id: patcher.c 2431 2005-05-03 19:27:11Z twisti $
*/
bool patcher_get_putstatic(u1 *sp)
{
- u1 *ra;
- u4 mcode;
- unresolved_field *uf;
- u1 *pv;
- fieldinfo *fi;
- s2 offset;
+ u1 *ra;
+ java_objectheader *o;
+ u4 mcode;
+ unresolved_field *uf;
+ u1 *pv;
+ fieldinfo *fi;
+ s2 offset;
/* get stuff from the stack */
- ra = (u1 *) *((ptrint *) (sp + 2 * 8));
- mcode = *((u4 *) (sp + 1 * 8));
- uf = (unresolved_field *) *((ptrint *) (sp + 0 * 8));
- pv = (u1 *) *((ptrint *) (sp - 2 * 8));
+ ra = (u1 *) *((ptrint *) (sp + 3 * 8));
+ o = (java_objectheader *) *((ptrint *) (sp + 2 * 8));
+ mcode = *((u4 *) (sp + 1 * 8));
+ uf = (unresolved_field *) *((ptrint *) (sp + 0 * 8));
+ pv = (u1 *) *((ptrint *) (sp - 2 * 8));
/* calculate and set the new return address */
ra = ra - 4;
- *((ptrint *) (sp + 2 * 8)) = (ptrint) ra;
+ *((ptrint *) (sp + 3 * 8)) = (ptrint) ra;
+
+#if defined(USE_THREADS)
+ /* enter a monitor on the patching position */
+
+ builtin_monitorenter(o);
+
+ /* check if the position has already been patched */
+
+ if (o->vftbl) {
+ builtin_monitorexit(o);
+
+ return true;
+ }
+#endif
/* get the fieldinfo */
asm_sync_instruction_cache();
+#if defined(USE_THREADS)
+ /* this position has been patched */
+
+ o->vftbl = (vftbl_t *) 1;
+
+ /* leave the monitor on the patching position */
+
+ builtin_monitorexit(o);
+#endif
+
return true;
}
bool patcher_get_putfield(u1 *sp)
{
- u1 *ra;
- u8 mcode;
- unresolved_field *uf;
- u1 *pv;
- fieldinfo *fi;
+ u1 *ra;
+ java_objectheader *o;
+ u8 mcode;
+ unresolved_field *uf;
+ u1 *pv;
+ fieldinfo *fi;
- ra = (u1 *) *((ptrint *) (sp + 2 * 8));
- mcode = *((u4 *) (sp + 1 * 8));
- uf = (unresolved_field *) *((ptrint *) (sp + 0 * 8));
- pv = (u1 *) *((ptrint *) (sp - 2 * 8));
+ ra = (u1 *) *((ptrint *) (sp + 3 * 8));
+ o = (java_objectheader *) *((ptrint *) (sp + 2 * 8));
+ mcode = *((u4 *) (sp + 1 * 8));
+ uf = (unresolved_field *) *((ptrint *) (sp + 0 * 8));
+ pv = (u1 *) *((ptrint *) (sp - 2 * 8));
/* calculate and set the new return address */
ra = ra - 4;
- *((ptrint *) (sp + 2 * 8)) = (ptrint) ra;
+ *((ptrint *) (sp + 3 * 8)) = (ptrint) ra;
+
+#if defined(USE_THREADS)
+ /* enter a monitor on the patching position */
+
+ builtin_monitorenter(o);
+
+ /* check if the position has already been patched */
+
+ if (o->vftbl) {
+ builtin_monitorexit(o);
+
+ return true;
+ }
+#endif
/* get the fieldinfo */
asm_sync_instruction_cache();
+#if defined(USE_THREADS)
+ /* this position has been patched */
+
+ o->vftbl = (vftbl_t *) 1;
+
+ /* leave the monitor on the patching position */
+
+ builtin_monitorexit(o);
+#endif
+
return true;
}
bool patcher_builtin_new(u1 *sp)
{
u1 *ra;
+ java_objectheader *o;
u4 mcode;
constant_classref *cr;
u1 *pv;
/* get stuff from the stack */
- ra = (u1 *) *((ptrint *) (sp + 2 * 8));
+ ra = (u1 *) *((ptrint *) (sp + 3 * 8));
+ o = (java_objectheader *) *((ptrint *) (sp + 2 * 8));
mcode = *((u4 *) (sp + 1 * 8));
cr = (constant_classref *) *((ptrint *) (sp + 0 * 8));
pv = (u1 *) *((ptrint *) (sp - 2 * 8));
/* calculate and set the new return address */
ra = ra - (4 + 4);
- *((ptrint *) (sp + 2 * 8)) = (ptrint) ra;
+ *((ptrint *) (sp + 3 * 8)) = (ptrint) ra;
+
+#if defined(USE_THREADS)
+ /* enter a monitor on the patching position */
+
+ builtin_monitorenter(o);
+
+ /* check if the position has already been patched */
+
+ if (o->vftbl) {
+ builtin_monitorexit(o);
+
+ return true;
+ }
+#endif
/* get the classinfo */
asm_sync_instruction_cache();
+#if defined(USE_THREADS)
+ /* this position has been patched */
+
+ o->vftbl = (vftbl_t *) 1;
+
+ /* leave the monitor on the patching position */
+
+ builtin_monitorexit(o);
+#endif
+
return true;
}
bool patcher_builtin_newarray(u1 *sp)
{
u1 *ra;
+ java_objectheader *o;
u4 mcode;
constant_classref *cr;
u1 *pv;
/* get stuff from the stack */
- ra = (u1 *) *((ptrint *) (sp + 2 * 8));
+ ra = (u1 *) *((ptrint *) (sp + 3 * 8));
+ o = (java_objectheader *) *((ptrint *) (sp + 2 * 8));
mcode = *((u4 *) (sp + 1 * 8));
cr = (constant_classref *) *((ptrint *) (sp + 0 * 8));
pv = (u1 *) *((ptrint *) (sp - 2 * 8));
/* calculate and set the new return address */
ra = ra - (4 + 4);
- *((ptrint *) (sp + 2 * 8)) = (ptrint) ra;
+ *((ptrint *) (sp + 3 * 8)) = (ptrint) ra;
+
+#if defined(USE_THREADS)
+ /* enter a monitor on the patching position */
+
+ builtin_monitorenter(o);
+
+ /* check if the position has already been patched */
+
+ if (o->vftbl) {
+ builtin_monitorexit(o);
+
+ return true;
+ }
+#endif
/* get the classinfo */
asm_sync_instruction_cache();
+#if defined(USE_THREADS)
+ /* this position has been patched */
+
+ o->vftbl = (vftbl_t *) 1;
+
+ /* leave the monitor on the patching position */
+
+ builtin_monitorexit(o);
+#endif
+
return true;
}
bool patcher_builtin_multianewarray(u1 *sp)
{
u1 *ra;
+ java_objectheader *o;
u4 mcode;
constant_classref *cr;
u1 *pv;
/* get stuff from the stack */
- ra = (u1 *) *((ptrint *) (sp + 2 * 8));
+ ra = (u1 *) *((ptrint *) (sp + 3 * 8));
+ o = (java_objectheader *) *((ptrint *) (sp + 2 * 8));
mcode = *((u4 *) (sp + 1 * 8));
cr = (constant_classref *) *((ptrint *) (sp + 0 * 8));
pv = (u1 *) *((ptrint *) (sp - 2 * 8));
/* calculate and set the new return address */
ra = ra - 4;
- *((ptrint *) (sp + 2 * 8)) = (ptrint) ra;
+ *((ptrint *) (sp + 3 * 8)) = (ptrint) ra;
+
+#if defined(USE_THREADS)
+ /* enter a monitor on the patching position */
+
+ builtin_monitorenter(o);
+
+ /* check if the position has already been patched */
+
+ if (o->vftbl) {
+ builtin_monitorexit(o);
+
+ return true;
+ }
+#endif
/* get the classinfo */
asm_sync_instruction_cache();
+#if defined(USE_THREADS)
+ /* this position has been patched */
+
+ o->vftbl = (vftbl_t *) 1;
+
+ /* leave the monitor on the patching position */
+
+ builtin_monitorexit(o);
+#endif
+
return true;
}
bool patcher_builtin_checkarraycast(u1 *sp)
{
u1 *ra;
+ java_objectheader *o;
u4 mcode;
constant_classref *cr;
u1 *pv;
/* get stuff from the stack */
- ra = (u1 *) *((ptrint *) (sp + 2 * 8));
+ ra = (u1 *) *((ptrint *) (sp + 3 * 8));
+ o = (java_objectheader *) *((ptrint *) (sp + 2 * 8));
mcode = *((u4 *) (sp + 1 * 8));
cr = (constant_classref *) *((ptrint *) (sp + 0 * 8));
pv = (u1 *) *((ptrint *) (sp - 2 * 8));
/* calculate and set the new return address */
ra = ra - (2 * 4);
- *((ptrint *) (sp + 2 * 8)) = (ptrint) ra;
+ *((ptrint *) (sp + 3 * 8)) = (ptrint) ra;
+
+#if defined(USE_THREADS)
+ /* enter a monitor on the patching position */
+
+ builtin_monitorenter(o);
+
+ /* check if the position has already been patched */
+
+ if (o->vftbl) {
+ builtin_monitorexit(o);
+
+ return true;
+ }
+#endif
/* get the classinfo */
asm_sync_instruction_cache();
+#if defined(USE_THREADS)
+ /* this position has been patched */
+
+ o->vftbl = (vftbl_t *) 1;
+
+ /* leave the monitor on the patching position */
+
+ builtin_monitorexit(o);
+#endif
+
return true;
}
bool patcher_builtin_arrayinstanceof(u1 *sp)
{
u1 *ra;
+ java_objectheader *o;
u4 mcode;
constant_classref *cr;
u1 *pv;
/* get stuff from the stack */
- ra = (u1 *) *((ptrint *) (sp + 2 * 8));
+ ra = (u1 *) *((ptrint *) (sp + 3 * 8));
+ o = (java_objectheader *) *((ptrint *) (sp + 2 * 8));
mcode = *((u4 *) (sp + 1 * 8));
cr = (constant_classref *) *((ptrint *) (sp + 0 * 8));
pv = (u1 *) *((ptrint *) (sp - 2 * 8));
/* calculate and set the new return address */
ra = ra - (4 + 4);
- *((ptrint *) (sp + 2 * 8)) = (ptrint) ra;
+ *((ptrint *) (sp + 3 * 8)) = (ptrint) ra;
+
+#if defined(USE_THREADS)
+ /* enter a monitor on the patching position */
+
+ builtin_monitorenter(o);
+
+ /* check if the position has already been patched */
+
+ if (o->vftbl) {
+ builtin_monitorexit(o);
+
+ return true;
+ }
+#endif
/* get the classinfo */
asm_sync_instruction_cache();
+#if defined(USE_THREADS)
+ /* this position has been patched */
+
+ o->vftbl = (vftbl_t *) 1;
+
+ /* leave the monitor on the patching position */
+
+ builtin_monitorexit(o);
+#endif
+
return true;
}
bool patcher_invokestatic_special(u1 *sp)
{
u1 *ra;
+ java_objectheader *o;
u4 mcode;
unresolved_method *um;
u1 *pv;
/* get stuff from the stack */
- ra = (u1 *) *((ptrint *) (sp + 2 * 8));
+ ra = (u1 *) *((ptrint *) (sp + 3 * 8));
+ o = (java_objectheader *) *((ptrint *) (sp + 2 * 8));
mcode = *((u4 *) (sp + 1 * 8));
um = (unresolved_method *) *((ptrint *) (sp + 0 * 8));
pv = (u1 *) *((ptrint *) (sp - 2 * 8));
/* calculate and set the new return address */
ra = ra - 4;
- *((ptrint *) (sp + 2 * 8)) = (ptrint) ra;
+ *((ptrint *) (sp + 3 * 8)) = (ptrint) ra;
+
+#if defined(USE_THREADS)
+ /* enter a monitor on the patching position */
+
+ builtin_monitorenter(o);
+
+ /* check if the position has already been patched */
+
+ if (o->vftbl) {
+ builtin_monitorexit(o);
+
+ return true;
+ }
+#endif
/* get the fieldinfo */
asm_sync_instruction_cache();
+#if defined(USE_THREADS)
+ /* this position has been patched */
+
+ o->vftbl = (vftbl_t *) 1;
+
+ /* leave the monitor on the patching position */
+
+ builtin_monitorexit(o);
+#endif
+
return true;
}
bool patcher_invokevirtual(u1 *sp)
{
u1 *ra;
+ java_objectheader *o;
u4 mcode;
unresolved_method *um;
methodinfo *m;
/* get stuff from the stack */
- ra = (u1 *) *((ptrint *) (sp + 2 * 8));
+ ra = (u1 *) *((ptrint *) (sp + 3 * 8));
+ o = (java_objectheader *) *((ptrint *) (sp + 2 * 8));
mcode = *((u4 *) (sp + 1 * 8));
um = (unresolved_method *) *((ptrint *) (sp + 0 * 8));
/* calculate and set the new return address */
ra = ra - 4;
- *((ptrint *) (sp + 2 * 8)) = (ptrint) ra;
+ *((ptrint *) (sp + 3 * 8)) = (ptrint) ra;
+
+#if defined(USE_THREADS)
+ /* enter a monitor on the patching position */
+
+ builtin_monitorenter(o);
+
+ /* check if the position has already been patched */
+
+ if (o->vftbl) {
+ builtin_monitorexit(o);
+
+ return true;
+ }
+#endif
/* get the fieldinfo */
asm_sync_instruction_cache();
+#if defined(USE_THREADS)
+ /* this position has been patched */
+
+ o->vftbl = (vftbl_t *) 1;
+
+ /* leave the monitor on the patching position */
+
+ builtin_monitorexit(o);
+#endif
+
return true;
}
bool patcher_invokeinterface(u1 *sp)
{
u1 *ra;
+ java_objectheader *o;
u4 mcode;
unresolved_method *um;
methodinfo *m;
/* get stuff from the stack */
- ra = (u1 *) *((ptrint *) (sp + 2 * 8));
+ ra = (u1 *) *((ptrint *) (sp + 3 * 8));
+ o = (java_objectheader *) *((ptrint *) (sp + 2 * 8));
mcode = *((u4 *) (sp + 1 * 8));
um = (unresolved_method *) *((ptrint *) (sp + 0 * 8));
/* calculate and set the new return address */
ra = ra - 4;
- *((ptrint *) (sp + 2 * 8)) = (ptrint) ra;
+ *((ptrint *) (sp + 3 * 8)) = (ptrint) ra;
+
+#if defined(USE_THREADS)
+ /* enter a monitor on the patching position */
+
+ builtin_monitorenter(o);
+
+ /* check if the position has already been patched */
+
+ if (o->vftbl) {
+ builtin_monitorexit(o);
+
+ return true;
+ }
+#endif
/* get the fieldinfo */
asm_sync_instruction_cache();
+#if defined(USE_THREADS)
+ /* this position has been patched */
+
+ o->vftbl = (vftbl_t *) 1;
+
+ /* leave the monitor on the patching position */
+
+ builtin_monitorexit(o);
+#endif
+
return true;
}
bool patcher_checkcast_instanceof_flags(u1 *sp)
{
u1 *ra;
+ java_objectheader *o;
u4 mcode;
constant_classref *cr;
u1 *pv;
/* get stuff from the stack */
- ra = (u1 *) *((ptrint *) (sp + 2 * 8));
+ ra = (u1 *) *((ptrint *) (sp + 3 * 8));
+ o = (java_objectheader *) *((ptrint *) (sp + 2 * 8));
mcode = *((u4 *) (sp + 1 * 8));
cr = (constant_classref *) *((ptrint *) (sp + 0 * 8));
pv = (u1 *) *((ptrint *) (sp - 2 * 8));
/* calculate and set the new return address */
ra = ra - 4;
- *((ptrint *) (sp + 2 * 8)) = (ptrint) ra;
+ *((ptrint *) (sp + 3 * 8)) = (ptrint) ra;
+
+#if defined(USE_THREADS)
+ /* enter a monitor on the patching position */
+
+ builtin_monitorenter(o);
+
+ /* check if the position has already been patched */
+
+ if (o->vftbl) {
+ builtin_monitorexit(o);
+
+ return true;
+ }
+#endif
/* get the fieldinfo */
asm_sync_instruction_cache();
+#if defined(USE_THREADS)
+ /* this position has been patched */
+
+ o->vftbl = (vftbl_t *) 1;
+
+ /* leave the monitor on the patching position */
+
+ builtin_monitorexit(o);
+#endif
+
return true;
}
bool patcher_checkcast_instanceof_interface(u1 *sp)
{
u1 *ra;
+ java_objectheader *o;
u4 mcode;
constant_classref *cr;
classinfo *c;
/* get stuff from the stack */
- ra = (u1 *) *((ptrint *) (sp + 2 * 8));
+ ra = (u1 *) *((ptrint *) (sp + 3 * 8));
+ o = (java_objectheader *) *((ptrint *) (sp + 2 * 8));
mcode = *((u4 *) (sp + 1 * 8));
cr = (constant_classref *) *((ptrint *) (sp + 0 * 8));
/* calculate and set the new return address */
ra = ra - 4;
- *((ptrint *) (sp + 2 * 8)) = (ptrint) ra;
+ *((ptrint *) (sp + 3 * 8)) = (ptrint) ra;
+
+#if defined(USE_THREADS)
+ /* enter a monitor on the patching position */
+
+ builtin_monitorenter(o);
+
+ /* check if the position has already been patched */
+
+ if (o->vftbl) {
+ builtin_monitorexit(o);
+
+ return true;
+ }
+#endif
/* get the fieldinfo */
asm_sync_instruction_cache();
+#if defined(USE_THREADS)
+ /* this position has been patched */
+
+ o->vftbl = (vftbl_t *) 1;
+
+ /* leave the monitor on the patching position */
+
+ builtin_monitorexit(o);
+#endif
+
return true;
}
bool patcher_checkcast_instanceof_class(u1 *sp)
{
u1 *ra;
+ java_objectheader *o;
u4 mcode;
constant_classref *cr;
u1 *pv;
/* get stuff from the stack */
- ra = (u1 *) *((ptrint *) (sp + 2 * 8));
+ ra = (u1 *) *((ptrint *) (sp + 3 * 8));
+ o = (java_objectheader *) *((ptrint *) (sp + 2 * 8));
mcode = *((u4 *) (sp + 1 * 8));
cr = (constant_classref *) *((ptrint *) (sp + 0 * 8));
pv = (u1 *) *((ptrint *) (sp - 2 * 8));
/* calculate and set the new return address */
ra = ra - 4;
- *((ptrint *) (sp + 2 * 8)) = (ptrint) ra;
+ *((ptrint *) (sp + 3 * 8)) = (ptrint) ra;
+
+#if defined(USE_THREADS)
+ /* enter a monitor on the patching position */
+
+ builtin_monitorenter(o);
+
+ /* check if the position has already been patched */
+
+ if (o->vftbl) {
+ builtin_monitorexit(o);
+
+ return true;
+ }
+#endif
/* get the fieldinfo */
asm_sync_instruction_cache();
+#if defined(USE_THREADS)
+ /* this position has been patched */
+
+ o->vftbl = (vftbl_t *) 1;
+
+ /* leave the monitor on the patching position */
+
+ builtin_monitorexit(o);
+#endif
+
return true;
}
bool patcher_clinit(u1 *sp)
{
- u1 *ra;
- u4 mcode;
- classinfo *c;
+ u1 *ra;
+ java_objectheader *o;
+ u4 mcode;
+ classinfo *c;
/* get stuff from the stack */
- ra = (u1 *) *((ptrint *) (sp + 2 * 8));
- mcode = *((u4 *) (sp + 1 * 8));
- c = (classinfo *) *((ptrint *) (sp + 0 * 8));
+ ra = (u1 *) *((ptrint *) (sp + 3 * 8));
+ o = (java_objectheader *) *((ptrint *) (sp + 2 * 8));
+ mcode = *((u4 *) (sp + 1 * 8));
+ c = (classinfo *) *((ptrint *) (sp + 0 * 8));
/* calculate and set the new return address */
ra = ra - 4;
- *((ptrint *) (sp + 2 * 8)) = (ptrint) ra;
+ *((ptrint *) (sp + 3 * 8)) = (ptrint) ra;
+
+#if defined(USE_THREADS)
+ /* enter a monitor on the patching position */
+
+ builtin_monitorenter(o);
+
+ /* check if the position has already been patched */
+
+ if (o->vftbl) {
+ builtin_monitorexit(o);
+
+ return true;
+ }
+#endif
/* check if the class is initialized */
asm_sync_instruction_cache();
+#if defined(USE_THREADS)
+ /* this position has been patched */
+
+ o->vftbl = (vftbl_t *) 1;
+
+ /* leave the monitor on the patching position */
+
+ builtin_monitorexit(o);
+#endif
+
return true;
}