Skip to content

Commit

Permalink
prototype for client/server #21
Browse files Browse the repository at this point in the history
  • Loading branch information
lehvolk committed Jul 19, 2022
1 parent 2c85993 commit e883860
Show file tree
Hide file tree
Showing 96 changed files with 583 additions and 143 deletions.
174 changes: 90 additions & 84 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,109 +23,115 @@ buildscript {
}
}

apply plugin: 'base'
apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: 'maven-publish'
apply plugin: 'org.jetbrains.kotlin.plugin.allopen'
apply plugin: 'org.jetbrains.kotlin.plugin.serialization'
apply plugin: 'org.jetbrains.kotlinx.benchmark'

dependencies {
implementation group: 'io.github.microutils', name: 'kotlin-logging', version: "1.8.3"
implementation group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib-jdk8', version: kotlin_version
implementation group: 'org.jetbrains.kotlin', name: 'kotlin-reflect', version: kotlin_version
implementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-core', version: coroutines_version
implementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-collections-immutable-jvm', version: collections_version
implementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-serialization-cbor', version: '1.3.3'
implementation group: 'org.jetbrains.xodus', name: 'xodus-entity-store', version: xodus_version
implementation group: 'org.ow2.asm', name: 'asm', version: asm_version
implementation group: 'org.ow2.asm', name: 'asm-tree', version: asm_version

testImplementation(platform('org.junit:junit-bom:5.8.2'))
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter'
testImplementation group: 'com.google.guava', name: 'guava', version: '31.1-jre'
testImplementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-benchmark-runtime', version: '0.4.4'
}
subprojects {

group = rootProject.group
version = rootProject.version

apply plugin: 'base'
apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: 'maven-publish'
apply plugin: 'org.jetbrains.kotlin.plugin.allopen'
apply plugin: 'org.jetbrains.kotlin.plugin.serialization'
apply plugin: 'org.jetbrains.kotlinx.benchmark'


publishing {
publications {
jar(MavenPublication) {
from components.java
groupId 'org.utbot'
artifactId project.name
}
}
}

allOpen {
annotation("org.openjdk.jmh.annotations.State")
}
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}

compileKotlin {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
languageVersion = "1.4"
apiVersion = "1.4"
freeCompilerArgs += ["-Xallow-result-return-type", "-Xinline-classes"]
allWarningsAsErrors = false
publishing {
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/UnitTestBot/java-compilation-database")
credentials {
username = project.findProperty("gprUser") ?: System.getenv("USERNAME")
password = project.findProperty("gprKey") ?: System.getenv("TOKEN")
}
}
}
publications {
gpr(MavenPublication) {
from components.java
groupId 'org.utbot'
artifactId project.name
}
}
}
}

compileTestKotlin {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
languageVersion = "1.4"
apiVersion = "1.4"
freeCompilerArgs += ["-Xallow-result-return-type", "-Xinline-classes"]
allWarningsAsErrors = false
dependencies {
testImplementation(platform('org.junit:junit-bom:5.8.2'))
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter'
testImplementation group: 'com.google.guava', name: 'guava', version: '31.1-jre'
testImplementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-benchmark-runtime', version: '0.4.4'
}
}

test {
useJUnitPlatform()
jvmArgs = ['-Xmx2g', '-XX:+HeapDumpOnOutOfMemoryError', '-XX:HeapDumpPath=heapdump.hprof']
testLogging {
events "passed", "skipped", "failed"
allOpen {
annotation("org.openjdk.jmh.annotations.State")
}
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
compileKotlin {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
languageVersion = "1.4"
apiVersion = "1.4"
freeCompilerArgs += ["-Xallow-result-return-type", "-Xinline-classes"]
allWarningsAsErrors = false
}
}

publishing {
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/UnitTestBot/java-compilation-database")
credentials {
username = project.findProperty("gprUser") ?: System.getenv("USERNAME")
password = project.findProperty("gprKey") ?: System.getenv("TOKEN")
}
compileTestKotlin {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
languageVersion = "1.4"
apiVersion = "1.4"
freeCompilerArgs += ["-Xallow-result-return-type", "-Xinline-classes"]
allWarningsAsErrors = false
}
}
publications {
gpr(MavenPublication) {
from components.java
groupId 'org.utbot'
artifactId project.name

test {
useJUnitPlatform()
jvmArgs = ['-Xmx2g', '-XX:+HeapDumpOnOutOfMemoryError', '-XX:HeapDumpPath=heapdump.hprof']
testLogging {
events "passed", "skipped", "failed"
}
}
}

repositories {
repositories {
mavenCentral()
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}


// Configure benchmark
benchmark {
configurations {
main { // main configuration is created automatically, but you can change its defaults
warmups = 3 // number of warmup iterations
iterations = 5 // number of iterations
benchmark {
configurations {
main { // main configuration is created automatically, but you can change its defaults
warmups = 3 // number of warmup iterations
iterations = 5 // number of iterations
}
}
}

// Setup configurations
targets {
// This one matches sourceSet name above
register("test") {
jmhVersion = "1.21"
// Setup configurations
targets {
// This one matches sourceSet name above
register("test") {
jmhVersion = "1.21"
}
}
}
}
}
16 changes: 16 additions & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
dependencies {
implementation group: 'io.github.microutils', name: 'kotlin-logging', version: "1.8.3"
implementation group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib-jdk8', version: kotlin_version
implementation group: 'org.jetbrains.kotlin', name: 'kotlin-reflect', version: kotlin_version
implementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-core', version: coroutines_version
implementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-collections-immutable-jvm', version: collections_version
implementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-serialization-cbor', version: '1.3.3'
implementation group: 'org.jetbrains.xodus', name: 'xodus-entity-store', version: xodus_version
implementation group: 'org.ow2.asm', name: 'asm', version: asm_version
implementation group: 'org.ow2.asm', name: 'asm-tree', version: asm_version

testImplementation(platform('org.junit:junit-bom:5.8.2'))
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter'
testImplementation group: 'com.google.guava', name: 'guava', version: '31.1-jre'
testImplementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-benchmark-runtime', version: '0.4.4'
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ suspend fun compilationDatabase(builder: CompilationDatabaseSettings.() -> Unit)
)
database.restoreDataFrom(restoredLocations.toMap())
database.loadLocations(notLoaded.toList())
database.afterStart()
return database
}
}
Expand All @@ -38,6 +39,7 @@ suspend fun compilationDatabase(builder: CompilationDatabaseSettings.() -> Unit)
if (settings.watchFileSystemChanges != null) {
database.watchFileSystemChanges()
}
database.afterStart()
return database
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.utbot.jcdb

import org.utbot.jcdb.api.Feature
import org.utbot.jcdb.api.Hook
import org.utbot.jcdb.impl.CompilationDatabaseImpl
import org.utbot.jcdb.impl.index.Hierarchy
import java.io.File

Expand All @@ -17,6 +19,8 @@ class CompilationDatabaseSettings {
/** jar files which should be loaded right after database is created */
var predefinedDirOrJars: List<File> = emptyList()

var hooks: MutableList<(CompilationDatabaseImpl) -> Hook> = arrayListOf()

/** mandatory setting for java location */
lateinit var jre: File

Expand All @@ -35,6 +39,11 @@ class CompilationDatabaseSettings {
watchFileSystemChanges = CompilationDatabaseWatchFileSystemSettings().also(settings)
}

/** builder for hooks */
fun withHook(hook: (CompilationDatabaseImpl) -> Hook) {
hooks += hook
}

/**
* use java from JAVA_HOME env variable
*/
Expand Down
File renamed without changes.
8 changes: 8 additions & 0 deletions core/src/main/kotlin/org/utbot/jcdb/api/Hook.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.utbot.jcdb.api

interface Hook {

fun afterStart()

fun afterStop() {}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class CompilationDatabaseImpl(

private val classTree = ClassTree()
internal val javaRuntime = JavaRuntime(settings.jre)
private val hooks = settings.hooks.map { it(this) }

internal val featureRegistry = FeaturesRegistry(persistentEnvironment, settings.fullFeatures)
internal val locationsRegistry = LocationsRegistry(featureRegistry)
Expand Down Expand Up @@ -152,6 +153,10 @@ class CompilationDatabaseImpl(
backgroundJobs.values.toList().joinAll()
}

fun afterStart() {
hooks.forEach { it.afterStart() }
}

override fun close() {
isClosed.set(true)
locationsRegistry.close()
Expand All @@ -160,6 +165,7 @@ class CompilationDatabaseImpl(
}
backgroundJobs.clear()
persistentEnvironment?.close()
hooks.forEach { it.afterStop() }
}

private fun assertNotClosed() {
Expand Down
64 changes: 64 additions & 0 deletions core/src/main/kotlin/org/utbot/jcdb/impl/fs/ByteCodeConverter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.utbot.jcdb.impl.fs

import kotlinx.collections.immutable.toImmutableList
import org.objectweb.asm.Type
import org.objectweb.asm.tree.AnnotationNode
import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.FieldNode
import org.objectweb.asm.tree.MethodNode
import org.utbot.jcdb.impl.types.*

interface ByteCodeConverter {

fun ClassNode.asClassInfo() = ClassInfo(
name = Type.getObjectType(name).className,
signature = signature,
access = access,

outerClass = outerClassName(),
innerClasses = innerClasses.map {
Type.getObjectType(it.name).className
}.toImmutableList(),
outerMethod = outerMethod,
outerMethodDesc = outerMethodDesc,
superClass = superName?.let { Type.getObjectType(it).className },
interfaces = interfaces.map { Type.getObjectType(it).className }.toImmutableList(),
methods = methods.map { it.asMethodInfo() }.toImmutableList(),
fields = fields.map { it.asFieldInfo() }.toImmutableList(),
annotations = visibleAnnotations.orEmpty().map { it.asAnnotationInfo() }.toImmutableList()
)

private fun ClassNode.outerClassName(): OuterClassRef? {
val innerRef = innerClasses.firstOrNull { it.name == name }

val direct = outerClass?.let { Type.getObjectType(it).className }
if (direct == null && innerRef != null) {
return OuterClassRef(Type.getObjectType(innerRef.outerName).className, innerRef.innerName)
}
return direct?.let {
OuterClassRef(it, innerRef?.innerName)
}
}

private fun AnnotationNode.asAnnotationInfo() = AnnotationInfo(
className = Type.getType(desc).className
)

private fun MethodNode.asMethodInfo() = MethodInfo(
name = name,
signature = signature,
desc = desc,
access = access,
returnType = Type.getReturnType(desc).className,
parameters = Type.getArgumentTypes(desc).map { it.className }.toImmutableList(),
annotations = visibleAnnotations.orEmpty().map { it.asAnnotationInfo() }.toImmutableList()
)

private fun FieldNode.asFieldInfo() = FieldInfo(
name = name,
signature = signature,
access = access,
type = Type.getType(desc).className,
annotations = visibleAnnotations.orEmpty().map { it.asAnnotationInfo() }.toImmutableList()
)
}
Loading

0 comments on commit e883860

Please sign in to comment.