LockPerf benchmark and related fixes (nested closures)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user