Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decide how to deal with JVM class initialization #916

Open
brianhuffman opened this issue Nov 18, 2020 · 2 comments
Open

Decide how to deal with JVM class initialization #916

brianhuffman opened this issue Nov 18, 2020 · 2 comments
Labels
needs design Technical design work is needed for issue to progress subsystem: crucible-jvm Issues related to Java verification with crucible-jvm type: bug Issues reporting bugs or unexpected/unwanted behavior unsoundness Issues that can lead to unsoundness or false verification
Milestone

Comments

@brianhuffman
Copy link
Contributor

The translation of JVM to crucible in the crucible-jvm package includes global state for keeping track of initialization status for each class, and many operations will conditionally call the static initializer method for a class (and its superclasses) if a class has not yet been initialized. However, we currently have no way to say anything about JVM class initialization status in saw-script.

At the moment I'm working on adding a jvm_static_field_is declaration to address #908. However, I'm running into a problem when I try to verify a method that reads from these static fields. The precondition section says that the static fields for class C should initially contain symbolic values. But then when I start symbolic simulation, the crucible-jvm class initialization status table says that class C is still uninitialized. So before the getstatic instruction is executed, it dutifully runs the static initializer method for class C, which overwrites all the static fields of C with 0. Then the method's return value is based on reading a 0 instead of the symbolic input I declared in the spec.

One could imagine having a SAW command declaring the precondition that a specific class must be initialized. However, this seems like it would be burdensome to use in some cases, because you might be forced to prove a whole collection of overrides for one method, each with a different combination of initialized classes in the preconditions. Most of the time you don't really care about the initialization status of most classes before you start, and the result and/or effects of a method call don't depend on the initialization status either. It would be nice if we could just prove a single override that would be applicable regardless of class initialization status.

@brianhuffman brianhuffman added the subsystem: crucible-jvm Issues related to Java verification with crucible-jvm label Nov 18, 2020
@brianhuffman
Copy link
Contributor Author

The old jss-based java verification interface provided the following setup command:

    java_requires_class : String -> JavaSetup ()

Declare that the given method can only be executed if the given
class has already been initialized.

We could probably use something similar for crucible-jvm verification.

@atomb atomb added this to the 0.8 milestone Dec 11, 2020
brianhuffman pushed a commit that referenced this issue Dec 16, 2020
This makes it possible to verify JVM specs that specify initial
values of static fields; previously the static initializers would
always run upon the first field access and overwrite the assumed
initial values.

Eventually the addition of explicit JVMSetup commands for class
initialization status preconditions will make this unnecessary (#916).
@brianhuffman brianhuffman self-assigned this Dec 16, 2020
brianhuffman pushed a commit that referenced this issue Jan 12, 2021
This makes it possible to verify JVM specs that specify initial
values of static fields; previously the static initializers would
always run upon the first field access and overwrite the assumed
initial values.

Eventually the addition of explicit JVMSetup commands for class
initialization status preconditions will make this unnecessary (#916).
brianhuffman pushed a commit that referenced this issue Jan 12, 2021
This makes it possible to verify JVM specs that specify initial
values of static fields; previously the static initializers would
always run upon the first field access and overwrite the assumed
initial values.

Eventually the addition of explicit JVMSetup commands for class
initialization status preconditions will make this unnecessary (#916).
@atomb atomb removed this from the 0.8 milestone Apr 9, 2021
@sauclovian-g sauclovian-g added type: bug Issues reporting bugs or unexpected/unwanted behavior unsoundness Issues that can lead to unsoundness or false verification needs design Technical design work is needed for issue to progress labels Oct 29, 2024
@sauclovian-g sauclovian-g added this to the 2025T1 milestone Oct 29, 2024
@sauclovian-g
Copy link
Collaborator

Initialization is great, but it's the wrong thing to do. When symbolically executing methods from a class, you aren't intending to only cover the cases where it was just initialized. If you do, you can miss stuff. (hence the unsoundness tag)

The right thing to do is for initialization to be an override spec that establishes the class's invariants, so that the resulting state is a general one that nonetheless respects whatever invariants the initialization is supposed to establish. (Which is also in turn sometimes nonempty, so skipping initialization and assigning a purely symbolic state is also wrong.)

As noted, this is the same as #357 (which is the same issue for C++ global initialization), but it's a general problem and the same considerations also apply to initialization of class instances and other state tracking.

See also #2053.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs design Technical design work is needed for issue to progress subsystem: crucible-jvm Issues related to Java verification with crucible-jvm type: bug Issues reporting bugs or unexpected/unwanted behavior unsoundness Issues that can lead to unsoundness or false verification
Projects
None yet
Development

No branches or pull requests

3 participants