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/04/28 18:03:00 UTC
[jira] [Comment Edited] (GROOVY-7700) Attribute access on same
statically compiled class should bypass ScriptBytecodeAdapter
[ https://issues.apache.org/jira/browse/GROOVY-7700?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17334912#comment-17334912 ]
Eric Milles edited comment on GROOVY-7700 at 4/28/21, 6:02 PM:
---------------------------------------------------------------
{code:groovy}
@groovy.transform.CompileStatic
class C {
private String f
void m(C that) {
def one = this.@f
def two = that.@f
}
}
{code}
{code}
public void m(C that);
0 aload_0 [this]
1 getfield C.f : java.lang.String [33]
4 astore_2 [one]
5 aload_2 [one]
6 pop
7 aload_1 [that]
8 getfield C.f : java.lang.String [33]
11 astore_3 [two]
12 aload_3 [two]
13 pop
14 return
{code}
was (Author: emilles):
{code:groovy}
@groovy.transform.CompileStatic
class C {
private String f
void m(C that) {
def one = this.@f
def two = that.@f
}
}
{code}
{code}
public void m(bugs.Pogo7700 that);
0 aload_0 [this]
1 getfield C.f : java.lang.String [33]
4 astore_2 [one]
5 aload_2 [one]
6 pop
7 aload_1 [that]
8 getfield C.f : java.lang.String [33]
11 astore_3 [two]
12 aload_3 [two]
13 pop
14 return
{code}
> Attribute access on same statically compiled class should bypass ScriptBytecodeAdapter
> --------------------------------------------------------------------------------------
>
> Key: GROOVY-7700
> URL: https://issues.apache.org/jira/browse/GROOVY-7700
> Project: Groovy
> Issue Type: Improvement
> Components: Compiler, Static compilation
> Affects Versions: 2.4.5
> Reporter: Christopher Smith
> Assignee: Eric Milles
> Priority: Minor
>
> In Java, it's not unusual to directly access fields of another instance of the same class, for example in {{equals}}. In writing an AST transformation, I found that an attribute expression accessing a (private) field on the same class is written out as a convoluted call through {{ScriptBytecodeAdapter}}, which sends it through a roundabout trip through the metaclass:
> {code}
> Object localObject = null;ScriptBytecodeAdapter.setGroovyObjectField((SimpleEntity)ScriptBytecodeAdapter.castToType(localObject, SimpleEntity.class), OtherEntity.class, other, (String)"bar");
> {code}
> When the {{objectExpression}} of an attribute expression is on the same class as {{this}}, the compiler should use the trivial field access instruction, at least in static compilation mode.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)