mirror of
https://github.com/corda/corda.git
synced 2025-01-03 19:54:13 +00:00
zero heap space ahead of time when allocating raw storage and garbage collecting, not when allocating individual objects
This helps us support the Java Memory Model without adding a memory barrier to every object allocation. It's also potentially more efficient, since we zero out each heap segment all at once instead of bit-by-bit with each object allocation.
This commit is contained in:
parent
8410e1d683
commit
6e6035505c
@ -27,7 +27,7 @@ search(Thread* t, jstring name, object (*op)(Thread*, object),
|
||||
bool replaceDots)
|
||||
{
|
||||
if (LIKELY(name)) {
|
||||
object n = makeByteArray(t, stringLength(t, *name) + 1, false);
|
||||
object n = makeByteArray(t, stringLength(t, *name) + 1);
|
||||
char* s = reinterpret_cast<char*>(&byteArrayBody(t, n, 0));
|
||||
stringChars(t, *name, s);
|
||||
|
||||
@ -406,7 +406,7 @@ Java_java_lang_reflect_Array_makeObjectArray
|
||||
{
|
||||
ENTER(t, Thread::ActiveState);
|
||||
|
||||
return makeLocalReference(t, makeObjectArray(t, *elementType, length, true));
|
||||
return makeLocalReference(t, makeObjectArray(t, *elementType, length));
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
@ -671,7 +671,7 @@ Java_java_lang_Throwable_trace(Thread* t, jclass, jint skipCount)
|
||||
|
||||
t->m->processor->walkStack(t, &v);
|
||||
|
||||
if (v.trace == 0) v.trace = makeArray(t, 0, true);
|
||||
if (v.trace == 0) v.trace = makeArray(t, 0);
|
||||
|
||||
return makeLocalReference(t, v.trace);
|
||||
}
|
||||
@ -683,8 +683,7 @@ Java_java_lang_Throwable_resolveTrace(Thread* t, jclass, jobject trace)
|
||||
|
||||
unsigned length = arrayLength(t, *trace);
|
||||
object array = makeObjectArray
|
||||
(t, arrayBody(t, t->m->types, Machine::StackTraceElementType),
|
||||
length, true);
|
||||
(t, arrayBody(t, t->m->types, Machine::StackTraceElementType), length);
|
||||
PROTECT(t, array);
|
||||
|
||||
object e = 0;
|
||||
|
@ -1568,8 +1568,7 @@ uint64_t
|
||||
makeBlankObjectArray(MyThread* t, object class_, int32_t length)
|
||||
{
|
||||
if (length >= 0) {
|
||||
return reinterpret_cast<uint64_t>
|
||||
(makeObjectArray(t, class_, length, true));
|
||||
return reinterpret_cast<uint64_t>(makeObjectArray(t, class_, length));
|
||||
} else {
|
||||
object message = makeString(t, "%d", length);
|
||||
t->exception = makeNegativeArraySizeException(t, message);
|
||||
@ -1581,7 +1580,7 @@ uint64_t
|
||||
makeBlankArray(MyThread* t, unsigned type, int32_t length)
|
||||
{
|
||||
if (length >= 0) {
|
||||
object (*constructor)(Thread*, uintptr_t, bool);
|
||||
object (*constructor)(Thread*, uintptr_t);
|
||||
switch (type) {
|
||||
case T_BOOLEAN:
|
||||
constructor = makeBooleanArray;
|
||||
@ -1618,7 +1617,7 @@ makeBlankArray(MyThread* t, unsigned type, int32_t length)
|
||||
default: abort(t);
|
||||
}
|
||||
|
||||
return reinterpret_cast<uintptr_t>(constructor(t, length, true));
|
||||
return reinterpret_cast<uintptr_t>(constructor(t, length));
|
||||
} else {
|
||||
object message = makeString(t, "%d", length);
|
||||
t->exception = makeNegativeArraySizeException(t, message);
|
||||
@ -1698,7 +1697,7 @@ makeMultidimensionalArray2(MyThread* t, object class_, uintptr_t* countStack,
|
||||
}
|
||||
}
|
||||
|
||||
object array = makeArray(t, counts[0], true);
|
||||
object array = makeArray(t, counts[0]);
|
||||
setObjectClass(t, array, class_);
|
||||
PROTECT(t, array);
|
||||
|
||||
@ -3828,10 +3827,10 @@ translateExceptionHandlerTable(MyThread* t, Compiler* c, object code,
|
||||
|
||||
unsigned length = exceptionHandlerTableLength(t, oldTable);
|
||||
|
||||
object newIndex = makeIntArray(t, length * 3, false);
|
||||
object newIndex = makeIntArray(t, length * 3);
|
||||
PROTECT(t, newIndex);
|
||||
|
||||
object newTable = makeArray(t, length + 1, true);
|
||||
object newTable = makeArray(t, length + 1);
|
||||
PROTECT(t, newTable);
|
||||
|
||||
set(t, newTable, ArrayBody, newIndex);
|
||||
@ -3874,7 +3873,7 @@ translateLineNumberTable(MyThread* t, Compiler* c, object code, intptr_t start)
|
||||
PROTECT(t, oldTable);
|
||||
|
||||
unsigned length = lineNumberTableLength(t, oldTable);
|
||||
object newTable = makeLineNumberTable(t, length, false);
|
||||
object newTable = makeLineNumberTable(t, length);
|
||||
for (unsigned i = 0; i < length; ++i) {
|
||||
LineNumber* oldLine = lineNumberTableBody(t, oldTable, i);
|
||||
LineNumber* newLine = lineNumberTableBody(t, newTable, i);
|
||||
@ -4107,7 +4106,7 @@ finish(MyThread* t, Allocator* allocator, Context* context)
|
||||
FixedSizeOfArray + ((context->objectPoolCount + 1) * BytesPerWord),
|
||||
true);
|
||||
|
||||
initArray(t, pool, context->objectPoolCount + 1, false);
|
||||
initArray(t, pool, context->objectPoolCount + 1);
|
||||
mark(t, pool, 0);
|
||||
|
||||
set(t, pool, ArrayBody, objectPools(t));
|
||||
@ -4150,7 +4149,7 @@ finish(MyThread* t, Allocator* allocator, Context* context)
|
||||
codeLineNumberTable(t, code),
|
||||
codeMaxStack(t, code),
|
||||
codeMaxLocals(t, code),
|
||||
0, false);
|
||||
0);
|
||||
|
||||
set(t, context->method, MethodCode, code);
|
||||
}
|
||||
@ -4176,8 +4175,7 @@ finish(MyThread* t, Allocator* allocator, Context* context)
|
||||
unsigned size = usableFrameSizeWithParameters(t, context->method);
|
||||
object map = makeIntArray
|
||||
(t, context->traceLogCount
|
||||
+ ceiling(context->traceLogCount * size, 32),
|
||||
false);
|
||||
+ ceiling(context->traceLogCount * size, 32));
|
||||
|
||||
assert(t, intArrayLength(t, map) == context->traceLogCount
|
||||
+ frameObjectMapSize(t, context->method, map));
|
||||
@ -5076,7 +5074,7 @@ class MyProcessor: public Processor {
|
||||
return vm::makeClass
|
||||
(t, flags, vmFlags, arrayDimensions, fixedSize, arrayElementSize,
|
||||
objectMask, name, super, interfaceTable, virtualTable, fieldTable,
|
||||
methodTable, staticTable, loader, vtableLength, false);
|
||||
methodTable, staticTable, loader, vtableLength);
|
||||
}
|
||||
|
||||
virtual void
|
||||
@ -5399,7 +5397,7 @@ class MyProcessor: public Processor {
|
||||
if (image) {
|
||||
::boot(static_cast<MyThread*>(t), image);
|
||||
} else {
|
||||
callTable = makeArray(t, 128, true);
|
||||
callTable = makeArray(t, 128);
|
||||
|
||||
methodTree = methodTreeSentinal = makeTreeNode(t, 0, 0, 0);
|
||||
set(t, methodTree, TreeNodeLeft, methodTreeSentinal);
|
||||
@ -5471,7 +5469,7 @@ resizeTable(MyThread* t, object oldTable, unsigned newLength)
|
||||
object oldNode = 0;
|
||||
PROTECT(t, oldNode);
|
||||
|
||||
object newTable = makeArray(t, newLength, true);
|
||||
object newTable = makeArray(t, newLength);
|
||||
PROTECT(t, newTable);
|
||||
|
||||
for (unsigned i = 0; i < arrayLength(t, oldTable); ++i) {
|
||||
@ -5532,7 +5530,7 @@ insertCallNode(MyThread* t, object node)
|
||||
object
|
||||
makeClassMap(Thread* t, unsigned* table, unsigned count, uintptr_t* heap)
|
||||
{
|
||||
object array = makeArray(t, nextPowerOfTwo(count), true);
|
||||
object array = makeArray(t, nextPowerOfTwo(count));
|
||||
object map = makeHashMap(t, 0, array);
|
||||
PROTECT(t, map);
|
||||
|
||||
@ -5548,7 +5546,7 @@ object
|
||||
makeStaticTableArray(Thread* t, unsigned* table, unsigned count,
|
||||
uintptr_t* heap)
|
||||
{
|
||||
object array = makeArray(t, count, false);
|
||||
object array = makeArray(t, count);
|
||||
|
||||
for (unsigned i = 0; i < count; ++i) {
|
||||
set(t, array, ArrayBody + (i * BytesPerWord),
|
||||
@ -5561,7 +5559,7 @@ makeStaticTableArray(Thread* t, unsigned* table, unsigned count,
|
||||
object
|
||||
makeStringMap(Thread* t, unsigned* table, unsigned count, uintptr_t* heap)
|
||||
{
|
||||
object array = makeArray(t, nextPowerOfTwo(count), true);
|
||||
object array = makeArray(t, nextPowerOfTwo(count));
|
||||
object map = makeWeakHashMap(t, 0, array);
|
||||
PROTECT(t, map);
|
||||
|
||||
@ -5577,7 +5575,7 @@ object
|
||||
makeCallTable(MyThread* t, uintptr_t* heap, unsigned* calls, unsigned count,
|
||||
uintptr_t base)
|
||||
{
|
||||
object table = makeArray(t, nextPowerOfTwo(count), true);
|
||||
object table = makeArray(t, nextPowerOfTwo(count));
|
||||
PROTECT(t, table);
|
||||
|
||||
unsigned size = 0;
|
||||
|
@ -168,7 +168,7 @@ NewString(Thread* t, const jchar* chars, jsize size)
|
||||
|
||||
object a = 0;
|
||||
if (size) {
|
||||
a = makeCharArray(t, size, false);
|
||||
a = makeCharArray(t, size);
|
||||
memcpy(&charArrayBody(t, a, 0), chars, size * sizeof(jchar));
|
||||
}
|
||||
object s = makeString(t, a, 0, size, 0);
|
||||
@ -184,7 +184,7 @@ NewStringUTF(Thread* t, const char* chars)
|
||||
object a = 0;
|
||||
unsigned size = strlen(chars);
|
||||
if (size) {
|
||||
a = makeByteArray(t, size, false);
|
||||
a = makeByteArray(t, size);
|
||||
memcpy(&byteArrayBody(t, a, 0), chars, size);
|
||||
}
|
||||
object s = makeString(t, a, 0, size, 0);
|
||||
@ -208,7 +208,7 @@ FindClass(Thread* t, const char* name)
|
||||
{
|
||||
ENTER(t, Thread::ActiveState);
|
||||
|
||||
object n = makeByteArray(t, strlen(name) + 1, false);
|
||||
object n = makeByteArray(t, strlen(name) + 1);
|
||||
replace('.', '/', name, &byteArrayBody(t, n, 0));
|
||||
|
||||
return makeLocalReference(t, resolveClass(t, n));
|
||||
@ -1214,7 +1214,7 @@ NewObjectArray(Thread* t, jsize length, jclass class_, jobject init)
|
||||
{
|
||||
ENTER(t, Thread::ActiveState);
|
||||
|
||||
object a = makeObjectArray(t, *class_, length, false);
|
||||
object a = makeObjectArray(t, *class_, length);
|
||||
object value = (init ? *init : 0);
|
||||
for (jsize i = 0; i < length; ++i) {
|
||||
set(t, a, ArrayBody + (i * BytesPerWord), value);
|
||||
@ -1244,7 +1244,7 @@ NewBooleanArray(Thread* t, jsize length)
|
||||
{
|
||||
ENTER(t, Thread::ActiveState);
|
||||
|
||||
return makeLocalReference(t, makeBooleanArray(t, length, true));
|
||||
return makeLocalReference(t, makeBooleanArray(t, length));
|
||||
}
|
||||
|
||||
jbyteArray JNICALL
|
||||
@ -1252,7 +1252,7 @@ NewByteArray(Thread* t, jsize length)
|
||||
{
|
||||
ENTER(t, Thread::ActiveState);
|
||||
|
||||
return makeLocalReference(t, makeByteArray(t, length, true));
|
||||
return makeLocalReference(t, makeByteArray(t, length));
|
||||
}
|
||||
|
||||
jcharArray JNICALL
|
||||
@ -1260,7 +1260,7 @@ NewCharArray(Thread* t, jsize length)
|
||||
{
|
||||
ENTER(t, Thread::ActiveState);
|
||||
|
||||
return makeLocalReference(t, makeCharArray(t, length, true));
|
||||
return makeLocalReference(t, makeCharArray(t, length));
|
||||
}
|
||||
|
||||
jshortArray JNICALL
|
||||
@ -1268,7 +1268,7 @@ NewShortArray(Thread* t, jsize length)
|
||||
{
|
||||
ENTER(t, Thread::ActiveState);
|
||||
|
||||
return makeLocalReference(t, makeShortArray(t, length, true));
|
||||
return makeLocalReference(t, makeShortArray(t, length));
|
||||
}
|
||||
|
||||
jintArray JNICALL
|
||||
@ -1276,7 +1276,7 @@ NewIntArray(Thread* t, jsize length)
|
||||
{
|
||||
ENTER(t, Thread::ActiveState);
|
||||
|
||||
return makeLocalReference(t, makeIntArray(t, length, true));
|
||||
return makeLocalReference(t, makeIntArray(t, length));
|
||||
}
|
||||
|
||||
jlongArray JNICALL
|
||||
@ -1284,7 +1284,7 @@ NewLongArray(Thread* t, jsize length)
|
||||
{
|
||||
ENTER(t, Thread::ActiveState);
|
||||
|
||||
return makeLocalReference(t, makeLongArray(t, length, true));
|
||||
return makeLocalReference(t, makeLongArray(t, length));
|
||||
}
|
||||
|
||||
jfloatArray JNICALL
|
||||
@ -1292,7 +1292,7 @@ NewFloatArray(Thread* t, jsize length)
|
||||
{
|
||||
ENTER(t, Thread::ActiveState);
|
||||
|
||||
return makeLocalReference(t, makeFloatArray(t, length, true));
|
||||
return makeLocalReference(t, makeFloatArray(t, length));
|
||||
}
|
||||
|
||||
jdoubleArray JNICALL
|
||||
@ -1300,7 +1300,7 @@ NewDoubleArray(Thread* t, jsize length)
|
||||
{
|
||||
ENTER(t, Thread::ActiveState);
|
||||
|
||||
return makeLocalReference(t, makeDoubleArray(t, length, true));
|
||||
return makeLocalReference(t, makeDoubleArray(t, length));
|
||||
}
|
||||
|
||||
jboolean* JNICALL
|
||||
|
@ -453,9 +453,16 @@ postCollect(Thread* t)
|
||||
t->m->heap->free(t->defaultHeap, ThreadHeapSizeInBytes);
|
||||
t->defaultHeap = static_cast<uintptr_t*>
|
||||
(t->m->heap->allocate(ThreadHeapSizeInBytes));
|
||||
memset(t->defaultHeap, 0, ThreadHeapSizeInBytes);
|
||||
#endif
|
||||
|
||||
t->heap = t->defaultHeap;
|
||||
if (t->heap == t->defaultHeap) {
|
||||
memset(t->defaultHeap, 0, t->heapIndex * BytesPerWord);
|
||||
} else {
|
||||
memset(t->defaultHeap, 0, ThreadHeapSizeInBytes);
|
||||
t->heap = t->defaultHeap;
|
||||
}
|
||||
|
||||
t->heapOffset = 0;
|
||||
t->heapIndex = 0;
|
||||
|
||||
@ -481,7 +488,7 @@ makeByteArray(Thread* t, const char* format, va_list a)
|
||||
int r = vsnprintf(buffer, Size - 1, format, a);
|
||||
expect(t, r >= 0 and r < Size - 1);
|
||||
|
||||
object s = makeByteArray(t, strlen(buffer) + 1, false);
|
||||
object s = makeByteArray(t, strlen(buffer) + 1);
|
||||
memcpy(&byteArrayBody(t, s, 0), buffer, byteArrayLength(t, s));
|
||||
|
||||
return s;
|
||||
@ -490,7 +497,7 @@ makeByteArray(Thread* t, const char* format, va_list a)
|
||||
object
|
||||
parseUtf8(Thread* t, Stream& s, unsigned length)
|
||||
{
|
||||
object value = makeByteArray(t, length + 1, false);
|
||||
object value = makeByteArray(t, length + 1);
|
||||
unsigned vi = 0;
|
||||
for (unsigned si = 0; si < length; ++si) {
|
||||
unsigned a = s.read1();
|
||||
@ -523,7 +530,7 @@ parseUtf8(Thread* t, Stream& s, unsigned length)
|
||||
if (vi < length) {
|
||||
PROTECT(t, value);
|
||||
|
||||
object v = makeByteArray(t, vi + 1, false);
|
||||
object v = makeByteArray(t, vi + 1);
|
||||
memcpy(&byteArrayBody(t, v, 0), &byteArrayBody(t, value, 0), vi);
|
||||
value = v;
|
||||
}
|
||||
@ -622,7 +629,7 @@ parsePool(Thread* t, Stream& s)
|
||||
{
|
||||
unsigned count = s.read2() - 1;
|
||||
|
||||
object pool = makeSingleton(t, count);
|
||||
object pool = makeSingletonOfSize(t, count);
|
||||
PROTECT(t, pool);
|
||||
|
||||
if (count) {
|
||||
@ -734,7 +741,7 @@ parseInterfaceTable(Thread* t, Stream& s, object class_, object pool)
|
||||
if ((classFlags(t, class_) & ACC_INTERFACE) == 0) {
|
||||
length *= 2;
|
||||
}
|
||||
interfaceTable = makeArray(t, length, true);
|
||||
interfaceTable = makeArray(t, length);
|
||||
PROTECT(t, interfaceTable);
|
||||
|
||||
unsigned i = 0;
|
||||
@ -749,7 +756,7 @@ parseInterfaceTable(Thread* t, Stream& s, object class_, object pool)
|
||||
if (classVirtualTable(t, interface)) {
|
||||
// we'll fill in this table in parseMethodTable():
|
||||
object vtable = makeArray
|
||||
(t, arrayLength(t, classVirtualTable(t, interface)), true);
|
||||
(t, arrayLength(t, classVirtualTable(t, interface)));
|
||||
|
||||
set(t, interfaceTable, ArrayBody + (i * BytesPerWord), vtable);
|
||||
}
|
||||
@ -778,10 +785,10 @@ parseFieldTable(Thread* t, Stream& s, object class_, object pool)
|
||||
unsigned staticOffset = BytesPerWord * 2;
|
||||
unsigned staticCount = 0;
|
||||
|
||||
object fieldTable = makeArray(t, count, true);
|
||||
object fieldTable = makeArray(t, count);
|
||||
PROTECT(t, fieldTable);
|
||||
|
||||
object staticValueTable = makeIntArray(t, count, false);
|
||||
object staticValueTable = makeIntArray(t, count);
|
||||
PROTECT(t, staticValueTable);
|
||||
|
||||
uint8_t staticTypes[count];
|
||||
@ -856,7 +863,7 @@ parseFieldTable(Thread* t, Stream& s, object class_, object pool)
|
||||
if (staticCount) {
|
||||
unsigned footprint = ceiling(staticOffset - (BytesPerWord * 2),
|
||||
BytesPerWord);
|
||||
object staticTable = makeSingleton(t, footprint);
|
||||
object staticTable = makeSingletonOfSize(t, footprint);
|
||||
|
||||
uint8_t* body = reinterpret_cast<uint8_t*>
|
||||
(&singletonBody(t, staticTable, 0));
|
||||
@ -901,8 +908,6 @@ parseFieldTable(Thread* t, Stream& s, object class_, object pool)
|
||||
|
||||
default: abort(t);
|
||||
}
|
||||
} else {
|
||||
memset(body + offset, 0, size);
|
||||
}
|
||||
|
||||
if (staticTypes[i] == ObjectField) {
|
||||
@ -925,7 +930,7 @@ parseFieldTable(Thread* t, Stream& s, object class_, object pool)
|
||||
classObjectMask(t, classSuper(t, class_)));
|
||||
} else {
|
||||
object mask = makeIntArray
|
||||
(t, ceiling(classFixedSize(t, class_), 32 * BytesPerWord), true);
|
||||
(t, ceiling(classFixedSize(t, class_), 32 * BytesPerWord));
|
||||
intArrayBody(t, mask, 0) = 1;
|
||||
|
||||
object superMask = 0;
|
||||
@ -970,13 +975,13 @@ parseCode(Thread* t, Stream& s, object pool)
|
||||
unsigned maxLocals = s.read2();
|
||||
unsigned length = s.read4();
|
||||
|
||||
object code = makeCode(t, pool, 0, 0, maxStack, maxLocals, length, false);
|
||||
object code = makeCode(t, pool, 0, 0, maxStack, maxLocals, length);
|
||||
s.read(&codeBody(t, code, 0), length);
|
||||
PROTECT(t, code);
|
||||
|
||||
unsigned ehtLength = s.read2();
|
||||
if (ehtLength) {
|
||||
object eht = makeExceptionHandlerTable(t, ehtLength, false);
|
||||
object eht = makeExceptionHandlerTable(t, ehtLength);
|
||||
for (unsigned i = 0; i < ehtLength; ++i) {
|
||||
ExceptionHandler* eh = exceptionHandlerTableBody(t, eht, i);
|
||||
exceptionHandlerStart(eh) = s.read2();
|
||||
@ -997,7 +1002,7 @@ parseCode(Thread* t, Stream& s, object pool)
|
||||
&byteArrayBody(t, name, 0)) == 0)
|
||||
{
|
||||
unsigned lntLength = s.read2();
|
||||
object lnt = makeLineNumberTable(t, lntLength, false);
|
||||
object lnt = makeLineNumberTable(t, lntLength);
|
||||
for (unsigned i = 0; i < lntLength; ++i) {
|
||||
LineNumber* ln = lineNumberTableBody(t, lnt, i);
|
||||
lineNumberIp(ln) = s.read2();
|
||||
@ -1094,7 +1099,7 @@ parseMethodTable(Thread* t, Stream& s, object class_, object pool)
|
||||
|
||||
unsigned count = s.read2();
|
||||
if (count) {
|
||||
object methodTable = makeArray(t, count, true);
|
||||
object methodTable = makeArray(t, count);
|
||||
PROTECT(t, methodTable);
|
||||
|
||||
for (unsigned i = 0; i < count; ++i) {
|
||||
@ -1199,13 +1204,13 @@ parseMethodTable(Thread* t, Stream& s, object class_, object pool)
|
||||
} else {
|
||||
// apparently, Object does not have any virtual methods. We
|
||||
// give it a vtable anyway so code doesn't break elsewhere.
|
||||
object vtable = makeArray(t, 0, false);
|
||||
object vtable = makeArray(t, 0);
|
||||
set(t, class_, ClassVirtualTable, vtable);
|
||||
}
|
||||
} else if (virtualCount) {
|
||||
// generate class vtable
|
||||
|
||||
object vtable = makeArray(t, virtualCount, true);
|
||||
object vtable = makeArray(t, virtualCount);
|
||||
|
||||
unsigned i = 0;
|
||||
if (classFlags(t, class_) & ACC_INTERFACE) {
|
||||
@ -1384,7 +1389,7 @@ makeArrayClass(Thread* t, object spec)
|
||||
const char* elementSpecStart = s;
|
||||
while (*s and *s != ';') ++ s;
|
||||
|
||||
elementSpec = makeByteArray(t, s - elementSpecStart + 1, false);
|
||||
elementSpec = makeByteArray(t, s - elementSpecStart + 1);
|
||||
memcpy(&byteArrayBody(t, elementSpec, 0),
|
||||
&byteArrayBody(t, spec, elementSpecStart - start),
|
||||
s - elementSpecStart);
|
||||
@ -1394,7 +1399,7 @@ makeArrayClass(Thread* t, object spec)
|
||||
default:
|
||||
if (dimensions > 1) {
|
||||
char c = *s;
|
||||
elementSpec = makeByteArray(t, 3, false);
|
||||
elementSpec = makeByteArray(t, 3);
|
||||
byteArrayBody(t, elementSpec, 0) = '[';
|
||||
byteArrayBody(t, elementSpec, 1) = c;
|
||||
byteArrayBody(t, elementSpec, 2) = 0;
|
||||
@ -1460,7 +1465,7 @@ bootClass(Thread* t, Machine::Type type, int superType, uint32_t objectMask,
|
||||
{
|
||||
mask = classObjectMask(t, arrayBody(t, t->m->types, superType));
|
||||
} else {
|
||||
mask = makeIntArray(t, 1, false);
|
||||
mask = makeIntArray(t, 1);
|
||||
intArrayBody(t, mask, 0) = objectMask;
|
||||
}
|
||||
} else {
|
||||
@ -1491,7 +1496,7 @@ bootJavaClass(Thread* t, Machine::Type type, int superType, const char* name,
|
||||
if (vtableLength >= 0) {
|
||||
PROTECT(t, class_);
|
||||
|
||||
vtable = makeArray(t, vtableLength, false);
|
||||
vtable = makeArray(t, vtableLength);
|
||||
for (int i = 0; i < vtableLength; ++ i) {
|
||||
arrayBody(t, vtable, i) = bootMethod;
|
||||
}
|
||||
@ -1514,11 +1519,9 @@ boot(Thread* t)
|
||||
m->unsafe = true;
|
||||
|
||||
m->loader = allocate(t, sizeof(void*) * 3, true);
|
||||
memset(m->loader, 0, sizeof(void*) * 2);
|
||||
|
||||
m->types = allocate(t, pad((TypeCount + 2) * BytesPerWord), true);
|
||||
arrayLength(t, m->types) = TypeCount;
|
||||
memset(&arrayBody(t, m->types, 0), 0, TypeCount * BytesPerWord);
|
||||
|
||||
#include "type-initializations.cpp"
|
||||
|
||||
@ -1578,7 +1581,7 @@ boot(Thread* t)
|
||||
|
||||
m->processor->boot(t, 0);
|
||||
|
||||
{ object bootCode = makeCode(t, 0, 0, 0, 0, 0, 1, false);
|
||||
{ object bootCode = makeCode(t, 0, 0, 0, 0, 0, 1);
|
||||
codeBody(t, bootCode, 0) = impdep1;
|
||||
object bootMethod = makeMethod
|
||||
(t, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, bootCode, 0);
|
||||
@ -1792,6 +1795,8 @@ Thread::Thread(Machine* m, object javaThread, Thread* parent):
|
||||
void
|
||||
Thread::init()
|
||||
{
|
||||
memset(defaultHeap, 0, ThreadHeapSizeInBytes);
|
||||
|
||||
if (parent == 0) {
|
||||
assert(this, m->rootThread == 0);
|
||||
assert(this, javaThread == 0);
|
||||
@ -1826,7 +1831,7 @@ Thread::init()
|
||||
|
||||
m->monitorMap = makeWeakHashMap(this, 0, 0);
|
||||
|
||||
m->jniMethodTable = makeVector(this, 0, 0, false);
|
||||
m->jniMethodTable = makeVector(this, 0, 0);
|
||||
|
||||
m->localThread->set(this);
|
||||
} else {
|
||||
@ -2063,7 +2068,10 @@ allocate3(Thread* t, Allocator* allocator, Machine::AllocationType type,
|
||||
if (t->m->heapPoolIndex < ThreadHeapPoolSize) {
|
||||
t->heap = static_cast<uintptr_t*>
|
||||
(t->m->heap->tryAllocate(ThreadHeapSizeInBytes));
|
||||
|
||||
if (t->heap) {
|
||||
memset(t->heap, 0, ThreadHeapSizeInBytes);
|
||||
|
||||
t->m->heapPool[t->m->heapPoolIndex++] = t->heap;
|
||||
t->heapOffset += t->heapIndex;
|
||||
t->heapIndex = 0;
|
||||
@ -2099,6 +2107,8 @@ allocate3(Thread* t, Allocator* allocator, Machine::AllocationType type,
|
||||
(t->m->heap->allocateFixed
|
||||
(allocator, ceiling(sizeInBytes, BytesPerWord), objectMask, &total));
|
||||
|
||||
memset(o, 0, sizeInBytes);
|
||||
|
||||
cast<uintptr_t>(o, 0) = FixedMark;
|
||||
|
||||
t->m->fixedFootprint += total;
|
||||
@ -2112,6 +2122,8 @@ allocate3(Thread* t, Allocator* allocator, Machine::AllocationType type,
|
||||
(t->m->heap->allocateImmortalFixed
|
||||
(allocator, ceiling(sizeInBytes, BytesPerWord), objectMask, &total));
|
||||
|
||||
memset(o, 0, sizeInBytes);
|
||||
|
||||
cast<uintptr_t>(o, 0) = FixedMark;
|
||||
|
||||
return o;
|
||||
@ -2376,8 +2388,7 @@ parseClass(Thread* t, const uint8_t* data, unsigned size)
|
||||
0, // methods
|
||||
0, // static table
|
||||
t->m->loader,
|
||||
0, // vtable length
|
||||
false);
|
||||
0);// vtable length
|
||||
PROTECT(t, class_);
|
||||
|
||||
unsigned super = s.read2();
|
||||
@ -2526,13 +2537,13 @@ resolveObjectArrayClass(Thread* t, object elementSpec)
|
||||
|
||||
object spec;
|
||||
if (byteArrayBody(t, elementSpec, 0) == '[') {
|
||||
spec = makeByteArray(t, byteArrayLength(t, elementSpec) + 1, false);
|
||||
spec = makeByteArray(t, byteArrayLength(t, elementSpec) + 1);
|
||||
byteArrayBody(t, spec, 0) = '[';
|
||||
memcpy(&byteArrayBody(t, spec, 1),
|
||||
&byteArrayBody(t, elementSpec, 0),
|
||||
byteArrayLength(t, elementSpec));
|
||||
} else {
|
||||
spec = makeByteArray(t, byteArrayLength(t, elementSpec) + 3, false);
|
||||
spec = makeByteArray(t, byteArrayLength(t, elementSpec) + 3);
|
||||
byteArrayBody(t, spec, 0) = '[';
|
||||
byteArrayBody(t, spec, 1) = 'L';
|
||||
memcpy(&byteArrayBody(t, spec, 2),
|
||||
@ -2546,12 +2557,12 @@ resolveObjectArrayClass(Thread* t, object elementSpec)
|
||||
}
|
||||
|
||||
object
|
||||
makeObjectArray(Thread* t, object elementClass, unsigned count, bool clear)
|
||||
makeObjectArray(Thread* t, object elementClass, unsigned count)
|
||||
{
|
||||
object arrayClass = resolveObjectArrayClass(t, className(t, elementClass));
|
||||
PROTECT(t, arrayClass);
|
||||
|
||||
object array = makeArray(t, count, clear);
|
||||
object array = makeArray(t, count);
|
||||
setObjectClass(t, array, arrayClass);
|
||||
|
||||
return array;
|
||||
@ -2900,7 +2911,7 @@ makeTrace(Thread* t, Processor::StackWalker* walker)
|
||||
|
||||
virtual bool visit(Processor::StackWalker* walker) {
|
||||
if (trace == 0) {
|
||||
trace = makeArray(t, walker->count(), true);
|
||||
trace = makeArray(t, walker->count());
|
||||
}
|
||||
|
||||
object e = makeTraceElement(t, walker->method(), walker->ip());
|
||||
@ -2918,7 +2929,7 @@ makeTrace(Thread* t, Processor::StackWalker* walker)
|
||||
|
||||
walker->walk(&v);
|
||||
|
||||
return v.trace ? v.trace : makeArray(t, 0, true);
|
||||
return v.trace ? v.trace : makeArray(t, 0);
|
||||
}
|
||||
|
||||
object
|
||||
@ -2939,7 +2950,7 @@ makeTrace(Thread* t, Thread* target)
|
||||
|
||||
t->m->processor->walkStack(target, &v);
|
||||
|
||||
return v.trace ? v.trace : makeArray(t, 0, true);
|
||||
return v.trace ? v.trace : makeArray(t, 0);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1490,6 +1490,9 @@ ensure(Thread* t, unsigned sizeInBytes)
|
||||
expect(t, t->backupHeap == 0);
|
||||
t->backupHeap = static_cast<uintptr_t*>
|
||||
(t->m->heap->allocate(pad(sizeInBytes)));
|
||||
|
||||
memset(t->backupHeap, 0, sizeInBytes);
|
||||
|
||||
t->backupHeapIndex = 0;
|
||||
t->backupHeapSizeInWords = ceiling(sizeInBytes, BytesPerWord);
|
||||
}
|
||||
@ -1763,8 +1766,6 @@ makeNew(Thread* t, object class_)
|
||||
unsigned sizeInBytes = pad(classFixedSize(t, class_));
|
||||
object instance = allocate(t, sizeInBytes, classObjectMask(t, class_));
|
||||
setObjectClass(t, instance, class_);
|
||||
memset(&cast<object>(instance, BytesPerWord), 0,
|
||||
sizeInBytes - BytesPerWord);
|
||||
|
||||
return instance;
|
||||
}
|
||||
@ -2068,7 +2069,7 @@ initClass(Thread* t, object c)
|
||||
}
|
||||
|
||||
object
|
||||
makeObjectArray(Thread* t, object elementClass, unsigned count, bool clear);
|
||||
makeObjectArray(Thread* t, object elementClass, unsigned count);
|
||||
|
||||
object
|
||||
findInTable(Thread* t, object table, object name, object spec,
|
||||
@ -2358,9 +2359,9 @@ singletonValue(Thread* t, object singleton, unsigned index)
|
||||
}
|
||||
|
||||
inline object
|
||||
makeSingleton(Thread* t, unsigned count)
|
||||
makeSingletonOfSize(Thread* t, unsigned count)
|
||||
{
|
||||
object o = makeSingleton(t, count + singletonMaskSize(count), true);
|
||||
object o = makeSingleton(t, count + singletonMaskSize(count));
|
||||
assert(t, singletonLength(t, o) == count + singletonMaskSize(t, o));
|
||||
if (count) {
|
||||
singletonMask(t, o)[0] = 1;
|
||||
|
@ -167,8 +167,7 @@ populateMultiArray(Thread* t, object array, int32_t* counts,
|
||||
object spec = className(t, objectClass(t, array));
|
||||
PROTECT(t, spec);
|
||||
|
||||
object elementSpec = makeByteArray
|
||||
(t, byteArrayLength(t, spec) - 1, false);
|
||||
object elementSpec = makeByteArray(t, byteArrayLength(t, spec) - 1);
|
||||
memcpy(&byteArrayBody(t, elementSpec, 0),
|
||||
&byteArrayBody(t, spec, 1),
|
||||
byteArrayLength(t, spec) - 1);
|
||||
@ -177,7 +176,7 @@ populateMultiArray(Thread* t, object array, int32_t* counts,
|
||||
PROTECT(t, class_);
|
||||
|
||||
for (int32_t i = 0; i < counts[index]; ++i) {
|
||||
object a = makeArray(t, counts[index + 1], true);
|
||||
object a = makeArray(t, counts[index + 1]);
|
||||
setObjectClass(t, a, class_);
|
||||
set(t, array, ArrayBody + (i * BytesPerWord), a);
|
||||
|
||||
|
@ -1796,10 +1796,6 @@ writeConstructorParameters(Output* out, Object* t)
|
||||
out->write(" ");
|
||||
out->write(obfuscate(memberName(m)));
|
||||
} break;
|
||||
|
||||
case Object::Array: {
|
||||
out->write(", bool clear");
|
||||
} break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
@ -1816,10 +1812,6 @@ writeConstructorArguments(Output* out, Object* t)
|
||||
out->write(", ");
|
||||
out->write(obfuscate(memberName(m)));
|
||||
} break;
|
||||
|
||||
case Object::Array: {
|
||||
out->write(", clear");
|
||||
} break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
@ -1839,17 +1831,6 @@ writeConstructorInitializations(Output* out, Object* t)
|
||||
out->write(obfuscate(memberName(m)));
|
||||
out->write(";\n");
|
||||
} break;
|
||||
|
||||
case Object::Array: {
|
||||
out->write(" if (clear and length) memset(");
|
||||
if (memberTypeObject(m) == 0) {
|
||||
out->write("&");
|
||||
}
|
||||
writeAccessorName(out, m);
|
||||
out->write("(t, o, 0), 0, length * ");
|
||||
out->write(arrayElementSize(m));
|
||||
out->write(");\n");
|
||||
} break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
|
@ -358,7 +358,7 @@ hashMapResize(Thread* t, object map, uint32_t (*hash)(Thread*, object),
|
||||
return;
|
||||
}
|
||||
|
||||
newArray = makeArray(t, newLength, true);
|
||||
newArray = makeArray(t, newLength);
|
||||
|
||||
if (oldArray != hashMapArray(t, map)) {
|
||||
// a resize was performed during a GC via the makeArray call
|
||||
@ -525,7 +525,7 @@ vectorAppend(Thread* t, object vector, object value)
|
||||
PROTECT(t, value);
|
||||
|
||||
object newVector = makeVector
|
||||
(t, vectorSize(t, vector), max(16, vectorSize(t, vector) * 2), false);
|
||||
(t, vectorSize(t, vector), max(16, vectorSize(t, vector) * 2));
|
||||
|
||||
if (vectorSize(t, vector)) {
|
||||
memcpy(&vectorBody(t, newVector, 0),
|
||||
|
Loading…
Reference in New Issue
Block a user