mirror of
https://github.com/corda/corda.git
synced 2024-12-28 16:58:55 +00:00
heap o' bugfixes
This commit is contained in:
parent
eba6a42700
commit
93748f2df9
@ -20,15 +20,15 @@ public class TestThreads implements Runnable {
|
|||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
try {
|
try {
|
||||||
System.out.println("I'm running in a seperate thread!");
|
System.out.println("I'm running in a separate thread!");
|
||||||
|
|
||||||
final int arrayCount = 8;
|
// final int arrayCount = 8;
|
||||||
final int arraySize = 4;
|
// final int arraySize = 4;
|
||||||
System.out.println("Allocating and discarding " + arrayCount +
|
// System.out.println("Allocating and discarding " + arrayCount +
|
||||||
" arrays of " + arraySize + "MB each");
|
// " arrays of " + arraySize + "MB each");
|
||||||
for (; i < arrayCount; ++i) {
|
// for (; i < arrayCount; ++i) {
|
||||||
byte[] array = new byte[arraySize * 1024 * 1024];
|
// byte[] array = new byte[arraySize * 1024 * 1024];
|
||||||
}
|
// }
|
||||||
|
|
||||||
long nap = 5;
|
long nap = 5;
|
||||||
System.out.println("sleeping for " + nap + " seconds");
|
System.out.println("sleeping for " + nap + " seconds");
|
||||||
|
@ -27,7 +27,7 @@ public class StringBuilder {
|
|||||||
index -= c.value.length();
|
index -= c.value.length();
|
||||||
c.value.getChars(0, c.value.length(), array, index);
|
c.value.getChars(0, c.value.length(), array, index);
|
||||||
}
|
}
|
||||||
return new String(array, 0, array.length, false);
|
return new String(array, 0, length, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Cell {
|
private static class Cell {
|
||||||
|
2
makefile
2
makefile
@ -29,7 +29,7 @@ thread-cflags = -pthread
|
|||||||
thread-lflags = -lpthread
|
thread-lflags = -lpthread
|
||||||
|
|
||||||
cflags = $(warnings) -fPIC -fno-rtti -fno-exceptions -fvisibility=hidden \
|
cflags = $(warnings) -fPIC -fno-rtti -fno-exceptions -fvisibility=hidden \
|
||||||
-I$(src) -I$(bld) $(thread-cflags)
|
-I$(src) -I$(bld) $(thread-cflags) -D__STDC_LIMIT_MACROS
|
||||||
lflags = $(thread-lflags) -ldl
|
lflags = $(thread-lflags) -ldl
|
||||||
test-cflags = -DDEBUG_MEMORY
|
test-cflags = -DDEBUG_MEMORY
|
||||||
stress-cflags = -DDEBUG_MEMORY -DDEBUG_MEMORY_MAJOR
|
stress-cflags = -DDEBUG_MEMORY -DDEBUG_MEMORY_MAJOR
|
||||||
|
@ -34,6 +34,16 @@ notifyAll(Thread* t, jobject this_)
|
|||||||
vm::notifyAll(t, *this_);
|
vm::notifyAll(t, *this_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sleep(Thread* t, jlong milliseconds)
|
||||||
|
{
|
||||||
|
if (milliseconds == 0) milliseconds = INT64_MAX;
|
||||||
|
|
||||||
|
ENTER(t, Thread::IdleState);
|
||||||
|
|
||||||
|
t->vm->system->sleep(milliseconds);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
loadLibrary(Thread* t, jstring nameString)
|
loadLibrary(Thread* t, jstring nameString)
|
||||||
{
|
{
|
||||||
@ -68,7 +78,7 @@ arraycopy(Thread* t, jobject src, jint srcOffset, jobject dst, jint dstOffset,
|
|||||||
unsigned elementSize = classArrayElementSize(t, objectClass(t, s));
|
unsigned elementSize = classArrayElementSize(t, objectClass(t, s));
|
||||||
|
|
||||||
if (LIKELY(elementSize)) {
|
if (LIKELY(elementSize)) {
|
||||||
unsigned offset = 0;
|
unsigned offset = 1;
|
||||||
|
|
||||||
if (objectClass(t, s)
|
if (objectClass(t, s)
|
||||||
== arrayBody(t, t->vm->types, Machine::ObjectArrayType))
|
== arrayBody(t, t->vm->types, Machine::ObjectArrayType))
|
||||||
@ -76,7 +86,7 @@ arraycopy(Thread* t, jobject src, jint srcOffset, jobject dst, jint dstOffset,
|
|||||||
if (LIKELY(objectArrayElementClass(t, s)
|
if (LIKELY(objectArrayElementClass(t, s)
|
||||||
== objectArrayElementClass(t, d)))
|
== objectArrayElementClass(t, d)))
|
||||||
{
|
{
|
||||||
offset = 1;
|
offset = 2;
|
||||||
} else {
|
} else {
|
||||||
t->exception = makeArrayStoreException(t);
|
t->exception = makeArrayStoreException(t);
|
||||||
return;
|
return;
|
||||||
@ -86,12 +96,12 @@ arraycopy(Thread* t, jobject src, jint srcOffset, jobject dst, jint dstOffset,
|
|||||||
intptr_t sl = cast<uintptr_t>(s, offset * BytesPerWord);
|
intptr_t sl = cast<uintptr_t>(s, offset * BytesPerWord);
|
||||||
intptr_t dl = cast<uintptr_t>(d, offset * BytesPerWord);
|
intptr_t dl = cast<uintptr_t>(d, offset * BytesPerWord);
|
||||||
if (LIKELY(srcOffset >= 0 and srcOffset + length <= sl and
|
if (LIKELY(srcOffset >= 0 and srcOffset + length <= sl and
|
||||||
dstOffset >= 0 and dstOffset + length < dl))
|
dstOffset >= 0 and dstOffset + length <= dl))
|
||||||
{
|
{
|
||||||
uint8_t* sbody = &cast<uint8_t>(s, (offset * BytesPerWord) + 4);
|
uint8_t* sbody = &cast<uint8_t>(s, (offset + 1) * BytesPerWord);
|
||||||
uint8_t* dbody = &cast<uint8_t>(s, (offset * BytesPerWord) + 4);
|
uint8_t* dbody = &cast<uint8_t>(d, (offset + 1) * BytesPerWord);
|
||||||
memcpy(sbody + (srcOffset * elementSize),
|
memcpy(dbody + (dstOffset * elementSize),
|
||||||
dbody + (dstOffset * elementSize),
|
sbody + (srcOffset * elementSize),
|
||||||
length * elementSize);
|
length * elementSize);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -143,7 +153,7 @@ start(Thread* t, jobject this_)
|
|||||||
|
|
||||||
class Runnable: public System::Runnable {
|
class Runnable: public System::Runnable {
|
||||||
public:
|
public:
|
||||||
Runnable(Thread* t): t(t) { }
|
Runnable(System* s, Thread* t): s(s), t(t) { }
|
||||||
|
|
||||||
virtual void run(System::Thread* st) {
|
virtual void run(System::Thread* st) {
|
||||||
t->systemThread = st;
|
t->systemThread = st;
|
||||||
@ -153,10 +163,16 @@ start(Thread* t, jobject this_)
|
|||||||
t->exit();
|
t->exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread* t;
|
virtual void dispose() {
|
||||||
} r(p);
|
s->free(this);
|
||||||
|
}
|
||||||
|
|
||||||
if (not t->vm->system->success(t->vm->system->start(&r))) {
|
System* s;
|
||||||
|
Thread* t;
|
||||||
|
}* r = new (t->vm->system->allocate(sizeof(Runnable)))
|
||||||
|
Runnable(t->vm->system, p);
|
||||||
|
|
||||||
|
if (not t->vm->system->success(t->vm->system->start(r))) {
|
||||||
p->exit();
|
p->exit();
|
||||||
|
|
||||||
object message = makeString(t, "unable to start native thread");
|
object message = makeString(t, "unable to start native thread");
|
||||||
@ -179,6 +195,8 @@ populate(Thread* t, object map)
|
|||||||
reinterpret_cast<void*>(notify) },
|
reinterpret_cast<void*>(notify) },
|
||||||
{ "Java_java_lang_Object_notifyAll",
|
{ "Java_java_lang_Object_notifyAll",
|
||||||
reinterpret_cast<void*>(notifyAll) },
|
reinterpret_cast<void*>(notifyAll) },
|
||||||
|
{ "Java_java_lang_Thread_sleep",
|
||||||
|
reinterpret_cast<void*>(sleep) },
|
||||||
{ "Java_java_lang_System_loadLibrary",
|
{ "Java_java_lang_System_loadLibrary",
|
||||||
reinterpret_cast<void*>(loadLibrary) },
|
reinterpret_cast<void*>(loadLibrary) },
|
||||||
{ "Java_java_lang_System_arraycopy",
|
{ "Java_java_lang_System_arraycopy",
|
||||||
|
@ -431,8 +431,9 @@ collect(Thread* t, Heap::CollectionType type)
|
|||||||
void
|
void
|
||||||
removeMonitor(Thread* t, object o)
|
removeMonitor(Thread* t, object o)
|
||||||
{
|
{
|
||||||
abort(t);
|
object p = hashMapRemove
|
||||||
hashMapRemove(t, t->vm->monitorMap, o, objectHash, referenceEqual);
|
(t, t->vm->monitorMap, o, objectHash, referenceEqual);
|
||||||
|
static_cast<System::Monitor*>(pointerValue(t, p))->dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
object
|
object
|
||||||
@ -770,7 +771,7 @@ makeString(Thread* t, const char* format, ...)
|
|||||||
object s = ::makeByteArray(t, format, a);
|
object s = ::makeByteArray(t, format, a);
|
||||||
va_end(a);
|
va_end(a);
|
||||||
|
|
||||||
return makeString(t, s, 0, byteArrayLength(t, s), 0);
|
return makeString(t, s, 0, byteArrayLength(t, s) - 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -882,7 +883,7 @@ hashMapRemove(Thread* t, object map, object key,
|
|||||||
object p = 0;
|
object p = 0;
|
||||||
while (n) {
|
while (n) {
|
||||||
if (equal(t, key, tripleFirst(t, n))) {
|
if (equal(t, key, tripleFirst(t, n))) {
|
||||||
o = tripleFirst(t, n);
|
o = tripleSecond(t, n);
|
||||||
if (p) {
|
if (p) {
|
||||||
set(t, tripleThird(t, p), tripleThird(t, n));
|
set(t, tripleThird(t, p), tripleThird(t, n));
|
||||||
} else {
|
} else {
|
||||||
|
@ -1439,7 +1439,7 @@ pushLong(Thread* t, uint64_t v)
|
|||||||
}
|
}
|
||||||
|
|
||||||
pushInt(t, v >> 32);
|
pushInt(t, v >> 32);
|
||||||
pushInt(t, v & 0xFF);
|
pushInt(t, v & 0xFFFFFFFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline object
|
inline object
|
||||||
@ -1555,7 +1555,7 @@ pokeLong(Thread* t, unsigned index, uint64_t value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
pokeInt(t, index, value >> 32);
|
pokeInt(t, index, value >> 32);
|
||||||
pokeInt(t, index + 1, value & 0xFF);
|
pokeInt(t, index + 1, value & 0xFFFFFFFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline object*
|
inline object*
|
||||||
|
@ -139,6 +139,7 @@ class System: public vm::System {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual void dispose() {
|
virtual void dispose() {
|
||||||
|
r->dispose();
|
||||||
s->free(this);
|
s->free(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -357,6 +358,12 @@ class System: public vm::System {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void sleep(int64_t milliseconds) {
|
||||||
|
timespec ts = { milliseconds / 1000, (milliseconds % 1000) * 1000 * 1000 };
|
||||||
|
|
||||||
|
nanosleep(&ts, 0);
|
||||||
|
}
|
||||||
|
|
||||||
virtual uint64_t call(void* function, uintptr_t* arguments, uint8_t* types,
|
virtual uint64_t call(void* function, uintptr_t* arguments, uint8_t* types,
|
||||||
unsigned count, unsigned size, unsigned returnType)
|
unsigned count, unsigned size, unsigned returnType)
|
||||||
{
|
{
|
||||||
|
15
src/run.cpp
15
src/run.cpp
@ -87,14 +87,6 @@ make(Thread* t, object class_)
|
|||||||
memset(static_cast<object*>(instance) + 1, 0,
|
memset(static_cast<object*>(instance) + 1, 0,
|
||||||
sizeInBytes - sizeof(object));
|
sizeInBytes - sizeof(object));
|
||||||
|
|
||||||
fprintf(stderr, "new instance: %p\n", instance);
|
|
||||||
|
|
||||||
if (class_ == arrayBody(t, t->vm->types, Machine::ThreadType)) {
|
|
||||||
if (threadPeer(t, instance)) {
|
|
||||||
fprintf(stderr, "yo!\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -390,7 +382,8 @@ parsePool(Thread* t, Stream& s)
|
|||||||
|
|
||||||
case CONSTANT_String: {
|
case CONSTANT_String: {
|
||||||
object bytes = arrayBody(t, pool, intArrayBody(t, o, 1) - 1);
|
object bytes = arrayBody(t, pool, intArrayBody(t, o, 1) - 1);
|
||||||
object value = makeString(t, bytes, 0, byteArrayLength(t, bytes), 0);
|
object value = makeString
|
||||||
|
(t, bytes, 0, byteArrayLength(t, bytes) - 1, 0);
|
||||||
set(t, arrayBody(t, pool, i), value);
|
set(t, arrayBody(t, pool, i), value);
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
@ -2377,7 +2370,7 @@ run(Thread* t)
|
|||||||
if (isSpecialMethod(t, method, class_)) {
|
if (isSpecialMethod(t, method, class_)) {
|
||||||
class_ = classSuper(t, class_);
|
class_ = classSuper(t, class_);
|
||||||
|
|
||||||
if (UNLIKELY(classVirtualTable(t, class_) == 0)) {
|
if (classVirtualTable(t, class_) == 0) {
|
||||||
PROTECT(t, class_);
|
PROTECT(t, class_);
|
||||||
|
|
||||||
resolveClass(t, className(t, class_));
|
resolveClass(t, className(t, class_));
|
||||||
@ -2435,7 +2428,7 @@ run(Thread* t)
|
|||||||
if (LIKELY(peekObject(t, sp - parameterFootprint))) {
|
if (LIKELY(peekObject(t, sp - parameterFootprint))) {
|
||||||
object class_ = objectClass(t, peekObject(t, sp - parameterFootprint));
|
object class_ = objectClass(t, peekObject(t, sp - parameterFootprint));
|
||||||
|
|
||||||
if (UNLIKELY(classVirtualTable(t, class_) == 0)) {
|
if (classVirtualTable(t, class_) == 0) {
|
||||||
PROTECT(t, class_);
|
PROTECT(t, class_);
|
||||||
|
|
||||||
resolveClass(t, className(t, class_));
|
resolveClass(t, className(t, class_));
|
||||||
|
@ -29,6 +29,7 @@ class System: public Allocator {
|
|||||||
public:
|
public:
|
||||||
virtual ~Runnable() { }
|
virtual ~Runnable() { }
|
||||||
virtual void run(Thread*) = 0;
|
virtual void run(Thread*) = 0;
|
||||||
|
virtual void dispose() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Monitor {
|
class Monitor {
|
||||||
@ -58,6 +59,7 @@ class System: public Allocator {
|
|||||||
virtual Status attach(Thread**) = 0;
|
virtual Status attach(Thread**) = 0;
|
||||||
virtual Status start(Runnable*) = 0;
|
virtual Status start(Runnable*) = 0;
|
||||||
virtual Status make(Monitor**) = 0;
|
virtual Status make(Monitor**) = 0;
|
||||||
|
virtual void sleep(int64_t milliseconds) = 0;
|
||||||
virtual uint64_t call(void* function, uintptr_t* arguments, uint8_t* types,
|
virtual uint64_t call(void* function, uintptr_t* arguments, uint8_t* types,
|
||||||
unsigned count, unsigned size,
|
unsigned count, unsigned size,
|
||||||
unsigned returnType) = 0;
|
unsigned returnType) = 0;
|
||||||
|
@ -145,7 +145,7 @@
|
|||||||
java/lang/ArrayIndexOutOfBoundsException
|
java/lang/ArrayIndexOutOfBoundsException
|
||||||
(extends runtimeException))
|
(extends runtimeException))
|
||||||
|
|
||||||
(type arrayStoreException java/lang/arrayStoreException
|
(type arrayStoreException java/lang/ArrayStoreException
|
||||||
(extends runtimeException))
|
(extends runtimeException))
|
||||||
|
|
||||||
(type negativeArraySizeException java/lang/NegativeArraySizeException
|
(type negativeArraySizeException java/lang/NegativeArraySizeException
|
||||||
|
Loading…
Reference in New Issue
Block a user