You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Daniel Sun (Jira)" <ji...@apache.org> on 2021/04/14 00:17:00 UTC

[jira] [Updated] (GROOVY-10035) CLONE - Compiler writes extra cast for Type[] to Object[]

     [ https://issues.apache.org/jira/browse/GROOVY-10035?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Daniel Sun updated GROOVY-10035:
--------------------------------
    Description: 
The ticket is to provide some suggestion to tweak the fix of GROOVY-10034 ( https://github.com/apache/groovy/pull/1556#discussion_r611833145 )

It seems that we could make the check simpler, we do not add extra checks but tweak the existing check:

[https://github.com/apache/groovy/blob/master/src/main/java/org/codehaus/groovy/classgen/asm/OperandStack.java#L334]

{code:java}
if (targetType == top) return;
{code}

tweaked as:

{code:java}
if (targetType.getTypeClass().isAssignableFrom(top.getTypeClass())) return;
{code}


  was:
Consider the following:
{code:groovy}
['x'].toArray(new String[0])
{code}

This produces a bytecode sequence that includes a cast from {{String[]}} to {{Object[]}}.  javac for the same code omits the cast.
{code}
     9  iconst_0
    10  multianewarray java.lang.String[] [44]
    14  invokedynamic 0 cast(java.lang.String[]) : java.lang.Object[] [58]
    19  invokeinterface java.util.Collection.toArray(java.lang.Object[]) : java.lang.Object[] [64] [nargs: 2]
{code}

Note: {{multianewarray}} vs {{anewarray}} was fixed by GROOVY-10031


> CLONE - Compiler writes extra cast for Type[] to Object[]
> ---------------------------------------------------------
>
>                 Key: GROOVY-10035
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10035
>             Project: Groovy
>          Issue Type: Improvement
>          Components: bytecode
>            Reporter: Eric Milles
>            Priority: Minor
>
> The ticket is to provide some suggestion to tweak the fix of GROOVY-10034 ( https://github.com/apache/groovy/pull/1556#discussion_r611833145 )
> It seems that we could make the check simpler, we do not add extra checks but tweak the existing check:
> [https://github.com/apache/groovy/blob/master/src/main/java/org/codehaus/groovy/classgen/asm/OperandStack.java#L334]
> {code:java}
> if (targetType == top) return;
> {code}
> tweaked as:
> {code:java}
> if (targetType.getTypeClass().isAssignableFrom(top.getTypeClass())) return;
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)