Skip to content

Conversation

retronym
Copy link
Member

VarHandles bring a host of new "polymorphic signature" methods to
the Java 9 standard library. This commit updates the way we detect
such methods to look at the absense/presense of the
PolymorphicSignature annotation, so as to include these (and any
future additions.)

When we see applications of such methods, we disable adaptation
of argument and return types.

Tested manually with JDK9-ea:

Welcome to Scala 2.12.2-20161208-165912-3de1c0c (Java HotSpot(TM) 64-Bit Server VM, Java 9-ea). Type in expressions for evaluation. Or try :help. scala> import java.lang.invoke._, scala.runtime.IntRef import java.lang.invoke._ import scala.runtime.IntRef scala> val varHandle = MethodHandles.lookup().in(classOf[IntRef]).findVarHandle(classOf[IntRef], "elem", classOf[Int]); varHandle: java.lang.invoke.VarHandle = java.lang.invoke.VarHandleInts$FieldInstanceReadWrite@7112ce6 scala> varHandle.getAndSet(ref, 1): Int res5: Int = 0 scala> varHandle.getAndSet(ref, 1): Int res6: Int = 1 

Inspecting bytecode shows the absense of box/unboxing:

object Test { import java.lang.invoke._, scala.runtime.IntRef val varHandle = MethodHandles.lookup().in(classOf[IntRef]).findVarHandle(classOf[IntRef], "elem", classOf[Int]); def main(args: Array[String]): Unit = { val i : Int = varHandle.getAndSet(IntRef.zero, 1) } } 
 public void main(java.lang.String[]); Code: 0: aload_0 1: invokevirtual #28 // Method varHandle:()Ljava/lang/invoke/VarHandle; 4: invokestatic #34 // Method scala/runtime/IntRef.zero:()Lscala/runtime/IntRef; 7: iconst_1 8: invokevirtual #40 // Method java/lang/invoke/VarHandle.getAndSet:(Lscala/runtime/IntRef;I)I 11: istore_2 12: return 

Reference scala/scala-dev#139

@scala-jenkins scala-jenkins added this to the 2.12.2 milestone Dec 12, 2016
@retronym
Copy link
Member Author

Review by @lrytz

@lrytz lrytz self-requested a review December 12, 2016 10:09
Copy link
Member

@lrytz lrytz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tiny cleanup, then 🚢 it

!! 1264 - run/t6240-universe-code-gen.scala [non-zero exit code] ##### Log file '/home/jenkins/workspace/scala-2.12.x-validate-test/test/files/run/t6240-universe-code-gen-run.log' from failed test ##### java.lang.AssertionError: assertion failed: /home/jenkins/workspace/scala-2.12.x-validate-test/src/reflect/scala/reflect/runtime/JavaUniverseForce.scala must be updated. =========================================================== DIFF: =========================================================== --- a +++ b @@ -268,2 +268,3 @@ definitions.RepeatedParamClass + definitions.JavaLangInvokePackage definitions.ConsClass 
VarHandles bring a host of new "polymorphic signature" methods to the Java 9 standard library. This commit updates the way we detect such methods to look at the absense/presense of the `PolymorphicSignature` annotation, so as to include these (and any future additions.) When we see applications of such methods, we disable adaptation of argument and return types. Tested manually with JDK9-ea: ``` Welcome to Scala 2.12.2-20161208-165912-3de1c0c (Java HotSpot(TM) 64-Bit Server VM, Java 9-ea). Type in expressions for evaluation. Or try :help. scala> import java.lang.invoke._, scala.runtime.IntRef import java.lang.invoke._ import scala.runtime.IntRef scala> val varHandle = MethodHandles.lookup().in(classOf[IntRef]).findVarHandle(classOf[IntRef], "elem", classOf[Int]); varHandle: java.lang.invoke.VarHandle = java.lang.invoke.VarHandleInts$FieldInstanceReadWrite@7112ce6 scala> varHandle.getAndSet(ref, 1): Int res5: Int = 0 scala> varHandle.getAndSet(ref, 1): Int res6: Int = 1 ``` Inspecting bytecode shows the absense of box/unboxing: ``` object Test { import java.lang.invoke._, scala.runtime.IntRef val varHandle = MethodHandles.lookup().in(classOf[IntRef]).findVarHandle(classOf[IntRef], "elem", classOf[Int]); def main(args: Array[String]): Unit = { val i : Int = varHandle.getAndSet(IntRef.zero, 1) } } ``` ``` public void main(java.lang.String[]); Code: 0: aload_0 1: invokevirtual #28 // Method varHandle:()Ljava/lang/invoke/VarHandle; 4: invokestatic #34 // Method scala/runtime/IntRef.zero:()Lscala/runtime/IntRef; 7: iconst_1 8: invokevirtual #40 // Method java/lang/invoke/VarHandle.getAndSet:(Lscala/runtime/IntRef;I)I 11: istore_2 12: return ```
@SethTisue

This comment was marked as outdated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants