For questions about the invokedynamic bytecode instruction of the Java virtual machine.
Questions tagged [invokedynamic]
78 questions
6
votes
1 answer
Benefit of specifying -jvm-target / jvmTarget version other than 1.8
As of Kotlin 1.6.0, for Kotlin/JVM projects one may specify the -jvm-target version option up to Java 17, see general and Gradle plugin documentation.
What are the benefits of doing so?
I couldn't find much on the benefits of specifying something…

Endzeit
- 4,810
- 5
- 29
- 52
6
votes
3 answers
How to mimic `tableswitch` using `MethodHandle`?
Context: I've been benchmarking the difference between using invokedynamic and manually generating bytecode (this is in the context of deciding whether a compiler targeting the JVM should emit more verbose "traditional" bytecode or just an…

Alec
- 31,829
- 7
- 67
- 114
6
votes
0 answers
Using Grails with Groovy's invoke dynamic feature
In Groovy 2.1, full support was added for invokedynamic (see here and here).
In order to use this feature, it looks like JDK7 is required and the "indy" Groovy jar.
I'm using Grails 2.4.3, with JDK7 and Groovy 2.3, so it seems like this should be…

DashFwd2
- 101
- 3
6
votes
1 answer
Generating working invokedynamic instruction with ASM
I'm working with Java bytecode via ASM and am trying to get a simple invokedynamic example functioning properly. I feel as though I'm fundamentally misunderstanding how invokedynamic is supposed to work. This is what I've tried so far:
In Test2.java…

arshajii
- 127,459
- 24
- 238
- 287
5
votes
2 answers
MethodHandle example throws WrongMethodTypeException on invokeExact call
The example shown in the description of the MethodHandle class throws a WrongMethodTypeException in the invocation of the statement mh.invokeExact("daddy",'d','n') with the following description: (CC)Ljava/lang/String; cannot be called with a…

Miguel Gamboa
- 8,855
- 7
- 47
- 94
5
votes
1 answer
Implement duck typing using java MethodHandles
I have two classes A and B, both define method foo() with common signature (accept nothing, return void). They don't have the common base class (or interface) that declares this method. I want to call this method on regardless As or Bs as long as…

Netherwire
- 2,669
- 3
- 31
- 54
5
votes
1 answer
Lambda matches signature of a FunctionalInterface, yet "does not". How do you explain that the argument is passed at all?
I am working on this project currently. It works surprisingly well.
Yet, after re-reading the README again, I started to wonder about how to document something that is bugging me...
To quote the example, and forgetting for a moment that exceptions…

fge
- 119,121
- 33
- 254
- 329
5
votes
1 answer
BootstrapMethodError caused by LambdaConversionException caused by using MethodHandle::invokeExact as a method reference
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…

srborlongan
- 4,460
- 4
- 26
- 33
4
votes
1 answer
InvokeDynamic - how to acces arguments in bootstrap method?
I am trying to implement "duck typing" with invokedynamic in JVM7. I created two different classes, both of them have the method greet() which returns String. I randomly select between one of them, store the instance on the stack and call…

jk_
- 5,448
- 5
- 25
- 23
4
votes
2 answers
invokedynamic and implicit methods
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…

Abhinav Sarkar
- 23,534
- 11
- 81
- 97
4
votes
0 answers
From `=> T` to `() => T` and back again
As parameters of types => T and () => T are both Function0, I always naively assumed that conversion from one to another is a noop. It seems however, that while true for (=>T) => (() => T), the other direction (() => T) => (=> T) results in wrapping…

Turin
- 2,208
- 15
- 23
4
votes
1 answer
What is call site in Java when calling method?
I'm trying to understand what is call site in JVM. Quote from https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-5.html#jvms-5.4.3.6
The result of call site specifier resolution is a tuple consisting of:
• the reference to an instance of…

Some Name
- 8,555
- 5
- 27
- 77
4
votes
1 answer
Java bytecode, java Supplier and invokedynamic argument
I have this class, and I compile it.
package org.test;
import java.util.function.Supplier;
public class Test {
static String get() { return "!!"; }
public static void main(String[] args) {
Supplier sup = Test::get;
…

Wyvie
- 140
- 1
- 6
4
votes
1 answer
Generate Invokedynamic with Javassist
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) :…

Christoph
- 687
- 1
- 6
- 12
3
votes
1 answer
How to bootstrap interface method reference with ObjectWeb2 ASM
I am trying to fix the metafactory call for an interface method reference in Groovy: https://issues.apache.org/jira/browse/GROOVY-9853
Given small Java program
public class J {
public static void main(String[] args) {
…

emilles
- 1,104
- 7
- 14