Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
@@ -1,13 +1,13 @@
package io.github.eisop.runtimeframework.checker.nullness;

import io.github.eisop.runtimeframework.core.RuntimeVerifier;
import io.github.eisop.runtimeframework.core.CheckGenerator;
import io.github.eisop.runtimeframework.runtime.AttributionKind;
import java.lang.classfile.CodeBuilder;
import java.lang.classfile.TypeKind;
import java.lang.constant.ClassDesc;
import java.lang.constant.MethodTypeDesc;

public class NullnessVerifier implements RuntimeVerifier {
public class NullnessCheckGenerator implements CheckGenerator {

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

private final AttributionKind attribution;

public NullnessVerifier() {
public NullnessCheckGenerator() {
this(AttributionKind.LOCAL);
}

public NullnessVerifier(AttributionKind attribution) {
public NullnessCheckGenerator(AttributionKind attribution) {
this.attribution = attribution;
}

@Override
public RuntimeVerifier withAttribution(AttributionKind kind) {
if (this.attribution == kind) return this;
return new NullnessVerifier(kind);
public CheckGenerator withAttribution(AttributionKind kind) {
return new NullnessCheckGenerator(kind);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package io.github.eisop.runtimeframework.checker.nullness;

import io.github.eisop.runtimeframework.core.AnnotationInstrumenter;
import io.github.eisop.runtimeframework.core.EnforcementInstrumenter;
import io.github.eisop.runtimeframework.core.RuntimeChecker;
import io.github.eisop.runtimeframework.core.RuntimeInstrumenter;
import io.github.eisop.runtimeframework.core.TypeSystemConfiguration;
import io.github.eisop.runtimeframework.core.ValidationKind;
import io.github.eisop.runtimeframework.filter.ClassInfo;
import io.github.eisop.runtimeframework.filter.Filter;
import io.github.eisop.runtimeframework.policy.EnforcementPolicy;
import io.github.eisop.runtimeframework.policy.InstrumentationStrategy;
import io.github.eisop.runtimeframework.resolution.BytecodeHierarchyResolver;
import io.github.eisop.runtimeframework.resolution.HierarchyResolver;
import org.checkerframework.checker.nullness.qual.NonNull;
Expand All @@ -22,20 +22,20 @@ public String getName() {

@Override
public RuntimeInstrumenter getInstrumenter(Filter<ClassInfo> filter) {
NullnessVerifier verifier = new NullnessVerifier();
NullnessCheckGenerator verifier = new NullnessCheckGenerator();

TypeSystemConfiguration config =
new TypeSystemConfiguration()
.onEnforce(NonNull.class, verifier)
.onNoop(Nullable.class)
.withDefault(ValidationKind.ENFORCE, verifier);

EnforcementPolicy policy = createPolicy(config, filter);
InstrumentationStrategy strategy = createStrategy(config, filter);

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

return new AnnotationInstrumenter(policy, resolver, filter);
return new EnforcementInstrumenter(strategy, resolver, filter);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public final class RuntimeAgent {

public static void premain(String args, Instrumentation inst) {
Filter<ClassInfo> safeFilter = new FrameworkSafetyFilter();
Filter<ClassInfo> policyFilter = safeFilter;
Filter<ClassInfo> strategyFilter = safeFilter;

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

Filter<ClassInfo> scanFilter = policyFilter;
Filter<ClassInfo> scanFilter = strategyFilter;
boolean scanAll = false;

if (trustAnnotatedFor) {
Expand Down Expand Up @@ -83,7 +83,8 @@ public static void premain(String args, Instrumentation inst) {
}

inst.addTransformer(
new RuntimeTransformer(scanFilter, policyFilter, checker, trustAnnotatedFor, isGlobalMode),
new RuntimeTransformer(
scanFilter, strategyFilter, checker, trustAnnotatedFor, isGlobalMode),
false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@
public class RuntimeTransformer implements ClassFileTransformer {

private final Filter<ClassInfo> scanFilter;
private final Filter<ClassInfo> policyFilter;
private final Filter<ClassInfo> strategyFilter;
private final RuntimeChecker checker;
private final boolean trustAnnotatedFor;
private final boolean isGlobalMode;
private final AnnotatedForFilter annotatedForFilter;

public RuntimeTransformer(
Filter<ClassInfo> scanFilter,
Filter<ClassInfo> policyFilter,
Filter<ClassInfo> strategyFilter,
RuntimeChecker checker,
boolean trustAnnotatedFor,
boolean isGlobalMode) {
this.scanFilter = scanFilter;
this.policyFilter = policyFilter;
this.strategyFilter = strategyFilter;
this.checker = checker;
this.trustAnnotatedFor = trustAnnotatedFor;
this.isGlobalMode = isGlobalMode;
Expand Down Expand Up @@ -62,7 +62,7 @@ public byte[] transform(
ClassFile cf = ClassFile.of();
ClassModel classModel = cf.parse(classfileBuffer);

boolean isChecked = policyFilter.test(info);
boolean isChecked = strategyFilter.test(info);

if (!isChecked && trustAnnotatedFor && annotatedForFilter != null) {
if (annotatedForFilter.test(classModel, loader)) {
Expand Down Expand Up @@ -94,7 +94,7 @@ public byte[] transform(
&& annotatedForFilter.test(effectiveCtx)) {
return true;
}
return policyFilter.test(effectiveCtx);
return strategyFilter.test(effectiveCtx);
};

RuntimeInstrumenter instrumenter = checker.getInstrumenter(dynamicFilter);
Expand Down
Loading
Loading