invokedynamic

When is invokedynamic actually useful (besides lazy constants)?

。_饼干妹妹 提交于 2020-05-27 09:56:22
问题 TL;DR Please provide a piece of code written in some well known dynamic language (e.g. JavaScript) and how that code would look like in Java bytecode using invokedynamic and explain why the usage of invokedynamic is a step forward here. Background I have googled and read quite a lot about the not-that-new-anymore invokedynamic instruction which everyone on the internet agrees on that it will help speed dynamic languages on the JVM. Thanks to stackoverflow I managed to get my own bytecode

Should I use Groovy's @CompileStatic if I'm also using Java 7

元气小坏坏 提交于 2020-01-01 07:56:11
问题 I've read through the "What's new in Groovy 2.0" and I'm a bit confused about when to use @CompileStatic. The article mentions that the @CompileStatic annotation was added for developers who weren't able to take advantage of the invoke dynamic part of Java7. So developers looking for performance improvements would not see much changes in Groovy 2.0, if they aren’t able to run on JDK 7. Luckily, the Groovy development team thought those developers could get interesting performance boost, among

Howto use invokedynamic with Jasmin?

霸气de小男生 提交于 2019-12-19 11:29:18
问题 Here it says: Since 2.1 : [..] added the invokedynamic instruction Thus I suppose that it is possible to write instruction code containing invokedynamics with jasmin. However I could not find any documentation on the jasmin syntax and I just figured out how to use invokedynamic to get VerifyErrors with Jasmin, but not how to create a working example. How is this instruction correctly used in Jasmin? 回答1: Each invokedynamic bytecode should refer to a corresponding call site specifier (JVMS 6.5

invokedynamic and implicit methods

别等时光非礼了梦想. 提交于 2019-12-12 09:44:33
问题 As I understand from reading this post about the new invokedynamic bytecode instruction in JDK 7, it makes it possible to call methods on the objects which are not statically defined in the object's class and have those method calls be resolved to some concrete static methods in some other class by intercepting the method call target resolution (the post gives an example). Does this mean that Java 7 classes can have implicit methods like Scala has? If not how is implicit method resolution in

How to instantiate an object using LambdaMetaFactory?

强颜欢笑 提交于 2019-12-11 03:04:29
问题 I have an interface Action: package action; public interface Action { public String act(); } Class SimpleAction: package action; public class SimpleAction implements Action { String action; public SimpleAction() {} public SimpleAction(String x) { this.action = x; } @Override public String act() { return "Act method from -" + this.action; } } Class ComplexAction: package action; public class ComplexAction implements Action{ String action; public ComplexAction() {} public ComplexAction(String x

Generate Invokedynamic with Javassist

邮差的信 提交于 2019-12-10 10:24:32
问题 I am trying to do something relatively simple, I think. Take for example the following Java bytecode for a method doSomething(int): public java.lang.String doSomething(int i); 0 iload_1 [i] 1 invokestatic MyHelper.doSomething(int) : Java.lang.String 4 areturn This bytecode pretty much only forwards the call to a static helper. What I want to do now is to replace the invokestatic with invokedynamic using Javassist. I know how to do this with ASM therefore just assume that I want to know how it

BootstrapMethodError caused by LambdaConversionException caused by using MethodHandle::invokeExact as a method reference

余生颓废 提交于 2019-12-07 11:10:43
问题 I was trying to check if it is possible to use MethodHandle::invoke or MethodHandle::invokeExact as method references for a functional interface that accepts a MethodHandle and returns a generified output. (I know that invoke and invokeExact are signature polymorphic, hence the metafactory call in InvokeExact. However, I wanted to know if the compiler is able to elide the things that I had to do to derive a suitable version of invoke/invokeExact.) invoke.InvokeExact0 package invoke; import

How to call MethodHandle.invokeExact() with an array of Object[]?

陌路散爱 提交于 2019-12-07 01:02:52
问题 Java's MethodHandle.invokeExact(Object...args) takes a variable-length list of arguments. When I try to pass an array of Object [] instead of a list, though, I get an error. See below: private void doIt() throws Throwable { Method meth = Foo.class.getDeclaredMethods()[0]; MethodHandles.Lookup lookup = MethodHandles.lookup(); MethodHandle mh = lookup.unreflect(meth); Foo foo = new Foo(); String myStr = "aaa"; Integer myInt = new Integer(10); Object [] myArray = {foo, myStr, myInt}; mh

How to call MethodHandle.invokeExact() with an array of Object[]?

為{幸葍}努か 提交于 2019-12-05 04:51:14
Java's MethodHandle.invokeExact(Object...args) takes a variable-length list of arguments. When I try to pass an array of Object [] instead of a list, though, I get an error. See below: private void doIt() throws Throwable { Method meth = Foo.class.getDeclaredMethods()[0]; MethodHandles.Lookup lookup = MethodHandles.lookup(); MethodHandle mh = lookup.unreflect(meth); Foo foo = new Foo(); String myStr = "aaa"; Integer myInt = new Integer(10); Object [] myArray = {foo, myStr, myInt}; mh.invokeExact(foo, myStr, myInt); // prints "Called aaa 10" mh.invokeExact(myArray); // throws Exception } class

Should I use Groovy's @CompileStatic if I'm also using Java 7

我们两清 提交于 2019-12-04 01:34:07
I've read through the "What's new in Groovy 2.0" and I'm a bit confused about when to use @CompileStatic. The article mentions that the @CompileStatic annotation was added for developers who weren't able to take advantage of the invoke dynamic part of Java7. So developers looking for performance improvements would not see much changes in Groovy 2.0, if they aren’t able to run on JDK 7. Luckily, the Groovy development team thought those developers could get interesting performance boost, among other advantages, by allowing type checked code to be compiled statically. My question is, if I'm