001 /* 002 * This file is part of the Jikes RVM project (http://jikesrvm.org). 003 * 004 * This file is licensed to You under the Eclipse Public License (EPL); 005 * You may not use this file except in compliance with the License. You 006 * may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/eclipse-1.0.php 009 * 010 * See the COPYRIGHT.txt file distributed with this work for information 011 * regarding copyright ownership. 012 */ 013 package org.jikesrvm.osr.bytecodes; 014 015 016 /** 017 * goto instruction 018 */ 019 public class Goto extends PseudoBytecode { 020 private int offset; 021 private byte[] codes; 022 private int bsize; 023 024 public Goto(int off) { 025 this.offset = off; 026 adjustFields(); 027 } 028 029 @Override 030 public byte[] getBytes() { 031 return codes; 032 } 033 034 @Override 035 public int getSize() { 036 return bsize; 037 } 038 039 public int getOffset() { 040 return this.offset; 041 } 042 043 @Override 044 public int stackChanges() { 045 return 0; 046 } 047 048 public void patch(int off) { 049 this.offset = off; 050 adjustFields(); 051 } 052 053 private void adjustFields() { 054 if ((offset >= -32768) && (offset <= 32767)) { 055 bsize = 3; 056 codes = new byte[3]; 057 codes[0] = (byte) JBC_goto; 058 codes[1] = (byte) (offset >> 8); 059 codes[2] = (byte) (offset & 0xFF); 060 } else { 061 bsize = 5; 062 codes = new byte[5]; 063 codes[0] = (byte) JBC_goto_w; 064 int2bytes(codes, 1, offset); 065 } 066 } 067 068 @Override 069 public String toString() { 070 return "goto " + this.offset; 071 } 072 }