Commit Graph

202 Commits

Author SHA1 Message Date
Erik Derr ee13713c4d Impl of IMethod.is(Wala)Synthetic and IClass.isSynthetic (#359)
* Impl of IMethod isSynthetic and isWalaSynthetic

So far IMethod.isSynthetic referred to WALA-generated helper functions
and there was no equivalent to check whether an IMethod is synthetic in
terms of compiler-generated.

To make naming consistent this patch first renames the isSynthetic to
isWalaSynthetic to clearly indicate that a given IMethod was generated
by WALA. Then, we re-introduce isSynthetic that from now on checks
whether an IMethod is synthetic/compiler-generated (referring to the
synthetic flag in bytecode)

* Implementation of IClass.isSynthetic

Complementary to IMethod.isSynthetic, this method checks whether
an IClass is compiler-generated.

* updated JavaDoc
2018-10-02 22:28:21 -07:00
Ben Liblit 5336a08af2 Avoid using deprecated boxing constructors
Boxing a primitive using the constructor ("new Integer(4)") always
creates a distinct new boxed instance.  That's rarely what you need,
and in fact all of those constructors have been deprecated in Java 9.
Using the static "valueOf" method instead ("Integer.valueOf(4)") can
give better performance by reusing existing instances.  You no longer
get a unique boxed object, but generally that's OK.
2018-06-05 14:44:59 -05:00
Julian Dolby 196f7cb153 fix for nasty bug in decoding dup2_x2 2018-05-31 19:32:02 -04:00
Ben Liblit b14804bfdc Don't put fixed-name, writable files into "java.io.tmpdir"
If multiple tests both write to "/tmp/cg.txt" (for example), then
these tests cannot safely run concurrently.  That never used to be a
problem with Maven, since our Maven tests were all strictly sequential
anyway.  But parallelized testing using Gradle requires that we do
better.  Fortunately, Java has perfectly reasonable APIs for
generating uniquely-named temporary files and directories.
2018-04-18 11:29:29 -05:00
Ben Liblit 99c2493e37 Revert "Build WALA using Gradle instead of Maven" (#298) 2018-04-18 12:15:56 -04:00
Ben Liblit 7886fa13dc Don't put fixed-name, writable files into "java.io.tmpdir"
If multiple tests both write to "/tmp/cg.txt" (for example), then
these tests cannot safely run concurrently.  That never used to be a
problem with Maven, since our Maven tests were all strictly sequential
anyway.  But parallelized testing using Gradle requires that we do
better.  Fortunately, Java has perfectly reasonable APIs for
generating uniquely-named temporary files and directories.
2018-04-17 15:02:36 -05:00
Julian Dolby cd944a8f12 refactoring of CAst front end machinery to allow more reuse 2018-01-25 14:42:27 -05:00
Ben Liblit f60c164ec1 Escape "<" and ">" in Javadoc when not used as HTML tag syntax 2017-12-19 16:53:52 -06:00
Julian Dolby d29e278291 more instrumentation fixes
remove junk from dominators
2017-12-08 11:19:41 +08:00
Julian Dolby 5a02cde690 more flexibility to not extract calls for invokedynamic. Potentially, this will break instrumented methods that have massive numbers of invokedynamics in them, but that seems unlikely to happen at least with Java use of invokedynamic so far. We can burn this bridge when we come to it. 2017-12-06 19:04:27 +08:00
Ben Liblit b25e461bfe Convert a few more loops into modern for-each loops 2017-12-04 14:04:39 -08:00
Julian Dolby b68ff20c82
Merge pull request #269 from liblit/modernization-java-8-lambdas-and-method-references
Use Java 8 lambdas and method references wherever possible
2017-12-03 09:54:09 +08:00
Julian Dolby 803243ea53 Merge branch 'master' of https://github.com/wala/WALA 2017-12-01 20:02:00 +08:00
Julian Dolby 7cd2a2acf8 Fixes for instrumentation of invoke dynamic 2017-12-01 20:01:16 +08:00
Ben Liblit 9c83e87cc1 Merge branch 'master' into modernization-java-8-lambdas-and-method-references 2017-11-29 10:51:33 -06:00
Ben Liblit ebfd885d22 Use modern for-each loops where possible
Java sources used as test data have been excluded from this mass
clean-up.
2017-11-28 14:44:53 -06:00
Ben Liblit 6261880264 Remove unnecessary casts of lambda expressions 2017-11-27 11:31:15 -06:00
Ben Liblit 74e0640771 Replace simple lambdas with method references wherever possible 2017-11-27 11:31:15 -06:00
Ben Liblit 790d37781b Convert many single-method anonymous classes to lambdas
Eclipse's automated code clean-up tool did most of the heavy lifting
here: it specifically has a clean-up option for converting functional
interfaces to lambdas.  I merely had to revert the automated changes
for a single enumeration class for which it produced invalid results,
and for a few test inputs that apparently aren't set up to be compiled
with Java 8.
2017-11-27 11:31:15 -06:00
Karim Ali 423db824b3 adding support for the dynamic call graph experiments
currentSite should be ThreadLocal because not having this screws up a lot of the instrumentation-based dynamic call graphs we generate for the shootout benchmarks.

I have also conditionally changed how the string of the currentSite is created based on the output format that Julian came up with for the dynamic call graph. This support is necessary, because the Java std libraries are not instrumented. Therefore, they would appear as if calls from them show up from nowhere in the log that WALA generates for the dynamic call graph. This fix make those calls originate from a fake library BLOB node in the call graph.
2017-10-23 17:54:01 -06:00
Julian Dolby 26d354d1fc remove debug printing 2017-10-19 17:38:37 -04:00
Julian Dolby 11120329e1 fix messages about final; these vaiables do not need to be final in Java 8, really. 2017-10-19 15:02:19 -04:00
Julian Dolby 0f2d9b7635 fixes to dynamic CG to minimize bloating of methods 2017-10-19 13:12:21 -04:00
Ben Liblit ea95940d0f Be explicit when case fall-through is intentional 2017-08-15 14:55:34 -07:00
Ben Liblit da5f925cab Be explicit when the proper default for a switch is to do nothing
Of course, doing nothing isn't always the right behavior.  Sometimes a
previously-unhandled value is truly unexpected and one should fail by
throwing an exception.  It may not always be clear whether an
exception or doing nothing is the right choice.  For some `switch`
statements affected by this commit, I initially guessed that throwing
an exception was the right default behavior, but was proven wrong when
doing so caused WALA regression test failures.  That's strong evidence
that the unmatched values were not really unexpected, but merely
should have been handled by doing nothing as before.
2017-08-15 14:55:34 -07:00
Ben Liblit ab791f8c41 Throw a loud exception if switch encounters unexpected enum value
Previously each of these `switch` statements would implicitly do
nothing if an unanticipated `enum` value came along.  My impression is
that each of these `switch` statements is supposed to be exhaustive,
such that an unexpected (unhandled) value should never appear.  If one
does, we should recognize it and complain loudly.

Of course, sometimes the right behavior for previously-unhandled
values is to do nothing.  It may not always be clear whether an
exception or doing nothing is the right choice.  For this commit,
WALA's regression tests still pass even with the possibility of
throwing an exception for unexpected values.  If we assume that the
test suite is thorough, that tells me that throwing an exception is
the right policy for each `switch` statement that I'm changing here.
2017-08-15 14:55:34 -07:00
Ben Liblit cbcfb40435 Don't be silent in case of weird enum value
This `switch` statement currently covers all possible values of the
`enum` it is testing.  However, if a new value were introduced in the
future, the `switch` would have been silent about it instead of
printing a debug message as is done in all of the other cases.  Better
to print *some* kind of debug in the default case too.
2017-08-15 14:55:34 -07:00
Ben Liblit ce335f495d Avoid unintended control fall-through in case of weird enum value
This `switch` statement currently covers all possible values of the
`enum` it is testing.  However, if a new value were introduced in the
future, the `switch` would have allowed control-flow to fall through
by default instead of throwing an exception as is done in all of the
other cases.  Better to throw *some* kind of exception in the default
case too.
2017-08-15 14:55:34 -07:00
Ben Liblit 7dc71151d1 Add missing `break`s to print just 1 debug message instead of 1-3 2017-08-15 14:55:34 -07:00
Ben Liblit 61e9641094 Semantics-preserving control-flow tweaks to fix switch warnings
Eclipse was warning that these `switch` statements had no `default`
cases.  Each did have some default behavior, but implemented outside
the `switch`.  By moving the default behavior into a `default` case
within the `switch`, we eliminate a static warning with no change
whatsoever to the run-time behavior.
2017-08-15 14:55:34 -07:00
Ben Liblit cb6d3b282a Fix Eclipse warnings about redundant null checks and assignments
Most of these are harmless, and are best fixed simply by removing the
redundant check or assignment.  The one in FlowType.compareBlocks,
however, revealed a real problem.  This code checks for nullness of
`a` *after* having called a method on `a`.  Assuming that `a` can
indeed be `null` here, the check must come first to avoid a
`NullPointerException`.

In several places, I saw code of this form:

   if (thing == null)
     assert thing != null : ... ;

I honestly don't understand the purpose of that `if` statement.  Why
not just have the `assert` statement there directly?  I removed the
seemingly irrelevant `if` statements in these cases, but if this is
some intentional pattern, please explain it to me.

In a few places where nullness is statically known but non-obvious,
add assert statements to point out what's going on to help future
developers.

Upgrade future such warnings to errors to keep us moving in a cleaner
direction.
2017-08-15 09:11:29 -07:00
Ben Liblit 321b28f149 Remove some unnecessary warning suppressions
One such annotation was unnecessary because the thing it was
suppressing no longer happens.  Any future unnecessary warning
suppressions of this kind will now be treated as errors.

The other annotations were unnecessary because the corresponding
warnings have been disabled entirely in the Eclipse projects'
configurations.  There seems to be no way to tell Eclipse to treat
these as anything other than "info" diagnostics in the future, so
that's how they will remain.
2017-08-05 13:29:50 -07:00
Ben Liblit 6087b73cee Fix or suppress all 242 Eclipse warnings about unused parameters
In general, my approach was to try to eliminate each unused parameter
using Eclipse's "Change Method Signature" refactoring.  That did not
always succeed: a parameter may be unused in some base class method,
but then be used in subclass's override of that method.  In cases
where refactoring to eliminate a parameter failed, I instead annotated
the parameter with '@SuppressWarnings("unused")' to silence the
warning.

Note: this group of changes creates a significant risk of
incompatibility for third-party WALA code.  Some removed parameters
change externally-visible APIs.  Furthermore, these changes do not
necessarily lead to Java compilation errors.  For example, suppose
third-party code subclasses a WALA class or interface, overrides a
method, but does not annotate that method as @Override.  Removing a
parameter means that the third-party method no longer overrides.  This
can quietly change code behavior without compile-time errors or
warnings.  This is exactly why one should use @Override wherever
possible, but we cannot guarantee that third-party WALA users have
done that.
2017-07-31 15:29:00 -07:00
Ben Liblit 191904d607 Remove "throws XYZ" declarations where XYZ cannot be thrown
Unnecessary "throws" declarations tend to cascade.  If foo() calls
bar() and bar() falsely declares that it might throw IOException, that
often leads a programmer to declare that foo() might throw IOException
as well.  Fixing the bar() throws declaration then reveals that we can
fix the foo() throws declaration too.  By the time we reach a fixed
point with cleaning these up, we have removed roughly 320 unnecessary
throws declarations.

In a few cases, this cleanup even lets us remove entire "try
... catch" statements where the only thing being caught was an
exception that we now statically know cannot be thrown.  Nice!

In Eclipse project configurations, upgrade any future such shenanigans
from warnings to errors.  Now that we've fixed this, we don't want it
coming back again.

There is a potential drawback to this change.  Conceivably some public
WALA API entry point might have declared that it could throw some
exception merely to reserve the *option* of throwing that exception in
third-party code that subclasses and overrides the API entry point in
question.  I have no idea whether this is a significant concern in
practice, though.
2017-07-28 10:20:28 -07:00
Ben Liblit a888a49fdd Fix all Eclipse warnings about unnecessary semicolons
I have *not* upgraded this problem to be treated as an error in the
future.  Unfortunately Eclipse uses a single configuration setting for
both unnecessary semicolons and also for empty control-flow statements
like `while (p) ;`.  I'm not convinced that it's worth rewriting all
instances of the latter into `while (p) { }`.  So this is just going
to stay as a warning for now.
2017-07-14 22:39:01 -07:00
Ben Liblit e316471d88 Fix nearly all Eclipse warnings about using raw types
Along the way, I also converted many "for (;;)" loops into modern
"for (:)" loops.  I didn't systematically look for all opportunities
to do this, though.  I merely made this change where I was already
converting raw Iterator uses into modern Iterator<...> uses.

Better use of generics also allowed many casts to become statically
redundant.  I have removed all such redundant casts.

Only three raw-types warnings remain after this batch of fixes.  All
three involve raw uses of CallGraphBuilder.  I've tried to fix these
too, but it quickly snowballs into a cascade of changes that may or
may not eventually reach a statically-type-save fixed point.  I may
give these last few problem areas another go in the future.  For now,
though, the hundreds of other fixes seem worth keeping even if there
are a few stragglers.

This commit may change some public APIs, but only by making weaker
type signatures stronger by replacing raw types with generic types.
For example, we may change something like "Set" into "Set<String>",
but we're not adding new arguments, changing any
underlying (post-generics-erasure) types, etc.
2017-07-12 10:39:06 -07:00
Ben Liblit 8cc4daf6a0 Access static fields directly via the classes that declare them
Previously some of these were accessing such fields through a subclass
of the declaring class.  That creates an unnecessary extra inter-class
dependency lower in the type hierarchy than necessary.

Also, suppress this warning in an automated test input where the
indirect static accesses are explicitly intentional.
2017-06-07 08:29:23 -07:00
Ben Liblit 72c754e874 Declare private methods static wherever possible
If a method is private, there's no risk that a subclass elsewhere
might be overriding it and depending on dynamic dispatch to choose the
right implementation.  So all of these private methods can safely be
declared static without risk of regression in either WALA code or
unseen third-party code.
2017-06-07 08:29:23 -07:00
Ben Liblit 214e0caa86 Suppress Eclipse warnings about unused allocations
In each of these cases, the constructor directly or indirectly has
side effects that we want to keep, even if the object itself is not
retained and used by eht code that invokes `new`.
2017-05-26 14:25:03 -07:00
Ben Liblit 4cef26162c Add @Override annotations wherever possible (#178)
* Fix warnings about unset javacProjectSettings build entries

Specifically, these are all warnings of the form "The
'javacProjectSettings' build entry should be set when there are project
specific compiler settings".

* Add @Override annotations to all methods that do override

This fixes 287 Eclipse code style warnings.

* Cannot add @Override annotations here, so suppress warnings instead

We should be able to add these @Override annotations in the future,
one Eclipse Mars and earlier are no longer supported.  For now,
though, they have to go away in order to be compatible with older
Eclipse releases.
2017-05-08 07:39:49 -07:00
Manu Sridharan 0c424e12b3 Fix #164 2017-04-16 18:23:56 -07:00
Ben Liblit 65be11f222 Merge branch 'master' into warning-fixes-unnecessary-code-controversial 2017-03-25 22:12:03 -05:00
Ben Liblit 42c7866dfd Prune constructor and method signatures after removing unused fields
Removing an unused field sometimes means removing constructor code
that used to initialize that field.  Removing that initialization code
sometimes leaves whole constructor arguments unused.  Removing those
unused arguments can leave us with unused code to compute those
arguments in constructors' callers, and so on.  This commit tries to
clean all of this up, working backward from the unused fields that an
earlier commit already removed.  Hopefully I have avoided removing
upstream code that had other important side effects, but it wouldn't
hurt for a WALA expert to review this change carefully.
2017-03-25 17:40:22 -05:00
Ben Liblit c94d4210ab Merge branch 'warning-fixes-unnecessary-code-uncontroversial' 2017-03-24 10:33:01 -05:00
Ben Liblit 16492c7b78 Revert "Suppress 157 Eclipse warnings about unused exception parameters"
This reverts commit fe9f7a793a.
2017-03-23 16:32:00 -05:00
Ben Liblit e52d872e3e Fix 19 Eclipse warnings about unnecessary casts 2017-03-23 12:28:14 -05:00
Ben Liblit b8264b884d Remove "@param" tags for which there is no corresponding parameter 2017-03-22 20:40:52 -05:00
Ben Liblit 934f8f524f Fix 11 Eclipse warnings about fields whose values are never used 2017-03-20 00:44:40 -05:00
Ben Liblit aaf66705e1 Fix 65 Eclipse warnings about unused exception parameters
In the cases addressed here, the caught exception was being "handled"
by throwing some new exception.  Instead of discarding the old
exception, pass it to the new exception's constructor to indicate the
original cause of the newly-created exception.  This practice, called
"exception chaining", can often be useful in debugging.
2017-03-20 00:44:39 -05:00
Ben Liblit fe9f7a793a Suppress 157 Eclipse warnings about unused exception parameters
In the cases addressed here, the caught exception is truly not needed
by the handling code.
2017-03-20 00:44:06 -05:00