{"action":"created","issue":{"url":"https://api.github.com/repos/sebthom/oval/issues/20","repository_url":"https://api.github.com/repos/sebthom/oval","labels_url":"https://api.github.com/repos/sebthom/oval/issues/20/labels{/name}","comments_url":"https://api.github.com/repos/sebthom/oval/issues/20/comments","events_url":"https://api.github.com/repos/sebthom/oval/issues/20/events","html_url":"https://github.com/sebthom/oval/issues/20","id":357982553,"node_id":"MDU6SXNzdWUzNTc5ODI1NTM=","number":20,"title":"High contention on ContextCache","user":{"login":"Cyrill","id":56274,"node_id":"MDQ6VXNlcjU2Mjc0","avatar_url":"https://avatars3.githubusercontent.com/u/56274?v=4","gravatar_id":"","url":"https://api.github.com/users/Cyrill","html_url":"https://github.com/Cyrill","followers_url":"https://api.github.com/users/Cyrill/followers","following_url":"https://api.github.com/users/Cyrill/following{/other_user}","gists_url":"https://api.github.com/users/Cyrill/gists{/gist_id}","starred_url":"https://api.github.com/users/Cyrill/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Cyrill/subscriptions","organizations_url":"https://api.github.com/users/Cyrill/orgs","repos_url":"https://api.github.com/users/Cyrill/repos","events_url":"https://api.github.com/users/Cyrill/events{/privacy}","received_events_url":"https://api.github.com/users/Cyrill/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-09-07T09:06:25Z","updated_at":"2018-09-07T11:41:36Z","closed_at":null,"author_association":"NONE","body":"Validators are extensively used in my project and recently I've found that almost all my worker threads are blocked waiting for lock inside `ContextCache.getFieldContext`.\r\n\r\nI started wondering what had caused that and here is what I have:\r\n`ContextCache.getFieldContext` uses WeakHashMap inside to cache FieldContext objects, however, according to [https://docs.oracle.com/javase/7/docs/api/java/util/WeakHashMap.html](https://docs.oracle.com/javase/7/docs/api/java/util/WeakHashMap.html)\r\n>The value objects in a WeakHashMap are held by ordinary strong references. Thus care should >be taken to ensure that value objects do not strongly refer to their own keys, either directly or >indirectly, since that will prevent the keys from being discarded.\r\n\r\n'FieldContext` has a strong reference to its key\r\n```\r\npublic static FieldContext getFieldContext(final Field field) {\r\n      synchronized (FIELD_CONTEXTS) {\r\n         FieldContext ctx = FIELD_CONTEXTS.get(field);\r\n         if (ctx == null) {\r\n            ctx = new FieldContext(field);\r\n            FIELD_CONTEXTS.put(field, ctx);\r\n         }\r\n         return ctx;\r\n      }\r\n}\r\n```\r\nMoreover, `FieldContext` calls `SerializableField.getInstance`, which in turn has the same pattern for caching. The same applies to some other `ContextCache` static methods.\r\n\r\nSo since we don't truly have any gain from using WeakHashMap here, would it be possible to replace these caches with something more performant in a concurrent environment, for example `ConcurrentHashMap`?"},"comment":{"url":"https://api.github.com/repos/sebthom/oval/issues/comments/419413843","html_url":"https://github.com/sebthom/oval/issues/20#issuecomment-419413843","issue_url":"https://api.github.com/repos/sebthom/oval/issues/20","id":419413843,"node_id":"MDEyOklzc3VlQ29tbWVudDQxOTQxMzg0Mw==","user":{"login":"sebthom","id":426959,"node_id":"MDQ6VXNlcjQyNjk1OQ==","avatar_url":"https://avatars1.githubusercontent.com/u/426959?v=4","gravatar_id":"","url":"https://api.github.com/users/sebthom","html_url":"https://github.com/sebthom","followers_url":"https://api.github.com/users/sebthom/followers","following_url":"https://api.github.com/users/sebthom/following{/other_user}","gists_url":"https://api.github.com/users/sebthom/gists{/gist_id}","starred_url":"https://api.github.com/users/sebthom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sebthom/subscriptions","organizations_url":"https://api.github.com/users/sebthom/orgs","repos_url":"https://api.github.com/users/sebthom/repos","events_url":"https://api.github.com/users/sebthom/events{/privacy}","received_events_url":"https://api.github.com/users/sebthom/received_events","type":"User","site_admin":false},"created_at":"2018-09-07T11:41:36Z","updated_at":"2018-09-07T11:41:36Z","author_association":"OWNER","body":"The reason why WeakHashMap is used is to allow classes to be unloaded/reloaded. E.g. in a JEE Server where you partially redeploy an EAR (replacing just a module, like an EJB/WAR). Otherwise classes may never be GCed. Maybe we can make the cache implementation to be used configurable."}}
{"actor":{"display_login":"sebthom"}}