Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bytecode round 9 #192

Closed
wants to merge 42 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
eea8b31
lifting concats
asotona Jul 22, 2024
d32912f
fixed generating of non-String concats
asotona Jul 22, 2024
f5eaa8f
fixed LocalsTypeMapper and lambdas lifting
asotona Jul 23, 2024
807a5c9
fixed LocalsTypeMapper to track uninitialized types
asotona Jul 25, 2024
e08395f
BytecodeLift fixes of code branching with deep stack and unitialized …
asotona Jul 25, 2024
0c9f586
removed debug output
asotona Jul 25, 2024
44faf01
removed obsolete BytecodeGenerator::conversion
asotona Jul 26, 2024
2415558
Merge branch 'code-reflection' into bytecode-round-9
asotona Jul 26, 2024
edf9639
LocalTypeMapper performs iterative correction of int stack map frame …
asotona Jul 26, 2024
8bc8d2f
block parameters constructions from fixed stack maps
asotona Jul 26, 2024
e2c90be
fixed lifting and generation of non-void returning MH used in void re…
asotona Jul 29, 2024
2a8f6f2
fixed SlotSSA to avoid explicit cast of primitive types
asotona Jul 29, 2024
12513ec
corrected stack to block parametrs conversion
asotona Jul 29, 2024
81de233
TestSmallCorpus progress
asotona Jul 29, 2024
ea75652
fixed unitialized stack maps objects in block parameters
asotona Jul 29, 2024
557fd9e
fixed lifting of IF_ACMPEQ and IF_ACMPNE
asotona Jul 29, 2024
40e2572
fixed ConstantInstruction type detection in LocalsTypeMapper
asotona Jul 30, 2024
4476219
BytecodeLift filters out exception handlers overlapping with try blocks
asotona Jul 31, 2024
0bd79b4
using trusted lookup in TestSmallCorpus
asotona Jul 31, 2024
0140e07
BytecodeLift detects branches out of the exception region and inserts…
asotona Jul 31, 2024
c1ac080
Fixd lifting of split exception table (with internal transitions) ime…
asotona Aug 1, 2024
401b438
fixed generation of exception regions with implicit exits only
asotona Aug 1, 2024
4983f05
Implemented BytecodeLift::extractExceptionHandlers to filter and spli…
asotona Aug 1, 2024
6a50b0e
fixed LshlOp generation
asotona Aug 2, 2024
3079016
fixed INDY lifting of BSMs with vararg parameter
asotona Aug 2, 2024
f19605a
fixed BytecodeLift::extractExceptionHandlers
asotona Aug 2, 2024
26b38f3
Do not cache class constants in BytecodeLift
asotona Aug 2, 2024
26073d9
fixed BytecodeGenerator NPE when result is used twice in one operands
asotona Aug 2, 2024
88c5550
SlotSSA modified to avoid adding block parameters to catch blocks
asotona Aug 2, 2024
cfda3b5
Removing catch blocks from dominance frontier in SlotSSA
asotona Aug 5, 2024
55c4108
fixed lifting of CONDY with vararg BSM
asotona Aug 6, 2024
4f6ed24
BytecodeLKift fixed insertion of exception region exits before handle…
asotona Aug 7, 2024
8c87a82
fixed generation of multi-catch exception regions
asotona Aug 8, 2024
4a6740a
fixed lifting of complex nested exception regions
asotona Aug 8, 2024
8af2006
fixed generation of BASTORE, SASTORE and CASTORE
asotona Aug 8, 2024
3d43c04
explicit cast of method return type to InvokeOp return type in Byteco…
asotona Aug 8, 2024
52b0ea7
included verification into TestSmallCorpus
asotona Aug 8, 2024
17fbfc5
fixed identification of the right target block in BytecodeLift
asotona Aug 9, 2024
129a80d
Merge remote-tracking branch 'babylon/code-reflection' into bytecode-…
asotona Aug 9, 2024
268128f
Updated TestSmallCorpus
asotona Aug 9, 2024
5400609
Updated TestSmallCorpus
asotona Aug 9, 2024
3a94b05
fixed BytecodeGenerator::moreThanOneUse calculation
asotona Aug 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -82,13 +82,11 @@ public final class BytecodeLift {
private static final JavaType MHS_LOOKUP = JavaType.type(ConstantDescs.CD_MethodHandles_Lookup);
private static final JavaType MH = JavaType.type(ConstantDescs.CD_MethodHandle);
private static final JavaType MT = JavaType.type(ConstantDescs.CD_MethodType);
private static final JavaType ARRAYLIST = JavaType.type(ArrayList.class.describeConstable().get());
private static final FunctionType ARRAYLIST_INIT = FunctionType.functionType(ARRAYLIST);
private static final JavaType CLASS_ARRAY = JavaType.array(JavaType.J_L_CLASS);
private static final MethodRef LCMP = MethodRef.method(JavaType.J_L_LONG, "compare", JavaType.INT, JavaType.LONG, JavaType.LONG);
private static final MethodRef FCMP = MethodRef.method(JavaType.J_L_FLOAT, "compare", JavaType.INT, JavaType.FLOAT, JavaType.FLOAT);
private static final MethodRef DCMP = MethodRef.method(JavaType.J_L_DOUBLE, "compare", JavaType.INT, JavaType.DOUBLE, JavaType.DOUBLE);
private static final MethodRef LOOKUP = MethodRef.method(JavaType.type(ConstantDescs.CD_MethodHandles), "lookup", MHS_LOOKUP);
private static final MethodRef ARRAYLIST_ADD = MethodRef.method(ARRAYLIST, "add", JavaType.BOOLEAN, JavaType.J_L_OBJECT);
private static final MethodRef FIND_STATIC = MethodRef.method(MHS_LOOKUP, "findStatic", MH, JavaType.J_L_CLASS, JavaType.J_L_STRING, MT);
private static final MethodRef FIND_VIRTUAL = MethodRef.method(MHS_LOOKUP, "findVirtual", MH, JavaType.J_L_CLASS, JavaType.J_L_STRING, MT);
private static final MethodRef FIND_CONSTRUCTOR = MethodRef.method(MHS_LOOKUP, "findConstructor", MH, JavaType.J_L_CLASS, MT);
@@ -98,7 +96,7 @@ public final class BytecodeLift {
private static final MethodRef FIND_STATIC_SETTER = MethodRef.method(MHS_LOOKUP, "findStaticSetter", MH, JavaType.J_L_CLASS, JavaType.J_L_STRING, JavaType.J_L_CLASS);
private static final MethodRef METHOD_TYPE_0 = MethodRef.method(MT, "methodType", MT, JavaType.J_L_CLASS);
private static final MethodRef METHOD_TYPE_1 = MethodRef.method(MT, "methodType", MT, JavaType.J_L_CLASS, JavaType.J_L_CLASS);
private static final MethodRef METHOD_TYPE_L = MethodRef.method(MT, "methodType", MT, JavaType.J_L_CLASS, JavaType.J_U_LIST);
private static final MethodRef METHOD_TYPE_L = MethodRef.method(MT, "methodType", MT, JavaType.J_L_CLASS, CLASS_ARRAY);

private final Block.Builder entryBlock;
private final ClassModel classModel;
@@ -610,18 +608,30 @@ yield op(CoreOp._new(
MethodTypeDesc mtd = inst.typeSymbol();

//bootstrap
List<Value> bootstrapArgs = new ArrayList<>();
bootstrapArgs.add(lookup());
bootstrapArgs.add(liftConstant(inst.name().toString()));
bootstrapArgs.add(liftConstant(mtd));
for (ConstantDesc barg : inst.bootstrapArgs()) {
bootstrapArgs.add(liftConstant(barg));
}
MethodTypeDesc bsmDesc = bsm.invocationType();
MethodRef bsmRef = MethodRef.method(JavaType.type(bsmOwner),
bsm.methodName(),
JavaType.type(bsmDesc.returnType()),
bsmDesc.parameterList().stream().map(JavaType::type).toArray(TypeElement[]::new));
Value[] bootstrapArgs = new Value[bsmDesc.parameterCount()];
bootstrapArgs[0] = lookup();
bootstrapArgs[1] = liftConstant(inst.name().toString());
bootstrapArgs[2] = liftConstant(mtd);
ClassDesc lastArgType = bsmDesc.parameterType(bsmDesc.parameterCount() - 1);
List<ConstantDesc> bsmArgs = inst.bootstrapArgs();
if (lastArgType.isArray()) {
for (int ai = 0; ai < bootstrapArgs.length - 4; ai++) {
bootstrapArgs[ai + 3] = liftConstant(bsmArgs.get(ai));
}
// Vararg tail of the bootstrap method parameters
bootstrapArgs[bootstrapArgs.length - 1] =
liftConstantsIntoArray(JavaType.type(lastArgType),
bsmArgs.subList(bootstrapArgs.length - 4, bsmArgs.size()).toArray());
} else {
for (int ai = 0; ai < bootstrapArgs.length - 3; ai++) {
bootstrapArgs[ai + 3] = liftConstant(bsmArgs.get(ai));
}
}
Value methodHandle = op(CoreOp.invoke(MethodRef.method(CallSite.class, "dynamicInvoker", MethodHandle.class),
op(CoreOp.invoke(JavaType.type(ConstantDescs.CD_CallSite), bsmRef, bootstrapArgs))));

@@ -795,6 +805,14 @@ private Op.Result lookup() {
return constantCache.computeIfAbsent(LOOKUP, _ -> op(CoreOp.invoke(LOOKUP)));
}

private Op.Result liftConstantsIntoArray(TypeElement arrayType, Object... constants) {
Op.Result array = op(CoreOp.newArray(arrayType, liftConstant(constants.length)));
for (int i = 0; i < constants.length; i++) {
op(CoreOp.arrayStoreOp(array, liftConstant(i), liftConstant(constants[i])));
}
return array;
}

private Op.Result liftConstant(Object c) {
Op.Result res = constantCache.get(c);
if (res == null) {
@@ -834,13 +852,7 @@ yield op(switch (dmh.kind()) {
case MethodTypeDesc mt -> op(switch (mt.parameterCount()) {
case 0 -> CoreOp.invoke(METHOD_TYPE_0, liftConstant(mt.returnType()));
case 1 -> CoreOp.invoke(METHOD_TYPE_1, liftConstant(mt.returnType()), liftConstant(mt.parameterType(0)));
default -> {
Op.Result list = op(CoreOp._new(ARRAYLIST_INIT));
for (ClassDesc p : mt.parameterList()) {
op(CoreOp.invoke(ARRAYLIST_ADD, list, liftConstant(p)));
}
yield CoreOp.invoke(METHOD_TYPE_L, liftConstant(mt.returnType()), list);
}
default -> CoreOp.invoke(METHOD_TYPE_L, liftConstant(mt.returnType()), liftConstantsIntoArray(CLASS_ARRAY, (Object[])mt.parameterArray()));
});
case DynamicConstantDesc<?> v when v.bootstrapMethod().owner().equals(ConstantDescs.CD_ConstantBootstraps)
&& v.bootstrapMethod().methodName().equals("nullConstant")
Original file line number Diff line number Diff line change
@@ -94,7 +94,7 @@ public void testDoubleRoundtripStability() throws Exception {
}

// @@@ There is still several failing cases and a lot of errors
Assert.assertTrue(passed > 33700, String.format("""
Assert.assertTrue(passed > 33750, String.format("""

passed: %d
not matching: %d