#ifndef RAVA_METHODCACHE_H #define RAVA_METHODCACHE_H #include #include #include "../ir/ir.h" #define RAVA_METHOD_CACHE_SIZE 256 #define RAVA_METHOD_CACHE_MASK (RAVA_METHOD_CACHE_SIZE - 1) #define RAVA_METHOD_CACHE_WAYS 2 typedef struct { uint32_t class_hash; uint32_t method_hash; RavaMethod_t* method; } MethodCacheSlot_t; typedef struct { MethodCacheSlot_t slots[RAVA_METHOD_CACHE_WAYS]; uint8_t lru; } 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