Skip to content

Commit

Permalink
Replace all PartialEvaluator constructor calls with builder calls
Browse files Browse the repository at this point in the history
  • Loading branch information
piazzesiNiccolo-GS authored and maqsoodahmadjan committed Oct 25, 2024
1 parent dd4b8bd commit 7b6712e
Show file tree
Hide file tree
Showing 16 changed files with 100 additions and 63 deletions.
41 changes: 30 additions & 11 deletions base/src/main/java/proguard/optimize/Optimizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,11 @@ public ClassVisitor createClassVisitor()
new AllMethodVisitor(
new AllAttributeVisitor(
new DebugAttributeVisitor("Filling out fields, method parameters, and return values in synthetic classes",
new PartialEvaluator(detailedValueFactory, storingInvocationUnit, false))))));
PartialEvaluator.Builder.create()
.setValueFactory(detailedValueFactory)
.setInvocationUnit(storingInvocationUnit)
.setEvaluateAllCode(false)
.build())))));

// Evaluate non-synthetic classes. We may need to evaluate all
// casts, to account for downcasts when specializing descriptors.
Expand All @@ -959,10 +963,14 @@ public ClassVisitor createClassVisitor()
new AllMethodVisitor(
new AllAttributeVisitor(
new DebugAttributeVisitor("Filling out fields, method parameters, and return values",
new PartialEvaluator(valueFactory, storingInvocationUnit,
fieldSpecializationType ||
methodSpecializationParametertype ||
methodSpecializationReturntype)))));
PartialEvaluator.Builder.create()
.setValueFactory(valueFactory)
.setInvocationUnit(storingInvocationUnit)
.setEvaluateAllCode(
fieldSpecializationType ||
methodSpecializationParametertype ||
methodSpecializationReturntype)
.build()))));
}
};

Expand Down Expand Up @@ -1056,7 +1064,11 @@ public ClassVisitor createClassVisitor()
new ClassAccessFilter(AccessConstants.SYNTHETIC, 0,
new AllMethodVisitor(
new AllAttributeVisitor(
new PartialEvaluator(valueFactory, loadingInvocationUnit, false)))));
PartialEvaluator.Builder.create()
.setValueFactory(valueFactory)
.setInvocationUnit(loadingInvocationUnit)
.setEvaluateAllCode(false)
.build()))));
}
}

Expand All @@ -1083,7 +1095,11 @@ public ClassVisitor createClassVisitor()
new DebugAttributeVisitor("Simplifying code",
new OptimizationCodeAttributeFilter(
new EvaluationSimplifier(
new PartialEvaluator(valueFactory, loadingInvocationUnit, false),
PartialEvaluator.Builder.create()
.setValueFactory(valueFactory)
.setInvocationUnit(loadingInvocationUnit)
.setEvaluateAllCode(false)
.build(),
codeSimplificationAdvancedCounter,
configuration.optimizeConservatively)))));
}
Expand Down Expand Up @@ -1125,11 +1141,14 @@ public ClassVisitor createClassVisitor()
new OptimizationCodeAttributeFilter(
new EvaluationShrinker(
new InstructionUsageMarker(
new PartialEvaluator(referenceTracingValueFactory,
new ParameterTracingInvocationUnit(loadingInvocationUnit),
!codeSimplificationAdvanced,
referenceTracingValueFactory),
PartialEvaluator.Builder.create()
.setValueFactory(referenceTracingValueFactory)
.setInvocationUnit(new ParameterTracingInvocationUnit(loadingInvocationUnit))
.setEvaluateAllCode(!codeSimplificationAdvanced)
.setExtraInstructionVisitor(referenceTracingValueFactory)
.build(),
true, configuration.optimizeConservatively), true, deletedCounter, addedCounter)))));

}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ public MemberVisitor createMemberVisitor(MemberVisitor influencedMethodCollector
ReferenceTracingValueFactory referenceTracingValueFactory1 =
new ReferenceTracingValueFactory(new TypedReferenceValueFactory());
PartialEvaluator partialEvaluator =
new PartialEvaluator(referenceTracingValueFactory1,
new ParameterTracingInvocationUnit(new BasicInvocationUnit(referenceTracingValueFactory1)),
false,
referenceTracingValueFactory1);
PartialEvaluator.Builder.create()
.setValueFactory(referenceTracingValueFactory1)
.setInvocationUnit(new ParameterTracingInvocationUnit(new BasicInvocationUnit(referenceTracingValueFactory1)))
.setEvaluateAllCode(false)
.setExtraInstructionVisitor(referenceTracingValueFactory1)
.build();
InstructionUsageMarker instructionUsageMarker =
new InstructionUsageMarker(partialEvaluator, false, false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public class EvaluationShrinker
*/
public EvaluationShrinker()
{
this(new PartialEvaluator(), true, false, null, null);
this(PartialEvaluator.Builder.create().build(), true, false, null, null);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class EvaluationSimplifier
*/
public EvaluationSimplifier(boolean predictNullPointerExceptions)
{
this(new PartialEvaluator(), null, predictNullPointerExceptions);
this(PartialEvaluator.Builder.create().build(), null, predictNullPointerExceptions);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public class InstructionUsageMarker
*/
public InstructionUsageMarker(boolean markExternalSideEffects)
{
this(new PartialEvaluator(), true, true, markExternalSideEffects);
this(PartialEvaluator.Builder.create().build(), true, true, markExternalSideEffects);
}

/**
Expand Down Expand Up @@ -129,9 +129,10 @@ public InstructionUsageMarker(PartialEvaluator partialEvaluator,
this.ensureSafetyForVerifier = ensureSafetyForVerifier;
this.markExternalSideEffects = markExternalSideEffects;
this.sideEffectInstructionChecker = new SideEffectInstructionChecker(true, true, markExternalSideEffects);
if (ensureSafetyForVerifier)
{
this.simplePartialEvaluator = new PartialEvaluator(new TypedReferenceValueFactory());
if (ensureSafetyForVerifier) {
this.simplePartialEvaluator = PartialEvaluator.Builder.create()
.setValueFactory(new TypedReferenceValueFactory())
.build();
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class SimpleEnumUseChecker
*/
public SimpleEnumUseChecker()
{
this(new PartialEvaluator(new TypedReferenceValueFactory()));
this(PartialEvaluator.Builder.create().setValueFactory(new TypedReferenceValueFactory()).build());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class SimpleEnumUseSimplifier
*/
public SimpleEnumUseSimplifier()
{
this(new PartialEvaluator(new TypedReferenceValueFactory()), null);
this(PartialEvaluator.Builder.create().setValueFactory(new TypedReferenceValueFactory()).build(), null);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ public class GsonBuilderInvocationFinder
private final InstructionSequenceMatcher registerTypeAdapterFactoryMatcher;
private final InstructionSequenceMatcher serializeSpecialFloatingPointValuesMatcher;
private final TypedReferenceValueFactory valueFactory =
new TypedReferenceValueFactory();
new TypedReferenceValueFactory();
private final PartialEvaluator partialEvaluator =
new PartialEvaluator(valueFactory,
new BasicInvocationUnit(new TypedReferenceValueFactory()),
true);
PartialEvaluator.Builder.create()
.setValueFactory(valueFactory)
.setInvocationUnit(new BasicInvocationUnit(valueFactory))
.setEvaluateAllCode(true)
.build();
private final AttributeVisitor lazyPartialEvaluator =
new AttributeNameFilter(Attribute.CODE,
new SingleTimeAttributeVisitor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ public class GsonConstructorPatcher

private final CodeAttributeEditor codeAttributeEditor;
private final TypedReferenceValueFactory valueFactory =
new TypedReferenceValueFactory();
new TypedReferenceValueFactory();
private final PartialEvaluator partialEvaluator =
new PartialEvaluator(valueFactory,
new BasicInvocationUnit(new TypedReferenceValueFactory()),
true);
PartialEvaluator.Builder.create()
.setValueFactory(valueFactory)
.setInvocationUnit(new BasicInvocationUnit(valueFactory))
.setEvaluateAllCode(true)
.build();
private final AttributeVisitor lazyPartialEvaluator =
new AttributeNameFilter(Attribute.CODE,
new SingleTimeAttributeVisitor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ public class GsonDeserializationInvocationFinder
private final ClassVisitor domainClassVisitor;
private final WarningPrinter warningPrinter;
private final FromJsonInvocationMatcher[] fromJsonInvocationMatchers;
private final TypedReferenceValueFactory valueFactory =
new TypedReferenceValueFactory();
private final PartialEvaluator partialEvaluator =
new PartialEvaluator(valueFactory,
new BasicInvocationUnit(new TypedReferenceValueFactory()),
true);
private final TypedReferenceValueFactory valueFactory =
new TypedReferenceValueFactory();
private final PartialEvaluator partialEvaluator =
PartialEvaluator.Builder.create()
.setValueFactory(valueFactory)
.setInvocationUnit(new BasicInvocationUnit(valueFactory))
.setEvaluateAllCode(true)
.build();
private final AttributeVisitor lazyPartialEvaluator =
new AttributeNameFilter(Attribute.CODE,
new SingleTimeAttributeVisitor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@ public class GsonSerializationInvocationFinder
private final WarningPrinter warningPrinter;
private final ToJsonInvocationMatcher[] toJsonInvocationMatchers;
private final TypedReferenceValueFactory valueFactory =
new TypedReferenceValueFactory();
new TypedReferenceValueFactory();
private final PartialEvaluator partialEvaluator =
new PartialEvaluator(valueFactory,
new BasicInvocationUnit(new TypedReferenceValueFactory()),
true);
PartialEvaluator.Builder.create()
.setValueFactory(valueFactory)
.setInvocationUnit(new BasicInvocationUnit(valueFactory))
.setEvaluateAllCode(true)
.build();
private final AttributeVisitor lazyPartialEvaluator =
new AttributeNameFilter(Attribute.CODE,
new SingleTimeAttributeVisitor(partialEvaluator));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,12 @@ public EscapingClassMarker(ValueFactory valueFactory)
*/
public EscapingClassMarker(ReferenceTracingValueFactory tracingValueFactory)
{
this(new PartialEvaluator(tracingValueFactory,
new ReferenceTracingInvocationUnit(new BasicInvocationUnit(tracingValueFactory)),
true,
tracingValueFactory),
this(PartialEvaluator.Builder.create()
.setValueFactory(tracingValueFactory)
.setInvocationUnit(new ReferenceTracingInvocationUnit(new BasicInvocationUnit(tracingValueFactory)))
.setEvaluateAllCode(true)
.setExtraInstructionVisitor(tracingValueFactory)
.build(),
true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,23 @@ public ParameterEscapeMarker(MemberVisitor extraMemberVisitor)
*/
public ParameterEscapeMarker(ValueFactory valueFactory, MemberVisitor extraMemberVisitor)
{
this(valueFactory, new ReferenceTracingValueFactory(valueFactory), extraMemberVisitor
this(new ReferenceTracingValueFactory(valueFactory), extraMemberVisitor
);
}


/**
* Creates a new ParameterEscapeMarker.
*/
public ParameterEscapeMarker(ValueFactory valueFactory,
ReferenceTracingValueFactory tracingValueFactory,
public ParameterEscapeMarker(ReferenceTracingValueFactory tracingValueFactory,
MemberVisitor extraMemberVisitor)
{
this(new PartialEvaluator(tracingValueFactory,
new ParameterTracingInvocationUnit(new BasicInvocationUnit(tracingValueFactory)),
true,
tracingValueFactory), true, extraMemberVisitor
this(PartialEvaluator.Builder.create()
.setValueFactory(tracingValueFactory)
.setInvocationUnit(new ParameterTracingInvocationUnit(new BasicInvocationUnit(tracingValueFactory)))
.setEvaluateAllCode(true)
.setExtraInstructionVisitor(tracingValueFactory)
.build(), true, extraMemberVisitor
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@ public class ParameterEscapedMarker
private final ClassVisitor parameterEscapedMarker =
new AllMethodVisitor(
new AllAttributeVisitor(this));
private final ValueFactory valueFactory = new BasicValueFactory();
private final ReferenceTracingValueFactory tracingValueFactory = new ReferenceTracingValueFactory(valueFactory);
private final ReferenceTracingValueFactory tracingValueFactory = new ReferenceTracingValueFactory(new BasicValueFactory());
private final PartialEvaluator partialEvaluator =
new PartialEvaluator(tracingValueFactory,
new ParameterTracingInvocationUnit(new BasicInvocationUnit(tracingValueFactory)),
true,
tracingValueFactory);
PartialEvaluator.Builder.create()
.setValueFactory(tracingValueFactory)
.setInvocationUnit(new ParameterTracingInvocationUnit(new BasicInvocationUnit(tracingValueFactory)))
.setEvaluateAllCode(true)
.setExtraInstructionVisitor(tracingValueFactory)
.build();
private final ReferenceEscapeChecker referenceEscapeChecker = new ReferenceEscapeChecker(partialEvaluator, false);

// Parameters and values for visitor methods.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class ParameterUsageMarker
private final boolean markThisParameter;
private final boolean markAllParameters;
private final boolean analyzeCode;
private final PartialEvaluator partialEvaluator = new PartialEvaluator();
private final PartialEvaluator partialEvaluator = PartialEvaluator.Builder.create().build();


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,13 @@ public ReferenceEscapeChecker()
*/
private ReferenceEscapeChecker(ReferenceTracingValueFactory referenceTracingValueFactory)
{
this(new PartialEvaluator(referenceTracingValueFactory,
new ParameterTracingInvocationUnit(new BasicInvocationUnit(referenceTracingValueFactory)),
true,
referenceTracingValueFactory),
this(
PartialEvaluator.Builder.create()
.setValueFactory(referenceTracingValueFactory)
.setInvocationUnit(new ParameterTracingInvocationUnit(new BasicInvocationUnit(referenceTracingValueFactory)))
.setEvaluateAllCode(true)
.setExtraInstructionVisitor(referenceTracingValueFactory)
.build(),
true);
}

Expand Down

0 comments on commit 7b6712e

Please sign in to comment.