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 */
013package org.jikesrvm.osr.bytecodes;
014
015import static org.jikesrvm.classloader.ClassLoaderConstants.DoubleTypeCode;
016import static org.jikesrvm.classloader.ClassLoaderConstants.LongTypeCode;
017import static org.jikesrvm.classloader.ClassLoaderConstants.VoidTypeCode;
018import static org.jikesrvm.osr.OSRConstants.CLEANREFS;
019import static org.jikesrvm.osr.OSRConstants.GETREFAT;
020import static org.jikesrvm.osr.OSRConstants.PSEUDO_InvokeStatic;
021
022import org.jikesrvm.VM;
023import org.jikesrvm.adaptive.AosEntrypoints;
024import org.jikesrvm.classloader.RVMMethod;
025import org.jikesrvm.classloader.TypeReference;
026
027/**
028 * Special invokestatic, with only two possible target
029 * ObjectHolder.getRefAt and ObjectHolder.cleanRefs
030 * indiced by GETREFAT and CLEANREFS.
031 */
032public class InvokeStatic extends PseudoBytecode {
033
034  private static final int bsize = 6;
035  private final int tid;  // target INDEX
036
037  public InvokeStatic(int targetId) {
038    this.tid = targetId;
039  }
040
041  @Override
042  public byte[] getBytes() {
043    byte[] codes = initBytes(bsize, PSEUDO_InvokeStatic);
044    int2bytes(codes, 2, tid);
045    return codes;
046  }
047
048  @Override
049  public int getSize() {
050    return bsize;
051  }
052
053  @Override
054  public int stackChanges() {
055    RVMMethod callee = targetMethod(tid);
056    int psize = callee.getParameterWords();
057    int schanges = -psize;
058
059    TypeReference rtype = callee.getReturnType();
060    byte tcode = rtype.getName().parseForTypeCode();
061
062    if (tcode == VoidTypeCode) {
063      // do nothing
064    } else {
065      if ((tcode == LongTypeCode) || (tcode == DoubleTypeCode)) {
066        schanges++;
067      }
068      schanges++;
069    }
070
071    return schanges;
072  }
073
074  @Override
075  public String toString() {
076    return "InvokeStatic " + tid;
077  }
078
079  public static RVMMethod targetMethod(int tid) {
080    switch (tid) {
081      case GETREFAT:
082        return AosEntrypoints.osrGetRefAtMethod;
083      case CLEANREFS:
084        return AosEntrypoints.osrCleanRefsMethod;
085      default:
086        if (VM.VerifyAssertions) VM._assert(VM.NOT_REACHED);
087        return null;
088    }
089  }
090}