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.compilers.common;
014
015import static org.jikesrvm.runtime.UnboxedSizeConstants.BYTES_IN_ADDRESS;
016
017import org.jikesrvm.mm.mminterface.GCMapIterator;
018import org.jikesrvm.runtime.Magic;
019import org.vmmagic.pragma.Uninterruptible;
020import org.vmmagic.unboxed.Address;
021import org.vmmagic.unboxed.AddressArray;
022import org.vmmagic.unboxed.Offset;
023import org.vmmagic.unboxed.WordArray;
024
025/**
026 * Iterator for stack frames inserted by hardware trap handler.
027 * Such frames are purely used as markers.
028 * They contain no object references or JSR return addresses.
029 */
030@Uninterruptible
031public final class HardwareTrapGCMapIterator extends GCMapIterator {
032
033  public HardwareTrapGCMapIterator(AddressArray registerLocations) {
034    super(registerLocations);
035  }
036
037  @Override
038  public void setupIterator(CompiledMethod compiledMethod, Offset instructionOffset, Address framePtr) {
039    this.framePtr = framePtr;
040  }
041
042  @Override
043  public Address getNextReferenceAddress() {
044    // update register locations, noting that the trap handler represented by this stackframe
045    // saved all registers into the thread's "exceptionRegisters" object
046    //
047    WordArray gprs  = thread.getExceptionRegisters().getGPRs();
048    Address gprAddr = Magic.objectAsAddress(gprs);
049    for (int i = 0; i < gprs.length(); ++i) {
050      registerLocations.set(i, gprAddr);
051      gprAddr = gprAddr.plus(BYTES_IN_ADDRESS);
052    }
053    return Address.zero();
054  }
055
056  @Override
057  public Address getNextReturnAddressAddress() {
058    return Address.zero();
059  }
060
061  @Override
062  public void reset() {}
063
064  @Override
065  public void cleanupPointers() {}
066
067  @Override
068  public int getType() {
069    return CompiledMethod.TRAP;
070  }
071}