8000 Upgrade to scala-asm 6.2 by retronym · Pull Request #6733 · scala/scala · GitHub
[go: up one dir, main page]

Skip to content

Upgrade to scala-asm 6.2 #6733

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

Merged
merged 6 commits into from
Jun 29, 2018
Merged

Upgrade to scala-asm 6.2 #6733

merged 6 commits into from
Jun 29, 2018

Conversation

retronym
Copy link
Member
@retronym retronym commented Jun 6, 2018

See: scala/scala-asm#5

Upstream changes in ASM:

scala/scala-asm@ASM_6_0...ASM_6_2
http://asm.ow2.io/versions.html

The motivations, other than just keeping current, are:

  • support for Java 9/10/11 updates to the classfile format.
  • reducing needless String => Array[Char] conversions thanks
    to internal changes in ASM.

This PR will fail to build until we publish artifact
from scala/scala-asm.

Fixes scala/bug#10717

@scala-jenkins scala-jenkins added this to the 2.13.0-M5 milestone Jun 6, 2018
@retronym retronym requested a review from lrytz June 6, 2018 01:40
@retronym retronym self-assigned this Jun 6, 2018
@retronym retronym added the WIP label Jun 6, 2018
@retronym
Copy link
Member Author
retronym commented Jun 6, 2018

Under the scalap corpus, this gives us a 3% reduction in allocations. These might be coming from https://gitlab.ow2.org/asm/asm/commit/5db12737cbb662c56bc5ed9cc9902530b3ec1154. I'll compare profiles to learn more.

I'm still measuring effect on compile time in the benchmark.

@lrytz
Copy link
Member
lrytz commented Jun 6, 2018

LGTM, let's release scala-asm 6.2.0-scala-1

@mkurz
Copy link
Contributor
mkurz commented Jun 6, 2018

Maybe it's time to try to get all the patches into the official asm repo?

@adriaanm
Copy link
Contributor
adriaanm commented Jun 6, 2018

Maybe it's time to try to get all the patches into the official asm repo?

We'd love to. Will keep trying (recent attempt: https://gitlab.ow2.org/asm/asm/issues/317828#note_35917). (EDIT: expanding a bit: they don't seem to have a clear story on how we can contribute our patches, but the bug we reported above was fixed. If someone here has a connection to the ASM maintainers and could introduce us, that'd be great.)

@retronym
Copy link
Member Author
retronym commented Jun 7, 2018

/rebuild

Copy link
Member
@lrytz lrytz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Squashed the two commits and included a fix for the failing test

@lrytz lrytz removed the WIP label Jun 7, 2018
@lrytz
Copy link
Member
lrytz commented Jun 7, 2018

Hmm, travis aborted

[warn] /home/travis/build/scala/scala/src/library/scala/collection/View.scala:147: @SerialVersionUID has no effect on non-serializable classes
[warn]   class Partition[A](val underlying: SomeIterableOps[A], val p: A => Boolean) {
[warn]         ^
[warn] /home/travis/build/scala/scala/src/library/scala/collection/View.scala:291: @SerialVersionUID has no effect on non-serializable classes
[warn]   class Unzip[A, A1, A2](underlying: SomeIterableOps[A])(implicit asPair: A => (A1, A2)) {
[warn]         ^
[warn] /home/travis/build/scala/scala/src/library/scala/collection/View.scala:297: @SerialVersionUID has no effect on non-serializable classes
[warn]   class Unzip3[A, A1, A2, A3](underlying: SomeIterableOps[A])(implicit asTriple: A => (A1, A2, A3)) {
[warn]         ^
[warn] there were 36 deprecation warnings (since 2.10.0)
[warn] there was one deprecation warning (since 2.11.0)
[warn] there were two deprecation warnings (since 2.12.0)
[warn] there were 14 deprecation warnings (since 2.13.0)
[warn] there were 53 deprecation warnings in total; re-run with -deprecation for details
[warn] there were 11 feature warnings; re-run with -feature for details
[warn] there were 411 inliner warnings; re-run enabling -opt-warnings for details, or try -help
[warn] 10 warnings found
[warn] there were two deprecation warnings
[warn] there were two deprecation warnings (since 2.10.0)
[warn] there were four deprecation warnings (since 2.10.1)
[warn] there were 15 deprecation warnings (since 2.11.0)
[warn] there were two deprecation warnings (since 2.12.3)
[warn] there were 22 deprecation warnings (since 2.13.0)
[warn] there were 47 deprecation warnings in total; re-run with -deprecation for details
[warn] there were four unchecked warnings; re-run with -unchecked for details
[warn] there were four inliner warnings; re-run enabling -opt-warnings for details, or try -help
[warn] 9 warnings found
No output has been received in the last 10m0s, this potentially indicates a stalled build or something wrong with the build itself.
Check the details on how to adjust your build configuration on: https://docs.travis-ci.com/user/common-build-problems/#Build-times-out-because-no-output-was-received

and jenkins seems to be stuck in the same place...

@lrytz
Copy link
Member
lrytz commented Jun 7, 2018

Jenkins continued now; but it does look little suspicious.

@retronym retronym added the performance the need for speed. usually compiler performance, sometimes runtime performance. label Jun 8, 2018
@retronym
Copy link
Member Author
retronym commented Jun 8, 2018

I've seen that output on Travis recently, so it might be a latent problem on this branch (OSGi plugin or something?) I'll take a look locally on Monday.

@lrytz
Copy link
Member
lrytz commented Jun 8, 2018

So you'd like to wait before merging?

@retronym
Copy link
Member Author
retronym commented Jun 8, 2018 via email

@retronym retronym force-pushed the bump/asm-6.2 branch 2 times, most recently from 232f71c to 2d3d96c Compare June 20, 2018 00:17
@retronym
Copy link
Member Author

Rebased. I tried locally to see if the (bootstrapped) build got stuck in a similar spot to those logs but didn't see it. I'd say we should merge this and revert it we see the problems in CI.

@retronym
Copy link
Member Author

Travis failed again on 2d3d96c with the same timeout. 😖

@retronym
Copy link
Member Author

I've captured stacks of the slowness in Jenkins. Looks like it shows up under -opt in ProdConsAnalyzer.

@retronym retronym force-pushed the bump/asm-6.2 branch from 10000 603521e to a0d9c08 Compare June 20, 2018 04:59
@retronym
Copy link
Member Author

I've added a benchmark that shows the performance regression, which starts right away in 54dbb0f.

Here are the profiles before and after

Looks like we're falling into this code much more than before: https://github.com/scala/scala-asm/blob/2e8a7bb0634ed905f7df86ba2ecef08c90855636/src/main/java/scala/tools/asm/tree/analysis/SourceInterpreter.java#L205-L208

@retronym
Copy link
Member Author

This diff in ASM triggers the slowness.

It now creates a new Frame for each instructon ➡️ enclosing-handler edge. We capture this in our pseudo instruction ExceptionProducer:

case class ExceptionProducer[V <: Value](handlerLabel: LabelNode, handlerFrame: Frame[V]) extends InitialProducer

These no longer get collapsed when entering them into the merging SourceValue#insn sets together in SourceInterpreter#merge.

The fix looks straight forward enough: just capture the handlerFrame.stackTop in our pseudo instruction, which is all we need later on.

@retronym
Copy link
Member Author

@lrytz Since you last looked:

  • I've included "Customise label handling without needing to modify ASM directly"
  • The performance regression in prod/cons is identified and remedied
  • I've added a commit to show that the "call copyOperation consistently" change that didn't get merged to upstream ASM isn't needed anyway, at least accordng to our test suite and my understanding of usage of ASM.

After this, we're ready to move to vanilla ASM 6.3. We still need to decided on whether to depend on it as a regular dependency or keep the status quo of repackaging (either with the scripts in scala-asm or perhaps just with JarJar).

retronym added 4 commits June 20, 2018 17:12
ASM 6.2 now creates a new Frame inside the loop in which
`newExceptionValue` is called. We were including this frame
in the case-class equality of the pseudo-instruction,
`ExceptionProducer`, and upon receiving new instances each
time the `ProdCons` analysis massively slowed down.

This commit just captures the data we need: the stack top of the
handler frame.
See: scala/scala-asm#5

Upstream changes in ASM:

  scala/scala-asm@ASM_6_0...ASM_6_2
  http://asm.ow2.io/versions.html

The motivations, other than just keeping current, are:

  - support for Java 9/10/11 updates to the classfile format.
  - reducing needless String => Array[Char] conversions thanks
    to internal changes in ASM.

This PR will fail to build until we publish artifact
from scala/scala-asm.

Includes a workaround for scala/bug#10418
It seems we don't need CustomAttr in our fork of scala-asm,
we can just override Attribute.write.
Copy link
Member
@lrytz lrytz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for finding and fixing the performance regression!

import scala.tools.asm.tree.ClassNode;
import scala.tools.asm.tree.MethodNode;

public class ClassNode1 extends ClassNode {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Le'ts add a comment why this custom class exists

import scala.tools.asm.tree.LabelNode;
import scala.tools.asm.tree.MethodNode;

public class MethodNode1 extends MethodNode {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here, a comment would be good.

@Override
protected LabelNode getLabelNode(Label label) {
if (!(label.info instanceof LabelNode)) {
label.info = new LabelNode1(label);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here, where the actual change is.

import scala.tools.asm.Label;
import scala.tools.asm.tree.LabelNode;

public class LabelNode1 extends LabelNode {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment what we customize

@@ -19,7 +19,7 @@ import AliasSet.SmallBitSet
*
* See the doc of package object `analysis` for some notes on the performance of alias analysis.
*/
class AliasingFrame[V <: Value](nLocals: Int, nStack: Int) extends Frame[V](nLocals, nStack) {
class AliasingFrame[V <: Value](nLocals: Int, nStack: Int) extends VanillaAsmFrame[V](nLocals, nStack) {
Copy link
Member
@lrytz lrytz Jun 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AliasingFrame is used in copy propagation and nullness analysis, but not in ProdConsAnalyzer. The following diff does that: https://github.com/retronym/scala/compare/bump/asm-6.2...lrytz:pr6733?expand=1

With that, some tests ProdConsAnalyzerTest actually start failing.

There might be a way to implement prod-cons without those additional calls to copyOperation, I haven't looked in detail.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect ProdConsAnalyzer to fail with the VanillaAsmFrame until ASM 6.3 which will start to call newParameterValue/newEmptyNonParameterLocalValue/newExceptionValue, which InitialProducerSourceInterpreter implements.

We only override copyOperation in NullnessInterpreter.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I follow.. The newXValue methods are called in the Analyzer, not in Frame / VanillaAsmFrame. The copyOperation implementation for ProdCons is inherited from SourceInterpreter. Anyway, we'll see when we update to 6.3.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I didn't consider the inherited implementation of copyOperation, i just looked for the one override in our codebase. Still, it should be easy enough to adapt when we need to.

@retronym
Copy link
Member Author

I've removed "38826f6320 Show that we don't actually need 'call copyOperation consistently" as it is just code that would be redundant with ASM 6.3. I've also added comments to the asm.tree._Node customizations.

@lrytz lrytz merged commit 78c0fc9 into scala:2.13.x Jun 29, 2018
ElfoLiNk pushed a commit to ElfoLiNk/scala that referenced this pull request Aug 18, 2018
Avoid performance problem after ASM upgrade in prod/cons analysis

ASM 6.2 now creates a new Frame inside the loop in which
`newExceptionValue` is called. We were including this frame
in the case-class equality of the pseudo-instruction,
`ExceptionProducer`, and upon receiving new instances each
time the `ProdCons` analysis massively slowed down.

This commit just captures the data we need: the stack top of the
handler frame.

Upgrade to scala-asm 6.2

See: scala/scala-asm#5

Upstream changes in ASM:

  scala/scala-asm@ASM_6_0...ASM_6_2
  http://asm.ow2.io/versions.html

The motivations, other than just keeping current, are:

  - support for Java 9/10/11 updates to the classfile format.
  - reducing needless String => Array[Char] conversions thanks
    to internal changes in ASM.

This PR will fail to build until we publish artifact
from scala/scala-asm.

Includes a workaround for scala/bug#10418

Move to the standard way of defining a custom asm.Attribute

It seems we don't need CustomAttr in our fork of scala-asm,
we can just override Attribute.write.

Customise label handling without needing to modify ASM directly

Comment on our customizations to asm.tree.*Node
smarter added a commit to dotty-staging/dotty that referenced this pull request Feb 12, 2019
Catch up with Scala 2.13.

The corresponding scalac PRs are
scala/scala#6733 and
scala/scala#7384

Most of the changes from these PRs aren't currently needed in Dotty
since they only affect the Scala 2 backend optimizer.
smarter added a commit to dotty-staging/dotty that referenced this pull request Feb 12, 2019
Catch up with Scala 2.13.

The corresponding scalac PRs are
scala/scala#6733 and
scala/scala#7384

Some of the changes from these PRs aren't currently needed in Dotty
since they only affect the Scala 2 backend optimizer.

Co-Authored-By: Jason Zaugg <jzaugg@gmail.com>
smarter added a commit to dotty-staging/dotty that referenced this pull request Feb 12, 2019
Catch up with Scala 2.13.

The corresponding scalac PRs are
scala/scala#6733 and
scala/scala#7384

Some of the changes from these PRs aren't currently needed in Dotty
since they only affect the Scala 2 backend optimizer.

This update does not change the generated bytecode (at least when
compiling dotty itself).

Co-Authored-By: Jason Zaugg <jzaugg@gmail.com>
adriaanm pushed a commit to adriaanm/scala that referenced this pull request May 23, 2019
Avoid performance problem after ASM upgrade in prod/cons analysis

ASM 6.2 now creates a new Frame inside the loop in which
`newExceptionValue` is called. We were including this frame
in the case-class equality of the pseudo-instruction,
`ExceptionProducer`, and upon receiving new instances each
time the `ProdCons` analysis massively slowed down.

This commit just captures the data we need: the stack top of the
handler frame.

Upgrade to scala-asm 6.2

See: scala/scala-asm#5

Upstream changes in ASM:

  scala/scala-asm@ASM_6_0...ASM_6_2
  http://asm.ow2.io/versions.html

The motivations, other than just keeping current, are:

  - support for Java 9/10/11 updates to the classfile format.
  - reducing needless String => Array[Char] conversions thanks
    to internal changes in ASM.

This PR will fail to build until we publish artifact
from scala/scala-asm.

Includes a workaround for scala/bug#10418

Move to the standard way of defining a custom asm.Attribute

It seems we don't need CustomAttr in our fork of scala-asm,
we can just override Attribute.write.

Customise label handling without needing to modify ASM directly

Comment on our customizations to asm.tree.*Node

(cherry picked from commit 79b7f2a)
adriaanm pushed a commit to adriaanm/scala that referenced this pull request May 23, 2019
Avoid performance problem after ASM upgrade in prod/cons analysis

ASM 6.2 now creates a new Frame inside the loop in which
`newExceptionValue` is called. We were including this frame
in the case-class equality of the pseudo-instruction,
`ExceptionProducer`, and upon receiving new instances each
time the `ProdCons` analysis massively slowed down.

This commit just captures the data we need: the stack top of the
handler frame.

Upgrade to scala-asm 6.2

See: scala/scala-asm#5

Upstream changes in ASM:

  scala/scala-asm@ASM_6_0...ASM_6_2
  http://asm.ow2.io/versions.html

The motivations, other than just keeping current, are:

  - support for Java 9/10/11 updates to the classfile format.
  - reducing needless String => Array[Char] conversions thanks
    to internal changes in ASM.

This PR will fail to build until we publish artifact
from scala/scala-asm.

Includes a workaround for scala/bug#10418

Move to the standard way of defining a custom asm.Attribute

It seems we don't need CustomAttr in our fork of scala-asm,
we can just override Attribute.write.

Customise label handling without needing to modify ASM directly

Comment on our customization
71F9
s to asm.tree.*Node

(cherry picked from commit 79b7f2a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance the need for speed. usually compiler performance, sometimes runtime performance.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0