mirror of
https://github.com/corda/corda.git
synced 2024-12-29 09:18:58 +00:00
4dbd404f64
* Remove non-deterministic classes from Avian (wip). * Complete integration between Avian and our local OpenJDK fork. * Revert accidental Avian modification. * Implements a "blacklist filter" for Avian's system classloader. * Remove .DSA, .RSA, .SF and .MF files when creating a fat jar. * Revert more accidental Avian changes. * Fix breakage with dependencies, and retain Kryo instance. * Apply blacklisting per thread rather than globally. * Blacklist java.lang.ClassLoader and all java.lang.Thread* classes. * Add comment explaining class blacklisting. * Fix Avian when building without OpenJDK. * Configure ProGuard to keep more classes for deserialisation. * Retain explicit return type for secure random function. * Add sources of random numbers to the class blacklist. * Blacklist the threading classes more precisely. * Make SystemClassLoader.isForbidden() static. * Prevent ProGuard from removing SerializedLambda.readResolve(). * Remove Avian tests involving direct buffers.
65 lines
1.8 KiB
Java
65 lines
1.8 KiB
Java
/**
|
|
* Demonstrates slow multithreaded memory access.
|
|
*/
|
|
public class MemoryRamp implements Runnable {
|
|
|
|
private static final int ARRAY_SIZE = 10 * 1024 * 1024; //10 MB in byte
|
|
private static final boolean ACCESS_ARRAY = true;
|
|
|
|
@Override
|
|
public void run() {
|
|
mem();
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
// get timing for single thread
|
|
long singleTime = mem();
|
|
System.out.println("Single thread: " + singleTime + "ms");
|
|
|
|
// run the same method with different thread numbers
|
|
for (int threadCount : new int[] {2, 3, 4}) {
|
|
long time = memMulti(threadCount);
|
|
double timeFactor = 1.0 * singleTime * threadCount / time;
|
|
System.out.println(threadCount + " threads: " + time + "ms (" + timeFactor + "x)");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Creates and accesses a ARRAY_SIZE big byte[].
|
|
* @return time to create and access array in milliseconds
|
|
*/
|
|
private static long mem() {
|
|
final byte[] array = new byte[ARRAY_SIZE];
|
|
if (ACCESS_ARRAY) {
|
|
for (int i = 0; i < array.length; i++) {
|
|
//array[i] = (byte) 170; //write
|
|
byte x = array[i]; //read
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* Starts multiple threads and runs mem() in each one.
|
|
* @return total time for all threads
|
|
*/
|
|
private static long memMulti(int numOfThreads) {
|
|
Thread[] threads = new Thread[numOfThreads];
|
|
|
|
for (int i = 0; i < threads.length; i++) {
|
|
threads[i] = new Thread(new MemoryRamp(), "mem-");
|
|
threads[i].start();
|
|
}
|
|
|
|
try {
|
|
for (Thread thread : threads) {
|
|
thread.join();
|
|
}
|
|
}
|
|
catch (InterruptedException iex) {
|
|
throw new RuntimeException(iex);
|
|
}
|
|
return 0;
|
|
}
|
|
}
|