Merge branch 'master' into jdk7

This commit is contained in:
Joshua Warner 2012-05-07 15:05:56 -06:00
commit 64b9407420
5 changed files with 57 additions and 25 deletions

View File

@ -559,7 +559,7 @@ using the OpenJDK library.)
Step 6: Build the boot and code images. Step 6: Build the boot and code images.
$ ../build/linux-i386-bootimage/bootimage-generator stage2 \ $ ../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 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 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 \ $ g++ -I$JAVA_HOME/include -I$JAVA_HOME/include/linux \
-D_JNI_IMPLEMENTATION_ -c bootimage-main.cpp -o main.o -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. executable, and optionally strip its symbols.
$ g++ -rdynamic *.o -ldl -lpthread -lz -o hello $ g++ -rdynamic *.o -ldl -lpthread -lz -o hello

View File

@ -55,7 +55,7 @@ public:
unsigned addr; unsigned addr;
String name; String name;
inline SymbolInfo(uint64_t addr, const char* name): inline SymbolInfo(uint64_t addr, const String& name):
addr(addr), addr(addr),
name(name) {} name(name) {}

View File

@ -1292,28 +1292,32 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp
class MyCompilationHandler : public Processor::CompilationHandler { class MyCompilationHandler : public Processor::CompilationHandler {
public: 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) { String heapDup(const char* name) {
size_t classLen = strlen(class_); String ret(name);
size_t nameLen = strlen(name); char* n = (char*)heap->allocate(ret.length + 1);
size_t specLen = strlen(spec); memcpy(n, ret.text, ret.length + 1);
ret.text = n;
char* completeName = (char*)malloc(classLen + nameLen + specLen + 2); return ret;
sprintf(completeName, "%s.%s%s", class_, name, spec); }
uint64_t offset = reinterpret_cast<uint64_t>(code) - codeOffset;
symbols.add(SymbolInfo(offset, completeName)); virtual void compiled(const void* code, unsigned size UNUSED, unsigned frameSize UNUSED, const char* name) {
// printf("%ld %ld %s.%s%s\n", offset, offset + size, class_, name, spec); uint64_t offset = reinterpret_cast<uint64_t>(code) - codeOffset;
} symbols.add(SymbolInfo(offset, heapDup(name)));
// printf("%ld %ld %s.%s%s\n", offset, offset + size, class_, name, spec);
} }
virtual void dispose() {} virtual void dispose() {}
DynamicArray<SymbolInfo> symbols; DynamicArray<SymbolInfo> symbols;
uint64_t codeOffset; uint64_t codeOffset;
Heap* heap;
MyCompilationHandler(uint64_t codeOffset): MyCompilationHandler(uint64_t codeOffset, Heap* heap):
codeOffset(codeOffset) {} codeOffset(codeOffset),
} compilationHandler(reinterpret_cast<uint64_t>(code)); heap(heap) {}
} compilationHandler(reinterpret_cast<uint64_t>(code), t->m->heap);
t->m->processor->addCompilationHandler(&compilationHandler); t->m->processor->addCompilationHandler(&compilationHandler);
@ -1661,13 +1665,13 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp
platform->writeObject(bootimageOutput, Slice<SymbolInfo>(bootimageSymbols, 2), Slice<const uint8_t>(bootimageData.data, bootimageData.length), Platform::Writable, TargetBytesPerWord); platform->writeObject(bootimageOutput, Slice<SymbolInfo>(bootimageSymbols, 2), Slice<const uint8_t>(bootimageData.data, bootimageData.length), Platform::Writable, TargetBytesPerWord);
compilationHandler.symbols.add(SymbolInfo(0, strdup("_binary_codeimage_bin_start"))); compilationHandler.symbols.add(SymbolInfo(0, "_binary_codeimage_bin_start"));
compilationHandler.symbols.add(SymbolInfo(image->codeSize, strdup("_binary_codeimage_bin_end"))); compilationHandler.symbols.add(SymbolInfo(image->codeSize, "_binary_codeimage_bin_end"));
platform->writeObject(codeOutput, Slice<SymbolInfo>(compilationHandler.symbols), Slice<const uint8_t>(code, image->codeSize), Platform::Executable, TargetBytesPerWord); platform->writeObject(codeOutput, Slice<SymbolInfo>(compilationHandler.symbols), Slice<const uint8_t>(code, image->codeSize), Platform::Executable, TargetBytesPerWord);
for(SymbolInfo* sym = compilationHandler.symbols.begin(); sym != compilationHandler.symbols.end(); sym++) { for(SymbolInfo* sym = compilationHandler.symbols.begin(); sym != compilationHandler.symbols.end() - 2; sym++) {
free(const_cast<void*>((const void*)sym->name.text)); t->m->heap->free(const_cast<void*>((const void*)sym->name.text), sym->name.length + 1);
} }
} }
} }

View File

@ -9093,6 +9093,20 @@ class MyProcessor: public Processor {
CompilationHandlerList* compilationHandlers; 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 void
logCompile(MyThread* t, const void* code, unsigned size, const char* class_, logCompile(MyThread* t, const void* code, unsigned size, const char* class_,
const char* name, const char* spec) const char* name, const char* spec)
@ -9114,9 +9128,15 @@ logCompile(MyThread* t, const void* code, unsigned size, const char* class_,
class_, name, spec); 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<MyProcessor*>(t->m->processor); MyProcessor* p = static_cast<MyProcessor*>(t->m->processor);
for(CompilationHandlerList* h = p->compilationHandlers; h; h = h->next) { 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->setDestination(start);
a->write(); 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<uintptr_t>(start); return reinterpret_cast<uintptr_t>(start);
} }

View File

@ -43,7 +43,7 @@ class Processor {
class CompilationHandler { class CompilationHandler {
public: 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; virtual void dispose() = 0;
}; };