LICENSE.txt 0000664 0001754 0001754 00000105430 12712531174 011741 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>.
elf.patch 0000700 0001754 0001754 00000352426 12713475052 011710 0 ustar tiant tiant ELF - Self-Inferencing Reflection Resolution for Java
Copyright (C) 2014 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 elf/gen-import
--- doop-r160113-bin/gen-import 2013-01-16 07:38:09.000000000 +1100
+++ elf/gen-import 2016-05-07 16:02:11.319508485 +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
+
+ # gen post-dominate facts about casting
+ 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/jre-link-arguments elf/jre-link-arguments
--- doop-r160113-bin/jre-link-arguments 2013-01-16 07:31:49.000000000 +1100
+++ elf/jre-link-arguments 2016-05-07 16:02:11.319508485 +1000
@@ -10,6 +10,7 @@
"jre1.4") linkargs="-l ${doopconf_jre14}/lib/rt.jar -l ${doopconf_jre14}/lib/jce.jar -l ${doopconf_jre14}/lib/jsse.jar";;
"jre1.5") linkargs="-l ${doopconf_jre15}/lib/rt.jar -l ${doopconf_jre15}/lib/jce.jar -l ${doopconf_jre15}/lib/jsse.jar";;
"jre1.6") linkargs="-l ${doopconf_jre16}/lib/rt.jar -l ${doopconf_jre16}/lib/jce.jar -l ${doopconf_jre16}/lib/jsse.jar";;
+ "jre1.7") linkargs="-l ${doopconf_jre17}/lib/rt.jar -l ${doopconf_jre17}/lib/jce.jar -l ${doopconf_jre17}/lib/jsse.jar";;
"system") linkargs="-lsystem";;
*) echo "error: unknown jre version"; exit 1;;
esac
diff -urN doop-r160113-bin/logic/context-sensitive.logic elf/logic/context-sensitive.logic
--- doop-r160113-bin/logic/context-sensitive.logic 2013-01-16 07:31:46.000000000 +1100
+++ elf/logic/context-sensitive.logic 2016-05-07 16:02:11.319508485 +1000
@@ -273,6 +273,11 @@
/**
* Load array index
*/
+
+ //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).
+*/
+
+// Use types of objects to filter reflective interprocedural assignments.
+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/elf/array.logic elf/logic/library/elf/array.logic
--- doop-r160113-bin/logic/library/elf/array.logic 1970-01-01 10:00:00.000000000 +1000
+++ elf/logic/library/elf/array.logic 2016-05-07 16:05:22.000000000 +1000
@@ -0,0 +1,95 @@
+/* ELF - Self-Inferencing Reflection Resolution for Java
+ *
+ * Copyright (C) 2014 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 RESOLVE_ARRAY
+
+#ifdef RESOLVE_ARRAY
+/*************************************************************
+ * Array.newInstance
+ * TODO handle multidimensional 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
+ *************************************************************/
+
+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
+ *************************************************************/
+
+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).
+
+#endif // #ifdef RESOLVE_ARRAY
diff -urN doop-r160113-bin/logic/library/elf/inference.logic elf/logic/library/elf/inference.logic
--- doop-r160113-bin/logic/library/elf/inference.logic 1970-01-01 10:00:00.000000000 +1000
+++ elf/logic/library/elf/inference.logic 2016-05-07 16:05:26.000000000 +1000
@@ -0,0 +1,540 @@
+/* ELF - Self-Inferencing Reflection Resolution for Java
+ *
+ * Copyright (C) 2014 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 RESOLVE_NEWINSTANCE_BY_CAST
+//#define CAST_LIMIT 20
+
+AbstractClass(?class) <-
+ ClassModifier(?abstract, ?class),
+ ModifierRef:Value(?abstract:"abstract").
+
+NewableSubtype(?type, ?subtype) <-
+ AssignCompatible(?type, ?subtype),
+ ClassType(?subtype), // exclude interface
+ !AbstractClass(?subtype).
+
+#ifdef CAST_LIMIT
+NrNewableSubtype[?type] = n <-
+ agg<> NewableSubtype(?type, _).
+
+CastLimited(?type) <-
+ NrNewableSubtype[?type] <= CAST_LIMIT.
+#else
+CastLimited(?type) <-
+ Type(?type).
+#endif // #ifdef CAST_LIMIT
+
+#ifdef RESOLVE_NEWINSTANCE_BY_CAST
+ResolvedByCast(?invo, ?castType, ?type),
+ReflectiveAssignHeapAllocation(?invo, ?type, ?ctx, ?to),
+ReflectiveSpecialMethodInvocation(?ctx, ?invo, ?constructor) <-
+ ClassNewInstanceCast(?invo, ?castType),
+ CastLimited(?castType),
+ NewableSubtype(?castType, ?type),
+ java:lang:Class:newInstance(?invo, ?to, ?from),
+ VarPointsTo(_, ?classHeap, ?ctx, ?from),
+ UnknownClass[?classHeap] = _,
+ ReifiedClass[?type] = ?class,
+ OptClassToConstructor(?constructor, ?class).
+#endif // #ifdef RESOLVE_NEWINSTANCE_BY_CAST
+
+#ifdef RESOLVE_NEWINSTANCE_BY_CAST
+// resolved ctor.newInstance by cast
+UnresolvedConstructorNewInstance(?invo, ?ctx, ?to) <-
+ java:lang:reflect:Constructor:newInstance(?invo, ?to, ?from),
+ VarPointsTo(_, ?ctorHeap, ?ctx, ?from),
+ UnknownConstructor[?ctorHeap] = _.
+
+ReflectiveAssignHeapAllocation(?invo, ?type, ?ctx, ?to),
+ReflectiveSpecialMethodInvocation(?ctx, ?invo, ?constructor) <-
+ UnresolvedConstructorNewInstance(?invo, ?ctx, ?to),
+ ConstructorNewInstanceCast(?invo, ?castType),
+ NewableSubtype(?castType, ?type),
+ TypeToPublicConstructor(?constructor, ?type),
+ ConstructorArgFilter(?invo, ?constructor).
+
+UnresolvedDeclaredConstructorNewInstance(?invo, ?ctx, ?to) <-
+ java:lang:reflect:Constructor:newInstance(?invo, ?to, ?from),
+ VarPointsTo(_, ?ctorHeap, ?ctx, ?from),
+ UnknownDeclaredConstructor[?ctorHeap] = _.
+
+ReflectiveAssignHeapAllocation(?invo, ?type, ?ctx, ?to),
+ReflectiveSpecialMethodInvocation(?ctx, ?invo, ?constructor) <-
+ UnresolvedDeclaredConstructorNewInstance(?invo, ?ctx, ?to),
+ ConstructorNewInstanceCast(?invo, ?castType),
+ NewableSubtype(?castType, ?type),
+ TypeToDeclaredConstructor(?constructor, ?type),
+ ConstructorArgFilter(?invo, ?constructor).
+
+TypeToPublicConstructor(?constructor, ?type) <-
+ TypeToDeclaredConstructor(?constructor, ?type),
+ ModifierRef:Value(?public:"public"),
+ MethodModifier(?public, ?constructor).
+
+TypeToDeclaredConstructor(?constructor, ?type) <-
+ MethodSignature:Type[?constructor] = ?type,
+ MethodSignature:SimpleName[?constructor] = ?simplename,
+ SimpleNameRef:Value(?simplename:"").
+#endif // #ifdef RESOLVE_NEWINSTANCE_BY_CAST
+
+FamilyType(?type, ?familyType) ->
+ Type(?type), Type(?familyType).
+
+FamilyType(?type, ?fatherType) <-
+ AssignCompatible(?fatherType, ?type).
+
+FamilyType(?type, ?childType) <-
+ AssignCompatible(?type, ?childType).
+
+// Inference Field access
+
+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").
+// a boxing object can be pointed-to by a variable of type java.lang.Object
+PrimitiveWrapperType(O) <- Type:Value(O:"java.lang.Object").
+
+LookUpFieldByType(?classType, ?fldType, ?field) ->
+ Type(?classType), Type(?fldType), FieldSignatureRef(?field).
+
+LookUpFieldByType(?classType, ?fldType, ?field) <-
+ FieldSignature(?field, ?classType, _, ?fldType),
+ ModifierRef:Value(?public:"public"),
+ FieldModifier(?public, ?field).
+
+LookUpFieldByType(?classType, ?fldType, ?field) <-
+ DirectSuperclass[?classType] = ?superType,
+ LookUpFieldByType(?superType, ?fldType, ?field).
+
+LookUpFieldByType(?type, ?fldType, ?field) <-
+ DirectSuperinterface(?type, ?superIface),
+ LookUpFieldByType(?superIface, ?fldType, ?field).
+
+// l = (A) f.get(o)
+ReflectiveLoadField(?invo, ?ctx, ?to, ?field) <-
+ java:lang:reflect:Field:get(?invo, ?to, ?base),
+ VarPointsTo(_, ?heap, ?ctx, ?base),
+ GetFieldHeap[?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),
+ GetDeclaredFieldHeap[?heap] = ?classType,
+ FieldGetCast(?invo, ?castType),
+ FamilyType(?castType, ?fieldType),
+ FieldSignature(?field, ?classType, _, ?fieldType).
+
+// 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).
+
+ReflectiveLoadField(?invo, ?ctx, ?to, ?signature) <-
+ java:lang:reflect:Field:get(?invo, ?to, ?base),
+ VarPointsTo(_, ?fieldHeap, ?ctx, ?base),
+ UnknownResolvedField[?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),
+ UnknownResolvedDeclaredField[?fieldHeap] = ?name,
+ java:lang:reflect:Field:get:base[?invo] = ?arg,
+ VarPointsTo(_, ?receiver, ?ctx, ?arg),
+ HeapAllocation:Type[?receiver] = ?type,
+ AllInstanceField(?type, ?name, ?signature).
+
+// l = f.get(o), f -> unknown field, o -> normal object
+ReflectiveLoadField(?invo, ?ctx, ?to, ?signature) <-
+ java:lang:reflect:Field:get(?invo, ?to, ?base),
+ VarPointsTo(_, ?fieldHeap, ?ctx, ?base),
+ UnknownField[?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),
+ UnknownDeclaredField[?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).
+
+SpecialSetCase(?invo) <-
+ java:lang:reflect:Field:set:base[?invo] = ?base,
+ java:lang:reflect:Field:set:from[?invo] = ?from,
+ Var:Type[?base] = ?baseType,
+ Var:Type[?from] = ?fromType,
+ (Type:Value(?baseType:"java.lang.Object");
+ Type:Value(?fromType:"java.lang.Object")).
+
+// f.set(o, v)
+// Resolve field type through dynamic types of v
+ReflectiveStoreField(?invo, ?field, ?ctx, ?from) <-
+ java:lang:reflect:Field:set(?invo, ?base),
+ !SpecialSetCase(?invo),
+ VarPointsTo(_, ?heap, ?ctx, ?base),
+ GetFieldHeap[?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),
+ !SpecialSetCase(?invo),
+ VarPointsTo(_, ?heap, ?ctx, ?base),
+ GetDeclaredFieldHeap[?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).
+
+AllNotFinalPublicInstanceField(?classType, ?field, ?fieldType) ->
+ Type(?classType),
+ FieldSignatureRef(?field),
+ Type(?fieldType).
+
+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).
+
+ReflectiveStoreField(?invo, ?field, ?ctx, ?from) <-
+ java:lang:reflect:Field:set(?invo, ?base),
+ VarPointsTo(_, ?fieldHeap, ?ctx, ?base),
+ UnknownResolvedField[?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),
+ UnknownResolvedDeclaredField[?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.set(o, val), f -> unknown field, o -> normal object
+ReflectiveStoreField(?invo, ?field, ?ctx, ?from) <-
+ java:lang:reflect:Field:set(?invo, ?base),
+ !SpecialSetCase(?invo),
+ VarPointsTo(_, ?fieldHeap, ?ctx, ?base),
+ UnknownField[?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),
+ !SpecialSetCase(?invo),
+ VarPointsTo(_, ?fieldHeap, ?ctx, ?base),
+ UnknownDeclaredField[?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]).
+
+/******************** Unknown Field end **********************/
+
+// intra-procedural analysis for resolving Method.invoke
+VarFlowToReflectiveArgs(?args, ?args) <-
+ ReflectiveActualParams[_] = ?args.
+
+VarFlowToReflectiveArgs(?from, ?args) <-
+ (
+ AssignLocal(?from, ?to, _);
+ AssignCast(_, ?from, ?to, _)
+ ),
+ VarFlowToReflectiveArgs(?to, ?args).
+
+UnresolvedReflectiveArgs(?invoke, ?args) <-
+ ReflectiveActualParams[?invoke] = ?args,
+ VarFlowToReflectiveArgs(?var, ?args),
+ (
+ LoadArrayIndex(_, ?var, _);
+ StoreArrayIndex(?var, _, _);
+ LoadInstanceField(_, _, ?var, _);
+ StoreInstanceField(?var, _, _, _);
+ LoadStaticField(_, ?var, _);
+ StoreStaticField(?var, _, _);
+ (
+ ActualParam[_, ?invo] = ?var,
+ !ReflectiveActualParams[?invo] = ?args
+ );
+ FormalParam[_, _] = ?var;
+ AssignReturnValue[_] = ?var;
+ (
+ java:lang:reflect:Method:invoke(?invoke, _),
+ AssignHeapAllocation(?argsArray, ?var, _),
+ SpecialArgsArray(?argsArray)
+ );
+ (
+ AssignHeapAllocation(?argsArray, ?var, _),
+ !NewArraySize[?argsArray] = _
+ );
+ StoreArrayVarIndexType(?var, _)
+ ).
+
+ResolvedArgsInvoke(?invo) <-
+ java:lang:reflect:Method:invoke(?invo, _),
+ ReflectiveActualParams[?invo] = ?args,
+ !UnresolvedReflectiveArgs(?invo, ?args).
+
+ResolvedArgsInvoke(?invo) <-
+ java:lang:reflect:Method:invoke(?invo, _),
+ !ReflectiveActualParams[?invo] = _.
+
+VarFlowToVar(?var, ?var) <-
+ VarFlowToReflectiveArgs(?var, _).
+
+VarFlowToVar(?from, ?to) <-
+ VarFlowToVar(?var, ?to),
+ (
+ AssignLocal(?from, ?var, _);
+ AssignCast(_, ?from, ?var, _)
+ ).
+
+ArgsArrayFlowToVar(?argsArray, ?to) <-
+ AssignHeapAllocation(?argsArray, ?var, _),
+ VarFlowToVar(?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.
+ArgsArrayStoreIndexType(?argsArray, ?index, ?type) <-
+ ArgsArrayFlowToVar(?argsArray, ?var),
+ StoreArrayConstantIndexType(?type, ?var, ?index).
+
+SpecialArgsArray(?argsArray) <-
+ ArgsArrayStoreIndexType(?argsArray, 0, ?argDeclType),
+ Type:Value(?argDeclType:"java.lang.Object"),
+ !ArgsArrayStoreIndexType(?argsArray, 1, _).
+
+ArgsArrayFlowToInvoke(?argsArray, ?invo) <-
+ ReflectiveActualParams[?invo] = ?args,
+ ArgsArrayFlowToVar(?argsArray, ?args).
+
+MatchedArgs(?invo, ?method) <-
+ java:lang:reflect:Method:invoke(?invo, _),
+ ResolvedArgsInvoke(?invo),
+ !ArgsArrayFlowToInvoke(_, ?invo),
+ ConcreteMethod(?method),
+ NrFormalParam[?method] = 0.
+
+MatchedArgs(?invo, ?method) <-
+ java:lang:reflect:Method:invoke(?invo, _),
+ ResolvedArgsInvoke(?invo),
+ ArgsArrayFlowToInvoke(?argsArray, ?invo),
+ ConcreteMethod(?method),
+ NewArraySize[?argsArray] = NrFormalParam[?method],
+ !ArgsArrayHasMismatchedParam(?argsArray, ?method).
+
+ArgsArrayHasMismatchedParam(?argsArray, ?method) <-
+ ArgsArrayStoreIndexType(?argsArray, ?argIndex, _),
+ ConcreteMethod(?method),
+ !ArgsArrayHasMatchedParam(?argsArray, ?argIndex, ?method).
+
+ArgsArrayHasMatchedParam(?argsArray, ?argIndex, ?method) <-
+ ArgsArrayStoreIndexType(?argsArray, ?argIndex, ?argDeclType),
+ AssignCompatible(?argDeclType, ?argType),
+ ConcreteMethod(?method),
+ FormalParam[?paramIndex, ?method] = ?param,
+ ParamIndexRef:Value[?paramIndex] = ArrayIndexRef:Value[?argIndex],
+ AssignCompatible(Var:Type[?param], ?argType).
+
+ArgsArrayHasMatchedParam(?argsArray, ?argIndex, ?method) <-
+ ArgsArrayStoreIndexType(?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).
+
+//////////////////////////////////////////////////////////
+// resolve method (from getMethod()) by arg,
+// m.invoke(obj, args), args is not null
+ReflectiveMethodInvocation(?ctx, ?invo, ?method) <-
+ java:lang:reflect:Method:invoke(?invo, ?base),
+ VarPointsTo(_, ?heap, ?ctx, ?base),
+ GetMethodHeap[?heap] = ?type,
+ LookUpMethod(?type, _, ?method),
+ FilterMethodByReturnType(?invo, ?method),
+ MatchedArgs(?invo, ?method).
+
+// resolve method (from getDeclaredMethod()) by arg,
+// m.invoke(obj, args), args is not null
+ReflectiveMethodInvocation(?ctx, ?invo, ?method) <-
+ java:lang:reflect:Method:invoke(?invo, ?base),
+ VarPointsTo(_, ?heap, ?ctx, ?base),
+ GetDeclaredMethodHeap[?heap] = ?type,
+ MethodSignature:Type[?method] = ?type,
+ MethodSignature:SimpleName[?method] != "", // exclude constructor
+ MethodSignature:SimpleName[?method] != "", // exclude class initializer
+ FilterMethodByReturnType(?invo, ?method),
+ MatchedArgs(?invo, ?method).
+
+ConcreteMethod(?method) <-
+ MethodImplemented[_, _, _] = ?method.
+
+AllPublicInstanceMethod(?type, ?method) <-
+ LookUpMethod(?type, _, ?method), // LookUpMethod only returns public methods
+ ModifierRef:Value(?static:"static"),
+ !MethodModifier(?static, ?method).
+
+AllInstanceMethod(?type, ?method) <-
+ MethodSignature:Type[?method] = ?type,
+ MethodSignature:SimpleName[?method] != "",
+ ModifierRef:Value(?static:"static"),
+ !MethodModifier(?static, ?method).
+
+AllInstanceMethod(?type, ?method) <-
+ DirectSuperclass[?type] = ?supertype,
+ AllInstanceMethod(?supertype, ?method).
+
+// m^u_s
+ReflectiveMethodInvocation(?ctx, ?invo, ?method) <-
+ java:lang:reflect:Method:invoke(?invo, ?base),
+ VarPointsTo(_, ?heap, ?ctx, ?base),
+ UnknownResolvedMethod[?heap] = ?name,
+ ReflectiveBaseVar[?invo] = ?receiver,
+ VarPointsTo(_, ?receiverHeap, ?ctx, ?receiver),
+ AllPublicInstanceMethod(HeapAllocation:Type[?receiverHeap], ?method),
+ MethodSignature:SimpleName[?method] = ?name.
+
+ReflectiveMethodInvocation(?ctx, ?invo, ?method) <-
+ java:lang:reflect:Method:invoke(?invo, ?base),
+ VarPointsTo(_, ?heap, ?ctx, ?base),
+ UnknownResolvedDeclaredMethod[?heap] = ?name,
+ ReflectiveBaseVar[?invo] = ?receiver,
+ VarPointsTo(_, ?receiverHeap, ?ctx, ?receiver),
+ AllInstanceMethod(HeapAllocation:Type[?receiverHeap], ?method),
+ MethodSignature:SimpleName[?method] = ?name.
+
+// resolve unknown Method & Field
+// m.invoke(o, arg), m -> unknown method, o -> normal object
+ReflectiveMethodInvocation(?ctx, ?invo, ?method) <-
+ java:lang:reflect:Method:invoke(?invo, ?base),
+ VarPointsTo(_, ?heap, ?ctx, ?base),
+ UnknownMethod[?heap] = _,
+ ReflectiveBaseVar[?invo] = ?receiver,
+ VarPointsTo(_, ?receiverHeap, ?ctx, ?receiver),
+ AllPublicInstanceMethod(HeapAllocation:Type[?receiverHeap], ?method),
+ FilterMethodByReturnType(?invo, ?method),
+ MatchedArgs(?invo, ?method).
+
+ReflectiveMethodInvocation(?ctx, ?invo, ?method) <-
+ java:lang:reflect:Method:invoke(?invo, ?base),
+ VarPointsTo(_, ?heap, ?ctx, ?base),
+ UnknownDeclaredMethod[?heap] = _,
+ ReflectiveBaseVar[?invo] = ?receiver,
+ VarPointsTo(_, ?receiverHeap, ?ctx, ?receiver),
+ AllInstanceMethod(HeapAllocation:Type[?receiverHeap], ?method),
+ FilterMethodByReturnType(?invo, ?method),
+ MatchedArgs(?invo, ?method).
+
+/******************* Unknown Method end **********************/
+
+
diff -urN doop-r160113-bin/logic/library/elf/propagation.logic elf/logic/library/elf/propagation.logic
--- doop-r160113-bin/logic/library/elf/propagation.logic 1970-01-01 10:00:00.000000000 +1000
+++ elf/logic/library/elf/propagation.logic 2016-05-07 16:05:30.000000000 +1000
@@ -0,0 +1,535 @@
+/* ELF - Self-Inferencing Reflection Resolution for Java
+ *
+ * Copyright (C) 2014 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 .
+ */
+
+StringConstantHeap(?heap) <-
+ InstructionRef:Value(?heap:"<>");
+ ClassNameStringConstant(?heap);
+ MethodNameStringConstant(?heap);
+ FieldNameStringConstant(?heap).
+
+UnresolvedReflectiveAssignClassConstant(?ctx, ?invocation) ->
+ Context(?ctx), MethodInvocationRef(?invocation).
+
+UnresolvedReflectiveAssignClassConstant(?ctx, ?invocation) <-
+ java:lang:Class:forName(?invocation, ?inmethod),
+ ReachableContext(?ctx, ?inmethod),
+ java:lang:Class:forName:ActualParam[?invocation] = ?param,
+ VarPointsTo(_, ?constant, ?ctx, ?param),
+ !StringConstantHeap(?constant),
+ !Config:DynamicClass(_, ?invocation).
+
+RecordMacro(?ctx, ?heap, ?hctx),
+VarPointsTo(?hctx, ?heap, ?ctx, ?return) <-
+ UnresolvedReflectiveAssignClassConstant(?ctx, ?invocation),
+ UnknownClass[?heap] = ?invocation,
+ AssignReturnValue[?invocation] = ?return.
+
+///////////////////////////////////////////////////////////////////////////////
+// m^t_s
+// API call scenario: Method mtd = clz.getField("const string");
+ResolvedMethod(?invo, ?meth, ?ctx) ->
+ MethodInvocationRef(?invo), MethodSignatureRef(?meth), Context(?ctx).
+
+UnresolvedMethod(?invo, ?ctx, ?type) ->
+ MethodInvocationRef(?invo),
+ Context(?ctx),
+ Type(?type).
+
+LookUpMethod(?type, ?methName, ?meth) ->
+ Type(?type), SimpleNameRef(?methName), MethodSignatureRef(?meth).
+
+LookUpMethod(?type, ?methName, ?meth) <-
+ MethodSignature:Type[?meth] = ?type,
+ MethodSignature:SimpleName[?meth] = ?methName,
+ MethodSignature:SimpleName[?meth] != "",
+ MethodSignature:SimpleName[?meth] != "",
+ ModifierRef:Value(?public:"public"),
+ MethodModifier(?public, ?meth).
+
+LookUpMethod(?type, ?methName, ?meth) <-
+ DirectSuperclass[?type] = ?super,
+ LookUpMethod(?super, ?methName, ?meth).
+
+LookUpMethod(?type, ?methName, ?meth) <-
+ InterfaceType(?type),
+ DirectSuperinterface(?type, ?superType),
+ LookUpMethod(?superType, ?methName, ?meth).
+
+LookUpMethod(?type, ?methName, ?meth) <-
+ ClassType(?type),
+ ModifierRef:Value(?abstract:"abstract"),
+ ClassModifier(?abstract, ?type),
+ DirectSuperinterface(?type, ?superType),
+ LookUpMethod(?superType, ?methName, ?meth).
+
+ResolvedMethod(?invo, ?meth, ?ctx) <-
+ java:lang:Class:getMethod(?invo, ?base),
+ VarPointsTo(_, ?class, ?ctx, ?base),
+ ReifiedClass[?type] = ?class,
+ ActualParam[?zero, ?invo] = ?argParam,
+ ParamIndexRef:Value(?zero:0),
+ VarPointsTo(_, ?methNameHeap, ?ctx, ?argParam),
+ MethodNameStringConstant:SimpleName[?methNameHeap] = ?methName,
+ LookUpMethod(?type, ?methName, ?meth).
+
+ResolvedMethod(?invo, ?meth, ?ctx) <-
+ java:lang:Class:getDeclaredMethod(?invo, ?base),
+ VarPointsTo(_, ?class, ?ctx, ?base),
+ ReifiedClass[?type] = ?class,
+ ActualParam[?zero, ?invo] = ?argParam,
+ ParamIndexRef:Value(?zero:0),
+ VarPointsTo(_, ?methNameHeap, ?ctx, ?argParam),
+ MethodNameStringConstant:SimpleName[?methNameHeap] = ?methName,
+ MethodSignature:SimpleName[?meth] = ?methName,
+ MethodSignature:Type[?meth] = ?type.
+
+RecordMacro(?ctx, ?heap, ?hctx),
+VarPointsTo(?hctx, ?heap, ?ctx, ?to) <-
+ ResolvedMethod(?invo, ?meth, ?ctx),
+ ReifiedMethod[?meth] = ?heap,
+ AssignReturnValue[?invo] = ?to.
+
+// m^t_u
+UnresolvedMethod(?invo, ?ctx, ?type) <-
+ java:lang:Class:getMethod(?invo, ?base),
+ VarPointsTo(_, ?class, ?ctx, ?base),
+ ReifiedClass[?type] = ?class,
+ ActualParam[?zero, ?invo] = ?argParam,
+ ParamIndexRef:Value(?zero:0),
+ VarPointsTo(_, ?methNameHeap, ?ctx, ?argParam),
+ !StringConstantHeap(?methNameHeap).
+
+RecordMacro(?ctx, ?heap, ?hctx),
+VarPointsTo(?hctx, ?heap, ?ctx, ?return) <-
+ java:lang:Class:getMethod(?invo, _),
+ UnresolvedMethod(?invo, ?ctx, ?type),
+ GetMethodHeap[?heap] = ?type,
+ AssignReturnValue[?invo] = ?return.
+
+UnresolvedMethod(?invo, ?ctx, ?type) <-
+ java:lang:Class:getDeclaredMethod(?invo, ?base),
+ VarPointsTo(_, ?class, ?ctx, ?base),
+ ReifiedClass[?type] = ?class,
+ ActualParam[?zero, ?invo] = ?argParam,
+ ParamIndexRef:Value(?zero:0),
+ VarPointsTo(_, ?methNameHeap, ?ctx, ?argParam),
+ !StringConstantHeap(?methNameHeap).
+
+RecordMacro(?ctx, ?heap, ?hctx),
+VarPointsTo(?hctx, ?heap, ?ctx, ?return) <-
+ java:lang:Class:getDeclaredMethod(?invo, _),
+ UnresolvedMethod(?invo, ?ctx, ?type),
+ GetDeclaredMethodHeap[?heap] = ?type,
+ AssignReturnValue[?invo] = ?return.
+
+// get[Declared]Methods
+UnresolvedMethod(?invo, ?ctx, ?type) <-
+ java:lang:Class:getMethods(?invo, ?base),
+ VarPointsTo(_, ?class, ?ctx, ?base),
+ ReifiedClass[?type] = ?class.
+
+RecordMacro(?ctx, ?baseheap, ?hctx),
+VarPointsTo(?hctx, ?baseheap, ?ctx, ?to),
+ArrayIndexPointsTo(?hctx, ?heap, ?hctx, ?baseheap) <-
+ java:lang:Class:getMethods(?invo, _),
+ UnresolvedMethod(?invo, ?ctx, ?type),
+ GetMethodHeap[?heap] = ?type,
+ GetMethodsHeap[?invo] = ?baseheap,
+ AssignReturnValue[?invo] = ?to.
+
+UnresolvedMethod(?invo, ?ctx, ?type) <-
+ java:lang:Class:getDeclaredMethods(?invo, ?base),
+ VarPointsTo(_, ?class, ?ctx, ?base),
+ ReifiedClass[?type] = ?class.
+
+RecordMacro(?ctx, ?baseheap, ?hctx),
+VarPointsTo(?hctx, ?baseheap, ?ctx, ?to),
+ArrayIndexPointsTo(?hctx, ?heap, ?hctx, ?baseheap) <-
+ java:lang:Class:getDeclaredMethods(?invo, _),
+ UnresolvedMethod(?invo, ?ctx, ?type),
+ GetDeclaredMethodHeap[?heap] = ?type,
+ GetDeclaredMethodsHeap[?invo] = ?baseheap,
+ AssignReturnValue[?invo] = ?to.
+
+// for getMethod
+// m^u_s
+OnlyNameMethod(?invo, ?ctx, ?name) <-
+ java:lang:Class:getMethod(?invo, ?base),
+ VarPointsTo(_, ?classHeap, ?ctx, ?base),
+ UnknownClass[?classHeap] = _,
+ ActualParam[0, ?invo] = ?argParam,
+ VarPointsTo(_, ?strHeap, ?ctx, ?argParam),
+ MethodNameStringConstant:SimpleName[?strHeap] = ?name.
+
+RecordImmutableMacro(?ctx, ?heap, ?hctx),
+VarPointsTo(?hctx, ?heap, ?ctx, ?return) <-
+ OnlyNameMethod(?invo, ?ctx, ?name),
+ UnknownResolvedMethod[?heap] = ?name,
+ AssignReturnValue[?invo] = ?return.
+
+OnlyNameDeclaredMethod(?invo, ?ctx, ?name) <-
+ java:lang:Class:getDeclaredMethod(?invo, ?base),
+ VarPointsTo(_, ?classHeap, ?ctx, ?base),
+ UnknownClass[?classHeap] = _,
+ ActualParam[0, ?invo] = ?argParam,
+ VarPointsTo(_, ?strHeap, ?ctx, ?argParam),
+ MethodNameStringConstant:SimpleName[?strHeap] = ?name.
+
+RecordImmutableMacro(?ctx, ?heap, ?hctx),
+VarPointsTo(?hctx, ?heap, ?ctx, ?return) <-
+ OnlyNameDeclaredMethod(?invo, ?ctx, ?name),
+ UnknownResolvedDeclaredMethod[?heap] = ?name,
+ AssignReturnValue[?invo] = ?return.
+
+// m^u_u
+TotallyUnknownMethod(?invo, ?ctx) <-
+ java:lang:Class:getMethod(?invo, ?base),
+ VarPointsTo(_, ?classHeap, ?ctx, ?base),
+ UnknownClass[?classHeap] = _,
+ ActualParam[0, ?invo] = ?argParam,
+ VarPointsTo(_, ?strHeap, ?ctx, ?argParam),
+ !StringConstantHeap(?strHeap).
+
+RecordImmutableMacro(?ctx, ?heap, ?hctx),
+VarPointsTo(?hctx, ?heap, ?ctx, ?return) <-
+ TotallyUnknownMethod(?invo, ?ctx),
+ UnknownMethod[?heap] = ?invo,
+ AssignReturnValue[?invo] = ?return.
+
+// for getDeclaredMethod
+TotallyUnknownDeclaredMethod(?invo, ?ctx) <-
+ java:lang:Class:getDeclaredMethod(?invo, ?base),
+ VarPointsTo(_, ?classHeap, ?ctx, ?base),
+ UnknownClass[?classHeap] = _,
+ ActualParam[0, ?invo] = ?argParam,
+ VarPointsTo(_, ?strHeap, ?ctx, ?argParam),
+ !StringConstantHeap(?strHeap).
+
+RecordImmutableMacro(?ctx, ?heap, ?hctx),
+VarPointsTo(?hctx, ?heap, ?ctx, ?return) <-
+ TotallyUnknownDeclaredMethod(?invo, ?ctx),
+ UnknownDeclaredMethod[?heap] = ?invo,
+ AssignReturnValue[?invo] = ?return.
+
+// for getMethods
+RecordMacro(?ctx, ?baseheap, ?hctx),
+VarPointsTo(?hctx, ?baseheap, ?ctx, ?to),
+ArrayIndexPointsTo(?hctx, ?heap, ?hctx, ?baseheap) <-
+ java:lang:Class:getMethods(?invo, ?base),
+ VarPointsTo(_, ?classHeap, ?ctx, ?base),
+ UnknownClass[?classHeap] = _,
+ UnknownMethod[?heap] = ?invo,
+ GetMethodsHeap[?invo] = ?baseheap,
+ AssignReturnValue[?invo] = ?to.
+
+// for getDeclaredMethods
+RecordMacro(?ctx, ?baseheap, ?hctx),
+VarPointsTo(?hctx, ?baseheap, ?ctx, ?to),
+ArrayIndexPointsTo(?hctx, ?heap, ?hctx, ?baseheap) <-
+ java:lang:Class:getDeclaredMethods(?invo, ?base),
+ VarPointsTo(_, ?classHeap, ?ctx, ?base),
+ UnknownClass[?classHeap] = _,
+ UnknownDeclaredMethod[?heap] = ?invo,
+ GetDeclaredMethodsHeap[?invo] = ?baseheap,
+ AssignReturnValue[?invo] = ?to.
+
+/******************* Unknown Field start *********************/
+// f^t_s
+// API call scenario: Field fld = clz.getField("const string");
+ResolvedField(?invo, ?field, ?ctx) ->
+ MethodInvocationRef(?invo), FieldSignatureRef(?field), Context(?ctx).
+
+LookUpField(?type, ?fldName, ?field) ->
+ Type(?type), SimpleNameRef(?fldName), FieldSignatureRef(?field).
+
+LookUpField(?classType, ?fldName, ?field) <-
+ FieldSignature(?field, ?classType, ?fldName, _),
+ ModifierRef:Value(?public:"public"),
+ FieldModifier(?public, ?field).
+
+LookUpField(?classType, ?fldName, ?field) <-
+ DirectSuperclass[?classType] = ?superType,
+ LookUpField(?superType, ?fldName, ?field).
+
+LookUpField(?type, ?fldName, ?field) <-
+ DirectSuperinterface(?type, ?superIface),
+ LookUpField(?superIface, ?fldName, ?field).
+
+ResolvedField(?invo, ?field, ?ctx) <-
+ java:lang:Class:getField(?invo, ?base),
+ VarPointsTo(_, ?class, ?ctx, ?base),
+ ReifiedClass[?type] = ?class,
+ ActualParam[?one, ?invo] = ?argParam,
+ ParamIndexRef:Value(?one:0),
+ VarPointsTo(_, ?fldNameHeap, ?ctx, ?argParam),
+ FieldNameStringConstant:SimpleName[?fldNameHeap] = ?fldName,
+ LookUpField(?type, ?fldName, ?field).
+
+ResolvedField(?invo, ?field, ?ctx) <-
+ java:lang:Class:getDeclaredField(?invo, ?base),
+ VarPointsTo(_, ?class, ?ctx, ?base),
+ ReifiedClass[?type] = ?class,
+ ActualParam[?one, ?invo] = ?argParam,
+ ParamIndexRef:Value(?one:0),
+ VarPointsTo(_, ?fldNameHeap, ?ctx, ?argParam),
+ FieldNameStringConstant:SimpleName[?fldNameHeap] = ?fldName,
+ FieldSignature(?field, ?type, ?fldName, _).
+
+RecordMacro(?ctx, ?heap, ?hctx),
+VarPointsTo(?hctx, ?heap, ?ctx, ?to) <-
+ ResolvedField(?invo, ?field, ?ctx),
+ ReifiedField(?field, ?heap),
+ AssignReturnValue[?invo] = ?to.
+
+// f^t_u
+UnresolvedField(?invo, ?ctx, ?type) ->
+ MethodInvocationRef(?invo), Context(?ctx), Type(?type).
+
+//We need class resolved and field unresolved here
+UnresolvedField(?invo, ?ctx, ?type) <-
+ java:lang:Class:getField(?invo, ?base),
+ VarPointsTo(_, ?class, ?ctx, ?base),
+ ReifiedClass[?type] = ?class,
+ ActualParam[?zero, ?invo] = ?argParam,
+ ParamIndexRef:Value(?zero:0),
+ VarPointsTo(_, ?fldNameHeap, ?ctx, ?argParam),
+ !StringConstantHeap(?fldNameHeap).
+
+RecordMacro(?ctx, ?heap, ?hctx),
+VarPointsTo(?hctx, ?heap, ?ctx, ?return) <-
+ java:lang:Class:getField(?invo, _),
+ UnresolvedField(?invo, ?ctx, ?type),
+ GetFieldHeap[?heap] = ?type,
+ AssignReturnValue[?invo] = ?return.
+
+//for getDeclaredField
+UnresolvedField(?invo, ?ctx, ?type) <-
+ java:lang:Class:getDeclaredField(?invo, ?base),
+ VarPointsTo(_, ?class, ?ctx, ?base),
+ ReifiedClass[?type] = ?class,
+ ActualParam[?zero, ?invo] = ?argParam,
+ ParamIndexRef:Value(?zero:0),
+ VarPointsTo(_, ?fldNameHeap, ?ctx, ?argParam),
+ !StringConstantHeap(?fldNameHeap).
+
+//for getDeclaredField
+RecordMacro(?ctx, ?heap, ?hctx),
+VarPointsTo(?hctx, ?heap, ?ctx, ?return) <-
+ java:lang:Class:getDeclaredField(?invo, _),
+ UnresolvedField(?invo, ?ctx, ?type),
+ GetDeclaredFieldHeap[?heap] = ?type,
+ AssignReturnValue[?invo] = ?return.
+
+UnresolvedField(?invo, ?ctx, ?type) <-
+ java:lang:Class:getFields(?invo, ?base),
+ VarPointsTo(_, ?class, ?ctx, ?base),
+ ReifiedClass[?type] = ?class.
+
+RecordMacro(?ctx, ?baseheap, ?hctx),
+VarPointsTo(?hctx, ?baseheap, ?ctx, ?to),
+ArrayIndexPointsTo(?hctx, ?heap, ?hctx, ?baseheap) <-
+ java:lang:Class:getFields(?invo, _),
+ UnresolvedField(?invo, ?ctx, ?type),
+ GetFieldHeap[?heap] = ?type,
+ GetFieldsHeap[?invo] = ?baseheap,
+ AssignReturnValue[?invo] = ?to.
+
+UnresolvedField(?invo, ?ctx, ?type) <-
+ java:lang:Class:getDeclaredFields(?invo, ?base),
+ VarPointsTo(_, ?class, ?ctx, ?base),
+ ReifiedClass[?type] = ?class.
+
+RecordMacro(?ctx, ?baseheap, ?hctx),
+VarPointsTo(?hctx, ?baseheap, ?ctx, ?to),
+ArrayIndexPointsTo(?hctx, ?heap, ?hctx, ?baseheap) <-
+ java:lang:Class:getDeclaredFields(?invo, _),
+ UnresolvedField(?invo, ?ctx, ?type),
+ GetDeclaredFieldHeap[?heap] = ?type,
+ GetDeclaredFieldsHeap[?invo] = ?baseheap,
+ AssignReturnValue[?invo] = ?to.
+
+
+
+// f^u_s
+OnlyNameField(?invo, ?ctx, ?name) <-
+ java:lang:Class:getField(?invo, ?base),
+ VarPointsTo(_, ?classHeap, ?ctx, ?base),
+ UnknownClass[?classHeap] = _,
+ ActualParam[0, ?invo] = ?argParam,
+ VarPointsTo(_, ?strHeap, ?ctx, ?argParam),
+ FieldNameStringConstant:SimpleName[?strHeap] = ?name.
+
+RecordImmutableMacro(?ctx, ?heap, ?hctx),
+VarPointsTo(?hctx, ?heap, ?ctx, ?return) <-
+ OnlyNameField(?invo, ?ctx, ?name),
+ UnknownResolvedField[?heap] = ?name,
+ AssignReturnValue[?invo] = ?return.
+
+OnlyNameDeclaredField(?invo, ?ctx, ?name) <-
+ java:lang:Class:getDeclaredField(?invo, ?base),
+ VarPointsTo(_, ?classHeap, ?ctx, ?base),
+ UnknownClass[?classHeap] = _,
+ ActualParam[0, ?invo] = ?argParam,
+ VarPointsTo(_, ?strHeap, ?ctx, ?argParam),
+ FieldNameStringConstant:SimpleName[?strHeap] = ?name.
+
+RecordImmutableMacro(?ctx, ?heap, ?hctx),
+VarPointsTo(?hctx, ?heap, ?ctx, ?return) <-
+ OnlyNameDeclaredField(?invo, ?ctx, ?name),
+ UnknownResolvedDeclaredField[?heap] = ?name,
+ AssignReturnValue[?invo] = ?return.
+
+// f^u_u
+// for getField
+TotallyUnknownField(?invo, ?ctx) <-
+ java:lang:Class:getField(?invo, ?base),
+ VarPointsTo(_, ?classHeap, ?ctx, ?base),
+ UnknownClass[?classHeap] = _,
+ ActualParam[0, ?invo] = ?argParam,
+ VarPointsTo(_, ?strHeap, ?ctx, ?argParam),
+ !StringConstantHeap(?strHeap).
+
+RecordImmutableMacro(?ctx, ?heap, ?hctx),
+VarPointsTo(?hctx, ?heap, ?ctx, ?return) <-
+ TotallyUnknownField(?invo, ?ctx),
+ UnknownField[?heap] = ?invo,
+ AssignReturnValue[?invo] = ?return.
+
+// for getDeclaredField
+TotallyUnknownDeclaredField(?invo, ?ctx) <-
+ java:lang:Class:getDeclaredField(?invo, ?base),
+ VarPointsTo(_, ?classHeap, ?ctx, ?base),
+ UnknownClass[?classHeap] = _,
+ ActualParam[0, ?invo] = ?argParam,
+ VarPointsTo(_, ?strHeap, ?ctx, ?argParam),
+ !StringConstantHeap(?strHeap).
+
+RecordImmutableMacro(?ctx, ?heap, ?hctx),
+VarPointsTo(?hctx, ?heap, ?ctx, ?return) <-
+ TotallyUnknownDeclaredField(?invo, ?ctx),
+ UnknownDeclaredField[?heap] = ?invo,
+ AssignReturnValue[?invo] = ?return.
+
+// for getFields
+RecordMacro(?ctx, ?baseheap, ?hctx),
+VarPointsTo(?hctx, ?baseheap, ?ctx, ?to),
+ArrayIndexPointsTo(?hctx, ?heap, ?hctx, ?baseheap) <-
+ java:lang:Class:getFields(?invo, ?base),
+ VarPointsTo(_, ?classHeap, ?ctx, ?base),
+ UnknownClass[?classHeap] = _,
+ UnknownField[?heap] = ?invo,
+ GetFieldsHeap[?invo] = ?baseheap,
+ AssignReturnValue[?invo] = ?to.
+
+// for getDeclaredFields
+RecordMacro(?ctx, ?baseheap, ?hctx),
+VarPointsTo(?hctx, ?baseheap, ?ctx, ?to),
+ArrayIndexPointsTo(?hctx, ?heap, ?hctx, ?baseheap) <-
+ java:lang:Class:getDeclaredFields(?invo, ?base),
+ VarPointsTo(_, ?classHeap, ?ctx, ?base),
+ UnknownClass[?classHeap] = _,
+ UnknownDeclaredField[?heap] = ?invo,
+ GetDeclaredFieldsHeap[?invo] = ?baseheap,
+ AssignReturnValue[?invo] = ?to.
+
+// propagate Constructor
+// known Constructor
+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).
+
+RecordMacro(?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,
+ ObjectShouldNotBeRefined(?heap).
+
+// unknown constructor
+RecordMacro(?ctx, ?heap, ?hctx),
+VarPointsTo(?hctx, ?heap, ?ctx, ?to) <-
+ java:lang:Class:getConstructor(?invo, ?to, ?from),
+ VarPointsTo(_, ?class, ?ctx, ?from),
+ UnknownClass[?class] = _,
+ UnknownConstructor[?heap] = ?invo.
+
+RecordMacro(?ctx, ?heap, ?hctx),
+VarPointsTo(?hctx, ?heap, ?ctx, ?to) <-
+ java:lang:Class:getDeclaredConstructor(?invo, ?to, ?from),
+ VarPointsTo(_, ?class, ?ctx, ?from),
+ UnknownClass[?class] = _,
+ UnknownDeclaredConstructor[?heap] = ?invo.
+
+/*
+RecordImmutableMacro(?ctx, ?heap, ?immHctx),
+RecordMacro(?ctx, ?baseheap, ?hctx),
+VarPointsTo(?hctx, ?baseheap, ?ctx, ?to),
+ArrayIndexPointsTo(?immHctx, ?heap, ?hctx, ?baseheap) <-
+ java:lang:Class:getConstructors(?invo, ?base),
+ VarPointsTo(_, ?class, ?ctx, ?base),
+ ReifiedClass[?type] = ?class,
+ MethodSignature:Type[?signature] = ?type,
+ ModifierRef:Value(?public:"public"),
+ MethodModifier(?public, ?signature),
+ ReifiedConstructor[?signature] = ?heap,
+ GetConstructorsHeap[?invo] = ?baseheap,
+ AssignReturnValue[?invo] = ?to.
+
+RecordImmutableMacro(?ctx, ?heap, ?immHctx),
+RecordMacro(?ctx, ?baseheap, ?hctx),
+VarPointsTo(?hctx, ?baseheap, ?ctx, ?to),
+ArrayIndexPointsTo(?immHctx, ?heap, ?hctx, ?baseheap) <-
+ java:lang:Class:getDeclaredConstructors(?invo, ?base),
+ VarPointsTo(_, ?class, ?ctx, ?base),
+ ReifiedClass[?type] = ?class,
+ MethodSignature:Type[?signature] = ?type,
+ ReifiedConstructor[?signature] = ?heap,
+ GetDeclaredConstructorsHeap[?invo] = ?baseheap,
+ AssignReturnValue[?invo] = ?to.
+*/
+
+RecordImmutableMacro(?ctx, ?heap, ?immHctx),
+RecordMacro(?ctx, ?baseheap, ?hctx),
+VarPointsTo(?hctx, ?baseheap, ?ctx, ?to),
+ArrayIndexPointsTo(?immHctx, ?heap, ?hctx, ?baseheap) <-
+ java:lang:Class:getConstructors(?invo, ?base),
+ VarPointsTo(_, ?class, ?ctx, ?base),
+ UnknownClass[?class] = _,
+ UnknownConstructor[?heap] = ?invo,
+ GetConstructorsHeap[?invo] = ?baseheap,
+ AssignReturnValue[?invo] = ?to.
+
+RecordImmutableMacro(?ctx, ?heap, ?immHctx),
+RecordMacro(?ctx, ?baseheap, ?hctx),
+VarPointsTo(?hctx, ?baseheap, ?ctx, ?to),
+ArrayIndexPointsTo(?immHctx, ?heap, ?hctx, ?baseheap) <-
+ java:lang:Class:getDeclaredConstructors(?invo, ?base),
+ VarPointsTo(_, ?class, ?ctx, ?base),
+ UnknownClass[?class] = _,
+ UnknownDeclaredConstructor[?heap] = ?invo,
+ GetDeclaredConstructorsHeap[?invo] = ?baseheap,
+ AssignReturnValue[?invo] = ?to.
diff -urN doop-r160113-bin/logic/library/elf/reflect-stats.logic elf/logic/library/elf/reflect-stats.logic
--- doop-r160113-bin/logic/library/elf/reflect-stats.logic 1970-01-01 10:00:00.000000000 +1000
+++ elf/logic/library/elf/reflect-stats.logic 2016-05-07 16:05:35.000000000 +1000
@@ -0,0 +1,167 @@
+/* ELF - Self-Inferencing Reflection Resolution for Java
+ *
+ * Copyright (C) 2014 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 .
+ */
+
+/*************************************************************
+ * refine var points to *
+ *************************************************************/
+ReflectionPlaceHolderHeap(?heap) <-
+ UnknownClass[?heap] = _;
+ GetMethodHeap[?heap] = _;
+ GetDeclaredMethodHeap[?heap] = _;
+ GetFieldHeap[?heap] = _;
+ GetDeclaredFieldHeap[?heap] = _;
+ GetMethodsHeap[_] = ?heap;
+ GetDeclaredMethodsHeap[_] = ?heap;
+ GetFieldsHeap[_] = ?heap;
+ GetDeclaredFieldsHeap[_] = ?heap;
+ GetConstructorsHeap[_] = ?heap;
+ GetDeclaredConstructorsHeap[_] = ?heap;
+ UnknownMethod[?heap] = _;
+ UnknownDeclaredMethod[?heap] = _;
+ UnknownField[?heap] = _;
+ UnknownDeclaredField[?heap] = _;
+ UnknownResolvedMethod[?heap] = _;
+ UnknownResolvedDeclaredMethod[?heap] = _;
+ UnknownResolvedField[?heap] = _;
+ UnknownResolvedDeclaredField[?heap] = _;
+ UnknownConstructor[?heap] = _;
+ UnknownDeclaredConstructor[?heap] = _.
+
+#ifdef DISTINGUISH_CLASS_STRING_CONSTANTS
+RefineVarPointsTo(?hctx, ?heap, ?ctx, ?var) <-
+ VarPointsTo(?hctx, ?heap, ?ctx, ?var),
+ // remove reflective place holder
+ ! ReflectionPlaceHolderHeap(?heap),
+ // remove constant string
+ ! MethodNameStringConstant(?heap),
+ ! FieldNameStringConstant(?heap).
+
+RefineVarPointsTo(?hctx, ?heap, ?ctx, ?var) <-
+ VarPointsTo(?hctx, ?methNameHeap, ?ctx, ?var),
+ MethodNameStringConstant(?methNameHeap),
+ InstructionRef:Value(?heap:"<>").
+
+RefineVarPointsTo(?hctx, ?heap, ?ctx, ?var) <-
+ VarPointsTo(?hctx, ?fldNameHeap, ?ctx, ?var),
+ FieldNameStringConstant(?fldNameHeap),
+ InstructionRef:Value(?heap:"<>").
+#endif // #ifdef DISTINGUISH_CLASS_STRING_CONSTANTS
+
+#ifdef DISTINGUISH_ALL_STRING_CONSTANTS
+RefineVarPointsTo(?hctx, ?heap, ?ctx, ?var) <-
+ VarPointsTo(?hctx, ?heap, ?ctx, ?var),
+ ! ReflectionPlaceHolderHeap(?heap).
+#endif // #ifdef DISTINGUISH_ALL_STRING_CONSTANTS
+
+InsensRefineVarPointsTo(?heap, ?var) <-
+ RefineVarPointsTo(_, ?heap, _, ?var).
+
+/*************************************************************
+ * reflection results query *
+ *************************************************************/
+// reflective call graph edges
+InsensReflectiveCallGraphEdge(?caller, ?callee) <-
+ ReflectiveCallGraphEdge(_, ?caller, _, ?callee).
+
+// clz/ctor.newInstance
+ReachableClassNewInstance(?invo) <-
+ java:lang:Class:newInstance(?invo, _, _),
+ Reachable(?inmethod),
+ VirtualMethodInvocation:In(?invo, ?inmethod).
+
+ReachableConstructorNewInstance(?invo) <-
+ java:lang:reflect:Constructor:newInstance(?invo, _, _),
+ Reachable(?inmethod),
+ VirtualMethodInvocation:In(?invo, ?inmethod).
+
+ReachableNewInstance(?invo) <-
+ ReachableClassNewInstance(?invo);
+ ReachableConstructorNewInstance(?invo).
+
+NewInstanceResults(?invo, ?type) <-
+ ReflectiveAssignHeapAllocation(?invo, ?type, _, _).
+
+ResolvedNewInstance(?invo) <-
+ NewInstanceResults(?invo, _).
+
+ClassNewInstanceResults(?invo, ?type) <-
+ NewInstanceResults(?invo, ?type),
+ java:lang:Class:newInstance(?invo, _, _).
+
+ResolvedClassNewInstance(?invo) <-
+ ClassNewInstanceResults(?invo, _).
+
+ConstructorNewInstanceResults(?invo, ?type) <-
+ NewInstanceResults(?invo, ?type),
+ java:lang:reflect:Constructor:newInstance(?invo, _, _).
+
+ResolvedConstructorNewInstance(?invo) <-
+ ConstructorNewInstanceResults(?invo, _).
+
+// mtd.invoke
+ReachableInvoke(?invo) <-
+ java:lang:reflect:Method:invoke(?invo, _),
+ Reachable(?inmethod),
+ VirtualMethodInvocation:In(?invo, ?inmethod).
+
+InvokeResults(?invo, ?method) <-
+ ReflectiveCallGraphEdge(_, ?invo, _, ?method),
+ java:lang:reflect:Method:invoke(?invo, _).
+
+ResolvedInvoke(?invo) <-
+ InvokeResults(?invo, _).
+
+// fld.get/set
+ReachableFieldGet(?invo) <-
+ java:lang:reflect:Field:get(?invo, _, _),
+ Reachable(?inmethod),
+ VirtualMethodInvocation:In(?invo, ?inmethod).
+
+FieldGetResults(?invo, ?field) <-
+ ReflectiveLoadField(?invo, _, _, ?field),
+ ModifierRef:Value(?static:"static"),
+ FieldModifier(?static, ?field).
+
+FieldGetResults(?invo, ?field) <-
+ ReflectiveLoadField(?invo, _, _, ?field),
+ ModifierRef:Value(?static:"static"),
+ ! FieldModifier(?static, ?field),
+ java:lang:reflect:Field:get:base[?invo] = _.
+
+ResolvedFieldGet(?invo) <-
+ FieldGetResults(?invo, _).
+
+ReachableFieldSet(?invo) <-
+ java:lang:reflect:Field:set(?invo, _),
+ Reachable(?inmethod),
+ VirtualMethodInvocation:In(?invo, ?inmethod).
+
+FieldSetResults(?invo, ?field) <-
+ ReflectiveStoreField(?invo, ?field, _, _),
+ ModifierRef:Value(?static:"static"),
+ FieldModifier(?static, ?field).
+
+FieldSetResults(?invo, ?field) <-
+ ReflectiveStoreField(?invo, ?field, _, _),
+ ModifierRef:Value(?static:"static"),
+ ! FieldModifier(?static, ?field),
+ java:lang:reflect:Field:set:base[?invo] = _.
+
+ResolvedFieldSet(?invo) <-
+ FieldSetResults(?invo, _).
+
diff -urN doop-r160113-bin/logic/library/fact-declarations.logic elf/logic/library/fact-declarations.logic
--- doop-r160113-bin/logic/library/fact-declarations.logic 2013-01-16 07:31:46.000000000 +1100
+++ elf/logic/library/fact-declarations.logic 2016-05-07 16:02:11.319508485 +1000
@@ -17,7 +17,9 @@
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).
@@ -59,13 +61,15 @@
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[`InstructionRef] = 1048576. /* 2^20 */
+lang:physical:capacity[`ThrowRef] = 1048576. /* = instruction */
+lang:physical:capacity[`CallGraphEdgeSourceRef] = 1048576. /* = instruction */
+lang:physical:capacity[`HeapAllocationRef] = 1048576. /* = instruction */
+lang:physical:capacity[`MethodInvocationRef] = 1048576. /* = instruction */
+lang:physical:capacity[`StringConstant] = 1048576./* = CallEdgeSourceRef */
+lang:physical:capacity[`ClassConstant] = 1048576./* = CallEdgeSourceRef */
+
lang:physical:capacity[`SimpleNameRef] = 131072.
lang:physical:capacity[`ExceptionHandlerRef] = 131072.
lang:physical:capacity[`VarRef] = 1048576. /* 2^20 */
@@ -95,6 +99,10 @@
MainClass(?ref) ->
ClassType(?ref).
+ClassModifier(?modifier, ?type) ->
+ ModifierRef(?modifier),
+ ClassType(?type).
+
/**
* Variable declarations
*/
@@ -157,13 +165,21 @@
MethodSignatureRef(?signature),
MethodDescriptorRef(?descriptor).
+MethodSignature:ReturnType[?signature] = ?retType ->
+ MethodSignatureRef(?signature),
+ Type(?retType).
+
MethodModifier(?mod, ?method) ->
MethodSignatureRef(?method),
ModifierRef(?mod).
/**
* Parameters
- */
+ */
+NrFormalParam[?method] = ?nr ->
+ MethodSignatureRef(?method),
+ int[16](?nr).
+
FormalParam[?index, ?method] = ?var ->
MethodSignatureRef(?method),
ParamIndexRef(?index),
@@ -334,6 +350,20 @@
VarRef(?from),
VarRef(?base).
+// for matching arguments to filter methods
+StoreArrayConstantIndexType(?type, ?base, ?index) ->
+ Type(?type),
+ VarRef(?base),
+ ArrayIndexRef(?index).
+
+StoreArrayVarIndexType(?base, ?type) ->
+ Type(?type),
+ VarRef(?base).
+
+NewArraySize[?arrayHeap] = ?size ->
+ HeapAllocationRef(?arrayHeap),
+ int[16](?size).
+
ComponentType[?arrayType] = ?componentType ->
ArrayType(?arrayType),
Type(?componentType).
@@ -413,6 +443,95 @@
HeapAllocationRef(?heap),
FieldSignatureRef(?field).
+//for rules about place holder heap in reflection-delta.logic
+
+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
+UnknownMethod[?heap] = ?invo ->
+ HeapAllocationRef(?heap),
+ MethodInvocationRef(?invo).
+
+UnknownDeclaredMethod[?heap] = ?invo ->
+ HeapAllocationRef(?heap),
+ MethodInvocationRef(?invo).
+
+UnknownResolvedMethod[?heap] = ?name ->
+ HeapAllocationRef(?heap),
+ SimpleNameRef(?name).
+
+UnknownResolvedDeclaredMethod[?heap] = ?name ->
+ HeapAllocationRef(?heap),
+ SimpleNameRef(?name).
+
+// unknown Field
+UnknownField[?heap] = ?invo ->
+ HeapAllocationRef(?heap),
+ MethodInvocationRef(?invo).
+
+UnknownDeclaredField[?heap] = ?invo ->
+ HeapAllocationRef(?heap),
+ MethodInvocationRef(?invo).
+
+UnknownResolvedField[?heap] = ?name ->
+ HeapAllocationRef(?heap),
+ SimpleNameRef(?name).
+
+UnknownResolvedDeclaredField[?heap] = ?name ->
+ HeapAllocationRef(?heap),
+ SimpleNameRef(?name).
+
+// unresolved method/field place holder
+GetMethodHeap[?heap] = ?type ->
+ HeapAllocationRef(?heap),
+ Type(?type).
+
+GetDeclaredMethodHeap[?heap] = ?type ->
+ HeapAllocationRef(?heap),
+ Type(?type).
+
+GetFieldHeap[?heap] = ?type ->
+ HeapAllocationRef(?heap),
+ Type(?type).
+
+GetDeclaredFieldHeap[?heap] = ?type ->
+ HeapAllocationRef(?heap),
+ Type(?type).
+
+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
@@ -446,38 +565,73 @@
* 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) ->
+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(?to, ?from) ->
+java:lang:Class:getDeclaredConstructor(?invo, ?to, ?from) ->
+ MethodInvocationRef(?invo),
VarRef(?to),
VarRef(?from).
-java:lang:Class:getDeclaredMethod(?to, ?from) ->
- VarRef(?to),
+java:lang:Class:getMethods(?invocation, ?from) ->
+ MethodInvocationRef(?invocation),
VarRef(?from).
-java:lang:Class:getDeclaredMethods(?to, ?from) ->
- VarRef(?to),
+java:lang:Class:getDeclaredMethods(?invocation, ?from) ->
+ MethodInvocationRef(?invocation),
VarRef(?from).
-java:lang:Class:getDeclaredField(?to, ?from) ->
- VarRef(?to),
+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:getDeclaredFields(?to, ?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:reflect:Method:invoke(?invocation, ?from) ->
MethodInvocationRef(?invocation),
VarRef(?from).
@@ -489,3 +643,31 @@
MethodInvocationRef(?invocation),
VarRef(?to),
VarRef(?field).
+
+/**
+ * cast post dominator of Class.newInstance,
+ * Constructor.newInstance, Field.get and Method.invoke
+ */
+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).
+
+/**
+ * Line numbers of invocations
+ */
+MethodInvocationLineNumber[?invocation] = ?lineNumber ->
+ MethodInvocationRef(?invocation),
+ int[32](?lineNumber).
+
diff -urN doop-r160113-bin/logic/library/native-delta.logic elf/logic/library/native-delta.logic
--- doop-r160113-bin/logic/library/native-delta.logic 2013-01-16 07:31:46.000000000 +1100
+++ elf/logic/library/native-delta.logic 2016-05-07 16:02:11.319508485 +1000
@@ -167,16 +167,109 @@
VirtualMethodInvocation:Signature[?invocation] = ?invoke,
VirtualMethodInvocation:Base[?invocation] = ?base,
AssignReturnValue[?invocation] = ?to.
+
+// 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).
+
++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
++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.
+
/**
* 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
/**********************************************************************************
diff -urN doop-r160113-bin/logic/library/reflection-delta.logic elf/logic/library/reflection-delta.logic
--- doop-r160113-bin/logic/library/reflection-delta.logic 2013-01-16 07:31:46.000000000 +1100
+++ elf/logic/library/reflection-delta.logic 2016-05-07 16:02:11.319508485 +1000
@@ -74,3 +74,240 @@
FieldSignatureRef:Value(?x:?signature),
?strHeap = "",
Type:Value(?type:"java.lang.reflect.Field").
+
+// place holder
++UnknownClass[?heap] = ?invo,
++InstructionRef:Value(?heap:?strHeap),
++HeapAllocationRef(?heap),
++HeapAllocation:Type[?heap] = ?type
+ <-
+ java:lang:Class:forName@previous(?invo, _),
+ Type:Value(?type:"java.lang.Class"),
+ InstructionRef:Value@previous(?invo:?strInvo),
+ ?strHeap = "".
+
++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 = "".
+
++UnknownMethod[?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 = "".
+
++UnknownDeclaredMethod[?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 = "".
+
++UnknownField[?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 = "".
+
++UnknownDeclaredField[?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 = "".
+
+// following place holders are used for the cast that
+// class name is unknown but method/field name is string constant
++UnknownResolvedMethod[?heap] = ?name,
++InstructionRef:Value(?heap:?strHeap),
++HeapAllocationRef(?heap),
++HeapAllocation:Type[?heap] = ?type
+ <-
+ MethodSignature:SimpleName[_] = ?name,
+ SimpleNameRef:Value(?name:?strName),
+ ?strHeap = "",
+ Type:Value(?type:"java.lang.reflect.Method").
+
++UnknownResolvedDeclaredMethod[?heap] = ?name,
++InstructionRef:Value(?heap:?strHeap),
++HeapAllocationRef(?heap),
++HeapAllocation:Type[?heap] = ?type
+ <-
+ MethodSignature:SimpleName[_] = ?name,
+ SimpleNameRef:Value(?name:?strName),
+ ?strHeap = "",
+ Type:Value(?type:"java.lang.reflect.Method").
+
++UnknownResolvedField[?heap] = ?name,
++InstructionRef:Value(?heap:?strHeap),
++HeapAllocationRef(?heap),
++HeapAllocation:Type[?heap] = ?type
+ <-
+ FieldSignature(_, _, ?name, _),
+ SimpleNameRef:Value(?name:?strName),
+ ?strHeap = "",
+ Type:Value(?type:"java.lang.reflect.Field").
+
++UnknownResolvedDeclaredField[?heap] = ?name,
++InstructionRef:Value(?heap:?strHeap),
++HeapAllocationRef(?heap),
++HeapAllocation:Type[?heap] = ?type
+ <-
+ FieldSignature(_, _, ?name, _),
+ SimpleNameRef:Value(?name:?strName),
+ ?strHeap = "",
+ Type:Value(?type:"java.lang.reflect.Field").
+
+// unresolved method/field place holder
++GetMethodHeap[?heap] = ?type,
++InstructionRef:Value(?heap:?strHeap),
++HeapAllocationRef(?heap),
++HeapAllocation:Type[?heap] = ?methodType
+ <-
+ ClassType(?type),
+ Type:Value(?type:?strType),
+ ?strHeap = "",
+ Type:Value(?methodType:"java.lang.reflect.Method").
+
++GetDeclaredMethodHeap[?heap] = ?type,
++InstructionRef:Value(?heap:?strHeap),
++HeapAllocationRef(?heap),
++HeapAllocation:Type[?heap] = ?methodType
+ <-
+ ClassType(?type),
+ Type:Value(?type:?strType),
+ ?strHeap = "",
+ Type:Value(?methodType:"java.lang.reflect.Method").
+
++GetFieldHeap[?heap] = ?type,
++InstructionRef:Value(?heap:?strHeap),
++HeapAllocationRef(?heap),
++HeapAllocation:Type[?heap] = ?fieldType
+ <-
+ ClassType(?type),
+ Type:Value(?type:?strType),
+ ?strHeap = "",
+ Type:Value(?fieldType:"java.lang.reflect.Field").
+
++GetDeclaredFieldHeap[?heap] = ?type,
++InstructionRef:Value(?heap:?strHeap),
++HeapAllocationRef(?heap),
++HeapAllocation:Type[?heap] = ?fieldType
+ <-
+ ClassType(?type),
+ Type:Value(?type:?strType),
+ ?strHeap = "",
+ Type:Value(?fieldType:"java.lang.reflect.Field").
+
+
+// Array heaps for getMethods and getDeclaredMethods
++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[]").
+
+// Array heaps for getFields and getDeclaredFields
++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[]").
+
+// getConstructors and getDeclaredConstructors
++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 = "".
+
diff -urN doop-r160113-bin/logic/library/reflection.logic elf/logic/library/reflection.logic
--- doop-r160113-bin/logic/library/reflection.logic 2013-01-16 07:31:46.000000000 +1100
+++ elf/logic/library/reflection.logic 2016-05-07 16:04:46.000000000 +1000
@@ -1,109 +1,15 @@
-/*************************************************************
- * 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
- *************************************************************/
-
-/*************************************************************
- * Object.getClass
- *
- * stable public interface
- * public final native Class getClass()
- *
- * Although Object.getClass is a reflection operation, it is easy to
- * analyse statically, because we know the type of every heap
- * allocation.
- *************************************************************/
+#include "elf/propagation.logic"
+#include "elf/inference.logic"
+#include "elf/array.logic"
+#include "elf/reflect-stats.logic"
-/**
- * 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
*/
@@ -135,157 +41,7 @@
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);
- *
- *************************************************************/
-
-/**
- * find invocations
- */
-java:lang:Class:getDeclaredMethod(?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: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
-
-/*************************************************************
- * 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.
- *
- *************************************************************/
-
-/**
- * find invocations
- */
-java:lang:Class:getConstructor(?to, ?from) <-
- MethodSignatureRef:Value(?signature:""),
- VirtualMethodInvocation:Signature[?invocation] = ?signature,
- AssignReturnValue[?invocation] = ?to,
- VirtualMethodInvocation:Base[?invocation] = ?from.
-
-java:lang:Class:getDeclaredConstructor(?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: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).
-
-RecordMacro(?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,
- ObjectShouldNotBeRefined(?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
-
-/*************************************************************
* 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) <-
@@ -314,30 +70,6 @@
/*************************************************************
* 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),
@@ -345,7 +77,9 @@
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),
+ ConstructorCastFilter(?invocation, ?type).
ReflectiveBaseVar[?invocation] = ?to <-
java:lang:reflect:Constructor:newInstance(?invocation, ?to, _).
@@ -355,41 +89,48 @@
ActualParam[?zero, ?invocation] = ?argsParam,
ParamIndexRef:Value(?zero:0).
+ConstructorArgFilter(?invocation, ?constructor) <-
+ MatchedNewInstanceArgs(?invocation, ?constructor).
+
+ConstructorArgFilter(?invocation, ?constructor) <-
+ java:lang:reflect:Constructor:newInstance(?invocation, _, _),
+ !ResolvedArgsNewInstance(?invocation),
+ ReifiedConstructor[?constructor] = _.
+
+ResolvedArgsNewInstance(?invo) <-
+ java:lang:reflect:Constructor:newInstance(?invo, _, _),
+ ReflectiveActualParams[?invo] = ?args,
+ !UnresolvedReflectiveArgs(?invo, ?args).
+
+ResolvedArgsNewInstance(?invo) <-
+ java:lang:reflect:Constructor:newInstance(?invo, _, _),
+ !ReflectiveActualParams[?invo] = _.
+
+MatchedNewInstanceArgs(?invo, ?ctor) <-
+ ResolvedArgsNewInstance(?invo),
+ !ArgsArrayFlowToInvoke(_, ?invo),
+ ReifiedConstructor[?ctor] = _,
+ NrFormalParam[?ctor] = 0.
+
+MatchedNewInstanceArgs(?invo, ?ctor) <-
+ ResolvedArgsNewInstance(?invo),
+ ArgsArrayFlowToInvoke(?argsArray, ?invo),
+ ReifiedConstructor[?ctor] = _,
+ NewArraySize[?argsArray] = NrFormalParam[?ctor],
+ !ArgsArrayHasMismatchedParam(?argsArray, ?ctor).
+
+ConstructorCastFilter(?invo, ?type) <-
+ java:lang:reflect:Constructor:newInstance(?invo, _, _),
+ ! ConstructorNewInstanceCast(?invo, _),
+ ClassType(?type),
+ ! AbstractClass(?type).
+
+ConstructorCastFilter(?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
@@ -403,93 +144,33 @@
MethodDescriptorRef:Value(?descriptor:"void()"),
SimpleNameRef:Value(?simplename:"").
+
ReflectiveAssignHeapAllocation(?invocation, ?type, ?ctx, ?to),
ReflectiveSpecialMethodInvocation(?ctx, ?invocation, ?constructor)
<-
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,
@@ -505,7 +186,6 @@
ActualParam[?zero, ?invocation] = ?base,
ParamIndexRef:Value(?zero:0).
-
/**
* Reflective load of field (instance or static)
*/
@@ -521,17 +201,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 +218,6 @@
/*************************************************************
* Field.set
- *
- * stable public interface
- * public void set(Object, Object)
- *
*************************************************************/
/**
diff -urN doop-r160113-bin/logic/library/reflective.logic elf/logic/library/reflective.logic
--- doop-r160113-bin/logic/library/reflective.logic 2013-01-16 07:31:46.000000000 +1100
+++ elf/logic/library/reflective.logic 2016-05-07 16:02:11.319508485 +1000
@@ -187,7 +187,7 @@
MethodSignature:Descriptor[?signature] = ?descriptor,
MethodLookup[?simplename, ?descriptor, ?heaptype] = ?tomethod,
ThisVar[?tomethod] = ?this.
-
+
/**
* Return values of reflective method invocations
*/
@@ -265,9 +265,26 @@
/**
* TODO it's unfortunate this code is so similar to normal LoadArrayIndex.
*/
+/**
+ * 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).
+
+/*
LoadHeapArrayIndex(?calleeCtx, ?to, ?basehctx, ?baseheap) <-
ReflectiveLoadArrayIndex(?calleeCtx, ?to, ?callerCtx, ?base),
VarPointsTo(?basehctx, ?baseheap, ?callerCtx, ?base).
+*/
/*************************************************************
@@ -298,7 +315,9 @@
StaticFieldPointsTo(?hctx, ?heap, ?signature) <-
ReflectiveStoreStaticField(?signature, ?ctx, ?var),
- VarPointsTo(?hctx, ?heap, ?ctx, ?var).
+ VarPointsTo(?hctx, ?heap, ?ctx, ?var),
+ FieldSignature(?signature, _, _, ?type),
+ AssignCompatible(?type, HeapAllocation:Type[?heap]).
/*************************************************************
*
@@ -324,6 +343,12 @@
Context(?fromCtx), VarRef(?from), Context(?baseCtx), VarRef(?base),
FieldSignatureRef(?signature).
-StoreHeapInstanceField(?signature, ?basehctx, ?baseheap, ?fromCtx, ?from) <-
+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/string-constants.logic elf/logic/library/string-constants.logic
--- doop-r160113-bin/logic/library/string-constants.logic 2013-01-16 07:31:46.000000000 +1100
+++ elf/logic/library/string-constants.logic 2016-05-07 16:02:11.323508485 +1000
@@ -71,9 +71,14 @@
HeapAllocation:Merge[?heap] = ?constant <-
StringConstant(?heap),
! ClassNameStringConstant(?heap),
+ ! MethodNameStringConstant(?heap),
+ ! FieldNameStringConstant(?heap),
HeapAllocationValue(?constant, "<>").
HeapAllocation:ContextInsensitive(?heap) <-
+// distinguish method name and field name
+ MethodNameStringConstant(?heap);
+ FieldNameStringConstant(?heap);
ClassNameStringConstant(?heap).
#endif
@@ -101,6 +106,37 @@
InstructionRef:Value(?heap:?string),
ReferenceType(?type),
Type:Value(?type:?string).
+
+MethodNameStringConstant(?heap) ->
+ HeapAllocationRef(?heap).
+
+MethodNameStringConstant:SimpleName[?heap] = ?simpleName ->
+ HeapAllocationRef(?heap),
+ SimpleNameRef(?simpleName).
+
+FieldNameStringConstant(?heap) ->
+ HeapAllocationRef(?heap).
+
+FieldNameStringConstant:SimpleName[?heap] = ?simpleName ->
+ HeapAllocationRef(?heap),
+ SimpleNameRef(?simpleName).
+
+MethodNameStringConstant(?heap),
+MethodNameStringConstant:SimpleName[?heap] = ?simpleName
+ <-
+ StringConstant(?heap),
+ InstructionRef:Value(?heap:?string),
+ MethodSignature:SimpleName[_] = ?simpleName,
+ SimpleNameRef:Value(?simpleName:?string).
+
+FieldNameStringConstant(?heap),
+FieldNameStringConstant:SimpleName[?heap] = ?simpleName
+ <-
+ StringConstant(?heap),
+ InstructionRef:Value(?heap:?string),
+ FieldSignature(_, _, ?simpleName, _),
+ SimpleNameRef:Value(?simpleName:?string).
+
#endif
/*************************************************************
@@ -151,8 +187,8 @@
//TypeToHeap2(?heap, ?heaptype) <-
// HeapAllocation:Type[?heap] = ?heaptype,
- // Type:Value(?throw:"java.lang.Throwable"),
- // AssignCompatible(?throw, ?heaptype),
+ // Type:Value(?throw:"java.lang.Throwable"),
+ // AssignCompatible(?throw, ?heaptype),
// ExceptionHandler:Type[_] = ?handlertype,
// AssignCompatible(?handlertype, ?heaptype).
diff -urN doop-r160113-bin/logic/library.logic elf/logic/library.logic
--- doop-r160113-bin/logic/library.logic 2013-01-16 07:31:46.000000000 +1100
+++ elf/logic/library.logic 2016-05-07 16:02:11.323508485 +1000
@@ -150,7 +150,6 @@
Field:Type[?signature] = ?type <-
FieldSignature(?signature, _, _, ?type).
-
/**
* Joins of input facts, useful for performance reasons.
*/
diff -urN doop-r160113-bin/run elf/run
--- doop-r160113-bin/run 2013-01-16 07:38:09.000000000 +1100
+++ elf/run 2016-05-07 16:02:11.323508485 +1000
@@ -20,6 +20,7 @@
${C_YELLOW}-jre1.4${C_RESET} Use jre1.4 (default: system)
${C_YELLOW}-jre1.5${C_RESET} Use jre1.5 (default: system)
${C_YELLOW}-jre1.6${C_RESET} Use jre1.6 (default: system)
+ ${C_YELLOW}-jre1.7${C_RESET} Use jre1.7 (default: system)
${C_YELLOW}-os NAME${C_RESET} Specify the operating system to simulate (win32, winnt, unix, default: unix)
${C_YELLOW}-stats${C_RESET} Load additional logic for collecting statistics
${C_YELLOW}-sanity${C_RESET} Load additional logic for sanity checks
@@ -135,7 +136,7 @@
export LD_LIBRARY_PATH=$LOGICBLOX_HOME/bin:$LD_LIBRARY_PATH
bloxbatch="$LOGICBLOX_HOME/bin/bloxbatch"
-
+#bloxbatch="$LOGICBLOX_HOME/bin/lb" # - use lb to replace bloxbatch
# defaults for options
CPPFLAGS_EXCEPTIONS="-DEXCEPTIONS_PRECISE"
CPPFLAGS_PADDLE_COMPAT=""
@@ -152,11 +153,11 @@
sanity="false"
stats="false"
transformInput="false"
-ssa="false"
classlib="system"
mainclass=""
os="unix"
dynamics=""
+genSootLog="false"
logicProfile=""
logLevel=""
refine="false"
@@ -255,10 +256,6 @@
transformInput="true"
shift 1
;;
- "-ssa")
- ssa="true"
- shift 1
- ;;
"-cache")
cache="true"
shift 1
@@ -273,7 +270,7 @@
mainclass="$1"
shift 1
;;
- "-jre1.3" | "-jre1.4" | "-jre1.5" | "-jre1.6")
+ "-jre1.3" | "-jre1.4" | "-jre1.5" | "-jre1.6" | "-jre1.7" )
classlib="${1:1:6}"
shift 1
;;
@@ -295,6 +292,10 @@
dynamics="${dynamics} $1"
shift 1
;;
+ "-generate-soot-reflection-log")
+ genSootLog="true"
+ shift 1
+ ;;
"-logicProfile")
shift 1
logicProfile="-logicProfile $1"
@@ -355,6 +356,9 @@
"jre1.6")
CPPFLAGS_JRE="-DJRE16"
;;
+ "jre1.7")
+ CPPFLAGS_JRE="-DJRE17"
+ ;;
"system")
CPPFLAGS_JRE="-DJRE16"
;;
@@ -467,7 +471,7 @@
function benchmark()
{
- timeLimit=5400
+ timeLimit=10800
echo "..."
printf "${C_YELLOW}MBBENCH logicblox START${C_RESET}\n"
@@ -490,6 +494,7 @@
function singleRun()
{
if test $singleRun = "true"; then
+ #bloxbatchRunning=`ps -ef | grep lb | { grep -v grep || true; }`
bloxbatchRunning=`ps -ef | grep bloxbatch | { grep -v grep || true; }`
if test "x${bloxbatchRunning}" != "x"; then
echo -n 'WARNING: Bloxbatch is already running. '
@@ -547,9 +552,6 @@
| sha256sum | awk '{print $1}')
suffix=""
- if test $ssa = "true"; then
- suffix="-ssa"
- fi
if test $transformInput = "true"; then
suffix=$suffix"-transformInput"
fi
@@ -579,16 +581,13 @@
sootFactGenArgs=""
- if test $ssa = "true"; then
- sootFactGenArgs="$sootFactGenArgs -ssa"
- fi
-
if test $phantom = "true"; then
sootFactGenArgs="$sootFactGenArgs -allow-phantom"
fi
- timing java -cp lib/sootclasses-2.3.0.jar:lib/soot-fact-generation.jar Main \
- -main $mainclass $sootFactGenArgs -full $(./jre-link-arguments $classlib) -d tmp/facts $jars $depargs
+ # use sootclasses-2.5.0 to replace soot 2.3
+ timing java -cp lib/sootclasses-2.5.0.jar:lib/soot-fact-generation.jar Main \
+ -main $mainclass $sootFactGenArgs -ssa -full $(./jre-link-arguments $classlib) -d tmp/facts $jars $depargs
mkdir -p $cachefacts
mv tmp/facts/* $cachefacts
@@ -613,6 +612,7 @@
echo "setting main class to $mainclass"
$bloxbatch -db $cachedatabase -execute "+MainClass(x) <- ClassType(x), Type:Value(x:\"$mainclass\")."
+
fi
mkdir -p $(dirname $database)
@@ -841,6 +841,13 @@
fi
}
+function gen-soot-reflection-log()
+{
+ printf "${C_WHITE}generating reflection log for Soot at ${C_GREEN}%s${C_RESET}\n" "$mainclass.log"
+ python scripts/get-refl-targets.py $mainclass $database tmp
+ python scripts/soot-converter.py $mainclass $database tmp
+}
+
function show-stats()
{
./stats-simple $database
@@ -1009,6 +1016,11 @@
run-stats
link-result
+
+if test $genSootLog = "true"; then
+ gen-soot-reflection-log
+fi
+
show-stats
if test -e logic/$analysis/refinement-delta.logic; then
diff -urN doop-r160113-bin/scripts/get-refl-targets.py elf/scripts/get-refl-targets.py
--- doop-r160113-bin/scripts/get-refl-targets.py 1970-01-01 10:00:00.000000000 +1000
+++ elf/scripts/get-refl-targets.py 2016-05-07 16:05:49.000000000 +1000
@@ -0,0 +1,82 @@
+#!/usr/bin/python
+
+# ELF - Self-Inferencing Reflection Resolution for Java
+#
+# Copyright (C) 2014 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 .
+
+import os, sys
+from collections import OrderedDict
+
+cmd_dict = {
+ 'forname':"bloxbatch -db %s -query \
+ '_(?invo, ?type) <- ReflectiveAssignClassConstant(_, ?invo, ?type), \
+ java:lang:Class:forName(?invo, _).' \
+ | sort",
+ 'cnew':'bloxbatch -db %s -query ClassNewInstanceResults | sort',
+ 'ctornew':'bloxbatch -db %s -query ConstructorNewInstanceResults | sort',
+ 'get':'bloxbatch -db %s -query FieldGetResults | sort',
+ 'set':'bloxbatch -db %s -query FieldSetResults | sort',
+ 'invo':'bloxbatch -db %s -query InvokeResults | sort',
+}
+
+def Run(bm, db, result_dir):
+ # Get reflection anlaysis results
+ if os.path.isdir(db):
+ for k, v in cmd_dict.items():
+ output = os.path.join(result_dir, '%s.%s' % (bm, k))
+ cmd = v % (db) + '>' + output
+ os.system(cmd)
+
+ # Output resolved reflective call sites
+ calls = OrderedDict()
+ calls['cnew'] = 'Class.newInstance'
+ calls['ctornew'] = 'Constructor.newInstance'
+ calls['invo'] = 'Method.invoke'
+ calls['get'] = 'Field.get*'
+ calls['set'] = 'Field.set*'
+
+ fout = open(os.path.join(result_dir, bm + '.resolved'), 'w')
+ for call, call_name in calls.items():
+ result_dict = OrderedDict()
+ fin = open(os.path.join(result_dir, bm + '.' + call))
+ for line in fin:
+ if line.strip() != '':
+ [callsite, target] = line.strip().split(', ')
+ if result_dict.has_key(callsite):
+ result_dict[callsite] += 1
+ else:
+ result_dict[callsite] = 1
+ fin.close()
+
+ fout.write('[%s]:\n' % (call_name))
+ for callsite, count in result_dict.items():
+ fout.write('%s, %d\n' % (callsite, count))
+ fout.write('\n')
+ fout.close()
+
+
+def PrintUsage():
+ print '[Usage]: ./get-refl-target.py bm db result_dir'
+
+if __name__ == '__main__':
+ try:
+ bm = sys.argv[1]
+ db = sys.argv[2]
+ result_dir = sys.argv[3]
+ Run(bm, db, result_dir)
+ except Exception:
+ PrintUsage()
+ raise
diff -urN doop-r160113-bin/scripts/soot-converter.py elf/scripts/soot-converter.py
--- doop-r160113-bin/scripts/soot-converter.py 1970-01-01 10:00:00.000000000 +1000
+++ elf/scripts/soot-converter.py 2016-05-07 16:34:05.000000000 +1000
@@ -0,0 +1,110 @@
+#!/usr/bin/python
+
+# ELF - Self-Inferencing Reflection Resolution for Java
+#
+# Copyright (C) 2014 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 .
+
+
+# Convert reflection analysis results to the format which can be recognized by Soot
+
+import os, sys
+from collections import OrderedDict
+
+ref_calls = OrderedDict()
+ref_calls['forname'] = 'Class.forName'
+ref_calls['cnew'] = 'Class.newInstance'
+ref_calls['ctornew'] = 'Constructor.newInstance'
+ref_calls['invo'] = 'Method.invoke'
+ref_calls['get'] = 'Field.get*'
+ref_calls['set'] = 'Field.set*'
+
+class Converter:
+ def __init__(self, bm, db, result_dir):
+ self.bm = bm
+ self.db = db
+ self.result_dir = result_dir
+ self.target_map = {} # key: call, value: (callsite -> targets)
+ self.lineno_map = {} # key: callsite, value: lineno
+
+ def ReadTargets(self, call):
+ if not self.target_map.has_key(call):
+ f = open('%s/%s.%s' % (self.result_dir, self.bm, call))
+ m = {}
+ for line in f:
+ [cs, target] = line.strip().split(', ')
+ if m.has_key(cs): m[cs].append(target)
+ else: m[cs] = [target]
+ f.close()
+ self.target_map[call] = m
+
+ def ReadLineNumberOfCallsite(self):
+ def IsReflCall(callsite):
+ for ref_call in ref_calls.values():
+ if ref_call.strip('*') in callsite:
+ return True
+ return False
+ if len(self.lineno_map) == 0:
+ ln_file = '%s/%s.ln' % (self.result_dir, self.bm)
+ os.system('bloxbatch -db %s -query MethodInvocationLineNumber > %s' % (self.db, ln_file))
+ f = open(ln_file)
+ for line in f:
+ [callsite, lineno] = line.strip().split(', ')
+ if IsReflCall(callsite):
+ if lineno != '0':
+ self.lineno_map[callsite] = lineno
+ else:
+ print 'Unknown line number in %s: callsite [%s]' % (self.bm, callsite)
+
+ def RemoveDescriptor(self, sig):
+ cls = sig.split(':')[0][1:]
+ name = sig.split(' ')[2].split('(')[0]
+ return cls + '.' + name
+
+ def ConvertCallSite(self, callsite, target, ln):
+ for ref_call in ref_calls.values():
+ if ref_call.strip('*') in callsite.split('/')[1]:
+ caller = callsite.split('/')[0]
+ if caller.startswith('<'): caller = self.RemoveDescriptor(caller)
+ return '%s;%s;%s;%s;;' % (ref_call, target, caller, ln)
+
+ def Convert(self, out):
+ for ref_call in ref_calls.keys():
+ self.ReadTargets(ref_call)
+ self.ReadLineNumberOfCallsite()
+ fout = open(out, 'w')
+ for call in ref_calls.keys():
+ for callsite, targets in self.target_map[call].items():
+ if self.lineno_map.has_key(callsite):
+ ln = self.lineno_map[callsite]
+ for target in targets:
+ entry = self.ConvertCallSite(callsite, target, ln)
+ if entry is not None:
+ fout.write(entry + '\n')
+ fout.close()
+
+def PrintUsage():
+ print '[Usage]: ./soot-converter.py bm db dir'
+
+if __name__ == '__main__':
+ try:
+ bm = sys.argv[1]
+ db = sys.argv[2]
+ result_dir = sys.argv[3]
+ converter = Converter(bm, db, result_dir)
+ converter.Convert('%s.log' % bm)
+ except Exception:
+ PrintUsage()
+ raise
diff -urN doop-r160113-bin/stats-simple elf/stats-simple
--- doop-r160113-bin/stats-simple 2013-01-16 07:31:45.000000000 +1100
+++ elf/stats-simple 2016-05-07 16:02:11.323508485 +1000
@@ -17,38 +17,48 @@
function print2()
{
- printf "%-80s %'d\n" "$1" "$2"
+ printf "%-50s %'d\n" "$1" "$2"
+ printf "%-50s %'d\n" "$1" "$2" >> tmp/temp.lb&
}
function print3()
{
- printf "%-80s %'d (insens) / %'d (sens)\n" "$1" "$2" "$3"
+ printf "%-50s %'d (insens) / %'d (sens)\n" "$1" "$2" "$3"
+ printf "%-50s %'d (insens) / %'d (sens)\n" "$1" "$2" "$3" >> tmp/temp.lb&
}
+function print4()
+{
+ printf "%-50s %'d (C:callsites) / %'d (T:targets)\n" "$1" "$2" "$3"
+}
-print3 "var points-to" $(size Stats:Simple:InsensVarPointsTo) $(size VarPointsTo)
-print3 "array index points-to" $(size Stats:Simple:InsensArrayIndexPointsTo) $(size ArrayIndexPointsTo)
-print3 "call graph edges" $(size Stats:Simple:InsensCallGraphEdge) $(size CallGraphEdge)
-# print3 "native call graph edges" $(size Stats:Simple:InsensNativeCallGraphEdge) $(size NativeCallGraphEdge)
-print3 "instance field points-to" $(size Stats:Simple:InsensInstanceFieldPointsTo) $(size InstanceFieldPointsTo)
-print3 "reachable methods" $(size Reachable) $(size ReachableContext)
+#print3 "var points-to" $(size Stats:Simple:InsensVarPointsTo) $(size VarPointsTo)
+#print3 "refine var points-to" $(size InsensRefineVarPointsTo) $(size RefineVarPointsTo)
+print3 "var points-to" $(size InsensRefineVarPointsTo) $(size RefineVarPointsTo)
print3 "reachable variables" $(size Stats:Simple:InsensReachableVar) $(size Stats:Simple:ReachableVar)
-print3 "static field points-to" $(size Stats:Simple:InsensStaticFieldPointsTo) $(size StaticFieldPointsTo)
+#print3 "array index points-to" $(size Stats:Simple:InsensArrayIndexPointsTo) $(size ArrayIndexPointsTo)
+print3 "regular call graph edges" $(size Stats:Simple:InsensCallGraphEdge) $(size CallGraphEdge)
+print3 "reflective call graph edges" $(size InsensReflectiveCallGraphEdge) $(size ReflectiveCallGraphEdge)
-print2 "virtual call sites (statically)" $(size VirtualMethodInvocation:In)
+#print3 "native call graph edges" $(size Stats:Simple:InsensNativeCallGraphEdge) $(size NativeCallGraphEdge)
+#print3 "instance field points-to" $(size Stats:Simple:InsensInstanceFieldPointsTo) $(size InstanceFieldPointsTo)
+print3 "reachable methods" $(size Reachable) $(size ReachableContext)
+#print3 "static field points-to" $(size Stats:Simple:InsensStaticFieldPointsTo) $(size StaticFieldPointsTo)
+
+#print2 "virtual call sites (statically)" $(size VirtualMethodInvocation:In)
print2 "reachable virtual call sites" $(size Stats:Simple:ReachableVirtualMethodInvocation)
print2 "polymorphic virtual call sites" $(size Stats:Simple:PolymorphicCallSite)
-print2 "null virtual call sites" $(size Stats:Simple:NullVirtualMethodInvocation)
-print2 "app virtual call sites (statically)" $(size Stats:Simple:Application:VirtualMethodInvocation)
-print2 "app reachable virtual call sites" $(size Stats:Simple:Application:ReachableVirtualMethodInvocation)
-print2 "app polymorphic virtual call sites" $(size Stats:Simple:Application:PolymorphicCallSite)
-print2 "app null virtual call sites" $(size Stats:Simple:Application:NullVirtualMethodInvocation)
-print2 "casts (statically)" $(size AssignCast)
+#print2 "null virtual call sites" $(size Stats:Simple:NullVirtualMethodInvocation)
+#print2 "app virtual call sites (statically)" $(size Stats:Simple:Application:VirtualMethodInvocation)
+#print2 "app reachable virtual call sites" $(size Stats:Simple:Application:ReachableVirtualMethodInvocation)
+#print2 "app polymorphic virtual call sites" $(size Stats:Simple:Application:PolymorphicCallSite)
+#print2 "app null virtual call sites" $(size Stats:Simple:Application:NullVirtualMethodInvocation)
+#print2 "casts (statically)" $(size AssignCast)
print2 "reachable casts" $(size Stats:Simple:ReachableCast)
print2 "reachable casts that may fail" $(size Stats:Simple:PotentiallyFailingCast)
-print2 "app casts (statically)" $(size Stats:Simple:Application:Cast)
-print2 "app reachable casts" $(size Stats:Simple:Application:ReachableCast)
-print2 "app reachable casts that may fail" $(size Stats:Simple:Application:PotentiallyFailingCast)
+#print2 "app casts (statically)" $(size Stats:Simple:Application:Cast)
+#print2 "app reachable casts" $(size Stats:Simple:Application:ReachableCast)
+#print2 "app reachable casts that may fail" $(size Stats:Simple:Application:PotentiallyFailingCast)
# print2 "array type" $(size ArrayType)
# print2 "direct superclass" $(size DirectSuperclass)
@@ -59,3 +69,7 @@
# print2 "superclass" $(size Superclass)
# print2 "superinterface" $(size Superinterface)
# print2 "variables" $(size VarRef)
+
+print4 "method invoke" $(size ResolvedInvoke) $(size InvokeResults)
+print4 "field get" $(size ResolvedFieldGet) $(size FieldGetResults)
+print4 "field set" $(size ResolvedFieldSet) $(size FieldSetResults)
gen.patch 0000700 0001754 0001754 00000315341 12713475057 011713 0 ustar tiant tiant ELF - Self-Inferencing Reflection Resolution for Java
Copyright (C) 2014 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 elf-gen/compile
--- soot-fact-generation-r958-src/compile 2009-06-05 22:41:56.000000000 +1000
+++ elf-gen/compile 2015-06-14 19:56:46.156125151 +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/FactGenerator.java elf-gen/src/FactGenerator.java
--- soot-fact-generation-r958-src/src/FactGenerator.java 2009-06-03 01:40:01.000000000 +1000
+++ elf-gen/src/FactGenerator.java 2015-06-14 20:04:27.000000000 +1000
@@ -1,521 +1,593 @@
-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.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
+ * @author Yue Li
+ * @author Tian Tan
* @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 _current_dominators;
+
+ 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();
+ generate(m, session);
+ }
+
+ // writing 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 classes.
+ // This method must be invoked after generate(m, session),
+ // because the generate(m, session) would set corresponding bodies
+ // (jimple or shimple) to the class.
+ writeClass(c);
+ }
+
+ 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 write 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
+ if (_ssa) {
+ _current_dominators = PostDominatorFinder.findPostDominate(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 (_ssa && _current_dominators.containsKey(stmt)) {
+ String predicate;
+ 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 {
+ return;
+ }
+ _writer.writePostDominatorCast(inMethod, stmt,
+ _current_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 elf-gen/src/FactWriter.java
--- soot-fact-generation-r958-src/src/FactWriter.java 2009-06-04 13:07:30.000000000 +1000
+++ elf-gen/src/FactWriter.java 2015-06-14 20:05:40.000000000 +1000
@@ -1,748 +1,745 @@
+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;
+import soot.tagkit.LineNumberTag;
+import soot.tagkit.SourceLnPosTag;
/**
- * 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
+ * @author Yue Li
+ * @author Tian Tan
* @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("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");
+
+ // For handling one dimension Array.newInstance(): primitive type
+ _db.add("ComponentType", _db.addEntity("ArrayType", "boolean[]"),
+ new Column("boolean"));
+ _db.add("ComponentType", _db.addEntity("ArrayType", "byte[]"),
+ new Column("byte"));
+ _db.add("ComponentType", _db.addEntity("ArrayType", "char[]"),
+ new Column("char"));
+ _db.add("ComponentType", _db.addEntity("ArrayType", "short[]"),
+ new Column("short"));
+ _db.add("ComponentType", _db.addEntity("ArrayType", "int[]"),
+ new Column("int"));
+ _db.add("ComponentType", _db.addEntity("ArrayType", "long[]"),
+ new Column("long"));
+ _db.add("ComponentType", _db.addEntity("ArrayType", "float[]"),
+ new Column("float"));
+ _db.add("ComponentType", _db.addEntity("ArrayType", "double[]"),
+ new Column("double"));
+ }
+
+ 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));
+ // For handling Class:getComponentType
+ 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) {
- 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()))));
+ _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 used for invoke cast
+ 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()))));
+ }
- return rep;
- }
+ 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)));
+ }
+ /*
+ * else { _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))); }
+ */
+ }
+
+ 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);
+ 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;
+ }
+
+ public void writePostDominatorCast(SootMethod inMethod, AssignStmt stmt,
+ Type t, Session session, String predicate) {
+ InvokeExpr expr = stmt.getInvokeExpr();
+ String name = expr.getMethod().getName();
+ String invoke = _rep.compactMethod(inMethod) + "/"
+ + expr.getMethod().getDeclaringClass() + "." + name + "/"
+ + session.currentNumber(name);
+
+ _db.add(predicate, _db.addEntity("MethodInvocationRef", invoke),
+ writeType(t));
+ }
+
+ 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 writeClassModifier(SootClass c, String modifier) {
+ _db.add("ClassModifier",
+ _db.addEntity("ModifierRef", _rep.modifier(modifier)),
+ _db.addEntity("ClassType", _rep.type(c)));
+ }
+
+ 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)));
+ }
+
+
}
diff -urN soot-fact-generation-r958-src/src/Main.java elf-gen/src/Main.java
--- soot-fact-generation-r958-src/src/Main.java 2009-06-04 13:07:30.000000000 +1000
+++ elf-gen/src/Main.java 2015-06-14 20:28:09.000000000 +1000
@@ -10,246 +10,220 @@
public class Main {
- public static enum Mode {INPUTS, FULL;}
+ 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 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);
+ }
+
+ 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);
+ }
+
+ // Adding classes for resolving.
+ scene.tryLoadClass("java.util.CurrencyData", SootClass.BODIES);
+ if (scene.containsClass("javax.swing.plaf.metal.MetalLookAndFeel")) {
+ scene.tryLoadClass("javax.swing.plaf.metal.MetalBorders",
+ SootClass.BODIES);
+ }
+
+ /*
+ * 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 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 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);
- }
-
- }
+ }
}
\ No newline at end of file
diff -urN soot-fact-generation-r958-src/src/NoSearchingClassProvider.java elf-gen/src/NoSearchingClassProvider.java
--- soot-fact-generation-r958-src/src/NoSearchingClassProvider.java 2009-06-04 01:45:54.000000000 +1000
+++ elf-gen/src/NoSearchingClassProvider.java 2015-06-14 19:56:46.000000000 +1000
@@ -78,9 +78,11 @@
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);
}
diff -urN soot-fact-generation-r958-src/src/PostDominatorFinder.java elf-gen/src/PostDominatorFinder.java
--- soot-fact-generation-r958-src/src/PostDominatorFinder.java 1970-01-01 10:00:00.000000000 +1000
+++ elf-gen/src/PostDominatorFinder.java 2015-06-14 20:32:31.000000000 +1000
@@ -0,0 +1,116 @@
+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 {
+ @SuppressWarnings("rawtypes")
+ public static Map findPostDominate(Body body) {
+ // get all clz.newInstance() units
+ List call_list = new ArrayList();
+ for (Unit unit : body.getUnits()) {
+ if (hasClassNewInstanceCall(unit) ||
+ hasConstructorNewInstanceCall(unit) ||
+ hasGetCall(unit) ||
+ hasInvokeCall(unit)) {
+ call_list.add((AssignStmt)unit);
+ }
+ }
+ // compute post-dominate relationship
+ Map result = new HashMap();
+ if (!call_list.isEmpty()) {
+ UnitGraph cfg = new BriefUnitGraph(body);
+ 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;
+ }
+
+ public static boolean hasClassNewInstanceCall(Unit unit) {
+ Stmt stmt = (Stmt) unit;
+ if (stmt instanceof AssignStmt && stmt.containsInvokeExpr()) {
+ return stmt.
+ getInvokeExpr().
+ getMethodRef().
+ getSignature().equals("");
+ } else {
+ return false;
+ }
+ }
+
+ public static boolean hasConstructorNewInstanceCall(Unit unit) {
+ Stmt stmt = (Stmt) unit;
+ if (stmt instanceof AssignStmt && stmt.containsInvokeExpr()) {
+ return stmt.
+ getInvokeExpr().
+ getMethodRef().
+ getSignature().equals("");
+ } else {
+ return false;
+ }
+ }
+
+ public static boolean hasGetCall(Unit unit) {
+ Stmt stmt = (Stmt) unit;
+ if (stmt instanceof AssignStmt && stmt.containsInvokeExpr()) {
+ return stmt.
+ getInvokeExpr().
+ getMethodRef().
+ getSignature().equals("");
+ } else {
+ return false;
+ }
+ }
+
+ public static boolean hasInvokeCall(Unit unit) {
+ Stmt stmt = (Stmt) unit;
+ if (stmt instanceof AssignStmt && stmt.containsInvokeExpr()) {
+ return stmt.
+ getInvokeExpr().
+ getMethodRef().
+ getSignature().equals("");
+ } else {
+ return false;
+ }
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ 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 (Object 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/Session.java elf-gen/src/Session.java
--- soot-fact-generation-r958-src/src/Session.java 2009-02-14 05:05:38.000000000 +1100
+++ elf-gen/src/Session.java 2015-06-14 19:56:46.000000000 +1000
@@ -21,6 +21,12 @@
return x.intValue();
}
+
+ // 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();
tutorial 0000700 0001754 0001754 00000011743 12713303013 011664 0 ustar tiant tiant -----------------------------
| Installation Instructions |
-----------------------------
1. Download DOOP (r160113) and soot-fact-generation (r958) from http://doop.program-analysis.org/download.html.
2. Unzip DOOP and soot-fact-generation, then set environment variable DOOP_HOME to the directory where you unpack DOOP by:
$ export DOOP_HOME=unpack_directory/doop-r160113-bin/
3. Download sootclasses-2.5.0.jar from http://www.sable.mcgill.ca/software/sootclasses-2.5.0.jar and then
put it in $DOOP_HOME/lib/ directory. (DOOP (r160113) provides sootclasses-2.3.0.jar, ELF's facts generator
needs sootclasses-2.5.0.jar)
4. Download elf.patch to $DOOP_HOME and then apply it to DOOP by:
$ cd $DOOP_HOME
$ patch -p1 < elf.patch
5. Download gen.patch to soot-fact-generation directory and then switch to soot-fact-generation directory, write:
$ patch -p1 < gen.patch
$ ./compile
$ ./install
Now, the ELF has been installed on the top of DOOP.
In addition, to run ELF, users should follow the instructions in $DOOP_HOME/README to setup the
applications and library (to be analyzed) and configure the corresponding paths.
----------
| Usages |
----------
ELF has the similiar usage with DOOP, except that you cannot use -disable-reflection, -disable-reflective-methods
and -distinguish-no-string-constants options.
In addition, ELF adds a "-generate-soot-reflection-log" option which enable ELF to output its reflection analysis
results with a format which is supported by Soot so that ELF can make use of SOLAR. Please see details in next section.
By default, ELF distinguishes a string constants if it is a class name, a method name or a field name. For fairly
comparing with DOOP, ELF treats the string constants which represent method names or field names as one string
constant while computing the size of points-to set.
-----------------------
| Using ELF with Soot |
-----------------------
It just takes two steps to use ELF to facilitate the static analysis with Soot.
Step 1: Running ELF and generating reflection log
---------------------------------------------------------------------
To let ELF create reflection log file, you can use the option "-generate-soot-reflection-log"
which is mentioned above, and then ELF will output its reflection analysis results into a
log file.
The log file name is the name of the main class of the program to be analyzed plus ".log" as suffix.
For example, let us use ELF to analyze luindex benchmark of DaCapo:
$ ./run -jre1.6 -generate-soot-reflection-log 1-call-site-sensitive jars/dacapo/luindex.jar
$ ...
$ generating reflection log for Soot at dacapo.luindex.Main.log
$ ...
Now, ELF has output its reflection analysis results to dacapo.luindex.Main.log.
Step 2: Running Soot with the reflection log generated by ELF
---------------------------------------------------------------------
To use the reflection analysis results of ELF with Soot, you just need to give Soot the log
file generated by ELF by using the option "reflection-log".
Soot provides the option "reflection-log" in call graph construction phase to load
a reflection log from the given file and use it to resolve reflective call sites.
For example, let us use Soot to analyze luindex with reflection log from ELF:
$ java -cp soot-2.5.0.jar soot.Main \ # run Soot
-w -app -p cg.spark enabled \ # enable Spark
-p cg reflection-log:dacapo.luindex.Main.log \ # use the reflection log from ELF
-cp luindex.jar:${JRE}/jce.jar:${JRE}/rt.jar \ # set up class path for Soot
-main-class dacapo.luindex.Main \ # specify main class
dacapo.luindex.Main
------------------------
| Main changes to DOOP |
------------------------
- soot-fact-generation/src/FactWriter.java, FactGenerator.java, PostDominatorFinder.java
Generate more facts for reflection analysis, such as the ones involving post dominance.
- gen-import
Import more facts for reflection analysis.
- logic/library/elf/propagation.logic
New added file which contains rules for resolving reflective calls by target propagation.
- logic/library/elf/inference.logic
New added file which includes rules for resolving reflective calls by target inference.
- logic/library/elf/array.logic
New added file which contains rules for handling methods of java.lang.reflect.Array.
- logic/library/elf/reflect-stats.logic
New added file which contains rules for collecting reflection analysis results.
- logic/context-sensitive.logic
- logic/library/reflective.logic
Fix unsound handling of argument passing for reflective invocation.
- logic/library/reflection-delta.logic
Add place holders for helping target inference.
- logic/library/string-constants.logic
Distinguish string constants whose values equal method names or field names.
- scripts/get-refl-targets.py
- scripts/soot-converter.py
New added scripts for assisting ELF output its results.
- run
Add "-ssa" option to fact generator arguments.
- stats-simple
Output reflection analysis results.
Please feel free to contact the authors if you have any concerns.
release-notes 0000700 0001754 0001754 00000000434 12537435147 012604 0 ustar tiant tiant ELF version 0.3 (Monday, 15 June 2015)
- Generated reflection log which can be used by Soot.
ELF version 0.2 (Tuesday, 4 November 2014)
- Improved precision without compromising soundness.
ELF version 0.1 (Friday, 18 July 2014)
- This is the first release of ELF.