/* src/vm/jit/intrp/patcher.c - Interpreter code patching functions
- 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
+ Copyright (C) 1996-2005, 2006, 2007 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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- 02111-1307, USA.
-
- Contact: cacao@complang.tuwien.ac.at
-
- Authors: Christian Thalinger
-
- Changes:
-
- $Id: patcher.c 3138 2005-09-02 15:15:18Z twisti $
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
*/
-#include "vm/jit/intrp/types.h"
+#include "config.h"
+#include "vm/types.h"
#include "mm/memory.h"
+
#include "native/native.h"
+
#include "vm/builtin.h"
-#include "vm/field.h"
#include "vm/initialize.h"
-#include "vm/options.h"
-#include "vm/references.h"
+
#include "vm/jit/asmpart.h"
-#include "vm/jit/helper.h"
#include "vm/jit/patcher.h"
+#include "vmcore/class.h"
+#include "vmcore/field.h"
+#include "vmcore/options.h"
+#include "vm/resolve.h"
+#include "vmcore/references.h"
+
/* patcher_get_putstatic *******************************************************
*******************************************************************************/
-bool patcher_get_putstatic(u1 *sp)
+bool intrp_patcher_get_putstatic(u1 *sp)
{
ptrint *ip;
unresolved_field *uf;
/* get the fieldinfo */
- if (!(fi = helper_resolve_fieldinfo(uf))) {
+ if (!(fi = resolve_field_eager(uf)))
return false;
- }
/* check if the field's class is initialized */
- if (!fi->class->initialized) {
- if (!initialize_class(fi->class)) {
+ if (!(fi->class->state & CLASS_INITIALIZED))
+ if (!initialize_class(fi->class))
return false;
- }
- }
/* patch the field's address */
}
-/* patcher_get_putfield ********************************************************
+/* patcher_get_putstatic_clinit ************************************************
+ This patcher is used if we already have the resolved fieldinfo but the
+ class of the field has not been initialized, yet.
+
Machine code:
*******************************************************************************/
-bool patcher_get_putfield(u1 *sp)
+bool intrp_patcher_get_putstatic_clinit(u1 *sp)
{
ptrint *ip;
- unresolved_field *uf;
fieldinfo *fi;
+ /* get the fieldinfo */
+
ip = (ptrint *) sp;
- uf = (unresolved_field *) ip[2];
+ fi = (fieldinfo *) ip[2];
- /* get the fieldinfo */
+ /* check if the field's class is initialized */
- if (!(fi = helper_resolve_fieldinfo(uf))) {
- return false;
- }
+ if (!(fi->class->state & CLASS_INITIALIZED))
+ if (!initialize_class(fi->class))
+ return false;
- /* patch the field's offset */
+ /* patch the field's address */
- ip[1] = fi->offset;
+ ip[1] = (ptrint) &(fi->value);
return true;
}
-/* patcher_builtin_new *********************************************************
+/* patcher_get_putfield ********************************************************
Machine code:
*******************************************************************************/
-bool patcher_builtin_new(u1 *sp)
+bool intrp_patcher_get_putfield(u1 *sp)
{
ptrint *ip;
- constant_classref *cr;
- classinfo *c;
+ unresolved_field *uf;
+ fieldinfo *fi;
ip = (ptrint *) sp;
- cr = (constant_classref *) ip[-1];
-
- /* get the classinfo */
+ uf = (unresolved_field *) ip[2];
+
+ /* get the fieldinfo */
- if (!(c = helper_resolve_classinfo(cr))) {
+ if (!(fi = resolve_field_eager(uf)))
return false;
- }
- /* patch the classinfo pointer */
+ /* patch the field's offset */
- ip[1] = (ptrint) c;
+ ip[1] = fi->offset;
return true;
}
-/* patcher_builtin_newarray ****************************************************
+/* patcher_aconst **************************************************************
Machine code:
- INFO: This one is also used for arrayinstanceof!
-
*******************************************************************************/
-bool patcher_builtin_newarray(u1 *sp)
+bool intrp_patcher_aconst(u1 *sp)
{
ptrint *ip;
constant_classref *cr;
classinfo *c;
ip = (ptrint *) sp;
- cr = (constant_classref *) ip[-1];
-
+ cr = (constant_classref *) ip[2];
+
/* get the classinfo */
- if (!(c = helper_resolve_classinfo(cr))) {
+ if (!(c = resolve_classref_eager(cr)))
return false;
- }
- /* patch the class' vftbl pointer */
+ /* patch the classinfo pointer */
- ip[1] = (ptrint) c->vftbl;
+ ip[1] = (ptrint) c;
return true;
}
-bool patcher_builtin_arrayinstanceof(u1 *sp)
-{
- return patcher_builtin_newarray(sp);
-}
-
-
/* patcher_builtin_multianewarray **********************************************
Machine code:
*******************************************************************************/
-bool patcher_builtin_multianewarray(u1 *sp)
+bool intrp_patcher_builtin_multianewarray(u1 *sp)
{
ptrint *ip;
constant_classref *cr;
/* get the classinfo */
- if (!(c = helper_resolve_classinfo(cr))) {
+ if (!(c = resolve_classref_eager(cr)))
return false;
- }
- /* patch the class' vftbl pointer */
+ /* patch the classinfo pointer */
- ip[1] = (ptrint) c->vftbl;
+ ip[1] = (ptrint) c;
return true;
}
*******************************************************************************/
-bool patcher_builtin_arraycheckcast(u1 *sp)
+bool intrp_patcher_builtin_arraycheckcast(u1 *sp)
{
ptrint *ip;
constant_classref *cr;
/* get the classinfo */
- if (!(c = helper_resolve_classinfo(cr))) {
+ if (!(c = resolve_classref_eager(cr)))
return false;
- }
- /* patch the class' vftbl pointer */
+ /* patch the classinfo pointer */
- ip[1] = (ptrint) c->vftbl;
+ ip[1] = (ptrint) c;
return true;
}
******************************************************************************/
-bool patcher_invokestatic_special(u1 *sp)
+bool intrp_patcher_invokestatic_special(u1 *sp)
{
ptrint *ip;
unresolved_method *um;
/* get the fieldinfo */
- if (!(m = helper_resolve_methodinfo(um))) {
+ if (!(m = resolve_method_eager(um)))
return false;
- }
- /* patch stubroutine */
+ /* patch methodinfo and stubroutine */
+ ip[3] = (ptrint) m;
ip[1] = (ptrint) m->stubroutine;
return true;
*******************************************************************************/
-bool patcher_invokevirtual(u1 *sp)
+bool intrp_patcher_invokevirtual(u1 *sp)
{
ptrint *ip;
unresolved_method *um;
/* get the fieldinfo */
- if (!(m = helper_resolve_methodinfo(um))) {
+ if (!(m = resolve_method_eager(um)))
return false;
- }
- /* patch vftbl index */
+ /* patch methodinfo and vftbl index */
+ ip[3] = (ptrint) m;
ip[1] = (OFFSET(vftbl_t, table[0]) + sizeof(methodptr) * m->vftblindex);
return true;
*******************************************************************************/
-bool patcher_invokeinterface(u1 *sp)
+bool intrp_patcher_invokeinterface(u1 *sp)
{
ptrint *ip;
unresolved_method *um;
/* get the methodinfo */
- if (!(m = helper_resolve_methodinfo(um))) {
+ if (!(m = resolve_method_eager(um)))
return false;
- }
/* patch interfacetable index */
ip[1] = (OFFSET(vftbl_t, interfacetable[0]) -
sizeof(methodptr*) * m->class->index);
- /* patch method offset */
+ /* patch methodinfo and method offset */
+ ip[4] = (ptrint) m;
ip[2] = (sizeof(methodptr) * (m - m->class->methods));
return true;
*******************************************************************************/
-bool patcher_checkcast_instanceof(u1 *sp)
+bool intrp_patcher_checkcast_instanceof(u1 *sp)
{
ptrint *ip;
constant_classref *cr;
/* get the classinfo */
- if (!(c = helper_resolve_classinfo(cr))) {
+ if (!(c = resolve_classref_eager(cr)))
return false;
- }
/* patch super class pointer */
*******************************************************************************/
-#if !defined(ENABLE_STATICVM)
-bool patcher_resolve_native(u1 *sp)
+#if !defined(WITH_STATIC_CLASSPATH)
+bool intrp_patcher_resolve_native(u1 *sp)
{
ptrint *ip;
methodinfo *m;
/* resolve native function */
- if (!(f = native_resolve_function(m))) {
+ if (!(f = native_resolve_function(m)))
return false;
- }
/* patch native function pointer */
return true;
}
-#endif /* !defined(ENABLE_STATICVM) */
+#endif /* !defined(WITH_STATIC_CLASSPATH) */
/*