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

Support diffing Jar bytecode versions #168

Open
wants to merge 9 commits into
base: trunk
Choose a base branch
from

Conversation

Goooler
Copy link
Contributor

@Goooler Goooler commented Aug 25, 2023

OLD: diffuse-0.2.0-SNAPSHOT-java11.jar (bytecodeVersion: 55)
NEW: diffuse-0.2.0-SNAPSHOT-java16.jar (bytecodeVersion: 60)

 JAR   │ old      │ new      │ diff
───────┼──────────┼──────────┼──────
 class │ 90.6 KiB │ 90.6 KiB │  0 B
 other │     96 B │     96 B │  0 B
───────┼──────────┼──────────┼──────
 total │ 90.7 KiB │ 90.7 KiB │  0 B

 CLASSES │ old │ new │ diff
─────────┼─────┼─────┼───────────
 classes │  24 │  24 │ 0 (+0 -0)
 methods │ 234 │ 234 │ 0 (+0 -0)
  fields │  78 │  78 │ 0 (+0 -0)

=================
====   JAR   ====
=================

 size │ diff │ path
──────┼──────┼─────────
  0 B │  0 B │ (total)

diffuse/src/main/rules.txt Outdated Show resolved Hide resolved
@@ -26,13 +27,14 @@ class Class private constructor(
@JvmName("parse")
fun Input.toClass(): Class {
val reader = ClassReader(toByteArray())
val bytecodeVersion = reader.readShort(0 + 6)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure how to implement this for Dex files.

@Goooler Goooler mentioned this pull request Sep 5, 2023
@@ -7,6 +7,7 @@ import com.jakewharton.diffuse.io.Input

class Jar private constructor(
override val filename: String?,
val bytecodeVersion: Short?,
Copy link
Owner

Choose a reason for hiding this comment

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

Unfortunately I think we're going to drown in nuance here. Jars don't have bytecode versions, classes do. And multiple classes within a jar can have different versions. You can conditionally classload classes based on capabilities and those classes could be compiled for two different versions of Java. There's also the multi-version jar standard which puts classes of different versions into META-INF/versions/N/. The ordering of the classes in the jar (read: zip) could be effectively random so taking the first class may not be indicative of what the majority of classes were compiled with.

I'm happy to discuss strategies for surfacing this information, but as-is I think this is too simple of an implementation. Note that it probably works for 99.99% of jars, but when it fails it fails in a spectacularly wrong way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now I count all the byte code versions in a Jar and filter the most one.

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.

2 participants