View Javadoc

1   // BootstrapCodeAddress.java, created Wed Sep 18  1:22:47 2002 by joewhaley
2   // Copyright (C) 2001-3 John Whaley <jwhaley@alum.mit.edu>
3   // Licensed under the terms of the GNU LGPL; see COPYING for details.
4   package joeq.Bootstrap;
5   
6   import joeq.Class.PrimordialClassLoader;
7   import joeq.Class.jq_Class;
8   import joeq.Memory.Address;
9   import joeq.Memory.CodeAddress;
10  import jwutil.strings.Strings;
11  
12  /***
13   * BootstrapCodeAddress
14   *
15   * @author  John Whaley <jwhaley@alum.mit.edu>
16   * @version $Id: BootstrapCodeAddress.java 1941 2004-09-30 03:37:06Z joewhaley $
17   */
18  public class BootstrapCodeAddress extends CodeAddress implements BootstrapAddress {
19  
20      public static BootstrapCodeAddressFactory FACTORY = new BootstrapCodeAddressFactory(BootstrapCodeAllocator.DEFAULT);
21      
22      public static class BootstrapCodeAddressFactory extends CodeAddressFactory {
23          final BootstrapCodeAllocator bca;
24          public BootstrapCodeAddressFactory(BootstrapCodeAllocator bca) {
25              this.bca = bca;
26          }
27          public int size() { return 4; }
28          public CodeAddress getNull() { return NULL; }
29          public static final BootstrapCodeAddress NULL = new BootstrapCodeAddress(0);
30      }
31      
32      public final int value;
33      
34      public BootstrapCodeAddress(int value) { this.value = value; }
35      
36      public Address peek() { return FACTORY.bca.peek(this); }
37      public byte    peek1() { return FACTORY.bca.peek1(this); }
38      public short   peek2() { return FACTORY.bca.peek2(this); }
39      public int     peek4() { return FACTORY.bca.peek4(this); }
40      public long    peek8() { return FACTORY.bca.peek8(this); }
41      
42      public void poke(Address v) { FACTORY.bca.poke(this, v); }
43      public void poke1(byte v) { FACTORY.bca.poke1(this, v); }
44      public void poke2(short v) { FACTORY.bca.poke2(this, v); }
45      public void poke4(int v) { FACTORY.bca.poke4(this, v); }
46      public void poke8(long v) { FACTORY.bca.poke8(this, v); }
47      
48      public Address offset(int offset) { return new BootstrapCodeAddress(value+offset); }
49      public Address align(int shift) {
50          int mask = (1 << shift) - 1;
51          return new BootstrapCodeAddress((value+mask)&~mask);
52      }
53      public int difference(Address v) { return this.value - v.to32BitValue(); }
54      public boolean isNull() { return value == 0; }
55      
56      public int to32BitValue() { return value; }
57      public String stringRep() { return Strings.hex8(value); }
58      
59      public static final jq_Class _class;
60      static {
61          _class = (jq_Class) PrimordialClassLoader.loader.getOrCreateBSType("Ljoeq/Bootstrap/BootstrapCodeAddress;");
62      }
63  }