Skip to content

Commit bb990b8

Browse files
committed
4.1.1.bytecode.1: Indy and Nests edition.
- 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
1 parent eb4fef7 commit bb990b8

File tree

246 files changed

+1698
-541
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

246 files changed

+1698
-541
lines changed

CHANGELOG.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# 4.1.1.bytecode.1
2+
3+
- Support for Java 11 Nest Based Access Control
4+
- Default to Java 16 Major Version
5+
- Use `invokedynamic` for String Concatenation for Java 9 or later .
6+
- Consistent InvokeDynamic (https://github.com/koresframework/Kores/issues/79).
7+
- Support Dynamic Constant
8+
- Support Field Specification
9+
- Better Method Specification
10+
11+
# 4.0.4.bytecode.1 - Not Found Edition
12+
13+
- Serialization support and updated to new `Literals` structure.

Kores

Submodule Kores updated 3290 files

build.gradle

+12-12
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ buildscript {
1818
}
1919

2020
group 'com.github.jonathanxd'
21-
version '4.0.4.bytecode.1'
21+
version '4.1.1.bytecode.1'
2222

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

@@ -28,16 +28,16 @@ dependencies {
2828
// with runtime dependency pointing to Kores published version
2929
//compile project(":Kores")
3030
compileOnly project(":Kores")
31-
runtime "com.github.JonathanxD.Kores:Kores:4.0.4.base"
32-
compile 'com.github.JonathanxD:BytecodeDisassembler:2.1.1'
33-
compile "org.ow2.asm:asm:6.0"
34-
compile "org.ow2.asm:asm-analysis:6.0"
35-
compile "org.ow2.asm:asm-tree:6.0"
36-
compile "org.ow2.asm:asm-util:6.0"
37-
38-
testCompile "com.github.JonathanxD.JwIUtils:links:$iutils_version"
39-
testCompile project(":Kores")
40-
testCompile project(path: ':Kores', configuration: 'tests')
31+
runtimeOnly "com.github.koresframework.Kores:Kores:4.1.1.base"
32+
implementation 'com.github.JonathanxD:BytecodeDisassembler:2.3.0'
33+
implementation "org.ow2.asm:asm:9.2"
34+
implementation "org.ow2.asm:asm-analysis:9.2"
35+
implementation "org.ow2.asm:asm-tree:9.2"
36+
implementation "org.ow2.asm:asm-util:9.2"
37+
38+
testImplementation "com.github.JonathanxD.JwIUtils:links:$iutils_version"
39+
testImplementation project(":Kores")
40+
testImplementation project(path: ':Kores', configuration: 'tests')
4141
}
4242

4343
tasks.dokkaGfm.configure {
@@ -51,4 +51,4 @@ shadowJar {
5151
include(dependency("com.github.JonathanxD:BytecodeDisassembler"))
5252
include(dependency("com.github.JonathanxD:JwIUtils"))
5353
}
54-
}
54+
}
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

src/main/kotlin/com/github/jonathanxd/kores/bytecode/BytecodeClass.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* The MIT License (MIT)
55
*
6-
* Copyright (c) 2018 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <jonathan.scripter@programmer.net>
6+
* Copyright (c) 2021 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <jonathan.scripter@programmer.net>
77
* Copyright (c) contributors
88
*
99
*

src/main/kotlin/com/github/jonathanxd/kores/bytecode/BytecodeModule.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* The MIT License (MIT)
55
*
6-
* Copyright (c) 2018 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <jonathan.scripter@programmer.net>
6+
* Copyright (c) 2021 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <jonathan.scripter@programmer.net>
77
* Copyright (c) contributors
88
*
99
*

src/main/kotlin/com/github/jonathanxd/kores/bytecode/BytecodeOptions.kt

+192-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* The MIT License (MIT)
55
*
6-
* Copyright (c) 2018 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <jonathan.scripter@programmer.net>
6+
* Copyright (c) 2021 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <jonathan.scripter@programmer.net>
77
* Copyright (c) contributors
88
*
99
*
@@ -35,6 +35,9 @@ import com.github.jonathanxd.kores.bytecode.post.GotoOptimizer
3535
import com.github.jonathanxd.kores.bytecode.post.MethodProcessor
3636
import com.github.jonathanxd.kores.bytecode.pre.GenLineVisitor
3737
import com.github.jonathanxd.iutils.option.Option
38+
import com.github.jonathanxd.iutils.option.Options
39+
import com.github.jonathanxd.kores.bytecode.doc.NestLogic
40+
import com.github.jonathanxd.kores.bytecode.doc.IndyConcatLogic
3841

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

121+
/**
122+
* Automatically generate synthetic accessors for private members in private inner classes.
123+
* Synthetic accessors will be only generated for private members which are accessed.
124+
*
125+
* An anonymous synthetic class may be generated for private constructors.
126+
*
127+
* @since 4.0.5.bytecode.5
128+
*/
129+
@JvmField
130+
val FORCE_GENERATE_SYNTHETIC_ACCESS = Option(false)
131+
132+
/**
133+
* When enabled, generate nests declarations as specified in [JEP 181](https://openjdk.java.net/jeps/181),
134+
* enabling this automatically disables [GENERATE_SYNTHETIC_ACCESS].
135+
*
136+
* To have both enabled, use [FORCE_GENERATE_SYNTHETIC_ACCESS]. This is not recommended since
137+
* [Nest-Based Access Control](https://openjdk.java.net/jeps/181) introduces JVM-Level access control
138+
* and removes the need of having bridge methods to access inner classes private members.
139+
*
140+
* @since 4.0.5.bytecode.5
141+
*/
142+
@JvmField
143+
val GENERATE_NESTS = Option(true)
144+
145+
/**
146+
* Force generate [Nests](https://openjdk.java.net/jeps/181) even when emitting bytecode for Java 10 (54) or earlier.
147+
*
148+
* Note that forcing to generate Nests may result in two scenarios:
149+
*
150+
* - Generate Nests info but invoke with **synthetic accessors** when [FORCE_GENERATE_SYNTHETIC_ACCESS] is set.
151+
* - Generate Nests info and access members directly. JVM may not accept this kind of access when running under Java 10 or earlier.
152+
*
153+
* Read more at [GENERATE_NESTS].
154+
*/
155+
@JvmField
156+
val FORCE_GENERATE_NESTS = Option(true)
157+
158+
/**
159+
* Uses `invokedynamic` instruction for string concatenation instead of [StringBuilder].
160+
*
161+
* This option is automatically disabled when emitting bytecode for Java 8 or earlier, to force use [FORCE_INDIFY_STRING_CONCAT].
162+
*
163+
* Read more at [IndyConcatLogic]
164+
*/
165+
@JvmField
166+
val INDIFY_STRING_CONCAT = Option(true)
167+
168+
/**
169+
* Force the use of `invokedynamic` instruction for string concatenation instead of [StringBuilder].
170+
*
171+
* This applies even if the target bytecode version is lower or equal to 52 (Java 8), so the concatenation will
172+
* only work when running under Java 9 or newer.
173+
*
174+
* Read [INDIFY_STRING_CONCAT] for more information.
175+
*/
176+
@JvmField
177+
val FORCE_INDIFY_STRING_CONCAT = Option(false)
178+
179+
/**
180+
* Specifies the strategy to use to generate `invokedynamic` string concatenation, as specified in
181+
* [java.lang.invoke.StringConcatFactory.makeConcatWithConstants].
182+
*
183+
* Read more at [IndyConcatLogic].
184+
*/
185+
@JvmField
186+
val INDY_CONCAT_STRATEGY = Option(IndyConcatStrategy.INTERPOLATE)
187+
188+
enum class IndyConcatStrategy {
189+
/**
190+
* Indify using interpolation, the produced `invokedynamic` instruction interpolates the constants in the
191+
* [recipe][java.lang.invoke.StringConcatFactory.makeConcatWithConstants] argument.
192+
*
193+
* For example, the following concatenation scenario:
194+
*
195+
* ```kotlin
196+
* fun concat(a: String, b: String) =
197+
* a + "<:>" + b
198+
* ```
199+
*
200+
* Is translated into the following recipe:
201+
* ```
202+
* aload 0 // Load a
203+
* aload 1 // Load b
204+
* makeConcatWithConstants<invokedynamic>("\u0001<:>\u0001")
205+
* ```
206+
*
207+
*/
208+
INTERPOLATE,
209+
210+
/**
211+
* Indify providing constants to the [bootstrap method constants parameter][java.lang.invoke.StringConcatFactory.makeConcatWithConstants].
212+
* This results in an interpolation using `\u0001` for arguments in the stack and `\u0002` for constants in the **ConstantPool**.
213+
*
214+
* For example, the following concatenation scenario:
215+
*
216+
* ```kotlin
217+
* fun concat(a: String, b: String) =
218+
* a + "<:>" + b
219+
* ```
220+
*
221+
* Is translated into the following recipe:
222+
* ```
223+
* aload 0 // Load a
224+
* aload 1 // Load b
225+
*
226+
* makeConcatWithConstants<invokedynamic>("\u0001\u0002\u0001", "<:>")
227+
* ```
228+
*
229+
* With `<:>` provided as an argument to the [bootstrap method constants parameter][java.lang.invoke.StringConcatFactory.makeConcatWithConstants].
230+
*/
231+
CONSTANT,
232+
233+
/**
234+
* Indify using only arguments in the stack. Constant values are pushed to the stack using `ldc` instruction.
235+
*
236+
* For example, the following concatenation scenario:
237+
*
238+
* ```kotlin
239+
* fun concat(a: String, b: String) =
240+
* a + "<:>" + b
241+
* ```
242+
*
243+
* Is translated into the following recipe:
244+
* ```
245+
* aload 0 // Load a
246+
* ldc "<:>"
247+
* aload 1 // Load b
248+
* makeConcatWithConstants<invokedynamic>("\u0001\u0001\u0001")
249+
* ```
250+
*/
251+
LDC
252+
}
253+
254+
/**
255+
* Read more in [NestLogic]
256+
*/
257+
fun Options.nestAccessGenerationMode(version: Int) =
258+
when {
259+
this[FORCE_GENERATE_SYNTHETIC_ACCESS] == true && this[GENERATE_NESTS] == true && version >= 55 -> NestAccessGenerationMode.MIXED
260+
this[FORCE_GENERATE_SYNTHETIC_ACCESS] == true && this[FORCE_GENERATE_NESTS] == true -> NestAccessGenerationMode.MIXED
261+
this[FORCE_GENERATE_NESTS] == true -> NestAccessGenerationMode.NEST_BASED
262+
this[GENERATE_NESTS] == true && version >= 55 -> NestAccessGenerationMode.NEST_BASED
263+
this[GENERATE_SYNTHETIC_ACCESS] == true -> NestAccessGenerationMode.SYNTHETIC_ONLY
264+
else -> NestAccessGenerationMode.DISABLED
265+
}
266+
267+
/**
268+
* Read more in [NestLogic]
269+
*/
270+
enum class NestAccessGenerationMode {
271+
/**
272+
* Synthetic and Bridge based inner class private member access.
273+
*/
274+
SYNTHETIC_ONLY,
275+
276+
/**
277+
* Nest-based inner class private member access, as specified in [JEP 181](https://openjdk.java.net/jeps/181).
278+
*/
279+
NEST_BASED,
280+
281+
/**
282+
* Mixed, generate NestHost and NestMember declarations, as specified in [JEP 181](https://openjdk.java.net/jeps/181),
283+
* but use **Synthetic Bridge Methods** for access instead of direct access.
284+
*
285+
* Not recommended since [Nest-Based Access Control](https://openjdk.java.net/jeps/181) allows direct access to private
286+
* members without **bridge methods**. This should only be used in **very very very** specific cases.
287+
*/
288+
MIXED,
289+
290+
/**
291+
* Totally disabled. This may cause **class load-time** and/or **runtime exceptions** in most JVM Implementations
292+
* since classes are not allowed to access private members.
293+
*/
294+
DISABLED
295+
}
296+
297+
/**
298+
* Read more in [NestLogic]
299+
*/
300+
fun NestAccessGenerationMode.isSyntheticAccess() =
301+
this == NestAccessGenerationMode.SYNTHETIC_ONLY || this == NestAccessGenerationMode.MIXED
302+
303+
/**
304+
* Read more in [NestLogic]
305+
*/
306+
fun NestAccessGenerationMode.isToGenerateNests() =
307+
this == NestAccessGenerationMode.MIXED || this == NestAccessGenerationMode.NEST_BASED
308+
118309
enum class VisitLineType {
119310
/**
120311
* Disable line visit

src/main/kotlin/com/github/jonathanxd/kores/bytecode/classloader/CachedCodeClassLoader.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* The MIT License (MIT)
55
*
6-
* Copyright (c) 2018 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <jonathan.scripter@programmer.net>
6+
* Copyright (c) 2021 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <jonathan.scripter@programmer.net>
77
* Copyright (c) contributors
88
*
99
*

src/main/kotlin/com/github/jonathanxd/kores/bytecode/classloader/ClassInject.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* The MIT License (MIT)
55
*
6-
* Copyright (c) 2018 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <jonathan.scripter@programmer.net>
6+
* Copyright (c) 2021 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <jonathan.scripter@programmer.net>
77
* Copyright (c) contributors
88
*
99
*

src/main/kotlin/com/github/jonathanxd/kores/bytecode/classloader/CodeClassLoader.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* The MIT License (MIT)
55
*
6-
* Copyright (c) 2018 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <jonathan.scripter@programmer.net>
6+
* Copyright (c) 2021 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <jonathan.scripter@programmer.net>
77
* Copyright (c) contributors
88
*
99
*

src/main/kotlin/com/github/jonathanxd/kores/bytecode/common/Flow.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* The MIT License (MIT)
55
*
6-
* Copyright (c) 2018 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <jonathan.scripter@programmer.net>
6+
* Copyright (c) 2021 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <jonathan.scripter@programmer.net>
77
* Copyright (c) contributors
88
*
99
*

src/main/kotlin/com/github/jonathanxd/kores/bytecode/common/Frame.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* The MIT License (MIT)
55
*
6-
* Copyright (c) 2018 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <jonathan.scripter@programmer.net>
6+
* Copyright (c) 2021 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <jonathan.scripter@programmer.net>
77
* Copyright (c) contributors
88
*
99
*

src/main/kotlin/com/github/jonathanxd/kores/bytecode/common/MethodVisitorHelper.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* The MIT License (MIT)
55
*
6-
* Copyright (c) 2018 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <jonathan.scripter@programmer.net>
6+
* Copyright (c) 2021 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <jonathan.scripter@programmer.net>
77
* Copyright (c) contributors
88
*
99
*

src/main/kotlin/com/github/jonathanxd/kores/bytecode/common/Timed.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* The MIT License (MIT)
55
*
6-
* Copyright (c) 2018 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <jonathan.scripter@programmer.net>
6+
* Copyright (c) 2021 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <jonathan.scripter@programmer.net>
77
* Copyright (c) contributors
88
*
99
*

src/main/kotlin/com/github/jonathanxd/kores/bytecode/common/Variable.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* The MIT License (MIT)
55
*
6-
* Copyright (c) 2018 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <jonathan.scripter@programmer.net>
6+
* Copyright (c) 2021 TheRealBuggy/JonathanxD (https://github.com/JonathanxD/) <jonathan.scripter@programmer.net>
77
* Copyright (c) contributors
88
*
99
*

0 commit comments

Comments
 (0)