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

Origin/develop/field immutability #3

Open
wants to merge 340 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 250 commits
Commits
Show all changes
340 commits
Select commit Hold shift + click to select a range
31f9f41
dependers are now a java HashSet. split dependers and suppressed depe…
Feb 18, 2020
6ded353
added todos
Feb 18, 2020
a0bfeed
Dependent Immutability improvements
Feb 19, 2020
1105873
updating PropertiesTest to the new status
Feb 19, 2020
9ec9506
updating PropertiesTest to the new status 2
Feb 19, 2020
3295463
updating PropertyStoreKey to the new status
Feb 19, 2020
ed84ec7
updating PropertiesTest to the new status
Feb 19, 2020
5de4582
formatting PropertiesTest
Feb 19, 2020
13600b8
replaced broken pkecpropertystore impl. with the new one
Feb 19, 2020
ca21247
removed dht store
Feb 19, 2020
633e4f4
Merge branch 'develop' into origin/develop/fieldImmutability
Feb 19, 2020
8de7983
Removed @volatile, the locks suffice
errt Feb 21, 2020
87879aa
handling extending generic types
Feb 21, 2020
b444e87
removing workaround for running on jdk
Feb 21, 2020
eff8129
also clear dependees for interim partial results
Feb 27, 2020
05ef76d
Merge branch 'develop' into feature/NewParallelStores
Feb 28, 2020
168bb52
Use multiple queues to avoid contention
errt Feb 28, 2020
a59629b
class immutability analysis optimization
Mar 5, 2020
98ad480
optimization in Field Immutability analysis. The best immutability pr…
Mar 6, 2020
e9fe41c
New Purity Analysis depending on new immutability analyses.
Mar 6, 2020
a90d28a
formatting
Mar 6, 2020
9ea92b8
tests improvements and formatting
Mar 7, 2020
339783a
new immutability tests and optimization
Mar 7, 2020
73d3055
improving test classes
Mar 7, 2020
c0febcf
more efficient hashcode&equals
Mar 9, 2020
230d75c
use better check order
Mar 9, 2020
668d2f7
changed API to use Set for dependees
Mar 9, 2020
87316e6
performance improvements
Mar 9, 2020
5f523e8
minor
Mar 9, 2020
5756d33
used lazy vals for hashcodes and pks
Mar 11, 2020
d5513cb
workstealing and initial queues
Mar 11, 2020
05dac40
avoid double read
Mar 11, 2020
3cac308
don’t use Integer.compareTo
Mar 11, 2020
5ae7b92
minor improvements
Mar 11, 2020
dab1fcd
wip
Mar 11, 2020
5b02ccf
Revise Demos for evaluation purpose
Mar 14, 2020
6386f8f
revise tests
Mar 14, 2020
d3f2a18
bug fixing in class imm analysis
Mar 14, 2020
dd957b2
removing unnecessary import
Mar 18, 2020
73bf290
analyze online project files
Mar 18, 2020
d5b2974
improvements: hardcoding deep immutability of String, handling of arr…
Mar 18, 2020
e6b401b
improvement: of class and interface separation, and filtering of muta…
Mar 18, 2020
6e27b90
New test-cases for fields with strings and arrays
Mar 18, 2020
f9b2c55
Improving and Bug Fixing
Mar 21, 2020
ce8de7b
extending Field with the property is synthetic (isSyn)
Mar 25, 2020
ac8f417
improving demos and test for evaluation
Mar 25, 2020
fc7384f
improvements and fixing of the missing case in class imm analysis of …
Mar 25, 2020
0578452
correction
Mar 26, 2020
b16d051
Use thread local evaluation up to MaxEvaluationDepth
errt May 7, 2020
37b60c9
Set thread count on PKECPropertyStore
errt May 7, 2020
c875b31
Clean up task managers
errt May 7, 2020
f2856d8
Fixing some minor problems
errt May 7, 2020
7a08da4
Fixed test suite, tests still failing, though
errt May 7, 2020
95c2156
Propagate final updates under suppression
errt May 8, 2020
41cd2a7
Merge branch 'develop' into feature/NewParallelStores
errt May 8, 2020
4347038
Minor improvements/fixes
errt May 11, 2020
5936e5e
More extensive testing
errt May 11, 2020
715d567
Formatting & ScalaDoc
errt May 11, 2020
2b8e7d3
Prevent threads from terminating while there are initial tasks
errt May 13, 2020
49c0e95
Merge branch 'develop' into origin/develop/fieldImmutability
Jun 3, 2020
ab806b5
first try to solve lazy initialization test errors: by reading all fi…
Jun 5, 2020
f797096
second try to solve lazy initialization test errors: reverting the re…
Jun 5, 2020
5f96b02
Adding LazyL0FieldImmutabilityAnalysis
Jun 5, 2020
d985cd6
test 3: for finding test errors
Jun 8, 2020
6b35b74
sandbox test 1 for finding test errors
Jun 9, 2020
77ebc32
eff deep imm fields introduction; still with debugging printlns
Jun 22, 2020
96092d9
format correction
Jun 23, 2020
be179c0
adapt the imports in demos to the new analysis location
Jun 23, 2020
5f314db
format + ref conf correction
Jun 23, 2020
2791a36
Test
Jun 23, 2020
2387fdb
revert Test
Jun 23, 2020
ed032f5
inserting printlns for debugging purpose
Jun 24, 2020
de498a9
inserting linebreak; trying to solve formatting issue
Jun 24, 2020
11fb3a0
optimized running analyses
Jun 24, 2020
35e75f0
inserted printlns for debugging purpose
Jun 24, 2020
2a9a21c
first attempt for double checked locking. Works with the provided tes…
Jun 25, 2020
fa0e345
inserting printlns for debugging purposes
Jun 25, 2020
685f28e
adjusting correct rater
Jun 26, 2020
ddc59ef
revise dcl recognition with domtree, and tests
Jun 30, 2020
f23bfb6
inserting printlns for debugging purposes
Jun 30, 2020
0e4a335
inserting printlns for debugging purposes
Jul 1, 2020
7c01ad0
inserting printlns for debugging purposes
Jul 1, 2020
612dcc6
inserting printlns for debugging purposes
Jul 1, 2020
8994dee
inserting printlns for debugging purposes
Jul 1, 2020
9399d39
set purity analysis rater
Jul 1, 2020
8998b04
import issue
Jul 1, 2020
2f29b59
run all imm tests
Jul 1, 2020
f8d9934
inserting printlns for debugging purposes in rta call graph analysis
Jul 3, 2020
919d5b3
inserting printlns for debugging purposes, revise
Jul 3, 2020
ad8a054
inserting printlns for debugging purposes
Jul 3, 2020
8c21add
inserting printlns for debugging purposes, revise
Jul 3, 2020
670692e
inserting printlns for debugging purposes, revise
Jul 3, 2020
681dabf
inserting printlns for debugging purposes,revise
Jul 3, 2020
6de092f
inserting printlns for debugging purposes
Jul 3, 2020
f03a58f
inserting exception for debugging purposes
Jul 3, 2020
60b3f52
compiling tests on github before run
Jul 3, 2020
b28ffbf
inserting printlns java version for debugging purposes
Jul 3, 2020
3f0a35a
inserting printlns for debugging purposes
Jul 3, 2020
3f5e20d
inserting println target
Jul 3, 2020
0fc4cf9
println return all methods
Jul 3, 2020
0a9cdfb
inserting printlns for printing body of init for debugging purposes
Jul 3, 2020
efa1e12
removing printlns from call graph analysis
Jul 9, 2020
477101c
extending reference immutability properties for different lazy initia…
Jul 9, 2020
39d8e02
removing printlns from old purity analysis
Jul 9, 2020
1a54a31
removing printlns from the new purity analysis and extending the anal…
Jul 9, 2020
7261eda
removing old first lazy initialization analysis try
Jul 9, 2020
9df1c1f
Reference Imm Analysis without printlns and extended for lazy initali…
Jul 9, 2020
3f73b12
adapt tests and demos for new ref imm properties
Jul 9, 2020
8c9f22b
field imm analysis without prinltns, adapted to the new ref imm li pr…
Jul 9, 2020
553f6e8
annotations for new li ref imm properties
Jul 9, 2020
a92916d
dcl combination and performance optimization of eff deep imm fields r…
Jul 14, 2020
037eaa5
tests revise
Jul 14, 2020
ddecfec
new dcl tests
Jul 14, 2020
95491e9
updating running analyses list
roterEmil Jul 14, 2020
fb668c8
revise imports
roterEmil Jul 14, 2020
b89d41c
performance optimizations
roterEmil Jul 17, 2020
6fc7a41
revise iterator handling => failed test correction
roterEmil Jul 20, 2020
209a3e4
iterator handling revise 2
roterEmil Jul 20, 2020
aef3171
using iterators
roterEmil Jul 21, 2020
0c14294
imm evaluation tool
roterEmil Jul 21, 2020
f6a5553
wip: reference imm without eff immutability checking
roterEmil Jul 27, 2020
beaa78e
wip field imm analysis with eff imm checking. 12 failing tests left.
roterEmil Jul 27, 2020
dfa3119
Revert "compiling tests on github before run"
roterEmil Jul 28, 2020
26eb303
revert changes
roterEmil Jul 28, 2020
743272f
revert changes
roterEmil Jul 28, 2020
83d6f74
revert changes
roterEmil Jul 28, 2020
5fdd758
revert changes
roterEmil Jul 28, 2020
78c462d
unnecessary
roterEmil Jul 28, 2020
d6aadae
removing the unnecessary demos. The ones using the purity analysis wi…
roterEmil Jul 28, 2020
5d0741a
delete the old tests. The ones using the new purity analysis (that us…
roterEmil Jul 29, 2020
642dd22
removed the escapes property from the immutable reference property
roterEmil Jul 29, 2020
7e2941b
revert changes
roterEmil Jul 29, 2020
ac769a9
revert changes
roterEmil Jul 29, 2020
f04c7f1
revert changes
roterEmil Jul 29, 2020
ca0fd75
revert changes
roterEmil Jul 29, 2020
a314b03
revert changes
roterEmil Jul 29, 2020
6e72a27
revert changes
roterEmil Jul 29, 2020
d41ce8a
revert changes
roterEmil Jul 29, 2020
738344f
revert changes
roterEmil Jul 29, 2020
8725f5a
revert changes
roterEmil Jul 29, 2020
f698a4e
revert changes
roterEmil Jul 29, 2020
2e0afde
revert changes
roterEmil Jul 29, 2020
d332038
corrected the naming of a property
roterEmil Jul 29, 2020
b903a0e
current status, still WIP
roterEmil Jul 29, 2020
1f587de
adapt the purity analysis to the immutable reference property change
roterEmil Jul 29, 2020
17b0b78
current status, still WIP
roterEmil Jul 29, 2020
63720a4
rearrange tests
roterEmil Jul 29, 2020
d0070e9
rearranging tests
roterEmil Jul 29, 2020
196d00f
rearranging tests
roterEmil Jul 29, 2020
37d668a
rearranging tests
roterEmil Jul 29, 2020
8581e32
rearranging tests
roterEmil Jul 29, 2020
b7fe248
revert immutable reference property changes
roterEmil Jul 29, 2020
d774349
current status, still WIP
roterEmil Jul 29, 2020
36ee2ef
current status, still WIP
roterEmil Jul 31, 2020
2ad80a0
current status, still WIP
roterEmil Jul 31, 2020
b972fec
current status, still WIP, code not fully revised, one test remaining
roterEmil Aug 7, 2020
c60745f
revised array handling, still wip. Not fully reviewed yet
roterEmil Aug 17, 2020
35b1cd6
extending with is-properties
roterEmil Aug 19, 2020
39699a3
begin of revise, still wip
roterEmil Aug 19, 2020
bc99756
revised and added tests
roterEmil Aug 19, 2020
e69dd22
renaming of classes for compatibility purposes
roterEmil Aug 20, 2020
37e4fc5
revised, still wip
roterEmil Aug 26, 2020
e105acf
revised tests
roterEmil Aug 26, 2020
471533e
running on all fields
roterEmil Aug 31, 2020
2ea6b9b
revised logic and time consumption, still wip
roterEmil Aug 31, 2020
fb9554e
added guards for correct property handling
roterEmil Aug 31, 2020
b515417
set closed package key and type extensibility key conservatively befo…
roterEmil Aug 31, 2020
d9b16d1
added concrete type immutability determination in cases where we know…
roterEmil Sep 10, 2020
c00faba
added lazy initialization handling for the case of a guard with mutli…
roterEmil Sep 10, 2020
9248b28
added multiple information in the test output like the amount of clas…
roterEmil Sep 10, 2020
61462d3
added more test cases
roterEmil Sep 10, 2020
acd0d78
undo formatting changes
roterEmil Sep 16, 2020
9e0491b
Fix indentation
roterEmil Sep 16, 2020
3d7954b
removed comment and fixed package declaration
roterEmil Sep 16, 2020
c3ec8f5
fixed grammar
roterEmil Sep 16, 2020
9176e15
undo changes
roterEmil Sep 16, 2020
e02fe35
fixed formatting and packages, optimized functions
roterEmil Sep 16, 2020
5fa974e
optimized functions, formatting and added comments
roterEmil Sep 16, 2020
4acc306
changed license
roterEmil Sep 16, 2020
49101b1
formatting
roterEmil Sep 16, 2020
742dbbc
revised, still wip
roterEmil Sep 16, 2020
ce575ff
revised, still wip
roterEmil Sep 16, 2020
529e441
revised, still wip
roterEmil Sep 16, 2020
a5537eb
formatting
roterEmil Sep 16, 2020
e03bdd6
revised, still wip
roterEmil Sep 16, 2020
51d07ad
renaming
roterEmil Sep 17, 2020
0a636c8
revised, still wip
roterEmil Sep 17, 2020
f5c4edb
integrate class immutability analyses and adapt all of them to the ne…
roterEmil Sep 24, 2020
440d9d7
integrate type Immutability analyses and adapt all of them to the new…
roterEmil Sep 24, 2020
9097265
integrate field immutability analyses and adapt all of them to the ne…
roterEmil Sep 24, 2020
c04c350
adapt purity analyses to the new immutability analysis and lattice
roterEmil Sep 24, 2020
88783c0
renew the property annotations for the test fixtures
roterEmil Sep 24, 2020
1d3312e
general immutability adjustments
roterEmil Sep 24, 2020
6fe0dd0
adapting the tests to the uniform immutability analyses
roterEmil Sep 24, 2020
06fc7d0
remove comments
roterEmil Sep 24, 2020
41e0b8e
revise
roterEmil Sep 28, 2020
c159db5
revise
roterEmil Sep 28, 2020
af4c234
remove commented out code
roterEmil Sep 28, 2020
932acaa
revised, still wip
roterEmil Oct 7, 2020
58e4b8b
renamed
roterEmil Oct 7, 2020
03b3003
correction
roterEmil Oct 7, 2020
281349b
revised, still wip
roterEmil Oct 9, 2020
aedaa5c
revised, still wip
roterEmil Oct 13, 2020
d6f1a45
revised, still wip
roterEmil Oct 16, 2020
66d5751
reformatted
roterEmil Oct 20, 2020
0d8f69b
revised, still wip
roterEmil Oct 22, 2020
14412f7
revised, still wip
roterEmil Oct 23, 2020
c8f8ac0
replaced deprecated property
roterEmil Oct 26, 2020
dac5962
conversion and renaming; still wip
roterEmil Oct 26, 2020
ea994eb
conversion and renaming; still wip
roterEmil Oct 26, 2020
d17c669
conversion and renaming; still wip
roterEmil Oct 26, 2020
8c273f2
removed println
roterEmil Oct 26, 2020
8e6616d
revised; still wip
roterEmil Oct 26, 2020
a25e715
revised; still wip
roterEmil Oct 26, 2020
fd598d6
optimizing comments if->whether
roterEmil Oct 26, 2020
3a29508
wip
roterEmil Nov 6, 2020
1abcf13
Merge branch 'feature/NewParallelStores' of https://github.com/stg-tu…
roterEmil Nov 6, 2020
e311dec
Avoid double notification of final results for non-suppressed PKs
errt Nov 9, 2020
3335d53
Improved contains check
errt Nov 9, 2020
977dd17
Merge branch 'feature/NewParallelStores' of https://github.com/stg-tu…
roterEmil Nov 9, 2020
3403667
using set for the new parallel store and formatting
roterEmil Dec 1, 2020
ab46ab8
using set for the new parallel store
roterEmil Dec 1, 2020
7824d57
revised; still wip
roterEmil Dec 1, 2020
ef6888b
fixing several bugs and optimization
roterEmil Dec 11, 2020
52e192f
fixing order of settings and first project call and optimization
roterEmil Dec 11, 2020
a6873fe
extending for new immutability analysis
roterEmil Dec 11, 2020
27ca712
enable all analysis tests
roterEmil Dec 11, 2020
e1bff23
fixing fake entity bug
roterEmil Dec 11, 2020
5795b36
formatting
roterEmil Dec 14, 2020
914a272
adjustment; nested generic classes seen as shaddow immutable.
roterEmil Dec 14, 2020
3d8dcce
changed reimInfer comparison. Now filters out synthetic fields and enums
roterEmil Dec 22, 2020
0afd811
removed reiminfer comparison
roterEmil Feb 11, 2021
7f1866a
removed escape setting possibility
roterEmil Feb 11, 2021
f1ca918
removed escape considering due to unsoundness
roterEmil Feb 15, 2021
8b2339c
adjust field reference imm analysis for evaluation. Removed: LazyInit…
roterEmil Feb 16, 2021
14ff435
ommitted analyzing native methods
roterEmil Feb 16, 2021
492e24a
outcommented unused values
roterEmil Feb 16, 2021
7d30ca6
outcomment unused values
roterEmil Feb 16, 2021
457f3ce
first sketch of immutability benchmark; glacier annotation is comment…
roterEmil Mar 8, 2021
1f72cce
first sketch of concrete "class type is known" recognition. Still wip…
roterEmil Mar 8, 2021
165e4a3
current status of immutability benchmark
roterEmil Mar 12, 2021
fef638b
current status of immutability tests
roterEmil Mar 12, 2021
501ac1d
temp tests
roterEmil Mar 12, 2021
e0f2638
new application config file
roterEmil Mar 12, 2021
bd023fd
new immutability benchmark test runner
roterEmil Mar 12, 2021
b8c2f09
purity runner customized for comparison
roterEmil Mar 12, 2021
8b44a0f
added recognition of known class type
roterEmil Mar 12, 2021
f53e375
current status of immutability demos
roterEmil Mar 12, 2021
ee87221
current status of field reference immutability analysis; still wip; t…
roterEmil Mar 12, 2021
defa4bb
temporary config file
roterEmil Mar 12, 2021
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
@@ -0,0 +1,168 @@
/* BSD 2-Clause License - see OPAL/LICENSE for details. */
package org.opalj
package fpcf
package analyses

import java.io.BufferedWriter
import java.io.File
import java.io.FileWriter
import java.net.URL
import java.util.Calendar

import org.opalj.br.ObjectType
import org.opalj.tac.fpcf.analyses.purity.LazyL2PurityAnalysis
import org.opalj.br.analyses.BasicReport
import org.opalj.br.analyses.Project
import org.opalj.br.analyses.ProjectAnalysisApplication
import org.opalj.br.fpcf.FPCFAnalysesManagerKey
import org.opalj.br.fpcf.analyses.LazyL0CompileTimeConstancyAnalysis
import org.opalj.br.fpcf.analyses.LazyStaticDataUsageAnalysis
import org.opalj.br.fpcf.analyses.LazyUnsoundPrematurelyReadFieldsAnalysis
import org.opalj.br.fpcf.properties.DeepImmutableClass
import org.opalj.br.fpcf.properties.DependentImmutableClass
import org.opalj.br.fpcf.properties.MutableClass
import org.opalj.br.fpcf.properties.ShallowImmutableClass
import org.opalj.tac.cg.RTACallGraphKey
import org.opalj.tac.fpcf.analyses.escape.LazyInterProceduralEscapeAnalysis
import org.opalj.tac.fpcf.analyses.immutability.EagerL1ClassImmutabilityAnalysis
import org.opalj.tac.fpcf.analyses.immutability.LazyL3FieldImmutabilityAnalysis
import org.opalj.tac.fpcf.analyses.immutability.LazyL1TypeImmutabilityAnalysis
import org.opalj.tac.fpcf.analyses.immutability.fieldreference.LazyL0FieldReferenceImmutabilityAnalysis
import org.opalj.util.PerformanceEvaluation.time
import org.opalj.util.Seconds
import java.io.IOException
import org.opalj.br.fpcf.properties.ClassImmutability
import org.opalj.tac.fpcf.analyses.LazyFieldLocalityAnalysis
import org.opalj.tac.fpcf.analyses.escape.LazyReturnValueFreshnessAnalysis

/**
* Runs the EagerL1ClassImmutabilityAnalysis as well as analyses needed for improving the result.
*
* @author Tobias Roth
*/
object ClassImmutabilityAnalysisDemo extends ProjectAnalysisApplication {

override def title: String = "determines the immutability of classes"

override def description: String = "identifies classes that are immutable in a shallow or deep way"

override def doAnalyze(
project: Project[URL],
parameters: Seq[String],
isInterrupted: () ⇒ Boolean
): BasicReport = {
val result = analyze(project)
BasicReport(result)
}

def analyze(project: Project[URL]): String = {

var propertyStore: PropertyStore = null
var analysisTime: Seconds = Seconds.None
val analysesManager = project.get(FPCFAnalysesManagerKey)
analysesManager.project.get(RTACallGraphKey)

time {
propertyStore = analysesManager
.runAll(
LazyUnsoundPrematurelyReadFieldsAnalysis,
LazyL2PurityAnalysis,
LazyL0FieldReferenceImmutabilityAnalysis,
LazyL3FieldImmutabilityAnalysis,
LazyL1TypeImmutabilityAnalysis,
EagerL1ClassImmutabilityAnalysis,
LazyStaticDataUsageAnalysis,
LazyL0CompileTimeConstancyAnalysis,
LazyInterProceduralEscapeAnalysis,
LazyReturnValueFreshnessAnalysis,
LazyFieldLocalityAnalysis
)
._1
roterEmil marked this conversation as resolved.
Show resolved Hide resolved

propertyStore.waitOnPhaseCompletion()

} { t ⇒
analysisTime = t.toSeconds
}

val allProjectClassTypes = project.allProjectClassFiles.map(_.thisType).toSet

val groupedResults = propertyStore.entities(ClassImmutability.key).
filter(x ⇒ allProjectClassTypes.contains(x.asInstanceOf[ObjectType])).toTraversable.groupBy(_.e)

val order = (eps1: EPS[Entity, ClassImmutability], eps2: EPS[Entity, ClassImmutability]) ⇒
eps1.e.toString < eps2.e.toString

val mutableClasses =
groupedResults(MutableClass).toSeq.sortWith(order)

val shallowImmutableClasses =
groupedResults(ShallowImmutableClass).toSeq.sortWith(order)

val dependentImmutableClasses =
groupedResults(DependentImmutableClass).toSeq.sortWith(order)

val deepImmutables = groupedResults(DeepImmutableClass).toSeq.sortWith(order)

val allInterfaces =
project.allProjectClassFiles.filter(_.isInterfaceDeclaration).map(_.thisType).toSet

val deepImmutableClassesInterfaces = deepImmutables
.filter(eps ⇒ allInterfaces.contains(eps.asInstanceOf[ObjectType])).sortWith(order)

val deepImmutableClasses =
deepImmutables
.filter(eps ⇒ !allInterfaces.contains(eps.asInstanceOf[ObjectType])).sortWith(order)

val output =
s"""
| Mutable Classes:
| ${mutableClasses.mkString(" | Mutable Class\n")}
|
| Shallow Immutable Classes:
| ${shallowImmutableClasses.mkString(" | Shallow Immutable Class\n")}
|
| Dependent Immutable Classes:
| ${dependentImmutableClasses.mkString(" | Dependent Immutable Class\n")}
|
| Deep Immutable Classes:
| ${deepImmutableClasses.mkString(" | Deep Immutable Classes\n")}
|
| Deep Immutable Class Interfaces:
| ${deepImmutableClassesInterfaces.mkString(" | Deep Immutable Classes Interfaces\n")}
|
|
| Mutable Classes: ${mutableClasses.size}
| Shallow Immutable Classes: ${shallowImmutableClasses.size}
| Dependent Immutable Classes: ${dependentImmutableClasses.size}
| Deep Immutable Classes: ${deepImmutableClasses.size}
| Deep Immutable Classes Interfaces: ${deepImmutableClassesInterfaces.size}
| Deep Immutables: ${deepImmutables.size}
|
| sum: ${
mutableClasses.size + shallowImmutableClasses.size + dependentImmutableClasses.size +
deepImmutableClasses.size + deepImmutableClassesInterfaces.size
}
| analysis took : $analysisTime seconds
|"""".stripMargin

val file = new File(s"${Calendar.getInstance().formatted("dd_MM_yyyy_hh_mm_ss")}.txt")

val bw = new BufferedWriter(new FileWriter(file))

try {
bw.write(output)
bw.close()
} catch {
case e: IOException ⇒ println(
s""" Could not write file: ${file.getName}
| ${e.getMessage}
|""".stripMargin
)
} finally {
bw.close()
}

output
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/* BSD 2-Clause License - see OPAL/LICENSE for details. */
package org.opalj
package fpcf
package analyses

import java.net.URL
import java.io.BufferedWriter
import java.io.File
import java.io.FileWriter
import java.util.Calendar
import java.io.IOException

import org.opalj.br.Field
import org.opalj.br.analyses.BasicReport
import org.opalj.br.analyses.Project
import org.opalj.br.analyses.ProjectAnalysisApplication
import org.opalj.br.fpcf.FPCFAnalysesManagerKey
import org.opalj.br.fpcf.analyses.LazyL0CompileTimeConstancyAnalysis
import org.opalj.br.fpcf.analyses.LazyStaticDataUsageAnalysis
import org.opalj.br.fpcf.analyses.LazyUnsoundPrematurelyReadFieldsAnalysis
import org.opalj.br.fpcf.properties.DeepImmutableField
import org.opalj.br.fpcf.properties.DependentImmutableField
import org.opalj.br.fpcf.properties.MutableField
import org.opalj.br.fpcf.properties.ShallowImmutableField
import org.opalj.tac.cg.RTACallGraphKey
import org.opalj.tac.fpcf.analyses.LazyFieldLocalityAnalysis
import org.opalj.tac.fpcf.analyses.escape.LazyInterProceduralEscapeAnalysis
import org.opalj.tac.fpcf.analyses.escape.LazyReturnValueFreshnessAnalysis
import org.opalj.tac.fpcf.analyses.immutability.EagerL3FieldImmutabilityAnalysis
import org.opalj.tac.fpcf.analyses.immutability.LazyL1ClassImmutabilityAnalysis
import org.opalj.tac.fpcf.analyses.immutability.LazyL1TypeImmutabilityAnalysis
import org.opalj.tac.fpcf.analyses.immutability.fieldreference.LazyL0FieldReferenceImmutabilityAnalysis
import org.opalj.tac.fpcf.analyses.purity.LazyL2PurityAnalysis
import org.opalj.util.PerformanceEvaluation.time
import org.opalj.util.Seconds
import org.opalj.br.fpcf.properties.FieldImmutability

/**
* Runs the EagerL0FieldImmutabilityAnalysis including all analyses needed for improving the result.
*
* @author Tobias Peter Roth
*/
object FieldImmutabilityAnalysisDemo extends ProjectAnalysisApplication {

override def title: String = "determines the immutability of (instance/static) fields"

override def description: String =
"identifies fields that are immutable in a deep or shallow way"

override def doAnalyze(
project: Project[URL],
parameters: Seq[String],
isInterrupted: () ⇒ Boolean
): BasicReport = {
val result = analyze(project)
BasicReport(result)
}

def analyze(project: Project[URL]): String = {

var propertyStore: PropertyStore = null
var analysisTime: Seconds = Seconds.None
val analysesManager = project.get(FPCFAnalysesManagerKey)
analysesManager.project.get(RTACallGraphKey)
time {
propertyStore = analysesManager
.runAll(
LazyL0FieldReferenceImmutabilityAnalysis,
LazyUnsoundPrematurelyReadFieldsAnalysis,
LazyL2PurityAnalysis,
EagerL3FieldImmutabilityAnalysis,
LazyL1ClassImmutabilityAnalysis,
LazyL1TypeImmutabilityAnalysis,
LazyStaticDataUsageAnalysis,
LazyL0CompileTimeConstancyAnalysis,
LazyInterProceduralEscapeAnalysis,
LazyReturnValueFreshnessAnalysis,
LazyFieldLocalityAnalysis
)
._1
propertyStore.waitOnPhaseCompletion();
} { t ⇒
analysisTime = t.toSeconds
}

val allFieldsInProjectClassFiles = project.allProjectClassFiles.toIterator.flatMap { _.fields }.toSet

val groupedResults = propertyStore.entities(FieldImmutability.key).
filter(field ⇒ allFieldsInProjectClassFiles.contains(field.asInstanceOf[Field])).
toTraversable.groupBy(_.toFinalEP.p)

val order = (eps1: EPS[Entity, FieldImmutability], eps2: EPS[Entity, FieldImmutability]) ⇒
eps1.e.toString < eps2.e.toString
val mutableFields = groupedResults(MutableField).toSeq.sortWith(order)
val shallowImmutableFields = groupedResults(ShallowImmutableField).toSeq.sortWith(order)
val dependentImmutableFields = groupedResults(DependentImmutableField).toSeq.sortWith(order)
val deepImmutableFields = groupedResults(DeepImmutableField).toSeq.sortWith(order)

val output =
s"""
| Mutable Fields:
| ${mutableFields.mkString(" | Mutable Field \n")}
|
| Shallow Immutable Fields:
| ${shallowImmutableFields.mkString(" | Shallow Immutable Field \n")}
|
| Dependent Immutable Fields:
| ${dependentImmutableFields.mkString(" | Dependent Immutable Field\n")}
|
| Deep Immutable Fields:
| ${deepImmutableFields.mkString(" | Deep Immutable Field\n")}
|
|
| Mutable Fields: ${mutableFields.size}
| Shallow Immutable Fields: ${shallowImmutableFields.size}
| Dependent Immutable Fields: ${dependentImmutableFields.size}
| Deep Immutable Fields: ${deepImmutableFields.size}
|
| sum: ${
mutableFields.size + shallowImmutableFields.size +
dependentImmutableFields.size + deepImmutableFields.size
}
|
| took : $analysisTime seconds
|""".stripMargin

val file = new File(s"${Calendar.getInstance().formatted("dd_MM_yyyy_hh_mm_ss")}.txt")

val bw = new BufferedWriter(new FileWriter(file))

try {
bw.write(output)
bw.close()
} catch {
case e: IOException ⇒ println(
s""" Could not write file: ${file.getName}
| ${e.getMessage}
|""".stripMargin
)
} finally {
bw.close()
}

output
}
}
Loading