📄 jvm_cache.c
字号:
return;
}
}
low_end = (unsigned char*)(_DERIVED(kal_int32, start, cachealign_size - 1) & cachealign_mask);
high_start = _DERIVED(kal_uint8 *, low_end, cachealign_size);
channel = _jvm_config_codecache(low_end, cachealign_size);
if (channel == 0xFFFF)
{
return;
}
saved_inited_channels |= (1 << channel);
if (end == high_start && start == low_end)
{
return;
}
while (1)
{
find_region = KAL_FALSE;
/* find low address suitable region */
if (_DERIVED(kal_uint8 *, low_end, -cachealign_size) >= start)
{
low_end = _DERIVED(kal_uint8 *, low_end, -cachealign_size);
channel = _jvm_config_codecache(low_end, cachealign_size);
if (channel == 0xFFFF)
{
break;
}
saved_inited_channels |= (1 << channel);
find_region = KAL_TRUE;
}
/* find upper address suitable region */
if (_DERIVED(kal_uint8 *, high_start, cachealign_size) <= end)
{
channel = _jvm_config_codecache(high_start, cachealign_size);
if (channel == 0xFFFF)
{
break;
}
saved_inited_channels |= (1 << channel);
high_start = _DERIVED(kal_uint8 *, high_start, cachealign_size);
find_region = KAL_TRUE;
}
if (end == high_start && start == low_end)
{
break;
}
if (find_region == KAL_FALSE)
{
cachealign_size >>= 1;
if (cachealign_size < 1024)
{
break;
}
}
}
#endif /* defined(__MTK_TARGET__) && (defined(MT6228) || defined(MT6229) || defined(MT6230)) */
}
/*****************************************************************************
* FUNCTION
* jvm_release_cache
* DESCRIPTION
*
* PARAMETERS
* void
* RETURNS
* void
*****************************************************************************/
void jvm_release_cache(void)
{
#if defined(__MTK_TARGET__) && (defined(MT6228) || defined(MT6229) || defined(MT6230))
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_uint16 channel;
CacheMenuType cache_setting;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
low_end = high_start = NULL;
if (saved_inited_channels != 0)
{
for (channel = 0; channel < 8; channel++)
{
if ((saved_inited_channels & (1 << channel)) != 0)
{
CodeCacheFreeChannel(&channel);
/* disable L1 cache mapping */
cache_setting.c_channel = channel;
cache_setting.c_enable = 0;
cache_setting.c_addr = (kal_uint32) 0;
cache_setting.c_range = 2048;
CodeCacheSetting(&cache_setting);
}
}
saved_inited_channels = l1cache_channels = 0;
}
jvm_flush_cache((unsigned char*)0, 0);
#endif /* defined(__MTK_TARGET__) && (defined(MT6228) || defined(MT6229) || defined(MT6230)) */
}
/*****************************************************************************
* FUNCTION
* jvm_flush_cache
* DESCRIPTION
*
* PARAMETERS
* start [?]
* size [IN]
* RETURNS
* void
*****************************************************************************/
void jvm_flush_cache(unsigned char *start, int size)
{
#if defined(__MTK_TARGET__) && (defined(MT6228) || defined(MT6229) || defined(MT6230))
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/* kal_uint32 interrupt_mask; */
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
// It should be OK that not in critical section, and interrupt occur.
// The performance will be better.
/* do not have to turn off interrupt. */
/* interrupt_mask = SaveAndSetIRQMask(); */
/* Invalidate and clean data cache */
*L2C_CON = 0x80000070;
DataCacheWaitCommandReady();
/* RestoreIRQMask(interrupt_mask); */
/* Drain Write Buffer */
/* interrupt_mask = SaveAndSetIRQMask(); */
*L2C_CON = 0x80000002;
/* Wait for command finishing */
DataCacheWaitCommandReady();
// Invalide all L1 code cache
// !!! - As spec describe, L1 cache is write-through, and shouldn't be invalided ideally.
// However, JIT need to modify some fields such as compiled method header (klass, size, link),
// and other unknown fields before calling flush write buffer here.
// Even you didn't read back modified value, cache line will be filled by closing data fields.
// For example, OopDesc::initalize()
// initialize(klass);
// _set_size(size);
// will be compiled as
// str r0,[r4]
// ldr r0,[r4+4] <- fetch whole cache line, and data not consistent if previous write not yet flushed.
//
// It's lucky that JIT wouldn't readback modified value before flushing here, or we only apply L2 cache or big
// job to add more invalidation action before read.
*CACHE_OP = 0x03;
/* RestoreIRQMask(interrupt_mask); */
#endif /* defined(__MTK_TARGET__) && (defined(MT6228) || defined(MT6229) || defined(MT6230)) */
(void)start;
(void)size;
}
/*****************************************************************************
* FUNCTION
* jvm_init_cache_for_hi
* DESCRIPTION
*
* PARAMETERS
* start [?]
* end [?]
* RETURNS
* void
*****************************************************************************/
void jvm_init_cache_for_hi(unsigned char *start, unsigned char *end)
{
#if !DATACACHE_FBBR_ON
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
jvm_init_cache(start, end);
#else /* !DATACACHE_FBBR_ON */
(void)start;
(void)end;
#endif /* !DATACACHE_FBBR_ON */
}
/*****************************************************************************
* FUNCTION
* jvm_release_cache_for_hi
* DESCRIPTION
*
* PARAMETERS
* void
* RETURNS
* void
*****************************************************************************/
void jvm_release_cache_for_hi(void)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
#if !DATACACHE_FBBR_ON
jvm_release_cache();
#endif /* !DATACACHE_FBBR_ON */
}
/*****************************************************************************
* FUNCTION
* jvm_flush_cache_for_hi
* DESCRIPTION
*
* PARAMETERS
* start [?]
* size [IN]
* RETURNS
* void
*****************************************************************************/
void jvm_flush_cache_for_hi(unsigned char *start, int size)
{
#if !DATACACHE_FBBR_ON
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
jvm_flush_cache(start, size);
#else /* !DATACACHE_FBBR_ON */
(void)start;
(void)size;
#endif /* !DATACACHE_FBBR_ON */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -