_Unknown_.java 0000644 0001754 0001754 00000005475 12712525021 012716 0 ustar tiant tiant /* SOLAR - Effective Soundness-Guided Reflection Analysis
*
* Copyright (C) 2015 Yue Li, Tian Tan, Jingling Xue
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
/**
* This is a auxiliary class which is used to introduce the Unknown type into
* the existing type system. Not introducing the Unknown type directly by rules
* or generator is to avoid the AssignCompatible predicate from Unknown to
* java.lang.Object which may cause performance bug.
*
* In addition, this class can help Solar soundly model the pointer-affecting
* methods which is directly invoked on the unknown objects during LHM (Lazy
* Heap Modelling). The heaps (the unknown objects) are lazily modelled, but they
* may affect the pointer analysis in the paths from newInstance() to the LHM points.
* However, as the unknown object is with declared type java.lang.Object, it has no
* fields and thus we only need to model the side effects introduced by the calls to the
* methods declared in java.lang.Object.
*
* Note that it is very rare in practice (i.e., calling methods of java.lang.Object
* before the LHM points), so we assume there is no such usage patterns in our SAS'15
* paper. However, for achieving a more comprehensive handling for LHM (considering the
* theoretical possibility), we handle this issue in our implementation.
*
* Note that all the results in the evaluation of SAS'15 are achieved under this
* implementation (although we consider it as an assumption in our paper to save space).
*
* There are only two methods in java.lang.Object need to modelled regarding
* pointer analysis:
* (1) toString()
* (2) getClass()
*
* As for clone() method, it cannot be invoked on a variable with java.lang.Object
* as declared type directly.
*
* This class overrides toString() by returning an java.lang.String object so that
* its side-effect can be soundly handled by pointer analysis rules for grant.
* The rules for handling getClass() reside in logic/library/reflection.logic.
* Actually, the rules return an unknown Class object to model getClass() soundly.
*
* Last comment at 10-09-2015
*
*/
public class _Unknown_ {
public String toString() { return new String(); }
}
_Unknown_.class 0000644 0001754 0001754 00000000453 12537476437 013116 0 ustar tiant tiant Ęţşľ 2
()V Code LineNumberTable toString ()Ljava/lang/String;
SourceFile _Unknown_.java java/lang/String _Unknown_ java/lang/Object ! *· ±
» Y· °
LICENSE.txt 0000644 0001754 0001754 00000105430 12712531174 011737 0 ustar tiant tiant
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright © 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies of this license document, but
changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for software and other kinds of works.
The licenses for most software and other practical works are designed to take away your freedom
to share and change the works. By contrast, the GNU General Public License is intended to
guarantee your freedom to share and change all versions of a program--to make sure it remains
free software for all its users. We, the Free Software Foundation, use the GNU General Public
License for most of our software; it applies also to any other work released this way by its
authors. You can apply it to your programs, too.
When we speak of free software, we are referring to freedom, not price. Our General Public
Licenses are designed to make sure that you have the freedom to distribute copies of free
software (and charge for them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new free programs, and that
you know you can do these things.
To protect your rights, we need to prevent others from denying you these rights or asking you
to surrender the rights. Therefore, you have certain responsibilities if you distribute copies
of the software, or if you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether gratis or for a fee, you must
pass on to the recipients the same freedoms that you received. You must make sure that they,
too, receive or can get the source code. And you must show them these terms so they know their
rights.
Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the
software, and (2) offer you this License giving you legal permission to copy, distribute and/or
modify it.
For the developers' and authors' protection, the GPL clearly explains that there is no warranty
for this free software. For both users' and authors' sake, the GPL requires that modified
versions be marked as changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run modified versions of the
software inside them, although the manufacturer can do so. This is fundamentally incompatible
with the aim of protecting users' freedom to change the software. The systematic pattern of
such abuse occurs in the area of products for individuals to use, which is precisely where it
is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the
practice for those products. If such problems arise substantially in other domains, we stand
ready to extend this provision to those domains in future versions of the GPL, as needed to
protect the freedom of users.
Finally, every program is threatened constantly by software patents. States should not allow
patents to restrict development and use of software on general-purpose computers, but in those
that do, we wish to avoid the special danger that patents applied to a free program could make
it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to
render the program non-free.
The precise terms and conditions for copying, distribution and modification follow.
TERMS AND CONDITIONS
0. Definitions.
“This License” refers to version 3 of the GNU General Public License.
“Copyright” also means copyright-like laws that apply to other kinds of works, such as
semiconductor masks.
“The Program” refers to any copyrightable work licensed under this License. Each licensee is
addressed as “you”. “Licensees” and “recipients” may be individuals or organizations.
To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring
copyright permission, other than the making of an exact copy. The resulting work is called a
“modified version” of the earlier work or a work “based on” the earlier work.
A “covered work” means either the unmodified Program or a work based on the Program.
To “propagate” a work means to do anything with it that, without permission, would make you
directly or secondarily liable for infringement under applicable copyright law, except
executing it on a computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the public, and in some
countries other activities as well.
To “convey” a work means any kind of propagation that enables other parties to make or receive
copies. Mere interaction with a user through a computer network, with no transfer of a copy, is
not conveying.
An interactive user interface displays “Appropriate Legal Notices” to the extent that it
includes a convenient and prominently visible feature that (1) displays an appropriate
copyright notice, and (2) tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the work under this License,
and how to view a copy of this License. If the interface presents a list of user commands or
options, such as a menu, a prominent item in the list meets this criterion.
1. Source Code.
The “source code” for a work means the preferred form of the work for making modifications to
it. “Object code” means any non-source form of a work.
A “Standard Interface” means an interface that either is an official standard defined by a
recognized standards body, or, in the case of interfaces specified for a particular programming
language, one that is widely used among developers working in that language.
The “System Libraries” of an executable work include anything, other than the work as a whole,
that (a) is included in the normal form of packaging a Major Component, but which is not part
of that Major Component, and (b) serves only to enable use of the work with that Major
Component, or to implement a Standard Interface for which an implementation is available to the
public in source code form. A “Major Component”, in this context, means a major essential
component (kernel, window system, and so on) of the specific operating system (if any) on which
the executable work runs, or a compiler used to produce the work, or an object code interpreter
used to run it.
The “Corresponding Source” for a work in object code form means all the source code needed to
generate, install, and (for an executable work) run the object code and to modify the work,
including scripts to control those activities. However, it does not include the work's System
Libraries, or general-purpose tools or generally available free programs which are used
unmodified in performing those activities but which are not part of the work. For example,
Corresponding Source includes interface definition files associated with source files for the
work, and the source code for shared libraries and dynamically linked subprograms that the work
is specifically designed to require, such as by intimate data communication or control flow
between those subprograms and other parts of the work.
The Corresponding Source need not include anything that users can regenerate automatically from
other parts of the Corresponding Source.
The Corresponding Source for a work in source code form is that same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of copyright on the Program, and
are irrevocable provided the stated conditions are met. This License explicitly affirms your
unlimited permission to run the unmodified Program. The output from running a covered work is
covered by this License only if the output, given its content, constitutes a covered work. This
License acknowledges your rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not convey, without conditions so
long as your license otherwise remains in force. You may convey covered works to others for the
sole purpose of having them make modifications exclusively for you, or provide you with
facilities for running those works, provided that you comply with the terms of this License in
conveying all material for which you do not control copyright. Those thus making or running the
covered works for you must do so exclusively on your behalf, under your direction and control,
on terms that prohibit them from making any copies of your copyrighted material outside their
relationship with you.
Conveying under any other circumstances is permitted solely under the conditions stated below.
Sublicensing is not allowed; section 10 makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological measure under any applicable
law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December
1996, or similar laws prohibiting or restricting circumvention of such measures.
When you convey a covered work, you waive any legal power to forbid circumvention of
technological measures to the extent such circumvention is effected by exercising rights under
this License with respect to the covered work, and you disclaim any intention to limit
operation or modification of the work as a means of enforcing, against the work's users, your
or third parties' legal rights to forbid circumvention of technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you receive it, in any medium,
provided that you conspicuously and appropriately publish on each copy an appropriate copyright
notice; keep intact all notices stating that this License and any non-permissive terms added in
accord with section 7 apply to the code; keep intact all notices of the absence of any
warranty; and give all recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey, and you may offer support
or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to produce it from the
Program, in the form of source code under the terms of section 4, provided that you also meet
all of these conditions:
a) The work must carry prominent notices stating that you modified it, and giving a
relevant date.
b) The work must carry prominent notices stating that it is released under this License and
any conditions added under section 7. This requirement modifies the requirement in section
4 to “keep intact all notices”.
c) You must license the entire work, as a whole, under this License to anyone who comes
into possession of a copy. This License will therefore apply, along with any applicable
section 7 additional terms, to the whole of the work, and all its parts, regardless of how
they are packaged. This License gives no permission to license the work in any other way,
but it does not invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display Appropriate Legal
Notices; however, if the Program has interactive interfaces that do not display Appropriate
Legal Notices, your work need not make them do so.
A compilation of a covered work with other separate and independent works, which are not by
their nature extensions of the covered work, and which are not combined with it such as to form
a larger program, in or on a volume of a storage or distribution medium, is called an
“aggregate” if the compilation and its resulting copyright are not used to limit the access or
legal rights of the compilation's users beyond what the individual works permit. Inclusion of a
covered work in an aggregate does not cause this License to apply to the other parts of the
aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms of sections 4 and 5, provided
that you also convey the machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product (including a physical
distribution medium), accompanied by the Corresponding Source fixed on a durable physical
medium customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product (including a physical
distribution medium), accompanied by a written offer, valid for at least three years and
valid for as long as you offer spare parts or customer support for that product model, to
give anyone who possesses the object code either (1) a copy of the Corresponding Source for
all the software in the product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no more than your reasonable
cost of physically performing this conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the written offer to provide
the Corresponding Source. This alternative is allowed only occasionally and
noncommercially, and only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated place (gratis or for a
charge), and offer equivalent access to the Corresponding Source in the same way through
the same place at no further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to copy the object code is a
network server, the Corresponding Source may be on a different server (operated by you or a
third party) that supports equivalent copying facilities, provided you maintain clear
directions next to the object code saying where to find the Corresponding Source.
Regardless of what server hosts the Corresponding Source, you remain obligated to ensure
that it is available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided you inform other peers
where the object code and Corresponding Source of the work are being offered to the general
public at no charge under subsection 6d.
A separable portion of the object code, whose source code is excluded from the Corresponding
Source as a System Library, need not be included in conveying the object code work.
A “User Product” is either (1) a “consumer product”, which means any tangible personal property
which is normally used for personal, family, or household purposes, or (2) anything designed or
sold for incorporation into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular product received by a
particular user, “normally used” refers to a typical or common use of that class of product,
regardless of the status of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product is a consumer product
regardless of whether the product has substantial commercial, industrial or non-consumer uses,
unless such uses represent the only significant mode of use of the product.
“Installation Information” for a User Product means any methods, procedures, authorization
keys, or other information required to install and execute modified versions of a covered work
in that User Product from a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object code is in no case
prevented or interfered with solely because modification has been made.
If you convey an object code work under this section in, or with, or specifically for use in, a
User Product, and the conveying occurs as part of a transaction in which the right of
possession and use of the User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the Corresponding Source
conveyed under this section must be accompanied by the Installation Information. But this
requirement does not apply if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has been installed in ROM).
The requirement to provide Installation Information does not include a requirement to continue
to provide support service, warranty, or updates for a work that has been modified or installed
by the recipient, or for the User Product in which it has been modified or installed. Access to
a network may be denied when the modification itself materially and adversely affects the
operation of the network or violates the rules and protocols for communication across the
network.
Corresponding Source conveyed, and Installation Information provided, in accord with this
section must be in a format that is publicly documented (and with an implementation available
to the public in source code form), and must require no special password or key for unpacking,
reading or copying.
7. Additional Terms.
“Additional permissions” are terms that supplement the terms of this License by making
exceptions from one or more of its conditions. Additional permissions that are applicable to
the entire Program shall be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions apply only to part of the
Program, that part may be used separately under those permissions, but the entire Program
remains governed by this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option remove any additional
permissions from that copy, or from any part of it. (Additional permissions may be written to
require their own removal in certain cases when you modify the work.) You may place additional
permissions on material, added by you to a covered work, for which you have or can give
appropriate copyright permission.
Notwithstanding any other provision of this License, for material you add to a covered work,
you may (if authorized by the copyright holders of that material) supplement the terms of this
License with terms:
a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and
16 of this License; or
b) Requiring preservation of specified reasonable legal notices or author attributions in
that material or in the Appropriate Legal Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or requiring that modified
versions of such material be marked in reasonable ways as different from the original
version; or
d) Limiting the use for publicity purposes of names of licensors or authors of the
material; or
e) Declining to grant rights under trademark law for use of some trade names, trademarks,
or service marks; or
f) Requiring indemnification of licensors and authors of that material by anyone who
conveys the material (or modified versions of it) with contractual assumptions of liability
to the recipient, for any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered “further restrictions” within the
meaning of section 10. If the Program as you received it, or any part of it, contains a notice
stating that it is governed by this License along with a term that is a further restriction,
you may remove that term. If a license document contains a further restriction but permits
relicensing or conveying under this License, you may add to a covered work material governed by
the terms of that license document, provided that the further restriction does not survive such
relicensing or conveying.
If you add terms to a covered work in accord with this section, you must place, in the relevant
source files, a statement of the additional terms that apply to those files, or a notice
indicating where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the form of a separately
written license, or stated as exceptions; the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly provided under this License.
Any attempt otherwise to propagate or modify it is void, and will automatically terminate your
rights under this License (including any patent licenses granted under the third paragraph of
section 11).
However, if you cease all violation of this License, then your license from a particular
copyright holder is reinstated (a) provisionally, unless and until the copyright holder
explicitly and finally terminates your license, and (b) permanently, if the copyright holder
fails to notify you of the violation by some reasonable means prior to 60 days after the
cessation.
Moreover, your license from a particular copyright holder is reinstated permanently if the
copyright holder notifies you of the violation by some reasonable means, this is the first time
you have received notice of violation of this License (for any work) from that copyright
holder, and you cure the violation prior to 30 days after your receipt of the notice.
Termination of your rights under this section does not terminate the licenses of parties who
have received copies or rights from you under this License. If your rights have been terminated
and not permanently reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or run a copy of the Program.
Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer
transmission to receive a copy likewise does not require acceptance. However, nothing other
than this License grants you permission to propagate or modify any covered work. These actions
infringe copyright if you do not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically receives a license from the
original licensors, to run, modify and propagate that work, subject to this License. You are
not responsible for enforcing compliance by third parties with this License.
An “entity transaction” is a transaction transferring control of an organization, or
substantially all assets of one, or subdividing an organization, or merging organizations. If
propagation of a covered work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever licenses to the work the
party's predecessor in interest had or could give under the previous paragraph, plus a right to
possession of the Corresponding Source of the work from the predecessor in interest, if the
predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the rights granted or affirmed
under this License. For example, you may not impose a license fee, royalty, or other charge for
exercise of rights granted under this License, and you may not initiate litigation (including a
cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by
making, using, selling, offering for sale, or importing the Program or any portion of it.
11. Patents.
A “contributor” is a copyright holder who authorizes use under this License of the Program or a
work on which the Program is based. The work thus licensed is called the contributor's
“contributor version”.
A contributor's “essential patent claims” are all patent claims owned or controlled by the
contributor, whether already acquired or hereafter acquired, that would be infringed by some
manner, permitted by this License, of making, using, or selling its contributor version, but do
not include claims that would be infringed only as a consequence of further modification of the
contributor version. For purposes of this definition, “control” includes the right to grant
patent sublicenses in a manner consistent with the requirements of this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the
contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise
run, modify and propagate the contents of its contributor version.
In the following three paragraphs, a “patent license” is any express agreement or commitment,
however denominated, not to enforce a patent (such as an express permission to practice a
patent or covenant not to sue for patent infringement). To “grant” such a patent license to a
party means to make such an agreement or commitment not to enforce a patent against the party.
If you convey a covered work, knowingly relying on a patent license, and the Corresponding
Source of the work is not available for anyone to copy, free of charge and under the terms of
this License, through a publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to
deprive yourself of the benefit of the patent license for this particular work, or (3) arrange,
in a manner consistent with the requirements of this License, to extend the patent license to
downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the
patent license, your conveying the covered work in a country, or your recipient's use of the
covered work in a country, would infringe one or more identifiable patents in that country that
you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or arrangement, you convey, or
propagate by procuring conveyance of, a covered work, and grant a patent license to some of the
parties receiving the covered work authorizing them to use, propagate, modify or convey a
specific copy of the covered work, then the patent license you grant is automatically extended
to all recipients of the covered work and works based on it.
A patent license is “discriminatory” if it does not include within the scope of its coverage,
prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights
that are specifically granted under this License. You may not convey a covered work if you are
a party to an arrangement with a third party that is in the business of distributing software,
under which you make payment to the third party based on the extent of your activity of
conveying the work, and under which the third party grants, to any of the parties who would
receive the covered work from you, a discriminatory patent license (a) in connection with
copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that contain the covered work,
unless you entered into that arrangement, or that patent license was granted, prior to 28 March
2007.
Nothing in this License shall be construed as excluding or limiting any implied license or
other defenses to infringement that may otherwise be available to you under applicable patent
law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or otherwise) that
contradict the conditions of this License, they do not excuse you from the conditions of this
License. If you cannot convey a covered work so as to satisfy simultaneously your obligations
under this License and any other pertinent obligations, then as a consequence you may not
convey it at all. For example, if you agree to terms that obligate you to collect a royalty for
further conveying from those to whom you convey the Program, the only way you could satisfy
both those terms and this License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have permission to link or combine any
covered work with a work licensed under version 3 of the GNU Affero General Public License into
a single combined work, and to convey the resulting work. The terms of this License will
continue to apply to the part which is the covered work, but the special requirements of the
GNU Affero General Public License, section 13, concerning interaction through a network will
apply to the combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of the GNU General Public
License from time to time. Such new versions will be similar in spirit to the present version,
but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Program specifies that a certain
numbered version of the GNU General Public License “or any later version” applies to it, you
have the option of following the terms and conditions either of that numbered version or of any
later version published by the Free Software Foundation. If the Program does not specify a
version number of the GNU General Public License, you may choose any version ever published by
the Free Software Foundation.
If the Program specifies that a proxy can decide which future versions of the GNU General
Public License can be used, that proxy's public statement of acceptance of a version
permanently authorizes you to choose that version for the Program.
Later license versions may give you additional or different permissions. However, no additional
obligations are imposed on any author or copyright holder as a result of your choosing to
follow a later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS
IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK
AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE
DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT
HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE
LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE
OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN
ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided above cannot be given local
legal effect according to their terms, reviewing courts shall apply local law that most closely
approximates an absolute waiver of all civil liability in connection with the Program, unless a
warranty or assumption of liability accompanies a copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest possible use to the public,
the best way to achieve this is to make it free software which everyone can redistribute and
change under these terms.
To do so, attach the following notices to the program. It is safest to attach them to the start
of each source file to most effectively state the exclusion of warranty; and each file should
have at least the “copyright” line and a pointer to where the full notice is found.
Copyright (C)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short notice like this when it
starts in an interactive mode:
Copyright (C)
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate parts of the
General Public License. Of course, your program's commands might be different; for a GUI
interface, you would use an “about box”.
You should also get your employer (if you work as a programmer) or school, if any, to sign a
“copyright disclaimer” for the program, if necessary. For more information on this, and how to
apply and follow the GNU GPL, see .
The GNU General Public License does not permit incorporating your program into proprietary
programs. If your program is a subroutine library, you may consider it more useful to permit
linking proprietary applications with the library. If this is what you want to do, use the GNU
Lesser General Public License instead of this License. But first, please read <
http://www.gnu.org/philosophy/why-not-lgpl.html>.
gen.patch 0000644 0001754 0001754 00000424604 12713476124 011721 0 ustar tiant tiant SOLAR - Effective Soundness-Guided Reflection Analysis
Copyright (C) 2015 Yue Li, Tian Tan, Jingling Xue
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
diff -urN soot-fact-generation-r958-src/compile solar-gen/compile
--- soot-fact-generation-r958-src/compile 2009-06-05 22:41:56.000000000 +1000
+++ solar-gen/compile 2015-05-26 16:40:43.000000000 +1000
@@ -2,7 +2,7 @@
set -e
-cp=$DOOP_HOME/lib/sootclasses-2.3.0.jar
+cp=$DOOP_HOME/lib/sootclasses-2.5.0.jar
mkdir -p build/content
javac -Xlint -cp $cp -d build/content $(find src -name '*.java')
diff -urN soot-fact-generation-r958-src/src/Column.java solar-gen/src/Column.java
--- soot-fact-generation-r958-src/src/Column.java 2009-06-04 01:45:54.000000000 +1000
+++ solar-gen/src/Column.java 2015-05-27 15:28:21.000000000 +1000
@@ -4,10 +4,12 @@
public class Column {
String data;
+
public Column(String data) {
this.data = data;
}
+
public String toString() {
return data;
}
-}
\ No newline at end of file
+}
diff -urN soot-fact-generation-r958-src/src/CSVDatabase.java solar-gen/src/CSVDatabase.java
--- soot-fact-generation-r958-src/src/CSVDatabase.java 2009-06-04 13:07:30.000000000 +1000
+++ solar-gen/src/CSVDatabase.java 2015-05-27 15:31:38.000000000 +1000
@@ -6,63 +6,49 @@
import java.util.HashMap;
import java.util.Map;
-public class CSVDatabase implements Database
-{
+public class CSVDatabase implements Database {
private final char SEP = '\t';
private final char EOL = '\n';
private File _directory;
private Map _writers;
- public CSVDatabase(File directory)
- {
+ public CSVDatabase(File directory) {
super();
_directory = directory;
_writers = new HashMap();
}
- public void close() throws IOException
- {
- for(Writer w: _writers.values())
- {
+ public void close() throws IOException {
+ for (Writer w : _writers.values()) {
w.close();
}
}
- public void add(String predicate, Column arg)
- {
- try
- {
+ public void add(String predicate, Column arg) {
+ try {
Writer w = getWriter(predicate);
w.write(arg.toString());
w.write(EOL);
- }
- catch(IOException exc)
- {
+ } catch (IOException exc) {
throw new RuntimeException(exc);
}
}
- public void add(String predicate, Column arg1, Column arg2)
- {
- try
- {
+ public void add(String predicate, Column arg1, Column arg2) {
+ try {
Writer w = getWriter(predicate);
w.write(arg1.toString());
w.write(SEP);
w.write(arg2.toString());
w.write(EOL);
- }
- catch(IOException exc)
- {
+ } catch (IOException exc) {
throw new RuntimeException(exc);
}
}
- public void add(String predicate, Column arg1, Column arg2, Column arg3)
- {
- try
- {
+ public void add(String predicate, Column arg1, Column arg2, Column arg3) {
+ try {
Writer w = getWriter(predicate);
w.write(arg1.toString());
w.write(SEP);
@@ -70,17 +56,14 @@
w.write(SEP);
w.write(arg3.toString());
w.write(EOL);
- }
- catch(IOException exc)
- {
+ } catch (IOException exc) {
throw new RuntimeException(exc);
}
}
- public void add(String predicate, Column arg1, Column arg2, Column arg3, Column arg4)
- {
- try
- {
+ public void add(String predicate, Column arg1, Column arg2, Column arg3,
+ Column arg4) {
+ try {
Writer w = getWriter(predicate);
w.write(arg1.toString());
w.write(SEP);
@@ -90,19 +73,16 @@
w.write(SEP);
w.write(arg4.toString());
w.write(EOL);
- }
- catch(IOException exc)
- {
+ } catch (IOException exc) {
throw new RuntimeException(exc);
}
}
- private Writer getWriter(String predicate) throws IOException
- {
+ private Writer getWriter(String predicate) throws IOException {
Writer result = _writers.get(predicate);
- if(result == null)
- {
- result = new OutputStreamWriter(new FileOutputStream(new File(_directory, predicate + ".facts")));
+ if (result == null) {
+ result = new OutputStreamWriter(new FileOutputStream(new File(
+ _directory, predicate + ".facts")));
_writers.put(predicate, result);
}
@@ -110,8 +90,8 @@
}
public Column addEntity(String string, String key) {
- add(string, new Column(key));
- return new Column(key);
+ add(string, new Column(key));
+ return new Column(key);
}
public Column asColumn(String arg) {
diff -urN soot-fact-generation-r958-src/src/Database.java solar-gen/src/Database.java
--- soot-fact-generation-r958-src/src/Database.java 2009-06-04 01:45:54.000000000 +1000
+++ solar-gen/src/Database.java 2015-05-27 15:31:52.000000000 +1000
@@ -1,15 +1,22 @@
import java.io.IOException;
public interface Database {
- public void add(String predicate, Column arg);
- public void add(String predicate, Column arg1, Column arg2);
- public void add(String predicate, Column arg1, Column arg2, Column arg3);
- public void add(String predicate, Column arg1, Column arg2, Column arg3, Column arg4);
- public Column addEntity(String string, String key);
- public Column asColumn(String arg);
- public Column asIntColumn(String arg);
- public Column asEntity(String arg);
-
- public void close() throws IOException;
+ public void add(String predicate, Column arg);
-}
\ No newline at end of file
+ public void add(String predicate, Column arg1, Column arg2);
+
+ public void add(String predicate, Column arg1, Column arg2, Column arg3);
+
+ public void add(String predicate, Column arg1, Column arg2, Column arg3, Column arg4);
+
+ public Column addEntity(String string, String key);
+
+ public Column asColumn(String arg);
+
+ public Column asIntColumn(String arg);
+
+ public Column asEntity(String arg);
+
+ public void close() throws IOException;
+
+}
diff -urN soot-fact-generation-r958-src/src/FactGenerator.java solar-gen/src/FactGenerator.java
--- soot-fact-generation-r958-src/src/FactGenerator.java 2009-06-03 01:40:01.000000000 +1000
+++ solar-gen/src/FactGenerator.java 2015-05-28 15:41:42.000000000 +1000
@@ -1,521 +1,596 @@
-import soot.jimple.*;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.util.HashMap;
+import java.util.Map;
+
import soot.Body;
import soot.Local;
import soot.Modifier;
import soot.PrimType;
+import soot.Printer;
+import soot.Scene;
import soot.SootClass;
import soot.SootField;
import soot.SootMethod;
+import soot.SourceLocator;
import soot.Trap;
+import soot.Type;
import soot.Unit;
import soot.Value;
+import soot.jimple.ArrayRef;
+import soot.jimple.AssignStmt;
+import soot.jimple.BinopExpr;
+import soot.jimple.CastExpr;
+import soot.jimple.CaughtExceptionRef;
+import soot.jimple.ClassConstant;
+import soot.jimple.DoubleConstant;
+import soot.jimple.FloatConstant;
+import soot.jimple.IdentityStmt;
+import soot.jimple.InstanceFieldRef;
+import soot.jimple.InstanceOfExpr;
+import soot.jimple.IntConstant;
+import soot.jimple.InvokeExpr;
+import soot.jimple.InvokeStmt;
+import soot.jimple.LengthExpr;
+import soot.jimple.LongConstant;
+import soot.jimple.NegExpr;
+import soot.jimple.NewArrayExpr;
+import soot.jimple.NewExpr;
+import soot.jimple.NewMultiArrayExpr;
+import soot.jimple.NullConstant;
+import soot.jimple.ParameterRef;
+import soot.jimple.ReturnStmt;
+import soot.jimple.StaticFieldRef;
+import soot.jimple.Stmt;
+import soot.jimple.StringConstant;
+import soot.jimple.ThisRef;
+import soot.jimple.ThrowStmt;
+import soot.options.Options;
import soot.shimple.PhiExpr;
import soot.shimple.Shimple;
+import soot.tagkit.LineNumberTag;
+import soot.tagkit.SourceLnPosTag;
/**
- * Traverses Soot classes and invokes methods in FactWriter to
- * generate facts. The class FactGenerator is the main class
- * controlling what facts are generated.
+ * Traverses Soot classes and invokes methods in FactWriter to generate facts.
+ * The class FactGenerator is the main class controlling what facts are
+ * generated.
*
* @author Martin Bravenboer
* @license MIT
*/
-public class FactGenerator
-{
- private FactWriter _writer;
- private boolean _ssa;
-
- public FactGenerator(FactWriter writer, boolean ssa)
- {
- _writer = writer;
- _writer.writeStandardFacts();
- _ssa = ssa;
- }
-
- public void generate(SootClass c)
- {
- _writer.writeClassOrInterfaceType(c);
-
- // the isInterface condition prevents Object as superclass of interface
- if(c.hasSuperclass() && !c.isInterface())
- {
- _writer.writeDirectSuperclass(c, c.getSuperclass());
- }
-
- for(SootClass i : c.getInterfaces())
- {
- _writer.writeDirectSuperinterface(c, i);
- }
-
- for(SootField f : c.getFields())
- {
- generate(f);
- }
-
- for(SootMethod m : c.getMethods())
- {
- Session session = new Session();
- generate(m, session);
- }
- }
-
- public void generate(SootField f)
- {
- _writer.writeFieldSignature(f);
-
- int modifiers = f.getModifiers();
- if(Modifier.isAbstract(modifiers))
- _writer.writeFieldModifier(f, "abstract");
- if(Modifier.isFinal(modifiers))
- _writer.writeFieldModifier(f, "final");
- if(Modifier.isNative(modifiers))
- _writer.writeFieldModifier(f, "native");
- if(Modifier.isPrivate(modifiers))
- _writer.writeFieldModifier(f, "private");
- if(Modifier.isProtected(modifiers))
- _writer.writeFieldModifier(f, "protected");
- if(Modifier.isPublic(modifiers))
- _writer.writeFieldModifier(f, "public");
- if(Modifier.isStatic(modifiers))
- _writer.writeFieldModifier(f, "static");
- if(Modifier.isSynchronized(modifiers))
- _writer.writeFieldModifier(f, "synchronized");
- if(Modifier.isTransient(modifiers))
- _writer.writeFieldModifier(f, "transient");
- if(Modifier.isVolatile(modifiers))
- _writer.writeFieldModifier(f, "volatile");
- // TODO interface?
- // TODO strictfp?
- // TODO annotation?
- // TODO enum?
- }
-
- public void generate(SootMethod m, Session session)
- {
- if (m.isPhantom())
- return;
-
- _writer.writeMethodDeclaration(m);
- _writer.writeMethodSignature(m);
-
- int modifiers = m.getModifiers();
- if(Modifier.isAbstract(modifiers))
- _writer.writeMethodModifier(m, "abstract");
- if(Modifier.isFinal(modifiers))
- _writer.writeMethodModifier(m, "final");
- if(Modifier.isNative(modifiers))
- _writer.writeMethodModifier(m, "native");
- if(Modifier.isPrivate(modifiers))
- _writer.writeMethodModifier(m, "private");
- if(Modifier.isProtected(modifiers))
- _writer.writeMethodModifier(m, "protected");
- if(Modifier.isPublic(modifiers))
- _writer.writeMethodModifier(m, "public");
- if(Modifier.isStatic(modifiers))
- _writer.writeMethodModifier(m, "static");
- if(Modifier.isSynchronized(modifiers))
- _writer.writeMethodModifier(m, "synchronized");
- // TODO would be nice to have isVarArgs in Soot
- if(Modifier.isTransient(modifiers))
- _writer.writeMethodModifier(m, "varargs");
- // TODO would be nice to have isBridge in Soot
- if(Modifier.isVolatile(modifiers))
- _writer.writeMethodModifier(m, "bridge");
- // TODO interface?
- // TODO strictfp?
- // TODO annotation?
- // TODO enum?
-
- if(!m.isStatic())
- {
- _writer.writeThisVar(m);
- }
-
- if(m.isNative())
- {
- _writer.writeNativeReturnVar(m);
- }
-
- for(int i = 0 ; i < m.getParameterCount(); i++)
- {
- _writer.writeFormalParam(m, i);
- }
-
- for(SootClass clazz: m.getExceptions())
- {
- _writer.writeMethodDeclarationException(m, clazz);
- }
-
- if(!(m.isAbstract() || m.isNative()))
- {
- if(!m.hasActiveBody())
- {
- m.retrieveActiveBody();
- }
-
- Body b = m.getActiveBody();
- if(_ssa)
- {
- b = Shimple.v().newBody(b);
- m.setActiveBody(b);
- }
-
- generate(m, b, session);
-
- m.releaseActiveBody();
- }
- }
-
- public void generate(SootMethod m, Body b, Session session)
- {
- b.validate();
- session.numberUnits(b.getUnits().iterator());
-
- for(Local l : b.getLocals())
- {
- _writer.writeLocal(m, l);
- }
-
- IrrelevantStmtSwitch sw = new IrrelevantStmtSwitch();
- for(Unit u : b.getUnits())
- {
- session.setCurrentUnit(u);
-
- Stmt stmt = (Stmt) u;
-
- stmt.apply(sw);
-
- if(sw.relevant)
- {
- if(stmt instanceof AssignStmt)
- {
- generate(m, (AssignStmt) stmt, session);
- }
- else if(stmt instanceof IdentityStmt)
- {
- generate(m, (IdentityStmt) stmt);
- }
- else if(stmt instanceof InvokeStmt)
- {
- _writer.writeInvoke(m, ((InvokeStmt) stmt).getInvokeExpr(), session);
- }
- else if(stmt instanceof ReturnStmt)
- {
- generate(m, (ReturnStmt) stmt, session);
- }
- else if(stmt instanceof ThrowStmt)
- {
- generate(m, (ThrowStmt) stmt, session);
- }
- else
- {
- throw new RuntimeException("Cannot handle statement: " + stmt);
- }
- }
- }
-
- Trap previous = null;
- for(Trap t : b.getTraps())
- {
- _writer.writeExceptionHandler(m, t, session);
- if(previous != null)
- {
- _writer.writeExceptionHandlerPrevious(m, t, previous, session);
- }
-
- previous = t;
- }
- }
-
- /**
- * Assignment statement
- */
- public void generate(SootMethod inMethod, AssignStmt stmt, Session session)
- {
- Value left = stmt.getLeftOp();
-
- if(left instanceof Local)
- {
- generateLeftLocal(inMethod, stmt, session);
- }
- else
- {
- generateLeftNonLocal(inMethod, stmt, session);
- }
- }
-
- public void generateLeftLocal(SootMethod inMethod, AssignStmt stmt, Session session)
- {
- Local left = (Local) stmt.getLeftOp();
- Value right = stmt.getRightOp();
-
- if(right instanceof Local)
- {
- _writer.writeAssignLocal(inMethod, left, (Local) right);
- }
- else if(right instanceof InvokeExpr)
- {
- _writer.writeAssignInvoke(inMethod, left, (InvokeExpr) right, session);
- }
- else if(right instanceof NewExpr)
- {
- _writer.writeAssignHeapAllocation(inMethod, left, (NewExpr) right, session);
- }
- else if(right instanceof NewArrayExpr)
- {
- _writer.writeAssignHeapAllocation(inMethod, left, (NewArrayExpr) right, session);
- }
- else if(right instanceof NewMultiArrayExpr)
- {
- _writer.writeAssignNewMultiArrayExpr(inMethod, left, (NewMultiArrayExpr) right, session);
- }
- else if(right instanceof StringConstant)
- {
- _writer.writeAssignStringConstant(inMethod, left, (StringConstant) right);
- }
- else if(right instanceof ClassConstant)
- {
- _writer.writeAssignClassConstant(inMethod, left, (ClassConstant) right);
- }
- else if(right instanceof InstanceFieldRef)
- {
- InstanceFieldRef ref = (InstanceFieldRef) right;
- _writer.writeLoadInstanceField(inMethod, ref.getField(), (Local) ref.getBase(), left);
- }
- else if(right instanceof StaticFieldRef)
- {
- StaticFieldRef ref = (StaticFieldRef) right;
-
- if(left.getType() instanceof PrimType)
- {
- // These load operations are not relevant for points-to
- // analysis, but they are for class initialization, so they
- // affect the call graph.
- _writer.writeLoadPrimStaticField(inMethod, ref.getField());
- }
- else
- {
- _writer.writeLoadStaticField(inMethod, ref.getField(), left);
- }
- }
- else if(right instanceof ArrayRef)
- {
- ArrayRef ref = (ArrayRef) right;
- Local base = (Local) ref.getBase();
- Value index = ref.getIndex();
-
- if(index instanceof Local || index instanceof IntConstant)
- {
- _writer.writeLoadArrayIndex(inMethod, base, left);
- }
- else
- {
- throw new RuntimeException("Cannot handle assignment: " + stmt + " (index: " + index.getClass() + ")");
- }
- }
- else if(right instanceof CastExpr)
- {
- CastExpr cast = (CastExpr) right;
- Value op = cast.getOp();
-
- if(op instanceof Local)
- {
- _writer.writeAssignCast(inMethod, left, (Local) op, cast.getCastType());
- }
- else if(
- op instanceof IntConstant
- || op instanceof LongConstant
- || op instanceof FloatConstant
- || op instanceof DoubleConstant
- || op instanceof NullConstant
- )
- {
- // ignore, not relevant for pointer analysis
- }
- else
- {
- throw new RuntimeException("Cannot handle assignment: " + stmt + " (op: " + op.getClass() + ")");
- }
- }
- else if(right instanceof PhiExpr)
- {
- for(Value alternative : ((PhiExpr) right).getValues())
- {
- _writer.writeAssignLocal(inMethod, left, (Local) alternative);
- }
- }
- else if(
- right instanceof IntConstant
- || right instanceof LongConstant
- || right instanceof FloatConstant
- || right instanceof DoubleConstant
- || right instanceof NullConstant
- || right instanceof BinopExpr
- || right instanceof NegExpr
- || right instanceof LengthExpr
- || right instanceof InstanceOfExpr)
- {
- // ignore, not relevant for pointer analysis
- }
- else
- {
- throw new RuntimeException("Cannot handle assignment: " + stmt + " (right: " + right.getClass() + ")");
- }
- }
-
- public void generateLeftNonLocal(SootMethod inMethod, AssignStmt stmt, Session session)
- {
- Value left = stmt.getLeftOp();
- Value right = stmt.getRightOp();
-
- // first make sure we have local variable for the right-hand-side.
- Local rightLocal = null;
-
- if(right instanceof Local)
- {
- rightLocal = (Local) right;
- }
- else if(right instanceof StringConstant)
- {
- rightLocal = _writer.writeStringConstantExpression(inMethod, (StringConstant) right, session);
- }
- else if(right instanceof ClassConstant)
- {
- rightLocal = _writer.writeClassConstantExpression(inMethod, (ClassConstant) right, session);
- }
-
- // arrays
- if(left instanceof ArrayRef && rightLocal != null)
- {
- ArrayRef ref = (ArrayRef) left;
- Local base = (Local) ref.getBase();
- _writer.writeStoreArrayIndex(inMethod, base, rightLocal);
- }
- else if(left instanceof ArrayRef &&
- ( right instanceof IntConstant
- || right instanceof LongConstant
- || right instanceof FloatConstant
- || right instanceof DoubleConstant
- || right instanceof NullConstant))
- {
- // skip, not relevant for pointer analysis
- }
- // instance fields
- else if(left instanceof InstanceFieldRef && rightLocal != null)
- {
- InstanceFieldRef ref = (InstanceFieldRef) left;
- _writer.writeStoreInstanceField(inMethod, ref.getField(), (Local) ref.getBase(), rightLocal);
- }
- else if(left instanceof InstanceFieldRef &&
- ( right instanceof IntConstant
- || right instanceof LongConstant
- || right instanceof FloatConstant
- || right instanceof DoubleConstant
- || right instanceof NullConstant))
- {
- // skip, not relevant for pointer analysis
- }
- // static fields
- else if(left instanceof StaticFieldRef && (right.getType() instanceof PrimType || right instanceof NullConstant))
- {
- // These store operations are not relevant for points-to
- // analysis, but they are for class initialization, so they
- // affect the call graph.
- StaticFieldRef ref = (StaticFieldRef) left;
- _writer.writeStorePrimStaticField(inMethod, ref.getField());
-
- // TODO: the NullConstant is a bit hacky. It's the right behaviour, but it's a bit ugly to call this a Prim.
- }
- else if(left instanceof StaticFieldRef && rightLocal != null)
- {
- StaticFieldRef ref = (StaticFieldRef) left;
- _writer.writeStoreStaticField(inMethod, ref.getField(), rightLocal);
- }
- else
- {
- throw new RuntimeException("Cannot handle assignment: " + stmt
- + " (right: " + right.getClass() + ")");
- }
- }
-
- public void generate(SootMethod inMethod, IdentityStmt stmt)
- {
- Value left = stmt.getLeftOp();
- Value right = stmt.getRightOp();
-
- if(right instanceof CaughtExceptionRef) {
- /* Handled by ExceptionHandler generation (ExceptionHandler:FormalParam).
-
- TODO Would be good to check more carefully that a caught
- exception does not occur anywhere else.
- */
- return;
- }
- else if(left instanceof Local && right instanceof ThisRef)
- {
- _writer.writeAssignLocal(inMethod, (Local) left, (ThisRef) right);
- }
- else if(left instanceof Local && right instanceof ParameterRef)
- {
- _writer.writeAssignLocal(inMethod, (Local) left, (ParameterRef) right);
- }
- else
- {
- throw new RuntimeException("Cannot handle identity statement: " + stmt);
- }
- }
-
- /**
- * Return statement
- */
- public void generate(SootMethod inMethod, ReturnStmt stmt, Session session)
- {
- Value v = stmt.getOp();
-
- if(v instanceof Local)
- {
- _writer.writeReturnVar(inMethod, (Local) v);
- }
- else if(v instanceof StringConstant)
- {
- Local tmp = _writer.writeStringConstantExpression(inMethod, (StringConstant) v, session);
- _writer.writeReturnVar(inMethod, tmp);
- }
- else if(v instanceof ClassConstant)
- {
- Local tmp = _writer.writeClassConstantExpression(inMethod, (ClassConstant) v, session);
- _writer.writeReturnVar(inMethod, tmp);
- }
- else if(
- v instanceof IntConstant
- || v instanceof LongConstant
- || v instanceof FloatConstant
- || v instanceof DoubleConstant
- || v instanceof NullConstant)
- {
- // skip, not relevant for pointer analysis
- }
- else
- {
- throw new RuntimeException("Unhandled return statement: " + stmt);
- }
- }
-
- public void generate(SootMethod inMethod, ThrowStmt stmt, Session session)
- {
- Value v = stmt.getOp();
-
- if(v instanceof Local)
- {
- _writer.writeThrow(inMethod, (Local) v, session);
- }
- else if(v instanceof NullConstant)
- {
- // skip, not relevant for pointer analysis.
- }
- else
- {
- throw new RuntimeException("Unhandled throw statement: " + stmt);
- }
- }
+public class FactGenerator {
+ private FactWriter _writer;
+ private boolean _ssa;
+ private Map _cast_dominators;
+ static Map invoke_rep;
+
+ public FactGenerator(FactWriter writer, boolean ssa) {
+ _writer = writer;
+ _writer.writeStandardFacts();
+ _ssa = ssa;
+ }
+
+ public void generate(SootClass c) {
+ // For handling Array.newInstance()
+ _writer.writeArrayType(c);
+
+ _writer.writeClassOrInterfaceType(c);
+
+ // the isInterface condition prevents Object as superclass of interface
+ if (c.hasSuperclass() && !c.isInterface()) {
+ _writer.writeDirectSuperclass(c, c.getSuperclass());
+ }
+
+ for (SootClass i : c.getInterfaces()) {
+ _writer.writeDirectSuperinterface(c, i);
+ }
+
+ for (SootField f : c.getFields()) {
+ generate(f);
+ }
+
+ for (SootMethod m : c.getMethods()) {
+ Session session = new Session();
+ invoke_rep = new HashMap();
+ generate(m, session);
+ }
+
+ // Write class modifier
+ int modifiers = c.getModifiers();
+ if (!c.isInterface()) {
+ if (Modifier.isPublic(modifiers)) {
+ _writer.writeClassModifier(c, "public");
+ }
+ if (Modifier.isProtected(modifiers)) {
+ _writer.writeClassModifier(c, "protected");
+ }
+ if (Modifier.isPrivate(modifiers)) {
+ _writer.writeClassModifier(c, "private");
+ }
+ if (Modifier.isAbstract(modifiers)) {
+ _writer.writeClassModifier(c, "abstract");
+ }
+ if (Modifier.isStatic(modifiers)) {
+ _writer.writeClassModifier(c, "static");
+ }
+ if (Modifier.isFinal(modifiers)) {
+ _writer.writeClassModifier(c, "final");
+ }
+ // TODO interface?
+ // TODO strictfp?
+ // TODO annotation?
+ // TODO enum?
+ }
+ // Output the jimple/shimple files of the class
+ // this method must invoked after generate(m, session),
+ // because the generate(m, session) would set corresponding bodies
+ // (jimple or shimple) to the class.
+ writeClass(c);
+ }
+
+ /*
+ * Output the jimple/shimple files of the class
+ */
+ private void writeClass(SootClass sClass) {
+ int output_format;
+ if (_ssa) {
+ output_format = Options.output_format_shimple;
+ } else {
+ output_format = Options.output_format_jimple;
+ }
+ OutputStream streamOut = null;
+ try {
+ String filename = SourceLocator.v().getFileNameFor(sClass,
+ output_format);
+ streamOut = new FileOutputStream(filename);
+ PrintWriter writerOut = new PrintWriter(new OutputStreamWriter(
+ streamOut));
+ Printer.v().printTo(sClass, writerOut);
+ writerOut.flush();
+ writerOut.close();
+ // release active body
+ for (SootMethod m : sClass.getMethods()) {
+ m.releaseActiveBody();
+ }
+ } catch (FileNotFoundException e) {
+ System.out.println(e.getMessage());
+ e.printStackTrace();
+ } finally {
+ if (streamOut != null)
+ try {
+ streamOut.close();
+ } catch (IOException e) {
+ System.out.println(e.getMessage());
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public void generate(SootField f) {
+ _writer.writeFieldSignature(f);
+
+ int modifiers = f.getModifiers();
+ if (Modifier.isAbstract(modifiers))
+ _writer.writeFieldModifier(f, "abstract");
+ if (Modifier.isFinal(modifiers))
+ _writer.writeFieldModifier(f, "final");
+ if (Modifier.isNative(modifiers))
+ _writer.writeFieldModifier(f, "native");
+ if (Modifier.isPrivate(modifiers))
+ _writer.writeFieldModifier(f, "private");
+ if (Modifier.isProtected(modifiers))
+ _writer.writeFieldModifier(f, "protected");
+ if (Modifier.isPublic(modifiers))
+ _writer.writeFieldModifier(f, "public");
+ if (Modifier.isStatic(modifiers))
+ _writer.writeFieldModifier(f, "static");
+ if (Modifier.isSynchronized(modifiers))
+ _writer.writeFieldModifier(f, "synchronized");
+ if (Modifier.isTransient(modifiers))
+ _writer.writeFieldModifier(f, "transient");
+ if (Modifier.isVolatile(modifiers))
+ _writer.writeFieldModifier(f, "volatile");
+ // TODO interface?
+ // TODO strictfp?
+ // TODO annotation?
+ // TODO enum?
+ }
+
+ public void generate(SootMethod m, Session session) {
+ if (m.isPhantom())
+ return;
+
+ _writer.writeMethodDeclaration(m);
+ _writer.writeMethodSignature(m);
+
+ int modifiers = m.getModifiers();
+ if (Modifier.isAbstract(modifiers))
+ _writer.writeMethodModifier(m, "abstract");
+ if (Modifier.isFinal(modifiers))
+ _writer.writeMethodModifier(m, "final");
+ if (Modifier.isNative(modifiers))
+ _writer.writeMethodModifier(m, "native");
+ if (Modifier.isPrivate(modifiers))
+ _writer.writeMethodModifier(m, "private");
+ if (Modifier.isProtected(modifiers))
+ _writer.writeMethodModifier(m, "protected");
+ if (Modifier.isPublic(modifiers))
+ _writer.writeMethodModifier(m, "public");
+ if (Modifier.isStatic(modifiers))
+ _writer.writeMethodModifier(m, "static");
+ if (Modifier.isSynchronized(modifiers))
+ _writer.writeMethodModifier(m, "synchronized");
+ // TODO would be nice to have isVarArgs in Soot
+ if (Modifier.isTransient(modifiers))
+ _writer.writeMethodModifier(m, "varargs");
+ // TODO would be nice to have isBridge in Soot
+ if (Modifier.isVolatile(modifiers))
+ _writer.writeMethodModifier(m, "bridge");
+ // TODO interface?
+ // TODO strictfp?
+ // TODO annotation?
+ // TODO enum?
+
+ if (!m.isStatic()) {
+ _writer.writeThisVar(m);
+ }
+
+ if (m.isNative()) {
+ _writer.writeNativeReturnVar(m);
+ }
+
+ for (int i = 0; i < m.getParameterCount(); i++) {
+ _writer.writeFormalParam(m, i);
+ }
+
+ for (SootClass clazz : m.getExceptions()) {
+ _writer.writeMethodDeclarationException(m, clazz);
+ }
+
+ if (!(m.isAbstract() || m.isNative())) {
+ if (!m.hasActiveBody()) {
+ m.retrieveActiveBody();
+ }
+
+ Body b = m.getActiveBody();
+ if (_ssa) {
+ b = Shimple.v().newBody(b);
+ m.setActiveBody(b);
+ }
+
+ generate(m, b, session);
+
+ // Release body after writing class
+ // m.releaseActiveBody();
+ }
+ }
+
+ public void generate(SootMethod m, Body b, Session session) {
+ b.validate();
+ session.numberUnits(b.getUnits().iterator());
+ // Obtain the post dominators of current body
+ _cast_dominators = PostDominatorFinder.findCastPostDominator(b);
+
+ for (Local l : b.getLocals()) {
+ _writer.writeLocal(m, l);
+ }
+
+ IrrelevantStmtSwitch sw = new IrrelevantStmtSwitch();
+ for (Unit u : b.getUnits()) {
+ session.setCurrentUnit(u);
+
+ Stmt stmt = (Stmt) u;
+
+ stmt.apply(sw);
+
+ if (sw.relevant) {
+ if (stmt instanceof AssignStmt) {
+ generate(m, (AssignStmt) stmt, session);
+ } else if (stmt instanceof IdentityStmt) {
+ generate(m, (IdentityStmt) stmt);
+ } else if (stmt instanceof InvokeStmt) {
+ _writer.writeInvoke(m, ((InvokeStmt) stmt).getInvokeExpr(),
+ getLineNumberOf(stmt), session);
+ } else if (stmt instanceof ReturnStmt) {
+ generate(m, (ReturnStmt) stmt, session);
+ } else if (stmt instanceof ThrowStmt) {
+ generate(m, (ThrowStmt) stmt, session);
+ } else {
+ throw new RuntimeException("Cannot handle statement: "
+ + stmt);
+ }
+ }
+ }
+
+ Trap previous = null;
+ for (Trap t : b.getTraps()) {
+ _writer.writeExceptionHandler(m, t, session);
+ if (previous != null) {
+ _writer.writeExceptionHandlerPrevious(m, t, previous, session);
+ }
+
+ previous = t;
+ }
+ }
+
+ /**
+ * Assignment statement
+ */
+ public void generate(SootMethod inMethod, AssignStmt stmt, Session session) {
+ Value left = stmt.getLeftOp();
+
+ if (left instanceof Local) {
+ generateLeftLocal(inMethod, stmt, session);
+ // Write post dominate casting facts here
+ // only examine post dominators of local variables
+ if (_cast_dominators.containsKey(stmt)) {
+ String predicate;
+ if (PostDominatorFinder.hasArrayGetCall(stmt)) {
+ predicate = "ArrayGetCast";
+ } else if (PostDominatorFinder.hasClassNewInstanceCall(stmt)) {
+ predicate = "ClassNewInstanceCast";
+ } else if (PostDominatorFinder.hasConstructorNewInstanceCall(stmt)) {
+ predicate = "ConstructorNewInstanceCast";
+ } else if (PostDominatorFinder.hasGetCall(stmt)) {
+ predicate = "FieldGetCast";
+ } else if (PostDominatorFinder.hasInvokeCall(stmt)) {
+ predicate = "InvokeCast";
+ } else { // should not happen
+ return;
+ }
+ _writer.writeCastPostDominator(inMethod, stmt,
+ _cast_dominators.get(stmt), session, predicate);
+ }
+ } else {
+ generateLeftNonLocal(inMethod, stmt, session);
+ }
+ }
+
+ public void generateLeftLocal(SootMethod inMethod, AssignStmt stmt,
+ Session session) {
+ Local left = (Local) stmt.getLeftOp();
+ Value right = stmt.getRightOp();
+
+ if (right instanceof Local) {
+ _writer.writeAssignLocal(inMethod, left, (Local) right);
+ } else if (right instanceof InvokeExpr) {
+ _writer.writeAssignInvoke(inMethod, left, (InvokeExpr) right,
+ getLineNumberOf(stmt), session);
+ } else if (right instanceof NewExpr) {
+ _writer.writeAssignHeapAllocation(inMethod, left, (NewExpr) right,
+ session);
+ } else if (right instanceof NewArrayExpr) {
+ _writer.writeAssignHeapAllocation(inMethod, left,
+ (NewArrayExpr) right, session);
+ } else if (right instanceof NewMultiArrayExpr) {
+ _writer.writeAssignNewMultiArrayExpr(inMethod, left,
+ (NewMultiArrayExpr) right, session);
+ } else if (right instanceof StringConstant) {
+ _writer.writeAssignStringConstant(inMethod, left,
+ (StringConstant) right);
+ } else if (right instanceof ClassConstant) {
+ _writer.writeAssignClassConstant(inMethod, left,
+ (ClassConstant) right);
+ } else if (right instanceof InstanceFieldRef) {
+ InstanceFieldRef ref = (InstanceFieldRef) right;
+ _writer.writeLoadInstanceField(inMethod, ref.getField(),
+ (Local) ref.getBase(), left);
+ } else if (right instanceof StaticFieldRef) {
+ StaticFieldRef ref = (StaticFieldRef) right;
+
+ if (left.getType() instanceof PrimType) {
+ // These load operations are not relevant for points-to
+ // analysis, but they are for class initialization, so they
+ // affect the call graph.
+ _writer.writeLoadPrimStaticField(inMethod, ref.getField());
+ } else {
+ _writer.writeLoadStaticField(inMethod, ref.getField(), left);
+ }
+ } else if (right instanceof ArrayRef) {
+ ArrayRef ref = (ArrayRef) right;
+ Local base = (Local) ref.getBase();
+ Value index = ref.getIndex();
+
+ if (index instanceof Local || index instanceof IntConstant) {
+ _writer.writeLoadArrayIndex(inMethod, base, left);
+ } else {
+ throw new RuntimeException("Cannot handle assignment: " + stmt
+ + " (index: " + index.getClass() + ")");
+ }
+ } else if (right instanceof CastExpr) {
+ CastExpr cast = (CastExpr) right;
+ Value op = cast.getOp();
+
+ if (op instanceof Local) {
+ _writer.writeAssignCast(inMethod, left, (Local) op,
+ cast.getCastType());
+ } else if (op instanceof IntConstant || op instanceof LongConstant
+ || op instanceof FloatConstant
+ || op instanceof DoubleConstant
+ || op instanceof NullConstant) {
+ // ignore, not relevant for pointer analysis
+ } else {
+ throw new RuntimeException("Cannot handle assignment: " + stmt
+ + " (op: " + op.getClass() + ")");
+ }
+ } else if (right instanceof PhiExpr) {
+ for (Value alternative : ((PhiExpr) right).getValues()) {
+ _writer.writeAssignLocal(inMethod, left, (Local) alternative);
+ }
+ } else if (right instanceof IntConstant
+ || right instanceof LongConstant
+ || right instanceof FloatConstant
+ || right instanceof DoubleConstant
+ || right instanceof NullConstant || right instanceof BinopExpr
+ || right instanceof NegExpr || right instanceof LengthExpr
+ || right instanceof InstanceOfExpr) {
+ // ignore, not relevant for pointer analysis
+ } else {
+ throw new RuntimeException("Cannot handle assignment: " + stmt
+ + " (right: " + right.getClass() + ")");
+ }
+ }
+
+ public void generateLeftNonLocal(SootMethod inMethod, AssignStmt stmt,
+ Session session) {
+ Value left = stmt.getLeftOp();
+ Value right = stmt.getRightOp();
+
+ // first make sure we have local variable for the right-hand-side.
+ Local rightLocal = null;
+
+ if (right instanceof Local) {
+ rightLocal = (Local) right;
+ } else if (right instanceof StringConstant) {
+ rightLocal = _writer.writeStringConstantExpression(inMethod,
+ (StringConstant) right, session);
+ } else if (right instanceof ClassConstant) {
+ rightLocal = _writer.writeClassConstantExpression(inMethod,
+ (ClassConstant) right, session);
+ }
+
+ // arrays
+ if (left instanceof ArrayRef && rightLocal != null) {
+ ArrayRef ref = (ArrayRef) left;
+ Local base = (Local) ref.getBase();
+ _writer.writeStoreArrayIndex(inMethod, base, rightLocal);
+ if (ref.getIndex() instanceof IntConstant) {
+ int index = ((IntConstant) ref.getIndex()).value;
+ _writer.writeStoreArrayConstantIndexType(inMethod, base,
+ rightLocal.getType(), index);
+ } else {
+ _writer.writeStoreArrayVarIndexType(inMethod, base,
+ rightLocal.getType());
+ }
+ } else if (left instanceof ArrayRef && right instanceof NullConstant) {
+ ArrayRef ref = (ArrayRef) left;
+ Local base = (Local) ref.getBase();
+ if (ref.getIndex() instanceof IntConstant) {
+ int index = ((IntConstant) ref.getIndex()).value;
+ _writer.writeStoreArrayConstantIndexType(inMethod, base, Scene
+ .v().getRefType("java.lang.Object"), index);
+ } else {
+ _writer.writeStoreArrayVarIndexType(inMethod, base, Scene.v()
+ .getRefType("java.lang.Object"));
+ }
+ } else if (left instanceof ArrayRef
+ && (right instanceof IntConstant
+ || right instanceof LongConstant
+ || right instanceof FloatConstant
+ || right instanceof DoubleConstant || right instanceof NullConstant)) {
+ // skip, not relevant for pointer analysis
+ }
+ // instance fields
+ else if (left instanceof InstanceFieldRef && rightLocal != null) {
+ InstanceFieldRef ref = (InstanceFieldRef) left;
+ _writer.writeStoreInstanceField(inMethod, ref.getField(),
+ (Local) ref.getBase(), rightLocal);
+ } else if (left instanceof InstanceFieldRef
+ && (right instanceof IntConstant
+ || right instanceof LongConstant
+ || right instanceof FloatConstant
+ || right instanceof DoubleConstant || right instanceof NullConstant)) {
+ // skip, not relevant for pointer analysis
+ }
+ // static fields
+ else if (left instanceof StaticFieldRef
+ && (right.getType() instanceof PrimType || right instanceof NullConstant)) {
+ // These store operations are not relevant for points-to
+ // analysis, but they are for class initialization, so they
+ // affect the call graph.
+ StaticFieldRef ref = (StaticFieldRef) left;
+ _writer.writeStorePrimStaticField(inMethod, ref.getField());
+
+ // TODO: the NullConstant is a bit hacky. It's the right behaviour,
+ // but it's a bit ugly to call this a Prim.
+ } else if (left instanceof StaticFieldRef && rightLocal != null) {
+ StaticFieldRef ref = (StaticFieldRef) left;
+ _writer.writeStoreStaticField(inMethod, ref.getField(), rightLocal);
+ } else {
+ throw new RuntimeException("Cannot handle assignment: " + stmt
+ + " (right: " + right.getClass() + ")");
+ }
+ }
+
+ public void generate(SootMethod inMethod, IdentityStmt stmt) {
+ Value left = stmt.getLeftOp();
+ Value right = stmt.getRightOp();
+
+ if (right instanceof CaughtExceptionRef) {
+ /*
+ * Handled by ExceptionHandler generation
+ * (ExceptionHandler:FormalParam).
+ *
+ * TODO Would be good to check more carefully that a caught
+ * exception does not occur anywhere else.
+ */
+ return;
+ } else if (left instanceof Local && right instanceof ThisRef) {
+ _writer.writeAssignLocal(inMethod, (Local) left, (ThisRef) right);
+ } else if (left instanceof Local && right instanceof ParameterRef) {
+ _writer.writeAssignLocal(inMethod, (Local) left,
+ (ParameterRef) right);
+ } else {
+ throw new RuntimeException("Cannot handle identity statement: "
+ + stmt);
+ }
+ }
+
+ /**
+ * Return statement
+ */
+ public void generate(SootMethod inMethod, ReturnStmt stmt, Session session) {
+ Value v = stmt.getOp();
+
+ if (v instanceof Local) {
+ _writer.writeReturnVar(inMethod, (Local) v);
+ } else if (v instanceof StringConstant) {
+ Local tmp = _writer.writeStringConstantExpression(inMethod,
+ (StringConstant) v, session);
+ _writer.writeReturnVar(inMethod, tmp);
+ } else if (v instanceof ClassConstant) {
+ Local tmp = _writer.writeClassConstantExpression(inMethod,
+ (ClassConstant) v, session);
+ _writer.writeReturnVar(inMethod, tmp);
+ } else if (v instanceof IntConstant || v instanceof LongConstant
+ || v instanceof FloatConstant || v instanceof DoubleConstant
+ || v instanceof NullConstant) {
+ // skip, not relevant for pointer analysis
+ } else {
+ throw new RuntimeException("Unhandled return statement: " + stmt);
+ }
+ }
+
+ public void generate(SootMethod inMethod, ThrowStmt stmt, Session session) {
+ Value v = stmt.getOp();
+
+ if (v instanceof Local) {
+ _writer.writeThrow(inMethod, (Local) v, session);
+ } else if (v instanceof NullConstant) {
+ // skip, not relevant for pointer analysis.
+ } else {
+ throw new RuntimeException("Unhandled throw statement: " + stmt);
+ }
+ }
+
+ public static int getLineNumberOf(Unit unit) {
+ int line = -1;
+ //get line from source
+ SourceLnPosTag tag = (SourceLnPosTag) unit.getTag("SourceLnPosTag");
+ if (tag != null) {
+ line = tag.startLn();
+ } else {
+ //get line from bytecode
+ LineNumberTag tag2 = (LineNumberTag) unit.getTag("LineNumberTag");
+ if (tag2 != null) {
+ line = tag2.getLineNumber();
+ }
+ }
+ return line;
+ }
}
diff -urN soot-fact-generation-r958-src/src/FactWriter.java solar-gen/src/FactWriter.java
--- soot-fact-generation-r958-src/src/FactWriter.java 2009-06-04 13:07:30.000000000 +1000
+++ solar-gen/src/FactWriter.java 2015-05-28 15:13:02.000000000 +1000
@@ -1,748 +1,737 @@
+import soot.ArrayType;
import soot.Local;
+import soot.NullType;
+import soot.PrimType;
import soot.RefLikeType;
+import soot.RefType;
import soot.SootClass;
import soot.SootField;
import soot.SootMethod;
import soot.Trap;
-
import soot.Type;
-import soot.PrimType;
-import soot.RefType;
-import soot.NullType;
-import soot.ArrayType;
-
-
import soot.Unit;
import soot.Value;
-import soot.jimple.*;
+import soot.jimple.AnyNewExpr;
+import soot.jimple.AssignStmt;
+import soot.jimple.CaughtExceptionRef;
+import soot.jimple.ClassConstant;
+import soot.jimple.DoubleConstant;
+import soot.jimple.FloatConstant;
+import soot.jimple.IdentityStmt;
+import soot.jimple.InstanceInvokeExpr;
+import soot.jimple.IntConstant;
+import soot.jimple.InterfaceInvokeExpr;
+import soot.jimple.InvokeExpr;
+import soot.jimple.LongConstant;
+import soot.jimple.NewArrayExpr;
+import soot.jimple.NewMultiArrayExpr;
+import soot.jimple.NullConstant;
+import soot.jimple.ParameterRef;
+import soot.jimple.SpecialInvokeExpr;
+import soot.jimple.StaticInvokeExpr;
+import soot.jimple.StringConstant;
+import soot.jimple.ThisRef;
+import soot.jimple.VirtualInvokeExpr;
import soot.jimple.internal.JimpleLocal;
/**
- * FactWriter determines the format of a fact and adds it to a
- * database. No traversal code here (see FactGenerator for that).
+ * FactWriter determines the format of a fact and adds it to a database. No
+ * traversal code here (see FactGenerator for that).
*
* @author Martin Bravenboer
* @license MIT
*/
-public class FactWriter
-{
+public class FactWriter {
+
+ private Database _db;
+ private Representation _rep;
+
+ public FactWriter(Database db) {
+ _db = db;
+ _rep = new Representation();
+ }
+
+ // For handling one dimension Array.newInstance(): reference type
+ public void writeArrayType(SootClass c) {
+ String componentType = _rep.type(c);
+ String arrayType = componentType + "[]";
+ Column col = _db.addEntity("ArrayType", arrayType);
+ _db.add("ComponentType", col, new Column(componentType));
+ }
+
+ public void writeStandardFacts() {
+ _db.addEntity("NullType", "null_type");
+
+ final String[] primType = { "boolean", "byte", "char", "short", "int",
+ "long", "float", "double" };
+
+ for (String t : primType) {
+ _db.addEntity("PrimitiveType", t);
+ // For handling one dimension Array.newInstance(): primitive type
+ String arr_t = t + "[]";
+ _db.add("ComponentType", _db.addEntity("ArrayType", arr_t),
+ new Column(t));
+
+ Column prim_class = _db.addEntity("ClassConstant", "");
+ Column prim_arr_class = _db.addEntity("ClassConstant", "");
+ _db.add("ReifiedClass", new Column(t), prim_class);
+ _db.add("ReifiedClass", new Column(arr_t), prim_arr_class);
+ }
+ }
+
+ public void writeClassOrInterfaceType(SootClass c) {
+ String rep = _rep.type(c);
+ Column col;
+
+ if (c.isInterface()) {
+ col = _db.addEntity("InterfaceType", rep);
+ } else {
+ col = _db.addEntity("ClassType", rep);
+ }
+
+ Column constant = _db.addEntity("ClassConstant", _rep.classconstant(c));
+ _db.add("ReifiedClass", col, constant);
+ _db.add("HeapAllocation-Type", constant,
+ _db.addEntity("ClassType", "java.lang.Class"));
+ }
+
+ public void writeDirectSuperclass(SootClass sub, SootClass sup) {
+ _db.add("DirectSuperclass", writeType(sub), writeType(sup));
+ }
+
+ public void writeDirectSuperinterface(SootClass clazz, SootClass iface) {
+ _db.add("DirectSuperinterface", writeType(clazz), writeType(iface));
+ }
+
+ public Column writeType(SootClass c) {
+ String result = _rep.type(c);
+
+ // The type itself is already taken care of by writing the
+ // SootClass declaration, so we don't actually write the type
+ // here, and just return the string.
+
+ return _db.asEntity(result);
+ }
+
+ public Column writeType(Type t) {
+ String result = _rep.type(t);
+ Column c;
+
+ if (t instanceof ArrayType) {
+ // For handling Class:getComponentType
+ c = _db.addEntity("ArrayType", result);
+ Type componentType = ((ArrayType) t).getElementType();
+ _db.add("ComponentType", c, writeType(componentType));
+
+ String rep = _rep.classconstant(t);
+ _db.add("ReifiedClass", _db.asEntity(result), _db.asEntity(rep));
+ } else if (t instanceof PrimType || t instanceof NullType) {
+ // taken care of by the standard facts
+ c = _db.asEntity(result);
+ } else if (t instanceof RefType) {
+ // taken care of by SootClass declaration.
+ c = _db.asEntity(result);
+ } else {
+ throw new RuntimeException("Don't know what to do with type " + t);
+ }
+
+ return c;
+ }
+
+ public void writeAssignLocal(SootMethod m, Local to, Local from) {
+ if (to.getType() instanceof RefLikeType) {
+ _db.add("AssignLocal",
+ _db.addEntity("VarRef", _rep.local(m, from)),
+ _db.addEntity("VarRef", _rep.local(m, to)),
+ _db.addEntity("MethodSignatureRef", _rep.method(m)));
+ }
+ }
+
+ public void writeAssignLocal(SootMethod m, Local to, ThisRef ref) {
+ _db.add("AssignLocal", _db.addEntity("VarRef", _rep.thisVar(m)),
+ _db.addEntity("VarRef", _rep.local(m, to)),
+ _db.addEntity("MethodSignatureRef", _rep.method(m)));
+ }
+
+ public void writeAssignLocal(SootMethod m, Local to, ParameterRef ref) {
+ if (to.getType() instanceof RefLikeType) {
+ _db.add("AssignLocal",
+ _db.addEntity("VarRef", _rep.param(m, ref.getIndex())),
+ _db.addEntity("VarRef", _rep.local(m, to)),
+ _db.addEntity("MethodSignatureRef", _rep.method(m)));
+ }
+ }
+
+ public void writeAssignInvoke(SootMethod inMethod, Local to,
+ InvokeExpr expr, int lineNumber, Session session) {
+ String rep = writeInvokeHelper(inMethod, expr, lineNumber, session);
+
+ if (to.getType() instanceof RefLikeType) {
+ _db.add("AssignReturnValue",
+ _db.addEntity("MethodInvocationRef", rep),
+ _db.addEntity("VarRef", _rep.local(inMethod, to)));
+ }
+ }
+
+ public void writeAssignHeapAllocation(SootMethod m, Local l,
+ AnyNewExpr expr, Session session) {
+ String rep = _rep.heapAlloc(m, expr, session);
+
+ _db.add("AssignHeapAllocation",
+ _db.addEntity("NormalHeapAllocationRef", rep),
+ _db.addEntity("VarRef", _rep.local(m, l)),
+ _db.addEntity("MethodSignatureRef", _rep.method(m)));
+
+ _db.addEntity("NormalHeapAllocationRef", rep);
+
+ _db.add("HeapAllocation-Type", _db.asEntity(rep),
+ writeType(expr.getType()));
+ // write array size for matching argument
+ if (expr instanceof NewArrayExpr) {
+ Value size = ((NewArrayExpr) expr).getSize();
+ if (size instanceof IntConstant) {
+ _db.add("NewArraySize",
+ _db.addEntity("NormalHeapAllocationRef", rep),
+ _db.asIntColumn(_rep.index(((IntConstant) size).value)));
+
+ }
+ }
+ }
+
+ private Type getComponentType(ArrayType type) {
+ // Soot calls the component type of an array type the "element
+ // type", which is rather confusing, since in an array type
+ // A[][][], the JVM Spec defines A to be the element type, and
+ // A[][] is the component type.
+ return type.getElementType();
+ }
+
+ /**
+ * NewMultiArray is slightly complicated because an array needs to be
+ * allocated separately for every dimension of the array.
+ */
+ public void writeAssignNewMultiArrayExpr(SootMethod m, Local l,
+ NewMultiArrayExpr expr, Session session) {
+ Type type = (ArrayType) expr.getType();
+
+ // local variable to assign the current array allocation to.
+ String assignTo = _rep.local(m, l);
+
+ while (type instanceof ArrayType) {
+ ArrayType arrayType = (ArrayType) type;
+ String rep = _rep.heapMultiArrayAlloc(m, expr, arrayType, session);
+
+ // assign the the current allocation to assignTo
+ _db.add("AssignHeapAllocation",
+ _db.addEntity("NormalHeapAllocationRef", rep),
+ _db.addEntity("VarRef", assignTo),
+ _db.addEntity("MethodSignatureRef", _rep.method(m)));
+
+ _db.addEntity("NormalHeapAllocationRef", rep);
+
+ // write the type of the current allocation
+ _db.add("HeapAllocation-Type", _db.asEntity(rep),
+ writeType(arrayType));
+
+ type = getComponentType(arrayType);
+ if (type instanceof ArrayType) {
+ // there is a subarray to allocate and assign to the array.
+
+ String base = assignTo;
+ assignTo = _rep.newLocalIntermediate(m, l, session);
+
+ // assign the subarray to the array of dim+1
+ _db.add("StoreArrayIndex", _db.addEntity("VarRef", assignTo),
+ _db.addEntity("VarRef", base),
+ _db.addEntity("MethodSignatureRef", _rep.method(m)));
+
+ // the assignTo is a fresh variable, so we need to write a
+ // fact for its type and the declaring method.
+ _db.add("Var-Type", _db.asEntity(assignTo), writeType(type));
+
+ _db.add("Var-DeclaringMethod", _db.asEntity(assignTo),
+ _db.asEntity(_rep.method(m)));
+ }
+ }
+ }
+
+ public void writeAssignStringConstant(SootMethod m, Local l,
+ StringConstant s) {
+ String rep = _rep.stringconstant(m, s);
+
+ _db.add("AssignHeapAllocation", _db.addEntity("StringConstant", rep),
+ _db.addEntity("VarRef", _rep.local(m, l)),
+ _db.addEntity("MethodSignatureRef", _rep.method(m)));
+
+ _db.add("HeapAllocation-Type", _db.asEntity(rep),
+ writeType(s.getType()));
+ }
+
+ public void writeAssignClassConstant(SootMethod m, Local l,
+ ClassConstant constant) {
+ // System.err.println("class constant " + constant + " in " + m);
+ String s = constant.getValue().replace('/', '.');
+
+ String rep;
+
+ /*
+ * There is some weirdness in class constants: normal Java class types
+ * seem to have been translated to a syntax with the initial L, but
+ * arrays are still represented as [, for example [C for char[]
+ */
+ if (s.charAt(0) == '[') {
+ // array type
+ Type t = soot.coffi.Util.v().jimpleTypeOfFieldDescriptor(s);
+
+ rep = _rep.classconstant(t);
+ _db.add("ReifiedClass", _db.asEntity(_rep.type(t)),
+ _db.asEntity(rep));
+
+ // TODO only classes have their heap allocation type written already
+ } else {
+ SootClass c = soot.Scene.v().getSootClass(s);
+ if (c == null) {
+ throw new RuntimeException("Unexpected class constant: "
+ + constant);
+ }
+
+ rep = _rep.classconstant(c);
+ }
+
+ _db.add("AssignHeapAllocation", _db.asEntity(rep),
+ _db.addEntity("VarRef", _rep.local(m, l)),
+ _db.addEntity("MethodSignatureRef", _rep.method(m)));
+ }
+
+ public void writeAssignCast(SootMethod m, Local to, Local from, Type t) {
+ if (to.getType() instanceof RefLikeType
+ && from.getType() instanceof RefLikeType) {
+ _db.add("AssignCast", writeType(t),
+ _db.addEntity("VarRef", _rep.local(m, from)),
+ _db.addEntity("VarRef", _rep.local(m, to)),
+ _db.addEntity("MethodSignatureRef", _rep.method(m)));
+ } else {
+ if (to.getType() instanceof RefLikeType
+ || from.getType() instanceof RefLikeType) {
+ throw new RuntimeException(
+ "error: didn't expect cast involving one reference type");
+ } else {
+ // cast from prim to prim, not relevant for pointer analysis.
+ }
+ }
+ }
+
+ public void writeStoreInstanceField(SootMethod m, SootField f, Local base,
+ Local from) {
+ if (f.getType() instanceof RefLikeType) {
+ _db.add("StoreInstanceField",
+ _db.addEntity("VarRef", _rep.local(m, from)),
+ _db.addEntity("VarRef", _rep.local(m, base)),
+ _db.addEntity("FieldSignatureRef", _rep.signature(f)),
+ _db.addEntity("MethodSignatureRef", _rep.method(m)));
+ }
+ }
+
+ public void writeLoadInstanceField(SootMethod m, SootField f, Local base,
+ Local to) {
+ if (to.getType() instanceof RefLikeType) {
+ _db.add("LoadInstanceField",
+ _db.addEntity("VarRef", _rep.local(m, base)),
+ _db.addEntity("FieldSignatureRef", _rep.signature(f)),
+ _db.addEntity("VarRef", _rep.local(m, to)),
+ _db.addEntity("MethodSignatureRef", _rep.method(m)));
+ }
+ }
+
+ public void writeStoreStaticField(SootMethod m, SootField f, Local from) {
+ _db.add("StoreStaticField",
+ _db.addEntity("VarRef", _rep.local(m, from)),
+ _db.addEntity("FieldSignatureRef", _rep.signature(f)),
+ _db.addEntity("MethodSignatureRef", _rep.method(m)));
+ }
+
+ public void writeStorePrimStaticField(SootMethod m, SootField f) {
+ _db.add("StorePrimStaticField",
+ _db.addEntity("FieldSignatureRef", _rep.signature(f)),
+ _db.addEntity("MethodSignatureRef", _rep.method(m)));
+ }
- private Database _db;
- private Representation _rep;
+ public void writeLoadStaticField(SootMethod m, SootField f, Local to) {
+ _db.add("LoadStaticField",
+ _db.addEntity("FieldSignatureRef", _rep.signature(f)),
+ _db.addEntity("VarRef", _rep.local(m, to)),
+ _db.addEntity("MethodSignatureRef", _rep.method(m)));
+ }
+
+ public void writeLoadPrimStaticField(SootMethod m, SootField f) {
+ _db.add("LoadPrimStaticField",
+ _db.addEntity("FieldSignatureRef", _rep.signature(f)),
+ _db.addEntity("MethodSignatureRef", _rep.method(m)));
+ }
+
+ public void writeLoadArrayIndex(SootMethod m, Local base, Local to) {
+ if (to.getType() instanceof RefLikeType) {
+ _db.add("LoadArrayIndex",
+ _db.addEntity("VarRef", _rep.local(m, base)),
+ _db.addEntity("VarRef", _rep.local(m, to)),
+ _db.addEntity("MethodSignatureRef", _rep.method(m)));
+ }
+ }
+
+ public void writeStoreArrayIndex(SootMethod m, Local base, Local from) {
+ if (from.getType() instanceof RefLikeType) {
+ _db.add("StoreArrayIndex",
+ _db.addEntity("VarRef", _rep.local(m, from)),
+ _db.addEntity("VarRef", _rep.local(m, base)),
+ _db.addEntity("MethodSignatureRef", _rep.method(m)));
+ }
+ }
+
+ public void writeApplicationClass(SootClass application) {
+ _db.add("ApplicationClass", writeType(application));
+ }
+
+ public void writeFieldSignature(SootField f) {
+ _db.add("FieldSignature",
+ _db.addEntity("FieldSignatureRef", _rep.signature(f)),
+ writeType(f.getDeclaringClass()),
+ _db.addEntity("SimpleNameRef", _rep.simpleName(f)),
+ writeType(f.getType()));
+ }
+
+ public void writeFieldModifier(SootField f, String modifier) {
+ _db.add("FieldModifier",
+ _db.addEntity("ModifierRef", _rep.modifier(modifier)),
+ _db.addEntity("FieldSignatureRef", _rep.signature(f)));
+ }
+
+ public void writeMethodDeclaration(SootMethod m) {
+ _db.add("MethodDeclaration",
+ _db.addEntity("MethodSignatureRef", _rep.signature(m)),
+ _db.addEntity("MethodSignatureRef", _rep.method(m)));
+ }
+
+ public void writeMethodSignature(SootMethod m) {
+
+ _db.add("MethodSignature-SimpleName",
+ _db.addEntity("MethodSignatureRef", _rep.signature(m)),
+ _db.addEntity("SimpleNameRef", _rep.simpleName(m)));
+ _db.add("MethodSignature-Descriptor",
+ _db.addEntity("MethodSignatureRef", _rep.signature(m)),
+ _db.addEntity("MethodDescriptorRef", _rep.descriptor(m)));
+ _db.add("MethodSignature-Type",
+ _db.addEntity("MethodSignatureRef", _rep.signature(m)),
+ writeType(m.getDeclaringClass()));
+ // Return type is used for precisely resolve Method.invoke
+ Type t = m.getReturnType();
+ if (!t.toString().equals("void")) {
+ _db.add("MethodSignature-ReturnType",
+ _db.addEntity("MethodSignatureRef", _rep.signature(m)),
+ writeType(t));
+ }
+ // Number of parameters used for matching arguments
+ _db.add("NrFormalParam",
+ _db.addEntity("MethodSignatureRef", _rep.signature(m)),
+ _db.asEntity(_rep.index(m.getParameterCount())));
+ }
+
+ public void writeMethodModifier(SootMethod m, String modifier) {
+ _db.add("MethodModifier",
+ _db.addEntity("ModifierRef", _rep.modifier(modifier)),
+ _db.addEntity("MethodSignatureRef", _rep.method(m)));
+ }
+
+ public void writeReturnVar(SootMethod m, Local l) {
+ if (l.getType() instanceof RefLikeType) {
+ _db.add("ReturnVar", _db.addEntity("VarRef", _rep.local(m, l)),
+ _db.addEntity("MethodSignatureRef", _rep.method(m)));
+
+ _db.add("Var-Type", _db.addEntity("VarRef", _rep.local(m, l)),
+ writeType(l.getType()));
+ }
+ }
+
+ public void writeNativeReturnVar(SootMethod m) {
+ if (m.getReturnType() instanceof RefLikeType) {
+ _db.add("ReturnVar",
+ _db.addEntity("VarRef", _rep.nativeReturnVar(m)),
+ _db.addEntity("MethodSignatureRef", _rep.method(m)));
+
+ _db.add("Var-Type", _db.asEntity(_rep.nativeReturnVar(m)),
+ writeType(m.getReturnType()));
+
+ _db.add("Var-DeclaringMethod",
+ _db.asEntity(_rep.nativeReturnVar(m)),
+ _db.asEntity(_rep.method(m)));
+ }
+ }
+
+ /**
+ * Throw statement
+ */
+ public void writeThrow(SootMethod m, Local l, Session session) {
+ String rep = _rep.throwLocal(m, l, session);
+
+ _db.add("Throw", _db.addEntity("ThrowRef", rep),
+ _db.addEntity("VarRef", _rep.local(m, l)));
+ _db.add("Throw-Method", _db.addEntity("ThrowRef", rep),
+ _db.addEntity("MethodSignatureRef", _rep.method(m)));
+
+ int index = session.getUnitNumber(session.getCurrentUnit());
+
+ _db.add("Instruction-Index", _db.asEntity(rep),
+ _db.asIntColumn(String.valueOf(index)));
+ }
+
+ public void writeExceptionHandlerPrevious(SootMethod m, Trap current,
+ Trap previous, Session session) {
+ _db.add("ExceptionHandler-Previous",
+ _db.addEntity("ExceptionHandlerRef",
+ _rep.handler(m, current, session)),
+ _db.addEntity("ExceptionHandlerRef",
+ _rep.handler(m, previous, session)));
+ }
+
+ public void writeExceptionHandler(SootMethod m, Trap handler,
+ Session session) {
+ SootClass exc = handler.getException();
+
+ Local caught;
+ {
+ Unit handlerUnit = handler.getHandlerUnit();
+ IdentityStmt stmt = (IdentityStmt) handlerUnit;
+ Value left = stmt.getLeftOp();
+ Value right = stmt.getRightOp();
+
+ if (right instanceof CaughtExceptionRef && left instanceof Local) {
+ caught = (Local) left;
+ } else {
+ throw new RuntimeException(
+ "Unexpected start of exception handler: " + handlerUnit);
+ }
+ }
+
+ /* simple fact for Paddle compatibility mode */
+ _db.add("SimpleExceptionHandler", _db.asEntity(_rep.type(exc)),
+ _db.addEntity("VarRef", _rep.local(m, caught)),
+ _db.addEntity("MethodSignatureRef", _rep.method(m)));
+
+ String rep = _rep.handler(m, handler, session);
+ _db.addEntity("ExceptionHandlerRef", rep);
+
+ _db.add("ExceptionHandler-Method", _db.asEntity(rep),
+ _db.asEntity(_rep.method(m)));
+
+ _db.add("ExceptionHandler-Type", _db.asEntity(rep),
+ _db.asEntity(_rep.type(exc)));
+
+ _db.add("ExceptionHandler-FormalParam", _db.asEntity(rep),
+ _db.asEntity(_rep.local(m, caught)));
+
+ _db.add("ExceptionHandler-Begin", _db.asEntity(rep), _db
+ .asIntColumn(String.valueOf(session.getUnitNumber(handler
+ .getBeginUnit()))));
+
+ _db.add("ExceptionHandler-End", _db.asEntity(rep), _db
+ .asIntColumn(String.valueOf(session.getUnitNumber(handler
+ .getEndUnit()))));
+ }
- public FactWriter(Database db)
- {
- _db = db;
- _rep = new Representation();
- }
-
- public void writeStandardFacts()
- {
- _db.addEntity("PrimitiveType", "boolean");
- _db.addEntity("PrimitiveType", "byte");
- _db.addEntity("PrimitiveType", "char");
- _db.addEntity("PrimitiveType", "short");
- _db.addEntity("PrimitiveType", "int");
- _db.addEntity("PrimitiveType", "long");
- _db.addEntity("PrimitiveType", "float");
- _db.addEntity("PrimitiveType", "double");
- _db.addEntity("NullType", "null_type");
- }
-
- public void writeClassOrInterfaceType(SootClass c)
- {
- String rep = _rep.type(c);
- Column col;
-
- if(c.isInterface())
- {
- col = _db.addEntity("InterfaceType", rep);
- }
- else
- {
- col = _db.addEntity("ClassType", rep);
- }
-
- Column constant = _db.addEntity("ClassConstant", _rep.classconstant(c));
- _db.add("ReifiedClass", col, constant);
- _db.add("HeapAllocation-Type", constant, _db.addEntity("ClassType", "java.lang.Class"));
- }
-
- public void writeDirectSuperclass(SootClass sub, SootClass sup)
- {
- _db.add("DirectSuperclass",
- writeType(sub),
- writeType(sup));
- }
-
- public void writeDirectSuperinterface(SootClass clazz, SootClass iface)
- {
- _db.add("DirectSuperinterface",
- writeType(clazz),
- writeType(iface));
- }
-
- public Column writeType(SootClass c)
- {
- String result = _rep.type(c);
-
- // The type itself is already taken care of by writing the
- // SootClass declaration, so we don't actually write the type
- // here, and just return the string.
-
- return _db.asEntity(result);
- }
-
- public Column writeType(Type t)
- {
- String result = _rep.type(t);
- Column c;
-
- if(t instanceof ArrayType)
- {
- c = _db.addEntity("ArrayType", result);
- Type componentType = ((ArrayType) t).getElementType();
- _db.add("ComponentType", c, writeType(componentType));
- }
- else if(t instanceof PrimType || t instanceof NullType)
- {
- // taken care of by the standard facts
- c = _db.asEntity(result);
- }
- else if(t instanceof RefType)
- {
- // taken care of by SootClass declaration.
- c = _db.asEntity(result);
- }
- else
- {
- throw new RuntimeException("Don't know what to do with type " + t);
- }
-
- return c;
- }
-
- public void writeAssignLocal(SootMethod m, Local to, Local from)
- {
- if(to.getType() instanceof RefLikeType)
- {
- _db.add("AssignLocal",
- _db.addEntity("VarRef", _rep.local(m, from)),
- _db.addEntity("VarRef", _rep.local(m, to)),
- _db.addEntity("MethodSignatureRef", _rep.method(m)));
- }
- }
-
- public void writeAssignLocal(SootMethod m, Local to, ThisRef ref)
- {
- _db.add("AssignLocal",
- _db.addEntity("VarRef", _rep.thisVar(m)),
- _db.addEntity("VarRef", _rep.local(m, to)),
- _db.addEntity("MethodSignatureRef", _rep.method(m)));
- }
-
- public void writeAssignLocal(SootMethod m, Local to, ParameterRef ref)
- {
- if(to.getType() instanceof RefLikeType)
- {
- _db.add("AssignLocal",
- _db.addEntity("VarRef", _rep.param(m, ref.getIndex())),
- _db.addEntity("VarRef", _rep.local(m, to)),
- _db.addEntity("MethodSignatureRef", _rep.method(m)));
- }
- }
-
- public void writeAssignInvoke(SootMethod inMethod, Local to, InvokeExpr expr, Session session)
- {
- String rep = writeInvokeHelper(inMethod, expr, session);
-
- if(to.getType() instanceof RefLikeType)
- {
- _db.add("AssignReturnValue",
- _db.addEntity("MethodInvocationRef", rep),
- _db.addEntity("VarRef", _rep.local(inMethod, to)));
- }
- }
-
- public void writeAssignHeapAllocation(SootMethod m, Local l, AnyNewExpr expr, Session session)
- {
- String rep = _rep.heapAlloc(m, expr, session);
-
- _db.add("AssignHeapAllocation",
- _db.addEntity("NormalHeapAllocationRef", rep),
- _db.addEntity("VarRef", _rep.local(m, l)),
- _db.addEntity("MethodSignatureRef", _rep.method(m)));
-
-
- _db.addEntity("NormalHeapAllocationRef", rep);
-
- _db.add("HeapAllocation-Type",
- _db.asEntity(rep),
- writeType(expr.getType()));
- }
-
- private Type getComponentType(ArrayType type)
- {
- // Soot calls the component type of an array type the "element
- // type", which is rather confusing, since in an array type
- // A[][][], the JVM Spec defines A to be the element type, and
- // A[][] is the component type.
- return type.getElementType();
- }
-
- /**
- * NewMultiArray is slightly complicated because an array needs to
- * be allocated separately for every dimension of the array.
- */
- public void writeAssignNewMultiArrayExpr(SootMethod m, Local l, NewMultiArrayExpr expr, Session session)
- {
- Type type = (ArrayType) expr.getType();
-
- // local variable to assign the current array allocation to.
- String assignTo = _rep.local(m, l);
-
- while(type instanceof ArrayType)
- {
- ArrayType arrayType = (ArrayType) type;
- String rep = _rep.heapMultiArrayAlloc(m, expr, arrayType, session);
-
- // assign the the current allocation to assignTo
- _db.add("AssignHeapAllocation",
- _db.addEntity("NormalHeapAllocationRef", rep),
- _db.addEntity("VarRef", assignTo),
- _db.addEntity("MethodSignatureRef", _rep.method(m))
- );
-
- _db.addEntity("NormalHeapAllocationRef", rep);
-
-
- // write the type of the current allocation
- _db.add("HeapAllocation-Type",
- _db.asEntity(rep),
- writeType(arrayType));
-
- type = getComponentType(arrayType);
- if(type instanceof ArrayType)
- {
- // there is a subarray to allocate and assign to the array.
-
- String base = assignTo;
- assignTo = _rep.newLocalIntermediate(m, l, session);
-
- // assign the subarray to the array of dim+1
- _db.add("StoreArrayIndex",
- _db.addEntity("VarRef", assignTo),
- _db.addEntity("VarRef", base),
- _db.addEntity("MethodSignatureRef", _rep.method(m)));
-
- // the assignTo is a fresh variable, so we need to write a
- // fact for its type and the declaring method.
- _db.add("Var-Type",
- _db.asEntity(assignTo),
- writeType(type));
-
- _db.add("Var-DeclaringMethod",
- _db.asEntity(assignTo),
- _db.asEntity(_rep.method(m)));
- }
- }
- }
-
- public void writeAssignStringConstant(SootMethod m, Local l, StringConstant s)
- {
- String rep = _rep.stringconstant(m, s);
-
- _db.add("AssignHeapAllocation",
- _db.addEntity("StringConstant", rep),
- _db.addEntity("VarRef", _rep.local(m, l)),
- _db.addEntity("MethodSignatureRef", _rep.method(m)));
-
- _db.add("HeapAllocation-Type",
- _db.asEntity(rep),
- writeType(s.getType()));
- }
-
- public void writeAssignClassConstant(SootMethod m, Local l, ClassConstant constant)
- {
- // System.err.println("class constant " + constant + " in " + m);
- String s = constant.getValue().replace('/', '.');
-
- String rep;
-
- /* There is some weirdness in class constants: normal Java class
- types seem to have been translated to a syntax with the initial
- L, but arrays are still represented as [, for example [C for
- char[] */
- if(s.charAt(0) == '[')
- {
- // array type
- Type t = soot.coffi.Util.v().jimpleTypeOfFieldDescriptor(s);
-
- rep = _rep.classconstant(t);
- _db.add("ReifiedClass", _db.asEntity(_rep.type(t)), _db.asEntity(rep));
-
- // TODO only classes have their heap allocation type written already
- }
- else
- {
- SootClass c = soot.Scene.v().getSootClass(s);
- if(c == null)
- {
- throw new RuntimeException("Unexpected class constant: " + constant);
- }
-
- rep = _rep.classconstant(c);
- }
-
- _db.add("AssignHeapAllocation",
- _db.asEntity(rep),
- _db.addEntity("VarRef", _rep.local(m, l)),
- _db.addEntity("MethodSignatureRef", _rep.method(m)));
- }
-
- public void writeAssignCast(SootMethod m, Local to, Local from, Type t)
- {
- if(to.getType() instanceof RefLikeType && from.getType() instanceof RefLikeType)
- {
- _db.add("AssignCast",
- writeType(t),
- _db.addEntity("VarRef", _rep.local(m, from)),
- _db.addEntity("VarRef", _rep.local(m, to)),
- _db.addEntity("MethodSignatureRef", _rep.method(m)));
- }
- else
- {
- if(to.getType() instanceof RefLikeType || from.getType() instanceof RefLikeType)
- {
- throw new RuntimeException("error: didn't expect cast involving one reference type");
- }
- else
- {
- // cast from prim to prim, not relevant for pointer analysis.
- }
- }
- }
-
- public void writeStoreInstanceField(SootMethod m, SootField f, Local base, Local from)
- {
- if(f.getType() instanceof RefLikeType)
- {
- _db.add("StoreInstanceField",
- _db.addEntity("VarRef", _rep.local(m, from)),
- _db.addEntity("VarRef", _rep.local(m, base)),
- _db.addEntity("FieldSignatureRef", _rep.signature(f)),
- _db.addEntity("MethodSignatureRef", _rep.method(m)));
- }
- }
-
- public void writeLoadInstanceField(SootMethod m, SootField f, Local base, Local to)
- {
- if(to.getType() instanceof RefLikeType)
- {
- _db.add("LoadInstanceField",
- _db.addEntity("VarRef", _rep.local(m, base)),
- _db.addEntity("FieldSignatureRef", _rep.signature(f)),
- _db.addEntity("VarRef", _rep.local(m, to)),
- _db.addEntity("MethodSignatureRef", _rep.method(m)));
- }
- }
-
- public void writeStoreStaticField(SootMethod m, SootField f, Local from)
- {
- _db.add("StoreStaticField",
- _db.addEntity("VarRef", _rep.local(m, from)),
- _db.addEntity("FieldSignatureRef", _rep.signature(f)),
- _db.addEntity("MethodSignatureRef", _rep.method(m)));
- }
-
- public void writeStorePrimStaticField(SootMethod m, SootField f)
- {
- _db.add("StorePrimStaticField",
- _db.addEntity("FieldSignatureRef", _rep.signature(f)),
- _db.addEntity("MethodSignatureRef", _rep.method(m)));
- }
-
- public void writeLoadStaticField(SootMethod m, SootField f, Local to)
- {
- _db.add("LoadStaticField",
- _db.addEntity("FieldSignatureRef", _rep.signature(f)),
- _db.addEntity("VarRef", _rep.local(m, to)),
- _db.addEntity("MethodSignatureRef", _rep.method(m)));
- }
-
- public void writeLoadPrimStaticField(SootMethod m, SootField f)
- {
- _db.add("LoadPrimStaticField",
- _db.addEntity("FieldSignatureRef", _rep.signature(f)),
- _db.addEntity("MethodSignatureRef", _rep.method(m)));
- }
-
- public void writeLoadArrayIndex(SootMethod m, Local base, Local to)
- {
- if(to.getType() instanceof RefLikeType)
- {
- _db.add("LoadArrayIndex",
- _db.addEntity("VarRef", _rep.local(m, base)),
- _db.addEntity("VarRef", _rep.local(m, to)),
- _db.addEntity("MethodSignatureRef", _rep.method(m)));
- }
- }
-
- public void writeStoreArrayIndex(SootMethod m, Local base, Local from)
- {
- if(from.getType() instanceof RefLikeType)
- {
- _db.add("StoreArrayIndex",
- _db.addEntity("VarRef", _rep.local(m, from)),
- _db.addEntity("VarRef", _rep.local(m, base)),
- _db.addEntity("MethodSignatureRef", _rep.method(m)));
- }
- }
-
- public void writeApplicationClass(SootClass application)
- {
- _db.add("ApplicationClass",
- writeType(application));
- }
-
- public void writeFieldSignature(SootField f)
- {
- _db.add("FieldSignature",
- _db.addEntity("FieldSignatureRef", _rep.signature(f)),
- writeType(f.getDeclaringClass()),
- _db.addEntity("SimpleNameRef", _rep.simpleName(f)),
- writeType(f.getType()));
- }
-
- public void writeFieldModifier(SootField f, String modifier)
- {
- _db.add("FieldModifier",
- _db.addEntity("ModifierRef", _rep.modifier(modifier)),
- _db.addEntity("FieldSignatureRef", _rep.signature(f)));
- }
-
- public void writeMethodDeclaration(SootMethod m)
- {
- _db.add("MethodDeclaration",
- _db.addEntity("MethodSignatureRef", _rep.signature(m)),
- _db.addEntity("MethodSignatureRef", _rep.method(m)));
- }
-
- public void writeMethodSignature(SootMethod m)
- {
-
- _db.add("MethodSignature-SimpleName",
- _db.addEntity("MethodSignatureRef", _rep.signature(m)),
- _db.addEntity("SimpleNameRef", _rep.simpleName(m)));
- _db.add("MethodSignature-Descriptor",
- _db.addEntity("MethodSignatureRef", _rep.signature(m)),
- _db.addEntity("MethodDescriptorRef", _rep.descriptor(m)));
- _db.add("MethodSignature-Type",
- _db.addEntity("MethodSignatureRef", _rep.signature(m)),
- writeType(m.getDeclaringClass()));
- }
-
- public void writeMethodModifier(SootMethod m, String modifier)
- {
- _db.add("MethodModifier",
- _db.addEntity("ModifierRef", _rep.modifier(modifier)),
- _db.addEntity("MethodSignatureRef", _rep.method(m)));
- }
-
- public void writeReturnVar(SootMethod m, Local l)
- {
- if(l.getType() instanceof RefLikeType)
- {
- _db.add("ReturnVar",
- _db.addEntity("VarRef", _rep.local(m, l)),
- _db.addEntity("MethodSignatureRef", _rep.method(m)));
-
- _db.add("Var-Type",
- _db.addEntity("VarRef", _rep.local(m, l)),
- writeType(l.getType()));
- }
- }
-
- public void writeNativeReturnVar(SootMethod m)
- {
- if(m.getReturnType() instanceof RefLikeType)
- {
- _db.add("ReturnVar",
- _db.addEntity("VarRef", _rep.nativeReturnVar(m)),
- _db.addEntity("MethodSignatureRef", _rep.method(m)));
-
- _db.add("Var-Type",
- _db.asEntity(_rep.nativeReturnVar(m)),
- writeType(m.getReturnType()));
-
- _db.add("Var-DeclaringMethod",
- _db.asEntity(_rep.nativeReturnVar(m)),
- _db.asEntity(_rep.method(m)));
- }
- }
-
- /**
- * Throw statement
- */
- public void writeThrow(SootMethod m, Local l, Session session)
- {
- String rep = _rep.throwLocal(m, l, session);
-
- _db.add("Throw",
- _db.addEntity("ThrowRef", rep),
- _db.addEntity("VarRef", _rep.local(m, l)));
- _db.add("Throw-Method",
- _db.addEntity("ThrowRef", rep),
- _db.addEntity("MethodSignatureRef", _rep.method(m)));
-
- int index = session.getUnitNumber(session.getCurrentUnit());
-
- _db.add("Instruction-Index",
- _db.asEntity(rep),
- _db.asIntColumn(String.valueOf(index)));
- }
-
- public void writeExceptionHandlerPrevious(SootMethod m, Trap current, Trap previous, Session session)
- {
- _db.add("ExceptionHandler-Previous",
- _db.addEntity("ExceptionHandlerRef", _rep.handler(m, current, session)),
- _db.addEntity("ExceptionHandlerRef", _rep.handler(m, previous, session)));
- }
-
- public void writeExceptionHandler(SootMethod m, Trap handler, Session session)
- {
- SootClass exc = handler.getException();
-
- Local caught;
- {
- Unit handlerUnit = handler.getHandlerUnit();
- IdentityStmt stmt = (IdentityStmt) handlerUnit;
- Value left = stmt.getLeftOp();
- Value right = stmt.getRightOp();
-
-
- if(right instanceof CaughtExceptionRef && left instanceof Local)
- {
- caught = (Local) left;
- }
- else
- {
- throw new RuntimeException("Unexpected start of exception handler: " + handlerUnit);
- }
- }
-
- /* simple fact for Paddle compatibility mode */
- _db.add("SimpleExceptionHandler",
- _db.asEntity(_rep.type(exc)),
- _db.addEntity("VarRef",_rep.local(m, caught)),
- _db.addEntity("MethodSignatureRef", _rep.method(m)));
-
- String rep = _rep.handler(m, handler, session);
- _db.addEntity("ExceptionHandlerRef", rep);
-
- _db.add("ExceptionHandler-Method",
- _db.asEntity(rep),
- _db.asEntity(_rep.method(m)));
-
- _db.add("ExceptionHandler-Type",
- _db.asEntity(rep),
- _db.asEntity(_rep.type(exc)));
-
- _db.add("ExceptionHandler-FormalParam",
- _db.asEntity(rep),
- _db.asEntity(_rep.local(m, caught)));
-
- _db.add("ExceptionHandler-Begin",
- _db.asEntity(rep),
- _db.asIntColumn(String.valueOf(session.getUnitNumber(handler.getBeginUnit()))));
-
- _db.add("ExceptionHandler-End",
- _db.asEntity(rep),
- _db.asIntColumn(String.valueOf(session.getUnitNumber(handler.getEndUnit()))));
- }
-
- public void writeThisVar(SootMethod m)
- {
- _db.add("ThisVar",
- _db.addEntity("MethodSignatureRef", _rep.method(m)),
- _db.addEntity("VarRef", _rep.thisVar(m)));
-
- _db.add("Var-Type",
- _db.asEntity(_rep.thisVar(m)),
- writeType(m.getDeclaringClass()));
-
- _db.add("Var-DeclaringMethod",
- _db.asEntity(_rep.thisVar(m)),
- _db.asEntity(_rep.method(m)));
- }
-
- public void writeMethodDeclarationException(SootMethod m, SootClass exception)
- {
- _db.add("MethodDeclaration-Exception",
- writeType(exception),
- _db.addEntity("MethodSignatureRef", _rep.method(m)));
- }
-
- public void writeFormalParam(SootMethod m, int i)
- {
- if(m.getParameterType(i) instanceof RefLikeType)
- {
- _db.add("FormalParam",
- _db.asIntColumn(_rep.index(i)),
- _db.addEntity("MethodSignatureRef", _rep.method(m)),
- _db.addEntity("VarRef", _rep.param(m, i)));
-
- _db.add("Var-Type",
- _db.asEntity(_rep.param(m, i)),
- writeType(m.getParameterType(i)));
-
- _db.add("Var-DeclaringMethod",
- _db.asEntity(_rep.param(m, i)),
- _db.asEntity(_rep.method(m)));
- }
- }
-
- public void writeLocal(SootMethod m, Local l)
- {
- if(l.getType() instanceof RefLikeType)
- {
- _db.add("Var-Type",
- _db.addEntity("VarRef", _rep.local(m, l)),
- writeType(l.getType()));
-
- _db.add("Var-DeclaringMethod",
- _db.asEntity(_rep.local(m, l)),
- _db.addEntity("MethodSignatureRef", _rep.method(m)));
- }
- }
-
- public Local writeStringConstantExpression(SootMethod inMethod, StringConstant constant, Session session)
- {
- // introduce a new temporary variable
- String basename = "$stringconstant";
- String varname = basename + session.nextNumber(basename);
- Local l = new JimpleLocal(varname, RefType.v("java.lang.String"));
- writeLocal(inMethod, l);
- writeAssignStringConstant(inMethod, l, constant);
- return l;
- }
-
- public Local writeClassConstantExpression(SootMethod inMethod, ClassConstant constant, Session session)
- {
- // introduce a new temporary variable
- String basename = "$classconstant";
- String varname = basename + session.nextNumber(basename);
- Local l = new JimpleLocal(varname, RefType.v("java.lang.Class"));
- writeLocal(inMethod, l);
- writeAssignClassConstant(inMethod, l, constant);
- return l;
- }
-
- private void writeActualParams(SootMethod inMethod, InvokeExpr expr, String invokeExprRepr, Session session)
- {
- for(int i = 0; i < expr.getArgCount(); i++)
- {
- Value v = expr.getArg(i);
-
- if(v instanceof StringConstant)
- {
- v = writeStringConstantExpression(inMethod, (StringConstant) v, session);
- }
- else if(v instanceof ClassConstant)
- {
- v = writeClassConstantExpression(inMethod, (ClassConstant) v, session);
- }
-
- if(v instanceof Local)
- {
- Local l = (Local) v;
- if(l.getType() instanceof RefLikeType)
- {
- _db.add("ActualParam",
- _db.asIntColumn(_rep.index(i)),
- _db.addEntity("MethodInvocationRef", invokeExprRepr),
- _db.addEntity("VarRef", _rep.local(inMethod, l)));
- }
- }
- else if( v instanceof IntConstant
- || v instanceof LongConstant
- || v instanceof FloatConstant
- || v instanceof DoubleConstant
- || v instanceof NullConstant)
- {
- continue;
- }
- else
- {
- throw new RuntimeException("Unknown actual parameter: " + v + " " + v.getClass());
- }
- }
- }
-
- public void writeInvoke(SootMethod inMethod, InvokeExpr expr, Session session)
- {
- writeInvokeHelper(inMethod, expr, session);
- }
-
- private String writeInvokeHelper(SootMethod inMethod, InvokeExpr expr, Session session)
- {
- String rep = _rep.invoke(inMethod, expr, session);
- writeActualParams(inMethod, expr, rep, session);
-
- _db.addEntity("MethodSignatureRef", _rep.method(inMethod));
- _db.addEntity("MethodInvocationRef", rep);
- _db.addEntity("MethodSignatureRef", _rep.signature(expr.getMethod()));
-
- if(expr instanceof StaticInvokeExpr)
- {
- _db.add("StaticMethodInvocation",
- _db.asEntity(rep),
- _db.asEntity(_rep.signature(expr.getMethod())),
- _db.asEntity(_rep.method(inMethod)));
- _db.add("StaticMethodInvocation-In",
- _db.asEntity(rep),
- _db.asEntity(_rep.method(inMethod)));
- _db.add("StaticMethodInvocation-Signature",
- _db.asEntity(rep),
- _db.asEntity(_rep.signature(expr.getMethod())));
- }
- else if(expr instanceof VirtualInvokeExpr || expr instanceof InterfaceInvokeExpr)
- {
- _db.add("VirtualMethodInvocation-Base",
- _db.asEntity(rep),
- _db.addEntity("VarRef", _rep.local(inMethod, (Local) ((InstanceInvokeExpr) expr).getBase())));
- _db.add("VirtualMethodInvocation-Signature",
- _db.asEntity(rep),
- _db.asEntity(_rep.signature(expr.getMethod())));
- _db.add("VirtualMethodInvocation-In",
- _db.asEntity(rep),
- _db.asEntity(_rep.method(inMethod)));
- _db.add("VirtualMethodInvocation",
- _db.asEntity(rep),
- _db.asEntity(_rep.signature(expr.getMethod())),
- _db.asEntity(_rep.method(inMethod)));
- }
- else if(expr instanceof SpecialInvokeExpr)
- {
- _db.add("SpecialMethodInvocation-Base",
- _db.asEntity(rep),
- _db.addEntity("VarRef", _rep.local(inMethod, (Local) ((InstanceInvokeExpr) expr).getBase())));
- _db.add("SpecialMethodInvocation-Signature",
- _db.asEntity(rep),
- _db.asEntity(_rep.signature(expr.getMethod())));
- _db.add("SpecialMethodInvocation-In",
- _db.asEntity(rep),
- _db.asEntity(_rep.method(inMethod)));
- }
- else
- {
- throw new RuntimeException("Cannot handle invoke expr: " + expr);
- }
-
- _db.add("Instruction-Index",
- _db.asEntity(rep),
- _db.asIntColumn(String.valueOf(session.getUnitNumber(session.getCurrentUnit()))));
+ public void writeThisVar(SootMethod m) {
+ _db.add("ThisVar", _db.addEntity("MethodSignatureRef", _rep.method(m)),
+ _db.addEntity("VarRef", _rep.thisVar(m)));
- return rep;
- }
+ _db.add("Var-Type", _db.asEntity(_rep.thisVar(m)),
+ writeType(m.getDeclaringClass()));
+
+ _db.add("Var-DeclaringMethod", _db.asEntity(_rep.thisVar(m)),
+ _db.asEntity(_rep.method(m)));
+ }
+
+ public void writeMethodDeclarationException(SootMethod m,
+ SootClass exception) {
+ _db.add("MethodDeclaration-Exception", writeType(exception),
+ _db.addEntity("MethodSignatureRef", _rep.method(m)));
+ }
+
+ public void writeFormalParam(SootMethod m, int i) {
+ if (m.getParameterType(i) instanceof RefLikeType) {
+ _db.add("FormalParam", _db.asIntColumn(_rep.index(i)),
+ _db.addEntity("MethodSignatureRef", _rep.method(m)),
+ _db.addEntity("VarRef", _rep.param(m, i)));
+
+ _db.add("Var-Type", _db.asEntity(_rep.param(m, i)),
+ writeType(m.getParameterType(i)));
+
+ _db.add("Var-DeclaringMethod", _db.asEntity(_rep.param(m, i)),
+ _db.asEntity(_rep.method(m)));
+ }
+ }
+
+ public void writeLocal(SootMethod m, Local l) {
+ if (l.getType() instanceof RefLikeType) {
+ _db.add("Var-Type", _db.addEntity("VarRef", _rep.local(m, l)),
+ writeType(l.getType()));
+
+ _db.add("Var-DeclaringMethod", _db.asEntity(_rep.local(m, l)),
+ _db.addEntity("MethodSignatureRef", _rep.method(m)));
+ }
+ }
+
+ public Local writeStringConstantExpression(SootMethod inMethod,
+ StringConstant constant, Session session) {
+ // introduce a new temporary variable
+ String basename = "$stringconstant";
+ String varname = basename + session.nextNumber(basename);
+ Local l = new JimpleLocal(varname, RefType.v("java.lang.String"));
+ writeLocal(inMethod, l);
+ writeAssignStringConstant(inMethod, l, constant);
+ return l;
+ }
+
+ public Local writeClassConstantExpression(SootMethod inMethod,
+ ClassConstant constant, Session session) {
+ // introduce a new temporary variable
+ String basename = "$classconstant";
+ String varname = basename + session.nextNumber(basename);
+ Local l = new JimpleLocal(varname, RefType.v("java.lang.Class"));
+ writeLocal(inMethod, l);
+ writeAssignClassConstant(inMethod, l, constant);
+ return l;
+ }
+
+ private void writeActualParams(SootMethod inMethod, InvokeExpr expr,
+ String invokeExprRepr, Session session) {
+ for (int i = 0; i < expr.getArgCount(); i++) {
+ Value v = expr.getArg(i);
+
+ if (v instanceof StringConstant) {
+ v = writeStringConstantExpression(inMethod, (StringConstant) v,
+ session);
+ } else if (v instanceof ClassConstant) {
+ v = writeClassConstantExpression(inMethod, (ClassConstant) v,
+ session);
+ }
+
+ if (v instanceof Local) {
+ Local l = (Local) v;
+ if (l.getType() instanceof RefLikeType) {
+ _db.add("ActualParam", _db.asIntColumn(_rep.index(i)), _db
+ .addEntity("MethodInvocationRef", invokeExprRepr),
+ _db.addEntity("VarRef", _rep.local(inMethod, l)));
+ }
+ } else if (v instanceof IntConstant || v instanceof LongConstant
+ || v instanceof FloatConstant
+ || v instanceof DoubleConstant || v instanceof NullConstant) {
+ continue;
+ } else {
+ throw new RuntimeException("Unknown actual parameter: " + v
+ + " " + v.getClass());
+ }
+ }
+ }
+
+ public void writeInvoke(SootMethod inMethod, InvokeExpr expr,
+ int lineNumber, Session session) {
+ writeInvokeHelper(inMethod, expr, lineNumber, session);
+ }
+
+ private String writeInvokeHelper(SootMethod inMethod, InvokeExpr expr,
+ int lineNumber, Session session) {
+ String rep = _rep.invoke(inMethod, expr, session);
+ FactGenerator.invoke_rep.put(expr, rep);
+
+ writeActualParams(inMethod, expr, rep, session);
+
+ _db.add("MethodInvocationLineNumber",
+ _db.addEntity("MethodInvocationRef", rep),
+ _db.asIntColumn(_rep.index(lineNumber)));
+
+ _db.addEntity("MethodSignatureRef", _rep.method(inMethod));
+ _db.addEntity("MethodInvocationRef", rep);
+ _db.addEntity("MethodSignatureRef", _rep.signature(expr.getMethod()));
+
+ if (expr instanceof StaticInvokeExpr) {
+ _db.add("StaticMethodInvocation", _db.asEntity(rep),
+ _db.asEntity(_rep.signature(expr.getMethod())),
+ _db.asEntity(_rep.method(inMethod)));
+ _db.add("StaticMethodInvocation-In", _db.asEntity(rep),
+ _db.asEntity(_rep.method(inMethod)));
+ _db.add("StaticMethodInvocation-Signature", _db.asEntity(rep),
+ _db.asEntity(_rep.signature(expr.getMethod())));
+ } else if (expr instanceof VirtualInvokeExpr
+ || expr instanceof InterfaceInvokeExpr) {
+ _db.add("VirtualMethodInvocation-Base", _db.asEntity(rep), _db
+ .addEntity("VarRef", _rep.local(inMethod,
+ (Local) ((InstanceInvokeExpr) expr).getBase())));
+ _db.add("VirtualMethodInvocation-Signature", _db.asEntity(rep),
+ _db.asEntity(_rep.signature(expr.getMethod())));
+ _db.add("VirtualMethodInvocation-In", _db.asEntity(rep),
+ _db.asEntity(_rep.method(inMethod)));
+ _db.add("VirtualMethodInvocation", _db.asEntity(rep),
+ _db.asEntity(_rep.signature(expr.getMethod())),
+ _db.asEntity(_rep.method(inMethod)));
+ } else if (expr instanceof SpecialInvokeExpr) {
+ _db.add("SpecialMethodInvocation-Base", _db.asEntity(rep), _db
+ .addEntity("VarRef", _rep.local(inMethod,
+ (Local) ((InstanceInvokeExpr) expr).getBase())));
+ _db.add("SpecialMethodInvocation-Signature", _db.asEntity(rep),
+ _db.asEntity(_rep.signature(expr.getMethod())));
+ _db.add("SpecialMethodInvocation-In", _db.asEntity(rep),
+ _db.asEntity(_rep.method(inMethod)));
+ } else {
+ throw new RuntimeException("Cannot handle invoke expr: " + expr);
+ }
+
+ _db.add("Instruction-Index", _db.asEntity(rep), _db.asIntColumn(String
+ .valueOf(session.getUnitNumber(session.getCurrentUnit()))));
+
+ return rep;
+ }
+
+ // Write post-dominator about clz.newInstance, ctor.newInstance,
+ // f.get, and m.invoke
+ public void writeCastPostDominator(SootMethod inMethod, AssignStmt stmt,
+ Type t, Session session, String predicate) {
+ InvokeExpr expr = stmt.getInvokeExpr();
+ String invoke = FactGenerator.invoke_rep.get(expr);
+
+ _db.add(predicate, _db.addEntity("MethodInvocationRef", invoke),
+ writeType(t));
+ }
+
+ // Write constant index of array store
+ public void writeStoreArrayConstantIndex(SootMethod m, Local base,
+ Local from, int index) {
+ if (from.getType() instanceof RefLikeType) {
+ _db.add("StoreArrayConstantIndex",
+ _db.addEntity("VarRef", _rep.local(m, from)),
+ _db.addEntity("VarRef", _rep.local(m, base)),
+ _db.addEntity("ArrayIndexRef", String.valueOf(index)));
+ }
+ }
+
+ // Write constant index of array store
+ public void writeStoreArrayConstantIndexType(SootMethod m, Local base,
+ Type t, int index) {
+ _db.add("StoreArrayConstantIndexType",
+ _db.addEntity("Type", _rep.type(t)),
+ _db.addEntity("VarRef", _rep.local(m, base)),
+ _db.addEntity("ArrayIndexRef", String.valueOf(index)));
+ }
+
+ public void writeStoreArrayVarIndexType(SootMethod m, Local base, Type t) {
+ _db.add("StoreArrayVarIndexType",
+ _db.addEntity("VarRef", _rep.local(m, base)),
+ _db.addEntity("Type", _rep.type(t)));
+ }
+
+ // Write class modifier to exclude newInstance for abstract class
+ public void writeClassModifier(SootClass c, String modifier) {
+ _db.add("ClassModifier",
+ _db.addEntity("ModifierRef", _rep.modifier(modifier)),
+ _db.addEntity("ClassType", _rep.type(c)));
+ }
}
diff -urN soot-fact-generation-r958-src/src/IrrelevantStmtSwitch.java solar-gen/src/IrrelevantStmtSwitch.java
--- soot-fact-generation-r958-src/src/IrrelevantStmtSwitch.java 2009-02-17 16:21:00.000000000 +1100
+++ solar-gen/src/IrrelevantStmtSwitch.java 2015-05-27 15:31:30.000000000 +1000
@@ -1,87 +1,70 @@
import soot.jimple.*;
import soot.jimple.StmtSwitch;
-public class IrrelevantStmtSwitch implements StmtSwitch
-{
- public boolean relevant = true;
-
- public void caseAssignStmt(AssignStmt stmt)
- {
- relevant = true;
- }
-
- public void caseBreakpointStmt(BreakpointStmt stmt)
- {
- relevant = false;
- }
-
- public void caseEnterMonitorStmt(EnterMonitorStmt stmt)
- {
- relevant = false;
- }
-
- public void caseExitMonitorStmt(ExitMonitorStmt stmt)
- {
- relevant = false;
- }
-
- public void caseGotoStmt(GotoStmt stmt)
- {
- relevant = false;
- }
-
- public void caseIdentityStmt(IdentityStmt stmt)
- {
- relevant = true;
- }
-
- public void caseIfStmt(IfStmt stmt)
- {
- relevant = false;
- }
-
- public void caseInvokeStmt(InvokeStmt stmt)
- {
- relevant = true;
- }
-
- public void caseLookupSwitchStmt(LookupSwitchStmt stmt)
- {
- relevant = false;
- }
-
- public void caseNopStmt(NopStmt stmt)
- {
- relevant = true;
- }
-
- public void caseRetStmt(RetStmt stmt)
- {
- relevant = false;
- }
-
- public void caseReturnStmt(ReturnStmt stmt)
- {
- relevant = true;
- }
-
- public void caseReturnVoidStmt(ReturnVoidStmt stmt)
- {
- relevant = false;
- }
-
- public void caseTableSwitchStmt(TableSwitchStmt stmt)
- {
- relevant = false;
- }
-
- public void caseThrowStmt(ThrowStmt stmt)
- {
- relevant = true;
- }
-
- public void defaultCase(Object obj)
- {
- throw new RuntimeException("uh, why is this invoked?");
- }
+public class IrrelevantStmtSwitch implements StmtSwitch {
+ public boolean relevant = true;
+
+ public void caseAssignStmt(AssignStmt stmt) {
+ relevant = true;
+ }
+
+ public void caseBreakpointStmt(BreakpointStmt stmt) {
+ relevant = false;
+ }
+
+ public void caseEnterMonitorStmt(EnterMonitorStmt stmt) {
+ relevant = false;
+ }
+
+ public void caseExitMonitorStmt(ExitMonitorStmt stmt) {
+ relevant = false;
+ }
+
+ public void caseGotoStmt(GotoStmt stmt) {
+ relevant = false;
+ }
+
+ public void caseIdentityStmt(IdentityStmt stmt) {
+ relevant = true;
+ }
+
+ public void caseIfStmt(IfStmt stmt) {
+ relevant = false;
+ }
+
+ public void caseInvokeStmt(InvokeStmt stmt) {
+ relevant = true;
+ }
+
+ public void caseLookupSwitchStmt(LookupSwitchStmt stmt) {
+ relevant = false;
+ }
+
+ public void caseNopStmt(NopStmt stmt) {
+ relevant = true;
+ }
+
+ public void caseRetStmt(RetStmt stmt) {
+ relevant = false;
+ }
+
+ public void caseReturnStmt(ReturnStmt stmt) {
+ relevant = true;
+ }
+
+ public void caseReturnVoidStmt(ReturnVoidStmt stmt) {
+ relevant = false;
+ }
+
+ public void caseTableSwitchStmt(TableSwitchStmt stmt) {
+ relevant = false;
+ }
+
+ public void caseThrowStmt(ThrowStmt stmt) {
+ relevant = true;
+ }
+
+ public void defaultCase(Object obj) {
+ throw new RuntimeException("uh, why is this invoked?");
+ }
}
diff -urN soot-fact-generation-r958-src/src/Main.java solar-gen/src/Main.java
--- soot-fact-generation-r958-src/src/Main.java 2009-06-04 13:07:30.000000000 +1000
+++ solar-gen/src/Main.java 2015-05-31 19:34:31.000000000 +1000
@@ -10,246 +10,213 @@
public class Main {
- public static enum Mode {INPUTS, FULL;}
-
-
- private static Mode _mode = null;
- private static List _inputs = new ArrayList();
- private static List _libraries = new ArrayList();
- private static String _outputDir = null;
- private static String _main = null;
- private static boolean _ssa = false;
- private static boolean _trap = false;
- private static boolean _allowPhantom = false;
+ public static enum Mode {
+ INPUTS, FULL;
+ }
+
+ private static Mode _mode = null;
+ private static List _inputs = new ArrayList();
+ private static List _libraries = new ArrayList();
+ private static String _outputDir = null;
+ private static String _main = null;
+ private static boolean _ssa = false;
+ private static boolean _trap = false;
+ private static boolean _allowPhantom = false;
+
+ private static int shift(String[] args, int index) {
+ if (args.length == index + 1) {
+ System.err.println("error: option " + args[index]
+ + " requires an argument");
+ System.exit(1);
+ }
+
+ return index + 1;
+ }
+
+ public static void main(String[] args) {
+ try {
+ if (args.length == 0) {
+ System.err
+ .println("usage: soot-fact-generation [options] file...");
+ System.exit(0);
+ }
+
+ for (int i = 0; i < args.length; i++) {
+ if (args[i].equals("--full") || args[i].equals("-full")) {
+ if (_mode != null) {
+ System.err.println("error: duplicate mode argument");
+ System.exit(1);
+ }
+
+ _mode = Mode.FULL;
+ } else if (args[i].equals("-d")) {
+ i = shift(args, i);
+ _outputDir = args[i];
+ } else if (args[i].equals("-main")) {
+ i = shift(args, i);
+ _main = args[i];
+ } else if (args[i].equals("-ssa")) {
+ _ssa = true;
+ } else if (args[i].equals("-l")) {
+ i = shift(args, i);
+ _libraries.add(args[i]);
+ } else if (args[i].equals("-lsystem")
+ || args[i].equals("--lsystem")) {
+ String javaHome = System.getProperty("java.home");
+ _libraries.add(javaHome + File.separator + "lib" + File.separator + "rt.jar");
+ _libraries.add(javaHome + File.separator + "lib" + File.separator + "jce.jar");
+ _libraries.add(javaHome + File.separator + "lib" + File.separator + "jsse.jar");
+ } else if (args[i].equals("-deps")) {
+ i = shift(args, i);
+ String folderName = args[i];
+ File f = new File(folderName);
+ if (!f.exists()) {
+ System.err.println("Dependency folder " + folderName
+ + " does not exist");
+ System.exit(0);
+ } else if (!f.isDirectory()) {
+ System.err.println("Dependency folder " + folderName
+ + " is not a directory");
+ System.exit(0);
+ }
+ for (File file : f.listFiles()) {
+ if (file.isFile() && file.getName().endsWith(".jar")) {
+ _libraries.add(file.getCanonicalPath());
+ }
+ }
+ } else if (args[i].equals("-trap")) {
+ _trap = true;
+ } else if (args[i].equals("-allow-phantom")) {
+ _allowPhantom = true;
+ } else if (args[i].equals("-h") || args[i].equals("--help")
+ || args[i].equals("-help")) {
+ System.err.println("usage: soot-fact-generation [options] file...");
+ System.err.println("options:");
+ System.err.println(" -main Specify the main name of the main class");
+ System.err.println(" -full Generate facts by full transitive resolution");
+ System.err.println(" -ssa Generate SSA facts, enabling flow-sensitive analysis");
+ System.err.println(" -d Specify where to generate csv fact files.");
+ System.err.println(" -l Find classes in jar/zip archive.");
+ System.err.println(" -lsystem Find classes in default system classes.");
+ System.err.println(" -deps Add jars in this directory to the class lookup path");
+ System.err.println(" -trap Generate TRAP files rather than CSV files");
+ System.err.println(" -h, -help, Print this help message.");
+ System.exit(0);
+ } else {
+ if (args[i].charAt(0) == '-') {
+ System.err.println("error: unrecognized option: "
+ + args[i]);
+ System.exit(0);
+ } else {
+ _inputs.add(args[i]);
+ }
+ }
+ }
+
+ if (_mode == null) {
+ _mode = Mode.INPUTS;
+ }
+
+ if (_outputDir == null) {
+ _outputDir = System.getProperty("user.dir");
+ }
+
+ run();
+ } catch (Exception exc) {
+ exc.printStackTrace();
+ System.exit(1);
+ }
+ }
- private static int shift(String[] args, int index) {
- if(args.length == index + 1) {
- System.err.println("error: option " + args[index] + " requires an argument");
- System.exit(1);
- }
-
- return index + 1;
- }
-
- public static void main(String[] args)
- {
- try
- {
- if(args.length == 0)
- {
- System.err.println("usage: soot-fact-generation [options] file...");
- System.exit(0);
- }
-
- for(int i = 0; i < args.length; i++)
- {
- if(args[i].equals("--full") || args[i].equals("-full"))
- {
- if( _mode != null)
- {
- System.err.println("error: duplicate mode argument");
- System.exit(1);
- }
-
- _mode = Mode.FULL;
- }
- else if(args[i].equals("-d"))
- {
- i = shift(args, i);
- _outputDir = args[i];
- }
- else if(args[i].equals("-main"))
- {
- i = shift(args, i);
- _main = args[i];
- }
- else if(args[i].equals("-ssa"))
- {
- _ssa = true;
- }
- else if(args[i].equals("-l"))
- {
- i = shift(args, i);
- _libraries.add(args[i]);
- }
- else if(args[i].equals("-lsystem") || args[i].equals("--lsystem"))
- {
- String javaHome = System.getProperty("java.home");
- _libraries.add(javaHome + File.separator + "lib" + File.separator + "rt.jar");
- _libraries.add(javaHome + File.separator + "lib" + File.separator + "jce.jar");
- _libraries.add(javaHome + File.separator + "lib" + File.separator + "jsse.jar");
- }
- else if(args[i].equals("-deps")) {
- i = shift(args, i);
- String folderName = args[i];
- File f = new File(folderName);
- if(!f.exists()) {
- System.err.println("Dependency folder " + folderName + " does not exist");
- System.exit(0);
- }
- else if(!f.isDirectory()) {
- System.err.println("Dependency folder " + folderName + " is not a directory");
- System.exit(0);
- }
- for(File file : f.listFiles()) {
- if(file.isFile() && file.getName().endsWith(".jar")) {
- _libraries.add(file.getCanonicalPath());
- }
- }
- }
- else if(args[i].equals("-trap"))
- {
- _trap = true;
- }
- else if(args[i].equals("-allow-phantom"))
- {
- _allowPhantom = true;
- }
- else if(args[i].equals("-h") || args[i].equals("--help") || args[i].equals("-help")) {
- System.err.println("usage: soot-fact-generation [options] file...");
- System.err.println("options:");
- System.err.println(" -main Specify the main name of the main class");
- System.err.println(" -full Generate facts by full transitive resolution");
- System.err.println(" -ssa Generate SSA facts, enabling flow-sensitive analysis");
- System.err.println(" -d Specify where to generate csv fact files.");
- System.err.println(" -l Find classes in jar/zip archive.");
- System.err.println(" -lsystem Find classes in default system classes.");
- System.err.println(" -deps Add jars in this directory to the class lookup path");
- System.err.println(" -trap Generate TRAP files rather than CSV files");
- System.err.println(" -h, -help, Print this help message.");
- System.exit(0);
- }
- else
- {
- if(args[i].charAt(0) == '-')
- {
- System.err.println("error: unrecognized option: " + args[i]);
- System.exit(0);
- }
- else
- {
- _inputs.add(args[i]);
- }
- }
- }
-
- if(_mode == null) {
- _mode = Mode.INPUTS;
- }
-
- if(_outputDir == null) {
- _outputDir = System.getProperty("user.dir");
- }
-
-
- run();
- }
- catch(Exception exc)
- {
- exc.printStackTrace();
- System.exit(1);
- }
- }
-
- private static void run() throws Exception
- {
- NoSearchingClassProvider provider = new NoSearchingClassProvider();
-
- for(String arg : _inputs)
- {
- if(arg.endsWith(".jar") || arg.endsWith(".zip"))
- {
- System.out.println("Adding archive: " + arg);
- provider.addArchive(new File(arg));
- }
- else
- {
- System.out.println("Adding file: " + arg);
- provider.addClass(new File(arg));
- }
- }
-
- for(String lib: _libraries) {
- System.out.println("Adding archive for resolving: " + lib);
- provider.addArchiveForResolving(new File(lib));
- }
-
- soot.SourceLocator.v().setClassProviders(Collections.singletonList((ClassProvider) provider));
- Scene scene = Scene.v();
- if(_main != null)
- {
- soot.options.Options.v().set_main_class(_main);
- }
-
- if(_mode == Mode.FULL)
- {
- soot.options.Options.v().set_full_resolver(true);
- }
-
- if(_allowPhantom)
- {
- soot.options.Options.v().set_allow_phantom_refs(true);
- }
-
- Collection classes = new ArrayList();
- for(String className : provider.getClassNames())
- {
- scene.loadClass(className, SootClass.SIGNATURES);
- SootClass c = scene.loadClass(className, SootClass.BODIES);
- c.setApplicationClass();
- classes.add(c);
- }
-
- /* For simulating the FileSystem class, we need the implementation
- of the FileSystem, but the classes are not loaded automatically
- due to the indirection via native code.
- */
- addCommonDynamicClass(scene, provider, "java.io.UnixFileSystem");
- addCommonDynamicClass(scene, provider, "java.io.WinNTFileSystem");
- addCommonDynamicClass(scene, provider, "java.io.Win32FileSystem");
-
- /* java.net.URL loads handlers dynamically */
- addCommonDynamicClass(scene, provider, "sun.net.www.protocol.file.Handler");
- addCommonDynamicClass(scene, provider, "sun.net.www.protocol.ftp.Handler");
- addCommonDynamicClass(scene, provider, "sun.net.www.protocol.http.Handler");
- addCommonDynamicClass(scene, provider, "sun.net.www.protocol.https.Handler");
- addCommonDynamicClass(scene, provider, "sun.net.www.protocol.jar.Handler");
-
- scene.loadNecessaryClasses();
-
- Database db;
- if(_trap)
- db = new TRAPDatabase(new File(_outputDir));
- else
- db = new CSVDatabase(new File(_outputDir));
- FactWriter writer = new FactWriter(db);
- FactGenerator generator = new FactGenerator(writer, _ssa);
-
- for(SootClass c : classes)
- {
- writer.writeApplicationClass(c);
- }
-
- if(_mode == Mode.FULL)
- {
- classes = scene.getClasses();
- }
-
- for(SootClass c : classes)
- {
- generator.generate(c);
- }
-
-
- db.close();
- }
-
- public static void addCommonDynamicClass(Scene scene, ClassProvider provider, String className)
- {
- if(provider.find(className) != null)
- {
- scene.addBasicClass(className);
- }
+ private static void run() throws Exception {
+ NoSearchingClassProvider provider = new NoSearchingClassProvider();
- }
-}
\ No newline at end of file
+ for (String arg : _inputs) {
+ if (arg.endsWith(".jar") || arg.endsWith(".zip")) {
+ System.out.println("Adding archive: " + arg);
+ provider.addArchive(new File(arg));
+ } else {
+ System.out.println("Adding file: " + arg);
+ provider.addClass(new File(arg));
+ }
+ }
+
+ for (String lib : _libraries) {
+ System.out.println("Adding archive for resolving: " + lib);
+ provider.addArchiveForResolving(new File(lib));
+ }
+
+ soot.SourceLocator.v().setClassProviders(
+ Collections.singletonList((ClassProvider) provider));
+ Scene scene = Scene.v();
+ if (_main != null) {
+ soot.options.Options.v().set_main_class(_main);
+ }
+
+ if (_mode == Mode.FULL) {
+ soot.options.Options.v().set_full_resolver(true);
+ }
+
+ if (_allowPhantom) {
+ soot.options.Options.v().set_allow_phantom_refs(true);
+ }
+
+ soot.options.Options.v().set_keep_line_number(true);
+
+ Collection classes = new ArrayList();
+ for (String className : provider.getClassNames()) {
+ scene.loadClass(className, SootClass.SIGNATURES);
+ SootClass c = scene.loadClass(className, SootClass.BODIES);
+ c.setApplicationClass();
+ classes.add(c);
+ }
+
+ /* For simulating the FileSystem class, we need the implementation
+ of the FileSystem, but the classes are not loaded automatically
+ due to the indirection via native code.
+ */
+ addCommonDynamicClass(scene, provider, "java.io.UnixFileSystem");
+ addCommonDynamicClass(scene, provider, "java.io.WinNTFileSystem");
+ addCommonDynamicClass(scene, provider, "java.io.Win32FileSystem");
+
+ /* java.net.URL loads handlers dynamically */
+ addCommonDynamicClass(scene, provider, "sun.net.www.protocol.file.Handler");
+ addCommonDynamicClass(scene, provider, "sun.net.www.protocol.ftp.Handler");
+ addCommonDynamicClass(scene, provider, "sun.net.www.protocol.http.Handler");
+ addCommonDynamicClass(scene, provider, "sun.net.www.protocol.https.Handler");
+ addCommonDynamicClass(scene, provider, "sun.net.www.protocol.jar.Handler");
+
+ MissingClassLoader.load(_main, scene);
+ scene.tryLoadClass("java.util.CurrencyData", SootClass.BODIES);
+ scene.loadNecessaryClasses();
+
+ Database db;
+ if (_trap)
+ db = new TRAPDatabase(new File(_outputDir));
+ else
+ db = new CSVDatabase(new File(_outputDir));
+ FactWriter writer = new FactWriter(db);
+ FactGenerator generator = new FactGenerator(writer, _ssa);
+
+ for (SootClass c : classes) {
+ writer.writeApplicationClass(c);
+ }
+
+ if (_mode == Mode.FULL) {
+ classes = scene.getClasses();
+ }
+
+ for (SootClass c : classes) {
+ generator.generate(c);
+ }
+
+ db.close();
+ }
+
+ public static void addCommonDynamicClass(Scene scene,
+ ClassProvider provider, String className) {
+ if (provider.find(className) != null) {
+ scene.addBasicClass(className);
+ }
+ }
+}
diff -urN soot-fact-generation-r958-src/src/MissingClassLoader.java solar-gen/src/MissingClassLoader.java
--- soot-fact-generation-r958-src/src/MissingClassLoader.java 1970-01-01 10:00:00.000000000 +1000
+++ solar-gen/src/MissingClassLoader.java 2015-05-31 19:33:53.000000000 +1000
@@ -0,0 +1,133 @@
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import soot.Scene;
+import soot.SootClass;
+
+
+public class MissingClassLoader {
+ private static Map> missingClasses;
+
+ static {
+ missingClasses = new HashMap>();
+ missingClasses.put("dacapo.antlr.Main", Arrays.asList(
+ "sun.security.provider.SHA",
+ "sun.util.resources.CurrencyNames", "java.util.CurrencyData",
+ "sun.security.provider.SHA",
+ "sun.util.resources.CurrencyNames",
+ "sun.util.resources.CurrencyNames_en_US",
+ "sun.text.resources.FormatData",
+ "sun.text.resources.FormatData_en",
+ "sun.text.resources.FormatData_en_US"));
+ missingClasses.put("dacapo.bloat.Main", Arrays.asList(
+ "sun.security.provider.SHA", "sun.util.resources.CalendarData",
+ "sun.util.resources.CalendarData_en",
+ "sun.util.resources.CurrencyNames",
+ "sun.util.resources.CurrencyNames_en_US",
+ "sun.text.resources.FormatData",
+ "sun.text.resources.FormatData_en",
+ "sun.text.resources.FormatData_en_US"));
+ missingClasses.put("dacapo.chart.Main", Arrays.asList(
+ "org.jfree.base.log.DefaultLogModule", "sun.awt.resources.awt",
+ "org.jfree.resources.JCommonResources",
+ "sun.util.resources.TimeZoneNames",
+ "sun.util.resources.TimeZoneNames_en",
+ "sun.text.resources.BreakIteratorInfo", "sun.awt.X11.XToolkit",
+ "sun.nio.cs.UTF_16", "sun.nio.cs.ISO_8859_1",
+ "sun.security.provider.MD5", "sun.security.provider.SHA",
+ "sun.text.resources.FormatData",
+ "sun.text.resources.FormatData_en",
+ "sun.text.resources.FormatData_en_US",
+ "sun.util.resources.CalendarData",
+ "sun.util.resources.CalendarData_en",
+ "sun.util.resources.CurrencyNames",
+ "sun.util.resources.CurrencyNames_en_US"));
+ missingClasses.put("dacapo.eclipse.Main", Arrays.asList(
+ "dacapo.eclipse.HarnessRunner",
+ "dacapo.eclipse.DaCapoPlugin",
+ "dacapo.eclipse.EclipseTests",
+ "java.net.Inet6AddressImpl",
+ "org.eclipse.core.internal.compatibility.PluginActivator",
+ "org.eclipse.core.internal.content.TextContentDescriber",
+ "org.eclipse.core.internal.plugins.CompatibilityActivator",
+ "org.eclipse.core.internal.preferences.InstancePreferences",
+ "org.eclipse.core.internal.resources.PreferenceInitializer",
+ "org.eclipse.jdt.internal.core.JavaCorePreferenceInitializer",
+ "org.eclipse.jdt.internal.launching.Standard11xVMType",
+ "org.eclipse.update.internal.configurator.ConfigurationActivator",
+ "org.eclipse.update.internal.configurator.ProductProvider",
+ "sun.nio.cs.ISO_8859_1",
+ "sun.security.provider.SHA",
+ "sun.util.resources.CalendarData",
+ "sun.util.resources.CalendarData_en",
+ "sun.util.resources.CurrencyNames",
+ "sun.util.resources.CurrencyNames_en_US",
+ "sun.text.resources.FormatData",
+ "sun.text.resources.FormatData_en",
+ "sun.text.resources.FormatData_en_US",
+ "sun.util.resources.TimeZoneNames",
+ "sun.util.resources.TimeZoneNames_en"));
+ missingClasses.put("dacapo.fop.Main", Arrays.asList(
+ "org.apache.xerces.jaxp.SAXParserFactoryImpl",
+ "sun.awt.resources.awt", "sun.nio.cs.ISO_8859_1",
+ "sun.security.provider.SHA", "sun.text.resources.FormatData",
+ "sun.text.resources.FormatData_en",
+ "sun.text.resources.FormatData_en_US",
+ "sun.util.resources.CurrencyNames",
+ "sun.util.resources.CurrencyNames_en_US"));
+ missingClasses.put("dacapo.hsqldb.Main", Arrays.asList(
+ "sun.jdbc.odbc.JdbcOdbcDriver", "sun.security.provider.SHA",
+ "sun.util.resources.CalendarData",
+ "sun.util.resources.CalendarData_en",
+ "sun.util.resources.CurrencyNames",
+ "sun.util.resources.CurrencyNames_en_US",
+ "sun.text.resources.FormatData",
+ "sun.text.resources.FormatData_en",
+ "sun.text.resources.FormatData_en_US"));
+ missingClasses.put("dacapo.luindex.Main", Arrays.asList(
+ "sun.security.provider.MD5", "sun.security.provider.SHA",
+ "sun.util.resources.CalendarData",
+ "sun.util.resources.CalendarData_en",
+ "sun.util.resources.CurrencyNames",
+ "sun.util.resources.CurrencyNames_en_US",
+ "sun.text.resources.FormatData",
+ "sun.text.resources.FormatData_en",
+ "sun.text.resources.FormatData_en_US"));
+ missingClasses.put("dacapo.lusearch.Main", Arrays.asList(
+ "sun.security.provider.MD5", "sun.security.provider.SHA",
+ "sun.util.resources.CurrencyNames",
+ "sun.util.resources.CurrencyNames_en_US",
+ "sun.text.resources.FormatData",
+ "sun.text.resources.FormatData_en",
+ "sun.text.resources.FormatData_en_US"));
+ missingClasses.put("dacapo.pmd.Main", Arrays.asList(
+ "org.apache.xerces.parsers.XML11Configuration",
+ "org.apache.xerces.impl.XMLDocumentScannerImpl",
+ "org.apache.xerces.impl.dtd.XMLDTDValidator.startDocument",
+ "org.jaxen.saxpath.base.XPathReader",
+ "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl",
+ "sun.security.provider.SHA", "sun.text.resources.FormatData",
+ "sun.text.resources.FormatData_en",
+ "sun.text.resources.FormatData_en_US",
+ "sun.util.resources.CurrencyNames",
+ "sun.util.resources.CurrencyNames_en_US"));
+ missingClasses.put("dacapo.xalan.Main", Arrays.asList(
+ "org.apache.xerces.jaxp.SAXParserFactoryImpl",
+ "sun.nio.cs.ISO_8859_1", "sun.security.provider.SHA",
+ "sun.text.resources.FormatData",
+ "sun.text.resources.FormatData_en",
+ "sun.text.resources.FormatData_en_US",
+ "sun.util.resources.CurrencyNames",
+ "sun.util.resources.CurrencyNames_en_US"));
+ }
+
+ public static void load(String main, Scene scene) {
+ if (missingClasses.containsKey(main)) {
+ for (String className : missingClasses.get(main)) {
+ scene.tryLoadClass(className, SootClass.BODIES);
+ }
+ }
+ }
+}
diff -urN soot-fact-generation-r958-src/src/NoSearchingClassProvider.java solar-gen/src/NoSearchingClassProvider.java
--- soot-fact-generation-r958-src/src/NoSearchingClassProvider.java 2009-06-04 01:45:54.000000000 +1000
+++ solar-gen/src/NoSearchingClassProvider.java 2015-05-27 15:30:42.000000000 +1000
@@ -8,7 +8,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Set ;
+import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
@@ -18,199 +18,195 @@
import soot.coffi.ClassFile;
/**
- * This class provider allows the specification of specific .class
- * files for finding classes. Instead of a search path, the specific
- * class files are added to the provider. In this way, it does not
- * matter at all where your classes are: the provider will never
- * return a class it accidentally found on the search path.
+ * This class provider allows the specification of specific .class files for
+ * finding classes. Instead of a search path, the specific class files are added
+ * to the provider. In this way, it does not matter at all where your classes
+ * are: the provider will never return a class it accidentally found on the
+ * search path.
*
- * This provider does allow archives, which are considered in the
- * order in which they've been added to the provider. It does,
- * however, warn if the same class file is added twice.
+ * This provider does allow archives, which are considered in the order in which
+ * they've been added to the provider. It does, however, warn if the same class
+ * file is added twice.
*/
public class NoSearchingClassProvider implements ClassProvider {
- private Map _classes;
- private List _archives;
+ private Map _classes;
+ private List _archives;
- public NoSearchingClassProvider() {
- _classes = new HashMap();
- _archives = new ArrayList();
- }
-
- public Set getClassNames() {
- return _classes.keySet();
- }
-
- /**
- * Adds a class file. Returns the class name of the class that was
- * added.
- */
- public String addClass(File f) throws IOException {
- return addClass(f.getPath(), new FileResource(f));
- }
-
- /**
- * Adds a class file in a zip/jar archive. Returns the class name of
- * the class that was added.
- */
- public String addClass(ZipFile archive, ZipEntry entry) throws IOException {
- return addClass(entry.getName(), new ZipEntryResource(archive, entry));
- }
-
- /**
- * Adds a class file from a resource.
- */
- public String addClass(String path, Resource resource) throws IOException {
- ClassFile c = new ClassFile(path);
-
- InputStream stream = null;
- try {
- stream = resource.open();
- c.loadClassFile(stream);
- }
- finally {
- if(stream != null) {
- stream.close();
- }
- }
-
- String className = c.toString().replace('/', '.');
-
- if(_classes.containsKey(className)) {
- throw new RuntimeException(
- "class " + className + " has already been added to this class provider");
- }
- else {
- _classes.put(className, resource);
- }
-
- return className;
- }
-
- /**
- * Adds an application archive to the class provider.
- */
- public List addArchive(File f) throws IOException {
- List result = new ArrayList();
-
- ZipFile archive = new ZipFile(f);
- Enumeration extends ZipEntry> entries = archive.entries();
- while(entries.hasMoreElements()) {
- ZipEntry entry = entries.nextElement();
- if(entry.getName().endsWith(".class")) {
- String className = addClass(archive, entry);
- result.add(className);
- }
- }
-
- return result;
- }
-
- /**
- * Adds a library archive to the class provider.
- */
- public void addArchiveForResolving(File f) throws IOException {
- ZipFile archive = new ZipFile(f);
- _archives.add(archive);
- }
-
- /**
- * Finds the class for the given className. This method is invoked
- * by the Soot SourceLocator.
- */
- public ClassSource find(String className) {
- Resource resource = _classes.get(className);
-
- if(resource == null) {
- String fileName = className.replace('.', '/') + ".class";
-
- for(ZipFile archive : _archives) {
- ZipEntry entry = archive.getEntry(fileName);
- if(entry != null) {
- resource = new ZipEntryResource(archive, entry);
- break;
- }
- }
- }
-
- if(resource == null) {
- return null;
- }
- else {
- // System.out.println("found: " + className + " at " + stream.toString());
-
- try {
- InputStream stream = resource.open();
- return new CoffiClassSource(className, stream);
- }
- catch(IOException exc) {
- throw new RuntimeException(exc);
- }
- }
- }
-
- /**
- * A resource is something to which we can open an InputStream 1 or
- * more times.
- *
- * Similar to FoundFile in SourceLocator, which is not accessible.
- */
- public static interface Resource {
- public InputStream open() throws IOException;
- }
-
- /**
- * File.
- */
- public static class FileResource implements Resource {
- private File _file;
-
- public FileResource(File file) {
- super();
- _file = file;
- }
-
- public InputStream open() throws IOException {
- return new FileInputStream(_file);
- }
- }
-
- /**
- * Zip file.
- */
- public static class ZipEntryResource implements Resource {
- private ZipFile _archive;
- private ZipEntry _entry;
-
- public ZipEntryResource(ZipFile archive, ZipEntry entry) {
- super();
- _archive = archive;
- _entry = entry;
- }
-
- public InputStream open() throws IOException {
- return doJDKBugWorkaround(_archive.getInputStream(_entry), _entry.getSize());
- }
-
- /**
- * Copied from SourceLocator because FoundFile is not accessible
- * outside the soot package.
- */
- private static InputStream doJDKBugWorkaround(InputStream is, long size) throws IOException {
- int sz = (int) size;
- byte[] buf = new byte[sz];
-
-
- final int N = 1024;
- int ln = 0;
- int count = 0;
- while (sz > 0 &&
- (ln = is.read(buf, count, Math.min(N, sz))) != -1) {
- count += ln;
- sz -= ln;
- }
- return new ByteArrayInputStream(buf);
- }
- }
+ public NoSearchingClassProvider() {
+ _classes = new HashMap();
+ _archives = new ArrayList();
+ }
+
+ public Set getClassNames() {
+ return _classes.keySet();
+ }
+
+ /**
+ * Adds a class file. Returns the class name of the class that was added.
+ */
+ public String addClass(File f) throws IOException {
+ return addClass(f.getPath(), new FileResource(f));
+ }
+
+ /**
+ * Adds a class file in a zip/jar archive. Returns the class name of the
+ * class that was added.
+ */
+ public String addClass(ZipFile archive, ZipEntry entry) throws IOException {
+ return addClass(entry.getName(), new ZipEntryResource(archive, entry));
+ }
+
+ /**
+ * Adds a class file from a resource.
+ */
+ public String addClass(String path, Resource resource) throws IOException {
+ ClassFile c = new ClassFile(path);
+
+ InputStream stream = null;
+ try {
+ stream = resource.open();
+ c.loadClassFile(stream);
+ } finally {
+ if (stream != null) {
+ stream.close();
+ }
+ }
+
+ String className = c.toString().replace('/', '.');
+
+ if (_classes.containsKey(className)) {
+ throw new RuntimeException("class " + className
+ + " has already been added to this class provider");
+ } else {
+ _classes.put(className, resource);
+ }
+
+ return className;
+ }
+
+ /**
+ * Adds an application archive to the class provider.
+ */
+ public List addArchive(File f) throws IOException {
+ List result = new ArrayList();
+
+ ZipFile archive = new ZipFile(f);
+ Enumeration extends ZipEntry> entries = archive.entries();
+ while (entries.hasMoreElements()) {
+ ZipEntry entry = entries.nextElement();
+ if (entry.getName().endsWith(".class")) {
+ String className = addClass(archive, entry);
+ result.add(className);
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Adds a library archive to the class provider.
+ */
+ public void addArchiveForResolving(File f) throws IOException {
+ ZipFile archive = new ZipFile(f);
+ _archives.add(archive);
+ }
+
+ /**
+ * Finds the class for the given className. This method is invoked by the
+ * Soot SourceLocator.
+ */
+ public ClassSource find(String className) {
+ Resource resource = _classes.get(className);
+
+ if (resource == null) {
+ String fileName = className.replace('.', '/') + ".class";
+
+ for (ZipFile archive : _archives) {
+ ZipEntry entry = archive.getEntry(fileName);
+ if (entry != null) {
+ resource = new ZipEntryResource(archive, entry);
+ break;
+ }
+ }
+ }
+
+ if (resource == null) {
+ return null;
+ } else {
+ // System.out.println("found: " + className + " at " +
+ // stream.toString());
+
+ try {
+ InputStream stream = resource.open();
+ return new CoffiClassSource(className, stream);
+ } catch (IOException exc) {
+ throw new RuntimeException(exc);
+ }
+ }
+ }
+
+ /**
+ * A resource is something to which we can open an InputStream 1 or more
+ * times.
+ *
+ * Similar to FoundFile in SourceLocator, which is not accessible.
+ */
+ public static interface Resource {
+ public InputStream open() throws IOException;
+ }
+
+ /**
+ * File.
+ */
+ public static class FileResource implements Resource {
+ private File _file;
+
+ public FileResource(File file) {
+ super();
+ _file = file;
+ }
+
+ public InputStream open() throws IOException {
+ return new FileInputStream(_file);
+ }
+ }
+
+ /**
+ * Zip file.
+ */
+ public static class ZipEntryResource implements Resource {
+ private ZipFile _archive;
+ private ZipEntry _entry;
+
+ public ZipEntryResource(ZipFile archive, ZipEntry entry) {
+ super();
+ _archive = archive;
+ _entry = entry;
+ }
+
+ public InputStream open() throws IOException {
+ return doJDKBugWorkaround(_archive.getInputStream(_entry),
+ _entry.getSize());
+ }
+
+ /**
+ * Copied from SourceLocator because FoundFile is not accessible outside
+ * the soot package.
+ */
+ private static InputStream doJDKBugWorkaround(InputStream is, long size)
+ throws IOException {
+ int sz = (int) size;
+ byte[] buf = new byte[sz];
+
+ final int N = 1024;
+ int ln = 0;
+ int count = 0;
+ while (sz > 0 && (ln = is.read(buf, count, Math.min(N, sz))) != -1) {
+ count += ln;
+ sz -= ln;
+ }
+ return new ByteArrayInputStream(buf);
+ }
+ }
}
\ No newline at end of file
diff -urN soot-fact-generation-r958-src/src/PostDominatorFinder.java solar-gen/src/PostDominatorFinder.java
--- soot-fact-generation-r958-src/src/PostDominatorFinder.java 1970-01-01 10:00:00.000000000 +1000
+++ solar-gen/src/PostDominatorFinder.java 2015-05-28 15:37:38.000000000 +1000
@@ -0,0 +1,99 @@
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import soot.ArrayType;
+import soot.Body;
+import soot.Local;
+import soot.Type;
+import soot.Unit;
+import soot.jimple.AssignStmt;
+import soot.jimple.CastExpr;
+import soot.jimple.Stmt;
+import soot.toolkits.graph.BriefUnitGraph;
+import soot.toolkits.graph.DominatorsFinder;
+import soot.toolkits.graph.MHGPostDominatorsFinder;
+import soot.toolkits.graph.UnitGraph;
+
+public class PostDominatorFinder {
+
+ public static Map findCastPostDominator(Body body) {
+ // 1. get all clz.newInstance() units
+ List call_list = new ArrayList();
+ for (Unit unit : body.getUnits()) {
+ if (hasClassNewInstanceCall(unit) ||
+ hasConstructorNewInstanceCall(unit) ||
+ hasGetCall(unit) ||
+ hasInvokeCall(unit) ||
+ hasArrayGetCall(unit)) {
+ call_list.add((AssignStmt)unit);
+ }
+ }
+ // 2. find cast post-dominator for newInstance, get, invoke
+ Map result = new HashMap();
+ if (!call_list.isEmpty()) {
+ UnitGraph cfg = new BriefUnitGraph(body);
+ @SuppressWarnings("unchecked")
+ DominatorsFinder dominators = new MHGPostDominatorsFinder(cfg);
+ for (AssignStmt stmt : call_list) {
+ Type t = getPostDominateType(cfg, dominators, stmt);
+ if (t != null) {
+ result.put(stmt, t);
+ }
+ }
+ }
+ return result;
+ }
+
+ private static boolean hasCall(Stmt stmt, String target) {
+ if (stmt instanceof AssignStmt && stmt.containsInvokeExpr()) {
+ String signature = stmt.getInvokeExpr().getMethodRef().getSignature();
+ if (signature.equals(target)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static boolean hasClassNewInstanceCall(Unit unit) {
+ return hasCall((Stmt) unit, "");
+ }
+
+ public static boolean hasConstructorNewInstanceCall(Unit unit) {
+ return hasCall((Stmt) unit, "");
+ }
+
+ public static boolean hasGetCall(Unit unit) {
+ return hasCall((Stmt) unit, "");
+ }
+
+ public static boolean hasInvokeCall(Unit unit) {
+ return hasCall((Stmt) unit, "");
+ }
+
+ public static boolean hasArrayGetCall(Unit unit) {
+ return hasCall((Stmt) unit, "");
+ }
+
+ private static Type getPostDominateType(UnitGraph cfg, DominatorsFinder dominators, AssignStmt stmt) {
+ // stmt contains clz.newInstance() or fld.get(obj) invocation
+ if (!(stmt.getLeftOp() instanceof Local)) {
+ return null;
+ }
+ Local temp = (Local) stmt.getLeftOp();
+ for (Unit dom : dominators.getDominators(stmt)) {
+ if (dom instanceof AssignStmt &&
+ ((AssignStmt) dom).getRightOp() instanceof CastExpr &&
+ ((CastExpr) ((AssignStmt) dom).getRightOp()).getOp().equals(temp)) {
+ Type t = ((CastExpr) ((AssignStmt) dom).getRightOp()).getCastType();
+ if (t instanceof ArrayType) { // ignore array type
+ return null;
+ } else {
+ return t;
+ }
+ }
+ }
+ return null;
+ }
+}
diff -urN soot-fact-generation-r958-src/src/Representation.java solar-gen/src/Representation.java
--- soot-fact-generation-r958-src/src/Representation.java 2009-03-22 15:45:59.000000000 +1100
+++ solar-gen/src/Representation.java 2015-05-28 15:05:55.000000000 +1000
@@ -1,3 +1,6 @@
+import java.util.HashMap;
+import java.util.Map;
+
import soot.ArrayType;
import soot.Local;
import soot.SootClass;
@@ -5,234 +8,201 @@
import soot.SootMethod;
import soot.Trap;
import soot.Type;
-import soot.Unit;
-import soot.Value;
-import soot.jimple.*;
-import java.util.HashMap;
-import java.util.Map;
+import soot.jimple.AnyNewExpr;
+import soot.jimple.InvokeExpr;
+import soot.jimple.NewArrayExpr;
+import soot.jimple.NewExpr;
+import soot.jimple.NewMultiArrayExpr;
+import soot.jimple.StringConstant;
+
+public class Representation {
+ private Map _methodRepr = new HashMap();
+ private Map _methodSigRepr = new HashMap();
+ private Map _trapRepr = new HashMap();
+
+ public String type(SootClass c) {
+ return c.getName();
+ }
+
+ public String type(Type t) {
+ return t.toString();
+ }
-public class Representation
-{
- private Map _methodRepr = new HashMap();
- private Map _methodSigRepr = new HashMap();
- private Map _trapRepr = new HashMap();
-
- public String type(SootClass c)
- {
- return c.getName();
- }
-
- public String type(Type t)
- {
- return t.toString();
- }
-
- /*
- public String classconstant(Type t)
- {
- return "";
- }
- */
-
- public String classconstant(SootClass c)
- {
- return "";
- }
-
- public String classconstant(Type t)
- {
- return "";
- }
-
- public String signature(SootMethod m)
- {
- String result = _methodSigRepr.get(m);
-
- if(result == null)
- {
- result = m.getSignature();
- _methodSigRepr.put(m, result);
- }
-
- return result;
- }
-
- public String signature(SootField f)
- {
- return f.getSignature();
- }
-
- public String simpleName(SootMethod m)
- {
- return m.getName();
- }
-
- public String simpleName(SootField m)
- {
- return m.getName();
- }
-
- public String modifier(String m)
- {
- return m;
- }
-
- public String descriptor(SootMethod m)
- {
- StringBuilder builder = new StringBuilder();
-
- builder.append(m.getReturnType().toString());
- builder.append("(");
- for(int i = 0; i < m.getParameterCount(); i++)
- {
- builder.append(m.getParameterType(i));
-
- if(i != m.getParameterCount() - 1)
- {
- builder.append(",");
- }
- }
- builder.append(")");
-
- return builder.toString();
- }
-
- public String thisVar(SootMethod m)
- {
- return compactMethod(m) + "/@this";
- }
-
- public String nativeReturnVar(SootMethod m)
- {
- return compactMethod(m) + "/@native-return";
- }
-
- public String param(SootMethod m, int i)
- {
- return compactMethod(m) + "/@param" + i;
- }
-
- public String index(int i)
- {
- return "" + i;
- }
-
- public String local(SootMethod m, Local l)
- {
- return compactMethod(m) + "/" + l.getName();
- }
-
- public String newLocalIntermediate(SootMethod m, Local l, Session session)
- {
- String s = local(m, l);
- return s + "/intermediate/" + session.nextNumber(s);
- }
-
- public String handler(SootMethod m, Trap trap, Session session)
- {
- String result = _trapRepr.get(trap);
-
- if(result == null)
- {
- String name = "catch " + type(trap.getException());
- result = compactMethod(m) + "/" + name + "/" + session.nextNumber(name);
-
- _trapRepr.put(trap, result);
- }
-
- return result;
- }
-
- public String throwLocal(SootMethod m, Local l, Session session)
- {
- String name = "throw " + l.getName();
- return compactMethod(m) + "/" + name + "/" + session.nextNumber(name);
- }
-
- public String method(SootMethod m)
- {
- return signature(m);
- }
-
- /**
- * If there is only one method with the name of m, then returns a
- * compact name. Otherwise, the signature is returned.
- */
- public String compactMethod(SootMethod m)
- {
- String result = _methodRepr.get(m);
-
- if(result == null) {
- String name = m.getName();
-
- int count = 0;
- for(SootMethod other : m.getDeclaringClass().getMethods()) {
- if(other.getName().equals(name)) {
- count++;
- }
- }
-
- if(count > 1) {
- result = m.getSignature();
- }
- else {
- result = m.getDeclaringClass().getName() + "." + name;
- }
-
- _methodRepr.put(m, result);
- }
-
- return result;
- }
-
- public String invoke(SootMethod inMethod, InvokeExpr expr, Session session)
- {
- String name = expr.getMethod().getName();
-
- return compactMethod(inMethod)
- + "/" + expr.getMethod().getDeclaringClass() + "." + name
- + "/" + session.nextNumber(name);
- }
-
- public String heapAlloc(SootMethod inMethod, AnyNewExpr expr, Session session)
- {
- if(expr instanceof NewExpr || expr instanceof NewArrayExpr)
- {
- return heapAlloc(inMethod, expr.getType(), session);
- }
- /* else if(expr instanceof NewMultiArrayExpr)
- {
- return compactMethod(inMethod) + "/" + type + "/" + session.nextNumber(type);
- } */
- else
- {
- throw new RuntimeException("Cannot handle new expression: " + expr);
- }
- }
-
- public String heapMultiArrayAlloc(SootMethod inMethod, NewMultiArrayExpr expr, ArrayType type, Session session)
- {
- return heapAlloc(inMethod, type, session);
- }
-
- public String heapAlloc(SootMethod inMethod, Type type, Session session)
- {
- String s = type.toString();
- return compactMethod(inMethod) + "/new " + s + "/" + session.nextNumber(s);
- }
-
- public String stringconstant(SootMethod inMethod, StringConstant constant)
- {
- String s = constant.toString();
- String content = s.substring(1, s.length() - 1);
-
- if(content.trim().equals(content) && content.length() > 0)
- {
- return content;
- }
- else
- {
- return "<<\"" + content + "\">>";
- }
- }
+ /*
+ * public String classconstant(Type t) { return ""; }
+ */
+
+ public String classconstant(SootClass c) {
+ return "";
+ }
+
+ public String classconstant(Type t) {
+ return "";
+ }
+
+ public String signature(SootMethod m) {
+ String result = _methodSigRepr.get(m);
+
+ if (result == null) {
+ result = m.getSignature();
+ _methodSigRepr.put(m, result);
+ }
+
+ return result;
+ }
+
+ public String signature(SootField f) {
+ return f.getSignature();
+ }
+
+ public String simpleName(SootMethod m) {
+ return m.getName();
+ }
+
+ public String simpleName(SootField m) {
+ return m.getName();
+ }
+
+ public String modifier(String m) {
+ return m;
+ }
+
+ public String descriptor(SootMethod m) {
+ StringBuilder builder = new StringBuilder();
+
+ builder.append(m.getReturnType().toString());
+ builder.append("(");
+ for (int i = 0; i < m.getParameterCount(); i++) {
+ builder.append(m.getParameterType(i));
+
+ if (i != m.getParameterCount() - 1) {
+ builder.append(",");
+ }
+ }
+ builder.append(")");
+
+ return builder.toString();
+ }
+
+ public String thisVar(SootMethod m) {
+ return compactMethod(m) + "/@this";
+ }
+
+ public String nativeReturnVar(SootMethod m) {
+ return compactMethod(m) + "/@native-return";
+ }
+
+ public String param(SootMethod m, int i) {
+ return compactMethod(m) + "/@param" + i;
+ }
+
+ public String index(int i) {
+ return "" + i;
+ }
+
+ public String local(SootMethod m, Local l) {
+ return compactMethod(m) + "/" + l.getName();
+ }
+
+ public String newLocalIntermediate(SootMethod m, Local l, Session session) {
+ String s = local(m, l);
+ return s + "/intermediate/" + session.nextNumber(s);
+ }
+
+ public String handler(SootMethod m, Trap trap, Session session) {
+ String result = _trapRepr.get(trap);
+
+ if (result == null) {
+ String name = "catch " + type(trap.getException());
+ result = compactMethod(m) + "/" + name + "/"
+ + session.nextNumber(name);
+
+ _trapRepr.put(trap, result);
+ }
+
+ return result;
+ }
+
+ public String throwLocal(SootMethod m, Local l, Session session) {
+ String name = "throw " + l.getName();
+ return compactMethod(m) + "/" + name + "/" + session.nextNumber(name);
+ }
+
+ public String method(SootMethod m) {
+ return signature(m);
+ }
+
+ /**
+ * If there is only one method with the name of m, then returns a compact
+ * name. Otherwise, the signature is returned.
+ */
+ public String compactMethod(SootMethod m) {
+ String result = _methodRepr.get(m);
+
+ if (result == null) {
+ String name = m.getName();
+
+ int count = 0;
+ for (SootMethod other : m.getDeclaringClass().getMethods()) {
+ if (other.getName().equals(name)) {
+ count++;
+ }
+ }
+
+ if (count > 1) {
+ result = m.getSignature();
+ } else {
+ result = m.getDeclaringClass().getName() + "." + name;
+ }
+
+ _methodRepr.put(m, result);
+ }
+
+ return result;
+ }
+
+ public String invoke(SootMethod inMethod, InvokeExpr expr, Session session) {
+ String name = expr.getMethod().getName();
+
+ return compactMethod(inMethod) + "/"
+ + expr.getMethod().getDeclaringClass() + "." + name + "/"
+ + session.nextNumber(name);
+ }
+
+ public String heapAlloc(SootMethod inMethod, AnyNewExpr expr,
+ Session session) {
+ if (expr instanceof NewExpr || expr instanceof NewArrayExpr) {
+ return heapAlloc(inMethod, expr.getType(), session);
+ }
+ /*
+ * else if(expr instanceof NewMultiArrayExpr) { return
+ * compactMethod(inMethod) + "/" + type + "/" +
+ * session.nextNumber(type); }
+ */
+ else {
+ throw new RuntimeException("Cannot handle new expression: " + expr);
+ }
+ }
+
+ public String heapMultiArrayAlloc(SootMethod inMethod,
+ NewMultiArrayExpr expr, ArrayType type, Session session) {
+ return heapAlloc(inMethod, type, session);
+ }
+
+ public String heapAlloc(SootMethod inMethod, Type type, Session session) {
+ String s = type.toString();
+ return compactMethod(inMethod) + "/new " + s + "/"
+ + session.nextNumber(s);
+ }
+
+ public String stringconstant(SootMethod inMethod, StringConstant constant) {
+ String s = constant.toString();
+ String content = s.substring(1, s.length() - 1);
+
+ if (content.trim().equals(content) && content.length() > 0) {
+ return content;
+ } else {
+ return "<<\"" + content + "\">>";
+ }
+ }
}
diff -urN soot-fact-generation-r958-src/src/Session.java solar-gen/src/Session.java
--- soot-fact-generation-r958-src/src/Session.java 2009-02-14 05:05:38.000000000 +1100
+++ solar-gen/src/Session.java 2015-05-27 15:30:30.000000000 +1000
@@ -4,51 +4,50 @@
import soot.Unit;
-public class Session
-{
- private Map _map = new HashMap();
-
- public int nextNumber(String s)
- {
- Integer x = _map.get(s);
-
- if(x == null)
- {
- x = new Integer(0);
- }
-
- _map.put(s, new Integer(x.intValue() + 1));
-
- return x.intValue();
- }
-
- private Map _units = new HashMap();
-
- public void numberUnits(Iterator iterator)
- {
- int index = 0;
-
- while(iterator.hasNext())
- {
- _units.put(iterator.next(), new Integer(index));
- index++;
- }
- }
-
- public int getUnitNumber(Unit u)
- {
- return _units.get(u);
- }
-
- private Unit _currentUnit;
-
- public void setCurrentUnit(Unit u)
- {
- _currentUnit = u;
- }
-
- public Unit getCurrentUnit()
- {
- return _currentUnit;
- }
+public class Session {
+ private Map _map = new HashMap();
+
+ public int nextNumber(String s) {
+ Integer x = _map.get(s);
+
+ if (x == null) {
+ x = new Integer(0);
+ }
+
+ _map.put(s, new Integer(x.intValue() + 1));
+
+ return x.intValue();
+ }
+
+ // Used for get number.
+ // Since the integer of the map is always "next value",
+ // the current number should be the value in map minus one
+ public int currentNumber(String s) {
+ return _map.get(s).intValue() - 1;
+ }
+
+ private Map _units = new HashMap();
+
+ public void numberUnits(Iterator iterator) {
+ int index = 0;
+
+ while (iterator.hasNext()) {
+ _units.put(iterator.next(), new Integer(index));
+ index++;
+ }
+ }
+
+ public int getUnitNumber(Unit u) {
+ return _units.get(u);
+ }
+
+ private Unit _currentUnit;
+
+ public void setCurrentUnit(Unit u) {
+ _currentUnit = u;
+ }
+
+ public Unit getCurrentUnit() {
+ return _currentUnit;
+ }
}
release-notes 0000644 0001754 0001754 00000000123 12537532537 012607 0 ustar tiant tiant SOLAR version 0.1 (Monday, 15 June 2015)
- This is the first release of SOLAR.
solar.patch 0000644 0001754 0001754 00000747774 12713476145 012313 0 ustar tiant tiant SOLAR - Effective Soundness-Guided Reflection Analysis
Copyright (C) 2015 Yue Li, Tian Tan, Jingling Xue
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
diff -urN doop-r160113-bin/gen-import solar/gen-import
--- doop-r160113-bin/gen-import 2013-01-16 07:38:09.000000000 +1100
+++ solar/gen-import 2015-08-27 20:55:26.000000000 +1000
@@ -64,6 +64,7 @@
gen-import MethodSignature:SimpleName 2
gen-import MethodSignature:Descriptor 2
gen-import MethodSignature:Type 2
+ gen-import MethodSignature:ReturnType 2
gen-import ReturnVar 2
@@ -103,6 +104,19 @@
gen-import ExceptionHandler:Previous 2
gen-import Instruction:Index 2
+
+ # Generate facts for reflection analysis
+ gen-import ClassNewInstanceCast 2
+ gen-import ConstructorNewInstanceCast 2
+ gen-import FieldGetCast 2
+ gen-import InvokeCast 2
+ gen-import ArrayIndexRef 1
+ gen-import StoreArrayConstantIndexType 3
+ gen-import StoreArrayVarIndexType 2
+ gen-import ClassModifier 2
+ gen-import NewArraySize 2
+ gen-import NrFormalParam 2
+ gen-import MethodInvocationLineNumber 2
}
function main()
diff -urN doop-r160113-bin/logic/context-sensitive.logic solar/logic/context-sensitive.logic
--- doop-r160113-bin/logic/context-sensitive.logic 2013-01-16 07:31:46.000000000 +1100
+++ solar/logic/context-sensitive.logic 2015-08-28 16:02:07.000000000 +1000
@@ -273,6 +273,11 @@
/**
* Load array index
*/
+
+ //YUE: array.f = heap; ; to = array.f
+ //AssignCompatible assure that type consistence between
+ //arg from array and each individual formal
+
VarPointsTo(?hctx, ?heap, ?ctx, ?to) <-
LoadHeapArrayIndex(?ctx, ?to, ?basehctx, ?baseheap),
ArrayIndexPointsTo(?hctx, ?heap, ?basehctx, ?baseheap),
@@ -281,10 +286,23 @@
ComponentType[?baseheaptype] = ?basecomponenttype,
AssignCompatible(?type, ?basecomponenttype).
-/* YANNIS: used to be the much less precise:
+/*
+VarPointsTo(?hctx, ?heap, ?ctx, ?to) <-
+ ReflectiveLoadHeapArrayIndex(?ctx, ?to, ?basehctx, ?baseheap),
+ ArrayIndexPointsTo(?hctx, ?heap, ?basehctx, ?baseheap),
+ Var:Type[?to] = ?type,
+ HeapAllocation:Type[?baseheap] = ?baseheaptype,
+ ComponentType[?baseheaptype] = ?basecomponenttype,
+ AssignCompatible(?type, ?basecomponenttype).
+*/
+
+// Added for handle arguments of reflective calls
+VarPointsTo(?hctx, ?heap, ?ctx, ?to) <-
+ ReflectiveLoadHeapArrayIndex(?ctx, ?to, ?basehctx, ?baseheap),
+ ArrayIndexPointsTo(?hctx, ?heap, ?basehctx, ?baseheap),
+ Var:Type[?to] = ?type,
HeapAllocation:Type[?heap] = ?heaptype,
AssignCompatible(?type, ?heaptype).
-*/
LoadHeapArrayIndex(?ctx, ?to, ?basehctx, ?baseheap) <-
ReachableLoadArrayIndexBase(?base),
@@ -325,12 +343,12 @@
StoreArrayIndex(?from, ?base, _).
/*
StoreHeapArrayIndex(?basehctx, ?baseheap, ?ctx, ?from) <-
- ReachableStoreArrayIndex(?from, ?base),
- VarPointsTo(?basehctx, ?baseheap, ?ctx, ?base).
+ ReachableStoreArrayIndex(?from, ?base),
+ VarPointsTo(?basehctx, ?baseheap, ?ctx, ?base).
ReachableStoreArrayIndex(?from, ?base) <-
- StoreArrayIndex(?from, ?base, ?inmethod),
- Reachable(?inmethod).
+ StoreArrayIndex(?from, ?base, ?inmethod),
+ Reachable(?inmethod).
*/
/**
diff -urN doop-r160113-bin/logic/library/checkcast.logic solar/logic/library/checkcast.logic
--- doop-r160113-bin/logic/library/checkcast.logic 2013-01-16 07:31:46.000000000 +1100
+++ solar/logic/library/checkcast.logic 2015-08-28 16:02:07.000000000 +1000
@@ -34,7 +34,7 @@
CheckCast(?s, t) <-
InterfaceType(?s),
Type:Value(t:"java.lang.Object").
-
+
/**
* o If T is an interface type, then T must be the same interface
* as S or a superinterface of S
diff -urN doop-r160113-bin/logic/library/class-initialization.logic solar/logic/library/class-initialization.logic
--- doop-r160113-bin/logic/library/class-initialization.logic 2013-01-16 07:31:46.000000000 +1100
+++ solar/logic/library/class-initialization.logic 2015-08-28 16:02:07.000000000 +1000
@@ -96,3 +96,7 @@
* TODO: no idea how a statement can ever be executed
* in a class that has not been initialized?
*/
+
+// Initialize the classes which are loaded dynamically
+InitializedClass(?class) <-
+ Config:LoadedClass(?class).
diff -urN doop-r160113-bin/logic/library/common-delta.logic solar/logic/library/common-delta.logic
--- doop-r160113-bin/logic/library/common-delta.logic 2013-01-16 07:31:46.000000000 +1100
+++ solar/logic/library/common-delta.logic 2015-08-28 16:02:07.000000000 +1000
@@ -1,8 +1,10 @@
-#include "native-delta.logic"
-
-PlusHeapAllocationRef(?alloc, "<>", "java.lang.String").
-PlusHeapAllocationRef(?alloc, "<>", "java.lang.StringBuffer").
-
-#if defined(JRE15) || defined(JRE16)
-PlusHeapAllocationRef(?alloc, "<>", "java.lang.StringBuilder").
-#endif
+#include "native-delta.logic"
+
+PlusHeapAllocationRef(?alloc, "<>", "java.lang.String").
+PlusHeapAllocationRef(?alloc, "<>", "java.lang.StringBuffer").
+
+#if defined(JRE15) || defined(JRE16)
+PlusHeapAllocationRef(?alloc, "<>", "java.lang.StringBuilder").
+#endif
+
+PlusHeapAllocationRef(?alloc, "<>", "java.lang.String").
diff -urN doop-r160113-bin/logic/library/fact-declarations.logic solar/logic/library/fact-declarations.logic
--- doop-r160113-bin/logic/library/fact-declarations.logic 2013-01-16 07:31:46.000000000 +1100
+++ solar/logic/library/fact-declarations.logic 2015-08-28 16:02:07.000000000 +1000
@@ -1,491 +1,705 @@
-/**
- * Declarations of facts generated from Jimple (analysis independent)
- *
- * @author Martin Bravenboer
- */
-
-/**
- * Ref-modes
- */
-VarRef(?x), VarRef:Value(?x:?s) -> string(?s).
-
-StringConstant(?x) -> HeapAllocationRef(?x).
-ClassConstant(?x) -> HeapAllocationRef(?x).
-lang:entity(`StringConstant).
-
-MethodSignatureRef(x), MethodSignatureRef:Value(x:s) -> string(s).
-MethodDescriptorRef(x), MethodDescriptorRef:Value(x:s) -> string(s).
-FieldSignatureRef(x), FieldSignatureRef:Value(x:s) -> string(s).
-
-ParamIndexRef(x), ParamIndexRef:Value(x:y) -> int[32](y).
-SimpleNameRef(x), SimpleNameRef:Value(x:s) -> string(s).
-
-ModifierRef(x), ModifierRef:Value(x:s) -> string(s).
-ExceptionHandlerRef(x), ExceptionHandlerRef:Value(x:s) -> string(s).
-
-/**
- * Bytecode Instructions
- */
-InstructionRef(?x), InstructionRef:Value(?x:?s) -> string(?s).
-
-ThrowRef(?x) -> InstructionRef(?x).
-CallGraphEdgeSourceRef(?x) -> InstructionRef(?x).
-MethodInvocationRef(?x) -> CallGraphEdgeSourceRef(?x).
-HeapAllocationRef(?x) -> CallGraphEdgeSourceRef(?x).
-
-/**
- * Java types
- *
- * TODO Improve type hierarchy: ArrayType is a subtype of ClassType,
- * turn ClassType into OrdinaryClassType.
- */
-Type(?x), Type:Value(?x:?s) -> string(?s).
-
-PrimitiveType(?x) -> Type(?x).
-lang:entity(`PrimitiveType).
-
-ReferenceType(?x) -> Type(?x).
-NullType(?x) -> Type(?x).
-lang:entity(`NullType).
-
-ArrayType(?x) -> ReferenceType(?x).
-ClassType(?x) -> ReferenceType(?x).
-InterfaceType(?x) -> ReferenceType(?x).
-lang:entity(`InterfaceType).
-
-/**
- * Capacity declarations
- */
-lang:physical:capacity[`FieldSignatureRef] = 65536. /* 2^16 */
-lang:physical:capacity[`MethodSignatureRef] = 131072.
-lang:physical:capacity[`MethodDescriptorRef] = 131072.
-lang:physical:capacity[`InstructionRef] = 524288. /* 2^19 */
-lang:physical:capacity[`ThrowRef] = 524288. /* = instruction */
-lang:physical:capacity[`CallGraphEdgeSourceRef] = 524288. /* = instruction */
-lang:physical:capacity[`HeapAllocationRef] = 524288. /* = instruction */
-lang:physical:capacity[`MethodInvocationRef] = 524288. /* = instruction */
-lang:physical:capacity[`StringConstant] = 524288./* = CallEdgeSourceRef */
-lang:physical:capacity[`ClassConstant] = 524288./* = CallEdgeSourceRef */
-lang:physical:capacity[`SimpleNameRef] = 131072.
-lang:physical:capacity[`ExceptionHandlerRef] = 131072.
-lang:physical:capacity[`VarRef] = 1048576. /* 2^20 */
-lang:physical:capacity[`ModifierRef] = 32.
-lang:physical:capacity[`Type] = 32768.
-lang:physical:capacity[`PrimitiveType] = 32768.
-lang:physical:capacity[`ReferenceType] = 32768.
-lang:physical:capacity[`NullType] = 32768.
-lang:physical:capacity[`ArrayType] = 32768.
-lang:physical:capacity[`ClassType] = 32768.
-lang:physical:capacity[`InterfaceType] = 32768.
-
-/**
- * Type declarations
- */
-DirectSuperclass[?ref] = ?super ->
- Type(?ref),
- Type(?super).
-
-DirectSuperinterface(?class, ?interface) ->
- Type(?class),
- Type(?interface).
-
-ApplicationClass(?ref) ->
- Type(?ref).
-
-MainClass(?ref) ->
- ClassType(?ref).
-
-/**
- * Variable declarations
- */
-Var:Type[?ref] = ?type ->
- VarRef(?ref),
- Type(?type).
-
-Var:DeclaringMethod(?ref, ?method) ->
- VarRef(?ref),
- MethodSignatureRef(?method).
-
-/**
- * Field declarations
- */
-FieldSignature(?ref, ?declaringClass, ?simplename, ?type) ->
- FieldSignatureRef(?ref),
- Type(?declaringClass),
- SimpleNameRef(?simplename),
- Type(?type).
-
-FieldModifier(?modifier, ?field) ->
- FieldSignatureRef(?field),
- ModifierRef(?modifier).
-
-/**
- * Method declarations
- */
-MethodDeclaration[?signature] = ?ref ->
- MethodSignatureRef(?signature),
- MethodSignatureRef(?ref).
-
-/**
- * Method ?method declares to throw exception ?exceptionType.
- *
- * This predicate corresponds to Java's throws clause, or the
- * Exceptions clause in Java bytecode.
- */
-MethodDeclaration:Exception(?exceptionType, ?method) ->
- MethodSignatureRef(?method),
- Type(?exceptionType).
-
-/**
- * method signatures
-
-MethodSignature(?ref, ?type, ?simplename, ?descriptor) ->
- MethodSignatureRef(?ref),
- Type(?type),
- SimpleNameRef(?simplename),
- MethodDescriptorRef(?descriptor).
- */
-MethodSignature:Type[?signature] = ?type ->
- MethodSignatureRef(?signature),
- Type(?type).
-
-MethodSignature:SimpleName[?signature] = ?simplename ->
- MethodSignatureRef(?signature),
- SimpleNameRef(?simplename).
-
-MethodSignature:Descriptor[?signature] = ?descriptor ->
- MethodSignatureRef(?signature),
- MethodDescriptorRef(?descriptor).
-
-MethodModifier(?mod, ?method) ->
- MethodSignatureRef(?method),
- ModifierRef(?mod).
-
-/**
- * Parameters
- */
-FormalParam[?index, ?method] = ?var ->
- MethodSignatureRef(?method),
- ParamIndexRef(?index),
- VarRef(?var).
-
-ActualParam[?index, ?invocation] = ?var ->
- MethodInvocationRef(?invocation),
- ParamIndexRef(?index),
- VarRef(?var).
-
-ThisVar[?method] = ?var ->
- MethodSignatureRef(?method),
- VarRef(?var).
-
-/**
- * Return variables
- *
- * Note: a Jimple method can have multiple return variables.
- */
-ReturnVar(?var, ?method) ->
- MethodSignatureRef(?method),
- VarRef(?var).
- // OPT: switched var and method because method is usually bound.
-
-/**
- * Special Method invocations
-SpecialMethodInvocation(?invocation, ?base, ?sig, ?inmethod) ->
- MethodInvocationRef(?invocation),
- VarRef(?base),
- MethodSignatureRef(?sig),
- MethodSignatureRef(?inmethod).
- */
-SpecialMethodInvocation:Base[?invocation] = ?base ->
- MethodInvocationRef(?invocation),
- VarRef(?base).
-
-SpecialMethodInvocation:In(?invocation, ?inmethod) ->
- MethodInvocationRef(?invocation),
- MethodSignatureRef(?inmethod).
-
-SpecialMethodInvocation:Signature[?invocation] = ?signature ->
- MethodInvocationRef(?invocation),
- MethodSignatureRef(?signature).
-
-/**
- * Virtual method invocations
- */
-VirtualMethodInvocation(?invocation, ?signature, ?inmethod) ->
- MethodInvocationRef(?invocation),
- MethodSignatureRef(?signature),
- MethodSignatureRef(?inmethod).
-
-VirtualMethodInvocation:Base[?invocation] = ?base ->
- MethodInvocationRef(?invocation),
- VarRef(?base).
-
-VirtualMethodInvocation:In(?invocation, ?inmethod) ->
- MethodInvocationRef(?invocation),
- MethodSignatureRef(?inmethod).
-
-VirtualMethodInvocation:Signature[?invocation] = ?signature ->
- MethodInvocationRef(?invocation),
- MethodSignatureRef(?signature).
-
-/**
- * Static method invocations
-
-StaticMethodInvocation(?invocation, ?sig, ?inmethod) ->
- MethodInvocationRef(?invocation),
- MethodSignatureRef(?sig),
- MethodSignatureRef(?inmethod).
- */
-StaticMethodInvocation(?invocation, ?signature, ?inmethod) ->
- MethodInvocationRef(?invocation),
- MethodSignatureRef(?signature),
- MethodSignatureRef(?inmethod).
-
-StaticMethodInvocation:In(?invocation, ?inmethod) ->
- MethodInvocationRef(?invocation),
- MethodSignatureRef(?inmethod).
-
-StaticMethodInvocation:Signature[?invocation] = ?signature ->
- MethodInvocationRef(?invocation),
- MethodSignatureRef(?signature).
-
-/**
- * Instructions
- */
-
-Instruction:Index[?instruction] = ?index ->
- InstructionRef(?instruction),
- int[32](?index).
-
-/**
- * Heap allocation
- */
-HeapAllocation:Type[?heap] = ?type ->
- HeapAllocationRef(?heap),
- Type(?type).
-
-/**
- * Assignments
- */
-AssignHeapAllocation(?heap, ?to, ?inmethod) ->
- HeapAllocationRef(?heap),
- MethodSignatureRef(?inmethod),
- VarRef(?to).
-
-AssignReturnValue[?invocation] = ?to ->
- MethodInvocationRef(?invocation),
- VarRef(?to).
-
-AssignLocal(?from, ?to, ?inmethod) ->
- MethodSignatureRef(?inmethod),
- VarRef(?from),
- VarRef(?to).
-
-AssignCast(?type, ?from, ?to, ?inmethod) ->
- MethodSignatureRef(?inmethod),
- VarRef(?from),
- VarRef(?to),
- Type(?type).
-
-/**
- * Fields
- */
-// OPT inmethod last
-LoadInstanceField(?base, ?sig, ?to, ?inmethod) ->
- MethodSignatureRef(?inmethod),
- VarRef(?base),
- FieldSignatureRef(?sig),
- VarRef(?to).
-
-LoadStaticField(?sig, ?to, ?inmethod) ->
- MethodSignatureRef(?inmethod),
- FieldSignatureRef(?sig),
- VarRef(?to).
-
-LoadPrimStaticField(?sig, ?inmethod) ->
- MethodSignatureRef(?inmethod),
- FieldSignatureRef(?sig).
-
-StoreInstanceField(?from, ?base, ?signature, ?inmethod) ->
- MethodSignatureRef(?inmethod),
- VarRef(?from),
- VarRef(?base),
- FieldSignatureRef(?signature).
-
-StoreStaticField(?from, ?signature, ?inmethod) ->
- MethodSignatureRef(?inmethod),
- VarRef(?from),
- FieldSignatureRef(?signature).
-
-StorePrimStaticField(?signature, ?inmethod) ->
- MethodSignatureRef(?inmethod),
- FieldSignatureRef(?signature).
-
-/**
- * Arrays
- */
-LoadArrayIndex(?base, ?to, ?inmethod) ->
- MethodSignatureRef(?inmethod),
- VarRef(?base),
- VarRef(?to).
-
-StoreArrayIndex(?from, ?base, ?inmethod) ->
- MethodSignatureRef(?inmethod),
- VarRef(?from),
- VarRef(?base).
-
-ComponentType[?arrayType] = ?componentType ->
- ArrayType(?arrayType),
- Type(?componentType).
-
-/**
- * Exceptions
- */
-Throw(?ref, ?var) ->
- ThrowRef(?ref),
- VarRef(?var).
-
-Throw:Method[?ref] = ?inmethod ->
- ThrowRef(?ref),
- MethodSignatureRef(?inmethod).
-
-/* fact for Paddle compatibility mode */
-SimpleExceptionHandler(?type, ?var, ?inmethod) ->
- Type(?type),
- MethodSignatureRef(?inmethod),
- VarRef(?var).
-
-ExceptionHandler:Method(?handler, ?inmethod) ->
- MethodSignatureRef(?inmethod),
- ExceptionHandlerRef(?handler).
-
-ExceptionHandler:Type[?handler] = ?type ->
- ExceptionHandlerRef(?handler),
- Type(?type).
-
-/**
- * Variable to which caught exceptions are assigned.
- */
-ExceptionHandler:FormalParam[?handler] = ?var ->
- ExceptionHandlerRef(?handler),
- VarRef(?var).
-
-/**
- * First index of the bytecodes covered by this handler.
- */
-ExceptionHandler:Begin[?handler] = ?index ->
- ExceptionHandlerRef(?handler),
- int[32](?index).
-
-/**
- * Last index (excluding this index) of the bytecodes covered by this handler.
- */
-ExceptionHandler:End[?handler] = ?index ->
- ExceptionHandlerRef(?handler),
- int[32](?index).
-
-/**
- * Previous exception handler (handlers are ordered inside a method).
- */
-ExceptionHandler:Previous[?handler] = ?previous ->
- ExceptionHandlerRef(?handler),
- ExceptionHandlerRef(?previous).
-
-/***********************************************************************
- *
- * Reflection
- *
- ***********************************************************************/
-
-ReifiedClass[?type] = ?heap ->
- ClassConstant(?heap),
- Type(?type).
-
-ReifiedConstructor[?constructor] = ?heap ->
- HeapAllocationRef(?heap),
- MethodSignatureRef(?constructor).
-
-ReifiedMethod[?method] = ?heap ->
- HeapAllocationRef(?heap),
- MethodSignatureRef(?method).
-
-ReifiedField[?field] = ?heap ->
- HeapAllocationRef(?heap),
- FieldSignatureRef(?field).
-
-
-/**
- * Reflective operations
- */
-java:lang:Class:newInstance(?invocation, ?to, ?from) ->
- MethodInvocationRef(?invocation),
- VarRef(?to),
- VarRef(?from).
-
-java:lang:reflect:Constructor:newInstance(?invocation, ?to, ?from) ->
- MethodInvocationRef(?invocation),
- VarRef(?to),
- VarRef(?from).
-
-/**
- * Types potentially returned by a specific Class.forName invocation.
- */
-Config:DynamicClass(?class, ?invocation) ->
- Type(?class),
- MethodInvocationRef(?invocation).
-
-ReflectiveHeapAllocation[?instruction, ?type] = ?heap ->
- HeapAllocationRef(?heap),
- Type(?type),
- InstructionRef(?instruction).
-
-/**
- * MISPLACED!!! (REVIEW--Yannis) Everything below this line is not really
- * an EDB. Maybe they used to be, but currently they are computed from regular
- * method calls as part of the reflection logic. This means that any
- * transformation that changes the input "abstract program" does not need
- * to change the relations below or analyze them.
- */
-java:lang:Object:getClass(?to, ?from) ->
- VarRef(?to),
- VarRef(?from).
-
-java:lang:Class:forName(?invocation, ?inmethod) ->
- MethodInvocationRef(?invocation),
- MethodSignatureRef(?inmethod).
-
-java:lang:Class:getConstructor(?to, ?from) ->
- VarRef(?to),
- VarRef(?from).
-
-java:lang:Class:getDeclaredConstructor(?to, ?from) ->
- VarRef(?to),
- VarRef(?from).
-
-java:lang:Class:getDeclaredMethod(?to, ?from) ->
- VarRef(?to),
- VarRef(?from).
-
-java:lang:Class:getDeclaredMethods(?to, ?from) ->
- VarRef(?to),
- VarRef(?from).
-
-java:lang:Class:getDeclaredField(?to, ?from) ->
- VarRef(?to),
- VarRef(?from).
-
-java:lang:Class:getDeclaredFields(?to, ?from) ->
- VarRef(?to),
- VarRef(?from).
-
-java:lang:reflect:Method:invoke(?invocation, ?from) ->
- MethodInvocationRef(?invocation),
- VarRef(?from).
-
-/**
- * Reflective load (get) of a field.
- */
-java:lang:reflect:Field:get(?invocation, ?to, ?field) ->
- MethodInvocationRef(?invocation),
- VarRef(?to),
- VarRef(?field).
+/**
+ * Declarations of facts generated from Jimple (analysis independent)
+ *
+ * @author Martin Bravenboer
+ */
+
+/**
+ * Ref-modes
+ */
+VarRef(?x), VarRef:Value(?x:?s) -> string(?s).
+
+StringConstant(?x) -> HeapAllocationRef(?x).
+ClassConstant(?x) -> HeapAllocationRef(?x).
+lang:entity(`StringConstant).
+
+MethodSignatureRef(x), MethodSignatureRef:Value(x:s) -> string(s).
+MethodDescriptorRef(x), MethodDescriptorRef:Value(x:s) -> string(s).
+FieldSignatureRef(x), FieldSignatureRef:Value(x:s) -> string(s).
+
+ParamIndexRef(x), ParamIndexRef:Value(x:y) -> int[32](y).
+ArrayIndexRef(x), ArrayIndexRef:Value(x:y) -> int[32](y).
+SimpleNameRef(x), SimpleNameRef:Value(x:s) -> string(s).
+
+ModifierRef(x), ModifierRef:Value(x:s) -> string(s).
+ExceptionHandlerRef(x), ExceptionHandlerRef:Value(x:s) -> string(s).
+
+/**
+ * Bytecode Instructions
+ */
+InstructionRef(?x), InstructionRef:Value(?x:?s) -> string(?s).
+
+ThrowRef(?x) -> InstructionRef(?x).
+CallGraphEdgeSourceRef(?x) -> InstructionRef(?x).
+MethodInvocationRef(?x) -> CallGraphEdgeSourceRef(?x).
+HeapAllocationRef(?x) -> CallGraphEdgeSourceRef(?x).
+
+/**
+ * Java types
+ *
+ * TODO Improve type hierarchy: ArrayType is a subtype of ClassType,
+ * turn ClassType into OrdinaryClassType.
+ */
+Type(?x), Type:Value(?x:?s) -> string(?s).
+
+PrimitiveType(?x) -> Type(?x).
+lang:entity(`PrimitiveType).
+
+ReferenceType(?x) -> Type(?x).
+NullType(?x) -> Type(?x).
+lang:entity(`NullType).
+
+ArrayType(?x) -> ReferenceType(?x).
+ClassType(?x) -> ReferenceType(?x).
+InterfaceType(?x) -> ReferenceType(?x).
+lang:entity(`InterfaceType).
+
+/**
+ * Capacity declarations
+ */
+lang:physical:capacity[`FieldSignatureRef] = 65536. /* 2^16 */
+lang:physical:capacity[`MethodSignatureRef] = 131072.
+lang:physical:capacity[`MethodDescriptorRef] = 131072.
+
+lang:physical:capacity[`InstructionRef] = 4194304. /* 2^22 */
+lang:physical:capacity[`ThrowRef] = 4194304. /* = instruction */
+lang:physical:capacity[`CallGraphEdgeSourceRef] = 4194304. /* = instruction */
+lang:physical:capacity[`HeapAllocationRef] = 4194304. /* = instruction */
+lang:physical:capacity[`MethodInvocationRef] = 4194304. /* = instruction */
+lang:physical:capacity[`StringConstant] = 4194304./* = CallEdgeSourceRef */
+lang:physical:capacity[`ClassConstant] = 4194304./* = CallEdgeSourceRef */
+
+lang:physical:capacity[`SimpleNameRef] = 131072.
+lang:physical:capacity[`ExceptionHandlerRef] = 131072.
+lang:physical:capacity[`VarRef] = 1048576. /* 2^20 */
+lang:physical:capacity[`ModifierRef] = 32.
+lang:physical:capacity[`Type] = 32768.
+lang:physical:capacity[`PrimitiveType] = 32768.
+lang:physical:capacity[`ReferenceType] = 32768.
+lang:physical:capacity[`NullType] = 32768.
+lang:physical:capacity[`ArrayType] = 32768.
+lang:physical:capacity[`ClassType] = 32768.
+lang:physical:capacity[`InterfaceType] = 32768.
+
+/**
+ * Type declarations
+ */
+DirectSuperclass[?ref] = ?super ->
+ Type(?ref),
+ Type(?super).
+
+DirectSuperinterface(?class, ?interface) ->
+ Type(?class),
+ Type(?interface).
+
+ApplicationClass(?ref) ->
+ Type(?ref).
+
+MainClass(?ref) ->
+ ClassType(?ref).
+
+ClassModifier(?modifier, ?type) ->
+ ModifierRef(?modifier),
+ ClassType(?type).
+
+/**
+ * Variable declarations
+ */
+Var:Type[?ref] = ?type ->
+ VarRef(?ref),
+ Type(?type).
+
+Var:DeclaringMethod(?ref, ?method) ->
+ VarRef(?ref),
+ MethodSignatureRef(?method).
+
+/**
+ * Field declarations
+ */
+FieldSignature(?ref, ?declaringClass, ?simplename, ?type) ->
+ FieldSignatureRef(?ref),
+ Type(?declaringClass),
+ SimpleNameRef(?simplename),
+ Type(?type).
+
+FieldModifier(?modifier, ?field) ->
+ FieldSignatureRef(?field),
+ ModifierRef(?modifier).
+
+/**
+ * Method declarations
+ */
+MethodDeclaration[?signature] = ?ref ->
+ MethodSignatureRef(?signature),
+ MethodSignatureRef(?ref).
+
+/**
+ * Method ?method declares to throw exception ?exceptionType.
+ *
+ * This predicate corresponds to Java's throws clause, or the
+ * Exceptions clause in Java bytecode.
+ */
+MethodDeclaration:Exception(?exceptionType, ?method) ->
+ MethodSignatureRef(?method),
+ Type(?exceptionType).
+
+/**
+ * method signatures
+
+MethodSignature(?ref, ?type, ?simplename, ?descriptor) ->
+ MethodSignatureRef(?ref),
+ Type(?type),
+ SimpleNameRef(?simplename),
+ MethodDescriptorRef(?descriptor).
+ */
+MethodSignature:Type[?signature] = ?type ->
+ MethodSignatureRef(?signature),
+ Type(?type).
+
+MethodSignature:SimpleName[?signature] = ?simplename ->
+ MethodSignatureRef(?signature),
+ SimpleNameRef(?simplename).
+
+MethodSignature:Descriptor[?signature] = ?descriptor ->
+ MethodSignatureRef(?signature),
+ MethodDescriptorRef(?descriptor).
+
+/**
+ * Add return type for invoke cast
+ */
+MethodSignature:ReturnType[?signature] = ?retType ->
+ MethodSignatureRef(?signature),
+ Type(?retType).
+
+MethodModifier(?mod, ?method) ->
+ MethodSignatureRef(?method),
+ ModifierRef(?mod).
+
+/**
+ * Parameters
+ */
+FormalParam[?index, ?method] = ?var ->
+ MethodSignatureRef(?method),
+ ParamIndexRef(?index),
+ VarRef(?var).
+
+ActualParam[?index, ?invocation] = ?var ->
+ MethodInvocationRef(?invocation),
+ ParamIndexRef(?index),
+ VarRef(?var).
+
+ThisVar[?method] = ?var ->
+ MethodSignatureRef(?method),
+ VarRef(?var).
+
+/**
+ * Return variables
+ *
+ * Note: a Jimple method can have multiple return variables.
+ */
+ReturnVar(?var, ?method) ->
+ MethodSignatureRef(?method),
+ VarRef(?var).
+ // OPT: switched var and method because method is usually bound.
+
+/**
+ * Special Method invocations
+SpecialMethodInvocation(?invocation, ?base, ?sig, ?inmethod) ->
+ MethodInvocationRef(?invocation),
+ VarRef(?base),
+ MethodSignatureRef(?sig),
+ MethodSignatureRef(?inmethod).
+ */
+SpecialMethodInvocation:Base[?invocation] = ?base ->
+ MethodInvocationRef(?invocation),
+ VarRef(?base).
+
+SpecialMethodInvocation:In(?invocation, ?inmethod) ->
+ MethodInvocationRef(?invocation),
+ MethodSignatureRef(?inmethod).
+
+SpecialMethodInvocation:Signature[?invocation] = ?signature ->
+ MethodInvocationRef(?invocation),
+ MethodSignatureRef(?signature).
+
+/**
+ * Virtual method invocations
+ */
+VirtualMethodInvocation(?invocation, ?signature, ?inmethod) ->
+ MethodInvocationRef(?invocation),
+ MethodSignatureRef(?signature),
+ MethodSignatureRef(?inmethod).
+
+VirtualMethodInvocation:Base[?invocation] = ?base ->
+ MethodInvocationRef(?invocation),
+ VarRef(?base).
+
+VirtualMethodInvocation:In(?invocation, ?inmethod) ->
+ MethodInvocationRef(?invocation),
+ MethodSignatureRef(?inmethod).
+
+VirtualMethodInvocation:Signature[?invocation] = ?signature ->
+ MethodInvocationRef(?invocation),
+ MethodSignatureRef(?signature).
+
+/**
+ * Static method invocations
+
+StaticMethodInvocation(?invocation, ?sig, ?inmethod) ->
+ MethodInvocationRef(?invocation),
+ MethodSignatureRef(?sig),
+ MethodSignatureRef(?inmethod).
+ */
+StaticMethodInvocation(?invocation, ?signature, ?inmethod) ->
+ MethodInvocationRef(?invocation),
+ MethodSignatureRef(?signature),
+ MethodSignatureRef(?inmethod).
+
+StaticMethodInvocation:In(?invocation, ?inmethod) ->
+ MethodInvocationRef(?invocation),
+ MethodSignatureRef(?inmethod).
+
+StaticMethodInvocation:Signature[?invocation] = ?signature ->
+ MethodInvocationRef(?invocation),
+ MethodSignatureRef(?signature).
+
+/**
+ * Instructions
+ */
+
+Instruction:Index[?instruction] = ?index ->
+ InstructionRef(?instruction),
+ int[32](?index).
+
+/**
+ * Heap allocation
+ */
+HeapAllocation:Type[?heap] = ?type ->
+ HeapAllocationRef(?heap),
+ Type(?type).
+
+/**
+ * Assignments
+ */
+AssignHeapAllocation(?heap, ?to, ?inmethod) ->
+ HeapAllocationRef(?heap),
+ MethodSignatureRef(?inmethod),
+ VarRef(?to).
+
+AssignReturnValue[?invocation] = ?to ->
+ MethodInvocationRef(?invocation),
+ VarRef(?to).
+
+AssignLocal(?from, ?to, ?inmethod) ->
+ MethodSignatureRef(?inmethod),
+ VarRef(?from),
+ VarRef(?to).
+
+AssignCast(?type, ?from, ?to, ?inmethod) ->
+ MethodSignatureRef(?inmethod),
+ VarRef(?from),
+ VarRef(?to),
+ Type(?type).
+
+/**
+ * Fields
+ */
+// OPT inmethod last
+LoadInstanceField(?base, ?sig, ?to, ?inmethod) ->
+ MethodSignatureRef(?inmethod),
+ VarRef(?base),
+ FieldSignatureRef(?sig),
+ VarRef(?to).
+
+LoadStaticField(?sig, ?to, ?inmethod) ->
+ MethodSignatureRef(?inmethod),
+ FieldSignatureRef(?sig),
+ VarRef(?to).
+
+LoadPrimStaticField(?sig, ?inmethod) ->
+ MethodSignatureRef(?inmethod),
+ FieldSignatureRef(?sig).
+
+StoreInstanceField(?from, ?base, ?signature, ?inmethod) ->
+ MethodSignatureRef(?inmethod),
+ VarRef(?from),
+ VarRef(?base),
+ FieldSignatureRef(?signature).
+
+StoreStaticField(?from, ?signature, ?inmethod) ->
+ MethodSignatureRef(?inmethod),
+ VarRef(?from),
+ FieldSignatureRef(?signature).
+
+StorePrimStaticField(?signature, ?inmethod) ->
+ MethodSignatureRef(?inmethod),
+ FieldSignatureRef(?signature).
+
+/**
+ * Arrays
+ */
+LoadArrayIndex(?base, ?to, ?inmethod) ->
+ MethodSignatureRef(?inmethod),
+ VarRef(?base),
+ VarRef(?to).
+
+StoreArrayIndex(?from, ?base, ?inmethod) ->
+ MethodSignatureRef(?inmethod),
+ VarRef(?from),
+ VarRef(?base).
+
+// For matching arguments to filter methods
+StoreArrayConstantIndexType(?type, ?base, ?index) ->
+ Type(?type),
+ VarRef(?base),
+ ArrayIndexRef(?index).
+
+StoreArrayVarIndexType(?base, ?type) ->
+ VarRef(?base),
+ Type(?type).
+
+ComponentType[?arrayType] = ?componentType ->
+ ArrayType(?arrayType),
+ Type(?componentType).
+
+/**
+ * Exceptions
+ */
+Throw(?ref, ?var) ->
+ ThrowRef(?ref),
+ VarRef(?var).
+
+Throw:Method[?ref] = ?inmethod ->
+ ThrowRef(?ref),
+ MethodSignatureRef(?inmethod).
+
+/* fact for Paddle compatibility mode */
+SimpleExceptionHandler(?type, ?var, ?inmethod) ->
+ Type(?type),
+ MethodSignatureRef(?inmethod),
+ VarRef(?var).
+
+ExceptionHandler:Method(?handler, ?inmethod) ->
+ MethodSignatureRef(?inmethod),
+ ExceptionHandlerRef(?handler).
+
+ExceptionHandler:Type[?handler] = ?type ->
+ ExceptionHandlerRef(?handler),
+ Type(?type).
+
+/**
+ * Variable to which caught exceptions are assigned.
+ */
+ExceptionHandler:FormalParam[?handler] = ?var ->
+ ExceptionHandlerRef(?handler),
+ VarRef(?var).
+
+/**
+ * First index of the bytecodes covered by this handler.
+ */
+ExceptionHandler:Begin[?handler] = ?index ->
+ ExceptionHandlerRef(?handler),
+ int[32](?index).
+
+/**
+ * Last index (excluding this index) of the bytecodes covered by this handler.
+ */
+ExceptionHandler:End[?handler] = ?index ->
+ ExceptionHandlerRef(?handler),
+ int[32](?index).
+
+/**
+ * Previous exception handler (handlers are ordered inside a method).
+ */
+ExceptionHandler:Previous[?handler] = ?previous ->
+ ExceptionHandlerRef(?handler),
+ ExceptionHandlerRef(?previous).
+
+/***********************************************************************
+ *
+ * Reflection
+ *
+ ***********************************************************************/
+ReifiedClass[?type] = ?heap ->
+ ClassConstant(?heap),
+ Type(?type).
+
+ReifiedConstructor[?constructor] = ?heap ->
+ HeapAllocationRef(?heap),
+ MethodSignatureRef(?constructor).
+
+ReifiedMethod[?method] = ?heap ->
+ HeapAllocationRef(?heap),
+ MethodSignatureRef(?method).
+
+ReifiedField[?field] = ?heap ->
+ HeapAllocationRef(?heap),
+ FieldSignatureRef(?field).
+
+// For rules about place holder heap in reflection-delta.logic
+UnknownObject[?invo] = ?heap ->
+ MethodInvocationRef(?invo),
+ HeapAllocationRef(?heap).
+
+UnknownClass[?heap] = ?invo ->
+ HeapAllocationRef(?heap),
+ MethodInvocationRef(?invo).
+
+// unknown Constructor
+UnknownConstructor[?heap] = ?invo ->
+ HeapAllocationRef(?heap),
+ MethodInvocationRef(?invo).
+
+UnknownDeclaredConstructor[?heap] = ?invo ->
+ HeapAllocationRef(?heap),
+ MethodInvocationRef(?invo).
+
+// unknown Method
+MethodUUHeap[?heap] = ?invo ->
+ HeapAllocationRef(?heap),
+ MethodInvocationRef(?invo).
+
+DeclaredMethodUUHeap[?heap] = ?invo ->
+ HeapAllocationRef(?heap),
+ MethodInvocationRef(?invo).
+
+MethodUSHeap[?heap] = ?name ->
+ HeapAllocationRef(?heap),
+ SimpleNameRef(?name).
+
+DeclaredMethodUSHeap[?heap] = ?name ->
+ HeapAllocationRef(?heap),
+ SimpleNameRef(?name).
+
+FieldUSHeap[?heap] = ?name ->
+ HeapAllocationRef(?heap),
+ SimpleNameRef(?name).
+
+DeclaredFieldUSHeap[?heap] = ?name ->
+ HeapAllocationRef(?heap),
+ SimpleNameRef(?name).
+
+// unknown Field
+FieldUUHeap[?heap] = ?invo ->
+ HeapAllocationRef(?heap),
+ MethodInvocationRef(?invo).
+
+DeclaredFieldUUHeap[?heap] = ?invo ->
+ HeapAllocationRef(?heap),
+ MethodInvocationRef(?invo).
+
+// unresolved method/field place holder
+MethodTUHeap[?heap] = ?type ->
+ HeapAllocationRef(?heap),
+ Type(?type).
+
+DeclaredMethodTUHeap[?heap] = ?type ->
+ HeapAllocationRef(?heap),
+ Type(?type).
+
+FieldTUHeap[?heap] = ?type ->
+ HeapAllocationRef(?heap),
+ Type(?type).
+
+DeclaredFieldTUHeap[?heap] = ?type ->
+ HeapAllocationRef(?heap),
+ Type(?type).
+
+// For rules about place holder
+GetMethodsHeap[?invo] = ?heap ->
+ HeapAllocationRef(?heap),
+ MethodInvocationRef(?invo).
+
+GetDeclaredMethodsHeap[?invo] = ?heap ->
+ HeapAllocationRef(?heap),
+ MethodInvocationRef(?invo).
+
+GetFieldsHeap[?invo] = ?heap ->
+ HeapAllocationRef(?heap),
+ MethodInvocationRef(?invo).
+
+GetDeclaredFieldsHeap[?invo] = ?heap ->
+ HeapAllocationRef(?heap),
+ MethodInvocationRef(?invo).
+
+GetConstructorsHeap[?invo] = ?heap ->
+ HeapAllocationRef(?heap),
+ MethodInvocationRef(?invo).
+
+GetDeclaredConstructorsHeap[?invo] = ?heap ->
+ HeapAllocationRef(?heap),
+ MethodInvocationRef(?invo).
+
+/**
+ * Reflective operations
+ */
+java:lang:Class:newInstance(?invocation, ?to, ?from) ->
+ MethodInvocationRef(?invocation),
+ VarRef(?to),
+ VarRef(?from).
+
+java:lang:reflect:Constructor:newInstance(?invocation, ?to, ?from) ->
+ MethodInvocationRef(?invocation),
+ VarRef(?to),
+ VarRef(?from).
+
+/**
+ * Types potentially returned by a specific Class.forName invocation.
+ */
+Config:DynamicClass(?class, ?invocation) ->
+ Type(?class),
+ MethodInvocationRef(?invocation).
+
+// Read annotation to aware which classes should be loaded
+Config:LoadedClass(?class) ->
+ Type(?class).
+
+Config:ReflectMethod(?invocation, ?method) ->
+ MethodInvocationRef(?invocation),
+ MethodSignatureRef(?method).
+
+ReflectiveHeapAllocation[?instruction, ?type] = ?heap ->
+ HeapAllocationRef(?heap),
+ Type(?type),
+ InstructionRef(?instruction).
+
+/**
+ * MISPLACED!!! (REVIEW--Yannis) Everything below this line is not really
+ * an EDB. Maybe they used to be, but currently they are computed from regular
+ * method calls as part of the reflection logic. This means that any
+ * transformation that changes the input "abstract program" does not need
+ * to change the relations below or analyze them.
+ */
+java:lang:Class:getMethod(?invo, ?base) ->
+ MethodInvocationRef(?invo), VarRef(?base).
+
+java:lang:Class:getField(?invo, ?base) ->
+ MethodInvocationRef(?invo), VarRef(?base).
+
+java:lang:Class:getDeclaredMethod(?invo, ?base) ->
+ MethodInvocationRef(?invo), VarRef(?base).
+
+java:lang:Class:getDeclaredField(?invo, ?base) ->
+ MethodInvocationRef(?invo), VarRef(?base).
+
+java:lang:Class:getConstructor(?invo, ?to, ?from) ->
+ MethodInvocationRef(?invo),
+ VarRef(?to),
+ VarRef(?from).
+
+java:lang:Class:getDeclaredConstructor(?invo, ?to, ?from) ->
+ MethodInvocationRef(?invo),
+ VarRef(?to),
+ VarRef(?from).
+
+java:lang:Class:getMethods(?invocation, ?from) ->
+ MethodInvocationRef(?invocation),
+ VarRef(?from).
+
+java:lang:Class:getDeclaredMethods(?invocation, ?from) ->
+ MethodInvocationRef(?invocation),
+ VarRef(?from).
+
+java:lang:Class:getFields(?invocation, ?from) ->
+ MethodInvocationRef(?invocation),
+ VarRef(?from).
+
+java:lang:Class:getDeclaredFields(?invocation, ?from) ->
+ MethodInvocationRef(?invocation),
+ VarRef(?from).
+
+java:lang:Class:getConstructors(?invocation, ?from) ->
+ MethodInvocationRef(?invocation),
+ VarRef(?from).
+
+java:lang:Class:getDeclaredConstructors(?invocation, ?from) ->
+ MethodInvocationRef(?invocation),
+ VarRef(?from).
+
+// For array newinstance
+java:lang:reflect:Array:newInstance(?invocation, ?to) ->
+ MethodInvocationRef(?invocation),
+ VarRef(?to).
+
+ReflectiveArrayHeapAllocation[?invo, ?componentType] = ?heap ->
+ MethodInvocationRef(?invo),
+ Type(?componentType),
+ HeapAllocationRef(?heap).
+
+java:lang:Object:getClass(?invo, ?to, ?from) ->
+ MethodInvocationRef(?invo),
+ VarRef(?to),
+ VarRef(?from).
+
+java:lang:Class:forName(?invocation, ?inmethod) ->
+ MethodInvocationRef(?invocation),
+ MethodSignatureRef(?inmethod).
+
+java:lang:Class:getName(?to, ?from) ->
+ VarRef(?to), VarRef(?from).
+
+loadClass(?invocation, ?inmethod) ->
+ MethodInvocationRef(?invocation),
+ MethodSignatureRef(?inmethod).
+
+java:lang:ClassLoader:loadClass(?invocation, ?inmethod) ->
+ MethodInvocationRef(?invocation),
+ MethodSignatureRef(?inmethod).
+
+java:lang:reflect:Method:invoke(?invocation, ?from) ->
+ MethodInvocationRef(?invocation),
+ VarRef(?from).
+
+/**
+ * Reflective load (get) of a field.
+ */
+java:lang:reflect:Field:get(?invocation, ?to, ?field) ->
+ MethodInvocationRef(?invocation),
+ VarRef(?to),
+ VarRef(?field).
+
+/**
+ * Cast post dominator of clz.newInstance,
+ * ctor.newInstance and fld.get
+ */
+ClassNewInstanceCast(?invocation, ?type) ->
+ MethodInvocationRef(?invocation),
+ Type(?type).
+
+ConstructorNewInstanceCast(?invocation, ?type) ->
+ MethodInvocationRef(?invocation),
+ Type(?type).
+
+FieldGetCast(?invocation, ?type) ->
+ MethodInvocationRef(?invocation),
+ Type(?type).
+
+InvokeCast(?invocation, ?type) ->
+ MethodInvocationRef(?invocation),
+ Type(?type).
+
+ArrayGetCast(?invocation, ?type) ->
+ MethodInvocationRef(?invocation),
+ Type(?type).
+
+NewArraySize[?arrayHeap] = ?size ->
+ HeapAllocationRef(?arrayHeap),
+ int[16](?size).
+
+NrFormalParam[?method] = ?nr ->
+ MethodSignatureRef(?method),
+ int[16](?nr).
+
+/**
+ * Line numbers of invocations
+ */
+MethodInvocationLineNumber[?invocation] = ?lineNumber ->
+ MethodInvocationRef(?invocation),
+ int[32](?lineNumber).
+
+/**
+ * Place holder of meta-objects.
+ */
+ClassToEntry[?class] = ?invo -> HeapAllocationRef(?class), MethodInvocationRef(?invo).
+ConstructorToMemberIntro[?ctor] = ?invo -> HeapAllocationRef(?ctor), MethodInvocationRef(?invo).
+MethodToMemberIntro[?method] = ?invo -> HeapAllocationRef(?method), MethodInvocationRef(?invo).
diff -urN doop-r160113-bin/logic/library/method-resolution.logic solar/logic/library/method-resolution.logic
--- doop-r160113-bin/logic/library/method-resolution.logic 2013-01-16 07:31:46.000000000 +1100
+++ solar/logic/library/method-resolution.logic 2015-08-28 16:02:07.000000000 +1000
@@ -50,5 +50,9 @@
MethodSignature:SimpleName[?signature] = ?simplename,
MethodSignature:Descriptor[?signature] = ?descriptor,
MethodDeclaration[?signature] = ?method,
+ ! SummariedMethod(?method),
ModifierRef:Value(?abstract:"abstract"),
! MethodModifier(?abstract, ?method).
+
+SummariedMethod(?method) <-
+ MethodSignatureRef:Value(?method:"").
diff -urN doop-r160113-bin/logic/library/native-delta.logic solar/logic/library/native-delta.logic
--- doop-r160113-bin/logic/library/native-delta.logic 2013-01-16 07:31:46.000000000 +1100
+++ solar/logic/library/native-delta.logic 2015-08-28 16:02:07.000000000 +1000
@@ -1,362 +1,458 @@
-/**********************************************************************************
- *
- * Simulation of native code by code generation.
- *
- * Note that some other natives are simulated by logic.
- *
- * @author Martin Bravenboer
- *
- **********************************************************************************/
-
-/**
- *
- * The ugly: macro abstractions
- *
- * This should really be generated from Jimple, but that's currently
- * somewhat complicated.
- */
-
-#define PlusAssignLocal(strFrom, strTo, strMethod) \
- +AssignLocal(?from, ?to, ?method) <- \
- VarRef:Value(?from:strFrom), \
- VarRef:Value(?to:strTo), \
- MethodSignatureRef:Value(?method:strMethod)
-
-#define PlusStoreStaticField(method, local, field) \
- +StoreStaticField(?l, ?sig, ?m) <- \
- MethodSignatureRef:Value(?m:method), \
- VarRef:Value(?l:local), \
- FieldSignatureRef:Value(?sig:field)
-
-#define SimulateNativeAllocation(strMethod, strHeap, strConstructor) \
- +AssignHeapAllocation(?heap, ?return, ?method) \
- <- \
- MethodSignatureRef:Value(?method:strMethod), \
- ReturnVar@previous(?return, ?method), \
- HeapAllocationValue(?heap, strHeap). \
- \
- +SpecialMethodInvocation:Base[?invocation] = ?return, \
- +SpecialMethodInvocation:In(?invocation, ?method), \
- +SpecialMethodInvocation:Signature[?invocation] = ?constructor, \
- PlusMethodInvocationRef(?invocation, ?strInvocation), \
- +Instruction:Index[?invocation] = ?index \
- <- \
- MethodSignatureRef:Value(?method:strMethod), \
- ReturnVar@previous(?return, ?method), \
- ?strInvocation = strMethod + "/native " + strConstructor, \
- MethodSignatureRef:Value(?constructor:strConstructor), \
- ?index = 1
-
-#define SimulateNativeArrayAllocation(strMethod, strArray, strElement, strElementType) \
- +AssignHeapAllocation(?heap, ?return, ?method) \
- <- \
- MethodSignatureRef:Value(?method:strMethod), \
- ReturnVar@previous(?return, ?method), \
- HeapAllocationValue(?heap, strArray). \
- \
- +VarRef:Value(?var), \
- +VarRef:Value(?var:?strVar), \
- +Var:Type[?var] = ?type, \
- +Var:DeclaringMethod(?var, ?method), \
- +AssignHeapAllocation(?heap, ?var, ?method), \
- +StoreArrayIndex(?var, ?base, ?method) \
- <- \
- MethodSignatureRef:Value(?method:strMethod), \
- ReturnVar@previous(?base, ?method), \
- ?strVar = strMethod + "/@native-array-element", \
- Type:Value(?type:strElementType), \
- HeapAllocationValue(?heap, strElement)
-
-#define SimulateNativeStringArrayAllocation(strMethod, strArray, strElement, strElementType) \
- +AssignHeapAllocation(?heap, ?return, ?method) \
- <- \
- MethodSignatureRef:Value(?method:strMethod), \
- ReturnVar@previous(?return, ?method), \
- HeapAllocationValue(?heap, strArray). \
- \
- +VarRef(?var), \
- +VarRef:Value(?var:?strVar), \
- +Var:Type[?var] = ?type, \
- +Var:DeclaringMethod(?var, ?method), \
- +AssignHeapAllocation(?heap, ?var, ?method), \
- +StoreArrayIndex(?var, ?base, ?method) \
- <- \
- MethodSignatureRef:Value(?method:strMethod), \
- ReturnVar@previous(?base, ?method), \
- ?strVar = strMethod + "/@native-array-element", \
- Type:Value(?type:strElementType), \
- HeapAllocationValue(?heap, strElement)
-
-#ifndef PADDLE_COMPAT
-
-#define SimulateNativeStaticToVirtual(strMethod, strVirtual) \
- PlusMethodInvocationRef(?invocation, ?strInvocation), \
- +VirtualMethodInvocation(?invocation, ?signature, ?inmethod), \
- +VirtualMethodInvocation:Base[?invocation] = ?base, \
- +VirtualMethodInvocation:In(?invocation, ?inmethod), \
- +VirtualMethodInvocation:Signature[?invocation] = ?signature, \
- +Instruction:Index[?invocation] = ?index \
- <- \
- MethodSignatureRef:Value(?inmethod:strMethod), \
- ParamIndexRef:Value(?zero:0), \
- FormalParam@previous[?zero, ?inmethod] = ?base, \
- ?strInvocation = strMethod + "/native " + strVirtual, \
- MethodSignatureRef:Value(?signature:strVirtual), \
- ?index = 1.\
- \
- PlusMethodInvocationRef(?invocation, ?strInvocation), \
- +AssignReturnValue[?invocation] = ?return \
- <- \
- MethodSignatureRef:Value(?inmethod:strMethod), \
- ReturnVar@previous(?return, ?inmethod), \
- ?strInvocation = strMethod + "/native " + strVirtual
-
-#else
-
-#define SimulateNativeStaticToVirtual(strMethod, strVirtual) \
- +VirtualMethodInvocation(?invocation, ?virtual, ?inmethod), \
- +VirtualMethodInvocation:Base[?invocation] = ?base, \
- +VirtualMethodInvocation:In(?invocation, ?inmethod), \
- +VirtualMethodInvocation:Signature[?invocation] = ?virtual \
- <- \
- MethodSignatureRef:Value(?native:strMethod), \
- StaticMethodInvocation:Signature[?invocation] = ?native, \
- StaticMethodInvocation:In(?invocation, ?inmethod), \
- ParamIndexRef:Value(?zero:0), \
- ActualParam@previous[?zero, ?invocation] = ?base, \
- MethodSignatureRef:Value(?virtual:strVirtual)
-#endif
-
-
-/**********************************************************************************
- *
- * java.lang.Object
- *
- **********************************************************************************/
-
-/**
- *
- *
- * TODO could throw CloneNotSupportedException
- *
- * TODO should check if the object is Cloneable.
- *
- * TODO should return a clone of the heap allocation (not
- * identity). The behaviour implemented here is based on Soot.
- */
-PlusAssignLocal(
- "java.lang.Object.clone/@this",
- "java.lang.Object.clone/@native-return",
- "").
-
-/**********************************************************************************
- *
- * java.lang.Class
- *
- **********************************************************************************/
-
-#ifndef PADDLE_COMPAT
-+java:lang:Class:newInstance(?invocation, ?to, ?from) <-
- MethodSignatureRef:Value(?newInstance:""),
- VirtualMethodInvocation:Signature[?invocation] = ?newInstance,
- AssignReturnValue[?invocation] = ?to,
- VirtualMethodInvocation:Base[?invocation] = ?from.
-
-+java:lang:reflect:Constructor:newInstance(?invocation, ?to, ?base) <-
- MethodSignatureRef:Value(?invoke:""),
- VirtualMethodInvocation:Signature[?invocation] = ?invoke,
- VirtualMethodInvocation:Base[?invocation] = ?base,
- AssignReturnValue[?invocation] = ?to.
-/**
- * TODO - In JRE1.3 this is actually not the native method
- * - In OpenJDK there is a different method getDeclaredMethods0
- * - In JRE 1.4 this seems to be defined in java.lang.reflect.Method
- */
-+java:lang:Class:getDeclaredMethods(?to, ?from) <-
- MethodSignatureRef:Value(?signature:""),
- VirtualMethodInvocation:Signature[?invocation] = ?signature,
- AssignReturnValue[?invocation] = ?to,
- VirtualMethodInvocation:Base[?invocation] = ?from.
-#endif
-
-/**********************************************************************************
- *
- * java.lang.System
- *
- ***************************************************/
-
-#ifndef PADDLE_COMPAT
-/**
- *
- */
-PlusStoreStaticField(
- "",
- "java.lang.System.setIn0/@param0",
- "").
-
-/**
- *
- */
-PlusStoreStaticField(
- "",
- "java.lang.System.setOut0/@param0",
- "").
-
-/**
- *
- */
-PlusStoreStaticField(
- "",
- "java.lang.System.setErr0/@param0",
- "").
-#endif
-
-/**
- *
- */
-/*
-PlusVarRef(?tmp, ?arraycopy, ?tmpStr, ?tmpType),
-+LoadArrayIndex(?src, ?tmp, ?arraycopy),
-+StoreArrayIndex(?tmp, ?dest, ?arraycopy)
- <-
- MethodSignatureRef:Value(?arraycopy:""),
- ParamIndexRef:Value(?zero:0),
- ParamIndexRef:Value(?two:2),
- FormalParam[?zero, ?arraycopy] = ?src,
- FormalParam[?two, ?arraycopy] = ?dest,
- Type:Value(?tmpType:"java.lang.Object"),
- ?tmpStr = "System.arraycopy/@native-tmp".
-*/
-#ifndef PADDLE_COMPAT
-PlusVarRef(?tmp, ?inmethod, ?tmpStr, ?tmpType),
-+LoadArrayIndex(?src, ?tmp, ?inmethod),
-+StoreArrayIndex(?tmp, ?dest, ?inmethod)
- <-
- MethodSignatureRef:Value(?arraycopy:""),
- StaticMethodInvocation(?invocation, ?arraycopy, ?inmethod),
- ParamIndexRef:Value(?zero:0),
- ParamIndexRef:Value(?two:2),
- ActualParam@previous[?zero, ?invocation] = ?src,
- ActualParam@previous[?two, ?invocation] = ?dest,
- MethodInvocationValue(?invocation, ?strInvocation),
- ?tmpStr = ?strInvocation + "/@tmp-arraycopy",
- Type:Value(?tmpType:"java.lang.Object").
-#endif
-
-/**********************************************************************************
- *
- * java.io.FileSystem
- *
- **********************************************************************************/
-
-#ifndef PADDLE_COMPAT
-#ifdef OS_UNIX
-PlusHeapAllocationRef(?alloc, "java.io.FileSystem.getFileSystem/new java.io.UnixFileSystem", "java.io.UnixFileSystem").
-PlusHeapAllocationRef(?alloc, "java.io.UnixFileSystem.list/new java.lang.String[]", "java.lang.String[]").
-PlusHeapAllocationRef(?alloc, "java.io.UnixFileSystem.list/new java.lang.String", "java.lang.String").
-
-SimulateNativeAllocation(
- "",
- "java.io.FileSystem.getFileSystem/new java.io.UnixFileSystem",
- "()>").
-
-SimulateNativeStringArrayAllocation(
- "",
- "java.io.UnixFileSystem.list/new java.lang.String[]",
- "java.io.UnixFileSystem.list/new java.lang.String",
- "java.lang.String").
-
-#endif
-
-#ifdef OS_WIN32
-PlusHeapAllocationRef(?alloc, "java.io.FileSystem.getFileSystem/new java.io.Win32FileSystem", "java.io.Win32FileSystem").
-PlusHeapAllocationRef(?alloc, "java.io.Win32FileSystem.list/new java.lang.String[]", "java.lang.String[]").
-PlusHeapAllocationRef(?alloc, "java.io.Win32FileSystem.list/new java.lang.String", "java.lang.String").
-
-SimulateNativeAllocation(
- "",
- "java.io.FileSystem.getFileSystem/new java.io.Win32FileSystem",
- "()>").
-
-SimulateNativeStringArrayAllocation(
- "",
- "java.io.Win32FileSystem.list/new java.lang.String[]",
- "java.io.Win32FileSystem.list/new java.lang.String",
- "java.lang.String").
-#endif
-
-#ifdef OS_WINNT
-PlusHeapAllocationRef(?alloc, "java.io.FileSystem.getFileSystem/new java.io.WinNTFileSystem", "java.io.WinNTFileSystem").
-PlusHeapAllocationRef(?alloc, "java.io.Win32FileSystem.list/new java.lang.String[]", "java.lang.String[]").
-PlusHeapAllocationRef(?alloc, "java.io.Win32FileSystem.list/new java.lang.String", "java.lang.String").
-
-SimulateNativeAllocation(
- "",
- "java.io.FileSystem.getFileSystem/new java.io.WinNTFileSystem",
- "()>").
-
-SimulateNativeStringArrayAllocation(
- "",
- "java.io.WinNTFileSystem.list/new java.lang.String[]",
- "java.io.WinNTFileSystem.list/new java.lang.String",
- "java.lang.String").
-#endif
-#endif
-
-/**********************************************************************************
- *
- * java.lang.ref.Finalizer
- *
- **********************************************************************************/
-
-/**
- * Indirect invocations of finalize methods from java.lang.ref.Finalizer.
- *
- * Object.finalize is a protected method, so it cannot be directly
- * invoked. Finalizer uses an indirection via native code to
- * circumvent this.
- */
-SimulateNativeStaticToVirtual(
- "",
- "").
-
-/**********************************************************************************
- *
- * java.security.AccessController
- *
- **********************************************************************************/
-
-/**
- * The run methods of privileged actions are invoked through the
- * AccessController.doPrivileged method. This introduces an
- * indirection via native code that needs to be simulated in a pointer
- * analysis.
- *
- * Call from an invocation of doPrivileged to an implementation of the
- * PrivilegedAction.run method that will be indirectly invoked.
- *
- * The first parameter of a doPrivileged invocation (a
- * PrivilegedAction) is assigned to the 'this' variable of 'run()'
- * method invocation.
- *
- * The return variable of the 'run()' method of a privileged action is
- * assigned to the return result of the doPrivileged method
- * invocation.
- *
- * TODO for PrivilegedExceptionAction, catch exceptions and wrap them in a PriviligedActionException.
- */
-SimulateNativeStaticToVirtual(
- "",
- "").
-
-SimulateNativeStaticToVirtual(
- "",
- "").
-
-SimulateNativeStaticToVirtual(
- "",
- "").
-
-SimulateNativeStaticToVirtual(
- "",
- "").
+/**********************************************************************************
+ *
+ * Simulation of native code by code generation.
+ *
+ * Note that some other natives are simulated by logic.
+ *
+ * @author Martin Bravenboer
+ *
+ **********************************************************************************/
+
+/**
+ *
+ * The ugly: macro abstractions
+ *
+ * This should really be generated from Jimple, but that's currently
+ * somewhat complicated.
+ */
+
+#define PlusAssignLocal(strFrom, strTo, strMethod) \
+ +AssignLocal(?from, ?to, ?method) <- \
+ VarRef:Value(?from:strFrom), \
+ VarRef:Value(?to:strTo), \
+ MethodSignatureRef:Value(?method:strMethod)
+
+#define PlusStoreStaticField(method, local, field) \
+ +StoreStaticField(?l, ?sig, ?m) <- \
+ MethodSignatureRef:Value(?m:method), \
+ VarRef:Value(?l:local), \
+ FieldSignatureRef:Value(?sig:field)
+
+#define SimulateNativeAllocation(strMethod, strHeap, strConstructor) \
+ +AssignHeapAllocation(?heap, ?return, ?method) \
+ <- \
+ MethodSignatureRef:Value(?method:strMethod), \
+ ReturnVar@previous(?return, ?method), \
+ HeapAllocationValue(?heap, strHeap). \
+ \
+ +SpecialMethodInvocation:Base[?invocation] = ?return, \
+ +SpecialMethodInvocation:In(?invocation, ?method), \
+ +SpecialMethodInvocation:Signature[?invocation] = ?constructor, \
+ PlusMethodInvocationRef(?invocation, ?strInvocation), \
+ +Instruction:Index[?invocation] = ?index \
+ <- \
+ MethodSignatureRef:Value(?method:strMethod), \
+ ReturnVar@previous(?return, ?method), \
+ ?strInvocation = strMethod + "/native " + strConstructor, \
+ MethodSignatureRef:Value(?constructor:strConstructor), \
+ ?index = 1
+
+#define SimulateNativeArrayAllocation(strMethod, strArray, strElement, strElementType) \
+ +AssignHeapAllocation(?heap, ?return, ?method) \
+ <- \
+ MethodSignatureRef:Value(?method:strMethod), \
+ ReturnVar@previous(?return, ?method), \
+ HeapAllocationValue(?heap, strArray). \
+ \
+ +VarRef:Value(?var), \
+ +VarRef:Value(?var:?strVar), \
+ +Var:Type[?var] = ?type, \
+ +Var:DeclaringMethod(?var, ?method), \
+ +AssignHeapAllocation(?heap, ?var, ?method), \
+ +StoreArrayIndex(?var, ?base, ?method) \
+ <- \
+ MethodSignatureRef:Value(?method:strMethod), \
+ ReturnVar@previous(?base, ?method), \
+ ?strVar = strMethod + "/@native-array-element", \
+ Type:Value(?type:strElementType), \
+ HeapAllocationValue(?heap, strElement)
+
+#define SimulateNativeStringArrayAllocation(strMethod, strArray, strElement, strElementType) \
+ +AssignHeapAllocation(?heap, ?return, ?method) \
+ <- \
+ MethodSignatureRef:Value(?method:strMethod), \
+ ReturnVar@previous(?return, ?method), \
+ HeapAllocationValue(?heap, strArray). \
+ \
+ +VarRef(?var), \
+ +VarRef:Value(?var:?strVar), \
+ +Var:Type[?var] = ?type, \
+ +Var:DeclaringMethod(?var, ?method), \
+ +AssignHeapAllocation(?heap, ?var, ?method), \
+ +StoreArrayIndex(?var, ?base, ?method) \
+ <- \
+ MethodSignatureRef:Value(?method:strMethod), \
+ ReturnVar@previous(?base, ?method), \
+ ?strVar = strMethod + "/@native-array-element", \
+ Type:Value(?type:strElementType), \
+ HeapAllocationValue(?heap, strElement)
+
+#ifndef PADDLE_COMPAT
+
+#define SimulateNativeStaticToVirtual(strMethod, strVirtual) \
+ PlusMethodInvocationRef(?invocation, ?strInvocation), \
+ +VirtualMethodInvocation(?invocation, ?signature, ?inmethod), \
+ +VirtualMethodInvocation:Base[?invocation] = ?base, \
+ +VirtualMethodInvocation:In(?invocation, ?inmethod), \
+ +VirtualMethodInvocation:Signature[?invocation] = ?signature, \
+ +Instruction:Index[?invocation] = ?index \
+ <- \
+ MethodSignatureRef:Value(?inmethod:strMethod), \
+ ParamIndexRef:Value(?zero:0), \
+ FormalParam@previous[?zero, ?inmethod] = ?base, \
+ ?strInvocation = strMethod + "/native " + strVirtual, \
+ MethodSignatureRef:Value(?signature:strVirtual), \
+ ?index = 1.\
+ \
+ PlusMethodInvocationRef(?invocation, ?strInvocation), \
+ +AssignReturnValue[?invocation] = ?return \
+ <- \
+ MethodSignatureRef:Value(?inmethod:strMethod), \
+ ReturnVar@previous(?return, ?inmethod), \
+ ?strInvocation = strMethod + "/native " + strVirtual
+
+#else
+
+#define SimulateNativeStaticToVirtual(strMethod, strVirtual) \
+ +VirtualMethodInvocation(?invocation, ?virtual, ?inmethod), \
+ +VirtualMethodInvocation:Base[?invocation] = ?base, \
+ +VirtualMethodInvocation:In(?invocation, ?inmethod), \
+ +VirtualMethodInvocation:Signature[?invocation] = ?virtual \
+ <- \
+ MethodSignatureRef:Value(?native:strMethod), \
+ StaticMethodInvocation:Signature[?invocation] = ?native, \
+ StaticMethodInvocation:In(?invocation, ?inmethod), \
+ ParamIndexRef:Value(?zero:0), \
+ ActualParam@previous[?zero, ?invocation] = ?base, \
+ MethodSignatureRef:Value(?virtual:strVirtual)
+#endif
+
+
+/**********************************************************************************
+ *
+ * java.lang.Object
+ *
+ **********************************************************************************/
+
+/**
+ *
+ *
+ * TODO could throw CloneNotSupportedException
+ *
+ * TODO should check if the object is Cloneable.
+ *
+ * TODO should return a clone of the heap allocation (not
+ * identity). The behaviour implemented here is based on Soot.
+ */
+PlusAssignLocal(
+ "java.lang.Object.clone/@this",
+ "java.lang.Object.clone/@native-return",
+ "").
+
+/**********************************************************************************
+ *
+ * java.lang.Class
+ *
+ **********************************************************************************/
+
+#ifndef PADDLE_COMPAT
++java:lang:Class:newInstance(?invocation, ?to, ?from) <-
+ MethodSignatureRef:Value(?newInstance:""),
+ VirtualMethodInvocation:Signature[?invocation] = ?newInstance,
+ AssignReturnValue[?invocation] = ?to,
+ VirtualMethodInvocation:Base[?invocation] = ?from.
+
++java:lang:reflect:Constructor:newInstance(?invocation, ?to, ?base) <-
+ MethodSignatureRef:Value(?newInstance:""),
+ VirtualMethodInvocation:Signature[?invocation] = ?newInstance,
+ VirtualMethodInvocation:Base[?invocation] = ?base,
+ AssignReturnValue[?invocation] = ?to.
+
+// java.lang.Class.getName
++java:lang:Class:getName(?to, ?from) <-
+ MethodSignatureRef:Value(?getName:""),
+ VirtualMethodInvocation:Signature[?invocation] = ?getName,
+ AssignReturnValue[?invocation] = ?to,
+ VirtualMethodInvocation:Base[?invocation] = ?from.
+
+// For rules about place holder heap in reflection-delta.logic
++java:lang:Class:forName(?invocation, ?inmethod) <-
+ MethodSignatureRef:Value(?forName:""),
+ StaticMethodInvocation(?invocation, ?forName, ?inmethod).
+
++java:lang:Class:forName(?invocation, ?inmethod) <-
+ MethodSignatureRef:Value(?forName:""),
+ StaticMethodInvocation(?invocation, ?forName, ?inmethod).
+
+// Handle loadClass
++loadClass(?invocation, ?inmethod) <-
+ VirtualMethodInvocation(?invocation, ?signature, ?inmethod),
+ MethodSignature:SimpleName[?signature] = ?simplename,
+ MethodSignature:Descriptor[?signature] = ?descriptor,
+ SimpleNameRef:Value(?simplename:"loadClass"),
+ MethodDescriptorRef:Value(?descriptor:"java.lang.Class(java.lang.String)").
+
++java:lang:Class:getMethod(?invocation, ?base) <-
+ MethodSignatureRef:Value(?signature:""),
+ VirtualMethodInvocation:Signature[?invocation] = ?signature,
+ VirtualMethodInvocation:Base[?invocation] = ?base.
+
++java:lang:Class:getDeclaredMethod(?invocation, ?base) <-
+ MethodSignatureRef:Value(?signature:""),
+ VirtualMethodInvocation:Signature[?invocation] = ?signature,
+ VirtualMethodInvocation:Base[?invocation] = ?base.
+
++java:lang:Class:getField(?invocation, ?base) <-
+ MethodSignatureRef:Value(?signature:""),
+ VirtualMethodInvocation:Signature[?invocation] = ?signature,
+ VirtualMethodInvocation:Base[?invocation] = ?base.
+
++java:lang:Class:getDeclaredField(?invocation, ?base) <-
+ MethodSignatureRef:Value(?signature:""),
+ VirtualMethodInvocation:Signature[?invocation] = ?signature,
+ VirtualMethodInvocation:Base[?invocation] = ?base.
+
+/**
+ * find invocations
+ */
++java:lang:Class:getConstructor(?invocation, ?to, ?from) <-
+ MethodSignatureRef:Value(?signature:""),
+ VirtualMethodInvocation:Signature[?invocation] = ?signature,
+ AssignReturnValue[?invocation] = ?to,
+ VirtualMethodInvocation:Base[?invocation] = ?from.
+
++java:lang:Class:getDeclaredConstructor(?invocation, ?to, ?from) <-
+ MethodSignatureRef:Value(?signature:""),
+ VirtualMethodInvocation:Signature[?invocation] = ?signature,
+ AssignReturnValue[?invocation] = ?to,
+ VirtualMethodInvocation:Base[?invocation] = ?from.
+
+/**
+ * find uses of getClass
+ */
++java:lang:Object:getClass(?invocation, ?to, ?from) <-
+ MethodSignatureRef:Value(?getClass:""),
+ VirtualMethodInvocation:Signature[?invocation] = ?getClass,
+ AssignReturnValue[?invocation] = ?to,
+ VirtualMethodInvocation:Base[?invocation] = ?from.
+
+// Add delta for reflection opeartions
+// getXXXs and getDeclaredXXXs (XXX includes Method, Field and Constructor
++java:lang:Class:getMethods(?invocation, ?from) <-
+ MethodSignatureRef:Value(?signature:""),
+ VirtualMethodInvocation:Signature[?invocation] = ?signature,
+ VirtualMethodInvocation:Base[?invocation] = ?from.
+
++java:lang:Class:getDeclaredMethods(?invocation, ?from) <-
+ MethodSignatureRef:Value(?signature:""),
+ VirtualMethodInvocation:Signature[?invocation] = ?signature,
+ VirtualMethodInvocation:Base[?invocation] = ?from.
+
++java:lang:Class:getFields(?invocation, ?from) <-
+ MethodSignatureRef:Value(?signature:""),
+ VirtualMethodInvocation:Signature[?invocation] = ?signature,
+ VirtualMethodInvocation:Base[?invocation] = ?from.
+
++java:lang:Class:getDeclaredFields(?invocation, ?from) <-
+ MethodSignatureRef:Value(?signature:""),
+ VirtualMethodInvocation:Signature[?invocation] = ?signature,
+ VirtualMethodInvocation:Base[?invocation] = ?from.
+
++java:lang:Class:getConstructors(?invocation, ?from) <-
+ MethodSignatureRef:Value(?signature:""),
+ VirtualMethodInvocation:Signature[?invocation] = ?signature,
+ VirtualMethodInvocation:Base[?invocation] = ?from.
+
++java:lang:Class:getDeclaredConstructors(?invocation, ?from) <-
+ MethodSignatureRef:Value(?signature:""),
+ VirtualMethodInvocation:Signature[?invocation] = ?signature,
+ VirtualMethodInvocation:Base[?invocation] = ?from.
+
++java:lang:reflect:Array:newInstance(?invo, ?to) <-
+ MethodSignatureRef:Value(?newInstance:""),
+ StaticMethodInvocation(?invo, ?newInstance, _),
+ AssignReturnValue[?invo] = ?to.
+
+#endif
+
+/**********************************************************************************
+ *
+ * java.lang.System
+ *
+ ***************************************************/
+
+#ifndef PADDLE_COMPAT
+/**
+ *
+ */
+PlusStoreStaticField(
+ "",
+ "java.lang.System.setIn0/@param0",
+ "").
+
+/**
+ *
+ */
+PlusStoreStaticField(
+ "",
+ "java.lang.System.setOut0/@param0",
+ "").
+
+/**
+ *
+ */
+PlusStoreStaticField(
+ "",
+ "java.lang.System.setErr0/@param0",
+ "").
+#endif
+
+/**
+ *
+ */
+/*
+PlusVarRef(?tmp, ?arraycopy, ?tmpStr, ?tmpType),
++LoadArrayIndex(?src, ?tmp, ?arraycopy),
++StoreArrayIndex(?tmp, ?dest, ?arraycopy)
+ <-
+ MethodSignatureRef:Value(?arraycopy:""),
+ ParamIndexRef:Value(?zero:0),
+ ParamIndexRef:Value(?two:2),
+ FormalParam[?zero, ?arraycopy] = ?src,
+ FormalParam[?two, ?arraycopy] = ?dest,
+ Type:Value(?tmpType:"java.lang.Object"),
+ ?tmpStr = "System.arraycopy/@native-tmp".
+*/
+#ifndef PADDLE_COMPAT
+PlusVarRef(?tmp, ?inmethod, ?tmpStr, ?tmpType),
++LoadArrayIndex(?src, ?tmp, ?inmethod),
++StoreArrayIndex(?tmp, ?dest, ?inmethod)
+ <-
+ MethodSignatureRef:Value(?arraycopy:""),
+ StaticMethodInvocation(?invocation, ?arraycopy, ?inmethod),
+ ParamIndexRef:Value(?zero:0),
+ ParamIndexRef:Value(?two:2),
+ ActualParam@previous[?zero, ?invocation] = ?src,
+ ActualParam@previous[?two, ?invocation] = ?dest,
+ MethodInvocationValue(?invocation, ?strInvocation),
+ ?tmpStr = ?strInvocation + "/@tmp-arraycopy",
+ Type:Value(?tmpType:"java.lang.Object").
+#endif
+
+/**********************************************************************************
+ *
+ * java.io.FileSystem
+ *
+ **********************************************************************************/
+
+#ifndef PADDLE_COMPAT
+#ifdef OS_UNIX
+PlusHeapAllocationRef(?alloc, "java.io.FileSystem.getFileSystem/new java.io.UnixFileSystem", "java.io.UnixFileSystem").
+PlusHeapAllocationRef(?alloc, "java.io.UnixFileSystem.list/new java.lang.String[]", "java.lang.String[]").
+PlusHeapAllocationRef(?alloc, "java.io.UnixFileSystem.list/new java.lang.String", "java.lang.String").
+
+SimulateNativeAllocation(
+ "",
+ "java.io.FileSystem.getFileSystem/new java.io.UnixFileSystem",
+ "()>").
+
+SimulateNativeStringArrayAllocation(
+ "",
+ "java.io.UnixFileSystem.list/new java.lang.String[]",
+ "java.io.UnixFileSystem.list/new java.lang.String",
+ "java.lang.String").
+
+#endif
+
+#ifdef OS_WIN32
+PlusHeapAllocationRef(?alloc, "java.io.FileSystem.getFileSystem/new java.io.Win32FileSystem", "java.io.Win32FileSystem").
+PlusHeapAllocationRef(?alloc, "java.io.Win32FileSystem.list/new java.lang.String[]", "java.lang.String[]").
+PlusHeapAllocationRef(?alloc, "java.io.Win32FileSystem.list/new java.lang.String", "java.lang.String").
+
+SimulateNativeAllocation(
+ "",
+ "java.io.FileSystem.getFileSystem/new java.io.Win32FileSystem",
+ "()>").
+
+SimulateNativeStringArrayAllocation(
+ "",
+ "java.io.Win32FileSystem.list/new java.lang.String[]",
+ "java.io.Win32FileSystem.list/new java.lang.String",
+ "java.lang.String").
+#endif
+
+#ifdef OS_WINNT
+PlusHeapAllocationRef(?alloc, "java.io.FileSystem.getFileSystem/new java.io.WinNTFileSystem", "java.io.WinNTFileSystem").
+PlusHeapAllocationRef(?alloc, "java.io.Win32FileSystem.list/new java.lang.String[]", "java.lang.String[]").
+PlusHeapAllocationRef(?alloc, "java.io.Win32FileSystem.list/new java.lang.String", "java.lang.String").
+
+SimulateNativeAllocation(
+ "",
+ "java.io.FileSystem.getFileSystem/new java.io.WinNTFileSystem",
+ "()>").
+
+SimulateNativeStringArrayAllocation(
+ "",
+ "java.io.WinNTFileSystem.list/new java.lang.String[]",
+ "java.io.WinNTFileSystem.list/new java.lang.String",
+ "java.lang.String").
+#endif
+#endif
+
+/**********************************************************************************
+ *
+ * java.lang.ref.Finalizer
+ *
+ **********************************************************************************/
+
+/**
+ * Indirect invocations of finalize methods from java.lang.ref.Finalizer.
+ *
+ * Object.finalize is a protected method, so it cannot be directly
+ * invoked. Finalizer uses an indirection via native code to
+ * circumvent this.
+ */
+SimulateNativeStaticToVirtual(
+ "",
+ "").
+
+/**********************************************************************************
+ *
+ * java.security.AccessController
+ *
+ **********************************************************************************/
+
+/**
+ * The run methods of privileged actions are invoked through the
+ * AccessController.doPrivileged method. This introduces an
+ * indirection via native code that needs to be simulated in a pointer
+ * analysis.
+ *
+ * Call from an invocation of doPrivileged to an implementation of the
+ * PrivilegedAction.run method that will be indirectly invoked.
+ *
+ * The first parameter of a doPrivileged invocation (a
+ * PrivilegedAction) is assigned to the 'this' variable of 'run()'
+ * method invocation.
+ *
+ * The return variable of the 'run()' method of a privileged action is
+ * assigned to the return result of the doPrivileged method
+ * invocation.
+ *
+ * TODO for PrivilegedExceptionAction, catch exceptions and wrap them in a PriviligedActionException.
+ */
+SimulateNativeStaticToVirtual(
+ "",
+ "").
+
+SimulateNativeStaticToVirtual(
+ "",
+ "").
+
+SimulateNativeStaticToVirtual(
+ "",
+ "").
+
+SimulateNativeStaticToVirtual(
+ "",
+ "").
diff -urN doop-r160113-bin/logic/library/reflection-delta.logic solar/logic/library/reflection-delta.logic
--- doop-r160113-bin/logic/library/reflection-delta.logic 2013-01-16 07:31:46.000000000 +1100
+++ solar/logic/library/reflection-delta.logic 2015-08-28 16:02:07.000000000 +1000
@@ -1,76 +1,354 @@
-/**
- * TODO Reified classes are generated by soot-fact-generation. Perhaps
- * a bit confusing. generating them here anyway would not hurt.
- *
- * TODO Heap allocations should not be instructions (the heap
- * allocation is contained in an instruction)
- */
-
-#include "fact-macros.logic"
-
-+ReflectiveHeapAllocation[?invocation, ?type] = ?heap,
-+InstructionRef:Value(?heap:?strHeap),
-+HeapAllocationRef(?heap),
-+HeapAllocation:Type[?heap] = ?type
- <-
- java:lang:Class:newInstance@previous(?invocation, _, _),
- ClassType(?type),
- Type:Value(?type:?strType),
- ?strHeap = "".
-// InstructionRef:Value@prev(?invocation:?strInvocation),
-// ?strHeap = "".
-
-+ReflectiveHeapAllocation[?invocation, ?type] = ?heap,
-+InstructionRef:Value(?heap:?strHeap),
-+HeapAllocationRef(?heap),
-+HeapAllocation:Type[?heap] = ?type
- <-
- java:lang:reflect:Constructor:newInstance@previous(?invocation, _, _),
- ClassType(?type),
- Type:Value(?type:?strType),
- ?strHeap = "".
-// InstructionRef:Value@prev(?invocation:?strInvocation),
-// ?strHeap = "".
-
-/**
- * Heap allocations for reified constructors (java.lang.reflect.Constructor)
- */
-+ReifiedConstructor[?signature] = ?heap,
-+InstructionRef:Value(?heap:?strHeap),
-+HeapAllocationRef(?heap),
-+HeapAllocation:Type[?heap] = ?type
- <-
- SimpleNameRef:Value(?init:""),
- MethodSignature:SimpleName[?signature] = ?init,
- MethodSignatureRef:Value(?signature:?strSignature),
- ?strHeap = "",
- Type:Value(?type:"java.lang.reflect.Constructor").
-
-/**
- * Heap allocations for reified methods (java.lang.reflect.Method).
- */
-+ReifiedMethod[?signature] = ?heap,
-+InstructionRef:Value(?heap:?strHeap),
-+HeapAllocationRef(?heap),
-+HeapAllocation:Type[?heap] = ?type
- <-
- MethodSignature:SimpleName[?signature] = ?simplename,
- SimpleNameRef:Value(?init:""),
- ?simplename != ?init,
- SimpleNameRef:Value(?clinit:""),
- ?simplename != ?clinit,
- MethodSignatureRef:Value(?signature:?strSignature),
- ?strHeap = "",
- Type:Value(?type:"java.lang.reflect.Method").
-
-/**
- * Heap allocations for reified fields (java.lang.reflect.Field).
- */
-+ReifiedField[?x] = ?heap,
-+InstructionRef:Value(?heap:?strHeap),
-+HeapAllocationRef(?heap),
-+HeapAllocation:Type[?heap] = ?type
- <-
- FieldSignatureRef:Value(?x:?signature),
- ?strHeap = "",
- Type:Value(?type:"java.lang.reflect.Field").
+#include "fact-macros.logic"
+
++UnknownObject[?invocation] = ?heap,
++InstructionRef:Value(?heap:?strHeap),
++HeapAllocationRef(?heap),
++HeapAllocation:Type[?heap] = ?type
+ <-
+ java:lang:Class:newInstance@previous(?invocation, _, _),
+ Type:Value(?type:"_Unknown_"),
+ InstructionRef:Value@prev(?invocation:?strInvocation),
+ ?strHeap = "".
+
++UnknownObject[?invocation] = ?heap,
++InstructionRef:Value(?heap:?strHeap),
++HeapAllocationRef(?heap),
++HeapAllocation:Type[?heap] = ?type
+ <-
+ java:lang:reflect:Constructor:newInstance@previous(?invocation, _, _),
+ Type:Value(?type:"_Unknown_"),
+ InstructionRef:Value@prev(?invocation:?strInvocation),
+ ?strHeap = "".
+
++ReflectiveHeapAllocation[?invocation, ?type] = ?heap,
++InstructionRef:Value(?heap:?strHeap),
++HeapAllocationRef(?heap),
++HeapAllocation:Type[?heap] = ?type
+ <-
+ java:lang:Class:newInstance@previous(?invocation, _, _),
+ ClassType(?type),
+ Type:Value(?type:?strType),
+ //?strHeap = "".
+ InstructionRef:Value@prev(?invocation:?strInvocation),
+ ?strHeap = "".
+
++ReflectiveHeapAllocation[?invocation, ?type] = ?heap,
++InstructionRef:Value(?heap:?strHeap),
++HeapAllocationRef(?heap),
++HeapAllocation:Type[?heap] = ?type
+ <-
+ java:lang:reflect:Constructor:newInstance@previous(?invocation, _, _),
+ ClassType(?type),
+ Type:Value(?type:?strType),
+//?strHeap = "".
+ InstructionRef:Value@prev(?invocation:?strInvocation),
+ ?strHeap = "".
+
+/**
+ * Heap allocations for reified constructors (java.lang.reflect.Constructor)
+ */
++ReifiedConstructor[?signature] = ?heap,
++InstructionRef:Value(?heap:?strHeap),
++HeapAllocationRef(?heap),
++HeapAllocation:Type[?heap] = ?type
+ <-
+ SimpleNameRef:Value(?init:""),
+ MethodSignature:SimpleName[?signature] = ?init,
+ MethodSignatureRef:Value(?signature:?strSignature),
+ ?strHeap = "",
+ Type:Value(?type:"java.lang.reflect.Constructor").
+
+/**
+ * Heap allocations for reified methods (java.lang.reflect.Method).
+ */
++ReifiedMethod[?signature] = ?heap,
++InstructionRef:Value(?heap:?strHeap),
++HeapAllocationRef(?heap),
++HeapAllocation:Type[?heap] = ?type
+ <-
+ MethodSignature:SimpleName[?signature] = ?simplename,
+ SimpleNameRef:Value(?init:""),
+ ?simplename != ?init,
+ SimpleNameRef:Value(?clinit:""),
+ ?simplename != ?clinit,
+ MethodSignatureRef:Value(?signature:?strSignature),
+ ?strHeap = "",
+ Type:Value(?type:"java.lang.reflect.Method").
+
+/**
+ * Heap allocations for reified fields (java.lang.reflect.Field).
+ */
++ReifiedField[?signature] = ?heap,
++InstructionRef:Value(?heap:?strHeap),
++HeapAllocationRef(?heap),
++HeapAllocation:Type[?heap] = ?type
+ <-
+ FieldSignatureRef:Value(?signature:?strSignature),
+ ?strHeap = "",
+ Type:Value(?type:"java.lang.reflect.Field").
+
+// For lazy heap modeling
++UnknownClass[?heap] = ?invo,
++InstructionRef:Value(?heap:?strHeap),
++HeapAllocationRef(?heap),
++HeapAllocation:Type[?heap] = ?type
+ <-
+ (
+ java:lang:Class:forName@previous(?invo, _);
+ loadClass@previous(?invo, _);
+ java:lang:Object:getClass@previous(?invo, _, _)
+ ),
+ Type:Value(?type:"java.lang.Class"),
+ InstructionRef:Value@previous(?invo:?strInvo),
+ ?strHeap = "".
+
+//We use the same unknown Constructor object to identify
+//the "Unknown" at one invocation for both getCons and getCon
++UnknownConstructor[?heap] = ?invo,
++InstructionRef:Value(?heap:?strHeap),
++HeapAllocationRef(?heap),
++HeapAllocation:Type[?heap] = ?type
+ <-
+ (java:lang:Class:getConstructors@previous(?invo, _);
+ java:lang:Class:getConstructor@previous(?invo, _, _)),
+ Type:Value(?type:"java.lang.reflect.Constructor"),
+ InstructionRef:Value@previous(?invo:?strInvo),
+ ?strHeap = "".
+
++UnknownDeclaredConstructor[?heap] = ?invo,
++InstructionRef:Value(?heap:?strHeap),
++HeapAllocationRef(?heap),
++HeapAllocation:Type[?heap] = ?type
+ <-
+ (java:lang:Class:getDeclaredConstructors@previous(?invo, _);
+ java:lang:Class:getDeclaredConstructor@previous(?invo, _, _)),
+ Type:Value(?type:"java.lang.reflect.Constructor"),
+ InstructionRef:Value@previous(?invo:?strInvo),
+ ?strHeap = "".
+
+//m^u_u
++MethodUUHeap[?heap] = ?invo,
++InstructionRef:Value(?heap:?strHeap),
++HeapAllocationRef(?heap),
++HeapAllocation:Type[?heap] = ?type
+ <-
+ (java:lang:Class:getMethod@previous(?invo, _);
+ java:lang:Class:getMethods@previous(?invo, _)),
+ Type:Value(?type:"java.lang.reflect.Method"),
+ InstructionRef:Value@previous(?invo:?strInvo),
+ ?strHeap = "".
+
++DeclaredMethodUUHeap[?heap] = ?invo,
++InstructionRef:Value(?heap:?strHeap),
++HeapAllocationRef(?heap),
++HeapAllocation:Type[?heap] = ?type
+ <-
+ (java:lang:Class:getDeclaredMethod@previous(?invo, _);
+ java:lang:Class:getDeclaredMethods@previous(?invo, _)),
+ Type:Value(?type:"java.lang.reflect.Method"),
+ InstructionRef:Value@previous(?invo:?strInvo),
+ ?strHeap = "".
+
+//f^u_u
++FieldUUHeap[?heap] = ?invo,
++InstructionRef:Value(?heap:?strHeap),
++HeapAllocationRef(?heap),
++HeapAllocation:Type[?heap] = ?type
+ <-
+ (java:lang:Class:getField@previous(?invo, _);
+ java:lang:Class:getFields@previous(?invo, _)),
+ Type:Value(?type:"java.lang.reflect.Field"),
+ InstructionRef:Value@previous(?invo:?strInvo),
+ ?strHeap = "".
+
++DeclaredFieldUUHeap[?heap] = ?invo,
++InstructionRef:Value(?heap:?strHeap),
++HeapAllocationRef(?heap),
++HeapAllocation:Type[?heap] = ?type
+ <-
+ (java:lang:Class:getDeclaredField@previous(?invo, _);
+ java:lang:Class:getDeclaredFields@previous(?invo, _)),
+ Type:Value(?type:"java.lang.reflect.Field"),
+ InstructionRef:Value@previous(?invo:?strInvo),
+ ?strHeap = "".
+
+// The following place holders are used for such cases that
+// class name is unknown but method/field name is string constant
++MethodUSHeap[?heap] = ?mtdName,
++InstructionRef:Value(?heap:?strHeap),
++HeapAllocationRef(?heap),
++HeapAllocation:Type[?heap] = ?type
+ <-
+ //java:lang:Class:getMethod@previous(?invo, _),
+ //InstructionRef:Value@previous(?invo:?strInvo),
+ MethodSignature:SimpleName[_] = ?mtdName,
+ SimpleNameRef:Value(?mtdName:?strName),
+ ?strHeap = "",
+ Type:Value(?type:"java.lang.reflect.Method").
+
++DeclaredMethodUSHeap[?heap] = ?mtdName,
++InstructionRef:Value(?heap:?strHeap),
++HeapAllocationRef(?heap),
++HeapAllocation:Type[?heap] = ?type
+ <-
+ //java:lang:Class:getDeclaredMethod@previous(?invo, _),
+ //InstructionRef:Value@previous(?invo:?strInvo),
+ MethodSignature:SimpleName[_] = ?mtdName,
+ SimpleNameRef:Value(?mtdName:?strName),
+ ?strHeap = "",
+ Type:Value(?type:"java.lang.reflect.Method").
+
++FieldUSHeap[?heap] = ?fldName,
++InstructionRef:Value(?heap:?strHeap),
++HeapAllocationRef(?heap),
++HeapAllocation:Type[?heap] = ?type
+ <-
+ //java:lang:Class:getMethod@previous(?invo, _),
+ //InstructionRef:Value@previous(?invo:?strInvo),
+ FieldSignature(_, _, ?fldName, _),
+ SimpleNameRef:Value(?fldName:?strName),
+ ?strHeap = "",
+ Type:Value(?type:"java.lang.reflect.Field").
+
++DeclaredFieldUSHeap[?heap] = ?fldName,
++InstructionRef:Value(?heap:?strHeap),
++HeapAllocationRef(?heap),
++HeapAllocation:Type[?heap] = ?type
+ <-
+ //java:lang:Class:getMethod@previous(?invo, _),
+ //InstructionRef:Value@previous(?invo:?strInvo),
+ FieldSignature(_, _, ?fldName, _),
+ SimpleNameRef:Value(?fldName:?strName),
+ ?strHeap = "",
+ Type:Value(?type:"java.lang.reflect.Field").
+
+// m^t_u
++MethodTUHeap[?heap] = ?clzType,
++InstructionRef:Value(?heap:?strHeap),
++HeapAllocationRef(?heap),
++HeapAllocation:Type[?heap] = ?type
+ <-
+ ClassType(?clzType),
+ Type:Value(?clzType:?strType),
+ ?strHeap = "",
+ Type:Value(?type:"java.lang.reflect.Method").
+
++DeclaredMethodTUHeap[?heap] = ?clzType,
++InstructionRef:Value(?heap:?strHeap),
++HeapAllocationRef(?heap),
++HeapAllocation:Type[?heap] = ?type
+ <-
+ ClassType(?clzType),
+ Type:Value(?clzType:?strType),
+ ?strHeap = "",
+ Type:Value(?type:"java.lang.reflect.Method").
+
+//f^t_u
++FieldTUHeap[?heap] = ?clzType,
++InstructionRef:Value(?heap:?strHeap),
++HeapAllocationRef(?heap),
++HeapAllocation:Type[?heap] = ?type
+ <-
+ ClassType(?clzType),
+ Type:Value(?clzType:?strType),
+ ?strHeap = "",
+ Type:Value(?type:"java.lang.reflect.Field").
+
++DeclaredFieldTUHeap[?heap] = ?clzType,
++InstructionRef:Value(?heap:?strHeap),
++HeapAllocationRef(?heap),
++HeapAllocation:Type[?heap] = ?type
+ <-
+ ClassType(?clzType),
+ Type:Value(?clzType:?strType),
+ ?strHeap = "",
+ Type:Value(?type:"java.lang.reflect.Field").
+
+
+// Heap allocations for getXXXs and getDeclaredXXXs
+
+//Reified Method array object
++GetMethodsHeap[?invo] = ?heap,
++InstructionRef:Value(?heap:?strHeap),
++HeapAllocationRef(?heap),
++HeapAllocation:Type[?heap] = ?type
+ <-
+ java:lang:Class:getMethods@previous(?invo,_),
+ InstructionRef:Value@previous(?invo:?strInvo),
+ ?strHeap = "",
+ Type:Value(?type:"java.lang.reflect.Method[]").
+
++GetDeclaredMethodsHeap[?invo] = ?heap,
++InstructionRef:Value(?heap:?strHeap),
++HeapAllocationRef(?heap),
++HeapAllocation:Type[?heap] = ?type
+ <-
+ java:lang:Class:getDeclaredMethods@previous(?invo,_),
+ InstructionRef:Value@previous(?invo:?strInvo),
+ ?strHeap = "",
+ Type:Value(?type:"java.lang.reflect.Method[]").
+
+//Reified Field array object
++GetFieldsHeap[?invo] = ?heap,
++InstructionRef:Value(?heap:?strHeap),
++HeapAllocationRef(?heap),
++HeapAllocation:Type[?heap] = ?type
+ <-
+ java:lang:Class:getFields@previous(?invo,_),
+ InstructionRef:Value@previous(?invo:?strInvo),
+ ?strHeap = "",
+ Type:Value(?type:"java.lang.reflect.Field[]").
+
++GetDeclaredFieldsHeap[?invo] = ?heap,
++InstructionRef:Value(?heap:?strHeap),
++HeapAllocationRef(?heap),
++HeapAllocation:Type[?heap] = ?type
+ <-
+ java:lang:Class:getDeclaredFields@previous(?invo,_),
+ InstructionRef:Value@previous(?invo:?strInvo),
+ ?strHeap = "",
+ Type:Value(?type:"java.lang.reflect.Field[]").
+
+// Reified Constructor array object
++GetConstructorsHeap[?invo] = ?heap,
++InstructionRef:Value(?heap:?strHeap),
++HeapAllocationRef(?heap),
++HeapAllocation:Type[?heap] = ?type
+ <-
+ java:lang:Class:getConstructors@previous(?invo,_),
+ InstructionRef:Value@previous(?invo:?strInvo),
+ ?strHeap = "",
+ Type:Value(?type:"java.lang.reflect.Constructor[]").
+
++GetDeclaredConstructorsHeap[?invo] = ?heap,
++InstructionRef:Value(?heap:?strHeap),
++HeapAllocationRef(?heap),
++HeapAllocation:Type[?heap] = ?type
+ <-
+ java:lang:Class:getDeclaredConstructors@previous(?invo,_),
+ InstructionRef:Value@previous(?invo:?strInvo),
+ ?strHeap = "",
+ Type:Value(?type:"java.lang.reflect.Constructor[]").
+
+
++ReflectiveArrayHeapAllocation[?invo, ?arrayType] = ?heap,
++InstructionRef:Value(?heap:?strHeap),
++HeapAllocationRef(?heap),
++HeapAllocation:Type[?heap] = ?arrayType
+ <-
+ java:lang:reflect:Array:newInstance@previous(?invo, _),
+ ArrayType(?arrayType),
+ Type:Value(?arrayType:?strType),
+ //?strHeap = "".
+ InstructionRef:Value@prev(?invo:?strInvo),
+ ?strHeap = "".
+
++UnknownObject[?invocation] = ?heap,
++InstructionRef:Value(?heap:?strHeap),
++HeapAllocationRef(?heap),
++HeapAllocation:Type[?heap] = ?type
+ <-
+ java:lang:reflect:Array:newInstance@previous(?invocation, _),
+ Type:Value(?type:"_Unknown_"),
+ InstructionRef:Value@prev(?invocation:?strInvocation),
+ ?strHeap = "".
diff -urN doop-r160113-bin/logic/library/reflection.logic solar/logic/library/reflection.logic
--- doop-r160113-bin/logic/library/reflection.logic 2013-01-16 07:31:46.000000000 +1100
+++ solar/logic/library/reflection.logic 2015-09-02 17:10:50.000000000 +1000
@@ -1,108 +1,26 @@
-/*************************************************************
- * Reflection analysis
- *
- * We use a distinct heap abstraction for every java.lang.Class,
- * i.e., for every class type that appears in the bytecode, for
- * example ''. The predicate ReifiedClass is
- * used to look up the heap abstraction for a given type.
- *
- * This allows us to track the type of a Class object and automate
- * newInstance invocations (and in the future java.lang.reflect.Method
- * and Constructor invocations as well).
- *
- * User configuration is required for Class.forName invocations. We
- * might implement some string analysis in the future, but most common
- * reflection cases use string manipulations for which a
- * straightforward string analysis would not help.
- *
- * Objects created by newInstance invocations are represented by a
- * generated heap allocation, a combination of the invocation-site of
- * newInstance and the type of the allocated object (see
- * reflection-delta.logic).
- *
- * TODO Note that this analysis currently does not support reflective
- * use of reflection. If you really want to, you can hide uses of
- * reflection in this way. The issue here is that the current
- * code does not consider reflective method invocations, only
- * virtual method invocations. For example:
- *
- * MethodSignatureRef:Value(?getClass:""),
- * VirtualMethodInvocation:Signature[?invocation] = ?getClass,
- *
- * Only checks for invocations of getClass in source code, not in
- * method invocations discovered during reflection analysis.
- *
- * @author Martin Bravenboer
- *************************************************************/
+#include "solar/annotation-guidance.logic"
+#include "solar/array.logic"
+#include "solar/inference.logic"
+#include "solar/lazy.logic"
+#include "solar/propagation.logic"
+#include "solar/reflect-stats.logic"
+
+
/*************************************************************
- * Object.getClass
*
- * stable public interface
- * public final native Class getClass()
+ * Handle getClass() for regular and unknown objects.
+ * For a getClass() call on an unknown object, Solar will return
+ * an unknown Class object.
*
- * Although Object.getClass is a reflection operation, it is easy to
- * analyse statically, because we know the type of every heap
- * allocation.
*************************************************************/
-
-/**
- * find uses of getClass
- */
-java:lang:Object:getClass(?to, ?from) <-
- MethodSignatureRef:Value(?getClass:""),
- VirtualMethodInvocation:Signature[?invocation] = ?getClass,
- AssignReturnValue[?invocation] = ?to,
- VirtualMethodInvocation:Base[?invocation] = ?from.
-
-/**
- * evaluate getClass
- */
RecordImmutableMacro(?ctx, ?class, ?immCtx),
VarPointsTo(?immCtx, ?class, ?ctx, ?to) <-
- java:lang:Object:getClass(?to, ?var),
+ java:lang:Object:getClass(_, ?to, ?var),
VarPointsTo(_, ?heap, ?ctx, ?var),
HeapAllocation:Type[?heap] = ?type,
ReifiedClass[?type] = ?class.
-/*************************************************************
- * Class.forName
- *
- * stable public interface
- * public static Class> forName(String className)
- * public static Class> forName(String name, boolean initialize, ClassLoader loader)
- *
- * native jre1.3
- * private static native Class forName0(String name, boolean initialize, ClassLoader loader)
- *
- * native openjdk
- * private static native Class forName0(String name, boolean initialize, ClassLoader loader)
- *
- *
- * Class.forName is the main fragile point of a static pointer
- * analysis. Arbitrary strings can be constructed by the program and
- * used as an argument to Class.forName, so we cannot predict which
- * classes they correspond to.
- *
- * Therefore, this is also the main user-configuration point (some
- * other points-to analysis implementations configure newInstance, but
- * we think Class.forName is the appropriate place)
- *
- * We do automatically support class name strings that occur as
- * constants in the program. For those, configuration is not
- * necessary.
- *************************************************************/
-
-/**
- * Find invocations of Class.forName
- */
-java:lang:Class:forName(?invocation, ?inmethod) <-
- MethodSignatureRef:Value(?forName:""),
- StaticMethodInvocation(?invocation, ?forName, ?inmethod).
-
-java:lang:Class:forName(?invocation, ?inmethod) <-
- MethodSignatureRef:Value(?forName:""),
- StaticMethodInvocation(?invocation, ?forName, ?inmethod).
/**
* Class.forName invocations with user-configured dynamic classes
@@ -121,6 +39,7 @@
ReflectiveAssignClassConstant(?ctx, ?invocation, ?type) <-
java:lang:Class:forName(?invocation, ?inmethod),
ReachableContext(?ctx, ?inmethod), // recursive
+ !Config:DynamicClass(_, ?invocation), // don't resolve annotated entry
java:lang:Class:forName:ActualParam[?invocation] = ?param,
VarPointsTo(_, ?constant, ?ctx, ?param), // recursive
ClassNameStringConstant:Type[?constant] = ?type.
@@ -134,160 +53,69 @@
ActualParam[?zero, ?invocation] = ?param,
java:lang:Class:forName(?invocation, _).
+
+
/*************************************************************
- * Class.getDeclaredMethods
- *
- * stable public interface
- * public Method[] getMethods()
- * public Method getMethod(String name, Class[] parameterTypes)
- * public Method[] getDeclaredMethods()
- * public Method getDeclaredMethod(String name, Class[] parameterTypes)
- *
- * jre1.3
- * private native Method[] getMethods0(int which);
- * private native Method getMethod0(String name, Class[] parameterTypes,
- *
- * openjdk
- * private native Method[] getDeclaredMethods0(boolean publicOnly);
- *
+ * ClassLoader.loadClass
*************************************************************/
+java:lang:ClassLoader:loadClass(?invo, ?inmethod) <-
+ loadClass(?invo, ?inmethod),
+ VirtualMethodInvocation:Signature[?invo] = ?signature,
+ MethodSignature:Type[?signature] = ?type,
+ Type:Value(?classLoader:"java.lang.ClassLoader"),
+ AssignCompatible(?classLoader, ?type).
-/**
- * find invocations
- */
-java:lang:Class:getDeclaredMethod(?to, ?from) <-
- MethodSignatureRef:Value(?signature:""),
- VirtualMethodInvocation:Signature[?invocation] = ?signature,
- AssignReturnValue[?invocation] = ?to,
- VirtualMethodInvocation:Base[?invocation] = ?from.
-
-/**
- * evaluate
- */
+ReflectiveAssignClassConstant(?ctx, ?invocation, ?type) <-
+ java:lang:ClassLoader:loadClass(?invocation, ?inmethod),
+ ReachableContext(?ctx, ?inmethod),
+ Config:DynamicClass(?type, ?invocation).
-RecordMacro(?ctx, ?heap, ?hctx),
-VarPointsTo(?hctx, ?heap, ?ctx, ?to) <-
- java:lang:Class:getDeclaredMethod(?to, ?from),
- VarPointsTo(_, ?class, ?ctx, ?from),
- ReifiedClass[?type] = ?class,
- MethodSignature:Type[?signature] = ?type,
- ReifiedMethod[?signature] = ?heap,
- ObjectShouldNotBeRefined(?heap).
-#ifdef RecordRefinedMacro
-RecordRefinedMacro(?ctx, ?heap, ?hctx),
-VarPointsTo(?hctx, ?heap, ?ctx, ?to) <-
- java:lang:Class:getDeclaredMethod(?to, ?from),
- VarPointsTo(_, ?class, ?ctx, ?from),
- ReifiedClass[?type] = ?class,
- MethodSignature:Type[?signature] = ?type,
- ReifiedMethod[?signature] = ?heap,
- ObjectShouldBeRefined(?heap).
-#endif
+ReflectiveAssignClassConstant(?ctx, ?invocation, ?type) <-
+ java:lang:ClassLoader:loadClass(?invocation, ?inmethod),
+ ReachableContext(?ctx, ?inmethod), // recursive
+ !Config:DynamicClass(_, ?invocation), // don't resolve annotated entry
+ java:lang:ClassLoader:loadClass:ActualParam[?invocation] = ?param,
+ VarPointsTo(_, ?constant, ?ctx, ?param), // recursive
+ ClassNameStringConstant:Type[?constant] = ?type.
-/*************************************************************
- * Class.getConstructors
- *
- * stable public interface
- * public Constructor getConstructor(Class[] parameterTypes)
- * public Constructor[] getConstructors()
- * public Constructor[] getDeclaredConstructors()
- * public Constructor getDeclaredConstructor(Class[] parameterTypes)
- *
- * native jre1.3
- * private native Constructor[] getConstructors0(int which);
- * private native Constructor getConstructor0(Class[] parameterTypes, int which)
- *
- * native openjdk
- * private native Constructor[] getDeclaredConstructors0(boolean publicOnly);
- *
- * Confusingly, the difference between getConstructor and getDeclaredConstructor is
- * that getConstructor only considers public constructors.
- *
- *************************************************************/
+java:lang:ClassLoader:loadClass:ActualParam[?invocation] = ?param ->
+ MethodInvocationRef(?invocation),
+ VarRef(?param).
-/**
- * find invocations
- */
-java:lang:Class:getConstructor(?to, ?from) <-
- MethodSignatureRef:Value(?signature:""),
- VirtualMethodInvocation:Signature[?invocation] = ?signature,
- AssignReturnValue[?invocation] = ?to,
- VirtualMethodInvocation:Base[?invocation] = ?from.
+java:lang:ClassLoader:loadClass:ActualParam[?invocation] = ?param <-
+ ParamIndexRef:Value(?zero:0),
+ ActualParam[?zero, ?invocation] = ?param,
+ java:lang:ClassLoader:loadClass(?invocation, _).
-java:lang:Class:getDeclaredConstructor(?to, ?from) <-
- MethodSignatureRef:Value(?signature:""),
- VirtualMethodInvocation:Signature[?invocation] = ?signature,
- AssignReturnValue[?invocation] = ?to,
- VirtualMethodInvocation:Base[?invocation] = ?from.
/**
- * evaluate
+ * cast
*/
-RecordMacro(?ctx, ?heap, ?hctx),
-VarPointsTo(?hctx, ?heap, ?ctx, ?to) <-
- java:lang:Class:getConstructor(?to, ?from),
- VarPointsTo(_, ?class, ?ctx, ?from),
- ReifiedClass[?type] = ?class,
- MethodSignature:Type[?signature] = ?type,
- ModifierRef:Value(?public:"public"),
- MethodModifier(?public, ?signature),
- ReifiedConstructor[?signature] = ?heap,
- ObjectShouldNotBeRefined(?heap).
+java:lang:Class:cast(?class, ?ctx, ?from, ?to) <-
+ MethodSignatureRef:Value(?cast:""),
+ VirtualMethodInvocation:Signature[?invocation] = ?cast,
+ VirtualMethodInvocation:Base[?invocation] = ?base,
+ VarPointsTo(_, ?class, ?ctx, ?base),
+ ActualParam[0, ?invocation] = ?from,
+ AssignReturnValue[?invocation] = ?to.
-RecordMacro(?ctx, ?heap, ?hctx),
VarPointsTo(?hctx, ?heap, ?ctx, ?to) <-
- java:lang:Class:getDeclaredConstructor(?to, ?from),
- VarPointsTo(_, ?class, ?ctx, ?from),
+ java:lang:Class:cast(?class, ?ctx, ?from, ?to),
ReifiedClass[?type] = ?class,
- MethodSignature:Type[?signature] = ?type,
- ReifiedConstructor[?signature] = ?heap,
- ObjectShouldNotBeRefined(?heap).
+ VarPointsTo(?hctx, ?heap, ?ctx, ?from),
+ AssignCompatible(?type, HeapAllocation:Type[?heap]),
+ ! UnknownObject[_] = ?heap.
-#ifdef RecordRefinedMacro
-RecordRefinedMacro(?ctx, ?heap, ?hctx),
VarPointsTo(?hctx, ?heap, ?ctx, ?to) <-
- java:lang:Class:getConstructor(?to, ?from),
- VarPointsTo(_, ?class, ?ctx, ?from),
- ReifiedClass[?type] = ?class,
- MethodSignature:Type[?signature] = ?type,
- ModifierRef:Value(?public:"public"),
- MethodModifier(?public, ?signature),
- ReifiedConstructor[?signature] = ?heap,
- ObjectShouldBeRefined(?heap).
-
-RecordRefinedMacro(?ctx, ?heap, ?hctx),
-VarPointsTo(?hctx, ?heap, ?ctx, ?to) <-
- java:lang:Class:getDeclaredConstructor(?to, ?from),
- VarPointsTo(_, ?class, ?ctx, ?from),
- ReifiedClass[?type] = ?class,
- MethodSignature:Type[?signature] = ?type,
- ReifiedConstructor[?signature] = ?heap,
- ObjectShouldBeRefined(?heap).
-#endif
-
+ java:lang:Class:cast(?class, ?ctx, ?from, ?to),
+ VarPointsTo(?hctx, ?heap, ?ctx, ?from),
+ UnknownClass[?class] = _.
+
/*************************************************************
* Method.invoke
- *
- * stable public interface
- * public Object invoke(Object obj, Object[] args)
- *
- * jre1.3
- * public native Object invoke(Object obj, Object[] args)
- *
- * openjdk
- * something way too complicated ...
- *
- * Notes:
- *
- * - currently we're simulating the public interface
- *
- * - The specification of reflective method invocations is
- * generic. The logic of this section makes Method.invoke
- * available as a reflective method invocation site.
- *
- ************************************************************/
-
+ *************************************************************/
+
java:lang:reflect:Method:invoke(?invocation, ?base) <-
MethodSignatureRef:Value(?invoke:""),
VirtualMethodInvocation:Signature[?invocation] = ?invoke,
@@ -314,38 +142,15 @@
/*************************************************************
* Constructor.newInstance
- *
- * stable public interface
- * public Object newInstance(Object[] initargs)
- *
- * native jre1.3
- * public native Object newInstance(Object[] initargs)
- *
- * openjdk
- * something way too complicated ...
- *
- *
- * Notes:
- *
- * - currently we're simulating the public interface
- *
- * - a constructor does not have a return value, so we do set the
- * ReflectiveAssignReturnValue.
- *
- * - although the return value of newInstance does not necessarily
- * get assigned to a local variable, we assume that is the case
- * here in prepration of the nice specification language that is
- * upcoming (where this will be replaced by a separate heap
- * allocation and constructor invocation).
- *
*************************************************************/
-
ReflectiveAssignHeapAllocation(?invocation, ?type, ?ctx, ?to),
ReflectiveSpecialMethodInvocation(?ctx, ?invocation, ?signature) <-
java:lang:reflect:Constructor:newInstance(?invocation, ?to, ?base),
VarPointsTo(_, ?constructor, ?ctx, ?base), // recursive
ReifiedConstructor[?signature] = ?constructor,
- MethodSignature:Type[?signature] = ?type.
+ MethodSignature:Type[?signature] = ?type,
+ ConstructorArgFilter(?invocation, ?signature),
+ ConstructorNewInstanceCastFilter(?invocation, ?type).
ReflectiveBaseVar[?invocation] = ?to <-
java:lang:reflect:Constructor:newInstance(?invocation, ?to, _).
@@ -355,41 +160,18 @@
ActualParam[?zero, ?invocation] = ?argsParam,
ParamIndexRef:Value(?zero:0).
+ConstructorNewInstanceCastFilter(?invo, ?type) <-
+ java:lang:reflect:Constructor:newInstance(?invo, _, _),
+ ! ConstructorNewInstanceCast(?invo, _),
+ ClassType(?type),
+ ! AbstractClass(?type).
+
+ConstructorNewInstanceCastFilter(?invo, ?type) <-
+ ConstructorNewInstanceCast(?invo, ?castType),
+ NewableSubtype(?castType, ?type).
+
/*************************************************************
* Class.newInstance
- *
- * stable public interface
- * public Object newInstance()
- *
- * native jre1.3
- * private native Object newInstance0()
- *
- * native openjdk
- * none, implemented in java using java.lang.reflect.Constructor.newInstance
- *
- * Notes:
- *
- * - Currently we're simulating the public interface
- *
- * - For the OpenJDK there is a duplication of simulating, since we
- * also simulate reflective constructor invocations. We'll soon
- * sort out what needs to be in #ifdefs exactly.
- *
- * - Class.newInstance is handled completely automatically. not
- * requiring any user-configuration. The reason why this is
- * possible is that we use a distinct heap abstraction for every
- * Class object of a distinct class.
- *
- *
- * TODO This should really be replaced by assignments to method
- * declaration return values, but the JRE differences make this
- * slightly complicated right now: this would be restricted to
- * JRE1.3
- *
- * TODO For JRE1.4 and higher this should be replaced by a more
- * general simulation of reflective access to constructors
- * (newInstance is no longer native there).
- *
*************************************************************/
// (YANNIS) Simple optimization predicate. It matters. This used
@@ -409,87 +191,26 @@
java:lang:Class:newInstance(?invocation, ?to, ?var),
VarPointsTo(_, ?class, ?ctx, ?var),
OptClassToConstructor(?constructor, ?class),
- MethodSignature:Type[?constructor] = ?type.
+ MethodSignature:Type[?constructor] = ?type,
+ ClassNewInstanceCastFilter(?invocation, ?type).
ReflectiveBaseVar[?invocation] = ?to <-
java:lang:Class:newInstance(?invocation, ?to, _).
-/*************************************************************
- * Class.getFields
- *
- * stable public interface
- * public Field getDeclaredField(String name)
- * public Field[] getDeclaredFields()
- * public Field getField(String name)
- * public Field[] getFields()
- *
- * native jre1.3
- * private native Field getField0(String name, int which)
- * private native Field[] getFields0(int which)
- *
- * native openjdk
- * private native Field[] getDeclaredFields0(boolean publicOnly)
- *
- * Notes:
- *
- * - getDeclaredField will not reflect the length field of an
- * array class (nor will getDeclaredFields, getField and
- * getFields, although that is not documented).
- *
- * TODO getField is often used with a constant string literal
- * argument. We should optimize for that.
- *
- *************************************************************/
-
-/**
- * find invocations
- */
-java:lang:Class:getDeclaredField(?to, ?from) <-
- MethodSignatureRef:Value(?signature:""),
- VirtualMethodInvocation:Signature[?invocation] = ?signature,
- AssignReturnValue[?invocation] = ?to,
- VirtualMethodInvocation:Base[?invocation] = ?from.
-
-/**
- * evaluate
- */
-RecordMacro(?ctx, ?heap, ?hctx),
-VarPointsTo(?hctx, ?heap, ?ctx, ?to) <-
- java:lang:Class:getDeclaredField(?to, ?from),
- VarPointsTo(_, ?class, ?ctx, ?from),
- ReifiedClass[?type] = ?class,
- Field:DeclaringClass[?signature] = ?type,
- ReifiedField[?signature] = ?heap,
- ObjectShouldNotBeRefined(?heap).
-
-#ifdef RecordRefinedMacro
-RecordRefinedMacro(?ctx, ?heap, ?hctx),
-VarPointsTo(?hctx, ?heap, ?ctx, ?to) <-
- java:lang:Class:getDeclaredField(?to, ?from),
- VarPointsTo(_, ?class, ?ctx, ?from),
- ReifiedClass[?type] = ?class,
- Field:DeclaringClass[?signature] = ?type,
- ReifiedField[?signature] = ?heap,
- ObjectShouldBeRefined(?heap).
-#endif
+ClassNewInstanceCastFilter(?invo, ?type) <-
+ java:lang:Class:newInstance(?invo, _, _),
+ ! ClassNewInstanceCast(?invo, _),
+ ClassType(?type),
+ ! AbstractClass(?type).
+
+ClassNewInstanceCastFilter(?invo, ?type) <-
+ ClassNewInstanceCast(?invo, ?castType),
+ NewableSubtype(?castType, ?type).
/*************************************************************
* Field.get
- *
- * stable public interface
- * public Object get(Object)
- *
*************************************************************/
-/**
- * Find invocations
- *
- * Notes:
- * - at this point, we cannot distinguish static fields from instance
- * fields.
- *
- * TODO refactor to have separate predicates.
- */
java:lang:reflect:Field:get(?invocation, ?to, ?field) <-
MethodSignatureRef:Value(?signature:""),
VirtualMethodInvocation:Signature[?invocation] = ?signature,
@@ -521,17 +242,6 @@
/**
* Load of static field.
- *
- * Notes:
- *
- * - For static fields, the actual argument of a call to get is not
- * relevant.
- *
- * - The context of the reified field heap object does not matter:
- * it has no fields whose value is determined by the context of
- * the allocation.
- *
- * TODO Check if class initialization handled by reflective.logic.
*/
ReflectiveLoadStaticField(?ctx, ?to, ?signature) <-
ReflectiveLoadField(_, ?ctx, ?to, ?signature),
@@ -549,10 +259,6 @@
/*************************************************************
* Field.set
- *
- * stable public interface
- * public void set(Object, Object)
- *
*************************************************************/
/**
@@ -604,8 +310,6 @@
/**
* Store of static field.
- *
- * TODO Check if class initialization handled by reflective.logic.
*/
ReflectiveStoreStaticField(?signature, ?ctx, ?from) <-
ReflectiveStoreField(_, ?signature, ?ctx, ?from),
@@ -620,3 +324,4 @@
ModifierRef:Value(?static:"static"),
! FieldModifier(?static, ?signature),
java:lang:reflect:Field:set:base[?invocation] = ?base.
+
diff -urN doop-r160113-bin/logic/library/reflective.logic solar/logic/library/reflective.logic
--- doop-r160113-bin/logic/library/reflective.logic 2013-01-16 07:31:46.000000000 +1100
+++ solar/logic/library/reflective.logic 2015-08-28 16:02:07.000000000 +1000
@@ -1,45 +1,4 @@
-/*************************************************************
- * Implementation of points-to propagation for concrete,
- * non-reflective, operations that have been discovered using
- * reflection.
- *
- * @author Martin Bravenboer
- *************************************************************/
-
-
-/*************************************************************
- * Reflective method calls
- *
- * Issues in the documentation:
- * - Class.getDeclaredMethods does not specify that is not returned.
- * - Method.invoke does not specify that private method calls do not do method lookup
- * - It is impossible to call an overridden method in a super class.
- *
- * Issues in Livshits' reflection analysis:
- * - no dynamic method lookup for instance methods (interface, abstract, overriden)
- * - no handling of exceptions
- * - unclear how to make context-sensitive
- * - not sound for reflective use of reflection
- * - no handling of boxing/unboxing
- *
- * Test:
- * - static initialization
- * - context-sensivitity
- * - virtual method lookup
- * - method declared in class of objParam
- *
- * TODO Boxing of primitive results
- *
- *************************************************************/
-/**
- * Method invocations resulting from propagating Method and
- * Constructor objects to reflective method invocations.
- *
- * As opposed to method invocations in the input facts, these must be
- * context-sensitive for precision purposes: for a reflective method
- * call sites, the invoked method can depend on the context.
- */
ReflectiveMethodInvocation(?ctx, ?caller, ?signature) ->
Context(?ctx), MethodInvocationRef(?caller),
MethodSignatureRef(?signature).
@@ -66,12 +25,24 @@
MethodInvocationRef(?caller),
VarRef(?actualParams).
+/**********************************************************
+ *
+ * Remove some fake reflective call graph edges which could affect performance.
+ *
+ *********************************************************/
+
+FakeReflectiveInvocation(?caller, ?target) ->
+ MethodInvocationRef(?caller),
+ MethodSignatureRef(?target).
+
+FakeReflectiveInvocation(?caller, ?target) <-
+ MethodInvocationRef(?caller),
+ InstructionRef:Value(?caller:"sun.reflect.misc.MethodUtil.invoke/java.lang.reflect.Method.invoke/0"),
+ MethodSignatureRef:Value(?target:"").
+
/*************************************************************
* Specific reflective method invocations
*
- * Reflective method invocations need to be specialized to determine
- * what kind of method call this is.
- *
*************************************************************/
ReflectiveSpecialMethodInvocation(?ctx, ?caller, ?signature) ->
@@ -97,6 +68,7 @@
*/
ReflectiveSpecialMethodInvocation(?ctx, ?caller, ?signature) <-
ReflectiveMethodInvocation(?ctx, ?caller, ?signature),
+ ! FakeReflectiveInvocation(?caller, ?signature),
ModifierRef:Value(?private:"private"),
MethodModifier(?private, ?signature),
ModifierRef:Value(?static:"static"),
@@ -107,6 +79,7 @@
*/
ReflectiveStaticMethodInvocation(?ctx, ?caller, ?signature) <-
ReflectiveMethodInvocation(?ctx, ?caller, ?signature),
+ ! FakeReflectiveInvocation(?caller, ?signature),
ModifierRef:Value(?static:"static"),
MethodModifier(?static, ?signature).
@@ -115,6 +88,7 @@
*/
ReflectiveVirtualMethodInvocation(?signature, ?ctx, ?caller) <-
ReflectiveMethodInvocation(?ctx, ?caller, ?signature),
+ ! FakeReflectiveInvocation(?caller, ?signature),
ModifierRef:Value(?private:"private"),
! MethodModifier(?private, ?signature),
ModifierRef:Value(?static:"static"),
@@ -122,11 +96,6 @@
/*************************************************************
* Reflective call graph edges
- *
- * TODO Unfortunately we have to redo the implementation of method
- * calls here. It might be a good idea to consider generation of
- * method invocations (but those are input predicates).
- *
*************************************************************/
/**
@@ -146,8 +115,10 @@
*
* TODO Macro for context
*/
+InitializedClass(?class),
ReflectiveCallGraphEdge(?callerCtx, ?caller, ?callerCtx, ?callee) <-
- ReflectiveStaticMethodInvocation(?callerCtx, ?caller, ?callee).
+ ReflectiveStaticMethodInvocation(?callerCtx, ?caller, ?callee),
+ MethodSignature:Type[?callee] = ?class.
/**
* Special methods
@@ -168,11 +139,6 @@
/**
* Virtual methods
- *
- * TODO Check if object is an instance of the class declaring the
- * method (only overapproximation)
- *
- * TODO Macro for context
*/
ReflectiveCallGraphEdge(?callerCtx, ?caller, ?callerCtx, ?tomethod),
VarPointsTo(?hctx, ?heap, ?callerCtx, ?this)
@@ -187,7 +153,7 @@
MethodSignature:Descriptor[?signature] = ?descriptor,
MethodLookup[?simplename, ?descriptor, ?heaptype] = ?tomethod,
ThisVar[?tomethod] = ?this.
-
+
/**
* Return values of reflective method invocations
*/
@@ -263,11 +229,28 @@
Context(?callerCtx), VarRef(?base).
/**
+ * Modification: original predicate name LoadHeapArrayIndex is replaced by
+ * ReflectiveLoadHeapArrayIndex. The relative change is reflected in context-sensitive.logic.
+ * The original implementation causes reflective parameters assign failed.
+ */
+ReflectiveLoadHeapArrayIndex(?calleeCtx, ?to, ?basehctx, ?baseheap) ->
+ Context(?calleeCtx),
+ VarRef(?to),
+ HContext(?basehctx),
+ HeapAllocationRef(?baseheap).
+
+ReflectiveLoadHeapArrayIndex(?calleeCtx, ?to, ?basehctx, ?baseheap) <-
+ ReflectiveLoadArrayIndex(?calleeCtx, ?to, ?callerCtx, ?base),
+ VarPointsTo(?basehctx, ?baseheap, ?callerCtx, ?base).
+
+/**
* TODO it's unfortunate this code is so similar to normal LoadArrayIndex.
*/
+/*
LoadHeapArrayIndex(?calleeCtx, ?to, ?basehctx, ?baseheap) <-
ReflectiveLoadArrayIndex(?calleeCtx, ?to, ?callerCtx, ?base),
VarPointsTo(?basehctx, ?baseheap, ?callerCtx, ?base).
+*/
/*************************************************************
@@ -296,9 +279,12 @@
ReflectiveStoreStaticField(?signature, ?ctx, ?var) ->
FieldSignatureRef(?signature), Context(?ctx), VarRef(?var).
+InitializedClass(?class),
StaticFieldPointsTo(?hctx, ?heap, ?signature) <-
ReflectiveStoreStaticField(?signature, ?ctx, ?var),
- VarPointsTo(?hctx, ?heap, ?ctx, ?var).
+ VarPointsTo(?hctx, ?heap, ?ctx, ?var),
+ FieldSignature(?signature, ?class, _, ?type),
+ AssignCompatible(?type, HeapAllocation:Type[?heap]).
/*************************************************************
*
@@ -310,8 +296,10 @@
Context(?baseCtx), VarRef(?base), FieldSignatureRef(?signature),
Context(?toCtx), VarRef(?to).
+InitializedClass(?class),
LoadHeapInstanceField(?toCtx, ?to, ?sig, ?basehctx, ?baseheap) <-
ReflectiveLoadInstanceField(?toCtx, ?to, ?sig, ?baseCtx, ?base),
+ Field:DeclaringClass[?sig] = ?class,
VarPointsTo(?basehctx, ?baseheap, ?baseCtx, ?base).
/*************************************************************
@@ -324,6 +312,13 @@
Context(?fromCtx), VarRef(?from), Context(?baseCtx), VarRef(?base),
FieldSignatureRef(?signature).
-StoreHeapInstanceField(?signature, ?basehctx, ?baseheap, ?fromCtx, ?from) <-
+// Special handle rules for reflective instance field store
+ReflectiveStoreHeapInstanceField(?signature, ?basehctx, ?baseheap, ?fromCtx, ?from) <-
ReflectiveStoreInstanceField(?fromCtx, ?from, ?signature, ?baseCtx, ?base),
VarPointsTo(?basehctx, ?baseheap, ?baseCtx, ?base).
+
+InstanceFieldPointsTo(?hctx, ?heap, ?signature, ?basehctx, ?baseheap) <-
+ ReflectiveStoreHeapInstanceField(?signature, ?basehctx, ?baseheap, ?ctx, ?from),
+ VarPointsTo(?hctx, ?heap, ?ctx, ?from),
+ FieldSignature(?signature, _, _, ?fieldType),
+ AssignCompatible(?fieldType, HeapAllocation:Type[?heap]).
diff -urN doop-r160113-bin/logic/library/solar/annotation-guidance.logic solar/logic/library/solar/annotation-guidance.logic
--- doop-r160113-bin/logic/library/solar/annotation-guidance.logic 1970-01-01 10:00:00.000000000 +1000
+++ solar/logic/library/solar/annotation-guidance.logic 2016-05-05 11:51:51.000000000 +1000
@@ -0,0 +1,260 @@
+/* SOLAR - Effective Soundness-Guided Reflection Analysis
+ *
+ * Copyright (C) 2015 Yue Li, Tian Tan, Jingling Xue
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+
+NewInstanceCastToEntry(?newInvo, ?entry, ?type, NrNewableSubtypeTemp[?type], ?inmethod) <-
+ AssignCast(?type, ?from, _, ?inmethod),
+ VarPointsTo(?hctx, ?unknownObj, _, ?from),
+ UnknownObject[?newInvo] = ?unknownObj,
+ UnknownObjectToEntry(?hctx, ?unknownObj, ?entry).
+
+UnknownObjectToEntry(?hctx, ?unknownObj, ?entry) <-
+ UnknownObject[?newInvo] = ?unknownObj,
+ java:lang:Class:newInstance(?newInvo, ?to, ?clsVar),
+ VarPointsTo(?hctx, ?unknownObj, ?toCtx, ?to),
+ VarPointsTo(_, ?unknownClass, ?toCtx, ?clsVar),
+ UnknownClass[?unknownClass] = ?entry.
+
+UnknownObjectToEntry(?hctx, ?unknownObj, ?entry) <-
+ UnknownObject[?newInvo] = ?unknownObj,
+ java:lang:reflect:Constructor:newInstance(?newInvo, ?to, ?base),
+ VarPointsTo(?hctx, ?unknownObj, ?toCtx, ?to),
+ VarPointsTo(_, ?unknownCtor, ?toCtx, ?base),
+ UnknownConstructorToEntry(?unknownCtor, ?entry).
+
+UnknownConstructorToEntry(?unknownCtor, ?entry) <-
+ UnknownConstructor[?unknownCtor] = ?invo,
+ (
+ java:lang:Class:getConstructor(?invo, _, ?from);
+ java:lang:Class:getConstructors(?invo, ?from)
+ ),
+ VarPointsTo(_, ?class, _, ?from),
+ UnknownClass[?class] = ?entry.
+
+UnknownConstructorToEntry(?unknownCtor, ?entry) <-
+ UnknownDeclaredConstructor[?unknownCtor] = ?invo,
+ (
+ java:lang:Class:getDeclaredConstructor(?invo, _, ?from);
+ java:lang:Class:getDeclaredConstructors(?invo, ?from)
+ ),
+ VarPointsTo(_, ?class, _, ?from),
+ UnknownClass[?class] = ?entry.
+
+
+/**
+ * unsound situation (entry + get*Method*):
+ * null
+ * 1. null + m^u_u
+ * 2. null + m^u_s (only get[Declared]Method) + unsolved signature
+ * ou
+ * 1. ou + m^u_u
+ * 2. ou + m^u_s (only get[Declared]Method) + unsolved signature
+ */
+
+UnsoundStaticInvoke(?invoke, ?getMethInvo, ?entry) <-
+ java:lang:reflect:Method:invoke(?invoke, ?mtd),
+ VarPointsTo(?mtdHctx, ?mtdHeap, _, ?mtd),
+ MethodUUToEntry(?mtdHctx, ?mtdHeap, ?getMethInvo, ?entry).
+
+UnsoundStaticInvoke(?invoke, ?getMethInvo, ?entry) <-
+ java:lang:reflect:Method:invoke(?invoke, ?mtd),
+ VarPointsTo(?mtdHctx, ?mtdHeap, _, ?mtd),
+ !ResolvedInvokeArgs(?invoke),
+ MethodUSToEntry(?mtdHctx, ?mtdHeap, ?getMethInvo, ?entry).
+
+InvokeWithUnknownObject(?invoke, ?ctx) <-
+ java:lang:reflect:Method:invoke(?invoke, _),
+ ReflectiveBaseVar[?invoke] = ?obj,
+ VarPointsTo(_, ?unknownObj, ?ctx, ?obj),
+ UnknownObject[_] = ?unknownObj.
+
+UnsoundInvoke(?invoke, ?getMethInvo, ?entry) <-
+ java:lang:reflect:Method:invoke(?invoke, ?mtd),
+ InvokeWithUnknownObject(?invoke, ?ctx),
+ VarPointsTo(?mtdHctx, ?mtdHeap, ?ctx, ?mtd),
+ MethodUUToEntry(?mtdHctx, ?mtdHeap, ?getMethInvo, ?entry).
+
+UnsoundInvoke(?invoke, ?getMethInvo, ?entry) <-
+ java:lang:reflect:Method:invoke(?invoke, ?mtd),
+ InvokeWithUnknownObject(?invoke, ?ctx),
+ VarPointsTo(?mtdHctx, ?mtdHeap, ?ctx, ?mtd),
+ !ResolvedInvokeArgs(?invoke),
+ MethodUSToEntry(?mtdHctx, ?mtdHeap, ?getMethInvo, ?entry).
+
+MethodUUToEntry(?mtdHctx, ?mtdHeap, ?getMethInvo, ?entry) <-
+ MethodUUHeap[?mtdHeap] = ?getMethInvo,
+ (
+ java:lang:Class:getMethod(?getMethInvo, ?from),
+ AssignReturnValue[?getMethInvo] = ?to,
+ VarPointsTo(?mtdHctx, ?mtdHeap, ?ctx, ?to);
+ java:lang:Class:getMethods(?getMethInvo, ?from),
+ AssignReturnValue[?getMethInvo] = ?to,
+ VarPointsTo(?mtdHctx, ?mtdArrayHeap, ?ctx, ?to),
+ ArrayIndexPointsTo(?mtdHctx, ?mtdHeap, ?mtdHctx, ?mtdArrayHeap)
+ ),
+ VarPointsTo(_, ?class, ?ctx, ?from),
+ UnknownClass[?class] = ?entry.
+
+MethodUUToEntry(?mtdHctx, ?mtdHeap, ?getMethInvo, ?entry) <-
+ DeclaredMethodUUHeap[?mtdHeap] = ?getMethInvo,
+ (
+ java:lang:Class:getDeclaredMethod(?getMethInvo, ?from),
+ AssignReturnValue[?getMethInvo] = ?to,
+ VarPointsTo(?mtdHctx, ?mtdHeap, ?ctx, ?to);
+ java:lang:Class:getDeclaredMethods(?getMethInvo, ?from),
+ AssignReturnValue[?getMethInvo] = ?to,
+ VarPointsTo(?mtdHctx, ?mtdArrayHeap, ?ctx, ?to),
+ ArrayIndexPointsTo(?mtdHctx, ?mtdHeap, ?mtdHctx, ?mtdArrayHeap)
+ ),
+ VarPointsTo(_, ?class, ?ctx, ?from),
+ UnknownClass[?class] = ?entry.
+
+MethodUSToEntry(?mtdHctx, ?mtdHeap, ?getMethInvo, ?entry) <-
+ (
+ MethodUSHeap[?mtdHeap] = _,
+ java:lang:Class:getMethod(?getMethInvo, ?from);
+ DeclaredMethodUSHeap[?mtdHeap] = _,
+ java:lang:Class:getDeclaredMethod(?getMethInvo, ?from)
+ ),
+ AssignReturnValue[?getMethInvo] = ?to,
+ VarPointsTo(?mtdHctx, ?mtdHeap, ?ctx, ?to),
+ VarPointsTo(_, ?class, ?ctx, ?from),
+ UnknownClass[?class] = ?entry.
+
+
+/**
+ * Guidance for imprecise situation (resolve methods only by class type)
+ *
+ */
+
+// 1. m^t_u + unsolved signature
+OnlyClassInvokeStaticMethod(?invoke, ?method) <-
+ java:lang:reflect:Method:invoke(?invoke, ?mtd),
+ !ResolvedInvokeArgs(?invoke),
+ VarPointsTo(_, ?mtdHeap, _, ?mtd),
+ (
+ MethodTUHeap[?mtdHeap] = ?type,
+ LookUpMethod(?type, _, ?method);
+ DeclaredMethodTUHeap[?mtdHeap] = ?type,
+ MethodSignature:Type[?method] = ?type
+ ),
+ MethodModifier("static", ?method).
+
+OnlyClassInvokeInstanceMethod(?invoke, ?method) <-
+ java:lang:reflect:Method:invoke(?invoke, ?mtd),
+ !ResolvedInvokeArgs(?invoke),
+ VarPointsTo(_, ?mtdHeap, _, ?mtd),
+ ReflectiveBaseVar[?invoke] = _,
+ (
+ DeclaredMethodTUHeap[?mtdHeap] = ?type,
+ MethodSignature:Type[?method] = ?type;
+ MethodTUHeap[?mtdHeap] = ?type,
+ LookUpMethod(?type, _, ?method)
+ ),
+ !MethodModifier("static", ?method).
+
+InvokeToGetMethod(?invoke, ?getMethInvo) <-
+ java:lang:reflect:Method:invoke(?invoke, ?mtd),
+ !ResolvedInvokeArgs(?invoke),
+ VarPointsTo(?mtdHctx, ?mtdHeap, _, ?mtd),
+ MethodTUToGetMethod(?mtdHctx, ?mtdHeap, ?getMethInvo).
+
+// track the get[Declared]Method[s] invocation
+MethodTUToGetMethod(?mtdHctx, ?mtdHeap, ?getMethInvo) <-
+ MethodTUHeap[?mtdHeap] = _,
+ (
+ java:lang:Class:getMethod(?getMethInvo, _),
+ AssignReturnValue[?getMethInvo] = ?to,
+ VarPointsTo(?mtdHctx, ?mtdHeap, _, ?to);
+ java:lang:Class:getMethods(?getMethInvo, _),
+ AssignReturnValue[?getMethInvo] = ?to,
+ VarPointsTo(?mtdHctx, ?mtdArrayHeap, _, ?to),
+ ArrayIndexPointsTo(?mtdHctx, ?mtdHeap, ?mtdHctx, ?mtdArrayHeap)
+ ).
+
+MethodTUToGetMethod(?mtdHctx, ?mtdHeap, ?getMethInvo) <-
+ DeclaredMethodTUHeap[?mtdHeap] = _,
+ (
+ java:lang:Class:getDeclaredMethod(?getMethInvo, _),
+ AssignReturnValue[?getMethInvo] = ?to,
+ VarPointsTo(?mtdHctx, ?mtdHeap, _, ?to);
+ java:lang:Class:getDeclaredMethods(?getMethInvo, _),
+ AssignReturnValue[?getMethInvo] = ?to,
+ VarPointsTo(?mtdHctx, ?mtdArrayHeap, _, ?to),
+ ArrayIndexPointsTo(?mtdHctx, ?mtdHeap, ?mtdHctx, ?mtdArrayHeap)
+ ).
+
+OnlyClassInvoke(?invoke, ?method, ?getMethInvo) <-
+ OnlyClassInvokeStaticMethod(?invoke, ?method),
+ InvokeToGetMethod(?invoke, ?getMethInvo).
+
+OnlyClassInvoke(?invoke, ?method, ?getMethInvo) <-
+ OnlyClassInvokeInstanceMethod(?invoke, ?method),
+ InvokeToGetMethod(?invoke, ?getMethInvo).
+
+// 2. m^u_u + unsolved signature
+OnlyClassInvoke(?invoke, ?method, ?getMethInvo) <-
+ java:lang:reflect:Method:invoke(?invoke, ?mtd),
+ !ResolvedInvokeArgs(?invoke),
+ ReflectiveBaseVar[?invoke] = ?receiver,
+ VarPointsTo(_, ?receiverHeap, ?ctx, ?receiver),
+ VarPointsTo(_, ?mtdHeap, ?ctx, ?mtd),
+ (
+ MethodUUHeap[?mtdHeap] = ?getMethInvo,
+ AllPublicInstanceMethod(HeapAllocation:Type[?receiverHeap], ?method);
+ DeclaredMethodUUHeap[?mtdHeap] = ?getMethInvo,
+ AllInstanceMethod(HeapAllocation:Type[?receiverHeap], ?method)
+ ).
+
+// 3. counting
+OnlyClassInvokeTarget(?invoke, ?method) <-
+ OnlyClassInvoke(?invoke, ?method, _).
+
+NrOnlyClassInvokeTarget[?invoke] = ?n <-
+ agg<> OnlyClassInvokeTarget(?invoke, _).
+
+ImpreciseInvoke(?invoke, ?n, ?getMethInvo) <-
+ OnlyClassInvoke(?invoke, _, ?getMethInvo),
+ NrOnlyClassInvokeTarget[?invoke] = ?n.
+
+// f^t_u
+OnlyClassTypeGetTU(?invo, ?classType) <-
+ java:lang:reflect:Field:get(?invo, _, ?base),
+ VarPointsTo(_, ?heap, _, ?base),
+ !FieldGetCast(?invo, _),
+ (
+ FieldTUHeap[?heap] = ?classType;
+ DeclaredFieldTUHeap[?heap] = ?classType
+ ).
+
+// f^u_u
+OnlyClassTypeGetUU(?invo, ?classType) <-
+ java:lang:reflect:Field:get(?invo, _, ?base),
+ java:lang:reflect:Field:get:base[?invo] = ?arg,
+ VarPointsTo(_, ?receiver, ?ctx, ?arg),
+ HeapAllocation:Type[?receiver] = ?classType,
+ !FieldGetCast(?invo, _),
+ VarPointsTo(_, ?fieldHeap, ?ctx, ?base),
+ (
+ FieldUUHeap[?fieldHeap] = _;
+ DeclaredFieldUUHeap[?fieldHeap] = _
+ ).
+
+ImpreciseGet(?invo) <-
+ OnlyClassTypeGetTU(?invo, _);
+ OnlyClassTypeGetUU(?invo, _).
diff -urN doop-r160113-bin/logic/library/solar/array.logic solar/logic/library/solar/array.logic
--- doop-r160113-bin/logic/library/solar/array.logic 1970-01-01 10:00:00.000000000 +1000
+++ solar/logic/library/solar/array.logic 2016-05-05 11:51:55.000000000 +1000
@@ -0,0 +1,101 @@
+/* SOLAR - Effective Soundness-Guided Reflection Analysis
+ *
+ * Copyright (C) 2015 Yue Li, Tian Tan, Jingling Xue
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+/*************************************************************
+ * Array.newInstance
+ *
+ * stable public interface
+ * public Object newInstance(Class, int)
+ *
+ * TODO handle multidimentional array
+ *************************************************************/
+// most class entrace of Array.newInstance is getComponentType
+java:lang:Class:getComponentType(?base, ?to) <-
+ MethodSignatureRef:Value(?getCompType:""),
+ VirtualMethodInvocation(?invo, ?getCompType, _),
+ VirtualMethodInvocation:Base[?invo] = ?base,
+ AssignReturnValue[?invo] = ?to.
+
+RecordImmutableMacro(?ctx, ?class, ?immCtx),
+VarPointsTo(?immCtx, ?class, ?ctx, ?to) <-
+ java:lang:Class:getComponentType(?base, ?to),
+ VarPointsTo(_, ?baseClass, ?ctx, ?base),
+ ReifiedClass[?baseType] = ?baseClass,
+ ComponentType[?baseType] = ?componentType,
+ ReifiedClass[?componentType] = ?class.
+
+ReflectiveAssignNewArrayHeap(?invo, ?ctx, ?arrayType, ?to) <-
+ java:lang:reflect:Array:newInstance(?invo, ?to),
+ ActualParam[0, ?invo] = ?var,
+ VarPointsTo(_, ?class, ?ctx, ?var),
+ ReifiedClass[?componentType] = ?class,
+ ComponentType[?arrayType] = ?componentType.
+
+RecordMacro(?ctx, ?heap, ?hctx),
+VarPointsTo(?hctx, ?heap, ?ctx, ?to) <-
+ ReflectiveAssignNewArrayHeap(?invo, ?ctx, ?arrayType, ?to),
+ ReflectiveArrayHeapAllocation[?invo, ?arrayType] = ?heap.
+
+/*************************************************************
+ * Array.get
+ *
+ * stable public interface
+ * public Object get(Object, int)
+ *
+ *************************************************************/
+// Resovle Object o = Array.get(base, index)
+java:lang:reflect:Array:get(?base, ?to) ->
+ VarRef(?base),
+ VarRef(?to).
+
+java:lang:reflect:Array:get(?base, ?to) <-
+ MethodSignatureRef:Value(?get:""),
+ StaticMethodInvocation:Signature[?invocation] = ?get,
+ ParamIndexRef:Value(?zero:0),
+ ActualParam[?zero, ?invocation] = ?base,
+ AssignReturnValue[?invocation] = ?to.
+
+ArrayGet(?baseheap, ?to),
+LoadHeapArrayIndex(?ctx, ?to, ?basehctx, ?baseheap) <-
+ java:lang:reflect:Array:get(?base, ?to),
+ VarPointsTo(?basehctx, ?baseheap, ?ctx, ?base).
+
+/*************************************************************
+ * Array.set
+ *
+ * stable public interface
+ * public void set(Object, int, Object)
+ *
+ *************************************************************/
+// Resolve Array.set(base, index, val)
+java:lang:reflect:Array:set(?base, ?from) ->
+ VarRef(?base),
+ VarRef(?from).
+
+java:lang:reflect:Array:set(?base, ?value) <-
+ MethodSignatureRef:Value(?set:""),
+ StaticMethodInvocation:Signature[?invocation] = ?set,
+ ParamIndexRef:Value(?zero:0),
+ ActualParam[?zero, ?invocation] = ?base,
+ ParamIndexRef:Value(?two:2),
+ ActualParam[?two, ?invocation] = ?value.
+
+ArraySet(?baseheap, ?from),
+StoreHeapArrayIndex(?basehctx, ?baseheap, ?ctx, ?from) <-
+ java:lang:reflect:Array:set(?base, ?from),
+ VarPointsTo(?basehctx, ?baseheap, ?ctx, ?base).
diff -urN doop-r160113-bin/logic/library/solar/inference.logic solar/logic/library/solar/inference.logic
--- doop-r160113-bin/logic/library/solar/inference.logic 1970-01-01 10:00:00.000000000 +1000
+++ solar/logic/library/solar/inference.logic 2016-05-05 11:52:12.000000000 +1000
@@ -0,0 +1,650 @@
+/* SOLAR - Effective Soundness-Guided Reflection Analysis
+ *
+ * Copyright (C) 2015 Yue Li, Tian Tan, Jingling Xue
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+
+#define INFERENCE
+#ifndef PROBE
+ #define RELAX_INFERENCE
+#endif
+
+FamilyType(?type, ?familyType) ->
+ Type(?type), Type(?familyType).
+
+FamilyType(?type, ?fatherType) <-
+ AssignCompatible(?fatherType, ?type).
+
+FamilyType(?type, ?childType) <-
+ AssignCompatible(?type, ?childType).
+
+PrimitiveWrapperType(B),
+FamilyType(B, b) <- Type:Value(B:"java.lang.Boolean"), Type:Value(b:"bool").
+PrimitiveWrapperType(B),
+FamilyType(B, b) <- Type:Value(B:"java.lang.Byte"), Type:Value(b:"byte").
+PrimitiveWrapperType(C),
+FamilyType(C, c) <- Type:Value(C:"java.lang.Character"), Type:Value(c:"char").
+PrimitiveWrapperType(S),
+FamilyType(S, s) <- Type:Value(S:"java.lang.Short"), Type:Value(s:"short").
+PrimitiveWrapperType(I),
+FamilyType(I, i) <- Type:Value(I:"java.lang.Integer"), Type:Value(i:"int").
+PrimitiveWrapperType(L),
+FamilyType(L, l) <- Type:Value(L:"java.lang.Long"), Type:Value(l:"long").
+PrimitiveWrapperType(F),
+FamilyType(F, f) <- Type:Value(F:"java.lang.Float"), Type:Value(f:"float").
+PrimitiveWrapperType(D),
+FamilyType(D, d) <- Type:Value(D:"java.lang.Double"), Type:Value(d:"double").
+PrimitiveWrapperType(O) <- Type:Value(O:"java.lang.Object").
+
+LookUpFieldByType(?classType, ?fldType, ?field) <-
+ LookUpField(?classType, _, ?field),
+ FieldSignature(?field, ?classType, _, ?fldType).
+
+// instance field
+AllInstanceField(?classType, ?name, ?field) <-
+ FieldSignature(?field, ?classType, ?name, _),
+ !FieldModifier("static", ?field).
+
+AllInstanceField(?classType, ?name, ?field) <-
+ DirectSuperclass[?classType] = ?super,
+ AllInstanceField(?super, ?name, ?field).
+
+AllInstanceField(?classType, ?name, ?field) <-
+ DirectSuperinterface(?classType, ?superIface),
+ AllInstanceField(?superIface, ?name, ?field).
+
+AllNotFinalPublicInstanceField(?classType, ?field, ?fieldType) <-
+ LookUpFieldByType(?classType, ?fieldType, ?field), // only get public field here
+ !FieldModifier("static", ?field),
+ !FieldModifier("final", ?field).
+
+AllNotFinalDeclaredInstanceField(?classType, ?field, ?fieldType) <-
+ FieldSignature(?field, ?classType, _, ?fieldType),
+ !FieldModifier("static", ?field),
+ !FieldModifier("final", ?field).
+
+AllNotFinalDeclaredInstanceField(?classType, ?field, ?fieldType) <-
+ DirectSuperclass[?classType] = ?super,
+ AllNotFinalDeclaredInstanceField(?super, ?field, ?fieldType).
+
+AllNotFinalDeclaredInstanceField(?classType, ?field, ?fieldType) <-
+ DirectSuperinterface(?classType, ?superIface),
+ AllNotFinalDeclaredInstanceField(?superIface, ?field, ?fieldType).
+
+#ifdef INFERENCE
+/** field.get */
+// f^t_u
+ReflectiveLoadField(?invo, ?ctx, ?to, ?field) <-
+ java:lang:reflect:Field:get(?invo, ?to, ?base),
+ VarPointsTo(_, ?heap, ?ctx, ?base),
+ FieldTUHeap[?heap] = ?classType,
+ FieldGetCast(?invo, ?castType),
+ FamilyType(?castType, ?fieldType),
+ LookUpFieldByType(?classType, ?fieldType, ?field).
+
+ReflectiveLoadField(?invo, ?ctx, ?to, ?field) <-
+ java:lang:reflect:Field:get(?invo, ?to, ?base),
+ VarPointsTo(_, ?heap, ?ctx, ?base),
+ DeclaredFieldTUHeap[?heap] = ?classType,
+ FieldGetCast(?invo, ?castType),
+ FamilyType(?castType, ?fieldType),
+ FieldSignature(?field, ?classType, _, ?fieldType).
+
+// f^u_s
+ReflectiveLoadField(?invo, ?ctx, ?to, ?signature) <-
+ java:lang:reflect:Field:get(?invo, ?to, ?base),
+ VarPointsTo(_, ?fieldHeap, ?ctx, ?base),
+ FieldUSHeap[?fieldHeap] = ?name,
+ java:lang:reflect:Field:get:base[?invo] = ?arg,
+ VarPointsTo(_, ?receiver, ?ctx, ?arg),
+ HeapAllocation:Type[?receiver] = ?type,
+ LookUpField(?type, ?name, ?signature),
+ !FieldModifier("static", ?signature).
+
+ReflectiveLoadField(?invo, ?ctx, ?to, ?signature) <-
+ java:lang:reflect:Field:get(?invo, ?to, ?base),
+ VarPointsTo(_, ?fieldHeap, ?ctx, ?base),
+ DeclaredFieldUSHeap[?fieldHeap] = ?name,
+ java:lang:reflect:Field:get:base[?invo] = ?arg,
+ VarPointsTo(_, ?receiver, ?ctx, ?arg),
+ HeapAllocation:Type[?receiver] = ?type,
+ AllInstanceField(?type, ?name, ?signature).
+
+// f^u_u
+ReflectiveLoadField(?invo, ?ctx, ?to, ?signature) <-
+ java:lang:reflect:Field:get(?invo, ?to, ?base),
+ VarPointsTo(_, ?fieldHeap, ?ctx, ?base),
+ FieldUUHeap[?fieldHeap] = _,
+ java:lang:reflect:Field:get:base[?invo] = ?arg,
+ VarPointsTo(_, ?receiver, ?ctx, ?arg),
+ HeapAllocation:Type[?receiver] = ?classType,
+ FieldGetCast(?invo, ?castType),
+ FamilyType(?castType, ?fieldType),
+ LookUpFieldByType(?classType, ?fieldType, ?signature),
+ !FieldModifier("static", ?signature).
+
+ReflectiveLoadField(?invo, ?ctx, ?to, ?signature) <-
+ java:lang:reflect:Field:get(?invo, ?to, ?base),
+ VarPointsTo(_, ?fieldHeap, ?ctx, ?base),
+ DeclaredFieldUUHeap[?fieldHeap] = _,
+ java:lang:reflect:Field:get:base[?invo] = ?arg,
+ VarPointsTo(_, ?receiver, ?ctx, ?arg),
+ HeapAllocation:Type[?receiver] = ?classType,
+ AllInstanceField(?classType, _, ?signature),
+ FieldGetCast(?invo, ?castType),
+ FamilyType(?castType, ?fieldType),
+ FieldSignature(?signature, _, _, ?fieldType).
+
+/** field.set */
+// f^t_u
+ReflectiveStoreField(?invo, ?field, ?ctx, ?from) <-
+ java:lang:reflect:Field:set(?invo, ?base),
+ VarPointsTo(_, ?heap, ?ctx, ?base),
+ FieldTUHeap[?heap] = ?classType,
+ java:lang:reflect:Field:set:from[?invo] = ?from,
+ VarPointsTo(_, ?valHeap, ?ctx, ?from),
+ HeapAllocation:Type[?valHeap] = ?valType,
+ AssignCompatible(?fieldType, ?valType),
+ LookUpFieldByType(?classType, ?fieldType, ?field),
+ ModifierRef:Value(?final:"final"),
+ !FieldModifier(?final, ?field).
+
+ReflectiveStoreField(?invo, ?field, ?ctx, ?from) <-
+ java:lang:reflect:Field:set(?invo, ?base),
+ VarPointsTo(_, ?heap, ?ctx, ?base),
+ DeclaredFieldTUHeap[?heap] = ?classType,
+ java:lang:reflect:Field:set:from[?invo] = ?from,
+ VarPointsTo(_, ?valHeap, ?ctx, ?from),
+ HeapAllocation:Type[?valHeap] = ?valType,
+ AssignCompatible(?fieldType, ?valType),
+ FieldSignature(?field, ?classType, _, ?fieldType),
+ ModifierRef:Value(?final:"final"),
+ !FieldModifier(?final, ?field).
+
+// f^u_s
+ReflectiveStoreField(?invo, ?field, ?ctx, ?from) <-
+ java:lang:reflect:Field:set(?invo, ?base),
+ VarPointsTo(_, ?fieldHeap, ?ctx, ?base),
+ FieldUSHeap[?fieldHeap] = ?name,
+ java:lang:reflect:Field:set:from[?invo] = ?from,
+ java:lang:reflect:Field:set:base[?invo] = ?arg,
+ VarPointsTo(_, ?receiver, ?ctx, ?arg),
+ HeapAllocation:Type[?receiver] = ?classType,
+ AllNotFinalPublicInstanceField(?classType, ?field, _),
+ FieldSignature(?field, _, ?name, _).
+
+ReflectiveStoreField(?invo, ?field, ?ctx, ?from) <-
+ java:lang:reflect:Field:set(?invo, ?base),
+ VarPointsTo(_, ?fieldHeap, ?ctx, ?base),
+ DeclaredFieldUSHeap[?fieldHeap] = ?name,
+ java:lang:reflect:Field:set:from[?invo] = ?from,
+ java:lang:reflect:Field:set:base[?invo] = ?arg,
+ VarPointsTo(_, ?receiver, ?ctx, ?arg),
+ HeapAllocation:Type[?receiver] = ?classType,
+ AllNotFinalDeclaredInstanceField(?classType, ?field, _),
+ FieldSignature(?field, _, ?name, _).
+
+// f^u_u
+ReflectiveStoreField(?invo, ?field, ?ctx, ?from) <-
+ java:lang:reflect:Field:set(?invo, ?base),
+ VarPointsTo(_, ?fieldHeap, ?ctx, ?base),
+ FieldUUHeap[?fieldHeap] = _,
+ java:lang:reflect:Field:set:base[?invo] = ?arg,
+ VarPointsTo(_, ?receiver, ?ctx, ?arg),
+ java:lang:reflect:Field:set:from[?invo] = ?from,
+ VarPointsTo(_, ?heap, ?ctx, ?from),
+ HeapAllocation:Type[?receiver] = ?classType,
+ AllNotFinalPublicInstanceField(?classType, ?field, ?fieldType),
+ AssignCompatible(?fieldType, HeapAllocation:Type[?heap]).
+
+ReflectiveStoreField(?invo, ?field, ?ctx, ?from) <-
+ java:lang:reflect:Field:set(?invo, ?base),
+ VarPointsTo(_, ?fieldHeap, ?ctx, ?base),
+ DeclaredFieldUUHeap[?fieldHeap] = _,
+ java:lang:reflect:Field:set:base[?invo] = ?arg,
+ VarPointsTo(_, ?receiver, ?ctx, ?arg),
+ java:lang:reflect:Field:set:from[?invo] = ?from,
+ VarPointsTo(_, ?heap, ?ctx, ?from),
+ HeapAllocation:Type[?receiver] = ?classType,
+ AllNotFinalDeclaredInstanceField(?classType, ?field, ?fieldType),
+ AssignCompatible(?fieldType, HeapAllocation:Type[?heap]).
+#endif // #ifdef INFERENCE
+
+/** method.invoke */
+ConcreteMethod(?method) <-
+ MethodImplemented[_, _, _] = ?method,
+ MethodSignature:SimpleName[?method] != "",
+ MethodSignature:SimpleName[?method] != "".
+
+// intra-procedural analysis for resolving Method.invoke
+VarFlowToInvokeArgs(?args, ?args) <-
+ java:lang:reflect:Method:invoke(?invoke, _),
+ ReflectiveActualParams[?invoke] = ?args.
+
+VarFlowToInvokeArgs(?from, ?args) <-
+ (
+ AssignLocal(?from, ?to, _);
+ AssignCast(_, ?from, ?to, _)
+ ),
+ VarFlowToInvokeArgs(?to, ?args).
+
+UnresolvedInvokeArgs(?invoke, ?args) <-
+ ReflectiveActualParams[?invoke] = ?args,
+ VarFlowToInvokeArgs(?var, ?args),
+ (
+ LoadArrayIndex(_, ?var, _);
+ StoreArrayIndex(?var, _, _);
+ LoadInstanceField(_, _, ?var, _);
+ StoreInstanceField(?var, _, _, _);
+ LoadStaticField(_, ?var, _);
+ StoreStaticField(?var, _, _);
+ (
+ ActualParam[_, ?invo] = ?var,
+ !ReflectiveActualParams[?invo] = ?args
+ );
+ FormalParam[_, _] = ?var;
+ AssignReturnValue[_] = ?var;
+ (
+ AssignHeapAllocation(?argsArray, ?var, _),
+ !NewArraySize[?argsArray] = _
+ );
+ StoreArrayVarIndexType(?var, _)
+ ).
+
+ResolvedInvokeArgs(?invo) <-
+ java:lang:reflect:Method:invoke(?invo, _),
+ ReflectiveActualParams[?invo] = ?args,
+ !UnresolvedInvokeArgs(?invo, ?args).
+
+ResolvedInvokeArgs(?invo) <-
+ java:lang:reflect:Method:invoke(?invo, _),
+ !ReflectiveActualParams[?invo] = _.
+
+VarFlowToInvokeVar(?var, ?var) <-
+ VarFlowToInvokeArgs(?var, _).
+
+VarFlowToInvokeVar(?from, ?to) <-
+ VarFlowToInvokeVar(?var, ?to),
+ (
+ AssignLocal(?from, ?var, _);
+ AssignCast(_, ?from, ?var, _)
+ ).
+
+ArgsArrayFlowToInvokeVar(?argsArray, ?to) <-
+ AssignHeapAllocation(?argsArray, ?var, _),
+ VarFlowToInvokeVar(?var, ?to).
+
+// It is straightforward and easily to use dynamic types of the
+// elements of array argument to infer the parameter types of
+// target methods (i.e., just using the points-to results).
+// However, doing so with Datalog would involve negation recursion problem
+// since we have to both use negation to simulate the effect of "for-each"
+// and use VarPointsTo for retrieving the dynamic types. May be this is
+// the limitation of Datalog? Currently, we use
+// declared types (stored in the relation StoreArrayConstantsIndexType)
+// and their subtypes (for soundness) of elements to look up
+// potential target methods.
+InvokeArgsArrayStoreIndexType(?argsArray, ?index, ?type) <-
+ ArgsArrayFlowToInvokeVar(?argsArray, ?var),
+ StoreArrayConstantIndexType(?type, ?var, ?index).
+
+ArgsArrayFlowToInvoke(?argsArray, ?invo) <-
+ java:lang:reflect:Method:invoke(?invo, _),
+ ReflectiveActualParams[?invo] = ?args,
+ ArgsArrayFlowToInvokeVar(?argsArray, ?args).
+
+MatchedInvokeArgs(?invo, ?method) <-
+ java:lang:reflect:Method:invoke(?invo, _),
+ ResolvedInvokeArgs(?invo),
+ !ArgsArrayFlowToInvoke(_, ?invo),
+ ConcreteMethod(?method),
+ NrFormalParam[?method] = 0.
+
+MatchedInvokeArgs(?invo, ?method) <-
+ java:lang:reflect:Method:invoke(?invo, _),
+ ResolvedInvokeArgs(?invo),
+ ArgsArrayFlowToInvoke(?argsArray, ?invo),
+ ConcreteMethod(?method),
+ NewArraySize[?argsArray] = NrFormalParam[?method],
+ !InvokeArgsArrayHasMismatchedParam(?argsArray, ?method).
+
+InvokeArgsArrayHasMismatchedParam(?argsArray, ?method) <-
+ InvokeArgsArrayStoreIndexType(?argsArray, ?argIndex, _),
+ ConcreteMethod(?method),
+ !InvokeArgsArrayHasMatchedParam(?argsArray, ?argIndex, ?method).
+
+InvokeArgsArrayHasMatchedParam(?argsArray, ?argIndex, ?method) <-
+ InvokeArgsArrayStoreIndexType(?argsArray, ?argIndex, ?argDeclType),
+ AssignCompatible(?argDeclType, ?argType),
+ ConcreteMethod(?method),
+ FormalParam[?paramIndex, ?method] = ?param,
+ ParamIndexRef:Value[?paramIndex] = ArrayIndexRef:Value[?argIndex],
+ AssignCompatible(Var:Type[?param], ?argType).
+
+InvokeArgsArrayHasMatchedParam(?argsArray, ?argIndex, ?method) <-
+ InvokeArgsArrayStoreIndexType(?argsArray, ?argIndex, ?argDeclType),
+ PrimitiveWrapperType(?argDeclType),
+ ConcreteMethod(?method),
+ !FormalParam[ArrayIndexRef:Value[?argIndex], ?method] = _.
+
+FilterMethodByReturnType(?invo, ?method) <-
+ java:lang:reflect:Method:invoke(?invo, _),
+ ConcreteMethod(?method),
+ !InvokeCast(?invo, _).
+
+FilterMethodByReturnType(?invo, ?method) <-
+ java:lang:reflect:Method:invoke(?invo, _),
+ ConcreteMethod(?method),
+ MethodSignature:ReturnType[?method] = ?retType,
+ InvokeCast(?invo, ?castType),
+ FamilyType(?castType, ?retType).
+
+AllPublicInstanceMethod(?type, ?method) <-
+ LookUpMethod(?type, _, ?method), // LookUpMethod only returns public methods
+ MethodSignature:SimpleName[?method] != "",
+ ModifierRef:Value(?static:"static"),
+ !MethodModifier(?static, ?method).
+
+AllInstanceMethod(?type, ?method) <-
+ MethodSignature:Type[?method] = ?type,
+ MethodSignature:SimpleName[?method] != "