AFAIR,  deadlock is due to that StampedLock is not re-entrant.

We can use ReentrantReadWriteLock to avoid deadlock.

Cheers,
Daniel Sun

On 2025/01/24 04:48:48 Paul King wrote:
> Hi folks, I am wondering whether the type for sourceCache in
> GroovyClassLoader should be hard-coded as the concrete type
> StampedCommonCache<String, Class> but instead be the interface
> EvictableCache<String, Class>?
> 
> https://github.com/apache/groovy/blob/master/src/main/java/groovy/lang/GroovyClassLoader.java#L102
> 
> This would let folks creating a custom class loader change to one of
> the other caches, e.g. ConcurrentCommonCache if facing things like the
> deadlock mentioned in StampedCommonCache (see also GROOVY-9742). That
> is known to be slower but doesn't have the reentrancy issues.
> 
> There is one place where a method only in StampedCommonCache is called
> but using instanceof, we could fallback to only using the interface
> methods (with some reduced functionality).
> 
> This would break binary compatibility so I would only suggest it for Groovy 5.
> 
> In addition to the type change, what do folks think about the proposed
> workaround mentioned in GROOVY-9742, e.g. change
> GroovyClassLoader#doParseClass() from private to public or protected.
> This could potentially be done for an earlier version, e.g. Groovy 4.
> 
> Cheers, Paul.
> 

Reply via email to