2025-12-02 06:54:32 +01:00
|
|
|
#ifndef RAVA_METHODCACHE_H
|
|
|
|
|
#define RAVA_METHODCACHE_H
|
|
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include "../ir/ir.h"
|
|
|
|
|
|
|
|
|
|
#define RAVA_METHOD_CACHE_SIZE 256
|
|
|
|
|
#define RAVA_METHOD_CACHE_MASK (RAVA_METHOD_CACHE_SIZE - 1)
|
2025-12-03 15:01:02 +01:00
|
|
|
#define RAVA_METHOD_CACHE_WAYS 2
|
2025-12-02 06:54:32 +01:00
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
uint32_t class_hash;
|
|
|
|
|
uint32_t method_hash;
|
|
|
|
|
RavaMethod_t* method;
|
2025-12-03 15:01:02 +01:00
|
|
|
} MethodCacheSlot_t;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
MethodCacheSlot_t slots[RAVA_METHOD_CACHE_WAYS];
|
|
|
|
|
uint8_t lru;
|
2025-12-02 06:54:32 +01:00
|
|
|
} MethodCacheEntry_t;
|
|
|
|
|
|
|
|
|
|
typedef struct MethodCache_s {
|
|
|
|
|
MethodCacheEntry_t entries[RAVA_METHOD_CACHE_SIZE];
|
|
|
|
|
} MethodCache_t;
|
|
|
|
|
|
|
|
|
|
static inline uint32_t rava_methodcache_hash(const char* str) {
|
|
|
|
|
uint32_t hash = 5381;
|
|
|
|
|
while (*str) {
|
|
|
|
|
hash = ((hash << 5) + hash) ^ (uint32_t)*str;
|
|
|
|
|
str++;
|
|
|
|
|
}
|
|
|
|
|
return hash;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MethodCache_t* rava_methodcache_create(void);
|
|
|
|
|
void rava_methodcache_destroy(MethodCache_t* cache);
|
|
|
|
|
RavaMethod_t* rava_methodcache_lookup(MethodCache_t* cache,
|
|
|
|
|
const char* classname,
|
|
|
|
|
const char* methodname);
|
|
|
|
|
void rava_methodcache_insert(MethodCache_t* cache,
|
|
|
|
|
const char* classname,
|
|
|
|
|
const char* methodname,
|
|
|
|
|
RavaMethod_t* method);
|
|
|
|
|
void rava_methodcache_clear(MethodCache_t* cache);
|
|
|
|
|
|
|
|
|
|
#endif
|