write java symbols to bootimage

This commit is contained in:
Joshua Warner 2012-05-02 09:49:31 -06:00
parent b742c58055
commit a09736e749
5 changed files with 130 additions and 29 deletions

View File

@ -12,6 +12,7 @@
#define AVIAN_TOOLS_H_
#include "environment.h"
#include <malloc.h>
namespace avian {
@ -86,6 +87,10 @@ public:
items(items),
count(count) {}
inline Slice(const Slice<T>& copy):
items(copy.items),
count(copy.count) {}
inline T* begin() {
return items;
}
@ -95,6 +100,31 @@ public:
}
};
template<class T>
class DynamicArray : public Slice<T> {
public:
size_t capacity;
DynamicArray():
Slice<T>((T*)malloc(10 * sizeof(T)), 0),
capacity(10) {}
~DynamicArray() {
free(Slice<T>::items);
}
void ensure(size_t more) {
if(Slice<T>::count + more > capacity) {
capacity = capacity * 2 + more;
Slice<T>::items = (T*)realloc(Slice<T>::items, capacity * sizeof(T));
}
}
void add(const T& item) {
ensure(1);
Slice<T>::items[Slice<T>::count++] = item;
}
};
class PlatformInfo {
public:
enum OperatingSystem {

View File

@ -1293,6 +1293,32 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp
{
Zone zone(t->m->system, t->m->heap, 64 * 1024);
class MyCompilationHandler : public Processor::CompilationHandler {
public:
virtual void compiled(const void* code, unsigned size, unsigned frameSize UNUSED, const char* class_, const char* name, const char* 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<uint64_t>(code) - codeOffset;
symbols.add(SymbolInfo(offset, completeName));
// printf("%ld %ld %s.%s%s\n", offset, offset + size, class_, name, spec);
free(completeName);
}
virtual void dispose() {}
DynamicArray<SymbolInfo> symbols;
uint64_t codeOffset;
MyCompilationHandler(uint64_t codeOffset):
codeOffset(codeOffset) {}
} compilationHandler(reinterpret_cast<uint64_t>(code));
t->m->processor->addCompilationHandler(&compilationHandler);
object classPoolMap;
object typeMaps;
object constants;
@ -1603,7 +1629,7 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp
bootimageOutput->writeChunk(stringTable, image->stringCount * sizeof(unsigned));
bootimageOutput->writeChunk(callTable, image->callCount * sizeof(unsigned) * 2);
unsigned offset = sizeof(BootImage)
unsigned offset = sizeof(BootImage)
+ (image->bootClassCount * sizeof(unsigned))
+ (image->appClassCount * sizeof(unsigned))
+ (image->stringCount * sizeof(unsigned))
@ -1628,15 +1654,10 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp
// return false;
// }
const char* const startName = "_binary_codeimage_bin_start";
const char* const endName = "_binary_codeimage_bin_end";
compilationHandler.symbols.add(SymbolInfo(0, "_binary_codeimage_bin_start"));
compilationHandler.symbols.add(SymbolInfo(image->codeSize, "_binary_codeimage_bin_end"));
SymbolInfo symbols[] = {
SymbolInfo(0, startName),
SymbolInfo(image->codeSize, endName)
};
platform->writeObject(codeOutput, Slice<SymbolInfo>(symbols, 2), 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);
}
}

View File

@ -6149,25 +6149,7 @@ FILE* compileLog = 0;
void
logCompile(MyThread* t, const void* code, unsigned size, const char* class_,
const char* name, const char* spec)
{
static bool open = false;
if (not open) {
open = true;
const char* path = findProperty(t, "avian.jit.log");
if (path) {
compileLog = vm::fopen(path, "wb");
} else if (DebugCompile) {
compileLog = stderr;
}
}
if (compileLog) {
fprintf(compileLog, "%p %p %s.%s%s\n",
code, static_cast<const uint8_t*>(code) + size,
class_, name, spec);
}
}
const char* name, const char* spec);
int
resolveIpForwards(Context* context, int start, int end)
@ -8448,6 +8430,24 @@ processor(MyThread* t);
void
compileThunks(MyThread* t, FixedAllocator* allocator);
class CompilationHandlerList {
public:
CompilationHandlerList(CompilationHandlerList* next, Processor::CompilationHandler* handler):
next(next),
handler(handler) {}
void dispose(Allocator* allocator) {
if(this) {
next->dispose(allocator);
handler->dispose();
allocator->free(this, sizeof(*this));
}
}
CompilationHandlerList* next;
Processor::CompilationHandler* handler;
};
class MyProcessor: public Processor {
public:
class Thunk {
@ -8491,7 +8491,8 @@ class MyProcessor: public Processor {
FixedSizeOfArithmeticException),
codeAllocator(s, 0, 0),
callTableSize(0),
useNativeFeatures(useNativeFeatures)
useNativeFeatures(useNativeFeatures),
compilationHandlers(0)
{
thunkTable[compileMethodIndex] = voidPointer(local::compileMethod);
thunkTable[compileVirtualMethodIndex] = voidPointer(compileVirtualMethod);
@ -8797,6 +8798,7 @@ class MyProcessor: public Processor {
t->arch->release();
t->m->heap->free(t, sizeof(*t));
}
virtual void dispose() {
@ -8804,6 +8806,8 @@ class MyProcessor: public Processor {
s->freeExecutable(codeAllocator.base, codeAllocator.capacity);
}
compilationHandlers->dispose(allocator);
s->handleSegFault(0);
allocator->free(this, sizeof(*this));
@ -8900,6 +8904,10 @@ class MyProcessor: public Processor {
codeAllocator.capacity = capacity;
}
virtual void addCompilationHandler(CompilationHandler* handler) {
compilationHandlers = new(allocator->allocate(sizeof(CompilationHandlerList))) CompilationHandlerList(compilationHandlers, handler);
}
virtual void compileMethod(Thread* vmt, Zone* zone, object* constants,
object* calls, DelayedPromise** addresses,
object method, OffsetResolver* resolver)
@ -9055,8 +9063,36 @@ class MyProcessor: public Processor {
unsigned callTableSize;
bool useNativeFeatures;
void* thunkTable[dummyIndex + 1];
CompilationHandlerList* compilationHandlers;
};
void
logCompile(MyThread* t, const void* code, unsigned size, const char* class_,
const char* name, const char* spec)
{
static bool open = false;
if (not open) {
open = true;
const char* path = findProperty(t, "avian.jit.log");
if (path) {
compileLog = vm::fopen(path, "wb");
} else if (DebugCompile) {
compileLog = stderr;
}
}
if (compileLog) {
fprintf(compileLog, "%p %p %s.%s%s\n",
code, static_cast<const uint8_t*>(code) + size,
class_, name, spec);
}
MyProcessor* p = static_cast<MyProcessor*>(t->m->processor);
for(CompilationHandlerList* h = p->compilationHandlers; h; h = h->next) {
h->handler->compiled(code, 0, 0, class_, name, spec);
}
}
void*
compileMethod2(MyThread* t, void* ip)
{

View File

@ -3067,6 +3067,10 @@ class MyProcessor: public Processor {
abort(s);
}
virtual void addCompilationHandler(CompilationHandler* handler) {
abort(s);
}
virtual void compileMethod(vm::Thread*, Zone*, object*, object*,
DelayedPromise**, object, OffsetResolver*)
{

View File

@ -41,6 +41,13 @@ class Processor {
virtual unsigned count() = 0;
};
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 dispose() = 0;
};
virtual Thread*
makeThread(Machine* m, object javaThread, Thread* parent) = 0;
@ -120,6 +127,9 @@ class Processor {
virtual void
initialize(BootImage* image, uint8_t* code, unsigned capacity) = 0;
virtual void
addCompilationHandler(CompilationHandler* handler) = 0;
virtual void
compileMethod(Thread* t, Zone* zone, object* constants, object* calls,
DelayedPromise** addresses, object method,