You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2021/12/06 21:54:00 UTC

[jira] [Commented] (GROOVY-10278) CompilerConfiguration: improve target bytecode selection

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

Eric Milles commented on GROOVY-10278:
--------------------------------------

https://github.com/apache/groovy/pull/1661

> CompilerConfiguration: improve target bytecode selection
> --------------------------------------------------------
>
>                 Key: GROOVY-10278
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10278
>             Project: Groovy
>          Issue Type: Improvement
>            Reporter: Eric Milles
>            Assignee: Eric Milles
>            Priority: Minor
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> The current implementation of {{CompilerConfiguration#setTargetBytecode(String)}} is to use the default version (currently "1.8") if the specified version is not supported. This can be a problem in joint compilation situations. If {{javac}} supports JDK19 or whatever comes along and {{groovyc}} only supports up to JDK17, then a target setting will be JDK19 for Java and JDK8 for Groovy.
> In groovy-eclipse, I have been selecting the nearest version. So if the user asks for "19" and "17" is supported, they'll get that. And if the user asks for "1.3" (hypothetical) then they'll get "1.4".  And if the user still uses "9.0" or "11.0" notation, they'll get what they expect.
> {code:java}
>     public void setTargetBytecode(final String version) {
>         setTargetBytecodeIfValid(version);
>     }
>     private void setTargetBytecodeIfValid(final String version) {
>         /* GRECLIPSE edit
>         if (JDK_TO_BYTECODE_VERSION_MAP.containsKey(version)) {
>             this.targetBytecode = version;
>         }
>         */
>         int index;
>         try { ALLOWED_JDKS[5] = "1.9"; // 9 is out of order for binary search
>             index = Arrays.binarySearch(ALLOWED_JDKS, !version.startsWith("1") ? "1." + version : version);
>         } finally {
>             ALLOWED_JDKS[5] = "9";
>         }
>         if (index >= 0) {
>             targetBytecode = ALLOWED_JDKS[index];
>         } else {
>             index = Math.abs(index) - 2; // closest version
>             targetBytecode = ALLOWED_JDKS[Math.max(0, index)];
>         }
>         // GRECLIPSE end
>     }
> {code}
> Note: the current algorithm breaks down when "20" or greater is supplied.



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