From 8176487c9382b4c114d80333544018e6f2295bb5 Mon Sep 17 00:00:00 2001 From: Alex Tkachman Date: Tue, 24 Jan 2012 14:48:09 +0200 Subject: [PATCH] changed synchronized from extension method to normal one --- .../jet/codegen/intrinsics/IntrinsicMethods.java | 2 +- .../jetbrains/jet/codegen/intrinsics/StupidSync.java | 3 +-- compiler/frontend/src/jet/Library.jet | 2 +- compiler/testData/codegen/controlStructures/sync.jet | 10 +++++----- stdlib/ktSrc/System.kt | 2 +- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IntrinsicMethods.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IntrinsicMethods.java index 372e4a4f3c1..55e6a8535c5 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IntrinsicMethods.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IntrinsicMethods.java @@ -96,7 +96,7 @@ public class IntrinsicMethods { declareOverload(myStdLib.getLibraryScope().getFunctions("plus"), 1, STRING_PLUS); declareOverload(myStdLib.getLibraryScope().getFunctions("Array"), 1, new NewArray()); declareOverload(myStdLib.getLibraryScope().getFunctions("sure"), 0, new Sure()); - declareOverload(myStdLib.getLibraryScope().getFunctions("synchronized"), 1, new StupidSync()); + declareOverload(myStdLib.getLibraryScope().getFunctions("synchronized"), 2, new StupidSync()); declareOverload(myStdLib.getLibraryScope().getFunctions("iterator"), 0, new IteratorIterator()); declareIntrinsicFunction("ByteIterator", "next", 0, ITERATOR_NEXT); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/StupidSync.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/StupidSync.java index 1e83272f26e..fe55095525c 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/StupidSync.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/StupidSync.java @@ -17,8 +17,7 @@ import java.util.List; public class StupidSync implements IntrinsicMethod { @Override public StackValue generate(ExpressionCodegen codegen, InstructionAdapter v, Type expectedType, @Nullable PsiElement element, @Nullable List arguments, StackValue receiver) { - receiver.put(receiver.type, v); - codegen.pushMethodArguments((JetCallExpression)element, Arrays.asList(JetTypeMapper.TYPE_FUNCTION0)); + codegen.pushMethodArguments((JetCallExpression)element, Arrays.asList(JetTypeMapper.TYPE_OBJECT, JetTypeMapper.TYPE_FUNCTION0)); v.invokestatic("jet/runtime/Intrinsics", "stupidSync", "(Ljava/lang/Object;Ljet/Function0;)Ljava/lang/Object;"); StackValue.onStack(JetTypeMapper.TYPE_OBJECT).put(expectedType, v); return StackValue.onStack(expectedType); diff --git a/compiler/frontend/src/jet/Library.jet b/compiler/frontend/src/jet/Library.jet index 127344a5d25..07c2f42ee7e 100644 --- a/compiler/frontend/src/jet/Library.jet +++ b/compiler/frontend/src/jet/Library.jet @@ -8,7 +8,7 @@ class TypeInfo { fun typeinfo() : TypeInfo fun typeinfo(expression : T) : TypeInfo -fun Any.synchronized(block : () -> R) : R +fun synchronized(lock: Any, block : () -> R) : R fun Any?.identityEquals(other : Any?) : Boolean // = this === other diff --git a/compiler/testData/codegen/controlStructures/sync.jet b/compiler/testData/codegen/controlStructures/sync.jet index 6af5e9af150..317fa64a53a 100644 --- a/compiler/testData/codegen/controlStructures/sync.jet +++ b/compiler/testData/codegen/controlStructures/sync.jet @@ -11,16 +11,16 @@ fun thread(block: ()->Unit ) { } fun box() : String { - val ref = AtomicInteger() + val mtref = AtomicInteger() val cdl = CountDownLatch(11) for(i in 0..10) { thread { var current = 0 do { - current = ref.synchronized { - val v = ref.get() + 1 + current = synchronized(mtref) { + val v = mtref.get() + 1 if(v < 100) - ref.set(v+1) + mtref.set(v+1) v } } @@ -29,5 +29,5 @@ fun box() : String { } } cdl.await() - return if(ref.get() == 100) "OK" else ref.get().toString() + return if(mtref.get() == 100) "OK" else mtref.get().toString() } \ No newline at end of file diff --git a/stdlib/ktSrc/System.kt b/stdlib/ktSrc/System.kt index 2d62972afbe..bd761eac5fe 100644 --- a/stdlib/ktSrc/System.kt +++ b/stdlib/ktSrc/System.kt @@ -10,7 +10,7 @@ fun measureTimeMillis(block: () -> Unit) : Long { } /** -Executes current block and returns elapsed time in milliseconds +Executes current block and returns elapsed time in nanoseconds */ fun measureTimeNano(block: () -> Unit) : Long { val start = System.nanoTime()