• Stars
    star
    129
  • Rank 279,216 (Top 6 %)
  • Language
    Java
  • License
    MIT License
  • Created over 6 years ago
  • Updated over 1 year ago

Reviews

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

Repository Details

A bestiary of classes implementing exotic semantics in Java

exotic Continuous Integration

A bestiary of classes implementing exotic semantics in Java

In Java, a static final field is considered as a constant by the virtual machine, but a final field of an object which is a constant is not itself considered as a constant. Exotic allows to see a constant's field as a constant, a result of a calculation as a constant, to change at runtime the value of a constant, etc.

This library run on Java 8+ and is fully compatible with Java 9 modules.

This library needs Java 11+ to be built.

MostlyConstant - javadoc

A constant for the VM that can be changed by de-optimizing all the codes that contain the previous value of the constant.

private static final MostlyConstant<Integer> FOO = new MostlyConstant<>(42, int.class);
private static final IntSupplier FOO_GETTER = FOO.intGetter();

public static int getFoo() {
  return FOO_GETTER.getAsInt();
}
public static void setFoo(int value) {
   FOO.setAndDeoptimize(value);
}

StableField - javadoc

A field that becomes a constant if the object itself is constant and the field is initialized

enum Option {
  a, b;
    
  private static final Function<Option, String> UPPERCASE =
      StableField.getter(lookup(), Option.class, "uppercase", String.class);
    
  private String uppercase;  // stable

  public String upperCase() {
    String uppercase = UPPERCASE.apply(this);
    if (uppercase != null) {
      return uppercase;
    }
    return this.uppercase = name().toUpperCase();
  }
}
...
Option.a.upperCase()  // constant "A"

ConstantMemoizer - javadoc

A function that returns a constant value if its parameter is a constant.

private static final ToIntFunction<Level> MEMOIZER =
    ConstantMemoizer.intMemoizer(Level::ordinal, Level.class);
...
MEMOIZER.applyAsInt("foo") // constant 3

ObjectSupport - javadoc

Provide a fast implementation for equals() and hashCode().

class Person {
  private static final ObjectSupport<Person> SUPPORT =
      ObjectSupport.of(lookup(), Person.class, p -> p.name);
    
  private String name;
  ...
  
  public boolean equals(Object other) {
    return SUPPORT.equals(this, other);
  }
    
  public int hashCode() {
    return SUPPORT.hashCode(this);
  }
}

StructuralCall - javadoc

A method call that can call different method implementations if they share the same name and same parameter types.

private static final StructuralCall IS_EMPTY =
    StructuralCall.create(lookup(), "isEmpty", methodType(boolean.class));

static boolean isEmpty(Object o) {  // can be called with a Map, a Collection or a String
  return IS_EMPTY.invoke(o);
}

Visitor - javadoc

An open visitor, a visitor that does allow new types and new operations, can be implemented using a Map that associates a class to a lambda, but this implementation loose inlining thus perform badly compared to the Gof Visitor. This class implements an open visitor that's used inlining caches.

private static final Visitor<Void, Integer> VISITOR =
    Visitor.create(Void.class, int.class, opt -> opt
      .register(Value.class, (v, value, __) -> value.value)
      .register(Add.class,   (v, add, __)   -> v.visit(add.left, null) + v.visit(add.right, null))
    );
...
Expr expr = new Add(new Add(new Value(7), new Value(10)), new Value(4));
int value = VISITOR.visit(expr, null);  // 21

TypeSwitch - javadoc

Express a switch on type as function from an object to an index + a classical switch on the possible indexes. The TypeSwitch should be more efficient than a cascade of if instanceof.

private static final TypeSwitch TYPE_SWITCH = TypeSwitch.create(true, Integer.class, String.class);
  
public static String asString(Object o) {
  switch(TYPE_SWITCH.typeSwitch(o)) {
  case TypeSwitch.NULL_MATCH:
    return "null";
  case 0:
    return "Integer";
  case 1:
    return "String";
  default: // TypeSwitch.NO_MATCH
    return "unknown";
  }
}

Build Tool Integration

Get latest binary distribution via JitPack

Maven

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>
<dependency>
    <groupId>com.github.forax</groupId>
    <artifactId>exotic</artifactId>
    <version>master-SNAPSHOT</version>
</dependency>

Gradle

repositories {
    ...
    maven { url 'https://jitpack.io' }
}
dependencies {
    compile 'com.github.forax:exotic:master-SNAPSHOT'
}

More Repositories

1

java-guide

A guide of modern Java (Java 17)
Jupyter Notebook
551
star
2

design-pattern-reloaded

Implementation of GoF design patterns using Java 21
Java
207
star
3

loom-fiber

Continuation & Fiber examples using the OpenJDK project Loom prototype
Java
116
star
4

pro

A Java build tool that works seamlessly with modules
Java
103
star
5

proxy2

Better / faster proxy generator than java.lang.reflect.Proxy for Java (require 1.7)
Java
69
star
6

beautiful_logger

Yet another logger API in Java with beautiful features
Java
65
star
7

record-util

Some utility classes around java records
Java
32
star
8

vector-handle

A high level API to express vectorized operations in Java
Java
25
star
9

kata-restrospective-11

Un kata sur comment utiliser Java 11 pour créer des APIs fonctionnelles
Java
25
star
10

macro

Java Macro Library
Java
23
star
11

moduletools

A small example of a Java 9 modular application
Java
20
star
12

kata-java17

A kata to transform an existing program to use Java 17 new features
Java
19
star
13

loom-actor

A small but fun actor framework based on loom
Java
19
star
14

mjolnir

Thor Hammer and a way to express invokedynamic in Java
Java
18
star
15

advent-of-code-2023

Let's try to do the advent of code 2023 in Java 21
Java
16
star
16

java-next

Binary builds of several OpenJDK projects
Shell
15
star
17

jexpress

A light express.js like library written in Java (in one file)
Java
15
star
18

vmboiler

A small library on top of ASM that generates optimistically typed bytecodes for dynamically typed JVM based languages
Java
14
star
19

write_your_dynamic_language_runtime

How to write interpreters or dynamic compilers for dynamically typed languages on top of the JVM
Java
13
star
20

jayspec

RSpec for Java 8
Java
13
star
21

hidden_proxy

A simple API that shows how,to use Hidden class to create proxies
Java
13
star
22

jsjs

jsjs is a JavaScript engine written in JavaScript on top of the Java Virtual Machine
Java
13
star
23

argvester

Argument Harvester - a simple command line parser
Java
12
star
24

blast_from_the_past

Evolution of Java on an example from 1.0 to 10
Java
12
star
25

write_your_own_java_framework_exercices

Try to implement small demos of the code powering usual Java frameworks
Java
11
star
26

write_your_own_java_framework

Understand how Spring, JakartaEE, Jackson, Guice and Hibernate works by rewriting a toy version of them
Java
11
star
27

do-synthetic-methods-dream-of-electric-switch-expressions

Slides for ParisJUG, ChtiJUG and DevoxxFR 2021
JavaScript
11
star
28

pratt_parser

Implementation of a Pratt Parser in Java
Java
9
star
29

einherjar

A Java tool that transforms a Java jar to an Einherjar to go to Valhalla
Java
9
star
30

valuetype-lworld

Tests of Java value type (lworld prototype)
Java
8
star
31

dragon

A simple enhanceable programming language for teaching algorithms
HTML
7
star
32

pro-demo

A small demo of pro
Java
6
star
33

we_are_all_to_gather

Demo of the new Stream Gatherer API of Java 22
Java
6
star
34

ninal

Ninal which stands for "Ninal is not a Lisp" is a small demo language (lisp like syntax/C like semantics) using Graal/Truffle
Java
5
star
35

jigsaw-jrtfs

A backport of jrtfs.jar for 1.7
Java
5
star
36

varhandle2

A safe yet efficient implementation of atomic operations for the JVM.
Java
5
star
37

tomahawk

A better Java API for Apache Arrow
Java
5
star
38

cplisp

A Lisp that is able to compile itself into the constant pool of a Java .class
Java
5
star
39

memory-mapper

A simpler API to the Foreign function memory API of Java
Java
5
star
40

indy-everywhere

A sample code that rewrite a folder of classes to use invokedynamic instead of getfield/putfield/invokevirtual/invokeinterface
Java
5
star
41

how_to_stop_a_thread

Different ways in Java to stop a thread
Java
5
star
42

dop-examples

Data Oriented Programming Examples
Java
4
star
43

java-interpolation

variation around how to implement string interpolation in Java
Java
4
star
44

java-21-demo

Java 21 : Add some sparkle to your life
Java
4
star
45

forax.github.io

blog pages
JavaScript
4
star
46

amber-record

tests of the OpenJDK Amber record/sealed types
Java
4
star
47

smartass

A toy language used to explain how to implement a dynamic language on top of the JVM
Java
4
star
48

virtual-bean

A simple API to compose bean behavior based on annotations
Java
4
star
49

umldoc

Automatically generates documentation with the UML diagrams using either plantUML or mermaidjs
Java
4
star
50

snowcamp-demo

one JDK8 application used as demo to show how to migrate to JDK9
JavaScript
3
star
51

blog

A blog publisher (like Jekyll) written in Java and tailored for me
Java
3
star
52

record-map

A java.util.Map that mostly supports Map interface but use a record instead of Map.Entry
Java
3
star
53

swisstable

A Java implementation of the Swisstable algorithm
Java
3
star
54

struct-of-array

Two data structures with the API of an array of structs (AoS) and the internals of a struct of arrays (SoA)
Java
3
star
55

cheapcoverage

A demo on how to gather code coverage information on Java (Kotlin, Scala, etc) classfiles
Java
3
star
56

panama-vector

A workspace to test the vector API of the OpenJDK Panama project
Java
3
star
57

amber-deconstructor

A prototype of how deconstructor can work for Amber OpenJDK project
Java
3
star
58

java-25-demo

Demo of Java 25
Java
3
star
59

civilizer

A bytecode rewriter that provides value types and specialized generics on top of OpenJDK Valhalla early access build
Java
3
star
60

jruby-methodcall-optimizer

a proof of concept of an optimizer of bytecodes able to transform recognizable pattern to invokedynamic
Java
2
star
61

8to6

A retroweaver from Java 8 to Java 6 in order to run Java 8 code on Android !
Java
2
star
62

jsonjedi

parsing JSON with JDK8 lambdas
Java
2
star
63

panama-fastaccess

Java
2
star
64

jsonapi

Proposal implementation for a Light-Weight JSON API (JEP 198)
Java
2
star
65

zen

A simple graphic library in Java (on top of AWT)
Java
2
star
66

flexible-constructor

Examples of flexible constructors (JEP 447) and more recent JEPs
Java
2
star
67

switch-pattern-combinator

A prototype showing how to generte the bytecode for a switch on patterns
Java
1
star
68

switch-carrier

A study of the carrier factory for the destructuring switch
Java
1
star
69

parisjug2013

The code I have shown during Paris JUG session "In bed with ..." in september 2013
Java
1
star
70

lambda-perf

performance of various implementations of lambda-lib (future jdk8 API)
Java
1
star
71

graalvm-demo

A demo of all graal projects
Java
1
star
72

pattern-matching

Examples of pattern matching in Java
Java
1
star
73

webapp-java17

A example of a Spring project using Java 17
Java
1
star
74

kija

Kija is a small programming language to teach algorithmics
Java
1
star
75

foraxproof

An example of a tool that analyze bytecode (like findbugs)
Java
1
star
76

reducedjs

A reduced set of the JavaScript feature that can run fast on the JVM
1
star
77

amber-demo

Examples of features of the Amber OpenJDK project
Java
1
star
78

html-component

A very small library to define unmodifiable HTML/XML components
Java
1
star
79

movie_buddy

A movie buddy application for Devoxx 2014 (Vertx + Java8 lambda)
JavaScript
1
star
80

thread-stop-experiment

Let see if we can not use the Arena/Segment as a lightweight cross thread mechanism
1
star