Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrong local variable table for methods containing while loops #9179

Closed
scabug opened this issue Feb 24, 2015 · 6 comments
Closed

wrong local variable table for methods containing while loops #9179

scabug opened this issue Feb 24, 2015 · 6 comments
Assignees
Labels
Milestone

Comments

@scabug
Copy link

scabug commented Feb 24, 2015

Local variables defined outside of a while loop sometimes are not visible from the body of this loop in the debugger.

{code}object Example {
def main(args: Array[String]) {
var x = ""
while (x != null) {
foo()
x = null
}
bar()
}

def foo() {}
def bar() {}
}
{code}

Bytecode instructions of the method main:

{code} 0 ldc #16
2 astore_2
3 aload_2
4 ifnonnull 12 (+8)
7 aload_0
8 invokevirtual #19 <Example$.bar>
11 return
12 aload_0
13 invokevirtual #22 <Example$.foo>
16 aconst_null
17 astore_2
18 goto 3 (-15)
{code}

Local variable x has attributes start_pc = 3, length = 8 in the local variable table. So it is not visible for a debugger inside the while statement body, when instructions 12 - 18 are executed.

It seems that this problem occurs when while statement condition has the form A != B, where A and B are reference type expressions.

@scabug
Copy link
Author

scabug commented Feb 24, 2015

Imported From: https://issues.scala-lang.org/browse/SI-9179?orig=1
Reporter: Nikolay Tropin (niktrop)
Affected Versions: 2.11.5

@scabug
Copy link
Author

scabug commented Mar 12, 2015

@retronym said:
This seems to be fixed under the experimental backend, GenBCode.

That backend will become the default in 2.12. We aren't making non-critical bug fixes to GenASM anymore, so I'm going to mark this as fixed for 2.12.

I'd appreciate if you could verify this under scala 2.11 compiling with -Ybackend:GenCode, and take a broader look at the debugger experience to check for any regressions in bytecode positions.

 % scalac -Ybackend:GenBCode -Ydebug -Xprint:typer sandbox/test.scala && echo ':javap -v -c Example$' | scala
...
  public void main(java.lang.String[]);
    descriptor: ([Ljava/lang/String;)V
    flags: ACC_PUBLIC
    Code:
      stack=1, locals=3, args_size=2
         0: ldc           #16                 // String
         2: astore_2
         3: aload_2
         4: ifnull        21
         7: goto          10
        10: aload_0
        11: invokevirtual #19                 // Method foo:()V
        14: aconst_null
        15: pop
        16: aconst_null
        17: astore_2
        18: goto          3
        21: aload_0
        22: invokevirtual #22                 // Method bar:()V
        25: return
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            2      23     2     x   Ljava/lang/String;
            0      26     0  this   LExample$;
            0      26     1  args   [Ljava/lang/String;

@scabug
Copy link
Author

scabug commented Mar 12, 2015

@lrytz said:
we should still add a test case

@scabug
Copy link
Author

scabug commented Mar 12, 2015

@retronym said:
Right you are.

@scabug
Copy link
Author

scabug commented Mar 13, 2015

Nikolay Tropin (niktrop) said:
It works on 2.11.4 with -Ybackend:GenBCode. I'll switch to this backend to test it further.

@scabug
Copy link
Author

scabug commented Apr 25, 2016

@lrytz said:
scala/scala#5122

@scabug scabug closed this as completed May 25, 2016
@scabug scabug added the bytecode label Apr 7, 2017
@scabug scabug added this to the 2.12.0-M5 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants