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

Add :javap and :asmp to the REPL #12210

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft

Conversation

griggt
Copy link
Collaborator

@griggt griggt commented Apr 24, 2021

I believe this draft to be fully functional, please give it a try if interested.

Unlike the Scala 2 implementation, this one has accomodations for working with JDK 16+. However, in light of the comments in scala/bug#12378, perhaps we should be looking to support an :asmp instead?

Closes lampepfl/dotty-feature-requests#80

[test_windows_full]
[test_java8]
[test_java11]
[test_java15]
[test_java17]
[test_java18]
[test_java19]

@griggt griggt force-pushed the add-javap-to-repl branch 3 times, most recently from d9e689d to 4c57f07 Compare April 25, 2021 03:46
@som-snytt
Copy link
Contributor

Can't have too many toys tools, but it's also true LOC are not free. OTOH existing tool works better than the not yet existing.

@griggt griggt self-assigned this Apr 26, 2021
@griggt
Copy link
Collaborator Author

griggt commented Jun 24, 2021

Now with experimental :asmp support.

@dwijnand
Copy link
Member

@griggt is this still in draft or is it ready for review?

@SethTisue

This comment has been minimized.

project/Build.scala Outdated Show resolved Hide resolved
@griggt

This comment was marked as outdated.

@griggt griggt force-pushed the add-javap-to-repl branch 2 times, most recently from 914fe48 to ea1ce6d Compare October 3, 2021 01:26
@SethTisue
Copy link
Member

@griggt where does this stand? I'm interested in seeing this land and might be interested in helping. (or reviewing it, if you finish it yourself.)

@SethTisue SethTisue changed the title Add :javap to the REPL Add :javap and :asmp to the REPL Oct 14, 2021
@SethTisue

This comment was marked as outdated.

@griggt

This comment was marked as outdated.

@griggt griggt force-pushed the add-javap-to-repl branch 3 times, most recently from 3ccaacb to a2c3874 Compare March 19, 2022 01:34
@griggt
Copy link
Collaborator Author

griggt commented Mar 19, 2022

It seems that our current version of scala-asm does not support Java 18 class files, so :asmp fails to disassemble them:

https://github.com/lampepfl/dotty/runs/5608623717?check_suite_focus=true#step:10:122

Error:  Test dotty.tools.repl.AsmpTests.java.lang.String signatures failed: java.lang.AssertionError: assertion failed: 
disassembly did not contain `public static varargs format(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;`
Error:  Disassembly was:
Error:  Unsupported class file major version 62

By contrast the :javap implementation appears to be OK on Java 18.

--

Edit: we're on ASM 9.1, scala/scala is on 9.2
Upgrade PR: #14711

@som-snytt
Copy link
Contributor

som-snytt commented Mar 19, 2022

I've needed this so badly recently, I meant to come back and whatever the phrase is, put my shoulder to the whatever you put your shoulder to. I need to see what stuff compiles to.

Edit: I already forgot I made this comment two days ago. Actually, what I needed today is -Ygen-asmp, which I learned about recently on Scala 2.

@SethTisue
Copy link
Member

We discussed this some at the Scala 3 issue spree today. One of the remaining issues is the interaction with @targetName, but I don't consider that a blocker (in part because it isn't an easy fix).

Comment on lines +547 to +548
// borrowed from ExtractDependencies#recordDependency and adapted to handle @targetName
private def binaryClassName: String =
Copy link
Collaborator Author

@griggt griggt Mar 22, 2022

Choose a reason for hiding this comment

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

To expand on Seth's comment, I believe this PR correctly deals with classes with the @targetName annotation because I borrowed and adapted this binaryClassName code from ExtractDependencies. But I suspect there may be incremental compilation issues related to @targetName, and ultimately I think this binaryClassName code should be shared rather than duplicated.

I'm going to try to find some test cases and open a separate ticket for any incremental compilation issues.

griggt added 5 commits May 9, 2022 10:33
This commit only provides a framework to support bytecode disassembly from
within the REPL, it does not supply any concrete implementations using any
particular disassembler -- those will follow in subsequent commits.

Adapted from the Scala 2 :javap implementation, which was
written by Paul Phillips and Som Snytt / A. P. Marki
Provides bytecode disassembly using the `javap` tool/interface
supplied by the user's JDK.

Adapted from the Scala 2 implementation, which was written by
Paul Phillips and Som Snytt / A. P. Marki
Provides bytecode disassembly using the ASM library bundled with
the Scala compiler.
@ckipp01
Copy link
Member

ckipp01 commented May 10, 2023

It's been quite some time here, so I wanted to circle back around. Is there any plans to return to this or bring it over the finish line?

@SethTisue
Copy link
Member

Is there a volunteer who would like to take this over and try to get it across the finish line?

@jxnu-liguobin
Copy link
Member

I have been following it for a long time when I was still using Scala2, but I don't know why it didn't move forward.

@som-snytt
Copy link
Contributor

som-snytt commented Sep 16, 2023

PSA there is no finish line. It is an oval track of endless laps.

Edit: I think there is also a PR to move repl to a subproject.

The comments made me revisit this and the scala 2 PRs. I wonder why it invites so many LOC. The scala 2 effort got pushback from retronym on complexity, and he was partially appeased. He comments sagely that it would be nice to support multi-release jars, which would hide some multiplexing/multicomplexity at the expense of a (one-time) hit to build complexity.

Alternatively, support only javap tool interface (latest) and asm is whatever the asm jar version is.

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

Successfully merging this pull request may close these issues.

Support :javap in REPL
6 participants