View Javadoc

1   // HostedVM.java, created Sat Dec 14  2:52:34 2002 by mcmartin
2   // Copyright (C) 2001-3 mcmartin
3   // Licensed under the terms of the GNU LGPL; see COPYING for details.
4   package joeq.Main;
5   
6   import java.util.Iterator;
7   import joeq.Class.PrimordialClassLoader;
8   import joeq.ClassLib.ClassLibInterface;
9   import joeq.Memory.Address;
10  import joeq.Memory.CodeAddress;
11  import joeq.Memory.HeapAddress;
12  import joeq.Memory.StackAddress;
13  import joeq.Runtime.Reflection;
14  import jwutil.util.Assert;
15  
16  /***
17   * @author  Michael Martin <mcmartin@stanford.edu>
18   * @version $Id: HostedVM.java 1931 2004-09-22 22:17:47Z joewhaley $
19   */
20  public abstract class HostedVM {
21      public static void initialize() {
22          if (jq.RunningNative) return;
23          
24          jq.DontCompile = true;
25  
26          CodeAddress.FACTORY = new CodeAddress.CodeAddressFactory() {
27              public int size() {
28                  return 4;
29              }
30              public CodeAddress getNull() {
31                  return null;
32              }
33          };
34          HeapAddress.FACTORY = new HeapAddress.HeapAddressFactory() {
35              public int size() {
36                  return 4;
37              }
38              
39              public int logSize() {
40                  return 2;
41              }
42              
43              public int pageAlign() {
44                  return 12; // 2**12 = 4096
45              }
46  
47              public HeapAddress getNull() {
48                  return bogus_heap_address;
49              }
50  
51              public HeapAddress addressOf(Object o) {
52                  return bogus_heap_address;
53              }
54  
55              public HeapAddress address32(int val) {
56                  return bogus_heap_address;
57              }
58          };
59          StackAddress.FACTORY = new StackAddress.StackAddressFactory() {
60              public int size() {
61                  return 4;
62              }
63  
64              public StackAddress alloca(int a) {
65                  Assert.UNREACHABLE();
66                  return null;
67              }
68  
69              public StackAddress getBasePointer() {
70                  Assert.UNREACHABLE();
71                  return null;
72              }
73  
74              public StackAddress getStackPointer() {
75                  Assert.UNREACHABLE();
76                  return null;
77              }
78          };
79          String classpath = System.getProperty("sun.boot.class.path") + System.getProperty("path.separator") + System.getProperty("java.class.path");
80          for (Iterator it = PrimordialClassLoader.classpaths(classpath); it.hasNext();) {
81              String s = (String) it.next();
82              PrimordialClassLoader.loader.addToClasspath(s);
83          }
84          Reflection.obj_trav = ClassLibInterface.DEFAULT.getObjectTraverser();
85          Reflection.obj_trav.initialize();
86      }
87      
88      public static final BogusHeapAddress bogus_heap_address = new BogusHeapAddress();
89      
90      public static class BogusHeapAddress extends HeapAddress {
91          
92          private BogusHeapAddress() {}
93          
94          /* (non-Javadoc)
95           * @see joeq.Memory.Address#align(int)
96           */
97          public Address align(int shift) {
98              return this;
99          }
100         /* (non-Javadoc)
101          * @see joeq.Memory.Address#difference(joeq.Memory.Address)
102          */
103         public int difference(Address v) {
104             return 0;
105         }
106         /* (non-Javadoc)
107          * @see joeq.Memory.Address#isNull()
108          */
109         public boolean isNull() {
110             return true;
111         }
112         /* (non-Javadoc)
113          * @see joeq.Memory.Address#offset(int)
114          */
115         public Address offset(int offset) {
116             return this;
117         }
118         /* (non-Javadoc)
119          * @see joeq.Memory.Address#peek()
120          */
121         public Address peek() {
122             return this;
123         }
124         /* (non-Javadoc)
125          * @see joeq.Memory.Address#peek1()
126          */
127         public byte peek1() {
128             return 0;
129         }
130         /* (non-Javadoc)
131          * @see joeq.Memory.Address#peek2()
132          */
133         public short peek2() {
134             return 0;
135         }
136         /* (non-Javadoc)
137          * @see joeq.Memory.Address#peek4()
138          */
139         public int peek4() {
140             return 0;
141         }
142         /* (non-Javadoc)
143          * @see joeq.Memory.Address#peek8()
144          */
145         public long peek8() {
146             return 0;
147         }
148         /* (non-Javadoc)
149          * @see joeq.Memory.Address#poke(joeq.Memory.Address)
150          */
151         public void poke(Address v) {
152         }
153         /* (non-Javadoc)
154          * @see joeq.Memory.Address#poke1(byte)
155          */
156         public void poke1(byte v) {
157         }
158         /* (non-Javadoc)
159          * @see joeq.Memory.Address#poke2(short)
160          */
161         public void poke2(short v) {
162         }
163         /* (non-Javadoc)
164          * @see joeq.Memory.Address#poke4(int)
165          */
166         public void poke4(int v) {
167         }
168         /* (non-Javadoc)
169          * @see joeq.Memory.Address#poke8(long)
170          */
171         public void poke8(long v) {
172         }
173         /* (non-Javadoc)
174          * @see joeq.Memory.Address#stringRep()
175          */
176         public String stringRep() {
177             return "bogus";
178         }
179         /* (non-Javadoc)
180          * @see joeq.Memory.Address#to32BitValue()
181          */
182         public int to32BitValue() {
183             return 0;
184         }
185 }
186 
187 }