001: /* RuntimeEnvironment Copyright (C) 1999-2002 Jochen Hoenicke.
002: *
003: * This program is free software; you can redistribute it and/or modify
004: * it under the terms of the GNU Lesser General Public License as published by
005: * the Free Software Foundation; either version 2, or (at your option)
006: * any later version.
007: *
008: * This program is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
011: * GNU General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public License
014: * along with this program; see the file COPYING.LESSER. If not, write to
015: * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
016: *
017: * $Id: RuntimeEnvironment.java,v 1.3.2.1 2002/05/28 17:34:12 hoenicke Exp $
018: */
019:
020: package jode.jvm;
021:
022: import jode.bytecode.Reference;
023: import java.lang.reflect.InvocationTargetException;
024:
025: /**
026: * This interface is used by the Interpreter to actually modify objects,
027: * invoke methods, etc. <br>
028: *
029: * The objects used in this runtime environment need not to be of the
030: * real type, but can be some other type of your choice. But some
031: * mappings must be preserved, since they are used inside the
032: * Interpreter:
033: * <ul> <li>boolean, byte, short, char and int are mapped to Integer. </li>
034: * <li> float, long, double are mapped to Float, Long, Double resp. </li>
035: * <li> array of primitive type is mapped to itself (not array of Integer)</li>
036: * <li> array of other types are mapped to array of mapped other type </li>
037: * </ul>
038: *
039: * @author Jochen Hoenicke */
040: public interface RuntimeEnvironment {
041: /**
042: * Get the value of a field member.
043: * @param fieldref the Reference of the field.
044: * @param obj the object of which the field should be taken, null
045: * if the field is static.
046: * @return the field value. Primitive types are wrapped to
047: * Object.
048: * @exception InterpreterException if the field does not exists, the
049: * object is not supported etc.
050: */
051: public Object getField(Reference fieldref, Object obj)
052: throws InterpreterException;
053:
054: /**
055: * Set the value of a field member.
056: * @param fieldref the Reference of the field.
057: * @param obj the object of which the field should be taken, null
058: * if the field is static.
059: * @param value the field value. Primitive types are wrapped to
060: * Object.
061: * @exception InterpreterException if the field does not exists, the
062: * object is not supported etc.
063: */
064: public void putField(Reference fieldref, Object obj, Object value)
065: throws InterpreterException;
066:
067: /**
068: * Invoke a method.
069: * @param methodRef the reference to the method.
070: * @param isVirtual true, iff the call is virtual
071: * @param cls the object on which the method should be called, null
072: * if the method is static.
073: * @param params the params of the method.
074: * @return the return value of the method. Void type is ignored,
075: * may be null.
076: * @exception InterpreterException if the field does not exists, the
077: * object is not supported etc. */
078: public Object invokeMethod(Reference methodRef, boolean isVirtual,
079: Object cls, Object[] params) throws InterpreterException,
080: InvocationTargetException;
081:
082: /**
083: * Create a new instance of an object.
084: * @param methodRef the reference of the constructor to invoke
085: * @param params the params of the method.
086: * @return the new object.
087: */
088: public Object invokeConstructor(Reference methodRef, Object[] params)
089: throws InterpreterException, InvocationTargetException;
090:
091: /**
092: * Check if obj is an instance of className
093: * @param className the type signature of the class.
094: * @return true, if obj is an instance of className, false otherwise.
095: */
096: public boolean instanceOf(Object obj, String className)
097: throws InterpreterException;
098:
099: /**
100: * Create a new multidimensional Array.
101: * @param type the type of the elements.
102: * @param dimensions the size in every dimension.
103: * @return the new array (this must be an array, see class comment).
104: */
105: public Object newArray(String type, int[] dimensions)
106: throws InterpreterException;
107:
108: /**
109: * Enter a monitor.
110: * @param object the object whose monitor should be taken.
111: */
112: public void enterMonitor(Object obj) throws InterpreterException;
113:
114: /**
115: * Exit a monitor.
116: * @param object the object whose monitor should be freed.
117: */
118: public void exitMonitor(Object obj) throws InterpreterException;
119: }
|