[ 
https://issues.apache.org/jira/browse/GROOVY-10440?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17470300#comment-17470300
 ] 

Robin commented on GROOVY-10440:
--------------------------------

After apply the patch, rerun the test script, we got the result:

 
{code:java}
class Script_281961721d66605f3d1f24d294f28232, hashCode=887981434
class Script_281961721d66605f3d1f24d294f28232, hashCode=887981434
true
true {code}
So it means the compiled class has been cache properly.

 

> GROOVY-9329 Not Really Cached the compiled class.
> -------------------------------------------------
>
>                 Key: GROOVY-10440
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10440
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 3.0.9
>            Reporter: Robin
>            Priority: Major
>              Labels: patch
>         Attachments: GroovyClassLoader_EnableCache.patch
>
>
> GROOVY-9329  the patch Not Really Cached the compiled class.
> If we run the next groovy script:
> {code:java}
> def gcl = new GroovyClassLoader()
> def scriptText = 'def x = 1'
> gcl.parseClass(scriptText)
> def begin = [email protected]()
> def clazz = [email protected]().iterator().next()
> println clazz.toString() + ", hashCode=" + clazz.hashCode()
> 3.times { gcl.parseClass(scriptText) }
> def end = [email protected]()
> def clazz_2 = [email protected]().iterator().next()
> println clazz_2.toString() + ", hashCode=" + clazz_2.hashCode()
> println(end == begin)
> println(clazz == clazz_2)
>  {code}
> The result is: 
> {code:java}
> class Script_281961721d66605f3d1f24d294f28232, hashCode=1976401987
> class Script_281961721d66605f3d1f24d294f28232, hashCode=1201004240
> true
> false {code}
> clazz != clazz_2,  it means that every time of calling 
> "parseClass(scriptText) ", script still be compiled again, then the new class 
> be put to classCache to replacing the old one.
> The fix is: Remove the "gcs.setCachable(false);" line of parseClass(text, 
> fileName) in GroovyClassLoader.java
> {code:java}
> public Class parseClass(final String text, final String fileName) throws 
> CompilationFailedException {
>     GroovyCodeSource gcs = 
> AccessController.doPrivileged((PrivilegedAction<GroovyCodeSource>) () -> new 
> GroovyCodeSource(text, fileName, "/groovy/script"));
>     gcs.setCachable(false);  <----- Remove the line
>     return parseClass(gcs);
> } {code}
>  
> The patch is in attachment: GroovyClassLoader_EnableCache.patch



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to