fix for while-loop-ending-with-if bug
This commit is contained in:
@@ -233,6 +233,9 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
|||||||
condition.condJump(elseLabel, true, v); // == 0, i.e. false
|
condition.condJump(elseLabel, true, v); // == 0, i.e. false
|
||||||
|
|
||||||
Label end = continueLabel == null ? new Label() : continueLabel;
|
Label end = continueLabel == null ? new Label() : continueLabel;
|
||||||
|
|
||||||
|
if(continueLabel != null)
|
||||||
|
asmType = Type.VOID_TYPE;
|
||||||
|
|
||||||
gen(thenExpression, asmType);
|
gen(thenExpression, asmType);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import java.lang.Runtime
|
||||||
|
|
||||||
|
fun box() : String {
|
||||||
|
val processors = Runtime.getRuntime().sure().availableProcessors()
|
||||||
|
var threadNum = 1
|
||||||
|
while(threadNum <= 1024) {
|
||||||
|
System.out?.println(threadNum)
|
||||||
|
if(threadNum < 2 * processors)
|
||||||
|
threadNum += 1
|
||||||
|
else
|
||||||
|
threadNum *= 2
|
||||||
|
}
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -244,6 +244,12 @@ public class ControlStructuresTest extends CodegenTestCase {
|
|||||||
public void testSynchronized() throws Exception {
|
public void testSynchronized() throws Exception {
|
||||||
createEnvironmentWithFullJdk();
|
createEnvironmentWithFullJdk();
|
||||||
blackBoxFile("controlStructures/sync.jet");
|
blackBoxFile("controlStructures/sync.jet");
|
||||||
|
// System.out.println(generateToText());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testIfInWhile() throws Exception {
|
||||||
|
createEnvironmentWithFullJdk();
|
||||||
|
blackBoxFile("controlStructures/ifInWhile.jet");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
namespace lockperformance
|
namespace lockperformance
|
||||||
|
|
||||||
|
import std.io.*
|
||||||
|
import std.util.*
|
||||||
import std.concurrent.*
|
import std.concurrent.*
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
@@ -13,41 +15,37 @@ fun <T> Int.latch(op: fun CountDownLatch.() : T) : T {
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Int.times(action: fun():Unit) {
|
|
||||||
for(i in 0..this-1)
|
|
||||||
action()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
val processors = Runtime.getRuntime().sure().availableProcessors()
|
val processors = Runtime.getRuntime().sure().availableProcessors()
|
||||||
var threadNum = 1
|
var threadNum = 1
|
||||||
while(threadNum <= 1024) {
|
while(threadNum <= 1024) {
|
||||||
val counter = AtomicInteger()
|
val counter = AtomicInteger()
|
||||||
|
|
||||||
val start = System.currentTimeMillis()
|
val duration = millisTime {
|
||||||
threadNum.latch{
|
threadNum.latch{
|
||||||
val lock = ReentrantLock()
|
val lock = ReentrantLock()
|
||||||
threadNum.times {
|
for(i in 0..threadNum-1) {
|
||||||
thread {
|
thread {
|
||||||
while(true) {
|
while(true) {
|
||||||
lock.lock()
|
lock.lock()
|
||||||
try {
|
try {
|
||||||
if (counter.get() == 100000000) {
|
if (counter.get() == 100000000) {
|
||||||
countDown();
|
countDown();
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
counter.incrementAndGet();
|
counter.incrementAndGet();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
lock.unlock()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
finally {
|
|
||||||
lock.unlock()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out?.println(threadNum.toString() + " " + (System.currentTimeMillis() - start));
|
println(threadNum.toString() + " " + duration)
|
||||||
|
|
||||||
if(threadNum < 2 * processors)
|
if(threadNum < 2 * processors)
|
||||||
threadNum = threadNum + 1
|
threadNum = threadNum + 1
|
||||||
|
|||||||
Reference in New Issue
Block a user