diff --git a/src/bootimage.cpp b/src/bootimage.cpp index ed8baa03bd..99360d6dbe 100644 --- a/src/bootimage.cpp +++ b/src/bootimage.cpp @@ -40,7 +40,7 @@ codeMapSize(unsigned codeSize) object makeCodeImage(Thread* t, BootImage* image, uint8_t* code, unsigned capacity) { - unsigned size; + unsigned size = 0; t->m->processor->compileThunks(t, image, code, &size, capacity); Zone zone(t->m->system, t->m->heap, 64 * 1024); @@ -56,15 +56,18 @@ makeCodeImage(Thread* t, BootImage* image, uint8_t* code, unsigned capacity) const char* name = it.next(&nameSize); if (endsWith(".class", name, nameSize)) { + fprintf(stderr, "%.*s\n", nameSize - 6, name); object c = resolveClass - (t, makeByteArray(t, "%*s", nameSize - 5, name)); + (t, makeByteArray(t, "%.*s", nameSize - 6, name)); PROTECT(t, c); - - for (unsigned i = 0; i < arrayLength(t, classMethodTable(t, c)); ++i) { - object method = arrayBody(t, classMethodTable(t, c), i); - if (methodCode(t, method)) { - t->m->processor->compileMethod - (t, &zone, code, &size, capacity, &constants, &calls, method); + + if (classMethodTable(t, c)) { + for (unsigned i = 0; i < arrayLength(t, classMethodTable(t, c)); ++i) { + object method = arrayBody(t, classMethodTable(t, c), i); + if (methodCode(t, method)) { + t->m->processor->compileMethod + (t, &zone, code, &size, capacity, &constants, &calls, method); + } } } } @@ -114,13 +117,14 @@ makeHeapImage(Thread* t, BootImage* image, uintptr_t* heap, uintptr_t* map, position(0), capacity(capacity) { } - void visit(object p, unsigned number) { + void visit(unsigned number) { if (currentObject) { - markBit(map, (currentObject - heap) + currentOffset); - currentObject[currentOffset] = number; + unsigned index = currentObject - 1 + currentOffset; + markBit(map, index); + heap[index] = number; } - currentObject = reinterpret_cast(p); + currentObject = number; } virtual void root() { @@ -137,7 +141,7 @@ makeHeapImage(Thread* t, BootImage* image, uintptr_t* heap, uintptr_t* map, unsigned number = position + 1; position += size; - visit(p, number); + visit(number); return number; } else { @@ -146,7 +150,7 @@ makeHeapImage(Thread* t, BootImage* image, uintptr_t* heap, uintptr_t* map, } virtual void visitOld(object, unsigned number) { - visit(0, number); + visit(number); } virtual void push(unsigned offset) { @@ -158,7 +162,7 @@ makeHeapImage(Thread* t, BootImage* image, uintptr_t* heap, uintptr_t* map, } Thread* t; - uintptr_t* currentObject; + unsigned currentObject; unsigned currentOffset; uintptr_t* heap; uintptr_t* map; @@ -200,7 +204,7 @@ offset(object a, uintptr_t* b) } void -writeBootImage(Thread* t, FILE* out) +writeBootImage(Thread* t, FILE*) { BootImage image; @@ -228,13 +232,15 @@ writeBootImage(Thread* t, FILE* out) image.magic = BootImage::Magic; - fwrite(&image, sizeof(BootImage), 1, out); + fprintf(stderr, "heap size %d code size %d\n", + image.heapSize, image.codeSize); +// fwrite(&image, sizeof(BootImage), 1, out); - 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); } } // namespace @@ -249,7 +255,7 @@ main(int ac, const char** av) System* s = makeSystem(0); Heap* h = makeHeap(s, 128 * 1024 * 1024); - Finder* f = makeFinder(s, av[0], 0); + Finder* f = makeFinder(s, av[1], 0); Processor* p = makeProcessor(s, h); Machine* m = new (h->allocate(sizeof(Machine))) Machine(s, h, f, p, 0, 0); Thread* t = p->makeThread(m, 0, 0); diff --git a/src/compile.cpp b/src/compile.cpp index a006622957..3441be0dae 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -4725,6 +4725,7 @@ class MyProcessor: public Processor { callTableSize(0), methodTree(0), methodTreeSentinal(0), + objectPools(0), codeAllocator(s), codeZone(s, &codeAllocator, 64 * 1024) { } @@ -5130,13 +5131,6 @@ compileThunks(MyThread* t, Allocator* allocator, MyProcessor* p, Assembler::Register result(a->returnLow()); a->apply(Jump, BytesPerWord, RegisterOperand, &result); - - void* p = defaultContext.promise.listener->resolve - (reinterpret_cast(voidPointer(compileMethod))); - - if (image) { - image->defaultThunk = static_cast(p) - imageBase; - } } ThunkContext nativeContext(t, &zone); @@ -5151,13 +5145,6 @@ compileThunks(MyThread* t, Allocator* allocator, MyProcessor* p, popThread(t, a); a->apply(Return); - - void* p = nativeContext.promise.listener->resolve - (reinterpret_cast(voidPointer(invokeNative))); - - if (image) { - image->nativeThunk = static_cast(p) - imageBase; - } } ThunkContext aioobContext(t, &zone); @@ -5169,13 +5156,6 @@ compileThunks(MyThread* t, Allocator* allocator, MyProcessor* p, Assembler::Constant proc(&(aioobContext.promise)); a->apply(LongCall, BytesPerWord, ConstantOperand, &proc); - - void* p = aioobContext.promise.listener->resolve - (reinterpret_cast(voidPointer(throwArrayIndexOutOfBounds))); - - if (image) { - image->aioobThunk = static_cast(p) - imageBase; - } } ThunkContext tableContext(t, &zone); @@ -5203,12 +5183,35 @@ compileThunks(MyThread* t, Allocator* allocator, MyProcessor* p, p->defaultThunk = finish (t, allocator, defaultContext.context.assembler, "default"); + { void* p = defaultContext.promise.listener->resolve + (reinterpret_cast(voidPointer(compileMethod))); + if (image) { + image->defaultThunk = static_cast(p) - imageBase; + } + } + p->nativeThunk = finish (t, allocator, nativeContext.context.assembler, "native"); + { void* p = nativeContext.promise.listener->resolve + (reinterpret_cast(voidPointer(invokeNative))); + + if (image) { + image->nativeThunk = static_cast(p) - imageBase; + } + } + p->aioobThunk = finish (t, allocator, aioobContext.context.assembler, "aioob"); + { void* p = aioobContext.promise.listener->resolve + (reinterpret_cast(voidPointer(throwArrayIndexOutOfBounds))); + + if (image) { + image->aioobThunk = static_cast(p) - imageBase; + } + } + p->thunkTable = static_cast (allocator->allocate(p->thunkSize * ThunkCount)); @@ -5291,8 +5294,10 @@ compile(MyThread* t, Allocator* allocator, BootContext* bootContext, ACQUIRE(t, t->m->classLock); if (methodCompiled(t, method) == defaultThunk(t)) { - initClass(t, methodClass(t, method)); - if (UNLIKELY(t->exception)) return; + if (bootContext == 0) { + initClass(t, methodClass(t, method)); + if (UNLIKELY(t->exception)) return; + } if (methodCompiled(t, method) == defaultThunk(t)) { object node; diff --git a/src/finder.cpp b/src/finder.cpp index 9867c01a13..d017e4ec4b 100644 --- a/src/finder.cpp +++ b/src/finder.cpp @@ -79,8 +79,8 @@ class DirectoryElement: public Element { public: class Iterator: public Element::Iterator { public: - Iterator(System* s, const char* name): - s(s), directory(0) + Iterator(System* s, const char* name, unsigned skip): + s(s), name(name), skip(skip), directory(0), last(0), it(0) { if (not s->success(s->open(&directory, name))) { directory = 0; @@ -88,14 +88,35 @@ class DirectoryElement: public Element { } virtual const char* next(unsigned* size) { + if (it) { + const char* v = it->next(size); + if (v) { + return v; + } else { + it->dispose(); + it = 0; + } + } + + if (last) { + s->free(last); + } + if (directory) { for (const char* v = directory->next(); v; v = directory->next()) { if (v[0] != '.') { - *size = strlen(v); - return v; + last = append(s, name, "/", v); + if (s->identify(last) == System::TypeDirectory) { + it = new (allocate(s, sizeof(Iterator))) Iterator(s, last, skip); + it->name = last; + } + const char* result = last + skip; + *size = strlen(result); + return result; } } } + return 0; } @@ -105,7 +126,11 @@ class DirectoryElement: public Element { } System* s; + const char* name; + unsigned skip; System::Directory* directory; + const char* last; + Iterator* it; }; DirectoryElement(System* s, const char* name): @@ -113,7 +138,8 @@ class DirectoryElement: public Element { { } virtual Element::Iterator* iterator() { - return new (allocate(s, sizeof(Iterator))) Iterator(s, name); + return new (allocate(s, sizeof(Iterator))) + Iterator(s, name, strlen(name) + 1); } virtual System::Region* find(const char* name) { @@ -449,6 +475,8 @@ class JarElement: public Element { { } virtual Element::Iterator* iterator() { + init(); + return new (allocate(s, sizeof(Iterator))) Iterator(s, index); } @@ -626,6 +654,8 @@ class MyIterator: public Finder::IteratorImp { if (e) { it = e->iterator(); e = e->next; + } else { + it = 0; } } } diff --git a/src/finder.h b/src/finder.h index f7c392c2ab..4cd1256baf 100644 --- a/src/finder.h +++ b/src/finder.h @@ -37,14 +37,16 @@ class Finder { } bool hasMore() { + if (current) return true; + current = it->next(¤tSize); return current != 0; } const char* next(unsigned* size) { - if (current) { - const char* v = current; + if (hasMore()) { *size = currentSize; - current = it->next(¤tSize); + const char* v = current; + current = 0; return v; } else { return 0;