JVM_IR disable IR and bytecode validation by default
This commit is contained in:
committed by
TeamCityServer
parent
1a40164ef0
commit
ebf837c135
@@ -17,11 +17,13 @@
|
|||||||
package org.jetbrains.kotlin.codegen.optimization
|
package org.jetbrains.kotlin.codegen.optimization
|
||||||
|
|
||||||
import org.jetbrains.kotlin.codegen.optimization.transformer.MethodTransformer
|
import org.jetbrains.kotlin.codegen.optimization.transformer.MethodTransformer
|
||||||
|
import org.jetbrains.kotlin.codegen.state.GenerationState
|
||||||
import org.jetbrains.org.objectweb.asm.tree.MethodNode
|
import org.jetbrains.org.objectweb.asm.tree.MethodNode
|
||||||
import org.jetbrains.org.objectweb.asm.tree.analysis.BasicVerifier
|
import org.jetbrains.org.objectweb.asm.tree.analysis.BasicVerifier
|
||||||
|
|
||||||
class MethodVerifier(private val checkPoint: String) : MethodTransformer() {
|
class MethodVerifier(private val checkPoint: String, private val generationState: GenerationState) : MethodTransformer() {
|
||||||
override fun transform(internalClassName: String, methodNode: MethodNode) {
|
override fun transform(internalClassName: String, methodNode: MethodNode) {
|
||||||
|
if (!generationState.shouldValidateBytecode) return
|
||||||
try {
|
try {
|
||||||
analyze(internalClassName, methodNode, BasicVerifier())
|
analyze(internalClassName, methodNode, BasicVerifier())
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
|
|||||||
+2
-2
@@ -41,7 +41,7 @@ class OptimizationMethodVisitor(
|
|||||||
|
|
||||||
val normalizationMethodTransformer = CompositeMethodTransformer(
|
val normalizationMethodTransformer = CompositeMethodTransformer(
|
||||||
FixStackWithLabelNormalizationMethodTransformer(),
|
FixStackWithLabelNormalizationMethodTransformer(),
|
||||||
MethodVerifier("AFTER mandatory stack transformations")
|
MethodVerifier("AFTER mandatory stack transformations", generationState)
|
||||||
)
|
)
|
||||||
|
|
||||||
val optimizationTransformer = CompositeMethodTransformer(
|
val optimizationTransformer = CompositeMethodTransformer(
|
||||||
@@ -55,7 +55,7 @@ class OptimizationMethodVisitor(
|
|||||||
DeadCodeEliminationMethodTransformer(),
|
DeadCodeEliminationMethodTransformer(),
|
||||||
RedundantGotoMethodTransformer(),
|
RedundantGotoMethodTransformer(),
|
||||||
RedundantNopsCleanupMethodTransformer(),
|
RedundantNopsCleanupMethodTransformer(),
|
||||||
MethodVerifier("AFTER optimizations")
|
MethodVerifier("AFTER optimizations", generationState)
|
||||||
)
|
)
|
||||||
|
|
||||||
override fun performTransformations(methodNode: MethodNode) {
|
override fun performTransformations(methodNode: MethodNode) {
|
||||||
|
|||||||
@@ -299,6 +299,8 @@ class GenerationState private constructor(
|
|||||||
!configuration.getBoolean(JVMConfigurationKeys.NO_UNIFIED_NULL_CHECKS)
|
!configuration.getBoolean(JVMConfigurationKeys.NO_UNIFIED_NULL_CHECKS)
|
||||||
val functionsWithInlineClassReturnTypesMangled: Boolean =
|
val functionsWithInlineClassReturnTypesMangled: Boolean =
|
||||||
languageVersionSettings.supportsFeature(LanguageFeature.MangleClassMembersReturningInlineClasses)
|
languageVersionSettings.supportsFeature(LanguageFeature.MangleClassMembersReturningInlineClasses)
|
||||||
|
val shouldValidateIr = configuration.getBoolean(JVMConfigurationKeys.VALIDATE_IR)
|
||||||
|
val shouldValidateBytecode = configuration.getBoolean(JVMConfigurationKeys.VALIDATE_BYTECODE)
|
||||||
|
|
||||||
val rootContext: CodegenContext<*> = RootContext(this)
|
val rootContext: CodegenContext<*> = RootContext(this)
|
||||||
|
|
||||||
|
|||||||
+12
@@ -511,6 +511,18 @@ default: `indy-with-constants` for JVM target 9 or greater, `inline` otherwise""
|
|||||||
)
|
)
|
||||||
var serializeIr: Boolean by FreezableVar(false)
|
var serializeIr: Boolean by FreezableVar(false)
|
||||||
|
|
||||||
|
@Argument(
|
||||||
|
value = "-Xvalidate-ir",
|
||||||
|
description = "Validate IR before and after lowering"
|
||||||
|
)
|
||||||
|
var validateIr: Boolean by FreezableVar(false)
|
||||||
|
|
||||||
|
@Argument(
|
||||||
|
value = "-Xvalidate-bytecode",
|
||||||
|
description = "Validate generated JVM bytecode before and after optimizations"
|
||||||
|
)
|
||||||
|
var validateBytecode: Boolean by FreezableVar(false)
|
||||||
|
|
||||||
override fun configureAnalysisFlags(collector: MessageCollector, languageVersion: LanguageVersion): MutableMap<AnalysisFlag<*>, Any> {
|
override fun configureAnalysisFlags(collector: MessageCollector, languageVersion: LanguageVersion): MutableMap<AnalysisFlag<*>, Any> {
|
||||||
val result = super.configureAnalysisFlags(collector, languageVersion)
|
val result = super.configureAnalysisFlags(collector, languageVersion)
|
||||||
result[JvmAnalysisFlags.strictMetadataVersionSemantics] = strictMetadataVersionSemantics
|
result[JvmAnalysisFlags.strictMetadataVersionSemantics] = strictMetadataVersionSemantics
|
||||||
|
|||||||
@@ -254,6 +254,9 @@ fun CompilerConfiguration.configureAdvancedJvmOptions(arguments: K2JVMCompilerAr
|
|||||||
|
|
||||||
put(JVMConfigurationKeys.SERIALIZE_IR, arguments.serializeIr)
|
put(JVMConfigurationKeys.SERIALIZE_IR, arguments.serializeIr)
|
||||||
|
|
||||||
|
put(JVMConfigurationKeys.VALIDATE_IR, arguments.validateIr)
|
||||||
|
put(JVMConfigurationKeys.VALIDATE_BYTECODE, arguments.validateBytecode)
|
||||||
|
|
||||||
if (!JVMConstructorCallNormalizationMode.isSupportedValue(arguments.constructorCallNormalizationMode)) {
|
if (!JVMConstructorCallNormalizationMode.isSupportedValue(arguments.constructorCallNormalizationMode)) {
|
||||||
messageCollector.report(
|
messageCollector.report(
|
||||||
ERROR,
|
ERROR,
|
||||||
|
|||||||
@@ -157,5 +157,11 @@ public class JVMConfigurationKeys {
|
|||||||
CompilerConfigurationKey.create("Don't automatically include kotlin-reflect.jar into the output if the output is a jar");
|
CompilerConfigurationKey.create("Don't automatically include kotlin-reflect.jar into the output if the output is a jar");
|
||||||
|
|
||||||
public static final CompilerConfigurationKey<Boolean> SERIALIZE_IR =
|
public static final CompilerConfigurationKey<Boolean> SERIALIZE_IR =
|
||||||
CompilerConfigurationKey.create("serialize IR to class metadata");
|
CompilerConfigurationKey.create("Serialize IR to class metadata");
|
||||||
|
|
||||||
|
public static final CompilerConfigurationKey<Boolean> VALIDATE_IR =
|
||||||
|
CompilerConfigurationKey.create("Validate IR");
|
||||||
|
|
||||||
|
public static final CompilerConfigurationKey<Boolean> VALIDATE_BYTECODE =
|
||||||
|
CompilerConfigurationKey.create("Validate generated JVM bytecode");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,14 +41,14 @@ private class PatchDeclarationParents : FileLoweringPass {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val validateIrBeforeLowering = makeCustomPhase<JvmBackendContext, IrModuleFragment>(
|
private val validateIrBeforeLowering = makeCustomPhase(
|
||||||
{ context, module -> validationCallback(context, module, checkProperties = true) },
|
::validateIr,
|
||||||
name = "ValidateIrBeforeLowering",
|
name = "ValidateIrBeforeLowering",
|
||||||
description = "Validate IR before lowering"
|
description = "Validate IR before lowering"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val validateIrAfterLowering = makeCustomPhase<JvmBackendContext, IrModuleFragment>(
|
private val validateIrAfterLowering = makeCustomPhase(
|
||||||
{ context, module -> validationCallback(context, module, checkProperties = true) },
|
::validateIr,
|
||||||
name = "ValidateIrAfterLowering",
|
name = "ValidateIrAfterLowering",
|
||||||
description = "Validate IR after lowering"
|
description = "Validate IR after lowering"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.backend.jvm.lower
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.backend.common.phaser.validationCallback
|
||||||
|
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||||
|
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||||
|
|
||||||
|
fun validateIr(context: JvmBackendContext, module: IrModuleFragment) {
|
||||||
|
if (!context.state.shouldValidateIr) return
|
||||||
|
validationCallback(context, module, checkProperties = true)
|
||||||
|
}
|
||||||
+2
@@ -146,6 +146,8 @@ where advanced options include:
|
|||||||
-Xuse-old-spilled-var-type-analysis
|
-Xuse-old-spilled-var-type-analysis
|
||||||
Use old, SourceInterpreter-based analysis for fields, used for spilled variables in coroutines
|
Use old, SourceInterpreter-based analysis for fields, used for spilled variables in coroutines
|
||||||
-Xuse-type-table Use type table in metadata serialization
|
-Xuse-type-table Use type table in metadata serialization
|
||||||
|
-Xvalidate-bytecode Validate generated JVM bytecode before and after optimizations
|
||||||
|
-Xvalidate-ir Validate IR before and after lowering
|
||||||
-Xallow-kotlin-package Allow compiling code in package 'kotlin' and allow not requiring kotlin.stdlib in module-info
|
-Xallow-kotlin-package Allow compiling code in package 'kotlin' and allow not requiring kotlin.stdlib in module-info
|
||||||
-Xallow-result-return-type Allow compiling code when `kotlin.Result` is used as a return type
|
-Xallow-result-return-type Allow compiling code when `kotlin.Result` is used as a return type
|
||||||
-Xbuiltins-from-sources Compile builtIns from sources
|
-Xbuiltins-from-sources Compile builtIns from sources
|
||||||
|
|||||||
+3
@@ -255,6 +255,9 @@ class JvmEnvironmentConfigurator(testServices: TestServices) : EnvironmentConfig
|
|||||||
if (CodegenTestDirectives.DUMP_IR_FOR_GIVEN_PHASES in module.directives) {
|
if (CodegenTestDirectives.DUMP_IR_FOR_GIVEN_PHASES in module.directives) {
|
||||||
configuration.putCustomPhaseConfigWithEnabledDump(module)
|
configuration.putCustomPhaseConfigWithEnabledDump(module)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
configuration.put(JVMConfigurationKeys.VALIDATE_IR, true)
|
||||||
|
configuration.put(JVMConfigurationKeys.VALIDATE_BYTECODE, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addJavaSourceRootsByJavaModules(configuration: CompilerConfiguration, moduleInfoFiles: List<TestFile>) {
|
private fun addJavaSourceRootsByJavaModules(configuration: CompilerConfiguration, moduleInfoFiles: List<TestFile>) {
|
||||||
|
|||||||
Reference in New Issue
Block a user