allocate root thread on heap, not stack

This commit is contained in:
Joel Dice 2007-07-20 17:26:13 -06:00
parent 108f8d7bc0
commit b57e1eee76
6 changed files with 9 additions and 31 deletions

View File

@ -180,8 +180,7 @@ start(Thread* t, jobject this_)
object message = makeString(t, "thread already started"); object message = makeString(t, "thread already started");
t->exception = makeIllegalStateException(t, message); t->exception = makeIllegalStateException(t, message);
} else { } else {
p = new (t->vm->system->allocate(sizeof(Thread))) p = new (t->vm->system->allocate(sizeof(Thread))) Thread(t->vm, *this_, t);
Thread(t->vm, t->vm->system, *this_, t);
enter(p, Thread::ActiveState); enter(p, Thread::ActiveState);

View File

@ -1,12 +1,8 @@
#include "sys/mman.h" #include "sys/mman.h"
#include "sys/types.h" #include "sys/types.h"
#include "sys/stat.h" #include "sys/stat.h"
#include "fcntl.h" #include "fcntl.h"
#include "system.h" #include "system.h"
#include "class-finder.h" #include "class-finder.h"

View File

@ -1,8 +1,6 @@
#ifndef COMMON_H #ifndef COMMON_H
#define COMMON_H #define COMMON_H
#include "stdint.h" #include "stdint.h"
#include "stdlib.h" #include "stdlib.h"
#include "stdarg.h" #include "stdarg.h"
@ -29,8 +27,6 @@
inline void* operator new(size_t, void* p) throw() { return p; } inline void* operator new(size_t, void* p) throw() { return p; }
namespace vm { namespace vm {
typedef void* object; typedef void* object;

View File

@ -1294,17 +1294,11 @@ Machine::dispose()
if (libraries) { if (libraries) {
libraries->dispose(); libraries->dispose();
} }
if (rootThread) {
rootThread->dispose();
}
} }
Thread::Thread(Machine* m, Allocator* allocator, object javaThread, Thread::Thread(Machine* m, object javaThread, Thread* parent):
Thread* parent):
vtable(&(m->jniEnvVTable)), vtable(&(m->jniEnvVTable)),
vm(m), vm(m),
allocator(allocator),
parent(parent), parent(parent),
peer((parent ? parent->child : 0)), peer((parent ? parent->child : 0)),
child(0), child(0),
@ -1412,9 +1406,7 @@ Thread::dispose()
heap = 0; heap = 0;
#endif // VM_STRESS #endif // VM_STRESS
if (allocator) { vm->system->free(this);
allocator->free(this);
}
} }
void void

View File

@ -1158,18 +1158,13 @@ class Thread {
static const unsigned HeapSizeInWords = HeapSizeInBytes / BytesPerWord; static const unsigned HeapSizeInWords = HeapSizeInBytes / BytesPerWord;
static const unsigned StackSizeInWords = StackSizeInBytes / BytesPerWord; static const unsigned StackSizeInWords = StackSizeInBytes / BytesPerWord;
Thread(Machine* m, Allocator* allocator, object javaThread, Thread* parent); Thread(Machine* m, object javaThread, Thread* parent);
~Thread() {
exit();
}
void exit(); void exit();
void dispose(); void dispose();
JNIEnvVTable* vtable; JNIEnvVTable* vtable;
Machine* vm; Machine* vm;
Allocator* allocator;
Thread* parent; Thread* parent;
Thread* peer; Thread* peer;
Thread* child; Thread* child;

View File

@ -2372,16 +2372,16 @@ run(System* system, Heap* heap, ClassFinder* classFinder,
const char* className, int argc, const char** argv) const char* className, int argc, const char** argv)
{ {
Machine m(system, heap, classFinder); Machine m(system, heap, classFinder);
Thread t(&m, 0, 0, 0); Thread* t = new (system->allocate(sizeof(Thread))) Thread(&m, 0, 0);
enter(&t, Thread::ActiveState); enter(t, Thread::ActiveState);
::run(&t, className, argc, argv); ::run(t, className, argc, argv);
int exitCode = 0; int exitCode = 0;
if (t.exception) exitCode = -1; if (t->exception) exitCode = -1;
exit(&t); exit(t);
return exitCode; return exitCode;
} }