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

Consider dropping support for Java 6 in kotlinx.coroutines 1.4 #1589

Closed
qwwdfsad opened this issue Oct 1, 2019 · 11 comments
Closed

Consider dropping support for Java 6 in kotlinx.coroutines 1.4 #1589

qwwdfsad opened this issue Oct 1, 2019 · 11 comments

Comments

@qwwdfsad
Copy link
Member

qwwdfsad commented Oct 1, 2019

Supporting Java 6 target creates a lot of maintenance burden and it would be nice if we could migrate to Java 7 or 8. A lot of widespread Android libraries work only with Java 8, Android toolchain knows how to desugar Java 6+ API (except for java.time that we don't use) and it's unlikely that there are users sitting on old Android toolchain, Java 6, but on the latest kotlinx.coroutines.

This issue is created to gather feedback and/or objections about such migration.

List of potential features blocked by Java 6 support:

  1. ClassValue in stacktrace recovery (instead of a concurrent map of weak references that is prone to class leaks)
  2. Possibility to piggyback on FJP for both Dispatchers.Default and Dispatchers.IO (using ManagedBlocker) on Android. It will reduce the size of resulting dex with kx.coroutines by ~20 KB and will share threads with common pool (less memory consumption -> better footprint on low-end devices)
  3. JvmDefault to evolve our public interfaces in a backward-compatible way (also, less bytecode)
  4. Proper addSuppressed without reflection or jdk8 jar.
  5. Better stacktrace recovery (inspect constructor parameters names reflectively)
    ...
@qwwdfsad qwwdfsad changed the title Consider dropping support for Java 6 in kotlinx.coroutiens 1.4 Consider dropping support for Java 6 in kotlinx.coroutines 1.4 Oct 1, 2019
@JakeWharton
Copy link
Contributor

From Android's perspective, the use of ForkJoinPool would set your minimum supported API level at 21 which would mean Throwable.addSuppressed would be natively available and not need desugared. Default interface methods still need desugared below API 24, but as you said users upgrading to 1.4 would likely have the necessary updated tooling in place (and their builds will fail if they don't).

@fvasco
Copy link
Contributor

fvasco commented Oct 1, 2019

it would be nice if we could migrate to Java 7 or 8

Please consider Java 8 only, I don't see any worth in Java 7 support.

@JakeWharton
Copy link
Contributor

What specifically are you looking for from 8 that is not available in 7? Also do you mean the APIs of 8, the classfile format version, or both?

@fvasco
Copy link
Contributor

fvasco commented Oct 2, 2019

I am considering class version 52.
It supports default method in interfaces, it is the point 4 in the list.

Personally I don't consider supporting Java 7 a worth, nor for Android now for regular JVM software.
Further similar issues can be solved using multi-release JARs, so upgrade to Java 8 as minimal requirement should be enough for a while.

@JakeWharton
Copy link
Contributor

JakeWharton commented Oct 4, 2019

Classfile version 52 and Java 7 APIs is acceptable from an Android perspective. Java versions essentially are meaningless when talking about Android support anyway. API 21 is a reasonable minimum-supported version and the toolchain can handle classfile version 52.

@elizarov
Copy link
Contributor

elizarov commented Oct 4, 2019

@JakeWharton What would be the easiest way to automatically (during CI) verify that we are only using APIs that are available in certain Android API version and what minimum API version you'd recommend to support for a core library like kotlinx.coroutines?

@JakeWharton
Copy link
Contributor

JakeWharton commented Oct 4, 2019

For OkHttp and Okio (which are also Kotlin multiplatform projects) we use Animal Sniffer on the JVM targets to ensure compatibility. For example, OkHttp supports Java 8 on the JVM and API 21 for Android so we configure both of those: https://github.com/square/okhttp/blob/master/build.gradle#L112-L119.

I personally think API 21 is a reasonable minimum supported version. The global platform dashboard (which inexplicably hasn't been updated since May) at https://developer.android.com/about/dashboards paints roughly 10% below that line, the most of which is 7% on API 19 (API 20 doesn't really exist). You can speculate that those numbers are even lower by now since they only go down. It's a long tail to zero though so I would not consider a non-zero number worth supporting simply because it exists.

Choosing a higher minimum supported version will always bring complaints. Plenty of people will be supporting API 19 and potentially even lower. You'll want your choice to be defensible. In OkHttp's case API 21 meant modern cipher suites are guaranteed which ensured the privacy of its user's data. I think the desire to use FJP unconditionally is a pretty strong position given the code size and runtime performance/memory impact.

It will also have interesting implications on the AndroidX libraries which depend on coroutines. Most (all?) of them support API 14+ for no real good reason other than historical and no strong motivation to move. I would not let that play a factor in your decision. They've been forced to bump the minimum of various modules before and those modules can decide to stick to a 1.3 dependency to retain compatibility or bump for new features just like everyone else.

(All of this is my personal view as an Android developer. If you need some official Android position that'll be a whole other ordeal)

@fvasco
Copy link
Contributor

fvasco commented Oct 14, 2019

Possibility to piggyback on FJP (...) on Android

The current custom scheduler provides a concrete improvement on non Android platform?
In other words: is it possible to focus development on a mature API using already provided battle-tested utilities like FJP?

@ZakTaccardi
Copy link

At this time, are Coroutines considering targeting which API level for 1.4? Java 7 or 8?

@elizarov
Copy link
Contributor

It would simplify dev setup if we compile against JDK 8 and target JDK 8 bytecode (version 52), but we are in no immediate need to use any JDK 8 API. JDK 7 should be enough. In this case, we'll need some kind of validation setup against a specific Android API surface we'll choose as a min version. Any pointers and other help here will be appreciated.

@JakeWharton
Copy link
Contributor

yorickhenning pushed a commit to yorickhenning/kotlinx.coroutines that referenced this issue Jan 28, 2022
Kotlin#2963)

* Introduce animalsniffer checks to coroutines and compile against Java 8 source and binary target, but still avoiding Java 7+ API
* Do not use deprecated target, language desugaring will handle default interface methods and Math/Long/Int static methods
* Partially migrate to .gradle.kts

Fixes Kotlin#1589
pablobaxter pushed a commit to pablobaxter/kotlinx.coroutines that referenced this issue Sep 14, 2022
Kotlin#2963)

* Introduce animalsniffer checks to coroutines and compile against Java 8 source and binary target, but still avoiding Java 7+ API
* Do not use deprecated target, language desugaring will handle default interface methods and Math/Long/Int static methods
* Partially migrate to .gradle.kts

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

No branches or pull requests

5 participants