KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jode > jvm > RuntimeEnvironment


1 /* RuntimeEnvironment Copyright (C) 1999-2002 Jochen Hoenicke.
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU Lesser General Public License as published by
5  * the Free Software Foundation; either version 2, or (at your option)
6  * any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program; see the file COPYING.LESSER. If not, write to
15  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
16  *
17  * $Id: RuntimeEnvironment.java,v 1.3.2.1 2002/05/28 17:34:12 hoenicke Exp $
18  */

19
20 package jode.jvm;
21 import jode.bytecode.Reference;
22 import java.lang.reflect.InvocationTargetException JavaDoc;
23
24 /**
25  * This interface is used by the Interpreter to actually modify objects,
26  * invoke methods, etc. <br>
27  *
28  * The objects used in this runtime environment need not to be of the
29  * real type, but can be some other type of your choice. But some
30  * mappings must be preserved, since they are used inside the
31  * Interpreter:
32  * <ul> <li>boolean, byte, short, char and int are mapped to Integer. </li>
33  * <li> float, long, double are mapped to Float, Long, Double resp. </li>
34  * <li> array of primitive type is mapped to itself (not array of Integer)</li>
35  * <li> array of other types are mapped to array of mapped other type </li>
36  * </ul>
37  *
38  * @author Jochen Hoenicke */

39 public interface RuntimeEnvironment {
40     /**
41      * Get the value of a field member.
42      * @param fieldref the Reference of the field.
43      * @param obj the object of which the field should be taken, null
44      * if the field is static.
45      * @return the field value. Primitive types are wrapped to
46      * Object.
47      * @exception InterpreterException if the field does not exists, the
48      * object is not supported etc.
49      */

50     public Object JavaDoc getField(Reference fieldref, Object JavaDoc obj)
51     throws InterpreterException;
52
53     /**
54      * Set the value of a field member.
55      * @param fieldref the Reference of the field.
56      * @param obj the object of which the field should be taken, null
57      * if the field is static.
58      * @param value the field value. Primitive types are wrapped to
59      * Object.
60      * @exception InterpreterException if the field does not exists, the
61      * object is not supported etc.
62      */

63     public void putField(Reference fieldref, Object JavaDoc obj, Object JavaDoc value)
64     throws InterpreterException;
65
66
67     /**
68      * Invoke a method.
69      * @param methodRef the reference to the method.
70      * @param isVirtual true, iff the call is virtual
71      * @param cls the object on which the method should be called, null
72      * if the method is static.
73      * @param params the params of the method.
74      * @return the return value of the method. Void type is ignored,
75      * may be null.
76      * @exception InterpreterException if the field does not exists, the
77      * object is not supported etc. */

78     public Object JavaDoc invokeMethod(Reference methodRef, boolean isVirtual,
79                    Object JavaDoc cls, Object JavaDoc[] params)
80     throws InterpreterException, InvocationTargetException JavaDoc;
81
82     /**
83      * Create a new instance of an object.
84      * @param methodRef the reference of the constructor to invoke
85      * @param params the params of the method.
86      * @return the new object.
87      */

88     public Object JavaDoc invokeConstructor(Reference methodRef, Object JavaDoc[] params)
89     throws InterpreterException, InvocationTargetException JavaDoc;
90
91     /**
92      * Check if obj is an instance of className
93      * @param className the type signature of the class.
94      * @return true, if obj is an instance of className, false otherwise.
95      */

96     public boolean instanceOf(Object JavaDoc obj, String JavaDoc className)
97     throws InterpreterException;
98
99     /**
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 JavaDoc newArray(String JavaDoc 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 JavaDoc obj)
113     throws InterpreterException;
114     /**
115      * Exit a monitor.
116      * @param object the object whose monitor should be freed.
117      */

118     public void exitMonitor(Object JavaDoc obj)
119     throws InterpreterException;
120 }
121
122
Popular Tags