mirror of
https://github.com/corda/corda.git
synced 2025-01-31 16:35:43 +00:00
write java symbols to bootimage
This commit is contained in:
parent
b742c58055
commit
a09736e749
@ -12,6 +12,7 @@
|
|||||||
#define AVIAN_TOOLS_H_
|
#define AVIAN_TOOLS_H_
|
||||||
|
|
||||||
#include "environment.h"
|
#include "environment.h"
|
||||||
|
#include <malloc.h>
|
||||||
|
|
||||||
namespace avian {
|
namespace avian {
|
||||||
|
|
||||||
@ -86,6 +87,10 @@ public:
|
|||||||
items(items),
|
items(items),
|
||||||
count(count) {}
|
count(count) {}
|
||||||
|
|
||||||
|
inline Slice(const Slice<T>& copy):
|
||||||
|
items(copy.items),
|
||||||
|
count(copy.count) {}
|
||||||
|
|
||||||
inline T* begin() {
|
inline T* begin() {
|
||||||
return items;
|
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 {
|
class PlatformInfo {
|
||||||
public:
|
public:
|
||||||
enum OperatingSystem {
|
enum OperatingSystem {
|
||||||
|
@ -1293,6 +1293,32 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp
|
|||||||
{
|
{
|
||||||
Zone zone(t->m->system, t->m->heap, 64 * 1024);
|
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 classPoolMap;
|
||||||
object typeMaps;
|
object typeMaps;
|
||||||
object constants;
|
object constants;
|
||||||
@ -1603,7 +1629,7 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp
|
|||||||
bootimageOutput->writeChunk(stringTable, image->stringCount * sizeof(unsigned));
|
bootimageOutput->writeChunk(stringTable, image->stringCount * sizeof(unsigned));
|
||||||
bootimageOutput->writeChunk(callTable, image->callCount * sizeof(unsigned) * 2);
|
bootimageOutput->writeChunk(callTable, image->callCount * sizeof(unsigned) * 2);
|
||||||
|
|
||||||
unsigned offset = sizeof(BootImage)
|
unsigned offset = sizeof(BootImage)
|
||||||
+ (image->bootClassCount * sizeof(unsigned))
|
+ (image->bootClassCount * sizeof(unsigned))
|
||||||
+ (image->appClassCount * sizeof(unsigned))
|
+ (image->appClassCount * sizeof(unsigned))
|
||||||
+ (image->stringCount * sizeof(unsigned))
|
+ (image->stringCount * sizeof(unsigned))
|
||||||
@ -1628,15 +1654,10 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp
|
|||||||
// return false;
|
// return false;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
const char* const startName = "_binary_codeimage_bin_start";
|
compilationHandler.symbols.add(SymbolInfo(0, "_binary_codeimage_bin_start"));
|
||||||
const char* const endName = "_binary_codeimage_bin_end";
|
compilationHandler.symbols.add(SymbolInfo(image->codeSize, "_binary_codeimage_bin_end"));
|
||||||
|
|
||||||
SymbolInfo symbols[] = {
|
platform->writeObject(codeOutput, Slice<SymbolInfo>(compilationHandler.symbols), Slice<const uint8_t>(code, image->codeSize), Platform::Executable, TargetBytesPerWord);
|
||||||
SymbolInfo(0, startName),
|
|
||||||
SymbolInfo(image->codeSize, endName)
|
|
||||||
};
|
|
||||||
|
|
||||||
platform->writeObject(codeOutput, Slice<SymbolInfo>(symbols, 2), Slice<const uint8_t>(code, image->codeSize), Platform::Executable, TargetBytesPerWord);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6149,25 +6149,7 @@ FILE* compileLog = 0;
|
|||||||
|
|
||||||
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);
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
resolveIpForwards(Context* context, int start, int end)
|
resolveIpForwards(Context* context, int start, int end)
|
||||||
@ -8448,6 +8430,24 @@ processor(MyThread* t);
|
|||||||
void
|
void
|
||||||
compileThunks(MyThread* t, FixedAllocator* allocator);
|
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 {
|
class MyProcessor: public Processor {
|
||||||
public:
|
public:
|
||||||
class Thunk {
|
class Thunk {
|
||||||
@ -8491,7 +8491,8 @@ class MyProcessor: public Processor {
|
|||||||
FixedSizeOfArithmeticException),
|
FixedSizeOfArithmeticException),
|
||||||
codeAllocator(s, 0, 0),
|
codeAllocator(s, 0, 0),
|
||||||
callTableSize(0),
|
callTableSize(0),
|
||||||
useNativeFeatures(useNativeFeatures)
|
useNativeFeatures(useNativeFeatures),
|
||||||
|
compilationHandlers(0)
|
||||||
{
|
{
|
||||||
thunkTable[compileMethodIndex] = voidPointer(local::compileMethod);
|
thunkTable[compileMethodIndex] = voidPointer(local::compileMethod);
|
||||||
thunkTable[compileVirtualMethodIndex] = voidPointer(compileVirtualMethod);
|
thunkTable[compileVirtualMethodIndex] = voidPointer(compileVirtualMethod);
|
||||||
@ -8797,6 +8798,7 @@ class MyProcessor: public Processor {
|
|||||||
t->arch->release();
|
t->arch->release();
|
||||||
|
|
||||||
t->m->heap->free(t, sizeof(*t));
|
t->m->heap->free(t, sizeof(*t));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void dispose() {
|
virtual void dispose() {
|
||||||
@ -8804,6 +8806,8 @@ class MyProcessor: public Processor {
|
|||||||
s->freeExecutable(codeAllocator.base, codeAllocator.capacity);
|
s->freeExecutable(codeAllocator.base, codeAllocator.capacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
compilationHandlers->dispose(allocator);
|
||||||
|
|
||||||
s->handleSegFault(0);
|
s->handleSegFault(0);
|
||||||
|
|
||||||
allocator->free(this, sizeof(*this));
|
allocator->free(this, sizeof(*this));
|
||||||
@ -8900,6 +8904,10 @@ class MyProcessor: public Processor {
|
|||||||
codeAllocator.capacity = capacity;
|
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,
|
virtual void compileMethod(Thread* vmt, Zone* zone, object* constants,
|
||||||
object* calls, DelayedPromise** addresses,
|
object* calls, DelayedPromise** addresses,
|
||||||
object method, OffsetResolver* resolver)
|
object method, OffsetResolver* resolver)
|
||||||
@ -9055,8 +9063,36 @@ class MyProcessor: public Processor {
|
|||||||
unsigned callTableSize;
|
unsigned callTableSize;
|
||||||
bool useNativeFeatures;
|
bool useNativeFeatures;
|
||||||
void* thunkTable[dummyIndex + 1];
|
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*
|
void*
|
||||||
compileMethod2(MyThread* t, void* ip)
|
compileMethod2(MyThread* t, void* ip)
|
||||||
{
|
{
|
||||||
|
@ -3067,6 +3067,10 @@ class MyProcessor: public Processor {
|
|||||||
abort(s);
|
abort(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void addCompilationHandler(CompilationHandler* handler) {
|
||||||
|
abort(s);
|
||||||
|
}
|
||||||
|
|
||||||
virtual void compileMethod(vm::Thread*, Zone*, object*, object*,
|
virtual void compileMethod(vm::Thread*, Zone*, object*, object*,
|
||||||
DelayedPromise**, object, OffsetResolver*)
|
DelayedPromise**, object, OffsetResolver*)
|
||||||
{
|
{
|
||||||
|
@ -41,6 +41,13 @@ class Processor {
|
|||||||
virtual unsigned count() = 0;
|
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*
|
virtual Thread*
|
||||||
makeThread(Machine* m, object javaThread, Thread* parent) = 0;
|
makeThread(Machine* m, object javaThread, Thread* parent) = 0;
|
||||||
|
|
||||||
@ -120,6 +127,9 @@ class Processor {
|
|||||||
virtual void
|
virtual void
|
||||||
initialize(BootImage* image, uint8_t* code, unsigned capacity) = 0;
|
initialize(BootImage* image, uint8_t* code, unsigned capacity) = 0;
|
||||||
|
|
||||||
|
virtual void
|
||||||
|
addCompilationHandler(CompilationHandler* handler) = 0;
|
||||||
|
|
||||||
virtual void
|
virtual void
|
||||||
compileMethod(Thread* t, Zone* zone, object* constants, object* calls,
|
compileMethod(Thread* t, Zone* zone, object* constants, object* calls,
|
||||||
DelayedPromise** addresses, object method,
|
DelayedPromise** addresses, object method,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user