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 import org.jikesrvm.SizeConstants; 016 import org.jikesrvm.classloader.BytecodeConstants; 017 import org.jikesrvm.osr.OSRConstants; 018 import org.vmmagic.unboxed.Word; 019 020 /** 021 * OSR_PseudoBytecode is super class of all pseudo instructions. 022 */ 023 public abstract class PseudoBytecode implements BytecodeConstants, OSRConstants, SizeConstants { 024 025 public PseudoBytecode next; 026 027 public abstract byte[] getBytes(); 028 029 public abstract int getSize(); 030 031 public abstract int stackChanges(); 032 033 public static byte[] initBytes(int size, int instruction) { 034 byte[] code = new byte[size]; 035 code[0] = (byte) JBC_impdep1; 036 code[1] = (byte) instruction; 037 return code; 038 } 039 040 public static void int2bytes(byte[] to, int p, int value) { 041 042 for (int i = 3; i >= 0; i--) { 043 to[p++] = (byte) ((value >>> (i << LOG_BITS_IN_BYTE)) & 0x0FF); 044 } 045 } 046 047 public static void long2bytes(byte[] to, int p, long value) { 048 049 for (int i = 7; i >= 0; i--) { 050 to[p++] = (byte) ((value >>> (i << LOG_BITS_IN_BYTE)) & 0x0FF); 051 } 052 } 053 054 public static void word2bytes(byte[] to, int p, Word value) { 055 056 for (int i = BYTES_IN_ADDRESS - 1; i >= 0; i--) { 057 to[p++] = (byte) (value.rshl(i << LOG_BITS_IN_BYTE).toInt() & 0x0FF); 058 } 059 } 060 061 public static void float2bytes(byte[] to, int p, float value) { 062 063 int v = Float.floatToIntBits(value); 064 int2bytes(to, p, v); 065 } 066 067 public static void double2bytes(byte[] to, int p, double value) { 068 069 long v = Double.doubleToLongBits(value); 070 long2bytes(to, p, v); 071 } 072 073 public static byte[] makeOUUcode(int op, int idx) { 074 075 byte[] codes = new byte[3]; 076 codes[0] = (byte) op; 077 codes[1] = (byte) ((idx >> 8) & 0x0FF); 078 codes[2] = (byte) (idx & 0x0FF); 079 080 return codes; 081 } 082 083 public static byte[] makeWOUUcode(int op, int idx) { 084 byte[] codes = new byte[4]; 085 codes[0] = (byte) JBC_wide; 086 codes[1] = (byte) op; 087 codes[2] = (byte) ((idx >> 8) & 0x0FF); 088 codes[3] = (byte) (idx & 0x0FF); 089 return codes; 090 } 091 092 public static byte[] makeOUcode(int op, int idx) { 093 byte[] codes = new byte[2]; 094 codes[0] = (byte) op; 095 codes[1] = (byte) (idx & 0x0FF); 096 return codes; 097 } 098 }