[vmkit-commits] [vmkit] r140727 - in /vmkit/trunk/lib: J3/Compiler/JavaAOTCompiler.cpp J3/Compiler/LLVMInfo.cpp J3/VMCore/JavaClass.cpp J3/VMCore/UTF8.h Mvm/StaticGCPrinter/VmkitGCPrinter.cpp
Nicolas Geoffray
nicolas.geoffray at lip6.fr
Wed Sep 28 14:25:02 PDT 2011
Author: geoffray
Date: Wed Sep 28 16:25:02 2011
New Revision: 140727
URL: http://llvm.org/viewvc/llvm-project?rev=140727&view=rev
Log:
Support customization for precompiled code.
Modified:
vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp
vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp
vmkit/trunk/lib/J3/VMCore/JavaClass.cpp
vmkit/trunk/lib/J3/VMCore/UTF8.h
vmkit/trunk/lib/Mvm/StaticGCPrinter/VmkitGCPrinter.cpp
Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp?rev=140727&r1=140726&r2=140727&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp Wed Sep 28 16:25:02 2011
@@ -2377,18 +2377,18 @@
for (std::map<Class*, Function*>::iterator
CI = LMI->customizedVersions.begin(),
CE = LMI->customizedVersions.end(); CI != CE; CI++) {
- parseFunction(I->first, NULL);
+ parseFunction(I->first, CI->first);
}
}
}
while (!toCompile.empty()) {
JavaMethod* meth = toCompile.back().first;
- // Class* customizeFor = toCompile.back().second;
+ Class* customizeFor = toCompile.back().second;
// parseFunction may introduce new functions to compile, so
// pop toCompile before calling parseFunction.
toCompile.pop_back();
- parseFunction(meth, NULL);
+ parseFunction(meth, customizeFor);
}
// Make sure classes and arrays already referenced in constant pools
Modified: vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp?rev=140727&r1=140726&r2=140727&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp Wed Sep 28 16:25:02 2011
@@ -140,6 +140,32 @@
extern bool JITEmitDebugInfo;
}
+static char* GetMethodName(mvm::ThreadAllocator& allocator,
+ JavaMethod* methodDef,
+ Class* customizeFor) {
+ const UTF8* jniConsClName = methodDef->classDef->name;
+ const UTF8* jniConsName = methodDef->name;
+ const UTF8* jniConsType = methodDef->type;
+ sint32 clen = jniConsClName->size;
+ sint32 mnlen = jniConsName->size;
+ sint32 mtlen = jniConsType->size;
+
+ char* buf = (char*)allocator.Allocate(
+ 3 + JNI_NAME_PRE_LEN + 1 + ((mnlen + clen + mtlen) << 3));
+
+ methodDef->jniConsFromMethOverloaded(buf + 1);
+ memcpy(buf, "JnJVM", 5);
+
+ if (customizeFor != NULL) {
+ int len = strlen(buf);
+ buf[len] = '_';
+ buf[len + 1] = '_';
+ buf[len + 2] = 0;
+ }
+
+ return buf;
+}
+
Function* LLVMMethodInfo::getMethod(Class* customizeFor) {
bool customizing = false;
Function* result = NULL;
@@ -152,20 +178,9 @@
if (result == NULL) {
if (Compiler->emitFunctionName() || JITEmitDebugInfo) {
- const UTF8* jniConsClName = methodDef->classDef->name;
- const UTF8* jniConsName = methodDef->name;
- const UTF8* jniConsType = methodDef->type;
- sint32 clen = jniConsClName->size;
- sint32 mnlen = jniConsName->size;
- sint32 mtlen = jniConsType->size;
-
mvm::ThreadAllocator allocator;
- char* buf = (char*)allocator.Allocate(
- 3 + JNI_NAME_PRE_LEN + 1 + ((mnlen + clen + mtlen) << 3));
-
- methodDef->jniConsFromMethOverloaded(buf + 1);
- memcpy(buf, "JnJVM", 5);
-
+ char* buf = GetMethodName(
+ allocator, methodDef, customizing ? customizeFor : NULL);
result = Function::Create(getFunctionType(),
GlobalValue::ExternalWeakLinkage, buf,
Compiler->getLLVMModule());
@@ -195,6 +210,9 @@
void LLVMMethodInfo::setCustomizedVersion(Class* cl, llvm::Function* F) {
assert(customizedVersions.size() == 0);
+ mvm::ThreadAllocator allocator;
+ char* buf = GetMethodName(allocator, methodDef, cl);
+ F->setName(buf);
methodFunction = NULL;
customizedVersions[cl] = F;
}
Modified: vmkit/trunk/lib/J3/VMCore/JavaClass.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaClass.cpp?rev=140727&r1=140726&r2=140727&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JavaClass.cpp (original)
+++ vmkit/trunk/lib/J3/VMCore/JavaClass.cpp Wed Sep 28 16:25:02 2011
@@ -1059,7 +1059,7 @@
memcpy(buf, JNI_NAME_PRE, JNI_NAME_PRE_LEN);
- for (sint32 i =0; i < clen; ++i) {
+ for (sint32 i = 0; i < clen; ++i) {
cur = jniConsClName->elements[i];
if (cur == '/') {
ptr[0] = '_';
@@ -1085,7 +1085,7 @@
ptr[0] = '_';
++ptr;
- for (sint32 i =0; i < mnlen; ++i) {
+ for (sint32 i = 0; i < mnlen; ++i) {
cur = jniConsName->elements[i];
if (cur == '/') {
ptr[0] = '_';
@@ -1130,7 +1130,7 @@
memcpy(buf, JNI_NAME_PRE, JNI_NAME_PRE_LEN);
- for (sint32 i =0; i < clen; ++i) {
+ for (sint32 i = 0; i < clen; ++i) {
cur = jniConsClName->elements[i];
if (cur == '/') {
ptr[0] = '_';
@@ -1156,7 +1156,7 @@
ptr[0] = '_';
++ptr;
- for (sint32 i =0; i < mnlen; ++i) {
+ for (sint32 i = 0; i < mnlen; ++i) {
cur = jniConsName->elements[i];
if (cur == '/') ptr[0] = '_';
else if (cur == '_') {
@@ -1228,7 +1228,6 @@
++ptr;
}
ptr[0] = 0;
-
}
Modified: vmkit/trunk/lib/J3/VMCore/UTF8.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/UTF8.h?rev=140727&r1=140726&r2=140727&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/UTF8.h (original)
+++ vmkit/trunk/lib/J3/VMCore/UTF8.h Wed Sep 28 16:25:02 2011
@@ -44,7 +44,7 @@
const char *buffer = contents;
uint32 len = strlen(buffer);
uint32 suffixLen = strlen(suffix);
- char* newBuffer = new char[(len << 1) + suffixLen + 1];
+ char* newBuffer = new char[(len << 3) + suffixLen + 1];
uint32 j = 0;
for (uint32 i = 0; i < len; ++i) {
if (buffer[i] == '/') {
@@ -60,6 +60,10 @@
newBuffer[j++] = '3';
} else if (buffer[i] == '$') {
newBuffer[j++] = '_';
+ newBuffer[j++] = '0';
+ newBuffer[j++] = '0';
+ newBuffer[j++] = '0';
+ newBuffer[j++] = '2';
newBuffer[j++] = '4';
} else {
newBuffer[j++] = buffer[i];
Modified: vmkit/trunk/lib/Mvm/StaticGCPrinter/VmkitGCPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/StaticGCPrinter/VmkitGCPrinter.cpp?rev=140727&r1=140726&r2=140727&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/StaticGCPrinter/VmkitGCPrinter.cpp (original)
+++ vmkit/trunk/lib/Mvm/StaticGCPrinter/VmkitGCPrinter.cpp Wed Sep 28 16:25:02 2011
@@ -117,6 +117,58 @@
AP.OutStreamer.EmitLabel(Sym);
}
+static bool methodNameMatches(StringRef compiledName,
+ Constant* name,
+ Constant* type) {
+ uint32_t size = compiledName.size();
+ std::string str;
+
+ for (uint32_t i = 0; i < name->getNumOperands(); ++i) {
+ int16_t cur = cast<ConstantInt>(name->getOperand(i))->getZExtValue();
+ if (cur == '/') {
+ str += '_';
+ } else if (cur == '_') {
+ str += "_1";
+ } else if (cur == '<') {
+ str += "_0003C";
+ } else if (cur == '>') {
+ str += "_0003E";
+ } else {
+ str += (char)cur;
+ }
+ }
+
+ for (uint32_t i = 0; i < type->getNumOperands(); ++i) {
+ int16_t cur = cast<ConstantInt>(type->getOperand(i))->getZExtValue();
+ if (cur == '(') {
+ str += "__";
+ } else if (cur == '/') {
+ str += '_';
+ } else if (cur == '_') {
+ str += "_1";
+ } else if (cur == '$') {
+ str += "_00024";
+ } else if (cur == ';') {
+ str += "_2";
+ } else if (cur == '[') {
+ str += "_3";
+ } else if (cur == ')') {
+ break;
+ } else {
+ str += (char)cur;
+ }
+ }
+
+ if (str.length() > size) return false;
+ if (str.compare(compiledName) == 0) return true;
+
+ str += 'S';
+
+ if (str.compare(compiledName) == 0) return true;
+
+ return false;
+}
+
Constant* FindMetadata(const Function& F) {
LLVMContext& context = F.getParent()->getContext();
for (Value::const_use_iterator I = F.use_begin(), E = F.use_end(); I != E; ++I) {
@@ -145,6 +197,39 @@
}
}
}
+
+ StringRef name = F.getName();
+ if (name.startswith("JnJVM")) {
+ // Metadata for customized methods.
+ StringRef methods = name.substr(0, name.find("__"));
+ StringRef methodName = name.substr(methods.rfind('_') + 1);
+ methodName = methodName.substr(0, methodName.rfind("__"));
+ methods = methods.substr(6, methods.rfind('_') - 5);
+ methods = std::string(methods) + "VirtualMethods";
+ Constant* VirtualMethods = cast<Constant>(F.getParent()->getNamedValue(methods));
+ assert(VirtualMethods);
+ Constant* MethodsArray = cast<Constant>(VirtualMethods->getOperand(0));
+ for (uint32_t index = 0; index < MethodsArray->getNumOperands(); index++) {
+ Constant* method = cast<Constant>(MethodsArray->getOperand(index));
+
+ Constant* name = cast<ConstantExpr>(method->getOperand(5));
+ name = cast<Constant>(name->getOperand(0));
+ name = cast<Constant>(name->getOperand(0));
+ name = cast<Constant>(name->getOperand(1));
+
+ Constant* type = cast<ConstantExpr>(method->getOperand(6));
+ type = cast<Constant>(type->getOperand(0));
+ type = cast<Constant>(type->getOperand(0));
+ type = cast<Constant>(type->getOperand(1));
+
+ if (methodNameMatches(methodName, name, type)) {
+ Constant* GEPs[2] = { ConstantInt::get(Type::getInt32Ty(context), 0),
+ ConstantInt::get(Type::getInt32Ty(context), index) };
+ return ConstantExpr::getGetElementPtr(VirtualMethods, GEPs, 2);
+ }
+ }
+ assert(0 && "Should have found a JavaMethod");
+ }
return NULL;
}
More information about the vmkit-commits
mailing list