Low level access to native memory, JVM and OS.
Switch branches/tags
chronicle-core-2.17.0 chronicle-core-1.16.29 chronicle-core-1.16.28 chronicle-core-1.16.27 chronicle-core-1.16.26 chronicle-core-1.16.25 chronicle-core-1.16.24 chronicle-core-1.16.23 chronicle-core-1.16.21 chronicle-core-1.16.20 chronicle-core-1.16.19 chronicle-core-1.16.18 chronicle-core-1.16.17 chronicle-core-1.16.16 chronicle-core-1.16.15 chronicle-core-1.16.14 chronicle-core-1.16.13 chronicle-core-1.16.12 chronicle-core-1.16.11 chronicle-core-1.16.10 chronicle-core-1.16.9 chronicle-core-1.16.8 chronicle-core-1.16.7 chronicle-core-1.16.6 chronicle-core-1.16.5 chronicle-core-1.16.4 chronicle-core-1.16.3 chronicle-core-1.16.2 chronicle-core-1.16.1 chronicle-core-1.16.0 chronicle-core-1.15.6 chronicle-core-1.15.5 chronicle-core-1.15.4 chronicle-core-1.15.3 chronicle-core-1.15.2 chronicle-core-1.15.1 chronicle-core-1.15.0 chronicle-core-1.12.8 chronicle-core-1.12.7 chronicle-core-1.12.6 chronicle-core-1.12.5 chronicle-core-1.12.4 chronicle-core-1.12.3 chronicle-core-1.12.2 chronicle-core-1.12.1 chronicle-core-1.12.0 chronicle-core-1.11.8 chronicle-core-1.11.7 chronicle-core-1.11.6 chronicle-core-1.11.5 chronicle-core-1.11.4 chronicle-core-1.11.3 chronicle-core-1.11.2 chronicle-core-1.11.1 chronicle-core-1.11.0 chronicle-core-1.10.1 chronicle-core-1.10.0 chronicle-core-1.9.28 chronicle-core-1.9.27 chronicle-core-1.9.26 chronicle-core-1.9.25 chronicle-core-1.9.24 chronicle-core-1.9.23 chronicle-core-1.9.22 chronicle-core-1.9.21 chronicle-core-1.9.20 chronicle-core-1.9.19 chronicle-core-1.9.18 chronicle-core-1.9.17 chronicle-core-1.9.16 chronicle-core-1.9.15 chronicle-core-1.9.14 chronicle-core-1.9.13 chronicle-core-1.9.12 chronicle-core-1.9.11 chronicle-core-1.9.10 chronicle-core-1.9.9 chronicle-core-1.9.8 chronicle-core-1.9.7 chronicle-core-1.9.6 chronicle-core-1.9.5 chronicle-core-1.9.4 chronicle-core-1.9.3 chronicle-core-1.9.2 chronicle-core-1.9.1 chronicle-core-1.9.0 chronicle-core-1.8.6 chronicle-core-1.8.5 chronicle-core-1.8.4 chronicle-core-1.8.3 chronicle-core-1.8.2 chronicle-core-1.8.1 chronicle-core-1.8.0 chronicle-core-1.7.16 chronicle-core-1.7.15 chronicle-core-1.7.14 chronicle-core-1.7.13 chronicle-core-1.7.12 chronicle-core-1.7.11 chronicle-core-1.7.10
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
benchmarks Reverting back to bom version 2.17-SNAPSHOT Oct 19, 2018
checked-exceptions Copyright chronicle.software in poms. Apr 26, 2018
src Ignore test for ARM Oct 31, 2018
.gitignore Standardise .gitignore across projects Jan 21, 2018
.travis.yml
LICENSE.adoc Migrate Chronicle-Queue to Apache v2.0 license Mar 27, 2016
README.md Basic doco on jlbh & event loop #49 Feb 25, 2018
pom.xml [maven-release-plugin] prepare for next development iteration Oct 19, 2018

README.md

Chronicle Core

Maven Central

This library wraps up low level access to

Off Heap Memory Access

This allows you to access native memory using primitives and some thread safe operations.

Memory memory = OS.memory();
long address = memory.allocate(1024);
try {
    memory.writeInt(address, 1);
    assert memory.readInt(address) == 1;
    final boolean swapped = memory.compareAndSwapInt(address, 1, 2);
    assert swapped;
    assert memory.readInt(address) == 2;
} finally {
    memory.freeMemory(address, 1024);
}

JVM Access Methods

Check the JVM is running in debug mode

if (Jvm.isDebug()) {
   // running in debug.

Rethrow a checked exception as an unchecked one.

try {
    // IO operation
} catch (IOException ioe) {
    throw Jvm.rethrow(ioe);
}

Get a Field for a Class by name

Field theUnsafe = Jvm.getField(Unsafe.class, "theUnsafe");
Unsafe unsafe = (Unsafe) theUnsafe.get(null);

OS Calls

Access to system calls

int processId = OS.getProcessId();
int maxProcessId = OS.getMaxProcessId();
int pageSize = OS.getPageSize();
boolean isWindows = OS.isWindows();
boolean is64bit = OS.is64Bit();
String hostname = OS.getHostName();
String username = OS.getUserName();
String targetDir = OS.getTarget(); // where is the target directory during builds.

Memory mapped files

FileChannel fc = new RandomAccessFile(fileName, "rw").getChannel();
// map in 64 KiB
long address = OS.map(fc, MapMode.READ_WRITE, 0, 64 << 10);
// use address
OS.memory().writeLong(1024L, 0x1234567890ABCDEFL);
// unmap memory region
OS.unmap(address, 64 << 10);

Resource Reference Counting

Use reference counting to deterministically release resources.

MappedFile mf = MappedFile.mappedFile(tmp, chunkSize, 0);
MappedBytesStore bs = mf.acquireByteStore(chunkSize + (1 << 10));

assertEquals(2, mf.refCount());
assertEquals(3, bs.refCount());
assertEquals("refCount: 2, 0, 3", mf.referenceCounts());

mf.close();
assertEquals(2, bs.refCount());
assertEquals("refCount: 1, 0, 2", mf.referenceCounts());
bs2.release();
assertEquals(1, mf.refCount());
assertEquals(1, bs.refCount());
bs.release();
assertEquals(0, bs.refCount());
assertEquals(0, mf.refCount());
assertEquals("refCount: 0, 0, 0", mf.referenceCounts());

Object Pools

There is String and Enum object pools to turn a CharSequence into a String.

Bytes b = Bytes.from("Hello World");
b.readSkip(6);

StringInterner si = new StringInterner(128);
String s = si.intern(b);
String s2 = si.intern(b);
assertEquals("World", s);
assertSame(s, s2);

Class Local Caching

Add caching of a data structure for each class using a lambda

public static final ClassLocal<EnumInterner> ENUM_INTERNER = 
        ClassLocal.withInitial(c -> new EnumInterner<>(c));
        
E enumValue = ENUM_INTERNER.get(enumClass).intern(stringBuilder);

Maths Functions

Maths functions to support rounds

double a = 0.1;
double b = 0.3;
double c= Maths.round2(b - a); // 0.2 rounded to 2 decimal places

Checking type conversions

int i = Maths.toInt32(longValue);

Serializable Lambdas

There is a number of FunctionalInterfaces you can utilise as method arguments. This allows implicitly making a lambda Serializable.

// in KeyedVisitable
default <R> R applyToKey(K key, @NotNull SerializableFunction<E, R> function) {

// in code

String fullename = map.applyToKey("u:123223", u -> u.getFullName());

Histogram

A high dynamic range histogram with tunable accuracy.

Histogram h = new Histogram(32, 4);
long start = instance.ticks(), prev = start;
for (int i = 0; i <= 1000_000_000; i++) {
    long now = instance.ticks();
    long time = now - prev;
    h.sample(time);
    prev = now;
}
System.out.println(h.toLongMicrosFormat(instance::toMicros));

JLBH

Java Latency Benchmark Harness is a tool that allows you to benchmark your code running in context, rather than in a microbenchmark. An excellent introduction can be found in this series of articles.

Since those articles were written the main change has been to allow JLBH to be installed to an event loop, rather than it running in its own thread. To do this, use the JLBH.eventLoopHandler method rather than JLBH.start.