Code Monkey home page Code Monkey logo

jacodb's People

Contributors

abdullinam avatar caelmbleidd avatar daniilstepanov avatar dvvrd avatar github-actions[bot] avatar lehvolk avatar lipen avatar olganaumenko avatar saloed avatar sergeypospelov avatar vassiliy-kudryashov avatar volivan239 avatar yalehvolk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

jacodb's Issues

Implement remote client

Idea is to run jcdb in a separate process and be able to communicate with this instance from another process on a localhost

  • remote database interface
  • classpath: common methods: close etc
  • classpath: findClasses
  • classpath: call indexes

Design and implement features for JcClasspath

Add ability to implement additional features for JcClasspath. This brings clear ability to:

  • cache classes
  • transform instructions list
  • add virtual classes, methods, fields which are absent in current classpath

To think about: there is possibility that JcUnknownType could be implemented and used by this feature

Investigate local tests failing

Symptoms @volivan239:

  • java tests passes
  • all kotlin tests failed with
Caused by: org.sqlite.SQLiteException: [SQLITE_ERROR] SQL error or missing database (incomplete input)
	at org.sqlite.core.DB.newSQLException(DB.java:1135)
	at org.sqlite.core.DB.newSQLException(DB.java:1146)
	at org.sqlite.core.DB.throwex(DB.java:1106)
	at org.sqlite.core.NativeDB.prepare_utf8(Native Method)
	at org.sqlite.core.NativeDB.prepare(NativeDB.java:117)
	at org.sqlite.core.DB.prepare(DB.java:264)
	at org.sqlite.core.CorePreparedStatement.<init>(CorePreparedStatement.java:45)
	at org.sqlite.jdbc3.JDBC3PreparedStatement.<init>(JDBC3PreparedStatement.java:30)
	at org.sqlite.jdbc4.JDBC4PreparedStatement.<init>(JDBC4PreparedStatement.java:25)
	at org.sqlite.jdbc4.JDBC4Connection.prepareStatement(JDBC4Connection.java:34)
	at org.sqlite.jdbc3.JDBC3Connection.prepareStatement(JDBC3Connection.java:155)
	at org.sqlite.jdbc3.JDBC3Connection.prepareStatement(JDBC3Connection.java:135)
	at org.sqlite.jdbc3.JDBC3Connection.prepareStatement(JDBC3Connection.java:140)
	at org.utbot.jcdb.impl.storage.JooqKt.insertElements(Jooq.kt:33)
	at org.utbot.jcdb.impl.storage.PersistentLocationRegistry$registerIfNeeded$1.invoke$lambda$4(PersistentLocationRegistry.kt:86)
	at org.jooq.impl.DefaultDSLContext$4.run(DefaultDSLContext.java:683)
	at org.jooq.impl.DefaultDSLContext$4.run(DefaultDSLContext.java:680)
	at org.jooq.impl.DefaultDSLContext.connectionResult(DefaultDSLContext.java:662)
	... 107 more

Kotlin tests are green if run separately.

JcGraphs is broken for Java 1.6 compiled code

As an example one could take one of:

  • java.mail jar
  • javax.activation jar
    and tried to build graphs based on this classes

There are two cases which were not covered:

  • instructions which predecessors have no entry point this frames for them are not computed
  • instructions which predecessors may be after current instruction and as a result have no calculated frames at current moment

Deploy to maven central

  • retrieve credentials for deployment
  • make a separate gradle task for deployment (skip jacodb-http module)
  • create deployment action

JcApplicationGraphImpl.callers() throws "not found" exception when used on standard library

Calling JcApplicationGraphImpl.callers() for some standard java methods leads to different not found exceptions. For example,

@Test
fun `analyse something`() = runBlocking {
    val graph = JcApplicationGraphImpl(cp, cp.usagesExt())
    val callers = graph.callers(cp.findClass<java.util.StringTokenizer>().constructors[2])
    println(callers.toList().size)
}

throws the following exception:

java.lang.IllegalStateException: com.sun.org.apache.xalan.internal.xsltc.compiler.Output#DUP not found
	at org.jacodb.impl.cfg.JcGraphBuilder.visitJcRawFieldRef(JcGraphBuilder.kt:503)
	at org.jacodb.impl.cfg.JcGraphBuilder.visitJcRawFieldRef(JcGraphBuilder.kt:176)
	at org.jacodb.api.cfg.JcRawFieldRef.accept(JcRawInst.kt:832)
	at org.jacodb.impl.cfg.JcGraphBuilder.visitJcRawAssignInst(JcGraphBuilder.kt:237)

Environment

  • SDK: Corretto 11.0.16

Take care of exception

IRTest:

10:21:40.334 [Test worker] WARN org.utbot.jacodb.impl.types.signature.MethodSignature - Can't parse signature '<X:Ljava/lang/Throwable;>(Ljava/lang/Throwable;Ljava/lang/Class<TX;>;)V^TX;' of field org.utbot.jacodb.impl.bytecode.JcMethodImpl@3e57d454
java.lang.ClassCastException: class org.utbot.jacodb.impl.types.signature.JvmTypeVariable cannot be cast to class org.utbot.jacodb.impl.types.signature.JvmClassRefType (org.utbot.jacodb.impl.types.signature.JvmTypeVariable and org.utbot.jacodb.impl.types.signature.JvmClassRefType are in unnamed module of loader 'app')
	at org.utbot.jacodb.impl.types.signature.MethodSignature$ExceptionTypeRegistrant.register(MethodSignature.kt:81)
	at org.utbot.jacodb.impl.types.signature.TypeExtractor.visitTypeVariable(TypeExtractor.kt:36)
	at org.objectweb.asm.signature.SignatureReader.parseType(SignatureReader.java:178)
	at org.objectweb.asm.signature.SignatureReader.accept(SignatureReader.java:117)
	at org.utbot.jacodb.impl.types.signature.Signature$Companion.of(Signature.kt:68)
	at org.utbot.jacodb.impl.types.signature.MethodSignature$Companion.withDeclarations(MethodSignature.kt:108)
	at org.utbot.jacodb.impl.types.JcTypedMethodImpl$info$2.invoke(JcTypedMethodImpl.kt:65)
	at org.utbot.jacodb.impl.types.JcTypedMethodImpl$info$2.invoke(JcTypedMethodImpl.kt:54)
	at kotlin.UnsafeLazyImpl.getValue(Lazy.kt:81)
	at org.utbot.jacodb.impl.types.JcTypedMethodImpl.getInfo(JcTypedMethodImpl.kt:54)
	at org.utbot.jacodb.impl.types.JcTypedMethodImpl.getExceptions(JcTypedMethodImpl.kt:80)
	at org.utbot.jacodb.impl.cfg.JcExceptionResolver.visitJcStaticCallExpr(GraphExt.kt:397)
	at org.utbot.jacodb.impl.cfg.JcExceptionResolver.visitJcStaticCallExpr(GraphExt.kt:224)
	at org.utbot.jacodb.api.cfg.JcStaticCallExpr.accept(JcInst.kt:693)
	at org.utbot.jacodb.impl.cfg.JcExceptionResolver.visitJcCallInst(GraphExt.kt:241)
	at org.utbot.jacodb.impl.cfg.JcExceptionResolver.visitJcCallInst(GraphExt.kt:224)
	at org.utbot.jacodb.api.cfg.JcCallInst.accept(JcInst.kt:89)
	at org.utbot.jacodb.impl.cfg.JcGraphImpl.<init>(JcGraphImpl.kt:74)
	at org.utbot.jacodb.impl.cfg.JcGraphBuilder.build(JcGraphBuilder.kt:43)
	at org.utbot.jacodb.impl.cfg.JcRawInstListImpl.graph(JcRawInstListImpl.kt:71)
	at org.utbot.jacodb.api.JcMethod.flowGraph(Classes.kt:73)
	at org.utbot.jacodb.impl.cfg.IRTest.testClass(IRTest.kt:366)
	at org.utbot.jacodb.impl.cfg.IRTest.runAlongLib(IRTest.kt:348)
	at org.utbot.jacodb.impl.cfg.IRTest.get ir of guava(IRTest.kt:333)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:727)
	at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
	at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:156)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:147)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:86)
	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(InterceptingExecutableInvoker.java:103)
	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.lambda$invoke$0(InterceptingExecutableInvoker.java:93)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:92)
	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:86)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:217)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:213)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:138)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:68)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:108)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:96)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:75)
	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:99)
	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$000(JUnitPlatformTestClassProcessor.java:79)
	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:75)
	at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
	at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
	at com.sun.proxy.$Proxy2.stop(Unknown Source)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker$3.run(TestWorker.java:193)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName(TestWorker.java:129)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:100)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:60)
	at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:56)
	at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:133)
	at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:71)
	at worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69)
	at worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74)

Add support of >= JDK 9

Currently we are looking for jar files inside installation. Add support for jmod files too

Hierarchy for JcClasspath for environment libs

Idea

Split classpaths into hierarchy and has an default classpath instance for environment libraries (jvm libraries). That may reduce memory consumption because caches for environment librs may be shared. As an opposite side class caches may be stored on bytecode level.

JcTypedMethodParameter stores parameter type instead of name in the property"name"

Seems like JcTypedParameterImpl stores type of parameters and not its name in JcTypedMethodParameter.name. Consider the following test:

@Test
fun `my test`() {
    class Example() {
        fun f(notNullable: String, nullable: String?): Int {
            return 0
        }
    }

    val clazz = typeOf<Example>()
    clazz as JcClassType
    val actualParameters = clazz.declaredMethods.single { it.name == "f" }.parameters.map { it.name }
    assertEquals(listOf("notNullable", "nullable"), actualParameters)
}

It fails with

Expected :[notNullable, nullable]
Actual   :[java.lang.String, java.lang.String]

Wrong IR for bytecode

For this method

 public static void main(String[] args) {
        Benchmark.alloc(1);
        A a = (A) Benchmark.taint(); //new A();
        A b = new A(); // Added to avoid cfg optimizations
        Benchmark.use(b);
        b = a; // REVERSED assignment in IR
        Benchmark.use(b);
        Benchmark.use(a);
        Benchmark.test("b",
                "{allocId:1, mayAlias:[a,b], notMayAlias:[], mustAlias:[a,b], notMustAlias:[]}");
    }

API design

Describe:

  • main interface and domain model
  • multithreading concepts and spec for this interfaces
  • example of usages

flowGraph() throws exception when local vars are initialized with null

Consider the following class:

class Example {
    void derefAfterCheck() {
        String myString = null;

        if (myString == null)
        {
            IO.writeLine(myString.length());
        }
    }
}

And the corresponding test:

val method = cp.findClass<Example>().declaredMethods.single { it.name == "derefAfterCheck" }
method.flowGraph()

Call to JcMethod.flowGraph() here fails with exception:

Could not find a method with correct signature java.lang.Object#length()I
java.lang.IllegalStateException: Could not find a method with correct signature java.lang.Object#length()I
	at org.jacodb.impl.cfg.JcGraphBuilder.getMethod(JcGraphBuilder.kt:420)
	at org.jacodb.impl.cfg.JcGraphBuilder.visitJcRawVirtualCallExpr(JcGraphBuilder.kt:457)
	at org.jacodb.impl.cfg.JcGraphBuilder.visitJcRawVirtualCallExpr(JcGraphBuilder.kt:176)
	at org.jacodb.api.cfg.JcRawVirtualCallExpr.accept(JcRawInst.kt:716)
	at org.jacodb.impl.cfg.JcGraphBuilder.visitJcRawAssignInst(JcGraphBuilder.kt:237)
	at org.jacodb.impl.cfg.JcGraphBuilder.visitJcRawAssignInst(JcGraphBuilder.kt:176)
	at org.jacodb.api.cfg.JcRawAssignInst.accept(JcRawInst.kt:42)
	at org.jacodb.impl.cfg.JcGraphBuilder.convertRawInst(JcGraphBuilder.kt:220)
	at org.jacodb.impl.cfg.JcGraphBuilder.buildFlowGraph(JcGraphBuilder.kt:203)
	at org.jacodb.impl.bytecode.JcMethodImpl.flowGraph(JcMethodImpl.kt:84)
        ...

The problem seems to be in incorrect assigning type Object to localvar myString due to null-initialization

Add indexes api

Add api for indexing bytecode. Switch search of all subclasses to index api.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.