[vmkit-commits] [vmkit] r199744 - Add a flag in j3meta.def to explicitly inform j3codegen when we want to create a local symbol.
Gael Thomas
gael.thomas at lip6.fr
Tue Jan 21 06:17:27 PST 2014
Author: gthomas
Date: Tue Jan 21 08:17:26 2014
New Revision: 199744
URL: http://llvm.org/viewvc/llvm-project?rev=199744&view=rev
Log:
Add a flag in j3meta.def to explicitly inform j3codegen when we want to create a local symbol.
Modified:
vmkit/branches/mcjit/include/j3/j3codegen.h
vmkit/branches/mcjit/include/j3/j3meta.def
vmkit/branches/mcjit/include/j3/j3object.h
vmkit/branches/mcjit/lib/j3/vm/j3class.cc
vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc
vmkit/branches/mcjit/lib/j3/vm/j3object.cc
vmkit/branches/mcjit/lib/vmkit/vmkit.cc
Modified: vmkit/branches/mcjit/include/j3/j3codegen.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3codegen.h?rev=199744&r1=199743&r2=199744&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3codegen.h (original)
+++ vmkit/branches/mcjit/include/j3/j3codegen.h Tue Jan 21 08:17:26 2014
@@ -197,7 +197,7 @@ namespace j3 {
void genDebugOpcode();
void genDebugEnterLeave(bool isLeave);
-#define _x(name, id) \
+#define _x(name, id, isLocal) \
llvm::Function* name;
#include "j3/j3meta.def"
#undef _x
Modified: vmkit/branches/mcjit/include/j3/j3meta.def
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3meta.def?rev=199744&r1=199743&r2=199744&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3meta.def (original)
+++ vmkit/branches/mcjit/include/j3/j3meta.def Tue Jan 21 08:17:26 2014
@@ -1,27 +1,25 @@
-_x(funcJ3TypeVT, "j3::J3Type::vt()")
-_x(funcJ3ObjectTypeResolve, "j3::J3Type::resolve()")
-_x(funcJ3ObjectTypeInitialise, "j3::J3Type::initialise()")
-_x(funcJ3TypeJavaClass, "j3::J3Type::javaClass(bool, j3::J3ObjectHandle*)")
-_x(funcJniEnv, "j3::J3::jniEnv()")
-_x(funcJ3ArrayObjectMultianewArray, "j3::J3ArrayObject::multianewArray(j3::J3ArrayClass*, unsigned int, unsigned int*)")
-_x(funcJ3ObjectAllocate, "j3::J3Object::allocate(j3::J3VirtualTable*, unsigned long)")
-_x(funcJ3ObjectMonitorEnter, "j3::J3Object::monitorEnter(j3::J3Object*)")
-_x(funcJ3ObjectMonitorExit, "j3::J3Object::monitorExit(j3::J3Object*)")
-_x(funcThrowException, "vmkit::VMKit::throwException(void*)")
-_x(funcReplayException, "j3::J3Thread::replayException()")
-_x(funcClassCastException, "j3::J3::classCastException()")
-_x(funcNullPointerException, "j3::J3::nullPointerException()")
-_x(funcJ3ThreadPushHandle, "j3::J3Thread::push(j3::J3ObjectHandle*)")
-_x(funcJ3ThreadPush, "j3::J3Thread::push(j3::J3Object*)")
-_x(funcJ3ThreadTell, "j3::J3Thread::tell()")
-_x(funcJ3ThreadRestore, "j3::J3Thread::restore(j3::J3ObjectHandle*)")
-_x(funcEchoDebugEnter, "j3::J3CodeGen::echoDebugEnter(unsigned int, char const*, ...)")
-_x(funcEchoDebugExecute, "j3::J3CodeGen::echoDebugExecute(unsigned int, char const*, ...)")
-_x(funcEchoElement, "j3::J3CodeGen::echoElement(unsigned int, unsigned int, unsigned long)")
-_x(funcIsAssignableTo, "j3::J3VirtualTable::isAssignableTo(j3::J3VirtualTable*)")
-_x(funcFastIsAssignableToPrimaryChecker, "j3::J3VirtualTable::fastIsAssignableToPrimaryChecker(j3::J3VirtualTable*, unsigned int)")
-_x(funcFastIsAssignableToNonPrimaryChecker, "j3::J3VirtualTable::fastIsAssignableToNonPrimaryChecker(j3::J3VirtualTable*)")
-_x(funcGXXPersonality, "__gxx_personality_v0")
-_x(funcCXABeginCatch, "__cxa_begin_catch")
-_x(funcCXAEndCatch, "__cxa_end_catch")
-_x(funcFake, "j3::J3::forceSymbolDefinition()")
+_x(funcJ3ObjectTypeResolve, "j3::J3Type::resolve()", 1)
+_x(funcJ3ObjectTypeInitialise, "j3::J3Type::initialise()", 1)
+_x(funcJ3TypeJavaClass, "j3::J3Type::javaClass(bool, j3::J3ObjectHandle*)", 1)
+_x(funcJniEnv, "j3::J3::jniEnv()", 1)
+_x(funcJ3ArrayObjectMultianewArray, "j3::J3ArrayObject::multianewArray(j3::J3ArrayClass*, unsigned int, unsigned int*)", 1)
+_x(funcJ3ObjectAllocate, "j3::J3Object::allocate(j3::J3VirtualTable*, unsigned long)", 1)
+_x(funcJ3ObjectMonitorEnter, "j3::J3Object::monitorEnter(j3::J3Object*)", 1)
+_x(funcJ3ObjectMonitorExit, "j3::J3Object::monitorExit(j3::J3Object*)", 1)
+_x(funcThrowException, "vmkit::VMKit::throwException(void*)", 1)
+_x(funcReplayException, "j3::J3Thread::replayException()", 1)
+_x(funcClassCastException, "j3::J3::classCastException()", 1)
+_x(funcNullPointerException, "j3::J3::nullPointerException()", 1)
+_x(funcJ3ThreadPushHandle, "j3::J3Thread::push(j3::J3ObjectHandle*)", 1)
+_x(funcJ3ThreadPush, "j3::J3Thread::push(j3::J3Object*)", 1)
+_x(funcJ3ThreadTell, "j3::J3Thread::tell()", 1)
+_x(funcJ3ThreadRestore, "j3::J3Thread::restore(j3::J3ObjectHandle*)", 1)
+_x(funcEchoDebugEnter, "j3::J3CodeGen::echoDebugEnter(unsigned int, char const*, ...)", 1)
+_x(funcEchoDebugExecute, "j3::J3CodeGen::echoDebugExecute(unsigned int, char const*, ...)", 1)
+_x(funcEchoElement, "j3::J3CodeGen::echoElement(unsigned int, unsigned int, unsigned long)", 1)
+_x(funcFastIsAssignableToPrimaryChecker, "j3::J3VirtualTable::fastIsAssignableToPrimaryChecker(j3::J3VirtualTable*, unsigned int)", 1)
+_x(funcFastIsAssignableToNonPrimaryChecker, "j3::J3VirtualTable::fastIsAssignableToNonPrimaryChecker(j3::J3VirtualTable*)", 1)
+_x(funcGXXPersonality, "__gxx_personality_v0", 1)
+_x(funcCXABeginCatch, "__cxa_begin_catch", 1)
+_x(funcCXAEndCatch, "__cxa_end_catch", 1)
+_x(funcFake, "j3::J3::forceSymbolDefinition()", 1)
Modified: vmkit/branches/mcjit/include/j3/j3object.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3object.h?rev=199744&r1=199743&r2=199744&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3object.h (original)
+++ vmkit/branches/mcjit/include/j3/j3object.h Tue Jan 21 08:17:26 2014
@@ -51,7 +51,9 @@ namespace j3 {
private:
J3Type* _type;
- J3TypeChecker _checker;
+ public:
+ J3TypeChecker checker;
+ private:
// see: Bowen Alpern, Anthony Cocchi, Stephen Fink, and David Grove. 2001.
// Efficient implementation of Java interfaces: Invokeinterface considered harmless. OOPSLA 2001.
void* _interfaceMethodTable[nbInterfaceMethodTable];
@@ -66,12 +68,10 @@ namespace j3 {
static J3VirtualTable* create(J3ArrayClass* cl);
static J3VirtualTable* create(J3Primitive* prim);
- J3TypeChecker* checker() { return &_checker; }
-
- uint32_t offset() { return _checker.offset; }
- bool isPrimaryChecker() { return _checker.offset < J3TypeChecker::cacheOffset; }
+ uint32_t offset() { return checker.offset; }
+ bool isPrimaryChecker() { return checker.offset < J3TypeChecker::cacheOffset; }
- bool slowIsAssignableTo(J3VirtualTable* parent);
+ bool slowIsAssignableTo(J3VirtualTable* parent) __attribute__((always_inline));
bool fastIsAssignableToPrimaryChecker(J3VirtualTable* parent, uint32_t parentOffset);
bool fastIsAssignableToNonPrimaryChecker(J3VirtualTable* parent);
bool isAssignableTo(J3VirtualTable* parent);
Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3class.cc?rev=199744&r1=199743&r2=199744&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Tue Jan 21 08:17:26 2014
@@ -217,11 +217,11 @@ void J3ObjectType::prepareInterfaceTable
uint32_t total = 0;
J3InterfaceSlotDescriptor* slots = _interfaceSlotDescriptors;
- for(uint32_t i=0; i<vt()->checker()->nbSecondaryTypes; i++) {
- J3Type* type = vt()->checker()->secondaryTypes[i]->type();
+ for(uint32_t i=0; i<vt()->checker.nbSecondaryTypes; i++) {
+ J3Type* type = vt()->checker.secondaryTypes[i]->type();
if(type->isClass()) {
- J3Class* ifce = vt()->checker()->secondaryTypes[i]->type()->asClass();
+ J3Class* ifce = vt()->checker.secondaryTypes[i]->type()->asClass();
if(J3Cst::isInterface(ifce->access())) {
//fprintf(stderr, " processing interface: %s\n", ifce->name()->cStr());
for(uint32_t j=0; j<ifce->nbMethods(); j++) {
Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=199744&r1=199743&r2=199744&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Tue Jan 21 08:17:26 2014
@@ -21,6 +21,9 @@
#include "llvm/IR/Argument.h"
#include "llvm/IR/Intrinsics.h"
+#include "llvm/Transforms/Utils/Cloning.h"
+#include "llvm/Support/CallSite.h"
+
#include "llvm/DebugInfo.h"
#include "llvm/DIBuilder.h"
@@ -69,8 +72,8 @@ J3CodeGen::J3CodeGen(vmkit::BumpAllocato
uintPtrTy = vm->dataLayout()->getIntPtrType(module->getContext());
nullValue = llvm::ConstantPointerNull::get((llvm::PointerType*)vm->typeJ3ObjectPtr);
-#define _x(name, id) \
- name = vm->introspectFunction(module, id);
+#define _x(name, id, isLocal) \
+ name = vm->introspectFunction(isLocal ? module : 0, id);
#include "j3/j3meta.def"
#undef _x
@@ -608,14 +611,38 @@ void J3CodeGen::newObject(J3Class* cl) {
llvm::Value* J3CodeGen::isAssignableTo(llvm::Value* obj, J3ObjectType* type) {
llvm::Value* vtType = vt(type); /* force the resolution of type */
llvm::Value* vtObj = vt(obj);
+ llvm::CallInst* res;
+
+#if 0
+ llvm::Function* pc = vm->introspectFunction(0, "j3::J3VirtualTable::fastIsAssignableToPrimaryChecker(j3::J3VirtualTable*, unsigned int)");
+ llvm::Function* npc = vm->introspectFunction(0, "j3::J3VirtualTable::fastIsAssignableToNonPrimaryChecker(j3::J3VirtualTable*)");
+#endif
if(type->vt()->isPrimaryChecker())
- return builder.CreateCall3(funcFastIsAssignableToPrimaryChecker,
- vtObj,
- vtType,
- builder.getInt32(type->vt()->offset()));
+ res = builder.CreateCall3(funcFastIsAssignableToPrimaryChecker,
+ vtObj,
+ vtType,
+ builder.getInt32(type->vt()->offset()));
else
- return builder.CreateCall2(funcFastIsAssignableToNonPrimaryChecker, vtObj, vtType);
+ res = builder.CreateCall2(funcFastIsAssignableToNonPrimaryChecker,
+ vtObj,
+ vtType);
+
+#if 0
+ llvmFunction->dump();
+ fprintf(stderr, " *** \n");
+
+ llvm::InlineFunctionInfo ifi;
+ llvm::InlineFunction(res, ifi);
+
+ llvmFunction->dump();
+ fprintf(stderr, " ----- \n");
+ //res->dump();
+
+ J3::internalError("implement me");
+#endif
+
+ return res;
}
void J3CodeGen::instanceof(llvm::Value* obj, J3ObjectType* type) {
Modified: vmkit/branches/mcjit/lib/j3/vm/j3object.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3object.cc?rev=199744&r1=199743&r2=199744&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3object.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3object.cc Tue Jan 21 08:17:26 2014
@@ -139,11 +139,11 @@ J3VirtualTable* J3VirtualTable::create(J
super->resolve();
//printf("%s super is %ls (%d)\n", cl->name()->cStr(), super->name()->cStr(), isSecondary);
- uint32_t n = baseClass->vt()->checker()->nbSecondaryTypes;
+ uint32_t n = baseClass->vt()->checker.nbSecondaryTypes;
secondaries = (J3Type**)alloca(n*sizeof(J3Type*));
for(uint32_t i=0; i<n; i++) {
- secondaries[nbSecondaries] = baseClass->vt()->checker()->secondaryTypes[i]->type();
+ secondaries[nbSecondaries] = baseClass->vt()->checker.secondaryTypes[i]->type();
if(secondaries[i] != baseClass) { /* don't add myself */
secondaries[nbSecondaries] = secondaries[nbSecondaries]->getArray(dim);
nbSecondaries++;
@@ -176,67 +176,67 @@ J3VirtualTable::J3VirtualTable(J3Type* t
// printf("*** Building the vt of %s based on %ls at %p\n", type->name()->cStr(), super->name()->cStr(), this);
if(super == type) {
- checker()->offset = 0;
- checker()->display[checker()->offset] = this;
+ checker.offset = 0;
+ checker.display[checker.offset] = this;
if(nbInterfaces)
J3::internalError("a root J3VirtualTable should not have interfaces");
} else {
- uint32_t parentDisplayLength = super->vt()->checker()->offset + 1;
+ uint32_t parentDisplayLength = super->vt()->checker.offset + 1;
- //printf("%s (%p) secondary: %p %p (%d)\n", type->name()->cStr(), this, checker()->secondaryTypes, checker()->display[6], parentDisplayLength);
+ //printf("%s (%p) secondary: %p %p (%d)\n", type->name()->cStr(), this, checker.secondaryTypes, checker.display[6], parentDisplayLength);
if(parentDisplayLength >= J3TypeChecker::cacheOffset)
isSecondary = 1;
- memcpy(checker()->display, super->vt()->checker()->display, parentDisplayLength*sizeof(J3VirtualTable*));
+ memcpy(checker.display, super->vt()->checker.display, parentDisplayLength*sizeof(J3VirtualTable*));
- checker()->nbSecondaryTypes = super->vt()->checker()->nbSecondaryTypes + nbInterfaces + isSecondary;
- checker()->secondaryTypes = (J3VirtualTable**)super->loader()->allocator()->allocate(checker()->nbSecondaryTypes*sizeof(J3VirtualTable*));
+ checker.nbSecondaryTypes = super->vt()->checker.nbSecondaryTypes + nbInterfaces + isSecondary;
+ checker.secondaryTypes = (J3VirtualTable**)super->loader()->allocator()->allocate(checker.nbSecondaryTypes*sizeof(J3VirtualTable*));
//printf("%s: %d - %d %d\n", type->name()->cStr(), isSecondary, parentDisplayLength, J3TypeChecker::displayLength);
if(isSecondary) {
- checker()->offset = J3TypeChecker::cacheOffset;
- checker()->secondaryTypes[0] = this;
+ checker.offset = J3TypeChecker::cacheOffset;
+ checker.secondaryTypes[0] = this;
} else {
- checker()->offset = parentDisplayLength;
- checker()->display[checker()->offset] = this;
+ checker.offset = parentDisplayLength;
+ checker.display[checker.offset] = this;
}
- memcpy(checker()->secondaryTypes + isSecondary,
- super->vt()->checker()->secondaryTypes,
- super->vt()->checker()->nbSecondaryTypes*sizeof(J3VirtualTable*));
+ memcpy(checker.secondaryTypes + isSecondary,
+ super->vt()->checker.secondaryTypes,
+ super->vt()->checker.nbSecondaryTypes*sizeof(J3VirtualTable*));
- for(uint32_t i=0, n=isSecondary+super->vt()->checker()->nbSecondaryTypes; i<nbInterfaces; i++) {
+ for(uint32_t i=0, n=isSecondary+super->vt()->checker.nbSecondaryTypes; i<nbInterfaces; i++) {
J3Type* sec = interfaces[i];
sec->resolve();
- checker()->secondaryTypes[n++] = sec->vt();
+ checker.secondaryTypes[n++] = sec->vt();
}
}
- if(checker()->nbSecondaryTypes) {
- std::sort(checker()->secondaryTypes, &checker()->secondaryTypes[checker()->nbSecondaryTypes]);
- J3VirtualTable** it = std::unique(checker()->secondaryTypes, &checker()->secondaryTypes[checker()->nbSecondaryTypes]);
- checker()->nbSecondaryTypes = std::distance(checker()->secondaryTypes, it);
+ if(checker.nbSecondaryTypes) {
+ std::sort(checker.secondaryTypes, &checker.secondaryTypes[checker.nbSecondaryTypes]);
+ J3VirtualTable** it = std::unique(checker.secondaryTypes, &checker.secondaryTypes[checker.nbSecondaryTypes]);
+ checker.nbSecondaryTypes = std::distance(checker.secondaryTypes, it);
}
//dump();
}
bool J3VirtualTable::slowIsAssignableTo(J3VirtualTable* parent) {
- for(uint32_t i=0; i<checker()->nbSecondaryTypes; i++)
- if(checker()->secondaryTypes[i] == parent) {
- checker()->display[J3TypeChecker::cacheOffset] = parent;
+ for(uint32_t i=0; i<checker.nbSecondaryTypes; i++)
+ if(checker.secondaryTypes[i] == parent) {
+ checker.display[J3TypeChecker::cacheOffset] = parent;
return true;
}
return false;
}
bool J3VirtualTable::fastIsAssignableToPrimaryChecker(J3VirtualTable* parent, uint32_t parentOffset) {
- return checker()->display[parentOffset] == parent;
+ return checker.display[parentOffset] == parent;
}
bool J3VirtualTable::fastIsAssignableToNonPrimaryChecker(J3VirtualTable* parent) {
- if(checker()->display[J3TypeChecker::cacheOffset] == parent)
+ if(checker.display[J3TypeChecker::cacheOffset] == parent)
return true;
else if(parent == this)
return true;
@@ -245,8 +245,8 @@ bool J3VirtualTable::fastIsAssignableToN
}
bool J3VirtualTable::isAssignableTo(J3VirtualTable* parent) {
- uint32_t parentOffset = parent->checker()->offset;
- if(checker()->display[parentOffset] == parent)
+ uint32_t parentOffset = parent->checker.offset;
+ if(checker.display[parentOffset] == parent)
return true;
else if(parentOffset != J3TypeChecker::cacheOffset)
return false;
@@ -260,7 +260,7 @@ void J3VirtualTable::dump() {
fprintf(stderr, "VirtualTable: %s%s (%p)\n",
type()->isLayout() && !type()->isClass() ? "static_" : "",
type()->name()->cStr(), this);
- checker()->dump();
+ checker.dump();
}
Modified: vmkit/branches/mcjit/lib/vmkit/vmkit.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/vmkit.cc?rev=199744&r1=199743&r2=199744&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/vmkit/vmkit.cc (original)
+++ vmkit/branches/mcjit/lib/vmkit/vmkit.cc Tue Jan 21 08:17:26 2014
@@ -90,14 +90,14 @@ llvm::Function* VMKit::introspectFunctio
if(!orig)
internalError("unable to find internal function: %s", name);
- return (llvm::Function*)dest->getOrInsertFunction(orig->getName(), orig->getFunctionType());
+ return dest ? (llvm::Function*)dest->getOrInsertFunction(orig->getName(), orig->getFunctionType()) : orig;
}
llvm::GlobalValue* VMKit::introspectGlobalValue(llvm::Module* dest, const char* name) {
llvm::GlobalValue* orig = mangleMap[name];
if(!orig)
internalError("unable to find internal global value: %s", name);
- return (llvm::GlobalValue*)dest->getOrInsertGlobal(orig->getName(), orig->getType());
+ return dest ? (llvm::GlobalValue*)dest->getOrInsertGlobal(orig->getName(), orig->getType()) : orig;
}
void VMKit::addSymbol(llvm::GlobalValue* gv) {
@@ -110,6 +110,7 @@ void VMKit::addSymbol(llvm::GlobalValue*
char* mangled = (char*)allocator()->allocate(length+1);
strcpy(mangled, tmp);
mangleMap[mangled] = gv;
+ gv->Materialize();
free(realname);
}
More information about the vmkit-commits
mailing list