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.classloader.RVMMethod; 016 import org.jikesrvm.classloader.TypeReference; 017 import org.jikesrvm.compilers.common.CompiledMethod; 018 import org.jikesrvm.compilers.common.CompiledMethods; 019 020 /** 021 * invoke a compiled method 022 */ 023 public class InvokeCompiledMethod extends PseudoBytecode { 024 025 private static int bsize = 10; 026 private int cmid; 027 028 // the bc index of referred call site 029 private int origIdx; 030 031 public InvokeCompiledMethod(int cmethId, int origBCIndex) { 032 this.cmid = cmethId; 033 this.origIdx = origBCIndex; 034 } 035 036 @Override 037 public byte[] getBytes() { 038 byte[] codes = initBytes(bsize, PSEUDO_InvokeCompiledMethod); 039 int2bytes(codes, 2, cmid); 040 int2bytes(codes, 6, origIdx); 041 return codes; 042 } 043 044 @Override 045 public int getSize() { 046 return bsize; 047 } 048 049 @Override 050 public int stackChanges() { 051 CompiledMethod cm = CompiledMethods.getCompiledMethod(cmid); 052 RVMMethod callee = cm.getMethod(); 053 054 int psize = callee.getParameterWords(); 055 int schanges = -psize; 056 057 // pop receiver 058 if (!callee.isStatic()) { 059 schanges--; 060 } 061 062 TypeReference rtype = callee.getReturnType(); 063 byte tcode = rtype.getName().parseForTypeCode(); 064 065 if (tcode == VoidTypeCode) { 066 // do nothing 067 } else { 068 if ((tcode == LongTypeCode) || (tcode == DoubleTypeCode)) { 069 schanges++; 070 } 071 schanges++; 072 } 073 074 return schanges; 075 } 076 077 @Override 078 public String toString() { 079 //CompiledMethod cm = CompiledMethods.getCompiledMethod(cmid); 080 return "InvokeCompiledMethod (0x" + Integer.toHexString(cmid) + ") " + "@" + origIdx; 081 } 082 }