Skip to content

Commit

Permalink
4.1.1.bytecode.1: Indy and Nests edition.
Browse files Browse the repository at this point in the history
- Support for Java 11 Nest Based Access Control
- Default to Java 16 Major Version
- Use `invokedynamic` for String Concatenation for Java 9 or later .
- Consistent InvokeDynamic (koresframework/Kores#79).
  - Support Dynamic Constant
  - Support Field Specification
  - Better Method Specification
  • Loading branch information
JonathanxD committed Aug 13, 2021
1 parent eb4fef7 commit bb990b8
Show file tree
Hide file tree
Showing 246 changed files with 1,698 additions and 541 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 4.1.1.bytecode.1

- Support for Java 11 Nest Based Access Control
- Default to Java 16 Major Version
- Use `invokedynamic` for String Concatenation for Java 9 or later .
- Consistent InvokeDynamic (https://github.com/koresframework/Kores/issues/79).
- Support Dynamic Constant
- Support Field Specification
- Better Method Specification

# 4.0.4.bytecode.1 - Not Found Edition

- Serialization support and updated to new `Literals` structure.
2 changes: 1 addition & 1 deletion Kores
Submodule Kores updated 3290 files
24 changes: 12 additions & 12 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ buildscript {
}

group 'com.github.jonathanxd'
version '4.0.4.bytecode.1'
version '4.1.1.bytecode.1'

apply from: project(":Kores").file("gradle/common.gradle")

Expand All @@ -28,16 +28,16 @@ dependencies {
// with runtime dependency pointing to Kores published version
//compile project(":Kores")
compileOnly project(":Kores")
runtime "com.github.JonathanxD.Kores:Kores:4.0.4.base"
compile 'com.github.JonathanxD:BytecodeDisassembler:2.1.1'
compile "org.ow2.asm:asm:6.0"
compile "org.ow2.asm:asm-analysis:6.0"
compile "org.ow2.asm:asm-tree:6.0"
compile "org.ow2.asm:asm-util:6.0"

testCompile "com.github.JonathanxD.JwIUtils:links:$iutils_version"
testCompile project(":Kores")
testCompile project(path: ':Kores', configuration: 'tests')
runtimeOnly "com.github.koresframework.Kores:Kores:4.1.1.base"
implementation 'com.github.JonathanxD:BytecodeDisassembler:2.3.0'
implementation "org.ow2.asm:asm:9.2"
implementation "org.ow2.asm:asm-analysis:9.2"
implementation "org.ow2.asm:asm-tree:9.2"
implementation "org.ow2.asm:asm-util:9.2"

testImplementation "com.github.JonathanxD.JwIUtils:links:$iutils_version"
testImplementation project(":Kores")
testImplementation project(path: ':Kores', configuration: 'tests')
}

tasks.dokkaGfm.configure {
Expand All @@ -51,4 +51,4 @@ shadowJar {
include(dependency("com.github.JonathanxD:BytecodeDisassembler"))
include(dependency("com.github.JonathanxD:JwIUtils"))
}
}
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* The MIT License (MIT)
*
* Copyright (c) 2018 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <[email protected]>
* Copyright (c) 2021 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <[email protected]>
* Copyright (c) contributors
*
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* The MIT License (MIT)
*
* Copyright (c) 2018 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <[email protected]>
* Copyright (c) 2021 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <[email protected]>
* Copyright (c) contributors
*
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* The MIT License (MIT)
*
* Copyright (c) 2018 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <[email protected]>
* Copyright (c) 2021 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <[email protected]>
* Copyright (c) contributors
*
*
Expand Down Expand Up @@ -35,6 +35,9 @@ import com.github.jonathanxd.kores.bytecode.post.GotoOptimizer
import com.github.jonathanxd.kores.bytecode.post.MethodProcessor
import com.github.jonathanxd.kores.bytecode.pre.GenLineVisitor
import com.github.jonathanxd.iutils.option.Option
import com.github.jonathanxd.iutils.option.Options
import com.github.jonathanxd.kores.bytecode.doc.NestLogic
import com.github.jonathanxd.kores.bytecode.doc.IndyConcatLogic

/**
* Calls [org.objectweb.asm.util.CheckClassAdapter] to check generated class.
Expand Down Expand Up @@ -115,6 +118,194 @@ val GENERATE_BRIDGE_METHODS = Option(false)
@JvmField
val GENERATE_SYNTHETIC_ACCESS = Option(true)

/**
* Automatically generate synthetic accessors for private members in private inner classes.
* Synthetic accessors will be only generated for private members which are accessed.
*
* An anonymous synthetic class may be generated for private constructors.
*
* @since 4.0.5.bytecode.5
*/
@JvmField
val FORCE_GENERATE_SYNTHETIC_ACCESS = Option(false)

/**
* When enabled, generate nests declarations as specified in [JEP 181](https://openjdk.java.net/jeps/181),
* enabling this automatically disables [GENERATE_SYNTHETIC_ACCESS].
*
* To have both enabled, use [FORCE_GENERATE_SYNTHETIC_ACCESS]. This is not recommended since
* [Nest-Based Access Control](https://openjdk.java.net/jeps/181) introduces JVM-Level access control
* and removes the need of having bridge methods to access inner classes private members.
*
* @since 4.0.5.bytecode.5
*/
@JvmField
val GENERATE_NESTS = Option(true)

/**
* Force generate [Nests](https://openjdk.java.net/jeps/181) even when emitting bytecode for Java 10 (54) or earlier.
*
* Note that forcing to generate Nests may result in two scenarios:
*
* - Generate Nests info but invoke with **synthetic accessors** when [FORCE_GENERATE_SYNTHETIC_ACCESS] is set.
* - Generate Nests info and access members directly. JVM may not accept this kind of access when running under Java 10 or earlier.
*
* Read more at [GENERATE_NESTS].
*/
@JvmField
val FORCE_GENERATE_NESTS = Option(true)

/**
* Uses `invokedynamic` instruction for string concatenation instead of [StringBuilder].
*
* This option is automatically disabled when emitting bytecode for Java 8 or earlier, to force use [FORCE_INDIFY_STRING_CONCAT].
*
* Read more at [IndyConcatLogic]
*/
@JvmField
val INDIFY_STRING_CONCAT = Option(true)

/**
* Force the use of `invokedynamic` instruction for string concatenation instead of [StringBuilder].
*
* This applies even if the target bytecode version is lower or equal to 52 (Java 8), so the concatenation will
* only work when running under Java 9 or newer.
*
* Read [INDIFY_STRING_CONCAT] for more information.
*/
@JvmField
val FORCE_INDIFY_STRING_CONCAT = Option(false)

/**
* Specifies the strategy to use to generate `invokedynamic` string concatenation, as specified in
* [java.lang.invoke.StringConcatFactory.makeConcatWithConstants].
*
* Read more at [IndyConcatLogic].
*/
@JvmField
val INDY_CONCAT_STRATEGY = Option(IndyConcatStrategy.INTERPOLATE)

enum class IndyConcatStrategy {
/**
* Indify using interpolation, the produced `invokedynamic` instruction interpolates the constants in the
* [recipe][java.lang.invoke.StringConcatFactory.makeConcatWithConstants] argument.
*
* For example, the following concatenation scenario:
*
* ```kotlin
* fun concat(a: String, b: String) =
* a + "<:>" + b
* ```
*
* Is translated into the following recipe:
* ```
* aload 0 // Load a
* aload 1 // Load b
* makeConcatWithConstants<invokedynamic>("\u0001<:>\u0001")
* ```
*
*/
INTERPOLATE,

/**
* Indify providing constants to the [bootstrap method constants parameter][java.lang.invoke.StringConcatFactory.makeConcatWithConstants].
* This results in an interpolation using `\u0001` for arguments in the stack and `\u0002` for constants in the **ConstantPool**.
*
* For example, the following concatenation scenario:
*
* ```kotlin
* fun concat(a: String, b: String) =
* a + "<:>" + b
* ```
*
* Is translated into the following recipe:
* ```
* aload 0 // Load a
* aload 1 // Load b
*
* makeConcatWithConstants<invokedynamic>("\u0001\u0002\u0001", "<:>")
* ```
*
* With `<:>` provided as an argument to the [bootstrap method constants parameter][java.lang.invoke.StringConcatFactory.makeConcatWithConstants].
*/
CONSTANT,

/**
* Indify using only arguments in the stack. Constant values are pushed to the stack using `ldc` instruction.
*
* For example, the following concatenation scenario:
*
* ```kotlin
* fun concat(a: String, b: String) =
* a + "<:>" + b
* ```
*
* Is translated into the following recipe:
* ```
* aload 0 // Load a
* ldc "<:>"
* aload 1 // Load b
* makeConcatWithConstants<invokedynamic>("\u0001\u0001\u0001")
* ```
*/
LDC
}

/**
* Read more in [NestLogic]
*/
fun Options.nestAccessGenerationMode(version: Int) =
when {
this[FORCE_GENERATE_SYNTHETIC_ACCESS] == true && this[GENERATE_NESTS] == true && version >= 55 -> NestAccessGenerationMode.MIXED
this[FORCE_GENERATE_SYNTHETIC_ACCESS] == true && this[FORCE_GENERATE_NESTS] == true -> NestAccessGenerationMode.MIXED
this[FORCE_GENERATE_NESTS] == true -> NestAccessGenerationMode.NEST_BASED
this[GENERATE_NESTS] == true && version >= 55 -> NestAccessGenerationMode.NEST_BASED
this[GENERATE_SYNTHETIC_ACCESS] == true -> NestAccessGenerationMode.SYNTHETIC_ONLY
else -> NestAccessGenerationMode.DISABLED
}

/**
* Read more in [NestLogic]
*/
enum class NestAccessGenerationMode {
/**
* Synthetic and Bridge based inner class private member access.
*/
SYNTHETIC_ONLY,

/**
* Nest-based inner class private member access, as specified in [JEP 181](https://openjdk.java.net/jeps/181).
*/
NEST_BASED,

/**
* Mixed, generate NestHost and NestMember declarations, as specified in [JEP 181](https://openjdk.java.net/jeps/181),
* but use **Synthetic Bridge Methods** for access instead of direct access.
*
* Not recommended since [Nest-Based Access Control](https://openjdk.java.net/jeps/181) allows direct access to private
* members without **bridge methods**. This should only be used in **very very very** specific cases.
*/
MIXED,

/**
* Totally disabled. This may cause **class load-time** and/or **runtime exceptions** in most JVM Implementations
* since classes are not allowed to access private members.
*/
DISABLED
}

/**
* Read more in [NestLogic]
*/
fun NestAccessGenerationMode.isSyntheticAccess() =
this == NestAccessGenerationMode.SYNTHETIC_ONLY || this == NestAccessGenerationMode.MIXED

/**
* Read more in [NestLogic]
*/
fun NestAccessGenerationMode.isToGenerateNests() =
this == NestAccessGenerationMode.MIXED || this == NestAccessGenerationMode.NEST_BASED

enum class VisitLineType {
/**
* Disable line visit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* The MIT License (MIT)
*
* Copyright (c) 2018 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <[email protected]>
* Copyright (c) 2021 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <[email protected]>
* Copyright (c) contributors
*
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* The MIT License (MIT)
*
* Copyright (c) 2018 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <[email protected]>
* Copyright (c) 2021 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <[email protected]>
* Copyright (c) contributors
*
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* The MIT License (MIT)
*
* Copyright (c) 2018 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <[email protected]>
* Copyright (c) 2021 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <[email protected]>
* Copyright (c) contributors
*
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* The MIT License (MIT)
*
* Copyright (c) 2018 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <[email protected]>
* Copyright (c) 2021 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <[email protected]>
* Copyright (c) contributors
*
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* The MIT License (MIT)
*
* Copyright (c) 2018 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <[email protected]>
* Copyright (c) 2021 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <[email protected]>
* Copyright (c) contributors
*
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* The MIT License (MIT)
*
* Copyright (c) 2018 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <[email protected]>
* Copyright (c) 2021 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <[email protected]>
* Copyright (c) contributors
*
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* The MIT License (MIT)
*
* Copyright (c) 2018 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <[email protected]>
* Copyright (c) 2021 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <[email protected]>
* Copyright (c) contributors
*
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* The MIT License (MIT)
*
* Copyright (c) 2018 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <[email protected]>
* Copyright (c) 2021 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <[email protected]>
* Copyright (c) contributors
*
*
Expand Down
Loading

0 comments on commit bb990b8

Please sign in to comment.