Skip to content

Hot compile java source file, and analysis which classes and methods are called.

License

Notifications You must be signed in to change notification settings

baifan/dynamic-compiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dynamic Compile Java && Check byte code

Build Status License

  1. Dynamic compile java source file to byte codes.
  2. Check which classes and methods are called in the byte codes.

Project Usage

Build

To build the project:

$ git clone [email protected]:baifan/dynamic-compiler.git
$ cd dynamic-compiler
## if you already has `mvn` in path, only use this cmd
## $ mvn compile package install
## if you doesn't has `mvn` in path, then use this cmd
$ ./mvnw compile package install

Binaries

This project does't upload to Maven Central. If you want to use it, you can install to local repository.

<dependency>
  <groupId>tech.weyi.dynamic.compiler</groupId>
  <artifactId>dynamic-compiler</artifactId>
  <version>0.0.1-SNAPSHOT</version>
</dependency>

Method

Compile java source

import tech.weiyi.dynamic.bytecode.compiler.DynamicCompiler;
import tech.weiyi.dynamic.bytecode.compiler.MemoryClazzFile;


import java.util.Map;


class TestCompile {
    public void testCompile(String clazzName, String clazzSource) {
        Map<String, MemoryClazzFile> byteClazzMap = DynamicCompiler.compile(clazzName, clazzSource);
    }
}

Analysis clazz element

import tech.weiyi.dynamic.bytecode.analysis.ClazzCallAnalyzer;
import tech.weiyi.dynamic.bytecode.analysis.ClazzElement;
import tech.weiyi.dynamic.bytecode.compiler.MemoryClazzFile;

import java.util.Map;
import java.util.Set;

class TestAnalysisClazz {
    public void testAnalysisClazz(String clazzName, Map<String, MemoryClazzFile> memClsMap) {
        MemoryClazzFile memoryClazzFile = memClsMap.get(clazzName);
        Set<ClazzElement> clazzElements = ClazzCallAnalyzer.getUsedClassSet(memoryClazzFile.getBytes());
    }
}

Analysis method element

import tech.weiyi.dynamic.bytecode.analysis.MethodCallAnalyzer;
import tech.weiyi.dynamic.bytecode.analysis.MethodCallElement;
import tech.weiyi.dynamic.bytecode.compiler.MemoryClazzFile;

import java.util.Map;
import java.util.Set;

class TestAnalysisMethod {
    public void testAnalysisMethod(String clazzName, Map<String, MemoryClazzFile> memClsMap) {
        MemoryClazzFile memoryClazzFile = memClsMap.get(clazzName);
        Set<MethodCallElement> methodCallElements = MethodCallAnalyzer.getUsedClassSet(memoryClazzFile.getBytes());
    }
}

About

Hot compile java source file, and analysis which classes and methods are called.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages