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
|
||||
|
||||
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.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) {
|
||||
if (!generationState.shouldValidateBytecode) return
|
||||
try {
|
||||
analyze(internalClassName, methodNode, BasicVerifier())
|
||||
} catch (e: Throwable) {
|
||||
|
||||
+2
-2
@@ -41,7 +41,7 @@ class OptimizationMethodVisitor(
|
||||
|
||||
val normalizationMethodTransformer = CompositeMethodTransformer(
|
||||
FixStackWithLabelNormalizationMethodTransformer(),
|
||||
MethodVerifier("AFTER mandatory stack transformations")
|
||||
MethodVerifier("AFTER mandatory stack transformations", generationState)
|
||||
)
|
||||
|
||||
val optimizationTransformer = CompositeMethodTransformer(
|
||||
@@ -55,7 +55,7 @@ class OptimizationMethodVisitor(
|
||||
DeadCodeEliminationMethodTransformer(),
|
||||
RedundantGotoMethodTransformer(),
|
||||
RedundantNopsCleanupMethodTransformer(),
|
||||
MethodVerifier("AFTER optimizations")
|
||||
MethodVerifier("AFTER optimizations", generationState)
|
||||
)
|
||||
|
||||
override fun performTransformations(methodNode: MethodNode) {
|
||||
|
||||
@@ -299,6 +299,8 @@ class GenerationState private constructor(
|
||||
!configuration.getBoolean(JVMConfigurationKeys.NO_UNIFIED_NULL_CHECKS)
|
||||
val functionsWithInlineClassReturnTypesMangled: Boolean =
|
||||
languageVersionSettings.supportsFeature(LanguageFeature.MangleClassMembersReturningInlineClasses)
|
||||
val shouldValidateIr = configuration.getBoolean(JVMConfigurationKeys.VALIDATE_IR)
|
||||
val shouldValidateBytecode = configuration.getBoolean(JVMConfigurationKeys.VALIDATE_BYTECODE)
|
||||
|
||||
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)
|
||||
|
||||
@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> {
|
||||
val result = super.configureAnalysisFlags(collector, languageVersion)
|
||||
result[JvmAnalysisFlags.strictMetadataVersionSemantics] = strictMetadataVersionSemantics
|
||||
|
||||
@@ -254,6 +254,9 @@ fun CompilerConfiguration.configureAdvancedJvmOptions(arguments: K2JVMCompilerAr
|
||||
|
||||
put(JVMConfigurationKeys.SERIALIZE_IR, arguments.serializeIr)
|
||||
|
||||
put(JVMConfigurationKeys.VALIDATE_IR, arguments.validateIr)
|
||||
put(JVMConfigurationKeys.VALIDATE_BYTECODE, arguments.validateBytecode)
|
||||
|
||||
if (!JVMConstructorCallNormalizationMode.isSupportedValue(arguments.constructorCallNormalizationMode)) {
|
||||
messageCollector.report(
|
||||
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");
|
||||
|
||||
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>(
|
||||
{ context, module -> validationCallback(context, module, checkProperties = true) },
|
||||
private val validateIrBeforeLowering = makeCustomPhase(
|
||||
::validateIr,
|
||||
name = "ValidateIrBeforeLowering",
|
||||
description = "Validate IR before lowering"
|
||||
)
|
||||
|
||||
private val validateIrAfterLowering = makeCustomPhase<JvmBackendContext, IrModuleFragment>(
|
||||
{ context, module -> validationCallback(context, module, checkProperties = true) },
|
||||
private val validateIrAfterLowering = makeCustomPhase(
|
||||
::validateIr,
|
||||
name = "ValidateIrAfterLowering",
|
||||
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
|
||||
Use old, SourceInterpreter-based analysis for fields, used for spilled variables in coroutines
|
||||
-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-result-return-type Allow compiling code when `kotlin.Result` is used as a return type
|
||||
-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) {
|
||||
configuration.putCustomPhaseConfigWithEnabledDump(module)
|
||||
}
|
||||
|
||||
configuration.put(JVMConfigurationKeys.VALIDATE_IR, true)
|
||||
configuration.put(JVMConfigurationKeys.VALIDATE_BYTECODE, true)
|
||||
}
|
||||
|
||||
private fun addJavaSourceRootsByJavaModules(configuration: CompilerConfiguration, moduleInfoFiles: List<TestFile>) {
|
||||
|
||||
Reference in New Issue
Block a user