[vmkit-commits] [vmkit] r141493 - in /vmkit/trunk: lib/J3/Compiler/JavaJIT.cpp lib/J3/VMCore/JavaTypes.h tests/ThisReferenceTest.java
Nicolas Geoffray
nicolas.geoffray at lip6.fr
Sat Oct 8 06:11:30 PDT 2011
Author: geoffray
Date: Sat Oct 8 08:11:29 2011
New Revision: 141493
URL: http://llvm.org/viewvc/llvm-project?rev=141493&view=rev
Log:
Fix off by one calculation of the 'this' reference. Also fix forgotten null check.
Added:
vmkit/trunk/tests/ThisReferenceTest.java
Modified:
vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp
vmkit/trunk/lib/J3/VMCore/JavaTypes.h
Modified: vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp?rev=141493&r1=141492&r2=141493&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp Sat Oct 8 08:11:29 2011
@@ -119,7 +119,8 @@
Signdef* signature = ctpInfo->infoOfInterfaceOrVirtualMethod(index, name);
bool customized = false;
- bool thisReference = isThisReference(stackSize() - signature->nbArguments - 1);
+ bool thisReference =
+ isThisReference(stackSize() - signature->getNumberOfSlots() - 1);
if (thisReference) {
assert(meth != NULL);
isCustomizable = true;
@@ -190,13 +191,14 @@
PHINode* node = 0;
Value* indexes2[2];
indexes2[0] = intrinsics->constantZero;
+ bool nullChecked = false;
if (meth) {
LLVMMethodInfo* LMI = TheCompiler->getMethodInfo(meth);
Constant* Offset = LMI->getOffset();
indexes2[1] = Offset;
} else {
-
+ nullChecked = true;
GlobalVariable* GV = new GlobalVariable(*llvmFunction->getParent(),
Type::getInt32Ty(*llvmContext),
false,
@@ -219,8 +221,9 @@
Args.push_back(ConstantInt::get(Type::getInt32Ty(*llvmContext), index));
Args.push_back(GV);
Value* targetObject = getTarget(signature);
- Args.push_back(new LoadInst(
- targetObject, "", false, currentBlock));
+ targetObject = new LoadInst(targetObject, "", false, currentBlock);
+ if (!thisReference) JITVerifyNull(targetObject);
+ Args.push_back(targetObject);
load = invoke(intrinsics->VirtualLookupFunction, Args, "", currentBlock);
node->addIncoming(load, currentBlock);
BranchInst::Create(endResolveVirtual, currentBlock);
@@ -230,7 +233,7 @@
}
makeArgs(it, index, args, signature->nbArguments + 1);
- if (!thisReference) JITVerifyNull(args[0]);
+ if (!nullChecked && !thisReference) JITVerifyNull(args[0]);
Value* VT = CallInst::Create(intrinsics->GetVTFunction, args[0], "",
currentBlock);
@@ -1551,7 +1554,8 @@
LLVMSignatureInfo* LSI = TheCompiler->getSignatureInfo(signature);
FunctionType* virtualType = LSI->getVirtualType();
meth = ctpInfo->infoOfStaticOrSpecialMethod(index, ACC_VIRTUAL, signature);
- bool thisReference = isThisReference(stackSize() - signature->nbArguments - 1);
+ bool thisReference =
+ isThisReference(stackSize() - signature->getNumberOfSlots() - 1);
Value* func = 0;
bool needsInit = false;
@@ -2097,7 +2101,8 @@
JavaConstantPool* ctpInfo = compilingClass->ctpInfo;
const UTF8* name = 0;
Signdef* signature = ctpInfo->infoOfInterfaceOrVirtualMethod(index, name);
- bool thisReference = isThisReference(stackSize() - signature->nbArguments - 1);
+ bool thisReference =
+ isThisReference(stackSize() - signature->getNumberOfSlots() - 1);
LLVMSignatureInfo* LSI = TheCompiler->getSignatureInfo(signature);
FunctionType* virtualType = LSI->getVirtualType();
Modified: vmkit/trunk/lib/J3/VMCore/JavaTypes.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaTypes.h?rev=141493&r1=141492&r2=141493&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JavaTypes.h (original)
+++ vmkit/trunk/lib/J3/VMCore/JavaTypes.h Sat Oct 8 08:11:29 2011
@@ -435,6 +435,16 @@
return &(arguments[1]);
}
+ uint32 getNumberOfSlots() {
+ uint32 result = nbArguments;
+ for (uint32 i = 1; i < nbArguments + 1; i++) {
+ if (arguments[i]->isDouble() || arguments[i]->isLong()) {
+ result++;
+ }
+ }
+ return result;
+ }
+
private:
/// arguments - The list of arguments of the signature. First is the return
Added: vmkit/trunk/tests/ThisReferenceTest.java
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tests/ThisReferenceTest.java?rev=141493&view=auto
==============================================================================
--- vmkit/trunk/tests/ThisReferenceTest.java (added)
+++ vmkit/trunk/tests/ThisReferenceTest.java Sat Oct 8 08:11:29 2011
@@ -0,0 +1,18 @@
+public class ThisReferenceTest {
+ public static void main(String[] args) {
+ try {
+ new ThisReferenceTest().foo();
+ } catch (NullPointerException e) {
+ }
+ }
+
+ public void foo() {
+ Nested other = null;
+ other.bar(this, 2L);
+ }
+
+ public static class Nested {
+ public void bar(ThisReferenceTest other, long l) {
+ }
+ }
+}
More information about the vmkit-commits
mailing list