diff --git a/readme.txt b/readme.txt index 45bc4add45..c0add23550 100644 --- a/readme.txt +++ b/readme.txt @@ -559,7 +559,7 @@ using the OpenJDK library.) Step 6: Build the boot and code images. $ ../build/linux-i386-bootimage/bootimage-generator stage2 \ - bootimage.bin codeimage.bin + bootimage-bin.o codeimage-bin.o Step 7: Write a driver which starts the VM and runs the desired main method. Note the bootimageBin function, which will be called by the @@ -668,7 +668,7 @@ EOF $ g++ -I$JAVA_HOME/include -I$JAVA_HOME/include/linux \ -D_JNI_IMPLEMENTATION_ -c bootimage-main.cpp -o main.o -Step 9: Link the objects produced above to produce the final +Step 8: Link the objects produced above to produce the final executable, and optionally strip its symbols. $ g++ -rdynamic *.o -ldl -lpthread -lz -o hello diff --git a/src/binaryToObject/tools.h b/src/binaryToObject/tools.h index 999d010535..ad7e81f86f 100644 --- a/src/binaryToObject/tools.h +++ b/src/binaryToObject/tools.h @@ -55,7 +55,7 @@ public: unsigned addr; String name; - inline SymbolInfo(uint64_t addr, const char* name): + inline SymbolInfo(uint64_t addr, const String& name): addr(addr), name(name) {} diff --git a/src/bootimage.cpp b/src/bootimage.cpp index 181b3cefaa..7a8b943310 100644 --- a/src/bootimage.cpp +++ b/src/bootimage.cpp @@ -1292,28 +1292,32 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp class MyCompilationHandler : public Processor::CompilationHandler { public: - virtual void compiled(const void* code, unsigned size UNUSED, unsigned frameSize UNUSED, const char* class_, const char* name, const char* spec) { - if (class_ and name and spec) { - size_t classLen = strlen(class_); - size_t nameLen = strlen(name); - size_t specLen = strlen(spec); - - char* completeName = (char*)malloc(classLen + nameLen + specLen + 2); - sprintf(completeName, "%s.%s%s", class_, name, spec); - uint64_t offset = reinterpret_cast(code) - codeOffset; - symbols.add(SymbolInfo(offset, completeName)); - // printf("%ld %ld %s.%s%s\n", offset, offset + size, class_, name, spec); - } + + String heapDup(const char* name) { + String ret(name); + char* n = (char*)heap->allocate(ret.length + 1); + memcpy(n, ret.text, ret.length + 1); + ret.text = n; + return ret; + } + + virtual void compiled(const void* code, unsigned size UNUSED, unsigned frameSize UNUSED, const char* name) { + uint64_t offset = reinterpret_cast(code) - codeOffset; + symbols.add(SymbolInfo(offset, heapDup(name))); + // printf("%ld %ld %s.%s%s\n", offset, offset + size, class_, name, spec); } virtual void dispose() {} DynamicArray symbols; uint64_t codeOffset; + Heap* heap; - MyCompilationHandler(uint64_t codeOffset): - codeOffset(codeOffset) {} - } compilationHandler(reinterpret_cast(code)); + MyCompilationHandler(uint64_t codeOffset, Heap* heap): + codeOffset(codeOffset), + heap(heap) {} + + } compilationHandler(reinterpret_cast(code), t->m->heap); t->m->processor->addCompilationHandler(&compilationHandler); @@ -1661,13 +1665,13 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp platform->writeObject(bootimageOutput, Slice(bootimageSymbols, 2), Slice(bootimageData.data, bootimageData.length), Platform::Writable, TargetBytesPerWord); - compilationHandler.symbols.add(SymbolInfo(0, strdup("_binary_codeimage_bin_start"))); - compilationHandler.symbols.add(SymbolInfo(image->codeSize, strdup("_binary_codeimage_bin_end"))); + compilationHandler.symbols.add(SymbolInfo(0, "_binary_codeimage_bin_start")); + compilationHandler.symbols.add(SymbolInfo(image->codeSize, "_binary_codeimage_bin_end")); platform->writeObject(codeOutput, Slice(compilationHandler.symbols), Slice(code, image->codeSize), Platform::Executable, TargetBytesPerWord); - for(SymbolInfo* sym = compilationHandler.symbols.begin(); sym != compilationHandler.symbols.end(); sym++) { - free(const_cast((const void*)sym->name.text)); + for(SymbolInfo* sym = compilationHandler.symbols.begin(); sym != compilationHandler.symbols.end() - 2; sym++) { + t->m->heap->free(const_cast((const void*)sym->name.text), sym->name.length + 1); } } } diff --git a/src/compile.cpp b/src/compile.cpp index 0823af833a..777cce124c 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -9093,6 +9093,20 @@ class MyProcessor: public Processor { CompilationHandlerList* compilationHandlers; }; +const char* +stringOrNull(const char* str) { + if(str) { + return str; + } else { + return "(null)"; + } +} + +size_t +stringOrNullSize(const char* str) { + return strlen(stringOrNull(str)); +} + void logCompile(MyThread* t, const void* code, unsigned size, const char* class_, const char* name, const char* spec) @@ -9114,9 +9128,15 @@ logCompile(MyThread* t, const void* code, unsigned size, const char* class_, class_, name, spec); } + size_t nameLength = stringOrNullSize(class_) + stringOrNullSize(name) + stringOrNullSize(spec) + 2; + + THREAD_RUNTIME_ARRAY(t, char, completeName, nameLength); + + sprintf(RUNTIME_ARRAY_BODY(completeName), "%s.%s%s", stringOrNull(class_), stringOrNull(name), stringOrNull(spec)); + MyProcessor* p = static_cast(t->m->processor); for(CompilationHandlerList* h = p->compilationHandlers; h; h = h->next) { - h->handler->compiled(code, 0, 0, class_, name, spec); + h->handler->compiled(code, 0, 0, RUNTIME_ARRAY_BODY(completeName)); } } @@ -9986,7 +10006,15 @@ compileVirtualThunk(MyThread* t, unsigned index, unsigned* size) a->setDestination(start); a->write(); - logCompile(t, start, *size, 0, "virtualThunk", 0); + const char* const virtualThunkBaseName = "virtualThunk"; + const size_t virtualThunkBaseNameLength = strlen(virtualThunkBaseName); + const size_t maxIntStringLength = 10; + + THREAD_RUNTIME_ARRAY(t, char, virtualThunkName, virtualThunkBaseNameLength + maxIntStringLength); + + sprintf(RUNTIME_ARRAY_BODY(virtualThunkName), "%s%d", virtualThunkBaseName, index); + + logCompile(t, start, *size, 0, virtualThunkName, 0); return reinterpret_cast(start); } diff --git a/src/processor.h b/src/processor.h index 3794570b14..a6b548387f 100644 --- a/src/processor.h +++ b/src/processor.h @@ -43,7 +43,7 @@ class Processor { class CompilationHandler { public: - virtual void compiled(const void* code, unsigned size, unsigned frameSize, const char* class_, const char* name, const char* spec) = 0; + virtual void compiled(const void* code, unsigned size, unsigned frameSize, const char* name) = 0; virtual void dispose() = 0; };