summaryrefslogtreecommitdiffstats
path: root/vespajlib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-10-25 18:49:16 +0200
committerHenning Baldersheim <balder@yahoo-inc.com>2022-10-25 18:51:54 +0200
commit682edac3e385154e0ce22ce0a502d8ab7d9c6c6a (patch)
treeb160da2329c1c68e5dd5169a4de694210097e038 /vespajlib
parente899053702569af8205d49c7fa5391bfbe6481b5 (diff)
Add a hook for tracking inserts into the method cache and log whenever clone methods are added.
Diffstat (limited to 'vespajlib')
-rw-r--r--vespajlib/src/main/java/com/yahoo/collections/MethodCache.java7
1 files changed, 7 insertions, 0 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/collections/MethodCache.java b/vespajlib/src/main/java/com/yahoo/collections/MethodCache.java
index 4a4331b1c6e..bf9200efb2e 100644
--- a/vespajlib/src/main/java/com/yahoo/collections/MethodCache.java
+++ b/vespajlib/src/main/java/com/yahoo/collections/MethodCache.java
@@ -4,6 +4,7 @@ package com.yahoo.collections;
import com.yahoo.concurrent.CopyOnWriteHashMap;
import java.lang.reflect.Method;
+import java.util.function.Consumer;
/**
* This will cache methods solved by reflection as reflection is expensive.
@@ -28,11 +29,17 @@ public final class MethodCache {
public void clear() {
cache.clear();
}
+
public Method get(Object object) {
+ return get(object, null);
+ }
+ public Method get(Object object, Consumer<String> onPut) {
Method m = cache.get(object.getClass().getName());
if (m == null) {
m = lookupMethod(object);
if (m != null) {
+ if (onPut != null)
+ onPut.accept(object.getClass().getName());
cache.put(object.getClass().getName(), m);
}
}