[code-reflection] RFR: Adjusted tests to use execution of a method and implementation of the execution model cache [v2]

Maurizio Cimadamore mcimadamore at openjdk.org
Fri Feb 28 09:59:47 UTC 2025


On Fri, 28 Feb 2025 07:51:05 GMT, Adam Sotona <asotona at openjdk.org> wrote:

>> cr-examples/onnx/src/main/java/oracle/code/onnx/OnnxRuntime.java line 60:
>> 
>>> 58:     record CachedModel(byte[] protoModel, int[] operandsMapping) {}
>>> 59: 
>>> 60:     private static final WeakHashMap<Class<?>, CachedModel> MODEL_CACHE = WeakHashMap.newWeakHashMap(10);
>> 
>> Using `ClassValue` is another option.
>
> Unfortunately `ClassValue` does not support computation if absent (if more than just the bare class is needed). Maybe if compute returns null and the cached value is added later...?

I believe `ClassValue` is similar to a thread local in how it's used -- e.g. you create an instance of it and stick it in a static final (the javadoc of `ClassValue` is useless in that respect):


ClassValue<CachedModel> CACHED_MODEL = new ClassValue<>() {
    @Override
    CachedModel computeValue() { <logic here> }
};


That should work here.

-------------

PR Review Comment: https://git.openjdk.org/babylon/pull/331#discussion_r1975129271


More information about the babylon-dev mailing list