Skip to content

Commit a13ee06

Browse files
Instrumentation pipeline refactor (#25)
* feat: add bridge return checks * feat: add field read check * feat: add unchecked method return checks * chore: spotless * refactor: Instrumentation pipeline refactor * chore: cleanup
1 parent edde206 commit a13ee06

16 files changed

Lines changed: 569 additions & 577 deletions

checker/src/main/java/io/github/eisop/runtimeframework/checker/nullness/NullnessVerifier.java renamed to checker/src/main/java/io/github/eisop/runtimeframework/checker/nullness/NullnessCheckGenerator.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package io.github.eisop.runtimeframework.checker.nullness;
22

3-
import io.github.eisop.runtimeframework.core.RuntimeVerifier;
3+
import io.github.eisop.runtimeframework.core.CheckGenerator;
44
import io.github.eisop.runtimeframework.runtime.AttributionKind;
55
import java.lang.classfile.CodeBuilder;
66
import java.lang.classfile.TypeKind;
77
import java.lang.constant.ClassDesc;
88
import java.lang.constant.MethodTypeDesc;
99

10-
public class NullnessVerifier implements RuntimeVerifier {
10+
public class NullnessCheckGenerator implements CheckGenerator {
1111

1212
private static final ClassDesc VERIFIER = ClassDesc.of(NullnessRuntimeVerifier.class.getName());
1313
private static final ClassDesc ATTRIBUTION_KIND = ClassDesc.of(AttributionKind.class.getName());
@@ -23,18 +23,17 @@ public class NullnessVerifier implements RuntimeVerifier {
2323

2424
private final AttributionKind attribution;
2525

26-
public NullnessVerifier() {
26+
public NullnessCheckGenerator() {
2727
this(AttributionKind.LOCAL);
2828
}
2929

30-
public NullnessVerifier(AttributionKind attribution) {
30+
public NullnessCheckGenerator(AttributionKind attribution) {
3131
this.attribution = attribution;
3232
}
3333

3434
@Override
35-
public RuntimeVerifier withAttribution(AttributionKind kind) {
36-
if (this.attribution == kind) return this;
37-
return new NullnessVerifier(kind);
35+
public CheckGenerator withAttribution(AttributionKind kind) {
36+
return new NullnessCheckGenerator(kind);
3837
}
3938

4039
@Override

checker/src/main/java/io/github/eisop/runtimeframework/checker/nullness/NullnessRuntimeChecker.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package io.github.eisop.runtimeframework.checker.nullness;
22

3-
import io.github.eisop.runtimeframework.core.AnnotationInstrumenter;
3+
import io.github.eisop.runtimeframework.core.EnforcementInstrumenter;
44
import io.github.eisop.runtimeframework.core.RuntimeChecker;
55
import io.github.eisop.runtimeframework.core.RuntimeInstrumenter;
66
import io.github.eisop.runtimeframework.core.TypeSystemConfiguration;
77
import io.github.eisop.runtimeframework.core.ValidationKind;
88
import io.github.eisop.runtimeframework.filter.ClassInfo;
99
import io.github.eisop.runtimeframework.filter.Filter;
10-
import io.github.eisop.runtimeframework.policy.EnforcementPolicy;
10+
import io.github.eisop.runtimeframework.policy.InstrumentationStrategy;
1111
import io.github.eisop.runtimeframework.resolution.BytecodeHierarchyResolver;
1212
import io.github.eisop.runtimeframework.resolution.HierarchyResolver;
1313
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -22,20 +22,20 @@ public String getName() {
2222

2323
@Override
2424
public RuntimeInstrumenter getInstrumenter(Filter<ClassInfo> filter) {
25-
NullnessVerifier verifier = new NullnessVerifier();
25+
NullnessCheckGenerator verifier = new NullnessCheckGenerator();
2626

2727
TypeSystemConfiguration config =
2828
new TypeSystemConfiguration()
2929
.onEnforce(NonNull.class, verifier)
3030
.onNoop(Nullable.class)
3131
.withDefault(ValidationKind.ENFORCE, verifier);
3232

33-
EnforcementPolicy policy = createPolicy(config, filter);
33+
InstrumentationStrategy strategy = createStrategy(config, filter);
3434

3535
HierarchyResolver resolver =
3636
new BytecodeHierarchyResolver(
3737
className -> filter.test(new ClassInfo(className.replace('.', '/'), null, null)));
3838

39-
return new AnnotationInstrumenter(policy, resolver, filter);
39+
return new EnforcementInstrumenter(strategy, resolver, filter);
4040
}
4141
}

framework/src/main/java/io/github/eisop/runtimeframework/agent/RuntimeAgent.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public final class RuntimeAgent {
1414

1515
public static void premain(String args, Instrumentation inst) {
1616
Filter<ClassInfo> safeFilter = new FrameworkSafetyFilter();
17-
Filter<ClassInfo> policyFilter = safeFilter;
17+
Filter<ClassInfo> strategyFilter = safeFilter;
1818

1919
String checkedClasses = System.getProperty("runtime.classes");
2020
boolean isGlobalMode = Boolean.getBoolean("runtime.global");
@@ -23,12 +23,12 @@ public static void premain(String args, Instrumentation inst) {
2323
if (checkedClasses != null && !checkedClasses.isBlank()) {
2424
System.out.println("[RuntimeAgent] Checked Scope restricted to: " + checkedClasses);
2525
Filter<ClassInfo> listFilter = new ClassListFilter(Arrays.asList(checkedClasses.split(",")));
26-
policyFilter = info -> safeFilter.test(info) && listFilter.test(info);
26+
strategyFilter = info -> safeFilter.test(info) && listFilter.test(info);
2727
} else if (trustAnnotatedFor) {
28-
policyFilter = info -> false;
28+
strategyFilter = info -> false;
2929
}
3030

31-
Filter<ClassInfo> scanFilter = policyFilter;
31+
Filter<ClassInfo> scanFilter = strategyFilter;
3232
boolean scanAll = false;
3333

3434
if (trustAnnotatedFor) {
@@ -83,7 +83,8 @@ public static void premain(String args, Instrumentation inst) {
8383
}
8484

8585
inst.addTransformer(
86-
new RuntimeTransformer(scanFilter, policyFilter, checker, trustAnnotatedFor, isGlobalMode),
86+
new RuntimeTransformer(
87+
scanFilter, strategyFilter, checker, trustAnnotatedFor, isGlobalMode),
8788
false);
8889
}
8990
}

framework/src/main/java/io/github/eisop/runtimeframework/agent/RuntimeTransformer.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@
1313
public class RuntimeTransformer implements ClassFileTransformer {
1414

1515
private final Filter<ClassInfo> scanFilter;
16-
private final Filter<ClassInfo> policyFilter;
16+
private final Filter<ClassInfo> strategyFilter;
1717
private final RuntimeChecker checker;
1818
private final boolean trustAnnotatedFor;
1919
private final boolean isGlobalMode;
2020
private final AnnotatedForFilter annotatedForFilter;
2121

2222
public RuntimeTransformer(
2323
Filter<ClassInfo> scanFilter,
24-
Filter<ClassInfo> policyFilter,
24+
Filter<ClassInfo> strategyFilter,
2525
RuntimeChecker checker,
2626
boolean trustAnnotatedFor,
2727
boolean isGlobalMode) {
2828
this.scanFilter = scanFilter;
29-
this.policyFilter = policyFilter;
29+
this.strategyFilter = strategyFilter;
3030
this.checker = checker;
3131
this.trustAnnotatedFor = trustAnnotatedFor;
3232
this.isGlobalMode = isGlobalMode;
@@ -62,7 +62,7 @@ public byte[] transform(
6262
ClassFile cf = ClassFile.of();
6363
ClassModel classModel = cf.parse(classfileBuffer);
6464

65-
boolean isChecked = policyFilter.test(info);
65+
boolean isChecked = strategyFilter.test(info);
6666

6767
if (!isChecked && trustAnnotatedFor && annotatedForFilter != null) {
6868
if (annotatedForFilter.test(classModel, loader)) {
@@ -94,7 +94,7 @@ public byte[] transform(
9494
&& annotatedForFilter.test(effectiveCtx)) {
9595
return true;
9696
}
97-
return policyFilter.test(effectiveCtx);
97+
return strategyFilter.test(effectiveCtx);
9898
};
9999

100100
RuntimeInstrumenter instrumenter = checker.getInstrumenter(dynamicFilter);

0 commit comments

Comments
 (0)