org.jikesrvm.compilers.common.assembler
Class ForwardReference

java.lang.Object
  extended by org.jikesrvm.compilers.common.assembler.ForwardReference
Direct Known Subclasses:
ForwardReference.ConditionalBranch, ForwardReference.LoadReturnAddress, ForwardReference.ShortBranch, ForwardReference.SwitchCase, ForwardReference.UnconditionalBranch

public abstract class ForwardReference
extends Object

A forward reference has a machine-code-index source and optionally a bytecode-index target. The idea is to fix up the instruction at the source when the machine-code-index of the target is known. There need not be an explicit target, if the reference is used (by the compiler) within the machine-code for one bytecode.

There are three kinds of forward reference:

  1. unconditional branches
  2. conditional branches
  3. switch cases
Each subclass must be able to resolve itself.

This class also includes the machinery for maintaining a priority queue of forward references, priorities being target bytecode addresses. The head of this priority queue is maintained by a Assembler object.

The priority queue is implemented as a one-way linked list of forward references with strictly increasing targets. The link for this list is "next". A separate linked list ("other" is the link) contains all forward references with the same target.


Nested Class Summary
static class ForwardReference.ConditionalBranch
           
static class ForwardReference.LoadReturnAddress
           
static class ForwardReference.ShortBranch
           
static class ForwardReference.SwitchCase
           
static class ForwardReference.UnconditionalBranch
           
 
Field Summary
(package private)  ForwardReference next
          Has next larger targetBytecodeIndex
(package private)  ForwardReference other
          Has the same targetBytecodeIndex
(package private)  int sourceMachinecodeIndex
           
(package private)  int targetBytecodeIndex
           
 
Constructor Summary
protected ForwardReference(int source)
          No target; for use within cases of the main compiler loop
protected ForwardReference(int source, int btarget)
           
 
Method Summary
static ForwardReference enqueue(ForwardReference q, ForwardReference r)
          Add a new reference r to a priority queue q
abstract  void resolve(AbstractAssembler asm)
          Rewrite source to reference current machine code (in asm's machineCodes)
static ForwardReference resolveMatching(AbstractAssembler asm, ForwardReference q, int bi)
          Resolve any forward references on priority queue q to bytecode index bi
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sourceMachinecodeIndex

final int sourceMachinecodeIndex

targetBytecodeIndex

final int targetBytecodeIndex

next

ForwardReference next
Has next larger targetBytecodeIndex


other

ForwardReference other
Has the same targetBytecodeIndex

Constructor Detail

ForwardReference

protected ForwardReference(int source,
                           int btarget)

ForwardReference

protected ForwardReference(int source)
No target; for use within cases of the main compiler loop

Method Detail

resolve

public abstract void resolve(AbstractAssembler asm)
Rewrite source to reference current machine code (in asm's machineCodes)


enqueue

public static ForwardReference enqueue(ForwardReference q,
                                       ForwardReference r)
Add a new reference r to a priority queue q

Returns:
the updated queue

resolveMatching

public static ForwardReference resolveMatching(AbstractAssembler asm,
                                               ForwardReference q,
                                               int bi)
Resolve any forward references on priority queue q to bytecode index bi

Returns:
queue of unresolved references