[vmkit-commits] [vmkit] r121420 - in /vmkit/trunk: include/mvm/ include/mvm/Threads/ lib/J3/Compiler/ lib/J3/VMCore/ lib/Mvm/CommonThread/ lib/Mvm/Compiler/ lib/Mvm/GCMmap2/ lib/Mvm/MMTk/ mmtk/java/src/org/j3/bindings/ mmtk/java/src/org/j3/mmtk/ mmtk/java/src/org/mmtk/plan/generational/ mmtk/mmtk-alloc/ mmtk/mmtk-j3/
Nicolas Geoffray
nicolas.geoffray at lip6.fr
Thu Dec 9 14:08:31 PST 2010
Author: geoffray
Date: Thu Dec 9 16:08:31 2010
New Revision: 121420
URL: http://llvm.org/viewvc/llvm-project?rev=121420&view=rev
Log:
Support generationnal collectors!
Modified:
vmkit/trunk/include/mvm/JIT.h
vmkit/trunk/include/mvm/Threads/CollectionRV.h
vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp
vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp
vmkit/trunk/lib/J3/VMCore/JNIReferences.h
vmkit/trunk/lib/J3/VMCore/JavaArray.h
vmkit/trunk/lib/J3/VMCore/JavaClass.cpp
vmkit/trunk/lib/J3/VMCore/JavaThread.cpp
vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h
vmkit/trunk/lib/J3/VMCore/LockedMap.cpp
vmkit/trunk/lib/Mvm/CommonThread/CollectionRV.cpp
vmkit/trunk/lib/Mvm/Compiler/InlineMalloc.cpp
vmkit/trunk/lib/Mvm/Compiler/JIT.cpp
vmkit/trunk/lib/Mvm/Compiler/LLVMRuntime.ll
vmkit/trunk/lib/Mvm/GCMmap2/MvmGC.h
vmkit/trunk/lib/Mvm/GCMmap2/gc.cpp
vmkit/trunk/lib/Mvm/MMTk/MvmGC.cpp
vmkit/trunk/lib/Mvm/MMTk/MvmGC.h
vmkit/trunk/mmtk/java/src/org/j3/bindings/Bindings.java
vmkit/trunk/mmtk/java/src/org/j3/mmtk/Barriers.java
vmkit/trunk/mmtk/java/src/org/mmtk/plan/generational/Gen.java
vmkit/trunk/mmtk/mmtk-alloc/Selected.cpp
vmkit/trunk/mmtk/mmtk-j3/Collection.cpp
Modified: vmkit/trunk/include/mvm/JIT.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/JIT.h?rev=121420&r1=121419&r2=121420&view=diff
==============================================================================
--- vmkit/trunk/include/mvm/JIT.h (original)
+++ vmkit/trunk/include/mvm/JIT.h Thu Dec 9 16:08:31 2010
@@ -122,6 +122,9 @@
llvm::Function* AllocateFunction;
llvm::Function* AllocateUnresolvedFunction;
llvm::Function* AddFinalizationCandidate;
+ llvm::Function* ArrayWriteBarrierFunction;
+ llvm::Function* FieldWriteBarrierFunction;
+ llvm::Function* NonHeapWriteBarrierFunction;
llvm::Constant* constantInt8Zero;
llvm::Constant* constantZero;
Modified: vmkit/trunk/include/mvm/Threads/CollectionRV.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Threads/CollectionRV.h?rev=121420&r1=121419&r2=121420&view=diff
==============================================================================
--- vmkit/trunk/include/mvm/Threads/CollectionRV.h (original)
+++ vmkit/trunk/include/mvm/Threads/CollectionRV.h Thu Dec 9 16:08:31 2010
@@ -29,10 +29,14 @@
/// nbJoined - Number of threads that joined the rendezvous.
unsigned nbJoined;
+
+ // initiator - The initiator of the rendesvous.
+ Thread* initiator;
public:
CollectionRV() {
nbJoined = 0;
+ initiator = NULL;
}
void lockRV() { _lockRV.lock(); }
@@ -52,6 +56,7 @@
}
void another_mark();
+ Thread* getInitiator() const { return initiator; }
virtual void finishRV() = 0;
virtual void synchronize() = 0;
@@ -64,7 +69,7 @@
};
class CooperativeCollectionRV : public CollectionRV {
-public:
+public:
void finishRV();
void synchronize();
@@ -72,6 +77,7 @@
void joinAfterUncooperative(void* SP);
void joinBeforeUncooperative();
void addThread(Thread* th);
+
};
class UncooperativeCollectionRV : public CollectionRV {
Modified: vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp?rev=121420&r1=121419&r2=121420&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp Thu Dec 9 16:08:31 2010
@@ -2066,8 +2066,15 @@
if (type != val->getType()) { // int1, int8, int16
convertValue(val, type, currentBlock, false);
}
-
- new StoreInst(val, ptr, false, currentBlock);
+
+ if (mvm::Collector::supportsWriteBarrier() && type == intrinsics->JavaObjectType) {
+ ptr = new BitCastInst(ptr, intrinsics->ptrPtrType, "", currentBlock);
+ val = new BitCastInst(val, intrinsics->ptrType, "", currentBlock);
+ Value* args[2] = { ptr, val };
+ CallInst::Create(intrinsics->NonHeapWriteBarrierFunction, args, args + 2, "", currentBlock);
+ } else {
+ new StoreInst(val, ptr, false, currentBlock);
+ }
}
void JavaJIT::getStaticField(uint16 index) {
@@ -2166,8 +2173,17 @@
if (type != val->getType()) { // int1, int8, int16
convertValue(val, type, currentBlock, false);
}
-
- new StoreInst(val, ptr, false, currentBlock);
+
+ if (mvm::Collector::supportsWriteBarrier() && type == intrinsics->JavaObjectType) {
+ ptr = new BitCastInst(ptr, intrinsics->ptrPtrType, "", currentBlock);
+ val = new BitCastInst(val, intrinsics->ptrType, "", currentBlock);
+ object = new LoadInst(object, "", currentBlock);
+ object = new BitCastInst(object, intrinsics->ptrType, "", currentBlock);
+ Value* args[3] = { object, ptr, val };
+ CallInst::Create(intrinsics->FieldWriteBarrierFunction, args, args + 3, "", currentBlock);
+ } else {
+ new StoreInst(val, ptr, false, currentBlock);
+ }
}
void JavaJIT::getVirtualField(uint16 index) {
Modified: vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp?rev=121420&r1=121419&r2=121420&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp Thu Dec 9 16:08:31 2010
@@ -721,8 +721,15 @@
Value* obj = pop();
Value* ptr = verifyAndComputePtr(obj, index,
intrinsics->JavaArrayObjectType);
-
- new StoreInst(val, ptr, false, currentBlock);
+ if (mvm::Collector::supportsWriteBarrier()) {
+ ptr = new BitCastInst(ptr, intrinsics->ptrPtrType, "", currentBlock);
+ val = new BitCastInst(val, intrinsics->ptrType, "", currentBlock);
+ obj = new BitCastInst(obj, intrinsics->ptrType, "", currentBlock);
+ Value* args[3] = { obj, ptr, val };
+ CallInst::Create(intrinsics->ArrayWriteBarrierFunction, args, args + 3, "", currentBlock);
+ } else {
+ new StoreInst(val, ptr, false, currentBlock);
+ }
break;
}
Modified: vmkit/trunk/lib/J3/VMCore/JNIReferences.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JNIReferences.h?rev=121420&r1=121419&r2=121420&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JNIReferences.h (original)
+++ vmkit/trunk/lib/J3/VMCore/JNIReferences.h Thu Dec 9 16:08:31 2010
@@ -69,8 +69,7 @@
return next->addJNIReference(obj);
} else {
++count;
- mvm::Collector::objectReferenceNonHeapWriteBarrier(
- (gc**)&(globalReferences[length]), (gc*)obj);
+ globalReferences[length] = obj;
return &globalReferences[length++];
}
}
Modified: vmkit/trunk/lib/J3/VMCore/JavaArray.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaArray.h?rev=121420&r1=121419&r2=121420&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JavaArray.h (original)
+++ vmkit/trunk/lib/J3/VMCore/JavaArray.h Thu Dec 9 16:08:31 2010
@@ -99,7 +99,7 @@
llvm_gcroot(self, 0);
llvm_gcroot(value, 0);
if (value != NULL) assert(value->getVirtualTable());
- mvm::Collector::objectReferenceWriteBarrier(
+ mvm::Collector::objectReferenceArrayWriteBarrier(
(gc*)self, (gc**)&(self->elements[i]), (gc*)value);
}
Modified: vmkit/trunk/lib/J3/VMCore/JavaClass.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaClass.cpp?rev=121420&r1=121419&r2=121420&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JavaClass.cpp (original)
+++ vmkit/trunk/lib/J3/VMCore/JavaClass.cpp Thu Dec 9 16:08:31 2010
@@ -580,7 +580,9 @@
void JavaField::InitStaticField(JavaObject* val) {
llvm_gcroot(val, 0);
void* obj = classDef->getStaticInstance();
- ((JavaObject**)((uint64)obj + ptrOffset))[0] = val;
+ assert(isReference());
+ JavaObject** ptr = (JavaObject**)((uint64)obj + ptrOffset);
+ mvm::Collector::objectReferenceNonHeapWriteBarrier((gc**)ptr, (gc*)val);
}
void JavaField::InitStaticField(double val) {
@@ -1059,38 +1061,27 @@
}
JavaObject* CommonClass::setDelegatee(JavaObject* val) {
- JavaObject* prev = NULL;
llvm_gcroot(val, 0);
- llvm_gcroot(prev, 0);
JavaObject** obj = &(delegatee[JavaThread::get()->getJVM()->IsolateID]);
-
- prev = (JavaObject*)__sync_val_compare_and_swap((uintptr_t)obj, NULL, val);
-
- if (prev == NULL) {
- // Write it again to execute the write barrier.
+ classLoader->lock.lock();
+ if (*obj == NULL) {
mvm::Collector::objectReferenceNonHeapWriteBarrier((gc**)obj, (gc*)val);
- return val;
- } else {
- return prev;
}
+ classLoader->lock.unlock();
+ return getDelegatee();
}
#else
JavaObject* CommonClass::setDelegatee(JavaObject* val) {
- JavaObject* prev = NULL;
llvm_gcroot(val, 0);
- llvm_gcroot(prev, 0);
- prev = (JavaObject*)__sync_val_compare_and_swap(&(delegatee[0]), NULL, val);
-
- if (prev == NULL) {
- // Write it again to execute the write barrier.
- mvm::Collector::objectReferenceNonHeapWriteBarrier(
- (gc**)&(delegatee[0]), (gc*)val);
- return val;
- } else {
- return prev;
+ JavaObject** obj = &(delegatee[0]);
+ classLoader->lock.lock();
+ if (*obj == NULL) {
+ mvm::Collector::objectReferenceNonHeapWriteBarrier((gc**)obj, (gc*)val);
}
+ classLoader->lock.unlock();
+ return getDelegatee();
}
#endif
Modified: vmkit/trunk/lib/J3/VMCore/JavaThread.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaThread.cpp?rev=121420&r1=121419&r2=121420&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JavaThread.cpp (original)
+++ vmkit/trunk/lib/J3/VMCore/JavaThread.cpp Thu Dec 9 16:08:31 2010
@@ -40,10 +40,8 @@
void JavaThread::initialise(JavaObject* thread, JavaObject* vmth) {
llvm_gcroot(thread, 0);
llvm_gcroot(vmth, 0);
- mvm::Collector::objectReferenceNonHeapWriteBarrier(
- (gc**)&javaThread, (gc*)thread);
- mvm::Collector::objectReferenceNonHeapWriteBarrier(
- (gc**)&vmThread, (gc*)vmth);
+ javaThread = thread;
+ vmThread = vmth;
}
JavaThread::~JavaThread() {
@@ -155,8 +153,7 @@
next->prev = this;
return next->addJNIReference(th, obj);
} else {
- mvm::Collector::objectReferenceNonHeapWriteBarrier(
- (gc**)&(localReferences[length]), (gc*)obj);
+ localReferences[length] = obj;
return &localReferences[length++];
}
}
Modified: vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h?rev=121420&r1=121419&r2=121420&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h (original)
+++ vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h Thu Dec 9 16:08:31 2010
@@ -304,6 +304,8 @@
Class* loadClassFromSelf(Jnjvm* vm, const char* name);
friend class Class;
+ friend class CommonClass;
+ friend class StringList;
};
/// JnjvmBootstrapLoader - This class is for the bootstrap class loader, which
@@ -513,9 +515,12 @@
JCL->strings = next;
return next->addString(JCL, obj);
} else {
+ JCL->lock.lock();
mvm::Collector::objectReferenceNonHeapWriteBarrier(
(gc**)&(strings[length]), (gc*)obj);
- return &strings[length++];
+ JavaString** res = &strings[length++];
+ JCL->lock.unlock();
+ return res;
}
}
};
Modified: vmkit/trunk/lib/J3/VMCore/LockedMap.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/LockedMap.cpp?rev=121420&r1=121419&r2=121420&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/LockedMap.cpp (original)
+++ vmkit/trunk/lib/J3/VMCore/LockedMap.cpp Thu Dec 9 16:08:31 2010
@@ -25,9 +25,4 @@
assert(map.find(array)->first == array);
assert(&(map.find(array)->second) == &(it->second));
assert(&(map.find(array)->first) == &(it->first));
- // Inform the GC that we just stored a string here.
- mvm::Collector::objectReferenceNonHeapWriteBarrier(
- (gc**)&(it->second), (gc*)str);
- mvm::Collector::objectReferenceNonHeapWriteBarrier(
- (gc**)&(it->first), (gc*)array);
}
Modified: vmkit/trunk/lib/Mvm/CommonThread/CollectionRV.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/CommonThread/CollectionRV.cpp?rev=121420&r1=121419&r2=121420&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/CommonThread/CollectionRV.cpp (original)
+++ vmkit/trunk/lib/Mvm/CommonThread/CollectionRV.cpp Thu Dec 9 16:08:31 2010
@@ -54,8 +54,9 @@
self->MyVM->ThreadLock.lock();
mvm::Thread* cur = self;
+ assert(initiator == NULL);
+ initiator = self;
do {
- assert(!cur->doYield);
cur->doYield = true;
assert(!cur->joinedRV);
cur = (mvm::Thread*)cur->next();
@@ -192,8 +193,8 @@
void CooperativeCollectionRV::finishRV() {
lockRV();
-
- mvm::Thread* initiator = mvm::Thread::get();
+
+ assert(mvm::Thread::get() == initiator);
mvm::Thread* cur = initiator;
do {
assert(cur->doYield && "Inconsistent state");
@@ -207,8 +208,9 @@
nbJoined = 0;
initiator->MyVM->ThreadLock.unlock();
condEndRV.broadcast();
+ initiator = NULL;
unlockRV();
- initiator->inRV = false;
+ mvm::Thread::get()->inRV = false;
}
void UncooperativeCollectionRV::finishRV() {
Modified: vmkit/trunk/lib/Mvm/Compiler/InlineMalloc.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Compiler/InlineMalloc.cpp?rev=121420&r1=121419&r2=121420&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/Compiler/InlineMalloc.cpp (original)
+++ vmkit/trunk/lib/Mvm/Compiler/InlineMalloc.cpp Thu Dec 9 16:08:31 2010
@@ -42,7 +42,9 @@
bool InlineMalloc::runOnFunction(Function& F) {
Function* Malloc = F.getParent()->getFunction("gcmalloc");
- if (!Malloc || Malloc->isDeclaration()) return false;
+ Function* FieldWriteBarrier = F.getParent()->getFunction("fieldWriteBarrier");
+ Function* ArrayWriteBarrier = F.getParent()->getFunction("arrayWriteBarrier");
+ Function* NonHeapWriteBarrier = F.getParent()->getFunction("nonHeapWriteBarrier");
bool Changed = false;
for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE; BI++) {
BasicBlock *Cur = BI;
@@ -61,6 +63,12 @@
Changed |= InlineFunction(Call, IFI);
break;
}
+ } else if (Temp == FieldWriteBarrier ||
+ Temp == NonHeapWriteBarrier ||
+ Temp == ArrayWriteBarrier) {
+ InlineFunctionInfo IFI(NULL, mvm::MvmModule::TheTargetData);
+ Changed |= InlineFunction(Call, IFI);
+ break;
}
}
}
Modified: vmkit/trunk/lib/Mvm/Compiler/JIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Compiler/JIT.cpp?rev=121420&r1=121419&r2=121420&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/Compiler/JIT.cpp (original)
+++ vmkit/trunk/lib/Mvm/Compiler/JIT.cpp Thu Dec 9 16:08:31 2010
@@ -322,6 +322,10 @@
assert(AllocateUnresolvedFunction && "No allocateUnresolved function");
AddFinalizationCandidate = module->getFunction("addFinalizationCandidate");
assert(AddFinalizationCandidate && "No addFinalizationCandidate function");
+
+ ArrayWriteBarrierFunction = module->getFunction("arrayWriteBarrier");
+ FieldWriteBarrierFunction = module->getFunction("fieldWriteBarrier");
+ NonHeapWriteBarrierFunction = module->getFunction("nonHeapWriteBarrier");
}
const llvm::TargetData* MvmModule::TheTargetData;
Modified: vmkit/trunk/lib/Mvm/Compiler/LLVMRuntime.ll
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Compiler/LLVMRuntime.ll?rev=121420&r1=121419&r2=121420&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/Compiler/LLVMRuntime.ll (original)
+++ vmkit/trunk/lib/Mvm/Compiler/LLVMRuntime.ll Thu Dec 9 16:08:31 2010
@@ -85,3 +85,6 @@
declare i8* @gcmalloc(i32, i8*)
declare i8* @gcmallocUnresolved(i32, i8*)
declare void @addFinalizationCandidate(i8*)
+declare void @arrayWriteBarrier(i8*, i8**, i8*)
+declare void @fieldWriteBarrier(i8*, i8**, i8*)
+declare void @nonHeapWriteBarrier(i8**, i8*)
Modified: vmkit/trunk/lib/Mvm/GCMmap2/MvmGC.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/GCMmap2/MvmGC.h?rev=121420&r1=121419&r2=121420&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/GCMmap2/MvmGC.h (original)
+++ vmkit/trunk/lib/Mvm/GCMmap2/MvmGC.h Thu Dec 9 16:08:31 2010
@@ -362,6 +362,10 @@
static void objectReferenceWriteBarrier(gc* ref, gc** slot, gc* value) {
*slot = value;
}
+
+ static void objectReferenceArrayWriteBarrier(gc* ref, gc** slot, gc* value) {
+ *slot = value;
+ }
static void objectReferenceNonHeapWriteBarrier(gc** slot, gc* value) {
*slot = value;
@@ -371,6 +375,10 @@
gc* res = __sync_val_compare_and_swap(slot, old, value);
return (res == old);
}
+
+ static bool supportsWriteBarrier() {
+ return false;
+ }
};
}
Modified: vmkit/trunk/lib/Mvm/GCMmap2/gc.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/GCMmap2/gc.cpp?rev=121420&r1=121419&r2=121420&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/GCMmap2/gc.cpp (original)
+++ vmkit/trunk/lib/Mvm/GCMmap2/gc.cpp Thu Dec 9 16:08:31 2010
@@ -34,6 +34,18 @@
// This is useless with GCmmap2, as the gcmalloc already did it.
}
+extern "C" void fieldWriteBarrier(gc* ref, gc** slot, gc* value) {
+ *slot = value;
+}
+
+extern "C" void arrayWriteBarrier(gc* ref, gc** slot, gc* value) {
+ *slot = value;
+}
+
+extern "C" void nonHeapWriteBarrier(gc** slot, gc* value) {
+ *slot = value;
+}
+
void Collector::scanObject(void** val, uintptr_t closure) {
void* obj = *val;
if (obj) {
Modified: vmkit/trunk/lib/Mvm/MMTk/MvmGC.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/MMTk/MvmGC.cpp?rev=121420&r1=121419&r2=121420&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/MMTk/MvmGC.cpp (original)
+++ vmkit/trunk/lib/Mvm/MMTk/MvmGC.cpp Thu Dec 9 16:08:31 2010
@@ -109,10 +109,27 @@
return NULL;
}
+extern "C" void arrayWriteBarrier(gc* ref, gc** ptr, gc* value) {
+ *ptr = value;
+}
+
+extern "C" void fieldWriteBarrier(gc* ref, gc** ptr, gc* value) {
+ *ptr = value;
+}
+
+extern "C" void nonHeapWriteBarrier(gc** ptr, gc* value) {
+ *ptr = value;
+}
+
+
void Collector::objectReferenceWriteBarrier(gc* ref, gc** slot, gc* value) {
*slot = value;
}
+void Collector::objectReferenceArrayWriteBarrier(gc* ref, gc** slot, gc* value) {
+ *slot = value;
+}
+
void Collector::objectReferenceNonHeapWriteBarrier(gc** slot, gc* value) {
*slot = value;
}
@@ -128,3 +145,7 @@
void Collector::initialise() {
}
+
+bool Collector::supportsWriteBarrier() {
+ return false;
+}
Modified: vmkit/trunk/lib/Mvm/MMTk/MvmGC.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/MMTk/MvmGC.h?rev=121420&r1=121419&r2=121420&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/MMTk/MvmGC.h (original)
+++ vmkit/trunk/lib/Mvm/MMTk/MvmGC.h Thu Dec 9 16:08:31 2010
@@ -77,8 +77,10 @@
static gc* getForwardedReference(gc* val, uintptr_t closure) __attribute__ ((always_inline));
static gc* getForwardedReferent(gc* val, uintptr_t closure) __attribute__ ((always_inline));
static void objectReferenceWriteBarrier(gc* ref, gc** slot, gc* value) __attribute__ ((always_inline));
+ static void objectReferenceArrayWriteBarrier(gc* ref, gc** slot, gc* value) __attribute__ ((always_inline));
static void objectReferenceNonHeapWriteBarrier(gc** slot, gc* value) __attribute__ ((always_inline));
static bool objectReferenceTryCASBarrier(gc* ref, gc** slot, gc* old, gc* value) __attribute__ ((always_inline));
+ static bool supportsWriteBarrier();
static void collect();
Modified: vmkit/trunk/mmtk/java/src/org/j3/bindings/Bindings.java
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/mmtk/java/src/org/j3/bindings/Bindings.java?rev=121420&r1=121419&r2=121420&view=diff
==============================================================================
--- vmkit/trunk/mmtk/java/src/org/j3/bindings/Bindings.java (original)
+++ vmkit/trunk/mmtk/java/src/org/j3/bindings/Bindings.java Thu Dec 9 16:08:31 2010
@@ -15,6 +15,7 @@
import org.mmtk.plan.TraceLocal;
import org.mmtk.plan.TransitiveClosure;
import org.mmtk.utility.heap.HeapGrowthManager;
+import org.mmtk.utility.Constants;
import org.vmmagic.pragma.Inline;
import org.vmmagic.unboxed.Address;
import org.vmmagic.unboxed.Extent;
@@ -114,4 +115,43 @@
private static native void memcpy(
ObjectReference to, ObjectReference from, int size);
+ @Inline
+ private static void arrayWriteBarrier(ObjectReference ref, Address slot, ObjectReference value) {
+ if (Selected.Constraints.get().needsObjectReferenceWriteBarrier()) {
+ Selected.Mutator mutator = Selected.Mutator.get();
+ mutator.objectReferenceWrite(ref, slot, value, slot.toWord(), slot.toWord(), Constants.ARRAY_ELEMENT);
+ } else {
+ slot.store(value);
+ }
+ }
+
+ @Inline
+ private static void fieldWriteBarrier(ObjectReference ref, Address slot, ObjectReference value) {
+ if (Selected.Constraints.get().needsObjectReferenceWriteBarrier()) {
+ Selected.Mutator mutator = Selected.Mutator.get();
+ mutator.objectReferenceWrite(ref, slot, value, slot.toWord(), slot.toWord(), Constants.INSTANCE_FIELD);
+ } else {
+ slot.store(value);
+ }
+ }
+
+ @Inline
+ private static void nonHeapWriteBarrier(Address slot, ObjectReference value) {
+ if (Selected.Constraints.get().needsObjectReferenceNonHeapWriteBarrier()) {
+ Selected.Mutator mutator = Selected.Mutator.get();
+ mutator.objectReferenceNonHeapWrite(slot, value, slot.toWord(), slot.toWord());
+ } else {
+ slot.store(value);
+ }
+ }
+
+ @Inline
+ private static boolean writeBarrierCAS(ObjectReference src, Address slot, ObjectReference old, ObjectReference value) {
+ if (Selected.Constraints.get().needsObjectReferenceWriteBarrier()) {
+ Selected.Mutator mutator = Selected.Mutator.get();
+ return mutator.objectReferenceTryCompareAndSwap(src, slot, old, value, slot.toWord(), slot.toWord(), Constants.INSTANCE_FIELD);
+ } else {
+ return slot.attempt(old.toAddress().toWord(), value.toAddress().toWord());
+ }
+ }
}
Modified: vmkit/trunk/mmtk/java/src/org/j3/mmtk/Barriers.java
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/mmtk/java/src/org/j3/mmtk/Barriers.java?rev=121420&r1=121419&r2=121420&view=diff
==============================================================================
--- vmkit/trunk/mmtk/java/src/org/j3/mmtk/Barriers.java (original)
+++ vmkit/trunk/mmtk/java/src/org/j3/mmtk/Barriers.java Thu Dec 9 16:08:31 2010
@@ -14,7 +14,7 @@
import org.jikesrvm.SizeConstants;
import org.jikesrvm.Magic;
-import org.mmtk.vm.VM;
+import org.j3.runtime.VM;
import org.vmmagic.unboxed.*;
import org.vmmagic.pragma.*;
@@ -33,6 +33,7 @@
@Inline
@Override
public final void booleanWrite(ObjectReference objref, boolean value, Word offset, Word location, int mode) {
+ VM._assert(VM.NOT_REACHED);
Magic.setBooleanAtOffset(objref.toObject(), offset.toOffset(), value, location.toInt());
}
@@ -48,6 +49,7 @@
@Inline
@Override
public final boolean booleanRead(ObjectReference objref, Word offset, Word location, int mode) {
+ VM._assert(VM.NOT_REACHED);
return Magic.getByteAtOffset(objref.toObject(), offset.toOffset()) == 0;
}
@@ -63,6 +65,7 @@
@Inline
@Override
public final void byteWrite(ObjectReference objref, byte value, Word offset, Word location, int mode) {
+ VM._assert(VM.NOT_REACHED);
Magic.setByteAtOffset(objref.toObject(), offset.toOffset(), value, location.toInt());
}
@@ -78,6 +81,7 @@
@Inline
@Override
public final byte byteRead(ObjectReference objref, Word offset, Word location, int mode) {
+ VM._assert(VM.NOT_REACHED);
return Magic.getByteAtOffset(objref.toObject(), offset.toOffset());
}
@@ -93,6 +97,7 @@
@Inline
@Override
public final void charWrite(ObjectReference objref, char value, Word offset, Word location, int mode) {
+ VM._assert(VM.NOT_REACHED);
Magic.setCharAtOffset(objref.toObject(), offset.toOffset(), value, location.toInt());
}
@@ -108,6 +113,7 @@
@Inline
@Override
public final char charRead(ObjectReference objref, Word offset, Word location, int mode) {
+ VM._assert(VM.NOT_REACHED);
return Magic.getCharAtOffset(objref.toObject(), offset.toOffset());
}
@@ -123,6 +129,7 @@
@Inline
@Override
public final void shortWrite(ObjectReference objref, short value, Word offset, Word location, int mode) {
+ VM._assert(VM.NOT_REACHED);
Magic.setShortAtOffset(objref.toObject(), offset.toOffset(), value, location.toInt());
}
@@ -138,6 +145,7 @@
@Inline
@Override
public final short shortRead(ObjectReference objref, Word offset, Word location, int mode) {
+ VM._assert(VM.NOT_REACHED);
return Magic.getShortAtOffset(objref.toObject(), offset.toOffset());
}
@@ -153,6 +161,7 @@
@Inline
@Override
public final void intWrite(ObjectReference objref, int value, Word offset, Word location, int mode) {
+ VM._assert(VM.NOT_REACHED);
Magic.setIntAtOffset(objref.toObject(), offset.toOffset(), value, location.toInt());
}
@@ -168,6 +177,7 @@
@Inline
@Override
public final int intRead(ObjectReference objref, Word offset, Word location, int mode) {
+ VM._assert(VM.NOT_REACHED);
return Magic.getIntAtOffset(objref.toObject(), offset.toOffset());
}
@@ -184,6 +194,7 @@
*/
@Override
public boolean intTryCompareAndSwap(ObjectReference objref, int expected, int newValue, Word offset, Word unused, int mode) {
+ VM._assert(VM.NOT_REACHED);
int oldValue;
do {
oldValue = Magic.prepareInt(objref, offset.toOffset());
@@ -204,6 +215,7 @@
@Inline
@Override
public final void longWrite(ObjectReference objref, long value, Word offset, Word location, int mode) {
+ VM._assert(VM.NOT_REACHED);
Magic.setLongAtOffset(objref.toObject(), offset.toOffset(), value, location.toInt());
}
@@ -219,6 +231,7 @@
@Inline
@Override
public final long longRead(ObjectReference objref, Word offset, Word location, int mode) {
+ VM._assert(VM.NOT_REACHED);
return Magic.getLongAtOffset(objref.toObject(), offset.toOffset());
}
@@ -235,6 +248,7 @@
*/
@Override
public boolean longTryCompareAndSwap(ObjectReference objref, long expected, long newValue, Word offset, Word unused, int mode) {
+ VM._assert(VM.NOT_REACHED);
long oldValue;
do {
oldValue = Magic.prepareLong(objref, offset.toOffset());
@@ -255,6 +269,7 @@
@Inline
@Override
public final void floatWrite(ObjectReference objref, float value, Word offset, Word location, int mode) {
+ VM._assert(VM.NOT_REACHED);
Magic.setFloatAtOffset(objref.toObject(), offset.toOffset(), value, location.toInt());
}
@@ -270,6 +285,7 @@
@Inline
@Override
public final float floatRead(ObjectReference objref, Word offset, Word location, int mode) {
+ VM._assert(VM.NOT_REACHED);
return Magic.getFloatAtOffset(objref.toObject(), offset.toOffset());
}
@@ -285,6 +301,7 @@
@Inline
@Override
public final void doubleWrite(ObjectReference objref, double value, Word offset, Word location, int mode) {
+ VM._assert(VM.NOT_REACHED);
Magic.setDoubleAtOffset(objref.toObject(), offset.toOffset(), value, location.toInt());
}
@@ -300,6 +317,7 @@
@Inline
@Override
public final double doubleRead(ObjectReference objref, Word offset, Word location, int mode) {
+ VM._assert(VM.NOT_REACHED);
return Magic.getDoubleAtOffset(objref.toObject(), offset.toOffset());
}
@@ -314,8 +332,8 @@
*/
@Inline
@Override
- public final void objectReferenceWrite(ObjectReference objref, ObjectReference value, Word offset, Word location, int mode) {
- Magic.setObjectAtOffset(objref.toObject(), offset.toOffset(), value.toObject(), location.toInt());
+ public final void objectReferenceWrite(ObjectReference objref, ObjectReference value, Word slot, Word location, int mode) {
+ slot.toAddress().store(value);
}
/**
@@ -330,6 +348,7 @@
@Inline
@Override
public final ObjectReference objectReferenceRead(ObjectReference objref, Word offset, Word location, int mode) {
+ VM._assert(VM.NOT_REACHED);
return ObjectReference.fromObject(Magic.getObjectAtOffset(objref.toObject(), offset.toOffset(), location.toInt()));
}
@@ -362,6 +381,7 @@
@Inline
@Override
public final ObjectReference objectReferenceAtomicWrite(ObjectReference objref, ObjectReference target, Word offset, Word unused, int mode) {
+ VM._assert(VM.NOT_REACHED);
Object obj = objref.toObject();
Object newObject = target.toObject();
Object oldObject;
@@ -385,6 +405,7 @@
@Inline
@Override
public final boolean objectReferenceTryCompareAndSwap(ObjectReference objref, ObjectReference old, ObjectReference target, Word offset, Word unused, int mode) {
+ VM._assert(VM.NOT_REACHED);
Object oldValue;
do {
oldValue = Magic.prepareObject(objref, offset.toOffset());
@@ -405,8 +426,8 @@
@Inline
@Override
public final void wordWrite(ObjectReference ref, Word target,
- Word offset, Word location, int mode) {
- Magic.setWordAtOffset(ref.toObject(), offset.toOffset(), target, location.toInt());
+ Word slot, Word location, int mode) {
+ slot.toAddress().store(target);
}
/**
@@ -424,6 +445,7 @@
@Override
public final Word wordAtomicWrite(ObjectReference ref, Word target,
Word offset, Word unused, int mode) {
+ VM._assert(VM.NOT_REACHED);
Word oldValue;
do {
oldValue = Magic.prepareWord(ref.toObject(), offset.toOffset());
@@ -446,6 +468,7 @@
@Override
public final boolean wordTryCompareAndSwap(ObjectReference ref, Word old, Word target,
Word offset, Word unused, int mode) {
+ VM._assert(VM.NOT_REACHED);
do {
Word currentValue = Magic.prepareWord(ref, offset.toOffset());
if (currentValue != old) return false;
@@ -466,6 +489,7 @@
@Override
public final Word wordRead(ObjectReference ref,
Word offset, Word location, int mode) {
+ VM._assert(VM.NOT_REACHED);
return Magic.getWordAtOffset(ref.toObject(), offset.toOffset(), location.toInt());
}
@@ -482,6 +506,7 @@
@Override
public final void addressWrite(ObjectReference ref, Address target,
Word offset, Word location, int mode) {
+ VM._assert(VM.NOT_REACHED);
Magic.setAddressAtOffset(ref.toObject(), offset.toOffset(), target, location.toInt());
}
@@ -498,6 +523,7 @@
@Override
public final Address addressRead(ObjectReference ref,
Word offset, Word location, int mode) {
+ VM._assert(VM.NOT_REACHED);
return Magic.getAddressAtOffset(ref.toObject(), offset.toOffset(), location.toInt());
}
@@ -514,6 +540,7 @@
*/
@Override
public boolean addressTryCompareAndSwap(ObjectReference objref, Address expected, Address newValue, Word offset, Word unused, int mode) {
+ VM._assert(VM.NOT_REACHED);
Address oldValue;
do {
oldValue = Magic.prepareAddress(objref, offset.toOffset());
@@ -535,6 +562,7 @@
@Override
public final void offsetWrite(ObjectReference ref, Offset target,
Word offset, Word location, int mode) {
+ VM._assert(VM.NOT_REACHED);
Magic.setOffsetAtOffset(ref.toObject(), offset.toOffset(), target, location.toInt());
}
@@ -551,6 +579,7 @@
@Override
public final Offset offsetRead(ObjectReference ref,
Word offset, Word location, int mode) {
+ VM._assert(VM.NOT_REACHED);
return Magic.getOffsetAtOffset(ref.toObject(), offset.toOffset(), location.toInt());
}
@@ -567,6 +596,7 @@
@Override
public final void extentWrite(ObjectReference ref, Extent target,
Word offset, Word location, int mode) {
+ VM._assert(VM.NOT_REACHED);
Magic.setExtentAtOffset(ref.toObject(), offset.toOffset(), target, location.toInt());
}
@@ -583,6 +613,7 @@
@Override
public final Extent extentRead(ObjectReference ref,
Word offset, Word location, int mode) {
+ VM._assert(VM.NOT_REACHED);
return Magic.getExtentAtOffset(ref.toObject(), offset.toOffset(), location.toInt());
}
Modified: vmkit/trunk/mmtk/java/src/org/mmtk/plan/generational/Gen.java
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/mmtk/java/src/org/mmtk/plan/generational/Gen.java?rev=121420&r1=121419&r2=121420&view=diff
==============================================================================
--- vmkit/trunk/mmtk/java/src/org/mmtk/plan/generational/Gen.java (original)
+++ vmkit/trunk/mmtk/java/src/org/mmtk/plan/generational/Gen.java Thu Dec 9 16:08:31 2010
@@ -56,7 +56,7 @@
protected static final float MATURE_FRACTION = 0.5f; // est yield
private static final float WORST_CASE_COPY_EXPANSION = 1.5f; // worst case for addition of one word overhead due to address based hashing
public static final boolean IGNORE_REMSETS = false;
- public static final boolean USE_NON_HEAP_OBJECT_REFERENCE_WRITE_BARRIER = false;
+ public static final boolean USE_NON_HEAP_OBJECT_REFERENCE_WRITE_BARRIER = true;
public static final boolean USE_OBJECT_BARRIER_FOR_AASTORE = false; // choose between slot and object barriers
public static final boolean USE_OBJECT_BARRIER_FOR_PUTFIELD = false; // choose between slot and object barriers
public static final boolean USE_OBJECT_BARRIER = USE_OBJECT_BARRIER_FOR_AASTORE || USE_OBJECT_BARRIER_FOR_PUTFIELD;
Modified: vmkit/trunk/mmtk/mmtk-alloc/Selected.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/mmtk/mmtk-alloc/Selected.cpp?rev=121420&r1=121419&r2=121420&view=diff
==============================================================================
--- vmkit/trunk/mmtk/mmtk-alloc/Selected.cpp (original)
+++ vmkit/trunk/mmtk/mmtk-alloc/Selected.cpp Thu Dec 9 16:08:31 2010
@@ -45,6 +45,14 @@
uintptr_t TraceLocal, void* obj) ALWAYS_INLINE;
extern "C" uint8_t JnJVM_org_j3_bindings_Bindings_isLive__Lorg_mmtk_plan_TraceLocal_2Lorg_vmmagic_unboxed_ObjectReference_2(
uintptr_t TraceLocal, void* obj) ALWAYS_INLINE;
+
+extern "C" uint8_t JnJVM_org_j3_bindings_Bindings_writeBarrierCAS__Lorg_vmmagic_unboxed_ObjectReference_2Lorg_vmmagic_unboxed_Address_2Lorg_vmmagic_unboxed_ObjectReference_2Lorg_vmmagic_unboxed_ObjectReference_2(gc* ref, gc** slot, gc* old, gc* value) ALWAYS_INLINE;
+
+extern "C" void JnJVM_org_j3_bindings_Bindings_arrayWriteBarrier__Lorg_vmmagic_unboxed_ObjectReference_2Lorg_vmmagic_unboxed_Address_2Lorg_vmmagic_unboxed_ObjectReference_2(gc* ref, gc** ptr, gc* value) ALWAYS_INLINE;
+
+extern "C" void JnJVM_org_j3_bindings_Bindings_fieldWriteBarrier__Lorg_vmmagic_unboxed_ObjectReference_2Lorg_vmmagic_unboxed_Address_2Lorg_vmmagic_unboxed_ObjectReference_2(gc* ref, gc** ptr, gc* value) ALWAYS_INLINE;
+
+extern "C" void JnJVM_org_j3_bindings_Bindings_nonHeapWriteBarrier__Lorg_vmmagic_unboxed_Address_2Lorg_vmmagic_unboxed_ObjectReference_2(gc** ptr, gc* value) ALWAYS_INLINE;
extern "C" void* JnJVM_org_j3_bindings_Bindings_gcmalloc__ILorg_vmmagic_unboxed_ObjectReference_2(
int sz, void* VT) ALWAYS_INLINE;
@@ -54,11 +62,11 @@
return (gc*)JnJVM_org_j3_bindings_Bindings_gcmalloc__ILorg_vmmagic_unboxed_ObjectReference_2(sz, VT);
}
-extern "C" void addFinalizationCandidate(void* obj) __attribute__((always_inline));
+extern "C" void addFinalizationCandidate(gc* obj) __attribute__((always_inline));
-extern "C" void addFinalizationCandidate(void* obj) {
+extern "C" void addFinalizationCandidate(gc* obj) {
llvm_gcroot(obj, 0);
- mvm::Thread::get()->MyVM->addFinalizationCandidate((gc*)obj);
+ mvm::Thread::get()->MyVM->addFinalizationCandidate(obj);
}
extern "C" void* gcmallocUnresolved(uint32_t sz, VirtualTable* VT) {
@@ -69,6 +77,23 @@
return res;
}
+extern "C" void arrayWriteBarrier(gc* ref, gc** ptr, gc* value) {
+ JnJVM_org_j3_bindings_Bindings_arrayWriteBarrier__Lorg_vmmagic_unboxed_ObjectReference_2Lorg_vmmagic_unboxed_Address_2Lorg_vmmagic_unboxed_ObjectReference_2(
+ ref, ptr, value);
+ if (mvm::Thread::get()->doYield) mvm::Collector::collect();
+}
+
+extern "C" void fieldWriteBarrier(gc* ref, gc** ptr, gc* value) {
+ JnJVM_org_j3_bindings_Bindings_fieldWriteBarrier__Lorg_vmmagic_unboxed_ObjectReference_2Lorg_vmmagic_unboxed_Address_2Lorg_vmmagic_unboxed_ObjectReference_2(
+ ref, ptr, value);
+ if (mvm::Thread::get()->doYield) mvm::Collector::collect();
+}
+
+extern "C" void nonHeapWriteBarrier(gc** ptr, gc* value) {
+ JnJVM_org_j3_bindings_Bindings_nonHeapWriteBarrier__Lorg_vmmagic_unboxed_Address_2Lorg_vmmagic_unboxed_ObjectReference_2(ptr, value);
+ if (mvm::Thread::get()->doYield) mvm::Collector::collect();
+}
+
void MutatorThread::init(Thread* _th) {
MutatorThread* th = (MutatorThread*)_th;
th->MutatorContext =
@@ -156,16 +181,25 @@
}
void Collector::objectReferenceWriteBarrier(gc* ref, gc** slot, gc* value) {
- *slot = value;
+ fieldWriteBarrier(ref, slot, value);
+}
+
+void Collector::objectReferenceArrayWriteBarrier(gc* ref, gc** slot, gc* value) {
+ arrayWriteBarrier(ref, slot, value);
}
void Collector::objectReferenceNonHeapWriteBarrier(gc** slot, gc* value) {
- *slot = value;
+ nonHeapWriteBarrier(slot, value);
+}
+
+bool Collector::objectReferenceTryCASBarrier(gc* ref, gc** slot, gc* old, gc* value) {
+ bool res = JnJVM_org_j3_bindings_Bindings_writeBarrierCAS__Lorg_vmmagic_unboxed_ObjectReference_2Lorg_vmmagic_unboxed_Address_2Lorg_vmmagic_unboxed_ObjectReference_2Lorg_vmmagic_unboxed_ObjectReference_2(ref, slot, old, value);
+ if (mvm::Thread::get()->doYield) mvm::Collector::collect();
+ return res;
}
-bool Collector::objectReferenceTryCASBarrier(gc*ref, gc** slot, gc* old, gc* value) {
- gc* res = __sync_val_compare_and_swap(slot, old, value);
- return (old == res);
+bool Collector::supportsWriteBarrier() {
+ return true;
}
//TODO: Remove these.
Modified: vmkit/trunk/mmtk/mmtk-j3/Collection.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/mmtk/mmtk-j3/Collection.cpp?rev=121420&r1=121419&r2=121420&view=diff
==============================================================================
--- vmkit/trunk/mmtk/mmtk-j3/Collection.cpp (original)
+++ vmkit/trunk/mmtk/mmtk-j3/Collection.cpp Thu Dec 9 16:08:31 2010
@@ -36,7 +36,7 @@
// Verify that another collection is not happening.
th->MyVM->rendezvous.startRV();
- if (th->doYield) {
+ if (th->MyVM->rendezvous.getInitiator() != NULL) {
th->MyVM->rendezvous.cancelRV();
th->MyVM->rendezvous.join();
return;
@@ -104,8 +104,16 @@
extern "C" void Java_org_j3_mmtk_Collection_reportPhysicalAllocationFailed__ (MMTkObject* C) { UNIMPLEMENTED(); }
-extern "C" void Java_org_j3_mmtk_Collection_triggerAsyncCollection__I (MMTkObject* C, sint32 val) { UNIMPLEMENTED(); }
-extern "C" void Java_org_j3_mmtk_Collection_noThreadsInGC__ (MMTkObject* C) { UNIMPLEMENTED(); }
+extern "C" void Java_org_j3_mmtk_Collection_triggerAsyncCollection__I (MMTkObject* C, sint32 val) {
+ mvm::Thread::get()->doYield = true;
+}
+
+extern "C" uint8_t Java_org_j3_mmtk_Collection_noThreadsInGC__ (MMTkObject* C) {
+ mvm::Thread* th = mvm::Thread::get();
+ bool threadInGC = th->doYield;
+ return !threadInGC;
+}
+
extern "C" void Java_org_j3_mmtk_Collection_requestMutatorFlush__ (MMTkObject* C) { UNIMPLEMENTED(); }
} // namespace mmtk
More information about the vmkit-commits
mailing list