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 */
013 package org.jikesrvm.runtime;
014
015 import org.jikesrvm.VM;
016 import org.jikesrvm.mm.mminterface.MemoryManager;
017 import org.vmmagic.pragma.Entrypoint;
018 import org.vmmagic.pragma.Uninterruptible;
019 import org.vmmagic.pragma.Untraced;
020 import org.vmmagic.unboxed.Address;
021 import org.vmmagic.unboxed.AddressArray;
022 import org.vmmagic.unboxed.Extent;
023 import org.vmmagic.unboxed.Offset;
024
025 /**
026 * Information required to start the virtual machine and communicate
027 * with the outside world.
028 *
029 * <p> The virtual machine image consists entirely of java objects.
030 * The first java-object, the boot record, is the communication area between
031 * the host operating system and the virtual machine. It consists of read-only
032 * fields containing startup information used by the assembler bootstrap
033 * loader, by the virtual machine's initializer methods, and by the virtual
034 * machine's operating system call interface methods.
035 *
036 * <p> See also: BootImageWriter.main(), RunBootImage.C
037 *
038 * <p>The boot record looks like this
039 * (note that fields are layed out "backwards"):
040 *
041 * <pre>
042 * lo-mem
043 * +---------------+
044 * | fieldN-1 |
045 * +---------------+
046 * | ... |
047 * +---------------+
048 * | field1 |
049 * +---------------+
050 * | field0 |
051 * +---------------+ \
052 * | tib pointer | |
053 * +---------------+ | object header
054 * | lock word | |
055 * +---------------+ /
056 * hi-mem
057 * </pre>
058 *
059 * The "spRegister" field of the boot record points to the word immediately
060 * preceeding the top of a stack object (ie. it's ready to accept a "push"
061 * instruction). The stack object is an array of words that looks like this:
062 *
063 * <pre>
064 * lo-mem
065 * +---------------+ \
066 * | tib pointer | |
067 * +---------------+ | array
068 * | lock word | | object
069 * +---------------+ | header
070 * | .length | |
071 * +---------------+ /
072 * | <empty> |
073 * +---------------+
074 * | ... |
075 * +---------------+
076 * | <empty> |
077 * +---------------+
078 * spRegister -> hi-mem
079 * </pre>
080 *
081 * <P> The "ipRegister" field of the boot record points to the first word
082 * of an array of machine instructions comprising
083 * the virtual machine's startoff code -- see "VM.boot()".
084 *
085 * <P> The "tocRegister" field of the boot record points to an array of words
086 * containing the static fields and method addresses of the virtual
087 * machine image -- see "Statics.slots[]".
088 *
089 * <P> The remaining fields of the boot record serve as a function linkage area
090 * between services residing in the host operating system and services
091 * residing in the virtual machine.
092 */
093 public class BootRecord {
094 /**
095 * The following static field is initialized by the boot image writer.
096 * It allows the virtual machine to address the boot record using normal
097 * field access instructions (the assembler bootstrap function, on the other
098 * hand, simply addresses the boot record as the first object in
099 * the boot image).
100 */
101 @Entrypoint
102 public static BootRecord the_boot_record;
103
104 public BootRecord() {
105 int len = 2 * (1 + MemoryManager.getMaxHeaps());
106 heapRanges = AddressArray.create(len);
107 // Indicate end of array with sentinel value
108 heapRanges.set(len - 1, Address.fromIntSignExtend(-1));
109 heapRanges.set(len - 2, Address.fromIntSignExtend(-1));
110 }
111
112 public void showHeapRanges() {
113 for (int i = 0; i < heapRanges.length() / 2; i++) {
114 VM.sysWrite(i, " ");
115 VM.sysWrite(heapRanges.get(2 * i));
116 VM.sysWrite(" ", heapRanges.get(2 * i + 1));
117 VM.sysWrite(" ");
118 }
119 }
120
121 @Uninterruptible
122 public void setHeapRange(int id, Address start, Address end) {
123 if (VM.VerifyAssertions) VM._assert(id < heapRanges.length() - 2);
124 heapRanges.set(2 * id, start);
125 heapRanges.set(2 * id + 1, end);
126 }
127
128 // The following fields are written when the virtual machine image
129 // is generated (see BootImage.java), loaded (see RunBootImage.C),
130 // or executed (see VM.java).
131 //
132 // If you add/remove/change fields here, be sure to change the
133 // corresponding code in RunBootImage.
134
135 /**
136 * address at which image is to be loaded into memory
137 */
138 public Address bootImageDataStart;
139 public Address bootImageDataEnd;
140 public Address bootImageCodeStart;
141 public Address bootImageCodeEnd;
142 public Address bootImageRMapStart;
143 public Address bootImageRMapEnd;
144
145 /**
146 * initial size of heap
147 */
148 public Extent initialHeapSize;
149
150 /**
151 * maximum size of heap
152 */
153 public Extent maximumHeapSize;
154
155 @Untraced
156 public AddressArray heapRanges; // [start1, end1, ..., start_k, end_k, -1, -1]
157 // C-style termination with sentinel values
158 /**
159 * Verbosity level for booting
160 * set by -X:verboseBoot=
161 */
162 public int verboseBoot = 0;
163
164 // RVM startoff
165 //
166 public int tiRegister; // value to place into TI register
167 public Address spRegister; // value to place into SP register
168 public Address ipRegister; // value to place into IP register
169 public Address tocRegister; // value to place into JTOC register
170
171 /**
172 * flag to indicate RVM has completed booting and ready to run Java programs
173 * added by Ton Ngo for JNI support
174 */
175 int bootCompleted; // use for start up by JNI_CreateJavaVM
176
177 /**
178 * address of JavaVM, used by JNI_OnLoad and JNIEnv.GetJavaVM,
179 * defined in Sys.C
180 */
181 public Address sysJavaVM;
182
183 // Additional RVM entrypoints
184 //
185 /**
186 * method id for inserting stackframes at site of hardware traps
187 */
188 int hardwareTrapMethodId;
189 /**
190 * jtoc offset of RuntimeEntrypoints.deliverHardwareException()
191 */
192 Offset deliverHardwareExceptionOffset;
193 /**
194 * jtoc offset of RVMThread.dumpStackAndDie(I)
195 */
196 public Offset dumpStackAndDieOffset;
197 /**
198 * jtoc offset of RVMThread.bootThread
199 */
200 public Offset bootThreadOffset;
201 /**
202 * jtoc offset of RVMThread.debugRequested
203 */
204 Offset debugRequestedOffset;
205 /**
206 * an external signal has been sent e.g. kill -signalnumber processid
207 */
208 @Entrypoint
209 int externalSignalFlag;
210
211 // Host operating system entrypoints - see "sys.C"
212 //
213
214 // lowlevel write to console
215 public Address sysConsoleWriteCharIP;
216 public Address sysConsoleWriteIntegerIP;
217 public Address sysConsoleWriteLongIP;
218 public Address sysConsoleWriteDoubleIP;
219
220 // startup/shutdown
221 public Address sysExitIP;
222 public Address sysArgIP;
223
224 // misc. info on the process -- used in startup/shutdown
225 public Address sysGetenvIP;
226
227 // memory
228 public Address sysCopyIP;
229 public Address sysMallocIP;
230 public Address sysCallocIP;
231 public Address sysFreeIP;
232 public Address sysZeroIP;
233 public Address sysZeroPagesIP;
234 public Address sysSyncCacheIP;
235
236 // files
237 public Address sysStatIP;
238 public Address sysReadByteIP;
239 public Address sysWriteByteIP;
240 public Address sysReadBytesIP;
241 public Address sysWriteBytesIP;
242 public Address sysBytesAvailableIP;
243 public Address sysSyncFileIP;
244 public Address sysSetFdCloseOnExecIP;
245
246 public Address sysAccessIP;
247
248 // mmap - memory mapping
249 public Address sysMMapIP;
250 public Address sysMMapErrnoIP;
251 public Address sysMProtectIP;
252 public Address sysGetPageSizeIP;
253
254 // threads
255 public Address sysNumProcessorsIP;
256 public Address sysThreadBindSupportedIP;
257 public Address sysThreadBindIP;
258 public Address sysThreadCreateIP;
259 public Address sysThreadYieldIP;
260 public Address sysGetThreadIdIP;
261 public Address sysSetupHardwareTrapHandlerIP;
262 public Address sysStashVMThreadIP;
263 public Address sysThreadTerminateIP;
264
265 // monitors
266 public Address sysMonitorCreateIP;
267 public Address sysMonitorDestroyIP;
268 public Address sysMonitorEnterIP;
269 public Address sysMonitorExitIP;
270 public Address sysMonitorTimedWaitAbsoluteIP;
271 public Address sysMonitorWaitIP;
272 public Address sysMonitorBroadcastIP;
273
274 // arithmetic
275 @Entrypoint
276 public Address sysLongDivideIP;
277 @Entrypoint
278 public Address sysLongRemainderIP;
279 @Entrypoint
280 public Address sysLongToFloatIP;
281 @Entrypoint
282 public Address sysLongToDoubleIP;
283 @Entrypoint
284 public Address sysFloatToIntIP;
285 @Entrypoint
286 public Address sysDoubleToIntIP;
287 @Entrypoint
288 public Address sysFloatToLongIP;
289 @Entrypoint
290 public Address sysDoubleToLongIP;
291 @Entrypoint
292 public Address sysDoubleRemainderIP;
293 public Address sysPrimitiveParseFloatIP;
294 public Address sysPrimitiveParseIntIP;
295 public Address sysParseMemorySizeIP;
296
297 // time
298 Address sysCurrentTimeMillisIP;
299 Address sysNanoTimeIP;
300 Address sysNanoSleepIP;
301
302 // shared libraries
303 Address sysDlopenIP;
304 Address sysDlsymIP;
305
306 // system startup pthread sync. primitives
307 public Address sysCreateThreadSpecificDataKeysIP;
308
309 // VMMath
310 public Address sysVMMathSinIP;
311 public Address sysVMMathCosIP;
312 public Address sysVMMathTanIP;
313 public Address sysVMMathAsinIP;
314 public Address sysVMMathAcosIP;
315 public Address sysVMMathAtanIP;
316 public Address sysVMMathAtan2IP;
317 public Address sysVMMathCoshIP;
318 public Address sysVMMathSinhIP;
319 public Address sysVMMathTanhIP;
320 public Address sysVMMathExpIP;
321 public Address sysVMMathLogIP;
322 public Address sysVMMathSqrtIP;
323 public Address sysVMMathPowIP;
324 public Address sysVMMathIEEEremainderIP;
325 public Address sysVMMathCeilIP;
326 public Address sysVMMathFloorIP;
327 public Address sysVMMathRintIP;
328 public Address sysVMMathCbrtIP;
329 public Address sysVMMathExpm1IP;
330 public Address sysVMMathHypotIP;
331 public Address sysVMMathLog10IP;
332 public Address sysVMMathLog1pIP;
333
334 // system calls for alignment checking
335 public Address sysEnableAlignmentCheckingIP;
336 public Address sysDisableAlignmentCheckingIP;
337 public Address sysReportAlignmentCheckingIP;
338
339 /* FIXME: We *really* don't want all these syscalls here unconditionally --- need to push them out somehow */
340 // GCspy entry points
341 public Address gcspyDriverAddStreamIP;
342 public Address gcspyDriverEndOutputIP;
343 public Address gcspyDriverInitIP;
344 public Address gcspyDriverInitOutputIP;
345 public Address gcspyDriverResizeIP;
346 public Address gcspyDriverSetTileNameRangeIP;
347 public Address gcspyDriverSetTileNameIP;
348 public Address gcspyDriverSpaceInfoIP;
349 public Address gcspyDriverStartCommIP;
350 public Address gcspyDriverStreamIP;
351 public Address gcspyDriverStreamByteValueIP;
352 public Address gcspyDriverStreamShortValueIP;
353 public Address gcspyDriverStreamIntValueIP;
354 public Address gcspyDriverSummaryIP;
355 public Address gcspyDriverSummaryValueIP;
356
357 public Address gcspyIntWriteControlIP;
358
359 public Address gcspyMainServerAddDriverIP;
360 public Address gcspyMainServerAddEventIP;
361 public Address gcspyMainServerInitIP;
362 public Address gcspyMainServerIsConnectedIP;
363 public Address gcspyMainServerOuterLoopIP;
364 public Address gcspyMainServerSafepointIP;
365 public Address gcspyMainServerSetGeneralInfoIP;
366 public Address gcspyMainServerStartCompensationTimerIP;
367 public Address gcspyMainServerStopCompensationTimerIP;
368
369 public Address gcspyStartserverIP;
370
371 public Address gcspyStreamInitIP;
372
373 public Address gcspyFormatSizeIP;
374 public Address gcspySprintfIP;
375
376 // perf event support
377 public Address sysPerfEventInitIP;
378 public Address sysPerfEventCreateIP;
379 public Address sysPerfEventEnableIP;
380 public Address sysPerfEventDisableIP;
381 public Address sysPerfEventReadIP;
382
383 }