Christian Ullrich
Edwin Steiner
- $Id: codegen.c 5289 2006-09-04 16:33:57Z twisti $
+ $Id: codegen.c 5290 2006-09-04 17:12:48Z christian $
*/
resolved the same class, the returned displacement
of dseg_addaddress is ok to use. */
- codegen_addpatchref(cd, PATCHER_aconst, cr, disp);
+ codegen_addpatchref(cd, PATCHER_resolve_classref_to_classinfo,
+ cr, disp);
if (opt_showdisassemble)
M_NOP;
disp = dseg_add_address(cd, &(fi->value));
if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
- codegen_addpatchref(cd, PATCHER_clinit, fi->class, 0);
+ codegen_addpatchref(cd, PATCHER_initialize_class, fi->class,
+ 0);
if (opt_showdisassemble)
M_NOP;
disp = dseg_add_address(cd, &(fi->value));
if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
- codegen_addpatchref(cd, PATCHER_clinit, fi->class, 0);
+ codegen_addpatchref(cd, PATCHER_initialize_class, fi->class,
+ 0);
if (opt_showdisassemble)
M_NOP;
disp = dseg_add_address(cd, &(fi->value));
if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
- codegen_addpatchref(cd, PATCHER_clinit, fi->class, 0);
+ codegen_addpatchref(cd, PATCHER_initialize_class, fi->class,
+ 0);
if (opt_showdisassemble)
M_NOP;
if (iptr->val.a) {
unresolved_class *uc = INSTRUCTION_UNRESOLVED_CLASS(iptr);
- codegen_addpatchref(cd, PATCHER_athrow_areturn, uc, 0);
+ codegen_addpatchref(cd, PATCHER_resolve_class, uc, 0);
if (opt_showdisassemble)
M_NOP;
if (iptr->val.a) {
unresolved_class *uc = INSTRUCTION_UNRESOLVED_CLASS(iptr);
- codegen_addpatchref(cd, PATCHER_athrow_areturn, uc, 0);
+ codegen_addpatchref(cd, PATCHER_resolve_class, uc, 0);
if (opt_showdisassemble)
M_NOP;
disp = dseg_add_unique_s4(cd, 0); /* super->flags */
- codegen_addpatchref(cd, PATCHER_checkcast_instanceof_flags,
+ codegen_addpatchref(cd, PATCHER_resolve_classref_to_flags,
(constant_classref *) iptr->target,
disp);
disp = dseg_add_unique_address(cd, NULL);
codegen_addpatchref(cd,
- PATCHER_checkcast_instanceof_class,
+ PATCHER_resolve_classref_to_vftbl,
(constant_classref *) iptr->target,
disp);
disp = dseg_addaddress(cd, iptr->val.a);
if (iptr->val.a == NULL) {
- codegen_addpatchref(cd, PATCHER_builtin_arraycheckcast,
+ codegen_addpatchref(cd,
+ PATCHER_resolve_classref_to_classinfo,
(constant_classref *) iptr->target,
disp);
disp = dseg_add_unique_s4(cd, 0); /* super->flags */
- codegen_addpatchref(cd, PATCHER_checkcast_instanceof_flags,
+ codegen_addpatchref(cd, PATCHER_resolve_classref_to_flags,
(constant_classref *) iptr->target, disp);
if (opt_showdisassemble)
if (super == NULL) {
disp = dseg_add_unique_address(cd, NULL);
- codegen_addpatchref(cd, PATCHER_checkcast_instanceof_class,
+ codegen_addpatchref(cd, PATCHER_resolve_classref_to_vftbl,
(constant_classref *) iptr->target,
disp);
if (iptr->val.a == NULL) {
disp = dseg_add_unique_address(cd, 0);
- codegen_addpatchref(cd, PATCHER_builtin_multianewarray,
+ codegen_addpatchref(cd, PATCHER_resolve_classref_to_classinfo,
(constant_classref *) iptr->target,
disp);
#if !defined(WITH_STATIC_CLASSPATH)
if (f == NULL) {
- codegen_addpatchref(cd, PATCHER_resolve_native, m, funcdisp);
+ codegen_addpatchref(cd, PATCHER_resolve_native_function, m, funcdisp);
if (opt_showdisassemble)
M_NOP;
Changes:
- $Id: patcher.c 5160 2006-07-19 09:13:34Z twisti $
+ $Id: patcher.c 5290 2006-09-04 17:12:48Z christian $
*/
return NULL;
}
+/* patcher_initialize_class ****************************************************
-/* patcher_get_putstatic *******************************************************
-
- Machine code:
-
- <patched call position>
- a73bff98 ldq t11,-104(pv)
- a2590000 ldl a2,0(t11)
+ Initalizes a given classinfo pointer. This function does not patch
+ any data.
*******************************************************************************/
-bool patcher_get_putstatic(u1 *sp)
+bool patcher_initialize_class(u1 *sp)
{
- unresolved_field *uf;
- s4 disp;
- u1 *pv;
- fieldinfo *fi;
+ classinfo *c;
/* get stuff from the stack */
- uf = (unresolved_field *) *((ptrint *) (sp + 2 * 8));
- disp = *((s4 *) (sp + 1 * 8));
- pv = (u1 *) *((ptrint *) (sp + 0 * 8));
-
- /* get the fieldinfo */
-
- if (!(fi = resolve_field_eager(uf)))
- return false;
+ c = (classinfo *) *((ptrint *) (sp + 2 * 8));
- /* check if the field's class is initialized */
+ /* check if the class is initialized */
- if (!(fi->class->state & CLASS_INITIALIZED))
- if (!initialize_class(fi->class))
+ if (!(c->state & CLASS_INITIALIZED))
+ if (!initialize_class(c))
return false;
- /* patch the field value's address */
-
- *((ptrint *) (pv + disp)) = (ptrint) &(fi->value);
-
return true;
}
+/* patcher_resolve_class *****************************************************
-/* patcher_get_putfield ********************************************************
-
- Machine code:
-
- <patched call position>
- a2af0020 ldl a5,32(s6)
+ Initalizes a given classinfo pointer. This function does not patch
+ any data.
*******************************************************************************/
-bool patcher_get_putfield(u1 *sp)
+#ifdef ENABLE_VERIFIER
+bool patcher_resolve_class(u1 *sp)
{
- u1 *ra;
- unresolved_field *uf;
- fieldinfo *fi;
-
- ra = (u1 *) *((ptrint *) (sp + 5 * 8));
- uf = (unresolved_field *) *((ptrint *) (sp + 2 * 8));
-
- /* get the fieldinfo */
-
- if (!(fi = resolve_field_eager(uf)))
- return false;
+ unresolved_class *uc;
+ classinfo *c;
- /* if we show disassembly, we have to skip the nop */
+ /* get stuff from the stack */
- if (opt_showdisassemble) {
- /* patch the field's offset into the instruction */
+ uc = (unresolved_class *) *((ptrint *) (sp + 2 * 8));
- *((u4 *) (ra + 4)) |= (s2) (fi->offset & 0x0000ffff);
- }
- else {
- /* otherwise store the patched instruction on the stack */
+ /* resolve the class */
- *((u4 *) (sp + 3 * 8)) |= (s2) (fi->offset & 0x0000ffff);
- }
+ if (!resolve_class(uc, resolveEager, false, &c))
+ return false;
return true;
}
+#endif /* ENABLE_VERIFIER */
-/* patcher_aconst **************************************************************
+/* patcher_resolve_classref_to_classinfo ***************************************
- Machine code:
+ ACONST:
<patched call postition>
a61bff80 ldq a0,-128(pv)
+ MULTIANEWARRAY:
+
+ <patched call position>
+ a63bff80 ldq a1,-128(pv)
+ 47de0412 mov sp,a2
+ a77bff78 ldq pv,-136(pv)
+ 6b5b4000 jsr (pv)
+
+ ARRAYCHECKCAST:
+
+ <patched call position>
+ a63bfe60 ldq a1,-416(pv)
+ a77bfe58 ldq pv,-424(pv)
+ 6b5b4000 jsr (pv)
+
*******************************************************************************/
-bool patcher_aconst(u1 *sp)
+bool patcher_resolve_classref_to_classinfo(u1 *sp)
{
constant_classref *cr;
s4 disp;
}
-/* patcher_builtin_multianewarray **********************************************
+/* patcher_resolve_classref_to_vftbl *******************************************
- Machine code:
+ CHECKCAST (class):
+ INSTANCEOF (class):
<patched call position>
- a63bff80 ldq a1,-128(pv)
- 47de0412 mov sp,a2
- a77bff78 ldq pv,-136(pv)
- 6b5b4000 jsr (pv)
+ a7940000 ldq at,0(a4)
+ a7bbff28 ldq gp,-216(pv)
*******************************************************************************/
-bool patcher_builtin_multianewarray(u1 *sp)
+bool patcher_resolve_classref_to_vftbl(u1 *sp)
{
constant_classref *cr;
s4 disp;
disp = *((s4 *) (sp + 1 * 8));
pv = (u1 *) *((ptrint *) (sp + 0 * 8));
- /* get the classinfo */
+ /* get the fieldinfo */
if (!(c = resolve_classref_eager(cr)))
return false;
- /* patch the classinfo pointer */
+ /* patch super class' vftbl */
- *((ptrint *) (pv + disp)) = (ptrint) c;
+ *((ptrint *) (pv + disp)) = (ptrint) c->vftbl;
return true;
}
-/* patcher_builtin_arraycheckcast **********************************************
+/* patcher_resolve_classref_to_flags *******************************************
- Machine code:
+ CHECKCAST/INSTANCEOF:
<patched call position>
- a63bfe60 ldq a1,-416(pv)
- a77bfe58 ldq pv,-424(pv)
- 6b5b4000 jsr (pv)
*******************************************************************************/
-bool patcher_builtin_arraycheckcast(u1 *sp)
+bool patcher_resolve_classref_to_flags(u1 *sp)
{
constant_classref *cr;
s4 disp;
disp = *((s4 *) (sp + 1 * 8));
pv = (u1 *) *((ptrint *) (sp + 0 * 8));
- /* get the classinfo */
+ /* get the fieldinfo */
if (!(c = resolve_classref_eager(cr)))
return false;
- /* patch the classinfo pointer */
+ /* patch class flags */
- *((ptrint *) (pv + disp)) = (ptrint) c;
+ *((s4 *) (pv + disp)) = (s4) c->flags;
+
+ return true;
+}
+
+
+/* patcher_resolve_native_function *********************************************
+
+ XXX
+
+*******************************************************************************/
+
+#if !defined(WITH_STATIC_CLASSPATH)
+bool patcher_resolve_native_function(u1 *sp)
+{
+ methodinfo *m;
+ s4 disp;
+ u1 *pv;
+ functionptr f;
+
+ /* get stuff from the stack */
+
+ m = (methodinfo *) *((ptrint *) (sp + 2 * 8));
+ disp = *((s4 *) (sp + 1 * 8));
+ pv = (u1 *) *((ptrint *) (sp + 0 * 8));
+
+ /* resolve native function */
+
+ if (!(f = native_resolve_function(m)))
+ return false;
+
+ /* patch native function pointer */
+
+ *((ptrint *) (pv + disp)) = (ptrint) f;
+
+ return true;
+}
+#endif /* !defined(WITH_STATIC_CLASSPATH) */
+
+
+/* patcher_get_putstatic *******************************************************
+
+ Machine code:
+
+ <patched call position>
+ a73bff98 ldq t11,-104(pv)
+ a2590000 ldl a2,0(t11)
+
+*******************************************************************************/
+
+bool patcher_get_putstatic(u1 *sp)
+{
+ unresolved_field *uf;
+ s4 disp;
+ u1 *pv;
+ fieldinfo *fi;
+
+ /* get stuff from the stack */
+
+ uf = (unresolved_field *) *((ptrint *) (sp + 2 * 8));
+ disp = *((s4 *) (sp + 1 * 8));
+ pv = (u1 *) *((ptrint *) (sp + 0 * 8));
+
+ /* get the fieldinfo */
+
+ if (!(fi = resolve_field_eager(uf)))
+ return false;
+
+ /* check if the field's class is initialized */
+
+ if (!(fi->class->state & CLASS_INITIALIZED))
+ if (!initialize_class(fi->class))
+ return false;
+
+ /* patch the field value's address */
+
+ *((ptrint *) (pv + disp)) = (ptrint) &(fi->value);
+
+ return true;
+}
+
+
+/* patcher_get_putfield ********************************************************
+
+ Machine code:
+
+ <patched call position>
+ a2af0020 ldl a5,32(s6)
+
+*******************************************************************************/
+
+bool patcher_get_putfield(u1 *sp)
+{
+ u1 *ra;
+ unresolved_field *uf;
+ fieldinfo *fi;
+
+ ra = (u1 *) *((ptrint *) (sp + 5 * 8));
+ uf = (unresolved_field *) *((ptrint *) (sp + 2 * 8));
+
+ /* get the fieldinfo */
+
+ if (!(fi = resolve_field_eager(uf)))
+ return false;
+
+ /* if we show disassembly, we have to skip the nop */
+
+ if (opt_showdisassemble) {
+ /* patch the field's offset into the instruction */
+
+ *((u4 *) (ra + 4)) |= (s2) (fi->offset & 0x0000ffff);
+ }
+ else {
+ /* otherwise store the patched instruction on the stack */
+
+ *((u4 *) (sp + 3 * 8)) |= (s2) (fi->offset & 0x0000ffff);
+ }
return true;
}
}
-/* patcher_checkcast_instanceof_flags ******************************************
-
- Machine code:
-
- <patched call position>
-
-*******************************************************************************/
-
-bool patcher_checkcast_instanceof_flags(u1 *sp)
-{
- constant_classref *cr;
- s4 disp;
- u1 *pv;
- classinfo *c;
-
- /* get stuff from the stack */
-
- cr = (constant_classref *) *((ptrint *) (sp + 2 * 8));
- disp = *((s4 *) (sp + 1 * 8));
- pv = (u1 *) *((ptrint *) (sp + 0 * 8));
-
- /* get the fieldinfo */
-
- if (!(c = resolve_classref_eager(cr)))
- return false;
-
- /* patch class flags */
-
- *((s4 *) (pv + disp)) = (s4) c->flags;
-
- return true;
-}
-
-
/* patcher_checkcast_instanceof_interface **************************************
Machine code:
}
-/* patcher_checkcast_instanceof_class ******************************************
-
- Machine code:
-
- <patched call position>
- a7940000 ldq at,0(a4)
- a7bbff28 ldq gp,-216(pv)
-
-*******************************************************************************/
-
-bool patcher_checkcast_instanceof_class(u1 *sp)
-{
- constant_classref *cr;
- s4 disp;
- u1 *pv;
- classinfo *c;
-
- /* get stuff from the stack */
-
- cr = (constant_classref *) *((ptrint *) (sp + 2 * 8));
- disp = *((s4 *) (sp + 1 * 8));
- pv = (u1 *) *((ptrint *) (sp + 0 * 8));
-
- /* get the fieldinfo */
-
- if (!(c = resolve_classref_eager(cr)))
- return false;
-
- /* patch super class' vftbl */
-
- *((ptrint *) (pv + disp)) = (ptrint) c->vftbl;
-
- return true;
-}
-
-
-/* patcher_clinit **************************************************************
-
- XXX
-
-*******************************************************************************/
-
-bool patcher_clinit(u1 *sp)
-{
- classinfo *c;
-
- /* get stuff from the stack */
-
- c = (classinfo *) *((ptrint *) (sp + 2 * 8));
-
- /* check if the class is initialized */
-
- if (!(c->state & CLASS_INITIALIZED))
- if (!initialize_class(c))
- return false;
-
- return true;
-}
-
-
-/* patcher_athrow_areturn ******************************************************
-
- Machine code:
-
- <patched call position>
-
-*******************************************************************************/
-
-#ifdef ENABLE_VERIFIER
-bool patcher_athrow_areturn(u1 *sp)
-{
- unresolved_class *uc;
- classinfo *c;
-
- /* get stuff from the stack */
-
- uc = (unresolved_class *) *((ptrint *) (sp + 2 * 8));
-
- /* resolve the class */
-
- if (!resolve_class(uc, resolveEager, false, &c))
- return false;
-
- return true;
-}
-#endif /* ENABLE_VERIFIER */
-
-
-/* patcher_resolve_native ******************************************************
-
- XXX
-
-*******************************************************************************/
-
-#if !defined(WITH_STATIC_CLASSPATH)
-bool patcher_resolve_native(u1 *sp)
-{
- methodinfo *m;
- s4 disp;
- u1 *pv;
- functionptr f;
-
- /* get stuff from the stack */
-
- m = (methodinfo *) *((ptrint *) (sp + 2 * 8));
- disp = *((s4 *) (sp + 1 * 8));
- pv = (u1 *) *((ptrint *) (sp + 0 * 8));
-
- /* resolve native function */
-
- if (!(f = native_resolve_function(m)))
- return false;
-
- /* patch native function pointer */
-
- *((ptrint *) (pv + disp)) = (ptrint) f;
-
- return true;
-}
-#endif /* !defined(WITH_STATIC_CLASSPATH) */
-
-
/*
* 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