Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

Commit

Permalink
Merge "Refinements relating to invoke-custom"
Browse files Browse the repository at this point in the history
  • Loading branch information
ohodson authored and Gerrit Code Review committed Jul 7, 2017
2 parents e65ce16 + ff80988 commit c4a548c
Show file tree
Hide file tree
Showing 10 changed files with 2,506 additions and 2,529 deletions.
3 changes: 2 additions & 1 deletion dexdump/DexDump.cpp
Expand Up @@ -1994,7 +1994,8 @@ static void dumpCallSites(DexFile* pDexFile)
const DexCallSiteId* ids = (const DexCallSiteId*)(pDexFile->baseAddr + item->offset);
for (u4 index = 0; index < item->size; ++index) {
bool doXml = (gOptions.outputFormat == OUTPUT_XML);
printf(doXml ? "<call_site index=\"%u\">\n" : "Call Site #%u\n", index);
printf(doXml ? "<call_site index=\"%u\" offset=\"%u\">\n" : "Call Site #%u // offset %u\n",
index, ids[index].callSiteOff);
const u1* data = pDexFile->baseAddr + ids[index].callSiteOff;
u4 count = readUnsignedLeb128(&data);
for (u4 i = 0; i < count; ++i) {
Expand Down
4 changes: 2 additions & 2 deletions dx/src/com/android/dx/cf/code/BasicBlocker.java
Expand Up @@ -17,7 +17,7 @@
package com.android.dx.cf.code;

import com.android.dx.rop.cst.Constant;
import com.android.dx.rop.cst.CstCallSiteRef;
import com.android.dx.rop.cst.CstInvokeDynamic;
import com.android.dx.rop.cst.CstMemberRef;
import com.android.dx.rop.cst.CstString;
import com.android.dx.rop.cst.CstType;
Expand Down Expand Up @@ -201,7 +201,7 @@ public void visitConstant(int opcode, int offset, int length,
visitCommon(offset, length, true);

if ((cst instanceof CstMemberRef) || (cst instanceof CstType) ||
(cst instanceof CstString) || (cst instanceof CstCallSiteRef)) {
(cst instanceof CstString) || (cst instanceof CstInvokeDynamic)) {
/*
* Instructions with these sorts of constants have the
* possibility of throwing, so this instruction needs to
Expand Down
3 changes: 1 addition & 2 deletions dx/src/com/android/dx/cf/code/BytecodeArray.java
Expand Up @@ -778,8 +778,7 @@ public int parseInstruction(int offset, Visitor visitor) {
int idx = bytes.getUnsignedShort(offset + 1);
// Skip to must-be-zero bytes at offsets 3 and 4
CstInvokeDynamic cstInvokeDynamic = (CstInvokeDynamic) pool.get(idx);
CstCallSiteRef ref = cstInvokeDynamic.addReference();
visitor.visitConstant(opcode, offset, 5, ref, 0);
visitor.visitConstant(opcode, offset, 5, cstInvokeDynamic, 0);
return 5;
}
case ByteOps.NEWARRAY: {
Expand Down
6 changes: 5 additions & 1 deletion dx/src/com/android/dx/cf/code/Simulator.java
Expand Up @@ -24,6 +24,7 @@
import com.android.dx.rop.cst.CstFieldRef;
import com.android.dx.rop.cst.CstInteger;
import com.android.dx.rop.cst.CstInterfaceMethodRef;
import com.android.dx.rop.cst.CstInvokeDynamic;
import com.android.dx.rop.cst.CstMethodRef;
import com.android.dx.rop.cst.CstType;
import com.android.dx.rop.type.Prototype;
Expand Down Expand Up @@ -711,9 +712,12 @@ public void visitConstant(int opcode, int offset, int length,
" (invokedynamic requires --min-sdk-version >= " +
DexFormat.API_INVOKE_POLYMORPHIC + ")");
}
CstCallSiteRef invokeDynamicRef = (CstCallSiteRef) cst;
CstInvokeDynamic invokeDynamicRef = (CstInvokeDynamic) cst;
Prototype prototype = invokeDynamicRef.getPrototype();
machine.popArgs(frame, prototype);
// Change the constant to be associated with instruction to
// a call site reference.
cst = invokeDynamicRef.addReference();
break;
}
case ByteOps.MULTIANEWARRAY: {
Expand Down
4,883 changes: 2,427 additions & 2,456 deletions dx/tests/135-invoke-custom/expected.txt

Large diffs are not rendered by default.

Binary file modified dx/tests/135-invoke-custom/invokecustom.jar
Binary file not shown.
36 changes: 36 additions & 0 deletions dx/tests/135-invoke-custom/run
Expand Up @@ -33,3 +33,39 @@ for SDK_VERSION in ${UNSUPPORTED_SDK_VERSION} ${SUPPORTED_SDK_VERSION}; do
exit 1
fi
done

# Check each invokedynamic instruction produced one invoke-custom
INVOKEDYNAMIC_COUNT=$( javap -c -v -cp invokecustom.jar invokecustom.InvokeCustom | \
grep "invokedynamic #" | \
wc -l )
INVOKE_CUSTOM_COUNT=$( dexdump -d invokecustom.dex | \
grep ": invoke-custom" | \
wc -l )
if [ "${INVOKEDYNAMIC_COUNT}" -ne "${INVOKE_CUSTOM_COUNT}" ]; then
echo Found ${INVOKEDYNAMIC_COUNT} uses of invokedynamic but ${INVOKE_CUSTOM_COUNT} uses of invoke-custom.
exit 1
fi

# Check there is a 1:1 correspondance between the number of call site ids and invoke-custom bytecodes.
CALL_SITE_ID_COUNT=$( dexdump invokecustom.dex | \
sed -n -e '/Call Site #/ p' | \
wc -l )
if [ ${CALL_SITE_ID_COUNT} -gt ${INVOKE_CUSTOM_COUNT} ]; then
echo Found ${CALL_SITE_ID_COUNT} call sites but ${INVOKE_CUSTOM_COUNT} uses of invoke-custom.
exit 1
fi

# Check number of invokedynamic constants matches the number of unique call sites
CST_INDY_COUNT=$( javap -c -v -cp invokecustom.jar invokecustom.InvokeCustom | \
sed -n -e '/: invokedynamic/ { s/.*invokedynamic #\([0-9]*\),.*/\1/ ; p }' | \
sort | \
uniq -c | \
wc -l )
CALL_SITE_COUNT=$( dexdump invokecustom.dex | \
sed -n -e '/^Call Site/ { s/[0-9]\+// ; p }' | \
uniq -c | \
wc -l)
if [ ${CST_INDY_COUNT} -ne ${CALL_SITE_COUNT} ]; then
echo Found ${CST_INDY_COUNT} invokedynamic constants but ${CALL_SITE_COUNT} call sites.
exit 1
fi
74 changes: 17 additions & 57 deletions dx/tests/137-dexmerger-dex38/expected.txt
Expand Up @@ -847,7 +847,7 @@ Class #1 -
outs : 0
insns size : 4 16-bit code units
004894: |[004894] invokecustom.InvokeCustom1.test1:()V
0048a4: fc00 0100 0000 |0000: invoke-custom {}, call_site@0001
0048a4: fc00 0000 0000 |0000: invoke-custom {}, call_site@0000
0048aa: 0e00 |0003: return-void
catches : (none)
positions :
Expand Down Expand Up @@ -1728,7 +1728,7 @@ Class #2 -
00510e: 1706 15cd 5b07 |000d: const-wide/32 v6, #float 1.6536e-34 // #075bcd15
005114: 1808 b6fa f8b0 4819 0c40 |0010: const-wide v8, #double 3.51235 // #400c1948b0f8fab6
00511e: 1a0a 4300 |0015: const-string v10, "String" // string@0043
005122: fd0b 0300 0000 |0017: invoke-custom/range {v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10}, call_site@0003
005122: fd0b 0100 0000 |0017: invoke-custom/range {v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10}, call_site@0001
005128: 0e00 |001a: return-void
catches : (none)
positions :
Expand Down Expand Up @@ -2600,7 +2600,7 @@ Class #3 -
outs : 0
insns size : 4 16-bit code units
005964: |[005964] invokecustom.InvokeCustom3.test3:()V
005974: fc00 0500 0000 |0000: invoke-custom {}, call_site@0005
005974: fc00 0200 0000 |0000: invoke-custom {}, call_site@0002
00597a: 0e00 |0003: return-void
catches : (none)
positions :
Expand Down Expand Up @@ -3475,7 +3475,7 @@ Class #4 -
0061c4: 1300 e803 |0000: const/16 v0, #int 1000 // #3e8
0061c8: 1301 65fc |0002: const/16 v1, #int -923 // #fc65
0061cc: 1302 4d00 |0004: const/16 v2, #int 77 // #4d
0061d0: fc30 0700 1002 |0006: invoke-custom {v0, v1, v2}, call_site@0007
0061d0: fc30 0300 1002 |0006: invoke-custom {v0, v1, v2}, call_site@0003
0061d6: 0a00 |0009: move-result v0
0061d8: 6201 1000 |000a: sget-object v1, Ljava/lang/System;.out:Ljava/io/PrintStream; // field@0010
0061dc: 2202 1700 |000c: new-instance v2, Ljava/lang/StringBuilder; // type@0017
Expand Down Expand Up @@ -4362,7 +4362,7 @@ Class #5 -
006a54: 1800 7777 7777 7707 0000 |0000: const-wide v0, #double 4.05612e-311 // #0000077777777777
006a5e: 1802 efee eeee eefe ffff |0005: const-wide v2, #double -nan // #fffffeeeeeeeeeef
006a68: 1804 6666 6666 6606 0000 |000a: const-wide v4, #double 3.47668e-311 // #0000066666666666
006a72: fd06 0900 0000 |000f: invoke-custom/range {v0, v1, v2, v3, v4, v5}, call_site@0009
006a72: fd06 0400 0000 |000f: invoke-custom/range {v0, v1, v2, v3, v4, v5}, call_site@0004
006a78: 0b00 |0012: move-result-wide v0
006a7a: 6202 1000 |0013: sget-object v2, Ljava/lang/System;.out:Ljava/io/PrintStream; // field@0010
006a7e: 2203 1700 |0015: new-instance v3, Ljava/lang/StringBuilder; // type@0017
Expand Down Expand Up @@ -5249,7 +5249,7 @@ Class #6 -
0072f4: 1400 0040 003f |0000: const v0, #float 0.500977 // #3f004000
0072fa: 1401 0040 00bf |0003: const v1, #float -0.500977 // #bf004000
007300: 1802 0000 0000 0410 d0bf |0006: const-wide v2, #double -0.250978 // #bfd0100400000000
00730a: fc40 0b00 1032 |000b: invoke-custom {v0, v1, v2, v3}, call_site@000b
00730a: fc40 0500 1032 |000b: invoke-custom {v0, v1, v2, v3}, call_site@0005
007310: 0b00 |000e: move-result-wide v0
007312: 6202 1000 |000f: sget-object v2, Ljava/lang/System;.out:Ljava/io/PrintStream; // field@0010
007316: 2203 1700 |0011: new-instance v3, Ljava/lang/StringBuilder; // type@0017
Expand Down Expand Up @@ -6134,11 +6134,11 @@ Class #7 -
insns size : 16 16-bit code units
007b7c: |[007b7c] invokecustom.InvokeCustom8.test8:()V
007b8c: 1a00 1400 |0000: const-string v0, "First invokedynamic invocation" // string@0014
007b90: fc10 0f00 0000 |0002: invoke-custom {v0}, call_site@000f
007b90: fc10 0600 0000 |0002: invoke-custom {v0}, call_site@0006
007b96: 1a00 4200 |0005: const-string v0, "Second invokedynamic invocation" // string@0042
007b9a: fc10 1000 0000 |0007: invoke-custom {v0}, call_site@0010
007b9a: fc10 0700 0000 |0007: invoke-custom {v0}, call_site@0007
007ba0: 1a00 0f00 |000a: const-string v0, "Dupe first invokedynamic invocation" // string@000f
007ba4: fc10 1100 0000 |000c: invoke-custom {v0}, call_site@0011
007ba4: fc10 0800 0000 |000c: invoke-custom {v0}, call_site@0008
007baa: 0e00 |000f: return-void
catches : (none)
positions :
Expand Down Expand Up @@ -7109,79 +7109,39 @@ Call site #0: // offset 57124
link_argument[0] : 0 (MethodHandle)
link_argument[1] : targetMethodTest1 (String)
link_argument[2] : ()V (MethodType)
Call site #1: // offset 57124
link_argument[0] : 0 (MethodHandle)
link_argument[1] : targetMethodTest1 (String)
link_argument[2] : ()V (MethodType)
Call site #2: // offset 57131
link_argument[0] : 0 (MethodHandle)
link_argument[1] : targetMethodTest2 (String)
link_argument[2] : (ZBCSIFJDLjava/lang/String;)V (MethodType)
Call site #3: // offset 57131
Call site #1: // offset 57131
link_argument[0] : 0 (MethodHandle)
link_argument[1] : targetMethodTest2 (String)
link_argument[2] : (ZBCSIFJDLjava/lang/String;)V (MethodType)
Call site #4: // offset 57138
link_argument[0] : 0 (MethodHandle)
link_argument[1] : targetMethodTest3 (String)
link_argument[2] : ()V (MethodType)
link_argument[3] : 1 (int)
link_argument[4] : 123456789 (long)
link_argument[5] : 123.456 (float)
link_argument[6] : 123457 (double)
Call site #5: // offset 57138
Call site #2: // offset 57138
link_argument[0] : 0 (MethodHandle)
link_argument[1] : targetMethodTest3 (String)
link_argument[2] : ()V (MethodType)
link_argument[3] : 1 (int)
link_argument[4] : 123456789 (long)
link_argument[5] : 123.456 (float)
link_argument[6] : 123457 (double)
Call site #6: // offset 57166
link_argument[0] : 0 (MethodHandle)
link_argument[1] : targetMethodTest5 (String)
link_argument[2] : (III)I (MethodType)
Call site #7: // offset 57166
Call site #3: // offset 57166
link_argument[0] : 0 (MethodHandle)
link_argument[1] : targetMethodTest5 (String)
link_argument[2] : (III)I (MethodType)
Call site #8: // offset 57173
Call site #4: // offset 57173
link_argument[0] : 0 (MethodHandle)
link_argument[1] : targetMethodTest6 (String)
link_argument[2] : (JJJ)J (MethodType)
Call site #9: // offset 57173
link_argument[0] : 0 (MethodHandle)
link_argument[1] : targetMethodTest6 (String)
link_argument[2] : (JJJ)J (MethodType)
Call site #10: // offset 57180
link_argument[0] : 0 (MethodHandle)
link_argument[1] : targetMethodTest7 (String)
link_argument[2] : (FFD)D (MethodType)
Call site #11: // offset 57180
Call site #5: // offset 57180
link_argument[0] : 0 (MethodHandle)
link_argument[1] : targetMethodTest7 (String)
link_argument[2] : (FFD)D (MethodType)
Call site #12: // offset 57187
link_argument[0] : 0 (MethodHandle)
link_argument[1] : targetMethodTest8 (String)
link_argument[2] : (Ljava/lang/String;)V (MethodType)
Call site #13: // offset 57187
link_argument[0] : 0 (MethodHandle)
link_argument[1] : targetMethodTest8 (String)
link_argument[2] : (Ljava/lang/String;)V (MethodType)
Call site #14: // offset 57187
link_argument[0] : 0 (MethodHandle)
link_argument[1] : targetMethodTest8 (String)
link_argument[2] : (Ljava/lang/String;)V (MethodType)
Call site #15: // offset 57187
Call site #6: // offset 57187
link_argument[0] : 0 (MethodHandle)
link_argument[1] : targetMethodTest8 (String)
link_argument[2] : (Ljava/lang/String;)V (MethodType)
Call site #16: // offset 57187
Call site #7: // offset 57187
link_argument[0] : 0 (MethodHandle)
link_argument[1] : targetMethodTest8 (String)
link_argument[2] : (Ljava/lang/String;)V (MethodType)
Call site #17: // offset 57187
Call site #8: // offset 57187
link_argument[0] : 0 (MethodHandle)
link_argument[1] : targetMethodTest8 (String)
link_argument[2] : (Ljava/lang/String;)V (MethodType)
15 changes: 7 additions & 8 deletions dx/tests/139-lambda-metafactory/expected.txt
@@ -1,9 +1,9 @@
Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
000000: 6465 780a 3033 3800 |magic: "dex\n038\0"
000008: 7e08 861f |checksum
00000c: e48a 8e6c 24e0 84f7 c591|signature
000016: a728 6015 6a2c 6639 54a9|
000008: 9607 cfef |checksum
00000c: 1d6a 9f47 2cbc a11c 1e0f|signature
000016: f188 46fc 9b74 db32 2eab|
000020: 3c07 0000 |file_size: 0000073c
000024: 7000 0000 |header_size: 00000070
000028: 7856 3412 |endian_tag: 12345678
Expand Down Expand Up @@ -277,8 +277,7 @@ Note: Recompile with -Xlint:unchecked for details.
|call_site_ids:
|[0] call site{method-handle{invoke-static,method{java.lang.invoke.LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;}}, string{"accept"}, proto{(LFoo;I)LConsumer;}, proto{(Ljava/lang/Object;)V}, method-handle{invoke-direct,method{Foo.lambda$bar$0:(ILjava/lang/Object;)V}}, proto{(Ljava/lang/Object;)V}}
000298: 1c06 0000 |call_site_off: 0000061c
|[1] call site{method-handle{invoke-static,method{java.lang.invoke.LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;}}, string{"accept"}, proto{(LFoo;I)LConsumer;}, proto{(Ljava/lang/Object;)V}, method-handle{invoke-direct,method{Foo.lambda$bar$0:(ILjava/lang/Object;)V}}, proto{(Ljava/lang/Object;)V}}
00029c: 1c06 0000 |call_site_off: 0000061c
00029c: 0000 0000 |
|
|method_handles:
0002a0: 0400 |kind: 0004
Expand Down Expand Up @@ -355,7 +354,7 @@ Note: Recompile with -Xlint:unchecked for details.
00030e: 0000 | tries_size: 0000
000310: ee05 0000 | debug_off: 000005ee
000314: 0d00 0000 | insns_size: 0000000d
000318: fc20 0100 3200 | 0000: invoke-custom {v2, v3}, {invoke-static,method{java.lang.invoke.LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;}, accept, (LFoo;I)LConsumer;, (Ljava/lang/Object;)V, invoke-direct,method{Foo.lambda$bar$0:(ILjava/lang/Object;)V}, (Ljava/lang/Object;)V} // CallSiteRef@0001
000318: fc20 0000 3200 | 0000: invoke-custom {v2, v3}, {invoke-static,method{java.lang.invoke.LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;}, accept, (LFoo;I)LConsumer;, (Ljava/lang/Object;)V, invoke-direct,method{Foo.lambda$bar$0:(ILjava/lang/Object;)V}, (Ljava/lang/Object;)V} // CallSiteRef@0000
00031e: 0c00 | 0003: move-result-object v0
000320: 1211 | 0004: const/4 v1, #int 1 // #1
000322: 7110 0800 0100 | 0005: invoke-static {v1}, java.lang.Integer.valueOf:(I)Ljava/lang/Integer; // method@0008
Expand Down Expand Up @@ -774,7 +773,7 @@ Note: Recompile with -Xlint:unchecked for details.
|[6ac] call_site_id_item map
0006ac: 0700 | type: 0007 // TYPE_CALL_SITE_ID_ITEM
0006ae: 0000 | unused: 0
0006b0: 0200 0000 | size: 00000002
0006b0: 0100 0000 | size: 00000001
0006b4: 9802 0000 | offset: 00000298
|[6b8] method_handle_item map
0006b8: 0800 | type: 0008 // TYPE_METHOD_HANDLE_ITEM
Expand Down Expand Up @@ -847,7 +846,7 @@ Note: Recompile with -Xlint:unchecked for details.
| 8 bytes/item
| annotations directory: 1 item; 24 bytes total
| 24 bytes/item
| call site id: 2 items; 8 bytes total
| call site id: 1 item; 4 bytes total
| 4 bytes/item
| class data: 3 items; 43 bytes total
| 8..21 bytes/item; average 14
Expand Down
11 changes: 9 additions & 2 deletions dx/tests/run-test
Expand Up @@ -124,8 +124,15 @@ if [ "$dev_mode" = "yes" ]; then
echo "exit status: $?" 1>&2
good="yes"
elif [ "$update_mode" = "yes" ]; then
"./$run" >"${progdir}/$td_expected" 2>&1
good="yes"
"./$run" >"$output" 2>&1
if [[ $? == 0 ]]; then
good="yes"
mv "$output" "${progdir}/${td_expected}"
else
echo "Test failed during update."
good="no"
fi

else
"./$run" >"$output" 2>&1
cmp -s "$expected" "$output"
Expand Down

0 comments on commit c4a548c

Please sign in to comment.