Skip to content
Permalink
Browse files

Add full invoke-custom example

  • Loading branch information...
JesusFreke committed May 22, 2018
1 parent 48d13b2 commit e6f4475c87dfac7f08ca4df9d5efbf3731400eb7
Showing with 113 additions and 0 deletions.
  1. +60 −0 examples/InvokeCustom/BootstrapLinker.smali
  2. +27 −0 examples/InvokeCustom/Custom.smali
  3. +26 −0 examples/InvokeCustom/Main.smali
@@ -0,0 +1,60 @@
.class public LBootstrapLinker;

.super Ljava/lang/Object;

.method public static normalLink(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/Object;)Ljava/lang/invoke/CallSite;
.registers 15

sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;
const-string v3, "BootstrapLinker.normalLink - "
invoke-virtual {v0, v3}, Ljava/io/PrintStream;->print(Ljava/lang/String;)V
invoke-virtual {p3}, Ljava/lang/Object;->toString()Ljava/lang/String;
move-result-object v1
invoke-virtual {v0, v1}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

const v0, 0
const v1, 1
invoke-virtual {p2, v0, v1}, Ljava/lang/invoke/MethodType;->dropParameterTypes(II)Ljava/lang/invoke/MethodType;
move-result-object p2

const-class v1, LCustom;

invoke-virtual {p0, v1, p1, p2}, Ljava/lang/invoke/MethodHandles$Lookup;->findVirtual(Ljava/lang/Class;Ljava/lang/String;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/MethodHandle;
move-result-object v2

new-instance v0, Ljava/lang/invoke/ConstantCallSite;
invoke-direct {v0, v2}, Ljava/lang/invoke/ConstantCallSite;-><init>(Ljava/lang/invoke/MethodHandle;)V

return-object v0
.end method


.method public static backwardsLink(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/String;)Ljava/lang/invoke/CallSite;
.registers 15

sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;
const-string v3, "BootstrapLinker.backwardsLink - "
invoke-virtual {v0, v3}, Ljava/io/PrintStream;->print(Ljava/lang/String;)V
invoke-virtual {v0, p3}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

const v0, 0
const v1, 1
invoke-virtual {p2, v0, v1}, Ljava/lang/invoke/MethodType;->dropParameterTypes(II)Ljava/lang/invoke/MethodType;
move-result-object p2

new-instance v0, Ljava/lang/StringBuffer;
invoke-direct {v0, p1}, Ljava/lang/StringBuffer;-><init>(Ljava/lang/String;)V
invoke-virtual {v0}, Ljava/lang/StringBuffer;->reverse()Ljava/lang/StringBuffer;
invoke-virtual {v0}, Ljava/lang/StringBuffer;->toString()Ljava/lang/String;
move-result-object p1

const-class v1, LCustom;

invoke-virtual {p0, v1, p1, p2}, Ljava/lang/invoke/MethodHandles$Lookup;->findVirtual(Ljava/lang/Class;Ljava/lang/String;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/MethodHandle;
move-result-object v2

new-instance v0, Ljava/lang/invoke/ConstantCallSite;
invoke-direct {v0, v2}, Ljava/lang/invoke/ConstantCallSite;-><init>(Ljava/lang/invoke/MethodHandle;)V

return-object v0
.end method
@@ -0,0 +1,27 @@
.class public LCustom;

.super Ljava/lang/Object;

.method public doSomething(Ljava/lang/String;)Ljava/lang/String;
.registers 15

sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;

invoke-virtual {v0, p1}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

const-string v1, "Custom"

return-object v1
.end method

.method public gnihtemoSod(Ljava/lang/String;)Ljava/lang/String;
.registers 15

sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;

invoke-virtual {v0, p1}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

const-string v1, "motsuC"

return-object v1
.end method
@@ -0,0 +1,26 @@
.class LMain;

.super Ljava/lang/Object;

.method public static main([Ljava/lang/String;)V
.registers 15

new-instance v0, LCustom;
invoke-direct {v0}, LCustom;-><init>()V

const-string v1, "Arg to doSomething"

invoke-custom {v0, v1}, normallyLinkedCallSite("doSomething", (LCustom;Ljava/lang/String;)Ljava/lang/String;, "just testing")@LBootstrapLinker;->normalLink(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/String;)Ljava/lang/invoke/CallSite;
move-result-object v2
sget-object v3, Ljava/lang/System;->out:Ljava/io/PrintStream;
const-string v4, "got back - "
invoke-virtual {v3, v4}, Ljava/io/PrintStream;->print(Ljava/lang/String;)V
invoke-virtual {v3, v2}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

invoke-custom {v0, v1}, backwardsLinkedCallSite("doSomething", (LCustom;Ljava/lang/String;)Ljava/lang/String;, "just testing")@LBootstrapLinker;->backwardsLink(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/String;)Ljava/lang/invoke/CallSite;
move-result-object v2
sget-object v3, Ljava/lang/System;->out:Ljava/io/PrintStream;
const-string v4, "got back - "
invoke-virtual {v3, v4}, Ljava/io/PrintStream;->print(Ljava/lang/String;)V
invoke-virtual {v3, v2}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V
.end method

0 comments on commit e6f4475

Please sign in to comment.
You can’t perform that action at this time.