[vmkit-commits] [vmkit] r111784 - in /vmkit/trunk: include/j3/J3Intrinsics.h lib/J3/Compiler/J3Intrinsics.cpp lib/J3/Compiler/JavaJIT.cpp lib/J3/LLVMRuntime/runtime-default.ll lib/J3/VMCore/JavaRuntimeJIT.cpp
Nicolas Geoffray
nicolas.geoffray at lip6.fr
Sun Aug 22 13:25:23 PDT 2010
Author: geoffray
Date: Sun Aug 22 15:25:23 2010
New Revision: 111784
URL: http://llvm.org/viewvc/llvm-project?rev=111784&view=rev
Log:
Only do a cas in the JIT-compiled code. Bail out to runtime if it fails.
Also remove the runtime intrinsic overflowThinLock.
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/LLVMRuntime/runtime-default.ll
vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp
Modified: vmkit/trunk/include/j3/J3Intrinsics.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/J3Intrinsics.h?rev=111784&r1=111783&r2=111784&view=diff
==============================================================================
--- vmkit/trunk/include/j3/J3Intrinsics.h (original)
+++ vmkit/trunk/include/j3/J3Intrinsics.h Sun Aug 22 15:25:23 2010
@@ -108,7 +108,6 @@
llvm::Function* GetBaseClassVTFromVTFunction;
llvm::Function* GetLockFunction;
- llvm::Function* OverflowThinLockFunction;
llvm::Function* GetFinalInt8FieldFunction;
llvm::Function* GetFinalInt16FieldFunction;
Modified: vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp?rev=111784&r1=111783&r2=111784&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp Sun Aug 22 15:25:23 2010
@@ -185,7 +185,6 @@
GetVTInDisplayFunction = module->getFunction("getVTInDisplay");
AquireObjectFunction = module->getFunction("j3JavaObjectAquire");
ReleaseObjectFunction = module->getFunction("j3JavaObjectRelease");
- OverflowThinLockFunction = module->getFunction("j3OverflowThinLock");
VirtualFieldLookupFunction = module->getFunction("j3VirtualFieldLookup");
StaticFieldLookupFunction = module->getFunction("j3StaticFieldLookup");
Modified: vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp?rev=111784&r1=111783&r2=111784&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp Sun Aug 22 15:25:23 2010
@@ -577,62 +577,14 @@
BasicBlock* OK = createBasicBlock("synchronize passed");
BasicBlock* NotOK = createBasicBlock("synchronize did not pass");
- BasicBlock* FatLockBB = createBasicBlock("fat lock");
- BasicBlock* ThinLockBB = createBasicBlock("thin lock");
BranchInst::Create(OK, NotOK, cmp, currentBlock);
+ // The atomic cas did not work.
currentBlock = NotOK;
-
- // The compare and swap did not pass, look if it's a thin lock
- Value* isThin = BinaryOperator::CreateAnd(atomic, intrinsics->constantFatMask, "",
- currentBlock);
- cmp = new ICmpInst(*currentBlock, ICmpInst::ICMP_EQ, isThin,
- intrinsics->constantPtrZero, "");
-
- BranchInst::Create(ThinLockBB, FatLockBB, cmp, currentBlock);
-
- // It's a thin lock. Look if we're the owner of this lock.
- currentBlock = ThinLockBB;
- Value* idMask = ConstantInt::get(intrinsics->pointerSizeType, mvm::Thread::IDMask);
- Value* cptMask = ConstantInt::get(intrinsics->pointerSizeType, mvm::ThinCountMask);
- Value* IdInLock = BinaryOperator::CreateAnd(atomic, idMask, "", currentBlock);
- Value* owner = new ICmpInst(*currentBlock, ICmpInst::ICMP_EQ, threadId,
- IdInLock, "");
-
- BasicBlock* OwnerBB = createBasicBlock("owner thread");
-
- BranchInst::Create(OwnerBB, FatLockBB, owner, currentBlock);
- currentBlock = OwnerBB;
-
- // OK, we are the owner, now check if the counter will overflow.
- Value* count = BinaryOperator::CreateAnd(atomic, cptMask, "", currentBlock);
- cmp = new ICmpInst(*currentBlock, ICmpInst::ICMP_ULT, count, cptMask, "");
-
- BasicBlock* IncCounterBB = createBasicBlock("Increment counter");
- BasicBlock* OverflowCounterBB = createBasicBlock("Overflow counter");
-
- BranchInst::Create(IncCounterBB, OverflowCounterBB, cmp, currentBlock);
- currentBlock = IncCounterBB;
-
- // The counter will not overflow, increment it.
- Value* One = ConstantInt::get(intrinsics->pointerSizeType, mvm::ThinCountAdd);
- Value* Add = BinaryOperator::CreateAdd(One, atomic, "", currentBlock);
- new StoreInst(Add, lockPtr, false, currentBlock);
- BranchInst::Create(OK, currentBlock);
-
- currentBlock = OverflowCounterBB;
-
- // The counter will overflow, call this function to create a new lock,
- // lock it 0x101 times, and pass.
- CallInst::Create(intrinsics->OverflowThinLockFunction, obj, "",
- currentBlock);
- BranchInst::Create(OK, currentBlock);
-
- currentBlock = FatLockBB;
- // Either it's a fat lock or there is contention.
CallInst::Create(intrinsics->AquireObjectFunction, obj, "", currentBlock);
BranchInst::Create(OK, currentBlock);
+
currentBlock = OK;
}
@@ -647,7 +599,7 @@
"", currentBlock);
Value* lock = new LoadInst(lockPtr, "", currentBlock);
Value* NonLockBitsMask = ConstantInt::get(
- intrinsics->pointerSizeType, ~mvm::NonLockBitsMask);
+ intrinsics->pointerSizeType, mvm::NonLockBitsMask);
Value* lockedMask = BinaryOperator::CreateAnd(
lock, NonLockBitsMask, "", currentBlock);
@@ -656,54 +608,34 @@
threadId = new PtrToIntInst(threadId, intrinsics->pointerSizeType, "",
currentBlock);
- Value* cmp = new ICmpInst(*currentBlock, ICmpInst::ICMP_EQ, lockedMask,
- threadId, "");
-
-
- BasicBlock* EndUnlock = createBasicBlock("end unlock");
- BasicBlock* LockedOnceBB = createBasicBlock("desynchronize thin lock");
- BasicBlock* NotLockedOnceBB =
- createBasicBlock("simple desynchronize did not pass");
- BasicBlock* FatLockBB = createBasicBlock("fat lock");
- BasicBlock* ThinLockBB = createBasicBlock("thin lock");
-
- BranchInst::Create(LockedOnceBB, NotLockedOnceBB, cmp, currentBlock);
-
- // Locked once, set zero
- currentBlock = LockedOnceBB;
- NonLockBitsMask = ConstantInt::get(
- intrinsics->pointerSizeType, mvm::NonLockBitsMask);
- lockedMask = BinaryOperator::CreateAnd(
- lock, NonLockBitsMask, "", currentBlock);
- new StoreInst(lockedMask, lockPtr, false, currentBlock);
- BranchInst::Create(EndUnlock, currentBlock);
+ Value* oldValMask = BinaryOperator::CreateOr(threadId, lockedMask, "",
+ currentBlock);
- currentBlock = NotLockedOnceBB;
- // Look if the lock is thin.
- Value* isThin = BinaryOperator::CreateAnd(lock, intrinsics->constantFatMask, "",
- currentBlock);
- cmp = new ICmpInst(*currentBlock, ICmpInst::ICMP_EQ, isThin,
- intrinsics->constantPtrZero, "");
+ std::vector<Value*> atomicArgs;
+ atomicArgs.push_back(lockPtr);
+ atomicArgs.push_back(oldValMask);
+ atomicArgs.push_back(lockedMask);
+
+ // Do the atomic compare and swap.
+ Value* atomic = CallInst::Create(intrinsics->llvm_atomic_lcs_ptr,
+ atomicArgs.begin(), atomicArgs.end(), "",
+ currentBlock);
- BranchInst::Create(ThinLockBB, FatLockBB, cmp, currentBlock);
+ Value* cmp = new ICmpInst(*currentBlock, ICmpInst::ICMP_EQ, atomic,
+ oldValMask, "");
- currentBlock = ThinLockBB;
+ BasicBlock* OK = createBasicBlock("unsynchronize passed");
+ BasicBlock* NotOK = createBasicBlock("unsynchronize did not pass");
- // Decrement the counter.
- Value* One = ConstantInt::get(intrinsics->pointerSizeType, mvm::ThinCountAdd);
- Value* Sub = BinaryOperator::CreateSub(lock, One, "", currentBlock);
- new StoreInst(Sub, lockPtr, false, currentBlock);
- BranchInst::Create(EndUnlock, currentBlock);
-
- currentBlock = FatLockBB;
+ BranchInst::Create(OK, NotOK, cmp, currentBlock);
- // Either it's a fat lock or there is contention.
+ // The atomic cas did not work.
+ currentBlock = NotOK;
CallInst::Create(intrinsics->ReleaseObjectFunction, obj, "", currentBlock);
- BranchInst::Create(EndUnlock, currentBlock);
- currentBlock = EndUnlock;
-}
-
+ BranchInst::Create(OK, currentBlock);
+ currentBlock = OK;
+}
#ifdef ISOLATE_SHARING
Value* JavaJIT::getStaticInstanceCtp() {
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=111784&r1=111783&r2=111784&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/LLVMRuntime/runtime-default.ll (original)
+++ vmkit/trunk/lib/J3/LLVMRuntime/runtime-default.ll Sun Aug 22 15:25:23 2010
@@ -161,10 +161,6 @@
;;; block or method.
declare void @j3JavaObjectRelease(%JavaObject*)
-;;; j3OverflowThinLock - Change a thin lock to a fat lock when the thin lock
-;;; overflows
-declare void @j3OverflowThinLock(%JavaObject*)
-
;;; isAssignableFrom - Returns if a type is a subtype of another type.
declare i1 @isAssignableFrom(%VT*, %VT*) readnone
Modified: vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp?rev=111784&r1=111783&r2=111784&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp (original)
+++ vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp Sun Aug 22 15:25:23 2010
@@ -385,12 +385,6 @@
return JavaThread::get()->throwException(obj);
}
-// Never throws.
-extern "C" void j3OverflowThinLock(JavaObject* obj) {
- llvm_gcroot(obj, 0);
- JavaObject::overflowThinLock(obj);
-}
-
// Creates a Java object and then throws it.
extern "C" JavaObject* j3NullPointerException() {
JavaObject *exc = 0;
More information about the vmkit-commits
mailing list