mirror of
https://github.com/corda/corda.git
synced 2025-03-17 17:45:17 +00:00
fix bootimage build
This commit is contained in:
parent
0debcf0f16
commit
11e61543a3
@ -33,12 +33,9 @@ endsWith(const char* suffix, const char* s, unsigned length)
|
||||
|
||||
object
|
||||
makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code,
|
||||
unsigned capacity, uintptr_t* codeMap, const char* className,
|
||||
uintptr_t* codeMap, const char* className,
|
||||
const char* methodName, const char* methodSpec)
|
||||
{
|
||||
unsigned size = 0;
|
||||
t->m->processor->initialize(t, image, code, &size, capacity);
|
||||
|
||||
object constants = 0;
|
||||
PROTECT(t, constants);
|
||||
|
||||
@ -118,8 +115,6 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code,
|
||||
- reinterpret_cast<intptr_t>(code));
|
||||
}
|
||||
|
||||
image->codeSize = size;
|
||||
|
||||
return constants;
|
||||
}
|
||||
|
||||
@ -143,7 +138,7 @@ visitRoots(Thread* t, BootImage* image, HeapWalker* w, object constants)
|
||||
image->loader = w->visitRoot(m->loader);
|
||||
image->types = w->visitRoot(m->types);
|
||||
|
||||
m->processor->visitRoots(image, w);
|
||||
m->processor->visitRoots(w);
|
||||
|
||||
for (; constants; constants = tripleThird(t, constants)) {
|
||||
w->visitRoot(tripleFirst(t, constants));
|
||||
@ -186,7 +181,7 @@ makeHeapImage(Thread* t, BootImage* image, uintptr_t* heap, uintptr_t* map,
|
||||
and (currentOffset * BytesPerWord) == ClassStaticTable)
|
||||
{
|
||||
FixedAllocator allocator
|
||||
(t, reinterpret_cast<uint8_t*>(heap + position),
|
||||
(t->m->system, reinterpret_cast<uint8_t*>(heap + position),
|
||||
(capacity - position) * BytesPerWord);
|
||||
|
||||
unsigned totalInBytes;
|
||||
@ -284,21 +279,18 @@ offset(object a, uintptr_t* b)
|
||||
}
|
||||
|
||||
void
|
||||
writeBootImage(Thread* t, FILE* out, const char* className,
|
||||
writeBootImage(Thread* t, FILE* out, BootImage* image, uint8_t* code,
|
||||
unsigned codeCapacity, const char* className,
|
||||
const char* methodName, const char* methodSpec)
|
||||
{
|
||||
Zone zone(t->m->system, t->m->heap, 64 * 1024);
|
||||
BootImage image;
|
||||
|
||||
const unsigned CodeCapacity = 32 * 1024 * 1024;
|
||||
uint8_t* code = static_cast<uint8_t*>(t->m->heap->allocate(CodeCapacity));
|
||||
uintptr_t* codeMap = static_cast<uintptr_t*>
|
||||
(t->m->heap->allocate(codeMapSize(CodeCapacity)));
|
||||
memset(codeMap, 0, codeMapSize(CodeCapacity));
|
||||
(t->m->heap->allocate(codeMapSize(codeCapacity)));
|
||||
memset(codeMap, 0, codeMapSize(codeCapacity));
|
||||
|
||||
object constants = makeCodeImage
|
||||
(t, &zone, &image, code, CodeCapacity, codeMap, className, methodName,
|
||||
methodSpec);
|
||||
(t, &zone, image, code, codeMap, className, methodName, methodSpec);
|
||||
|
||||
if (t->exception) return;
|
||||
|
||||
@ -314,13 +306,13 @@ writeBootImage(Thread* t, FILE* out, const char* className,
|
||||
collect(t, Heap::MajorCollection);
|
||||
|
||||
HeapWalker* heapWalker = makeHeapImage
|
||||
(t, &image, heap, heapMap, HeapCapacity, constants);
|
||||
(t, image, heap, heapMap, HeapCapacity, constants);
|
||||
|
||||
updateConstants(t, constants, code, codeMap, heapWalker->map());
|
||||
|
||||
image.classCount = hashMapSize(t, t->m->classMap);
|
||||
image->classCount = hashMapSize(t, t->m->classMap);
|
||||
unsigned* classTable = static_cast<unsigned*>
|
||||
(t->m->heap->allocate(image.classCount * sizeof(unsigned)));
|
||||
(t->m->heap->allocate(image->classCount * sizeof(unsigned)));
|
||||
|
||||
{ unsigned i = 0;
|
||||
for (HashMapIterator it(t, t->m->classMap); it.hasMore();) {
|
||||
@ -328,9 +320,9 @@ writeBootImage(Thread* t, FILE* out, const char* className,
|
||||
}
|
||||
}
|
||||
|
||||
image.stringCount = hashMapSize(t, t->m->stringMap);
|
||||
image->stringCount = hashMapSize(t, t->m->stringMap);
|
||||
unsigned* stringTable = static_cast<unsigned*>
|
||||
(t->m->heap->allocate(image.stringCount * sizeof(unsigned)));
|
||||
(t->m->heap->allocate(image->stringCount * sizeof(unsigned)));
|
||||
|
||||
{ unsigned i = 0;
|
||||
for (HashMapIterator it(t, t->m->stringMap); it.hasMore();) {
|
||||
@ -339,29 +331,28 @@ writeBootImage(Thread* t, FILE* out, const char* className,
|
||||
}
|
||||
}
|
||||
|
||||
unsigned* callTable = t->m->processor->makeCallTable
|
||||
(t, &image, heapWalker, code);
|
||||
unsigned* callTable = t->m->processor->makeCallTable(t, heapWalker);
|
||||
|
||||
heapWalker->dispose();
|
||||
|
||||
image.magic = BootImage::Magic;
|
||||
image.codeBase = reinterpret_cast<uintptr_t>(code);
|
||||
image->magic = BootImage::Magic;
|
||||
image->codeBase = reinterpret_cast<uintptr_t>(code);
|
||||
|
||||
fprintf(stderr, "class count %d string count %d call count %d\n"
|
||||
"heap size %d code size %d\n",
|
||||
image.classCount, image.stringCount, image.callCount, image.heapSize,
|
||||
image.codeSize);
|
||||
image->classCount, image->stringCount, image->callCount,
|
||||
image->heapSize, image->codeSize);
|
||||
|
||||
if (true) {
|
||||
fwrite(&image, sizeof(BootImage), 1, out);
|
||||
fwrite(image, sizeof(BootImage), 1, out);
|
||||
|
||||
fwrite(classTable, image.classCount * sizeof(unsigned), 1, out);
|
||||
fwrite(stringTable, image.stringCount * sizeof(unsigned), 1, out);
|
||||
fwrite(callTable, image.callCount * sizeof(unsigned) * 2, 1, out);
|
||||
fwrite(classTable, image->classCount * sizeof(unsigned), 1, out);
|
||||
fwrite(stringTable, image->stringCount * sizeof(unsigned), 1, out);
|
||||
fwrite(callTable, image->callCount * sizeof(unsigned) * 2, 1, out);
|
||||
|
||||
unsigned offset = (image.classCount * sizeof(unsigned))
|
||||
+ (image.stringCount * sizeof(unsigned))
|
||||
+ (image.callCount * sizeof(unsigned) * 2);
|
||||
unsigned offset = (image->classCount * sizeof(unsigned))
|
||||
+ (image->stringCount * sizeof(unsigned))
|
||||
+ (image->callCount * sizeof(unsigned) * 2);
|
||||
|
||||
while (offset % BytesPerWord) {
|
||||
uint8_t c = 0;
|
||||
@ -369,11 +360,11 @@ writeBootImage(Thread* t, FILE* out, const char* className,
|
||||
++ offset;
|
||||
}
|
||||
|
||||
fwrite(heapMap, pad(heapMapSize(image.heapSize)), 1, out);
|
||||
fwrite(heap, pad(image.heapSize), 1, out);
|
||||
fwrite(heapMap, pad(heapMapSize(image->heapSize)), 1, out);
|
||||
fwrite(heap, pad(image->heapSize), 1, out);
|
||||
|
||||
fwrite(codeMap, pad(codeMapSize(image.codeSize)), 1, out);
|
||||
fwrite(code, pad(image.codeSize), 1, out);
|
||||
fwrite(codeMap, pad(codeMapSize(image->codeSize)), 1, out);
|
||||
fwrite(code, pad(image->codeSize), 1, out);
|
||||
}
|
||||
}
|
||||
|
||||
@ -392,6 +383,12 @@ main(int ac, const char** av)
|
||||
Heap* h = makeHeap(s, 128 * 1024 * 1024);
|
||||
Finder* f = makeFinder(s, av[1], 0);
|
||||
Processor* p = makeProcessor(s, h);
|
||||
|
||||
BootImage image;
|
||||
const unsigned CodeCapacity = 32 * 1024 * 1024;
|
||||
uint8_t* code = static_cast<uint8_t*>(h->allocate(CodeCapacity));
|
||||
p->initialize(&image, code, CodeCapacity);
|
||||
|
||||
Machine* m = new (h->allocate(sizeof(Machine))) Machine(s, h, f, p, 0, 0);
|
||||
Thread* t = p->makeThread(m, 0, 0);
|
||||
|
||||
@ -399,8 +396,8 @@ main(int ac, const char** av)
|
||||
enter(t, Thread::IdleState);
|
||||
|
||||
writeBootImage
|
||||
(t, stdout, (ac > 2 ? av[2] : 0), (ac > 3 ? av[3] : 0),
|
||||
(ac > 4 ? av[4] : 0));
|
||||
(t, stdout, &image, code, CodeCapacity,
|
||||
(ac > 2 ? av[2] : 0), (ac > 3 ? av[3] : 0), (ac > 4 ? av[4] : 0));
|
||||
|
||||
if (t->exception) {
|
||||
printTrace(t, t->exception);
|
||||
|
@ -5884,8 +5884,7 @@ boot(MyThread* t, BootImage* image);
|
||||
class MyProcessor;
|
||||
|
||||
void
|
||||
compileThunks(MyThread* t, Allocator* allocator, MyProcessor* p,
|
||||
BootImage* image, uint8_t* imageBase);
|
||||
compileThunks(MyThread* t, Allocator* allocator, MyProcessor* p);
|
||||
|
||||
MyProcessor*
|
||||
processor(MyThread* t);
|
||||
@ -5909,7 +5908,8 @@ class MyProcessor: public Processor {
|
||||
receiveMethod(0),
|
||||
windMethod(0),
|
||||
rewindMethod(0),
|
||||
codeAllocator(s, 0, 0)
|
||||
codeAllocator(s, 0, 0),
|
||||
bootImage(0)
|
||||
{ }
|
||||
|
||||
virtual Thread*
|
||||
@ -6248,14 +6248,10 @@ class MyProcessor: public Processor {
|
||||
return visitor.trace;
|
||||
}
|
||||
|
||||
virtual void initialize(Thread* vmt, BootImage* image, uint8_t* code,
|
||||
unsigned capacity)
|
||||
{
|
||||
virtual void initialize(BootImage* image, uint8_t* code, unsigned capacity) {
|
||||
bootImage = image;
|
||||
codeAllocator.base = code;
|
||||
codeAllocator.capacity = capacity;
|
||||
|
||||
::compileThunks
|
||||
(static_cast<MyThread*>(vmt), &codeAllocator, this, image, code);
|
||||
}
|
||||
|
||||
virtual void compileMethod(Thread* vmt, Zone* zone, object* constants,
|
||||
@ -6272,16 +6268,15 @@ class MyProcessor: public Processor {
|
||||
*addresses = bootContext.addresses;
|
||||
}
|
||||
|
||||
virtual void visitRoots(BootImage* image, HeapWalker* w) {
|
||||
image->methodTree = w->visitRoot(methodTree);
|
||||
image->methodTreeSentinal = w->visitRoot(methodTreeSentinal);
|
||||
image->virtualThunks = w->visitRoot(virtualThunks);
|
||||
virtual void visitRoots(HeapWalker* w) {
|
||||
bootImage->methodTree = w->visitRoot(methodTree);
|
||||
bootImage->methodTreeSentinal = w->visitRoot(methodTreeSentinal);
|
||||
bootImage->virtualThunks = w->visitRoot(virtualThunks);
|
||||
}
|
||||
|
||||
virtual unsigned* makeCallTable(Thread* t, BootImage* image, HeapWalker* w,
|
||||
uint8_t* code)
|
||||
{
|
||||
image->callCount = callTableSize;
|
||||
virtual unsigned* makeCallTable(Thread* t, HeapWalker* w) {
|
||||
bootImage->codeSize = codeAllocator.offset;
|
||||
bootImage->callCount = callTableSize;
|
||||
|
||||
unsigned* table = static_cast<unsigned*>
|
||||
(t->m->heap->allocate(callTableSize * sizeof(unsigned) * 2));
|
||||
@ -6290,7 +6285,7 @@ class MyProcessor: public Processor {
|
||||
for (unsigned i = 0; i < arrayLength(t, callTable); ++i) {
|
||||
for (object p = arrayBody(t, callTable, i); p; p = callNodeNext(t, p)) {
|
||||
table[index++] = callNodeAddress(t, p)
|
||||
- reinterpret_cast<uintptr_t>(code);
|
||||
- reinterpret_cast<uintptr_t>(codeAllocator.base);
|
||||
table[index++] = w->map()->find(callNodeTarget(t, p))
|
||||
| (static_cast<unsigned>(callNodeFlags(t, p)) << BootShift);
|
||||
}
|
||||
@ -6300,9 +6295,11 @@ class MyProcessor: public Processor {
|
||||
}
|
||||
|
||||
virtual void boot(Thread* t, BootImage* image) {
|
||||
codeAllocator.base = static_cast<uint8_t*>
|
||||
(s->tryAllocateExecutable(ExecutableAreaSizeInBytes));
|
||||
codeAllocator.capacity = ExecutableAreaSizeInBytes;
|
||||
if (codeAllocator.base == 0) {
|
||||
codeAllocator.base = static_cast<uint8_t*>
|
||||
(s->tryAllocateExecutable(ExecutableAreaSizeInBytes));
|
||||
codeAllocator.capacity = ExecutableAreaSizeInBytes;
|
||||
}
|
||||
|
||||
if (image) {
|
||||
::boot(static_cast<MyThread*>(t), image);
|
||||
@ -6313,7 +6310,7 @@ class MyProcessor: public Processor {
|
||||
set(t, methodTree, TreeNodeLeft, methodTreeSentinal);
|
||||
set(t, methodTree, TreeNodeRight, methodTreeSentinal);
|
||||
|
||||
::compileThunks(static_cast<MyThread*>(t), &codeAllocator, this, 0, 0);
|
||||
::compileThunks(static_cast<MyThread*>(t), &codeAllocator, this);
|
||||
}
|
||||
|
||||
segFaultHandler.m = t->m;
|
||||
@ -6389,6 +6386,7 @@ class MyProcessor: public Processor {
|
||||
object rewindMethod;
|
||||
SegFaultHandler segFaultHandler;
|
||||
FixedAllocator codeAllocator;
|
||||
BootImage* bootImage;
|
||||
};
|
||||
|
||||
object
|
||||
@ -6697,9 +6695,9 @@ fixupVirtualThunks(MyThread* t, BootImage* image, uint8_t* code)
|
||||
MyProcessor* p = processor(t);
|
||||
|
||||
for (unsigned i = 0; i < wordArrayLength(t, p->virtualThunks); ++i) {
|
||||
if (wordArrayBody(t, p->virtualThunks, 0)) {
|
||||
wordArrayBody(t, p->virtualThunks, 0)
|
||||
= (wordArrayBody(t, p->virtualThunks, 0) - image->codeBase)
|
||||
if (wordArrayBody(t, p->virtualThunks, i)) {
|
||||
wordArrayBody(t, p->virtualThunks, i)
|
||||
= (wordArrayBody(t, p->virtualThunks, i) - image->codeBase)
|
||||
+ reinterpret_cast<uintptr_t>(code);
|
||||
}
|
||||
}
|
||||
@ -6779,8 +6777,7 @@ getThunk(MyThread* t, Thunk thunk)
|
||||
}
|
||||
|
||||
void
|
||||
compileThunks(MyThread* t, Allocator* allocator, MyProcessor* p,
|
||||
BootImage* image, uint8_t* imageBase)
|
||||
compileThunks(MyThread* t, Allocator* allocator, MyProcessor* p)
|
||||
{
|
||||
class ThunkContext {
|
||||
public:
|
||||
@ -6905,6 +6902,9 @@ compileThunks(MyThread* t, Allocator* allocator, MyProcessor* p,
|
||||
p->defaultThunk = finish
|
||||
(t, allocator, defaultContext.context.assembler, "default");
|
||||
|
||||
BootImage* image = p->bootImage;
|
||||
uint8_t* imageBase = p->codeAllocator.base;
|
||||
|
||||
{ void* call;
|
||||
defaultContext.promise.listener->resolve
|
||||
(reinterpret_cast<intptr_t>(voidPointer(compileMethod)), &call);
|
||||
|
@ -3217,7 +3217,7 @@ class MyProcessor: public Processor {
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual void initialize(vm::Thread*, BootImage*, uint8_t*, unsigned) {
|
||||
virtual void initialize(BootImage*, uint8_t*, unsigned) {
|
||||
abort(s);
|
||||
}
|
||||
|
||||
@ -3227,13 +3227,11 @@ class MyProcessor: public Processor {
|
||||
abort(s);
|
||||
}
|
||||
|
||||
virtual void visitRoots(BootImage*, HeapWalker*) {
|
||||
virtual void visitRoots(HeapWalker*) {
|
||||
abort(s);
|
||||
}
|
||||
|
||||
virtual unsigned* makeCallTable(vm::Thread*, BootImage*, HeapWalker*,
|
||||
uint8_t*)
|
||||
{
|
||||
virtual unsigned* makeCallTable(vm::Thread*, HeapWalker*) {
|
||||
abort(s);
|
||||
}
|
||||
|
||||
|
@ -117,18 +117,17 @@ class Processor {
|
||||
getStackTrace(Thread* t, Thread* target) = 0;
|
||||
|
||||
virtual void
|
||||
initialize(Thread* t, BootImage* image, uint8_t* code,
|
||||
unsigned capacity) = 0;
|
||||
initialize(BootImage* image, uint8_t* code, unsigned capacity) = 0;
|
||||
|
||||
virtual void
|
||||
compileMethod(Thread* t, Zone* zone, object* constants, object* calls,
|
||||
DelayedPromise** addresses, object method) = 0;
|
||||
|
||||
virtual void
|
||||
visitRoots(BootImage* image, HeapWalker* w) = 0;
|
||||
visitRoots(HeapWalker* w) = 0;
|
||||
|
||||
virtual unsigned*
|
||||
makeCallTable(Thread* t, BootImage* image, HeapWalker* w, uint8_t* code) = 0;
|
||||
makeCallTable(Thread* t, HeapWalker* w) = 0;
|
||||
|
||||
virtual void
|
||||
boot(Thread* t, BootImage* image) = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user