[vmkit-commits] [vmkit] r180495 - New llvm intrinsics to interpret some opcodes.
Peter Senna Tschudin
peter.senna at gmail.com
Thu Apr 25 10:18:23 PDT 2013
Author: peter.senna
Date: Thu Apr 25 12:16:34 2013
New Revision: 180495
URL: http://llvm.org/viewvc/llvm-project?rev=180495&view=rev
Log:
New llvm intrinsics to interpret some opcodes.
isSecondaryType is now handled by a function inside the binary. This mean that the Jitter only emit a call to the function instead of the function body.
It is the same in opcode AASTORE: Now, we check if the object is assignable to the aray in a function.
(cherry picked from commit bac3efd9cb3a4c582796da9fdb1187ac41a170ce)
Modified:
vmkit/trunk/include/j3/J3Intrinsics.h
vmkit/trunk/lib/j3/Compiler/J3Intrinsics.cpp
vmkit/trunk/lib/j3/Compiler/JavaJIT.cpp
vmkit/trunk/lib/j3/Compiler/JavaJITCompiler.cpp
vmkit/trunk/lib/j3/Compiler/JavaJITOpcodes.cpp
vmkit/trunk/lib/j3/LLVMRuntime/runtime-default.ll
vmkit/trunk/lib/j3/VMCore/JavaClass.cpp
vmkit/trunk/lib/j3/VMCore/JavaClass.h
Modified: vmkit/trunk/include/j3/J3Intrinsics.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/J3Intrinsics.h?rev=180495&r1=180494&r2=180495&view=diff
==============================================================================
--- vmkit/trunk/include/j3/J3Intrinsics.h (original)
+++ vmkit/trunk/include/j3/J3Intrinsics.h Thu Apr 25 12:16:34 2013
@@ -73,7 +73,10 @@ public:
llvm::Function* VirtualLookupFunction;
llvm::Function* IsSubclassOfFunction;
+ llvm::Function* IsSubclassOfFunctionInner;
+ llvm::Function* CheckIfAssignable;
llvm::Function* IsSecondaryClassFunction;
+ llvm::Function* IsSecondaryClassFunctionInner;
llvm::Function* GetDepthFunction;
llvm::Function* GetDisplayFunction;
llvm::Function* GetVTInDisplayFunction;
Modified: vmkit/trunk/lib/j3/Compiler/J3Intrinsics.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/j3/Compiler/J3Intrinsics.cpp?rev=180495&r1=180494&r2=180495&view=diff
==============================================================================
--- vmkit/trunk/lib/j3/Compiler/J3Intrinsics.cpp (original)
+++ vmkit/trunk/lib/j3/Compiler/J3Intrinsics.cpp Thu Apr 25 12:16:34 2013
@@ -192,7 +192,10 @@ void J3Intrinsics::init(llvm::Module* mo
GetClassDelegateeFunction = module->getFunction("getClassDelegatee");
RuntimeDelegateeFunction = module->getFunction("j3RuntimeDelegatee");
IsSubclassOfFunction = module->getFunction("isSubclassOf");
+ IsSubclassOfFunctionInner = module->getFunction("isSubclassOf_Inner");
+ CheckIfAssignable = module->getFunction("checkIfObjectIsAssignableToArrayPosition");
IsSecondaryClassFunction = module->getFunction("isSecondaryClass");
+ IsSecondaryClassFunctionInner = module->getFunction("isSecondaryClass_Inner");
GetDepthFunction = module->getFunction("getDepth");
GetStaticInstanceFunction = module->getFunction("getStaticInstance");
GetDisplayFunction = module->getFunction("getDisplay");
Modified: vmkit/trunk/lib/j3/Compiler/JavaJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/j3/Compiler/JavaJIT.cpp?rev=180495&r1=180494&r2=180495&view=diff
==============================================================================
--- vmkit/trunk/lib/j3/Compiler/JavaJIT.cpp (original)
+++ vmkit/trunk/lib/j3/Compiler/JavaJIT.cpp Thu Apr 25 12:16:34 2013
@@ -2571,9 +2571,13 @@ unsigned JavaJIT::readExceptionTable(Rea
if (depth >= JavaVirtualTable::getDisplayLength()) {
Value* classArgs[2] = { objVT, VTVar };
-
- cmp = CallInst::Create(intrinsics->IsSecondaryClassFunction,
+
+ if (TheCompiler->isStaticCompiling())
+ cmp = CallInst::Create(intrinsics->IsSecondaryClassFunction,
classArgs, "isSecondaryClass", currentBlock);
+ else
+ cmp = CallInst::Create(intrinsics->IsSecondaryClassFunctionInner,
+ classArgs, "isSecondaryClass", currentBlock);
} else {
Modified: vmkit/trunk/lib/j3/Compiler/JavaJITCompiler.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/j3/Compiler/JavaJITCompiler.cpp?rev=180495&r1=180494&r2=180495&view=diff
==============================================================================
--- vmkit/trunk/lib/j3/Compiler/JavaJITCompiler.cpp (original)
+++ vmkit/trunk/lib/j3/Compiler/JavaJITCompiler.cpp Thu Apr 25 12:16:34 2013
@@ -186,6 +186,10 @@ JavaJITCompiler::JavaJITCompiler(const s
JavaIntrinsics.FieldWriteBarrierFunction, (void*)(word_t)fieldWriteBarrier);
executionEngine->updateGlobalMapping(
JavaIntrinsics.NonHeapWriteBarrierFunction, (void*)(word_t)nonHeapWriteBarrier);
+
+ executionEngine->updateGlobalMapping(JavaIntrinsics.IsSecondaryClassFunctionInner, (void*)(word_t) IsSubtypeIntrinsic);
+ executionEngine->updateGlobalMapping(JavaIntrinsics.IsSubclassOfFunctionInner, (void*)(word_t) IsSubtypeIntrinsic);
+ executionEngine->updateGlobalMapping(JavaIntrinsics.CheckIfAssignable, (void*)(word_t) CheckIfObjectIsAssignableToArrayPosition);
}
JavaJITCompiler::~JavaJITCompiler() {
Modified: vmkit/trunk/lib/j3/Compiler/JavaJITOpcodes.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/j3/Compiler/JavaJITOpcodes.cpp?rev=180495&r1=180494&r2=180495&view=diff
==============================================================================
--- vmkit/trunk/lib/j3/Compiler/JavaJITOpcodes.cpp (original)
+++ vmkit/trunk/lib/j3/Compiler/JavaJITOpcodes.cpp Thu Apr 25 12:16:34 2013
@@ -981,35 +981,49 @@ void JavaJIT::compileOpcodes(Reader& rea
false,
currentBlock);
JITVerifyNull(obj);
- Value* cmp = new ICmpInst(*currentBlock, ICmpInst::ICMP_EQ, val,
+
+
+
+ Value* res = 0;
+ if (TheCompiler->isStaticCompiling()) {
+ BasicBlock* endBlock = createBasicBlock("end array store check");
+ BasicBlock* checkBlock = createBasicBlock("array store check");
+ BasicBlock* exceptionBlock =
+ createBasicBlock("array store exception");
+ Value* cmp = new ICmpInst(*currentBlock, ICmpInst::ICMP_EQ, val,
intrinsics->JavaObjectNullConstant, "");
- BasicBlock* endBlock = createBasicBlock("end array store check");
- BasicBlock* checkBlock = createBasicBlock("array store check");
- BasicBlock* exceptionBlock =
- createBasicBlock("array store exception");
- BranchInst::Create(endBlock, checkBlock, cmp, currentBlock);
- currentBlock = checkBlock;
+
+ BranchInst::Create(endBlock, checkBlock, cmp, currentBlock);
+ currentBlock = checkBlock;
- Value* valVT = CallInst::Create(intrinsics->GetVTFunction, val, "",
+ Value* valVT = CallInst::Create(intrinsics->GetVTFunction, val, "",
currentBlock);
- Value* objVT = CallInst::Create(intrinsics->GetVTFunction, obj, "",
+ Value* objVT = CallInst::Create(intrinsics->GetVTFunction, obj, "",
currentBlock);
- objVT = CallInst::Create(intrinsics->GetBaseClassVTFromVTFunction, objVT,
+ objVT = CallInst::Create(intrinsics->GetBaseClassVTFromVTFunction, objVT,
"", currentBlock);
- Value* VTArgs[2] = { valVT, objVT };
+ Value* VTArgs[2] = { valVT, objVT };
- Value* res = CallInst::Create(intrinsics->IsSubclassOfFunction,
+ res = CallInst::Create(
+ (TheCompiler->isStaticCompiling())?
+ intrinsics->IsSubclassOfFunction:
+ intrinsics->IsSubclassOfFunctionInner,
VTArgs, "", currentBlock);
+ BranchInst::Create(endBlock, exceptionBlock, res, currentBlock);
- BranchInst::Create(endBlock, exceptionBlock, res, currentBlock);
-
- currentBlock = exceptionBlock;
- throwRuntimeException(intrinsics->ArrayStoreExceptionFunction, VTArgs, 2);
+ currentBlock = exceptionBlock;
+ throwRuntimeException(intrinsics->ArrayStoreExceptionFunction, VTArgs, 2);
+ currentBlock = endBlock;
+ }
+ else {
+ Value* objects[2] = {val, obj};
+ res = CallInst::Create(intrinsics->CheckIfAssignable, objects, "", currentBlock);
+ }
- currentBlock = endBlock;
+
}
Value* val = pop();
Value* index = pop();
@@ -1179,7 +1193,7 @@ void JavaJIT::compileOpcodes(Reader& rea
Value* val2 = popAsInt();
Value* val1 = popAsInt();
push(BinaryOperator::CreateAdd(val1, val2, "", currentBlock),
- false);
+ false);
break;
}
@@ -2543,8 +2557,12 @@ void JavaJIT::compileOpcodes(Reader& rea
Value* res = 0;
if (cl) {
if (cl->isSecondaryClass()) {
- res = CallInst::Create(intrinsics->IsSecondaryClassFunction,
+ if (TheCompiler->isStaticCompiling())
+ res = CallInst::Create(intrinsics->IsSecondaryClassFunction,
classArgs, "", currentBlock);
+ else
+ res = CallInst::Create(intrinsics->IsSecondaryClassFunctionInner,
+ classArgs, "", currentBlock);
} else {
Value* inDisplay = CallInst::Create(intrinsics->GetDisplayFunction,
objVT, "", currentBlock);
@@ -2560,8 +2578,12 @@ void JavaJIT::compileOpcodes(Reader& rea
TheVT, "");
}
} else {
- res = CallInst::Create(intrinsics->IsSubclassOfFunction,
+ if (TheCompiler->isStaticCompiling())
+ res = CallInst::Create(intrinsics->IsSubclassOfFunction,
classArgs, "", currentBlock);
+ else
+ res = CallInst::Create(intrinsics->IsSubclassOfFunctionInner,
+ classArgs, "", currentBlock);
}
node->addIncoming(res, currentBlock);
Modified: vmkit/trunk/lib/j3/LLVMRuntime/runtime-default.ll
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/j3/LLVMRuntime/runtime-default.ll?rev=180495&r1=180494&r2=180495&view=diff
==============================================================================
--- vmkit/trunk/lib/j3/LLVMRuntime/runtime-default.ll (original)
+++ vmkit/trunk/lib/j3/LLVMRuntime/runtime-default.ll Thu Apr 25 12:16:34 2013
@@ -211,10 +211,20 @@ declare void @j3JavaObjectRelease(%JavaO
;;; isSubclassOf - Returns if a type is a subtype of another type.
declare i1 @isSubclassOf(%VT*, %VT*) readnone
+;;; isSubclassOf - Returns if a type is a subtype of another type.
+declare i1 @isSubclassOf_Inner(%VT*, %VT*) readnone
+
+;;; isSubclassOf - Returns if a type is a subtype of another type.
+declare i1 @checkIfObjectIsAssignableToArrayPosition(%JavaObject*, %JavaObject*) readnone
+
;;; isSecondaryClass - Returns if a type is a secondary super type of
;;; another type.
declare i1 @isSecondaryClass(%VT*, %VT*) readnone
+;;; isSecondaryClass_Inner - Returns if a type is a secondary super type of
+;;; another type.
+declare i1 @isSecondaryClass_Inner(%VT*, %VT*) readnone
+
;;; getClassDelegatee - Returns the java/lang/Class representation of the
;;; class. This method is lowered to the GEP to the class delegatee in
;;; the common class.
Modified: vmkit/trunk/lib/j3/VMCore/JavaClass.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/j3/VMCore/JavaClass.cpp?rev=180495&r1=180494&r2=180495&view=diff
==============================================================================
--- vmkit/trunk/lib/j3/VMCore/JavaClass.cpp (original)
+++ vmkit/trunk/lib/j3/VMCore/JavaClass.cpp Thu Apr 25 12:16:34 2013
@@ -29,6 +29,7 @@
#include "Reader.h"
#include <cstring>
+#include <cstdlib>
#if 0
using namespace vmkit;
@@ -62,6 +63,35 @@ extern "C" void ArrayObjectTracer(JavaOb
extern "C" void RegularObjectTracer(JavaObject*);
extern "C" void ReferenceObjectTracer(JavaObject*);
+
+extern "C" bool CheckIfObjectIsAssignableToArrayPosition(JavaObject * obj, JavaObject* array) {
+ llvm_gcroot(obj, 0);
+ llvm_gcroot(array, 0);
+ if (obj == 0)
+ return true;
+ bool b = obj->getVirtualTable()->isSubtypeOf(array->getVirtualTable()->baseClassVT);
+ if (!b) {
+ BEGIN_NATIVE_EXCEPTION(0)
+ Jnjvm* vm = JavaThread::get()->getJVM();
+ vm->CreateArrayStoreException(obj->getVirtualTable());
+ END_NATIVE_EXCEPTION
+ }
+ return b;
+}
+
+extern "C" bool IsSubtypeIntrinsic(JavaVirtualTable* obj, JavaVirtualTable* clazz){
+ //printf("2 + 1 \n");
+ return obj->isSubtypeOf(clazz);
+}
+
+static int compJavaVirtualTable (const void * elem1, const void * elem2) {
+ void * f = *((void**)elem1);
+ void * s = *((void**)elem2);
+ if (f > s) return 1;
+ if (f < s) return -1;
+ return 0;
+}
+
JavaAttribute::JavaAttribute(const UTF8* name, uint32 length,
uint32 offset) {
@@ -525,7 +555,6 @@ bool JavaVirtualTable::isSubtypeOf(JavaV
if (secondaryTypes[i] == otherVT) {
cache = otherVT;
return true;
- }
}
}
return false;
@@ -1493,6 +1522,20 @@ JavaVirtualTable::JavaVirtualTable(Class
lastIndex += cur->nbSecondaryTypes;
}
+ if (nbSecondaryTypes) {
+ qsort(secondaryTypes, nbSecondaryTypes, sizeof(JavaVirtualTable*), compJavaVirtualTable);
+ lastIndex = 1;
+ JavaVirtualTable* temp = secondaryTypes[0];
+ for (uint32 i = 1 ; i < nbSecondaryTypes ; i++ )
+ if (secondaryTypes[i] != temp) {
+ secondaryTypes[lastIndex++] = secondaryTypes[i];
+ temp = secondaryTypes[i];
+ }
+ nbSecondaryTypes = lastIndex;
+ //isSortedSecondaryTypes = true;
+ }
+
+
} else {
// Set the tracer, destructor and delete.
tracer = (word_t)JavaObjectTracer;
@@ -1726,6 +1769,18 @@ JavaVirtualTable::JavaVirtualTable(Class
// java.lang.Object[]. The initialiseVT function will update the current
// array to point to java.lang.Object[]'s secondary list.
}
+ if (offset == getCacheIndex() && nbSecondaryTypes) {
+ qsort(secondaryTypes, nbSecondaryTypes, sizeof(JavaVirtualTable*), compJavaVirtualTable);
+ uint32 lastIndex = 1;
+ JavaVirtualTable* temp = secondaryTypes[0];
+ for (uint32 i = 1 ; i < nbSecondaryTypes ; ++i )
+ if (secondaryTypes[i] != temp) {
+ secondaryTypes[lastIndex++] = secondaryTypes[i];
+ temp = secondaryTypes[i];
+ }
+ nbSecondaryTypes = lastIndex;
+ //isSortedSecondaryTypes = true;
+ }
}
Modified: vmkit/trunk/lib/j3/VMCore/JavaClass.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/j3/VMCore/JavaClass.h?rev=180495&r1=180494&r2=180495&view=diff
==============================================================================
--- vmkit/trunk/lib/j3/VMCore/JavaClass.h (original)
+++ vmkit/trunk/lib/j3/VMCore/JavaClass.h Thu Apr 25 12:16:34 2013
@@ -62,6 +62,9 @@ typedef TJavaArray<JavaObject*> ArrayObj
#define erroneous 6 /// The class is in an erroneous state.
+extern "C" bool IsSubtypeIntrinsic(JavaVirtualTable* obj, JavaVirtualTable* clazz);
+extern "C" bool CheckIfObjectIsAssignableToArrayPosition(JavaObject * obj, JavaObject* array);
+
class AnnotationReader {
public:
Reader& reader;
More information about the vmkit-commits
mailing list