View Javadoc

1   /*
2    * @(#) JSR.java Jan 8, 2004
3    * 
4    * Copyright (c) 2003 Delft University of Technology Jaffalaan 5, 2628 BX Delft,
5    * the Netherlands All rights reserved.
6    * 
7    * This software is proprietary information of Delft University of Technology
8    * The code is published under the General Public License
9    */
10  package nl.tudelft.simulation.dsol.interpreter.operations;
11  
12  import java.io.DataInput;
13  import java.io.IOException;
14  
15  import nl.tudelft.simulation.dsol.interpreter.LocalVariable;
16  import nl.tudelft.simulation.dsol.interpreter.OperandStack;
17  import nl.tudelft.simulation.dsol.interpreter.classfile.Constant;
18  
19  /***
20   * The JSR operation as defined in <a
21   * href="http://java.sun.com/docs/books/vmspec/2nd-edition/html/Instructions2.doc7.html">
22   * http://java.sun.com/docs/books/vmspec/2nd-edition/html/Instructions2.doc7.html
23   * </a>.
24   * <p>
25   * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
26   * University of Technology </a>, the Netherlands. <br>
27   * See for project information <a
28   * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
29   * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
30   * License (GPL) </a>, no warranty <br>
31   * 
32   * @author <a href="http://www.tbm.tudelft.nl/webstaf/peterja/index.htm">Peter
33   *         Jacobs </a><a
34   *         href="http://www.tbm.tudelft.nl/webstaf/alexandv/index.htm">Alexander
35   *         Verbraeck </a>
36   * @version 1.3 Apr 6, 2004
37   * @since 1.4
38   */
39  public class JSR extends JumpOperation
40  {
41  	/*** OP refers to the operand code */
42  	public static final int OP = 168;
43  
44  	/*** the index to load */
45  	private int offset = -1;
46  
47  	/*** the startAddress of the next operation */
48  	private int nextAddress = -1;
49  
50  	/***
51  	 * constructs a new JSR
52  	 * 
53  	 * @param dataInput the dataInput
54  	 * @param startBytePosition the startBytePosition of this operation
55  	 * @throws IOException on IOfailure
56  	 */
57  	public JSR(final DataInput dataInput, final int startBytePosition)
58  			throws IOException
59  	{
60  		super();
61  		this.offset = dataInput.readShort();
62  		this.nextAddress = this.getByteLength() + startBytePosition;
63  	}
64  
65  	/***
66  	 * @see nl.tudelft.simulation.dsol.interpreter.operations.JumpOperation
67  	 *      #execute(nl.tudelft.simulation.dsol.interpreter.OperandStack,
68  	 *      nl.tudelft.simulation.dsol.interpreter.classfile.Constant[],
69  	 *      nl.tudelft.simulation.dsol.interpreter.LocalVariable[])
70  	 */
71  	public int execute(final OperandStack stack, final Constant[] constantPool,
72  			final LocalVariable[] localVariables)
73  	{
74  		stack.push(new Integer(this.nextAddress));
75  		return this.offset;
76  	}
77  
78  	/***
79  	 * @see nl.tudelft.simulation.dsol.interpreter.Operation#getByteLength()
80  	 */
81  	public int getByteLength()
82  	{
83  		return OPCODE_BYTE_LENGTH + 2;
84  	}
85  
86  	/***
87  	 * @see nl.tudelft.simulation.dsol.interpreter.Operation#getOpcode()
88  	 */
89  	public int getOpcode()
90  	{
91  		return JSR.OP;
92  	}
93  }