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

Using a null in a context that expect something other than null causes redundant bytecode #7015

Closed
scabug opened this issue Jan 23, 2013 · 4 comments
Milestone

Comments

@scabug
Copy link

scabug commented Jan 23, 2013

class X {
  def f(x: String) = x

  f(null)
}

Produces the icode

  def g(): String {
  locals: 
  startBlock: 1
  blocks: [1]
  
  1: 
    7	THIS(X)
    7	CONSTANT(null)
    ?	DROP REF(class Null)
    ?	CONSTANT(null)
    7	CALL_METHOD X.f (dynamic)
    7	RETURN(REF(class String))
    
  }{code}

Note the CONSTANT(null) DROP REF(class Null) CONSTANT(NULL)

And that generates the bytecode

public java.lang.String g();
Code:
0: aload_0
1: aconst_null
2: pop
3: aconst_null
4: invokevirtual #18; //Method f:(Ljava/lang/String;)Ljava/lang/String;
7: areturn
{code}
Again, the redundant push null, pop, push null sequence.

@scabug
Copy link
Author

scabug commented Jan 23, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7015?orig=1
Reporter: @JamesIry
Assignee: @JamesIry
See #7159

@scabug
Copy link
Author

scabug commented Feb 20, 2013

@JamesIry said:
scala/scala#2147

@scabug
Copy link
Author

scabug commented Feb 20, 2013

@magarciaEPFL said:
For the example

class X {

  def f(x: String) = x

  def g { f(null) }

}

GenBCode emits:

  public void g();
    flags: ACC_PUBLIC

    Code:
      stack=2, locals=1, args_size=1
         0: aload_0       
         1: aconst_null   
         2: invokevirtual #13                 // Method f:(Ljava/lang/String;)Ljava/lang/String;
         5: pop           
         6: return        

Details at http://magarciaepfl.github.com/scala/

@scabug
Copy link
Author

scabug commented Feb 21, 2013

@JamesIry said:
With this fix, so does GenICode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant