KAnnotator : Inferring Type Information from Java Byte Codes

Embed Size (px)

DESCRIPTION

KAnnotator : Inferring Type Information from Java Byte Codes. Alexey Sedunov Andrey Breslav Svetlana Isakova Evgeny Gerashchenko. JetBrains , s. r. o. 2013. Annotation Inference. Several languages on the Java platform refine Java type system to ensure program safety at compile-time - PowerPoint PPT Presentation

Text of KAnnotator : Inferring Type Information from Java Byte Codes

Kannotator: Inferring Type Information from Java Bytecode

KAnnotator: Inferring Type Information from Java Byte CodesAlexey SedunovAndrey BreslavSvetlana IsakovaEvgeny GerashchenkoJetBrains, s. r. o.2013

Annotation InferenceSeveral languages on the Java platform refine Java type system to ensure program safety at compile-timeKotlin: nullable/non-nullable typesIn practice interoperability with existing Java code requires developers to provide missing type information, e.g. in a form of annotations.KAnnotator is a tool which automatically infers type annotations for a given set of classes (libraries) based on their bytecode2KAnnotator FeaturesAnnotation inference based on the bytecode of library classes@Nullable/@NotNull@MutableSupport of predefined annotationsInternal vs. external annotationsVerification modeExtensible context-insensitive inference engineOpen-sourcehttps://github.com/jetbrains/kannotator 3ComparisonJuliahttp://julia.scienze.univr.it/general frameworkmore preciselonger runtimeJQualhttp://www.cs.umd.edu/projects/PL/jqual/general frameworkmore precise mutabilityAST-driven NIThttp://nit.gforge.inria.fr/sound theorymore precise treatment of fieldsspecializedlonger runtime

4Inference Process Overview5Load predefined annotationsPropagate annotationsApply inference to dependency graphConstruct dependency & inheritance graphsLoad class filesProcess conflictsBytecode Inference EngineInference engine is based on the ObjectWeb 2 ASM data-flow analysis frameworkCompatible with ASM bytecode representationDoes not require explicit construction of CFGAnalyzer iterates over execution paths until all frames are stabilizedImprovements to the ASM analyzer:Pseudo-errors corresponding to possible abnormal terminationsDetection of unreachable pathsAnalysis-specific frame transformers

6Mutability: Motivation7

Mutability: Mutating Invocations void copy(@ReadOnly Collection from, @Mutable Collection to) { for (T fromElement : from) { //mutating invocation to.add(fromElement); }}8Mutability: Propagating Invocations void removeFirst(@Mutable Iterable a) { //mutability propagating invocation Iterator it = a.iterator(); if (it.hasNext()) { it.remove(); }}9Nullability: Motivationfun sort( a: Collection?):List?10 List sort(Collection a) { List list = new ArrayList(a); Collections.sort(list); return list;}JAVAKOTLINfun sort( a: Collection):ListNo type informationNullability: Annotation Criteria11@NullableNull does not reach ANY error nodeNull or Not Null reach SOME return node@NotNullNull does not reach ANY return nodeNull reaches SOME error nodeNo Null is lostUNKNOWNNullability: @Nullablevoid foo1(@Nullable String s) {if (s == null) return; bar(s); // null reaches return}12void foo2(@Nullable String s) { if (s == null) s = "empty"; bar(s); // not-null reaches return}Nullability: @NotNullvoid foo3(@NotNull String s) { if (s == null) { throw new RuntimeException(); } bar(s);}13void foo4(@NotNull String s) { if (s.isEmpty()) return; bar(s);}

Nullability: Unknownvoid foo5(String s) { if (check(s)) { throw new RuntimeException(); } if (s == null) { s = "empty"; } bar(s);}14StatisticsSize(MB)Number of methodsTime(Preprocess/Analyze)

@NotNull/@Mutable(%)OW2 ASM 4.00.31660