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 sysZeroNTIP;
233      public Address sysZeroIP;
234      public Address sysZeroPagesIP;
235      public Address sysSyncCacheIP;
236    
237      // files
238      public Address sysStatIP;
239      public Address sysReadByteIP;
240      public Address sysWriteByteIP;
241      public Address sysReadBytesIP;
242      public Address sysWriteBytesIP;
243      public Address sysBytesAvailableIP;
244      public Address sysSyncFileIP;
245      public Address sysSetFdCloseOnExecIP;
246    
247      public Address sysAccessIP;
248    
249      // mmap - memory mapping
250      public Address sysMMapIP;
251      public Address sysMMapErrnoIP;
252      public Address sysMProtectIP;
253      public Address sysGetPageSizeIP;
254    
255      // threads
256      public Address sysNumProcessorsIP;
257      public Address sysThreadBindSupportedIP;
258      public Address sysThreadBindIP;
259      public Address sysThreadCreateIP;
260      public Address sysThreadYieldIP;
261      public Address sysGetThreadIdIP;
262      public Address sysSetupHardwareTrapHandlerIP;
263      public Address sysStashVMThreadIP;
264      public Address sysThreadTerminateIP;
265    
266      // monitors
267      public Address sysMonitorCreateIP;
268      public Address sysMonitorDestroyIP;
269      public Address sysMonitorEnterIP;
270      public Address sysMonitorExitIP;
271      public Address sysMonitorTimedWaitAbsoluteIP;
272      public Address sysMonitorWaitIP;
273      public Address sysMonitorBroadcastIP;
274    
275      // arithmetic
276      @Entrypoint
277      public Address sysLongDivideIP;
278      @Entrypoint
279      public Address sysLongRemainderIP;
280      @Entrypoint
281      public Address sysLongToFloatIP;
282      @Entrypoint
283      public Address sysLongToDoubleIP;
284      @Entrypoint
285      public Address sysFloatToIntIP;
286      @Entrypoint
287      public Address sysDoubleToIntIP;
288      @Entrypoint
289      public Address sysFloatToLongIP;
290      @Entrypoint
291      public Address sysDoubleToLongIP;
292      @Entrypoint
293      public Address sysDoubleRemainderIP;
294      public Address sysPrimitiveParseFloatIP;
295      public Address sysPrimitiveParseIntIP;
296      public Address sysParseMemorySizeIP;
297    
298      // time
299      Address sysCurrentTimeMillisIP;
300      Address sysNanoTimeIP;
301      Address sysNanoSleepIP;
302    
303      // shared libraries
304      Address sysDlopenIP;
305      Address sysDlsymIP;
306    
307      // system startup pthread sync. primitives
308      public Address sysCreateThreadSpecificDataKeysIP;
309    
310      // VMMath
311      public Address sysVMMathSinIP;
312      public Address sysVMMathCosIP;
313      public Address sysVMMathTanIP;
314      public Address sysVMMathAsinIP;
315      public Address sysVMMathAcosIP;
316      public Address sysVMMathAtanIP;
317      public Address sysVMMathAtan2IP;
318      public Address sysVMMathCoshIP;
319      public Address sysVMMathSinhIP;
320      public Address sysVMMathTanhIP;
321      public Address sysVMMathExpIP;
322      public Address sysVMMathLogIP;
323      public Address sysVMMathSqrtIP;
324      public Address sysVMMathPowIP;
325      public Address sysVMMathIEEEremainderIP;
326      public Address sysVMMathCeilIP;
327      public Address sysVMMathFloorIP;
328      public Address sysVMMathRintIP;
329      public Address sysVMMathCbrtIP;
330      public Address sysVMMathExpm1IP;
331      public Address sysVMMathHypotIP;
332      public Address sysVMMathLog10IP;
333      public Address sysVMMathLog1pIP;
334    
335      // system calls for alignment checking
336      public Address sysEnableAlignmentCheckingIP;
337      public Address sysDisableAlignmentCheckingIP;
338      public Address sysReportAlignmentCheckingIP;
339    
340      /* FIXME: We *really* don't want all these syscalls here unconditionally --- need to push them out somehow */
341      // GCspy entry points
342      public Address gcspyDriverAddStreamIP;
343      public Address gcspyDriverEndOutputIP;
344      public Address gcspyDriverInitIP;
345      public Address gcspyDriverInitOutputIP;
346      public Address gcspyDriverResizeIP;
347      public Address gcspyDriverSetTileNameRangeIP;
348      public Address gcspyDriverSetTileNameIP;
349      public Address gcspyDriverSpaceInfoIP;
350      public Address gcspyDriverStartCommIP;
351      public Address gcspyDriverStreamIP;
352      public Address gcspyDriverStreamByteValueIP;
353      public Address gcspyDriverStreamShortValueIP;
354      public Address gcspyDriverStreamIntValueIP;
355      public Address gcspyDriverSummaryIP;
356      public Address gcspyDriverSummaryValueIP;
357    
358      public Address gcspyIntWriteControlIP;
359    
360      public Address gcspyMainServerAddDriverIP;
361      public Address gcspyMainServerAddEventIP;
362      public Address gcspyMainServerInitIP;
363      public Address gcspyMainServerIsConnectedIP;
364      public Address gcspyMainServerOuterLoopIP;
365      public Address gcspyMainServerSafepointIP;
366      public Address gcspyMainServerSetGeneralInfoIP;
367      public Address gcspyMainServerStartCompensationTimerIP;
368      public Address gcspyMainServerStopCompensationTimerIP;
369    
370      public Address gcspyStartserverIP;
371    
372      public Address gcspyStreamInitIP;
373    
374      public Address gcspyFormatSizeIP;
375      public Address gcspySprintfIP;
376    
377      // perf event support
378      public Address sysPerfEventInitIP;
379      public Address sysPerfEventCreateIP;
380      public Address sysPerfEventEnableIP;
381      public Address sysPerfEventDisableIP;
382      public Address sysPerfEventReadIP;
383    
384    }