Skip to content

Commit

Permalink
support constructor references
Browse files Browse the repository at this point in the history
  • Loading branch information
dicej committed Jul 9, 2017
1 parent a329416 commit 24b9501
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
18 changes: 16 additions & 2 deletions classpath/java/lang/invoke/LambdaMetafactory.java
Expand Up @@ -278,7 +278,7 @@ private static byte[] makeInvocationCode(List<PoolEntry> pool,
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
write2(out, fieldType.footprint()
+ localType.footprint() + 2); // max stack
+ localType.footprint() + 3); // max stack
write2(out, localType.footprint() + 1); // max locals
write4(out, 0); // length (we'll set the real value later)

Expand Down Expand Up @@ -326,6 +326,18 @@ private static byte[] makeInvocationCode(List<PoolEntry> pool,
writeMethodReference(out, pool, implementation.method);
break;

case MethodHandle.REF_newInvokeSpecial:
write1(out, new_);
write2(out, ConstantPool.addClass
(pool,
Classes.makeString
(implementation.method.class_.name, 0,
implementation.method.class_.name.length - 1)) + 1);
write1(out, dup);
write1(out, invokespecial);
writeMethodReference(out, pool, implementation.method);
break;

case MethodHandle.REF_invokeInterface:
write1(out, invokeinterface);
writeInterfaceMethodReference(out, pool, implementation.method);
Expand All @@ -337,7 +349,9 @@ private static byte[] makeInvocationCode(List<PoolEntry> pool,
("todo: implement '" + implementation.kind + "' per http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-5.html#jvms-5.4.3.5");
}

maybeBoxOrUnbox(out, pool, implementation.type().result(), localType.result());
if (implementation.kind != MethodHandle.REF_newInvokeSpecial) {
maybeBoxOrUnbox(out, pool, implementation.type().result(), localType.result());
}
write1(out, localType.result().return_());

write2(out, 0); // exception handler table length
Expand Down
1 change: 1 addition & 0 deletions classpath/java/lang/invoke/MethodHandle.java
Expand Up @@ -17,6 +17,7 @@ public class MethodHandle {
static final int REF_invokeVirtual = 5;
static final int REF_invokeStatic = 6;
static final int REF_invokeSpecial = 7;
static final int REF_newInvokeSpecial = 8;
static final int REF_invokeInterface = 9;

final int kind;
Expand Down
4 changes: 4 additions & 0 deletions test/InvokeDynamic.java
Expand Up @@ -176,5 +176,9 @@ private void test() {
{ Unboxed s = InvokeDynamic::addBoxed;
expect(s.add(1, 2) == 3);
}

{ Supplier<java.util.List<String>> s = java.util.ArrayList<String>::new;
java.util.List<String> list = s.get();
}
}
}

0 comments on commit 24b9501

Please sign in to comment.