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

📄 jvm_runtime.c

📁 java 1.1 gemini 08_16
💻 C
📖 第 1 页 / 共 4 页
字号:
    /* We cannot accurately determine this value, so set it to 0 for now */
    calendar_time[MILLISECOND] = 0;
}


/*****************************************************************************
 * FUNCTION
 *  jvm_debug_print
 * DESCRIPTION
 *  debug print
 * PARAMETERS
 *  s       [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void jvm_debug_print(const char *s)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    /* Direct to device level directly. */
#ifdef __MTK_TARGET__
    char ch;
    kal_uint32 indx = 0, str_len = strlen(s);

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    while (indx < str_len)
    {
        ch = s[indx];
        indx++;

        if (ch == '\0' || ch == '\n' || ch == '\r' || (_jvm_log_index >= JVM_DEBUG_STRINGBUFFER_SIZE - 2))
        {
            if (_jvm_log_index >= JVM_DEBUG_STRINGBUFFER_SIZE - 2)
            {
                _jvm_log_buffer[_jvm_log_index++] = ch;
            }

            _jvm_log_buffer[_jvm_log_index++] = '\0';
            kal_print(_kvmLogStr);
            _jvm_log_index = 0;
        }
        else
        {
            _jvm_log_buffer[_jvm_log_index++] = ch;
        }
    }
    if (_jvm_log_index != 0 && str_len > 1)
    {   /* if the str_len is 1, we'll treat it as Kputchar from Java level */
        _jvm_log_buffer[_jvm_log_index++] = '\0';
        kal_print(_kvmLogStr);
        _jvm_log_index = 0;
    }
#else /* __MTK_TARGET__ */ 
    printf("%s", s);
#endif /* __MTK_TARGET__ */ 
}


/*****************************************************************************
 * FUNCTION
 *  jvm_task_sleep
 * DESCRIPTION
 *  debug print
 * PARAMETERS
 *  sleep_ticks     [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void jvm_task_sleep(kal_uint32 sleep_ticks)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    kal_sleep_task(sleep_ticks);
}


/*****************************************************************************
 * FUNCTION
 *  _floor_divide
 * DESCRIPTION
 *  Get the offset time form 1970/1/1 to now in day
 * PARAMETERS
 *  numerator       [IN]        
 *  denominator     [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
static long _floor_divide(long numerator, long denominator)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    /* We do this computation in order to handle a numerator of Long.MIN_VALUE correctly */
    return (numerator >= 0) ? numerator / denominator : ((numerator + 1) / denominator) - 1;
}


/*****************************************************************************
 * FUNCTION
 *  _julianday_to_ms
 * DESCRIPTION
 *  
 * PARAMETERS
 *  julian      [IN]        
 * RETURNS
 *  
 *****************************************************************************/
static kal_uint64 _julianday_to_ms(long julian)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    return ((kal_uint64) (julian - JAN_1_1970_GREGORIAN_DAY_TO_JULIAN_DAY)) * (kal_uint64) MILISPERDAT;
}


/*****************************************************************************
 * FUNCTION
 *  jvm_get_julian_day
 * DESCRIPTION
 *  
 * PARAMETERS
 *  year        [IN]        
 *  month       [IN]        
 *  day         [IN]        
 * RETURNS
 *  
 *****************************************************************************/
long jvm_get_julian_day(int year, int month, int day)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    int y;
    long julian_day;
    kal_bool leap_year = (year % 4 == 0);

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    y = year - 1;
    julian_day = 365L * y + _floor_divide(y, 4) + (GREGORIAN_DAY_TO_JULIAN_DAY - 3);

    leap_year = leap_year && ((year % 100 != 0) || (year % 400 == 0));
    /* Add 2 because Gregorian calendar starts 2 days after Julian calendar */
    julian_day += _floor_divide(y, 400) - _floor_divide(y, 100) + 2;
    julian_day += leap_year ? LEAP_NUM_DAYS[month] : NUM_DAYS[month];
    julian_day += day;

    return julian_day;
}

/* Return Julian time in ms from 1970 */


/*****************************************************************************
 * FUNCTION
 *  jvm_get_julian_time_ms
 * DESCRIPTION
 *  
 * PARAMETERS
 *  year        [IN]        
 *  month       [IN]        
 *  day         [IN]        
 *  hour        [IN]        
 *  minute      [IN]        
 *  second      [IN]        
 *  milli       [IN]        
 * RETURNS
 *  
 *****************************************************************************/
kal_uint64
jvm_get_julian_time_ms(
    unsigned short year,
    unsigned char month,
    unsigned char day,
    unsigned char hour,
    unsigned char minute,
    unsigned char second,
    int milli)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    long julian_day = jvm_get_julian_day(year, month, day);
    kal_uint64 millis = _julianday_to_ms(julian_day);

    long time_ms = 0;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    time_ms += hour;
    time_ms *= 60;
    time_ms += minute;
    time_ms *= 60;
    time_ms += second;
    time_ms *= 1000;
    time_ms += milli;
    return millis + (kal_uint64) time_ms;
}


/*****************************************************************************
 * FUNCTION
 *  jvm_str_dup
 * DESCRIPTION
 *  
 * PARAMETERS
 *  string      [?] 
 *  length      [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
kal_char *jvm_str_dup(kal_char *string, kal_int32 length)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_char *ptr;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (string == NULL)
    {
        return (kal_char*) NULL;
    }

    ptr = (kal_char*) get_ctrl_buffer(length + 1);
    if (ptr == NULL)
    {
        return NULL;
    }

    kal_mem_cpy(ptr, string, length);
    ptr[length] = 0;

    return ptr;
}


/*****************************************************************************
 * FUNCTION
 *  FBBR_heap_init
 * DESCRIPTION
 *  
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void FBBR_heap_init(void)
{
#if DATACACHE_FBBR_ON
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (!is_jvm_in_busy)
    {
        return;
    }

    if (!FBBR_initialized)
    {
        FBBR_initialized = KAL_TRUE;
        if (javaheap_size == 512 * 1024 || javaheap_size == 768 * 1024)
        {
            ASSERT((((int)javaheap_space) & (256 * 1024 - 1)) == 0);
        }
        else if (javaheap_size == 1024 * 1024 || javaheap_size == 1280 * 1024 || javaheap_size == 1152 * 1024)
        {
            /* MT6229 has more cache regiesters to be used by Java */
            ASSERT((((int)javaheap_space) & (512 * 1024 - 1)) == 0);
        }
        else if (javaheap_size == 1536 * 1024)
        {
            ASSERT((((int)javaheap_space) & (512 * 1024 - 1)) == 0);
        }
        else if (javaheap_size == 2 * 1024 * 1024 || javaheap_size == 3 * 1024 * 1024 ||
                 javaheap_size == 5 * 1024 * 1024)
        {
            ASSERT((((int)javaheap_space) & (1024 * 1024 - 1)) == 0);
        }
        else if (javaheap_size == 4 * 1024 * 1024 || javaheap_size == 6 * 1024 * 1024 ||
                 javaheap_size == 8 * 1024 * 1024)
        {
            ASSERT((((int)javaheap_space) & (2 * 1024 * 1024 - 1)) == 0);
        }
        else
        {
            ASSERT(0);
        }
        saveFBBRvalue = EnableFBBR();
        jvm_init_cache((unsigned char*)javaheap_space, (unsigned char*)javaheap_space + javaheap_size);
    }
#endif /* DATACACHE_FBBR_ON */ 
}


/*****************************************************************************
 * FUNCTION
 *  FBBR_heap_finalize
 * DESCRIPTION
 *  
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void FBBR_heap_finalize(void)
{
#if DATACACHE_FBBR_ON
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (FBBR_initialized)
    {
        FBBR_initialized = KAL_FALSE;
        jvm_release_cache();
        DisableFBBR(saveFBBRvalue);
    }
#endif /* DATACACHE_FBBR_ON */ 
}

#if DATACACHE_FBBR_ON
#pragma arm section code = "INTERNCODE"
#endif /* #if defined(MT6228) || defined(MT6229) || defined(MT6230) */


/*****************************************************************************
 * FUNCTION
 *  FBBR_invalid_l1_cache
 * DESCRIPTION
 *  
 * PARAMETERS
 *  dst         [?] 
 *  length      [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void *FBBR_invalid_l1_cache(void *dst, kal_int32 length)
{
#if DATACACHE_FBBR_ON
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 *startPtr = (U8*) dst;

    /* kal_int32 lineWidth = length; */
    U8 *invalidPtr;
    U8 *invalidPtrEnd;
    kal_int32 interruptMask;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (!FBBR_initialized || (int)dst < (int)javaheap_space || (int)dst > (int)((char*)javaheap_space + javaheap_size))
    {
        return dst;
    }

    invalidPtr = (U8*) ((kal_int32) startPtr & (~0x1f));
    length >>= 5;

    if (startPtr != invalidPtr)
    {
        length += 2;
    }
    else
    {
        length++;
    }

    /*    if (((((kal_uint32) (((lineWidth << 27) >> 27) + startPtr)) >> 5) << 5) != (kal_uint32) invalidPtr)

⌨️ 快捷键说明

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