• Stars
    star
    111
  • Rank 314,510 (Top 7 %)
  • Language
    Java
  • Created over 11 years ago
  • Updated over 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Java Off Heap Object Pool and On the Fly Instrumentation Tool
  1. What is Jillegal? ==============

Jillegal is a library including unknown tricks of Java. It abstracts developer from low-level details to implement those tricks. Its design and logic are based on Java 8 and JRockit so it can be used at only Java 8 and JRockit platforms. Java 6 and Java 7 supports are in progress and as soon as possible they will be released. Demo applications are avaiable at https://github.com/serkan-ozal/jillegal-demo and https://github.com/serkan-ozal/jillegal-demo-web.

NOTE: This is an experimental project. So, please notify me for all kind of suggestions, feedbacks and issues (with crash log files and test cases if possible :))

Currently it has three main modules: OffHeap, Instrumentation and In Memory Compiler.

1.1. OffHeap Module

Design and logic of Jillegal OffHeap module different from all of the other offheap frameworks. It doesn't serilalize/deserialize objects to/from allocated offheap memory region. Because objects already lives on offheap and GC doesn't track them :). With this feature, all objects in pool are exist as sequential at memory, so sequential accessing to them is faster. Because, they will be fetched to CPU cache together as limited size of CPU cache.

LIMITATIONS:

  • Only Hotspot Java 8 JVM, Oracle JRockit JVM and Azul's Zulu Java 8 JVM are supported. Java 6 and Java 7 based JVMs are not supported yet.

  • Only CMS collector (-XX:+UseConcMarkSweepGC), G1 collector (-XX:+UseG1GC) and Serial collector (-XX:+UseSerialGC) are supported for Hotspot JVM. Don't try with other collectors such as Default or Parallel collector (-XX:+UseParallelGC or -XX:+UseParallelOldGC) since there is an issue associated with these collectors's Young GC collections :).

  • Offheap module needs to disabled compressed-oops (-XX:-UseCompressedOops) since there is no quarantee that allocated native memory space can be represented with compressed-oops with huge memory sizes.

  • Off-Heap objects must not reference to On-Heap objects since they can be moved while GC and Off-Heap objects are not aware of this movement since they are not under GC control. However, On-Heap objects can reference to Off-Heap objects and also Off-Heap objects can references to Off-Heap objects as well.

1.2. Instrumentation Module

Instrumenting and redefining any Java class, interface, ... (even core Java classes) at runtime with developer friendly API (with Builder Pattern based design) is supported. You can add your custom pre/post listeners to method and constructor invocations dynamically. It serves a platform to develop your custom AOP framework. It uses Java Instrumentation API but adding extra VM argument (like -javaagent:<jarpath>[=<options>]) is not required. Jillegal has its own internal agent and it can enable it's agent at runtime dynamically.

1.3. In Memory Compiler Module

Compiling Java and Groovy source codes in memory is supported. You can compile your Java and Groovy based source codes at runtime in memory and can get its compiled class.

  1. Compile and Build =======

  2. First clone code from GitHub. git clone https://github.com/serkan-ozal/jillegal.git

  3. To set JDK / JRE installation/home directory:

    2.1. For Java 8, add an environment variable named JAVA8_HOME points to JDK 8 / JRE 8 installation/home directory.

    2.2. For JRockit, add an environment variable named JROCKIT_HOME points to JRockit JDK / JRockit JRE installation/home directory.

  4. Compile with maven. mvn clean install

  5. Installation =======

In your pom.xml, you must add repository and dependency for Jillegal. You can change jillegal.version to any existing Jillegal library version. Latest version is 2.1-SNAPSHOT.

...
<properties>
    ...
    <jillegal.version>2.1-SNAPSHOT</jillegal.version>
    ...
</properties>
...
<dependencies>
    ...
	<dependency>
		<groupId>tr.com.serkanozal</groupId>
		<artifactId>jillegal</artifactId>
		<version>${jillegal.version}</version>
	</dependency>
	...
</dependencies>
...
<repositories>
	...
	<repository>
		<id>serkanozal-maven-repository</id>
		<url>https://github.com/serkan-ozal/maven-repository/raw/master/</url>
	</repository>
	...
</repositories>
...

For JRockit usage, change <artifactId> to jillegal-jrockit in dependency such as:

...
	<dependency>
		<groupId>tr.com.serkanozal</groupId>
		<artifactId>jillegal-jrockit</artifactId>
		<version>${jillegal.version}</version>
	</dependency>
...
  1. Usage =======

To initialize Jillegal and find Jillegal Aware classes, there are two ways:

  1. You just need to call explicitly making aware method at startup in anywhere of your application.
...

tr.com.serkanozal.jillegal.Jillegal.init();

...

or

  1. You can extend your main class from tr.com.serkanozal.jillegal.util.JillegalAware class.
...

public class JillegalDemo extends JillegalAware {

	public static void main(String[] args) {
	
		...
	
	}
	
}	

...

4.1. Jillegal Aware OffHeap Pool

To make any of your class, just annotate it with tr.com.serkanozal.jillegal.config.annotation.JillegalAware annotation. So it will be detected by Jillegal on initialize cycle and will be instrumented automatically to be aware of Jillegal.

@JillegalAware
public class JillegalAwareSampleClassWrapper {

	@OffHeapObject
	private SampleClass sampleClass;

	@OffHeapArray(length = 1000)
	private SampleClass[] sampleClassArray;

	public SampleClass getSampleClass() {
		return sampleClass;
	}

	public void setSampleClass(SampleClass sampleClass) {
		this.sampleClass = sampleClass;
	}

	public SampleClass[] getSampleClassArray() {
		return sampleClassArray;
	}

	public void setSampleClassArray(SampleClass[] sampleClassArray) {
		this.sampleClassArray = sampleClassArray;
	}

}
public class SampleClass {

	private int i1 = 5;
	private int i2 = 10;
	private int order;

	public int getI1() {
		return i1;
	}

	public int getI2() {
		return i2;
	}

	public int getOrder() {
		return order;
	}
	
}
JillegalAwareSampleClassWrapper sampleClassWrapper = new JillegalAwareSampleClassWrapper();

sampleClassWrapper.getSampleClass().setOrder(-1);

SampleClass[] objArray = sampleClassWrapper.getSampleClassArray();
    	
for (int i = 0; i < objArray.length; i++) {
    	SampleClass obj = objArray[i];
    	obj.setOrder(i);
    	System.out.println("Order value of auto injected off-heap object field has been set to " + i);
}

System.out.println("Order value of sample object at off heap pool: " + 
sampleClassWrapper.getSampleClass().getOrder());
    	
for (int i = 0; i < objArray.length; i++) {
    	SampleClass obj = objArray[i];
    	System.out.println("Order value of " + i + ". object at off heap pool: " + obj.getOrder());
}

4.2. Eager Referenced Object OffHeap Pool

OffHeapService offHeapService = OffHeapServiceFactory.getOffHeapService();

ObjectOffHeapPoolCreateParameterBuilder<SampleClass> offHeapPoolParameterBuilder = 
				new ObjectOffHeapPoolCreateParameterBuilder<SampleClass>().
						type(SampleClass.class).
						objectCount(ELEMENT_COUNT).
						makeOffHeapableAsAuto(true).
						referenceType(ObjectPoolReferenceType.EAGER_REFERENCED);
ObjectOffHeapPoolCreateParameter<SampleClass> offHeapPoolParameter = offHeapPoolParameterBuilder.build();
EagerReferencedObjectOffHeapPool<SampleClass> eagerReferencedObjectPool = 
				offHeapService.createOffHeapPool(offHeapPoolParameter);
for (int i = 0; i < ELEMENT_COUNT; i++) {
	SampleClass obj = eagerReferencedObjectPool.get();
	...
}

4.3. Lazy Referenced Object OffHeap Pool

OffHeapService offHeapService = OffHeapServiceFactory.getOffHeapService();

ObjectOffHeapPoolCreateParameterBuilder<SampleClass> offHeapPoolParameterBuilder = 
				new ObjectOffHeapPoolCreateParameterBuilder<SampleClass>().
						type(SampleClass.class).
						objectCount(ELEMENT_COUNT).
						makeOffHeapableAsAuto(true).
						referenceType(ObjectPoolReferenceType.LAZY_REFERENCED);
ObjectOffHeapPoolCreateParameter<SampleClass> offHeapPoolParameter = offHeapPoolParameterBuilder.build();
LazyReferencedObjectOffHeapPool<SampleClass> lazyReferencedObjectPool = 
				offHeapService.createOffHeapPool(offHeapPoolParameter);
for (int i = 0; i < ELEMENT_COUNT; i++) {
	SampleClass obj = lazyReferencedObjectPool.get();
	...
}

4.4. Primitive Type Array OffHeap Pool

OffHeapService offHeapService = OffHeapServiceFactory.getOffHeapService();

PrimitiveTypeArrayOffHeapPool<Integer, int[]> primitiveTypeArrayPool = 
				offHeapService.createOffHeapPool(
						new ArrayOffHeapPoolCreateParameterBuilder<Integer>().
								type(Integer.class).
								length(ELEMENT_COUNT).
								usePrimitiveTypes(true).
							build());

int[] primitiveArray = primitiveTypeArrayPool.getArray();

for (int i = 0; i < primitiveArray.length; i++) {
	primitiveArray[i] = i;
}

4.5. Complex Type Array OffHeap Pool

OffHeapService offHeapService = OffHeapServiceFactory.getOffHeapService();

ComplexTypeArrayOffHeapPool<SampleClass, SampleClass[]> complexTypeArrayPool = 
				offHeapService.createOffHeapPool(
						new ArrayOffHeapPoolCreateParameterBuilder<SampleClass>().
								type(SampleClass.class).
								length(ELEMENT_COUNT).
								initializeElements(true).
							build());
							
SampleClass[] complexArray = complexTypeArrayPool.getArray();

for (int i = 0; i < complexArray.length; i++) {
	SampleClass obj = complexArray[i];
	...
}	

4.6. Extendable Eager Referenced Object OffHeap Pool

OffHeapService offHeapService = OffHeapServiceFactory.getOffHeapService();

EagerReferencedObjectOffHeapPool<SampleClass> sequentialObjectPool = 
				offHeapService.createOffHeapPool(
						new ObjectOffHeapPoolCreateParameterBuilder<SampleClass>().
								type(SampleClass.class).
								objectCount(ELEMENT_COUNT).
								referenceType(ObjectPoolReferenceType.EAGER_REFERENCED).
							build());

ExtendableObjectOffHeapPool<SampleClass> extendableObjectPool =
				offHeapService.createOffHeapPool(
						new ExtendableObjectOffHeapPoolCreateParameterBuilder<SampleClass>().
								forkableObjectOffHeapPool(sequentialObjectPool).
							build());

for (int i = 0; i < TOTAL_ELEMENT_COUNT; i++) {
	SampleClass obj = extendableObjectPool.get();
	...
}	

4.7. Extendable Lazy Referenced Object OffHeap Pool

OffHeapService offHeapService = OffHeapServiceFactory.getOffHeapService();

LazyReferencedObjectOffHeapPool<SampleClass> sequentialObjectPool = 
				offHeapService.createOffHeapPool(
						new ObjectOffHeapPoolCreateParameterBuilder<SampleClass>().
								type(SampleClass.class).
								objectCount(ELEMENT_COUNT).
								referenceType(ObjectPoolReferenceType.LAZY_REFERENCED).
							build());

ExtendableObjectOffHeapPool<SampleClass> extendableObjectPool =
				offHeapService.createOffHeapPool(
						new ExtendableObjectOffHeapPoolCreateParameterBuilder<SampleClass>().
								forkableObjectOffHeapPool(sequentialObjectPool).
							build());

for (int i = 0; i < TOTAL_ELEMENT_COUNT; i++) {
	SampleClass obj = extendableObjectPool.get();
	...
}	

4.8. String OffHeap Pool

OffHeapService offHeapService = OffHeapServiceFactory.getOffHeapService();

StringOffHeapPool stringPool = 
				offHeapService.createOffHeapPool(
						new StringOffHeapPoolCreateParameterBuilder().
								estimatedStringCount(STRING_COUNT).
								estimatedStringLength(ESTIMATED_STRING_LENGTH).
							build());
   
for (int i = 0; i < STRING_COUNT; i++) {
	System.out.println(stringPool.get("String " + i));
}
    	

4.9. Extendable String OffHeap Pool

OffHeapService offHeapService = OffHeapServiceFactory.getOffHeapService();

DeeplyForkableStringOffHeapPool stringPool = 
				offHeapService.createOffHeapPool(
						new StringOffHeapPoolCreateParameterBuilder().
								estimatedStringCount(STRING_COUNT).
								estimatedStringLength(ESTIMATED_STRING_LENGTH).
							build());
   
ExtendableStringOffHeapPool extendableStringPool =
				offHeapService.createOffHeapPool(
						new ExtendableStringOffHeapPoolCreateParameterBuilder().
								forkableStringOffHeapPool(stringPool).
							build());

for (int i = 0; i < TOTAL_STRING_COUNT; i++) {
	System.out.println(stringPool.get("String " + i));
}

4.10. Instrumentation Module

public class SampleClass {

	public SampleClass() {
		System.out.println("SampleInstrumentClass.SampleClassToInstrument()"); 
	}

	public void methodToIntercept() {
		System.out.println("SampleInstrumentClass.methodToIntercept()"); 
	}
	
}
Jillegal.init();

System.out.println("Before Intrumentation: ");
System.out.println("=====================================================");

SampleClass obj1 = new SampleClass();
obj1.methodToIntercept();

System.out.println("=====================================================");

System.out.println("After Intrumentation: ");
System.out.println("=====================================================");

InstrumentService instrumentService = InstrumentServiceFactory.getInstrumentService();
Instrumenter<SampleClass> inst = instrumentService.getInstrumenter(SampleClass.class);
GeneratedClass<SampleClass> redefinedClass =
	inst.
		insertBeforeConstructors(
			new BeforeConstructorInterceptor<SampleClass>() {
				@Override
				public void beforeConstructor(SampleClass o, Constructor<SampleClass> c, Object[] args) {
					System.out.println("Intercepted by Jillegal before constructor ...");
				}}).

		insertAfterConstructors("System.out.println(\"Intercepted by Jillegal after constructor ...\");").

		insertBeforeMethod("methodToIntercept", 
			new BeforeMethodInterceptor<SampleClass>() {
				@Override
				public void beforeMethod(SampleClass o, Method m, Object[] args) {
					System.out.println("Intercepted by Jillegal before methodToIntercept method ...");
				}}).

		insertAfterMethod("methodToIntercept", 
			"System.out.println(\"Intercepted by Jillegal after methodToIntercept method ...\");").
                    			
	build();

instrumentService.redefineClass(redefinedClass); 

SampleClass obj2 = new SampleClass();
obj2.methodToIntercept();
        
System.out.println("=====================================================");

4.11. In Memory Java Compiler

ClassCompilerService classCompilerService = 
			ClassCompilerServiceFactory.getClassCompilerService();
			
String code = 
	"package tr.com.serkanozal.jillegal.compiler.demo;"+ "\n" +
	"\n" +
	"public class SampleJavaClass {" + "\n" +
	"\n" +
	"\t" + "public String toString() {" + "\n" +
	"\t" + "\t" + "return \"I am SampleJavaClass\";" + "\n" +
	"\t" + 	"}" + "\n" +
	"\n" +
	"}";

Class<?> compiledClass = classCompilerService.getClassCompiler(DefaultCodeType.JAVA).compile(code);
Object obj = compiledClass.newInstance();
		
System.out.println(obj.toString());

4.12. In Memory Groovy Compiler

ClassCompilerService classCompilerService = 
			ClassCompilerServiceFactory.getClassCompilerService();
			
String code = 
	"package tr.com.serkanozal.jillegal.compiler.demo;"+ "\n" +
	"\n" +
	"public class SampleGroovyClass {" + "\n" +
	"\n" +
	"\t" + "public String toString() {" + "\n" +
	"\t" + "\t" + "def str = \"I am SampleGroovyClass\";" + "\n" +
	"\t" + "\t" + "return str;" + "\n" +
	"\t" + 	"}" + "\n" +
	"\n" +
	"}";

Class<?> compiledClass = classCompilerService.getClassCompiler(DefaultCodeType.GROOVY).compile(code);
Object obj = compiledClass.newInstance();
		
System.out.println(obj.toString());
  1. Roadmap =======
  • Parallel GC support for OffHeap module.

  • Object lifecycle awareness support for OffHeap module.

  • Java 6 / Java 7 support for OffHeap module.

  • IBM JVM support for OffHeap module.

More Repositories

1

mysafe

My Unsafe - Unsafe Interceptor, Native Memory Leak Tracker and Access Checker on the JVM
Java
41
star
2

otel-bash

Bash library to instrument and trace bash scripts automatically with OpenTelemetry
Shell
39
star
3

ocean-of-memories

Codes for ocean-of-memories article series
Java
22
star
4

spring-jdbc-roma-impl

Java
20
star
5

leanser

AWS Lambda Cleaner - Cleanup resources on AWS Lambda container shutdown (timeout and/or spin-down)
JavaScript
20
star
6

otel-cli

CLI to send traces to an external OpenTelemetry collector OTLP endpoint
TypeScript
19
star
7

jemstone

Hidden Gems of JVM/JDK
Java
18
star
8

jillegal-agent

Java Agent Library for All Jillegal Frameworks
Java
14
star
9

spring-jdbc-roma

Spring JDBC extension for object mapping supported rowmapper
Java
11
star
10

jvm-playground

Playground project for JVM
Java
9
star
11

ankaracloudmeetup-bigdata-demo

Ankara Cloud Meetup Big Data Demo
Python
7
star
12

whitebox

Public version of JDK 8+ internal WhiteBox API
Java
7
star
13

samba

Stateful AWS Lambda
Java
6
star
14

hazelcast-aware

Make your application aware of Hazelcast with Java Instrumentation API
Java
5
star
15

dynacast

Hazelcast cached and synched AWS DynamoDB
Java
5
star
16

hermgen

Hazelcast Based Distributed ClassLoader and PermGen
Java
5
star
17

aws-tweet-crawler

A Platform that crawls tweets on AWS
Java
4
star
18

spring-jdbc-roma-demo

Demo of spring-jdbc-roma
Java
4
star
19

t2-hackathon-mapreduce

T2 Big Data Hackathon MapReduce Example
4
star
20

proxyable

Anymore, even final classes/methods and static methods will be used as proxy
Java
4
star
21

sarras

Reflection Configuration File Generator for Graal Substrate VM by Static and Dynamic Profiling of Java Applications
4
star
22

otel-js-instrumentation-http-plus

Provides advanced automatic instrumentation for Node.js http and https modules on top of OpenTelemetry
TypeScript
4
star
23

stackwriter-serverless

StackWriter allows developers to be able to get, manipulate and send/report callstacks with local variables manually or automatically on error.
3
star
24

jemstone-plugin

Plug-in repository for Jemstone
Java
2
star
25

ankarajug-bigdata-demo

Ankara JUG Big Data Demo
Java
2
star
26

samba-aws-lambda-demo

AWS Lambda Demo for Samba (Statefull AWS Lambda)
Java
2
star
27

java-hsdis-builder

Shell
2
star
28

t2-hackathon-answers

T2 Big Data Hackathon Questions and Answers
Java
2
star
29

t2-hackathon-questions

T2 Big Data Hackathon Questions
2
star
30

jillegal-demo

Jillegal Demo
Java
2
star
31

mystring

MyString allows creating custom String implementations (has off-heap based as built-in) on the JVM
Java
2
star
32

leshy

Leshy is a framework for replacing default Java serialization with your custom implementation on the fly without any code change in your application by using Java Instrumentation API.
Java
2
star
33

jday2015-jcache

JCache Demo for JDay 2015
Java
1
star
34

dynacast-demo

Demo application for demonstrating DynaCast
Java
1
star
35

photorazzo

Java
1
star
36

vaadin-s4v-demo

Demo of vaadin-s4v
JavaScript
1
star
37

spring-interceptor

Spring module for defining your rules seperated from your operations
1
star
38

javassist-issue-report

Java
1
star
39

jaster

Faster operations (IO, Reflection, etc ...) for Java
1
star
40

java-vector-distance-benchmark

Java
1
star
41

otel-js-console-tracer

Injects current/active OpenTelemetry trace id and span id into the console logs
TypeScript
1
star
42

maven-repository

Batchfile
1
star
43

jillegal-demo-web

Jillegal Demo Web Application
Java
1
star
44

blog

Repository that includes contents published at my blog (serkanozal.blogspot.com)
Java
1
star
45

ring

Java
1
star
46

hazelcast-aware-demo

Demo application for Hazelcast-Aware
Java
1
star
47

publications

1
star
48

jillegal-offheap

Java High Performance Off Heap Memory Implementation Framework Without Serialization/Deserialization
Java
1
star
49

vaadin-s4v

Spring for Vaadin
Java
1
star
50

spring-jdbc-roma-api

Java
1
star
51

mystring-api

API of MyString which allows create custom String implementations on the JVM
Java
1
star
52

jcommon

Java library for common usage
Java
1
star
53

ice-cracker

Initialization support for CJS modules during handler load in AWS Lambda to reduce coldstart delay
1
star
54

jiagara

High-Performance, Generic, Automated and Customizable Java Serialization/Deserialization Framework
Java
1
star
55

hazelcast-distributedclassloader-demo

Demo application for Hazelcast-DistributedClassLoader
Java
1
star
56

hazelcast-distributedclassloader

Distributed ClassLoader Implementation On Top of Hazelcast
Java
1
star
57

hermgen-demo

Demo application for HermGen
Java
1
star