1
2
3
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;
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
95
96
97 public Address align(int shift) {
98 return this;
99 }
100
101
102
103 public int difference(Address v) {
104 return 0;
105 }
106
107
108
109 public boolean isNull() {
110 return true;
111 }
112
113
114
115 public Address offset(int offset) {
116 return this;
117 }
118
119
120
121 public Address peek() {
122 return this;
123 }
124
125
126
127 public byte peek1() {
128 return 0;
129 }
130
131
132
133 public short peek2() {
134 return 0;
135 }
136
137
138
139 public int peek4() {
140 return 0;
141 }
142
143
144
145 public long peek8() {
146 return 0;
147 }
148
149
150
151 public void poke(Address v) {
152 }
153
154
155
156 public void poke1(byte v) {
157 }
158
159
160
161 public void poke2(short v) {
162 }
163
164
165
166 public void poke4(int v) {
167 }
168
169
170
171 public void poke8(long v) {
172 }
173
174
175
176 public String stringRep() {
177 return "bogus";
178 }
179
180
181
182 public int to32BitValue() {
183 return 0;
184 }
185 }
186
187 }