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.ia32;
014
015import static org.jikesrvm.ia32.RegisterConstants.NUM_FPRS;
016import static org.jikesrvm.ia32.RegisterConstants.NUM_GPRS;
017
018import org.jikesrvm.architecture.AbstractRegisters;
019import org.jikesrvm.util.Services;
020import org.vmmagic.unboxed.Address;
021import org.vmmagic.unboxed.WordArray;
022
023/**
024 * Temporary register set.
025 * see: Registers
026 */
027public class TempRegisters {
028
029  final Address ip;        // next instruction address
030  final WordArray gprs;
031  final double[] fprs;
032
033  /**
034   * if a GPR hold a reference to an object, we convert the raw memory
035   * address to a reference. When objs[i] is null, the GPR[i] is not
036   * holding a reference.
037   */
038  final Object[] objs;
039
040  public TempRegisters(AbstractRegisters contextRegisters) {
041    gprs = WordArray.create(NUM_GPRS);
042    fprs = new double[NUM_FPRS];
043    objs = new Object[NUM_GPRS];
044
045    for (int i = 0; i < NUM_GPRS; i++) {
046      gprs.set(i, contextRegisters.getGPRs().get(i));
047    }
048    System.arraycopy(contextRegisters.getFPRs(), 0, fprs, 0, NUM_FPRS);
049    ip = contextRegisters.getIP();
050  }
051
052  public void dumpContents() {
053    System.err.println("OSR_TempRegister: @" + Services.addressAsHexString(ip));
054    System.err.println("  GPRS: ");
055    for (int i = 0; i < NUM_GPRS; i++) {
056      System.err.println("    (" + i + "," + Services.addressAsHexString(gprs.get(i).toAddress()) + ")");
057    }
058
059    System.err.println();
060    System.err.println("  OBJS: ");
061    for (int i = 0; i < NUM_GPRS; i++) {
062      if (objs[i] != null) {
063        System.err.println("    (" + i + "," + objs[i] + ")");
064      }
065    }
066
067    System.err.println();
068    System.err.println("  FPRS  ");
069    for (int i = 0; i < NUM_FPRS; i++) {
070      System.err.println("    (" + i + "," + fprs[i] + ")");
071    }
072  }
073}