This commit is contained in:
Marco Castelluccio 2015-08-14 22:45:59 +02:00
Родитель f4f9f08ad4 a7a689440a
Коммит 3fbd965073
4 изменённых файлов: 68 добавлений и 14 удалений

57
bench/ArrayBench.java Normal file
Просмотреть файл

@ -0,0 +1,57 @@
package benchmark;
import com.sun.cldchi.jvm.JVM;
public class ArrayBench {
void runConstantIterationBenchmark() {
long start, time;
int len = 1;
int iterations = 1000;
System.out.println("Time to allocate int arrays of variable lengths a constant " + iterations + " times, by length, in ms:");
for (int i = 0; i < 20; i++) {
start = JVM.monotonicTimeMillis();
for (int j = 0; j < iterations; j++) {
int[] array = new int[len];
}
time = JVM.monotonicTimeMillis() - start;
System.out.println("ArrayBench-" + len + ": " + time);
// There's no Math.pow in J2ME, so we multiply length ourselves.
len = len * 2;
}
}
void runVariableIterationBenchmark() {
long start, time;
int len = 1;
int iterations = 0;
System.out.println("Time to allocate int arrays of variable lengths a variable number of times, by length * iterations, in ms:");
for (int i = 0; i < 20; i++) {
// There's no Math.pow in J2ME, so we multiply iterations ourselves.
iterations = 1;
for (int k = 1; k < (20 - i); k++) {
iterations *= 2;
}
start = JVM.monotonicTimeMillis();
for (int j = 0; j < iterations; j++) {
int[] array = new int[len];
}
time = JVM.monotonicTimeMillis() - start;
System.out.println("ArrayBench-" + len + "*" + iterations + ": " + time);
len = len * 2;
}
}
public static void main(String args[]) {
ArrayBench bench = new ArrayBench();
bench.runConstantIterationBenchmark();
bench.runVariableIterationBenchmark();
}
}

Просмотреть файл

@ -285,11 +285,12 @@ tests.push(function() {
next();
});
tests.push(function() {
// Since we can't control where the memory is allocated by Boehm, we allocate it multiple times
// hoping that within 1000 iterations the areas allocated by the gcMallocAtomic calls will
// collide (in my testing this happens within 2 iterations, so 1000 should be a safe bet).
// For the zero-out tests below, since we can't control where the memory
// is allocated by Boehm, we allocate it multiple times hoping that within 1000
// iterations the areas allocated by the allocations will collide (in my testing
// this happens within 2 iterations, so 1000 should be a safe bet).
tests.push(function() {
var zeroedOut = true;
for (var i = 0; i < 1000; i++) {
var addr = ASM._gcMallocAtomic(8);
@ -311,7 +312,7 @@ tests.push(function() {
ASM._forceCollection();
}
ok(!zeroedOut, "gcMallocAtomic doesn't zero-out allocated memory");
ok(zeroedOut, "gcMallocAtomic does zero-out allocated memory");
next();
});
@ -338,7 +339,7 @@ tests.push(function() {
ASM._forceCollection();
}
ok(zeroedOut, "newArray does zero-out allocated memory");
ok(zeroedOut, "newIntArray does zero-out allocated memory");
next();
});

Просмотреть файл

@ -8,6 +8,7 @@
#include <stdlib.h>
#include <inttypes.h>
#include <emscripten.h>
#include <string.h>
// #define GC_NONE
#define GC_NONE_HEAP_CHUNK_SIZE (2 * 1024 * 1024)
@ -108,7 +109,9 @@ extern "C" {
#ifdef GC_NONE
return gcMalloc(size);
#else
return (uintptr_t)GC_MALLOC_ATOMIC(size);
uintptr_t ptr = (uintptr_t)GC_MALLOC_ATOMIC(size);
memset((void*)ptr, 0, size);
return ptr;
#endif
}

Просмотреть файл

@ -1420,13 +1420,6 @@ module J2ME {
if (elementClassInfo instanceof PrimitiveClassInfo) {
addr = gcMallocAtomic(Constants.ARRAY_HDR_SIZE + size * (<PrimitiveArrayClassInfo>arrayClassInfo).bytesPerElement);
// Zero-out memory because GC_MALLOC_ATOMIC doesn't do it automatically.
var off = Constants.ARRAY_HDR_SIZE + addr;
var end = off + size * (<PrimitiveArrayClassInfo>arrayClassInfo).bytesPerElement;
for (var i = off; i < end; i++) {
i8[i] = 0;
}
} else {
// We need to hold an integer to define the length of the array
// and *size* references.