mirror of
https://github.com/corda/corda.git
synced 2024-12-29 17:28:56 +00:00
CORDA-2877: Load bytecode from a persistent cache to prevent repeated rewriting. (#75)
* Load bytecode from a persistent cache to prevent repeated rewriting. * Refactor byte-code cache to SandboxConfiguration instead of AnalysisConfiguration. We cannot "mix and match" byte-code generated by different sets of rules.
This commit is contained in:
parent
d604308563
commit
ed23c4b998
@ -4,16 +4,12 @@ import net.corda.core.serialization.ConstructorForDeserialization
|
||||
import net.corda.core.serialization.CordaSerializable
|
||||
import net.corda.core.serialization.DeprecatedConstructorForDeserialization
|
||||
import net.corda.djvm.SandboxConfiguration
|
||||
import net.corda.djvm.SandboxConfiguration.Companion.ALL_DEFINITION_PROVIDERS
|
||||
import net.corda.djvm.SandboxConfiguration.Companion.ALL_EMITTERS
|
||||
import net.corda.djvm.SandboxConfiguration.Companion.ALL_RULES
|
||||
import net.corda.djvm.SandboxRuntimeContext
|
||||
import net.corda.djvm.analysis.AnalysisConfiguration
|
||||
import net.corda.djvm.analysis.Whitelist.Companion.MINIMAL
|
||||
import net.corda.djvm.execution.ExecutionProfile.*
|
||||
import net.corda.djvm.messages.Severity
|
||||
import net.corda.djvm.messages.Severity.*
|
||||
import net.corda.djvm.rewiring.SandboxClassLoader
|
||||
import net.corda.djvm.source.BootstrapClassLoader
|
||||
import net.corda.djvm.source.UserPathSource
|
||||
import org.junit.jupiter.api.AfterAll
|
||||
@ -40,8 +36,7 @@ abstract class TestBase(type: SandboxType) {
|
||||
.split(File.pathSeparator).map { Paths.get(it) }.filter { exists(it) }
|
||||
|
||||
private lateinit var bootstrapClassLoader: BootstrapClassLoader
|
||||
private lateinit var configuration: SandboxConfiguration
|
||||
private lateinit var parentClassLoader: SandboxClassLoader
|
||||
private lateinit var parentConfiguration: SandboxConfiguration
|
||||
|
||||
@BeforeAll
|
||||
@JvmStatic
|
||||
@ -57,15 +52,11 @@ abstract class TestBase(type: SandboxType) {
|
||||
),
|
||||
bootstrapSource = bootstrapClassLoader
|
||||
)
|
||||
configuration = SandboxConfiguration.of(
|
||||
UNLIMITED,
|
||||
ALL_RULES,
|
||||
ALL_EMITTERS,
|
||||
ALL_DEFINITION_PROVIDERS,
|
||||
true,
|
||||
rootConfiguration
|
||||
parentConfiguration = SandboxConfiguration.createFor(
|
||||
analysisConfiguration = rootConfiguration,
|
||||
profile = UNLIMITED,
|
||||
enableTracing = false
|
||||
)
|
||||
parentClassLoader = SandboxClassLoader.createFor(configuration)
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
@ -81,42 +72,32 @@ abstract class TestBase(type: SandboxType) {
|
||||
}
|
||||
|
||||
fun sandbox(action: SandboxRuntimeContext.() -> Unit) {
|
||||
return sandbox(WARNING, emptySet(), emptySet(), false, action)
|
||||
return sandbox(WARNING, emptySet(), emptySet(), action)
|
||||
}
|
||||
|
||||
fun sandbox(visibleAnnotations: Set<Class<out Annotation>>, action: SandboxRuntimeContext.() -> Unit) {
|
||||
return sandbox(WARNING, visibleAnnotations, emptySet(), false, action)
|
||||
return sandbox(WARNING, visibleAnnotations, emptySet(), action)
|
||||
}
|
||||
|
||||
fun sandbox(visibleAnnotations: Set<Class<out Annotation>>, sandboxOnlyAnnotations: Set<String>, action: SandboxRuntimeContext.() -> Unit) {
|
||||
return sandbox(WARNING, visibleAnnotations, sandboxOnlyAnnotations, false, action)
|
||||
return sandbox(WARNING, visibleAnnotations, sandboxOnlyAnnotations, action)
|
||||
}
|
||||
|
||||
fun sandbox(
|
||||
minimumSeverityLevel: Severity,
|
||||
visibleAnnotations: Set<Class<out Annotation>>,
|
||||
sandboxOnlyAnnotations: Set<String>,
|
||||
enableTracing: Boolean,
|
||||
action: SandboxRuntimeContext.() -> Unit
|
||||
) {
|
||||
var thrownException: Throwable? = null
|
||||
thread {
|
||||
try {
|
||||
UserPathSource(classPaths).use { userSource ->
|
||||
val analysisConfiguration = configuration.analysisConfiguration.createChild(
|
||||
SandboxRuntimeContext(parentConfiguration.createChild(
|
||||
userSource = userSource,
|
||||
newMinimumSeverityLevel = minimumSeverityLevel,
|
||||
visibleAnnotations = visibleAnnotations,
|
||||
sandboxOnlyAnnotations = sandboxOnlyAnnotations
|
||||
)
|
||||
SandboxRuntimeContext(SandboxConfiguration.of(
|
||||
configuration.executionProfile,
|
||||
configuration.rules,
|
||||
configuration.emitters,
|
||||
configuration.definitionProviders,
|
||||
enableTracing,
|
||||
analysisConfiguration,
|
||||
parentClassLoader
|
||||
)).use {
|
||||
action(this)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user