LockPerf benchmark and related fixes (nested closures)

This commit is contained in:
Alex Tkachman
2011-12-08 16:24:41 +02:00
parent b89956f1fd
commit 42a0062b79
3 changed files with 36 additions and 18 deletions
@@ -254,19 +254,24 @@ public class ClosureCodegen extends ObjectOrClosureCodegen {
iv.invokespecial(funClass, "<init>", "(Ljet/typeinfo/TypeInfo;)V");
i = 1;
int k = 0;
for (Type type : argTypes) {
StackValue.local(0, JetTypeMapper.TYPE_OBJECT).put(JetTypeMapper.TYPE_OBJECT, iv);
StackValue.local(i, type).put(type, iv);
final String fieldName;
if (captureThis && i == 1) {
fieldName = "this$0";
i++;
k++;
}
else {
if (captureReceiver != null && (captureThis && i == 2 || !captureThis && i == 1)) {
fieldName = "receiver$0";
i++;
k++;
}
else {
fieldName = "$" + (i);
fieldName = "$" + (i-k);
i++;
}
}
@@ -200,6 +200,8 @@ public class JetTypeMapper {
}
return name;
}
if(name.contains("/"))
return name;
if (container != null) {
if (container instanceof ModuleDescriptor) {
return name;
+28 -17
View File
@@ -15,36 +15,47 @@ fun thread(f: fun ()) {
thread.start()
}
fun <T> Int.latch(op: fun CountDownLatch.() : T) : T {
val cdl = CountDownLatch(this)
val res = cdl.op()
cdl.await()
return res
}
fun Int.times(action: fun Int.()) {
for(i in 0..this-1)
action()
}
fun main(args: Array<String>) {
val processors = Runtime.getRuntime().sure().availableProcessors()
var threadNum = 1
while(threadNum <= 1024) {
val counter = AtomicInteger()
val cdl = CountDownLatch(threadNum)
val lock = ReentrantLock()
val start = System.currentTimeMillis()
for(i in 0..threadNum-1) {
thread {
while(true) {
lock.lock()
try {
if (counter.get() == 100000000) {
cdl.countDown();
break;
} else {
counter.incrementAndGet();
threadNum.latch{
val lock = ReentrantLock()
threadNum.times {
thread {
while(true) {
lock.lock()
try {
if (counter.get() == 100000000) {
countDown();
break;
} else {
counter.incrementAndGet();
}
}
finally {
lock.unlock()
}
}
finally {
lock.unlock()
}
}
}
}
cdl.await()
System.out?.println(threadNum.toString() + " " + (System.currentTimeMillis() - start));
if(threadNum < 2 * processors)