[
https://issues.apache.org/jira/browse/DRILL-5116?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15790211#comment-15790211
]
Paul Rogers commented on DRILL-5116:
------------------------------------
A final issue also concerns nested classes illustrated by the
{{ExampleTemplateWithInner}} test case. The nested classes are non-static
"inner classes" that have access to the fields in the outer class via the
hidden "this$0" field.
{code}
public abstract class ExampleTemplateWithInner implements ExampleInner{
public class TheInnerClass {
...
{code}
Previously, when Drill generated the nested classes, it did so as static classes
{code}
public abstract class ExampleTemplateWithInnerGen0 implements ExampleInner{
public static class TheInnerClass {
...
{code}
To make plain Java work, the code generator must generated the inner class as
non-static (if the template class is also non-static):
{code}
public abstract class ExampleTemplateWithInnerGen0 extends
ExampleTemplateWithInner {
public class TheInnerClass {
...
{code}
The above works fine for plain Java. But, it causes issues for the byte code
merge. The decompiled, merged byte code files has two copies of {{this$0}}:
{code}
public class
org.apache.drill.exec.test.generated.ExampleInnerGen0$TheInnerClass {
final org.apache.drill.exec.test.generated.ExampleInnerGen0 this$0;
final org.apache.drill.exec.test.generated.ExampleInnerGen0 this$0;
{code}
The class fails on load into the JVM. The reason for the duplicate is that the
byte code merge assumes that the generated class is static: an empty shell into
which the merge can copy all fields (including hidden fields) from the template
class.
There are two solutions. One is to generate the inner class as static for
byte-code merge and non-static for plain-old Java. Because of code structure,
doing so requires that we make the plain-old Java decision at the point we
create the {{CodeGenerator}}, with is awkward.
The other solution is to modify the byte-code merge to assume that the
generated class is non-static. In merging fields in an inner class, omit those
with the name "this$x", where x is a number. This second solution is the one
adopted.
> Enable generated code debugging in each Drill operator
> ------------------------------------------------------
>
> Key: DRILL-5116
> URL: https://issues.apache.org/jira/browse/DRILL-5116
> Project: Apache Drill
> Issue Type: Improvement
> Affects Versions: 1.9.0
> Reporter: Paul Rogers
> Assignee: Paul Rogers
> Priority: Minor
>
> DRILL-5052 adds the ability to debug generated code. Some of the code
> generated by Drill's operators has minor problems when compiled directly
> using the new technique. These issues are ignore by the byte-code-merge
> technique uses in production. This ticket asks to try the DRILL-5052 feature
> in each operator, clean up any minor problems, and ensure each operator
> generates code suitable for debugging. Use the new
> {{CodeGenerator.plainOldJavaCapable()}} method to mark each generated class
> as ready for "plain-old Java" code gen.
> The advantages of this feature are two:
> 1. Ability to step through the generated code to increase understanding of
> existing operators and to ease development of improvements to existing
> operators and of any new operators we choose to create.
> 2. Open the door to experimenting with how to improve performance of the
> generated code.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)