support logging addresses and names of JIT-compiled methods to a file specified via a system property

This commit is contained in:
Joel Dice 2008-09-19 11:34:37 -06:00
parent 27efbcf5e1
commit 1657fb794c
6 changed files with 70 additions and 17 deletions

View File

@ -456,6 +456,11 @@ Java_java_lang_System_getVMProperty(Thread* t, jclass, jstring name,
r = makeLocalReference(t, makeString(t, "%s", t->m->finder->path()));
} else if (strcmp(n, "avian.version") == 0) {
r = makeLocalReference(t, makeString(t, AVIAN_VERSION));
} else {
const char* v = findProperty(t, n);
if (v) {
r = makeLocalReference(t, makeString(t, v));
}
}
if (r) {

View File

@ -27,7 +27,7 @@ vmCall();
namespace {
const bool Verbose = false;
const bool DebugCompile = true;
const bool DebugNatives = false;
const bool DebugCallTable = false;
const bool DebugMethodTree = false;
@ -3389,12 +3389,26 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip,
}
void
logCompile(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)
{
fprintf(stderr, "%s.%s%s: %p %p\n",
class_, name, spec, code,
static_cast<const uint8_t*>(code) + size);
static FILE* log = 0;
static bool open = false;
if (not open) {
open = true;
const char* path = findProperty(t, "avian.jit.log");
if (name) {
log = fopen(path, "wb");
} else {
log = stderr;
}
}
if (log) {
fprintf(log, "%p %p %s.%s%s\n",
code, static_cast<const uint8_t*>(code) + size,
class_, name, spec);
}
}
void
@ -3644,8 +3658,8 @@ finish(MyThread* t, Assembler* a, const char* name)
a->writeTo(start);
if (Verbose) {
logCompile(start, a->length(), 0, name, 0);
if (DebugCompile) {
logCompile(t, start, a->length(), 0, name, 0);
}
return result;
@ -3740,9 +3754,9 @@ finish(MyThread* t, Context* context)
set(t, result, SingletonBody + offset, p->value);
}
if (Verbose) {
if (DebugCompile) {
logCompile
(start, codeSize,
(t, start, codeSize,
reinterpret_cast<const char*>
(&byteArrayBody(t, className(t, methodClass(t, context->method)), 0)),
reinterpret_cast<const char*>
@ -4992,9 +5006,9 @@ compileThunks(MyThread* t, MyProcessor* p)
uint8_t* start = reinterpret_cast<uint8_t*>
(&singletonValue(t, p->thunkTable, 0));
if (Verbose) {
logCompile(start, p->thunkSize * ThunkCount, 0, "thunkTable", 0);
fprintf(stderr, "thunk size: %d\n", p->thunkSize);
if (DebugCompile) {
logCompile(t, start, p->thunkSize * ThunkCount, 0, "thunkTable", 0);
//fprintf(stderr, "thunk size: %d\n", p->thunkSize);
}
tableContext.promise.resolved_ = true;

View File

@ -20,7 +20,7 @@ void*
allocate(System* s, unsigned size)
{
void* p = s->tryAllocate(size);
if (p == 0) abort();
if (p == 0) s->abort();
return p;
}

View File

@ -2072,6 +2072,8 @@ JNI_CreateJavaVM(Machine** m, Thread** t, void* args)
const char* bootClasspath = "";
const char* bootClasspathAppend = "";
unsigned propertyCount = 0;
for (int i = 0; i < a->nOptions; ++i) {
if (strncmp(a->options[i].optionString, "-X", 2) == 0) {
const char* p = a->options[i].optionString + 2;
@ -2106,7 +2108,7 @@ JNI_CreateJavaVM(Machine** m, Thread** t, void* args)
classpath = p + sizeof(CLASSPATH_PROPERTY);
}
// todo: add properties to VM
++ propertyCount;
}
}
@ -2133,8 +2135,17 @@ JNI_CreateJavaVM(Machine** m, Thread** t, void* args)
Finder* f = makeFinder(s, classpathBuffer, bootLibrary);
Processor* p = makeProcessor(s, h);
const char** properties = static_cast<const char**>
(h->allocate(sizeof(const char*) * propertyCount));
const char** propertyPointer = properties;
for (int i = 0; i < a->nOptions; ++i) {
if (strncmp(a->options[i].optionString, "-D", 2) == 0) {
*(propertyPointer++) = a->options[i].optionString + 2;
}
}
*m = new (h->allocate(sizeof(Machine)))
Machine(s, h, f, p, bootLibrary, builtins);
Machine(s, h, f, p, bootLibrary, builtins, properties, propertyCount);
*t = p->makeThread(*m, 0, 0);

View File

@ -1633,7 +1633,8 @@ namespace vm {
Machine::Machine(System* system, Heap* heap, Finder* finder,
Processor* processor, const char* bootLibrary,
const char* builtins):
const char* builtins, const char** properties,
unsigned propertyCount):
vtable(&javaVMVTable),
system(system),
heapClient(new (heap->allocate(sizeof(HeapClient)))
@ -1645,6 +1646,8 @@ Machine::Machine(System* system, Heap* heap, Finder* finder,
exclusive(0),
jniReferences(0),
builtins(builtins),
properties(properties),
propertyCount(propertyCount),
activeCount(0),
liveCount(0),
fixedFootprint(0),

View File

@ -1122,7 +1122,8 @@ class Machine {
};
Machine(System* system, Heap* heap, Finder* finder, Processor* processor,
const char* bootLibrary, const char* builtins);
const char* bootLibrary, const char* builtins,
const char** properties, unsigned propertyCount);
~Machine() {
dispose();
@ -1144,6 +1145,8 @@ class Machine {
Thread* exclusive;
Reference* jniReferences;
const char* builtins;
const char** properties;
unsigned propertyCount;
unsigned activeCount;
unsigned liveCount;
unsigned fixedFootprint;
@ -1510,6 +1513,23 @@ setObjectClass(Thread*, object o, object value)
| (reinterpret_cast<uintptr_t>(cast<object>(o, 0)) & (~PointerMask)));
}
inline const char*
findProperty(Thread* t, const char* name)
{
for (unsigned i = 0; i < t->m->propertyCount; ++i) {
const char* p = t->m->properties[i];
const char* n = name;
while (*p and *p != '=' and *n and *p == *n) {
++ p;
++ n;
}
if (*p == '=' and *n == 0) {
return p + 1;
}
}
return 0;
}
object&
arrayBodyUnsafe(Thread*, object, unsigned);