⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 runtime_md.c

📁 This is a java virtual machine implement in c
💻 C
字号:
/*0001*//*
/*0002./ * Copyright (c) 1998-2001 Sun Microsystems, Inc. All Rights Reserved.
/*0003./ *
/*0004./ * This software is the confidential and proprietary information of Sun
/*0005./ * Microsystems, Inc. ("Confidential Information").  You shall not
/*0006./ * disclose such Confidential Information and shall use it only in
/*0007./ * accordance with the terms of the license agreement you entered into
/*0008./ * with Sun.
/*0009./ *
/*0010./ * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
/*0011./ * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
/*0012./ * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
/*0013./ * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
/*0014./ * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
/*0015./ * THIS SOFTWARE OR ITS DERIVATIVES.
/*0016./ *
/*0017./ */
/*0018*/
/*0019*//*=========================================================================
/*0020./ * KVM
/*0021./ *=========================================================================
/*0022./ * SYSTEM:    KVM
/*0023./ * SUBSYSTEM: Machine-specific implementations needed by virtual machine
/*0024./ * FILE:      runtime_md.c
/*0025./ * AUTHOR:    Frank Yellin
/*0026./ *=======================================================================*/
/*0027*/
/*0028*//*=========================================================================
/*0029./ * Include files
/*0030./ *=======================================================================*/
/*0031*/
/*0032*/#include <global.h>
/*0033*/#include <async.h>
/*0034*/
/*0035*/#include <stdlib.h>
/*0036*/#include <string.h>
/*0037*/#include <time.h>
/*0038*/
/*0039*//*=========================================================================
/*0040./ * FUNCTION:      alertUser()
/*0041./ * TYPE:          error handling operation
/*0042./ * OVERVIEW:      Show an alert dialog to the user and wait for
/*0043./ *                confirmation before continuing execution.
/*0044./ * INTERFACE:
/*0045./ *   parameters:  message string
/*0046./ *   returns:     <nothing>
/*0047./ *=======================================================================*/
/*0048*/
/*0049*/void AlertUser(const char* message)
/*0050*/{
/*0051*/    fprintf(stderr, "ALERT: %s\n", message);
/*0052*/}
/*0053*/
/*0054*//*=========================================================================
/*0055./ * FUNCTION:      allocateHeap()
/*0056./ * TYPE:          allocates memory
/*0057./ * OVERVIEW:      Show an alert dialog to the user and wait for
/*0058./ *                confirmation before continuing execution.
/*0059./ * INTERFACE:
/*0060./ *   parameters:  *sizeptr:  INPUT:   Pointer to size of heap to allocate
/*0061./ *                           OUTPUT:  Pointer to actually size of heap
/*0062./ *                *realresultptr: Returns pointer to actual pointer than
/*0063./ *                           was allocated, before any adjustments for
/*0064./ *                           memory alignment.  This is the value that
/*0065./ *                           must be passed to "free()"
/*0066./ *
/*0067./ *  returns:      pointer to aligned memory.
/*0068./ *
/*0069./ *  Note that "sizeptr" reflects the size of the "aligned" memory, and
/*0070./ *  note the actual size of the memory that has been allocated.
/*0071./ *=======================================================================*/
/*0072*/
/*0073*/cell *allocateHeap(long *sizeptr, void **realresultptr) {
/*0074*/        void *space = malloc(*sizeptr + sizeof(cell) - 1);
/*0075*/        *realresultptr = space;
/*0076*/        return (void *) ((((long)space) + (sizeof(cell) - 1)) & ~(sizeof(cell) - 1));
/*0077*/}
/*0078*/
/*0079*//* Virtual memory allocation and protection operations. */
/*0080*//* Used for testing the correctness of the garbage collector */
/*0081*/
/*0082*/int getpagesize() {
/*0083*/    SYSTEM_INFO sysInfo;
/*0084*/    GetSystemInfo(&sysInfo);
/*0085*/    return sysInfo.dwPageSize;
/*0086*/}
/*0087*/
/*0088*/void*
/*0089*/allocateVirtualMemory_md(long size) {
/*0090*/    return VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE);
/*0091*/}
/*0092*/
/*0093*/void
/*0094*/freeVirtualMemory_md(void *address, long size) {
/*0095*/    VirtualFree(address, size, MEM_RELEASE);
/*0096*/}
/*0097*/
/*0098*/void
/*0099*/protectVirtualMemory_md(void *address, long size, int protection)
/*0100*/{
/*0101*/    long o;                     /* old protection value */
/*0102*/    int flag;
/*0103*/    switch (protection) {
/*0104*/        case PVM_NoAccess:  flag = PAGE_NOACCESS; break;
/*0105*/        case PVM_ReadOnly:  flag = PAGE_READONLY; break;
/*0106*/        case PVM_ReadWrite: flag = PAGE_READWRITE; break;
/*0107*/        default:            fatalError("Bad argument");
/*0108*/    }
/*0109*/    VirtualProtect(address, size, flag, &o);
/*0110*/}
/*0111*/
/*0112*//*=========================================================================
/*0113./ * FUNCTION:      CurrentTime_md
/*0114./ * TYPE:          Public link routine
/*0115./ * OVERVIEW:      Get the system time in ms since 1970
/*0116./ * INTERFACE:
/*0117./ *   parameters:  none
/*0118./ *   returns:     time
/*0119./ *=======================================================================*/
/*0120*/
/*0121*/ulong64
/*0122*/CurrentTime_md(void) {
/*0123*/    return sysTimeMillis();
/*0124*/}
/*0125*/
/*0126*//*=========================================================================
/*0127./ * FUNCTION:      InitializeNativeCode
/*0128./ * TYPE:          initialization
/*0129./ * OVERVIEW:      Called at start up to perform machine-specific
/*0130./ *                initialization.
/*0131./ * INTERFACE:
/*0132./ *   parameters:  none
/*0133./ *   returns:     none
/*0134./ *=======================================================================*/
/*0135*/
/*0136*/void InitializeNativeCode() {
/*0137*/    extern void runtime2_md_init(void);
/*0138*/    runtime2_md_init();
/*0139*/}
/*0140*/
/*0141*//*=========================================================================
/*0142./ * FUNCTION:      nativeFinalization
/*0143./ * TYPE:          initialization
/*0144./ * OVERVIEW:      Called at start up to perform machine-specific
/*0145./ *                finalization.
/*0146./ * INTERFACE:
/*0147./ *   parameters:  none
/*0148./ *   returns:     none
/*0149./ *=======================================================================*/
/*0150*/
/*0151*/void FinalizeNativeCode() {
/*0152*/}
/*0153*/
/*0154*//*=========================================================================
/*0155./ * Asynchronous (non-blocking) I/O Routines
/*0156./ *=======================================================================*/
/*0157*/
/*0158*/#if ASYNCHRONOUS_NATIVE_FUNCTIONS
/*0159*/
/*0160*//*
/*0161./ * Parameters to processAcyncThread
/*0162./ */
/*0163*/static ASYNCIOCB *nextIocb;
/*0164*/static void (*nextRoutine)(ASYNCIOCB *);
/*0165*/
/*0166*//*
/*0167./ * Routine called from runtime2_md.c when a thread is unblocked
/*0168./ */
/*0169*/void processAcyncThread(void) {
/*0170*/
/*0171*/    /*
/*0172./     * Pick up parameters
/*0173./     */
/*0174*/    ASYNCIOCB *iocb          = nextIocb;
/*0175*/    void (*rtn)(ASYNCIOCB *) = nextRoutine;
/*0176*/
/*0177*/    /*
/*0178./     * Clear input queue
/*0179./     */
/*0180*/    nextRoutine = 0;
/*0181*/    nextIocb    = 0;
/*0182*/
/*0183*/    /*
/*0184./     * Sanity check
/*0185./     */
/*0186*/    if (iocb == 0 || rtn == 0) {
/*0187*/        fatalError("processAcyncThread problem");
/*0188*/    }
/*0189*/
/*0190*/    /*
/*0191./     * Execute async function
/*0192./     */
/*0193*/    (rtn)(iocb);
/*0194*/}
/*0195*/
/*0196*//*=========================================================================
/*0197./ * FUNCTION:      CallAsyncNativeFunction_md()
/*0198./ * TYPE:          Public link routine for asynchronous native methods
/*0199./ * OVERVIEW:      Call an asynchronous native method
/*0200./ * INTERFACE:
/*0201./ *   parameters:  thread pointer, native function pointer
/*0202./ *   returns:     <nothing>
/*0203./ *
/*0204./ * Note: This is just an example implementation for demonstration purposes.
/*0205./ *       and does not actually work very well because eventually the WIN32
/*0206./ *       program seems to run out of thread resources and no new threads
/*0207./ *       seem to run. Typically no error code is ever returned!
/*0208./ *=======================================================================*/
/*0209*/
/*0210*/void CallAsyncNativeFunction_md(ASYNCIOCB *iocb, void (*afp)(ASYNCIOCB *)) {
/*0211*/
/*0212*/    /*
/*0213./     * Sanity check
/*0214./     */
/*0215*/    if (nextRoutine != 0 || nextIocb != 0 || iocb == 0 || afp == 0) {
/*0216*/        fatalError("CallAsyncNativeFunction_md problem");
/*0217*/    }
/*0218*/
/*0219*/    /*
/*0220./     * Save the thread parameters
/*0221./     */
/*0222*/    nextRoutine = afp;
/*0223*/    nextIocb    = iocb;
/*0224*/
/*0225*/    /*
/*0226./     * Release a thread. This function will cause
/*0227./     * processAcyncThread to be called
/*0228./     */
/*0229*/    releaseAsyncThread();
/*0230*/
/*0231*/    /*
/*0232./     * Wait until it is running and has taken the queued request
/*0233./     */
/*0234*/    while(nextIocb != 0) {
/*0235*/        Yield_md();
/*0236*/    }
/*0237*/}
/*0238*/
/*0239*/#endif /* ASYNCHRONOUS_NATIVE_FUNCTIONS */
/*0240*/
/*0241*/#ifdef NOGUI
/*0242*/
/*0243*//*=========================================================================
/*0244./ * FUNCTION:      The stub of GetAndStoreNextKVMEvent
/*0245./ * TYPE:          event handler
/*0246./ * OVERVIEW:      Wait for an external event.  Read the KVM
/*0247./ *                Porting Guide for details on parameters, etc.
/*0248./ *  returns:      void
/*0249./ *=======================================================================*/
/*0250*/
/*0251*/void GetAndStoreNextKVMEvent(bool_t forever, ulong64 waitUntil) {}
/*0252*/
/*0253*/#endif /* NOGUI */
/*0254*/
/*0255*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -